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(),
|
invoiceId: z.string(),
|
||||||
userId: z.string(),
|
userId: z.string(),
|
||||||
amount: z.number(),
|
amount: z.number(),
|
||||||
|
currency: z.string().default('usd'),
|
||||||
retryCount: z.number(),
|
retryCount: z.number(),
|
||||||
productId: z.string(),
|
productId: z.string(),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -124,7 +124,7 @@ export function registerDeliverySubscribers(
|
|||||||
displayName: user.displayName,
|
displayName: user.displayName,
|
||||||
productName: resolveProductName(productId),
|
productName: resolveProductName(productId),
|
||||||
amount: String(event.payload.amount ?? ''),
|
amount: String(event.payload.amount ?? ''),
|
||||||
currency: '',
|
currency: event.payload.currency ?? 'usd',
|
||||||
billingUrl: `${baseUrl}/billing`,
|
billingUrl: `${baseUrl}/billing`,
|
||||||
},
|
},
|
||||||
productId,
|
productId,
|
||||||
|
|||||||
@ -43,12 +43,39 @@ export function registerDiagnosticsSubscribers(
|
|||||||
};
|
};
|
||||||
await auditRepo.create(auditDoc);
|
await auditRepo.create(auditDoc);
|
||||||
|
|
||||||
// Send email notification to target user if email is available
|
// Notify the target user via email if they have an account
|
||||||
// Note: In production, we'd look up the user's email from the users repository
|
if (event.payload.targetUserId) {
|
||||||
// For now, we log that notification would be sent
|
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(
|
log.info(
|
||||||
{ sessionId: event.payload.sessionId, targetUserId: event.payload.targetUserId },
|
{ sessionId: event.payload.sessionId, targetUserId: event.payload.targetUserId },
|
||||||
'[diagnostics/subscriber] Session created, user notification queued'
|
'[diagnostics/subscriber] Session created, user notified'
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error(
|
log.error(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user