On this page
- Status: Accepted. Connected-metrics-only audit, Batch 8 (2026-09-17).
- Owners: Platform (alerts / notifications).
- Extends: ADR 0046 (delivery posture — the three-tier
gate and the in-app-only default are unchanged by this ADR),
ADR 0047 (
notification_preferencesis the one answer to "which channel"), ADR 0048 (the vertical/domain registry a domain now declares its notification types in), ADR 0049 (the connector contract this adapter contract mirrors).
Context#
Two vocabularies were closed unions in hand-written code. NOTIFICATION_CHANNELS was a five-value
tuple, and the answer to "what is a channel" was additionally spelled out in a config schema, a target
schema, a dispatch switch, a label map, two linkable-channel sets and an admin default-label record:
adding a transport (Slack, Teams, SMS, WhatsApp, a customer's own webhook) meant editing each of them,
and a channel missed in one place compiled forever. NOTIFICATION_TYPES was one flat array, so a
vertical could declare its brief personas, its levers, its conversion sources and its dataset packs at
its own registry row (ADR 0048) but not its own notification types.
This ADR generalises the MECHANISM. The policy model is untouched: same three tiers, same defaults.
Decisions#
D1 — the channel registry is the one enumeration, and it lives in the pure package
packages/notify/src/channels.ts holds NOTIFICATION_CHANNEL_REGISTRY, one row per channel:
interface NotificationChannelDescriptor {
readonly id: NotificationChannelId; // the token every `channels` jsonb already stores
readonly kind: 'in_app' | 'external';
readonly userLink: 'none' | 'push_subscription' | 'link_code';
readonly i18nLabelKey: string; // the label every surface renders
readonly defaultLabel: string; // the admin card's name before an operator renames it
}
NotificationChannelId = keyof typeof NOTIFICATION_CHANNEL_REGISTRY, and everything else is derived
from the rows: NOTIFICATION_CHANNELS, EXTERNAL_NOTIFICATION_CHANNELS, NotificationChannelSchema
(the Zod boundary), notificationChannelsRequiringUserLink(), notificationChannelsLinkedByCode().
No consumer asks a membership question by naming ids: the settings card's linkable set, the admin
router's unlink input and default labels, and the public-meta read all read a derivation.
It lives in @yng/notify rather than in the delivery package because the preference matrix and the
platform ceiling table are CLIENT components and render these rows, and a credential or an HTTP
transport may not enter a client bundle (§73). The ids are declared where both sides can import them;
the adapters live where delivery does.
D2 — a channel adapter, mirroring the connector contract
packages/notify-channels/src/adapters/contract.ts. defineChannelAdapter fills probeConfig and
testSend in, so every channel answers them identically:
interface NotificationChannelAdapter<Config, Target> {
readonly id: ExternalNotificationChannel;
readonly i18nLabelKey: string;
readonly defaultLabel: string;
readonly userLink: NotificationChannelUserLink;
readonly configSchema: z.ZodType<Config>; // the platform credential, named Zod
readonly targetSchema: z.ZodType<Target>; // one delivery address, named Zod
readonly emptyTargetReason: 'no_target' | 'channel_not_linked';
probeConfig(value: unknown): ChannelConfigProbe<Config>; // configured at platform level?
publicMeta(config: Config): Record<string, string>; // the non-secret half
resolveUserTargets(
db: ChannelAdapterDb,
recipient: ChannelRecipient,
): Promise<readonly ChannelUserTarget<Target>[]>;
revokeTarget?(db: ChannelAdapterWriteDb, revokeId: string): Promise<void>;
deliver(input: ChannelDeliverInput<Config, Target>): Promise<ChannelSendOutcome>;
testSend(input: ChannelTestSendInput<Config>): Promise<ChannelSendOutcome>;
}
NOTIFICATION_CHANNEL_ADAPTERS is typed Record<ExternalNotificationChannel, NotificationChannelAdapter>: a registry row with no adapter does not COMPILE — the same closure
discipline ADR 0049's DATASET_BINDING_ADAPTERS uses, a type rather than a test. ChannelConfig and
ChannelTarget are unions derived from the adapters' own schemas, so there is no hand-written
discriminated union of either any more. sendThroughChannel has no per-channel branch: the target's
channel selects the adapter, the adapter's targetSchema validates the address, deliver is the
adapter's. Neither does the alert engine's dispatchExternalNotification: it walks
resolveUserTargets and retires a target the far side reports gone through revokeTarget, which is
what several push subscriptions and one email address have in common.
Policy is not in the adapter. An adapter is handed a config and a target only after all three tiers have passed, and it cannot widen them.
D3 — the three tiers are unchanged
Platform (/admin/notifications/channels — a channel is configured and active) -> org
(/admin/notifications/orgs — OFF for every org on every external channel until a super admin turns
it on) -> person (/settings/notifications — per notification type, per brand where the type is
brand-scoped, in-app only until they tick a cell). resolveChannelAvailability and resolveDelivery
are unchanged, in-app is still exempt from the platform tier, and the audit trail
(admin.notification_channel.update / .enable) is unchanged.
D4 — a domain declares its own notification types
A verticals.ts row gains notificationTypes: NotificationTypeDeclaration[], alongside
briefPersonas / levers / conversionSources / packs:
const notificationTypeDeclarationSchema = z.object({
key: z.string().min(1).max(64), // == the notification_settings.rule_id that governs it
ownerSurface: z.string().min(1).max(120),
brandScoped: z.boolean(),
severityDefault: z.enum(['info', 'warn', 'critical']),
i18nKey: z.string().min(1).max(64),
capability: z.string().min(1).max(32).optional(), // the plane whose ROWS it needs
});
The six ECOM-shaped types (stockout_imminent, gmv_anomaly, creator_hour_spike,
return_rate_spike, price_conflict, margin_collapse) move to the ecom row — same keys, same
order, same capability: 'ecom', so no data migration and no change to what /admin/notifications
edits. The platform-audience types (§79: sync_failure_run, webhook_lag,
reconciliation_critical, budget_burn) and the domain-less org types (dataset.rule_fired,
brief.ready) stay in NOTIFICATION_BASE_TYPES (@yng/notify/catalogue): a tenant dataset rule and
the Morning Brief belong to no vertical, so no vertical could own them. A domain may not declare a
platform-audience type, and a declared capability must be the domain's own key.
NOTIFICATION_TYPES is the union of the domains' declarations and the base list, and it is
ORG-BLIND: the emit path (findNotificationType) must resolve a producer's key whatever an org has
activated, or a real finding would vanish from an inbox. What an org may be OFFERED is
notificationTypesForOrg() plus the caller's capability filter — three gates, in this order:
- audience (§79) — a
platformtype is invisible to anyone but a super admin; - domain activation — a domain-declared type is offered only where that domain is activated
(
org_domain_activations, viaactivatedDomainsForOrg). An org with NO activation row keeps every domain type, which is the pre-backfill answer and the one that cannot take a type away from an org already receiving it; - data capability —
resolveOrgCapabilities(orgId, 'data'), applied at the boundary innotifications.preferences: an org that activatedecombut has never synced an order is offered nothing eCom-shaped.
Gate 2 asks what the org was PROVISIONED with; gate 3 asks what rows it actually holds. Both must pass.
D5 — the guards
Record<ExternalNotificationChannel, NotificationChannelAdapter>(D2) — a channel without an adapter fails the build.packages/notify-channels/src/adapters/registry.test.ts— registry membership equals the channel registry's external set, every adapter answers every member of the contract, each config schema parses its own example including the defaults it declares (the ZaloappIdcase), each target schema refuses another channel's address, and target resolution / revoke behave peruserLink.scripts/audit/notification-single-preference-store.pycheck 4 (inaudit:all) — outsidechannels.ts, no file spells the channel ids out as a closed union or an inline list. A comment naming the tokens a column stores, a rule row's ownchannelsdefault, and a test's expectations are not flagged.apps/web/src/__tests__/notification-type-registry.test.ts— every id the platform can produce resolves (everyDEFAULT_RULE_IDSmember, and a tenant rule to the one shared key), the catalogue and its copy are a bijection invianden, and the domain gate is exercised both ways.- The type registry itself fails the BUILD on a duplicate key, a type claimed by two domains, or a
capabilitynaming a plane@yng/notifydoes not know.
Consequences#
- Adding a transport is a registry row plus an adapter: no union edit in a router, an admin page, the worker or the preference matrix. The admin console's per-channel CONFIG FORM FIELDS stay per-channel UI — they are that vendor's own credential shape — but they are enumerated by the registry-derived union, so the compiler names the gap.
- A future vertical (warehouse, a real finance one) declares its notification types where it already declares its personas and levers, and an org that has not activated that domain is never offered them.
@yng/notifynow depends on@yng/plugin-host(one direction only; plugin-host depends on neither notify package). The channel registry is a separate module (@yng/notify/channels) so a client component importing channels does not pull the vertical registry into its bundle.packages/notify-channels/src/target.tsis gone: its two per-user reads are nowidentities.ts(raw rows, no channel types) plus each adapter's ownresolveUserTargets. Those reads are capped atUSER_PUSH_SUBSCRIPTION_CAP(20) per person, where the previous loader was unbounded (§1).AlertDelivery(packages/alerts) is deleted — an unused interface carrying a three-value channel union from the pre-ADR-0047 sink design.