@nest-omni/core 4.1.3-3 → 4.1.3-31

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 (370) hide show
  1. package/audit/audit.module.d.ts +1 -0
  2. package/audit/audit.module.js +51 -2
  3. package/audit/controllers/audit.controller.d.ts +57 -1
  4. package/audit/controllers/audit.controller.js +43 -0
  5. package/audit/decorators/audit-action.decorator.d.ts +74 -0
  6. package/audit/decorators/audit-action.decorator.js +42 -0
  7. package/audit/decorators/audit-controller.decorator.d.ts +1 -1
  8. package/audit/decorators/audit-controller.decorator.js +2 -2
  9. package/audit/decorators/audit-operation.decorator.d.ts +0 -7
  10. package/audit/decorators/audit-operation.decorator.js +0 -7
  11. package/audit/decorators/entity-audit.decorator.d.ts +78 -2
  12. package/audit/decorators/entity-audit.decorator.js +145 -4
  13. package/audit/decorators/index.d.ts +2 -0
  14. package/audit/decorators/index.js +2 -0
  15. package/audit/dto/audit-action-query.dto.d.ts +13 -0
  16. package/audit/dto/audit-action-query.dto.js +77 -0
  17. package/audit/dto/index.d.ts +1 -0
  18. package/audit/dto/index.js +1 -0
  19. package/audit/entities/audit-action-summary.entity.d.ts +23 -0
  20. package/audit/entities/audit-action-summary.entity.js +101 -0
  21. package/audit/entities/entity-audit-log.entity.d.ts +7 -2
  22. package/audit/entities/entity-audit-log.entity.js +45 -9
  23. package/audit/entities/entity-transaction.entity.d.ts +8 -2
  24. package/audit/entities/entity-transaction.entity.js +39 -3
  25. package/audit/entities/index.d.ts +3 -0
  26. package/audit/entities/index.js +3 -0
  27. package/audit/entities/manual-operation-log.entity.d.ts +0 -2
  28. package/audit/entities/manual-operation-log.entity.js +8 -9
  29. package/audit/enums/audit.enums.d.ts +14 -6
  30. package/audit/enums/audit.enums.js +18 -9
  31. package/audit/examples/decorator-value-mapping.example.d.ts +70 -0
  32. package/audit/examples/decorator-value-mapping.example.js +414 -0
  33. package/audit/index.d.ts +5 -1
  34. package/audit/index.js +29 -2
  35. package/audit/interceptors/audit-action.interceptor.d.ts +39 -0
  36. package/audit/interceptors/audit-action.interceptor.js +217 -0
  37. package/audit/interceptors/audit.interceptor.d.ts +1 -0
  38. package/audit/interceptors/audit.interceptor.js +19 -11
  39. package/audit/interceptors/index.d.ts +1 -0
  40. package/audit/interceptors/index.js +1 -0
  41. package/audit/interfaces/audit.interfaces.d.ts +132 -4
  42. package/audit/services/audit-action.service.d.ts +142 -0
  43. package/audit/services/audit-action.service.js +246 -0
  44. package/audit/services/audit-context.service.d.ts +91 -0
  45. package/audit/services/audit-context.service.js +170 -0
  46. package/audit/services/entity-audit.service.d.ts +220 -9
  47. package/audit/services/entity-audit.service.js +761 -72
  48. package/audit/services/index.d.ts +3 -0
  49. package/audit/services/index.js +3 -0
  50. package/audit/services/manual-audit-log.service.d.ts +23 -23
  51. package/audit/services/manual-audit-log.service.js +34 -57
  52. package/audit/services/multi-database.service.d.ts +0 -5
  53. package/audit/services/multi-database.service.js +0 -24
  54. package/audit/services/operation-description.service.d.ts +14 -3
  55. package/audit/services/operation-description.service.js +165 -26
  56. package/audit/services/transaction-audit.service.d.ts +1 -0
  57. package/audit/services/transaction-audit.service.js +12 -9
  58. package/audit/subscribers/entity-audit.subscriber.d.ts +5 -0
  59. package/audit/subscribers/entity-audit.subscriber.js +69 -5
  60. package/cache/cache.module.d.ts +7 -8
  61. package/cache/cache.module.js +15 -13
  62. package/cache/cache.service.d.ts +6 -4
  63. package/cache/cache.service.js +24 -12
  64. package/cache/decorators/cache-put.decorator.js +5 -4
  65. package/cache/dependencies/callback.dependency.js +9 -0
  66. package/cache/dependencies/db.dependency.d.ts +43 -12
  67. package/cache/dependencies/db.dependency.js +46 -18
  68. package/cache/dependencies/tag.dependency.d.ts +31 -4
  69. package/cache/dependencies/tag.dependency.js +100 -11
  70. package/cache/entities/index.d.ts +1 -0
  71. package/cache/entities/index.js +17 -0
  72. package/cache/entities/typeorm-cache.entity.d.ts +71 -0
  73. package/cache/entities/typeorm-cache.entity.js +110 -0
  74. package/cache/index.d.ts +2 -1
  75. package/cache/index.js +19 -2
  76. package/cache/interfaces/cache-options.interface.d.ts +8 -0
  77. package/cache/providers/index.d.ts +2 -1
  78. package/cache/providers/index.js +2 -1
  79. package/cache/providers/lrucache.provider.d.ts +77 -0
  80. package/cache/providers/lrucache.provider.js +228 -0
  81. package/cache/providers/redis-cache.provider.d.ts +1 -0
  82. package/cache/providers/redis-cache.provider.js +8 -6
  83. package/cache/providers/typeorm-cache.provider.d.ts +211 -0
  84. package/cache/providers/typeorm-cache.provider.js +483 -0
  85. package/common/boilerplate.polyfill.d.ts +1 -0
  86. package/common/boilerplate.polyfill.js +18 -1
  87. package/common/helpers/validation-metadata-helper.d.ts +112 -0
  88. package/common/helpers/validation-metadata-helper.js +164 -0
  89. package/common/index.d.ts +1 -0
  90. package/common/index.js +4 -0
  91. package/decorators/examples/field-i18n.example.d.ts +294 -0
  92. package/decorators/examples/field-i18n.example.js +478 -0
  93. package/decorators/field.decorators.d.ts +95 -3
  94. package/decorators/field.decorators.js +152 -18
  95. package/decorators/transform.decorators.d.ts +0 -2
  96. package/decorators/transform.decorators.js +0 -23
  97. package/decorators/translate.decorator.d.ts +26 -0
  98. package/decorators/translate.decorator.js +26 -1
  99. package/email-log/email-log.constants.d.ts +8 -0
  100. package/email-log/email-log.constants.js +11 -0
  101. package/email-log/email-log.module.d.ts +47 -0
  102. package/email-log/email-log.module.js +140 -0
  103. package/email-log/index.d.ts +11 -0
  104. package/email-log/index.js +48 -0
  105. package/email-log/interfaces/email-log-options.interface.d.ts +61 -0
  106. package/email-log/interfaces/email-log-options.interface.js +134 -0
  107. package/email-log/interfaces/email-log-transport.interface.d.ts +20 -0
  108. package/email-log/interfaces/email-log-transport.interface.js +2 -0
  109. package/email-log/interfaces/index.d.ts +2 -0
  110. package/email-log/interfaces/index.js +18 -0
  111. package/email-log/providers/email-provider.d.ts +42 -0
  112. package/email-log/providers/email-provider.js +127 -0
  113. package/email-log/providers/index.d.ts +1 -0
  114. package/email-log/providers/index.js +17 -0
  115. package/email-log/services/email-log-alert.service.d.ts +46 -0
  116. package/email-log/services/email-log-alert.service.js +162 -0
  117. package/email-log/services/email-log-formatter.service.d.ts +78 -0
  118. package/email-log/services/email-log-formatter.service.js +442 -0
  119. package/email-log/services/email-log-logger.service.d.ts +85 -0
  120. package/email-log/services/email-log-logger.service.js +168 -0
  121. package/email-log/services/email-log-rate-limiter.service.d.ts +42 -0
  122. package/email-log/services/email-log-rate-limiter.service.js +110 -0
  123. package/email-log/services/email-log-transport.service.d.ts +80 -0
  124. package/email-log/services/email-log-transport.service.js +271 -0
  125. package/email-log/services/index.d.ts +5 -0
  126. package/email-log/services/index.js +21 -0
  127. package/email-log/transports/index.d.ts +1 -0
  128. package/email-log/transports/index.js +17 -0
  129. package/email-log/transports/pino-email.transport.d.ts +56 -0
  130. package/email-log/transports/pino-email.transport.js +188 -0
  131. package/email-log/utils/index.d.ts +2 -0
  132. package/email-log/utils/index.js +18 -0
  133. package/email-log/utils/log-level.helper.d.ts +46 -0
  134. package/email-log/utils/log-level.helper.js +74 -0
  135. package/email-log/utils/pino-transport.utils.d.ts +135 -0
  136. package/email-log/utils/pino-transport.utils.js +238 -0
  137. package/file-upload/controllers/file-access.controller.d.ts +23 -0
  138. package/file-upload/controllers/file-access.controller.js +128 -0
  139. package/file-upload/decorators/column.decorator.d.ts +151 -0
  140. package/file-upload/decorators/column.decorator.js +273 -0
  141. package/file-upload/decorators/csv-data.decorator.d.ts +30 -0
  142. package/file-upload/decorators/csv-data.decorator.js +85 -0
  143. package/file-upload/decorators/csv-import.decorator.d.ts +34 -0
  144. package/file-upload/decorators/csv-import.decorator.js +24 -0
  145. package/file-upload/decorators/examples/column-mapping.example.d.ts +76 -0
  146. package/file-upload/decorators/examples/column-mapping.example.js +122 -0
  147. package/file-upload/decorators/excel-data.decorator.d.ts +30 -0
  148. package/file-upload/decorators/excel-data.decorator.js +85 -0
  149. package/file-upload/decorators/file-upload.decorator.d.ts +83 -0
  150. package/file-upload/decorators/file-upload.decorator.js +172 -0
  151. package/file-upload/decorators/index.d.ts +5 -0
  152. package/file-upload/decorators/index.js +38 -0
  153. package/file-upload/decorators/process.decorator.d.ts +40 -0
  154. package/file-upload/decorators/process.decorator.js +52 -0
  155. package/file-upload/decorators/validate-data.decorator.d.ts +91 -0
  156. package/file-upload/decorators/validate-data.decorator.js +39 -0
  157. package/file-upload/dto/create-file.dto.d.ts +24 -0
  158. package/file-upload/dto/create-file.dto.js +112 -0
  159. package/file-upload/dto/find-files.dto.d.ts +15 -0
  160. package/file-upload/dto/find-files.dto.js +76 -0
  161. package/file-upload/dto/index.d.ts +4 -0
  162. package/file-upload/dto/index.js +20 -0
  163. package/file-upload/dto/pagination.dto.d.ts +7 -0
  164. package/file-upload/dto/pagination.dto.js +39 -0
  165. package/file-upload/dto/update-file.dto.d.ts +15 -0
  166. package/file-upload/dto/update-file.dto.js +67 -0
  167. package/file-upload/entities/file-metadata.entity.d.ts +25 -0
  168. package/file-upload/entities/file-metadata.entity.js +76 -0
  169. package/file-upload/entities/file.entity.d.ts +114 -0
  170. package/file-upload/entities/file.entity.js +350 -0
  171. package/file-upload/entities/index.d.ts +2 -0
  172. package/file-upload/entities/index.js +18 -0
  173. package/file-upload/enums/file-type.enum.d.ts +72 -0
  174. package/file-upload/enums/file-type.enum.js +212 -0
  175. package/file-upload/exceptions/file-upload.exception.d.ts +57 -0
  176. package/file-upload/exceptions/file-upload.exception.js +120 -0
  177. package/file-upload/exceptions/index.d.ts +1 -0
  178. package/file-upload/exceptions/index.js +17 -0
  179. package/file-upload/file-upload.module.d.ts +89 -0
  180. package/file-upload/file-upload.module.js +292 -0
  181. package/file-upload/index.d.ts +37 -0
  182. package/file-upload/index.js +77 -0
  183. package/file-upload/interceptors/file-upload.interceptor.d.ts +101 -0
  184. package/file-upload/interceptors/file-upload.interceptor.js +594 -0
  185. package/file-upload/interceptors/index.d.ts +1 -0
  186. package/file-upload/interceptors/index.js +17 -0
  187. package/file-upload/interfaces/custom-file-type.interface.d.ts +72 -0
  188. package/file-upload/interfaces/custom-file-type.interface.js +2 -0
  189. package/file-upload/interfaces/file-buffer.interface.d.ts +72 -0
  190. package/file-upload/interfaces/file-buffer.interface.js +2 -0
  191. package/file-upload/interfaces/file-entity.interface.d.ts +142 -0
  192. package/file-upload/interfaces/file-entity.interface.js +28 -0
  193. package/file-upload/interfaces/file-metadata.interface.d.ts +21 -0
  194. package/file-upload/interfaces/file-metadata.interface.js +2 -0
  195. package/file-upload/interfaces/file-processor.interface.d.ts +93 -0
  196. package/file-upload/interfaces/file-processor.interface.js +2 -0
  197. package/file-upload/interfaces/file-upload-options.interface.d.ts +74 -0
  198. package/file-upload/interfaces/file-upload-options.interface.js +5 -0
  199. package/file-upload/interfaces/index.d.ts +7 -0
  200. package/file-upload/interfaces/index.js +24 -0
  201. package/file-upload/interfaces/processor-options.interface.d.ts +102 -0
  202. package/file-upload/interfaces/processor-options.interface.js +2 -0
  203. package/file-upload/interfaces/storage-provider.interface.d.ts +239 -0
  204. package/file-upload/interfaces/storage-provider.interface.js +2 -0
  205. package/file-upload/interfaces/upload-options.interface.d.ts +19 -0
  206. package/file-upload/interfaces/upload-options.interface.js +2 -0
  207. package/file-upload/processors/csv.processor.d.ts +98 -0
  208. package/file-upload/processors/csv.processor.js +391 -0
  209. package/file-upload/processors/excel.processor.d.ts +130 -0
  210. package/file-upload/processors/excel.processor.js +547 -0
  211. package/file-upload/processors/image.processor.d.ts +199 -0
  212. package/file-upload/processors/image.processor.js +377 -0
  213. package/file-upload/providers/index.d.ts +2 -0
  214. package/file-upload/providers/index.js +18 -0
  215. package/file-upload/providers/local-storage.provider.d.ts +98 -0
  216. package/file-upload/providers/local-storage.provider.js +484 -0
  217. package/file-upload/providers/s3-storage.provider.d.ts +87 -0
  218. package/file-upload/providers/s3-storage.provider.js +455 -0
  219. package/file-upload/services/file-signature-validator.service.d.ts +118 -0
  220. package/file-upload/services/file-signature-validator.service.js +376 -0
  221. package/file-upload/services/file.service.d.ts +193 -0
  222. package/file-upload/services/file.service.js +638 -0
  223. package/file-upload/services/index.d.ts +4 -0
  224. package/file-upload/services/index.js +20 -0
  225. package/file-upload/services/malicious-file-detector.service.d.ts +300 -0
  226. package/file-upload/services/malicious-file-detector.service.js +1234 -0
  227. package/file-upload/services/mime-registry.service.d.ts +47 -0
  228. package/file-upload/services/mime-registry.service.js +167 -0
  229. package/file-upload/utils/checksum.util.d.ts +28 -0
  230. package/file-upload/utils/checksum.util.js +65 -0
  231. package/file-upload/utils/dynamic-import.util.d.ts +54 -0
  232. package/file-upload/utils/dynamic-import.util.js +156 -0
  233. package/file-upload/utils/filename.util.d.ts +59 -0
  234. package/file-upload/utils/filename.util.js +184 -0
  235. package/file-upload/utils/filepath.util.d.ts +70 -0
  236. package/file-upload/utils/filepath.util.js +152 -0
  237. package/file-upload/utils/index.d.ts +4 -0
  238. package/file-upload/utils/index.js +20 -0
  239. package/filters/bad-request.filter.d.ts +9 -0
  240. package/filters/bad-request.filter.js +57 -16
  241. package/http-client/config/http-client.config.d.ts +5 -0
  242. package/http-client/config/http-client.config.js +27 -14
  243. package/http-client/decorators/http-client.decorators.d.ts +7 -28
  244. package/http-client/decorators/http-client.decorators.js +124 -99
  245. package/http-client/entities/http-log.entity.d.ts +0 -20
  246. package/http-client/entities/http-log.entity.js +1 -21
  247. package/http-client/examples/advanced-usage.example.d.ts +4 -5
  248. package/http-client/examples/advanced-usage.example.js +7 -59
  249. package/http-client/examples/axios-config-extended.example.d.ts +17 -0
  250. package/http-client/examples/axios-config-extended.example.js +311 -0
  251. package/http-client/examples/flexible-response-example.d.ts +28 -0
  252. package/http-client/examples/flexible-response-example.js +120 -0
  253. package/http-client/examples/index.d.ts +2 -0
  254. package/http-client/examples/index.js +2 -0
  255. package/http-client/examples/proxy-from-environment.example.d.ts +133 -0
  256. package/http-client/examples/proxy-from-environment.example.js +409 -0
  257. package/http-client/examples/ssl-certificate.example.d.ts +47 -0
  258. package/http-client/examples/ssl-certificate.example.js +432 -0
  259. package/http-client/http-client.module.d.ts +43 -2
  260. package/http-client/http-client.module.js +150 -90
  261. package/http-client/index.d.ts +1 -1
  262. package/http-client/interfaces/api-client-config.interface.d.ts +24 -103
  263. package/http-client/interfaces/http-client-config.interface.d.ts +137 -62
  264. package/http-client/services/api-client-registry.service.d.ts +8 -21
  265. package/http-client/services/api-client-registry.service.js +31 -282
  266. package/http-client/services/circuit-breaker.service.d.ts +69 -2
  267. package/http-client/services/circuit-breaker.service.js +185 -7
  268. package/http-client/services/http-client.service.d.ts +85 -23
  269. package/http-client/services/http-client.service.js +512 -168
  270. package/http-client/services/http-log-query.service.js +0 -13
  271. package/http-client/services/index.d.ts +0 -1
  272. package/http-client/services/index.js +0 -1
  273. package/http-client/services/logging.service.d.ts +69 -16
  274. package/http-client/services/logging.service.js +290 -170
  275. package/http-client/utils/call-stack-extractor.util.d.ts +26 -0
  276. package/http-client/utils/call-stack-extractor.util.js +35 -0
  277. package/http-client/utils/context-extractor.util.d.ts +2 -0
  278. package/http-client/utils/context-extractor.util.js +17 -3
  279. package/http-client/utils/curl-generator.util.js +2 -5
  280. package/http-client/utils/index.d.ts +2 -0
  281. package/http-client/utils/index.js +2 -0
  282. package/http-client/utils/proxy-environment.util.d.ts +42 -0
  283. package/http-client/utils/proxy-environment.util.js +154 -0
  284. package/http-client/utils/retry-recorder.util.d.ts +0 -4
  285. package/http-client/utils/retry-recorder.util.js +2 -27
  286. package/http-client/utils/sanitize.util.d.ts +58 -0
  287. package/http-client/utils/sanitize.util.js +188 -0
  288. package/http-client/utils/security-validator.util.d.ts +118 -0
  289. package/http-client/utils/security-validator.util.js +354 -0
  290. package/index.d.ts +4 -1
  291. package/index.js +6 -1
  292. package/interceptors/translation-interceptor.service.d.ts +7 -0
  293. package/interceptors/translation-interceptor.service.js +40 -8
  294. package/ip-filter/constants.d.ts +21 -0
  295. package/ip-filter/constants.js +24 -0
  296. package/ip-filter/decorators/index.d.ts +1 -0
  297. package/ip-filter/decorators/index.js +17 -0
  298. package/ip-filter/decorators/ip-filter.decorator.d.ts +58 -0
  299. package/ip-filter/decorators/ip-filter.decorator.js +79 -0
  300. package/ip-filter/guards/index.d.ts +1 -0
  301. package/ip-filter/guards/index.js +17 -0
  302. package/ip-filter/guards/ip-filter.guard.d.ts +62 -0
  303. package/ip-filter/guards/ip-filter.guard.js +174 -0
  304. package/ip-filter/index.d.ts +7 -0
  305. package/ip-filter/index.js +23 -0
  306. package/ip-filter/interfaces/index.d.ts +4 -0
  307. package/ip-filter/interfaces/index.js +20 -0
  308. package/ip-filter/interfaces/ip-filter-async-options.interface.d.ts +15 -0
  309. package/ip-filter/interfaces/ip-filter-async-options.interface.js +2 -0
  310. package/ip-filter/interfaces/ip-filter-metadata.interface.d.ts +26 -0
  311. package/ip-filter/interfaces/ip-filter-metadata.interface.js +2 -0
  312. package/ip-filter/interfaces/ip-filter-options.interface.d.ts +34 -0
  313. package/ip-filter/interfaces/ip-filter-options.interface.js +2 -0
  314. package/ip-filter/interfaces/ip-rule.interface.d.ts +36 -0
  315. package/ip-filter/interfaces/ip-rule.interface.js +2 -0
  316. package/ip-filter/ip-filter.module.d.ts +55 -0
  317. package/ip-filter/ip-filter.module.js +105 -0
  318. package/ip-filter/services/index.d.ts +1 -0
  319. package/ip-filter/services/index.js +17 -0
  320. package/ip-filter/services/ip-filter.service.d.ts +92 -0
  321. package/ip-filter/services/ip-filter.service.js +238 -0
  322. package/ip-filter/utils/index.d.ts +1 -0
  323. package/ip-filter/utils/index.js +17 -0
  324. package/ip-filter/utils/ip-utils.d.ts +61 -0
  325. package/ip-filter/utils/ip-utils.js +162 -0
  326. package/package.json +34 -29
  327. package/providers/context.provider.d.ts +9 -0
  328. package/providers/context.provider.js +13 -0
  329. package/redis-lock/comprehensive-lock-cleanup.service.d.ts +94 -0
  330. package/redis-lock/comprehensive-lock-cleanup.service.js +253 -0
  331. package/redis-lock/index.d.ts +2 -0
  332. package/redis-lock/index.js +5 -1
  333. package/redis-lock/lock-heartbeat.service.d.ts +80 -0
  334. package/redis-lock/lock-heartbeat.service.js +232 -0
  335. package/redis-lock/redis-lock.module.d.ts +6 -0
  336. package/redis-lock/redis-lock.module.js +136 -77
  337. package/redis-lock/redis-lock.service.d.ts +31 -0
  338. package/redis-lock/redis-lock.service.js +124 -17
  339. package/setup/bootstrap.setup.d.ts +2 -1
  340. package/setup/bootstrap.setup.js +3 -2
  341. package/setup/index.d.ts +1 -0
  342. package/setup/index.js +1 -0
  343. package/setup/run-in-mode.decorator.d.ts +56 -0
  344. package/setup/run-in-mode.decorator.js +92 -0
  345. package/setup/schedule.decorator.d.ts +1 -0
  346. package/setup/schedule.decorator.js +28 -13
  347. package/setup/worker.decorator.js +10 -1
  348. package/shared/index.d.ts +1 -1
  349. package/shared/index.js +1 -1
  350. package/shared/{serviceRegistryModule.js → service-registry.module.js} +28 -17
  351. package/shared/services/api-config.service.d.ts +41 -0
  352. package/shared/services/api-config.service.js +175 -8
  353. package/shared/services/index.d.ts +0 -1
  354. package/shared/services/index.js +0 -1
  355. package/validators/custom-validate.validator.d.ts +1 -0
  356. package/validators/custom-validate.validator.js +1 -0
  357. package/validators/file-mimetype.validator.d.ts +0 -2
  358. package/validators/file-mimetype.validator.js +4 -6
  359. package/validators/is-exists.validator.d.ts +15 -6
  360. package/validators/is-exists.validator.js +8 -7
  361. package/validators/is-unique.validator.d.ts +22 -7
  362. package/validators/is-unique.validator.js +41 -17
  363. package/vault/vault-config.service.js +1 -1
  364. package/cache/providers/memory-cache.provider.d.ts +0 -49
  365. package/cache/providers/memory-cache.provider.js +0 -197
  366. package/http-client/services/cache.service.d.ts +0 -76
  367. package/http-client/services/cache.service.js +0 -333
  368. package/shared/services/validator.service.d.ts +0 -3
  369. package/shared/services/validator.service.js +0 -20
  370. /package/shared/{serviceRegistryModule.d.ts → service-registry.module.d.ts} +0 -0
@@ -1,37 +1,119 @@
1
1
  import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
- import { CacheOptions } from '../../cache/interfaces/cache-options.interface';
3
2
  import { LogCleanupConfig } from '../services/log-cleanup.service';
3
+ import { SSRFProtectionConfig, URLValidationConfig } from '../utils/security-validator.util';
4
+ import type { AgentOptions } from 'https';
5
+ /**
6
+ * SSL/TLS 证书配置
7
+ * 兼容 Node.js https.Agent 的选项
8
+ * 参考: https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
9
+ */
10
+ export interface SslCertificateConfig extends Partial<Omit<AgentOptions, 'host' | 'port' | 'path'>> {
11
+ /**
12
+ * 是否禁用证书验证(仅用于开发/测试环境)
13
+ * 警告:设置为 true 会使连接不安全,生产环境严禁使用
14
+ */
15
+ rejectUnauthorized?: boolean;
16
+ /**
17
+ * CA 证书内容(PEM 格式)
18
+ * 可以是单个证书或多个证书的字符串
19
+ */
20
+ ca?: string | string[] | Buffer;
21
+ /**
22
+ * 客户端证书内容(PEM 格式)
23
+ */
24
+ cert?: string | string[] | Buffer;
25
+ /**
26
+ * 客户端私钥内容(PEM 格式)
27
+ */
28
+ key?: string | string[] | Buffer;
29
+ /**
30
+ * 私钥密码
31
+ */
32
+ passphrase?: string;
33
+ /**
34
+ * 服务器名称(用于 SNI)
35
+ */
36
+ servername?: string;
37
+ /**
38
+ * 支持的 TLS 版本
39
+ */
40
+ minVersion?: 'TLSv1' | 'TLSv1.1' | 'TLSv1.2' | 'TLSv1.3';
41
+ maxVersion?: 'TLSv1' | 'TLSv1.1' | 'TLSv1.2' | 'TLSv1.3';
42
+ /**
43
+ * 支持的加密套件
44
+ */
45
+ ciphers?: string;
46
+ /**
47
+ * 是否支持 DH 参数
48
+ */
49
+ dhparam?: string | Buffer;
50
+ /**
51
+ * 是否使用安全 renegotiation
52
+ */
53
+ secureOptions?: number;
54
+ }
55
+ /**
56
+ * Axios 原生配置透传
57
+ * 基于 AxiosRequestConfig,排除已在 HttpClientConfig 中定义的字段
58
+ *
59
+ * 使用方式:
60
+ * - 直接传 Axios 原生配置对象
61
+ * - 类型安全,支持所有 Axios 配置项
62
+ * - ssl 配置会被自动转换为 httpsAgent
63
+ */
64
+ export type AxiosNativeConfig = Omit<AxiosRequestConfig, 'baseURL' | 'timeout' | 'proxy' | 'url' | 'method' | 'data' | 'headers' | 'params'> & {
65
+ /**
66
+ * SSL/TLS 证书配置(简化版)
67
+ * 会自动转换为 httpsAgent,优先级高于直接指定的 httpsAgent
68
+ */
69
+ ssl?: SslCertificateConfig;
70
+ };
4
71
  /**
5
72
  * HTTP客户端配置接口
6
73
  * 基于Spring Boot的@ConfigurationProperties设计理念
74
+ * 所有字段都是可选的,模块会使用合理的默认值
7
75
  */
8
76
  export interface HttpClientConfig {
9
77
  /** 基础配置 */
10
78
  baseURL?: string;
11
79
  timeout?: number;
12
80
  /** 重试配置 */
13
- retry?: RetryConfig;
81
+ retry?: Partial<RetryConfig>;
14
82
  /** 熔断器配置 */
15
- circuitBreaker?: CircuitBreakerConfig;
16
- /** 缓存配置 */
17
- cache?: HttpCacheConfig;
83
+ circuitBreaker?: Partial<CircuitBreakerConfig>;
18
84
  /** 代理配置 */
19
- proxy?: ProxyConfig;
85
+ proxy?: Partial<ProxyConfig>;
20
86
  /** 日志配置 */
21
- logging?: LoggingConfig;
87
+ logging?: Partial<LoggingConfig>;
22
88
  /** 日志清理配置 */
23
- logCleanup?: LogCleanupConfig;
89
+ logCleanup?: Partial<LogCleanupConfig>;
24
90
  /** 拦截器配置 */
25
- interceptors?: InterceptorConfig;
91
+ interceptors?: Partial<InterceptorConfig>;
26
92
  /** 连接池配置 */
27
- connectionPool?: ConnectionPoolConfig;
93
+ connectionPool?: Partial<ConnectionPoolConfig>;
94
+ /** 安全配置 */
95
+ security?: {
96
+ /** URL验证配置 */
97
+ urlValidation?: Partial<URLValidationConfig>;
98
+ /** SSRF防护配置 */
99
+ ssrfProtection?: Partial<SSRFProtectionConfig>;
100
+ /** 是否启用安全验证 */
101
+ enabled?: boolean;
102
+ };
103
+ /**
104
+ * Axios 原生配置透传
105
+ * 用于直接传递 Axios 支持的任何配置项,提供最大灵活性
106
+ * 优先级低于上述显式配置,会进行深度合并
107
+ */
108
+ axiosConfig?: AxiosNativeConfig;
28
109
  }
29
110
  /**
30
111
  * 重试配置
31
112
  * 基于axios-retry库的配置
113
+ * 所有字段都是可选的
32
114
  */
33
115
  export interface RetryConfig {
34
- enabled: boolean;
116
+ enabled?: boolean;
35
117
  retries?: number;
36
118
  retryDelay?: (retryCount: number) => number;
37
119
  retryCondition?: (error: any) => boolean;
@@ -41,82 +123,80 @@ export interface RetryConfig {
41
123
  /**
42
124
  * 熔断器配置
43
125
  * 类似Spring Cloud CircuitBreaker
126
+ * 所有字段都是可选的
44
127
  */
45
128
  export interface CircuitBreakerConfig {
46
- enabled: boolean;
47
- failureThreshold: number;
48
- recoveryTimeoutMs: number;
49
- monitoringPeriodMs: number;
50
- minimumThroughputThreshold: number;
51
- countHalfOpenCalls: boolean;
52
- }
53
- /**
54
- * HTTP缓存配置
55
- * 集成现有的三层缓存架构
56
- */
57
- export interface HttpCacheConfig {
58
- enabled: boolean;
59
- /** 缓存选项,使用core中的CacheOptions */
60
- options?: Omit<CacheOptions, 'ttl' | 'namespace'>;
61
- /** 默认TTL(毫秒) */
62
- defaultTtl?: number;
63
- /** 可缓存的方法 */
64
- cacheableMethods: string[];
65
- /** 可缓存的状态码 */
66
- cacheableStatusCodes: number[];
67
- /** 自定义缓存键生成器 */
68
- keyGenerator?: (config: AxiosRequestConfig) => string;
129
+ enabled?: boolean;
130
+ failureThreshold?: number;
131
+ recoveryTimeoutMs?: number;
132
+ monitoringPeriodMs?: number;
133
+ minimumThroughputThreshold?: number;
134
+ countHalfOpenCalls?: boolean;
69
135
  }
70
136
  /**
71
137
  * 代理配置
138
+ * 所有字段都是可选的
72
139
  */
73
140
  export interface ProxyConfig {
74
- enabled: boolean;
141
+ enabled?: boolean;
142
+ /** 是否从环境变量读取代理配置 (HTTP_PROXY, HTTPS_PROXY, NO_PROXY) */
143
+ fromEnvironment?: boolean;
144
+ /** 手动指定的代理主机 (当 fromEnvironment 为 false 时使用) */
75
145
  host?: string;
146
+ /** 手动指定的代理端口 (当 fromEnvironment 为 false 时使用) */
76
147
  port?: number;
148
+ /** 代理协议 */
77
149
  protocol?: 'http' | 'https';
150
+ /** 代理认证信息 */
78
151
  auth?: {
79
- username: string;
80
- password: string;
152
+ username?: string;
153
+ password?: string;
81
154
  };
82
155
  }
83
156
  /**
84
157
  * 日志配置
85
158
  * 类似Spring Boot的logging配置
159
+ * 所有字段都是可选的
86
160
  */
87
161
  export interface LoggingConfig {
88
- enabled: boolean;
89
- logRequests: boolean;
90
- logResponses: boolean;
91
- logErrors: boolean;
92
- logHeaders: boolean;
93
- logBody: boolean;
94
- maxBodyLength: number;
95
- sanitizeHeaders: string[];
96
- logLevel: 'debug' | 'info' | 'warn' | 'error';
162
+ enabled?: boolean;
163
+ logRequests?: boolean;
164
+ logResponses?: boolean;
165
+ logErrors?: boolean;
166
+ logHeaders?: boolean;
167
+ logBody?: boolean;
168
+ maxBodyLength?: number;
169
+ /**
170
+ * 脱敏配置
171
+ * 敏感字段列表,统一适用于 headers、body、query string
172
+ * 例如:['password', 'token', 'secret', 'apiKey']
173
+ */
174
+ sanitize?: string[];
175
+ logLevel?: 'debug' | 'info' | 'warn' | 'error';
97
176
  databaseLogging?: {
98
- enabled: boolean;
99
- dataSource: string;
100
- tableName: string;
177
+ enabled?: boolean;
178
+ dataSource?: string;
101
179
  };
102
180
  }
103
181
  /**
104
182
  * 拦截器配置
183
+ * 所有字段都是可选的
105
184
  */
106
185
  export interface InterceptorConfig {
107
- requestInterceptors: string[];
108
- responseInterceptors: string[];
109
- errorInterceptors: string[];
186
+ requestInterceptors?: string[];
187
+ responseInterceptors?: string[];
188
+ errorInterceptors?: string[];
110
189
  }
111
190
  /**
112
191
  * 连接池配置
192
+ * 所有字段都是可选的
113
193
  */
114
194
  export interface ConnectionPoolConfig {
115
- enabled: boolean;
116
- maxSockets: number;
117
- maxFreeSockets: number;
118
- timeoutMs: number;
119
- keepAlive: boolean;
195
+ enabled?: boolean;
196
+ maxSockets?: number;
197
+ maxFreeSockets?: number;
198
+ timeoutMs?: number;
199
+ keepAlive?: boolean;
120
200
  }
121
201
  /**
122
202
  * HTTP请求上下文
@@ -175,9 +255,4 @@ export interface HttpStats {
175
255
  requestsByMethod: Record<HttpMethod, number>;
176
256
  requestsByStatus: Record<number, number>;
177
257
  circuitBreakerStats: Record<string, any>;
178
- cacheStats: {
179
- hits: number;
180
- misses: number;
181
- hitRate: number;
182
- };
183
258
  }
@@ -1,24 +1,22 @@
1
- import { ApiClientConfig, ApiClientInstanceConfig, ApiClientRegistryConfig, AuthType, OAuth2Config, ResponseTransformerConfig } from '../interfaces/api-client-config.interface';
2
- import { HttpClientService } from './http-client.service';
1
+ import { ApiClientConfig, ApiClientInstanceConfig, ApiClientRegistryConfig, AuthType, ResponseTransformerConfig } from '../interfaces/api-client-config.interface';
3
2
  import { HttpCircuitBreakerService } from './circuit-breaker.service';
4
3
  import { HttpLoggingService } from './logging.service';
5
- import { HttpCacheService } from './cache.service';
6
- export { ApiClientInstanceConfig, AuthType, OAuth2Config, ResponseTransformerConfig, };
4
+ export { ApiClientInstanceConfig, AuthType, ResponseTransformerConfig };
7
5
  /**
8
6
  * API客户端注册服务
7
+ * 负责管理多个 HttpClientService 实例
9
8
  */
10
9
  export declare class ApiClientRegistryService {
11
- private readonly httpClientService;
12
10
  private readonly circuitBreakerService;
13
11
  private readonly loggingService;
14
- private readonly cacheService;
15
12
  private readonly logger;
16
13
  private readonly clients;
17
14
  private readonly clientConfigs;
18
15
  private readonly globalDefaults;
19
- constructor(httpClientService: HttpClientService, circuitBreakerService: HttpCircuitBreakerService, loggingService: HttpLoggingService, cacheService: HttpCacheService, globalConfig?: ApiClientRegistryConfig);
16
+ constructor(circuitBreakerService: HttpCircuitBreakerService, loggingService: HttpLoggingService, globalConfig?: ApiClientRegistryConfig);
20
17
  /**
21
18
  * 创建API客户端实例
19
+ * 使用 HttpClientService.createApiClient 静态方法创建
22
20
  */
23
21
  createClient<T = any>(config: ApiClientInstanceConfig): T;
24
22
  /**
@@ -76,21 +74,10 @@ export declare class ApiClientRegistryService {
76
74
  }>;
77
75
  }>;
78
76
  /**
79
- * 创建Axios实例
77
+ * 深度合并配置(已废弃,不再需要)
78
+ * @deprecated 配置结构简化后不再需要此方法
80
79
  */
81
- private createAxiosInstance;
82
- /**
83
- * 应用鉴权配置
84
- */
85
- private applyAuthentication;
86
- /**
87
- * 应用响应转换器
88
- */
89
- private applyResponseTransformer;
90
- /**
91
- * 根据路径提取数据
92
- */
93
- private extractDataByPath;
80
+ private deepMergeConfigs;
94
81
  /**
95
82
  * 合并环境特定配置
96
83
  */
@@ -21,25 +21,19 @@ var ApiClientRegistryService_1;
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.ApiClientRegistryService = exports.AuthType = void 0;
23
23
  const common_1 = require("@nestjs/common");
24
- const axios_1 = require("axios");
25
- const axios_retry_1 = require("axios-retry");
26
24
  const api_client_config_interface_1 = require("../interfaces/api-client-config.interface");
27
25
  Object.defineProperty(exports, "AuthType", { enumerable: true, get: function () { return api_client_config_interface_1.AuthType; } });
28
26
  const http_client_service_1 = require("./http-client.service");
29
27
  const circuit_breaker_service_1 = require("./circuit-breaker.service");
30
28
  const logging_service_1 = require("./logging.service");
31
- const cache_service_1 = require("./cache.service");
32
- const context_extractor_util_1 = require("../utils/context-extractor.util");
33
- const utils_1 = require("../../common/utils");
34
29
  /**
35
30
  * API客户端注册服务
31
+ * 负责管理多个 HttpClientService 实例
36
32
  */
37
33
  let ApiClientRegistryService = ApiClientRegistryService_1 = class ApiClientRegistryService {
38
- constructor(httpClientService, circuitBreakerService, loggingService, cacheService, globalConfig = {}) {
39
- this.httpClientService = httpClientService;
34
+ constructor(circuitBreakerService, loggingService, globalConfig = {}) {
40
35
  this.circuitBreakerService = circuitBreakerService;
41
36
  this.loggingService = loggingService;
42
- this.cacheService = cacheService;
43
37
  this.logger = new common_1.Logger(ApiClientRegistryService_1.name);
44
38
  this.clients = new Map();
45
39
  this.clientConfigs = new Map();
@@ -53,7 +47,7 @@ let ApiClientRegistryService = ApiClientRegistryService_1 = class ApiClientRegis
53
47
  logHeaders: true,
54
48
  logBody: true,
55
49
  maxBodyLength: 10000,
56
- sanitizeHeaders: ['authorization', 'api-key'],
50
+ sanitize: ['authorization', 'api-key'],
57
51
  logLevel: 'info',
58
52
  },
59
53
  timeout: 30000,
@@ -65,6 +59,7 @@ let ApiClientRegistryService = ApiClientRegistryService_1 = class ApiClientRegis
65
59
  }
66
60
  /**
67
61
  * 创建API客户端实例
62
+ * 使用 HttpClientService.createApiClient 静态方法创建
68
63
  */
69
64
  createClient(config) {
70
65
  const clientName = config.name;
@@ -75,15 +70,30 @@ let ApiClientRegistryService = ApiClientRegistryService_1 = class ApiClientRegis
75
70
  }
76
71
  // 合并环境特定配置
77
72
  const finalConfig = this.mergeEnvironmentConfig(config);
78
- // 创建Axios实例
79
- const axiosInstance = this.createAxiosInstance(finalConfig);
80
- // 创建API客户端
81
- const client = new ApiClientInstance(clientName, finalConfig, axiosInstance, this.httpClientService, this.loggingService, this.cacheService);
73
+ // 构建 HttpClient 配置
74
+ // 1. 从全局默认配置开始
75
+ // 2. 合并 ApiClient 的 httpConfig
76
+ // 3. 应用 ApiClient 特有的 retry 配置(兼容旧代码)
77
+ const mergedHttpConfig = Object.assign(Object.assign({}, this.globalDefaults.globalDefaults), finalConfig.httpConfig);
78
+ // 兼容:如果 ApiClientConfig 顶层有 retry 配置,合并到 httpConfig.retry
79
+ if (finalConfig.retry) {
80
+ mergedHttpConfig.retry = Object.assign(Object.assign({}, mergedHttpConfig.retry), finalConfig.retry);
81
+ }
82
+ // 使用静态工厂方法创建 HttpClientService 实例
83
+ const httpClient = http_client_service_1.HttpClientService.createApiClient({
84
+ circuitBreakerService: this.circuitBreakerService,
85
+ loggingService: this.loggingService,
86
+ }, {
87
+ name: clientName,
88
+ baseURL: finalConfig.baseURL,
89
+ httpConfig: mergedHttpConfig,
90
+ auth: finalConfig.auth,
91
+ });
82
92
  // 存储客户端和配置
83
- this.clients.set(clientName, client);
93
+ this.clients.set(clientName, httpClient);
84
94
  this.clientConfigs.set(clientName, finalConfig);
85
95
  this.logger.log(`Created API client: ${clientName}`);
86
- return client;
96
+ return httpClient;
87
97
  }
88
98
  /**
89
99
  * 获取已注册的客户端
@@ -210,180 +220,11 @@ let ApiClientRegistryService = ApiClientRegistryService_1 = class ApiClientRegis
210
220
  });
211
221
  }
212
222
  /**
213
- * 创建Axios实例
214
- */
215
- createAxiosInstance(config) {
216
- var _a, _b, _c, _d, _e, _f;
217
- const axiosConfig = {
218
- baseURL: config.baseURL,
219
- timeout: ((_a = config.httpConfig) === null || _a === void 0 ? void 0 : _a.timeout) || 30000,
220
- headers: Object.assign({ 'Content-Type': 'application/json', 'User-Agent': `${config.name}/1.0.0` }, config.defaultHeaders),
221
- params: config.defaultParams,
222
- };
223
- const instance = axios_1.default.create(axiosConfig);
224
- const clientName = config.name; // Capture client name for use in closures
225
- // 配置请求拦截器
226
- instance.interceptors.request.use((config) => {
227
- // 添加鉴权信息 - for now, skip async authentication to avoid type issues
228
- const authenticatedConfig = config;
229
- // Add simple auth headers for basic cases
230
- if (config.auth) {
231
- switch (config.auth.type) {
232
- case api_client_config_interface_1.AuthType.BEARER_TOKEN:
233
- const bearerConfig = config.auth.config;
234
- authenticatedConfig.headers = authenticatedConfig.headers || {};
235
- authenticatedConfig.headers['Authorization'] =
236
- `Bearer ${bearerConfig.token}`;
237
- break;
238
- case api_client_config_interface_1.AuthType.API_KEY:
239
- const apiKeyConfig = config.auth.config;
240
- if (apiKeyConfig.location === 'header') {
241
- const headerName = apiKeyConfig.name || 'X-API-Key';
242
- const value = apiKeyConfig.prefix
243
- ? `${apiKeyConfig.prefix} ${apiKeyConfig.key}`
244
- : apiKeyConfig.key;
245
- authenticatedConfig.headers = authenticatedConfig.headers || {};
246
- authenticatedConfig.headers[headerName] = value;
247
- }
248
- break;
249
- }
250
- }
251
- // 添加请求ID和上下文信息
252
- const context = context_extractor_util_1.ContextExtractor.getHttpContext();
253
- const requestId = context.requestId || (0, utils_1.generateRequestId)();
254
- authenticatedConfig.headers = authenticatedConfig.headers || {};
255
- authenticatedConfig.headers['X-Request-ID'] = requestId;
256
- if (context.userId) {
257
- authenticatedConfig.headers['X-User-ID'] = context.userId;
258
- }
259
- // 添加API标识
260
- authenticatedConfig.headers['X-API-Client'] = clientName;
261
- return authenticatedConfig;
262
- }, (error) => {
263
- this.logger.error(`[${clientName}] Request interceptor error`, error);
264
- return Promise.reject(error);
265
- });
266
- // 配置响应拦截器
267
- instance.interceptors.response.use((response) => {
268
- // 应用响应转换器
269
- return this.applyResponseTransformer(response, config.responseTransformer);
270
- }, (error) => {
271
- var _a;
272
- // 应用错误转换器
273
- if ((_a = config.responseTransformer) === null || _a === void 0 ? void 0 : _a.error) {
274
- return config.responseTransformer.error(error);
275
- }
276
- return Promise.reject(error);
277
- });
278
- // 配置axios-retry
279
- if (((_b = config.retry) === null || _b === void 0 ? void 0 : _b.enabled) !== false &&
280
- this.globalDefaults.enableGlobalRetry) {
281
- (0, axios_retry_1.default)(instance, {
282
- retries: ((_c = config.retry) === null || _c === void 0 ? void 0 : _c.retries) ||
283
- ((_e = (_d = this.globalDefaults.globalDefaults) === null || _d === void 0 ? void 0 : _d.retry) === null || _e === void 0 ? void 0 : _e.retries) ||
284
- 3,
285
- retryDelay: (retryCount) => Math.pow(2, retryCount) * 1000,
286
- retryCondition: ((_f = config.retry) === null || _f === void 0 ? void 0 : _f.retryCondition) ||
287
- ((error) => {
288
- if (!error.response)
289
- return true;
290
- const status = error.response.status;
291
- return status >= 500 || status === 429;
292
- }),
293
- shouldResetTimeout: true,
294
- onRetry: (retryCount, error, requestConfig) => {
295
- var _a;
296
- this.logger.warn(`[${config.name}] Retrying request (attempt ${retryCount}): ${(_a = requestConfig.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()} ${requestConfig.url}`);
297
- },
298
- });
299
- }
300
- return instance;
301
- }
302
- /**
303
- * 应用鉴权配置
304
- */
305
- applyAuthentication(config, auth) {
306
- return __awaiter(this, void 0, void 0, function* () {
307
- if (!auth) {
308
- return config;
309
- }
310
- const authenticatedConfig = Object.assign({}, config);
311
- switch (auth.type) {
312
- case api_client_config_interface_1.AuthType.NONE:
313
- break;
314
- case api_client_config_interface_1.AuthType.API_KEY:
315
- const apiKeyConfig = auth.config;
316
- if (apiKeyConfig.location === 'header') {
317
- const headerName = apiKeyConfig.name || 'X-API-Key';
318
- const value = apiKeyConfig.prefix
319
- ? `${apiKeyConfig.prefix} ${apiKeyConfig.key}`
320
- : apiKeyConfig.key;
321
- authenticatedConfig.headers = Object.assign(Object.assign({}, authenticatedConfig.headers), { [headerName]: value });
322
- }
323
- else if (apiKeyConfig.location === 'query') {
324
- const paramName = apiKeyConfig.name || 'api_key';
325
- authenticatedConfig.params = Object.assign(Object.assign({}, authenticatedConfig.params), { [paramName]: apiKeyConfig.key });
326
- }
327
- break;
328
- case api_client_config_interface_1.AuthType.BEARER_TOKEN:
329
- const bearerConfig = auth.config;
330
- const scheme = bearerConfig.scheme || 'Bearer';
331
- authenticatedConfig.headers = Object.assign(Object.assign({}, authenticatedConfig.headers), { Authorization: `${scheme} ${bearerConfig.token}` });
332
- break;
333
- case api_client_config_interface_1.AuthType.BASIC_AUTH:
334
- const basicConfig = auth.config;
335
- const credentials = Buffer.from(`${basicConfig.username}:${basicConfig.password}`).toString('base64');
336
- authenticatedConfig.headers = Object.assign(Object.assign({}, authenticatedConfig.headers), { Authorization: `Basic ${credentials}` });
337
- break;
338
- case api_client_config_interface_1.AuthType.OAUTH2:
339
- const oauthConfig = auth.config;
340
- // OAuth2实现需要异步获取token
341
- // 这里简化处理,实际项目中可能需要更复杂的逻辑
342
- authenticatedConfig.headers = Object.assign(Object.assign({}, authenticatedConfig.headers), { Authorization: `Bearer ${oauthConfig.clientSecret}` });
343
- break;
344
- case api_client_config_interface_1.AuthType.CUSTOM:
345
- const customConfig = auth.config;
346
- return yield customConfig.authenticator(authenticatedConfig);
347
- }
348
- return authenticatedConfig;
349
- });
350
- }
351
- /**
352
- * 应用响应转换器
353
- */
354
- applyResponseTransformer(response, transformer) {
355
- if (!transformer) {
356
- return response;
357
- }
358
- // 应用成功响应转换器
359
- if (transformer.success) {
360
- response.data = transformer.success(response);
361
- }
362
- // 应用数据路径提取
363
- if (transformer.dataPath) {
364
- response.data = this.extractDataByPath(response.data, transformer.dataPath);
365
- }
366
- // 应用响应验证
367
- if (transformer.validateResponse && transformer.validator) {
368
- if (!transformer.validator(response.data)) {
369
- throw new Error(`Response validation failed for ${transformer.dataPath}`);
370
- }
371
- }
372
- return response;
373
- }
374
- /**
375
- * 根据路径提取数据
223
+ * 深度合并配置(已废弃,不再需要)
224
+ * @deprecated 配置结构简化后不再需要此方法
376
225
  */
377
- extractDataByPath(data, path) {
378
- const keys = path.split('.');
379
- let current = data;
380
- for (const key of keys) {
381
- if (current === null || current === undefined) {
382
- return undefined;
383
- }
384
- current = current[key];
385
- }
386
- return current;
226
+ deepMergeConfigs(defaults, userConfig) {
227
+ return Object.assign(Object.assign({}, defaults), userConfig);
387
228
  }
388
229
  /**
389
230
  * 合并环境特定配置
@@ -398,98 +239,6 @@ let ApiClientRegistryService = ApiClientRegistryService_1 = class ApiClientRegis
398
239
  exports.ApiClientRegistryService = ApiClientRegistryService;
399
240
  exports.ApiClientRegistryService = ApiClientRegistryService = ApiClientRegistryService_1 = __decorate([
400
241
  (0, common_1.Injectable)(),
401
- __metadata("design:paramtypes", [http_client_service_1.HttpClientService,
402
- circuit_breaker_service_1.HttpCircuitBreakerService,
403
- logging_service_1.HttpLoggingService,
404
- cache_service_1.HttpCacheService, Object])
242
+ __metadata("design:paramtypes", [circuit_breaker_service_1.HttpCircuitBreakerService,
243
+ logging_service_1.HttpLoggingService, Object])
405
244
  ], ApiClientRegistryService);
406
- /**
407
- * API客户端实例实现
408
- */
409
- class ApiClientInstance {
410
- constructor(name, config, axiosInstance, httpClientService, loggingService, cacheService) {
411
- this.name = name;
412
- this.config = config;
413
- this.axiosInstance = axiosInstance;
414
- this.httpClientService = httpClientService;
415
- this.loggingService = loggingService;
416
- this.cacheService = cacheService;
417
- this.stats = {
418
- totalRequests: 0,
419
- successfulRequests: 0,
420
- failedRequests: 0,
421
- totalResponseTime: 0,
422
- averageResponseTime: 0,
423
- };
424
- }
425
- get(url, config) {
426
- return __awaiter(this, void 0, void 0, function* () {
427
- return this.request(Object.assign(Object.assign({}, config), { method: 'GET', url }));
428
- });
429
- }
430
- post(url, data, config) {
431
- return __awaiter(this, void 0, void 0, function* () {
432
- return this.request(Object.assign(Object.assign({}, config), { method: 'POST', url, data }));
433
- });
434
- }
435
- put(url, data, config) {
436
- return __awaiter(this, void 0, void 0, function* () {
437
- return this.request(Object.assign(Object.assign({}, config), { method: 'PUT', url, data }));
438
- });
439
- }
440
- patch(url, data, config) {
441
- return __awaiter(this, void 0, void 0, function* () {
442
- return this.request(Object.assign(Object.assign({}, config), { method: 'PATCH', url, data }));
443
- });
444
- }
445
- delete(url, config) {
446
- return __awaiter(this, void 0, void 0, function* () {
447
- return this.request(Object.assign(Object.assign({}, config), { method: 'DELETE', url }));
448
- });
449
- }
450
- request(config) {
451
- return __awaiter(this, void 0, void 0, function* () {
452
- const startTime = Date.now();
453
- this.stats.totalRequests++;
454
- try {
455
- const response = yield this.axiosInstance.request(config);
456
- // 更新统计信息
457
- const responseTime = Date.now() - startTime;
458
- this.updateStats(true, responseTime);
459
- return response.data;
460
- }
461
- catch (error) {
462
- // 更新统计信息
463
- const responseTime = Date.now() - startTime;
464
- this.updateStats(false, responseTime);
465
- throw error;
466
- }
467
- });
468
- }
469
- getStats() {
470
- return Object.assign({}, this.stats);
471
- }
472
- resetStats() {
473
- this.stats.totalRequests = 0;
474
- this.stats.successfulRequests = 0;
475
- this.stats.failedRequests = 0;
476
- this.stats.totalResponseTime = 0;
477
- this.stats.averageResponseTime = 0;
478
- }
479
- updateStats(success, responseTime) {
480
- if (success) {
481
- this.stats.successfulRequests++;
482
- }
483
- else {
484
- this.stats.failedRequests++;
485
- }
486
- this.stats.totalResponseTime += responseTime;
487
- this.stats.averageResponseTime =
488
- this.stats.totalResponseTime / this.stats.totalRequests;
489
- // 响应时间警告
490
- if (this.config.responseTimeWarningThreshold &&
491
- responseTime > this.config.responseTimeWarningThreshold) {
492
- console.warn(`[API Client ${this.name}] Slow response detected: ${responseTime}ms for ${this.axiosInstance.defaults.baseURL}`);
493
- }
494
- }
495
- }