1 |
|
2 | export type AxiosRequestHeaders = Record<string, string | number | boolean>;
|
3 |
|
4 | export type AxiosResponseHeaders = Record<string, string> & {
|
5 | "set-cookie"?: string[]
|
6 | };
|
7 |
|
8 | export interface AxiosRequestTransformer {
|
9 | (data: any, headers?: AxiosRequestHeaders): any;
|
10 | }
|
11 |
|
12 | export interface AxiosResponseTransformer {
|
13 | (data: any, headers?: AxiosResponseHeaders): any;
|
14 | }
|
15 |
|
16 | export interface AxiosAdapter {
|
17 | (config: AxiosRequestConfig): AxiosPromise;
|
18 | }
|
19 |
|
20 | export interface AxiosBasicCredentials {
|
21 | username: string;
|
22 | password: string;
|
23 | }
|
24 |
|
25 | export interface AxiosProxyConfig {
|
26 | host: string;
|
27 | port: number;
|
28 | auth?: {
|
29 | username: string;
|
30 | password: string;
|
31 | };
|
32 | protocol?: string;
|
33 | }
|
34 |
|
35 | export type Method =
|
36 | | 'get' | 'GET'
|
37 | | 'delete' | 'DELETE'
|
38 | | 'head' | 'HEAD'
|
39 | | 'options' | 'OPTIONS'
|
40 | | 'post' | 'POST'
|
41 | | 'put' | 'PUT'
|
42 | | 'patch' | 'PATCH'
|
43 | | 'purge' | 'PURGE'
|
44 | | 'link' | 'LINK'
|
45 | | 'unlink' | 'UNLINK';
|
46 |
|
47 | export type ResponseType =
|
48 | | 'arraybuffer'
|
49 | | 'blob'
|
50 | | 'document'
|
51 | | 'json'
|
52 | | 'text'
|
53 | | 'stream';
|
54 |
|
55 | export type responseEncoding =
|
56 | | 'ascii' | 'ASCII'
|
57 | | 'ansi' | 'ANSI'
|
58 | | 'binary' | 'BINARY'
|
59 | | 'base64' | 'BASE64'
|
60 | | 'base64url' | 'BASE64URL'
|
61 | | 'hex' | 'HEX'
|
62 | | 'latin1' | 'LATIN1'
|
63 | | 'ucs-2' | 'UCS-2'
|
64 | | 'ucs2' | 'UCS2'
|
65 | | 'utf-8' | 'UTF-8'
|
66 | | 'utf8' | 'UTF8'
|
67 | | 'utf16le' | 'UTF16LE';
|
68 |
|
69 | export interface TransitionalOptions {
|
70 | silentJSONParsing?: boolean;
|
71 | forcedJSONParsing?: boolean;
|
72 | clarifyTimeoutError?: boolean;
|
73 | }
|
74 |
|
75 | export interface AxiosRequestConfig<D = any> {
|
76 | url?: string;
|
77 | method?: Method | string;
|
78 | baseURL?: string;
|
79 | transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
|
80 | transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
81 | headers?: AxiosRequestHeaders;
|
82 | params?: any;
|
83 | paramsSerializer?: (params: any) => string;
|
84 | data?: D;
|
85 | timeout?: number;
|
86 | timeoutErrorMessage?: string;
|
87 | withCredentials?: boolean;
|
88 | adapter?: AxiosAdapter;
|
89 | auth?: AxiosBasicCredentials;
|
90 | responseType?: ResponseType;
|
91 | responseEncoding?: responseEncoding | string;
|
92 | xsrfCookieName?: string;
|
93 | xsrfHeaderName?: string;
|
94 | onUploadProgress?: (progressEvent: any) => void;
|
95 | onDownloadProgress?: (progressEvent: any) => void;
|
96 | maxContentLength?: number;
|
97 | validateStatus?: ((status: number) => boolean) | null;
|
98 | maxBodyLength?: number;
|
99 | maxRedirects?: number;
|
100 | beforeRedirect?: (options: Record<string, any>, responseDetails: {headers: Record<string, string>}) => void;
|
101 | socketPath?: string | null;
|
102 | httpAgent?: any;
|
103 | httpsAgent?: any;
|
104 | proxy?: AxiosProxyConfig | false;
|
105 | cancelToken?: CancelToken;
|
106 | decompress?: boolean;
|
107 | transitional?: TransitionalOptions;
|
108 | signal?: AbortSignal;
|
109 | insecureHTTPParser?: boolean;
|
110 | env?: {
|
111 | FormData?: new (...args: any[]) => object;
|
112 | };
|
113 | }
|
114 |
|
115 | export interface HeadersDefaults {
|
116 | common: AxiosRequestHeaders;
|
117 | delete: AxiosRequestHeaders;
|
118 | get: AxiosRequestHeaders;
|
119 | head: AxiosRequestHeaders;
|
120 | post: AxiosRequestHeaders;
|
121 | put: AxiosRequestHeaders;
|
122 | patch: AxiosRequestHeaders;
|
123 | options?: AxiosRequestHeaders;
|
124 | purge?: AxiosRequestHeaders;
|
125 | link?: AxiosRequestHeaders;
|
126 | unlink?: AxiosRequestHeaders;
|
127 | }
|
128 |
|
129 | export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
130 | headers: HeadersDefaults;
|
131 | }
|
132 |
|
133 | export interface AxiosResponse<T = any, D = any> {
|
134 | data: T;
|
135 | status: number;
|
136 | statusText: string;
|
137 | headers: AxiosResponseHeaders;
|
138 | config: AxiosRequestConfig<D>;
|
139 | request?: any;
|
140 | }
|
141 |
|
142 | export class AxiosError<T = unknown, D = any> extends Error {
|
143 | constructor(
|
144 | message?: string,
|
145 | code?: string,
|
146 | config?: AxiosRequestConfig<D>,
|
147 | request?: any,
|
148 | response?: AxiosResponse<T, D>
|
149 | );
|
150 |
|
151 | config: AxiosRequestConfig<D>;
|
152 | code?: string;
|
153 | request?: any;
|
154 | response?: AxiosResponse<T, D>;
|
155 | isAxiosError: boolean;
|
156 | status?: string;
|
157 | toJSON: () => object;
|
158 | static readonly ERR_FR_TOO_MANY_REDIRECTS = "ERR_FR_TOO_MANY_REDIRECTS";
|
159 | static readonly ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
|
160 | static readonly ERR_BAD_OPTION = "ERR_BAD_OPTION";
|
161 | static readonly ERR_NETWORK = "ERR_NETWORK";
|
162 | static readonly ERR_DEPRECATED = "ERR_DEPRECATED";
|
163 | static readonly ERR_BAD_RESPONSE = "ERR_BAD_RESPONSE";
|
164 | static readonly ERR_BAD_REQUEST = "ERR_BAD_REQUEST";
|
165 | static readonly ERR_CANCELED = "ERR_CANCELED";
|
166 | static readonly ECONNABORTED = "ECONNABORTED";
|
167 | static readonly ETIMEDOUT = "ETIMEDOUT";
|
168 | }
|
169 |
|
170 | export class CanceledError<T> extends AxiosError<T> {
|
171 | }
|
172 |
|
173 | export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
|
174 | }
|
175 |
|
176 | export interface CancelStatic {
|
177 | new (message?: string): Cancel;
|
178 | }
|
179 |
|
180 | export interface Cancel {
|
181 | message: string | undefined;
|
182 | }
|
183 |
|
184 | export interface Canceler {
|
185 | (message?: string): void;
|
186 | }
|
187 |
|
188 | export interface CancelTokenStatic {
|
189 | new (executor: (cancel: Canceler) => void): CancelToken;
|
190 | source(): CancelTokenSource;
|
191 | }
|
192 |
|
193 | export interface CancelToken {
|
194 | promise: Promise<Cancel>;
|
195 | reason?: Cancel;
|
196 | throwIfRequested(): void;
|
197 | }
|
198 |
|
199 | export interface CancelTokenSource {
|
200 | token: CancelToken;
|
201 | cancel: Canceler;
|
202 | }
|
203 |
|
204 | export interface AxiosInterceptorOptions {
|
205 | synchronous?: boolean;
|
206 | runWhen?: (config: AxiosRequestConfig) => boolean;
|
207 | }
|
208 |
|
209 | export interface AxiosInterceptorManager<V> {
|
210 | use<T = V>(onFulfilled?: (value: V) => T | Promise<T>, onRejected?: (error: any) => any, options?: AxiosInterceptorOptions): number;
|
211 | eject(id: number): void;
|
212 | }
|
213 |
|
214 | export class Axios {
|
215 | constructor(config?: AxiosRequestConfig);
|
216 | defaults: AxiosDefaults;
|
217 | interceptors: {
|
218 | request: AxiosInterceptorManager<AxiosRequestConfig>;
|
219 | response: AxiosInterceptorManager<AxiosResponse>;
|
220 | };
|
221 | getUri(config?: AxiosRequestConfig): string;
|
222 | request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
223 | get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
224 | delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
225 | head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
226 | options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
227 | post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
228 | put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
229 | patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
230 | postForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
231 | putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
232 | patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
|
233 | }
|
234 |
|
235 | export interface AxiosInstance extends Axios {
|
236 | (config: AxiosRequestConfig): AxiosPromise;
|
237 | (url: string, config?: AxiosRequestConfig): AxiosPromise;
|
238 | }
|
239 |
|
240 | export interface AxiosStatic extends AxiosInstance {
|
241 | create(config?: AxiosRequestConfig): AxiosInstance;
|
242 | Cancel: CancelStatic;
|
243 | CancelToken: CancelTokenStatic;
|
244 | Axios: typeof Axios;
|
245 | readonly VERSION: string;
|
246 | isCancel(value: any): boolean;
|
247 | all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
|
248 | spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
|
249 | isAxiosError(payload: any): payload is AxiosError;
|
250 | }
|
251 |
|
252 | declare const axios: AxiosStatic;
|
253 |
|
254 | export default axios;
|