@vynelix/vynemit-core 1.0.0 → 1.0.1
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/README.md +11 -11
- package/dist/index.d.mts +208 -0
- package/dist/index.d.ts +208 -0
- package/dist/index.js +227 -1
- package/dist/index.mjs +227 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**Unified Notification Model** - Single interface for in-app, push, email, SMS, and webhooks
|
|
8
8
|
**Event-Based Dispatch** - Reactive system with real-time subscriptions
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
**Read/Unread Tracking** - Built-in state management
|
|
10
|
+
**Channel Filters** - User preferences for notification channels
|
|
11
|
+
**Queue Support** - Redis, BullMQ, or in-memory queues
|
|
12
|
+
**Pluggable Architecture** - Swap storage and transport adapters
|
|
13
|
+
**Template System** - Reusable notification templates
|
|
14
|
+
**Middleware Support** - Rate limiting, deduplication, analytics
|
|
15
15
|
**Zero Dependencies** - Lightweight core with optional adapters
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
@@ -394,7 +394,7 @@ Contributions welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) first.
|
|
|
394
394
|
|
|
395
395
|
## Support
|
|
396
396
|
|
|
397
|
-
-
|
|
398
|
-
-
|
|
399
|
-
-
|
|
400
|
-
-
|
|
397
|
+
- Email: [EMAIL ADDRESS](mailto:admin@vynelix.com)
|
|
398
|
+
- Discord: [Join our community](https://discord.gg/synq)
|
|
399
|
+
- Docs: [docs](https://vynelix.com/docs)
|
|
400
|
+
- Issues: [GitHub Issues](https://github.com/IsaiahTek/vynemit/issues)
|
package/dist/index.d.mts
CHANGED
|
@@ -227,52 +227,260 @@ interface NotificationStats {
|
|
|
227
227
|
byPriority: Record<NotificationPriority, number>;
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
+
/**
|
|
231
|
+
* The core NotificationCenter class responsible for dispatching, routing, storing,
|
|
232
|
+
* and managing the lifecycle of notifications across multiple transports.
|
|
233
|
+
*/
|
|
230
234
|
declare class NotificationCenter {
|
|
235
|
+
/** The configuration object for the NotificationCenter. */
|
|
231
236
|
private config;
|
|
237
|
+
/** The storage adapter used for persisting notifications and preferences. */
|
|
232
238
|
private storage;
|
|
239
|
+
/** A map of available transport adapters, indexed by channel type. */
|
|
233
240
|
private transports;
|
|
241
|
+
/** The queue adapter used for asynchronous delivery and scheduling (optional). */
|
|
234
242
|
private queue?;
|
|
243
|
+
/** A map of registered notification templates. */
|
|
235
244
|
private templates;
|
|
245
|
+
/** A list of middleware functions applied to notifications during their lifecycle. */
|
|
236
246
|
private middleware;
|
|
247
|
+
/** Subscribers listening for raw incoming notifications by user ID. */
|
|
237
248
|
private subscribers;
|
|
249
|
+
/** Subscribers listening for notification lifecycle events (e.g., read, sent) by user ID. */
|
|
238
250
|
private eventSubscribers;
|
|
251
|
+
/** Subscribers listening to unread count changes by user ID. */
|
|
239
252
|
private unreadSubscribers;
|
|
253
|
+
/** Indicates whether the NotificationCenter background processes are currently running. */
|
|
240
254
|
private isRunning;
|
|
255
|
+
/** The interval handle for the queue worker. */
|
|
241
256
|
private workerInterval?;
|
|
257
|
+
/**
|
|
258
|
+
* Initializes a new NotificationCenter with the provided configuration.
|
|
259
|
+
* @param config - The configuration options including adapters and transports.
|
|
260
|
+
*/
|
|
242
261
|
constructor(config: NotificationConfig);
|
|
262
|
+
/**
|
|
263
|
+
* Dispatches a single notification based on the provided input.
|
|
264
|
+
* If a queue is configured, the delivery takes place asynchronously.
|
|
265
|
+
*
|
|
266
|
+
* @param input - The notification payload and routing instructions.
|
|
267
|
+
* @returns A promise that resolves to the processed Notification object.
|
|
268
|
+
*/
|
|
243
269
|
send(input: NotificationInput): Promise<Notification>;
|
|
270
|
+
/**
|
|
271
|
+
* Dispatches an array of notifications sequentially or concurrently.
|
|
272
|
+
*
|
|
273
|
+
* @param inputs - An array of notification inputs.
|
|
274
|
+
* @returns A promise resolving to an array of generated Notification objects.
|
|
275
|
+
*/
|
|
244
276
|
sendBatch(inputs: NotificationInput[]): Promise<Notification[]>;
|
|
277
|
+
/**
|
|
278
|
+
* Sends an identical notification to a list of users (multicast).
|
|
279
|
+
* Automatically optimizes push/sms transport delivery if transport supports bulk send.
|
|
280
|
+
*
|
|
281
|
+
* @param input - Multicast payload including the target `userIds`.
|
|
282
|
+
* @returns A promise resolving to the dispatched notifications.
|
|
283
|
+
*/
|
|
245
284
|
sendMulticast(input: NotificationMulticastInput): Promise<Notification[]>;
|
|
285
|
+
/**
|
|
286
|
+
* Schedules a notification to be sent at a specific future date/time.
|
|
287
|
+
* Automatically enqueues it if the queue adapter supports delayed jobs.
|
|
288
|
+
*
|
|
289
|
+
* @param input - The notification input.
|
|
290
|
+
* @param when - The Date at which the notification should be delivered.
|
|
291
|
+
* @returns A promise resolving to the generated Notification ID.
|
|
292
|
+
*/
|
|
246
293
|
schedule(input: NotificationInput, when: Date): Promise<string>;
|
|
294
|
+
/**
|
|
295
|
+
* Retrieves notifications intended for a specific user ID.
|
|
296
|
+
*
|
|
297
|
+
* @param userId - The target user's ID.
|
|
298
|
+
* @param filters - Optional filters like status, type, limit, offset.
|
|
299
|
+
* @returns A promise resolving to the list of matched notifications.
|
|
300
|
+
*/
|
|
247
301
|
getForUser(userId: string, filters?: NotificationFilters): Promise<Notification[]>;
|
|
302
|
+
/**
|
|
303
|
+
* Retrieves the current number of unread notifications for a specified user.
|
|
304
|
+
*
|
|
305
|
+
* @param userId - The target user's ID.
|
|
306
|
+
* @returns The count of unread notifications.
|
|
307
|
+
*/
|
|
248
308
|
getUnreadCount(userId: string): Promise<number>;
|
|
309
|
+
/**
|
|
310
|
+
* Retrieves a specific notification by its unique ID.
|
|
311
|
+
*
|
|
312
|
+
* @param id - The Notification ID.
|
|
313
|
+
* @returns The notification object if found, otherwise null.
|
|
314
|
+
*/
|
|
249
315
|
getById(id: string): Promise<Notification | null>;
|
|
316
|
+
/**
|
|
317
|
+
* Aggregates notification statistics for a specified user (e.g., total, unread, counts by channel).
|
|
318
|
+
*
|
|
319
|
+
* @param userId - The user's ID to fetch stats for.
|
|
320
|
+
* @returns An object containing grouped statistics.
|
|
321
|
+
*/
|
|
250
322
|
getStats(userId: string): Promise<NotificationStats>;
|
|
323
|
+
/**
|
|
324
|
+
* Marks a specific notification as "read" and triggers real-time updates for listeners.
|
|
325
|
+
*
|
|
326
|
+
* @param notificationId - The unique ID of the notification.
|
|
327
|
+
*/
|
|
251
328
|
markAsRead(notificationId: string): Promise<void>;
|
|
329
|
+
/**
|
|
330
|
+
* Marks all notifications belonging to a user as "read".
|
|
331
|
+
*
|
|
332
|
+
* @param userId - The user's ID.
|
|
333
|
+
*/
|
|
252
334
|
markAllAsRead(userId: string): Promise<void>;
|
|
335
|
+
/**
|
|
336
|
+
* Reverts a notification status back to "unread".
|
|
337
|
+
*
|
|
338
|
+
* @param notificationId - The unique ID of the notification.
|
|
339
|
+
*/
|
|
253
340
|
markAsUnread(notificationId: string): Promise<void>;
|
|
341
|
+
/**
|
|
342
|
+
* Marks all notifications belonging to a user as "unread".
|
|
343
|
+
*
|
|
344
|
+
* @param userId - The target user's ID.
|
|
345
|
+
*/
|
|
254
346
|
markAllAsUnread(userId: string): Promise<void>;
|
|
347
|
+
/**
|
|
348
|
+
* Deletes a specific notification from storage.
|
|
349
|
+
*
|
|
350
|
+
* @param notificationId - The Notification ID to delete.
|
|
351
|
+
*/
|
|
255
352
|
delete(notificationId: string): Promise<void>;
|
|
353
|
+
/**
|
|
354
|
+
* Deletes all notifications for a specific user.
|
|
355
|
+
*
|
|
356
|
+
* @param userId - The user's ID.
|
|
357
|
+
*/
|
|
256
358
|
deleteAll(userId: string): Promise<void>;
|
|
359
|
+
/**
|
|
360
|
+
* Retrieves the notification opt-in/opt-out routing preferences for a given user.
|
|
361
|
+
*
|
|
362
|
+
* @param userId - The user's ID.
|
|
363
|
+
* @returns A promise resolving to the user's NotificationPreferences.
|
|
364
|
+
*/
|
|
257
365
|
getPreferences(userId: string): Promise<NotificationPreferences>;
|
|
366
|
+
/**
|
|
367
|
+
* Updates the notification routing and delivery preferences for an user.
|
|
368
|
+
*
|
|
369
|
+
* @param userId - The user's ID.
|
|
370
|
+
* @param prefs - A partial object containing the updated preferences.
|
|
371
|
+
*/
|
|
258
372
|
updatePreferences(userId: string, prefs: Partial<NotificationPreferences>): Promise<void>;
|
|
373
|
+
/**
|
|
374
|
+
* Registers a notification template, mapping a named key to dynamic defaults/formatting.
|
|
375
|
+
*
|
|
376
|
+
* @param template - The NotificationTemplate definitions.
|
|
377
|
+
*/
|
|
259
378
|
registerTemplate(template: NotificationTemplate): void;
|
|
379
|
+
/**
|
|
380
|
+
* Looks up a registered template by its ID.
|
|
381
|
+
*
|
|
382
|
+
* @param id - The ID of the template.
|
|
383
|
+
* @returns The template object, or undefined if not found.
|
|
384
|
+
*/
|
|
260
385
|
getTemplate(id: string): NotificationTemplate | undefined;
|
|
386
|
+
/**
|
|
387
|
+
* Unregisters a template from the NotificationCenter.
|
|
388
|
+
*
|
|
389
|
+
* @param id - The template ID to remove.
|
|
390
|
+
*/
|
|
261
391
|
unregisterTemplate(id: string): void;
|
|
392
|
+
/**
|
|
393
|
+
* Enables batch notification "digests" for a specific user to prevent notification fatigue.
|
|
394
|
+
*
|
|
395
|
+
* @param userId - The user's ID.
|
|
396
|
+
* @param config - The timeframe and configuration for the user's digest.
|
|
397
|
+
*/
|
|
262
398
|
enableDigest(userId: string, config: DigestConfig): Promise<void>;
|
|
399
|
+
/**
|
|
400
|
+
* Disables the digest feature for a user, reverting to immediate delivery.
|
|
401
|
+
*
|
|
402
|
+
* @param userId - The target user's ID.
|
|
403
|
+
*/
|
|
263
404
|
disableDigest(userId: string): Promise<void>;
|
|
405
|
+
/**
|
|
406
|
+
* Fetches the current digest rules configured for a user.
|
|
407
|
+
*
|
|
408
|
+
* @param userId - The user's ID.
|
|
409
|
+
* @returns The digest configuration, or null if disabled.
|
|
410
|
+
*/
|
|
264
411
|
getDigestConfig(userId: string): Promise<DigestConfig | null>;
|
|
412
|
+
/**
|
|
413
|
+
* Retrieves all delivery receipts generated from transports for a specific notification.
|
|
414
|
+
* Useful to see which channels succeeded and which failed.
|
|
415
|
+
*
|
|
416
|
+
* @param notificationId - The notification's ID.
|
|
417
|
+
* @returns An array of delivery receipts.
|
|
418
|
+
*/
|
|
265
419
|
getDeliveryStatus(notificationId: string): Promise<DeliveryReceipt[]>;
|
|
420
|
+
/**
|
|
421
|
+
* Attempts to resend a notification for any channels that previously marked it as "failed".
|
|
422
|
+
*
|
|
423
|
+
* @param notificationId - The target notification ID.
|
|
424
|
+
* @param channel - Optional channel scope. If provided, retries only on this specific transport.
|
|
425
|
+
*/
|
|
266
426
|
retryFailed(notificationId: string, channel?: ChannelType): Promise<void>;
|
|
427
|
+
/**
|
|
428
|
+
* Registers a callback to be invoked whenever a notification is sent to a specific user.
|
|
429
|
+
*
|
|
430
|
+
* @param userId - The target user's ID.
|
|
431
|
+
* @param callback - Function to handle the raw notification map.
|
|
432
|
+
* @returns A cleanup function to unsubscribe from this event.
|
|
433
|
+
*/
|
|
267
434
|
subscribe(userId: string, callback: (notification: Notification) => void): Unsubscribe;
|
|
435
|
+
/**
|
|
436
|
+
* Registers a callback for state changes (e.g. read/unread status updates) for a user's notifications.
|
|
437
|
+
*
|
|
438
|
+
* @param userId - The target user's ID.
|
|
439
|
+
* @param callback - Lifecycle event listener.
|
|
440
|
+
* @returns A cleanup function to unsubscribe.
|
|
441
|
+
*/
|
|
268
442
|
subscribeToEvents(userId: string, callback: (event: NotificationEvent) => void): Unsubscribe;
|
|
443
|
+
/**
|
|
444
|
+
* Registers a listener to react to changes in the unread notification count for a user.
|
|
445
|
+
*
|
|
446
|
+
* @param userId - The user's ID.
|
|
447
|
+
* @param callback - Handlers receiving the current unread count.
|
|
448
|
+
* @returns Unsubscribe function.
|
|
449
|
+
*/
|
|
269
450
|
onUnreadCountChange(userId: string, callback: (count: number, userId: string) => void): Unsubscribe;
|
|
451
|
+
/**
|
|
452
|
+
* Injects a middleware interceptor to apply custom logic before or after notifications are sent.
|
|
453
|
+
*
|
|
454
|
+
* @param middleware - The middleware object conforming to `NotificationMiddleware`.
|
|
455
|
+
*/
|
|
270
456
|
use(middleware: NotificationMiddleware): void;
|
|
457
|
+
/**
|
|
458
|
+
* Removes a previously configured middleware globally.
|
|
459
|
+
*
|
|
460
|
+
* @param name - The name identifier of the middleware to remove.
|
|
461
|
+
*/
|
|
271
462
|
removeMiddleware(name: string): void;
|
|
463
|
+
/**
|
|
464
|
+
* Boots up the NotificationCenter, initializing storage, queues, and worker loops if enabled.
|
|
465
|
+
*/
|
|
272
466
|
start(): Promise<void>;
|
|
467
|
+
/**
|
|
468
|
+
* Gracefully shuts down the NotificationCenter, terminating background queues and workers.
|
|
469
|
+
*/
|
|
273
470
|
stop(): Promise<void>;
|
|
471
|
+
/**
|
|
472
|
+
* Pings all registered transports to report on their current health and active status.
|
|
473
|
+
*
|
|
474
|
+
* @returns A map representing the readiness boolean state of each registered transport.
|
|
475
|
+
*/
|
|
274
476
|
healthCheck(): Promise<Record<string, boolean>>;
|
|
477
|
+
/**
|
|
478
|
+
* Applies metadata, templates, and defaults to construct the internal Notification shape.
|
|
479
|
+
*/
|
|
275
480
|
private buildNotification;
|
|
481
|
+
/**
|
|
482
|
+
* Internal mechanism sending payload out across desired transports without queue delay.
|
|
483
|
+
*/
|
|
276
484
|
private sendNow;
|
|
277
485
|
private castNotification;
|
|
278
486
|
private startWorker;
|
package/dist/index.d.ts
CHANGED
|
@@ -227,52 +227,260 @@ interface NotificationStats {
|
|
|
227
227
|
byPriority: Record<NotificationPriority, number>;
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
+
/**
|
|
231
|
+
* The core NotificationCenter class responsible for dispatching, routing, storing,
|
|
232
|
+
* and managing the lifecycle of notifications across multiple transports.
|
|
233
|
+
*/
|
|
230
234
|
declare class NotificationCenter {
|
|
235
|
+
/** The configuration object for the NotificationCenter. */
|
|
231
236
|
private config;
|
|
237
|
+
/** The storage adapter used for persisting notifications and preferences. */
|
|
232
238
|
private storage;
|
|
239
|
+
/** A map of available transport adapters, indexed by channel type. */
|
|
233
240
|
private transports;
|
|
241
|
+
/** The queue adapter used for asynchronous delivery and scheduling (optional). */
|
|
234
242
|
private queue?;
|
|
243
|
+
/** A map of registered notification templates. */
|
|
235
244
|
private templates;
|
|
245
|
+
/** A list of middleware functions applied to notifications during their lifecycle. */
|
|
236
246
|
private middleware;
|
|
247
|
+
/** Subscribers listening for raw incoming notifications by user ID. */
|
|
237
248
|
private subscribers;
|
|
249
|
+
/** Subscribers listening for notification lifecycle events (e.g., read, sent) by user ID. */
|
|
238
250
|
private eventSubscribers;
|
|
251
|
+
/** Subscribers listening to unread count changes by user ID. */
|
|
239
252
|
private unreadSubscribers;
|
|
253
|
+
/** Indicates whether the NotificationCenter background processes are currently running. */
|
|
240
254
|
private isRunning;
|
|
255
|
+
/** The interval handle for the queue worker. */
|
|
241
256
|
private workerInterval?;
|
|
257
|
+
/**
|
|
258
|
+
* Initializes a new NotificationCenter with the provided configuration.
|
|
259
|
+
* @param config - The configuration options including adapters and transports.
|
|
260
|
+
*/
|
|
242
261
|
constructor(config: NotificationConfig);
|
|
262
|
+
/**
|
|
263
|
+
* Dispatches a single notification based on the provided input.
|
|
264
|
+
* If a queue is configured, the delivery takes place asynchronously.
|
|
265
|
+
*
|
|
266
|
+
* @param input - The notification payload and routing instructions.
|
|
267
|
+
* @returns A promise that resolves to the processed Notification object.
|
|
268
|
+
*/
|
|
243
269
|
send(input: NotificationInput): Promise<Notification>;
|
|
270
|
+
/**
|
|
271
|
+
* Dispatches an array of notifications sequentially or concurrently.
|
|
272
|
+
*
|
|
273
|
+
* @param inputs - An array of notification inputs.
|
|
274
|
+
* @returns A promise resolving to an array of generated Notification objects.
|
|
275
|
+
*/
|
|
244
276
|
sendBatch(inputs: NotificationInput[]): Promise<Notification[]>;
|
|
277
|
+
/**
|
|
278
|
+
* Sends an identical notification to a list of users (multicast).
|
|
279
|
+
* Automatically optimizes push/sms transport delivery if transport supports bulk send.
|
|
280
|
+
*
|
|
281
|
+
* @param input - Multicast payload including the target `userIds`.
|
|
282
|
+
* @returns A promise resolving to the dispatched notifications.
|
|
283
|
+
*/
|
|
245
284
|
sendMulticast(input: NotificationMulticastInput): Promise<Notification[]>;
|
|
285
|
+
/**
|
|
286
|
+
* Schedules a notification to be sent at a specific future date/time.
|
|
287
|
+
* Automatically enqueues it if the queue adapter supports delayed jobs.
|
|
288
|
+
*
|
|
289
|
+
* @param input - The notification input.
|
|
290
|
+
* @param when - The Date at which the notification should be delivered.
|
|
291
|
+
* @returns A promise resolving to the generated Notification ID.
|
|
292
|
+
*/
|
|
246
293
|
schedule(input: NotificationInput, when: Date): Promise<string>;
|
|
294
|
+
/**
|
|
295
|
+
* Retrieves notifications intended for a specific user ID.
|
|
296
|
+
*
|
|
297
|
+
* @param userId - The target user's ID.
|
|
298
|
+
* @param filters - Optional filters like status, type, limit, offset.
|
|
299
|
+
* @returns A promise resolving to the list of matched notifications.
|
|
300
|
+
*/
|
|
247
301
|
getForUser(userId: string, filters?: NotificationFilters): Promise<Notification[]>;
|
|
302
|
+
/**
|
|
303
|
+
* Retrieves the current number of unread notifications for a specified user.
|
|
304
|
+
*
|
|
305
|
+
* @param userId - The target user's ID.
|
|
306
|
+
* @returns The count of unread notifications.
|
|
307
|
+
*/
|
|
248
308
|
getUnreadCount(userId: string): Promise<number>;
|
|
309
|
+
/**
|
|
310
|
+
* Retrieves a specific notification by its unique ID.
|
|
311
|
+
*
|
|
312
|
+
* @param id - The Notification ID.
|
|
313
|
+
* @returns The notification object if found, otherwise null.
|
|
314
|
+
*/
|
|
249
315
|
getById(id: string): Promise<Notification | null>;
|
|
316
|
+
/**
|
|
317
|
+
* Aggregates notification statistics for a specified user (e.g., total, unread, counts by channel).
|
|
318
|
+
*
|
|
319
|
+
* @param userId - The user's ID to fetch stats for.
|
|
320
|
+
* @returns An object containing grouped statistics.
|
|
321
|
+
*/
|
|
250
322
|
getStats(userId: string): Promise<NotificationStats>;
|
|
323
|
+
/**
|
|
324
|
+
* Marks a specific notification as "read" and triggers real-time updates for listeners.
|
|
325
|
+
*
|
|
326
|
+
* @param notificationId - The unique ID of the notification.
|
|
327
|
+
*/
|
|
251
328
|
markAsRead(notificationId: string): Promise<void>;
|
|
329
|
+
/**
|
|
330
|
+
* Marks all notifications belonging to a user as "read".
|
|
331
|
+
*
|
|
332
|
+
* @param userId - The user's ID.
|
|
333
|
+
*/
|
|
252
334
|
markAllAsRead(userId: string): Promise<void>;
|
|
335
|
+
/**
|
|
336
|
+
* Reverts a notification status back to "unread".
|
|
337
|
+
*
|
|
338
|
+
* @param notificationId - The unique ID of the notification.
|
|
339
|
+
*/
|
|
253
340
|
markAsUnread(notificationId: string): Promise<void>;
|
|
341
|
+
/**
|
|
342
|
+
* Marks all notifications belonging to a user as "unread".
|
|
343
|
+
*
|
|
344
|
+
* @param userId - The target user's ID.
|
|
345
|
+
*/
|
|
254
346
|
markAllAsUnread(userId: string): Promise<void>;
|
|
347
|
+
/**
|
|
348
|
+
* Deletes a specific notification from storage.
|
|
349
|
+
*
|
|
350
|
+
* @param notificationId - The Notification ID to delete.
|
|
351
|
+
*/
|
|
255
352
|
delete(notificationId: string): Promise<void>;
|
|
353
|
+
/**
|
|
354
|
+
* Deletes all notifications for a specific user.
|
|
355
|
+
*
|
|
356
|
+
* @param userId - The user's ID.
|
|
357
|
+
*/
|
|
256
358
|
deleteAll(userId: string): Promise<void>;
|
|
359
|
+
/**
|
|
360
|
+
* Retrieves the notification opt-in/opt-out routing preferences for a given user.
|
|
361
|
+
*
|
|
362
|
+
* @param userId - The user's ID.
|
|
363
|
+
* @returns A promise resolving to the user's NotificationPreferences.
|
|
364
|
+
*/
|
|
257
365
|
getPreferences(userId: string): Promise<NotificationPreferences>;
|
|
366
|
+
/**
|
|
367
|
+
* Updates the notification routing and delivery preferences for an user.
|
|
368
|
+
*
|
|
369
|
+
* @param userId - The user's ID.
|
|
370
|
+
* @param prefs - A partial object containing the updated preferences.
|
|
371
|
+
*/
|
|
258
372
|
updatePreferences(userId: string, prefs: Partial<NotificationPreferences>): Promise<void>;
|
|
373
|
+
/**
|
|
374
|
+
* Registers a notification template, mapping a named key to dynamic defaults/formatting.
|
|
375
|
+
*
|
|
376
|
+
* @param template - The NotificationTemplate definitions.
|
|
377
|
+
*/
|
|
259
378
|
registerTemplate(template: NotificationTemplate): void;
|
|
379
|
+
/**
|
|
380
|
+
* Looks up a registered template by its ID.
|
|
381
|
+
*
|
|
382
|
+
* @param id - The ID of the template.
|
|
383
|
+
* @returns The template object, or undefined if not found.
|
|
384
|
+
*/
|
|
260
385
|
getTemplate(id: string): NotificationTemplate | undefined;
|
|
386
|
+
/**
|
|
387
|
+
* Unregisters a template from the NotificationCenter.
|
|
388
|
+
*
|
|
389
|
+
* @param id - The template ID to remove.
|
|
390
|
+
*/
|
|
261
391
|
unregisterTemplate(id: string): void;
|
|
392
|
+
/**
|
|
393
|
+
* Enables batch notification "digests" for a specific user to prevent notification fatigue.
|
|
394
|
+
*
|
|
395
|
+
* @param userId - The user's ID.
|
|
396
|
+
* @param config - The timeframe and configuration for the user's digest.
|
|
397
|
+
*/
|
|
262
398
|
enableDigest(userId: string, config: DigestConfig): Promise<void>;
|
|
399
|
+
/**
|
|
400
|
+
* Disables the digest feature for a user, reverting to immediate delivery.
|
|
401
|
+
*
|
|
402
|
+
* @param userId - The target user's ID.
|
|
403
|
+
*/
|
|
263
404
|
disableDigest(userId: string): Promise<void>;
|
|
405
|
+
/**
|
|
406
|
+
* Fetches the current digest rules configured for a user.
|
|
407
|
+
*
|
|
408
|
+
* @param userId - The user's ID.
|
|
409
|
+
* @returns The digest configuration, or null if disabled.
|
|
410
|
+
*/
|
|
264
411
|
getDigestConfig(userId: string): Promise<DigestConfig | null>;
|
|
412
|
+
/**
|
|
413
|
+
* Retrieves all delivery receipts generated from transports for a specific notification.
|
|
414
|
+
* Useful to see which channels succeeded and which failed.
|
|
415
|
+
*
|
|
416
|
+
* @param notificationId - The notification's ID.
|
|
417
|
+
* @returns An array of delivery receipts.
|
|
418
|
+
*/
|
|
265
419
|
getDeliveryStatus(notificationId: string): Promise<DeliveryReceipt[]>;
|
|
420
|
+
/**
|
|
421
|
+
* Attempts to resend a notification for any channels that previously marked it as "failed".
|
|
422
|
+
*
|
|
423
|
+
* @param notificationId - The target notification ID.
|
|
424
|
+
* @param channel - Optional channel scope. If provided, retries only on this specific transport.
|
|
425
|
+
*/
|
|
266
426
|
retryFailed(notificationId: string, channel?: ChannelType): Promise<void>;
|
|
427
|
+
/**
|
|
428
|
+
* Registers a callback to be invoked whenever a notification is sent to a specific user.
|
|
429
|
+
*
|
|
430
|
+
* @param userId - The target user's ID.
|
|
431
|
+
* @param callback - Function to handle the raw notification map.
|
|
432
|
+
* @returns A cleanup function to unsubscribe from this event.
|
|
433
|
+
*/
|
|
267
434
|
subscribe(userId: string, callback: (notification: Notification) => void): Unsubscribe;
|
|
435
|
+
/**
|
|
436
|
+
* Registers a callback for state changes (e.g. read/unread status updates) for a user's notifications.
|
|
437
|
+
*
|
|
438
|
+
* @param userId - The target user's ID.
|
|
439
|
+
* @param callback - Lifecycle event listener.
|
|
440
|
+
* @returns A cleanup function to unsubscribe.
|
|
441
|
+
*/
|
|
268
442
|
subscribeToEvents(userId: string, callback: (event: NotificationEvent) => void): Unsubscribe;
|
|
443
|
+
/**
|
|
444
|
+
* Registers a listener to react to changes in the unread notification count for a user.
|
|
445
|
+
*
|
|
446
|
+
* @param userId - The user's ID.
|
|
447
|
+
* @param callback - Handlers receiving the current unread count.
|
|
448
|
+
* @returns Unsubscribe function.
|
|
449
|
+
*/
|
|
269
450
|
onUnreadCountChange(userId: string, callback: (count: number, userId: string) => void): Unsubscribe;
|
|
451
|
+
/**
|
|
452
|
+
* Injects a middleware interceptor to apply custom logic before or after notifications are sent.
|
|
453
|
+
*
|
|
454
|
+
* @param middleware - The middleware object conforming to `NotificationMiddleware`.
|
|
455
|
+
*/
|
|
270
456
|
use(middleware: NotificationMiddleware): void;
|
|
457
|
+
/**
|
|
458
|
+
* Removes a previously configured middleware globally.
|
|
459
|
+
*
|
|
460
|
+
* @param name - The name identifier of the middleware to remove.
|
|
461
|
+
*/
|
|
271
462
|
removeMiddleware(name: string): void;
|
|
463
|
+
/**
|
|
464
|
+
* Boots up the NotificationCenter, initializing storage, queues, and worker loops if enabled.
|
|
465
|
+
*/
|
|
272
466
|
start(): Promise<void>;
|
|
467
|
+
/**
|
|
468
|
+
* Gracefully shuts down the NotificationCenter, terminating background queues and workers.
|
|
469
|
+
*/
|
|
273
470
|
stop(): Promise<void>;
|
|
471
|
+
/**
|
|
472
|
+
* Pings all registered transports to report on their current health and active status.
|
|
473
|
+
*
|
|
474
|
+
* @returns A map representing the readiness boolean state of each registered transport.
|
|
475
|
+
*/
|
|
274
476
|
healthCheck(): Promise<Record<string, boolean>>;
|
|
477
|
+
/**
|
|
478
|
+
* Applies metadata, templates, and defaults to construct the internal Notification shape.
|
|
479
|
+
*/
|
|
275
480
|
private buildNotification;
|
|
481
|
+
/**
|
|
482
|
+
* Internal mechanism sending payload out across desired transports without queue delay.
|
|
483
|
+
*/
|
|
276
484
|
private sendNow;
|
|
277
485
|
private castNotification;
|
|
278
486
|
private startWorker;
|