@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
101 lines (100 loc) • 3.38 kB
TypeScript
import { GenerateRule, Request, IRequest } from "../request";
import { RequestInfo } from "../interchange";
import { Header } from "../utils/headers";
/**
* Type of response format for WHM API 1. The data can be requested to be sent back
* either in JSON format or XML format.
*/
export declare enum WhmApiType {
/**
* Json-Api request
*/
JsonApi = "json-api",
/**
* Xml-Api request
*/
XmlApi = "xml-api"
}
export declare class WhmApiRequest extends Request {
/**
* The API output format the request should be generated for.
*/
apiType: WhmApiType;
/**
* Add a custom HTTP header to the request
*
* @param name Name of a column
* @return Updated Request object.
*/
addHeader(header: Header): Request;
/**
* Build a fragment of the parameter list based on the list of name/value pairs.
*
* @param params Parameters to serialize.
* @param encoder Encoder to use to serialize the each parameter.
* @return Fragment with the serialized parameters
*/
private _build;
/**
* Convert from a number into a string that WHM API 1 will sort
* in the same order as the numbers; e.g.: 26=>"za", 52=>"zza", ...
* @method _make_whm_api_fieldspec_from_number
* @private
* @param num Index of sort item
* @return letter combination for the index of the sort item.
*/
private _make_whm_api_fieldspec_from_number;
/**
* Generates the arguments for the request.
*
* @param params List of parameters to adjust based on the sort rules in the Request.
*/
private _generateArguments;
/**
* Generates the sort parameters for the request.
*
* @param params List of parameters to adjust based on the sort rules in the Request.
*/
private _generateSorts;
/**
* Look up the correct name for the filter operator
*
* @param operator Type of filter operator to use to filter the items
* @returns The string counter part for the filter operator.
* @throws Will throw an error if an unrecognized FilterOperator is provided.
*/
private _lookupFilterOperator;
/**
* Generate the filter parameters, if any.
*
* @param params List of parameters to adjust based on the filter rules provided.
*/
private _generateFilters;
/**
* In UAPI, we request the starting record, not the starting page. This translates
* the page and page size into the correct starting record.
*
* @param pager Object containing pager settings.
*/
private _translatePageToStart;
/**
* Generate the pager request parameters, if any.
*
* @param params List of parameters to adjust based on the pagination rules.
*/
private _generatePagination;
/**
* Create a new UAPI request.
*
* @param init Optional request object used to initialize this object.
*/
constructor(apiType: WhmApiType, init?: IRequest);
/**
* Generate the interchange object that has the pre-encoded
* request using UAPI formatting.
*
* @param rule Optional parameter to specify a specific Rule we want the Request to be generated for.
* @return {RequestInfo} Request information ready to be used by a remoting layer
*/
generate(rule?: GenerateRule): RequestInfo;
}