@yildizpay/http-adapter 3.4.1 → 3.6.0
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 +35 -4
- package/README.tr.md +35 -4
- package/dist/auth/api-key.interceptor.d.ts +17 -0
- package/dist/auth/api-key.interceptor.js +26 -0
- package/dist/auth/api-key.interceptor.js.map +1 -0
- package/dist/auth/basic-auth.interceptor.d.ts +8 -0
- package/dist/auth/basic-auth.interceptor.js +17 -0
- package/dist/auth/basic-auth.interceptor.js.map +1 -0
- package/dist/auth/bearer-auth.interceptor.d.ts +9 -0
- package/dist/auth/bearer-auth.interceptor.js +19 -0
- package/dist/auth/bearer-auth.interceptor.js.map +1 -0
- package/dist/auth/token-provider.d.ts +2 -0
- package/dist/auth/token-provider.js +7 -0
- package/dist/auth/token-provider.js.map +1 -0
- package/dist/contracts/retry-policy.contract.d.ts +5 -1
- package/dist/contracts/retry-policy.contract.js +10 -0
- package/dist/contracts/retry-policy.contract.js.map +1 -1
- package/dist/contracts/retry-predicate.contract.d.ts +4 -0
- package/dist/contracts/retry-predicate.contract.js +3 -0
- package/dist/contracts/retry-predicate.contract.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/models/request.js +1 -2
- package/dist/models/request.js.map +1 -1
- package/dist/resilience/policies/decorrelated-jitter.retry-policy.d.ts +8 -0
- package/dist/resilience/policies/decorrelated-jitter.retry-policy.js +18 -0
- package/dist/resilience/policies/decorrelated-jitter.retry-policy.js.map +1 -0
- package/dist/resilience/policies/exponential-backoff.retry-policy.d.ts +0 -1
- package/dist/resilience/policies/exponential-backoff.retry-policy.js +0 -5
- package/dist/resilience/policies/exponential-backoff.retry-policy.js.map +1 -1
- package/dist/resilience/policies/fixed-delay.retry-policy.d.ts +7 -0
- package/dist/resilience/policies/fixed-delay.retry-policy.js +16 -0
- package/dist/resilience/policies/fixed-delay.retry-policy.js.map +1 -0
- package/dist/resilience/policies/full-jitter.retry-policy.d.ts +7 -0
- package/dist/resilience/policies/full-jitter.retry-policy.js +17 -0
- package/dist/resilience/policies/full-jitter.retry-policy.js.map +1 -0
- package/dist/resilience/policies/linear-backoff.retry-policy.d.ts +7 -0
- package/dist/resilience/policies/linear-backoff.retry-policy.js +16 -0
- package/dist/resilience/policies/linear-backoff.retry-policy.js.map +1 -0
- package/dist/resilience/retry.policies.d.ts +8 -0
- package/dist/resilience/retry.policies.js +16 -0
- package/dist/resilience/retry.policies.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/common/utils/str.util.d.ts +0 -3
- package/dist/common/utils/str.util.js +0 -14
- package/dist/common/utils/str.util.js.map +0 -1
package/README.md
CHANGED
|
@@ -334,15 +334,46 @@ export class GlobalErrorInterceptor implements HttpErrorInterceptor {
|
|
|
334
334
|
|
|
335
335
|
Network instability is inevitable. This adapter allows you to define robust retry strategies.
|
|
336
336
|
|
|
337
|
-
###
|
|
337
|
+
### Built-in Retry Policies
|
|
338
338
|
|
|
339
|
-
|
|
339
|
+
| Policy | Factory | Behaviour |
|
|
340
|
+
|---|---|---|
|
|
341
|
+
| Exponential Backoff | `RetryPolicies.exponential(attempts)` | Delay doubles with each attempt plus small jitter — default choice |
|
|
342
|
+
| Fixed Delay | `RetryPolicies.fixedDelay(attempts, delayMs)` | Constant wait between every retry |
|
|
343
|
+
| Linear Backoff | `RetryPolicies.linearBackoff(attempts, stepMs)` | Delay grows linearly (`attempt × stepMs`) |
|
|
344
|
+
| Full Jitter | `RetryPolicies.fullJitter(attempts, baseMs)` | Fully random delay within exponential cap — best for spreading concurrent load |
|
|
345
|
+
| Decorrelated Jitter | `RetryPolicies.decorrelatedJitter(attempts, baseMs, maxDelayMs)` | AWS-recommended algorithm with widest spread across concurrent clients |
|
|
340
346
|
|
|
341
347
|
```typescript
|
|
342
348
|
import { RetryPolicies } from '@yildizpay/http-adapter';
|
|
343
349
|
|
|
344
|
-
//
|
|
345
|
-
|
|
350
|
+
// All policies retry on 429, 502, 503, 504 and network errors by default
|
|
351
|
+
RetryPolicies.exponential(3);
|
|
352
|
+
RetryPolicies.fixedDelay(3, 1000); // 1 s between each attempt
|
|
353
|
+
RetryPolicies.linearBackoff(3, 500); // 500 ms, 1000 ms, 1500 ms
|
|
354
|
+
RetryPolicies.fullJitter(3, 100); // random within [0, 2^attempt * 100 ms]
|
|
355
|
+
RetryPolicies.decorrelatedJitter(3, 100); // AWS decorrelated jitter, cap 30 s
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Custom Retry Predicate
|
|
359
|
+
|
|
360
|
+
Override the default retry decision (`error.isRetryable()`) for any policy via `retryIf()`. Accepts a plain function or a class implementing `RetryPredicate`.
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
import { RetryPolicies, RetryPredicate, BaseAdapterException, isNetworkException } from '@yildizpay/http-adapter';
|
|
364
|
+
|
|
365
|
+
// Inline function
|
|
366
|
+
const policy = RetryPolicies.exponential(3)
|
|
367
|
+
.retryIf((error) => isNetworkException(error));
|
|
368
|
+
|
|
369
|
+
// Class-based predicate
|
|
370
|
+
class BusinessRetryPredicate implements RetryPredicate {
|
|
371
|
+
shouldRetry(error: BaseAdapterException): boolean {
|
|
372
|
+
return error.isRetryable() && myCircuitIsAllowing();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const policy = RetryPolicies.fullJitter(3).retryIf(new BusinessRetryPredicate());
|
|
346
377
|
```
|
|
347
378
|
|
|
348
379
|
### Circuit Breaker
|
package/README.tr.md
CHANGED
|
@@ -334,15 +334,46 @@ export class GlobalErrorInterceptor implements HttpErrorInterceptor {
|
|
|
334
334
|
|
|
335
335
|
Ağ kararsızlığı kaçınılmazdır. Bu adaptör, sağlam retry stratejileri tanımlamanıza olanak tanır.
|
|
336
336
|
|
|
337
|
-
###
|
|
337
|
+
### Built-in Retry Policy'ler
|
|
338
338
|
|
|
339
|
-
|
|
339
|
+
| Policy | Factory | Davranış |
|
|
340
|
+
|---|---|---|
|
|
341
|
+
| Exponential Backoff | `RetryPolicies.exponential(attempts)` | Her denemede gecikme iki katına çıkar, küçük jitter eklenir — varsayılan seçim |
|
|
342
|
+
| Fixed Delay | `RetryPolicies.fixedDelay(attempts, delayMs)` | Her retry arasında sabit bekleme süresi |
|
|
343
|
+
| Linear Backoff | `RetryPolicies.linearBackoff(attempts, stepMs)` | Gecikme doğrusal büyür (`attempt × stepMs`) |
|
|
344
|
+
| Full Jitter | `RetryPolicies.fullJitter(attempts, baseMs)` | Üstel cap içinde tamamen rastgele gecikme — concurrent yükü yaymak için en iyi seçim |
|
|
345
|
+
| Decorrelated Jitter | `RetryPolicies.decorrelatedJitter(attempts, baseMs, maxDelayMs)` | AWS tarafından önerilen algoritma, concurrent istemciler arasında en geniş yayılımı sağlar |
|
|
340
346
|
|
|
341
347
|
```typescript
|
|
342
348
|
import { RetryPolicies } from '@yildizpay/http-adapter';
|
|
343
349
|
|
|
344
|
-
// 429, 502, 503, 504 ve ağ hatalarında retry yapar
|
|
345
|
-
|
|
350
|
+
// Tüm policy'ler varsayılan olarak 429, 502, 503, 504 ve ağ hatalarında retry yapar
|
|
351
|
+
RetryPolicies.exponential(3);
|
|
352
|
+
RetryPolicies.fixedDelay(3, 1000); // her denemede 1 sn bekleme
|
|
353
|
+
RetryPolicies.linearBackoff(3, 500); // 500 ms, 1000 ms, 1500 ms
|
|
354
|
+
RetryPolicies.fullJitter(3, 100); // [0, 2^attempt * 100 ms] aralığında rastgele
|
|
355
|
+
RetryPolicies.decorrelatedJitter(3, 100); // AWS decorrelated jitter, cap 30 sn
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Özel Retry Predicate
|
|
359
|
+
|
|
360
|
+
`retryIf()` ile herhangi bir policy'nin varsayılan retry kararını (`error.isRetryable()`) override edebilirsiniz. Düz bir fonksiyon ya da `RetryPredicate` interface'ini implement eden bir sınıf kabul eder.
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
import { RetryPolicies, RetryPredicate, BaseAdapterException, isNetworkException } from '@yildizpay/http-adapter';
|
|
364
|
+
|
|
365
|
+
// Inline fonksiyon
|
|
366
|
+
const policy = RetryPolicies.exponential(3)
|
|
367
|
+
.retryIf((error) => isNetworkException(error));
|
|
368
|
+
|
|
369
|
+
// Sınıf tabanlı predicate
|
|
370
|
+
class BusinessRetryPredicate implements RetryPredicate {
|
|
371
|
+
shouldRetry(error: BaseAdapterException): boolean {
|
|
372
|
+
return error.isRetryable() && myCircuitIsAllowing();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const policy = RetryPolicies.fullJitter(3).retryIf(new BusinessRetryPredicate());
|
|
346
377
|
```
|
|
347
378
|
|
|
348
379
|
### Circuit Breaker
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HttpRequestInterceptor } from '../contracts/http-interceptor.contract';
|
|
2
|
+
import { Request } from '../models/request';
|
|
3
|
+
import { TokenProvider } from './token-provider';
|
|
4
|
+
export type ApiKeyPlacement = {
|
|
5
|
+
header: string;
|
|
6
|
+
queryParam?: never;
|
|
7
|
+
} | {
|
|
8
|
+
queryParam: string;
|
|
9
|
+
header?: never;
|
|
10
|
+
};
|
|
11
|
+
export declare class ApiKeyInterceptor implements HttpRequestInterceptor {
|
|
12
|
+
private readonly provider;
|
|
13
|
+
private readonly placement;
|
|
14
|
+
private constructor();
|
|
15
|
+
static of(provider: TokenProvider, placement: ApiKeyPlacement): ApiKeyInterceptor;
|
|
16
|
+
onRequest(request: Request): Promise<Request>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiKeyInterceptor = void 0;
|
|
4
|
+
const token_provider_1 = require("./token-provider");
|
|
5
|
+
class ApiKeyInterceptor {
|
|
6
|
+
constructor(provider, placement) {
|
|
7
|
+
this.provider = provider;
|
|
8
|
+
this.placement = placement;
|
|
9
|
+
}
|
|
10
|
+
static of(provider, placement) {
|
|
11
|
+
return new ApiKeyInterceptor(provider, placement);
|
|
12
|
+
}
|
|
13
|
+
async onRequest(request) {
|
|
14
|
+
const key = await (0, token_provider_1.resolveToken)(this.provider);
|
|
15
|
+
const { header, queryParam } = this.placement;
|
|
16
|
+
if (queryParam) {
|
|
17
|
+
request.addQueryParam(queryParam, key);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
request.addHeader(header, key);
|
|
21
|
+
}
|
|
22
|
+
return request;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.ApiKeyInterceptor = ApiKeyInterceptor;
|
|
26
|
+
//# sourceMappingURL=api-key.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key.interceptor.js","sourceRoot":"","sources":["../../src/auth/api-key.interceptor.ts"],"names":[],"mappings":";;;AAEA,qDAA+D;AA0B/D,MAAa,iBAAiB;IAC5B,YACmB,QAAuB,EACvB,SAA0B;QAD1B,aAAQ,GAAR,QAAQ,CAAe;QACvB,cAAS,GAAT,SAAS,CAAiB;IAC1C,CAAC;IAQG,MAAM,CAAC,EAAE,CAAC,QAAuB,EAAE,SAA0B;QAClE,OAAO,IAAI,iBAAiB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACpD,CAAC;IAEM,KAAK,CAAC,SAAS,CAAC,OAAgB;QACrC,MAAM,GAAG,GAAG,MAAM,IAAA,6BAAY,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE9C,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;QAE9C,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,CAAC,aAAa,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QACzC,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,SAAS,CAAC,MAAO,EAAE,GAAG,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AA7BD,8CA6BC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HttpRequestInterceptor } from '../contracts/http-interceptor.contract';
|
|
2
|
+
import { Request } from '../models/request';
|
|
3
|
+
export declare class BasicAuthInterceptor implements HttpRequestInterceptor {
|
|
4
|
+
private readonly encoded;
|
|
5
|
+
private constructor();
|
|
6
|
+
static of(username: string, password: string): BasicAuthInterceptor;
|
|
7
|
+
onRequest(request: Request): Promise<Request>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BasicAuthInterceptor = void 0;
|
|
4
|
+
class BasicAuthInterceptor {
|
|
5
|
+
constructor(username, password) {
|
|
6
|
+
this.encoded = Buffer.from(`${username}:${password}`).toString('base64');
|
|
7
|
+
}
|
|
8
|
+
static of(username, password) {
|
|
9
|
+
return new BasicAuthInterceptor(username, password);
|
|
10
|
+
}
|
|
11
|
+
async onRequest(request) {
|
|
12
|
+
request.addHeader('Authorization', `Basic ${this.encoded}`);
|
|
13
|
+
return request;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.BasicAuthInterceptor = BasicAuthInterceptor;
|
|
17
|
+
//# sourceMappingURL=basic-auth.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic-auth.interceptor.js","sourceRoot":"","sources":["../../src/auth/basic-auth.interceptor.ts"],"names":[],"mappings":";;;AAcA,MAAa,oBAAoB;IAG/B,YAAoB,QAAgB,EAAE,QAAgB;QACpD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,IAAI,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC3E,CAAC;IAQM,MAAM,CAAC,EAAE,CAAC,QAAgB,EAAE,QAAgB;QACjD,OAAO,IAAI,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;IAEM,KAAK,CAAC,SAAS,CAAC,OAAgB;QACrC,OAAO,CAAC,SAAS,CAAC,eAAe,EAAE,SAAS,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5D,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AArBD,oDAqBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HttpRequestInterceptor } from '../contracts/http-interceptor.contract';
|
|
2
|
+
import { Request } from '../models/request';
|
|
3
|
+
import { TokenProvider } from './token-provider';
|
|
4
|
+
export declare class BearerAuthInterceptor implements HttpRequestInterceptor {
|
|
5
|
+
private readonly provider;
|
|
6
|
+
private constructor();
|
|
7
|
+
static of(provider: TokenProvider): BearerAuthInterceptor;
|
|
8
|
+
onRequest(request: Request): Promise<Request>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BearerAuthInterceptor = void 0;
|
|
4
|
+
const token_provider_1 = require("./token-provider");
|
|
5
|
+
class BearerAuthInterceptor {
|
|
6
|
+
constructor(provider) {
|
|
7
|
+
this.provider = provider;
|
|
8
|
+
}
|
|
9
|
+
static of(provider) {
|
|
10
|
+
return new BearerAuthInterceptor(provider);
|
|
11
|
+
}
|
|
12
|
+
async onRequest(request) {
|
|
13
|
+
const token = await (0, token_provider_1.resolveToken)(this.provider);
|
|
14
|
+
request.addHeader('Authorization', `Bearer ${token}`);
|
|
15
|
+
return request;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.BearerAuthInterceptor = BearerAuthInterceptor;
|
|
19
|
+
//# sourceMappingURL=bearer-auth.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bearer-auth.interceptor.js","sourceRoot":"","sources":["../../src/auth/bearer-auth.interceptor.ts"],"names":[],"mappings":";;;AAEA,qDAA+D;AAmB/D,MAAa,qBAAqB;IAChC,YAAqC,QAAuB;QAAvB,aAAQ,GAAR,QAAQ,CAAe;IAAG,CAAC;IAOzD,MAAM,CAAC,EAAE,CAAC,QAAuB;QACtC,OAAO,IAAI,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,SAAS,CAAC,OAAgB;QACrC,MAAM,KAAK,GAAG,MAAM,IAAA,6BAAY,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChD,OAAO,CAAC,SAAS,CAAC,eAAe,EAAE,UAAU,KAAK,EAAE,CAAC,CAAC;QACtD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAjBD,sDAiBC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveToken = resolveToken;
|
|
4
|
+
async function resolveToken(provider) {
|
|
5
|
+
return typeof provider === 'function' ? provider() : provider;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=token-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-provider.js","sourceRoot":"","sources":["../../src/auth/token-provider.ts"],"names":[],"mappings":";;AAwBA,oCAEC;AAFM,KAAK,UAAU,YAAY,CAAC,QAAuB;IACxD,OAAO,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;AAChE,CAAC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { BaseAdapterException } from '../exceptions/base-adapter.exception';
|
|
2
|
+
import { RetryPredicate } from './retry-predicate.contract';
|
|
1
3
|
export declare abstract class RetryPolicy {
|
|
2
4
|
abstract maxAttempts: number;
|
|
5
|
+
private predicate;
|
|
6
|
+
retryIf(predicate: RetryPredicate | ((error: BaseAdapterException) => boolean)): this;
|
|
7
|
+
retryOn(error: unknown): boolean;
|
|
3
8
|
abstract backoffMs(attempt: number): number;
|
|
4
|
-
abstract retryOn(error: unknown): boolean;
|
|
5
9
|
}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RetryPolicy = void 0;
|
|
4
|
+
const base_adapter_exception_1 = require("../exceptions/base-adapter.exception");
|
|
4
5
|
class RetryPolicy {
|
|
6
|
+
retryIf(predicate) {
|
|
7
|
+
this.predicate = typeof predicate === 'function' ? { shouldRetry: predicate } : predicate;
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
retryOn(error) {
|
|
11
|
+
if (!(error instanceof base_adapter_exception_1.BaseAdapterException))
|
|
12
|
+
return false;
|
|
13
|
+
return this.predicate ? this.predicate.shouldRetry(error) : error.isRetryable();
|
|
14
|
+
}
|
|
5
15
|
}
|
|
6
16
|
exports.RetryPolicy = RetryPolicy;
|
|
7
17
|
//# sourceMappingURL=retry-policy.contract.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry-policy.contract.js","sourceRoot":"","sources":["../../src/contracts/retry-policy.contract.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"retry-policy.contract.js","sourceRoot":"","sources":["../../src/contracts/retry-policy.contract.ts"],"names":[],"mappings":";;;AAAA,iFAA4E;AAU5E,MAAsB,WAAW;IA6BxB,OAAO,CAAC,SAAsE;QACnF,IAAI,CAAC,SAAS,GAAG,OAAO,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QAC1F,OAAO,IAAI,CAAC;IACd,CAAC;IAWM,OAAO,CAAC,KAAc;QAC3B,IAAI,CAAC,CAAC,KAAK,YAAY,6CAAoB,CAAC;YAAE,OAAO,KAAK,CAAC;QAC3D,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;IAClF,CAAC;CASF;AAvDD,kCAuDC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-predicate.contract.js","sourceRoot":"","sources":["../../src/contracts/retry-predicate.contract.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,11 +9,21 @@ export * from './models/request-context';
|
|
|
9
9
|
export * from './models/correlation-id-config';
|
|
10
10
|
export * from './contracts/http-interceptor.contract';
|
|
11
11
|
export * from './contracts/retry-policy.contract';
|
|
12
|
+
export * from './contracts/retry-predicate.contract';
|
|
12
13
|
export * from './contracts/response-validator.contract';
|
|
13
14
|
export * from './resilience/retry.policies';
|
|
15
|
+
export * from './resilience/policies/exponential-backoff.retry-policy';
|
|
16
|
+
export * from './resilience/policies/fixed-delay.retry-policy';
|
|
17
|
+
export * from './resilience/policies/linear-backoff.retry-policy';
|
|
18
|
+
export * from './resilience/policies/full-jitter.retry-policy';
|
|
19
|
+
export * from './resilience/policies/decorrelated-jitter.retry-policy';
|
|
14
20
|
export * from './resilience/circuit-breaker/circuit-state.enum';
|
|
15
21
|
export * from './resilience/circuit-breaker/circuit-breaker-options';
|
|
16
22
|
export * from './resilience/circuit-breaker/circuit-breaker';
|
|
23
|
+
export * from './auth/token-provider';
|
|
24
|
+
export * from './auth/bearer-auth.interceptor';
|
|
25
|
+
export * from './auth/basic-auth.interceptor';
|
|
26
|
+
export * from './auth/api-key.interceptor';
|
|
17
27
|
export * from './common/enums/http-method.enum';
|
|
18
28
|
export * from './common/types/http.types';
|
|
19
29
|
export * from './exceptions/circuit-breaker-open.exception';
|
package/dist/index.js
CHANGED
|
@@ -25,11 +25,21 @@ __exportStar(require("./models/request-context"), exports);
|
|
|
25
25
|
__exportStar(require("./models/correlation-id-config"), exports);
|
|
26
26
|
__exportStar(require("./contracts/http-interceptor.contract"), exports);
|
|
27
27
|
__exportStar(require("./contracts/retry-policy.contract"), exports);
|
|
28
|
+
__exportStar(require("./contracts/retry-predicate.contract"), exports);
|
|
28
29
|
__exportStar(require("./contracts/response-validator.contract"), exports);
|
|
29
30
|
__exportStar(require("./resilience/retry.policies"), exports);
|
|
31
|
+
__exportStar(require("./resilience/policies/exponential-backoff.retry-policy"), exports);
|
|
32
|
+
__exportStar(require("./resilience/policies/fixed-delay.retry-policy"), exports);
|
|
33
|
+
__exportStar(require("./resilience/policies/linear-backoff.retry-policy"), exports);
|
|
34
|
+
__exportStar(require("./resilience/policies/full-jitter.retry-policy"), exports);
|
|
35
|
+
__exportStar(require("./resilience/policies/decorrelated-jitter.retry-policy"), exports);
|
|
30
36
|
__exportStar(require("./resilience/circuit-breaker/circuit-state.enum"), exports);
|
|
31
37
|
__exportStar(require("./resilience/circuit-breaker/circuit-breaker-options"), exports);
|
|
32
38
|
__exportStar(require("./resilience/circuit-breaker/circuit-breaker"), exports);
|
|
39
|
+
__exportStar(require("./auth/token-provider"), exports);
|
|
40
|
+
__exportStar(require("./auth/bearer-auth.interceptor"), exports);
|
|
41
|
+
__exportStar(require("./auth/basic-auth.interceptor"), exports);
|
|
42
|
+
__exportStar(require("./auth/api-key.interceptor"), exports);
|
|
33
43
|
__exportStar(require("./common/enums/http-method.enum"), exports);
|
|
34
44
|
__exportStar(require("./common/types/http.types"), exports);
|
|
35
45
|
__exportStar(require("./exceptions/circuit-breaker-open.exception"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,sDAAoC;AACpC,6DAA2C;AAG3C,6DAA2C;AAC3C,kEAAgD;AAGhD,mDAAiC;AACjC,oDAAkC;AAClC,2DAAyC;AACzC,2DAAyC;AACzC,iEAA+C;AAG/C,wEAAsD;AACtD,oEAAkD;AAClD,0EAAwD;AAGxD,8DAA4C;AAC5C,kFAAgE;AAChE,uFAAqE;AACrE,+EAA6D;AAG7D,kEAAgD;AAChD,4DAA0C;AAG1C,8EAA4D;AAC5D,sEAAoD;AACpD,sEAAoD;AACpD,sEAAoD;AACpD,kEAAgD;AAChD,yEAAuD;AACvD,iEAA+C;AAC/C,oEAAkD;AAClD,gEAA8C;AAC9C,yDAAuC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,sDAAoC;AACpC,6DAA2C;AAG3C,6DAA2C;AAC3C,kEAAgD;AAGhD,mDAAiC;AACjC,oDAAkC;AAClC,2DAAyC;AACzC,2DAAyC;AACzC,iEAA+C;AAG/C,wEAAsD;AACtD,oEAAkD;AAClD,uEAAqD;AACrD,0EAAwD;AAGxD,8DAA4C;AAC5C,yFAAuE;AACvE,iFAA+D;AAC/D,oFAAkE;AAClE,iFAA+D;AAC/D,yFAAuE;AACvE,kFAAgE;AAChE,uFAAqE;AACrE,+EAA6D;AAG7D,wDAAsC;AACtC,iEAA+C;AAC/C,gEAA8C;AAC9C,6DAA2C;AAG3C,kEAAgD;AAChD,4DAA0C;AAG1C,8EAA4D;AAC5D,sEAAoD;AACpD,sEAAoD;AACpD,sEAAoD;AACpD,kEAAgD;AAChD,yEAAuD;AACvD,iEAA+C;AAC/C,oEAAkD;AAClD,gEAA8C;AAC9C,yDAAuC"}
|
package/dist/models/request.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Request = void 0;
|
|
4
|
-
const str_util_1 = require("../common/utils/str.util");
|
|
5
4
|
const http_method_enum_1 = require("../common/enums/http-method.enum");
|
|
6
5
|
const request_options_1 = require("./request-options");
|
|
7
6
|
class Request {
|
|
@@ -15,7 +14,7 @@ class Request {
|
|
|
15
14
|
this.options = options;
|
|
16
15
|
this.validators = validators;
|
|
17
16
|
this.correlationIdConfig = correlationIdConfig;
|
|
18
|
-
this.systemCorrelationId =
|
|
17
|
+
this.systemCorrelationId = crypto.randomUUID();
|
|
19
18
|
this.timestamp = new Date();
|
|
20
19
|
}
|
|
21
20
|
addParam(key, value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/models/request.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/models/request.ts"],"names":[],"mappings":";;;AAAA,uEAA8D;AAE9D,uDAAmD;AAWnD,MAAa,OAAO;IAsBlB,YACkB,OAAe,EACf,QAAgB,EAChB,SAAqB,6BAAU,CAAC,IAAI,EACpC,UAAkC,EAAE,EACpC,cAAsC,EAAE,EACxC,OAAwB,IAAI,EAC5B,UAA0B,IAAI,gCAAc,EAAE,EAC9C,aAAkC,EAAE,EACpC,mBAAyC;QARzC,YAAO,GAAP,OAAO,CAAQ;QACf,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAA8B;QACpC,YAAO,GAAP,OAAO,CAA6B;QACpC,gBAAW,GAAX,WAAW,CAA6B;QACxC,SAAI,GAAJ,IAAI,CAAwB;QAC5B,YAAO,GAAP,OAAO,CAAuC;QAC9C,eAAU,GAAV,UAAU,CAA0B;QACpC,wBAAmB,GAAnB,mBAAmB,CAAsB;QAEzD,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QAC/C,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAC9B,CAAC;IASM,QAAQ,CAAC,GAAW,EAAE,KAA4C;QACvE,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACzB,CAAC;IAQM,SAAS,CAAC,GAAW,EAAE,KAAa;QACzC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC5B,CAAC;IAQM,aAAa,CAAC,GAAW,EAAE,KAAa;QAC7C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAChC,CAAC;IAOM,YAAY,CAAC,SAAe;QACjC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAOM,aAAa;QAClB,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;CACF;AA9FD,0BA8FC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RetryPolicy } from '../../contracts/retry-policy.contract';
|
|
2
|
+
export declare class DecorrelatedJitterPolicy extends RetryPolicy {
|
|
3
|
+
maxAttempts: number;
|
|
4
|
+
private readonly baseMs;
|
|
5
|
+
private readonly maxDelayMs;
|
|
6
|
+
constructor(maxAttempts?: number, baseMs?: number, maxDelayMs?: number);
|
|
7
|
+
backoffMs(attempt: number): number;
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DecorrelatedJitterPolicy = void 0;
|
|
4
|
+
const retry_policy_contract_1 = require("../../contracts/retry-policy.contract");
|
|
5
|
+
class DecorrelatedJitterPolicy extends retry_policy_contract_1.RetryPolicy {
|
|
6
|
+
constructor(maxAttempts = 3, baseMs = 100, maxDelayMs = 30000) {
|
|
7
|
+
super();
|
|
8
|
+
this.maxAttempts = maxAttempts;
|
|
9
|
+
this.baseMs = baseMs;
|
|
10
|
+
this.maxDelayMs = maxDelayMs;
|
|
11
|
+
}
|
|
12
|
+
backoffMs(attempt) {
|
|
13
|
+
const cap = Math.min(this.maxDelayMs, this.baseMs * Math.pow(3, attempt));
|
|
14
|
+
return Math.random() * (cap - this.baseMs) + this.baseMs;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.DecorrelatedJitterPolicy = DecorrelatedJitterPolicy;
|
|
18
|
+
//# sourceMappingURL=decorrelated-jitter.retry-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorrelated-jitter.retry-policy.js","sourceRoot":"","sources":["../../../src/resilience/policies/decorrelated-jitter.retry-policy.ts"],"names":[],"mappings":";;;AAAA,iFAAoE;AAiBpE,MAAa,wBAAyB,SAAQ,mCAAW;IACvD,YACS,cAAsB,CAAC,EACb,SAAiB,GAAG,EACpB,aAAqB,KAAK;QAE3C,KAAK,EAAE,CAAC;QAJD,gBAAW,GAAX,WAAW,CAAY;QACb,WAAM,GAAN,MAAM,CAAc;QACpB,eAAU,GAAV,UAAU,CAAgB;IAG7C,CAAC;IAEM,SAAS,CAAC,OAAe;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3D,CAAC;CACF;AAbD,4DAaC"}
|
|
@@ -2,6 +2,5 @@ import { RetryPolicy } from '../../contracts/retry-policy.contract';
|
|
|
2
2
|
export declare class ExponentialBackoffPolicy extends RetryPolicy {
|
|
3
3
|
maxAttempts: number;
|
|
4
4
|
constructor(maxAttempts?: number);
|
|
5
|
-
retryOn(error: unknown): boolean;
|
|
6
5
|
backoffMs(attempt: number): number;
|
|
7
6
|
}
|
|
@@ -2,15 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExponentialBackoffPolicy = void 0;
|
|
4
4
|
const retry_policy_contract_1 = require("../../contracts/retry-policy.contract");
|
|
5
|
-
const base_adapter_exception_1 = require("../../exceptions/base-adapter.exception");
|
|
6
5
|
class ExponentialBackoffPolicy extends retry_policy_contract_1.RetryPolicy {
|
|
7
6
|
constructor(maxAttempts = 3) {
|
|
8
7
|
super();
|
|
9
8
|
this.maxAttempts = maxAttempts;
|
|
10
|
-
this.maxAttempts = maxAttempts;
|
|
11
|
-
}
|
|
12
|
-
retryOn(error) {
|
|
13
|
-
return error instanceof base_adapter_exception_1.BaseAdapterException && error.isRetryable();
|
|
14
9
|
}
|
|
15
10
|
backoffMs(attempt) {
|
|
16
11
|
const base = Math.pow(2, attempt) * 100;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exponential-backoff.retry-policy.js","sourceRoot":"","sources":["../../../src/resilience/policies/exponential-backoff.retry-policy.ts"],"names":[],"mappings":";;;AAAA,iFAAoE;
|
|
1
|
+
{"version":3,"file":"exponential-backoff.retry-policy.js","sourceRoot":"","sources":["../../../src/resilience/policies/exponential-backoff.retry-policy.ts"],"names":[],"mappings":";;;AAAA,iFAAoE;AAQpE,MAAa,wBAAyB,SAAQ,mCAAW;IACvD,YAAmB,cAAsB,CAAC;QACxC,KAAK,EAAE,CAAC;QADS,gBAAW,GAAX,WAAW,CAAY;IAE1C,CAAC;IAEM,SAAS,CAAC,OAAe;QAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,GAAG,CAAC;QACxC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC;QAClC,OAAO,IAAI,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAVD,4DAUC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RetryPolicy } from '../../contracts/retry-policy.contract';
|
|
2
|
+
export declare class FixedDelayPolicy extends RetryPolicy {
|
|
3
|
+
maxAttempts: number;
|
|
4
|
+
private readonly delayMs;
|
|
5
|
+
constructor(maxAttempts?: number, delayMs?: number);
|
|
6
|
+
backoffMs(_attempt: number): number;
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FixedDelayPolicy = void 0;
|
|
4
|
+
const retry_policy_contract_1 = require("../../contracts/retry-policy.contract");
|
|
5
|
+
class FixedDelayPolicy extends retry_policy_contract_1.RetryPolicy {
|
|
6
|
+
constructor(maxAttempts = 3, delayMs = 1000) {
|
|
7
|
+
super();
|
|
8
|
+
this.maxAttempts = maxAttempts;
|
|
9
|
+
this.delayMs = delayMs;
|
|
10
|
+
}
|
|
11
|
+
backoffMs(_attempt) {
|
|
12
|
+
return this.delayMs;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.FixedDelayPolicy = FixedDelayPolicy;
|
|
16
|
+
//# sourceMappingURL=fixed-delay.retry-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixed-delay.retry-policy.js","sourceRoot":"","sources":["../../../src/resilience/policies/fixed-delay.retry-policy.ts"],"names":[],"mappings":";;;AAAA,iFAAoE;AAapE,MAAa,gBAAiB,SAAQ,mCAAW;IAC/C,YACS,cAAsB,CAAC,EACb,UAAkB,IAAI;QAEvC,KAAK,EAAE,CAAC;QAHD,gBAAW,GAAX,WAAW,CAAY;QACb,YAAO,GAAP,OAAO,CAAe;IAGzC,CAAC;IAEM,SAAS,CAAC,QAAgB;QAC/B,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAXD,4CAWC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RetryPolicy } from '../../contracts/retry-policy.contract';
|
|
2
|
+
export declare class FullJitterPolicy extends RetryPolicy {
|
|
3
|
+
maxAttempts: number;
|
|
4
|
+
private readonly baseMs;
|
|
5
|
+
constructor(maxAttempts?: number, baseMs?: number);
|
|
6
|
+
backoffMs(attempt: number): number;
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FullJitterPolicy = void 0;
|
|
4
|
+
const retry_policy_contract_1 = require("../../contracts/retry-policy.contract");
|
|
5
|
+
class FullJitterPolicy extends retry_policy_contract_1.RetryPolicy {
|
|
6
|
+
constructor(maxAttempts = 3, baseMs = 100) {
|
|
7
|
+
super();
|
|
8
|
+
this.maxAttempts = maxAttempts;
|
|
9
|
+
this.baseMs = baseMs;
|
|
10
|
+
}
|
|
11
|
+
backoffMs(attempt) {
|
|
12
|
+
const cap = Math.pow(2, attempt) * this.baseMs;
|
|
13
|
+
return Math.random() * cap;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.FullJitterPolicy = FullJitterPolicy;
|
|
17
|
+
//# sourceMappingURL=full-jitter.retry-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"full-jitter.retry-policy.js","sourceRoot":"","sources":["../../../src/resilience/policies/full-jitter.retry-policy.ts"],"names":[],"mappings":";;;AAAA,iFAAoE;AAiBpE,MAAa,gBAAiB,SAAQ,mCAAW;IAC/C,YACS,cAAsB,CAAC,EACb,SAAiB,GAAG;QAErC,KAAK,EAAE,CAAC;QAHD,gBAAW,GAAX,WAAW,CAAY;QACb,WAAM,GAAN,MAAM,CAAc;IAGvC,CAAC;IAEM,SAAS,CAAC,OAAe;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QAC/C,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;IAC7B,CAAC;CACF;AAZD,4CAYC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RetryPolicy } from '../../contracts/retry-policy.contract';
|
|
2
|
+
export declare class LinearBackoffPolicy extends RetryPolicy {
|
|
3
|
+
maxAttempts: number;
|
|
4
|
+
private readonly stepMs;
|
|
5
|
+
constructor(maxAttempts?: number, stepMs?: number);
|
|
6
|
+
backoffMs(attempt: number): number;
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LinearBackoffPolicy = void 0;
|
|
4
|
+
const retry_policy_contract_1 = require("../../contracts/retry-policy.contract");
|
|
5
|
+
class LinearBackoffPolicy extends retry_policy_contract_1.RetryPolicy {
|
|
6
|
+
constructor(maxAttempts = 3, stepMs = 500) {
|
|
7
|
+
super();
|
|
8
|
+
this.maxAttempts = maxAttempts;
|
|
9
|
+
this.stepMs = stepMs;
|
|
10
|
+
}
|
|
11
|
+
backoffMs(attempt) {
|
|
12
|
+
return attempt * this.stepMs;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.LinearBackoffPolicy = LinearBackoffPolicy;
|
|
16
|
+
//# sourceMappingURL=linear-backoff.retry-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linear-backoff.retry-policy.js","sourceRoot":"","sources":["../../../src/resilience/policies/linear-backoff.retry-policy.ts"],"names":[],"mappings":";;;AAAA,iFAAoE;AAYpE,MAAa,mBAAoB,SAAQ,mCAAW;IAClD,YACS,cAAsB,CAAC,EACb,SAAiB,GAAG;QAErC,KAAK,EAAE,CAAC;QAHD,gBAAW,GAAX,WAAW,CAAY;QACb,WAAM,GAAN,MAAM,CAAc;IAGvC,CAAC;IAEM,SAAS,CAAC,OAAe;QAC9B,OAAO,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC;IAC/B,CAAC;CACF;AAXD,kDAWC"}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { ExponentialBackoffPolicy } from './policies/exponential-backoff.retry-policy';
|
|
2
|
+
import { FixedDelayPolicy } from './policies/fixed-delay.retry-policy';
|
|
3
|
+
import { LinearBackoffPolicy } from './policies/linear-backoff.retry-policy';
|
|
4
|
+
import { FullJitterPolicy } from './policies/full-jitter.retry-policy';
|
|
5
|
+
import { DecorrelatedJitterPolicy } from './policies/decorrelated-jitter.retry-policy';
|
|
2
6
|
export declare class RetryPolicies {
|
|
3
7
|
static exponential(attempts?: number): ExponentialBackoffPolicy;
|
|
8
|
+
static fixedDelay(attempts?: number, delayMs?: number): FixedDelayPolicy;
|
|
9
|
+
static linearBackoff(attempts?: number, stepMs?: number): LinearBackoffPolicy;
|
|
10
|
+
static fullJitter(attempts?: number, baseMs?: number): FullJitterPolicy;
|
|
11
|
+
static decorrelatedJitter(attempts?: number, baseMs?: number, maxDelayMs?: number): DecorrelatedJitterPolicy;
|
|
4
12
|
}
|
|
@@ -2,10 +2,26 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RetryPolicies = void 0;
|
|
4
4
|
const exponential_backoff_retry_policy_1 = require("./policies/exponential-backoff.retry-policy");
|
|
5
|
+
const fixed_delay_retry_policy_1 = require("./policies/fixed-delay.retry-policy");
|
|
6
|
+
const linear_backoff_retry_policy_1 = require("./policies/linear-backoff.retry-policy");
|
|
7
|
+
const full_jitter_retry_policy_1 = require("./policies/full-jitter.retry-policy");
|
|
8
|
+
const decorrelated_jitter_retry_policy_1 = require("./policies/decorrelated-jitter.retry-policy");
|
|
5
9
|
class RetryPolicies {
|
|
6
10
|
static exponential(attempts = 3) {
|
|
7
11
|
return new exponential_backoff_retry_policy_1.ExponentialBackoffPolicy(attempts);
|
|
8
12
|
}
|
|
13
|
+
static fixedDelay(attempts = 3, delayMs = 1000) {
|
|
14
|
+
return new fixed_delay_retry_policy_1.FixedDelayPolicy(attempts, delayMs);
|
|
15
|
+
}
|
|
16
|
+
static linearBackoff(attempts = 3, stepMs = 500) {
|
|
17
|
+
return new linear_backoff_retry_policy_1.LinearBackoffPolicy(attempts, stepMs);
|
|
18
|
+
}
|
|
19
|
+
static fullJitter(attempts = 3, baseMs = 100) {
|
|
20
|
+
return new full_jitter_retry_policy_1.FullJitterPolicy(attempts, baseMs);
|
|
21
|
+
}
|
|
22
|
+
static decorrelatedJitter(attempts = 3, baseMs = 100, maxDelayMs = 30000) {
|
|
23
|
+
return new decorrelated_jitter_retry_policy_1.DecorrelatedJitterPolicy(attempts, baseMs, maxDelayMs);
|
|
24
|
+
}
|
|
9
25
|
}
|
|
10
26
|
exports.RetryPolicies = RetryPolicies;
|
|
11
27
|
//# sourceMappingURL=retry.policies.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.policies.js","sourceRoot":"","sources":["../../src/resilience/retry.policies.ts"],"names":[],"mappings":";;;AAAA,kGAAuF;AAQvF,MAAa,aAAa;IAOxB,MAAM,CAAC,WAAW,CAAC,QAAQ,GAAG,CAAC;QAC7B,OAAO,IAAI,2DAAwB,CAAC,QAAQ,CAAC,CAAC;IAChD,CAAC;CACF;
|
|
1
|
+
{"version":3,"file":"retry.policies.js","sourceRoot":"","sources":["../../src/resilience/retry.policies.ts"],"names":[],"mappings":";;;AAAA,kGAAuF;AACvF,kFAAuE;AACvE,wFAA6E;AAC7E,kFAAuE;AACvE,kGAAuF;AAQvF,MAAa,aAAa;IAOxB,MAAM,CAAC,WAAW,CAAC,QAAQ,GAAG,CAAC;QAC7B,OAAO,IAAI,2DAAwB,CAAC,QAAQ,CAAC,CAAC;IAChD,CAAC;IAQD,MAAM,CAAC,UAAU,CAAC,QAAQ,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI;QAC5C,OAAO,IAAI,2CAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IASD,MAAM,CAAC,aAAa,CAAC,QAAQ,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG;QAC7C,OAAO,IAAI,iDAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;IAUD,MAAM,CAAC,UAAU,CAAC,QAAQ,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG;QAC1C,OAAO,IAAI,2CAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IAWD,MAAM,CAAC,kBAAkB,CACvB,QAAQ,GAAG,CAAC,EACZ,MAAM,GAAG,GAAG,EACZ,UAAU,GAAG,KAAK;QAElB,OAAO,IAAI,2DAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IACpE,CAAC;CACF;AA5DD,sCA4DC"}
|