@nest-omni/core 4.1.3-1 → 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.d.ts +10 -0
- package/audit/audit.module.js +39 -1
- 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 +9 -1
- package/audit/decorators/audit-controller.decorator.js +11 -2
- 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 +76 -1
- package/audit/decorators/entity-audit.decorator.js +135 -3
- package/audit/decorators/index.d.ts +1 -0
- package/audit/decorators/index.js +1 -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 +8 -0
- package/audit/entities/entity-audit-log.entity.js +33 -1
- package/audit/entities/entity-transaction.entity.d.ts +10 -0
- package/audit/entities/entity-transaction.entity.js +33 -1
- package/audit/entities/index.d.ts +2 -0
- package/audit/entities/index.js +2 -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 +45 -5
- package/audit/enums/audit.enums.js +47 -4
- package/audit/index.d.ts +3 -1
- package/audit/index.js +30 -1
- package/audit/interceptors/audit.interceptor.d.ts +15 -0
- package/audit/interceptors/audit.interceptor.js +23 -1
- package/audit/interfaces/audit.interfaces.d.ts +182 -2
- 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 +129 -3
- package/audit/services/entity-audit.service.js +301 -6
- package/audit/services/index.d.ts +2 -0
- package/audit/services/index.js +2 -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 -4
- package/common/boilerplate.polyfill.js +24 -100
- 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 +20 -5
- 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/i18n/en_US/validation.json +2 -1
- package/i18n/zh_CN/validation.json +2 -1
- 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/comprehensive-lock-cleanup.service.d.ts +94 -0
- package/redis-lock/comprehensive-lock-cleanup.service.js +253 -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.d.ts +2 -0
- package/redis-lock/index.js +8 -1
- package/redis-lock/lock-heartbeat.service.d.ts +78 -0
- package/redis-lock/lock-heartbeat.service.js +222 -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 +66 -0
- package/redis-lock/redis-lock.module.js +175 -70
- package/redis-lock/redis-lock.service.d.ts +278 -0
- package/redis-lock/redis-lock.service.js +282 -12
- 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 +227 -0
- package/setup/schedule.decorator.js +235 -12
- package/setup/worker.decorator.d.ts +86 -0
- package/setup/worker.decorator.js +88 -0
- package/shared/serviceRegistryModule.js +27 -14
- 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 +96 -0
- package/validators/custom-validate.examples.js +400 -0
- package/validators/custom-validate.validator.d.ts +134 -0
- package/validators/custom-validate.validator.js +214 -0
- package/validators/index.d.ts +2 -0
- package/validators/index.js +2 -0
- package/validators/is-exists.validator.d.ts +18 -4
- package/validators/is-exists.validator.js +67 -6
- package/validators/is-unique.validator.d.ts +32 -5
- package/validators/is-unique.validator.js +99 -17
- 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
|
@@ -2,6 +2,11 @@ import { Repository, DataSource } from 'typeorm';
|
|
|
2
2
|
import { ManualOperationLogEntity, EntityTransactionEntity } from '../entities';
|
|
3
3
|
import { AuditContextService } from './audit-context.service';
|
|
4
4
|
import { ManualLogOptions } from '../interfaces';
|
|
5
|
+
/**
|
|
6
|
+
* 手动审计日志服务
|
|
7
|
+
*
|
|
8
|
+
* 提供全局静态方法,在任意地方手动记录操作日志
|
|
9
|
+
*/
|
|
5
10
|
export declare class ManualAuditLogService {
|
|
6
11
|
private readonly manualLogRepository;
|
|
7
12
|
private readonly transactionRepository;
|
|
@@ -9,15 +14,134 @@ export declare class ManualAuditLogService {
|
|
|
9
14
|
private readonly dataSource;
|
|
10
15
|
private static instance;
|
|
11
16
|
constructor(manualLogRepository: Repository<ManualOperationLogEntity>, transactionRepository: Repository<EntityTransactionEntity>, contextService: AuditContextService, dataSource: DataSource);
|
|
17
|
+
/**
|
|
18
|
+
* 全局静态方法:记录操作日志
|
|
19
|
+
*
|
|
20
|
+
* @description
|
|
21
|
+
* 支持三种记录模式:
|
|
22
|
+
* 1. 模板键模式:从数据库查找模板
|
|
23
|
+
* 2. 直接描述模式:直接传入字符串或多语言描述
|
|
24
|
+
* 3. 内联模板模式:传入多语言模板 + 参数
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // 模式1:模板键模式
|
|
28
|
+
* await ManualAuditLogService.log({
|
|
29
|
+
* templateKey: 'user.login',
|
|
30
|
+
* descriptionParams: {
|
|
31
|
+
* username: 'john.doe',
|
|
32
|
+
* loginTime: new Date().toISOString(),
|
|
33
|
+
* },
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // 模式2:直接描述模式(字符串)
|
|
38
|
+
* await ManualAuditLogService.log({
|
|
39
|
+
* description: '用户登录系统',
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // 模式2:直接描述模式(多语言)
|
|
44
|
+
* await ManualAuditLogService.log({
|
|
45
|
+
* description: {
|
|
46
|
+
* zh: '用户登录系统',
|
|
47
|
+
* en: 'User logged in',
|
|
48
|
+
* },
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // 模式3:内联模板模式
|
|
53
|
+
* await ManualAuditLogService.log({
|
|
54
|
+
* descriptionTemplate: {
|
|
55
|
+
* zh: '用户 {username} 在 {time} 登录了系统',
|
|
56
|
+
* en: 'User {username} logged in at {time}',
|
|
57
|
+
* },
|
|
58
|
+
* descriptionParams: {
|
|
59
|
+
* username: 'john.doe',
|
|
60
|
+
* time: new Date().toISOString(),
|
|
61
|
+
* },
|
|
62
|
+
* });
|
|
63
|
+
*/
|
|
12
64
|
static log(options: ManualLogOptions): Promise<ManualOperationLogEntity>;
|
|
65
|
+
/**
|
|
66
|
+
* 实例方法:记录操作日志
|
|
67
|
+
*/
|
|
13
68
|
logOperation(options: ManualLogOptions): Promise<ManualOperationLogEntity>;
|
|
69
|
+
/**
|
|
70
|
+
* 静态方法:带事务记录
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const txId = await ManualAuditLogService.beginTransaction('user-123', 'John Doe');
|
|
75
|
+
*
|
|
76
|
+
* await ManualAuditLogService.log({
|
|
77
|
+
* templateKey: 'order.create',
|
|
78
|
+
* descriptionParams: { orderId: 'order-1' },
|
|
79
|
+
* transactionId: txId,
|
|
80
|
+
* autoCreateTransaction: false,
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* await ManualAuditLogService.log({
|
|
84
|
+
* templateKey: 'payment.process',
|
|
85
|
+
* descriptionParams: { paymentId: 'pay-1' },
|
|
86
|
+
* transactionId: txId,
|
|
87
|
+
* autoCreateTransaction: false,
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* await ManualAuditLogService.commitTransaction(txId);
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
14
93
|
static beginTransaction(userId?: string, username?: string): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* 静态方法:提交事务
|
|
96
|
+
*/
|
|
15
97
|
static commitTransaction(transactionId: string): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* 静态方法:回滚事务
|
|
100
|
+
*/
|
|
16
101
|
static rollbackTransaction(transactionId: string): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* 创建事务
|
|
104
|
+
*/
|
|
17
105
|
private createTransaction;
|
|
106
|
+
/**
|
|
107
|
+
* 更新事务状态
|
|
108
|
+
*/
|
|
18
109
|
private updateTransactionStatus;
|
|
110
|
+
/**
|
|
111
|
+
* 生成事务ID
|
|
112
|
+
*/
|
|
19
113
|
private generateTransactionId;
|
|
114
|
+
/**
|
|
115
|
+
* 批量记录操作日志
|
|
116
|
+
*
|
|
117
|
+
* @description
|
|
118
|
+
* 批量记录多个操作,支持所有三种记录模式
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* // 混合使用多种模式
|
|
123
|
+
* await ManualAuditLogService.logBatch([
|
|
124
|
+
* {
|
|
125
|
+
* templateKey: 'product.update',
|
|
126
|
+
* descriptionParams: { productId: 'p1', field: 'price' },
|
|
127
|
+
* },
|
|
128
|
+
* {
|
|
129
|
+
* description: '批量更新库存',
|
|
130
|
+
* },
|
|
131
|
+
* {
|
|
132
|
+
* descriptionTemplate: {
|
|
133
|
+
* zh: '更新产品 {productId} 的 {field}',
|
|
134
|
+
* en: 'Update {field} of product {productId}',
|
|
135
|
+
* },
|
|
136
|
+
* descriptionParams: { productId: 'p3', field: 'stock' },
|
|
137
|
+
* },
|
|
138
|
+
* ]);
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
20
141
|
static logBatch(operations: ManualLogOptions[], sharedTransactionId?: string): Promise<ManualOperationLogEntity[]>;
|
|
142
|
+
/**
|
|
143
|
+
* 查询操作日志
|
|
144
|
+
*/
|
|
21
145
|
static findLogs(options: {
|
|
22
146
|
templateKey?: string;
|
|
23
147
|
userId?: string;
|
|
@@ -30,14 +30,67 @@ const entities_1 = require("../entities");
|
|
|
30
30
|
const audit_context_service_1 = require("./audit-context.service");
|
|
31
31
|
const enums_1 = require("../enums");
|
|
32
32
|
const crypto_1 = require("crypto");
|
|
33
|
+
/**
|
|
34
|
+
* 手动审计日志服务
|
|
35
|
+
*
|
|
36
|
+
* 提供全局静态方法,在任意地方手动记录操作日志
|
|
37
|
+
*/
|
|
33
38
|
let ManualAuditLogService = ManualAuditLogService_1 = class ManualAuditLogService {
|
|
34
39
|
constructor(manualLogRepository, transactionRepository, contextService, dataSource) {
|
|
35
40
|
this.manualLogRepository = manualLogRepository;
|
|
36
41
|
this.transactionRepository = transactionRepository;
|
|
37
42
|
this.contextService = contextService;
|
|
38
43
|
this.dataSource = dataSource;
|
|
44
|
+
// 设置静态实例
|
|
39
45
|
ManualAuditLogService_1.instance = this;
|
|
40
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* 全局静态方法:记录操作日志
|
|
49
|
+
*
|
|
50
|
+
* @description
|
|
51
|
+
* 支持三种记录模式:
|
|
52
|
+
* 1. 模板键模式:从数据库查找模板
|
|
53
|
+
* 2. 直接描述模式:直接传入字符串或多语言描述
|
|
54
|
+
* 3. 内联模板模式:传入多语言模板 + 参数
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // 模式1:模板键模式
|
|
58
|
+
* await ManualAuditLogService.log({
|
|
59
|
+
* templateKey: 'user.login',
|
|
60
|
+
* descriptionParams: {
|
|
61
|
+
* username: 'john.doe',
|
|
62
|
+
* loginTime: new Date().toISOString(),
|
|
63
|
+
* },
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* // 模式2:直接描述模式(字符串)
|
|
68
|
+
* await ManualAuditLogService.log({
|
|
69
|
+
* description: '用户登录系统',
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* // 模式2:直接描述模式(多语言)
|
|
74
|
+
* await ManualAuditLogService.log({
|
|
75
|
+
* description: {
|
|
76
|
+
* zh: '用户登录系统',
|
|
77
|
+
* en: 'User logged in',
|
|
78
|
+
* },
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* // 模式3:内联模板模式
|
|
83
|
+
* await ManualAuditLogService.log({
|
|
84
|
+
* descriptionTemplate: {
|
|
85
|
+
* zh: '用户 {username} 在 {time} 登录了系统',
|
|
86
|
+
* en: 'User {username} logged in at {time}',
|
|
87
|
+
* },
|
|
88
|
+
* descriptionParams: {
|
|
89
|
+
* username: 'john.doe',
|
|
90
|
+
* time: new Date().toISOString(),
|
|
91
|
+
* },
|
|
92
|
+
* });
|
|
93
|
+
*/
|
|
41
94
|
static log(options) {
|
|
42
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
96
|
if (!ManualAuditLogService_1.instance) {
|
|
@@ -46,30 +99,44 @@ let ManualAuditLogService = ManualAuditLogService_1 = class ManualAuditLogServic
|
|
|
46
99
|
return ManualAuditLogService_1.instance.logOperation(options);
|
|
47
100
|
});
|
|
48
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* 实例方法:记录操作日志
|
|
104
|
+
*/
|
|
49
105
|
logOperation(options) {
|
|
50
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
107
|
const { templateKey, description, descriptionTemplate, descriptionParams, userId, username, requestIp, rollbackActions, transactionId, autoCreateTransaction = true, } = options;
|
|
108
|
+
// 验证参数:至少提供一种模式
|
|
52
109
|
if (!templateKey && !description && !descriptionTemplate) {
|
|
53
110
|
throw new Error('ManualAuditLogService.log() requires one of: templateKey, description, or descriptionTemplate');
|
|
54
111
|
}
|
|
112
|
+
// 验证参数冲突
|
|
55
113
|
const modeCount = [templateKey, description, descriptionTemplate].filter(Boolean).length;
|
|
56
114
|
if (modeCount > 1) {
|
|
57
115
|
throw new Error('ManualAuditLogService.log() accepts only one mode: use either templateKey, description, or descriptionTemplate');
|
|
58
116
|
}
|
|
117
|
+
// 获取当前上下文(如果有)
|
|
59
118
|
const context = yield this.contextService.getCurrentContext();
|
|
119
|
+
// 合并用户信息(优先使用传入的参数)
|
|
60
120
|
const finalUserId = userId || context.userId || 'system';
|
|
61
121
|
const finalUsername = username || context.username || 'system';
|
|
62
122
|
const finalRequestIp = requestIp || context.requestIp || 'unknown';
|
|
123
|
+
// 生成或使用事务ID
|
|
63
124
|
let finalTransactionId = transactionId || context.transactionId;
|
|
64
125
|
if (!finalTransactionId && autoCreateTransaction) {
|
|
126
|
+
// 自动创建事务
|
|
65
127
|
finalTransactionId = yield this.createTransaction(finalUserId, finalUsername);
|
|
66
128
|
}
|
|
129
|
+
// 创建手动操作日志
|
|
67
130
|
const manualLog = this.manualLogRepository.create({
|
|
68
131
|
transactionId: finalTransactionId,
|
|
132
|
+
// 模式1: 模板键模式
|
|
69
133
|
operationTemplateKey: templateKey || null,
|
|
70
134
|
descriptionParams: descriptionParams || null,
|
|
135
|
+
// 模式2: 直接描���模式
|
|
71
136
|
directDescription: description || null,
|
|
137
|
+
// 模式3: 内联模板模式
|
|
72
138
|
inlineTemplate: descriptionTemplate || null,
|
|
139
|
+
// 通用字段
|
|
73
140
|
userId: finalUserId,
|
|
74
141
|
username: finalUsername,
|
|
75
142
|
requestIp: finalRequestIp,
|
|
@@ -78,6 +145,30 @@ let ManualAuditLogService = ManualAuditLogService_1 = class ManualAuditLogServic
|
|
|
78
145
|
return this.manualLogRepository.save(manualLog);
|
|
79
146
|
});
|
|
80
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* 静态方法:带事务记录
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const txId = await ManualAuditLogService.beginTransaction('user-123', 'John Doe');
|
|
154
|
+
*
|
|
155
|
+
* await ManualAuditLogService.log({
|
|
156
|
+
* templateKey: 'order.create',
|
|
157
|
+
* descriptionParams: { orderId: 'order-1' },
|
|
158
|
+
* transactionId: txId,
|
|
159
|
+
* autoCreateTransaction: false,
|
|
160
|
+
* });
|
|
161
|
+
*
|
|
162
|
+
* await ManualAuditLogService.log({
|
|
163
|
+
* templateKey: 'payment.process',
|
|
164
|
+
* descriptionParams: { paymentId: 'pay-1' },
|
|
165
|
+
* transactionId: txId,
|
|
166
|
+
* autoCreateTransaction: false,
|
|
167
|
+
* });
|
|
168
|
+
*
|
|
169
|
+
* await ManualAuditLogService.commitTransaction(txId);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
81
172
|
static beginTransaction(userId, username) {
|
|
82
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
174
|
if (!ManualAuditLogService_1.instance) {
|
|
@@ -86,6 +177,9 @@ let ManualAuditLogService = ManualAuditLogService_1 = class ManualAuditLogServic
|
|
|
86
177
|
return ManualAuditLogService_1.instance.createTransaction(userId, username);
|
|
87
178
|
});
|
|
88
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* 静态方法:提交事务
|
|
182
|
+
*/
|
|
89
183
|
static commitTransaction(transactionId) {
|
|
90
184
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
185
|
if (!ManualAuditLogService_1.instance) {
|
|
@@ -94,6 +188,9 @@ let ManualAuditLogService = ManualAuditLogService_1 = class ManualAuditLogServic
|
|
|
94
188
|
yield ManualAuditLogService_1.instance.updateTransactionStatus(transactionId, enums_1.TransactionStatus.COMMITTED);
|
|
95
189
|
});
|
|
96
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* 静态方法:回滚事务
|
|
193
|
+
*/
|
|
97
194
|
static rollbackTransaction(transactionId) {
|
|
98
195
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
196
|
if (!ManualAuditLogService_1.instance) {
|
|
@@ -102,6 +199,9 @@ let ManualAuditLogService = ManualAuditLogService_1 = class ManualAuditLogServic
|
|
|
102
199
|
yield ManualAuditLogService_1.instance.updateTransactionStatus(transactionId, enums_1.TransactionStatus.ROLLED_BACK);
|
|
103
200
|
});
|
|
104
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* 创建事务
|
|
204
|
+
*/
|
|
105
205
|
createTransaction(userId, username) {
|
|
106
206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
207
|
const context = yield this.contextService.getCurrentContext();
|
|
@@ -117,19 +217,53 @@ let ManualAuditLogService = ManualAuditLogService_1 = class ManualAuditLogServic
|
|
|
117
217
|
return saved.id;
|
|
118
218
|
});
|
|
119
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* 更新事务状态
|
|
222
|
+
*/
|
|
120
223
|
updateTransactionStatus(transactionId, status) {
|
|
121
224
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
225
|
yield this.transactionRepository.update({ id: transactionId }, { status });
|
|
123
226
|
});
|
|
124
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* 生成事务ID
|
|
230
|
+
*/
|
|
125
231
|
generateTransactionId() {
|
|
126
232
|
return `txn-${Date.now()}-${(0, crypto_1.randomBytes)(8).toString('hex')}`;
|
|
127
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* 批量记录操作日志
|
|
236
|
+
*
|
|
237
|
+
* @description
|
|
238
|
+
* 批量记录多个操作,支持所有三种记录模式
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* // 混合使用多种模式
|
|
243
|
+
* await ManualAuditLogService.logBatch([
|
|
244
|
+
* {
|
|
245
|
+
* templateKey: 'product.update',
|
|
246
|
+
* descriptionParams: { productId: 'p1', field: 'price' },
|
|
247
|
+
* },
|
|
248
|
+
* {
|
|
249
|
+
* description: '批量更新库存',
|
|
250
|
+
* },
|
|
251
|
+
* {
|
|
252
|
+
* descriptionTemplate: {
|
|
253
|
+
* zh: '更新产品 {productId} 的 {field}',
|
|
254
|
+
* en: 'Update {field} of product {productId}',
|
|
255
|
+
* },
|
|
256
|
+
* descriptionParams: { productId: 'p3', field: 'stock' },
|
|
257
|
+
* },
|
|
258
|
+
* ]);
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
128
261
|
static logBatch(operations, sharedTransactionId) {
|
|
129
262
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
263
|
if (!ManualAuditLogService_1.instance) {
|
|
131
264
|
throw new Error('ManualAuditLogService is not initialized');
|
|
132
265
|
}
|
|
266
|
+
// 创建共享事务ID
|
|
133
267
|
const transactionId = sharedTransactionId ||
|
|
134
268
|
(yield ManualAuditLogService_1.instance.createTransaction());
|
|
135
269
|
const results = [];
|
|
@@ -137,12 +271,16 @@ let ManualAuditLogService = ManualAuditLogService_1 = class ManualAuditLogServic
|
|
|
137
271
|
const result = yield ManualAuditLogService_1.instance.logOperation(Object.assign(Object.assign({}, operation), { transactionId, autoCreateTransaction: false }));
|
|
138
272
|
results.push(result);
|
|
139
273
|
}
|
|
274
|
+
// 自动提交事务(如果是自动创建的)
|
|
140
275
|
if (!sharedTransactionId) {
|
|
141
276
|
yield ManualAuditLogService_1.instance.updateTransactionStatus(transactionId, enums_1.TransactionStatus.COMMITTED);
|
|
142
277
|
}
|
|
143
278
|
return results;
|
|
144
279
|
});
|
|
145
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* 查询操作日志
|
|
283
|
+
*/
|
|
146
284
|
static findLogs(options) {
|
|
147
285
|
return __awaiter(this, void 0, void 0, function* () {
|
|
148
286
|
if (!ManualAuditLogService_1.instance) {
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { DataSource } from 'typeorm';
|
|
2
2
|
import { ModuleRef } from '@nestjs/core';
|
|
3
|
+
/**
|
|
4
|
+
* 多数据库连接管理服务
|
|
5
|
+
*/
|
|
3
6
|
export declare class MultiDatabaseService {
|
|
4
7
|
private readonly moduleRef;
|
|
5
8
|
private readonly config?;
|
|
6
9
|
constructor(moduleRef: ModuleRef, config?: any);
|
|
10
|
+
/**
|
|
11
|
+
* 获取指定连接的 DataSource
|
|
12
|
+
*/
|
|
7
13
|
getDataSource(connectionName?: string): Promise<DataSource>;
|
|
14
|
+
/**
|
|
15
|
+
* 获取所有监听的数据库连接
|
|
16
|
+
*/
|
|
8
17
|
getMonitoredConnections(): string[];
|
|
18
|
+
/**
|
|
19
|
+
* 获取审计日志存储的数据库连接
|
|
20
|
+
*/
|
|
9
21
|
getAuditConnection(): string;
|
|
10
22
|
}
|
|
@@ -25,11 +25,17 @@ exports.MultiDatabaseService = void 0;
|
|
|
25
25
|
const common_1 = require("@nestjs/common");
|
|
26
26
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
27
27
|
const core_1 = require("@nestjs/core");
|
|
28
|
+
/**
|
|
29
|
+
* 多数据库连接管理服务
|
|
30
|
+
*/
|
|
28
31
|
let MultiDatabaseService = class MultiDatabaseService {
|
|
29
32
|
constructor(moduleRef, config) {
|
|
30
33
|
this.moduleRef = moduleRef;
|
|
31
34
|
this.config = config;
|
|
32
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* 获取指定连接的 DataSource
|
|
38
|
+
*/
|
|
33
39
|
getDataSource() {
|
|
34
40
|
return __awaiter(this, arguments, void 0, function* (connectionName = 'default') {
|
|
35
41
|
try {
|
|
@@ -41,10 +47,16 @@ let MultiDatabaseService = class MultiDatabaseService {
|
|
|
41
47
|
}
|
|
42
48
|
});
|
|
43
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* 获取所有监听的数据库连接
|
|
52
|
+
*/
|
|
44
53
|
getMonitoredConnections() {
|
|
45
54
|
var _a, _b;
|
|
46
55
|
return ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.connections) === null || _b === void 0 ? void 0 : _b.monitored) || ['default'];
|
|
47
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* 获取审计日志存储的数据库连接
|
|
59
|
+
*/
|
|
48
60
|
getAuditConnection() {
|
|
49
61
|
var _a, _b;
|
|
50
62
|
return ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.connections) === null || _b === void 0 ? void 0 : _b.audit) || 'default';
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Repository } from 'typeorm';
|
|
2
2
|
import { OperationTemplateEntity, EntityTransactionEntity, EntityAuditLogEntity, ManualOperationLogEntity } from '../entities';
|
|
3
3
|
import { ChangeDetail, TransactionDescription } from '../interfaces';
|
|
4
|
+
/**
|
|
5
|
+
* 操作描述服务
|
|
6
|
+
* 负责根据模板和参数动态生成多语言描述
|
|
7
|
+
*/
|
|
4
8
|
export declare class OperationDescriptionService {
|
|
5
9
|
private readonly templateRepository;
|
|
6
10
|
private readonly transactionRepository;
|
|
@@ -8,14 +12,69 @@ export declare class OperationDescriptionService {
|
|
|
8
12
|
private readonly manualOperationRepository;
|
|
9
13
|
private templateCache;
|
|
10
14
|
constructor(templateRepository: Repository<OperationTemplateEntity>, transactionRepository: Repository<EntityTransactionEntity>, auditLogRepository: Repository<EntityAuditLogEntity>, manualOperationRepository: Repository<ManualOperationLogEntity>);
|
|
15
|
+
/**
|
|
16
|
+
* 动态生成操作名称
|
|
17
|
+
* @param templateKey 模板键
|
|
18
|
+
* @param language 语言
|
|
19
|
+
* @returns 操作名称
|
|
20
|
+
*/
|
|
11
21
|
generateOperationName(templateKey: string, language?: string): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* 动态生成操作描述
|
|
24
|
+
* @param templateKey 模板键
|
|
25
|
+
* @param descriptionParams 描述参数
|
|
26
|
+
* @param language 语言
|
|
27
|
+
* @returns 描述文本
|
|
28
|
+
*/
|
|
12
29
|
generateDescription(templateKey: string, descriptionParams: Record<string, any>, language?: string): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* 动态生成变更详情
|
|
32
|
+
* @param changeDetails 变更详情列表
|
|
33
|
+
* @param language 语言
|
|
34
|
+
* @returns 格式化的变更详情
|
|
35
|
+
*/
|
|
13
36
|
generateChangeDetails(changeDetails: ChangeDetail[], language?: string): Promise<any[]>;
|
|
37
|
+
/**
|
|
38
|
+
* 获取事务描述(包含所有变更)
|
|
39
|
+
* @param transactionId 事务ID
|
|
40
|
+
* @param language 语言
|
|
41
|
+
* @returns 事务描述对象
|
|
42
|
+
*/
|
|
14
43
|
getTransactionDescription(transactionId: string, language?: string): Promise<TransactionDescription>;
|
|
44
|
+
/**
|
|
45
|
+
* 批量获取事务描述
|
|
46
|
+
* @param transactionIds 事务ID列表
|
|
47
|
+
* @param language 语言
|
|
48
|
+
* @returns 事务描述映射
|
|
49
|
+
*/
|
|
15
50
|
batchGetTransactionDescriptions(transactionIds: string[], language?: string): Promise<Record<string, TransactionDescription>>;
|
|
51
|
+
/**
|
|
52
|
+
* 填充模板
|
|
53
|
+
* @param template 模板字符串
|
|
54
|
+
* @param params 参数
|
|
55
|
+
* @returns 填充后的字符串
|
|
56
|
+
*/
|
|
16
57
|
private fillTemplate;
|
|
58
|
+
/**
|
|
59
|
+
* 格式化显示值
|
|
60
|
+
* @param value 原始值
|
|
61
|
+
* @param displayValue 显示值
|
|
62
|
+
* @returns 格式化后的值
|
|
63
|
+
*/
|
|
17
64
|
private formatDisplayValue;
|
|
65
|
+
/**
|
|
66
|
+
* 获取操作模板(带缓存)
|
|
67
|
+
* @param templateKey 模板键
|
|
68
|
+
* @returns 操作模板
|
|
69
|
+
*/
|
|
18
70
|
private getOperationTemplate;
|
|
71
|
+
/**
|
|
72
|
+
* 清除模板缓存
|
|
73
|
+
*/
|
|
19
74
|
clearTemplateCache(): void;
|
|
75
|
+
/**
|
|
76
|
+
* 预加载模板到缓存
|
|
77
|
+
* @param templateKeys 模板键列表
|
|
78
|
+
*/
|
|
20
79
|
preloadTemplates(templateKeys: string[]): Promise<void>;
|
|
21
80
|
}
|