denotify-client 1.1.8 → 1.1.9

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/index.js CHANGED
@@ -1,4214 +1,32 @@
1
1
  'use strict';
2
2
 
3
3
  var supabaseJs = require('@supabase/supabase-js');
4
- var FormData$1 = require('form-data');
5
- var url = require('url');
6
- var proxyFromEnv = require('proxy-from-env');
7
- var http = require('http');
8
- var https = require('https');
9
- var util = require('util');
10
- var followRedirects = require('follow-redirects');
11
- var zlib = require('zlib');
12
- var stream = require('stream');
13
- var EventEmitter = require('events');
14
4
  var yup = require('yup');
15
5
  var ethers = require('ethers');
6
+ var fetch = require('node-fetch');
16
7
 
17
8
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
9
 
19
10
  function _interopNamespace(e) {
20
- if (e && e.__esModule) return e;
21
- var n = Object.create(null);
22
- if (e) {
23
- Object.keys(e).forEach(function (k) {
24
- if (k !== 'default') {
25
- var d = Object.getOwnPropertyDescriptor(e, k);
26
- Object.defineProperty(n, k, d.get ? d : {
27
- enumerable: true,
28
- get: function () { return e[k]; }
29
- });
30
- }
31
- });
32
- }
33
- n["default"] = e;
34
- return Object.freeze(n);
35
- }
36
-
37
- var FormData__default = /*#__PURE__*/_interopDefaultLegacy(FormData$1);
38
- var url__default = /*#__PURE__*/_interopDefaultLegacy(url);
39
- var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
40
- var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
41
- var util__default = /*#__PURE__*/_interopDefaultLegacy(util);
42
- var followRedirects__default = /*#__PURE__*/_interopDefaultLegacy(followRedirects);
43
- var zlib__default = /*#__PURE__*/_interopDefaultLegacy(zlib);
44
- var stream__default = /*#__PURE__*/_interopDefaultLegacy(stream);
45
- var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
46
- var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
47
-
48
- function bind(fn, thisArg) {
49
- return function wrap() {
50
- return fn.apply(thisArg, arguments);
51
- };
52
- }
53
-
54
- // utils is a library of generic helper functions non-specific to axios
55
-
56
- const {toString} = Object.prototype;
57
- const {getPrototypeOf} = Object;
58
-
59
- const kindOf = (cache => thing => {
60
- const str = toString.call(thing);
61
- return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
62
- })(Object.create(null));
63
-
64
- const kindOfTest = (type) => {
65
- type = type.toLowerCase();
66
- return (thing) => kindOf(thing) === type
67
- };
68
-
69
- const typeOfTest = type => thing => typeof thing === type;
70
-
71
- /**
72
- * Determine if a value is an Array
73
- *
74
- * @param {Object} val The value to test
75
- *
76
- * @returns {boolean} True if value is an Array, otherwise false
77
- */
78
- const {isArray} = Array;
79
-
80
- /**
81
- * Determine if a value is undefined
82
- *
83
- * @param {*} val The value to test
84
- *
85
- * @returns {boolean} True if the value is undefined, otherwise false
86
- */
87
- const isUndefined = typeOfTest('undefined');
88
-
89
- /**
90
- * Determine if a value is a Buffer
91
- *
92
- * @param {*} val The value to test
93
- *
94
- * @returns {boolean} True if value is a Buffer, otherwise false
95
- */
96
- function isBuffer(val) {
97
- return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
98
- && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
99
- }
100
-
101
- /**
102
- * Determine if a value is an ArrayBuffer
103
- *
104
- * @param {*} val The value to test
105
- *
106
- * @returns {boolean} True if value is an ArrayBuffer, otherwise false
107
- */
108
- const isArrayBuffer = kindOfTest('ArrayBuffer');
109
-
110
-
111
- /**
112
- * Determine if a value is a view on an ArrayBuffer
113
- *
114
- * @param {*} val The value to test
115
- *
116
- * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
117
- */
118
- function isArrayBufferView(val) {
119
- let result;
120
- if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
121
- result = ArrayBuffer.isView(val);
122
- } else {
123
- result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
124
- }
125
- return result;
126
- }
127
-
128
- /**
129
- * Determine if a value is a String
130
- *
131
- * @param {*} val The value to test
132
- *
133
- * @returns {boolean} True if value is a String, otherwise false
134
- */
135
- const isString = typeOfTest('string');
136
-
137
- /**
138
- * Determine if a value is a Function
139
- *
140
- * @param {*} val The value to test
141
- * @returns {boolean} True if value is a Function, otherwise false
142
- */
143
- const isFunction = typeOfTest('function');
144
-
145
- /**
146
- * Determine if a value is a Number
147
- *
148
- * @param {*} val The value to test
149
- *
150
- * @returns {boolean} True if value is a Number, otherwise false
151
- */
152
- const isNumber = typeOfTest('number');
153
-
154
- /**
155
- * Determine if a value is an Object
156
- *
157
- * @param {*} thing The value to test
158
- *
159
- * @returns {boolean} True if value is an Object, otherwise false
160
- */
161
- const isObject = (thing) => thing !== null && typeof thing === 'object';
162
-
163
- /**
164
- * Determine if a value is a Boolean
165
- *
166
- * @param {*} thing The value to test
167
- * @returns {boolean} True if value is a Boolean, otherwise false
168
- */
169
- const isBoolean = thing => thing === true || thing === false;
170
-
171
- /**
172
- * Determine if a value is a plain Object
173
- *
174
- * @param {*} val The value to test
175
- *
176
- * @returns {boolean} True if value is a plain Object, otherwise false
177
- */
178
- const isPlainObject = (val) => {
179
- if (kindOf(val) !== 'object') {
180
- return false;
181
- }
182
-
183
- const prototype = getPrototypeOf(val);
184
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
185
- };
186
-
187
- /**
188
- * Determine if a value is a Date
189
- *
190
- * @param {*} val The value to test
191
- *
192
- * @returns {boolean} True if value is a Date, otherwise false
193
- */
194
- const isDate = kindOfTest('Date');
195
-
196
- /**
197
- * Determine if a value is a File
198
- *
199
- * @param {*} val The value to test
200
- *
201
- * @returns {boolean} True if value is a File, otherwise false
202
- */
203
- const isFile = kindOfTest('File');
204
-
205
- /**
206
- * Determine if a value is a Blob
207
- *
208
- * @param {*} val The value to test
209
- *
210
- * @returns {boolean} True if value is a Blob, otherwise false
211
- */
212
- const isBlob = kindOfTest('Blob');
213
-
214
- /**
215
- * Determine if a value is a FileList
216
- *
217
- * @param {*} val The value to test
218
- *
219
- * @returns {boolean} True if value is a File, otherwise false
220
- */
221
- const isFileList = kindOfTest('FileList');
222
-
223
- /**
224
- * Determine if a value is a Stream
225
- *
226
- * @param {*} val The value to test
227
- *
228
- * @returns {boolean} True if value is a Stream, otherwise false
229
- */
230
- const isStream = (val) => isObject(val) && isFunction(val.pipe);
231
-
232
- /**
233
- * Determine if a value is a FormData
234
- *
235
- * @param {*} thing The value to test
236
- *
237
- * @returns {boolean} True if value is an FormData, otherwise false
238
- */
239
- const isFormData = (thing) => {
240
- const pattern = '[object FormData]';
241
- return thing && (
242
- (typeof FormData === 'function' && thing instanceof FormData) ||
243
- toString.call(thing) === pattern ||
244
- (isFunction(thing.toString) && thing.toString() === pattern)
245
- );
246
- };
247
-
248
- /**
249
- * Determine if a value is a URLSearchParams object
250
- *
251
- * @param {*} val The value to test
252
- *
253
- * @returns {boolean} True if value is a URLSearchParams object, otherwise false
254
- */
255
- const isURLSearchParams = kindOfTest('URLSearchParams');
256
-
257
- /**
258
- * Trim excess whitespace off the beginning and end of a string
259
- *
260
- * @param {String} str The String to trim
261
- *
262
- * @returns {String} The String freed of excess whitespace
263
- */
264
- const trim = (str) => str.trim ?
265
- str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
266
-
267
- /**
268
- * Iterate over an Array or an Object invoking a function for each item.
269
- *
270
- * If `obj` is an Array callback will be called passing
271
- * the value, index, and complete array for each item.
272
- *
273
- * If 'obj' is an Object callback will be called passing
274
- * the value, key, and complete object for each property.
275
- *
276
- * @param {Object|Array} obj The object to iterate
277
- * @param {Function} fn The callback to invoke for each item
278
- *
279
- * @param {Boolean} [allOwnKeys = false]
280
- * @returns {any}
281
- */
282
- function forEach(obj, fn, {allOwnKeys = false} = {}) {
283
- // Don't bother if no value provided
284
- if (obj === null || typeof obj === 'undefined') {
285
- return;
286
- }
287
-
288
- let i;
289
- let l;
290
-
291
- // Force an array if not already something iterable
292
- if (typeof obj !== 'object') {
293
- /*eslint no-param-reassign:0*/
294
- obj = [obj];
295
- }
296
-
297
- if (isArray(obj)) {
298
- // Iterate over array values
299
- for (i = 0, l = obj.length; i < l; i++) {
300
- fn.call(null, obj[i], i, obj);
301
- }
302
- } else {
303
- // Iterate over object keys
304
- const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
305
- const len = keys.length;
306
- let key;
307
-
308
- for (i = 0; i < len; i++) {
309
- key = keys[i];
310
- fn.call(null, obj[key], key, obj);
311
- }
312
- }
313
- }
314
-
315
- function findKey(obj, key) {
316
- key = key.toLowerCase();
317
- const keys = Object.keys(obj);
318
- let i = keys.length;
319
- let _key;
320
- while (i-- > 0) {
321
- _key = keys[i];
322
- if (key === _key.toLowerCase()) {
323
- return _key;
324
- }
325
- }
326
- return null;
327
- }
328
-
329
- const _global = (() => {
330
- /*eslint no-undef:0*/
331
- if (typeof globalThis !== "undefined") return globalThis;
332
- return typeof self !== "undefined" ? self : (typeof window !== 'undefined' ? window : global)
333
- })();
334
-
335
- const isContextDefined = (context) => !isUndefined(context) && context !== _global;
336
-
337
- /**
338
- * Accepts varargs expecting each argument to be an object, then
339
- * immutably merges the properties of each object and returns result.
340
- *
341
- * When multiple objects contain the same key the later object in
342
- * the arguments list will take precedence.
343
- *
344
- * Example:
345
- *
346
- * ```js
347
- * var result = merge({foo: 123}, {foo: 456});
348
- * console.log(result.foo); // outputs 456
349
- * ```
350
- *
351
- * @param {Object} obj1 Object to merge
352
- *
353
- * @returns {Object} Result of all merge properties
354
- */
355
- function merge(/* obj1, obj2, obj3, ... */) {
356
- const {caseless} = isContextDefined(this) && this || {};
357
- const result = {};
358
- const assignValue = (val, key) => {
359
- const targetKey = caseless && findKey(result, key) || key;
360
- if (isPlainObject(result[targetKey]) && isPlainObject(val)) {
361
- result[targetKey] = merge(result[targetKey], val);
362
- } else if (isPlainObject(val)) {
363
- result[targetKey] = merge({}, val);
364
- } else if (isArray(val)) {
365
- result[targetKey] = val.slice();
366
- } else {
367
- result[targetKey] = val;
368
- }
369
- };
370
-
371
- for (let i = 0, l = arguments.length; i < l; i++) {
372
- arguments[i] && forEach(arguments[i], assignValue);
373
- }
374
- return result;
375
- }
376
-
377
- /**
378
- * Extends object a by mutably adding to it the properties of object b.
379
- *
380
- * @param {Object} a The object to be extended
381
- * @param {Object} b The object to copy properties from
382
- * @param {Object} thisArg The object to bind function to
383
- *
384
- * @param {Boolean} [allOwnKeys]
385
- * @returns {Object} The resulting value of object a
386
- */
387
- const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
388
- forEach(b, (val, key) => {
389
- if (thisArg && isFunction(val)) {
390
- a[key] = bind(val, thisArg);
391
- } else {
392
- a[key] = val;
393
- }
394
- }, {allOwnKeys});
395
- return a;
396
- };
397
-
398
- /**
399
- * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
400
- *
401
- * @param {string} content with BOM
402
- *
403
- * @returns {string} content value without BOM
404
- */
405
- const stripBOM = (content) => {
406
- if (content.charCodeAt(0) === 0xFEFF) {
407
- content = content.slice(1);
408
- }
409
- return content;
410
- };
411
-
412
- /**
413
- * Inherit the prototype methods from one constructor into another
414
- * @param {function} constructor
415
- * @param {function} superConstructor
416
- * @param {object} [props]
417
- * @param {object} [descriptors]
418
- *
419
- * @returns {void}
420
- */
421
- const inherits = (constructor, superConstructor, props, descriptors) => {
422
- constructor.prototype = Object.create(superConstructor.prototype, descriptors);
423
- constructor.prototype.constructor = constructor;
424
- Object.defineProperty(constructor, 'super', {
425
- value: superConstructor.prototype
426
- });
427
- props && Object.assign(constructor.prototype, props);
428
- };
429
-
430
- /**
431
- * Resolve object with deep prototype chain to a flat object
432
- * @param {Object} sourceObj source object
433
- * @param {Object} [destObj]
434
- * @param {Function|Boolean} [filter]
435
- * @param {Function} [propFilter]
436
- *
437
- * @returns {Object}
438
- */
439
- const toFlatObject = (sourceObj, destObj, filter, propFilter) => {
440
- let props;
441
- let i;
442
- let prop;
443
- const merged = {};
444
-
445
- destObj = destObj || {};
446
- // eslint-disable-next-line no-eq-null,eqeqeq
447
- if (sourceObj == null) return destObj;
448
-
449
- do {
450
- props = Object.getOwnPropertyNames(sourceObj);
451
- i = props.length;
452
- while (i-- > 0) {
453
- prop = props[i];
454
- if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
455
- destObj[prop] = sourceObj[prop];
456
- merged[prop] = true;
457
- }
458
- }
459
- sourceObj = filter !== false && getPrototypeOf(sourceObj);
460
- } while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
461
-
462
- return destObj;
463
- };
464
-
465
- /**
466
- * Determines whether a string ends with the characters of a specified string
467
- *
468
- * @param {String} str
469
- * @param {String} searchString
470
- * @param {Number} [position= 0]
471
- *
472
- * @returns {boolean}
473
- */
474
- const endsWith = (str, searchString, position) => {
475
- str = String(str);
476
- if (position === undefined || position > str.length) {
477
- position = str.length;
478
- }
479
- position -= searchString.length;
480
- const lastIndex = str.indexOf(searchString, position);
481
- return lastIndex !== -1 && lastIndex === position;
482
- };
483
-
484
-
485
- /**
486
- * Returns new array from array like object or null if failed
487
- *
488
- * @param {*} [thing]
489
- *
490
- * @returns {?Array}
491
- */
492
- const toArray = (thing) => {
493
- if (!thing) return null;
494
- if (isArray(thing)) return thing;
495
- let i = thing.length;
496
- if (!isNumber(i)) return null;
497
- const arr = new Array(i);
498
- while (i-- > 0) {
499
- arr[i] = thing[i];
500
- }
501
- return arr;
502
- };
503
-
504
- /**
505
- * Checking if the Uint8Array exists and if it does, it returns a function that checks if the
506
- * thing passed in is an instance of Uint8Array
507
- *
508
- * @param {TypedArray}
509
- *
510
- * @returns {Array}
511
- */
512
- // eslint-disable-next-line func-names
513
- const isTypedArray = (TypedArray => {
514
- // eslint-disable-next-line func-names
515
- return thing => {
516
- return TypedArray && thing instanceof TypedArray;
517
- };
518
- })(typeof Uint8Array !== 'undefined' && getPrototypeOf(Uint8Array));
519
-
520
- /**
521
- * For each entry in the object, call the function with the key and value.
522
- *
523
- * @param {Object<any, any>} obj - The object to iterate over.
524
- * @param {Function} fn - The function to call for each entry.
525
- *
526
- * @returns {void}
527
- */
528
- const forEachEntry = (obj, fn) => {
529
- const generator = obj && obj[Symbol.iterator];
530
-
531
- const iterator = generator.call(obj);
532
-
533
- let result;
534
-
535
- while ((result = iterator.next()) && !result.done) {
536
- const pair = result.value;
537
- fn.call(obj, pair[0], pair[1]);
538
- }
539
- };
540
-
541
- /**
542
- * It takes a regular expression and a string, and returns an array of all the matches
543
- *
544
- * @param {string} regExp - The regular expression to match against.
545
- * @param {string} str - The string to search.
546
- *
547
- * @returns {Array<boolean>}
548
- */
549
- const matchAll = (regExp, str) => {
550
- let matches;
551
- const arr = [];
552
-
553
- while ((matches = regExp.exec(str)) !== null) {
554
- arr.push(matches);
555
- }
556
-
557
- return arr;
558
- };
559
-
560
- /* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */
561
- const isHTMLForm = kindOfTest('HTMLFormElement');
562
-
563
- const toCamelCase = str => {
564
- return str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,
565
- function replacer(m, p1, p2) {
566
- return p1.toUpperCase() + p2;
567
- }
568
- );
569
- };
570
-
571
- /* Creating a function that will check if an object has a property. */
572
- const hasOwnProperty = (({hasOwnProperty}) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);
573
-
574
- /**
575
- * Determine if a value is a RegExp object
576
- *
577
- * @param {*} val The value to test
578
- *
579
- * @returns {boolean} True if value is a RegExp object, otherwise false
580
- */
581
- const isRegExp = kindOfTest('RegExp');
582
-
583
- const reduceDescriptors = (obj, reducer) => {
584
- const descriptors = Object.getOwnPropertyDescriptors(obj);
585
- const reducedDescriptors = {};
586
-
587
- forEach(descriptors, (descriptor, name) => {
588
- if (reducer(descriptor, name, obj) !== false) {
589
- reducedDescriptors[name] = descriptor;
590
- }
591
- });
592
-
593
- Object.defineProperties(obj, reducedDescriptors);
594
- };
595
-
596
- /**
597
- * Makes all methods read-only
598
- * @param {Object} obj
599
- */
600
-
601
- const freezeMethods = (obj) => {
602
- reduceDescriptors(obj, (descriptor, name) => {
603
- // skip restricted props in strict mode
604
- if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
605
- return false;
606
- }
607
-
608
- const value = obj[name];
609
-
610
- if (!isFunction(value)) return;
611
-
612
- descriptor.enumerable = false;
613
-
614
- if ('writable' in descriptor) {
615
- descriptor.writable = false;
616
- return;
617
- }
618
-
619
- if (!descriptor.set) {
620
- descriptor.set = () => {
621
- throw Error('Can not rewrite read-only method \'' + name + '\'');
622
- };
623
- }
624
- });
625
- };
626
-
627
- const toObjectSet = (arrayOrString, delimiter) => {
628
- const obj = {};
629
-
630
- const define = (arr) => {
631
- arr.forEach(value => {
632
- obj[value] = true;
633
- });
634
- };
635
-
636
- isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
637
-
638
- return obj;
639
- };
640
-
641
- const noop = () => {};
642
-
643
- const toFiniteNumber = (value, defaultValue) => {
644
- value = +value;
645
- return Number.isFinite(value) ? value : defaultValue;
646
- };
647
-
648
- const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
649
-
650
- const DIGIT = '0123456789';
651
-
652
- const ALPHABET = {
653
- DIGIT,
654
- ALPHA,
655
- ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
656
- };
657
-
658
- const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
659
- let str = '';
660
- const {length} = alphabet;
661
- while (size--) {
662
- str += alphabet[Math.random() * length|0];
663
- }
664
-
665
- return str;
666
- };
667
-
668
- /**
669
- * If the thing is a FormData object, return true, otherwise return false.
670
- *
671
- * @param {unknown} thing - The thing to check.
672
- *
673
- * @returns {boolean}
674
- */
675
- function isSpecCompliantForm(thing) {
676
- return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator]);
677
- }
678
-
679
- const toJSONObject = (obj) => {
680
- const stack = new Array(10);
681
-
682
- const visit = (source, i) => {
683
-
684
- if (isObject(source)) {
685
- if (stack.indexOf(source) >= 0) {
686
- return;
687
- }
688
-
689
- if(!('toJSON' in source)) {
690
- stack[i] = source;
691
- const target = isArray(source) ? [] : {};
692
-
693
- forEach(source, (value, key) => {
694
- const reducedValue = visit(value, i + 1);
695
- !isUndefined(reducedValue) && (target[key] = reducedValue);
696
- });
697
-
698
- stack[i] = undefined;
699
-
700
- return target;
701
- }
702
- }
703
-
704
- return source;
705
- };
706
-
707
- return visit(obj, 0);
708
- };
709
-
710
- var utils = {
711
- isArray,
712
- isArrayBuffer,
713
- isBuffer,
714
- isFormData,
715
- isArrayBufferView,
716
- isString,
717
- isNumber,
718
- isBoolean,
719
- isObject,
720
- isPlainObject,
721
- isUndefined,
722
- isDate,
723
- isFile,
724
- isBlob,
725
- isRegExp,
726
- isFunction,
727
- isStream,
728
- isURLSearchParams,
729
- isTypedArray,
730
- isFileList,
731
- forEach,
732
- merge,
733
- extend,
734
- trim,
735
- stripBOM,
736
- inherits,
737
- toFlatObject,
738
- kindOf,
739
- kindOfTest,
740
- endsWith,
741
- toArray,
742
- forEachEntry,
743
- matchAll,
744
- isHTMLForm,
745
- hasOwnProperty,
746
- hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
747
- reduceDescriptors,
748
- freezeMethods,
749
- toObjectSet,
750
- toCamelCase,
751
- noop,
752
- toFiniteNumber,
753
- findKey,
754
- global: _global,
755
- isContextDefined,
756
- ALPHABET,
757
- generateString,
758
- isSpecCompliantForm,
759
- toJSONObject
760
- };
761
-
762
- /**
763
- * Create an Error with the specified message, config, error code, request and response.
764
- *
765
- * @param {string} message The error message.
766
- * @param {string} [code] The error code (for example, 'ECONNABORTED').
767
- * @param {Object} [config] The config.
768
- * @param {Object} [request] The request.
769
- * @param {Object} [response] The response.
770
- *
771
- * @returns {Error} The created error.
772
- */
773
- function AxiosError(message, code, config, request, response) {
774
- Error.call(this);
775
-
776
- if (Error.captureStackTrace) {
777
- Error.captureStackTrace(this, this.constructor);
778
- } else {
779
- this.stack = (new Error()).stack;
780
- }
781
-
782
- this.message = message;
783
- this.name = 'AxiosError';
784
- code && (this.code = code);
785
- config && (this.config = config);
786
- request && (this.request = request);
787
- response && (this.response = response);
788
- }
789
-
790
- utils.inherits(AxiosError, Error, {
791
- toJSON: function toJSON() {
792
- return {
793
- // Standard
794
- message: this.message,
795
- name: this.name,
796
- // Microsoft
797
- description: this.description,
798
- number: this.number,
799
- // Mozilla
800
- fileName: this.fileName,
801
- lineNumber: this.lineNumber,
802
- columnNumber: this.columnNumber,
803
- stack: this.stack,
804
- // Axios
805
- config: utils.toJSONObject(this.config),
806
- code: this.code,
807
- status: this.response && this.response.status ? this.response.status : null
808
- };
809
- }
810
- });
811
-
812
- const prototype$1 = AxiosError.prototype;
813
- const descriptors = {};
814
-
815
- [
816
- 'ERR_BAD_OPTION_VALUE',
817
- 'ERR_BAD_OPTION',
818
- 'ECONNABORTED',
819
- 'ETIMEDOUT',
820
- 'ERR_NETWORK',
821
- 'ERR_FR_TOO_MANY_REDIRECTS',
822
- 'ERR_DEPRECATED',
823
- 'ERR_BAD_RESPONSE',
824
- 'ERR_BAD_REQUEST',
825
- 'ERR_CANCELED',
826
- 'ERR_NOT_SUPPORT',
827
- 'ERR_INVALID_URL'
828
- // eslint-disable-next-line func-names
829
- ].forEach(code => {
830
- descriptors[code] = {value: code};
831
- });
832
-
833
- Object.defineProperties(AxiosError, descriptors);
834
- Object.defineProperty(prototype$1, 'isAxiosError', {value: true});
835
-
836
- // eslint-disable-next-line func-names
837
- AxiosError.from = (error, code, config, request, response, customProps) => {
838
- const axiosError = Object.create(prototype$1);
839
-
840
- utils.toFlatObject(error, axiosError, function filter(obj) {
841
- return obj !== Error.prototype;
842
- }, prop => {
843
- return prop !== 'isAxiosError';
844
- });
845
-
846
- AxiosError.call(axiosError, error.message, code, config, request, response);
847
-
848
- axiosError.cause = error;
849
-
850
- axiosError.name = error.name;
851
-
852
- customProps && Object.assign(axiosError, customProps);
853
-
854
- return axiosError;
855
- };
856
-
857
- /**
858
- * Determines if the given thing is a array or js object.
859
- *
860
- * @param {string} thing - The object or array to be visited.
861
- *
862
- * @returns {boolean}
863
- */
864
- function isVisitable(thing) {
865
- return utils.isPlainObject(thing) || utils.isArray(thing);
866
- }
867
-
868
- /**
869
- * It removes the brackets from the end of a string
870
- *
871
- * @param {string} key - The key of the parameter.
872
- *
873
- * @returns {string} the key without the brackets.
874
- */
875
- function removeBrackets(key) {
876
- return utils.endsWith(key, '[]') ? key.slice(0, -2) : key;
877
- }
878
-
879
- /**
880
- * It takes a path, a key, and a boolean, and returns a string
881
- *
882
- * @param {string} path - The path to the current key.
883
- * @param {string} key - The key of the current object being iterated over.
884
- * @param {string} dots - If true, the key will be rendered with dots instead of brackets.
885
- *
886
- * @returns {string} The path to the current key.
887
- */
888
- function renderKey(path, key, dots) {
889
- if (!path) return key;
890
- return path.concat(key).map(function each(token, i) {
891
- // eslint-disable-next-line no-param-reassign
892
- token = removeBrackets(token);
893
- return !dots && i ? '[' + token + ']' : token;
894
- }).join(dots ? '.' : '');
895
- }
896
-
897
- /**
898
- * If the array is an array and none of its elements are visitable, then it's a flat array.
899
- *
900
- * @param {Array<any>} arr - The array to check
901
- *
902
- * @returns {boolean}
903
- */
904
- function isFlatArray(arr) {
905
- return utils.isArray(arr) && !arr.some(isVisitable);
906
- }
907
-
908
- const predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
909
- return /^is[A-Z]/.test(prop);
910
- });
911
-
912
- /**
913
- * Convert a data object to FormData
914
- *
915
- * @param {Object} obj
916
- * @param {?Object} [formData]
917
- * @param {?Object} [options]
918
- * @param {Function} [options.visitor]
919
- * @param {Boolean} [options.metaTokens = true]
920
- * @param {Boolean} [options.dots = false]
921
- * @param {?Boolean} [options.indexes = false]
922
- *
923
- * @returns {Object}
924
- **/
925
-
926
- /**
927
- * It converts an object into a FormData object
928
- *
929
- * @param {Object<any, any>} obj - The object to convert to form data.
930
- * @param {string} formData - The FormData object to append to.
931
- * @param {Object<string, any>} options
932
- *
933
- * @returns
934
- */
935
- function toFormData(obj, formData, options) {
936
- if (!utils.isObject(obj)) {
937
- throw new TypeError('target must be an object');
938
- }
939
-
940
- // eslint-disable-next-line no-param-reassign
941
- formData = formData || new (FormData__default["default"] || FormData)();
942
-
943
- // eslint-disable-next-line no-param-reassign
944
- options = utils.toFlatObject(options, {
945
- metaTokens: true,
946
- dots: false,
947
- indexes: false
948
- }, false, function defined(option, source) {
949
- // eslint-disable-next-line no-eq-null,eqeqeq
950
- return !utils.isUndefined(source[option]);
951
- });
952
-
953
- const metaTokens = options.metaTokens;
954
- // eslint-disable-next-line no-use-before-define
955
- const visitor = options.visitor || defaultVisitor;
956
- const dots = options.dots;
957
- const indexes = options.indexes;
958
- const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
959
- const useBlob = _Blob && utils.isSpecCompliantForm(formData);
960
-
961
- if (!utils.isFunction(visitor)) {
962
- throw new TypeError('visitor must be a function');
963
- }
964
-
965
- function convertValue(value) {
966
- if (value === null) return '';
967
-
968
- if (utils.isDate(value)) {
969
- return value.toISOString();
970
- }
971
-
972
- if (!useBlob && utils.isBlob(value)) {
973
- throw new AxiosError('Blob is not supported. Use a Buffer instead.');
974
- }
975
-
976
- if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) {
977
- return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
978
- }
979
-
980
- return value;
981
- }
982
-
983
- /**
984
- * Default visitor.
985
- *
986
- * @param {*} value
987
- * @param {String|Number} key
988
- * @param {Array<String|Number>} path
989
- * @this {FormData}
990
- *
991
- * @returns {boolean} return true to visit the each prop of the value recursively
992
- */
993
- function defaultVisitor(value, key, path) {
994
- let arr = value;
995
-
996
- if (value && !path && typeof value === 'object') {
997
- if (utils.endsWith(key, '{}')) {
998
- // eslint-disable-next-line no-param-reassign
999
- key = metaTokens ? key : key.slice(0, -2);
1000
- // eslint-disable-next-line no-param-reassign
1001
- value = JSON.stringify(value);
1002
- } else if (
1003
- (utils.isArray(value) && isFlatArray(value)) ||
1004
- ((utils.isFileList(value) || utils.endsWith(key, '[]')) && (arr = utils.toArray(value))
1005
- )) {
1006
- // eslint-disable-next-line no-param-reassign
1007
- key = removeBrackets(key);
1008
-
1009
- arr.forEach(function each(el, index) {
1010
- !(utils.isUndefined(el) || el === null) && formData.append(
1011
- // eslint-disable-next-line no-nested-ternary
1012
- indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),
1013
- convertValue(el)
1014
- );
1015
- });
1016
- return false;
1017
- }
1018
- }
1019
-
1020
- if (isVisitable(value)) {
1021
- return true;
1022
- }
1023
-
1024
- formData.append(renderKey(path, key, dots), convertValue(value));
1025
-
1026
- return false;
1027
- }
1028
-
1029
- const stack = [];
1030
-
1031
- const exposedHelpers = Object.assign(predicates, {
1032
- defaultVisitor,
1033
- convertValue,
1034
- isVisitable
1035
- });
1036
-
1037
- function build(value, path) {
1038
- if (utils.isUndefined(value)) return;
1039
-
1040
- if (stack.indexOf(value) !== -1) {
1041
- throw Error('Circular reference detected in ' + path.join('.'));
1042
- }
1043
-
1044
- stack.push(value);
1045
-
1046
- utils.forEach(value, function each(el, key) {
1047
- const result = !(utils.isUndefined(el) || el === null) && visitor.call(
1048
- formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers
1049
- );
1050
-
1051
- if (result === true) {
1052
- build(el, path ? path.concat(key) : [key]);
1053
- }
1054
- });
1055
-
1056
- stack.pop();
1057
- }
1058
-
1059
- if (!utils.isObject(obj)) {
1060
- throw new TypeError('data must be an object');
1061
- }
1062
-
1063
- build(obj);
1064
-
1065
- return formData;
1066
- }
1067
-
1068
- /**
1069
- * It encodes a string by replacing all characters that are not in the unreserved set with
1070
- * their percent-encoded equivalents
1071
- *
1072
- * @param {string} str - The string to encode.
1073
- *
1074
- * @returns {string} The encoded string.
1075
- */
1076
- function encode$1(str) {
1077
- const charMap = {
1078
- '!': '%21',
1079
- "'": '%27',
1080
- '(': '%28',
1081
- ')': '%29',
1082
- '~': '%7E',
1083
- '%20': '+',
1084
- '%00': '\x00'
1085
- };
1086
- return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
1087
- return charMap[match];
1088
- });
1089
- }
1090
-
1091
- /**
1092
- * It takes a params object and converts it to a FormData object
1093
- *
1094
- * @param {Object<string, any>} params - The parameters to be converted to a FormData object.
1095
- * @param {Object<string, any>} options - The options object passed to the Axios constructor.
1096
- *
1097
- * @returns {void}
1098
- */
1099
- function AxiosURLSearchParams(params, options) {
1100
- this._pairs = [];
1101
-
1102
- params && toFormData(params, this, options);
1103
- }
1104
-
1105
- const prototype = AxiosURLSearchParams.prototype;
1106
-
1107
- prototype.append = function append(name, value) {
1108
- this._pairs.push([name, value]);
1109
- };
1110
-
1111
- prototype.toString = function toString(encoder) {
1112
- const _encode = encoder ? function(value) {
1113
- return encoder.call(this, value, encode$1);
1114
- } : encode$1;
1115
-
1116
- return this._pairs.map(function each(pair) {
1117
- return _encode(pair[0]) + '=' + _encode(pair[1]);
1118
- }, '').join('&');
1119
- };
1120
-
1121
- /**
1122
- * It replaces all instances of the characters `:`, `$`, `,`, `+`, `[`, and `]` with their
1123
- * URI encoded counterparts
1124
- *
1125
- * @param {string} val The value to be encoded.
1126
- *
1127
- * @returns {string} The encoded value.
1128
- */
1129
- function encode(val) {
1130
- return encodeURIComponent(val).
1131
- replace(/%3A/gi, ':').
1132
- replace(/%24/g, '$').
1133
- replace(/%2C/gi, ',').
1134
- replace(/%20/g, '+').
1135
- replace(/%5B/gi, '[').
1136
- replace(/%5D/gi, ']');
1137
- }
1138
-
1139
- /**
1140
- * Build a URL by appending params to the end
1141
- *
1142
- * @param {string} url The base of the url (e.g., http://www.google.com)
1143
- * @param {object} [params] The params to be appended
1144
- * @param {?object} options
1145
- *
1146
- * @returns {string} The formatted url
1147
- */
1148
- function buildURL(url, params, options) {
1149
- /*eslint no-param-reassign:0*/
1150
- if (!params) {
1151
- return url;
1152
- }
1153
-
1154
- const _encode = options && options.encode || encode;
1155
-
1156
- const serializeFn = options && options.serialize;
1157
-
1158
- let serializedParams;
1159
-
1160
- if (serializeFn) {
1161
- serializedParams = serializeFn(params, options);
1162
- } else {
1163
- serializedParams = utils.isURLSearchParams(params) ?
1164
- params.toString() :
1165
- new AxiosURLSearchParams(params, options).toString(_encode);
1166
- }
1167
-
1168
- if (serializedParams) {
1169
- const hashmarkIndex = url.indexOf("#");
1170
-
1171
- if (hashmarkIndex !== -1) {
1172
- url = url.slice(0, hashmarkIndex);
1173
- }
1174
- url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
1175
- }
1176
-
1177
- return url;
1178
- }
1179
-
1180
- class InterceptorManager {
1181
- constructor() {
1182
- this.handlers = [];
1183
- }
1184
-
1185
- /**
1186
- * Add a new interceptor to the stack
1187
- *
1188
- * @param {Function} fulfilled The function to handle `then` for a `Promise`
1189
- * @param {Function} rejected The function to handle `reject` for a `Promise`
1190
- *
1191
- * @return {Number} An ID used to remove interceptor later
1192
- */
1193
- use(fulfilled, rejected, options) {
1194
- this.handlers.push({
1195
- fulfilled,
1196
- rejected,
1197
- synchronous: options ? options.synchronous : false,
1198
- runWhen: options ? options.runWhen : null
1199
- });
1200
- return this.handlers.length - 1;
1201
- }
1202
-
1203
- /**
1204
- * Remove an interceptor from the stack
1205
- *
1206
- * @param {Number} id The ID that was returned by `use`
1207
- *
1208
- * @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
1209
- */
1210
- eject(id) {
1211
- if (this.handlers[id]) {
1212
- this.handlers[id] = null;
1213
- }
1214
- }
1215
-
1216
- /**
1217
- * Clear all interceptors from the stack
1218
- *
1219
- * @returns {void}
1220
- */
1221
- clear() {
1222
- if (this.handlers) {
1223
- this.handlers = [];
1224
- }
1225
- }
1226
-
1227
- /**
1228
- * Iterate over all the registered interceptors
1229
- *
1230
- * This method is particularly useful for skipping over any
1231
- * interceptors that may have become `null` calling `eject`.
1232
- *
1233
- * @param {Function} fn The function to call for each interceptor
1234
- *
1235
- * @returns {void}
1236
- */
1237
- forEach(fn) {
1238
- utils.forEach(this.handlers, function forEachHandler(h) {
1239
- if (h !== null) {
1240
- fn(h);
1241
- }
1242
- });
1243
- }
1244
- }
1245
-
1246
- var InterceptorManager$1 = InterceptorManager;
1247
-
1248
- var transitionalDefaults = {
1249
- silentJSONParsing: true,
1250
- forcedJSONParsing: true,
1251
- clarifyTimeoutError: false
1252
- };
1253
-
1254
- var URLSearchParams = url__default["default"].URLSearchParams;
1255
-
1256
- var platform = {
1257
- isNode: true,
1258
- classes: {
1259
- URLSearchParams,
1260
- FormData: FormData__default["default"],
1261
- Blob: typeof Blob !== 'undefined' && Blob || null
1262
- },
1263
- protocols: [ 'http', 'https', 'file', 'data' ]
1264
- };
1265
-
1266
- function toURLEncodedForm(data, options) {
1267
- return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
1268
- visitor: function(value, key, path, helpers) {
1269
- if (utils.isBuffer(value)) {
1270
- this.append(key, value.toString('base64'));
1271
- return false;
1272
- }
1273
-
1274
- return helpers.defaultVisitor.apply(this, arguments);
1275
- }
1276
- }, options));
1277
- }
1278
-
1279
- /**
1280
- * It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
1281
- *
1282
- * @param {string} name - The name of the property to get.
1283
- *
1284
- * @returns An array of strings.
1285
- */
1286
- function parsePropPath(name) {
1287
- // foo[x][y][z]
1288
- // foo.x.y.z
1289
- // foo-x-y-z
1290
- // foo x y z
1291
- return utils.matchAll(/\w+|\[(\w*)]/g, name).map(match => {
1292
- return match[0] === '[]' ? '' : match[1] || match[0];
1293
- });
1294
- }
1295
-
1296
- /**
1297
- * Convert an array to an object.
1298
- *
1299
- * @param {Array<any>} arr - The array to convert to an object.
1300
- *
1301
- * @returns An object with the same keys and values as the array.
1302
- */
1303
- function arrayToObject(arr) {
1304
- const obj = {};
1305
- const keys = Object.keys(arr);
1306
- let i;
1307
- const len = keys.length;
1308
- let key;
1309
- for (i = 0; i < len; i++) {
1310
- key = keys[i];
1311
- obj[key] = arr[key];
1312
- }
1313
- return obj;
1314
- }
1315
-
1316
- /**
1317
- * It takes a FormData object and returns a JavaScript object
1318
- *
1319
- * @param {string} formData The FormData object to convert to JSON.
1320
- *
1321
- * @returns {Object<string, any> | null} The converted object.
1322
- */
1323
- function formDataToJSON(formData) {
1324
- function buildPath(path, value, target, index) {
1325
- let name = path[index++];
1326
- const isNumericKey = Number.isFinite(+name);
1327
- const isLast = index >= path.length;
1328
- name = !name && utils.isArray(target) ? target.length : name;
1329
-
1330
- if (isLast) {
1331
- if (utils.hasOwnProp(target, name)) {
1332
- target[name] = [target[name], value];
1333
- } else {
1334
- target[name] = value;
1335
- }
1336
-
1337
- return !isNumericKey;
1338
- }
1339
-
1340
- if (!target[name] || !utils.isObject(target[name])) {
1341
- target[name] = [];
1342
- }
1343
-
1344
- const result = buildPath(path, value, target[name], index);
1345
-
1346
- if (result && utils.isArray(target[name])) {
1347
- target[name] = arrayToObject(target[name]);
1348
- }
1349
-
1350
- return !isNumericKey;
1351
- }
1352
-
1353
- if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
1354
- const obj = {};
1355
-
1356
- utils.forEachEntry(formData, (name, value) => {
1357
- buildPath(parsePropPath(name), value, obj, 0);
1358
- });
1359
-
1360
- return obj;
1361
- }
1362
-
1363
- return null;
1364
- }
1365
-
1366
- const DEFAULT_CONTENT_TYPE = {
1367
- 'Content-Type': undefined
1368
- };
1369
-
1370
- /**
1371
- * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1372
- * of the input
1373
- *
1374
- * @param {any} rawValue - The value to be stringified.
1375
- * @param {Function} parser - A function that parses a string into a JavaScript object.
1376
- * @param {Function} encoder - A function that takes a value and returns a string.
1377
- *
1378
- * @returns {string} A stringified version of the rawValue.
1379
- */
1380
- function stringifySafely(rawValue, parser, encoder) {
1381
- if (utils.isString(rawValue)) {
1382
- try {
1383
- (parser || JSON.parse)(rawValue);
1384
- return utils.trim(rawValue);
1385
- } catch (e) {
1386
- if (e.name !== 'SyntaxError') {
1387
- throw e;
1388
- }
1389
- }
1390
- }
1391
-
1392
- return (encoder || JSON.stringify)(rawValue);
1393
- }
1394
-
1395
- const defaults = {
1396
-
1397
- transitional: transitionalDefaults,
1398
-
1399
- adapter: ['xhr', 'http'],
1400
-
1401
- transformRequest: [function transformRequest(data, headers) {
1402
- const contentType = headers.getContentType() || '';
1403
- const hasJSONContentType = contentType.indexOf('application/json') > -1;
1404
- const isObjectPayload = utils.isObject(data);
1405
-
1406
- if (isObjectPayload && utils.isHTMLForm(data)) {
1407
- data = new FormData(data);
1408
- }
1409
-
1410
- const isFormData = utils.isFormData(data);
1411
-
1412
- if (isFormData) {
1413
- if (!hasJSONContentType) {
1414
- return data;
1415
- }
1416
- return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
1417
- }
1418
-
1419
- if (utils.isArrayBuffer(data) ||
1420
- utils.isBuffer(data) ||
1421
- utils.isStream(data) ||
1422
- utils.isFile(data) ||
1423
- utils.isBlob(data)
1424
- ) {
1425
- return data;
1426
- }
1427
- if (utils.isArrayBufferView(data)) {
1428
- return data.buffer;
1429
- }
1430
- if (utils.isURLSearchParams(data)) {
1431
- headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
1432
- return data.toString();
1433
- }
1434
-
1435
- let isFileList;
1436
-
1437
- if (isObjectPayload) {
1438
- if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
1439
- return toURLEncodedForm(data, this.formSerializer).toString();
1440
- }
1441
-
1442
- if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
1443
- const _FormData = this.env && this.env.FormData;
1444
-
1445
- return toFormData(
1446
- isFileList ? {'files[]': data} : data,
1447
- _FormData && new _FormData(),
1448
- this.formSerializer
1449
- );
1450
- }
1451
- }
1452
-
1453
- if (isObjectPayload || hasJSONContentType ) {
1454
- headers.setContentType('application/json', false);
1455
- return stringifySafely(data);
1456
- }
1457
-
1458
- return data;
1459
- }],
1460
-
1461
- transformResponse: [function transformResponse(data) {
1462
- const transitional = this.transitional || defaults.transitional;
1463
- const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
1464
- const JSONRequested = this.responseType === 'json';
1465
-
1466
- if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
1467
- const silentJSONParsing = transitional && transitional.silentJSONParsing;
1468
- const strictJSONParsing = !silentJSONParsing && JSONRequested;
1469
-
1470
- try {
1471
- return JSON.parse(data);
1472
- } catch (e) {
1473
- if (strictJSONParsing) {
1474
- if (e.name === 'SyntaxError') {
1475
- throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
1476
- }
1477
- throw e;
1478
- }
1479
- }
1480
- }
1481
-
1482
- return data;
1483
- }],
1484
-
1485
- /**
1486
- * A timeout in milliseconds to abort a request. If set to 0 (default) a
1487
- * timeout is not created.
1488
- */
1489
- timeout: 0,
1490
-
1491
- xsrfCookieName: 'XSRF-TOKEN',
1492
- xsrfHeaderName: 'X-XSRF-TOKEN',
1493
-
1494
- maxContentLength: -1,
1495
- maxBodyLength: -1,
1496
-
1497
- env: {
1498
- FormData: platform.classes.FormData,
1499
- Blob: platform.classes.Blob
1500
- },
1501
-
1502
- validateStatus: function validateStatus(status) {
1503
- return status >= 200 && status < 300;
1504
- },
1505
-
1506
- headers: {
1507
- common: {
1508
- 'Accept': 'application/json, text/plain, */*'
1509
- }
1510
- }
1511
- };
1512
-
1513
- utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
1514
- defaults.headers[method] = {};
1515
- });
1516
-
1517
- utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
1518
- defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
1519
- });
1520
-
1521
- var defaults$1 = defaults;
1522
-
1523
- // RawAxiosHeaders whose duplicates are ignored by node
1524
- // c.f. https://nodejs.org/api/http.html#http_message_headers
1525
- const ignoreDuplicateOf = utils.toObjectSet([
1526
- 'age', 'authorization', 'content-length', 'content-type', 'etag',
1527
- 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
1528
- 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
1529
- 'referer', 'retry-after', 'user-agent'
1530
- ]);
1531
-
1532
- /**
1533
- * Parse headers into an object
1534
- *
1535
- * ```
1536
- * Date: Wed, 27 Aug 2014 08:58:49 GMT
1537
- * Content-Type: application/json
1538
- * Connection: keep-alive
1539
- * Transfer-Encoding: chunked
1540
- * ```
1541
- *
1542
- * @param {String} rawHeaders Headers needing to be parsed
1543
- *
1544
- * @returns {Object} Headers parsed into an object
1545
- */
1546
- var parseHeaders = rawHeaders => {
1547
- const parsed = {};
1548
- let key;
1549
- let val;
1550
- let i;
1551
-
1552
- rawHeaders && rawHeaders.split('\n').forEach(function parser(line) {
1553
- i = line.indexOf(':');
1554
- key = line.substring(0, i).trim().toLowerCase();
1555
- val = line.substring(i + 1).trim();
1556
-
1557
- if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
1558
- return;
1559
- }
1560
-
1561
- if (key === 'set-cookie') {
1562
- if (parsed[key]) {
1563
- parsed[key].push(val);
1564
- } else {
1565
- parsed[key] = [val];
1566
- }
1567
- } else {
1568
- parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
1569
- }
1570
- });
1571
-
1572
- return parsed;
1573
- };
1574
-
1575
- const $internals = Symbol('internals');
1576
-
1577
- function normalizeHeader(header) {
1578
- return header && String(header).trim().toLowerCase();
1579
- }
1580
-
1581
- function normalizeValue(value) {
1582
- if (value === false || value == null) {
1583
- return value;
1584
- }
1585
-
1586
- return utils.isArray(value) ? value.map(normalizeValue) : String(value);
1587
- }
1588
-
1589
- function parseTokens(str) {
1590
- const tokens = Object.create(null);
1591
- const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
1592
- let match;
1593
-
1594
- while ((match = tokensRE.exec(str))) {
1595
- tokens[match[1]] = match[2];
1596
- }
1597
-
1598
- return tokens;
1599
- }
1600
-
1601
- function isValidHeaderName(str) {
1602
- return /^[-_a-zA-Z]+$/.test(str.trim());
1603
- }
1604
-
1605
- function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
1606
- if (utils.isFunction(filter)) {
1607
- return filter.call(this, value, header);
1608
- }
1609
-
1610
- if (isHeaderNameFilter) {
1611
- value = header;
1612
- }
1613
-
1614
- if (!utils.isString(value)) return;
1615
-
1616
- if (utils.isString(filter)) {
1617
- return value.indexOf(filter) !== -1;
1618
- }
1619
-
1620
- if (utils.isRegExp(filter)) {
1621
- return filter.test(value);
1622
- }
1623
- }
1624
-
1625
- function formatHeader(header) {
1626
- return header.trim()
1627
- .toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str) => {
1628
- return char.toUpperCase() + str;
1629
- });
1630
- }
1631
-
1632
- function buildAccessors(obj, header) {
1633
- const accessorName = utils.toCamelCase(' ' + header);
1634
-
1635
- ['get', 'set', 'has'].forEach(methodName => {
1636
- Object.defineProperty(obj, methodName + accessorName, {
1637
- value: function(arg1, arg2, arg3) {
1638
- return this[methodName].call(this, header, arg1, arg2, arg3);
1639
- },
1640
- configurable: true
1641
- });
1642
- });
1643
- }
1644
-
1645
- class AxiosHeaders {
1646
- constructor(headers) {
1647
- headers && this.set(headers);
1648
- }
1649
-
1650
- set(header, valueOrRewrite, rewrite) {
1651
- const self = this;
1652
-
1653
- function setHeader(_value, _header, _rewrite) {
1654
- const lHeader = normalizeHeader(_header);
1655
-
1656
- if (!lHeader) {
1657
- throw new Error('header name must be a non-empty string');
1658
- }
1659
-
1660
- const key = utils.findKey(self, lHeader);
1661
-
1662
- if(!key || self[key] === undefined || _rewrite === true || (_rewrite === undefined && self[key] !== false)) {
1663
- self[key || _header] = normalizeValue(_value);
1664
- }
1665
- }
1666
-
1667
- const setHeaders = (headers, _rewrite) =>
1668
- utils.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
1669
-
1670
- if (utils.isPlainObject(header) || header instanceof this.constructor) {
1671
- setHeaders(header, valueOrRewrite);
1672
- } else if(utils.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
1673
- setHeaders(parseHeaders(header), valueOrRewrite);
1674
- } else {
1675
- header != null && setHeader(valueOrRewrite, header, rewrite);
1676
- }
1677
-
1678
- return this;
1679
- }
1680
-
1681
- get(header, parser) {
1682
- header = normalizeHeader(header);
1683
-
1684
- if (header) {
1685
- const key = utils.findKey(this, header);
1686
-
1687
- if (key) {
1688
- const value = this[key];
1689
-
1690
- if (!parser) {
1691
- return value;
1692
- }
1693
-
1694
- if (parser === true) {
1695
- return parseTokens(value);
1696
- }
1697
-
1698
- if (utils.isFunction(parser)) {
1699
- return parser.call(this, value, key);
1700
- }
1701
-
1702
- if (utils.isRegExp(parser)) {
1703
- return parser.exec(value);
1704
- }
1705
-
1706
- throw new TypeError('parser must be boolean|regexp|function');
1707
- }
1708
- }
1709
- }
1710
-
1711
- has(header, matcher) {
1712
- header = normalizeHeader(header);
1713
-
1714
- if (header) {
1715
- const key = utils.findKey(this, header);
1716
-
1717
- return !!(key && this[key] !== undefined && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
1718
- }
1719
-
1720
- return false;
1721
- }
1722
-
1723
- delete(header, matcher) {
1724
- const self = this;
1725
- let deleted = false;
1726
-
1727
- function deleteHeader(_header) {
1728
- _header = normalizeHeader(_header);
1729
-
1730
- if (_header) {
1731
- const key = utils.findKey(self, _header);
1732
-
1733
- if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
1734
- delete self[key];
1735
-
1736
- deleted = true;
1737
- }
1738
- }
1739
- }
1740
-
1741
- if (utils.isArray(header)) {
1742
- header.forEach(deleteHeader);
1743
- } else {
1744
- deleteHeader(header);
1745
- }
1746
-
1747
- return deleted;
1748
- }
1749
-
1750
- clear(matcher) {
1751
- const keys = Object.keys(this);
1752
- let i = keys.length;
1753
- let deleted = false;
1754
-
1755
- while (i--) {
1756
- const key = keys[i];
1757
- if(!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
1758
- delete this[key];
1759
- deleted = true;
1760
- }
1761
- }
1762
-
1763
- return deleted;
1764
- }
1765
-
1766
- normalize(format) {
1767
- const self = this;
1768
- const headers = {};
1769
-
1770
- utils.forEach(this, (value, header) => {
1771
- const key = utils.findKey(headers, header);
1772
-
1773
- if (key) {
1774
- self[key] = normalizeValue(value);
1775
- delete self[header];
1776
- return;
1777
- }
1778
-
1779
- const normalized = format ? formatHeader(header) : String(header).trim();
1780
-
1781
- if (normalized !== header) {
1782
- delete self[header];
1783
- }
1784
-
1785
- self[normalized] = normalizeValue(value);
1786
-
1787
- headers[normalized] = true;
1788
- });
1789
-
1790
- return this;
1791
- }
1792
-
1793
- concat(...targets) {
1794
- return this.constructor.concat(this, ...targets);
1795
- }
1796
-
1797
- toJSON(asStrings) {
1798
- const obj = Object.create(null);
1799
-
1800
- utils.forEach(this, (value, header) => {
1801
- value != null && value !== false && (obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value);
1802
- });
1803
-
1804
- return obj;
1805
- }
1806
-
1807
- [Symbol.iterator]() {
1808
- return Object.entries(this.toJSON())[Symbol.iterator]();
1809
- }
1810
-
1811
- toString() {
1812
- return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
1813
- }
1814
-
1815
- get [Symbol.toStringTag]() {
1816
- return 'AxiosHeaders';
1817
- }
1818
-
1819
- static from(thing) {
1820
- return thing instanceof this ? thing : new this(thing);
1821
- }
1822
-
1823
- static concat(first, ...targets) {
1824
- const computed = new this(first);
1825
-
1826
- targets.forEach((target) => computed.set(target));
1827
-
1828
- return computed;
1829
- }
1830
-
1831
- static accessor(header) {
1832
- const internals = this[$internals] = (this[$internals] = {
1833
- accessors: {}
1834
- });
1835
-
1836
- const accessors = internals.accessors;
1837
- const prototype = this.prototype;
1838
-
1839
- function defineAccessor(_header) {
1840
- const lHeader = normalizeHeader(_header);
1841
-
1842
- if (!accessors[lHeader]) {
1843
- buildAccessors(prototype, _header);
1844
- accessors[lHeader] = true;
1845
- }
1846
- }
1847
-
1848
- utils.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
1849
-
1850
- return this;
1851
- }
1852
- }
1853
-
1854
- AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
1855
-
1856
- utils.freezeMethods(AxiosHeaders.prototype);
1857
- utils.freezeMethods(AxiosHeaders);
1858
-
1859
- var AxiosHeaders$1 = AxiosHeaders;
1860
-
1861
- /**
1862
- * Transform the data for a request or a response
1863
- *
1864
- * @param {Array|Function} fns A single function or Array of functions
1865
- * @param {?Object} response The response object
1866
- *
1867
- * @returns {*} The resulting transformed data
1868
- */
1869
- function transformData(fns, response) {
1870
- const config = this || defaults$1;
1871
- const context = response || config;
1872
- const headers = AxiosHeaders$1.from(context.headers);
1873
- let data = context.data;
1874
-
1875
- utils.forEach(fns, function transform(fn) {
1876
- data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
1877
- });
1878
-
1879
- headers.normalize();
1880
-
1881
- return data;
1882
- }
1883
-
1884
- function isCancel(value) {
1885
- return !!(value && value.__CANCEL__);
1886
- }
1887
-
1888
- /**
1889
- * A `CanceledError` is an object that is thrown when an operation is canceled.
1890
- *
1891
- * @param {string=} message The message.
1892
- * @param {Object=} config The config.
1893
- * @param {Object=} request The request.
1894
- *
1895
- * @returns {CanceledError} The created error.
1896
- */
1897
- function CanceledError(message, config, request) {
1898
- // eslint-disable-next-line no-eq-null,eqeqeq
1899
- AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
1900
- this.name = 'CanceledError';
1901
- }
1902
-
1903
- utils.inherits(CanceledError, AxiosError, {
1904
- __CANCEL__: true
1905
- });
1906
-
1907
- /**
1908
- * Resolve or reject a Promise based on response status.
1909
- *
1910
- * @param {Function} resolve A function that resolves the promise.
1911
- * @param {Function} reject A function that rejects the promise.
1912
- * @param {object} response The response.
1913
- *
1914
- * @returns {object} The response.
1915
- */
1916
- function settle(resolve, reject, response) {
1917
- const validateStatus = response.config.validateStatus;
1918
- if (!response.status || !validateStatus || validateStatus(response.status)) {
1919
- resolve(response);
1920
- } else {
1921
- reject(new AxiosError(
1922
- 'Request failed with status code ' + response.status,
1923
- [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
1924
- response.config,
1925
- response.request,
1926
- response
1927
- ));
1928
- }
1929
- }
1930
-
1931
- /**
1932
- * Determines whether the specified URL is absolute
1933
- *
1934
- * @param {string} url The URL to test
1935
- *
1936
- * @returns {boolean} True if the specified URL is absolute, otherwise false
1937
- */
1938
- function isAbsoluteURL(url) {
1939
- // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
1940
- // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
1941
- // by any combination of letters, digits, plus, period, or hyphen.
1942
- return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
1943
- }
1944
-
1945
- /**
1946
- * Creates a new URL by combining the specified URLs
1947
- *
1948
- * @param {string} baseURL The base URL
1949
- * @param {string} relativeURL The relative URL
1950
- *
1951
- * @returns {string} The combined URL
1952
- */
1953
- function combineURLs(baseURL, relativeURL) {
1954
- return relativeURL
1955
- ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
1956
- : baseURL;
1957
- }
1958
-
1959
- /**
1960
- * Creates a new URL by combining the baseURL with the requestedURL,
1961
- * only when the requestedURL is not already an absolute URL.
1962
- * If the requestURL is absolute, this function returns the requestedURL untouched.
1963
- *
1964
- * @param {string} baseURL The base URL
1965
- * @param {string} requestedURL Absolute or relative URL to combine
1966
- *
1967
- * @returns {string} The combined full path
1968
- */
1969
- function buildFullPath(baseURL, requestedURL) {
1970
- if (baseURL && !isAbsoluteURL(requestedURL)) {
1971
- return combineURLs(baseURL, requestedURL);
1972
- }
1973
- return requestedURL;
1974
- }
1975
-
1976
- const VERSION = "1.3.4";
1977
-
1978
- function parseProtocol(url) {
1979
- const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1980
- return match && match[1] || '';
1981
- }
1982
-
1983
- const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;
1984
-
1985
- /**
1986
- * Parse data uri to a Buffer or Blob
1987
- *
1988
- * @param {String} uri
1989
- * @param {?Boolean} asBlob
1990
- * @param {?Object} options
1991
- * @param {?Function} options.Blob
1992
- *
1993
- * @returns {Buffer|Blob}
1994
- */
1995
- function fromDataURI(uri, asBlob, options) {
1996
- const _Blob = options && options.Blob || platform.classes.Blob;
1997
- const protocol = parseProtocol(uri);
1998
-
1999
- if (asBlob === undefined && _Blob) {
2000
- asBlob = true;
2001
- }
2002
-
2003
- if (protocol === 'data') {
2004
- uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
2005
-
2006
- const match = DATA_URL_PATTERN.exec(uri);
2007
-
2008
- if (!match) {
2009
- throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
2010
- }
2011
-
2012
- const mime = match[1];
2013
- const isBase64 = match[2];
2014
- const body = match[3];
2015
- const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8');
2016
-
2017
- if (asBlob) {
2018
- if (!_Blob) {
2019
- throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
2020
- }
2021
-
2022
- return new _Blob([buffer], {type: mime});
2023
- }
2024
-
2025
- return buffer;
2026
- }
2027
-
2028
- throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
2029
- }
2030
-
2031
- /**
2032
- * Throttle decorator
2033
- * @param {Function} fn
2034
- * @param {Number} freq
2035
- * @return {Function}
2036
- */
2037
- function throttle(fn, freq) {
2038
- let timestamp = 0;
2039
- const threshold = 1000 / freq;
2040
- let timer = null;
2041
- return function throttled(force, args) {
2042
- const now = Date.now();
2043
- if (force || now - timestamp > threshold) {
2044
- if (timer) {
2045
- clearTimeout(timer);
2046
- timer = null;
2047
- }
2048
- timestamp = now;
2049
- return fn.apply(null, args);
2050
- }
2051
- if (!timer) {
2052
- timer = setTimeout(() => {
2053
- timer = null;
2054
- timestamp = Date.now();
2055
- return fn.apply(null, args);
2056
- }, threshold - (now - timestamp));
2057
- }
2058
- };
2059
- }
2060
-
2061
- /**
2062
- * Calculate data maxRate
2063
- * @param {Number} [samplesCount= 10]
2064
- * @param {Number} [min= 1000]
2065
- * @returns {Function}
2066
- */
2067
- function speedometer(samplesCount, min) {
2068
- samplesCount = samplesCount || 10;
2069
- const bytes = new Array(samplesCount);
2070
- const timestamps = new Array(samplesCount);
2071
- let head = 0;
2072
- let tail = 0;
2073
- let firstSampleTS;
2074
-
2075
- min = min !== undefined ? min : 1000;
2076
-
2077
- return function push(chunkLength) {
2078
- const now = Date.now();
2079
-
2080
- const startedAt = timestamps[tail];
2081
-
2082
- if (!firstSampleTS) {
2083
- firstSampleTS = now;
2084
- }
2085
-
2086
- bytes[head] = chunkLength;
2087
- timestamps[head] = now;
2088
-
2089
- let i = tail;
2090
- let bytesCount = 0;
2091
-
2092
- while (i !== head) {
2093
- bytesCount += bytes[i++];
2094
- i = i % samplesCount;
2095
- }
2096
-
2097
- head = (head + 1) % samplesCount;
2098
-
2099
- if (head === tail) {
2100
- tail = (tail + 1) % samplesCount;
2101
- }
2102
-
2103
- if (now - firstSampleTS < min) {
2104
- return;
2105
- }
2106
-
2107
- const passed = startedAt && now - startedAt;
2108
-
2109
- return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
2110
- };
2111
- }
2112
-
2113
- const kInternals = Symbol('internals');
2114
-
2115
- class AxiosTransformStream extends stream__default["default"].Transform{
2116
- constructor(options) {
2117
- options = utils.toFlatObject(options, {
2118
- maxRate: 0,
2119
- chunkSize: 64 * 1024,
2120
- minChunkSize: 100,
2121
- timeWindow: 500,
2122
- ticksRate: 2,
2123
- samplesCount: 15
2124
- }, null, (prop, source) => {
2125
- return !utils.isUndefined(source[prop]);
2126
- });
2127
-
2128
- super({
2129
- readableHighWaterMark: options.chunkSize
2130
- });
2131
-
2132
- const self = this;
2133
-
2134
- const internals = this[kInternals] = {
2135
- length: options.length,
2136
- timeWindow: options.timeWindow,
2137
- ticksRate: options.ticksRate,
2138
- chunkSize: options.chunkSize,
2139
- maxRate: options.maxRate,
2140
- minChunkSize: options.minChunkSize,
2141
- bytesSeen: 0,
2142
- isCaptured: false,
2143
- notifiedBytesLoaded: 0,
2144
- ts: Date.now(),
2145
- bytes: 0,
2146
- onReadCallback: null
2147
- };
2148
-
2149
- const _speedometer = speedometer(internals.ticksRate * options.samplesCount, internals.timeWindow);
2150
-
2151
- this.on('newListener', event => {
2152
- if (event === 'progress') {
2153
- if (!internals.isCaptured) {
2154
- internals.isCaptured = true;
2155
- }
2156
- }
2157
- });
2158
-
2159
- let bytesNotified = 0;
2160
-
2161
- internals.updateProgress = throttle(function throttledHandler() {
2162
- const totalBytes = internals.length;
2163
- const bytesTransferred = internals.bytesSeen;
2164
- const progressBytes = bytesTransferred - bytesNotified;
2165
- if (!progressBytes || self.destroyed) return;
2166
-
2167
- const rate = _speedometer(progressBytes);
2168
-
2169
- bytesNotified = bytesTransferred;
2170
-
2171
- process.nextTick(() => {
2172
- self.emit('progress', {
2173
- 'loaded': bytesTransferred,
2174
- 'total': totalBytes,
2175
- 'progress': totalBytes ? (bytesTransferred / totalBytes) : undefined,
2176
- 'bytes': progressBytes,
2177
- 'rate': rate ? rate : undefined,
2178
- 'estimated': rate && totalBytes && bytesTransferred <= totalBytes ?
2179
- (totalBytes - bytesTransferred) / rate : undefined
2180
- });
2181
- });
2182
- }, internals.ticksRate);
2183
-
2184
- const onFinish = () => {
2185
- internals.updateProgress(true);
2186
- };
2187
-
2188
- this.once('end', onFinish);
2189
- this.once('error', onFinish);
2190
- }
2191
-
2192
- _read(size) {
2193
- const internals = this[kInternals];
2194
-
2195
- if (internals.onReadCallback) {
2196
- internals.onReadCallback();
2197
- }
2198
-
2199
- return super._read(size);
2200
- }
2201
-
2202
- _transform(chunk, encoding, callback) {
2203
- const self = this;
2204
- const internals = this[kInternals];
2205
- const maxRate = internals.maxRate;
2206
-
2207
- const readableHighWaterMark = this.readableHighWaterMark;
2208
-
2209
- const timeWindow = internals.timeWindow;
2210
-
2211
- const divider = 1000 / timeWindow;
2212
- const bytesThreshold = (maxRate / divider);
2213
- const minChunkSize = internals.minChunkSize !== false ? Math.max(internals.minChunkSize, bytesThreshold * 0.01) : 0;
2214
-
2215
- function pushChunk(_chunk, _callback) {
2216
- const bytes = Buffer.byteLength(_chunk);
2217
- internals.bytesSeen += bytes;
2218
- internals.bytes += bytes;
2219
-
2220
- if (internals.isCaptured) {
2221
- internals.updateProgress();
2222
- }
2223
-
2224
- if (self.push(_chunk)) {
2225
- process.nextTick(_callback);
2226
- } else {
2227
- internals.onReadCallback = () => {
2228
- internals.onReadCallback = null;
2229
- process.nextTick(_callback);
2230
- };
2231
- }
2232
- }
2233
-
2234
- const transformChunk = (_chunk, _callback) => {
2235
- const chunkSize = Buffer.byteLength(_chunk);
2236
- let chunkRemainder = null;
2237
- let maxChunkSize = readableHighWaterMark;
2238
- let bytesLeft;
2239
- let passed = 0;
2240
-
2241
- if (maxRate) {
2242
- const now = Date.now();
2243
-
2244
- if (!internals.ts || (passed = (now - internals.ts)) >= timeWindow) {
2245
- internals.ts = now;
2246
- bytesLeft = bytesThreshold - internals.bytes;
2247
- internals.bytes = bytesLeft < 0 ? -bytesLeft : 0;
2248
- passed = 0;
2249
- }
2250
-
2251
- bytesLeft = bytesThreshold - internals.bytes;
2252
- }
2253
-
2254
- if (maxRate) {
2255
- if (bytesLeft <= 0) {
2256
- // next time window
2257
- return setTimeout(() => {
2258
- _callback(null, _chunk);
2259
- }, timeWindow - passed);
2260
- }
2261
-
2262
- if (bytesLeft < maxChunkSize) {
2263
- maxChunkSize = bytesLeft;
2264
- }
2265
- }
2266
-
2267
- if (maxChunkSize && chunkSize > maxChunkSize && (chunkSize - maxChunkSize) > minChunkSize) {
2268
- chunkRemainder = _chunk.subarray(maxChunkSize);
2269
- _chunk = _chunk.subarray(0, maxChunkSize);
2270
- }
2271
-
2272
- pushChunk(_chunk, chunkRemainder ? () => {
2273
- process.nextTick(_callback, null, chunkRemainder);
2274
- } : _callback);
2275
- };
2276
-
2277
- transformChunk(chunk, function transformNextChunk(err, _chunk) {
2278
- if (err) {
2279
- return callback(err);
2280
- }
2281
-
2282
- if (_chunk) {
2283
- transformChunk(_chunk, transformNextChunk);
2284
- } else {
2285
- callback(null);
2286
- }
2287
- });
2288
- }
2289
-
2290
- setLength(length) {
2291
- this[kInternals].length = +length;
2292
- return this;
2293
- }
2294
- }
2295
-
2296
- var AxiosTransformStream$1 = AxiosTransformStream;
2297
-
2298
- const {asyncIterator} = Symbol;
2299
-
2300
- const readBlob = async function* (blob) {
2301
- if (blob.stream) {
2302
- yield* blob.stream();
2303
- } else if (blob.arrayBuffer) {
2304
- yield await blob.arrayBuffer();
2305
- } else if (blob[asyncIterator]) {
2306
- yield* blob[asyncIterator]();
2307
- } else {
2308
- yield blob;
2309
- }
2310
- };
2311
-
2312
- var readBlob$1 = readBlob;
2313
-
2314
- const BOUNDARY_ALPHABET = utils.ALPHABET.ALPHA_DIGIT + '-_';
2315
-
2316
- const textEncoder = new util.TextEncoder();
2317
-
2318
- const CRLF = '\r\n';
2319
- const CRLF_BYTES = textEncoder.encode(CRLF);
2320
- const CRLF_BYTES_COUNT = 2;
2321
-
2322
- class FormDataPart {
2323
- constructor(name, value) {
2324
- const {escapeName} = this.constructor;
2325
- const isStringValue = utils.isString(value);
2326
-
2327
- let headers = `Content-Disposition: form-data; name="${escapeName(name)}"${
2328
- !isStringValue && value.name ? `; filename="${escapeName(value.name)}"` : ''
2329
- }${CRLF}`;
2330
-
2331
- if (isStringValue) {
2332
- value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF));
2333
- } else {
2334
- headers += `Content-Type: ${value.type || "application/octet-stream"}${CRLF}`;
2335
- }
2336
-
2337
- this.headers = textEncoder.encode(headers + CRLF);
2338
-
2339
- this.contentLength = isStringValue ? value.byteLength : value.size;
2340
-
2341
- this.size = this.headers.byteLength + this.contentLength + CRLF_BYTES_COUNT;
2342
-
2343
- this.name = name;
2344
- this.value = value;
2345
- }
2346
-
2347
- async *encode(){
2348
- yield this.headers;
2349
-
2350
- const {value} = this;
2351
-
2352
- if(utils.isTypedArray(value)) {
2353
- yield value;
2354
- } else {
2355
- yield* readBlob$1(value);
2356
- }
2357
-
2358
- yield CRLF_BYTES;
2359
- }
2360
-
2361
- static escapeName(name) {
2362
- return String(name).replace(/[\r\n"]/g, (match) => ({
2363
- '\r' : '%0D',
2364
- '\n' : '%0A',
2365
- '"' : '%22',
2366
- }[match]));
2367
- }
2368
- }
2369
-
2370
- const formDataToStream = (form, headersHandler, options) => {
2371
- const {
2372
- tag = 'form-data-boundary',
2373
- size = 25,
2374
- boundary = tag + '-' + utils.generateString(size, BOUNDARY_ALPHABET)
2375
- } = options || {};
2376
-
2377
- if(!utils.isFormData(form)) {
2378
- throw TypeError('FormData instance required');
2379
- }
2380
-
2381
- if (boundary.length < 1 || boundary.length > 70) {
2382
- throw Error('boundary must be 10-70 characters long')
2383
- }
2384
-
2385
- const boundaryBytes = textEncoder.encode('--' + boundary + CRLF);
2386
- const footerBytes = textEncoder.encode('--' + boundary + '--' + CRLF + CRLF);
2387
- let contentLength = footerBytes.byteLength;
2388
-
2389
- const parts = Array.from(form.entries()).map(([name, value]) => {
2390
- const part = new FormDataPart(name, value);
2391
- contentLength += part.size;
2392
- return part;
2393
- });
2394
-
2395
- contentLength += boundaryBytes.byteLength * parts.length;
2396
-
2397
- contentLength = utils.toFiniteNumber(contentLength);
2398
-
2399
- const computedHeaders = {
2400
- 'Content-Type': `multipart/form-data; boundary=${boundary}`
2401
- };
2402
-
2403
- if (Number.isFinite(contentLength)) {
2404
- computedHeaders['Content-Length'] = contentLength;
2405
- }
2406
-
2407
- headersHandler && headersHandler(computedHeaders);
2408
-
2409
- return stream.Readable.from((async function *() {
2410
- for(const part of parts) {
2411
- yield boundaryBytes;
2412
- yield* part.encode();
2413
- }
2414
-
2415
- yield footerBytes;
2416
- })());
2417
- };
2418
-
2419
- var formDataToStream$1 = formDataToStream;
2420
-
2421
- class ZlibHeaderTransformStream extends stream__default["default"].Transform {
2422
- __transform(chunk, encoding, callback) {
2423
- this.push(chunk);
2424
- callback();
2425
- }
2426
-
2427
- _transform(chunk, encoding, callback) {
2428
- if (chunk.length !== 0) {
2429
- this._transform = this.__transform;
2430
-
2431
- // Add Default Compression headers if no zlib headers are present
2432
- if (chunk[0] !== 120) { // Hex: 78
2433
- const header = Buffer.alloc(2);
2434
- header[0] = 120; // Hex: 78
2435
- header[1] = 156; // Hex: 9C
2436
- this.push(header, encoding);
2437
- }
2438
- }
2439
-
2440
- this.__transform(chunk, encoding, callback);
2441
- }
2442
- }
2443
-
2444
- var ZlibHeaderTransformStream$1 = ZlibHeaderTransformStream;
2445
-
2446
- const zlibOptions = {
2447
- flush: zlib__default["default"].constants.Z_SYNC_FLUSH,
2448
- finishFlush: zlib__default["default"].constants.Z_SYNC_FLUSH
2449
- };
2450
-
2451
- const brotliOptions = {
2452
- flush: zlib__default["default"].constants.BROTLI_OPERATION_FLUSH,
2453
- finishFlush: zlib__default["default"].constants.BROTLI_OPERATION_FLUSH
2454
- };
2455
-
2456
- const isBrotliSupported = utils.isFunction(zlib__default["default"].createBrotliDecompress);
2457
-
2458
- const {http: httpFollow, https: httpsFollow} = followRedirects__default["default"];
2459
-
2460
- const isHttps = /https:?/;
2461
-
2462
- const supportedProtocols = platform.protocols.map(protocol => {
2463
- return protocol + ':';
2464
- });
2465
-
2466
- /**
2467
- * If the proxy or config beforeRedirects functions are defined, call them with the options
2468
- * object.
2469
- *
2470
- * @param {Object<string, any>} options - The options object that was passed to the request.
2471
- *
2472
- * @returns {Object<string, any>}
2473
- */
2474
- function dispatchBeforeRedirect(options) {
2475
- if (options.beforeRedirects.proxy) {
2476
- options.beforeRedirects.proxy(options);
2477
- }
2478
- if (options.beforeRedirects.config) {
2479
- options.beforeRedirects.config(options);
2480
- }
2481
- }
2482
-
2483
- /**
2484
- * If the proxy or config afterRedirects functions are defined, call them with the options
2485
- *
2486
- * @param {http.ClientRequestArgs} options
2487
- * @param {AxiosProxyConfig} configProxy configuration from Axios options object
2488
- * @param {string} location
2489
- *
2490
- * @returns {http.ClientRequestArgs}
2491
- */
2492
- function setProxy(options, configProxy, location) {
2493
- let proxy = configProxy;
2494
- if (!proxy && proxy !== false) {
2495
- const proxyUrl = proxyFromEnv.getProxyForUrl(location);
2496
- if (proxyUrl) {
2497
- proxy = new URL(proxyUrl);
2498
- }
2499
- }
2500
- if (proxy) {
2501
- // Basic proxy authorization
2502
- if (proxy.username) {
2503
- proxy.auth = (proxy.username || '') + ':' + (proxy.password || '');
2504
- }
2505
-
2506
- if (proxy.auth) {
2507
- // Support proxy auth object form
2508
- if (proxy.auth.username || proxy.auth.password) {
2509
- proxy.auth = (proxy.auth.username || '') + ':' + (proxy.auth.password || '');
2510
- }
2511
- const base64 = Buffer
2512
- .from(proxy.auth, 'utf8')
2513
- .toString('base64');
2514
- options.headers['Proxy-Authorization'] = 'Basic ' + base64;
2515
- }
2516
-
2517
- options.headers.host = options.hostname + (options.port ? ':' + options.port : '');
2518
- const proxyHost = proxy.hostname || proxy.host;
2519
- options.hostname = proxyHost;
2520
- // Replace 'host' since options is not a URL object
2521
- options.host = proxyHost;
2522
- options.port = proxy.port;
2523
- options.path = location;
2524
- if (proxy.protocol) {
2525
- options.protocol = proxy.protocol.includes(':') ? proxy.protocol : `${proxy.protocol}:`;
2526
- }
2527
- }
2528
-
2529
- options.beforeRedirects.proxy = function beforeRedirect(redirectOptions) {
2530
- // Configure proxy for redirected request, passing the original config proxy to apply
2531
- // the exact same logic as if the redirected request was performed by axios directly.
2532
- setProxy(redirectOptions, configProxy, redirectOptions.href);
2533
- };
2534
- }
2535
-
2536
- const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(process) === 'process';
2537
-
2538
- // temporary hotfix
2539
-
2540
- const wrapAsync = (asyncExecutor) => {
2541
- return new Promise((resolve, reject) => {
2542
- let onDone;
2543
- let isDone;
2544
-
2545
- const done = (value, isRejected) => {
2546
- if (isDone) return;
2547
- isDone = true;
2548
- onDone && onDone(value, isRejected);
2549
- };
2550
-
2551
- const _resolve = (value) => {
2552
- done(value);
2553
- resolve(value);
2554
- };
2555
-
2556
- const _reject = (reason) => {
2557
- done(reason, true);
2558
- reject(reason);
2559
- };
2560
-
2561
- asyncExecutor(_resolve, _reject, (onDoneHandler) => (onDone = onDoneHandler)).catch(_reject);
2562
- })
2563
- };
2564
-
2565
- /*eslint consistent-return:0*/
2566
- var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2567
- return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
2568
- let {data} = config;
2569
- const {responseType, responseEncoding} = config;
2570
- const method = config.method.toUpperCase();
2571
- let isDone;
2572
- let rejected = false;
2573
- let req;
2574
-
2575
- // temporary internal emitter until the AxiosRequest class will be implemented
2576
- const emitter = new EventEmitter__default["default"]();
2577
-
2578
- const onFinished = () => {
2579
- if (config.cancelToken) {
2580
- config.cancelToken.unsubscribe(abort);
2581
- }
2582
-
2583
- if (config.signal) {
2584
- config.signal.removeEventListener('abort', abort);
2585
- }
2586
-
2587
- emitter.removeAllListeners();
2588
- };
2589
-
2590
- onDone((value, isRejected) => {
2591
- isDone = true;
2592
- if (isRejected) {
2593
- rejected = true;
2594
- onFinished();
2595
- }
2596
- });
2597
-
2598
- function abort(reason) {
2599
- emitter.emit('abort', !reason || reason.type ? new CanceledError(null, config, req) : reason);
2600
- }
2601
-
2602
- emitter.once('abort', reject);
2603
-
2604
- if (config.cancelToken || config.signal) {
2605
- config.cancelToken && config.cancelToken.subscribe(abort);
2606
- if (config.signal) {
2607
- config.signal.aborted ? abort() : config.signal.addEventListener('abort', abort);
2608
- }
2609
- }
2610
-
2611
- // Parse url
2612
- const fullPath = buildFullPath(config.baseURL, config.url);
2613
- const parsed = new URL(fullPath, 'http://localhost');
2614
- const protocol = parsed.protocol || supportedProtocols[0];
2615
-
2616
- if (protocol === 'data:') {
2617
- let convertedData;
2618
-
2619
- if (method !== 'GET') {
2620
- return settle(resolve, reject, {
2621
- status: 405,
2622
- statusText: 'method not allowed',
2623
- headers: {},
2624
- config
2625
- });
2626
- }
2627
-
2628
- try {
2629
- convertedData = fromDataURI(config.url, responseType === 'blob', {
2630
- Blob: config.env && config.env.Blob
2631
- });
2632
- } catch (err) {
2633
- throw AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config);
2634
- }
2635
-
2636
- if (responseType === 'text') {
2637
- convertedData = convertedData.toString(responseEncoding);
2638
-
2639
- if (!responseEncoding || responseEncoding === 'utf8') {
2640
- convertedData = utils.stripBOM(convertedData);
2641
- }
2642
- } else if (responseType === 'stream') {
2643
- convertedData = stream__default["default"].Readable.from(convertedData);
2644
- }
2645
-
2646
- return settle(resolve, reject, {
2647
- data: convertedData,
2648
- status: 200,
2649
- statusText: 'OK',
2650
- headers: new AxiosHeaders$1(),
2651
- config
2652
- });
2653
- }
2654
-
2655
- if (supportedProtocols.indexOf(protocol) === -1) {
2656
- return reject(new AxiosError(
2657
- 'Unsupported protocol ' + protocol,
2658
- AxiosError.ERR_BAD_REQUEST,
2659
- config
2660
- ));
2661
- }
2662
-
2663
- const headers = AxiosHeaders$1.from(config.headers).normalize();
2664
-
2665
- // Set User-Agent (required by some servers)
2666
- // See https://github.com/axios/axios/issues/69
2667
- // User-Agent is specified; handle case where no UA header is desired
2668
- // Only set header if it hasn't been set in config
2669
- headers.set('User-Agent', 'axios/' + VERSION, false);
2670
-
2671
- const onDownloadProgress = config.onDownloadProgress;
2672
- const onUploadProgress = config.onUploadProgress;
2673
- const maxRate = config.maxRate;
2674
- let maxUploadRate = undefined;
2675
- let maxDownloadRate = undefined;
2676
-
2677
- // support for spec compliant FormData objects
2678
- if (utils.isSpecCompliantForm(data)) {
2679
- const userBoundary = headers.getContentType(/boundary=([-_\w\d]{10,70})/i);
2680
-
2681
- data = formDataToStream$1(data, (formHeaders) => {
2682
- headers.set(formHeaders);
2683
- }, {
2684
- tag: `axios-${VERSION}-boundary`,
2685
- boundary: userBoundary && userBoundary[1] || undefined
2686
- });
2687
- // support for https://www.npmjs.com/package/form-data api
2688
- } else if (utils.isFormData(data) && utils.isFunction(data.getHeaders)) {
2689
- headers.set(data.getHeaders());
2690
-
2691
- if (!headers.hasContentLength()) {
2692
- try {
2693
- const knownLength = await util__default["default"].promisify(data.getLength).call(data);
2694
- Number.isFinite(knownLength) && knownLength >= 0 && headers.setContentLength(knownLength);
2695
- /*eslint no-empty:0*/
2696
- } catch (e) {
2697
- }
2698
- }
2699
- } else if (utils.isBlob(data)) {
2700
- data.size && headers.setContentType(data.type || 'application/octet-stream');
2701
- headers.setContentLength(data.size || 0);
2702
- data = stream__default["default"].Readable.from(readBlob$1(data));
2703
- } else if (data && !utils.isStream(data)) {
2704
- if (Buffer.isBuffer(data)) ; else if (utils.isArrayBuffer(data)) {
2705
- data = Buffer.from(new Uint8Array(data));
2706
- } else if (utils.isString(data)) {
2707
- data = Buffer.from(data, 'utf-8');
2708
- } else {
2709
- return reject(new AxiosError(
2710
- 'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
2711
- AxiosError.ERR_BAD_REQUEST,
2712
- config
2713
- ));
2714
- }
2715
-
2716
- // Add Content-Length header if data exists
2717
- headers.setContentLength(data.length, false);
2718
-
2719
- if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
2720
- return reject(new AxiosError(
2721
- 'Request body larger than maxBodyLength limit',
2722
- AxiosError.ERR_BAD_REQUEST,
2723
- config
2724
- ));
2725
- }
2726
- }
2727
-
2728
- const contentLength = utils.toFiniteNumber(headers.getContentLength());
2729
-
2730
- if (utils.isArray(maxRate)) {
2731
- maxUploadRate = maxRate[0];
2732
- maxDownloadRate = maxRate[1];
2733
- } else {
2734
- maxUploadRate = maxDownloadRate = maxRate;
2735
- }
2736
-
2737
- if (data && (onUploadProgress || maxUploadRate)) {
2738
- if (!utils.isStream(data)) {
2739
- data = stream__default["default"].Readable.from(data, {objectMode: false});
2740
- }
2741
-
2742
- data = stream__default["default"].pipeline([data, new AxiosTransformStream$1({
2743
- length: contentLength,
2744
- maxRate: utils.toFiniteNumber(maxUploadRate)
2745
- })], utils.noop);
2746
-
2747
- onUploadProgress && data.on('progress', progress => {
2748
- onUploadProgress(Object.assign(progress, {
2749
- upload: true
2750
- }));
2751
- });
2752
- }
2753
-
2754
- // HTTP basic authentication
2755
- let auth = undefined;
2756
- if (config.auth) {
2757
- const username = config.auth.username || '';
2758
- const password = config.auth.password || '';
2759
- auth = username + ':' + password;
2760
- }
2761
-
2762
- if (!auth && parsed.username) {
2763
- const urlUsername = parsed.username;
2764
- const urlPassword = parsed.password;
2765
- auth = urlUsername + ':' + urlPassword;
2766
- }
2767
-
2768
- auth && headers.delete('authorization');
2769
-
2770
- let path;
2771
-
2772
- try {
2773
- path = buildURL(
2774
- parsed.pathname + parsed.search,
2775
- config.params,
2776
- config.paramsSerializer
2777
- ).replace(/^\?/, '');
2778
- } catch (err) {
2779
- const customErr = new Error(err.message);
2780
- customErr.config = config;
2781
- customErr.url = config.url;
2782
- customErr.exists = true;
2783
- return reject(customErr);
2784
- }
2785
-
2786
- headers.set(
2787
- 'Accept-Encoding',
2788
- 'gzip, compress, deflate' + (isBrotliSupported ? ', br' : ''), false
2789
- );
2790
-
2791
- const options = {
2792
- path,
2793
- method: method,
2794
- headers: headers.toJSON(),
2795
- agents: { http: config.httpAgent, https: config.httpsAgent },
2796
- auth,
2797
- protocol,
2798
- beforeRedirect: dispatchBeforeRedirect,
2799
- beforeRedirects: {}
2800
- };
2801
-
2802
- if (config.socketPath) {
2803
- options.socketPath = config.socketPath;
2804
- } else {
2805
- options.hostname = parsed.hostname;
2806
- options.port = parsed.port;
2807
- setProxy(options, config.proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path);
2808
- }
2809
-
2810
- let transport;
2811
- const isHttpsRequest = isHttps.test(options.protocol);
2812
- options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
2813
- if (config.transport) {
2814
- transport = config.transport;
2815
- } else if (config.maxRedirects === 0) {
2816
- transport = isHttpsRequest ? https__default["default"] : http__default["default"];
2817
- } else {
2818
- if (config.maxRedirects) {
2819
- options.maxRedirects = config.maxRedirects;
2820
- }
2821
- if (config.beforeRedirect) {
2822
- options.beforeRedirects.config = config.beforeRedirect;
2823
- }
2824
- transport = isHttpsRequest ? httpsFollow : httpFollow;
2825
- }
2826
-
2827
- if (config.maxBodyLength > -1) {
2828
- options.maxBodyLength = config.maxBodyLength;
2829
- } else {
2830
- // follow-redirects does not skip comparison, so it should always succeed for axios -1 unlimited
2831
- options.maxBodyLength = Infinity;
2832
- }
2833
-
2834
- if (config.insecureHTTPParser) {
2835
- options.insecureHTTPParser = config.insecureHTTPParser;
2836
- }
2837
-
2838
- // Create the request
2839
- req = transport.request(options, function handleResponse(res) {
2840
- if (req.destroyed) return;
2841
-
2842
- const streams = [res];
2843
-
2844
- const responseLength = +res.headers['content-length'];
2845
-
2846
- if (onDownloadProgress) {
2847
- const transformStream = new AxiosTransformStream$1({
2848
- length: utils.toFiniteNumber(responseLength),
2849
- maxRate: utils.toFiniteNumber(maxDownloadRate)
2850
- });
2851
-
2852
- onDownloadProgress && transformStream.on('progress', progress => {
2853
- onDownloadProgress(Object.assign(progress, {
2854
- download: true
2855
- }));
2856
- });
2857
-
2858
- streams.push(transformStream);
2859
- }
2860
-
2861
- // decompress the response body transparently if required
2862
- let responseStream = res;
2863
-
2864
- // return the last request in case of redirects
2865
- const lastRequest = res.req || req;
2866
-
2867
- // if decompress disabled we should not decompress
2868
- if (config.decompress !== false && res.headers['content-encoding']) {
2869
- // if no content, but headers still say that it is encoded,
2870
- // remove the header not confuse downstream operations
2871
- if (method === 'HEAD' || res.statusCode === 204) {
2872
- delete res.headers['content-encoding'];
2873
- }
2874
-
2875
- switch (res.headers['content-encoding']) {
2876
- /*eslint default-case:0*/
2877
- case 'gzip':
2878
- case 'x-gzip':
2879
- case 'compress':
2880
- case 'x-compress':
2881
- // add the unzipper to the body stream processing pipeline
2882
- streams.push(zlib__default["default"].createUnzip(zlibOptions));
2883
-
2884
- // remove the content-encoding in order to not confuse downstream operations
2885
- delete res.headers['content-encoding'];
2886
- break;
2887
- case 'deflate':
2888
- streams.push(new ZlibHeaderTransformStream$1());
2889
-
2890
- // add the unzipper to the body stream processing pipeline
2891
- streams.push(zlib__default["default"].createUnzip(zlibOptions));
2892
-
2893
- // remove the content-encoding in order to not confuse downstream operations
2894
- delete res.headers['content-encoding'];
2895
- break;
2896
- case 'br':
2897
- if (isBrotliSupported) {
2898
- streams.push(zlib__default["default"].createBrotliDecompress(brotliOptions));
2899
- delete res.headers['content-encoding'];
2900
- }
2901
- }
2902
- }
2903
-
2904
- responseStream = streams.length > 1 ? stream__default["default"].pipeline(streams, utils.noop) : streams[0];
2905
-
2906
- const offListeners = stream__default["default"].finished(responseStream, () => {
2907
- offListeners();
2908
- onFinished();
2909
- });
2910
-
2911
- const response = {
2912
- status: res.statusCode,
2913
- statusText: res.statusMessage,
2914
- headers: new AxiosHeaders$1(res.headers),
2915
- config,
2916
- request: lastRequest
2917
- };
2918
-
2919
- if (responseType === 'stream') {
2920
- response.data = responseStream;
2921
- settle(resolve, reject, response);
2922
- } else {
2923
- const responseBuffer = [];
2924
- let totalResponseBytes = 0;
2925
-
2926
- responseStream.on('data', function handleStreamData(chunk) {
2927
- responseBuffer.push(chunk);
2928
- totalResponseBytes += chunk.length;
2929
-
2930
- // make sure the content length is not over the maxContentLength if specified
2931
- if (config.maxContentLength > -1 && totalResponseBytes > config.maxContentLength) {
2932
- // stream.destroy() emit aborted event before calling reject() on Node.js v16
2933
- rejected = true;
2934
- responseStream.destroy();
2935
- reject(new AxiosError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
2936
- AxiosError.ERR_BAD_RESPONSE, config, lastRequest));
2937
- }
2938
- });
2939
-
2940
- responseStream.on('aborted', function handlerStreamAborted() {
2941
- if (rejected) {
2942
- return;
2943
- }
2944
-
2945
- const err = new AxiosError(
2946
- 'maxContentLength size of ' + config.maxContentLength + ' exceeded',
2947
- AxiosError.ERR_BAD_RESPONSE,
2948
- config,
2949
- lastRequest
2950
- );
2951
- responseStream.destroy(err);
2952
- reject(err);
2953
- });
2954
-
2955
- responseStream.on('error', function handleStreamError(err) {
2956
- if (req.destroyed) return;
2957
- reject(AxiosError.from(err, null, config, lastRequest));
2958
- });
2959
-
2960
- responseStream.on('end', function handleStreamEnd() {
2961
- try {
2962
- let responseData = responseBuffer.length === 1 ? responseBuffer[0] : Buffer.concat(responseBuffer);
2963
- if (responseType !== 'arraybuffer') {
2964
- responseData = responseData.toString(responseEncoding);
2965
- if (!responseEncoding || responseEncoding === 'utf8') {
2966
- responseData = utils.stripBOM(responseData);
2967
- }
11
+ if (e && e.__esModule) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
2968
21
  }
2969
- response.data = responseData;
2970
- } catch (err) {
2971
- reject(AxiosError.from(err, null, config, response.request, response));
2972
- }
2973
- settle(resolve, reject, response);
2974
22
  });
2975
- }
2976
-
2977
- emitter.once('abort', err => {
2978
- if (!responseStream.destroyed) {
2979
- responseStream.emit('error', err);
2980
- responseStream.destroy();
2981
- }
2982
- });
2983
- });
2984
-
2985
- emitter.once('abort', err => {
2986
- reject(err);
2987
- req.destroy(err);
2988
- });
2989
-
2990
- // Handle errors
2991
- req.on('error', function handleRequestError(err) {
2992
- // @todo remove
2993
- // if (req.aborted && err.code !== AxiosError.ERR_FR_TOO_MANY_REDIRECTS) return;
2994
- reject(AxiosError.from(err, null, config, req));
2995
- });
2996
-
2997
- // set tcp keep alive to prevent drop connection by peer
2998
- req.on('socket', function handleRequestSocket(socket) {
2999
- // default interval of sending ack packet is 1 minute
3000
- socket.setKeepAlive(true, 1000 * 60);
3001
- });
3002
-
3003
- // Handle request timeout
3004
- if (config.timeout) {
3005
- // This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types.
3006
- const timeout = parseInt(config.timeout, 10);
3007
-
3008
- if (isNaN(timeout)) {
3009
- reject(new AxiosError(
3010
- 'error trying to parse `config.timeout` to int',
3011
- AxiosError.ERR_BAD_OPTION_VALUE,
3012
- config,
3013
- req
3014
- ));
3015
-
3016
- return;
3017
- }
3018
-
3019
- // Sometime, the response will be very slow, and does not respond, the connect event will be block by event loop system.
3020
- // And timer callback will be fired, and abort() will be invoked before connection, then get "socket hang up" and code ECONNRESET.
3021
- // At this time, if we have a large number of request, nodejs will hang up some socket on background. and the number will up and up.
3022
- // And then these socket which be hang up will devouring CPU little by little.
3023
- // ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
3024
- req.setTimeout(timeout, function handleRequestTimeout() {
3025
- if (isDone) return;
3026
- let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
3027
- const transitional = config.transitional || transitionalDefaults;
3028
- if (config.timeoutErrorMessage) {
3029
- timeoutErrorMessage = config.timeoutErrorMessage;
3030
- }
3031
- reject(new AxiosError(
3032
- timeoutErrorMessage,
3033
- transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
3034
- config,
3035
- req
3036
- ));
3037
- abort();
3038
- });
3039
- }
3040
-
3041
-
3042
- // Send the request
3043
- if (utils.isStream(data)) {
3044
- let ended = false;
3045
- let errored = false;
3046
-
3047
- data.on('end', () => {
3048
- ended = true;
3049
- });
3050
-
3051
- data.once('error', err => {
3052
- errored = true;
3053
- req.destroy(err);
3054
- });
3055
-
3056
- data.on('close', () => {
3057
- if (!ended && !errored) {
3058
- abort(new CanceledError('Request stream has been aborted', config, req));
3059
- }
3060
- });
3061
-
3062
- data.pipe(req);
3063
- } else {
3064
- req.end(data);
3065
- }
3066
- });
3067
- };
3068
-
3069
- var cookies = platform.isStandardBrowserEnv ?
3070
-
3071
- // Standard browser envs support document.cookie
3072
- (function standardBrowserEnv() {
3073
- return {
3074
- write: function write(name, value, expires, path, domain, secure) {
3075
- const cookie = [];
3076
- cookie.push(name + '=' + encodeURIComponent(value));
3077
-
3078
- if (utils.isNumber(expires)) {
3079
- cookie.push('expires=' + new Date(expires).toGMTString());
3080
- }
3081
-
3082
- if (utils.isString(path)) {
3083
- cookie.push('path=' + path);
3084
- }
3085
-
3086
- if (utils.isString(domain)) {
3087
- cookie.push('domain=' + domain);
3088
- }
3089
-
3090
- if (secure === true) {
3091
- cookie.push('secure');
3092
- }
3093
-
3094
- document.cookie = cookie.join('; ');
3095
- },
3096
-
3097
- read: function read(name) {
3098
- const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
3099
- return (match ? decodeURIComponent(match[3]) : null);
3100
- },
3101
-
3102
- remove: function remove(name) {
3103
- this.write(name, '', Date.now() - 86400000);
3104
- }
3105
- };
3106
- })() :
3107
-
3108
- // Non standard browser env (web workers, react-native) lack needed support.
3109
- (function nonStandardBrowserEnv() {
3110
- return {
3111
- write: function write() {},
3112
- read: function read() { return null; },
3113
- remove: function remove() {}
3114
- };
3115
- })();
3116
-
3117
- var isURLSameOrigin = platform.isStandardBrowserEnv ?
3118
-
3119
- // Standard browser envs have full support of the APIs needed to test
3120
- // whether the request URL is of the same origin as current location.
3121
- (function standardBrowserEnv() {
3122
- const msie = /(msie|trident)/i.test(navigator.userAgent);
3123
- const urlParsingNode = document.createElement('a');
3124
- let originURL;
3125
-
3126
- /**
3127
- * Parse a URL to discover it's components
3128
- *
3129
- * @param {String} url The URL to be parsed
3130
- * @returns {Object}
3131
- */
3132
- function resolveURL(url) {
3133
- let href = url;
3134
-
3135
- if (msie) {
3136
- // IE needs attribute set twice to normalize properties
3137
- urlParsingNode.setAttribute('href', href);
3138
- href = urlParsingNode.href;
3139
- }
3140
-
3141
- urlParsingNode.setAttribute('href', href);
3142
-
3143
- // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
3144
- return {
3145
- href: urlParsingNode.href,
3146
- protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
3147
- host: urlParsingNode.host,
3148
- search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
3149
- hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
3150
- hostname: urlParsingNode.hostname,
3151
- port: urlParsingNode.port,
3152
- pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
3153
- urlParsingNode.pathname :
3154
- '/' + urlParsingNode.pathname
3155
- };
3156
- }
3157
-
3158
- originURL = resolveURL(window.location.href);
3159
-
3160
- /**
3161
- * Determine if a URL shares the same origin as the current location
3162
- *
3163
- * @param {String} requestURL The URL to test
3164
- * @returns {boolean} True if URL shares the same origin, otherwise false
3165
- */
3166
- return function isURLSameOrigin(requestURL) {
3167
- const parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
3168
- return (parsed.protocol === originURL.protocol &&
3169
- parsed.host === originURL.host);
3170
- };
3171
- })() :
3172
-
3173
- // Non standard browser envs (web workers, react-native) lack needed support.
3174
- (function nonStandardBrowserEnv() {
3175
- return function isURLSameOrigin() {
3176
- return true;
3177
- };
3178
- })();
3179
-
3180
- function progressEventReducer(listener, isDownloadStream) {
3181
- let bytesNotified = 0;
3182
- const _speedometer = speedometer(50, 250);
3183
-
3184
- return e => {
3185
- const loaded = e.loaded;
3186
- const total = e.lengthComputable ? e.total : undefined;
3187
- const progressBytes = loaded - bytesNotified;
3188
- const rate = _speedometer(progressBytes);
3189
- const inRange = loaded <= total;
3190
-
3191
- bytesNotified = loaded;
3192
-
3193
- const data = {
3194
- loaded,
3195
- total,
3196
- progress: total ? (loaded / total) : undefined,
3197
- bytes: progressBytes,
3198
- rate: rate ? rate : undefined,
3199
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
3200
- event: e
3201
- };
3202
-
3203
- data[isDownloadStream ? 'download' : 'upload'] = true;
3204
-
3205
- listener(data);
3206
- };
3207
- }
3208
-
3209
- const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
3210
-
3211
- var xhrAdapter = isXHRAdapterSupported && function (config) {
3212
- return new Promise(function dispatchXhrRequest(resolve, reject) {
3213
- let requestData = config.data;
3214
- const requestHeaders = AxiosHeaders$1.from(config.headers).normalize();
3215
- const responseType = config.responseType;
3216
- let onCanceled;
3217
- function done() {
3218
- if (config.cancelToken) {
3219
- config.cancelToken.unsubscribe(onCanceled);
3220
- }
3221
-
3222
- if (config.signal) {
3223
- config.signal.removeEventListener('abort', onCanceled);
3224
- }
3225
- }
3226
-
3227
- if (utils.isFormData(requestData) && (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv)) {
3228
- requestHeaders.setContentType(false); // Let the browser set it
3229
- }
3230
-
3231
- let request = new XMLHttpRequest();
3232
-
3233
- // HTTP basic authentication
3234
- if (config.auth) {
3235
- const username = config.auth.username || '';
3236
- const password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
3237
- requestHeaders.set('Authorization', 'Basic ' + btoa(username + ':' + password));
3238
- }
3239
-
3240
- const fullPath = buildFullPath(config.baseURL, config.url);
3241
-
3242
- request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
3243
-
3244
- // Set the request timeout in MS
3245
- request.timeout = config.timeout;
3246
-
3247
- function onloadend() {
3248
- if (!request) {
3249
- return;
3250
- }
3251
- // Prepare the response
3252
- const responseHeaders = AxiosHeaders$1.from(
3253
- 'getAllResponseHeaders' in request && request.getAllResponseHeaders()
3254
- );
3255
- const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
3256
- request.responseText : request.response;
3257
- const response = {
3258
- data: responseData,
3259
- status: request.status,
3260
- statusText: request.statusText,
3261
- headers: responseHeaders,
3262
- config,
3263
- request
3264
- };
3265
-
3266
- settle(function _resolve(value) {
3267
- resolve(value);
3268
- done();
3269
- }, function _reject(err) {
3270
- reject(err);
3271
- done();
3272
- }, response);
3273
-
3274
- // Clean up request
3275
- request = null;
3276
- }
3277
-
3278
- if ('onloadend' in request) {
3279
- // Use onloadend if available
3280
- request.onloadend = onloadend;
3281
- } else {
3282
- // Listen for ready state to emulate onloadend
3283
- request.onreadystatechange = function handleLoad() {
3284
- if (!request || request.readyState !== 4) {
3285
- return;
3286
- }
3287
-
3288
- // The request errored out and we didn't get a response, this will be
3289
- // handled by onerror instead
3290
- // With one exception: request that using file: protocol, most browsers
3291
- // will return status as 0 even though it's a successful request
3292
- if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
3293
- return;
3294
- }
3295
- // readystate handler is calling before onerror or ontimeout handlers,
3296
- // so we should call onloadend on the next 'tick'
3297
- setTimeout(onloadend);
3298
- };
3299
- }
3300
-
3301
- // Handle browser request cancellation (as opposed to a manual cancellation)
3302
- request.onabort = function handleAbort() {
3303
- if (!request) {
3304
- return;
3305
- }
3306
-
3307
- reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
3308
-
3309
- // Clean up request
3310
- request = null;
3311
- };
3312
-
3313
- // Handle low level network errors
3314
- request.onerror = function handleError() {
3315
- // Real errors are hidden from us by the browser
3316
- // onerror should only fire if it's a network error
3317
- reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
3318
-
3319
- // Clean up request
3320
- request = null;
3321
- };
3322
-
3323
- // Handle timeout
3324
- request.ontimeout = function handleTimeout() {
3325
- let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
3326
- const transitional = config.transitional || transitionalDefaults;
3327
- if (config.timeoutErrorMessage) {
3328
- timeoutErrorMessage = config.timeoutErrorMessage;
3329
- }
3330
- reject(new AxiosError(
3331
- timeoutErrorMessage,
3332
- transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
3333
- config,
3334
- request));
3335
-
3336
- // Clean up request
3337
- request = null;
3338
- };
3339
-
3340
- // Add xsrf header
3341
- // This is only done if running in a standard browser environment.
3342
- // Specifically not if we're in a web worker, or react-native.
3343
- if (platform.isStandardBrowserEnv) {
3344
- // Add xsrf header
3345
- const xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath))
3346
- && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
3347
-
3348
- if (xsrfValue) {
3349
- requestHeaders.set(config.xsrfHeaderName, xsrfValue);
3350
- }
3351
- }
3352
-
3353
- // Remove Content-Type if data is undefined
3354
- requestData === undefined && requestHeaders.setContentType(null);
3355
-
3356
- // Add headers to the request
3357
- if ('setRequestHeader' in request) {
3358
- utils.forEach(requestHeaders.toJSON(), function setRequestHeader(val, key) {
3359
- request.setRequestHeader(key, val);
3360
- });
3361
- }
3362
-
3363
- // Add withCredentials to request if needed
3364
- if (!utils.isUndefined(config.withCredentials)) {
3365
- request.withCredentials = !!config.withCredentials;
3366
- }
3367
-
3368
- // Add responseType to request if needed
3369
- if (responseType && responseType !== 'json') {
3370
- request.responseType = config.responseType;
3371
- }
3372
-
3373
- // Handle progress if needed
3374
- if (typeof config.onDownloadProgress === 'function') {
3375
- request.addEventListener('progress', progressEventReducer(config.onDownloadProgress, true));
3376
- }
3377
-
3378
- // Not all browsers support upload events
3379
- if (typeof config.onUploadProgress === 'function' && request.upload) {
3380
- request.upload.addEventListener('progress', progressEventReducer(config.onUploadProgress));
3381
- }
3382
-
3383
- if (config.cancelToken || config.signal) {
3384
- // Handle cancellation
3385
- // eslint-disable-next-line func-names
3386
- onCanceled = cancel => {
3387
- if (!request) {
3388
- return;
3389
- }
3390
- reject(!cancel || cancel.type ? new CanceledError(null, config, request) : cancel);
3391
- request.abort();
3392
- request = null;
3393
- };
3394
-
3395
- config.cancelToken && config.cancelToken.subscribe(onCanceled);
3396
- if (config.signal) {
3397
- config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
3398
- }
3399
- }
3400
-
3401
- const protocol = parseProtocol(fullPath);
3402
-
3403
- if (protocol && platform.protocols.indexOf(protocol) === -1) {
3404
- reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
3405
- return;
3406
- }
3407
-
3408
-
3409
- // Send the request
3410
- request.send(requestData || null);
3411
- });
3412
- };
3413
-
3414
- const knownAdapters = {
3415
- http: httpAdapter,
3416
- xhr: xhrAdapter
3417
- };
3418
-
3419
- utils.forEach(knownAdapters, (fn, value) => {
3420
- if(fn) {
3421
- try {
3422
- Object.defineProperty(fn, 'name', {value});
3423
- } catch (e) {
3424
- // eslint-disable-next-line no-empty
3425
- }
3426
- Object.defineProperty(fn, 'adapterName', {value});
3427
- }
3428
- });
3429
-
3430
- var adapters = {
3431
- getAdapter: (adapters) => {
3432
- adapters = utils.isArray(adapters) ? adapters : [adapters];
3433
-
3434
- const {length} = adapters;
3435
- let nameOrAdapter;
3436
- let adapter;
3437
-
3438
- for (let i = 0; i < length; i++) {
3439
- nameOrAdapter = adapters[i];
3440
- if((adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter)) {
3441
- break;
3442
- }
3443
- }
3444
-
3445
- if (!adapter) {
3446
- if (adapter === false) {
3447
- throw new AxiosError(
3448
- `Adapter ${nameOrAdapter} is not supported by the environment`,
3449
- 'ERR_NOT_SUPPORT'
3450
- );
3451
- }
3452
-
3453
- throw new Error(
3454
- utils.hasOwnProp(knownAdapters, nameOrAdapter) ?
3455
- `Adapter '${nameOrAdapter}' is not available in the build` :
3456
- `Unknown adapter '${nameOrAdapter}'`
3457
- );
3458
- }
3459
-
3460
- if (!utils.isFunction(adapter)) {
3461
- throw new TypeError('adapter is not a function');
3462
- }
3463
-
3464
- return adapter;
3465
- },
3466
- adapters: knownAdapters
3467
- };
3468
-
3469
- /**
3470
- * Throws a `CanceledError` if cancellation has been requested.
3471
- *
3472
- * @param {Object} config The config that is to be used for the request
3473
- *
3474
- * @returns {void}
3475
- */
3476
- function throwIfCancellationRequested(config) {
3477
- if (config.cancelToken) {
3478
- config.cancelToken.throwIfRequested();
3479
- }
3480
-
3481
- if (config.signal && config.signal.aborted) {
3482
- throw new CanceledError(null, config);
3483
- }
3484
- }
3485
-
3486
- /**
3487
- * Dispatch a request to the server using the configured adapter.
3488
- *
3489
- * @param {object} config The config that is to be used for the request
3490
- *
3491
- * @returns {Promise} The Promise to be fulfilled
3492
- */
3493
- function dispatchRequest(config) {
3494
- throwIfCancellationRequested(config);
3495
-
3496
- config.headers = AxiosHeaders$1.from(config.headers);
3497
-
3498
- // Transform request data
3499
- config.data = transformData.call(
3500
- config,
3501
- config.transformRequest
3502
- );
3503
-
3504
- if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
3505
- config.headers.setContentType('application/x-www-form-urlencoded', false);
3506
- }
3507
-
3508
- const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
3509
-
3510
- return adapter(config).then(function onAdapterResolution(response) {
3511
- throwIfCancellationRequested(config);
3512
-
3513
- // Transform response data
3514
- response.data = transformData.call(
3515
- config,
3516
- config.transformResponse,
3517
- response
3518
- );
3519
-
3520
- response.headers = AxiosHeaders$1.from(response.headers);
3521
-
3522
- return response;
3523
- }, function onAdapterRejection(reason) {
3524
- if (!isCancel(reason)) {
3525
- throwIfCancellationRequested(config);
3526
-
3527
- // Transform response data
3528
- if (reason && reason.response) {
3529
- reason.response.data = transformData.call(
3530
- config,
3531
- config.transformResponse,
3532
- reason.response
3533
- );
3534
- reason.response.headers = AxiosHeaders$1.from(reason.response.headers);
3535
- }
3536
- }
3537
-
3538
- return Promise.reject(reason);
3539
- });
3540
- }
3541
-
3542
- const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? thing.toJSON() : thing;
3543
-
3544
- /**
3545
- * Config-specific merge-function which creates a new config-object
3546
- * by merging two configuration objects together.
3547
- *
3548
- * @param {Object} config1
3549
- * @param {Object} config2
3550
- *
3551
- * @returns {Object} New object resulting from merging config2 to config1
3552
- */
3553
- function mergeConfig(config1, config2) {
3554
- // eslint-disable-next-line no-param-reassign
3555
- config2 = config2 || {};
3556
- const config = {};
3557
-
3558
- function getMergedValue(target, source, caseless) {
3559
- if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
3560
- return utils.merge.call({caseless}, target, source);
3561
- } else if (utils.isPlainObject(source)) {
3562
- return utils.merge({}, source);
3563
- } else if (utils.isArray(source)) {
3564
- return source.slice();
3565
23
  }
3566
- return source;
3567
- }
3568
-
3569
- // eslint-disable-next-line consistent-return
3570
- function mergeDeepProperties(a, b, caseless) {
3571
- if (!utils.isUndefined(b)) {
3572
- return getMergedValue(a, b, caseless);
3573
- } else if (!utils.isUndefined(a)) {
3574
- return getMergedValue(undefined, a, caseless);
3575
- }
3576
- }
3577
-
3578
- // eslint-disable-next-line consistent-return
3579
- function valueFromConfig2(a, b) {
3580
- if (!utils.isUndefined(b)) {
3581
- return getMergedValue(undefined, b);
3582
- }
3583
- }
3584
-
3585
- // eslint-disable-next-line consistent-return
3586
- function defaultToConfig2(a, b) {
3587
- if (!utils.isUndefined(b)) {
3588
- return getMergedValue(undefined, b);
3589
- } else if (!utils.isUndefined(a)) {
3590
- return getMergedValue(undefined, a);
3591
- }
3592
- }
3593
-
3594
- // eslint-disable-next-line consistent-return
3595
- function mergeDirectKeys(a, b, prop) {
3596
- if (prop in config2) {
3597
- return getMergedValue(a, b);
3598
- } else if (prop in config1) {
3599
- return getMergedValue(undefined, a);
3600
- }
3601
- }
3602
-
3603
- const mergeMap = {
3604
- url: valueFromConfig2,
3605
- method: valueFromConfig2,
3606
- data: valueFromConfig2,
3607
- baseURL: defaultToConfig2,
3608
- transformRequest: defaultToConfig2,
3609
- transformResponse: defaultToConfig2,
3610
- paramsSerializer: defaultToConfig2,
3611
- timeout: defaultToConfig2,
3612
- timeoutMessage: defaultToConfig2,
3613
- withCredentials: defaultToConfig2,
3614
- adapter: defaultToConfig2,
3615
- responseType: defaultToConfig2,
3616
- xsrfCookieName: defaultToConfig2,
3617
- xsrfHeaderName: defaultToConfig2,
3618
- onUploadProgress: defaultToConfig2,
3619
- onDownloadProgress: defaultToConfig2,
3620
- decompress: defaultToConfig2,
3621
- maxContentLength: defaultToConfig2,
3622
- maxBodyLength: defaultToConfig2,
3623
- beforeRedirect: defaultToConfig2,
3624
- transport: defaultToConfig2,
3625
- httpAgent: defaultToConfig2,
3626
- httpsAgent: defaultToConfig2,
3627
- cancelToken: defaultToConfig2,
3628
- socketPath: defaultToConfig2,
3629
- responseEncoding: defaultToConfig2,
3630
- validateStatus: mergeDirectKeys,
3631
- headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
3632
- };
3633
-
3634
- utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
3635
- const merge = mergeMap[prop] || mergeDeepProperties;
3636
- const configValue = merge(config1[prop], config2[prop], prop);
3637
- (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
3638
- });
3639
-
3640
- return config;
3641
- }
3642
-
3643
- const validators$1 = {};
3644
-
3645
- // eslint-disable-next-line func-names
3646
- ['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach((type, i) => {
3647
- validators$1[type] = function validator(thing) {
3648
- return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
3649
- };
3650
- });
3651
-
3652
- const deprecatedWarnings = {};
3653
-
3654
- /**
3655
- * Transitional option validator
3656
- *
3657
- * @param {function|boolean?} validator - set to false if the transitional option has been removed
3658
- * @param {string?} version - deprecated version / removed since version
3659
- * @param {string?} message - some message with additional info
3660
- *
3661
- * @returns {function}
3662
- */
3663
- validators$1.transitional = function transitional(validator, version, message) {
3664
- function formatMessage(opt, desc) {
3665
- return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
3666
- }
3667
-
3668
- // eslint-disable-next-line func-names
3669
- return (value, opt, opts) => {
3670
- if (validator === false) {
3671
- throw new AxiosError(
3672
- formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')),
3673
- AxiosError.ERR_DEPRECATED
3674
- );
3675
- }
3676
-
3677
- if (version && !deprecatedWarnings[opt]) {
3678
- deprecatedWarnings[opt] = true;
3679
- // eslint-disable-next-line no-console
3680
- console.warn(
3681
- formatMessage(
3682
- opt,
3683
- ' has been deprecated since v' + version + ' and will be removed in the near future'
3684
- )
3685
- );
3686
- }
3687
-
3688
- return validator ? validator(value, opt, opts) : true;
3689
- };
3690
- };
3691
-
3692
- /**
3693
- * Assert object's properties type
3694
- *
3695
- * @param {object} options
3696
- * @param {object} schema
3697
- * @param {boolean?} allowUnknown
3698
- *
3699
- * @returns {object}
3700
- */
3701
-
3702
- function assertOptions(options, schema, allowUnknown) {
3703
- if (typeof options !== 'object') {
3704
- throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE);
3705
- }
3706
- const keys = Object.keys(options);
3707
- let i = keys.length;
3708
- while (i-- > 0) {
3709
- const opt = keys[i];
3710
- const validator = schema[opt];
3711
- if (validator) {
3712
- const value = options[opt];
3713
- const result = value === undefined || validator(value, opt, options);
3714
- if (result !== true) {
3715
- throw new AxiosError('option ' + opt + ' must be ' + result, AxiosError.ERR_BAD_OPTION_VALUE);
3716
- }
3717
- continue;
3718
- }
3719
- if (allowUnknown !== true) {
3720
- throw new AxiosError('Unknown option ' + opt, AxiosError.ERR_BAD_OPTION);
3721
- }
3722
- }
3723
- }
3724
-
3725
- var validator = {
3726
- assertOptions,
3727
- validators: validators$1
3728
- };
3729
-
3730
- const validators = validator.validators;
3731
-
3732
- /**
3733
- * Create a new instance of Axios
3734
- *
3735
- * @param {Object} instanceConfig The default config for the instance
3736
- *
3737
- * @return {Axios} A new instance of Axios
3738
- */
3739
- class Axios {
3740
- constructor(instanceConfig) {
3741
- this.defaults = instanceConfig;
3742
- this.interceptors = {
3743
- request: new InterceptorManager$1(),
3744
- response: new InterceptorManager$1()
3745
- };
3746
- }
3747
-
3748
- /**
3749
- * Dispatch a request
3750
- *
3751
- * @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
3752
- * @param {?Object} config
3753
- *
3754
- * @returns {Promise} The Promise to be fulfilled
3755
- */
3756
- request(configOrUrl, config) {
3757
- /*eslint no-param-reassign:0*/
3758
- // Allow for axios('example/url'[, config]) a la fetch API
3759
- if (typeof configOrUrl === 'string') {
3760
- config = config || {};
3761
- config.url = configOrUrl;
3762
- } else {
3763
- config = configOrUrl || {};
3764
- }
3765
-
3766
- config = mergeConfig(this.defaults, config);
3767
-
3768
- const {transitional, paramsSerializer, headers} = config;
3769
-
3770
- if (transitional !== undefined) {
3771
- validator.assertOptions(transitional, {
3772
- silentJSONParsing: validators.transitional(validators.boolean),
3773
- forcedJSONParsing: validators.transitional(validators.boolean),
3774
- clarifyTimeoutError: validators.transitional(validators.boolean)
3775
- }, false);
3776
- }
3777
-
3778
- if (paramsSerializer !== undefined) {
3779
- validator.assertOptions(paramsSerializer, {
3780
- encode: validators.function,
3781
- serialize: validators.function
3782
- }, true);
3783
- }
3784
-
3785
- // Set config.method
3786
- config.method = (config.method || this.defaults.method || 'get').toLowerCase();
3787
-
3788
- let contextHeaders;
3789
-
3790
- // Flatten headers
3791
- contextHeaders = headers && utils.merge(
3792
- headers.common,
3793
- headers[config.method]
3794
- );
3795
-
3796
- contextHeaders && utils.forEach(
3797
- ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
3798
- (method) => {
3799
- delete headers[method];
3800
- }
3801
- );
3802
-
3803
- config.headers = AxiosHeaders$1.concat(contextHeaders, headers);
3804
-
3805
- // filter out skipped interceptors
3806
- const requestInterceptorChain = [];
3807
- let synchronousRequestInterceptors = true;
3808
- this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
3809
- if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
3810
- return;
3811
- }
3812
-
3813
- synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
3814
-
3815
- requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
3816
- });
3817
-
3818
- const responseInterceptorChain = [];
3819
- this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
3820
- responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
3821
- });
3822
-
3823
- let promise;
3824
- let i = 0;
3825
- let len;
3826
-
3827
- if (!synchronousRequestInterceptors) {
3828
- const chain = [dispatchRequest.bind(this), undefined];
3829
- chain.unshift.apply(chain, requestInterceptorChain);
3830
- chain.push.apply(chain, responseInterceptorChain);
3831
- len = chain.length;
3832
-
3833
- promise = Promise.resolve(config);
3834
-
3835
- while (i < len) {
3836
- promise = promise.then(chain[i++], chain[i++]);
3837
- }
3838
-
3839
- return promise;
3840
- }
3841
-
3842
- len = requestInterceptorChain.length;
3843
-
3844
- let newConfig = config;
3845
-
3846
- i = 0;
3847
-
3848
- while (i < len) {
3849
- const onFulfilled = requestInterceptorChain[i++];
3850
- const onRejected = requestInterceptorChain[i++];
3851
- try {
3852
- newConfig = onFulfilled(newConfig);
3853
- } catch (error) {
3854
- onRejected.call(this, error);
3855
- break;
3856
- }
3857
- }
3858
-
3859
- try {
3860
- promise = dispatchRequest.call(this, newConfig);
3861
- } catch (error) {
3862
- return Promise.reject(error);
3863
- }
3864
-
3865
- i = 0;
3866
- len = responseInterceptorChain.length;
3867
-
3868
- while (i < len) {
3869
- promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
3870
- }
3871
-
3872
- return promise;
3873
- }
3874
-
3875
- getUri(config) {
3876
- config = mergeConfig(this.defaults, config);
3877
- const fullPath = buildFullPath(config.baseURL, config.url);
3878
- return buildURL(fullPath, config.params, config.paramsSerializer);
3879
- }
3880
- }
3881
-
3882
- // Provide aliases for supported request methods
3883
- utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
3884
- /*eslint func-names:0*/
3885
- Axios.prototype[method] = function(url, config) {
3886
- return this.request(mergeConfig(config || {}, {
3887
- method,
3888
- url,
3889
- data: (config || {}).data
3890
- }));
3891
- };
3892
- });
3893
-
3894
- utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3895
- /*eslint func-names:0*/
3896
-
3897
- function generateHTTPMethod(isForm) {
3898
- return function httpMethod(url, data, config) {
3899
- return this.request(mergeConfig(config || {}, {
3900
- method,
3901
- headers: isForm ? {
3902
- 'Content-Type': 'multipart/form-data'
3903
- } : {},
3904
- url,
3905
- data
3906
- }));
3907
- };
3908
- }
3909
-
3910
- Axios.prototype[method] = generateHTTPMethod();
3911
-
3912
- Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
3913
- });
3914
-
3915
- var Axios$1 = Axios;
3916
-
3917
- /**
3918
- * A `CancelToken` is an object that can be used to request cancellation of an operation.
3919
- *
3920
- * @param {Function} executor The executor function.
3921
- *
3922
- * @returns {CancelToken}
3923
- */
3924
- class CancelToken {
3925
- constructor(executor) {
3926
- if (typeof executor !== 'function') {
3927
- throw new TypeError('executor must be a function.');
3928
- }
3929
-
3930
- let resolvePromise;
3931
-
3932
- this.promise = new Promise(function promiseExecutor(resolve) {
3933
- resolvePromise = resolve;
3934
- });
3935
-
3936
- const token = this;
3937
-
3938
- // eslint-disable-next-line func-names
3939
- this.promise.then(cancel => {
3940
- if (!token._listeners) return;
3941
-
3942
- let i = token._listeners.length;
3943
-
3944
- while (i-- > 0) {
3945
- token._listeners[i](cancel);
3946
- }
3947
- token._listeners = null;
3948
- });
3949
-
3950
- // eslint-disable-next-line func-names
3951
- this.promise.then = onfulfilled => {
3952
- let _resolve;
3953
- // eslint-disable-next-line func-names
3954
- const promise = new Promise(resolve => {
3955
- token.subscribe(resolve);
3956
- _resolve = resolve;
3957
- }).then(onfulfilled);
3958
-
3959
- promise.cancel = function reject() {
3960
- token.unsubscribe(_resolve);
3961
- };
3962
-
3963
- return promise;
3964
- };
3965
-
3966
- executor(function cancel(message, config, request) {
3967
- if (token.reason) {
3968
- // Cancellation has already been requested
3969
- return;
3970
- }
3971
-
3972
- token.reason = new CanceledError(message, config, request);
3973
- resolvePromise(token.reason);
3974
- });
3975
- }
3976
-
3977
- /**
3978
- * Throws a `CanceledError` if cancellation has been requested.
3979
- */
3980
- throwIfRequested() {
3981
- if (this.reason) {
3982
- throw this.reason;
3983
- }
3984
- }
3985
-
3986
- /**
3987
- * Subscribe to the cancel signal
3988
- */
3989
-
3990
- subscribe(listener) {
3991
- if (this.reason) {
3992
- listener(this.reason);
3993
- return;
3994
- }
3995
-
3996
- if (this._listeners) {
3997
- this._listeners.push(listener);
3998
- } else {
3999
- this._listeners = [listener];
4000
- }
4001
- }
4002
-
4003
- /**
4004
- * Unsubscribe from the cancel signal
4005
- */
4006
-
4007
- unsubscribe(listener) {
4008
- if (!this._listeners) {
4009
- return;
4010
- }
4011
- const index = this._listeners.indexOf(listener);
4012
- if (index !== -1) {
4013
- this._listeners.splice(index, 1);
4014
- }
4015
- }
4016
-
4017
- /**
4018
- * Returns an object that contains a new `CancelToken` and a function that, when called,
4019
- * cancels the `CancelToken`.
4020
- */
4021
- static source() {
4022
- let cancel;
4023
- const token = new CancelToken(function executor(c) {
4024
- cancel = c;
4025
- });
4026
- return {
4027
- token,
4028
- cancel
4029
- };
4030
- }
4031
- }
4032
-
4033
- var CancelToken$1 = CancelToken;
4034
-
4035
- /**
4036
- * Syntactic sugar for invoking a function and expanding an array for arguments.
4037
- *
4038
- * Common use case would be to use `Function.prototype.apply`.
4039
- *
4040
- * ```js
4041
- * function f(x, y, z) {}
4042
- * var args = [1, 2, 3];
4043
- * f.apply(null, args);
4044
- * ```
4045
- *
4046
- * With `spread` this example can be re-written.
4047
- *
4048
- * ```js
4049
- * spread(function(x, y, z) {})([1, 2, 3]);
4050
- * ```
4051
- *
4052
- * @param {Function} callback
4053
- *
4054
- * @returns {Function}
4055
- */
4056
- function spread(callback) {
4057
- return function wrap(arr) {
4058
- return callback.apply(null, arr);
4059
- };
4060
- }
4061
-
4062
- /**
4063
- * Determines whether the payload is an error thrown by Axios
4064
- *
4065
- * @param {*} payload The value to test
4066
- *
4067
- * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
4068
- */
4069
- function isAxiosError(payload) {
4070
- return utils.isObject(payload) && (payload.isAxiosError === true);
4071
- }
4072
-
4073
- const HttpStatusCode = {
4074
- Continue: 100,
4075
- SwitchingProtocols: 101,
4076
- Processing: 102,
4077
- EarlyHints: 103,
4078
- Ok: 200,
4079
- Created: 201,
4080
- Accepted: 202,
4081
- NonAuthoritativeInformation: 203,
4082
- NoContent: 204,
4083
- ResetContent: 205,
4084
- PartialContent: 206,
4085
- MultiStatus: 207,
4086
- AlreadyReported: 208,
4087
- ImUsed: 226,
4088
- MultipleChoices: 300,
4089
- MovedPermanently: 301,
4090
- Found: 302,
4091
- SeeOther: 303,
4092
- NotModified: 304,
4093
- UseProxy: 305,
4094
- Unused: 306,
4095
- TemporaryRedirect: 307,
4096
- PermanentRedirect: 308,
4097
- BadRequest: 400,
4098
- Unauthorized: 401,
4099
- PaymentRequired: 402,
4100
- Forbidden: 403,
4101
- NotFound: 404,
4102
- MethodNotAllowed: 405,
4103
- NotAcceptable: 406,
4104
- ProxyAuthenticationRequired: 407,
4105
- RequestTimeout: 408,
4106
- Conflict: 409,
4107
- Gone: 410,
4108
- LengthRequired: 411,
4109
- PreconditionFailed: 412,
4110
- PayloadTooLarge: 413,
4111
- UriTooLong: 414,
4112
- UnsupportedMediaType: 415,
4113
- RangeNotSatisfiable: 416,
4114
- ExpectationFailed: 417,
4115
- ImATeapot: 418,
4116
- MisdirectedRequest: 421,
4117
- UnprocessableEntity: 422,
4118
- Locked: 423,
4119
- FailedDependency: 424,
4120
- TooEarly: 425,
4121
- UpgradeRequired: 426,
4122
- PreconditionRequired: 428,
4123
- TooManyRequests: 429,
4124
- RequestHeaderFieldsTooLarge: 431,
4125
- UnavailableForLegalReasons: 451,
4126
- InternalServerError: 500,
4127
- NotImplemented: 501,
4128
- BadGateway: 502,
4129
- ServiceUnavailable: 503,
4130
- GatewayTimeout: 504,
4131
- HttpVersionNotSupported: 505,
4132
- VariantAlsoNegotiates: 506,
4133
- InsufficientStorage: 507,
4134
- LoopDetected: 508,
4135
- NotExtended: 510,
4136
- NetworkAuthenticationRequired: 511,
4137
- };
4138
-
4139
- Object.entries(HttpStatusCode).forEach(([key, value]) => {
4140
- HttpStatusCode[value] = key;
4141
- });
4142
-
4143
- var HttpStatusCode$1 = HttpStatusCode;
4144
-
4145
- /**
4146
- * Create an instance of Axios
4147
- *
4148
- * @param {Object} defaultConfig The default config for the instance
4149
- *
4150
- * @returns {Axios} A new instance of Axios
4151
- */
4152
- function createInstance(defaultConfig) {
4153
- const context = new Axios$1(defaultConfig);
4154
- const instance = bind(Axios$1.prototype.request, context);
4155
-
4156
- // Copy axios.prototype to instance
4157
- utils.extend(instance, Axios$1.prototype, context, {allOwnKeys: true});
4158
-
4159
- // Copy context to instance
4160
- utils.extend(instance, context, null, {allOwnKeys: true});
4161
-
4162
- // Factory for creating new instances
4163
- instance.create = function create(instanceConfig) {
4164
- return createInstance(mergeConfig(defaultConfig, instanceConfig));
4165
- };
4166
-
4167
- return instance;
24
+ n["default"] = e;
25
+ return Object.freeze(n);
4168
26
  }
4169
27
 
4170
- // Create the default instance to be exported
4171
- const axios = createInstance(defaults$1);
4172
-
4173
- // Expose Axios class to allow class inheritance
4174
- axios.Axios = Axios$1;
4175
-
4176
- // Expose Cancel & CancelToken
4177
- axios.CanceledError = CanceledError;
4178
- axios.CancelToken = CancelToken$1;
4179
- axios.isCancel = isCancel;
4180
- axios.VERSION = VERSION;
4181
- axios.toFormData = toFormData;
4182
-
4183
- // Expose AxiosError class
4184
- axios.AxiosError = AxiosError;
4185
-
4186
- // alias for CanceledError for backward compatibility
4187
- axios.Cancel = axios.CanceledError;
4188
-
4189
- // Expose all/spread
4190
- axios.all = function all(promises) {
4191
- return Promise.all(promises);
4192
- };
4193
-
4194
- axios.spread = spread;
4195
-
4196
- // Expose isAxiosError
4197
- axios.isAxiosError = isAxiosError;
4198
-
4199
- // Expose mergeConfig
4200
- axios.mergeConfig = mergeConfig;
4201
-
4202
- axios.AxiosHeaders = AxiosHeaders$1;
4203
-
4204
- axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
4205
-
4206
- axios.HttpStatusCode = HttpStatusCode$1;
4207
-
4208
- axios.default = axios;
4209
-
4210
- // this module should only have a default export
4211
- var axios$1 = axios;
28
+ var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
29
+ var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
4212
30
 
4213
31
  const NOTIFY_DISCORD_WEBHOOK_RAW_ID = 'notify_discord_webhook';
4214
32
  class NotifyDiscordWebhook {
@@ -4626,16 +444,16 @@ class DeNotifyClient {
4626
444
  url.searchParams.append(param, options.params[param]);
4627
445
  }
4628
446
  }
4629
- console.log(url.toString());
4630
447
  const payload = {
4631
448
  method,
4632
- url: url.toString(),
4633
449
  headers: this.headers
4634
450
  };
4635
451
  if (options.body)
4636
- payload.data = options.body;
4637
- const res = await axios$1(payload);
4638
- return res.data;
452
+ payload.body = JSON.stringify(options.body);
453
+ const res = await fetch__default["default"](url.toString(), payload);
454
+ if (!res.ok)
455
+ throw new Error(`unexpected response ${res.statusText}`);
456
+ return await res.json();
4639
457
  }
4640
458
  async getAbi(network, address) {
4641
459
  const ret = await this.request('get', `abi/${network}/${address}`);
@@ -4729,18 +547,18 @@ class AlertBuilder {
4729
547
  }
4730
548
 
4731
549
  var index$1 = /*#__PURE__*/Object.freeze({
4732
- __proto__: null,
4733
- Trigger: Trigger,
4734
- HandlerFunctionCallV2: HandlerFunctionCallV2,
4735
- HandlerFunctionCall: HandlerFunctionCall,
4736
- HandlerOnchainEvent: HandlerOnchainEvent
550
+ __proto__: null,
551
+ Trigger: Trigger,
552
+ HandlerFunctionCallV2: HandlerFunctionCallV2,
553
+ HandlerFunctionCall: HandlerFunctionCall,
554
+ HandlerOnchainEvent: HandlerOnchainEvent
4737
555
  });
4738
556
 
4739
557
  var index = /*#__PURE__*/Object.freeze({
4740
- __proto__: null,
4741
- NOTIFY_DISCORD_WEBHOOK_RAW_ID: NOTIFY_DISCORD_WEBHOOK_RAW_ID,
4742
- NotifyDiscordWebhook: NotifyDiscordWebhook,
4743
- Notification: Notification
558
+ __proto__: null,
559
+ NOTIFY_DISCORD_WEBHOOK_RAW_ID: NOTIFY_DISCORD_WEBHOOK_RAW_ID,
560
+ NotifyDiscordWebhook: NotifyDiscordWebhook,
561
+ Notification: Notification
4744
562
  });
4745
563
 
4746
564
  exports.AlertBuilder = AlertBuilder;