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

barracks-sdk

v0.0.2

Published

Barracks SDK node module

Downloads

3

Readme

Barracks logo

Barracks SDK for JavaScript

The JavaScript SDK to interact with the Barracks API

Installation

$ npm install barracks-sdk

Usage

Create a Barracks SDK instance:

var Barracks = require('barracks-sdk');

var barracks = new Barracks({
  apiKey: 'Your user API key',
  unitId: 'The unique device identifier'
});

Your user api key you can be found on the Account page of the Barracks application.

Check for an update:

barracks.checkUpdate(currentDeviceVersion, customClientData).then(function (update) {
  if (update) {
    // Do something with the update
  } else {
    // Do something when no updates are available
  }
}).catch(function (err) {
  // Do something with the error (See error handling section)
});

Check for an update and download it:

barracks.checkUpdate(currentDeviceVersion, customClientData).then(function (update) {
  if (update) {
    return update.download();
  }
  return Promise.resolve();
}).then(function (file) {
  if (file) {
    // Do something with the file
  }
}).catch(function (err) {
  // Do something with the error (See error handling section)
});

Check for an update and download it without chaining the Promises:

barracks.checkUpdate(currentDeviceVersion, customClientData).then(function (update) {
  if (update) {
    update.download().then(function (file) {
      // Do something with the file
    }).catch(function (err) {
      // Do something with the download error
    });
  }
}).catch(function (err) {
  // Do something with the error (See error handling section)
});

Check for an update and download it with a single function:

barracks.checkUpdateAndDownload(currentDeviceVersion, customClientData).then(function (file) {
  // Do something with the file
}).catch(function (err) {
  // Do something with the error (See error handling section)
});

Error Handling

All errors returned by the SDK follow the same object format:

{
  type: 'ERROR_TYPE',
  message: 'Details about the error'
}

Error type can be one of the the following:

  • REQUEST_FAILED, is returned by both Barracks.checkUpdate() and Barracks.checkUpdateAndDownload() methods if the check update request fails. The error object also contains one additional property requestError that is the Error object returned by the request library.
  • UNEXPECTED_SERVER_RESPONSE, is returned by both Barracks.checkUpdate() and Barracks.checkUpdateAndDownload() methods if the HTTP response code is not 200 (a new update is available) or 204 (no update available).
  • DOWNLOAD_FAILED, is returned by both Update.download() and Barracks.checkUpdateAndDownload() methods if the download of an update package fails.
  • DELETE_FILE_FAILED, is returned by both Update.download() and Barracks.checkUpdateAndDownload() methods if the SDK fail to delete an update package that did not pass the MD5 checksum verification.
  • CHECKSUM_VERIFICATION_FAILED, is returned by both Update.download() and Barracks.checkUpdateAndDownload() methods if the MD5 checksum verification of the update package downloaded fails.
  • MD5_HASH_CREATION_FAILED, is returned by both Update.download() and Barracks.checkUpdateAndDownload() methods if the SDK is not able to generate the MD5 checksum of the update package downloaded.

Docs & Community

License

Apache License, Version 2.0