Notifications (A09, G01–G05)
:::caution Registered in code — live after the owner's next deploy
The nine 008 routes (A09a/b, G01a–d, G02a/b, G05) are registered in
lib/routes.ts in the notify route-area stack
cse-http-be-<stage>-api-notify (Q27: shared HttpApi + authorizer).
G03 (POST /v1/notification-rules:preview) rides POST /v1/{collection}
in ApiStack (CR-2). All are routed (the area stack is created by a default cdk synth; the web team observed these routes answering on dev on 2026-10-28). Remaining gaps:
- the NotifyStack (recompute/reconcile and digest workers) is built but not
deployed, and exists only with
-c busEnabled=true. Where it exists, audiences beyond the first 25 users are queued to notify-recompute (Q36); without it they are recomputed synchronously after commit, in chunks of 25, so rule writes in very large orgs can be slow (Lambda timeout 25 s); if the timeout is exceeded the rule is saved but some audiences may stay stale until the next weekly reconcile once the NotifyStack is deployed; - the
notify.*.v1events (notify.user.v1,notify.audience.v1,notify.org-settings.v1) are written to the outbox on deploy but reach TCP only whenbusEnabledis on; - PUSH/EMAIL
availabilitycomes from SSM channel flags; unset meansUNAVAILABLE(Q37); - department/team recipients are not expanded from an org directory yet (Q38);
- the email consumer is off by default (SES sandbox).
Nothing here has been executed against any stage. All JSON is an
illustrative example, derived from the Zod schemas in
packages/core/src/schemas.ts (RegisterPushTokenInput, PushTokenView,
CreateNotificationRuleInput, UpdateNotificationRuleInput,
PreviewNotificationRuleInput, PutNotificationSettingsInput,
NotificationSettingsView) and specs/008-alerts-notifications/contracts/http-api.md.
:::
This service stores the who and how of notifications (push tokens,
rules, org settings) and publishes them to the TCP Server as projections.
The TCP Server detects alerts and sends push. The delivery log is
served by TCP over the WebSocket (get_notification_deliveries), not by
this API (G04 was removed). See Notifications architecture.
Common rules
| Aspect | Rule |
|---|---|
| Auth | Cognito JWT (Authorization: Bearer <idToken>) on every route |
| Org context | /v1/orgs/{orgId}/… — org from the path; caller needs an ACTIVE membership → else 403 FORBIDDEN. G03 needs X-Org-Id → 400 ORG_CONTEXT_REQUIRED |
| Level | alerts permission of the caller's role: VIEW to read, MANAGE to edit rules, FULL to edit settings |
| Bodies | Content-Type: application/json (else 415), ≤ 256 KB (else 413), strict (unknown field → 422 VALIDATION_FAILED) |
| Common errors | 400 MALFORMED_REQUEST, 400 VALIDATION_FAILED (unknown query param), 401, 403 FORBIDDEN / ACCOUNT_SUSPENDED, 429 RATE_LIMITED (+Retry-After), 503 DEPENDENCY_UNAVAILABLE, 500 INTERNAL |
| Concurrency | Responses carry ETag: "<version>"; mutations need If-Match → missing 428 PRECONDITION_REQUIRED, stale 409 VERSION_CONFLICT (details.currentVersion) |
A09a — POST /v1/me/push-tokens
Register the FCM token of this device (Android, iOS, web browser). Call it
after sign-in, on every token refresh, and (web) when desktop alerts are
enabled. Self only. Idempotency-Key optional; naturally idempotent on
(platform, token).
| Field | Type | Req | Validation |
|---|---|---|---|
platform | ANDROID | IOS | WEB | yes | enum |
token | string | yes | 16–4096 chars, ^[A-Za-z0-9:_\-.]+$; never logged or returned |
appId | string | no | ≤ 128, ^[A-Za-z0-9._-]+$ |
deviceLabel | string | no | trimmed, ≤ 64 |
appVersion | string | no | ≤ 32 |
Response 201 (new) or 200 (same user re-registered the token) —
illustrative example:
{ "tokenId": "q3Jk…43chars", "platform": "ANDROID", "deviceLabel": "Pixel 8",
"appVersion": "1.4.0", "createdAt": "2026-09-28T10:00:00.000Z",
"lastSeenAt": "2026-09-28T10:00:00.000Z" }
| Status | Code | When |
|---|---|---|
| 201 / 200 | — | created / refreshed |
| 422 | VALIDATION_FAILED | schema failure |
| 422 | IDEMPOTENCY_KEY_REUSED | same key, different body |
| 409 | IDEMPOTENCY_IN_PROGRESS | same key in flight |
| 429 | RATE_LIMITED | more than 20 new registrations by this user in the current UTC day (Retry-After = seconds to 00:00 UTC) |
Rate limit (WP-7, committed 2026-11-06, not deployed). Only a token the
user does not already hold counts. Re-posting a registered token (the 200
case: page load, token refresh) never counts. The limit is per user, in a
fixed UTC-day window that resets at 00:00 UTC. It is not a rolling 24 hours.
Before this change every call counted, re-posts included.
Push is for End Users only, on every platform (ADR 0025,
which generalises WP-3 / ADR 0022). A token of any platform (ANDROID, IOS, WEB) is
accepted from anyone with the same 201/200. It is sent to the TCP Server only while
every active membership the person holds is an End User membership, which means one of:
- the End User role;
- a Customer org;
- their personal org.
A staff user's tokens (Super Admin, Administrator, Business, Installer) are
stored but not used for alerts or other pushes. The person's notify.user.v1
carries pushEligible: false, so the TCP Server also skips the tokens the app
registered with it directly. The tokens are used for everything again if the
person later holds End User memberships only.
Exception: membership notices (ADR 0031, 2026-11-26). Since
ADR 0031 a staff user's endpoints are sent to the TCP Server too. The only pushes
they can receive are JOIN_REQUEST_RECEIVED, INVITATION_RECEIVED and ADDED_TO_BUSINESS.
Edge cases: a token already held by another user moves to the caller; an 11th token evicts the least recently seen one (max 10 per user). Registration works even when the Push channel is unavailable.
A09b — DELETE /v1/me/push-tokens/{tokenId}
Sign-out on this device. tokenId is 43-char base64url → else
422 VALIDATION_FAILED. Always 204: absent token, deleted token, and a
token owned by someone else (nothing changes — non-disclosure).
G01a — GET /v1/orgs/{orgId}/notification-rules
alerts ≥ VIEW. No pagination (≤ 50 rules by construction); any query
param → 400. The system rule ("Critical alerts — all plants") is seeded
on first read. Response 200 — illustrative example:
{
"items": [
{ "ruleId": "00000000000000000000000000", "name": "Critical alerts — all plants",
"severity": "CRITICAL", "categories": [], "scope": { "kind": "ALL", "targetIds": [] },
"recipients": [{ "kind": "ALERT_MANAGERS" }], "schedule": { "kind": "ANY_TIME" },
"channels": ["PUSH", "EMAIL"], "notifyOn": ["RAISED"], "enabled": true, "system": true,
"lockedFields": ["name", "severity", "scope", "schedule", "enabled"], "version": 1,
"createdAt": "2026-09-28T10:00:00.000Z", "updatedAt": "2026-09-28T10:00:00.000Z" }
],
"summary": { "count": 1, "activeCount": 1 },
"viewer": { "capabilities": ["notificationRules.view"] }
}
viewer.capabilities includes notificationRules.edit when the caller's
alerts level is ≥ MANAGE — use it to show the edit controls. A label whose
target no longer exists is omitted and the entry gets stale: true.
G01b — POST /v1/orgs/{orgId}/notification-rules
alerts ≥ MANAGE. Idempotency-Key required (428 PRECONDITION_REQUIRED).
60 rule writes / org / hour. Body CreateNotificationRuleInput: name?,
severity, categories?, scope, recipients, schedule, channels,
notifyOn?, enabled?. Response 201 with the rule, ETag: "1" and
Location.
scope.targetIds: none for ALL; for PLANT_TYPE, 1–3 unique values from RESIDENTIAL, COMMERCIAL, INDUSTRIAL (owner decision Q1); every other kind 1–50 ids in this org. Out of range or an unknown plant type → 422 VALIDATION_FAILED.
| Status | Code | When |
|---|---|---|
| 201 | — | created (replay: original 201 + Idempotent-Replayed: true) |
| 422 | VALIDATION_FAILED | schema; scope/recipient target missing or in another org |
| 422 | UNSUPPORTED_OPERATION | channel SMS/WHATSAPP (details.reason: CHANNEL_PLANNED) |
| 422 | LIMIT_EXCEEDED | 50 rules (details.limit: 50) |
| 428 | PRECONDITION_REQUIRED | no Idempotency-Key |
| 422 | IDEMPOTENCY_KEY_REUSED | same key, different body |
| 409 | IDEMPOTENCY_IN_PROGRESS | same key in flight |
| 429 | RATE_LIMITED | > 60 rule writes / org / hour (shared by POST, PATCH, DELETE) |
| 403 | FORBIDDEN | alerts < MANAGE |
G01c — PATCH /v1/orgs/{orgId}/notification-rules/{ruleId}
alerts ≥ MANAGE, If-Match required, JSON merge with at least one field;
null is rejected. Response 200 + ETag.
| Status | Code | When |
|---|---|---|
| 404 | NOT_FOUND | rule not in this org, or ruleId not a ULID |
| 428 | PRECONDITION_REQUIRED | no If-Match |
| 409 | VERSION_CONFLICT | stale version |
| 422 | UNSUPPORTED_OPERATION | system rule locked field (SYSTEM_RULE_LOCKED, details.fields); planned channel |
| 422 | VALIDATION_FAILED | schema; empty recipients/channels; digest schedule without EMAIL |
| 429 | RATE_LIMITED | shared 60 rule writes / org / hour |
G01d — DELETE /v1/orgs/{orgId}/notification-rules/{ruleId}
alerts ≥ MANAGE, If-Match required. 204. Already deleted → 404;
system rule → 422 UNSUPPORTED_OPERATION; non-ULID ruleId → 404;
plus 428, 409, 429 RATE_LIMITED (shared 60 / org / hour).
G02a — GET /v1/orgs/{orgId}/notification-settings[?include=rules]
alerts ≥ VIEW. include=rules adds the G01a items. No stored settings →
defaults with version: 0. An include value other than rules →
400 VALIDATION_FAILED. Response 200 + ETag — illustrative example:
{
"orgId": "01J9Z1…", "timezone": "Asia/Karachi", "version": 4,
"channels": [
{ "channel": "PUSH", "enabled": true, "availability": "ACTIVE" },
{ "channel": "EMAIL", "enabled": true, "availability": "UNAVAILABLE",
"unavailableReason": "EMAIL_PROVIDER_NOT_READY" },
{ "channel": "SMS", "enabled": false, "availability": "PLANNED" },
{ "channel": "WHATSAPP", "enabled": false, "availability": "PLANNED" }
],
"grouping": { "enabled": true, "windowMinutes": 60 },
"digest": { "enabled": true, "time": "08:00", "weeklyDay": "MON" },
"quietHours": { "enabled": false, "start": "22:00", "end": "07:00" },
"workingHours": { "start": "09:00", "end": "18:00", "days": ["MON","TUE","WED","THU","FRI","SAT"] },
"workOrderAssignment": { "inApp": true, "push": true, "audience": "ASSIGNEE", "timing": "IMMEDIATE" },
"rulesSummary": { "count": 5, "activeCount": 4 },
"viewer": { "capabilities": ["notificationSettings.view", "notificationRules.view"] },
"updatedAt": "2026-09-28T10:00:00.000Z"
}
viewer.capabilities ⊆ notificationSettings.view,
notificationSettings.edit (alerts = FULL), notificationRules.view,
notificationRules.edit (≥ MANAGE), notificationDeliveries.view
(≥ MANAGE; a UI hint — the log itself comes from TCP).
Availability comes from SSM flags: PUSH is ACTIVE only while
/cse-tcp-be/<stage>/notify/push-enabled is true, EMAIL only while
/cse-http-be/<stage>/notify/email-enabled is true. An unset flag means
UNAVAILABLE (PUSH_SENDER_NOT_READY / EMAIL_PROVIDER_NOT_READY).
Work order assignment (workOrderAssignment, issue #14 BP-3, committed 2026-11-13, not deployed): the
"Work order assignment" default row. When a work order is assigned or reassigned, the assignee always gets the
in-app inbox item (WORK_ORDER_ASSIGNED). push (default true) decides whether that
item is also sent as a web push. inApp: true, audience: "ASSIGNEE" and
timing: "IMMEDIATE" are fixed. Settings saved before this field existed read as push: true. It affects only the
WORK_ORDER_ASSIGNED push; every other inbox kind is unchanged. A monthly customer summary default is not built
(there is no backend source for it).
G02b — PUT /v1/orgs/{orgId}/notification-settings
alerts = FULL. If-Match required ("0" for the first write). Full
replace: channels (all four keys, each { enabled }), grouping,
digest, quietHours, workingHours, and optionally
workOrderAssignment: { push: boolean } (issue #14). If
workOrderAssignment is left out, the stored value is kept, so older
clients keep working. Computed fields are rejected (send only push, not
inApp, audience or timing).
Response 200 (G02a shape without rules).
| Status | Code | When |
|---|---|---|
| 422 | UNSUPPORTED_OPERATION | enabling SMS/WHATSAPP (CHANNEL_PLANNED); disabling both PUSH and EMAIL (LAST_CRITICAL_CHANNEL) |
| 422 | VALIDATION_FAILED | ranges/formats; quietHours.start == end; workingHours.start >= end |
| 428 | PRECONDITION_REQUIRED | no If-Match |
| 409 | VERSION_CONFLICT | stale |
| 403 | FORBIDDEN | alerts < FULL |
A digest-time change applies to digests scheduled after the change.
G03 — POST /v1/notification-rules:preview
alerts ≥ MANAGE in the X-Org-Id org. No side effects. 60 / user / min.
Body { "rule": CreateNotificationRuleInput, "ruleId"?: ULID } (ruleId
when previewing an edit). Response 200 — illustrative example:
{
"summary": "Warning alerts · Region: Sindh → Operations Manager · Working hours (09:00–18:00) · Push",
"parts": { "severity": "Warning alerts", "scope": "Region: Sindh", "recipients": "Operations Manager",
"when": "Working hours (09:00–18:00)", "channels": "Push" },
"plantCount": { "value": 312, "approximate": true },
"recipientCount": 6,
"recipientSample": [{ "sub": "…", "name": "Bilal Ahmed" }],
"warnings": [{ "code": "CHANNEL_UNAVAILABLE", "channel": "EMAIL" }]
}
warnings[].code ∈ CHANNEL_UNAVAILABLE, CHANNEL_DISABLED_FOR_ORG,
NO_RECIPIENT_WITH_ACCESS, DUPLICATE_RULE, COVERED_BY_SYSTEM_RULE,
SCOPE_EMPTY. Errors: 400 ORG_CONTEXT_REQUIRED, 422 VALIDATION_FAILED,
422 UNSUPPORTED_OPERATION, 403 FORBIDDEN.
G04 — delivery log (served by TCP)
Not an HTTP route. The TCP Server serves it over the WebSocket as
get_notification_deliveries. It needs only a verified (signed-in) caller and
returns that caller's own deliveries; no alerts level is checked (confirmed
by the TCP Server, 2026-10-29). See the TCP Server docs.
HTTP in-app inbox (T-12)
:::caution Routed on dev, not captured signed in
GET /v1/me/notifications and POST /v1/me/notifications:mark-read are committed (867d62d, 2026-10-29). The
web team observed GET /v1/me/notifications answering 401 without a token on dev on 2026-11-02, so it is
routed there. No signed-in response has been captured yet. Every JSON block below is an illustrative example
derived from the Zod schemas (InboxListView, InboxNotificationView, MarkNotificationsReadInput in
packages/core/src/schemas.ts) and packages/api/src/handlers/me-notifications.ts, not a captured response.
:::
Two inboxes, agreed with the TCP Server. Each server keeps its own inbox. The TCP Server keeps device-alert
items; this server keeps items for HTTP-owned events. The web console shows both, and its unread badge is the TCP
device-alert unread count plus this server's unreadCount.
Producers. Items are planned in packages/core/src/inbox/producers.ts. The stream-router writes them, and
work-order items are also written on the request path (below). One item goes to one known user, never to the
actor about their own action:
kind | Recipient | link.type |
|---|---|---|
WORK_ORDER_ASSIGNED | The newly assigned technician | WORK_ORDER |
WORK_ORDER_STATUS | The work order's creator (user) | WORK_ORDER |
ACCESS_REQUEST_DECIDED | The requester | ACCESS_REQUEST |
SHARE_GRANTED | A user grantee of a share | SHARE |
REPORT_READY | The user who created the report | REPORT |
WORK_ORDER_UNASSIGNED | The previous technician, on reassign or unassign (WO-10, 2026-11-04) | WORK_ORDER |
WORK_ORDER_ACCEPTED / WORK_ORDER_DECLINED | The Business user who made the assignment (assignedBy) and the order's creator | WORK_ORDER |
WORK_ORDER_COMPLETED | The same Business users; replaces the creator's WORK_ORDER_STATUS item for that transition | WORK_ORDER |
WORK_ORDER_STARTED | The Business users (assignedBy and the creator), when the Installer starts an accepted order (ADR 0023) | WORK_ORDER |
WORK_ORDER_PROGRESS | The Business users, when the assigned Installer adds a note; at most one per order per recipient per hour (the id embeds the hour) (ADR 0023) | WORK_ORDER |
WORK_ORDER_HOLD_REQUESTED | The Business users, when the Installer asks for a hold (ADR 0023) | WORK_ORDER |
WORK_ORDER_VERIFIED | The Business users, when the order is verified (ADR 0023) | WORK_ORDER |
WORK_ORDER_COMPLETION_REJECTED | The Installer, when the Business sends the completion back (ADR 0023) | WORK_ORDER |
WORK_ORDER_ON_HOLD / WORK_ORDER_RESUMED | The Installer and the Business users, on hold and resume (ADR 0023) | WORK_ORDER |
WORK_ORDER_CLOSED / WORK_ORDER_CANCELLED | The Installer and the Business users, on close and cancel (ADR 0023) | WORK_ORDER |
SERVICE_REQUEST_SUBMITTED / SERVICE_REQUEST_DECIDED | No longer produced (ADR 0023 D12 retired service requests). Older items stay readable until they expire | SERVICE_REQUEST |
INVITATION_RECEIVED | The invitee, when an INTERNAL/DELEGATED invitation to their verified email is created or renewed (2026-11-23, console R1). Carries an extra invitation object. See Invitation notification | INVITATION (no orgId) |
JOIN_REQUEST_RECEIVED | The Business members who can decide it (team ≥ MANAGE, at most 20, never the requester), when an Installer's POST /v1/me/join-requests succeeds (ADR 0031, 2026-11-26) | JOIN_REQUEST (with orgId) |
ADDED_TO_BUSINESS | An End User a plant transfer added straight into a Business as a member, never the actor (ADR 0031, 2026-11-26) | ORG (id = orgId) |
PLANT_SHARE_REQUESTED | 2026-11-27 (ADR 0032): an independent End User asked to share a plant. To the Business's active members with team ≥ MANAGE (at most 20), never the actor | PLANT_SHARE (id = shareId, orgId = the Business) |
PLANT_SHARE_ACCEPTED / PLANT_SHARE_DECLINED | ADR 0032: to the End User when the Business answers | PLANT_SHARE |
PLANT_SHARE_REVOKED | ADR 0032: an active share ended. To the other side (the End User, or the Business's team ≥ MANAGE members) | PLANT_SHARE |
The six kinds added on 2026-11-04/05 (ADR 0019) are deployed on dev. The
nine kinds added by ADR 0023 (work-order lifecycle v2, 2026-11-10) are built
but not deployed; until the next deploy, dev still produces the
service-request kinds. "The Business users" are the user who made the current
assignment and the order's creator. The creator's generic WORK_ORDER_STATUS
item is not sent when one of the specific items already reaches them. Crown
staff are not notified about every Business's orders; they use the activity
history and the Crown-wide work-order list. Details:
work-order notifications.
The work-order items are written on the request path right after the change (best-effort). They therefore arrive even without the stream-router. The ids are deterministic, so a later stream delivery of the same change is a no-op.
INVITATION_RECEIVED (built and deployed to dev 2026-11-23) is also written on the request
path: after an INTERNAL/DELEGATED invitation is created or renewed, the handler resolves the invited address to
the one account with that email verified (one Cognito ListUsers) and writes the item. No account → no item;
the person sees the invitation in GET /v1/me/invitations after sign-up and verification. The item is marked
read when the invitation is accepted, declined, revoked or renewed, and its TTL is the invitation's expiry. Full
rules: Invitation notification.
:::note Needs the stream-router
The producers run in the stream-router, which exists only when the stage is deployed with busEnabled on. It is
deployed on dev, the only stage: the bus has been on since 2026-11-19, and the cse-http-be-dev-integration
stack was re-verified UPDATE_COMPLETE on 2026-11-23. On a stage without the stream-router, the list
holds only the work-order items (and, until ADR 0023 is deployed, the service-request items) that are written on
the request path. ACCESS_REQUEST_DECIDED, SHARE_GRANTED and REPORT_READY still need the stream-router. See
KI-43.
:::
Web push for inbox items (WP-4 / WP-6, committed 2026-11-06, not deployed).
When an item of the kinds below is created, the same DynamoDB transaction writes
one notify.push.requested.v1 for the TCP Server to send. The item is therefore
always in this inbox before the push goes out. A duplicate delivery of the same
change creates nothing and sends nothing. The push goes to web endpoints
only (platforms: ["WEB"]), so the mobile app gets no new notifications.
Only End Users have endpoints in the TCP Server's copy (pushEligible, see A09a
above), so staff recipients get no push either.
kind | Push link | tag |
|---|---|---|
WORK_ORDER_ASSIGNED, WORK_ORDER_STATUS, WORK_ORDER_UNASSIGNED, WORK_ORDER_ACCEPTED, WORK_ORDER_DECLINED, WORK_ORDER_COMPLETED, and the nine ADR 0023 kinds (WORK_ORDER_STARTED, WORK_ORDER_PROGRESS, WORK_ORDER_COMPLETION_REJECTED, WORK_ORDER_VERIFIED, WORK_ORDER_CLOSED, WORK_ORDER_CANCELLED, WORK_ORDER_ON_HOLD, WORK_ORDER_RESUMED, WORK_ORDER_HOLD_REQUESTED) | /service?order=<workOrderId> | wo-<workOrderId> |
REPORT_READY | /reports | report-<reportId> |
INVITATION_RECEIVED | / (confirmed by the console team 2026-11-23: the header bell lists invitations on every page) | invite-<inviteId> |
JOIN_REQUEST_RECEIVED (ADR 0031) | / | joinreq-<requestId> |
ADDED_TO_BUSINESS (ADR 0031) | / | joined-<orgId> |
PLANT_SHARE_REQUESTED, PLANT_SHARE_ACCEPTED, PLANT_SHARE_DECLINED, PLANT_SHARE_REVOKED (ADR 0032) | / | pshare-<shareId> (data.shareId, data.orgId) |
INVITATION_RECEIVED, JOIN_REQUEST_RECEIVED and ADDED_TO_BUSINESS are the exception to "web only" and
"End Users only". See Membership notices.
The four PLANT_SHARE_* kinds (ADR 0032, 2026-11-27) are pushed to Android, iOS and web, but only to End Users
(ADR 0025 eligibility applies, no exception). The End User gets accepted, declined and revoked on their phone. Business
staff get the inbox item only. See the
share a plant with a business guide.
Push title and body are the item's title and body. With no body the push
says "Open the console for details.". data carries type (the kind),
notificationId, tag, workOrderId, reportId, inviteId or requestId, and orgId when known (never for INVITATION_RECEIVED).
ACCESS_REQUEST_DECIDED, SHARE_GRANTED and the (retired) service-request kinds are
not pushed: the console team has not given a path for them yet. Sending needs
the TCP Server's web push sender, which is not running yet (KI-48).
REPORT_READY cannot happen until a report renderer exists (KI-41).
Storage and retention. One item USER#<sub>/NOTIF#<ulid> per notification, deleted by DynamoDB TTL 90 days
after createdAt, or at the invitation's expiry for INVITATION_RECEIVED (expired items are also filtered out of reads). The unread counter USER#<sub>/NOTIFCOUNT goes
+1 with each new item (same transaction) and −n on mark-read (never below 0). Item ids are derived from the
source event, so a redelivered stream record creates nothing new.
GET /v1/me/notifications
Signed-in user, own items only. No org level; X-Org-Id is optional, but if sent it must be an org you can
select. Rate-limit family me-settings.
| Query | Rule |
|---|---|
limit | 1–50; default 15 on the first page, 10 with a cursor (lazy loading) |
cursor | Opaque nextCursor from the previous page; an invalid one is 400 INVALID_CURSOR |
unreadOnly | true or false (default false) |
| anything else | 400 VALIDATION_FAILED |
Newest first. A page may hold fewer than limit items when many are read or expired (at most 5 DynamoDB queries
per page); keep following nextCursor until it is absent. unreadCount is maintained incrementally, so it may briefly over-count after unread items expire (TTL); a
mark-all resets it, and a list that reads the whole partition also repairs it. Clients must tolerate unknown
kind and link.type values (the enums are additive).
{
"items": [
{
"notificationId": "01JBZ0000000000000000000N1",
"kind": "WORK_ORDER_ASSIGNED",
"title": "Work order assigned to you",
"body": "WO-0042 at Lahore Rooftop",
"link": { "type": "WORK_ORDER", "id": "01JBZ0000000000000000000W1", "orgId": "01JBZ0000000000000000000O1" },
"actor": { "displayName": "Ayesha Khan" },
"createdAt": "2026-10-29T08:00:00.000Z"
}
],
"unreadCount": 1,
"nextCursor": "eyJ…"
}
Fields: title ≤ 160 chars, body ≤ 500 (optional), actor optional, readAt present once read. link
carries ids only; opening the target goes through that target's own route and its own authorization, so a link
the user can no longer open returns that route's 403/404.
POST /v1/me/notifications:mark-read
Body {"ids": ["<ulid>", …]} (1–100 ULIDs) marks those items read. No body (or {}) marks all unread items
read. Each call marks at most 500 items (5 pages of 100) and still returns 204; if more remain, call it again.
After a mark-all the counter is recounted from the live unread items, without losing an item created meanwhile. "ids": [] is rejected (422 VALIDATION_FAILED). Unknown, foreign or already-read ids are skipped
silently. Idempotent; no Idempotency-Key. 204 No Content on success. Rate-limited to 120 calls per hour per user:
over the limit it returns 429 RATE_LIMITED with Retry-After.
{ "ids": ["01JBZ0000000000000000000N1"] }
Errors for both routes: 400 VALIDATION_FAILED (unknown query parameter), 401, 403 FORBIDDEN (X-Org-Id
not selectable), 415/422 on a bad body, 429 RATE_LIMITED, 503 DEPENDENCY_UNAVAILABLE.
G05 — GET /v1/alerts/{alertId}/work-orders
Implemented in packages/api/src/handlers/list-alert-work-orders.ts,
registered in cse-http-be-<stage>-api-notify (live after the owner's next deploy). Work-order strip in the alert drawer. Signed in, no org
context. Each row is kept only if the caller has service ≥ VIEW on its
plant. At most 20 rows, newest first, no cursor.
| Field | Notes |
|---|---|
workOrderId, code, plantId, status, priority, createdAt | always present |
assignee | optional; { sub?, name } — sub is omitted for customer-portal-only callers |
dueAt | optional; equals the work order's responseTargetAt |
Response 200 — illustrative example:
{ "items": [{ "workOrderId": "01J…", "code": "WO-2026-0498", "plantId": "01J…",
"status": "ASSIGNED", "priority": "HIGH", "assignee": { "sub": "…", "name": "Hina Rauf" },
"dueAt": "…", "createdAt": "…" }] }
| Status | Code | When |
|---|---|---|
| 200 | — | rows (possibly empty). Unknown alert, invisible rows, or links whose work order or plant is gone → dropped / { "items": [] } (never 404/403) |
| 400 | VALIDATION_FAILED | any query parameter |
| 422 | VALIDATION_FAILED | alertId not ^[A-Za-z0-9_-]{1,64}$ |
| 401 / 403 | common | not signed in; ACCOUNT_SUSPENDED |
Membership notices (ADR 0031)
Built 2026-11-26, not committed, not deployed. Fixes the bug "a Business sees an Installer's join request only after a refresh, and gets no push". The owner named three exceptions to the End-Users-only push rule. There are no others:
| Who is told | When | Kind |
|---|---|---|
The Business: ACTIVE members with effective team ≥ MANAGE, at most 20, never the requester | An Installer sends a join request with the join code (POST /v1/me/join-requests) | JOIN_REQUEST_RECEIVED |
| The Installer | A Business invites them (in-app invitation) | INVITATION_RECEIVED |
| The End User | A Business invites them (INVITATION_RECEIVED), or a plant transfer adds them straight into the Business (ADDED_TO_BUSINESS) | INVITATION_RECEIVED, ADDED_TO_BUSINESS |
- Inbox item first. Each item is written on the request path right after the join request, invitation or transfer commits. It is best-effort: a failure is logged and the original call still succeeds. Ids are deterministic, so a retry does not notify twice.
- Push on every platform. These kinds write
notify.push.requested.v1withplatforms: ["ANDROID","IOS","WEB"]andeligibilityExempt: true. The TCP Server sends them even when the person'spushEligibleisfalse. The person's own push toggle and quiet hours still apply. - No refresh needed (Flutter). The push
datacarriestype(the kind),orgIdand, for a join request,requestId. On a push withdata.type = JOIN_REQUEST_RECEIVED, foreground included, the app reloadsGET /v1/orgs/{orgId}/join-requests. OnINVITATION_RECEIVEDit reloadsGET /v1/me/invitations. OnADDED_TO_BUSINESSit reloadsGET /v1/me/context. The item is also inGET /v1/me/notifications, andunreadCountgoes up. - Open dependency (TCP Server). The TCP Server must honour
eligibilityExempt. Until it does, staff recipients (the Business for a join request, an Installer for an invitation) get the inbox item but no push. End Users already get theirs. - Not done: a Business's
JOIN_REQUEST_RECEIVEDitems stay unread after the request is accepted, rejected or cancelled. They expire after 90 days.
Illustrative example, derived from packages/core/src/inbox/push.ts. It is not a captured execution.
{
"requestId": "inbox-<notificationId>",
"userSub": "<business-member-sub>",
"title": "Ali Installer asked to join your business",
"body": "Open Requests to accept or reject.",
"link": "/",
"tag": "joinreq-<requestId>",
"platforms": ["ANDROID", "IOS", "WEB"],
"eligibilityExempt": true,
"data": { "type": "JOIN_REQUEST_RECEIVED", "notificationId": "<notificationId>", "requestId": "<requestId>", "orgId": "<orgId>", "tag": "joinreq-<requestId>" }
}
Push: End Users only and the push toggle (ADR 0025)
Committed to the working tree 2026-11-13. Not deployed, and not exercised against any stage. This generalises ADR 0022 (below) from web push to every platform.
- Who gets push: End Users only (rule under A09a). Super Admin, Administrator, Business and Installer never get push, on any platform, even if they are also an End User elsewhere.
notify.user.v1gainspushEligible: boolean. It is always sent by this server. Consumers treat a missing value (older events) astrue. When it isfalse, the event has no endpoints, and the TCP Server must also skip the tokens it holds itself. The flag is in the content hash, so an eligibility change alone republishes the event.- Push toggle:
PATCH /v1/me/preferencesnotifications.channels.push(Account settings).false(pushEnabled: falsein the event) means no push at all, CRITICAL included. The CRITICAL override falls back to email, then toNO_CHANNEL. A notifications change republishesnotify.user.v1in the same transaction as the save. - When eligibility changes: member suspend, restore or remove, a role or
scope change, a bulk scope change and an invitation accept all republish
the person's
notify.user.v1, whether or not they hold an HTTP token. It goes in the same transaction for up to 25 people, otherwise right after the commit. Rule, share, technician-team and role-permission changes skip this, because they cannot change eligibility. - Coverage: an End User who never registered a token here, never changed
preferences and never had a membership change has no
notify.user.v1. The TCP Server treats such a user as eligible. The reconciliation gives a firstnotify.user.v1to every member of a Platform, Business or Installer org that has none, so after one completed run every staff member is covered withpushEligible: false. - Delivery-policy reason: a new
NOT_ELIGIBLEreason marks a push suppressed for a staff member (contract §C2, conformance vectors).
Web push (ADR 0022)
Browser notifications for the web console, sent by the TCP Server through FCM
(Firebase project crown-solar-energy-dev on dev; dev is the only stage).
Committed 2026-11-06, not deployed, and nothing has been sent yet. This
server's part:
- Who: End Users only, decided per person (see A09a). A person with any active staff membership gets no web push, even if they are also an End User elsewhere.
- When it stops: a membership or role change republishes the person's
notify.user.v1in the same transaction (≤ 25 users) or right after the commit. Since ADR 0025 this applies to every platform (see above). Their endpoints disappear from the TCP Server's copy within seconds of the bus delivering it, inside the console's 2-minute bound. The weekly reconciliation repairs any miss. - What: alert pushes come from the TCP Server (its docs). HTTP-owned pushes are the inbox kinds listed under HTTP in-app inbox.
- Dead tokens: when the TCP Server reports
notify.endpoint.invalid.v1, this server deletes the token. That part is already built. - Quota: see the rate-limit note under A09a.
The TCP Server's half is listed in KI-48.