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.

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