@feathers-baas/plugin-notifications 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @feathers-baas/plugin-notifications
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4d99238: Fix BullMQ startup crash and make auth email links configurable (#6, #7).
8
+ - The queue is now named `feathers-baas-notifications` with BullMQ `prefix: 'feathers-baas'` (exported as `NOTIFICATION_QUEUE_PREFIX`). bullmq ≥ 5 rejects `:` in queue names, so the old name crashed the app at startup whenever `REDIS_URL` and an email driver were both set. Queue and worker use the same name and prefix.
9
+ - Notifier options accept `paths` (`verify`, `resetPassword`, `verifySetPassword`), `verifyDelay` / `resetDelay`, and a `buildNotification` override. `buildAuthNotification` and `formatDuration` are exported so apps can wrap the default emails.
10
+ - The "link expires in…" copy is derived from the configured token lifetimes (the verification email used to say 24 hours while tokens lived 5 days).
11
+
12
+ ## 0.2.1
13
+
14
+ ### Patch Changes
15
+
16
+ - Add README for each package, update AGENTS.md template, fix MongoDB auth entityId, and add timestamp hooks for consistent createdAt/updatedAt across all databases
17
+
3
18
  ## 0.2.0
4
19
 
5
20
  ### Minor Changes
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # @feathers-baas/plugin-notifications
2
+
3
+ Notification plugin for [feathers-baas](https://github.com/anthropics/feathers-baas) — BullMQ-backed email delivery with SMTP, Resend, SendGrid, and Brevo drivers.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @feathers-baas/plugin-notifications
9
+ ```
10
+
11
+ ## How it works
12
+
13
+ Auth events (verify email, reset password, etc.) are routed through the notification system. Two delivery modes:
14
+
15
+ - **Direct mode** (no Redis) — drivers called synchronously in the request path. Suitable for development and API-based drivers.
16
+ - **Queue mode** (with Redis) — jobs enqueued in BullMQ with automatic retries and exponential backoff. Best for production.
17
+
18
+ If no driver env vars are configured, auth events are logged to console.
19
+
20
+ ## Setup
21
+
22
+ Add driver env vars to `.env`:
23
+
24
+ ```env
25
+ # Pick one (or more):
26
+
27
+ # SMTP
28
+ SMTP_URL=smtp://user:pass@localhost:1025
29
+ SMTP_FROM_NAME=My App
30
+ SMTP_FROM_ADDRESS=no-reply@example.com
31
+
32
+ # Resend
33
+ RESEND_API_KEY=re_xxxxxxxxxxxx
34
+ RESEND_FROM_NAME=My App
35
+ RESEND_FROM_ADDRESS=no-reply@yourdomain.com
36
+
37
+ # SendGrid
38
+ SENDGRID_API_KEY=SG.xxxxxxxxxxxx
39
+ SENDGRID_FROM_NAME=My App
40
+ SENDGRID_FROM_ADDRESS=no-reply@yourdomain.com
41
+
42
+ # Brevo
43
+ BREVO_API_KEY=xkeysib-xxxxxxxxxxxx
44
+ BREVO_FROM_NAME=My App
45
+ BREVO_FROM_ADDRESS=no-reply@yourdomain.com
46
+ ```
47
+
48
+ For queue mode, add Redis:
49
+
50
+ ```env
51
+ REDIS_URL=redis://localhost:6379
52
+ ```
53
+
54
+ No code changes needed — `@feathers-baas/core` auto-configures drivers from env vars.
55
+
56
+ ## Email drivers
57
+
58
+ | Driver | Class | Env var | Use case |
59
+ |----------|-----------------|--------------------|-----------------------------------|
60
+ | SMTP | `SMTPDriver` | `SMTP_URL` | Self-hosted SMTP, Mailtrap |
61
+ | Resend | `ResendDriver` | `RESEND_API_KEY` | Managed transactional email |
62
+ | SendGrid | `SendGridDriver`| `SENDGRID_API_KEY` | Twilio SendGrid |
63
+ | Brevo | `BrevoDriver` | `BREVO_API_KEY` | Brevo (formerly Sendinblue) |
64
+
65
+ All configured drivers are active simultaneously.
66
+
67
+ ## Auth events handled automatically
68
+
69
+ | Event | Trigger |
70
+ |--------------------|----------------------------|
71
+ | Verify email | User registers |
72
+ | Resend verification| User requests re-send |
73
+ | Reset password | User requests reset |
74
+ | Password changed | After successful reset |
75
+ | Email change | Identity change request |
76
+
77
+ ## Exports
78
+
79
+ ```ts
80
+ // Drivers
81
+ import { SMTPDriver, ResendDriver, SendGridDriver, BrevoDriver } from '@feathers-baas/plugin-notifications'
82
+
83
+ // Driver registry
84
+ import { DriverRegistry } from '@feathers-baas/plugin-notifications'
85
+
86
+ // Notifier factories
87
+ import { createBullMQNotifier, createDirectNotifier } from '@feathers-baas/plugin-notifications'
88
+
89
+ // Queue utilities
90
+ import { createNotificationQueue, createNotificationWorker } from '@feathers-baas/plugin-notifications'
91
+ ```
92
+
93
+ ## Plugin interface
94
+
95
+ This package exports a `FeathersBaasPlugin` default export and is auto-discovered by `@feathers-baas/core` when listed as a dependency. Drivers are configured automatically from env vars by core's `configureNotifications()`.
96
+
97
+ ## License
98
+
99
+ MIT
package/dist/index.cjs CHANGED
@@ -33,15 +33,18 @@ __export(index_exports, {
33
33
  BrevoDriver: () => BrevoDriver,
34
34
  DriverRegistry: () => DriverRegistry,
35
35
  NOTIFICATION_QUEUE_NAME: () => NOTIFICATION_QUEUE_NAME,
36
+ NOTIFICATION_QUEUE_PREFIX: () => NOTIFICATION_QUEUE_PREFIX,
36
37
  ResendDriver: () => ResendDriver,
37
38
  SMTPDriver: () => SMTPDriver,
38
39
  SendGridDriver: () => SendGridDriver,
40
+ buildAuthNotification: () => buildAuthNotification,
39
41
  createBullMQNotifier: () => createBullMQNotifier,
40
42
  createDirectNotifier: () => createDirectNotifier,
41
43
  createNotificationQueue: () => createNotificationQueue,
42
44
  createNotificationWorker: () => createNotificationWorker,
43
45
  default: () => index_default,
44
- enqueueNotification: () => enqueueNotification
46
+ enqueueNotification: () => enqueueNotification,
47
+ formatDuration: () => formatDuration
45
48
  });
46
49
  module.exports = __toCommonJS(index_exports);
47
50
  var import_node_module = require("module");
@@ -78,10 +81,12 @@ var DriverRegistry = class {
78
81
 
79
82
  // src/queue/producer.ts
80
83
  var import_bullmq = require("bullmq");
81
- var NOTIFICATION_QUEUE_NAME = "feathers-baas:notifications";
84
+ var NOTIFICATION_QUEUE_NAME = "feathers-baas-notifications";
85
+ var NOTIFICATION_QUEUE_PREFIX = "feathers-baas";
82
86
  function createNotificationQueue(redis) {
83
87
  return new import_bullmq.Queue(NOTIFICATION_QUEUE_NAME, {
84
88
  connection: redis,
89
+ prefix: NOTIFICATION_QUEUE_PREFIX,
85
90
  defaultJobOptions: {
86
91
  attempts: 5,
87
92
  backoff: {
@@ -108,14 +113,39 @@ var AUTH_MANAGEMENT_EVENT_MAP = {
108
113
  passwordChange: "auth.password-change",
109
114
  identityChange: "auth.identity-change"
110
115
  };
111
- function buildAuthNotification(type, user, appUrl) {
116
+ var DEFAULT_VERIFY_DELAY_MS = 1e3 * 60 * 60 * 24 * 5;
117
+ var DEFAULT_RESET_DELAY_MS = 1e3 * 60 * 60 * 2;
118
+ function formatDuration(ms) {
119
+ const units = [
120
+ ["day", 864e5],
121
+ ["hour", 36e5],
122
+ ["minute", 6e4]
123
+ ];
124
+ for (const [name, size] of units) {
125
+ if (ms >= size && ms % size === 0) {
126
+ const n = ms / size;
127
+ return `${n} ${name}${n === 1 ? "" : "s"}`;
128
+ }
129
+ }
130
+ const minutes = Math.max(1, Math.round(ms / 6e4));
131
+ return `${minutes} minute${minutes === 1 ? "" : "s"}`;
132
+ }
133
+ function buildLink(appUrl, path, token) {
134
+ const base = appUrl.replace(/\/+$/, "");
135
+ const route = path.startsWith("/") ? path : `/${path}`;
136
+ return `${base}${route}?token=${encodeURIComponent(token ?? "")}`;
137
+ }
138
+ function buildAuthNotification(type, user, opts) {
139
+ const { appUrl, paths = {} } = opts;
140
+ const verifyExpiry = formatDuration(opts.verifyDelay ?? DEFAULT_VERIFY_DELAY_MS);
141
+ const resetExpiry = formatDuration(opts.resetDelay ?? DEFAULT_RESET_DELAY_MS);
112
142
  const email = user["email"];
113
143
  if (!email) return null;
114
144
  switch (type) {
115
145
  case "auth.verify-signup":
116
146
  case "auth.resend-verify-signup": {
117
147
  const token = user["verifyToken"];
118
- const verifyUrl = `${appUrl}/verify?token=${token ?? ""}`;
148
+ const verifyUrl = buildLink(appUrl, paths.verify ?? "/verify", token);
119
149
  return {
120
150
  to: email,
121
151
  channel: "email",
@@ -124,15 +154,15 @@ function buildAuthNotification(type, user, appUrl) {
124
154
  <h2>Welcome!</h2>
125
155
  <p>Click the link below to verify your email address:</p>
126
156
  <p><a href="<%= verifyUrl %>">Verify email</a></p>
127
- <p>This link expires in 24 hours.</p>
157
+ <p>This link expires in <%= expiresIn %>.</p>
128
158
  `,
129
159
  textTemplate: `Verify your email: <%= verifyUrl %>`,
130
- data: { verifyUrl, user }
160
+ data: { verifyUrl, expiresIn: verifyExpiry, user }
131
161
  };
132
162
  }
133
163
  case "auth.send-reset-pwd": {
134
164
  const token = user["resetToken"];
135
- const resetUrl = `${appUrl}/reset-password?token=${token ?? ""}`;
165
+ const resetUrl = buildLink(appUrl, paths.resetPassword ?? "/reset-password", token);
136
166
  return {
137
167
  to: email,
138
168
  channel: "email",
@@ -141,10 +171,10 @@ function buildAuthNotification(type, user, appUrl) {
141
171
  <h2>Password reset requested</h2>
142
172
  <p>Click the link below to reset your password:</p>
143
173
  <p><a href="<%= resetUrl %>">Reset password</a></p>
144
- <p>This link expires in 2 hours. If you did not request this, ignore this email.</p>
174
+ <p>This link expires in <%= expiresIn %>. If you did not request this, ignore this email.</p>
145
175
  `,
146
176
  textTemplate: `Reset your password: <%= resetUrl %>`,
147
- data: { resetUrl, user }
177
+ data: { resetUrl, expiresIn: resetExpiry, user }
148
178
  };
149
179
  }
150
180
  case "auth.reset-pwd": {
@@ -179,7 +209,7 @@ function buildAuthNotification(type, user, appUrl) {
179
209
  }
180
210
  case "auth.verify-signup-set-password": {
181
211
  const token = user["verifyToken"];
182
- const verifyUrl = `${appUrl}/verify-set-password?token=${token ?? ""}`;
212
+ const verifyUrl = buildLink(appUrl, paths.verifySetPassword ?? "/verify-set-password", token);
183
213
  return {
184
214
  to: email,
185
215
  channel: "email",
@@ -198,7 +228,7 @@ function createDirectNotifier(opts) {
198
228
  return async (type, user, _notifierOptions) => {
199
229
  const eventKey = AUTH_MANAGEMENT_EVENT_MAP[type];
200
230
  if (!eventKey) return;
201
- const notification = buildAuthNotification(eventKey, user, opts.appUrl);
231
+ const notification = (opts.buildNotification ?? buildAuthNotification)(eventKey, user, opts);
202
232
  if (!notification) return;
203
233
  const driverNames = opts.registry.getDriversForEvent(eventKey);
204
234
  if (driverNames.length === 0) return;
@@ -215,7 +245,7 @@ function createBullMQNotifier(opts) {
215
245
  return async (type, user, _notifierOptions) => {
216
246
  const eventKey = AUTH_MANAGEMENT_EVENT_MAP[type];
217
247
  if (!eventKey) return;
218
- const notification = buildAuthNotification(eventKey, user, opts.appUrl);
248
+ const notification = (opts.buildNotification ?? buildAuthNotification)(eventKey, user, opts);
219
249
  if (!notification) return;
220
250
  const driverNames = opts.registry.getDriversForEvent(eventKey);
221
251
  if (driverNames.length === 0) return;
@@ -243,6 +273,8 @@ function createNotificationWorker(registry, redis, opts = {}) {
243
273
  },
244
274
  {
245
275
  connection: redis,
276
+ // Must match the producer, or jobs are enqueued where the worker isn't listening
277
+ prefix: NOTIFICATION_QUEUE_PREFIX,
246
278
  concurrency,
247
279
  // Don't create a new redis connection per job — reuse the pool
248
280
  autorun: true
@@ -382,13 +414,16 @@ var index_default = plugin;
382
414
  BrevoDriver,
383
415
  DriverRegistry,
384
416
  NOTIFICATION_QUEUE_NAME,
417
+ NOTIFICATION_QUEUE_PREFIX,
385
418
  ResendDriver,
386
419
  SMTPDriver,
387
420
  SendGridDriver,
421
+ buildAuthNotification,
388
422
  createBullMQNotifier,
389
423
  createDirectNotifier,
390
424
  createNotificationQueue,
391
425
  createNotificationWorker,
392
- enqueueNotification
426
+ enqueueNotification,
427
+ formatDuration
393
428
  });
394
429
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/registry.ts","../src/queue/producer.ts","../src/notifier.ts","../src/queue/worker.ts","../src/drivers/smtp.driver.ts","../src/drivers/resend.driver.ts","../src/drivers/sendgrid.driver.ts","../src/drivers/brevo.driver.ts"],"sourcesContent":["// Generated by feathers-baas. Safe to edit.\nimport { createRequire } from 'node:module'\nimport type { FeathersBaasPlugin } from './plugin.js'\n\nconst pkg = createRequire(import.meta.url)('../package.json') as { version: string }\n\nconst plugin: FeathersBaasPlugin = {\n name: '@feathers-baas/plugin-notifications',\n version: pkg.version,\n async install(_app, _options) {\n // Notification drivers are configured via core's configureNotifications()\n // based on env vars. Auto-install is a no-op; discovery confirms the plugin is present.\n },\n}\n\nexport default plugin\n\nexport { DriverRegistry } from './registry.js'\nexport { createBullMQNotifier, createDirectNotifier } from './notifier.js'\nexport type { NotifierFn, BullMQNotifierOptions, DirectNotifierOptions } from './notifier.js'\n\n// Queue\nexport { createNotificationQueue, enqueueNotification, NOTIFICATION_QUEUE_NAME } from './queue/producer.js'\nexport { createNotificationWorker } from './queue/worker.js'\nexport type { WorkerOptions } from './queue/worker.js'\n\n// Drivers\nexport { SMTPDriver } from './drivers/smtp.driver.js'\nexport type { SMTPDriverOptions } from './drivers/smtp.driver.js'\nexport { ResendDriver } from './drivers/resend.driver.js'\nexport type { ResendDriverOptions } from './drivers/resend.driver.js'\nexport { SendGridDriver } from './drivers/sendgrid.driver.js'\nexport type { SendGridDriverOptions } from './drivers/sendgrid.driver.js'\nexport { BrevoDriver } from './drivers/brevo.driver.js'\nexport type { BrevoDriverOptions } from './drivers/brevo.driver.js'\n\n// Types\nexport type {\n Notification,\n NotifierDriver,\n NotificationJob,\n NotificationEvent,\n AuthNotificationEvent,\n} from './types.js'\n","// Generated by feathers-baas. Safe to edit.\nimport type { NotifierDriver, NotificationEvent } from './types.js'\n\n/**\n * DriverRegistry maps event keys to the list of drivers that should handle\n * that event.\n *\n * A single driver instance can handle multiple events (e.g. the SMTP driver\n * handles all auth.* email events).\n *\n * @example\n * ```ts\n * const registry = new DriverRegistry()\n * registry.registerDriver(smtpDriver)\n * registry.mapEvent('auth.verify-signup', 'smtp')\n * registry.mapEvent('auth.send-reset-pwd', 'smtp')\n * ```\n */\nexport class DriverRegistry {\n private readonly drivers = new Map<string, NotifierDriver>()\n private readonly eventMap = new Map<NotificationEvent, string[]>()\n\n /** Register a driver under its name. Overwrites any existing driver with the same name. */\n registerDriver(driver: NotifierDriver): void {\n this.drivers.set(driver.name, driver)\n }\n\n /** Map a notification event to a driver name. Multiple calls for the same event add drivers. */\n mapEvent(event: NotificationEvent, driverName: string): void {\n const existing = this.eventMap.get(event) ?? []\n if (!existing.includes(driverName)) {\n existing.push(driverName)\n }\n this.eventMap.set(event, existing)\n }\n\n /** Look up a driver by name. Returns undefined if not registered. */\n getDriver(name: string): NotifierDriver | undefined {\n return this.drivers.get(name)\n }\n\n /** Get all driver names mapped to the given event. */\n getDriversForEvent(event: NotificationEvent): string[] {\n return this.eventMap.get(event) ?? []\n }\n\n /** All registered driver names. */\n listDriverNames(): string[] {\n return [...this.drivers.keys()]\n }\n}\n","// Generated by feathers-baas. Safe to edit.\nimport { Queue } from 'bullmq'\nimport type { Redis } from 'ioredis'\nimport type { NotificationJob } from '../types.js'\n\nexport const NOTIFICATION_QUEUE_NAME = 'feathers-baas:notifications'\n\n/**\n * Create a BullMQ Queue instance for notification jobs.\n *\n * @example\n * ```ts\n * const redis = new Redis(process.env.REDIS_URL)\n * const queue = createNotificationQueue(redis)\n * await enqueueNotification(queue, { driverName: 'smtp', notification: { ... } })\n * ```\n */\nexport function createNotificationQueue(redis: Redis): Queue<NotificationJob> {\n return new Queue<NotificationJob>(NOTIFICATION_QUEUE_NAME, {\n connection: redis,\n defaultJobOptions: {\n attempts: 5,\n backoff: {\n type: 'exponential',\n delay: 1_000, // initial delay: 1s → 2s → 4s → 8s → 16s\n },\n removeOnComplete: { count: 100 },\n removeOnFail: { count: 500 },\n },\n })\n}\n\n/**\n * Enqueue a notification job.\n *\n * @param queue BullMQ Queue instance from createNotificationQueue()\n * @param job Job payload { driverName, notification }\n */\nexport async function enqueueNotification(\n queue: Queue<NotificationJob>,\n job: NotificationJob,\n): Promise<void> {\n await queue.add('send', job)\n}\n","// Generated by feathers-baas. Safe to edit.\nimport type { Queue } from 'bullmq'\nimport type { NotificationJob, Notification, AuthNotificationEvent } from './types.js'\nimport { enqueueNotification } from './queue/producer.js'\nimport type { DriverRegistry } from './registry.js'\n\n/**\n * Auth-management notification types mapped to feathers-baas event keys.\n * feathers-authentication-management passes these type strings to the notifier.\n */\nconst AUTH_MANAGEMENT_EVENT_MAP: Record<string, AuthNotificationEvent> = {\n resendVerifySignup: 'auth.resend-verify-signup',\n verifySignup: 'auth.verify-signup',\n verifySignupSetPassword: 'auth.verify-signup-set-password',\n sendResetPwd: 'auth.send-reset-pwd',\n resetPwd: 'auth.reset-pwd',\n passwordChange: 'auth.password-change',\n identityChange: 'auth.identity-change',\n}\n\n/**\n * Build a default Notification payload for each auth event type.\n * Templates use EJS — `<%= variable %>` for output, `<% code %>` for logic.\n */\nfunction buildAuthNotification(\n type: AuthNotificationEvent,\n user: Record<string, unknown>,\n appUrl: string,\n): Notification | null {\n const email = user['email'] as string\n if (!email) return null\n\n switch (type) {\n case 'auth.verify-signup':\n case 'auth.resend-verify-signup': {\n const token = user['verifyToken'] as string | undefined\n const verifyUrl = `${appUrl}/verify?token=${token ?? ''}`\n return {\n to: email,\n channel: 'email',\n subject: 'Verify your email address',\n bodyTemplate: `\n <h2>Welcome!</h2>\n <p>Click the link below to verify your email address:</p>\n <p><a href=\"<%= verifyUrl %>\">Verify email</a></p>\n <p>This link expires in 24 hours.</p>\n `,\n textTemplate: `Verify your email: <%= verifyUrl %>`,\n data: { verifyUrl, user },\n }\n }\n\n case 'auth.send-reset-pwd': {\n const token = user['resetToken'] as string | undefined\n const resetUrl = `${appUrl}/reset-password?token=${token ?? ''}`\n return {\n to: email,\n channel: 'email',\n subject: 'Reset your password',\n bodyTemplate: `\n <h2>Password reset requested</h2>\n <p>Click the link below to reset your password:</p>\n <p><a href=\"<%= resetUrl %>\">Reset password</a></p>\n <p>This link expires in 2 hours. If you did not request this, ignore this email.</p>\n `,\n textTemplate: `Reset your password: <%= resetUrl %>`,\n data: { resetUrl, user },\n }\n }\n\n case 'auth.reset-pwd': {\n return {\n to: email,\n channel: 'email',\n subject: 'Your password has been reset',\n bodyTemplate: `<p>Your password has been successfully reset. If you did not do this, please contact support immediately.</p>`,\n textTemplate: `Your password has been reset. If you did not do this, please contact support.`,\n data: { user },\n }\n }\n\n case 'auth.password-change': {\n return {\n to: email,\n channel: 'email',\n subject: 'Your password has been changed',\n bodyTemplate: `<p>Your account password was just changed. If this was not you, please contact support immediately.</p>`,\n textTemplate: `Your password was changed. Contact support if this wasn't you.`,\n data: { user },\n }\n }\n\n case 'auth.identity-change': {\n return {\n to: email,\n channel: 'email',\n subject: 'Your email address is being changed',\n bodyTemplate: `<p>A request was made to change your email address. Click the link to confirm.</p>`,\n textTemplate: `Confirm your email change by clicking the link in the HTML email.`,\n data: { user },\n }\n }\n\n case 'auth.verify-signup-set-password': {\n const token = user['verifyToken'] as string | undefined\n const verifyUrl = `${appUrl}/verify-set-password?token=${token ?? ''}`\n return {\n to: email,\n channel: 'email',\n subject: 'Set your password',\n bodyTemplate: `\n <h2>Set your password</h2>\n <p><a href=\"<%= verifyUrl %>\">Set password</a></p>\n `,\n textTemplate: `Set your password: <%= verifyUrl %>`,\n data: { verifyUrl, user },\n }\n }\n }\n}\n\nexport type NotifierFn = (\n type: string,\n user: Record<string, unknown>,\n notifierOptions: Record<string, unknown>,\n) => Promise<void>\n\nexport interface BullMQNotifierOptions {\n /** BullMQ Queue instance — from createNotificationQueue(). */\n queue: Queue<NotificationJob>\n /** Driver registry — used to determine which drivers handle each event. */\n registry: DriverRegistry\n /**\n * Public base URL of the app, e.g. https://api.example.com\n * Used to construct verification / reset URLs in email templates.\n */\n appUrl: string\n}\n\n/**\n * Create a notifier function compatible with feathers-authentication-management.\n *\n * When an auth event fires (verifySignup, sendResetPwd, etc.), this notifier:\n * 1. Maps the event type to a feathers-baas notification event key\n * 2. Looks up all registered drivers for that event\n * 3. Enqueues one BullMQ job per driver\n * 4. Returns immediately — delivery is asynchronous\n *\n * Wire into the app:\n * ```ts\n * app.set('notifier', createBullMQNotifier({ queue, registry, appUrl }))\n * ```\n */\nexport interface DirectNotifierOptions {\n /** Driver registry — used to determine which drivers handle each event. */\n registry: DriverRegistry\n /** Public base URL of the app. */\n appUrl: string\n}\n\n/**\n * Create a notifier that sends notifications directly via the driver (no queue).\n * Use this when Redis/BullMQ is not available — suitable for API-based drivers\n * (Brevo, Resend, SendGrid) in development or low-traffic environments.\n */\nexport function createDirectNotifier(opts: DirectNotifierOptions): NotifierFn {\n return async (type, user, _notifierOptions) => {\n const eventKey = AUTH_MANAGEMENT_EVENT_MAP[type]\n if (!eventKey) return\n\n const notification = buildAuthNotification(eventKey, user, opts.appUrl)\n if (!notification) return\n\n const driverNames = opts.registry.getDriversForEvent(eventKey)\n if (driverNames.length === 0) return\n\n await Promise.all(\n driverNames.map(async (driverName) => {\n const driver = opts.registry.getDriver(driverName)\n if (!driver) return\n await driver.send(notification)\n }),\n )\n }\n}\n\nexport function createBullMQNotifier(opts: BullMQNotifierOptions): NotifierFn {\n return async (type, user, _notifierOptions) => {\n const eventKey = AUTH_MANAGEMENT_EVENT_MAP[type]\n if (!eventKey) return // Unknown event type — no-op\n\n const notification = buildAuthNotification(eventKey, user, opts.appUrl)\n if (!notification) return // Missing required user fields — no-op\n\n const driverNames = opts.registry.getDriversForEvent(eventKey)\n if (driverNames.length === 0) return // No drivers configured for this event\n\n await Promise.all(\n driverNames.map((driverName) =>\n enqueueNotification(opts.queue, { driverName, notification }),\n ),\n )\n }\n}\n","// Generated by feathers-baas. Safe to edit.\nimport { Worker } from 'bullmq'\nimport type { Redis } from 'ioredis'\nimport type { DriverRegistry } from '../registry.js'\nimport type { NotificationJob } from '../types.js'\nimport { NOTIFICATION_QUEUE_NAME } from './producer.js'\n\nexport interface WorkerOptions {\n /** BullMQ concurrency — number of jobs processed in parallel. */\n concurrency?: number\n}\n\n/**\n * Create and start the BullMQ worker that processes notification jobs.\n *\n * The worker looks up the driver from the registry by name, renders the\n * EJS template, and calls driver.send(). BullMQ handles retries with\n * exponential back-off automatically.\n *\n * Call worker.close() during graceful shutdown to drain in-flight jobs.\n *\n * @example\n * ```ts\n * const worker = createNotificationWorker(registry, redis, { concurrency: 5 })\n *\n * process.on('SIGTERM', async () => {\n * await worker.close()\n * })\n * ```\n */\nexport function createNotificationWorker(\n registry: DriverRegistry,\n redis: Redis,\n opts: WorkerOptions = {},\n): Worker<NotificationJob> {\n const concurrency = opts.concurrency ?? 5\n\n const worker = new Worker<NotificationJob>(\n NOTIFICATION_QUEUE_NAME,\n async (job) => {\n const { driverName, notification } = job.data\n\n const driver = registry.getDriver(driverName)\n if (!driver) {\n throw new Error(`Notification driver \"${driverName}\" is not registered`)\n }\n\n await driver.send(notification)\n },\n {\n connection: redis,\n concurrency,\n // Don't create a new redis connection per job — reuse the pool\n autorun: true,\n },\n )\n\n worker.on('failed', (job, err) => {\n // BullMQ handles retries; this is just for observability\n const jobId = job?.id ?? 'unknown'\n const message = err instanceof Error ? err.message : String(err)\n console.error(`[notifications] Job ${jobId} failed: ${message}`)\n })\n\n return worker\n}\n","// Generated by feathers-baas. Safe to edit.\nimport nodemailer from 'nodemailer'\nimport * as ejs from 'ejs'\nimport type { NotifierDriver, Notification } from '../types.js'\n\n// ejs is a CommonJS module — alias the render function defensively\nconst ejsRender = (ejs as unknown as { render?: typeof ejs.render }).render ?? ejs.render\n\nexport interface SMTPDriverOptions {\n /** SMTP connection URL, e.g. smtp://user:pass@mail.example.com:587 */\n url: string\n /** Display name shown in the From field. */\n fromName: string\n /** Email address shown in the From field. */\n fromAddress: string\n}\n\n/**\n * Email driver backed by nodemailer over SMTP.\n * Templates are rendered with EJS at send time.\n *\n * Use this driver for self-hosted SMTP servers (Postfix, Mailtrap, etc.).\n * For transactional email services, prefer ResendDriver.\n */\nexport class SMTPDriver implements NotifierDriver {\n readonly name = 'smtp'\n\n private readonly transporter: nodemailer.Transporter\n\n constructor(private readonly opts: SMTPDriverOptions) {\n this.transporter = nodemailer.createTransport(opts.url)\n }\n\n async send(notification: Notification): Promise<void> {\n const html = ejsRender(notification.bodyTemplate, notification.data, { async: false })\n const text = notification.textTemplate\n ? ejsRender(notification.textTemplate, notification.data, { async: false })\n : undefined\n\n await this.transporter.sendMail({\n from: `\"${this.opts.fromName}\" <${this.opts.fromAddress}>`,\n to: notification.to,\n subject: notification.subject ?? '(no subject)',\n html,\n text,\n })\n }\n\n /** Verify SMTP connectivity. Throws if the server is unreachable. */\n async verify(): Promise<void> {\n await this.transporter.verify()\n }\n\n /** Close the underlying connection pool. */\n close(): void {\n this.transporter.close()\n }\n}\n","// Generated by feathers-baas. Safe to edit.\nimport { Resend } from 'resend'\nimport * as ejs from 'ejs'\nimport type { NotifierDriver, Notification } from '../types.js'\n\nconst ejsRender = (ejs as unknown as { render?: typeof ejs.render }).render ?? ejs.render\n\nexport interface ResendDriverOptions {\n /** Resend API key (from https://resend.com/api-keys). */\n apiKey: string\n /** Display name shown in the From field. */\n fromName: string\n /** Verified sender address. Must be a verified domain in your Resend account. */\n fromAddress: string\n}\n\n/**\n * Email driver backed by the Resend transactional email API.\n * Templates are rendered with EJS at send time.\n *\n * Resend offers generous free tier and excellent deliverability,\n * making it the recommended choice for new projects.\n */\nexport class ResendDriver implements NotifierDriver {\n readonly name = 'resend'\n\n private readonly client: Resend\n\n constructor(private readonly opts: ResendDriverOptions) {\n this.client = new Resend(opts.apiKey)\n }\n\n async send(notification: Notification): Promise<void> {\n const html = ejsRender(notification.bodyTemplate, notification.data, { async: false })\n const text = notification.textTemplate\n ? ejsRender(notification.textTemplate, notification.data, { async: false })\n : undefined\n\n const result = await this.client.emails.send({\n from: `${this.opts.fromName} <${this.opts.fromAddress}>`,\n to: [notification.to],\n subject: notification.subject ?? '(no subject)',\n html,\n text,\n })\n\n if ('error' in result && result.error) {\n throw new Error(`Resend error: ${result.error.message}`)\n }\n }\n}\n","// Generated by feathers-baas. Safe to edit.\nimport sgMail from '@sendgrid/mail'\nimport * as ejs from 'ejs'\nimport type { NotifierDriver, Notification } from '../types.js'\n\n// ejs is a CommonJS module — alias the render function defensively\nconst ejsRender = (ejs as unknown as { render?: typeof ejs.render }).render ?? ejs.render\n\nexport interface SendGridDriverOptions {\n /** SendGrid API key (from https://app.sendgrid.com/settings/api_keys). */\n apiKey: string\n /** Display name shown in the From field. */\n fromName: string\n /** Verified sender address. Must be verified in your SendGrid account. */\n fromAddress: string\n}\n\n/**\n * Email driver backed by the SendGrid API.\n * Templates are rendered with EJS at send time.\n */\nexport class SendGridDriver implements NotifierDriver {\n readonly name = 'sendgrid'\n\n constructor(private readonly opts: SendGridDriverOptions) {\n sgMail.setApiKey(opts.apiKey)\n }\n\n async send(notification: Notification): Promise<void> {\n const html = ejsRender(notification.bodyTemplate, notification.data, { async: false })\n const text = notification.textTemplate\n ? ejsRender(notification.textTemplate, notification.data, { async: false })\n : undefined\n\n await sgMail.send({\n from: { name: this.opts.fromName, email: this.opts.fromAddress },\n to: notification.to,\n subject: notification.subject ?? '(no subject)',\n html,\n ...(text ? { text } : {}),\n })\n }\n}\n","// Generated by feathers-baas. Safe to edit.\nimport { TransactionalEmailsApi, TransactionalEmailsApiApiKeys, SendSmtpEmail } from '@getbrevo/brevo'\nimport * as ejs from 'ejs'\nimport type { NotifierDriver, Notification } from '../types.js'\n\n// ejs is a CommonJS module — alias the render function defensively\nconst ejsRender = (ejs as unknown as { render?: typeof ejs.render }).render ?? ejs.render\n\nexport interface BrevoDriverOptions {\n /** Brevo API key (from https://app.brevo.com/settings/keys/api). */\n apiKey: string\n /** Display name shown in the From field. */\n fromName: string\n /** Verified sender address. Must be verified in your Brevo account. */\n fromAddress: string\n}\n\n/**\n * Email driver backed by the Brevo (formerly Sendinblue) Transactional Email API.\n * Templates are rendered with EJS at send time.\n */\nexport class BrevoDriver implements NotifierDriver {\n readonly name = 'brevo'\n\n private readonly apiInstance: TransactionalEmailsApi\n\n constructor(private readonly opts: BrevoDriverOptions) {\n this.apiInstance = new TransactionalEmailsApi()\n this.apiInstance.setApiKey(TransactionalEmailsApiApiKeys.apiKey, opts.apiKey)\n }\n\n async send(notification: Notification): Promise<void> {\n const html = ejsRender(notification.bodyTemplate, notification.data, { async: false })\n const text = notification.textTemplate\n ? ejsRender(notification.textTemplate, notification.data, { async: false })\n : undefined\n\n const email = new SendSmtpEmail()\n email.sender = { name: this.opts.fromName, email: this.opts.fromAddress }\n email.to = [{ email: notification.to }]\n email.subject = notification.subject ?? '(no subject)'\n email.htmlContent = html\n if (text) email.textContent = text\n\n await this.apiInstance.sendTransacEmail(email)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAA8B;;;ACiBvB,IAAM,iBAAN,MAAqB;AAAA,EACT,UAAU,oBAAI,IAA4B;AAAA,EAC1C,WAAW,oBAAI,IAAiC;AAAA;AAAA,EAGjE,eAAe,QAA8B;AAC3C,SAAK,QAAQ,IAAI,OAAO,MAAM,MAAM;AAAA,EACtC;AAAA;AAAA,EAGA,SAAS,OAA0B,YAA0B;AAC3D,UAAM,WAAW,KAAK,SAAS,IAAI,KAAK,KAAK,CAAC;AAC9C,QAAI,CAAC,SAAS,SAAS,UAAU,GAAG;AAClC,eAAS,KAAK,UAAU;AAAA,IAC1B;AACA,SAAK,SAAS,IAAI,OAAO,QAAQ;AAAA,EACnC;AAAA;AAAA,EAGA,UAAU,MAA0C;AAClD,WAAO,KAAK,QAAQ,IAAI,IAAI;AAAA,EAC9B;AAAA;AAAA,EAGA,mBAAmB,OAAoC;AACrD,WAAO,KAAK,SAAS,IAAI,KAAK,KAAK,CAAC;AAAA,EACtC;AAAA;AAAA,EAGA,kBAA4B;AAC1B,WAAO,CAAC,GAAG,KAAK,QAAQ,KAAK,CAAC;AAAA,EAChC;AACF;;;ACjDA,o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C;AAAA,EAOjB,MAAM,KAAK,cAA2C;AACpD,UAAM,OAAOA,WAAU,aAAa,cAAc,aAAa,MAAM,EAAE,OAAO,MAAM,CAAC;AACrF,UAAM,OAAO,aAAa,eACtBA,WAAU,aAAa,cAAc,aAAa,MAAM,EAAE,OAAO,MAAM,CAAC,IACxE;AAEJ,UAAM,QAAQ,IAAI,2BAAc;AAChC,UAAM,SAAS,EAAE,MAAM,KAAK,KAAK,UAAU,OAAO,KAAK,KAAK,YAAY;AACxE,UAAM,KAAK,CAAC,EAAE,OAAO,aAAa,GAAG,CAAC;AACtC,UAAM,UAAU,aAAa,WAAW;AACxC,UAAM,cAAc;AACpB,QAAI,KAAM,OAAM,cAAc;AAE9B,UAAM,KAAK,YAAY,iBAAiB,KAAK;AAAA,EAC/C;AACF;;;AR9CA;AAIA,IAAM,UAAM,kCAAc,YAAY,GAAG,EAAE,iBAAiB;AAE5D,IAAM,SAA6B;AAAA,EACjC,MAAM;AAAA,EACN,SAAS,IAAI;AAAA,EACb,MAAM,QAAQ,MAAM,UAAU;AAAA,EAG9B;AACF;AAEA,IAAO,gBAAQ;","names":["import_bullmq","nodemailer","ejs","ejsRender","ejs","ejsRender","sgMail","ejs","ejsRender"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/registry.ts","../src/queue/producer.ts","../src/notifier.ts","../src/queue/worker.ts","../src/drivers/smtp.driver.ts","../src/drivers/resend.driver.ts","../src/drivers/sendgrid.driver.ts","../src/drivers/brevo.driver.ts"],"sourcesContent":["// Generated by feathers-baas. Safe to edit.\nimport { createRequire } from 'node:module'\nimport type { FeathersBaasPlugin } from './plugin.js'\n\nconst pkg = createRequire(import.meta.url)('../package.json') as { version: string }\n\nconst plugin: FeathersBaasPlugin = {\n name: '@feathers-baas/plugin-notifications',\n version: pkg.version,\n async install(_app, _options) {\n // Notification drivers are configured via core's configureNotifications()\n // based on env vars. Auto-install is a no-op; discovery confirms the plugin is present.\n },\n}\n\nexport default plugin\n\nexport { DriverRegistry } from './registry.js'\nexport { createBullMQNotifier, createDirectNotifier, buildAuthNotification, formatDuration } from './notifier.js'\nexport type {\n NotifierFn,\n BullMQNotifierOptions,\n DirectNotifierOptions,\n AuthNotificationOptions,\n AuthNotificationBuilder,\n} from './notifier.js'\n\n// Queue\nexport {\n createNotificationQueue,\n enqueueNotification,\n NOTIFICATION_QUEUE_NAME,\n NOTIFICATION_QUEUE_PREFIX,\n} from './queue/producer.js'\nexport { createNotificationWorker } from './queue/worker.js'\nexport type { WorkerOptions } from './queue/worker.js'\n\n// Drivers\nexport { SMTPDriver } from './drivers/smtp.driver.js'\nexport type { SMTPDriverOptions } from './drivers/smtp.driver.js'\nexport { ResendDriver } from './drivers/resend.driver.js'\nexport type { ResendDriverOptions } from './drivers/resend.driver.js'\nexport { SendGridDriver } from './drivers/sendgrid.driver.js'\nexport type { SendGridDriverOptions } from './drivers/sendgrid.driver.js'\nexport { BrevoDriver } from './drivers/brevo.driver.js'\nexport type { BrevoDriverOptions } from './drivers/brevo.driver.js'\n\n// Types\nexport type {\n Notification,\n NotifierDriver,\n NotificationJob,\n NotificationEvent,\n AuthNotificationEvent,\n} from './types.js'\n","// Generated by feathers-baas. Safe to edit.\nimport type { NotifierDriver, NotificationEvent } from './types.js'\n\n/**\n * DriverRegistry maps event keys to the list of drivers that should handle\n * that event.\n *\n * A single driver instance can handle multiple events (e.g. the SMTP driver\n * handles all auth.* email events).\n *\n * @example\n * ```ts\n * const registry = new DriverRegistry()\n * registry.registerDriver(smtpDriver)\n * registry.mapEvent('auth.verify-signup', 'smtp')\n * registry.mapEvent('auth.send-reset-pwd', 'smtp')\n * ```\n */\nexport class DriverRegistry {\n private readonly drivers = new Map<string, NotifierDriver>()\n private readonly eventMap = new Map<NotificationEvent, string[]>()\n\n /** Register a driver under its name. Overwrites any existing driver with the same name. */\n registerDriver(driver: NotifierDriver): void {\n this.drivers.set(driver.name, driver)\n }\n\n /** Map a notification event to a driver name. Multiple calls for the same event add drivers. */\n mapEvent(event: NotificationEvent, driverName: string): void {\n const existing = this.eventMap.get(event) ?? []\n if (!existing.includes(driverName)) {\n existing.push(driverName)\n }\n this.eventMap.set(event, existing)\n }\n\n /** Look up a driver by name. Returns undefined if not registered. */\n getDriver(name: string): NotifierDriver | undefined {\n return this.drivers.get(name)\n }\n\n /** Get all driver names mapped to the given event. */\n getDriversForEvent(event: NotificationEvent): string[] {\n return this.eventMap.get(event) ?? []\n }\n\n /** All registered driver names. */\n listDriverNames(): string[] {\n return [...this.drivers.keys()]\n }\n}\n","// Generated by feathers-baas. Safe to edit.\nimport { Queue } from 'bullmq'\nimport type { Redis } from 'ioredis'\nimport type { NotificationJob } from '../types.js'\n\n// BullMQ rejects ':' in queue names — namespace with its `prefix` option instead.\nexport const NOTIFICATION_QUEUE_NAME = 'feathers-baas-notifications'\nexport const NOTIFICATION_QUEUE_PREFIX = 'feathers-baas'\n\n/**\n * Create a BullMQ Queue instance for notification jobs.\n *\n * @example\n * ```ts\n * const redis = new Redis(process.env.REDIS_URL)\n * const queue = createNotificationQueue(redis)\n * await enqueueNotification(queue, { driverName: 'smtp', notification: { ... } })\n * ```\n */\nexport function createNotificationQueue(redis: Redis): Queue<NotificationJob> {\n return new Queue<NotificationJob>(NOTIFICATION_QUEUE_NAME, {\n connection: redis,\n prefix: NOTIFICATION_QUEUE_PREFIX,\n defaultJobOptions: {\n attempts: 5,\n backoff: {\n type: 'exponential',\n delay: 1_000, // initial delay: 1s → 2s → 4s → 8s → 16s\n },\n removeOnComplete: { count: 100 },\n removeOnFail: { count: 500 },\n },\n })\n}\n\n/**\n * Enqueue a notification job.\n *\n * @param queue BullMQ Queue instance from createNotificationQueue()\n * @param job Job payload { driverName, notification }\n */\nexport async function enqueueNotification(\n queue: Queue<NotificationJob>,\n job: NotificationJob,\n): Promise<void> {\n await queue.add('send', job)\n}\n","// Generated by feathers-baas. Safe to edit.\nimport type { Queue } from 'bullmq'\nimport type { NotificationJob, Notification, AuthNotificationEvent } from './types.js'\nimport { enqueueNotification } from './queue/producer.js'\nimport type { DriverRegistry } from './registry.js'\n\n/**\n * Auth-management notification types mapped to feathers-baas event keys.\n * feathers-authentication-management passes these type strings to the notifier.\n */\nconst AUTH_MANAGEMENT_EVENT_MAP: Record<string, AuthNotificationEvent> = {\n resendVerifySignup: 'auth.resend-verify-signup',\n verifySignup: 'auth.verify-signup',\n verifySignupSetPassword: 'auth.verify-signup-set-password',\n sendResetPwd: 'auth.send-reset-pwd',\n resetPwd: 'auth.reset-pwd',\n passwordChange: 'auth.password-change',\n identityChange: 'auth.identity-change',\n}\n\n/** Defaults match feathers-authentication-management's own `delay` / `resetDelay`. */\nconst DEFAULT_VERIFY_DELAY_MS = 1000 * 60 * 60 * 24 * 5\nconst DEFAULT_RESET_DELAY_MS = 1000 * 60 * 60 * 2\n\nexport interface AuthNotificationOptions {\n /**\n * Public base URL of the **web app** that redeems the tokens (not this API),\n * e.g. https://app.example.com\n */\n appUrl: string\n /** Frontend routes the email links point to. */\n paths?: {\n /** Default: `/verify` */\n verify?: string\n /** Default: `/reset-password` */\n resetPassword?: string\n /** Default: `/verify-set-password` */\n verifySetPassword?: string\n }\n /** Verification token lifetime in ms — must match auth-management's `delay`. Default: 5 days. */\n verifyDelay?: number\n /** Reset token lifetime in ms — must match auth-management's `resetDelay`. Default: 2 hours. */\n resetDelay?: number\n}\n\nexport type AuthNotificationBuilder = (\n type: AuthNotificationEvent,\n user: Record<string, unknown>,\n opts: AuthNotificationOptions,\n) => Notification | null\n\n/** Human-readable duration for email copy, e.g. 432000000 → \"5 days\". */\nexport function formatDuration(ms: number): string {\n const units: [string, number][] = [\n ['day', 86_400_000],\n ['hour', 3_600_000],\n ['minute', 60_000],\n ]\n for (const [name, size] of units) {\n if (ms >= size && ms % size === 0) {\n const n = ms / size\n return `${n} ${name}${n === 1 ? '' : 's'}`\n }\n }\n const minutes = Math.max(1, Math.round(ms / 60_000))\n return `${minutes} minute${minutes === 1 ? '' : 's'}`\n}\n\nfunction buildLink(appUrl: string, path: string, token: string | undefined): string {\n const base = appUrl.replace(/\\/+$/, '')\n const route = path.startsWith('/') ? path : `/${path}`\n return `${base}${route}?token=${encodeURIComponent(token ?? '')}`\n}\n\n/**\n * Build the default Notification payload for each auth event type.\n * Exported so apps can wrap it via the notifier's `buildNotification` option.\n * Templates use EJS — `<%= variable %>` for output, `<% code %>` for logic.\n */\nexport function buildAuthNotification(\n type: AuthNotificationEvent,\n user: Record<string, unknown>,\n opts: AuthNotificationOptions,\n): Notification | null {\n const { appUrl, paths = {} } = opts\n const verifyExpiry = formatDuration(opts.verifyDelay ?? DEFAULT_VERIFY_DELAY_MS)\n const resetExpiry = formatDuration(opts.resetDelay ?? DEFAULT_RESET_DELAY_MS)\n const email = user['email'] as string\n if (!email) return null\n\n switch (type) {\n case 'auth.verify-signup':\n case 'auth.resend-verify-signup': {\n const token = user['verifyToken'] as string | undefined\n const verifyUrl = buildLink(appUrl, paths.verify ?? '/verify', token)\n return {\n to: email,\n channel: 'email',\n subject: 'Verify your email address',\n bodyTemplate: `\n <h2>Welcome!</h2>\n <p>Click the link below to verify your email address:</p>\n <p><a href=\"<%= verifyUrl %>\">Verify email</a></p>\n <p>This link expires in <%= expiresIn %>.</p>\n `,\n textTemplate: `Verify your email: <%= verifyUrl %>`,\n data: { verifyUrl, expiresIn: verifyExpiry, user },\n }\n }\n\n case 'auth.send-reset-pwd': {\n const token = user['resetToken'] as string | undefined\n const resetUrl = buildLink(appUrl, paths.resetPassword ?? '/reset-password', token)\n return {\n to: email,\n channel: 'email',\n subject: 'Reset your password',\n bodyTemplate: `\n <h2>Password reset requested</h2>\n <p>Click the link below to reset your password:</p>\n <p><a href=\"<%= resetUrl %>\">Reset password</a></p>\n <p>This link expires in <%= expiresIn %>. If you did not request this, ignore this email.</p>\n `,\n textTemplate: `Reset your password: <%= resetUrl %>`,\n data: { resetUrl, expiresIn: resetExpiry, user },\n }\n }\n\n case 'auth.reset-pwd': {\n return {\n to: email,\n channel: 'email',\n subject: 'Your password has been reset',\n bodyTemplate: `<p>Your password has been successfully reset. If you did not do this, please contact support immediately.</p>`,\n textTemplate: `Your password has been reset. If you did not do this, please contact support.`,\n data: { user },\n }\n }\n\n case 'auth.password-change': {\n return {\n to: email,\n channel: 'email',\n subject: 'Your password has been changed',\n bodyTemplate: `<p>Your account password was just changed. If this was not you, please contact support immediately.</p>`,\n textTemplate: `Your password was changed. Contact support if this wasn't you.`,\n data: { user },\n }\n }\n\n case 'auth.identity-change': {\n return {\n to: email,\n channel: 'email',\n subject: 'Your email address is being changed',\n bodyTemplate: `<p>A request was made to change your email address. Click the link to confirm.</p>`,\n textTemplate: `Confirm your email change by clicking the link in the HTML email.`,\n data: { user },\n }\n }\n\n case 'auth.verify-signup-set-password': {\n const token = user['verifyToken'] as string | undefined\n const verifyUrl = buildLink(appUrl, paths.verifySetPassword ?? '/verify-set-password', token)\n return {\n to: email,\n channel: 'email',\n subject: 'Set your password',\n bodyTemplate: `\n <h2>Set your password</h2>\n <p><a href=\"<%= verifyUrl %>\">Set password</a></p>\n `,\n textTemplate: `Set your password: <%= verifyUrl %>`,\n data: { verifyUrl, user },\n }\n }\n }\n}\n\nexport type NotifierFn = (\n type: string,\n user: Record<string, unknown>,\n notifierOptions: Record<string, unknown>,\n) => Promise<void>\n\ninterface NotifierBaseOptions extends AuthNotificationOptions {\n /** Driver registry — used to determine which drivers handle each event. */\n registry: DriverRegistry\n /** Replace the default email composition. Wrap `buildAuthNotification` to tweak it. */\n buildNotification?: AuthNotificationBuilder\n}\n\nexport interface BullMQNotifierOptions extends NotifierBaseOptions {\n /** BullMQ Queue instance — from createNotificationQueue(). */\n queue: Queue<NotificationJob>\n}\n\n/**\n * Create a notifier function compatible with feathers-authentication-management.\n *\n * When an auth event fires (verifySignup, sendResetPwd, etc.), this notifier:\n * 1. Maps the event type to a feathers-baas notification event key\n * 2. Looks up all registered drivers for that event\n * 3. Enqueues one BullMQ job per driver\n * 4. Returns immediately — delivery is asynchronous\n *\n * Wire into the app:\n * ```ts\n * app.set('notifier', createBullMQNotifier({ queue, registry, appUrl }))\n * ```\n */\nexport type DirectNotifierOptions = NotifierBaseOptions\n\n/**\n * Create a notifier that sends notifications directly via the driver (no queue).\n * Use this when Redis/BullMQ is not available — suitable for API-based drivers\n * (Brevo, Resend, SendGrid) in development or low-traffic environments.\n */\nexport function createDirectNotifier(opts: DirectNotifierOptions): NotifierFn {\n return async (type, user, _notifierOptions) => {\n const eventKey = AUTH_MANAGEMENT_EVENT_MAP[type]\n if (!eventKey) return\n\n const notification = (opts.buildNotification ?? buildAuthNotification)(eventKey, user, opts)\n if (!notification) return\n\n const driverNames = opts.registry.getDriversForEvent(eventKey)\n if (driverNames.length === 0) return\n\n await Promise.all(\n driverNames.map(async (driverName) => {\n const driver = opts.registry.getDriver(driverName)\n if (!driver) return\n await driver.send(notification)\n }),\n )\n }\n}\n\nexport function createBullMQNotifier(opts: BullMQNotifierOptions): NotifierFn {\n return async (type, user, _notifierOptions) => {\n const eventKey = AUTH_MANAGEMENT_EVENT_MAP[type]\n if (!eventKey) return // Unknown event type — no-op\n\n const notification = (opts.buildNotification ?? buildAuthNotification)(eventKey, user, opts)\n if (!notification) return // Missing required user fields — no-op\n\n const driverNames = opts.registry.getDriversForEvent(eventKey)\n if (driverNames.length === 0) return // No drivers configured for this event\n\n await Promise.all(\n driverNames.map((driverName) =>\n enqueueNotification(opts.queue, { driverName, notification }),\n ),\n )\n }\n}\n","// Generated by feathers-baas. Safe to edit.\nimport { Worker } from 'bullmq'\nimport type { Redis } from 'ioredis'\nimport type { DriverRegistry } from '../registry.js'\nimport type { NotificationJob } from '../types.js'\nimport { NOTIFICATION_QUEUE_NAME, NOTIFICATION_QUEUE_PREFIX } from './producer.js'\n\nexport interface WorkerOptions {\n /** BullMQ concurrency — number of jobs processed in parallel. */\n concurrency?: number\n}\n\n/**\n * Create and start the BullMQ worker that processes notification jobs.\n *\n * The worker looks up the driver from the registry by name, renders the\n * EJS template, and calls driver.send(). BullMQ handles retries with\n * exponential back-off automatically.\n *\n * Call worker.close() during graceful shutdown to drain in-flight jobs.\n *\n * @example\n * ```ts\n * const worker = createNotificationWorker(registry, redis, { concurrency: 5 })\n *\n * process.on('SIGTERM', async () => {\n * await worker.close()\n * })\n * ```\n */\nexport function createNotificationWorker(\n registry: DriverRegistry,\n redis: Redis,\n opts: WorkerOptions = {},\n): Worker<NotificationJob> {\n const concurrency = opts.concurrency ?? 5\n\n const worker = new Worker<NotificationJob>(\n NOTIFICATION_QUEUE_NAME,\n async (job) => {\n const { driverName, notification } = job.data\n\n const driver = registry.getDriver(driverName)\n if (!driver) {\n throw new Error(`Notification driver \"${driverName}\" is not registered`)\n }\n\n await driver.send(notification)\n },\n {\n connection: redis,\n // Must match the producer, or jobs are enqueued where the worker isn't listening\n prefix: NOTIFICATION_QUEUE_PREFIX,\n concurrency,\n // Don't create a new redis connection per job — reuse the pool\n autorun: true,\n },\n )\n\n worker.on('failed', (job, err) => {\n // BullMQ handles retries; this is just for observability\n const jobId = job?.id ?? 'unknown'\n const message = err instanceof Error ? err.message : String(err)\n console.error(`[notifications] Job ${jobId} failed: ${message}`)\n })\n\n return worker\n}\n","// Generated by feathers-baas. Safe to edit.\nimport nodemailer from 'nodemailer'\nimport * as ejs from 'ejs'\nimport type { NotifierDriver, Notification } from '../types.js'\n\n// ejs is a CommonJS module — alias the render function defensively\nconst ejsRender = (ejs as unknown as { render?: typeof ejs.render }).render ?? ejs.render\n\nexport interface SMTPDriverOptions {\n /** SMTP connection URL, e.g. smtp://user:pass@mail.example.com:587 */\n url: string\n /** Display name shown in the From field. */\n fromName: string\n /** Email address shown in the From field. */\n fromAddress: string\n}\n\n/**\n * Email driver backed by nodemailer over SMTP.\n * Templates are rendered with EJS at send time.\n *\n * Use this driver for self-hosted SMTP servers (Postfix, Mailtrap, etc.).\n * For transactional email services, prefer ResendDriver.\n */\nexport class SMTPDriver implements NotifierDriver {\n readonly name = 'smtp'\n\n private readonly transporter: nodemailer.Transporter\n\n constructor(private readonly opts: SMTPDriverOptions) {\n this.transporter = nodemailer.createTransport(opts.url)\n }\n\n async send(notification: Notification): Promise<void> {\n const html = ejsRender(notification.bodyTemplate, notification.data, { async: false })\n const text = notification.textTemplate\n ? ejsRender(notification.textTemplate, notification.data, { async: false })\n : undefined\n\n await this.transporter.sendMail({\n from: `\"${this.opts.fromName}\" <${this.opts.fromAddress}>`,\n to: notification.to,\n subject: notification.subject ?? '(no subject)',\n html,\n text,\n })\n }\n\n /** Verify SMTP connectivity. Throws if the server is unreachable. */\n async verify(): Promise<void> {\n await this.transporter.verify()\n }\n\n /** Close the underlying connection pool. */\n close(): void {\n this.transporter.close()\n }\n}\n","// Generated by feathers-baas. Safe to edit.\nimport { Resend } from 'resend'\nimport * as ejs from 'ejs'\nimport type { NotifierDriver, Notification } from '../types.js'\n\nconst ejsRender = (ejs as unknown as { render?: typeof ejs.render }).render ?? ejs.render\n\nexport interface ResendDriverOptions {\n /** Resend API key (from https://resend.com/api-keys). */\n apiKey: string\n /** Display name shown in the From field. */\n fromName: string\n /** Verified sender address. Must be a verified domain in your Resend account. */\n fromAddress: string\n}\n\n/**\n * Email driver backed by the Resend transactional email API.\n * Templates are rendered with EJS at send time.\n *\n * Resend offers generous free tier and excellent deliverability,\n * making it the recommended choice for new projects.\n */\nexport class ResendDriver implements NotifierDriver {\n readonly name = 'resend'\n\n private readonly client: Resend\n\n constructor(private readonly opts: ResendDriverOptions) {\n this.client = new Resend(opts.apiKey)\n }\n\n async send(notification: Notification): Promise<void> {\n const html = ejsRender(notification.bodyTemplate, notification.data, { async: false })\n const text = notification.textTemplate\n ? ejsRender(notification.textTemplate, notification.data, { async: false })\n : undefined\n\n const result = await this.client.emails.send({\n from: `${this.opts.fromName} <${this.opts.fromAddress}>`,\n to: [notification.to],\n subject: notification.subject ?? '(no subject)',\n html,\n text,\n })\n\n if ('error' in result && result.error) {\n throw new Error(`Resend error: ${result.error.message}`)\n }\n }\n}\n","// Generated by feathers-baas. Safe to edit.\nimport sgMail from '@sendgrid/mail'\nimport * as ejs from 'ejs'\nimport type { NotifierDriver, Notification } from '../types.js'\n\n// ejs is a CommonJS module — alias the render function defensively\nconst ejsRender = (ejs as unknown as { render?: typeof ejs.render }).render ?? ejs.render\n\nexport interface SendGridDriverOptions {\n /** SendGrid API key (from https://app.sendgrid.com/settings/api_keys). */\n apiKey: string\n /** Display name shown in the From field. */\n fromName: string\n /** Verified sender address. Must be verified in your SendGrid account. */\n fromAddress: string\n}\n\n/**\n * Email driver backed by the SendGrid API.\n * Templates are rendered with EJS at send time.\n */\nexport class SendGridDriver implements NotifierDriver {\n readonly name = 'sendgrid'\n\n constructor(private readonly opts: SendGridDriverOptions) {\n sgMail.setApiKey(opts.apiKey)\n }\n\n async send(notification: Notification): Promise<void> {\n const html = ejsRender(notification.bodyTemplate, notification.data, { async: false })\n const text = notification.textTemplate\n ? ejsRender(notification.textTemplate, notification.data, { async: false })\n : undefined\n\n await sgMail.send({\n from: { name: this.opts.fromName, email: this.opts.fromAddress },\n to: notification.to,\n subject: notification.subject ?? '(no subject)',\n html,\n ...(text ? { text } : {}),\n })\n }\n}\n","// Generated by feathers-baas. Safe to edit.\nimport { TransactionalEmailsApi, TransactionalEmailsApiApiKeys, SendSmtpEmail } from '@getbrevo/brevo'\nimport * as ejs from 'ejs'\nimport type { NotifierDriver, Notification } from '../types.js'\n\n// ejs is a CommonJS module — alias the render function defensively\nconst ejsRender = (ejs as unknown as { render?: typeof ejs.render }).render ?? ejs.render\n\nexport interface BrevoDriverOptions {\n /** Brevo API key (from https://app.brevo.com/settings/keys/api). */\n apiKey: string\n /** Display name shown in the From field. */\n fromName: string\n /** Verified sender address. Must be verified in your Brevo account. */\n fromAddress: string\n}\n\n/**\n * Email driver backed by the Brevo (formerly Sendinblue) Transactional Email API.\n * Templates are rendered with EJS at send time.\n */\nexport class BrevoDriver implements NotifierDriver {\n readonly name = 'brevo'\n\n private readonly apiInstance: TransactionalEmailsApi\n\n constructor(private readonly opts: BrevoDriverOptions) {\n this.apiInstance = new TransactionalEmailsApi()\n this.apiInstance.setApiKey(TransactionalEmailsApiApiKeys.apiKey, opts.apiKey)\n }\n\n async send(notification: Notification): Promise<void> {\n const html = ejsRender(notification.bodyTemplate, notification.data, { async: false })\n const text = notification.textTemplate\n ? ejsRender(notification.textTemplate, notification.data, { async: false })\n : undefined\n\n const email = new SendSmtpEmail()\n email.sender = { name: this.opts.fromName, email: this.opts.fromAddress }\n email.to = [{ email: notification.to }]\n email.subject = notification.subject ?? '(no subject)'\n email.htmlContent = html\n if (text) email.textContent = text\n\n await this.apiInstance.sendTransacEmail(email)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAA8B;;;ACiBvB,IAAM,iBAAN,MAAqB;AAAA,EACT,UAAU,oBAAI,IAA4B;AAAA,EAC1C,WAAW,oBAAI,IAAiC;AAAA;AAAA,EAGjE,eAAe,QAA8B;AAC3C,SAAK,QAAQ,IAAI,OAAO,MAAM,MAAM;AAAA,EACtC;AAAA;AAAA,EAGA,SAAS,OAA0B,YAA0B;AAC3D,UAAM,WAAW,KAAK,SAAS,IAAI,KAAK,KAAK,CAAC;AAC9C,QAAI,CAAC,SAAS,SAAS,UAAU,GAAG;AAClC,eAAS,KAAK,UAAU;AAAA,IAC1B;AACA,SAAK,SAAS,IAAI,OAAO,QAAQ;AAAA,EACnC;AAAA;AAAA,EAGA,UAAU,MAA0C;AAClD,WAAO,KAAK,QAAQ,IAAI,IAAI;AAAA,EAC9B;AAAA;AAAA,EAGA,mBAAmB,OAAoC;AACrD,WAAO,KAAK,SAAS,IAAI,KAAK,KAAK,CAAC;AAAA,EACtC;AAAA;AAAA,EAGA,kBAA4B;AAC1B,WAAO,CAAC,GAAG,KAAK,QAAQ,KAAK,CAAC;AAAA,EAChC;AACF;;;AC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E,OAAO,MAAM,CAAC,IACxE;AAEJ,UAAM,QAAQ,IAAI,2BAAc;AAChC,UAAM,SAAS,EAAE,MAAM,KAAK,KAAK,UAAU,OAAO,KAAK,KAAK,YAAY;AACxE,UAAM,KAAK,CAAC,EAAE,OAAO,aAAa,GAAG,CAAC;AACtC,UAAM,UAAU,aAAa,WAAW;AACxC,UAAM,cAAc;AACpB,QAAI,KAAM,OAAM,cAAc;AAE9B,UAAM,KAAK,YAAY,iBAAiB,KAAK;AAAA,EAC/C;AACF;;;AR9CA;AAIA,IAAM,UAAM,kCAAc,YAAY,GAAG,EAAE,iBAAiB;AAE5D,IAAM,SAA6B;AAAA,EACjC,MAAM;AAAA,EACN,SAAS,IAAI;AAAA,EACb,MAAM,QAAQ,MAAM,UAAU;AAAA,EAG9B;AACF;AAEA,IAAO,gBAAQ;","names":["import_bullmq","nodemailer","ejs","ejsRender","ejs","ejsRender","sgMail","ejs","ejsRender"]}
package/dist/index.d.cts CHANGED
@@ -82,17 +82,45 @@ declare class DriverRegistry {
82
82
  listDriverNames(): string[];
83
83
  }
84
84
 
85
- type NotifierFn = (type: string, user: Record<string, unknown>, notifierOptions: Record<string, unknown>) => Promise<void>;
86
- interface BullMQNotifierOptions {
87
- /** BullMQ Queue instance — from createNotificationQueue(). */
88
- queue: Queue<NotificationJob>;
89
- /** Driver registry — used to determine which drivers handle each event. */
90
- registry: DriverRegistry;
85
+ interface AuthNotificationOptions {
91
86
  /**
92
- * Public base URL of the app, e.g. https://api.example.com
93
- * Used to construct verification / reset URLs in email templates.
87
+ * Public base URL of the **web app** that redeems the tokens (not this API),
88
+ * e.g. https://app.example.com
94
89
  */
95
90
  appUrl: string;
91
+ /** Frontend routes the email links point to. */
92
+ paths?: {
93
+ /** Default: `/verify` */
94
+ verify?: string;
95
+ /** Default: `/reset-password` */
96
+ resetPassword?: string;
97
+ /** Default: `/verify-set-password` */
98
+ verifySetPassword?: string;
99
+ };
100
+ /** Verification token lifetime in ms — must match auth-management's `delay`. Default: 5 days. */
101
+ verifyDelay?: number;
102
+ /** Reset token lifetime in ms — must match auth-management's `resetDelay`. Default: 2 hours. */
103
+ resetDelay?: number;
104
+ }
105
+ type AuthNotificationBuilder = (type: AuthNotificationEvent, user: Record<string, unknown>, opts: AuthNotificationOptions) => Notification | null;
106
+ /** Human-readable duration for email copy, e.g. 432000000 → "5 days". */
107
+ declare function formatDuration(ms: number): string;
108
+ /**
109
+ * Build the default Notification payload for each auth event type.
110
+ * Exported so apps can wrap it via the notifier's `buildNotification` option.
111
+ * Templates use EJS — `<%= variable %>` for output, `<% code %>` for logic.
112
+ */
113
+ declare function buildAuthNotification(type: AuthNotificationEvent, user: Record<string, unknown>, opts: AuthNotificationOptions): Notification | null;
114
+ type NotifierFn = (type: string, user: Record<string, unknown>, notifierOptions: Record<string, unknown>) => Promise<void>;
115
+ interface NotifierBaseOptions extends AuthNotificationOptions {
116
+ /** Driver registry — used to determine which drivers handle each event. */
117
+ registry: DriverRegistry;
118
+ /** Replace the default email composition. Wrap `buildAuthNotification` to tweak it. */
119
+ buildNotification?: AuthNotificationBuilder;
120
+ }
121
+ interface BullMQNotifierOptions extends NotifierBaseOptions {
122
+ /** BullMQ Queue instance — from createNotificationQueue(). */
123
+ queue: Queue<NotificationJob>;
96
124
  }
97
125
  /**
98
126
  * Create a notifier function compatible with feathers-authentication-management.
@@ -108,12 +136,7 @@ interface BullMQNotifierOptions {
108
136
  * app.set('notifier', createBullMQNotifier({ queue, registry, appUrl }))
109
137
  * ```
110
138
  */
111
- interface DirectNotifierOptions {
112
- /** Driver registry — used to determine which drivers handle each event. */
113
- registry: DriverRegistry;
114
- /** Public base URL of the app. */
115
- appUrl: string;
116
- }
139
+ type DirectNotifierOptions = NotifierBaseOptions;
117
140
  /**
118
141
  * Create a notifier that sends notifications directly via the driver (no queue).
119
142
  * Use this when Redis/BullMQ is not available — suitable for API-based drivers
@@ -122,7 +145,8 @@ interface DirectNotifierOptions {
122
145
  declare function createDirectNotifier(opts: DirectNotifierOptions): NotifierFn;
123
146
  declare function createBullMQNotifier(opts: BullMQNotifierOptions): NotifierFn;
124
147
 
125
- declare const NOTIFICATION_QUEUE_NAME = "feathers-baas:notifications";
148
+ declare const NOTIFICATION_QUEUE_NAME = "feathers-baas-notifications";
149
+ declare const NOTIFICATION_QUEUE_PREFIX = "feathers-baas";
126
150
  /**
127
151
  * Create a BullMQ Queue instance for notification jobs.
128
152
  *
@@ -257,4 +281,4 @@ declare class BrevoDriver implements NotifierDriver {
257
281
 
258
282
  declare const plugin: FeathersBaasPlugin;
259
283
 
260
- export { type AuthNotificationEvent, BrevoDriver, type BrevoDriverOptions, type BullMQNotifierOptions, type DirectNotifierOptions, DriverRegistry, NOTIFICATION_QUEUE_NAME, type Notification, type NotificationEvent, type NotificationJob, type NotifierDriver, type NotifierFn, ResendDriver, type ResendDriverOptions, SMTPDriver, type SMTPDriverOptions, SendGridDriver, type SendGridDriverOptions, type WorkerOptions, createBullMQNotifier, createDirectNotifier, createNotificationQueue, createNotificationWorker, plugin as default, enqueueNotification };
284
+ export { type AuthNotificationBuilder, type AuthNotificationEvent, type AuthNotificationOptions, BrevoDriver, type BrevoDriverOptions, type BullMQNotifierOptions, type DirectNotifierOptions, DriverRegistry, NOTIFICATION_QUEUE_NAME, NOTIFICATION_QUEUE_PREFIX, type Notification, type NotificationEvent, type NotificationJob, type NotifierDriver, type NotifierFn, ResendDriver, type ResendDriverOptions, SMTPDriver, type SMTPDriverOptions, SendGridDriver, type SendGridDriverOptions, type WorkerOptions, buildAuthNotification, createBullMQNotifier, createDirectNotifier, createNotificationQueue, createNotificationWorker, plugin as default, enqueueNotification, formatDuration };
package/dist/index.d.ts CHANGED
@@ -82,17 +82,45 @@ declare class DriverRegistry {
82
82
  listDriverNames(): string[];
83
83
  }
84
84
 
85
- type NotifierFn = (type: string, user: Record<string, unknown>, notifierOptions: Record<string, unknown>) => Promise<void>;
86
- interface BullMQNotifierOptions {
87
- /** BullMQ Queue instance — from createNotificationQueue(). */
88
- queue: Queue<NotificationJob>;
89
- /** Driver registry — used to determine which drivers handle each event. */
90
- registry: DriverRegistry;
85
+ interface AuthNotificationOptions {
91
86
  /**
92
- * Public base URL of the app, e.g. https://api.example.com
93
- * Used to construct verification / reset URLs in email templates.
87
+ * Public base URL of the **web app** that redeems the tokens (not this API),
88
+ * e.g. https://app.example.com
94
89
  */
95
90
  appUrl: string;
91
+ /** Frontend routes the email links point to. */
92
+ paths?: {
93
+ /** Default: `/verify` */
94
+ verify?: string;
95
+ /** Default: `/reset-password` */
96
+ resetPassword?: string;
97
+ /** Default: `/verify-set-password` */
98
+ verifySetPassword?: string;
99
+ };
100
+ /** Verification token lifetime in ms — must match auth-management's `delay`. Default: 5 days. */
101
+ verifyDelay?: number;
102
+ /** Reset token lifetime in ms — must match auth-management's `resetDelay`. Default: 2 hours. */
103
+ resetDelay?: number;
104
+ }
105
+ type AuthNotificationBuilder = (type: AuthNotificationEvent, user: Record<string, unknown>, opts: AuthNotificationOptions) => Notification | null;
106
+ /** Human-readable duration for email copy, e.g. 432000000 → "5 days". */
107
+ declare function formatDuration(ms: number): string;
108
+ /**
109
+ * Build the default Notification payload for each auth event type.
110
+ * Exported so apps can wrap it via the notifier's `buildNotification` option.
111
+ * Templates use EJS — `<%= variable %>` for output, `<% code %>` for logic.
112
+ */
113
+ declare function buildAuthNotification(type: AuthNotificationEvent, user: Record<string, unknown>, opts: AuthNotificationOptions): Notification | null;
114
+ type NotifierFn = (type: string, user: Record<string, unknown>, notifierOptions: Record<string, unknown>) => Promise<void>;
115
+ interface NotifierBaseOptions extends AuthNotificationOptions {
116
+ /** Driver registry — used to determine which drivers handle each event. */
117
+ registry: DriverRegistry;
118
+ /** Replace the default email composition. Wrap `buildAuthNotification` to tweak it. */
119
+ buildNotification?: AuthNotificationBuilder;
120
+ }
121
+ interface BullMQNotifierOptions extends NotifierBaseOptions {
122
+ /** BullMQ Queue instance — from createNotificationQueue(). */
123
+ queue: Queue<NotificationJob>;
96
124
  }
97
125
  /**
98
126
  * Create a notifier function compatible with feathers-authentication-management.
@@ -108,12 +136,7 @@ interface BullMQNotifierOptions {
108
136
  * app.set('notifier', createBullMQNotifier({ queue, registry, appUrl }))
109
137
  * ```
110
138
  */
111
- interface DirectNotifierOptions {
112
- /** Driver registry — used to determine which drivers handle each event. */
113
- registry: DriverRegistry;
114
- /** Public base URL of the app. */
115
- appUrl: string;
116
- }
139
+ type DirectNotifierOptions = NotifierBaseOptions;
117
140
  /**
118
141
  * Create a notifier that sends notifications directly via the driver (no queue).
119
142
  * Use this when Redis/BullMQ is not available — suitable for API-based drivers
@@ -122,7 +145,8 @@ interface DirectNotifierOptions {
122
145
  declare function createDirectNotifier(opts: DirectNotifierOptions): NotifierFn;
123
146
  declare function createBullMQNotifier(opts: BullMQNotifierOptions): NotifierFn;
124
147
 
125
- declare const NOTIFICATION_QUEUE_NAME = "feathers-baas:notifications";
148
+ declare const NOTIFICATION_QUEUE_NAME = "feathers-baas-notifications";
149
+ declare const NOTIFICATION_QUEUE_PREFIX = "feathers-baas";
126
150
  /**
127
151
  * Create a BullMQ Queue instance for notification jobs.
128
152
  *
@@ -257,4 +281,4 @@ declare class BrevoDriver implements NotifierDriver {
257
281
 
258
282
  declare const plugin: FeathersBaasPlugin;
259
283
 
260
- export { type AuthNotificationEvent, BrevoDriver, type BrevoDriverOptions, type BullMQNotifierOptions, type DirectNotifierOptions, DriverRegistry, NOTIFICATION_QUEUE_NAME, type Notification, type NotificationEvent, type NotificationJob, type NotifierDriver, type NotifierFn, ResendDriver, type ResendDriverOptions, SMTPDriver, type SMTPDriverOptions, SendGridDriver, type SendGridDriverOptions, type WorkerOptions, createBullMQNotifier, createDirectNotifier, createNotificationQueue, createNotificationWorker, plugin as default, enqueueNotification };
284
+ export { type AuthNotificationBuilder, type AuthNotificationEvent, type AuthNotificationOptions, BrevoDriver, type BrevoDriverOptions, type BullMQNotifierOptions, type DirectNotifierOptions, DriverRegistry, NOTIFICATION_QUEUE_NAME, NOTIFICATION_QUEUE_PREFIX, type Notification, type NotificationEvent, type NotificationJob, type NotifierDriver, type NotifierFn, ResendDriver, type ResendDriverOptions, SMTPDriver, type SMTPDriverOptions, SendGridDriver, type SendGridDriverOptions, type WorkerOptions, buildAuthNotification, createBullMQNotifier, createDirectNotifier, createNotificationQueue, createNotificationWorker, plugin as default, enqueueNotification, formatDuration };