@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,59 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.MultiDatabaseService = void 0;
|
|
25
|
+
const common_1 = require("@nestjs/common");
|
|
26
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
27
|
+
const core_1 = require("@nestjs/core");
|
|
28
|
+
let MultiDatabaseService = class MultiDatabaseService {
|
|
29
|
+
constructor(moduleRef, config) {
|
|
30
|
+
this.moduleRef = moduleRef;
|
|
31
|
+
this.config = config;
|
|
32
|
+
}
|
|
33
|
+
getDataSource() {
|
|
34
|
+
return __awaiter(this, arguments, void 0, function* (connectionName = 'default') {
|
|
35
|
+
try {
|
|
36
|
+
const dataSource = this.moduleRef.get((0, typeorm_1.getDataSourceToken)(connectionName), { strict: false });
|
|
37
|
+
return dataSource;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new Error(`Failed to get DataSource for connection: ${connectionName}`);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
getMonitoredConnections() {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
return ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.connections) === null || _b === void 0 ? void 0 : _b.monitored) || ['default'];
|
|
47
|
+
}
|
|
48
|
+
getAuditConnection() {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
return ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.connections) === null || _b === void 0 ? void 0 : _b.audit) || 'default';
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.MultiDatabaseService = MultiDatabaseService;
|
|
54
|
+
exports.MultiDatabaseService = MultiDatabaseService = __decorate([
|
|
55
|
+
(0, common_1.Injectable)(),
|
|
56
|
+
__param(1, (0, common_1.Optional)()),
|
|
57
|
+
__param(1, (0, common_1.Inject)('AUDIT_CONFIG')),
|
|
58
|
+
__metadata("design:paramtypes", [core_1.ModuleRef, Object])
|
|
59
|
+
], MultiDatabaseService);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { OperationTemplateEntity, EntityTransactionEntity, EntityAuditLogEntity, ManualOperationLogEntity } from '../entities';
|
|
3
|
+
import { ChangeDetail, TransactionDescription } from '../interfaces';
|
|
4
|
+
export declare class OperationDescriptionService {
|
|
5
|
+
private readonly templateRepository;
|
|
6
|
+
private readonly transactionRepository;
|
|
7
|
+
private readonly auditLogRepository;
|
|
8
|
+
private readonly manualOperationRepository;
|
|
9
|
+
private templateCache;
|
|
10
|
+
constructor(templateRepository: Repository<OperationTemplateEntity>, transactionRepository: Repository<EntityTransactionEntity>, auditLogRepository: Repository<EntityAuditLogEntity>, manualOperationRepository: Repository<ManualOperationLogEntity>);
|
|
11
|
+
generateOperationName(templateKey: string, language?: string): Promise<string>;
|
|
12
|
+
generateDescription(templateKey: string, descriptionParams: Record<string, any>, language?: string): Promise<string>;
|
|
13
|
+
generateChangeDetails(changeDetails: ChangeDetail[], language?: string): Promise<any[]>;
|
|
14
|
+
getTransactionDescription(transactionId: string, language?: string): Promise<TransactionDescription>;
|
|
15
|
+
batchGetTransactionDescriptions(transactionIds: string[], language?: string): Promise<Record<string, TransactionDescription>>;
|
|
16
|
+
private fillTemplate;
|
|
17
|
+
private formatDisplayValue;
|
|
18
|
+
private getOperationTemplate;
|
|
19
|
+
clearTemplateCache(): void;
|
|
20
|
+
preloadTemplates(templateKeys: string[]): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.OperationDescriptionService = void 0;
|
|
25
|
+
const common_1 = require("@nestjs/common");
|
|
26
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
27
|
+
const typeorm_2 = require("typeorm");
|
|
28
|
+
const entities_1 = require("../entities");
|
|
29
|
+
let OperationDescriptionService = class OperationDescriptionService {
|
|
30
|
+
constructor(templateRepository, transactionRepository, auditLogRepository, manualOperationRepository) {
|
|
31
|
+
this.templateRepository = templateRepository;
|
|
32
|
+
this.transactionRepository = transactionRepository;
|
|
33
|
+
this.auditLogRepository = auditLogRepository;
|
|
34
|
+
this.manualOperationRepository = manualOperationRepository;
|
|
35
|
+
this.templateCache = new Map();
|
|
36
|
+
}
|
|
37
|
+
generateOperationName(templateKey_1) {
|
|
38
|
+
return __awaiter(this, arguments, void 0, function* (templateKey, language = 'zh') {
|
|
39
|
+
const template = yield this.getOperationTemplate(templateKey);
|
|
40
|
+
if (!template) {
|
|
41
|
+
return templateKey;
|
|
42
|
+
}
|
|
43
|
+
return template.nameTemplates[language] || template.nameTemplates['zh'] || templateKey;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
generateDescription(templateKey_1, descriptionParams_1) {
|
|
47
|
+
return __awaiter(this, arguments, void 0, function* (templateKey, descriptionParams, language = 'zh') {
|
|
48
|
+
const template = yield this.getOperationTemplate(templateKey);
|
|
49
|
+
if (!template) {
|
|
50
|
+
return templateKey;
|
|
51
|
+
}
|
|
52
|
+
const templateStr = template.descriptionTemplates[language] || template.descriptionTemplates['zh'] || templateKey;
|
|
53
|
+
return this.fillTemplate(templateStr, descriptionParams);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
generateChangeDetails(changeDetails_1) {
|
|
57
|
+
return __awaiter(this, arguments, void 0, function* (changeDetails, language = 'zh') {
|
|
58
|
+
return changeDetails.map((detail) => {
|
|
59
|
+
var _a, _b, _c;
|
|
60
|
+
return ({
|
|
61
|
+
fieldName: detail.fieldName,
|
|
62
|
+
fieldLabel: ((_a = detail.fieldLabels) === null || _a === void 0 ? void 0 : _a[language]) || detail.fieldName,
|
|
63
|
+
oldValue: this.formatDisplayValue(detail.oldValue, (_b = detail.displayOldValue) === null || _b === void 0 ? void 0 : _b[language]),
|
|
64
|
+
newValue: this.formatDisplayValue(detail.newValue, (_c = detail.displayNewValue) === null || _c === void 0 ? void 0 : _c[language]),
|
|
65
|
+
changeType: detail.changeType,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
getTransactionDescription(transactionId_1) {
|
|
71
|
+
return __awaiter(this, arguments, void 0, function* (transactionId, language = 'zh') {
|
|
72
|
+
const transaction = yield this.transactionRepository.findOne({
|
|
73
|
+
where: { id: transactionId },
|
|
74
|
+
});
|
|
75
|
+
if (!transaction) {
|
|
76
|
+
throw new Error(`Transaction ${transactionId} not found`);
|
|
77
|
+
}
|
|
78
|
+
const auditLogs = yield this.auditLogRepository.find({
|
|
79
|
+
where: { requestId: transactionId },
|
|
80
|
+
order: { createdAt: 'ASC' },
|
|
81
|
+
});
|
|
82
|
+
const manualOperations = yield this.manualOperationRepository.find({
|
|
83
|
+
where: { transactionId },
|
|
84
|
+
order: { createdAt: 'ASC' },
|
|
85
|
+
});
|
|
86
|
+
let operationName;
|
|
87
|
+
let description;
|
|
88
|
+
if (transaction.operationTemplateKey) {
|
|
89
|
+
operationName = yield this.generateOperationName(transaction.operationTemplateKey, language);
|
|
90
|
+
description = yield this.generateDescription(transaction.operationTemplateKey, transaction.descriptionParams || {}, language);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const firstLog = auditLogs[0];
|
|
94
|
+
if (firstLog && firstLog.operationTemplateKey) {
|
|
95
|
+
operationName = yield this.generateOperationName(firstLog.operationTemplateKey, language);
|
|
96
|
+
description = yield this.generateDescription(firstLog.operationTemplateKey, firstLog.descriptionParams || {}, language);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
operationName = 'Unknown Operation';
|
|
100
|
+
description = transaction.description || 'Unknown operation';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const changes = [];
|
|
104
|
+
for (const log of auditLogs) {
|
|
105
|
+
const changeDescription = log.operationTemplateKey
|
|
106
|
+
? yield this.generateDescription(log.operationTemplateKey, log.descriptionParams || {}, language)
|
|
107
|
+
: log.description || '';
|
|
108
|
+
const changeDetails = log.changeDetails
|
|
109
|
+
? yield this.generateChangeDetails(log.changeDetails, language)
|
|
110
|
+
: [];
|
|
111
|
+
changes.push({
|
|
112
|
+
entityName: log.entityType,
|
|
113
|
+
entityId: log.entityId,
|
|
114
|
+
operation: log.operation,
|
|
115
|
+
description: changeDescription,
|
|
116
|
+
details: changeDetails,
|
|
117
|
+
createdAt: log.createdAt,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
for (const manualOp of manualOperations) {
|
|
121
|
+
const opName = yield this.generateOperationName(manualOp.operationTemplateKey, language);
|
|
122
|
+
const opDescription = yield this.generateDescription(manualOp.operationTemplateKey, manualOp.descriptionParams, language);
|
|
123
|
+
changes.push({
|
|
124
|
+
type: 'manual',
|
|
125
|
+
description: `${opName}: ${opDescription}`,
|
|
126
|
+
details: manualOp.descriptionParams,
|
|
127
|
+
createdAt: manualOp.createdAt,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
changes.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
131
|
+
return {
|
|
132
|
+
operationName,
|
|
133
|
+
description,
|
|
134
|
+
changes,
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
batchGetTransactionDescriptions(transactionIds_1) {
|
|
139
|
+
return __awaiter(this, arguments, void 0, function* (transactionIds, language = 'zh') {
|
|
140
|
+
const results = {};
|
|
141
|
+
for (const transactionId of transactionIds) {
|
|
142
|
+
try {
|
|
143
|
+
results[transactionId] = yield this.getTransactionDescription(transactionId, language);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error(`Failed to get description for transaction ${transactionId}:`, error);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return results;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
fillTemplate(template, params) {
|
|
153
|
+
if (!template)
|
|
154
|
+
return '';
|
|
155
|
+
let result = template;
|
|
156
|
+
for (const [key, value] of Object.entries(params || {})) {
|
|
157
|
+
const placeholder = `{${key}}`;
|
|
158
|
+
if (result.includes(placeholder)) {
|
|
159
|
+
result = result.replace(new RegExp(placeholder.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), String(value || ''));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
formatDisplayValue(value, displayValue) {
|
|
165
|
+
if (displayValue !== undefined) {
|
|
166
|
+
return displayValue;
|
|
167
|
+
}
|
|
168
|
+
if (value === null || value === undefined) {
|
|
169
|
+
return '';
|
|
170
|
+
}
|
|
171
|
+
return String(value);
|
|
172
|
+
}
|
|
173
|
+
getOperationTemplate(templateKey) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
if (this.templateCache.has(templateKey)) {
|
|
176
|
+
return this.templateCache.get(templateKey);
|
|
177
|
+
}
|
|
178
|
+
const template = yield this.templateRepository.findOne({
|
|
179
|
+
where: { key: templateKey },
|
|
180
|
+
});
|
|
181
|
+
if (template) {
|
|
182
|
+
this.templateCache.set(templateKey, template);
|
|
183
|
+
}
|
|
184
|
+
return template;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
clearTemplateCache() {
|
|
188
|
+
this.templateCache.clear();
|
|
189
|
+
}
|
|
190
|
+
preloadTemplates(templateKeys) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
const templates = yield this.templateRepository
|
|
193
|
+
.createQueryBuilder('template')
|
|
194
|
+
.where('template.key IN (:...keys)', { keys: templateKeys })
|
|
195
|
+
.getMany();
|
|
196
|
+
for (const template of templates) {
|
|
197
|
+
this.templateCache.set(template.key, template);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
exports.OperationDescriptionService = OperationDescriptionService;
|
|
203
|
+
exports.OperationDescriptionService = OperationDescriptionService = __decorate([
|
|
204
|
+
(0, common_1.Injectable)(),
|
|
205
|
+
__param(0, (0, typeorm_1.InjectRepository)(entities_1.OperationTemplateEntity)),
|
|
206
|
+
__param(1, (0, typeorm_1.InjectRepository)(entities_1.EntityTransactionEntity)),
|
|
207
|
+
__param(2, (0, typeorm_1.InjectRepository)(entities_1.EntityAuditLogEntity)),
|
|
208
|
+
__param(3, (0, typeorm_1.InjectRepository)(entities_1.ManualOperationLogEntity)),
|
|
209
|
+
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
210
|
+
typeorm_2.Repository,
|
|
211
|
+
typeorm_2.Repository,
|
|
212
|
+
typeorm_2.Repository])
|
|
213
|
+
], OperationDescriptionService);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { EntityTransactionEntity } from '../entities';
|
|
3
|
+
import { AuditOperation } from '../enums';
|
|
4
|
+
import { AuditContextService } from './audit-context.service';
|
|
5
|
+
import { EntityAuditService } from './entity-audit.service';
|
|
6
|
+
import { MultiDatabaseService } from './multi-database.service';
|
|
7
|
+
export declare class TransactionAuditService {
|
|
8
|
+
private readonly transactionRepository;
|
|
9
|
+
private readonly contextService;
|
|
10
|
+
private readonly auditService;
|
|
11
|
+
private readonly multiDbService;
|
|
12
|
+
constructor(transactionRepository: Repository<EntityTransactionEntity>, contextService: AuditContextService, auditService: EntityAuditService, multiDbService: MultiDatabaseService);
|
|
13
|
+
beginTransaction(description: string): Promise<string>;
|
|
14
|
+
commitTransaction(transactionId: string): Promise<void>;
|
|
15
|
+
rollbackTransaction(transactionId: string): Promise<void>;
|
|
16
|
+
addEntityToTransaction(transactionId: string, entityType: string, entityId: string, operation: AuditOperation): Promise<void>;
|
|
17
|
+
private performRollback;
|
|
18
|
+
private groupEntitiesByConnection;
|
|
19
|
+
private rollbackEntitiesInConnection;
|
|
20
|
+
private rollbackSingleEntity;
|
|
21
|
+
private getLatestAuditLog;
|
|
22
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.TransactionAuditService = void 0;
|
|
25
|
+
const common_1 = require("@nestjs/common");
|
|
26
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
27
|
+
const typeorm_2 = require("typeorm");
|
|
28
|
+
const entities_1 = require("../entities");
|
|
29
|
+
const enums_1 = require("../enums");
|
|
30
|
+
const audit_context_service_1 = require("./audit-context.service");
|
|
31
|
+
const entity_audit_service_1 = require("./entity-audit.service");
|
|
32
|
+
const multi_database_service_1 = require("./multi-database.service");
|
|
33
|
+
let TransactionAuditService = class TransactionAuditService {
|
|
34
|
+
constructor(transactionRepository, contextService, auditService, multiDbService) {
|
|
35
|
+
this.transactionRepository = transactionRepository;
|
|
36
|
+
this.contextService = contextService;
|
|
37
|
+
this.auditService = auditService;
|
|
38
|
+
this.multiDbService = multiDbService;
|
|
39
|
+
}
|
|
40
|
+
beginTransaction(description) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const context = yield this.contextService.getCurrentContext();
|
|
43
|
+
const transaction = this.transactionRepository.create({
|
|
44
|
+
description,
|
|
45
|
+
status: enums_1.TransactionStatus.PENDING,
|
|
46
|
+
entities: [],
|
|
47
|
+
userId: context.userId,
|
|
48
|
+
username: context.username,
|
|
49
|
+
});
|
|
50
|
+
const savedTransaction = yield this.transactionRepository.save(transaction);
|
|
51
|
+
this.contextService.setContext({
|
|
52
|
+
transactionId: savedTransaction.id,
|
|
53
|
+
});
|
|
54
|
+
return savedTransaction.id;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
commitTransaction(transactionId) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const transaction = yield this.transactionRepository.findOne({
|
|
60
|
+
where: { id: transactionId },
|
|
61
|
+
});
|
|
62
|
+
if (!transaction) {
|
|
63
|
+
throw new Error(`Transaction not found: ${transactionId}`);
|
|
64
|
+
}
|
|
65
|
+
transaction.status = enums_1.TransactionStatus.COMMITTED;
|
|
66
|
+
yield this.transactionRepository.save(transaction);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
rollbackTransaction(transactionId) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const transaction = yield this.transactionRepository.findOne({
|
|
72
|
+
where: { id: transactionId },
|
|
73
|
+
});
|
|
74
|
+
if (!transaction) {
|
|
75
|
+
throw new Error(`Transaction not found: ${transactionId}`);
|
|
76
|
+
}
|
|
77
|
+
yield this.performRollback(transaction);
|
|
78
|
+
transaction.status = enums_1.TransactionStatus.ROLLED_BACK;
|
|
79
|
+
yield this.transactionRepository.save(transaction);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
addEntityToTransaction(transactionId, entityType, entityId, operation) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const transaction = yield this.transactionRepository.findOne({
|
|
85
|
+
where: { id: transactionId },
|
|
86
|
+
});
|
|
87
|
+
if (!transaction) {
|
|
88
|
+
throw new Error(`Transaction not found: ${transactionId}`);
|
|
89
|
+
}
|
|
90
|
+
transaction.entities.push({
|
|
91
|
+
entityType,
|
|
92
|
+
entityId,
|
|
93
|
+
operation,
|
|
94
|
+
});
|
|
95
|
+
yield this.transactionRepository.save(transaction);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
performRollback(transaction) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const reversedEntities = [...transaction.entities].reverse();
|
|
101
|
+
const entitiesByConnection = yield this.groupEntitiesByConnection(reversedEntities);
|
|
102
|
+
for (const [connectionName, entities] of Object.entries(entitiesByConnection)) {
|
|
103
|
+
yield this.rollbackEntitiesInConnection(connectionName, entities);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
groupEntitiesByConnection(entities) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const grouped = {};
|
|
110
|
+
const monitoredConnections = this.multiDbService.getMonitoredConnections();
|
|
111
|
+
for (const entity of entities) {
|
|
112
|
+
let connectionFound = false;
|
|
113
|
+
for (const connectionName of monitoredConnections) {
|
|
114
|
+
try {
|
|
115
|
+
const dataSource = yield this.multiDbService.getDataSource(connectionName);
|
|
116
|
+
const metadata = dataSource.getMetadata(entity.entityType);
|
|
117
|
+
if (metadata) {
|
|
118
|
+
if (!grouped[connectionName]) {
|
|
119
|
+
grouped[connectionName] = [];
|
|
120
|
+
}
|
|
121
|
+
grouped[connectionName].push(entity);
|
|
122
|
+
connectionFound = true;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (!connectionFound) {
|
|
131
|
+
const defaultConnection = 'default';
|
|
132
|
+
if (!grouped[defaultConnection]) {
|
|
133
|
+
grouped[defaultConnection] = [];
|
|
134
|
+
}
|
|
135
|
+
grouped[defaultConnection].push(entity);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return grouped;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
rollbackEntitiesInConnection(connectionName, entities) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
const dataSource = yield this.multiDbService.getDataSource(connectionName);
|
|
144
|
+
yield dataSource.transaction((manager) => __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
for (const entity of entities) {
|
|
146
|
+
try {
|
|
147
|
+
yield this.rollbackSingleEntity(manager, entity, connectionName);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
console.error(`Failed to rollback entity ${entity.entityType}:${entity.entityId} in connection ${connectionName}:`, error);
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}));
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
rollbackSingleEntity(manager, entity, connectionName) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const repository = manager.getRepository(entity.entityType);
|
|
160
|
+
switch (entity.operation) {
|
|
161
|
+
case enums_1.AuditOperation.CREATE:
|
|
162
|
+
yield repository.delete({ id: entity.entityId });
|
|
163
|
+
break;
|
|
164
|
+
case enums_1.AuditOperation.UPDATE:
|
|
165
|
+
const auditLog = yield this.getLatestAuditLog(entity.entityType, entity.entityId);
|
|
166
|
+
if (auditLog && auditLog.oldValue) {
|
|
167
|
+
yield repository.update({ id: entity.entityId }, auditLog.oldValue);
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
case enums_1.AuditOperation.DELETE:
|
|
171
|
+
const deletedAuditLog = yield this.getLatestAuditLog(entity.entityType, entity.entityId);
|
|
172
|
+
if (deletedAuditLog && deletedAuditLog.oldValue) {
|
|
173
|
+
yield repository.save(deletedAuditLog.oldValue);
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
case enums_1.AuditOperation.RESTORE:
|
|
177
|
+
const restoreAuditLog = yield this.getLatestAuditLog(entity.entityType, entity.entityId);
|
|
178
|
+
if (restoreAuditLog && restoreAuditLog.oldValue) {
|
|
179
|
+
yield repository.update({ id: entity.entityId }, restoreAuditLog.oldValue);
|
|
180
|
+
}
|
|
181
|
+
break;
|
|
182
|
+
default:
|
|
183
|
+
console.warn(`Unknown operation type: ${entity.operation}`);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
getLatestAuditLog(entityType, entityId) {
|
|
188
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
+
return null;
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
exports.TransactionAuditService = TransactionAuditService;
|
|
194
|
+
exports.TransactionAuditService = TransactionAuditService = __decorate([
|
|
195
|
+
(0, common_1.Injectable)(),
|
|
196
|
+
__param(0, (0, typeorm_1.InjectRepository)(entities_1.EntityTransactionEntity)),
|
|
197
|
+
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
198
|
+
audit_context_service_1.AuditContextService,
|
|
199
|
+
entity_audit_service_1.EntityAuditService,
|
|
200
|
+
multi_database_service_1.MultiDatabaseService])
|
|
201
|
+
], TransactionAuditService);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EntitySubscriberInterface, InsertEvent, UpdateEvent, RemoveEvent, DataSource } from 'typeorm';
|
|
2
|
+
import { EntityAuditService } from '../services/entity-audit.service';
|
|
3
|
+
import { AuditContextService } from '../services/audit-context.service';
|
|
4
|
+
import { DefaultAuditStrategy } from '../services/audit-strategy.service';
|
|
5
|
+
export declare class EntityAuditSubscriber implements EntitySubscriberInterface<any> {
|
|
6
|
+
private readonly entityAuditService;
|
|
7
|
+
private readonly contextService;
|
|
8
|
+
private readonly auditStrategy;
|
|
9
|
+
constructor(entityAuditService: EntityAuditService, contextService: AuditContextService, auditStrategy: DefaultAuditStrategy, dataSource: DataSource);
|
|
10
|
+
afterInsert(event: InsertEvent<any>): Promise<void>;
|
|
11
|
+
afterUpdate(event: UpdateEvent<any>): Promise<void>;
|
|
12
|
+
beforeRemove(event: RemoveEvent<any>): Promise<void>;
|
|
13
|
+
private isAuditEnabled;
|
|
14
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
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.EntityAuditSubscriber = void 0;
|
|
22
|
+
const common_1 = require("@nestjs/common");
|
|
23
|
+
const typeorm_1 = require("typeorm");
|
|
24
|
+
const entity_audit_service_1 = require("../services/entity-audit.service");
|
|
25
|
+
const audit_context_service_1 = require("../services/audit-context.service");
|
|
26
|
+
const audit_strategy_service_1 = require("../services/audit-strategy.service");
|
|
27
|
+
const enums_1 = require("../enums");
|
|
28
|
+
const decorators_1 = require("../decorators");
|
|
29
|
+
let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
30
|
+
constructor(entityAuditService, contextService, auditStrategy, dataSource) {
|
|
31
|
+
this.entityAuditService = entityAuditService;
|
|
32
|
+
this.contextService = contextService;
|
|
33
|
+
this.auditStrategy = auditStrategy;
|
|
34
|
+
dataSource.subscribers.push(this);
|
|
35
|
+
}
|
|
36
|
+
afterInsert(event) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const entity = event.entity;
|
|
39
|
+
if (!entity)
|
|
40
|
+
return;
|
|
41
|
+
const entityType = entity.constructor.name;
|
|
42
|
+
const entityId = entity.id;
|
|
43
|
+
if (!this.isAuditEnabled(entity)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (!this.auditStrategy.shouldRecord(entityType, enums_1.AuditOperation.CREATE)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const context = yield this.contextService.getCurrentContext();
|
|
51
|
+
yield this.entityAuditService.logEntityChange(entityType, entityId, enums_1.AuditOperation.CREATE, {}, entity, {
|
|
52
|
+
requestId: context.requestId,
|
|
53
|
+
requestIp: context.requestIp,
|
|
54
|
+
userAgent: context.userAgent,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error('Failed to log audit for insert:', error);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
afterUpdate(event) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const entity = event.entity;
|
|
65
|
+
const databaseEntity = event.databaseEntity;
|
|
66
|
+
if (!entity)
|
|
67
|
+
return;
|
|
68
|
+
const entityType = entity.constructor.name;
|
|
69
|
+
const entityId = entity.id;
|
|
70
|
+
if (!this.isAuditEnabled(entity)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!this.auditStrategy.shouldRecord(entityType, enums_1.AuditOperation.UPDATE)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const context = yield this.contextService.getCurrentContext();
|
|
78
|
+
yield this.entityAuditService.logEntityChange(entityType, entityId, enums_1.AuditOperation.UPDATE, databaseEntity || {}, entity, {
|
|
79
|
+
requestId: context.requestId,
|
|
80
|
+
requestIp: context.requestIp,
|
|
81
|
+
userAgent: context.userAgent,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error('Failed to log audit for update:', error);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
beforeRemove(event) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const entity = event.entity;
|
|
92
|
+
if (!entity)
|
|
93
|
+
return;
|
|
94
|
+
const entityType = entity.constructor.name;
|
|
95
|
+
const entityId = entity.id;
|
|
96
|
+
if (!this.isAuditEnabled(entity)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (!this.auditStrategy.shouldRecord(entityType, enums_1.AuditOperation.DELETE)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const context = yield this.contextService.getCurrentContext();
|
|
104
|
+
yield this.entityAuditService.logEntityChange(entityType, entityId, enums_1.AuditOperation.DELETE, entity, {}, {
|
|
105
|
+
requestId: context.requestId,
|
|
106
|
+
requestIp: context.requestIp,
|
|
107
|
+
userAgent: context.userAgent,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error('Failed to log audit for delete:', error);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
isAuditEnabled(entity) {
|
|
116
|
+
try {
|
|
117
|
+
const auditOptions = Reflect.getMetadata(decorators_1.ENTITY_AUDIT_OPTIONS, entity.constructor);
|
|
118
|
+
if (auditOptions && auditOptions.enabled === false) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
exports.EntityAuditSubscriber = EntityAuditSubscriber;
|
|
129
|
+
exports.EntityAuditSubscriber = EntityAuditSubscriber = __decorate([
|
|
130
|
+
(0, common_1.Injectable)(),
|
|
131
|
+
(0, typeorm_1.EventSubscriber)(),
|
|
132
|
+
__metadata("design:paramtypes", [entity_audit_service_1.EntityAuditService,
|
|
133
|
+
audit_context_service_1.AuditContextService,
|
|
134
|
+
audit_strategy_service_1.DefaultAuditStrategy,
|
|
135
|
+
typeorm_1.DataSource])
|
|
136
|
+
], EntityAuditSubscriber);
|