{"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"}