index.d.cts 20 KB

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