Skip to content

Manual Logging

Use AuditService.log() for business events that are not automatically tracked by the Prisma extension.

Basic Usage

typescript
await auditService.log({
  action: 'invoice.approved',
  targetId: 'inv-123',
  targetType: 'Invoice',
  metadata: { amount: 5000, currency: 'USD' },
});

With Transaction

typescript
await prisma.base.$transaction(async (tx) => {
  await tx.invoice.update({ where: { id }, data: { status: 'approved' } });
  await auditService.log({ action: 'invoice.approved', targetId: id }, tx);
  // Both roll back together if anything fails
});

AuditLogModule.forRoot / forRootAsync Options

OptionTypeDefaultDescription
prismaPrismaClientrequiredBase Prisma client for audit storage
actorExtractor(req) => AuditActorrequiredExtracts actor from HTTP request
tenantRequiredbooleanfalseWhen true, throws if tenant context is unavailable

Released under the MIT License.