Skip to main content

Access-change log API (B14)

Feature 003 (Organisations, Team & Access), user story 10 — a single, append-only audit trail of every access-affecting change in an organisation: memberships, roles, scopes, shares, invitations, access requests, session revocations and two-factor resets. Nothing on this page can be updated or deleted through the API — it is a read-only view onto a write path every other 003 route already participates in.

:::caution Code-complete, not yet captured against a real deployment As of 2026-10-03, packages/core/src/repositories/access-log.ts (the append helper and the GET query), packages/api/src/handlers/access-log.ts (the route handler) and the CDK route (lib/routes.ts's GetAccessLog) are all landed and unit-tested (packages/api/test/handlers/access-log.test.ts, packages/api/test/contract/openapi.test.ts). Every request/response shape below is still illustrative — derived from the OpenAPI schema (docs/openapi.yaml, schema AccessLogEntryView) and the Zod schemas in packages/core/src/schemas.ts (AccessLogEntry, AccessLogItem, AccessLogQuery) — not a captured execution against a running stack. :::

How an entry gets here​

This page has no write route. An entry is appended by the SAME atomic DynamoDB transaction as the change it describes — packages/core/src/ repositories/access-log.ts's accessLogPut() returns one Put transact item that every one of the following repositories folds into its own transaction, never as a separate write:

  • Memberships — role/scope/department/MFA-requirement changes, suspend, restore, remove, end-sessions, MFA reset (see Team and its member-actions section)
  • Roles and departments — created, updated, deleted
  • Shares — created, updated, suspended, restored, revoked (see Shares)
  • Invitations — invited, resent, revoked, accepted (see Invitations)
  • Access requests — requested, approved, rejected (see Access requests)
  • The organisation itself — created, updated
  • A personal organisation's lazy creation

A static test (packages/core/test/access-log.architecture.test.ts) enforces that every mutating function across these repositories calls accessLogPut() exactly once per transaction, and that no code path ever Updates or Deletes an ACCESSLOG# item — so the guarantee "every access change is logged, and the log can't be edited" is structural, not just documented.

GET /v1/orgs/{orgId}/access-log​

Purpose: the "Recent access changes" feed — newest first, filterable by type and date range.

  • Auth: audit ≥ VIEW (ADR 0014; was team ≥ VIEW — audit derives from team for roles stored earlier, see Roles & permissions). A caller with no ACTIVE membership in {orgId} gets 404 NOT_FOUND (same requireOrgLevel convention as every other 003 route), not 403.

  • A member-level secret: the changes (before/after of the changed fields) and requestId fields on each row are included only for a caller at audit = FULL — the Super Admin (RBAC-S1, 2026-11-23; was audit ≥ MANAGE). An Administrator (audit: MANAGE) or an audit: VIEW caller gets every other field (type, at, actor, target, summary, impact) with those two simply absent from the JSON (never null). Build the "show details" affordance around whether the field is present, not around a separate permission check — the server has already decided.

  • Query parameters:

    ParamTypeNotes
    typeone or more of the 31 AccessLogType values (see below)Optional, repeatable (type=A&type=B), matched with an IN filter — same explode: true convention as GET /v1/orgs/{orgId}/members's status
    fromISO-8601 datetimeOptional. Inclusive lower bound.
    toISO-8601 datetimeOptional. Inclusive upper bound. from must be ≤ to.
    limitinteger≤ 50, default per ListQuery
    cursoropaque stringFrom a previous page's nextCursor

    Supplying from/to together with a span over 366 days is rejected (422 VALIDATION_FAILED, details.maxSpanDays: 366) — the FE should cap any custom date-range picker at a year to avoid a round trip that's guaranteed to fail. An unknown query parameter is 400 VALIDATION_FAILED with details.unknown, same convention as every other strict 003 list route (see Overview → Conventions).

The type values​

ORG_CREATED, ORG_UPDATED,
MEMBER_INVITED, MEMBER_ROLE_CHANGED, MEMBER_SCOPE_CHANGED,
MEMBER_DEPARTMENT_CHANGED, MEMBER_MFA_REQUIREMENT_CHANGED,
MEMBER_SUSPENDED, MEMBER_RESTORED, MEMBER_REMOVED,
MEMBER_SESSIONS_ENDED, MEMBER_MFA_RESET,
INVITATION_RESENT, INVITATION_REVOKED, INVITATION_ACCEPTED, INVITATION_DECLINED,
ROLE_CREATED, ROLE_UPDATED, ROLE_DELETED,
DEPARTMENT_CREATED, DEPARTMENT_UPDATED, DEPARTMENT_DELETED,
SHARE_CREATED, SHARE_UPDATED, SHARE_SUSPENDED, SHARE_RESTORED,
SHARE_REVOKED,
ACCESS_REQUESTED, ACCESS_REQUEST_APPROVED, ACCESS_REQUEST_REJECTED,
PERSONAL_ORG_CREATED,
TAG_ACCESS_IMPACT,
PLANT_ACCESS_CHANGED, CUSTOMER_PORTAL_CHANGED, CUSTOMER_CLOSED,
PARTNER_SUSPENDED, PLANT_ARCHIVED, PLANT_RESTORED,
PLANT_DELETION_REQUESTED, PLANT_SHARE_LINK_CREATED, PLANT_SHARE_LINK_REVOKED,
NOTIFICATION_RULE_CREATED, NOTIFICATION_RULE_UPDATED,
NOTIFICATION_RULE_DELETED, NOTIFICATION_SETTINGS_UPDATED,
MFA_DISABLED, MFA_DISABLED_OUT_OF_BAND,
PLATFORM_ACCESS, SESSION_ENDED, INVITATION_UPDATED,
BUSINESS_LIMIT_CHANGED, PLANT_INSTALLER_CHANGED

BUSINESS_LIMIT_CHANGED (2026-11-03) is written to both the PLATFORM org and the Business org when an Admin or Super Admin changes a Business limit; changes.permsLimit holds per-category { from, to } (null = no limit). PLANT_INSTALLER_CHANGED (2026-11-03) is written to the Business org when a plant's assigned Installer changes (target.kind: PLANT, changes.assignedInstaller: { from, to } as subs or null).

The list matches AccessLogType in packages/core/src/schemas.ts.

PLATFORM_ACCESS and viaPlatform (owner Q15, 2026-10-27)​

Written when Crown platform staff act in this org without a membership of their own here: the org-level platform fallback, plant routes (logged to the plant's operator org), roster/technicians/ maintenance plans, work orders, reports, device binding at plant create, lookups, plant jobs and member actions. One entry per request, written to this (target) org's log after the handler responds, for every state-changing request (any method other than GET/HEAD/OPTIONS, unless the route is declared read-only), including refused ones. Reads are not logged, with one exception (2026-11-26): Crown staff reading or downloading another org's report (GET /v1/reports/{reportId}, …/download) write an entry with checks reports:read / reports:download (see Reports → Browsing the Businesses from HQ). Unlike other entries it is not in the same transaction as the change; if the write fails the API logs ERROR platform_access_log_failed and still returns the action's own response.

FieldValue
typePLATFORM_ACCESS
viaPlatformtrue (absent on every other type)
actorthe platform user's sub and display name (falls back to the sub)
target{ kind: "ORG", id: <this org>, label: <org name> }
summaryCrown platform access: <routeKey> → <status>
changes{ routeKey, status, platformOrgId, checks }; checks lists the decisions, e.g. service:MANAGE, plant. Readers below audit FULL (everyone but the Super Admin, RBAC-S1) see viaPlatform but not changes/requestId

Masked for readers outside the Crown org (2026-11-12). Since then the action's own entries written during platform access (e.g. MEMBER_INVITED) also carry viaPlatform: true. A reader with no Crown membership sees every such entry's actor as { "displayName": "Crown Support", "viaPlatform": true } — no sub. Crown members see the person. Older entries other than PLATFORM_ACCESS carry no marker and are shown as stored. See Role boundaries.

TAG_ACCESS_IMPACT (feature 004 plant tags) is written when a tag is attached to or detached from a plant, after a bulk tag run, and, since 2026-11-30 (QA B7), when a plant is created with tagIds. A single-plant entry's impact has gained and lost counts. It also has gainedSubs: the Cognito subs of the members who gained the plant through the tag, at most 50. Bulk entries have counts only. The Business owner is not notified; that is a pending product decision.

Response (illustrative)​

{
items: Array<{
entryId: string; // ULID — the log entry's own sort-key id
type: string; // one of the values above
at: string; // ISO-8601 UTC
actor: { sub?: string; displayName: string }; // sub omitted for a SYSTEM-attributed entry
target: { kind: "MEMBER"|"ROLE"|"DEPARTMENT"|"SHARE"|"INVITATION"|"ACCESS_REQUEST"|"ORG"|"TAG"; id: string; label: string };
summary: string; // human-readable, ≤ 300 chars, never an email or token
impact?: { members?: number; plants?: number; approximate?: boolean };
changes?: Record<string, unknown>; // audit = FULL (Super Admin) only — RBAC-S1
requestId?: string; // audit = FULL (Super Admin) only — RBAC-S1
correlationId?: string;
viaPlatform?: true; // PLATFORM_ACCESS entries only (Q15)
}>;
nextCursor?: string;
}

Note the field is entryId on the wire, even though the underlying repository calls the same value id internally — the handler renames it on the way out so this page's shape matches docs/openapi.yaml exactly.

Status codes​

StatuscodeWhenFE action
200—OKRender newest-first; show "details" only for rows carrying changes
400VALIDATION_FAILEDUnknown query parameter, from after to, or date-range span over 366 daysFix the request; for the span case, narrow the date picker
401UNAUTHENTICATEDMissing/invalid/expired tokenRefresh token / re-authenticate
403FORBIDDENteam < VIEW in orgIdHide the "Recent access changes" section
500/503INTERNAL / DEPENDENCY_UNAVAILABLEUnexpected / AWS dependency issueRetry with backoff (503 carries Retry-After)

Edge cases​

  • Empty result: items: [], no nextCursor — same "empty list, not an error" convention as every other 003 list route.
  • Invalid/expired cursor: this is a strict route, so a malformed, reused-against-a-different-filter, or otherwise invalid cursor is 400 INVALID_CURSOR — it does not silently restart from page 1 the way the seven legacy mobile routes do.
  • A page can come back shorter than limit even though more matching rows exist further on. The type filter is applied as a DynamoDB FilterExpression after the Limit on the underlying Query (the same imprecision GET /v1/orgs/{orgId}/access-requests's own filtering has) — keep paging with the returned nextCursor rather than assuming a short page means "last page."
  • status=EXPIRED-style derived filters don't apply here — unlike access requests, nothing in this feed is "derived" at read time; every row reflects exactly what was true when the change happened.
  • No mutation route exists for entries, intentionally — there is no PATCH/DELETE to call, by design (see the Super Admin note on the product's own "Recent access changes" screen: "Every action a Super Admin takes is logged and cannot be deleted").

Known gaps​

  • There is no bulk-export route on this page. audit.export is a listed capability (see Architecture → Authorization model) but no route currently exercises it for this feed specifically. When one does, only the Super Admin holds it: it needs the role's audit-trail flag, which an Administrator does not have (RBAC-S1).