@elchinabilov/nestjs-audit-logs 1.0.0
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 +100 -0
- package/dist/audit-log.controller.d.ts +7 -0
- package/dist/audit-log.controller.js +45 -0
- package/dist/audit-log.controller.js.map +1 -0
- package/dist/audit-log.decorator.d.ts +6 -0
- package/dist/audit-log.decorator.js +8 -0
- package/dist/audit-log.decorator.js.map +1 -0
- package/dist/audit-log.entity.d.ts +13 -0
- package/dist/audit-log.entity.js +68 -0
- package/dist/audit-log.entity.js.map +1 -0
- package/dist/audit-log.interceptor.d.ts +11 -0
- package/dist/audit-log.interceptor.js +50 -0
- package/dist/audit-log.interceptor.js.map +1 -0
- package/dist/audit-log.module.d.ts +2 -0
- package/dist/audit-log.module.js +36 -0
- package/dist/audit-log.module.js.map +1 -0
- package/dist/audit-log.service.d.ts +18 -0
- package/dist/audit-log.service.js +66 -0
- package/dist/audit-log.service.js.map +1 -0
- package/dist/cls.middleware.d.ts +8 -0
- package/dist/cls.middleware.js +30 -0
- package/dist/cls.middleware.js.map +1 -0
- package/dist/context/audit-context.middleware.d.ts +8 -0
- package/dist/context/audit-context.middleware.js +36 -0
- package/dist/context/audit-context.middleware.js.map +1 -0
- package/dist/dto/audit-log-filter.dto.d.ts +7 -0
- package/dist/dto/audit-log-filter.dto.js +42 -0
- package/dist/dto/audit-log-filter.dto.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/cls.middleware.d.ts +8 -0
- package/dist/middleware/cls.middleware.js +30 -0
- package/dist/middleware/cls.middleware.js.map +1 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# @elchinabilov/nestjs-audit-logs
|
|
2
|
+
|
|
3
|
+
NestJS audit log module for TypeORM with CLS context support.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
- TypeORM entity and service for storing audit logs
|
|
7
|
+
- Interceptor that captures request metadata
|
|
8
|
+
- Decorator for per-route metadata
|
|
9
|
+
- CLS integration via `nestjs-cls` (installed automatically)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
```bash
|
|
13
|
+
npm install @elchinabilov/nestjs-audit-logs
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Peer dependencies
|
|
17
|
+
Make sure your app has these installed:
|
|
18
|
+
- `@nestjs/common`
|
|
19
|
+
- `@nestjs/core`
|
|
20
|
+
- `@nestjs/typeorm`
|
|
21
|
+
- `typeorm`
|
|
22
|
+
- `rxjs`
|
|
23
|
+
- `class-validator`
|
|
24
|
+
|
|
25
|
+
`nestjs-cls` is a direct dependency and will be installed automatically.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### 1) Import the module
|
|
30
|
+
```ts
|
|
31
|
+
import { Module } from '@nestjs/common';
|
|
32
|
+
import { AuditLogModule } from '@elchinabilov/nestjs-audit-logs';
|
|
33
|
+
|
|
34
|
+
@Module({
|
|
35
|
+
imports: [AuditLogModule],
|
|
36
|
+
})
|
|
37
|
+
export class AppModule {}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2) Ensure the entity is registered
|
|
41
|
+
If you use `autoLoadEntities: true`, it will be picked up automatically. Otherwise, add `AuditLogEntity` to your TypeORM entities.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
45
|
+
import { AuditLogEntity } from '@elchinabilov/nestjs-audit-logs';
|
|
46
|
+
|
|
47
|
+
TypeOrmModule.forRoot({
|
|
48
|
+
// ...
|
|
49
|
+
entities: [AuditLogEntity],
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 3) Register the interceptor
|
|
54
|
+
You can apply it globally or per-controller.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { APP_INTERCEPTOR } from '@nestjs/core';
|
|
58
|
+
import { AuditLogInterceptor } from '@elchinabilov/nestjs-audit-logs';
|
|
59
|
+
|
|
60
|
+
providers: [
|
|
61
|
+
{
|
|
62
|
+
provide: APP_INTERCEPTOR,
|
|
63
|
+
useClass: AuditLogInterceptor,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 4) Add metadata (optional)
|
|
69
|
+
```ts
|
|
70
|
+
import { AuditLog } from '@elchinabilov/nestjs-audit-logs';
|
|
71
|
+
|
|
72
|
+
@AuditLog({ module: 'users' })
|
|
73
|
+
@Get('users')
|
|
74
|
+
findAll() {}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 5) Set CLS values
|
|
78
|
+
The interceptor reads `userId`, `role`, `ip`, and `requestId` from the CLS context. Populate these values in a guard, middleware, or interceptor before the audit interceptor runs.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { Injectable, NestMiddleware } from '@nestjs/common';
|
|
82
|
+
import { ClsService } from 'nestjs-cls';
|
|
83
|
+
|
|
84
|
+
@Injectable()
|
|
85
|
+
export class AuditContextMiddleware implements NestMiddleware {
|
|
86
|
+
constructor(private readonly cls: ClsService) {}
|
|
87
|
+
|
|
88
|
+
use(req: any, res: any, next: () => void) {
|
|
89
|
+
this.cls.set('userId', req.user?.id);
|
|
90
|
+
this.cls.set('role', req.user?.role);
|
|
91
|
+
this.cls.set('ip', req.ip);
|
|
92
|
+
this.cls.set('requestId', req.headers['x-request-id']);
|
|
93
|
+
next();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Notes
|
|
99
|
+
- The module calls `ClsModule.forRoot({ global: true, middleware: { mount: true } })` internally.
|
|
100
|
+
- Logs are stored in the `audit_logs` table.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AuditLogService } from './audit-log.service';
|
|
2
|
+
import { AuditLogFilterDto } from './dto/audit-log-filter.dto';
|
|
3
|
+
export declare class AuditLogController {
|
|
4
|
+
private readonly service;
|
|
5
|
+
constructor(service: AuditLogService);
|
|
6
|
+
list(query: AuditLogFilterDto): Promise<import("./audit-log.entity").AuditLogEntity[]>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AuditLogController = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const audit_log_service_1 = require("./audit-log.service");
|
|
18
|
+
const audit_log_filter_dto_1 = require("./dto/audit-log-filter.dto");
|
|
19
|
+
let AuditLogController = class AuditLogController {
|
|
20
|
+
constructor(service) {
|
|
21
|
+
this.service = service;
|
|
22
|
+
}
|
|
23
|
+
async list(query) {
|
|
24
|
+
return this.service.find({
|
|
25
|
+
userId: query.userId,
|
|
26
|
+
module: query.module,
|
|
27
|
+
action: query.action,
|
|
28
|
+
from: query.from ? new Date(query.from) : undefined,
|
|
29
|
+
to: query.to ? new Date(query.to) : undefined,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.AuditLogController = AuditLogController;
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, common_1.Get)(),
|
|
36
|
+
__param(0, (0, common_1.Query)()),
|
|
37
|
+
__metadata("design:type", Function),
|
|
38
|
+
__metadata("design:paramtypes", [audit_log_filter_dto_1.AuditLogFilterDto]),
|
|
39
|
+
__metadata("design:returntype", Promise)
|
|
40
|
+
], AuditLogController.prototype, "list", null);
|
|
41
|
+
exports.AuditLogController = AuditLogController = __decorate([
|
|
42
|
+
(0, common_1.Controller)('admin/audit-logs'),
|
|
43
|
+
__metadata("design:paramtypes", [audit_log_service_1.AuditLogService])
|
|
44
|
+
], AuditLogController);
|
|
45
|
+
//# sourceMappingURL=audit-log.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log.controller.js","sourceRoot":"","sources":["../src/audit-log.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAwD;AACxD,2DAAsD;AACtD,qEAA+D;AAGxD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC9B,YAA6B,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;IAAG,CAAC;IAGnD,AAAN,KAAK,CAAC,IAAI,CAAU,KAAwB;QAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YACxB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;YACnD,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS;SAC7C,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AAbY,gDAAkB;AAIxB;IADL,IAAA,YAAG,GAAE;IACM,WAAA,IAAA,cAAK,GAAE,CAAA;;qCAAQ,wCAAiB;;8CAQ3C;6BAZW,kBAAkB;IAD9B,IAAA,mBAAU,EAAC,kBAAkB,CAAC;qCAEQ,mCAAe;GADzC,kBAAkB,CAa9B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuditLog = exports.AUDIT_LOG_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.AUDIT_LOG_KEY = 'audit_log';
|
|
6
|
+
const AuditLog = (meta) => (0, common_1.SetMetadata)(exports.AUDIT_LOG_KEY, meta);
|
|
7
|
+
exports.AuditLog = AuditLog;
|
|
8
|
+
//# sourceMappingURL=audit-log.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log.decorator.js","sourceRoot":"","sources":["../src/audit-log.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAEhC,QAAA,aAAa,GAAG,WAAW,CAAC;AAOlC,MAAM,QAAQ,GAAG,CAAC,IAAmB,EAAE,EAAE,CAC/C,IAAA,oBAAW,EAAC,qBAAa,EAAE,IAAI,CAAC,CAAC;AADrB,QAAA,QAAQ,YACa"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class AuditLogEntity {
|
|
2
|
+
id: string;
|
|
3
|
+
userId: string;
|
|
4
|
+
role: string;
|
|
5
|
+
module: string;
|
|
6
|
+
method: string;
|
|
7
|
+
endpoint: string;
|
|
8
|
+
payload?: Record<string, any>;
|
|
9
|
+
metadata?: Record<string, any>;
|
|
10
|
+
ip: string;
|
|
11
|
+
requestId: string;
|
|
12
|
+
createdAt: Date;
|
|
13
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuditLogEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
let AuditLogEntity = class AuditLogEntity {
|
|
15
|
+
};
|
|
16
|
+
exports.AuditLogEntity = AuditLogEntity;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
|
|
19
|
+
__metadata("design:type", String)
|
|
20
|
+
], AuditLogEntity.prototype, "id", void 0);
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, typeorm_1.Index)(),
|
|
23
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
24
|
+
__metadata("design:type", String)
|
|
25
|
+
], AuditLogEntity.prototype, "userId", void 0);
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, typeorm_1.Index)(),
|
|
28
|
+
(0, typeorm_1.Column)(),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], AuditLogEntity.prototype, "role", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, typeorm_1.Index)(),
|
|
33
|
+
(0, typeorm_1.Column)(),
|
|
34
|
+
__metadata("design:type", String)
|
|
35
|
+
], AuditLogEntity.prototype, "module", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, typeorm_1.Column)(),
|
|
38
|
+
__metadata("design:type", String)
|
|
39
|
+
], AuditLogEntity.prototype, "method", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
(0, typeorm_1.Column)(),
|
|
42
|
+
__metadata("design:type", String)
|
|
43
|
+
], AuditLogEntity.prototype, "endpoint", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, typeorm_1.Column)({ type: 'json', nullable: true }),
|
|
46
|
+
__metadata("design:type", Object)
|
|
47
|
+
], AuditLogEntity.prototype, "payload", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, typeorm_1.Column)({ type: 'json', nullable: true }),
|
|
50
|
+
__metadata("design:type", Object)
|
|
51
|
+
], AuditLogEntity.prototype, "metadata", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, typeorm_1.Column)(),
|
|
54
|
+
__metadata("design:type", String)
|
|
55
|
+
], AuditLogEntity.prototype, "ip", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, typeorm_1.Index)(),
|
|
58
|
+
(0, typeorm_1.Column)(),
|
|
59
|
+
__metadata("design:type", String)
|
|
60
|
+
], AuditLogEntity.prototype, "requestId", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, typeorm_1.CreateDateColumn)(),
|
|
63
|
+
__metadata("design:type", Date)
|
|
64
|
+
], AuditLogEntity.prototype, "createdAt", void 0);
|
|
65
|
+
exports.AuditLogEntity = AuditLogEntity = __decorate([
|
|
66
|
+
(0, typeorm_1.Entity)('audit_logs')
|
|
67
|
+
], AuditLogEntity);
|
|
68
|
+
//# sourceMappingURL=audit-log.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log.entity.js","sourceRoot":"","sources":["../src/audit-log.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAMiB;AAGV,IAAM,cAAc,GAApB,MAAM,cAAc;CAqC1B,CAAA;AArCY,wCAAc;AAE1B;IADC,IAAA,gCAAsB,EAAC,MAAM,CAAC;;0CACpB;AAIX;IAFC,IAAA,eAAK,GAAE;IACP,IAAA,gBAAM,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;8CACZ;AAIf;IAFC,IAAA,eAAK,GAAE;IACP,IAAA,gBAAM,GAAE;;4CACI;AAIb;IAFC,IAAA,eAAK,GAAE;IACP,IAAA,gBAAM,GAAE;;8CACM;AAGf;IADC,IAAA,gBAAM,GAAE;;8CACM;AAGf;IADC,IAAA,gBAAM,GAAE;;gDACQ;AAGjB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;+CACX;AAG9B;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;gDACV;AAG/B;IADC,IAAA,gBAAM,GAAE;;0CACE;AAIX;IAFC,IAAA,eAAK,GAAE;IACP,IAAA,gBAAM,GAAE;;iDACS;AAGlB;IADC,IAAA,0BAAgB,GAAE;8BACR,IAAI;iDAAC;yBApCJ,cAAc;IAD1B,IAAA,gBAAM,EAAC,YAAY,CAAC;GACR,cAAc,CAqC1B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from "@nestjs/common";
|
|
2
|
+
import { Reflector } from "@nestjs/core";
|
|
3
|
+
import { ClsService } from "nestjs-cls";
|
|
4
|
+
import { AuditLogService } from "./audit-log.service";
|
|
5
|
+
export declare class AuditLogInterceptor implements NestInterceptor {
|
|
6
|
+
private readonly reflector;
|
|
7
|
+
private readonly cls;
|
|
8
|
+
private readonly auditService;
|
|
9
|
+
constructor(reflector: Reflector, cls: ClsService, auditService: AuditLogService);
|
|
10
|
+
intercept(context: ExecutionContext, next: CallHandler): import("rxjs").Observable<any>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuditLogInterceptor = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const nestjs_cls_1 = require("nestjs-cls");
|
|
16
|
+
const operators_1 = require("rxjs/operators");
|
|
17
|
+
const audit_log_decorator_1 = require("./audit-log.decorator");
|
|
18
|
+
const audit_log_service_1 = require("./audit-log.service");
|
|
19
|
+
let AuditLogInterceptor = class AuditLogInterceptor {
|
|
20
|
+
constructor(reflector, cls, auditService) {
|
|
21
|
+
this.reflector = reflector;
|
|
22
|
+
this.cls = cls;
|
|
23
|
+
this.auditService = auditService;
|
|
24
|
+
}
|
|
25
|
+
intercept(context, next) {
|
|
26
|
+
const handler = context.getHandler();
|
|
27
|
+
const meta = this.reflector.get(audit_log_decorator_1.AUDIT_LOG_KEY, handler);
|
|
28
|
+
const request = context.switchToHttp().getRequest();
|
|
29
|
+
return next.handle().pipe((0, operators_1.tap)(async () => {
|
|
30
|
+
await this.auditService.create({
|
|
31
|
+
userId: this.cls.get("userId"),
|
|
32
|
+
role: this.cls.get("role"),
|
|
33
|
+
ip: this.cls.get("ip"),
|
|
34
|
+
requestId: this.cls.get("requestId"),
|
|
35
|
+
module: (meta?.module || request.originalUrl.split("/")[1]) ?? "unknown",
|
|
36
|
+
method: request.method,
|
|
37
|
+
endpoint: request.originalUrl,
|
|
38
|
+
payload: request.body,
|
|
39
|
+
});
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.AuditLogInterceptor = AuditLogInterceptor;
|
|
44
|
+
exports.AuditLogInterceptor = AuditLogInterceptor = __decorate([
|
|
45
|
+
(0, common_1.Injectable)(),
|
|
46
|
+
__metadata("design:paramtypes", [core_1.Reflector,
|
|
47
|
+
nestjs_cls_1.ClsService,
|
|
48
|
+
audit_log_service_1.AuditLogService])
|
|
49
|
+
], AuditLogInterceptor);
|
|
50
|
+
//# sourceMappingURL=audit-log.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log.interceptor.js","sourceRoot":"","sources":["../src/audit-log.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,uCAAyC;AACzC,2CAAwC;AACxC,8CAAqC;AACrC,+DAAoE;AACpE,2DAAsD;AAG/C,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,YACmB,SAAoB,EACpB,GAAe,EACf,YAA6B;QAF7B,cAAS,GAAT,SAAS,CAAW;QACpB,QAAG,GAAH,GAAG,CAAY;QACf,iBAAY,GAAZ,YAAY,CAAiB;IAC7C,CAAC;IAEJ,SAAS,CAAC,OAAyB,EAAE,IAAiB;QACpD,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAe,mCAAa,EAAE,OAAO,CAAC,CAAC;QAMtE,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QAEpD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CACvB,IAAA,eAAG,EAAC,KAAK,IAAI,EAAE;YACb,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;gBAC7B,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC;gBAC9B,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC;gBAC1B,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC;gBACtB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC;gBACpC,MAAM,EACJ,CAAC,IAAI,EAAE,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS;gBAClE,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,QAAQ,EAAE,OAAO,CAAC,WAAW;gBAC7B,OAAO,EAAE,OAAO,CAAC,IAAI;aACtB,CAAC,CAAC;QACL,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAA;AAjCY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;qCAGmB,gBAAS;QACf,uBAAU;QACD,mCAAe;GAJrC,mBAAmB,CAiC/B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AuditLogModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
12
|
+
const nestjs_cls_1 = require("nestjs-cls");
|
|
13
|
+
const audit_log_controller_1 = require("./audit-log.controller");
|
|
14
|
+
const audit_log_entity_1 = require("./audit-log.entity");
|
|
15
|
+
const audit_log_interceptor_1 = require("./audit-log.interceptor");
|
|
16
|
+
const audit_log_service_1 = require("./audit-log.service");
|
|
17
|
+
let AuditLogModule = class AuditLogModule {
|
|
18
|
+
};
|
|
19
|
+
exports.AuditLogModule = AuditLogModule;
|
|
20
|
+
exports.AuditLogModule = AuditLogModule = __decorate([
|
|
21
|
+
(0, common_1.Module)({
|
|
22
|
+
imports: [
|
|
23
|
+
typeorm_1.TypeOrmModule.forFeature([audit_log_entity_1.AuditLogEntity]),
|
|
24
|
+
nestjs_cls_1.ClsModule.forRoot({
|
|
25
|
+
global: true,
|
|
26
|
+
middleware: {
|
|
27
|
+
mount: true,
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
providers: [audit_log_service_1.AuditLogService, audit_log_interceptor_1.AuditLogInterceptor],
|
|
32
|
+
controllers: [audit_log_controller_1.AuditLogController],
|
|
33
|
+
exports: [audit_log_service_1.AuditLogService, audit_log_interceptor_1.AuditLogInterceptor],
|
|
34
|
+
})
|
|
35
|
+
], AuditLogModule);
|
|
36
|
+
//# sourceMappingURL=audit-log.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log.module.js","sourceRoot":"","sources":["../src/audit-log.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,6CAAgD;AAChD,2CAAuC;AACvC,iEAA4D;AAC5D,yDAAoD;AACpD,mEAA8D;AAC9D,2DAAsD;AAiB/C,IAAM,cAAc,GAApB,MAAM,cAAc;CAAG,CAAA;AAAjB,wCAAc;yBAAd,cAAc;IAf1B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,uBAAa,CAAC,UAAU,CAAC,CAAC,iCAAc,CAAC,CAAC;YAE1C,sBAAS,CAAC,OAAO,CAAC;gBAChB,MAAM,EAAE,IAAI;gBACZ,UAAU,EAAE;oBACV,KAAK,EAAE,IAAI;iBACZ;aACF,CAAC;SACH;QACD,SAAS,EAAE,CAAC,mCAAe,EAAE,2CAAmB,CAAC;QACjD,WAAW,EAAE,CAAC,yCAAkB,CAAC;QACjC,OAAO,EAAE,CAAC,mCAAe,EAAE,2CAAmB,CAAC;KAChD,CAAC;GACW,cAAc,CAAG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { AuditLogEntity } from './audit-log.entity';
|
|
3
|
+
export declare class AuditLogService {
|
|
4
|
+
private readonly repo;
|
|
5
|
+
constructor(repo: Repository<AuditLogEntity>);
|
|
6
|
+
create(data: Partial<AuditLogEntity>): Promise<void>;
|
|
7
|
+
find(filters: {
|
|
8
|
+
userId?: string;
|
|
9
|
+
module?: string;
|
|
10
|
+
action?: string;
|
|
11
|
+
from?: Date;
|
|
12
|
+
to?: Date;
|
|
13
|
+
}): Promise<AuditLogEntity[]>;
|
|
14
|
+
buildMetadataFromPayload(payload: any): {
|
|
15
|
+
payload: {};
|
|
16
|
+
fields: string[];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AuditLogService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
18
|
+
const typeorm_2 = require("typeorm");
|
|
19
|
+
const audit_log_entity_1 = require("./audit-log.entity");
|
|
20
|
+
let AuditLogService = class AuditLogService {
|
|
21
|
+
constructor(repo) {
|
|
22
|
+
this.repo = repo;
|
|
23
|
+
}
|
|
24
|
+
async create(data) {
|
|
25
|
+
const log = this.repo.create(data);
|
|
26
|
+
await this.repo.save(log);
|
|
27
|
+
}
|
|
28
|
+
async find(filters) {
|
|
29
|
+
const qb = this.repo.createQueryBuilder('log');
|
|
30
|
+
if (filters.userId) {
|
|
31
|
+
qb.andWhere('log.userId = :userId', { userId: filters.userId });
|
|
32
|
+
}
|
|
33
|
+
if (filters.module) {
|
|
34
|
+
qb.andWhere('log.module = :module', { module: filters.module });
|
|
35
|
+
}
|
|
36
|
+
if (filters.action) {
|
|
37
|
+
qb.andWhere('log.action = :action', { action: filters.action });
|
|
38
|
+
}
|
|
39
|
+
if (filters.from && filters.to) {
|
|
40
|
+
qb.andWhere('log.createdAt BETWEEN :from AND :to', {
|
|
41
|
+
from: filters.from,
|
|
42
|
+
to: filters.to,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return qb.orderBy('log.createdAt', 'DESC').getMany();
|
|
46
|
+
}
|
|
47
|
+
buildMetadataFromPayload(payload) {
|
|
48
|
+
if (!payload || typeof payload !== 'object')
|
|
49
|
+
return undefined;
|
|
50
|
+
const safePayload = {};
|
|
51
|
+
for (const key of Object.keys(payload)) {
|
|
52
|
+
safePayload[key] = payload[key];
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
payload: safePayload,
|
|
56
|
+
fields: Object.keys(safePayload),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.AuditLogService = AuditLogService;
|
|
61
|
+
exports.AuditLogService = AuditLogService = __decorate([
|
|
62
|
+
(0, common_1.Injectable)(),
|
|
63
|
+
__param(0, (0, typeorm_1.InjectRepository)(audit_log_entity_1.AuditLogEntity)),
|
|
64
|
+
__metadata("design:paramtypes", [typeorm_2.Repository])
|
|
65
|
+
], AuditLogService);
|
|
66
|
+
//# sourceMappingURL=audit-log.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log.service.js","sourceRoot":"","sources":["../src/audit-log.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6CAAmD;AACnD,qCAAqC;AACrC,yDAAoD;AAG7C,IAAM,eAAe,GAArB,MAAM,eAAe;IAC3B,YAEkB,IAAgC;QAAhC,SAAI,GAAJ,IAAI,CAA4B;IAC/C,CAAC;IAEJ,KAAK,CAAC,MAAM,CAAC,IAA6B;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACnC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAMV;QACA,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAE/C,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,EAAE,CAAC,QAAQ,CAAC,sBAAsB,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACjE,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,EAAE,CAAC,QAAQ,CAAC,sBAAsB,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACjE,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,EAAE,CAAC,QAAQ,CAAC,sBAAsB,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACjE,CAAC;QAED,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;YAChC,EAAE,CAAC,QAAQ,CAAC,qCAAqC,EAAE;gBAClD,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,EAAE,EAAE,OAAO,CAAC,EAAE;aACd,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;IACtD,CAAC;IAED,wBAAwB,CAAC,OAAY;QACpC,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QAE9D,MAAM,WAAW,GAAG,EAAE,CAAC;QAEvB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAGxC,WAAW,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QACjC,CAAC;QAED,OAAO;YACN,OAAO,EAAE,WAAW;YACpB,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;SAChC,CAAC;IACH,CAAC;CACD,CAAA;AA1DY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAGV,WAAA,IAAA,0BAAgB,EAAC,iCAAc,CAAC,CAAA;qCACV,oBAAU;GAHtB,eAAe,CA0D3B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NestMiddleware } from "@nestjs/common";
|
|
2
|
+
import { Request, Response, NextFunction } from "express";
|
|
3
|
+
import { ClsService } from "nestjs-cls";
|
|
4
|
+
export declare class ClsMiddleware implements NestMiddleware {
|
|
5
|
+
private readonly cls;
|
|
6
|
+
constructor(cls: ClsService);
|
|
7
|
+
use(req: Request, res: Response, next: NextFunction): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ClsMiddleware = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const nestjs_cls_1 = require("nestjs-cls");
|
|
15
|
+
let ClsMiddleware = class ClsMiddleware {
|
|
16
|
+
constructor(cls) {
|
|
17
|
+
this.cls = cls;
|
|
18
|
+
}
|
|
19
|
+
use(req, res, next) {
|
|
20
|
+
this.cls.run(() => {
|
|
21
|
+
next();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.ClsMiddleware = ClsMiddleware;
|
|
26
|
+
exports.ClsMiddleware = ClsMiddleware = __decorate([
|
|
27
|
+
(0, common_1.Injectable)(),
|
|
28
|
+
__metadata("design:paramtypes", [nestjs_cls_1.ClsService])
|
|
29
|
+
], ClsMiddleware);
|
|
30
|
+
//# sourceMappingURL=cls.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cls.middleware.js","sourceRoot":"","sources":["../src/cls.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4D;AAE5D,2CAAwC;AAGjC,IAAM,aAAa,GAAnB,MAAM,aAAa;IACxB,YAA6B,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;IAAG,CAAC;IAEhD,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;QAEjD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE;YAChB,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AATY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;qCAEuB,uBAAU;GADjC,aAAa,CASzB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NestMiddleware } from "@nestjs/common";
|
|
2
|
+
import { NextFunction, Response } from "express";
|
|
3
|
+
import { ClsService } from "nestjs-cls";
|
|
4
|
+
export declare class AuditContextMiddleware implements NestMiddleware {
|
|
5
|
+
private readonly cls;
|
|
6
|
+
constructor(cls: ClsService);
|
|
7
|
+
use(req: any, res: Response, next: NextFunction): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuditContextMiddleware = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const nestjs_cls_1 = require("nestjs-cls");
|
|
15
|
+
let AuditContextMiddleware = class AuditContextMiddleware {
|
|
16
|
+
constructor(cls) {
|
|
17
|
+
this.cls = cls;
|
|
18
|
+
}
|
|
19
|
+
use(req, res, next) {
|
|
20
|
+
if (req.user) {
|
|
21
|
+
this.cls.set("userId", req.user.id);
|
|
22
|
+
this.cls.set("role", req.user.role);
|
|
23
|
+
}
|
|
24
|
+
this.cls.set("ip", req.ip);
|
|
25
|
+
if (req.headers["x-request-id"]) {
|
|
26
|
+
this.cls.set("requestId", req.headers["x-request-id"]);
|
|
27
|
+
}
|
|
28
|
+
next();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.AuditContextMiddleware = AuditContextMiddleware;
|
|
32
|
+
exports.AuditContextMiddleware = AuditContextMiddleware = __decorate([
|
|
33
|
+
(0, common_1.Injectable)(),
|
|
34
|
+
__metadata("design:paramtypes", [nestjs_cls_1.ClsService])
|
|
35
|
+
], AuditContextMiddleware);
|
|
36
|
+
//# sourceMappingURL=audit-context.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-context.middleware.js","sourceRoot":"","sources":["../../src/context/audit-context.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4D;AAE5D,2CAAwC;AAGjC,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,YAA6B,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;IAAG,CAAC;IAEhD,GAAG,CAAC,GAAQ,EAAE,GAAa,EAAE,IAAkB;QAC7C,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;YACb,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACpC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtC,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAE3B,IAAI,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YAChC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,EAAE,CAAC;IACT,CAAC;CACF,CAAA;AAjBY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;qCAEuB,uBAAU;GADjC,sBAAsB,CAiBlC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuditLogFilterDto = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
class AuditLogFilterDto {
|
|
15
|
+
}
|
|
16
|
+
exports.AuditLogFilterDto = AuditLogFilterDto;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, class_validator_1.IsOptional)(),
|
|
19
|
+
(0, class_validator_1.IsString)(),
|
|
20
|
+
__metadata("design:type", String)
|
|
21
|
+
], AuditLogFilterDto.prototype, "userId", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, class_validator_1.IsOptional)(),
|
|
24
|
+
(0, class_validator_1.IsString)(),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], AuditLogFilterDto.prototype, "module", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, class_validator_1.IsOptional)(),
|
|
29
|
+
(0, class_validator_1.IsString)(),
|
|
30
|
+
__metadata("design:type", String)
|
|
31
|
+
], AuditLogFilterDto.prototype, "action", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, class_validator_1.IsOptional)(),
|
|
34
|
+
(0, class_validator_1.IsDateString)(),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], AuditLogFilterDto.prototype, "from", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, class_validator_1.IsOptional)(),
|
|
39
|
+
(0, class_validator_1.IsDateString)(),
|
|
40
|
+
__metadata("design:type", String)
|
|
41
|
+
], AuditLogFilterDto.prototype, "to", void 0);
|
|
42
|
+
//# sourceMappingURL=audit-log-filter.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log-filter.dto.js","sourceRoot":"","sources":["../../src/dto/audit-log-filter.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAqE;AAErE,MAAa,iBAAiB;CAoB7B;AApBD,8CAoBC;AAjBA;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;iDACK;AAIhB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;iDACK;AAIhB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;iDACK;AAIhB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,8BAAY,GAAE;;+CACD;AAId;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,8BAAY,GAAE;;6CACH"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./audit-log.module";
|
|
2
|
+
export * from "./audit-log.decorator";
|
|
3
|
+
export * from "./audit-log.entity";
|
|
4
|
+
export * from "./audit-log.service";
|
|
5
|
+
export * from "./audit-log.interceptor";
|
|
6
|
+
export * from "./audit-log.controller";
|
|
7
|
+
export * from "./cls.middleware";
|
|
8
|
+
export * from "./dto/audit-log-filter.dto";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./audit-log.module"), exports);
|
|
18
|
+
__exportStar(require("./audit-log.decorator"), exports);
|
|
19
|
+
__exportStar(require("./audit-log.entity"), exports);
|
|
20
|
+
__exportStar(require("./audit-log.service"), exports);
|
|
21
|
+
__exportStar(require("./audit-log.interceptor"), exports);
|
|
22
|
+
__exportStar(require("./audit-log.controller"), exports);
|
|
23
|
+
__exportStar(require("./cls.middleware"), exports);
|
|
24
|
+
__exportStar(require("./dto/audit-log-filter.dto"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,wDAAsC;AACtC,qDAAmC;AACnC,sDAAoC;AACpC,0DAAwC;AACxC,yDAAuC;AACvC,mDAAiC;AACjC,6DAA2C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NestMiddleware } from "@nestjs/common";
|
|
2
|
+
import { Request, Response, NextFunction } from "express";
|
|
3
|
+
import { ClsService } from "nestjs-cls";
|
|
4
|
+
export declare class ClsMiddleware implements NestMiddleware {
|
|
5
|
+
private readonly cls;
|
|
6
|
+
constructor(cls: ClsService);
|
|
7
|
+
use(req: Request, res: Response, next: NextFunction): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ClsMiddleware = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const nestjs_cls_1 = require("nestjs-cls");
|
|
15
|
+
let ClsMiddleware = class ClsMiddleware {
|
|
16
|
+
constructor(cls) {
|
|
17
|
+
this.cls = cls;
|
|
18
|
+
}
|
|
19
|
+
use(req, res, next) {
|
|
20
|
+
this.cls.run(() => {
|
|
21
|
+
next();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.ClsMiddleware = ClsMiddleware;
|
|
26
|
+
exports.ClsMiddleware = ClsMiddleware = __decorate([
|
|
27
|
+
(0, common_1.Injectable)(),
|
|
28
|
+
__metadata("design:paramtypes", [nestjs_cls_1.ClsService])
|
|
29
|
+
], ClsMiddleware);
|
|
30
|
+
//# sourceMappingURL=cls.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cls.middleware.js","sourceRoot":"","sources":["../../src/middleware/cls.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4D;AAE5D,2CAAwC;AAGjC,IAAM,aAAa,GAAnB,MAAM,aAAa;IACxB,YAA6B,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;IAAG,CAAC;IAEhD,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;QAEjD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE;YAChB,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AATY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;qCAEuB,uBAAU;GADjC,aAAa,CASzB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elchinabilov/nestjs-audit-logs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "NestJS audit log module with TypeORM and CLS context",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.json",
|
|
20
|
+
"prepublishOnly": "npm run build"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"nestjs",
|
|
24
|
+
"audit",
|
|
25
|
+
"audit-log",
|
|
26
|
+
"typeorm",
|
|
27
|
+
"cls"
|
|
28
|
+
],
|
|
29
|
+
"author": "Elchin Abilov",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@types/express": "^5.0.6",
|
|
36
|
+
"express": "^5.2.1",
|
|
37
|
+
"nestjs-cls": "^6.2.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@nestjs/common": "^10.0.0",
|
|
41
|
+
"@nestjs/core": "^10.0.0",
|
|
42
|
+
"@nestjs/typeorm": "^11.0.0",
|
|
43
|
+
"class-validator": "^0.14.0",
|
|
44
|
+
"rxjs": "^7.8.0",
|
|
45
|
+
"typeorm": "^0.3.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@nestjs/common": "^10.0.0",
|
|
49
|
+
"@nestjs/core": "^10.0.0",
|
|
50
|
+
"@nestjs/typeorm": "^11.0.0",
|
|
51
|
+
"@types/node": "^20.0.0",
|
|
52
|
+
"class-validator": "^0.14.0",
|
|
53
|
+
"rxjs": "^7.8.0",
|
|
54
|
+
"typeorm": "^0.3.0",
|
|
55
|
+
"typescript": "^5.0.0"
|
|
56
|
+
}
|
|
57
|
+
}
|