index.d.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  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. /** @deprecated Use `ContentTooLarge` instead. */
  174. PayloadTooLarge = 413,
  175. ContentTooLarge = 413,
  176. UriTooLong = 414,
  177. UnsupportedMediaType = 415,
  178. RangeNotSatisfiable = 416,
  179. ExpectationFailed = 417,
  180. ImATeapot = 418,
  181. MisdirectedRequest = 421,
  182. /** @deprecated Use `UnprocessableContent` instead. */
  183. UnprocessableEntity = 422,
  184. UnprocessableContent = 422,
  185. Locked = 423,
  186. FailedDependency = 424,
  187. TooEarly = 425,
  188. UpgradeRequired = 426,
  189. PreconditionRequired = 428,
  190. TooManyRequests = 429,
  191. RequestHeaderFieldsTooLarge = 431,
  192. UnavailableForLegalReasons = 451,
  193. InternalServerError = 500,
  194. NotImplemented = 501,
  195. BadGateway = 502,
  196. ServiceUnavailable = 503,
  197. GatewayTimeout = 504,
  198. HttpVersionNotSupported = 505,
  199. VariantAlsoNegotiates = 506,
  200. InsufficientStorage = 507,
  201. LoopDetected = 508,
  202. NotExtended = 510,
  203. NetworkAuthenticationRequired = 511,
  204. WebServerReturnsAnUnknownError = 520,
  205. WebServerIsDown = 521,
  206. ConnectionTimedOut = 522,
  207. OriginIsUnreachable = 523,
  208. TimeoutOccurred = 524,
  209. SslHandshakeFailed = 525,
  210. InvalidSslCertificate = 526,
  211. }
  212. type UppercaseMethod =
  213. | 'GET'
  214. | 'DELETE'
  215. | 'HEAD'
  216. | 'OPTIONS'
  217. | 'POST'
  218. | 'PUT'
  219. | 'PATCH'
  220. | 'PURGE'
  221. | 'LINK'
  222. | 'UNLINK'
  223. | 'QUERY';
  224. export type Method = (UppercaseMethod | Lowercase<UppercaseMethod>) & {};
  225. export type ResponseType =
  226. | 'arraybuffer'
  227. | 'blob'
  228. | 'document'
  229. | 'json'
  230. | 'text'
  231. | 'stream'
  232. | 'formdata';
  233. type UppercaseResponseEncoding =
  234. | 'ASCII'
  235. | 'ANSI'
  236. | 'BINARY'
  237. | 'BASE64'
  238. | 'BASE64URL'
  239. | 'HEX'
  240. | 'LATIN1'
  241. | 'UCS-2'
  242. | 'UCS2'
  243. | 'UTF-8'
  244. | 'UTF8'
  245. | 'UTF16LE';
  246. export type responseEncoding = (
  247. | UppercaseResponseEncoding
  248. | Lowercase<UppercaseResponseEncoding>
  249. ) & {};
  250. export interface TransitionalOptions {
  251. silentJSONParsing?: boolean;
  252. forcedJSONParsing?: boolean;
  253. clarifyTimeoutError?: boolean;
  254. legacyInterceptorReqResOrdering?: boolean;
  255. advertiseZstdAcceptEncoding?: boolean;
  256. validateStatusUndefinedResolves?: boolean;
  257. /** Opt in to UTF-8 Basic auth usernames in XHR/Fetch config resolution. Defaults to false. */
  258. encodeBasicAuthUsername?: boolean;
  259. }
  260. export interface GenericAbortSignal {
  261. readonly aborted: boolean;
  262. onabort?: ((...args: any) => any) | null;
  263. addEventListener?: (...args: any) => any;
  264. removeEventListener?: (...args: any) => any;
  265. }
  266. export interface FormDataVisitorHelpers {
  267. defaultVisitor: SerializerVisitor;
  268. convertValue: (value: any) => any;
  269. isVisitable: (value: any) => boolean;
  270. }
  271. export interface SerializerVisitor {
  272. (
  273. this: GenericFormData,
  274. value: any,
  275. key: string | number,
  276. path: null | Array<string | number>,
  277. helpers: FormDataVisitorHelpers
  278. ): boolean;
  279. }
  280. export interface SerializerOptions {
  281. visitor?: SerializerVisitor;
  282. dots?: boolean;
  283. metaTokens?: boolean;
  284. indexes?: boolean | null;
  285. maxDepth?: number;
  286. Blob?: { new (...args: any[]): any };
  287. }
  288. // tslint:disable-next-line
  289. export interface FormSerializerOptions extends SerializerOptions {}
  290. export interface ParamEncoder {
  291. (value: any, defaultEncoder: (value: any) => any): any;
  292. }
  293. export interface CustomParamsSerializer<P = Record<string, any>> {
  294. (params: P, options?: ParamsSerializerOptions<P>): string;
  295. }
  296. export interface ParamsSerializerOptions<P = Record<string, any>> extends SerializerOptions {
  297. encode?: ParamEncoder;
  298. serialize?: CustomParamsSerializer<P>;
  299. }
  300. type MaxUploadRate = number;
  301. type MaxDownloadRate = number;
  302. type BrowserProgressEvent = any;
  303. export interface AxiosProgressEvent {
  304. loaded: number;
  305. total?: number;
  306. progress?: number;
  307. bytes: number;
  308. rate?: number;
  309. estimated?: number;
  310. upload?: boolean;
  311. download?: boolean;
  312. event?: BrowserProgressEvent;
  313. lengthComputable: boolean;
  314. }
  315. type Milliseconds = number;
  316. type AxiosAdapterName = StringLiteralsOrString<'xhr' | 'http' | 'fetch'>;
  317. type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
  318. export type AddressFamily = 4 | 6 | undefined;
  319. export interface LookupAddressEntry {
  320. address: string;
  321. family?: AddressFamily;
  322. }
  323. export type LookupAddress = string | LookupAddressEntry;
  324. export interface AxiosRequestConfig<D = any, P = any> {
  325. url?: string;
  326. method?: StringLiteralsOrString<Method>;
  327. baseURL?: string;
  328. allowAbsoluteUrls?: boolean;
  329. transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
  330. transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
  331. headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
  332. params?: P;
  333. paramsSerializer?:
  334. | ParamsSerializerOptions<unknown extends P ? Record<string, any> : P>
  335. | CustomParamsSerializer<unknown extends P ? Record<string, any> : P>;
  336. data?: D;
  337. timeout?: Milliseconds;
  338. timeoutErrorMessage?: string;
  339. withCredentials?: boolean;
  340. adapter?: AxiosAdapterConfig | AxiosAdapterConfig[];
  341. auth?: AxiosBasicCredentials;
  342. responseType?: ResponseType;
  343. responseEncoding?: StringLiteralsOrString<responseEncoding>;
  344. xsrfCookieName?: string;
  345. xsrfHeaderName?: string;
  346. onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
  347. onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
  348. maxContentLength?: number;
  349. validateStatus?: ((status: number) => boolean) | null;
  350. maxBodyLength?: number;
  351. maxRedirects?: number;
  352. maxRate?: number | [MaxUploadRate, MaxDownloadRate];
  353. beforeRedirect?: (
  354. options: Record<string, any>,
  355. responseDetails: {
  356. headers: Record<string, string>;
  357. statusCode: HttpStatusCode;
  358. },
  359. requestDetails: {
  360. headers: Record<string, string>;
  361. url: string;
  362. method: string;
  363. },
  364. ) => void;
  365. socketPath?: string | null;
  366. allowedSocketPaths?: string | string[] | null;
  367. transport?: any;
  368. httpAgent?: any;
  369. httpsAgent?: any;
  370. proxy?: AxiosProxyConfig | false;
  371. cancelToken?: CancelToken | undefined;
  372. decompress?: boolean;
  373. transitional?: TransitionalOptions;
  374. signal?: GenericAbortSignal;
  375. insecureHTTPParser?: boolean;
  376. env?: {
  377. FormData?: new (...args: any[]) => object;
  378. fetch?: (input: URL | Request | string, init?: RequestInit) => Promise<Response>;
  379. Request?: new (input: URL | Request | string, init?: RequestInit) => Request;
  380. /**
  381. * Custom Response constructor for the fetch adapter.
  382. * When response-body streaming is supported, must also accept
  383. * `ReadableStream<Uint8Array>` bodies at runtime for `onDownloadProgress`,
  384. * enabled `maxContentLength` limits, or cancellation/timeout tracking with
  385. * `responseType: 'stream'` or `'response'`.
  386. * The body parameter retains its legacy type for compatibility.
  387. */
  388. Response?: new (
  389. body?: ArrayBuffer | ArrayBufferView | Blob | FormData | URLSearchParams | string | null,
  390. init?: ResponseInit
  391. ) => Response;
  392. };
  393. formSerializer?: FormSerializerOptions;
  394. family?: AddressFamily;
  395. lookup?:
  396. | ((
  397. hostname: string,
  398. options: object,
  399. cb: (
  400. err: Error | null,
  401. address: LookupAddress | LookupAddress[],
  402. family?: AddressFamily
  403. ) => void
  404. ) => void)
  405. | ((
  406. hostname: string,
  407. options: object
  408. ) => Promise<
  409. [address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress
  410. >);
  411. withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig<D, P>) => boolean | undefined);
  412. parseReviver?: (this: any, key: string, value: any, context?: { source?: string }) => any;
  413. fetchOptions?: Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'> | Record<string, any>;
  414. httpVersion?: 1 | 2;
  415. http2Options?: Record<string, any> & {
  416. sessionTimeout?: number;
  417. };
  418. formDataHeaderPolicy?: 'legacy' | 'content-only';
  419. redact?: string[];
  420. sensitiveHeaders?: string[];
  421. }
  422. // Alias
  423. export type RawAxiosRequestConfig<D = any, P = any> = AxiosRequestConfig<D, P>;
  424. export interface InternalAxiosRequestConfig<D = any, P = any> extends AxiosRequestConfig<D, P> {
  425. headers: AxiosRequestHeaders;
  426. }
  427. export interface HeadersDefaults {
  428. common: RawAxiosRequestHeaders;
  429. delete: RawAxiosRequestHeaders;
  430. get: RawAxiosRequestHeaders;
  431. head: RawAxiosRequestHeaders;
  432. post: RawAxiosRequestHeaders;
  433. put: RawAxiosRequestHeaders;
  434. patch: RawAxiosRequestHeaders;
  435. options?: RawAxiosRequestHeaders;
  436. purge?: RawAxiosRequestHeaders;
  437. link?: RawAxiosRequestHeaders;
  438. unlink?: RawAxiosRequestHeaders;
  439. query?: RawAxiosRequestHeaders;
  440. }
  441. export interface AxiosDefaults<D = any, P = any> extends Omit<AxiosRequestConfig<D, P>, 'headers'> {
  442. headers: HeadersDefaults;
  443. }
  444. export interface CreateAxiosDefaults<D = any, P = any> extends Omit<
  445. AxiosRequestConfig<D, P>,
  446. 'headers'
  447. > {
  448. headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
  449. }
  450. export interface AxiosResponse<T = any, D = any, H = {}, P = any> {
  451. data: T;
  452. status: number;
  453. statusText: string;
  454. /**
  455. * Whole milliseconds from adapter invocation to settlement, clamped at zero. Measured with
  456. * `performance.now()` when available, otherwise `Date.now()`.
  457. * Excludes interceptors and request/response transforms. Stream consumption is not included.
  458. */
  459. duration?: number;
  460. headers: (H & RawAxiosResponseHeaders) | AxiosResponseHeaders;
  461. config: InternalAxiosRequestConfig<D, P>;
  462. request?: any;
  463. }
  464. export class AxiosError<T = unknown, D = any, P = any> extends Error {
  465. constructor(
  466. message?: string,
  467. code?: string,
  468. config?: InternalAxiosRequestConfig<D, P>,
  469. request?: any,
  470. response?: AxiosResponse<T, D, {}, P>
  471. );
  472. config?: InternalAxiosRequestConfig<D, P>;
  473. code?: string;
  474. request?: any;
  475. response?: AxiosResponse<T, D, {}, P>;
  476. isAxiosError: boolean;
  477. status?: number;
  478. toJSON: () => object;
  479. cause?: Error;
  480. event?: BrowserProgressEvent;
  481. static from<T = unknown, D = any, P = any>(
  482. error: Error | unknown,
  483. code?: string,
  484. config?: InternalAxiosRequestConfig<D, P>,
  485. request?: any,
  486. response?: AxiosResponse<T, D, {}, P>,
  487. customProps?: object
  488. ): AxiosError<T, D, P>;
  489. static readonly ERR_FR_TOO_MANY_REDIRECTS = 'ERR_FR_TOO_MANY_REDIRECTS';
  490. static readonly ERR_BAD_OPTION_VALUE = 'ERR_BAD_OPTION_VALUE';
  491. static readonly ERR_BAD_OPTION = 'ERR_BAD_OPTION';
  492. static readonly ERR_NETWORK = 'ERR_NETWORK';
  493. static readonly ERR_DEPRECATED = 'ERR_DEPRECATED';
  494. static readonly ERR_BAD_RESPONSE = 'ERR_BAD_RESPONSE';
  495. static readonly ERR_BAD_REQUEST = 'ERR_BAD_REQUEST';
  496. static readonly ERR_NOT_SUPPORT = 'ERR_NOT_SUPPORT';
  497. static readonly ERR_INVALID_URL = 'ERR_INVALID_URL';
  498. static readonly ERR_CANCELED = 'ERR_CANCELED';
  499. static readonly ERR_FORM_DATA_DEPTH_EXCEEDED = 'ERR_FORM_DATA_DEPTH_EXCEEDED';
  500. static readonly ECONNABORTED = 'ECONNABORTED';
  501. static readonly ECONNREFUSED = 'ECONNREFUSED';
  502. static readonly ETIMEDOUT = 'ETIMEDOUT';
  503. }
  504. export class CanceledError<T, D = any, P = any> extends AxiosError<T, D, P> {
  505. constructor(message?: string, config?: InternalAxiosRequestConfig<D, P>, request?: any);
  506. readonly name: 'CanceledError';
  507. __CANCEL__?: boolean;
  508. }
  509. declare const axiosResponseDefault: unique symbol;
  510. export interface AxiosResponseDefault {
  511. readonly [axiosResponseDefault]: true;
  512. }
  513. type AxiosResponseResult<T, R, D, P> = R extends AxiosResponseDefault
  514. ? AxiosResponse<T, D, {}, P>
  515. : R;
  516. export type AxiosPromise<T = any, D = any, P = any> = Promise<AxiosResponse<T, D, {}, P>>;
  517. export interface CancelStatic {
  518. new (message?: string): Cancel;
  519. }
  520. export interface Cancel {
  521. message: string | undefined;
  522. }
  523. export interface Canceler {
  524. (message?: string, config?: AxiosRequestConfig, request?: any): void;
  525. }
  526. export interface CancelTokenStatic {
  527. new (executor: (cancel: Canceler) => void): CancelToken;
  528. source(): CancelTokenSource;
  529. }
  530. export interface CancelToken {
  531. promise: Promise<Cancel>;
  532. reason?: Cancel;
  533. throwIfRequested(): void;
  534. subscribe(listener: (cancel: Cancel | any) => void): void;
  535. unsubscribe(listener: (cancel: Cancel | any) => void): void;
  536. toAbortSignal(): AbortSignal;
  537. }
  538. export interface CancelTokenSource {
  539. token: CancelToken;
  540. cancel: Canceler;
  541. }
  542. export interface AxiosInterceptorOptions {
  543. synchronous?: boolean;
  544. runWhen?: ((config: InternalAxiosRequestConfig) => boolean) | null;
  545. }
  546. type AxiosInterceptorFulfilled<T> = (value: T) => T | Promise<T>;
  547. type AxiosInterceptorRejected = (error: any) => any;
  548. type AxiosRequestInterceptorUse<T> = (
  549. onFulfilled?: AxiosInterceptorFulfilled<T> | null,
  550. onRejected?: AxiosInterceptorRejected | null,
  551. options?: AxiosInterceptorOptions
  552. ) => number;
  553. type AxiosResponseInterceptorUse<T> = (
  554. onFulfilled?: AxiosInterceptorFulfilled<T> | null,
  555. onRejected?: AxiosInterceptorRejected | null
  556. ) => number;
  557. interface AxiosInterceptorHandler<T> {
  558. fulfilled: AxiosInterceptorFulfilled<T>;
  559. rejected?: AxiosInterceptorRejected;
  560. synchronous: boolean;
  561. runWhen?: ((config: InternalAxiosRequestConfig) => boolean) | null;
  562. }
  563. export interface AxiosInterceptorManager<V> {
  564. use: V extends AxiosResponse ? AxiosResponseInterceptorUse<V> : AxiosRequestInterceptorUse<V>;
  565. eject(id: number): void;
  566. clear(): void;
  567. handlers?: Array<AxiosInterceptorHandler<V>>;
  568. }
  569. export class Axios {
  570. constructor(config?: AxiosRequestConfig);
  571. defaults: AxiosDefaults;
  572. interceptors: {
  573. request: AxiosInterceptorManager<InternalAxiosRequestConfig>;
  574. response: AxiosInterceptorManager<AxiosResponse>;
  575. };
  576. getUri(config?: AxiosRequestConfig): string;
  577. request<T = any, R = AxiosResponseDefault, D = any, P = any>(
  578. config: AxiosRequestConfig<D, P>
  579. ): Promise<AxiosResponseResult<T, R, D, P>>;
  580. get<T = any, R = AxiosResponseDefault, D = any, P = any>(
  581. url: string,
  582. config?: AxiosRequestConfig<D, P>
  583. ): Promise<AxiosResponseResult<T, R, D, P>>;
  584. delete<T = any, R = AxiosResponseDefault, D = any, P = any>(
  585. url: string,
  586. config?: AxiosRequestConfig<D, P>
  587. ): Promise<AxiosResponseResult<T, R, D, P>>;
  588. head<T = any, R = AxiosResponseDefault, D = any, P = any>(
  589. url: string,
  590. config?: AxiosRequestConfig<D, P>
  591. ): Promise<AxiosResponseResult<T, R, D, P>>;
  592. options<T = any, R = AxiosResponseDefault, D = any, P = any>(
  593. url: string,
  594. config?: AxiosRequestConfig<D, P>
  595. ): Promise<AxiosResponseResult<T, R, D, P>>;
  596. post<T = any, R = AxiosResponseDefault, D = any, P = any>(
  597. url: string,
  598. data?: D,
  599. config?: AxiosRequestConfig<D, P>
  600. ): Promise<AxiosResponseResult<T, R, D, P>>;
  601. put<T = any, R = AxiosResponseDefault, D = any, P = any>(
  602. url: string,
  603. data?: D,
  604. config?: AxiosRequestConfig<D, P>
  605. ): Promise<AxiosResponseResult<T, R, D, P>>;
  606. patch<T = any, R = AxiosResponseDefault, D = any, P = any>(
  607. url: string,
  608. data?: D,
  609. config?: AxiosRequestConfig<D, P>
  610. ): Promise<AxiosResponseResult<T, R, D, P>>;
  611. postForm<T = any, R = AxiosResponseDefault, D = any, P = any>(
  612. url: string,
  613. data?: D,
  614. config?: AxiosRequestConfig<D, P>
  615. ): Promise<AxiosResponseResult<T, R, D, P>>;
  616. putForm<T = any, R = AxiosResponseDefault, D = any, P = any>(
  617. url: string,
  618. data?: D,
  619. config?: AxiosRequestConfig<D, P>
  620. ): Promise<AxiosResponseResult<T, R, D, P>>;
  621. patchForm<T = any, R = AxiosResponseDefault, D = any, P = any>(
  622. url: string,
  623. data?: D,
  624. config?: AxiosRequestConfig<D, P>
  625. ): Promise<AxiosResponseResult<T, R, D, P>>;
  626. query<T = any, R = AxiosResponseDefault, D = any, P = any>(
  627. url: string,
  628. data?: D,
  629. config?: AxiosRequestConfig<D, P>
  630. ): Promise<AxiosResponseResult<T, R, D, P>>;
  631. }
  632. export interface AxiosInstance extends Axios {
  633. <T = any, R = AxiosResponseDefault, D = any, P = any>(
  634. config: AxiosRequestConfig<D, P>
  635. ): Promise<AxiosResponseResult<T, R, D, P>>;
  636. <T = any, R = AxiosResponseDefault, D = any, P = any>(
  637. url: string,
  638. config?: AxiosRequestConfig<D, P>
  639. ): Promise<AxiosResponseResult<T, R, D, P>>;
  640. create(config?: CreateAxiosDefaults): AxiosInstance;
  641. defaults: Omit<AxiosDefaults, 'headers'> & {
  642. headers: HeadersDefaults & {
  643. [key: string]: AxiosHeaderValue;
  644. };
  645. };
  646. }
  647. export interface GenericFormData {
  648. append(name: string, value: any, options?: any): any;
  649. }
  650. export interface GenericHTMLFormElement {
  651. name: string;
  652. method: string;
  653. submit(): void;
  654. }
  655. /**
  656. * Resolves an adapter by name, adapter function, or priority list.
  657. * @param config Request config forwarded to adapter getters. The built-in `fetch`
  658. * adapter reads `env.fetch`, `env.Request`, and `env.Response` from it and falls
  659. * back to the globals when it is omitted. Other fields are not applied here.
  660. */
  661. export function getAdapter(
  662. adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined,
  663. config?: AxiosRequestConfig
  664. ): AxiosAdapter;
  665. export function toFormData(
  666. sourceObj: object,
  667. targetFormData?: GenericFormData,
  668. options?: FormSerializerOptions
  669. ): GenericFormData;
  670. export function formToJSON(form: GenericFormData | GenericHTMLFormElement): object;
  671. export function isAxiosError<T = any, D = any, P = any>(
  672. payload: any
  673. ): payload is AxiosError<T, D, P>;
  674. export function spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
  675. export function isCancel<T = any, D = any, P = any>(value: any): value is CanceledError<T, D, P>;
  676. export function all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
  677. export function mergeConfig<D = any, P = any>(
  678. config1: AxiosRequestConfig<D, P>,
  679. config2: AxiosRequestConfig<D, P>
  680. ): AxiosRequestConfig<D, P>;
  681. export function create(config?: CreateAxiosDefaults): AxiosInstance;
  682. export interface AxiosStatic extends AxiosInstance {
  683. Cancel: typeof CanceledError;
  684. CancelToken: CancelTokenStatic;
  685. Axios: typeof Axios;
  686. AxiosError: typeof AxiosError;
  687. HttpStatusCode: typeof HttpStatusCode;
  688. readonly VERSION: string;
  689. isCancel: typeof isCancel;
  690. all: typeof all;
  691. spread: typeof spread;
  692. isAxiosError: typeof isAxiosError;
  693. toFormData: typeof toFormData;
  694. formToJSON: typeof formToJSON;
  695. getAdapter: typeof getAdapter;
  696. CanceledError: typeof CanceledError;
  697. AxiosHeaders: typeof AxiosHeaders;
  698. mergeConfig: typeof mergeConfig;
  699. }
  700. declare const axios: AxiosStatic;
  701. export default axios;