@nest-omni/core 3.1.2-8 → 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/http-client/examples/advanced-usage.example.js +14 -1
- 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 +1 -9
- package/http-client/examples/basic-usage.example.js +4 -14
- package/http-client/examples/multi-api-configuration.example.js +4 -4
- package/http-client/http-client.module.js +7 -4
- package/http-client/services/api-client-registry.service.d.ts +2 -1
- package/http-client/services/api-client-registry.service.js +2 -1
- package/http-client/services/http-client.service.d.ts +18 -1
- package/http-client/services/http-client.service.js +123 -3
- package/http-client/services/http-log-query.service.d.ts +20 -0
- package/http-client/services/http-log-query.service.js +176 -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/log-cleanup.service.js +2 -2
- package/http-client/services/logging.service.js +1 -1
- package/http-client/utils/request-id.util.d.ts +4 -0
- package/http-client/utils/request-id.util.js +34 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/setup/bootstrap.setup.js +5 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { AuditConfig } from './interfaces';
|
|
3
|
+
export declare class AuditModule {
|
|
4
|
+
static forRoot(config?: AuditConfig): DynamicModule;
|
|
5
|
+
static forRootAsync(options: {
|
|
6
|
+
imports?: any[];
|
|
7
|
+
inject?: any[];
|
|
8
|
+
useFactory: (...args: any[]) => Promise<AuditConfig> | AuditConfig;
|
|
9
|
+
}): DynamicModule;
|
|
10
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var AuditModule_1;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.AuditModule = void 0;
|
|
20
|
+
const common_1 = require("@nestjs/common");
|
|
21
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
22
|
+
const nestjs_cls_1 = require("nestjs-cls");
|
|
23
|
+
const entities_1 = require("./entities");
|
|
24
|
+
const services_1 = require("./services");
|
|
25
|
+
const subscribers_1 = require("./subscribers");
|
|
26
|
+
const interceptors_1 = require("./interceptors");
|
|
27
|
+
const controllers_1 = require("./controllers");
|
|
28
|
+
let AuditModule = AuditModule_1 = class AuditModule {
|
|
29
|
+
static forRoot(config) {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
const auditConnectionName = ((_a = config === null || config === void 0 ? void 0 : config.connections) === null || _a === void 0 ? void 0 : _a.audit) || 'default';
|
|
32
|
+
const monitoredConnections = ((_b = config === null || config === void 0 ? void 0 : config.connections) === null || _b === void 0 ? void 0 : _b.monitored) || ['default'];
|
|
33
|
+
const subscriberProviders = monitoredConnections.map((connectionName) => ({
|
|
34
|
+
provide: `AUDIT_SUBSCRIBER_${connectionName}`,
|
|
35
|
+
useFactory: (auditService, contextService, auditStrategy, dataSource) => {
|
|
36
|
+
const subscriber = new subscribers_1.EntityAuditSubscriber(auditService, contextService, auditStrategy, dataSource);
|
|
37
|
+
return subscriber;
|
|
38
|
+
},
|
|
39
|
+
inject: [
|
|
40
|
+
services_1.EntityAuditService,
|
|
41
|
+
services_1.AuditContextService,
|
|
42
|
+
services_1.DefaultAuditStrategy,
|
|
43
|
+
(0, typeorm_1.getDataSourceToken)(connectionName),
|
|
44
|
+
],
|
|
45
|
+
}));
|
|
46
|
+
const repositoryProviders = [
|
|
47
|
+
{
|
|
48
|
+
provide: (0, typeorm_1.getRepositoryToken)(entities_1.EntityAuditLogEntity),
|
|
49
|
+
useFactory: (dataSource) => {
|
|
50
|
+
return dataSource.getRepository(entities_1.EntityAuditLogEntity);
|
|
51
|
+
},
|
|
52
|
+
inject: [(0, typeorm_1.getDataSourceToken)(auditConnectionName)],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
provide: (0, typeorm_1.getRepositoryToken)(entities_1.EntityTransactionEntity),
|
|
56
|
+
useFactory: (dataSource) => {
|
|
57
|
+
return dataSource.getRepository(entities_1.EntityTransactionEntity);
|
|
58
|
+
},
|
|
59
|
+
inject: [(0, typeorm_1.getDataSourceToken)(auditConnectionName)],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
provide: (0, typeorm_1.getRepositoryToken)(entities_1.OperationTemplateEntity),
|
|
63
|
+
useFactory: (dataSource) => {
|
|
64
|
+
return dataSource.getRepository(entities_1.OperationTemplateEntity);
|
|
65
|
+
},
|
|
66
|
+
inject: [(0, typeorm_1.getDataSourceToken)(auditConnectionName)],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
provide: (0, typeorm_1.getRepositoryToken)(entities_1.ManualOperationLogEntity),
|
|
70
|
+
useFactory: (dataSource) => {
|
|
71
|
+
return dataSource.getRepository(entities_1.ManualOperationLogEntity);
|
|
72
|
+
},
|
|
73
|
+
inject: [(0, typeorm_1.getDataSourceToken)(auditConnectionName)],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
provide: 'AUDIT_ENTITY_MANAGER',
|
|
77
|
+
useFactory: (dataSource) => {
|
|
78
|
+
return dataSource.manager;
|
|
79
|
+
},
|
|
80
|
+
inject: [(0, typeorm_1.getDataSourceToken)(auditConnectionName)],
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
return {
|
|
84
|
+
module: AuditModule_1,
|
|
85
|
+
imports: [
|
|
86
|
+
typeorm_1.TypeOrmModule.forFeature([
|
|
87
|
+
entities_1.EntityAuditLogEntity,
|
|
88
|
+
entities_1.EntityTransactionEntity,
|
|
89
|
+
entities_1.OperationTemplateEntity,
|
|
90
|
+
entities_1.ManualOperationLogEntity,
|
|
91
|
+
], auditConnectionName),
|
|
92
|
+
nestjs_cls_1.ClsModule.forRoot({
|
|
93
|
+
global: true,
|
|
94
|
+
middleware: { mount: true },
|
|
95
|
+
}),
|
|
96
|
+
],
|
|
97
|
+
controllers: [controllers_1.AuditController],
|
|
98
|
+
providers: [
|
|
99
|
+
{
|
|
100
|
+
provide: 'AUDIT_CONFIG',
|
|
101
|
+
useValue: config || {},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
provide: 'AUDIT_STRATEGY',
|
|
105
|
+
useClass: services_1.DefaultAuditStrategy,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
provide: 'AUDIT_CONNECTION_NAME',
|
|
109
|
+
useValue: auditConnectionName,
|
|
110
|
+
},
|
|
111
|
+
services_1.AuditContextService,
|
|
112
|
+
services_1.DefaultAuditStrategy,
|
|
113
|
+
services_1.MultiDatabaseService,
|
|
114
|
+
...repositoryProviders,
|
|
115
|
+
services_1.EntityAuditService,
|
|
116
|
+
services_1.TransactionAuditService,
|
|
117
|
+
services_1.OperationDescriptionService,
|
|
118
|
+
interceptors_1.AuditInterceptor,
|
|
119
|
+
...subscriberProviders,
|
|
120
|
+
],
|
|
121
|
+
exports: [
|
|
122
|
+
services_1.AuditContextService,
|
|
123
|
+
services_1.DefaultAuditStrategy,
|
|
124
|
+
services_1.MultiDatabaseService,
|
|
125
|
+
services_1.EntityAuditService,
|
|
126
|
+
services_1.TransactionAuditService,
|
|
127
|
+
services_1.OperationDescriptionService,
|
|
128
|
+
interceptors_1.AuditInterceptor,
|
|
129
|
+
],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
static forRootAsync(options) {
|
|
133
|
+
const repositoryProviders = [
|
|
134
|
+
{
|
|
135
|
+
provide: (0, typeorm_1.getRepositoryToken)(entities_1.EntityAuditLogEntity),
|
|
136
|
+
useFactory: (dataSource, ...args) => __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
var _a;
|
|
138
|
+
const config = yield options.useFactory(...args);
|
|
139
|
+
const auditConnectionName = ((_a = config === null || config === void 0 ? void 0 : config.connections) === null || _a === void 0 ? void 0 : _a.audit) || 'default';
|
|
140
|
+
return dataSource.getRepository(entities_1.EntityAuditLogEntity);
|
|
141
|
+
}),
|
|
142
|
+
inject: [
|
|
143
|
+
{
|
|
144
|
+
token: (0, typeorm_1.getDataSourceToken)(),
|
|
145
|
+
optional: false,
|
|
146
|
+
},
|
|
147
|
+
...(options.inject || []),
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
provide: (0, typeorm_1.getRepositoryToken)(entities_1.EntityTransactionEntity),
|
|
152
|
+
useFactory: (dataSource, ...args) => __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
var _a;
|
|
154
|
+
const config = yield options.useFactory(...args);
|
|
155
|
+
const auditConnectionName = ((_a = config === null || config === void 0 ? void 0 : config.connections) === null || _a === void 0 ? void 0 : _a.audit) || 'default';
|
|
156
|
+
return dataSource.getRepository(entities_1.EntityTransactionEntity);
|
|
157
|
+
}),
|
|
158
|
+
inject: [
|
|
159
|
+
{
|
|
160
|
+
token: (0, typeorm_1.getDataSourceToken)(),
|
|
161
|
+
optional: false,
|
|
162
|
+
},
|
|
163
|
+
...(options.inject || []),
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
provide: 'AUDIT_ENTITY_MANAGER',
|
|
168
|
+
useFactory: (dataSource, ...args) => __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
var _a;
|
|
170
|
+
const config = yield options.useFactory(...args);
|
|
171
|
+
const auditConnectionName = ((_a = config === null || config === void 0 ? void 0 : config.connections) === null || _a === void 0 ? void 0 : _a.audit) || 'default';
|
|
172
|
+
return dataSource.manager;
|
|
173
|
+
}),
|
|
174
|
+
inject: [
|
|
175
|
+
{
|
|
176
|
+
token: (0, typeorm_1.getDataSourceToken)(),
|
|
177
|
+
optional: false,
|
|
178
|
+
},
|
|
179
|
+
...(options.inject || []),
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
return {
|
|
184
|
+
module: AuditModule_1,
|
|
185
|
+
imports: [
|
|
186
|
+
nestjs_cls_1.ClsModule.forRoot({
|
|
187
|
+
global: true,
|
|
188
|
+
middleware: { mount: true },
|
|
189
|
+
}),
|
|
190
|
+
...(options.imports || []),
|
|
191
|
+
],
|
|
192
|
+
controllers: [controllers_1.AuditController],
|
|
193
|
+
providers: [
|
|
194
|
+
{
|
|
195
|
+
provide: 'AUDIT_CONFIG',
|
|
196
|
+
useFactory: options.useFactory,
|
|
197
|
+
inject: options.inject || [],
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
provide: 'AUDIT_STRATEGY',
|
|
201
|
+
useClass: services_1.DefaultAuditStrategy,
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
provide: 'AUDIT_CONNECTION_NAME',
|
|
205
|
+
useFactory: (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
var _a;
|
|
207
|
+
const config = yield options.useFactory(...args);
|
|
208
|
+
return ((_a = config === null || config === void 0 ? void 0 : config.connections) === null || _a === void 0 ? void 0 : _a.audit) || 'default';
|
|
209
|
+
}),
|
|
210
|
+
inject: options.inject || [],
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
provide: 'AUDIT_SUBSCRIBERS',
|
|
214
|
+
useFactory: (auditService, contextService, auditStrategy, ...args) => __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
var _a, _b;
|
|
216
|
+
const config = yield options.useFactory(...args);
|
|
217
|
+
const monitoredConnections = ((_a = config === null || config === void 0 ? void 0 : config.connections) === null || _a === void 0 ? void 0 : _a.monitored) || ['default'];
|
|
218
|
+
const auditConnectionName = ((_b = config === null || config === void 0 ? void 0 : config.connections) === null || _b === void 0 ? void 0 : _b.audit) || 'default';
|
|
219
|
+
const typeOrmModule = typeorm_1.TypeOrmModule.forFeature([entities_1.EntityAuditLogEntity, entities_1.EntityTransactionEntity], auditConnectionName);
|
|
220
|
+
return monitoredConnections;
|
|
221
|
+
}),
|
|
222
|
+
inject: [
|
|
223
|
+
services_1.EntityAuditService,
|
|
224
|
+
services_1.AuditContextService,
|
|
225
|
+
services_1.DefaultAuditStrategy,
|
|
226
|
+
...(options.inject || []),
|
|
227
|
+
],
|
|
228
|
+
},
|
|
229
|
+
services_1.AuditContextService,
|
|
230
|
+
services_1.DefaultAuditStrategy,
|
|
231
|
+
services_1.MultiDatabaseService,
|
|
232
|
+
...repositoryProviders,
|
|
233
|
+
services_1.EntityAuditService,
|
|
234
|
+
services_1.TransactionAuditService,
|
|
235
|
+
services_1.OperationDescriptionService,
|
|
236
|
+
interceptors_1.AuditInterceptor,
|
|
237
|
+
],
|
|
238
|
+
exports: [
|
|
239
|
+
services_1.AuditContextService,
|
|
240
|
+
services_1.DefaultAuditStrategy,
|
|
241
|
+
services_1.MultiDatabaseService,
|
|
242
|
+
services_1.EntityAuditService,
|
|
243
|
+
services_1.TransactionAuditService,
|
|
244
|
+
services_1.OperationDescriptionService,
|
|
245
|
+
interceptors_1.AuditInterceptor,
|
|
246
|
+
],
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
exports.AuditModule = AuditModule;
|
|
251
|
+
exports.AuditModule = AuditModule = AuditModule_1 = __decorate([
|
|
252
|
+
(0, common_1.Global)(),
|
|
253
|
+
(0, common_1.Module)({})
|
|
254
|
+
], AuditModule);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EntityAuditService } from '../services/entity-audit.service';
|
|
2
|
+
import { TransactionAuditService } from '../services/transaction-audit.service';
|
|
3
|
+
import { AuditLogQueryDto, CompareEntitiesDto, RestoreEntityDto, PreCheckRestoreDto, BeginTransactionDto } from '../dto';
|
|
4
|
+
import { EntityAuditLogEntity } from '../entities';
|
|
5
|
+
import { EntityDifference, PreCheckResult, RestoreResult } from '../interfaces';
|
|
6
|
+
import { PageDto } from '../../common/dto';
|
|
7
|
+
export declare class AuditController {
|
|
8
|
+
private readonly entityAuditService;
|
|
9
|
+
private readonly transactionAuditService;
|
|
10
|
+
constructor(entityAuditService: EntityAuditService, transactionAuditService: TransactionAuditService);
|
|
11
|
+
getAuditLogs(query: AuditLogQueryDto): Promise<PageDto<EntityAuditLogEntity>>;
|
|
12
|
+
compareEntities(query: CompareEntitiesDto): Promise<EntityDifference>;
|
|
13
|
+
preCheckRestore(preCheckDto: PreCheckRestoreDto): Promise<PreCheckResult>;
|
|
14
|
+
restoreEntity(restoreDto: RestoreEntityDto): Promise<RestoreResult>;
|
|
15
|
+
beginTransaction(beginTransactionDto: BeginTransactionDto): Promise<{
|
|
16
|
+
transactionId: string;
|
|
17
|
+
}>;
|
|
18
|
+
commitTransaction(transactionId: string): Promise<void>;
|
|
19
|
+
rollbackTransaction(transactionId: string): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
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.AuditController = void 0;
|
|
25
|
+
const common_1 = require("@nestjs/common");
|
|
26
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
27
|
+
const entity_audit_service_1 = require("../services/entity-audit.service");
|
|
28
|
+
const transaction_audit_service_1 = require("../services/transaction-audit.service");
|
|
29
|
+
const dto_1 = require("../dto");
|
|
30
|
+
let AuditController = class AuditController {
|
|
31
|
+
constructor(entityAuditService, transactionAuditService) {
|
|
32
|
+
this.entityAuditService = entityAuditService;
|
|
33
|
+
this.transactionAuditService = transactionAuditService;
|
|
34
|
+
}
|
|
35
|
+
getAuditLogs(query) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
return this.entityAuditService.getAuditLogs(query);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
compareEntities(query) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
return this.entityAuditService.compareEntities(query.entityType, query.entityId, (_a = query.fromVersion) === null || _a === void 0 ? void 0 : _a.toString(), (_b = query.toVersion) === null || _b === void 0 ? void 0 : _b.toString());
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
preCheckRestore(preCheckDto) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
return this.entityAuditService.preCheckRestore(preCheckDto.entityType, preCheckDto.entityId, preCheckDto.auditLogId);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
restoreEntity(restoreDto) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
return this.entityAuditService.restoreEntity(restoreDto.entityType, restoreDto.entityId, restoreDto.auditLogId, restoreDto.options);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
beginTransaction(beginTransactionDto) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const transactionId = yield this.transactionAuditService.beginTransaction(beginTransactionDto.description);
|
|
59
|
+
return { transactionId };
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
commitTransaction(transactionId) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
return this.transactionAuditService.commitTransaction(transactionId);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
rollbackTransaction(transactionId) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
return this.transactionAuditService.rollbackTransaction(transactionId);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
exports.AuditController = AuditController;
|
|
74
|
+
__decorate([
|
|
75
|
+
(0, common_1.Get)('logs'),
|
|
76
|
+
(0, swagger_1.ApiOperation)({ summary: '查询实体审计日志' }),
|
|
77
|
+
(0, swagger_1.ApiResponse)({ status: 200, description: '成功返回审计日志列表' }),
|
|
78
|
+
__param(0, (0, common_1.Query)()),
|
|
79
|
+
__metadata("design:type", Function),
|
|
80
|
+
__metadata("design:paramtypes", [dto_1.AuditLogQueryDto]),
|
|
81
|
+
__metadata("design:returntype", Promise)
|
|
82
|
+
], AuditController.prototype, "getAuditLogs", null);
|
|
83
|
+
__decorate([
|
|
84
|
+
(0, common_1.Get)('compare'),
|
|
85
|
+
(0, swagger_1.ApiOperation)({ summary: '比较实体版本' }),
|
|
86
|
+
(0, swagger_1.ApiResponse)({ status: 200, description: '成功返回比较结果' }),
|
|
87
|
+
__param(0, (0, common_1.Query)()),
|
|
88
|
+
__metadata("design:type", Function),
|
|
89
|
+
__metadata("design:paramtypes", [dto_1.CompareEntitiesDto]),
|
|
90
|
+
__metadata("design:returntype", Promise)
|
|
91
|
+
], AuditController.prototype, "compareEntities", null);
|
|
92
|
+
__decorate([
|
|
93
|
+
(0, common_1.Post)('restore/precheck'),
|
|
94
|
+
(0, swagger_1.ApiOperation)({ summary: '预检查恢复操作' }),
|
|
95
|
+
(0, swagger_1.ApiResponse)({ status: 200, description: '成功返回预检查结果' }),
|
|
96
|
+
__param(0, (0, common_1.Body)()),
|
|
97
|
+
__metadata("design:type", Function),
|
|
98
|
+
__metadata("design:paramtypes", [dto_1.PreCheckRestoreDto]),
|
|
99
|
+
__metadata("design:returntype", Promise)
|
|
100
|
+
], AuditController.prototype, "preCheckRestore", null);
|
|
101
|
+
__decorate([
|
|
102
|
+
(0, common_1.Post)('restore'),
|
|
103
|
+
(0, swagger_1.ApiOperation)({ summary: '恢复实体到指定版本' }),
|
|
104
|
+
(0, swagger_1.ApiResponse)({ status: 200, description: '成功恢复实体' }),
|
|
105
|
+
__param(0, (0, common_1.Body)()),
|
|
106
|
+
__metadata("design:type", Function),
|
|
107
|
+
__metadata("design:paramtypes", [dto_1.RestoreEntityDto]),
|
|
108
|
+
__metadata("design:returntype", Promise)
|
|
109
|
+
], AuditController.prototype, "restoreEntity", null);
|
|
110
|
+
__decorate([
|
|
111
|
+
(0, common_1.Post)('transactions'),
|
|
112
|
+
(0, swagger_1.ApiOperation)({ summary: '开始审计事务' }),
|
|
113
|
+
(0, swagger_1.ApiResponse)({ status: 201, description: '成功创建事务' }),
|
|
114
|
+
__param(0, (0, common_1.Body)()),
|
|
115
|
+
__metadata("design:type", Function),
|
|
116
|
+
__metadata("design:paramtypes", [dto_1.BeginTransactionDto]),
|
|
117
|
+
__metadata("design:returntype", Promise)
|
|
118
|
+
], AuditController.prototype, "beginTransaction", null);
|
|
119
|
+
__decorate([
|
|
120
|
+
(0, common_1.Post)('transactions/:transactionId/commit'),
|
|
121
|
+
(0, swagger_1.ApiOperation)({ summary: '提交审计事务' }),
|
|
122
|
+
(0, swagger_1.ApiResponse)({ status: 200, description: '成功提交事务' }),
|
|
123
|
+
__param(0, (0, common_1.Param)('transactionId')),
|
|
124
|
+
__metadata("design:type", Function),
|
|
125
|
+
__metadata("design:paramtypes", [String]),
|
|
126
|
+
__metadata("design:returntype", Promise)
|
|
127
|
+
], AuditController.prototype, "commitTransaction", null);
|
|
128
|
+
__decorate([
|
|
129
|
+
(0, common_1.Post)('transactions/:transactionId/rollback'),
|
|
130
|
+
(0, swagger_1.ApiOperation)({ summary: '回滚审计事务' }),
|
|
131
|
+
(0, swagger_1.ApiResponse)({ status: 200, description: '成功回滚事务' }),
|
|
132
|
+
__param(0, (0, common_1.Param)('transactionId')),
|
|
133
|
+
__metadata("design:type", Function),
|
|
134
|
+
__metadata("design:paramtypes", [String]),
|
|
135
|
+
__metadata("design:returntype", Promise)
|
|
136
|
+
], AuditController.prototype, "rollbackTransaction", null);
|
|
137
|
+
exports.AuditController = AuditController = __decorate([
|
|
138
|
+
(0, common_1.Controller)('audit'),
|
|
139
|
+
(0, swagger_1.ApiTags)('audit'),
|
|
140
|
+
__metadata("design:paramtypes", [entity_audit_service_1.EntityAuditService,
|
|
141
|
+
transaction_audit_service_1.TransactionAuditService])
|
|
142
|
+
], AuditController);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit.controller';
|
|
@@ -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.controller"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ControllerAuditOptions, MethodAuditOptions } from '../interfaces';
|
|
2
|
+
export declare const CONTROLLER_AUDIT_OPTIONS: unique symbol;
|
|
3
|
+
export declare const METHOD_AUDIT_OPTIONS: unique symbol;
|
|
4
|
+
export declare function AuditController(options?: ControllerAuditOptions): ClassDecorator;
|
|
5
|
+
export declare function AuditMethod(options?: MethodAuditOptions): MethodDecorator;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.METHOD_AUDIT_OPTIONS = exports.CONTROLLER_AUDIT_OPTIONS = void 0;
|
|
4
|
+
exports.AuditController = AuditController;
|
|
5
|
+
exports.AuditMethod = AuditMethod;
|
|
6
|
+
exports.CONTROLLER_AUDIT_OPTIONS = Symbol('CONTROLLER_AUDIT_OPTIONS');
|
|
7
|
+
exports.METHOD_AUDIT_OPTIONS = Symbol('METHOD_AUDIT_OPTIONS');
|
|
8
|
+
function AuditController(options) {
|
|
9
|
+
return (target) => {
|
|
10
|
+
Reflect.defineMetadata(exports.CONTROLLER_AUDIT_OPTIONS, options || {}, target);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function AuditMethod(options) {
|
|
14
|
+
return (target, propertyKey, descriptor) => {
|
|
15
|
+
Reflect.defineMetadata(exports.METHOD_AUDIT_OPTIONS, options || {}, descriptor.value);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AuditOperationOptions } from '../interfaces';
|
|
2
|
+
export declare const AUDIT_OPERATION_OPTIONS: unique symbol;
|
|
3
|
+
export declare function AuditLog(options: AuditOperationOptions): MethodDecorator;
|
|
4
|
+
export declare function getAuditOperationConfig(target: any, propertyKey: string | symbol): AuditOperationOptions | undefined;
|
|
5
|
+
export declare function hasAuditOperation(target: any, propertyKey: string | symbol): boolean;
|
|
6
|
+
export declare const LogOperation: typeof AuditLog;
|
|
7
|
+
export declare const AuditOperation: typeof AuditLog;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuditOperation = exports.LogOperation = exports.AUDIT_OPERATION_OPTIONS = void 0;
|
|
4
|
+
exports.AuditLog = AuditLog;
|
|
5
|
+
exports.getAuditOperationConfig = getAuditOperationConfig;
|
|
6
|
+
exports.hasAuditOperation = hasAuditOperation;
|
|
7
|
+
exports.AUDIT_OPERATION_OPTIONS = Symbol('AUDIT_OPERATION_OPTIONS');
|
|
8
|
+
function AuditLog(options) {
|
|
9
|
+
return (target, propertyKey, descriptor) => {
|
|
10
|
+
if (!options.templateKey) {
|
|
11
|
+
throw new Error(`@AuditLog requires templateKey for method ${String(propertyKey)}`);
|
|
12
|
+
}
|
|
13
|
+
const methodMetadata = Object.assign(Object.assign({}, options), { methodName: String(propertyKey) });
|
|
14
|
+
Reflect.defineMetadata(exports.AUDIT_OPERATION_OPTIONS, methodMetadata, target, propertyKey);
|
|
15
|
+
return descriptor;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function getAuditOperationConfig(target, propertyKey) {
|
|
19
|
+
return Reflect.getMetadata(exports.AUDIT_OPERATION_OPTIONS, target, propertyKey);
|
|
20
|
+
}
|
|
21
|
+
function hasAuditOperation(target, propertyKey) {
|
|
22
|
+
return Reflect.hasMetadata(exports.AUDIT_OPERATION_OPTIONS, target, propertyKey);
|
|
23
|
+
}
|
|
24
|
+
exports.LogOperation = AuditLog;
|
|
25
|
+
exports.AuditOperation = AuditLog;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EntityAuditConfig, FieldDisplayOptions } from '../interfaces';
|
|
2
|
+
export declare const ENTITY_AUDIT_OPTIONS: unique symbol;
|
|
3
|
+
export declare const FIELD_AUDIT_OPTIONS: unique symbol;
|
|
4
|
+
export declare function AuditEntity(options?: EntityAuditConfig): ClassDecorator;
|
|
5
|
+
export declare function AuditField(options?: FieldDisplayOptions): PropertyDecorator;
|
|
6
|
+
export declare function getEntityAuditConfig(target: any): EntityAuditConfig;
|
|
7
|
+
export declare function getFieldAuditConfig(target: any): Record<string, FieldDisplayOptions>;
|
|
8
|
+
export declare function getFieldLabel(target: any, fieldName: string, language?: string): string;
|
|
9
|
+
export declare function getFieldValueLabel(target: any, fieldName: string, value: any, language?: string): string;
|
|
10
|
+
export declare const EntityAudit: typeof AuditEntity;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityAudit = exports.FIELD_AUDIT_OPTIONS = exports.ENTITY_AUDIT_OPTIONS = void 0;
|
|
4
|
+
exports.AuditEntity = AuditEntity;
|
|
5
|
+
exports.AuditField = AuditField;
|
|
6
|
+
exports.getEntityAuditConfig = getEntityAuditConfig;
|
|
7
|
+
exports.getFieldAuditConfig = getFieldAuditConfig;
|
|
8
|
+
exports.getFieldLabel = getFieldLabel;
|
|
9
|
+
exports.getFieldValueLabel = getFieldValueLabel;
|
|
10
|
+
exports.ENTITY_AUDIT_OPTIONS = Symbol('ENTITY_AUDIT_OPTIONS');
|
|
11
|
+
exports.FIELD_AUDIT_OPTIONS = Symbol('FIELD_AUDIT_OPTIONS');
|
|
12
|
+
function AuditEntity(options) {
|
|
13
|
+
return (target) => {
|
|
14
|
+
const mergedOptions = Object.assign(Object.assign({}, options), { maskFields: [
|
|
15
|
+
...((options === null || options === void 0 ? void 0 : options.maskFields) || []),
|
|
16
|
+
...((options === null || options === void 0 ? void 0 : options.sensitiveFields) || []),
|
|
17
|
+
] });
|
|
18
|
+
if (mergedOptions.maskFields && mergedOptions.maskFields.length > 0) {
|
|
19
|
+
mergedOptions.maskFields = [...new Set(mergedOptions.maskFields)];
|
|
20
|
+
}
|
|
21
|
+
Reflect.defineMetadata(exports.ENTITY_AUDIT_OPTIONS, mergedOptions, target);
|
|
22
|
+
if (mergedOptions.templateKey) {
|
|
23
|
+
Reflect.defineMetadata('entity-log:enabled', true, target);
|
|
24
|
+
Reflect.defineMetadata('entity-log:options', {
|
|
25
|
+
templateKey: mergedOptions.templateKey,
|
|
26
|
+
excludeFields: mergedOptions.excludeFields,
|
|
27
|
+
sensitiveFields: mergedOptions.maskFields,
|
|
28
|
+
}, target);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function AuditField(options) {
|
|
33
|
+
return (target, propertyKey) => {
|
|
34
|
+
const existingOptions = Reflect.getMetadata(exports.FIELD_AUDIT_OPTIONS, target.constructor) || {};
|
|
35
|
+
existingOptions[propertyKey] = options || {};
|
|
36
|
+
Reflect.defineMetadata(exports.FIELD_AUDIT_OPTIONS, existingOptions, target.constructor);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function getEntityAuditConfig(target) {
|
|
40
|
+
return Reflect.getMetadata(exports.ENTITY_AUDIT_OPTIONS, target) || {};
|
|
41
|
+
}
|
|
42
|
+
function getFieldAuditConfig(target) {
|
|
43
|
+
return Reflect.getMetadata(exports.FIELD_AUDIT_OPTIONS, target) || {};
|
|
44
|
+
}
|
|
45
|
+
function getFieldLabel(target, fieldName, language = 'zh') {
|
|
46
|
+
var _a;
|
|
47
|
+
const fieldConfig = getFieldAuditConfig(target);
|
|
48
|
+
const label = (_a = fieldConfig[fieldName]) === null || _a === void 0 ? void 0 : _a.label;
|
|
49
|
+
if (!label) {
|
|
50
|
+
return fieldName;
|
|
51
|
+
}
|
|
52
|
+
if (typeof label === 'string') {
|
|
53
|
+
return label;
|
|
54
|
+
}
|
|
55
|
+
return label[language] || label['zh'] || fieldName;
|
|
56
|
+
}
|
|
57
|
+
function getFieldValueLabel(target, fieldName, value, language = 'zh') {
|
|
58
|
+
var _a;
|
|
59
|
+
const fieldConfig = getFieldAuditConfig(target);
|
|
60
|
+
const valueLabels = (_a = fieldConfig[fieldName]) === null || _a === void 0 ? void 0 : _a.valueLabels;
|
|
61
|
+
if (!valueLabels || !valueLabels[value]) {
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
const labelMap = valueLabels[value];
|
|
65
|
+
if (typeof labelMap === 'string') {
|
|
66
|
+
return labelMap;
|
|
67
|
+
}
|
|
68
|
+
return labelMap[language] || labelMap['zh'] || value;
|
|
69
|
+
}
|
|
70
|
+
exports.EntityAudit = AuditEntity;
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./entity-audit.decorator"), exports);
|
|
18
|
+
__exportStar(require("./audit-controller.decorator"), exports);
|
|
19
|
+
__exportStar(require("./audit-operation.decorator"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AuditOperation } from '../enums';
|
|
2
|
+
export declare class AuditLogQueryDto {
|
|
3
|
+
page?: number;
|
|
4
|
+
limit?: number;
|
|
5
|
+
entityType?: string;
|
|
6
|
+
entityId?: string;
|
|
7
|
+
operation?: AuditOperation;
|
|
8
|
+
userId?: string;
|
|
9
|
+
startDate?: string;
|
|
10
|
+
endDate?: string;
|
|
11
|
+
search?: string;
|
|
12
|
+
sortBy?: string;
|
|
13
|
+
sortOrder?: 'ASC' | 'DESC';
|
|
14
|
+
}
|