axios 1.12.1 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,13 @@
1
- /*! Axios v1.12.1 Copyright (c) 2025 Matt Zabriskie and contributors */
1
+ /*! Axios v1.13.0 Copyright (c) 2025 Matt Zabriskie and contributors */
2
2
  'use strict';
3
3
 
4
+ /**
5
+ * Create a bound version of a function with a specified `this` context
6
+ *
7
+ * @param {Function} fn - The function to bind
8
+ * @param {*} thisArg - The value to be passed as the `this` parameter
9
+ * @returns {Function} A new function that will call the original function with the specified `this` context
10
+ */
4
11
  function bind(fn, thisArg) {
5
12
  return function wrap() {
6
13
  return fn.apply(thisArg, arguments);
@@ -356,10 +363,8 @@ function merge(/* obj1, obj2, obj3, ... */) {
356
363
  result[targetKey] = merge({}, val);
357
364
  } else if (isArray(val)) {
358
365
  result[targetKey] = val.slice();
359
- } else {
360
- if (!skipUndefined || !isUndefined(val)) {
361
- result[targetKey] = val;
362
- }
366
+ } else if (!skipUndefined || !isUndefined(val)) {
367
+ result[targetKey] = val;
363
368
  }
364
369
  };
365
370
 
@@ -1255,7 +1260,7 @@ class InterceptorManager {
1255
1260
  *
1256
1261
  * @param {Number} id The ID that was returned by `use`
1257
1262
  *
1258
- * @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
1263
+ * @returns {void}
1259
1264
  */
1260
1265
  eject(id) {
1261
1266
  if (this.handlers[id]) {
@@ -2221,27 +2226,38 @@ var cookies = platform.hasStandardBrowserEnv ?
2221
2226
 
2222
2227
  // Standard browser envs support document.cookie
2223
2228
  {
2224
- write(name, value, expires, path, domain, secure) {
2225
- const cookie = [name + '=' + encodeURIComponent(value)];
2226
-
2227
- utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
2229
+ write(name, value, expires, path, domain, secure, sameSite) {
2230
+ if (typeof document === 'undefined') return;
2228
2231
 
2229
- utils$1.isString(path) && cookie.push('path=' + path);
2232
+ const cookie = [`${name}=${encodeURIComponent(value)}`];
2230
2233
 
2231
- utils$1.isString(domain) && cookie.push('domain=' + domain);
2232
-
2233
- secure === true && cookie.push('secure');
2234
+ if (utils$1.isNumber(expires)) {
2235
+ cookie.push(`expires=${new Date(expires).toUTCString()}`);
2236
+ }
2237
+ if (utils$1.isString(path)) {
2238
+ cookie.push(`path=${path}`);
2239
+ }
2240
+ if (utils$1.isString(domain)) {
2241
+ cookie.push(`domain=${domain}`);
2242
+ }
2243
+ if (secure === true) {
2244
+ cookie.push('secure');
2245
+ }
2246
+ if (utils$1.isString(sameSite)) {
2247
+ cookie.push(`SameSite=${sameSite}`);
2248
+ }
2234
2249
 
2235
2250
  document.cookie = cookie.join('; ');
2236
2251
  },
2237
2252
 
2238
2253
  read(name) {
2239
- const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
2240
- return (match ? decodeURIComponent(match[3]) : null);
2254
+ if (typeof document === 'undefined') return null;
2255
+ const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
2256
+ return match ? decodeURIComponent(match[1]) : null;
2241
2257
  },
2242
2258
 
2243
2259
  remove(name) {
2244
- this.write(name, '', Date.now() - 86400000);
2260
+ this.write(name, '', Date.now() - 86400000, '/');
2245
2261
  }
2246
2262
  }
2247
2263
 
@@ -2330,11 +2346,11 @@ function mergeConfig(config1, config2) {
2330
2346
  }
2331
2347
 
2332
2348
  // eslint-disable-next-line consistent-return
2333
- function mergeDeepProperties(a, b, prop , caseless) {
2349
+ function mergeDeepProperties(a, b, prop, caseless) {
2334
2350
  if (!utils$1.isUndefined(b)) {
2335
- return getMergedValue(a, b, prop , caseless);
2351
+ return getMergedValue(a, b, prop, caseless);
2336
2352
  } else if (!utils$1.isUndefined(a)) {
2337
- return getMergedValue(undefined, a, prop , caseless);
2353
+ return getMergedValue(undefined, a, prop, caseless);
2338
2354
  }
2339
2355
  }
2340
2356
 
@@ -2392,7 +2408,7 @@ function mergeConfig(config1, config2) {
2392
2408
  socketPath: defaultToConfig2,
2393
2409
  responseEncoding: defaultToConfig2,
2394
2410
  validateStatus: mergeDirectKeys,
2395
- headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
2411
+ headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
2396
2412
  };
2397
2413
 
2398
2414
  utils$1.forEach(Object.keys({...config1, ...config2}), function computeConfigValue(prop) {
@@ -2782,9 +2798,9 @@ const DEFAULT_CHUNK_SIZE = 64 * 1024;
2782
2798
 
2783
2799
  const {isFunction} = utils$1;
2784
2800
 
2785
- const globalFetchAPI = (({fetch, Request, Response}) => ({
2786
- fetch, Request, Response
2787
- }))(utils$1.global);
2801
+ const globalFetchAPI = (({Request, Response}) => ({
2802
+ Request, Response
2803
+ }))(utils$1.global);
2788
2804
 
2789
2805
  const {
2790
2806
  ReadableStream: ReadableStream$1, TextEncoder
@@ -2800,8 +2816,12 @@ const test = (fn, ...args) => {
2800
2816
  };
2801
2817
 
2802
2818
  const factory = (env) => {
2803
- const {fetch, Request, Response} = Object.assign({}, globalFetchAPI, env);
2804
- const isFetchSupported = isFunction(fetch);
2819
+ env = utils$1.merge.call({
2820
+ skipUndefined: true
2821
+ }, globalFetchAPI, env);
2822
+
2823
+ const {fetch: envFetch, Request, Response} = env;
2824
+ const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === 'function';
2805
2825
  const isRequestSupported = isFunction(Request);
2806
2826
  const isResponseSupported = isFunction(Response);
2807
2827
 
@@ -2904,6 +2924,8 @@ const factory = (env) => {
2904
2924
  fetchOptions
2905
2925
  } = resolveConfig(config);
2906
2926
 
2927
+ let _fetch = envFetch || fetch;
2928
+
2907
2929
  responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2908
2930
 
2909
2931
  let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
@@ -2963,7 +2985,7 @@ const factory = (env) => {
2963
2985
 
2964
2986
  request = isRequestSupported && new Request(url, resolvedOptions);
2965
2987
 
2966
- let response = await (isRequestSupported ? fetch(request, fetchOptions) : fetch(url, resolvedOptions));
2988
+ let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions));
2967
2989
 
2968
2990
  const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
2969
2991
 
@@ -3026,12 +3048,8 @@ const factory = (env) => {
3026
3048
  const seedCache = new Map();
3027
3049
 
3028
3050
  const getFetch = (config) => {
3029
- let env = utils$1.merge.call({
3030
- skipUndefined: true
3031
- }, globalFetchAPI, config ? config.env : null);
3032
-
3051
+ let env = (config && config.env) || {};
3033
3052
  const {fetch, Request, Response} = env;
3034
-
3035
3053
  const seeds = [
3036
3054
  Request, Response, fetch
3037
3055
  ];
@@ -3053,6 +3071,15 @@ const getFetch = (config) => {
3053
3071
 
3054
3072
  getFetch();
3055
3073
 
3074
+ /**
3075
+ * Known adapters mapping.
3076
+ * Provides environment-specific adapters for Axios:
3077
+ * - `http` for Node.js
3078
+ * - `xhr` for browsers
3079
+ * - `fetch` for fetch API-based requests
3080
+ *
3081
+ * @type {Object<string, Function|Object>}
3082
+ */
3056
3083
  const knownAdapters = {
3057
3084
  http: httpAdapter,
3058
3085
  xhr: xhrAdapter,
@@ -3061,71 +3088,107 @@ const knownAdapters = {
3061
3088
  }
3062
3089
  };
3063
3090
 
3091
+ // Assign adapter names for easier debugging and identification
3064
3092
  utils$1.forEach(knownAdapters, (fn, value) => {
3065
3093
  if (fn) {
3066
3094
  try {
3067
- Object.defineProperty(fn, 'name', {value});
3095
+ Object.defineProperty(fn, 'name', { value });
3068
3096
  } catch (e) {
3069
3097
  // eslint-disable-next-line no-empty
3070
3098
  }
3071
- Object.defineProperty(fn, 'adapterName', {value});
3099
+ Object.defineProperty(fn, 'adapterName', { value });
3072
3100
  }
3073
3101
  });
3074
3102
 
3103
+ /**
3104
+ * Render a rejection reason string for unknown or unsupported adapters
3105
+ *
3106
+ * @param {string} reason
3107
+ * @returns {string}
3108
+ */
3075
3109
  const renderReason = (reason) => `- ${reason}`;
3076
3110
 
3111
+ /**
3112
+ * Check if the adapter is resolved (function, null, or false)
3113
+ *
3114
+ * @param {Function|null|false} adapter
3115
+ * @returns {boolean}
3116
+ */
3077
3117
  const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
3078
3118
 
3079
- var adapters = {
3080
- getAdapter: (adapters, config) => {
3081
- adapters = utils$1.isArray(adapters) ? adapters : [adapters];
3082
-
3083
- const {length} = adapters;
3084
- let nameOrAdapter;
3085
- let adapter;
3119
+ /**
3120
+ * Get the first suitable adapter from the provided list.
3121
+ * Tries each adapter in order until a supported one is found.
3122
+ * Throws an AxiosError if no adapter is suitable.
3123
+ *
3124
+ * @param {Array<string|Function>|string|Function} adapters - Adapter(s) by name or function.
3125
+ * @param {Object} config - Axios request configuration
3126
+ * @throws {AxiosError} If no suitable adapter is available
3127
+ * @returns {Function} The resolved adapter function
3128
+ */
3129
+ function getAdapter(adapters, config) {
3130
+ adapters = utils$1.isArray(adapters) ? adapters : [adapters];
3086
3131
 
3087
- const rejectedReasons = {};
3132
+ const { length } = adapters;
3133
+ let nameOrAdapter;
3134
+ let adapter;
3088
3135
 
3089
- for (let i = 0; i < length; i++) {
3090
- nameOrAdapter = adapters[i];
3091
- let id;
3136
+ const rejectedReasons = {};
3092
3137
 
3093
- adapter = nameOrAdapter;
3138
+ for (let i = 0; i < length; i++) {
3139
+ nameOrAdapter = adapters[i];
3140
+ let id;
3094
3141
 
3095
- if (!isResolvedHandle(nameOrAdapter)) {
3096
- adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
3142
+ adapter = nameOrAdapter;
3097
3143
 
3098
- if (adapter === undefined) {
3099
- throw new AxiosError(`Unknown adapter '${id}'`);
3100
- }
3101
- }
3144
+ if (!isResolvedHandle(nameOrAdapter)) {
3145
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
3102
3146
 
3103
- if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
3104
- break;
3147
+ if (adapter === undefined) {
3148
+ throw new AxiosError(`Unknown adapter '${id}'`);
3105
3149
  }
3150
+ }
3106
3151
 
3107
- rejectedReasons[id || '#' + i] = adapter;
3152
+ if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
3153
+ break;
3108
3154
  }
3109
3155
 
3110
- if (!adapter) {
3156
+ rejectedReasons[id || '#' + i] = adapter;
3157
+ }
3111
3158
 
3112
- const reasons = Object.entries(rejectedReasons)
3113
- .map(([id, state]) => `adapter ${id} ` +
3114
- (state === false ? 'is not supported by the environment' : 'is not available in the build')
3115
- );
3159
+ if (!adapter) {
3160
+ const reasons = Object.entries(rejectedReasons)
3161
+ .map(([id, state]) => `adapter ${id} ` +
3162
+ (state === false ? 'is not supported by the environment' : 'is not available in the build')
3163
+ );
3116
3164
 
3117
- let s = length ?
3118
- (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
3119
- 'as no adapter specified';
3165
+ let s = length ?
3166
+ (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
3167
+ 'as no adapter specified';
3120
3168
 
3121
- throw new AxiosError(
3122
- `There is no suitable adapter to dispatch the request ` + s,
3123
- 'ERR_NOT_SUPPORT'
3124
- );
3125
- }
3169
+ throw new AxiosError(
3170
+ `There is no suitable adapter to dispatch the request ` + s,
3171
+ 'ERR_NOT_SUPPORT'
3172
+ );
3173
+ }
3126
3174
 
3127
- return adapter;
3128
- },
3175
+ return adapter;
3176
+ }
3177
+
3178
+ /**
3179
+ * Exports Axios adapters and utility to resolve an adapter
3180
+ */
3181
+ var adapters = {
3182
+ /**
3183
+ * Resolve an adapter from a list of adapter names or functions.
3184
+ * @type {Function}
3185
+ */
3186
+ getAdapter,
3187
+
3188
+ /**
3189
+ * Exposes all known adapters
3190
+ * @type {Object<string, Function|Object>}
3191
+ */
3129
3192
  adapters: knownAdapters
3130
3193
  };
3131
3194
 
@@ -3202,7 +3265,7 @@ function dispatchRequest(config) {
3202
3265
  });
3203
3266
  }
3204
3267
 
3205
- const VERSION = "1.12.1";
3268
+ const VERSION = "1.13.0";
3206
3269
 
3207
3270
  const validators$1 = {};
3208
3271
 
@@ -3458,8 +3521,6 @@ class Axios {
3458
3521
 
3459
3522
  let newConfig = config;
3460
3523
 
3461
- i = 0;
3462
-
3463
3524
  while (i < len) {
3464
3525
  const onFulfilled = requestInterceptorChain[i++];
3465
3526
  const onRejected = requestInterceptorChain[i++];
@@ -3763,6 +3824,12 @@ const HttpStatusCode = {
3763
3824
  LoopDetected: 508,
3764
3825
  NotExtended: 510,
3765
3826
  NetworkAuthenticationRequired: 511,
3827
+ WebServerIsDown: 521,
3828
+ ConnectionTimedOut: 522,
3829
+ OriginIsUnreachable: 523,
3830
+ TimeoutOccurred: 524,
3831
+ SslHandshakeFailed: 525,
3832
+ InvalidSslCertificate: 526,
3766
3833
  };
3767
3834
 
3768
3835
  Object.entries(HttpStatusCode).forEach(([key, value]) => {