@felixgeelhaar/govee-api-client 1.1.0 → 2.0.1
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.
- package/README.md +160 -7
- package/dist/GoveeClient.d.ts +31 -0
- package/dist/GoveeClient.d.ts.map +1 -1
- package/dist/GoveeClient.js +33 -0
- package/dist/GoveeClient.js.map +1 -1
- package/dist/errors/GoveeApiError.d.ts +1 -1
- package/dist/errors/GoveeApiError.d.ts.map +1 -1
- package/dist/errors/GoveeApiError.js +9 -2
- package/dist/errors/GoveeApiError.js.map +1 -1
- package/dist/errors/ValidationError.d.ts +28 -0
- package/dist/errors/ValidationError.d.ts.map +1 -0
- package/dist/errors/ValidationError.js +44 -0
- package/dist/errors/ValidationError.js.map +1 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +1 -0
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/GoveeDeviceRepository.d.ts.map +1 -1
- package/dist/infrastructure/GoveeDeviceRepository.js +26 -3
- package/dist/infrastructure/GoveeDeviceRepository.js.map +1 -1
- package/dist/infrastructure/SlidingWindowRateLimiter.d.ts +83 -0
- package/dist/infrastructure/SlidingWindowRateLimiter.d.ts.map +1 -0
- package/dist/infrastructure/SlidingWindowRateLimiter.js +218 -0
- package/dist/infrastructure/SlidingWindowRateLimiter.js.map +1 -0
- package/dist/infrastructure/index.d.ts +2 -0
- package/dist/infrastructure/index.d.ts.map +1 -1
- package/dist/infrastructure/index.js +2 -0
- package/dist/infrastructure/index.js.map +1 -1
- package/dist/infrastructure/response-schemas.d.ts +82 -0
- package/dist/infrastructure/response-schemas.d.ts.map +1 -0
- package/dist/infrastructure/response-schemas.js +59 -0
- package/dist/infrastructure/response-schemas.js.map +1 -0
- package/dist/infrastructure/retry/IntegrationGuide.d.ts +133 -0
- package/dist/infrastructure/retry/IntegrationGuide.d.ts.map +1 -0
- package/dist/infrastructure/retry/IntegrationGuide.js +295 -0
- package/dist/infrastructure/retry/IntegrationGuide.js.map +1 -0
- package/dist/infrastructure/retry/RetryConfigPresets.d.ts +114 -0
- package/dist/infrastructure/retry/RetryConfigPresets.d.ts.map +1 -0
- package/dist/infrastructure/retry/RetryConfigPresets.js +406 -0
- package/dist/infrastructure/retry/RetryConfigPresets.js.map +1 -0
- package/dist/infrastructure/retry/RetryPolicy.d.ts +148 -0
- package/dist/infrastructure/retry/RetryPolicy.d.ts.map +1 -0
- package/dist/infrastructure/retry/RetryPolicy.js +373 -0
- package/dist/infrastructure/retry/RetryPolicy.js.map +1 -0
- package/dist/infrastructure/retry/RetryableRepository.d.ts +75 -0
- package/dist/infrastructure/retry/RetryableRepository.d.ts.map +1 -0
- package/dist/infrastructure/retry/RetryableRepository.js +142 -0
- package/dist/infrastructure/retry/RetryableRepository.js.map +1 -0
- package/dist/infrastructure/retry/RetryableRequest.d.ts +132 -0
- package/dist/infrastructure/retry/RetryableRequest.d.ts.map +1 -0
- package/dist/infrastructure/retry/RetryableRequest.js +248 -0
- package/dist/infrastructure/retry/RetryableRequest.js.map +1 -0
- package/dist/infrastructure/retry/index.d.ts +35 -0
- package/dist/infrastructure/retry/index.d.ts.map +1 -0
- package/dist/infrastructure/retry/index.js +36 -0
- package/dist/infrastructure/retry/index.js.map +1 -0
- package/dist/services/GoveeControlService.d.ts +53 -0
- package/dist/services/GoveeControlService.d.ts.map +1 -1
- package/dist/services/GoveeControlService.js +138 -12
- package/dist/services/GoveeControlService.js.map +1 -1
- package/docs/EXAMPLES.md +799 -0
- package/docs/LLM_API_REFERENCE.md +425 -0
- package/docs/TYPE_DEFINITIONS.md +803 -0
- package/package.json +25 -16
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration Guide for Retry Logic with Govee API Client
|
|
3
|
+
*
|
|
4
|
+
* This file provides comprehensive examples and integration patterns for
|
|
5
|
+
* adding retry logic to the Govee API client after rate limiting is implemented.
|
|
6
|
+
*/
|
|
7
|
+
import { Logger } from 'pino';
|
|
8
|
+
import { GoveeControlService } from '../../services/GoveeControlService';
|
|
9
|
+
import { RetryPolicy, RetryableRepository } from './index';
|
|
10
|
+
/**
|
|
11
|
+
* INTEGRATION EXAMPLE 1: Basic Retry-Enabled Repository
|
|
12
|
+
*
|
|
13
|
+
* This example shows how to wrap the existing GoveeDeviceRepository
|
|
14
|
+
* with retry functionality using default Govee API optimized settings.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createBasicRetryRepository(apiKey: string, logger?: Logger): RetryableRepository;
|
|
17
|
+
/**
|
|
18
|
+
* INTEGRATION EXAMPLE 2: Production-Ready Service with Retry Logic
|
|
19
|
+
*
|
|
20
|
+
* This example shows how to integrate retry logic into the GoveeControlService
|
|
21
|
+
* for production environments with conservative retry policies.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createProductionGoveeService(apiKey: string, logger: Logger): GoveeControlService;
|
|
24
|
+
/**
|
|
25
|
+
* INTEGRATION EXAMPLE 3: Custom Retry Configuration for Specific Use Cases
|
|
26
|
+
*
|
|
27
|
+
* This example demonstrates creating custom retry policies for different
|
|
28
|
+
* operational scenarios.
|
|
29
|
+
*/
|
|
30
|
+
export declare class CustomRetryConfigurations {
|
|
31
|
+
/**
|
|
32
|
+
* Configuration for bulk operations that need to be resilient
|
|
33
|
+
*/
|
|
34
|
+
static createBulkOperationConfig(logger?: Logger): RetryPolicy;
|
|
35
|
+
/**
|
|
36
|
+
* Configuration for real-time operations that need fast failure
|
|
37
|
+
*/
|
|
38
|
+
static createRealTimeConfig(logger?: Logger): RetryPolicy;
|
|
39
|
+
/**
|
|
40
|
+
* Configuration optimized for rate-limited APIs
|
|
41
|
+
*/
|
|
42
|
+
static createRateLimitOptimizedConfig(logger?: Logger): RetryPolicy;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* INTEGRATION EXAMPLE 4: Service with Multiple Retry Strategies
|
|
46
|
+
*
|
|
47
|
+
* This example shows how to use different retry strategies for different
|
|
48
|
+
* types of operations within the same service.
|
|
49
|
+
*/
|
|
50
|
+
export declare class AdvancedGoveeService {
|
|
51
|
+
private readonly bulkRepository;
|
|
52
|
+
private readonly realTimeRepository;
|
|
53
|
+
private readonly baseRepository;
|
|
54
|
+
private readonly logger;
|
|
55
|
+
constructor(apiKey: string, logger: Logger);
|
|
56
|
+
/**
|
|
57
|
+
* Bulk device discovery with resilient retry logic
|
|
58
|
+
*/
|
|
59
|
+
discoverAllDevices(): Promise<import("../..").GoveeDevice[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Real-time device state check with fast failure
|
|
62
|
+
*/
|
|
63
|
+
getDeviceStateRealTime(deviceId: string, sku: string): Promise<import("../..").DeviceState>;
|
|
64
|
+
/**
|
|
65
|
+
* Get comprehensive retry metrics across all strategies
|
|
66
|
+
*/
|
|
67
|
+
getRetryMetrics(): {
|
|
68
|
+
bulk: Readonly<import("./RetryPolicy").RetryMetrics>;
|
|
69
|
+
realTime: Readonly<import("./RetryPolicy").RetryMetrics>;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Reset all retry metrics
|
|
73
|
+
*/
|
|
74
|
+
resetMetrics(): void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* INTEGRATION EXAMPLE 5: Monitoring and Observability Integration
|
|
78
|
+
*
|
|
79
|
+
* This example shows how to integrate retry metrics with monitoring systems.
|
|
80
|
+
*/
|
|
81
|
+
export declare class RetryMetricsCollector {
|
|
82
|
+
private readonly retryableRepository;
|
|
83
|
+
private readonly logger;
|
|
84
|
+
private readonly metricsIntervalMs;
|
|
85
|
+
private metricsInterval?;
|
|
86
|
+
constructor(retryableRepository: RetryableRepository, logger: Logger, metricsIntervalMs?: number);
|
|
87
|
+
/**
|
|
88
|
+
* Start collecting and logging retry metrics
|
|
89
|
+
*/
|
|
90
|
+
startMetricsCollection(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Stop metrics collection
|
|
93
|
+
*/
|
|
94
|
+
stopMetricsCollection(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Get current metrics snapshot
|
|
97
|
+
*/
|
|
98
|
+
getMetricsSnapshot(): {
|
|
99
|
+
timestamp: string;
|
|
100
|
+
total_attempts: number;
|
|
101
|
+
successful_retries: number;
|
|
102
|
+
failed_retries: number;
|
|
103
|
+
success_rate: number;
|
|
104
|
+
average_retry_delay_ms: number;
|
|
105
|
+
circuit_breaker_state: "closed" | "open" | "half-open";
|
|
106
|
+
last_error: {
|
|
107
|
+
name: string;
|
|
108
|
+
code: string;
|
|
109
|
+
message: string;
|
|
110
|
+
timestamp: string;
|
|
111
|
+
stack?: string;
|
|
112
|
+
cause?: unknown;
|
|
113
|
+
} | undefined;
|
|
114
|
+
last_retry: string | undefined;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* INTEGRATION EXAMPLE 6: Environment-Specific Configuration Factory
|
|
119
|
+
*
|
|
120
|
+
* This factory creates appropriate retry configurations based on environment.
|
|
121
|
+
*/
|
|
122
|
+
export declare class RetryConfigFactory {
|
|
123
|
+
/**
|
|
124
|
+
* Create retry configuration based on environment
|
|
125
|
+
*/
|
|
126
|
+
static createForEnvironment(environment: 'development' | 'testing' | 'staging' | 'production', logger?: Logger): RetryPolicy;
|
|
127
|
+
/**
|
|
128
|
+
* Create retry configuration for specific use cases
|
|
129
|
+
*/
|
|
130
|
+
static createForUseCase(useCase: 'bulk' | 'realtime' | 'background' | 'interactive', logger?: Logger): RetryPolicy;
|
|
131
|
+
}
|
|
132
|
+
export { RetryExecutorFactory } from './RetryableRequest';
|
|
133
|
+
//# sourceMappingURL=IntegrationGuide.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntegrationGuide.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/retry/IntegrationGuide.ts"],"names":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AAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IALpC,OAAO,CAAC,eAAe,CAAC,CAAiB;gBAGtB,mBAAmB,EAAE,mBAAmB,EACxC,MAAM,EAAE,MAAM,EACd,iBAAiB,GAAE,MAAc;IAGpD;;OAEG;IACH,sBAAsB;IAsBtB;;OAEG;IACH,qBAAqB;IAOrB;;OAEG;IACH,kBAAkB;;;;;;;;;;;;;;;;;;CAgBnB;AAED;;;;GAIG;AACH,qBAAa,kBAAkB;IAC7B;;OAEG;IACH,MAAM,CAAC,oBAAoB,CACzB,WAAW,EAAE,aAAa,GAAG,SAAS,GAAG,SAAS,GAAG,YAAY,EACjE,MAAM,CAAC,EAAE,MAAM,GACd,WAAW;IAuBd;;OAEG;IACH,MAAM,CAAC,gBAAgB,CACrB,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,YAAY,GAAG,aAAa,EAC3D,MAAM,CAAC,EAAE,MAAM,GACd,WAAW;CAkBf;AAGD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration Guide for Retry Logic with Govee API Client
|
|
3
|
+
*
|
|
4
|
+
* This file provides comprehensive examples and integration patterns for
|
|
5
|
+
* adding retry logic to the Govee API client after rate limiting is implemented.
|
|
6
|
+
*/
|
|
7
|
+
import { GoveeDeviceRepository } from '../GoveeDeviceRepository';
|
|
8
|
+
import { GoveeControlService } from '../../services/GoveeControlService';
|
|
9
|
+
import { RetryPolicy, RetryExecutor, RetryableRepository, RetryConfigPresets, RetryExecutorFactory, } from './index';
|
|
10
|
+
/**
|
|
11
|
+
* INTEGRATION EXAMPLE 1: Basic Retry-Enabled Repository
|
|
12
|
+
*
|
|
13
|
+
* This example shows how to wrap the existing GoveeDeviceRepository
|
|
14
|
+
* with retry functionality using default Govee API optimized settings.
|
|
15
|
+
*/
|
|
16
|
+
export function createBasicRetryRepository(apiKey, logger) {
|
|
17
|
+
// Create the base repository
|
|
18
|
+
const baseRepository = new GoveeDeviceRepository({
|
|
19
|
+
apiKey,
|
|
20
|
+
timeout: 30000,
|
|
21
|
+
logger,
|
|
22
|
+
});
|
|
23
|
+
// Wrap with retry functionality
|
|
24
|
+
const retryableRepository = new RetryableRepository({
|
|
25
|
+
repository: baseRepository,
|
|
26
|
+
retryExecutor: RetryExecutorFactory.createForGoveeApi(logger),
|
|
27
|
+
logger,
|
|
28
|
+
enableRequestIds: true,
|
|
29
|
+
});
|
|
30
|
+
return retryableRepository;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* INTEGRATION EXAMPLE 2: Production-Ready Service with Retry Logic
|
|
34
|
+
*
|
|
35
|
+
* This example shows how to integrate retry logic into the GoveeControlService
|
|
36
|
+
* for production environments with conservative retry policies.
|
|
37
|
+
*/
|
|
38
|
+
export function createProductionGoveeService(apiKey, logger) {
|
|
39
|
+
// Create base repository
|
|
40
|
+
const baseRepository = new GoveeDeviceRepository({
|
|
41
|
+
apiKey,
|
|
42
|
+
timeout: 30000,
|
|
43
|
+
logger,
|
|
44
|
+
});
|
|
45
|
+
// Create production-optimized retry executor
|
|
46
|
+
const retryPolicy = RetryPolicy.createConservative(logger);
|
|
47
|
+
const retryExecutor = new RetryExecutor(retryPolicy, {
|
|
48
|
+
logger,
|
|
49
|
+
enableRequestLogging: true,
|
|
50
|
+
enablePerformanceTracking: true,
|
|
51
|
+
});
|
|
52
|
+
// Wrap repository with retry logic
|
|
53
|
+
const retryableRepository = new RetryableRepository({
|
|
54
|
+
repository: baseRepository,
|
|
55
|
+
retryExecutor,
|
|
56
|
+
logger,
|
|
57
|
+
});
|
|
58
|
+
// Create service with retry-enabled repository
|
|
59
|
+
return new GoveeControlService({
|
|
60
|
+
repository: retryableRepository,
|
|
61
|
+
rateLimit: 100, // 100 requests per minute
|
|
62
|
+
logger,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* INTEGRATION EXAMPLE 3: Custom Retry Configuration for Specific Use Cases
|
|
67
|
+
*
|
|
68
|
+
* This example demonstrates creating custom retry policies for different
|
|
69
|
+
* operational scenarios.
|
|
70
|
+
*/
|
|
71
|
+
export class CustomRetryConfigurations {
|
|
72
|
+
/**
|
|
73
|
+
* Configuration for bulk operations that need to be resilient
|
|
74
|
+
*/
|
|
75
|
+
static createBulkOperationConfig(logger) {
|
|
76
|
+
const builder = RetryConfigPresets.custom()
|
|
77
|
+
.withExponentialBackoff(2000, 60000, 1.5) // Start at 2s, max 1min, gentle growth
|
|
78
|
+
.withDecorrelatedJitter(0.2) // Sophisticated jitter
|
|
79
|
+
.withBasicConditions(5, 300000, [429, 502, 503, 504]) // 5 attempts, 5min total
|
|
80
|
+
.withBasicCircuitBreaker(7, 60000, 3) // Higher failure threshold
|
|
81
|
+
.withMetrics(true);
|
|
82
|
+
if (logger) {
|
|
83
|
+
builder.withLogger(logger);
|
|
84
|
+
}
|
|
85
|
+
return new RetryPolicy(builder.build());
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Configuration for real-time operations that need fast failure
|
|
89
|
+
*/
|
|
90
|
+
static createRealTimeConfig(logger) {
|
|
91
|
+
const builder = RetryConfigPresets.custom()
|
|
92
|
+
.withLinearBackoff(500, 2000) // Quick linear backoff
|
|
93
|
+
.withEqualJitter(0.1) // Low jitter
|
|
94
|
+
.withBasicConditions(2, 5000, [429, 503, 504]) // Quick failure
|
|
95
|
+
.withBasicCircuitBreaker(3, 10000, 1) // Fast circuit breaking
|
|
96
|
+
.withMetrics(true);
|
|
97
|
+
if (logger) {
|
|
98
|
+
builder.withLogger(logger);
|
|
99
|
+
}
|
|
100
|
+
return new RetryPolicy(builder.build());
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Configuration optimized for rate-limited APIs
|
|
104
|
+
*/
|
|
105
|
+
static createRateLimitOptimizedConfig(logger) {
|
|
106
|
+
return new RetryPolicy(RetryConfigPresets.rateLimitAware(logger));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* INTEGRATION EXAMPLE 4: Service with Multiple Retry Strategies
|
|
111
|
+
*
|
|
112
|
+
* This example shows how to use different retry strategies for different
|
|
113
|
+
* types of operations within the same service.
|
|
114
|
+
*/
|
|
115
|
+
export class AdvancedGoveeService {
|
|
116
|
+
constructor(apiKey, logger) {
|
|
117
|
+
this.logger = logger;
|
|
118
|
+
// Create base repository
|
|
119
|
+
this.baseRepository = new GoveeDeviceRepository({
|
|
120
|
+
apiKey,
|
|
121
|
+
timeout: 30000,
|
|
122
|
+
logger,
|
|
123
|
+
});
|
|
124
|
+
// Create bulk operations repository (resilient, slower)
|
|
125
|
+
const bulkRetryExecutor = new RetryExecutor(CustomRetryConfigurations.createBulkOperationConfig(logger), { logger, enableRequestLogging: true, enablePerformanceTracking: true });
|
|
126
|
+
this.bulkRepository = new RetryableRepository({
|
|
127
|
+
repository: this.baseRepository,
|
|
128
|
+
retryExecutor: bulkRetryExecutor,
|
|
129
|
+
logger,
|
|
130
|
+
});
|
|
131
|
+
// Create real-time repository (fast failure)
|
|
132
|
+
const realTimeRetryExecutor = new RetryExecutor(CustomRetryConfigurations.createRealTimeConfig(logger), { logger, enableRequestLogging: true, enablePerformanceTracking: true });
|
|
133
|
+
this.realTimeRepository = new RetryableRepository({
|
|
134
|
+
repository: this.baseRepository,
|
|
135
|
+
retryExecutor: realTimeRetryExecutor,
|
|
136
|
+
logger,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Bulk device discovery with resilient retry logic
|
|
141
|
+
*/
|
|
142
|
+
async discoverAllDevices() {
|
|
143
|
+
this.logger.info('Starting bulk device discovery');
|
|
144
|
+
const result = await this.bulkRepository.findAllWithRetryResult();
|
|
145
|
+
this.logger.info({
|
|
146
|
+
devices: result.data?.length || 0,
|
|
147
|
+
attempts: result.totalAttempts,
|
|
148
|
+
totalTime: result.totalTimeMs,
|
|
149
|
+
success: result.success,
|
|
150
|
+
}, 'Bulk device discovery completed');
|
|
151
|
+
if (!result.success) {
|
|
152
|
+
throw result.error;
|
|
153
|
+
}
|
|
154
|
+
return result.data;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Real-time device state check with fast failure
|
|
158
|
+
*/
|
|
159
|
+
async getDeviceStateRealTime(deviceId, sku) {
|
|
160
|
+
this.logger.debug({ deviceId, sku }, 'Getting device state (real-time)');
|
|
161
|
+
const result = await this.realTimeRepository.findStateWithRetryResult(deviceId, sku);
|
|
162
|
+
if (!result.success) {
|
|
163
|
+
this.logger.warn({
|
|
164
|
+
deviceId,
|
|
165
|
+
sku,
|
|
166
|
+
attempts: result.totalAttempts,
|
|
167
|
+
error: result.error?.toObject(),
|
|
168
|
+
}, 'Real-time state check failed');
|
|
169
|
+
throw result.error;
|
|
170
|
+
}
|
|
171
|
+
return result.data;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get comprehensive retry metrics across all strategies
|
|
175
|
+
*/
|
|
176
|
+
getRetryMetrics() {
|
|
177
|
+
return {
|
|
178
|
+
bulk: this.bulkRepository.getRetryMetrics(),
|
|
179
|
+
realTime: this.realTimeRepository.getRetryMetrics(),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Reset all retry metrics
|
|
184
|
+
*/
|
|
185
|
+
resetMetrics() {
|
|
186
|
+
this.bulkRepository.resetRetryMetrics();
|
|
187
|
+
this.realTimeRepository.resetRetryMetrics();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* INTEGRATION EXAMPLE 5: Monitoring and Observability Integration
|
|
192
|
+
*
|
|
193
|
+
* This example shows how to integrate retry metrics with monitoring systems.
|
|
194
|
+
*/
|
|
195
|
+
export class RetryMetricsCollector {
|
|
196
|
+
constructor(retryableRepository, logger, metricsIntervalMs = 60000 // 1 minute
|
|
197
|
+
) {
|
|
198
|
+
this.retryableRepository = retryableRepository;
|
|
199
|
+
this.logger = logger;
|
|
200
|
+
this.metricsIntervalMs = metricsIntervalMs;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Start collecting and logging retry metrics
|
|
204
|
+
*/
|
|
205
|
+
startMetricsCollection() {
|
|
206
|
+
this.metricsInterval = setInterval(() => {
|
|
207
|
+
const metrics = this.retryableRepository.getRetryMetrics();
|
|
208
|
+
this.logger.info({
|
|
209
|
+
retry_metrics: {
|
|
210
|
+
total_attempts: metrics.totalAttempts,
|
|
211
|
+
successful_retries: metrics.successfulRetries,
|
|
212
|
+
failed_retries: metrics.failedRetries,
|
|
213
|
+
total_retry_time_ms: metrics.totalRetryTimeMs,
|
|
214
|
+
average_retry_delay_ms: metrics.averageRetryDelayMs,
|
|
215
|
+
circuit_breaker_state: metrics.circuitBreakerState,
|
|
216
|
+
success_rate: metrics.totalAttempts > 0 ? metrics.successfulRetries / metrics.totalAttempts : 0,
|
|
217
|
+
},
|
|
218
|
+
}, 'Retry metrics collected');
|
|
219
|
+
}, this.metricsIntervalMs);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Stop metrics collection
|
|
223
|
+
*/
|
|
224
|
+
stopMetricsCollection() {
|
|
225
|
+
if (this.metricsInterval) {
|
|
226
|
+
clearInterval(this.metricsInterval);
|
|
227
|
+
this.metricsInterval = undefined;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get current metrics snapshot
|
|
232
|
+
*/
|
|
233
|
+
getMetricsSnapshot() {
|
|
234
|
+
const metrics = this.retryableRepository.getRetryMetrics();
|
|
235
|
+
return {
|
|
236
|
+
timestamp: new Date().toISOString(),
|
|
237
|
+
total_attempts: metrics.totalAttempts,
|
|
238
|
+
successful_retries: metrics.successfulRetries,
|
|
239
|
+
failed_retries: metrics.failedRetries,
|
|
240
|
+
success_rate: metrics.totalAttempts > 0 ? (metrics.successfulRetries / metrics.totalAttempts) * 100 : 0,
|
|
241
|
+
average_retry_delay_ms: metrics.averageRetryDelayMs,
|
|
242
|
+
circuit_breaker_state: metrics.circuitBreakerState,
|
|
243
|
+
last_error: metrics.lastError?.toObject(),
|
|
244
|
+
last_retry: metrics.lastRetryTimestamp?.toISOString(),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* INTEGRATION EXAMPLE 6: Environment-Specific Configuration Factory
|
|
250
|
+
*
|
|
251
|
+
* This factory creates appropriate retry configurations based on environment.
|
|
252
|
+
*/
|
|
253
|
+
export class RetryConfigFactory {
|
|
254
|
+
/**
|
|
255
|
+
* Create retry configuration based on environment
|
|
256
|
+
*/
|
|
257
|
+
static createForEnvironment(environment, logger) {
|
|
258
|
+
switch (environment) {
|
|
259
|
+
case 'development':
|
|
260
|
+
return new RetryPolicy(RetryConfigPresets.development(logger));
|
|
261
|
+
case 'testing':
|
|
262
|
+
return new RetryPolicy(RetryConfigPresets.testing(logger));
|
|
263
|
+
case 'staging':
|
|
264
|
+
// Use production-like settings but with more logging
|
|
265
|
+
return new RetryPolicy({
|
|
266
|
+
...RetryConfigPresets.production(logger),
|
|
267
|
+
enableMetrics: true,
|
|
268
|
+
});
|
|
269
|
+
case 'production':
|
|
270
|
+
return new RetryPolicy(RetryConfigPresets.production(logger));
|
|
271
|
+
default:
|
|
272
|
+
throw new Error(`Unknown environment: ${environment}`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Create retry configuration for specific use cases
|
|
277
|
+
*/
|
|
278
|
+
static createForUseCase(useCase, logger) {
|
|
279
|
+
switch (useCase) {
|
|
280
|
+
case 'bulk':
|
|
281
|
+
return CustomRetryConfigurations.createBulkOperationConfig(logger);
|
|
282
|
+
case 'realtime':
|
|
283
|
+
return CustomRetryConfigurations.createRealTimeConfig(logger);
|
|
284
|
+
case 'background':
|
|
285
|
+
return new RetryPolicy(RetryConfigPresets.networkResilient(logger));
|
|
286
|
+
case 'interactive':
|
|
287
|
+
return new RetryPolicy(RetryConfigPresets.highFrequency(logger));
|
|
288
|
+
default:
|
|
289
|
+
throw new Error(`Unknown use case: ${useCase}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
// Re-export for convenience
|
|
294
|
+
export { RetryExecutorFactory } from './RetryableRequest';
|
|
295
|
+
//# sourceMappingURL=IntegrationGuide.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntegrationGuide.js","sourceRoot":"","sources":["../../../src/infrastructure/retry/IntegrationGuide.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EACL,WAAW,EACX,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAElB,oBAAoB,GACrB,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAc,EAAE,MAAe;IACxE,6BAA6B;IAC7B,MAAM,cAAc,GAAG,IAAI,qBAAqB,CAAC;QAC/C,MAAM;QACN,OAAO,EAAE,KAAK;QACd,MAAM;KACP,CAAC,CAAC;IAEH,gCAAgC;IAChC,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,CAAC;QAClD,UAAU,EAAE,cAAc;QAC1B,aAAa,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,MAAM,CAAC;QAC7D,MAAM;QACN,gBAAgB,EAAE,IAAI;KACvB,CAAC,CAAC;IAEH,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAAC,MAAc,EAAE,MAAc;IACzE,yBAAyB;IACzB,MAAM,cAAc,GAAG,IAAI,qBAAqB,CAAC;QAC/C,MAAM;QACN,OAAO,EAAE,KAAK;QACd,MAAM;KACP,CAAC,CAAC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1
|
+
import { Logger } from 'pino';
|
|
2
|
+
import { RetryPolicyConfig, BackoffStrategy, JitterConfig, RetryCondition, CircuitBreakerConfig } from './RetryPolicy';
|
|
3
|
+
/**
|
|
4
|
+
* Environment-specific retry configuration presets
|
|
5
|
+
*/
|
|
6
|
+
export declare class RetryConfigPresets {
|
|
7
|
+
/**
|
|
8
|
+
* Development environment configuration - aggressive retries for testing
|
|
9
|
+
*/
|
|
10
|
+
static development(logger?: Logger): RetryPolicyConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Testing environment configuration - predictable behavior
|
|
13
|
+
*/
|
|
14
|
+
static testing(logger?: Logger): RetryPolicyConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Production environment configuration - conservative and reliable
|
|
17
|
+
*/
|
|
18
|
+
static production(logger?: Logger): RetryPolicyConfig;
|
|
19
|
+
/**
|
|
20
|
+
* High-frequency operations configuration - optimized for frequent API calls
|
|
21
|
+
*/
|
|
22
|
+
static highFrequency(logger?: Logger): RetryPolicyConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Rate-limit aware configuration - optimized for APIs with strict rate limits
|
|
25
|
+
*/
|
|
26
|
+
static rateLimitAware(logger?: Logger): RetryPolicyConfig;
|
|
27
|
+
/**
|
|
28
|
+
* Network-resilient configuration - optimized for unreliable networks
|
|
29
|
+
*/
|
|
30
|
+
static networkResilient(logger?: Logger): RetryPolicyConfig;
|
|
31
|
+
/**
|
|
32
|
+
* Custom configuration builder for specific use cases
|
|
33
|
+
*/
|
|
34
|
+
static custom(): RetryConfigBuilder;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Fluent builder for creating custom retry configurations
|
|
38
|
+
*/
|
|
39
|
+
export declare class RetryConfigBuilder {
|
|
40
|
+
private config;
|
|
41
|
+
/**
|
|
42
|
+
* Set backoff strategy
|
|
43
|
+
*/
|
|
44
|
+
withBackoff(strategy: BackoffStrategy): this;
|
|
45
|
+
/**
|
|
46
|
+
* Set exponential backoff with defaults
|
|
47
|
+
*/
|
|
48
|
+
withExponentialBackoff(initialDelayMs?: number, maxDelayMs?: number, multiplier?: number): this;
|
|
49
|
+
/**
|
|
50
|
+
* Set linear backoff
|
|
51
|
+
*/
|
|
52
|
+
withLinearBackoff(initialDelayMs?: number, maxDelayMs?: number): this;
|
|
53
|
+
/**
|
|
54
|
+
* Set fixed backoff
|
|
55
|
+
*/
|
|
56
|
+
withFixedBackoff(delayMs?: number): this;
|
|
57
|
+
/**
|
|
58
|
+
* Set custom backoff function
|
|
59
|
+
*/
|
|
60
|
+
withCustomBackoff(initialDelayMs: number, maxDelayMs: number, customBackoff: (attempt: number, error: any) => number): this;
|
|
61
|
+
/**
|
|
62
|
+
* Set jitter configuration
|
|
63
|
+
*/
|
|
64
|
+
withJitter(jitter: JitterConfig): this;
|
|
65
|
+
/**
|
|
66
|
+
* Set no jitter
|
|
67
|
+
*/
|
|
68
|
+
withoutJitter(): this;
|
|
69
|
+
/**
|
|
70
|
+
* Set equal jitter
|
|
71
|
+
*/
|
|
72
|
+
withEqualJitter(factor?: number): this;
|
|
73
|
+
/**
|
|
74
|
+
* Set full jitter
|
|
75
|
+
*/
|
|
76
|
+
withFullJitter(factor?: number): this;
|
|
77
|
+
/**
|
|
78
|
+
* Set decorrelated jitter
|
|
79
|
+
*/
|
|
80
|
+
withDecorrelatedJitter(factor?: number): this;
|
|
81
|
+
/**
|
|
82
|
+
* Set retry conditions
|
|
83
|
+
*/
|
|
84
|
+
withConditions(conditions: RetryCondition): this;
|
|
85
|
+
/**
|
|
86
|
+
* Set basic retry conditions
|
|
87
|
+
*/
|
|
88
|
+
withBasicConditions(maxAttempts?: number, maxTotalTimeMs?: number, retryableStatusCodes?: number[]): this;
|
|
89
|
+
/**
|
|
90
|
+
* Set circuit breaker configuration
|
|
91
|
+
*/
|
|
92
|
+
withCircuitBreaker(circuitBreaker: CircuitBreakerConfig): this;
|
|
93
|
+
/**
|
|
94
|
+
* Enable circuit breaker with defaults
|
|
95
|
+
*/
|
|
96
|
+
withBasicCircuitBreaker(failureThreshold?: number, recoveryTimeoutMs?: number, halfOpenSuccessThreshold?: number): this;
|
|
97
|
+
/**
|
|
98
|
+
* Disable circuit breaker
|
|
99
|
+
*/
|
|
100
|
+
withoutCircuitBreaker(): this;
|
|
101
|
+
/**
|
|
102
|
+
* Set logger
|
|
103
|
+
*/
|
|
104
|
+
withLogger(logger: Logger): this;
|
|
105
|
+
/**
|
|
106
|
+
* Enable or disable metrics
|
|
107
|
+
*/
|
|
108
|
+
withMetrics(enabled?: boolean): this;
|
|
109
|
+
/**
|
|
110
|
+
* Build the final configuration
|
|
111
|
+
*/
|
|
112
|
+
build(): RetryPolicyConfig;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=RetryConfigPresets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RetryConfigPresets.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/retry/RetryConfigPresets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,oBAAoB,EACrB,MAAM,eAAe,CAAC;AAGvB;;GAEG;AACH,qBAAa,kBAAkB;IAC7B;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,iBAAiB;IA6BtD;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,iBAAiB;IA2BlD;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,iBAAiB;IA6BrD;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,iBAAiB;IA4BxD;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,iBAAiB;IAoCzD;;OAEG;IACH,MAAM,CA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