Developer guide · 4 min
Notification delivery & worker lifecycle
The personal inbox projects committed business outboxes. Device alerts are a separate opt-in delivery channel and never drive financial or fulfillment state.
Database lifecycle
Nest initializes the shared TypeORM DataSource. Scheduled work waits for application bootstrap and checks isInitialized before starting. On module destruction, workers stop accepting work and await their active batch before TypeORM closes the pool.
Do not initialize or destroy a separate database connection inside a worker tick. A Driver not Connected error means the worker reached an unavailable pool; check shutdown signals, application restarts and accidental manual destroy calls.
Enable device alerts
Install the backend web-push runtime dependency and apply PersonalNotifications1793538000000 after the existing business migrations. Configure NOTIFICATIONS_PUSH_ENABLED, NOTIFICATIONS_VAPID_PUBLIC_KEY, NOTIFICATIONS_VAPID_PRIVATE_KEY and NOTIFICATIONS_VAPID_SUBJECT. Keep the private key on the backend.
Serve the frontend over HTTPS. The manifest, notification icons and notifications-sw.js must be public and served from the same origin. Device registration is authenticated. No permission is requested on page load.
The service worker handles device alerts only; it never caches checkout, receipts or payment API responses. If your deployment already has a service worker, integrate these handlers into that worker before enabling this feature.
Delivery semantics and recovery
New business events are projected in bounded batches every 15 seconds. Recent history can populate the inbox without sending retrospective device alerts. Email and WhatsApp events for the same subscription cycle and kind become one inbox update.
Push retries use durable leases, bounded backoff and a stable browser notification tag. Expired subscriptions are disabled; alerts more than 24 hours old are skipped. ACCEPTED means the push provider accepted the request, not that the device displayed or the user read it.
In-app reads are per user. Role and active-account checks use current database records. Manual order updates use request IDs for replay protection and preserve the author ID.
Personal inbox API
GET /notifications/me accepts limit and cursor. PATCH /notifications/me/:notificationId/read marks an owned notification as read. PATCH /notifications/me/read-all accepts a through cursor so later arrivals stay unread.
GET /notifications/push/configuration returns the public VAPID key when configured. POST /notifications/push/devices registers this device; DELETE /notifications/push/devices/:deviceId revokes it. POST /notifications/admin/message sends an audited order-specific in-app update.
