axios 0.32.0 → 0.34.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.
package/dist/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- // axios v0.32.0 Copyright (c) 2026 Matt Zabriskie
1
+ // axios v0.34.0 Copyright (c) 2026 Matt Zabriskie
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) :
@@ -402,6 +402,15 @@
402
402
  return content;
403
403
  }
404
404
 
405
+ function defineOwnProperty(target, key, value) {
406
+ var descriptor = Object.create(null);
407
+ descriptor.value = value;
408
+ descriptor.writable = true;
409
+ descriptor.enumerable = true;
410
+ descriptor.configurable = true;
411
+ Object.defineProperty(target, key, descriptor);
412
+ }
413
+
405
414
  /**
406
415
  * Inherit the prototype methods from one constructor into another
407
416
  * @param {function} constructor
@@ -409,14 +418,35 @@
409
418
  * @param {object} [props]
410
419
  * @param {object} [descriptors]
411
420
  */
412
-
413
421
  function inherits(constructor, superConstructor, props, descriptors) {
414
422
  constructor.prototype = Object.create(
415
423
  superConstructor.prototype,
416
424
  descriptors
417
425
  );
418
- constructor.prototype.constructor = constructor;
419
- props && Object.assign(constructor.prototype, props);
426
+ if (Object.prototype.hasOwnProperty.call(constructor.prototype, 'constructor')) {
427
+ constructor.prototype.constructor = constructor;
428
+ } else {
429
+ defineOwnProperty(constructor.prototype, 'constructor', constructor);
430
+ }
431
+
432
+ if (props) {
433
+ var keys = Object.keys(props);
434
+ if (Object.getOwnPropertySymbols) {
435
+ keys = keys.concat(Object.getOwnPropertySymbols(props).filter(function(key) {
436
+ return Object.prototype.propertyIsEnumerable.call(props, key);
437
+ }));
438
+ }
439
+ keys.forEach(function(key) {
440
+ var value = props[key];
441
+ if (Object.prototype.hasOwnProperty.call(constructor.prototype, key)) {
442
+ constructor.prototype[key] = value;
443
+ } else {
444
+ // Assignment would invoke an inherited setter or fail on a read-only
445
+ // property installed by another library, such as Error.prototype.toJSON.
446
+ defineOwnProperty(constructor.prototype, key, value);
447
+ }
448
+ });
449
+ }
420
450
  }
421
451
 
422
452
  /**
@@ -779,6 +809,40 @@
779
809
  return thing && utils.isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator];
780
810
  }
781
811
 
812
+ var UNSAFE_OPTION_KEYS = ['__proto__', 'constructor', 'prototype'];
813
+
814
+ // Materialises the serializer options onto a null-prototype object. Reading the
815
+ // options from a plain object let a polluted Object.prototype supply a visitor,
816
+ // a depth limit, a Blob implementation or key-format flags that the caller never
817
+ // asked for, and also let a polluted key mask an option the caller did set.
818
+ // Only own, defined properties of the caller's options are carried over.
819
+ function toFormDataOptions(source) {
820
+ var options = Object.create(null);
821
+
822
+ options.metaTokens = true;
823
+ options.dots = false;
824
+ options.indexes = false;
825
+
826
+ // eslint-disable-next-line no-eq-null,eqeqeq
827
+ if (source == null) {
828
+ return options;
829
+ }
830
+
831
+ var names = Object.getOwnPropertyNames(source);
832
+
833
+ for (var i = 0; i < names.length; i++) {
834
+ var name = names[i];
835
+
836
+ if (UNSAFE_OPTION_KEYS.indexOf(name) !== -1 || utils.isUndefined(source[name])) {
837
+ continue;
838
+ }
839
+
840
+ options[name] = source[name];
841
+ }
842
+
843
+ return options;
844
+ }
845
+
782
846
  /**
783
847
  * Convert a data object to FormData
784
848
  * @param {Object} obj
@@ -800,14 +864,7 @@
800
864
  formData = formData || new (FormData$1 || FormData)();
801
865
 
802
866
  // eslint-disable-next-line no-param-reassign
803
- options = utils.toFlatObject(options, {
804
- metaTokens: true,
805
- dots: false,
806
- indexes: false
807
- }, false, function defined(option, source) {
808
- // eslint-disable-next-line no-eq-null,eqeqeq
809
- return !utils.isUndefined(source[option]);
810
- });
867
+ options = toFormDataOptions(options);
811
868
 
812
869
  var metaTokens = options.metaTokens;
813
870
  // eslint-disable-next-line no-use-before-define
@@ -840,6 +897,29 @@
840
897
  return value;
841
898
  }
842
899
 
900
+ var stack = [];
901
+
902
+ function assertValueDepth(value, depth) {
903
+ if (depth > maxDepth) {
904
+ throw new AxiosError_1(
905
+ 'Maximum object depth of ' + maxDepth + ' exceeded (got ' + depth + ' levels)',
906
+ AxiosError_1.ERR_FORM_DATA_DEPTH_EXCEEDED
907
+ );
908
+ }
909
+
910
+ if (!utils.isObject(value) || stack.indexOf(value) !== -1) {
911
+ return;
912
+ }
913
+
914
+ stack.push(value);
915
+
916
+ utils.forEach(value, function each(el) {
917
+ assertValueDepth(el, depth + 1);
918
+ });
919
+
920
+ stack.pop();
921
+ }
922
+
843
923
  /**
844
924
  *
845
925
  * @param {*} value
@@ -855,6 +935,7 @@
855
935
  if (utils.endsWith(key, '{}')) {
856
936
  // eslint-disable-next-line no-param-reassign
857
937
  key = metaTokens ? key : key.slice(0, -2);
938
+ assertValueDepth(value, 1);
858
939
  // eslint-disable-next-line no-param-reassign
859
940
  value = JSON.stringify(value);
860
941
  } else if (
@@ -884,8 +965,6 @@
884
965
  return false;
885
966
  }
886
967
 
887
- var stack = [];
888
-
889
968
  var exposedHelpers = Object.assign(predicates, {
890
969
  defaultVisitor: defaultVisitor,
891
970
  convertValue: convertValue,
@@ -1012,9 +1091,17 @@
1012
1091
  url = url.slice(0, hashmarkIndex);
1013
1092
  }
1014
1093
 
1015
- var _encode = options && options.encode || encode;
1094
+ var _encode = encode;
1095
+ var serializeFn;
1016
1096
 
1017
- var serializeFn = options && options.serialize;
1097
+ if (options) {
1098
+ if (utils.isFunction(options)) {
1099
+ serializeFn = options;
1100
+ } else {
1101
+ _encode = utils.hasOwnProperty(options, 'encode') && options.encode || encode;
1102
+ serializeFn = utils.hasOwnProperty(options, 'serialize') ? options.serialize : undefined;
1103
+ }
1104
+ }
1018
1105
 
1019
1106
  var serializedParams;
1020
1107
 
@@ -1137,6 +1224,19 @@
1137
1224
  }, options));
1138
1225
  };
1139
1226
 
1227
+ var MAX_FORM_DATA_TO_JSON_DEPTH = 100;
1228
+
1229
+ function assertPathDepth(path) {
1230
+ var depth = path.length - 1;
1231
+
1232
+ if (depth > MAX_FORM_DATA_TO_JSON_DEPTH) {
1233
+ throw new AxiosError_1(
1234
+ 'Maximum object depth of ' + MAX_FORM_DATA_TO_JSON_DEPTH + ' exceeded (got ' + depth + ' levels)',
1235
+ AxiosError_1.ERR_FORM_DATA_DEPTH_EXCEEDED
1236
+ );
1237
+ }
1238
+ }
1239
+
1140
1240
  function parsePropPath(name) {
1141
1241
  // foo[x][y][z]
1142
1242
  // foo.x.y.z
@@ -1197,7 +1297,10 @@
1197
1297
  var obj = {};
1198
1298
 
1199
1299
  utils.forEachEntry(formData, function(name, value) {
1200
- buildPath(parsePropPath(name), value, obj, 0);
1300
+ var path = parsePropPath(name);
1301
+
1302
+ assertPathDepth(path);
1303
+ buildPath(path, value, obj, 0);
1201
1304
  });
1202
1305
 
1203
1306
  return obj;
@@ -1473,6 +1576,23 @@
1473
1576
 
1474
1577
  var CanceledError_1 = CanceledError;
1475
1578
 
1579
+ var fromSignal = function fromSignal(signal, config, request) {
1580
+ var error = new CanceledError_1(null, config, request);
1581
+
1582
+ if (signal) {
1583
+ try {
1584
+ var reason = signal.reason;
1585
+ if (reason !== undefined) {
1586
+ error.reason = reason;
1587
+ }
1588
+ } catch (e) {
1589
+ // A custom signal getter must not prevent cancellation.
1590
+ }
1591
+ }
1592
+
1593
+ return error;
1594
+ };
1595
+
1476
1596
  var parseProtocol = function parseProtocol(url) {
1477
1597
  var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1478
1598
  return match && match[1] || '';
@@ -1505,10 +1625,11 @@
1505
1625
  var request = new XMLHttpRequest();
1506
1626
 
1507
1627
  // HTTP basic authentication
1508
- if (config.auth) {
1509
- var username = config.auth.username || '';
1510
- var password = config.auth.password
1511
- ? unescape(encodeURIComponent(config.auth.password))
1628
+ var configAuth = utils.hasOwnProperty(config, 'auth') ? config.auth : undefined;
1629
+ if (configAuth) {
1630
+ var username = utils.hasOwnProperty(configAuth, 'username') ? configAuth.username || '' : '';
1631
+ var password = utils.hasOwnProperty(configAuth, 'password') && configAuth.password
1632
+ ? unescape(encodeURIComponent(configAuth.password))
1512
1633
  : '';
1513
1634
  requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
1514
1635
  }
@@ -1521,7 +1642,11 @@
1521
1642
 
1522
1643
  request.open(
1523
1644
  config.method.toUpperCase(),
1524
- buildURL(fullPath, config.params, config.paramsSerializer),
1645
+ buildURL(
1646
+ fullPath,
1647
+ config.params,
1648
+ utils.hasOwnProperty(config, 'paramsSerializer') ? config.paramsSerializer : undefined
1649
+ ),
1525
1650
  true
1526
1651
  );
1527
1652
 
@@ -1721,7 +1846,7 @@
1721
1846
  }
1722
1847
  reject(
1723
1848
  !cancel || cancel.type
1724
- ? new CanceledError_1(null, config, request)
1849
+ ? fromSignal(config.signal, config, request)
1725
1850
  : cancel
1726
1851
  );
1727
1852
  request.abort();
@@ -1985,7 +2110,7 @@
1985
2110
  }
1986
2111
 
1987
2112
  if (config.signal && config.signal.aborted) {
1988
- throw new CanceledError_1();
2113
+ throw fromSignal(config.signal, config);
1989
2114
  }
1990
2115
  }
1991
2116
 
@@ -1998,8 +2123,9 @@
1998
2123
  var dispatchRequest = function dispatchRequest(config) {
1999
2124
  throwIfCancellationRequested(config);
2000
2125
 
2001
- // Ensure headers exist
2002
- config.headers = config.headers || {};
2126
+ // Ensure headers exist. A request interceptor may return a replacement config
2127
+ // that inherits from Object.prototype, so only an own headers value is used.
2128
+ config.headers = (utils.hasOwnProperty(config, 'headers') && config.headers) || {};
2003
2129
 
2004
2130
  // Transform request data
2005
2131
  config.data = transformData.call(
@@ -2132,6 +2258,11 @@
2132
2258
  }
2133
2259
  }
2134
2260
 
2261
+ function defaultToConfig2Reference(prop) {
2262
+ var value = getOwn(config2, prop);
2263
+ return utils.isUndefined(value) ? getOwn(config1, prop) : value;
2264
+ }
2265
+
2135
2266
  // eslint-disable-next-line consistent-return
2136
2267
  function mergeDirectKeys(prop) {
2137
2268
  if (hasOwn(config2, prop)) {
@@ -2167,6 +2298,8 @@
2167
2298
  'httpAgent': defaultToConfig2,
2168
2299
  'httpsAgent': defaultToConfig2,
2169
2300
  'cancelToken': defaultToConfig2,
2301
+ // Signals are live objects; cloning them snapshots getters and reasons.
2302
+ 'signal': defaultToConfig2Reference,
2170
2303
  'socketPath': defaultToConfig2,
2171
2304
  'allowedSocketPaths': defaultToConfig2,
2172
2305
  'responseEncoding': defaultToConfig2,
@@ -2186,7 +2319,7 @@
2186
2319
  };
2187
2320
 
2188
2321
  var data = {
2189
- "version": "0.32.0"
2322
+ "version": "0.34.0"
2190
2323
  };
2191
2324
 
2192
2325
  var VERSION = data.version;
@@ -2275,6 +2408,56 @@
2275
2408
  };
2276
2409
 
2277
2410
  var validators = validator.validators;
2411
+
2412
+ function captureCallerStack(boundary) {
2413
+ var caller = {};
2414
+ try {
2415
+ if (Error.captureStackTrace) {
2416
+ Error.captureStackTrace(caller, boundary);
2417
+ } else {
2418
+ caller = new Error();
2419
+ }
2420
+ } catch (e) {
2421
+ // Stack hooks must not prevent a request from being sent.
2422
+ }
2423
+ return caller;
2424
+ }
2425
+
2426
+ function attachCallerStack(promise, caller) {
2427
+ if (!caller) {
2428
+ return promise;
2429
+ }
2430
+
2431
+ return promise.then(null, function onRequestRejected(error) {
2432
+ try {
2433
+ if (error instanceof Error || Object.prototype.toString.call(error) === '[object Error]') {
2434
+ // Capture at dispatch time, but only format the stack on failure.
2435
+ // Capturing in this callback would lose callers using .then/.catch.
2436
+ var stack = caller.stack;
2437
+ if (typeof stack === 'string') {
2438
+ var newline = stack.indexOf('\n');
2439
+ stack = newline === -1 ? '' : stack.slice(newline + 1);
2440
+ var original = error.stack;
2441
+ if (stack && (original === undefined || original === null || original === '')) {
2442
+ error.stack = stack;
2443
+ } else if (stack && typeof original === 'string' && original.indexOf(stack) === -1) {
2444
+ error.stack = original + '\n' + stack;
2445
+ }
2446
+ }
2447
+ }
2448
+ } catch (e) {
2449
+ // Frozen errors and custom stack accessors must retain their rejection.
2450
+ }
2451
+ return Promise.reject(error);
2452
+ });
2453
+ }
2454
+
2455
+ function dispatchAfterRecovery(config) {
2456
+ return function dispatchRecoveredRequest() {
2457
+ return dispatchRequest(config);
2458
+ };
2459
+ }
2460
+
2278
2461
  /**
2279
2462
  * Create a new instance of Axios
2280
2463
  *
@@ -2305,11 +2488,14 @@
2305
2488
  }
2306
2489
 
2307
2490
  config = mergeConfig(this.defaults, config);
2491
+ var caller = config.captureCallerStack === true ? captureCallerStack(request) : null;
2308
2492
 
2309
- // Set config.method
2493
+ // Set config.method. The merged config is null-prototype, but instance
2494
+ // defaults may be an ordinary object, so the fallback is read as an own
2495
+ // property to keep an inherited value from choosing the request method.
2310
2496
  if (config.method) {
2311
2497
  config.method = config.method.toLowerCase();
2312
- } else if (this.defaults.method) {
2498
+ } else if (utils.hasOwnProperty(this.defaults, 'method') && this.defaults.method) {
2313
2499
  config.method = this.defaults.method.toLowerCase();
2314
2500
  } else {
2315
2501
  config.method = 'get';
@@ -2371,7 +2557,7 @@
2371
2557
  promise = promise.then(chain.shift(), chain.shift());
2372
2558
  }
2373
2559
 
2374
- return promise;
2560
+ return attachCallerStack(promise, caller);
2375
2561
  }
2376
2562
 
2377
2563
 
@@ -2380,24 +2566,39 @@
2380
2566
  var onFulfilled = requestInterceptorChain.shift();
2381
2567
  var onRejected = requestInterceptorChain.shift();
2382
2568
  try {
2383
- newConfig = onFulfilled(newConfig);
2569
+ newConfig = onFulfilled ? onFulfilled(newConfig) : newConfig;
2384
2570
  } catch (error) {
2385
- onRejected(error);
2571
+ if (!onRejected) {
2572
+ promise = Promise.reject(error);
2573
+ break;
2574
+ }
2575
+ try {
2576
+ var recovery = onRejected(error);
2577
+ if (recovery && typeof recovery.then === 'function') {
2578
+ promise = Promise.resolve(recovery).then(dispatchAfterRecovery(newConfig));
2579
+ }
2580
+ } catch (rejectedError) {
2581
+ promise = Promise.reject(rejectedError);
2582
+ }
2386
2583
  break;
2387
2584
  }
2388
2585
  }
2389
2586
 
2390
- try {
2391
- promise = dispatchRequest(newConfig);
2392
- } catch (error) {
2393
- return Promise.reject(error);
2587
+ if (!promise) {
2588
+ try {
2589
+ promise = dispatchRequest(newConfig);
2590
+ } catch (error) {
2591
+ // Dispatch errors, including pre-aborted signals, still go through the
2592
+ // response interceptors registered below.
2593
+ promise = Promise.reject(error);
2594
+ }
2394
2595
  }
2395
2596
 
2396
2597
  while (responseInterceptorChain.length) {
2397
2598
  promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
2398
2599
  }
2399
2600
 
2400
- return promise;
2601
+ return attachCallerStack(promise, caller);
2401
2602
  };
2402
2603
 
2403
2604
  Axios.prototype.getUri = function getUri(config) {
@@ -2410,10 +2611,12 @@
2410
2611
  utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
2411
2612
  /*eslint func-names:0*/
2412
2613
  Axios.prototype[method] = function(url, config) {
2413
- return this.request(mergeConfig(config || {}, {
2614
+ var requestConfig = config || {};
2615
+
2616
+ return this.request(mergeConfig(requestConfig, {
2414
2617
  method: method,
2415
2618
  url: url,
2416
- data: (config || {}).data
2619
+ data: utils.hasOwnProperty(requestConfig, 'data') ? requestConfig.data : undefined
2417
2620
  }));
2418
2621
  };
2419
2622
  });