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

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 (63) hide show
  1. package/common/utils.d.ts +1 -0
  2. package/common/utils.js +6 -0
  3. package/http-client/config/http-client.config.d.ts +6 -0
  4. package/http-client/config/http-client.config.js +87 -0
  5. package/http-client/config/index.d.ts +1 -0
  6. package/http-client/config/index.js +17 -0
  7. package/http-client/decorators/http-client.decorators.d.ts +72 -0
  8. package/http-client/decorators/http-client.decorators.js +204 -0
  9. package/http-client/decorators/index.d.ts +1 -0
  10. package/http-client/decorators/index.js +17 -0
  11. package/http-client/entities/http-log.entity.d.ts +98 -0
  12. package/http-client/entities/http-log.entity.js +143 -0
  13. package/http-client/entities/index.d.ts +1 -0
  14. package/http-client/entities/index.js +17 -0
  15. package/http-client/errors/http-client.errors.d.ts +56 -0
  16. package/http-client/errors/http-client.errors.js +149 -0
  17. package/http-client/errors/index.d.ts +1 -0
  18. package/http-client/errors/index.js +17 -0
  19. package/http-client/examples/advanced-usage.example.d.ts +23 -0
  20. package/http-client/examples/advanced-usage.example.js +319 -0
  21. package/http-client/examples/basic-usage.example.d.ts +61 -0
  22. package/http-client/examples/basic-usage.example.js +171 -0
  23. package/http-client/examples/index.d.ts +3 -0
  24. package/http-client/examples/index.js +19 -0
  25. package/http-client/examples/multi-api-configuration.example.d.ts +98 -0
  26. package/http-client/examples/multi-api-configuration.example.js +353 -0
  27. package/http-client/http-client.module.d.ts +11 -0
  28. package/http-client/http-client.module.js +254 -0
  29. package/http-client/index.d.ts +10 -0
  30. package/http-client/index.js +27 -0
  31. package/http-client/interfaces/api-client-config.interface.d.ts +152 -0
  32. package/http-client/interfaces/api-client-config.interface.js +12 -0
  33. package/http-client/interfaces/http-client-config.interface.d.ts +123 -0
  34. package/http-client/interfaces/http-client-config.interface.js +2 -0
  35. package/http-client/services/api-client-registry.service.d.ts +40 -0
  36. package/http-client/services/api-client-registry.service.js +411 -0
  37. package/http-client/services/cache.service.d.ts +24 -0
  38. package/http-client/services/cache.service.js +264 -0
  39. package/http-client/services/circuit-breaker.service.d.ts +33 -0
  40. package/http-client/services/circuit-breaker.service.js +180 -0
  41. package/http-client/services/http-client.service.d.ts +43 -0
  42. package/http-client/services/http-client.service.js +384 -0
  43. package/http-client/services/http-log-query.service.d.ts +56 -0
  44. package/http-client/services/http-log-query.service.js +414 -0
  45. package/http-client/services/index.d.ts +7 -0
  46. package/http-client/services/index.js +23 -0
  47. package/http-client/services/log-cleanup.service.d.ts +64 -0
  48. package/http-client/services/log-cleanup.service.js +268 -0
  49. package/http-client/services/logging.service.d.ts +36 -0
  50. package/http-client/services/logging.service.js +445 -0
  51. package/http-client/utils/call-stack-extractor.util.d.ts +29 -0
  52. package/http-client/utils/call-stack-extractor.util.js +138 -0
  53. package/http-client/utils/context-extractor.util.d.ts +44 -0
  54. package/http-client/utils/context-extractor.util.js +173 -0
  55. package/http-client/utils/curl-generator.util.d.ts +9 -0
  56. package/http-client/utils/curl-generator.util.js +169 -0
  57. package/http-client/utils/index.d.ts +4 -0
  58. package/http-client/utils/index.js +20 -0
  59. package/http-client/utils/retry-recorder.util.d.ts +30 -0
  60. package/http-client/utils/retry-recorder.util.js +143 -0
  61. package/index.d.ts +1 -0
  62. package/index.js +1 -0
  63. package/package.json +1 -1
@@ -0,0 +1,319 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.PaymentHttpService = exports.GitHubHttpService = void 0;
22
+ const common_1 = require("@nestjs/common");
23
+ const decorators_1 = require("../decorators");
24
+ const http_client_service_1 = require("../services/http-client.service");
25
+ let GitHubHttpService = class GitHubHttpService {
26
+ constructor(httpClient) {
27
+ this.httpClient = httpClient;
28
+ }
29
+ getUser(username) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return this.httpClient.get(`/users/${username}`);
32
+ });
33
+ }
34
+ searchRepositories(query_1) {
35
+ return __awaiter(this, arguments, void 0, function* (query, sort = 'stars', order = 'desc') {
36
+ return this.httpClient.get('/search/repositories', {
37
+ params: {
38
+ q: query,
39
+ sort,
40
+ order,
41
+ per_page: 20,
42
+ },
43
+ });
44
+ });
45
+ }
46
+ getUserRepositories(username) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return this.httpClient.get(`/users/${username}/repos`, {
49
+ params: {
50
+ type: 'owner',
51
+ sort: 'updated',
52
+ per_page: 50,
53
+ },
54
+ });
55
+ });
56
+ }
57
+ createRepository(repoData, token) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ return this.httpClient.post('/user/repos', repoData, {
60
+ headers: {
61
+ Authorization: `token ${token}`,
62
+ Accept: 'application/vnd.github.v3+json',
63
+ },
64
+ });
65
+ });
66
+ }
67
+ getRepositoryContributors(owner, repo) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ return this.httpClient.get(`/repos/${owner}/${repo}/contributors`);
70
+ });
71
+ }
72
+ getMultipleUsers(usernames) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ const promises = usernames.map((username) => this.getUser(username).catch((error) => {
75
+ console.error(`Failed to get user ${username}:`, error.message);
76
+ return null;
77
+ }));
78
+ return Promise.all(promises);
79
+ });
80
+ }
81
+ getRepositoryDetails(owner, repo, options) {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ return this.httpClient.get(`/repos/${owner}/${repo}`);
84
+ });
85
+ }
86
+ };
87
+ exports.GitHubHttpService = GitHubHttpService;
88
+ __decorate([
89
+ (0, decorators_1.HttpRetry)({
90
+ retries: 5,
91
+ retryDelay: (retryCount) => Math.pow(2, retryCount) * 1000,
92
+ retryCondition: (error) => {
93
+ if (!error.response)
94
+ return true;
95
+ const status = error.response.status;
96
+ return status >= 500 || status === 429;
97
+ },
98
+ }),
99
+ (0, decorators_1.HttpCircuitBreaker)({
100
+ failureThreshold: 3,
101
+ recoveryTimeoutMs: 30000,
102
+ }),
103
+ (0, decorators_1.HttpCacheable)({
104
+ ttl: 300000,
105
+ layers: ['cls', 'memory', 'redis'],
106
+ namespace: 'github',
107
+ }),
108
+ (0, decorators_1.HttpLogRequest)({
109
+ databaseLog: true,
110
+ logHeaders: true,
111
+ logBody: false,
112
+ serviceClass: 'GitHubHttpService',
113
+ methodName: 'getUser',
114
+ operationName: 'github.getUser',
115
+ }),
116
+ (0, decorators_1.HttpTimeout)(15000),
117
+ __metadata("design:type", Function),
118
+ __metadata("design:paramtypes", [String]),
119
+ __metadata("design:returntype", Promise)
120
+ ], GitHubHttpService.prototype, "getUser", null);
121
+ __decorate([
122
+ (0, decorators_1.HttpRetry)({ retries: 3 }),
123
+ (0, decorators_1.HttpCacheable)({
124
+ ttl: 600000,
125
+ layers: ['memory', 'redis'],
126
+ namespace: 'github-search',
127
+ condition: (args) => args[0].length > 2,
128
+ }),
129
+ __metadata("design:type", Function),
130
+ __metadata("design:paramtypes", [String, String, String]),
131
+ __metadata("design:returntype", Promise)
132
+ ], GitHubHttpService.prototype, "searchRepositories", null);
133
+ __decorate([
134
+ (0, decorators_1.HttpUseProxy)({
135
+ host: 'proxy.example.com',
136
+ port: 8080,
137
+ protocol: 'http',
138
+ }),
139
+ (0, decorators_1.HttpCacheable)({
140
+ ttl: 120000,
141
+ namespace: 'github-repos',
142
+ }),
143
+ __metadata("design:type", Function),
144
+ __metadata("design:paramtypes", [String]),
145
+ __metadata("design:returntype", Promise)
146
+ ], GitHubHttpService.prototype, "getUserRepositories", null);
147
+ __decorate([
148
+ (0, decorators_1.HttpLogRequest)({
149
+ logHeaders: true,
150
+ logBody: true,
151
+ databaseLog: true,
152
+ sanitizeHeaders: ['authorization', 'x-api-key'],
153
+ }),
154
+ __metadata("design:type", Function),
155
+ __metadata("design:paramtypes", [Object, String]),
156
+ __metadata("design:returntype", Promise)
157
+ ], GitHubHttpService.prototype, "createRepository", null);
158
+ __decorate([
159
+ (0, decorators_1.HttpCircuitBreaker)({
160
+ failureThreshold: 5,
161
+ recoveryTimeoutMs: 60000,
162
+ }),
163
+ (0, decorators_1.HttpCacheable)({
164
+ ttl: 900000,
165
+ namespace: 'github-contributors',
166
+ }),
167
+ __metadata("design:type", Function),
168
+ __metadata("design:paramtypes", [String, String]),
169
+ __metadata("design:returntype", Promise)
170
+ ], GitHubHttpService.prototype, "getRepositoryContributors", null);
171
+ __decorate([
172
+ (0, decorators_1.HttpCacheable)({
173
+ ttl: 120000,
174
+ layers: ['memory'],
175
+ namespace: 'github-repo-details',
176
+ condition: (args) => { var _a; return ((_a = args[2]) === null || _a === void 0 ? void 0 : _a.public) === true; },
177
+ unless: (result, args) => (result === null || result === void 0 ? void 0 : result.archived) === true,
178
+ }),
179
+ __metadata("design:type", Function),
180
+ __metadata("design:paramtypes", [String, String, Object]),
181
+ __metadata("design:returntype", Promise)
182
+ ], GitHubHttpService.prototype, "getRepositoryDetails", null);
183
+ exports.GitHubHttpService = GitHubHttpService = __decorate([
184
+ (0, decorators_1.HttpClient)({
185
+ baseURL: 'https://api.github.com',
186
+ timeout: 10000,
187
+ cache: {
188
+ enabled: true,
189
+ defaultTtl: 300000,
190
+ options: {
191
+ layers: ['memory', 'redis'],
192
+ },
193
+ },
194
+ logging: {
195
+ enabled: true,
196
+ logHeaders: true,
197
+ logBody: true,
198
+ sanitizeHeaders: ['authorization'],
199
+ },
200
+ }),
201
+ (0, common_1.Injectable)(),
202
+ __metadata("design:paramtypes", [http_client_service_1.HttpClientService])
203
+ ], GitHubHttpService);
204
+ let PaymentHttpService = class PaymentHttpService {
205
+ constructor(httpClient) {
206
+ this.httpClient = httpClient;
207
+ }
208
+ createPayment(paymentData, apiKey) {
209
+ return __awaiter(this, void 0, void 0, function* () {
210
+ return this.httpClient.post('/payments', paymentData, {
211
+ headers: {
212
+ Authorization: `Bearer ${apiKey}`,
213
+ 'X-Idempotency-Key': this.generateIdempotencyKey(),
214
+ 'Content-Type': 'application/json',
215
+ },
216
+ });
217
+ });
218
+ }
219
+ getPaymentStatus(paymentId, apiKey) {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ return this.httpClient.get(`/payments/${paymentId}`, {
222
+ headers: {
223
+ Authorization: `Bearer ${apiKey}`,
224
+ },
225
+ });
226
+ });
227
+ }
228
+ refundPayment(paymentId, refundData, apiKey) {
229
+ return __awaiter(this, void 0, void 0, function* () {
230
+ return this.httpClient.post(`/payments/${paymentId}/refund`, refundData, {
231
+ headers: {
232
+ Authorization: `Bearer ${apiKey}`,
233
+ 'X-Idempotency-Key': this.generateIdempotencyKey(),
234
+ },
235
+ });
236
+ });
237
+ }
238
+ callExternalApi(url_1) {
239
+ return __awaiter(this, arguments, void 0, function* (url, method = 'GET', data) {
240
+ const { CallStackExtractor } = require('../utils');
241
+ CallStackExtractor.setCallInfo('PaymentHttpService', 'callExternalApi', `payment.${method.toLowerCase()}`);
242
+ try {
243
+ return this.httpClient.request({
244
+ url,
245
+ method,
246
+ data,
247
+ headers: {
248
+ 'Content-Type': 'application/json',
249
+ Authorization: 'Bearer token123',
250
+ },
251
+ });
252
+ }
253
+ finally {
254
+ CallStackExtractor.clearCallInfo();
255
+ }
256
+ });
257
+ }
258
+ generateIdempotencyKey() {
259
+ return `pay_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
260
+ }
261
+ };
262
+ exports.PaymentHttpService = PaymentHttpService;
263
+ __decorate([
264
+ (0, decorators_1.HttpLogRequest)({
265
+ logHeaders: false,
266
+ logBody: false,
267
+ databaseLog: false,
268
+ }),
269
+ (0, decorators_1.HttpTimeout)(10000),
270
+ __metadata("design:type", Function),
271
+ __metadata("design:paramtypes", [Object, String]),
272
+ __metadata("design:returntype", Promise)
273
+ ], PaymentHttpService.prototype, "createPayment", null);
274
+ __decorate([
275
+ (0, decorators_1.HttpCacheable)({
276
+ ttl: 30000,
277
+ layers: ['redis'],
278
+ namespace: 'payment-status',
279
+ }),
280
+ __metadata("design:type", Function),
281
+ __metadata("design:paramtypes", [String, String]),
282
+ __metadata("design:returntype", Promise)
283
+ ], PaymentHttpService.prototype, "getPaymentStatus", null);
284
+ __decorate([
285
+ (0, decorators_1.HttpRetry)({
286
+ retries: 2,
287
+ retryDelay: (retryCount) => retryCount * 2000,
288
+ retryCondition: (error) => {
289
+ if (!error.response)
290
+ return true;
291
+ return error.response.status >= 500;
292
+ },
293
+ }),
294
+ (0, decorators_1.HttpLogRequest)({
295
+ logHeaders: false,
296
+ logBody: false,
297
+ databaseLog: true,
298
+ }),
299
+ __metadata("design:type", Function),
300
+ __metadata("design:paramtypes", [String, Object, String]),
301
+ __metadata("design:returntype", Promise)
302
+ ], PaymentHttpService.prototype, "refundPayment", null);
303
+ exports.PaymentHttpService = PaymentHttpService = __decorate([
304
+ (0, decorators_1.HttpClient)({
305
+ baseURL: 'https://api.payment-provider.com',
306
+ timeout: 15000,
307
+ retry: {
308
+ enabled: false,
309
+ },
310
+ logging: {
311
+ enabled: true,
312
+ logHeaders: false,
313
+ logBody: false,
314
+ sanitizeHeaders: ['authorization', 'x-api-key', 'x-client-secret'],
315
+ },
316
+ }),
317
+ (0, common_1.Injectable)(),
318
+ __metadata("design:paramtypes", [http_client_service_1.HttpClientService])
319
+ ], PaymentHttpService);
@@ -0,0 +1,61 @@
1
+ import { HttpClientService, HttpLogQueryService } from '../services';
2
+ import { HttpLogQueryOptions } from '../entities';
3
+ export declare class BasicHttpExample {
4
+ private readonly httpClient;
5
+ private readonly logQueryService;
6
+ constructor(httpClient: HttpClientService, logQueryService: HttpLogQueryService);
7
+ getUser(id: string): Promise<any>;
8
+ searchUsers(query: string, page?: number, limit?: number): Promise<any>;
9
+ createUser(userData: any): Promise<any>;
10
+ updateUser(id: string, userData: any): Promise<any>;
11
+ deleteUser(id: string): Promise<any>;
12
+ uploadFile(file: Buffer, filename: string): Promise<any>;
13
+ customRequest(): Promise<any>;
14
+ getStatistics(): any;
15
+ resetStatistics(): void;
16
+ generateCurlForRequest(url: string, method?: string, data?: any): string;
17
+ queryHttpLogs(options?: HttpLogQueryOptions): Promise<{
18
+ logs: import("../entities").HttpLogEntity[];
19
+ total: number;
20
+ page: number;
21
+ limit: number;
22
+ totalPages: number;
23
+ }>;
24
+ findErrorLogs(limit?: number): Promise<{
25
+ logs: import("../entities").HttpLogEntity[];
26
+ total: number;
27
+ }>;
28
+ findSlowRequests(minResponseTime?: number): Promise<{
29
+ logs: import("../entities").HttpLogEntity[];
30
+ total: number;
31
+ }>;
32
+ findRetryLogs(minRetries?: number): Promise<{
33
+ logs: import("../entities").HttpLogEntity[];
34
+ total: number;
35
+ }>;
36
+ findLogsByServiceClass(serviceClass: string, limit?: number): Promise<{
37
+ logs: import("../entities").HttpLogEntity[];
38
+ total: number;
39
+ page: number;
40
+ limit: number;
41
+ totalPages: number;
42
+ }>;
43
+ findLogsByMethodName(methodName: string, limit?: number): Promise<{
44
+ logs: import("../entities").HttpLogEntity[];
45
+ total: number;
46
+ page: number;
47
+ limit: number;
48
+ totalPages: number;
49
+ }>;
50
+ findLogsByOperationName(operationName: string, limit?: number): Promise<{
51
+ logs: import("../entities").HttpLogEntity[];
52
+ total: number;
53
+ page: number;
54
+ limit: number;
55
+ totalPages: number;
56
+ }>;
57
+ getHttpStats(startDate?: Date, endDate?: Date): Promise<import("../entities").HttpLogStats>;
58
+ findLogByRequestId(requestId: string): Promise<import("../entities").HttpLogEntity>;
59
+ findLogsByCorrelationId(correlationId: string): Promise<any>;
60
+ cleanupOldLogs(daysToKeep?: number): Promise<number>;
61
+ }
@@ -0,0 +1,171 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.BasicHttpExample = void 0;
22
+ const common_1 = require("@nestjs/common");
23
+ const services_1 = require("../services");
24
+ let BasicHttpExample = class BasicHttpExample {
25
+ constructor(httpClient, logQueryService) {
26
+ this.httpClient = httpClient;
27
+ this.logQueryService = logQueryService;
28
+ }
29
+ getUser(id) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return this.httpClient.get(`/users/${id}`);
32
+ });
33
+ }
34
+ searchUsers(query_1) {
35
+ return __awaiter(this, arguments, void 0, function* (query, page = 1, limit = 10) {
36
+ return this.httpClient.get('/users', {
37
+ params: {
38
+ q: query,
39
+ page,
40
+ limit,
41
+ },
42
+ });
43
+ });
44
+ }
45
+ createUser(userData) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ return this.httpClient.post('/users', userData, {
48
+ headers: {
49
+ 'Content-Type': 'application/json',
50
+ },
51
+ });
52
+ });
53
+ }
54
+ updateUser(id, userData) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ return this.httpClient.put(`/users/${id}`, userData);
57
+ });
58
+ }
59
+ deleteUser(id) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ return this.httpClient.delete(`/users/${id}`);
62
+ });
63
+ }
64
+ uploadFile(file, filename) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const formData = new FormData();
67
+ formData.append('file', new Blob([file]), filename);
68
+ return this.httpClient.post('/upload', formData, {
69
+ headers: {
70
+ 'Content-Type': 'multipart/form-data',
71
+ },
72
+ });
73
+ });
74
+ }
75
+ customRequest() {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ return this.httpClient.request({
78
+ method: 'PATCH',
79
+ url: '/users/123',
80
+ data: { name: 'New Name' },
81
+ headers: {
82
+ Authorization: 'Bearer token123',
83
+ 'X-Custom-Header': 'custom-value',
84
+ },
85
+ timeout: 5000,
86
+ params: {
87
+ fields: 'id,name,email',
88
+ },
89
+ });
90
+ });
91
+ }
92
+ getStatistics() {
93
+ return this.httpClient.getStats();
94
+ }
95
+ resetStatistics() {
96
+ this.httpClient.resetStats();
97
+ }
98
+ generateCurlForRequest(url, method = 'GET', data) {
99
+ const config = {
100
+ url,
101
+ method,
102
+ data,
103
+ headers: {
104
+ 'Content-Type': 'application/json',
105
+ 'User-Agent': 'MyApp/1.0',
106
+ },
107
+ };
108
+ return this.httpClient.generateCurlCommand(config);
109
+ }
110
+ queryHttpLogs() {
111
+ return __awaiter(this, arguments, void 0, function* (options = {}) {
112
+ return this.logQueryService.findLogs(options);
113
+ });
114
+ }
115
+ findErrorLogs() {
116
+ return __awaiter(this, arguments, void 0, function* (limit = 10) {
117
+ return this.logQueryService.findErrorLogs({ limit });
118
+ });
119
+ }
120
+ findSlowRequests() {
121
+ return __awaiter(this, arguments, void 0, function* (minResponseTime = 5000) {
122
+ return this.logQueryService.findSlowRequests(minResponseTime);
123
+ });
124
+ }
125
+ findRetryLogs() {
126
+ return __awaiter(this, arguments, void 0, function* (minRetries = 2) {
127
+ return this.logQueryService.findRetryLogs({ minRetries });
128
+ });
129
+ }
130
+ findLogsByServiceClass(serviceClass_1) {
131
+ return __awaiter(this, arguments, void 0, function* (serviceClass, limit = 20) {
132
+ return this.logQueryService.findLogs({ serviceClass, limit });
133
+ });
134
+ }
135
+ findLogsByMethodName(methodName_1) {
136
+ return __awaiter(this, arguments, void 0, function* (methodName, limit = 20) {
137
+ return this.logQueryService.findLogs({ methodName, limit });
138
+ });
139
+ }
140
+ findLogsByOperationName(operationName_1) {
141
+ return __awaiter(this, arguments, void 0, function* (operationName, limit = 20) {
142
+ return this.logQueryService.findLogs({ operationName, limit });
143
+ });
144
+ }
145
+ getHttpStats(startDate, endDate) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ return this.logQueryService.getStats({ startDate, endDate });
148
+ });
149
+ }
150
+ findLogByRequestId(requestId) {
151
+ return __awaiter(this, void 0, void 0, function* () {
152
+ return this.logQueryService.findLogByRequestId(requestId);
153
+ });
154
+ }
155
+ findLogsByCorrelationId(correlationId) {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ return this.logQueryService.findLogsByCorrelationId(correlationId);
158
+ });
159
+ }
160
+ cleanupOldLogs() {
161
+ return __awaiter(this, arguments, void 0, function* (daysToKeep = 30) {
162
+ return this.logQueryService.deleteOldLogs(daysToKeep);
163
+ });
164
+ }
165
+ };
166
+ exports.BasicHttpExample = BasicHttpExample;
167
+ exports.BasicHttpExample = BasicHttpExample = __decorate([
168
+ (0, common_1.Injectable)(),
169
+ __metadata("design:paramtypes", [services_1.HttpClientService,
170
+ services_1.HttpLogQueryService])
171
+ ], BasicHttpExample);
@@ -0,0 +1,3 @@
1
+ export * from './basic-usage.example';
2
+ export * from './advanced-usage.example';
3
+ export * from './multi-api-configuration.example';
@@ -0,0 +1,19 @@
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
+ __exportStar(require("./basic-usage.example"), exports);
18
+ __exportStar(require("./advanced-usage.example"), exports);
19
+ __exportStar(require("./multi-api-configuration.example"), exports);
@@ -0,0 +1,98 @@
1
+ import { ApiClientInstanceConfig, ApiClientRegistryService } from '../services/api-client-registry.service';
2
+ export declare class GitHubApiService {
3
+ private readonly apiRegistry;
4
+ constructor(apiRegistry: ApiClientRegistryService);
5
+ get github(): GitHubApiClient;
6
+ private initializeClients;
7
+ }
8
+ export interface GitHubApiClient {
9
+ get<T = any>(url: string, config?: any): Promise<T>;
10
+ post<T = any>(url: string, data?: any, config?: any): Promise<T>;
11
+ put<T = any>(url: string, data?: any, config?: any): Promise<T>;
12
+ delete<T = any>(url: string, config?: any): Promise<T>;
13
+ request<T = any>(config: any): Promise<T>;
14
+ getStats(): any;
15
+ resetStats(): void;
16
+ }
17
+ export declare class StripeApiService {
18
+ private readonly apiRegistry;
19
+ constructor(apiRegistry: ApiClientRegistryService);
20
+ get stripe(): StripeApiClient;
21
+ private initializeClients;
22
+ }
23
+ export interface StripeApiClient {
24
+ get<T = any>(url: string, config?: any): Promise<T>;
25
+ post<T = any>(url: string, data?: any, config?: any): Promise<T>;
26
+ request<T = any>(config: any): Promise<T>;
27
+ getStats(): any;
28
+ resetStats(): void;
29
+ }
30
+ export declare class WeChatApiService {
31
+ private readonly apiRegistry;
32
+ constructor(apiRegistry: ApiClientRegistryService);
33
+ get wechat(): WeChatApiClient;
34
+ private initializeClients;
35
+ }
36
+ export interface WeChatApiClient {
37
+ get<T = any>(url: string, config?: any): Promise<T>;
38
+ post<T = any>(url: string, data?: any, config?: any): Promise<T>;
39
+ request<T = any>(config: any): Promise<T>;
40
+ getStats(): any;
41
+ resetStats(): void;
42
+ }
43
+ export declare class CustomApiService {
44
+ private readonly apiRegistry;
45
+ constructor(apiRegistry: ApiClientRegistryService);
46
+ get customApi(): CustomApiClient;
47
+ private initializeClients;
48
+ private getValidToken;
49
+ private refreshToken;
50
+ private generateSignature;
51
+ }
52
+ export interface CustomApiClient {
53
+ get<T = any>(url: string, config?: any): Promise<T>;
54
+ post<T = any>(url: string, data?: any, config?: any): Promise<T>;
55
+ put<T = any>(url: string, data?: any, config?: any): Promise<T>;
56
+ patch<T = any>(url: string, data?: any, config?: any): Promise<T>;
57
+ delete<T = any>(url: string, config?: any): Promise<T>;
58
+ request<T = any>(config: any): Promise<T>;
59
+ getStats(): any;
60
+ resetStats(): void;
61
+ }
62
+ export declare class ApiManagementService {
63
+ private readonly apiRegistry;
64
+ constructor(apiRegistry: ApiClientRegistryService);
65
+ createDynamicClient(name: string, config: Partial<ApiClientInstanceConfig>): any;
66
+ getAllStats(): Record<string, any>;
67
+ resetAllStats(): void;
68
+ healthCheck(): Promise<{
69
+ status: "healthy" | "unhealthy";
70
+ clients: Record<string, {
71
+ status: "healthy" | "unhealthy";
72
+ error?: string;
73
+ }>;
74
+ }>;
75
+ createMultipleClients(configs: ApiClientInstanceConfig[]): void;
76
+ listClients(): string[];
77
+ }
78
+ export declare class ExampleController {
79
+ private readonly githubApi;
80
+ private readonly stripeApi;
81
+ private readonly wechatApi;
82
+ private readonly customApi;
83
+ private readonly apiManagement;
84
+ constructor(githubApi: GitHubApiService, stripeApi: StripeApiService, wechatApi: WeChatApiService, customApi: CustomApiService, apiManagement: ApiManagementService);
85
+ getGitHubUser(username: string): Promise<any>;
86
+ createStripePayment(amount: number, currency: string): Promise<any>;
87
+ sendWeChatMessage(openid: string, content: string): Promise<any>;
88
+ getCustomData(id: string): Promise<any>;
89
+ callDynamicApi(url: string): Promise<any>;
90
+ getApiHealth(): Promise<{
91
+ status: "healthy" | "unhealthy";
92
+ clients: Record<string, {
93
+ status: "healthy" | "unhealthy";
94
+ error?: string;
95
+ }>;
96
+ }>;
97
+ getApiStats(): Promise<Record<string, any>>;
98
+ }