@ahoo-wang/fetcher 1.8.5 → 1.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fetcher.d.ts +11 -11
- package/dist/fetcher.d.ts.map +1 -1
- package/dist/index.es.js +236 -211
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/requestBodyInterceptor.d.ts +20 -2
- package/dist/requestBodyInterceptor.d.ts.map +1 -1
- package/dist/timeout.d.ts.map +1 -1
- package/package.json +9 -3
package/dist/index.es.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
function
|
|
1
|
+
function L(e) {
|
|
2
2
|
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(e);
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
return
|
|
4
|
+
function M(e, t) {
|
|
5
|
+
return L(t) ? t : t ? e.replace(/\/?\/$/, "") + "/" + t.replace(/^\/+/, "") : e;
|
|
6
6
|
}
|
|
7
|
-
var
|
|
8
|
-
function
|
|
9
|
-
return e === 1 ?
|
|
7
|
+
var G = /* @__PURE__ */ ((e) => (e[e.UriTemplate = 0] = "UriTemplate", e[e.Express = 1] = "Express", e))(G || {});
|
|
8
|
+
function H(e) {
|
|
9
|
+
return e === 1 ? j : B;
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function x(e, t, r) {
|
|
12
12
|
return r ? e.replace(t, (s, o) => {
|
|
13
13
|
const n = r[o];
|
|
14
14
|
if (n === void 0)
|
|
@@ -16,14 +16,14 @@ function N(e, t, r) {
|
|
|
16
16
|
return encodeURIComponent(n);
|
|
17
17
|
}) : e;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function F(e, t) {
|
|
20
20
|
const r = [];
|
|
21
21
|
let s;
|
|
22
22
|
for (; (s = t.exec(e)) !== null; )
|
|
23
23
|
r.push(s[1]);
|
|
24
24
|
return r;
|
|
25
25
|
}
|
|
26
|
-
const
|
|
26
|
+
const h = class h {
|
|
27
27
|
/**
|
|
28
28
|
* Extracts path parameters from a URL string.
|
|
29
29
|
*
|
|
@@ -48,9 +48,9 @@ const a = class a {
|
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
50
|
extractPathParams(t) {
|
|
51
|
-
return
|
|
51
|
+
return F(
|
|
52
52
|
t,
|
|
53
|
-
|
|
53
|
+
h.PATH_PARAM_REGEX
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
@@ -90,16 +90,16 @@ const a = class a {
|
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
92
92
|
resolve(t, r) {
|
|
93
|
-
return
|
|
93
|
+
return x(
|
|
94
94
|
t,
|
|
95
|
-
|
|
95
|
+
h.PATH_PARAM_REGEX,
|
|
96
96
|
r
|
|
97
97
|
);
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
|
-
|
|
101
|
-
let
|
|
102
|
-
const
|
|
100
|
+
h.PATH_PARAM_REGEX = /{([^}]+)}/g;
|
|
101
|
+
let P = h;
|
|
102
|
+
const B = new P(), l = class l {
|
|
103
103
|
/**
|
|
104
104
|
* Extracts path parameters from an Express-style URL string.
|
|
105
105
|
*
|
|
@@ -120,9 +120,9 @@ const G = new m(), h = class h {
|
|
|
120
120
|
* ```
|
|
121
121
|
*/
|
|
122
122
|
extractPathParams(t) {
|
|
123
|
-
return
|
|
123
|
+
return F(
|
|
124
124
|
t,
|
|
125
|
-
|
|
125
|
+
l.PATH_PARAM_REGEX
|
|
126
126
|
);
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
@@ -158,17 +158,17 @@ const G = new m(), h = class h {
|
|
|
158
158
|
* ```
|
|
159
159
|
*/
|
|
160
160
|
resolve(t, r) {
|
|
161
|
-
return
|
|
161
|
+
return x(
|
|
162
162
|
t,
|
|
163
|
-
|
|
163
|
+
l.PATH_PARAM_REGEX,
|
|
164
164
|
r
|
|
165
165
|
);
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
|
-
|
|
169
|
-
let
|
|
170
|
-
const
|
|
171
|
-
class
|
|
168
|
+
l.PATH_PARAM_REGEX = /:([^/]+)/g;
|
|
169
|
+
let g = l;
|
|
170
|
+
const j = new g();
|
|
171
|
+
class $ {
|
|
172
172
|
/**
|
|
173
173
|
* Initializes a new UrlBuilder instance.
|
|
174
174
|
*
|
|
@@ -187,7 +187,7 @@ class j {
|
|
|
187
187
|
* ```
|
|
188
188
|
*/
|
|
189
189
|
constructor(t, r) {
|
|
190
|
-
this.baseURL = t, this.urlTemplateResolver =
|
|
190
|
+
this.baseURL = t, this.urlTemplateResolver = H(r);
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
193
|
* Builds a complete URL, including path parameter replacement and query parameter addition.
|
|
@@ -208,13 +208,13 @@ class j {
|
|
|
208
208
|
* ```
|
|
209
209
|
*/
|
|
210
210
|
build(t, r) {
|
|
211
|
-
const s = r?.path, o = r?.query, n =
|
|
212
|
-
let
|
|
211
|
+
const s = r?.path, o = r?.query, n = M(this.baseURL, t);
|
|
212
|
+
let i = this.urlTemplateResolver.resolve(n, s);
|
|
213
213
|
if (o) {
|
|
214
|
-
const
|
|
215
|
-
|
|
214
|
+
const a = new URLSearchParams(o).toString();
|
|
215
|
+
a && (i += "?" + a);
|
|
216
216
|
}
|
|
217
|
-
return
|
|
217
|
+
return i;
|
|
218
218
|
}
|
|
219
219
|
/**
|
|
220
220
|
* Resolves a complete URL from a FetchRequest.
|
|
@@ -229,7 +229,7 @@ class j {
|
|
|
229
229
|
return this.build(t.url, t.urlParams);
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
-
class
|
|
232
|
+
class E extends Error {
|
|
233
233
|
/**
|
|
234
234
|
* Creates a new FetcherError instance.
|
|
235
235
|
*
|
|
@@ -238,10 +238,10 @@ class l extends Error {
|
|
|
238
238
|
*/
|
|
239
239
|
constructor(t, r) {
|
|
240
240
|
const s = t || r?.message || "An error occurred in the fetcher";
|
|
241
|
-
super(s), this.cause = r, this.name = "FetcherError", r?.stack && (this.stack = r.stack), Object.setPrototypeOf(this,
|
|
241
|
+
super(s), this.cause = r, this.name = "FetcherError", r?.stack && (this.stack = r.stack), Object.setPrototypeOf(this, E.prototype);
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
|
-
class
|
|
244
|
+
class I extends E {
|
|
245
245
|
/**
|
|
246
246
|
* Creates a new FetchTimeoutError instance.
|
|
247
247
|
*
|
|
@@ -249,38 +249,38 @@ class g extends l {
|
|
|
249
249
|
*/
|
|
250
250
|
constructor(t) {
|
|
251
251
|
const r = t.method || "GET", s = `Request timeout of ${t.timeout}ms exceeded for ${r} ${t.url}`;
|
|
252
|
-
super(s), this.name = "FetchTimeoutError", this.request = t, Object.setPrototypeOf(this,
|
|
252
|
+
super(s), this.name = "FetchTimeoutError", this.request = t, Object.setPrototypeOf(this, I.prototype);
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
|
-
function
|
|
255
|
+
function X(e, t) {
|
|
256
256
|
return typeof e < "u" ? e : t;
|
|
257
257
|
}
|
|
258
|
-
async function
|
|
258
|
+
async function V(e) {
|
|
259
259
|
const t = e.url, r = e.timeout, s = e;
|
|
260
260
|
if (e.signal)
|
|
261
261
|
return fetch(t, s);
|
|
262
262
|
if (!r)
|
|
263
263
|
return e.abortController && (s.signal = e.abortController.signal), fetch(t, s);
|
|
264
264
|
const o = e.abortController ?? new AbortController();
|
|
265
|
-
s.signal = o.signal;
|
|
265
|
+
e.abortController = o, s.signal = o.signal;
|
|
266
266
|
let n = null;
|
|
267
|
-
const
|
|
267
|
+
const i = new Promise((a, T) => {
|
|
268
268
|
n = setTimeout(() => {
|
|
269
269
|
n && clearTimeout(n);
|
|
270
|
-
const
|
|
271
|
-
o.abort(
|
|
270
|
+
const w = new I(e);
|
|
271
|
+
o.abort(w), T(w);
|
|
272
272
|
}, r);
|
|
273
273
|
});
|
|
274
274
|
try {
|
|
275
|
-
return await Promise.race([fetch(t, s),
|
|
275
|
+
return await Promise.race([fetch(t, s), i]);
|
|
276
276
|
} finally {
|
|
277
277
|
n && clearTimeout(n);
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
-
const
|
|
281
|
-
class
|
|
280
|
+
const k = "UrlResolveInterceptor", C = Number.MIN_SAFE_INTEGER + 1e3;
|
|
281
|
+
class J {
|
|
282
282
|
constructor() {
|
|
283
|
-
this.name =
|
|
283
|
+
this.name = k, this.order = C;
|
|
284
284
|
}
|
|
285
285
|
/**
|
|
286
286
|
* Resolves the final URL by combining the base URL, path parameters, and query parameters.
|
|
@@ -292,21 +292,43 @@ class V {
|
|
|
292
292
|
r.url = t.fetcher.urlBuilder.resolveRequestUrl(r);
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
var
|
|
296
|
-
const
|
|
295
|
+
var u = /* @__PURE__ */ ((e) => (e.GET = "GET", e.POST = "POST", e.PUT = "PUT", e.DELETE = "DELETE", e.PATCH = "PATCH", e.HEAD = "HEAD", e.OPTIONS = "OPTIONS", e))(u || {});
|
|
296
|
+
const c = "Content-Type", p = class p {
|
|
297
297
|
};
|
|
298
|
-
|
|
299
|
-
let
|
|
300
|
-
const
|
|
301
|
-
class
|
|
298
|
+
p.APPLICATION_JSON = "application/json", p.TEXT_EVENT_STREAM = "text/event-stream";
|
|
299
|
+
let d = p;
|
|
300
|
+
const Q = "RequestBodyInterceptor", Y = C + 1e3;
|
|
301
|
+
class z {
|
|
302
302
|
constructor() {
|
|
303
|
-
this.name =
|
|
303
|
+
this.name = Q, this.order = Y;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Checks if the provided body is of a supported complex type that doesn't require JSON serialization.
|
|
307
|
+
*
|
|
308
|
+
* @param body - The request body to check
|
|
309
|
+
* @returns True if the body is an ArrayBuffer, TypedArray, DataView or ReadableStream, false otherwise
|
|
310
|
+
*/
|
|
311
|
+
isSupportedComplexBodyType(t) {
|
|
312
|
+
return t instanceof ArrayBuffer || ArrayBuffer.isView(t) || t instanceof ReadableStream;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Checks if the provided body is of a type that automatically appends Content-Type header.
|
|
316
|
+
*
|
|
317
|
+
* @param body - The request body to check
|
|
318
|
+
* @returns True if the body is a Blob, File, FormData or URLSearchParams, false otherwise
|
|
319
|
+
*/
|
|
320
|
+
isAutoAppendContentType(t) {
|
|
321
|
+
return t instanceof Blob || t instanceof File || t instanceof FormData || t instanceof URLSearchParams;
|
|
304
322
|
}
|
|
305
323
|
/**
|
|
306
324
|
* Attempts to convert request body to a valid fetch API body type.
|
|
307
325
|
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
326
|
+
* This method follows a specific processing order to handle different types of request bodies:
|
|
327
|
+
* 1. Check if the body is null or undefined and return early if so
|
|
328
|
+
* 2. Check if the body is a non-object type and return early if so
|
|
329
|
+
* 3. Check if the body is a type that automatically appends Content-Type header
|
|
330
|
+
* 4. Check if the body is a supported complex type that doesn't require JSON serialization
|
|
331
|
+
* 5. For plain objects, convert to JSON string and set Content-Type header to application/json
|
|
310
332
|
*
|
|
311
333
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body}
|
|
312
334
|
*
|
|
@@ -341,18 +363,20 @@ class Q {
|
|
|
341
363
|
*/
|
|
342
364
|
intercept(t) {
|
|
343
365
|
const r = t.request;
|
|
344
|
-
if (r.body === void 0 || r.body === null || typeof r.body != "object"
|
|
345
|
-
r.body instanceof Blob || r.body instanceof File || r.body instanceof URLSearchParams || r.body instanceof FormData || r.body instanceof ReadableStream)
|
|
366
|
+
if (r.body === void 0 || r.body === null || typeof r.body != "object")
|
|
346
367
|
return;
|
|
347
|
-
t.request.body = JSON.stringify(r.body);
|
|
348
368
|
const s = t.ensureRequestHeaders();
|
|
349
|
-
|
|
369
|
+
if (this.isAutoAppendContentType(r.body)) {
|
|
370
|
+
s[c] && delete s[c];
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
this.isSupportedComplexBodyType(r.body) || (t.request.body = JSON.stringify(r.body), s[c] || (s[c] = d.APPLICATION_JSON));
|
|
350
374
|
}
|
|
351
375
|
}
|
|
352
|
-
const
|
|
353
|
-
class
|
|
376
|
+
const K = "FetchInterceptor", W = Number.MAX_SAFE_INTEGER - 1e3;
|
|
377
|
+
class Z {
|
|
354
378
|
constructor() {
|
|
355
|
-
this.name =
|
|
379
|
+
this.name = K, this.order = W;
|
|
356
380
|
}
|
|
357
381
|
/**
|
|
358
382
|
* Intercept and process HTTP requests.
|
|
@@ -380,10 +404,10 @@ class K {
|
|
|
380
404
|
* console.log(exchange.response); // HTTP response object
|
|
381
405
|
*/
|
|
382
406
|
async intercept(t) {
|
|
383
|
-
t.response = await
|
|
407
|
+
t.response = await V(t.request);
|
|
384
408
|
}
|
|
385
409
|
}
|
|
386
|
-
function
|
|
410
|
+
function m(e, t) {
|
|
387
411
|
return t ? e.filter(t).sort((r, s) => r.order - s.order) : [...e].sort((r, s) => r.order - s.order);
|
|
388
412
|
}
|
|
389
413
|
class f {
|
|
@@ -397,7 +421,7 @@ class f {
|
|
|
397
421
|
* upon construction.
|
|
398
422
|
*/
|
|
399
423
|
constructor(t = []) {
|
|
400
|
-
this.sortedInterceptors = [], this.sortedInterceptors =
|
|
424
|
+
this.sortedInterceptors = [], this.sortedInterceptors = m(t);
|
|
401
425
|
}
|
|
402
426
|
/**
|
|
403
427
|
* Gets the name of this interceptor registry.
|
|
@@ -435,7 +459,7 @@ class f {
|
|
|
435
459
|
* After adding, interceptors are automatically sorted by their order property.
|
|
436
460
|
*/
|
|
437
461
|
use(t) {
|
|
438
|
-
return this.sortedInterceptors.some((r) => r.name === t.name) ? !1 : (this.sortedInterceptors =
|
|
462
|
+
return this.sortedInterceptors.some((r) => r.name === t.name) ? !1 : (this.sortedInterceptors = m([
|
|
439
463
|
...this.sortedInterceptors,
|
|
440
464
|
t
|
|
441
465
|
]), !0);
|
|
@@ -449,7 +473,7 @@ class f {
|
|
|
449
473
|
*/
|
|
450
474
|
eject(t) {
|
|
451
475
|
const r = this.sortedInterceptors;
|
|
452
|
-
return this.sortedInterceptors =
|
|
476
|
+
return this.sortedInterceptors = m(
|
|
453
477
|
r,
|
|
454
478
|
(s) => s.name !== t
|
|
455
479
|
), r.length !== this.sortedInterceptors.length;
|
|
@@ -479,21 +503,21 @@ class f {
|
|
|
479
503
|
await r.intercept(t);
|
|
480
504
|
}
|
|
481
505
|
}
|
|
482
|
-
class
|
|
506
|
+
class q extends E {
|
|
483
507
|
constructor(t) {
|
|
484
508
|
super(
|
|
485
509
|
`Request failed with status code ${t.response?.status} for ${t.request.url}`
|
|
486
|
-
), this.exchange = t, this.name = "HttpStatusValidationError", Object.setPrototypeOf(this,
|
|
510
|
+
), this.exchange = t, this.name = "HttpStatusValidationError", Object.setPrototypeOf(this, q.prototype);
|
|
487
511
|
}
|
|
488
512
|
}
|
|
489
|
-
const
|
|
490
|
-
class
|
|
513
|
+
const tt = (e) => e >= 200 && e < 300, et = "ValidateStatusInterceptor", rt = Number.MAX_SAFE_INTEGER - 1e3;
|
|
514
|
+
class st {
|
|
491
515
|
/**
|
|
492
516
|
* Creates a new ValidateStatusInterceptor instance.
|
|
493
517
|
*
|
|
494
518
|
* @param validateStatus - Function that determines if a status code is valid
|
|
495
519
|
*/
|
|
496
|
-
constructor(t =
|
|
520
|
+
constructor(t = tt) {
|
|
497
521
|
this.validateStatus = t;
|
|
498
522
|
}
|
|
499
523
|
/**
|
|
@@ -502,7 +526,7 @@ class et {
|
|
|
502
526
|
* @returns The name of this interceptor
|
|
503
527
|
*/
|
|
504
528
|
get name() {
|
|
505
|
-
return
|
|
529
|
+
return et;
|
|
506
530
|
}
|
|
507
531
|
/**
|
|
508
532
|
* Gets the order of this interceptor.
|
|
@@ -510,7 +534,7 @@ class et {
|
|
|
510
534
|
* @returns VALIDATE_STATUS_INTERCEPTOR_ORDER, indicating this interceptor should execute early
|
|
511
535
|
*/
|
|
512
536
|
get order() {
|
|
513
|
-
return
|
|
537
|
+
return rt;
|
|
514
538
|
}
|
|
515
539
|
/**
|
|
516
540
|
* Validates the response status code.
|
|
@@ -530,10 +554,10 @@ class et {
|
|
|
530
554
|
return;
|
|
531
555
|
const r = t.response.status;
|
|
532
556
|
if (!this.validateStatus(r))
|
|
533
|
-
throw new
|
|
557
|
+
throw new q(t);
|
|
534
558
|
}
|
|
535
559
|
}
|
|
536
|
-
class R extends
|
|
560
|
+
class R extends E {
|
|
537
561
|
/**
|
|
538
562
|
* Creates a new ExchangeError instance.
|
|
539
563
|
*
|
|
@@ -545,14 +569,14 @@ class R extends l {
|
|
|
545
569
|
super(s, t.error), this.exchange = t, this.name = "ExchangeError", Object.setPrototypeOf(this, R.prototype);
|
|
546
570
|
}
|
|
547
571
|
}
|
|
548
|
-
class
|
|
572
|
+
class ot {
|
|
549
573
|
constructor() {
|
|
550
574
|
this.request = new f([
|
|
551
|
-
new
|
|
552
|
-
new
|
|
553
|
-
new
|
|
575
|
+
new J(),
|
|
576
|
+
new z(),
|
|
577
|
+
new Z()
|
|
554
578
|
]), this.response = new f([
|
|
555
|
-
new
|
|
579
|
+
new st()
|
|
556
580
|
]), this.error = new f();
|
|
557
581
|
}
|
|
558
582
|
/**
|
|
@@ -651,17 +675,17 @@ class rt {
|
|
|
651
675
|
}
|
|
652
676
|
}
|
|
653
677
|
}
|
|
654
|
-
const
|
|
655
|
-
Exchange:
|
|
656
|
-
Response:
|
|
657
|
-
Json:
|
|
658
|
-
Text:
|
|
678
|
+
const nt = (e) => e, it = (e) => e.requiredResponse, ut = (e) => e.requiredResponse.json(), at = (e) => e.requiredResponse.text(), b = {
|
|
679
|
+
Exchange: nt,
|
|
680
|
+
Response: it,
|
|
681
|
+
Json: ut,
|
|
682
|
+
Text: at
|
|
659
683
|
};
|
|
660
|
-
function
|
|
684
|
+
function S(e, t) {
|
|
661
685
|
if (!(e === void 0 && t === void 0))
|
|
662
686
|
return t === void 0 ? e : e === void 0 ? t : { ...e, ...t };
|
|
663
687
|
}
|
|
664
|
-
function
|
|
688
|
+
function ct(e, t) {
|
|
665
689
|
if (t ??= /* @__PURE__ */ new Map(), !e)
|
|
666
690
|
return t;
|
|
667
691
|
if (e instanceof Map) {
|
|
@@ -673,9 +697,9 @@ function it(e, t) {
|
|
|
673
697
|
t.set(r, s);
|
|
674
698
|
return t;
|
|
675
699
|
}
|
|
676
|
-
class
|
|
700
|
+
class ht {
|
|
677
701
|
constructor(t) {
|
|
678
|
-
this.fetcher = t.fetcher, this.request = t.request, this.resultExtractor = t.resultExtractor ??
|
|
702
|
+
this.fetcher = t.fetcher, this.request = t.request, this.resultExtractor = t.resultExtractor ?? b.Exchange, this.attributes = ct(t.attributes), this._response = t.response, this.error = t.error;
|
|
679
703
|
}
|
|
680
704
|
/**
|
|
681
705
|
* Ensures that request headers object exists, creating it if necessary.
|
|
@@ -774,12 +798,12 @@ function dt(e, t) {
|
|
|
774
798
|
if (Object.keys(t).length === 0)
|
|
775
799
|
return e;
|
|
776
800
|
const r = {
|
|
777
|
-
path:
|
|
778
|
-
query:
|
|
801
|
+
path: S(e.urlParams?.path, t.urlParams?.path),
|
|
802
|
+
query: S(e.urlParams?.query, t.urlParams?.query)
|
|
779
803
|
}, s = {
|
|
780
804
|
...e.headers,
|
|
781
805
|
...t.headers
|
|
782
|
-
}, o = t.method ?? e.method, n = t.body ?? e.body,
|
|
806
|
+
}, o = t.method ?? e.method, n = t.body ?? e.body, i = t.timeout ?? e.timeout, a = t.signal ?? e.signal, T = t.abortController ?? e.abortController;
|
|
783
807
|
return {
|
|
784
808
|
...e,
|
|
785
809
|
...t,
|
|
@@ -787,26 +811,26 @@ function dt(e, t) {
|
|
|
787
811
|
urlParams: r,
|
|
788
812
|
headers: s,
|
|
789
813
|
body: n,
|
|
790
|
-
timeout:
|
|
791
|
-
signal:
|
|
792
|
-
abortController:
|
|
814
|
+
timeout: i,
|
|
815
|
+
signal: a,
|
|
816
|
+
abortController: T
|
|
793
817
|
};
|
|
794
818
|
}
|
|
795
|
-
function
|
|
819
|
+
function A(e, t) {
|
|
796
820
|
return t && t.resultExtractor && t.attributes ? t : {
|
|
797
|
-
resultExtractor: t?.resultExtractor ?? e?.resultExtractor ??
|
|
821
|
+
resultExtractor: t?.resultExtractor ?? e?.resultExtractor ?? v.resultExtractor,
|
|
798
822
|
attributes: t?.attributes ?? e?.attributes
|
|
799
823
|
};
|
|
800
824
|
}
|
|
801
|
-
const
|
|
802
|
-
|
|
803
|
-
},
|
|
825
|
+
const y = {
|
|
826
|
+
[c]: d.APPLICATION_JSON
|
|
827
|
+
}, U = {
|
|
804
828
|
baseURL: "",
|
|
805
|
-
headers:
|
|
806
|
-
},
|
|
807
|
-
resultExtractor:
|
|
829
|
+
headers: y
|
|
830
|
+
}, v = { resultExtractor: b.Exchange }, N = {
|
|
831
|
+
resultExtractor: b.Response
|
|
808
832
|
};
|
|
809
|
-
class
|
|
833
|
+
class D {
|
|
810
834
|
/**
|
|
811
835
|
* Initializes a new Fetcher instance with optional configuration.
|
|
812
836
|
*
|
|
@@ -820,29 +844,8 @@ class U {
|
|
|
820
844
|
* @param options.urlTemplateStyle - Style for URL template parameter interpolation.
|
|
821
845
|
* @param options.interceptors - Interceptor manager for processing requests and responses.
|
|
822
846
|
*/
|
|
823
|
-
constructor(t =
|
|
824
|
-
this.headers =
|
|
825
|
-
}
|
|
826
|
-
/**
|
|
827
|
-
* Processes an HTTP request through the Fetcher's internal workflow.
|
|
828
|
-
*
|
|
829
|
-
* This method prepares the request by merging headers and timeout settings,
|
|
830
|
-
* creates a FetchExchange object, and passes it through the exchange method
|
|
831
|
-
* for interceptor processing.
|
|
832
|
-
*
|
|
833
|
-
* @template R - The type of the result to be returned
|
|
834
|
-
* @param request - Complete request configuration object
|
|
835
|
-
* @param options - Request options including result extractor and attributes
|
|
836
|
-
* @param options.resultExtractor - Function to extract the desired result from the exchange.
|
|
837
|
-
* Defaults to ExchangeResultExtractor which returns the entire exchange object.
|
|
838
|
-
* @param options.attributes - Optional shared attributes that can be accessed by interceptors
|
|
839
|
-
* throughout the request lifecycle. These attributes allow passing
|
|
840
|
-
* custom data between different interceptors.
|
|
841
|
-
* @returns Promise that resolves to the extracted result based on resultExtractor
|
|
842
|
-
* @throws Error if an unhandled error occurs during request processing
|
|
843
|
-
*/
|
|
844
|
-
async request(t, r) {
|
|
845
|
-
return (await this.exchange(t, r)).extractResult();
|
|
847
|
+
constructor(t = U) {
|
|
848
|
+
this.headers = y, this.urlBuilder = new $(t.baseURL, t.urlTemplateStyle), this.headers = t.headers ?? y, this.timeout = t.timeout, this.interceptors = t.interceptors ?? new ot();
|
|
846
849
|
}
|
|
847
850
|
/**
|
|
848
851
|
* Processes an HTTP request through the Fetcher's internal workflow.
|
|
@@ -861,17 +864,38 @@ class U {
|
|
|
861
864
|
}, o = {
|
|
862
865
|
...t,
|
|
863
866
|
headers: s,
|
|
864
|
-
timeout:
|
|
867
|
+
timeout: X(t.timeout, this.timeout)
|
|
865
868
|
}, {
|
|
866
869
|
resultExtractor: n,
|
|
867
|
-
attributes:
|
|
868
|
-
} =
|
|
870
|
+
attributes: i
|
|
871
|
+
} = A(v, r), a = new ht({
|
|
869
872
|
fetcher: this,
|
|
870
873
|
request: o,
|
|
871
874
|
resultExtractor: n,
|
|
872
|
-
attributes:
|
|
875
|
+
attributes: i
|
|
873
876
|
});
|
|
874
|
-
return this.interceptors.exchange(
|
|
877
|
+
return this.interceptors.exchange(a);
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Processes an HTTP request through the Fetcher's internal workflow.
|
|
881
|
+
*
|
|
882
|
+
* This method prepares the request by merging headers and timeout settings,
|
|
883
|
+
* creates a FetchExchange object, and passes it through the exchange method
|
|
884
|
+
* for interceptor processing.
|
|
885
|
+
*
|
|
886
|
+
* @template R - The type of the result to be returned
|
|
887
|
+
* @param request - Complete request configuration object
|
|
888
|
+
* @param options - Request options including result extractor and attributes
|
|
889
|
+
* @param options.resultExtractor - Function to extract the desired result from the exchange.
|
|
890
|
+
* Defaults to ExchangeResultExtractor which returns the entire exchange object.
|
|
891
|
+
* @param options.attributes - Optional shared attributes that can be accessed by interceptors
|
|
892
|
+
* throughout the request lifecycle. These attributes allow passing
|
|
893
|
+
* custom data between different interceptors.
|
|
894
|
+
* @returns Promise that resolves to the extracted result based on resultExtractor
|
|
895
|
+
* @throws Error if an unhandled error occurs during request processing
|
|
896
|
+
*/
|
|
897
|
+
async request(t, r) {
|
|
898
|
+
return (await this.exchange(t, r)).extractResult();
|
|
875
899
|
}
|
|
876
900
|
/**
|
|
877
901
|
* Executes an HTTP request with the specified URL and options.
|
|
@@ -892,8 +916,11 @@ class U {
|
|
|
892
916
|
* @throws FetchError if the request fails and no response is generated
|
|
893
917
|
*/
|
|
894
918
|
async fetch(t, r = {}, s) {
|
|
895
|
-
const o =
|
|
896
|
-
|
|
919
|
+
const o = {
|
|
920
|
+
...r,
|
|
921
|
+
url: t
|
|
922
|
+
};
|
|
923
|
+
return this.request(o, A(N, s));
|
|
897
924
|
}
|
|
898
925
|
/**
|
|
899
926
|
* Internal helper method for making HTTP requests with a specific method.
|
|
@@ -914,14 +941,12 @@ class U {
|
|
|
914
941
|
* @returns Promise that resolves to the HTTP response
|
|
915
942
|
*/
|
|
916
943
|
async methodFetch(t, r, s = {}, o) {
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
o
|
|
924
|
-
);
|
|
944
|
+
const n = {
|
|
945
|
+
...s,
|
|
946
|
+
url: r,
|
|
947
|
+
method: t
|
|
948
|
+
};
|
|
949
|
+
return this.request(n, A(N, o));
|
|
925
950
|
}
|
|
926
951
|
/**
|
|
927
952
|
* Makes a GET HTTP request.
|
|
@@ -941,7 +966,7 @@ class U {
|
|
|
941
966
|
* @returns Promise that resolves to the HTTP response
|
|
942
967
|
*/
|
|
943
968
|
async get(t, r = {}, s) {
|
|
944
|
-
return this.methodFetch(
|
|
969
|
+
return this.methodFetch(u.GET, t, r, s);
|
|
945
970
|
}
|
|
946
971
|
/**
|
|
947
972
|
* Makes a PUT HTTP request.
|
|
@@ -960,7 +985,7 @@ class U {
|
|
|
960
985
|
* @returns Promise that resolves to the HTTP response
|
|
961
986
|
*/
|
|
962
987
|
async put(t, r = {}, s) {
|
|
963
|
-
return this.methodFetch(
|
|
988
|
+
return this.methodFetch(u.PUT, t, r, s);
|
|
964
989
|
}
|
|
965
990
|
/**
|
|
966
991
|
* Makes a POST HTTP request.
|
|
@@ -979,7 +1004,7 @@ class U {
|
|
|
979
1004
|
* @returns Promise that resolves to the HTTP response
|
|
980
1005
|
*/
|
|
981
1006
|
async post(t, r = {}, s) {
|
|
982
|
-
return this.methodFetch(
|
|
1007
|
+
return this.methodFetch(u.POST, t, r, s);
|
|
983
1008
|
}
|
|
984
1009
|
/**
|
|
985
1010
|
* Makes a PATCH HTTP request.
|
|
@@ -998,7 +1023,7 @@ class U {
|
|
|
998
1023
|
* @returns Promise that resolves to the HTTP response
|
|
999
1024
|
*/
|
|
1000
1025
|
async patch(t, r = {}, s) {
|
|
1001
|
-
return this.methodFetch(
|
|
1026
|
+
return this.methodFetch(u.PATCH, t, r, s);
|
|
1002
1027
|
}
|
|
1003
1028
|
/**
|
|
1004
1029
|
* Makes a DELETE HTTP request.
|
|
@@ -1017,7 +1042,7 @@ class U {
|
|
|
1017
1042
|
* @returns Promise that resolves to the HTTP response
|
|
1018
1043
|
*/
|
|
1019
1044
|
async delete(t, r = {}, s) {
|
|
1020
|
-
return this.methodFetch(
|
|
1045
|
+
return this.methodFetch(u.DELETE, t, r, s);
|
|
1021
1046
|
}
|
|
1022
1047
|
/**
|
|
1023
1048
|
* Makes a HEAD HTTP request.
|
|
@@ -1037,7 +1062,7 @@ class U {
|
|
|
1037
1062
|
* @returns Promise that resolves to the HTTP response
|
|
1038
1063
|
*/
|
|
1039
1064
|
async head(t, r = {}, s) {
|
|
1040
|
-
return this.methodFetch(
|
|
1065
|
+
return this.methodFetch(u.HEAD, t, r, s);
|
|
1041
1066
|
}
|
|
1042
1067
|
/**
|
|
1043
1068
|
* Makes an OPTIONS HTTP request.
|
|
@@ -1057,11 +1082,11 @@ class U {
|
|
|
1057
1082
|
* @returns Promise that resolves to the HTTP response
|
|
1058
1083
|
*/
|
|
1059
1084
|
async options(t, r = {}, s) {
|
|
1060
|
-
return this.methodFetch(
|
|
1085
|
+
return this.methodFetch(u.OPTIONS, t, r, s);
|
|
1061
1086
|
}
|
|
1062
1087
|
}
|
|
1063
|
-
const
|
|
1064
|
-
class
|
|
1088
|
+
const _ = "default";
|
|
1089
|
+
class lt {
|
|
1065
1090
|
constructor() {
|
|
1066
1091
|
this.registrar = /* @__PURE__ */ new Map();
|
|
1067
1092
|
}
|
|
@@ -1134,7 +1159,7 @@ class ht {
|
|
|
1134
1159
|
* const defaultFetcher = fetcherRegistrar.default;
|
|
1135
1160
|
*/
|
|
1136
1161
|
get default() {
|
|
1137
|
-
return this.requiredGet(
|
|
1162
|
+
return this.requiredGet(_);
|
|
1138
1163
|
}
|
|
1139
1164
|
/**
|
|
1140
1165
|
* Set the default Fetcher instance
|
|
@@ -1145,7 +1170,7 @@ class ht {
|
|
|
1145
1170
|
* fetcherRegistrar.default = fetcher;
|
|
1146
1171
|
*/
|
|
1147
1172
|
set default(t) {
|
|
1148
|
-
this.register(
|
|
1173
|
+
this.register(_, t);
|
|
1149
1174
|
}
|
|
1150
1175
|
/**
|
|
1151
1176
|
* Get a copy of all registered fetchers
|
|
@@ -1161,11 +1186,11 @@ class ht {
|
|
|
1161
1186
|
return new Map(this.registrar);
|
|
1162
1187
|
}
|
|
1163
1188
|
}
|
|
1164
|
-
const
|
|
1165
|
-
function
|
|
1166
|
-
return e ? e instanceof
|
|
1189
|
+
const O = new lt();
|
|
1190
|
+
function pt(e, t) {
|
|
1191
|
+
return e ? e instanceof D ? e : O.requiredGet(e) : t ?? O.default;
|
|
1167
1192
|
}
|
|
1168
|
-
class
|
|
1193
|
+
class Et extends D {
|
|
1169
1194
|
/**
|
|
1170
1195
|
* Create a NamedFetcher instance and automatically register it with the global fetcherRegistrar
|
|
1171
1196
|
*
|
|
@@ -1183,66 +1208,66 @@ class lt extends U {
|
|
|
1183
1208
|
* headers: { 'Authorization': 'Bearer token' }
|
|
1184
1209
|
* });
|
|
1185
1210
|
*/
|
|
1186
|
-
constructor(t, r =
|
|
1187
|
-
super(r), this.name = t,
|
|
1211
|
+
constructor(t, r = U) {
|
|
1212
|
+
super(r), this.name = t, O.register(t, this);
|
|
1188
1213
|
}
|
|
1189
1214
|
}
|
|
1190
|
-
const
|
|
1215
|
+
const Rt = new Et(_);
|
|
1191
1216
|
export {
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1217
|
+
c as CONTENT_TYPE_HEADER,
|
|
1218
|
+
d as ContentTypeValues,
|
|
1219
|
+
_ as DEFAULT_FETCHER_NAME,
|
|
1220
|
+
N as DEFAULT_FETCH_OPTIONS,
|
|
1221
|
+
U as DEFAULT_OPTIONS,
|
|
1222
|
+
v as DEFAULT_REQUEST_OPTIONS,
|
|
1198
1223
|
R as ExchangeError,
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1224
|
+
nt as ExchangeResultExtractor,
|
|
1225
|
+
g as ExpressUrlTemplateResolver,
|
|
1226
|
+
K as FETCH_INTERCEPTOR_NAME,
|
|
1227
|
+
W as FETCH_INTERCEPTOR_ORDER,
|
|
1228
|
+
ht as FetchExchange,
|
|
1229
|
+
Z as FetchInterceptor,
|
|
1230
|
+
I as FetchTimeoutError,
|
|
1231
|
+
D as Fetcher,
|
|
1232
|
+
E as FetcherError,
|
|
1233
|
+
lt as FetcherRegistrar,
|
|
1234
|
+
u as HttpMethod,
|
|
1235
|
+
q as HttpStatusValidationError,
|
|
1236
|
+
ot as InterceptorManager,
|
|
1212
1237
|
f as InterceptorRegistry,
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1238
|
+
ut as JsonResultExtractor,
|
|
1239
|
+
Et as NamedFetcher,
|
|
1240
|
+
Q as REQUEST_BODY_INTERCEPTOR_NAME,
|
|
1241
|
+
Y as REQUEST_BODY_INTERCEPTOR_ORDER,
|
|
1242
|
+
z as RequestBodyInterceptor,
|
|
1243
|
+
it as ResponseResultExtractor,
|
|
1244
|
+
b as ResultExtractors,
|
|
1245
|
+
at as TextResultExtractor,
|
|
1246
|
+
k as URL_RESOLVE_INTERCEPTOR_NAME,
|
|
1247
|
+
C as URL_RESOLVE_INTERCEPTOR_ORDER,
|
|
1248
|
+
P as UriTemplateResolver,
|
|
1249
|
+
$ as UrlBuilder,
|
|
1250
|
+
J as UrlResolveInterceptor,
|
|
1251
|
+
G as UrlTemplateStyle,
|
|
1252
|
+
et as VALIDATE_STATUS_INTERCEPTOR_NAME,
|
|
1253
|
+
rt as VALIDATE_STATUS_INTERCEPTOR_ORDER,
|
|
1254
|
+
st as ValidateStatusInterceptor,
|
|
1255
|
+
M as combineURLs,
|
|
1256
|
+
j as expressUrlTemplateResolver,
|
|
1257
|
+
Rt as fetcher,
|
|
1258
|
+
O as fetcherRegistrar,
|
|
1259
|
+
pt as getFetcher,
|
|
1260
|
+
H as getUrlTemplateResolver,
|
|
1261
|
+
L as isAbsoluteURL,
|
|
1262
|
+
ct as mergeRecordToMap,
|
|
1263
|
+
S as mergeRecords,
|
|
1239
1264
|
dt as mergeRequest,
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1265
|
+
A as mergeRequestOptions,
|
|
1266
|
+
X as resolveTimeout,
|
|
1267
|
+
V as timeoutFetch,
|
|
1268
|
+
m as toSorted,
|
|
1269
|
+
B as uriTemplateResolver,
|
|
1270
|
+
F as urlTemplateRegexExtract,
|
|
1271
|
+
x as urlTemplateRegexResolve
|
|
1247
1272
|
};
|
|
1248
1273
|
//# sourceMappingURL=index.es.js.map
|