@cpanel/api
v6.0.0
Published
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
Downloads
358
Readme
@cpanel/api Libraries
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 API's behind classes that abstract the underlying variances between these API systems. Users of this library can focus on what they want to accomplish rather than having to learn the various complexities of the underlying wire formats for each of the cPanel product's APIs.
Installing @cpanel/api
To install these libraries with NPM, run:
npm install @cpanel/api
Using @cpanel/api
TypeScript
Calling a WHM API 1 function
import {
Argument,
WhmApiResponse,
WhmApiRequest,
WhmApiType,
WhmApiTokenHeader,
} from "@cpanel/api";
const token = "...paste your API token here...";
const request = new WhmApiRequest(WhmApiType.JsonApi, {
method: "api_token_create",
arguments: [
new Argument("token_name", "my-Auth-Token"),
// ---- API Token Permissions ----
// Login to the UI
new Argument("acl", "create-user-session"),
// Delete a token
new Argument("acl", "manage-api-tokens"),
],
headers: [new WhmApiTokenHeader(token, "root")],
}).generate();
fetch("http://my-cpanel-server.com:2087", {
method: "POST",
headers: request.headers.toObject(),
body: request.body,
})
.then((response) => response.json())
.then((response) => {
response.data = new WhmApiResponse(response.data);
if (!response.data.status) {
throw new Error(response.data.errors[0].message);
}
return response;
})
.then((data) => console.log(data));
JavaScript
Calling a WHM API 1 function
let {
Argument,
WhmApiResponse,
WhmApiRequest,
WhmApiType,
WhmApiTokenHeader
} = require("@cpanel/api");
const token = "...paste your API token here...";
const request = new WhmApiRequest(WhmApiType.JsonApi, {
method: "api_token_create",
arguments: [
new Argument('token_name', 'my-Auth-Token'),
// ---- API Token Permissions ----
// Login to the UI
new Argument('acl', 'create-user-session'),
// Delete a token
new Argument('acl', 'manage-api-tokens'),
],
headers: [
new WhmApiTokenHeader(token, 'root'),
],
}).generate();
fetch('http://my-cpanel-server.com:2087', {
method: 'POST',
headers: request.headers.toObject()),
body: request.body
})
.then(response => response.json())
.then(response => {
response.data = new WhmApiResponse(response.data);
if(!response.data.status) {
throw new Error(response.data.errors[0].message);
}
return response;
})
.then(data => console.log(data));
Development
Set up your development environment to test the local version of your library rather than the one distributed on
npm.dev.cpanel.net
:npm install --also=dev npm run build:dev
Make the changes to the library.
Rebuild the library:
npm run build:dev
Testing
To install the development dependencies, run:
npm install --also=dev
npm run test
Contributing
The maintainer will evaluate all bugs and feature requests, and reserves the right to reject a request for any reason.
Bugs
Please submit bugs via the github issue tracker. Bug reports must include the following:
- The version of the @cpanel/api library.
- The version of cPanel & WHM you are testing against.
- A step by step set of instructions on how to reproduce the bug.
- Sample code that reproduces the bug.
The maintainers will evaluate all bugs.
Improvements and Feature Requests
Please submit feature requests via the github issue tracker.
Describe the feature in detail. Try to include information on why the suggested feature would be valuable and under what scenarios.
Pull requests
We welcome pull requests against the @cpanel/api library.
The maintainers will evaluate all pull requests. Pull requests are subject to review by the maintainers. We may request additional adjustments to any submitted pull requests.
Any code submitted via pull requests that is incorporated into the library will become the property of cPanel L.L.C. and will be published under the cPanel L.L.C. copyright and the MIT license.
Publishing
Note Publishing is limited to select cPanel maintainers.
When your changes are implemented and tested, and you're ready to publish, run:
Developer publishing (publishing an alpha build for testing)
- As part of the development changes update the
version
property inpackage.json
to the formatX.X.X-alpha.X
so that the semver is updated correctly and appended with alpha build information (1.0.0 -> 1.0.1-alpha.1). - Request maintainers of the repository to publish alpha builds using
npm publish
Production publishing (This will be done by a UI3)
- When dev changes are accepted and complete update the
version
property inpackage.json
to the formatX.X.X
so that the semver is updated correctly and alpha build information has been removed. Do this on the development branch before merging pull request (1.0.1-alpha.1 -> 1.0.1). - Request maintainers of the repository to publish your latest changes using
npm publish
post merge.
Authors
- Team Phoenix @ cPanel
- Team Artemis @ cPanel
- Team Cobra @ cPanel
- Team Moonshot @ cPanel
Contributors
- Thomas Green [email protected]
- Sruthi Sanigarapu [email protected]
- Aneece Yazdani [email protected]
- Sarah Kiniry [email protected]
- Dustin Scherer [email protected]
- Philip King [email protected]
- Caitlin Flattery [email protected]
- Aspen Hollyer [email protected]
License
Copyright © 2024 cPanel, L.L.C. Licensed under the included MIT license.