Skip to content

@nestarc/audit-log

Audit logging module for NestJS with automatic Prisma change tracking and append-only PostgreSQL storage.

Features

  • Automatic CUD tracking via Prisma $extends — create, update, delete, upsert, and batch operations
  • Transaction contract is explicit — business writes keep the caller $transaction, while automatic audit inserts are best-effort outside that transaction
  • Before/after diffs with deep comparison for JSON fields
  • Sensitive field masking — configurable [REDACTED] replacement
  • Manual logging APIAuditService.log() for business events (with optional transaction support)
  • Query API v2AuditService.query() with keyset cursors, wildcard filters, optional totals, and getById()
  • Decorators@NoAudit(), @AuditAction(), and @AuditReason() on handlers or controllers
  • Custom primary keys — configurable per-model PK field (defaults to id)
  • Multi-tenant — optional @nestarc/tenancy integration with explicit tenant scoping and authorized cross-tenant reads
  • Retention & partitioning — monthly PostgreSQL partitions, ensurePartitions(), and AuditService.prune()
  • Append-only — trigger enforcement blocks UPDATE/DELETE on audit records by default

Requirements

  • NestJS 10 or 11
  • Prisma 5 or 6
  • PostgreSQL

Released under the MIT License.