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