@yildizpay/http-adapter 3.1.0 → 3.3.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 +92 -17
- package/README.tr.md +93 -18
- package/dist/builders/http-adapter.builder.d.ts +17 -0
- package/dist/builders/http-adapter.builder.js +31 -0
- package/dist/builders/http-adapter.builder.js.map +1 -0
- package/dist/builders/request.builder.d.ts +3 -0
- package/dist/builders/request.builder.js +6 -1
- package/dist/builders/request.builder.js.map +1 -1
- package/dist/contracts/http-interceptor.contract.d.ts +4 -1
- package/dist/contracts/response-validator.contract.d.ts +4 -0
- package/dist/contracts/response-validator.contract.js +3 -0
- package/dist/contracts/response-validator.contract.js.map +1 -0
- package/dist/core/http.adapter.d.ts +2 -0
- package/dist/core/http.adapter.js +21 -0
- package/dist/core/http.adapter.js.map +1 -1
- package/dist/exceptions/exception.guards.d.ts +2 -0
- package/dist/exceptions/exception.guards.js +5 -0
- package/dist/exceptions/exception.guards.js.map +1 -1
- package/dist/exceptions/validation.exception.d.ts +9 -0
- package/dist/exceptions/validation.exception.js +25 -0
- package/dist/exceptions/validation.exception.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/models/request.d.ts +3 -1
- package/dist/models/request.js +2 -1
- package/dist/models/request.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -3
package/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/logo.png" width="20%" alt="@yildizpay/http-adapter" />
|
|
3
|
+
<h1 align="center">@yildizpay/http-adapter</h1>
|
|
4
|
+
<p align="center">
|
|
5
|
+
<b>🇬🇧 English</b> | <a href="README.tr.md">🇹🇷 Türkçe</a>
|
|
6
|
+
</p>
|
|
7
|
+
<p align="center">
|
|
8
|
+
<img src="https://github.com/yildizpay/http-adapter/actions/workflows/ci.yml/badge.svg" alt="Build Status" />
|
|
9
|
+
<img src="https://img.shields.io/npm/v/@yildizpay/http-adapter" alt="NPM Version" />
|
|
10
|
+
<img src="https://img.shields.io/npm/l/@yildizpay/http-adapter" alt="License" />
|
|
11
|
+
</p>
|
|
12
|
+
</p>
|
|
8
13
|
|
|
9
14
|
A professional, robust, and highly configurable HTTP client adapter designed for enterprise-grade Node.js applications. It provides a fluent API, built-in resilience patterns, and a powerful interceptor system, all natively sitting on top of the **Node.js Native Fetch API**, making it a zero-dependency library while allowing injection of custom HTTP clients.
|
|
10
15
|
|
|
@@ -12,6 +17,7 @@ A professional, robust, and highly configurable HTTP client adapter designed for
|
|
|
12
17
|
|
|
13
18
|
- **Fluent Request Builder:** Construct complex HTTP requests with an intuitive, chainable API.
|
|
14
19
|
- **Structured Exception Hierarchy:** Every HTTP status code and network failure maps to a dedicated, named exception class with rich metadata, `isRetryable()` signals, and structured `toJSON()` serialization.
|
|
20
|
+
- **Response Validation:** Attach one or more `ResponseValidator` implementations to any request to enforce schema constraints or business rules automatically before the response reaches your code.
|
|
15
21
|
- **Interceptor Architecture:** Easily implement middleware for logging, authentication, error handling, and data transformation.
|
|
16
22
|
- **Resilience & Reliability:** Built-in support for retry policies (Exponential Backoff, etc.) and a generic **Circuit Breaker** to handle transient failures gracefully and prevent cascading failures in S2S communication.
|
|
17
23
|
- **Type Safety:** Fully typed requests and responses using generics, ensuring type safety across your application.
|
|
@@ -47,23 +53,26 @@ const request = new RequestBuilder('https://api.example.com')
|
|
|
47
53
|
|
|
48
54
|
### 2. Creating the Adapter
|
|
49
55
|
|
|
50
|
-
Instantiate the `HttpAdapter`
|
|
56
|
+
Instantiate the `HttpAdapter` using the fluent builder API.
|
|
51
57
|
|
|
52
58
|
```typescript
|
|
53
59
|
import { HttpAdapter, RetryPolicies, CircuitBreaker } from '@yildizpay/http-adapter';
|
|
54
60
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
})
|
|
61
|
+
const adapter = HttpAdapter.builder()
|
|
62
|
+
.withInterceptor(new AuthInterceptor(), new LoggingInterceptor())
|
|
63
|
+
.withRetryPolicy(RetryPolicies.exponential(3))
|
|
64
|
+
.withCircuitBreaker({ failureThreshold: 5, resetTimeoutMs: 60000 })
|
|
65
|
+
.build();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
You can also use `HttpAdapter.create()` directly if you prefer a single-call approach.
|
|
59
69
|
|
|
70
|
+
```typescript
|
|
60
71
|
const adapter = HttpAdapter.create(
|
|
61
|
-
[
|
|
62
|
-
|
|
63
|
-
],
|
|
64
|
-
RetryPolicies.exponential(3), // Retry up to 3 times with exponential backoff
|
|
72
|
+
[new AuthInterceptor()],
|
|
73
|
+
RetryPolicies.exponential(3),
|
|
65
74
|
undefined, // Optional custom HTTP client
|
|
66
|
-
|
|
75
|
+
new CircuitBreaker({ failureThreshold: 5, resetTimeoutMs: 60000 }),
|
|
67
76
|
);
|
|
68
77
|
```
|
|
69
78
|
|
|
@@ -231,6 +240,72 @@ Every exception automatically carries a `RequestContext` object (`method`, `url`
|
|
|
231
240
|
}
|
|
232
241
|
```
|
|
233
242
|
|
|
243
|
+
### Response Validators
|
|
244
|
+
|
|
245
|
+
Attach validators to a request to automatically enforce schema constraints or business rules on the response before it reaches your code. Validators run sequentially after the HTTP call succeeds and before response-side interceptors. The first validator that throws halts the chain.
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
import { ResponseValidator, ValidationException, Response } from '@yildizpay/http-adapter';
|
|
249
|
+
|
|
250
|
+
class PaymentStatusValidator implements ResponseValidator<IyzicoResponse> {
|
|
251
|
+
validate(response: Response<IyzicoResponse>): void {
|
|
252
|
+
if (response.data.status !== 'success') {
|
|
253
|
+
throw new ValidationException(
|
|
254
|
+
`Payment failed: ${response.data.errorMessage}`,
|
|
255
|
+
response,
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Works with any schema validation library — zero coupling to Zod, Joi, etc.
|
|
262
|
+
class PaymentSchemaValidator implements ResponseValidator<unknown> {
|
|
263
|
+
validate(response: Response<unknown>): void {
|
|
264
|
+
IyzicoResponseSchema.parse(response.data); // Zod throws on mismatch
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const request = new RequestBuilder('https://api.iyzipay.com')
|
|
269
|
+
.setEndpoint('/payment/auth')
|
|
270
|
+
.setMethod(HttpMethod.POST)
|
|
271
|
+
.setBody(dto)
|
|
272
|
+
.validateWith(new PaymentSchemaValidator(), new PaymentStatusValidator())
|
|
273
|
+
.build();
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Catching a validation failure:
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
import { isValidationException } from '@yildizpay/http-adapter';
|
|
280
|
+
|
|
281
|
+
} catch (error) {
|
|
282
|
+
if (isValidationException(error)) {
|
|
283
|
+
console.error('Validation failed:', error.message);
|
|
284
|
+
console.error('Raw response:', error.response.data);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Non-`BaseAdapterException` errors thrown inside a validator (e.g. `ZodError`) are automatically wrapped in `ValidationException` with the original error available as `cause`. Use the generic parameter for typed access:
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
} catch (error) {
|
|
293
|
+
if (isValidationException<ZodError>(error) && error.cause) {
|
|
294
|
+
console.error('Schema issues:', error.cause.issues);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
The full interceptor lifecycle when validators are registered:
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
onRequest → HTTP call → onResponse → validators → onResponseValidated → caller
|
|
303
|
+
↓ (on failure)
|
|
304
|
+
onError
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
`onResponse` always fires. `onResponseValidated` only fires when all validators pass — ideal for caching or downstream side effects that require a business-valid response.
|
|
308
|
+
|
|
234
309
|
### Error Interceptor
|
|
235
310
|
|
|
236
311
|
You can also catch and transform exceptions at the interceptor layer before they reach your business logic.
|
package/README.tr.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/logo.png" width="20%" alt="@yildizpay/http-adapter" />
|
|
3
|
+
<h1 align="center">@yildizpay/http-adapter</h1>
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="README.md">🇬🇧 English</a> | <b>🇹🇷 Türkçe</b>
|
|
6
|
+
</p>
|
|
7
|
+
<p align="center">
|
|
8
|
+
<img src="https://github.com/yildizpay/http-adapter/actions/workflows/ci.yml/badge.svg" alt="Build Status" />
|
|
9
|
+
<img src="https://img.shields.io/npm/v/@yildizpay/http-adapter" alt="NPM Version" />
|
|
10
|
+
<img src="https://img.shields.io/npm/l/@yildizpay/http-adapter" alt="License" />
|
|
11
|
+
</p>
|
|
12
|
+
</p>
|
|
8
13
|
|
|
9
14
|
Node.js tabanlı kurumsal uygulamalar için tasarlanmış profesyonel ve yüksek oranda yapılandırılabilir bir HTTP client adaptörü. Fluent API, built-in resilience pattern'ları, güçlü bir interceptor sistemi ve kapsamlı bir exception hiyerarşisi sunar. Zero-dependency olan paketin çekirdeği **Node.js Native Fetch API** kullanır; ancak istenen farklı custom HTTP client'lara da kolayca genişletilebilir.
|
|
10
15
|
|
|
@@ -12,6 +17,7 @@ Node.js tabanlı kurumsal uygulamalar için tasarlanmış profesyonel ve yüksek
|
|
|
12
17
|
|
|
13
18
|
- **Fluent Request Builder:** Sezgisel ve zincirlenebilir bir API ile karmaşık HTTP isteklerini kolayca oluşturun.
|
|
14
19
|
- **Structured Exception Hierarchy:** Her HTTP durum kodu ve ağ hatası, zengin metadata, `isRetryable()` sinyali ve `toJSON()` desteğiyle ayrı bir exception sınıfına dönüştürülür.
|
|
20
|
+
- **Response Validation:** Herhangi bir request'e bir veya daha fazla `ResponseValidator` ekleyerek schema kısıtlamalarını veya business rule'ları response kodunuza ulaşmadan otomatik olarak denetleyebilirsiniz.
|
|
15
21
|
- **Interceptor Mimarisi:** Loglama, kimlik doğrulama, hata yönetimi ve veri dönüşümü gibi middleware işlemlerini zahmetsizce entegre edin.
|
|
16
22
|
- **Resilience & Reliability:** S2S entegrasyonlarında geçici hataları zarif bir şekilde yönetmek için Exponential Backoff gibi retry policy'ler ve built-in **Circuit Breaker** içerir.
|
|
17
23
|
- **Type Safety:** Generic'ler kullanılarak tam olarak tiplendirilmiş request ve response'lar ile uygulama genelinde tip güvenliği sağlanır.
|
|
@@ -47,23 +53,26 @@ const request = new RequestBuilder('https://api.example.com')
|
|
|
47
53
|
|
|
48
54
|
### 2. Adapter'ı Başlatma
|
|
49
55
|
|
|
50
|
-
|
|
56
|
+
Fluent builder API ile `HttpAdapter` oluşturun.
|
|
51
57
|
|
|
52
58
|
```typescript
|
|
53
|
-
import { HttpAdapter, RetryPolicies
|
|
59
|
+
import { HttpAdapter, RetryPolicies } from '@yildizpay/http-adapter';
|
|
54
60
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
})
|
|
61
|
+
const adapter = HttpAdapter.builder()
|
|
62
|
+
.withInterceptor(new AuthInterceptor(), new LoggingInterceptor())
|
|
63
|
+
.withRetryPolicy(RetryPolicies.exponential(3))
|
|
64
|
+
.withCircuitBreaker({ failureThreshold: 5, resetTimeoutMs: 60000 })
|
|
65
|
+
.build();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Tek seferlik kurulum için `HttpAdapter.create()` de kullanılabilir.
|
|
59
69
|
|
|
70
|
+
```typescript
|
|
60
71
|
const adapter = HttpAdapter.create(
|
|
61
|
-
[
|
|
62
|
-
|
|
63
|
-
],
|
|
64
|
-
RetryPolicies.exponential(3), // Exponential backoff ile 3 defaya kadar retry
|
|
72
|
+
[new AuthInterceptor()],
|
|
73
|
+
RetryPolicies.exponential(3),
|
|
65
74
|
undefined, // Opsiyonel custom HTTP client
|
|
66
|
-
|
|
75
|
+
new CircuitBreaker({ failureThreshold: 5, resetTimeoutMs: 60000 }),
|
|
67
76
|
);
|
|
68
77
|
```
|
|
69
78
|
|
|
@@ -231,6 +240,72 @@ Her exception, kaynak request'ten alınan `RequestContext` objesini (`method`, `
|
|
|
231
240
|
}
|
|
232
241
|
```
|
|
233
242
|
|
|
243
|
+
### Response Validator'lar
|
|
244
|
+
|
|
245
|
+
Request'e validator ekleyerek schema kısıtlamalarını veya business rule'ları response kodunuza ulaşmadan otomatik olarak denetleyebilirsiniz. Validator'lar HTTP çağrısı başarılı olduktan sonra, response-side interceptor'lardan önce sırayla çalışır. İlk hata veren validator chain'i durdurur.
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
import { ResponseValidator, ValidationException, Response } from '@yildizpay/http-adapter';
|
|
249
|
+
|
|
250
|
+
class PaymentStatusValidator implements ResponseValidator<IyzicoResponse> {
|
|
251
|
+
validate(response: Response<IyzicoResponse>): void {
|
|
252
|
+
if (response.data.status !== 'success') {
|
|
253
|
+
throw new ValidationException(
|
|
254
|
+
`Payment failed: ${response.data.errorMessage}`,
|
|
255
|
+
response,
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Zod, Joi gibi herhangi bir validation kütüphanesiyle çalışır
|
|
262
|
+
class PaymentSchemaValidator implements ResponseValidator<unknown> {
|
|
263
|
+
validate(response: Response<unknown>): void {
|
|
264
|
+
IyzicoResponseSchema.parse(response.data); // Zod uyuşmazlıkta exception fırlatır
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const request = new RequestBuilder('https://api.iyzipay.com')
|
|
269
|
+
.setEndpoint('/payment/auth')
|
|
270
|
+
.setMethod(HttpMethod.POST)
|
|
271
|
+
.setBody(dto)
|
|
272
|
+
.validateWith(new PaymentSchemaValidator(), new PaymentStatusValidator())
|
|
273
|
+
.build();
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Validation hatasını yakalamak:
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
import { isValidationException } from '@yildizpay/http-adapter';
|
|
280
|
+
|
|
281
|
+
} catch (error) {
|
|
282
|
+
if (isValidationException(error)) {
|
|
283
|
+
console.error('Validation başarısız:', error.message);
|
|
284
|
+
console.error('Ham response:', error.response.data);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Validator içinde fırlatılan `BaseAdapterException` olmayan hatalar (örn. `ZodError`) otomatik olarak `ValidationException`'a sarılır; orijinal hata `cause`'ta tutulur. Typed erişim için generic parametre kullanılabilir:
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
} catch (error) {
|
|
293
|
+
if (isValidationException<ZodError>(error) && error.cause) {
|
|
294
|
+
console.error('Schema hataları:', error.cause.issues);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Validator kayıtlıyken tam interceptor lifecycle'ı:
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
onRequest → HTTP call → onResponse → validators → onResponseValidated → caller
|
|
303
|
+
↓ (hata durumunda)
|
|
304
|
+
onError
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
`onResponse` her zaman çalışır. `onResponseValidated` yalnızca tüm validator'lar geçtiğinde çalışır — business açısından geçerli bir response gerektiren cache veya side effect işlemleri için idealdir.
|
|
308
|
+
|
|
234
309
|
### Error Interceptor
|
|
235
310
|
|
|
236
311
|
Exception'lar business logic'e ulaşmadan önce interceptor seviyesinde yakalanabilir ve dönüştürülebilir.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HttpAdapter } from '../core/http.adapter';
|
|
2
|
+
import { HttpInterceptor } from '../contracts/http-interceptor.contract';
|
|
3
|
+
import { RetryPolicy } from '../contracts/retry-policy.contract';
|
|
4
|
+
import { HttpClientContract } from '../contracts/http-client.contract';
|
|
5
|
+
import { CircuitBreaker } from '../resilience/circuit-breaker/circuit-breaker';
|
|
6
|
+
import { CircuitBreakerOptions } from '../resilience/circuit-breaker/circuit-breaker-options';
|
|
7
|
+
export declare class HttpAdapterBuilder {
|
|
8
|
+
private readonly interceptors;
|
|
9
|
+
private retryPolicy;
|
|
10
|
+
private httpClient;
|
|
11
|
+
private circuitBreaker;
|
|
12
|
+
withInterceptor(...interceptors: HttpInterceptor[]): this;
|
|
13
|
+
withRetryPolicy(policy: RetryPolicy): this;
|
|
14
|
+
withCircuitBreaker(breaker: CircuitBreaker | CircuitBreakerOptions): this;
|
|
15
|
+
withHttpClient(client: HttpClientContract): this;
|
|
16
|
+
build(): HttpAdapter;
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpAdapterBuilder = void 0;
|
|
4
|
+
const http_adapter_1 = require("../core/http.adapter");
|
|
5
|
+
const circuit_breaker_1 = require("../resilience/circuit-breaker/circuit-breaker");
|
|
6
|
+
class HttpAdapterBuilder {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.interceptors = [];
|
|
9
|
+
}
|
|
10
|
+
withInterceptor(...interceptors) {
|
|
11
|
+
this.interceptors.push(...interceptors);
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
withRetryPolicy(policy) {
|
|
15
|
+
this.retryPolicy = policy;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
withCircuitBreaker(breaker) {
|
|
19
|
+
this.circuitBreaker = breaker instanceof circuit_breaker_1.CircuitBreaker ? breaker : new circuit_breaker_1.CircuitBreaker(breaker);
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
withHttpClient(client) {
|
|
23
|
+
this.httpClient = client;
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
build() {
|
|
27
|
+
return http_adapter_1.HttpAdapter.create(this.interceptors, this.retryPolicy, this.httpClient, this.circuitBreaker);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.HttpAdapterBuilder = HttpAdapterBuilder;
|
|
31
|
+
//# sourceMappingURL=http-adapter.builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-adapter.builder.js","sourceRoot":"","sources":["../../src/builders/http-adapter.builder.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AAInD,mFAA+E;AAmB/E,MAAa,kBAAkB;IAA/B;QACmB,iBAAY,GAAsB,EAAE,CAAC;IAiExD,CAAC;IAtDQ,eAAe,CAAC,GAAG,YAA+B;QACvD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAOM,eAAe,CAAC,MAAmB;QACxC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAWM,kBAAkB,CAAC,OAA+C;QACvE,IAAI,CAAC,cAAc,GAAG,OAAO,YAAY,gCAAc,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,gCAAc,CAAC,OAAO,CAAC,CAAC;QAChG,OAAO,IAAI,CAAC;IACd,CAAC;IASM,cAAc,CAAC,MAA0B;QAC9C,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAOM,KAAK;QACV,OAAO,0BAAW,CAAC,MAAM,CACvB,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,cAAc,CACpB,CAAC;IACJ,CAAC;CACF;AAlED,gDAkEC"}
|
|
@@ -2,6 +2,7 @@ import { HttpMethod } from '../common/enums/http-method.enum';
|
|
|
2
2
|
import { HttpBody } from '../common/types/http.types';
|
|
3
3
|
import { Request } from '../models/request';
|
|
4
4
|
import { RequestOptions } from '../models/request-options';
|
|
5
|
+
import { ResponseValidator } from '../contracts/response-validator.contract';
|
|
5
6
|
export declare class RequestBuilder {
|
|
6
7
|
private readonly baseUrl;
|
|
7
8
|
private endpoint;
|
|
@@ -10,6 +11,7 @@ export declare class RequestBuilder {
|
|
|
10
11
|
private body;
|
|
11
12
|
private queryParams;
|
|
12
13
|
private options;
|
|
14
|
+
private readonly validators;
|
|
13
15
|
constructor(baseUrl: string);
|
|
14
16
|
setEndpoint(endpoint: string): this;
|
|
15
17
|
setMethod(method: HttpMethod): this;
|
|
@@ -33,5 +35,6 @@ export declare class RequestBuilder {
|
|
|
33
35
|
resetQueryParams(): this;
|
|
34
36
|
setTimeout(timeout: number): this;
|
|
35
37
|
setOptions(options: RequestOptions): this;
|
|
38
|
+
validateWith(...validators: ResponseValidator[]): this;
|
|
36
39
|
build(): Request;
|
|
37
40
|
}
|
|
@@ -13,6 +13,7 @@ class RequestBuilder {
|
|
|
13
13
|
};
|
|
14
14
|
this.body = {};
|
|
15
15
|
this.queryParams = {};
|
|
16
|
+
this.validators = [];
|
|
16
17
|
this.baseUrl = baseUrl;
|
|
17
18
|
this.options = new request_options_1.RequestOptions();
|
|
18
19
|
}
|
|
@@ -104,8 +105,12 @@ class RequestBuilder {
|
|
|
104
105
|
this.options = options;
|
|
105
106
|
return this;
|
|
106
107
|
}
|
|
108
|
+
validateWith(...validators) {
|
|
109
|
+
this.validators.push(...validators);
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
107
112
|
build() {
|
|
108
|
-
return new request_1.Request(this.baseUrl, this.endpoint, this.method, this.headers, this.queryParams, this.body ? { ...this.body } : undefined, this.options);
|
|
113
|
+
return new request_1.Request(this.baseUrl, this.endpoint, this.method, this.headers, this.queryParams, this.body ? { ...this.body } : undefined, this.options, this.validators);
|
|
109
114
|
}
|
|
110
115
|
}
|
|
111
116
|
exports.RequestBuilder = RequestBuilder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.builder.js","sourceRoot":"","sources":["../../src/builders/request.builder.ts"],"names":[],"mappings":";;;AAAA,uEAA8D;AAE9D,+CAA4C;AAC5C,+DAA2D;
|
|
1
|
+
{"version":3,"file":"request.builder.js","sourceRoot":"","sources":["../../src/builders/request.builder.ts"],"names":[],"mappings":";;;AAAA,uEAA8D;AAE9D,+CAA4C;AAC5C,+DAA2D;AAW3D,MAAa,cAAc;IAiBzB,YAAmB,OAAe;QAf1B,aAAQ,GAAW,EAAE,CAAC;QACtB,WAAM,GAAe,6BAAU,CAAC,IAAI,CAAC;QACrC,YAAO,GAA2B;YACxC,cAAc,EAAE,kBAAkB;SACnC,CAAC;QACM,SAAI,GAAa,EAAE,CAAC;QACpB,gBAAW,GAA2B,EAAE,CAAC;QAEhC,eAAU,GAAwB,EAAE,CAAC;QAQpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,IAAI,gCAAc,EAAE,CAAC;IACtC,CAAC;IAQM,WAAW,CAAC,QAAgB;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAQM,SAAS,CAAC,MAAkB;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAQM,KAAK;QACV,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,UAAU,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAQM,gBAAgB;QACrB,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,mCAAmC,CAAC;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IAQM,MAAM;QACX,IAAI,CAAC,OAAO,CAAC,cAAc,C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,IAAI,CAAC,UAAU,CAChB,CAAC;IACJ,CAAC;CACF;AA/SD,wCA+SC"}
|
|
@@ -7,7 +7,10 @@ export interface HttpRequestInterceptor {
|
|
|
7
7
|
export interface HttpResponseInterceptor {
|
|
8
8
|
onResponse(response: Response): Promise<Response>;
|
|
9
9
|
}
|
|
10
|
+
export interface HttpValidatedResponseInterceptor {
|
|
11
|
+
onResponseValidated(response: Response): Promise<Response>;
|
|
12
|
+
}
|
|
10
13
|
export interface HttpErrorInterceptor {
|
|
11
14
|
onError(error: BaseAdapterException, request: Request): Promise<BaseAdapterException>;
|
|
12
15
|
}
|
|
13
|
-
export type HttpInterceptor = Partial<HttpRequestInterceptor> & Partial<HttpResponseInterceptor> & Partial<HttpErrorInterceptor>;
|
|
16
|
+
export type HttpInterceptor = Partial<HttpRequestInterceptor> & Partial<HttpResponseInterceptor> & Partial<HttpValidatedResponseInterceptor> & Partial<HttpErrorInterceptor>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-validator.contract.js","sourceRoot":"","sources":["../../src/contracts/response-validator.contract.ts"],"names":[],"mappings":""}
|
|
@@ -4,6 +4,7 @@ import { HttpInterceptor } from '../contracts/http-interceptor.contract';
|
|
|
4
4
|
import { RetryPolicy } from '../contracts/retry-policy.contract';
|
|
5
5
|
import { CircuitBreaker } from '../resilience/circuit-breaker/circuit-breaker';
|
|
6
6
|
import { HttpClientContract } from '../contracts/http-client.contract';
|
|
7
|
+
import { HttpAdapterBuilder } from '../builders/http-adapter.builder';
|
|
7
8
|
export declare class HttpAdapter {
|
|
8
9
|
private readonly interceptors;
|
|
9
10
|
private readonly httpClient;
|
|
@@ -11,6 +12,7 @@ export declare class HttpAdapter {
|
|
|
11
12
|
private readonly circuitBreaker?;
|
|
12
13
|
private constructor();
|
|
13
14
|
static create(interceptors: HttpInterceptor[], retryPolicy?: RetryPolicy, httpClient?: HttpClientContract, circuitBreaker?: CircuitBreaker): HttpAdapter;
|
|
15
|
+
static builder(): HttpAdapterBuilder;
|
|
14
16
|
send<T = unknown>(request: Request): Promise<Response<T>>;
|
|
15
17
|
private dispatch;
|
|
16
18
|
}
|
|
@@ -5,6 +5,9 @@ const default_http_client_1 = require("./default-http-client");
|
|
|
5
5
|
const response_1 = require("../models/response");
|
|
6
6
|
const retry_executor_1 = require("../resilience/retry-executor");
|
|
7
7
|
const error_converter_1 = require("./error.converter");
|
|
8
|
+
const base_adapter_exception_1 = require("../exceptions/base-adapter.exception");
|
|
9
|
+
const validation_exception_1 = require("../exceptions/validation.exception");
|
|
10
|
+
const http_adapter_builder_1 = require("../builders/http-adapter.builder");
|
|
8
11
|
class HttpAdapter {
|
|
9
12
|
constructor(interceptors, httpClient, retryPolicy, circuitBreaker) {
|
|
10
13
|
this.interceptors = interceptors;
|
|
@@ -15,6 +18,9 @@ class HttpAdapter {
|
|
|
15
18
|
static create(interceptors, retryPolicy, httpClient, circuitBreaker) {
|
|
16
19
|
return new HttpAdapter(interceptors, httpClient ?? default_http_client_1.defaultHttpClient, retryPolicy, circuitBreaker);
|
|
17
20
|
}
|
|
21
|
+
static builder() {
|
|
22
|
+
return new http_adapter_builder_1.HttpAdapterBuilder();
|
|
23
|
+
}
|
|
18
24
|
async send(request) {
|
|
19
25
|
const executePipeline = () => {
|
|
20
26
|
if (!this.retryPolicy) {
|
|
@@ -61,6 +67,21 @@ class HttpAdapter {
|
|
|
61
67
|
response = (await interceptor.onResponse(response));
|
|
62
68
|
}
|
|
63
69
|
}
|
|
70
|
+
for (const validator of request.validators) {
|
|
71
|
+
try {
|
|
72
|
+
await validator.validate(response);
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
if (err instanceof base_adapter_exception_1.BaseAdapterException)
|
|
76
|
+
throw err;
|
|
77
|
+
throw new validation_exception_1.ValidationException('Response validation failed', response, err);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const interceptor of this.interceptors) {
|
|
81
|
+
if (interceptor.onResponseValidated) {
|
|
82
|
+
response = (await interceptor.onResponseValidated(response));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
64
85
|
return response;
|
|
65
86
|
}
|
|
66
87
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.adapter.js","sourceRoot":"","sources":["../../src/core/http.adapter.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAE1D,iDAA8C;AAI9C,iEAA6D;AAG7D,uDAAmD;
|
|
1
|
+
{"version":3,"file":"http.adapter.js","sourceRoot":"","sources":["../../src/core/http.adapter.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAE1D,iDAA8C;AAI9C,iEAA6D;AAG7D,uDAAmD;AACnD,iFAA4E;AAC5E,6EAAyE;AACzE,2EAAsE;AAYtE,MAAa,WAAW;IAQtB,YACmB,YAA+B,EAC/B,UAA8B,EAC9B,WAAyB,EACzB,cAA+B;QAH/B,iBAAY,GAAZ,YAAY,CAAmB;QAC/B,eAAU,GAAV,UAAU,CAAoB;QAC9B,gBAAW,GAAX,WAAW,CAAc;QACzB,mBAAc,GAAd,cAAc,CAAiB;IAC/C,CAAC;IAUG,MAAM,CAAC,MAAM,CAClB,YAA+B,EAC/B,WAAyB,EACzB,UAA+B,EAC/B,cAA+B;QAE/B,OAAO,IAAI,WAAW,CACpB,YAAY,EACZ,UAAU,IAAI,uCAAiB,EAC/B,WAAW,EACX,cAAc,CACf,CAAC;IACJ,CAAC;IAiBM,MAAM,CAAC,OAAO;QACnB,OAAO,IAAI,yCAAkB,EAAE,CAAC;IAClC,CAAC;IAUM,KAAK,CAAC,IAAI,CAAc,OAAgB;QAC7C,MAAM,eAAe,GAAG,GAAG,EAAE;YAC3B,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;gBACtB,OAAO,IAAI,CAAC,QAAQ,CAAI,OAAO,CAAC,CAAC;YACnC,CAAC;YACD,MAAM,QAAQ,GAAG,IAAI,8BAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACr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kB,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;YAG/E,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBAC5C,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;oBACxB,eAAe,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;gBACjF,CAAC;YACH,CAAC;YAED,MAAM,eAAe,CAAC;QACxB,CAAC;IACH,CAAC;CACF;AA9KD,kCA8KC"}
|
|
@@ -3,6 +3,7 @@ import { CircuitBreakerOpenException } from './circuit-breaker-open.exception';
|
|
|
3
3
|
import { HttpException } from './http-status.exceptions';
|
|
4
4
|
import { NetworkException, TimeoutException, ConnectionRefusedException, DnsResolutionException, SocketResetException, HostUnreachableException } from './network.exceptions';
|
|
5
5
|
import { UnknownException } from './unknown.exception';
|
|
6
|
+
import { ValidationException } from './validation.exception';
|
|
6
7
|
export declare function isBaseAdapterException(error: unknown): error is BaseAdapterException;
|
|
7
8
|
export declare function isHttpException(error: unknown): error is HttpException;
|
|
8
9
|
export declare function isNetworkException(error: unknown): error is NetworkException;
|
|
@@ -13,3 +14,4 @@ export declare function isSocketResetException(error: unknown): error is SocketR
|
|
|
13
14
|
export declare function isHostUnreachableException(error: unknown): error is HostUnreachableException;
|
|
14
15
|
export declare function isUnknownException(error: unknown): error is UnknownException;
|
|
15
16
|
export declare function isCircuitBreakerOpenException(error: unknown): error is CircuitBreakerOpenException;
|
|
17
|
+
export declare function isValidationException<TCause = unknown>(error: unknown): error is ValidationException<TCause>;
|
|
@@ -10,11 +10,13 @@ exports.isSocketResetException = isSocketResetException;
|
|
|
10
10
|
exports.isHostUnreachableException = isHostUnreachableException;
|
|
11
11
|
exports.isUnknownException = isUnknownException;
|
|
12
12
|
exports.isCircuitBreakerOpenException = isCircuitBreakerOpenException;
|
|
13
|
+
exports.isValidationException = isValidationException;
|
|
13
14
|
const base_adapter_exception_1 = require("./base-adapter.exception");
|
|
14
15
|
const circuit_breaker_open_exception_1 = require("./circuit-breaker-open.exception");
|
|
15
16
|
const http_status_exceptions_1 = require("./http-status.exceptions");
|
|
16
17
|
const network_exceptions_1 = require("./network.exceptions");
|
|
17
18
|
const unknown_exception_1 = require("./unknown.exception");
|
|
19
|
+
const validation_exception_1 = require("./validation.exception");
|
|
18
20
|
function isBaseAdapterException(error) {
|
|
19
21
|
return error instanceof base_adapter_exception_1.BaseAdapterException;
|
|
20
22
|
}
|
|
@@ -45,4 +47,7 @@ function isUnknownException(error) {
|
|
|
45
47
|
function isCircuitBreakerOpenException(error) {
|
|
46
48
|
return error instanceof circuit_breaker_open_exception_1.CircuitBreakerOpenException;
|
|
47
49
|
}
|
|
50
|
+
function isValidationException(error) {
|
|
51
|
+
return error instanceof validation_exception_1.ValidationException;
|
|
52
|
+
}
|
|
48
53
|
//# sourceMappingURL=exception.guards.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception.guards.js","sourceRoot":"","sources":["../../src/exceptions/exception.guards.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"exception.guards.js","sourceRoot":"","sources":["../../src/exceptions/exception.guards.ts"],"names":[],"mappings":";;AAcA,wDAEC;AAED,0CAEC;AAED,gDAEC;AAED,gDAEC;AAED,oEAEC;AAED,4DAEC;AAED,wDAEC;AAED,gEAEC;AAED,gDAEC;AAED,sEAIC;AAED,sDAIC;AA5DD,qEAAgE;AAChE,qFAA+E;AAC/E,qEAAyD;AACzD,6DAO8B;AAC9B,2DAAuD;AACvD,iEAA6D;AAE7D,SAAgB,sBAAsB,CAAC,KAAc;IACnD,OAAO,KAAK,YAAY,6CAAoB,CAAC;AAC/C,CAAC;AAED,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,KAAK,YAAY,sCAAa,CAAC;AACxC,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,OAAO,KAAK,YAAY,qCAAgB,CAAC;AAC3C,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,OAAO,KAAK,YAAY,qCAAgB,CAAC;AAC3C,CAAC;AAED,SAAgB,4BAA4B,CAAC,KAAc;IACzD,OAAO,KAAK,YAAY,+CAA0B,CAAC;AACrD,CAAC;AAED,SAAgB,wBAAwB,CAAC,KAAc;IACrD,OAAO,KAAK,YAAY,2CAAsB,CAAC;AACjD,CAAC;AAED,SAAgB,sBAAsB,CAAC,KAAc;IACnD,OAAO,KAAK,YAAY,yCAAoB,CAAC;AAC/C,CAAC;AAED,SAAgB,0BAA0B,CAAC,KAAc;IACvD,OAAO,KAAK,YAAY,6CAAwB,CAAC;AACnD,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,OAAO,KAAK,YAAY,oCAAgB,CAAC;AAC3C,CAAC;AAED,SAAgB,6BAA6B,CAC3C,KAAc;IAEd,OAAO,KAAK,YAAY,4DAA2B,CAAC;AACtD,CAAC;AAED,SAAgB,qBAAqB,CACnC,KAAc;IAEd,OAAO,KAAK,YAAY,0CAAmB,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Response } from '../models/response';
|
|
2
|
+
import { BaseAdapterException } from './base-adapter.exception';
|
|
3
|
+
export declare class ValidationException<TCause = unknown> extends BaseAdapterException {
|
|
4
|
+
readonly name = "ValidationException";
|
|
5
|
+
readonly response: Response;
|
|
6
|
+
readonly cause: TCause | undefined;
|
|
7
|
+
constructor(message: string, response: Response, cause?: TCause);
|
|
8
|
+
toJSON(): Record<string, unknown>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationException = void 0;
|
|
4
|
+
const base_adapter_exception_1 = require("./base-adapter.exception");
|
|
5
|
+
class ValidationException extends base_adapter_exception_1.BaseAdapterException {
|
|
6
|
+
constructor(message, response, cause) {
|
|
7
|
+
super(message, 'ERR_VALIDATION', cause);
|
|
8
|
+
this.name = 'ValidationException';
|
|
9
|
+
this.response = response;
|
|
10
|
+
this.cause = cause;
|
|
11
|
+
Object.setPrototypeOf(this, ValidationException.prototype);
|
|
12
|
+
}
|
|
13
|
+
toJSON() {
|
|
14
|
+
return {
|
|
15
|
+
...super.toJSON(),
|
|
16
|
+
response: {
|
|
17
|
+
status: this.response.status,
|
|
18
|
+
data: this.response.data,
|
|
19
|
+
request: this.response.requestContext,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ValidationException = ValidationException;
|
|
25
|
+
//# sourceMappingURL=validation.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.exception.js","sourceRoot":"","sources":["../../src/exceptions/validation.exception.ts"],"names":[],"mappings":";;;AACA,qEAAgE;AAehE,MAAa,mBAAsC,SAAQ,6CAAoB;IAK7E,YAAmB,OAAe,EAAE,QAAkB,EAAE,KAAc;QACpE,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;QALjB,SAAI,GAAG,qBAAqB,CAAC;QAMpD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC;IAEe,MAAM;QACpB,OAAO;YACL,GAAG,KAAK,CAAC,MAAM,EAAE;YACjB,QAAQ,EAAE;gBACR,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;gBAC5B,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;gBACxB,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,cAAc;aACtC;SACF,CAAC;IACJ,CAAC;CACF;AAtBD,kDAsBC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export * from './core/http.adapter';
|
|
2
2
|
export * from './core/default-http-client';
|
|
3
3
|
export * from './builders/request.builder';
|
|
4
|
+
export * from './builders/http-adapter.builder';
|
|
4
5
|
export * from './models/request';
|
|
5
6
|
export * from './models/response';
|
|
6
7
|
export * from './models/request-options';
|
|
7
8
|
export * from './models/request-context';
|
|
8
9
|
export * from './contracts/http-interceptor.contract';
|
|
9
10
|
export * from './contracts/retry-policy.contract';
|
|
11
|
+
export * from './contracts/response-validator.contract';
|
|
10
12
|
export * from './resilience/retry.policies';
|
|
11
13
|
export * from './resilience/circuit-breaker/circuit-state.enum';
|
|
12
14
|
export * from './resilience/circuit-breaker/circuit-breaker-options';
|
|
@@ -20,5 +22,6 @@ export * from './exceptions/http-exception.factory';
|
|
|
20
22
|
export * from './exceptions/network.exceptions';
|
|
21
23
|
export * from './exceptions/network-exception.factory';
|
|
22
24
|
export * from './exceptions/unknown.exception';
|
|
25
|
+
export * from './exceptions/validation.exception';
|
|
23
26
|
export * from './exceptions/exception.guards';
|
|
24
27
|
export * from './core/error.converter';
|
package/dist/index.js
CHANGED
|
@@ -17,12 +17,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./core/http.adapter"), exports);
|
|
18
18
|
__exportStar(require("./core/default-http-client"), exports);
|
|
19
19
|
__exportStar(require("./builders/request.builder"), exports);
|
|
20
|
+
__exportStar(require("./builders/http-adapter.builder"), exports);
|
|
20
21
|
__exportStar(require("./models/request"), exports);
|
|
21
22
|
__exportStar(require("./models/response"), exports);
|
|
22
23
|
__exportStar(require("./models/request-options"), exports);
|
|
23
24
|
__exportStar(require("./models/request-context"), exports);
|
|
24
25
|
__exportStar(require("./contracts/http-interceptor.contract"), exports);
|
|
25
26
|
__exportStar(require("./contracts/retry-policy.contract"), exports);
|
|
27
|
+
__exportStar(require("./contracts/response-validator.contract"), exports);
|
|
26
28
|
__exportStar(require("./resilience/retry.policies"), exports);
|
|
27
29
|
__exportStar(require("./resilience/circuit-breaker/circuit-state.enum"), exports);
|
|
28
30
|
__exportStar(require("./resilience/circuit-breaker/circuit-breaker-options"), exports);
|
|
@@ -36,6 +38,7 @@ __exportStar(require("./exceptions/http-exception.factory"), exports);
|
|
|
36
38
|
__exportStar(require("./exceptions/network.exceptions"), exports);
|
|
37
39
|
__exportStar(require("./exceptions/network-exception.factory"), exports);
|
|
38
40
|
__exportStar(require("./exceptions/unknown.exception"), exports);
|
|
41
|
+
__exportStar(require("./exceptions/validation.exception"), exports);
|
|
39
42
|
__exportStar(require("./exceptions/exception.guards"), exports);
|
|
40
43
|
__exportStar(require("./core/error.converter"), exports);
|
|
41
44
|
//# sourceMappingURL=index.js.map
|