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