axios 1.1.3 → 1.2.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.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

package/index.d.cts ADDED
@@ -0,0 +1,490 @@
1
+ type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
2
+ type RawAxiosHeaders = Record<string, AxiosHeaderValue>;
3
+
4
+ type MethodsHeaders = {
5
+ [Key in axios.Method as Lowercase<Key>]: AxiosHeaders;
6
+ };
7
+
8
+ interface CommonHeaders {
9
+ common: AxiosHeaders;
10
+ }
11
+
12
+ type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string, headers: RawAxiosHeaders) => boolean;
13
+
14
+ type AxiosHeaderSetter = (value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher) => AxiosHeaders;
15
+
16
+ type AxiosHeaderGetter = ((parser?: RegExp) => RegExpExecArray | null) |
17
+ ((matcher?: AxiosHeaderMatcher) => AxiosHeaderValue);
18
+
19
+ type AxiosHeaderTester = (matcher?: AxiosHeaderMatcher) => boolean;
20
+
21
+ type MaxUploadRate = number;
22
+
23
+ type MaxDownloadRate = number;
24
+
25
+ type Milliseconds = number;
26
+
27
+ declare class AxiosHeaders {
28
+ constructor(
29
+ headers?: RawAxiosHeaders | AxiosHeaders,
30
+ defaultHeaders?: RawAxiosHeaders | AxiosHeaders
31
+ );
32
+
33
+ set(headerName?: string, value?: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
34
+ set(headers?: RawAxiosHeaders | AxiosHeaders, rewrite?: boolean): AxiosHeaders;
35
+
36
+ get(headerName: string, parser: RegExp): RegExpExecArray | null;
37
+ get(headerName: string, matcher?: true | AxiosHeaderMatcher): AxiosHeaderValue;
38
+
39
+ has(header: string, matcher?: true | AxiosHeaderMatcher): boolean;
40
+
41
+ delete(header: string | string[], matcher?: AxiosHeaderMatcher): boolean;
42
+
43
+ clear(): boolean;
44
+
45
+ normalize(format: boolean): AxiosHeaders;
46
+
47
+ toJSON(asStrings?: boolean): RawAxiosHeaders;
48
+
49
+ static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
50
+
51
+ static accessor(header: string | string[]): AxiosHeaders;
52
+
53
+ setContentType: AxiosHeaderSetter;
54
+ getContentType: AxiosHeaderGetter;
55
+ hasContentType: AxiosHeaderTester;
56
+
57
+ setContentLength: AxiosHeaderSetter;
58
+ getContentLength: AxiosHeaderGetter;
59
+ hasContentLength: AxiosHeaderTester;
60
+
61
+ setAccept: AxiosHeaderSetter;
62
+ getAccept: AxiosHeaderGetter;
63
+ hasAccept: AxiosHeaderTester;
64
+
65
+ setUserAgent: AxiosHeaderSetter;
66
+ getUserAgent: AxiosHeaderGetter;
67
+ hasUserAgent: AxiosHeaderTester;
68
+
69
+ setContentEncoding: AxiosHeaderSetter;
70
+ getContentEncoding: AxiosHeaderGetter;
71
+ hasContentEncoding: AxiosHeaderTester;
72
+ }
73
+
74
+ declare class AxiosError<T = unknown, D = any> extends Error {
75
+ constructor(
76
+ message?: string,
77
+ code?: string,
78
+ config?: axios.AxiosRequestConfig<D>,
79
+ request?: any,
80
+ response?: axios.AxiosResponse<T, D>
81
+ );
82
+
83
+ config?: axios.AxiosRequestConfig<D>;
84
+ code?: string;
85
+ request?: any;
86
+ response?: axios.AxiosResponse<T, D>;
87
+ isAxiosError: boolean;
88
+ status?: number;
89
+ toJSON: () => object;
90
+ cause?: Error;
91
+ static readonly ERR_FR_TOO_MANY_REDIRECTS = "ERR_FR_TOO_MANY_REDIRECTS";
92
+ static readonly ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
93
+ static readonly ERR_BAD_OPTION = "ERR_BAD_OPTION";
94
+ static readonly ERR_NETWORK = "ERR_NETWORK";
95
+ static readonly ERR_DEPRECATED = "ERR_DEPRECATED";
96
+ static readonly ERR_BAD_RESPONSE = "ERR_BAD_RESPONSE";
97
+ static readonly ERR_BAD_REQUEST = "ERR_BAD_REQUEST";
98
+ static readonly ERR_NOT_SUPPORT = "ERR_NOT_SUPPORT";
99
+ static readonly ERR_INVALID_URL = "ERR_INVALID_URL";
100
+ static readonly ERR_CANCELED = "ERR_CANCELED";
101
+ static readonly ECONNABORTED = "ECONNABORTED";
102
+ static readonly ETIMEDOUT = "ETIMEDOUT";
103
+ }
104
+
105
+ declare class CanceledError<T> extends AxiosError<T> {
106
+ }
107
+
108
+ declare class Axios {
109
+ constructor(config?: axios.AxiosRequestConfig);
110
+ defaults: axios.AxiosDefaults;
111
+ interceptors: {
112
+ request: axios.AxiosInterceptorManager<axios.AxiosRequestConfig>;
113
+ response: axios.AxiosInterceptorManager<axios.AxiosResponse>;
114
+ };
115
+ getUri(config?: axios.AxiosRequestConfig): string;
116
+ request<T = any, R = axios.AxiosResponse<T>, D = any>(config: axios.AxiosRequestConfig<D>): Promise<R>;
117
+ get<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
118
+ delete<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
119
+ head<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
120
+ options<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
121
+ post<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
122
+ put<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
123
+ patch<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
124
+ postForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
125
+ putForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
126
+ patchForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
127
+ }
128
+
129
+ declare enum HttpStatusCode {
130
+ Continue = 100,
131
+ SwitchingProtocols = 101,
132
+ Processing = 102,
133
+ EarlyHints = 103,
134
+ Ok = 200,
135
+ Created = 201,
136
+ Accepted = 202,
137
+ NonAuthoritativeInformation = 203,
138
+ NoContent = 204,
139
+ ResetContent = 205,
140
+ PartialContent = 206,
141
+ MultiStatus = 207,
142
+ AlreadyReported = 208,
143
+ ImUsed = 226,
144
+ MultipleChoices = 300,
145
+ MovedPermanently = 301,
146
+ Found = 302,
147
+ SeeOther = 303,
148
+ NotModified = 304,
149
+ UseProxy = 305,
150
+ Unused = 306,
151
+ TemporaryRedirect = 307,
152
+ PermanentRedirect = 308,
153
+ BadRequest = 400,
154
+ Unauthorized = 401,
155
+ PaymentRequired = 402,
156
+ Forbidden = 403,
157
+ NotFound = 404,
158
+ MethodNotAllowed = 405,
159
+ NotAcceptable = 406,
160
+ ProxyAuthenticationRequired = 407,
161
+ RequestTimeout = 408,
162
+ Conflict = 409,
163
+ Gone = 410,
164
+ LengthRequired = 411,
165
+ PreconditionFailed = 412,
166
+ PayloadTooLarge = 413,
167
+ UriTooLong = 414,
168
+ UnsupportedMediaType = 415,
169
+ RangeNotSatisfiable = 416,
170
+ ExpectationFailed = 417,
171
+ ImATeapot = 418,
172
+ MisdirectedRequest = 421,
173
+ UnprocessableEntity = 422,
174
+ Locked = 423,
175
+ FailedDependency = 424,
176
+ TooEarly = 425,
177
+ UpgradeRequired = 426,
178
+ PreconditionRequired = 428,
179
+ TooManyRequests = 429,
180
+ RequestHeaderFieldsTooLarge = 431,
181
+ UnavailableForLegalReasons = 451,
182
+ InternalServerError = 500,
183
+ NotImplemented = 501,
184
+ BadGateway = 502,
185
+ ServiceUnavailable = 503,
186
+ GatewayTimeout = 504,
187
+ HttpVersionNotSupported = 505,
188
+ VariantAlsoNegotiates = 506,
189
+ InsufficientStorage = 507,
190
+ LoopDetected = 508,
191
+ NotExtended = 510,
192
+ NetworkAuthenticationRequired = 511,
193
+ }
194
+
195
+ type InternalAxiosError<T = unknown, D = any> = AxiosError<T, D>;
196
+
197
+ declare namespace axios {
198
+ type AxiosError<T = unknown, D = any> = InternalAxiosError<T, D>;
199
+
200
+ type RawAxiosRequestHeaders = Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders>;
201
+
202
+ type AxiosRequestHeaders = Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders> & AxiosHeaders;
203
+
204
+ type RawAxiosResponseHeaders = Partial<Record<string, string> & {
205
+ "set-cookie"?: string[]
206
+ }>;
207
+
208
+ type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;
209
+
210
+ interface AxiosRequestTransformer {
211
+ (this: AxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
212
+ }
213
+
214
+ interface AxiosResponseTransformer {
215
+ (this: AxiosRequestConfig, data: any, headers: AxiosResponseHeaders, status?: number): any;
216
+ }
217
+
218
+ interface AxiosAdapter {
219
+ (config: AxiosRequestConfig): AxiosPromise;
220
+ }
221
+
222
+ interface AxiosBasicCredentials {
223
+ username: string;
224
+ password: string;
225
+ }
226
+
227
+ interface AxiosProxyConfig {
228
+ host: string;
229
+ port: number;
230
+ auth?: {
231
+ username: string;
232
+ password: string;
233
+ };
234
+ protocol?: string;
235
+ }
236
+
237
+ type Method =
238
+ | 'get' | 'GET'
239
+ | 'delete' | 'DELETE'
240
+ | 'head' | 'HEAD'
241
+ | 'options' | 'OPTIONS'
242
+ | 'post' | 'POST'
243
+ | 'put' | 'PUT'
244
+ | 'patch' | 'PATCH'
245
+ | 'purge' | 'PURGE'
246
+ | 'link' | 'LINK'
247
+ | 'unlink' | 'UNLINK';
248
+
249
+ type ResponseType =
250
+ | 'arraybuffer'
251
+ | 'blob'
252
+ | 'document'
253
+ | 'json'
254
+ | 'text'
255
+ | 'stream';
256
+
257
+ type responseEncoding =
258
+ | 'ascii' | 'ASCII'
259
+ | 'ansi' | 'ANSI'
260
+ | 'binary' | 'BINARY'
261
+ | 'base64' | 'BASE64'
262
+ | 'base64url' | 'BASE64URL'
263
+ | 'hex' | 'HEX'
264
+ | 'latin1' | 'LATIN1'
265
+ | 'ucs-2' | 'UCS-2'
266
+ | 'ucs2' | 'UCS2'
267
+ | 'utf-8' | 'UTF-8'
268
+ | 'utf8' | 'UTF8'
269
+ | 'utf16le' | 'UTF16LE';
270
+
271
+ interface TransitionalOptions {
272
+ silentJSONParsing?: boolean;
273
+ forcedJSONParsing?: boolean;
274
+ clarifyTimeoutError?: boolean;
275
+ }
276
+
277
+ interface GenericAbortSignal {
278
+ readonly aborted: boolean;
279
+ onabort?: ((...args: any) => any) | null;
280
+ addEventListener?: (...args: any) => any;
281
+ removeEventListener?: (...args: any) => any;
282
+ }
283
+
284
+ interface FormDataVisitorHelpers {
285
+ defaultVisitor: SerializerVisitor;
286
+ convertValue: (value: any) => any;
287
+ isVisitable: (value: any) => boolean;
288
+ }
289
+
290
+ interface SerializerVisitor {
291
+ (
292
+ this: GenericFormData,
293
+ value: any,
294
+ key: string | number,
295
+ path: null | Array<string | number>,
296
+ helpers: FormDataVisitorHelpers
297
+ ): boolean;
298
+ }
299
+
300
+ interface SerializerOptions {
301
+ visitor?: SerializerVisitor;
302
+ dots?: boolean;
303
+ metaTokens?: boolean;
304
+ indexes?: boolean | null;
305
+ }
306
+
307
+ // tslint:disable-next-line
308
+ interface FormSerializerOptions extends SerializerOptions {
309
+ }
310
+
311
+ interface ParamEncoder {
312
+ (value: any, defaultEncoder: (value: any) => any): any;
313
+ }
314
+
315
+ interface CustomParamsSerializer {
316
+ (params: Record<string, any>, options?: ParamsSerializerOptions): string;
317
+ }
318
+
319
+ interface ParamsSerializerOptions extends SerializerOptions {
320
+ encode?: ParamEncoder;
321
+ serialize?: CustomParamsSerializer;
322
+ }
323
+
324
+ interface AxiosProgressEvent {
325
+ loaded: number;
326
+ total?: number;
327
+ progress?: number;
328
+ bytes: number;
329
+ rate?: number;
330
+ estimated?: number;
331
+ upload?: boolean;
332
+ download?: boolean;
333
+ }
334
+
335
+ interface AxiosRequestConfig<D = any> {
336
+ url?: string;
337
+ method?: Method | string;
338
+ baseURL?: string;
339
+ transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
340
+ transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
341
+ headers?: RawAxiosRequestHeaders;
342
+ params?: any;
343
+ paramsSerializer?: ParamsSerializerOptions;
344
+ data?: D;
345
+ timeout?: Milliseconds;
346
+ timeoutErrorMessage?: string;
347
+ withCredentials?: boolean;
348
+ adapter?: AxiosAdapter;
349
+ auth?: AxiosBasicCredentials;
350
+ responseType?: ResponseType;
351
+ responseEncoding?: responseEncoding | string;
352
+ xsrfCookieName?: string;
353
+ xsrfHeaderName?: string;
354
+ onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
355
+ onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
356
+ maxContentLength?: number;
357
+ validateStatus?: ((status: number) => boolean) | null;
358
+ maxBodyLength?: number;
359
+ maxRedirects?: number;
360
+ maxRate?: number | [MaxUploadRate, MaxDownloadRate];
361
+ beforeRedirect?: (options: Record<string, any>, responseDetails: {headers: Record<string, string>}) => void;
362
+ socketPath?: string | null;
363
+ httpAgent?: any;
364
+ httpsAgent?: any;
365
+ proxy?: AxiosProxyConfig | false;
366
+ cancelToken?: CancelToken;
367
+ decompress?: boolean;
368
+ transitional?: TransitionalOptions;
369
+ signal?: GenericAbortSignal;
370
+ insecureHTTPParser?: boolean;
371
+ env?: {
372
+ FormData?: new (...args: any[]) => object;
373
+ };
374
+ formSerializer?: FormSerializerOptions;
375
+ }
376
+
377
+ interface HeadersDefaults {
378
+ common: RawAxiosRequestHeaders;
379
+ delete: RawAxiosRequestHeaders;
380
+ get: RawAxiosRequestHeaders;
381
+ head: RawAxiosRequestHeaders;
382
+ post: RawAxiosRequestHeaders;
383
+ put: RawAxiosRequestHeaders;
384
+ patch: RawAxiosRequestHeaders;
385
+ options?: RawAxiosRequestHeaders;
386
+ purge?: RawAxiosRequestHeaders;
387
+ link?: RawAxiosRequestHeaders;
388
+ unlink?: RawAxiosRequestHeaders;
389
+ }
390
+
391
+ interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
392
+ headers: HeadersDefaults;
393
+ }
394
+
395
+ interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
396
+ headers?: RawAxiosRequestHeaders | Partial<HeadersDefaults>;
397
+ }
398
+
399
+ interface AxiosResponse<T = any, D = any> {
400
+ data: T;
401
+ status: number;
402
+ statusText: string;
403
+ headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
404
+ config: AxiosRequestConfig<D>;
405
+ request?: any;
406
+ }
407
+
408
+ type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
409
+
410
+ interface CancelStatic {
411
+ new (message?: string): Cancel;
412
+ }
413
+
414
+ interface Cancel {
415
+ message: string | undefined;
416
+ }
417
+
418
+ interface Canceler {
419
+ (message?: string, config?: AxiosRequestConfig, request?: any): void;
420
+ }
421
+
422
+ interface CancelTokenStatic {
423
+ new (executor: (cancel: Canceler) => void): CancelToken;
424
+ source(): CancelTokenSource;
425
+ }
426
+
427
+ interface CancelToken {
428
+ promise: Promise<Cancel>;
429
+ reason?: Cancel;
430
+ throwIfRequested(): void;
431
+ }
432
+
433
+ interface CancelTokenSource {
434
+ token: CancelToken;
435
+ cancel: Canceler;
436
+ }
437
+
438
+ interface AxiosInterceptorOptions {
439
+ synchronous?: boolean;
440
+ runWhen?: (config: AxiosRequestConfig) => boolean;
441
+ }
442
+
443
+ interface AxiosInterceptorManager<V> {
444
+ use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any, options?: AxiosInterceptorOptions): number;
445
+ eject(id: number): void;
446
+ clear(): void;
447
+ }
448
+
449
+ interface AxiosInstance extends Axios {
450
+ <T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
451
+ <T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
452
+
453
+ defaults: Omit<AxiosDefaults, 'headers'> & {
454
+ headers: HeadersDefaults & {
455
+ [key: string]: AxiosHeaderValue
456
+ }
457
+ };
458
+ }
459
+
460
+ interface GenericFormData {
461
+ append(name: string, value: any, options?: any): any;
462
+ }
463
+
464
+ interface GenericHTMLFormElement {
465
+ name: string;
466
+ method: string;
467
+ submit(): void;
468
+ }
469
+
470
+ interface AxiosStatic extends AxiosInstance {
471
+ create(config?: CreateAxiosDefaults): AxiosInstance;
472
+ Cancel: CancelStatic;
473
+ CancelToken: CancelTokenStatic;
474
+ Axios: typeof Axios;
475
+ AxiosError: typeof AxiosError;
476
+ CanceledError: typeof CanceledError;
477
+ HttpStatusCode: typeof HttpStatusCode;
478
+ readonly VERSION: string;
479
+ isCancel(value: any): value is Cancel;
480
+ all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
481
+ spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
482
+ isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
483
+ toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
484
+ formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
485
+ }
486
+ }
487
+
488
+ declare const axios: axios.AxiosStatic;
489
+
490
+ export = axios;
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // TypeScript Version: 4.1
1
+ // TypeScript Version: 4.7
2
2
  type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
3
3
  type RawAxiosHeaders = Record<string, AxiosHeaderValue>;
4
4
 
@@ -21,8 +21,7 @@ type AxiosHeaderTester = (matcher?: AxiosHeaderMatcher) => boolean;
21
21
 
22
22
  export class AxiosHeaders {
23
23
  constructor(
24
- headers?: RawAxiosHeaders | AxiosHeaders,
25
- defaultHeaders?: RawAxiosHeaders | AxiosHeaders
24
+ headers?: RawAxiosHeaders | AxiosHeaders
26
25
  );
27
26
 
28
27
  set(headerName?: string, value?: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
@@ -39,12 +38,16 @@ export class AxiosHeaders {
39
38
 
40
39
  normalize(format: boolean): AxiosHeaders;
41
40
 
41
+ concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string>): AxiosHeaders;
42
+
42
43
  toJSON(asStrings?: boolean): RawAxiosHeaders;
43
44
 
44
45
  static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
45
46
 
46
47
  static accessor(header: string | string[]): AxiosHeaders;
47
48
 
49
+ static concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string>): AxiosHeaders;
50
+
48
51
  setContentType: AxiosHeaderSetter;
49
52
  getContentType: AxiosHeaderGetter;
50
53
  hasContentType: AxiosHeaderTester;
@@ -269,10 +272,15 @@ export interface AxiosProgressEvent {
269
272
  estimated?: number;
270
273
  upload?: boolean;
271
274
  download?: boolean;
275
+ event?: ProgressEvent;
272
276
  }
273
277
 
274
278
  type Milliseconds = number;
275
279
 
280
+ type AxiosAdapterName = 'xhr' | 'http' | string;
281
+
282
+ type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
283
+
276
284
  export interface AxiosRequestConfig<D = any> {
277
285
  url?: string;
278
286
  method?: Method | string;
@@ -286,7 +294,7 @@ export interface AxiosRequestConfig<D = any> {
286
294
  timeout?: Milliseconds;
287
295
  timeoutErrorMessage?: string;
288
296
  withCredentials?: boolean;
289
- adapter?: AxiosAdapter;
297
+ adapter?: AxiosAdapterConfig | AxiosAdapterConfig[];
290
298
  auth?: AxiosBasicCredentials;
291
299
  responseType?: ResponseType;
292
300
  responseEncoding?: responseEncoding | string;
@@ -416,7 +424,7 @@ export interface AxiosInterceptorOptions {
416
424
  }
417
425
 
418
426
  export interface AxiosInterceptorManager<V> {
419
- use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any, options?: AxiosInterceptorOptions): number;
427
+ use(onFulfilled?: ((value: V) => V | Promise<V>) | null, onRejected?: ((error: any) => any) | null, options?: AxiosInterceptorOptions): number;
420
428
  eject(id: number): void;
421
429
  clear(): void;
422
430
  }
@@ -463,6 +471,18 @@ export interface GenericHTMLFormElement {
463
471
  submit(): void;
464
472
  }
465
473
 
474
+ export function toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
475
+
476
+ export function formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
477
+
478
+ export function isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
479
+
480
+ export function spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
481
+
482
+ export function isCancel(value: any): value is Cancel;
483
+
484
+ export function all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
485
+
466
486
  export interface AxiosStatic extends AxiosInstance {
467
487
  create(config?: CreateAxiosDefaults): AxiosInstance;
468
488
  Cancel: CancelStatic;
@@ -470,12 +490,14 @@ export interface AxiosStatic extends AxiosInstance {
470
490
  Axios: typeof Axios;
471
491
  AxiosError: typeof AxiosError;
472
492
  readonly VERSION: string;
473
- isCancel(value: any): value is Cancel;
474
- all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
475
- spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
476
- isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
477
- toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
478
- formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
493
+ isCancel: typeof isCancel;
494
+ all: typeof all;
495
+ spread: typeof spread;
496
+ isAxiosError: typeof isAxiosError;
497
+ toFormData: typeof toFormData;
498
+ formToJSON: typeof formToJSON;
499
+ CanceledError: typeof CanceledError;
500
+ AxiosHeaders: typeof AxiosHeaders;
479
501
  }
480
502
 
481
503
  declare const axios: AxiosStatic;
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import axios from './lib/axios.js';
2
2
 
3
+ // This module is intended to unwrap Axios default export as named.
3
4
  // Keep top-level export same with static properties
4
5
  // so that it can keep same with es module or cjs
5
6
  const {
@@ -13,11 +14,13 @@ const {
13
14
  Cancel,
14
15
  isAxiosError,
15
16
  spread,
16
- toFormData
17
+ toFormData,
18
+ AxiosHeaders,
19
+ formToJSON
17
20
  } = axios;
18
21
 
19
- export default axios;
20
22
  export {
23
+ axios as default,
21
24
  Axios,
22
25
  AxiosError,
23
26
  CanceledError,
@@ -28,5 +31,7 @@ export {
28
31
  Cancel,
29
32
  isAxiosError,
30
33
  spread,
31
- toFormData
34
+ toFormData,
35
+ AxiosHeaders,
36
+ formToJSON
32
37
  }
package/karma.conf.cjs CHANGED
@@ -129,7 +129,7 @@ module.exports = function(config) {
129
129
  );
130
130
  browsers = ['Firefox'];
131
131
  } else if (process.env.GITHUB_ACTIONS === 'true') {
132
- console.log('Running ci on Github Actions.');
132
+ console.log('Running ci on GitHub Actions.');
133
133
  browsers = ['FirefoxHeadless', 'ChromeHeadless'];
134
134
  } else {
135
135
  browsers = browsers || ['Chrome'];
@@ -0,0 +1,59 @@
1
+ import utils from '../utils.js';
2
+ import httpAdapter from './http.js';
3
+ import xhrAdapter from './xhr.js';
4
+ import AxiosError from "../core/AxiosError.js";
5
+
6
+ const knownAdapters = {
7
+ http: httpAdapter,
8
+ xhr: xhrAdapter
9
+ }
10
+
11
+ utils.forEach(knownAdapters, (fn, value) => {
12
+ if(fn) {
13
+ try {
14
+ Object.defineProperty(fn, 'name', {value});
15
+ } catch (e) {
16
+ // eslint-disable-next-line no-empty
17
+ }
18
+ Object.defineProperty(fn, 'adapterName', {value});
19
+ }
20
+ });
21
+
22
+ export default {
23
+ getAdapter: (adapters) => {
24
+ adapters = utils.isArray(adapters) ? adapters : [adapters];
25
+
26
+ const {length} = adapters;
27
+ let nameOrAdapter;
28
+ let adapter;
29
+
30
+ for (let i = 0; i < length; i++) {
31
+ nameOrAdapter = adapters[i];
32
+ if((adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter)) {
33
+ break;
34
+ }
35
+ }
36
+
37
+ if (!adapter) {
38
+ if (adapter === false) {
39
+ throw new AxiosError(
40
+ `Adapter ${nameOrAdapter} is not supported by the environment`,
41
+ 'ERR_NOT_SUPPORT'
42
+ );
43
+ }
44
+
45
+ throw new Error(
46
+ utils.hasOwnProp(knownAdapters, nameOrAdapter) ?
47
+ `Adapter '${nameOrAdapter}' is not available in the build` :
48
+ `Unknown adapter '${nameOrAdapter}'`
49
+ );
50
+ }
51
+
52
+ if (!utils.isFunction(adapter)) {
53
+ throw new TypeError('adapter is not a function');
54
+ }
55
+
56
+ return adapter;
57
+ },
58
+ adapters: knownAdapters
59
+ }