axios 1.18.0 → 1.19.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +192 -23
  3. package/dist/axios.js +410 -101
  4. package/dist/axios.min.js +3 -3
  5. package/dist/axios.min.js.map +1 -1
  6. package/dist/browser/axios.cjs +484 -119
  7. package/dist/esm/axios.js +484 -119
  8. package/dist/esm/axios.min.js +2 -2
  9. package/dist/esm/axios.min.js.map +1 -1
  10. package/dist/node/axios.cjs +589 -139
  11. package/index.d.cts +114 -74
  12. package/index.d.ts +112 -68
  13. package/lib/adapters/adapters.js +1 -1
  14. package/lib/adapters/fetch.js +27 -12
  15. package/lib/adapters/http.js +95 -34
  16. package/lib/adapters/xhr.js +1 -0
  17. package/lib/core/Axios.js +24 -6
  18. package/lib/core/AxiosError.js +46 -3
  19. package/lib/core/AxiosHeaders.js +124 -1
  20. package/lib/core/buildFullPath.js +45 -7
  21. package/lib/core/mergeConfig.js +19 -3
  22. package/lib/core/setFormDataHeaders.js +27 -0
  23. package/lib/env/data.js +1 -1
  24. package/lib/helpers/AxiosURLSearchParams.js +1 -3
  25. package/lib/helpers/HttpStatusCode.js +1 -0
  26. package/lib/helpers/buildURL.js +1 -0
  27. package/lib/helpers/combineURLs.js +11 -3
  28. package/lib/helpers/composeSignals.js +12 -1
  29. package/lib/helpers/cookies.js +5 -1
  30. package/lib/helpers/estimateDataURLDecodedBytes.js +115 -54
  31. package/lib/helpers/formDataToJSON.js +11 -5
  32. package/lib/helpers/fromDataURI.js +4 -2
  33. package/lib/helpers/parseHeaders.js +5 -3
  34. package/lib/helpers/progressEventReducer.js +3 -3
  35. package/lib/helpers/resolveConfig.js +10 -19
  36. package/lib/helpers/shouldBypassProxy.js +120 -1
  37. package/lib/helpers/toFormData.js +8 -1
  38. package/lib/helpers/validator.js +1 -1
  39. package/lib/platform/node/classes/Buffer.js +11 -0
  40. package/lib/utils.js +17 -5
  41. package/package.json +22 -20
package/index.d.cts CHANGED
@@ -50,7 +50,12 @@ declare class AxiosHeaders {
50
50
  rewrite?: boolean | AxiosHeaderMatcher
51
51
  ): AxiosHeaders;
52
52
  set(headers?: axios.RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;
53
+ set(headers?: Iterable<[string, axios.AxiosHeaderValue]>, rewrite?: boolean): AxiosHeaders;
53
54
 
55
+ get(
56
+ headerName: string,
57
+ parser: typeof AxiosHeaders.parseParameters
58
+ ): axios.AxiosHeaderParameters;
54
59
  get(headerName: string, parser: RegExp): RegExpExecArray | null;
55
60
  get(headerName: string, matcher?: true | AxiosHeaderParser): axios.AxiosHeaderValue;
56
61
 
@@ -72,6 +77,8 @@ declare class AxiosHeaders {
72
77
 
73
78
  static from(thing?: AxiosHeaders | axios.RawAxiosHeaders | string): AxiosHeaders;
74
79
 
80
+ static parseParameters(value: axios.AxiosHeaderValue): axios.AxiosHeaderParameters;
81
+
75
82
  static accessor(header: string | string[]): AxiosHeaders;
76
83
 
77
84
  static concat(
@@ -119,35 +126,37 @@ declare class AxiosHeaders {
119
126
 
120
127
  getSetCookie(): string[];
121
128
 
129
+ toString(): string;
130
+
122
131
  [Symbol.iterator](): IterableIterator<[string, axios.AxiosHeaderValue]>;
123
132
  }
124
133
 
125
- declare class AxiosError<T = unknown, D = any> extends Error {
134
+ declare class AxiosError<T = unknown, D = any, P = any> extends Error {
126
135
  constructor(
127
136
  message?: string,
128
137
  code?: string,
129
- config?: axios.InternalAxiosRequestConfig<D>,
138
+ config?: axios.InternalAxiosRequestConfig<D, P>,
130
139
  request?: any,
131
- response?: axios.AxiosResponse<T, D>
140
+ response?: axios.AxiosResponse<T, D, {}, P>
132
141
  );
133
142
 
134
- config?: axios.InternalAxiosRequestConfig<D>;
143
+ config?: axios.InternalAxiosRequestConfig<D, P>;
135
144
  code?: string;
136
145
  request?: any;
137
- response?: axios.AxiosResponse<T, D>;
146
+ response?: axios.AxiosResponse<T, D, {}, P>;
138
147
  isAxiosError: boolean;
139
148
  status?: number;
140
149
  toJSON: () => object;
141
150
  cause?: Error;
142
151
  event?: BrowserProgressEvent;
143
- static from<T = unknown, D = any>(
152
+ static from<T = unknown, D = any, P = any>(
144
153
  error: Error | unknown,
145
154
  code?: string,
146
- config?: axios.InternalAxiosRequestConfig<D>,
155
+ config?: axios.InternalAxiosRequestConfig<D, P>,
147
156
  request?: any,
148
- response?: axios.AxiosResponse<T, D>,
157
+ response?: axios.AxiosResponse<T, D, {}, P>,
149
158
  customProps?: object
150
- ): AxiosError<T, D>;
159
+ ): AxiosError<T, D, P>;
151
160
  static readonly ERR_FR_TOO_MANY_REDIRECTS = 'ERR_FR_TOO_MANY_REDIRECTS';
152
161
  static readonly ERR_BAD_OPTION_VALUE = 'ERR_BAD_OPTION_VALUE';
153
162
  static readonly ERR_BAD_OPTION = 'ERR_BAD_OPTION';
@@ -164,10 +173,20 @@ declare class AxiosError<T = unknown, D = any> extends Error {
164
173
  static readonly ETIMEDOUT = 'ETIMEDOUT';
165
174
  }
166
175
 
167
- declare class CanceledError<T> extends AxiosError<T> {
176
+ declare class CanceledError<T, D = any, P = any> extends AxiosError<T, D, P> {
177
+ constructor(message?: string, config?: axios.InternalAxiosRequestConfig<D, P>, request?: any);
168
178
  readonly name: 'CanceledError';
179
+ __CANCEL__?: boolean;
169
180
  }
170
181
 
182
+ declare const axiosResponseDefault: unique symbol;
183
+
184
+ type AxiosResponseDefault = typeof axiosResponseDefault;
185
+
186
+ type AxiosResponseResult<T, R, D, P> = R extends AxiosResponseDefault
187
+ ? axios.AxiosResponse<T, D, {}, P>
188
+ : R;
189
+
171
190
  declare class Axios {
172
191
  constructor(config?: axios.AxiosRequestConfig);
173
192
  defaults: axios.AxiosDefaults;
@@ -176,60 +195,60 @@ declare class Axios {
176
195
  response: axios.AxiosInterceptorManager<axios.AxiosResponse>;
177
196
  };
178
197
  getUri(config?: axios.AxiosRequestConfig): string;
179
- request<T = any, R = axios.AxiosResponse<T>, D = any>(
180
- config: axios.AxiosRequestConfig<D>
181
- ): Promise<R>;
182
- get<T = any, R = axios.AxiosResponse<T>, D = any>(
198
+ request<T = any, R = AxiosResponseDefault, D = any, P = any>(
199
+ config: axios.AxiosRequestConfig<D, P>
200
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
201
+ get<T = any, R = AxiosResponseDefault, D = any, P = any>(
183
202
  url: string,
184
- config?: axios.AxiosRequestConfig<D>
185
- ): Promise<R>;
186
- delete<T = any, R = axios.AxiosResponse<T>, D = any>(
203
+ config?: axios.AxiosRequestConfig<D, P>
204
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
205
+ delete<T = any, R = AxiosResponseDefault, D = any, P = any>(
187
206
  url: string,
188
- config?: axios.AxiosRequestConfig<D>
189
- ): Promise<R>;
190
- head<T = any, R = axios.AxiosResponse<T>, D = any>(
207
+ config?: axios.AxiosRequestConfig<D, P>
208
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
209
+ head<T = any, R = AxiosResponseDefault, D = any, P = any>(
191
210
  url: string,
192
- config?: axios.AxiosRequestConfig<D>
193
- ): Promise<R>;
194
- options<T = any, R = axios.AxiosResponse<T>, D = any>(
211
+ config?: axios.AxiosRequestConfig<D, P>
212
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
213
+ options<T = any, R = AxiosResponseDefault, D = any, P = any>(
195
214
  url: string,
196
- config?: axios.AxiosRequestConfig<D>
197
- ): Promise<R>;
198
- post<T = any, R = axios.AxiosResponse<T>, D = any>(
215
+ config?: axios.AxiosRequestConfig<D, P>
216
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
217
+ post<T = any, R = AxiosResponseDefault, D = any, P = any>(
199
218
  url: string,
200
219
  data?: D,
201
- config?: axios.AxiosRequestConfig<D>
202
- ): Promise<R>;
203
- put<T = any, R = axios.AxiosResponse<T>, D = any>(
220
+ config?: axios.AxiosRequestConfig<D, P>
221
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
222
+ put<T = any, R = AxiosResponseDefault, D = any, P = any>(
204
223
  url: string,
205
224
  data?: D,
206
- config?: axios.AxiosRequestConfig<D>
207
- ): Promise<R>;
208
- patch<T = any, R = axios.AxiosResponse<T>, D = any>(
225
+ config?: axios.AxiosRequestConfig<D, P>
226
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
227
+ patch<T = any, R = AxiosResponseDefault, D = any, P = any>(
209
228
  url: string,
210
229
  data?: D,
211
- config?: axios.AxiosRequestConfig<D>
212
- ): Promise<R>;
213
- postForm<T = any, R = axios.AxiosResponse<T>, D = any>(
230
+ config?: axios.AxiosRequestConfig<D, P>
231
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
232
+ postForm<T = any, R = AxiosResponseDefault, D = any, P = any>(
214
233
  url: string,
215
234
  data?: D,
216
- config?: axios.AxiosRequestConfig<D>
217
- ): Promise<R>;
218
- putForm<T = any, R = axios.AxiosResponse<T>, D = any>(
235
+ config?: axios.AxiosRequestConfig<D, P>
236
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
237
+ putForm<T = any, R = AxiosResponseDefault, D = any, P = any>(
219
238
  url: string,
220
239
  data?: D,
221
- config?: axios.AxiosRequestConfig<D>
222
- ): Promise<R>;
223
- patchForm<T = any, R = axios.AxiosResponse<T>, D = any>(
240
+ config?: axios.AxiosRequestConfig<D, P>
241
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
242
+ patchForm<T = any, R = AxiosResponseDefault, D = any, P = any>(
224
243
  url: string,
225
244
  data?: D,
226
- config?: axios.AxiosRequestConfig<D>
227
- ): Promise<R>;
228
- query<T = any, R = axios.AxiosResponse<T>, D = any>(
245
+ config?: axios.AxiosRequestConfig<D, P>
246
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
247
+ query<T = any, R = AxiosResponseDefault, D = any, P = any>(
229
248
  url: string,
230
249
  data?: D,
231
- config?: axios.AxiosRequestConfig<D>
232
- ): Promise<R>;
250
+ config?: axios.AxiosRequestConfig<D, P>
251
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
233
252
  }
234
253
 
235
254
  declare enum HttpStatusCode {
@@ -296,12 +315,21 @@ declare enum HttpStatusCode {
296
315
  LoopDetected = 508,
297
316
  NotExtended = 510,
298
317
  NetworkAuthenticationRequired = 511,
318
+ WebServerReturnsAnUnknownError = 520,
319
+ WebServerIsDown = 521,
320
+ ConnectionTimedOut = 522,
321
+ OriginIsUnreachable = 523,
322
+ TimeoutOccurred = 524,
323
+ SslHandshakeFailed = 525,
324
+ InvalidSslCertificate = 526,
299
325
  }
300
326
 
301
- type InternalAxiosError<T = unknown, D = any> = AxiosError<T, D>;
327
+ type InternalAxiosError<T = unknown, D = any, P = any> = AxiosError<T, D, P>;
302
328
 
303
329
  declare namespace axios {
304
- type AxiosError<T = unknown, D = any> = InternalAxiosError<T, D>;
330
+ type AxiosHeaderParameters = Record<string, string>;
331
+
332
+ type AxiosError<T = unknown, D = any, P = any> = InternalAxiosError<T, D, P>;
305
333
 
306
334
  interface RawAxiosHeaders {
307
335
  [key: string]: AxiosHeaderValue;
@@ -428,6 +456,8 @@ declare namespace axios {
428
456
  dots?: boolean;
429
457
  metaTokens?: boolean;
430
458
  indexes?: boolean | null;
459
+ maxDepth?: number;
460
+ Blob?: { new (...args: any[]): any };
431
461
  }
432
462
 
433
463
  // tslint:disable-next-line
@@ -437,13 +467,13 @@ declare namespace axios {
437
467
  (value: any, defaultEncoder: (value: any) => any): any;
438
468
  }
439
469
 
440
- interface CustomParamsSerializer {
441
- (params: Record<string, any>, options?: ParamsSerializerOptions): string;
470
+ interface CustomParamsSerializer<P = Record<string, any>> {
471
+ (params: P, options?: ParamsSerializerOptions<P>): string;
442
472
  }
443
473
 
444
- interface ParamsSerializerOptions extends SerializerOptions {
474
+ interface ParamsSerializerOptions<P = Record<string, any>> extends SerializerOptions {
445
475
  encode?: ParamEncoder;
446
- serialize?: CustomParamsSerializer;
476
+ serialize?: CustomParamsSerializer<P>;
447
477
  }
448
478
 
449
479
  type MaxUploadRate = number;
@@ -478,7 +508,7 @@ declare namespace axios {
478
508
 
479
509
  type LookupAddress = string | LookupAddressEntry;
480
510
 
481
- interface AxiosRequestConfig<D = any> {
511
+ interface AxiosRequestConfig<D = any, P = any> {
482
512
  url?: string;
483
513
  method?: Method | string;
484
514
  baseURL?: string;
@@ -486,8 +516,10 @@ declare namespace axios {
486
516
  transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
487
517
  transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
488
518
  headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
489
- params?: any;
490
- paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
519
+ params?: P;
520
+ paramsSerializer?:
521
+ | ParamsSerializerOptions<unknown extends P ? Record<string, any> : P>
522
+ | CustomParamsSerializer<unknown extends P ? Record<string, any> : P>;
491
523
  data?: D;
492
524
  timeout?: Milliseconds;
493
525
  timeoutErrorMessage?: string;
@@ -549,7 +581,7 @@ declare namespace axios {
549
581
  | [address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily]
550
582
  | LookupAddress
551
583
  >);
552
- withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
584
+ withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig<D, P>) => boolean | undefined);
553
585
  parseReviver?: (this: any, key: string, value: any, context?: { source?: string }) => any;
554
586
  fetchOptions?:
555
587
  | Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'>
@@ -564,9 +596,9 @@ declare namespace axios {
564
596
  }
565
597
 
566
598
  // Alias
567
- type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
599
+ type RawAxiosRequestConfig<D = any, P = any> = AxiosRequestConfig<D, P>;
568
600
 
569
- interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
601
+ interface InternalAxiosRequestConfig<D = any, P = any> extends AxiosRequestConfig<D, P> {
570
602
  headers: AxiosRequestHeaders;
571
603
  }
572
604
 
@@ -585,24 +617,27 @@ declare namespace axios {
585
617
  query?: RawAxiosRequestHeaders;
586
618
  }
587
619
 
588
- interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
620
+ interface AxiosDefaults<D = any, P = any> extends Omit<AxiosRequestConfig<D, P>, 'headers'> {
589
621
  headers: HeadersDefaults;
590
622
  }
591
623
 
592
- interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
624
+ interface CreateAxiosDefaults<D = any, P = any> extends Omit<
625
+ AxiosRequestConfig<D, P>,
626
+ 'headers'
627
+ > {
593
628
  headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
594
629
  }
595
630
 
596
- interface AxiosResponse<T = any, D = any, H = {}> {
631
+ interface AxiosResponse<T = any, D = any, H = {}, P = any> {
597
632
  data: T;
598
633
  status: number;
599
634
  statusText: string;
600
635
  headers: (H & RawAxiosResponseHeaders) | AxiosResponseHeaders;
601
- config: InternalAxiosRequestConfig<D>;
636
+ config: InternalAxiosRequestConfig<D, P>;
602
637
  request?: any;
603
638
  }
604
639
 
605
- type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
640
+ type AxiosPromise<T = any, D = any, P = any> = Promise<AxiosResponse<T, D, {}, P>>;
606
641
 
607
642
  interface CancelStatic {
608
643
  new (message?: string): Cancel;
@@ -625,6 +660,9 @@ declare namespace axios {
625
660
  promise: Promise<Cancel>;
626
661
  reason?: Cancel;
627
662
  throwIfRequested(): void;
663
+ subscribe(listener: (cancel: Cancel | any) => void): void;
664
+ unsubscribe(listener: (cancel: Cancel | any) => void): void;
665
+ toAbortSignal(): AbortSignal;
628
666
  }
629
667
 
630
668
  interface CancelTokenSource {
@@ -666,11 +704,13 @@ declare namespace axios {
666
704
  }
667
705
 
668
706
  interface AxiosInstance extends Axios {
669
- <T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
670
- <T = any, R = AxiosResponse<T>, D = any>(
707
+ <T = any, R = AxiosResponseDefault, D = any, P = any>(
708
+ config: AxiosRequestConfig<D, P>
709
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
710
+ <T = any, R = AxiosResponseDefault, D = any, P = any>(
671
711
  url: string,
672
- config?: AxiosRequestConfig<D>
673
- ): Promise<R>;
712
+ config?: AxiosRequestConfig<D, P>
713
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
674
714
 
675
715
  create(config?: CreateAxiosDefaults): AxiosInstance;
676
716
  defaults: Omit<AxiosDefaults, 'headers'> & {
@@ -691,17 +731,17 @@ declare namespace axios {
691
731
  }
692
732
 
693
733
  interface AxiosStatic extends AxiosInstance {
694
- Cancel: CancelStatic;
734
+ Cancel: typeof CanceledError;
695
735
  CancelToken: CancelTokenStatic;
696
736
  Axios: typeof Axios;
697
737
  AxiosError: typeof AxiosError;
698
738
  CanceledError: typeof CanceledError;
699
739
  HttpStatusCode: typeof HttpStatusCode;
700
740
  readonly VERSION: string;
701
- isCancel<T = any>(value: any): value is CanceledError<T>;
741
+ isCancel<T = any, D = any, P = any>(value: any): value is CanceledError<T, D, P>;
702
742
  all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
703
743
  spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
704
- isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
744
+ isAxiosError<T = any, D = any, P = any>(payload: any): payload is AxiosError<T, D, P>;
705
745
  toFormData(
706
746
  sourceObj: object,
707
747
  targetFormData?: GenericFormData,
@@ -710,10 +750,10 @@ declare namespace axios {
710
750
  formToJSON(form: GenericFormData | GenericHTMLFormElement): object;
711
751
  getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
712
752
  AxiosHeaders: typeof AxiosHeaders;
713
- mergeConfig<D = any>(
714
- config1: AxiosRequestConfig<D>,
715
- config2: AxiosRequestConfig<D>
716
- ): AxiosRequestConfig<D>;
753
+ mergeConfig<D = any, P = any>(
754
+ config1: AxiosRequestConfig<D, P>,
755
+ config2: AxiosRequestConfig<D, P>
756
+ ): AxiosRequestConfig<D, P>;
717
757
  }
718
758
  }
719
759