axios 1.7.0-beta.0 → 1.7.0-beta.2

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,32 @@
1
1
  # Changelog
2
2
 
3
+ # [1.7.0-beta.2](https://github.com/axios/axios/compare/v1.7.0-beta.1...v1.7.0-beta.2) (2024-05-19)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **fetch:** capitalize HTTP method names; ([#6395](https://github.com/axios/axios/issues/6395)) ([ad3174a](https://github.com/axios/axios/commit/ad3174a3515c3c2573f4bcb94818d582826f3914))
9
+ * **fetch:** fix & optimize progress capturing for cases when the request data has a nullish value or zero data length ([#6400](https://github.com/axios/axios/issues/6400)) ([95a3e8e](https://github.com/axios/axios/commit/95a3e8e346cfd6a5548e171f2341df3235d0e26b))
10
+ * **fetch:** fix headers getting from a stream response; ([#6401](https://github.com/axios/axios/issues/6401)) ([870e0a7](https://github.com/axios/axios/commit/870e0a76f60d0094774a6a63fa606eec52a381af))
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 "+99/-46 (#6405 #6404 #6401 #6400 #6395 )")
15
+
16
+ # [1.7.0-beta.1](https://github.com/axios/axios/compare/v1.7.0-beta.0...v1.7.0-beta.1) (2024-05-07)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * **core/axios:** handle un-writable error stack ([#6362](https://github.com/axios/axios/issues/6362)) ([81e0455](https://github.com/axios/axios/commit/81e0455b7b57fbaf2be16a73ebe0e6591cc6d8f9))
22
+ * **fetch:** fix cases when ReadableStream or Response.body are not available; ([#6377](https://github.com/axios/axios/issues/6377)) ([d1d359d](https://github.com/axios/axios/commit/d1d359da347704e8b28d768e61515a3e96c5b072))
23
+ * **fetch:** treat fetch-related TypeError as an AxiosError.ERR_NETWORK error; ([#6380](https://github.com/axios/axios/issues/6380)) ([bb5f9a5](https://github.com/axios/axios/commit/bb5f9a5ab768452de9e166dc28d0ffc234245ef1))
24
+
25
+ ### Contributors to this release
26
+
27
+ - <img src="https://avatars.githubusercontent.com/u/16711696?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [Alexandre ABRIOUX](https://github.com/alexandre-abrioux "+56/-6 (#6362 )")
28
+ - <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 "+42/-17 (#6380 #6377 )")
29
+
3
30
  # [1.7.0-beta.0](https://github.com/axios/axios/compare/v1.6.8...v1.7.0-beta.0) (2024-04-28)
4
31
 
5
32
 
package/dist/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- // Axios v1.7.0-beta.0 Copyright (c) 2024 Matt Zabriskie and contributors
1
+ // Axios v1.7.0-beta.2 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) :
@@ -3226,7 +3226,8 @@
3226
3226
  };
3227
3227
  };
3228
3228
  var isFetchSupported = typeof fetch !== 'undefined';
3229
- var supportsRequestStreams = isFetchSupported && function () {
3229
+ var isReadableStreamSupported = isFetchSupported && typeof ReadableStream !== 'undefined';
3230
+ var supportsRequestStream = isReadableStreamSupported && function () {
3230
3231
  var duplexAccessed = false;
3231
3232
  var hasContentType = new Request(platform.origin, {
3232
3233
  body: new ReadableStream(),
@@ -3239,56 +3240,71 @@
3239
3240
  return duplexAccessed && !hasContentType;
3240
3241
  }();
3241
3242
  var DEFAULT_CHUNK_SIZE = 64 * 1024;
3243
+ var supportsResponseStream = isReadableStreamSupported && !!function () {
3244
+ try {
3245
+ return utils$1.isReadableStream(new Response('').body);
3246
+ } catch (err) {
3247
+ // return undefined
3248
+ }
3249
+ }();
3242
3250
  var resolvers = {
3243
- stream: function stream(res) {
3251
+ stream: supportsResponseStream && function (res) {
3244
3252
  return res.body;
3245
3253
  }
3246
3254
  };
3247
- isFetchSupported && ['text', 'arrayBuffer', 'blob', 'formData'].forEach(function (type) {
3248
- return [resolvers[type] = utils$1.isFunction(Response.prototype[type]) ? function (res) {
3249
- return res[type]();
3250
- } : function (_, config) {
3251
- throw new AxiosError("Response type ".concat(type, " is not supported"), AxiosError.ERR_NOT_SUPPORT, config);
3252
- }];
3253
- });
3255
+ isFetchSupported && function (res) {
3256
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(function (type) {
3257
+ !resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? function (res) {
3258
+ return res[type]();
3259
+ } : function (_, config) {
3260
+ throw new AxiosError("Response type '".concat(type, "' is not supported"), AxiosError.ERR_NOT_SUPPORT, config);
3261
+ });
3262
+ });
3263
+ }(new Response());
3254
3264
  var getBodyLength = /*#__PURE__*/function () {
3255
3265
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(body) {
3256
3266
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3257
3267
  while (1) switch (_context.prev = _context.next) {
3258
3268
  case 0:
3259
- if (!utils$1.isBlob(body)) {
3269
+ if (!(body == null)) {
3260
3270
  _context.next = 2;
3261
3271
  break;
3262
3272
  }
3263
- return _context.abrupt("return", body.size);
3273
+ return _context.abrupt("return", 0);
3264
3274
  case 2:
3275
+ if (!utils$1.isBlob(body)) {
3276
+ _context.next = 4;
3277
+ break;
3278
+ }
3279
+ return _context.abrupt("return", body.size);
3280
+ case 4:
3265
3281
  if (!utils$1.isSpecCompliantForm(body)) {
3266
- _context.next = 6;
3282
+ _context.next = 8;
3267
3283
  break;
3268
3284
  }
3269
- _context.next = 5;
3285
+ _context.next = 7;
3270
3286
  return new Request(body).arrayBuffer();
3271
- case 5:
3287
+ case 7:
3272
3288
  return _context.abrupt("return", _context.sent.byteLength);
3273
- case 6:
3289
+ case 8:
3274
3290
  if (!utils$1.isArrayBufferView(body)) {
3275
- _context.next = 8;
3291
+ _context.next = 10;
3276
3292
  break;
3277
3293
  }
3278
3294
  return _context.abrupt("return", body.byteLength);
3279
- case 8:
3295
+ case 10:
3280
3296
  if (utils$1.isURLSearchParams(body)) {
3281
3297
  body = body + '';
3282
3298
  }
3283
3299
  if (!utils$1.isString(body)) {
3284
- _context.next = 13;
3300
+ _context.next = 15;
3285
3301
  break;
3286
3302
  }
3287
- _context.next = 12;
3303
+ _context.next = 14;
3288
3304
  return new TextEncoder().encode(body);
3289
- case 12:
3305
+ case 14:
3290
3306
  return _context.abrupt("return", _context.sent.byteLength);
3291
- case 13:
3307
+ case 15:
3292
3308
  case "end":
3293
3309
  return _context.stop();
3294
3310
  }
@@ -3316,9 +3332,9 @@
3316
3332
  return _ref2.apply(this, arguments);
3317
3333
  };
3318
3334
  }();
3319
- var fetchAdapter = ( /*#__PURE__*/(function () {
3335
+ var fetchAdapter = isFetchSupported && ( /*#__PURE__*/function () {
3320
3336
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(config) {
3321
- var _resolveConfig, url, method, data, signal, cancelToken, timeout, onDownloadProgress, onUploadProgress, responseType, headers, _resolveConfig$withCr, withCredentials, fetchOptions, _ref4, _ref5, composedSignal, stopTimeout, finished, request, onFinish, requestContentLength, _request, contentTypeHeader, response, isStreamResponse, options, responseContentLength, responseData, code;
3337
+ var _resolveConfig, url, method, data, signal, cancelToken, timeout, onDownloadProgress, onUploadProgress, responseType, headers, _resolveConfig$withCr, withCredentials, fetchOptions, _ref4, _ref5, composedSignal, stopTimeout, finished, request, onFinish, requestContentLength, _request, contentTypeHeader, response, isStreamResponse, options, responseContentLength, responseData;
3322
3338
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
3323
3339
  while (1) switch (_context3.prev = _context3.next) {
3324
3340
  case 0:
@@ -3332,56 +3348,65 @@
3332
3348
  finished = true;
3333
3349
  };
3334
3350
  _context3.prev = 4;
3335
- if (!(onUploadProgress && supportsRequestStreams && method !== 'get' && method !== 'head')) {
3336
- _context3.next = 12;
3351
+ _context3.t0 = onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head';
3352
+ if (!_context3.t0) {
3353
+ _context3.next = 11;
3337
3354
  break;
3338
3355
  }
3339
- _context3.next = 8;
3356
+ _context3.next = 9;
3340
3357
  return resolveBodyLength(headers, data);
3341
- case 8:
3342
- requestContentLength = _context3.sent;
3358
+ case 9:
3359
+ _context3.t1 = requestContentLength = _context3.sent;
3360
+ _context3.t0 = _context3.t1 !== 0;
3361
+ case 11:
3362
+ if (!_context3.t0) {
3363
+ _context3.next = 15;
3364
+ break;
3365
+ }
3343
3366
  _request = new Request(url, {
3344
- method: method,
3367
+ method: 'POST',
3345
3368
  body: data,
3346
3369
  duplex: "half"
3347
3370
  });
3348
3371
  if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
3349
3372
  headers.setContentType(contentTypeHeader);
3350
3373
  }
3351
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(requestContentLength, progressEventReducer(onUploadProgress)));
3352
- case 12:
3374
+ if (_request.body) {
3375
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(requestContentLength, progressEventReducer(onUploadProgress)));
3376
+ }
3377
+ case 15:
3353
3378
  if (!utils$1.isString(withCredentials)) {
3354
3379
  withCredentials = withCredentials ? 'cors' : 'omit';
3355
3380
  }
3356
3381
  request = new Request(url, _objectSpread2(_objectSpread2({}, fetchOptions), {}, {
3357
3382
  signal: composedSignal,
3358
- method: method,
3383
+ method: method.toUpperCase(),
3359
3384
  headers: headers.normalize().toJSON(),
3360
3385
  body: data,
3361
3386
  duplex: "half",
3362
3387
  withCredentials: withCredentials
3363
3388
  }));
3364
- _context3.next = 16;
3389
+ _context3.next = 19;
3365
3390
  return fetch(request);
3366
- case 16:
3391
+ case 19:
3367
3392
  response = _context3.sent;
3368
3393
  isStreamResponse = responseType === 'stream' || responseType === 'response';
3369
- if (onDownloadProgress || isStreamResponse) {
3394
+ if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
3370
3395
  options = {};
3371
- Object.getOwnPropertyNames(response).forEach(function (prop) {
3396
+ ['status', 'statusText', 'headers'].forEach(function (prop) {
3372
3397
  options[prop] = response[prop];
3373
3398
  });
3374
3399
  responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
3375
3400
  response = new Response(trackStream(response.body, DEFAULT_CHUNK_SIZE, onDownloadProgress && fetchProgressDecorator(responseContentLength, progressEventReducer(onDownloadProgress, true)), isStreamResponse && onFinish), options);
3376
3401
  }
3377
3402
  responseType = responseType || 'text';
3378
- _context3.next = 22;
3403
+ _context3.next = 25;
3379
3404
  return resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
3380
- case 22:
3405
+ case 25:
3381
3406
  responseData = _context3.sent;
3382
3407
  !isStreamResponse && onFinish();
3383
3408
  stopTimeout && stopTimeout();
3384
- _context3.next = 27;
3409
+ _context3.next = 30;
3385
3410
  return new Promise(function (resolve, reject) {
3386
3411
  settle(resolve, reject, {
3387
3412
  data: responseData,
@@ -3392,27 +3417,31 @@
3392
3417
  request: request
3393
3418
  });
3394
3419
  });
3395
- case 27:
3396
- return _context3.abrupt("return", _context3.sent);
3397
3420
  case 30:
3398
- _context3.prev = 30;
3399
- _context3.t0 = _context3["catch"](4);
3421
+ return _context3.abrupt("return", _context3.sent);
3422
+ case 33:
3423
+ _context3.prev = 33;
3424
+ _context3.t2 = _context3["catch"](4);
3400
3425
  onFinish();
3401
- code = _context3.t0.code;
3402
- if (_context3.t0.name === 'NetworkError') {
3403
- code = AxiosError.ERR_NETWORK;
3426
+ if (!(_context3.t2 && _context3.t2.name === 'TypeError' && /fetch/i.test(_context3.t2.message))) {
3427
+ _context3.next = 38;
3428
+ break;
3404
3429
  }
3405
- throw AxiosError.from(_context3.t0, code, config, request);
3406
- case 36:
3430
+ throw Object.assign(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request), {
3431
+ cause: _context3.t2.cause || _context3.t2
3432
+ });
3433
+ case 38:
3434
+ throw AxiosError.from(_context3.t2, _context3.t2 && _context3.t2.code, config, request);
3435
+ case 39:
3407
3436
  case "end":
3408
3437
  return _context3.stop();
3409
3438
  }
3410
- }, _callee3, null, [[4, 30]]);
3439
+ }, _callee3, null, [[4, 33]]);
3411
3440
  }));
3412
3441
  return function (_x4) {
3413
3442
  return _ref3.apply(this, arguments);
3414
3443
  };
3415
- })());
3444
+ }());
3416
3445
 
3417
3446
  var knownAdapters = {
3418
3447
  http: httpAdapter,
@@ -3531,7 +3560,7 @@
3531
3560
  });
3532
3561
  }
3533
3562
 
3534
- var VERSION = "1.7.0-beta.0";
3563
+ var VERSION = "1.7.0-beta.2";
3535
3564
 
3536
3565
  var validators$1 = {};
3537
3566
 
@@ -3656,11 +3685,15 @@
3656
3685
 
3657
3686
  // slice off the Error: ... line
3658
3687
  stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
3659
- if (!_context.t0.stack) {
3660
- _context.t0.stack = stack;
3661
- // match without the 2 top stack lines
3662
- } else if (stack && !String(_context.t0.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
3663
- _context.t0.stack += '\n' + stack;
3688
+ try {
3689
+ if (!_context.t0.stack) {
3690
+ _context.t0.stack = stack;
3691
+ // match without the 2 top stack lines
3692
+ } else if (stack && !String(_context.t0.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
3693
+ _context.t0.stack += '\n' + stack;
3694
+ }
3695
+ } catch (e) {
3696
+ // ignore the case where "stack" is an un-writable property
3664
3697
  }
3665
3698
  }
3666
3699
  throw _context.t0;