index.d.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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;
  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. socketPath?: string | null;
  90. httpAgent?: any;
  91. httpsAgent?: any;
  92. proxy?: AxiosProxyConfig | false;
  93. cancelToken?: CancelToken;
  94. decompress?: boolean;
  95. transitional?: TransitionalOptions;
  96. signal?: AbortSignal;
  97. insecureHTTPParser?: boolean;
  98. }
  99. export interface HeadersDefaults {
  100. common: AxiosRequestHeaders;
  101. delete: AxiosRequestHeaders;
  102. get: AxiosRequestHeaders;
  103. head: AxiosRequestHeaders;
  104. post: AxiosRequestHeaders;
  105. put: AxiosRequestHeaders;
  106. patch: AxiosRequestHeaders;
  107. options?: AxiosRequestHeaders;
  108. purge?: AxiosRequestHeaders;
  109. link?: AxiosRequestHeaders;
  110. unlink?: AxiosRequestHeaders;
  111. }
  112. export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
  113. headers: HeadersDefaults;
  114. }
  115. export interface AxiosResponse<T = any, D = any> {
  116. data: T;
  117. status: number;
  118. statusText: string;
  119. headers: AxiosResponseHeaders;
  120. config: AxiosRequestConfig<D>;
  121. request?: any;
  122. }
  123. export interface AxiosError<T = any, D = any> extends Error {
  124. config: AxiosRequestConfig<D>;
  125. code?: string;
  126. request?: any;
  127. response?: AxiosResponse<T, D>;
  128. isAxiosError: boolean;
  129. toJSON: () => object;
  130. }
  131. export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
  132. }
  133. export interface CancelStatic {
  134. new (message?: string): Cancel;
  135. }
  136. export interface Cancel {
  137. message: string | undefined;
  138. }
  139. export interface Canceler {
  140. (message?: string): void;
  141. }
  142. export interface CancelTokenStatic {
  143. new (executor: (cancel: Canceler) => void): CancelToken;
  144. source(): CancelTokenSource;
  145. }
  146. export interface CancelToken {
  147. promise: Promise<Cancel>;
  148. reason?: Cancel;
  149. throwIfRequested(): void;
  150. }
  151. export interface CancelTokenSource {
  152. token: CancelToken;
  153. cancel: Canceler;
  154. }
  155. export interface AxiosInterceptorManager<V> {
  156. use<T = V>(onFulfilled?: (value: V) => T | Promise<T>, onRejected?: (error: any) => any): number;
  157. eject(id: number): void;
  158. }
  159. export class Axios {
  160. constructor(config?: AxiosRequestConfig);
  161. defaults: AxiosDefaults;
  162. interceptors: {
  163. request: AxiosInterceptorManager<AxiosRequestConfig>;
  164. response: AxiosInterceptorManager<AxiosResponse>;
  165. };
  166. getUri(config?: AxiosRequestConfig): string;
  167. request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
  168. get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
  169. delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
  170. head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
  171. options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
  172. post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
  173. put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
  174. patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
  175. }
  176. export interface AxiosInstance extends Axios {
  177. (config: AxiosRequestConfig): AxiosPromise;
  178. (url: string, config?: AxiosRequestConfig): AxiosPromise;
  179. }
  180. export interface AxiosStatic extends AxiosInstance {
  181. create(config?: AxiosRequestConfig): AxiosInstance;
  182. Cancel: CancelStatic;
  183. CancelToken: CancelTokenStatic;
  184. Axios: typeof Axios;
  185. readonly VERSION: string;
  186. isCancel(value: any): boolean;
  187. all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
  188. spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
  189. isAxiosError(payload: any): payload is AxiosError;
  190. }
  191. declare const axios: AxiosStatic;
  192. export default axios;