@nest-omni/core 4.1.3-20 → 4.1.3-22

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 (98) hide show
  1. package/audit/audit.module.d.ts +1 -0
  2. package/audit/audit.module.js +5 -3
  3. package/audit/controllers/audit.controller.d.ts +3 -11
  4. package/audit/controllers/audit.controller.js +12 -19
  5. package/audit/decorators/audit-operation.decorator.d.ts +0 -7
  6. package/audit/decorators/audit-operation.decorator.js +0 -7
  7. package/audit/dto/audit-action-query.dto.d.ts +13 -0
  8. package/audit/dto/audit-action-query.dto.js +77 -0
  9. package/audit/dto/index.d.ts +1 -0
  10. package/audit/dto/index.js +1 -0
  11. package/audit/entities/entity-audit-log.entity.d.ts +1 -4
  12. package/audit/entities/entity-audit-log.entity.js +1 -17
  13. package/audit/entities/manual-operation-log.entity.d.ts +0 -2
  14. package/audit/entities/manual-operation-log.entity.js +0 -8
  15. package/audit/enums/audit.enums.d.ts +0 -8
  16. package/audit/enums/audit.enums.js +1 -10
  17. package/audit/examples/decorator-value-mapping.example.d.ts +70 -0
  18. package/audit/examples/decorator-value-mapping.example.js +414 -0
  19. package/audit/index.d.ts +1 -0
  20. package/audit/index.js +5 -1
  21. package/audit/interceptors/audit.interceptor.d.ts +1 -0
  22. package/audit/interceptors/audit.interceptor.js +19 -11
  23. package/audit/interfaces/audit.interfaces.d.ts +2 -17
  24. package/audit/services/audit-context.service.d.ts +9 -0
  25. package/audit/services/entity-audit.service.d.ts +65 -24
  26. package/audit/services/entity-audit.service.js +280 -93
  27. package/audit/services/manual-audit-log.service.d.ts +0 -1
  28. package/audit/services/manual-audit-log.service.js +1 -3
  29. package/audit/subscribers/entity-audit.subscriber.d.ts +1 -0
  30. package/audit/subscribers/entity-audit.subscriber.js +22 -5
  31. package/cache/cache.module.d.ts +7 -2
  32. package/cache/cache.module.js +9 -7
  33. package/cache/cache.service.d.ts +4 -4
  34. package/cache/cache.service.js +5 -5
  35. package/cache/entities/index.d.ts +1 -0
  36. package/cache/entities/index.js +17 -0
  37. package/cache/entities/typeorm-cache.entity.d.ts +71 -0
  38. package/cache/entities/typeorm-cache.entity.js +110 -0
  39. package/cache/index.d.ts +2 -1
  40. package/cache/index.js +19 -2
  41. package/cache/providers/index.d.ts +2 -1
  42. package/cache/providers/index.js +2 -1
  43. package/cache/providers/lrucache.provider.d.ts +76 -0
  44. package/cache/providers/lrucache.provider.js +226 -0
  45. package/cache/providers/typeorm-cache.provider.d.ts +211 -0
  46. package/cache/providers/typeorm-cache.provider.js +483 -0
  47. package/common/boilerplate.polyfill.d.ts +1 -0
  48. package/common/boilerplate.polyfill.js +17 -0
  49. package/common/helpers/validation-metadata-helper.d.ts +55 -0
  50. package/common/helpers/validation-metadata-helper.js +60 -0
  51. package/common/index.d.ts +1 -0
  52. package/common/index.js +4 -0
  53. package/decorators/field.decorators.d.ts +71 -2
  54. package/decorators/field.decorators.js +147 -18
  55. package/decorators/transform.decorators.d.ts +0 -2
  56. package/decorators/transform.decorators.js +0 -23
  57. package/filters/bad-request.filter.js +19 -4
  58. package/http-client/utils/context-extractor.util.js +2 -0
  59. package/ip-filter/constants.d.ts +21 -0
  60. package/ip-filter/constants.js +24 -0
  61. package/ip-filter/decorators/index.d.ts +1 -0
  62. package/ip-filter/decorators/index.js +17 -0
  63. package/ip-filter/decorators/ip-filter.decorator.d.ts +58 -0
  64. package/ip-filter/decorators/ip-filter.decorator.js +79 -0
  65. package/ip-filter/guards/index.d.ts +1 -0
  66. package/ip-filter/guards/index.js +17 -0
  67. package/ip-filter/guards/ip-filter.guard.d.ts +62 -0
  68. package/ip-filter/guards/ip-filter.guard.js +174 -0
  69. package/ip-filter/index.d.ts +7 -0
  70. package/ip-filter/index.js +23 -0
  71. package/ip-filter/interfaces/index.d.ts +4 -0
  72. package/ip-filter/interfaces/index.js +20 -0
  73. package/ip-filter/interfaces/ip-filter-async-options.interface.d.ts +15 -0
  74. package/ip-filter/interfaces/ip-filter-async-options.interface.js +2 -0
  75. package/ip-filter/interfaces/ip-filter-metadata.interface.d.ts +26 -0
  76. package/ip-filter/interfaces/ip-filter-metadata.interface.js +2 -0
  77. package/ip-filter/interfaces/ip-filter-options.interface.d.ts +34 -0
  78. package/ip-filter/interfaces/ip-filter-options.interface.js +2 -0
  79. package/ip-filter/interfaces/ip-rule.interface.d.ts +36 -0
  80. package/ip-filter/interfaces/ip-rule.interface.js +2 -0
  81. package/ip-filter/ip-filter.module.d.ts +55 -0
  82. package/ip-filter/ip-filter.module.js +105 -0
  83. package/ip-filter/services/index.d.ts +1 -0
  84. package/ip-filter/services/index.js +17 -0
  85. package/ip-filter/services/ip-filter.service.d.ts +92 -0
  86. package/ip-filter/services/ip-filter.service.js +238 -0
  87. package/ip-filter/utils/index.d.ts +1 -0
  88. package/ip-filter/utils/index.js +17 -0
  89. package/ip-filter/utils/ip-utils.d.ts +61 -0
  90. package/ip-filter/utils/ip-utils.js +162 -0
  91. package/package.json +23 -24
  92. package/providers/context.provider.d.ts +9 -0
  93. package/providers/context.provider.js +13 -0
  94. package/setup/bootstrap.setup.d.ts +1 -1
  95. package/setup/bootstrap.setup.js +1 -1
  96. package/shared/service-registry.module.js +0 -1
  97. package/cache/providers/memory-cache.provider.d.ts +0 -69
  98. package/cache/providers/memory-cache.provider.js +0 -237
@@ -0,0 +1,414 @@
1
+ "use strict";
2
+ /**
3
+ * 装饰器值映射完整示例
4
+ *
5
+ * 本示例演示如何使用 @AuditField 装饰器的 valueLabels 功能
6
+ * 实现字段值的多语言显示和映射
7
+ */
8
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
9
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
11
+ 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;
12
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
13
+ };
14
+ var __metadata = (this && this.__metadata) || function (k, v) {
15
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.InventoryEntity = exports.UserEntity = exports.OrderEntity = exports.ProductEntity = void 0;
19
+ const typeorm_1 = require("typeorm");
20
+ const entity_audit_decorator_1 = require("../decorators/entity-audit.decorator");
21
+ // ============================================
22
+ // 示例 1: 电商产品实体
23
+ // ============================================
24
+ let ProductEntity = class ProductEntity {
25
+ };
26
+ exports.ProductEntity = ProductEntity;
27
+ __decorate([
28
+ (0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
29
+ __metadata("design:type", String)
30
+ ], ProductEntity.prototype, "id", void 0);
31
+ __decorate([
32
+ (0, typeorm_1.Column)(),
33
+ (0, entity_audit_decorator_1.AuditField)({
34
+ label: { zh: '产品名称', en: 'Product Name' },
35
+ }),
36
+ __metadata("design:type", String)
37
+ ], ProductEntity.prototype, "name", void 0);
38
+ __decorate([
39
+ (0, typeorm_1.Column)({ type: 'decimal', precision: 10, scale: 2 }),
40
+ (0, entity_audit_decorator_1.AuditField)({
41
+ label: { zh: '价格', en: 'Price' },
42
+ formatter: (value) => `¥${parseFloat(value).toFixed(2)}`,
43
+ }),
44
+ __metadata("design:type", Number)
45
+ ], ProductEntity.prototype, "price", void 0);
46
+ __decorate([
47
+ (0, typeorm_1.Column)({ type: 'decimal', precision: 10, scale: 2 }),
48
+ (0, entity_audit_decorator_1.AuditField)({
49
+ label: { zh: '成本价', en: 'Cost Price' },
50
+ sensitive: true,
51
+ }),
52
+ __metadata("design:type", Number)
53
+ ], ProductEntity.prototype, "costPrice", void 0);
54
+ __decorate([
55
+ (0, typeorm_1.Column)({ default: 0 }),
56
+ (0, entity_audit_decorator_1.AuditField)({
57
+ label: { zh: '库存', en: 'Stock' },
58
+ formatter: (value) => `${value} 件`,
59
+ }),
60
+ __metadata("design:type", Number)
61
+ ], ProductEntity.prototype, "stock", void 0);
62
+ __decorate([
63
+ (0, typeorm_1.Column)({
64
+ type: 'enum',
65
+ enum: ['active', 'inactive', 'out_of_stock', 'discontinued'],
66
+ default: 'active',
67
+ }),
68
+ (0, entity_audit_decorator_1.AuditField)({
69
+ label: { zh: '状态', en: 'Status' },
70
+ valueLabels: {
71
+ active: { zh: '在售', en: 'Active', ja: '販売中' },
72
+ inactive: { zh: '停售', en: 'Inactive', ja: '販売停止' },
73
+ out_of_stock: { zh: '缺货', en: 'Out of Stock', ja: '在庫切れ' },
74
+ discontinued: { zh: '已停产', en: 'Discontinued', ja: '廃盤' },
75
+ },
76
+ }),
77
+ __metadata("design:type", String)
78
+ ], ProductEntity.prototype, "status", void 0);
79
+ __decorate([
80
+ (0, typeorm_1.Column)({ default: false }),
81
+ (0, entity_audit_decorator_1.AuditField)({
82
+ label: { zh: '是否推荐', en: 'Featured' },
83
+ valueLabels: {
84
+ true: { zh: '是', en: 'Yes', ja: 'はい' },
85
+ false: { zh: '否', en: 'No', ja: 'いいえ' },
86
+ },
87
+ }),
88
+ __metadata("design:type", Boolean)
89
+ ], ProductEntity.prototype, "isFeatured", void 0);
90
+ __decorate([
91
+ (0, typeorm_1.Column)({
92
+ type: 'enum',
93
+ enum: ['physical', 'digital', 'service'],
94
+ default: 'physical',
95
+ }),
96
+ (0, entity_audit_decorator_1.AuditField)({
97
+ label: { zh: '产品类型', en: 'Product Type' },
98
+ valueLabels: {
99
+ physical: { zh: '实物', en: 'Physical', ja: '物理商品' },
100
+ digital: { zh: '数字产品', en: 'Digital', ja: 'デジタル商品' },
101
+ service: { zh: '服务', en: 'Service', ja: 'サービス' },
102
+ },
103
+ }),
104
+ __metadata("design:type", String)
105
+ ], ProductEntity.prototype, "productType", void 0);
106
+ __decorate([
107
+ (0, typeorm_1.Column)({ nullable: true }),
108
+ __metadata("design:type", String)
109
+ ], ProductEntity.prototype, "internalNotes", void 0);
110
+ __decorate([
111
+ (0, typeorm_1.Column)({ nullable: true }),
112
+ __metadata("design:type", String)
113
+ ], ProductEntity.prototype, "supplierCode", void 0);
114
+ exports.ProductEntity = ProductEntity = __decorate([
115
+ (0, typeorm_1.Entity)('products'),
116
+ (0, entity_audit_decorator_1.AuditEntity)({
117
+ enabled: true,
118
+ excludeFields: ['internalNotes', 'supplierCode'],
119
+ maskFields: ['costPrice'],
120
+ })
121
+ ], ProductEntity);
122
+ // ============================================
123
+ // 示例 2: 订单实体
124
+ // ============================================
125
+ let OrderEntity = class OrderEntity {
126
+ };
127
+ exports.OrderEntity = OrderEntity;
128
+ __decorate([
129
+ (0, typeorm_1.Column)(),
130
+ (0, entity_audit_decorator_1.AuditField)({
131
+ label: { zh: '订单号', en: 'Order Number' },
132
+ }),
133
+ __metadata("design:type", String)
134
+ ], OrderEntity.prototype, "orderSn", void 0);
135
+ __decorate([
136
+ (0, typeorm_1.Column)({ type: 'decimal', precision: 10, scale: 2 }),
137
+ (0, entity_audit_decorator_1.AuditField)({
138
+ label: { zh: '订单金额', en: 'Order Amount' },
139
+ formatter: (value) => `¥${parseFloat(value).toFixed(2)}`,
140
+ }),
141
+ __metadata("design:type", Number)
142
+ ], OrderEntity.prototype, "totalAmount", void 0);
143
+ __decorate([
144
+ (0, typeorm_1.Column)({
145
+ type: 'enum',
146
+ enum: ['pending', 'confirmed', 'processing', 'shipped', 'delivered', 'cancelled', 'refunded'],
147
+ default: 'pending',
148
+ }),
149
+ (0, entity_audit_decorator_1.AuditField)({
150
+ label: { zh: '订单状态', en: 'Order Status' },
151
+ valueLabels: {
152
+ pending: { zh: '待确认', en: 'Pending', ja: '保留中' },
153
+ confirmed: { zh: '已确认', en: 'Confirmed', ja: '確認済み' },
154
+ processing: { zh: '处理中', en: 'Processing', ja: '処理中' },
155
+ shipped: { zh: '已发货', en: 'Shipped', ja: '発送済み' },
156
+ delivered: { zh: '已送达', en: 'Delivered', ja: '配達済み' },
157
+ cancelled: { zh: '已取消', en: 'Cancelled', ja: 'キャンセル済み' },
158
+ refunded: { zh: '已退款', en: 'Refunded', ja: '返金済み' },
159
+ },
160
+ }),
161
+ __metadata("design:type", String)
162
+ ], OrderEntity.prototype, "orderStatus", void 0);
163
+ __decorate([
164
+ (0, typeorm_1.Column)({
165
+ type: 'enum',
166
+ enum: ['unpaid', 'partial_paid', 'paid', 'refunded'],
167
+ default: 'unpaid',
168
+ }),
169
+ (0, entity_audit_decorator_1.AuditField)({
170
+ label: { zh: '支付状态', en: 'Payment Status' },
171
+ valueLabels: {
172
+ unpaid: { zh: '未支付', en: 'Unpaid', ja: '未払い' },
173
+ partial_paid: { zh: '部分支付', en: 'Partial Paid', ja: '一部支払い' },
174
+ paid: { zh: '已支付', en: 'Paid', ja: '支払い済み' },
175
+ refunded: { zh: '已退款', en: 'Refunded', ja: '返金済み' },
176
+ },
177
+ }),
178
+ __metadata("design:type", String)
179
+ ], OrderEntity.prototype, "paymentStatus", void 0);
180
+ __decorate([
181
+ (0, typeorm_1.Column)({
182
+ type: 'enum',
183
+ enum: ['standard', 'express', 'overnight', 'international'],
184
+ default: 'standard',
185
+ }),
186
+ (0, entity_audit_decorator_1.AuditField)({
187
+ label: { zh: '配送方式', en: 'Shipping Method' },
188
+ valueLabels: {
189
+ standard: { zh: '标准配送', en: 'Standard', ja: '標準配送' },
190
+ express: { zh: '加急配送', en: 'Express', ja: '急行配送' },
191
+ overnight: { zh: '次日达', en: 'Overnight', ja: '翌日配達' },
192
+ international: { zh: '国际配送', en: 'International', ja: '国際配送' },
193
+ },
194
+ }),
195
+ __metadata("design:type", String)
196
+ ], OrderEntity.prototype, "shippingMethod", void 0);
197
+ __decorate([
198
+ (0, typeorm_1.Column)(),
199
+ (0, entity_audit_decorator_1.AuditField)({
200
+ label: { zh: '客户电话', en: 'Customer Phone' },
201
+ sensitive: true,
202
+ }),
203
+ __metadata("design:type", String)
204
+ ], OrderEntity.prototype, "customerPhone", void 0);
205
+ __decorate([
206
+ (0, typeorm_1.Column)(),
207
+ (0, entity_audit_decorator_1.AuditField)({
208
+ label: { zh: '客户邮箱', en: 'Customer Email' },
209
+ sensitive: true,
210
+ }),
211
+ __metadata("design:type", String)
212
+ ], OrderEntity.prototype, "customerEmail", void 0);
213
+ exports.OrderEntity = OrderEntity = __decorate([
214
+ (0, typeorm_1.Entity)('orders'),
215
+ (0, entity_audit_decorator_1.AuditEntity)({
216
+ enabled: true,
217
+ maskFields: ['customerPhone', 'customerEmail'],
218
+ })
219
+ ], OrderEntity);
220
+ // ============================================
221
+ // 示例 3: 用户实体
222
+ // ============================================
223
+ let UserEntity = class UserEntity {
224
+ };
225
+ exports.UserEntity = UserEntity;
226
+ __decorate([
227
+ (0, typeorm_1.Column)({ unique: true }),
228
+ (0, entity_audit_decorator_1.AuditField)({
229
+ label: { zh: '用户名', en: 'Username' },
230
+ }),
231
+ __metadata("design:type", String)
232
+ ], UserEntity.prototype, "username", void 0);
233
+ __decorate([
234
+ (0, typeorm_1.Column)(),
235
+ (0, entity_audit_decorator_1.AuditField)({
236
+ label: { zh: '邮箱', en: 'Email' },
237
+ }),
238
+ __metadata("design:type", String)
239
+ ], UserEntity.prototype, "email", void 0);
240
+ __decorate([
241
+ (0, typeorm_1.Column)(),
242
+ (0, entity_audit_decorator_1.AuditField)({
243
+ label: { zh: '手机号', en: 'Phone' },
244
+ sensitive: true,
245
+ }),
246
+ __metadata("design:type", String)
247
+ ], UserEntity.prototype, "phone", void 0);
248
+ __decorate([
249
+ (0, typeorm_1.Column)({
250
+ type: 'enum',
251
+ enum: ['active', 'inactive', 'suspended', 'banned'],
252
+ default: 'inactive',
253
+ }),
254
+ (0, entity_audit_decorator_1.AuditField)({
255
+ label: { zh: '账号状态', en: 'Account Status' },
256
+ valueLabels: {
257
+ active: { zh: '正常', en: 'Active', ja: '有効' },
258
+ inactive: { zh: '未激活', en: 'Inactive', ja: '無効' },
259
+ suspended: { zh: '已暂停', en: 'Suspended', ja: '停止中' },
260
+ banned: { zh: '已封禁', en: 'Banned', ja: '禁止' },
261
+ },
262
+ }),
263
+ __metadata("design:type", String)
264
+ ], UserEntity.prototype, "status", void 0);
265
+ __decorate([
266
+ (0, typeorm_1.Column)({
267
+ type: 'enum',
268
+ enum: ['user', 'vip', 'admin', 'super_admin'],
269
+ default: 'user',
270
+ }),
271
+ (0, entity_audit_decorator_1.AuditField)({
272
+ label: { zh: '角色', en: 'Role' },
273
+ valueLabels: {
274
+ user: { zh: '普通用户', en: 'User', ja: '一般ユーザー' },
275
+ vip: { zh: 'VIP用户', en: 'VIP User', ja: 'VIPユーザー' },
276
+ admin: { zh: '管理员', en: 'Admin', ja: '管理者' },
277
+ super_admin: { zh: '超级管理员', en: 'Super Admin', ja: 'スーパー管理者' },
278
+ },
279
+ }),
280
+ __metadata("design:type", String)
281
+ ], UserEntity.prototype, "role", void 0);
282
+ __decorate([
283
+ (0, typeorm_1.Column)({ default: true }),
284
+ (0, entity_audit_decorator_1.AuditField)({
285
+ label: { zh: '邮件通知', en: 'Email Notification' },
286
+ valueLabels: {
287
+ true: { zh: '开启', en: 'Enabled', ja: '有効' },
288
+ false: { zh: '关闭', en: 'Disabled', ja: '無効' },
289
+ },
290
+ }),
291
+ __metadata("design:type", Boolean)
292
+ ], UserEntity.prototype, "emailNotificationEnabled", void 0);
293
+ __decorate([
294
+ (0, typeorm_1.Column)({ default: true }),
295
+ (0, entity_audit_decorator_1.AuditField)({
296
+ label: { zh: '短信通知', en: 'SMS Notification' },
297
+ valueLabels: {
298
+ true: { zh: '开启', en: 'Enabled', ja: '有効' },
299
+ false: { zh: '关闭', en: 'Disabled', ja: '無効' },
300
+ },
301
+ }),
302
+ __metadata("design:type", Boolean)
303
+ ], UserEntity.prototype, "smsNotificationEnabled", void 0);
304
+ __decorate([
305
+ (0, typeorm_1.Column)({
306
+ type: 'enum',
307
+ enum: ['male', 'female', 'other', 'unknown'],
308
+ default: 'unknown',
309
+ }),
310
+ (0, entity_audit_decorator_1.AuditField)({
311
+ label: { zh: '性别', en: 'Gender' },
312
+ valueLabels: {
313
+ male: { zh: '男', en: 'Male', ja: '男性' },
314
+ female: { zh: '女', en: 'Female', ja: '女性' },
315
+ other: { zh: '其他', en: 'Other', ja: 'その他' },
316
+ unknown: { zh: '未知', en: 'Unknown', ja: '不明' },
317
+ },
318
+ }),
319
+ __metadata("design:type", String)
320
+ ], UserEntity.prototype, "gender", void 0);
321
+ __decorate([
322
+ (0, typeorm_1.Column)(),
323
+ (0, entity_audit_decorator_1.AuditField)({
324
+ label: { zh: '密码', en: 'Password' },
325
+ sensitive: true,
326
+ }),
327
+ __metadata("design:type", String)
328
+ ], UserEntity.prototype, "password", void 0);
329
+ exports.UserEntity = UserEntity = __decorate([
330
+ (0, typeorm_1.Entity)('users'),
331
+ (0, entity_audit_decorator_1.AuditEntity)({
332
+ enabled: true,
333
+ maskFields: ['password', 'idCard', 'bankAccount'],
334
+ })
335
+ ], UserEntity);
336
+ // ============================================
337
+ // 示例 4: 库存实体
338
+ // ============================================
339
+ let InventoryEntity = class InventoryEntity {
340
+ };
341
+ exports.InventoryEntity = InventoryEntity;
342
+ __decorate([
343
+ (0, typeorm_1.Column)(),
344
+ (0, entity_audit_decorator_1.AuditField)({
345
+ label: { zh: '商品编号', en: 'Product Code' },
346
+ }),
347
+ __metadata("design:type", String)
348
+ ], InventoryEntity.prototype, "productCode", void 0);
349
+ __decorate([
350
+ (0, typeorm_1.Column)({ default: 0 }),
351
+ (0, entity_audit_decorator_1.AuditField)({
352
+ label: { zh: '可用库存', en: 'Available Stock' },
353
+ formatter: (value) => `${value} 件`,
354
+ }),
355
+ __metadata("design:type", Number)
356
+ ], InventoryEntity.prototype, "availableStock", void 0);
357
+ __decorate([
358
+ (0, typeorm_1.Column)({ default: 0 }),
359
+ (0, entity_audit_decorator_1.AuditField)({
360
+ label: { zh: '锁定库存', en: 'Locked Stock' },
361
+ formatter: (value) => `${value} 件`,
362
+ }),
363
+ __metadata("design:type", Number)
364
+ ], InventoryEntity.prototype, "lockedStock", void 0);
365
+ __decorate([
366
+ (0, typeorm_1.Column)({ default: 0 }),
367
+ (0, entity_audit_decorator_1.AuditField)({
368
+ label: { zh: '总库存', en: 'Total Stock' },
369
+ formatter: (value) => `${value} 件`,
370
+ }),
371
+ __metadata("design:type", Number)
372
+ ], InventoryEntity.prototype, "totalStock", void 0);
373
+ __decorate([
374
+ (0, typeorm_1.Column)({
375
+ type: 'enum',
376
+ enum: ['in_stock', 'low_stock', 'out_of_stock'],
377
+ default: 'in_stock',
378
+ }),
379
+ (0, entity_audit_decorator_1.AuditField)({
380
+ label: { zh: '库存状态', en: 'Stock Status' },
381
+ valueLabels: {
382
+ in_stock: { zh: '充足', en: 'In Stock', ja: '在庫あり' },
383
+ low_stock: { zh: '偏低', en: 'Low Stock', ja: '在庫少' },
384
+ out_of_stock: { zh: '缺货', en: 'Out of Stock', ja: '在庫切れ' },
385
+ },
386
+ }),
387
+ __metadata("design:type", String)
388
+ ], InventoryEntity.prototype, "stockStatus", void 0);
389
+ exports.InventoryEntity = InventoryEntity = __decorate([
390
+ (0, typeorm_1.Entity)('inventory'),
391
+ (0, entity_audit_decorator_1.AuditEntity)({
392
+ enabled: true,
393
+ })
394
+ ], InventoryEntity);
395
+ // ============================================
396
+ // 使用示例
397
+ // ============================================
398
+ const entity_audit_decorator_2 = require("../decorators/entity-audit.decorator");
399
+ // 示例:获取字段标签
400
+ const statusLabelZh = (0, entity_audit_decorator_2.getFieldLabel)(ProductEntity, 'status', 'zh'); // '状态'
401
+ const statusLabelEn = (0, entity_audit_decorator_2.getFieldLabel)(ProductEntity, 'status', 'en'); // 'Status'
402
+ // 示例:获取字段值的标签
403
+ const statusValueZh = (0, entity_audit_decorator_2.getFieldValueLabel)(ProductEntity, 'status', 'active', 'zh'); // '在售'
404
+ const statusValueEn = (0, entity_audit_decorator_2.getFieldValueLabel)(ProductEntity, 'status', 'active', 'en'); // 'Active'
405
+ const statusValueJa = (0, entity_audit_decorator_2.getFieldValueLabel)(ProductEntity, 'status', 'active', 'ja'); // '販売中'
406
+ // 布尔值示例
407
+ const featuredValueZh = (0, entity_audit_decorator_2.getFieldValueLabel)(ProductEntity, 'isFeatured', true, 'zh'); // '是'
408
+ const featuredValueEn = (0, entity_audit_decorator_2.getFieldValueLabel)(ProductEntity, 'isFeatured', false, 'en'); // 'No'
409
+ // 订单状态示例
410
+ const orderStatusZh = (0, entity_audit_decorator_2.getFieldValueLabel)(OrderEntity, 'orderStatus', 'shipped', 'zh'); // '已发货'
411
+ const orderStatusEn = (0, entity_audit_decorator_2.getFieldValueLabel)(OrderEntity, 'orderStatus', 'shipped', 'en'); // 'Shipped'
412
+ // 用户角色示例
413
+ const roleValueZh = (0, entity_audit_decorator_2.getFieldValueLabel)(UserEntity, 'role', 'vip', 'zh'); // 'VIP用户'
414
+ const roleValueEn = (0, entity_audit_decorator_2.getFieldValueLabel)(UserEntity, 'role', 'super_admin', 'en'); // 'Super Admin'
package/audit/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { AuditController, AuditMethod, CONTROLLER_AUDIT_OPTIONS, METHOD_AUDIT_OP
7
7
  export { AuditLog, getAuditOperationConfig, hasAuditOperation, AUDIT_OPERATION_OPTIONS, } from './decorators/audit-operation.decorator';
8
8
  export { AuditAction, AuditActionOptions, AuditActionMetadata, AUDIT_ACTION_METADATA, } from './decorators/audit-action.decorator';
9
9
  export * from './services';
10
+ export { registerEntityClass, getEntityClass } from './services/entity-audit.service';
10
11
  export * from './subscribers';
11
12
  export * from './interceptors';
12
13
  export * from './controllers';
package/audit/index.js CHANGED
@@ -14,7 +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
+ exports.getEntityClass = exports.registerEntityClass = 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;
18
18
  // Entities
19
19
  __exportStar(require("./entities"), exports);
20
20
  // Enums
@@ -49,6 +49,10 @@ Object.defineProperty(exports, "AuditAction", { enumerable: true, get: function
49
49
  Object.defineProperty(exports, "AUDIT_ACTION_METADATA", { enumerable: true, get: function () { return audit_action_decorator_1.AUDIT_ACTION_METADATA; } });
50
50
  // Services
51
51
  __exportStar(require("./services"), exports);
52
+ // Entity class registry (for decorator value mapping)
53
+ var entity_audit_service_1 = require("./services/entity-audit.service");
54
+ Object.defineProperty(exports, "registerEntityClass", { enumerable: true, get: function () { return entity_audit_service_1.registerEntityClass; } });
55
+ Object.defineProperty(exports, "getEntityClass", { enumerable: true, get: function () { return entity_audit_service_1.getEntityClass; } });
52
56
  // Subscribers
53
57
  __exportStar(require("./subscribers"), exports);
54
58
  // Interceptors
@@ -6,6 +6,7 @@ import { AuditContextService } from '../services/audit-context.service';
6
6
  */
7
7
  export declare class AuditInterceptor implements NestInterceptor {
8
8
  private readonly contextService;
9
+ private readonly logger;
9
10
  constructor(contextService: AuditContextService);
10
11
  intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
11
12
  /**
@@ -17,6 +17,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
17
17
  step((generator = generator.apply(thisArg, _arguments || [])).next());
18
18
  });
19
19
  };
20
+ var AuditInterceptor_1;
20
21
  Object.defineProperty(exports, "__esModule", { value: true });
21
22
  exports.AuditInterceptor = void 0;
22
23
  const common_1 = require("@nestjs/common");
@@ -27,9 +28,10 @@ const decorators_1 = require("../decorators");
27
28
  /**
28
29
  * 审计拦截器
29
30
  */
30
- let AuditInterceptor = class AuditInterceptor {
31
+ let AuditInterceptor = AuditInterceptor_1 = class AuditInterceptor {
31
32
  constructor(contextService) {
32
33
  this.contextService = contextService;
34
+ this.logger = new common_1.Logger(AuditInterceptor_1.name);
33
35
  }
34
36
  intercept(context, next) {
35
37
  const request = context.switchToHttp().getRequest();
@@ -70,16 +72,22 @@ let AuditInterceptor = class AuditInterceptor {
70
72
  */
71
73
  handleError(error, request) {
72
74
  return __awaiter(this, void 0, void 0, function* () {
73
- // 记录错误信息到上下文
74
- this.contextService.setContext({
75
- metadata: {
76
- error: {
77
- message: error.message,
78
- stack: error.stack,
79
- status: error.status,
75
+ try {
76
+ // 记录错误信息到上下文
77
+ this.contextService.setContext({
78
+ metadata: {
79
+ error: {
80
+ message: error.message,
81
+ stack: error.stack,
82
+ status: error.status,
83
+ },
80
84
  },
81
- },
82
- });
85
+ });
86
+ }
87
+ catch (contextError) {
88
+ // 不影响请求处理,只记录日志
89
+ this.logger.warn(`Failed to set error context: ${contextError.message}`);
90
+ }
83
91
  });
84
92
  }
85
93
  /**
@@ -111,7 +119,7 @@ let AuditInterceptor = class AuditInterceptor {
111
119
  }
112
120
  };
113
121
  exports.AuditInterceptor = AuditInterceptor;
114
- exports.AuditInterceptor = AuditInterceptor = __decorate([
122
+ exports.AuditInterceptor = AuditInterceptor = AuditInterceptor_1 = __decorate([
115
123
  (0, common_1.Injectable)(),
116
124
  __metadata("design:paramtypes", [audit_context_service_1.AuditContextService])
117
125
  ], AuditInterceptor);
@@ -1,4 +1,4 @@
1
- import { AuditOperation, MaskingStrategy, RecordStrategy, RollbackActionType, ChangeType } from '../enums/audit.enums';
1
+ import { AuditOperation, MaskingStrategy, RecordStrategy, ChangeType } from '../enums/audit.enums';
2
2
  /**
3
3
  * 审计上下文
4
4
  */
@@ -113,8 +113,6 @@ export interface AuditConfig {
113
113
  entities?: Record<string, EntityAuditConfig>;
114
114
  operations?: Record<string, OperationAuditConfig>;
115
115
  security?: {
116
- hashChainEnabled?: boolean;
117
- hashAlgorithm?: string;
118
116
  masking?: {
119
117
  defaultStrategy?: MaskingStrategy;
120
118
  strategies?: Record<string, MaskingStrategy>;
@@ -220,16 +218,6 @@ export interface ChangeDetail {
220
218
  displayNewValue?: Record<string, string>;
221
219
  changeType: ChangeType;
222
220
  }
223
- /**
224
- * 回滚操作
225
- */
226
- export interface RollbackAction {
227
- type: RollbackActionType;
228
- action: string;
229
- params: Record<string, any>;
230
- order: number;
231
- handler?: string;
232
- }
233
221
  /**
234
222
  * 操作模板配置(用于数据库存储)
235
223
  */
@@ -252,7 +240,6 @@ export interface ManualOperationData {
252
240
  userId?: string;
253
241
  username?: string;
254
242
  requestIp?: string;
255
- rollbackActions?: RollbackAction[];
256
243
  }
257
244
  /**
258
245
  * 手动日志记录选项(支持三种模式)
@@ -265,17 +252,15 @@ export interface ManualLogOptions {
265
252
  userId?: string;
266
253
  username?: string;
267
254
  requestIp?: string;
268
- rollbackActions?: RollbackAction[];
269
255
  transactionId?: string;
270
256
  autoCreateTransaction?: boolean;
271
257
  }
272
258
  /**
273
- * 方法审计选项(支持模板和回滚)
259
+ * 方法审计选项(支持模板)
274
260
  */
275
261
  export interface AuditOperationOptions {
276
262
  templateKey: string;
277
263
  descriptionParams?: (args: any[], result: any, context: any) => Record<string, any>;
278
- rollbackActions?: (args: any[], result: any, context: any) => RollbackAction[];
279
264
  autoTransaction?: boolean;
280
265
  }
281
266
  /**
@@ -12,6 +12,15 @@ export interface EntityChangeDetail {
12
12
  newValue: Record<string, any>;
13
13
  changedFields: string[];
14
14
  sequence: number;
15
+ changeDetails?: Array<{
16
+ fieldName: string;
17
+ fieldLabel?: Record<string, string>;
18
+ oldValue: any;
19
+ newValue: any;
20
+ displayOldValue?: Record<string, string>;
21
+ displayNewValue?: Record<string, string>;
22
+ changeType: string;
23
+ }>;
15
24
  metadata?: Record<string, any>;
16
25
  }
17
26
  /**