@zola_do/audit 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @zola_do/audit
|
|
2
|
+
|
|
3
|
+
RabbitMQ-based audit logging for NestJS applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install individually
|
|
9
|
+
npm install @zola_do/audit
|
|
10
|
+
|
|
11
|
+
# Or via meta package
|
|
12
|
+
npm install @zola_do/nestjs-shared
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Optional Dependencies for Audit Features
|
|
16
|
+
|
|
17
|
+
Audit logging requires RabbitMQ. Install these peer dependencies to enable audit features:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @nestjs/microservices amqplib
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Note:** 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.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Module Setup
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { Module } from '@nestjs/common';
|
|
31
|
+
import { AuditModule } from '@zola_do/audit';
|
|
32
|
+
|
|
33
|
+
@Module({
|
|
34
|
+
imports: [AuditModule],
|
|
35
|
+
})
|
|
36
|
+
export class AppModule {}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Marking Routes for Audit
|
|
40
|
+
|
|
41
|
+
Use `@AuditRmqEvent()` to mark controller methods for audit logging:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { Controller, Post, Body } from '@nestjs/common';
|
|
45
|
+
import { AuditRmqEvent } from '@zola_do/audit';
|
|
46
|
+
|
|
47
|
+
@Controller('orders')
|
|
48
|
+
export class OrdersController {
|
|
49
|
+
@Post()
|
|
50
|
+
@AuditRmqEvent()
|
|
51
|
+
createOrder(@Body() dto: CreateOrderDto) {
|
|
52
|
+
// This request will be logged to RabbitMQ
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Ignoring Audit Logging
|
|
58
|
+
|
|
59
|
+
Use `@IgnoreLogger()` to exclude specific routes from audit logging:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { IgnoreLogger } from '@zola_do/audit';
|
|
63
|
+
|
|
64
|
+
@Get('health')
|
|
65
|
+
@IgnoreLogger()
|
|
66
|
+
healthCheck() {
|
|
67
|
+
return { status: 'ok' };
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### AuditLoggerInterceptor
|
|
72
|
+
|
|
73
|
+
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.
|
|
74
|
+
|
|
75
|
+
## Environment Variables
|
|
76
|
+
|
|
77
|
+
| Variable | Description |
|
|
78
|
+
|----------|-------------|
|
|
79
|
+
| `RMQ_URL` | RabbitMQ connection URL (e.g. `amqp://user:pass@localhost:5672`) |
|
|
80
|
+
|
|
81
|
+
## Exports
|
|
82
|
+
|
|
83
|
+
- `AuditModule` — Register the audit module
|
|
84
|
+
- `AuditRmqEvent` / `AUDIT_RMQ_EVENT` — Decorator to mark routes for audit
|
|
85
|
+
- `IgnoreLogger` — Decorator to exclude routes from audit
|
|
86
|
+
- `AuditLoggerInterceptor` — Interceptor (auto-registered when deps available)
|
|
87
|
+
- `AuditSubscriber` — TypeORM subscriber for entity change auditing
|
|
88
|
+
- `auditLoggerConfig` — RabbitMQ client config
|
|
89
|
+
|
|
90
|
+
## Related Packages
|
|
91
|
+
|
|
92
|
+
- [@zola_do/core](../core) — Shared types
|
|
93
|
+
- [@zola_do/authorization](../authorization) — User context for audit
|