diff --git a/packages/events/src/types.ts b/packages/events/src/types.ts index 56a0cc88..f59677b3 100644 --- a/packages/events/src/types.ts +++ b/packages/events/src/types.ts @@ -120,6 +120,7 @@ export const PlatformEventSchemas = { invoiceId: z.string(), userId: z.string(), amount: z.number(), + currency: z.string().default('usd'), retryCount: z.number(), productId: z.string(), }), diff --git a/services/platform-service/src/modules/delivery/subscribers.ts b/services/platform-service/src/modules/delivery/subscribers.ts index f260ce47..c17f1acf 100644 --- a/services/platform-service/src/modules/delivery/subscribers.ts +++ b/services/platform-service/src/modules/delivery/subscribers.ts @@ -124,7 +124,7 @@ export function registerDeliverySubscribers( displayName: user.displayName, productName: resolveProductName(productId), amount: String(event.payload.amount ?? ''), - currency: '', + currency: event.payload.currency ?? 'usd', billingUrl: `${baseUrl}/billing`, }, productId, diff --git a/services/platform-service/src/modules/diagnostics/subscribers.ts b/services/platform-service/src/modules/diagnostics/subscribers.ts index 5e19f949..de97b9a8 100644 --- a/services/platform-service/src/modules/diagnostics/subscribers.ts +++ b/services/platform-service/src/modules/diagnostics/subscribers.ts @@ -43,12 +43,39 @@ export function registerDiagnosticsSubscribers( }; await auditRepo.create(auditDoc); - // Send email notification to target user if email is available - // Note: In production, we'd look up the user's email from the users repository - // For now, we log that notification would be sent + // Notify the target user via email if they have an account + if (event.payload.targetUserId) { + try { + const targetUser = await getUserById(event.payload.targetUserId); + if (targetUser) { + const session = await getSession(event.payload.sessionId); + await dispatchEmail( + { + to: targetUser.email, + templateId: 'diagnostics-session-created', + variables: { + displayName: targetUser.displayName || targetUser.email.split('@')[0], + productName: event.payload.productId, + sessionId: event.payload.sessionId, + startedAt: new Date().toISOString(), + maxDurationMinutes: String(session?.maxDurationMinutes ?? 30), + }, + productId: event.payload.productId, + userId: event.payload.targetUserId, + }, + log + ); + } + } catch (notifyErr) { + log.error( + { notifyErr }, + '[diagnostics/subscriber] Failed to notify target user on create' + ); + } + } log.info( { sessionId: event.payload.sessionId, targetUserId: event.payload.targetUserId }, - '[diagnostics/subscriber] Session created, user notification queued' + '[diagnostics/subscriber] Session created, user notified' ); } catch (err) { log.error(