@nest-omni/core 3.1.2-7 → 3.1.2-9
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/audit/audit.module.d.ts +10 -0
- package/audit/audit.module.js +254 -0
- package/audit/controllers/audit.controller.d.ts +20 -0
- package/audit/controllers/audit.controller.js +142 -0
- package/audit/controllers/index.d.ts +1 -0
- package/audit/controllers/index.js +17 -0
- package/audit/decorators/audit-controller.decorator.d.ts +5 -0
- package/audit/decorators/audit-controller.decorator.js +17 -0
- package/audit/decorators/audit-operation.decorator.d.ts +7 -0
- package/audit/decorators/audit-operation.decorator.js +25 -0
- package/audit/decorators/entity-audit.decorator.d.ts +10 -0
- package/audit/decorators/entity-audit.decorator.js +70 -0
- package/audit/decorators/index.d.ts +3 -0
- package/audit/decorators/index.js +19 -0
- package/audit/dto/audit-log-query.dto.d.ts +14 -0
- package/audit/dto/audit-log-query.dto.js +95 -0
- package/audit/dto/begin-transaction.dto.d.ts +3 -0
- package/audit/dto/begin-transaction.dto.js +22 -0
- package/audit/dto/compare-entities.dto.d.ts +6 -0
- package/audit/dto/compare-entities.dto.js +44 -0
- package/audit/dto/index.d.ts +5 -0
- package/audit/dto/index.js +21 -0
- package/audit/dto/pre-check-restore.dto.d.ts +5 -0
- package/audit/dto/pre-check-restore.dto.js +32 -0
- package/audit/dto/restore-entity.dto.d.ts +9 -0
- package/audit/dto/restore-entity.dto.js +53 -0
- package/audit/entities/entity-audit-log.entity.d.ts +23 -0
- package/audit/entities/entity-audit-log.entity.js +110 -0
- package/audit/entities/entity-transaction.entity.d.ts +21 -0
- package/audit/entities/entity-transaction.entity.js +80 -0
- package/audit/entities/index.d.ts +4 -0
- package/audit/entities/index.js +20 -0
- package/audit/entities/manual-operation-log.entity.d.ts +13 -0
- package/audit/entities/manual-operation-log.entity.js +65 -0
- package/audit/entities/operation-template.entity.d.ts +11 -0
- package/audit/entities/operation-template.entity.js +65 -0
- package/audit/enums/audit.enums.d.ts +42 -0
- package/audit/enums/audit.enums.js +53 -0
- package/audit/enums/index.d.ts +1 -0
- package/audit/enums/index.js +17 -0
- package/audit/index.d.ts +12 -0
- package/audit/index.js +48 -0
- package/audit/interceptors/audit.interceptor.d.ts +12 -0
- package/audit/interceptors/audit.interceptor.js +95 -0
- package/audit/interceptors/index.d.ts +1 -0
- package/audit/interceptors/index.js +17 -0
- package/audit/interfaces/audit.interfaces.d.ts +180 -0
- package/audit/interfaces/audit.interfaces.js +2 -0
- package/audit/interfaces/index.d.ts +1 -0
- package/audit/interfaces/index.js +17 -0
- package/audit/services/audit-context.service.d.ts +10 -0
- package/audit/services/audit-context.service.js +55 -0
- package/audit/services/audit-strategy.service.d.ts +19 -0
- package/audit/services/audit-strategy.service.js +89 -0
- package/audit/services/entity-audit.service.d.ts +65 -0
- package/audit/services/entity-audit.service.js +626 -0
- package/audit/services/index.d.ts +6 -0
- package/audit/services/index.js +22 -0
- package/audit/services/multi-database.service.d.ts +10 -0
- package/audit/services/multi-database.service.js +59 -0
- package/audit/services/operation-description.service.d.ts +21 -0
- package/audit/services/operation-description.service.js +213 -0
- package/audit/services/transaction-audit.service.d.ts +22 -0
- package/audit/services/transaction-audit.service.js +201 -0
- package/audit/subscribers/entity-audit.subscriber.d.ts +14 -0
- package/audit/subscribers/entity-audit.subscriber.js +136 -0
- package/audit/subscribers/index.d.ts +1 -0
- package/audit/subscribers/index.js +17 -0
- package/common/utils.d.ts +1 -0
- package/common/utils.js +6 -0
- package/http-client/config/http-client.config.d.ts +6 -0
- package/http-client/config/http-client.config.js +87 -0
- package/http-client/config/index.d.ts +1 -0
- package/http-client/config/index.js +17 -0
- package/http-client/decorators/http-client.decorators.d.ts +72 -0
- package/http-client/decorators/http-client.decorators.js +204 -0
- package/http-client/decorators/index.d.ts +1 -0
- package/http-client/decorators/index.js +17 -0
- package/http-client/entities/http-log.entity.d.ts +98 -0
- package/http-client/entities/http-log.entity.js +143 -0
- package/http-client/entities/index.d.ts +1 -0
- package/http-client/entities/index.js +17 -0
- package/http-client/errors/http-client.errors.d.ts +56 -0
- package/http-client/errors/http-client.errors.js +149 -0
- package/http-client/errors/index.d.ts +1 -0
- package/http-client/errors/index.js +17 -0
- package/http-client/examples/advanced-usage.example.d.ts +23 -0
- package/http-client/examples/advanced-usage.example.js +332 -0
- package/http-client/examples/auth-with-waiting-lock.example.d.ts +17 -0
- package/http-client/examples/auth-with-waiting-lock.example.js +336 -0
- package/http-client/examples/basic-usage.example.d.ts +53 -0
- package/http-client/examples/basic-usage.example.js +161 -0
- package/http-client/examples/index.d.ts +3 -0
- package/http-client/examples/index.js +19 -0
- package/http-client/examples/multi-api-configuration.example.d.ts +98 -0
- package/http-client/examples/multi-api-configuration.example.js +353 -0
- package/http-client/http-client.module.d.ts +11 -0
- package/http-client/http-client.module.js +257 -0
- package/http-client/index.d.ts +10 -0
- package/http-client/index.js +27 -0
- package/http-client/interfaces/api-client-config.interface.d.ts +152 -0
- package/http-client/interfaces/api-client-config.interface.js +12 -0
- package/http-client/interfaces/http-client-config.interface.d.ts +123 -0
- package/http-client/interfaces/http-client-config.interface.js +2 -0
- package/http-client/services/api-client-registry.service.d.ts +41 -0
- package/http-client/services/api-client-registry.service.js +412 -0
- package/http-client/services/cache.service.d.ts +24 -0
- package/http-client/services/cache.service.js +264 -0
- package/http-client/services/circuit-breaker.service.d.ts +33 -0
- package/http-client/services/circuit-breaker.service.js +180 -0
- package/http-client/services/http-client.service.d.ts +60 -0
- package/http-client/services/http-client.service.js +504 -0
- package/http-client/services/http-log-query.service.d.ts +76 -0
- package/http-client/services/http-log-query.service.js +590 -0
- package/http-client/services/http-replay.service.d.ts +58 -0
- package/http-client/services/http-replay.service.js +266 -0
- package/http-client/services/index.d.ts +7 -0
- package/http-client/services/index.js +23 -0
- package/http-client/services/log-cleanup.service.d.ts +64 -0
- package/http-client/services/log-cleanup.service.js +268 -0
- package/http-client/services/logging.service.d.ts +36 -0
- package/http-client/services/logging.service.js +445 -0
- package/http-client/utils/call-stack-extractor.util.d.ts +29 -0
- package/http-client/utils/call-stack-extractor.util.js +138 -0
- package/http-client/utils/context-extractor.util.d.ts +44 -0
- package/http-client/utils/context-extractor.util.js +173 -0
- package/http-client/utils/curl-generator.util.d.ts +9 -0
- package/http-client/utils/curl-generator.util.js +169 -0
- package/http-client/utils/index.d.ts +4 -0
- package/http-client/utils/index.js +20 -0
- package/http-client/utils/request-id.util.d.ts +4 -0
- package/http-client/utils/request-id.util.js +34 -0
- package/http-client/utils/retry-recorder.util.d.ts +30 -0
- package/http-client/utils/retry-recorder.util.js +143 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/setup/bootstrap.setup.js +5 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AbstractUuidPrimaryEntity } from '../../common/abstract.entity';
|
|
2
|
+
import { AuditOperation } from '../enums';
|
|
3
|
+
export declare class OperationTemplateEntity extends AbstractUuidPrimaryEntity {
|
|
4
|
+
key: string;
|
|
5
|
+
entityName: string;
|
|
6
|
+
operation: AuditOperation;
|
|
7
|
+
nameTemplates: Record<string, string>;
|
|
8
|
+
descriptionTemplates: Record<string, string>;
|
|
9
|
+
fieldLabels: Record<string, Record<string, string>>;
|
|
10
|
+
valueDisplays: Record<string, Record<string, Record<string, string>>>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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.OperationTemplateEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const abstract_entity_1 = require("../../common/abstract.entity");
|
|
15
|
+
const enums_1 = require("../enums");
|
|
16
|
+
let OperationTemplateEntity = class OperationTemplateEntity extends abstract_entity_1.AbstractUuidPrimaryEntity {
|
|
17
|
+
};
|
|
18
|
+
exports.OperationTemplateEntity = OperationTemplateEntity;
|
|
19
|
+
__decorate([
|
|
20
|
+
(0, typeorm_1.Column)({ unique: true, comment: '模板键,唯一标识' }),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], OperationTemplateEntity.prototype, "key", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, typeorm_1.Column)({ comment: '实体类名,* 表示通用模板' }),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], OperationTemplateEntity.prototype, "entityName", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, typeorm_1.Column)({ type: 'enum', enum: enums_1.AuditOperation, comment: '操作类型' }),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], OperationTemplateEntity.prototype, "operation", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, typeorm_1.Column)({
|
|
33
|
+
type: 'json',
|
|
34
|
+
comment: '多语言操作名称模板 { zh: "创建用户", en: "Create User" }',
|
|
35
|
+
}),
|
|
36
|
+
__metadata("design:type", Object)
|
|
37
|
+
], OperationTemplateEntity.prototype, "nameTemplates", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, typeorm_1.Column)({
|
|
40
|
+
type: 'json',
|
|
41
|
+
comment: '多语言操作描述模板 { zh: "创建了用户 {name}", en: "Created user {name}" }',
|
|
42
|
+
}),
|
|
43
|
+
__metadata("design:type", Object)
|
|
44
|
+
], OperationTemplateEntity.prototype, "descriptionTemplates", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, typeorm_1.Column)({
|
|
47
|
+
type: 'json',
|
|
48
|
+
nullable: true,
|
|
49
|
+
comment: '字段标签映射 { name: { zh: "姓名", en: "Name" } }',
|
|
50
|
+
}),
|
|
51
|
+
__metadata("design:type", Object)
|
|
52
|
+
], OperationTemplateEntity.prototype, "fieldLabels", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, typeorm_1.Column)({
|
|
55
|
+
type: 'json',
|
|
56
|
+
nullable: true,
|
|
57
|
+
comment: '值显示映射 { status: { active: { zh: "激活", en: "Active" } } }',
|
|
58
|
+
}),
|
|
59
|
+
__metadata("design:type", Object)
|
|
60
|
+
], OperationTemplateEntity.prototype, "valueDisplays", void 0);
|
|
61
|
+
exports.OperationTemplateEntity = OperationTemplateEntity = __decorate([
|
|
62
|
+
(0, typeorm_1.Entity)('operation_template'),
|
|
63
|
+
(0, typeorm_1.Index)('idx_template_key', ['key'], { unique: true }),
|
|
64
|
+
(0, typeorm_1.Index)('idx_entity_operation', ['entityName', 'operation'])
|
|
65
|
+
], OperationTemplateEntity);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare enum OperationType {
|
|
2
|
+
CREATE = "create",
|
|
3
|
+
UPDATE = "update",
|
|
4
|
+
DELETE = "delete"
|
|
5
|
+
}
|
|
6
|
+
export declare enum AuditOperation {
|
|
7
|
+
CREATE = "CREATE",
|
|
8
|
+
UPDATE = "UPDATE",
|
|
9
|
+
DELETE = "DELETE",
|
|
10
|
+
RESTORE = "RESTORE"
|
|
11
|
+
}
|
|
12
|
+
export declare enum TransactionStatus {
|
|
13
|
+
PENDING = "pending",
|
|
14
|
+
COMMITTED = "committed",
|
|
15
|
+
ROLLED_BACK = "rolled_back"
|
|
16
|
+
}
|
|
17
|
+
export declare enum RecoveryStrategy {
|
|
18
|
+
ENTITY_ONLY = "ENTITY_ONLY",
|
|
19
|
+
TRANSACTION_RESTORE = "TRANSACTION_RESTORE",
|
|
20
|
+
DEPENDENCY_GRAPH = "DEPENDENCY_GRAPH"
|
|
21
|
+
}
|
|
22
|
+
export declare enum RecordStrategy {
|
|
23
|
+
FULL = "FULL",
|
|
24
|
+
DIFF_ONLY = "DIFF_ONLY",
|
|
25
|
+
DISABLED = "DISABLED"
|
|
26
|
+
}
|
|
27
|
+
export declare enum MaskingStrategy {
|
|
28
|
+
NONE = "NONE",
|
|
29
|
+
HASH = "HASH",
|
|
30
|
+
MASK = "MASK",
|
|
31
|
+
PARTIAL = "PARTIAL"
|
|
32
|
+
}
|
|
33
|
+
export declare enum RollbackActionType {
|
|
34
|
+
ENTITY = "entity",
|
|
35
|
+
FILE = "file",
|
|
36
|
+
CUSTOM = "custom"
|
|
37
|
+
}
|
|
38
|
+
export declare enum ChangeType {
|
|
39
|
+
ADDED = "added",
|
|
40
|
+
REMOVED = "removed",
|
|
41
|
+
MODIFIED = "modified"
|
|
42
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChangeType = exports.RollbackActionType = exports.MaskingStrategy = exports.RecordStrategy = exports.RecoveryStrategy = exports.TransactionStatus = exports.AuditOperation = exports.OperationType = void 0;
|
|
4
|
+
var OperationType;
|
|
5
|
+
(function (OperationType) {
|
|
6
|
+
OperationType["CREATE"] = "create";
|
|
7
|
+
OperationType["UPDATE"] = "update";
|
|
8
|
+
OperationType["DELETE"] = "delete";
|
|
9
|
+
})(OperationType || (exports.OperationType = OperationType = {}));
|
|
10
|
+
var AuditOperation;
|
|
11
|
+
(function (AuditOperation) {
|
|
12
|
+
AuditOperation["CREATE"] = "CREATE";
|
|
13
|
+
AuditOperation["UPDATE"] = "UPDATE";
|
|
14
|
+
AuditOperation["DELETE"] = "DELETE";
|
|
15
|
+
AuditOperation["RESTORE"] = "RESTORE";
|
|
16
|
+
})(AuditOperation || (exports.AuditOperation = AuditOperation = {}));
|
|
17
|
+
var TransactionStatus;
|
|
18
|
+
(function (TransactionStatus) {
|
|
19
|
+
TransactionStatus["PENDING"] = "pending";
|
|
20
|
+
TransactionStatus["COMMITTED"] = "committed";
|
|
21
|
+
TransactionStatus["ROLLED_BACK"] = "rolled_back";
|
|
22
|
+
})(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
|
|
23
|
+
var RecoveryStrategy;
|
|
24
|
+
(function (RecoveryStrategy) {
|
|
25
|
+
RecoveryStrategy["ENTITY_ONLY"] = "ENTITY_ONLY";
|
|
26
|
+
RecoveryStrategy["TRANSACTION_RESTORE"] = "TRANSACTION_RESTORE";
|
|
27
|
+
RecoveryStrategy["DEPENDENCY_GRAPH"] = "DEPENDENCY_GRAPH";
|
|
28
|
+
})(RecoveryStrategy || (exports.RecoveryStrategy = RecoveryStrategy = {}));
|
|
29
|
+
var RecordStrategy;
|
|
30
|
+
(function (RecordStrategy) {
|
|
31
|
+
RecordStrategy["FULL"] = "FULL";
|
|
32
|
+
RecordStrategy["DIFF_ONLY"] = "DIFF_ONLY";
|
|
33
|
+
RecordStrategy["DISABLED"] = "DISABLED";
|
|
34
|
+
})(RecordStrategy || (exports.RecordStrategy = RecordStrategy = {}));
|
|
35
|
+
var MaskingStrategy;
|
|
36
|
+
(function (MaskingStrategy) {
|
|
37
|
+
MaskingStrategy["NONE"] = "NONE";
|
|
38
|
+
MaskingStrategy["HASH"] = "HASH";
|
|
39
|
+
MaskingStrategy["MASK"] = "MASK";
|
|
40
|
+
MaskingStrategy["PARTIAL"] = "PARTIAL";
|
|
41
|
+
})(MaskingStrategy || (exports.MaskingStrategy = MaskingStrategy = {}));
|
|
42
|
+
var RollbackActionType;
|
|
43
|
+
(function (RollbackActionType) {
|
|
44
|
+
RollbackActionType["ENTITY"] = "entity";
|
|
45
|
+
RollbackActionType["FILE"] = "file";
|
|
46
|
+
RollbackActionType["CUSTOM"] = "custom";
|
|
47
|
+
})(RollbackActionType || (exports.RollbackActionType = RollbackActionType = {}));
|
|
48
|
+
var ChangeType;
|
|
49
|
+
(function (ChangeType) {
|
|
50
|
+
ChangeType["ADDED"] = "added";
|
|
51
|
+
ChangeType["REMOVED"] = "removed";
|
|
52
|
+
ChangeType["MODIFIED"] = "modified";
|
|
53
|
+
})(ChangeType || (exports.ChangeType = ChangeType = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit.enums';
|
|
@@ -0,0 +1,17 @@
|
|
|
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.enums"), exports);
|
package/audit/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './entities';
|
|
2
|
+
export * from './enums';
|
|
3
|
+
export * from './interfaces';
|
|
4
|
+
export * from './dto';
|
|
5
|
+
export { AuditEntity, EntityAudit, AuditField, getEntityAuditConfig, getFieldAuditConfig, getFieldLabel, getFieldValueLabel, ENTITY_AUDIT_OPTIONS, FIELD_AUDIT_OPTIONS, } from './decorators/entity-audit.decorator';
|
|
6
|
+
export { AuditController, AuditMethod, CONTROLLER_AUDIT_OPTIONS, METHOD_AUDIT_OPTIONS, } from './decorators/audit-controller.decorator';
|
|
7
|
+
export { AuditLog, LogOperation, AuditOperation, getAuditOperationConfig, hasAuditOperation, AUDIT_OPERATION_OPTIONS, } from './decorators/audit-operation.decorator';
|
|
8
|
+
export * from './services';
|
|
9
|
+
export * from './subscribers';
|
|
10
|
+
export * from './interceptors';
|
|
11
|
+
export * from './controllers';
|
|
12
|
+
export * from './audit.module';
|
package/audit/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
exports.AUDIT_OPERATION_OPTIONS = exports.hasAuditOperation = exports.getAuditOperationConfig = exports.AuditOperation = exports.LogOperation = exports.AuditLog = exports.METHOD_AUDIT_OPTIONS = exports.CONTROLLER_AUDIT_OPTIONS = exports.AuditMethod = exports.AuditController = exports.FIELD_AUDIT_OPTIONS = exports.ENTITY_AUDIT_OPTIONS = exports.getFieldValueLabel = exports.getFieldLabel = exports.getFieldAuditConfig = exports.getEntityAuditConfig = exports.AuditField = exports.EntityAudit = exports.AuditEntity = void 0;
|
|
18
|
+
__exportStar(require("./entities"), exports);
|
|
19
|
+
__exportStar(require("./enums"), exports);
|
|
20
|
+
__exportStar(require("./interfaces"), exports);
|
|
21
|
+
__exportStar(require("./dto"), exports);
|
|
22
|
+
var entity_audit_decorator_1 = require("./decorators/entity-audit.decorator");
|
|
23
|
+
Object.defineProperty(exports, "AuditEntity", { enumerable: true, get: function () { return entity_audit_decorator_1.AuditEntity; } });
|
|
24
|
+
Object.defineProperty(exports, "EntityAudit", { enumerable: true, get: function () { return entity_audit_decorator_1.EntityAudit; } });
|
|
25
|
+
Object.defineProperty(exports, "AuditField", { enumerable: true, get: function () { return entity_audit_decorator_1.AuditField; } });
|
|
26
|
+
Object.defineProperty(exports, "getEntityAuditConfig", { enumerable: true, get: function () { return entity_audit_decorator_1.getEntityAuditConfig; } });
|
|
27
|
+
Object.defineProperty(exports, "getFieldAuditConfig", { enumerable: true, get: function () { return entity_audit_decorator_1.getFieldAuditConfig; } });
|
|
28
|
+
Object.defineProperty(exports, "getFieldLabel", { enumerable: true, get: function () { return entity_audit_decorator_1.getFieldLabel; } });
|
|
29
|
+
Object.defineProperty(exports, "getFieldValueLabel", { enumerable: true, get: function () { return entity_audit_decorator_1.getFieldValueLabel; } });
|
|
30
|
+
Object.defineProperty(exports, "ENTITY_AUDIT_OPTIONS", { enumerable: true, get: function () { return entity_audit_decorator_1.ENTITY_AUDIT_OPTIONS; } });
|
|
31
|
+
Object.defineProperty(exports, "FIELD_AUDIT_OPTIONS", { enumerable: true, get: function () { return entity_audit_decorator_1.FIELD_AUDIT_OPTIONS; } });
|
|
32
|
+
var audit_controller_decorator_1 = require("./decorators/audit-controller.decorator");
|
|
33
|
+
Object.defineProperty(exports, "AuditController", { enumerable: true, get: function () { return audit_controller_decorator_1.AuditController; } });
|
|
34
|
+
Object.defineProperty(exports, "AuditMethod", { enumerable: true, get: function () { return audit_controller_decorator_1.AuditMethod; } });
|
|
35
|
+
Object.defineProperty(exports, "CONTROLLER_AUDIT_OPTIONS", { enumerable: true, get: function () { return audit_controller_decorator_1.CONTROLLER_AUDIT_OPTIONS; } });
|
|
36
|
+
Object.defineProperty(exports, "METHOD_AUDIT_OPTIONS", { enumerable: true, get: function () { return audit_controller_decorator_1.METHOD_AUDIT_OPTIONS; } });
|
|
37
|
+
var audit_operation_decorator_1 = require("./decorators/audit-operation.decorator");
|
|
38
|
+
Object.defineProperty(exports, "AuditLog", { enumerable: true, get: function () { return audit_operation_decorator_1.AuditLog; } });
|
|
39
|
+
Object.defineProperty(exports, "LogOperation", { enumerable: true, get: function () { return audit_operation_decorator_1.LogOperation; } });
|
|
40
|
+
Object.defineProperty(exports, "AuditOperation", { enumerable: true, get: function () { return audit_operation_decorator_1.AuditOperation; } });
|
|
41
|
+
Object.defineProperty(exports, "getAuditOperationConfig", { enumerable: true, get: function () { return audit_operation_decorator_1.getAuditOperationConfig; } });
|
|
42
|
+
Object.defineProperty(exports, "hasAuditOperation", { enumerable: true, get: function () { return audit_operation_decorator_1.hasAuditOperation; } });
|
|
43
|
+
Object.defineProperty(exports, "AUDIT_OPERATION_OPTIONS", { enumerable: true, get: function () { return audit_operation_decorator_1.AUDIT_OPERATION_OPTIONS; } });
|
|
44
|
+
__exportStar(require("./services"), exports);
|
|
45
|
+
__exportStar(require("./subscribers"), exports);
|
|
46
|
+
__exportStar(require("./interceptors"), exports);
|
|
47
|
+
__exportStar(require("./controllers"), exports);
|
|
48
|
+
__exportStar(require("./audit.module"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { AuditContextService } from '../services/audit-context.service';
|
|
4
|
+
export declare class AuditInterceptor implements NestInterceptor {
|
|
5
|
+
private readonly contextService;
|
|
6
|
+
constructor(contextService: AuditContextService);
|
|
7
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
8
|
+
private setRequestContext;
|
|
9
|
+
private handleError;
|
|
10
|
+
private isAuditEnabled;
|
|
11
|
+
private generateRequestId;
|
|
12
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.AuditInterceptor = void 0;
|
|
22
|
+
const common_1 = require("@nestjs/common");
|
|
23
|
+
const operators_1 = require("rxjs/operators");
|
|
24
|
+
const crypto_1 = require("crypto");
|
|
25
|
+
const audit_context_service_1 = require("../services/audit-context.service");
|
|
26
|
+
const decorators_1 = require("../decorators");
|
|
27
|
+
let AuditInterceptor = class AuditInterceptor {
|
|
28
|
+
constructor(contextService) {
|
|
29
|
+
this.contextService = contextService;
|
|
30
|
+
}
|
|
31
|
+
intercept(context, next) {
|
|
32
|
+
const request = context.switchToHttp().getRequest();
|
|
33
|
+
const handler = context.getHandler();
|
|
34
|
+
const controller = context.getClass();
|
|
35
|
+
if (!this.isAuditEnabled(controller, handler)) {
|
|
36
|
+
return next.handle();
|
|
37
|
+
}
|
|
38
|
+
this.setRequestContext(request);
|
|
39
|
+
return next.handle().pipe((0, operators_1.tap)(() => {
|
|
40
|
+
}), (0, operators_1.catchError)((error) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
yield this.handleError(error, request);
|
|
42
|
+
throw error;
|
|
43
|
+
})));
|
|
44
|
+
}
|
|
45
|
+
setRequestContext(request) {
|
|
46
|
+
var _a, _b, _c;
|
|
47
|
+
const user = request.user || {};
|
|
48
|
+
const auditContext = {
|
|
49
|
+
userId: user.uid || 'anonymous',
|
|
50
|
+
username: user.username || 'anonymous',
|
|
51
|
+
requestId: request.id || ((_a = request.headers) === null || _a === void 0 ? void 0 : _a['x-request-id']) || this.generateRequestId(),
|
|
52
|
+
requestIp: request.ip || ((_b = request.connection) === null || _b === void 0 ? void 0 : _b.remoteAddress),
|
|
53
|
+
userAgent: (_c = request.headers) === null || _c === void 0 ? void 0 : _c['user-agent'],
|
|
54
|
+
timestamp: new Date(),
|
|
55
|
+
};
|
|
56
|
+
this.contextService.setContext(auditContext);
|
|
57
|
+
}
|
|
58
|
+
handleError(error, request) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
this.contextService.setContext({
|
|
61
|
+
metadata: {
|
|
62
|
+
error: {
|
|
63
|
+
message: error.message,
|
|
64
|
+
stack: error.stack,
|
|
65
|
+
status: error.status,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
isAuditEnabled(controller, handler) {
|
|
72
|
+
try {
|
|
73
|
+
const controllerMetadata = Reflect.getMetadata(decorators_1.CONTROLLER_AUDIT_OPTIONS, controller);
|
|
74
|
+
if (controllerMetadata && controllerMetadata.enabled === false) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const handlerMetadata = Reflect.getMetadata(decorators_1.METHOD_AUDIT_OPTIONS, handler);
|
|
78
|
+
if (handlerMetadata && handlerMetadata.enabled === false) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
generateRequestId() {
|
|
88
|
+
return (0, crypto_1.randomBytes)(16).toString('hex');
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
exports.AuditInterceptor = AuditInterceptor;
|
|
92
|
+
exports.AuditInterceptor = AuditInterceptor = __decorate([
|
|
93
|
+
(0, common_1.Injectable)(),
|
|
94
|
+
__metadata("design:paramtypes", [audit_context_service_1.AuditContextService])
|
|
95
|
+
], AuditInterceptor);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit.interceptor';
|
|
@@ -0,0 +1,17 @@
|
|
|
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.interceptor"), exports);
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { AuditOperation, MaskingStrategy, RecordStrategy, RollbackActionType, ChangeType } from '../enums/audit.enums';
|
|
2
|
+
export interface AuditContext {
|
|
3
|
+
userId?: string;
|
|
4
|
+
username?: string;
|
|
5
|
+
requestId?: string;
|
|
6
|
+
requestIp?: string;
|
|
7
|
+
userAgent?: string;
|
|
8
|
+
timestamp?: Date;
|
|
9
|
+
transactionId?: string;
|
|
10
|
+
metadata?: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
export interface IAuditStrategy {
|
|
13
|
+
shouldRecord(entityType: string, operation: AuditOperation): boolean;
|
|
14
|
+
getRecordStrategy(entityType: string, operation: AuditOperation): RecordStrategy;
|
|
15
|
+
getFieldFilter(entityType: string): IFieldFilter;
|
|
16
|
+
}
|
|
17
|
+
export interface IFieldFilter {
|
|
18
|
+
shouldIncludeField(fieldName: string, path: string[]): boolean;
|
|
19
|
+
shouldMaskField(fieldName: string, path: string[]): boolean;
|
|
20
|
+
getMaskingStrategy(fieldName: string, path: string[]): MaskingStrategy;
|
|
21
|
+
}
|
|
22
|
+
export interface EntityDifference {
|
|
23
|
+
changes: Array<{
|
|
24
|
+
path: string[];
|
|
25
|
+
type: 'ADD' | 'REMOVE' | 'CHANGE';
|
|
26
|
+
oldValue: any;
|
|
27
|
+
newValue: any;
|
|
28
|
+
}>;
|
|
29
|
+
summary: {
|
|
30
|
+
added: number;
|
|
31
|
+
removed: number;
|
|
32
|
+
changed: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface RestoreOptions {
|
|
36
|
+
force?: boolean;
|
|
37
|
+
dryRun?: boolean;
|
|
38
|
+
excludeFields?: string[];
|
|
39
|
+
includeFields?: string[];
|
|
40
|
+
skipDependencies?: boolean;
|
|
41
|
+
connectionName?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface RestoreResult {
|
|
44
|
+
success: boolean;
|
|
45
|
+
message?: string;
|
|
46
|
+
conflicts?: Array<{
|
|
47
|
+
field: string;
|
|
48
|
+
reason: string;
|
|
49
|
+
currentValue: any;
|
|
50
|
+
targetValue: any;
|
|
51
|
+
}>;
|
|
52
|
+
restoredEntities?: Array<{
|
|
53
|
+
entityType: string;
|
|
54
|
+
entityId: string;
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
export interface PreCheckResult {
|
|
58
|
+
canRestore: boolean;
|
|
59
|
+
conflicts: Array<{
|
|
60
|
+
field: string;
|
|
61
|
+
reason: string;
|
|
62
|
+
currentValue: any;
|
|
63
|
+
targetValue: any;
|
|
64
|
+
}>;
|
|
65
|
+
warnings: string[];
|
|
66
|
+
}
|
|
67
|
+
export interface BatchOperationResult {
|
|
68
|
+
total: number;
|
|
69
|
+
success: number;
|
|
70
|
+
failed: number;
|
|
71
|
+
errors: Array<{
|
|
72
|
+
index: number;
|
|
73
|
+
error: string;
|
|
74
|
+
}>;
|
|
75
|
+
results: any[];
|
|
76
|
+
}
|
|
77
|
+
export interface AuditConfig {
|
|
78
|
+
enabled?: boolean;
|
|
79
|
+
defaultStrategy?: RecordStrategy;
|
|
80
|
+
maxDiffDepth?: number;
|
|
81
|
+
maxDiffFields?: number;
|
|
82
|
+
connections?: {
|
|
83
|
+
audit?: string;
|
|
84
|
+
monitored?: string[];
|
|
85
|
+
};
|
|
86
|
+
entities?: Record<string, EntityAuditConfig>;
|
|
87
|
+
operations?: Record<string, OperationAuditConfig>;
|
|
88
|
+
security?: {
|
|
89
|
+
hashChainEnabled?: boolean;
|
|
90
|
+
hashAlgorithm?: string;
|
|
91
|
+
masking?: {
|
|
92
|
+
defaultStrategy?: MaskingStrategy;
|
|
93
|
+
strategies?: Record<string, MaskingStrategy>;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export interface EntityAuditConfig {
|
|
98
|
+
enabled?: boolean;
|
|
99
|
+
strategy?: RecordStrategy;
|
|
100
|
+
includeFields?: string[];
|
|
101
|
+
excludeFields?: string[];
|
|
102
|
+
maskFields?: string[];
|
|
103
|
+
templateKey?: string;
|
|
104
|
+
sensitiveFields?: string[];
|
|
105
|
+
}
|
|
106
|
+
export interface OperationAuditConfig {
|
|
107
|
+
enabled?: boolean;
|
|
108
|
+
strategy?: RecordStrategy;
|
|
109
|
+
}
|
|
110
|
+
export interface FieldDisplayOptions {
|
|
111
|
+
label?: string | Record<string, string>;
|
|
112
|
+
valueLabels?: Record<string, Record<string, string>>;
|
|
113
|
+
sensitive?: boolean;
|
|
114
|
+
formatter?: (value: any) => string;
|
|
115
|
+
}
|
|
116
|
+
export interface ControllerAuditOptions {
|
|
117
|
+
enabled?: boolean;
|
|
118
|
+
operations?: AuditOperation[];
|
|
119
|
+
}
|
|
120
|
+
export interface MethodAuditOptions {
|
|
121
|
+
enabled?: boolean;
|
|
122
|
+
}
|
|
123
|
+
export interface ChangeDetail {
|
|
124
|
+
fieldName: string;
|
|
125
|
+
fieldLabels?: Record<string, string>;
|
|
126
|
+
oldValue: any;
|
|
127
|
+
newValue: any;
|
|
128
|
+
displayOldValue?: Record<string, string>;
|
|
129
|
+
displayNewValue?: Record<string, string>;
|
|
130
|
+
changeType: ChangeType;
|
|
131
|
+
}
|
|
132
|
+
export interface RollbackAction {
|
|
133
|
+
type: RollbackActionType;
|
|
134
|
+
action: string;
|
|
135
|
+
params: Record<string, any>;
|
|
136
|
+
order: number;
|
|
137
|
+
handler?: string;
|
|
138
|
+
}
|
|
139
|
+
export interface OperationTemplateData {
|
|
140
|
+
key: string;
|
|
141
|
+
entityName: string;
|
|
142
|
+
operation: AuditOperation;
|
|
143
|
+
nameTemplates: Record<string, string>;
|
|
144
|
+
descriptionTemplates: Record<string, string>;
|
|
145
|
+
fieldLabels?: Record<string, Record<string, string>>;
|
|
146
|
+
valueDisplays?: Record<string, Record<string, Record<string, string>>>;
|
|
147
|
+
}
|
|
148
|
+
export interface ManualOperationData {
|
|
149
|
+
transactionId: string;
|
|
150
|
+
operationTemplateKey: string;
|
|
151
|
+
descriptionParams: Record<string, any>;
|
|
152
|
+
userId?: string;
|
|
153
|
+
username?: string;
|
|
154
|
+
requestIp?: string;
|
|
155
|
+
rollbackActions?: RollbackAction[];
|
|
156
|
+
}
|
|
157
|
+
export interface AuditOperationOptions {
|
|
158
|
+
templateKey: string;
|
|
159
|
+
descriptionParams?: (args: any[], result: any, context: any) => Record<string, any>;
|
|
160
|
+
rollbackActions?: (args: any[], result: any, context: any) => RollbackAction[];
|
|
161
|
+
autoTransaction?: boolean;
|
|
162
|
+
}
|
|
163
|
+
export interface EnhancedEntityAuditConfig extends EntityAuditConfig {
|
|
164
|
+
templateKey?: string;
|
|
165
|
+
fieldLabels?: Record<string, Record<string, string>>;
|
|
166
|
+
valueDisplays?: Record<string, Record<string, Record<string, string>>>;
|
|
167
|
+
}
|
|
168
|
+
export interface TransactionDescription {
|
|
169
|
+
operationName: string;
|
|
170
|
+
description: string;
|
|
171
|
+
changes: Array<{
|
|
172
|
+
entityName?: string;
|
|
173
|
+
entityId?: string;
|
|
174
|
+
operation?: AuditOperation;
|
|
175
|
+
type?: string;
|
|
176
|
+
description: string;
|
|
177
|
+
details: any;
|
|
178
|
+
createdAt: Date;
|
|
179
|
+
}>;
|
|
180
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit.interfaces';
|
|
@@ -0,0 +1,17 @@
|
|
|
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.interfaces"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ClsService } from 'nestjs-cls';
|
|
2
|
+
import { AuditContext } from '../interfaces';
|
|
3
|
+
export declare class AuditContextService {
|
|
4
|
+
private readonly cls;
|
|
5
|
+
constructor(cls: ClsService);
|
|
6
|
+
getCurrentContext(): Promise<AuditContext>;
|
|
7
|
+
setContext(context: Partial<AuditContext>): void;
|
|
8
|
+
clearContext(): void;
|
|
9
|
+
private getDefaultContext;
|
|
10
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.AuditContextService = void 0;
|
|
22
|
+
const common_1 = require("@nestjs/common");
|
|
23
|
+
const nestjs_cls_1 = require("nestjs-cls");
|
|
24
|
+
let AuditContextService = class AuditContextService {
|
|
25
|
+
constructor(cls) {
|
|
26
|
+
this.cls = cls;
|
|
27
|
+
}
|
|
28
|
+
getCurrentContext() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
return this.cls.get('auditContext') || this.getDefaultContext();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
setContext(context) {
|
|
34
|
+
const currentContext = this.cls.get('auditContext') || this.getDefaultContext();
|
|
35
|
+
this.cls.set('auditContext', Object.assign(Object.assign({}, currentContext), context));
|
|
36
|
+
}
|
|
37
|
+
clearContext() {
|
|
38
|
+
this.cls.set('auditContext', undefined);
|
|
39
|
+
}
|
|
40
|
+
getDefaultContext() {
|
|
41
|
+
return {
|
|
42
|
+
userId: 'system',
|
|
43
|
+
username: 'system',
|
|
44
|
+
requestId: '',
|
|
45
|
+
requestIp: '',
|
|
46
|
+
userAgent: '',
|
|
47
|
+
timestamp: new Date(),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.AuditContextService = AuditContextService;
|
|
52
|
+
exports.AuditContextService = AuditContextService = __decorate([
|
|
53
|
+
(0, common_1.Injectable)(),
|
|
54
|
+
__metadata("design:paramtypes", [nestjs_cls_1.ClsService])
|
|
55
|
+
], AuditContextService);
|