axios 1.7.2 → 1.7.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.7.3](https://github.com/axios/axios/compare/v1.7.2...v1.7.3) (2024-08-01)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **adapter:** fix progress event emitting; ([#6518](https://github.com/axios/axios/issues/6518)) ([e3c76fc](https://github.com/axios/axios/commit/e3c76fc9bdd03aa4d98afaf211df943e2031453f))
9
+ * **fetch:** fix withCredentials request config ([#6505](https://github.com/axios/axios/issues/6505)) ([85d4d0e](https://github.com/axios/axios/commit/85d4d0ea0aae91082f04e303dec46510d1b4e787))
10
+ * **xhr:** return original config on errors from XHR adapter ([#6515](https://github.com/axios/axios/issues/6515)) ([8966ee7](https://github.com/axios/axios/commit/8966ee7ea62ecbd6cfb39a905939bcdab5cf6388))
11
+
12
+ ### Contributors to this release
13
+
14
+ - <img src="https://avatars.githubusercontent.com/u/12586868?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS "+211/-159 (#6518 #6519 )")
15
+ - <img src="https://avatars.githubusercontent.com/u/10867286?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [Valerii Sidorenko](https://github.com/ValeraS "+3/-3 (#6515 )")
16
+ - <img src="https://avatars.githubusercontent.com/u/8599535?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [prianYu](https://github.com/prianyu "+2/-2 (#6505 )")
17
+
3
18
  ## [1.7.2](https://github.com/axios/axios/compare/v1.7.1...v1.7.2) (2024-05-21)
4
19
 
5
20
 
package/dist/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- // Axios v1.7.2 Copyright (c) 2024 Matt Zabriskie and contributors
1
+ // Axios v1.7.3 Copyright (c) 2024 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) :
@@ -1320,6 +1320,34 @@
1320
1320
  var isThenable = function isThenable(thing) {
1321
1321
  return thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing["catch"]);
1322
1322
  };
1323
+
1324
+ // original code
1325
+ // https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
1326
+
1327
+ var _setImmediate = function (setImmediateSupported, postMessageSupported) {
1328
+ if (setImmediateSupported) {
1329
+ return setImmediate;
1330
+ }
1331
+ return postMessageSupported ? function (token, callbacks) {
1332
+ _global.addEventListener("message", function (_ref5) {
1333
+ var source = _ref5.source,
1334
+ data = _ref5.data;
1335
+ if (source === _global && data === token) {
1336
+ callbacks.length && callbacks.shift()();
1337
+ }
1338
+ }, false);
1339
+ return function (cb) {
1340
+ callbacks.push(cb);
1341
+ _global.postMessage(token, "*");
1342
+ };
1343
+ }("axios@".concat(Math.random()), []) : function (cb) {
1344
+ return setTimeout(cb);
1345
+ };
1346
+ }(typeof setImmediate === 'function', isFunction(_global.postMessage));
1347
+ var asap = typeof queueMicrotask !== 'undefined' ? queueMicrotask.bind(_global) : typeof process !== 'undefined' && process.nextTick || _setImmediate;
1348
+
1349
+ // *********************
1350
+
1323
1351
  var utils$1 = {
1324
1352
  isArray: isArray,
1325
1353
  isArrayBuffer: isArrayBuffer,
@@ -1376,7 +1404,9 @@
1376
1404
  isSpecCompliantForm: isSpecCompliantForm,
1377
1405
  toJSONObject: toJSONObject,
1378
1406
  isAsyncFn: isAsyncFn,
1379
- isThenable: isThenable
1407
+ isThenable: isThenable,
1408
+ setImmediate: _setImmediate,
1409
+ asap: asap
1380
1410
  };
1381
1411
 
1382
1412
  /**
@@ -2528,30 +2558,43 @@
2528
2558
  function throttle(fn, freq) {
2529
2559
  var timestamp = 0;
2530
2560
  var threshold = 1000 / freq;
2531
- var timer = null;
2532
- return function throttled() {
2533
- var _arguments = arguments;
2534
- var force = this === true;
2561
+ var lastArgs;
2562
+ var timer;
2563
+ var invoke = function invoke(args) {
2564
+ var now = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
2565
+ timestamp = now;
2566
+ lastArgs = null;
2567
+ if (timer) {
2568
+ clearTimeout(timer);
2569
+ timer = null;
2570
+ }
2571
+ fn.apply(null, args);
2572
+ };
2573
+ var throttled = function throttled() {
2535
2574
  var now = Date.now();
2536
- if (force || now - timestamp > threshold) {
2537
- if (timer) {
2538
- clearTimeout(timer);
2539
- timer = null;
2540
- }
2541
- timestamp = now;
2542
- return fn.apply(null, arguments);
2575
+ var passed = now - timestamp;
2576
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2577
+ args[_key] = arguments[_key];
2543
2578
  }
2544
- if (!timer) {
2545
- timer = setTimeout(function () {
2546
- timer = null;
2547
- timestamp = Date.now();
2548
- return fn.apply(null, _arguments);
2549
- }, threshold - (now - timestamp));
2579
+ if (passed >= threshold) {
2580
+ invoke(args, now);
2581
+ } else {
2582
+ lastArgs = args;
2583
+ if (!timer) {
2584
+ timer = setTimeout(function () {
2585
+ timer = null;
2586
+ invoke(lastArgs);
2587
+ }, threshold - passed);
2588
+ }
2550
2589
  }
2551
2590
  };
2591
+ var flush = function flush() {
2592
+ return lastArgs && invoke(lastArgs);
2593
+ };
2594
+ return [throttled, flush];
2552
2595
  }
2553
2596
 
2554
- var progressEventReducer = (function (listener, isDownloadStream) {
2597
+ var progressEventReducer = function progressEventReducer(listener, isDownloadStream) {
2555
2598
  var freq = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3;
2556
2599
  var bytesNotified = 0;
2557
2600
  var _speedometer = speedometer(50, 250);
@@ -2562,7 +2605,7 @@
2562
2605
  var rate = _speedometer(progressBytes);
2563
2606
  var inRange = loaded <= total;
2564
2607
  bytesNotified = loaded;
2565
- var data = {
2608
+ var data = _defineProperty({
2566
2609
  loaded: loaded,
2567
2610
  total: total,
2568
2611
  progress: total ? loaded / total : undefined,
@@ -2571,11 +2614,30 @@
2571
2614
  estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
2572
2615
  event: e,
2573
2616
  lengthComputable: total != null
2574
- };
2575
- data[isDownloadStream ? 'download' : 'upload'] = true;
2617
+ }, isDownloadStream ? 'download' : 'upload', true);
2576
2618
  listener(data);
2577
2619
  }, freq);
2578
- });
2620
+ };
2621
+ var progressEventDecorator = function progressEventDecorator(total, throttled) {
2622
+ var lengthComputable = total != null;
2623
+ return [function (loaded) {
2624
+ return throttled[0]({
2625
+ lengthComputable: lengthComputable,
2626
+ total: total,
2627
+ loaded: loaded
2628
+ });
2629
+ }, throttled[1]];
2630
+ };
2631
+ var asyncDecorator = function asyncDecorator(fn) {
2632
+ return function () {
2633
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2634
+ args[_key] = arguments[_key];
2635
+ }
2636
+ return utils$1.asap(function () {
2637
+ return fn.apply(void 0, args);
2638
+ });
2639
+ };
2640
+ };
2579
2641
 
2580
2642
  var isURLSameOrigin = platform.hasStandardBrowserEnv ?
2581
2643
  // Standard browser envs have full support of the APIs needed to test
@@ -2861,15 +2923,18 @@
2861
2923
  var _config = resolveConfig(config);
2862
2924
  var requestData = _config.data;
2863
2925
  var requestHeaders = AxiosHeaders$1.from(_config.headers).normalize();
2864
- var responseType = _config.responseType;
2926
+ var responseType = _config.responseType,
2927
+ onUploadProgress = _config.onUploadProgress,
2928
+ onDownloadProgress = _config.onDownloadProgress;
2865
2929
  var onCanceled;
2930
+ var uploadThrottled, downloadThrottled;
2931
+ var flushUpload, flushDownload;
2866
2932
  function done() {
2867
- if (_config.cancelToken) {
2868
- _config.cancelToken.unsubscribe(onCanceled);
2869
- }
2870
- if (_config.signal) {
2871
- _config.signal.removeEventListener('abort', onCanceled);
2872
- }
2933
+ flushUpload && flushUpload(); // flush events
2934
+ flushDownload && flushDownload(); // flush events
2935
+
2936
+ _config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
2937
+ _config.signal && _config.signal.removeEventListener('abort', onCanceled);
2873
2938
  }
2874
2939
  var request = new XMLHttpRequest();
2875
2940
  request.open(_config.method.toUpperCase(), _config.url, true);
@@ -2930,7 +2995,7 @@
2930
2995
  if (!request) {
2931
2996
  return;
2932
2997
  }
2933
- reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, _config, request));
2998
+ reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
2934
2999
 
2935
3000
  // Clean up request
2936
3001
  request = null;
@@ -2940,7 +3005,7 @@
2940
3005
  request.onerror = function handleError() {
2941
3006
  // Real errors are hidden from us by the browser
2942
3007
  // onerror should only fire if it's a network error
2943
- reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, _config, request));
3008
+ reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
2944
3009
 
2945
3010
  // Clean up request
2946
3011
  request = null;
@@ -2953,7 +3018,7 @@
2953
3018
  if (_config.timeoutErrorMessage) {
2954
3019
  timeoutErrorMessage = _config.timeoutErrorMessage;
2955
3020
  }
2956
- reject(new AxiosError(timeoutErrorMessage, transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED, _config, request));
3021
+ reject(new AxiosError(timeoutErrorMessage, transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED, config, request));
2957
3022
 
2958
3023
  // Clean up request
2959
3024
  request = null;
@@ -2980,13 +3045,22 @@
2980
3045
  }
2981
3046
 
2982
3047
  // Handle progress if needed
2983
- if (typeof _config.onDownloadProgress === 'function') {
2984
- request.addEventListener('progress', progressEventReducer(_config.onDownloadProgress, true));
3048
+ if (onDownloadProgress) {
3049
+ var _progressEventReducer = progressEventReducer(onDownloadProgress, true);
3050
+ var _progressEventReducer2 = _slicedToArray(_progressEventReducer, 2);
3051
+ downloadThrottled = _progressEventReducer2[0];
3052
+ flushDownload = _progressEventReducer2[1];
3053
+ request.addEventListener('progress', downloadThrottled);
2985
3054
  }
2986
3055
 
2987
3056
  // Not all browsers support upload events
2988
- if (typeof _config.onUploadProgress === 'function' && request.upload) {
2989
- request.upload.addEventListener('progress', progressEventReducer(_config.onUploadProgress));
3057
+ if (onUploadProgress && request.upload) {
3058
+ var _progressEventReducer3 = progressEventReducer(onUploadProgress);
3059
+ var _progressEventReducer4 = _slicedToArray(_progressEventReducer3, 2);
3060
+ uploadThrottled = _progressEventReducer4[0];
3061
+ flushUpload = _progressEventReducer4[1];
3062
+ request.upload.addEventListener('progress', uploadThrottled);
3063
+ request.upload.addEventListener('loadend', flushUpload);
2990
3064
  }
2991
3065
  if (_config.cancelToken || _config.signal) {
2992
3066
  // Handle cancellation
@@ -3171,40 +3245,57 @@
3171
3245
  var trackStream = function trackStream(stream, chunkSize, onProgress, onFinish, encode) {
3172
3246
  var iterator = readBytes(stream, chunkSize, encode);
3173
3247
  var bytes = 0;
3248
+ var done;
3249
+ var _onFinish = function _onFinish(e) {
3250
+ if (!done) {
3251
+ done = true;
3252
+ onFinish && onFinish(e);
3253
+ }
3254
+ };
3174
3255
  return new ReadableStream({
3175
- type: 'bytes',
3176
3256
  pull: function pull(controller) {
3177
3257
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
3178
- var _yield$iterator$next, done, value, len;
3258
+ var _yield$iterator$next, _done, value, len, loadedBytes;
3179
3259
  return _regeneratorRuntime().wrap(function _callee2$(_context3) {
3180
3260
  while (1) switch (_context3.prev = _context3.next) {
3181
3261
  case 0:
3182
- _context3.next = 2;
3262
+ _context3.prev = 0;
3263
+ _context3.next = 3;
3183
3264
  return iterator.next();
3184
- case 2:
3265
+ case 3:
3185
3266
  _yield$iterator$next = _context3.sent;
3186
- done = _yield$iterator$next.done;
3267
+ _done = _yield$iterator$next.done;
3187
3268
  value = _yield$iterator$next.value;
3188
- if (!done) {
3189
- _context3.next = 9;
3269
+ if (!_done) {
3270
+ _context3.next = 10;
3190
3271
  break;
3191
3272
  }
3273
+ _onFinish();
3192
3274
  controller.close();
3193
- onFinish();
3194
3275
  return _context3.abrupt("return");
3195
- case 9:
3276
+ case 10:
3196
3277
  len = value.byteLength;
3197
- onProgress && onProgress(bytes += len);
3278
+ if (onProgress) {
3279
+ loadedBytes = bytes += len;
3280
+ onProgress(loadedBytes);
3281
+ }
3198
3282
  controller.enqueue(new Uint8Array(value));
3199
- case 12:
3283
+ _context3.next = 19;
3284
+ break;
3285
+ case 15:
3286
+ _context3.prev = 15;
3287
+ _context3.t0 = _context3["catch"](0);
3288
+ _onFinish(_context3.t0);
3289
+ throw _context3.t0;
3290
+ case 19:
3200
3291
  case "end":
3201
3292
  return _context3.stop();
3202
3293
  }
3203
- }, _callee2);
3294
+ }, _callee2, null, [[0, 15]]);
3204
3295
  }))();
3205
3296
  },
3206
3297
  cancel: function cancel(reason) {
3207
- onFinish(reason);
3298
+ _onFinish(reason);
3208
3299
  return iterator["return"]();
3209
3300
  }
3210
3301
  }, {
@@ -3212,18 +3303,6 @@
3212
3303
  });
3213
3304
  };
3214
3305
 
3215
- var fetchProgressDecorator = function fetchProgressDecorator(total, fn) {
3216
- var lengthComputable = total != null;
3217
- return function (loaded) {
3218
- return setTimeout(function () {
3219
- return fn({
3220
- lengthComputable: lengthComputable,
3221
- total: total,
3222
- loaded: loaded
3223
- });
3224
- });
3225
- };
3226
- };
3227
3306
  var isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
3228
3307
  var isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
3229
3308
 
@@ -3253,7 +3332,17 @@
3253
3332
  return _ref.apply(this, arguments);
3254
3333
  };
3255
3334
  }()));
3256
- var supportsRequestStream = isReadableStreamSupported && function () {
3335
+ var test = function test(fn) {
3336
+ try {
3337
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
3338
+ args[_key - 1] = arguments[_key];
3339
+ }
3340
+ return !!fn.apply(void 0, args);
3341
+ } catch (e) {
3342
+ return false;
3343
+ }
3344
+ };
3345
+ var supportsRequestStream = isReadableStreamSupported && test(function () {
3257
3346
  var duplexAccessed = false;
3258
3347
  var hasContentType = new Request(platform.origin, {
3259
3348
  body: new ReadableStream(),
@@ -3264,15 +3353,11 @@
3264
3353
  }
3265
3354
  }).headers.has('Content-Type');
3266
3355
  return duplexAccessed && !hasContentType;
3267
- }();
3356
+ });
3268
3357
  var DEFAULT_CHUNK_SIZE = 64 * 1024;
3269
- var supportsResponseStream = isReadableStreamSupported && !!function () {
3270
- try {
3271
- return utils$1.isReadableStream(new Response('').body);
3272
- } catch (err) {
3273
- // return undefined
3274
- }
3275
- }();
3358
+ var supportsResponseStream = isReadableStreamSupported && test(function () {
3359
+ return utils$1.isReadableStream(new Response('').body);
3360
+ });
3276
3361
  var resolvers = {
3277
3362
  stream: supportsResponseStream && function (res) {
3278
3363
  return res.body;
@@ -3313,7 +3398,7 @@
3313
3398
  case 7:
3314
3399
  return _context2.abrupt("return", _context2.sent.byteLength);
3315
3400
  case 8:
3316
- if (!utils$1.isArrayBufferView(body)) {
3401
+ if (!(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body))) {
3317
3402
  _context2.next = 10;
3318
3403
  break;
3319
3404
  }
@@ -3360,7 +3445,7 @@
3360
3445
  }();
3361
3446
  var fetchAdapter = isFetchSupported && ( /*#__PURE__*/function () {
3362
3447
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(config) {
3363
- var _resolveConfig, url, method, data, signal, cancelToken, timeout, onDownloadProgress, onUploadProgress, responseType, headers, _resolveConfig$withCr, withCredentials, fetchOptions, _ref5, _ref6, composedSignal, stopTimeout, finished, request, onFinish, requestContentLength, _request, contentTypeHeader, response, isStreamResponse, options, responseContentLength, responseData;
3448
+ var _resolveConfig, url, method, data, signal, cancelToken, timeout, onDownloadProgress, onUploadProgress, responseType, headers, _resolveConfig$withCr, withCredentials, fetchOptions, _ref5, _ref6, composedSignal, stopTimeout, finished, request, onFinish, requestContentLength, _request, contentTypeHeader, _progressEventDecorat, _progressEventDecorat2, onProgress, flush, response, isStreamResponse, options, responseContentLength, _ref7, _ref8, _onProgress, _flush, responseData;
3364
3449
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
3365
3450
  while (1) switch (_context4.prev = _context4.next) {
3366
3451
  case 0:
@@ -3398,11 +3483,12 @@
3398
3483
  headers.setContentType(contentTypeHeader);
3399
3484
  }
3400
3485
  if (_request.body) {
3401
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(requestContentLength, progressEventReducer(onUploadProgress)), null, encodeText);
3486
+ _progressEventDecorat = progressEventDecorator(requestContentLength, progressEventReducer(asyncDecorator(onUploadProgress))), _progressEventDecorat2 = _slicedToArray(_progressEventDecorat, 2), onProgress = _progressEventDecorat2[0], flush = _progressEventDecorat2[1];
3487
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
3402
3488
  }
3403
3489
  case 15:
3404
3490
  if (!utils$1.isString(withCredentials)) {
3405
- withCredentials = withCredentials ? 'cors' : 'omit';
3491
+ withCredentials = withCredentials ? 'include' : 'omit';
3406
3492
  }
3407
3493
  request = new Request(url, _objectSpread2(_objectSpread2({}, fetchOptions), {}, {
3408
3494
  signal: composedSignal,
@@ -3410,7 +3496,7 @@
3410
3496
  headers: headers.normalize().toJSON(),
3411
3497
  body: data,
3412
3498
  duplex: "half",
3413
- withCredentials: withCredentials
3499
+ credentials: withCredentials
3414
3500
  }));
3415
3501
  _context4.next = 19;
3416
3502
  return fetch(request);
@@ -3423,7 +3509,11 @@
3423
3509
  options[prop] = response[prop];
3424
3510
  });
3425
3511
  responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
3426
- response = new Response(trackStream(response.body, DEFAULT_CHUNK_SIZE, onDownloadProgress && fetchProgressDecorator(responseContentLength, progressEventReducer(onDownloadProgress, true)), isStreamResponse && onFinish, encodeText), options);
3512
+ _ref7 = onDownloadProgress && progressEventDecorator(responseContentLength, progressEventReducer(asyncDecorator(onDownloadProgress), true)) || [], _ref8 = _slicedToArray(_ref7, 2), _onProgress = _ref8[0], _flush = _ref8[1];
3513
+ response = new Response(trackStream(response.body, DEFAULT_CHUNK_SIZE, _onProgress, function () {
3514
+ _flush && _flush();
3515
+ isStreamResponse && onFinish();
3516
+ }, encodeText), options);
3427
3517
  }
3428
3518
  responseType = responseType || 'text';
3429
3519
  _context4.next = 25;
@@ -3586,7 +3676,7 @@
3586
3676
  });
3587
3677
  }
3588
3678
 
3589
- var VERSION = "1.7.2";
3679
+ var VERSION = "1.7.3";
3590
3680
 
3591
3681
  var validators$1 = {};
3592
3682