Sustituye el envío de push por la API legacy de GCM (muerta desde jun-2024) y saca el envío del observer de Meteor a una cola BullMQ controlada. - poller: consume 'notifications' pendientes (campos correctos; el cron viejo tenía un typo nofitied/emailNofitied que nunca casaba) - fcm-worker: firebase-admin (FCM HTTP v1), payload compatible con la app Flutter (FLUTTER_NOTIFICATION_CLICK, collapseKey=_id, data); purga tokens muertos sin reintentar - email-worker: nodemailer + plantillas new-fire portadas verbatim - idempotencia persistente: notification_sends, indice unico (notificationId, channel) -> sobrevive reinicios y replays - salvaguardas anti-spam: modos dry-run/shadow/canary/full, exclusion mutua por canal (OWNED_CHANNELS + notifDisabledChannels en Meteor), kill switch, limites por usuario/dia y circuit breaker por batch - docs/legacy-behavior.md (caracterizacion) + docs/rollout.md - 47 tests (vitest + mongodb-memory-server), typecheck y build OK - deploy: systemd + pm2 (Node 22 standalone) Falta el service account de Firebase para envio real de push (pedir al usuario).
14 lines
641 B
TypeScript
14 lines
641 B
TypeScript
import type { UserDoc } from './types.js';
|
|
|
|
/**
|
|
* Ported from imports/modules/get-email-of-user.js.
|
|
* Returns the recipient email only if verified. firstName from the profile.
|
|
* (The old code also consults an OAuth profile; for our channels the verified
|
|
* primary email is the operative case — OAuth users still carry emails[].)
|
|
*/
|
|
export function getEmailOf(user: UserDoc): { emailAddress: string | null; firstName: string } {
|
|
const firstName = user.profile?.name?.first ?? '';
|
|
const primary = user.emails?.[0];
|
|
const emailAddress = primary && primary.verified ? primary.address : null;
|
|
return { emailAddress, firstName };
|
|
}
|