enterprise-fetch 1.0.1 → 2.0.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/dist/client/enterprise-fetch.cjs.js +1119 -1449
- package/dist/client/enterprise-fetch.cjs.min.js +3 -1
- package/dist/client/enterprise-fetch.esm.js +583 -611
- package/dist/client/enterprise-fetch.esm.min.js +1 -1
- package/dist/enterprise-fetch.cjs.js +107 -139
- package/dist/enterprise-fetch.d.ts +5 -6
- package/dist/enterprise-fetch.esm.js +107 -113
- package/dist/enterprise-fetch.esm.js.map +1 -0
- package/dist/fetch-defaults.d.ts +3 -3
- package/dist/models/AppError.d.ts +27 -27
- package/dist/models/EnterpriseFetch.d.ts +15 -15
- package/dist/models/index.d.ts +2 -2
- package/dist/util/client/is-client.d.ts +2 -2
- package/dist/util/parsejson.d.ts +3 -3
- package/dist/util/resolve.d.ts +1 -0
- package/dist/util/server/fetch.d.ts +2 -2
- package/dist/util/server/proxy-agent.d.ts +5 -5
- package/dist/util/typeguards.d.ts +2 -2
- package/package.json +47 -48
|
@@ -1,612 +1,584 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}(this, (function (exports
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
clearTimeout(timeoutId);
|
|
586
|
-
|
|
587
|
-
if (isFunc(doRetry) && (await doRetry(attempt, response, {
|
|
588
|
-
url,
|
|
589
|
-
options: init
|
|
590
|
-
}))) {
|
|
591
|
-
retry(response);
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
return response;
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
clearTimeout(timeoutId);
|
|
598
|
-
return response;
|
|
599
|
-
}, init.retry || fetchDefaults$1.retry);
|
|
600
|
-
return fetchResponse;
|
|
601
|
-
};
|
|
602
|
-
|
|
603
|
-
return enterpriseFetch;
|
|
604
|
-
};
|
|
605
|
-
var enterpriseFetch = fetchWithDefaults(fetchDefaults);
|
|
606
|
-
|
|
607
|
-
exports.default = enterpriseFetch;
|
|
608
|
-
exports.fetchWithDefaults = fetchWithDefaults;
|
|
609
|
-
|
|
610
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
611
|
-
|
|
612
|
-
})));
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["enterprise-fetch"] = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function getDefaultExportFromCjs (x) {
|
|
8
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
var browser = {exports: {}};
|
|
12
|
+
|
|
13
|
+
/*globals self, window */
|
|
14
|
+
|
|
15
|
+
var hasRequiredBrowser;
|
|
16
|
+
|
|
17
|
+
function requireBrowser () {
|
|
18
|
+
if (hasRequiredBrowser) return browser.exports;
|
|
19
|
+
hasRequiredBrowser = 1;
|
|
20
|
+
|
|
21
|
+
/*eslint-disable @mysticatea/prettier */
|
|
22
|
+
const { AbortController, AbortSignal } =
|
|
23
|
+
typeof self !== "undefined" ? self :
|
|
24
|
+
typeof window !== "undefined" ? window :
|
|
25
|
+
/* otherwise */ undefined;
|
|
26
|
+
/*eslint-enable @mysticatea/prettier */
|
|
27
|
+
|
|
28
|
+
browser.exports = AbortController;
|
|
29
|
+
browser.exports.AbortSignal = AbortSignal;
|
|
30
|
+
browser.exports.default = AbortController;
|
|
31
|
+
return browser.exports;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var browserExports = requireBrowser();
|
|
35
|
+
var AbortController = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param { Promise } promise
|
|
39
|
+
* @param { Object= } errorExt - Additional Information you can pass to the err object
|
|
40
|
+
* @return { Promise }
|
|
41
|
+
*/
|
|
42
|
+
function to(promise, errorExt) {
|
|
43
|
+
return promise
|
|
44
|
+
.then(function (data) { return [null, data]; })
|
|
45
|
+
.catch(function (err) {
|
|
46
|
+
return [err, undefined];
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var errCode;
|
|
51
|
+
var hasRequiredErrCode;
|
|
52
|
+
|
|
53
|
+
function requireErrCode () {
|
|
54
|
+
if (hasRequiredErrCode) return errCode;
|
|
55
|
+
hasRequiredErrCode = 1;
|
|
56
|
+
|
|
57
|
+
function assign(obj, props) {
|
|
58
|
+
for (const key in props) {
|
|
59
|
+
Object.defineProperty(obj, key, {
|
|
60
|
+
value: props[key],
|
|
61
|
+
enumerable: true,
|
|
62
|
+
configurable: true,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return obj;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function createError(err, code, props) {
|
|
70
|
+
if (!err || typeof err === 'string') {
|
|
71
|
+
throw new TypeError('Please pass an Error to err-code');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!props) {
|
|
75
|
+
props = {};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (typeof code === 'object') {
|
|
79
|
+
props = code;
|
|
80
|
+
code = undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (code != null) {
|
|
84
|
+
props.code = code;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
return assign(err, props);
|
|
89
|
+
} catch (_) {
|
|
90
|
+
props.message = err.message;
|
|
91
|
+
props.stack = err.stack;
|
|
92
|
+
|
|
93
|
+
const ErrClass = function () {};
|
|
94
|
+
|
|
95
|
+
ErrClass.prototype = Object.create(Object.getPrototypeOf(err));
|
|
96
|
+
|
|
97
|
+
return assign(new ErrClass(), props);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
errCode = createError;
|
|
102
|
+
return errCode;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
var retry$1 = {};
|
|
106
|
+
|
|
107
|
+
var retry_operation;
|
|
108
|
+
var hasRequiredRetry_operation;
|
|
109
|
+
|
|
110
|
+
function requireRetry_operation () {
|
|
111
|
+
if (hasRequiredRetry_operation) return retry_operation;
|
|
112
|
+
hasRequiredRetry_operation = 1;
|
|
113
|
+
function RetryOperation(timeouts, options) {
|
|
114
|
+
// Compatibility for the old (timeouts, retryForever) signature
|
|
115
|
+
if (typeof options === 'boolean') {
|
|
116
|
+
options = { forever: options };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
120
|
+
this._timeouts = timeouts;
|
|
121
|
+
this._options = options || {};
|
|
122
|
+
this._maxRetryTime = options && options.maxRetryTime || Infinity;
|
|
123
|
+
this._fn = null;
|
|
124
|
+
this._errors = [];
|
|
125
|
+
this._attempts = 1;
|
|
126
|
+
this._operationTimeout = null;
|
|
127
|
+
this._operationTimeoutCb = null;
|
|
128
|
+
this._timeout = null;
|
|
129
|
+
this._operationStart = null;
|
|
130
|
+
|
|
131
|
+
if (this._options.forever) {
|
|
132
|
+
this._cachedTimeouts = this._timeouts.slice(0);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
retry_operation = RetryOperation;
|
|
136
|
+
|
|
137
|
+
RetryOperation.prototype.reset = function() {
|
|
138
|
+
this._attempts = 1;
|
|
139
|
+
this._timeouts = this._originalTimeouts;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
RetryOperation.prototype.stop = function() {
|
|
143
|
+
if (this._timeout) {
|
|
144
|
+
clearTimeout(this._timeout);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
this._timeouts = [];
|
|
148
|
+
this._cachedTimeouts = null;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
RetryOperation.prototype.retry = function(err) {
|
|
152
|
+
if (this._timeout) {
|
|
153
|
+
clearTimeout(this._timeout);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!err) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
var currentTime = new Date().getTime();
|
|
160
|
+
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
161
|
+
this._errors.unshift(new Error('RetryOperation timeout occurred'));
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
this._errors.push(err);
|
|
166
|
+
|
|
167
|
+
var timeout = this._timeouts.shift();
|
|
168
|
+
if (timeout === undefined) {
|
|
169
|
+
if (this._cachedTimeouts) {
|
|
170
|
+
// retry forever, only keep last error
|
|
171
|
+
this._errors.splice(this._errors.length - 1, this._errors.length);
|
|
172
|
+
this._timeouts = this._cachedTimeouts.slice(0);
|
|
173
|
+
timeout = this._timeouts.shift();
|
|
174
|
+
} else {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
var self = this;
|
|
180
|
+
var timer = setTimeout(function() {
|
|
181
|
+
self._attempts++;
|
|
182
|
+
|
|
183
|
+
if (self._operationTimeoutCb) {
|
|
184
|
+
self._timeout = setTimeout(function() {
|
|
185
|
+
self._operationTimeoutCb(self._attempts);
|
|
186
|
+
}, self._operationTimeout);
|
|
187
|
+
|
|
188
|
+
if (self._options.unref) {
|
|
189
|
+
self._timeout.unref();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
self._fn(self._attempts);
|
|
194
|
+
}, timeout);
|
|
195
|
+
|
|
196
|
+
if (this._options.unref) {
|
|
197
|
+
timer.unref();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return true;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
|
|
204
|
+
this._fn = fn;
|
|
205
|
+
|
|
206
|
+
if (timeoutOps) {
|
|
207
|
+
if (timeoutOps.timeout) {
|
|
208
|
+
this._operationTimeout = timeoutOps.timeout;
|
|
209
|
+
}
|
|
210
|
+
if (timeoutOps.cb) {
|
|
211
|
+
this._operationTimeoutCb = timeoutOps.cb;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
var self = this;
|
|
216
|
+
if (this._operationTimeoutCb) {
|
|
217
|
+
this._timeout = setTimeout(function() {
|
|
218
|
+
self._operationTimeoutCb();
|
|
219
|
+
}, self._operationTimeout);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
this._operationStart = new Date().getTime();
|
|
223
|
+
|
|
224
|
+
this._fn(this._attempts);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
RetryOperation.prototype.try = function(fn) {
|
|
228
|
+
console.log('Using RetryOperation.try() is deprecated');
|
|
229
|
+
this.attempt(fn);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
RetryOperation.prototype.start = function(fn) {
|
|
233
|
+
console.log('Using RetryOperation.start() is deprecated');
|
|
234
|
+
this.attempt(fn);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
238
|
+
|
|
239
|
+
RetryOperation.prototype.errors = function() {
|
|
240
|
+
return this._errors;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
RetryOperation.prototype.attempts = function() {
|
|
244
|
+
return this._attempts;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
RetryOperation.prototype.mainError = function() {
|
|
248
|
+
if (this._errors.length === 0) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
var counts = {};
|
|
253
|
+
var mainError = null;
|
|
254
|
+
var mainErrorCount = 0;
|
|
255
|
+
|
|
256
|
+
for (var i = 0; i < this._errors.length; i++) {
|
|
257
|
+
var error = this._errors[i];
|
|
258
|
+
var message = error.message;
|
|
259
|
+
var count = (counts[message] || 0) + 1;
|
|
260
|
+
|
|
261
|
+
counts[message] = count;
|
|
262
|
+
|
|
263
|
+
if (count >= mainErrorCount) {
|
|
264
|
+
mainError = error;
|
|
265
|
+
mainErrorCount = count;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return mainError;
|
|
270
|
+
};
|
|
271
|
+
return retry_operation;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
var hasRequiredRetry$1;
|
|
275
|
+
|
|
276
|
+
function requireRetry$1 () {
|
|
277
|
+
if (hasRequiredRetry$1) return retry$1;
|
|
278
|
+
hasRequiredRetry$1 = 1;
|
|
279
|
+
(function (exports) {
|
|
280
|
+
var RetryOperation = requireRetry_operation();
|
|
281
|
+
|
|
282
|
+
exports.operation = function(options) {
|
|
283
|
+
var timeouts = exports.timeouts(options);
|
|
284
|
+
return new RetryOperation(timeouts, {
|
|
285
|
+
forever: options && options.forever,
|
|
286
|
+
unref: options && options.unref,
|
|
287
|
+
maxRetryTime: options && options.maxRetryTime
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
exports.timeouts = function(options) {
|
|
292
|
+
if (options instanceof Array) {
|
|
293
|
+
return [].concat(options);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
var opts = {
|
|
297
|
+
retries: 10,
|
|
298
|
+
factor: 2,
|
|
299
|
+
minTimeout: 1 * 1000,
|
|
300
|
+
maxTimeout: Infinity,
|
|
301
|
+
randomize: false
|
|
302
|
+
};
|
|
303
|
+
for (var key in options) {
|
|
304
|
+
opts[key] = options[key];
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (opts.minTimeout > opts.maxTimeout) {
|
|
308
|
+
throw new Error('minTimeout is greater than maxTimeout');
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
var timeouts = [];
|
|
312
|
+
for (var i = 0; i < opts.retries; i++) {
|
|
313
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (options && options.forever && !timeouts.length) {
|
|
317
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// sort the array numerically ascending
|
|
321
|
+
timeouts.sort(function(a,b) {
|
|
322
|
+
return a - b;
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
return timeouts;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
exports.createTimeout = function(attempt, opts) {
|
|
329
|
+
var random = (opts.randomize)
|
|
330
|
+
? (Math.random() + 1)
|
|
331
|
+
: 1;
|
|
332
|
+
|
|
333
|
+
var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
|
|
334
|
+
timeout = Math.min(timeout, opts.maxTimeout);
|
|
335
|
+
|
|
336
|
+
return timeout;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
exports.wrap = function(obj, options, methods) {
|
|
340
|
+
if (options instanceof Array) {
|
|
341
|
+
methods = options;
|
|
342
|
+
options = null;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (!methods) {
|
|
346
|
+
methods = [];
|
|
347
|
+
for (var key in obj) {
|
|
348
|
+
if (typeof obj[key] === 'function') {
|
|
349
|
+
methods.push(key);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
for (var i = 0; i < methods.length; i++) {
|
|
355
|
+
var method = methods[i];
|
|
356
|
+
var original = obj[method];
|
|
357
|
+
|
|
358
|
+
obj[method] = function retryWrapper(original) {
|
|
359
|
+
var op = exports.operation(options);
|
|
360
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
361
|
+
var callback = args.pop();
|
|
362
|
+
|
|
363
|
+
args.push(function(err) {
|
|
364
|
+
if (op.retry(err)) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (err) {
|
|
368
|
+
arguments[0] = op.mainError();
|
|
369
|
+
}
|
|
370
|
+
callback.apply(this, arguments);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
op.attempt(function() {
|
|
374
|
+
original.apply(obj, args);
|
|
375
|
+
});
|
|
376
|
+
}.bind(obj, original);
|
|
377
|
+
obj[method].options = options;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
} (retry$1));
|
|
381
|
+
return retry$1;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
var retry;
|
|
385
|
+
var hasRequiredRetry;
|
|
386
|
+
|
|
387
|
+
function requireRetry () {
|
|
388
|
+
if (hasRequiredRetry) return retry;
|
|
389
|
+
hasRequiredRetry = 1;
|
|
390
|
+
retry = requireRetry$1();
|
|
391
|
+
return retry;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
var promiseRetry_1;
|
|
395
|
+
var hasRequiredPromiseRetry;
|
|
396
|
+
|
|
397
|
+
function requirePromiseRetry () {
|
|
398
|
+
if (hasRequiredPromiseRetry) return promiseRetry_1;
|
|
399
|
+
hasRequiredPromiseRetry = 1;
|
|
400
|
+
|
|
401
|
+
var errcode = requireErrCode();
|
|
402
|
+
var retry = requireRetry();
|
|
403
|
+
|
|
404
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
405
|
+
|
|
406
|
+
function isRetryError(err) {
|
|
407
|
+
return err && err.code === 'EPROMISERETRY' && hasOwn.call(err, 'retried');
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function promiseRetry(fn, options) {
|
|
411
|
+
var temp;
|
|
412
|
+
var operation;
|
|
413
|
+
|
|
414
|
+
if (typeof fn === 'object' && typeof options === 'function') {
|
|
415
|
+
// Swap options and fn when using alternate signature (options, fn)
|
|
416
|
+
temp = options;
|
|
417
|
+
options = fn;
|
|
418
|
+
fn = temp;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
operation = retry.operation(options);
|
|
422
|
+
|
|
423
|
+
return new Promise(function (resolve, reject) {
|
|
424
|
+
operation.attempt(function (number) {
|
|
425
|
+
Promise.resolve()
|
|
426
|
+
.then(function () {
|
|
427
|
+
return fn(function (err) {
|
|
428
|
+
if (isRetryError(err)) {
|
|
429
|
+
err = err.retried;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
throw errcode(new Error('Retrying'), 'EPROMISERETRY', { retried: err });
|
|
433
|
+
}, number);
|
|
434
|
+
})
|
|
435
|
+
.then(resolve, function (err) {
|
|
436
|
+
if (isRetryError(err)) {
|
|
437
|
+
err = err.retried;
|
|
438
|
+
|
|
439
|
+
if (operation.retry(err || new Error())) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
reject(err);
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
promiseRetry_1 = promiseRetry;
|
|
451
|
+
return promiseRetry_1;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
var promiseRetryExports = requirePromiseRetry();
|
|
455
|
+
var promiseRetry = /*@__PURE__*/getDefaultExportFromCjs(promiseRetryExports);
|
|
456
|
+
|
|
457
|
+
const fetchDefaults = {
|
|
458
|
+
// The timeout to apply to requests that do not supply a timeout option
|
|
459
|
+
timeout: 60 * 1000,
|
|
460
|
+
// Retry policy for all fetch requests
|
|
461
|
+
retry: {
|
|
462
|
+
retries: 3,
|
|
463
|
+
minTimeout: 400,
|
|
464
|
+
factor: 2
|
|
465
|
+
},
|
|
466
|
+
// Do retry function to examine failures and apply custom retry logic
|
|
467
|
+
// return true to retry the fetch call
|
|
468
|
+
doRetry: async (attempt, res, {
|
|
469
|
+
url,
|
|
470
|
+
options
|
|
471
|
+
}) => {
|
|
472
|
+
// Get the retry policy from options or fetchDefaults
|
|
473
|
+
const {
|
|
474
|
+
retry = fetchDefaults.retry
|
|
475
|
+
} = options;
|
|
476
|
+
if (attempt <= retry.retries) {
|
|
477
|
+
const counter = `${attempt}/${retry.retries}`;
|
|
478
|
+
// Retry request on any network error,
|
|
479
|
+
// or 4xx or 5xx status codes. No retry on 404
|
|
480
|
+
if (!res.status || res.status >= 400 && res.status !== 404) {
|
|
481
|
+
if ('message' in res) console.warn(`[fetch] Attempt ${counter} ${res.name}: ${res.message} ${url}`);else console.warn(`[fetch] Attempt ${counter} ${res.status}: ${res.statusText} ${url}`);
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
const isClient = () => typeof window !== 'undefined';
|
|
490
|
+
|
|
491
|
+
const resolveFetch = async () => {
|
|
492
|
+
if (isClient()) return window.fetch;
|
|
493
|
+
if (typeof globalThis.fetch === 'function') return globalThis.fetch;
|
|
494
|
+
const nodeFetch = await ('node-fetch');
|
|
495
|
+
// recast node-fetch to keep typescript happy
|
|
496
|
+
return nodeFetch.default;
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
// Setting http_proxy in env will inject a proxy agent header and disable certificate verification
|
|
500
|
+
const proxyAgent = async () => {
|
|
501
|
+
const proxyUri = !isClient() && typeof process !== 'undefined' && process.env.http_proxy || false;
|
|
502
|
+
if (proxyUri) {
|
|
503
|
+
// console.info(`Proxying via http_proxy: ${process.env.http_proxy}`);
|
|
504
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
505
|
+
// NOTE: This uses the HttpsProxyAgent class from https-proxy-agent v7.x
|
|
506
|
+
// Will break in v8+ where only a default factory function is exported
|
|
507
|
+
const {
|
|
508
|
+
HttpsProxyAgent
|
|
509
|
+
} = await ('https-proxy-agent');
|
|
510
|
+
return {
|
|
511
|
+
agent: new HttpsProxyAgent(proxyUri)
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
return {};
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
const isFunc = func => typeof func === 'function';
|
|
518
|
+
|
|
519
|
+
const fetchWithDefaults = (fetchDefaults$1 = fetchDefaults) => {
|
|
520
|
+
// Fetch function using hoisted defaults wrapped in a promise
|
|
521
|
+
// retry function adhering to a default or supplied policy calling
|
|
522
|
+
// a doRetry function on each failure that requires a boolean return
|
|
523
|
+
const enterpriseFetch = async (url, init = {}) => {
|
|
524
|
+
const thisFetch = await resolveFetch();
|
|
525
|
+
const fetchResponse = await promiseRetry(async (retry, attempt) => {
|
|
526
|
+
const {
|
|
527
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
528
|
+
retry: retryPolicy = fetchDefaults$1.retry,
|
|
529
|
+
timeout: rtimeout = fetchDefaults$1.timeout,
|
|
530
|
+
doRetry = fetchDefaults$1.doRetry || fetchDefaults.doRetry,
|
|
531
|
+
...options
|
|
532
|
+
} = init;
|
|
533
|
+
const timeoutMs = rtimeout || fetchDefaults$1.timeout || 60 * 1000;
|
|
534
|
+
// Abort signal pattern
|
|
535
|
+
// Since v15.4.0 Node.js comes with AbortController out of the box
|
|
536
|
+
const controller = new AbortController();
|
|
537
|
+
const timeoutId = setTimeout(() => {
|
|
538
|
+
controller.abort();
|
|
539
|
+
}, timeoutMs);
|
|
540
|
+
// Try fetching, wait for error or response
|
|
541
|
+
const [error, response] = await to(thisFetch(url, {
|
|
542
|
+
// Standard fetch options
|
|
543
|
+
...options,
|
|
544
|
+
// Conditionally add a proxy agent to debug requests
|
|
545
|
+
...(await proxyAgent()),
|
|
546
|
+
// The signal will recieve abort() after timeout elapsed
|
|
547
|
+
signal: controller.signal
|
|
548
|
+
}));
|
|
549
|
+
if (error) {
|
|
550
|
+
clearTimeout(timeoutId);
|
|
551
|
+
if (isFunc(doRetry) && (await doRetry(attempt, error, {
|
|
552
|
+
url: url.toString(),
|
|
553
|
+
options: init
|
|
554
|
+
}))) {
|
|
555
|
+
retry(error);
|
|
556
|
+
}
|
|
557
|
+
throw error;
|
|
558
|
+
}
|
|
559
|
+
if (!response.ok) {
|
|
560
|
+
clearTimeout(timeoutId);
|
|
561
|
+
if (isFunc(doRetry) && (await doRetry(attempt, response, {
|
|
562
|
+
url: url.toString(),
|
|
563
|
+
options: init
|
|
564
|
+
}))) {
|
|
565
|
+
retry(response);
|
|
566
|
+
}
|
|
567
|
+
return response;
|
|
568
|
+
}
|
|
569
|
+
clearTimeout(timeoutId);
|
|
570
|
+
return response;
|
|
571
|
+
}, init.retry || fetchDefaults$1.retry);
|
|
572
|
+
return fetchResponse;
|
|
573
|
+
};
|
|
574
|
+
return enterpriseFetch;
|
|
575
|
+
};
|
|
576
|
+
const fetch = fetchWithDefaults(fetchDefaults);
|
|
577
|
+
|
|
578
|
+
exports.default = fetch;
|
|
579
|
+
exports.fetch = fetch;
|
|
580
|
+
exports.fetchWithDefaults = fetchWithDefaults;
|
|
581
|
+
|
|
582
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
583
|
+
|
|
584
|
+
}));
|