@warlock.js/notifications 4.8.2 → 4.9.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.
Files changed (83) hide show
  1. package/cjs/index.cjs +18 -18
  2. package/cjs/index.cjs.map +1 -1
  3. package/esm/channels/database-channel.d.mts +1 -1
  4. package/esm/channels/database-channel.d.mts.map +1 -1
  5. package/esm/channels/database-channel.mjs +1 -1
  6. package/esm/channels/database-channel.mjs.map +1 -1
  7. package/esm/channels/mail-channel.d.mts +1 -1
  8. package/esm/channels/mail-channel.d.mts.map +1 -1
  9. package/esm/channels/mail-channel.mjs +1 -1
  10. package/esm/channels/mail-channel.mjs.map +1 -1
  11. package/esm/config.d.mts +1 -1
  12. package/esm/config.d.mts.map +1 -1
  13. package/esm/config.mjs +1 -1
  14. package/esm/config.mjs.map +1 -1
  15. package/esm/contracts/channel.contract.d.mts +1 -1
  16. package/esm/contracts/channel.contract.d.mts.map +1 -1
  17. package/esm/contracts/notification.contract.d.mts +1 -1
  18. package/esm/contracts/notification.contract.d.mts.map +1 -1
  19. package/esm/contracts/preference-provider.contract.d.mts +1 -1
  20. package/esm/contracts/preference-provider.contract.d.mts.map +1 -1
  21. package/esm/contracts/queue-dispatcher.contract.d.mts +1 -1
  22. package/esm/contracts/queue-dispatcher.contract.d.mts.map +1 -1
  23. package/esm/contracts/rate-limiter.contract.d.mts +1 -1
  24. package/esm/contracts/rate-limiter.contract.d.mts.map +1 -1
  25. package/esm/dispatch/define-channel.d.mts +1 -1
  26. package/esm/dispatch/define-channel.d.mts.map +1 -1
  27. package/esm/dispatch/define-channel.mjs +1 -1
  28. package/esm/dispatch/define-channel.mjs.map +1 -1
  29. package/esm/dispatch/define-notification.d.mts +1 -1
  30. package/esm/dispatch/define-notification.d.mts.map +1 -1
  31. package/esm/dispatch/define-notification.mjs +1 -1
  32. package/esm/dispatch/define-notification.mjs.map +1 -1
  33. package/esm/dispatch/dispatch-id.mjs +1 -1
  34. package/esm/dispatch/dispatch-id.mjs.map +1 -1
  35. package/esm/dispatch/dispatcher.mjs +1 -1
  36. package/esm/dispatch/dispatcher.mjs.map +1 -1
  37. package/esm/dispatch/notifications-event-bus.d.mts +1 -1
  38. package/esm/dispatch/notifications-event-bus.d.mts.map +1 -1
  39. package/esm/dispatch/notifications-event-bus.mjs +1 -1
  40. package/esm/dispatch/notifications-event-bus.mjs.map +1 -1
  41. package/esm/dispatch/notify.d.mts +1 -1
  42. package/esm/dispatch/notify.d.mts.map +1 -1
  43. package/esm/dispatch/notify.mjs +1 -1
  44. package/esm/dispatch/notify.mjs.map +1 -1
  45. package/esm/errors.d.mts +1 -1
  46. package/esm/errors.d.mts.map +1 -1
  47. package/esm/errors.mjs +1 -1
  48. package/esm/errors.mjs.map +1 -1
  49. package/esm/in-app/base-notifications-repository.d.mts +1 -1
  50. package/esm/in-app/base-notifications-repository.d.mts.map +1 -1
  51. package/esm/in-app/base-notifications-repository.mjs +1 -1
  52. package/esm/in-app/base-notifications-repository.mjs.map +1 -1
  53. package/esm/in-app/column-map.d.mts +1 -1
  54. package/esm/in-app/column-map.d.mts.map +1 -1
  55. package/esm/in-app/column-map.mjs +1 -1
  56. package/esm/in-app/column-map.mjs.map +1 -1
  57. package/esm/in-app/database-notification.d.mts +1 -1
  58. package/esm/in-app/database-notification.d.mts.map +1 -1
  59. package/esm/in-app/database-notification.mjs +1 -1
  60. package/esm/in-app/database-notification.mjs.map +1 -1
  61. package/esm/in-app/in-app.d.mts +1 -1
  62. package/esm/in-app/in-app.d.mts.map +1 -1
  63. package/esm/in-app/in-app.mjs +1 -1
  64. package/esm/in-app/in-app.mjs.map +1 -1
  65. package/esm/migration/notification-columns.d.mts +1 -1
  66. package/esm/migration/notification-columns.d.mts.map +1 -1
  67. package/esm/migration/notification-columns.mjs +1 -1
  68. package/esm/migration/notification-columns.mjs.map +1 -1
  69. package/esm/queue/herald-queue.d.mts +1 -1
  70. package/esm/queue/herald-queue.d.mts.map +1 -1
  71. package/esm/queue/herald-queue.mjs +1 -1
  72. package/esm/queue/herald-queue.mjs.map +1 -1
  73. package/esm/queue/load-herald.d.mts +1 -1
  74. package/esm/queue/load-herald.d.mts.map +1 -1
  75. package/esm/queue/load-herald.mjs +1 -1
  76. package/esm/queue/load-herald.mjs.map +1 -1
  77. package/esm/queue/notifications-worker.d.mts +1 -1
  78. package/esm/queue/notifications-worker.d.mts.map +1 -1
  79. package/esm/queue/notifications-worker.mjs +1 -1
  80. package/esm/queue/notifications-worker.mjs.map +1 -1
  81. package/esm/types.d.mts +1 -1
  82. package/esm/types.d.mts.map +1 -1
  83. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"mail-channel.mjs","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/channels/mail-channel.ts"],"sourcesContent":["/**\n * `mailChannel` — wraps `@warlock.js/core` `sendMail`.\n *\n * Route is `notifiable.email` by convention; override via `config.route`\n * when the column is named differently or computed.\n *\n * The renderer's payload is forwarded verbatim (`subject`, `html`, `text`,\n * `cc`). `from` is set once at channel-config time; per-send overrides go\n * through the payload itself (you can include `from` in `MailPayload` if\n * you extend the registry — but the convention is one channel = one\n * sender identity).\n *\n * @example\n * // src/config/notifications.ts\n * channels: {\n * mail: mailChannel({ from: \"no-reply@store.com\" }),\n * }\n *\n * // anywhere\n * await notify.mail(user, { subject: \"Welcome\", html: \"<p>Hi!</p>\" });\n */\nimport { sendMail } from \"@warlock.js/core\";\nimport type { Channel } from \"../contracts\";\nimport { defineChannel } from \"../dispatch/define-channel\";\nimport type { MailPayload, Notifiable } from \"../types\";\n\nexport type MailChannelConfig = {\n /** Default `from` address for every send through this channel. */\n from?: string;\n /** Route resolver. Defaults to `notifiable.get(\"email\")`. */\n route?: (notifiable: Notifiable) => string;\n};\n\nexport function mailChannel(config: MailChannelConfig = {}): Channel<MailPayload> {\n const resolveRoute = config.route ?? ((n) => n.get(\"email\") as string);\n\n return defineChannel<MailPayload>({\n name: \"mail\",\n route: (notifiable) => resolveRoute(notifiable),\n async send({ payload, route }) {\n await sendMail({\n to: route as string,\n from: config.from,\n ...payload,\n });\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,YAAY,SAA4B,CAAC,GAAyB;CAChF,MAAM,eAAe,OAAO,WAAW,MAAM,EAAE,IAAI,OAAO;CAE1D,OAAO,cAA2B;EAChC,MAAM;EACN,QAAQ,eAAe,aAAa,UAAU;EAC9C,MAAM,KAAK,EAAE,SAAS,SAAS;GAC7B,MAAM,SAAS;IACb,IAAI;IACJ,MAAM,OAAO;IACb,GAAG;GACL,CAAC;EACH;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"mail-channel.mjs","names":[],"sources":["../../../../../../../notifications/src/channels/mail-channel.ts"],"sourcesContent":["/**\n * `mailChannel` — wraps `@warlock.js/core` `sendMail`.\n *\n * Route is `notifiable.email` by convention; override via `config.route`\n * when the column is named differently or computed.\n *\n * The renderer's payload is forwarded verbatim (`subject`, `html`, `text`,\n * `cc`). `from` is set once at channel-config time; per-send overrides go\n * through the payload itself (you can include `from` in `MailPayload` if\n * you extend the registry — but the convention is one channel = one\n * sender identity).\n *\n * @example\n * // src/config/notifications.ts\n * channels: {\n * mail: mailChannel({ from: \"no-reply@store.com\" }),\n * }\n *\n * // anywhere\n * await notify.mail(user, { subject: \"Welcome\", html: \"<p>Hi!</p>\" });\n */\nimport { sendMail } from \"@warlock.js/core\";\nimport type { Channel } from \"../contracts\";\nimport { defineChannel } from \"../dispatch/define-channel\";\nimport type { MailPayload, Notifiable } from \"../types\";\n\nexport type MailChannelConfig = {\n /** Default `from` address for every send through this channel. */\n from?: string;\n /** Route resolver. Defaults to `notifiable.get(\"email\")`. */\n route?: (notifiable: Notifiable) => string;\n};\n\nexport function mailChannel(config: MailChannelConfig = {}): Channel<MailPayload> {\n const resolveRoute = config.route ?? ((n) => n.get(\"email\") as string);\n\n return defineChannel<MailPayload>({\n name: \"mail\",\n route: (notifiable) => resolveRoute(notifiable),\n async send({ payload, route }) {\n await sendMail({\n to: route as string,\n from: config.from,\n ...payload,\n });\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,YAAY,SAA4B,CAAC,GAAyB;CAChF,MAAM,eAAe,OAAO,WAAW,MAAM,EAAE,IAAI,OAAO;CAE1D,OAAO,cAA2B;EAChC,MAAM;EACN,QAAQ,eAAe,aAAa,UAAU;EAC9C,MAAM,KAAK,EAAE,SAAS,SAAS;GAC7B,MAAM,SAAS;IACb,IAAI;IACJ,MAAM,OAAO;IACb,GAAG;GACL,CAAC;EACH;CACF,CAAC;AACH"}
package/esm/config.d.mts CHANGED
@@ -3,7 +3,7 @@ import { Channel } from "./contracts/channel.contract.mjs";
3
3
  import { PreferenceProvider } from "./contracts/preference-provider.contract.mjs";
4
4
  import { QueueDispatcher } from "./contracts/queue-dispatcher.contract.mjs";
5
5
  import { RateLimiter } from "./contracts/rate-limiter.contract.mjs";
6
- //#region ../@warlock.js/notifications/src/config.d.ts
6
+ //#region ../notifications/src/config.d.ts
7
7
  /**
8
8
  * Channel registry — each key is a registered channel name, each value the
9
9
  * channel whose payload type matches the registry. Typed as a partial map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.mts","names":[],"sources":["../../../../../../@warlock.js/notifications/src/config.ts"],"mappings":";;;;;;;;AAuCoD;AAQpD;;;;;KATY,UAAA,GAAa,OAAA,SACjB,WAAA,GAAc,OAAA,CAAQ,oBAAA,CAAqB,CAAA;;;;;;KAQvC,kBAAA;EAMI,4EAJd,QAAA,EAAU,UAAA,EAME;EAJZ,KAAA,GAAQ,eAAA,EAIe;EAFvB,WAAA,GAAc,kBAAA,EAaqB;EAXnC,SAAA,GAAY,WAAA;AAAA;AAWkD;AAQhE;;;;AAA2D;AARK,iBAAhD,qBAAA,CAAsB,MAA0B,EAAlB,kBAAkB;;;;AAmBzB;iBAXvB,qBAAA,IAAyB,kBAAkB;;;;;iBAW3C,uBAAA"}
1
+ {"version":3,"file":"config.d.mts","names":[],"sources":["../../../../../../notifications/src/config.ts"],"mappings":";;;;;;;;AAuCoD;AAQpD;;;;;KATY,UAAA,GAAa,OAAA,SACjB,WAAA,GAAc,OAAA,CAAQ,oBAAA,CAAqB,CAAA;;;;;;KAQvC,kBAAA;EAMI,4EAJd,QAAA,EAAU,UAAA,EAME;EAJZ,KAAA,GAAQ,eAAA,EAIe;EAFvB,WAAA,GAAc,kBAAA,EAaqB;EAXnC,SAAA,GAAY,WAAA;AAAA;AAWkD;AAQhE;;;;AAA2D;AARK,iBAAhD,qBAAA,CAAsB,MAA0B,EAAlB,kBAAkB;;;;AAmBzB;iBAXvB,qBAAA,IAAyB,kBAAkB;;;;;iBAW3C,uBAAA"}
package/esm/config.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { NotificationsNotConfiguredError } from "./errors.mjs";
2
2
 
3
- //#region ../@warlock.js/notifications/src/config.ts
3
+ //#region ../notifications/src/config.ts
4
4
  let activeConfig;
5
5
  /**
6
6
  * Set the active notifications configuration. In a Warlock app the
@@ -1 +1 @@
1
- {"version":3,"file":"config.mjs","names":[],"sources":["../../../../../../@warlock.js/notifications/src/config.ts"],"sourcesContent":["/**\n * Notification configuration holder — the runtime singleton the dispatch core\n * reads from. In a Warlock app you do NOT call `setNotificationConfig`\n * directly: `src/config/notifications.ts` exports a `NotificationConfig` as its\n * default, and the notifications connector calls this at boot. Tests (and\n * non-Warlock embeddings) may call it directly.\n *\n * @example src/config/notifications.ts — declarative; the connector registers it\n * import { type NotificationConfig, mailChannel, inApp } from \"@warlock.js/notifications\";\n * import { Notification } from \"app/notifications/notification.model\";\n *\n * const config: NotificationConfig = {\n * channels: {\n * mail: mailChannel({ from: \"no-reply@store.com\" }),\n * database: inApp.configure({ model: Notification }),\n * },\n * // preferences / rateLimit / queue all optional\n * };\n *\n * export default config;\n */\nimport type {\n Channel,\n PreferenceProvider,\n QueueDispatcher,\n RateLimiter,\n} from \"./contracts\";\nimport { NotificationsNotConfiguredError } from \"./errors\";\nimport type { ChannelName, NotificationChannels } from \"./types\";\n\n/**\n * Channel registry — each key is a registered channel name, each value the\n * channel whose payload type matches the registry. Typed as a partial map\n * over `ChannelName` so `setNotificationConfig` rejects a channel whose\n * payload doesn't line up with its registry entry, AND so a custom channel\n * (declaration-merged into `NotificationChannels`) is accepted with its real\n * payload type rather than `any`.\n */\nexport type ChannelMap = Partial<{\n [C in ChannelName]: Channel<NotificationChannels[C]>;\n}>;\n\n/**\n * Runtime configuration the dispatcher reads on every send. `queue`,\n * `preferences`, and `rateLimit` are all OPTIONAL slots — the package\n * reserves their shape but ships no defaults.\n */\nexport type NotificationConfig = {\n /** Channel registry — keys correlate to `NotificationChannels` payloads. */\n channels: ChannelMap;\n /** Async dispatcher backing `.queue()`. Phase 2 ships a herald impl. */\n queue?: QueueDispatcher;\n /** Pre-send gate: drops channels the recipient opted out of. */\n preferences?: PreferenceProvider;\n /** Pre-send gate: drops channels exceeding per-recipient budgets. */\n rateLimit?: RateLimiter;\n};\n\nlet activeConfig: NotificationConfig | undefined;\n\n/**\n * Set the active notifications configuration. In a Warlock app the\n * notifications connector calls this at boot with the default export of\n * `src/config/notifications.ts`. Subsequent calls REPLACE the active config\n * (does not merge) — pass the complete config, not a partial.\n */\nexport function setNotificationConfig(config: NotificationConfig): void {\n activeConfig = config;\n}\n\n/**\n * Get the active notifications configuration. Throws if not yet configured —\n * fail loudly at the first send rather than silently doing nothing.\n */\nexport function getNotificationConfig(): NotificationConfig {\n if (!activeConfig) {\n throw new NotificationsNotConfiguredError();\n }\n return activeConfig;\n}\n\n/**\n * Clear the active configuration. Intended for tests; not part of the runtime\n * surface. Production code should never call this.\n */\nexport function resetNotificationConfig(): void {\n activeConfig = undefined;\n}\n"],"mappings":";;;AA0DA,IAAI;;;;;;;AAQJ,SAAgB,sBAAsB,QAAkC;CACtE,eAAe;AACjB;;;;;AAMA,SAAgB,wBAA4C;CAC1D,IAAI,CAAC,cACH,MAAM,IAAI,gCAAgC;CAE5C,OAAO;AACT;;;;;AAMA,SAAgB,0BAAgC;CAC9C,eAAe;AACjB"}
1
+ {"version":3,"file":"config.mjs","names":[],"sources":["../../../../../../notifications/src/config.ts"],"sourcesContent":["/**\n * Notification configuration holder — the runtime singleton the dispatch core\n * reads from. In a Warlock app you do NOT call `setNotificationConfig`\n * directly: `src/config/notifications.ts` exports a `NotificationConfig` as its\n * default, and the notifications connector calls this at boot. Tests (and\n * non-Warlock embeddings) may call it directly.\n *\n * @example src/config/notifications.ts — declarative; the connector registers it\n * import { type NotificationConfig, mailChannel, inApp } from \"@warlock.js/notifications\";\n * import { Notification } from \"app/notifications/notification.model\";\n *\n * const config: NotificationConfig = {\n * channels: {\n * mail: mailChannel({ from: \"no-reply@store.com\" }),\n * database: inApp.configure({ model: Notification }),\n * },\n * // preferences / rateLimit / queue all optional\n * };\n *\n * export default config;\n */\nimport type {\n Channel,\n PreferenceProvider,\n QueueDispatcher,\n RateLimiter,\n} from \"./contracts\";\nimport { NotificationsNotConfiguredError } from \"./errors\";\nimport type { ChannelName, NotificationChannels } from \"./types\";\n\n/**\n * Channel registry — each key is a registered channel name, each value the\n * channel whose payload type matches the registry. Typed as a partial map\n * over `ChannelName` so `setNotificationConfig` rejects a channel whose\n * payload doesn't line up with its registry entry, AND so a custom channel\n * (declaration-merged into `NotificationChannels`) is accepted with its real\n * payload type rather than `any`.\n */\nexport type ChannelMap = Partial<{\n [C in ChannelName]: Channel<NotificationChannels[C]>;\n}>;\n\n/**\n * Runtime configuration the dispatcher reads on every send. `queue`,\n * `preferences`, and `rateLimit` are all OPTIONAL slots — the package\n * reserves their shape but ships no defaults.\n */\nexport type NotificationConfig = {\n /** Channel registry — keys correlate to `NotificationChannels` payloads. */\n channels: ChannelMap;\n /** Async dispatcher backing `.queue()`. Phase 2 ships a herald impl. */\n queue?: QueueDispatcher;\n /** Pre-send gate: drops channels the recipient opted out of. */\n preferences?: PreferenceProvider;\n /** Pre-send gate: drops channels exceeding per-recipient budgets. */\n rateLimit?: RateLimiter;\n};\n\nlet activeConfig: NotificationConfig | undefined;\n\n/**\n * Set the active notifications configuration. In a Warlock app the\n * notifications connector calls this at boot with the default export of\n * `src/config/notifications.ts`. Subsequent calls REPLACE the active config\n * (does not merge) — pass the complete config, not a partial.\n */\nexport function setNotificationConfig(config: NotificationConfig): void {\n activeConfig = config;\n}\n\n/**\n * Get the active notifications configuration. Throws if not yet configured —\n * fail loudly at the first send rather than silently doing nothing.\n */\nexport function getNotificationConfig(): NotificationConfig {\n if (!activeConfig) {\n throw new NotificationsNotConfiguredError();\n }\n return activeConfig;\n}\n\n/**\n * Clear the active configuration. Intended for tests; not part of the runtime\n * surface. Production code should never call this.\n */\nexport function resetNotificationConfig(): void {\n activeConfig = undefined;\n}\n"],"mappings":";;;AA0DA,IAAI;;;;;;;AAQJ,SAAgB,sBAAsB,QAAkC;CACtE,eAAe;AACjB;;;;;AAMA,SAAgB,wBAA4C;CAC1D,IAAI,CAAC,cACH,MAAM,IAAI,gCAAgC;CAE5C,OAAO;AACT;;;;;AAMA,SAAgB,0BAAgC;CAC9C,eAAe;AACjB"}
@@ -1,6 +1,6 @@
1
1
  import { Id, Notifiable, SendOptions } from "../types.mjs";
2
2
 
3
- //#region ../@warlock.js/notifications/src/contracts/channel.contract.d.ts
3
+ //#region ../notifications/src/contracts/channel.contract.d.ts
4
4
  /**
5
5
  * A channel = one `send` + how it resolves a route from a notifiable.
6
6
  *
@@ -1 +1 @@
1
- {"version":3,"file":"channel.contract.d.mts","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/contracts/channel.contract.ts"],"mappings":";;;;;AAUA;;;;;;UAAiB,OAAA;EAkBA;EAAA,SAhBN,IAAA;EAkBL;;;;;EAXJ,KAAA,EAAO,UAAA,EAAY,UAAA;IAAwB,EAAA,EAAI,EAAA;EAAA;EAAJ;;;;EAM3C,IAAA,CAAK,GAAA;IACH,OAAA,EAAS,CAAA;IACT,KAAA;MAAkB,EAAA,EAAI,EAAA;IAAA;IACtB,UAAA,GAAa,UAAA;IACb,OAAA,EAAS,WAAA;EAAA,IACP,OAAA;AAAA"}
1
+ {"version":3,"file":"channel.contract.d.mts","names":[],"sources":["../../../../../../../notifications/src/contracts/channel.contract.ts"],"mappings":";;;;;AAUA;;;;;;UAAiB,OAAA;EAkBA;EAAA,SAhBN,IAAA;EAkBL;;;;;EAXJ,KAAA,EAAO,UAAA,EAAY,UAAA;IAAwB,EAAA,EAAI,EAAA;EAAA;EAAJ;;;;EAM3C,IAAA,CAAK,GAAA;IACH,OAAA,EAAS,CAAA;IACT,KAAA;MAAkB,EAAA,EAAI,EAAA;IAAA;IACtB,UAAA,GAAa,UAAA;IACb,OAAA,EAAS,WAAA;EAAA,IACP,OAAA;AAAA"}
@@ -1,6 +1,6 @@
1
1
  import { Id } from "../types.mjs";
2
2
 
3
- //#region ../@warlock.js/notifications/src/contracts/notification.contract.d.ts
3
+ //#region ../notifications/src/contracts/notification.contract.d.ts
4
4
  /**
5
5
  * The stored in-app record contract the database channel + `inApp` depend on.
6
6
  * Accessors are the STABLE surface; physical columns vary per app and are
@@ -1 +1 @@
1
- {"version":3,"file":"notification.contract.d.mts","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/contracts/notification.contract.ts"],"mappings":";;;;;AAOA;;;UAAiB,oBAAA;EAAA,SACN,WAAA,EAAa,EAAA;EAAA,SACb,IAAA;EAAA,SACA,MAAA;EAAA,SACA,MAAA,EAAQ,IAAA;EACjB,QAAA,IAAY,OAAA;AAAA"}
1
+ {"version":3,"file":"notification.contract.d.mts","names":[],"sources":["../../../../../../../notifications/src/contracts/notification.contract.ts"],"mappings":";;;;;AAOA;;;UAAiB,oBAAA;EAAA,SACN,WAAA,EAAa,EAAA;EAAA,SACb,IAAA;EAAA,SACA,MAAA;EAAA,SACA,MAAA,EAAQ,IAAA;EACjB,QAAA,IAAY,OAAA;AAAA"}
@@ -1,6 +1,6 @@
1
1
  import { ChannelName, Notifiable } from "../types.mjs";
2
2
 
3
- //#region ../@warlock.js/notifications/src/contracts/preference-provider.contract.d.ts
3
+ //#region ../notifications/src/contracts/preference-provider.contract.d.ts
4
4
  /**
5
5
  * Pre-send gate consulted BEFORE each channel dispatch. Returns the subset of
6
6
  * `requested` channels this recipient accepts (mute lists, quiet hours,
@@ -1 +1 @@
1
- {"version":3,"file":"preference-provider.contract.d.mts","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/contracts/preference-provider.contract.ts"],"mappings":";;;;;AAaA;;;;;;;;;UAAiB,kBAAA;EACf,eAAA,CACE,UAAA,EAAY,UAAA,EACZ,IAAA,UACA,iBAAA,EAAmB,WAAA,KAClB,OAAA,CAAQ,WAAA,MAAiB,WAAA;AAAA"}
1
+ {"version":3,"file":"preference-provider.contract.d.mts","names":[],"sources":["../../../../../../../notifications/src/contracts/preference-provider.contract.ts"],"mappings":";;;;;AAaA;;;;;;;;;UAAiB,kBAAA;EACf,eAAA,CACE,UAAA,EAAY,UAAA,EACZ,IAAA,UACA,iBAAA,EAAmB,WAAA,KAClB,OAAA,CAAQ,WAAA,MAAiB,WAAA;AAAA"}
@@ -1,6 +1,6 @@
1
1
  import { SendOptions } from "../types.mjs";
2
2
 
3
- //#region ../@warlock.js/notifications/src/contracts/queue-dispatcher.contract.d.ts
3
+ //#region ../notifications/src/contracts/queue-dispatcher.contract.d.ts
4
4
  /**
5
5
  * Async dispatcher contract — what `.queue(...)` hands rendered jobs to.
6
6
  * The shipped implementation backs onto `@warlock.js/herald` (Phase 2). Apps
@@ -1 +1 @@
1
- {"version":3,"file":"queue-dispatcher.contract.d.mts","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/contracts/queue-dispatcher.contract.ts"],"mappings":";;;;;AAWA;;;;;;;UAAiB,eAAA;EACf,QAAA,CAAS,GAAA;IACP,OAAA;IACA,KAAA;IACA,OAAA;IACA,OAAA,EAAS,WAAA;EAAA,IACP,OAAO;AAAA"}
1
+ {"version":3,"file":"queue-dispatcher.contract.d.mts","names":[],"sources":["../../../../../../../notifications/src/contracts/queue-dispatcher.contract.ts"],"mappings":";;;;;AAWA;;;;;;;UAAiB,eAAA;EACf,QAAA,CAAS,GAAA;IACP,OAAA;IACA,KAAA;IACA,OAAA;IACA,OAAA,EAAS,WAAA;EAAA,IACP,OAAO;AAAA"}
@@ -1,6 +1,6 @@
1
1
  import { ChannelName, Notifiable } from "../types.mjs";
2
2
 
3
- //#region ../@warlock.js/notifications/src/contracts/rate-limiter.contract.d.ts
3
+ //#region ../notifications/src/contracts/rate-limiter.contract.d.ts
4
4
  /**
5
5
  * Per-(recipient, channel, type) rate limit. Return `false` to drop the
6
6
  * channel for this send → a `skipped` event fires with reason `"rate-limit"`.
@@ -1 +1 @@
1
- {"version":3,"file":"rate-limiter.contract.d.mts","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/contracts/rate-limiter.contract.ts"],"mappings":";;;;;AAgBA;;;;;;;;;;;;UAAiB,WAAA;EACf,KAAA,CACE,UAAA,EAAY,UAAA,EACZ,OAAA,EAAS,WAAA,EACT,IAAA,WACC,OAAA;AAAA"}
1
+ {"version":3,"file":"rate-limiter.contract.d.mts","names":[],"sources":["../../../../../../../notifications/src/contracts/rate-limiter.contract.ts"],"mappings":";;;;;AAgBA;;;;;;;;;;;;UAAiB,WAAA;EACf,KAAA,CACE,UAAA,EAAY,UAAA,EACZ,OAAA,EAAS,WAAA,EACT,IAAA,WACC,OAAA;AAAA"}
@@ -1,5 +1,5 @@
1
1
  import { Channel } from "../contracts/channel.contract.mjs";
2
- //#region ../@warlock.js/notifications/src/dispatch/define-channel.d.ts
2
+ //#region ../notifications/src/dispatch/define-channel.d.ts
3
3
  /**
4
4
  * Identity helper that narrows the channel type to its payload. Use it when
5
5
  * you want TypeScript to enforce the `send` payload shape against the
@@ -1 +1 @@
1
- {"version":3,"file":"define-channel.d.mts","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/dispatch/define-channel.ts"],"mappings":";;;;;AAiCA;;;;;;;;;;;;;;;;AAAgE;;;;;;;;;;;;iBAAhD,aAAA,IAAiB,OAAA,EAAS,OAAA,CAAQ,CAAA,IAAK,OAAA,CAAQ,CAAA"}
1
+ {"version":3,"file":"define-channel.d.mts","names":[],"sources":["../../../../../../../notifications/src/dispatch/define-channel.ts"],"mappings":";;;;;AAiCA;;;;;;;;;;;;;;;;AAAgE;;;;;;;;;;;;iBAAhD,aAAA,IAAiB,OAAA,EAAS,OAAA,CAAQ,CAAA,IAAK,OAAA,CAAQ,CAAA"}
@@ -1,4 +1,4 @@
1
- //#region ../@warlock.js/notifications/src/dispatch/define-channel.ts
1
+ //#region ../notifications/src/dispatch/define-channel.ts
2
2
  /**
3
3
  * Identity helper that narrows the channel type to its payload. Use it when
4
4
  * you want TypeScript to enforce the `send` payload shape against the
@@ -1 +1 @@
1
- {"version":3,"file":"define-channel.mjs","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/dispatch/define-channel.ts"],"sourcesContent":["import type { Channel } from \"../contracts\";\n\n/**\n * Identity helper that narrows the channel type to its payload. Use it when\n * you want TypeScript to enforce the `send` payload shape against the\n * payload type you declared.\n *\n * Built-in channels (`mail`, `database`) ship as factories; custom channels\n * are usually defined with this helper.\n *\n * @example\n * import { defineChannel } from \"@warlock.js/notifications\";\n *\n * type DiscordPayload = { content: string };\n *\n * export const discordChannel = () =>\n * defineChannel<DiscordPayload>({\n * name: \"discord\",\n * route: (n) => n.get(\"discord_webhook\"),\n * async send({ payload, route }) {\n * await fetch(route as string, {\n * method: \"POST\",\n * headers: { \"content-type\": \"application/json\" },\n * body: JSON.stringify(payload),\n * });\n * },\n * });\n *\n * // Then teach the registry:\n * declare module \"@warlock.js/notifications\" {\n * interface NotificationChannels { discord: DiscordPayload }\n * }\n */\nexport function defineChannel<P>(channel: Channel<P>): Channel<P> {\n return channel;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,cAAiB,SAAiC;CAChE,OAAO;AACT"}
1
+ {"version":3,"file":"define-channel.mjs","names":[],"sources":["../../../../../../../notifications/src/dispatch/define-channel.ts"],"sourcesContent":["import type { Channel } from \"../contracts\";\n\n/**\n * Identity helper that narrows the channel type to its payload. Use it when\n * you want TypeScript to enforce the `send` payload shape against the\n * payload type you declared.\n *\n * Built-in channels (`mail`, `database`) ship as factories; custom channels\n * are usually defined with this helper.\n *\n * @example\n * import { defineChannel } from \"@warlock.js/notifications\";\n *\n * type DiscordPayload = { content: string };\n *\n * export const discordChannel = () =>\n * defineChannel<DiscordPayload>({\n * name: \"discord\",\n * route: (n) => n.get(\"discord_webhook\"),\n * async send({ payload, route }) {\n * await fetch(route as string, {\n * method: \"POST\",\n * headers: { \"content-type\": \"application/json\" },\n * body: JSON.stringify(payload),\n * });\n * },\n * });\n *\n * // Then teach the registry:\n * declare module \"@warlock.js/notifications\" {\n * interface NotificationChannels { discord: DiscordPayload }\n * }\n */\nexport function defineChannel<P>(channel: Channel<P>): Channel<P> {\n return channel;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,cAAiB,SAAiC;CAChE,OAAO;AACT"}
@@ -1,6 +1,6 @@
1
1
  import { ChannelName, Notifiable, NotificationChannels, RenderContext, SendOptions } from "../types.mjs";
2
2
 
3
- //#region ../@warlock.js/notifications/src/dispatch/define-notification.d.ts
3
+ //#region ../notifications/src/dispatch/define-notification.d.ts
4
4
  /**
5
5
  * Per-channel renderer return type. The `database` renderer may OMIT `type`
6
6
  * — it inherits from `NotificationDef.type` at dispatch time.
@@ -1 +1 @@
1
- {"version":3,"file":"define-notification.d.mts","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/dispatch/define-notification.ts"],"mappings":";;;;;AA4CkB;;KASb,cAAA,WAAyB,WAAA,IAAe,CAAA,sBACzC,IAAA,CAAK,oBAAA,wBACL,oBAAA,CAAqB,CAAA;AAAA,KAEpB,QAAA,iBAAyB,WAAA,KAC5B,IAAA,EAAM,IAAA,EACN,EAAA,EAAI,UAAA,EACJ,GAAA,EAAK,aAAA,KACF,cAAA,CAAe,CAAA;AAAA,KAER,eAAA;EACV,IAAA;EACA,GAAA,EAAK,WAAA,OAAkB,IAAA,EAAM,IAAA,EAAM,EAAA,EAAI,UAAA,KAAe,WAAA;AAAA,YAEhD,WAAA,IAAe,QAAA,CAAS,IAAA,EAAM,CAAA;AAAA,UAGrB,mBAAA;EACf,IAAA,CAAK,EAAA,EAAI,UAAA,GAAa,UAAA,IAAc,IAAA,EAAM,IAAA,EAAM,OAAA,GAAU,WAAA,GAAc,OAAA;EACxE,KAAA,CAAM,EAAA,EAAI,UAAA,GAAa,UAAA,IAAc,IAAA,EAAM,IAAA,EAAM,OAAA,GAAU,WAAA,GAAc,OAAA;EACzE,IAAA,IAAQ,QAAA,EAAU,WAAA,KAAgB,mBAAA,CAAoB,IAAA;AAAA;AAAA,iBAYxC,kBAAA,OAAyB,GAAA,EAAK,eAAA,CAAgB,IAAA,IAAQ,mBAAA,CAAoB,IAAA"}
1
+ {"version":3,"file":"define-notification.d.mts","names":[],"sources":["../../../../../../../notifications/src/dispatch/define-notification.ts"],"mappings":";;;;;AA4CkB;;KASb,cAAA,WAAyB,WAAA,IAAe,CAAA,sBACzC,IAAA,CAAK,oBAAA,wBACL,oBAAA,CAAqB,CAAA;AAAA,KAEpB,QAAA,iBAAyB,WAAA,KAC5B,IAAA,EAAM,IAAA,EACN,EAAA,EAAI,UAAA,EACJ,GAAA,EAAK,aAAA,KACF,cAAA,CAAe,CAAA;AAAA,KAER,eAAA;EACV,IAAA;EACA,GAAA,EAAK,WAAA,OAAkB,IAAA,EAAM,IAAA,EAAM,EAAA,EAAI,UAAA,KAAe,WAAA;AAAA,YAEhD,WAAA,IAAe,QAAA,CAAS,IAAA,EAAM,CAAA;AAAA,UAGrB,mBAAA;EACf,IAAA,CAAK,EAAA,EAAI,UAAA,GAAa,UAAA,IAAc,IAAA,EAAM,IAAA,EAAM,OAAA,GAAU,WAAA,GAAc,OAAA;EACxE,KAAA,CAAM,EAAA,EAAI,UAAA,GAAa,UAAA,IAAc,IAAA,EAAM,IAAA,EAAM,OAAA,GAAU,WAAA,GAAc,OAAA;EACzE,IAAA,IAAQ,QAAA,EAAU,WAAA,KAAgB,mBAAA,CAAoB,IAAA;AAAA;AAAA,iBAYxC,kBAAA,OAAyB,GAAA,EAAK,eAAA,CAAgB,IAAA,IAAQ,mBAAA,CAAoB,IAAA"}
@@ -5,7 +5,7 @@ import { emit } from "./notifications-event-bus.mjs";
5
5
  import { dispatchChannel } from "./dispatcher.mjs";
6
6
  import { log } from "@warlock.js/logger";
7
7
 
8
- //#region ../@warlock.js/notifications/src/dispatch/define-notification.ts
8
+ //#region ../notifications/src/dispatch/define-notification.ts
9
9
  /**
10
10
  * `defineNotification` — reusable, type-safe, multi-channel notification.
11
11
  *
@@ -1 +1 @@
1
- {"version":3,"file":"define-notification.mjs","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/dispatch/define-notification.ts"],"sourcesContent":["/**\n * `defineNotification` — reusable, type-safe, multi-channel notification.\n *\n * Functional, not class-based: pass `via` + a renderer per channel + a\n * stable `type`. The returned object exposes `.send` / `.queue` / `.only`.\n *\n * Renderer signature is `(data, to, ctx)` where `ctx` carries `locale` and\n * `meta` from `SendOptions`. The database renderer's `type` is OPTIONAL — the\n * dispatcher injects `def.type`, keeping the type defined in ONE place.\n *\n * ## Error policy\n * - **Config errors** (missing renderer, no queue dispatcher, unknown channel)\n * are programmer mistakes → they REJECT `.send()`/`.queue()` (and a static\n * `via` with a missing renderer throws at definition time). Consistent with\n * `notify`, which rejects `ChannelNotFoundError`.\n * - **Transport errors** (a channel's `send` throwing) stay ISOLATED — emitted\n * as a `failed` event, never aborting sibling channels/recipients.\n * - **`via()` / preferences throws** for one recipient are logged and that\n * recipient is dropped (the rest of a fan-out still go).\n *\n * @example\n * export const orderShipped = defineNotification<{ order: Order }>({\n * type: \"order.shipped\",\n * via: [\"mail\", \"database\"],\n * mail: ({ order }, to) => ({ subject: `#${order.number} shipped`, html: \"…\" }),\n * database: ({ order }) => ({ title: \"Your order shipped\", payload: { id: order.id } }),\n * });\n * await orderShipped.send(user, { order });\n * await orderShipped.queue([buyer, salesRep], { order }, { delay: \"10m\" });\n * await orderShipped.only(\"mail\").send(user, { order });\n */\nimport { log } from \"@warlock.js/logger\";\nimport { getNotificationConfig } from \"../config\";\nimport {\n ChannelNotFoundError,\n MissingRendererError,\n NoQueueDispatcherError,\n} from \"../errors\";\nimport type {\n ChannelName,\n Notifiable,\n NotificationChannels,\n RenderContext,\n SendOptions,\n} from \"../types\";\nimport { newDispatchId } from \"./dispatch-id\";\nimport { dispatchChannel, type DispatchMode } from \"./dispatcher\";\nimport { emit } from \"./notifications-event-bus\";\n\n/**\n * Per-channel renderer return type. The `database` renderer may OMIT `type`\n * — it inherits from `NotificationDef.type` at dispatch time.\n */\ntype RendererReturn<C extends ChannelName> = C extends \"database\"\n ? Omit<NotificationChannels[\"database\"], \"type\">\n : NotificationChannels[C];\n\ntype Renderer<Data, C extends ChannelName> = (\n data: Data,\n to: Notifiable,\n ctx: RenderContext,\n) => RendererReturn<C>;\n\nexport type NotificationDef<Data> = {\n type: string;\n via: ChannelName[] | ((data: Data, to: Notifiable) => ChannelName[]);\n} & {\n [C in ChannelName]?: Renderer<Data, C>;\n};\n\nexport interface DefinedNotification<Data> {\n send(to: Notifiable | Notifiable[], data: Data, options?: SendOptions): Promise<void>;\n queue(to: Notifiable | Notifiable[], data: Data, options?: SendOptions): Promise<void>;\n only(...channels: ChannelName[]): DefinedNotification<Data>;\n}\n\n/** Errors that represent a misconfiguration and must surface (reject), not isolate. */\nfunction isConfigError(error: unknown): boolean {\n return (\n error instanceof MissingRendererError ||\n error instanceof NoQueueDispatcherError ||\n error instanceof ChannelNotFoundError\n );\n}\n\nexport function defineNotification<Data>(def: NotificationDef<Data>): DefinedNotification<Data> {\n const make = (restrict?: ChannelName[]): DefinedNotification<Data> => {\n // Validate at definition time when the channel set is static — a missing\n // renderer is a programmer error, surfaced loudly at import.\n if (Array.isArray(def.via)) {\n const channels = restrict ? def.via.filter((c) => restrict.includes(c)) : def.via;\n for (const channel of channels) {\n if (!def[channel]) {\n throw new MissingRendererError(def.type, channel);\n }\n }\n }\n\n return {\n send(to, data, options) {\n return dispatchAll(def, to, data, options ?? {}, \"send\", restrict);\n },\n queue(to, data, options) {\n return dispatchAll(def, to, data, options ?? {}, \"queue\", restrict);\n },\n only(...channels) {\n return make(channels);\n },\n };\n };\n\n return make();\n}\n\n/**\n * Fan-out to all recipients. Each recipient dispatches independently; one\n * recipient's transport failure never aborts the others. CONFIG errors,\n * however, propagate — they reject the returned promise.\n */\nasync function dispatchAll<Data>(\n def: NotificationDef<Data>,\n to: Notifiable | Notifiable[],\n data: Data,\n options: SendOptions,\n mode: DispatchMode,\n restrict?: ChannelName[],\n): Promise<void> {\n const recipients = Array.isArray(to) ? to : [to];\n\n const results = await Promise.allSettled(\n recipients.map((recipient) =>\n dispatchToRecipient(def, recipient, data, options, mode, restrict),\n ),\n );\n\n rethrowConfigErrors(results);\n}\n\nasync function dispatchToRecipient<Data>(\n def: NotificationDef<Data>,\n to: Notifiable,\n data: Data,\n options: SendOptions,\n mode: DispatchMode,\n restrict?: ChannelName[],\n): Promise<void> {\n const config = getNotificationConfig();\n\n // Resolve channels (via + preferences). A throw here drops THIS recipient\n // with a log — it's a per-recipient data problem, not a config error.\n let channels: ChannelName[];\n try {\n channels = typeof def.via === \"function\" ? def.via(data, to) : [...def.via];\n\n if (restrict) {\n channels = channels.filter((c) => restrict.includes(c));\n }\n\n if (!options.force && config.preferences) {\n const allowed = await config.preferences.resolveChannels(to, def.type, channels);\n for (const channel of channels.filter((c) => !allowed.includes(c))) {\n await emit(\"skipped\", {\n dispatchId: newDispatchId(),\n channel,\n notifiable: to,\n reason: \"preference\",\n options,\n });\n }\n channels = channels.filter((c) => allowed.includes(c));\n }\n } catch (error) {\n log.error(\"notifications\", `resolve.${def.type}`, error as Error);\n return;\n }\n\n const renderCtx: RenderContext = { locale: options.locale, meta: options.meta };\n\n const results = await Promise.allSettled(\n channels.map((name) => {\n const renderer = def[name] as Renderer<Data, ChannelName> | undefined;\n if (!renderer) {\n // Dynamic via chose a channel with no renderer — surface it.\n return Promise.reject(new MissingRendererError(def.type, name));\n }\n\n let payload: unknown = renderer(data, to, renderCtx);\n\n // Default the database channel's `type` from `def.type` when omitted.\n if (name === \"database\" && payload && typeof payload === \"object\" && !(\"type\" in payload)) {\n payload = { ...(payload as object), type: def.type };\n }\n\n return dispatchChannel({\n channelName: name,\n payload,\n to,\n notificationType: def.type,\n mode,\n options,\n });\n }),\n );\n\n rethrowConfigErrors(results);\n}\n\n/** Collect config-class rejections and rethrow (single or AggregateError). */\nfunction rethrowConfigErrors(results: PromiseSettledResult<unknown>[]): void {\n const configErrors = results\n .filter((r): r is PromiseRejectedResult => r.status === \"rejected\" && isConfigError(r.reason))\n .map((r) => r.reason);\n\n if (configErrors.length === 1) {\n throw configErrors[0];\n }\n if (configErrors.length > 1) {\n throw new AggregateError(configErrors, \"Multiple notification configuration errors\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,SAAS,cAAc,OAAyB;CAC9C,OACE,iBAAiB,wBACjB,iBAAiB,0BACjB,iBAAiB;AAErB;AAEA,SAAgB,mBAAyB,KAAuD;CAC9F,MAAM,QAAQ,aAAwD;EAGpE,IAAI,MAAM,QAAQ,IAAI,GAAG,GAAG;GAC1B,MAAM,WAAW,WAAW,IAAI,IAAI,QAAQ,MAAM,SAAS,SAAS,CAAC,CAAC,IAAI,IAAI;GAC9E,KAAK,MAAM,WAAW,UACpB,IAAI,CAAC,IAAI,UACP,MAAM,IAAI,qBAAqB,IAAI,MAAM,OAAO;EAGtD;EAEA,OAAO;GACL,KAAK,IAAI,MAAM,SAAS;IACtB,OAAO,YAAY,KAAK,IAAI,MAAM,WAAW,CAAC,GAAG,QAAQ,QAAQ;GACnE;GACA,MAAM,IAAI,MAAM,SAAS;IACvB,O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EH,OAAO,QAAQ,OAAO,IAAI,qBAAqB,IAAI,MAAM,IAAI,CAAC;EAGhE,IAAI,UAAmB,SAAS,MAAM,IAAI,SAAS;EAGnD,IAAI,SAAS,cAAc,WAAW,OAAO,YAAY,YAAY,EAAE,UAAU,UAC/E,UAAU;GAAE,GAAI;GAAoB,MAAM,IAAI;EAAK;EAGrD,OAAO,gBAAgB;GACrB,aAAa;GACb;GACA;GACA,kBAAkB,IAAI;GACtB;GACA;EACF,CAAC;CACH,CAAC,CACH,CAE2B;AAC7B;;AAGA,SAAS,oBAAoB,SAAgD;CAC3E,MAAM,eAAe,QAClB,QAAQ,MAAkC,EAAE,WAAW,cAAc,cAAc,EAAE,MAAM,CAAC,CAAC,CAC7F,KAAK,MAAM,EAAE,MAAM;CAEtB,IAAI,aAAa,WAAW,GAC1B,MAAM,aAAa;CAErB,IAAI,aAAa,SAAS,GACxB,MAAM,IAAI,eAAe,cAAc,4CAA4C;AAEvF"}
1
+ {"version":3,"file":"define-notification.mjs","names":[],"sources":["../../../../../../../notifications/src/dispatch/define-notification.ts"],"sourcesContent":["/**\n * `defineNotification` — reusable, type-safe, multi-channel notification.\n *\n * Functional, not class-based: pass `via` + a renderer per channel + a\n * stable `type`. The returned object exposes `.send` / `.queue` / `.only`.\n *\n * Renderer signature is `(data, to, ctx)` where `ctx` carries `locale` and\n * `meta` from `SendOptions`. The database renderer's `type` is OPTIONAL — the\n * dispatcher injects `def.type`, keeping the type defined in ONE place.\n *\n * ## Error policy\n * - **Config errors** (missing renderer, no queue dispatcher, unknown channel)\n * are programmer mistakes → they REJECT `.send()`/`.queue()` (and a static\n * `via` with a missing renderer throws at definition time). Consistent with\n * `notify`, which rejects `ChannelNotFoundError`.\n * - **Transport errors** (a channel's `send` throwing) stay ISOLATED — emitted\n * as a `failed` event, never aborting sibling channels/recipients.\n * - **`via()` / preferences throws** for one recipient are logged and that\n * recipient is dropped (the rest of a fan-out still go).\n *\n * @example\n * export const orderShipped = defineNotification<{ order: Order }>({\n * type: \"order.shipped\",\n * via: [\"mail\", \"database\"],\n * mail: ({ order }, to) => ({ subject: `#${order.number} shipped`, html: \"…\" }),\n * database: ({ order }) => ({ title: \"Your order shipped\", payload: { id: order.id } }),\n * });\n * await orderShipped.send(user, { order });\n * await orderShipped.queue([buyer, salesRep], { order }, { delay: \"10m\" });\n * await orderShipped.only(\"mail\").send(user, { order });\n */\nimport { log } from \"@warlock.js/logger\";\nimport { getNotificationConfig } from \"../config\";\nimport {\n ChannelNotFoundError,\n MissingRendererError,\n NoQueueDispatcherError,\n} from \"../errors\";\nimport type {\n ChannelName,\n Notifiable,\n NotificationChannels,\n RenderContext,\n SendOptions,\n} from \"../types\";\nimport { newDispatchId } from \"./dispatch-id\";\nimport { dispatchChannel, type DispatchMode } from \"./dispatcher\";\nimport { emit } from \"./notifications-event-bus\";\n\n/**\n * Per-channel renderer return type. The `database` renderer may OMIT `type`\n * — it inherits from `NotificationDef.type` at dispatch time.\n */\ntype RendererReturn<C extends ChannelName> = C extends \"database\"\n ? Omit<NotificationChannels[\"database\"], \"type\">\n : NotificationChannels[C];\n\ntype Renderer<Data, C extends ChannelName> = (\n data: Data,\n to: Notifiable,\n ctx: RenderContext,\n) => RendererReturn<C>;\n\nexport type NotificationDef<Data> = {\n type: string;\n via: ChannelName[] | ((data: Data, to: Notifiable) => ChannelName[]);\n} & {\n [C in ChannelName]?: Renderer<Data, C>;\n};\n\nexport interface DefinedNotification<Data> {\n send(to: Notifiable | Notifiable[], data: Data, options?: SendOptions): Promise<void>;\n queue(to: Notifiable | Notifiable[], data: Data, options?: SendOptions): Promise<void>;\n only(...channels: ChannelName[]): DefinedNotification<Data>;\n}\n\n/** Errors that represent a misconfiguration and must surface (reject), not isolate. */\nfunction isConfigError(error: unknown): boolean {\n return (\n error instanceof MissingRendererError ||\n error instanceof NoQueueDispatcherError ||\n error instanceof ChannelNotFoundError\n );\n}\n\nexport function defineNotification<Data>(def: NotificationDef<Data>): DefinedNotification<Data> {\n const make = (restrict?: ChannelName[]): DefinedNotification<Data> => {\n // Validate at definition time when the channel set is static — a missing\n // renderer is a programmer error, surfaced loudly at import.\n if (Array.isArray(def.via)) {\n const channels = restrict ? def.via.filter((c) => restrict.includes(c)) : def.via;\n for (const channel of channels) {\n if (!def[channel]) {\n throw new MissingRendererError(def.type, channel);\n }\n }\n }\n\n return {\n send(to, data, options) {\n return dispatchAll(def, to, data, options ?? {}, \"send\", restrict);\n },\n queue(to, data, options) {\n return dispatchAll(def, to, data, options ?? {}, \"queue\", restrict);\n },\n only(...channels) {\n return make(channels);\n },\n };\n };\n\n return make();\n}\n\n/**\n * Fan-out to all recipients. Each recipient dispatches independently; one\n * recipient's transport failure never aborts the others. CONFIG errors,\n * however, propagate — they reject the returned promise.\n */\nasync function dispatchAll<Data>(\n def: NotificationDef<Data>,\n to: Notifiable | Notifiable[],\n data: Data,\n options: SendOptions,\n mode: DispatchMode,\n restrict?: ChannelName[],\n): Promise<void> {\n const recipients = Array.isArray(to) ? to : [to];\n\n const results = await Promise.allSettled(\n recipients.map((recipient) =>\n dispatchToRecipient(def, recipient, data, options, mode, restrict),\n ),\n );\n\n rethrowConfigErrors(results);\n}\n\nasync function dispatchToRecipient<Data>(\n def: NotificationDef<Data>,\n to: Notifiable,\n data: Data,\n options: SendOptions,\n mode: DispatchMode,\n restrict?: ChannelName[],\n): Promise<void> {\n const config = getNotificationConfig();\n\n // Resolve channels (via + preferences). A throw here drops THIS recipient\n // with a log — it's a per-recipient data problem, not a config error.\n let channels: ChannelName[];\n try {\n channels = typeof def.via === \"function\" ? def.via(data, to) : [...def.via];\n\n if (restrict) {\n channels = channels.filter((c) => restrict.includes(c));\n }\n\n if (!options.force && config.preferences) {\n const allowed = await config.preferences.resolveChannels(to, def.type, channels);\n for (const channel of channels.filter((c) => !allowed.includes(c))) {\n await emit(\"skipped\", {\n dispatchId: newDispatchId(),\n channel,\n notifiable: to,\n reason: \"preference\",\n options,\n });\n }\n channels = channels.filter((c) => allowed.includes(c));\n }\n } catch (error) {\n log.error(\"notifications\", `resolve.${def.type}`, error as Error);\n return;\n }\n\n const renderCtx: RenderContext = { locale: options.locale, meta: options.meta };\n\n const results = await Promise.allSettled(\n channels.map((name) => {\n const renderer = def[name] as Renderer<Data, ChannelName> | undefined;\n if (!renderer) {\n // Dynamic via chose a channel with no renderer — surface it.\n return Promise.reject(new MissingRendererError(def.type, name));\n }\n\n let payload: unknown = renderer(data, to, renderCtx);\n\n // Default the database channel's `type` from `def.type` when omitted.\n if (name === \"database\" && payload && typeof payload === \"object\" && !(\"type\" in payload)) {\n payload = { ...(payload as object), type: def.type };\n }\n\n return dispatchChannel({\n channelName: name,\n payload,\n to,\n notificationType: def.type,\n mode,\n options,\n });\n }),\n );\n\n rethrowConfigErrors(results);\n}\n\n/** Collect config-class rejections and rethrow (single or AggregateError). */\nfunction rethrowConfigErrors(results: PromiseSettledResult<unknown>[]): void {\n const configErrors = results\n .filter((r): r is PromiseRejectedResult => r.status === \"rejected\" && isConfigError(r.reason))\n .map((r) => r.reason);\n\n if (configErrors.length === 1) {\n throw configErrors[0];\n }\n if (configErrors.length > 1) {\n throw new AggregateError(configErrors, \"Multiple notification configuration errors\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,SAAS,cAAc,OAAyB;CAC9C,OACE,iBAAiB,wBACjB,iBAAiB,0BACjB,iBAAiB;AAErB;AAEA,SAAgB,mBAAyB,KAAuD;CAC9F,MAAM,QAAQ,aAAwD;EAGpE,IAAI,MAAM,QAAQ,IAAI,GAAG,GAAG;GAC1B,MAAM,WAAW,WAAW,IAAI,IAAI,QAAQ,MAAM,SAAS,SAAS,CAAC,CAAC,IAAI,IAAI;GAC9E,KAAK,MAAM,WAAW,UACpB,IAAI,CAAC,IAAI,UACP,MAAM,IAAI,qBAAqB,IAAI,MAAM,OAAO;EAGtD;EAEA,OAAO;GACL,KAAK,IAAI,MAAM,SAAS;IACtB,OAAO,YAAY,KAA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AoB,MA1BE,QAAQ,WAC5B,SAAS,KAAK,SAAS;EACrB,MAAM,WAAW,IAAI;EACrB,IAAI,CAAC,UAEH,OAAO,QAAQ,OAAO,IAAI,qBAAqB,IAAI,MAAM,IAAI,CAAC;EAGhE,IAAI,UAAmB,SAAS,MAAM,IAAI,SAAS;EAGnD,IAAI,SAAS,cAAc,WAAW,OAAO,YAAY,YAAY,EAAE,UAAU,UAC/E,UAAU;GAAE,GAAI;GAAoB,MAAM,IAAI;EAAK;EAGrD,OAAO,gBAAgB;GACrB,aAAa;GACb;GACA;GACA,kBAAkB,IAAI;GACtB;GACA;EACF,CAAC;CACH,CAAC,CACH,CAE2B;AAC7B;;AAGA,SAAS,oBAAoB,SAAgD;CAC3E,MAAM,eAAe,QAClB,QAAQ,MAAkC,EAAE,WAAW,cAAc,cAAc,EAAE,MAAM,CAAC,CAAC,CAC7F,KAAK,MAAM,EAAE,MAAM;CAEtB,IAAI,aAAa,WAAW,GAC1B,MAAM,aAAa;CAErB,IAAI,aAAa,SAAS,GACxB,MAAM,IAAI,eAAe,cAAc,4CAA4C;AAEvF"}
@@ -1,6 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
 
3
- //#region ../@warlock.js/notifications/src/dispatch/dispatch-id.ts
3
+ //#region ../notifications/src/dispatch/dispatch-id.ts
4
4
  /**
5
5
  * A unique id for one (channel, recipient) dispatch. `sending` and its terminal
6
6
  * `sent` / `failed` event share it so observers can pair them — for tracing
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch-id.mjs","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/dispatch/dispatch-id.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\n\n/**\n * A unique id for one (channel, recipient) dispatch. `sending` and its terminal\n * `sent` / `failed` event share it so observers can pair them — for tracing\n * spans, latency, or spotting a `sending` with no terminal (a hung send).\n */\nexport function newDispatchId(): string {\n return randomUUID();\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,gBAAwB;CACtC,OAAO,WAAW;AACpB"}
1
+ {"version":3,"file":"dispatch-id.mjs","names":[],"sources":["../../../../../../../notifications/src/dispatch/dispatch-id.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\n\n/**\n * A unique id for one (channel, recipient) dispatch. `sending` and its terminal\n * `sent` / `failed` event share it so observers can pair them — for tracing\n * spans, latency, or spotting a `sending` with no terminal (a hung send).\n */\nexport function newDispatchId(): string {\n return randomUUID();\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,gBAAwB;CACtC,OAAO,WAAW;AACpB"}
@@ -3,7 +3,7 @@ import { getNotificationConfig } from "../config.mjs";
3
3
  import { newDispatchId } from "./dispatch-id.mjs";
4
4
  import { emit } from "./notifications-event-bus.mjs";
5
5
 
6
- //#region ../@warlock.js/notifications/src/dispatch/dispatcher.ts
6
+ //#region ../notifications/src/dispatch/dispatcher.ts
7
7
  /**
8
8
  * Internal dispatch core — shared by `defineNotification` and `notify.<channel>`.
9
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"dispatcher.mjs","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/dispatch/dispatcher.ts"],"sourcesContent":["/**\n * Internal dispatch core — shared by `defineNotification` and `notify.<channel>`.\n *\n * Responsibilities:\n * 1. Look up the channel in the configured registry (throws if missing).\n * 2. Run the rate-limit gate (if a notification type is known) — drop with a\n * `skipped` event when the limiter refuses.\n * 3. Resolve the route: raw string > channel.route(notifiable) > { id }.\n * 4. Inject the per-send `idempotencyKey` into the database payload.\n * 5. Dispatch (sync via channel.send OR async via queue.dispatch).\n * 6. Emit `sent` on success, `failed` on throw.\n *\n * Per-channel failure isolation is the CALLER's job (it wraps a list of\n * `dispatchChannel` calls in `Promise.allSettled`).\n */\nimport { getNotificationConfig } from \"../config\";\nimport { ChannelNotFoundError, NoQueueDispatcherError, UnresolvableRouteError } from \"../errors\";\nimport type { ChannelName, Id, Notifiable, SendOptions } from \"../types\";\nimport { newDispatchId } from \"./dispatch-id\";\nimport { emit } from \"./notifications-event-bus\";\n\nexport type DispatchMode = \"send\" | \"queue\";\n\nexport type DispatchChannelArgs = {\n channelName: string;\n payload: unknown;\n /** The recipient model — undefined when dispatching to a raw route string. */\n to: Notifiable | undefined;\n /** Raw route override (ad-hoc `notify.mail(\"x@y.com\", …)`). */\n rawRoute?: string;\n /** Notification type — drives the rate-limit gate. May be undefined. */\n notificationType: string | undefined;\n mode: DispatchMode;\n options: SendOptions;\n};\n\n/**\n * Dispatch ONE rendered payload to ONE recipient through ONE channel.\n * Does NOT consult `PreferenceProvider` — that gate runs at the caller level.\n *\n * Throws `ChannelNotFoundError` (channel not registered) and\n * `UnresolvableRouteError` (channel's `route()` returned undefined) — both are\n * configuration/data errors that should surface loudly. Transport failures\n * (channel.send throwing) are emitted as `failed` AND rethrown.\n */\nexport async function dispatchChannel(args: DispatchChannelArgs): Promise<void> {\n const config = getNotificationConfig();\n const channel = config.channels[args.channelName as ChannelName];\n\n if (!channel) {\n throw new ChannelNotFoundError(args.channelName);\n }\n\n // One id for this (channel, recipient) dispatch — `sending` and its terminal\n // `sent` / `failed` share it so observers can pair them.\n const dispatchId = newDispatchId();\n\n // Rate-limit gate. Only applies when we have a notifiable + a notification\n // type (otherwise there's nothing to rate-limit on). `force` does NOT\n // bypass — rate limits are a safety valve, not a UX preference.\n //\n // NOTE (Phase-2 seam): for mode \"queue\" the budget is consumed at ENQUEUE\n // time here, not at delivery. When the herald worker lands it should run\n // this gate at delivery instead; see RateLimiter docstring.\n if (args.to && args.notificationType && config.rateLimit) {\n const allowed = await config.rateLimit.allow(\n args.to,\n args.channelName as ChannelName,\n args.notificationType,\n );\n\n if (!allowed) {\n await emit(\"skipped\", {\n dispatchId,\n channel: args.channelName,\n notifiable: args.to,\n reason: \"rate-limit\",\n options: args.options,\n });\n return;\n }\n }\n\n const route = resolveRoute(args, channel.route);\n\n // Inject idempotency key into the database payload (so the repo can dedupe).\n let payload = args.payload;\n if (\n args.channelName === \"database\" &&\n args.options.idempotencyKey &&\n payload &&\n typeof payload === \"object\"\n ) {\n payload = { ...(payload as object), idempotencyKey: args.options.idempotencyKey };\n }\n\n // `sending` fires after the gates pass + the route resolves, BEFORE the\n // transport — awaited so it always precedes the send. Observers can't abort\n // the send, but a slow handler delays it; keep them fast.\n await emit(\"sending\", {\n dispatchId,\n channel: args.channelName,\n notifiable: args.to,\n payload,\n options: args.options,\n });\n\n const startedAt = Date.now();\n\n try {\n if (args.mode === \"queue\") {\n if (!config.queue) {\n throw new NoQueueDispatcherError(args.channelName);\n }\n await config.queue.dispatch({\n channel: args.channelName,\n route,\n payload,\n options: args.options,\n });\n } else {\n await channel.send({\n payload: payload as never,\n route,\n notifiable: args.to,\n options: args.options,\n });\n }\n\n await emit(\"sent\", {\n dispatchId,\n channel: args.channelName,\n notifiable: args.to,\n payload,\n options: args.options,\n durationMs: Date.now() - startedAt,\n });\n } catch (error) {\n await emit(\"failed\", {\n dispatchId,\n channel: args.channelName,\n notifiable: args.to,\n payload,\n error: error as Error,\n options: args.options,\n durationMs: Date.now() - startedAt,\n });\n throw error;\n }\n}\n\n/**\n * Route resolution priority:\n * 1. raw route string (ad-hoc `notify.mail(\"x@y.com\", …)`)\n * 2. the channel's `route(notifiable)` resolver\n * 3. `{ id: notifiable.id }` — ONLY when the channel declares no resolver\n *\n * When a channel HAS a resolver but it returns undefined (e.g. a mail\n * recipient with no email), we throw `UnresolvableRouteError` rather than\n * silently coercing to `{ id }` — that would hand a string-route channel an\n * object and fail deep inside the transport.\n */\nfunction resolveRoute(\n args: DispatchChannelArgs,\n resolver: ((notifiable: Notifiable) => string | { id: Id } | undefined) | undefined,\n): string | { id: Id } {\n if (args.rawRoute !== undefined) {\n return args.rawRoute;\n }\n\n if (!args.to) {\n throw new UnresolvableRouteError(args.channelName);\n }\n\n // No resolver declared → the channel addresses by id (database/internal).\n if (!resolver) {\n return { id: args.to.id };\n }\n\n const resolved = resolver(args.to);\n\n if (resolved === undefined) {\n throw new UnresolvableRouteError(args.channelName, args.to.id);\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;EACd,MAAM,KAAK,UAAU;GACnB;GACA,SAAS,KAAK;GACd,YAAY,KAAK;GACjB;GACO;GACP,SAAS,KAAK;GACd,YAAY,KAAK,IAAI,IAAI;EAC3B,CAAC;EACD,MAAM;CACR;AACF;;;;;;;;;;;;AAaA,SAAS,aACP,MACA,UACqB;CACrB,IAAI,KAAK,aAAa,QACpB,OAAO,KAAK;CAGd,IAAI,CAAC,KAAK,IACR,MAAM,IAAI,uBAAuB,KAAK,WAAW;CAInD,IAAI,CAAC,UACH,OAAO,EAAE,IAAI,KAAK,GAAG,GAAG;CAG1B,MAAM,WAAW,SAAS,KAAK,EAAE;CAEjC,IAAI,aAAa,QACf,MAAM,IAAI,uBAAuB,KAAK,aAAa,KAAK,GAAG,EAAE;CAG/D,OAAO;AACT"}
1
+ {"version":3,"file":"dispatcher.mjs","names":[],"sources":["../../../../../../../notifications/src/dispatch/dispatcher.ts"],"sourcesContent":["/**\n * Internal dispatch core — shared by `defineNotification` and `notify.<channel>`.\n *\n * Responsibilities:\n * 1. Look up the channel in the configured registry (throws if missing).\n * 2. Run the rate-limit gate (if a notification type is known) — drop with a\n * `skipped` event when the limiter refuses.\n * 3. Resolve the route: raw string > channel.route(notifiable) > { id }.\n * 4. Inject the per-send `idempotencyKey` into the database payload.\n * 5. Dispatch (sync via channel.send OR async via queue.dispatch).\n * 6. Emit `sent` on success, `failed` on throw.\n *\n * Per-channel failure isolation is the CALLER's job (it wraps a list of\n * `dispatchChannel` calls in `Promise.allSettled`).\n */\nimport { getNotificationConfig } from \"../config\";\nimport { ChannelNotFoundError, NoQueueDispatcherError, UnresolvableRouteError } from \"../errors\";\nimport type { ChannelName, Id, Notifiable, SendOptions } from \"../types\";\nimport { newDispatchId } from \"./dispatch-id\";\nimport { emit } from \"./notifications-event-bus\";\n\nexport type DispatchMode = \"send\" | \"queue\";\n\nexport type DispatchChannelArgs = {\n channelName: string;\n payload: unknown;\n /** The recipient model — undefined when dispatching to a raw route string. */\n to: Notifiable | undefined;\n /** Raw route override (ad-hoc `notify.mail(\"x@y.com\", …)`). */\n rawRoute?: string;\n /** Notification type — drives the rate-limit gate. May be undefined. */\n notificationType: string | undefined;\n mode: DispatchMode;\n options: SendOptions;\n};\n\n/**\n * Dispatch ONE rendered payload to ONE recipient through ONE channel.\n * Does NOT consult `PreferenceProvider` — that gate runs at the caller level.\n *\n * Throws `ChannelNotFoundError` (channel not registered) and\n * `UnresolvableRouteError` (channel's `route()` returned undefined) — both are\n * configuration/data errors that should surface loudly. Transport failures\n * (channel.send throwing) are emitted as `failed` AND rethrown.\n */\nexport async function dispatchChannel(args: DispatchChannelArgs): Promise<void> {\n const config = getNotificationConfig();\n const channel = config.channels[args.channelName as ChannelName];\n\n if (!channel) {\n throw new ChannelNotFoundError(args.channelName);\n }\n\n // One id for this (channel, recipient) dispatch — `sending` and its terminal\n // `sent` / `failed` share it so observers can pair them.\n const dispatchId = newDispatchId();\n\n // Rate-limit gate. Only applies when we have a notifiable + a notification\n // type (otherwise there's nothing to rate-limit on). `force` does NOT\n // bypass — rate limits are a safety valve, not a UX preference.\n //\n // NOTE (Phase-2 seam): for mode \"queue\" the budget is consumed at ENQUEUE\n // time here, not at delivery. When the herald worker lands it should run\n // this gate at delivery instead; see RateLimiter docstring.\n if (args.to && args.notificationType && config.rateLimit) {\n const allowed = await config.rateLimit.allow(\n args.to,\n args.channelName as ChannelName,\n args.notificationType,\n );\n\n if (!allowed) {\n await emit(\"skipped\", {\n dispatchId,\n channel: args.channelName,\n notifiable: args.to,\n reason: \"rate-limit\",\n options: args.options,\n });\n return;\n }\n }\n\n const route = resolveRoute(args, channel.route);\n\n // Inject idempotency key into the database payload (so the repo can dedupe).\n let payload = args.payload;\n if (\n args.channelName === \"database\" &&\n args.options.idempotencyKey &&\n payload &&\n typeof payload === \"object\"\n ) {\n payload = { ...(payload as object), idempotencyKey: args.options.idempotencyKey };\n }\n\n // `sending` fires after the gates pass + the route resolves, BEFORE the\n // transport — awaited so it always precedes the send. Observers can't abort\n // the send, but a slow handler delays it; keep them fast.\n await emit(\"sending\", {\n dispatchId,\n channel: args.channelName,\n notifiable: args.to,\n payload,\n options: args.options,\n });\n\n const startedAt = Date.now();\n\n try {\n if (args.mode === \"queue\") {\n if (!config.queue) {\n throw new NoQueueDispatcherError(args.channelName);\n }\n await config.queue.dispatch({\n channel: args.channelName,\n route,\n payload,\n options: args.options,\n });\n } else {\n await channel.send({\n payload: payload as never,\n route,\n notifiable: args.to,\n options: args.options,\n });\n }\n\n await emit(\"sent\", {\n dispatchId,\n channel: args.channelName,\n notifiable: args.to,\n payload,\n options: args.options,\n durationMs: Date.now() - startedAt,\n });\n } catch (error) {\n await emit(\"failed\", {\n dispatchId,\n channel: args.channelName,\n notifiable: args.to,\n payload,\n error: error as Error,\n options: args.options,\n durationMs: Date.now() - startedAt,\n });\n throw error;\n }\n}\n\n/**\n * Route resolution priority:\n * 1. raw route string (ad-hoc `notify.mail(\"x@y.com\", …)`)\n * 2. the channel's `route(notifiable)` resolver\n * 3. `{ id: notifiable.id }` — ONLY when the channel declares no resolver\n *\n * When a channel HAS a resolver but it returns undefined (e.g. a mail\n * recipient with no email), we throw `UnresolvableRouteError` rather than\n * silently coercing to `{ id }` — that would hand a string-route channel an\n * object and fail deep inside the transport.\n */\nfunction resolveRoute(\n args: DispatchChannelArgs,\n resolver: ((notifiable: Notifiable) => string | { id: Id } | undefined) | undefined,\n): string | { id: Id } {\n if (args.rawRoute !== undefined) {\n return args.rawRoute;\n }\n\n if (!args.to) {\n throw new UnresolvableRouteError(args.channelName);\n }\n\n // No resolver declared → the channel addresses by id (database/internal).\n if (!resolver) {\n return { id: args.to.id };\n }\n\n const resolved = resolver(args.to);\n\n if (resolved === undefined) {\n throw new UnresolvableRouteError(args.channelName, args.to.id);\n }\n\n return resolved;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,eAAsB,gBAAgB,MAA0C;CAC9E,MAAM,SAAS,sBAAsB;CACrC,MAAM,UAA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,MAAM;CACR;AACF;;;;;;;;;;;;AAaA,SAAS,aACP,MACA,UACqB;CACrB,IAAI,KAAK,aAAa,QACpB,OAAO,KAAK;CAGd,IAAI,CAAC,KAAK,IACR,MAAM,IAAI,uBAAuB,KAAK,WAAW;CAInD,IAAI,CAAC,UACH,OAAO,EAAE,IAAI,KAAK,GAAG,GAAG;CAG1B,MAAM,WAAW,SAAS,KAAK,EAAE;CAEjC,IAAI,aAAa,QACf,MAAM,IAAI,uBAAuB,KAAK,aAAa,KAAK,GAAG,EAAE;CAG/D,OAAO;AACT"}
@@ -1,6 +1,6 @@
1
1
  import { NotificationEvents } from "../types.mjs";
2
2
 
3
- //#region ../@warlock.js/notifications/src/dispatch/notifications-event-bus.d.ts
3
+ //#region ../notifications/src/dispatch/notifications-event-bus.d.ts
4
4
  type EventName = keyof NotificationEvents;
5
5
  type Handler<E extends EventName> = (data: NotificationEvents[E]) => void | Promise<void>;
6
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"notifications-event-bus.d.mts","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/dispatch/notifications-event-bus.ts"],"mappings":";;;KAkBK,SAAA,SAAkB,kBAAkB;AAAA,KACpC,OAAA,WAAkB,SAAA,KAAc,IAAA,EAAM,kBAAA,CAAmB,CAAA,aAAc,OAAA;AAHzB;;;;AAEV;AAAA;AAFU,cAkBtC,aAAA;eACE,SAAA,EAAS,KAAA,EAAS,CAAA,EAAC,OAAA,EAAW,OAAA,CAAQ,CAAA;gBAMrC,SAAA,EAAS,KAAA,EAAS,CAAA,EAAC,OAAA,EAAW,OAAA,CAAQ,CAAA;AAAA"}
1
+ {"version":3,"file":"notifications-event-bus.d.mts","names":[],"sources":["../../../../../../../notifications/src/dispatch/notifications-event-bus.ts"],"mappings":";;;KAkBK,SAAA,SAAkB,kBAAkB;AAAA,KACpC,OAAA,WAAkB,SAAA,KAAc,IAAA,EAAM,kBAAA,CAAmB,CAAA,aAAc,OAAA;AAHzB;;;;AAEV;AAAA;AAFU,cAkBtC,aAAA;eACE,SAAA,EAAS,KAAA,EAAS,CAAA,EAAC,OAAA,EAAW,OAAA,CAAQ,CAAA;gBAMrC,SAAA,EAAS,KAAA,EAAS,CAAA,EAAC,OAAA,EAAW,OAAA,CAAQ,CAAA;AAAA"}
@@ -1,6 +1,6 @@
1
1
  import { log } from "@warlock.js/logger";
2
2
 
3
- //#region ../@warlock.js/notifications/src/dispatch/notifications-event-bus.ts
3
+ //#region ../notifications/src/dispatch/notifications-event-bus.ts
4
4
  /**
5
5
  * Typed event bus for notifications observability. Emits `sent`, `failed`,
6
6
  * and `skipped` events per (channel, recipient) — fan-out emits N events.
@@ -1 +1 @@
1
- {"version":3,"file":"notifications-event-bus.mjs","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/dispatch/notifications-event-bus.ts"],"sourcesContent":["/**\n * Typed event bus for notifications observability. Emits `sent`, `failed`,\n * and `skipped` events per (channel, recipient) — fan-out emits N events.\n *\n * Intentionally minimal — a `Map<event, Set<handler>>` keeps tests trivial\n * and avoids pulling event-emitter machinery for what is fundamentally\n * pub/sub. Handler exceptions are logged-and-swallowed so one bad listener\n * cannot break the dispatcher.\n *\n * @example\n * notifications.on(\"sent\", ({ channel }) => metrics.inc(`notif.${channel}.sent`));\n * notifications.on(\"skipped\", ({ reason }) => metrics.inc(`notif.skipped.${reason}`));\n * const off = notifications.on(\"failed\", logErr);\n * off(); // unsubscribe\n */\nimport { log } from \"@warlock.js/logger\";\nimport type { NotificationEvents } from \"../types\";\n\ntype EventName = keyof NotificationEvents;\ntype Handler<E extends EventName> = (data: NotificationEvents[E]) => void | Promise<void>;\n\nconst handlers: { [E in EventName]: Set<Handler<E>> } = {\n sending: new Set(),\n sent: new Set(),\n failed: new Set(),\n skipped: new Set(),\n};\n\n/**\n * Public observability surface.\n *\n * `on(event, handler)` returns an unsubscribe function. `off` exists for\n * symmetry with libraries that hold handler references for later removal.\n */\nexport const notifications = {\n on<E extends EventName>(event: E, handler: Handler<E>): () => void {\n handlers[event].add(handler as Handler<EventName>);\n return () => {\n handlers[event].delete(handler as Handler<EventName>);\n };\n },\n off<E extends EventName>(event: E, handler: Handler<E>): void {\n handlers[event].delete(handler as Handler<EventName>);\n },\n};\n\n/**\n * Internal emit — used by the dispatcher. Not exported from the package.\n * Handlers run in registration order; an awaited Promise.allSettled isolates\n * each listener so one throw cannot block the others.\n */\nexport async function emit<E extends EventName>(\n event: E,\n data: NotificationEvents[E],\n): Promise<void> {\n const set = handlers[event];\n if (set.size === 0) return;\n\n // The `async` wrapper turns SYNC handler throws into promise rejections so\n // `Promise.allSettled` can isolate them. Without it, a `throw` inside the\n // handler escapes the array map before allSettled gets a chance to catch.\n const results = await Promise.allSettled(\n Array.from(set).map(async (handler) => {\n await (handler as Handler<E>)(data);\n }),\n );\n\n for (const result of results) {\n if (result.status === \"rejected\") {\n log.error(\"notifications\", \"event-handler\", result.reason);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBA,MAAM,WAAkD;CACtD,yBAAS,IAAI,IAAI;CACjB,sBAAM,IAAI,IAAI;CACd,wBAAQ,IAAI,IAAI;CAChB,yBAAS,IAAI,IAAI;AACnB;;;;;;;AAQA,MAAa,gBAAgB;CAC3B,GAAwB,OAAU,SAAiC;EACjE,SAAS,MAAM,CAAC,IAAI,OAA6B;EACjD,aAAa;GACX,SAAS,MAAM,CAAC,OAAO,OAA6B;EACtD;CACF;CACA,IAAyB,OAAU,SAA2B;EAC5D,SAAS,MAAM,CAAC,OAAO,OAA6B;CACtD;AACF;;;;;;AAOA,eAAsB,KACpB,OACA,MACe;CACf,MAAM,MAAM,SAAS;CACrB,IAAI,IAAI,SAAS,GAAG;CAKpB,MAAM,UAAU,MAAM,QAAQ,WAC5B,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,OAAO,YAAY;EACrC,MAAO,QAAuB,IAAI;CACpC,CAAC,CACH;CAEA,KAAK,MAAM,UAAU,SACnB,IAAI,OAAO,WAAW,YACpB,IAAI,MAAM,iBAAiB,iBAAiB,OAAO,MAAM;AAG/D"}
1
+ {"version":3,"file":"notifications-event-bus.mjs","names":[],"sources":["../../../../../../../notifications/src/dispatch/notifications-event-bus.ts"],"sourcesContent":["/**\n * Typed event bus for notifications observability. Emits `sent`, `failed`,\n * and `skipped` events per (channel, recipient) — fan-out emits N events.\n *\n * Intentionally minimal — a `Map<event, Set<handler>>` keeps tests trivial\n * and avoids pulling event-emitter machinery for what is fundamentally\n * pub/sub. Handler exceptions are logged-and-swallowed so one bad listener\n * cannot break the dispatcher.\n *\n * @example\n * notifications.on(\"sent\", ({ channel }) => metrics.inc(`notif.${channel}.sent`));\n * notifications.on(\"skipped\", ({ reason }) => metrics.inc(`notif.skipped.${reason}`));\n * const off = notifications.on(\"failed\", logErr);\n * off(); // unsubscribe\n */\nimport { log } from \"@warlock.js/logger\";\nimport type { NotificationEvents } from \"../types\";\n\ntype EventName = keyof NotificationEvents;\ntype Handler<E extends EventName> = (data: NotificationEvents[E]) => void | Promise<void>;\n\nconst handlers: { [E in EventName]: Set<Handler<E>> } = {\n sending: new Set(),\n sent: new Set(),\n failed: new Set(),\n skipped: new Set(),\n};\n\n/**\n * Public observability surface.\n *\n * `on(event, handler)` returns an unsubscribe function. `off` exists for\n * symmetry with libraries that hold handler references for later removal.\n */\nexport const notifications = {\n on<E extends EventName>(event: E, handler: Handler<E>): () => void {\n handlers[event].add(handler as Handler<EventName>);\n return () => {\n handlers[event].delete(handler as Handler<EventName>);\n };\n },\n off<E extends EventName>(event: E, handler: Handler<E>): void {\n handlers[event].delete(handler as Handler<EventName>);\n },\n};\n\n/**\n * Internal emit — used by the dispatcher. Not exported from the package.\n * Handlers run in registration order; an awaited Promise.allSettled isolates\n * each listener so one throw cannot block the others.\n */\nexport async function emit<E extends EventName>(\n event: E,\n data: NotificationEvents[E],\n): Promise<void> {\n const set = handlers[event];\n if (set.size === 0) return;\n\n // The `async` wrapper turns SYNC handler throws into promise rejections so\n // `Promise.allSettled` can isolate them. Without it, a `throw` inside the\n // handler escapes the array map before allSettled gets a chance to catch.\n const results = await Promise.allSettled(\n Array.from(set).map(async (handler) => {\n await (handler as Handler<E>)(data);\n }),\n );\n\n for (const result of results) {\n if (result.status === \"rejected\") {\n log.error(\"notifications\", \"event-handler\", result.reason);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBA,MAAM,WAAkD;CACtD,yBAAS,IAAI,IAAI;CACjB,sBAAM,IAAI,IAAI;CACd,wBAAQ,IAAI,IAAI;CAChB,yBAAS,IAAI,IAAI;AACnB;;;;;;;AAQA,MAAa,gBAAgB;CAC3B,GAAwB,OAAU,SAAiC;EACjE,SAAS,MAAM,CAAC,IAAI,OAA6B;EACjD,aAAa;GACX,SAAS,MAAM,CAAC,OAAO,OAA6B;EACtD;CACF;CACA,IAAyB,OAAU,SAA2B;EAC5D,SAAS,MAAM,CAAC,OAAO,OAA6B;CACtD;AACF;;;;;;AAOA,eAAsB,KACpB,OACA,MACe;CACf,MAAM,MAAM,SAAS;CACrB,IAAI,IAAI,SAAS,GAAG;CAKpB,MAAM,UAAU,MAAM,QAAQ,WAC5B,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,OAAO,YAAY;EACrC,MAAO,QAAuB,IAAI;CACpC,CAAC,CACH;CAEA,KAAK,MAAM,UAAU,SACnB,IAAI,OAAO,WAAW,YACpB,IAAI,MAAM,iBAAiB,iBAAiB,OAAO,MAAM;AAG/D"}
@@ -1,6 +1,6 @@
1
1
  import { ChannelName, Notifiable, NotificationChannels, SendOptions } from "../types.mjs";
2
2
 
3
- //#region ../@warlock.js/notifications/src/dispatch/notify.d.ts
3
+ //#region ../notifications/src/dispatch/notify.d.ts
4
4
  /**
5
5
  * Public shape of `notify`. The mapped portion gives `notify.<channel>` per
6
6
  * registered channel; `channel(name)` is the runtime escape.
@@ -1 +1 @@
1
- {"version":3,"file":"notify.d.mts","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/dispatch/notify.ts"],"mappings":";;;;;AA8BA;;KAAY,MAAA;EACV,OAAA,CAAQ,IAAA;IACN,IAAA,CACE,EAAA,EAAI,UAAA,WACJ,OAAA,WACA,OAAA,GAAU,WAAA,GACT,OAAA;EAAA;AAAA,YAGC,WAAA,IACJ,EAAA,EAAI,UAAA,WACJ,OAAA,EAAS,oBAAA,CAAqB,CAAA,GAC9B,OAAA,GAAU,WAAA,KACP,OAAA;;;;;cA0EM,MAAA,EAAQ,MAuBnB"}
1
+ {"version":3,"file":"notify.d.mts","names":[],"sources":["../../../../../../../notifications/src/dispatch/notify.ts"],"mappings":";;;;;AA8BA;;KAAY,MAAA;EACV,OAAA,CAAQ,IAAA;IACN,IAAA,CACE,EAAA,EAAI,UAAA,WACJ,OAAA,WACA,OAAA,GAAU,WAAA,GACT,OAAA;EAAA;AAAA,YAGC,WAAA,IACJ,EAAA,EAAI,UAAA,WACJ,OAAA,EAAS,oBAAA,CAAqB,CAAA,GAC9B,OAAA,GAAU,WAAA,KACP,OAAA;;;;;cA0EM,MAAA,EAAQ,MAuBnB"}
@@ -3,7 +3,7 @@ import { newDispatchId } from "./dispatch-id.mjs";
3
3
  import { emit } from "./notifications-event-bus.mjs";
4
4
  import { dispatchChannel } from "./dispatcher.mjs";
5
5
 
6
- //#region ../@warlock.js/notifications/src/dispatch/notify.ts
6
+ //#region ../notifications/src/dispatch/notify.ts
7
7
  /**
8
8
  * `notify` — ad-hoc, per-channel send facade.
9
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"notify.mjs","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/dispatch/notify.ts"],"sourcesContent":["/**\n * `notify` — ad-hoc, per-channel send facade.\n *\n * A Proxy keyed by the channel registry. `notify.<channel>(to, payload,\n * options?)` works for ANY channel name registered in\n * `NotificationChannels` — built-in or custom (via declaration merging).\n *\n * For multi-channel sends, use `defineNotification` — that's the reusable\n * pattern and the only mental model for \"send through several channels at\n * once\" (no inline multi-channel overload here on purpose).\n *\n * `notify.channel(name)` is the runtime escape when the channel name isn't a\n * compile-time literal.\n *\n * @example\n * await notify.mail(user, { subject: \"Welcome\", html: \"<p>Hi!</p>\" });\n * await notify.database(user, { type: \"welcome\", title: \"Welcome!\" });\n * await notify.mail(\"guest@example.com\", { subject: \"…\", html: \"…\" }); // raw target\n * await notify.channel(dynamicName).send(user, payload); // dynamic name\n */\nimport { getNotificationConfig } from \"../config\";\nimport type { ChannelName, Notifiable, NotificationChannels, SendOptions } from \"../types\";\nimport { newDispatchId } from \"./dispatch-id\";\nimport { dispatchChannel } from \"./dispatcher\";\nimport { emit } from \"./notifications-event-bus\";\n\n/**\n * Public shape of `notify`. The mapped portion gives `notify.<channel>` per\n * registered channel; `channel(name)` is the runtime escape.\n */\nexport type Notify = {\n channel(name: string): {\n send(\n to: Notifiable | string,\n payload: unknown,\n options?: SendOptions,\n ): Promise<void>;\n };\n} & {\n [C in ChannelName]: (\n to: Notifiable | string,\n payload: NotificationChannels[C],\n options?: SendOptions,\n ) => Promise<void>;\n};\n\n/**\n * Per-call dispatch for `notify.<channel>`. Mirrors `defineNotification`'s\n * pipeline but without rendering: payload is already concrete.\n *\n * Preferences gate runs ONLY when a notification `type` is known — explicit\n * via `options.type`, or implicit from a database payload's `type` field.\n * Without a type we have nothing to gate on, and ad-hoc sends bypass\n * preferences silently (use `defineNotification` if you want guaranteed\n * gating).\n */\nasync function notifyImpl(\n channelName: string,\n to: Notifiable | string,\n payload: unknown,\n options: SendOptions = {},\n): Promise<void> {\n const isRawTarget = typeof to === \"string\";\n const notifiable: Notifiable | undefined = isRawTarget ? undefined : to;\n\n // Derive the type: explicit `options.type` wins, then the payload's\n // `type` field (database channel convention).\n let notificationType: string | undefined = options.type;\n if (\n notificationType === undefined &&\n payload &&\n typeof payload === \"object\" &&\n \"type\" in payload &&\n typeof (payload as { type: unknown }).type === \"string\"\n ) {\n notificationType = (payload as { type: string }).type;\n }\n\n // Preferences gate — only when notifiable + type are both available.\n if (notifiable && notificationType && !options.force) {\n const config = getNotificationConfig();\n\n if (config.preferences) {\n const allowed = await config.preferences.resolveChannels(\n notifiable,\n notificationType,\n [channelName as ChannelName],\n );\n\n if (!allowed.includes(channelName as ChannelName)) {\n await emit(\"skipped\", {\n dispatchId: newDispatchId(),\n channel: channelName,\n notifiable,\n reason: \"preference\",\n options,\n });\n return;\n }\n }\n }\n\n await dispatchChannel({\n channelName,\n payload,\n to: notifiable,\n rawRoute: isRawTarget ? to : undefined,\n notificationType,\n mode: \"send\",\n options,\n });\n}\n\n/**\n * Build the `notify` proxy. `channel(name)` returns a `{ send }` object;\n * any other property access returns a one-shot dispatcher for that channel.\n */\nexport const notify: Notify = new Proxy({} as Notify, {\n get(_target, prop) {\n if (typeof prop === \"symbol\") {\n return undefined;\n }\n\n // Don't masquerade as a thenable — awaiting or Promise-wrapping `notify`\n // must NOT invoke notify.then(...) as a channel send. Also keep common\n // serialization probes from being treated as channel names.\n if (prop === \"then\" || prop === \"catch\" || prop === \"finally\" || prop === \"toJSON\") {\n return undefined;\n }\n\n if (prop === \"channel\") {\n return (name: string) => ({\n send: (to: Notifiable | string, payload: unknown, options?: SendOptions) =>\n notifyImpl(name, to, payload, options),\n });\n }\n\n return (to: Notifiable | string, payload: unknown, options?: SendOptions) =>\n notifyImpl(prop, to, payload, options);\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,eAAe,WACb,aACA,IACA,SACA,UAAuB,CAAC,GACT;CACf,MAAM,cAAc,OAAO,OAAO;CAClC,MAAM,aAAqC,cAAc,SAAY;CAIrE,IAAI,mBAAuC,QAAQ;CACnD,IACE,qBAAqB,UACrB,WACA,OAAO,YAAY,YACnB,UAAU,WACV,OAAQ,QAA8B,SAAS,UAE/C,mBAAoB,QAA6B;CAInD,IAAI,cAAc,oBAAoB,CAAC,QAAQ,OAAO;EACpD,MAAM,SAAS,sBAAsB;EAErC,IAAI,OAAO,aAOT;OAAI,EAAC,MANiB,OAAO,YAAY,gBACvC,YACA,kBACA,CAAC,WAA0B,CAC7B,EAEY,CAAC,SAAS,WAA0B,GAAG;IACjD,MAAM,KAAK,WAAW;KACpB,YAAY,cAAc;KAC1B,SAAS;KACT;KACA,QAAQ;KACR;IACF,CAAC;IACD;GACF;;CAEJ;CAEA,MAAM,gBAAgB;EACpB;EACA;EACA,IAAI;EACJ,UAAU,cAAc,KAAK;EAC7B;EACA,MAAM;EACN;CACF,CAAC;AACH;;;;;AAMA,MAAa,SAAiB,IAAI,MAAM,CAAC,GAAa,EACpD,IAAI,SAAS,MAAM;CACjB,IAAI,OAAO,SAAS,UAClB;CAMF,IAAI,SAAS,UAAU,SAAS,WAAW,SAAS,aAAa,SAAS,UACxE;CAGF,IAAI,SAAS,WACX,QAAQ,UAAkB,EACxB,OAAO,IAAyB,SAAkB,YAChD,WAAW,MAAM,IAAI,SAAS,OAAO,EACzC;CAGF,QAAQ,IAAyB,SAAkB,YACjD,WAAW,MAAM,IAAI,SAAS,OAAO;AACzC,EACF,CAAC"}
1
+ {"version":3,"file":"notify.mjs","names":[],"sources":["../../../../../../../notifications/src/dispatch/notify.ts"],"sourcesContent":["/**\n * `notify` — ad-hoc, per-channel send facade.\n *\n * A Proxy keyed by the channel registry. `notify.<channel>(to, payload,\n * options?)` works for ANY channel name registered in\n * `NotificationChannels` — built-in or custom (via declaration merging).\n *\n * For multi-channel sends, use `defineNotification` — that's the reusable\n * pattern and the only mental model for \"send through several channels at\n * once\" (no inline multi-channel overload here on purpose).\n *\n * `notify.channel(name)` is the runtime escape when the channel name isn't a\n * compile-time literal.\n *\n * @example\n * await notify.mail(user, { subject: \"Welcome\", html: \"<p>Hi!</p>\" });\n * await notify.database(user, { type: \"welcome\", title: \"Welcome!\" });\n * await notify.mail(\"guest@example.com\", { subject: \"…\", html: \"…\" }); // raw target\n * await notify.channel(dynamicName).send(user, payload); // dynamic name\n */\nimport { getNotificationConfig } from \"../config\";\nimport type { ChannelName, Notifiable, NotificationChannels, SendOptions } from \"../types\";\nimport { newDispatchId } from \"./dispatch-id\";\nimport { dispatchChannel } from \"./dispatcher\";\nimport { emit } from \"./notifications-event-bus\";\n\n/**\n * Public shape of `notify`. The mapped portion gives `notify.<channel>` per\n * registered channel; `channel(name)` is the runtime escape.\n */\nexport type Notify = {\n channel(name: string): {\n send(\n to: Notifiable | string,\n payload: unknown,\n options?: SendOptions,\n ): Promise<void>;\n };\n} & {\n [C in ChannelName]: (\n to: Notifiable | string,\n payload: NotificationChannels[C],\n options?: SendOptions,\n ) => Promise<void>;\n};\n\n/**\n * Per-call dispatch for `notify.<channel>`. Mirrors `defineNotification`'s\n * pipeline but without rendering: payload is already concrete.\n *\n * Preferences gate runs ONLY when a notification `type` is known — explicit\n * via `options.type`, or implicit from a database payload's `type` field.\n * Without a type we have nothing to gate on, and ad-hoc sends bypass\n * preferences silently (use `defineNotification` if you want guaranteed\n * gating).\n */\nasync function notifyImpl(\n channelName: string,\n to: Notifiable | string,\n payload: unknown,\n options: SendOptions = {},\n): Promise<void> {\n const isRawTarget = typeof to === \"string\";\n const notifiable: Notifiable | undefined = isRawTarget ? undefined : to;\n\n // Derive the type: explicit `options.type` wins, then the payload's\n // `type` field (database channel convention).\n let notificationType: string | undefined = options.type;\n if (\n notificationType === undefined &&\n payload &&\n typeof payload === \"object\" &&\n \"type\" in payload &&\n typeof (payload as { type: unknown }).type === \"string\"\n ) {\n notificationType = (payload as { type: string }).type;\n }\n\n // Preferences gate — only when notifiable + type are both available.\n if (notifiable && notificationType && !options.force) {\n const config = getNotificationConfig();\n\n if (config.preferences) {\n const allowed = await config.preferences.resolveChannels(\n notifiable,\n notificationType,\n [channelName as ChannelName],\n );\n\n if (!allowed.includes(channelName as ChannelName)) {\n await emit(\"skipped\", {\n dispatchId: newDispatchId(),\n channel: channelName,\n notifiable,\n reason: \"preference\",\n options,\n });\n return;\n }\n }\n }\n\n await dispatchChannel({\n channelName,\n payload,\n to: notifiable,\n rawRoute: isRawTarget ? to : undefined,\n notificationType,\n mode: \"send\",\n options,\n });\n}\n\n/**\n * Build the `notify` proxy. `channel(name)` returns a `{ send }` object;\n * any other property access returns a one-shot dispatcher for that channel.\n */\nexport const notify: Notify = new Proxy({} as Notify, {\n get(_target, prop) {\n if (typeof prop === \"symbol\") {\n return undefined;\n }\n\n // Don't masquerade as a thenable — awaiting or Promise-wrapping `notify`\n // must NOT invoke notify.then(...) as a channel send. Also keep common\n // serialization probes from being treated as channel names.\n if (prop === \"then\" || prop === \"catch\" || prop === \"finally\" || prop === \"toJSON\") {\n return undefined;\n }\n\n if (prop === \"channel\") {\n return (name: string) => ({\n send: (to: Notifiable | string, payload: unknown, options?: SendOptions) =>\n notifyImpl(name, to, payload, options),\n });\n }\n\n return (to: Notifiable | string, payload: unknown, options?: SendOptions) =>\n notifyImpl(prop, to, payload, options);\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,eAAe,WACb,aACA,IACA,SACA,UAAuB,CAAC,GACT;CACf,MAAM,cAAc,OAAO,OAAO;CAClC,MAAM,aAAqC,cAAc,SAAY;CAIrE,IAAI,mBAAuC,QAAQ;CACnD,IACE,qBAAqB,UACrB,WACA,OAAO,YAAY,YACnB,UAAU,WACV,OAAQ,QAA8B,SAAS,UAE/C,mBAAoB,QAA6B;CAInD,IAAI,cAAc,oBAAoB,CAAC,QAAQ,OAAO;EACpD,MAAM,SAAS,sBAAsB;EAErC,IAAI,OAAO,aAOT;OAAI,EAAC,MANiB,OAAO,YAAY,gBACvC,YACA,kBACA,CAAC,WAA0B,CAC7B,EAEY,CAAC,SAAS,WAA0B,GAAG;IACjD,MAAM,KAAK,WAAW;KACpB,YAAY,cAAc;KAC1B,SAAS;KACT;KACA,QAAQ;KACR;IACF,CAAC;IACD;GACF;;CAEJ;CAEA,MAAM,gBAAgB;EACpB;EACA;EACA,IAAI;EACJ,UAAU,cAAc,KAAK;EAC7B;EACA,MAAM;EACN;CACF,CAAC;AACH;;;;;AAMA,MAAa,SAAiB,IAAI,MAAM,CAAC,GAAa,EACpD,IAAI,SAAS,MAAM;CACjB,IAAI,OAAO,SAAS,UAClB;CAMF,IAAI,SAAS,UAAU,SAAS,WAAW,SAAS,aAAa,SAAS,UACxE;CAGF,IAAI,SAAS,WACX,QAAQ,UAAkB,EACxB,OAAO,IAAyB,SAAkB,YAChD,WAAW,MAAM,IAAI,SAAS,OAAO,EACzC;CAGF,QAAQ,IAAyB,SAAkB,YACjD,WAAW,MAAM,IAAI,SAAS,OAAO;AACzC,EACF,CAAC"}
package/esm/errors.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- //#region ../@warlock.js/notifications/src/errors.d.ts
1
+ //#region ../notifications/src/errors.d.ts
2
2
  /**
3
3
  * Domain errors for `@warlock.js/notifications`. All extend `Error` directly
4
4
  * (no framework HttpError) so the package stays runtime-agnostic — the host
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.mts","names":[],"sources":["../../../../../../@warlock.js/notifications/src/errors.ts"],"mappings":";;AAiBA;;;;;AAWA;;cAXa,+BAAA,SAAwC,KAAK;EAAL,WAAA;AAAA;AAAA,cAWxC,oBAAA,SAA6B,KAAK;cAC1B,WAAA;AAAA;AAAA,cAUR,sBAAA,SAA+B,KAAK;cAC5B,WAAA;AAAA;AAAA,cAUR,oBAAA,SAA6B,KAAK;cAC1B,gBAAA,UAA0B,WAAA;AAAA;;;;AAXP;AAUxC;cAgBa,sBAAA,SAA+B,KAAK;cAC5B,WAAA,UAAqB,WAAA;AAAA"}
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../../../../../../notifications/src/errors.ts"],"mappings":";;AAiBA;;;;;AAWA;;cAXa,+BAAA,SAAwC,KAAK;EAAL,WAAA;AAAA;AAAA,cAWxC,oBAAA,SAA6B,KAAK;cAC1B,WAAA;AAAA;AAAA,cAUR,sBAAA,SAA+B,KAAK;cAC5B,WAAA;AAAA;AAAA,cAUR,oBAAA,SAA6B,KAAK;cAC1B,gBAAA,UAA0B,WAAA;AAAA;;;;AAXP;AAUxC;cAgBa,sBAAA,SAA+B,KAAK;cAC5B,WAAA,UAAqB,WAAA;AAAA"}
package/esm/errors.mjs CHANGED
@@ -1,4 +1,4 @@
1
- //#region ../@warlock.js/notifications/src/errors.ts
1
+ //#region ../notifications/src/errors.ts
2
2
  /**
3
3
  * Domain errors for `@warlock.js/notifications`. All extend `Error` directly
4
4
  * (no framework HttpError) so the package stays runtime-agnostic — the host
@@ -1 +1 @@
1
- {"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../../@warlock.js/notifications/src/errors.ts"],"sourcesContent":["/**\n * Domain errors for `@warlock.js/notifications`. All extend `Error` directly\n * (no framework HttpError) so the package stays runtime-agnostic — the host\n * app maps them to its own error shape via `instanceof` if needed.\n *\n * Each captures a clean V8 stack (drops the Error-constructor frame) to match\n * the cascade convention.\n */\n\nfunction captureStack(target: object, ctor: new (...args: any[]) => unknown): void {\n // V8 only; guarded for non-V8 runtimes.\n (Error as unknown as { captureStackTrace?: (t: object, c: unknown) => void }).captureStackTrace?.(\n target,\n ctor,\n );\n}\n\nexport class NotificationsNotConfiguredError extends Error {\n public constructor() {\n super(\n \"Notifications not configured — add `src/config/notifications.ts` with a \" +\n \"default-exported config; the notifications connector registers it at boot.\",\n );\n this.name = \"NotificationsNotConfiguredError\";\n captureStack(this, NotificationsNotConfiguredError);\n }\n}\n\nexport class ChannelNotFoundError extends Error {\n public constructor(channelName: string) {\n super(\n `Channel \"${channelName}\" is not configured. Add it to the ` +\n \"`channels` map in `src/config/notifications.ts`.\",\n );\n this.name = \"ChannelNotFoundError\";\n captureStack(this, ChannelNotFoundError);\n }\n}\n\nexport class NoQueueDispatcherError extends Error {\n public constructor(channelName: string) {\n super(\n `Cannot queue to channel \"${channelName}\" — no queue dispatcher configured. ` +\n \"Add a `queue` to `src/config/notifications.ts`, or call `.send()` instead of `.queue()`.\",\n );\n this.name = \"NoQueueDispatcherError\";\n captureStack(this, NoQueueDispatcherError);\n }\n}\n\nexport class MissingRendererError extends Error {\n public constructor(notificationType: string, channelName: string) {\n super(\n `Notification \"${notificationType}\" routes to channel \"${channelName}\" via ` +\n `\\`via\\` but defines no \\`${channelName}\\` renderer.`,\n );\n this.name = \"MissingRendererError\";\n captureStack(this, MissingRendererError);\n }\n}\n\n/**\n * Thrown when a channel's `route()` resolver runs but returns `undefined` for\n * a recipient (e.g. a mail recipient with no email). Distinct from \"the\n * channel declares no resolver\" — that case falls back to `{ id }`.\n */\nexport class UnresolvableRouteError extends Error {\n public constructor(channelName: string, recipientId?: unknown) {\n super(\n `Channel \"${channelName}\" could not resolve a route for recipient ` +\n `${recipientId ?? \"(unknown)\"}. The channel's \\`route()\\` returned undefined — ` +\n \"the recipient is missing the address column this channel needs.\",\n );\n this.name = \"UnresolvableRouteError\";\n captureStack(this, UnresolvableRouteError);\n }\n}\n"],"mappings":";;;;;;;;;AASA,SAAS,aAAa,QAAgB,MAA6C;CAEjF,AAAC,MAA6E,oBAC5E,QACA,IACF;AACF;AAEA,IAAa,kCAAb,MAAa,wCAAwC,MAAM;CACzD,AAAO,cAAc;EACnB,MACE,oJAEF;EACA,KAAK,OAAO;EACZ,aAAa,MAAM,+BAA+B;CACpD;AACF;AAEA,IAAa,uBAAb,MAAa,6BAA6B,MAAM;CAC9C,AAAO,YAAY,aAAqB;EACtC,MACE,YAAY,YAAY,wFAE1B;EACA,KAAK,OAAO;EACZ,aAAa,MAAM,oBAAoB;CACzC;AACF;AAEA,IAAa,yBAAb,MAAa,+BAA+B,MAAM;CAChD,AAAO,YAAY,aAAqB;EACtC,MACE,4BAA4B,YAAY,qIAE1C;EACA,KAAK,OAAO;EACZ,aAAa,MAAM,sBAAsB;CAC3C;AACF;AAEA,IAAa,uBAAb,MAAa,6BAA6B,MAAM;CAC9C,AAAO,YAAY,kBAA0B,aAAqB;EAChE,MACE,iBAAiB,iBAAiB,uBAAuB,YAAY,iCACvC,YAAY,aAC5C;EACA,KAAK,OAAO;EACZ,aAAa,MAAM,oBAAoB;CACzC;AACF;;;;;;AAOA,IAAa,yBAAb,MAAa,+BAA+B,MAAM;CAChD,AAAO,YAAY,aAAqB,aAAuB;EAC7D,MACE,YAAY,YAAY,4CACnB,eAAe,YAAY,iHAElC;EACA,KAAK,OAAO;EACZ,aAAa,MAAM,sBAAsB;CAC3C;AACF"}
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../../notifications/src/errors.ts"],"sourcesContent":["/**\n * Domain errors for `@warlock.js/notifications`. All extend `Error` directly\n * (no framework HttpError) so the package stays runtime-agnostic — the host\n * app maps them to its own error shape via `instanceof` if needed.\n *\n * Each captures a clean V8 stack (drops the Error-constructor frame) to match\n * the cascade convention.\n */\n\nfunction captureStack(target: object, ctor: new (...args: any[]) => unknown): void {\n // V8 only; guarded for non-V8 runtimes.\n (Error as unknown as { captureStackTrace?: (t: object, c: unknown) => void }).captureStackTrace?.(\n target,\n ctor,\n );\n}\n\nexport class NotificationsNotConfiguredError extends Error {\n public constructor() {\n super(\n \"Notifications not configured — add `src/config/notifications.ts` with a \" +\n \"default-exported config; the notifications connector registers it at boot.\",\n );\n this.name = \"NotificationsNotConfiguredError\";\n captureStack(this, NotificationsNotConfiguredError);\n }\n}\n\nexport class ChannelNotFoundError extends Error {\n public constructor(channelName: string) {\n super(\n `Channel \"${channelName}\" is not configured. Add it to the ` +\n \"`channels` map in `src/config/notifications.ts`.\",\n );\n this.name = \"ChannelNotFoundError\";\n captureStack(this, ChannelNotFoundError);\n }\n}\n\nexport class NoQueueDispatcherError extends Error {\n public constructor(channelName: string) {\n super(\n `Cannot queue to channel \"${channelName}\" — no queue dispatcher configured. ` +\n \"Add a `queue` to `src/config/notifications.ts`, or call `.send()` instead of `.queue()`.\",\n );\n this.name = \"NoQueueDispatcherError\";\n captureStack(this, NoQueueDispatcherError);\n }\n}\n\nexport class MissingRendererError extends Error {\n public constructor(notificationType: string, channelName: string) {\n super(\n `Notification \"${notificationType}\" routes to channel \"${channelName}\" via ` +\n `\\`via\\` but defines no \\`${channelName}\\` renderer.`,\n );\n this.name = \"MissingRendererError\";\n captureStack(this, MissingRendererError);\n }\n}\n\n/**\n * Thrown when a channel's `route()` resolver runs but returns `undefined` for\n * a recipient (e.g. a mail recipient with no email). Distinct from \"the\n * channel declares no resolver\" — that case falls back to `{ id }`.\n */\nexport class UnresolvableRouteError extends Error {\n public constructor(channelName: string, recipientId?: unknown) {\n super(\n `Channel \"${channelName}\" could not resolve a route for recipient ` +\n `${recipientId ?? \"(unknown)\"}. The channel's \\`route()\\` returned undefined — ` +\n \"the recipient is missing the address column this channel needs.\",\n );\n this.name = \"UnresolvableRouteError\";\n captureStack(this, UnresolvableRouteError);\n }\n}\n"],"mappings":";;;;;;;;;AASA,SAAS,aAAa,QAAgB,MAA6C;CAEjF,AAAC,MAA6E,oBAC5E,QACA,IACF;AACF;AAEA,IAAa,kCAAb,MAAa,wCAAwC,MAAM;CACzD,AAAO,cAAc;EACnB,MACE,oJAEF;EACA,KAAK,OAAO;EACZ,aAAa,MAAM,+BAA+B;CACpD;AACF;AAEA,IAAa,uBAAb,MAAa,6BAA6B,MAAM;CAC9C,AAAO,YAAY,aAAqB;EACtC,MACE,YAAY,YAAY,wFAE1B;EACA,KAAK,OAAO;EACZ,aAAa,MAAM,oBAAoB;CACzC;AACF;AAEA,IAAa,yBAAb,MAAa,+BAA+B,MAAM;CAChD,AAAO,YAAY,aAAqB;EACtC,MACE,4BAA4B,YAAY,qIAE1C;EACA,KAAK,OAAO;EACZ,aAAa,MAAM,sBAAsB;CAC3C;AACF;AAEA,IAAa,uBAAb,MAAa,6BAA6B,MAAM;CAC9C,AAAO,YAAY,kBAA0B,aAAqB;EAChE,MACE,iBAAiB,iBAAiB,uBAAuB,YAAY,iCACvC,YAAY,aAC5C;EACA,KAAK,OAAO;EACZ,aAAa,MAAM,oBAAoB;CACzC;AACF;;;;;;AAOA,IAAa,yBAAb,MAAa,+BAA+B,MAAM;CAChD,AAAO,YAAY,aAAqB,aAAuB;EAC7D,MACE,YAAY,YAAY,4CACnB,eAAe,YAAY,iHAElC;EACA,KAAK,OAAO;EACZ,aAAa,MAAM,sBAAsB;CAC3C;AACF"}
@@ -4,7 +4,7 @@ import { NotificationColumnMapHost } from "./column-map.mjs";
4
4
  import { DatabaseNotification } from "./database-notification.mjs";
5
5
  import { FilterRules, RepositoryManager } from "@warlock.js/core";
6
6
 
7
- //#region ../@warlock.js/notifications/src/in-app/base-notifications-repository.d.ts
7
+ //#region ../notifications/src/in-app/base-notifications-repository.d.ts
8
8
  /**
9
9
  * Filter shape — logical keys the repo understands. `filterBy` maps each to a
10
10
  * physical column (or a predicate) derived from the model's `columnMap`.
@@ -1 +1 @@
1
- {"version":3,"file":"base-notifications-repository.d.mts","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/in-app/base-notifications-repository.ts"],"mappings":";;;;;;;;;;;KA2CY,mBAAA;EACV,EAAA,GAAK,EAAA;EACL,IAAA,WA0Ge;EAxGf,MAAA;EACA,WAAA,GAAc,EAAE;EAChB,cAAA;AAAA;;KAIU,sBAAA,YAAkC,IAAA,YAAgB,oBAAA,IAC5D,yBAAyB;AAAA,cAEd,2BAAA,gBACI,oBAAA,GAAuB,oBAAA,UAC9B,iBAAA,CAAkB,MAAA,EAAQ,mBAAA;EA4IvB;EAAA,iBA1IM,OAAA;EAEV,QAAA,EAAU,WAAA;cAEE,KAAA,GAAQ,sBAAA;EAkJgB;EAAA,IAtIhC,YAAA;EA8J6B;;;;;EAAA,QArJhC,aAAA;EAgLsB;;;;;;;EAAA,UArIpB,KAAA,CAAM,GAAA,EAAK,MAAA,oBAA0B,MAAA;EAvET;;;;;;;;;EA6FzB,SAAA,CACX,WAAA,EAAa,EAAA,EACb,KAAA,EAAO,eAAA,EACP,QAAA,GAAW,EAAA,GACV,OAAA,CAAQ,MAAA;EA9EA;;;;;EAsHJ,aAAA,CACL,YAAA,EAAc,EAAA,IACd,KAAA,EAAO,eAAA,EACP,QAAA,GAAW,EAAA,GACV,OAAA,CAAQ,MAAA;EAhDE;;;;;;EA4DN,QAAA,CAAS,WAAA,EAAa,EAAA,EAAI,EAAA,GAAK,EAAA,GAAK,OAAA;EAxDxC;;;;EAgFI,UAAA,CAAW,WAAA,EAAa,EAAA,EAAI,EAAA,GAAK,EAAA,GAAK,OAAA;EAtCpC;EAyDF,OAAA,CAAQ,WAAA,EAAa,EAAA,EAAI,EAAA,EAAI,EAAA,GAAK,OAAA,CAAQ,MAAA;EAxDpC;;;;EAgEN,SAAA,CAAU,WAAA,EAAa,EAAA,EAAI,EAAA,GAAK,EAAA,GAAK,OAAA;EAnDf;EAAA,QAwDrB,qBAAA;AAAA"}
1
+ {"version":3,"file":"base-notifications-repository.d.mts","names":[],"sources":["../../../../../../../notifications/src/in-app/base-notifications-repository.ts"],"mappings":";;;;;;;;;;;KA2CY,mBAAA;EACV,EAAA,GAAK,EAAA;EACL,IAAA,WA0Ge;EAxGf,MAAA;EACA,WAAA,GAAc,EAAE;EAChB,cAAA;AAAA;;KAIU,sBAAA,YAAkC,IAAA,YAAgB,oBAAA,IAC5D,yBAAyB;AAAA,cAEd,2BAAA,gBACI,oBAAA,GAAuB,oBAAA,UAC9B,iBAAA,CAAkB,MAAA,EAAQ,mBAAA;EA4IvB;EAAA,iBA1IM,OAAA;EAEV,QAAA,EAAU,WAAA;cAEE,KAAA,GAAQ,sBAAA;EAkJgB;EAAA,IAtIhC,YAAA;EA8J6B;;;;;EAAA,QArJhC,aAAA;EAgLsB;;;;;;;EAAA,UArIpB,KAAA,CAAM,GAAA,EAAK,MAAA,oBAA0B,MAAA;EAvET;;;;;;;;;EA6FzB,SAAA,CACX,WAAA,EAAa,EAAA,EACb,KAAA,EAAO,eAAA,EACP,QAAA,GAAW,EAAA,GACV,OAAA,CAAQ,MAAA;EA9EA;;;;;EAsHJ,aAAA,CACL,YAAA,EAAc,EAAA,IACd,KAAA,EAAO,eAAA,EACP,QAAA,GAAW,EAAA,GACV,OAAA,CAAQ,MAAA;EAhDE;;;;;;EA4DN,QAAA,CAAS,WAAA,EAAa,EAAA,EAAI,EAAA,GAAK,EAAA,GAAK,OAAA;EAxDxC;;;;EAgFI,UAAA,CAAW,WAAA,EAAa,EAAA,EAAI,EAAA,GAAK,EAAA,GAAK,OAAA;EAtCpC;EAyDF,OAAA,CAAQ,WAAA,EAAa,EAAA,EAAI,EAAA,EAAI,EAAA,GAAK,OAAA,CAAQ,MAAA;EAxDpC;;;;EAgEN,SAAA,CAAU,WAAA,EAAa,EAAA,EAAI,EAAA,GAAK,EAAA,GAAK,OAAA;EAnDf;EAAA,QAwDrB,qBAAA;AAAA"}
@@ -1,7 +1,7 @@
1
1
  import { resolveColumnMap } from "./column-map.mjs";
2
2
  import { RepositoryManager } from "@warlock.js/core";
3
3
 
4
- //#region ../@warlock.js/notifications/src/in-app/base-notifications-repository.ts
4
+ //#region ../notifications/src/in-app/base-notifications-repository.ts
5
5
  /**
6
6
  * Shipped behavior repository for the in-app store.
7
7
  *
@@ -1 +1 @@
1
- {"version":3,"file":"base-notifications-repository.mjs","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/in-app/base-notifications-repository.ts"],"sourcesContent":["/**\n * Shipped behavior repository for the in-app store.\n *\n * Concrete (NOT abstract) so `inApp.configure({ model })` can\n * `new BaseNotificationsRepository(model)` without subclassing. The dev only\n * extends this when they need extra query methods.\n *\n * ## The single source of truth: the model's `columnMap`\n *\n * The model declares its physical columns ONCE via `static columnMap`. The\n * constructor resolves that map and derives BOTH sides from it:\n *\n * - the READ path — `filterBy` maps logical keys (`recipientId`, `unread`,\n * `type`, …) onto the model's columns; `RepositoryManager` applies it.\n * - the WRITE / UPDATE / DELETE path — `createFor` / `markRead` / … translate\n * logical keys through the same `filterBy` via `toRow`.\n *\n * Because both come from one `columnMap`, reads and writes can never target\n * different columns. `unread` is mode-agnostic: it filters `is_read = false`\n * when the model has that flag, otherwise `read_at IS NULL`.\n *\n * @example default (SQL snake_case — no subclass needed)\n * inApp.configure({ model: Notification })\n *\n * @example custom columns — declare them on the model, not here\n * class Notification extends DatabaseNotification {\n * public static columnMap = { recipient: \"audience_id\", isRead: \"seen\" };\n * }\n */\nimport { type FilterRules, RepositoryManager } from \"@warlock.js/core\";\nimport type { NotificationContract } from \"../contracts\";\nimport type { DatabasePayload, Id } from \"../types\";\nimport {\n type NotificationColumnMapHost,\n type ResolvedNotificationColumnMap,\n resolveColumnMap,\n} from \"./column-map\";\nimport type { DatabaseNotification } from \"./database-notification\";\n\n/**\n * Filter shape — logical keys the repo understands. `filterBy` maps each to a\n * physical column (or a predicate) derived from the model's `columnMap`.\n */\nexport type NotificationsFilter = {\n id?: Id;\n type?: string;\n /** Mode-agnostic unread filter — resolves to the model's read-state column. */\n unread?: boolean;\n recipientId?: Id;\n idempotencyKey?: string;\n};\n\n/** Class form of a `DatabaseNotification` subclass — what `configure()` accepts. */\nexport type NotificationModelClass = (new (...args: any[]) => DatabaseNotification) &\n NotificationColumnMapHost;\n\nexport class BaseNotificationsRepository<\n TModel extends NotificationContract = NotificationContract,\n> extends RepositoryManager<TModel, NotificationsFilter> {\n /** Resolved physical columns for the bound model — the single source. */\n private readonly columns: ResolvedNotificationColumnMap;\n\n public filterBy: FilterRules;\n\n public constructor(model?: NotificationModelClass) {\n super();\n\n if (model) {\n this.source = model;\n }\n\n this.columns = resolveColumnMap(model?.columnMap);\n this.filterBy = this.buildFilterBy();\n }\n\n /** The tenant column for this model, or `undefined` for single-tenant. */\n public get tenantColumn(): string | undefined {\n return this.columns.tenant;\n }\n\n /**\n * Build `filterBy` from the resolved column map. `unread` is the\n * mode-agnostic read filter; `isRead` / `readAt` / `tenant` are exposed for\n * direct filtering only when the model declares those columns.\n */\n private buildFilterBy(): FilterRules {\n const { recipient, tenant, readAt, isRead } = this.columns;\n\n const rules: FilterRules = {\n id: \"=\",\n type: \"=\",\n recipientId: [\"=\", recipient],\n idempotencyKey: [\"=\", \"idempotency_key\"],\n unread: (value, query) => {\n if (value !== true && value !== \"true\") {\n return;\n }\n\n if (isRead) {\n query.where(isRead, false);\n } else if (readAt) {\n query.whereNull(readAt);\n }\n },\n };\n\n if (isRead) {\n rules.isRead = [\"=\", isRead];\n }\n\n if (readAt) {\n rules.readAt = [\"=\", readAt];\n }\n\n if (tenant) {\n rules.tenant = [\"=\", tenant];\n }\n\n return rules;\n }\n\n /**\n * Translate an object keyed by LOGICAL names into one keyed by PHYSICAL\n * columns, using `filterBy` as the lookup. Keys with no `[op, column]` tuple\n * (e.g. `title`, `body`, `payload`, `type`, `id`) pass through unchanged —\n * they're already physical. Used for every write / update / delete payload +\n * filter (the paths `RepositoryManager` does NOT map).\n */\n protected toRow(obj: Record<string, unknown>): Record<string, unknown> {\n const rules = this.filterBy as Record<string, unknown>;\n const row: Record<string, unknown> = {};\n\n for (const [logical, value] of Object.entries(obj)) {\n const rule = rules[logical];\n const column = Array.isArray(rule) ? (rule[1] as string) : logical;\n row[column] = value;\n }\n\n return row;\n }\n\n /**\n * Create one row for the recipient. New rows start unread; the tenant column\n * (when the model declares one) is written from `tenantId`, which the\n * database channel reads off the recipient.\n *\n * Idempotency: when `input.idempotencyKey` is set, find-or-create — return\n * the existing row instead of inserting a duplicate. A unique index on the\n * key is the backstop for the rare insert race (we re-fetch on conflict).\n */\n public async createFor(\n recipientId: Id,\n input: DatabasePayload,\n tenantId?: Id,\n ): Promise<TModel> {\n const { idempotencyKey } = input;\n\n if (idempotencyKey) {\n const existing = await this.firstByIdempotencyKey(recipientId, idempotencyKey);\n if (existing) {\n return existing;\n }\n }\n\n const row: Record<string, unknown> = { recipientId, ...input };\n\n if (this.columns.isRead) {\n row.isRead = false;\n }\n\n if (this.columns.tenant && tenantId !== undefined) {\n row.tenant = tenantId;\n }\n\n try {\n return await this.create(this.toRow(row));\n } catch (error) {\n // Lost the insert race to a concurrent send with the same key → re-fetch.\n if (idempotencyKey) {\n const existing = await this.firstByIdempotencyKey(recipientId, idempotencyKey);\n if (existing) {\n return existing;\n }\n }\n\n throw error;\n }\n }\n\n /**\n * Bulk-create one row per recipient sharing the same input + tenant. Reserved\n * for the Phase-2 `Channel.sendMany` fan-out hook; not on the per-recipient\n * send path yet.\n */\n public createManyFor(\n recipientIds: Id[],\n input: DatabasePayload,\n tenantId?: Id,\n ): Promise<TModel[]> {\n return Promise.all(\n recipientIds.map((recipientId) => this.createFor(recipientId, input, tenantId)),\n );\n }\n\n /**\n * Mark rows read — recipient-scoped. `id` omitted → all unread rows for the\n * recipient; `id` given → that one row, still scoped to the recipient. Scoped\n * to unread so a re-mark never overwrites an earlier `read_at` timestamp.\n * Sets whichever read-state column(s) the model declares.\n */\n public markRead(recipientId: Id, id?: Id): Promise<number> {\n const { isRead, readAt } = this.columns;\n const unreadScope = isRead ? { isRead: false } : { readAt: null };\n\n const data: Record<string, unknown> = {};\n\n if (isRead) {\n data.isRead = true;\n }\n\n if (readAt) {\n data.readAt = new Date();\n }\n\n return this.updateMany(\n this.toRow({ recipientId, ...unreadScope, ...(id !== undefined ? { id } : {}) }),\n this.toRow(data),\n );\n }\n\n /**\n * Inverse of `markRead`, same recipient-scoping. No unread scope needed —\n * clearing the read-state of an already-unread row is a no-op.\n */\n public markUnread(recipientId: Id, id?: Id): Promise<number> {\n const { isRead, readAt } = this.columns;\n const data: Record<string, unknown> = {};\n\n if (isRead) {\n data.isRead = false;\n }\n\n if (readAt) {\n data.readAt = null;\n }\n\n return this.updateMany(\n this.toRow({ recipientId, ...(id !== undefined ? { id } : {}) }),\n this.toRow(data),\n );\n }\n\n /** Find one row for a recipient (read path — `filterBy` maps the keys). */\n public findFor(recipientId: Id, id: Id): Promise<TModel | null> {\n return this.first({ recipientId, id } as NotificationsFilter);\n }\n\n /**\n * Delete rows — recipient-scoped. `id` omitted → clear all for the\n * recipient; `id` given → that one row.\n */\n public deleteFor(recipientId: Id, id?: Id): Promise<number> {\n return this.deleteMany(this.toRow({ recipientId, ...(id !== undefined ? { id } : {}) }));\n }\n\n /** Read path — `filterBy` maps `recipientId`/`idempotencyKey` to columns. */\n private firstByIdempotencyKey(recipientId: Id, idempotencyKey: string): Promise<TModel | null> {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;CACF;;CAGA,AAAO,QAAQ,aAAiB,IAAgC;EAC9D,OAAO,KAAK,MAAM;GAAE;GAAa;EAAG,CAAwB;CAC9D;;;;;CAMA,AAAO,UAAU,aAAiB,IAA0B;EAC1D,OAAO,KAAK,WAAW,KAAK,MAAM;GAAE;GAAa,GAAI,OAAO,SAAY,EAAE,GAAG,IAAI,CAAC;EAAG,CAAC,CAAC;CACzF;;CAGA,AAAQ,sBAAsB,aAAiB,gBAAgD;EAC7F,OAAO,KAAK,MAAM;GAAE;GAAa;EAAe,CAAwB;CAC1E;AACF"}
1
+ {"version":3,"file":"base-notifications-repository.mjs","names":[],"sources":["../../../../../../../notifications/src/in-app/base-notifications-repository.ts"],"sourcesContent":["/**\n * Shipped behavior repository for the in-app store.\n *\n * Concrete (NOT abstract) so `inApp.configure({ model })` can\n * `new BaseNotificationsRepository(model)` without subclassing. The dev only\n * extends this when they need extra query methods.\n *\n * ## The single source of truth: the model's `columnMap`\n *\n * The model declares its physical columns ONCE via `static columnMap`. The\n * constructor resolves that map and derives BOTH sides from it:\n *\n * - the READ path — `filterBy` maps logical keys (`recipientId`, `unread`,\n * `type`, …) onto the model's columns; `RepositoryManager` applies it.\n * - the WRITE / UPDATE / DELETE path — `createFor` / `markRead` / … translate\n * logical keys through the same `filterBy` via `toRow`.\n *\n * Because both come from one `columnMap`, reads and writes can never target\n * different columns. `unread` is mode-agnostic: it filters `is_read = false`\n * when the model has that flag, otherwise `read_at IS NULL`.\n *\n * @example default (SQL snake_case — no subclass needed)\n * inApp.configure({ model: Notification })\n *\n * @example custom columns — declare them on the model, not here\n * class Notification extends DatabaseNotification {\n * public static columnMap = { recipient: \"audience_id\", isRead: \"seen\" };\n * }\n */\nimport { type FilterRules, RepositoryManager } from \"@warlock.js/core\";\nimport type { NotificationContract } from \"../contracts\";\nimport type { DatabasePayload, Id } from \"../types\";\nimport {\n type NotificationColumnMapHost,\n type ResolvedNotificationColumnMap,\n resolveColumnMap,\n} from \"./column-map\";\nimport type { DatabaseNotification } from \"./database-notification\";\n\n/**\n * Filter shape — logical keys the repo understands. `filterBy` maps each to a\n * physical column (or a predicate) derived from the model's `columnMap`.\n */\nexport type NotificationsFilter = {\n id?: Id;\n type?: string;\n /** Mode-agnostic unread filter — resolves to the model's read-state column. */\n unread?: boolean;\n recipientId?: Id;\n idempotencyKey?: string;\n};\n\n/** Class form of a `DatabaseNotification` subclass — what `configure()` accepts. */\nexport type NotificationModelClass = (new (...args: any[]) => DatabaseNotification) &\n NotificationColumnMapHost;\n\nexport class BaseNotificationsRepository<\n TModel extends NotificationContract = NotificationContract,\n> extends RepositoryManager<TModel, NotificationsFilter> {\n /** Resolved physical columns for the bound model — the single source. */\n private readonly columns: ResolvedNotificationColumnMap;\n\n public filterBy: FilterRules;\n\n public constructor(model?: NotificationModelClass) {\n super();\n\n if (model) {\n this.source = model;\n }\n\n this.columns = resolveColumnMap(model?.columnMap);\n this.filterBy = this.buildFilterBy();\n }\n\n /** The tenant column for this model, or `undefined` for single-tenant. */\n public get tenantColumn(): string | undefined {\n return this.columns.tenant;\n }\n\n /**\n * Build `filterBy` from the resolved column map. `unread` is the\n * mode-agnostic read filter; `isRead` / `readAt` / `tenant` are exposed for\n * direct filtering only when the model declares those columns.\n */\n private buildFilterBy(): FilterRules {\n const { recipient, tenant, readAt, isRead } = this.columns;\n\n const rules: FilterRules = {\n id: \"=\",\n type: \"=\",\n recipientId: [\"=\", recipient],\n idempotencyKey: [\"=\", \"idempotency_key\"],\n unread: (value, query) => {\n if (value !== true && value !== \"true\") {\n return;\n }\n\n if (isRead) {\n query.where(isRead, false);\n } else if (readAt) {\n query.whereNull(readAt);\n }\n },\n };\n\n if (isRead) {\n rules.isRead = [\"=\", isRead];\n }\n\n if (readAt) {\n rules.readAt = [\"=\", readAt];\n }\n\n if (tenant) {\n rules.tenant = [\"=\", tenant];\n }\n\n return rules;\n }\n\n /**\n * Translate an object keyed by LOGICAL names into one keyed by PHYSICAL\n * columns, using `filterBy` as the lookup. Keys with no `[op, column]` tuple\n * (e.g. `title`, `body`, `payload`, `type`, `id`) pass through unchanged —\n * they're already physical. Used for every write / update / delete payload +\n * filter (the paths `RepositoryManager` does NOT map).\n */\n protected toRow(obj: Record<string, unknown>): Record<string, unknown> {\n const rules = this.filterBy as Record<string, unknown>;\n const row: Record<string, unknown> = {};\n\n for (const [logical, value] of Object.entries(obj)) {\n const rule = rules[logical];\n const column = Array.isArray(rule) ? (rule[1] as string) : logical;\n row[column] = value;\n }\n\n return row;\n }\n\n /**\n * Create one row for the recipient. New rows start unread; the tenant column\n * (when the model declares one) is written from `tenantId`, which the\n * database channel reads off the recipient.\n *\n * Idempotency: when `input.idempotencyKey` is set, find-or-create — return\n * the existing row instead of inserting a duplicate. A unique index on the\n * key is the backstop for the rare insert race (we re-fetch on conflict).\n */\n public async createFor(\n recipientId: Id,\n input: DatabasePayload,\n tenantId?: Id,\n ): Promise<TModel> {\n const { idempotencyKey } = input;\n\n if (idempotencyKey) {\n const existing = await this.firstByIdempotencyKey(recipientId, idempotencyKey);\n if (existing) {\n return existing;\n }\n }\n\n const row: Record<string, unknown> = { recipientId, ...input };\n\n if (this.columns.isRead) {\n row.isRead = false;\n }\n\n if (this.columns.tenant && tenantId !== undefined) {\n row.tenant = tenantId;\n }\n\n try {\n return await this.create(this.toRow(row));\n } catch (error) {\n // Lost the insert race to a concurrent send with the same key → re-fetch.\n if (idempotencyKey) {\n const existing = await this.firstByIdempotencyKey(recipientId, idempotencyKey);\n if (existing) {\n return existing;\n }\n }\n\n throw error;\n }\n }\n\n /**\n * Bulk-create one row per recipient sharing the same input + tenant. Reserved\n * for the Phase-2 `Channel.sendMany` fan-out hook; not on the per-recipient\n * send path yet.\n */\n public createManyFor(\n recipientIds: Id[],\n input: DatabasePayload,\n tenantId?: Id,\n ): Promise<TModel[]> {\n return Promise.all(\n recipientIds.map((recipientId) => this.createFor(recipientId, input, tenantId)),\n );\n }\n\n /**\n * Mark rows read — recipient-scoped. `id` omitted → all unread rows for the\n * recipient; `id` given → that one row, still scoped to the recipient. Scoped\n * to unread so a re-mark never overwrites an earlier `read_at` timestamp.\n * Sets whichever read-state column(s) the model declares.\n */\n public markRead(recipientId: Id, id?: Id): Promise<number> {\n const { isRead, readAt } = this.columns;\n const unreadScope = isRead ? { isRead: false } : { readAt: null };\n\n const data: Record<string, unknown> = {};\n\n if (isRead) {\n data.isRead = true;\n }\n\n if (readAt) {\n data.readAt = new Date();\n }\n\n return this.updateMany(\n this.toRow({ recipientId, ...unreadScope, ...(id !== undefined ? { id } : {}) }),\n this.toRow(data),\n );\n }\n\n /**\n * Inverse of `markRead`, same recipient-scoping. No unread scope needed —\n * clearing the read-state of an already-unread row is a no-op.\n */\n public markUnread(recipientId: Id, id?: Id): Promise<number> {\n const { isRead, readAt } = this.columns;\n const data: Record<string, unknown> = {};\n\n if (isRead) {\n data.isRead = false;\n }\n\n if (readAt) {\n data.readAt = null;\n }\n\n return this.updateMany(\n this.toRow({ recipientId, ...(id !== undefined ? { id } : {}) }),\n this.toRow(data),\n );\n }\n\n /** Find one row for a recipient (read path — `filterBy` maps the keys). */\n public findFor(recipientId: Id, id: Id): Promise<TModel | null> {\n return this.first({ recipientId, id } as NotificationsFilter);\n }\n\n /**\n * Delete rows — recipient-scoped. `id` omitted → clear all for the\n * recipient; `id` given → that one row.\n */\n public deleteFor(recipientId: Id, id?: Id): Promise<number> {\n return this.deleteMany(this.toRow({ recipientId, ...(id !== undefined ? { id } : {}) }));\n }\n\n /** Read path — `filterBy` maps `recipientId`/`idempotencyKey` to columns. */\n private firstByIdempotencyKey(recipientId: Id, idempotencyKey: string): Promise<TModel | null> {\n return this.first({ recipientId, idempotencyKey } as NotificationsFilter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,IAAa,8BAAb,cAEU,kBAA+C;;CAEvD,AAAiB;CAEjB,AAAO;CAEP,AAAO,YAAY,OAAgC;EACjD,MAAM;EAEN,IAAI,OACF,KAAK,SAAS;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C;EAAG,CAAC,CAAC;CACzF;;CAGA,AAAQ,sBAAsB,aAAiB,gBAAgD;EAC7F,OAAO,KAAK,MAAM;GAAE;GAAa;EAAe,CAAwB;CAC1E;AACF"}
@@ -1,4 +1,4 @@
1
- //#region ../@warlock.js/notifications/src/in-app/column-map.d.ts
1
+ //#region ../notifications/src/in-app/column-map.d.ts
2
2
  /**
3
3
  * `columnMap` — how a notification model's logical roles map to the physical
4
4
  * columns of ITS table. The ONE source the model getters, the repository
@@ -1 +1 @@
1
- {"version":3,"file":"column-map.d.mts","names":[],"sources":["../../../../../../../@warlock.js/notifications/src/in-app/column-map.ts"],"mappings":";;AAkCA;;;;;;;;;AAQQ;AAQR;;;;;;;;;AAIQ;AAIR;;;;AACmC;AAYnC;;;;;;;KArCY,qBAAA;EAuCoB,iDArC9B,SAAA;EAEA,MAAA;EAEA,MAAA;EAEA,MAAA;AAAA;;;;;;KAQU,6BAAA;EACV,SAAA;EACA,MAAA;EACA,MAAA;EACA,MAAA;AAAA;;KAIU,yBAAA;EACV,SAAA,GAAY,qBAAqB;AAAA;;;;;;;iBAYnB,gBAAA,CACd,GAAA,EAAK,qBAAA,eACJ,6BAA6B"}
1
+ {"version":3,"file":"column-map.d.mts","names":[],"sources":["../../../../../../../notifications/src/in-app/column-map.ts"],"mappings":";;AAkCA;;;;;;;;;AAQQ;AAQR;;;;;;;;;AAIQ;AAIR;;;;AACmC;AAYnC;;;;;;;KArCY,qBAAA;EAuCoB,iDArC9B,SAAA;EAEA,MAAA;EAEA,MAAA;EAEA,MAAA;AAAA;;;;;;KAQU,6BAAA;EACV,SAAA;EACA,MAAA;EACA,MAAA;EACA,MAAA;AAAA;;KAIU,yBAAA;EACV,SAAA,GAAY,qBAAqB;AAAA;;;;;;;iBAYnB,gBAAA,CACd,GAAA,EAAK,qBAAA,eACJ,6BAA6B"}
@@ -1,4 +1,4 @@
1
- //#region ../@warlock.js/notifications/src/in-app/column-map.ts
1
+ //#region ../notifications/src/in-app/column-map.ts
2
2
  const DEFAULT_RECIPIENT_COLUMN = "user_id";
3
3
  const DEFAULT_READ_AT_COLUMN = "read_at";
4
4
  /**