@team-internet/apiconnector
Version:
Node.js SDK for the insanely fast CentralNic Reseller (fka RRPProxy) API
234 lines (233 loc) • 7.8 kB
TypeScript
import { Logger } from "./logger.js";
import { Response } from "./response.js";
export declare const CNR_CONNECTION_URL_PROXY = "http://127.0.0.1/api/call.cgi";
export declare const CNR_CONNECTION_URL_LIVE = "https://api.rrpproxy.net/api/call.cgi";
export declare const CNR_CONNECTION_URL_OTE = "https://api-ote.rrpproxy.net/api/call.cgi";
/**
* APIClient class
*/
export declare class APIClient {
/**
* API connection timeout setting
*/
static readonly socketTimeout: number;
/**
* User Agent string
*/
private ua;
/**
* API connection url
*/
private socketURL;
/**
* Object covering API connection data
*/
private socketConfig;
/**
* activity flag for debug mode
*/
private debugMode;
/**
* additional connection settings
*/
private curlopts;
/**
* logger function for debug mode
*/
private logger;
/**
* set sub user account
*/
private subUser;
/**
* set sub user account role seperater
*/
private readonly roleSeparator;
constructor();
/**
* set custom logger to use instead of default one
* @param customLogger
* @returns Current APIClient instance for method chaining
*/
setCustomLogger(customLogger: Logger): APIClient;
/**
* set default logger to use
* @returns Current APIClient instance for method chaining
*/
setDefaultLogger(): APIClient;
/**
* Enable Debug Output to STDOUT
* @returns Current APIClient instance for method chaining
*/
enableDebugMode(): APIClient;
/**
* Disable Debug Output
* @returns Current APIClient instance for method chaining
*/
disableDebugMode(): APIClient;
/**
* Get the API connection url that is currently set
* @returns API connection url currently in use
*/
getURL(): string;
/**
* Possibility to customize default user agent to fit your needs
* @param str user agent label
* @param rv revision of user agent
* @param modules further modules to add to user agent string, format: ["<mod1>/<rev>", "<mod2>/<rev>", ... ]
* @returns Current APIClient instance for method chaining
*/
setUserAgent(str: string, rv: string, modules?: any): APIClient;
/**
* Get the User Agent
* @returns User Agent string
*/
getUserAgent(): string;
/**
* Set the proxy server to use for API communication
* @param proxy proxy server to use for communicatio
* @returns Current APIClient instance for method chaining
*/
setProxy(proxy: string): APIClient;
/**
* Get the proxy server configuration
* @returns proxy server configuration value or null if not set
*/
getProxy(): string | null;
/**
* Set the referer to use for API communication
* @param referer Referer
* @returns Current APIClient instance for method chaining
*/
setReferer(referer: string): APIClient;
/**
* Get the referer configuration
* @returns referer configuration value or null if not set
*/
getReferer(): string | null;
/**
* Get the current module version
* @returns module version
*/
getVersion(): string;
/**
* Apply session data (session id and system entity) to given client request session
* @param session ClientRequest session instance
* @returns Current APIClient instance for method chaining
*/
saveSession(session: any): APIClient;
/**
* Use existing configuration out of ClientRequest session
* to rebuild and reuse connection settings
* @param session ClientRequest session instance
* @returns Current APIClient instance for method chaining
*/
reuseSession(session: any): APIClient;
/**
* Set another connection url to be used for API communication
* @param value API connection url to set
* @returns Current APIClient instance for method chaining
*/
setURL(value: string): APIClient;
/**
* Set Persistent to request session id for API communication
* @param value API session id
* @returns Current APIClient instance for method chaining
*/
setPersistent(): APIClient;
/**
* Set Credentials to be used for API communication
* @param uid account name
* @param pw account password
* @returns Current APIClient instance for method chaining
*/
setCredentials(uid: string, pw?: string): APIClient;
/**
* Set Credentials to be used for API communication
* @param uid account name
* @param role role user id
* @param pw role user password
* @returns Current APIClient instance for method chaining
*/
setRoleCredentials(uid: string, role: string, pw?: string): APIClient;
/**
* Perform API login to start session-based communication
* @param otp optional one time password
* @returns Promise resolving with API Response
*/
login(): Promise<Response>;
/**
* Perform API logout to close API session in use
* @returns Promise resolving with API Response
*/
logout(): Promise<Response>;
/**
* Perform API request using the given command
* @param cmd API command to request
* @returns Promise resolving with API Response
*/
request(cmd: any, setUserView?: boolean): Promise<Response>;
/**
* Request the next page of list entries for the current list query
* Useful for tables
* @param rr API Response of current page
* @returns Promise resolving with API Response or null in case there are no further list entries
*/
requestNextResponsePage(rr: Response): Promise<Response | null>;
/**
* Request all pages/entries for the given query command
* @param cmd API list command to use
* @returns Promise resolving with array of API Responses
*/
requestAllResponsePages(cmd: any): Promise<Response[]>;
/**
* Set a data view to a given subuser
* @param uid subuser account name
* @returns Current APIClient instance for method chaining
*/
setUserView(uid: string): APIClient;
/**
* Reset data view back from subuser to user
* @returns Current APIClient instance for method chaining
*/
resetUserView(): APIClient;
/**
* Activate High Performance Connection Setup
* @see https://github.com/centralnicgroup-opensource/rtldev-middleware-node-sdk/blob/master/README.md
* @returns Current APIClient instance for method chaining
*/
useHighPerformanceConnectionSetup(): APIClient;
/**
* Activate Default Connection Setup (the default)
* @returns Current APIClient instance for method chaining
*/
useDefaultConnectionSetup(): APIClient;
/**
* Set OT&E System for API communication
* @returns Current APIClient instance for method chaining
*/
useOTESystem(): APIClient;
/**
* Set LIVE System for API communication (this is the default setting)
* @returns Current APIClient instance for method chaining
*/
useLIVESystem(): APIClient;
/**
* Serialize given command for POST request including connection configuration data
* @param cmd API command to encode
* @returns encoded POST data string
*/
getPOSTData(cmd: any, secured?: boolean): string;
/**
* Flatten nested arrays in command
* @param cmd api command
* @returns api command with flattended parameters
*/
private flattenCommand;
/**
* Auto convert API command parameters to punycode, if necessary.
* @param cmd api command
* @returns Promise resolving with api command with IDN values replaced to punycode
*/
private autoIDNConvert;
}