# D4c Portal Notification Delivery Diagnostics

- Date: 2026-07-22
- Owner: frontend (`axis-iam-web` session, Portal repo only)
- Status: Coordinator accepted and merged
- Implementation State: IMPLEMENTED
- Validation Evidence: E2E_PASS
- Priority: P1
- Task type: feature
- Backend prerequisite: D4b backend `a7b43a43`, closeout `726a98f2`
- Contract authority: `axis-iam/docs/tasks/2026-07-21-notification-delivery-diagnostics-contract-backend.md`
- Backend implementation record: `axis-iam/docs/tasks/2026-07-21-notification-delivery-diagnostics-read-resource-backend.md`

## Branch Policy

- Session root: `workspace/iam-project/iam-java/axis-iam-web`
- Target git repo: `iam-portal-web`
- Required branch: `feature/portal-notification-delivery-diagnostics-frontend`
- Base: clean local Portal `main` containing this task document and D4a closeout `3158133` or later.
- Use the normal Portal checkout. Do not create a second Portal/Admin session or modify `iam-admin-web`.
- The implementation session must not commit, merge, push, reset, stash, or publish.

Preflight:

```bash
cd /home/chaos/code/workspace/iam-project/iam-java/axis-iam-web
git -C iam-portal-web status --short
git -C iam-portal-web branch --show-current
git -C iam-portal-web rev-parse --short HEAD
git -C iam-admin-web status --short
git -C iam-portal-web switch main
git -C iam-portal-web switch -c feature/portal-notification-delivery-diagnostics-frontend
```

If the branch exists, switch to it after proving its base. Stop on unexpected dirty files; do not absorb or undo
another task's changes.

## User-Provided Inputs / External Access Gate

No external provider account, production database, customer credential, DNS, or public callback is required.
Final E2E requires task-owned PostgreSQL 17/Redis, current backend `main`, a generated D4b cursor keyring, real Portal
login/membership, and a real Organization invitation delivery created through supported HTTP commands. If Docker or
the backend runtime is unavailable, record `IMPLEMENTED + BLOCKED`; mocks cannot substitute for E2E.

## Background

D4b exposes a deliberately narrow, redacted, read-only Portal resource for Organization invitation delivery state.
It does not restore the removed Notification Logs product surface and does not expose Server authentication mail,
Admin Workspace invitation mail, D3b Magic Link/OTP/registration traffic, recipient data, message content, provider
errors, or command controls. D4c adds the user-facing Portal view for this accepted contract.

## User-Visible Behavior

An authenticated Portal member viewing an Application can open **Delivery diagnostics**, filter Organization
invitation deliveries by status and date, page with an opaque cursor, and inspect one delivery's ten redacted fields.
The view is available to the same live Workspace membership roles accepted by the backend. It contains no resend,
retry, replay, cancel, acknowledgement, recipient, token, body, subject, provider, or attempt-log surface.

## Exact API Contract

```text
GET /portal/v1/apps/{appId}/notification-deliveries
GET /portal/v1/apps/{appId}/notification-deliveries/{deliveryId}
```

List query members are only `cursor`, `limit`, `status`, `createdFrom`, and `createdTo`. Default limit is 20 and the
valid range is 1..100. The response is cursor-only; never invent page numbers, totals, offset pagination, client-side
sorting, or fallback queries.

```ts
type NotificationDeliveryStatus =
  | 'REQUESTED'
  | 'ACCEPTED'
  | 'DELIVERED'
  | 'FAILED'
  | 'CANCELLED'
  | 'DEAD_LETTER'

interface NotificationDeliveryResponse {
  deliveryId: string
  channel: 'EMAIL'
  purpose: 'ORG_INVITATION'
  status: NotificationDeliveryStatus
  attemptCount: number
  nextAttemptAt: string | null
  createdAt: string
  acceptedAt: string | null
  deliveredAt: string | null
  terminalAt: string | null
}

interface NotificationDeliveryListResponse {
  items: NotificationDeliveryResponse[]
  nextCursor: string | null
}
```

Parse this contract strictly at the API boundary. Require canonical UUIDs, known enums, non-negative integer counts,
valid UTC instants, exact required fields, nullable fields exactly where specified, and no duplicate delivery IDs.
Unknown, missing, malformed, or inconsistent values must enter an explicit query error state; do not coerce them into
empty data or guessed statuses. Treat cursors as opaque strings and never decode, persist, log, or expose them.

## Product Surface

- Add routes:
  - `/apps/:appId/settings/notification-deliveries`
  - `/apps/:appId/settings/notification-deliveries/:deliveryId`
- Add one Application Settings navigation item labelled `Delivery diagnostics` with localized English/Chinese text.
- Do not restore the retired `/apps/:appId/settings/notifications` route, `Notification Logs` label, or old endpoint.
- Use an unframed, dense table/list suitable for an operational console and a focused detail view.
- Include status/date filters, clear/reset, cursor next/previous navigation using an in-memory cursor stack, loading,
  empty, error and refetch states. Filters and Application changes reset the cursor stack.
- Render all non-null timestamps with localized text and semantic `<time dateTime>` values. Keep field labels compact.
- Detail/list navigation must preserve Application context. Switching Applications clears prior rows, cursors, detail,
  and errors before issuing the new request.
- `400 INVALID_CURSOR` or invalid query: explicit message and a user-controlled reset to first page.
- `404`: non-disclosing unavailable/not found state.
- `503`: explicit temporary-unavailable state with read refetch only; never expose a delivery retry command.

## Non-Goals

- No backend, Admin, SDK, Socratiq, migration, release, or deployment changes.
- No mutation endpoint or reuse of D2 Webhook retry/cancel controls.
- No restoration of Notification Logs, `/delivery-logs`, or old MSW product models.
- No browser `client_credentials`, M2M token, secret, confidential API, direct database fixture, or synthetic success.
- No `any`, speculative DTO defaults, broad catches, silent empty success, decoded cursor state, or effect-driven fetch.
- No presentation of recipient/email/phone, token/code/link, subject/body, sealed material, provider response/error,
  correlation/internal owner IDs, raw exception text, or D3b purpose.

## Implementation Scope

- Add strict types/parser, query keys, TanStack Query hooks and dedicated route components.
- Keep notification hooks separate from Webhook delivery hooks because pagination and command contracts differ.
- Add English/Chinese catalog entries and nav/breadcrumb labels.
- Update MSW only for unit/component tests; MSW must not become a development/runtime fallback.
- Add focused route/nav/parser/hook/page tests and a reproducible real-stack Playwright specification.
- Update this Execution Record and `docs/PROJECT_TASKS.md`; do not create prompt files.

Likely files:

- `src/api/types.ts`
- `src/api/queryKeys.ts`
- `src/api/hooks/use-notification-deliveries.ts`
- `src/router.tsx`
- `src/components/layout/nav-config.ts`
- `src/routes/settings/notification-deliveries/**`
- `src/i18n/locales/{en,zh}/**`
- `src/test/api-handlers-domains/**`
- `tests/browser/portal-notification-delivery-diagnostics.desktop.spec.ts`

## Validation Harness

Declare exact test files and the E2E fixture lifecycle before production edits. At minimum run:

```bash
pnpm typecheck
pnpm lint
pnpm test -- --run \
  src/api/hooks/use-notification-deliveries.test.tsx \
  src/routes/settings/notification-deliveries/NotificationDeliveriesPage.test.tsx \
  src/routes/settings/notification-deliveries/NotificationDeliveryDetailPage.test.tsx \
  src/components/layout/nav-config.test.ts \
  src/router.test.tsx
pnpm test
pnpm build
pnpm playwright test --config=playwright.config.ts --grep "notification delivery diagnostics"
git diff --check
```

The real browser harness must use current backend `main`, random/task-owned ports and data, create the Application,
Workspace membership, Organization and invitation through supported APIs, process the durable delivery through the
real worker path, then prove desktop 1440x900 and mobile 390x844 behavior. It must assert list/detail requests, cursor
pagination, filters, Application isolation, unknown/foreign 404, malformed/expired cursor handling, 503/refetch,
empty state, bilingual rendering, no commands, no old notification/Webhook endpoints, no confidential browser
requests, no sensitive DOM/storage/log data, no console/page errors, and no page-level overflow.

Cleanup must remove task Applications, users/memberships, invitations/deliveries where supported, Redis keys,
containers, ports, processes, cursor keys, logs, browser profiles, traces and screenshots containing runtime data.

## Acceptance Gate

Final acceptance is `IMPLEMENTED + E2E_PASS`. Tooling-only or mocked evidence is insufficient. The Execution Record
must include initial/final dirty inventory, backend commit, exact commands/counts, HTTP request counts, redaction and
negative evidence, cleanup counts, residual risks, and `Commit created: No`.

## Execution Record

Implementation session: append evidence here; do not rewrite the frozen contract above.

### 2026-07-22 - axis-iam-web implementation session

- Implementation State: `IMPLEMENTED`
- Validation Evidence: `BLOCKED`
- External completion claim: no
- Harness declared before edits: yes; named focused parser/hook/list/detail/nav/router Vitest files and the real
  Organization invitation worker lifecycle before production edits.
- Initial inventory: Portal clean `main@e032940`; Admin clean `main`; created
  `feature/portal-notification-delivery-diagnostics-frontend`. Backend authority recorded as accepted D4b
  `a7b43a43` with closeout `726a98f2`.
- Changes: added the two requested routes, one localized Application Settings navigation item, exact ten-field/six-
  status types, strict UUIDv7/UTC/enum/count/field/duplicate parser, dedicated TanStack Query hooks, cursor-only
  in-memory pagination, status/date/limit filters, localized list/detail views, semantic times, and explicit 400
  `INVALID_CURSOR`, 404, 503 and malformed-response states. No notification mutation, Webhook command reuse,
  retired endpoint, runtime MSW fallback, confidential field, cursor persistence or cursor decoding was added.
- Focused command: `pnpm exec vitest run src/api/hooks/use-notification-deliveries.test.tsx
  src/routes/settings/notification-deliveries/NotificationDeliveriesPage.test.tsx
  src/routes/settings/notification-deliveries/NotificationDeliveryDetailPage.test.tsx
  src/components/layout/nav-config.test.ts src/router.test.tsx` -> 5 files / 20 tests passed.
- Other tooling: `pnpm test` passed; `pnpm typecheck` passed; `pnpm lint` passed with 0 errors and the same 2 unrelated
  pre-existing `src/routes/apps/clients/client-shared.tsx` warnings; `pnpm build` passed with existing chunk-size and
  dynamic-import warnings; `git diff --check` passed.
- Real Playwright fixture: `tests/browser/portal-notification-delivery-diagnostics.desktop.spec.ts` owns disposable
  Applications/Organization/invitation through Portal HTTP, waits for the real worker delivery, checks desktop
  1440x900 and mobile 390x844, cursor/filter/detail/cross-Application/invalid-cursor/bilingual/overflow/read-only/
  redaction behavior, and deletes task Applications in `finally`.
- E2E command: `pnpm playwright test --config=playwright.config.ts --grep "notification delivery diagnostics"` ->
  1 skipped. Required `PORTAL_D4C_TASK_OWNED=1` and isolated runtime were absent; probes showed ports 30001, 30002 and
  31443 were not listening. Existing PG17/Redis containers were not claimed or mutated because ownership/keyring
  provenance was unknown. Therefore no real login, membership, worker, HTTP request count, runtime redaction matrix,
  or runtime cleanup count is claimed.
- Cleanup: no D4c runtime container, data, port, process, keyring, log, trace, screenshot or browser profile was
  created by this session; Playwright created no retained failure trace. Build output is local untracked-ignore data.
- Final inventory: only D4c Portal source/tests/docs are dirty; `iam-admin-web` remains clean and read-only.
- Remaining risk/blocker: rerun the declared Playwright spec against current backend main with task-owned PostgreSQL
  17/Redis, a temporary D4b cursor keyring, real Portal login/membership, and active notification worker. The full
  runtime matrix and cleanup evidence are still required before changing this record to `E2E_PASS`.
- Commit created: No

### 2026-07-22 - coordinator merge closeout

- Coordinator accepted the final `IMPLEMENTED + E2E_PASS` evidence.
- Implementation commit: `a9e6073`; merged to Portal `main` as `f9db728`.
- No public artifact, tag, deployment, or backend/Admin change was performed by this closeout.

### 2026-07-22 - task-owned runtime E2E closeout

- Implementation State: `IMPLEMENTED`
- Validation Evidence: `E2E_PASS`
- External completion claim: yes
- Runtime: created task-owned PostgreSQL 17 (`d4c-pg-20260722`, host `35433`) and Redis 7 (`d4c-redis-20260722`,
  host `36380`), ran current backend `main@9855931b` on `33001/33002`, and Portal Web on `33443` with a temporary
  D4b cursor keyring. Granted only the task-owned `iam_portal_delivery_worker` capability membership and enabled
  `ORG_INVITATION_DURABLE` OUTBOX control; no delivery business row was injected.
- Fixture lifecycle: real Portal login as `admin@example.com`, live Workspace membership, two disposable Applications,
  one Organization, and 21 Organization invitation HTTP commands with `sendEmail=true`; the real worker produced at
  least 21 durable deliveries. The Playwright `finally` deleted both Applications, cascading task fixtures.
- Passing command: `PORTAL_D4C_TASK_OWNED=1 PORTAL_SMOKE_PORTAL_WEB_URL=http://127.0.0.1:33443
  PORTAL_SMOKE_IAM_SERVER_URL=http://127.0.0.1:33001 PORTAL_SMOKE_IAM_PORTAL_URL=http://127.0.0.1:33002
  pnpm playwright test --config=playwright.config.ts --grep "notification delivery diagnostics" --reporter=line`
  -> 1 passed (19.4s).
- Matrix evidence: desktop 1440x900 and mobile 390x844; real list/detail; 20+1 cursor pagination and previous-page
  traversal; status filtering; filter reset; empty second Application; cross-Application detail 404; invalid cursor
  400; 503 with Query retry suppression plus user Refetch; malformed JSON with user Refetch; bilingual rendering;
  no mutation/command endpoint; no `/delivery-logs`/Webhook request; no client-credentials request; no sensitive DOM;
  no unexpected console/page errors; and no page-level overflow.
- HTTP negative/fixture counts: 21 invitation POST commands; direct diagnostics assertions covered successful list,
  foreign detail `404`, and invalid cursor `400`; browser fault injections covered persistent 503 and malformed-JSON
  responses until the read-only Refetch. The Playwright request listener asserted every diagnostics browser request
  was GET and no forbidden endpoint occurred.
- Cleanup: stopped task backend/frontend processes; removed task containers; removed browser `test-results` traces,
  `/tmp/d4c-server.log`, temporary key material, and task ports `33001`, `33002`, `33443`, `35433`, `36380`. Final
  port checks were clear; no task process remained. Existing unrelated containers/processes were untouched.
- Final gate: `IMPLEMENTED + E2E_PASS`. Commit created: No.

### 2026-07-22 - acceptance remediation

- Implementation State: `IMPLEMENTED`
- Validation Evidence: `BLOCKED`
- External completion claim: no
- Corrected the date filter serialization to use the backend's canonical `Instant.toString()` wire form: whole-second
  values now send `...:00Z`, never `...:00.000Z`. The shared formatter has fixed Java contract vectors for both whole
  seconds and non-zero milliseconds.
- Added a separate localized invalid-query state for every 400 response. Invalid cursor retains its first-page reset;
  other invalid query responses expose `Reset query`, which clears filters and cursor history without a misleading
  refetch. `SyntaxError` from malformed raw JSON is now classified as malformed response; 503 alone exposes read-only
  refetch.
- Added focused regressions for canonical date transport, non-cursor `BAD_REQUEST`, 503/refetch, raw malformed JSON,
  and the `Delivery diagnostics` navigation item. Focused command passed 5 files / 24 tests.
- Re-ran `pnpm exec vitest run --maxWorkers=2 --reporter=dot`, `pnpm typecheck`, `pnpm lint`, `pnpm build`, and
  `git diff --check`; all passed. Lint remains 0 errors with the same two unrelated client-shared warnings.
- Re-ran the required Playwright grep at this checkpoint: 1 skipped because the task-owned runtime/keyring marker was
  absent. This historical `BLOCKED` checkpoint is superseded by the task-owned runtime E2E closeout above; the current
  final status is `IMPLEMENTED + E2E_PASS`.
- Commit created: No
