// Type definitions for axios based off of Definitions by: Marcel Buesing but adapted for xlib use by JasonS@Novaleaf.com /** a NOT BLUEBIRD COMPATABLE, promise-like construct returned by axios calls. should NOT passs this through the system. you need to wrap it in a "new Promise((resolve,reject)=>{})" object. * this interface actually is more promise-compatabile than what we expose, but we limit it to the minimum to force you to wrap in a 'new Promise()', otherwise BAD THINGS WILL HAPPEN TO YOU! */ export interface IAxiosPromiseish { then(onFulfilled?: (value: R) => void): { catch(onRejected?: (error: AxiosErrorResponse) => void): void; }; } //export interface IP extends PromiseLike { } /** * HTTP Basic auth details */ export interface AxiosHttpBasicAuth { username: string; password: string; } /** * Common axios XHR config interface. * - request body data type */ export interface AxiosXHRConfigBase { /** * will be prepended to `url` unless `url` is absolute. * It can be convenient to set `baseURL` for an instance * of axios to pass relative URLs to methods of that instance. */ baseURL?: string; /** * custom headers to be sent */ headers?: { [key: string]: string }; /** * URL parameters to be sent with the request */ params?: Object; /** * optional function in charge of serializing `params` * (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/) */ paramsSerializer?: (params: Object) => string; /** * specifies the number of milliseconds before the request times out. * If the request takes longer than `timeout`, the request will be aborted. */ timeout?: number; /** * indicates whether or not cross-site Access-Control requests * should be made using credentials */ withCredentials?: boolean; /** * indicates that HTTP Basic auth should be used, and supplies * credentials. This will set an `Authorization` header, * overwriting any existing `Authorization` custom headers you have * set using `headers`. */ auth?: AxiosHttpBasicAuth; /** * indicates the type of data that the server will respond with * options are 'arraybuffer', 'blob', 'document', 'json', 'text' */ responseType?: string; /** * name of the cookie to use as a value for xsrf token */ xsrfCookieName?: string; /** * name of the http header that carries the xsrf token value */ xsrfHeaderName?: string; /** * Change the request data before it is sent to the server. * This is only applicable for request methods 'PUT', 'POST', and 'PATCH' * The last function in the array must return a string or an ArrayBuffer */ transformRequest?: ((data: T) => U) | [(data: T) => U]; /** * change the response data to be made before it is passed to then/catch */ transformResponse?: (data: T) => U; } /** * - request body data type */ export interface AxiosXHRConfig extends AxiosXHRConfigBase { /** * server URL that will be used for the request, options are: * GET, PUT, POST, DELETE, CONNECT, HEAD, OPTIONS, TRACE, PATCH */ url: string; /** * request method to be used when making the request */ method?: string; /** * data to be sent as the request body * Only applicable for request methods 'PUT', 'POST', and 'PATCH' * When no `transformRequest` is set, must be a string, an ArrayBuffer or a hash */ data?: T; } export interface AxiosXHRConfigDefaults extends AxiosXHRConfigBase { // /** // * custom headers to be sent // */ // headers: { // common: { [index: string]: string }; // patch: { [index: string]: string }; // post: { [index: string]: string }; // put: { [index: string]: string }; // //[key:string]:string; // }; } /** * - expected response type, * - request body data type */ export interface AxiosXHR { /** payload that came with the response */ data: T; /** * HTTP status code from the server response */ status: number; /** * HTTP status message from the server response */ statusText: string; /** * headers that the server responded with */ headers: Object; /** * config that was provided to `axios` for the request */ config: AxiosXHRConfig; } /** the response from an error. this inherits from the Error object */ export interface AxiosErrorResponse extends Error { /** inherited from the Error object*/ name: "Error"; /**human readable error message, such as ```getaddrinfo ENOTFOUND moo moo:443``` or ```Request failed with status code 401``` */ message: string; /** * config that was provided to `axios` for the request */ config: AxiosXHRConfig; /** The server response. ```undefined``` if no response from server (such as invalid url or network timeout */ response?: AxiosXHR; /** example ```ENOTFOUND```, but only set if unable to get response from server. otherwise does not exist (not even undefined!). */ code?: string; /** example ```ENOTFOUND```, but only set if unable to get response from server. otherwise does not exist (not even undefined!). */ errno?: string; /** example ```getaddrinfo```, but only set if unable to get response from server. otherwise does not exist (not even undefined!). */ syscall?: string; /** only set if unable to get response from server. otherwise does not exist (not even undefined!). */ hostname?: string; /** only set if unable to get response from server. otherwise does not exist (not even undefined!). */ host?: string; /** only set if unable to get response from server. otherwise does not exist (not even undefined!). */ port?: number; } export interface Interceptor { /** * intercept request before it is sent */ request: RequestInterceptor; /** * intercept response of request when it is received. */ response: ResponseInterceptor } export type InterceptorId = number; export interface RequestInterceptor { /** * - request body data type */ use(fulfilledFn: (config: AxiosXHRConfig) => AxiosXHRConfig): InterceptorId; use(fulfilledFn: (config: AxiosXHRConfig) => AxiosXHRConfig, rejectedFn: (error: any) => any) : InterceptorId; eject(interceptorId: InterceptorId): void; } export interface ResponseInterceptor { /** * - expected response type */ use(fulfilledFn: (config: AxiosXHR) => AxiosXHR): InterceptorId; use(fulfilledFn: (config: AxiosXHR) => AxiosXHR, rejectedFn: (error: any) => any) : InterceptorId; eject(interceptorId: InterceptorId): void; } /** * - expected response type, * - request body data type */ export interface AxiosInstance { /** * Send request as configured */ (config: AxiosXHRConfig): IAxiosPromiseish>; /** * Send request as configured */ new (config: AxiosXHRConfig): IAxiosPromiseish>; /** * Send request as configured */ request(config: AxiosXHRConfig): IAxiosPromiseish>; /** * intercept requests or responses before they are handled by then or catch */ interceptors: Interceptor; /** * Config defaults */ defaults: AxiosXHRConfigDefaults; /** * equivalent to `Promise.all` */ all(values: [T1 | IAxiosPromiseish>, T2 | IAxiosPromiseish>, T3 | IAxiosPromiseish>, T4 | IAxiosPromiseish>, T5 | IAxiosPromiseish>, T6 | IAxiosPromiseish>, T7 | IAxiosPromiseish>, T8 | IAxiosPromiseish>, T9 | IAxiosPromiseish>, T10 | IAxiosPromiseish>]): IAxiosPromiseish<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IAxiosPromiseish>, T2 | IAxiosPromiseish>, T3 | IAxiosPromiseish>, T4 | IAxiosPromiseish>, T5 | IAxiosPromiseish>, T6 | IAxiosPromiseish>, T7 | IAxiosPromiseish>, T8 | IAxiosPromiseish>, T9 | IAxiosPromiseish>]): IAxiosPromiseish<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IAxiosPromiseish>, T2 | IAxiosPromiseish>, T3 | IAxiosPromiseish>, T4 | IAxiosPromiseish>, T5 | IAxiosPromiseish>, T6 | IAxiosPromiseish>, T7 | IAxiosPromiseish>, T8 | IAxiosPromiseish>]): IAxiosPromiseish<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IAxiosPromiseish>, T2 | IAxiosPromiseish>, T3 | IAxiosPromiseish>, T4 | IAxiosPromiseish>, T5 | IAxiosPromiseish>, T6 | IAxiosPromiseish>, T7 | IAxiosPromiseish>]): IAxiosPromiseish<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IAxiosPromiseish>, T2 | IAxiosPromiseish>, T3 | IAxiosPromiseish>, T4 | IAxiosPromiseish>, T5 | IAxiosPromiseish>, T6 | IAxiosPromiseish>]): IAxiosPromiseish<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IAxiosPromiseish>, T2 | IAxiosPromiseish>, T3 | IAxiosPromiseish>, T4 | IAxiosPromiseish>, T5 | IAxiosPromiseish>]): IAxiosPromiseish<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IAxiosPromiseish>, T2 | IAxiosPromiseish>, T3 | IAxiosPromiseish>, T4 | IAxiosPromiseish>]): IAxiosPromiseish<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IAxiosPromiseish>, T2 | IAxiosPromiseish>, T3 | IAxiosPromiseish>]): IAxiosPromiseish<[AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IAxiosPromiseish>, T2 | IAxiosPromiseish>]): IAxiosPromiseish<[AxiosXHR, AxiosXHR]>; /** * spread array parameter to `fn`. * note: alternative to `spread`, destructuring assignment. */ spread(fn: (t1: T1, t2: T2) => U): (arr: ([T1, T2])) => U; /** * convenience alias, method = GET */ get(url: string, config?: AxiosXHRConfigBase): IAxiosPromiseish>; /** * convenience alias, method = DELETE */ delete(url: string, config?: AxiosXHRConfigBase): IAxiosPromiseish>; /** * convenience alias, method = HEAD */ head(url: string, config?: AxiosXHRConfigBase): IAxiosPromiseish>; /** * convenience alias, method = POST */ post(url: string, data?: any, config?: AxiosXHRConfigBase): IAxiosPromiseish>; /** * convenience alias, method = PUT */ put(url: string, data?: any, config?: AxiosXHRConfigBase): IAxiosPromiseish>; /** * convenience alias, method = PATCH */ patch(url: string, data?: any, config?: AxiosXHRConfigBase): IAxiosPromiseish>; } /** * - expected response type, */ export interface AxiosStatic extends AxiosInstance { /** * create a new instance of axios with a custom config */ create(config: AxiosXHRConfigBase): AxiosInstance; } //declare var axios: AxiosStatic; //declare module "axios" { // export = axios; //} // export let axios: AxiosStatic = require( "axios" ); // let originalPost = axios.post; // axios.post = function(...args:any[]){ // return new Promise((resolve,reject)=>{ // }); // }.bind(axios) as any;