axios 1.3.6 → 1.5.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.3.6 Copyright (c) 2023 Matt Zabriskie and contributors
1
+ // Axios v1.5.0 Copyright (c) 2023 Matt Zabriskie and contributors
2
2
  'use strict';
3
3
 
4
4
  const FormData$1 = require('form-data');
@@ -568,8 +568,9 @@ const reduceDescriptors = (obj, reducer) => {
568
568
  const reducedDescriptors = {};
569
569
 
570
570
  forEach(descriptors, (descriptor, name) => {
571
- if (reducer(descriptor, name, obj) !== false) {
572
- reducedDescriptors[name] = descriptor;
571
+ let ret;
572
+ if ((ret = reducer(descriptor, name, obj)) !== false) {
573
+ reducedDescriptors[name] = ret || descriptor;
573
574
  }
574
575
  });
575
576
 
@@ -690,6 +691,11 @@ const toJSONObject = (obj) => {
690
691
  return visit(obj, 0);
691
692
  };
692
693
 
694
+ const isAsyncFn = kindOfTest('AsyncFunction');
695
+
696
+ const isThenable = (thing) =>
697
+ thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
698
+
693
699
  const utils = {
694
700
  isArray,
695
701
  isArrayBuffer,
@@ -739,7 +745,9 @@ const utils = {
739
745
  ALPHABET,
740
746
  generateString,
741
747
  isSpecCompliantForm,
742
- toJSONObject
748
+ toJSONObject,
749
+ isAsyncFn,
750
+ isThenable
743
751
  };
744
752
 
745
753
  /**
@@ -1346,10 +1354,6 @@ function formDataToJSON(formData) {
1346
1354
  return null;
1347
1355
  }
1348
1356
 
1349
- const DEFAULT_CONTENT_TYPE = {
1350
- 'Content-Type': undefined
1351
- };
1352
-
1353
1357
  /**
1354
1358
  * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1355
1359
  * of the input
@@ -1379,7 +1383,7 @@ const defaults = {
1379
1383
 
1380
1384
  transitional: transitionalDefaults,
1381
1385
 
1382
- adapter: ['xhr', 'http'],
1386
+ adapter: 'http' ,
1383
1387
 
1384
1388
  transformRequest: [function transformRequest(data, headers) {
1385
1389
  const contentType = headers.getContentType() || '';
@@ -1488,19 +1492,16 @@ const defaults = {
1488
1492
 
1489
1493
  headers: {
1490
1494
  common: {
1491
- 'Accept': 'application/json, text/plain, */*'
1495
+ 'Accept': 'application/json, text/plain, */*',
1496
+ 'Content-Type': undefined
1492
1497
  }
1493
1498
  }
1494
1499
  };
1495
1500
 
1496
- utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
1501
+ utils.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
1497
1502
  defaults.headers[method] = {};
1498
1503
  });
1499
1504
 
1500
- utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
1501
- defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
1502
- });
1503
-
1504
1505
  const defaults$1 = defaults;
1505
1506
 
1506
1507
  // RawAxiosHeaders whose duplicates are ignored by node
@@ -1834,7 +1835,17 @@ class AxiosHeaders {
1834
1835
 
1835
1836
  AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
1836
1837
 
1837
- utils.freezeMethods(AxiosHeaders.prototype);
1838
+ // reserved names hotfix
1839
+ utils.reduceDescriptors(AxiosHeaders.prototype, ({value}, key) => {
1840
+ let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
1841
+ return {
1842
+ get: () => value,
1843
+ set(headerValue) {
1844
+ this[mapped] = headerValue;
1845
+ }
1846
+ }
1847
+ });
1848
+
1838
1849
  utils.freezeMethods(AxiosHeaders);
1839
1850
 
1840
1851
  const AxiosHeaders$1 = AxiosHeaders;
@@ -1954,7 +1965,7 @@ function buildFullPath(baseURL, requestedURL) {
1954
1965
  return requestedURL;
1955
1966
  }
1956
1967
 
1957
- const VERSION = "1.3.6";
1968
+ const VERSION = "1.5.0";
1958
1969
 
1959
1970
  function parseProtocol(url) {
1960
1971
  const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
@@ -2424,6 +2435,21 @@ class ZlibHeaderTransformStream extends stream__default["default"].Transform {
2424
2435
 
2425
2436
  const ZlibHeaderTransformStream$1 = ZlibHeaderTransformStream;
2426
2437
 
2438
+ const callbackify = (fn, reducer) => {
2439
+ return utils.isAsyncFn(fn) ? function (...args) {
2440
+ const cb = args.pop();
2441
+ fn.apply(this, args).then((value) => {
2442
+ try {
2443
+ reducer ? cb(null, ...reducer(value)) : cb(null, value);
2444
+ } catch (err) {
2445
+ cb(err);
2446
+ }
2447
+ }, cb);
2448
+ } : fn;
2449
+ };
2450
+
2451
+ const callbackify$1 = callbackify;
2452
+
2427
2453
  const zlibOptions = {
2428
2454
  flush: zlib__default["default"].constants.Z_SYNC_FLUSH,
2429
2455
  finishFlush: zlib__default["default"].constants.Z_SYNC_FLUSH
@@ -2546,13 +2572,24 @@ const wrapAsync = (asyncExecutor) => {
2546
2572
  /*eslint consistent-return:0*/
2547
2573
  const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2548
2574
  return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
2549
- let {data} = config;
2575
+ let {data, lookup, family} = config;
2550
2576
  const {responseType, responseEncoding} = config;
2551
2577
  const method = config.method.toUpperCase();
2552
2578
  let isDone;
2553
2579
  let rejected = false;
2554
2580
  let req;
2555
2581
 
2582
+ if (lookup && utils.isAsyncFn(lookup)) {
2583
+ lookup = callbackify$1(lookup, (entry) => {
2584
+ if(utils.isString(entry)) {
2585
+ entry = [entry, entry.indexOf('.') < 0 ? 6 : 4];
2586
+ } else if (!utils.isArray(entry)) {
2587
+ throw new TypeError('lookup async function must return an array [ip: string, family: number]]')
2588
+ }
2589
+ return entry;
2590
+ });
2591
+ }
2592
+
2556
2593
  // temporary internal emitter until the AxiosRequest class will be implemented
2557
2594
  const emitter = new EventEmitter__default["default"]();
2558
2595
 
@@ -2776,10 +2813,14 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2776
2813
  agents: { http: config.httpAgent, https: config.httpsAgent },
2777
2814
  auth,
2778
2815
  protocol,
2816
+ family,
2779
2817
  beforeRedirect: dispatchBeforeRedirect,
2780
2818
  beforeRedirects: {}
2781
2819
  };
2782
2820
 
2821
+ // cacheable-lookup integration hotfix
2822
+ !utils.isUndefined(lookup) && (options.lookup = lookup);
2823
+
2783
2824
  if (config.socketPath) {
2784
2825
  options.socketPath = config.socketPath;
2785
2826
  } else {
@@ -3205,8 +3246,12 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
3205
3246
  }
3206
3247
  }
3207
3248
 
3208
- if (utils.isFormData(requestData) && (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv)) {
3209
- requestHeaders.setContentType(false); // Let the browser set it
3249
+ if (utils.isFormData(requestData)) {
3250
+ if (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv) {
3251
+ requestHeaders.setContentType(false); // Let the browser set it
3252
+ } else {
3253
+ requestHeaders.setContentType('multipart/form-data;', false); // mobile/desktop app frameworks
3254
+ }
3210
3255
  }
3211
3256
 
3212
3257
  let request = new XMLHttpRequest();
@@ -3612,7 +3657,7 @@ function mergeConfig(config1, config2) {
3612
3657
  headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
3613
3658
  };
3614
3659
 
3615
- utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
3660
+ utils.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
3616
3661
  const merge = mergeMap[prop] || mergeDeepProperties;
3617
3662
  const configValue = merge(config1[prop], config2[prop], prop);
3618
3663
  (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
@@ -3772,15 +3817,13 @@ class Axios {
3772
3817
  // Set config.method
3773
3818
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
3774
3819
 
3775
- let contextHeaders;
3776
-
3777
3820
  // Flatten headers
3778
- contextHeaders = headers && utils.merge(
3821
+ let contextHeaders = headers && utils.merge(
3779
3822
  headers.common,
3780
3823
  headers[config.method]
3781
3824
  );
3782
3825
 
3783
- contextHeaders && utils.forEach(
3826
+ headers && utils.forEach(
3784
3827
  ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
3785
3828
  (method) => {
3786
3829
  delete headers[method];
@@ -4190,6 +4233,8 @@ axios.AxiosHeaders = AxiosHeaders$1;
4190
4233
 
4191
4234
  axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
4192
4235
 
4236
+ axios.getAdapter = adapters.getAdapter;
4237
+
4193
4238
  axios.HttpStatusCode = HttpStatusCode$1;
4194
4239
 
4195
4240
  axios.default = axios;