index.d.cts 17 KB

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