@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 API —
AuditService.log()for business events (with optional transaction support) - Query API v2 —
AuditService.query()with keyset cursors, wildcard filters, optional totals, andgetById() - Decorators —
@NoAudit(),@AuditAction(), and@AuditReason()on handlers or controllers - Custom primary keys — configurable per-model PK field (defaults to
id) - Multi-tenant — optional
@nestarc/tenancyintegration with explicit tenant scoping and authorized cross-tenant reads - Retention & partitioning — monthly PostgreSQL partitions,
ensurePartitions(), andAuditService.prune() - Append-only — trigger enforcement blocks UPDATE/DELETE on audit records by default
Requirements
- NestJS 10 or 11
- Prisma 5 or 6
- PostgreSQL