@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,53 @@
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
+ findLogsByServiceName(serviceName: string, limit?: number): Promise<{
37
+ logs: import("../entities").HttpLogEntity[];
38
+ total: number;
39
+ page: number;
40
+ limit: number;
41
+ totalPages: number;
42
+ }>;
43
+ findLogsByOperationName(operationName: string, limit?: number): Promise<{
44
+ logs: import("../entities").HttpLogEntity[];
45
+ total: number;
46
+ page: number;
47
+ limit: number;
48
+ totalPages: number;
49
+ }>;
50
+ getHttpStats(startDate?: Date, endDate?: Date): Promise<import("../entities").HttpLogStats>;
51
+ findLogByRequestId(requestId: string): Promise<import("../entities").HttpLogEntity>;
52
+ cleanupOldLogs(daysToKeep?: number): Promise<number>;
53
+ }
@@ -0,0 +1,161 @@
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([new Uint8Array(file)], { type: 'application/octet-stream' }), 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
+ findLogsByServiceName(serviceName_1) {
131
+ return __awaiter(this, arguments, void 0, function* (serviceName, limit = 20) {
132
+ return this.logQueryService.findLogs({ serviceName, limit });
133
+ });
134
+ }
135
+ findLogsByOperationName(operationName_1) {
136
+ return __awaiter(this, arguments, void 0, function* (operationName, limit = 20) {
137
+ return this.logQueryService.findLogs({ operationName, limit });
138
+ });
139
+ }
140
+ getHttpStats(startDate, endDate) {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ return this.logQueryService.getStats({ startDate, endDate });
143
+ });
144
+ }
145
+ findLogByRequestId(requestId) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ return this.logQueryService.findLogByRequestId(requestId);
148
+ });
149
+ }
150
+ cleanupOldLogs() {
151
+ return __awaiter(this, arguments, void 0, function* (daysToKeep = 30) {
152
+ return this.logQueryService.deleteOldLogs(daysToKeep);
153
+ });
154
+ }
155
+ };
156
+ exports.BasicHttpExample = BasicHttpExample;
157
+ exports.BasicHttpExample = BasicHttpExample = __decorate([
158
+ (0, common_1.Injectable)(),
159
+ __metadata("design:paramtypes", [services_1.HttpClientService,
160
+ services_1.HttpLogQueryService])
161
+ ], 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
+ }
@@ -0,0 +1,353 @@
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.ExampleController = exports.ApiManagementService = exports.CustomApiService = exports.WeChatApiService = exports.StripeApiService = exports.GitHubApiService = void 0;
22
+ const common_1 = require("@nestjs/common");
23
+ const api_client_registry_service_1 = require("../services/api-client-registry.service");
24
+ let GitHubApiService = class GitHubApiService {
25
+ constructor(apiRegistry) {
26
+ this.apiRegistry = apiRegistry;
27
+ this.initializeClients();
28
+ }
29
+ get github() {
30
+ return this.apiRegistry.getClient('github');
31
+ }
32
+ initializeClients() {
33
+ this.apiRegistry.createClient({
34
+ name: 'github',
35
+ baseURL: 'https://api.github.com',
36
+ auth: {
37
+ type: api_client_registry_service_1.AuthType.BEARER_TOKEN,
38
+ config: {
39
+ token: process.env.GITHUB_TOKEN,
40
+ },
41
+ },
42
+ responseTransformer: {
43
+ dataPath: 'data',
44
+ success: (response) => response.data,
45
+ error: (error) => {
46
+ var _a, _b;
47
+ if ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) {
48
+ throw new Error(`GitHub API Error: ${error.response.data.message}`);
49
+ }
50
+ throw error;
51
+ },
52
+ },
53
+ retry: {
54
+ enabled: true,
55
+ retries: 3,
56
+ retryCondition: (error) => {
57
+ var _a, _b;
58
+ return (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 403 || ((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) === 429);
59
+ },
60
+ },
61
+ responseTimeWarningThreshold: 2000,
62
+ tags: ['github', 'vcs'],
63
+ });
64
+ }
65
+ };
66
+ exports.GitHubApiService = GitHubApiService;
67
+ exports.GitHubApiService = GitHubApiService = __decorate([
68
+ (0, common_1.Injectable)(),
69
+ __metadata("design:paramtypes", [api_client_registry_service_1.ApiClientRegistryService])
70
+ ], GitHubApiService);
71
+ let StripeApiService = class StripeApiService {
72
+ constructor(apiRegistry) {
73
+ this.apiRegistry = apiRegistry;
74
+ this.initializeClients();
75
+ }
76
+ get stripe() {
77
+ return this.apiRegistry.getClient('stripe');
78
+ }
79
+ initializeClients() {
80
+ this.apiRegistry.createClient({
81
+ name: 'stripe',
82
+ baseURL: 'https://api.stripe.com/v1',
83
+ auth: {
84
+ type: api_client_registry_service_1.AuthType.BASIC_AUTH,
85
+ config: {
86
+ username: process.env.STRIPE_SECRET_KEY || '',
87
+ password: '',
88
+ },
89
+ },
90
+ defaultHeaders: {
91
+ 'Stripe-Version': '2023-10-16',
92
+ },
93
+ responseTransformer: {
94
+ dataPath: 'data',
95
+ error: (error) => {
96
+ var _a, _b, _c;
97
+ if ((_c = (_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.message) {
98
+ throw new Error(`Stripe API Error: ${error.response.data.error.message}`);
99
+ }
100
+ throw error;
101
+ },
102
+ },
103
+ responseTimeWarningThreshold: 3000,
104
+ tags: ['stripe', 'payment'],
105
+ });
106
+ }
107
+ };
108
+ exports.StripeApiService = StripeApiService;
109
+ exports.StripeApiService = StripeApiService = __decorate([
110
+ (0, common_1.Injectable)(),
111
+ __metadata("design:paramtypes", [api_client_registry_service_1.ApiClientRegistryService])
112
+ ], StripeApiService);
113
+ let WeChatApiService = class WeChatApiService {
114
+ constructor(apiRegistry) {
115
+ this.apiRegistry = apiRegistry;
116
+ this.initializeClients();
117
+ }
118
+ get wechat() {
119
+ return this.apiRegistry.getClient('wechat');
120
+ }
121
+ initializeClients() {
122
+ this.apiRegistry.createClient({
123
+ name: 'wechat',
124
+ baseURL: 'https://api.weixin.qq.com',
125
+ auth: {
126
+ type: api_client_registry_service_1.AuthType.NONE,
127
+ },
128
+ responseTransformer: {
129
+ success: (response) => {
130
+ if (response.data.errcode !== 0) {
131
+ throw new Error(`WeChat API Error (${response.data.errcode}): ${response.data.errmsg}`);
132
+ }
133
+ return response.data.data;
134
+ },
135
+ },
136
+ tags: ['wechat', 'social'],
137
+ environments: {
138
+ development: {
139
+ baseURL: 'https://api.tunnel.com/wechat',
140
+ },
141
+ },
142
+ });
143
+ }
144
+ };
145
+ exports.WeChatApiService = WeChatApiService;
146
+ exports.WeChatApiService = WeChatApiService = __decorate([
147
+ (0, common_1.Injectable)(),
148
+ __metadata("design:paramtypes", [api_client_registry_service_1.ApiClientRegistryService])
149
+ ], WeChatApiService);
150
+ let CustomApiService = class CustomApiService {
151
+ constructor(apiRegistry) {
152
+ this.apiRegistry = apiRegistry;
153
+ this.initializeClients();
154
+ }
155
+ get customApi() {
156
+ return this.apiRegistry.getClient('custom-api');
157
+ }
158
+ initializeClients() {
159
+ this.apiRegistry.createClient({
160
+ name: 'custom-api',
161
+ baseURL: process.env.CUSTOM_API_URL,
162
+ auth: {
163
+ type: api_client_registry_service_1.AuthType.CUSTOM,
164
+ config: {
165
+ authenticator(config) {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ const token = yield this.getValidToken();
168
+ config.headers = Object.assign(Object.assign({}, config.headers), { Authorization: `Bearer ${token}`, 'X-Timestamp': Date.now().toString(), 'X-Signature': this.generateSignature(config) });
169
+ return config;
170
+ });
171
+ },
172
+ refresher(config, error) {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ var _a;
175
+ if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
176
+ const newToken = yield this.refreshToken();
177
+ config.headers['Authorization'] = `Bearer ${newToken}`;
178
+ return config;
179
+ }
180
+ throw error;
181
+ });
182
+ },
183
+ },
184
+ },
185
+ responseTransformer: {
186
+ success: (response) => {
187
+ const result = response.data;
188
+ if (result.success === false) {
189
+ throw new Error(result.message || 'API request failed');
190
+ }
191
+ return {
192
+ data: result.data || result,
193
+ code: result.code || 0,
194
+ message: result.message || 'Success',
195
+ pagination: result.pagination,
196
+ requestId: result.requestId,
197
+ };
198
+ },
199
+ error: (error) => {
200
+ var _a;
201
+ if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) {
202
+ const errorData = error.response.data;
203
+ const customError = new Error(errorData.message || 'API request failed');
204
+ customError.code = errorData.code;
205
+ customError.details = errorData.details;
206
+ throw customError;
207
+ }
208
+ throw error;
209
+ },
210
+ },
211
+ defaultHeaders: {
212
+ 'Content-Type': 'application/json',
213
+ Accept: 'application/json',
214
+ },
215
+ retry: {
216
+ enabled: true,
217
+ retries: 2,
218
+ retryCondition: (error) => {
219
+ if (!error.response)
220
+ return true;
221
+ return error.response.status >= 500;
222
+ },
223
+ },
224
+ tags: ['custom', 'business'],
225
+ });
226
+ }
227
+ getValidToken() {
228
+ return __awaiter(this, void 0, void 0, function* () {
229
+ return 'mock-jwt-token';
230
+ });
231
+ }
232
+ refreshToken() {
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ return 'refreshed-jwt-token';
235
+ });
236
+ }
237
+ generateSignature(config) {
238
+ return 'mock-signature';
239
+ }
240
+ };
241
+ exports.CustomApiService = CustomApiService;
242
+ exports.CustomApiService = CustomApiService = __decorate([
243
+ (0, common_1.Injectable)(),
244
+ __metadata("design:paramtypes", [api_client_registry_service_1.ApiClientRegistryService])
245
+ ], CustomApiService);
246
+ let ApiManagementService = class ApiManagementService {
247
+ constructor(apiRegistry) {
248
+ this.apiRegistry = apiRegistry;
249
+ }
250
+ createDynamicClient(name, config) {
251
+ return this.apiRegistry.createClient(Object.assign({ name, baseURL: config.baseURL || '' }, config));
252
+ }
253
+ getAllStats() {
254
+ return this.apiRegistry.getAllStats();
255
+ }
256
+ resetAllStats() {
257
+ this.apiRegistry.resetAllStats();
258
+ }
259
+ healthCheck() {
260
+ return __awaiter(this, void 0, void 0, function* () {
261
+ return this.apiRegistry.healthCheck();
262
+ });
263
+ }
264
+ createMultipleClients(configs) {
265
+ this.apiRegistry.createClients(configs);
266
+ }
267
+ listClients() {
268
+ return this.apiRegistry.listClients();
269
+ }
270
+ };
271
+ exports.ApiManagementService = ApiManagementService;
272
+ exports.ApiManagementService = ApiManagementService = __decorate([
273
+ (0, common_1.Injectable)(),
274
+ __metadata("design:paramtypes", [api_client_registry_service_1.ApiClientRegistryService])
275
+ ], ApiManagementService);
276
+ let ExampleController = class ExampleController {
277
+ constructor(githubApi, stripeApi, wechatApi, customApi, apiManagement) {
278
+ this.githubApi = githubApi;
279
+ this.stripeApi = stripeApi;
280
+ this.wechatApi = wechatApi;
281
+ this.customApi = customApi;
282
+ this.apiManagement = apiManagement;
283
+ }
284
+ getGitHubUser(username) {
285
+ return __awaiter(this, void 0, void 0, function* () {
286
+ const github = this.githubApi.github;
287
+ return github.get(`/users/${username}`);
288
+ });
289
+ }
290
+ createStripePayment(amount, currency) {
291
+ return __awaiter(this, void 0, void 0, function* () {
292
+ const stripe = this.stripeApi.stripe;
293
+ return stripe.post('/charges', {
294
+ amount,
295
+ currency,
296
+ source: 'tok_visa',
297
+ });
298
+ });
299
+ }
300
+ sendWeChatMessage(openid, content) {
301
+ return __awaiter(this, void 0, void 0, function* () {
302
+ const wechat = this.wechatApi.wechat;
303
+ return wechat.post('/cgi-bin/message/custom/send', {
304
+ touser: openid,
305
+ msgtype: 'text',
306
+ text: {
307
+ content,
308
+ },
309
+ });
310
+ });
311
+ }
312
+ getCustomData(id) {
313
+ return __awaiter(this, void 0, void 0, function* () {
314
+ const custom = this.customApi.customApi;
315
+ return custom.get(`/data/${id}`);
316
+ });
317
+ }
318
+ callDynamicApi(url) {
319
+ return __awaiter(this, void 0, void 0, function* () {
320
+ const client = this.apiManagement.createDynamicClient('dynamic', {
321
+ baseURL: url,
322
+ auth: {
323
+ type: api_client_registry_service_1.AuthType.API_KEY,
324
+ config: {
325
+ key: process.env.DYNAMIC_API_KEY,
326
+ location: 'header',
327
+ name: 'X-API-Key',
328
+ },
329
+ },
330
+ });
331
+ return client.get('/');
332
+ });
333
+ }
334
+ getApiHealth() {
335
+ return __awaiter(this, void 0, void 0, function* () {
336
+ return this.apiManagement.healthCheck();
337
+ });
338
+ }
339
+ getApiStats() {
340
+ return __awaiter(this, void 0, void 0, function* () {
341
+ return this.apiManagement.getAllStats();
342
+ });
343
+ }
344
+ };
345
+ exports.ExampleController = ExampleController;
346
+ exports.ExampleController = ExampleController = __decorate([
347
+ (0, common_1.Injectable)(),
348
+ __metadata("design:paramtypes", [GitHubApiService,
349
+ StripeApiService,
350
+ WeChatApiService,
351
+ CustomApiService,
352
+ ApiManagementService])
353
+ ], ExampleController);