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