@zola_do/audit 0.2.15 → 0.2.17
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 +33 -2
- package/dist/audit-logger.interceptor.d.ts +3 -3
- package/dist/audit-logger.interceptor.js +24 -16
- package/dist/audit-logger.interceptor.js.map +1 -1
- package/dist/audit-module-options.d.ts +12 -0
- package/dist/audit-module-options.js +14 -0
- package/dist/audit-module-options.js.map +1 -1
- package/dist/audit-redaction.helper.d.ts +5 -0
- package/dist/audit-redaction.helper.js +78 -0
- package/dist/audit-redaction.helper.js.map +1 -0
- package/dist/audit-rmq-readiness.d.ts +6 -0
- package/dist/audit-rmq-readiness.js +61 -0
- package/dist/audit-rmq-readiness.js.map +1 -0
- package/dist/audit.constants.d.ts +1 -0
- package/dist/audit.constants.js +2 -1
- package/dist/audit.constants.js.map +1 -1
- package/dist/audit.module.js +18 -42
- package/dist/audit.module.js.map +1 -1
- package/dist/audit.subscriber.d.ts +3 -1
- package/dist/audit.subscriber.js +16 -4
- package/dist/audit.subscriber.js.map +1 -1
- package/dist/get-client-ip.helper.d.ts +12 -0
- package/dist/get-client-ip.helper.js +26 -0
- package/dist/get-client-ip.helper.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/request-id.interceptor.d.ts +6 -0
- package/dist/request-id.interceptor.js +30 -0
- package/dist/request-id.interceptor.js.map +1 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ RabbitMQ-based audit logging for NestJS applications with entity change tracking
|
|
|
15
15
|
- **Entity Auditing** — TypeORM subscriber for INSERT/UPDATE/DELETE
|
|
16
16
|
- **Conditional Loading** — Gracefully degrades without RabbitMQ
|
|
17
17
|
- **User Context** — Captures user and organization from request
|
|
18
|
+
- **Request correlation** — Optional `RequestIdInterceptor` for `x-request-id` / `req.requestId`
|
|
18
19
|
|
|
19
20
|
## Installation
|
|
20
21
|
|
|
@@ -31,9 +32,11 @@ npm install @zola_do/nestjs-shared
|
|
|
31
32
|
For full audit functionality:
|
|
32
33
|
|
|
33
34
|
```bash
|
|
34
|
-
npm install @nestjs/microservices amqplib
|
|
35
|
+
npm install @nestjs/microservices amqplib amqp-connection-manager
|
|
35
36
|
```
|
|
36
37
|
|
|
38
|
+
Set `RMQ_URL` in the environment. Without it (or without the packages above), `AuditModule` loads safely but RabbitMQ audit is disabled.
|
|
39
|
+
|
|
37
40
|
**Note:** The module loads successfully without these dependencies but audit features are disabled with a development warning.
|
|
38
41
|
|
|
39
42
|
## Quick Start
|
|
@@ -53,11 +56,39 @@ import { Module } from '@nestjs/common';
|
|
|
53
56
|
import { AuditModule } from '@zola_do/audit';
|
|
54
57
|
|
|
55
58
|
@Module({
|
|
56
|
-
imports: [AuditModule],
|
|
59
|
+
imports: [AuditModule.forRoot()],
|
|
57
60
|
})
|
|
58
61
|
export class AppModule {}
|
|
59
62
|
```
|
|
60
63
|
|
|
64
|
+
### Request correlation (optional)
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { RequestIdInterceptor } from '@zola_do/audit';
|
|
68
|
+
|
|
69
|
+
app.useGlobalInterceptors(new RequestIdInterceptor());
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Preserves incoming `x-request-id` or generates one; sets `req.requestId` for structured logs and audit correlation.
|
|
73
|
+
|
|
74
|
+
### Optional: extra sinks and redaction
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
AuditModule.forRoot({
|
|
78
|
+
extraSinks: [
|
|
79
|
+
async (log) => {
|
|
80
|
+
// e.g. stdout in local dev, secondary queue, or observability bridge
|
|
81
|
+
console.log(JSON.stringify(log));
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
sensitiveBodyFields: ['password', 'token', 'refresh_token'],
|
|
85
|
+
sensitiveColumns: ['passwordHash', 'ssn'],
|
|
86
|
+
logSqlParameters: false, // default — omit bind params from SQL audit events
|
|
87
|
+
})
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
By default, audit payloads redact `authorization`, `x-api-key`, cookies (names only), and common secret body fields before RabbitMQ emit.
|
|
91
|
+
|
|
61
92
|
### 3. Mark Routes for Audit
|
|
62
93
|
|
|
63
94
|
```typescript
|
|
@@ -3,18 +3,18 @@ import { Reflector } from '@nestjs/core';
|
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
4
|
import { ClientProxy } from '@nestjs/microservices';
|
|
5
5
|
import { DataSource } from 'typeorm';
|
|
6
|
-
import type { AuditLogSink } from './audit-module-options';
|
|
6
|
+
import type { AuditLogSink, NormalizedAuditModuleOptions } from './audit-module-options';
|
|
7
7
|
export declare class AuditLoggerInterceptor implements NestInterceptor {
|
|
8
8
|
private reflector;
|
|
9
9
|
private readonly connection;
|
|
10
10
|
private readonly rmsRMQClient;
|
|
11
11
|
private readonly extraSinks;
|
|
12
|
-
|
|
12
|
+
private readonly moduleOptions;
|
|
13
|
+
constructor(reflector: Reflector, connection: DataSource, rmsRMQClient: ClientProxy, extraSinks?: AuditLogSink[], moduleOptions?: NormalizedAuditModuleOptions);
|
|
13
14
|
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
14
15
|
private handleRequestAuditInitiation;
|
|
15
16
|
private handleEventAuditInitiation;
|
|
16
17
|
private handleTransaction;
|
|
17
18
|
private mapHeaders;
|
|
18
|
-
private mapCookies;
|
|
19
19
|
private notifyExtraSinks;
|
|
20
20
|
}
|
|
@@ -23,12 +23,20 @@ const event_audit_decorator_1 = require("./event-audit.decorator");
|
|
|
23
23
|
const audit_logger_enum_1 = require("./audit-logger.enum");
|
|
24
24
|
const ignore_logger_decorator_1 = require("./ignore-logger.decorator");
|
|
25
25
|
const audit_constants_1 = require("./audit.constants");
|
|
26
|
+
const get_client_ip_helper_1 = require("./get-client-ip.helper");
|
|
27
|
+
const audit_redaction_helper_1 = require("./audit-redaction.helper");
|
|
26
28
|
let AuditLoggerInterceptor = class AuditLoggerInterceptor {
|
|
27
|
-
constructor(reflector, connection, rmsRMQClient, extraSinks = []
|
|
29
|
+
constructor(reflector, connection, rmsRMQClient, extraSinks = [], moduleOptions = {
|
|
30
|
+
extraSinks: [],
|
|
31
|
+
sensitiveBodyFields: [],
|
|
32
|
+
sensitiveColumns: [],
|
|
33
|
+
logSqlParameters: false,
|
|
34
|
+
}) {
|
|
28
35
|
this.reflector = reflector;
|
|
29
36
|
this.connection = connection;
|
|
30
37
|
this.rmsRMQClient = rmsRMQClient;
|
|
31
38
|
this.extraSinks = extraSinks;
|
|
39
|
+
this.moduleOptions = moduleOptions;
|
|
32
40
|
}
|
|
33
41
|
intercept(context, next) {
|
|
34
42
|
const auditRmqEvent = this.reflector.getAllAndOverride(event_audit_decorator_1.AUDIT_RMQ_EVENT, [context.getHandler(), context.getClass()]);
|
|
@@ -61,7 +69,7 @@ let AuditLoggerInterceptor = class AuditLoggerInterceptor {
|
|
|
61
69
|
handleRequestAuditInitiation(context, next, requestId) {
|
|
62
70
|
var _a, _b;
|
|
63
71
|
const req = context.switchToHttp().getRequest();
|
|
64
|
-
const {
|
|
72
|
+
const { method, originalUrl, headers, body, params, user } = req;
|
|
65
73
|
const userPayload = (this.connection['user'] = {
|
|
66
74
|
id: user === null || user === void 0 ? void 0 : user.id,
|
|
67
75
|
name: `${user === null || user === void 0 ? void 0 : user.firstName} ${user === null || user === void 0 ? void 0 : user.lastName}`,
|
|
@@ -73,10 +81,12 @@ let AuditLoggerInterceptor = class AuditLoggerInterceptor {
|
|
|
73
81
|
requestMethod: method,
|
|
74
82
|
application: process.env.APPLICATION_NAME,
|
|
75
83
|
module: originalUrl.split('/')[2],
|
|
76
|
-
requestBody: originalUrl.includes('/auth')
|
|
84
|
+
requestBody: originalUrl.includes('/auth')
|
|
85
|
+
? {}
|
|
86
|
+
: (0, audit_redaction_helper_1.redactBody)(body, this.moduleOptions.sensitiveBodyFields),
|
|
77
87
|
requestHeader: this.mapHeaders(headers),
|
|
78
88
|
statusCode: 201,
|
|
79
|
-
ipAddress: (
|
|
89
|
+
ipAddress: (0, get_client_ip_helper_1.getClientIp)(req),
|
|
80
90
|
executionTime: 0,
|
|
81
91
|
user: userPayload,
|
|
82
92
|
};
|
|
@@ -92,7 +102,7 @@ let AuditLoggerInterceptor = class AuditLoggerInterceptor {
|
|
|
92
102
|
requestMethod: audit_logger_enum_1.EAuditLogRequestMethod.EVENT,
|
|
93
103
|
application: process.env.APPLICATION_NAME,
|
|
94
104
|
module: eventPattern,
|
|
95
|
-
requestBody: eventPayload,
|
|
105
|
+
requestBody: (0, audit_redaction_helper_1.redactBody)(eventPayload, this.moduleOptions.sensitiveBodyFields),
|
|
96
106
|
requestHeader: {},
|
|
97
107
|
statusCode: 201,
|
|
98
108
|
ipAddress: '-',
|
|
@@ -113,21 +123,17 @@ let AuditLoggerInterceptor = class AuditLoggerInterceptor {
|
|
|
113
123
|
this.rmsRMQClient.emit(type == 'Commit' ? audit_logger_enum_1.CommitRequestAudit : audit_logger_enum_1.RollbackRequestAudit, approvePayload);
|
|
114
124
|
}
|
|
115
125
|
mapHeaders(headers) {
|
|
116
|
-
return
|
|
117
|
-
}
|
|
118
|
-
mapCookies(cookie) {
|
|
119
|
-
return cookie.split(';').reduce((acc, cookie) => {
|
|
120
|
-
const [key] = cookie.split('=').map((part) => part.trim());
|
|
121
|
-
acc.push(key);
|
|
122
|
-
return acc;
|
|
123
|
-
}, []);
|
|
126
|
+
return (0, audit_redaction_helper_1.redactHeaders)(headers);
|
|
124
127
|
}
|
|
125
128
|
notifyExtraSinks(log) {
|
|
126
129
|
var _a;
|
|
127
|
-
|
|
130
|
+
const sinks = ((_a = this.extraSinks) === null || _a === void 0 ? void 0 : _a.length)
|
|
131
|
+
? this.extraSinks
|
|
132
|
+
: this.moduleOptions.extraSinks;
|
|
133
|
+
if (!(sinks === null || sinks === void 0 ? void 0 : sinks.length)) {
|
|
128
134
|
return;
|
|
129
135
|
}
|
|
130
|
-
for (const sink of
|
|
136
|
+
for (const sink of sinks) {
|
|
131
137
|
try {
|
|
132
138
|
void Promise.resolve(sink(log)).catch(() => undefined);
|
|
133
139
|
}
|
|
@@ -142,8 +148,10 @@ exports.AuditLoggerInterceptor = AuditLoggerInterceptor = __decorate([
|
|
|
142
148
|
__param(2, (0, common_1.Inject)(audit_logger_enum_1.AuditLoggerRMQClient)),
|
|
143
149
|
__param(3, (0, common_1.Optional)()),
|
|
144
150
|
__param(3, (0, common_1.Inject)(audit_constants_1.AUDIT_EXTRA_SINKS)),
|
|
151
|
+
__param(4, (0, common_1.Optional)()),
|
|
152
|
+
__param(4, (0, common_1.Inject)(audit_constants_1.AUDIT_MODULE_OPTIONS)),
|
|
145
153
|
__metadata("design:paramtypes", [core_1.Reflector,
|
|
146
154
|
typeorm_1.DataSource,
|
|
147
|
-
microservices_1.ClientProxy, Array])
|
|
155
|
+
microservices_1.ClientProxy, Array, Object])
|
|
148
156
|
], AuditLoggerInterceptor);
|
|
149
157
|
//# sourceMappingURL=audit-logger.interceptor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-logger.interceptor.js","sourceRoot":"","sources":["../src/audit-logger.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAOwB;AACxB,uCAAyC;AACzC,+BAA6D;AAC7D,yDAAoD;AACpD,qCAAqC;AACrC,mCAAoC;AAEpC,mEAA0D;AAC1D,2DAM6B;AAC7B,uEAAgE;AAChE,
|
|
1
|
+
{"version":3,"file":"audit-logger.interceptor.js","sourceRoot":"","sources":["../src/audit-logger.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAOwB;AACxB,uCAAyC;AACzC,+BAA6D;AAC7D,yDAAoD;AACpD,qCAAqC;AACrC,mCAAoC;AAEpC,mEAA0D;AAC1D,2DAM6B;AAC7B,uEAAgE;AAChE,uDAA4E;AAK5E,iEAAqD;AACrD,qEAAqE;AAG9D,IAAM,sBAAsB,GAA5B,MAAM,sBAAs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C,UAAU,CAAC;QAClC,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,CAAA,EAAE,CAAC;YACnB,OAAO;QACT,CAAC;QACD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC;gBACH,KAAK,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YACzD,CAAC;YAAC,WAAM,CAAC;YAET,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAA;AA/KY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,wCAAoB,CAAC,CAAA;IAE5B,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,mCAAiB,CAAC,CAAA;IAEzB,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,sCAAoB,CAAC,CAAA;qCARV,gBAAS;QACC,oBAAU;QAER,2BAAW;GALjC,sBAAsB,CA+KlC"}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import type { CreateAuditLogDto } from './audit.dto';
|
|
2
|
+
import { DEFAULT_SENSITIVE_BODY_FIELDS, DEFAULT_SENSITIVE_HEADER_KEYS } from './audit-redaction.helper';
|
|
2
3
|
export type AuditLogSink = (log: CreateAuditLogDto) => void | Promise<void>;
|
|
3
4
|
export type AuditModuleRootOptions = {
|
|
4
5
|
extraSinks?: AuditLogSink[];
|
|
6
|
+
sensitiveBodyFields?: string[];
|
|
7
|
+
sensitiveColumns?: string[];
|
|
8
|
+
logSqlParameters?: boolean;
|
|
5
9
|
};
|
|
10
|
+
export type NormalizedAuditModuleOptions = {
|
|
11
|
+
extraSinks: AuditLogSink[];
|
|
12
|
+
sensitiveBodyFields: string[];
|
|
13
|
+
sensitiveColumns: string[];
|
|
14
|
+
logSqlParameters: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare function normalizeAuditModuleOptions(options?: AuditModuleRootOptions): NormalizedAuditModuleOptions;
|
|
17
|
+
export { DEFAULT_SENSITIVE_BODY_FIELDS, DEFAULT_SENSITIVE_HEADER_KEYS };
|
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_SENSITIVE_HEADER_KEYS = exports.DEFAULT_SENSITIVE_BODY_FIELDS = void 0;
|
|
4
|
+
exports.normalizeAuditModuleOptions = normalizeAuditModuleOptions;
|
|
5
|
+
const audit_redaction_helper_1 = require("./audit-redaction.helper");
|
|
6
|
+
Object.defineProperty(exports, "DEFAULT_SENSITIVE_BODY_FIELDS", { enumerable: true, get: function () { return audit_redaction_helper_1.DEFAULT_SENSITIVE_BODY_FIELDS; } });
|
|
7
|
+
Object.defineProperty(exports, "DEFAULT_SENSITIVE_HEADER_KEYS", { enumerable: true, get: function () { return audit_redaction_helper_1.DEFAULT_SENSITIVE_HEADER_KEYS; } });
|
|
8
|
+
function normalizeAuditModuleOptions(options = {}) {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
return {
|
|
11
|
+
extraSinks: (_a = options.extraSinks) !== null && _a !== void 0 ? _a : [],
|
|
12
|
+
sensitiveBodyFields: (_b = options.sensitiveBodyFields) !== null && _b !== void 0 ? _b : audit_redaction_helper_1.DEFAULT_SENSITIVE_BODY_FIELDS,
|
|
13
|
+
sensitiveColumns: (_c = options.sensitiveColumns) !== null && _c !== void 0 ? _c : [],
|
|
14
|
+
logSqlParameters: options.logSqlParameters === true,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
3
17
|
//# sourceMappingURL=audit-module-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-module-options.js","sourceRoot":"","sources":["../src/audit-module-options.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"audit-module-options.js","sourceRoot":"","sources":["../src/audit-module-options.ts"],"names":[],"mappings":";;;AA8BA,kEAUC;AAvCD,qEAGkC;AAsCzB,8GAxCP,sDAA6B,OAwCO;AAAE,8GAvCtC,sDAA6B,OAuCsC;AAZrE,SAAgB,2BAA2B,CACzC,UAAkC,EAAE;;IAEpC,OAAO;QACL,UAAU,EAAE,MAAA,OAAO,CAAC,UAAU,mCAAI,EAAE;QACpC,mBAAmB,EACjB,MAAA,OAAO,CAAC,mBAAmB,mCAAI,sDAA6B;QAC9D,gBAAgB,EAAE,MAAA,OAAO,CAAC,gBAAgB,mCAAI,EAAE;QAChD,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,KAAK,IAAI;KACpD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const DEFAULT_SENSITIVE_BODY_FIELDS: string[];
|
|
2
|
+
export declare const DEFAULT_SENSITIVE_HEADER_KEYS: string[];
|
|
3
|
+
export declare function redactHeaders(headers: Record<string, unknown> | undefined, sensitiveKeys?: string[]): Record<string, unknown>;
|
|
4
|
+
export declare function redactBody(body: Record<string, unknown> | undefined, sensitiveFields?: string[]): Record<string, unknown>;
|
|
5
|
+
export declare function redactEntity(entity: Record<string, unknown> | undefined, sensitiveColumns?: string[]): Record<string, unknown> | undefined;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_SENSITIVE_HEADER_KEYS = exports.DEFAULT_SENSITIVE_BODY_FIELDS = void 0;
|
|
4
|
+
exports.redactHeaders = redactHeaders;
|
|
5
|
+
exports.redactBody = redactBody;
|
|
6
|
+
exports.redactEntity = redactEntity;
|
|
7
|
+
exports.DEFAULT_SENSITIVE_BODY_FIELDS = [
|
|
8
|
+
'password',
|
|
9
|
+
'token',
|
|
10
|
+
'secret',
|
|
11
|
+
'refresh_token',
|
|
12
|
+
'refreshToken',
|
|
13
|
+
'apiKey',
|
|
14
|
+
'api_key',
|
|
15
|
+
'accessToken',
|
|
16
|
+
'access_token',
|
|
17
|
+
];
|
|
18
|
+
exports.DEFAULT_SENSITIVE_HEADER_KEYS = [
|
|
19
|
+
'authorization',
|
|
20
|
+
'cookie',
|
|
21
|
+
'x-api-key',
|
|
22
|
+
'x-auth-token',
|
|
23
|
+
'proxy-authorization',
|
|
24
|
+
];
|
|
25
|
+
function redactHeaders(headers, sensitiveKeys = exports.DEFAULT_SENSITIVE_HEADER_KEYS) {
|
|
26
|
+
if (!headers) {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
const normalizedSensitive = new Set(sensitiveKeys.map((key) => key.toLowerCase()));
|
|
30
|
+
const result = {};
|
|
31
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
32
|
+
const lowerKey = key.toLowerCase();
|
|
33
|
+
if (!normalizedSensitive.has(lowerKey)) {
|
|
34
|
+
result[key] = value;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (lowerKey === 'authorization' && value) {
|
|
38
|
+
result[key] = 'Bearer [REDACTED]';
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (lowerKey === 'cookie' && typeof value === 'string') {
|
|
42
|
+
result[key] = value.split(';').map((part) => { var _a; return (_a = part.split('=')[0]) === null || _a === void 0 ? void 0 : _a.trim(); });
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
result[key] = '[REDACTED]';
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
function redactBody(body, sensitiveFields = exports.DEFAULT_SENSITIVE_BODY_FIELDS) {
|
|
50
|
+
if (!body || typeof body !== 'object') {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
const sensitive = new Set(sensitiveFields.map((field) => field.toLowerCase()));
|
|
54
|
+
const result = Object.assign({}, body);
|
|
55
|
+
for (const key of Object.keys(result)) {
|
|
56
|
+
if (sensitive.has(key.toLowerCase())) {
|
|
57
|
+
result[key] = '[REDACTED]';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
function redactEntity(entity, sensitiveColumns = []) {
|
|
63
|
+
if (!entity || typeof entity !== 'object') {
|
|
64
|
+
return entity;
|
|
65
|
+
}
|
|
66
|
+
if (!sensitiveColumns.length) {
|
|
67
|
+
return entity;
|
|
68
|
+
}
|
|
69
|
+
const sensitive = new Set(sensitiveColumns.map((column) => column.toLowerCase()));
|
|
70
|
+
const result = Object.assign({}, entity);
|
|
71
|
+
for (const key of Object.keys(result)) {
|
|
72
|
+
if (sensitive.has(key.toLowerCase())) {
|
|
73
|
+
result[key] = '[REDACTED]';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=audit-redaction.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-redaction.helper.js","sourceRoot":"","sources":["../src/audit-redaction.helper.ts"],"names":[],"mappings":";;;AAoBA,sCAkCC;AAED,gCAoBC;AAED,oCAwBC;AAtGY,QAAA,6BAA6B,GAAG;IAC3C,UAAU;IACV,OAAO;IACP,QAAQ;IACR,eAAe;IACf,cAAc;IACd,QAAQ;IACR,SAAS;IACT,aAAa;IACb,cAAc;CACf,CAAC;AAEW,QAAA,6BAA6B,GAAG;IAC3C,eAAe;IACf,QAAQ;IACR,WAAW;IACX,cAAc;IACd,qBAAqB;CACtB,CAAC;AAEF,SAAgB,aAAa,CAC3B,OAA4C,EAC5C,gBAA0B,qCAA6B;IAEvD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,mBAAmB,GAAG,IAAI,GAAG,CACjC,aAAa,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,C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CAAE,CAAC;IAEpD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,IAAI,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;YACrC,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAgB,YAAY,CAC1B,MAA2C,EAC3C,mBAA6B,EAAE;IAE/B,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC;QAC7B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,GAAG,CACvB,gBAAgB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CACvD,CAAC;IACF,MAAM,MAAM,qBAAiC,MAAM,CAAE,CAAC;IAEtD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,IAAI,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;YACrC,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function isAmqplibAvailable(): boolean;
|
|
2
|
+
export declare function isMicroservicesAvailable(): boolean;
|
|
3
|
+
export declare function isAmqpConnectionManagerAvailable(): boolean;
|
|
4
|
+
export declare function isRmqUrlConfigured(): boolean;
|
|
5
|
+
export declare function isRmqAuditReady(): boolean;
|
|
6
|
+
export declare function describeRmqAuditGap(): string | null;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAmqplibAvailable = isAmqplibAvailable;
|
|
4
|
+
exports.isMicroservicesAvailable = isMicroservicesAvailable;
|
|
5
|
+
exports.isAmqpConnectionManagerAvailable = isAmqpConnectionManagerAvailable;
|
|
6
|
+
exports.isRmqUrlConfigured = isRmqUrlConfigured;
|
|
7
|
+
exports.isRmqAuditReady = isRmqAuditReady;
|
|
8
|
+
exports.describeRmqAuditGap = describeRmqAuditGap;
|
|
9
|
+
function isAmqplibAvailable() {
|
|
10
|
+
try {
|
|
11
|
+
require.resolve('amqplib');
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
catch (_a) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function isMicroservicesAvailable() {
|
|
19
|
+
try {
|
|
20
|
+
require.resolve('@nestjs/microservices');
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
catch (_a) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function isAmqpConnectionManagerAvailable() {
|
|
28
|
+
try {
|
|
29
|
+
require.resolve('amqp-connection-manager');
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
catch (_a) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function isRmqUrlConfigured() {
|
|
37
|
+
var _a;
|
|
38
|
+
return Boolean((_a = process.env.RMQ_URL) === null || _a === void 0 ? void 0 : _a.trim());
|
|
39
|
+
}
|
|
40
|
+
function isRmqAuditReady() {
|
|
41
|
+
return (isAmqplibAvailable() &&
|
|
42
|
+
isMicroservicesAvailable() &&
|
|
43
|
+
isAmqpConnectionManagerAvailable() &&
|
|
44
|
+
isRmqUrlConfigured());
|
|
45
|
+
}
|
|
46
|
+
function describeRmqAuditGap() {
|
|
47
|
+
if (!isMicroservicesAvailable()) {
|
|
48
|
+
return '@nestjs/microservices is not installed';
|
|
49
|
+
}
|
|
50
|
+
if (!isAmqplibAvailable()) {
|
|
51
|
+
return 'amqplib is not installed';
|
|
52
|
+
}
|
|
53
|
+
if (!isAmqpConnectionManagerAvailable()) {
|
|
54
|
+
return 'amqp-connection-manager is not installed (required by NestJS ClientRMQ)';
|
|
55
|
+
}
|
|
56
|
+
if (!isRmqUrlConfigured()) {
|
|
57
|
+
return 'RMQ_URL is not configured';
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=audit-rmq-readiness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-rmq-readiness.js","sourceRoot":"","sources":["../src/audit-rmq-readiness.ts"],"names":[],"mappings":";;AAAA,gDAOC;AAED,4DAOC;AAED,4EAOC;AAED,gDAEC;AAGD,0CAOC;AAED,kDAcC;AAvDD,SAAgB,kBAAkB;IAChC,IAAI,CAAC;QACH,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAgB,wBAAwB;IACtC,IAAI,CAAC;QACH,OAAO,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAgB,gCAAgC;IAC9C,IAAI,CAAC;QACH,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAgB,kBAAkB;;IAChC,OAAO,OAAO,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,OAAO,0CAAE,IAAI,EAAE,CAAC,CAAC;AAC9C,CAAC;AAGD,SAAgB,eAAe;IAC7B,OAAO,CACL,kBAAkB,EAAE;QACpB,wBAAwB,EAAE;QAC1B,gCAAgC,EAAE;QAClC,kBAAkB,EAAE,CACrB,CAAC;AACJ,CAAC;AAED,SAAgB,mBAAmB;IACjC,IAAI,CAAC,wBAAwB,EAAE,EAAE,CAAC;QAChC,OAAO,wCAAwC,CAAC;IAClD,CAAC;IACD,IAAI,CAAC,kBAAkB,EAAE,EAAE,CAAC;QAC1B,OAAO,0BAA0B,CAAC;IACpC,CAAC;IACD,IAAI,CAAC,gCAAgC,EAAE,EAAE,CAAC;QACxC,OAAO,yEAAyE,CAAC;IACnF,CAAC;IACD,IAAI,CAAC,kBAAkB,EAAE,EAAE,CAAC;QAC1B,OAAO,2BAA2B,CAAC;IACrC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/audit.constants.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AUDIT_EXTRA_SINKS = void 0;
|
|
3
|
+
exports.AUDIT_MODULE_OPTIONS = exports.AUDIT_EXTRA_SINKS = void 0;
|
|
4
4
|
exports.AUDIT_EXTRA_SINKS = Symbol('AUDIT_EXTRA_SINKS');
|
|
5
|
+
exports.AUDIT_MODULE_OPTIONS = Symbol('AUDIT_MODULE_OPTIONS');
|
|
5
6
|
//# sourceMappingURL=audit.constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.constants.js","sourceRoot":"","sources":["../src/audit.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"audit.constants.js","sourceRoot":"","sources":["../src/audit.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAChD,QAAA,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC"}
|
package/dist/audit.module.js
CHANGED
|
@@ -17,45 +17,33 @@ const typeorm_1 = require("typeorm");
|
|
|
17
17
|
const audit_logger_config_1 = require("./audit.logger.config");
|
|
18
18
|
const audit_constants_1 = require("./audit.constants");
|
|
19
19
|
const audit_logger_enum_1 = require("./audit-logger.enum");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
require.resolve('amqplib');
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
catch (_a) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function isMicroservicesAvailable() {
|
|
30
|
-
try {
|
|
31
|
-
require.resolve('@nestjs/microservices');
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
catch (_a) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
20
|
+
const audit_module_options_1 = require("./audit-module-options");
|
|
21
|
+
const audit_rmq_readiness_1 = require("./audit-rmq-readiness");
|
|
38
22
|
function createAuditModuleConfig(options = {}) {
|
|
39
|
-
var _a;
|
|
40
23
|
const imports = [];
|
|
41
|
-
const providers = [
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
if (hasAmqplib && hasMicroservices) {
|
|
24
|
+
const providers = [];
|
|
25
|
+
const normalizedOptions = (0, audit_module_options_1.normalizeAuditModuleOptions)(options);
|
|
26
|
+
if ((0, audit_rmq_readiness_1.isRmqAuditReady)()) {
|
|
45
27
|
try {
|
|
46
28
|
imports.push(microservices_1.ClientsModule.register([audit_logger_config_1.auditLoggerConfig]));
|
|
29
|
+
providers.push(audit_subscriber_1.AuditSubscriber);
|
|
30
|
+
providers.push({
|
|
31
|
+
provide: audit_constants_1.AUDIT_MODULE_OPTIONS,
|
|
32
|
+
useValue: normalizedOptions,
|
|
33
|
+
});
|
|
47
34
|
providers.push({
|
|
48
35
|
provide: audit_constants_1.AUDIT_EXTRA_SINKS,
|
|
49
|
-
useValue:
|
|
36
|
+
useValue: normalizedOptions.extraSinks,
|
|
50
37
|
});
|
|
51
38
|
providers.push({
|
|
52
39
|
provide: core_1.APP_INTERCEPTOR,
|
|
53
|
-
useFactory: (reflector, connection, rmsRMQClient, extraSinks) => new audit_logger_interceptor_1.AuditLoggerInterceptor(reflector, connection, rmsRMQClient, extraSinks),
|
|
40
|
+
useFactory: (reflector, connection, rmsRMQClient, extraSinks, moduleOptions) => new audit_logger_interceptor_1.AuditLoggerInterceptor(reflector, connection, rmsRMQClient, extraSinks, moduleOptions),
|
|
54
41
|
inject: [
|
|
55
42
|
core_1.Reflector,
|
|
56
43
|
typeorm_1.DataSource,
|
|
57
44
|
audit_logger_enum_1.AuditLoggerRMQClient,
|
|
58
45
|
audit_constants_1.AUDIT_EXTRA_SINKS,
|
|
46
|
+
audit_constants_1.AUDIT_MODULE_OPTIONS,
|
|
59
47
|
],
|
|
60
48
|
});
|
|
61
49
|
}
|
|
@@ -65,22 +53,14 @@ function createAuditModuleConfig(options = {}) {
|
|
|
65
53
|
}
|
|
66
54
|
}
|
|
67
55
|
}
|
|
68
|
-
else {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
else if (!hasAmqplib) {
|
|
74
|
-
console.warn('AuditModule: amqplib is not installed. Install it to enable audit logging.');
|
|
75
|
-
}
|
|
76
|
-
else if (!hasMicroservices) {
|
|
77
|
-
console.warn('AuditModule: @nestjs/microservices is not installed. Install it to enable audit logging.');
|
|
78
|
-
}
|
|
56
|
+
else if (process.env.NODE_ENV !== 'production') {
|
|
57
|
+
const gap = (0, audit_rmq_readiness_1.describeRmqAuditGap)();
|
|
58
|
+
if (gap) {
|
|
59
|
+
console.warn(`AuditModule: RabbitMQ audit disabled — ${gap}.`);
|
|
79
60
|
}
|
|
80
61
|
}
|
|
81
62
|
return { imports, providers };
|
|
82
63
|
}
|
|
83
|
-
const moduleConfig = createAuditModuleConfig();
|
|
84
64
|
let AuditModule = AuditModule_1 = class AuditModule {
|
|
85
65
|
static forRoot(options = {}) {
|
|
86
66
|
const config = createAuditModuleConfig(options);
|
|
@@ -97,10 +77,6 @@ let AuditModule = AuditModule_1 = class AuditModule {
|
|
|
97
77
|
};
|
|
98
78
|
exports.AuditModule = AuditModule;
|
|
99
79
|
exports.AuditModule = AuditModule = AuditModule_1 = __decorate([
|
|
100
|
-
(0, common_1.Module)({
|
|
101
|
-
imports: moduleConfig.imports,
|
|
102
|
-
providers: moduleConfig.providers,
|
|
103
|
-
exports: moduleConfig.providers,
|
|
104
|
-
})
|
|
80
|
+
(0, common_1.Module)({})
|
|
105
81
|
], AuditModule);
|
|
106
82
|
//# sourceMappingURL=audit.module.js.map
|
package/dist/audit.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.module.js","sourceRoot":"","sources":["../src/audit.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,yDAAqD;AACrD,yEAAoE;AACpE,2CAAuD;AACvD,uCAA0D;AAC1D,yDAAmE;AACnE,qCAAqC;AACrC,+DAA0D;AAC1D,
|
|
1
|
+
{"version":3,"file":"audit.module.js","sourceRoot":"","sources":["../src/audit.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,yDAAqD;AACrD,yEAAoE;AACpE,2CAAuD;AACvD,uCAA0D;AAC1D,yDAAmE;AACnE,qCAAqC;AACrC,+DAA0D;AAC1D,uDAA4E;AAC5E,2DAA2D;AAE3D,iEAAqE;AACrE,+DAG+B;AAE/B,SAAS,uBAAuB,CAAC,UAAkC,EAAE;IAInE,MAAM,OAAO,GAAU,EAAE,CAAC;IAC1B,MAAM,SAAS,GAAU,EAAE,CAAC;IAE5B,MAAM,iBAAiB,GAAG,IAAA,kDAA2B,EAAC,OAAO,CAAC,CAAC;IAE/D,IAAI,IAAA,qCAAe,GAAE,EAAE,CAAC;QACtB,IAAI,CAAC;YACH,O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,MAAM,CAAC,OAAO,CAAC,UAAkC,EAAE;QACjD,MAAM,MAAM,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC;QAChD,OAAO;YACL,MAAM,EAAE,aAAW;YACnB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,OAAO,EAAE,MAAM,CAAC,SAAS;SAC1B,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,UAAkC,EAAE;QACtD,OAAO,aAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;CACF,CAAA;AAdY,kCAAW;sBAAX,WAAW;IADvB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,WAAW,CAcvB"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { ClientProxy } from '@nestjs/microservices';
|
|
2
2
|
import { DataSource, EntitySubscriberInterface, InsertEvent } from 'typeorm';
|
|
3
3
|
import type { AfterQueryEvent } from 'typeorm/subscriber/event/QueryEvent';
|
|
4
|
+
import type { NormalizedAuditModuleOptions } from './audit-module-options';
|
|
4
5
|
export declare class AuditSubscriber implements EntitySubscriberInterface {
|
|
5
6
|
private readonly dataSource;
|
|
6
7
|
private readonly rmsRMQClient;
|
|
7
|
-
|
|
8
|
+
private readonly moduleOptions;
|
|
9
|
+
constructor(dataSource: DataSource, rmsRMQClient: ClientProxy, moduleOptions?: NormalizedAuditModuleOptions);
|
|
8
10
|
afterInsert(event: InsertEvent<any>): Promise<any> | void;
|
|
9
11
|
afterQuery(event: AfterQueryEvent): Promise<any> | void;
|
|
10
12
|
}
|
package/dist/audit.subscriber.js
CHANGED
|
@@ -17,10 +17,18 @@ const common_1 = require("@nestjs/common");
|
|
|
17
17
|
const microservices_1 = require("@nestjs/microservices");
|
|
18
18
|
const typeorm_1 = require("typeorm");
|
|
19
19
|
const audit_logger_enum_1 = require("./audit-logger.enum");
|
|
20
|
+
const audit_constants_1 = require("./audit.constants");
|
|
21
|
+
const audit_redaction_helper_1 = require("./audit-redaction.helper");
|
|
20
22
|
let AuditSubscriber = class AuditSubscriber {
|
|
21
|
-
constructor(dataSource, rmsRMQClient
|
|
23
|
+
constructor(dataSource, rmsRMQClient, moduleOptions = {
|
|
24
|
+
extraSinks: [],
|
|
25
|
+
sensitiveBodyFields: [],
|
|
26
|
+
sensitiveColumns: [],
|
|
27
|
+
logSqlParameters: false,
|
|
28
|
+
}) {
|
|
22
29
|
this.dataSource = dataSource;
|
|
23
30
|
this.rmsRMQClient = rmsRMQClient;
|
|
31
|
+
this.moduleOptions = moduleOptions;
|
|
24
32
|
dataSource.subscribers.push(this);
|
|
25
33
|
}
|
|
26
34
|
afterInsert(event) {
|
|
@@ -28,7 +36,7 @@ let AuditSubscriber = class AuditSubscriber {
|
|
|
28
36
|
user: this.dataSource['user'],
|
|
29
37
|
entityName: event.metadata.tableName,
|
|
30
38
|
entityId: event.entity.id,
|
|
31
|
-
entity: event.entity,
|
|
39
|
+
entity: (0, audit_redaction_helper_1.redactEntity)(event.entity, this.moduleOptions.sensitiveColumns),
|
|
32
40
|
requestId: this.dataSource['requestId'],
|
|
33
41
|
query: 'INSERT',
|
|
34
42
|
createdAt: new Date(),
|
|
@@ -44,7 +52,9 @@ let AuditSubscriber = class AuditSubscriber {
|
|
|
44
52
|
createdAt: new Date(),
|
|
45
53
|
query: event.query,
|
|
46
54
|
requestId: this.dataSource['requestId'],
|
|
47
|
-
parameters:
|
|
55
|
+
parameters: this.moduleOptions.logSqlParameters
|
|
56
|
+
? event.parameters
|
|
57
|
+
: undefined,
|
|
48
58
|
user: this.dataSource['user'],
|
|
49
59
|
};
|
|
50
60
|
this.rmsRMQClient.emit(event.query.startsWith('DELETE') ? audit_logger_enum_1.RecordDeletion : audit_logger_enum_1.RecordUpdate, payload);
|
|
@@ -54,7 +64,9 @@ exports.AuditSubscriber = AuditSubscriber;
|
|
|
54
64
|
exports.AuditSubscriber = AuditSubscriber = __decorate([
|
|
55
65
|
(0, typeorm_1.EventSubscriber)(),
|
|
56
66
|
__param(1, (0, common_1.Inject)(audit_logger_enum_1.AuditLoggerRMQClient)),
|
|
67
|
+
__param(2, (0, common_1.Optional)()),
|
|
68
|
+
__param(2, (0, common_1.Inject)(audit_constants_1.AUDIT_MODULE_OPTIONS)),
|
|
57
69
|
__metadata("design:paramtypes", [typeorm_1.DataSource,
|
|
58
|
-
microservices_1.ClientProxy])
|
|
70
|
+
microservices_1.ClientProxy, Object])
|
|
59
71
|
], AuditSubscriber);
|
|
60
72
|
//# sourceMappingURL=audit.subscriber.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.subscriber.js","sourceRoot":"","sources":["../src/audit.subscriber.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"audit.subscriber.js","sourceRoot":"","sources":["../src/audit.subscriber.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAkD;AAClD,yDAAoD;AACpD,qCAKiB;AAGjB,2DAK6B;AAC7B,uDAAyD;AAEzD,qEAAwD;AAGjD,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,YACmB,UAAsB,EAEtB,YAAyB,EAGzB,gBAA8C;QAC7D,UAAU,EAAE,EAAE;QACd,mBAAmB,EAAE,EAAE;QACvB,gBAAgB,EAAE,EAAE;QACpB,gBAAgB,EAAE,KAAK;KACxB;QAVgB,eAAU,GAAV,UAAU,CAAY;QAEtB,iBAAY,GAAZ,YAAY,CAAa;QAGzB,kBAAa,GAAb,aAAa,CAK7B;QAED,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,WAAW,CAAC,KAAuB;QACjC,MAAM,OAAO,GAAmB;YAC9B,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;YAC7B,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,SAAS;YACpC,QAAQ,EAAE,KAAK,CAAC,M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M,EAAC,sCAAoB,CAAC,CAAA;qCAJA,oBAAU;QAER,2BAAW;GAJjC,eAAe,CAqD3B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ClientIpRequest = {
|
|
2
|
+
ip?: string;
|
|
3
|
+
ips?: string[];
|
|
4
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
5
|
+
socket?: {
|
|
6
|
+
remoteAddress?: string;
|
|
7
|
+
};
|
|
8
|
+
connection?: {
|
|
9
|
+
remoteAddress?: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare function getClientIp(req: ClientIpRequest): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getClientIp = getClientIp;
|
|
4
|
+
function getClientIp(req) {
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
6
|
+
if ((_a = req.ips) === null || _a === void 0 ? void 0 : _a.length) {
|
|
7
|
+
return req.ips[0];
|
|
8
|
+
}
|
|
9
|
+
if (req.ip) {
|
|
10
|
+
return req.ip;
|
|
11
|
+
}
|
|
12
|
+
const xff = (_b = req.headers) === null || _b === void 0 ? void 0 : _b['x-forwarded-for'];
|
|
13
|
+
if (xff) {
|
|
14
|
+
const raw = Array.isArray(xff) ? xff[0] : xff;
|
|
15
|
+
const first = (_c = raw.split(',')[0]) === null || _c === void 0 ? void 0 : _c.trim();
|
|
16
|
+
if (first) {
|
|
17
|
+
return first;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const realIp = (_d = req.headers) === null || _d === void 0 ? void 0 : _d['x-real-ip'];
|
|
21
|
+
if (realIp) {
|
|
22
|
+
return Array.isArray(realIp) ? realIp[0] : realIp;
|
|
23
|
+
}
|
|
24
|
+
return ((_h = (_f = (_e = req.socket) === null || _e === void 0 ? void 0 : _e.remoteAddress) !== null && _f !== void 0 ? _f : (_g = req.connection) === null || _g === void 0 ? void 0 : _g.remoteAddress) !== null && _h !== void 0 ? _h : 'unknown');
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=get-client-ip.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-client-ip.helper.js","sourceRoot":"","sources":["../src/get-client-ip.helper.ts"],"names":[],"mappings":";;AAQA,kCA4BC;AA5BD,SAAgB,WAAW,CAAC,GAAoB;;IAC9C,IAAI,MAAA,GAAG,CAAC,GAAG,0CAAE,MAAM,EAAE,CAAC;QACpB,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC;QACX,OAAO,GAAG,CAAC,EAAE,CAAC;IAChB,CAAC;IAED,MAAM,GAAG,GAAG,MAAA,GAAG,CAAC,OAAO,0CAAG,iBAAiB,CAAC,CAAC;IAC7C,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QAC9C,MAAM,KAAK,GAAG,MAAA,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,0CAAE,IAAI,EAAE,CAAC;QACxC,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,MAAA,GAAG,CAAC,OAAO,0CAAG,WAAW,CAAC,CAAC;IAC1C,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACpD,CAAC;IAED,OAAO,CACL,MAAA,MAAA,MAAA,GAAG,CAAC,MAAM,0CAAE,aAAa,mCACzB,MAAA,GAAG,CAAC,UAAU,0CAAE,aAAa,mCAC7B,SAAS,CACV,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -25,4 +25,5 @@ __exportStar(require("./audit-module-options"), exports);
|
|
|
25
25
|
__exportStar(require("./audit.subscriber"), exports);
|
|
26
26
|
__exportStar(require("./event-audit.decorator"), exports);
|
|
27
27
|
__exportStar(require("./ignore-logger.decorator"), exports);
|
|
28
|
+
__exportStar(require("./request-id.interceptor"), exports);
|
|
28
29
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,sDAAoC;AACpC,6DAA2C;AAC3C,sDAAoC;AACpC,8CAA4B;AAC5B,wDAAsC;AACtC,iDAA+B;AAC/B,yDAAuC;AACvC,qDAAmC;AACnC,0DAAwC;AACxC,4DAA0C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,sDAAoC;AACpC,6DAA2C;AAC3C,sDAAoC;AACpC,8CAA4B;AAC5B,wDAAsC;AACtC,iDAA+B;AAC/B,yDAAuC;AACvC,qDAAmC;AACnC,0DAAwC;AACxC,4DAA0C;AAC1C,2DAAyC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export declare const REQUEST_ID_HEADER = "x-request-id";
|
|
4
|
+
export declare class RequestIdInterceptor implements NestInterceptor {
|
|
5
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
6
|
+
}
|
|
@@ -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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.RequestIdInterceptor = exports.REQUEST_ID_HEADER = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
12
|
+
exports.REQUEST_ID_HEADER = 'x-request-id';
|
|
13
|
+
let RequestIdInterceptor = class RequestIdInterceptor {
|
|
14
|
+
intercept(context, next) {
|
|
15
|
+
var _a;
|
|
16
|
+
const req = context.switchToHttp().getRequest();
|
|
17
|
+
const incoming = (_a = req.headers) === null || _a === void 0 ? void 0 : _a[exports.REQUEST_ID_HEADER];
|
|
18
|
+
const requestId = typeof incoming === 'string' && incoming.length > 0
|
|
19
|
+
? incoming
|
|
20
|
+
: (0, crypto_1.randomUUID)();
|
|
21
|
+
req.requestId = requestId;
|
|
22
|
+
req.headers[exports.REQUEST_ID_HEADER] = requestId;
|
|
23
|
+
return next.handle();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.RequestIdInterceptor = RequestIdInterceptor;
|
|
27
|
+
exports.RequestIdInterceptor = RequestIdInterceptor = __decorate([
|
|
28
|
+
(0, common_1.Injectable)()
|
|
29
|
+
], RequestIdInterceptor);
|
|
30
|
+
//# sourceMappingURL=request-id.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-id.interceptor.js","sourceRoot":"","sources":["../src/request-id.interceptor.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAKwB;AACxB,mCAAoC;AAGvB,QAAA,iBAAiB,GAAG,cAAc,CAAC;AAGzC,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC/B,SAAS,CAAC,OAAyB,EAAE,IAAiB;;QACpD,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QAChD,MAAM,QAAQ,GAAG,MAAA,GAAG,CAAC,OAAO,0CAAG,yBAAiB,CAAC,CAAC;QAClD,MAAM,SAAS,GACb,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;YACjD,CAAC,CAAC,QAAQ;YACV,CAAC,CAAC,IAAA,mBAAU,GAAE,CAAC;QACnB,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC;QAC1B,GAAG,CAAC,OAAO,CAAC,yBAAiB,CAAC,GAAG,SAAS,CAAC;QAC3C,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACF,CAAA;AAZY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;GACA,oBAAoB,CAYhC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zola_do/audit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.17",
|
|
4
4
|
"description": "RabbitMQ-based audit logging for NestJS",
|
|
5
5
|
"author": "zolaDO",
|
|
6
6
|
"license": "ISC",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
36
36
|
"@nestjs/microservices": "^10.0.0 || ^11.0.0",
|
|
37
37
|
"amqplib": "^0.10.0",
|
|
38
|
+
"amqp-connection-manager": "^4.0.0",
|
|
38
39
|
"reflect-metadata": "^0.1.0 || ^0.2.0",
|
|
39
40
|
"rxjs": "^7.0.0 || ^8.0.0",
|
|
40
41
|
"typeorm": "^0.3.0 || ^1.0.0"
|
|
@@ -46,6 +47,9 @@
|
|
|
46
47
|
"amqplib": {
|
|
47
48
|
"optional": true
|
|
48
49
|
},
|
|
50
|
+
"amqp-connection-manager": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
49
53
|
"typeorm": {
|
|
50
54
|
"optional": true
|
|
51
55
|
}
|