index.d.cts 17 KB

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