Open MercatoDocsSearch docsAPI reference

Framework

Notification Delivery

Trace a notification from its type definition to the user's device. When a phone stays quiet, first check whether delivery was allowed for that user and channel, then inspect the transport and provider response.

Four modules cooperate to turn notificationService.create(...) into a banner on someone's phone. Each owns exactly one thing:

ModuleOwns
notificationsThe content, the type registry, per-user preferences, and the single delivery gate.
devicesThe address book – which devices a user has and what push token each holds.
push_notificationsTransport for the push channel: fan-out, queue worker, retries, delivery log.
communication_channelsThe provider credentials and the adapter that talks to FCM / APNs / Expo.

This page is the map between them. For creating notifications (service API, batch, role- and feature-targeted sends, renderers) see Notifications; for the transport internals see Push Notifications and Devices.

The path a notification takes

  1. Your code calls notificationService.create({ type, recipientUserId, ... }).
  2. The gate runs once, at create time, per candidate channel – packages/core/src/modules/notifications/lib/shouldDeliver.ts. The surviving set is snapshotted onto the notification's channels column, so every downstream strategy obeys one decision instead of re-deriving it.
  3. The dispatcher invokes each surviving channel's delivery strategy.
  4. For push, that strategy enqueues a fan-out; the actual provider send happens in a worker, so a slow provider never blocks notification creation.

The important consequence: a channel that the gate removed is not "skipped later", it never reaches the strategy at all. When you debug a missing notification, start at the gate.

Registering a notification type

This is the part your own module writes. A notification type is declared in a notifications.ts file at the module root – a convention file the generator discovers (packages/core/src/modules/notifications/generators.ts). There is no runtime registration call and no central list to edit.

// packages/<pkg>/src/modules/<module>/notifications.ts
// or apps/mercato/src/modules/<module>/notifications.ts
import type { NotificationTypeDefinition } from '@open-mercato/shared/modules/notifications/types'

export const notificationTypes: NotificationTypeDefinition[] = [
  {
    type: 'shipping.shipment.delayed',
    module: 'shipping',
    channels: ['in_app', 'email', 'push'],
    titleKey: 'shipping.notifications.shipmentDelayed.title',
    bodyKey: 'shipping.notifications.shipmentDelayed.body',
    icon: 'truck',
    severity: 'warning',
    actions: [
      { id: 'view', labelKey: 'common.view', href: '/backend/shipping/shipments', icon: 'external-link' },
    ],
    linkHref: '/backend/shipping/shipments',
    expiresAfterHours: 72,
  },
]

Then run yarn generate. Emitting one is an ordinary service call:

await notificationService.create({
  type: 'shipping.shipment.delayed',
  recipientUserId: userId,
  tenantId,
  organizationId,
  titleVariables: { trackingNumber },
})

The type definition

Declared in packages/shared/src/modules/notifications/types.ts.

FieldRequiredWhat it does
typeyesStable id, module.entity.action. Never rename one in place – a renamed type stops matching stored preferences, and in-flight notifications referencing it lose their nonOptOut enforcement.
moduleyesOwning module id.
titleKey / bodyKeytitle yesi18n keys resolved per recipient locale.
icon, severityyes / yesinfo | warning | success | error.
actions, primaryActionId, linkHrefnoButtons and the click-through target.
channelsno, and that mattersThe channels this type may ever use. See the warning below.
nonOptOutnoThe recipient cannot disable it. Preference UIs render it locked; setPreferences refuses to store an opt-out row. Use for security and account alerts.
silentnoPush is delivered as a data-only wake-up instead of a visible alert. Style only – it does not imply non-opt-out. To force a silent push through, mark the type nonOptOut as well.
hiddenFromSettingsnoNot mirrored to notification_types, so a client's preferences screen never lists it. For server-dispatched internal types.
category, labelKey, descriptionKeynoGrouping and copy for a preferences screen. category defaults to the prefix before the first dot.
expiresAfterHoursnoAuto-expiry of the in-app row.
RenderernoClient-side custom rendering – declared in notifications.client.ts, not here.

Warning · A type that omits channels is eligible for every registered channel

resolveEligibleChannels returns null for such a type, and null means no restriction – not no channels. Once a tenant connects a push provider, every type without an explicit channels list becomes push-eligible. 2 of the 83 types currently in the registry omit it (see the map below, where they render as — (all registered)).

The fallback stays as it is, so a third-party type that omits channels keeps working unchanged. What changed with #5495 is that every built-in type now declares its eligibility explicitly rather than inheriting the fallback; the two that still omit it are push_notifications' hidden admin custom-push types, which bypass the catalogue entirely. Declare channels explicitly on every type you add – packages/core/src/__tests__/notification-channel-eligibility.test.ts enforces that for every first-party module-root catalogue.

Where a type ends up

syncNotificationTypes (packages/core/src/modules/notifications/lib/notification-type-registry.ts) reconciles the in-memory catalogue into the notification_types table. That table is the read-through mirror remote clients use:

Category labels live in the declaring module's i18n/*.json under notifications.categories.<key>; the notifications module deliberately ships none and holds no list of categories.

Channels

A channel has two halves, in two different convention files – do not conflate them.

Metadata – what the preferences UI calls it. notification-channels.ts, exporting notificationChannels: NotificationChannelDefinition[]. Core ships one such file, packages/core/src/modules/notifications/notification-channels.ts, declaring in_app, email and push. It backs GET /api/notifications/channels.

Behavior – what actually delivers. notifications.delivery-strategies.ts, exporting deliveryStrategies. The generator plugin declared in packages/core/src/modules/notifications/generators.ts collects them into a generated registry that packages/core/src/modules/notifications/lib/delivery-strategies-registry.ts installs at bootstrap. push_notifications ships exactly this and nothing more exotic – packages/core/src/modules/push_notifications/notifications.delivery-strategies.ts is two imports and two exports.

// packages/<pkg>/src/modules/<module>/notifications.delivery-strategies.ts
export const deliveryStrategies = [myChannelDeliveryStrategy]

A strategy declares id (the channel id), label, defaultEnabled, and an async deliver(ctx). Keep deliver fast: enqueue, do not send. packages/core/src/modules/push_notifications/lib/push-delivery-strategy.ts is the reference.

The delivery gate

shouldDeliver is the one place a per-channel decision is made. A channel delivers when all four hold, in this order:

  1. It is a registered strategy id. An unregistered channel never delivers, whatever the type says.
  2. The type is eligible for it – the operator's stored override (notification_types.channels) if set, otherwise the code-declared type.channels. This runs before the nonOptOut bypass, so a channel outside the effective set is completely off for that type, even for a non-opt-out security alert.
  3. It is in the per-send target, when the caller supplied one.
  4. Either the type is effectively nonOptOut, or the recipient has not disabled it.

silent is deliberately not consulted: it selects push style, not whether a channel delivers.

A type id with no registered definition (a renamed or removed type still referenced by an in-flight notification) cannot have its code-declared nonOptOut enforced, so it becomes user-suppressible. The gate logs that once per type id per process – worth grepping for after a rename.

Operator overrides

An operator changes a type's channel eligibility and its non-opt-out flag per tenant, without a code change, from Settings → Notification Delivery (/backend/config/notifications, feature notifications.manage). The override replaces the code-declared value for that tenant only, and beats user preferences in both directions: a channel removed there is off even for a nonOptOut type, and preference UIs lock the cell.

Preferences

Preferences are stored per (user, type, channel).

ScreenPathFeature
A user's own preferences/backend/profile/notification-preferencesnotifications.manage_preferences
Another user's preferences (admin)/backend/notifications/user-preferencesnotifications.manage_user_preferences
Per-type channel eligibility (operator)/backend/config/notificationsnotifications.manage

ACL features: notifications.view, notifications.create, notifications.manage, notifications.manage_preferences, notifications.manage_user_preferences (packages/core/src/modules/notifications/acl.ts).

Registered notification types

Every type currently in the registry, grouped by the module that declares it. — (all registered) means the type declares no channels and is therefore eligible for every registered channel, push included.

This map is asserted against the real convention files by apps/docs/__tests__/notification-registry.test.mjs – every cell of every row, not just the type id, plus the two counts quoted in the warning above. Adding a type without documenting it here, or changing a type's severity, channels or flags without updating its row, fails the docs test.

Groups marked (enterprise) are declared in packages/enterprise and are not present in an OSS install.

agent_orchestrator (enterprise)

TypeSeverityDeclared channelsFlags
agent_orchestrator.proposal.pendinginfoin_app –
agent_orchestrator.run.review_requestedwarningin_app –

ai_assistant

TypeSeverityDeclared channelsFlags
ai_assistant.conversation_sharedinfoin_app, email –
ai_assistant.pending_action.awaiting_approvalwarningin_app, email –

auth

TypeSeverityDeclared channelsFlags
auth.account.lockedwarningin_app, emailnon-opt-out
auth.login.new_deviceinfoin_app, emailnon-opt-out
auth.password_reset.completedsuccessin_app, email –
auth.password_reset.requestedinfoin_app, email –
auth.role.assignedsuccessin_app, email –
auth.role.revokedwarningin_app, email –

business_rules

TypeSeverityDeclared channelsFlags
business_rules.rule.execution_failederrorin_app, email –

catalog

TypeSeverityDeclared channelsFlags
catalog.product.low_stockwarningin_app, email –

checkout

TypeSeverityDeclared channelsFlags
checkout.link.usageLimitReachedwarningin_app, email –
checkout.transaction.completedsuccessin_app, email –
checkout.transaction.failederrorin_app, email –

communication_channels

TypeSeverityDeclared channelsFlags
communication_channels.channel.requires_reauthwarningin_app, email –
communication_channels.message.receivedinfoin_app, email –

customer_accounts

TypeSeverityDeclared channelsFlags
customer_accounts.domain_mapping.activatedsuccessin_app, email –
customer_accounts.domain_mapping.dns_failedwarningin_app, email –
customer_accounts.domain_mapping.tls_failedwarningin_app, email –
customer_accounts.domain_mapping.verifiedsuccessin_app, email –
customer_accounts.user.lockedwarningin_app, email –
customer_accounts.user.signupinfoin_app, email –

customers

TypeSeverityDeclared channelsFlags
customers.deal.lostwarningin_app, email –
customers.deal.wonsuccessin_app, email –

documents

TypeSeverityDeclared channelsFlags
documents.comment.mentionedinfoin_app, email –
documents.watch.changedinfoin_app, email –
documents.watch.commentedinfoin_app, email –

ecommerce

TypeSeverityDeclared channelsFlags
ecommerce.store.assortment_emptywarningin_app –
ecommerce.store.channel_binding_missingwarningin_app –

eudr

TypeSeverityDeclared channelsFlags
eudr.mitigation.completedsuccessin_app, email –
eudr.risk.non_negligiblewarningin_app, email –
eudr.statement.reference_issuedsuccessin_app, email –
eudr.statement.submittedinfoin_app, email –
eudr.statement.withdrawnwarningin_app, email –

example

TypeSeverityDeclared channelsFlags
demo.push_playgroundinfopush –
demo.silent_pinginfopushsilent
example.umes.actionableinfoin_app, email –

inbox_ops

TypeSeverityDeclared channelsFlags
inbox_ops.proposal.createdinfoin_app, email –

messages

TypeSeverityDeclared channelsFlags
messages.newinfoin_app, email –

push_notifications

TypeSeverityDeclared channelsFlags
admin.custom_messageinfo – (all registered)non-opt-out, hidden from settings
admin.custom_silentinfo – (all registered)non-opt-out, silent, hidden from settings

record_locks (enterprise)

TypeSeverityDeclared channelsFlags
record_locks.conflict.detectedwarningin_app, email –
record_locks.conflict.resolvedinfoin_app, email –
record_locks.incoming_changes.availableinfoin_app, email –
record_locks.lock.contendedwarningin_app, email –
record_locks.lock.force_releasedwarningin_app, email –
record_locks.participant.joinedinfoin_app, email –
record_locks.participant.leftinfoin_app, email –
record_locks.record.deletedwarningin_app, email –

sales

TypeSeverityDeclared channelsFlags
sales.order.createdinfoin_app, email –
sales.payment.receivedsuccessin_app, email –
sales.quote.createdinfoin_app, email –
sales.quote.expiringwarningin_app, email –

security (enterprise)

TypeSeverityDeclared channelsFlags
security.mfa.emergency_bypass_detectedwarningin_app –
security.mfa.enforcement_deadlinewarningin_app, email –
security.mfa.enrolledsuccessin_app, email –
security.mfa.resetwarningin_app, email –
security.password.changedsuccessin_app, email –

staff

TypeSeverityDeclared channelsFlags
staff.leave_request.approvedsuccessin_app, email –
staff.leave_request.pendingwarningin_app, email –
staff.leave_request.rejectedwarningin_app, email –
staff.support_ticket.createdinfoin_app, email –
staff.support_ticket.customer_repliedinfoin_app, email –
staff.timesheets.project_access.requestedinfoin_app, email –
staff.timesheets.time_entry.timer_running_longwarningin_app –
staff.timesheets.time_project.budget_threshold_reachedwarningin_app, email –
staff.timesheets.time_report.approvedsuccessin_app, email –
staff.timesheets.time_report.ready_for_approvalinfoin_app, email –
staff.timesheets.time_task.assignedinfoin_app –
staff.timesheets.time_task.releasedinfoin_app –
staff.timesheets.timesheet.period_incompletewarningin_app, email –

warranty_claims

TypeSeverityDeclared channelsFlags
warranty_claims.claim.assignedinfoin_app, email –
warranty_claims.claim.customer_repliedinfoin_app, email –
warranty_claims.claim.escalatedwarningin_app, email –
warranty_claims.claim.status_changedinfoin_app, email –
warranty_claims.claim.submittedinfoin_app, email –

webhooks

TypeSeverityDeclared channelsFlags
webhooks.delivery.failederrorin_app, email –

wms

TypeSeverityDeclared channelsFlags
wms.inventory.low_stockwarningin_app, email –
wms.inventory.reservation_shortfallwarningin_app, email –

workflows

TypeSeverityDeclared channelsFlags
workflows.task.assignedinfoin_app, email –
workflows.task.deadline_breachederrorin_app, email –
workflows.task.reminder_duewarningin_app, email –

Previous: Messages System · Next: Notifications System