UNPKG

@syncano/client

Version:

Interact with your Syncano Sockets.

100 lines (99 loc) 4.01 kB
import * as axios from 'axios'; export interface SyncanoClientOptions { host?: string; token?: string; apiVersion?: string; transformResponse?: (response: axios.AxiosResponse) => void; } export default class SyncanoClient { /** * User api key used to authenticate requests * * @type {string} */ token?: string; /** * Syncano Instance name. See cheatsheet to learn how to create instance * * @see https://cheatsheet.syncano.io/#cli * @type {string} */ instanceName?: string; private host?; private apiVersion?; private transformResponse?; private DEFAULT_HEADERS; constructor(instanceName: string, options?: SyncanoClientOptions); /** * Helper method that generates endpoint url * * @param {string} path Endpoint path in format `socket-name/endpoint-name` * @param {object} [params] The params to be appended * @returns {string} The formatted url */ url(path: string, params?: object, options?: { protocol: 'https' | 'wss'; }): string; /** * Set user api key. Use this to make all request authenticated * Call this method without any argument to clear api key * * @param {string} [token] */ setToken(token?: string): this; /** * Send request using GET method * * @param {string} endpoint Endpoint path in format `socket-name/endpoint-name` * @param {object} [params={}] Additional request parameters * @param {axios.AxiosRequestConfig} [options={}] Additional request options, like headers. See axios config for info * @see https://github.com/axios/axios#request-config */ get(endpoint: string, params?: object, options?: axios.AxiosRequestConfig): Promise<any>; /** * Send request using PATCH method * * @param {string} endpoint Endpoint path in format `socket-name/endpoint-name` * @param {any} [data={}] Additional request parameters * @param {axios.AxiosRequestConfig} [options={}] Additional request options, like headers. See axios config for info * @see https://github.com/axios/axios#request-config */ patch(endpoint: string, data?: any, options?: axios.AxiosRequestConfig): Promise<any>; /** * Send request using POST method * * @param {string} endpoint Endpoint path in format `socket-name/endpoint-name` * @param {any} [data={}] Additional request parameters * @param {axios.AxiosRequestConfig} [options={}] Additional request options, like headers. See axios config for info * @see https://github.com/axios/axios#request-config */ post(endpoint: string, data?: any, options?: axios.AxiosRequestConfig): Promise<any>; /** * Send request using PUT method * * @param {string} endpoint Endpoint path in format `socket-name/endpoint-name` * @param {any} [data={}] Additional request parameters * @param {axios.AxiosRequestConfig} [options={}] Additional request options, like headers. See axios config for info * @see https://github.com/axios/axios#request-config */ put(endpoint: string, data?: any, options?: axios.AxiosRequestConfig): Promise<any>; /** * Send request using DELETE method * * @param {string} endpoint Endpoint path in format `socket-name/endpoint-name` * @param {object} [params={}] Additional request parameters * @param {axios.AxiosRequestConfig} [options={}] Additional request options, like headers. See axios config for info * @see https://github.com/axios/axios#request-config */ delete(endpoint: string, params?: object, options?: axios.AxiosRequestConfig): Promise<any>; /** * * * @param {string} endpoint Endpoint path in format `socket-name/endpoint-name` * @param {object} [params] Params to be appended to the URL */ listen(endpoint: string, params?: object): WebSocket; private transform; private options; private checkInstanceName; }