name: identity-notifications description: Add or change identity notification types in the 6529 SEIZE backend by updating notification causes, domain data types, DB-to-domain mappers, UserNotifier creation methods, push notification rendering/settings, notification API mappings, OpenAPI enums, and tests. Use when adding new notification types, creating identity notifications, changing notification payloads, or extending push/API notification behavior.
Identity Notifications
Use this workflow when a new event should appear in identity notification lists, push notifications, or both.
Workflow
- Define the notification contract before editing:
- cause enum in
UPPER_SNAKE_CASE - recipient, actor, related drop(s), wave, visibility group, and custom
additional_data - trigger location and transaction boundary
- whether self-notifications must be skipped
- API related identities/drops needed by the frontend
- push title, body, image, deep link, and settings key
- cause enum in
- Update the core domain files:
- add the cause to
IdentityNotificationCauseinsrc/entities/IIdentityNotification.ts - add a data interface and full notification interface in
src/notifications/user-notification.types.ts - add the new interface to the
UserNotificationunion
- add the cause to
- Update
src/notifications/user-notification.mapper.ts:- add a switch case in
entityToNotification() - map entity columns and
additional_datainto the new typed payload - use non-null assertions only for columns guaranteed by the notifier
- add a switch case in
- Add or update
UserNotifierinsrc/notifications/user.notifier.ts:- insert
identity_idas the recipient - insert
additional_identity_idas the actor when there is one - fill
related_drop_id,related_drop_part_no,related_drop_2_id,related_drop_2_part_no, andwave_idconsistently - store only custom fields in
additional_data - pass
visibility_group_id - pass
connectionorctx.connectionwhen inside a transaction - skip self-notifications where the existing notification semantics do
- insert
- Wire the notifier call after the primary action succeeds. Decide deliberately whether notification failure should fail the parent operation.
- Update push notification behavior in
src/pushNotificationsHandler/identityPushNotifications.tswhen the cause should produce a push:- add a
CAUSE_TO_SETTING_KEYentry when users should be able to disable it with an existing or new setting - add a
generateNotificationData()switch case - add a focused handler that returns
{ title, body, data, imageUrl }or the skip sentinel when appropriate - use existing helpers such as
getDropSerialNo,getDropPart,getDrop, andgetWaveEntityOrThrow - handle deleted or missing related entities deliberately
- add a
- Update API notification mapping in
src/api-serverless/src/notifications/notifications.api.service.ts:- add related IDs in
getAllRelatedIds() - update
mapToApiNotificationV2WithoutRelatedWave()or related V2 helpers - update legacy
mapToApiNotification()if the V1 route still exposes the cause - keep
enums.resolveOrThrow(ApiNotificationCause, notificationCause)compatible with generated enum values
- add related IDs in
- Update
src/api-serverless/openapi.yaml:- add the cause to
ApiNotificationCause - add or update response fields only if the API shape changes
- run
cd src/api-serverless && npm run restructure-openapi && npm run generate
- add the cause to
- Add or update focused tests:
src/notifications/user-notification-mapper.test.tssrc/notifications/user.notifier.test.tssrc/pushNotificationsHandler/*push-notification*.test.tswhen push output changessrc/api-serverless/src/notifications/notifications-api-service.test.ts
- Run
npm run lintfrom the repo root.
Storage Fields
Prefer existing columns before adding schema:
identity_id: recipientadditional_identity_id: actor or related identityrelated_drop_idandrelated_drop_part_no: primary droprelated_drop_2_idandrelated_drop_2_part_no: secondary dropwave_id: wave contextvisibility_group_id: notification visibility restrictionadditional_data: custom JSON fields only
Common Patterns
- Identity action: recipient in
identity_id, actor inadditional_identity_id, no drop. - Drop action: recipient is the drop author, actor in
additional_identity_id, primary drop inrelated_drop_id, wave inwave_id. - Reply/quote action: new drop in
related_drop_id, original drop inrelated_drop_2_id. - Wave action: affected identities in
identity_id, actor inadditional_identity_id, wave inwave_id.
Validation
- Enum value added to
IdentityNotificationCauseinsrc/entities/IIdentityNotification.ts. - Data interface created in
src/notifications/user-notification.types.ts. - Notification interface created and added to
UserNotificationunion. - Mapper case added in
src/notifications/user-notification.mapper.ts. - Notifier method created in
src/notifications/user.notifier.ts. - Notifier wired up in trigger location.
- Push settings and handler updated in
src/pushNotificationsHandler/identityPushNotifications.tswhen push applies. -
getAllRelatedIds()case added in notifications API service. - V2 API mapping updated, and V1 mapping updated if still exposed.
- OpenAPI schema updated with new enum value.
- Types regenerated with
cd src/api-serverless && npm run restructure-openapi && npm run generate. - Tests cover mapper, notifier, push output, and API mapping as applicable.
-
npm run lintpasses.