proto-sudoku-wc 0.0.485 → 0.0.486
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/proto-sudoku.cjs.entry.js +472 -2921
- package/dist/collection/utils/store.js +22 -16
- package/dist/esm/proto-sudoku.entry.js +472 -2921
- package/dist/proto-sudoku-wc/p-ebff75e1.entry.js +2 -0
- package/dist/proto-sudoku-wc/proto-sudoku-wc.esm.js +1 -1
- package/dist/types/utils/store.d.ts +1 -1
- package/package.json +2 -2
- package/dist/proto-sudoku-wc/p-5fac1fa8.entry.js +0 -1
@@ -246,2940 +246,485 @@ const createStore = (defaultState, shouldUpdate) => {
|
|
246
246
|
return map;
|
247
247
|
};
|
248
248
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
};
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
const {isArray} = Array;
|
280
|
-
|
281
|
-
/**
|
282
|
-
* Determine if a value is undefined
|
283
|
-
*
|
284
|
-
* @param {*} val The value to test
|
285
|
-
*
|
286
|
-
* @returns {boolean} True if the value is undefined, otherwise false
|
287
|
-
*/
|
288
|
-
const isUndefined = typeOfTest('undefined');
|
289
|
-
|
290
|
-
/**
|
291
|
-
* Determine if a value is a Buffer
|
292
|
-
*
|
293
|
-
* @param {*} val The value to test
|
294
|
-
*
|
295
|
-
* @returns {boolean} True if value is a Buffer, otherwise false
|
296
|
-
*/
|
297
|
-
function isBuffer(val) {
|
298
|
-
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
|
299
|
-
&& isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
300
|
-
}
|
301
|
-
|
302
|
-
/**
|
303
|
-
* Determine if a value is an ArrayBuffer
|
304
|
-
*
|
305
|
-
* @param {*} val The value to test
|
306
|
-
*
|
307
|
-
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
308
|
-
*/
|
309
|
-
const isArrayBuffer = kindOfTest('ArrayBuffer');
|
310
|
-
|
311
|
-
|
312
|
-
/**
|
313
|
-
* Determine if a value is a view on an ArrayBuffer
|
314
|
-
*
|
315
|
-
* @param {*} val The value to test
|
316
|
-
*
|
317
|
-
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
318
|
-
*/
|
319
|
-
function isArrayBufferView(val) {
|
320
|
-
let result;
|
321
|
-
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
322
|
-
result = ArrayBuffer.isView(val);
|
323
|
-
} else {
|
324
|
-
result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
|
325
|
-
}
|
326
|
-
return result;
|
327
|
-
}
|
328
|
-
|
329
|
-
/**
|
330
|
-
* Determine if a value is a String
|
331
|
-
*
|
332
|
-
* @param {*} val The value to test
|
333
|
-
*
|
334
|
-
* @returns {boolean} True if value is a String, otherwise false
|
335
|
-
*/
|
336
|
-
const isString = typeOfTest('string');
|
337
|
-
|
338
|
-
/**
|
339
|
-
* Determine if a value is a Function
|
340
|
-
*
|
341
|
-
* @param {*} val The value to test
|
342
|
-
* @returns {boolean} True if value is a Function, otherwise false
|
343
|
-
*/
|
344
|
-
const isFunction = typeOfTest('function');
|
345
|
-
|
346
|
-
/**
|
347
|
-
* Determine if a value is a Number
|
348
|
-
*
|
349
|
-
* @param {*} val The value to test
|
350
|
-
*
|
351
|
-
* @returns {boolean} True if value is a Number, otherwise false
|
352
|
-
*/
|
353
|
-
const isNumber = typeOfTest('number');
|
354
|
-
|
355
|
-
/**
|
356
|
-
* Determine if a value is an Object
|
357
|
-
*
|
358
|
-
* @param {*} thing The value to test
|
359
|
-
*
|
360
|
-
* @returns {boolean} True if value is an Object, otherwise false
|
361
|
-
*/
|
362
|
-
const isObject = (thing) => thing !== null && typeof thing === 'object';
|
363
|
-
|
364
|
-
/**
|
365
|
-
* Determine if a value is a Boolean
|
366
|
-
*
|
367
|
-
* @param {*} thing The value to test
|
368
|
-
* @returns {boolean} True if value is a Boolean, otherwise false
|
369
|
-
*/
|
370
|
-
const isBoolean = thing => thing === true || thing === false;
|
371
|
-
|
372
|
-
/**
|
373
|
-
* Determine if a value is a plain Object
|
374
|
-
*
|
375
|
-
* @param {*} val The value to test
|
376
|
-
*
|
377
|
-
* @returns {boolean} True if value is a plain Object, otherwise false
|
378
|
-
*/
|
379
|
-
const isPlainObject = (val) => {
|
380
|
-
if (kindOf(val) !== 'object') {
|
381
|
-
return false;
|
382
|
-
}
|
383
|
-
|
384
|
-
const prototype = getPrototypeOf(val);
|
385
|
-
return prototype === null || prototype === Object.prototype;
|
386
|
-
};
|
387
|
-
|
388
|
-
/**
|
389
|
-
* Determine if a value is a Date
|
390
|
-
*
|
391
|
-
* @param {*} val The value to test
|
392
|
-
*
|
393
|
-
* @returns {boolean} True if value is a Date, otherwise false
|
394
|
-
*/
|
395
|
-
const isDate = kindOfTest('Date');
|
396
|
-
|
397
|
-
/**
|
398
|
-
* Determine if a value is a File
|
399
|
-
*
|
400
|
-
* @param {*} val The value to test
|
401
|
-
*
|
402
|
-
* @returns {boolean} True if value is a File, otherwise false
|
403
|
-
*/
|
404
|
-
const isFile = kindOfTest('File');
|
405
|
-
|
406
|
-
/**
|
407
|
-
* Determine if a value is a Blob
|
408
|
-
*
|
409
|
-
* @param {*} val The value to test
|
410
|
-
*
|
411
|
-
* @returns {boolean} True if value is a Blob, otherwise false
|
412
|
-
*/
|
413
|
-
const isBlob = kindOfTest('Blob');
|
414
|
-
|
415
|
-
/**
|
416
|
-
* Determine if a value is a FileList
|
417
|
-
*
|
418
|
-
* @param {*} val The value to test
|
419
|
-
*
|
420
|
-
* @returns {boolean} True if value is a File, otherwise false
|
421
|
-
*/
|
422
|
-
const isFileList = kindOfTest('FileList');
|
423
|
-
|
424
|
-
/**
|
425
|
-
* Determine if a value is a Stream
|
426
|
-
*
|
427
|
-
* @param {*} val The value to test
|
428
|
-
*
|
429
|
-
* @returns {boolean} True if value is a Stream, otherwise false
|
430
|
-
*/
|
431
|
-
const isStream = (val) => isObject(val) && isFunction(val.pipe);
|
432
|
-
|
433
|
-
/**
|
434
|
-
* Determine if a value is a FormData
|
435
|
-
*
|
436
|
-
* @param {*} thing The value to test
|
437
|
-
*
|
438
|
-
* @returns {boolean} True if value is an FormData, otherwise false
|
439
|
-
*/
|
440
|
-
const isFormData = (thing) => {
|
441
|
-
const pattern = '[object FormData]';
|
442
|
-
return thing && (
|
443
|
-
(typeof FormData === 'function' && thing instanceof FormData) ||
|
444
|
-
toString.call(thing) === pattern ||
|
445
|
-
(isFunction(thing.toString) && thing.toString() === pattern)
|
446
|
-
);
|
447
|
-
};
|
448
|
-
|
449
|
-
/**
|
450
|
-
* Determine if a value is a URLSearchParams object
|
451
|
-
*
|
452
|
-
* @param {*} val The value to test
|
453
|
-
*
|
454
|
-
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
455
|
-
*/
|
456
|
-
const isURLSearchParams = kindOfTest('URLSearchParams');
|
457
|
-
|
458
|
-
/**
|
459
|
-
* Trim excess whitespace off the beginning and end of a string
|
460
|
-
*
|
461
|
-
* @param {String} str The String to trim
|
462
|
-
*
|
463
|
-
* @returns {String} The String freed of excess whitespace
|
464
|
-
*/
|
465
|
-
const trim = (str) => str.trim ?
|
466
|
-
str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
467
|
-
|
468
|
-
/**
|
469
|
-
* Iterate over an Array or an Object invoking a function for each item.
|
470
|
-
*
|
471
|
-
* If `obj` is an Array callback will be called passing
|
472
|
-
* the value, index, and complete array for each item.
|
473
|
-
*
|
474
|
-
* If 'obj' is an Object callback will be called passing
|
475
|
-
* the value, key, and complete object for each property.
|
476
|
-
*
|
477
|
-
* @param {Object|Array} obj The object to iterate
|
478
|
-
* @param {Function} fn The callback to invoke for each item
|
479
|
-
*
|
480
|
-
* @param {Boolean} [allOwnKeys = false]
|
481
|
-
* @returns {void}
|
482
|
-
*/
|
483
|
-
function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
484
|
-
// Don't bother if no value provided
|
485
|
-
if (obj === null || typeof obj === 'undefined') {
|
486
|
-
return;
|
487
|
-
}
|
488
|
-
|
489
|
-
let i;
|
490
|
-
let l;
|
491
|
-
|
492
|
-
// Force an array if not already something iterable
|
493
|
-
if (typeof obj !== 'object') {
|
494
|
-
/*eslint no-param-reassign:0*/
|
495
|
-
obj = [obj];
|
496
|
-
}
|
497
|
-
|
498
|
-
if (isArray(obj)) {
|
499
|
-
// Iterate over array values
|
500
|
-
for (i = 0, l = obj.length; i < l; i++) {
|
501
|
-
fn.call(null, obj[i], i, obj);
|
502
|
-
}
|
503
|
-
} else {
|
504
|
-
// Iterate over object keys
|
505
|
-
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
506
|
-
const len = keys.length;
|
507
|
-
let key;
|
508
|
-
|
509
|
-
for (i = 0; i < len; i++) {
|
510
|
-
key = keys[i];
|
511
|
-
fn.call(null, obj[key], key, obj);
|
512
|
-
}
|
513
|
-
}
|
514
|
-
}
|
515
|
-
|
516
|
-
/**
|
517
|
-
* Accepts varargs expecting each argument to be an object, then
|
518
|
-
* immutably merges the properties of each object and returns result.
|
519
|
-
*
|
520
|
-
* When multiple objects contain the same key the later object in
|
521
|
-
* the arguments list will take precedence.
|
522
|
-
*
|
523
|
-
* Example:
|
524
|
-
*
|
525
|
-
* ```js
|
526
|
-
* var result = merge({foo: 123}, {foo: 456});
|
527
|
-
* console.log(result.foo); // outputs 456
|
528
|
-
* ```
|
529
|
-
*
|
530
|
-
* @param {Object} obj1 Object to merge
|
531
|
-
*
|
532
|
-
* @returns {Object} Result of all merge properties
|
533
|
-
*/
|
534
|
-
function merge(/* obj1, obj2, obj3, ... */) {
|
535
|
-
const result = {};
|
536
|
-
const assignValue = (val, key) => {
|
537
|
-
if (isPlainObject(result[key]) && isPlainObject(val)) {
|
538
|
-
result[key] = merge(result[key], val);
|
539
|
-
} else if (isPlainObject(val)) {
|
540
|
-
result[key] = merge({}, val);
|
541
|
-
} else if (isArray(val)) {
|
542
|
-
result[key] = val.slice();
|
543
|
-
} else {
|
544
|
-
result[key] = val;
|
545
|
-
}
|
546
|
-
};
|
547
|
-
|
548
|
-
for (let i = 0, l = arguments.length; i < l; i++) {
|
549
|
-
arguments[i] && forEach(arguments[i], assignValue);
|
550
|
-
}
|
551
|
-
return result;
|
552
|
-
}
|
553
|
-
|
554
|
-
/**
|
555
|
-
* Extends object a by mutably adding to it the properties of object b.
|
556
|
-
*
|
557
|
-
* @param {Object} a The object to be extended
|
558
|
-
* @param {Object} b The object to copy properties from
|
559
|
-
* @param {Object} thisArg The object to bind function to
|
560
|
-
*
|
561
|
-
* @param {Boolean} [allOwnKeys]
|
562
|
-
* @returns {Object} The resulting value of object a
|
563
|
-
*/
|
564
|
-
const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
|
565
|
-
forEach(b, (val, key) => {
|
566
|
-
if (thisArg && isFunction(val)) {
|
567
|
-
a[key] = bind(val, thisArg);
|
568
|
-
} else {
|
569
|
-
a[key] = val;
|
570
|
-
}
|
571
|
-
}, {allOwnKeys});
|
572
|
-
return a;
|
573
|
-
};
|
574
|
-
|
575
|
-
/**
|
576
|
-
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
577
|
-
*
|
578
|
-
* @param {string} content with BOM
|
579
|
-
*
|
580
|
-
* @returns {string} content value without BOM
|
581
|
-
*/
|
582
|
-
const stripBOM = (content) => {
|
583
|
-
if (content.charCodeAt(0) === 0xFEFF) {
|
584
|
-
content = content.slice(1);
|
585
|
-
}
|
586
|
-
return content;
|
587
|
-
};
|
588
|
-
|
589
|
-
/**
|
590
|
-
* Inherit the prototype methods from one constructor into another
|
591
|
-
* @param {function} constructor
|
592
|
-
* @param {function} superConstructor
|
593
|
-
* @param {object} [props]
|
594
|
-
* @param {object} [descriptors]
|
595
|
-
*
|
596
|
-
* @returns {void}
|
597
|
-
*/
|
598
|
-
const inherits = (constructor, superConstructor, props, descriptors) => {
|
599
|
-
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
600
|
-
constructor.prototype.constructor = constructor;
|
601
|
-
Object.defineProperty(constructor, 'super', {
|
602
|
-
value: superConstructor.prototype
|
603
|
-
});
|
604
|
-
props && Object.assign(constructor.prototype, props);
|
605
|
-
};
|
606
|
-
|
607
|
-
/**
|
608
|
-
* Resolve object with deep prototype chain to a flat object
|
609
|
-
* @param {Object} sourceObj source object
|
610
|
-
* @param {Object} [destObj]
|
611
|
-
* @param {Function|Boolean} [filter]
|
612
|
-
* @param {Function} [propFilter]
|
613
|
-
*
|
614
|
-
* @returns {Object}
|
615
|
-
*/
|
616
|
-
const toFlatObject = (sourceObj, destObj, filter, propFilter) => {
|
617
|
-
let props;
|
618
|
-
let i;
|
619
|
-
let prop;
|
620
|
-
const merged = {};
|
621
|
-
|
622
|
-
destObj = destObj || {};
|
623
|
-
// eslint-disable-next-line no-eq-null,eqeqeq
|
624
|
-
if (sourceObj == null) return destObj;
|
625
|
-
|
626
|
-
do {
|
627
|
-
props = Object.getOwnPropertyNames(sourceObj);
|
628
|
-
i = props.length;
|
629
|
-
while (i-- > 0) {
|
630
|
-
prop = props[i];
|
631
|
-
if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
|
632
|
-
destObj[prop] = sourceObj[prop];
|
633
|
-
merged[prop] = true;
|
634
|
-
}
|
635
|
-
}
|
636
|
-
sourceObj = filter !== false && getPrototypeOf(sourceObj);
|
637
|
-
} while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
638
|
-
|
639
|
-
return destObj;
|
640
|
-
};
|
641
|
-
|
642
|
-
/**
|
643
|
-
* Determines whether a string ends with the characters of a specified string
|
644
|
-
*
|
645
|
-
* @param {String} str
|
646
|
-
* @param {String} searchString
|
647
|
-
* @param {Number} [position= 0]
|
648
|
-
*
|
649
|
-
* @returns {boolean}
|
650
|
-
*/
|
651
|
-
const endsWith = (str, searchString, position) => {
|
652
|
-
str = String(str);
|
653
|
-
if (position === undefined || position > str.length) {
|
654
|
-
position = str.length;
|
655
|
-
}
|
656
|
-
position -= searchString.length;
|
657
|
-
const lastIndex = str.indexOf(searchString, position);
|
658
|
-
return lastIndex !== -1 && lastIndex === position;
|
659
|
-
};
|
660
|
-
|
661
|
-
|
662
|
-
/**
|
663
|
-
* Returns new array from array like object or null if failed
|
664
|
-
*
|
665
|
-
* @param {*} [thing]
|
666
|
-
*
|
667
|
-
* @returns {?Array}
|
668
|
-
*/
|
669
|
-
const toArray = (thing) => {
|
670
|
-
if (!thing) return null;
|
671
|
-
if (isArray(thing)) return thing;
|
672
|
-
let i = thing.length;
|
673
|
-
if (!isNumber(i)) return null;
|
674
|
-
const arr = new Array(i);
|
675
|
-
while (i-- > 0) {
|
676
|
-
arr[i] = thing[i];
|
677
|
-
}
|
678
|
-
return arr;
|
679
|
-
};
|
680
|
-
|
681
|
-
/**
|
682
|
-
* Checking if the Uint8Array exists and if it does, it returns a function that checks if the
|
683
|
-
* thing passed in is an instance of Uint8Array
|
684
|
-
*
|
685
|
-
* @param {TypedArray}
|
686
|
-
*
|
687
|
-
* @returns {Array}
|
688
|
-
*/
|
689
|
-
// eslint-disable-next-line func-names
|
690
|
-
const isTypedArray = (TypedArray => {
|
691
|
-
// eslint-disable-next-line func-names
|
692
|
-
return thing => {
|
693
|
-
return TypedArray && thing instanceof TypedArray;
|
694
|
-
};
|
695
|
-
})(typeof Uint8Array !== 'undefined' && getPrototypeOf(Uint8Array));
|
696
|
-
|
697
|
-
/**
|
698
|
-
* For each entry in the object, call the function with the key and value.
|
699
|
-
*
|
700
|
-
* @param {Object<any, any>} obj - The object to iterate over.
|
701
|
-
* @param {Function} fn - The function to call for each entry.
|
702
|
-
*
|
703
|
-
* @returns {void}
|
704
|
-
*/
|
705
|
-
const forEachEntry = (obj, fn) => {
|
706
|
-
const generator = obj && obj[Symbol.iterator];
|
707
|
-
|
708
|
-
const iterator = generator.call(obj);
|
709
|
-
|
710
|
-
let result;
|
711
|
-
|
712
|
-
while ((result = iterator.next()) && !result.done) {
|
713
|
-
const pair = result.value;
|
714
|
-
fn.call(obj, pair[0], pair[1]);
|
715
|
-
}
|
716
|
-
};
|
717
|
-
|
718
|
-
/**
|
719
|
-
* It takes a regular expression and a string, and returns an array of all the matches
|
720
|
-
*
|
721
|
-
* @param {string} regExp - The regular expression to match against.
|
722
|
-
* @param {string} str - The string to search.
|
723
|
-
*
|
724
|
-
* @returns {Array<boolean>}
|
725
|
-
*/
|
726
|
-
const matchAll = (regExp, str) => {
|
727
|
-
let matches;
|
728
|
-
const arr = [];
|
729
|
-
|
730
|
-
while ((matches = regExp.exec(str)) !== null) {
|
731
|
-
arr.push(matches);
|
732
|
-
}
|
733
|
-
|
734
|
-
return arr;
|
735
|
-
};
|
736
|
-
|
737
|
-
/* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */
|
738
|
-
const isHTMLForm = kindOfTest('HTMLFormElement');
|
739
|
-
|
740
|
-
const toCamelCase = str => {
|
741
|
-
return str.toLowerCase().replace(/[_-\s]([a-z\d])(\w*)/g,
|
742
|
-
function replacer(m, p1, p2) {
|
743
|
-
return p1.toUpperCase() + p2;
|
744
|
-
}
|
745
|
-
);
|
746
|
-
};
|
747
|
-
|
748
|
-
/* Creating a function that will check if an object has a property. */
|
749
|
-
const hasOwnProperty = (({hasOwnProperty}) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);
|
750
|
-
|
751
|
-
/**
|
752
|
-
* Determine if a value is a RegExp object
|
753
|
-
*
|
754
|
-
* @param {*} val The value to test
|
755
|
-
*
|
756
|
-
* @returns {boolean} True if value is a RegExp object, otherwise false
|
757
|
-
*/
|
758
|
-
const isRegExp = kindOfTest('RegExp');
|
759
|
-
|
760
|
-
const reduceDescriptors = (obj, reducer) => {
|
761
|
-
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
762
|
-
const reducedDescriptors = {};
|
763
|
-
|
764
|
-
forEach(descriptors, (descriptor, name) => {
|
765
|
-
if (reducer(descriptor, name, obj) !== false) {
|
766
|
-
reducedDescriptors[name] = descriptor;
|
767
|
-
}
|
768
|
-
});
|
769
|
-
|
770
|
-
Object.defineProperties(obj, reducedDescriptors);
|
771
|
-
};
|
772
|
-
|
773
|
-
/**
|
774
|
-
* Makes all methods read-only
|
775
|
-
* @param {Object} obj
|
776
|
-
*/
|
777
|
-
|
778
|
-
const freezeMethods = (obj) => {
|
779
|
-
reduceDescriptors(obj, (descriptor, name) => {
|
780
|
-
const value = obj[name];
|
781
|
-
|
782
|
-
if (!isFunction(value)) return;
|
783
|
-
|
784
|
-
descriptor.enumerable = false;
|
785
|
-
|
786
|
-
if ('writable' in descriptor) {
|
787
|
-
descriptor.writable = false;
|
788
|
-
return;
|
789
|
-
}
|
790
|
-
|
791
|
-
if (!descriptor.set) {
|
792
|
-
descriptor.set = () => {
|
793
|
-
throw Error('Can not read-only method \'' + name + '\'');
|
794
|
-
};
|
795
|
-
}
|
796
|
-
});
|
797
|
-
};
|
798
|
-
|
799
|
-
const toObjectSet = (arrayOrString, delimiter) => {
|
800
|
-
const obj = {};
|
801
|
-
|
802
|
-
const define = (arr) => {
|
803
|
-
arr.forEach(value => {
|
804
|
-
obj[value] = true;
|
805
|
-
});
|
806
|
-
};
|
807
|
-
|
808
|
-
isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
|
809
|
-
|
810
|
-
return obj;
|
811
|
-
};
|
812
|
-
|
813
|
-
const noop = () => {};
|
814
|
-
|
815
|
-
const toFiniteNumber = (value, defaultValue) => {
|
816
|
-
value = +value;
|
817
|
-
return Number.isFinite(value) ? value : defaultValue;
|
818
|
-
};
|
819
|
-
|
820
|
-
const utils = {
|
821
|
-
isArray,
|
822
|
-
isArrayBuffer,
|
823
|
-
isBuffer,
|
824
|
-
isFormData,
|
825
|
-
isArrayBufferView,
|
826
|
-
isString,
|
827
|
-
isNumber,
|
828
|
-
isBoolean,
|
829
|
-
isObject,
|
830
|
-
isPlainObject,
|
831
|
-
isUndefined,
|
832
|
-
isDate,
|
833
|
-
isFile,
|
834
|
-
isBlob,
|
835
|
-
isRegExp,
|
836
|
-
isFunction,
|
837
|
-
isStream,
|
838
|
-
isURLSearchParams,
|
839
|
-
isTypedArray,
|
840
|
-
isFileList,
|
841
|
-
forEach,
|
842
|
-
merge,
|
843
|
-
extend,
|
844
|
-
trim,
|
845
|
-
stripBOM,
|
846
|
-
inherits,
|
847
|
-
toFlatObject,
|
848
|
-
kindOf,
|
849
|
-
kindOfTest,
|
850
|
-
endsWith,
|
851
|
-
toArray,
|
852
|
-
forEachEntry,
|
853
|
-
matchAll,
|
854
|
-
isHTMLForm,
|
855
|
-
hasOwnProperty,
|
856
|
-
hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
|
857
|
-
reduceDescriptors,
|
858
|
-
freezeMethods,
|
859
|
-
toObjectSet,
|
860
|
-
toCamelCase,
|
861
|
-
noop,
|
862
|
-
toFiniteNumber
|
863
|
-
};
|
864
|
-
|
865
|
-
/**
|
866
|
-
* Create an Error with the specified message, config, error code, request and response.
|
867
|
-
*
|
868
|
-
* @param {string} message The error message.
|
869
|
-
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
870
|
-
* @param {Object} [config] The config.
|
871
|
-
* @param {Object} [request] The request.
|
872
|
-
* @param {Object} [response] The response.
|
873
|
-
*
|
874
|
-
* @returns {Error} The created error.
|
875
|
-
*/
|
876
|
-
function AxiosError(message, code, config, request, response) {
|
877
|
-
Error.call(this);
|
878
|
-
|
879
|
-
if (Error.captureStackTrace) {
|
880
|
-
Error.captureStackTrace(this, this.constructor);
|
881
|
-
} else {
|
882
|
-
this.stack = (new Error()).stack;
|
883
|
-
}
|
884
|
-
|
885
|
-
this.message = message;
|
886
|
-
this.name = 'AxiosError';
|
887
|
-
code && (this.code = code);
|
888
|
-
config && (this.config = config);
|
889
|
-
request && (this.request = request);
|
890
|
-
response && (this.response = response);
|
891
|
-
}
|
892
|
-
|
893
|
-
utils.inherits(AxiosError, Error, {
|
894
|
-
toJSON: function toJSON() {
|
895
|
-
return {
|
896
|
-
// Standard
|
897
|
-
message: this.message,
|
898
|
-
name: this.name,
|
899
|
-
// Microsoft
|
900
|
-
description: this.description,
|
901
|
-
number: this.number,
|
902
|
-
// Mozilla
|
903
|
-
fileName: this.fileName,
|
904
|
-
lineNumber: this.lineNumber,
|
905
|
-
columnNumber: this.columnNumber,
|
906
|
-
stack: this.stack,
|
907
|
-
// Axios
|
908
|
-
config: this.config,
|
909
|
-
code: this.code,
|
910
|
-
status: this.response && this.response.status ? this.response.status : null
|
911
|
-
};
|
912
|
-
}
|
913
|
-
});
|
914
|
-
|
915
|
-
const prototype$1 = AxiosError.prototype;
|
916
|
-
const descriptors = {};
|
917
|
-
|
918
|
-
[
|
919
|
-
'ERR_BAD_OPTION_VALUE',
|
920
|
-
'ERR_BAD_OPTION',
|
921
|
-
'ECONNABORTED',
|
922
|
-
'ETIMEDOUT',
|
923
|
-
'ERR_NETWORK',
|
924
|
-
'ERR_FR_TOO_MANY_REDIRECTS',
|
925
|
-
'ERR_DEPRECATED',
|
926
|
-
'ERR_BAD_RESPONSE',
|
927
|
-
'ERR_BAD_REQUEST',
|
928
|
-
'ERR_CANCELED',
|
929
|
-
'ERR_NOT_SUPPORT',
|
930
|
-
'ERR_INVALID_URL'
|
931
|
-
// eslint-disable-next-line func-names
|
932
|
-
].forEach(code => {
|
933
|
-
descriptors[code] = {value: code};
|
934
|
-
});
|
935
|
-
|
936
|
-
Object.defineProperties(AxiosError, descriptors);
|
937
|
-
Object.defineProperty(prototype$1, 'isAxiosError', {value: true});
|
938
|
-
|
939
|
-
// eslint-disable-next-line func-names
|
940
|
-
AxiosError.from = (error, code, config, request, response, customProps) => {
|
941
|
-
const axiosError = Object.create(prototype$1);
|
942
|
-
|
943
|
-
utils.toFlatObject(error, axiosError, function filter(obj) {
|
944
|
-
return obj !== Error.prototype;
|
945
|
-
}, prop => {
|
946
|
-
return prop !== 'isAxiosError';
|
947
|
-
});
|
948
|
-
|
949
|
-
AxiosError.call(axiosError, error.message, code, config, request, response);
|
950
|
-
|
951
|
-
axiosError.cause = error;
|
952
|
-
|
953
|
-
axiosError.name = error.name;
|
954
|
-
|
955
|
-
customProps && Object.assign(axiosError, customProps);
|
956
|
-
|
957
|
-
return axiosError;
|
958
|
-
};
|
959
|
-
|
960
|
-
/* eslint-env browser */
|
961
|
-
var browser = typeof self == 'object' ? self.FormData : window.FormData;
|
962
|
-
|
963
|
-
/**
|
964
|
-
* Determines if the given thing is a array or js object.
|
965
|
-
*
|
966
|
-
* @param {string} thing - The object or array to be visited.
|
967
|
-
*
|
968
|
-
* @returns {boolean}
|
969
|
-
*/
|
970
|
-
function isVisitable(thing) {
|
971
|
-
return utils.isPlainObject(thing) || utils.isArray(thing);
|
972
|
-
}
|
973
|
-
|
974
|
-
/**
|
975
|
-
* It removes the brackets from the end of a string
|
976
|
-
*
|
977
|
-
* @param {string} key - The key of the parameter.
|
978
|
-
*
|
979
|
-
* @returns {string} the key without the brackets.
|
980
|
-
*/
|
981
|
-
function removeBrackets(key) {
|
982
|
-
return utils.endsWith(key, '[]') ? key.slice(0, -2) : key;
|
983
|
-
}
|
984
|
-
|
985
|
-
/**
|
986
|
-
* It takes a path, a key, and a boolean, and returns a string
|
987
|
-
*
|
988
|
-
* @param {string} path - The path to the current key.
|
989
|
-
* @param {string} key - The key of the current object being iterated over.
|
990
|
-
* @param {string} dots - If true, the key will be rendered with dots instead of brackets.
|
991
|
-
*
|
992
|
-
* @returns {string} The path to the current key.
|
993
|
-
*/
|
994
|
-
function renderKey(path, key, dots) {
|
995
|
-
if (!path) return key;
|
996
|
-
return path.concat(key).map(function each(token, i) {
|
997
|
-
// eslint-disable-next-line no-param-reassign
|
998
|
-
token = removeBrackets(token);
|
999
|
-
return !dots && i ? '[' + token + ']' : token;
|
1000
|
-
}).join(dots ? '.' : '');
|
1001
|
-
}
|
1002
|
-
|
1003
|
-
/**
|
1004
|
-
* If the array is an array and none of its elements are visitable, then it's a flat array.
|
1005
|
-
*
|
1006
|
-
* @param {Array<any>} arr - The array to check
|
1007
|
-
*
|
1008
|
-
* @returns {boolean}
|
1009
|
-
*/
|
1010
|
-
function isFlatArray(arr) {
|
1011
|
-
return utils.isArray(arr) && !arr.some(isVisitable);
|
1012
|
-
}
|
1013
|
-
|
1014
|
-
const predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
|
1015
|
-
return /^is[A-Z]/.test(prop);
|
1016
|
-
});
|
1017
|
-
|
1018
|
-
/**
|
1019
|
-
* If the thing is a FormData object, return true, otherwise return false.
|
1020
|
-
*
|
1021
|
-
* @param {unknown} thing - The thing to check.
|
1022
|
-
*
|
1023
|
-
* @returns {boolean}
|
1024
|
-
*/
|
1025
|
-
function isSpecCompliant(thing) {
|
1026
|
-
return thing && utils.isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator];
|
1027
|
-
}
|
1028
|
-
|
1029
|
-
/**
|
1030
|
-
* Convert a data object to FormData
|
1031
|
-
*
|
1032
|
-
* @param {Object} obj
|
1033
|
-
* @param {?Object} [formData]
|
1034
|
-
* @param {?Object} [options]
|
1035
|
-
* @param {Function} [options.visitor]
|
1036
|
-
* @param {Boolean} [options.metaTokens = true]
|
1037
|
-
* @param {Boolean} [options.dots = false]
|
1038
|
-
* @param {?Boolean} [options.indexes = false]
|
1039
|
-
*
|
1040
|
-
* @returns {Object}
|
1041
|
-
**/
|
1042
|
-
|
1043
|
-
/**
|
1044
|
-
* It converts an object into a FormData object
|
1045
|
-
*
|
1046
|
-
* @param {Object<any, any>} obj - The object to convert to form data.
|
1047
|
-
* @param {string} formData - The FormData object to append to.
|
1048
|
-
* @param {Object<string, any>} options
|
1049
|
-
*
|
1050
|
-
* @returns
|
1051
|
-
*/
|
1052
|
-
function toFormData(obj, formData, options) {
|
1053
|
-
if (!utils.isObject(obj)) {
|
1054
|
-
throw new TypeError('target must be an object');
|
1055
|
-
}
|
1056
|
-
|
1057
|
-
// eslint-disable-next-line no-param-reassign
|
1058
|
-
formData = formData || new (browser || FormData)();
|
1059
|
-
|
1060
|
-
// eslint-disable-next-line no-param-reassign
|
1061
|
-
options = utils.toFlatObject(options, {
|
1062
|
-
metaTokens: true,
|
1063
|
-
dots: false,
|
1064
|
-
indexes: false
|
1065
|
-
}, false, function defined(option, source) {
|
1066
|
-
// eslint-disable-next-line no-eq-null,eqeqeq
|
1067
|
-
return !utils.isUndefined(source[option]);
|
1068
|
-
});
|
1069
|
-
|
1070
|
-
const metaTokens = options.metaTokens;
|
1071
|
-
// eslint-disable-next-line no-use-before-define
|
1072
|
-
const visitor = options.visitor || defaultVisitor;
|
1073
|
-
const dots = options.dots;
|
1074
|
-
const indexes = options.indexes;
|
1075
|
-
const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
|
1076
|
-
const useBlob = _Blob && isSpecCompliant(formData);
|
1077
|
-
|
1078
|
-
if (!utils.isFunction(visitor)) {
|
1079
|
-
throw new TypeError('visitor must be a function');
|
1080
|
-
}
|
1081
|
-
|
1082
|
-
function convertValue(value) {
|
1083
|
-
if (value === null) return '';
|
1084
|
-
|
1085
|
-
if (utils.isDate(value)) {
|
1086
|
-
return value.toISOString();
|
1087
|
-
}
|
1088
|
-
|
1089
|
-
if (!useBlob && utils.isBlob(value)) {
|
1090
|
-
throw new AxiosError('Blob is not supported. Use a Buffer instead.');
|
1091
|
-
}
|
1092
|
-
|
1093
|
-
if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) {
|
1094
|
-
return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
|
1095
|
-
}
|
1096
|
-
|
1097
|
-
return value;
|
1098
|
-
}
|
1099
|
-
|
1100
|
-
/**
|
1101
|
-
* Default visitor.
|
1102
|
-
*
|
1103
|
-
* @param {*} value
|
1104
|
-
* @param {String|Number} key
|
1105
|
-
* @param {Array<String|Number>} path
|
1106
|
-
* @this {FormData}
|
1107
|
-
*
|
1108
|
-
* @returns {boolean} return true to visit the each prop of the value recursively
|
1109
|
-
*/
|
1110
|
-
function defaultVisitor(value, key, path) {
|
1111
|
-
let arr = value;
|
1112
|
-
|
1113
|
-
if (value && !path && typeof value === 'object') {
|
1114
|
-
if (utils.endsWith(key, '{}')) {
|
1115
|
-
// eslint-disable-next-line no-param-reassign
|
1116
|
-
key = metaTokens ? key : key.slice(0, -2);
|
1117
|
-
// eslint-disable-next-line no-param-reassign
|
1118
|
-
value = JSON.stringify(value);
|
1119
|
-
} else if (
|
1120
|
-
(utils.isArray(value) && isFlatArray(value)) ||
|
1121
|
-
(utils.isFileList(value) || utils.endsWith(key, '[]') && (arr = utils.toArray(value))
|
1122
|
-
)) {
|
1123
|
-
// eslint-disable-next-line no-param-reassign
|
1124
|
-
key = removeBrackets(key);
|
1125
|
-
|
1126
|
-
arr.forEach(function each(el, index) {
|
1127
|
-
!utils.isUndefined(el) && formData.append(
|
1128
|
-
// eslint-disable-next-line no-nested-ternary
|
1129
|
-
indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),
|
1130
|
-
convertValue(el)
|
1131
|
-
);
|
1132
|
-
});
|
1133
|
-
return false;
|
1134
|
-
}
|
1135
|
-
}
|
1136
|
-
|
1137
|
-
if (isVisitable(value)) {
|
1138
|
-
return true;
|
1139
|
-
}
|
1140
|
-
|
1141
|
-
formData.append(renderKey(path, key, dots), convertValue(value));
|
1142
|
-
|
1143
|
-
return false;
|
1144
|
-
}
|
1145
|
-
|
1146
|
-
const stack = [];
|
1147
|
-
|
1148
|
-
const exposedHelpers = Object.assign(predicates, {
|
1149
|
-
defaultVisitor,
|
1150
|
-
convertValue,
|
1151
|
-
isVisitable
|
1152
|
-
});
|
1153
|
-
|
1154
|
-
function build(value, path) {
|
1155
|
-
if (utils.isUndefined(value)) return;
|
1156
|
-
|
1157
|
-
if (stack.indexOf(value) !== -1) {
|
1158
|
-
throw Error('Circular reference detected in ' + path.join('.'));
|
1159
|
-
}
|
1160
|
-
|
1161
|
-
stack.push(value);
|
1162
|
-
|
1163
|
-
utils.forEach(value, function each(el, key) {
|
1164
|
-
const result = !utils.isUndefined(el) && visitor.call(
|
1165
|
-
formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers
|
1166
|
-
);
|
1167
|
-
|
1168
|
-
if (result === true) {
|
1169
|
-
build(el, path ? path.concat(key) : [key]);
|
1170
|
-
}
|
1171
|
-
});
|
1172
|
-
|
1173
|
-
stack.pop();
|
1174
|
-
}
|
1175
|
-
|
1176
|
-
if (!utils.isObject(obj)) {
|
1177
|
-
throw new TypeError('data must be an object');
|
1178
|
-
}
|
1179
|
-
|
1180
|
-
build(obj);
|
1181
|
-
|
1182
|
-
return formData;
|
1183
|
-
}
|
1184
|
-
|
1185
|
-
/**
|
1186
|
-
* It encodes a string by replacing all characters that are not in the unreserved set with
|
1187
|
-
* their percent-encoded equivalents
|
1188
|
-
*
|
1189
|
-
* @param {string} str - The string to encode.
|
1190
|
-
*
|
1191
|
-
* @returns {string} The encoded string.
|
1192
|
-
*/
|
1193
|
-
function encode$1(str) {
|
1194
|
-
const charMap = {
|
1195
|
-
'!': '%21',
|
1196
|
-
"'": '%27',
|
1197
|
-
'(': '%28',
|
1198
|
-
')': '%29',
|
1199
|
-
'~': '%7E',
|
1200
|
-
'%20': '+',
|
1201
|
-
'%00': '\x00'
|
1202
|
-
};
|
1203
|
-
return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
|
1204
|
-
return charMap[match];
|
1205
|
-
});
|
1206
|
-
}
|
1207
|
-
|
1208
|
-
/**
|
1209
|
-
* It takes a params object and converts it to a FormData object
|
1210
|
-
*
|
1211
|
-
* @param {Object<string, any>} params - The parameters to be converted to a FormData object.
|
1212
|
-
* @param {Object<string, any>} options - The options object passed to the Axios constructor.
|
1213
|
-
*
|
1214
|
-
* @returns {void}
|
1215
|
-
*/
|
1216
|
-
function AxiosURLSearchParams(params, options) {
|
1217
|
-
this._pairs = [];
|
1218
|
-
|
1219
|
-
params && toFormData(params, this, options);
|
1220
|
-
}
|
1221
|
-
|
1222
|
-
const prototype = AxiosURLSearchParams.prototype;
|
1223
|
-
|
1224
|
-
prototype.append = function append(name, value) {
|
1225
|
-
this._pairs.push([name, value]);
|
1226
|
-
};
|
1227
|
-
|
1228
|
-
prototype.toString = function toString(encoder) {
|
1229
|
-
const _encode = encoder ? function(value) {
|
1230
|
-
return encoder.call(this, value, encode$1);
|
1231
|
-
} : encode$1;
|
1232
|
-
|
1233
|
-
return this._pairs.map(function each(pair) {
|
1234
|
-
return _encode(pair[0]) + '=' + _encode(pair[1]);
|
1235
|
-
}, '').join('&');
|
1236
|
-
};
|
1237
|
-
|
1238
|
-
/**
|
1239
|
-
* It replaces all instances of the characters `:`, `$`, `,`, `+`, `[`, and `]` with their
|
1240
|
-
* URI encoded counterparts
|
1241
|
-
*
|
1242
|
-
* @param {string} val The value to be encoded.
|
1243
|
-
*
|
1244
|
-
* @returns {string} The encoded value.
|
1245
|
-
*/
|
1246
|
-
function encode(val) {
|
1247
|
-
return encodeURIComponent(val).
|
1248
|
-
replace(/%3A/gi, ':').
|
1249
|
-
replace(/%24/g, '$').
|
1250
|
-
replace(/%2C/gi, ',').
|
1251
|
-
replace(/%20/g, '+').
|
1252
|
-
replace(/%5B/gi, '[').
|
1253
|
-
replace(/%5D/gi, ']');
|
1254
|
-
}
|
1255
|
-
|
1256
|
-
/**
|
1257
|
-
* Build a URL by appending params to the end
|
1258
|
-
*
|
1259
|
-
* @param {string} url The base of the url (e.g., http://www.google.com)
|
1260
|
-
* @param {object} [params] The params to be appended
|
1261
|
-
* @param {?object} options
|
1262
|
-
*
|
1263
|
-
* @returns {string} The formatted url
|
1264
|
-
*/
|
1265
|
-
function buildURL(url, params, options) {
|
1266
|
-
/*eslint no-param-reassign:0*/
|
1267
|
-
if (!params) {
|
1268
|
-
return url;
|
1269
|
-
}
|
1270
|
-
|
1271
|
-
const hashmarkIndex = url.indexOf('#');
|
1272
|
-
|
1273
|
-
if (hashmarkIndex !== -1) {
|
1274
|
-
url = url.slice(0, hashmarkIndex);
|
1275
|
-
}
|
1276
|
-
|
1277
|
-
const _encode = options && options.encode || encode;
|
1278
|
-
|
1279
|
-
const serializerParams = utils.isURLSearchParams(params) ?
|
1280
|
-
params.toString() :
|
1281
|
-
new AxiosURLSearchParams(params, options).toString(_encode);
|
1282
|
-
|
1283
|
-
if (serializerParams) {
|
1284
|
-
url += (url.indexOf('?') === -1 ? '?' : '&') + serializerParams;
|
1285
|
-
}
|
1286
|
-
|
1287
|
-
return url;
|
1288
|
-
}
|
1289
|
-
|
1290
|
-
class InterceptorManager {
|
1291
|
-
constructor() {
|
1292
|
-
this.handlers = [];
|
1293
|
-
}
|
1294
|
-
|
1295
|
-
/**
|
1296
|
-
* Add a new interceptor to the stack
|
1297
|
-
*
|
1298
|
-
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
1299
|
-
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
1300
|
-
*
|
1301
|
-
* @return {Number} An ID used to remove interceptor later
|
1302
|
-
*/
|
1303
|
-
use(fulfilled, rejected, options) {
|
1304
|
-
this.handlers.push({
|
1305
|
-
fulfilled,
|
1306
|
-
rejected,
|
1307
|
-
synchronous: options ? options.synchronous : false,
|
1308
|
-
runWhen: options ? options.runWhen : null
|
1309
|
-
});
|
1310
|
-
return this.handlers.length - 1;
|
1311
|
-
}
|
1312
|
-
|
1313
|
-
/**
|
1314
|
-
* Remove an interceptor from the stack
|
1315
|
-
*
|
1316
|
-
* @param {Number} id The ID that was returned by `use`
|
1317
|
-
*
|
1318
|
-
* @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
|
1319
|
-
*/
|
1320
|
-
eject(id) {
|
1321
|
-
if (this.handlers[id]) {
|
1322
|
-
this.handlers[id] = null;
|
1323
|
-
}
|
1324
|
-
}
|
1325
|
-
|
1326
|
-
/**
|
1327
|
-
* Clear all interceptors from the stack
|
1328
|
-
*
|
1329
|
-
* @returns {void}
|
1330
|
-
*/
|
1331
|
-
clear() {
|
1332
|
-
if (this.handlers) {
|
1333
|
-
this.handlers = [];
|
1334
|
-
}
|
1335
|
-
}
|
1336
|
-
|
1337
|
-
/**
|
1338
|
-
* Iterate over all the registered interceptors
|
1339
|
-
*
|
1340
|
-
* This method is particularly useful for skipping over any
|
1341
|
-
* interceptors that may have become `null` calling `eject`.
|
1342
|
-
*
|
1343
|
-
* @param {Function} fn The function to call for each interceptor
|
1344
|
-
*
|
1345
|
-
* @returns {void}
|
1346
|
-
*/
|
1347
|
-
forEach(fn) {
|
1348
|
-
utils.forEach(this.handlers, function forEachHandler(h) {
|
1349
|
-
if (h !== null) {
|
1350
|
-
fn(h);
|
1351
|
-
}
|
1352
|
-
});
|
1353
|
-
}
|
1354
|
-
}
|
1355
|
-
|
1356
|
-
const transitionalDefaults = {
|
1357
|
-
silentJSONParsing: true,
|
1358
|
-
forcedJSONParsing: true,
|
1359
|
-
clarifyTimeoutError: false
|
1360
|
-
};
|
1361
|
-
|
1362
|
-
const URLSearchParams$1 = typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams;
|
1363
|
-
|
1364
|
-
const FormData$1 = FormData;
|
1365
|
-
|
1366
|
-
/**
|
1367
|
-
* Determine if we're running in a standard browser environment
|
1368
|
-
*
|
1369
|
-
* This allows axios to run in a web worker, and react-native.
|
1370
|
-
* Both environments support XMLHttpRequest, but not fully standard globals.
|
1371
|
-
*
|
1372
|
-
* web workers:
|
1373
|
-
* typeof window -> undefined
|
1374
|
-
* typeof document -> undefined
|
1375
|
-
*
|
1376
|
-
* react-native:
|
1377
|
-
* navigator.product -> 'ReactNative'
|
1378
|
-
* nativescript
|
1379
|
-
* navigator.product -> 'NativeScript' or 'NS'
|
1380
|
-
*
|
1381
|
-
* @returns {boolean}
|
1382
|
-
*/
|
1383
|
-
const isStandardBrowserEnv = (() => {
|
1384
|
-
let product;
|
1385
|
-
if (typeof navigator !== 'undefined' && (
|
1386
|
-
(product = navigator.product) === 'ReactNative' ||
|
1387
|
-
product === 'NativeScript' ||
|
1388
|
-
product === 'NS')
|
1389
|
-
) {
|
1390
|
-
return false;
|
1391
|
-
}
|
1392
|
-
|
1393
|
-
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
1394
|
-
})();
|
1395
|
-
|
1396
|
-
const platform = {
|
1397
|
-
isBrowser: true,
|
1398
|
-
classes: {
|
1399
|
-
URLSearchParams: URLSearchParams$1,
|
1400
|
-
FormData: FormData$1,
|
1401
|
-
Blob
|
1402
|
-
},
|
1403
|
-
isStandardBrowserEnv,
|
1404
|
-
protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
|
1405
|
-
};
|
1406
|
-
|
1407
|
-
function toURLEncodedForm(data, options) {
|
1408
|
-
return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
|
1409
|
-
visitor: function(value, key, path, helpers) {
|
1410
|
-
|
1411
|
-
return helpers.defaultVisitor.apply(this, arguments);
|
1412
|
-
}
|
1413
|
-
}, options));
|
1414
|
-
}
|
1415
|
-
|
1416
|
-
/**
|
1417
|
-
* It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
|
1418
|
-
*
|
1419
|
-
* @param {string} name - The name of the property to get.
|
1420
|
-
*
|
1421
|
-
* @returns An array of strings.
|
1422
|
-
*/
|
1423
|
-
function parsePropPath(name) {
|
1424
|
-
// foo[x][y][z]
|
1425
|
-
// foo.x.y.z
|
1426
|
-
// foo-x-y-z
|
1427
|
-
// foo x y z
|
1428
|
-
return utils.matchAll(/\w+|\[(\w*)]/g, name).map(match => {
|
1429
|
-
return match[0] === '[]' ? '' : match[1] || match[0];
|
1430
|
-
});
|
1431
|
-
}
|
1432
|
-
|
1433
|
-
/**
|
1434
|
-
* Convert an array to an object.
|
1435
|
-
*
|
1436
|
-
* @param {Array<any>} arr - The array to convert to an object.
|
1437
|
-
*
|
1438
|
-
* @returns An object with the same keys and values as the array.
|
1439
|
-
*/
|
1440
|
-
function arrayToObject(arr) {
|
1441
|
-
const obj = {};
|
1442
|
-
const keys = Object.keys(arr);
|
1443
|
-
let i;
|
1444
|
-
const len = keys.length;
|
1445
|
-
let key;
|
1446
|
-
for (i = 0; i < len; i++) {
|
1447
|
-
key = keys[i];
|
1448
|
-
obj[key] = arr[key];
|
1449
|
-
}
|
1450
|
-
return obj;
|
1451
|
-
}
|
1452
|
-
|
1453
|
-
/**
|
1454
|
-
* It takes a FormData object and returns a JavaScript object
|
1455
|
-
*
|
1456
|
-
* @param {string} formData The FormData object to convert to JSON.
|
1457
|
-
*
|
1458
|
-
* @returns {Object<string, any> | null} The converted object.
|
1459
|
-
*/
|
1460
|
-
function formDataToJSON(formData) {
|
1461
|
-
function buildPath(path, value, target, index) {
|
1462
|
-
let name = path[index++];
|
1463
|
-
const isNumericKey = Number.isFinite(+name);
|
1464
|
-
const isLast = index >= path.length;
|
1465
|
-
name = !name && utils.isArray(target) ? target.length : name;
|
1466
|
-
|
1467
|
-
if (isLast) {
|
1468
|
-
if (utils.hasOwnProp(target, name)) {
|
1469
|
-
target[name] = [target[name], value];
|
1470
|
-
} else {
|
1471
|
-
target[name] = value;
|
1472
|
-
}
|
1473
|
-
|
1474
|
-
return !isNumericKey;
|
1475
|
-
}
|
1476
|
-
|
1477
|
-
if (!target[name] || !utils.isObject(target[name])) {
|
1478
|
-
target[name] = [];
|
1479
|
-
}
|
1480
|
-
|
1481
|
-
const result = buildPath(path, value, target[name], index);
|
1482
|
-
|
1483
|
-
if (result && utils.isArray(target[name])) {
|
1484
|
-
target[name] = arrayToObject(target[name]);
|
1485
|
-
}
|
1486
|
-
|
1487
|
-
return !isNumericKey;
|
1488
|
-
}
|
1489
|
-
|
1490
|
-
if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
|
1491
|
-
const obj = {};
|
1492
|
-
|
1493
|
-
utils.forEachEntry(formData, (name, value) => {
|
1494
|
-
buildPath(parsePropPath(name), value, obj, 0);
|
1495
|
-
});
|
1496
|
-
|
1497
|
-
return obj;
|
1498
|
-
}
|
1499
|
-
|
1500
|
-
return null;
|
1501
|
-
}
|
1502
|
-
|
1503
|
-
/**
|
1504
|
-
* Resolve or reject a Promise based on response status.
|
1505
|
-
*
|
1506
|
-
* @param {Function} resolve A function that resolves the promise.
|
1507
|
-
* @param {Function} reject A function that rejects the promise.
|
1508
|
-
* @param {object} response The response.
|
1509
|
-
*
|
1510
|
-
* @returns {object} The response.
|
1511
|
-
*/
|
1512
|
-
function settle(resolve, reject, response) {
|
1513
|
-
const validateStatus = response.config.validateStatus;
|
1514
|
-
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
1515
|
-
resolve(response);
|
1516
|
-
} else {
|
1517
|
-
reject(new AxiosError(
|
1518
|
-
'Request failed with status code ' + response.status,
|
1519
|
-
[AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
|
1520
|
-
response.config,
|
1521
|
-
response.request,
|
1522
|
-
response
|
1523
|
-
));
|
1524
|
-
}
|
1525
|
-
}
|
1526
|
-
|
1527
|
-
const cookies = platform.isStandardBrowserEnv ?
|
1528
|
-
|
1529
|
-
// Standard browser envs support document.cookie
|
1530
|
-
(function standardBrowserEnv() {
|
1531
|
-
return {
|
1532
|
-
write: function write(name, value, expires, path, domain, secure) {
|
1533
|
-
const cookie = [];
|
1534
|
-
cookie.push(name + '=' + encodeURIComponent(value));
|
1535
|
-
|
1536
|
-
if (utils.isNumber(expires)) {
|
1537
|
-
cookie.push('expires=' + new Date(expires).toGMTString());
|
1538
|
-
}
|
1539
|
-
|
1540
|
-
if (utils.isString(path)) {
|
1541
|
-
cookie.push('path=' + path);
|
1542
|
-
}
|
1543
|
-
|
1544
|
-
if (utils.isString(domain)) {
|
1545
|
-
cookie.push('domain=' + domain);
|
1546
|
-
}
|
1547
|
-
|
1548
|
-
if (secure === true) {
|
1549
|
-
cookie.push('secure');
|
1550
|
-
}
|
1551
|
-
|
1552
|
-
document.cookie = cookie.join('; ');
|
1553
|
-
},
|
1554
|
-
|
1555
|
-
read: function read(name) {
|
1556
|
-
const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
1557
|
-
return (match ? decodeURIComponent(match[3]) : null);
|
1558
|
-
},
|
1559
|
-
|
1560
|
-
remove: function remove(name) {
|
1561
|
-
this.write(name, '', Date.now() - 86400000);
|
1562
|
-
}
|
1563
|
-
};
|
1564
|
-
})() :
|
1565
|
-
|
1566
|
-
// Non standard browser env (web workers, react-native) lack needed support.
|
1567
|
-
(function nonStandardBrowserEnv() {
|
1568
|
-
return {
|
1569
|
-
write: function write() {},
|
1570
|
-
read: function read() { return null; },
|
1571
|
-
remove: function remove() {}
|
1572
|
-
};
|
1573
|
-
})();
|
1574
|
-
|
1575
|
-
/**
|
1576
|
-
* Determines whether the specified URL is absolute
|
1577
|
-
*
|
1578
|
-
* @param {string} url The URL to test
|
1579
|
-
*
|
1580
|
-
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
1581
|
-
*/
|
1582
|
-
function isAbsoluteURL(url) {
|
1583
|
-
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
1584
|
-
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
1585
|
-
// by any combination of letters, digits, plus, period, or hyphen.
|
1586
|
-
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
1587
|
-
}
|
1588
|
-
|
1589
|
-
/**
|
1590
|
-
* Creates a new URL by combining the specified URLs
|
1591
|
-
*
|
1592
|
-
* @param {string} baseURL The base URL
|
1593
|
-
* @param {string} relativeURL The relative URL
|
1594
|
-
*
|
1595
|
-
* @returns {string} The combined URL
|
1596
|
-
*/
|
1597
|
-
function combineURLs(baseURL, relativeURL) {
|
1598
|
-
return relativeURL
|
1599
|
-
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
1600
|
-
: baseURL;
|
1601
|
-
}
|
1602
|
-
|
1603
|
-
/**
|
1604
|
-
* Creates a new URL by combining the baseURL with the requestedURL,
|
1605
|
-
* only when the requestedURL is not already an absolute URL.
|
1606
|
-
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
1607
|
-
*
|
1608
|
-
* @param {string} baseURL The base URL
|
1609
|
-
* @param {string} requestedURL Absolute or relative URL to combine
|
1610
|
-
*
|
1611
|
-
* @returns {string} The combined full path
|
1612
|
-
*/
|
1613
|
-
function buildFullPath(baseURL, requestedURL) {
|
1614
|
-
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
1615
|
-
return combineURLs(baseURL, requestedURL);
|
1616
|
-
}
|
1617
|
-
return requestedURL;
|
1618
|
-
}
|
1619
|
-
|
1620
|
-
const isURLSameOrigin = platform.isStandardBrowserEnv ?
|
1621
|
-
|
1622
|
-
// Standard browser envs have full support of the APIs needed to test
|
1623
|
-
// whether the request URL is of the same origin as current location.
|
1624
|
-
(function standardBrowserEnv() {
|
1625
|
-
const msie = /(msie|trident)/i.test(navigator.userAgent);
|
1626
|
-
const urlParsingNode = document.createElement('a');
|
1627
|
-
let originURL;
|
1628
|
-
|
1629
|
-
/**
|
1630
|
-
* Parse a URL to discover it's components
|
1631
|
-
*
|
1632
|
-
* @param {String} url The URL to be parsed
|
1633
|
-
* @returns {Object}
|
1634
|
-
*/
|
1635
|
-
function resolveURL(url) {
|
1636
|
-
let href = url;
|
1637
|
-
|
1638
|
-
if (msie) {
|
1639
|
-
// IE needs attribute set twice to normalize properties
|
1640
|
-
urlParsingNode.setAttribute('href', href);
|
1641
|
-
href = urlParsingNode.href;
|
1642
|
-
}
|
1643
|
-
|
1644
|
-
urlParsingNode.setAttribute('href', href);
|
1645
|
-
|
1646
|
-
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
1647
|
-
return {
|
1648
|
-
href: urlParsingNode.href,
|
1649
|
-
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
1650
|
-
host: urlParsingNode.host,
|
1651
|
-
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
1652
|
-
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
1653
|
-
hostname: urlParsingNode.hostname,
|
1654
|
-
port: urlParsingNode.port,
|
1655
|
-
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
1656
|
-
urlParsingNode.pathname :
|
1657
|
-
'/' + urlParsingNode.pathname
|
1658
|
-
};
|
1659
|
-
}
|
1660
|
-
|
1661
|
-
originURL = resolveURL(window.location.href);
|
1662
|
-
|
1663
|
-
/**
|
1664
|
-
* Determine if a URL shares the same origin as the current location
|
1665
|
-
*
|
1666
|
-
* @param {String} requestURL The URL to test
|
1667
|
-
* @returns {boolean} True if URL shares the same origin, otherwise false
|
1668
|
-
*/
|
1669
|
-
return function isURLSameOrigin(requestURL) {
|
1670
|
-
const parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
1671
|
-
return (parsed.protocol === originURL.protocol &&
|
1672
|
-
parsed.host === originURL.host);
|
1673
|
-
};
|
1674
|
-
})() :
|
1675
|
-
|
1676
|
-
// Non standard browser envs (web workers, react-native) lack needed support.
|
1677
|
-
(function nonStandardBrowserEnv() {
|
1678
|
-
return function isURLSameOrigin() {
|
1679
|
-
return true;
|
1680
|
-
};
|
1681
|
-
})();
|
1682
|
-
|
1683
|
-
/**
|
1684
|
-
* A `CanceledError` is an object that is thrown when an operation is canceled.
|
1685
|
-
*
|
1686
|
-
* @param {string=} message The message.
|
1687
|
-
* @param {Object=} config The config.
|
1688
|
-
* @param {Object=} request The request.
|
1689
|
-
*
|
1690
|
-
* @returns {CanceledError} The created error.
|
1691
|
-
*/
|
1692
|
-
function CanceledError(message, config, request) {
|
1693
|
-
// eslint-disable-next-line no-eq-null,eqeqeq
|
1694
|
-
AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
|
1695
|
-
this.name = 'CanceledError';
|
1696
|
-
}
|
1697
|
-
|
1698
|
-
utils.inherits(CanceledError, AxiosError, {
|
1699
|
-
__CANCEL__: true
|
1700
|
-
});
|
1701
|
-
|
1702
|
-
function parseProtocol(url) {
|
1703
|
-
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
1704
|
-
return match && match[1] || '';
|
1705
|
-
}
|
1706
|
-
|
1707
|
-
// RawAxiosHeaders whose duplicates are ignored by node
|
1708
|
-
// c.f. https://nodejs.org/api/http.html#http_message_headers
|
1709
|
-
const ignoreDuplicateOf = utils.toObjectSet([
|
1710
|
-
'age', 'authorization', 'content-length', 'content-type', 'etag',
|
1711
|
-
'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
|
1712
|
-
'last-modified', 'location', 'max-forwards', 'proxy-authorization',
|
1713
|
-
'referer', 'retry-after', 'user-agent'
|
1714
|
-
]);
|
1715
|
-
|
1716
|
-
/**
|
1717
|
-
* Parse headers into an object
|
1718
|
-
*
|
1719
|
-
* ```
|
1720
|
-
* Date: Wed, 27 Aug 2014 08:58:49 GMT
|
1721
|
-
* Content-Type: application/json
|
1722
|
-
* Connection: keep-alive
|
1723
|
-
* Transfer-Encoding: chunked
|
1724
|
-
* ```
|
1725
|
-
*
|
1726
|
-
* @param {String} rawHeaders Headers needing to be parsed
|
1727
|
-
*
|
1728
|
-
* @returns {Object} Headers parsed into an object
|
1729
|
-
*/
|
1730
|
-
const parseHeaders = rawHeaders => {
|
1731
|
-
const parsed = {};
|
1732
|
-
let key;
|
1733
|
-
let val;
|
1734
|
-
let i;
|
1735
|
-
|
1736
|
-
rawHeaders && rawHeaders.split('\n').forEach(function parser(line) {
|
1737
|
-
i = line.indexOf(':');
|
1738
|
-
key = line.substring(0, i).trim().toLowerCase();
|
1739
|
-
val = line.substring(i + 1).trim();
|
1740
|
-
|
1741
|
-
if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
|
1742
|
-
return;
|
1743
|
-
}
|
1744
|
-
|
1745
|
-
if (key === 'set-cookie') {
|
1746
|
-
if (parsed[key]) {
|
1747
|
-
parsed[key].push(val);
|
1748
|
-
} else {
|
1749
|
-
parsed[key] = [val];
|
1750
|
-
}
|
1751
|
-
} else {
|
1752
|
-
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
1753
|
-
}
|
1754
|
-
});
|
1755
|
-
|
1756
|
-
return parsed;
|
1757
|
-
};
|
1758
|
-
|
1759
|
-
const $internals = Symbol('internals');
|
1760
|
-
const $defaults = Symbol('defaults');
|
1761
|
-
|
1762
|
-
function normalizeHeader(header) {
|
1763
|
-
return header && String(header).trim().toLowerCase();
|
1764
|
-
}
|
1765
|
-
|
1766
|
-
function normalizeValue(value) {
|
1767
|
-
if (value === false || value == null) {
|
1768
|
-
return value;
|
1769
|
-
}
|
1770
|
-
|
1771
|
-
return String(value);
|
1772
|
-
}
|
1773
|
-
|
1774
|
-
function parseTokens(str) {
|
1775
|
-
const tokens = Object.create(null);
|
1776
|
-
const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
|
1777
|
-
let match;
|
1778
|
-
|
1779
|
-
while ((match = tokensRE.exec(str))) {
|
1780
|
-
tokens[match[1]] = match[2];
|
1781
|
-
}
|
1782
|
-
|
1783
|
-
return tokens;
|
1784
|
-
}
|
1785
|
-
|
1786
|
-
function matchHeaderValue(context, value, header, filter) {
|
1787
|
-
if (utils.isFunction(filter)) {
|
1788
|
-
return filter.call(this, value, header);
|
1789
|
-
}
|
1790
|
-
|
1791
|
-
if (!utils.isString(value)) return;
|
1792
|
-
|
1793
|
-
if (utils.isString(filter)) {
|
1794
|
-
return value.indexOf(filter) !== -1;
|
1795
|
-
}
|
1796
|
-
|
1797
|
-
if (utils.isRegExp(filter)) {
|
1798
|
-
return filter.test(value);
|
1799
|
-
}
|
1800
|
-
}
|
1801
|
-
|
1802
|
-
function formatHeader(header) {
|
1803
|
-
return header.trim()
|
1804
|
-
.toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str) => {
|
1805
|
-
return char.toUpperCase() + str;
|
1806
|
-
});
|
1807
|
-
}
|
1808
|
-
|
1809
|
-
function buildAccessors(obj, header) {
|
1810
|
-
const accessorName = utils.toCamelCase(' ' + header);
|
1811
|
-
|
1812
|
-
['get', 'set', 'has'].forEach(methodName => {
|
1813
|
-
Object.defineProperty(obj, methodName + accessorName, {
|
1814
|
-
value: function(arg1, arg2, arg3) {
|
1815
|
-
return this[methodName].call(this, header, arg1, arg2, arg3);
|
1816
|
-
},
|
1817
|
-
configurable: true
|
1818
|
-
});
|
1819
|
-
});
|
1820
|
-
}
|
1821
|
-
|
1822
|
-
function findKey(obj, key) {
|
1823
|
-
key = key.toLowerCase();
|
1824
|
-
const keys = Object.keys(obj);
|
1825
|
-
let i = keys.length;
|
1826
|
-
let _key;
|
1827
|
-
while (i-- > 0) {
|
1828
|
-
_key = keys[i];
|
1829
|
-
if (key === _key.toLowerCase()) {
|
1830
|
-
return _key;
|
1831
|
-
}
|
1832
|
-
}
|
1833
|
-
return null;
|
1834
|
-
}
|
1835
|
-
|
1836
|
-
function AxiosHeaders(headers, defaults) {
|
1837
|
-
headers && this.set(headers);
|
1838
|
-
this[$defaults] = defaults || null;
|
1839
|
-
}
|
1840
|
-
|
1841
|
-
Object.assign(AxiosHeaders.prototype, {
|
1842
|
-
set: function(header, valueOrRewrite, rewrite) {
|
1843
|
-
const self = this;
|
1844
|
-
|
1845
|
-
function setHeader(_value, _header, _rewrite) {
|
1846
|
-
const lHeader = normalizeHeader(_header);
|
1847
|
-
|
1848
|
-
if (!lHeader) {
|
1849
|
-
throw new Error('header name must be a non-empty string');
|
1850
|
-
}
|
1851
|
-
|
1852
|
-
const key = findKey(self, lHeader);
|
1853
|
-
|
1854
|
-
if (key && _rewrite !== true && (self[key] === false || _rewrite === false)) {
|
1855
|
-
return;
|
1856
|
-
}
|
1857
|
-
|
1858
|
-
if (utils.isArray(_value)) {
|
1859
|
-
_value = _value.map(normalizeValue);
|
1860
|
-
} else {
|
1861
|
-
_value = normalizeValue(_value);
|
1862
|
-
}
|
1863
|
-
|
1864
|
-
self[key || _header] = _value;
|
1865
|
-
}
|
1866
|
-
|
1867
|
-
if (utils.isPlainObject(header)) {
|
1868
|
-
utils.forEach(header, (_value, _header) => {
|
1869
|
-
setHeader(_value, _header, valueOrRewrite);
|
1870
|
-
});
|
1871
|
-
} else {
|
1872
|
-
setHeader(valueOrRewrite, header, rewrite);
|
1873
|
-
}
|
1874
|
-
|
1875
|
-
return this;
|
1876
|
-
},
|
1877
|
-
|
1878
|
-
get: function(header, parser) {
|
1879
|
-
header = normalizeHeader(header);
|
1880
|
-
|
1881
|
-
if (!header) return undefined;
|
1882
|
-
|
1883
|
-
const key = findKey(this, header);
|
1884
|
-
|
1885
|
-
if (key) {
|
1886
|
-
const value = this[key];
|
1887
|
-
|
1888
|
-
if (!parser) {
|
1889
|
-
return value;
|
1890
|
-
}
|
1891
|
-
|
1892
|
-
if (parser === true) {
|
1893
|
-
return parseTokens(value);
|
1894
|
-
}
|
1895
|
-
|
1896
|
-
if (utils.isFunction(parser)) {
|
1897
|
-
return parser.call(this, value, key);
|
1898
|
-
}
|
1899
|
-
|
1900
|
-
if (utils.isRegExp(parser)) {
|
1901
|
-
return parser.exec(value);
|
1902
|
-
}
|
1903
|
-
|
1904
|
-
throw new TypeError('parser must be boolean|regexp|function');
|
1905
|
-
}
|
1906
|
-
},
|
1907
|
-
|
1908
|
-
has: function(header, matcher) {
|
1909
|
-
header = normalizeHeader(header);
|
1910
|
-
|
1911
|
-
if (header) {
|
1912
|
-
const key = findKey(this, header);
|
1913
|
-
|
1914
|
-
return !!(key && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
|
1915
|
-
}
|
1916
|
-
|
1917
|
-
return false;
|
1918
|
-
},
|
1919
|
-
|
1920
|
-
delete: function(header, matcher) {
|
1921
|
-
const self = this;
|
1922
|
-
let deleted = false;
|
1923
|
-
|
1924
|
-
function deleteHeader(_header) {
|
1925
|
-
_header = normalizeHeader(_header);
|
1926
|
-
|
1927
|
-
if (_header) {
|
1928
|
-
const key = findKey(self, _header);
|
1929
|
-
|
1930
|
-
if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
|
1931
|
-
delete self[key];
|
1932
|
-
|
1933
|
-
deleted = true;
|
1934
|
-
}
|
1935
|
-
}
|
1936
|
-
}
|
1937
|
-
|
1938
|
-
if (utils.isArray(header)) {
|
1939
|
-
header.forEach(deleteHeader);
|
1940
|
-
} else {
|
1941
|
-
deleteHeader(header);
|
1942
|
-
}
|
1943
|
-
|
1944
|
-
return deleted;
|
1945
|
-
},
|
1946
|
-
|
1947
|
-
clear: function() {
|
1948
|
-
return Object.keys(this).forEach(this.delete.bind(this));
|
1949
|
-
},
|
1950
|
-
|
1951
|
-
normalize: function(format) {
|
1952
|
-
const self = this;
|
1953
|
-
const headers = {};
|
1954
|
-
|
1955
|
-
utils.forEach(this, (value, header) => {
|
1956
|
-
const key = findKey(headers, header);
|
1957
|
-
|
1958
|
-
if (key) {
|
1959
|
-
self[key] = normalizeValue(value);
|
1960
|
-
delete self[header];
|
1961
|
-
return;
|
1962
|
-
}
|
1963
|
-
|
1964
|
-
const normalized = format ? formatHeader(header) : String(header).trim();
|
1965
|
-
|
1966
|
-
if (normalized !== header) {
|
1967
|
-
delete self[header];
|
1968
|
-
}
|
1969
|
-
|
1970
|
-
self[normalized] = normalizeValue(value);
|
1971
|
-
|
1972
|
-
headers[normalized] = true;
|
1973
|
-
});
|
1974
|
-
|
1975
|
-
return this;
|
1976
|
-
},
|
1977
|
-
|
1978
|
-
toJSON: function() {
|
1979
|
-
const obj = Object.create(null);
|
1980
|
-
|
1981
|
-
utils.forEach(Object.assign({}, this[$defaults] || null, this),
|
1982
|
-
(value, header) => {
|
1983
|
-
if (value == null || value === false) return;
|
1984
|
-
obj[header] = utils.isArray(value) ? value.join(', ') : value;
|
1985
|
-
});
|
1986
|
-
|
1987
|
-
return obj;
|
1988
|
-
}
|
1989
|
-
});
|
1990
|
-
|
1991
|
-
Object.assign(AxiosHeaders, {
|
1992
|
-
from: function(thing) {
|
1993
|
-
if (utils.isString(thing)) {
|
1994
|
-
return new this(parseHeaders(thing));
|
1995
|
-
}
|
1996
|
-
return thing instanceof this ? thing : new this(thing);
|
1997
|
-
},
|
1998
|
-
|
1999
|
-
accessor: function(header) {
|
2000
|
-
const internals = this[$internals] = (this[$internals] = {
|
2001
|
-
accessors: {}
|
2002
|
-
});
|
2003
|
-
|
2004
|
-
const accessors = internals.accessors;
|
2005
|
-
const prototype = this.prototype;
|
2006
|
-
|
2007
|
-
function defineAccessor(_header) {
|
2008
|
-
const lHeader = normalizeHeader(_header);
|
2009
|
-
|
2010
|
-
if (!accessors[lHeader]) {
|
2011
|
-
buildAccessors(prototype, _header);
|
2012
|
-
accessors[lHeader] = true;
|
2013
|
-
}
|
2014
|
-
}
|
2015
|
-
|
2016
|
-
utils.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
2017
|
-
|
2018
|
-
return this;
|
2019
|
-
}
|
2020
|
-
});
|
2021
|
-
|
2022
|
-
AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
|
2023
|
-
|
2024
|
-
utils.freezeMethods(AxiosHeaders.prototype);
|
2025
|
-
utils.freezeMethods(AxiosHeaders);
|
2026
|
-
|
2027
|
-
/**
|
2028
|
-
* Calculate data maxRate
|
2029
|
-
* @param {Number} [samplesCount= 10]
|
2030
|
-
* @param {Number} [min= 1000]
|
2031
|
-
* @returns {Function}
|
2032
|
-
*/
|
2033
|
-
function speedometer(samplesCount, min) {
|
2034
|
-
samplesCount = samplesCount || 10;
|
2035
|
-
const bytes = new Array(samplesCount);
|
2036
|
-
const timestamps = new Array(samplesCount);
|
2037
|
-
let head = 0;
|
2038
|
-
let tail = 0;
|
2039
|
-
let firstSampleTS;
|
2040
|
-
|
2041
|
-
min = min !== undefined ? min : 1000;
|
2042
|
-
|
2043
|
-
return function push(chunkLength) {
|
2044
|
-
const now = Date.now();
|
2045
|
-
|
2046
|
-
const startedAt = timestamps[tail];
|
2047
|
-
|
2048
|
-
if (!firstSampleTS) {
|
2049
|
-
firstSampleTS = now;
|
2050
|
-
}
|
2051
|
-
|
2052
|
-
bytes[head] = chunkLength;
|
2053
|
-
timestamps[head] = now;
|
2054
|
-
|
2055
|
-
let i = tail;
|
2056
|
-
let bytesCount = 0;
|
2057
|
-
|
2058
|
-
while (i !== head) {
|
2059
|
-
bytesCount += bytes[i++];
|
2060
|
-
i = i % samplesCount;
|
2061
|
-
}
|
2062
|
-
|
2063
|
-
head = (head + 1) % samplesCount;
|
2064
|
-
|
2065
|
-
if (head === tail) {
|
2066
|
-
tail = (tail + 1) % samplesCount;
|
2067
|
-
}
|
2068
|
-
|
2069
|
-
if (now - firstSampleTS < min) {
|
2070
|
-
return;
|
2071
|
-
}
|
2072
|
-
|
2073
|
-
const passed = startedAt && now - startedAt;
|
2074
|
-
|
2075
|
-
return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
|
2076
|
-
};
|
2077
|
-
}
|
2078
|
-
|
2079
|
-
function progressEventReducer(listener, isDownloadStream) {
|
2080
|
-
let bytesNotified = 0;
|
2081
|
-
const _speedometer = speedometer(50, 250);
|
2082
|
-
|
2083
|
-
return e => {
|
2084
|
-
const loaded = e.loaded;
|
2085
|
-
const total = e.lengthComputable ? e.total : undefined;
|
2086
|
-
const progressBytes = loaded - bytesNotified;
|
2087
|
-
const rate = _speedometer(progressBytes);
|
2088
|
-
const inRange = loaded <= total;
|
2089
|
-
|
2090
|
-
bytesNotified = loaded;
|
2091
|
-
|
2092
|
-
const data = {
|
2093
|
-
loaded,
|
2094
|
-
total,
|
2095
|
-
progress: total ? (loaded / total) : undefined,
|
2096
|
-
bytes: progressBytes,
|
2097
|
-
rate: rate ? rate : undefined,
|
2098
|
-
estimated: rate && total && inRange ? (total - loaded) / rate : undefined
|
2099
|
-
};
|
2100
|
-
|
2101
|
-
data[isDownloadStream ? 'download' : 'upload'] = true;
|
2102
|
-
|
2103
|
-
listener(data);
|
2104
|
-
};
|
2105
|
-
}
|
2106
|
-
|
2107
|
-
function xhrAdapter(config) {
|
2108
|
-
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
2109
|
-
let requestData = config.data;
|
2110
|
-
const requestHeaders = AxiosHeaders.from(config.headers).normalize();
|
2111
|
-
const responseType = config.responseType;
|
2112
|
-
let onCanceled;
|
2113
|
-
function done() {
|
2114
|
-
if (config.cancelToken) {
|
2115
|
-
config.cancelToken.unsubscribe(onCanceled);
|
2116
|
-
}
|
2117
|
-
|
2118
|
-
if (config.signal) {
|
2119
|
-
config.signal.removeEventListener('abort', onCanceled);
|
2120
|
-
}
|
2121
|
-
}
|
2122
|
-
|
2123
|
-
if (utils.isFormData(requestData) && platform.isStandardBrowserEnv) {
|
2124
|
-
requestHeaders.setContentType(false); // Let the browser set it
|
2125
|
-
}
|
2126
|
-
|
2127
|
-
let request = new XMLHttpRequest();
|
2128
|
-
|
2129
|
-
// HTTP basic authentication
|
2130
|
-
if (config.auth) {
|
2131
|
-
const username = config.auth.username || '';
|
2132
|
-
const password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
2133
|
-
requestHeaders.set('Authorization', 'Basic ' + btoa(username + ':' + password));
|
2134
|
-
}
|
2135
|
-
|
2136
|
-
const fullPath = buildFullPath(config.baseURL, config.url);
|
2137
|
-
|
2138
|
-
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
2139
|
-
|
2140
|
-
// Set the request timeout in MS
|
2141
|
-
request.timeout = config.timeout;
|
2142
|
-
|
2143
|
-
function onloadend() {
|
2144
|
-
if (!request) {
|
2145
|
-
return;
|
2146
|
-
}
|
2147
|
-
// Prepare the response
|
2148
|
-
const responseHeaders = AxiosHeaders.from(
|
2149
|
-
'getAllResponseHeaders' in request && request.getAllResponseHeaders()
|
2150
|
-
);
|
2151
|
-
const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
|
2152
|
-
request.responseText : request.response;
|
2153
|
-
const response = {
|
2154
|
-
data: responseData,
|
2155
|
-
status: request.status,
|
2156
|
-
statusText: request.statusText,
|
2157
|
-
headers: responseHeaders,
|
2158
|
-
config,
|
2159
|
-
request
|
2160
|
-
};
|
2161
|
-
|
2162
|
-
settle(function _resolve(value) {
|
2163
|
-
resolve(value);
|
2164
|
-
done();
|
2165
|
-
}, function _reject(err) {
|
2166
|
-
reject(err);
|
2167
|
-
done();
|
2168
|
-
}, response);
|
2169
|
-
|
2170
|
-
// Clean up request
|
2171
|
-
request = null;
|
2172
|
-
}
|
2173
|
-
|
2174
|
-
if ('onloadend' in request) {
|
2175
|
-
// Use onloadend if available
|
2176
|
-
request.onloadend = onloadend;
|
2177
|
-
} else {
|
2178
|
-
// Listen for ready state to emulate onloadend
|
2179
|
-
request.onreadystatechange = function handleLoad() {
|
2180
|
-
if (!request || request.readyState !== 4) {
|
2181
|
-
return;
|
2182
|
-
}
|
2183
|
-
|
2184
|
-
// The request errored out and we didn't get a response, this will be
|
2185
|
-
// handled by onerror instead
|
2186
|
-
// With one exception: request that using file: protocol, most browsers
|
2187
|
-
// will return status as 0 even though it's a successful request
|
2188
|
-
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
2189
|
-
return;
|
2190
|
-
}
|
2191
|
-
// readystate handler is calling before onerror or ontimeout handlers,
|
2192
|
-
// so we should call onloadend on the next 'tick'
|
2193
|
-
setTimeout(onloadend);
|
2194
|
-
};
|
2195
|
-
}
|
2196
|
-
|
2197
|
-
// Handle browser request cancellation (as opposed to a manual cancellation)
|
2198
|
-
request.onabort = function handleAbort() {
|
2199
|
-
if (!request) {
|
2200
|
-
return;
|
2201
|
-
}
|
2202
|
-
|
2203
|
-
reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
|
2204
|
-
|
2205
|
-
// Clean up request
|
2206
|
-
request = null;
|
2207
|
-
};
|
2208
|
-
|
2209
|
-
// Handle low level network errors
|
2210
|
-
request.onerror = function handleError() {
|
2211
|
-
// Real errors are hidden from us by the browser
|
2212
|
-
// onerror should only fire if it's a network error
|
2213
|
-
reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
|
2214
|
-
|
2215
|
-
// Clean up request
|
2216
|
-
request = null;
|
2217
|
-
};
|
2218
|
-
|
2219
|
-
// Handle timeout
|
2220
|
-
request.ontimeout = function handleTimeout() {
|
2221
|
-
let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
|
2222
|
-
const transitional = config.transitional || transitionalDefaults;
|
2223
|
-
if (config.timeoutErrorMessage) {
|
2224
|
-
timeoutErrorMessage = config.timeoutErrorMessage;
|
2225
|
-
}
|
2226
|
-
reject(new AxiosError(
|
2227
|
-
timeoutErrorMessage,
|
2228
|
-
transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
|
2229
|
-
config,
|
2230
|
-
request));
|
2231
|
-
|
2232
|
-
// Clean up request
|
2233
|
-
request = null;
|
2234
|
-
};
|
2235
|
-
|
2236
|
-
// Add xsrf header
|
2237
|
-
// This is only done if running in a standard browser environment.
|
2238
|
-
// Specifically not if we're in a web worker, or react-native.
|
2239
|
-
if (platform.isStandardBrowserEnv) {
|
2240
|
-
// Add xsrf header
|
2241
|
-
const xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath))
|
2242
|
-
&& config.xsrfCookieName && cookies.read(config.xsrfCookieName);
|
2243
|
-
|
2244
|
-
if (xsrfValue) {
|
2245
|
-
requestHeaders.set(config.xsrfHeaderName, xsrfValue);
|
2246
|
-
}
|
2247
|
-
}
|
2248
|
-
|
2249
|
-
// Remove Content-Type if data is undefined
|
2250
|
-
requestData === undefined && requestHeaders.setContentType(null);
|
2251
|
-
|
2252
|
-
// Add headers to the request
|
2253
|
-
if ('setRequestHeader' in request) {
|
2254
|
-
utils.forEach(requestHeaders.toJSON(), function setRequestHeader(val, key) {
|
2255
|
-
request.setRequestHeader(key, val);
|
2256
|
-
});
|
2257
|
-
}
|
2258
|
-
|
2259
|
-
// Add withCredentials to request if needed
|
2260
|
-
if (!utils.isUndefined(config.withCredentials)) {
|
2261
|
-
request.withCredentials = !!config.withCredentials;
|
2262
|
-
}
|
2263
|
-
|
2264
|
-
// Add responseType to request if needed
|
2265
|
-
if (responseType && responseType !== 'json') {
|
2266
|
-
request.responseType = config.responseType;
|
2267
|
-
}
|
2268
|
-
|
2269
|
-
// Handle progress if needed
|
2270
|
-
if (typeof config.onDownloadProgress === 'function') {
|
2271
|
-
request.addEventListener('progress', progressEventReducer(config.onDownloadProgress, true));
|
2272
|
-
}
|
2273
|
-
|
2274
|
-
// Not all browsers support upload events
|
2275
|
-
if (typeof config.onUploadProgress === 'function' && request.upload) {
|
2276
|
-
request.upload.addEventListener('progress', progressEventReducer(config.onUploadProgress));
|
2277
|
-
}
|
2278
|
-
|
2279
|
-
if (config.cancelToken || config.signal) {
|
2280
|
-
// Handle cancellation
|
2281
|
-
// eslint-disable-next-line func-names
|
2282
|
-
onCanceled = cancel => {
|
2283
|
-
if (!request) {
|
2284
|
-
return;
|
2285
|
-
}
|
2286
|
-
reject(!cancel || cancel.type ? new CanceledError(null, config, request) : cancel);
|
2287
|
-
request.abort();
|
2288
|
-
request = null;
|
2289
|
-
};
|
2290
|
-
|
2291
|
-
config.cancelToken && config.cancelToken.subscribe(onCanceled);
|
2292
|
-
if (config.signal) {
|
2293
|
-
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
|
2294
|
-
}
|
2295
|
-
}
|
2296
|
-
|
2297
|
-
const protocol = parseProtocol(fullPath);
|
2298
|
-
|
2299
|
-
if (protocol && platform.protocols.indexOf(protocol) === -1) {
|
2300
|
-
reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
|
2301
|
-
return;
|
2302
|
-
}
|
2303
|
-
|
2304
|
-
|
2305
|
-
// Send the request
|
2306
|
-
request.send(requestData || null);
|
2307
|
-
});
|
2308
|
-
}
|
2309
|
-
|
2310
|
-
const adapters = {
|
2311
|
-
http: xhrAdapter,
|
2312
|
-
xhr: xhrAdapter
|
2313
|
-
};
|
2314
|
-
|
2315
|
-
const adapters$1 = {
|
2316
|
-
getAdapter: (nameOrAdapter) => {
|
2317
|
-
if(utils.isString(nameOrAdapter)){
|
2318
|
-
const adapter = adapters[nameOrAdapter];
|
2319
|
-
|
2320
|
-
if (!nameOrAdapter) {
|
2321
|
-
throw Error(
|
2322
|
-
utils.hasOwnProp(nameOrAdapter) ?
|
2323
|
-
`Adapter '${nameOrAdapter}' is not available in the build` :
|
2324
|
-
`Can not resolve adapter '${nameOrAdapter}'`
|
2325
|
-
);
|
2326
|
-
}
|
2327
|
-
|
2328
|
-
return adapter
|
2329
|
-
}
|
2330
|
-
|
2331
|
-
if (!utils.isFunction(nameOrAdapter)) {
|
2332
|
-
throw new TypeError('adapter is not a function');
|
2333
|
-
}
|
2334
|
-
|
2335
|
-
return nameOrAdapter;
|
2336
|
-
},
|
2337
|
-
adapters
|
2338
|
-
};
|
2339
|
-
|
2340
|
-
const DEFAULT_CONTENT_TYPE = {
|
2341
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
2342
|
-
};
|
2343
|
-
|
2344
|
-
/**
|
2345
|
-
* If the browser has an XMLHttpRequest object, use the XHR adapter, otherwise use the HTTP
|
2346
|
-
* adapter
|
2347
|
-
*
|
2348
|
-
* @returns {Function}
|
2349
|
-
*/
|
2350
|
-
function getDefaultAdapter() {
|
2351
|
-
let adapter;
|
2352
|
-
if (typeof XMLHttpRequest !== 'undefined') {
|
2353
|
-
// For browsers use XHR adapter
|
2354
|
-
adapter = adapters$1.getAdapter('xhr');
|
2355
|
-
} else if (typeof process !== 'undefined' && utils.kindOf(process) === 'process') {
|
2356
|
-
// For node use HTTP adapter
|
2357
|
-
adapter = adapters$1.getAdapter('http');
|
2358
|
-
}
|
2359
|
-
return adapter;
|
2360
|
-
}
|
2361
|
-
|
2362
|
-
/**
|
2363
|
-
* It takes a string, tries to parse it, and if it fails, it returns the stringified version
|
2364
|
-
* of the input
|
2365
|
-
*
|
2366
|
-
* @param {any} rawValue - The value to be stringified.
|
2367
|
-
* @param {Function} parser - A function that parses a string into a JavaScript object.
|
2368
|
-
* @param {Function} encoder - A function that takes a value and returns a string.
|
2369
|
-
*
|
2370
|
-
* @returns {string} A stringified version of the rawValue.
|
2371
|
-
*/
|
2372
|
-
function stringifySafely(rawValue, parser, encoder) {
|
2373
|
-
if (utils.isString(rawValue)) {
|
2374
|
-
try {
|
2375
|
-
(parser || JSON.parse)(rawValue);
|
2376
|
-
return utils.trim(rawValue);
|
2377
|
-
} catch (e) {
|
2378
|
-
if (e.name !== 'SyntaxError') {
|
2379
|
-
throw e;
|
2380
|
-
}
|
2381
|
-
}
|
2382
|
-
}
|
2383
|
-
|
2384
|
-
return (encoder || JSON.stringify)(rawValue);
|
2385
|
-
}
|
2386
|
-
|
2387
|
-
const defaults = {
|
2388
|
-
|
2389
|
-
transitional: transitionalDefaults,
|
2390
|
-
|
2391
|
-
adapter: getDefaultAdapter(),
|
2392
|
-
|
2393
|
-
transformRequest: [function transformRequest(data, headers) {
|
2394
|
-
const contentType = headers.getContentType() || '';
|
2395
|
-
const hasJSONContentType = contentType.indexOf('application/json') > -1;
|
2396
|
-
const isObjectPayload = utils.isObject(data);
|
2397
|
-
|
2398
|
-
if (isObjectPayload && utils.isHTMLForm(data)) {
|
2399
|
-
data = new FormData(data);
|
2400
|
-
}
|
2401
|
-
|
2402
|
-
const isFormData = utils.isFormData(data);
|
2403
|
-
|
2404
|
-
if (isFormData) {
|
2405
|
-
if (!hasJSONContentType) {
|
2406
|
-
return data;
|
2407
|
-
}
|
2408
|
-
return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
|
2409
|
-
}
|
2410
|
-
|
2411
|
-
if (utils.isArrayBuffer(data) ||
|
2412
|
-
utils.isBuffer(data) ||
|
2413
|
-
utils.isStream(data) ||
|
2414
|
-
utils.isFile(data) ||
|
2415
|
-
utils.isBlob(data)
|
2416
|
-
) {
|
2417
|
-
return data;
|
2418
|
-
}
|
2419
|
-
if (utils.isArrayBufferView(data)) {
|
2420
|
-
return data.buffer;
|
2421
|
-
}
|
2422
|
-
if (utils.isURLSearchParams(data)) {
|
2423
|
-
headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
|
2424
|
-
return data.toString();
|
2425
|
-
}
|
2426
|
-
|
2427
|
-
let isFileList;
|
2428
|
-
|
2429
|
-
if (isObjectPayload) {
|
2430
|
-
if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
|
2431
|
-
return toURLEncodedForm(data, this.formSerializer).toString();
|
2432
|
-
}
|
2433
|
-
|
2434
|
-
if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
|
2435
|
-
const _FormData = this.env && this.env.FormData;
|
2436
|
-
|
2437
|
-
return toFormData(
|
2438
|
-
isFileList ? {'files[]': data} : data,
|
2439
|
-
_FormData && new _FormData(),
|
2440
|
-
this.formSerializer
|
2441
|
-
);
|
2442
|
-
}
|
2443
|
-
}
|
2444
|
-
|
2445
|
-
if (isObjectPayload || hasJSONContentType ) {
|
2446
|
-
headers.setContentType('application/json', false);
|
2447
|
-
return stringifySafely(data);
|
2448
|
-
}
|
2449
|
-
|
2450
|
-
return data;
|
2451
|
-
}],
|
2452
|
-
|
2453
|
-
transformResponse: [function transformResponse(data) {
|
2454
|
-
const transitional = this.transitional || defaults.transitional;
|
2455
|
-
const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
|
2456
|
-
const JSONRequested = this.responseType === 'json';
|
2457
|
-
|
2458
|
-
if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
|
2459
|
-
const silentJSONParsing = transitional && transitional.silentJSONParsing;
|
2460
|
-
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
2461
|
-
|
2462
|
-
try {
|
2463
|
-
return JSON.parse(data);
|
2464
|
-
} catch (e) {
|
2465
|
-
if (strictJSONParsing) {
|
2466
|
-
if (e.name === 'SyntaxError') {
|
2467
|
-
throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
|
2468
|
-
}
|
2469
|
-
throw e;
|
2470
|
-
}
|
2471
|
-
}
|
2472
|
-
}
|
2473
|
-
|
2474
|
-
return data;
|
2475
|
-
}],
|
2476
|
-
|
2477
|
-
/**
|
2478
|
-
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
2479
|
-
* timeout is not created.
|
2480
|
-
*/
|
2481
|
-
timeout: 0,
|
2482
|
-
|
2483
|
-
xsrfCookieName: 'XSRF-TOKEN',
|
2484
|
-
xsrfHeaderName: 'X-XSRF-TOKEN',
|
2485
|
-
|
2486
|
-
maxContentLength: -1,
|
2487
|
-
maxBodyLength: -1,
|
2488
|
-
|
2489
|
-
env: {
|
2490
|
-
FormData: platform.classes.FormData,
|
2491
|
-
Blob: platform.classes.Blob
|
2492
|
-
},
|
2493
|
-
|
2494
|
-
validateStatus: function validateStatus(status) {
|
2495
|
-
return status >= 200 && status < 300;
|
2496
|
-
},
|
2497
|
-
|
2498
|
-
headers: {
|
2499
|
-
common: {
|
2500
|
-
'Accept': 'application/json, text/plain, */*'
|
2501
|
-
}
|
2502
|
-
}
|
2503
|
-
};
|
2504
|
-
|
2505
|
-
utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
|
2506
|
-
defaults.headers[method] = {};
|
2507
|
-
});
|
2508
|
-
|
2509
|
-
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
2510
|
-
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
2511
|
-
});
|
2512
|
-
|
2513
|
-
/**
|
2514
|
-
* Transform the data for a request or a response
|
2515
|
-
*
|
2516
|
-
* @param {Array|Function} fns A single function or Array of functions
|
2517
|
-
* @param {?Object} response The response object
|
2518
|
-
*
|
2519
|
-
* @returns {*} The resulting transformed data
|
2520
|
-
*/
|
2521
|
-
function transformData(fns, response) {
|
2522
|
-
const config = this || defaults;
|
2523
|
-
const context = response || config;
|
2524
|
-
const headers = AxiosHeaders.from(context.headers);
|
2525
|
-
let data = context.data;
|
2526
|
-
|
2527
|
-
utils.forEach(fns, function transform(fn) {
|
2528
|
-
data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
|
2529
|
-
});
|
2530
|
-
|
2531
|
-
headers.normalize();
|
2532
|
-
|
2533
|
-
return data;
|
2534
|
-
}
|
2535
|
-
|
2536
|
-
function isCancel(value) {
|
2537
|
-
return !!(value && value.__CANCEL__);
|
2538
|
-
}
|
2539
|
-
|
2540
|
-
/**
|
2541
|
-
* Throws a `CanceledError` if cancellation has been requested.
|
2542
|
-
*
|
2543
|
-
* @param {Object} config The config that is to be used for the request
|
2544
|
-
*
|
2545
|
-
* @returns {void}
|
2546
|
-
*/
|
2547
|
-
function throwIfCancellationRequested(config) {
|
2548
|
-
if (config.cancelToken) {
|
2549
|
-
config.cancelToken.throwIfRequested();
|
2550
|
-
}
|
2551
|
-
|
2552
|
-
if (config.signal && config.signal.aborted) {
|
2553
|
-
throw new CanceledError();
|
2554
|
-
}
|
2555
|
-
}
|
2556
|
-
|
2557
|
-
/**
|
2558
|
-
* Dispatch a request to the server using the configured adapter.
|
2559
|
-
*
|
2560
|
-
* @param {object} config The config that is to be used for the request
|
2561
|
-
*
|
2562
|
-
* @returns {Promise} The Promise to be fulfilled
|
2563
|
-
*/
|
2564
|
-
function dispatchRequest(config) {
|
2565
|
-
throwIfCancellationRequested(config);
|
2566
|
-
|
2567
|
-
config.headers = AxiosHeaders.from(config.headers);
|
2568
|
-
|
2569
|
-
// Transform request data
|
2570
|
-
config.data = transformData.call(
|
2571
|
-
config,
|
2572
|
-
config.transformRequest
|
2573
|
-
);
|
2574
|
-
|
2575
|
-
const adapter = config.adapter || defaults.adapter;
|
2576
|
-
|
2577
|
-
return adapter(config).then(function onAdapterResolution(response) {
|
2578
|
-
throwIfCancellationRequested(config);
|
2579
|
-
|
2580
|
-
// Transform response data
|
2581
|
-
response.data = transformData.call(
|
2582
|
-
config,
|
2583
|
-
config.transformResponse,
|
2584
|
-
response
|
2585
|
-
);
|
2586
|
-
|
2587
|
-
response.headers = AxiosHeaders.from(response.headers);
|
2588
|
-
|
2589
|
-
return response;
|
2590
|
-
}, function onAdapterRejection(reason) {
|
2591
|
-
if (!isCancel(reason)) {
|
2592
|
-
throwIfCancellationRequested(config);
|
2593
|
-
|
2594
|
-
// Transform response data
|
2595
|
-
if (reason && reason.response) {
|
2596
|
-
reason.response.data = transformData.call(
|
2597
|
-
config,
|
2598
|
-
config.transformResponse,
|
2599
|
-
reason.response
|
2600
|
-
);
|
2601
|
-
reason.response.headers = AxiosHeaders.from(reason.response.headers);
|
2602
|
-
}
|
249
|
+
// eslint-lint-disable-next-line @typescript-eslint/naming-convention
|
250
|
+
class HTTPError extends Error {
|
251
|
+
constructor(response, request, options) {
|
252
|
+
const code = (response.status || response.status === 0) ? response.status : '';
|
253
|
+
const title = response.statusText || '';
|
254
|
+
const status = `${code} ${title}`.trim();
|
255
|
+
const reason = status ? `status code ${status}` : 'an unknown error';
|
256
|
+
super(`Request failed with ${reason}`);
|
257
|
+
Object.defineProperty(this, "response", {
|
258
|
+
enumerable: true,
|
259
|
+
configurable: true,
|
260
|
+
writable: true,
|
261
|
+
value: void 0
|
262
|
+
});
|
263
|
+
Object.defineProperty(this, "request", {
|
264
|
+
enumerable: true,
|
265
|
+
configurable: true,
|
266
|
+
writable: true,
|
267
|
+
value: void 0
|
268
|
+
});
|
269
|
+
Object.defineProperty(this, "options", {
|
270
|
+
enumerable: true,
|
271
|
+
configurable: true,
|
272
|
+
writable: true,
|
273
|
+
value: void 0
|
274
|
+
});
|
275
|
+
this.name = 'HTTPError';
|
276
|
+
this.response = response;
|
277
|
+
this.request = request;
|
278
|
+
this.options = options;
|
2603
279
|
}
|
2604
|
-
|
2605
|
-
return Promise.reject(reason);
|
2606
|
-
});
|
2607
280
|
}
|
2608
281
|
|
2609
|
-
|
2610
|
-
|
2611
|
-
|
2612
|
-
|
2613
|
-
|
2614
|
-
|
2615
|
-
|
2616
|
-
|
2617
|
-
|
2618
|
-
|
2619
|
-
|
2620
|
-
config2 = config2 || {};
|
2621
|
-
const config = {};
|
2622
|
-
|
2623
|
-
function getMergedValue(target, source) {
|
2624
|
-
if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
|
2625
|
-
return utils.merge(target, source);
|
2626
|
-
} else if (utils.isPlainObject(source)) {
|
2627
|
-
return utils.merge({}, source);
|
2628
|
-
} else if (utils.isArray(source)) {
|
2629
|
-
return source.slice();
|
2630
|
-
}
|
2631
|
-
return source;
|
2632
|
-
}
|
2633
|
-
|
2634
|
-
// eslint-disable-next-line consistent-return
|
2635
|
-
function mergeDeepProperties(prop) {
|
2636
|
-
if (!utils.isUndefined(config2[prop])) {
|
2637
|
-
return getMergedValue(config1[prop], config2[prop]);
|
2638
|
-
} else if (!utils.isUndefined(config1[prop])) {
|
2639
|
-
return getMergedValue(undefined, config1[prop]);
|
2640
|
-
}
|
2641
|
-
}
|
2642
|
-
|
2643
|
-
// eslint-disable-next-line consistent-return
|
2644
|
-
function valueFromConfig2(prop) {
|
2645
|
-
if (!utils.isUndefined(config2[prop])) {
|
2646
|
-
return getMergedValue(undefined, config2[prop]);
|
2647
|
-
}
|
2648
|
-
}
|
2649
|
-
|
2650
|
-
// eslint-disable-next-line consistent-return
|
2651
|
-
function defaultToConfig2(prop) {
|
2652
|
-
if (!utils.isUndefined(config2[prop])) {
|
2653
|
-
return getMergedValue(undefined, config2[prop]);
|
2654
|
-
} else if (!utils.isUndefined(config1[prop])) {
|
2655
|
-
return getMergedValue(undefined, config1[prop]);
|
2656
|
-
}
|
2657
|
-
}
|
2658
|
-
|
2659
|
-
// eslint-disable-next-line consistent-return
|
2660
|
-
function mergeDirectKeys(prop) {
|
2661
|
-
if (prop in config2) {
|
2662
|
-
return getMergedValue(config1[prop], config2[prop]);
|
2663
|
-
} else if (prop in config1) {
|
2664
|
-
return getMergedValue(undefined, config1[prop]);
|
282
|
+
class TimeoutError extends Error {
|
283
|
+
constructor(request) {
|
284
|
+
super('Request timed out');
|
285
|
+
Object.defineProperty(this, "request", {
|
286
|
+
enumerable: true,
|
287
|
+
configurable: true,
|
288
|
+
writable: true,
|
289
|
+
value: void 0
|
290
|
+
});
|
291
|
+
this.name = 'TimeoutError';
|
292
|
+
this.request = request;
|
2665
293
|
}
|
2666
|
-
}
|
2667
|
-
|
2668
|
-
const mergeMap = {
|
2669
|
-
'url': valueFromConfig2,
|
2670
|
-
'method': valueFromConfig2,
|
2671
|
-
'data': valueFromConfig2,
|
2672
|
-
'baseURL': defaultToConfig2,
|
2673
|
-
'transformRequest': defaultToConfig2,
|
2674
|
-
'transformResponse': defaultToConfig2,
|
2675
|
-
'paramsSerializer': defaultToConfig2,
|
2676
|
-
'timeout': defaultToConfig2,
|
2677
|
-
'timeoutMessage': defaultToConfig2,
|
2678
|
-
'withCredentials': defaultToConfig2,
|
2679
|
-
'adapter': defaultToConfig2,
|
2680
|
-
'responseType': defaultToConfig2,
|
2681
|
-
'xsrfCookieName': defaultToConfig2,
|
2682
|
-
'xsrfHeaderName': defaultToConfig2,
|
2683
|
-
'onUploadProgress': defaultToConfig2,
|
2684
|
-
'onDownloadProgress': defaultToConfig2,
|
2685
|
-
'decompress': defaultToConfig2,
|
2686
|
-
'maxContentLength': defaultToConfig2,
|
2687
|
-
'maxBodyLength': defaultToConfig2,
|
2688
|
-
'beforeRedirect': defaultToConfig2,
|
2689
|
-
'transport': defaultToConfig2,
|
2690
|
-
'httpAgent': defaultToConfig2,
|
2691
|
-
'httpsAgent': defaultToConfig2,
|
2692
|
-
'cancelToken': defaultToConfig2,
|
2693
|
-
'socketPath': defaultToConfig2,
|
2694
|
-
'responseEncoding': defaultToConfig2,
|
2695
|
-
'validateStatus': mergeDirectKeys
|
2696
|
-
};
|
2697
|
-
|
2698
|
-
utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
|
2699
|
-
const merge = mergeMap[prop] || mergeDeepProperties;
|
2700
|
-
const configValue = merge(prop);
|
2701
|
-
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
2702
|
-
});
|
2703
|
-
|
2704
|
-
return config;
|
2705
294
|
}
|
2706
295
|
|
2707
|
-
|
2708
|
-
|
2709
|
-
const validators$1 = {};
|
2710
|
-
|
2711
|
-
// eslint-disable-next-line func-names
|
2712
|
-
['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach((type, i) => {
|
2713
|
-
validators$1[type] = function validator(thing) {
|
2714
|
-
return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
|
2715
|
-
};
|
2716
|
-
});
|
2717
|
-
|
2718
|
-
const deprecatedWarnings = {};
|
2719
|
-
|
2720
|
-
/**
|
2721
|
-
* Transitional option validator
|
2722
|
-
*
|
2723
|
-
* @param {function|boolean?} validator - set to false if the transitional option has been removed
|
2724
|
-
* @param {string?} version - deprecated version / removed since version
|
2725
|
-
* @param {string?} message - some message with additional info
|
2726
|
-
*
|
2727
|
-
* @returns {function}
|
2728
|
-
*/
|
2729
|
-
validators$1.transitional = function transitional(validator, version, message) {
|
2730
|
-
function formatMessage(opt, desc) {
|
2731
|
-
return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
|
2732
|
-
}
|
2733
|
-
|
2734
|
-
// eslint-disable-next-line func-names
|
2735
|
-
return (value, opt, opts) => {
|
2736
|
-
if (validator === false) {
|
2737
|
-
throw new AxiosError(
|
2738
|
-
formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')),
|
2739
|
-
AxiosError.ERR_DEPRECATED
|
2740
|
-
);
|
2741
|
-
}
|
296
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
297
|
+
const isObject = (value) => value !== null && typeof value === 'object';
|
2742
298
|
|
2743
|
-
|
2744
|
-
|
2745
|
-
|
2746
|
-
|
2747
|
-
|
2748
|
-
opt,
|
2749
|
-
' has been deprecated since v' + version + ' and will be removed in the near future'
|
2750
|
-
)
|
2751
|
-
);
|
299
|
+
const validateAndMerge = (...sources) => {
|
300
|
+
for (const source of sources) {
|
301
|
+
if ((!isObject(source) || Array.isArray(source)) && typeof source !== 'undefined') {
|
302
|
+
throw new TypeError('The `options` argument must be an object');
|
303
|
+
}
|
2752
304
|
}
|
2753
|
-
|
2754
|
-
return validator ? validator(value, opt, opts) : true;
|
2755
|
-
};
|
305
|
+
return deepMerge({}, ...sources);
|
2756
306
|
};
|
2757
|
-
|
2758
|
-
|
2759
|
-
|
2760
|
-
|
2761
|
-
|
2762
|
-
|
2763
|
-
|
2764
|
-
|
2765
|
-
|
2766
|
-
|
2767
|
-
|
2768
|
-
function assertOptions(options, schema, allowUnknown) {
|
2769
|
-
if (typeof options !== 'object') {
|
2770
|
-
throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE);
|
2771
|
-
}
|
2772
|
-
const keys = Object.keys(options);
|
2773
|
-
let i = keys.length;
|
2774
|
-
while (i-- > 0) {
|
2775
|
-
const opt = keys[i];
|
2776
|
-
const validator = schema[opt];
|
2777
|
-
if (validator) {
|
2778
|
-
const value = options[opt];
|
2779
|
-
const result = value === undefined || validator(value, opt, options);
|
2780
|
-
if (result !== true) {
|
2781
|
-
throw new AxiosError('option ' + opt + ' must be ' + result, AxiosError.ERR_BAD_OPTION_VALUE);
|
2782
|
-
}
|
2783
|
-
continue;
|
2784
|
-
}
|
2785
|
-
if (allowUnknown !== true) {
|
2786
|
-
throw new AxiosError('Unknown option ' + opt, AxiosError.ERR_BAD_OPTION);
|
307
|
+
const mergeHeaders = (source1 = {}, source2 = {}) => {
|
308
|
+
const result = new globalThis.Headers(source1);
|
309
|
+
const isHeadersInstance = source2 instanceof globalThis.Headers;
|
310
|
+
const source = new globalThis.Headers(source2);
|
311
|
+
for (const [key, value] of source.entries()) {
|
312
|
+
if ((isHeadersInstance && value === 'undefined') || value === undefined) {
|
313
|
+
result.delete(key);
|
314
|
+
}
|
315
|
+
else {
|
316
|
+
result.set(key, value);
|
317
|
+
}
|
2787
318
|
}
|
2788
|
-
|
2789
|
-
}
|
2790
|
-
|
2791
|
-
const validator = {
|
2792
|
-
assertOptions,
|
2793
|
-
validators: validators$1
|
319
|
+
return result;
|
2794
320
|
};
|
2795
|
-
|
2796
|
-
const
|
2797
|
-
|
2798
|
-
|
2799
|
-
|
2800
|
-
|
2801
|
-
|
2802
|
-
|
2803
|
-
|
2804
|
-
|
2805
|
-
|
2806
|
-
|
2807
|
-
|
2808
|
-
|
2809
|
-
|
2810
|
-
|
2811
|
-
|
2812
|
-
|
2813
|
-
|
2814
|
-
|
2815
|
-
|
2816
|
-
|
2817
|
-
|
2818
|
-
* @param {?Object} config
|
2819
|
-
*
|
2820
|
-
* @returns {Promise} The Promise to be fulfilled
|
2821
|
-
*/
|
2822
|
-
request(configOrUrl, config) {
|
2823
|
-
/*eslint no-param-reassign:0*/
|
2824
|
-
// Allow for axios('example/url'[, config]) a la fetch API
|
2825
|
-
if (typeof configOrUrl === 'string') {
|
2826
|
-
config = config || {};
|
2827
|
-
config.url = configOrUrl;
|
2828
|
-
} else {
|
2829
|
-
config = configOrUrl || {};
|
2830
|
-
}
|
2831
|
-
|
2832
|
-
config = mergeConfig(this.defaults, config);
|
2833
|
-
|
2834
|
-
const transitional = config.transitional;
|
2835
|
-
|
2836
|
-
if (transitional !== undefined) {
|
2837
|
-
validator.assertOptions(transitional, {
|
2838
|
-
silentJSONParsing: validators.transitional(validators.boolean),
|
2839
|
-
forcedJSONParsing: validators.transitional(validators.boolean),
|
2840
|
-
clarifyTimeoutError: validators.transitional(validators.boolean)
|
2841
|
-
}, false);
|
2842
|
-
}
|
2843
|
-
|
2844
|
-
// Set config.method
|
2845
|
-
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
2846
|
-
|
2847
|
-
// Flatten headers
|
2848
|
-
const defaultHeaders = config.headers && utils.merge(
|
2849
|
-
config.headers.common,
|
2850
|
-
config.headers[config.method]
|
2851
|
-
);
|
2852
|
-
|
2853
|
-
defaultHeaders && utils.forEach(
|
2854
|
-
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
2855
|
-
function cleanHeaderConfig(method) {
|
2856
|
-
delete config.headers[method];
|
2857
|
-
}
|
2858
|
-
);
|
2859
|
-
|
2860
|
-
config.headers = new AxiosHeaders(config.headers, defaultHeaders);
|
2861
|
-
|
2862
|
-
// filter out skipped interceptors
|
2863
|
-
const requestInterceptorChain = [];
|
2864
|
-
let synchronousRequestInterceptors = true;
|
2865
|
-
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
2866
|
-
if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
|
2867
|
-
return;
|
2868
|
-
}
|
2869
|
-
|
2870
|
-
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
2871
|
-
|
2872
|
-
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
2873
|
-
});
|
2874
|
-
|
2875
|
-
const responseInterceptorChain = [];
|
2876
|
-
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
2877
|
-
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
2878
|
-
});
|
2879
|
-
|
2880
|
-
let promise;
|
2881
|
-
let i = 0;
|
2882
|
-
let len;
|
2883
|
-
|
2884
|
-
if (!synchronousRequestInterceptors) {
|
2885
|
-
const chain = [dispatchRequest.bind(this), undefined];
|
2886
|
-
chain.unshift.apply(chain, requestInterceptorChain);
|
2887
|
-
chain.push.apply(chain, responseInterceptorChain);
|
2888
|
-
len = chain.length;
|
2889
|
-
|
2890
|
-
promise = Promise.resolve(config);
|
2891
|
-
|
2892
|
-
while (i < len) {
|
2893
|
-
promise = promise.then(chain[i++], chain[i++]);
|
2894
|
-
}
|
2895
|
-
|
2896
|
-
return promise;
|
321
|
+
// TODO: Make this strongly-typed (no `any`).
|
322
|
+
const deepMerge = (...sources) => {
|
323
|
+
let returnValue = {};
|
324
|
+
let headers = {};
|
325
|
+
for (const source of sources) {
|
326
|
+
if (Array.isArray(source)) {
|
327
|
+
if (!Array.isArray(returnValue)) {
|
328
|
+
returnValue = [];
|
329
|
+
}
|
330
|
+
returnValue = [...returnValue, ...source];
|
331
|
+
}
|
332
|
+
else if (isObject(source)) {
|
333
|
+
for (let [key, value] of Object.entries(source)) {
|
334
|
+
if (isObject(value) && key in returnValue) {
|
335
|
+
value = deepMerge(returnValue[key], value);
|
336
|
+
}
|
337
|
+
returnValue = { ...returnValue, [key]: value };
|
338
|
+
}
|
339
|
+
if (isObject(source.headers)) {
|
340
|
+
headers = mergeHeaders(headers, source.headers);
|
341
|
+
returnValue.headers = headers;
|
342
|
+
}
|
343
|
+
}
|
2897
344
|
}
|
2898
|
-
|
2899
|
-
|
2900
|
-
|
2901
|
-
|
2902
|
-
|
2903
|
-
|
2904
|
-
|
2905
|
-
|
2906
|
-
|
2907
|
-
|
2908
|
-
|
2909
|
-
|
2910
|
-
|
2911
|
-
|
2912
|
-
|
2913
|
-
|
345
|
+
return returnValue;
|
346
|
+
};
|
347
|
+
|
348
|
+
const supportsStreams = (() => {
|
349
|
+
let duplexAccessed = false;
|
350
|
+
let hasContentType = false;
|
351
|
+
const supportsReadableStream = typeof globalThis.ReadableStream === 'function';
|
352
|
+
if (supportsReadableStream) {
|
353
|
+
hasContentType = new globalThis.Request('https://a.com', {
|
354
|
+
body: new globalThis.ReadableStream(),
|
355
|
+
method: 'POST',
|
356
|
+
// @ts-expect-error - Types are outdated.
|
357
|
+
get duplex() {
|
358
|
+
duplexAccessed = true;
|
359
|
+
return 'half';
|
360
|
+
},
|
361
|
+
}).headers.has('Content-Type');
|
2914
362
|
}
|
2915
|
-
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
2919
|
-
|
363
|
+
return duplexAccessed && !hasContentType;
|
364
|
+
})();
|
365
|
+
const supportsAbortController = typeof globalThis.AbortController === 'function';
|
366
|
+
const supportsFormData = typeof globalThis.FormData === 'function';
|
367
|
+
const requestMethods = ['get', 'post', 'put', 'patch', 'head', 'delete'];
|
368
|
+
const responseTypes = {
|
369
|
+
json: 'application/json',
|
370
|
+
text: 'text/*',
|
371
|
+
formData: 'multipart/form-data',
|
372
|
+
arrayBuffer: '*/*',
|
373
|
+
blob: '*/*',
|
374
|
+
};
|
375
|
+
// The maximum value of a 32bit int (see issue #117)
|
376
|
+
const maxSafeTimeout = 2147483647;
|
377
|
+
const stop = Symbol('stop');
|
378
|
+
|
379
|
+
const normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
|
380
|
+
const retryMethods = ['get', 'put', 'head', 'delete', 'options', 'trace'];
|
381
|
+
const retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
|
382
|
+
const retryAfterStatusCodes = [413, 429, 503];
|
383
|
+
const defaultRetryOptions = {
|
384
|
+
limit: 2,
|
385
|
+
methods: retryMethods,
|
386
|
+
statusCodes: retryStatusCodes,
|
387
|
+
afterStatusCodes: retryAfterStatusCodes,
|
388
|
+
maxRetryAfter: Number.POSITIVE_INFINITY,
|
389
|
+
};
|
390
|
+
const normalizeRetryOptions = (retry = {}) => {
|
391
|
+
if (typeof retry === 'number') {
|
392
|
+
return {
|
393
|
+
...defaultRetryOptions,
|
394
|
+
limit: retry,
|
395
|
+
};
|
2920
396
|
}
|
2921
|
-
|
2922
|
-
|
2923
|
-
len = responseInterceptorChain.length;
|
2924
|
-
|
2925
|
-
while (i < len) {
|
2926
|
-
promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
397
|
+
if (retry.methods && !Array.isArray(retry.methods)) {
|
398
|
+
throw new Error('retry.methods must be an array');
|
2927
399
|
}
|
2928
|
-
|
2929
|
-
|
2930
|
-
}
|
2931
|
-
|
2932
|
-
getUri(config) {
|
2933
|
-
config = mergeConfig(this.defaults, config);
|
2934
|
-
const fullPath = buildFullPath(config.baseURL, config.url);
|
2935
|
-
return buildURL(fullPath, config.params, config.paramsSerializer);
|
2936
|
-
}
|
2937
|
-
}
|
2938
|
-
|
2939
|
-
// Provide aliases for supported request methods
|
2940
|
-
utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
|
2941
|
-
/*eslint func-names:0*/
|
2942
|
-
Axios.prototype[method] = function(url, config) {
|
2943
|
-
return this.request(mergeConfig(config || {}, {
|
2944
|
-
method,
|
2945
|
-
url,
|
2946
|
-
data: (config || {}).data
|
2947
|
-
}));
|
2948
|
-
};
|
2949
|
-
});
|
2950
|
-
|
2951
|
-
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
2952
|
-
/*eslint func-names:0*/
|
2953
|
-
|
2954
|
-
function generateHTTPMethod(isForm) {
|
2955
|
-
return function httpMethod(url, data, config) {
|
2956
|
-
return this.request(mergeConfig(config || {}, {
|
2957
|
-
method,
|
2958
|
-
headers: isForm ? {
|
2959
|
-
'Content-Type': 'multipart/form-data'
|
2960
|
-
} : {},
|
2961
|
-
url,
|
2962
|
-
data
|
2963
|
-
}));
|
2964
|
-
};
|
2965
|
-
}
|
2966
|
-
|
2967
|
-
Axios.prototype[method] = generateHTTPMethod();
|
2968
|
-
|
2969
|
-
Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
2970
|
-
});
|
2971
|
-
|
2972
|
-
/**
|
2973
|
-
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
2974
|
-
*
|
2975
|
-
* @param {Function} executor The executor function.
|
2976
|
-
*
|
2977
|
-
* @returns {CancelToken}
|
2978
|
-
*/
|
2979
|
-
class CancelToken {
|
2980
|
-
constructor(executor) {
|
2981
|
-
if (typeof executor !== 'function') {
|
2982
|
-
throw new TypeError('executor must be a function.');
|
400
|
+
if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {
|
401
|
+
throw new Error('retry.statusCodes must be an array');
|
2983
402
|
}
|
2984
|
-
|
2985
|
-
|
2986
|
-
|
2987
|
-
|
2988
|
-
resolvePromise = resolve;
|
2989
|
-
});
|
2990
|
-
|
2991
|
-
const token = this;
|
2992
|
-
|
2993
|
-
// eslint-disable-next-line func-names
|
2994
|
-
this.promise.then(cancel => {
|
2995
|
-
if (!token._listeners) return;
|
2996
|
-
|
2997
|
-
let i = token._listeners.length;
|
2998
|
-
|
2999
|
-
while (i-- > 0) {
|
3000
|
-
token._listeners[i](cancel);
|
3001
|
-
}
|
3002
|
-
token._listeners = null;
|
3003
|
-
});
|
3004
|
-
|
3005
|
-
// eslint-disable-next-line func-names
|
3006
|
-
this.promise.then = onfulfilled => {
|
3007
|
-
let _resolve;
|
3008
|
-
// eslint-disable-next-line func-names
|
3009
|
-
const promise = new Promise(resolve => {
|
3010
|
-
token.subscribe(resolve);
|
3011
|
-
_resolve = resolve;
|
3012
|
-
}).then(onfulfilled);
|
3013
|
-
|
3014
|
-
promise.cancel = function reject() {
|
3015
|
-
token.unsubscribe(_resolve);
|
3016
|
-
};
|
3017
|
-
|
3018
|
-
return promise;
|
403
|
+
return {
|
404
|
+
...defaultRetryOptions,
|
405
|
+
...retry,
|
406
|
+
afterStatusCodes: retryAfterStatusCodes,
|
3019
407
|
};
|
408
|
+
};
|
3020
409
|
|
3021
|
-
|
3022
|
-
|
3023
|
-
|
3024
|
-
|
3025
|
-
|
3026
|
-
|
3027
|
-
|
3028
|
-
|
410
|
+
// `Promise.race()` workaround (#91)
|
411
|
+
const timeout = async (request, abortController, options) => new Promise((resolve, reject) => {
|
412
|
+
const timeoutId = setTimeout(() => {
|
413
|
+
if (abortController) {
|
414
|
+
abortController.abort();
|
415
|
+
}
|
416
|
+
reject(new TimeoutError(request));
|
417
|
+
}, options.timeout);
|
418
|
+
void options
|
419
|
+
.fetch(request)
|
420
|
+
.then(resolve)
|
421
|
+
.catch(reject)
|
422
|
+
.then(() => {
|
423
|
+
clearTimeout(timeoutId);
|
3029
424
|
});
|
3030
|
-
|
425
|
+
});
|
426
|
+
const delay = async (ms) => new Promise(resolve => {
|
427
|
+
setTimeout(resolve, ms);
|
428
|
+
});
|
3031
429
|
|
3032
|
-
|
3033
|
-
|
3034
|
-
|
3035
|
-
|
3036
|
-
|
3037
|
-
|
430
|
+
class Ky {
|
431
|
+
// eslint-disable-next-line complexity
|
432
|
+
constructor(input, options = {}) {
|
433
|
+
Object.defineProperty(this, "request", {
|
434
|
+
enumerable: true,
|
435
|
+
configurable: true,
|
436
|
+
writable: true,
|
437
|
+
value: void 0
|
438
|
+
});
|
439
|
+
Object.defineProperty(this, "abortController", {
|
440
|
+
enumerable: true,
|
441
|
+
configurable: true,
|
442
|
+
writable: true,
|
443
|
+
value: void 0
|
444
|
+
});
|
445
|
+
Object.defineProperty(this, "_retryCount", {
|
446
|
+
enumerable: true,
|
447
|
+
configurable: true,
|
448
|
+
writable: true,
|
449
|
+
value: 0
|
450
|
+
});
|
451
|
+
Object.defineProperty(this, "_input", {
|
452
|
+
enumerable: true,
|
453
|
+
configurable: true,
|
454
|
+
writable: true,
|
455
|
+
value: void 0
|
456
|
+
});
|
457
|
+
Object.defineProperty(this, "_options", {
|
458
|
+
enumerable: true,
|
459
|
+
configurable: true,
|
460
|
+
writable: true,
|
461
|
+
value: void 0
|
462
|
+
});
|
463
|
+
this._input = input;
|
464
|
+
this._options = {
|
465
|
+
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
|
466
|
+
credentials: this._input.credentials || 'same-origin',
|
467
|
+
...options,
|
468
|
+
headers: mergeHeaders(this._input.headers, options.headers),
|
469
|
+
hooks: deepMerge({
|
470
|
+
beforeRequest: [],
|
471
|
+
beforeRetry: [],
|
472
|
+
beforeError: [],
|
473
|
+
afterResponse: [],
|
474
|
+
}, options.hooks),
|
475
|
+
method: normalizeRequestMethod(options.method ?? this._input.method),
|
476
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
477
|
+
prefixUrl: String(options.prefixUrl || ''),
|
478
|
+
retry: normalizeRetryOptions(options.retry),
|
479
|
+
throwHttpErrors: options.throwHttpErrors !== false,
|
480
|
+
timeout: typeof options.timeout === 'undefined' ? 10000 : options.timeout,
|
481
|
+
fetch: options.fetch ?? globalThis.fetch.bind(globalThis),
|
482
|
+
};
|
483
|
+
if (typeof this._input !== 'string' && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {
|
484
|
+
throw new TypeError('`input` must be a string, URL, or Request');
|
485
|
+
}
|
486
|
+
if (this._options.prefixUrl && typeof this._input === 'string') {
|
487
|
+
if (this._input.startsWith('/')) {
|
488
|
+
throw new Error('`input` must not begin with a slash when using `prefixUrl`');
|
489
|
+
}
|
490
|
+
if (!this._options.prefixUrl.endsWith('/')) {
|
491
|
+
this._options.prefixUrl += '/';
|
492
|
+
}
|
493
|
+
this._input = this._options.prefixUrl + this._input;
|
494
|
+
}
|
495
|
+
if (supportsAbortController) {
|
496
|
+
this.abortController = new globalThis.AbortController();
|
497
|
+
if (this._options.signal) {
|
498
|
+
this._options.signal.addEventListener('abort', () => {
|
499
|
+
this.abortController.abort();
|
500
|
+
});
|
501
|
+
}
|
502
|
+
this._options.signal = this.abortController.signal;
|
503
|
+
}
|
504
|
+
this.request = new globalThis.Request(this._input, this._options);
|
505
|
+
if (supportsStreams) {
|
506
|
+
// @ts-expect-error - Types are outdated.
|
507
|
+
this.request.duplex = 'half';
|
508
|
+
}
|
509
|
+
if (this._options.searchParams) {
|
510
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
511
|
+
const textSearchParams = typeof this._options.searchParams === 'string'
|
512
|
+
? this._options.searchParams.replace(/^\?/, '')
|
513
|
+
: new URLSearchParams(this._options.searchParams).toString();
|
514
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
515
|
+
const searchParams = '?' + textSearchParams;
|
516
|
+
const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
|
517
|
+
// To provide correct form boundary, Content-Type header should be deleted each time when new Request instantiated from another one
|
518
|
+
if (((supportsFormData && this._options.body instanceof globalThis.FormData)
|
519
|
+
|| this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers['content-type'])) {
|
520
|
+
this.request.headers.delete('content-type');
|
521
|
+
}
|
522
|
+
this.request = new globalThis.Request(new globalThis.Request(url, this.request), this._options);
|
523
|
+
}
|
524
|
+
if (this._options.json !== undefined) {
|
525
|
+
this._options.body = JSON.stringify(this._options.json);
|
526
|
+
this.request.headers.set('content-type', this._options.headers.get('content-type') ?? 'application/json');
|
527
|
+
this.request = new globalThis.Request(this.request, { body: this._options.body });
|
528
|
+
}
|
3038
529
|
}
|
3039
|
-
|
3040
|
-
|
3041
|
-
|
3042
|
-
|
3043
|
-
|
3044
|
-
|
3045
|
-
|
3046
|
-
|
3047
|
-
|
3048
|
-
|
530
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
531
|
+
static create(input, options) {
|
532
|
+
const ky = new Ky(input, options);
|
533
|
+
const fn = async () => {
|
534
|
+
if (ky._options.timeout > maxSafeTimeout) {
|
535
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
|
536
|
+
}
|
537
|
+
// Delay the fetch so that body method shortcuts can set the Accept header
|
538
|
+
await Promise.resolve();
|
539
|
+
let response = await ky._fetch();
|
540
|
+
for (const hook of ky._options.hooks.afterResponse) {
|
541
|
+
// eslint-disable-next-line no-await-in-loop
|
542
|
+
const modifiedResponse = await hook(ky.request, ky._options, ky._decorateResponse(response.clone()));
|
543
|
+
if (modifiedResponse instanceof globalThis.Response) {
|
544
|
+
response = modifiedResponse;
|
545
|
+
}
|
546
|
+
}
|
547
|
+
ky._decorateResponse(response);
|
548
|
+
if (!response.ok && ky._options.throwHttpErrors) {
|
549
|
+
let error = new HTTPError(response, ky.request, ky._options);
|
550
|
+
for (const hook of ky._options.hooks.beforeError) {
|
551
|
+
// eslint-disable-next-line no-await-in-loop
|
552
|
+
error = await hook(error);
|
553
|
+
}
|
554
|
+
throw error;
|
555
|
+
}
|
556
|
+
// If `onDownloadProgress` is passed, it uses the stream API internally
|
557
|
+
/* istanbul ignore next */
|
558
|
+
if (ky._options.onDownloadProgress) {
|
559
|
+
if (typeof ky._options.onDownloadProgress !== 'function') {
|
560
|
+
throw new TypeError('The `onDownloadProgress` option must be a function');
|
561
|
+
}
|
562
|
+
if (!supportsStreams) {
|
563
|
+
throw new Error('Streams are not supported in your environment. `ReadableStream` is missing.');
|
564
|
+
}
|
565
|
+
return ky._stream(response.clone(), ky._options.onDownloadProgress);
|
566
|
+
}
|
567
|
+
return response;
|
568
|
+
};
|
569
|
+
const isRetriableMethod = ky._options.retry.methods.includes(ky.request.method.toLowerCase());
|
570
|
+
const result = (isRetriableMethod ? ky._retry(fn) : fn());
|
571
|
+
for (const [type, mimeType] of Object.entries(responseTypes)) {
|
572
|
+
result[type] = async () => {
|
573
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
574
|
+
ky.request.headers.set('accept', ky.request.headers.get('accept') || mimeType);
|
575
|
+
const awaitedResult = await result;
|
576
|
+
const response = awaitedResult.clone();
|
577
|
+
if (type === 'json') {
|
578
|
+
if (response.status === 204) {
|
579
|
+
return '';
|
580
|
+
}
|
581
|
+
if (options.parseJson) {
|
582
|
+
return options.parseJson(await response.text());
|
583
|
+
}
|
584
|
+
}
|
585
|
+
return response[type]();
|
586
|
+
};
|
587
|
+
}
|
588
|
+
return result;
|
589
|
+
}
|
590
|
+
_calculateRetryDelay(error) {
|
591
|
+
this._retryCount++;
|
592
|
+
if (this._retryCount < this._options.retry.limit && !(error instanceof TimeoutError)) {
|
593
|
+
if (error instanceof HTTPError) {
|
594
|
+
if (!this._options.retry.statusCodes.includes(error.response.status)) {
|
595
|
+
return 0;
|
596
|
+
}
|
597
|
+
const retryAfter = error.response.headers.get('Retry-After');
|
598
|
+
if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {
|
599
|
+
let after = Number(retryAfter);
|
600
|
+
if (Number.isNaN(after)) {
|
601
|
+
after = Date.parse(retryAfter) - Date.now();
|
602
|
+
}
|
603
|
+
else {
|
604
|
+
after *= 1000;
|
605
|
+
}
|
606
|
+
if (typeof this._options.retry.maxRetryAfter !== 'undefined' && after > this._options.retry.maxRetryAfter) {
|
607
|
+
return 0;
|
608
|
+
}
|
609
|
+
return after;
|
610
|
+
}
|
611
|
+
if (error.response.status === 413) {
|
612
|
+
return 0;
|
613
|
+
}
|
614
|
+
}
|
615
|
+
const BACKOFF_FACTOR = 0.3;
|
616
|
+
return BACKOFF_FACTOR * (2 ** (this._retryCount - 1)) * 1000;
|
617
|
+
}
|
618
|
+
return 0;
|
3049
619
|
}
|
3050
|
-
|
3051
|
-
|
3052
|
-
|
3053
|
-
|
3054
|
-
|
620
|
+
_decorateResponse(response) {
|
621
|
+
if (this._options.parseJson) {
|
622
|
+
response.json = async () => this._options.parseJson(await response.text());
|
623
|
+
}
|
624
|
+
return response;
|
3055
625
|
}
|
3056
|
-
|
3057
|
-
|
3058
|
-
|
3059
|
-
|
3060
|
-
|
3061
|
-
|
3062
|
-
|
3063
|
-
|
3064
|
-
|
626
|
+
async _retry(fn) {
|
627
|
+
try {
|
628
|
+
return await fn();
|
629
|
+
// eslint-disable-next-line @typescript-eslint/no-implicit-any-catch
|
630
|
+
}
|
631
|
+
catch (error) {
|
632
|
+
const ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);
|
633
|
+
if (ms !== 0 && this._retryCount > 0) {
|
634
|
+
await delay(ms);
|
635
|
+
for (const hook of this._options.hooks.beforeRetry) {
|
636
|
+
// eslint-disable-next-line no-await-in-loop
|
637
|
+
const hookResult = await hook({
|
638
|
+
request: this.request,
|
639
|
+
options: this._options,
|
640
|
+
error: error,
|
641
|
+
retryCount: this._retryCount,
|
642
|
+
});
|
643
|
+
// If `stop` is returned from the hook, the retry process is stopped
|
644
|
+
if (hookResult === stop) {
|
645
|
+
return;
|
646
|
+
}
|
647
|
+
}
|
648
|
+
return this._retry(fn);
|
649
|
+
}
|
650
|
+
throw error;
|
651
|
+
}
|
3065
652
|
}
|
3066
|
-
|
3067
|
-
|
3068
|
-
|
653
|
+
async _fetch() {
|
654
|
+
for (const hook of this._options.hooks.beforeRequest) {
|
655
|
+
// eslint-disable-next-line no-await-in-loop
|
656
|
+
const result = await hook(this.request, this._options);
|
657
|
+
if (result instanceof Request) {
|
658
|
+
this.request = result;
|
659
|
+
break;
|
660
|
+
}
|
661
|
+
if (result instanceof Response) {
|
662
|
+
return result;
|
663
|
+
}
|
664
|
+
}
|
665
|
+
if (this._options.timeout === false) {
|
666
|
+
return this._options.fetch(this.request.clone());
|
667
|
+
}
|
668
|
+
return timeout(this.request.clone(), this.abortController, this._options);
|
669
|
+
}
|
670
|
+
/* istanbul ignore next */
|
671
|
+
_stream(response, onDownloadProgress) {
|
672
|
+
const totalBytes = Number(response.headers.get('content-length')) || 0;
|
673
|
+
let transferredBytes = 0;
|
674
|
+
if (response.status === 204) {
|
675
|
+
if (onDownloadProgress) {
|
676
|
+
onDownloadProgress({ percent: 1, totalBytes, transferredBytes }, new Uint8Array());
|
677
|
+
}
|
678
|
+
return new globalThis.Response(null, {
|
679
|
+
status: response.status,
|
680
|
+
statusText: response.statusText,
|
681
|
+
headers: response.headers,
|
682
|
+
});
|
683
|
+
}
|
684
|
+
return new globalThis.Response(new globalThis.ReadableStream({
|
685
|
+
async start(controller) {
|
686
|
+
const reader = response.body.getReader();
|
687
|
+
if (onDownloadProgress) {
|
688
|
+
onDownloadProgress({ percent: 0, transferredBytes: 0, totalBytes }, new Uint8Array());
|
689
|
+
}
|
690
|
+
async function read() {
|
691
|
+
const { done, value } = await reader.read();
|
692
|
+
if (done) {
|
693
|
+
controller.close();
|
694
|
+
return;
|
695
|
+
}
|
696
|
+
if (onDownloadProgress) {
|
697
|
+
transferredBytes += value.byteLength;
|
698
|
+
const percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
|
699
|
+
onDownloadProgress({ percent, transferredBytes, totalBytes }, value);
|
700
|
+
}
|
701
|
+
controller.enqueue(value);
|
702
|
+
await read();
|
703
|
+
}
|
704
|
+
await read();
|
705
|
+
},
|
706
|
+
}), {
|
707
|
+
status: response.status,
|
708
|
+
statusText: response.statusText,
|
709
|
+
headers: response.headers,
|
710
|
+
});
|
3069
711
|
}
|
3070
|
-
}
|
3071
|
-
|
3072
|
-
/**
|
3073
|
-
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
3074
|
-
* cancels the `CancelToken`.
|
3075
|
-
*/
|
3076
|
-
static source() {
|
3077
|
-
let cancel;
|
3078
|
-
const token = new CancelToken(function executor(c) {
|
3079
|
-
cancel = c;
|
3080
|
-
});
|
3081
|
-
return {
|
3082
|
-
token,
|
3083
|
-
cancel
|
3084
|
-
};
|
3085
|
-
}
|
3086
|
-
}
|
3087
|
-
|
3088
|
-
/**
|
3089
|
-
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
3090
|
-
*
|
3091
|
-
* Common use case would be to use `Function.prototype.apply`.
|
3092
|
-
*
|
3093
|
-
* ```js
|
3094
|
-
* function f(x, y, z) {}
|
3095
|
-
* var args = [1, 2, 3];
|
3096
|
-
* f.apply(null, args);
|
3097
|
-
* ```
|
3098
|
-
*
|
3099
|
-
* With `spread` this example can be re-written.
|
3100
|
-
*
|
3101
|
-
* ```js
|
3102
|
-
* spread(function(x, y, z) {})([1, 2, 3]);
|
3103
|
-
* ```
|
3104
|
-
*
|
3105
|
-
* @param {Function} callback
|
3106
|
-
*
|
3107
|
-
* @returns {Function}
|
3108
|
-
*/
|
3109
|
-
function spread(callback) {
|
3110
|
-
return function wrap(arr) {
|
3111
|
-
return callback.apply(null, arr);
|
3112
|
-
};
|
3113
|
-
}
|
3114
|
-
|
3115
|
-
/**
|
3116
|
-
* Determines whether the payload is an error thrown by Axios
|
3117
|
-
*
|
3118
|
-
* @param {*} payload The value to test
|
3119
|
-
*
|
3120
|
-
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
3121
|
-
*/
|
3122
|
-
function isAxiosError(payload) {
|
3123
|
-
return utils.isObject(payload) && (payload.isAxiosError === true);
|
3124
|
-
}
|
3125
|
-
|
3126
|
-
/**
|
3127
|
-
* Create an instance of Axios
|
3128
|
-
*
|
3129
|
-
* @param {Object} defaultConfig The default config for the instance
|
3130
|
-
*
|
3131
|
-
* @returns {Axios} A new instance of Axios
|
3132
|
-
*/
|
3133
|
-
function createInstance(defaultConfig) {
|
3134
|
-
const context = new Axios(defaultConfig);
|
3135
|
-
const instance = bind(Axios.prototype.request, context);
|
3136
|
-
|
3137
|
-
// Copy axios.prototype to instance
|
3138
|
-
utils.extend(instance, Axios.prototype, context, {allOwnKeys: true});
|
3139
|
-
|
3140
|
-
// Copy context to instance
|
3141
|
-
utils.extend(instance, context, null, {allOwnKeys: true});
|
3142
|
-
|
3143
|
-
// Factory for creating new instances
|
3144
|
-
instance.create = function create(instanceConfig) {
|
3145
|
-
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
3146
|
-
};
|
3147
|
-
|
3148
|
-
return instance;
|
3149
712
|
}
|
3150
713
|
|
3151
|
-
|
3152
|
-
const
|
3153
|
-
|
3154
|
-
|
3155
|
-
|
3156
|
-
|
3157
|
-
|
3158
|
-
|
3159
|
-
|
3160
|
-
|
3161
|
-
|
3162
|
-
|
3163
|
-
|
3164
|
-
// Expose AxiosError class
|
3165
|
-
axios.AxiosError = AxiosError;
|
3166
|
-
|
3167
|
-
// alias for CanceledError for backward compatibility
|
3168
|
-
axios.Cancel = axios.CanceledError;
|
3169
|
-
|
3170
|
-
// Expose all/spread
|
3171
|
-
axios.all = function all(promises) {
|
3172
|
-
return Promise.all(promises);
|
3173
|
-
};
|
3174
|
-
|
3175
|
-
axios.spread = spread;
|
3176
|
-
|
3177
|
-
// Expose isAxiosError
|
3178
|
-
axios.isAxiosError = isAxiosError;
|
3179
|
-
|
3180
|
-
axios.formToJSON = thing => {
|
3181
|
-
return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
714
|
+
/*! MIT License © Sindre Sorhus */
|
715
|
+
const createInstance = (defaults) => {
|
716
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
717
|
+
const ky = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
|
718
|
+
for (const method of requestMethods) {
|
719
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
720
|
+
ky[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
|
721
|
+
}
|
722
|
+
ky.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
|
723
|
+
ky.extend = (newDefaults) => createInstance(validateAndMerge(defaults, newDefaults));
|
724
|
+
ky.stop = stop;
|
725
|
+
return ky;
|
3182
726
|
};
|
727
|
+
const ky = createInstance();
|
3183
728
|
|
3184
729
|
// --------------------------------------------------------[ mutable store ]
|
3185
730
|
const storeDef = {
|
@@ -3316,10 +861,17 @@ const processPick = (next) => {
|
|
3316
861
|
savePick(state.pick);
|
3317
862
|
};
|
3318
863
|
// --------------------------------------------------------[ utils ]
|
3319
|
-
const api =
|
3320
|
-
|
864
|
+
const api = ky.extend({
|
865
|
+
hooks: {
|
866
|
+
beforeRequest: [
|
867
|
+
request => {
|
868
|
+
request.headers.set('X-Requested-With', 'ky');
|
869
|
+
request.headers.set('X-Custom-Header', 'foobar');
|
870
|
+
},
|
871
|
+
],
|
872
|
+
},
|
873
|
+
prefixUrl: 'https://sudoku-rust-api.vercel.app/api',
|
3321
874
|
timeout: 10000,
|
3322
|
-
headers: { 'X-Custom-Header': 'foobar' },
|
3323
875
|
});
|
3324
876
|
const saveInputs = (inputs) => {
|
3325
877
|
bag.inputs.store(inputs);
|
@@ -3360,27 +912,26 @@ const initApp = () => {
|
|
3360
912
|
}
|
3361
913
|
}
|
3362
914
|
};
|
3363
|
-
const refresh = () => {
|
915
|
+
const refresh = async () => {
|
3364
916
|
clearStore(true);
|
3365
917
|
saveInputs([]);
|
3366
918
|
savePick(state.pick);
|
3367
|
-
|
3368
|
-
|
3369
|
-
.get('
|
3370
|
-
.then(({ data }) => {
|
919
|
+
try {
|
920
|
+
// fetch a new puzzle from the api...
|
921
|
+
const data = await api.get('puzzle').json();
|
3371
922
|
updateStore(data);
|
3372
|
-
}
|
3373
|
-
|
923
|
+
}
|
924
|
+
catch (err) {
|
3374
925
|
// handle error...
|
3375
|
-
const { message } =
|
926
|
+
const { message } = err;
|
3376
927
|
console.log('-- ', message);
|
3377
|
-
console.log(
|
928
|
+
console.log(err);
|
3378
929
|
state.error = message;
|
3379
|
-
}
|
3380
|
-
|
930
|
+
}
|
931
|
+
finally {
|
3381
932
|
// always executed
|
3382
933
|
state.loading = false;
|
3383
|
-
}
|
934
|
+
}
|
3384
935
|
};
|
3385
936
|
const select = (cell) => {
|
3386
937
|
processPick(cell);
|