refactor(backend): move db repos to typescript and update imports

This commit is contained in:
Haileyesus
2026-03-27 20:10:01 +03:00
parent 33cea381c4
commit 90d234d9f3
26 changed files with 960 additions and 60 deletions

View File

@@ -0,0 +1,42 @@
import webPush from 'web-push';
import { vapidKeysDb } from '@/shared/database/repositories/vapid-keys.js';
type VapidKeyPair = {
publicKey: string;
privateKey: string;
};
let cachedKeys: VapidKeyPair | null = null;
function ensureVapidKeys(): VapidKeyPair {
if (cachedKeys) return cachedKeys;
const existingKeys = vapidKeysDb.getVapidKeys();
if (existingKeys) {
cachedKeys = existingKeys;
return existingKeys;
}
const generatedKeys = webPush.generateVAPIDKeys();
vapidKeysDb.createVapidKeys(generatedKeys.publicKey, generatedKeys.privateKey);
cachedKeys = generatedKeys;
return generatedKeys;
}
function getPublicKey(): string {
return ensureVapidKeys().publicKey;
}
function configureWebPush(): void {
const keys = ensureVapidKeys();
webPush.setVapidDetails(
'mailto:noreply@claudecodeui.local',
keys.publicKey,
keys.privateKey
);
console.log('Web Push notifications configured');
}
export { ensureVapidKeys, getPublicKey, configureWebPush };