axios 1.7.9 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.cts CHANGED
@@ -6,7 +6,7 @@ type MethodsHeaders = Partial<{
6
6
  [Key in axios.Method as Lowercase<Key>]: AxiosHeaders;
7
7
  } & {common: AxiosHeaders}>;
8
8
 
9
- type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string, headers: RawAxiosHeaders) => boolean;
9
+ type AxiosHeaderMatcher = string | RegExp | ((this: AxiosHeaders, value: string, name: string) => boolean);
10
10
 
11
11
  type AxiosHeaderParser = (this: AxiosHeaders, value: axios.AxiosHeaderValue, header: string) => any;
12
12
 
@@ -16,6 +16,8 @@ type ContentType = axios.AxiosHeaderValue | 'text/html' | 'text/plain' | 'multip
16
16
 
17
17
  type CommonResponseHeadersList = 'Server' | 'Content-Type' | 'Content-Length' | 'Cache-Control'| 'Content-Encoding';
18
18
 
19
+ type BrowserProgressEvent = any;
20
+
19
21
  declare class AxiosHeaders {
20
22
  constructor(
21
23
  headers?: RawAxiosHeaders | AxiosHeaders | string
@@ -77,6 +79,8 @@ declare class AxiosHeaders {
77
79
  getAuthorization(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
78
80
  hasAuthorization(matcher?: AxiosHeaderMatcher): boolean;
79
81
 
82
+ getSetCookie(): string[];
83
+
80
84
  [Symbol.iterator](): IterableIterator<[string, axios.AxiosHeaderValue]>;
81
85
  }
82
86
 
@@ -96,7 +100,16 @@ declare class AxiosError<T = unknown, D = any> extends Error {
96
100
  isAxiosError: boolean;
97
101
  status?: number;
98
102
  toJSON: () => object;
99
- cause?: Error;
103
+ cause?: unknown;
104
+ event?: BrowserProgressEvent;
105
+ static from<T = unknown, D = any>(
106
+ error: Error | unknown,
107
+ code?: string,
108
+ config?: axios.InternalAxiosRequestConfig<D>,
109
+ request?: any,
110
+ response?: axios.AxiosResponse<T, D>,
111
+ customProps?: object,
112
+ ): AxiosError<T, D>;
100
113
  static readonly ERR_FR_TOO_MANY_REDIRECTS = "ERR_FR_TOO_MANY_REDIRECTS";
101
114
  static readonly ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
102
115
  static readonly ERR_BAD_OPTION = "ERR_BAD_OPTION";
@@ -342,8 +355,6 @@ declare namespace axios {
342
355
 
343
356
  type MaxDownloadRate = number;
344
357
 
345
- type BrowserProgressEvent = any;
346
-
347
358
  interface AxiosProgressEvent {
348
359
  loaded: number;
349
360
  total?: number;
@@ -359,7 +370,7 @@ declare namespace axios {
359
370
 
360
371
  type Milliseconds = number;
361
372
 
362
- type AxiosAdapterName = 'fetch' | 'xhr' | 'http' | string;
373
+ type AxiosAdapterName = 'fetch' | 'xhr' | 'http' | (string & {});
363
374
 
364
375
  type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
365
376
 
@@ -376,6 +387,7 @@ declare namespace axios {
376
387
  url?: string;
377
388
  method?: Method | string;
378
389
  baseURL?: string;
390
+ allowAbsoluteUrls?: boolean;
379
391
  transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
380
392
  transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
381
393
  headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
@@ -411,19 +423,22 @@ declare namespace axios {
411
423
  insecureHTTPParser?: boolean;
412
424
  env?: {
413
425
  FormData?: new (...args: any[]) => object;
426
+ fetch?: (input: URL | Request | string, init?: RequestInit) => Promise<Response>;
427
+ Request?: new (input: (RequestInfo | URL), init?: RequestInit) => Request;
428
+ Response?: new (body?: (BodyInit | null), init?: ResponseInit) => Response;
414
429
  };
415
430
  formSerializer?: FormSerializerOptions;
416
431
  family?: AddressFamily;
417
432
  lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: LookupAddress | LookupAddress[], family?: AddressFamily) => void) => void) |
418
433
  ((hostname: string, options: object) => Promise<[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress>);
419
434
  withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
420
- fetchOptions?: Record<string, any>;
435
+ fetchOptions?: Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'> | Record<string, any>;
421
436
  }
422
437
 
423
438
  // Alias
424
439
  type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
425
440
 
426
- interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig {
441
+ interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
427
442
  headers: AxiosRequestHeaders;
428
443
  }
429
444
 
@@ -449,11 +464,11 @@ declare namespace axios {
449
464
  headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
450
465
  }
451
466
 
452
- interface AxiosResponse<T = any, D = any> {
467
+ interface AxiosResponse<T = any, D = any, H = {}> {
453
468
  data: T;
454
469
  status: number;
455
470
  statusText: string;
456
- headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
471
+ headers: H & RawAxiosResponseHeaders | AxiosResponseHeaders;
457
472
  config: InternalAxiosRequestConfig<D>;
458
473
  request?: any;
459
474
  }
@@ -507,6 +522,7 @@ declare namespace axios {
507
522
  <T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
508
523
  <T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
509
524
 
525
+ create(config?: CreateAxiosDefaults): AxiosInstance;
510
526
  defaults: Omit<AxiosDefaults, 'headers'> & {
511
527
  headers: HeadersDefaults & {
512
528
  [key: string]: AxiosHeaderValue
@@ -525,7 +541,6 @@ declare namespace axios {
525
541
  }
526
542
 
527
543
  interface AxiosStatic extends AxiosInstance {
528
- create(config?: CreateAxiosDefaults): AxiosInstance;
529
544
  Cancel: CancelStatic;
530
545
  CancelToken: CancelTokenStatic;
531
546
  Axios: typeof Axios;
@@ -541,6 +556,7 @@ declare namespace axios {
541
556
  formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
542
557
  getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
543
558
  AxiosHeaders: typeof AxiosHeaders;
559
+ mergeConfig<D = any>(config1: AxiosRequestConfig<D>, config2: AxiosRequestConfig<D>): AxiosRequestConfig<D>;
544
560
  }
545
561
  }
546
562
 
package/index.d.ts CHANGED
@@ -74,6 +74,8 @@ export class AxiosHeaders {
74
74
  getAuthorization(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
75
75
  hasAuthorization(matcher?: AxiosHeaderMatcher): boolean;
76
76
 
77
+ getSetCookie(): string[];
78
+
77
79
  [Symbol.iterator](): IterableIterator<[string, AxiosHeaderValue]>;
78
80
  }
79
81
 
@@ -300,7 +302,7 @@ export interface AxiosProgressEvent {
300
302
 
301
303
  type Milliseconds = number;
302
304
 
303
- type AxiosAdapterName = 'fetch' | 'xhr' | 'http' | string;
305
+ type AxiosAdapterName = 'fetch' | 'xhr' | 'http' | (string & {});
304
306
 
305
307
  type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
306
308
 
@@ -317,6 +319,7 @@ export interface AxiosRequestConfig<D = any> {
317
319
  url?: string;
318
320
  method?: Method | string;
319
321
  baseURL?: string;
322
+ allowAbsoluteUrls?: boolean;
320
323
  transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
321
324
  transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
322
325
  headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
@@ -352,13 +355,17 @@ export interface AxiosRequestConfig<D = any> {
352
355
  insecureHTTPParser?: boolean;
353
356
  env?: {
354
357
  FormData?: new (...args: any[]) => object;
358
+ fetch?: (input: URL | Request | string, init?: RequestInit) => Promise<Response>;
359
+ Request?: new (input: (RequestInfo | URL), init?: RequestInit) => Request;
360
+ Response?: new (body?: (BodyInit | null), init?: ResponseInit) => Response;
355
361
  };
356
362
  formSerializer?: FormSerializerOptions;
357
363
  family?: AddressFamily;
358
364
  lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: LookupAddress | LookupAddress[], family?: AddressFamily) => void) => void) |
359
365
  ((hostname: string, options: object) => Promise<[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress>);
360
366
  withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
361
- fetchOptions?: Record<string, any>;
367
+ parseReviver?: (this: any, key: string, value: any) => any;
368
+ fetchOptions?: Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'> | Record<string, any>;
362
369
  }
363
370
 
364
371
  // Alias
@@ -390,11 +397,11 @@ export interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>
390
397
  headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
391
398
  }
392
399
 
393
- export interface AxiosResponse<T = any, D = any> {
400
+ export interface AxiosResponse<T = any, D = any, H = {}> {
394
401
  data: T;
395
402
  status: number;
396
403
  statusText: string;
397
- headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
404
+ headers: H & RawAxiosResponseHeaders | AxiosResponseHeaders;
398
405
  config: InternalAxiosRequestConfig<D>;
399
406
  request?: any;
400
407
  }
@@ -415,7 +422,8 @@ export class AxiosError<T = unknown, D = any> extends Error {
415
422
  isAxiosError: boolean;
416
423
  status?: number;
417
424
  toJSON: () => object;
418
- cause?: Error;
425
+ cause?: unknown;
426
+ event?: BrowserProgressEvent;
419
427
  static from<T = unknown, D = any>(
420
428
  error: Error | unknown,
421
429
  code?: string,
@@ -439,6 +447,7 @@ export class AxiosError<T = unknown, D = any> extends Error {
439
447
  }
440
448
 
441
449
  export class CanceledError<T> extends AxiosError<T> {
450
+ readonly name: "CanceledError";
442
451
  }
443
452
 
444
453
  export type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
@@ -511,6 +520,7 @@ export interface AxiosInstance extends Axios {
511
520
  <T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
512
521
  <T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
513
522
 
523
+ create(config?: CreateAxiosDefaults): AxiosInstance;
514
524
  defaults: Omit<AxiosDefaults, 'headers'> & {
515
525
  headers: HeadersDefaults & {
516
526
  [key: string]: AxiosHeaderValue
@@ -538,14 +548,13 @@ export function isAxiosError<T = any, D = any>(payload: any): payload is AxiosEr
538
548
 
539
549
  export function spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
540
550
 
541
- export function isCancel(value: any): value is Cancel;
551
+ export function isCancel<T = any>(value: any): value is CanceledError<T>;
542
552
 
543
553
  export function all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
544
554
 
545
555
  export function mergeConfig<D = any>(config1: AxiosRequestConfig<D>, config2: AxiosRequestConfig<D>): AxiosRequestConfig<D>;
546
556
 
547
557
  export interface AxiosStatic extends AxiosInstance {
548
- create(config?: CreateAxiosDefaults): AxiosInstance;
549
558
  Cancel: CancelStatic;
550
559
  CancelToken: CancelTokenStatic;
551
560
  Axios: typeof Axios;
@@ -1,13 +1,15 @@
1
1
  import utils from '../utils.js';
2
2
  import httpAdapter from './http.js';
3
3
  import xhrAdapter from './xhr.js';
4
- import fetchAdapter from './fetch.js';
4
+ import * as fetchAdapter from './fetch.js';
5
5
  import AxiosError from "../core/AxiosError.js";
6
6
 
7
7
  const knownAdapters = {
8
8
  http: httpAdapter,
9
9
  xhr: xhrAdapter,
10
- fetch: fetchAdapter
10
+ fetch: {
11
+ get: fetchAdapter.getFetch,
12
+ }
11
13
  }
12
14
 
13
15
  utils.forEach(knownAdapters, (fn, value) => {
@@ -26,7 +28,7 @@ const renderReason = (reason) => `- ${reason}`;
26
28
  const isResolvedHandle = (adapter) => utils.isFunction(adapter) || adapter === null || adapter === false;
27
29
 
28
30
  export default {
29
- getAdapter: (adapters) => {
31
+ getAdapter: (adapters, config) => {
30
32
  adapters = utils.isArray(adapters) ? adapters : [adapters];
31
33
 
32
34
  const {length} = adapters;
@@ -49,7 +51,7 @@ export default {
49
51
  }
50
52
  }
51
53
 
52
- if (adapter) {
54
+ if (adapter && (utils.isFunction(adapter) || (adapter = adapter.get(config)))) {
53
55
  break;
54
56
  }
55
57