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