index.d.ts 17 KB

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