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

jiffybox

v0.0.3

Published

HTTPS client for accessing JiffyBox API

Downloads

1

Readme

JiffyBox

Client library for managing domainFACTORY virtual servers via the JiffyBox API.

Original (German) PDF Documentation.

The JiffyBox API is a simple HTTP REST API.

This library uses the request, rate limiter, and bluebird Promise library to make the API usage a bit more comfortable (and honor the API limits!).

Sample Usage

var client = require("jiffybox")("API KEY HERE");

// Get a listing of your JiffyBoxes
client.getJiffyBoxes().then(function(boxes){
  // boxes is Array of data from Webservice
})

// Using bluebird promises, create a box & wait for it to be ready
Promise.try(function(){
  return [
    client.getDistros(),
    client.getPlans()
  ]
})
.spread(function(distros, plans){
  client.createJiffyBox({
    name: "TestBox",
    planid: pickPlan(plans),           // your own function!
    distribution: pickDistro(distros), // your own function!
    password: "super secret password",
  })
})
.then(function(box){
  isReady = function(box){ return box.running && box.status === "READY"};
  client.waitForStatus(box.id, isReady)
})
.then(function(box){
  console.log("Your JiffyBox '" + box.name + "' is ready")
})
.catch(function(e){
  console.error(e)
})

Methods

You must first always provide your API key to create a client:

var client = require("jiffybox")(apiKey);

NOTE: the JiffyBox API often returns lists of things (servers, plans, distributions) as an object, where I preferred an array. In these cases, this library converts it to an array of objects, adding the property "key" to each entry (which is sometimes needed). The property "key" is not native to the JiffyBox API, but all other properties refer directly to the API objects.

Promise-based API

All other methods return a Promise for a value. Only the value is described below!

client.getDistros()

Gets an array of currently available distributions. Each distro has:

  • minDiskSizeMB (e.g. 2048)
  • name (e.g. 'Debian Jessie (8) 64-Bit')
  • rootdiskMode (e.g. 'ro')
  • defaultKernel (e.g. 'xen-pvops-x86_64')
  • key (e.g. 'debian_jessie_64bit')

client.getPlans()

Gets an array of currently available server plans. Each plan has:

  • id (e.g. 20, needed for creating JiffyBox)
  • name (e.g. 'CloudLevel 1', see JiffyBox products)
  • diskSizeInMB (e.g. 76800)
  • ramInMB (e.g. 2048)
  • pricePerHour (e.g. 0.02, Euro/hour when active)
  • pricePerHourFrozen (e.g. 0.005, Euro/hour when frozen)
  • cpus (e.g. 3)
  • key (e.g. '20')

client.getBackups()

Gets an array of available backups. Each backup has:

  • daily: backup object
  • weekly: backup object
  • biweekly: backup object
  • key: string, corresponds to the JiffyBox ID backups are for

Each backup object has:

  • id: string
  • created: UNIX timestamp

client.createJiffyBox(options)

Creates a brand-new JiffyBox. According to the API, the following properties must be given:

  • name (string: unique to account, max 30 chars, and may contain spaces and the following characters: "a-zA-Z0-9üöäÜÖÄß_()=!*@.-"
  • planid: must match either id or name of one of the plans

And you also have to have *exactly one of these, NOT both:

  • backupid: from client.getBackups() (to clone from a backup)
  • distribution: from client.getDistros(), corresponds to key property

The following are optional:

  • password: (string) set the root password instead of creating a random one
  • use_sshkey: (bool) sets up root login to accept SSH keys (setup via JiffyBox control panel required)
  • metadata: (object) arbitrary metadata

client.getJiffyBoxes()

Gets all JiffyBoxes for your account. Refer to the API for full documentation. These are the ones I find most useful:

  • id (number) used for deletion and status changing
  • name (string) the unique name for the server
  • ips: (object)
    • public: array of public IP addresses
    • private: array of private IP addresses (internal JiffyBox network)
  • status (string)

client.getJiffyBox(id)

Gets data for a single JiffyBox. See client.getJiffyBoxes()

client.deleteJiffyBox(id)

Deletes a single JiffyBox. Note that the status must first be "SHUTDOWN".

client.setStatus(id, status)

Sets the status of a single JiffyBox. Most useful values of status are:

  • "START": starts the server
  • "SHUTDOWN": shuts down the server
  • "PULLPLUG": perform a pull-the-plug, i.e. immediate power off
  • "FREEZE": freezes the box
  • "THAW": unfreezes the box

Usually you will use the next method instead...

client.setStatusAndWait(id, nextStatus, checkStatus)

Sets the status and waits until the status was adopted (internally polling every 5 seconds to check the status).

The parameter nextStatus is a string (see client.setStatus()).

The parameter checkStatus is either a string or function. If a string, the Promise will be fulfilled as soon as the JiffyBox's status field matches this. If a function (better for API), the function will be called on every internal polling to see if the status is done.

Here are two examples from the tests:

// for starting up
function boxIsReady(box) {
  return box.status === "READY" && box.running;
}
client.setStatusAndWait(id, "START", boxIsReady);

// for shutting down
function boxIsShutdown(box) {
  return box.status === "READY" && ! box.running;
}
client.setStatusAndWait(id, "SHUTDOWN", boxIsShutdown);

client.waitForStatus(id, checkStatus)

Similar to client.setStatusAndWait(), but does not try to set a status. Used internally, but if you never set a status elsewhere, this could hang forever. However, you could use the bluebird Promise.timeout API to ensure it does not do so.