source: node_modules/axios/index.d.ts

Last change on this file was ff72ad2, checked in by ste08 <sjovanoska@…>, 2 months ago

Adding review works\!

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