@nest-omni/core 3.1.2-6 → 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 (64) hide show
  1. package/common/dto/dto-extensions.js +6 -5
  2. package/common/utils.d.ts +1 -0
  3. package/common/utils.js +6 -0
  4. package/http-client/config/http-client.config.d.ts +6 -0
  5. package/http-client/config/http-client.config.js +87 -0
  6. package/http-client/config/index.d.ts +1 -0
  7. package/http-client/config/index.js +17 -0
  8. package/http-client/decorators/http-client.decorators.d.ts +72 -0
  9. package/http-client/decorators/http-client.decorators.js +204 -0
  10. package/http-client/decorators/index.d.ts +1 -0
  11. package/http-client/decorators/index.js +17 -0
  12. package/http-client/entities/http-log.entity.d.ts +98 -0
  13. package/http-client/entities/http-log.entity.js +143 -0
  14. package/http-client/entities/index.d.ts +1 -0
  15. package/http-client/entities/index.js +17 -0
  16. package/http-client/errors/http-client.errors.d.ts +56 -0
  17. package/http-client/errors/http-client.errors.js +149 -0
  18. package/http-client/errors/index.d.ts +1 -0
  19. package/http-client/errors/index.js +17 -0
  20. package/http-client/examples/advanced-usage.example.d.ts +23 -0
  21. package/http-client/examples/advanced-usage.example.js +319 -0
  22. package/http-client/examples/basic-usage.example.d.ts +61 -0
  23. package/http-client/examples/basic-usage.example.js +171 -0
  24. package/http-client/examples/index.d.ts +3 -0
  25. package/http-client/examples/index.js +19 -0
  26. package/http-client/examples/multi-api-configuration.example.d.ts +98 -0
  27. package/http-client/examples/multi-api-configuration.example.js +353 -0
  28. package/http-client/http-client.module.d.ts +11 -0
  29. package/http-client/http-client.module.js +254 -0
  30. package/http-client/index.d.ts +10 -0
  31. package/http-client/index.js +27 -0
  32. package/http-client/interfaces/api-client-config.interface.d.ts +152 -0
  33. package/http-client/interfaces/api-client-config.interface.js +12 -0
  34. package/http-client/interfaces/http-client-config.interface.d.ts +123 -0
  35. package/http-client/interfaces/http-client-config.interface.js +2 -0
  36. package/http-client/services/api-client-registry.service.d.ts +40 -0
  37. package/http-client/services/api-client-registry.service.js +411 -0
  38. package/http-client/services/cache.service.d.ts +24 -0
  39. package/http-client/services/cache.service.js +264 -0
  40. package/http-client/services/circuit-breaker.service.d.ts +33 -0
  41. package/http-client/services/circuit-breaker.service.js +180 -0
  42. package/http-client/services/http-client.service.d.ts +43 -0
  43. package/http-client/services/http-client.service.js +384 -0
  44. package/http-client/services/http-log-query.service.d.ts +56 -0
  45. package/http-client/services/http-log-query.service.js +414 -0
  46. package/http-client/services/index.d.ts +7 -0
  47. package/http-client/services/index.js +23 -0
  48. package/http-client/services/log-cleanup.service.d.ts +64 -0
  49. package/http-client/services/log-cleanup.service.js +268 -0
  50. package/http-client/services/logging.service.d.ts +36 -0
  51. package/http-client/services/logging.service.js +445 -0
  52. package/http-client/utils/call-stack-extractor.util.d.ts +29 -0
  53. package/http-client/utils/call-stack-extractor.util.js +138 -0
  54. package/http-client/utils/context-extractor.util.d.ts +44 -0
  55. package/http-client/utils/context-extractor.util.js +173 -0
  56. package/http-client/utils/curl-generator.util.d.ts +9 -0
  57. package/http-client/utils/curl-generator.util.js +169 -0
  58. package/http-client/utils/index.d.ts +4 -0
  59. package/http-client/utils/index.js +20 -0
  60. package/http-client/utils/retry-recorder.util.d.ts +30 -0
  61. package/http-client/utils/retry-recorder.util.js +143 -0
  62. package/index.d.ts +1 -0
  63. package/index.js +1 -0
  64. package/package.json +1 -1
@@ -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,40 @@
1
+ import { ApiClientConfig, ApiClientInstanceConfig, ApiClientRegistryConfig } 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 declare class ApiClientRegistryService {
7
+ private readonly httpClientService;
8
+ private readonly circuitBreakerService;
9
+ private readonly loggingService;
10
+ private readonly cacheService;
11
+ private readonly logger;
12
+ private readonly clients;
13
+ private readonly clientConfigs;
14
+ private readonly globalDefaults;
15
+ constructor(httpClientService: HttpClientService, circuitBreakerService: HttpCircuitBreakerService, loggingService: HttpLoggingService, cacheService: HttpCacheService, globalConfig?: ApiClientRegistryConfig);
16
+ createClient<T = any>(config: ApiClientInstanceConfig): T;
17
+ getClient<T = any>(name: string): T;
18
+ listClients(): string[];
19
+ updateClient(name: string, config: Partial<ApiClientConfig>): void;
20
+ removeClient(name: string): void;
21
+ getClientConfig(name: string): ApiClientConfig | undefined;
22
+ getAllClientConfigs(): Record<string, ApiClientConfig>;
23
+ createClients(configs: ApiClientInstanceConfig[]): void;
24
+ getGlobalConfig(): ApiClientRegistryConfig;
25
+ updateGlobalConfig(config: Partial<ApiClientRegistryConfig>): void;
26
+ getAllStats(): Record<string, any>;
27
+ resetAllStats(): void;
28
+ healthCheck(): Promise<{
29
+ status: 'healthy' | 'unhealthy';
30
+ clients: Record<string, {
31
+ status: 'healthy' | 'unhealthy';
32
+ error?: string;
33
+ }>;
34
+ }>;
35
+ private createAxiosInstance;
36
+ private applyAuthentication;
37
+ private applyResponseTransformer;
38
+ private extractDataByPath;
39
+ private mergeEnvironmentConfig;
40
+ }