Auto-commit 2026-05-02 09:37
This commit is contained in:
@@ -25,6 +25,7 @@ export class EmailService {
|
||||
subject: string,
|
||||
htmlBody: string,
|
||||
textBody?: string,
|
||||
templateId?: string,
|
||||
attachments?: Array<{
|
||||
filename: string;
|
||||
content: Buffer | string;
|
||||
@@ -35,7 +36,7 @@ export class EmailService {
|
||||
id: `email_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
||||
userId: recipient.userId,
|
||||
channel: NotificationChannel.EMAIL,
|
||||
templateId: 'custom', // Can be updated to use actual template
|
||||
templateId: templateId || 'custom',
|
||||
priority: NotificationPriority.NORMAL,
|
||||
status: NotificationStatus.PENDING,
|
||||
to: recipient.email!,
|
||||
|
||||
@@ -15,23 +15,27 @@ export class PushService {
|
||||
|
||||
constructor(fcmConfig?: FCMConfig, apnsConfig?: APNsConfig) {
|
||||
if (fcmConfig) {
|
||||
if (!admin.apps.length && fcmConfig.keyPath) {
|
||||
// Use named app instance for multi-tenant support
|
||||
const appName = fcmConfig.keyPath
|
||||
? `fcm_${fcmConfig.projectId}`
|
||||
: 'fcm_default';
|
||||
|
||||
// Check if app with this name already exists
|
||||
const existingApp = admin.app(appName);
|
||||
|
||||
if (!existingApp) {
|
||||
this.fcm = admin.initializeApp({
|
||||
credential: admin.credential.cert({
|
||||
projectId: fcmConfig.projectId,
|
||||
privateKey: fcmConfig.privateKey.replace(/\\n/g, '\n'),
|
||||
clientEmail: fcmConfig.clientEmail,
|
||||
}),
|
||||
storageBucket: `${fcmConfig.projectId}.appspot.com`,
|
||||
});
|
||||
} else if (!admin.apps.length) {
|
||||
this.fcm = admin.initializeApp({
|
||||
credential: admin.credential.cert({
|
||||
projectId: fcmConfig.projectId,
|
||||
privateKey: fcmConfig.privateKey.replace(/\\n/g, '\n'),
|
||||
clientEmail: fcmConfig.clientEmail,
|
||||
...(fcmConfig.keyPath && {
|
||||
storageBucket: `${fcmConfig.projectId}.appspot.com`,
|
||||
}),
|
||||
});
|
||||
}, appName);
|
||||
} else {
|
||||
this.fcm = existingApp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,8 +152,9 @@ export class PushService {
|
||||
return notification;
|
||||
}
|
||||
|
||||
// APNs implementation would go here
|
||||
// For now, we'll use FCM for iOS as well (FCM supports APNs)
|
||||
// FCM supports sending to APNs tokens (iOS devices)
|
||||
// This leverages FCM's unified push infrastructure for iOS
|
||||
// APNs token format: device-specific token from iOS
|
||||
if (this.fcm && recipient.apnsToken) {
|
||||
const message: admin.messaging.Message = {
|
||||
token: recipient.apnsToken,
|
||||
@@ -246,12 +251,12 @@ export class PushService {
|
||||
return !!this.fcm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown FCM app
|
||||
*/
|
||||
async shutdown(): Promise<void> {
|
||||
if (this.fcm) {
|
||||
await this.fcm.terminate();
|
||||
/**
|
||||
* Shutdown FCM app
|
||||
*/
|
||||
async shutdown(): Promise<void> {
|
||||
if (this.fcm) {
|
||||
await this.fcm.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user