@kontent-ai/core-sdk 10.12.5 → 10.12.7

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.
Files changed (40) hide show
  1. package/.npmignore +14 -14
  2. package/LICENSE.md +9 -9
  3. package/README.md +30 -30
  4. package/dist/cjs/http/http.functions.js +109 -23
  5. package/dist/cjs/http/http.functions.js.map +1 -1
  6. package/dist/cjs/sdk-info.generated.js +1 -1
  7. package/dist/es6/http/http.functions.js +109 -23
  8. package/dist/es6/http/http.functions.js.map +1 -1
  9. package/dist/es6/sdk-info.generated.js +1 -1
  10. package/dist/esnext/http/http.functions.js +109 -23
  11. package/dist/esnext/http/http.functions.js.map +1 -1
  12. package/dist/esnext/sdk-info.generated.js +1 -1
  13. package/dist/umd/kontent-core.umd.js +646 -147
  14. package/dist/umd/kontent-core.umd.js.map +1 -1
  15. package/dist/umd/kontent-core.umd.min.js +1 -1
  16. package/dist/umd/kontent-core.umd.min.js.LICENSE.txt +1 -1
  17. package/dist/umd/kontent-core.umd.min.js.map +1 -1
  18. package/dist/umd/report.json +1 -1
  19. package/dist/umd/report.min.json +1 -1
  20. package/dist/umd/stats.json +441 -441
  21. package/dist/umd/stats.min.json +449 -449
  22. package/lib/helpers/header.helper.ts +23 -23
  23. package/lib/helpers/headers-helper.ts +15 -15
  24. package/lib/helpers/index.ts +4 -4
  25. package/lib/helpers/retry-helper.ts +204 -204
  26. package/lib/helpers/url.helper.ts +26 -26
  27. package/lib/http/http.debugger.ts +21 -21
  28. package/lib/http/http.functions.ts +416 -314
  29. package/lib/http/http.models.ts +83 -83
  30. package/lib/http/http.service.ts +91 -91
  31. package/lib/http/ihttp.service.ts +20 -20
  32. package/lib/http/index.ts +6 -6
  33. package/lib/http/test-http.service.ts +70 -70
  34. package/lib/index.ts +4 -4
  35. package/lib/models/index.ts +3 -3
  36. package/lib/models/isdk-info.ts +15 -15
  37. package/lib/models/parameters.ts +25 -25
  38. package/lib/models/url.models.ts +3 -3
  39. package/lib/sdk-info.generated.ts +1 -1
  40. package/package.json +93 -93
@@ -347,7 +347,7 @@ const headers_helper_1 = __webpack_require__(/*! ../helpers/headers-helper */ ".
347
347
  const http_debugger_1 = __webpack_require__(/*! ./http.debugger */ "./lib/http/http.debugger.ts");
348
348
  const retry_helper_1 = __webpack_require__(/*! ../helpers/retry-helper */ "./lib/helpers/retry-helper.ts");
349
349
  function getWithRetryAsync(instance, call, functionsConfig, options) {
350
- var _a;
350
+ var _a, _b;
351
351
  return __awaiter(this, void 0, void 0, function* () {
352
352
  const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retry_helper_1.retryHelper.defaultRetryStrategy;
353
353
  return yield runWithRetryAsync({
@@ -355,13 +355,14 @@ function getWithRetryAsync(instance, call, functionsConfig, options) {
355
355
  url: call.url,
356
356
  retryStrategy: retryStrategyOptions,
357
357
  functionsConfig: functionsConfig,
358
+ headers: (_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [],
358
359
  call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
359
- var _b, _c;
360
+ var _c, _d;
360
361
  http_debugger_1.httpDebugger.debugStartHttpRequest();
361
362
  const axiosResponse = yield instance.get(call.url, {
362
- headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
363
+ headers: getHeadersJson((_c = options === null || options === void 0 ? void 0 : options.headers) !== null && _c !== void 0 ? _c : [], false),
363
364
  responseType: options === null || options === void 0 ? void 0 : options.responseType,
364
- cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
365
+ cancelToken: (_d = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _d === void 0 ? void 0 : _d.token
365
366
  });
366
367
  const response = {
367
368
  data: axiosResponse.data,
@@ -381,7 +382,7 @@ function getWithRetryAsync(instance, call, functionsConfig, options) {
381
382
  }
382
383
  exports.getWithRetryAsync = getWithRetryAsync;
383
384
  function postWithRetryAsync(instance, call, functionsConfig, options) {
384
- var _a;
385
+ var _a, _b;
385
386
  return __awaiter(this, void 0, void 0, function* () {
386
387
  const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retry_helper_1.retryHelper.defaultRetryStrategy;
387
388
  return yield runWithRetryAsync({
@@ -389,17 +390,18 @@ function postWithRetryAsync(instance, call, functionsConfig, options) {
389
390
  url: call.url,
390
391
  retryStrategy: retryStrategyOptions,
391
392
  functionsConfig: functionsConfig,
393
+ headers: (_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [],
392
394
  call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
393
- var _b, _c;
395
+ var _c, _d;
394
396
  http_debugger_1.httpDebugger.debugStartHttpRequest();
395
397
  const axiosResponse = yield instance.post(call.url, call.body, {
396
- headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
398
+ headers: getHeadersJson((_c = options === null || options === void 0 ? void 0 : options.headers) !== null && _c !== void 0 ? _c : [], false),
397
399
  responseType: options === null || options === void 0 ? void 0 : options.responseType,
398
400
  // required for uploading large files
399
401
  // https://github.com/axios/axios/issues/1362
400
402
  maxContentLength: 'Infinity',
401
403
  maxBodyLength: 'Infinity',
402
- cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
404
+ cancelToken: (_d = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _d === void 0 ? void 0 : _d.token
403
405
  });
404
406
  const response = {
405
407
  data: axiosResponse.data,
@@ -419,7 +421,7 @@ function postWithRetryAsync(instance, call, functionsConfig, options) {
419
421
  }
420
422
  exports.postWithRetryAsync = postWithRetryAsync;
421
423
  function putWithRetryAsync(instance, call, functionsConfig, options) {
422
- var _a;
424
+ var _a, _b;
423
425
  return __awaiter(this, void 0, void 0, function* () {
424
426
  const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retry_helper_1.retryHelper.defaultRetryStrategy;
425
427
  return yield runWithRetryAsync({
@@ -427,17 +429,18 @@ function putWithRetryAsync(instance, call, functionsConfig, options) {
427
429
  url: call.url,
428
430
  retryStrategy: retryStrategyOptions,
429
431
  functionsConfig: functionsConfig,
432
+ headers: (_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [],
430
433
  call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
431
- var _b, _c;
434
+ var _c, _d;
432
435
  http_debugger_1.httpDebugger.debugStartHttpRequest();
433
436
  const axiosResponse = yield instance.put(call.url, call.body, {
434
- headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
437
+ headers: getHeadersJson((_c = options === null || options === void 0 ? void 0 : options.headers) !== null && _c !== void 0 ? _c : [], false),
435
438
  responseType: options === null || options === void 0 ? void 0 : options.responseType,
436
439
  // required for uploading large files
437
440
  // https://github.com/axios/axios/issues/1362
438
441
  maxContentLength: 'Infinity',
439
442
  maxBodyLength: 'Infinity',
440
- cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
443
+ cancelToken: (_d = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _d === void 0 ? void 0 : _d.token
441
444
  });
442
445
  const response = {
443
446
  data: axiosResponse.data,
@@ -457,7 +460,7 @@ function putWithRetryAsync(instance, call, functionsConfig, options) {
457
460
  }
458
461
  exports.putWithRetryAsync = putWithRetryAsync;
459
462
  function patchWithRetryAsync(instance, call, functionsConfig, options) {
460
- var _a;
463
+ var _a, _b;
461
464
  return __awaiter(this, void 0, void 0, function* () {
462
465
  const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retry_helper_1.retryHelper.defaultRetryStrategy;
463
466
  return yield runWithRetryAsync({
@@ -465,17 +468,18 @@ function patchWithRetryAsync(instance, call, functionsConfig, options) {
465
468
  url: call.url,
466
469
  retryStrategy: retryStrategyOptions,
467
470
  functionsConfig: functionsConfig,
471
+ headers: (_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [],
468
472
  call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
469
- var _b, _c;
473
+ var _c, _d;
470
474
  http_debugger_1.httpDebugger.debugStartHttpRequest();
471
475
  const axiosResponse = yield instance.patch(call.url, call.body, {
472
- headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
476
+ headers: getHeadersJson((_c = options === null || options === void 0 ? void 0 : options.headers) !== null && _c !== void 0 ? _c : [], false),
473
477
  responseType: options === null || options === void 0 ? void 0 : options.responseType,
474
478
  // required for uploading large files
475
479
  // https://github.com/axios/axios/issues/1362
476
480
  maxContentLength: 'Infinity',
477
481
  maxBodyLength: 'Infinity',
478
- cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
482
+ cancelToken: (_d = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _d === void 0 ? void 0 : _d.token
479
483
  });
480
484
  const response = {
481
485
  data: axiosResponse.data,
@@ -495,7 +499,7 @@ function patchWithRetryAsync(instance, call, functionsConfig, options) {
495
499
  }
496
500
  exports.patchWithRetryAsync = patchWithRetryAsync;
497
501
  function deleteWithRetryAsync(instance, call, functionsConfig, options) {
498
- var _a;
502
+ var _a, _b;
499
503
  return __awaiter(this, void 0, void 0, function* () {
500
504
  const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retry_helper_1.retryHelper.defaultRetryStrategy;
501
505
  return yield runWithRetryAsync({
@@ -503,17 +507,18 @@ function deleteWithRetryAsync(instance, call, functionsConfig, options) {
503
507
  url: call.url,
504
508
  retryStrategy: retryStrategyOptions,
505
509
  functionsConfig: functionsConfig,
510
+ headers: (_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [],
506
511
  call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
507
- var _b, _c;
512
+ var _c, _d;
508
513
  http_debugger_1.httpDebugger.debugStartHttpRequest();
509
514
  const axiosResponse = yield instance.delete(call.url, {
510
- headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
515
+ headers: getHeadersJson((_c = options === null || options === void 0 ? void 0 : options.headers) !== null && _c !== void 0 ? _c : [], false),
511
516
  responseType: options === null || options === void 0 ? void 0 : options.responseType,
512
517
  // required for uploading large files
513
518
  // https://github.com/axios/axios/issues/1362
514
519
  maxContentLength: 'Infinity',
515
520
  maxBodyLength: 'Infinity',
516
- cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
521
+ cancelToken: (_d = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _d === void 0 ? void 0 : _d.token
517
522
  });
518
523
  const response = {
519
524
  data: axiosResponse.data,
@@ -568,16 +573,97 @@ function runWithRetryAsync(data) {
568
573
  retryStrategy: data.retryStrategy,
569
574
  retryAttempt: data.retryAttempt + 1,
570
575
  url: data.url,
571
- functionsConfig: data.functionsConfig
576
+ functionsConfig: data.functionsConfig,
577
+ headers: data.headers
572
578
  });
573
579
  }
580
+ // sanitize the error before logging / re-throwing so the authorization token is not leaked
581
+ const sanitizedError = sanitizeError(error, data.headers);
574
582
  if (data.functionsConfig.logErrorsToConsole) {
575
- console.error(`Executing '${data.url}' failed. Request was retried '${data.retryAttempt}' times. `, error);
583
+ console.error(`Executing '${data.url}' failed. Request was retried '${data.retryAttempt}' times.`, sanitizedError);
576
584
  }
577
- throw error;
585
+ throw sanitizedError;
578
586
  }
579
587
  });
580
588
  }
589
+ const redactedValue = 'redacted';
590
+ const maxRedactionDepth = 10;
591
+ /**
592
+ * Returns the caller-supplied 'authorization' header value(s), which are the secret token(s) to
593
+ * scrub from errors. Note: if a consumer sets the authorization token on the axios instance defaults
594
+ * instead of passing it via 'options.headers', it is not known here and cannot be redacted.
595
+ */
596
+ function getSecretHeaderValues(headers) {
597
+ return headers
598
+ .filter((header) => header.header.toLowerCase() === 'authorization')
599
+ .map((header) => header.value)
600
+ // skip empty values - splitting on an empty string would corrupt every string
601
+ .filter((value) => typeof value === 'string' && value.length > 0);
602
+ }
603
+ function redactStringValue(value, secrets) {
604
+ let result = value;
605
+ for (const secret of secrets) {
606
+ if (result.includes(secret)) {
607
+ result = result.split(secret).join(redactedValue);
608
+ }
609
+ }
610
+ return result;
611
+ }
612
+ /**
613
+ * Walks the object graph (cycle- and depth-guarded) replacing every occurrence of a secret with the
614
+ * redacted placeholder in place.
615
+ */
616
+ function redactSecretsInPlace(target, secrets, seen, depth) {
617
+ if (depth > maxRedactionDepth || target === null || typeof target !== 'object') {
618
+ return;
619
+ }
620
+ if (seen.has(target)) {
621
+ // break cycles (config.headers, request.socket, response.request, ...)
622
+ return;
623
+ }
624
+ seen.add(target);
625
+ for (const key of Object.keys(target)) {
626
+ let value;
627
+ try {
628
+ value = target[key];
629
+ }
630
+ catch (_a) {
631
+ // accessing the property threw (e.g. a getter) - skip it
632
+ continue;
633
+ }
634
+ if (typeof value === 'string') {
635
+ const redacted = redactStringValue(value, secrets);
636
+ if (redacted !== value) {
637
+ try {
638
+ target[key] = redacted;
639
+ }
640
+ catch (_b) {
641
+ // property is read-only - skip it
642
+ }
643
+ }
644
+ }
645
+ else if (value && typeof value === 'object') {
646
+ redactSecretsInPlace(value, secrets, seen, depth + 1);
647
+ }
648
+ }
649
+ }
650
+ /**
651
+ * If 'error' is an axios error, redacts every occurrence of the caller's authorization token (taken
652
+ * from 'headers') throughout the error, replacing it with a redacted placeholder. Non-axios errors
653
+ * and errors with no known token are returned unchanged. This prevents the authorization token from
654
+ * leaking via console logs or the re-thrown error. All other axios properties are preserved.
655
+ */
656
+ function sanitizeError(error, headers) {
657
+ if (!axios_1.default.isAxiosError(error)) {
658
+ return error;
659
+ }
660
+ const secrets = getSecretHeaderValues(headers);
661
+ if (secrets.length === 0) {
662
+ return error;
663
+ }
664
+ redactSecretsInPlace(error, secrets, new WeakSet(), 0);
665
+ return error;
666
+ }
581
667
  function getHeadersJson(headers, addContentTypeHeader) {
582
668
  const headerJson = {};
583
669
  headers.forEach((header) => {
@@ -899,7 +985,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
899
985
  \***************************************************/
900
986
  (module, __unused_webpack_exports, __webpack_require__) {
901
987
 
902
- /*! Axios v1.16.1 Copyright (c) 2026 Matt Zabriskie and contributors */
988
+ /*! Axios v1.18.1 Copyright (c) 2026 Matt Zabriskie and contributors */
903
989
 
904
990
 
905
991
  /**
@@ -921,6 +1007,57 @@ const { toString } = Object.prototype;
921
1007
  const { getPrototypeOf } = Object;
922
1008
  const { iterator, toStringTag } = Symbol;
923
1009
 
1010
+ /* Creating a function that will check if an object has a property. */
1011
+ const hasOwnProperty = (
1012
+ ({ hasOwnProperty }) =>
1013
+ (obj, prop) =>
1014
+ hasOwnProperty.call(obj, prop)
1015
+ )(Object.prototype);
1016
+
1017
+ /**
1018
+ * Walk the prototype chain (excluding the shared Object.prototype) looking for
1019
+ * an own `prop`. This distinguishes genuine own/inherited members — including
1020
+ * class accessors and template prototypes — from members injected via
1021
+ * Object.prototype pollution (e.g. `Object.prototype.username = '...'`), which
1022
+ * live on Object.prototype itself and are therefore never matched.
1023
+ *
1024
+ * @param {*} thing The value whose chain to inspect
1025
+ * @param {string|symbol} prop The property key to look for
1026
+ *
1027
+ * @returns {boolean} True when `prop` is owned below Object.prototype
1028
+ */
1029
+ const hasOwnInPrototypeChain = (thing, prop) => {
1030
+ let obj = thing;
1031
+ const seen = [];
1032
+
1033
+ while (obj != null && obj !== Object.prototype) {
1034
+ if (seen.indexOf(obj) !== -1) {
1035
+ return false;
1036
+ }
1037
+ seen.push(obj);
1038
+
1039
+ if (hasOwnProperty(obj, prop)) {
1040
+ return true;
1041
+ }
1042
+ obj = getPrototypeOf(obj);
1043
+ }
1044
+ return false;
1045
+ };
1046
+
1047
+ /**
1048
+ * Read `obj[prop]` only when it is safe from Object.prototype pollution. Own
1049
+ * properties and members inherited from a non-Object.prototype source (a class
1050
+ * instance or template object) are honored; a value reachable only through a
1051
+ * polluted Object.prototype is ignored and `undefined` is returned.
1052
+ *
1053
+ * @param {*} obj The source object
1054
+ * @param {string|symbol} prop The property key to read
1055
+ *
1056
+ * @returns {*} The resolved value, or undefined when unsafe/absent
1057
+ */
1058
+ const getSafeProp = (obj, prop) =>
1059
+ obj != null && hasOwnInPrototypeChain(obj, prop) ? obj[prop] : undefined;
1060
+
924
1061
  const kindOf = ((cache) => (thing) => {
925
1062
  const str = toString.call(thing);
926
1063
  return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
@@ -1046,7 +1183,7 @@ const isBoolean = (thing) => thing === true || thing === false;
1046
1183
  * @returns {boolean} True if value is a plain Object, otherwise false
1047
1184
  */
1048
1185
  const isPlainObject = (val) => {
1049
- if (kindOf(val) !== 'object') {
1186
+ if (!isObject(val)) {
1050
1187
  return false;
1051
1188
  }
1052
1189
 
@@ -1054,9 +1191,12 @@ const isPlainObject = (val) => {
1054
1191
  return (
1055
1192
  (prototype === null ||
1056
1193
  prototype === Object.prototype ||
1057
- Object.getPrototypeOf(prototype) === null) &&
1058
- !(toStringTag in val) &&
1059
- !(iterator in val)
1194
+ getPrototypeOf(prototype) === null) &&
1195
+ // Treat any genuine (non-Object.prototype-polluted) Symbol.toStringTag or
1196
+ // Symbol.iterator as evidence the value is a tagged/iterable type rather
1197
+ // than a plain object, while ignoring keys injected onto Object.prototype.
1198
+ !hasOwnInPrototypeChain(val, toStringTag) &&
1199
+ !hasOwnInPrototypeChain(val, iterator)
1060
1200
  );
1061
1201
  };
1062
1202
 
@@ -1325,7 +1465,9 @@ function merge(...objs) {
1325
1465
  return;
1326
1466
  }
1327
1467
 
1328
- const targetKey = (caseless && findKey(result, key)) || key;
1468
+ // findKey lowercases the key, so caseless lookup only applies to strings —
1469
+ // symbol keys are identity-matched.
1470
+ const targetKey = (caseless && typeof key === 'string' && findKey(result, key)) || key;
1329
1471
  // Read via own-prop only — a bare `result[targetKey]` walks the prototype
1330
1472
  // chain, so a polluted Object.prototype value could surface here and get
1331
1473
  // copied into the merged result.
@@ -1342,7 +1484,24 @@ function merge(...objs) {
1342
1484
  };
1343
1485
 
1344
1486
  for (let i = 0, l = objs.length; i < l; i++) {
1345
- objs[i] && forEach(objs[i], assignValue);
1487
+ const source = objs[i];
1488
+ if (!source || isBuffer(source)) {
1489
+ continue;
1490
+ }
1491
+
1492
+ forEach(source, assignValue);
1493
+
1494
+ if (typeof source !== 'object' || isArray(source)) {
1495
+ continue;
1496
+ }
1497
+
1498
+ const symbols = Object.getOwnPropertySymbols(source);
1499
+ for (let j = 0; j < symbols.length; j++) {
1500
+ const symbol = symbols[j];
1501
+ if (propertyIsEnumerable.call(source, symbol)) {
1502
+ assignValue(source[symbol], symbol);
1503
+ }
1504
+ }
1346
1505
  }
1347
1506
  return result;
1348
1507
  }
@@ -1564,12 +1723,7 @@ const toCamelCase = (str) => {
1564
1723
  });
1565
1724
  };
1566
1725
 
1567
- /* Creating a function that will check if an object has a property. */
1568
- const hasOwnProperty = (
1569
- ({ hasOwnProperty }) =>
1570
- (obj, prop) =>
1571
- hasOwnProperty.call(obj, prop)
1572
- )(Object.prototype);
1726
+ const { propertyIsEnumerable } = Object.prototype;
1573
1727
 
1574
1728
  /**
1575
1729
  * Determine if a value is a RegExp object
@@ -1782,6 +1936,20 @@ const asap =
1782
1936
 
1783
1937
  const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
1784
1938
 
1939
+ /**
1940
+ * Determine if a value is iterable via an iterator that is NOT sourced solely
1941
+ * from a polluted Object.prototype. Use this instead of `isIterable` whenever
1942
+ * the iterable comes from untrusted input (e.g. user-supplied header sources),
1943
+ * so `Object.prototype[Symbol.iterator] = ...` cannot turn an ordinary object
1944
+ * into an attacker-controlled entries iterator.
1945
+ *
1946
+ * @param {*} thing The value to test
1947
+ *
1948
+ * @returns {boolean} True if value has a non-polluted iterator
1949
+ */
1950
+ const isSafeIterable = (thing) =>
1951
+ thing != null && hasOwnInPrototypeChain(thing, iterator) && isIterable(thing);
1952
+
1785
1953
  var utils$1 = {
1786
1954
  isArray,
1787
1955
  isArrayBuffer,
@@ -1826,6 +1994,8 @@ var utils$1 = {
1826
1994
  isHTMLForm,
1827
1995
  hasOwnProperty,
1828
1996
  hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
1997
+ hasOwnInPrototypeChain,
1998
+ getSafeProp,
1829
1999
  reduceDescriptors,
1830
2000
  freezeMethods,
1831
2001
  toObjectSet,
@@ -1842,6 +2012,7 @@ var utils$1 = {
1842
2012
  setImmediate: _setImmediate,
1843
2013
  asap,
1844
2014
  isIterable,
2015
+ isSafeIterable,
1845
2016
  };
1846
2017
 
1847
2018
  // RawAxiosHeaders whose duplicates are ignored by node
@@ -2052,7 +2223,7 @@ class AxiosHeaders {
2052
2223
  const lHeader = normalizeHeader(_header);
2053
2224
 
2054
2225
  if (!lHeader) {
2055
- throw new Error('header name must be a non-empty string');
2226
+ return;
2056
2227
  }
2057
2228
 
2058
2229
  const key = utils$1.findKey(self, lHeader);
@@ -2074,20 +2245,23 @@ class AxiosHeaders {
2074
2245
  setHeaders(header, valueOrRewrite);
2075
2246
  } else if (utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
2076
2247
  setHeaders(parseHeaders(header), valueOrRewrite);
2077
- } else if (utils$1.isObject(header) && utils$1.isIterable(header)) {
2078
- let obj = {},
2248
+ } else if (utils$1.isObject(header) && utils$1.isSafeIterable(header)) {
2249
+ let obj = Object.create(null),
2079
2250
  dest,
2080
2251
  key;
2081
2252
  for (const entry of header) {
2082
2253
  if (!utils$1.isArray(entry)) {
2083
- throw TypeError('Object iterator must return a key-value pair');
2254
+ throw new TypeError('Object iterator must return a key-value pair');
2084
2255
  }
2085
2256
 
2086
- obj[(key = entry[0])] = (dest = obj[key])
2087
- ? utils$1.isArray(dest)
2088
- ? [...dest, entry[1]]
2089
- : [dest, entry[1]]
2090
- : entry[1];
2257
+ key = entry[0];
2258
+
2259
+ if (utils$1.hasOwnProp(obj, key)) {
2260
+ dest = obj[key];
2261
+ obj[key] = utils$1.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]];
2262
+ } else {
2263
+ obj[key] = entry[1];
2264
+ }
2091
2265
  }
2092
2266
 
2093
2267
  setHeaders(obj, valueOrRewrite);
@@ -2380,7 +2554,19 @@ function redactConfig(config, redactKeys) {
2380
2554
  class AxiosError extends Error {
2381
2555
  static from(error, code, config, request, response, customProps) {
2382
2556
  const axiosError = new AxiosError(error.message, code || error.code, config, request, response);
2383
- axiosError.cause = error;
2557
+ // Match native `Error` `cause` semantics: non-enumerable. The wrapped
2558
+ // error often carries circular internals (sockets, requests, agents), so
2559
+ // an enumerable `cause` makes structured loggers (pino/winston) and any
2560
+ // own-property walk throw "Converting circular structure to JSON".
2561
+ // Regression from #6982; see #7205. `__proto__: null` mirrors the
2562
+ // `message` descriptor below (prototype-pollution-safe descriptor).
2563
+ Object.defineProperty(axiosError, 'cause', {
2564
+ __proto__: null,
2565
+ value: error,
2566
+ writable: true,
2567
+ enumerable: false,
2568
+ configurable: true,
2569
+ });
2384
2570
  axiosError.name = error.name;
2385
2571
 
2386
2572
  // Preserve status from the original error if not already set from response
@@ -2481,6 +2667,10 @@ AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED = 'ERR_FORM_DATA_DEPTH_EXCEEDED';
2481
2667
  // eslint-disable-next-line strict
2482
2668
  var httpAdapter = null;
2483
2669
 
2670
+ // Default nesting limit shared with the inverse transform (formDataToJSON) so
2671
+ // the FormData <-> JSON round-trip stays symmetric.
2672
+ const DEFAULT_FORM_DATA_MAX_DEPTH = 100;
2673
+
2484
2674
  /**
2485
2675
  * Determines if the given thing is a array or js object.
2486
2676
  *
@@ -2591,8 +2781,9 @@ function toFormData(obj, formData, options) {
2591
2781
  const dots = options.dots;
2592
2782
  const indexes = options.indexes;
2593
2783
  const _Blob = options.Blob || (typeof Blob !== 'undefined' && Blob);
2594
- const maxDepth = options.maxDepth === undefined ? 100 : options.maxDepth;
2784
+ const maxDepth = options.maxDepth === undefined ? DEFAULT_FORM_DATA_MAX_DEPTH : options.maxDepth;
2595
2785
  const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);
2786
+ const stack = [];
2596
2787
 
2597
2788
  if (!utils$1.isFunction(visitor)) {
2598
2789
  throw new TypeError('visitor must be a function');
@@ -2614,12 +2805,50 @@ function toFormData(obj, formData, options) {
2614
2805
  }
2615
2806
 
2616
2807
  if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
2617
- return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
2808
+ if (useBlob && typeof _Blob === 'function') {
2809
+ return new _Blob([value]);
2810
+ }
2811
+ if (typeof Buffer !== 'undefined') {
2812
+ return Buffer.from(value);
2813
+ }
2814
+ throw new AxiosError('Blob is not supported. Use a Buffer instead.', AxiosError.ERR_NOT_SUPPORT);
2618
2815
  }
2619
2816
 
2620
2817
  return value;
2621
2818
  }
2622
2819
 
2820
+ function throwIfMaxDepthExceeded(depth) {
2821
+ if (depth > maxDepth) {
2822
+ throw new AxiosError(
2823
+ 'Object is too deeply nested (' + depth + ' levels). Max depth: ' + maxDepth,
2824
+ AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
2825
+ );
2826
+ }
2827
+ }
2828
+
2829
+ function stringifyWithDepthLimit(value, depth) {
2830
+ if (maxDepth === Infinity) {
2831
+ return JSON.stringify(value);
2832
+ }
2833
+
2834
+ const ancestors = [];
2835
+
2836
+ return JSON.stringify(value, function limitDepth(_key, currentValue) {
2837
+ if (!utils$1.isObject(currentValue)) {
2838
+ return currentValue;
2839
+ }
2840
+
2841
+ while (ancestors.length && ancestors[ancestors.length - 1] !== this) {
2842
+ ancestors.pop();
2843
+ }
2844
+
2845
+ ancestors.push(currentValue);
2846
+ throwIfMaxDepthExceeded(depth + ancestors.length - 1);
2847
+
2848
+ return currentValue;
2849
+ });
2850
+ }
2851
+
2623
2852
  /**
2624
2853
  * Default visitor.
2625
2854
  *
@@ -2643,7 +2872,7 @@ function toFormData(obj, formData, options) {
2643
2872
  // eslint-disable-next-line no-param-reassign
2644
2873
  key = metaTokens ? key : key.slice(0, -2);
2645
2874
  // eslint-disable-next-line no-param-reassign
2646
- value = JSON.stringify(value);
2875
+ value = stringifyWithDepthLimit(value, 1);
2647
2876
  } else if (
2648
2877
  (utils$1.isArray(value) && isFlatArray(value)) ||
2649
2878
  ((utils$1.isFileList(value) || utils$1.endsWith(key, '[]')) && (arr = utils$1.toArray(value)))
@@ -2676,8 +2905,6 @@ function toFormData(obj, formData, options) {
2676
2905
  return false;
2677
2906
  }
2678
2907
 
2679
- const stack = [];
2680
-
2681
2908
  const exposedHelpers = Object.assign(predicates, {
2682
2909
  defaultVisitor,
2683
2910
  convertValue,
@@ -2687,15 +2914,10 @@ function toFormData(obj, formData, options) {
2687
2914
  function build(value, path, depth = 0) {
2688
2915
  if (utils$1.isUndefined(value)) return;
2689
2916
 
2690
- if (depth > maxDepth) {
2691
- throw new AxiosError(
2692
- 'Object is too deeply nested (' + depth + ' levels). Max depth: ' + maxDepth,
2693
- AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
2694
- );
2695
- }
2917
+ throwIfMaxDepthExceeded(depth);
2696
2918
 
2697
2919
  if (stack.indexOf(value) !== -1) {
2698
- throw Error('Circular reference detected in ' + path.join('.'));
2920
+ throw new Error('Circular reference detected in ' + path.join('.'));
2699
2921
  }
2700
2922
 
2701
2923
  stack.push(value);
@@ -2766,9 +2988,7 @@ prototype.append = function append(name, value) {
2766
2988
 
2767
2989
  prototype.toString = function toString(encoder) {
2768
2990
  const _encode = encoder
2769
- ? function (value) {
2770
- return encoder.call(this, value, encode$1);
2771
- }
2991
+ ? (value) => encoder.call(this, value, encode$1)
2772
2992
  : encode$1;
2773
2993
 
2774
2994
  return this._pairs
@@ -2807,8 +3027,7 @@ function buildURL(url, params, options) {
2807
3027
  if (!params) {
2808
3028
  return url;
2809
3029
  }
2810
-
2811
- const _encode = (options && options.encode) || encode;
3030
+ url = url || '';
2812
3031
 
2813
3032
  const _options = utils$1.isFunction(options)
2814
3033
  ? {
@@ -2816,7 +3035,11 @@ function buildURL(url, params, options) {
2816
3035
  }
2817
3036
  : options;
2818
3037
 
2819
- const serializeFn = _options && _options.serialize;
3038
+ // Read serializer options pollution-safely: own properties and methods on a
3039
+ // class/template prototype are honored, but values injected onto a polluted
3040
+ // Object.prototype are ignored.
3041
+ const _encode = utils$1.getSafeProp(_options, 'encode') || encode;
3042
+ const serializeFn = utils$1.getSafeProp(_options, 'serialize');
2820
3043
 
2821
3044
  let serializedParams;
2822
3045
 
@@ -2912,6 +3135,8 @@ var transitionalDefaults = {
2912
3135
  forcedJSONParsing: true,
2913
3136
  clarifyTimeoutError: false,
2914
3137
  legacyInterceptorReqResOrdering: true,
3138
+ advertiseZstdAcceptEncoding: false,
3139
+ validateStatusUndefinedResolves: true,
2915
3140
  };
2916
3141
 
2917
3142
  var URLSearchParams$1 = typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams;
@@ -3003,6 +3228,17 @@ function toURLEncodedForm(data, options) {
3003
3228
  });
3004
3229
  }
3005
3230
 
3231
+ const MAX_DEPTH = DEFAULT_FORM_DATA_MAX_DEPTH;
3232
+
3233
+ function throwIfDepthExceeded(index) {
3234
+ if (index > MAX_DEPTH) {
3235
+ throw new AxiosError(
3236
+ 'FormData field is too deeply nested (' + index + ' levels). Max depth: ' + MAX_DEPTH,
3237
+ AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
3238
+ );
3239
+ }
3240
+ }
3241
+
3006
3242
  /**
3007
3243
  * It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
3008
3244
  *
@@ -3015,9 +3251,16 @@ function parsePropPath(name) {
3015
3251
  // foo.x.y.z
3016
3252
  // foo-x-y-z
3017
3253
  // foo x y z
3018
- return utils$1.matchAll(/\w+|\[(\w*)]/g, name).map((match) => {
3019
- return match[0] === '[]' ? '' : match[1] || match[0];
3020
- });
3254
+ const path = [];
3255
+ const pattern = /\w+|\[(\w*)]/g;
3256
+ let match;
3257
+
3258
+ while ((match = pattern.exec(name)) !== null) {
3259
+ throwIfDepthExceeded(path.length);
3260
+ path.push(match[0] === '[]' ? '' : match[1] || match[0]);
3261
+ }
3262
+
3263
+ return path;
3021
3264
  }
3022
3265
 
3023
3266
  /**
@@ -3049,6 +3292,8 @@ function arrayToObject(arr) {
3049
3292
  */
3050
3293
  function formDataToJSON(formData) {
3051
3294
  function buildPath(path, value, target, index) {
3295
+ throwIfDepthExceeded(index);
3296
+
3052
3297
  let name = path[index++];
3053
3298
 
3054
3299
  if (name === '__proto__') return true;
@@ -3534,7 +3779,11 @@ var cookies = platform.hasStandardBrowserEnv
3534
3779
  const cookie = cookies[i].replace(/^\s+/, '');
3535
3780
  const eq = cookie.indexOf('=');
3536
3781
  if (eq !== -1 && cookie.slice(0, eq) === name) {
3537
- return decodeURIComponent(cookie.slice(eq + 1));
3782
+ try {
3783
+ return decodeURIComponent(cookie.slice(eq + 1));
3784
+ } catch (e) {
3785
+ return cookie.slice(eq + 1);
3786
+ }
3538
3787
  }
3539
3788
  }
3540
3789
  return null;
@@ -3585,6 +3834,31 @@ function combineURLs(baseURL, relativeURL) {
3585
3834
  : baseURL;
3586
3835
  }
3587
3836
 
3837
+ const malformedHttpProtocol = /^https?:(?!\/\/)/i;
3838
+ const httpProtocolControlCharacters = /[\t\n\r]/g;
3839
+
3840
+ function stripLeadingC0ControlOrSpace(url) {
3841
+ let i = 0;
3842
+ while (i < url.length && url.charCodeAt(i) <= 0x20) {
3843
+ i++;
3844
+ }
3845
+ return url.slice(i);
3846
+ }
3847
+
3848
+ function normalizeURLForProtocolCheck(url) {
3849
+ return stripLeadingC0ControlOrSpace(url).replace(httpProtocolControlCharacters, '');
3850
+ }
3851
+
3852
+ function assertValidHttpProtocolURL(url, config) {
3853
+ if (typeof url === 'string' && malformedHttpProtocol.test(normalizeURLForProtocolCheck(url))) {
3854
+ throw new AxiosError(
3855
+ 'Invalid URL: missing "//" after protocol',
3856
+ AxiosError.ERR_INVALID_URL,
3857
+ config
3858
+ );
3859
+ }
3860
+ }
3861
+
3588
3862
  /**
3589
3863
  * Creates a new URL by combining the baseURL with the requestedURL,
3590
3864
  * only when the requestedURL is not already an absolute URL.
@@ -3595,9 +3869,11 @@ function combineURLs(baseURL, relativeURL) {
3595
3869
  *
3596
3870
  * @returns {string} The combined full path
3597
3871
  */
3598
- function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
3872
+ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls, config) {
3873
+ assertValidHttpProtocolURL(requestedURL, config);
3599
3874
  let isRelativeUrl = !isAbsoluteURL(requestedURL);
3600
3875
  if (baseURL && (isRelativeUrl || allowAbsoluteUrls === false)) {
3876
+ assertValidHttpProtocolURL(baseURL, config);
3601
3877
  return combineURLs(baseURL, requestedURL);
3602
3878
  }
3603
3879
  return requestedURL;
@@ -3616,6 +3892,7 @@ const headersToObject = (thing) => (thing instanceof AxiosHeaders ? { ...thing }
3616
3892
  */
3617
3893
  function mergeConfig(config1, config2) {
3618
3894
  // eslint-disable-next-line no-param-reassign
3895
+ config1 = config1 || {};
3619
3896
  config2 = config2 || {};
3620
3897
 
3621
3898
  // Use a null-prototype object so that downstream reads such as `config.auth`
@@ -3668,6 +3945,28 @@ function mergeConfig(config1, config2) {
3668
3945
  }
3669
3946
  }
3670
3947
 
3948
+ function getMergedTransitionalOption(prop) {
3949
+ const transitional2 = utils$1.hasOwnProp(config2, 'transitional') ? config2.transitional : undefined;
3950
+
3951
+ if (!utils$1.isUndefined(transitional2)) {
3952
+ if (utils$1.isPlainObject(transitional2)) {
3953
+ if (utils$1.hasOwnProp(transitional2, prop)) {
3954
+ return transitional2[prop];
3955
+ }
3956
+ } else {
3957
+ return undefined;
3958
+ }
3959
+ }
3960
+
3961
+ const transitional1 = utils$1.hasOwnProp(config1, 'transitional') ? config1.transitional : undefined;
3962
+
3963
+ if (utils$1.isPlainObject(transitional1) && utils$1.hasOwnProp(transitional1, prop)) {
3964
+ return transitional1[prop];
3965
+ }
3966
+
3967
+ return undefined;
3968
+ }
3969
+
3671
3970
  // eslint-disable-next-line consistent-return
3672
3971
  function mergeDirectKeys(a, b, prop) {
3673
3972
  if (utils$1.hasOwnProp(config2, prop)) {
@@ -3720,6 +4019,18 @@ function mergeConfig(config1, config2) {
3720
4019
  (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
3721
4020
  });
3722
4021
 
4022
+ if (
4023
+ utils$1.hasOwnProp(config2, 'validateStatus') &&
4024
+ utils$1.isUndefined(config2.validateStatus) &&
4025
+ getMergedTransitionalOption('validateStatusUndefinedResolves') === false
4026
+ ) {
4027
+ if (utils$1.hasOwnProp(config1, 'validateStatus')) {
4028
+ config.validateStatus = getMergedValue(undefined, config1.validateStatus);
4029
+ } else {
4030
+ delete config.validateStatus;
4031
+ }
4032
+ }
4033
+
3723
4034
  return config;
3724
4035
  }
3725
4036
 
@@ -3731,7 +4042,7 @@ function setFormDataHeaders(headers, formHeaders, policy) {
3731
4042
  return;
3732
4043
  }
3733
4044
 
3734
- Object.entries(formHeaders).forEach(([key, val]) => {
4045
+ Object.entries(formHeaders || {}).forEach(([key, val]) => {
3735
4046
  if (FORM_DATA_CONTENT_HEADERS.includes(key.toLowerCase())) {
3736
4047
  headers.set(key, val);
3737
4048
  }
@@ -3746,12 +4057,12 @@ function setFormDataHeaders(headers, formHeaders, policy) {
3746
4057
  *
3747
4058
  * @returns {string} UTF-8 bytes as a Latin-1 string
3748
4059
  */
3749
- const encodeUTF8 = (str) =>
4060
+ const encodeUTF8$1 = (str) =>
3750
4061
  encodeURIComponent(str).replace(/%([0-9A-F]{2})/gi, (_, hex) =>
3751
4062
  String.fromCharCode(parseInt(hex, 16))
3752
4063
  );
3753
4064
 
3754
- var resolveConfig = (config) => {
4065
+ function resolveConfig(config) {
3755
4066
  const newConfig = mergeConfig({}, config);
3756
4067
 
3757
4068
  // Read only own properties to prevent prototype pollution gadgets
@@ -3771,23 +4082,33 @@ var resolveConfig = (config) => {
3771
4082
  newConfig.headers = headers = AxiosHeaders.from(headers);
3772
4083
 
3773
4084
  newConfig.url = buildURL(
3774
- buildFullPath(baseURL, url, allowAbsoluteUrls),
3775
- config.params,
3776
- config.paramsSerializer
4085
+ buildFullPath(baseURL, url, allowAbsoluteUrls, newConfig),
4086
+ own('params'),
4087
+ own('paramsSerializer')
3777
4088
  );
3778
4089
 
3779
4090
  // HTTP basic authentication
3780
4091
  if (auth) {
3781
- headers.set(
3782
- 'Authorization',
3783
- 'Basic ' +
3784
- btoa((auth.username || '') + ':' + (auth.password ? encodeUTF8(auth.password) : ''))
3785
- );
4092
+ const username = utils$1.getSafeProp(auth, 'username') || '';
4093
+ const password = utils$1.getSafeProp(auth, 'password') || '';
4094
+
4095
+ try {
4096
+ headers.set(
4097
+ 'Authorization',
4098
+ 'Basic ' + btoa(username + ':' + (password ? encodeUTF8$1(password) : ''))
4099
+ );
4100
+ } catch (e) {
4101
+ throw AxiosError.from(e, AxiosError.ERR_BAD_OPTION_VALUE, config);
4102
+ }
3786
4103
  }
3787
4104
 
3788
4105
  if (utils$1.isFormData(data)) {
3789
- if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
3790
- headers.setContentType(undefined); // browser handles it
4106
+ if (
4107
+ platform.hasStandardBrowserEnv ||
4108
+ platform.hasStandardBrowserWebWorkerEnv ||
4109
+ utils$1.isReactNative(data)
4110
+ ) {
4111
+ headers.setContentType(undefined); // browser/web worker/RN handles it
3791
4112
  } else if (utils$1.isFunction(data.getHeaders)) {
3792
4113
  // Node.js FormData (like form-data package)
3793
4114
  setFormDataHeaders(headers, data.getHeaders(), own('formDataHeaderPolicy'));
@@ -3819,7 +4140,7 @@ var resolveConfig = (config) => {
3819
4140
  }
3820
4141
 
3821
4142
  return newConfig;
3822
- };
4143
+ }
3823
4144
 
3824
4145
  const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
3825
4146
 
@@ -4029,6 +4350,7 @@ var xhrAdapter = isXHRAdapterSupported &&
4029
4350
  config
4030
4351
  )
4031
4352
  );
4353
+ done();
4032
4354
  return;
4033
4355
  }
4034
4356
 
@@ -4080,7 +4402,7 @@ const composeSignals = (signals, timeout) => {
4080
4402
  signals = null;
4081
4403
  };
4082
4404
 
4083
- signals.forEach((signal) => signal.addEventListener('abort', onabort));
4405
+ signals.forEach((signal) => signal.addEventListener('abort', onabort, { once: true }));
4084
4406
 
4085
4407
  const { signal } = controller;
4086
4408
 
@@ -4183,11 +4505,19 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
4183
4505
  * Estimate decoded byte length of a data:// URL *without* allocating large buffers.
4184
4506
  * - For base64: compute exact decoded size using length and padding;
4185
4507
  * handle %XX at the character-count level (no string allocation).
4186
- * - For non-base64: use UTF-8 byteLength of the encoded body as a safe upper bound.
4508
+ * - For non-base64: compute the exact percent-decoded UTF-8 byte length.
4187
4509
  *
4188
4510
  * @param {string} url
4189
4511
  * @returns {number}
4190
4512
  */
4513
+ const isHexDigit = (charCode) =>
4514
+ (charCode >= 48 && charCode <= 57) ||
4515
+ (charCode >= 65 && charCode <= 70) ||
4516
+ (charCode >= 97 && charCode <= 102);
4517
+
4518
+ const isPercentEncodedByte = (str, i, len) =>
4519
+ i + 2 < len && isHexDigit(str.charCodeAt(i + 1)) && isHexDigit(str.charCodeAt(i + 2));
4520
+
4191
4521
  function estimateDataURLDecodedBytes(url) {
4192
4522
  if (!url || typeof url !== 'string') return 0;
4193
4523
  if (!url.startsWith('data:')) return 0;
@@ -4207,9 +4537,7 @@ function estimateDataURLDecodedBytes(url) {
4207
4537
  if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {
4208
4538
  const a = body.charCodeAt(i + 1);
4209
4539
  const b = body.charCodeAt(i + 2);
4210
- const isHex =
4211
- ((a >= 48 && a <= 57) || (a >= 65 && a <= 70) || (a >= 97 && a <= 102)) &&
4212
- ((b >= 48 && b <= 57) || (b >= 65 && b <= 70) || (b >= 97 && b <= 102));
4540
+ const isHex = isHexDigit(a) && isHexDigit(b);
4213
4541
 
4214
4542
  if (isHex) {
4215
4543
  effectiveLen -= 2;
@@ -4250,18 +4578,17 @@ function estimateDataURLDecodedBytes(url) {
4250
4578
  return bytes > 0 ? bytes : 0;
4251
4579
  }
4252
4580
 
4253
- if (typeof Buffer !== 'undefined' && typeof Buffer.byteLength === 'function') {
4254
- return Buffer.byteLength(body, 'utf8');
4255
- }
4256
-
4257
4581
  // Compute UTF-8 byte length directly from UTF-16 code units without allocating
4258
4582
  // a byte buffer (TextEncoder.encode would defeat the DoS guard on large bodies).
4259
- // Using body.length here would undercount non-ASCII (e.g. '€' is 1 code unit
4260
- // but 3 UTF-8 bytes).
4583
+ // Valid %XX triplets count as one decoded byte; this matches the bytes that
4584
+ // decodeURIComponent(body) would produce before Buffer re-encodes the string.
4261
4585
  let bytes = 0;
4262
4586
  for (let i = 0, len = body.length; i < len; i++) {
4263
4587
  const c = body.charCodeAt(i);
4264
- if (c < 0x80) {
4588
+ if (c === 37 /* '%' */ && isPercentEncodedByte(body, i, len)) {
4589
+ bytes += 1;
4590
+ i += 2;
4591
+ } else if (c < 0x80) {
4265
4592
  bytes += 1;
4266
4593
  } else if (c < 0x800) {
4267
4594
  bytes += 2;
@@ -4280,12 +4607,41 @@ function estimateDataURLDecodedBytes(url) {
4280
4607
  return bytes;
4281
4608
  }
4282
4609
 
4283
- const VERSION = "1.16.1";
4610
+ const VERSION = "1.18.1";
4284
4611
 
4285
4612
  const DEFAULT_CHUNK_SIZE = 64 * 1024;
4286
4613
 
4287
4614
  const { isFunction } = utils$1;
4288
4615
 
4616
+ /**
4617
+ * Encode a UTF-8 string to a Latin-1 byte string for use with btoa().
4618
+ * This is a modern replacement for the deprecated unescape(encodeURIComponent(str)) pattern.
4619
+ *
4620
+ * @param {string} str The string to encode
4621
+ *
4622
+ * @returns {string} UTF-8 bytes as a Latin-1 string
4623
+ */
4624
+ const encodeUTF8 = (str) =>
4625
+ encodeURIComponent(str).replace(/%([0-9A-F]{2})/gi, (_, hex) =>
4626
+ String.fromCharCode(parseInt(hex, 16))
4627
+ );
4628
+
4629
+ // Node's WHATWG URL parser returns `username` and `password` percent-encoded.
4630
+ // Decode before composing the `auth` option so credentials such as
4631
+ // `my%40email.com:pass` are sent as `my@email.com:pass`. Falls back to the
4632
+ // original value for malformed input so a bad encoding never throws.
4633
+ const decodeURIComponentSafe = (value) => {
4634
+ if (!utils$1.isString(value)) {
4635
+ return value;
4636
+ }
4637
+
4638
+ try {
4639
+ return decodeURIComponent(value);
4640
+ } catch (error) {
4641
+ return value;
4642
+ }
4643
+ };
4644
+
4289
4645
  const test = (fn, ...args) => {
4290
4646
  try {
4291
4647
  return !!fn(...args);
@@ -4294,6 +4650,15 @@ const test = (fn, ...args) => {
4294
4650
  }
4295
4651
  };
4296
4652
 
4653
+ const maybeWithAuthCredentials = (url) => {
4654
+ const protocolIndex = url.indexOf('://');
4655
+ let urlToCheck = url;
4656
+ if (protocolIndex !== -1) {
4657
+ urlToCheck = urlToCheck.slice(protocolIndex + 3);
4658
+ }
4659
+ return urlToCheck.includes('@') || urlToCheck.includes(':');
4660
+ };
4661
+
4297
4662
  const factory = (env) => {
4298
4663
  const globalObject =
4299
4664
  utils$1.global !== undefined && utils$1.global !== null
@@ -4441,6 +4806,7 @@ const factory = (env) => {
4441
4806
 
4442
4807
  const hasMaxContentLength = utils$1.isNumber(maxContentLength) && maxContentLength > -1;
4443
4808
  const hasMaxBodyLength = utils$1.isNumber(maxBodyLength) && maxBodyLength > -1;
4809
+ const own = (key) => (utils$1.hasOwnProp(config, key) ? config[key] : undefined);
4444
4810
 
4445
4811
  let _fetch = envFetch || fetch;
4446
4812
 
@@ -4462,7 +4828,61 @@ const factory = (env) => {
4462
4828
 
4463
4829
  let requestContentLength;
4464
4830
 
4831
+ // AxiosError we raise while the request body is being streamed. Captured
4832
+ // by identity so the catch block can surface it directly, regardless of
4833
+ // how the runtime wraps the resulting fetch rejection (undici exposes it
4834
+ // as `err.cause`; some browsers drop the original error entirely).
4835
+ let pendingBodyError = null;
4836
+
4837
+ const maxBodyLengthError = () =>
4838
+ new AxiosError(
4839
+ 'Request body larger than maxBodyLength limit',
4840
+ AxiosError.ERR_BAD_REQUEST,
4841
+ config,
4842
+ request
4843
+ );
4844
+
4465
4845
  try {
4846
+ // HTTP basic authentication
4847
+ let auth = undefined;
4848
+ const configAuth = own('auth');
4849
+
4850
+ if (configAuth) {
4851
+ const username = utils$1.getSafeProp(configAuth, 'username') || '';
4852
+ const password = utils$1.getSafeProp(configAuth, 'password') || '';
4853
+ auth = {
4854
+ username,
4855
+ password
4856
+ };
4857
+ }
4858
+
4859
+ if (maybeWithAuthCredentials(url)) {
4860
+ const parsedURL = new URL(url, platform.origin);
4861
+
4862
+ if (!auth && (parsedURL.username || parsedURL.password)) {
4863
+ const urlUsername = decodeURIComponentSafe(parsedURL.username);
4864
+ const urlPassword = decodeURIComponentSafe(parsedURL.password);
4865
+ auth = {
4866
+ username: urlUsername,
4867
+ password: urlPassword
4868
+ };
4869
+ }
4870
+
4871
+ if (parsedURL.username || parsedURL.password) {
4872
+ parsedURL.username = '';
4873
+ parsedURL.password = '';
4874
+ url = parsedURL.href;
4875
+ }
4876
+ }
4877
+
4878
+ if (auth) {
4879
+ headers.delete('authorization');
4880
+ headers.set(
4881
+ 'Authorization',
4882
+ 'Basic ' + btoa(encodeUTF8((auth.username || '') + ':' + (auth.password || '')))
4883
+ );
4884
+ }
4885
+
4466
4886
  // Enforce maxContentLength for data: URLs up-front so we never materialize
4467
4887
  // an oversized payload. The HTTP adapter applies the same check (see http.js
4468
4888
  // "if (protocol === 'data:')" branch).
@@ -4478,53 +4898,96 @@ const factory = (env) => {
4478
4898
  }
4479
4899
  }
4480
4900
 
4481
- // Enforce maxBodyLength against the outbound request body before dispatch.
4482
- // Mirrors http.js behavior (ERR_BAD_REQUEST / 'Request body larger than
4483
- // maxBodyLength limit'). Skip when the body length cannot be determined
4484
- // (e.g. a live ReadableStream supplied by the caller).
4901
+ // Enforce maxBodyLength against known-size bodies before dispatch using
4902
+ // the body's *actual* size never a caller-declared Content-Length,
4903
+ // which could under-report to slip an oversized body past the check.
4904
+ // Unknown-size streams return undefined here and are counted per-chunk
4905
+ // below as fetch consumes them.
4485
4906
  if (hasMaxBodyLength && method !== 'get' && method !== 'head') {
4486
- const outboundLength = await resolveBodyLength(headers, data);
4487
- if (
4488
- typeof outboundLength === 'number' &&
4489
- isFinite(outboundLength) &&
4490
- outboundLength > maxBodyLength
4491
- ) {
4492
- throw new AxiosError(
4493
- 'Request body larger than maxBodyLength limit',
4494
- AxiosError.ERR_BAD_REQUEST,
4495
- config,
4496
- request
4497
- );
4907
+ const outboundLength = await getBodyLength(data);
4908
+ if (typeof outboundLength === 'number' && isFinite(outboundLength)) {
4909
+ requestContentLength = outboundLength;
4910
+ if (outboundLength > maxBodyLength) {
4911
+ throw maxBodyLengthError();
4912
+ }
4498
4913
  }
4499
4914
  }
4500
4915
 
4916
+ // A streamed body under maxBodyLength must be counted as fetch consumes
4917
+ // it; its size is never trusted from a caller-declared Content-Length.
4918
+ const mustEnforceStreamBody =
4919
+ hasMaxBodyLength && (utils$1.isReadableStream(data) || utils$1.isStream(data));
4920
+
4921
+ const trackRequestStream = (stream, onProgress, flush) =>
4922
+ trackStream(
4923
+ stream,
4924
+ DEFAULT_CHUNK_SIZE,
4925
+ (loadedBytes) => {
4926
+ if (hasMaxBodyLength && loadedBytes > maxBodyLength) {
4927
+ throw (pendingBodyError = maxBodyLengthError());
4928
+ }
4929
+ onProgress && onProgress(loadedBytes);
4930
+ },
4931
+ flush
4932
+ );
4933
+
4501
4934
  if (
4502
- onUploadProgress &&
4503
4935
  supportsRequestStream &&
4504
4936
  method !== 'get' &&
4505
4937
  method !== 'head' &&
4506
- (requestContentLength = await resolveBodyLength(headers, data)) !== 0
4938
+ (onUploadProgress || mustEnforceStreamBody)
4507
4939
  ) {
4508
- let _request = new Request(url, {
4509
- method: 'POST',
4510
- body: data,
4511
- duplex: 'half',
4512
- });
4940
+ requestContentLength =
4941
+ requestContentLength == null ? await resolveBodyLength(headers, data) : requestContentLength;
4942
+
4943
+ // A declared length of 0 is only trusted to skip the wrap when we are
4944
+ // not enforcing a stream limit (which must not rely on that header).
4945
+ if (requestContentLength !== 0 || mustEnforceStreamBody) {
4946
+ let _request = new Request(url, {
4947
+ method: 'POST',
4948
+ body: data,
4949
+ duplex: 'half',
4950
+ });
4513
4951
 
4514
- let contentTypeHeader;
4952
+ let contentTypeHeader;
4515
4953
 
4516
- if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
4517
- headers.setContentType(contentTypeHeader);
4518
- }
4954
+ if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
4955
+ headers.setContentType(contentTypeHeader);
4956
+ }
4519
4957
 
4520
- if (_request.body) {
4521
- const [onProgress, flush] = progressEventDecorator(
4522
- requestContentLength,
4523
- progressEventReducer(asyncDecorator(onUploadProgress))
4524
- );
4958
+ if (_request.body) {
4959
+ const [onProgress, flush] =
4960
+ (onUploadProgress &&
4961
+ progressEventDecorator(
4962
+ requestContentLength,
4963
+ progressEventReducer(asyncDecorator(onUploadProgress))
4964
+ )) ||
4965
+ [];
4525
4966
 
4526
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
4967
+ data = trackRequestStream(_request.body, onProgress, flush);
4968
+ }
4527
4969
  }
4970
+ } else if (
4971
+ mustEnforceStreamBody &&
4972
+ !isRequestSupported &&
4973
+ isReadableStreamSupported &&
4974
+ method !== 'get' &&
4975
+ method !== 'head'
4976
+ ) {
4977
+ data = trackRequestStream(data);
4978
+ } else if (
4979
+ mustEnforceStreamBody &&
4980
+ isRequestSupported &&
4981
+ !supportsRequestStream &&
4982
+ method !== 'get' &&
4983
+ method !== 'head'
4984
+ ) {
4985
+ throw new AxiosError(
4986
+ 'Stream request bodies are not supported by the current fetch implementation',
4987
+ AxiosError.ERR_NOT_SUPPORT,
4988
+ config,
4989
+ request
4990
+ );
4528
4991
  }
4529
4992
 
4530
4993
  if (!utils$1.isString(withCredentials)) {
@@ -4567,10 +5030,12 @@ const factory = (env) => {
4567
5030
  ? _fetch(request, fetchOptions)
4568
5031
  : _fetch(url, resolvedOptions));
4569
5032
 
5033
+ const responseHeaders = AxiosHeaders.from(response.headers);
5034
+
4570
5035
  // Cheap pre-check: if the server honestly declares a content-length that
4571
5036
  // already exceeds the cap, reject before we start streaming.
4572
5037
  if (hasMaxContentLength) {
4573
- const declaredLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
5038
+ const declaredLength = utils$1.toFiniteNumber(responseHeaders.getContentLength());
4574
5039
  if (declaredLength != null && declaredLength > maxContentLength) {
4575
5040
  throw new AxiosError(
4576
5041
  'maxContentLength size of ' + maxContentLength + ' exceeded',
@@ -4595,7 +5060,7 @@ const factory = (env) => {
4595
5060
  options[prop] = response[prop];
4596
5061
  });
4597
5062
 
4598
- const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
5063
+ const responseContentLength = utils$1.toFiniteNumber(responseHeaders.getContentLength());
4599
5064
 
4600
5065
  const [onProgress, flush] =
4601
5066
  (onDownloadProgress &&
@@ -4686,23 +5151,55 @@ const factory = (env) => {
4686
5151
  const canceledError = composedSignal.reason;
4687
5152
  canceledError.config = config;
4688
5153
  request && (canceledError.request = request);
4689
- err !== canceledError && (canceledError.cause = err);
5154
+ if (err !== canceledError) {
5155
+ // Non-enumerable to match native Error `cause` semantics so loggers
5156
+ // don't recurse into circular fetch internals (see #7205).
5157
+ Object.defineProperty(canceledError, 'cause', {
5158
+ __proto__: null,
5159
+ value: err,
5160
+ writable: true,
5161
+ enumerable: false,
5162
+ configurable: true,
5163
+ });
5164
+ }
4690
5165
  throw canceledError;
4691
5166
  }
4692
5167
 
5168
+ // Surface a maxBodyLength violation we raised while the request body was
5169
+ // being streamed. Matching by identity (rather than reading
5170
+ // `err.cause.isAxiosError`) keeps the error deterministic across runtimes
5171
+ // and avoids both prototype-pollution reads and mis-attributing a foreign
5172
+ // AxiosError that merely happened to land in `err.cause`.
5173
+ if (pendingBodyError) {
5174
+ request && !pendingBodyError.request && (pendingBodyError.request = request);
5175
+ throw pendingBodyError;
5176
+ }
5177
+
5178
+ // Re-throw AxiosErrors we raised synchronously (data: URL / content-length
5179
+ // pre-checks, response size enforcement) without re-wrapping them.
5180
+ if (err instanceof AxiosError) {
5181
+ request && !err.request && (err.request = request);
5182
+ throw err;
5183
+ }
5184
+
4693
5185
  if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
4694
- throw Object.assign(
4695
- new AxiosError(
4696
- 'Network Error',
4697
- AxiosError.ERR_NETWORK,
4698
- config,
4699
- request,
4700
- err && err.response
4701
- ),
4702
- {
4703
- cause: err.cause || err,
4704
- }
5186
+ const networkError = new AxiosError(
5187
+ 'Network Error',
5188
+ AxiosError.ERR_NETWORK,
5189
+ config,
5190
+ request,
5191
+ err && err.response
4705
5192
  );
5193
+ // Non-enumerable to match native Error `cause` semantics so loggers
5194
+ // don't recurse into circular fetch internals (see #7205).
5195
+ Object.defineProperty(networkError, 'cause', {
5196
+ __proto__: null,
5197
+ value: err.cause || err,
5198
+ writable: true,
5199
+ enumerable: false,
5200
+ configurable: true,
5201
+ });
5202
+ throw networkError;
4706
5203
  }
4707
5204
 
4708
5205
  throw AxiosError.from(err, err && err.code, config, request, err && err.response);
@@ -4840,7 +5337,7 @@ function getAdapter(adapters, config) {
4840
5337
 
4841
5338
  throw new AxiosError(
4842
5339
  `There is no suitable adapter to dispatch the request ` + s,
4843
- 'ERR_NOT_SUPPORT'
5340
+ AxiosError.ERR_NOT_SUPPORT
4844
5341
  );
4845
5342
  }
4846
5343
 
@@ -5021,7 +5518,7 @@ validators$1.spelling = function spelling(correctSpelling) {
5021
5518
  */
5022
5519
 
5023
5520
  function assertOptions(options, schema, allowUnknown) {
5024
- if (typeof options !== 'object') {
5521
+ if (typeof options !== 'object' || options === null) {
5025
5522
  throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE);
5026
5523
  }
5027
5524
  const keys = Object.keys(options);
@@ -5144,6 +5641,8 @@ class Axios {
5144
5641
  forcedJSONParsing: validators.transitional(validators.boolean),
5145
5642
  clarifyTimeoutError: validators.transitional(validators.boolean),
5146
5643
  legacyInterceptorReqResOrdering: validators.transitional(validators.boolean),
5644
+ advertiseZstdAcceptEncoding: validators.transitional(validators.boolean),
5645
+ validateStatusUndefinedResolves: validators.transitional(validators.boolean),
5147
5646
  },
5148
5647
  false
5149
5648
  );
@@ -5273,7 +5772,7 @@ class Axios {
5273
5772
 
5274
5773
  getUri(config) {
5275
5774
  config = mergeConfig(this.defaults, config);
5276
- const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
5775
+ const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls, config);
5277
5776
  return buildURL(fullPath, config.params, config.paramsSerializer);
5278
5777
  }
5279
5778
  }
@@ -5286,7 +5785,7 @@ utils$1.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoDa
5286
5785
  mergeConfig(config || {}, {
5287
5786
  method,
5288
5787
  url,
5289
- data: (config || {}).data,
5788
+ data: config && utils$1.hasOwnProp(config, 'data') ? config.data : undefined,
5290
5789
  })
5291
5790
  );
5292
5791
  };