proto-sudoku-wc 0.0.484 → 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 +477 -2007
- package/dist/collection/utils/store.js +22 -16
- package/dist/esm/proto-sudoku.entry.js +477 -2007
- 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 +3 -3
- package/dist/proto-sudoku-wc/p-72c4c8f5.entry.js +0 -1
@@ -250,2021 +250,485 @@ const createStore = (defaultState, shouldUpdate) => {
|
|
250
250
|
return map;
|
251
251
|
};
|
252
252
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
/**
|
284
|
-
* Determine if a value is an Array
|
285
|
-
*
|
286
|
-
* @param {Object} val The value to test
|
287
|
-
* @returns {boolean} True if value is an Array, otherwise false
|
288
|
-
*/
|
289
|
-
function isArray(val) {
|
290
|
-
return Array.isArray(val);
|
291
|
-
}
|
292
|
-
|
293
|
-
/**
|
294
|
-
* Determine if a value is undefined
|
295
|
-
*
|
296
|
-
* @param {Object} val The value to test
|
297
|
-
* @returns {boolean} True if the value is undefined, otherwise false
|
298
|
-
*/
|
299
|
-
function isUndefined(val) {
|
300
|
-
return typeof val === 'undefined';
|
301
|
-
}
|
302
|
-
|
303
|
-
/**
|
304
|
-
* Determine if a value is a Buffer
|
305
|
-
*
|
306
|
-
* @param {Object} val The value to test
|
307
|
-
* @returns {boolean} True if value is a Buffer, otherwise false
|
308
|
-
*/
|
309
|
-
function isBuffer(val) {
|
310
|
-
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
|
311
|
-
&& typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
|
312
|
-
}
|
313
|
-
|
314
|
-
/**
|
315
|
-
* Determine if a value is an ArrayBuffer
|
316
|
-
*
|
317
|
-
* @function
|
318
|
-
* @param {Object} val The value to test
|
319
|
-
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
320
|
-
*/
|
321
|
-
var isArrayBuffer = kindOfTest('ArrayBuffer');
|
322
|
-
|
323
|
-
|
324
|
-
/**
|
325
|
-
* Determine if a value is a view on an ArrayBuffer
|
326
|
-
*
|
327
|
-
* @param {Object} val The value to test
|
328
|
-
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
329
|
-
*/
|
330
|
-
function isArrayBufferView(val) {
|
331
|
-
var result;
|
332
|
-
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
333
|
-
result = ArrayBuffer.isView(val);
|
334
|
-
} else {
|
335
|
-
result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
|
336
|
-
}
|
337
|
-
return result;
|
338
|
-
}
|
339
|
-
|
340
|
-
/**
|
341
|
-
* Determine if a value is a String
|
342
|
-
*
|
343
|
-
* @param {Object} val The value to test
|
344
|
-
* @returns {boolean} True if value is a String, otherwise false
|
345
|
-
*/
|
346
|
-
function isString(val) {
|
347
|
-
return typeof val === 'string';
|
348
|
-
}
|
349
|
-
|
350
|
-
/**
|
351
|
-
* Determine if a value is a Number
|
352
|
-
*
|
353
|
-
* @param {Object} val The value to test
|
354
|
-
* @returns {boolean} True if value is a Number, otherwise false
|
355
|
-
*/
|
356
|
-
function isNumber(val) {
|
357
|
-
return typeof val === 'number';
|
358
|
-
}
|
359
|
-
|
360
|
-
/**
|
361
|
-
* Determine if a value is an Object
|
362
|
-
*
|
363
|
-
* @param {Object} val The value to test
|
364
|
-
* @returns {boolean} True if value is an Object, otherwise false
|
365
|
-
*/
|
366
|
-
function isObject(val) {
|
367
|
-
return val !== null && typeof val === 'object';
|
368
|
-
}
|
369
|
-
|
370
|
-
/**
|
371
|
-
* Determine if a value is a plain Object
|
372
|
-
*
|
373
|
-
* @param {Object} val The value to test
|
374
|
-
* @return {boolean} True if value is a plain Object, otherwise false
|
375
|
-
*/
|
376
|
-
function isPlainObject(val) {
|
377
|
-
if (kindOf(val) !== 'object') {
|
378
|
-
return false;
|
379
|
-
}
|
380
|
-
|
381
|
-
var prototype = Object.getPrototypeOf(val);
|
382
|
-
return prototype === null || prototype === Object.prototype;
|
383
|
-
}
|
384
|
-
|
385
|
-
/**
|
386
|
-
* Determine if a value is a Date
|
387
|
-
*
|
388
|
-
* @function
|
389
|
-
* @param {Object} val The value to test
|
390
|
-
* @returns {boolean} True if value is a Date, otherwise false
|
391
|
-
*/
|
392
|
-
var isDate = kindOfTest('Date');
|
393
|
-
|
394
|
-
/**
|
395
|
-
* Determine if a value is a File
|
396
|
-
*
|
397
|
-
* @function
|
398
|
-
* @param {Object} val The value to test
|
399
|
-
* @returns {boolean} True if value is a File, otherwise false
|
400
|
-
*/
|
401
|
-
var isFile = kindOfTest('File');
|
402
|
-
|
403
|
-
/**
|
404
|
-
* Determine if a value is a Blob
|
405
|
-
*
|
406
|
-
* @function
|
407
|
-
* @param {Object} val The value to test
|
408
|
-
* @returns {boolean} True if value is a Blob, otherwise false
|
409
|
-
*/
|
410
|
-
var isBlob = kindOfTest('Blob');
|
411
|
-
|
412
|
-
/**
|
413
|
-
* Determine if a value is a FileList
|
414
|
-
*
|
415
|
-
* @function
|
416
|
-
* @param {Object} val The value to test
|
417
|
-
* @returns {boolean} True if value is a File, otherwise false
|
418
|
-
*/
|
419
|
-
var isFileList = kindOfTest('FileList');
|
420
|
-
|
421
|
-
/**
|
422
|
-
* Determine if a value is a Function
|
423
|
-
*
|
424
|
-
* @param {Object} val The value to test
|
425
|
-
* @returns {boolean} True if value is a Function, otherwise false
|
426
|
-
*/
|
427
|
-
function isFunction(val) {
|
428
|
-
return toString.call(val) === '[object Function]';
|
429
|
-
}
|
430
|
-
|
431
|
-
/**
|
432
|
-
* Determine if a value is a Stream
|
433
|
-
*
|
434
|
-
* @param {Object} val The value to test
|
435
|
-
* @returns {boolean} True if value is a Stream, otherwise false
|
436
|
-
*/
|
437
|
-
function isStream(val) {
|
438
|
-
return isObject(val) && isFunction(val.pipe);
|
439
|
-
}
|
440
|
-
|
441
|
-
/**
|
442
|
-
* Determine if a value is a FormData
|
443
|
-
*
|
444
|
-
* @param {Object} thing The value to test
|
445
|
-
* @returns {boolean} True if value is an FormData, otherwise false
|
446
|
-
*/
|
447
|
-
function isFormData(thing) {
|
448
|
-
var pattern = '[object FormData]';
|
449
|
-
return thing && (
|
450
|
-
(typeof FormData === 'function' && thing instanceof FormData) ||
|
451
|
-
toString.call(thing) === pattern ||
|
452
|
-
(isFunction(thing.toString) && thing.toString() === pattern)
|
453
|
-
);
|
454
|
-
}
|
455
|
-
|
456
|
-
/**
|
457
|
-
* Determine if a value is a URLSearchParams object
|
458
|
-
* @function
|
459
|
-
* @param {Object} val The value to test
|
460
|
-
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
461
|
-
*/
|
462
|
-
var isURLSearchParams = kindOfTest('URLSearchParams');
|
463
|
-
|
464
|
-
/**
|
465
|
-
* Trim excess whitespace off the beginning and end of a string
|
466
|
-
*
|
467
|
-
* @param {String} str The String to trim
|
468
|
-
* @returns {String} The String freed of excess whitespace
|
469
|
-
*/
|
470
|
-
function trim(str) {
|
471
|
-
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '');
|
472
|
-
}
|
473
|
-
|
474
|
-
/**
|
475
|
-
* Determine if we're running in a standard browser environment
|
476
|
-
*
|
477
|
-
* This allows axios to run in a web worker, and react-native.
|
478
|
-
* Both environments support XMLHttpRequest, but not fully standard globals.
|
479
|
-
*
|
480
|
-
* web workers:
|
481
|
-
* typeof window -> undefined
|
482
|
-
* typeof document -> undefined
|
483
|
-
*
|
484
|
-
* react-native:
|
485
|
-
* navigator.product -> 'ReactNative'
|
486
|
-
* nativescript
|
487
|
-
* navigator.product -> 'NativeScript' or 'NS'
|
488
|
-
*/
|
489
|
-
function isStandardBrowserEnv() {
|
490
|
-
if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' ||
|
491
|
-
navigator.product === 'NativeScript' ||
|
492
|
-
navigator.product === 'NS')) {
|
493
|
-
return false;
|
494
|
-
}
|
495
|
-
return (
|
496
|
-
typeof window !== 'undefined' &&
|
497
|
-
typeof document !== 'undefined'
|
498
|
-
);
|
499
|
-
}
|
500
|
-
|
501
|
-
/**
|
502
|
-
* Iterate over an Array or an Object invoking a function for each item.
|
503
|
-
*
|
504
|
-
* If `obj` is an Array callback will be called passing
|
505
|
-
* the value, index, and complete array for each item.
|
506
|
-
*
|
507
|
-
* If 'obj' is an Object callback will be called passing
|
508
|
-
* the value, key, and complete object for each property.
|
509
|
-
*
|
510
|
-
* @param {Object|Array} obj The object to iterate
|
511
|
-
* @param {Function} fn The callback to invoke for each item
|
512
|
-
*/
|
513
|
-
function forEach(obj, fn) {
|
514
|
-
// Don't bother if no value provided
|
515
|
-
if (obj === null || typeof obj === 'undefined') {
|
516
|
-
return;
|
517
|
-
}
|
518
|
-
|
519
|
-
// Force an array if not already something iterable
|
520
|
-
if (typeof obj !== 'object') {
|
521
|
-
/*eslint no-param-reassign:0*/
|
522
|
-
obj = [obj];
|
523
|
-
}
|
524
|
-
|
525
|
-
if (isArray(obj)) {
|
526
|
-
// Iterate over array values
|
527
|
-
for (var i = 0, l = obj.length; i < l; i++) {
|
528
|
-
fn.call(null, obj[i], i, obj);
|
529
|
-
}
|
530
|
-
} else {
|
531
|
-
// Iterate over object keys
|
532
|
-
for (var key in obj) {
|
533
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
534
|
-
fn.call(null, obj[key], key, obj);
|
535
|
-
}
|
536
|
-
}
|
537
|
-
}
|
538
|
-
}
|
539
|
-
|
540
|
-
/**
|
541
|
-
* Accepts varargs expecting each argument to be an object, then
|
542
|
-
* immutably merges the properties of each object and returns result.
|
543
|
-
*
|
544
|
-
* When multiple objects contain the same key the later object in
|
545
|
-
* the arguments list will take precedence.
|
546
|
-
*
|
547
|
-
* Example:
|
548
|
-
*
|
549
|
-
* ```js
|
550
|
-
* var result = merge({foo: 123}, {foo: 456});
|
551
|
-
* console.log(result.foo); // outputs 456
|
552
|
-
* ```
|
553
|
-
*
|
554
|
-
* @param {Object} obj1 Object to merge
|
555
|
-
* @returns {Object} Result of all merge properties
|
556
|
-
*/
|
557
|
-
function merge(/* obj1, obj2, obj3, ... */) {
|
558
|
-
var result = {};
|
559
|
-
function assignValue(val, key) {
|
560
|
-
if (isPlainObject(result[key]) && isPlainObject(val)) {
|
561
|
-
result[key] = merge(result[key], val);
|
562
|
-
} else if (isPlainObject(val)) {
|
563
|
-
result[key] = merge({}, val);
|
564
|
-
} else if (isArray(val)) {
|
565
|
-
result[key] = val.slice();
|
566
|
-
} else {
|
567
|
-
result[key] = val;
|
568
|
-
}
|
569
|
-
}
|
570
|
-
|
571
|
-
for (var i = 0, l = arguments.length; i < l; i++) {
|
572
|
-
forEach(arguments[i], assignValue);
|
573
|
-
}
|
574
|
-
return result;
|
575
|
-
}
|
576
|
-
|
577
|
-
/**
|
578
|
-
* Extends object a by mutably adding to it the properties of object b.
|
579
|
-
*
|
580
|
-
* @param {Object} a The object to be extended
|
581
|
-
* @param {Object} b The object to copy properties from
|
582
|
-
* @param {Object} thisArg The object to bind function to
|
583
|
-
* @return {Object} The resulting value of object a
|
584
|
-
*/
|
585
|
-
function extend(a, b, thisArg) {
|
586
|
-
forEach(b, function assignValue(val, key) {
|
587
|
-
if (thisArg && typeof val === 'function') {
|
588
|
-
a[key] = bind(val, thisArg);
|
589
|
-
} else {
|
590
|
-
a[key] = val;
|
591
|
-
}
|
592
|
-
});
|
593
|
-
return a;
|
594
|
-
}
|
595
|
-
|
596
|
-
/**
|
597
|
-
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
598
|
-
*
|
599
|
-
* @param {string} content with BOM
|
600
|
-
* @return {string} content value without BOM
|
601
|
-
*/
|
602
|
-
function stripBOM(content) {
|
603
|
-
if (content.charCodeAt(0) === 0xFEFF) {
|
604
|
-
content = content.slice(1);
|
605
|
-
}
|
606
|
-
return content;
|
607
|
-
}
|
608
|
-
|
609
|
-
/**
|
610
|
-
* Inherit the prototype methods from one constructor into another
|
611
|
-
* @param {function} constructor
|
612
|
-
* @param {function} superConstructor
|
613
|
-
* @param {object} [props]
|
614
|
-
* @param {object} [descriptors]
|
615
|
-
*/
|
616
|
-
|
617
|
-
function inherits(constructor, superConstructor, props, descriptors) {
|
618
|
-
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
619
|
-
constructor.prototype.constructor = constructor;
|
620
|
-
props && Object.assign(constructor.prototype, props);
|
621
|
-
}
|
622
|
-
|
623
|
-
/**
|
624
|
-
* Resolve object with deep prototype chain to a flat object
|
625
|
-
* @param {Object} sourceObj source object
|
626
|
-
* @param {Object} [destObj]
|
627
|
-
* @param {Function} [filter]
|
628
|
-
* @returns {Object}
|
629
|
-
*/
|
630
|
-
|
631
|
-
function toFlatObject(sourceObj, destObj, filter) {
|
632
|
-
var props;
|
633
|
-
var i;
|
634
|
-
var prop;
|
635
|
-
var merged = {};
|
636
|
-
|
637
|
-
destObj = destObj || {};
|
638
|
-
|
639
|
-
do {
|
640
|
-
props = Object.getOwnPropertyNames(sourceObj);
|
641
|
-
i = props.length;
|
642
|
-
while (i-- > 0) {
|
643
|
-
prop = props[i];
|
644
|
-
if (!merged[prop]) {
|
645
|
-
destObj[prop] = sourceObj[prop];
|
646
|
-
merged[prop] = true;
|
647
|
-
}
|
648
|
-
}
|
649
|
-
sourceObj = Object.getPrototypeOf(sourceObj);
|
650
|
-
} while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
651
|
-
|
652
|
-
return destObj;
|
653
|
-
}
|
654
|
-
|
655
|
-
/*
|
656
|
-
* determines whether a string ends with the characters of a specified string
|
657
|
-
* @param {String} str
|
658
|
-
* @param {String} searchString
|
659
|
-
* @param {Number} [position= 0]
|
660
|
-
* @returns {boolean}
|
661
|
-
*/
|
662
|
-
function endsWith(str, searchString, position) {
|
663
|
-
str = String(str);
|
664
|
-
if (position === undefined || position > str.length) {
|
665
|
-
position = str.length;
|
666
|
-
}
|
667
|
-
position -= searchString.length;
|
668
|
-
var lastIndex = str.indexOf(searchString, position);
|
669
|
-
return lastIndex !== -1 && lastIndex === position;
|
670
|
-
}
|
671
|
-
|
672
|
-
|
673
|
-
/**
|
674
|
-
* Returns new array from array like object
|
675
|
-
* @param {*} [thing]
|
676
|
-
* @returns {Array}
|
677
|
-
*/
|
678
|
-
function toArray(thing) {
|
679
|
-
if (!thing) return null;
|
680
|
-
var i = thing.length;
|
681
|
-
if (isUndefined(i)) return null;
|
682
|
-
var arr = new Array(i);
|
683
|
-
while (i-- > 0) {
|
684
|
-
arr[i] = thing[i];
|
685
|
-
}
|
686
|
-
return arr;
|
687
|
-
}
|
688
|
-
|
689
|
-
// eslint-disable-next-line func-names
|
690
|
-
var isTypedArray = (function(TypedArray) {
|
691
|
-
// eslint-disable-next-line func-names
|
692
|
-
return function(thing) {
|
693
|
-
return TypedArray && thing instanceof TypedArray;
|
694
|
-
};
|
695
|
-
})(typeof Uint8Array !== 'undefined' && Object.getPrototypeOf(Uint8Array));
|
696
|
-
|
697
|
-
var utils = {
|
698
|
-
isArray: isArray,
|
699
|
-
isArrayBuffer: isArrayBuffer,
|
700
|
-
isBuffer: isBuffer,
|
701
|
-
isFormData: isFormData,
|
702
|
-
isArrayBufferView: isArrayBufferView,
|
703
|
-
isString: isString,
|
704
|
-
isNumber: isNumber,
|
705
|
-
isObject: isObject,
|
706
|
-
isPlainObject: isPlainObject,
|
707
|
-
isUndefined: isUndefined,
|
708
|
-
isDate: isDate,
|
709
|
-
isFile: isFile,
|
710
|
-
isBlob: isBlob,
|
711
|
-
isFunction: isFunction,
|
712
|
-
isStream: isStream,
|
713
|
-
isURLSearchParams: isURLSearchParams,
|
714
|
-
isStandardBrowserEnv: isStandardBrowserEnv,
|
715
|
-
forEach: forEach,
|
716
|
-
merge: merge,
|
717
|
-
extend: extend,
|
718
|
-
trim: trim,
|
719
|
-
stripBOM: stripBOM,
|
720
|
-
inherits: inherits,
|
721
|
-
toFlatObject: toFlatObject,
|
722
|
-
kindOf: kindOf,
|
723
|
-
kindOfTest: kindOfTest,
|
724
|
-
endsWith: endsWith,
|
725
|
-
toArray: toArray,
|
726
|
-
isTypedArray: isTypedArray,
|
727
|
-
isFileList: isFileList
|
728
|
-
};
|
729
|
-
|
730
|
-
function encode(val) {
|
731
|
-
return encodeURIComponent(val).
|
732
|
-
replace(/%3A/gi, ':').
|
733
|
-
replace(/%24/g, '$').
|
734
|
-
replace(/%2C/gi, ',').
|
735
|
-
replace(/%20/g, '+').
|
736
|
-
replace(/%5B/gi, '[').
|
737
|
-
replace(/%5D/gi, ']');
|
738
|
-
}
|
739
|
-
|
740
|
-
/**
|
741
|
-
* Build a URL by appending params to the end
|
742
|
-
*
|
743
|
-
* @param {string} url The base of the url (e.g., http://www.google.com)
|
744
|
-
* @param {object} [params] The params to be appended
|
745
|
-
* @returns {string} The formatted url
|
746
|
-
*/
|
747
|
-
var buildURL = function buildURL(url, params, paramsSerializer) {
|
748
|
-
/*eslint no-param-reassign:0*/
|
749
|
-
if (!params) {
|
750
|
-
return url;
|
751
|
-
}
|
752
|
-
|
753
|
-
var serializedParams;
|
754
|
-
if (paramsSerializer) {
|
755
|
-
serializedParams = paramsSerializer(params);
|
756
|
-
} else if (utils.isURLSearchParams(params)) {
|
757
|
-
serializedParams = params.toString();
|
758
|
-
} else {
|
759
|
-
var parts = [];
|
760
|
-
|
761
|
-
utils.forEach(params, function serialize(val, key) {
|
762
|
-
if (val === null || typeof val === 'undefined') {
|
763
|
-
return;
|
764
|
-
}
|
765
|
-
|
766
|
-
if (utils.isArray(val)) {
|
767
|
-
key = key + '[]';
|
768
|
-
} else {
|
769
|
-
val = [val];
|
770
|
-
}
|
771
|
-
|
772
|
-
utils.forEach(val, function parseValue(v) {
|
773
|
-
if (utils.isDate(v)) {
|
774
|
-
v = v.toISOString();
|
775
|
-
} else if (utils.isObject(v)) {
|
776
|
-
v = JSON.stringify(v);
|
777
|
-
}
|
778
|
-
parts.push(encode(key) + '=' + encode(v));
|
779
|
-
});
|
780
|
-
});
|
781
|
-
|
782
|
-
serializedParams = parts.join('&');
|
783
|
-
}
|
784
|
-
|
785
|
-
if (serializedParams) {
|
786
|
-
var hashmarkIndex = url.indexOf('#');
|
787
|
-
if (hashmarkIndex !== -1) {
|
788
|
-
url = url.slice(0, hashmarkIndex);
|
789
|
-
}
|
790
|
-
|
791
|
-
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
792
|
-
}
|
793
|
-
|
794
|
-
return url;
|
795
|
-
};
|
796
|
-
|
797
|
-
function InterceptorManager() {
|
798
|
-
this.handlers = [];
|
799
|
-
}
|
800
|
-
|
801
|
-
/**
|
802
|
-
* Add a new interceptor to the stack
|
803
|
-
*
|
804
|
-
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
805
|
-
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
806
|
-
*
|
807
|
-
* @return {Number} An ID used to remove interceptor later
|
808
|
-
*/
|
809
|
-
InterceptorManager.prototype.use = function use(fulfilled, rejected, options) {
|
810
|
-
this.handlers.push({
|
811
|
-
fulfilled: fulfilled,
|
812
|
-
rejected: rejected,
|
813
|
-
synchronous: options ? options.synchronous : false,
|
814
|
-
runWhen: options ? options.runWhen : null
|
815
|
-
});
|
816
|
-
return this.handlers.length - 1;
|
817
|
-
};
|
818
|
-
|
819
|
-
/**
|
820
|
-
* Remove an interceptor from the stack
|
821
|
-
*
|
822
|
-
* @param {Number} id The ID that was returned by `use`
|
823
|
-
*/
|
824
|
-
InterceptorManager.prototype.eject = function eject(id) {
|
825
|
-
if (this.handlers[id]) {
|
826
|
-
this.handlers[id] = null;
|
827
|
-
}
|
828
|
-
};
|
829
|
-
|
830
|
-
/**
|
831
|
-
* Iterate over all the registered interceptors
|
832
|
-
*
|
833
|
-
* This method is particularly useful for skipping over any
|
834
|
-
* interceptors that may have become `null` calling `eject`.
|
835
|
-
*
|
836
|
-
* @param {Function} fn The function to call for each interceptor
|
837
|
-
*/
|
838
|
-
InterceptorManager.prototype.forEach = function forEach(fn) {
|
839
|
-
utils.forEach(this.handlers, function forEachHandler(h) {
|
840
|
-
if (h !== null) {
|
841
|
-
fn(h);
|
842
|
-
}
|
843
|
-
});
|
844
|
-
};
|
845
|
-
|
846
|
-
var InterceptorManager_1 = InterceptorManager;
|
847
|
-
|
848
|
-
var normalizeHeaderName = function normalizeHeaderName(headers, normalizedName) {
|
849
|
-
utils.forEach(headers, function processHeader(value, name) {
|
850
|
-
if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
|
851
|
-
headers[normalizedName] = value;
|
852
|
-
delete headers[name];
|
853
|
-
}
|
854
|
-
});
|
855
|
-
};
|
856
|
-
|
857
|
-
/**
|
858
|
-
* Create an Error with the specified message, config, error code, request and response.
|
859
|
-
*
|
860
|
-
* @param {string} message The error message.
|
861
|
-
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
862
|
-
* @param {Object} [config] The config.
|
863
|
-
* @param {Object} [request] The request.
|
864
|
-
* @param {Object} [response] The response.
|
865
|
-
* @returns {Error} The created error.
|
866
|
-
*/
|
867
|
-
function AxiosError(message, code, config, request, response) {
|
868
|
-
Error.call(this);
|
869
|
-
this.message = message;
|
870
|
-
this.name = 'AxiosError';
|
871
|
-
code && (this.code = code);
|
872
|
-
config && (this.config = config);
|
873
|
-
request && (this.request = request);
|
874
|
-
response && (this.response = response);
|
875
|
-
}
|
876
|
-
|
877
|
-
utils.inherits(AxiosError, Error, {
|
878
|
-
toJSON: function toJSON() {
|
879
|
-
return {
|
880
|
-
// Standard
|
881
|
-
message: this.message,
|
882
|
-
name: this.name,
|
883
|
-
// Microsoft
|
884
|
-
description: this.description,
|
885
|
-
number: this.number,
|
886
|
-
// Mozilla
|
887
|
-
fileName: this.fileName,
|
888
|
-
lineNumber: this.lineNumber,
|
889
|
-
columnNumber: this.columnNumber,
|
890
|
-
stack: this.stack,
|
891
|
-
// Axios
|
892
|
-
config: this.config,
|
893
|
-
code: this.code,
|
894
|
-
status: this.response && this.response.status ? this.response.status : null
|
895
|
-
};
|
896
|
-
}
|
897
|
-
});
|
898
|
-
|
899
|
-
var prototype = AxiosError.prototype;
|
900
|
-
var descriptors = {};
|
901
|
-
|
902
|
-
[
|
903
|
-
'ERR_BAD_OPTION_VALUE',
|
904
|
-
'ERR_BAD_OPTION',
|
905
|
-
'ECONNABORTED',
|
906
|
-
'ETIMEDOUT',
|
907
|
-
'ERR_NETWORK',
|
908
|
-
'ERR_FR_TOO_MANY_REDIRECTS',
|
909
|
-
'ERR_DEPRECATED',
|
910
|
-
'ERR_BAD_RESPONSE',
|
911
|
-
'ERR_BAD_REQUEST',
|
912
|
-
'ERR_CANCELED'
|
913
|
-
// eslint-disable-next-line func-names
|
914
|
-
].forEach(function(code) {
|
915
|
-
descriptors[code] = {value: code};
|
916
|
-
});
|
917
|
-
|
918
|
-
Object.defineProperties(AxiosError, descriptors);
|
919
|
-
Object.defineProperty(prototype, 'isAxiosError', {value: true});
|
920
|
-
|
921
|
-
// eslint-disable-next-line func-names
|
922
|
-
AxiosError.from = function(error, code, config, request, response, customProps) {
|
923
|
-
var axiosError = Object.create(prototype);
|
924
|
-
|
925
|
-
utils.toFlatObject(error, axiosError, function filter(obj) {
|
926
|
-
return obj !== Error.prototype;
|
927
|
-
});
|
928
|
-
|
929
|
-
AxiosError.call(axiosError, error.message, code, config, request, response);
|
930
|
-
|
931
|
-
axiosError.name = error.name;
|
932
|
-
|
933
|
-
customProps && Object.assign(axiosError, customProps);
|
934
|
-
|
935
|
-
return axiosError;
|
936
|
-
};
|
937
|
-
|
938
|
-
var AxiosError_1 = AxiosError;
|
939
|
-
|
940
|
-
var transitional = {
|
941
|
-
silentJSONParsing: true,
|
942
|
-
forcedJSONParsing: true,
|
943
|
-
clarifyTimeoutError: false
|
944
|
-
};
|
945
|
-
|
946
|
-
/**
|
947
|
-
* Convert a data object to FormData
|
948
|
-
* @param {Object} obj
|
949
|
-
* @param {?Object} [formData]
|
950
|
-
* @returns {Object}
|
951
|
-
**/
|
952
|
-
|
953
|
-
function toFormData(obj, formData) {
|
954
|
-
// eslint-disable-next-line no-param-reassign
|
955
|
-
formData = formData || new FormData();
|
956
|
-
|
957
|
-
var stack = [];
|
958
|
-
|
959
|
-
function convertValue(value) {
|
960
|
-
if (value === null) return '';
|
961
|
-
|
962
|
-
if (utils.isDate(value)) {
|
963
|
-
return value.toISOString();
|
964
|
-
}
|
965
|
-
|
966
|
-
if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) {
|
967
|
-
return typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
|
968
|
-
}
|
969
|
-
|
970
|
-
return value;
|
971
|
-
}
|
972
|
-
|
973
|
-
function build(data, parentKey) {
|
974
|
-
if (utils.isPlainObject(data) || utils.isArray(data)) {
|
975
|
-
if (stack.indexOf(data) !== -1) {
|
976
|
-
throw Error('Circular reference detected in ' + parentKey);
|
977
|
-
}
|
978
|
-
|
979
|
-
stack.push(data);
|
980
|
-
|
981
|
-
utils.forEach(data, function each(value, key) {
|
982
|
-
if (utils.isUndefined(value)) return;
|
983
|
-
var fullKey = parentKey ? parentKey + '.' + key : key;
|
984
|
-
var arr;
|
985
|
-
|
986
|
-
if (value && !parentKey && typeof value === 'object') {
|
987
|
-
if (utils.endsWith(key, '{}')) {
|
988
|
-
// eslint-disable-next-line no-param-reassign
|
989
|
-
value = JSON.stringify(value);
|
990
|
-
} else if (utils.endsWith(key, '[]') && (arr = utils.toArray(value))) {
|
991
|
-
// eslint-disable-next-line func-names
|
992
|
-
arr.forEach(function(el) {
|
993
|
-
!utils.isUndefined(el) && formData.append(fullKey, convertValue(el));
|
994
|
-
});
|
995
|
-
return;
|
996
|
-
}
|
997
|
-
}
|
998
|
-
|
999
|
-
build(value, fullKey);
|
1000
|
-
});
|
1001
|
-
|
1002
|
-
stack.pop();
|
1003
|
-
} else {
|
1004
|
-
formData.append(parentKey, convertValue(data));
|
1005
|
-
}
|
1006
|
-
}
|
1007
|
-
|
1008
|
-
build(obj);
|
1009
|
-
|
1010
|
-
return formData;
|
1011
|
-
}
|
1012
|
-
|
1013
|
-
var toFormData_1 = toFormData;
|
1014
|
-
|
1015
|
-
/**
|
1016
|
-
* Resolve or reject a Promise based on response status.
|
1017
|
-
*
|
1018
|
-
* @param {Function} resolve A function that resolves the promise.
|
1019
|
-
* @param {Function} reject A function that rejects the promise.
|
1020
|
-
* @param {object} response The response.
|
1021
|
-
*/
|
1022
|
-
var settle = function settle(resolve, reject, response) {
|
1023
|
-
var validateStatus = response.config.validateStatus;
|
1024
|
-
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
1025
|
-
resolve(response);
|
1026
|
-
} else {
|
1027
|
-
reject(new AxiosError_1(
|
1028
|
-
'Request failed with status code ' + response.status,
|
1029
|
-
[AxiosError_1.ERR_BAD_REQUEST, AxiosError_1.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
|
1030
|
-
response.config,
|
1031
|
-
response.request,
|
1032
|
-
response
|
1033
|
-
));
|
1034
|
-
}
|
1035
|
-
};
|
1036
|
-
|
1037
|
-
var cookies = (
|
1038
|
-
utils.isStandardBrowserEnv() ?
|
1039
|
-
|
1040
|
-
// Standard browser envs support document.cookie
|
1041
|
-
(function standardBrowserEnv() {
|
1042
|
-
return {
|
1043
|
-
write: function write(name, value, expires, path, domain, secure) {
|
1044
|
-
var cookie = [];
|
1045
|
-
cookie.push(name + '=' + encodeURIComponent(value));
|
1046
|
-
|
1047
|
-
if (utils.isNumber(expires)) {
|
1048
|
-
cookie.push('expires=' + new Date(expires).toGMTString());
|
1049
|
-
}
|
1050
|
-
|
1051
|
-
if (utils.isString(path)) {
|
1052
|
-
cookie.push('path=' + path);
|
1053
|
-
}
|
1054
|
-
|
1055
|
-
if (utils.isString(domain)) {
|
1056
|
-
cookie.push('domain=' + domain);
|
1057
|
-
}
|
1058
|
-
|
1059
|
-
if (secure === true) {
|
1060
|
-
cookie.push('secure');
|
1061
|
-
}
|
1062
|
-
|
1063
|
-
document.cookie = cookie.join('; ');
|
1064
|
-
},
|
1065
|
-
|
1066
|
-
read: function read(name) {
|
1067
|
-
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
1068
|
-
return (match ? decodeURIComponent(match[3]) : null);
|
1069
|
-
},
|
1070
|
-
|
1071
|
-
remove: function remove(name) {
|
1072
|
-
this.write(name, '', Date.now() - 86400000);
|
1073
|
-
}
|
1074
|
-
};
|
1075
|
-
})() :
|
1076
|
-
|
1077
|
-
// Non standard browser env (web workers, react-native) lack needed support.
|
1078
|
-
(function nonStandardBrowserEnv() {
|
1079
|
-
return {
|
1080
|
-
write: function write() {},
|
1081
|
-
read: function read() { return null; },
|
1082
|
-
remove: function remove() {}
|
1083
|
-
};
|
1084
|
-
})()
|
1085
|
-
);
|
1086
|
-
|
1087
|
-
/**
|
1088
|
-
* Determines whether the specified URL is absolute
|
1089
|
-
*
|
1090
|
-
* @param {string} url The URL to test
|
1091
|
-
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
1092
|
-
*/
|
1093
|
-
var isAbsoluteURL = function isAbsoluteURL(url) {
|
1094
|
-
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
1095
|
-
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
1096
|
-
// by any combination of letters, digits, plus, period, or hyphen.
|
1097
|
-
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
1098
|
-
};
|
1099
|
-
|
1100
|
-
/**
|
1101
|
-
* Creates a new URL by combining the specified URLs
|
1102
|
-
*
|
1103
|
-
* @param {string} baseURL The base URL
|
1104
|
-
* @param {string} relativeURL The relative URL
|
1105
|
-
* @returns {string} The combined URL
|
1106
|
-
*/
|
1107
|
-
var combineURLs = function combineURLs(baseURL, relativeURL) {
|
1108
|
-
return relativeURL
|
1109
|
-
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
1110
|
-
: baseURL;
|
1111
|
-
};
|
1112
|
-
|
1113
|
-
/**
|
1114
|
-
* Creates a new URL by combining the baseURL with the requestedURL,
|
1115
|
-
* only when the requestedURL is not already an absolute URL.
|
1116
|
-
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
1117
|
-
*
|
1118
|
-
* @param {string} baseURL The base URL
|
1119
|
-
* @param {string} requestedURL Absolute or relative URL to combine
|
1120
|
-
* @returns {string} The combined full path
|
1121
|
-
*/
|
1122
|
-
var buildFullPath = function buildFullPath(baseURL, requestedURL) {
|
1123
|
-
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
1124
|
-
return combineURLs(baseURL, requestedURL);
|
1125
|
-
}
|
1126
|
-
return requestedURL;
|
1127
|
-
};
|
1128
|
-
|
1129
|
-
// Headers whose duplicates are ignored by node
|
1130
|
-
// c.f. https://nodejs.org/api/http.html#http_message_headers
|
1131
|
-
var ignoreDuplicateOf = [
|
1132
|
-
'age', 'authorization', 'content-length', 'content-type', 'etag',
|
1133
|
-
'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
|
1134
|
-
'last-modified', 'location', 'max-forwards', 'proxy-authorization',
|
1135
|
-
'referer', 'retry-after', 'user-agent'
|
1136
|
-
];
|
1137
|
-
|
1138
|
-
/**
|
1139
|
-
* Parse headers into an object
|
1140
|
-
*
|
1141
|
-
* ```
|
1142
|
-
* Date: Wed, 27 Aug 2014 08:58:49 GMT
|
1143
|
-
* Content-Type: application/json
|
1144
|
-
* Connection: keep-alive
|
1145
|
-
* Transfer-Encoding: chunked
|
1146
|
-
* ```
|
1147
|
-
*
|
1148
|
-
* @param {String} headers Headers needing to be parsed
|
1149
|
-
* @returns {Object} Headers parsed into an object
|
1150
|
-
*/
|
1151
|
-
var parseHeaders = function parseHeaders(headers) {
|
1152
|
-
var parsed = {};
|
1153
|
-
var key;
|
1154
|
-
var val;
|
1155
|
-
var i;
|
1156
|
-
|
1157
|
-
if (!headers) { return parsed; }
|
1158
|
-
|
1159
|
-
utils.forEach(headers.split('\n'), function parser(line) {
|
1160
|
-
i = line.indexOf(':');
|
1161
|
-
key = utils.trim(line.substr(0, i)).toLowerCase();
|
1162
|
-
val = utils.trim(line.substr(i + 1));
|
1163
|
-
|
1164
|
-
if (key) {
|
1165
|
-
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
|
1166
|
-
return;
|
1167
|
-
}
|
1168
|
-
if (key === 'set-cookie') {
|
1169
|
-
parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
|
1170
|
-
} else {
|
1171
|
-
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
1172
|
-
}
|
1173
|
-
}
|
1174
|
-
});
|
1175
|
-
|
1176
|
-
return parsed;
|
1177
|
-
};
|
1178
|
-
|
1179
|
-
var isURLSameOrigin = (
|
1180
|
-
utils.isStandardBrowserEnv() ?
|
1181
|
-
|
1182
|
-
// Standard browser envs have full support of the APIs needed to test
|
1183
|
-
// whether the request URL is of the same origin as current location.
|
1184
|
-
(function standardBrowserEnv() {
|
1185
|
-
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
1186
|
-
var urlParsingNode = document.createElement('a');
|
1187
|
-
var originURL;
|
1188
|
-
|
1189
|
-
/**
|
1190
|
-
* Parse a URL to discover it's components
|
1191
|
-
*
|
1192
|
-
* @param {String} url The URL to be parsed
|
1193
|
-
* @returns {Object}
|
1194
|
-
*/
|
1195
|
-
function resolveURL(url) {
|
1196
|
-
var href = url;
|
1197
|
-
|
1198
|
-
if (msie) {
|
1199
|
-
// IE needs attribute set twice to normalize properties
|
1200
|
-
urlParsingNode.setAttribute('href', href);
|
1201
|
-
href = urlParsingNode.href;
|
1202
|
-
}
|
1203
|
-
|
1204
|
-
urlParsingNode.setAttribute('href', href);
|
1205
|
-
|
1206
|
-
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
1207
|
-
return {
|
1208
|
-
href: urlParsingNode.href,
|
1209
|
-
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
1210
|
-
host: urlParsingNode.host,
|
1211
|
-
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
1212
|
-
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
1213
|
-
hostname: urlParsingNode.hostname,
|
1214
|
-
port: urlParsingNode.port,
|
1215
|
-
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
1216
|
-
urlParsingNode.pathname :
|
1217
|
-
'/' + urlParsingNode.pathname
|
1218
|
-
};
|
1219
|
-
}
|
1220
|
-
|
1221
|
-
originURL = resolveURL(window.location.href);
|
1222
|
-
|
1223
|
-
/**
|
1224
|
-
* Determine if a URL shares the same origin as the current location
|
1225
|
-
*
|
1226
|
-
* @param {String} requestURL The URL to test
|
1227
|
-
* @returns {boolean} True if URL shares the same origin, otherwise false
|
1228
|
-
*/
|
1229
|
-
return function isURLSameOrigin(requestURL) {
|
1230
|
-
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
1231
|
-
return (parsed.protocol === originURL.protocol &&
|
1232
|
-
parsed.host === originURL.host);
|
1233
|
-
};
|
1234
|
-
})() :
|
1235
|
-
|
1236
|
-
// Non standard browser envs (web workers, react-native) lack needed support.
|
1237
|
-
(function nonStandardBrowserEnv() {
|
1238
|
-
return function isURLSameOrigin() {
|
1239
|
-
return true;
|
1240
|
-
};
|
1241
|
-
})()
|
1242
|
-
);
|
1243
|
-
|
1244
|
-
/**
|
1245
|
-
* A `CanceledError` is an object that is thrown when an operation is canceled.
|
1246
|
-
*
|
1247
|
-
* @class
|
1248
|
-
* @param {string=} message The message.
|
1249
|
-
*/
|
1250
|
-
function CanceledError(message) {
|
1251
|
-
// eslint-disable-next-line no-eq-null,eqeqeq
|
1252
|
-
AxiosError_1.call(this, message == null ? 'canceled' : message, AxiosError_1.ERR_CANCELED);
|
1253
|
-
this.name = 'CanceledError';
|
1254
|
-
}
|
1255
|
-
|
1256
|
-
utils.inherits(CanceledError, AxiosError_1, {
|
1257
|
-
__CANCEL__: true
|
1258
|
-
});
|
1259
|
-
|
1260
|
-
var CanceledError_1 = CanceledError;
|
1261
|
-
|
1262
|
-
var parseProtocol = function parseProtocol(url) {
|
1263
|
-
var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
1264
|
-
return match && match[1] || '';
|
1265
|
-
};
|
1266
|
-
|
1267
|
-
var xhr = function xhrAdapter(config) {
|
1268
|
-
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
1269
|
-
var requestData = config.data;
|
1270
|
-
var requestHeaders = config.headers;
|
1271
|
-
var responseType = config.responseType;
|
1272
|
-
var onCanceled;
|
1273
|
-
function done() {
|
1274
|
-
if (config.cancelToken) {
|
1275
|
-
config.cancelToken.unsubscribe(onCanceled);
|
1276
|
-
}
|
1277
|
-
|
1278
|
-
if (config.signal) {
|
1279
|
-
config.signal.removeEventListener('abort', onCanceled);
|
1280
|
-
}
|
1281
|
-
}
|
1282
|
-
|
1283
|
-
if (utils.isFormData(requestData) && utils.isStandardBrowserEnv()) {
|
1284
|
-
delete requestHeaders['Content-Type']; // Let the browser set it
|
1285
|
-
}
|
1286
|
-
|
1287
|
-
var request = new XMLHttpRequest();
|
1288
|
-
|
1289
|
-
// HTTP basic authentication
|
1290
|
-
if (config.auth) {
|
1291
|
-
var username = config.auth.username || '';
|
1292
|
-
var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
1293
|
-
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
1294
|
-
}
|
1295
|
-
|
1296
|
-
var fullPath = buildFullPath(config.baseURL, config.url);
|
1297
|
-
|
1298
|
-
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
1299
|
-
|
1300
|
-
// Set the request timeout in MS
|
1301
|
-
request.timeout = config.timeout;
|
1302
|
-
|
1303
|
-
function onloadend() {
|
1304
|
-
if (!request) {
|
1305
|
-
return;
|
1306
|
-
}
|
1307
|
-
// Prepare the response
|
1308
|
-
var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
|
1309
|
-
var responseData = !responseType || responseType === 'text' || responseType === 'json' ?
|
1310
|
-
request.responseText : request.response;
|
1311
|
-
var response = {
|
1312
|
-
data: responseData,
|
1313
|
-
status: request.status,
|
1314
|
-
statusText: request.statusText,
|
1315
|
-
headers: responseHeaders,
|
1316
|
-
config: config,
|
1317
|
-
request: request
|
1318
|
-
};
|
1319
|
-
|
1320
|
-
settle(function _resolve(value) {
|
1321
|
-
resolve(value);
|
1322
|
-
done();
|
1323
|
-
}, function _reject(err) {
|
1324
|
-
reject(err);
|
1325
|
-
done();
|
1326
|
-
}, response);
|
1327
|
-
|
1328
|
-
// Clean up request
|
1329
|
-
request = null;
|
1330
|
-
}
|
1331
|
-
|
1332
|
-
if ('onloadend' in request) {
|
1333
|
-
// Use onloadend if available
|
1334
|
-
request.onloadend = onloadend;
|
1335
|
-
} else {
|
1336
|
-
// Listen for ready state to emulate onloadend
|
1337
|
-
request.onreadystatechange = function handleLoad() {
|
1338
|
-
if (!request || request.readyState !== 4) {
|
1339
|
-
return;
|
1340
|
-
}
|
1341
|
-
|
1342
|
-
// The request errored out and we didn't get a response, this will be
|
1343
|
-
// handled by onerror instead
|
1344
|
-
// With one exception: request that using file: protocol, most browsers
|
1345
|
-
// will return status as 0 even though it's a successful request
|
1346
|
-
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
1347
|
-
return;
|
1348
|
-
}
|
1349
|
-
// readystate handler is calling before onerror or ontimeout handlers,
|
1350
|
-
// so we should call onloadend on the next 'tick'
|
1351
|
-
setTimeout(onloadend);
|
1352
|
-
};
|
1353
|
-
}
|
1354
|
-
|
1355
|
-
// Handle browser request cancellation (as opposed to a manual cancellation)
|
1356
|
-
request.onabort = function handleAbort() {
|
1357
|
-
if (!request) {
|
1358
|
-
return;
|
1359
|
-
}
|
1360
|
-
|
1361
|
-
reject(new AxiosError_1('Request aborted', AxiosError_1.ECONNABORTED, config, request));
|
1362
|
-
|
1363
|
-
// Clean up request
|
1364
|
-
request = null;
|
1365
|
-
};
|
1366
|
-
|
1367
|
-
// Handle low level network errors
|
1368
|
-
request.onerror = function handleError() {
|
1369
|
-
// Real errors are hidden from us by the browser
|
1370
|
-
// onerror should only fire if it's a network error
|
1371
|
-
reject(new AxiosError_1('Network Error', AxiosError_1.ERR_NETWORK, config, request, request));
|
1372
|
-
|
1373
|
-
// Clean up request
|
1374
|
-
request = null;
|
1375
|
-
};
|
1376
|
-
|
1377
|
-
// Handle timeout
|
1378
|
-
request.ontimeout = function handleTimeout() {
|
1379
|
-
var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
|
1380
|
-
var transitional$1 = config.transitional || transitional;
|
1381
|
-
if (config.timeoutErrorMessage) {
|
1382
|
-
timeoutErrorMessage = config.timeoutErrorMessage;
|
1383
|
-
}
|
1384
|
-
reject(new AxiosError_1(
|
1385
|
-
timeoutErrorMessage,
|
1386
|
-
transitional$1.clarifyTimeoutError ? AxiosError_1.ETIMEDOUT : AxiosError_1.ECONNABORTED,
|
1387
|
-
config,
|
1388
|
-
request));
|
1389
|
-
|
1390
|
-
// Clean up request
|
1391
|
-
request = null;
|
1392
|
-
};
|
1393
|
-
|
1394
|
-
// Add xsrf header
|
1395
|
-
// This is only done if running in a standard browser environment.
|
1396
|
-
// Specifically not if we're in a web worker, or react-native.
|
1397
|
-
if (utils.isStandardBrowserEnv()) {
|
1398
|
-
// Add xsrf header
|
1399
|
-
var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
|
1400
|
-
cookies.read(config.xsrfCookieName) :
|
1401
|
-
undefined;
|
1402
|
-
|
1403
|
-
if (xsrfValue) {
|
1404
|
-
requestHeaders[config.xsrfHeaderName] = xsrfValue;
|
1405
|
-
}
|
1406
|
-
}
|
1407
|
-
|
1408
|
-
// Add headers to the request
|
1409
|
-
if ('setRequestHeader' in request) {
|
1410
|
-
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
|
1411
|
-
if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
|
1412
|
-
// Remove Content-Type if data is undefined
|
1413
|
-
delete requestHeaders[key];
|
1414
|
-
} else {
|
1415
|
-
// Otherwise add header to the request
|
1416
|
-
request.setRequestHeader(key, val);
|
1417
|
-
}
|
1418
|
-
});
|
1419
|
-
}
|
1420
|
-
|
1421
|
-
// Add withCredentials to request if needed
|
1422
|
-
if (!utils.isUndefined(config.withCredentials)) {
|
1423
|
-
request.withCredentials = !!config.withCredentials;
|
1424
|
-
}
|
1425
|
-
|
1426
|
-
// Add responseType to request if needed
|
1427
|
-
if (responseType && responseType !== 'json') {
|
1428
|
-
request.responseType = config.responseType;
|
1429
|
-
}
|
1430
|
-
|
1431
|
-
// Handle progress if needed
|
1432
|
-
if (typeof config.onDownloadProgress === 'function') {
|
1433
|
-
request.addEventListener('progress', config.onDownloadProgress);
|
1434
|
-
}
|
1435
|
-
|
1436
|
-
// Not all browsers support upload events
|
1437
|
-
if (typeof config.onUploadProgress === 'function' && request.upload) {
|
1438
|
-
request.upload.addEventListener('progress', config.onUploadProgress);
|
1439
|
-
}
|
1440
|
-
|
1441
|
-
if (config.cancelToken || config.signal) {
|
1442
|
-
// Handle cancellation
|
1443
|
-
// eslint-disable-next-line func-names
|
1444
|
-
onCanceled = function(cancel) {
|
1445
|
-
if (!request) {
|
1446
|
-
return;
|
1447
|
-
}
|
1448
|
-
reject(!cancel || (cancel && cancel.type) ? new CanceledError_1() : cancel);
|
1449
|
-
request.abort();
|
1450
|
-
request = null;
|
1451
|
-
};
|
1452
|
-
|
1453
|
-
config.cancelToken && config.cancelToken.subscribe(onCanceled);
|
1454
|
-
if (config.signal) {
|
1455
|
-
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
|
1456
|
-
}
|
1457
|
-
}
|
1458
|
-
|
1459
|
-
if (!requestData) {
|
1460
|
-
requestData = null;
|
1461
|
-
}
|
1462
|
-
|
1463
|
-
var protocol = parseProtocol(fullPath);
|
1464
|
-
|
1465
|
-
if (protocol && [ 'http', 'https', 'file' ].indexOf(protocol) === -1) {
|
1466
|
-
reject(new AxiosError_1('Unsupported protocol ' + protocol + ':', AxiosError_1.ERR_BAD_REQUEST, config));
|
1467
|
-
return;
|
1468
|
-
}
|
1469
|
-
|
1470
|
-
|
1471
|
-
// Send the request
|
1472
|
-
request.send(requestData);
|
1473
|
-
});
|
1474
|
-
};
|
1475
|
-
|
1476
|
-
// eslint-disable-next-line strict
|
1477
|
-
var _null = null;
|
1478
|
-
|
1479
|
-
var DEFAULT_CONTENT_TYPE = {
|
1480
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
1481
|
-
};
|
1482
|
-
|
1483
|
-
function setContentTypeIfUnset(headers, value) {
|
1484
|
-
if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
|
1485
|
-
headers['Content-Type'] = value;
|
1486
|
-
}
|
1487
|
-
}
|
1488
|
-
|
1489
|
-
function getDefaultAdapter() {
|
1490
|
-
var adapter;
|
1491
|
-
if (typeof XMLHttpRequest !== 'undefined') {
|
1492
|
-
// For browsers use XHR adapter
|
1493
|
-
adapter = xhr;
|
1494
|
-
} else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
|
1495
|
-
// For node use HTTP adapter
|
1496
|
-
adapter = xhr;
|
1497
|
-
}
|
1498
|
-
return adapter;
|
1499
|
-
}
|
1500
|
-
|
1501
|
-
function stringifySafely(rawValue, parser, encoder) {
|
1502
|
-
if (utils.isString(rawValue)) {
|
1503
|
-
try {
|
1504
|
-
(parser || JSON.parse)(rawValue);
|
1505
|
-
return utils.trim(rawValue);
|
1506
|
-
} catch (e) {
|
1507
|
-
if (e.name !== 'SyntaxError') {
|
1508
|
-
throw e;
|
1509
|
-
}
|
1510
|
-
}
|
1511
|
-
}
|
1512
|
-
|
1513
|
-
return (encoder || JSON.stringify)(rawValue);
|
1514
|
-
}
|
1515
|
-
|
1516
|
-
var defaults = {
|
1517
|
-
|
1518
|
-
transitional: transitional,
|
1519
|
-
|
1520
|
-
adapter: getDefaultAdapter(),
|
1521
|
-
|
1522
|
-
transformRequest: [function transformRequest(data, headers) {
|
1523
|
-
normalizeHeaderName(headers, 'Accept');
|
1524
|
-
normalizeHeaderName(headers, 'Content-Type');
|
1525
|
-
|
1526
|
-
if (utils.isFormData(data) ||
|
1527
|
-
utils.isArrayBuffer(data) ||
|
1528
|
-
utils.isBuffer(data) ||
|
1529
|
-
utils.isStream(data) ||
|
1530
|
-
utils.isFile(data) ||
|
1531
|
-
utils.isBlob(data)
|
1532
|
-
) {
|
1533
|
-
return data;
|
1534
|
-
}
|
1535
|
-
if (utils.isArrayBufferView(data)) {
|
1536
|
-
return data.buffer;
|
1537
|
-
}
|
1538
|
-
if (utils.isURLSearchParams(data)) {
|
1539
|
-
setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
|
1540
|
-
return data.toString();
|
1541
|
-
}
|
1542
|
-
|
1543
|
-
var isObjectPayload = utils.isObject(data);
|
1544
|
-
var contentType = headers && headers['Content-Type'];
|
1545
|
-
|
1546
|
-
var isFileList;
|
1547
|
-
|
1548
|
-
if ((isFileList = utils.isFileList(data)) || (isObjectPayload && contentType === 'multipart/form-data')) {
|
1549
|
-
var _FormData = this.env && this.env.FormData;
|
1550
|
-
return toFormData_1(isFileList ? {'files[]': data} : data, _FormData && new _FormData());
|
1551
|
-
} else if (isObjectPayload || contentType === 'application/json') {
|
1552
|
-
setContentTypeIfUnset(headers, 'application/json');
|
1553
|
-
return stringifySafely(data);
|
1554
|
-
}
|
1555
|
-
|
1556
|
-
return data;
|
1557
|
-
}],
|
1558
|
-
|
1559
|
-
transformResponse: [function transformResponse(data) {
|
1560
|
-
var transitional = this.transitional || defaults.transitional;
|
1561
|
-
var silentJSONParsing = transitional && transitional.silentJSONParsing;
|
1562
|
-
var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
|
1563
|
-
var strictJSONParsing = !silentJSONParsing && this.responseType === 'json';
|
1564
|
-
|
1565
|
-
if (strictJSONParsing || (forcedJSONParsing && utils.isString(data) && data.length)) {
|
1566
|
-
try {
|
1567
|
-
return JSON.parse(data);
|
1568
|
-
} catch (e) {
|
1569
|
-
if (strictJSONParsing) {
|
1570
|
-
if (e.name === 'SyntaxError') {
|
1571
|
-
throw AxiosError_1.from(e, AxiosError_1.ERR_BAD_RESPONSE, this, null, this.response);
|
1572
|
-
}
|
1573
|
-
throw e;
|
1574
|
-
}
|
1575
|
-
}
|
1576
|
-
}
|
1577
|
-
|
1578
|
-
return data;
|
1579
|
-
}],
|
1580
|
-
|
1581
|
-
/**
|
1582
|
-
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
1583
|
-
* timeout is not created.
|
1584
|
-
*/
|
1585
|
-
timeout: 0,
|
1586
|
-
|
1587
|
-
xsrfCookieName: 'XSRF-TOKEN',
|
1588
|
-
xsrfHeaderName: 'X-XSRF-TOKEN',
|
1589
|
-
|
1590
|
-
maxContentLength: -1,
|
1591
|
-
maxBodyLength: -1,
|
1592
|
-
|
1593
|
-
env: {
|
1594
|
-
FormData: _null
|
1595
|
-
},
|
1596
|
-
|
1597
|
-
validateStatus: function validateStatus(status) {
|
1598
|
-
return status >= 200 && status < 300;
|
1599
|
-
},
|
1600
|
-
|
1601
|
-
headers: {
|
1602
|
-
common: {
|
1603
|
-
'Accept': 'application/json, text/plain, */*'
|
1604
|
-
}
|
1605
|
-
}
|
1606
|
-
};
|
1607
|
-
|
1608
|
-
utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
|
1609
|
-
defaults.headers[method] = {};
|
1610
|
-
});
|
1611
|
-
|
1612
|
-
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
1613
|
-
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
1614
|
-
});
|
1615
|
-
|
1616
|
-
var defaults_1 = defaults;
|
1617
|
-
|
1618
|
-
/**
|
1619
|
-
* Transform the data for a request or a response
|
1620
|
-
*
|
1621
|
-
* @param {Object|String} data The data to be transformed
|
1622
|
-
* @param {Array} headers The headers for the request or response
|
1623
|
-
* @param {Array|Function} fns A single function or Array of functions
|
1624
|
-
* @returns {*} The resulting transformed data
|
1625
|
-
*/
|
1626
|
-
var transformData = function transformData(data, headers, fns) {
|
1627
|
-
var context = this || defaults_1;
|
1628
|
-
/*eslint no-param-reassign:0*/
|
1629
|
-
utils.forEach(fns, function transform(fn) {
|
1630
|
-
data = fn.call(context, data, headers);
|
1631
|
-
});
|
1632
|
-
|
1633
|
-
return data;
|
1634
|
-
};
|
1635
|
-
|
1636
|
-
var isCancel = function isCancel(value) {
|
1637
|
-
return !!(value && value.__CANCEL__);
|
1638
|
-
};
|
1639
|
-
|
1640
|
-
/**
|
1641
|
-
* Throws a `CanceledError` if cancellation has been requested.
|
1642
|
-
*/
|
1643
|
-
function throwIfCancellationRequested(config) {
|
1644
|
-
if (config.cancelToken) {
|
1645
|
-
config.cancelToken.throwIfRequested();
|
1646
|
-
}
|
1647
|
-
|
1648
|
-
if (config.signal && config.signal.aborted) {
|
1649
|
-
throw new CanceledError_1();
|
1650
|
-
}
|
1651
|
-
}
|
1652
|
-
|
1653
|
-
/**
|
1654
|
-
* Dispatch a request to the server using the configured adapter.
|
1655
|
-
*
|
1656
|
-
* @param {object} config The config that is to be used for the request
|
1657
|
-
* @returns {Promise} The Promise to be fulfilled
|
1658
|
-
*/
|
1659
|
-
var dispatchRequest = function dispatchRequest(config) {
|
1660
|
-
throwIfCancellationRequested(config);
|
1661
|
-
|
1662
|
-
// Ensure headers exist
|
1663
|
-
config.headers = config.headers || {};
|
1664
|
-
|
1665
|
-
// Transform request data
|
1666
|
-
config.data = transformData.call(
|
1667
|
-
config,
|
1668
|
-
config.data,
|
1669
|
-
config.headers,
|
1670
|
-
config.transformRequest
|
1671
|
-
);
|
1672
|
-
|
1673
|
-
// Flatten headers
|
1674
|
-
config.headers = utils.merge(
|
1675
|
-
config.headers.common || {},
|
1676
|
-
config.headers[config.method] || {},
|
1677
|
-
config.headers
|
1678
|
-
);
|
1679
|
-
|
1680
|
-
utils.forEach(
|
1681
|
-
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
1682
|
-
function cleanHeaderConfig(method) {
|
1683
|
-
delete config.headers[method];
|
1684
|
-
}
|
1685
|
-
);
|
1686
|
-
|
1687
|
-
var adapter = config.adapter || defaults_1.adapter;
|
1688
|
-
|
1689
|
-
return adapter(config).then(function onAdapterResolution(response) {
|
1690
|
-
throwIfCancellationRequested(config);
|
1691
|
-
|
1692
|
-
// Transform response data
|
1693
|
-
response.data = transformData.call(
|
1694
|
-
config,
|
1695
|
-
response.data,
|
1696
|
-
response.headers,
|
1697
|
-
config.transformResponse
|
1698
|
-
);
|
1699
|
-
|
1700
|
-
return response;
|
1701
|
-
}, function onAdapterRejection(reason) {
|
1702
|
-
if (!isCancel(reason)) {
|
1703
|
-
throwIfCancellationRequested(config);
|
1704
|
-
|
1705
|
-
// Transform response data
|
1706
|
-
if (reason && reason.response) {
|
1707
|
-
reason.response.data = transformData.call(
|
1708
|
-
config,
|
1709
|
-
reason.response.data,
|
1710
|
-
reason.response.headers,
|
1711
|
-
config.transformResponse
|
1712
|
-
);
|
1713
|
-
}
|
1714
|
-
}
|
1715
|
-
|
1716
|
-
return Promise.reject(reason);
|
1717
|
-
});
|
1718
|
-
};
|
1719
|
-
|
1720
|
-
/**
|
1721
|
-
* Config-specific merge-function which creates a new config-object
|
1722
|
-
* by merging two configuration objects together.
|
1723
|
-
*
|
1724
|
-
* @param {Object} config1
|
1725
|
-
* @param {Object} config2
|
1726
|
-
* @returns {Object} New object resulting from merging config2 to config1
|
1727
|
-
*/
|
1728
|
-
var mergeConfig = function mergeConfig(config1, config2) {
|
1729
|
-
// eslint-disable-next-line no-param-reassign
|
1730
|
-
config2 = config2 || {};
|
1731
|
-
var config = {};
|
1732
|
-
|
1733
|
-
function getMergedValue(target, source) {
|
1734
|
-
if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
|
1735
|
-
return utils.merge(target, source);
|
1736
|
-
} else if (utils.isPlainObject(source)) {
|
1737
|
-
return utils.merge({}, source);
|
1738
|
-
} else if (utils.isArray(source)) {
|
1739
|
-
return source.slice();
|
1740
|
-
}
|
1741
|
-
return source;
|
1742
|
-
}
|
1743
|
-
|
1744
|
-
// eslint-disable-next-line consistent-return
|
1745
|
-
function mergeDeepProperties(prop) {
|
1746
|
-
if (!utils.isUndefined(config2[prop])) {
|
1747
|
-
return getMergedValue(config1[prop], config2[prop]);
|
1748
|
-
} else if (!utils.isUndefined(config1[prop])) {
|
1749
|
-
return getMergedValue(undefined, config1[prop]);
|
253
|
+
// eslint-lint-disable-next-line @typescript-eslint/naming-convention
|
254
|
+
class HTTPError extends Error {
|
255
|
+
constructor(response, request, options) {
|
256
|
+
const code = (response.status || response.status === 0) ? response.status : '';
|
257
|
+
const title = response.statusText || '';
|
258
|
+
const status = `${code} ${title}`.trim();
|
259
|
+
const reason = status ? `status code ${status}` : 'an unknown error';
|
260
|
+
super(`Request failed with ${reason}`);
|
261
|
+
Object.defineProperty(this, "response", {
|
262
|
+
enumerable: true,
|
263
|
+
configurable: true,
|
264
|
+
writable: true,
|
265
|
+
value: void 0
|
266
|
+
});
|
267
|
+
Object.defineProperty(this, "request", {
|
268
|
+
enumerable: true,
|
269
|
+
configurable: true,
|
270
|
+
writable: true,
|
271
|
+
value: void 0
|
272
|
+
});
|
273
|
+
Object.defineProperty(this, "options", {
|
274
|
+
enumerable: true,
|
275
|
+
configurable: true,
|
276
|
+
writable: true,
|
277
|
+
value: void 0
|
278
|
+
});
|
279
|
+
this.name = 'HTTPError';
|
280
|
+
this.response = response;
|
281
|
+
this.request = request;
|
282
|
+
this.options = options;
|
1750
283
|
}
|
1751
|
-
|
284
|
+
}
|
1752
285
|
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
286
|
+
class TimeoutError extends Error {
|
287
|
+
constructor(request) {
|
288
|
+
super('Request timed out');
|
289
|
+
Object.defineProperty(this, "request", {
|
290
|
+
enumerable: true,
|
291
|
+
configurable: true,
|
292
|
+
writable: true,
|
293
|
+
value: void 0
|
294
|
+
});
|
295
|
+
this.name = 'TimeoutError';
|
296
|
+
this.request = request;
|
1757
297
|
}
|
1758
|
-
|
298
|
+
}
|
1759
299
|
|
1760
|
-
|
1761
|
-
|
1762
|
-
if (!utils.isUndefined(config2[prop])) {
|
1763
|
-
return getMergedValue(undefined, config2[prop]);
|
1764
|
-
} else if (!utils.isUndefined(config1[prop])) {
|
1765
|
-
return getMergedValue(undefined, config1[prop]);
|
1766
|
-
}
|
1767
|
-
}
|
300
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
301
|
+
const isObject = (value) => value !== null && typeof value === 'object';
|
1768
302
|
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
return getMergedValue(undefined, config1[prop]);
|
303
|
+
const validateAndMerge = (...sources) => {
|
304
|
+
for (const source of sources) {
|
305
|
+
if ((!isObject(source) || Array.isArray(source)) && typeof source !== 'undefined') {
|
306
|
+
throw new TypeError('The `options` argument must be an object');
|
307
|
+
}
|
1775
308
|
}
|
1776
|
-
|
1777
|
-
|
1778
|
-
var mergeMap = {
|
1779
|
-
'url': valueFromConfig2,
|
1780
|
-
'method': valueFromConfig2,
|
1781
|
-
'data': valueFromConfig2,
|
1782
|
-
'baseURL': defaultToConfig2,
|
1783
|
-
'transformRequest': defaultToConfig2,
|
1784
|
-
'transformResponse': defaultToConfig2,
|
1785
|
-
'paramsSerializer': defaultToConfig2,
|
1786
|
-
'timeout': defaultToConfig2,
|
1787
|
-
'timeoutMessage': defaultToConfig2,
|
1788
|
-
'withCredentials': defaultToConfig2,
|
1789
|
-
'adapter': defaultToConfig2,
|
1790
|
-
'responseType': defaultToConfig2,
|
1791
|
-
'xsrfCookieName': defaultToConfig2,
|
1792
|
-
'xsrfHeaderName': defaultToConfig2,
|
1793
|
-
'onUploadProgress': defaultToConfig2,
|
1794
|
-
'onDownloadProgress': defaultToConfig2,
|
1795
|
-
'decompress': defaultToConfig2,
|
1796
|
-
'maxContentLength': defaultToConfig2,
|
1797
|
-
'maxBodyLength': defaultToConfig2,
|
1798
|
-
'beforeRedirect': defaultToConfig2,
|
1799
|
-
'transport': defaultToConfig2,
|
1800
|
-
'httpAgent': defaultToConfig2,
|
1801
|
-
'httpsAgent': defaultToConfig2,
|
1802
|
-
'cancelToken': defaultToConfig2,
|
1803
|
-
'socketPath': defaultToConfig2,
|
1804
|
-
'responseEncoding': defaultToConfig2,
|
1805
|
-
'validateStatus': mergeDirectKeys
|
1806
|
-
};
|
1807
|
-
|
1808
|
-
utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
|
1809
|
-
var merge = mergeMap[prop] || mergeDeepProperties;
|
1810
|
-
var configValue = merge(prop);
|
1811
|
-
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
1812
|
-
});
|
1813
|
-
|
1814
|
-
return config;
|
309
|
+
return deepMerge({}, ...sources);
|
1815
310
|
};
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
1823
|
-
|
1824
|
-
|
1825
|
-
|
1826
|
-
|
1827
|
-
['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach(function(type, i) {
|
1828
|
-
validators$1[type] = function validator(thing) {
|
1829
|
-
return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
|
1830
|
-
};
|
1831
|
-
});
|
1832
|
-
|
1833
|
-
var deprecatedWarnings = {};
|
1834
|
-
|
1835
|
-
/**
|
1836
|
-
* Transitional option validator
|
1837
|
-
* @param {function|boolean?} validator - set to false if the transitional option has been removed
|
1838
|
-
* @param {string?} version - deprecated version / removed since version
|
1839
|
-
* @param {string?} message - some message with additional info
|
1840
|
-
* @returns {function}
|
1841
|
-
*/
|
1842
|
-
validators$1.transitional = function transitional(validator, version, message) {
|
1843
|
-
function formatMessage(opt, desc) {
|
1844
|
-
return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
|
1845
|
-
}
|
1846
|
-
|
1847
|
-
// eslint-disable-next-line func-names
|
1848
|
-
return function(value, opt, opts) {
|
1849
|
-
if (validator === false) {
|
1850
|
-
throw new AxiosError_1(
|
1851
|
-
formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')),
|
1852
|
-
AxiosError_1.ERR_DEPRECATED
|
1853
|
-
);
|
1854
|
-
}
|
1855
|
-
|
1856
|
-
if (version && !deprecatedWarnings[opt]) {
|
1857
|
-
deprecatedWarnings[opt] = true;
|
1858
|
-
// eslint-disable-next-line no-console
|
1859
|
-
console.warn(
|
1860
|
-
formatMessage(
|
1861
|
-
opt,
|
1862
|
-
' has been deprecated since v' + version + ' and will be removed in the near future'
|
1863
|
-
)
|
1864
|
-
);
|
311
|
+
const mergeHeaders = (source1 = {}, source2 = {}) => {
|
312
|
+
const result = new globalThis.Headers(source1);
|
313
|
+
const isHeadersInstance = source2 instanceof globalThis.Headers;
|
314
|
+
const source = new globalThis.Headers(source2);
|
315
|
+
for (const [key, value] of source.entries()) {
|
316
|
+
if ((isHeadersInstance && value === 'undefined') || value === undefined) {
|
317
|
+
result.delete(key);
|
318
|
+
}
|
319
|
+
else {
|
320
|
+
result.set(key, value);
|
321
|
+
}
|
1865
322
|
}
|
1866
|
-
|
1867
|
-
return validator ? validator(value, opt, opts) : true;
|
1868
|
-
};
|
323
|
+
return result;
|
1869
324
|
};
|
1870
|
-
|
1871
|
-
|
1872
|
-
|
1873
|
-
|
1874
|
-
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1884
|
-
|
1885
|
-
|
1886
|
-
|
1887
|
-
|
1888
|
-
|
1889
|
-
|
1890
|
-
|
1891
|
-
|
1892
|
-
|
1893
|
-
continue;
|
1894
|
-
}
|
1895
|
-
if (allowUnknown !== true) {
|
1896
|
-
throw new AxiosError_1('Unknown option ' + opt, AxiosError_1.ERR_BAD_OPTION);
|
325
|
+
// TODO: Make this strongly-typed (no `any`).
|
326
|
+
const deepMerge = (...sources) => {
|
327
|
+
let returnValue = {};
|
328
|
+
let headers = {};
|
329
|
+
for (const source of sources) {
|
330
|
+
if (Array.isArray(source)) {
|
331
|
+
if (!Array.isArray(returnValue)) {
|
332
|
+
returnValue = [];
|
333
|
+
}
|
334
|
+
returnValue = [...returnValue, ...source];
|
335
|
+
}
|
336
|
+
else if (isObject(source)) {
|
337
|
+
for (let [key, value] of Object.entries(source)) {
|
338
|
+
if (isObject(value) && key in returnValue) {
|
339
|
+
value = deepMerge(returnValue[key], value);
|
340
|
+
}
|
341
|
+
returnValue = { ...returnValue, [key]: value };
|
342
|
+
}
|
343
|
+
if (isObject(source.headers)) {
|
344
|
+
headers = mergeHeaders(headers, source.headers);
|
345
|
+
returnValue.headers = headers;
|
346
|
+
}
|
347
|
+
}
|
1897
348
|
}
|
1898
|
-
|
1899
|
-
}
|
1900
|
-
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1947
|
-
|
1948
|
-
|
1949
|
-
validator.assertOptions(transitional, {
|
1950
|
-
silentJSONParsing: validators.transitional(validators.boolean),
|
1951
|
-
forcedJSONParsing: validators.transitional(validators.boolean),
|
1952
|
-
clarifyTimeoutError: validators.transitional(validators.boolean)
|
1953
|
-
}, false);
|
1954
|
-
}
|
1955
|
-
|
1956
|
-
// filter out skipped interceptors
|
1957
|
-
var requestInterceptorChain = [];
|
1958
|
-
var synchronousRequestInterceptors = true;
|
1959
|
-
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
1960
|
-
if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
|
1961
|
-
return;
|
349
|
+
return returnValue;
|
350
|
+
};
|
351
|
+
|
352
|
+
const supportsStreams = (() => {
|
353
|
+
let duplexAccessed = false;
|
354
|
+
let hasContentType = false;
|
355
|
+
const supportsReadableStream = typeof globalThis.ReadableStream === 'function';
|
356
|
+
if (supportsReadableStream) {
|
357
|
+
hasContentType = new globalThis.Request('https://a.com', {
|
358
|
+
body: new globalThis.ReadableStream(),
|
359
|
+
method: 'POST',
|
360
|
+
// @ts-expect-error - Types are outdated.
|
361
|
+
get duplex() {
|
362
|
+
duplexAccessed = true;
|
363
|
+
return 'half';
|
364
|
+
},
|
365
|
+
}).headers.has('Content-Type');
|
366
|
+
}
|
367
|
+
return duplexAccessed && !hasContentType;
|
368
|
+
})();
|
369
|
+
const supportsAbortController = typeof globalThis.AbortController === 'function';
|
370
|
+
const supportsFormData = typeof globalThis.FormData === 'function';
|
371
|
+
const requestMethods = ['get', 'post', 'put', 'patch', 'head', 'delete'];
|
372
|
+
const responseTypes = {
|
373
|
+
json: 'application/json',
|
374
|
+
text: 'text/*',
|
375
|
+
formData: 'multipart/form-data',
|
376
|
+
arrayBuffer: '*/*',
|
377
|
+
blob: '*/*',
|
378
|
+
};
|
379
|
+
// The maximum value of a 32bit int (see issue #117)
|
380
|
+
const maxSafeTimeout = 2147483647;
|
381
|
+
const stop = Symbol('stop');
|
382
|
+
|
383
|
+
const normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
|
384
|
+
const retryMethods = ['get', 'put', 'head', 'delete', 'options', 'trace'];
|
385
|
+
const retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
|
386
|
+
const retryAfterStatusCodes = [413, 429, 503];
|
387
|
+
const defaultRetryOptions = {
|
388
|
+
limit: 2,
|
389
|
+
methods: retryMethods,
|
390
|
+
statusCodes: retryStatusCodes,
|
391
|
+
afterStatusCodes: retryAfterStatusCodes,
|
392
|
+
maxRetryAfter: Number.POSITIVE_INFINITY,
|
393
|
+
};
|
394
|
+
const normalizeRetryOptions = (retry = {}) => {
|
395
|
+
if (typeof retry === 'number') {
|
396
|
+
return {
|
397
|
+
...defaultRetryOptions,
|
398
|
+
limit: retry,
|
399
|
+
};
|
1962
400
|
}
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
1967
|
-
});
|
1968
|
-
|
1969
|
-
var responseInterceptorChain = [];
|
1970
|
-
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
1971
|
-
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
1972
|
-
});
|
1973
|
-
|
1974
|
-
var promise;
|
1975
|
-
|
1976
|
-
if (!synchronousRequestInterceptors) {
|
1977
|
-
var chain = [dispatchRequest, undefined];
|
1978
|
-
|
1979
|
-
Array.prototype.unshift.apply(chain, requestInterceptorChain);
|
1980
|
-
chain = chain.concat(responseInterceptorChain);
|
1981
|
-
|
1982
|
-
promise = Promise.resolve(config);
|
1983
|
-
while (chain.length) {
|
1984
|
-
promise = promise.then(chain.shift(), chain.shift());
|
401
|
+
if (retry.methods && !Array.isArray(retry.methods)) {
|
402
|
+
throw new Error('retry.methods must be an array');
|
1985
403
|
}
|
1986
|
-
|
1987
|
-
|
1988
|
-
}
|
1989
|
-
|
1990
|
-
|
1991
|
-
var newConfig = config;
|
1992
|
-
while (requestInterceptorChain.length) {
|
1993
|
-
var onFulfilled = requestInterceptorChain.shift();
|
1994
|
-
var onRejected = requestInterceptorChain.shift();
|
1995
|
-
try {
|
1996
|
-
newConfig = onFulfilled(newConfig);
|
1997
|
-
} catch (error) {
|
1998
|
-
onRejected(error);
|
1999
|
-
break;
|
404
|
+
if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {
|
405
|
+
throw new Error('retry.statusCodes must be an array');
|
2000
406
|
}
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
return Promise.reject(error);
|
2007
|
-
}
|
2008
|
-
|
2009
|
-
while (responseInterceptorChain.length) {
|
2010
|
-
promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
|
2011
|
-
}
|
2012
|
-
|
2013
|
-
return promise;
|
2014
|
-
};
|
2015
|
-
|
2016
|
-
Axios.prototype.getUri = function getUri(config) {
|
2017
|
-
config = mergeConfig(this.defaults, config);
|
2018
|
-
var fullPath = buildFullPath(config.baseURL, config.url);
|
2019
|
-
return buildURL(fullPath, config.params, config.paramsSerializer);
|
407
|
+
return {
|
408
|
+
...defaultRetryOptions,
|
409
|
+
...retry,
|
410
|
+
afterStatusCodes: retryAfterStatusCodes,
|
411
|
+
};
|
2020
412
|
};
|
2021
413
|
|
2022
|
-
//
|
2023
|
-
|
2024
|
-
|
2025
|
-
|
2026
|
-
|
2027
|
-
|
2028
|
-
|
2029
|
-
|
2030
|
-
|
2031
|
-
|
414
|
+
// `Promise.race()` workaround (#91)
|
415
|
+
const timeout = async (request, abortController, options) => new Promise((resolve, reject) => {
|
416
|
+
const timeoutId = setTimeout(() => {
|
417
|
+
if (abortController) {
|
418
|
+
abortController.abort();
|
419
|
+
}
|
420
|
+
reject(new TimeoutError(request));
|
421
|
+
}, options.timeout);
|
422
|
+
void options
|
423
|
+
.fetch(request)
|
424
|
+
.then(resolve)
|
425
|
+
.catch(reject)
|
426
|
+
.then(() => {
|
427
|
+
clearTimeout(timeoutId);
|
428
|
+
});
|
2032
429
|
});
|
2033
|
-
|
2034
|
-
|
2035
|
-
/*eslint func-names:0*/
|
2036
|
-
|
2037
|
-
function generateHTTPMethod(isForm) {
|
2038
|
-
return function httpMethod(url, data, config) {
|
2039
|
-
return this.request(mergeConfig(config || {}, {
|
2040
|
-
method: method,
|
2041
|
-
headers: isForm ? {
|
2042
|
-
'Content-Type': 'multipart/form-data'
|
2043
|
-
} : {},
|
2044
|
-
url: url,
|
2045
|
-
data: data
|
2046
|
-
}));
|
2047
|
-
};
|
2048
|
-
}
|
2049
|
-
|
2050
|
-
Axios.prototype[method] = generateHTTPMethod();
|
2051
|
-
|
2052
|
-
Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
430
|
+
const delay = async (ms) => new Promise(resolve => {
|
431
|
+
setTimeout(resolve, ms);
|
2053
432
|
});
|
2054
433
|
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2068
|
-
|
2069
|
-
|
2070
|
-
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2074
|
-
|
2075
|
-
|
2076
|
-
|
2077
|
-
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2082
|
-
|
2083
|
-
|
2084
|
-
|
434
|
+
class Ky {
|
435
|
+
// eslint-disable-next-line complexity
|
436
|
+
constructor(input, options = {}) {
|
437
|
+
Object.defineProperty(this, "request", {
|
438
|
+
enumerable: true,
|
439
|
+
configurable: true,
|
440
|
+
writable: true,
|
441
|
+
value: void 0
|
442
|
+
});
|
443
|
+
Object.defineProperty(this, "abortController", {
|
444
|
+
enumerable: true,
|
445
|
+
configurable: true,
|
446
|
+
writable: true,
|
447
|
+
value: void 0
|
448
|
+
});
|
449
|
+
Object.defineProperty(this, "_retryCount", {
|
450
|
+
enumerable: true,
|
451
|
+
configurable: true,
|
452
|
+
writable: true,
|
453
|
+
value: 0
|
454
|
+
});
|
455
|
+
Object.defineProperty(this, "_input", {
|
456
|
+
enumerable: true,
|
457
|
+
configurable: true,
|
458
|
+
writable: true,
|
459
|
+
value: void 0
|
460
|
+
});
|
461
|
+
Object.defineProperty(this, "_options", {
|
462
|
+
enumerable: true,
|
463
|
+
configurable: true,
|
464
|
+
writable: true,
|
465
|
+
value: void 0
|
466
|
+
});
|
467
|
+
this._input = input;
|
468
|
+
this._options = {
|
469
|
+
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
|
470
|
+
credentials: this._input.credentials || 'same-origin',
|
471
|
+
...options,
|
472
|
+
headers: mergeHeaders(this._input.headers, options.headers),
|
473
|
+
hooks: deepMerge({
|
474
|
+
beforeRequest: [],
|
475
|
+
beforeRetry: [],
|
476
|
+
beforeError: [],
|
477
|
+
afterResponse: [],
|
478
|
+
}, options.hooks),
|
479
|
+
method: normalizeRequestMethod(options.method ?? this._input.method),
|
480
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
481
|
+
prefixUrl: String(options.prefixUrl || ''),
|
482
|
+
retry: normalizeRetryOptions(options.retry),
|
483
|
+
throwHttpErrors: options.throwHttpErrors !== false,
|
484
|
+
timeout: typeof options.timeout === 'undefined' ? 10000 : options.timeout,
|
485
|
+
fetch: options.fetch ?? globalThis.fetch.bind(globalThis),
|
486
|
+
};
|
487
|
+
if (typeof this._input !== 'string' && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {
|
488
|
+
throw new TypeError('`input` must be a string, URL, or Request');
|
489
|
+
}
|
490
|
+
if (this._options.prefixUrl && typeof this._input === 'string') {
|
491
|
+
if (this._input.startsWith('/')) {
|
492
|
+
throw new Error('`input` must not begin with a slash when using `prefixUrl`');
|
493
|
+
}
|
494
|
+
if (!this._options.prefixUrl.endsWith('/')) {
|
495
|
+
this._options.prefixUrl += '/';
|
496
|
+
}
|
497
|
+
this._input = this._options.prefixUrl + this._input;
|
498
|
+
}
|
499
|
+
if (supportsAbortController) {
|
500
|
+
this.abortController = new globalThis.AbortController();
|
501
|
+
if (this._options.signal) {
|
502
|
+
this._options.signal.addEventListener('abort', () => {
|
503
|
+
this.abortController.abort();
|
504
|
+
});
|
505
|
+
}
|
506
|
+
this._options.signal = this.abortController.signal;
|
507
|
+
}
|
508
|
+
this.request = new globalThis.Request(this._input, this._options);
|
509
|
+
if (supportsStreams) {
|
510
|
+
// @ts-expect-error - Types are outdated.
|
511
|
+
this.request.duplex = 'half';
|
512
|
+
}
|
513
|
+
if (this._options.searchParams) {
|
514
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
515
|
+
const textSearchParams = typeof this._options.searchParams === 'string'
|
516
|
+
? this._options.searchParams.replace(/^\?/, '')
|
517
|
+
: new URLSearchParams(this._options.searchParams).toString();
|
518
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
519
|
+
const searchParams = '?' + textSearchParams;
|
520
|
+
const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
|
521
|
+
// To provide correct form boundary, Content-Type header should be deleted each time when new Request instantiated from another one
|
522
|
+
if (((supportsFormData && this._options.body instanceof globalThis.FormData)
|
523
|
+
|| this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers['content-type'])) {
|
524
|
+
this.request.headers.delete('content-type');
|
525
|
+
}
|
526
|
+
this.request = new globalThis.Request(new globalThis.Request(url, this.request), this._options);
|
527
|
+
}
|
528
|
+
if (this._options.json !== undefined) {
|
529
|
+
this._options.body = JSON.stringify(this._options.json);
|
530
|
+
this.request.headers.set('content-type', this._options.headers.get('content-type') ?? 'application/json');
|
531
|
+
this.request = new globalThis.Request(this.request, { body: this._options.body });
|
532
|
+
}
|
2085
533
|
}
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
534
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
535
|
+
static create(input, options) {
|
536
|
+
const ky = new Ky(input, options);
|
537
|
+
const fn = async () => {
|
538
|
+
if (ky._options.timeout > maxSafeTimeout) {
|
539
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
|
540
|
+
}
|
541
|
+
// Delay the fetch so that body method shortcuts can set the Accept header
|
542
|
+
await Promise.resolve();
|
543
|
+
let response = await ky._fetch();
|
544
|
+
for (const hook of ky._options.hooks.afterResponse) {
|
545
|
+
// eslint-disable-next-line no-await-in-loop
|
546
|
+
const modifiedResponse = await hook(ky.request, ky._options, ky._decorateResponse(response.clone()));
|
547
|
+
if (modifiedResponse instanceof globalThis.Response) {
|
548
|
+
response = modifiedResponse;
|
549
|
+
}
|
550
|
+
}
|
551
|
+
ky._decorateResponse(response);
|
552
|
+
if (!response.ok && ky._options.throwHttpErrors) {
|
553
|
+
let error = new HTTPError(response, ky.request, ky._options);
|
554
|
+
for (const hook of ky._options.hooks.beforeError) {
|
555
|
+
// eslint-disable-next-line no-await-in-loop
|
556
|
+
error = await hook(error);
|
557
|
+
}
|
558
|
+
throw error;
|
559
|
+
}
|
560
|
+
// If `onDownloadProgress` is passed, it uses the stream API internally
|
561
|
+
/* istanbul ignore next */
|
562
|
+
if (ky._options.onDownloadProgress) {
|
563
|
+
if (typeof ky._options.onDownloadProgress !== 'function') {
|
564
|
+
throw new TypeError('The `onDownloadProgress` option must be a function');
|
565
|
+
}
|
566
|
+
if (!supportsStreams) {
|
567
|
+
throw new Error('Streams are not supported in your environment. `ReadableStream` is missing.');
|
568
|
+
}
|
569
|
+
return ky._stream(response.clone(), ky._options.onDownloadProgress);
|
570
|
+
}
|
571
|
+
return response;
|
572
|
+
};
|
573
|
+
const isRetriableMethod = ky._options.retry.methods.includes(ky.request.method.toLowerCase());
|
574
|
+
const result = (isRetriableMethod ? ky._retry(fn) : fn());
|
575
|
+
for (const [type, mimeType] of Object.entries(responseTypes)) {
|
576
|
+
result[type] = async () => {
|
577
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
578
|
+
ky.request.headers.set('accept', ky.request.headers.get('accept') || mimeType);
|
579
|
+
const awaitedResult = await result;
|
580
|
+
const response = awaitedResult.clone();
|
581
|
+
if (type === 'json') {
|
582
|
+
if (response.status === 204) {
|
583
|
+
return '';
|
584
|
+
}
|
585
|
+
if (options.parseJson) {
|
586
|
+
return options.parseJson(await response.text());
|
587
|
+
}
|
588
|
+
}
|
589
|
+
return response[type]();
|
590
|
+
};
|
591
|
+
}
|
592
|
+
return result;
|
593
|
+
}
|
594
|
+
_calculateRetryDelay(error) {
|
595
|
+
this._retryCount++;
|
596
|
+
if (this._retryCount < this._options.retry.limit && !(error instanceof TimeoutError)) {
|
597
|
+
if (error instanceof HTTPError) {
|
598
|
+
if (!this._options.retry.statusCodes.includes(error.response.status)) {
|
599
|
+
return 0;
|
600
|
+
}
|
601
|
+
const retryAfter = error.response.headers.get('Retry-After');
|
602
|
+
if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {
|
603
|
+
let after = Number(retryAfter);
|
604
|
+
if (Number.isNaN(after)) {
|
605
|
+
after = Date.parse(retryAfter) - Date.now();
|
606
|
+
}
|
607
|
+
else {
|
608
|
+
after *= 1000;
|
609
|
+
}
|
610
|
+
if (typeof this._options.retry.maxRetryAfter !== 'undefined' && after > this._options.retry.maxRetryAfter) {
|
611
|
+
return 0;
|
612
|
+
}
|
613
|
+
return after;
|
614
|
+
}
|
615
|
+
if (error.response.status === 413) {
|
616
|
+
return 0;
|
617
|
+
}
|
618
|
+
}
|
619
|
+
const BACKOFF_FACTOR = 0.3;
|
620
|
+
return BACKOFF_FACTOR * (2 ** (this._retryCount - 1)) * 1000;
|
621
|
+
}
|
622
|
+
return 0;
|
623
|
+
}
|
624
|
+
_decorateResponse(response) {
|
625
|
+
if (this._options.parseJson) {
|
626
|
+
response.json = async () => this._options.parseJson(await response.text());
|
627
|
+
}
|
628
|
+
return response;
|
629
|
+
}
|
630
|
+
async _retry(fn) {
|
631
|
+
try {
|
632
|
+
return await fn();
|
633
|
+
// eslint-disable-next-line @typescript-eslint/no-implicit-any-catch
|
634
|
+
}
|
635
|
+
catch (error) {
|
636
|
+
const ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);
|
637
|
+
if (ms !== 0 && this._retryCount > 0) {
|
638
|
+
await delay(ms);
|
639
|
+
for (const hook of this._options.hooks.beforeRetry) {
|
640
|
+
// eslint-disable-next-line no-await-in-loop
|
641
|
+
const hookResult = await hook({
|
642
|
+
request: this.request,
|
643
|
+
options: this._options,
|
644
|
+
error: error,
|
645
|
+
retryCount: this._retryCount,
|
646
|
+
});
|
647
|
+
// If `stop` is returned from the hook, the retry process is stopped
|
648
|
+
if (hookResult === stop) {
|
649
|
+
return;
|
650
|
+
}
|
651
|
+
}
|
652
|
+
return this._retry(fn);
|
653
|
+
}
|
654
|
+
throw error;
|
655
|
+
}
|
656
|
+
}
|
657
|
+
async _fetch() {
|
658
|
+
for (const hook of this._options.hooks.beforeRequest) {
|
659
|
+
// eslint-disable-next-line no-await-in-loop
|
660
|
+
const result = await hook(this.request, this._options);
|
661
|
+
if (result instanceof Request) {
|
662
|
+
this.request = result;
|
663
|
+
break;
|
664
|
+
}
|
665
|
+
if (result instanceof Response) {
|
666
|
+
return result;
|
667
|
+
}
|
668
|
+
}
|
669
|
+
if (this._options.timeout === false) {
|
670
|
+
return this._options.fetch(this.request.clone());
|
671
|
+
}
|
672
|
+
return timeout(this.request.clone(), this.abortController, this._options);
|
673
|
+
}
|
674
|
+
/* istanbul ignore next */
|
675
|
+
_stream(response, onDownloadProgress) {
|
676
|
+
const totalBytes = Number(response.headers.get('content-length')) || 0;
|
677
|
+
let transferredBytes = 0;
|
678
|
+
if (response.status === 204) {
|
679
|
+
if (onDownloadProgress) {
|
680
|
+
onDownloadProgress({ percent: 1, totalBytes, transferredBytes }, new Uint8Array());
|
681
|
+
}
|
682
|
+
return new globalThis.Response(null, {
|
683
|
+
status: response.status,
|
684
|
+
statusText: response.statusText,
|
685
|
+
headers: response.headers,
|
686
|
+
});
|
687
|
+
}
|
688
|
+
return new globalThis.Response(new globalThis.ReadableStream({
|
689
|
+
async start(controller) {
|
690
|
+
const reader = response.body.getReader();
|
691
|
+
if (onDownloadProgress) {
|
692
|
+
onDownloadProgress({ percent: 0, transferredBytes: 0, totalBytes }, new Uint8Array());
|
693
|
+
}
|
694
|
+
async function read() {
|
695
|
+
const { done, value } = await reader.read();
|
696
|
+
if (done) {
|
697
|
+
controller.close();
|
698
|
+
return;
|
699
|
+
}
|
700
|
+
if (onDownloadProgress) {
|
701
|
+
transferredBytes += value.byteLength;
|
702
|
+
const percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
|
703
|
+
onDownloadProgress({ percent, transferredBytes, totalBytes }, value);
|
704
|
+
}
|
705
|
+
controller.enqueue(value);
|
706
|
+
await read();
|
707
|
+
}
|
708
|
+
await read();
|
709
|
+
},
|
710
|
+
}), {
|
711
|
+
status: response.status,
|
712
|
+
statusText: response.statusText,
|
713
|
+
headers: response.headers,
|
714
|
+
});
|
2109
715
|
}
|
2110
|
-
|
2111
|
-
token.reason = new CanceledError_1(message);
|
2112
|
-
resolvePromise(token.reason);
|
2113
|
-
});
|
2114
|
-
}
|
2115
|
-
|
2116
|
-
/**
|
2117
|
-
* Throws a `CanceledError` if cancellation has been requested.
|
2118
|
-
*/
|
2119
|
-
CancelToken.prototype.throwIfRequested = function throwIfRequested() {
|
2120
|
-
if (this.reason) {
|
2121
|
-
throw this.reason;
|
2122
|
-
}
|
2123
|
-
};
|
2124
|
-
|
2125
|
-
/**
|
2126
|
-
* Subscribe to the cancel signal
|
2127
|
-
*/
|
2128
|
-
|
2129
|
-
CancelToken.prototype.subscribe = function subscribe(listener) {
|
2130
|
-
if (this.reason) {
|
2131
|
-
listener(this.reason);
|
2132
|
-
return;
|
2133
|
-
}
|
2134
|
-
|
2135
|
-
if (this._listeners) {
|
2136
|
-
this._listeners.push(listener);
|
2137
|
-
} else {
|
2138
|
-
this._listeners = [listener];
|
2139
|
-
}
|
2140
|
-
};
|
2141
|
-
|
2142
|
-
/**
|
2143
|
-
* Unsubscribe from the cancel signal
|
2144
|
-
*/
|
2145
|
-
|
2146
|
-
CancelToken.prototype.unsubscribe = function unsubscribe(listener) {
|
2147
|
-
if (!this._listeners) {
|
2148
|
-
return;
|
2149
|
-
}
|
2150
|
-
var index = this._listeners.indexOf(listener);
|
2151
|
-
if (index !== -1) {
|
2152
|
-
this._listeners.splice(index, 1);
|
2153
|
-
}
|
2154
|
-
};
|
2155
|
-
|
2156
|
-
/**
|
2157
|
-
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
2158
|
-
* cancels the `CancelToken`.
|
2159
|
-
*/
|
2160
|
-
CancelToken.source = function source() {
|
2161
|
-
var cancel;
|
2162
|
-
var token = new CancelToken(function executor(c) {
|
2163
|
-
cancel = c;
|
2164
|
-
});
|
2165
|
-
return {
|
2166
|
-
token: token,
|
2167
|
-
cancel: cancel
|
2168
|
-
};
|
2169
|
-
};
|
2170
|
-
|
2171
|
-
var CancelToken_1 = CancelToken;
|
2172
|
-
|
2173
|
-
/**
|
2174
|
-
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
2175
|
-
*
|
2176
|
-
* Common use case would be to use `Function.prototype.apply`.
|
2177
|
-
*
|
2178
|
-
* ```js
|
2179
|
-
* function f(x, y, z) {}
|
2180
|
-
* var args = [1, 2, 3];
|
2181
|
-
* f.apply(null, args);
|
2182
|
-
* ```
|
2183
|
-
*
|
2184
|
-
* With `spread` this example can be re-written.
|
2185
|
-
*
|
2186
|
-
* ```js
|
2187
|
-
* spread(function(x, y, z) {})([1, 2, 3]);
|
2188
|
-
* ```
|
2189
|
-
*
|
2190
|
-
* @param {Function} callback
|
2191
|
-
* @returns {Function}
|
2192
|
-
*/
|
2193
|
-
var spread = function spread(callback) {
|
2194
|
-
return function wrap(arr) {
|
2195
|
-
return callback.apply(null, arr);
|
2196
|
-
};
|
2197
|
-
};
|
2198
|
-
|
2199
|
-
/**
|
2200
|
-
* Determines whether the payload is an error thrown by Axios
|
2201
|
-
*
|
2202
|
-
* @param {*} payload The value to test
|
2203
|
-
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
2204
|
-
*/
|
2205
|
-
var isAxiosError = function isAxiosError(payload) {
|
2206
|
-
return utils.isObject(payload) && (payload.isAxiosError === true);
|
2207
|
-
};
|
2208
|
-
|
2209
|
-
/**
|
2210
|
-
* Create an instance of Axios
|
2211
|
-
*
|
2212
|
-
* @param {Object} defaultConfig The default config for the instance
|
2213
|
-
* @return {Axios} A new instance of Axios
|
2214
|
-
*/
|
2215
|
-
function createInstance(defaultConfig) {
|
2216
|
-
var context = new Axios_1(defaultConfig);
|
2217
|
-
var instance = bind(Axios_1.prototype.request, context);
|
2218
|
-
|
2219
|
-
// Copy axios.prototype to instance
|
2220
|
-
utils.extend(instance, Axios_1.prototype, context);
|
2221
|
-
|
2222
|
-
// Copy context to instance
|
2223
|
-
utils.extend(instance, context);
|
2224
|
-
|
2225
|
-
// Factory for creating new instances
|
2226
|
-
instance.create = function create(instanceConfig) {
|
2227
|
-
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
2228
|
-
};
|
2229
|
-
|
2230
|
-
return instance;
|
2231
716
|
}
|
2232
717
|
|
2233
|
-
|
2234
|
-
|
2235
|
-
|
2236
|
-
|
2237
|
-
|
2238
|
-
|
2239
|
-
|
2240
|
-
|
2241
|
-
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2246
|
-
// Expose AxiosError class
|
2247
|
-
axios$1.AxiosError = AxiosError_1;
|
2248
|
-
|
2249
|
-
// alias for CanceledError for backward compatibility
|
2250
|
-
axios$1.Cancel = axios$1.CanceledError;
|
2251
|
-
|
2252
|
-
// Expose all/spread
|
2253
|
-
axios$1.all = function all(promises) {
|
2254
|
-
return Promise.all(promises);
|
718
|
+
/*! MIT License © Sindre Sorhus */
|
719
|
+
const createInstance = (defaults) => {
|
720
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
721
|
+
const ky = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
|
722
|
+
for (const method of requestMethods) {
|
723
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
724
|
+
ky[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
|
725
|
+
}
|
726
|
+
ky.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
|
727
|
+
ky.extend = (newDefaults) => createInstance(validateAndMerge(defaults, newDefaults));
|
728
|
+
ky.stop = stop;
|
729
|
+
return ky;
|
2255
730
|
};
|
2256
|
-
|
2257
|
-
|
2258
|
-
// Expose isAxiosError
|
2259
|
-
axios$1.isAxiosError = isAxiosError;
|
2260
|
-
|
2261
|
-
var axios_1 = axios$1;
|
2262
|
-
|
2263
|
-
// Allow use of default import syntax in TypeScript
|
2264
|
-
var _default = axios$1;
|
2265
|
-
axios_1.default = _default;
|
2266
|
-
|
2267
|
-
var axios = axios_1;
|
731
|
+
const ky = createInstance();
|
2268
732
|
|
2269
733
|
// --------------------------------------------------------[ mutable store ]
|
2270
734
|
const storeDef = {
|
@@ -2401,10 +865,17 @@ const processPick = (next) => {
|
|
2401
865
|
savePick(state.pick);
|
2402
866
|
};
|
2403
867
|
// --------------------------------------------------------[ utils ]
|
2404
|
-
const api =
|
2405
|
-
|
868
|
+
const api = ky.extend({
|
869
|
+
hooks: {
|
870
|
+
beforeRequest: [
|
871
|
+
request => {
|
872
|
+
request.headers.set('X-Requested-With', 'ky');
|
873
|
+
request.headers.set('X-Custom-Header', 'foobar');
|
874
|
+
},
|
875
|
+
],
|
876
|
+
},
|
877
|
+
prefixUrl: 'https://sudoku-rust-api.vercel.app/api',
|
2406
878
|
timeout: 10000,
|
2407
|
-
headers: { 'X-Custom-Header': 'foobar' },
|
2408
879
|
});
|
2409
880
|
const saveInputs = (inputs) => {
|
2410
881
|
bag.inputs.store(inputs);
|
@@ -2445,27 +916,26 @@ const initApp = () => {
|
|
2445
916
|
}
|
2446
917
|
}
|
2447
918
|
};
|
2448
|
-
const refresh = () => {
|
919
|
+
const refresh = async () => {
|
2449
920
|
clearStore(true);
|
2450
921
|
saveInputs([]);
|
2451
922
|
savePick(state.pick);
|
2452
|
-
|
2453
|
-
|
2454
|
-
.get('
|
2455
|
-
.then(({ data }) => {
|
923
|
+
try {
|
924
|
+
// fetch a new puzzle from the api...
|
925
|
+
const data = await api.get('puzzle').json();
|
2456
926
|
updateStore(data);
|
2457
|
-
}
|
2458
|
-
|
927
|
+
}
|
928
|
+
catch (err) {
|
2459
929
|
// handle error...
|
2460
|
-
const { message } =
|
930
|
+
const { message } = err;
|
2461
931
|
console.log('-- ', message);
|
2462
|
-
console.log(
|
932
|
+
console.log(err);
|
2463
933
|
state.error = message;
|
2464
|
-
}
|
2465
|
-
|
934
|
+
}
|
935
|
+
finally {
|
2466
936
|
// always executed
|
2467
937
|
state.loading = false;
|
2468
|
-
}
|
938
|
+
}
|
2469
939
|
};
|
2470
940
|
const select = (cell) => {
|
2471
941
|
processPick(cell);
|