Agent Guide
This guide targets published @nestarc/audit-log@0.7.0. Use the installed package's declarations and 0.7.0 changelog as the version boundary. The release artifact includes older README/Quick Start labels; use this site's Quick Start and Incremental Adoption for the 0.7.0 install path.
- Check Node.js, NestJS, Prisma, and PostgreSQL requirements in Installation. Use the generated
{ Prisma }namespace for Prisma 7 at both the module and extension boundaries. - Start with one manual event or one tracked model. Use
defineAuditConfig()to build shared actor, tenant, table, masking, module, extension, schema, and partition options. Put shared fields only inshared; provideprismaat module registration. Omitextensionfor manual-only use. The factory creates no client and performs no schema or database work. - Create the audit schema in a migration. Keep the base client for audit storage; use
createAuditedClient()for automatic business writes and an explicittrackedModelsallowlist. Setconsistency: 'atomic-required'and usewithAuditTransaction()for supported tracked writes. Automatic audit failures prevent helper commit even when caught. Manuallog(input, tx)errors still must escape the callback for rollback.best-efforthas independent audit inserts. - Use direct operations for tracked child writes. Atomic nested-write checks include untracked parents and intermediate relations. Atomic
createMany,updateMany,createManyAndReturn, andupdateManyAndReturnare rejected for tracked models; use sequential single-record calls.deleteManyhas a per-record cap. Check Automatic CUD Tracking and Migrating to 0.7.0. - Use
actorExtractionStage: 'interceptor'when a Guard populates identity. Authenticate and authorize in the host app.actorRequiredis optional and defaults tofalse; enabling it requires non-blank string IDs for users, API keys, and workers. Workers useAuditContext.runAs()and establish tenant context separately. Automatic exclusions remain intentional bypasses; explicit manual logs still enforce the actor policy. - Match action names and source exactly. Automatic
Invoicewrites useInvoice.*; a manualinvoice.approvedevent hassource: 'manual'. Query API lists filters, inclusive time bounds, optional totals, and pagination constraints.actorRequireddoes not authenticate reads or grant cross-tenant access. - Use explicit scope for exports. A saved
after === untilis a completed range with no replay in 0.7.0. Treat durable streams as timestamp-based delivery of observed rows: late commits can be missed. Use entry-ID deduplication and external CDC or reconciliation when complete continuous capture is required. - Load every required stream state before retention. A missing checkpoint must stop prune; a timestamp checkpoint does not replace CDC or reconciliation completion evidence. Use the same custom table name for runtime, schema, and partition maintenance.
- For the atomic lifecycle bridge, pair audit-log 0.7.0 with soft-delete 0.7.4, ordered audit-log then soft-delete. Optional tenancy transaction/RLS composition requires separate verification; a populated audit tenant ID alone does not prove transaction-local tenant isolation.
Verify one committed write, one rollback, expected actor and tenant values, one redacted field, and a query that finds the event. Also test missing-actor rejection if enabled, including worker execution, and a caught automatic policy failure to verify rollback of earlier writes. Schema owners and maintenance credentials remain separate from the request-serving runtime.