index.d.ts 23 KB

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