fix(platform-service+events): 3 more gaps in diagnostics + delivery
- diagnostics/subscribers: wire session.created email notification to target user using existing 'diagnostics-session-created' template (was just logging instead of sending the email) - events/types: add missing 'currency' field to payment.failed schema (payment.succeeded had it, payment.failed did not — inconsistency) - delivery/subscribers: use event.payload.currency instead of hardcoded empty string in payment-failed email variables - Typecheck clean, 1483/1483 tests pass
This commit is contained in:
parent
73b07c2c3a
commit
841cdf3a16
@ -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(),
|
||||
}),
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user