You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

550 lines
18 KiB

  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 AxiosHeaderParser = (this: AxiosHeaders, value: axios.AxiosHeaderValue, header: string) => any;
  9. type CommonRequestHeadersList = 'Accept' | 'Content-Length' | 'User-Agent'| 'Content-Encoding' | 'Authorization';
  10. type ContentType = axios.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 | string
  15. );
  16. [key: string]: any;
  17. set(headerName?: string, value?: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
  18. set(headers?: RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;
  19. get(headerName: string, parser: RegExp): RegExpExecArray | null;
  20. get(headerName: string, matcher?: true | AxiosHeaderParser): axios.AxiosHeaderValue;
  21. has(header: string, matcher?: 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): axios.AxiosHeaderValue;
  33. hasContentType(matcher?: AxiosHeaderMatcher): boolean;
  34. setContentLength(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
  35. getContentLength(parser?: RegExp): RegExpExecArray | null;
  36. getContentLength(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
  37. hasContentLength(matcher?: AxiosHeaderMatcher): boolean;
  38. setAccept(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
  39. getAccept(parser?: RegExp): RegExpExecArray | null;
  40. getAccept(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
  41. hasAccept(matcher?: AxiosHeaderMatcher): boolean;
  42. setUserAgent(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
  43. getUserAgent(parser?: RegExp): RegExpExecArray | null;
  44. getUserAgent(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
  45. hasUserAgent(matcher?: AxiosHeaderMatcher): boolean;
  46. setContentEncoding(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
  47. getContentEncoding(parser?: RegExp): RegExpExecArray | null;
  48. getContentEncoding(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
  49. hasContentEncoding(matcher?: AxiosHeaderMatcher): boolean;
  50. setAuthorization(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
  51. getAuthorization(parser?: RegExp): RegExpExecArray | null;
  52. getAuthorization(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
  53. hasAuthorization(matcher?: AxiosHeaderMatcher): boolean;
  54. [Symbol.iterator](): IterableIterator<[string, axios.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 AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
  182. type RawCommonResponseHeaders = {
  183. [Key in CommonResponseHeadersList]: AxiosHeaderValue;
  184. } & {
  185. "set-cookie": string[];
  186. };
  187. type RawAxiosResponseHeaders = Partial<RawAxiosHeaders & RawCommonResponseHeaders>;
  188. type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;
  189. interface AxiosRequestTransformer {
  190. (this: InternalAxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
  191. }
  192. interface AxiosResponseTransformer {
  193. (this: InternalAxiosRequestConfig, data: any, headers: AxiosResponseHeaders, status?: number): any;
  194. }
  195. interface AxiosAdapter {
  196. (config: InternalAxiosRequestConfig): AxiosPromise;
  197. }
  198. interface AxiosBasicCredentials {
  199. username: string;
  200. password: string;
  201. }
  202. interface AxiosProxyConfig {
  203. host: string;
  204. port: number;
  205. auth?: AxiosBasicCredentials;
  206. protocol?: string;
  207. }
  208. type Method =
  209. | 'get' | 'GET'
  210. | 'delete' | 'DELETE'
  211. | 'head' | 'HEAD'
  212. | 'options' | 'OPTIONS'
  213. | 'post' | 'POST'
  214. | 'put' | 'PUT'
  215. | 'patch' | 'PATCH'
  216. | 'purge' | 'PURGE'
  217. | 'link' | 'LINK'
  218. | 'unlink' | 'UNLINK';
  219. type ResponseType =
  220. | 'arraybuffer'
  221. | 'blob'
  222. | 'document'
  223. | 'json'
  224. | 'text'
  225. | 'stream'
  226. | 'formdata';
  227. type responseEncoding =
  228. | 'ascii' | 'ASCII'
  229. | 'ansi' | 'ANSI'
  230. | 'binary' | 'BINARY'
  231. | 'base64' | 'BASE64'
  232. | 'base64url' | 'BASE64URL'
  233. | 'hex' | 'HEX'
  234. | 'latin1' | 'LATIN1'
  235. | 'ucs-2' | 'UCS-2'
  236. | 'ucs2' | 'UCS2'
  237. | 'utf-8' | 'UTF-8'
  238. | 'utf8' | 'UTF8'
  239. | 'utf16le' | 'UTF16LE';
  240. interface TransitionalOptions {
  241. silentJSONParsing?: boolean;
  242. forcedJSONParsing?: boolean;
  243. clarifyTimeoutError?: boolean;
  244. }
  245. interface GenericAbortSignal {
  246. readonly aborted: boolean;
  247. onabort?: ((...args: any) => any) | null;
  248. addEventListener?: (...args: any) => any;
  249. removeEventListener?: (...args: any) => any;
  250. }
  251. interface FormDataVisitorHelpers {
  252. defaultVisitor: SerializerVisitor;
  253. convertValue: (value: any) => any;
  254. isVisitable: (value: any) => boolean;
  255. }
  256. interface SerializerVisitor {
  257. (
  258. this: GenericFormData,
  259. value: any,
  260. key: string | number,
  261. path: null | Array<string | number>,
  262. helpers: FormDataVisitorHelpers
  263. ): boolean;
  264. }
  265. interface SerializerOptions {
  266. visitor?: SerializerVisitor;
  267. dots?: boolean;
  268. metaTokens?: boolean;
  269. indexes?: boolean | null;
  270. }
  271. // tslint:disable-next-line
  272. interface FormSerializerOptions extends SerializerOptions {
  273. }
  274. interface ParamEncoder {
  275. (value: any, defaultEncoder: (value: any) => any): any;
  276. }
  277. interface CustomParamsSerializer {
  278. (params: Record<string, any>, options?: ParamsSerializerOptions): string;
  279. }
  280. interface ParamsSerializerOptions extends SerializerOptions {
  281. encode?: ParamEncoder;
  282. serialize?: CustomParamsSerializer;
  283. }
  284. type MaxUploadRate = number;
  285. type MaxDownloadRate = number;
  286. type BrowserProgressEvent = any;
  287. interface AxiosProgressEvent {
  288. loaded: number;
  289. total?: number;
  290. progress?: number;
  291. bytes: number;
  292. rate?: number;
  293. estimated?: number;
  294. upload?: boolean;
  295. download?: boolean;
  296. event?: BrowserProgressEvent;
  297. lengthComputable: boolean;
  298. }
  299. type Milliseconds = number;
  300. type AxiosAdapterName = 'fetch' | 'xhr' | 'http' | string;
  301. type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
  302. type AddressFamily = 4 | 6 | undefined;
  303. interface LookupAddressEntry {
  304. address: string;
  305. family?: AddressFamily;
  306. }
  307. type LookupAddress = string | LookupAddressEntry;
  308. interface AxiosRequestConfig<D = any> {
  309. url?: string;
  310. method?: Method | string;
  311. baseURL?: string;
  312. allowAbsoluteUrls?: boolean;
  313. transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
  314. transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
  315. headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
  316. params?: any;
  317. paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
  318. data?: D;
  319. timeout?: Milliseconds;
  320. timeoutErrorMessage?: string;
  321. withCredentials?: boolean;
  322. adapter?: AxiosAdapterConfig | AxiosAdapterConfig[];
  323. auth?: AxiosBasicCredentials;
  324. responseType?: ResponseType;
  325. responseEncoding?: responseEncoding | string;
  326. xsrfCookieName?: string;
  327. xsrfHeaderName?: string;
  328. onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
  329. onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
  330. maxContentLength?: number;
  331. validateStatus?: ((status: number) => boolean) | null;
  332. maxBodyLength?: number;
  333. maxRedirects?: number;
  334. maxRate?: number | [MaxUploadRate, MaxDownloadRate];
  335. beforeRedirect?: (options: Record<string, any>, responseDetails: {headers: Record<string, string>, statusCode: HttpStatusCode}) => void;
  336. socketPath?: string | null;
  337. transport?: any;
  338. httpAgent?: any;
  339. httpsAgent?: any;
  340. proxy?: AxiosProxyConfig | false;
  341. cancelToken?: CancelToken;
  342. decompress?: boolean;
  343. transitional?: TransitionalOptions;
  344. signal?: GenericAbortSignal;
  345. insecureHTTPParser?: boolean;
  346. env?: {
  347. FormData?: new (...args: any[]) => object;
  348. };
  349. formSerializer?: FormSerializerOptions;
  350. family?: AddressFamily;
  351. lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: LookupAddress | LookupAddress[], family?: AddressFamily) => void) => void) |
  352. ((hostname: string, options: object) => Promise<[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress>);
  353. withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
  354. fetchOptions?: Record<string, any>;
  355. }
  356. // Alias
  357. type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
  358. interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig {
  359. headers: AxiosRequestHeaders;
  360. }
  361. interface HeadersDefaults {
  362. common: RawAxiosRequestHeaders;
  363. delete: RawAxiosRequestHeaders;
  364. get: RawAxiosRequestHeaders;
  365. head: RawAxiosRequestHeaders;
  366. post: RawAxiosRequestHeaders;
  367. put: RawAxiosRequestHeaders;
  368. patch: RawAxiosRequestHeaders;
  369. options?: RawAxiosRequestHeaders;
  370. purge?: RawAxiosRequestHeaders;
  371. link?: RawAxiosRequestHeaders;
  372. unlink?: RawAxiosRequestHeaders;
  373. }
  374. interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
  375. headers: HeadersDefaults;
  376. }
  377. interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
  378. headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
  379. }
  380. interface AxiosResponse<T = any, D = any> {
  381. data: T;
  382. status: number;
  383. statusText: string;
  384. headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
  385. config: InternalAxiosRequestConfig<D>;
  386. request?: any;
  387. }
  388. type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
  389. interface CancelStatic {
  390. new (message?: string): Cancel;
  391. }
  392. interface Cancel {
  393. message: string | undefined;
  394. }
  395. interface Canceler {
  396. (message?: string, config?: AxiosRequestConfig, request?: any): void;
  397. }
  398. interface CancelTokenStatic {
  399. new (executor: (cancel: Canceler) => void): CancelToken;
  400. source(): CancelTokenSource;
  401. }
  402. interface CancelToken {
  403. promise: Promise<Cancel>;
  404. reason?: Cancel;
  405. throwIfRequested(): void;
  406. }
  407. interface CancelTokenSource {
  408. token: CancelToken;
  409. cancel: Canceler;
  410. }
  411. interface AxiosInterceptorOptions {
  412. synchronous?: boolean;
  413. runWhen?: (config: InternalAxiosRequestConfig) => boolean;
  414. }
  415. type AxiosRequestInterceptorUse<T> = (onFulfilled?: ((value: T) => T | Promise<T>) | null, onRejected?: ((error: any) => any) | null, options?: AxiosInterceptorOptions) => number;
  416. type AxiosResponseInterceptorUse<T> = (onFulfilled?: ((value: T) => T | Promise<T>) | null, onRejected?: ((error: any) => any) | null) => number;
  417. interface AxiosInterceptorManager<V> {
  418. use: V extends AxiosResponse ? AxiosResponseInterceptorUse<V> : AxiosRequestInterceptorUse<V>;
  419. eject(id: number): void;
  420. clear(): void;
  421. }
  422. interface AxiosInstance extends Axios {
  423. <T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
  424. <T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
  425. defaults: Omit<AxiosDefaults, 'headers'> & {
  426. headers: HeadersDefaults & {
  427. [key: string]: AxiosHeaderValue
  428. }
  429. };
  430. }
  431. interface GenericFormData {
  432. append(name: string, value: any, options?: any): any;
  433. }
  434. interface GenericHTMLFormElement {
  435. name: string;
  436. method: string;
  437. submit(): void;
  438. }
  439. interface AxiosStatic extends AxiosInstance {
  440. create(config?: CreateAxiosDefaults): AxiosInstance;
  441. Cancel: CancelStatic;
  442. CancelToken: CancelTokenStatic;
  443. Axios: typeof Axios;
  444. AxiosError: typeof AxiosError;
  445. CanceledError: typeof CanceledError;
  446. HttpStatusCode: typeof HttpStatusCode;
  447. readonly VERSION: string;
  448. isCancel(value: any): value is Cancel;
  449. all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
  450. spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
  451. isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
  452. toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
  453. formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
  454. getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
  455. AxiosHeaders: typeof AxiosHeaders;
  456. }
  457. }
  458. declare const axios: axios.AxiosStatic;
  459. export = axios;