Giter Club home page Giter Club logo

balena-sdk's Introduction

Balena SDK

The official JavaScript balena SDK.

npm version dependencies Build Status Build status

Role

The intention of this module is to provide developers a nice API to integrate their JavaScript applications with balena.

Installation

Install the balena SDK by running:

$ npm install --save balena-sdk

Platforms

We currently support NodeJS (6+) and the browser.

The following features are node-only:

  • OS image streaming download (balena.models.os.download),
  • balena settings client (balena.settings).

In Node you can simply require('balena-sdk'), but in the browser things are more complicated. The balena SDK provides a bundled single file for browsers, which allows you to include a single file with all dependencies included, available as balena-browser.min.js (or balena-browser.js if you'd like the much larger unminified version). This uses the UMD format, and will register itself as either a CommonJS or AMD module called balena-sdk if possible, or create a balenaSdk global if not.

Bundling for browsers

If you're using webpack, browserify, or a similar tool then you probably want to bundle the balena SDK into your application yourself, rather than using the pre-built balena-browser.js bundle. If you do that, you should be aware that you may pick up some dependencies that are actually unnecessary in the browser, because they're only used in Node environments. You can safely exclude these dependencies, if you're not using them yourself, and significantly reduce the size of your resulting bundle.

In the browser the balena SDK doesn't use the following dependencies:

  • fs
  • path
  • balena-settings-client
  • node-localstorage

For the future we're looking at ways to automatically exclude these in downstream bundles. See #254 for more information.

Documentation

The module exports a single factory function. Use it like this:

var balena = require('balena-sdk')({
	apiUrl: "https://api.balena-cloud.com/",
	dataDirectory: "/opt/local/balena"
})

Where the factory method accepts the following options:

  • apiUrl, string, optional, is the balena API url. Defaults to https://api.balena-cloud.com/,
  • builderUrl, string, optional , is the balena builder url. Defaults to https://builder.balena-cloud.com/,
  • imageMakerUrl, string, optional deprecated , is the balena image maker url. Defaults to https://img.balena-cloud.com/,
  • deviceUrlsBase, string, optional, is the base balena device API url. Defaults to balena-devices.com,
  • dataDirectory, string, optional, ignored in the browser, is the directory where the user settings are stored, normally retrieved like require('balena-settings-client').get('dataDirectory'). Defaults to $HOME/.balena,
  • isBrowser, boolean, optional, is the flag to tell if the module works in the browser. If not set will be computed based on the presence of the global window value,
  • debug, boolean, optional, when set will print some extra debug information.

See the JSDoc markdown documentation for the returned balena object in DOCUMENTATION.md.

Support

If you're having any problem, please raise an issue on GitHub and the balena team will be happy to help.

Tests

In order to run the balena SDK test suite, set the following environment variables from an account that exists and doesn't have a billing account code:
WARNING: This will delete all applications and public keys of the test user

  • TEST_EMAIL: The main account email
  • TEST_PASSWORD: The main account password
  • TEST_USERNAME: The main account username.

You also have to provide the following environment variables from an account that doesn't yet exists:

  • TEST_REGISTER_EMAIL: The email of the account to register.
  • TEST_REGISTER_PASSWORD: The password of the account to register.
  • TEST_REGISTER_USERNAME: The username of the account to register.

In order to test the billing methods for a paid account, you also have to configure the following environment variables:

  • TEST_PAID_EMAIL: The email of the paid account.
  • TEST_PAID_PASSWORD: The password of the account.

Note: The paid user's account billing code should be set to testdev so that it's tested against the test plan.

You can also, optionally, set the TEST_API_URL environment variable in order to run the tests using a different API backend (eg: https://api.balena-staging.com).

You can persist these settings by putting them all into a .env file in the root of this repo, in dotenv format (KEY=VALUE\n). This will be automatically detected and used in the tests. Make sure you don't accidentally commit this file (.env by default is gitignored, so hopefully this should be difficult).

Run the test suite by doing:

$ npm test

In order to make the develop & test cycle faster, you can use mocha's .only & .skip variants to only run the subset of the test cases that is relevant to your changes/additions. You should make sure to remove those from your code before you push and make sure that the complete test suite completes successfully.

Contribute

Before submitting a PR, please make sure that you

  • don't have uncommited changes on the documentation or the build output
  • don't have any .only or .skip in your tests
  • include typings for new methods
  • include tests and that they pass
$ npm test

License

The project is licensed under the Apache 2.0 license.

balena-sdk's People

Contributors

balena-ci avatar dimitrisnl avatar emirotin avatar flesler avatar hedss avatar horia-delicoti avatar james2710 avatar jviotti avatar karaxuna avatar lekkas avatar lucianbuzzo avatar moranf avatar page- avatar pcarranzav avatar pimterry avatar sradevski avatar thgreasi avatar xginn8 avatar zvin avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.