Skip to Content
gentlemans-stack
ReferenceModels

audit-model

Browser-safe Zod schemas and inferred types for the audit log. Persistence is in domains/audit-domain.

API

ExportWhat it is
auditEventSchema / AuditEventA stored event: id, at (ISO), optional workspaceId, actor snapshot, action, optional target, outcome, optional changes, context.
auditEventInputSchema / AuditEventInputWhat a caller records: the same without id and at.
AUDIT_ACTIONS, auditActionSchemaThe typed union of actions (member, invite, workspace, todo and account events).
AUDIT_OUTCOMES, auditOutcomeSchemasuccess, denied or failed.
AUDIT_CHANGE_FIELDS, pickAllowedChanges(action, changes)The per-action allow-list of changes fields, and the function that drops everything else.
auditEventViewSchema, auditPageViewSchemaWhat audit.list returns: an event whose context has no ip, spanId or traceId (those stay in the database for operators).
auditListQuerySchema, auditPageSchemaThe list input (workspaceId, action?, actorId?, cursor?, limit) and its { items, nextCursor? } output.

actor is a snapshot (type, optional id, name, email), so a row stays readable after the user is renamed or deleted. context carries requestId, service and, when a trace is active, traceId, spanId; ip and userAgent are optional.

Adding an action means adding it to AUDIT_ACTIONS and AUDIT_CHANGE_FIELDS (the spec fails if one is missing).

Commands

pnpm nx run audit-model:typecheck   # type-check the package
pnpm nx run audit-model:test        # run the Vitest suite

On this page