axios 1.6.7 → 1.7.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

package/dist/esm/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- // Axios v1.6.7 Copyright (c) 2024 Matt Zabriskie and contributors
1
+ // Axios v1.7.0-beta.0 Copyright (c) 2024 Matt Zabriskie and contributors
2
2
  function bind(fn, thisArg) {
3
3
  return function wrap() {
4
4
  return fn.apply(thisArg, arguments);
@@ -212,6 +212,8 @@ const isFormData = (thing) => {
212
212
  */
213
213
  const isURLSearchParams = kindOfTest('URLSearchParams');
214
214
 
215
+ const [isReadableStream, isRequest, isResponse, isHeaders] = ['ReadableStream', 'Request', 'Response', 'Headers'].map(kindOfTest);
216
+
215
217
  /**
216
218
  * Trim excess whitespace off the beginning and end of a string
217
219
  *
@@ -600,8 +602,7 @@ const toObjectSet = (arrayOrString, delimiter) => {
600
602
  const noop = () => {};
601
603
 
602
604
  const toFiniteNumber = (value, defaultValue) => {
603
- value = +value;
604
- return Number.isFinite(value) ? value : defaultValue;
605
+ return value != null && Number.isFinite(value = +value) ? value : defaultValue;
605
606
  };
606
607
 
607
608
  const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
@@ -682,6 +683,10 @@ const utils$1 = {
682
683
  isBoolean,
683
684
  isObject,
684
685
  isPlainObject,
686
+ isReadableStream,
687
+ isRequest,
688
+ isResponse,
689
+ isHeaders,
685
690
  isUndefined,
686
691
  isDate,
687
692
  isFile,
@@ -1278,11 +1283,14 @@ const hasStandardBrowserWebWorkerEnv = (() => {
1278
1283
  );
1279
1284
  })();
1280
1285
 
1286
+ const origin = hasBrowserEnv && window.location.href || 'http://localhost';
1287
+
1281
1288
  const utils = /*#__PURE__*/Object.freeze({
1282
1289
  __proto__: null,
1283
1290
  hasBrowserEnv: hasBrowserEnv,
1284
1291
  hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
1285
- hasStandardBrowserEnv: hasStandardBrowserEnv
1292
+ hasStandardBrowserEnv: hasStandardBrowserEnv,
1293
+ origin: origin
1286
1294
  });
1287
1295
 
1288
1296
  const platform = {
@@ -1422,7 +1430,7 @@ const defaults = {
1422
1430
 
1423
1431
  transitional: transitionalDefaults,
1424
1432
 
1425
- adapter: ['xhr', 'http'],
1433
+ adapter: ['xhr', 'http', 'fetch'],
1426
1434
 
1427
1435
  transformRequest: [function transformRequest(data, headers) {
1428
1436
  const contentType = headers.getContentType() || '';
@@ -1443,7 +1451,8 @@ const defaults = {
1443
1451
  utils$1.isBuffer(data) ||
1444
1452
  utils$1.isStream(data) ||
1445
1453
  utils$1.isFile(data) ||
1446
- utils$1.isBlob(data)
1454
+ utils$1.isBlob(data) ||
1455
+ utils$1.isReadableStream(data)
1447
1456
  ) {
1448
1457
  return data;
1449
1458
  }
@@ -1486,6 +1495,10 @@ const defaults = {
1486
1495
  const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
1487
1496
  const JSONRequested = this.responseType === 'json';
1488
1497
 
1498
+ if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
1499
+ return data;
1500
+ }
1501
+
1489
1502
  if (data && utils$1.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
1490
1503
  const silentJSONParsing = transitional && transitional.silentJSONParsing;
1491
1504
  const strictJSONParsing = !silentJSONParsing && JSONRequested;
@@ -1689,6 +1702,10 @@ class AxiosHeaders$1 {
1689
1702
  setHeaders(header, valueOrRewrite);
1690
1703
  } else if(utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
1691
1704
  setHeaders(parseHeaders(header), valueOrRewrite);
1705
+ } else if (utils$1.isHeaders(header)) {
1706
+ for (const [key, value] of header.entries()) {
1707
+ setHeader(value, key, rewrite);
1708
+ }
1692
1709
  } else {
1693
1710
  header != null && setHeader(valueOrRewrite, header, rewrite);
1694
1711
  }
@@ -1956,90 +1973,125 @@ function settle(resolve, reject, response) {
1956
1973
  }
1957
1974
  }
1958
1975
 
1959
- const cookies = platform.hasStandardBrowserEnv ?
1976
+ function parseProtocol(url) {
1977
+ const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1978
+ return match && match[1] || '';
1979
+ }
1960
1980
 
1961
- // Standard browser envs support document.cookie
1962
- {
1963
- write(name, value, expires, path, domain, secure) {
1964
- const cookie = [name + '=' + encodeURIComponent(value)];
1981
+ /**
1982
+ * Calculate data maxRate
1983
+ * @param {Number} [samplesCount= 10]
1984
+ * @param {Number} [min= 1000]
1985
+ * @returns {Function}
1986
+ */
1987
+ function speedometer(samplesCount, min) {
1988
+ samplesCount = samplesCount || 10;
1989
+ const bytes = new Array(samplesCount);
1990
+ const timestamps = new Array(samplesCount);
1991
+ let head = 0;
1992
+ let tail = 0;
1993
+ let firstSampleTS;
1965
1994
 
1966
- utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
1995
+ min = min !== undefined ? min : 1000;
1967
1996
 
1968
- utils$1.isString(path) && cookie.push('path=' + path);
1997
+ return function push(chunkLength) {
1998
+ const now = Date.now();
1969
1999
 
1970
- utils$1.isString(domain) && cookie.push('domain=' + domain);
2000
+ const startedAt = timestamps[tail];
1971
2001
 
1972
- secure === true && cookie.push('secure');
2002
+ if (!firstSampleTS) {
2003
+ firstSampleTS = now;
2004
+ }
1973
2005
 
1974
- document.cookie = cookie.join('; ');
1975
- },
2006
+ bytes[head] = chunkLength;
2007
+ timestamps[head] = now;
1976
2008
 
1977
- read(name) {
1978
- const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
1979
- return (match ? decodeURIComponent(match[3]) : null);
1980
- },
2009
+ let i = tail;
2010
+ let bytesCount = 0;
1981
2011
 
1982
- remove(name) {
1983
- this.write(name, '', Date.now() - 86400000);
2012
+ while (i !== head) {
2013
+ bytesCount += bytes[i++];
2014
+ i = i % samplesCount;
1984
2015
  }
1985
- }
1986
2016
 
1987
- :
2017
+ head = (head + 1) % samplesCount;
1988
2018
 
1989
- // Non-standard browser env (web workers, react-native) lack needed support.
1990
- {
1991
- write() {},
1992
- read() {
1993
- return null;
1994
- },
1995
- remove() {}
1996
- };
2019
+ if (head === tail) {
2020
+ tail = (tail + 1) % samplesCount;
2021
+ }
1997
2022
 
1998
- /**
1999
- * Determines whether the specified URL is absolute
2000
- *
2001
- * @param {string} url The URL to test
2002
- *
2003
- * @returns {boolean} True if the specified URL is absolute, otherwise false
2004
- */
2005
- function isAbsoluteURL(url) {
2006
- // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
2007
- // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
2008
- // by any combination of letters, digits, plus, period, or hyphen.
2009
- return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
2010
- }
2023
+ if (now - firstSampleTS < min) {
2024
+ return;
2025
+ }
2011
2026
 
2012
- /**
2013
- * Creates a new URL by combining the specified URLs
2014
- *
2015
- * @param {string} baseURL The base URL
2016
- * @param {string} relativeURL The relative URL
2017
- *
2018
- * @returns {string} The combined URL
2019
- */
2020
- function combineURLs(baseURL, relativeURL) {
2021
- return relativeURL
2022
- ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
2023
- : baseURL;
2027
+ const passed = startedAt && now - startedAt;
2028
+
2029
+ return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
2030
+ };
2024
2031
  }
2025
2032
 
2026
2033
  /**
2027
- * Creates a new URL by combining the baseURL with the requestedURL,
2028
- * only when the requestedURL is not already an absolute URL.
2029
- * If the requestURL is absolute, this function returns the requestedURL untouched.
2030
- *
2031
- * @param {string} baseURL The base URL
2032
- * @param {string} requestedURL Absolute or relative URL to combine
2033
- *
2034
- * @returns {string} The combined full path
2034
+ * Throttle decorator
2035
+ * @param {Function} fn
2036
+ * @param {Number} freq
2037
+ * @return {Function}
2035
2038
  */
2036
- function buildFullPath(baseURL, requestedURL) {
2037
- if (baseURL && !isAbsoluteURL(requestedURL)) {
2038
- return combineURLs(baseURL, requestedURL);
2039
- }
2040
- return requestedURL;
2039
+ function throttle(fn, freq) {
2040
+ let timestamp = 0;
2041
+ const threshold = 1000 / freq;
2042
+ let timer = null;
2043
+ return function throttled() {
2044
+ const force = this === true;
2045
+
2046
+ const now = Date.now();
2047
+ if (force || now - timestamp > threshold) {
2048
+ if (timer) {
2049
+ clearTimeout(timer);
2050
+ timer = null;
2051
+ }
2052
+ timestamp = now;
2053
+ return fn.apply(null, arguments);
2054
+ }
2055
+ if (!timer) {
2056
+ timer = setTimeout(() => {
2057
+ timer = null;
2058
+ timestamp = Date.now();
2059
+ return fn.apply(null, arguments);
2060
+ }, threshold - (now - timestamp));
2061
+ }
2062
+ };
2041
2063
  }
2042
2064
 
2065
+ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
2066
+ let bytesNotified = 0;
2067
+ const _speedometer = speedometer(50, 250);
2068
+
2069
+ return throttle(e => {
2070
+ const loaded = e.loaded;
2071
+ const total = e.lengthComputable ? e.total : undefined;
2072
+ const progressBytes = loaded - bytesNotified;
2073
+ const rate = _speedometer(progressBytes);
2074
+ const inRange = loaded <= total;
2075
+
2076
+ bytesNotified = loaded;
2077
+
2078
+ const data = {
2079
+ loaded,
2080
+ total,
2081
+ progress: total ? (loaded / total) : undefined,
2082
+ bytes: progressBytes,
2083
+ rate: rate ? rate : undefined,
2084
+ estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
2085
+ event: e,
2086
+ lengthComputable: total != null
2087
+ };
2088
+
2089
+ data[isDownloadStream ? 'download' : 'upload'] = true;
2090
+
2091
+ listener(data);
2092
+ }, freq);
2093
+ };
2094
+
2043
2095
  const isURLSameOrigin = platform.hasStandardBrowserEnv ?
2044
2096
 
2045
2097
  // Standard browser envs have full support of the APIs needed to test
@@ -2103,137 +2155,265 @@ const isURLSameOrigin = platform.hasStandardBrowserEnv ?
2103
2155
  };
2104
2156
  })();
2105
2157
 
2106
- function parseProtocol(url) {
2107
- const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
2108
- return match && match[1] || '';
2109
- }
2158
+ const cookies = platform.hasStandardBrowserEnv ?
2110
2159
 
2111
- /**
2112
- * Calculate data maxRate
2113
- * @param {Number} [samplesCount= 10]
2114
- * @param {Number} [min= 1000]
2115
- * @returns {Function}
2116
- */
2117
- function speedometer(samplesCount, min) {
2118
- samplesCount = samplesCount || 10;
2119
- const bytes = new Array(samplesCount);
2120
- const timestamps = new Array(samplesCount);
2121
- let head = 0;
2122
- let tail = 0;
2123
- let firstSampleTS;
2160
+ // Standard browser envs support document.cookie
2161
+ {
2162
+ write(name, value, expires, path, domain, secure) {
2163
+ const cookie = [name + '=' + encodeURIComponent(value)];
2124
2164
 
2125
- min = min !== undefined ? min : 1000;
2165
+ utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
2126
2166
 
2127
- return function push(chunkLength) {
2128
- const now = Date.now();
2167
+ utils$1.isString(path) && cookie.push('path=' + path);
2129
2168
 
2130
- const startedAt = timestamps[tail];
2169
+ utils$1.isString(domain) && cookie.push('domain=' + domain);
2131
2170
 
2132
- if (!firstSampleTS) {
2133
- firstSampleTS = now;
2134
- }
2171
+ secure === true && cookie.push('secure');
2135
2172
 
2136
- bytes[head] = chunkLength;
2137
- timestamps[head] = now;
2173
+ document.cookie = cookie.join('; ');
2174
+ },
2138
2175
 
2139
- let i = tail;
2140
- let bytesCount = 0;
2176
+ read(name) {
2177
+ const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
2178
+ return (match ? decodeURIComponent(match[3]) : null);
2179
+ },
2141
2180
 
2142
- while (i !== head) {
2143
- bytesCount += bytes[i++];
2144
- i = i % samplesCount;
2181
+ remove(name) {
2182
+ this.write(name, '', Date.now() - 86400000);
2145
2183
  }
2184
+ }
2146
2185
 
2147
- head = (head + 1) % samplesCount;
2186
+ :
2148
2187
 
2149
- if (head === tail) {
2150
- tail = (tail + 1) % samplesCount;
2151
- }
2188
+ // Non-standard browser env (web workers, react-native) lack needed support.
2189
+ {
2190
+ write() {},
2191
+ read() {
2192
+ return null;
2193
+ },
2194
+ remove() {}
2195
+ };
2152
2196
 
2153
- if (now - firstSampleTS < min) {
2154
- return;
2155
- }
2197
+ /**
2198
+ * Determines whether the specified URL is absolute
2199
+ *
2200
+ * @param {string} url The URL to test
2201
+ *
2202
+ * @returns {boolean} True if the specified URL is absolute, otherwise false
2203
+ */
2204
+ function isAbsoluteURL(url) {
2205
+ // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
2206
+ // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
2207
+ // by any combination of letters, digits, plus, period, or hyphen.
2208
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
2209
+ }
2156
2210
 
2157
- const passed = startedAt && now - startedAt;
2211
+ /**
2212
+ * Creates a new URL by combining the specified URLs
2213
+ *
2214
+ * @param {string} baseURL The base URL
2215
+ * @param {string} relativeURL The relative URL
2216
+ *
2217
+ * @returns {string} The combined URL
2218
+ */
2219
+ function combineURLs(baseURL, relativeURL) {
2220
+ return relativeURL
2221
+ ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
2222
+ : baseURL;
2223
+ }
2158
2224
 
2159
- return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
2160
- };
2225
+ /**
2226
+ * Creates a new URL by combining the baseURL with the requestedURL,
2227
+ * only when the requestedURL is not already an absolute URL.
2228
+ * If the requestURL is absolute, this function returns the requestedURL untouched.
2229
+ *
2230
+ * @param {string} baseURL The base URL
2231
+ * @param {string} requestedURL Absolute or relative URL to combine
2232
+ *
2233
+ * @returns {string} The combined full path
2234
+ */
2235
+ function buildFullPath(baseURL, requestedURL) {
2236
+ if (baseURL && !isAbsoluteURL(requestedURL)) {
2237
+ return combineURLs(baseURL, requestedURL);
2238
+ }
2239
+ return requestedURL;
2161
2240
  }
2162
2241
 
2163
- function progressEventReducer(listener, isDownloadStream) {
2164
- let bytesNotified = 0;
2165
- const _speedometer = speedometer(50, 250);
2242
+ const headersToObject = (thing) => thing instanceof AxiosHeaders$2 ? { ...thing } : thing;
2166
2243
 
2167
- return e => {
2168
- const loaded = e.loaded;
2169
- const total = e.lengthComputable ? e.total : undefined;
2170
- const progressBytes = loaded - bytesNotified;
2171
- const rate = _speedometer(progressBytes);
2172
- const inRange = loaded <= total;
2244
+ /**
2245
+ * Config-specific merge-function which creates a new config-object
2246
+ * by merging two configuration objects together.
2247
+ *
2248
+ * @param {Object} config1
2249
+ * @param {Object} config2
2250
+ *
2251
+ * @returns {Object} New object resulting from merging config2 to config1
2252
+ */
2253
+ function mergeConfig$1(config1, config2) {
2254
+ // eslint-disable-next-line no-param-reassign
2255
+ config2 = config2 || {};
2256
+ const config = {};
2173
2257
 
2174
- bytesNotified = loaded;
2258
+ function getMergedValue(target, source, caseless) {
2259
+ if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
2260
+ return utils$1.merge.call({caseless}, target, source);
2261
+ } else if (utils$1.isPlainObject(source)) {
2262
+ return utils$1.merge({}, source);
2263
+ } else if (utils$1.isArray(source)) {
2264
+ return source.slice();
2265
+ }
2266
+ return source;
2267
+ }
2175
2268
 
2176
- const data = {
2177
- loaded,
2178
- total,
2179
- progress: total ? (loaded / total) : undefined,
2180
- bytes: progressBytes,
2181
- rate: rate ? rate : undefined,
2182
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
2183
- event: e
2184
- };
2269
+ // eslint-disable-next-line consistent-return
2270
+ function mergeDeepProperties(a, b, caseless) {
2271
+ if (!utils$1.isUndefined(b)) {
2272
+ return getMergedValue(a, b, caseless);
2273
+ } else if (!utils$1.isUndefined(a)) {
2274
+ return getMergedValue(undefined, a, caseless);
2275
+ }
2276
+ }
2185
2277
 
2186
- data[isDownloadStream ? 'download' : 'upload'] = true;
2278
+ // eslint-disable-next-line consistent-return
2279
+ function valueFromConfig2(a, b) {
2280
+ if (!utils$1.isUndefined(b)) {
2281
+ return getMergedValue(undefined, b);
2282
+ }
2283
+ }
2187
2284
 
2188
- listener(data);
2285
+ // eslint-disable-next-line consistent-return
2286
+ function defaultToConfig2(a, b) {
2287
+ if (!utils$1.isUndefined(b)) {
2288
+ return getMergedValue(undefined, b);
2289
+ } else if (!utils$1.isUndefined(a)) {
2290
+ return getMergedValue(undefined, a);
2291
+ }
2292
+ }
2293
+
2294
+ // eslint-disable-next-line consistent-return
2295
+ function mergeDirectKeys(a, b, prop) {
2296
+ if (prop in config2) {
2297
+ return getMergedValue(a, b);
2298
+ } else if (prop in config1) {
2299
+ return getMergedValue(undefined, a);
2300
+ }
2301
+ }
2302
+
2303
+ const mergeMap = {
2304
+ url: valueFromConfig2,
2305
+ method: valueFromConfig2,
2306
+ data: valueFromConfig2,
2307
+ baseURL: defaultToConfig2,
2308
+ transformRequest: defaultToConfig2,
2309
+ transformResponse: defaultToConfig2,
2310
+ paramsSerializer: defaultToConfig2,
2311
+ timeout: defaultToConfig2,
2312
+ timeoutMessage: defaultToConfig2,
2313
+ withCredentials: defaultToConfig2,
2314
+ withXSRFToken: defaultToConfig2,
2315
+ adapter: defaultToConfig2,
2316
+ responseType: defaultToConfig2,
2317
+ xsrfCookieName: defaultToConfig2,
2318
+ xsrfHeaderName: defaultToConfig2,
2319
+ onUploadProgress: defaultToConfig2,
2320
+ onDownloadProgress: defaultToConfig2,
2321
+ decompress: defaultToConfig2,
2322
+ maxContentLength: defaultToConfig2,
2323
+ maxBodyLength: defaultToConfig2,
2324
+ beforeRedirect: defaultToConfig2,
2325
+ transport: defaultToConfig2,
2326
+ httpAgent: defaultToConfig2,
2327
+ httpsAgent: defaultToConfig2,
2328
+ cancelToken: defaultToConfig2,
2329
+ socketPath: defaultToConfig2,
2330
+ responseEncoding: defaultToConfig2,
2331
+ validateStatus: mergeDirectKeys,
2332
+ headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
2189
2333
  };
2334
+
2335
+ utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
2336
+ const merge = mergeMap[prop] || mergeDeepProperties;
2337
+ const configValue = merge(config1[prop], config2[prop], prop);
2338
+ (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
2339
+ });
2340
+
2341
+ return config;
2190
2342
  }
2191
2343
 
2344
+ const resolveConfig = (config) => {
2345
+ const newConfig = mergeConfig$1({}, config);
2346
+
2347
+ let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
2348
+
2349
+ newConfig.headers = headers = AxiosHeaders$2.from(headers);
2350
+
2351
+ newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
2352
+
2353
+ // HTTP basic authentication
2354
+ if (auth) {
2355
+ headers.set('Authorization', 'Basic ' +
2356
+ btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : ''))
2357
+ );
2358
+ }
2359
+
2360
+ let contentType;
2361
+
2362
+ if (utils$1.isFormData(data)) {
2363
+ if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
2364
+ headers.setContentType(undefined); // Let the browser set it
2365
+ } else if ((contentType = headers.getContentType()) !== false) {
2366
+ // fix semicolon duplication issue for ReactNative FormData implementation
2367
+ const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
2368
+ headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
2369
+ }
2370
+ }
2371
+
2372
+ // Add xsrf header
2373
+ // This is only done if running in a standard browser environment.
2374
+ // Specifically not if we're in a web worker, or react-native.
2375
+
2376
+ if (platform.hasStandardBrowserEnv) {
2377
+ withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
2378
+
2379
+ if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
2380
+ // Add xsrf header
2381
+ const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
2382
+
2383
+ if (xsrfValue) {
2384
+ headers.set(xsrfHeaderName, xsrfValue);
2385
+ }
2386
+ }
2387
+ }
2388
+
2389
+ return newConfig;
2390
+ };
2391
+
2192
2392
  const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
2193
2393
 
2194
2394
  const xhrAdapter = isXHRAdapterSupported && function (config) {
2195
2395
  return new Promise(function dispatchXhrRequest(resolve, reject) {
2196
- let requestData = config.data;
2197
- const requestHeaders = AxiosHeaders$2.from(config.headers).normalize();
2198
- let {responseType, withXSRFToken} = config;
2396
+ const _config = resolveConfig(config);
2397
+ let requestData = _config.data;
2398
+ const requestHeaders = AxiosHeaders$2.from(_config.headers).normalize();
2399
+ let {responseType} = _config;
2199
2400
  let onCanceled;
2200
2401
  function done() {
2201
- if (config.cancelToken) {
2202
- config.cancelToken.unsubscribe(onCanceled);
2203
- }
2204
-
2205
- if (config.signal) {
2206
- config.signal.removeEventListener('abort', onCanceled);
2402
+ if (_config.cancelToken) {
2403
+ _config.cancelToken.unsubscribe(onCanceled);
2207
2404
  }
2208
- }
2209
-
2210
- let contentType;
2211
2405
 
2212
- if (utils$1.isFormData(requestData)) {
2213
- if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
2214
- requestHeaders.setContentType(false); // Let the browser set it
2215
- } else if ((contentType = requestHeaders.getContentType()) !== false) {
2216
- // fix semicolon duplication issue for ReactNative FormData implementation
2217
- const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
2218
- requestHeaders.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
2406
+ if (_config.signal) {
2407
+ _config.signal.removeEventListener('abort', onCanceled);
2219
2408
  }
2220
2409
  }
2221
2410
 
2222
2411
  let request = new XMLHttpRequest();
2223
2412
 
2224
- // HTTP basic authentication
2225
- if (config.auth) {
2226
- const username = config.auth.username || '';
2227
- const password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
2228
- requestHeaders.set('Authorization', 'Basic ' + btoa(username + ':' + password));
2229
- }
2230
-
2231
- const fullPath = buildFullPath(config.baseURL, config.url);
2232
-
2233
- request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
2413
+ request.open(_config.method.toUpperCase(), _config.url, true);
2234
2414
 
2235
2415
  // Set the request timeout in MS
2236
- request.timeout = config.timeout;
2416
+ request.timeout = _config.timeout;
2237
2417
 
2238
2418
  function onloadend() {
2239
2419
  if (!request) {
@@ -2295,7 +2475,7 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
2295
2475
  return;
2296
2476
  }
2297
2477
 
2298
- reject(new AxiosError$1('Request aborted', AxiosError$1.ECONNABORTED, config, request));
2478
+ reject(new AxiosError$1('Request aborted', AxiosError$1.ECONNABORTED, _config, request));
2299
2479
 
2300
2480
  // Clean up request
2301
2481
  request = null;
@@ -2305,7 +2485,7 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
2305
2485
  request.onerror = function handleError() {
2306
2486
  // Real errors are hidden from us by the browser
2307
2487
  // onerror should only fire if it's a network error
2308
- reject(new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, config, request));
2488
+ reject(new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, _config, request));
2309
2489
 
2310
2490
  // Clean up request
2311
2491
  request = null;
@@ -2313,37 +2493,21 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
2313
2493
 
2314
2494
  // Handle timeout
2315
2495
  request.ontimeout = function handleTimeout() {
2316
- let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
2317
- const transitional = config.transitional || transitionalDefaults;
2318
- if (config.timeoutErrorMessage) {
2319
- timeoutErrorMessage = config.timeoutErrorMessage;
2496
+ let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
2497
+ const transitional = _config.transitional || transitionalDefaults;
2498
+ if (_config.timeoutErrorMessage) {
2499
+ timeoutErrorMessage = _config.timeoutErrorMessage;
2320
2500
  }
2321
2501
  reject(new AxiosError$1(
2322
2502
  timeoutErrorMessage,
2323
2503
  transitional.clarifyTimeoutError ? AxiosError$1.ETIMEDOUT : AxiosError$1.ECONNABORTED,
2324
- config,
2504
+ _config,
2325
2505
  request));
2326
2506
 
2327
2507
  // Clean up request
2328
2508
  request = null;
2329
2509
  };
2330
2510
 
2331
- // Add xsrf header
2332
- // This is only done if running in a standard browser environment.
2333
- // Specifically not if we're in a web worker, or react-native.
2334
- if(platform.hasStandardBrowserEnv) {
2335
- withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(config));
2336
-
2337
- if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(fullPath))) {
2338
- // Add xsrf header
2339
- const xsrfValue = config.xsrfHeaderName && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
2340
-
2341
- if (xsrfValue) {
2342
- requestHeaders.set(config.xsrfHeaderName, xsrfValue);
2343
- }
2344
- }
2345
- }
2346
-
2347
2511
  // Remove Content-Type if data is undefined
2348
2512
  requestData === undefined && requestHeaders.setContentType(null);
2349
2513
 
@@ -2355,26 +2519,26 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
2355
2519
  }
2356
2520
 
2357
2521
  // Add withCredentials to request if needed
2358
- if (!utils$1.isUndefined(config.withCredentials)) {
2359
- request.withCredentials = !!config.withCredentials;
2522
+ if (!utils$1.isUndefined(_config.withCredentials)) {
2523
+ request.withCredentials = !!_config.withCredentials;
2360
2524
  }
2361
2525
 
2362
2526
  // Add responseType to request if needed
2363
2527
  if (responseType && responseType !== 'json') {
2364
- request.responseType = config.responseType;
2528
+ request.responseType = _config.responseType;
2365
2529
  }
2366
2530
 
2367
2531
  // Handle progress if needed
2368
- if (typeof config.onDownloadProgress === 'function') {
2369
- request.addEventListener('progress', progressEventReducer(config.onDownloadProgress, true));
2532
+ if (typeof _config.onDownloadProgress === 'function') {
2533
+ request.addEventListener('progress', progressEventReducer(_config.onDownloadProgress, true));
2370
2534
  }
2371
2535
 
2372
2536
  // Not all browsers support upload events
2373
- if (typeof config.onUploadProgress === 'function' && request.upload) {
2374
- request.upload.addEventListener('progress', progressEventReducer(config.onUploadProgress));
2537
+ if (typeof _config.onUploadProgress === 'function' && request.upload) {
2538
+ request.upload.addEventListener('progress', progressEventReducer(_config.onUploadProgress));
2375
2539
  }
2376
2540
 
2377
- if (config.cancelToken || config.signal) {
2541
+ if (_config.cancelToken || _config.signal) {
2378
2542
  // Handle cancellation
2379
2543
  // eslint-disable-next-line func-names
2380
2544
  onCanceled = cancel => {
@@ -2386,13 +2550,13 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
2386
2550
  request = null;
2387
2551
  };
2388
2552
 
2389
- config.cancelToken && config.cancelToken.subscribe(onCanceled);
2390
- if (config.signal) {
2391
- config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
2553
+ _config.cancelToken && _config.cancelToken.subscribe(onCanceled);
2554
+ if (_config.signal) {
2555
+ _config.signal.aborted ? onCanceled() : _config.signal.addEventListener('abort', onCanceled);
2392
2556
  }
2393
2557
  }
2394
2558
 
2395
- const protocol = parseProtocol(fullPath);
2559
+ const protocol = parseProtocol(_config.url);
2396
2560
 
2397
2561
  if (protocol && platform.protocols.indexOf(protocol) === -1) {
2398
2562
  reject(new AxiosError$1('Unsupported protocol ' + protocol + ':', AxiosError$1.ERR_BAD_REQUEST, config));
@@ -2405,9 +2569,296 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
2405
2569
  });
2406
2570
  };
2407
2571
 
2572
+ const composeSignals = (signals, timeout) => {
2573
+ let controller = new AbortController();
2574
+
2575
+ let aborted;
2576
+
2577
+ const onabort = function (cancel) {
2578
+ if (!aborted) {
2579
+ aborted = true;
2580
+ unsubscribe();
2581
+ const err = cancel instanceof Error ? cancel : this.reason;
2582
+ controller.abort(err instanceof AxiosError$1 ? err : new CanceledError$1(err instanceof Error ? err.message : err));
2583
+ }
2584
+ };
2585
+
2586
+ let timer = timeout && setTimeout(() => {
2587
+ onabort(new AxiosError$1(`timeout ${timeout} of ms exceeded`, AxiosError$1.ETIMEDOUT));
2588
+ }, timeout);
2589
+
2590
+ const unsubscribe = () => {
2591
+ if (signals) {
2592
+ timer && clearTimeout(timer);
2593
+ timer = null;
2594
+ signals.forEach(signal => {
2595
+ signal &&
2596
+ (signal.removeEventListener ? signal.removeEventListener('abort', onabort) : signal.unsubscribe(onabort));
2597
+ });
2598
+ signals = null;
2599
+ }
2600
+ };
2601
+
2602
+ signals.forEach((signal) => signal && signal.addEventListener && signal.addEventListener('abort', onabort));
2603
+
2604
+ const {signal} = controller;
2605
+
2606
+ signal.unsubscribe = unsubscribe;
2607
+
2608
+ return [signal, () => {
2609
+ timer && clearTimeout(timer);
2610
+ timer = null;
2611
+ }];
2612
+ };
2613
+
2614
+ const composeSignals$1 = composeSignals;
2615
+
2616
+ const streamChunk = function* (chunk, chunkSize) {
2617
+ let len = chunk.byteLength;
2618
+
2619
+ if (!chunkSize || len < chunkSize) {
2620
+ yield chunk;
2621
+ return;
2622
+ }
2623
+
2624
+ let pos = 0;
2625
+ let end;
2626
+
2627
+ while (pos < len) {
2628
+ end = pos + chunkSize;
2629
+ yield chunk.slice(pos, end);
2630
+ pos = end;
2631
+ }
2632
+ };
2633
+
2634
+ const encoder = new TextEncoder();
2635
+
2636
+ const readBytes = async function* (iterable, chunkSize) {
2637
+ for await (const chunk of iterable) {
2638
+ yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encoder.encode(String(chunk))), chunkSize);
2639
+ }
2640
+ };
2641
+
2642
+ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
2643
+ const iterator = readBytes(stream, chunkSize);
2644
+
2645
+ let bytes = 0;
2646
+
2647
+ return new ReadableStream({
2648
+ type: 'bytes',
2649
+
2650
+ async pull(controller) {
2651
+ const {done, value} = await iterator.next();
2652
+
2653
+ if (done) {
2654
+ controller.close();
2655
+ onFinish();
2656
+ return;
2657
+ }
2658
+
2659
+ let len = value.byteLength;
2660
+ onProgress && onProgress(bytes += len);
2661
+ controller.enqueue(new Uint8Array(value));
2662
+ },
2663
+ cancel(reason) {
2664
+ onFinish(reason);
2665
+ return iterator.return();
2666
+ }
2667
+ }, {
2668
+ highWaterMark: 2
2669
+ })
2670
+ };
2671
+
2672
+ const fetchProgressDecorator = (total, fn) => {
2673
+ const lengthComputable = total != null;
2674
+ return (loaded) => setTimeout(() => fn({
2675
+ lengthComputable,
2676
+ total,
2677
+ loaded
2678
+ }));
2679
+ };
2680
+
2681
+ const isFetchSupported = typeof fetch !== 'undefined';
2682
+
2683
+ const supportsRequestStreams = isFetchSupported && (() => {
2684
+ let duplexAccessed = false;
2685
+
2686
+ const hasContentType = new Request(platform.origin, {
2687
+ body: new ReadableStream(),
2688
+ method: 'POST',
2689
+ get duplex() {
2690
+ duplexAccessed = true;
2691
+ return 'half';
2692
+ },
2693
+ }).headers.has('Content-Type');
2694
+
2695
+ return duplexAccessed && !hasContentType;
2696
+ })();
2697
+
2698
+ const DEFAULT_CHUNK_SIZE = 64 * 1024;
2699
+
2700
+ const resolvers = {
2701
+ stream: (res) => res.body
2702
+ };
2703
+
2704
+ isFetchSupported && ['text', 'arrayBuffer', 'blob', 'formData'].forEach(type => [
2705
+ resolvers[type] = utils$1.isFunction(Response.prototype[type]) ? (res) => res[type]() : (_, config) => {
2706
+ throw new AxiosError$1(`Response type ${type} is not supported`, AxiosError$1.ERR_NOT_SUPPORT, config);
2707
+ }
2708
+ ]);
2709
+
2710
+ const getBodyLength = async (body) => {
2711
+ if(utils$1.isBlob(body)) {
2712
+ return body.size;
2713
+ }
2714
+
2715
+ if(utils$1.isSpecCompliantForm(body)) {
2716
+ return (await new Request(body).arrayBuffer()).byteLength;
2717
+ }
2718
+
2719
+ if(utils$1.isArrayBufferView(body)) {
2720
+ return body.byteLength;
2721
+ }
2722
+
2723
+ if(utils$1.isURLSearchParams(body)) {
2724
+ body = body + '';
2725
+ }
2726
+
2727
+ if(utils$1.isString(body)) {
2728
+ return (await new TextEncoder().encode(body)).byteLength;
2729
+ }
2730
+ };
2731
+
2732
+ const resolveBodyLength = async (headers, body) => {
2733
+ const length = utils$1.toFiniteNumber(headers.getContentLength());
2734
+
2735
+ return length == null ? getBodyLength(body) : length;
2736
+ };
2737
+
2738
+ const fetchAdapter = async (config) => {
2739
+ let {
2740
+ url,
2741
+ method,
2742
+ data,
2743
+ signal,
2744
+ cancelToken,
2745
+ timeout,
2746
+ onDownloadProgress,
2747
+ onUploadProgress,
2748
+ responseType,
2749
+ headers,
2750
+ withCredentials = 'same-origin',
2751
+ fetchOptions
2752
+ } = resolveConfig(config);
2753
+
2754
+ responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2755
+
2756
+ let [composedSignal, stopTimeout] = (signal || cancelToken || timeout) ?
2757
+ composeSignals$1([signal, cancelToken], timeout) : [];
2758
+
2759
+ let finished, request;
2760
+
2761
+ const onFinish = () => {
2762
+ !finished && setTimeout(() => {
2763
+ composedSignal && composedSignal.unsubscribe();
2764
+ });
2765
+
2766
+ finished = true;
2767
+ };
2768
+
2769
+ try {
2770
+ if (onUploadProgress && supportsRequestStreams && method !== 'get' && method !== 'head') {
2771
+ let requestContentLength = await resolveBodyLength(headers, data);
2772
+
2773
+ let _request = new Request(url, {
2774
+ method,
2775
+ body: data,
2776
+ duplex: "half"
2777
+ });
2778
+
2779
+ let contentTypeHeader;
2780
+
2781
+ if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
2782
+ headers.setContentType(contentTypeHeader);
2783
+ }
2784
+
2785
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(
2786
+ requestContentLength,
2787
+ progressEventReducer(onUploadProgress)
2788
+ ));
2789
+ }
2790
+
2791
+ if (!utils$1.isString(withCredentials)) {
2792
+ withCredentials = withCredentials ? 'cors' : 'omit';
2793
+ }
2794
+
2795
+ request = new Request(url, {
2796
+ ...fetchOptions,
2797
+ signal: composedSignal,
2798
+ method,
2799
+ headers: headers.normalize().toJSON(),
2800
+ body: data,
2801
+ duplex: "half",
2802
+ withCredentials
2803
+ });
2804
+
2805
+ let response = await fetch(request);
2806
+
2807
+ const isStreamResponse = responseType === 'stream' || responseType === 'response';
2808
+
2809
+ if (onDownloadProgress || isStreamResponse) {
2810
+ const options = {};
2811
+
2812
+ Object.getOwnPropertyNames(response).forEach(prop => {
2813
+ options[prop] = response[prop];
2814
+ });
2815
+
2816
+ const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
2817
+
2818
+ response = new Response(
2819
+ trackStream(response.body, DEFAULT_CHUNK_SIZE, onDownloadProgress && fetchProgressDecorator(
2820
+ responseContentLength,
2821
+ progressEventReducer(onDownloadProgress, true)
2822
+ ), isStreamResponse && onFinish),
2823
+ options
2824
+ );
2825
+ }
2826
+
2827
+ responseType = responseType || 'text';
2828
+
2829
+ let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
2830
+
2831
+ !isStreamResponse && onFinish();
2832
+
2833
+ stopTimeout && stopTimeout();
2834
+
2835
+ return await new Promise((resolve, reject) => {
2836
+ settle(resolve, reject, {
2837
+ data: responseData,
2838
+ headers: AxiosHeaders$2.from(response.headers),
2839
+ status: response.status,
2840
+ statusText: response.statusText,
2841
+ config,
2842
+ request
2843
+ });
2844
+ })
2845
+ } catch (err) {
2846
+ onFinish();
2847
+
2848
+ let {code} = err;
2849
+
2850
+ if (err.name === 'NetworkError') {
2851
+ code = AxiosError$1.ERR_NETWORK;
2852
+ }
2853
+
2854
+ throw AxiosError$1.from(err, code, config, request);
2855
+ }
2856
+ };
2857
+
2408
2858
  const knownAdapters = {
2409
2859
  http: httpAdapter,
2410
- xhr: xhrAdapter
2860
+ xhr: xhrAdapter,
2861
+ fetch: fetchAdapter
2411
2862
  };
2412
2863
 
2413
2864
  utils$1.forEach(knownAdapters, (fn, value) => {
@@ -2551,109 +3002,7 @@ function dispatchRequest(config) {
2551
3002
  });
2552
3003
  }
2553
3004
 
2554
- const headersToObject = (thing) => thing instanceof AxiosHeaders$2 ? thing.toJSON() : thing;
2555
-
2556
- /**
2557
- * Config-specific merge-function which creates a new config-object
2558
- * by merging two configuration objects together.
2559
- *
2560
- * @param {Object} config1
2561
- * @param {Object} config2
2562
- *
2563
- * @returns {Object} New object resulting from merging config2 to config1
2564
- */
2565
- function mergeConfig$1(config1, config2) {
2566
- // eslint-disable-next-line no-param-reassign
2567
- config2 = config2 || {};
2568
- const config = {};
2569
-
2570
- function getMergedValue(target, source, caseless) {
2571
- if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
2572
- return utils$1.merge.call({caseless}, target, source);
2573
- } else if (utils$1.isPlainObject(source)) {
2574
- return utils$1.merge({}, source);
2575
- } else if (utils$1.isArray(source)) {
2576
- return source.slice();
2577
- }
2578
- return source;
2579
- }
2580
-
2581
- // eslint-disable-next-line consistent-return
2582
- function mergeDeepProperties(a, b, caseless) {
2583
- if (!utils$1.isUndefined(b)) {
2584
- return getMergedValue(a, b, caseless);
2585
- } else if (!utils$1.isUndefined(a)) {
2586
- return getMergedValue(undefined, a, caseless);
2587
- }
2588
- }
2589
-
2590
- // eslint-disable-next-line consistent-return
2591
- function valueFromConfig2(a, b) {
2592
- if (!utils$1.isUndefined(b)) {
2593
- return getMergedValue(undefined, b);
2594
- }
2595
- }
2596
-
2597
- // eslint-disable-next-line consistent-return
2598
- function defaultToConfig2(a, b) {
2599
- if (!utils$1.isUndefined(b)) {
2600
- return getMergedValue(undefined, b);
2601
- } else if (!utils$1.isUndefined(a)) {
2602
- return getMergedValue(undefined, a);
2603
- }
2604
- }
2605
-
2606
- // eslint-disable-next-line consistent-return
2607
- function mergeDirectKeys(a, b, prop) {
2608
- if (prop in config2) {
2609
- return getMergedValue(a, b);
2610
- } else if (prop in config1) {
2611
- return getMergedValue(undefined, a);
2612
- }
2613
- }
2614
-
2615
- const mergeMap = {
2616
- url: valueFromConfig2,
2617
- method: valueFromConfig2,
2618
- data: valueFromConfig2,
2619
- baseURL: defaultToConfig2,
2620
- transformRequest: defaultToConfig2,
2621
- transformResponse: defaultToConfig2,
2622
- paramsSerializer: defaultToConfig2,
2623
- timeout: defaultToConfig2,
2624
- timeoutMessage: defaultToConfig2,
2625
- withCredentials: defaultToConfig2,
2626
- withXSRFToken: defaultToConfig2,
2627
- adapter: defaultToConfig2,
2628
- responseType: defaultToConfig2,
2629
- xsrfCookieName: defaultToConfig2,
2630
- xsrfHeaderName: defaultToConfig2,
2631
- onUploadProgress: defaultToConfig2,
2632
- onDownloadProgress: defaultToConfig2,
2633
- decompress: defaultToConfig2,
2634
- maxContentLength: defaultToConfig2,
2635
- maxBodyLength: defaultToConfig2,
2636
- beforeRedirect: defaultToConfig2,
2637
- transport: defaultToConfig2,
2638
- httpAgent: defaultToConfig2,
2639
- httpsAgent: defaultToConfig2,
2640
- cancelToken: defaultToConfig2,
2641
- socketPath: defaultToConfig2,
2642
- responseEncoding: defaultToConfig2,
2643
- validateStatus: mergeDirectKeys,
2644
- headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
2645
- };
2646
-
2647
- utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
2648
- const merge = mergeMap[prop] || mergeDeepProperties;
2649
- const configValue = merge(config1[prop], config2[prop], prop);
2650
- (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
2651
- });
2652
-
2653
- return config;
2654
- }
2655
-
2656
- const VERSION$1 = "1.6.7";
3005
+ const VERSION$1 = "1.7.0-beta.0";
2657
3006
 
2658
3007
  const validators$1 = {};
2659
3008