@nest-omni/core 4.1.3-10 → 4.1.3-11
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.js +25 -2
- package/audit/decorators/audit-controller.decorator.d.ts +1 -1
- package/audit/decorators/audit-controller.decorator.js +2 -2
- package/audit/decorators/entity-audit.decorator.d.ts +69 -2
- package/audit/decorators/entity-audit.decorator.js +127 -4
- package/audit/decorators/index.d.ts +1 -0
- package/audit/decorators/index.js +1 -0
- package/audit/entities/entity-audit-log.entity.d.ts +5 -0
- package/audit/entities/entity-audit-log.entity.js +30 -1
- package/audit/entities/entity-transaction.entity.d.ts +7 -0
- package/audit/entities/entity-transaction.entity.js +30 -1
- package/audit/entities/index.d.ts +2 -0
- package/audit/entities/index.js +2 -0
- package/audit/enums/audit.enums.d.ts +30 -5
- package/audit/enums/audit.enums.js +34 -6
- package/audit/index.d.ts +3 -1
- package/audit/index.js +21 -2
- package/audit/interfaces/audit.interfaces.d.ts +140 -2
- package/audit/services/entity-audit.service.d.ts +72 -3
- package/audit/services/entity-audit.service.js +210 -6
- package/audit/services/index.d.ts +2 -0
- package/audit/services/index.js +2 -0
- package/http-client/http-client.module.js +1 -5
- package/package.json +1 -1
- package/redis-lock/lock-heartbeat.service.d.ts +2 -2
- package/redis-lock/lock-heartbeat.service.js +4 -4
- package/redis-lock/redis-lock.service.d.ts +18 -0
- package/redis-lock/redis-lock.service.js +38 -8
- package/setup/schedule.decorator.js +18 -8
- package/shared/serviceRegistryModule.js +18 -13
package/audit/audit.module.js
CHANGED
|
@@ -67,6 +67,20 @@ let AuditModule = AuditModule_1 = class AuditModule {
|
|
|
67
67
|
},
|
|
68
68
|
inject: [(0, typeorm_1.getDataSourceToken)(auditConnectionName)],
|
|
69
69
|
},
|
|
70
|
+
{
|
|
71
|
+
provide: (0, typeorm_1.getRepositoryToken)(entities_1.OperationTemplateEntity),
|
|
72
|
+
useFactory: (dataSource) => {
|
|
73
|
+
return dataSource.getRepository(entities_1.OperationTemplateEntity);
|
|
74
|
+
},
|
|
75
|
+
inject: [(0, typeorm_1.getDataSourceToken)(auditConnectionName)],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
provide: (0, typeorm_1.getRepositoryToken)(entities_1.ManualOperationLogEntity),
|
|
79
|
+
useFactory: (dataSource) => {
|
|
80
|
+
return dataSource.getRepository(entities_1.ManualOperationLogEntity);
|
|
81
|
+
},
|
|
82
|
+
inject: [(0, typeorm_1.getDataSourceToken)(auditConnectionName)],
|
|
83
|
+
},
|
|
70
84
|
{
|
|
71
85
|
provide: 'AUDIT_ENTITY_MANAGER',
|
|
72
86
|
useFactory: (dataSource) => {
|
|
@@ -78,8 +92,13 @@ let AuditModule = AuditModule_1 = class AuditModule {
|
|
|
78
92
|
return {
|
|
79
93
|
module: AuditModule_1,
|
|
80
94
|
imports: [
|
|
81
|
-
//
|
|
82
|
-
typeorm_1.TypeOrmModule.forFeature([
|
|
95
|
+
// ��计日志存储到指定的数据库连接
|
|
96
|
+
typeorm_1.TypeOrmModule.forFeature([
|
|
97
|
+
entities_1.EntityAuditLogEntity,
|
|
98
|
+
entities_1.EntityTransactionEntity,
|
|
99
|
+
entities_1.OperationTemplateEntity,
|
|
100
|
+
entities_1.ManualOperationLogEntity,
|
|
101
|
+
], auditConnectionName),
|
|
83
102
|
nestjs_cls_1.ClsModule.forRoot({
|
|
84
103
|
global: true,
|
|
85
104
|
middleware: { mount: true },
|
|
@@ -105,6 +124,7 @@ let AuditModule = AuditModule_1 = class AuditModule {
|
|
|
105
124
|
...repositoryProviders,
|
|
106
125
|
services_1.EntityAuditService,
|
|
107
126
|
services_1.TransactionAuditService,
|
|
127
|
+
services_1.OperationDescriptionService,
|
|
108
128
|
interceptors_1.AuditInterceptor,
|
|
109
129
|
...subscriberProviders,
|
|
110
130
|
],
|
|
@@ -114,6 +134,7 @@ let AuditModule = AuditModule_1 = class AuditModule {
|
|
|
114
134
|
services_1.MultiDatabaseService,
|
|
115
135
|
services_1.EntityAuditService,
|
|
116
136
|
services_1.TransactionAuditService,
|
|
137
|
+
services_1.OperationDescriptionService,
|
|
117
138
|
interceptors_1.AuditInterceptor,
|
|
118
139
|
],
|
|
119
140
|
};
|
|
@@ -226,6 +247,7 @@ let AuditModule = AuditModule_1 = class AuditModule {
|
|
|
226
247
|
...repositoryProviders,
|
|
227
248
|
services_1.EntityAuditService,
|
|
228
249
|
services_1.TransactionAuditService,
|
|
250
|
+
services_1.OperationDescriptionService,
|
|
229
251
|
interceptors_1.AuditInterceptor,
|
|
230
252
|
],
|
|
231
253
|
exports: [
|
|
@@ -234,6 +256,7 @@ let AuditModule = AuditModule_1 = class AuditModule {
|
|
|
234
256
|
services_1.MultiDatabaseService,
|
|
235
257
|
services_1.EntityAuditService,
|
|
236
258
|
services_1.TransactionAuditService,
|
|
259
|
+
services_1.OperationDescriptionService,
|
|
237
260
|
interceptors_1.AuditInterceptor,
|
|
238
261
|
],
|
|
239
262
|
};
|
|
@@ -5,7 +5,7 @@ export declare const METHOD_AUDIT_OPTIONS: unique symbol;
|
|
|
5
5
|
* 控制器审计装饰器
|
|
6
6
|
* @param options 控制器审计选项
|
|
7
7
|
*/
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function AuditController(options?: ControllerAuditOptions): ClassDecorator;
|
|
9
9
|
/**
|
|
10
10
|
* 方法审计装饰器
|
|
11
11
|
* @param options 方法审计选项
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.METHOD_AUDIT_OPTIONS = exports.CONTROLLER_AUDIT_OPTIONS = void 0;
|
|
4
|
-
exports.
|
|
4
|
+
exports.AuditController = AuditController;
|
|
5
5
|
exports.AuditMethod = AuditMethod;
|
|
6
6
|
// 元数据键
|
|
7
7
|
exports.CONTROLLER_AUDIT_OPTIONS = Symbol('CONTROLLER_AUDIT_OPTIONS');
|
|
@@ -10,7 +10,7 @@ exports.METHOD_AUDIT_OPTIONS = Symbol('METHOD_AUDIT_OPTIONS');
|
|
|
10
10
|
* 控制器审计装饰器
|
|
11
11
|
* @param options 控制器审计选项
|
|
12
12
|
*/
|
|
13
|
-
function
|
|
13
|
+
function AuditController(options) {
|
|
14
14
|
return (target) => {
|
|
15
15
|
Reflect.defineMetadata(exports.CONTROLLER_AUDIT_OPTIONS, options || {}, target);
|
|
16
16
|
};
|
|
@@ -3,11 +3,78 @@ export declare const ENTITY_AUDIT_OPTIONS: unique symbol;
|
|
|
3
3
|
export declare const FIELD_AUDIT_OPTIONS: unique symbol;
|
|
4
4
|
/**
|
|
5
5
|
* 实体审计装饰器
|
|
6
|
+
*
|
|
7
|
+
* @description
|
|
8
|
+
* 支持基础审计配置。
|
|
9
|
+
* 字段标签和值标签请使用 @AuditField({ label: { zh: '姓名', en: 'Name' } })
|
|
10
|
+
*
|
|
6
11
|
* @param options 审计配置选项
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // 基础用法
|
|
15
|
+
* @AuditEntity({
|
|
16
|
+
* enabled: true,
|
|
17
|
+
* excludeFields: ['password'],
|
|
18
|
+
* maskFields: ['email']
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // 指定模板键
|
|
23
|
+
* @AuditEntity({
|
|
24
|
+
* enabled: true,
|
|
25
|
+
* templateKey: 'user',
|
|
26
|
+
* })
|
|
7
27
|
*/
|
|
8
|
-
export declare function
|
|
28
|
+
export declare function AuditEntity(options?: EntityAuditConfig): ClassDecorator;
|
|
9
29
|
/**
|
|
10
30
|
* 字段审计装饰器
|
|
11
|
-
* @param options
|
|
31
|
+
* @param options 字段显示选项(支持多语言 label 和 valueLabels)
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // 单语言
|
|
35
|
+
* @AuditField({ label: '姓名' })
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // 多语言
|
|
39
|
+
* @AuditField({ label: { zh: '姓名', en: 'Name' } })
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // 带值标签映射
|
|
43
|
+
* @AuditField({
|
|
44
|
+
* label: { zh: '状态', en: 'Status' },
|
|
45
|
+
* valueLabels: {
|
|
46
|
+
* active: { zh: '激活', en: 'Active' },
|
|
47
|
+
* inactive: { zh: '未激活', en: 'Inactive' }
|
|
48
|
+
* }
|
|
49
|
+
* })
|
|
12
50
|
*/
|
|
13
51
|
export declare function AuditField(options?: FieldDisplayOptions): PropertyDecorator;
|
|
52
|
+
/**
|
|
53
|
+
* 获取实体审计配置
|
|
54
|
+
* @param target 目标类
|
|
55
|
+
* @returns 审计配置
|
|
56
|
+
*/
|
|
57
|
+
export declare function getEntityAuditConfig(target: any): EntityAuditConfig;
|
|
58
|
+
/**
|
|
59
|
+
* 获取字段审计配置
|
|
60
|
+
* @param target 目标类
|
|
61
|
+
* @returns 字段配置映射
|
|
62
|
+
*/
|
|
63
|
+
export declare function getFieldAuditConfig(target: any): Record<string, FieldDisplayOptions>;
|
|
64
|
+
/**
|
|
65
|
+
* 获取字段的标签(支持多语言)
|
|
66
|
+
* @param target 目标类
|
|
67
|
+
* @param fieldName 字段名
|
|
68
|
+
* @param language 语言代码(默认:zh)
|
|
69
|
+
* @returns 字段标签
|
|
70
|
+
*/
|
|
71
|
+
export declare function getFieldLabel(target: any, fieldName: string, language?: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* 获取字段值的标签(支持多语言)
|
|
74
|
+
* @param target 目标类
|
|
75
|
+
* @param fieldName 字段名
|
|
76
|
+
* @param value 值
|
|
77
|
+
* @param language 语言代码(默认:zh)
|
|
78
|
+
* @returns 值的标签
|
|
79
|
+
*/
|
|
80
|
+
export declare function getFieldValueLabel(target: any, fieldName: string, value: any, language?: string): string;
|
|
@@ -1,23 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FIELD_AUDIT_OPTIONS = exports.ENTITY_AUDIT_OPTIONS = void 0;
|
|
4
|
-
exports.
|
|
4
|
+
exports.AuditEntity = AuditEntity;
|
|
5
5
|
exports.AuditField = AuditField;
|
|
6
|
+
exports.getEntityAuditConfig = getEntityAuditConfig;
|
|
7
|
+
exports.getFieldAuditConfig = getFieldAuditConfig;
|
|
8
|
+
exports.getFieldLabel = getFieldLabel;
|
|
9
|
+
exports.getFieldValueLabel = getFieldValueLabel;
|
|
6
10
|
// 元数据键
|
|
7
11
|
exports.ENTITY_AUDIT_OPTIONS = Symbol('ENTITY_AUDIT_OPTIONS');
|
|
8
12
|
exports.FIELD_AUDIT_OPTIONS = Symbol('FIELD_AUDIT_OPTIONS');
|
|
9
13
|
/**
|
|
10
14
|
* 实体审计装饰器
|
|
15
|
+
*
|
|
16
|
+
* @description
|
|
17
|
+
* 支持基础审计配置。
|
|
18
|
+
* 字段标签和值标签请使用 @AuditField({ label: { zh: '姓名', en: 'Name' } })
|
|
19
|
+
*
|
|
11
20
|
* @param options 审计配置选项
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // 基础用法
|
|
24
|
+
* @AuditEntity({
|
|
25
|
+
* enabled: true,
|
|
26
|
+
* excludeFields: ['password'],
|
|
27
|
+
* maskFields: ['email']
|
|
28
|
+
* })
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // 指定模板键
|
|
32
|
+
* @AuditEntity({
|
|
33
|
+
* enabled: true,
|
|
34
|
+
* templateKey: 'user',
|
|
35
|
+
* })
|
|
12
36
|
*/
|
|
13
|
-
function
|
|
37
|
+
function AuditEntity(options) {
|
|
14
38
|
return (target) => {
|
|
15
|
-
|
|
39
|
+
// 处理兼容性:sensitiveFields 别名
|
|
40
|
+
const mergedOptions = Object.assign(Object.assign({}, options), {
|
|
41
|
+
// 合并 sensitiveFields 到 maskFields
|
|
42
|
+
maskFields: [
|
|
43
|
+
...((options === null || options === void 0 ? void 0 : options.maskFields) || []),
|
|
44
|
+
...((options === null || options === void 0 ? void 0 : options.sensitiveFields) || []),
|
|
45
|
+
] });
|
|
46
|
+
// 去重
|
|
47
|
+
if (mergedOptions.maskFields && mergedOptions.maskFields.length > 0) {
|
|
48
|
+
mergedOptions.maskFields = [...new Set(mergedOptions.maskFields)];
|
|
49
|
+
}
|
|
50
|
+
// 存储基础审计元数据
|
|
51
|
+
Reflect.defineMetadata(exports.ENTITY_AUDIT_OPTIONS, mergedOptions, target);
|
|
52
|
+
// 如果有 templateKey,同时存储到 entity-log 元数据(兼容性)
|
|
53
|
+
if (mergedOptions.templateKey) {
|
|
54
|
+
Reflect.defineMetadata('entity-log:enabled', true, target);
|
|
55
|
+
Reflect.defineMetadata('entity-log:options', {
|
|
56
|
+
templateKey: mergedOptions.templateKey,
|
|
57
|
+
excludeFields: mergedOptions.excludeFields,
|
|
58
|
+
sensitiveFields: mergedOptions.maskFields,
|
|
59
|
+
}, target);
|
|
60
|
+
}
|
|
16
61
|
};
|
|
17
62
|
}
|
|
18
63
|
/**
|
|
19
64
|
* 字段审计装饰器
|
|
20
|
-
* @param options
|
|
65
|
+
* @param options 字段显示选项(支持多语言 label 和 valueLabels)
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // 单语言
|
|
69
|
+
* @AuditField({ label: '姓名' })
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // 多语言
|
|
73
|
+
* @AuditField({ label: { zh: '姓名', en: 'Name' } })
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // 带值标签映射
|
|
77
|
+
* @AuditField({
|
|
78
|
+
* label: { zh: '状态', en: 'Status' },
|
|
79
|
+
* valueLabels: {
|
|
80
|
+
* active: { zh: '激活', en: 'Active' },
|
|
81
|
+
* inactive: { zh: '未激活', en: 'Inactive' }
|
|
82
|
+
* }
|
|
83
|
+
* })
|
|
21
84
|
*/
|
|
22
85
|
function AuditField(options) {
|
|
23
86
|
return (target, propertyKey) => {
|
|
@@ -26,3 +89,63 @@ function AuditField(options) {
|
|
|
26
89
|
Reflect.defineMetadata(exports.FIELD_AUDIT_OPTIONS, existingOptions, target.constructor);
|
|
27
90
|
};
|
|
28
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* 获取实体审计配置
|
|
94
|
+
* @param target 目标类
|
|
95
|
+
* @returns 审计配置
|
|
96
|
+
*/
|
|
97
|
+
function getEntityAuditConfig(target) {
|
|
98
|
+
return Reflect.getMetadata(exports.ENTITY_AUDIT_OPTIONS, target) || {};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 获取字段审计配置
|
|
102
|
+
* @param target 目标类
|
|
103
|
+
* @returns 字段配置映射
|
|
104
|
+
*/
|
|
105
|
+
function getFieldAuditConfig(target) {
|
|
106
|
+
return Reflect.getMetadata(exports.FIELD_AUDIT_OPTIONS, target) || {};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 获取字段的标签(支持多语言)
|
|
110
|
+
* @param target 目标类
|
|
111
|
+
* @param fieldName 字段名
|
|
112
|
+
* @param language 语言代码(默认:zh)
|
|
113
|
+
* @returns 字段标签
|
|
114
|
+
*/
|
|
115
|
+
function getFieldLabel(target, fieldName, language = 'zh') {
|
|
116
|
+
var _a;
|
|
117
|
+
const fieldConfig = getFieldAuditConfig(target);
|
|
118
|
+
const label = (_a = fieldConfig[fieldName]) === null || _a === void 0 ? void 0 : _a.label;
|
|
119
|
+
if (!label) {
|
|
120
|
+
return fieldName;
|
|
121
|
+
}
|
|
122
|
+
// 如果是字符串,直接返回
|
|
123
|
+
if (typeof label === 'string') {
|
|
124
|
+
return label;
|
|
125
|
+
}
|
|
126
|
+
// 如果是对象,返回指定语言的值
|
|
127
|
+
return label[language] || label['zh'] || fieldName;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 获取字段值的标签(支持多语言)
|
|
131
|
+
* @param target 目标类
|
|
132
|
+
* @param fieldName 字段名
|
|
133
|
+
* @param value 值
|
|
134
|
+
* @param language 语言代码(默认:zh)
|
|
135
|
+
* @returns 值的标签
|
|
136
|
+
*/
|
|
137
|
+
function getFieldValueLabel(target, fieldName, value, language = 'zh') {
|
|
138
|
+
var _a;
|
|
139
|
+
const fieldConfig = getFieldAuditConfig(target);
|
|
140
|
+
const valueLabels = (_a = fieldConfig[fieldName]) === null || _a === void 0 ? void 0 : _a.valueLabels;
|
|
141
|
+
if (!valueLabels || !valueLabels[value]) {
|
|
142
|
+
return value;
|
|
143
|
+
}
|
|
144
|
+
const labelMap = valueLabels[value];
|
|
145
|
+
// 如果是字符串,直接返回
|
|
146
|
+
if (typeof labelMap === 'string') {
|
|
147
|
+
return labelMap;
|
|
148
|
+
}
|
|
149
|
+
// 如果是对象,返回指定语言的值
|
|
150
|
+
return labelMap[language] || labelMap['zh'] || value;
|
|
151
|
+
}
|
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./entity-audit.decorator"), exports);
|
|
18
18
|
__exportStar(require("./audit-controller.decorator"), exports);
|
|
19
|
+
__exportStar(require("./audit-operation.decorator"), exports);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AbstractUuidPrimaryEntity } from '../../common/abstract.entity';
|
|
2
2
|
import { AuditOperation } from '../enums';
|
|
3
|
+
import { ChangeDetail, RollbackAction } from '../interfaces';
|
|
3
4
|
/**
|
|
4
5
|
* 实体审计日志
|
|
5
6
|
*/
|
|
@@ -18,4 +19,8 @@ export declare class EntityAuditLogEntity extends AbstractUuidPrimaryEntity {
|
|
|
18
19
|
userAgent: string;
|
|
19
20
|
description: string;
|
|
20
21
|
hashChain: Record<string, any>;
|
|
22
|
+
operationTemplateKey: string;
|
|
23
|
+
descriptionParams: Record<string, any>;
|
|
24
|
+
changeDetails: ChangeDetail[];
|
|
25
|
+
rollbackActions: RollbackAction[];
|
|
21
26
|
}
|
|
@@ -75,10 +75,39 @@ __decorate([
|
|
|
75
75
|
(0, typeorm_1.Column)({ type: 'json', nullable: true, comment: '哈希链' }),
|
|
76
76
|
__metadata("design:type", Object)
|
|
77
77
|
], EntityAuditLogEntity.prototype, "hashChain", void 0);
|
|
78
|
+
__decorate([
|
|
79
|
+
(0, typeorm_1.Column)({ nullable: true, comment: '操作模板键,用于动态生成描述' }),
|
|
80
|
+
__metadata("design:type", String)
|
|
81
|
+
], EntityAuditLogEntity.prototype, "operationTemplateKey", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
(0, typeorm_1.Column)({
|
|
84
|
+
type: 'json',
|
|
85
|
+
nullable: true,
|
|
86
|
+
comment: '描述参数,用于填充模板占位符',
|
|
87
|
+
}),
|
|
88
|
+
__metadata("design:type", Object)
|
|
89
|
+
], EntityAuditLogEntity.prototype, "descriptionParams", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
(0, typeorm_1.Column)({
|
|
92
|
+
type: 'json',
|
|
93
|
+
nullable: true,
|
|
94
|
+
comment: '结构化变更详情列表(包含多语言支持)',
|
|
95
|
+
}),
|
|
96
|
+
__metadata("design:type", Array)
|
|
97
|
+
], EntityAuditLogEntity.prototype, "changeDetails", void 0);
|
|
98
|
+
__decorate([
|
|
99
|
+
(0, typeorm_1.Column)({
|
|
100
|
+
type: 'json',
|
|
101
|
+
nullable: true,
|
|
102
|
+
comment: '回滚操作列表',
|
|
103
|
+
}),
|
|
104
|
+
__metadata("design:type", Array)
|
|
105
|
+
], EntityAuditLogEntity.prototype, "rollbackActions", void 0);
|
|
78
106
|
exports.EntityAuditLogEntity = EntityAuditLogEntity = __decorate([
|
|
79
107
|
(0, typeorm_1.Entity)('entity_audit_log'),
|
|
80
108
|
(0, typeorm_1.Index)('idx_entity_relation', ['entityType', 'entityId']),
|
|
81
109
|
(0, typeorm_1.Index)('idx_operation', ['operation']),
|
|
82
110
|
(0, typeorm_1.Index)('idx_user', ['userId']),
|
|
83
|
-
(0, typeorm_1.Index)('idx_created_at', ['createdAt'])
|
|
111
|
+
(0, typeorm_1.Index)('idx_created_at', ['createdAt']),
|
|
112
|
+
(0, typeorm_1.Index)('idx_template_key', ['operationTemplateKey'])
|
|
84
113
|
], EntityAuditLogEntity);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AbstractUuidPrimaryEntity } from '../../common/abstract.entity';
|
|
2
2
|
import { AuditOperation, TransactionStatus } from '../enums';
|
|
3
|
+
import { ManualOperationLogEntity } from './manual-operation-log.entity';
|
|
3
4
|
/**
|
|
4
5
|
* 实体事务
|
|
5
6
|
*/
|
|
@@ -14,4 +15,10 @@ export declare class EntityTransactionEntity extends AbstractUuidPrimaryEntity {
|
|
|
14
15
|
userId: string;
|
|
15
16
|
username: string;
|
|
16
17
|
dependencyGraph: Record<string, any>;
|
|
18
|
+
operationTemplateKey: string;
|
|
19
|
+
descriptionParams: Record<string, any>;
|
|
20
|
+
requestIp: string;
|
|
21
|
+
metadata: Record<string, any>;
|
|
22
|
+
completedAt: Date;
|
|
23
|
+
manualOperations: ManualOperationLogEntity[];
|
|
17
24
|
}
|
|
@@ -46,9 +46,38 @@ __decorate([
|
|
|
46
46
|
(0, typeorm_1.Column)({ type: 'json', nullable: true, comment: '依赖图' }),
|
|
47
47
|
__metadata("design:type", Object)
|
|
48
48
|
], EntityTransactionEntity.prototype, "dependencyGraph", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, typeorm_1.Column)({ nullable: true, comment: '操作模板键(事务级别)' }),
|
|
51
|
+
__metadata("design:type", String)
|
|
52
|
+
], EntityTransactionEntity.prototype, "operationTemplateKey", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, typeorm_1.Column)({
|
|
55
|
+
type: 'json',
|
|
56
|
+
nullable: true,
|
|
57
|
+
comment: '描述参数,用于填充事务级别的模板占位符',
|
|
58
|
+
}),
|
|
59
|
+
__metadata("design:type", Object)
|
|
60
|
+
], EntityTransactionEntity.prototype, "descriptionParams", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, typeorm_1.Column)({ nullable: true, comment: '请求IP' }),
|
|
63
|
+
__metadata("design:type", String)
|
|
64
|
+
], EntityTransactionEntity.prototype, "requestIp", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, typeorm_1.Column)({ type: 'json', nullable: true, comment: '事务元数据' }),
|
|
67
|
+
__metadata("design:type", Object)
|
|
68
|
+
], EntityTransactionEntity.prototype, "metadata", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, typeorm_1.Column)({ type: 'timestamp', nullable: true, comment: '完成时间' }),
|
|
71
|
+
__metadata("design:type", Date)
|
|
72
|
+
], EntityTransactionEntity.prototype, "completedAt", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, typeorm_1.OneToMany)('ManualOperationLogEntity', (log) => log.transaction),
|
|
75
|
+
__metadata("design:type", Array)
|
|
76
|
+
], EntityTransactionEntity.prototype, "manualOperations", void 0);
|
|
49
77
|
exports.EntityTransactionEntity = EntityTransactionEntity = __decorate([
|
|
50
78
|
(0, typeorm_1.Entity)('entity_transaction'),
|
|
51
79
|
(0, typeorm_1.Index)('idx_status', ['status']),
|
|
52
80
|
(0, typeorm_1.Index)('idx_user', ['userId']),
|
|
53
|
-
(0, typeorm_1.Index)('idx_created_at', ['createdAt'])
|
|
81
|
+
(0, typeorm_1.Index)('idx_created_at', ['createdAt']),
|
|
82
|
+
(0, typeorm_1.Index)('idx_template_key', ['operationTemplateKey'])
|
|
54
83
|
], EntityTransactionEntity);
|
package/audit/entities/index.js
CHANGED
|
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./entity-audit-log.entity"), exports);
|
|
18
18
|
__exportStar(require("./entity-transaction.entity"), exports);
|
|
19
|
+
__exportStar(require("./operation-template.entity"), exports);
|
|
20
|
+
__exportStar(require("./manual-operation-log.entity"), exports);
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 操作类型(设计文档标准命名)
|
|
3
|
+
*/
|
|
4
|
+
export declare enum OperationType {
|
|
5
|
+
CREATE = "create",
|
|
6
|
+
UPDATE = "update",
|
|
7
|
+
DELETE = "delete"
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 审计操作类型(兼容性别名,映射到 OperationType)
|
|
11
|
+
* @deprecated 请使用 OperationType
|
|
3
12
|
*/
|
|
4
13
|
export declare enum AuditOperation {
|
|
5
14
|
CREATE = "CREATE",
|
|
@@ -8,12 +17,12 @@ export declare enum AuditOperation {
|
|
|
8
17
|
RESTORE = "RESTORE"
|
|
9
18
|
}
|
|
10
19
|
/**
|
|
11
|
-
*
|
|
20
|
+
* 事务状态(设计文档标准命名)
|
|
12
21
|
*/
|
|
13
22
|
export declare enum TransactionStatus {
|
|
14
|
-
PENDING = "
|
|
15
|
-
COMMITTED = "
|
|
16
|
-
ROLLED_BACK = "
|
|
23
|
+
PENDING = "pending",
|
|
24
|
+
COMMITTED = "committed",
|
|
25
|
+
ROLLED_BACK = "rolled_back"
|
|
17
26
|
}
|
|
18
27
|
/**
|
|
19
28
|
* 恢复策略
|
|
@@ -40,3 +49,19 @@ export declare enum MaskingStrategy {
|
|
|
40
49
|
MASK = "MASK",
|
|
41
50
|
PARTIAL = "PARTIAL"
|
|
42
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* 回滚操作类型(设计文档标准命名)
|
|
54
|
+
*/
|
|
55
|
+
export declare enum RollbackActionType {
|
|
56
|
+
ENTITY = "entity",// 实体回滚(删除/恢复)
|
|
57
|
+
FILE = "file",// 文件回滚(删除上传的文件)
|
|
58
|
+
CUSTOM = "custom"
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 变更类型(设计文档标准命名)
|
|
62
|
+
*/
|
|
63
|
+
export declare enum ChangeType {
|
|
64
|
+
ADDED = "added",// 新增字段
|
|
65
|
+
REMOVED = "removed",// 删除字段
|
|
66
|
+
MODIFIED = "modified"
|
|
67
|
+
}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MaskingStrategy = exports.RecordStrategy = exports.RecoveryStrategy = exports.TransactionStatus = exports.AuditOperation = void 0;
|
|
3
|
+
exports.ChangeType = exports.RollbackActionType = exports.MaskingStrategy = exports.RecordStrategy = exports.RecoveryStrategy = exports.TransactionStatus = exports.AuditOperation = exports.OperationType = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 操作类型(设计文档标准命名)
|
|
6
|
+
*/
|
|
7
|
+
var OperationType;
|
|
8
|
+
(function (OperationType) {
|
|
9
|
+
OperationType["CREATE"] = "create";
|
|
10
|
+
OperationType["UPDATE"] = "update";
|
|
11
|
+
OperationType["DELETE"] = "delete";
|
|
12
|
+
})(OperationType || (exports.OperationType = OperationType = {}));
|
|
13
|
+
/**
|
|
14
|
+
* 审计操作类型(兼容性别名,映射到 OperationType)
|
|
15
|
+
* @deprecated 请使用 OperationType
|
|
6
16
|
*/
|
|
7
17
|
var AuditOperation;
|
|
8
18
|
(function (AuditOperation) {
|
|
@@ -12,13 +22,13 @@ var AuditOperation;
|
|
|
12
22
|
AuditOperation["RESTORE"] = "RESTORE";
|
|
13
23
|
})(AuditOperation || (exports.AuditOperation = AuditOperation = {}));
|
|
14
24
|
/**
|
|
15
|
-
*
|
|
25
|
+
* 事务状态(设计文档标准命名)
|
|
16
26
|
*/
|
|
17
27
|
var TransactionStatus;
|
|
18
28
|
(function (TransactionStatus) {
|
|
19
|
-
TransactionStatus["PENDING"] = "
|
|
20
|
-
TransactionStatus["COMMITTED"] = "
|
|
21
|
-
TransactionStatus["ROLLED_BACK"] = "
|
|
29
|
+
TransactionStatus["PENDING"] = "pending";
|
|
30
|
+
TransactionStatus["COMMITTED"] = "committed";
|
|
31
|
+
TransactionStatus["ROLLED_BACK"] = "rolled_back";
|
|
22
32
|
})(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
|
|
23
33
|
/**
|
|
24
34
|
* 恢复策略
|
|
@@ -48,3 +58,21 @@ var MaskingStrategy;
|
|
|
48
58
|
MaskingStrategy["MASK"] = "MASK";
|
|
49
59
|
MaskingStrategy["PARTIAL"] = "PARTIAL";
|
|
50
60
|
})(MaskingStrategy || (exports.MaskingStrategy = MaskingStrategy = {}));
|
|
61
|
+
/**
|
|
62
|
+
* 回滚操作类型(设计文档标准命名)
|
|
63
|
+
*/
|
|
64
|
+
var RollbackActionType;
|
|
65
|
+
(function (RollbackActionType) {
|
|
66
|
+
RollbackActionType["ENTITY"] = "entity";
|
|
67
|
+
RollbackActionType["FILE"] = "file";
|
|
68
|
+
RollbackActionType["CUSTOM"] = "custom";
|
|
69
|
+
})(RollbackActionType || (exports.RollbackActionType = RollbackActionType = {}));
|
|
70
|
+
/**
|
|
71
|
+
* 变更类型(设计文档标准命名)
|
|
72
|
+
*/
|
|
73
|
+
var ChangeType;
|
|
74
|
+
(function (ChangeType) {
|
|
75
|
+
ChangeType["ADDED"] = "added";
|
|
76
|
+
ChangeType["REMOVED"] = "removed";
|
|
77
|
+
ChangeType["MODIFIED"] = "modified";
|
|
78
|
+
})(ChangeType || (exports.ChangeType = ChangeType = {}));
|
package/audit/index.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ export * from './entities';
|
|
|
2
2
|
export * from './enums';
|
|
3
3
|
export * from './interfaces';
|
|
4
4
|
export * from './dto';
|
|
5
|
-
export
|
|
5
|
+
export { AuditEntity, 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, getAuditOperationConfig, hasAuditOperation, AUDIT_OPERATION_OPTIONS, } from './decorators/audit-operation.decorator';
|
|
6
8
|
export * from './services';
|
|
7
9
|
export * from './subscribers';
|
|
8
10
|
export * from './interceptors';
|
package/audit/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AUDIT_OPERATION_OPTIONS = exports.hasAuditOperation = exports.getAuditOperationConfig = 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.AuditEntity = void 0;
|
|
17
18
|
// Entities
|
|
18
19
|
__exportStar(require("./entities"), exports);
|
|
19
20
|
// Enums
|
|
@@ -22,8 +23,26 @@ __exportStar(require("./enums"), exports);
|
|
|
22
23
|
__exportStar(require("./interfaces"), exports);
|
|
23
24
|
// DTO
|
|
24
25
|
__exportStar(require("./dto"), exports);
|
|
25
|
-
// Decorators
|
|
26
|
-
|
|
26
|
+
// Decorators - explicit exports
|
|
27
|
+
var entity_audit_decorator_1 = require("./decorators/entity-audit.decorator");
|
|
28
|
+
Object.defineProperty(exports, "AuditEntity", { enumerable: true, get: function () { return entity_audit_decorator_1.AuditEntity; } });
|
|
29
|
+
Object.defineProperty(exports, "AuditField", { enumerable: true, get: function () { return entity_audit_decorator_1.AuditField; } });
|
|
30
|
+
Object.defineProperty(exports, "getEntityAuditConfig", { enumerable: true, get: function () { return entity_audit_decorator_1.getEntityAuditConfig; } });
|
|
31
|
+
Object.defineProperty(exports, "getFieldAuditConfig", { enumerable: true, get: function () { return entity_audit_decorator_1.getFieldAuditConfig; } });
|
|
32
|
+
Object.defineProperty(exports, "getFieldLabel", { enumerable: true, get: function () { return entity_audit_decorator_1.getFieldLabel; } });
|
|
33
|
+
Object.defineProperty(exports, "getFieldValueLabel", { enumerable: true, get: function () { return entity_audit_decorator_1.getFieldValueLabel; } });
|
|
34
|
+
Object.defineProperty(exports, "ENTITY_AUDIT_OPTIONS", { enumerable: true, get: function () { return entity_audit_decorator_1.ENTITY_AUDIT_OPTIONS; } });
|
|
35
|
+
Object.defineProperty(exports, "FIELD_AUDIT_OPTIONS", { enumerable: true, get: function () { return entity_audit_decorator_1.FIELD_AUDIT_OPTIONS; } });
|
|
36
|
+
var audit_controller_decorator_1 = require("./decorators/audit-controller.decorator");
|
|
37
|
+
Object.defineProperty(exports, "AuditController", { enumerable: true, get: function () { return audit_controller_decorator_1.AuditController; } });
|
|
38
|
+
Object.defineProperty(exports, "AuditMethod", { enumerable: true, get: function () { return audit_controller_decorator_1.AuditMethod; } });
|
|
39
|
+
Object.defineProperty(exports, "CONTROLLER_AUDIT_OPTIONS", { enumerable: true, get: function () { return audit_controller_decorator_1.CONTROLLER_AUDIT_OPTIONS; } });
|
|
40
|
+
Object.defineProperty(exports, "METHOD_AUDIT_OPTIONS", { enumerable: true, get: function () { return audit_controller_decorator_1.METHOD_AUDIT_OPTIONS; } });
|
|
41
|
+
var audit_operation_decorator_1 = require("./decorators/audit-operation.decorator");
|
|
42
|
+
Object.defineProperty(exports, "AuditLog", { enumerable: true, get: function () { return audit_operation_decorator_1.AuditLog; } });
|
|
43
|
+
Object.defineProperty(exports, "getAuditOperationConfig", { enumerable: true, get: function () { return audit_operation_decorator_1.getAuditOperationConfig; } });
|
|
44
|
+
Object.defineProperty(exports, "hasAuditOperation", { enumerable: true, get: function () { return audit_operation_decorator_1.hasAuditOperation; } });
|
|
45
|
+
Object.defineProperty(exports, "AUDIT_OPERATION_OPTIONS", { enumerable: true, get: function () { return audit_operation_decorator_1.AUDIT_OPERATION_OPTIONS; } });
|
|
27
46
|
// Services
|
|
28
47
|
__exportStar(require("./services"), exports);
|
|
29
48
|
// Subscribers
|