index.d.ts 7.4 KB

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