@cpanel/api
Version:
cPanel API JavaScript and TypeScript interface libraries. This library provides a set of classes for calling cPanel WHM API 1 and UAPI calls. The classes hide much of the complexity of these APIs behind classes the abstract the underlying variances betwee
207 lines (206 loc) • 5.44 kB
TypeScript
import { IArgument } from "./utils/argument";
import { IFilter, Filter } from "./utils/filter";
import { IPager, Pager } from "./utils/pager";
import { ISort, Sort } from "./utils/sort";
import { RequestInfo } from "./interchange";
import { Header, Headers } from "./utils/headers";
import { IArgumentEncoder } from "./utils/encoders";
import { HttpVerb } from "./http/verb";
/**
* Rule used to convert a request to the interchange format
*/
export interface GenerateRule {
/**
* Http verb
*/
verb: HttpVerb | string;
/**
* Specific Argument Encoder
*/
encoder: IArgumentEncoder;
}
/**
* Other top level options for the construction of the request.
*/
export interface IRequestConfiguration {
/**
* Enable analytics for the request
*/
analytics?: boolean;
/**
* Encode the arguments as a JSON object
*/
json?: boolean;
}
/**
* Interface for developers that just want to pass a object literal
*/
export interface IRequest {
/**
* Namespace where the API call lives
*/
namespace?: string;
/**
* Method name of the API call.
*/
method: string;
/**
* Optional list of arguments for the API call. You can use types
* * Argument or IArgument
*/
arguments?: IArgument[];
/**
* Optional list of sorting rules to pass to the API call.
*/
sorts?: ISort[];
/**
* Optional list of filter rules to pass to the API call.
*/
filters?: IFilter[];
/**
* Optional list of columns to include with the response to the API call.
*/
columns?: string[];
/**
* Optional pager rule to pass to the API.
*/
pager?: IPager;
/**
* Optional additional configuration for the request.
*/
config?: IRequestConfiguration;
/**
* Optional additional HTTP headers for the request.
*/
headers?: Header[];
}
/**
* Extra information about the request that generates the request.
*/
export interface IRequestMeta {
/**
* Request object that generated the RequestInfo object.
* @type {Request}
*/
request: Request;
}
/**
* Extra information about the batch request that generates the request.
*/
export interface IBatchRequestMeta {
/**
* List of abstract request objects that make up the batch that generated the RequestInfo object.
*/
requests: Request[];
}
/**
* Abstract base class for all Request objects. Developers should
* create a subclass of this that implements the generate() method.
*/
export declare abstract class Request {
/**
* Namespace where the API call lives
* @type {string}
*/
namespace: string;
/**
* Method name of the API call.
* @type {string}
*/
method: string;
/**
* Optional list of arguments for the API call.
* @type {IArgument[]}
*/
arguments: IArgument[];
/**
* Optional list of sorting rules to pass to the API call.
*/
sorts: Sort[];
/**
* Optional list of filter rules to pass to the API call.
*/
filters: Filter[];
/**
* Optional list of columns to include with the response to the API call.
*/
columns: string[];
/**
* Optional pager rule to pass to the API.
*/
pager: Pager;
/**
* Optional custom headers collection
*/
headers: Headers;
private _usePager;
/**
* Use the pager only if true.
*/
get usePager(): boolean;
/**
* Default configuration object.
*/
private defaultConfig;
/**
* Optional configuration information
*/
config: IRequestConfiguration;
/**
* Create a new request.
*
* @param init Optional request object used to initialize this object.
*/
constructor(init?: IRequest);
/**
* Add an argument to the request.
*
* @param argument
* @return Updated Request object.
*/
addArgument(argument: IArgument): Request;
/**
* Add sorting rule to the request.
*
* @param sort Sort object with sorting information.
* @return Updated Request object.
*/
addSort(sort: ISort): Request;
/**
* Add a filter to the request.
*
* @param filter Filter object with filter information.
* @return Updated Request object.
*/
addFilter(filter: IFilter): Request;
/**
* Add a column to include in the request. If no columns are specified, all columns are retrieved.
*
* @param name Name of a column
* @return Updated Request object.
*/
addColumn(column: string): Request;
/**
* Add a custom http header to the request
*
* @param name Name of a column
* @return Updated Request object.
*/
addHeader(header: Header): Request;
/**
* Set the pager setting for the request.
*
* @param pager Pager object with pagination information.
* @return Updated Request object.
*/
paginate(pager: IPager): Request;
/**
* Generate the request interchange information. Note: This method is abstracted and
* must be implemented in derived request generators.
*
* @param Rule used to create the interchange. If not provided, implementations
* should select the rule to use.
* @return Interchange data.
*/
abstract generate(rule?: GenerateRule): RequestInfo;
}