@core-tecnologias-empresariales/core-notifications
v0.1.0
Published
Notificaciones desacopladas de canal (Email, In-App, futuros Push/SMS) para el ecosistema Core Tecnología Empresarial.
Readme
@core-tecnologias-empresariales/core-notifications
Notificaciones del ecosistema Core Tecnología Empresarial. Separa Notification (el evento) de Channel (por dónde se entrega) — CLAUDE.md §15.
API
import { dispatchNotification, createEmailChannel, createInAppChannel } from "@core-tecnologias-empresariales/core-notifications";
import { createMailer, createSmtpTransport } from "@core-tecnologias-empresariales/core-mail";
const mailer = createMailer([createSmtpTransport({ name: "principal", host: "smtp.example.com", port: 587 })]);
const emailChannel = createEmailChannel({
mailer,
from: "[email protected]",
resolveEmail: (userId) => lookupEmail(userId), // tu propia resolución
});
const inAppChannel = createInAppChannel({
save: (userId, notification) => db.inAppNotifications.insert({ userId, ...notification }),
});
const results = await dispatchNotification({
notification: { id: "n1", userId: "u1", type: "sale_created", title: "Venta registrada", body: "Venta #83921 creada" },
channels: [emailChannel, inAppChannel],
isChannelEnabled: (userId, channel) => getUserPreferences(userId).includes(channel),
});
// [{ channel: "email", outcome: "sent" }, { channel: "in-app", outcome: "sent" }]Un canal que falla se reporta como { outcome: "failed", error } — nunca bloquea a los demás ni lanza. Sin isChannelEnabled, todos los canales se consideran habilitados.
Canales incluidos
- Email (
createEmailChannel) — sobrecore-mail. Usatitle/bodyde la notificación por defecto; aceptarenderSubject/renderHtmlpara personalizar sin construir un motor de templates completo. - In-App (
createInAppChannel) — delega la persistencia alstoreinyectado (regla "no core-database": cada producto guarda sus notificaciones in-app donde quiera).
Para qué NO sirve todavía (ponytail: diferido)
Push y SMS quedan preparados por el NotificationChannel interface pero sin implementación — se agregan cuando haya un proveedor real elegido. Programación (scheduled) e idioma/i18n de la notificación tampoco están en v0.1: se integran con core-jobs y core-i18n respectivamente cuando exista el caso concreto.
Instalación
pnpm add @core-tecnologias-empresariales/core-notificationsDesarrollo
pnpm build
pnpm test