index.d.ts 17 KB

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