@nest-omni/core 4.1.3-2 → 4.1.3-4
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 +15 -0
- package/audit/controllers/audit.controller.d.ts +24 -0
- package/audit/controllers/audit.controller.js +24 -0
- package/audit/decorators/audit-controller.decorator.d.ts +8 -0
- package/audit/decorators/audit-controller.decorator.js +9 -0
- package/audit/decorators/audit-operation.decorator.d.ts +45 -0
- package/audit/decorators/audit-operation.decorator.js +49 -0
- package/audit/decorators/entity-audit.decorator.d.ts +8 -0
- package/audit/decorators/entity-audit.decorator.js +9 -0
- package/audit/dto/audit-log-query.dto.d.ts +3 -0
- package/audit/dto/audit-log-query.dto.js +3 -0
- package/audit/dto/begin-transaction.dto.d.ts +3 -0
- package/audit/dto/begin-transaction.dto.js +3 -0
- package/audit/dto/compare-entities.dto.d.ts +3 -0
- package/audit/dto/compare-entities.dto.js +3 -0
- package/audit/dto/pre-check-restore.dto.d.ts +3 -0
- package/audit/dto/pre-check-restore.dto.js +3 -0
- package/audit/dto/restore-entity.dto.d.ts +3 -0
- package/audit/dto/restore-entity.dto.js +3 -0
- package/audit/entities/entity-audit-log.entity.d.ts +3 -0
- package/audit/entities/entity-audit-log.entity.js +3 -0
- package/audit/entities/entity-transaction.entity.d.ts +3 -0
- package/audit/entities/entity-transaction.entity.js +3 -0
- package/audit/entities/manual-operation-log.entity.d.ts +4 -0
- package/audit/entities/manual-operation-log.entity.js +4 -0
- package/audit/entities/operation-template.entity.d.ts +4 -0
- package/audit/entities/operation-template.entity.js +4 -0
- package/audit/enums/audit.enums.d.ts +17 -2
- package/audit/enums/audit.enums.js +15 -0
- package/audit/index.js +10 -0
- package/audit/interceptors/audit.interceptor.d.ts +15 -0
- package/audit/interceptors/audit.interceptor.js +23 -1
- package/audit/interfaces/audit.interfaces.d.ts +42 -0
- package/audit/services/audit-context.service.d.ts +15 -0
- package/audit/services/audit-context.service.js +15 -0
- package/audit/services/audit-strategy.service.d.ts +6 -0
- package/audit/services/audit-strategy.service.js +13 -0
- package/audit/services/entity-audit.service.d.ts +57 -0
- package/audit/services/entity-audit.service.js +91 -0
- package/audit/services/manual-audit-log.service.d.ts +124 -0
- package/audit/services/manual-audit-log.service.js +138 -0
- package/audit/services/multi-database.service.d.ts +12 -0
- package/audit/services/multi-database.service.js +12 -0
- package/audit/services/operation-description.service.d.ts +59 -0
- package/audit/services/operation-description.service.js +76 -2
- package/audit/services/transaction-audit.service.d.ts +30 -0
- package/audit/services/transaction-audit.service.js +47 -0
- package/audit/subscribers/entity-audit.subscriber.d.ts +15 -0
- package/audit/subscribers/entity-audit.subscriber.js +29 -1
- package/cache/cache-metrics.service.d.ts +67 -0
- package/cache/cache-metrics.service.js +68 -4
- package/cache/cache-serialization.service.d.ts +31 -0
- package/cache/cache-serialization.service.js +25 -0
- package/cache/cache.constants.d.ts +9 -0
- package/cache/cache.constants.js +9 -0
- package/cache/cache.health.d.ts +26 -0
- package/cache/cache.health.js +30 -0
- package/cache/cache.module.d.ts +86 -0
- package/cache/cache.module.js +71 -0
- package/cache/cache.service.d.ts +140 -0
- package/cache/cache.service.js +157 -0
- package/cache/cache.warmup.service.d.ts +39 -0
- package/cache/cache.warmup.service.js +32 -0
- package/cache/decorators/cache-evict.decorator.d.ts +47 -0
- package/cache/decorators/cache-evict.decorator.js +56 -0
- package/cache/decorators/cache-put.decorator.d.ts +34 -0
- package/cache/decorators/cache-put.decorator.js +39 -0
- package/cache/decorators/cacheable.decorator.d.ts +40 -0
- package/cache/decorators/cacheable.decorator.js +55 -0
- package/cache/dependencies/callback.dependency.d.ts +33 -0
- package/cache/dependencies/callback.dependency.js +39 -1
- package/cache/dependencies/chain.dependency.d.ts +28 -0
- package/cache/dependencies/chain.dependency.js +34 -0
- package/cache/dependencies/db.dependency.d.ts +45 -0
- package/cache/dependencies/db.dependency.js +48 -1
- package/cache/dependencies/file.dependency.d.ts +32 -0
- package/cache/dependencies/file.dependency.js +34 -0
- package/cache/dependencies/tag.dependency.d.ts +36 -0
- package/cache/dependencies/tag.dependency.js +36 -0
- package/cache/dependencies/time.dependency.d.ts +43 -0
- package/cache/dependencies/time.dependency.js +43 -0
- package/cache/examples/basic-usage.d.ts +15 -0
- package/cache/examples/basic-usage.js +62 -8
- package/cache/index.js +9 -0
- package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
- package/cache/interfaces/cache-options.interface.d.ts +81 -0
- package/cache/interfaces/cache-options.interface.js +6 -0
- package/cache/interfaces/cache-provider.interface.d.ts +78 -0
- package/cache/providers/base-cache.provider.d.ts +14 -0
- package/cache/providers/base-cache.provider.js +16 -0
- package/cache/providers/cls-cache.provider.d.ts +20 -0
- package/cache/providers/cls-cache.provider.js +28 -0
- package/cache/providers/memory-cache.provider.d.ts +23 -0
- package/cache/providers/memory-cache.provider.js +26 -0
- package/cache/providers/redis-cache.provider.d.ts +26 -0
- package/cache/providers/redis-cache.provider.js +29 -0
- package/cache/utils/dependency-manager.util.d.ts +52 -0
- package/cache/utils/dependency-manager.util.js +59 -0
- package/cache/utils/key-generator.util.d.ts +42 -0
- package/cache/utils/key-generator.util.js +53 -1
- package/common/abstract.entity.d.ts +14 -0
- package/common/abstract.entity.js +14 -0
- package/common/boilerplate.polyfill.d.ts +142 -0
- package/common/boilerplate.polyfill.js +17 -0
- package/common/dto/dto-container.d.ts +16 -0
- package/common/dto/dto-container.js +20 -0
- package/common/dto/dto-decorators.d.ts +18 -0
- package/common/dto/dto-decorators.js +14 -0
- package/common/dto/dto-extensions.d.ts +11 -0
- package/common/dto/dto-extensions.js +9 -0
- package/common/dto/dto-service-accessor.d.ts +17 -0
- package/common/dto/dto-service-accessor.js +18 -0
- package/common/dto/dto-transformer.d.ts +12 -0
- package/common/dto/dto-transformer.js +9 -0
- package/common/dto/index.js +2 -0
- package/common/examples/paginate-and-map.example.d.ts +6 -0
- package/common/examples/paginate-and-map.example.js +26 -0
- package/common/utils.d.ts +15 -0
- package/common/utils.js +15 -0
- package/constants/language-code.js +1 -0
- package/decorators/field.decorators.js +8 -1
- package/decorators/property.decorators.js +1 -0
- package/decorators/public-route.decorator.js +1 -0
- package/decorators/transform.decorators.d.ts +27 -0
- package/decorators/transform.decorators.js +29 -0
- package/decorators/translate.decorator.js +1 -0
- package/decorators/user.decorator.js +1 -0
- package/decorators/validator.decorators.d.ts +8 -18
- package/decorators/validator.decorators.js +22 -190
- package/filters/constraint-errors.js +1 -0
- package/helpers/common.helper.d.ts +13 -0
- package/helpers/common.helper.js +13 -0
- package/http-client/config/http-client.config.d.ts +15 -0
- package/http-client/config/http-client.config.js +25 -9
- package/http-client/decorators/http-client.decorators.d.ts +63 -0
- package/http-client/decorators/http-client.decorators.js +71 -3
- package/http-client/entities/http-log.entity.d.ts +229 -0
- package/http-client/entities/http-log.entity.js +6 -1
- package/http-client/errors/http-client.errors.d.ts +57 -0
- package/http-client/errors/http-client.errors.js +58 -0
- package/http-client/examples/advanced-usage.example.d.ts +41 -0
- package/http-client/examples/advanced-usage.example.js +68 -24
- package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
- package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
- package/http-client/examples/basic-usage.example.d.ts +60 -0
- package/http-client/examples/basic-usage.example.js +60 -0
- package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
- package/http-client/examples/multi-api-configuration.example.js +76 -5
- package/http-client/http-client.module.d.ts +13 -0
- package/http-client/http-client.module.js +19 -0
- package/http-client/index.js +8 -0
- package/http-client/interfaces/api-client-config.interface.d.ts +125 -0
- package/http-client/interfaces/api-client-config.interface.js +3 -0
- package/http-client/interfaces/http-client-config.interface.d.ts +60 -0
- package/http-client/services/api-client-registry.service.d.ts +57 -0
- package/http-client/services/api-client-registry.service.js +84 -1
- package/http-client/services/cache.service.d.ts +52 -0
- package/http-client/services/cache.service.js +72 -3
- package/http-client/services/circuit-breaker.service.d.ts +46 -0
- package/http-client/services/circuit-breaker.service.js +52 -0
- package/http-client/services/http-client.service.d.ts +67 -0
- package/http-client/services/http-client.service.js +105 -4
- package/http-client/services/http-log-query.service.d.ts +83 -0
- package/http-client/services/http-log-query.service.js +122 -1
- package/http-client/services/http-replay.service.d.ts +101 -0
- package/http-client/services/http-replay.service.js +86 -0
- package/http-client/services/log-cleanup.service.d.ts +63 -0
- package/http-client/services/log-cleanup.service.js +54 -2
- package/http-client/services/logging.service.d.ts +40 -0
- package/http-client/services/logging.service.js +53 -0
- package/http-client/utils/call-stack-extractor.util.d.ts +37 -0
- package/http-client/utils/call-stack-extractor.util.js +48 -0
- package/http-client/utils/context-extractor.util.d.ts +49 -0
- package/http-client/utils/context-extractor.util.js +52 -0
- package/http-client/utils/curl-generator.util.d.ts +21 -0
- package/http-client/utils/curl-generator.util.js +44 -3
- package/http-client/utils/request-id.util.d.ts +18 -0
- package/http-client/utils/request-id.util.js +20 -0
- package/http-client/utils/retry-recorder.util.d.ts +42 -0
- package/http-client/utils/retry-recorder.util.js +44 -0
- package/index.js +8 -0
- package/interceptors/translation-interceptor.service.js +5 -0
- package/package.json +1 -1
- package/providers/context.provider.js +2 -0
- package/providers/generator.provider.d.ts +4 -0
- package/providers/generator.provider.js +4 -0
- package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
- package/redis-lock/examples/lock-strategy.examples.js +130 -15
- package/redis-lock/index.js +3 -0
- package/redis-lock/redis-lock.decorator.d.ts +101 -0
- package/redis-lock/redis-lock.decorator.js +120 -0
- package/redis-lock/redis-lock.module.d.ts +60 -0
- package/redis-lock/redis-lock.module.js +46 -0
- package/redis-lock/redis-lock.service.d.ts +251 -0
- package/redis-lock/redis-lock.service.js +219 -3
- package/setup/bootstrap.setup.js +20 -0
- package/setup/mode.setup.d.ts +44 -0
- package/setup/mode.setup.js +44 -0
- package/setup/schedule.decorator.d.ts +226 -0
- package/setup/schedule.decorator.js +214 -1
- package/setup/worker.decorator.d.ts +86 -0
- package/setup/worker.decorator.js +88 -0
- package/shared/serviceRegistryModule.js +5 -1
- package/shared/services/api-config.service.d.ts +3 -0
- package/shared/services/api-config.service.js +20 -9
- package/validator-json/decorators.d.ts +17 -0
- package/validator-json/decorators.js +17 -2
- package/validator-json/default.d.ts +6 -0
- package/validator-json/default.js +30 -2
- package/validator-json/defaultConverters.js +1 -0
- package/validator-json/options.d.ts +23 -0
- package/validators/common-validators.d.ts +143 -0
- package/validators/common-validators.js +249 -0
- package/validators/custom-validate.examples.d.ts +23 -0
- package/validators/custom-validate.examples.js +78 -6
- package/validators/custom-validate.validator.d.ts +107 -0
- package/validators/custom-validate.validator.js +84 -0
- package/validators/index.d.ts +1 -0
- package/validators/index.js +1 -0
- package/validators/is-exists.validator.d.ts +11 -0
- package/validators/is-exists.validator.js +22 -0
- package/validators/is-unique.validator.d.ts +11 -0
- package/validators/is-unique.validator.js +31 -3
- package/validators/skip-empty.validator.d.ts +5 -0
- package/validators/skip-empty.validator.js +5 -0
- package/vault/interfaces/vault-options.interface.d.ts +9 -0
- package/vault/vault-config.loader.d.ts +30 -0
- package/vault/vault-config.loader.js +48 -1
- package/vault/vault-config.service.d.ts +53 -0
- package/vault/vault-config.service.js +57 -0
- package/vault/vault.module.d.ts +4 -0
- package/vault/vault.module.js +4 -0
- package/decorators/examples/validation-decorators.example.d.ts +0 -69
- package/decorators/examples/validation-decorators.example.js +0 -331
package/audit/index.js
CHANGED
|
@@ -14,13 +14,23 @@ 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
|
+
// Entities
|
|
17
18
|
__exportStar(require("./entities"), exports);
|
|
19
|
+
// Enums
|
|
18
20
|
__exportStar(require("./enums"), exports);
|
|
21
|
+
// Interfaces
|
|
19
22
|
__exportStar(require("./interfaces"), exports);
|
|
23
|
+
// DTO
|
|
20
24
|
__exportStar(require("./dto"), exports);
|
|
25
|
+
// Decorators
|
|
21
26
|
__exportStar(require("./decorators"), exports);
|
|
27
|
+
// Services
|
|
22
28
|
__exportStar(require("./services"), exports);
|
|
29
|
+
// Subscribers
|
|
23
30
|
__exportStar(require("./subscribers"), exports);
|
|
31
|
+
// Interceptors
|
|
24
32
|
__exportStar(require("./interceptors"), exports);
|
|
33
|
+
// Controllers
|
|
25
34
|
__exportStar(require("./controllers"), exports);
|
|
35
|
+
// Module
|
|
26
36
|
__exportStar(require("./audit.module"), exports);
|
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { AuditContextService } from '../services/audit-context.service';
|
|
4
|
+
/**
|
|
5
|
+
* 审计拦截器
|
|
6
|
+
*/
|
|
4
7
|
export declare class AuditInterceptor implements NestInterceptor {
|
|
5
8
|
private readonly contextService;
|
|
6
9
|
constructor(contextService: AuditContextService);
|
|
7
10
|
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
11
|
+
/**
|
|
12
|
+
* 设置请求上下文
|
|
13
|
+
*/
|
|
8
14
|
private setRequestContext;
|
|
15
|
+
/**
|
|
16
|
+
* 处理错误
|
|
17
|
+
*/
|
|
9
18
|
private handleError;
|
|
19
|
+
/**
|
|
20
|
+
* 检查是否启用了审计
|
|
21
|
+
*/
|
|
10
22
|
private isAuditEnabled;
|
|
23
|
+
/**
|
|
24
|
+
* 生成请求ID
|
|
25
|
+
*/
|
|
11
26
|
private generateRequestId;
|
|
12
27
|
}
|
|
@@ -24,6 +24,9 @@ const operators_1 = require("rxjs/operators");
|
|
|
24
24
|
const crypto_1 = require("crypto");
|
|
25
25
|
const audit_context_service_1 = require("../services/audit-context.service");
|
|
26
26
|
const decorators_1 = require("../decorators");
|
|
27
|
+
/**
|
|
28
|
+
* 审计拦截器
|
|
29
|
+
*/
|
|
27
30
|
let AuditInterceptor = class AuditInterceptor {
|
|
28
31
|
constructor(contextService) {
|
|
29
32
|
this.contextService = contextService;
|
|
@@ -32,16 +35,23 @@ let AuditInterceptor = class AuditInterceptor {
|
|
|
32
35
|
const request = context.switchToHttp().getRequest();
|
|
33
36
|
const handler = context.getHandler();
|
|
34
37
|
const controller = context.getClass();
|
|
38
|
+
// 检查是否启用了审计
|
|
35
39
|
if (!this.isAuditEnabled(controller, handler)) {
|
|
36
40
|
return next.handle();
|
|
37
41
|
}
|
|
42
|
+
// 设置请求上下文
|
|
38
43
|
this.setRequestContext(request);
|
|
39
44
|
return next.handle().pipe((0, operators_1.tap)(() => {
|
|
45
|
+
// 在响应后执行的操作
|
|
40
46
|
}), (0, operators_1.catchError)((error) => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
// 处理错误情况
|
|
41
48
|
yield this.handleError(error, request);
|
|
42
49
|
throw error;
|
|
43
50
|
})));
|
|
44
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* 设置请求上下文
|
|
54
|
+
*/
|
|
45
55
|
setRequestContext(request) {
|
|
46
56
|
var _a, _b, _c;
|
|
47
57
|
const user = request.user || {};
|
|
@@ -55,8 +65,12 @@ let AuditInterceptor = class AuditInterceptor {
|
|
|
55
65
|
};
|
|
56
66
|
this.contextService.setContext(auditContext);
|
|
57
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* 处理错误
|
|
70
|
+
*/
|
|
58
71
|
handleError(error, request) {
|
|
59
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
// 记录错误信息到上下文
|
|
60
74
|
this.contextService.setContext({
|
|
61
75
|
metadata: {
|
|
62
76
|
error: {
|
|
@@ -68,12 +82,17 @@ let AuditInterceptor = class AuditInterceptor {
|
|
|
68
82
|
});
|
|
69
83
|
});
|
|
70
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* 检查是否启用了审计
|
|
87
|
+
*/
|
|
71
88
|
isAuditEnabled(controller, handler) {
|
|
72
89
|
try {
|
|
90
|
+
// 检查控制器级别设置
|
|
73
91
|
const controllerMetadata = Reflect.getMetadata(decorators_1.CONTROLLER_AUDIT_OPTIONS, controller);
|
|
74
92
|
if (controllerMetadata && controllerMetadata.enabled === false) {
|
|
75
93
|
return false;
|
|
76
94
|
}
|
|
95
|
+
// 检查方法级别设置
|
|
77
96
|
const handlerMetadata = Reflect.getMetadata(decorators_1.METHOD_AUDIT_OPTIONS, handler);
|
|
78
97
|
if (handlerMetadata && handlerMetadata.enabled === false) {
|
|
79
98
|
return false;
|
|
@@ -81,9 +100,12 @@ let AuditInterceptor = class AuditInterceptor {
|
|
|
81
100
|
return true;
|
|
82
101
|
}
|
|
83
102
|
catch (error) {
|
|
84
|
-
return true;
|
|
103
|
+
return true; // 默认启用
|
|
85
104
|
}
|
|
86
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* 生成请求ID
|
|
108
|
+
*/
|
|
87
109
|
generateRequestId() {
|
|
88
110
|
return (0, crypto_1.randomBytes)(16).toString('hex');
|
|
89
111
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { AuditOperation, MaskingStrategy, RecordStrategy } from '../enums/audit.enums';
|
|
2
|
+
/**
|
|
3
|
+
* 审计上下文
|
|
4
|
+
*/
|
|
2
5
|
export interface AuditContext {
|
|
3
6
|
userId?: string;
|
|
4
7
|
username?: string;
|
|
@@ -9,16 +12,25 @@ export interface AuditContext {
|
|
|
9
12
|
transactionId?: string;
|
|
10
13
|
metadata?: Record<string, any>;
|
|
11
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* 审计策略接口
|
|
17
|
+
*/
|
|
12
18
|
export interface IAuditStrategy {
|
|
13
19
|
shouldRecord(entityType: string, operation: AuditOperation): boolean;
|
|
14
20
|
getRecordStrategy(entityType: string, operation: AuditOperation): RecordStrategy;
|
|
15
21
|
getFieldFilter(entityType: string): IFieldFilter;
|
|
16
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* 字段过滤器接口
|
|
25
|
+
*/
|
|
17
26
|
export interface IFieldFilter {
|
|
18
27
|
shouldIncludeField(fieldName: string, path: string[]): boolean;
|
|
19
28
|
shouldMaskField(fieldName: string, path: string[]): boolean;
|
|
20
29
|
getMaskingStrategy(fieldName: string, path: string[]): MaskingStrategy;
|
|
21
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* 实体差异
|
|
33
|
+
*/
|
|
22
34
|
export interface EntityDifference {
|
|
23
35
|
changes: Array<{
|
|
24
36
|
path: string[];
|
|
@@ -32,6 +44,9 @@ export interface EntityDifference {
|
|
|
32
44
|
changed: number;
|
|
33
45
|
};
|
|
34
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* 恢复选项
|
|
49
|
+
*/
|
|
35
50
|
export interface RestoreOptions {
|
|
36
51
|
force?: boolean;
|
|
37
52
|
dryRun?: boolean;
|
|
@@ -40,6 +55,9 @@ export interface RestoreOptions {
|
|
|
40
55
|
skipDependencies?: boolean;
|
|
41
56
|
connectionName?: string;
|
|
42
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* 恢复结果
|
|
60
|
+
*/
|
|
43
61
|
export interface RestoreResult {
|
|
44
62
|
success: boolean;
|
|
45
63
|
message?: string;
|
|
@@ -54,6 +72,9 @@ export interface RestoreResult {
|
|
|
54
72
|
entityId: string;
|
|
55
73
|
}>;
|
|
56
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* 预检查结果
|
|
77
|
+
*/
|
|
57
78
|
export interface PreCheckResult {
|
|
58
79
|
canRestore: boolean;
|
|
59
80
|
conflicts: Array<{
|
|
@@ -64,6 +85,9 @@ export interface PreCheckResult {
|
|
|
64
85
|
}>;
|
|
65
86
|
warnings: string[];
|
|
66
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* 批量操作结果
|
|
90
|
+
*/
|
|
67
91
|
export interface BatchOperationResult {
|
|
68
92
|
total: number;
|
|
69
93
|
success: number;
|
|
@@ -74,6 +98,9 @@ export interface BatchOperationResult {
|
|
|
74
98
|
}>;
|
|
75
99
|
results: any[];
|
|
76
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* 审计配置
|
|
103
|
+
*/
|
|
77
104
|
export interface AuditConfig {
|
|
78
105
|
enabled?: boolean;
|
|
79
106
|
defaultStrategy?: RecordStrategy;
|
|
@@ -94,6 +121,9 @@ export interface AuditConfig {
|
|
|
94
121
|
};
|
|
95
122
|
};
|
|
96
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* 实体级别审计配置
|
|
126
|
+
*/
|
|
97
127
|
export interface EntityAuditConfig {
|
|
98
128
|
enabled?: boolean;
|
|
99
129
|
strategy?: RecordStrategy;
|
|
@@ -101,19 +131,31 @@ export interface EntityAuditConfig {
|
|
|
101
131
|
excludeFields?: string[];
|
|
102
132
|
maskFields?: string[];
|
|
103
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* 操作级别审计配置
|
|
136
|
+
*/
|
|
104
137
|
export interface OperationAuditConfig {
|
|
105
138
|
enabled?: boolean;
|
|
106
139
|
strategy?: RecordStrategy;
|
|
107
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* 字段显示选项
|
|
143
|
+
*/
|
|
108
144
|
export interface FieldDisplayOptions {
|
|
109
145
|
displayName?: string;
|
|
110
146
|
sensitive?: boolean;
|
|
111
147
|
formatter?: (value: any) => string;
|
|
112
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* 控制器审计选项
|
|
151
|
+
*/
|
|
113
152
|
export interface ControllerAuditOptions {
|
|
114
153
|
enabled?: boolean;
|
|
115
154
|
operations?: AuditOperation[];
|
|
116
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* 方法审计选项
|
|
158
|
+
*/
|
|
117
159
|
export interface MethodAuditOptions {
|
|
118
160
|
enabled?: boolean;
|
|
119
161
|
}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { ClsService } from 'nestjs-cls';
|
|
2
2
|
import { AuditContext } from '../interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* 审计上下文服务
|
|
5
|
+
*/
|
|
3
6
|
export declare class AuditContextService {
|
|
4
7
|
private readonly cls;
|
|
5
8
|
constructor(cls: ClsService);
|
|
9
|
+
/**
|
|
10
|
+
* 获取当前上下文
|
|
11
|
+
*/
|
|
6
12
|
getCurrentContext(): Promise<AuditContext>;
|
|
13
|
+
/**
|
|
14
|
+
* 设置上下文
|
|
15
|
+
*/
|
|
7
16
|
setContext(context: Partial<AuditContext>): void;
|
|
17
|
+
/**
|
|
18
|
+
* 清除上下文
|
|
19
|
+
*/
|
|
8
20
|
clearContext(): void;
|
|
21
|
+
/**
|
|
22
|
+
* 获取默认上下文
|
|
23
|
+
*/
|
|
9
24
|
private getDefaultContext;
|
|
10
25
|
}
|
|
@@ -21,22 +21,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
exports.AuditContextService = void 0;
|
|
22
22
|
const common_1 = require("@nestjs/common");
|
|
23
23
|
const nestjs_cls_1 = require("nestjs-cls");
|
|
24
|
+
/**
|
|
25
|
+
* 审计上下文服务
|
|
26
|
+
*/
|
|
24
27
|
let AuditContextService = class AuditContextService {
|
|
25
28
|
constructor(cls) {
|
|
26
29
|
this.cls = cls;
|
|
27
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* 获取当前上下文
|
|
33
|
+
*/
|
|
28
34
|
getCurrentContext() {
|
|
29
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
36
|
return this.cls.get('auditContext') || this.getDefaultContext();
|
|
31
37
|
});
|
|
32
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* 设置上下文
|
|
41
|
+
*/
|
|
33
42
|
setContext(context) {
|
|
34
43
|
const currentContext = this.cls.get('auditContext') || this.getDefaultContext();
|
|
35
44
|
this.cls.set('auditContext', Object.assign(Object.assign({}, currentContext), context));
|
|
36
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* 清除上下文
|
|
48
|
+
*/
|
|
37
49
|
clearContext() {
|
|
38
50
|
this.cls.set('auditContext', undefined);
|
|
39
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* 获取默认上下文
|
|
54
|
+
*/
|
|
40
55
|
getDefaultContext() {
|
|
41
56
|
return {
|
|
42
57
|
userId: 'system',
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { IAuditStrategy, IFieldFilter, AuditConfig } from '../interfaces';
|
|
2
2
|
import { AuditOperation, RecordStrategy, MaskingStrategy } from '../enums';
|
|
3
|
+
/**
|
|
4
|
+
* 默认字段过滤器
|
|
5
|
+
*/
|
|
3
6
|
export declare class DefaultFieldFilter implements IFieldFilter {
|
|
4
7
|
private readonly includeFields?;
|
|
5
8
|
private readonly excludeFields?;
|
|
@@ -10,6 +13,9 @@ export declare class DefaultFieldFilter implements IFieldFilter {
|
|
|
10
13
|
getMaskingStrategy(fieldName: string, path: string[]): MaskingStrategy;
|
|
11
14
|
private matchPattern;
|
|
12
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* 默认审计策略
|
|
18
|
+
*/
|
|
13
19
|
export declare class DefaultAuditStrategy implements IAuditStrategy {
|
|
14
20
|
private readonly config?;
|
|
15
21
|
constructor(config?: AuditConfig);
|
|
@@ -15,6 +15,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.DefaultAuditStrategy = exports.DefaultFieldFilter = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const enums_1 = require("../enums");
|
|
18
|
+
/**
|
|
19
|
+
* 默认字段过滤器
|
|
20
|
+
*/
|
|
18
21
|
class DefaultFieldFilter {
|
|
19
22
|
constructor(includeFields, excludeFields, maskFields) {
|
|
20
23
|
this.includeFields = includeFields;
|
|
@@ -23,9 +26,11 @@ class DefaultFieldFilter {
|
|
|
23
26
|
}
|
|
24
27
|
shouldIncludeField(fieldName, path) {
|
|
25
28
|
const fullPath = [...path, fieldName].join('.');
|
|
29
|
+
// 如果指定了包含字段,则只记录这些字段
|
|
26
30
|
if (this.includeFields && this.includeFields.length > 0) {
|
|
27
31
|
return this.includeFields.some((pattern) => this.matchPattern(fullPath, pattern));
|
|
28
32
|
}
|
|
33
|
+
// 如果指定了排除字段,则排除这些字段
|
|
29
34
|
if (this.excludeFields && this.excludeFields.length > 0) {
|
|
30
35
|
return !this.excludeFields.some((pattern) => this.matchPattern(fullPath, pattern));
|
|
31
36
|
}
|
|
@@ -40,6 +45,7 @@ class DefaultFieldFilter {
|
|
|
40
45
|
return enums_1.MaskingStrategy.MASK;
|
|
41
46
|
}
|
|
42
47
|
matchPattern(path, pattern) {
|
|
48
|
+
// 支持通配符匹配,如 user.address.*
|
|
43
49
|
if (pattern.endsWith('*')) {
|
|
44
50
|
return path.startsWith(pattern.slice(0, -1));
|
|
45
51
|
}
|
|
@@ -47,18 +53,24 @@ class DefaultFieldFilter {
|
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
55
|
exports.DefaultFieldFilter = DefaultFieldFilter;
|
|
56
|
+
/**
|
|
57
|
+
* 默认审计策略
|
|
58
|
+
*/
|
|
50
59
|
let DefaultAuditStrategy = class DefaultAuditStrategy {
|
|
51
60
|
constructor(config) {
|
|
52
61
|
this.config = config;
|
|
53
62
|
}
|
|
54
63
|
shouldRecord(entityType, operation) {
|
|
55
64
|
var _a, _b, _c, _d, _e;
|
|
65
|
+
// 检查全局配置
|
|
56
66
|
const globalEnabled = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.enabled) !== false;
|
|
57
67
|
if (!globalEnabled)
|
|
58
68
|
return false;
|
|
69
|
+
// 检查实体级别配置
|
|
59
70
|
const entityConfig = (_c = (_b = this.config) === null || _b === void 0 ? void 0 : _b.entities) === null || _c === void 0 ? void 0 : _c[entityType];
|
|
60
71
|
if (entityConfig && entityConfig.enabled === false)
|
|
61
72
|
return false;
|
|
73
|
+
// 检查操作级别配置
|
|
62
74
|
const operationConfig = (_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.operations) === null || _e === void 0 ? void 0 : _e[operation];
|
|
63
75
|
if (operationConfig && operationConfig.enabled === false)
|
|
64
76
|
return false;
|
|
@@ -66,6 +78,7 @@ let DefaultAuditStrategy = class DefaultAuditStrategy {
|
|
|
66
78
|
}
|
|
67
79
|
getRecordStrategy(entityType, operation) {
|
|
68
80
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
81
|
+
// 优先级: 实体级别 > 操作级别 > 全局默认
|
|
69
82
|
const entityStrategy = (_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.entities) === null || _b === void 0 ? void 0 : _b[entityType]) === null || _c === void 0 ? void 0 : _c.strategy;
|
|
70
83
|
if (entityStrategy)
|
|
71
84
|
return entityStrategy;
|
|
@@ -6,6 +6,9 @@ import { AuditContextService } from './audit-context.service';
|
|
|
6
6
|
import { MultiDatabaseService } from './multi-database.service';
|
|
7
7
|
import { PageDto } from '../../common/dto';
|
|
8
8
|
import { AuditLogQueryDto } from '../dto';
|
|
9
|
+
/**
|
|
10
|
+
* 实体审计服务
|
|
11
|
+
*/
|
|
9
12
|
export declare class EntityAuditService {
|
|
10
13
|
private readonly auditLogRepository;
|
|
11
14
|
private readonly transactionRepository;
|
|
@@ -16,22 +19,76 @@ export declare class EntityAuditService {
|
|
|
16
19
|
private readonly config?;
|
|
17
20
|
private readonly auditConnectionName;
|
|
18
21
|
constructor(auditLogRepository: Repository<EntityAuditLogEntity>, transactionRepository: Repository<EntityTransactionEntity>, entityManager: EntityManager, contextService: AuditContextService, multiDbService: MultiDatabaseService, auditStrategy?: IAuditStrategy, config?: AuditConfig, auditConnectionName?: string);
|
|
22
|
+
/**
|
|
23
|
+
* 记录实体变更
|
|
24
|
+
*/
|
|
19
25
|
logEntityChange(entityType: string, entityId: string, operation: AuditOperation, oldValue: Record<string, any>, newValue: Record<string, any>, metadata?: Record<string, any>): Promise<EntityAuditLogEntity | null>;
|
|
26
|
+
/**
|
|
27
|
+
* 查询审计日志
|
|
28
|
+
*/
|
|
20
29
|
getAuditLogs(query: AuditLogQueryDto): Promise<PageDto<EntityAuditLogEntity>>;
|
|
30
|
+
/**
|
|
31
|
+
* 比较实体差异
|
|
32
|
+
*/
|
|
21
33
|
compareEntities(entityType: string, entityId: string, fromLogId?: string, toLogId?: string): Promise<EntityDifference>;
|
|
34
|
+
/**
|
|
35
|
+
* 预检查恢复操作
|
|
36
|
+
*/
|
|
22
37
|
preCheckRestore(entityType: string, entityId: string, auditLogId: string): Promise<PreCheckResult>;
|
|
38
|
+
/**
|
|
39
|
+
* 恢复实体
|
|
40
|
+
*/
|
|
23
41
|
restoreEntity(entityType: string, entityId: string, auditLogId: string, options?: RestoreOptions): Promise<RestoreResult>;
|
|
42
|
+
/**
|
|
43
|
+
* 计算变更字段
|
|
44
|
+
*/
|
|
24
45
|
private calculateChangedFields;
|
|
46
|
+
/**
|
|
47
|
+
* 计算变更字段路径
|
|
48
|
+
*/
|
|
25
49
|
private calculateChangedFieldPaths;
|
|
50
|
+
/**
|
|
51
|
+
* 深度比较对象
|
|
52
|
+
*/
|
|
26
53
|
private deepEqual;
|
|
54
|
+
/**
|
|
55
|
+
* 深度差异比较
|
|
56
|
+
*/
|
|
27
57
|
private deepDiff;
|
|
58
|
+
/**
|
|
59
|
+
* 比较快照数据
|
|
60
|
+
*/
|
|
28
61
|
private compareSnapshotData;
|
|
62
|
+
/**
|
|
63
|
+
* 过滤和脱敏字段
|
|
64
|
+
*/
|
|
29
65
|
private filterAndMaskFields;
|
|
66
|
+
/**
|
|
67
|
+
* 应用脱敏策略
|
|
68
|
+
*/
|
|
30
69
|
private applyMasking;
|
|
70
|
+
/**
|
|
71
|
+
* 哈希值
|
|
72
|
+
*/
|
|
31
73
|
private hashValue;
|
|
74
|
+
/**
|
|
75
|
+
* 掩码值
|
|
76
|
+
*/
|
|
32
77
|
private maskValue;
|
|
78
|
+
/**
|
|
79
|
+
* 部分掩码值
|
|
80
|
+
*/
|
|
33
81
|
private partialMaskValue;
|
|
82
|
+
/**
|
|
83
|
+
* 生成哈希链
|
|
84
|
+
*/
|
|
34
85
|
private generateHashChain;
|
|
86
|
+
/**
|
|
87
|
+
* 生成描述
|
|
88
|
+
*/
|
|
35
89
|
private generateDescription;
|
|
90
|
+
/**
|
|
91
|
+
* 检测冲突
|
|
92
|
+
*/
|
|
36
93
|
private detectConflicts;
|
|
37
94
|
}
|