axios 1.2.0-alpha.1 → 1.2.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/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- // Axios v1.2.0-alpha.1 Copyright (c) 2022 Matt Zabriskie and contributors
1
+ // Axios v1.2.0 Copyright (c) 2022 Matt Zabriskie and contributors
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -666,6 +666,28 @@
666
666
  value = +value;
667
667
  return Number.isFinite(value) ? value : defaultValue;
668
668
  };
669
+ var toJSONObject = function toJSONObject(obj) {
670
+ var stack = new Array(10);
671
+ var visit = function visit(source, i) {
672
+ if (isObject(source)) {
673
+ if (stack.indexOf(source) >= 0) {
674
+ return;
675
+ }
676
+ if (!('toJSON' in source)) {
677
+ stack[i] = source;
678
+ var target = isArray(source) ? [] : {};
679
+ forEach(source, function (value, key) {
680
+ var reducedValue = visit(value, i + 1);
681
+ !isUndefined(reducedValue) && (target[key] = reducedValue);
682
+ });
683
+ stack[i] = undefined;
684
+ return target;
685
+ }
686
+ }
687
+ return source;
688
+ };
689
+ return visit(obj, 0);
690
+ };
669
691
  var utils = {
670
692
  isArray: isArray,
671
693
  isArrayBuffer: isArrayBuffer,
@@ -712,7 +734,8 @@
712
734
  toFiniteNumber: toFiniteNumber,
713
735
  findKey: findKey,
714
736
  global: _global,
715
- isContextDefined: isContextDefined
737
+ isContextDefined: isContextDefined,
738
+ toJSONObject: toJSONObject
716
739
  };
717
740
 
718
741
  /**
@@ -755,7 +778,7 @@
755
778
  columnNumber: this.columnNumber,
756
779
  stack: this.stack,
757
780
  // Axios
758
- config: this.config,
781
+ config: utils.toJSONObject(this.config),
759
782
  code: this.code,
760
783
  status: this.response && this.response.status ? this.response.status : null
761
784
  };
@@ -1289,238 +1312,180 @@
1289
1312
  return null;
1290
1313
  }
1291
1314
 
1315
+ var DEFAULT_CONTENT_TYPE = {
1316
+ 'Content-Type': undefined
1317
+ };
1318
+
1292
1319
  /**
1293
- * Resolve or reject a Promise based on response status.
1320
+ * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1321
+ * of the input
1294
1322
  *
1295
- * @param {Function} resolve A function that resolves the promise.
1296
- * @param {Function} reject A function that rejects the promise.
1297
- * @param {object} response The response.
1323
+ * @param {any} rawValue - The value to be stringified.
1324
+ * @param {Function} parser - A function that parses a string into a JavaScript object.
1325
+ * @param {Function} encoder - A function that takes a value and returns a string.
1298
1326
  *
1299
- * @returns {object} The response.
1327
+ * @returns {string} A stringified version of the rawValue.
1300
1328
  */
1301
- function settle(resolve, reject, response) {
1302
- var validateStatus = response.config.validateStatus;
1303
- if (!response.status || !validateStatus || validateStatus(response.status)) {
1304
- resolve(response);
1305
- } else {
1306
- reject(new AxiosError('Request failed with status code ' + response.status, [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4], response.config, response.request, response));
1329
+ function stringifySafely(rawValue, parser, encoder) {
1330
+ if (utils.isString(rawValue)) {
1331
+ try {
1332
+ (parser || JSON.parse)(rawValue);
1333
+ return utils.trim(rawValue);
1334
+ } catch (e) {
1335
+ if (e.name !== 'SyntaxError') {
1336
+ throw e;
1337
+ }
1338
+ }
1307
1339
  }
1340
+ return (encoder || JSON.stringify)(rawValue);
1308
1341
  }
1309
-
1310
- var cookies = platform.isStandardBrowserEnv ?
1311
- // Standard browser envs support document.cookie
1312
- function standardBrowserEnv() {
1313
- return {
1314
- write: function write(name, value, expires, path, domain, secure) {
1315
- var cookie = [];
1316
- cookie.push(name + '=' + encodeURIComponent(value));
1317
- if (utils.isNumber(expires)) {
1318
- cookie.push('expires=' + new Date(expires).toGMTString());
1342
+ var defaults = {
1343
+ transitional: transitionalDefaults,
1344
+ adapter: ['xhr', 'http'],
1345
+ transformRequest: [function transformRequest(data, headers) {
1346
+ var contentType = headers.getContentType() || '';
1347
+ var hasJSONContentType = contentType.indexOf('application/json') > -1;
1348
+ var isObjectPayload = utils.isObject(data);
1349
+ if (isObjectPayload && utils.isHTMLForm(data)) {
1350
+ data = new FormData(data);
1351
+ }
1352
+ var isFormData = utils.isFormData(data);
1353
+ if (isFormData) {
1354
+ if (!hasJSONContentType) {
1355
+ return data;
1319
1356
  }
1320
- if (utils.isString(path)) {
1321
- cookie.push('path=' + path);
1357
+ return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
1358
+ }
1359
+ if (utils.isArrayBuffer(data) || utils.isBuffer(data) || utils.isStream(data) || utils.isFile(data) || utils.isBlob(data)) {
1360
+ return data;
1361
+ }
1362
+ if (utils.isArrayBufferView(data)) {
1363
+ return data.buffer;
1364
+ }
1365
+ if (utils.isURLSearchParams(data)) {
1366
+ headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
1367
+ return data.toString();
1368
+ }
1369
+ var isFileList;
1370
+ if (isObjectPayload) {
1371
+ if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
1372
+ return toURLEncodedForm(data, this.formSerializer).toString();
1322
1373
  }
1323
- if (utils.isString(domain)) {
1324
- cookie.push('domain=' + domain);
1374
+ if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
1375
+ var _FormData = this.env && this.env.FormData;
1376
+ return toFormData(isFileList ? {
1377
+ 'files[]': data
1378
+ } : data, _FormData && new _FormData(), this.formSerializer);
1325
1379
  }
1326
- if (secure === true) {
1327
- cookie.push('secure');
1380
+ }
1381
+ if (isObjectPayload || hasJSONContentType) {
1382
+ headers.setContentType('application/json', false);
1383
+ return stringifySafely(data);
1384
+ }
1385
+ return data;
1386
+ }],
1387
+ transformResponse: [function transformResponse(data) {
1388
+ var transitional = this.transitional || defaults.transitional;
1389
+ var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
1390
+ var JSONRequested = this.responseType === 'json';
1391
+ if (data && utils.isString(data) && (forcedJSONParsing && !this.responseType || JSONRequested)) {
1392
+ var silentJSONParsing = transitional && transitional.silentJSONParsing;
1393
+ var strictJSONParsing = !silentJSONParsing && JSONRequested;
1394
+ try {
1395
+ return JSON.parse(data);
1396
+ } catch (e) {
1397
+ if (strictJSONParsing) {
1398
+ if (e.name === 'SyntaxError') {
1399
+ throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
1400
+ }
1401
+ throw e;
1402
+ }
1328
1403
  }
1329
- document.cookie = cookie.join('; ');
1330
- },
1331
- read: function read(name) {
1332
- var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
1333
- return match ? decodeURIComponent(match[3]) : null;
1334
- },
1335
- remove: function remove(name) {
1336
- this.write(name, '', Date.now() - 86400000);
1337
1404
  }
1338
- };
1339
- }() :
1340
- // Non standard browser env (web workers, react-native) lack needed support.
1341
- function nonStandardBrowserEnv() {
1342
- return {
1343
- write: function write() {},
1344
- read: function read() {
1345
- return null;
1346
- },
1347
- remove: function remove() {}
1348
- };
1349
- }();
1405
+ return data;
1406
+ }],
1407
+ /**
1408
+ * A timeout in milliseconds to abort a request. If set to 0 (default) a
1409
+ * timeout is not created.
1410
+ */
1411
+ timeout: 0,
1412
+ xsrfCookieName: 'XSRF-TOKEN',
1413
+ xsrfHeaderName: 'X-XSRF-TOKEN',
1414
+ maxContentLength: -1,
1415
+ maxBodyLength: -1,
1416
+ env: {
1417
+ FormData: platform.classes.FormData,
1418
+ Blob: platform.classes.Blob
1419
+ },
1420
+ validateStatus: function validateStatus(status) {
1421
+ return status >= 200 && status < 300;
1422
+ },
1423
+ headers: {
1424
+ common: {
1425
+ 'Accept': 'application/json, text/plain, */*'
1426
+ }
1427
+ }
1428
+ };
1429
+ utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
1430
+ defaults.headers[method] = {};
1431
+ });
1432
+ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
1433
+ defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
1434
+ });
1435
+ var defaults$1 = defaults;
1350
1436
 
1351
- /**
1352
- * Determines whether the specified URL is absolute
1353
- *
1354
- * @param {string} url The URL to test
1355
- *
1356
- * @returns {boolean} True if the specified URL is absolute, otherwise false
1357
- */
1358
- function isAbsoluteURL(url) {
1359
- // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
1360
- // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
1361
- // by any combination of letters, digits, plus, period, or hyphen.
1362
- return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
1363
- }
1437
+ // RawAxiosHeaders whose duplicates are ignored by node
1438
+ // c.f. https://nodejs.org/api/http.html#http_message_headers
1439
+ var ignoreDuplicateOf = utils.toObjectSet(['age', 'authorization', 'content-length', 'content-type', 'etag', 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since', 'last-modified', 'location', 'max-forwards', 'proxy-authorization', 'referer', 'retry-after', 'user-agent']);
1364
1440
 
1365
1441
  /**
1366
- * Creates a new URL by combining the specified URLs
1367
- *
1368
- * @param {string} baseURL The base URL
1369
- * @param {string} relativeURL The relative URL
1442
+ * Parse headers into an object
1370
1443
  *
1371
- * @returns {string} The combined URL
1372
- */
1373
- function combineURLs(baseURL, relativeURL) {
1374
- return relativeURL ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') : baseURL;
1375
- }
1376
-
1377
- /**
1378
- * Creates a new URL by combining the baseURL with the requestedURL,
1379
- * only when the requestedURL is not already an absolute URL.
1380
- * If the requestURL is absolute, this function returns the requestedURL untouched.
1444
+ * ```
1445
+ * Date: Wed, 27 Aug 2014 08:58:49 GMT
1446
+ * Content-Type: application/json
1447
+ * Connection: keep-alive
1448
+ * Transfer-Encoding: chunked
1449
+ * ```
1381
1450
  *
1382
- * @param {string} baseURL The base URL
1383
- * @param {string} requestedURL Absolute or relative URL to combine
1451
+ * @param {String} rawHeaders Headers needing to be parsed
1384
1452
  *
1385
- * @returns {string} The combined full path
1453
+ * @returns {Object} Headers parsed into an object
1386
1454
  */
1387
- function buildFullPath(baseURL, requestedURL) {
1388
- if (baseURL && !isAbsoluteURL(requestedURL)) {
1389
- return combineURLs(baseURL, requestedURL);
1455
+ var parseHeaders = (function (rawHeaders) {
1456
+ var parsed = {};
1457
+ var key;
1458
+ var val;
1459
+ var i;
1460
+ rawHeaders && rawHeaders.split('\n').forEach(function parser(line) {
1461
+ i = line.indexOf(':');
1462
+ key = line.substring(0, i).trim().toLowerCase();
1463
+ val = line.substring(i + 1).trim();
1464
+ if (!key || parsed[key] && ignoreDuplicateOf[key]) {
1465
+ return;
1466
+ }
1467
+ if (key === 'set-cookie') {
1468
+ if (parsed[key]) {
1469
+ parsed[key].push(val);
1470
+ } else {
1471
+ parsed[key] = [val];
1472
+ }
1473
+ } else {
1474
+ parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
1475
+ }
1476
+ });
1477
+ return parsed;
1478
+ });
1479
+
1480
+ var $internals = Symbol('internals');
1481
+ function normalizeHeader(header) {
1482
+ return header && String(header).trim().toLowerCase();
1483
+ }
1484
+ function normalizeValue(value) {
1485
+ if (value === false || value == null) {
1486
+ return value;
1390
1487
  }
1391
- return requestedURL;
1392
- }
1393
-
1394
- var isURLSameOrigin = platform.isStandardBrowserEnv ?
1395
- // Standard browser envs have full support of the APIs needed to test
1396
- // whether the request URL is of the same origin as current location.
1397
- function standardBrowserEnv() {
1398
- var msie = /(msie|trident)/i.test(navigator.userAgent);
1399
- var urlParsingNode = document.createElement('a');
1400
- var originURL;
1401
-
1402
- /**
1403
- * Parse a URL to discover it's components
1404
- *
1405
- * @param {String} url The URL to be parsed
1406
- * @returns {Object}
1407
- */
1408
- function resolveURL(url) {
1409
- var href = url;
1410
- if (msie) {
1411
- // IE needs attribute set twice to normalize properties
1412
- urlParsingNode.setAttribute('href', href);
1413
- href = urlParsingNode.href;
1414
- }
1415
- urlParsingNode.setAttribute('href', href);
1416
-
1417
- // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
1418
- return {
1419
- href: urlParsingNode.href,
1420
- protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
1421
- host: urlParsingNode.host,
1422
- search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
1423
- hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
1424
- hostname: urlParsingNode.hostname,
1425
- port: urlParsingNode.port,
1426
- pathname: urlParsingNode.pathname.charAt(0) === '/' ? urlParsingNode.pathname : '/' + urlParsingNode.pathname
1427
- };
1428
- }
1429
- originURL = resolveURL(window.location.href);
1430
-
1431
- /**
1432
- * Determine if a URL shares the same origin as the current location
1433
- *
1434
- * @param {String} requestURL The URL to test
1435
- * @returns {boolean} True if URL shares the same origin, otherwise false
1436
- */
1437
- return function isURLSameOrigin(requestURL) {
1438
- var parsed = utils.isString(requestURL) ? resolveURL(requestURL) : requestURL;
1439
- return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
1440
- };
1441
- }() :
1442
- // Non standard browser envs (web workers, react-native) lack needed support.
1443
- function nonStandardBrowserEnv() {
1444
- return function isURLSameOrigin() {
1445
- return true;
1446
- };
1447
- }();
1448
-
1449
- /**
1450
- * A `CanceledError` is an object that is thrown when an operation is canceled.
1451
- *
1452
- * @param {string=} message The message.
1453
- * @param {Object=} config The config.
1454
- * @param {Object=} request The request.
1455
- *
1456
- * @returns {CanceledError} The created error.
1457
- */
1458
- function CanceledError(message, config, request) {
1459
- // eslint-disable-next-line no-eq-null,eqeqeq
1460
- AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
1461
- this.name = 'CanceledError';
1462
- }
1463
- utils.inherits(CanceledError, AxiosError, {
1464
- __CANCEL__: true
1465
- });
1466
-
1467
- function parseProtocol(url) {
1468
- var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1469
- return match && match[1] || '';
1470
- }
1471
-
1472
- // RawAxiosHeaders whose duplicates are ignored by node
1473
- // c.f. https://nodejs.org/api/http.html#http_message_headers
1474
- var ignoreDuplicateOf = utils.toObjectSet(['age', 'authorization', 'content-length', 'content-type', 'etag', 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since', 'last-modified', 'location', 'max-forwards', 'proxy-authorization', 'referer', 'retry-after', 'user-agent']);
1475
-
1476
- /**
1477
- * Parse headers into an object
1478
- *
1479
- * ```
1480
- * Date: Wed, 27 Aug 2014 08:58:49 GMT
1481
- * Content-Type: application/json
1482
- * Connection: keep-alive
1483
- * Transfer-Encoding: chunked
1484
- * ```
1485
- *
1486
- * @param {String} rawHeaders Headers needing to be parsed
1487
- *
1488
- * @returns {Object} Headers parsed into an object
1489
- */
1490
- var parseHeaders = (function (rawHeaders) {
1491
- var parsed = {};
1492
- var key;
1493
- var val;
1494
- var i;
1495
- rawHeaders && rawHeaders.split('\n').forEach(function parser(line) {
1496
- i = line.indexOf(':');
1497
- key = line.substring(0, i).trim().toLowerCase();
1498
- val = line.substring(i + 1).trim();
1499
- if (!key || parsed[key] && ignoreDuplicateOf[key]) {
1500
- return;
1501
- }
1502
- if (key === 'set-cookie') {
1503
- if (parsed[key]) {
1504
- parsed[key].push(val);
1505
- } else {
1506
- parsed[key] = [val];
1507
- }
1508
- } else {
1509
- parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
1510
- }
1511
- });
1512
- return parsed;
1513
- });
1514
-
1515
- var $internals = Symbol('internals');
1516
- function normalizeHeader(header) {
1517
- return header && String(header).trim().toLowerCase();
1518
- }
1519
- function normalizeValue(value) {
1520
- if (value === false || value == null) {
1521
- return value;
1522
- }
1523
- return utils.isArray(value) ? value.map(normalizeValue) : String(value);
1488
+ return utils.isArray(value) ? value.map(normalizeValue) : String(value);
1524
1489
  }
1525
1490
  function parseTokens(str) {
1526
1491
  var tokens = Object.create(null);
@@ -1758,6 +1723,213 @@
1758
1723
  utils.freezeMethods(AxiosHeaders);
1759
1724
  var AxiosHeaders$1 = AxiosHeaders;
1760
1725
 
1726
+ /**
1727
+ * Transform the data for a request or a response
1728
+ *
1729
+ * @param {Array|Function} fns A single function or Array of functions
1730
+ * @param {?Object} response The response object
1731
+ *
1732
+ * @returns {*} The resulting transformed data
1733
+ */
1734
+ function transformData(fns, response) {
1735
+ var config = this || defaults$1;
1736
+ var context = response || config;
1737
+ var headers = AxiosHeaders$1.from(context.headers);
1738
+ var data = context.data;
1739
+ utils.forEach(fns, function transform(fn) {
1740
+ data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
1741
+ });
1742
+ headers.normalize();
1743
+ return data;
1744
+ }
1745
+
1746
+ function isCancel(value) {
1747
+ return !!(value && value.__CANCEL__);
1748
+ }
1749
+
1750
+ /**
1751
+ * A `CanceledError` is an object that is thrown when an operation is canceled.
1752
+ *
1753
+ * @param {string=} message The message.
1754
+ * @param {Object=} config The config.
1755
+ * @param {Object=} request The request.
1756
+ *
1757
+ * @returns {CanceledError} The created error.
1758
+ */
1759
+ function CanceledError(message, config, request) {
1760
+ // eslint-disable-next-line no-eq-null,eqeqeq
1761
+ AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
1762
+ this.name = 'CanceledError';
1763
+ }
1764
+ utils.inherits(CanceledError, AxiosError, {
1765
+ __CANCEL__: true
1766
+ });
1767
+
1768
+ // eslint-disable-next-line strict
1769
+ var httpAdapter = null;
1770
+
1771
+ /**
1772
+ * Resolve or reject a Promise based on response status.
1773
+ *
1774
+ * @param {Function} resolve A function that resolves the promise.
1775
+ * @param {Function} reject A function that rejects the promise.
1776
+ * @param {object} response The response.
1777
+ *
1778
+ * @returns {object} The response.
1779
+ */
1780
+ function settle(resolve, reject, response) {
1781
+ var validateStatus = response.config.validateStatus;
1782
+ if (!response.status || !validateStatus || validateStatus(response.status)) {
1783
+ resolve(response);
1784
+ } else {
1785
+ reject(new AxiosError('Request failed with status code ' + response.status, [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4], response.config, response.request, response));
1786
+ }
1787
+ }
1788
+
1789
+ var cookies = platform.isStandardBrowserEnv ?
1790
+ // Standard browser envs support document.cookie
1791
+ function standardBrowserEnv() {
1792
+ return {
1793
+ write: function write(name, value, expires, path, domain, secure) {
1794
+ var cookie = [];
1795
+ cookie.push(name + '=' + encodeURIComponent(value));
1796
+ if (utils.isNumber(expires)) {
1797
+ cookie.push('expires=' + new Date(expires).toGMTString());
1798
+ }
1799
+ if (utils.isString(path)) {
1800
+ cookie.push('path=' + path);
1801
+ }
1802
+ if (utils.isString(domain)) {
1803
+ cookie.push('domain=' + domain);
1804
+ }
1805
+ if (secure === true) {
1806
+ cookie.push('secure');
1807
+ }
1808
+ document.cookie = cookie.join('; ');
1809
+ },
1810
+ read: function read(name) {
1811
+ var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
1812
+ return match ? decodeURIComponent(match[3]) : null;
1813
+ },
1814
+ remove: function remove(name) {
1815
+ this.write(name, '', Date.now() - 86400000);
1816
+ }
1817
+ };
1818
+ }() :
1819
+ // Non standard browser env (web workers, react-native) lack needed support.
1820
+ function nonStandardBrowserEnv() {
1821
+ return {
1822
+ write: function write() {},
1823
+ read: function read() {
1824
+ return null;
1825
+ },
1826
+ remove: function remove() {}
1827
+ };
1828
+ }();
1829
+
1830
+ /**
1831
+ * Determines whether the specified URL is absolute
1832
+ *
1833
+ * @param {string} url The URL to test
1834
+ *
1835
+ * @returns {boolean} True if the specified URL is absolute, otherwise false
1836
+ */
1837
+ function isAbsoluteURL(url) {
1838
+ // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
1839
+ // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
1840
+ // by any combination of letters, digits, plus, period, or hyphen.
1841
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
1842
+ }
1843
+
1844
+ /**
1845
+ * Creates a new URL by combining the specified URLs
1846
+ *
1847
+ * @param {string} baseURL The base URL
1848
+ * @param {string} relativeURL The relative URL
1849
+ *
1850
+ * @returns {string} The combined URL
1851
+ */
1852
+ function combineURLs(baseURL, relativeURL) {
1853
+ return relativeURL ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') : baseURL;
1854
+ }
1855
+
1856
+ /**
1857
+ * Creates a new URL by combining the baseURL with the requestedURL,
1858
+ * only when the requestedURL is not already an absolute URL.
1859
+ * If the requestURL is absolute, this function returns the requestedURL untouched.
1860
+ *
1861
+ * @param {string} baseURL The base URL
1862
+ * @param {string} requestedURL Absolute or relative URL to combine
1863
+ *
1864
+ * @returns {string} The combined full path
1865
+ */
1866
+ function buildFullPath(baseURL, requestedURL) {
1867
+ if (baseURL && !isAbsoluteURL(requestedURL)) {
1868
+ return combineURLs(baseURL, requestedURL);
1869
+ }
1870
+ return requestedURL;
1871
+ }
1872
+
1873
+ var isURLSameOrigin = platform.isStandardBrowserEnv ?
1874
+ // Standard browser envs have full support of the APIs needed to test
1875
+ // whether the request URL is of the same origin as current location.
1876
+ function standardBrowserEnv() {
1877
+ var msie = /(msie|trident)/i.test(navigator.userAgent);
1878
+ var urlParsingNode = document.createElement('a');
1879
+ var originURL;
1880
+
1881
+ /**
1882
+ * Parse a URL to discover it's components
1883
+ *
1884
+ * @param {String} url The URL to be parsed
1885
+ * @returns {Object}
1886
+ */
1887
+ function resolveURL(url) {
1888
+ var href = url;
1889
+ if (msie) {
1890
+ // IE needs attribute set twice to normalize properties
1891
+ urlParsingNode.setAttribute('href', href);
1892
+ href = urlParsingNode.href;
1893
+ }
1894
+ urlParsingNode.setAttribute('href', href);
1895
+
1896
+ // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
1897
+ return {
1898
+ href: urlParsingNode.href,
1899
+ protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
1900
+ host: urlParsingNode.host,
1901
+ search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
1902
+ hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
1903
+ hostname: urlParsingNode.hostname,
1904
+ port: urlParsingNode.port,
1905
+ pathname: urlParsingNode.pathname.charAt(0) === '/' ? urlParsingNode.pathname : '/' + urlParsingNode.pathname
1906
+ };
1907
+ }
1908
+ originURL = resolveURL(window.location.href);
1909
+
1910
+ /**
1911
+ * Determine if a URL shares the same origin as the current location
1912
+ *
1913
+ * @param {String} requestURL The URL to test
1914
+ * @returns {boolean} True if URL shares the same origin, otherwise false
1915
+ */
1916
+ return function isURLSameOrigin(requestURL) {
1917
+ var parsed = utils.isString(requestURL) ? resolveURL(requestURL) : requestURL;
1918
+ return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
1919
+ };
1920
+ }() :
1921
+ // Non standard browser envs (web workers, react-native) lack needed support.
1922
+ function nonStandardBrowserEnv() {
1923
+ return function isURLSameOrigin() {
1924
+ return true;
1925
+ };
1926
+ }();
1927
+
1928
+ function parseProtocol(url) {
1929
+ var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1930
+ return match && match[1] || '';
1931
+ }
1932
+
1761
1933
  /**
1762
1934
  * Calculate data maxRate
1763
1935
  * @param {Number} [samplesCount= 10]
@@ -1821,7 +1993,8 @@
1821
1993
  listener(data);
1822
1994
  };
1823
1995
  }
1824
- function xhrAdapter(config) {
1996
+ var isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
1997
+ var xhrAdapter = isXHRAdapterSupported && function (config) {
1825
1998
  return new Promise(function dispatchXhrRequest(resolve, reject) {
1826
1999
  var requestData = config.data;
1827
2000
  var requestHeaders = AxiosHeaders$1.from(config.headers).normalize();
@@ -2000,192 +2173,52 @@
2000
2173
  // Send the request
2001
2174
  request.send(requestData || null);
2002
2175
  });
2003
- }
2004
-
2005
- var adapters = {
2006
- http: xhrAdapter,
2007
- xhr: xhrAdapter
2008
- };
2009
- var adapters$1 = {
2010
- getAdapter: function getAdapter(nameOrAdapter) {
2011
- if (utils.isString(nameOrAdapter)) {
2012
- var adapter = adapters[nameOrAdapter];
2013
- if (!nameOrAdapter) {
2014
- throw Error(utils.hasOwnProp(nameOrAdapter) ? "Adapter '".concat(nameOrAdapter, "' is not available in the build") : "Can not resolve adapter '".concat(nameOrAdapter, "'"));
2015
- }
2016
- return adapter;
2017
- }
2018
- if (!utils.isFunction(nameOrAdapter)) {
2019
- throw new TypeError('adapter is not a function');
2020
- }
2021
- return nameOrAdapter;
2022
- },
2023
- adapters: adapters
2024
2176
  };
2025
2177
 
2026
- var DEFAULT_CONTENT_TYPE = {
2027
- 'Content-Type': undefined
2178
+ var knownAdapters = {
2179
+ http: httpAdapter,
2180
+ xhr: xhrAdapter
2028
2181
  };
2029
-
2030
- /**
2031
- * If the browser has an XMLHttpRequest object, use the XHR adapter, otherwise use the HTTP
2032
- * adapter
2033
- *
2034
- * @returns {Function}
2035
- */
2036
- function getDefaultAdapter() {
2037
- var adapter;
2038
- if (typeof XMLHttpRequest !== 'undefined') {
2039
- // For browsers use XHR adapter
2040
- adapter = adapters$1.getAdapter('xhr');
2041
- } else if (typeof process !== 'undefined' && utils.kindOf(process) === 'process') {
2042
- // For node use HTTP adapter
2043
- adapter = adapters$1.getAdapter('http');
2044
- }
2045
- return adapter;
2046
- }
2047
-
2048
- /**
2049
- * It takes a string, tries to parse it, and if it fails, it returns the stringified version
2050
- * of the input
2051
- *
2052
- * @param {any} rawValue - The value to be stringified.
2053
- * @param {Function} parser - A function that parses a string into a JavaScript object.
2054
- * @param {Function} encoder - A function that takes a value and returns a string.
2055
- *
2056
- * @returns {string} A stringified version of the rawValue.
2057
- */
2058
- function stringifySafely(rawValue, parser, encoder) {
2059
- if (utils.isString(rawValue)) {
2182
+ utils.forEach(knownAdapters, function (fn, value) {
2183
+ if (fn) {
2060
2184
  try {
2061
- (parser || JSON.parse)(rawValue);
2062
- return utils.trim(rawValue);
2185
+ Object.defineProperty(fn, 'name', {
2186
+ value: value
2187
+ });
2063
2188
  } catch (e) {
2064
- if (e.name !== 'SyntaxError') {
2065
- throw e;
2066
- }
2189
+ // eslint-disable-next-line no-empty
2067
2190
  }
2191
+ Object.defineProperty(fn, 'adapterName', {
2192
+ value: value
2193
+ });
2068
2194
  }
2069
- return (encoder || JSON.stringify)(rawValue);
2070
- }
2071
- var defaults = {
2072
- transitional: transitionalDefaults,
2073
- adapter: getDefaultAdapter(),
2074
- transformRequest: [function transformRequest(data, headers) {
2075
- var contentType = headers.getContentType() || '';
2076
- var hasJSONContentType = contentType.indexOf('application/json') > -1;
2077
- var isObjectPayload = utils.isObject(data);
2078
- if (isObjectPayload && utils.isHTMLForm(data)) {
2079
- data = new FormData(data);
2080
- }
2081
- var isFormData = utils.isFormData(data);
2082
- if (isFormData) {
2083
- if (!hasJSONContentType) {
2084
- return data;
2195
+ });
2196
+ var adapters = {
2197
+ getAdapter: function getAdapter(adapters) {
2198
+ adapters = utils.isArray(adapters) ? adapters : [adapters];
2199
+ var _adapters = adapters,
2200
+ length = _adapters.length;
2201
+ var nameOrAdapter;
2202
+ var adapter;
2203
+ for (var i = 0; i < length; i++) {
2204
+ nameOrAdapter = adapters[i];
2205
+ if (adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter) {
2206
+ break;
2085
2207
  }
2086
- return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
2087
- }
2088
- if (utils.isArrayBuffer(data) || utils.isBuffer(data) || utils.isStream(data) || utils.isFile(data) || utils.isBlob(data)) {
2089
- return data;
2090
- }
2091
- if (utils.isArrayBufferView(data)) {
2092
- return data.buffer;
2093
- }
2094
- if (utils.isURLSearchParams(data)) {
2095
- headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
2096
- return data.toString();
2097
2208
  }
2098
- var isFileList;
2099
- if (isObjectPayload) {
2100
- if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
2101
- return toURLEncodedForm(data, this.formSerializer).toString();
2209
+ if (!adapter) {
2210
+ if (adapter === false) {
2211
+ throw new AxiosError("Adapter ".concat(nameOrAdapter, " is not supported by the environment"), 'ERR_NOT_SUPPORT');
2102
2212
  }
2103
- if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
2104
- var _FormData = this.env && this.env.FormData;
2105
- return toFormData(isFileList ? {
2106
- 'files[]': data
2107
- } : data, _FormData && new _FormData(), this.formSerializer);
2108
- }
2109
- }
2110
- if (isObjectPayload || hasJSONContentType) {
2111
- headers.setContentType('application/json', false);
2112
- return stringifySafely(data);
2213
+ throw new Error(utils.hasOwnProp(knownAdapters, nameOrAdapter) ? "Adapter '".concat(nameOrAdapter, "' is not available in the build") : "Unknown adapter '".concat(nameOrAdapter, "'"));
2113
2214
  }
2114
- return data;
2115
- }],
2116
- transformResponse: [function transformResponse(data) {
2117
- var transitional = this.transitional || defaults.transitional;
2118
- var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
2119
- var JSONRequested = this.responseType === 'json';
2120
- if (data && utils.isString(data) && (forcedJSONParsing && !this.responseType || JSONRequested)) {
2121
- var silentJSONParsing = transitional && transitional.silentJSONParsing;
2122
- var strictJSONParsing = !silentJSONParsing && JSONRequested;
2123
- try {
2124
- return JSON.parse(data);
2125
- } catch (e) {
2126
- if (strictJSONParsing) {
2127
- if (e.name === 'SyntaxError') {
2128
- throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
2129
- }
2130
- throw e;
2131
- }
2132
- }
2215
+ if (!utils.isFunction(adapter)) {
2216
+ throw new TypeError('adapter is not a function');
2133
2217
  }
2134
- return data;
2135
- }],
2136
- /**
2137
- * A timeout in milliseconds to abort a request. If set to 0 (default) a
2138
- * timeout is not created.
2139
- */
2140
- timeout: 0,
2141
- xsrfCookieName: 'XSRF-TOKEN',
2142
- xsrfHeaderName: 'X-XSRF-TOKEN',
2143
- maxContentLength: -1,
2144
- maxBodyLength: -1,
2145
- env: {
2146
- FormData: platform.classes.FormData,
2147
- Blob: platform.classes.Blob
2148
- },
2149
- validateStatus: function validateStatus(status) {
2150
- return status >= 200 && status < 300;
2218
+ return adapter;
2151
2219
  },
2152
- headers: {
2153
- common: {
2154
- 'Accept': 'application/json, text/plain, */*'
2155
- }
2156
- }
2220
+ adapters: knownAdapters
2157
2221
  };
2158
- utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
2159
- defaults.headers[method] = {};
2160
- });
2161
- utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
2162
- defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
2163
- });
2164
- var defaults$1 = defaults;
2165
-
2166
- /**
2167
- * Transform the data for a request or a response
2168
- *
2169
- * @param {Array|Function} fns A single function or Array of functions
2170
- * @param {?Object} response The response object
2171
- *
2172
- * @returns {*} The resulting transformed data
2173
- */
2174
- function transformData(fns, response) {
2175
- var config = this || defaults$1;
2176
- var context = response || config;
2177
- var headers = AxiosHeaders$1.from(context.headers);
2178
- var data = context.data;
2179
- utils.forEach(fns, function transform(fn) {
2180
- data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
2181
- });
2182
- headers.normalize();
2183
- return data;
2184
- }
2185
-
2186
- function isCancel(value) {
2187
- return !!(value && value.__CANCEL__);
2188
- }
2189
2222
 
2190
2223
  /**
2191
2224
  * Throws a `CanceledError` if cancellation has been requested.
@@ -2219,7 +2252,7 @@
2219
2252
  if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
2220
2253
  config.headers.setContentType('application/x-www-form-urlencoded', false);
2221
2254
  }
2222
- var adapter = config.adapter || defaults$1.adapter;
2255
+ var adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
2223
2256
  return adapter(config).then(function onAdapterResolution(response) {
2224
2257
  throwIfCancellationRequested(config);
2225
2258
 
@@ -2344,7 +2377,7 @@
2344
2377
  return config;
2345
2378
  }
2346
2379
 
2347
- var VERSION = "1.2.0-alpha.1";
2380
+ var VERSION = "1.2.0";
2348
2381
 
2349
2382
  var validators$1 = {};
2350
2383