@nest-omni/core 3.1.2-7 → 3.1.2-9

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 (138) hide show
  1. package/audit/audit.module.d.ts +10 -0
  2. package/audit/audit.module.js +254 -0
  3. package/audit/controllers/audit.controller.d.ts +20 -0
  4. package/audit/controllers/audit.controller.js +142 -0
  5. package/audit/controllers/index.d.ts +1 -0
  6. package/audit/controllers/index.js +17 -0
  7. package/audit/decorators/audit-controller.decorator.d.ts +5 -0
  8. package/audit/decorators/audit-controller.decorator.js +17 -0
  9. package/audit/decorators/audit-operation.decorator.d.ts +7 -0
  10. package/audit/decorators/audit-operation.decorator.js +25 -0
  11. package/audit/decorators/entity-audit.decorator.d.ts +10 -0
  12. package/audit/decorators/entity-audit.decorator.js +70 -0
  13. package/audit/decorators/index.d.ts +3 -0
  14. package/audit/decorators/index.js +19 -0
  15. package/audit/dto/audit-log-query.dto.d.ts +14 -0
  16. package/audit/dto/audit-log-query.dto.js +95 -0
  17. package/audit/dto/begin-transaction.dto.d.ts +3 -0
  18. package/audit/dto/begin-transaction.dto.js +22 -0
  19. package/audit/dto/compare-entities.dto.d.ts +6 -0
  20. package/audit/dto/compare-entities.dto.js +44 -0
  21. package/audit/dto/index.d.ts +5 -0
  22. package/audit/dto/index.js +21 -0
  23. package/audit/dto/pre-check-restore.dto.d.ts +5 -0
  24. package/audit/dto/pre-check-restore.dto.js +32 -0
  25. package/audit/dto/restore-entity.dto.d.ts +9 -0
  26. package/audit/dto/restore-entity.dto.js +53 -0
  27. package/audit/entities/entity-audit-log.entity.d.ts +23 -0
  28. package/audit/entities/entity-audit-log.entity.js +110 -0
  29. package/audit/entities/entity-transaction.entity.d.ts +21 -0
  30. package/audit/entities/entity-transaction.entity.js +80 -0
  31. package/audit/entities/index.d.ts +4 -0
  32. package/audit/entities/index.js +20 -0
  33. package/audit/entities/manual-operation-log.entity.d.ts +13 -0
  34. package/audit/entities/manual-operation-log.entity.js +65 -0
  35. package/audit/entities/operation-template.entity.d.ts +11 -0
  36. package/audit/entities/operation-template.entity.js +65 -0
  37. package/audit/enums/audit.enums.d.ts +42 -0
  38. package/audit/enums/audit.enums.js +53 -0
  39. package/audit/enums/index.d.ts +1 -0
  40. package/audit/enums/index.js +17 -0
  41. package/audit/index.d.ts +12 -0
  42. package/audit/index.js +48 -0
  43. package/audit/interceptors/audit.interceptor.d.ts +12 -0
  44. package/audit/interceptors/audit.interceptor.js +95 -0
  45. package/audit/interceptors/index.d.ts +1 -0
  46. package/audit/interceptors/index.js +17 -0
  47. package/audit/interfaces/audit.interfaces.d.ts +180 -0
  48. package/audit/interfaces/audit.interfaces.js +2 -0
  49. package/audit/interfaces/index.d.ts +1 -0
  50. package/audit/interfaces/index.js +17 -0
  51. package/audit/services/audit-context.service.d.ts +10 -0
  52. package/audit/services/audit-context.service.js +55 -0
  53. package/audit/services/audit-strategy.service.d.ts +19 -0
  54. package/audit/services/audit-strategy.service.js +89 -0
  55. package/audit/services/entity-audit.service.d.ts +65 -0
  56. package/audit/services/entity-audit.service.js +626 -0
  57. package/audit/services/index.d.ts +6 -0
  58. package/audit/services/index.js +22 -0
  59. package/audit/services/multi-database.service.d.ts +10 -0
  60. package/audit/services/multi-database.service.js +59 -0
  61. package/audit/services/operation-description.service.d.ts +21 -0
  62. package/audit/services/operation-description.service.js +213 -0
  63. package/audit/services/transaction-audit.service.d.ts +22 -0
  64. package/audit/services/transaction-audit.service.js +201 -0
  65. package/audit/subscribers/entity-audit.subscriber.d.ts +14 -0
  66. package/audit/subscribers/entity-audit.subscriber.js +136 -0
  67. package/audit/subscribers/index.d.ts +1 -0
  68. package/audit/subscribers/index.js +17 -0
  69. package/common/utils.d.ts +1 -0
  70. package/common/utils.js +6 -0
  71. package/http-client/config/http-client.config.d.ts +6 -0
  72. package/http-client/config/http-client.config.js +87 -0
  73. package/http-client/config/index.d.ts +1 -0
  74. package/http-client/config/index.js +17 -0
  75. package/http-client/decorators/http-client.decorators.d.ts +72 -0
  76. package/http-client/decorators/http-client.decorators.js +204 -0
  77. package/http-client/decorators/index.d.ts +1 -0
  78. package/http-client/decorators/index.js +17 -0
  79. package/http-client/entities/http-log.entity.d.ts +98 -0
  80. package/http-client/entities/http-log.entity.js +143 -0
  81. package/http-client/entities/index.d.ts +1 -0
  82. package/http-client/entities/index.js +17 -0
  83. package/http-client/errors/http-client.errors.d.ts +56 -0
  84. package/http-client/errors/http-client.errors.js +149 -0
  85. package/http-client/errors/index.d.ts +1 -0
  86. package/http-client/errors/index.js +17 -0
  87. package/http-client/examples/advanced-usage.example.d.ts +23 -0
  88. package/http-client/examples/advanced-usage.example.js +332 -0
  89. package/http-client/examples/auth-with-waiting-lock.example.d.ts +17 -0
  90. package/http-client/examples/auth-with-waiting-lock.example.js +336 -0
  91. package/http-client/examples/basic-usage.example.d.ts +53 -0
  92. package/http-client/examples/basic-usage.example.js +161 -0
  93. package/http-client/examples/index.d.ts +3 -0
  94. package/http-client/examples/index.js +19 -0
  95. package/http-client/examples/multi-api-configuration.example.d.ts +98 -0
  96. package/http-client/examples/multi-api-configuration.example.js +353 -0
  97. package/http-client/http-client.module.d.ts +11 -0
  98. package/http-client/http-client.module.js +257 -0
  99. package/http-client/index.d.ts +10 -0
  100. package/http-client/index.js +27 -0
  101. package/http-client/interfaces/api-client-config.interface.d.ts +152 -0
  102. package/http-client/interfaces/api-client-config.interface.js +12 -0
  103. package/http-client/interfaces/http-client-config.interface.d.ts +123 -0
  104. package/http-client/interfaces/http-client-config.interface.js +2 -0
  105. package/http-client/services/api-client-registry.service.d.ts +41 -0
  106. package/http-client/services/api-client-registry.service.js +412 -0
  107. package/http-client/services/cache.service.d.ts +24 -0
  108. package/http-client/services/cache.service.js +264 -0
  109. package/http-client/services/circuit-breaker.service.d.ts +33 -0
  110. package/http-client/services/circuit-breaker.service.js +180 -0
  111. package/http-client/services/http-client.service.d.ts +60 -0
  112. package/http-client/services/http-client.service.js +504 -0
  113. package/http-client/services/http-log-query.service.d.ts +76 -0
  114. package/http-client/services/http-log-query.service.js +590 -0
  115. package/http-client/services/http-replay.service.d.ts +58 -0
  116. package/http-client/services/http-replay.service.js +266 -0
  117. package/http-client/services/index.d.ts +7 -0
  118. package/http-client/services/index.js +23 -0
  119. package/http-client/services/log-cleanup.service.d.ts +64 -0
  120. package/http-client/services/log-cleanup.service.js +268 -0
  121. package/http-client/services/logging.service.d.ts +36 -0
  122. package/http-client/services/logging.service.js +445 -0
  123. package/http-client/utils/call-stack-extractor.util.d.ts +29 -0
  124. package/http-client/utils/call-stack-extractor.util.js +138 -0
  125. package/http-client/utils/context-extractor.util.d.ts +44 -0
  126. package/http-client/utils/context-extractor.util.js +173 -0
  127. package/http-client/utils/curl-generator.util.d.ts +9 -0
  128. package/http-client/utils/curl-generator.util.js +169 -0
  129. package/http-client/utils/index.d.ts +4 -0
  130. package/http-client/utils/index.js +20 -0
  131. package/http-client/utils/request-id.util.d.ts +4 -0
  132. package/http-client/utils/request-id.util.js +34 -0
  133. package/http-client/utils/retry-recorder.util.d.ts +30 -0
  134. package/http-client/utils/retry-recorder.util.js +143 -0
  135. package/index.d.ts +2 -0
  136. package/index.js +2 -0
  137. package/package.json +1 -1
  138. package/setup/bootstrap.setup.js +5 -1
@@ -0,0 +1,11 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { HttpClientConfig } from './interfaces/http-client-config.interface';
3
+ export declare class HttpClientModule {
4
+ static forRoot(config?: HttpClientConfig): DynamicModule;
5
+ static forRootAsync(config: {
6
+ useFactory: (...args: any[]) => Promise<HttpClientConfig> | HttpClientConfig;
7
+ inject?: any[];
8
+ imports?: any[];
9
+ }): DynamicModule;
10
+ private static loadConfigFromEnvironment;
11
+ }
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ var HttpClientModule_1;
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.HttpClientModule = void 0;
20
+ const common_1 = require("@nestjs/common");
21
+ const schedule_1 = require("@nestjs/schedule");
22
+ const config_1 = require("@nestjs/config");
23
+ const typeorm_1 = require("@nestjs/typeorm");
24
+ const cache_service_1 = require("../cache/cache.service");
25
+ const http_client_service_1 = require("./services/http-client.service");
26
+ const circuit_breaker_service_1 = require("./services/circuit-breaker.service");
27
+ const logging_service_1 = require("./services/logging.service");
28
+ const cache_service_2 = require("./services/cache.service");
29
+ const http_log_query_service_1 = require("./services/http-log-query.service");
30
+ const log_cleanup_service_1 = require("./services/log-cleanup.service");
31
+ const api_client_registry_service_1 = require("./services/api-client-registry.service");
32
+ const entities_1 = require("./entities");
33
+ const cache_options_interface_1 = require("../cache/interfaces/cache-options.interface");
34
+ const redis_lock_service_1 = require("../redis-lock/redis-lock.service");
35
+ let HttpClientModule = HttpClientModule_1 = class HttpClientModule {
36
+ static forRoot(config = {}) {
37
+ var _a, _b, _c;
38
+ const baseProviders = [
39
+ {
40
+ provide: 'HTTP_CLIENT_CONFIG',
41
+ useFactory: (configService, cacheService) => {
42
+ const envConfig = this.loadConfigFromEnvironment(configService);
43
+ return Object.assign(Object.assign({}, config), envConfig);
44
+ },
45
+ inject: [config_1.ConfigService, cache_service_1.CacheService],
46
+ },
47
+ circuit_breaker_service_1.HttpCircuitBreakerService,
48
+ logging_service_1.HttpLoggingService,
49
+ cache_service_2.HttpCacheService,
50
+ http_log_query_service_1.HttpLogQueryService,
51
+ log_cleanup_service_1.HttpLogCleanupService,
52
+ api_client_registry_service_1.ApiClientRegistryService,
53
+ {
54
+ provide: http_client_service_1.HttpClientService,
55
+ useFactory: (circuitBreakerService, loggingService, cacheService, redisLockService, httpConfig) => {
56
+ return new http_client_service_1.HttpClientService(circuitBreakerService, loggingService, cacheService, redisLockService, httpConfig);
57
+ },
58
+ inject: [
59
+ circuit_breaker_service_1.HttpCircuitBreakerService,
60
+ logging_service_1.HttpLoggingService,
61
+ cache_service_2.HttpCacheService,
62
+ redis_lock_service_1.RedisLockService,
63
+ 'HTTP_CLIENT_CONFIG',
64
+ ],
65
+ },
66
+ ];
67
+ const baseExports = [
68
+ http_client_service_1.HttpClientService,
69
+ circuit_breaker_service_1.HttpCircuitBreakerService,
70
+ logging_service_1.HttpLoggingService,
71
+ cache_service_2.HttpCacheService,
72
+ http_log_query_service_1.HttpLogQueryService,
73
+ log_cleanup_service_1.HttpLogCleanupService,
74
+ api_client_registry_service_1.ApiClientRegistryService,
75
+ ];
76
+ const dynamicImports = [config_1.ConfigModule];
77
+ if ((_b = (_a = config.logging) === null || _a === void 0 ? void 0 : _a.databaseLogging) === null || _b === void 0 ? void 0 : _b.enabled) {
78
+ dynamicImports.push(typeorm_1.TypeOrmModule.forFeature([entities_1.HttpLogEntity]));
79
+ }
80
+ if ((_c = config.logCleanup) === null || _c === void 0 ? void 0 : _c.enabled) {
81
+ dynamicImports.push(schedule_1.ScheduleModule.forRoot());
82
+ }
83
+ return {
84
+ module: HttpClientModule_1,
85
+ imports: dynamicImports,
86
+ providers: baseProviders,
87
+ exports: baseExports,
88
+ };
89
+ }
90
+ static forRootAsync(config) {
91
+ const baseProviders = [
92
+ {
93
+ provide: 'HTTP_CLIENT_CONFIG',
94
+ useFactory: (...args) => __awaiter(this, void 0, void 0, function* () {
95
+ const userConfig = yield config.useFactory(...args);
96
+ const envConfig = this.loadConfigFromEnvironment(args[0]);
97
+ return Object.assign(Object.assign({}, userConfig), envConfig);
98
+ }),
99
+ inject: config.inject || [config_1.ConfigService],
100
+ },
101
+ circuit_breaker_service_1.HttpCircuitBreakerService,
102
+ logging_service_1.HttpLoggingService,
103
+ cache_service_2.HttpCacheService,
104
+ http_log_query_service_1.HttpLogQueryService,
105
+ log_cleanup_service_1.HttpLogCleanupService,
106
+ api_client_registry_service_1.ApiClientRegistryService,
107
+ {
108
+ provide: http_client_service_1.HttpClientService,
109
+ useFactory: (circuitBreakerService, loggingService, cacheService, redisLockService, httpConfig) => {
110
+ return new http_client_service_1.HttpClientService(circuitBreakerService, loggingService, cacheService, redisLockService, httpConfig);
111
+ },
112
+ inject: [
113
+ circuit_breaker_service_1.HttpCircuitBreakerService,
114
+ logging_service_1.HttpLoggingService,
115
+ cache_service_2.HttpCacheService,
116
+ redis_lock_service_1.RedisLockService,
117
+ 'HTTP_CLIENT_CONFIG',
118
+ ],
119
+ },
120
+ ];
121
+ const baseExports = [
122
+ http_client_service_1.HttpClientService,
123
+ circuit_breaker_service_1.HttpCircuitBreakerService,
124
+ logging_service_1.HttpLoggingService,
125
+ cache_service_2.HttpCacheService,
126
+ http_log_query_service_1.HttpLogQueryService,
127
+ log_cleanup_service_1.HttpLogCleanupService,
128
+ api_client_registry_service_1.ApiClientRegistryService,
129
+ ];
130
+ const dynamicImports = [config_1.ConfigModule, ...(config.imports || [])];
131
+ return {
132
+ module: HttpClientModule_1,
133
+ imports: dynamicImports,
134
+ providers: baseProviders,
135
+ exports: baseExports,
136
+ };
137
+ }
138
+ static loadConfigFromEnvironment(configService) {
139
+ var _a, _b, _c, _d, _e, _f, _g;
140
+ return {
141
+ baseURL: configService.get('HTTP_CLIENT_BASE_URL'),
142
+ timeout: configService.get('HTTP_CLIENT_TIMEOUT')
143
+ ? parseInt(configService.get('HTTP_CLIENT_TIMEOUT'))
144
+ : undefined,
145
+ retry: {
146
+ enabled: configService.get('HTTP_CLIENT_RETRY_ENABLED') === 'true',
147
+ retries: configService.get('HTTP_CLIENT_RETRY_RETRIES')
148
+ ? parseInt(configService.get('HTTP_CLIENT_RETRY_RETRIES'))
149
+ : undefined,
150
+ retryDelay: configService.get('HTTP_CLIENT_RETRY_DELAY_STRATEGY') ===
151
+ 'exponential'
152
+ ? (retryCount) => Math.pow(2, retryCount) * 1000
153
+ : undefined,
154
+ retryCondition: configService.get('HTTP_CLIENT_RETRY_CONDITION') ===
155
+ 'network_only'
156
+ ? (error) => !error.response
157
+ : undefined,
158
+ shouldResetTimeout: configService.get('HTTP_CLIENT_RETRY_RESET_TIMEOUT') !==
159
+ 'false',
160
+ },
161
+ circuitBreaker: {
162
+ enabled: configService.get('HTTP_CLIENT_CIRCUIT_BREAKER_ENABLED') ===
163
+ 'true',
164
+ failureThreshold: configService.get('HTTP_CLIENT_CIRCUIT_BREAKER_FAILURE_THRESHOLD')
165
+ ? parseInt(configService.get('HTTP_CLIENT_CIRCUIT_BREAKER_FAILURE_THRESHOLD'))
166
+ : 5,
167
+ recoveryTimeoutMs: configService.get('HTTP_CLIENT_CIRCUIT_BREAKER_RECOVERY_TIMEOUT')
168
+ ? parseInt(configService.get('HTTP_CLIENT_CIRCUIT_BREAKER_RECOVERY_TIMEOUT'))
169
+ : 60000,
170
+ monitoringPeriodMs: configService.get('HTTP_CLIENT_CIRCUIT_BREAKER_MONITORING_PERIOD')
171
+ ? parseInt(configService.get('HTTP_CLIENT_CIRCUIT_BREAKER_MONITORING_PERIOD'))
172
+ : 10000,
173
+ minimumThroughputThreshold: configService.get('HTTP_CLIENT_CIRCUIT_BREAKER_MINIMUM_THROUGHPUT')
174
+ ? parseInt(configService.get('HTTP_CLIENT_CIRCUIT_BREAKER_MINIMUM_THROUGHPUT'))
175
+ : 10,
176
+ countHalfOpenCalls: configService.get('HTTP_CLIENT_CIRCUIT_BREAKER_COUNT_HALF_OPEN') === 'true',
177
+ },
178
+ cache: {
179
+ enabled: configService.get('HTTP_CLIENT_CACHE_ENABLED') !== 'false',
180
+ defaultTtl: configService.get('HTTP_CLIENT_CACHE_DEFAULT_TTL')
181
+ ? parseInt(configService.get('HTTP_CLIENT_CACHE_DEFAULT_TTL'))
182
+ : 300000,
183
+ cacheableMethods: ((_b = (_a = configService
184
+ .get('HTTP_CLIENT_CACHEABLE_METHODS')) === null || _a === void 0 ? void 0 : _a.split(',')) === null || _b === void 0 ? void 0 : _b.map((method) => method.trim().toUpperCase())) || [
185
+ 'GET',
186
+ 'HEAD',
187
+ ],
188
+ cacheableStatusCodes: ((_d = (_c = configService
189
+ .get('HTTP_CLIENT_CACHEABLE_STATUS_CODES')) === null || _c === void 0 ? void 0 : _c.split(',')) === null || _d === void 0 ? void 0 : _d.map((code) => parseInt(code.trim()))) || [200, 201, 304],
190
+ options: {
191
+ layers: ((_f = (_e = configService
192
+ .get('HTTP_CLIENT_CACHE_LAYERS')) === null || _e === void 0 ? void 0 : _e.split(',')) === null || _f === void 0 ? void 0 : _f.map((layer) => {
193
+ const trimmed = layer.trim();
194
+ switch (trimmed) {
195
+ case 'cls':
196
+ return cache_options_interface_1.CacheLayer.CLS;
197
+ case 'memory':
198
+ return cache_options_interface_1.CacheLayer.MEMORY;
199
+ case 'redis':
200
+ return cache_options_interface_1.CacheLayer.REDIS;
201
+ default:
202
+ return cache_options_interface_1.CacheLayer.MEMORY;
203
+ }
204
+ })) || [cache_options_interface_1.CacheLayer.MEMORY],
205
+ },
206
+ },
207
+ logging: {
208
+ enabled: configService.get('HTTP_CLIENT_LOGGING_ENABLED') !== 'false',
209
+ logRequests: configService.get('HTTP_CLIENT_LOG_REQUESTS') !== 'false',
210
+ logResponses: configService.get('HTTP_CLIENT_LOG_RESPONSES') !== 'false',
211
+ logErrors: configService.get('HTTP_CLIENT_LOG_ERRORS') !== 'false',
212
+ logHeaders: configService.get('HTTP_CLIENT_LOG_HEADERS') !== 'false',
213
+ logBody: configService.get('HTTP_CLIENT_LOG_BODY') !== 'false',
214
+ maxBodyLength: configService.get('HTTP_CLIENT_LOG_MAX_BODY_LENGTH')
215
+ ? parseInt(configService.get('HTTP_CLIENT_LOG_MAX_BODY_LENGTH'))
216
+ : undefined,
217
+ sanitizeHeaders: (_g = configService
218
+ .get('HTTP_CLIENT_LOG_SANITIZE_HEADERS')) === null || _g === void 0 ? void 0 : _g.split(','),
219
+ logLevel: configService.get('HTTP_CLIENT_LOG_LEVEL'),
220
+ databaseLogging: {
221
+ enabled: configService.get('HTTP_CLIENT_DB_LOGGING_ENABLED') ===
222
+ 'true',
223
+ dataSource: configService.get('HTTP_CLIENT_DB_LOGGING_DATA_SOURCE') ||
224
+ 'default',
225
+ tableName: configService.get('HTTP_CLIENT_DB_LOGGING_TABLE_NAME') ||
226
+ 'http_logs',
227
+ },
228
+ },
229
+ proxy: {
230
+ enabled: configService.get('HTTP_CLIENT_PROXY_ENABLED') === 'true',
231
+ host: configService.get('HTTP_CLIENT_PROXY_HOST'),
232
+ port: configService.get('HTTP_CLIENT_PROXY_PORT')
233
+ ? parseInt(configService.get('HTTP_CLIENT_PROXY_PORT'))
234
+ : undefined,
235
+ protocol: configService.get('HTTP_CLIENT_PROXY_PROTOCOL'),
236
+ },
237
+ logCleanup: {
238
+ enabled: configService.get('HTTP_CLIENT_LOG_CLEANUP_ENABLED') ===
239
+ 'true',
240
+ retentionDays: configService.get('HTTP_CLIENT_LOG_CLEANUP_RETENTION_DAYS')
241
+ ? parseInt(configService.get('HTTP_CLIENT_LOG_CLEANUP_RETENTION_DAYS'))
242
+ : 30,
243
+ maxRecords: configService.get('HTTP_CLIENT_LOG_CLEANUP_MAX_RECORDS'),
244
+ batchSize: configService.get('HTTP_CLIENT_LOG_CLEANUP_BATCH_SIZE')
245
+ ? parseInt(configService.get('HTTP_CLIENT_LOG_CLEANUP_BATCH_SIZE'))
246
+ : 1000,
247
+ schedule: configService.get('HTTP_CLIENT_LOG_CLEANUP_SCHEDULE') || '0 2 * * *',
248
+ strategy: configService.get('HTTP_CLIENT_LOG_CLEANUP_STRATEGY') || 'retention',
249
+ },
250
+ };
251
+ }
252
+ };
253
+ exports.HttpClientModule = HttpClientModule;
254
+ exports.HttpClientModule = HttpClientModule = HttpClientModule_1 = __decorate([
255
+ (0, common_1.Global)(),
256
+ (0, common_1.Module)({})
257
+ ], HttpClientModule);
@@ -0,0 +1,10 @@
1
+ export { HttpClientConfig, RetryConfig, CircuitBreakerConfig, HttpCacheConfig, ProxyConfig, LoggingConfig, InterceptorConfig, ConnectionPoolConfig, HttpContext, HttpInterceptor, HttpMethod, HttpStats, } from './interfaces/http-client-config.interface';
2
+ export * from './interfaces/api-client-config.interface';
3
+ export { HttpLogEntity, RetryRecord } from './entities';
4
+ export * from './decorators';
5
+ export * from './services';
6
+ export * from './utils';
7
+ export * from './errors';
8
+ export * from './config';
9
+ export * from './http-client.module';
10
+ export * from './examples';
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.HttpLogEntity = void 0;
18
+ __exportStar(require("./interfaces/api-client-config.interface"), exports);
19
+ var entities_1 = require("./entities");
20
+ Object.defineProperty(exports, "HttpLogEntity", { enumerable: true, get: function () { return entities_1.HttpLogEntity; } });
21
+ __exportStar(require("./decorators"), exports);
22
+ __exportStar(require("./services"), exports);
23
+ __exportStar(require("./utils"), exports);
24
+ __exportStar(require("./errors"), exports);
25
+ __exportStar(require("./config"), exports);
26
+ __exportStar(require("./http-client.module"), exports);
27
+ __exportStar(require("./examples"), exports);
@@ -0,0 +1,152 @@
1
+ import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ import { HttpClientConfig } from './http-client-config.interface';
3
+ export declare enum AuthType {
4
+ NONE = "none",
5
+ API_KEY = "apiKey",
6
+ BEARER_TOKEN = "bearer",
7
+ BASIC_AUTH = "basic",
8
+ OAUTH2 = "oauth2",
9
+ CUSTOM = "custom"
10
+ }
11
+ export interface ApiKeyConfig {
12
+ key: string;
13
+ location: 'header' | 'query';
14
+ name?: string;
15
+ prefix?: string;
16
+ }
17
+ export interface BearerTokenConfig {
18
+ token: string;
19
+ scheme?: string;
20
+ }
21
+ export interface BasicAuthConfig {
22
+ username: string;
23
+ password: string;
24
+ }
25
+ export interface OAuth2Config {
26
+ clientId: string;
27
+ clientSecret: string;
28
+ tokenUrl: string;
29
+ scopes?: string[];
30
+ grantType?: 'client_credentials' | 'password' | 'authorization_code';
31
+ username?: string;
32
+ password?: string;
33
+ redirectUri?: string;
34
+ refreshToken?: string;
35
+ }
36
+ export interface CustomAuthConfig {
37
+ authenticator: (config: AxiosRequestConfig) => Promise<AxiosRequestConfig>;
38
+ refresher?: (config: AxiosRequestConfig, error: any) => Promise<AxiosRequestConfig>;
39
+ }
40
+ export type AuthConfig = {
41
+ type: AuthType.NONE;
42
+ } | {
43
+ type: AuthType.API_KEY;
44
+ config: ApiKeyConfig;
45
+ } | {
46
+ type: AuthType.BEARER_TOKEN;
47
+ config: BearerTokenConfig;
48
+ } | {
49
+ type: AuthType.BASIC_AUTH;
50
+ config: BasicAuthConfig;
51
+ } | {
52
+ type: AuthType.OAUTH2;
53
+ config: OAuth2Config;
54
+ } | {
55
+ type: AuthType.CUSTOM;
56
+ config: CustomAuthConfig;
57
+ };
58
+ export interface ResponseTransformerConfig {
59
+ success?: (response: AxiosResponse) => any;
60
+ error?: (error: any) => any;
61
+ dataPath?: string;
62
+ errorPath?: string;
63
+ validateResponse?: boolean;
64
+ validator?: (data: any) => boolean;
65
+ }
66
+ export interface ApiClientConfig {
67
+ name: string;
68
+ baseURL: string;
69
+ httpConfig?: HttpClientConfig;
70
+ auth?: AuthConfig;
71
+ responseTransformer?: ResponseTransformerConfig;
72
+ defaultHeaders?: Record<string, string>;
73
+ defaultParams?: Record<string, any>;
74
+ interceptors?: {
75
+ request?: Array<(config: AxiosRequestConfig) => AxiosRequestConfig | Promise<AxiosRequestConfig>>;
76
+ response?: Array<(response: AxiosResponse) => AxiosResponse | Promise<AxiosResponse>>;
77
+ error?: Array<(error: any) => any>;
78
+ };
79
+ retry?: {
80
+ enabled?: boolean;
81
+ retries?: number;
82
+ retryCondition?: (error: any) => boolean;
83
+ };
84
+ enableValidation?: boolean;
85
+ responseTimeWarningThreshold?: number;
86
+ tags?: string[];
87
+ enableDetailedLogging?: boolean;
88
+ }
89
+ export interface ApiClientInstanceConfig extends ApiClientConfig {
90
+ override?: boolean;
91
+ environments?: {
92
+ development?: Partial<ApiClientConfig>;
93
+ staging?: Partial<ApiClientConfig>;
94
+ production?: Partial<ApiClientConfig>;
95
+ };
96
+ }
97
+ export interface ApiClientRegistryConfig {
98
+ globalDefaults?: Partial<HttpClientConfig>;
99
+ logCleanup?: {
100
+ enabled?: boolean;
101
+ retentionDays?: number;
102
+ maxRecords?: number;
103
+ };
104
+ defaultResponseTransformer?: ResponseTransformerConfig;
105
+ enableGlobalRetry?: boolean;
106
+ enableCircuitBreaker?: boolean;
107
+ }
108
+ export interface ApiClientFactory {
109
+ createClient<T = any>(config: ApiClientInstanceConfig): T;
110
+ getClient<T = any>(name: string): T;
111
+ listClients(): string[];
112
+ updateClient(name: string, config: Partial<ApiClientConfig>): void;
113
+ removeClient(name: string): void;
114
+ }
115
+ export interface ApiClient {
116
+ name: string;
117
+ config: ApiClientConfig;
118
+ get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
119
+ post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
120
+ put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
121
+ patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
122
+ delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
123
+ request<T = any>(config: AxiosRequestConfig): Promise<T>;
124
+ getStats(): any;
125
+ resetStats(): void;
126
+ }
127
+ export interface ApiResponse<T = any> {
128
+ data?: T;
129
+ code?: number;
130
+ message?: string;
131
+ success?: boolean;
132
+ error?: {
133
+ code?: string;
134
+ message?: string;
135
+ details?: any;
136
+ };
137
+ pagination?: {
138
+ page?: number;
139
+ pageSize?: number;
140
+ total?: number;
141
+ totalPages?: number;
142
+ };
143
+ requestId?: string;
144
+ timestamp?: string;
145
+ }
146
+ export interface ErrorResponse {
147
+ code: string | number;
148
+ message: string;
149
+ details?: any;
150
+ stack?: string;
151
+ requestId?: string;
152
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthType = void 0;
4
+ var AuthType;
5
+ (function (AuthType) {
6
+ AuthType["NONE"] = "none";
7
+ AuthType["API_KEY"] = "apiKey";
8
+ AuthType["BEARER_TOKEN"] = "bearer";
9
+ AuthType["BASIC_AUTH"] = "basic";
10
+ AuthType["OAUTH2"] = "oauth2";
11
+ AuthType["CUSTOM"] = "custom";
12
+ })(AuthType || (exports.AuthType = AuthType = {}));
@@ -0,0 +1,123 @@
1
+ import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ import { CacheOptions } from '../../cache/interfaces/cache-options.interface';
3
+ import { LogCleanupConfig } from '../services/log-cleanup.service';
4
+ export interface HttpClientConfig {
5
+ baseURL?: string;
6
+ timeout?: number;
7
+ retry?: RetryConfig;
8
+ circuitBreaker?: CircuitBreakerConfig;
9
+ cache?: HttpCacheConfig;
10
+ proxy?: ProxyConfig;
11
+ logging?: LoggingConfig;
12
+ logCleanup?: LogCleanupConfig;
13
+ interceptors?: InterceptorConfig;
14
+ connectionPool?: ConnectionPoolConfig;
15
+ }
16
+ export interface RetryConfig {
17
+ enabled: boolean;
18
+ retries?: number;
19
+ retryDelay?: (retryCount: number) => number;
20
+ retryCondition?: (error: any) => boolean;
21
+ shouldResetTimeout?: boolean;
22
+ onRetry?: (retryCount: number, error: any, requestConfig: AxiosRequestConfig) => void;
23
+ }
24
+ export interface CircuitBreakerConfig {
25
+ enabled: boolean;
26
+ failureThreshold: number;
27
+ recoveryTimeoutMs: number;
28
+ monitoringPeriodMs: number;
29
+ minimumThroughputThreshold: number;
30
+ countHalfOpenCalls: boolean;
31
+ }
32
+ export interface HttpCacheConfig {
33
+ enabled: boolean;
34
+ options?: Omit<CacheOptions, 'ttl' | 'namespace'>;
35
+ defaultTtl?: number;
36
+ cacheableMethods: string[];
37
+ cacheableStatusCodes: number[];
38
+ keyGenerator?: (config: AxiosRequestConfig) => string;
39
+ }
40
+ export interface ProxyConfig {
41
+ enabled: boolean;
42
+ host?: string;
43
+ port?: number;
44
+ protocol?: 'http' | 'https';
45
+ auth?: {
46
+ username: string;
47
+ password: string;
48
+ };
49
+ }
50
+ export interface LoggingConfig {
51
+ enabled: boolean;
52
+ logRequests: boolean;
53
+ logResponses: boolean;
54
+ logErrors: boolean;
55
+ logHeaders: boolean;
56
+ logBody: boolean;
57
+ maxBodyLength: number;
58
+ sanitizeHeaders: string[];
59
+ logLevel: 'debug' | 'info' | 'warn' | 'error';
60
+ databaseLogging?: {
61
+ enabled: boolean;
62
+ dataSource: string;
63
+ tableName: string;
64
+ };
65
+ }
66
+ export interface InterceptorConfig {
67
+ requestInterceptors: string[];
68
+ responseInterceptors: string[];
69
+ errorInterceptors: string[];
70
+ }
71
+ export interface ConnectionPoolConfig {
72
+ enabled: boolean;
73
+ maxSockets: number;
74
+ maxFreeSockets: number;
75
+ timeoutMs: number;
76
+ keepAlive: boolean;
77
+ }
78
+ export interface HttpContext {
79
+ requestId: string;
80
+ startTime: number;
81
+ attemptCount: number;
82
+ parentRequestId?: string;
83
+ traceId?: string;
84
+ userId?: string;
85
+ correlationId?: string;
86
+ metadata: Record<string, any>;
87
+ }
88
+ export interface HttpLogEntity {
89
+ id: string;
90
+ requestId: string;
91
+ method: string;
92
+ url: string;
93
+ headers: Record<string, string>;
94
+ body?: string;
95
+ statusCode?: number;
96
+ responseTime: number;
97
+ attemptCount: number;
98
+ success: boolean;
99
+ errorMessage?: string;
100
+ userId?: string;
101
+ timestamp: Date;
102
+ metadata: Record<string, any>;
103
+ }
104
+ export interface HttpInterceptor {
105
+ name: string;
106
+ order: number;
107
+ intercept(request: AxiosRequestConfig, next: () => Promise<AxiosResponse>): Promise<AxiosResponse>;
108
+ }
109
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
110
+ export interface HttpStats {
111
+ totalRequests: number;
112
+ successfulRequests: number;
113
+ failedRequests: number;
114
+ averageResponseTime: number;
115
+ requestsByMethod: Record<HttpMethod, number>;
116
+ requestsByStatus: Record<number, number>;
117
+ circuitBreakerStats: Record<string, any>;
118
+ cacheStats: {
119
+ hits: number;
120
+ misses: number;
121
+ hitRate: number;
122
+ };
123
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,41 @@
1
+ import { ApiClientConfig, ApiClientInstanceConfig, ApiClientRegistryConfig, AuthType, OAuth2Config, ResponseTransformerConfig } from '../interfaces/api-client-config.interface';
2
+ import { HttpClientService } from './http-client.service';
3
+ import { HttpCircuitBreakerService } from './circuit-breaker.service';
4
+ import { HttpLoggingService } from './logging.service';
5
+ import { HttpCacheService } from './cache.service';
6
+ export { ApiClientInstanceConfig, AuthType, OAuth2Config, ResponseTransformerConfig, };
7
+ export declare class ApiClientRegistryService {
8
+ private readonly httpClientService;
9
+ private readonly circuitBreakerService;
10
+ private readonly loggingService;
11
+ private readonly cacheService;
12
+ private readonly logger;
13
+ private readonly clients;
14
+ private readonly clientConfigs;
15
+ private readonly globalDefaults;
16
+ constructor(httpClientService: HttpClientService, circuitBreakerService: HttpCircuitBreakerService, loggingService: HttpLoggingService, cacheService: HttpCacheService, globalConfig?: ApiClientRegistryConfig);
17
+ createClient<T = any>(config: ApiClientInstanceConfig): T;
18
+ getClient<T = any>(name: string): T;
19
+ listClients(): string[];
20
+ updateClient(name: string, config: Partial<ApiClientConfig>): void;
21
+ removeClient(name: string): void;
22
+ getClientConfig(name: string): ApiClientConfig | undefined;
23
+ getAllClientConfigs(): Record<string, ApiClientConfig>;
24
+ createClients(configs: ApiClientInstanceConfig[]): void;
25
+ getGlobalConfig(): ApiClientRegistryConfig;
26
+ updateGlobalConfig(config: Partial<ApiClientRegistryConfig>): void;
27
+ getAllStats(): Record<string, any>;
28
+ resetAllStats(): void;
29
+ healthCheck(): Promise<{
30
+ status: 'healthy' | 'unhealthy';
31
+ clients: Record<string, {
32
+ status: 'healthy' | 'unhealthy';
33
+ error?: string;
34
+ }>;
35
+ }>;
36
+ private createAxiosInstance;
37
+ private applyAuthentication;
38
+ private applyResponseTransformer;
39
+ private extractDataByPath;
40
+ private mergeEnvironmentConfig;
41
+ }