@zola_do/audit
v0.1.10
Published
RabbitMQ-based audit logging for NestJS
Readme
@zola_do/audit
RabbitMQ-based audit logging for NestJS applications.
Installation
# Install individually
npm install @zola_do/audit
# Or via meta package
npm install @zola_do/nestjs-sharedOptional Dependencies for Audit Features
Audit logging requires RabbitMQ. Install these peer dependencies to enable audit features:
npm install @nestjs/microservices amqplibNote: You can safely import AuditModule without these dependencies. The module will load successfully but audit features will be disabled (with a development-mode warning). This allows the rest of your app to work without RabbitMQ.
Usage
Module Setup
import { Module } from '@nestjs/common';
import { AuditModule } from '@zola_do/audit';
@Module({
imports: [AuditModule],
})
export class AppModule {}Marking Routes for Audit
Use @AuditRmqEvent() to mark controller methods for audit logging:
import { Controller, Post, Body } from '@nestjs/common';
import { AuditRmqEvent } from '@zola_do/audit';
@Controller('orders')
export class OrdersController {
@Post()
@AuditRmqEvent()
createOrder(@Body() dto: CreateOrderDto) {
// This request will be logged to RabbitMQ
}
}Ignoring Audit Logging
Use @IgnoreLogger() to exclude specific routes from audit logging:
import { IgnoreLogger } from '@zola_do/audit';
@Get('health')
@IgnoreLogger()
healthCheck() {
return { status: 'ok' };
}AuditLoggerInterceptor
When amqplib and @nestjs/microservices are installed, AuditLoggerInterceptor is automatically registered as a global interceptor. It captures requests to routes decorated with @AuditRmqEvent() and publishes audit events to RabbitMQ.
Environment Variables
| Variable | Description |
|----------|-------------|
| RMQ_URL | RabbitMQ connection URL (e.g. amqp://user:pass@localhost:5672) |
Exports
AuditModule— Register the audit moduleAuditRmqEvent/AUDIT_RMQ_EVENT— Decorator to mark routes for auditIgnoreLogger— Decorator to exclude routes from auditAuditLoggerInterceptor— Interceptor (auto-registered when deps available)AuditSubscriber— TypeORM subscriber for entity change auditingauditLoggerConfig— RabbitMQ client config
Related Packages
- @zola_do/core — Shared types
- @zola_do/authorization — User context for audit
