index.d.cts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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?: {
  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 | CustomParamsSerializer;
  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. transport?: any;
  331. httpAgent?: any;
  332. httpsAgent?: any;
  333. proxy?: AxiosProxyConfig | false;
  334. cancelToken?: CancelToken;
  335. decompress?: boolean;
  336. transitional?: TransitionalOptions;
  337. signal?: GenericAbortSignal;
  338. insecureHTTPParser?: boolean;
  339. env?: {
  340. FormData?: new (...args: any[]) => object;
  341. };
  342. formSerializer?: FormSerializerOptions;
  343. family?: 4 | 6 | undefined;
  344. lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: string, family: number) => void) => void) |
  345. ((hostname: string, options: object) => Promise<[address: string, family: number] | string>);
  346. }
  347. // Alias
  348. type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
  349. interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig {
  350. headers: AxiosRequestHeaders;
  351. }
  352. interface HeadersDefaults {
  353. common: RawAxiosRequestHeaders;
  354. delete: RawAxiosRequestHeaders;
  355. get: RawAxiosRequestHeaders;
  356. head: RawAxiosRequestHeaders;
  357. post: RawAxiosRequestHeaders;
  358. put: RawAxiosRequestHeaders;
  359. patch: RawAxiosRequestHeaders;
  360. options?: RawAxiosRequestHeaders;
  361. purge?: RawAxiosRequestHeaders;
  362. link?: RawAxiosRequestHeaders;
  363. unlink?: RawAxiosRequestHeaders;
  364. }
  365. interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
  366. headers: HeadersDefaults;
  367. }
  368. interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
  369. headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
  370. }
  371. interface AxiosResponse<T = any, D = any> {
  372. data: T;
  373. status: number;
  374. statusText: string;
  375. headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
  376. config: InternalAxiosRequestConfig<D>;
  377. request?: any;
  378. }
  379. type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
  380. interface CancelStatic {
  381. new (message?: string): Cancel;
  382. }
  383. interface Cancel {
  384. message: string | undefined;
  385. }
  386. interface Canceler {
  387. (message?: string, config?: AxiosRequestConfig, request?: any): void;
  388. }
  389. interface CancelTokenStatic {
  390. new (executor: (cancel: Canceler) => void): CancelToken;
  391. source(): CancelTokenSource;
  392. }
  393. interface CancelToken {
  394. promise: Promise<Cancel>;
  395. reason?: Cancel;
  396. throwIfRequested(): void;
  397. }
  398. interface CancelTokenSource {
  399. token: CancelToken;
  400. cancel: Canceler;
  401. }
  402. interface AxiosInterceptorOptions {
  403. synchronous?: boolean;
  404. runWhen?: (config: InternalAxiosRequestConfig) => boolean;
  405. }
  406. interface AxiosInterceptorManager<V> {
  407. use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any, options?: AxiosInterceptorOptions): number;
  408. eject(id: number): void;
  409. clear(): void;
  410. }
  411. interface AxiosInstance extends Axios {
  412. <T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
  413. <T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
  414. defaults: Omit<AxiosDefaults, 'headers'> & {
  415. headers: HeadersDefaults & {
  416. [key: string]: AxiosHeaderValue
  417. }
  418. };
  419. }
  420. interface GenericFormData {
  421. append(name: string, value: any, options?: any): any;
  422. }
  423. interface GenericHTMLFormElement {
  424. name: string;
  425. method: string;
  426. submit(): void;
  427. }
  428. interface AxiosStatic extends AxiosInstance {
  429. create(config?: CreateAxiosDefaults): AxiosInstance;
  430. Cancel: CancelStatic;
  431. CancelToken: CancelTokenStatic;
  432. Axios: typeof Axios;
  433. AxiosError: typeof AxiosError;
  434. CanceledError: typeof CanceledError;
  435. HttpStatusCode: typeof HttpStatusCode;
  436. readonly VERSION: string;
  437. isCancel(value: any): value is Cancel;
  438. all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
  439. spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
  440. isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
  441. toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
  442. formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
  443. getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
  444. AxiosHeaders: typeof AxiosHeaders;
  445. }
  446. }
  447. declare const axios: axios.AxiosStatic;
  448. export = axios;