Agent Guide
This guide targets published @nestarc/[email protected]. Use the installed package declarations and 0.8.0 release source as the version boundary. Start with the Quick Start, Incremental Adoption, or SQL Server guide.
- Require Node.js
^22.23.4 || ^24.22.1, NestJS 10/11/12.0.1+, and compatible Prisma 5/6/7 dependencies. Use matching Prisma CLI/client/adapter versions. Pass the generated{ Prisma }namespace for Prisma 7 at module and extension boundaries. - Choose the provider explicitly when needed: omitted
providerselects PostgreSQL. SQL Server supports manual logging, managed manual transactions, andquery()/getById(). It does not support automatic tracking, scan/export, retention, partitions, GIN indexes, or rule enforcement. The pinned SQL Server validation stack is SQL Server 2025 with Prisma 7.10.0. - Start with one manual event or one PostgreSQL tracked model. Use
defineAuditConfig()to share actor, tenant, table, provider, and masking settings. Put shared fields only inshared, andstrictManualValidation,maxMetadataBytes, andonAuditOperationinmodule. Provideprismaat module registration; omitextensionfor manual-only use. The factory performs no database work. - Create audit storage in an explicit migration with a setup identity. Keep the base client for audit storage. On PostgreSQL, use
createAuditedClient()and atrackedModelsallowlist for automatic writes, withconsistency: 'atomic-required'andwithAuditTransaction(). Caught automatic audit failures still prevent helper commit.best-efforthas independent inserts. - For manual events, use
audit.withManualTransaction(base, async ({ tx, log }) => ...)when caught audit failures must prevent commit. Await the bound writer; use itstxfor all business writes. Already-started writes settle before completion, expired writers reject, and nested managed helpers are unsupported. The helper cannot detect missing events or enlist a captured base client. Caller-ownedlog(input, tx)remains available; its errors must escape the callback. - Manual validation defaults to off. Before enabling it, review identifiers and JSON metadata.
maxMetadataBytesmeasures final redacted JSON in UTF-8 bytes, including context metadata; oversize events reject rather than truncate. HandleAuditInputError.codeand.fieldwithout logging raw event values. Catching these errors inside the managed helper still prevents commit. - Use
actorExtractionStage: 'interceptor'when a Guard populates identity. Authenticate and authorize in the host. OptionalactorRequiredneeds non-blank string IDs for users, API keys, and workers. Workers useAuditContext.runAs()and establish tenant context separately. Automatic exclusions remain bypasses; explicit manual logs still enforce actor policy. - Use explicit operations for tracked children. Atomic nested-write checks include untracked parents and intermediate relations. Atomic
createMany,updateMany,createManyAndReturn, andupdateManyAndReturnreject for tracked models; use sequential single-record calls.deleteManyhas a per-record cap. See Automatic CUD Tracking. - Authorize history access before selecting tenant scope. Match action and source: automatic
Invoice.*versus manualinvoice.approved. SQL Server cursors retain full timestamp precision; keep them opaque and never reuse them across providers. Read credentials need SELECT privileges. getCapabilities()reports configured provider APIs without database I/O; it does not prove connection, schema, or permissions. The audited client'sgetAuditCapabilities()reports the separate automatic consistency/lifecycle contract.onAuditOperationomits event contents; a successful log reports INSERT completion, while managed transactions have a final outcome. Filter detailedonAuditErrordata before forwarding it to telemetry.- PostgreSQL exports require explicit scope.
after === untilcompletes without replay. Durable streams may miss late commits; use entry-ID deduplication and CDC or reconciliation for complete capture. Load required checkpoints before retention; missing checkpoints must stop pruning. - Soft-delete 0.7.4 excludes audit-log 0.8.0 from its peer range. Do not use that unsupported tuple or bypass strict peers. The documented older lifecycle recipe retains its 0.7.0 / 0.7.4 scope; a new combined tuple needs an exact published compatible companion and lifecycle validation. Optional tenancy transaction/RLS composition also requires separate verification: an audit tenant ID alone does not establish transaction-local tenant isolation.
Verify a committed write, rollback, actor and tenant values, redaction, and an authorized history query. Test missing-actor and enabled validation/size failures, including caught failures in the managed helper. Keep setup/maintenance credentials separate from the request-serving runtime. SQL Server inspection can have incomplete metadata and never proves trigger enforcement; verify actual permissions and commit/rollback behavior. Read indexes require an explicit migration.