@nest-omni/core 4.1.3-10 → 4.1.3-12

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.
Files changed (183) hide show
  1. package/audit/audit.module.js +42 -2
  2. package/audit/controllers/audit.controller.d.ts +64 -0
  3. package/audit/controllers/audit.controller.js +50 -0
  4. package/audit/decorators/audit-action.decorator.d.ts +74 -0
  5. package/audit/decorators/audit-action.decorator.js +42 -0
  6. package/audit/decorators/audit-controller.decorator.d.ts +1 -1
  7. package/audit/decorators/audit-controller.decorator.js +2 -2
  8. package/audit/decorators/entity-audit.decorator.d.ts +78 -2
  9. package/audit/decorators/entity-audit.decorator.js +145 -4
  10. package/audit/decorators/index.d.ts +2 -0
  11. package/audit/decorators/index.js +2 -0
  12. package/audit/entities/audit-action-summary.entity.d.ts +23 -0
  13. package/audit/entities/audit-action-summary.entity.js +101 -0
  14. package/audit/entities/entity-audit-log.entity.d.ts +8 -0
  15. package/audit/entities/entity-audit-log.entity.js +54 -2
  16. package/audit/entities/entity-transaction.entity.d.ts +8 -2
  17. package/audit/entities/entity-transaction.entity.js +39 -3
  18. package/audit/entities/index.d.ts +3 -0
  19. package/audit/entities/index.js +3 -0
  20. package/audit/entities/manual-operation-log.entity.js +8 -1
  21. package/audit/enums/audit.enums.d.ts +22 -6
  22. package/audit/enums/audit.enums.js +27 -9
  23. package/audit/index.d.ts +4 -1
  24. package/audit/index.js +25 -2
  25. package/audit/interceptors/audit-action.interceptor.d.ts +38 -0
  26. package/audit/interceptors/audit-action.interceptor.js +215 -0
  27. package/audit/interceptors/index.d.ts +1 -0
  28. package/audit/interceptors/index.js +1 -0
  29. package/audit/interfaces/audit.interfaces.d.ts +145 -2
  30. package/audit/services/audit-action.service.d.ts +141 -0
  31. package/audit/services/audit-action.service.js +244 -0
  32. package/audit/services/audit-context.service.d.ts +82 -0
  33. package/audit/services/audit-context.service.js +170 -0
  34. package/audit/services/entity-audit.service.d.ts +174 -4
  35. package/audit/services/entity-audit.service.js +515 -14
  36. package/audit/services/index.d.ts +3 -0
  37. package/audit/services/index.js +3 -0
  38. package/audit/services/manual-audit-log.service.d.ts +24 -23
  39. package/audit/services/manual-audit-log.service.js +32 -53
  40. package/audit/services/operation-description.service.d.ts +13 -3
  41. package/audit/services/operation-description.service.js +161 -24
  42. package/audit/services/transaction-audit.service.js +3 -3
  43. package/audit/subscribers/entity-audit.subscriber.d.ts +4 -0
  44. package/audit/subscribers/entity-audit.subscriber.js +47 -0
  45. package/file-upload/controllers/file-access.controller.d.ts +23 -0
  46. package/file-upload/controllers/file-access.controller.js +128 -0
  47. package/file-upload/decorators/csv-data.decorator.d.ts +44 -0
  48. package/file-upload/decorators/csv-data.decorator.js +131 -0
  49. package/file-upload/decorators/excel-data.decorator.d.ts +44 -0
  50. package/file-upload/decorators/excel-data.decorator.js +125 -0
  51. package/file-upload/decorators/file-upload.decorator.d.ts +83 -0
  52. package/file-upload/decorators/file-upload.decorator.js +172 -0
  53. package/file-upload/decorators/index.d.ts +4 -0
  54. package/file-upload/decorators/index.js +20 -0
  55. package/file-upload/decorators/process.decorator.d.ts +40 -0
  56. package/file-upload/decorators/process.decorator.js +52 -0
  57. package/file-upload/dto/create-file.dto.d.ts +24 -0
  58. package/file-upload/dto/create-file.dto.js +112 -0
  59. package/file-upload/dto/find-files.dto.d.ts +15 -0
  60. package/file-upload/dto/find-files.dto.js +76 -0
  61. package/file-upload/dto/index.d.ts +4 -0
  62. package/file-upload/dto/index.js +20 -0
  63. package/file-upload/dto/pagination.dto.d.ts +7 -0
  64. package/file-upload/dto/pagination.dto.js +39 -0
  65. package/file-upload/dto/update-file.dto.d.ts +16 -0
  66. package/file-upload/dto/update-file.dto.js +71 -0
  67. package/file-upload/entities/file-metadata.entity.d.ts +22 -0
  68. package/file-upload/entities/file-metadata.entity.js +84 -0
  69. package/file-upload/entities/file.entity.d.ts +129 -0
  70. package/file-upload/entities/file.entity.js +384 -0
  71. package/file-upload/entities/index.d.ts +2 -0
  72. package/file-upload/entities/index.js +18 -0
  73. package/file-upload/enums/file-type.enum.d.ts +72 -0
  74. package/file-upload/enums/file-type.enum.js +212 -0
  75. package/file-upload/exceptions/file-upload.exception.d.ts +57 -0
  76. package/file-upload/exceptions/file-upload.exception.js +120 -0
  77. package/file-upload/exceptions/index.d.ts +1 -0
  78. package/file-upload/exceptions/index.js +17 -0
  79. package/file-upload/file-upload.module.d.ts +89 -0
  80. package/file-upload/file-upload.module.js +264 -0
  81. package/file-upload/index.d.ts +26 -0
  82. package/file-upload/index.js +59 -0
  83. package/file-upload/interceptors/file-upload.interceptor.d.ts +48 -0
  84. package/file-upload/interceptors/file-upload.interceptor.js +434 -0
  85. package/file-upload/interceptors/index.d.ts +1 -0
  86. package/file-upload/interceptors/index.js +17 -0
  87. package/file-upload/interfaces/custom-file-type.interface.d.ts +72 -0
  88. package/file-upload/interfaces/custom-file-type.interface.js +2 -0
  89. package/file-upload/interfaces/file-buffer.interface.d.ts +72 -0
  90. package/file-upload/interfaces/file-buffer.interface.js +2 -0
  91. package/file-upload/interfaces/file-entity.interface.d.ts +142 -0
  92. package/file-upload/interfaces/file-entity.interface.js +28 -0
  93. package/file-upload/interfaces/file-metadata.interface.d.ts +21 -0
  94. package/file-upload/interfaces/file-metadata.interface.js +2 -0
  95. package/file-upload/interfaces/file-upload-options.interface.d.ts +117 -0
  96. package/file-upload/interfaces/file-upload-options.interface.js +2 -0
  97. package/file-upload/interfaces/index.d.ts +7 -0
  98. package/file-upload/interfaces/index.js +24 -0
  99. package/file-upload/interfaces/storage-provider.interface.d.ts +239 -0
  100. package/file-upload/interfaces/storage-provider.interface.js +2 -0
  101. package/file-upload/interfaces/upload-options.interface.d.ts +19 -0
  102. package/file-upload/interfaces/upload-options.interface.js +2 -0
  103. package/file-upload/providers/index.d.ts +2 -0
  104. package/file-upload/providers/index.js +18 -0
  105. package/file-upload/providers/local-storage.provider.d.ts +98 -0
  106. package/file-upload/providers/local-storage.provider.js +484 -0
  107. package/file-upload/providers/s3-storage.provider.d.ts +87 -0
  108. package/file-upload/providers/s3-storage.provider.js +455 -0
  109. package/file-upload/services/file-signature-validator.service.d.ts +118 -0
  110. package/file-upload/services/file-signature-validator.service.js +376 -0
  111. package/file-upload/services/file.service.d.ts +190 -0
  112. package/file-upload/services/file.service.js +609 -0
  113. package/file-upload/services/index.d.ts +4 -0
  114. package/file-upload/services/index.js +20 -0
  115. package/file-upload/services/malicious-file-detector.service.d.ts +274 -0
  116. package/file-upload/services/malicious-file-detector.service.js +1035 -0
  117. package/file-upload/services/mime-registry.service.d.ts +47 -0
  118. package/file-upload/services/mime-registry.service.js +167 -0
  119. package/file-upload/utils/checksum.util.d.ts +28 -0
  120. package/file-upload/utils/checksum.util.js +65 -0
  121. package/file-upload/utils/dynamic-import.util.d.ts +50 -0
  122. package/file-upload/utils/dynamic-import.util.js +144 -0
  123. package/file-upload/utils/filename.util.d.ts +59 -0
  124. package/file-upload/utils/filename.util.js +184 -0
  125. package/file-upload/utils/filepath.util.d.ts +70 -0
  126. package/file-upload/utils/filepath.util.js +152 -0
  127. package/file-upload/utils/index.d.ts +4 -0
  128. package/file-upload/utils/index.js +20 -0
  129. package/http-client/http-client.module.js +1 -5
  130. package/index.d.ts +3 -1
  131. package/index.js +4 -1
  132. package/package.json +4 -5
  133. package/redis-lock/lock-heartbeat.service.d.ts +2 -2
  134. package/redis-lock/lock-heartbeat.service.js +4 -4
  135. package/redis-lock/redis-lock.service.d.ts +18 -0
  136. package/redis-lock/redis-lock.service.js +38 -8
  137. package/setup/bootstrap.setup.d.ts +1 -0
  138. package/setup/bootstrap.setup.js +1 -0
  139. package/setup/schedule.decorator.js +18 -8
  140. package/shared/index.d.ts +1 -1
  141. package/shared/index.js +1 -1
  142. package/shared/{serviceRegistryModule.js → service-registry.module.js} +9 -16
  143. package/shared/services/index.d.ts +0 -1
  144. package/shared/services/index.js +0 -1
  145. package/transaction/__tests__/mocks.d.ts +9 -0
  146. package/transaction/__tests__/mocks.js +33 -0
  147. package/transaction/base-service-transaction.d.ts +99 -0
  148. package/transaction/base-service-transaction.js +286 -0
  149. package/transaction/cls-compatibility.service.d.ts +55 -0
  150. package/transaction/cls-compatibility.service.js +127 -0
  151. package/transaction/data-source-registry.d.ts +91 -0
  152. package/transaction/data-source-registry.js +349 -0
  153. package/transaction/database-adapter.d.ts +44 -0
  154. package/transaction/database-adapter.js +240 -0
  155. package/transaction/decorators/entity-datasource.decorator.d.ts +62 -0
  156. package/transaction/decorators/entity-datasource.decorator.js +105 -0
  157. package/transaction/index.d.ts +14 -0
  158. package/transaction/index.js +57 -0
  159. package/transaction/logging-transactional.interceptor.d.ts +18 -0
  160. package/transaction/logging-transactional.interceptor.js +163 -0
  161. package/transaction/transaction-context.service.d.ts +137 -0
  162. package/transaction/transaction-context.service.js +411 -0
  163. package/transaction/transaction-manager.d.ts +230 -0
  164. package/transaction/transaction-manager.js +1001 -0
  165. package/transaction/transaction-synchronization.d.ts +171 -0
  166. package/transaction/transaction-synchronization.js +380 -0
  167. package/transaction/transaction.errors.d.ts +91 -0
  168. package/transaction/transaction.errors.js +206 -0
  169. package/transaction/transaction.module.d.ts +30 -0
  170. package/transaction/transaction.module.js +98 -0
  171. package/transaction/transactional.decorator.d.ts +82 -0
  172. package/transaction/transactional.decorator.js +319 -0
  173. package/transaction/typeorm-module-wrapper.d.ts +96 -0
  174. package/transaction/typeorm-module-wrapper.js +197 -0
  175. package/validators/file-mimetype.validator.d.ts +0 -2
  176. package/validators/file-mimetype.validator.js +4 -6
  177. package/validators/is-exists.validator.d.ts +2 -5
  178. package/validators/is-exists.validator.js +4 -6
  179. package/validators/is-unique.validator.d.ts +2 -5
  180. package/validators/is-unique.validator.js +6 -11
  181. package/shared/services/validator.service.d.ts +0 -3
  182. package/shared/services/validator.service.js +0 -20
  183. /package/shared/{serviceRegistryModule.d.ts → service-registry.module.d.ts} +0 -0
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AuditActionSummaryEntity = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const abstract_entity_1 = require("../../common/abstract.entity");
15
+ /**
16
+ * 审计动作汇总实体
17
+ * 记录一次 API 调用的审计摘要信息
18
+ */
19
+ let AuditActionSummaryEntity = class AuditActionSummaryEntity extends abstract_entity_1.AbstractUuidPrimaryEntity {
20
+ };
21
+ exports.AuditActionSummaryEntity = AuditActionSummaryEntity;
22
+ __decorate([
23
+ (0, typeorm_1.Column)({ comment: '操作名称,如 createOrder, cancelOrder' }),
24
+ __metadata("design:type", String)
25
+ ], AuditActionSummaryEntity.prototype, "actionName", void 0);
26
+ __decorate([
27
+ (0, typeorm_1.Column)({ nullable: true, comment: '操作模板键,用于多语言支持' }),
28
+ __metadata("design:type", String)
29
+ ], AuditActionSummaryEntity.prototype, "operationTemplateKey", void 0);
30
+ __decorate([
31
+ (0, typeorm_1.Column)({ type: 'json', nullable: true, comment: '描述参数,用于填充模板' }),
32
+ __metadata("design:type", Object)
33
+ ], AuditActionSummaryEntity.prototype, "descriptionParams", void 0);
34
+ __decorate([
35
+ (0, typeorm_1.Column)({ type: 'text', nullable: true, comment: '操作描述文本(根据模板生成)' }),
36
+ __metadata("design:type", String)
37
+ ], AuditActionSummaryEntity.prototype, "description", void 0);
38
+ __decorate([
39
+ (0, typeorm_1.Column)({ comment: '请求ID' }),
40
+ __metadata("design:type", String)
41
+ ], AuditActionSummaryEntity.prototype, "requestId", void 0);
42
+ __decorate([
43
+ (0, typeorm_1.Column)({ nullable: true, comment: '用户ID' }),
44
+ __metadata("design:type", String)
45
+ ], AuditActionSummaryEntity.prototype, "userId", void 0);
46
+ __decorate([
47
+ (0, typeorm_1.Column)({ nullable: true, comment: '用户名' }),
48
+ __metadata("design:type", String)
49
+ ], AuditActionSummaryEntity.prototype, "username", void 0);
50
+ __decorate([
51
+ (0, typeorm_1.Column)({ nullable: true, comment: '请求IP' }),
52
+ __metadata("design:type", String)
53
+ ], AuditActionSummaryEntity.prototype, "requestIp", void 0);
54
+ __decorate([
55
+ (0, typeorm_1.Column)({ type: 'text', nullable: true, comment: '用户代理' }),
56
+ __metadata("design:type", String)
57
+ ], AuditActionSummaryEntity.prototype, "userAgent", void 0);
58
+ __decorate([
59
+ (0, typeorm_1.Column)({ type: 'int', default: 0, comment: '涉及的实体变更数量' }),
60
+ __metadata("design:type", Number)
61
+ ], AuditActionSummaryEntity.prototype, "entityChangesCount", void 0);
62
+ __decorate([
63
+ (0, typeorm_1.Column)({ type: 'json', nullable: true, comment: '涉及的实体类型列表' }),
64
+ __metadata("design:type", Array)
65
+ ], AuditActionSummaryEntity.prototype, "entityTypes", void 0);
66
+ __decorate([
67
+ (0, typeorm_1.Column)({ type: 'json', nullable: true, comment: '操作统计: {CREATE: 3, UPDATE: 2}' }),
68
+ __metadata("design:type", Object)
69
+ ], AuditActionSummaryEntity.prototype, "operationStats", void 0);
70
+ __decorate([
71
+ (0, typeorm_1.Column)({ type: 'boolean', default: true, comment: '操作是否成功' }),
72
+ __metadata("design:type", Boolean)
73
+ ], AuditActionSummaryEntity.prototype, "success", void 0);
74
+ __decorate([
75
+ (0, typeorm_1.Column)({ type: 'text', nullable: true, comment: '错误信息(如果失败)' }),
76
+ __metadata("design:type", String)
77
+ ], AuditActionSummaryEntity.prototype, "errorMessage", void 0);
78
+ __decorate([
79
+ (0, typeorm_1.Column)({ type: 'int', default: 0, comment: '操作耗时(毫秒)' }),
80
+ __metadata("design:type", Number)
81
+ ], AuditActionSummaryEntity.prototype, "duration", void 0);
82
+ __decorate([
83
+ (0, typeorm_1.Column)({ type: 'json', nullable: true, comment: '扩展元数据' }),
84
+ __metadata("design:type", Object)
85
+ ], AuditActionSummaryEntity.prototype, "metadata", void 0);
86
+ exports.AuditActionSummaryEntity = AuditActionSummaryEntity = __decorate([
87
+ (0, typeorm_1.Entity)('audit_action_summary')
88
+ // 单字段索引
89
+ ,
90
+ (0, typeorm_1.Index)('idx_action_name', ['actionName']),
91
+ (0, typeorm_1.Index)('idx_request_id', ['requestId']),
92
+ (0, typeorm_1.Index)('idx_user', ['userId']),
93
+ (0, typeorm_1.Index)('idx_created_at', ['createdAt']),
94
+ (0, typeorm_1.Index)('idx_success', ['success'])
95
+ // 复合索引 - 优化常见查询
96
+ ,
97
+ (0, typeorm_1.Index)('idx_action_user', ['actionName', 'userId']),
98
+ (0, typeorm_1.Index)('idx_user_time', ['userId', 'createdAt']),
99
+ (0, typeorm_1.Index)('idx_success_time', ['success', 'createdAt']),
100
+ (0, typeorm_1.Index)('idx_action_success_time', ['actionName', 'success', 'createdAt'])
101
+ ], AuditActionSummaryEntity);
@@ -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,11 @@ export declare class EntityAuditLogEntity extends AbstractUuidPrimaryEntity {
18
19
  userAgent: string;
19
20
  description: string;
20
21
  hashChain: Record<string, any>;
22
+ auditActionId: string;
23
+ auditActionName: string;
24
+ sequenceInAction: number;
25
+ operationTemplateKey: string;
26
+ descriptionParams: Record<string, any>;
27
+ changeDetails: ChangeDetail[];
28
+ rollbackActions: RollbackAction[];
21
29
  }
@@ -75,10 +75,62 @@ __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: '审计动作ID,用于关联同一业务操作的多个实体变化' }),
80
+ __metadata("design:type", String)
81
+ ], EntityAuditLogEntity.prototype, "auditActionId", void 0);
82
+ __decorate([
83
+ (0, typeorm_1.Column)({ nullable: true, comment: '审计动作名称,如 createOrder、updateUser' }),
84
+ __metadata("design:type", String)
85
+ ], EntityAuditLogEntity.prototype, "auditActionName", void 0);
86
+ __decorate([
87
+ (0, typeorm_1.Column)({ type: 'int', default: 0, comment: '在审计动作内的序号' }),
88
+ __metadata("design:type", Number)
89
+ ], EntityAuditLogEntity.prototype, "sequenceInAction", void 0);
90
+ __decorate([
91
+ (0, typeorm_1.Column)({ nullable: true, comment: '操作模板键,用于动态生成描述' }),
92
+ __metadata("design:type", String)
93
+ ], EntityAuditLogEntity.prototype, "operationTemplateKey", void 0);
94
+ __decorate([
95
+ (0, typeorm_1.Column)({
96
+ type: 'json',
97
+ nullable: true,
98
+ comment: '描述参数,用于填充模板占位符',
99
+ }),
100
+ __metadata("design:type", Object)
101
+ ], EntityAuditLogEntity.prototype, "descriptionParams", void 0);
102
+ __decorate([
103
+ (0, typeorm_1.Column)({
104
+ type: 'json',
105
+ nullable: true,
106
+ comment: '结构化变更详情列表(包含多语言支持)',
107
+ }),
108
+ __metadata("design:type", Array)
109
+ ], EntityAuditLogEntity.prototype, "changeDetails", void 0);
110
+ __decorate([
111
+ (0, typeorm_1.Column)({
112
+ type: 'json',
113
+ nullable: true,
114
+ comment: '回滚操作列表',
115
+ }),
116
+ __metadata("design:type", Array)
117
+ ], EntityAuditLogEntity.prototype, "rollbackActions", void 0);
78
118
  exports.EntityAuditLogEntity = EntityAuditLogEntity = __decorate([
79
- (0, typeorm_1.Entity)('entity_audit_log'),
119
+ (0, typeorm_1.Entity)('entity_audit_log')
120
+ // 单字段索引
121
+ ,
80
122
  (0, typeorm_1.Index)('idx_entity_relation', ['entityType', 'entityId']),
81
123
  (0, typeorm_1.Index)('idx_operation', ['operation']),
82
124
  (0, typeorm_1.Index)('idx_user', ['userId']),
83
- (0, typeorm_1.Index)('idx_created_at', ['createdAt'])
125
+ (0, typeorm_1.Index)('idx_created_at', ['createdAt']),
126
+ (0, typeorm_1.Index)('idx_template_key', ['operationTemplateKey']),
127
+ (0, typeorm_1.Index)('idx_request_id', ['requestId']),
128
+ (0, typeorm_1.Index)('idx_audit_action', ['auditActionId'])
129
+ // 复合索引 - 优化常见查询
130
+ ,
131
+ (0, typeorm_1.Index)('idx_entity_operation', ['entityType', 'entityId', 'operation']),
132
+ (0, typeorm_1.Index)('idx_entity_time', ['entityType', 'entityId', 'createdAt']),
133
+ (0, typeorm_1.Index)('idx_user_time', ['userId', 'createdAt']),
134
+ (0, typeorm_1.Index)('idx_request_time', ['requestId', 'createdAt']),
135
+ (0, typeorm_1.Index)('idx_action_sequence', ['auditActionId', 'sequenceInAction'])
84
136
  ], EntityAuditLogEntity);
@@ -1,11 +1,11 @@
1
1
  import { AbstractUuidPrimaryEntity } from '../../common/abstract.entity';
2
- import { AuditOperation, TransactionStatus } from '../enums';
2
+ import { AuditOperation, AuditTransactionStatus } from '../enums';
3
3
  /**
4
4
  * 实体事务
5
5
  */
6
6
  export declare class EntityTransactionEntity extends AbstractUuidPrimaryEntity {
7
7
  description: string;
8
- status: TransactionStatus;
8
+ status: AuditTransactionStatus;
9
9
  entities: Array<{
10
10
  entityType: string;
11
11
  entityId: string;
@@ -14,4 +14,10 @@ export declare class EntityTransactionEntity extends AbstractUuidPrimaryEntity {
14
14
  userId: string;
15
15
  username: string;
16
16
  dependencyGraph: Record<string, any>;
17
+ operationTemplateKey: string;
18
+ descriptionParams: Record<string, any>;
19
+ requestIp: string;
20
+ metadata: Record<string, any>;
21
+ completedAt: Date;
22
+ manualOperations: any[];
17
23
  }
@@ -24,7 +24,7 @@ __decorate([
24
24
  __metadata("design:type", String)
25
25
  ], EntityTransactionEntity.prototype, "description", void 0);
26
26
  __decorate([
27
- (0, typeorm_1.Column)({ type: 'enum', enum: enums_1.TransactionStatus, comment: '事务状态' }),
27
+ (0, typeorm_1.Column)({ type: 'enum', enum: enums_1.AuditTransactionStatus, comment: '事务状态' }),
28
28
  __metadata("design:type", String)
29
29
  ], EntityTransactionEntity.prototype, "status", void 0);
30
30
  __decorate([
@@ -46,9 +46,45 @@ __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', 'transaction'),
75
+ __metadata("design:type", Array)
76
+ ], EntityTransactionEntity.prototype, "manualOperations", void 0);
49
77
  exports.EntityTransactionEntity = EntityTransactionEntity = __decorate([
50
- (0, typeorm_1.Entity)('entity_transaction'),
78
+ (0, typeorm_1.Entity)('entity_transaction')
79
+ // 单字段索引
80
+ ,
51
81
  (0, typeorm_1.Index)('idx_status', ['status']),
52
82
  (0, typeorm_1.Index)('idx_user', ['userId']),
53
- (0, typeorm_1.Index)('idx_created_at', ['createdAt'])
83
+ (0, typeorm_1.Index)('idx_created_at', ['createdAt']),
84
+ (0, typeorm_1.Index)('idx_template_key', ['operationTemplateKey'])
85
+ // 复合索引 - 优化常见查询
86
+ ,
87
+ (0, typeorm_1.Index)('idx_user_status', ['userId', 'status']),
88
+ (0, typeorm_1.Index)('idx_user_time', ['userId', 'createdAt']),
89
+ (0, typeorm_1.Index)('idx_status_time', ['status', 'createdAt'])
54
90
  ], EntityTransactionEntity);
@@ -1,2 +1,5 @@
1
1
  export * from './entity-audit-log.entity';
2
2
  export * from './entity-transaction.entity';
3
+ export * from './operation-template.entity';
4
+ export * from './manual-operation-log.entity';
5
+ export * from './audit-action-summary.entity';
@@ -16,3 +16,6 @@ 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);
21
+ __exportStar(require("./audit-action-summary.entity"), exports);
@@ -78,9 +78,16 @@ __decorate([
78
78
  __metadata("design:type", entity_transaction_entity_1.EntityTransactionEntity)
79
79
  ], ManualOperationLogEntity.prototype, "transaction", void 0);
80
80
  exports.ManualOperationLogEntity = ManualOperationLogEntity = __decorate([
81
- (0, typeorm_1.Entity)('manual_operation_log'),
81
+ (0, typeorm_1.Entity)('manual_operation_log')
82
+ // 单字段索引
83
+ ,
82
84
  (0, typeorm_1.Index)('idx_transaction', ['transactionId']),
83
85
  (0, typeorm_1.Index)('idx_template_key', ['operationTemplateKey']),
84
86
  (0, typeorm_1.Index)('idx_user', ['userId']),
85
87
  (0, typeorm_1.Index)('idx_created_at', ['createdAt'])
88
+ // 复合索引 - 优化常见查询
89
+ ,
90
+ (0, typeorm_1.Index)('idx_transaction_time', ['transactionId', 'createdAt']),
91
+ (0, typeorm_1.Index)('idx_user_time', ['userId', 'createdAt']),
92
+ (0, typeorm_1.Index)('idx_template_user', ['operationTemplateKey', 'userId'])
86
93
  ], ManualOperationLogEntity);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 审计操作类型
2
+ * 审计操作类型(兼容性别名,映射到 OperationType)
3
3
  */
4
4
  export declare enum AuditOperation {
5
5
  CREATE = "CREATE",
@@ -8,12 +8,12 @@ export declare enum AuditOperation {
8
8
  RESTORE = "RESTORE"
9
9
  }
10
10
  /**
11
- * 事务状态
11
+ * 事务状态(设计文档标准命名)
12
12
  */
13
- export declare enum TransactionStatus {
14
- PENDING = "PENDING",
15
- COMMITTED = "COMMITTED",
16
- ROLLED_BACK = "ROLLED_BACK"
13
+ export declare enum AuditTransactionStatus {
14
+ PENDING = "pending",
15
+ COMMITTED = "committed",
16
+ ROLLED_BACK = "rolled_back"
17
17
  }
18
18
  /**
19
19
  * 恢复策略
@@ -40,3 +40,19 @@ export declare enum MaskingStrategy {
40
40
  MASK = "MASK",
41
41
  PARTIAL = "PARTIAL"
42
42
  }
43
+ /**
44
+ * 回滚操作类型(设计文档标准命名)
45
+ */
46
+ export declare enum RollbackActionType {
47
+ ENTITY = "entity",// 实体回滚(删除/恢复)
48
+ FILE = "file",// 文件回滚(删除上传的文件)
49
+ CUSTOM = "custom"
50
+ }
51
+ /**
52
+ * 变更类型(设计文档标准命名)
53
+ */
54
+ export declare enum ChangeType {
55
+ ADDED = "added",// 新增字段
56
+ REMOVED = "removed",// 删除字段
57
+ MODIFIED = "modified"
58
+ }
@@ -1,8 +1,8 @@
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.AuditTransactionStatus = exports.AuditOperation = void 0;
4
4
  /**
5
- * 审计操作类型
5
+ * 审计操作类型(兼容性别名,映射到 OperationType)
6
6
  */
7
7
  var AuditOperation;
8
8
  (function (AuditOperation) {
@@ -12,14 +12,14 @@ var AuditOperation;
12
12
  AuditOperation["RESTORE"] = "RESTORE";
13
13
  })(AuditOperation || (exports.AuditOperation = AuditOperation = {}));
14
14
  /**
15
- * 事务状态
15
+ * 事务状态(设计文档标准命名)
16
16
  */
17
- var TransactionStatus;
18
- (function (TransactionStatus) {
19
- TransactionStatus["PENDING"] = "PENDING";
20
- TransactionStatus["COMMITTED"] = "COMMITTED";
21
- TransactionStatus["ROLLED_BACK"] = "ROLLED_BACK";
22
- })(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
17
+ var AuditTransactionStatus;
18
+ (function (AuditTransactionStatus) {
19
+ AuditTransactionStatus["PENDING"] = "pending";
20
+ AuditTransactionStatus["COMMITTED"] = "committed";
21
+ AuditTransactionStatus["ROLLED_BACK"] = "rolled_back";
22
+ })(AuditTransactionStatus || (exports.AuditTransactionStatus = AuditTransactionStatus = {}));
23
23
  /**
24
24
  * 恢复策略
25
25
  */
@@ -48,3 +48,21 @@ var MaskingStrategy;
48
48
  MaskingStrategy["MASK"] = "MASK";
49
49
  MaskingStrategy["PARTIAL"] = "PARTIAL";
50
50
  })(MaskingStrategy || (exports.MaskingStrategy = MaskingStrategy = {}));
51
+ /**
52
+ * 回滚操作类型(设计文档标准命名)
53
+ */
54
+ var RollbackActionType;
55
+ (function (RollbackActionType) {
56
+ RollbackActionType["ENTITY"] = "entity";
57
+ RollbackActionType["FILE"] = "file";
58
+ RollbackActionType["CUSTOM"] = "custom";
59
+ })(RollbackActionType || (exports.RollbackActionType = RollbackActionType = {}));
60
+ /**
61
+ * 变更类型(设计文档标准命名)
62
+ */
63
+ var ChangeType;
64
+ (function (ChangeType) {
65
+ ChangeType["ADDED"] = "added";
66
+ ChangeType["REMOVED"] = "removed";
67
+ ChangeType["MODIFIED"] = "modified";
68
+ })(ChangeType || (exports.ChangeType = ChangeType = {}));
package/audit/index.d.ts CHANGED
@@ -2,7 +2,10 @@ export * from './entities';
2
2
  export * from './enums';
3
3
  export * from './interfaces';
4
4
  export * from './dto';
5
- export * from './decorators';
5
+ export { AuditEntity, AuditField, getEntityAuditConfig, getFieldAuditConfig, getFieldLabel, getFieldValueLabel, getEntityLabel, 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';
8
+ export { AuditAction, AuditActionOptions, AuditActionMetadata, AUDIT_ACTION_METADATA, } from './decorators/audit-action.decorator';
6
9
  export * from './services';
7
10
  export * from './subscribers';
8
11
  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_ACTION_METADATA = exports.AuditAction = 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.getEntityLabel = 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,30 @@ __exportStar(require("./enums"), exports);
22
23
  __exportStar(require("./interfaces"), exports);
23
24
  // DTO
24
25
  __exportStar(require("./dto"), exports);
25
- // Decorators
26
- __exportStar(require("./decorators"), exports);
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, "getEntityLabel", { enumerable: true, get: function () { return entity_audit_decorator_1.getEntityLabel; } });
35
+ Object.defineProperty(exports, "ENTITY_AUDIT_OPTIONS", { enumerable: true, get: function () { return entity_audit_decorator_1.ENTITY_AUDIT_OPTIONS; } });
36
+ Object.defineProperty(exports, "FIELD_AUDIT_OPTIONS", { enumerable: true, get: function () { return entity_audit_decorator_1.FIELD_AUDIT_OPTIONS; } });
37
+ var audit_controller_decorator_1 = require("./decorators/audit-controller.decorator");
38
+ Object.defineProperty(exports, "AuditController", { enumerable: true, get: function () { return audit_controller_decorator_1.AuditController; } });
39
+ Object.defineProperty(exports, "AuditMethod", { enumerable: true, get: function () { return audit_controller_decorator_1.AuditMethod; } });
40
+ Object.defineProperty(exports, "CONTROLLER_AUDIT_OPTIONS", { enumerable: true, get: function () { return audit_controller_decorator_1.CONTROLLER_AUDIT_OPTIONS; } });
41
+ Object.defineProperty(exports, "METHOD_AUDIT_OPTIONS", { enumerable: true, get: function () { return audit_controller_decorator_1.METHOD_AUDIT_OPTIONS; } });
42
+ var audit_operation_decorator_1 = require("./decorators/audit-operation.decorator");
43
+ Object.defineProperty(exports, "AuditLog", { enumerable: true, get: function () { return audit_operation_decorator_1.AuditLog; } });
44
+ Object.defineProperty(exports, "getAuditOperationConfig", { enumerable: true, get: function () { return audit_operation_decorator_1.getAuditOperationConfig; } });
45
+ Object.defineProperty(exports, "hasAuditOperation", { enumerable: true, get: function () { return audit_operation_decorator_1.hasAuditOperation; } });
46
+ Object.defineProperty(exports, "AUDIT_OPERATION_OPTIONS", { enumerable: true, get: function () { return audit_operation_decorator_1.AUDIT_OPERATION_OPTIONS; } });
47
+ var audit_action_decorator_1 = require("./decorators/audit-action.decorator");
48
+ Object.defineProperty(exports, "AuditAction", { enumerable: true, get: function () { return audit_action_decorator_1.AuditAction; } });
49
+ Object.defineProperty(exports, "AUDIT_ACTION_METADATA", { enumerable: true, get: function () { return audit_action_decorator_1.AUDIT_ACTION_METADATA; } });
27
50
  // Services
28
51
  __exportStar(require("./services"), exports);
29
52
  // Subscribers
@@ -0,0 +1,38 @@
1
+ import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
2
+ import { Reflector } from '@nestjs/core';
3
+ import { Observable } from 'rxjs';
4
+ import { Repository } from 'typeorm';
5
+ import { AuditContextService } from '../services/audit-context.service';
6
+ import { OperationDescriptionService } from '../services/operation-description.service';
7
+ import { AuditActionSummaryEntity } from '../entities';
8
+ /**
9
+ * 审计动作拦截器
10
+ * 在请求开始时创建审计动作上下文,在请求结束时生成汇总记录
11
+ */
12
+ export declare class AuditActionInterceptor implements NestInterceptor {
13
+ private readonly reflector;
14
+ private readonly contextService;
15
+ private readonly summaryRepository;
16
+ private readonly descriptionService?;
17
+ constructor(reflector: Reflector, contextService: AuditContextService, summaryRepository: Repository<AuditActionSummaryEntity>, descriptionService?: OperationDescriptionService);
18
+ intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
19
+ /**
20
+ * 生成审计汇总记录
21
+ */
22
+ private generateSummary;
23
+ /**
24
+ * 生成操作描述文本
25
+ * 优先从 OperationDescriptionService 获取多语言模板
26
+ * 如果没有,则使用默认格式
27
+ */
28
+ private generateDescription;
29
+ /**
30
+ * 替换模板中的占位符
31
+ * 支持格式:{key} 或 {key:format}
32
+ */
33
+ private replaceTemplatePlaceholders;
34
+ /**
35
+ * 格式化值为字符串
36
+ */
37
+ private formatValue;
38
+ }