Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

balena-register-device

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

balena-register-device - npm Package Compare versions

Comparing version 6.1.6 to 7.0.0-7-x-933e42c26f327bbf94ce5302dcaa1a809ba65dc8

build/register.d.ts

215

build/register.js

@@ -1,5 +0,4 @@

// Generated by CoffeeScript 1.12.7
"use strict";
/*
Copyright 2016 Balena
Copyright 2016-2020 Balena Ltd.

@@ -17,14 +16,16 @@ Licensed under the Apache License, Version 2.0 (the "License");

limitations under the License.
*/
var ApiError, Promise, TypedError, randomstring,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Promise = require('bluebird');
randomstring = require('randomstring');
TypedError = require('typed-error');
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiError = exports.getRegisterDevice = void 0;
const randomstring = require("randomstring");
const typed_error_1 = require("typed-error");
/**

@@ -37,106 +38,92 @@ * @summary Creates a Balena Register Device instance

*/
module.exports = function(arg) {
var request;
request = arg.request;
return {
exports.getRegisterDevice = ({ request, }) => ({
/**
* @summary Generate a random key, useful for both uuid and api key.
* @function
* @public
*
* @returns {String} A generated key
*
* @example
* randomKey = deviceRegister.generateUniqueKey()
* # randomKey is a randomly generated key that can be used as either a uuid or an api key
* console.log(randomKey)
* @summary Generate a random key, useful for both uuid and api key.
* @function
* @public
*
* @returns {String} A generated key
*
* @example
* randomKey = deviceRegister.generateUniqueKey()
* # randomKey is a randomly generated key that can be used as either a uuid or an api key
* console.log(randomKey)
*/
generateUniqueKey: function() {
return randomstring.generate({
length: 32,
charset: 'hex'
});
generateUniqueKey() {
return randomstring.generate({
length: 32,
charset: 'hex',
});
},
/**
* @summary Register a device with Balena
* @function
* @public
*
* @description
* This function allows promise style if the callback is omitted.
*
* @param {Object} options - options
* @param {Number} [options.userId] - user id
* @param {Number} options.applicationId - application id
* @param {String} options.uuid - device uuid
* @param {String} options.deviceType - device type
* @param {String} options.deviceApiKey - api key to create for the device
* @param {String} options.provisioningApiKey - provisioning api key
* @param {String} options.apiEndpoint - api endpoint
* @param {Function} [callback] - callback (error, deviceInfo)
*
* @example
* deviceRegister.register
* userId: 199
* applicationId: 10350
* uuid: '...'
* deviceType: 'raspberry-pi'
* deviceApiKey: '...'
* provisioningApiKey: '...'
* apiEndpoint: 'https://api.balena-cloud.com'
* , (error, deviceInfo) ->
* throw error if error?
* console.log(deviceInfo) # { id }
* @summary Register a device with Balena
* @function
* @public
*
* @param {Object} options - options
* @param {Number} [options.userId] - user id
* @param {Number} options.applicationId - application id
* @param {String} options.uuid - device uuid
* @param {String} options.deviceType - device type
* @param {String} options.deviceApiKey - api key to create for the device
* @param {String} options.provisioningApiKey - provisioning api key
* @param {String} options.apiEndpoint - api endpoint
*
* @example
* deviceRegister.register
* userId: 199
* applicationId: 10350
* uuid: '...'
* deviceType: 'raspberry-pi'
* deviceApiKey: '...'
* provisioningApiKey: '...'
* apiEndpoint: 'https://api.balena-cloud.com'
* .then (deviceInfo) ->
* console.log(deviceInfo) # { id }
*/
register: Promise.method(function(options, callback) {
var i, len, opt, ref;
ref = ['applicationId', 'uuid', 'deviceType', 'provisioningApiKey', 'apiEndpoint'];
for (i = 0, len = ref.length; i < len; i++) {
opt = ref[i];
if (options[opt] == null) {
throw new Error("Options must contain a '" + opt + "' entry.");
}
}
return request.send({
method: 'POST',
baseUrl: options.apiEndpoint,
url: '/device/register',
refreshToken: false,
sendToken: false,
headers: {
Authorization: "Bearer " + options.provisioningApiKey
},
timeout: 30000,
body: {
user: options.userId,
application: options.applicationId,
uuid: options.uuid,
device_type: options.deviceType,
api_key: options.deviceApiKey
}
}).tap(function(response) {
if (response.statusCode !== 201) {
throw new ApiError(response.body, response);
}
}).get('body').asCallback(callback);
})
};
};
module.exports.ApiError = ApiError = (function(superClass) {
extend(ApiError, superClass);
function ApiError(message, response1) {
if (message == null) {
message = 'Error with API request';
register: function (options) {
return __awaiter(this, void 0, void 0, function* () {
for (const opt of [
'applicationId',
'uuid',
'deviceType',
'provisioningApiKey',
'apiEndpoint',
]) {
if (options[opt] == null) {
throw new Error(`Options must contain a '${opt}' entry.`);
}
}
const response = yield request
.send({
method: 'POST',
baseUrl: options.apiEndpoint,
url: '/device/register',
refreshToken: false,
sendToken: false,
headers: {
Authorization: `Bearer ${options.provisioningApiKey}`,
},
timeout: 30000,
body: {
user: options.userId,
application: options.applicationId,
uuid: options.uuid,
device_type: options.deviceType,
api_key: options.deviceApiKey,
},
});
if (response.statusCode !== 201) {
throw new ApiError(response.body, response);
}
return response.body;
});
},
});
class ApiError extends typed_error_1.TypedError {
constructor(message = 'Error with API request', response) {
super(message);
this.response = response;
}
this.response = response1;
ApiError.__super__.constructor.call(this, this.message);
}
return ApiError;
})(TypedError);
}
exports.ApiError = ApiError;

@@ -8,2 +8,12 @@ # Change Log

# v7.0.0
## (2020-07-03)
* Update to balena-request 11.x [Pagan Gazzard]
* Switch to returning native promises [Pagan Gazzard]
* Update to typed-error 3.x [Pagan Gazzard]
* Convert to typescript [Pagan Gazzard]
* Switch to a named export [Pagan Gazzard]
* Drop callback interface in favor of promise interface [Pagan Gazzard]
# v6.1.6

@@ -10,0 +20,0 @@ ## (2020-05-26)

{
"name": "balena-register-device",
"version": "6.1.6",
"version": "7.0.0-7-x-933e42c26f327bbf94ce5302dcaa1a809ba65dc8",
"description": "Balena device registration utilities",

@@ -24,9 +24,10 @@ "main": "build/register.js",

"scripts": {
"build": "gulp build",
"lint:coffee": "balena-lint lib gulpfile.coffee",
"lint:js": "balena-lint -e js --typescript tests",
"lint": "npm run lint:coffee && npm run lint:js",
"test-node": "gulp test",
"build": "npx tsc",
"lint": "balena-lint -e js --typescript lib tests",
"lint-fix": "balena-lint -e js --typescript --fix lib tests",
"test-node": "npx mocha --reporter spec tests/**/*.spec.js",
"test-browser": "mockttp -c karma start",
"test": "npm run lint && npm run test-node && npm run test-browser",
"pretest": "npm run build",
"test": "npm run test-node && npm run test-browser",
"posttest": "npm run lint",
"prepare": "npm run build"

@@ -37,12 +38,7 @@ },

"devDependencies": {
"@balena/lint": "^5.0.2",
"@balena/lint": "^5.1.0",
"balena-config-karma": "^2.3.1",
"balena-request": "^10.0.0",
"balena-request": "^10.0.9",
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"coffeescript": "~1.12.2",
"gulp": "^4.0.2",
"gulp-coffee": "^2.3.0",
"gulp-mocha": "^7.0.2",
"gulp-util": "^3.0.1",
"karma": "^1.7.0",

@@ -55,9 +51,9 @@ "lodash": "^4.0.0",

"dependencies": {
"bluebird": "^3.7.2",
"@types/randomstring": "^1.1.6",
"randomstring": "^1.1.5",
"typed-error": "^2.0.0"
"typed-error": "^3.2.0"
},
"peerDependencies": {
"balena-request": "^10.0.0"
"balena-request": "^11.0.0-11-x-0f67d2157ff70c8cfada7b6359ba4b58aeeacf3c"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc