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

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 (235) 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 -0
  105. package/common/boilerplate.polyfill.js +17 -0
  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/index.js +8 -0
  183. package/interceptors/translation-interceptor.service.js +5 -0
  184. package/package.json +1 -1
  185. package/providers/context.provider.js +2 -0
  186. package/providers/generator.provider.d.ts +4 -0
  187. package/providers/generator.provider.js +4 -0
  188. package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
  189. package/redis-lock/examples/lock-strategy.examples.js +130 -15
  190. package/redis-lock/index.js +3 -0
  191. package/redis-lock/redis-lock.decorator.d.ts +101 -0
  192. package/redis-lock/redis-lock.decorator.js +120 -0
  193. package/redis-lock/redis-lock.module.d.ts +60 -0
  194. package/redis-lock/redis-lock.module.js +46 -0
  195. package/redis-lock/redis-lock.service.d.ts +251 -0
  196. package/redis-lock/redis-lock.service.js +219 -3
  197. package/setup/bootstrap.setup.js +20 -0
  198. package/setup/mode.setup.d.ts +44 -0
  199. package/setup/mode.setup.js +44 -0
  200. package/setup/schedule.decorator.d.ts +226 -0
  201. package/setup/schedule.decorator.js +214 -1
  202. package/setup/worker.decorator.d.ts +86 -0
  203. package/setup/worker.decorator.js +88 -0
  204. package/shared/serviceRegistryModule.js +5 -1
  205. package/shared/services/api-config.service.d.ts +3 -0
  206. package/shared/services/api-config.service.js +20 -9
  207. package/validator-json/decorators.d.ts +17 -0
  208. package/validator-json/decorators.js +17 -2
  209. package/validator-json/default.d.ts +6 -0
  210. package/validator-json/default.js +30 -2
  211. package/validator-json/defaultConverters.js +1 -0
  212. package/validator-json/options.d.ts +23 -0
  213. package/validators/common-validators.d.ts +143 -0
  214. package/validators/common-validators.js +249 -0
  215. package/validators/custom-validate.examples.d.ts +23 -0
  216. package/validators/custom-validate.examples.js +78 -6
  217. package/validators/custom-validate.validator.d.ts +107 -0
  218. package/validators/custom-validate.validator.js +84 -0
  219. package/validators/index.d.ts +1 -0
  220. package/validators/index.js +1 -0
  221. package/validators/is-exists.validator.d.ts +11 -0
  222. package/validators/is-exists.validator.js +22 -0
  223. package/validators/is-unique.validator.d.ts +11 -0
  224. package/validators/is-unique.validator.js +18 -0
  225. package/validators/skip-empty.validator.d.ts +5 -0
  226. package/validators/skip-empty.validator.js +5 -0
  227. package/vault/interfaces/vault-options.interface.d.ts +9 -0
  228. package/vault/vault-config.loader.d.ts +30 -0
  229. package/vault/vault-config.loader.js +48 -1
  230. package/vault/vault-config.service.d.ts +53 -0
  231. package/vault/vault-config.service.js +57 -0
  232. package/vault/vault.module.d.ts +4 -0
  233. package/vault/vault.module.js +4 -0
  234. package/decorators/examples/validation-decorators.example.d.ts +0 -69
  235. package/decorators/examples/validation-decorators.example.js +0 -331
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ErrorFactory = exports.CacheError = exports.ApiClientConfigError = exports.ResponseFormatError = exports.ServerError = exports.RateLimitError = exports.AuthorizationError = exports.AuthenticationError = exports.CircuitBreakerOpenError = exports.RetryExhaustedError = exports.TimeoutError = exports.NetworkError = exports.HttpClientError = void 0;
4
+ /**
5
+ * HTTP客户端基础错误类
6
+ */
4
7
  class HttpClientError extends Error {
5
8
  constructor(message, code = 'HTTP_CLIENT_ERROR', statusCode, response, config) {
6
9
  super(message);
@@ -13,6 +16,9 @@ class HttpClientError extends Error {
13
16
  }
14
17
  }
15
18
  exports.HttpClientError = HttpClientError;
19
+ /**
20
+ * 网络错误
21
+ */
16
22
  class NetworkError extends HttpClientError {
17
23
  constructor(message, config) {
18
24
  super(message, 'NETWORK_ERROR', undefined, undefined, config);
@@ -20,6 +26,9 @@ class NetworkError extends HttpClientError {
20
26
  }
21
27
  }
22
28
  exports.NetworkError = NetworkError;
29
+ /**
30
+ * 超时错误
31
+ */
23
32
  class TimeoutError extends HttpClientError {
24
33
  constructor(message, config) {
25
34
  super(message, 'TIMEOUT_ERROR', undefined, undefined, config);
@@ -27,6 +36,9 @@ class TimeoutError extends HttpClientError {
27
36
  }
28
37
  }
29
38
  exports.TimeoutError = TimeoutError;
39
+ /**
40
+ * 重试失败错误
41
+ */
30
42
  class RetryExhaustedError extends HttpClientError {
31
43
  constructor(message, attempts, lastError, config) {
32
44
  super(message, 'RETRY_EXHAUSTED', undefined, undefined, config);
@@ -36,6 +48,9 @@ class RetryExhaustedError extends HttpClientError {
36
48
  }
37
49
  }
38
50
  exports.RetryExhaustedError = RetryExhaustedError;
51
+ /**
52
+ * 熔断器开启错误
53
+ */
39
54
  class CircuitBreakerOpenError extends HttpClientError {
40
55
  constructor(message, circuitName, failureCount, config) {
41
56
  super(message, 'CIRCUIT_BREAKER_OPEN', 503, undefined, config);
@@ -45,6 +60,9 @@ class CircuitBreakerOpenError extends HttpClientError {
45
60
  }
46
61
  }
47
62
  exports.CircuitBreakerOpenError = CircuitBreakerOpenError;
63
+ /**
64
+ * API认证错误
65
+ */
48
66
  class AuthenticationError extends HttpClientError {
49
67
  constructor(message, statusCode = 401, response, config) {
50
68
  super(message, 'AUTHENTICATION_ERROR', statusCode, response, config);
@@ -52,6 +70,9 @@ class AuthenticationError extends HttpClientError {
52
70
  }
53
71
  }
54
72
  exports.AuthenticationError = AuthenticationError;
73
+ /**
74
+ * API授权错误
75
+ */
55
76
  class AuthorizationError extends HttpClientError {
56
77
  constructor(message, statusCode = 403, response, config) {
57
78
  super(message, 'AUTHORIZATION_ERROR', statusCode, response, config);
@@ -59,6 +80,9 @@ class AuthorizationError extends HttpClientError {
59
80
  }
60
81
  }
61
82
  exports.AuthorizationError = AuthorizationError;
83
+ /**
84
+ * 限流错误
85
+ */
62
86
  class RateLimitError extends HttpClientError {
63
87
  constructor(message, statusCode = 429, response, config, retryAfter, limit, remaining) {
64
88
  super(message, 'RATE_LIMIT_ERROR', statusCode, response, config);
@@ -69,6 +93,9 @@ class RateLimitError extends HttpClientError {
69
93
  }
70
94
  }
71
95
  exports.RateLimitError = RateLimitError;
96
+ /**
97
+ * 服务器错误
98
+ */
72
99
  class ServerError extends HttpClientError {
73
100
  constructor(message, statusCode = 500, response, config) {
74
101
  super(message, 'SERVER_ERROR', statusCode, response, config);
@@ -76,6 +103,9 @@ class ServerError extends HttpClientError {
76
103
  }
77
104
  }
78
105
  exports.ServerError = ServerError;
106
+ /**
107
+ * 响应格式错误
108
+ */
79
109
  class ResponseFormatError extends HttpClientError {
80
110
  constructor(message, responseData, config) {
81
111
  super(message, 'RESPONSE_FORMAT_ERROR', undefined, undefined, config);
@@ -84,6 +114,9 @@ class ResponseFormatError extends HttpClientError {
84
114
  }
85
115
  }
86
116
  exports.ResponseFormatError = ResponseFormatError;
117
+ /**
118
+ * API客户端配置错误
119
+ */
87
120
  class ApiClientConfigError extends HttpClientError {
88
121
  constructor(message, config) {
89
122
  super(message, 'API_CLIENT_CONFIG_ERROR', 500, undefined, config);
@@ -91,6 +124,9 @@ class ApiClientConfigError extends HttpClientError {
91
124
  }
92
125
  }
93
126
  exports.ApiClientConfigError = ApiClientConfigError;
127
+ /**
128
+ * 缓存错误
129
+ */
94
130
  class CacheError extends HttpClientError {
95
131
  constructor(message, config) {
96
132
  super(message, 'CACHE_ERROR', undefined, undefined, config);
@@ -98,11 +134,18 @@ class CacheError extends HttpClientError {
98
134
  }
99
135
  }
100
136
  exports.CacheError = CacheError;
137
+ /**
138
+ * 错误工厂函数
139
+ */
101
140
  class ErrorFactory {
141
+ /**
142
+ * 根据axios错误创建对应的HTTP客户端错误
143
+ */
102
144
  static fromAxiosError(error) {
103
145
  const config = error.config;
104
146
  const response = error.response;
105
147
  const message = error.message || 'Unknown error';
148
+ // 网络错误
106
149
  if (!error.response) {
107
150
  if (error.code === 'ECONNABORTED') {
108
151
  return new TimeoutError(`Request timeout: ${message}`, config);
@@ -130,18 +173,33 @@ class ErrorFactory {
130
173
  return new HttpClientError((responseData === null || responseData === void 0 ? void 0 : responseData.message) || `HTTP error (${statusCode})`, 'HTTP_ERROR', statusCode, response, config);
131
174
  }
132
175
  }
176
+ /**
177
+ * 创建重试失败错误
178
+ */
133
179
  static createRetryExhaustedError(attempts, lastError, config) {
134
180
  return new RetryExhaustedError(`Retry failed after ${attempts} attempts. Last error: ${lastError.message}`, attempts, lastError, config);
135
181
  }
182
+ /**
183
+ * 创建熔断器开启错误
184
+ */
136
185
  static createCircuitBreakerOpenError(circuitName, failureCount, config) {
137
186
  return new CircuitBreakerOpenError(`Circuit breaker '${circuitName}' is open after ${failureCount} failures`, circuitName, failureCount, config);
138
187
  }
188
+ /**
189
+ * 创建响应格式错误
190
+ */
139
191
  static createResponseFormatError(message, responseData, config) {
140
192
  return new ResponseFormatError(message, responseData, config);
141
193
  }
194
+ /**
195
+ * 创建API客户端配置错误
196
+ */
142
197
  static createApiClientConfigError(message, config) {
143
198
  return new ApiClientConfigError(message, config);
144
199
  }
200
+ /**
201
+ * 创建缓存错误
202
+ */
145
203
  static createCacheError(message, config) {
146
204
  return new CacheError(message, config);
147
205
  }
@@ -1,23 +1,64 @@
1
1
  import { HttpClientService } from '../services/http-client.service';
2
+ /**
3
+ * 高级使用示例 - GitHub API客户端
4
+ * 集成现有的三层缓存架构
5
+ */
2
6
  export declare class GitHubHttpService {
3
7
  private httpClient;
4
8
  constructor(httpClient: HttpClientService);
9
+ /**
10
+ * 获取用户信息 - 带重试、熔断器、缓存和日志
11
+ */
5
12
  getUser(username: string): Promise<any>;
13
+ /**
14
+ * 搜索仓库 - 带重试和缓存
15
+ */
6
16
  searchRepositories(query: string, sort?: string, order?: string): Promise<any>;
17
+ /**
18
+ * 获取用户仓库 - 使用代理
19
+ */
7
20
  getUserRepositories(username: string): Promise<any>;
21
+ /**
22
+ * 创建仓库 - 带详细日志
23
+ */
8
24
  createRepository(repoData: any, token: string): Promise<any>;
25
+ /**
26
+ * 获取仓库贡献者 - 熔断器保护
27
+ */
9
28
  getRepositoryContributors(owner: string, repo: string): Promise<any>;
29
+ /**
30
+ * 批量获取用户信息 - 并行请求
31
+ */
10
32
  getMultipleUsers(usernames: string[]): Promise<any[]>;
33
+ /**
34
+ * 条件缓存示例
35
+ */
11
36
  getRepositoryDetails(owner: string, repo: string, options?: {
12
37
  public?: boolean;
13
38
  }): Promise<any>;
14
39
  }
40
+ /**
41
+ * 支付服务示例 - 高安全性要求
42
+ * 使用Redis锁定确保并发安全
43
+ */
15
44
  export declare class PaymentHttpService {
16
45
  private httpClient;
17
46
  constructor(httpClient: HttpClientService);
47
+ /**
48
+ * 创建支付 - 严格的安全控制
49
+ */
18
50
  createPayment(paymentData: any, apiKey: string): Promise<any>;
51
+ /**
52
+ * 查询支付状态 - 可缓存
53
+ */
19
54
  getPaymentStatus(paymentId: string, apiKey: string): Promise<any>;
55
+ /**
56
+ * 退款操作 - 重试机制
57
+ */
20
58
  refundPayment(paymentId: string, refundData: any, apiKey: string): Promise<any>;
59
+ /**
60
+ * 动态调用示例 - 手动设置调用信息
61
+ */
21
62
  callExternalApi(url: string, method?: string, data?: any): Promise<any>;
22
63
  private generateIdempotencyKey;
23
64
  }
@@ -23,15 +23,25 @@ const common_1 = require("@nestjs/common");
23
23
  const decorators_1 = require("../decorators");
24
24
  const http_client_service_1 = require("../services/http-client.service");
25
25
  const cache_options_interface_1 = require("../../cache/interfaces/cache-options.interface");
26
+ /**
27
+ * 高级使用示例 - GitHub API客户端
28
+ * 集成现有的三层缓存架构
29
+ */
26
30
  let GitHubHttpService = class GitHubHttpService {
27
31
  constructor(httpClient) {
28
32
  this.httpClient = httpClient;
29
33
  }
34
+ /**
35
+ * 获取用户信息 - 带重试、熔断器、缓存和日志
36
+ */
30
37
  getUser(username) {
31
38
  return __awaiter(this, void 0, void 0, function* () {
32
39
  return this.httpClient.get(`/users/${username}`);
33
40
  });
34
41
  }
42
+ /**
43
+ * 搜索仓库 - 带重试和缓存
44
+ */
35
45
  searchRepositories(query_1) {
36
46
  return __awaiter(this, arguments, void 0, function* (query, sort = 'stars', order = 'desc') {
37
47
  return this.httpClient.get('/search/repositories', {
@@ -44,6 +54,9 @@ let GitHubHttpService = class GitHubHttpService {
44
54
  });
45
55
  });
46
56
  }
57
+ /**
58
+ * 获取用户仓库 - 使用代理
59
+ */
47
60
  getUserRepositories(username) {
48
61
  return __awaiter(this, void 0, void 0, function* () {
49
62
  return this.httpClient.get(`/users/${username}/repos`, {
@@ -55,6 +68,9 @@ let GitHubHttpService = class GitHubHttpService {
55
68
  });
56
69
  });
57
70
  }
71
+ /**
72
+ * 创建仓库 - 带详细日志
73
+ */
58
74
  createRepository(repoData, token) {
59
75
  return __awaiter(this, void 0, void 0, function* () {
60
76
  return this.httpClient.post('/user/repos', repoData, {
@@ -65,11 +81,17 @@ let GitHubHttpService = class GitHubHttpService {
65
81
  });
66
82
  });
67
83
  }
84
+ /**
85
+ * 获取仓库贡献者 - 熔断器保护
86
+ */
68
87
  getRepositoryContributors(owner, repo) {
69
88
  return __awaiter(this, void 0, void 0, function* () {
70
89
  return this.httpClient.get(`/repos/${owner}/${repo}/contributors`);
71
90
  });
72
91
  }
92
+ /**
93
+ * 批量获取用户信息 - 并行请求
94
+ */
73
95
  getMultipleUsers(usernames) {
74
96
  return __awaiter(this, void 0, void 0, function* () {
75
97
  const promises = usernames.map((username) => this.getUser(username).catch((error) => {
@@ -79,6 +101,9 @@ let GitHubHttpService = class GitHubHttpService {
79
101
  return Promise.all(promises);
80
102
  });
81
103
  }
104
+ /**
105
+ * 条件缓存示例
106
+ */
82
107
  getRepositoryDetails(owner, repo, options) {
83
108
  return __awaiter(this, void 0, void 0, function* () {
84
109
  return this.httpClient.get(`/repos/${owner}/${repo}`);
@@ -92,9 +117,9 @@ __decorate([
92
117
  retryDelay: (retryCount) => Math.pow(2, retryCount) * 1000,
93
118
  retryCondition: (error) => {
94
119
  if (!error.response)
95
- return true;
120
+ return true; // 网络错误
96
121
  const status = error.response.status;
97
- return status >= 500 || status === 429;
122
+ return status >= 500 || status === 429; // 5xx错误或429限流
98
123
  },
99
124
  }),
100
125
  (0, decorators_1.HttpCircuitBreaker)({
@@ -102,17 +127,17 @@ __decorate([
102
127
  recoveryTimeoutMs: 30000,
103
128
  }),
104
129
  (0, decorators_1.HttpCacheable)({
105
- ttl: 300000,
106
- layers: ['cls', 'memory', 'redis'],
130
+ ttl: 300000, // 5分钟缓存
131
+ layers: ['cls', 'memory', 'redis'], // 使用三层缓存
107
132
  namespace: 'github',
108
133
  }),
109
134
  (0, decorators_1.HttpLogRequest)({
110
135
  databaseLog: true,
111
136
  logHeaders: true,
112
137
  logBody: false,
113
- serviceClass: 'GitHubHttpService',
114
- methodName: 'getUser',
115
- operationName: 'github.getUser',
138
+ serviceClass: 'GitHubHttpService', // 自定义服务类名
139
+ methodName: 'getUser', // 自定义方法名
140
+ operationName: 'github.getUser', // 自定义操作名
116
141
  }),
117
142
  (0, decorators_1.HttpTimeout)(15000),
118
143
  __metadata("design:type", Function),
@@ -122,10 +147,10 @@ __decorate([
122
147
  __decorate([
123
148
  (0, decorators_1.HttpRetry)({ retries: 3 }),
124
149
  (0, decorators_1.HttpCacheable)({
125
- ttl: 600000,
126
- layers: ['memory', 'redis'],
150
+ ttl: 600000, // 10分钟缓存
151
+ layers: ['memory', 'redis'], // 仅使用内存和Redis缓存
127
152
  namespace: 'github-search',
128
- condition: (args) => args[0].length > 2,
153
+ condition: (args) => args[0].length > 2, // 只缓存搜索词长度大于2的请求
129
154
  }),
130
155
  __metadata("design:type", Function),
131
156
  __metadata("design:paramtypes", [String, String, String]),
@@ -138,7 +163,7 @@ __decorate([
138
163
  protocol: 'http',
139
164
  }),
140
165
  (0, decorators_1.HttpCacheable)({
141
- ttl: 120000,
166
+ ttl: 120000, // 2分钟缓存
142
167
  namespace: 'github-repos',
143
168
  }),
144
169
  __metadata("design:type", Function),
@@ -162,7 +187,7 @@ __decorate([
162
187
  recoveryTimeoutMs: 60000,
163
188
  }),
164
189
  (0, decorators_1.HttpCacheable)({
165
- ttl: 900000,
190
+ ttl: 900000, // 15分钟缓存
166
191
  namespace: 'github-contributors',
167
192
  }),
168
193
  __metadata("design:type", Function),
@@ -171,11 +196,11 @@ __decorate([
171
196
  ], GitHubHttpService.prototype, "getRepositoryContributors", null);
172
197
  __decorate([
173
198
  (0, decorators_1.HttpCacheable)({
174
- ttl: 120000,
175
- layers: ['memory'],
199
+ ttl: 120000, // 2分钟缓存
200
+ layers: ['memory'], // 仅内存缓存
176
201
  namespace: 'github-repo-details',
177
- condition: (args) => { var _a; return ((_a = args[2]) === null || _a === void 0 ? void 0 : _a.public) === true; },
178
- unless: (result, args) => (result === null || result === void 0 ? void 0 : result.archived) === true,
202
+ condition: (args) => { var _a; return ((_a = args[2]) === null || _a === void 0 ? void 0 : _a.public) === true; }, // 只缓存公开仓库
203
+ unless: (result, args) => (result === null || result === void 0 ? void 0 : result.archived) === true, // 不缓存已归档的仓库
179
204
  }),
180
205
  __metadata("design:type", Function),
181
206
  __metadata("design:paramtypes", [String, String, Object]),
@@ -191,7 +216,7 @@ exports.GitHubHttpService = GitHubHttpService = __decorate([
191
216
  cacheableMethods: ['GET', 'HEAD'],
192
217
  cacheableStatusCodes: [200, 304],
193
218
  options: {
194
- layers: [cache_options_interface_1.CacheLayer.MEMORY, cache_options_interface_1.CacheLayer.REDIS],
219
+ layers: [cache_options_interface_1.CacheLayer.MEMORY, cache_options_interface_1.CacheLayer.REDIS], // 使用现有的三层缓存
195
220
  },
196
221
  },
197
222
  logging: {
@@ -209,10 +234,17 @@ exports.GitHubHttpService = GitHubHttpService = __decorate([
209
234
  (0, common_1.Injectable)(),
210
235
  __metadata("design:paramtypes", [http_client_service_1.HttpClientService])
211
236
  ], GitHubHttpService);
237
+ /**
238
+ * 支付服务示例 - 高安全性要求
239
+ * 使用Redis锁定确保并发安全
240
+ */
212
241
  let PaymentHttpService = class PaymentHttpService {
213
242
  constructor(httpClient) {
214
243
  this.httpClient = httpClient;
215
244
  }
245
+ /**
246
+ * 创建支付 - 严格的安全控制
247
+ */
216
248
  createPayment(paymentData, apiKey) {
217
249
  return __awaiter(this, void 0, void 0, function* () {
218
250
  return this.httpClient.post('/payments', paymentData, {
@@ -224,6 +256,9 @@ let PaymentHttpService = class PaymentHttpService {
224
256
  });
225
257
  });
226
258
  }
259
+ /**
260
+ * 查询支付状态 - 可缓存
261
+ */
227
262
  getPaymentStatus(paymentId, apiKey) {
228
263
  return __awaiter(this, void 0, void 0, function* () {
229
264
  return this.httpClient.get(`/payments/${paymentId}`, {
@@ -233,6 +268,9 @@ let PaymentHttpService = class PaymentHttpService {
233
268
  });
234
269
  });
235
270
  }
271
+ /**
272
+ * 退款操作 - 重试机制
273
+ */
236
274
  refundPayment(paymentId, refundData, apiKey) {
237
275
  return __awaiter(this, void 0, void 0, function* () {
238
276
  return this.httpClient.post(`/payments/${paymentId}/refund`, refundData, {
@@ -243,8 +281,12 @@ let PaymentHttpService = class PaymentHttpService {
243
281
  });
244
282
  });
245
283
  }
284
+ /**
285
+ * 动态调用示例 - 手动设置调用信息
286
+ */
246
287
  callExternalApi(url_1) {
247
288
  return __awaiter(this, arguments, void 0, function* (url, method = 'GET', data) {
289
+ // 手动设置调用信息
248
290
  const { CallStackExtractor } = require('../utils');
249
291
  CallStackExtractor.setCallInfo('PaymentHttpService', 'callExternalApi', `payment.${method.toLowerCase()}`);
250
292
  try {
@@ -259,6 +301,7 @@ let PaymentHttpService = class PaymentHttpService {
259
301
  });
260
302
  }
261
303
  finally {
304
+ // 清理调用信息
262
305
  CallStackExtractor.clearCallInfo();
263
306
  }
264
307
  });
@@ -281,8 +324,8 @@ __decorate([
281
324
  ], PaymentHttpService.prototype, "createPayment", null);
282
325
  __decorate([
283
326
  (0, decorators_1.HttpCacheable)({
284
- ttl: 30000,
285
- layers: ['redis'],
327
+ ttl: 30000, // 30秒缓存
328
+ layers: ['redis'], // 仅Redis缓存,确保多实例共享
286
329
  namespace: 'payment-status',
287
330
  }),
288
331
  __metadata("design:type", Function),
@@ -292,8 +335,9 @@ __decorate([
292
335
  __decorate([
293
336
  (0, decorators_1.HttpRetry)({
294
337
  retries: 2,
295
- retryDelay: (retryCount) => retryCount * 2000,
338
+ retryDelay: (retryCount) => retryCount * 2000, // 线性退避
296
339
  retryCondition: (error) => {
340
+ // 只对网络错误和5xx错误重试,4xx错误不重试
297
341
  if (!error.response)
298
342
  return true;
299
343
  return error.response.status >= 500;
@@ -302,7 +346,7 @@ __decorate([
302
346
  (0, decorators_1.HttpLogRequest)({
303
347
  logHeaders: false,
304
348
  logBody: false,
305
- databaseLog: true,
349
+ databaseLog: true, // 退款操作需要记录到数据库
306
350
  }),
307
351
  __metadata("design:type", Function),
308
352
  __metadata("design:paramtypes", [String, Object, String]),
@@ -313,15 +357,15 @@ exports.PaymentHttpService = PaymentHttpService = __decorate([
313
357
  baseURL: 'https://api.payment-provider.com',
314
358
  timeout: 15000,
315
359
  retry: {
316
- enabled: false,
360
+ enabled: false, // 支付操作不自动重试
317
361
  },
318
362
  logging: {
319
363
  enabled: true,
320
364
  logRequests: true,
321
365
  logResponses: true,
322
366
  logErrors: true,
323
- logHeaders: false,
324
- logBody: false,
367
+ logHeaders: false, // 不记录敏感头信息
368
+ logBody: false, // 不记录支付数据
325
369
  maxBodyLength: 1000,
326
370
  sanitizeHeaders: ['authorization', 'x-api-key', 'x-client-secret'],
327
371
  logLevel: 'info',
@@ -1,17 +1,48 @@
1
1
  import { HttpClientService } from '../services/http-client.service';
2
2
  import { HttpLogQueryService } from '../services/http-log-query.service';
3
3
  import { HttpReplayService } from '../services/http-replay.service';
4
+ /**
5
+ * 使用等待锁的认证示例
6
+ * 演示如何在原有的HTTP客户端中使用等待锁机制
7
+ */
4
8
  export declare class AuthWithWaitingLockExample {
5
9
  private readonly httpClient;
6
10
  private readonly logQueryService;
7
11
  private readonly replayService;
8
12
  private readonly logger;
9
13
  constructor(httpClient: HttpClientService, logQueryService: HttpLogQueryService, replayService: HttpReplayService);
14
+ /**
15
+ * 示例1: 基本的带等待锁的认证请求
16
+ * 演示如何使用authRequest方法确保只有一个进程获取token
17
+ */
10
18
  basicAuthWithLock(): Promise<any>;
19
+ /**
20
+ * 示例2: 批量带等待锁的认证请求
21
+ * 演示如何在批量操作中共享token,避免重复认证
22
+ */
11
23
  batchAuthWithLock(): Promise<any[]>;
24
+ /**
25
+ * 示例3: 从HTTP日志生成curl命令
26
+ * 演示如何从已有的HTTP日志生成可执行的curl命令
27
+ */
12
28
  generateCurlFromLogs(): Promise<void>;
29
+ /**
30
+ * 示例4: 请求重放功能
31
+ * 演示如何重放已有的HTTP请求
32
+ */
13
33
  demonstrateRequestReplay(): Promise<void>;
34
+ /**
35
+ * 示例5: 批量重放和比较
36
+ * 演示如何批量重放请求并比较结果
37
+ */
14
38
  batchReplayAndCompare(): Promise<void>;
39
+ /**
40
+ * 示例6: 综合演示 - 等待锁 + curl生成 + 请求重放
41
+ * 演示完整的工作流程
42
+ */
15
43
  comprehensiveDemo(): Promise<void>;
44
+ /**
45
+ * 运行所有示例
46
+ */
16
47
  runAllExamples(): Promise<void>;
17
48
  }