Notifications
Multi-channel notification engine (email, web push, in-app) with a preference-aware dispatcher.
@halostack/notifications is the monorepo's notification engine. It can reach
users through three channels — email (Resend or nodemailer, rendered with
react-email), web push, and in-app messages persisted to @halostack/db —
all fronted by a single dispatcher that honors each user's per-channel
preferences. Application code asks the dispatcher to send a notification; the
dispatcher decides which channels are eligible and routes accordingly.
Importing
The package exposes a few subpaths, each scoped to a different need. Import the narrowest one that does the job.
The ./email subpath is deliberately db-free. That lets @halostack/auth (and
the test preload's mock.module) import the transactional senders without
pulling the database into scope.
Structure
The codebase splits along channels and notification kinds:
src/dispatcher.ts,src/channels.ts, and the per-channelchannel-email.ts/channel-web-push.ts/channel-in-app.tsfiles carry the routing and delivery logic.src/kinds.tsand thekind-*.tsfiles define the notification kinds, each with a typed payload.src/preferences.tsholds the per-user opt-in / opt-out matrix.src/email/containstransactional.ts,render.ts, andtransport.ts, alongside thetemplates/directory of react-email.tsxfiles, sharedcomponents/, and atheme.ts.
Conventions
A few things worth knowing before you extend the package:
- This package's
tsconfigenables JSX, because it renders react-email on the server. - You can preview the email templates locally with
bun run --filter @halostack/notifications dev:email, which serves them on port 3333. - Validate notification payloads with Zod, and read all transport
configuration through
@halostack/envrather thanprocess.env.