17.5.0 • Published 9 months ago

balena-sdk v17.5.0

Weekly downloads
5,351
License
Apache-2.0
Repository
github
Last release
9 months ago

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 (14+) 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. 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. You can also use the es2018 version if desired.

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.min.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.

Bundling with pkg

The balena SDK includes builds for various ECMAScript versions that are dynamically selected at runtime (using @balena/es-version). For this reason, packagers like pkg are not able to automatically detect which assets to include in the output package. The following sample pkg section should be added to your application's package.json file to instruct pkg to bundle the required assets:

  "pkg": {
    "scripts": [
      "node_modules/balena-sdk/**/*.js"
    ],
    "assets": [
      "node_modules/pinejs-client-core/**/*"
    ]
  }

For more information, please refer to the respective documentation from the pkg project.

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/,
  • 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 face any issues, please raise an issue on GitHub and the balena team will be happy to help.

Deprecation policy

The balena SDK uses semver versioning, with the concepts of major, minor and patch version releases.

The latest release of the previous major version of the balena SDK will remain compatible with the balenaCloud backend services for one year from the date when the next major version is released. For example, balena SDK v12.33.4, as the latest v12 release, would remain compatible with the balenaCloud backend for one year from the date when v13.0.0 is released.

At the end of this period, the older major version is considered deprecated and some of the functionality that depends on balenaCloud services may stop working at any time. Users are encouraged to regularly update the balena SDK to the latest version.

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 users. As such, all emails are required to contain the string +testsdk to avoid accidental deletion

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

  • TEST_MEMBER_EMAIL: The email of the account for the membership tests.

  • TEST_MEMBER_PASSWORD: The password of the account for the membership tests.
  • TEST_MEMBER_USERNAME: The username of the account for the membership tests.

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

  • 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.
  • You can use npm run test:fast which fixes linting issues, only builds for a single ES target and runs the tests only on node. This can save time when implementing a method that interacts with an API endpoint, but should be avoided if the feature might work different or only in the browser.

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
  • ran the lint script on the modified files
$ npm run lint:fix
  • include tests and that they pass
$ npm test

License

The project is licensed under the Apache 2.0 license.

17.5.0

9 months ago

17.3.2

9 months ago

17.3.1

10 months ago

17.4.0

9 months ago

17.1.2

10 months ago

17.1.1

10 months ago

17.1.4

10 months ago

17.1.3

10 months ago

17.1.0

10 months ago

16.45.0

11 months ago

16.45.1

10 months ago

17.2.1

10 months ago

17.2.0

10 months ago

17.2.3

10 months ago

17.2.2

10 months ago

17.3.0

10 months ago

16.44.2

11 months ago

16.44.3

11 months ago

17.0.2

10 months ago

17.0.1

10 months ago

17.0.0

10 months ago

16.42.0

11 months ago

16.43.0

11 months ago

16.44.0

11 months ago

16.44.1

11 months ago

16.41.0

12 months ago

16.39.0

12 months ago

16.39.1

12 months ago

16.40.0

12 months ago

16.36.0

1 year ago

16.36.1

1 year ago

16.36.2

1 year ago

16.36.3

1 year ago

16.36.4

1 year ago

16.36.5

1 year ago

16.36.6

1 year ago

16.32.2

1 year ago

16.32.3

1 year ago

16.37.0

1 year ago

16.33.0

1 year ago

16.38.0

1 year ago

16.38.1

1 year ago

16.38.2

1 year ago

16.34.0

1 year ago

16.35.0

1 year ago

16.32.1

1 year ago

16.30.1

1 year ago

16.30.2

1 year ago

16.31.0

1 year ago

16.31.1

1 year ago

16.31.2

1 year ago

16.27.0

1 year ago

16.28.0

1 year ago

16.28.2

1 year ago

16.28.1

1 year ago

16.28.4

1 year ago

16.29.1

1 year ago

16.29.0

1 year ago

16.29.3

1 year ago

16.29.2

1 year ago

16.30.0

1 year ago

16.26.6

1 year ago

16.26.7

1 year ago

16.26.2

2 years ago

16.26.4

2 years ago

16.26.3

2 years ago

16.26.5

2 years ago

16.23.0

2 years ago

16.24.0

2 years ago

16.24.2

2 years ago

16.24.1

2 years ago

16.25.1

2 years ago

16.25.0

2 years ago

16.26.0

2 years ago

16.26.1

2 years ago

16.20.0

2 years ago

16.20.2

2 years ago

16.20.1

2 years ago

16.20.4

2 years ago

16.20.3

2 years ago

16.20.6

2 years ago

16.20.5

2 years ago

16.19.14

2 years ago

16.21.1

2 years ago

16.21.0

2 years ago

16.22.0

2 years ago

16.19.8

2 years ago

16.19.9

2 years ago

16.19.11

2 years ago

16.19.10

2 years ago

16.19.13

2 years ago

16.19.12

2 years ago

16.18.0

2 years ago

16.19.6

2 years ago

16.19.5

2 years ago

16.19.7

2 years ago

16.19.0

2 years ago

16.19.2

2 years ago

16.19.1

2 years ago

16.19.4

2 years ago

16.19.3

2 years ago

16.16.1

2 years ago

16.17.0

2 years ago

16.15.1

2 years ago

16.16.0

2 years ago

16.5.0

2 years ago

16.14.0

2 years ago

16.3.0

2 years ago

16.12.1

2 years ago

16.12.0

2 years ago

16.9.1

2 years ago

16.9.0

2 years ago

16.9.4

2 years ago

16.9.3

2 years ago

16.9.2

2 years ago

16.7.0

2 years ago

16.1.0

2 years ago

16.10.0

2 years ago

16.15.0

2 years ago

16.6.0

2 years ago

16.13.0

2 years ago

16.13.2

2 years ago

16.13.1

2 years ago

16.13.4

2 years ago

16.13.3

2 years ago

16.4.1

2 years ago

16.4.0

2 years ago

16.8.2

2 years ago

16.8.1

2 years ago

16.8.0

2 years ago

15.59.1

2 years ago

15.59.2

2 years ago

16.11.0

2 years ago

16.11.2

2 years ago

16.11.1

2 years ago

16.11.3

2 years ago

16.2.0

2 years ago

16.2.3

2 years ago

16.2.2

2 years ago

16.2.1

2 years ago

16.0.0

2 years ago

15.56.0

2 years ago

15.58.1

2 years ago

15.58.0

2 years ago

15.59.0

2 years ago

15.55.0

2 years ago

15.57.2

2 years ago

15.57.0

2 years ago

15.57.1

2 years ago

15.54.2

2 years ago

15.54.1

2 years ago

15.54.0

2 years ago

15.52.0

2 years ago

15.53.0

2 years ago

15.51.4

2 years ago

15.51.2

2 years ago

15.51.3

2 years ago

15.51.1

3 years ago

15.51.0

3 years ago

15.50.1

3 years ago

15.50.0

3 years ago

15.49.1

3 years ago

15.49.0

3 years ago

15.48.1

3 years ago

15.48.3

3 years ago

15.48.2

3 years ago

15.48.0

3 years ago

15.47.1

3 years ago

15.47.0

3 years ago

15.46.1

3 years ago

15.45.0

3 years ago

15.46.0

3 years ago

15.44.0

3 years ago

15.43.0

3 years ago

15.42.2

3 years ago

15.42.1

3 years ago

15.42.0

3 years ago

15.41.1

3 years ago

15.41.0

3 years ago

15.40.0

3 years ago

15.39.3

3 years ago

15.39.2

3 years ago

15.39.4

3 years ago

15.36.0

3 years ago

15.38.0

3 years ago

15.34.2

3 years ago

15.37.0

3 years ago

15.39.1

3 years ago

15.39.0

3 years ago

15.35.2

3 years ago

15.35.1

3 years ago

15.35.0

3 years ago

15.34.1

3 years ago

15.34.0

3 years ago

15.33.0

3 years ago

15.32.0

3 years ago

15.31.2

3 years ago

15.31.1

3 years ago

15.31.0

3 years ago

15.30.2

3 years ago

15.30.1

3 years ago

15.30.0

3 years ago

15.29.0

3 years ago

15.28.1

3 years ago

15.28.0

3 years ago

15.27.1

3 years ago

15.27.0

3 years ago

15.26.0

3 years ago

15.25.1

3 years ago

15.25.2

3 years ago

15.25.0

3 years ago

15.24.7

3 years ago

15.24.6

3 years ago

15.24.5

3 years ago

15.24.4

3 years ago

15.24.2

3 years ago

15.24.3

3 years ago

15.24.1

3 years ago

15.24.0

3 years ago

15.23.2

3 years ago

15.23.1

3 years ago

15.23.0

3 years ago

15.22.2

3 years ago

15.22.0

3 years ago

15.22.1

3 years ago

15.21.5

3 years ago

15.21.4

3 years ago

15.21.3

3 years ago

15.21.2

3 years ago

15.21.1

3 years ago

15.21.0

3 years ago

15.20.0

3 years ago

15.19.0

3 years ago

15.18.1

3 years ago

15.18.0

3 years ago

15.17.0

3 years ago

15.16.0

3 years ago

15.15.0

3 years ago

15.14.0

3 years ago

15.13.0

3 years ago

15.12.1

4 years ago

15.12.0

4 years ago

15.11.2

4 years ago

15.11.3

4 years ago

15.11.1

4 years ago

15.11.0

4 years ago

15.10.6

4 years ago

15.10.5

4 years ago

15.10.4

4 years ago

15.10.3

4 years ago

15.10.2

4 years ago

15.10.1

4 years ago

15.10.0

4 years ago

15.9.0

4 years ago

15.9.1

4 years ago

15.8.1

4 years ago

15.8.0

4 years ago

15.7.0

4 years ago

15.7.1

4 years ago

15.6.0

4 years ago

15.5.0

4 years ago

15.4.5

4 years ago

15.4.4

4 years ago

15.4.1

4 years ago

15.4.0

4 years ago

15.4.2

4 years ago

15.3.7

4 years ago

15.3.4

4 years ago

15.3.6

4 years ago

15.3.5

4 years ago

15.3.3

4 years ago

15.3.2

4 years ago

15.3.1

4 years ago

15.3.0

4 years ago

15.2.4

4 years ago

15.2.5

4 years ago

15.2.3

4 years ago

15.2.2

4 years ago

15.2.1

4 years ago

15.2.0

4 years ago

15.1.1

4 years ago

15.1.0

4 years ago

15.0.3

4 years ago

15.0.2

4 years ago

15.0.1

4 years ago

15.0.0

4 years ago

14.8.0

4 years ago

14.7.1

4 years ago

14.7.0

4 years ago

14.6.0

4 years ago

14.5.1

4 years ago

14.5.0

4 years ago

14.4.2

4 years ago

14.4.1

4 years ago

14.4.0

4 years ago

14.3.3

4 years ago

14.3.2

4 years ago

14.3.1

4 years ago

14.3.0

4 years ago

14.2.9

4 years ago

14.2.8

4 years ago

14.2.7

4 years ago

14.2.5

4 years ago

14.2.6

4 years ago

14.2.4

4 years ago

14.2.3

4 years ago

14.2.2

4 years ago

14.2.1

4 years ago

14.2.0

4 years ago

14.1.0

4 years ago

14.0.2

4 years ago

14.0.1

4 years ago

14.0.0

4 years ago

13.8.0

4 years ago

13.7.0

4 years ago

13.6.0

4 years ago

13.5.0

4 years ago

13.4.2

4 years ago

13.4.1

4 years ago

13.3.8

4 years ago

13.3.7

4 years ago

13.3.6

4 years ago

13.3.5

4 years ago

13.3.4

4 years ago

13.3.3

4 years ago

13.3.1

4 years ago

13.3.2

4 years ago

13.3.0

4 years ago

13.2.7

4 years ago

13.2.6

4 years ago

13.2.5

4 years ago

13.2.4

4 years ago

13.2.3

4 years ago

13.2.2

4 years ago

13.2.1

4 years ago

13.2.0

4 years ago

13.1.1

4 years ago

13.1.0

4 years ago

13.0.2

4 years ago

13.0.1

4 years ago

13.0.0

4 years ago

12.33.0

4 years ago

12.32.0

4 years ago

12.31.13

4 years ago

12.31.12

4 years ago

12.31.11

4 years ago

12.31.10

4 years ago

12.31.9

4 years ago

12.31.8

4 years ago

12.31.7

4 years ago

12.31.6

4 years ago

12.31.5

4 years ago

12.31.4

4 years ago

12.31.3

4 years ago

12.31.2

4 years ago

12.31.1

4 years ago

12.31.0

4 years ago

12.30.4

4 years ago

12.30.5

4 years ago

12.30.6

4 years ago

12.30.3

4 years ago

12.30.2

4 years ago

12.30.1

4 years ago

12.30.0

4 years ago

12.29.3

4 years ago

12.29.2

4 years ago

12.29.1

4 years ago

12.29.0

4 years ago

12.28.2

4 years ago

12.28.1

4 years ago

12.27.0

4 years ago

12.27.1

4 years ago

12.28.0

4 years ago

12.26.7

4 years ago

12.26.6

4 years ago

12.26.5

4 years ago

12.26.4

4 years ago

12.26.3

4 years ago

12.26.2

4 years ago

12.26.1

4 years ago

12.26.0

4 years ago

12.25.1

4 years ago

12.25.0

4 years ago

12.24.4

4 years ago

12.24.3

4 years ago

12.24.2

4 years ago

12.24.1

4 years ago

12.24.0

4 years ago

12.23.9

4 years ago

12.23.8

4 years ago

12.23.7

4 years ago

12.23.6

4 years ago

12.23.5

4 years ago

12.23.4

4 years ago

12.23.1

4 years ago

12.23.2

4 years ago

12.23.3

4 years ago

12.23.0

4 years ago

12.21.3

4 years ago

12.22.0

4 years ago

12.21.2

4 years ago

12.21.1

4 years ago

12.21.0

4 years ago

12.20.4

4 years ago

12.20.3

4 years ago

12.20.2

4 years ago

12.20.1

4 years ago

12.20.0

4 years ago

12.19.0

4 years ago

12.18.0

4 years ago

12.17.6

4 years ago

12.17.5

4 years ago

12.17.4

4 years ago

12.17.3

4 years ago

12.17.2

4 years ago

12.17.1

4 years ago

12.17.0

4 years ago

12.16.4

4 years ago

12.16.3

4 years ago

12.16.2

4 years ago

12.16.1

4 years ago

12.16.0

4 years ago

12.15.3

4 years ago

12.15.2

4 years ago

12.15.1

4 years ago

12.15.0

4 years ago

12.14.0

4 years ago

12.13.0

4 years ago

12.12.1

4 years ago

12.12.0

4 years ago

12.11.1

5 years ago

12.11.0

5 years ago

12.10.2

5 years ago

12.10.1

5 years ago

12.10.0

5 years ago

12.9.0

5 years ago

12.8.0

5 years ago

12.7.1

5 years ago

12.7.0

5 years ago

12.6.0

5 years ago

12.5.0

5 years ago

12.4.2

5 years ago

12.4.1

5 years ago

12.4.0

5 years ago

12.3.0

5 years ago

12.2.0

5 years ago

12.1.4

5 years ago

12.1.3

5 years ago

12.1.2

5 years ago

12.1.1

5 years ago

12.1.0

5 years ago

12.0.1

5 years ago

12.0.0

5 years ago

11.18.2

5 years ago

11.18.1

5 years ago

11.18.0

5 years ago

11.17.1

5 years ago

11.17.0

5 years ago

11.16.1

5 years ago

11.16.0

5 years ago

11.15.0

5 years ago

11.14.3

5 years ago

11.14.2

5 years ago

11.14.1

5 years ago

11.14.0

5 years ago

11.13.0

5 years ago

11.12.0

5 years ago

11.11.2

5 years ago

11.11.1

5 years ago

11.11.0

5 years ago

11.10.0

5 years ago

11.9.1

5 years ago

11.9.0

5 years ago

11.8.0

5 years ago

11.7.1

5 years ago

11.7.0

5 years ago

11.6.4

5 years ago

11.6.3

5 years ago

11.6.2

5 years ago

11.6.1

5 years ago

11.6.0

5 years ago

11.5.0

5 years ago

11.4.0

5 years ago

11.3.0

5 years ago

11.2.1

5 years ago

11.2.0

5 years ago

11.1.1

5 years ago

11.1.0

5 years ago

11.0.0

5 years ago

11.0.0-beta1

5 years ago