///
import { AxiosRequestHeaders, AxiosProxyConfig } from "axios";
import { ManagerOptions, Socket, SocketOptions } from "socket.io-client";
import { Server } from "http";
/**
* HTTP methods.
*/
export declare type Methods = "get" | "post" | "put" | "delete";
/**
* HTTP request options.
*/
export interface Options {
headers?: AxiosRequestHeaders;
body?: T extends object ? T : object;
timeout?: number;
maxBodyLength?: number;
maxContentLength?: number;
withCredentials?: boolean;
maxRedirects?: number;
proxy?: AxiosProxyConfig;
}
/**
* HTTP options for bridged request.
*/
export interface OnOptions {
url: string;
method: Methods;
headers?: AxiosRequestHeaders;
body?: object;
}
/**
* Callback for multiple bridged requests.
*/
export declare type Callback = (c: Controller) => Promise;
/**
* Websocket request options.
*/
export interface WsReqOptions {
timeout?: number;
clients?: number;
config?: Partial;
}
/**
* Transform from ws to http.
* @param uri Uri to change.
* @returns New uri.
*/
export declare const toHttp: (uri: string) => string;
/**
* HTTP request maker.
*/
export declare class HTTPRequest {
private baseUrl;
/**
* HTTP request maker.
* @param baseUrl HTTP server base url.
*/
constructor(baseUrl: string);
/**
* Makes a HTTP Request.
* @param url Endpoint url.
* @param method HTTP method.
* @param opts Request Options.
* @returns Data from success request.
*/
private base;
/**
* Makes a GET request.
* @param url Endpoint url.
* @param opts Request options.
* @returns Data from success request.
*/
get(url: string, opts?: Options): Promise;
/**
* Makes a POST request.
* @param url Endpoint url.
* @param opts Request options.
* @returns Data from success request.
*/
post(url: string, opts?: Options): Promise;
/**
* Makes a PUT request.
* @param url Endpoint url.
* @param opts Request options.
* @returns Data from success request.
*/
put(url: string, opts?: Options): Promise;
/**
* Makes a DELETE request.
* @param url Endpoint url.
* @param opts Request options.
* @returns Data from success request.
*/
delete(url: string, opts?: Options): Promise;
}
export declare class Controller {
private bridge;
private req;
/**
* Controller to handle connections.
* @param bridge Bridge to websocket methods.
* @param req Bridge to HTTP methods.
*/
constructor(bridge: Bridge, req: HTTPRequest);
/**
* @returns Bridge to websocket methods.
*/
get ws(): Bridge;
/**
* @returns Bridge to HTTP methods.
*/
get http(): HTTPRequest;
}
/**
* Bridge between connections.
*/
export declare class Bridge {
private url;
private socket;
private timeout;
private app;
/**
* Bridge between connections.
* @param url Base url to the server.
* @param socket Websocket
* @param timeout Time to wait for server answer.
* @param app Http Server with websocket upgrade.
*/
constructor(url: string, socket: Socket, timeout: number, app?: Server);
get connection(): {
id: string;
connected: boolean;
};
/**
* Adds a new event listener to the socket.
* @param ev Event name.
* @returns Data retrived from the event.
*/
on(ev: string): Promise;
/**
* Adds a new event listener to the socket and makes a http request to force the emit event in http server.
* @param ev Event name.
* @param opts HTTP request options.
* @returns Data retrived from the event.
* @note Use only if you want to test emits from APIs.
*/
onWithHttp(ev: string, opts: OnOptions): Promise<{
ws: T;
http: U;
}>;
/**
* Emits a new event to the websocket server.
* @param ev Event name.
* @param data Data to send.
* @returns Bridge between on and emit socket methods.
* @note Be sure to emit before add an event listener.
*/
emit(ev: string, data?: T): this;
/**
* Emits and add the message event.
* @param data Data to send.
* @returns Any data from server.
*/
send(data: any): Promise;
/**
* Allows to make multi-requests.
* @param callback Gives access to the socket and http request modules.
* @returns Data from callback or void if no return statement is present.
*/
multiple(callback: Callback): Promise;
/**
* Close the connection.
* @note If local, close the server.
*/
close(httpServer?: boolean): void;
}