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

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 (242) hide show
  1. package/audit/audit.module.d.ts +10 -0
  2. package/audit/audit.module.js +15 -0
  3. package/audit/controllers/audit.controller.d.ts +24 -0
  4. package/audit/controllers/audit.controller.js +24 -0
  5. package/audit/decorators/audit-controller.decorator.d.ts +8 -0
  6. package/audit/decorators/audit-controller.decorator.js +9 -0
  7. package/audit/decorators/audit-operation.decorator.d.ts +45 -0
  8. package/audit/decorators/audit-operation.decorator.js +49 -0
  9. package/audit/decorators/entity-audit.decorator.d.ts +8 -0
  10. package/audit/decorators/entity-audit.decorator.js +9 -0
  11. package/audit/dto/audit-log-query.dto.d.ts +3 -0
  12. package/audit/dto/audit-log-query.dto.js +3 -0
  13. package/audit/dto/begin-transaction.dto.d.ts +3 -0
  14. package/audit/dto/begin-transaction.dto.js +3 -0
  15. package/audit/dto/compare-entities.dto.d.ts +3 -0
  16. package/audit/dto/compare-entities.dto.js +3 -0
  17. package/audit/dto/pre-check-restore.dto.d.ts +3 -0
  18. package/audit/dto/pre-check-restore.dto.js +3 -0
  19. package/audit/dto/restore-entity.dto.d.ts +3 -0
  20. package/audit/dto/restore-entity.dto.js +3 -0
  21. package/audit/entities/entity-audit-log.entity.d.ts +3 -0
  22. package/audit/entities/entity-audit-log.entity.js +3 -0
  23. package/audit/entities/entity-transaction.entity.d.ts +3 -0
  24. package/audit/entities/entity-transaction.entity.js +3 -0
  25. package/audit/entities/manual-operation-log.entity.d.ts +4 -0
  26. package/audit/entities/manual-operation-log.entity.js +4 -0
  27. package/audit/entities/operation-template.entity.d.ts +4 -0
  28. package/audit/entities/operation-template.entity.js +4 -0
  29. package/audit/enums/audit.enums.d.ts +17 -2
  30. package/audit/enums/audit.enums.js +15 -0
  31. package/audit/index.js +10 -0
  32. package/audit/interceptors/audit.interceptor.d.ts +15 -0
  33. package/audit/interceptors/audit.interceptor.js +23 -1
  34. package/audit/interfaces/audit.interfaces.d.ts +42 -0
  35. package/audit/services/audit-context.service.d.ts +15 -0
  36. package/audit/services/audit-context.service.js +15 -0
  37. package/audit/services/audit-strategy.service.d.ts +6 -0
  38. package/audit/services/audit-strategy.service.js +13 -0
  39. package/audit/services/entity-audit.service.d.ts +57 -0
  40. package/audit/services/entity-audit.service.js +91 -0
  41. package/audit/services/manual-audit-log.service.d.ts +124 -0
  42. package/audit/services/manual-audit-log.service.js +138 -0
  43. package/audit/services/multi-database.service.d.ts +12 -0
  44. package/audit/services/multi-database.service.js +12 -0
  45. package/audit/services/operation-description.service.d.ts +59 -0
  46. package/audit/services/operation-description.service.js +76 -2
  47. package/audit/services/transaction-audit.service.d.ts +30 -0
  48. package/audit/services/transaction-audit.service.js +47 -0
  49. package/audit/subscribers/entity-audit.subscriber.d.ts +15 -0
  50. package/audit/subscribers/entity-audit.subscriber.js +29 -1
  51. package/cache/cache-metrics.service.d.ts +67 -0
  52. package/cache/cache-metrics.service.js +68 -4
  53. package/cache/cache-serialization.service.d.ts +31 -0
  54. package/cache/cache-serialization.service.js +25 -0
  55. package/cache/cache.constants.d.ts +9 -0
  56. package/cache/cache.constants.js +9 -0
  57. package/cache/cache.health.d.ts +26 -0
  58. package/cache/cache.health.js +30 -0
  59. package/cache/cache.module.d.ts +86 -0
  60. package/cache/cache.module.js +71 -0
  61. package/cache/cache.service.d.ts +140 -0
  62. package/cache/cache.service.js +157 -0
  63. package/cache/cache.warmup.service.d.ts +39 -0
  64. package/cache/cache.warmup.service.js +32 -0
  65. package/cache/decorators/cache-evict.decorator.d.ts +47 -0
  66. package/cache/decorators/cache-evict.decorator.js +56 -0
  67. package/cache/decorators/cache-put.decorator.d.ts +34 -0
  68. package/cache/decorators/cache-put.decorator.js +39 -0
  69. package/cache/decorators/cacheable.decorator.d.ts +40 -0
  70. package/cache/decorators/cacheable.decorator.js +55 -0
  71. package/cache/dependencies/callback.dependency.d.ts +33 -0
  72. package/cache/dependencies/callback.dependency.js +39 -1
  73. package/cache/dependencies/chain.dependency.d.ts +28 -0
  74. package/cache/dependencies/chain.dependency.js +34 -0
  75. package/cache/dependencies/db.dependency.d.ts +45 -0
  76. package/cache/dependencies/db.dependency.js +48 -1
  77. package/cache/dependencies/file.dependency.d.ts +32 -0
  78. package/cache/dependencies/file.dependency.js +34 -0
  79. package/cache/dependencies/tag.dependency.d.ts +36 -0
  80. package/cache/dependencies/tag.dependency.js +36 -0
  81. package/cache/dependencies/time.dependency.d.ts +43 -0
  82. package/cache/dependencies/time.dependency.js +43 -0
  83. package/cache/examples/basic-usage.d.ts +15 -0
  84. package/cache/examples/basic-usage.js +62 -8
  85. package/cache/index.js +9 -0
  86. package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
  87. package/cache/interfaces/cache-options.interface.d.ts +81 -0
  88. package/cache/interfaces/cache-options.interface.js +6 -0
  89. package/cache/interfaces/cache-provider.interface.d.ts +78 -0
  90. package/cache/providers/base-cache.provider.d.ts +14 -0
  91. package/cache/providers/base-cache.provider.js +16 -0
  92. package/cache/providers/cls-cache.provider.d.ts +20 -0
  93. package/cache/providers/cls-cache.provider.js +28 -0
  94. package/cache/providers/memory-cache.provider.d.ts +23 -0
  95. package/cache/providers/memory-cache.provider.js +26 -0
  96. package/cache/providers/redis-cache.provider.d.ts +26 -0
  97. package/cache/providers/redis-cache.provider.js +29 -0
  98. package/cache/utils/dependency-manager.util.d.ts +52 -0
  99. package/cache/utils/dependency-manager.util.js +59 -0
  100. package/cache/utils/key-generator.util.d.ts +42 -0
  101. package/cache/utils/key-generator.util.js +53 -1
  102. package/common/abstract.entity.d.ts +14 -0
  103. package/common/abstract.entity.js +14 -0
  104. package/common/boilerplate.polyfill.d.ts +142 -4
  105. package/common/boilerplate.polyfill.js +24 -100
  106. package/common/dto/dto-container.d.ts +16 -0
  107. package/common/dto/dto-container.js +20 -0
  108. package/common/dto/dto-decorators.d.ts +18 -0
  109. package/common/dto/dto-decorators.js +14 -0
  110. package/common/dto/dto-extensions.d.ts +11 -0
  111. package/common/dto/dto-extensions.js +9 -0
  112. package/common/dto/dto-service-accessor.d.ts +17 -0
  113. package/common/dto/dto-service-accessor.js +18 -0
  114. package/common/dto/dto-transformer.d.ts +12 -0
  115. package/common/dto/dto-transformer.js +9 -0
  116. package/common/dto/index.js +2 -0
  117. package/common/examples/paginate-and-map.example.d.ts +6 -0
  118. package/common/examples/paginate-and-map.example.js +26 -0
  119. package/common/utils.d.ts +15 -0
  120. package/common/utils.js +15 -0
  121. package/constants/language-code.js +1 -0
  122. package/decorators/field.decorators.js +8 -1
  123. package/decorators/property.decorators.js +1 -0
  124. package/decorators/public-route.decorator.js +1 -0
  125. package/decorators/transform.decorators.d.ts +27 -0
  126. package/decorators/transform.decorators.js +29 -0
  127. package/decorators/translate.decorator.js +1 -0
  128. package/decorators/user.decorator.js +1 -0
  129. package/decorators/validator.decorators.d.ts +8 -18
  130. package/decorators/validator.decorators.js +22 -190
  131. package/filters/constraint-errors.js +1 -0
  132. package/helpers/common.helper.d.ts +13 -0
  133. package/helpers/common.helper.js +13 -0
  134. package/http-client/config/http-client.config.d.ts +15 -0
  135. package/http-client/config/http-client.config.js +25 -9
  136. package/http-client/decorators/http-client.decorators.d.ts +63 -0
  137. package/http-client/decorators/http-client.decorators.js +71 -3
  138. package/http-client/entities/http-log.entity.d.ts +229 -0
  139. package/http-client/entities/http-log.entity.js +6 -1
  140. package/http-client/errors/http-client.errors.d.ts +57 -0
  141. package/http-client/errors/http-client.errors.js +58 -0
  142. package/http-client/examples/advanced-usage.example.d.ts +41 -0
  143. package/http-client/examples/advanced-usage.example.js +68 -24
  144. package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
  145. package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
  146. package/http-client/examples/basic-usage.example.d.ts +60 -0
  147. package/http-client/examples/basic-usage.example.js +60 -0
  148. package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
  149. package/http-client/examples/multi-api-configuration.example.js +76 -5
  150. package/http-client/http-client.module.d.ts +13 -0
  151. package/http-client/http-client.module.js +19 -0
  152. package/http-client/index.js +8 -0
  153. package/http-client/interfaces/api-client-config.interface.d.ts +125 -0
  154. package/http-client/interfaces/api-client-config.interface.js +3 -0
  155. package/http-client/interfaces/http-client-config.interface.d.ts +60 -0
  156. package/http-client/services/api-client-registry.service.d.ts +57 -0
  157. package/http-client/services/api-client-registry.service.js +84 -1
  158. package/http-client/services/cache.service.d.ts +52 -0
  159. package/http-client/services/cache.service.js +72 -3
  160. package/http-client/services/circuit-breaker.service.d.ts +46 -0
  161. package/http-client/services/circuit-breaker.service.js +52 -0
  162. package/http-client/services/http-client.service.d.ts +67 -0
  163. package/http-client/services/http-client.service.js +105 -4
  164. package/http-client/services/http-log-query.service.d.ts +83 -0
  165. package/http-client/services/http-log-query.service.js +122 -1
  166. package/http-client/services/http-replay.service.d.ts +101 -0
  167. package/http-client/services/http-replay.service.js +86 -0
  168. package/http-client/services/log-cleanup.service.d.ts +63 -0
  169. package/http-client/services/log-cleanup.service.js +54 -2
  170. package/http-client/services/logging.service.d.ts +40 -0
  171. package/http-client/services/logging.service.js +53 -0
  172. package/http-client/utils/call-stack-extractor.util.d.ts +37 -0
  173. package/http-client/utils/call-stack-extractor.util.js +48 -0
  174. package/http-client/utils/context-extractor.util.d.ts +49 -0
  175. package/http-client/utils/context-extractor.util.js +52 -0
  176. package/http-client/utils/curl-generator.util.d.ts +21 -0
  177. package/http-client/utils/curl-generator.util.js +44 -3
  178. package/http-client/utils/request-id.util.d.ts +18 -0
  179. package/http-client/utils/request-id.util.js +20 -0
  180. package/http-client/utils/retry-recorder.util.d.ts +42 -0
  181. package/http-client/utils/retry-recorder.util.js +44 -0
  182. package/i18n/en_US/validation.json +2 -1
  183. package/i18n/zh_CN/validation.json +2 -1
  184. package/index.js +8 -0
  185. package/interceptors/translation-interceptor.service.js +5 -0
  186. package/package.json +1 -1
  187. package/providers/context.provider.js +2 -0
  188. package/providers/generator.provider.d.ts +4 -0
  189. package/providers/generator.provider.js +4 -0
  190. package/redis-lock/comprehensive-lock-cleanup.service.d.ts +94 -0
  191. package/redis-lock/comprehensive-lock-cleanup.service.js +253 -0
  192. package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
  193. package/redis-lock/examples/lock-strategy.examples.js +130 -15
  194. package/redis-lock/index.d.ts +2 -0
  195. package/redis-lock/index.js +8 -1
  196. package/redis-lock/lock-heartbeat.service.d.ts +78 -0
  197. package/redis-lock/lock-heartbeat.service.js +222 -0
  198. package/redis-lock/redis-lock.decorator.d.ts +101 -0
  199. package/redis-lock/redis-lock.decorator.js +120 -0
  200. package/redis-lock/redis-lock.module.d.ts +66 -0
  201. package/redis-lock/redis-lock.module.js +175 -70
  202. package/redis-lock/redis-lock.service.d.ts +260 -0
  203. package/redis-lock/redis-lock.service.js +244 -4
  204. package/setup/bootstrap.setup.js +20 -0
  205. package/setup/mode.setup.d.ts +44 -0
  206. package/setup/mode.setup.js +44 -0
  207. package/setup/schedule.decorator.d.ts +227 -0
  208. package/setup/schedule.decorator.js +219 -6
  209. package/setup/worker.decorator.d.ts +86 -0
  210. package/setup/worker.decorator.js +88 -0
  211. package/shared/serviceRegistryModule.js +9 -1
  212. package/shared/services/api-config.service.d.ts +3 -0
  213. package/shared/services/api-config.service.js +20 -9
  214. package/validator-json/decorators.d.ts +17 -0
  215. package/validator-json/decorators.js +17 -2
  216. package/validator-json/default.d.ts +6 -0
  217. package/validator-json/default.js +30 -2
  218. package/validator-json/defaultConverters.js +1 -0
  219. package/validator-json/options.d.ts +23 -0
  220. package/validators/common-validators.d.ts +143 -0
  221. package/validators/common-validators.js +249 -0
  222. package/validators/custom-validate.examples.d.ts +96 -0
  223. package/validators/custom-validate.examples.js +400 -0
  224. package/validators/custom-validate.validator.d.ts +134 -0
  225. package/validators/custom-validate.validator.js +214 -0
  226. package/validators/index.d.ts +2 -0
  227. package/validators/index.js +2 -0
  228. package/validators/is-exists.validator.d.ts +18 -4
  229. package/validators/is-exists.validator.js +67 -6
  230. package/validators/is-unique.validator.d.ts +32 -5
  231. package/validators/is-unique.validator.js +99 -17
  232. package/validators/skip-empty.validator.d.ts +5 -0
  233. package/validators/skip-empty.validator.js +5 -0
  234. package/vault/interfaces/vault-options.interface.d.ts +9 -0
  235. package/vault/vault-config.loader.d.ts +30 -0
  236. package/vault/vault-config.loader.js +48 -1
  237. package/vault/vault-config.service.d.ts +53 -0
  238. package/vault/vault-config.service.js +57 -0
  239. package/vault/vault.module.d.ts +4 -0
  240. package/vault/vault.module.js +4 -0
  241. package/decorators/examples/validation-decorators.example.d.ts +0 -69
  242. package/decorators/examples/validation-decorators.example.js +0 -331
@@ -26,6 +26,10 @@ const http_log_entity_1 = require("../entities/http-log.entity");
26
26
  const request_id_util_1 = require("../utils/request-id.util");
27
27
  const context_extractor_util_1 = require("../utils/context-extractor.util");
28
28
  const call_stack_extractor_util_1 = require("../utils/call-stack-extractor.util");
29
+ /**
30
+ * HTTP日志服务
31
+ * 基于Spring Boot的请求日志记录机制,集成现有的ContextProvider
32
+ */
29
33
  let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
30
34
  constructor(dataSource) {
31
35
  this.dataSource = dataSource;
@@ -35,7 +39,11 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
35
39
  this.initializeDatabaseLogging();
36
40
  }
37
41
  }
42
+ /**
43
+ * 记录请求开始
44
+ */
38
45
  logRequestStart(config, loggingOptions, requestId) {
46
+ // 从ContextProvider获取上下文信息
39
47
  const context = context_extractor_util_1.ContextExtractor.getHttpContext();
40
48
  const actualRequestId = requestId || context.requestId || (0, request_id_util_1.generateRequestId)();
41
49
  const { logHeaders = true, logBody = true, sanitizeHeaders = [], } = loggingOptions || {};
@@ -63,10 +71,14 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
63
71
  }
64
72
  return actualRequestId;
65
73
  }
74
+ /**
75
+ * 记录请求成功响应
76
+ */
66
77
  logRequestSuccess(response, startTime, requestId, loggingOptions, databaseLogging = false, retryRecords, cacheHit, circuitBreakerState, decoratorContext) {
67
78
  var _a, _b;
68
79
  const { logHeaders = true, logBody = true, sanitizeHeaders = [], } = loggingOptions || {};
69
80
  const responseTime = Date.now() - startTime;
81
+ // 获取当前上下文信息
70
82
  const context = context_extractor_util_1.ContextExtractor.getHttpContext();
71
83
  const logData = {
72
84
  requestId,
@@ -91,7 +103,9 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
91
103
  this.logger.log(logMessage, logData);
92
104
  break;
93
105
  }
106
+ // 数据库日志记录
94
107
  if (databaseLogging && this.logRepository) {
108
+ // 提取调用信息
95
109
  const callInfo = this.extractCallInfo(decoratorContext, response.config);
96
110
  this.saveToDatabase({
97
111
  id: requestId,
@@ -126,10 +140,14 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
126
140
  });
127
141
  }
128
142
  }
143
+ /**
144
+ * 记录请求错误
145
+ */
129
146
  logRequestError(error, startTime, requestId, attemptCount, loggingOptions, databaseLogging = false, retryRecords, cacheHit, circuitBreakerState, decoratorContext) {
130
147
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
131
148
  const { logHeaders = true, sanitizeHeaders = [] } = loggingOptions;
132
149
  const responseTime = Date.now() - startTime;
150
+ // 获取当前上下文信息
133
151
  const context = context_extractor_util_1.ContextExtractor.getHttpContext();
134
152
  const logData = {
135
153
  requestId,
@@ -160,7 +178,9 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
160
178
  this.logger.error(logMessage, logData);
161
179
  break;
162
180
  }
181
+ // 数据库日志记录
163
182
  if (databaseLogging && this.logRepository) {
183
+ // 提取调用信息
164
184
  const callInfo = this.extractCallInfo(decoratorContext, error.config);
165
185
  this.saveToDatabase({
166
186
  id: requestId,
@@ -193,6 +213,9 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
193
213
  });
194
214
  }
195
215
  }
216
+ /**
217
+ * 查询请求日志
218
+ */
196
219
  findLogs(options) {
197
220
  return __awaiter(this, void 0, void 0, function* () {
198
221
  if (!this.logRepository) {
@@ -243,6 +266,9 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
243
266
  return queryBuilder.getMany();
244
267
  });
245
268
  }
269
+ /**
270
+ * 获取请求统计信息
271
+ */
246
272
  getStatistics(options) {
247
273
  return __awaiter(this, void 0, void 0, function* () {
248
274
  if (!this.logRepository) {
@@ -272,12 +298,14 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
272
298
  .clone()
273
299
  .select('AVG(log.responseTime)', 'avg')
274
300
  .getRawOne();
301
+ // 按状态码统计
275
302
  const statusStats = yield queryBuilder
276
303
  .clone()
277
304
  .select('log.statusCode', 'statusCode')
278
305
  .addSelect('COUNT(*)', 'count')
279
306
  .groupBy('log.statusCode')
280
307
  .getRawMany();
308
+ // 按方法统计
281
309
  const methodStats = yield queryBuilder
282
310
  .clone()
283
311
  .select('log.method', 'method')
@@ -301,6 +329,9 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
301
329
  };
302
330
  });
303
331
  }
332
+ /**
333
+ * 初始化数据库日志记录
334
+ */
304
335
  initializeDatabaseLogging() {
305
336
  return __awaiter(this, void 0, void 0, function* () {
306
337
  try {
@@ -312,7 +343,11 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
312
343
  }
313
344
  });
314
345
  }
346
+ /**
347
+ * 提取调用信息
348
+ */
315
349
  extractCallInfo(decoratorContext, config) {
350
+ // 优先使用装饰器配置的调用信息
316
351
  if (decoratorContext) {
317
352
  const decoratorInfo = call_stack_extractor_util_1.CallStackExtractor.extractFromDecorator(decoratorContext.target, decoratorContext.propertyKey);
318
353
  if (decoratorInfo.serviceClass && decoratorInfo.methodName) {
@@ -321,18 +356,21 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
321
356
  };
322
357
  }
323
358
  }
359
+ // 然后尝试手动设置的调用信息
324
360
  const manualInfo = call_stack_extractor_util_1.CallStackExtractor.getManualCallInfo();
325
361
  if (manualInfo) {
326
362
  return {
327
363
  operationName: manualInfo.operationName,
328
364
  };
329
365
  }
366
+ // 最后尝试从调用栈自动提取
330
367
  const stackInfo = call_stack_extractor_util_1.CallStackExtractor.getCallInfo();
331
368
  if (stackInfo.serviceClass && stackInfo.methodName) {
332
369
  return {
333
370
  operationName: stackInfo.operationName,
334
371
  };
335
372
  }
373
+ // 如果都无法获取,根据URL生成操作名称
336
374
  if (config === null || config === void 0 ? void 0 : config.url) {
337
375
  const pathParts = config.url
338
376
  .split('/')
@@ -346,6 +384,9 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
346
384
  }
347
385
  return {};
348
386
  }
387
+ /**
388
+ * 保存到数据库
389
+ */
349
390
  saveToDatabase(logEntity) {
350
391
  return __awaiter(this, void 0, void 0, function* () {
351
392
  if (!this.logRepository)
@@ -358,6 +399,9 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
358
399
  }
359
400
  });
360
401
  }
402
+ /**
403
+ * 转换请求体为字符串
404
+ */
361
405
  sanitizeBodyAsString(data) {
362
406
  if (!data)
363
407
  return undefined;
@@ -369,6 +413,9 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
369
413
  ? jsonString.substring(0, 5000) + '...'
370
414
  : jsonString;
371
415
  }
416
+ /**
417
+ * 清理敏感头信息
418
+ */
372
419
  sanitizeHeaders(headers, sanitizeHeaders) {
373
420
  if (!headers)
374
421
  return {};
@@ -395,6 +442,9 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
395
442
  });
396
443
  return sanitized;
397
444
  }
445
+ /**
446
+ * 清理敏感请求体信息
447
+ */
398
448
  sanitizeBody(body) {
399
449
  if (!body)
400
450
  return undefined;
@@ -425,6 +475,9 @@ let HttpLoggingService = HttpLoggingService_1 = class HttpLoggingService {
425
475
  }
426
476
  return body;
427
477
  }
478
+ /**
479
+ * 递归清理对象中的敏感字段
480
+ */
428
481
  sanitizeObject(obj, sensitiveFields) {
429
482
  if (typeof obj !== 'object' || obj === null)
430
483
  return;
@@ -1,29 +1,66 @@
1
+ /**
2
+ * 调用栈提取工具
3
+ * 用于自动提取HTTP请求的调用服务和方法信息
4
+ */
1
5
  export declare class CallStackExtractor {
6
+ /**
7
+ * 从调用栈中提取服务和方法信息
8
+ */
2
9
  static extractCallInfo(): {
3
10
  serviceClass?: string;
4
11
  methodName?: string;
5
12
  operationName?: string;
6
13
  };
14
+ /**
15
+ * 手动设置调用信息(当自动检测失败时)
16
+ */
7
17
  static setCallInfo(serviceClass: string, methodName: string, operationName?: string): void;
18
+ /**
19
+ * 获取手动设置的调用信息
20
+ */
8
21
  static getManualCallInfo(): {
9
22
  serviceClass?: string;
10
23
  methodName?: string;
11
24
  operationName?: string;
12
25
  } | null;
26
+ /**
27
+ * 清理手动设置的调用信息
28
+ */
13
29
  static clearCallInfo(): void;
30
+ /**
31
+ * 获取调用信息(优先使用手动设置的信息)
32
+ */
14
33
  static getCallInfo(): {
15
34
  serviceClass?: string;
16
35
  methodName?: string;
17
36
  operationName?: string;
18
37
  };
38
+ /**
39
+ * 从装饰器中提取调用信息
40
+ */
19
41
  static extractFromDecorator(target: any, propertyKey: string): {
20
42
  serviceClass?: string;
21
43
  methodName?: string;
22
44
  operationName?: string;
23
45
  };
46
+ /**
47
+ * 生成操作名称
48
+ */
24
49
  static generateOperationName(serviceClass?: string, methodName?: string, config?: any): string;
50
+ /**
51
+ * 格式化服务类名
52
+ */
25
53
  static formatServiceClass(serviceClass?: string): string;
54
+ /**
55
+ * 格式化方法名
56
+ */
26
57
  static formatMethodName(methodName?: string): string;
58
+ /**
59
+ * 解析调用栈行
60
+ */
27
61
  private static parseStackLine;
62
+ /**
63
+ * 判断是否为内部调用
64
+ */
28
65
  private static isInternalCall;
29
66
  }
@@ -1,18 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CallStackExtractor = void 0;
4
+ /**
5
+ * 调用栈提取工具
6
+ * 用于自动提取HTTP请求的调用服务和方法信息
7
+ */
4
8
  class CallStackExtractor {
9
+ /**
10
+ * 从调用栈中提取服务和方法信息
11
+ */
5
12
  static extractCallInfo() {
6
13
  const stack = new Error().stack;
7
14
  if (!stack) {
8
15
  return {};
9
16
  }
10
17
  const lines = stack.split('\n');
18
+ // 跳过当前函数和HTTP客户端内部调用
11
19
  const httpClientIndex = lines.findIndex((line) => line.includes('http-client.service.ts') ||
12
20
  line.includes('HttpClientService'));
13
21
  if (httpClientIndex === -1) {
14
22
  return {};
15
23
  }
24
+ // 查找实际的业务调用
16
25
  for (let i = httpClientIndex + 1; i < lines.length; i++) {
17
26
  const line = lines[i];
18
27
  const callInfo = this.parseStackLine(line);
@@ -22,7 +31,11 @@ class CallStackExtractor {
22
31
  }
23
32
  return {};
24
33
  }
34
+ /**
35
+ * 手动设置调用信息(当自动检测失败时)
36
+ */
25
37
  static setCallInfo(serviceClass, methodName, operationName) {
38
+ // 存储到当前上下文中
26
39
  if (typeof global !== 'undefined') {
27
40
  global.httpCallContext = {
28
41
  serviceClass,
@@ -32,9 +45,13 @@ class CallStackExtractor {
32
45
  };
33
46
  }
34
47
  }
48
+ /**
49
+ * 获取手动设置的调用信息
50
+ */
35
51
  static getManualCallInfo() {
36
52
  if (typeof global !== 'undefined' && global.httpCallContext) {
37
53
  const context = global.httpCallContext;
54
+ // 清理过期的上下文(超过1秒)
38
55
  if (Date.now() - context.timestamp < 1000) {
39
56
  return {
40
57
  serviceClass: context.serviceClass,
@@ -46,18 +63,29 @@ class CallStackExtractor {
46
63
  }
47
64
  return null;
48
65
  }
66
+ /**
67
+ * 清理手动设置的调用信息
68
+ */
49
69
  static clearCallInfo() {
50
70
  if (typeof global !== 'undefined' && global.httpCallContext) {
51
71
  delete global.httpCallContext;
52
72
  }
53
73
  }
74
+ /**
75
+ * 获取调用信息(优先使用手动设置的信息)
76
+ */
54
77
  static getCallInfo() {
78
+ // 首先尝试获取手动设置的信息
55
79
  const manualInfo = this.getManualCallInfo();
56
80
  if (manualInfo) {
57
81
  return manualInfo;
58
82
  }
83
+ // 然后尝试从调用栈中自动提取
59
84
  return this.extractCallInfo();
60
85
  }
86
+ /**
87
+ * 从装饰器中提取调用信息
88
+ */
61
89
  static extractFromDecorator(target, propertyKey) {
62
90
  var _a;
63
91
  const serviceClass = (_a = target.constructor) === null || _a === void 0 ? void 0 : _a.name;
@@ -70,13 +98,18 @@ class CallStackExtractor {
70
98
  : undefined,
71
99
  };
72
100
  }
101
+ /**
102
+ * 生成操作名称
103
+ */
73
104
  static generateOperationName(serviceClass, methodName, config) {
74
105
  if (!serviceClass || !methodName) {
75
106
  return 'Unknown';
76
107
  }
108
+ // 根据URL生成操作名称
77
109
  let operationName = `${serviceClass}.${methodName}`;
78
110
  if (config === null || config === void 0 ? void 0 : config.url) {
79
111
  const url = config.url;
112
+ // 提取URL中的关键路径部分
80
113
  const pathParts = url
81
114
  .split('/')
82
115
  .filter((part) => part && !part.includes('{'));
@@ -89,20 +122,32 @@ class CallStackExtractor {
89
122
  }
90
123
  return operationName;
91
124
  }
125
+ /**
126
+ * 格式化服务类名
127
+ */
92
128
  static formatServiceClass(serviceClass) {
93
129
  if (!serviceClass)
94
130
  return 'Unknown';
131
+ // 移除常见的后缀
95
132
  return serviceClass.replace(/Service|Controller|Provider|Handler$/, '');
96
133
  }
134
+ /**
135
+ * 格式化方法名
136
+ */
97
137
  static formatMethodName(methodName) {
98
138
  if (!methodName)
99
139
  return 'unknown';
140
+ // 将驼峰命名转换为更友好的格式
100
141
  return methodName
101
142
  .replace(/([A-Z])/g, ' $1')
102
143
  .replace(/^./, (str) => str.toUpperCase())
103
144
  .trim();
104
145
  }
146
+ /**
147
+ * 解析调用栈行
148
+ */
105
149
  static parseStackLine(line) {
150
+ // 匹配格式:at ClassName.methodName (/path/to/file.js:line:column)
106
151
  const match = line.match(/at\s+([^.]+)\.([^(]+)\s*\(/);
107
152
  if (!match) {
108
153
  return null;
@@ -114,6 +159,9 @@ class CallStackExtractor {
114
159
  operationName: `${serviceClass}.${methodName}`,
115
160
  };
116
161
  }
162
+ /**
163
+ * 判断是否为内部调用
164
+ */
117
165
  static isInternalCall(serviceClass) {
118
166
  if (!serviceClass)
119
167
  return true;
@@ -1,4 +1,11 @@
1
+ /**
2
+ * 上下文信息提取器
3
+ * 从ContextProvider获取请求相关的上下文信息
4
+ */
1
5
  export declare class ContextExtractor {
6
+ /**
7
+ * 获取完整的HTTP请求上下文
8
+ */
2
9
  static getHttpContext(): {
3
10
  requestId?: string;
4
11
  userId?: string;
@@ -8,14 +15,41 @@ export declare class ContextExtractor {
8
15
  metadata?: Record<string, any>;
9
16
  tags?: string[];
10
17
  };
18
+ /**
19
+ * 获取请求ID
20
+ */
11
21
  static getRequestId(): string | undefined;
22
+ /**
23
+ * 获取用户ID
24
+ */
12
25
  static getUserId(): string | undefined;
26
+ /**
27
+ * 获取客户端IP
28
+ */
13
29
  static getClientIp(): string | undefined;
30
+ /**
31
+ * 获取用户代理
32
+ */
14
33
  static getUserAgent(): string | undefined;
34
+ /**
35
+ * 获取服务名称
36
+ */
15
37
  static getServiceName(): string | undefined;
38
+ /**
39
+ * 获取元数据
40
+ */
16
41
  static getMetadata(): Record<string, any> | undefined;
42
+ /**
43
+ * 获取标签
44
+ */
17
45
  static getTags(): string[];
46
+ /**
47
+ * 添加标签到上下文
48
+ */
18
49
  static addTag(tag: string): void;
50
+ /**
51
+ * 获取上下文摘要
52
+ */
19
53
  static getContextSummary(): {
20
54
  requestId?: string;
21
55
  userId?: string;
@@ -24,13 +58,22 @@ export declare class ContextExtractor {
24
58
  hasUser: boolean;
25
59
  requestSource: string;
26
60
  };
61
+ /**
62
+ * 获取请求来源信息
63
+ */
27
64
  static getRequestSource(): {
28
65
  source: 'internal' | 'external' | 'unknown';
29
66
  ip?: string;
30
67
  userAgent?: string;
31
68
  service?: string;
32
69
  };
70
+ /**
71
+ * 判断是否为内部请求
72
+ */
33
73
  static isInternalRequest(): boolean;
74
+ /**
75
+ * 获取安全上下文
76
+ */
34
77
  static getSecurityContext(): {
35
78
  isAuthenticated: boolean;
36
79
  userId?: string;
@@ -39,6 +82,12 @@ export declare class ContextExtractor {
39
82
  permissions: string[];
40
83
  securityLevel: 'low' | 'medium' | 'high';
41
84
  };
85
+ /**
86
+ * 生成Span ID
87
+ */
42
88
  private static generateSpanId;
89
+ /**
90
+ * 检查172.x.x.x是否为内网IP (172.16.0.0 - 172.31.255.255)
91
+ */
43
92
  private static isInternal172IP;
44
93
  }
@@ -2,7 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ContextExtractor = void 0;
4
4
  const providers_1 = require("../../providers");
5
+ /**
6
+ * 上下文信息提取器
7
+ * 从ContextProvider获取请求相关的上下文信息
8
+ */
5
9
  class ContextExtractor {
10
+ /**
11
+ * 获取完整的HTTP请求上下文
12
+ */
6
13
  static getHttpContext() {
7
14
  try {
8
15
  const requestId = providers_1.ContextProvider.getRequestId();
@@ -21,11 +28,15 @@ class ContextExtractor {
21
28
  };
22
29
  }
23
30
  catch (_a) {
31
+ // If no context is available, return empty context
24
32
  return {
25
33
  tags: [],
26
34
  };
27
35
  }
28
36
  }
37
+ /**
38
+ * 获取请求ID
39
+ */
29
40
  static getRequestId() {
30
41
  try {
31
42
  return providers_1.ContextProvider.getRequestId();
@@ -34,6 +45,9 @@ class ContextExtractor {
34
45
  return undefined;
35
46
  }
36
47
  }
48
+ /**
49
+ * 获取用户ID
50
+ */
37
51
  static getUserId() {
38
52
  try {
39
53
  const authUser = providers_1.ContextProvider.getAuthUser();
@@ -43,6 +57,9 @@ class ContextExtractor {
43
57
  return undefined;
44
58
  }
45
59
  }
60
+ /**
61
+ * 获取客户端IP
62
+ */
46
63
  static getClientIp() {
47
64
  try {
48
65
  const router = providers_1.ContextProvider.getRouter();
@@ -52,6 +69,9 @@ class ContextExtractor {
52
69
  return undefined;
53
70
  }
54
71
  }
72
+ /**
73
+ * 获取用户代理
74
+ */
55
75
  static getUserAgent() {
56
76
  try {
57
77
  const router = providers_1.ContextProvider.getRouter();
@@ -61,6 +81,9 @@ class ContextExtractor {
61
81
  return undefined;
62
82
  }
63
83
  }
84
+ /**
85
+ * 获取服务名称
86
+ */
64
87
  static getServiceName() {
65
88
  try {
66
89
  const authUser = providers_1.ContextProvider.getAuthUser();
@@ -70,6 +93,9 @@ class ContextExtractor {
70
93
  return undefined;
71
94
  }
72
95
  }
96
+ /**
97
+ * 获取元数据
98
+ */
73
99
  static getMetadata() {
74
100
  try {
75
101
  const authUser = providers_1.ContextProvider.getAuthUser();
@@ -83,6 +109,9 @@ class ContextExtractor {
83
109
  return undefined;
84
110
  }
85
111
  }
112
+ /**
113
+ * 获取标签
114
+ */
86
115
  static getTags() {
87
116
  try {
88
117
  const context = this.getHttpContext();
@@ -92,6 +121,9 @@ class ContextExtractor {
92
121
  return [];
93
122
  }
94
123
  }
124
+ /**
125
+ * 添加标签到上下文
126
+ */
95
127
  static addTag(tag) {
96
128
  try {
97
129
  const context = this.getHttpContext();
@@ -102,8 +134,12 @@ class ContextExtractor {
102
134
  }
103
135
  }
104
136
  catch (_a) {
137
+ // Silently fail if context is not available
105
138
  }
106
139
  }
140
+ /**
141
+ * 获取上下文摘要
142
+ */
107
143
  static getContextSummary() {
108
144
  const context = this.getHttpContext();
109
145
  return {
@@ -115,11 +151,15 @@ class ContextExtractor {
115
151
  requestSource: this.getRequestSource().source,
116
152
  };
117
153
  }
154
+ /**
155
+ * 获取请求来源信息
156
+ */
118
157
  static getRequestSource() {
119
158
  const context = this.getHttpContext();
120
159
  if (!context.clientIp) {
121
160
  return { source: 'unknown' };
122
161
  }
162
+ // Check if it's an internal IP
123
163
  const internalIPs = ['::1', '127.0.0.1', 'localhost'];
124
164
  const isInternal = internalIPs.includes(context.clientIp) ||
125
165
  context.clientIp.startsWith('192.168.') ||
@@ -133,10 +173,16 @@ class ContextExtractor {
133
173
  service: context.appId,
134
174
  };
135
175
  }
176
+ /**
177
+ * 判断是否为内部请求
178
+ */
136
179
  static isInternalRequest() {
137
180
  const requestSource = this.getRequestSource();
138
181
  return requestSource.source === 'internal';
139
182
  }
183
+ /**
184
+ * 获取安全上下文
185
+ */
140
186
  static getSecurityContext() {
141
187
  try {
142
188
  const authUser = providers_1.ContextProvider.getAuthUser();
@@ -157,9 +203,15 @@ class ContextExtractor {
157
203
  };
158
204
  }
159
205
  }
206
+ /**
207
+ * 生成Span ID
208
+ */
160
209
  static generateSpanId() {
161
210
  return Math.random().toString(36).substring(2, 15);
162
211
  }
212
+ /**
213
+ * 检查172.x.x.x是否为内网IP (172.16.0.0 - 172.31.255.255)
214
+ */
163
215
  static isInternal172IP(ip) {
164
216
  if (!ip.startsWith('172.'))
165
217
  return false;
@@ -1,9 +1,30 @@
1
1
  import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ /**
3
+ * HTTP请求curl命令生成器
4
+ */
2
5
  export declare class CurlGenerator {
6
+ /**
7
+ * 生成curl命令
8
+ */
3
9
  static generateCurlCommand(config: AxiosRequestConfig, response?: AxiosResponse): string;
10
+ /**
11
+ * 生成简化的curl命令(用于日志记录)
12
+ */
4
13
  static generateSimplifiedCurl(config: AxiosRequestConfig): string;
14
+ /**
15
+ * 生成用于调试的详细curl命令
16
+ */
5
17
  static generateDebugCurl(config: AxiosRequestConfig, response?: AxiosResponse): string;
18
+ /**
19
+ * 从curl命令解析请求配置
20
+ */
6
21
  static parseCurlCommand(curlCommand: string): Partial<AxiosRequestConfig>;
22
+ /**
23
+ * 构建完整URL
24
+ */
7
25
  private static buildUrl;
26
+ /**
27
+ * 过滤敏感头信息
28
+ */
8
29
  private static sanitizeHeaderValue;
9
30
  }