axios 1.18.1 → 1.20.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 (43) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +297 -5
  3. package/dist/axios.js +728 -170
  4. package/dist/axios.min.js +3 -3
  5. package/dist/axios.min.js.map +1 -1
  6. package/dist/browser/axios.cjs +871 -188
  7. package/dist/esm/axios.js +871 -188
  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 +1037 -225
  11. package/index.d.cts +102 -74
  12. package/index.d.ts +100 -68
  13. package/lib/adapters/fetch.js +64 -11
  14. package/lib/adapters/http.js +140 -67
  15. package/lib/adapters/xhr.js +52 -3
  16. package/lib/core/Axios.js +43 -20
  17. package/lib/core/AxiosError.js +33 -2
  18. package/lib/core/AxiosHeaders.js +124 -1
  19. package/lib/core/InterceptorManager.js +107 -8
  20. package/lib/core/buildFullPath.js +41 -15
  21. package/lib/core/dispatchRequest.js +8 -2
  22. package/lib/core/mergeConfig.js +19 -4
  23. package/lib/core/methodList.js +17 -0
  24. package/lib/core/setFormDataHeaders.js +27 -0
  25. package/lib/defaults/index.js +2 -1
  26. package/lib/env/data.js +1 -1
  27. package/lib/helpers/Http2Sessions.js +2 -0
  28. package/lib/helpers/HttpStatusCode.js +12 -1
  29. package/lib/helpers/combineURLs.js +11 -3
  30. package/lib/helpers/composeSignals.js +12 -1
  31. package/lib/helpers/estimateDataURLDecodedBytes.js +115 -54
  32. package/lib/helpers/formDataToJSON.js +11 -5
  33. package/lib/helpers/fromDataURI.js +5 -4
  34. package/lib/helpers/normalizeURLForProtocolCheck.js +24 -0
  35. package/lib/helpers/parseHeaders.js +5 -3
  36. package/lib/helpers/progressEventReducer.js +4 -4
  37. package/lib/helpers/resolveConfig.js +5 -17
  38. package/lib/helpers/shouldBypassProxy.js +300 -5
  39. package/lib/helpers/throttle.js +3 -2
  40. package/lib/helpers/toFormData.js +17 -23
  41. package/lib/platform/node/classes/Buffer.js +11 -0
  42. package/lib/utils.js +151 -18
  43. package/package.json +21 -19
package/index.d.cts CHANGED
@@ -52,6 +52,10 @@ declare class AxiosHeaders {
52
52
  set(headers?: axios.RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;
53
53
  set(headers?: Iterable<[string, axios.AxiosHeaderValue]>, rewrite?: boolean): AxiosHeaders;
54
54
 
55
+ get(
56
+ headerName: string,
57
+ parser: typeof AxiosHeaders.parseParameters
58
+ ): axios.AxiosHeaderParameters;
55
59
  get(headerName: string, parser: RegExp): RegExpExecArray | null;
56
60
  get(headerName: string, matcher?: true | AxiosHeaderParser): axios.AxiosHeaderValue;
57
61
 
@@ -73,6 +77,8 @@ declare class AxiosHeaders {
73
77
 
74
78
  static from(thing?: AxiosHeaders | axios.RawAxiosHeaders | string): AxiosHeaders;
75
79
 
80
+ static parseParameters(value: axios.AxiosHeaderValue): axios.AxiosHeaderParameters;
81
+
76
82
  static accessor(header: string | string[]): AxiosHeaders;
77
83
 
78
84
  static concat(
@@ -125,32 +131,32 @@ declare class AxiosHeaders {
125
131
  [Symbol.iterator](): IterableIterator<[string, axios.AxiosHeaderValue]>;
126
132
  }
127
133
 
128
- declare class AxiosError<T = unknown, D = any> extends Error {
134
+ declare class AxiosError<T = unknown, D = any, P = any> extends Error {
129
135
  constructor(
130
136
  message?: string,
131
137
  code?: string,
132
- config?: axios.InternalAxiosRequestConfig<D>,
138
+ config?: axios.InternalAxiosRequestConfig<D, P>,
133
139
  request?: any,
134
- response?: axios.AxiosResponse<T, D>
140
+ response?: axios.AxiosResponse<T, D, {}, P>
135
141
  );
136
142
 
137
- config?: axios.InternalAxiosRequestConfig<D>;
143
+ config?: axios.InternalAxiosRequestConfig<D, P>;
138
144
  code?: string;
139
145
  request?: any;
140
- response?: axios.AxiosResponse<T, D>;
146
+ response?: axios.AxiosResponse<T, D, {}, P>;
141
147
  isAxiosError: boolean;
142
148
  status?: number;
143
149
  toJSON: () => object;
144
150
  cause?: Error;
145
151
  event?: BrowserProgressEvent;
146
- static from<T = unknown, D = any>(
152
+ static from<T = unknown, D = any, P = any>(
147
153
  error: Error | unknown,
148
154
  code?: string,
149
- config?: axios.InternalAxiosRequestConfig<D>,
155
+ config?: axios.InternalAxiosRequestConfig<D, P>,
150
156
  request?: any,
151
- response?: axios.AxiosResponse<T, D>,
157
+ response?: axios.AxiosResponse<T, D, {}, P>,
152
158
  customProps?: object
153
- ): AxiosError<T, D>;
159
+ ): AxiosError<T, D, P>;
154
160
  static readonly ERR_FR_TOO_MANY_REDIRECTS = 'ERR_FR_TOO_MANY_REDIRECTS';
155
161
  static readonly ERR_BAD_OPTION_VALUE = 'ERR_BAD_OPTION_VALUE';
156
162
  static readonly ERR_BAD_OPTION = 'ERR_BAD_OPTION';
@@ -167,12 +173,20 @@ declare class AxiosError<T = unknown, D = any> extends Error {
167
173
  static readonly ETIMEDOUT = 'ETIMEDOUT';
168
174
  }
169
175
 
170
- declare class CanceledError<T> extends AxiosError<T> {
171
- constructor(message?: string, config?: axios.InternalAxiosRequestConfig, request?: any);
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);
172
178
  readonly name: 'CanceledError';
173
179
  __CANCEL__?: boolean;
174
180
  }
175
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
+
176
190
  declare class Axios {
177
191
  constructor(config?: axios.AxiosRequestConfig);
178
192
  defaults: axios.AxiosDefaults;
@@ -181,60 +195,60 @@ declare class Axios {
181
195
  response: axios.AxiosInterceptorManager<axios.AxiosResponse>;
182
196
  };
183
197
  getUri(config?: axios.AxiosRequestConfig): string;
184
- request<T = any, R = axios.AxiosResponse<T>, D = any>(
185
- config: axios.AxiosRequestConfig<D>
186
- ): Promise<R>;
187
- 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>(
188
202
  url: string,
189
- config?: axios.AxiosRequestConfig<D>
190
- ): Promise<R>;
191
- 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>(
192
206
  url: string,
193
- config?: axios.AxiosRequestConfig<D>
194
- ): Promise<R>;
195
- 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>(
196
210
  url: string,
197
- config?: axios.AxiosRequestConfig<D>
198
- ): Promise<R>;
199
- 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>(
200
214
  url: string,
201
- config?: axios.AxiosRequestConfig<D>
202
- ): Promise<R>;
203
- 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>(
204
218
  url: string,
205
219
  data?: D,
206
- config?: axios.AxiosRequestConfig<D>
207
- ): Promise<R>;
208
- 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>(
209
223
  url: string,
210
224
  data?: D,
211
- config?: axios.AxiosRequestConfig<D>
212
- ): Promise<R>;
213
- 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>(
214
228
  url: string,
215
229
  data?: D,
216
- config?: axios.AxiosRequestConfig<D>
217
- ): Promise<R>;
218
- 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>(
219
233
  url: string,
220
234
  data?: D,
221
- config?: axios.AxiosRequestConfig<D>
222
- ): Promise<R>;
223
- 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>(
224
238
  url: string,
225
239
  data?: D,
226
- config?: axios.AxiosRequestConfig<D>
227
- ): Promise<R>;
228
- 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>(
229
243
  url: string,
230
244
  data?: D,
231
- config?: axios.AxiosRequestConfig<D>
232
- ): Promise<R>;
233
- 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>(
234
248
  url: string,
235
249
  data?: D,
236
- config?: axios.AxiosRequestConfig<D>
237
- ): Promise<R>;
250
+ config?: axios.AxiosRequestConfig<D, P>
251
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
238
252
  }
239
253
 
240
254
  declare enum HttpStatusCode {
@@ -274,14 +288,18 @@ declare enum HttpStatusCode {
274
288
  Gone = 410,
275
289
  LengthRequired = 411,
276
290
  PreconditionFailed = 412,
291
+ /** @deprecated Use `ContentTooLarge` instead. */
277
292
  PayloadTooLarge = 413,
293
+ ContentTooLarge = 413,
278
294
  UriTooLong = 414,
279
295
  UnsupportedMediaType = 415,
280
296
  RangeNotSatisfiable = 416,
281
297
  ExpectationFailed = 417,
282
298
  ImATeapot = 418,
283
299
  MisdirectedRequest = 421,
300
+ /** @deprecated Use `UnprocessableContent` instead. */
284
301
  UnprocessableEntity = 422,
302
+ UnprocessableContent = 422,
285
303
  Locked = 423,
286
304
  FailedDependency = 424,
287
305
  TooEarly = 425,
@@ -301,6 +319,7 @@ declare enum HttpStatusCode {
301
319
  LoopDetected = 508,
302
320
  NotExtended = 510,
303
321
  NetworkAuthenticationRequired = 511,
322
+ WebServerReturnsAnUnknownError = 520,
304
323
  WebServerIsDown = 521,
305
324
  ConnectionTimedOut = 522,
306
325
  OriginIsUnreachable = 523,
@@ -309,10 +328,12 @@ declare enum HttpStatusCode {
309
328
  InvalidSslCertificate = 526,
310
329
  }
311
330
 
312
- type InternalAxiosError<T = unknown, D = any> = AxiosError<T, D>;
331
+ type InternalAxiosError<T = unknown, D = any, P = any> = AxiosError<T, D, P>;
313
332
 
314
333
  declare namespace axios {
315
- type AxiosError<T = unknown, D = any> = InternalAxiosError<T, D>;
334
+ type AxiosHeaderParameters = Record<string, string>;
335
+
336
+ type AxiosError<T = unknown, D = any, P = any> = InternalAxiosError<T, D, P>;
316
337
 
317
338
  interface RawAxiosHeaders {
318
339
  [key: string]: AxiosHeaderValue;
@@ -450,13 +471,13 @@ declare namespace axios {
450
471
  (value: any, defaultEncoder: (value: any) => any): any;
451
472
  }
452
473
 
453
- interface CustomParamsSerializer {
454
- (params: Record<string, any>, options?: ParamsSerializerOptions): string;
474
+ interface CustomParamsSerializer<P = Record<string, any>> {
475
+ (params: P, options?: ParamsSerializerOptions<P>): string;
455
476
  }
456
477
 
457
- interface ParamsSerializerOptions extends SerializerOptions {
478
+ interface ParamsSerializerOptions<P = Record<string, any>> extends SerializerOptions {
458
479
  encode?: ParamEncoder;
459
- serialize?: CustomParamsSerializer;
480
+ serialize?: CustomParamsSerializer<P>;
460
481
  }
461
482
 
462
483
  type MaxUploadRate = number;
@@ -491,7 +512,7 @@ declare namespace axios {
491
512
 
492
513
  type LookupAddress = string | LookupAddressEntry;
493
514
 
494
- interface AxiosRequestConfig<D = any> {
515
+ interface AxiosRequestConfig<D = any, P = any> {
495
516
  url?: string;
496
517
  method?: Method | string;
497
518
  baseURL?: string;
@@ -499,8 +520,10 @@ declare namespace axios {
499
520
  transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
500
521
  transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
501
522
  headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
502
- params?: any;
503
- paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
523
+ params?: P;
524
+ paramsSerializer?:
525
+ | ParamsSerializerOptions<unknown extends P ? Record<string, any> : P>
526
+ | CustomParamsSerializer<unknown extends P ? Record<string, any> : P>;
504
527
  data?: D;
505
528
  timeout?: Milliseconds;
506
529
  timeoutErrorMessage?: string;
@@ -562,7 +585,7 @@ declare namespace axios {
562
585
  | [address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily]
563
586
  | LookupAddress
564
587
  >);
565
- withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
588
+ withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig<D, P>) => boolean | undefined);
566
589
  parseReviver?: (this: any, key: string, value: any, context?: { source?: string }) => any;
567
590
  fetchOptions?:
568
591
  | Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'>
@@ -577,9 +600,9 @@ declare namespace axios {
577
600
  }
578
601
 
579
602
  // Alias
580
- type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
603
+ type RawAxiosRequestConfig<D = any, P = any> = AxiosRequestConfig<D, P>;
581
604
 
582
- interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
605
+ interface InternalAxiosRequestConfig<D = any, P = any> extends AxiosRequestConfig<D, P> {
583
606
  headers: AxiosRequestHeaders;
584
607
  }
585
608
 
@@ -598,24 +621,27 @@ declare namespace axios {
598
621
  query?: RawAxiosRequestHeaders;
599
622
  }
600
623
 
601
- interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
624
+ interface AxiosDefaults<D = any, P = any> extends Omit<AxiosRequestConfig<D, P>, 'headers'> {
602
625
  headers: HeadersDefaults;
603
626
  }
604
627
 
605
- interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
628
+ interface CreateAxiosDefaults<D = any, P = any> extends Omit<
629
+ AxiosRequestConfig<D, P>,
630
+ 'headers'
631
+ > {
606
632
  headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
607
633
  }
608
634
 
609
- interface AxiosResponse<T = any, D = any, H = {}> {
635
+ interface AxiosResponse<T = any, D = any, H = {}, P = any> {
610
636
  data: T;
611
637
  status: number;
612
638
  statusText: string;
613
639
  headers: (H & RawAxiosResponseHeaders) | AxiosResponseHeaders;
614
- config: InternalAxiosRequestConfig<D>;
640
+ config: InternalAxiosRequestConfig<D, P>;
615
641
  request?: any;
616
642
  }
617
643
 
618
- type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
644
+ type AxiosPromise<T = any, D = any, P = any> = Promise<AxiosResponse<T, D, {}, P>>;
619
645
 
620
646
  interface CancelStatic {
621
647
  new (message?: string): Cancel;
@@ -682,11 +708,13 @@ declare namespace axios {
682
708
  }
683
709
 
684
710
  interface AxiosInstance extends Axios {
685
- <T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
686
- <T = any, R = AxiosResponse<T>, D = any>(
711
+ <T = any, R = AxiosResponseDefault, D = any, P = any>(
712
+ config: AxiosRequestConfig<D, P>
713
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
714
+ <T = any, R = AxiosResponseDefault, D = any, P = any>(
687
715
  url: string,
688
- config?: AxiosRequestConfig<D>
689
- ): Promise<R>;
716
+ config?: AxiosRequestConfig<D, P>
717
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
690
718
 
691
719
  create(config?: CreateAxiosDefaults): AxiosInstance;
692
720
  defaults: Omit<AxiosDefaults, 'headers'> & {
@@ -714,10 +742,10 @@ declare namespace axios {
714
742
  CanceledError: typeof CanceledError;
715
743
  HttpStatusCode: typeof HttpStatusCode;
716
744
  readonly VERSION: string;
717
- isCancel<T = any>(value: any): value is CanceledError<T>;
745
+ isCancel<T = any, D = any, P = any>(value: any): value is CanceledError<T, D, P>;
718
746
  all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
719
747
  spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
720
- isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
748
+ isAxiosError<T = any, D = any, P = any>(payload: any): payload is AxiosError<T, D, P>;
721
749
  toFormData(
722
750
  sourceObj: object,
723
751
  targetFormData?: GenericFormData,
@@ -726,10 +754,10 @@ declare namespace axios {
726
754
  formToJSON(form: GenericFormData | GenericHTMLFormElement): object;
727
755
  getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
728
756
  AxiosHeaders: typeof AxiosHeaders;
729
- mergeConfig<D = any>(
730
- config1: AxiosRequestConfig<D>,
731
- config2: AxiosRequestConfig<D>
732
- ): AxiosRequestConfig<D>;
757
+ mergeConfig<D = any, P = any>(
758
+ config1: AxiosRequestConfig<D, P>,
759
+ config2: AxiosRequestConfig<D, P>
760
+ ): AxiosRequestConfig<D, P>;
733
761
  }
734
762
  }
735
763