• Stars
    star
    145
  • Rank 254,144 (Top 6 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created almost 10 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The SDK to make balena powered JavaScript applications.

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.

More Repositories

1

etcher

Flash OS images to SD cards & USB drives, safely and easily.
TypeScript
29,210
star
2

open-balena

Open source software to manage connected IoT devices at scale
Shell
1,060
star
3

balena-cli

The official balena CLI tool.
TypeScript
452
star
4

triangular.js

A natural fusion between d3 and angular.js. See http://alexandros.resin.io/angular-d3-svg/ for more information
CoffeeScript
174
star
5

docs

Documentation for the balenaCloud platform.
HTML
68
star
6

balena-sdk-python

Balena SDK for Python
Python
67
star
7

qemu

QEMU with additional QEMU_EXECVE flag that persists emulator after an execve
C
62
star
8

pinejs

Generate rest APIs from natural language models
TypeScript
61
star
9

open-balena-api

The core API of openBalena
TypeScript
58
star
10

open-balena-vpn

openBalena VPN
TypeScript
57
star
11

deploy-to-balena-action

Official Github action to deploy releases to balenaCloud environments
TypeScript
37
star
12

lxc-docker-PKGBUILD

Docker for the RaspberryPi
Shell
34
star
13

docker-install-script

Just the docker install script
Shell
29
star
14

etcher-cli

DEPRECATED: See https://github.com/resin-io/etcher/blob/master/docs/CLI.md
JavaScript
29
star
15

balena-cli-masterclass

A guide to getting started with the balena CLI
JavaScript
29
star
16

sshproxy

sshproxy is a simple ssh server library exposing an even simpler API
Go
28
star
17

capitano

Powerful, non opinionated command line parser for serious applications
CoffeeScript
25
star
18

autohat

balenaCloud end-to-end tests (autohat).
RobotFramework
22
star
19

balena-emails

resin.io email generator
JavaScript
18
star
20

doxx

Doxx — a static docs generator with dynamic pages support.
CoffeeScript
16
star
21

contracts

Balena.io Base Contracts
Smarty
16
star
22

open-balena-registry

Docker image storage backend for openBalena
Dockerfile
16
star
23

etcher-homepage

Static website for etcher
JavaScript
15
star
24

balenaos-masterclass

An introduction to balenaOS
14
star
25

open-balena-s3

Amazon S3-compatible storage backend for openBalena
Dockerfile
13
star
26

balena-mdns-publisher

MDNS address publisher for balena services
TypeScript
13
star
27

reconfix

(Re)Configuration toolkit
Rust
13
star
28

debugging-masterclass

A guide to debugging balena device issues
JavaScript
11
star
29

valletta

Tool to build and manage Discourse theme customizations
JavaScript
10
star
30

autohat-board

Automated Hardware Test Rig
KiCad Layout
9
star
31

docker-masterclass

JavaScript
8
star
32

pensieve

A tool for managing and viewing structured documents, backed by the power of git
JavaScript
7
star
33

balena-base-ui

Extension of resin base that adds Nginx, Yarn and Chrome
JavaScript
7
star
34

logs-to-vector

Shell
6
star
35

resin-node-images

6
star
36

balena-fleet-management-masterclass

A guide to managing an application fleet with balena
Python
6
star
37

open-balena-db

Shell
5
star
38

open-balena-haproxy

Haproxy component for resin environments (bob, onprem, etc)
Lua
5
star
39

community

5
star
40

ca-private

Certificate authority based on CloudFlare's PKI/TLS toolkit.
Shell
5
star
41

resin-multivisor

WORK IN PROGRESS: A modified resin-supervisor that runs as a Resin app and runs multiple containers
CoffeeScript
5
star
42

onlinelabs-cloudformation

CloudFormation Custom Resources for online.net ARM servers
CoffeeScript
5
star
43

balena-cli-advanced-masterclass

A guide to the advanced features available in balena CLI
JavaScript
5
star
44

balena-supervisor-base

Minimal base image for https://github.com/balena-io/balena-supervisor - built with Yocto
Shell
5
star
45

resin-cli-installer-osx

Resin CLI OS X installer
Makefile
4
star
46

arm-builder-kernels

Custom Linux kernel for balenaCloud remote ARM builders.
Dockerfile
4
star
47

resin-yocto

[deprecated] Resin.io Yocto manifests with repo tool
4
star
48

open-balena-registry-proxy

Pull images from balenaCloud container registry with fleet slugs!
TypeScript
4
star
49

resin-plugin-sync

[DEPRECATED] Watch a local project directory and sync it on the fly.
CoffeeScript
4
star
50

services-masterclass

A guide to developing and deploying services on a balena device
JavaScript
4
star
51

cert-manager

Certificate manager with Let's Encrypt DNS validation and private CA support
Shell
4
star
52

renovate-config

Shared renovate configuration and GitHub Action
JavaScript
4
star
53

resin-network-config

DEPRECATED. Handle resin images network configuration.
CoffeeScript
3
star
54

resin-parallella-demo

C
3
star
55

python-connman-control

Example python application that connects to the network manager running on a Resin device.
Python
3
star
56

diskio

DEPRECATED. Raw disk I/O that works in all major operating systems
CoffeeScript
3
star
57

autohat-ondevice

On device application for Automated Hardware Tests
Python
3
star
58

node-audio-stream-skew-correction

Testing audio stream time skew correction in NodeJS
CoffeeScript
3
star
59

resin-cli-installer-win32

Resin CLI Win32 installer
NSIS
2
star
60

capitanodoc

Documentation generator for Capitano projects
JavaScript
2
star
61

resin-device-path

DEPRECATED. Parse Resin.io device and partition paths.
CoffeeScript
2
star
62

balena-masterclass-skeleton

A template skeleton base for balena masterclasses
2
star
63

resin-config-inject

DEPRECATED. Resin.io config.json injection.
CoffeeScript
2
star
64

resin-image

DEPRECATED. Resin.io image utilities.
CoffeeScript
2
star
65

resin-image-config

DEPRECATED. Resin.io image FAT configuration
CoffeeScript
2
star
66

resin-olive-fruit

CoffeeScript
2
star
67

node-binary

DEPRECATED: Download node binaries for various platforms and architectures, easily.
CoffeeScript
2
star
68

leviathan-worker

TypeScript
2
star
69

fleetops-os-update

Shell
2
star
70

resin-librato

Shell
2
star
71

balena-popularity-metrics

TypeScript
2
star
72

fleetops-supervisor-update

Shell
1
star
73

networking-masterclass

A guide to on-device networking on balena devices
1
star
74

balena-blog

Create, edit, and manage the content and design of balena's blog. Uses GatsbyJS and hosted on Netlify.
JavaScript
1
star
75

resin-caddy

Caddy Docker container
JavaScript
1
star
76

autohat-resin-jenkins

Resin application to manage AutoHAT rack
Shell
1
star
77

fleetops-appmigrate

(Experimental) migrate balenaOS devices between apps while migrating volume data
Shell
1
star
78

etcher-homepage-staging

JavaScript
1
star
79

autohat-configurator

A resin application that allows to configure an autohat for a specific device type testing
JavaScript
1
star