npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cpanel/api

v5.2.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

196

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

  1. 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
  2. Make the changes to the library.

  3. 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:

  1. The version of the @cpanel/api library.
  2. The version of cPanel & WHM you are testing against.
  3. A step by step set of instructions on how to reproduce the bug.
  4. 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)

  1. As part of the development changes update the version property in package.json to the format X.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).
  2. Request maintainers of the repository to publish alpha builds using npm publish

Production publishing (This will be done by a UI3)

  1. When dev changes are accepted and complete update the version property in package.json to the format X.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).
  2. 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

License

Copyright © 2024 cPanel, L.L.C. Licensed under the included MIT license.