balena-register-device
Advanced tools
Comparing version 6.1.6 to 7.0.0-7-x-07c1879565f07fa35a8966f2d443b8e745d05a22
@@ -1,5 +0,4 @@ | ||
// Generated by CoffeeScript 1.12.7 | ||
"use strict"; | ||
/* | ||
Copyright 2016 Balena | ||
Copyright 2016-2020 Balena Ltd. | ||
@@ -17,14 +16,8 @@ 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'); | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ApiError = exports.getRegisterDevice = void 0; | ||
const tslib_1 = require("tslib"); | ||
const randomstring = require("randomstring"); | ||
const typed_error_1 = require("typed-error"); | ||
/** | ||
@@ -37,106 +30,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 tslib_1.__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-07c1879565f07fa35a8966f2d443b8e745d05a22", | ||
"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,10 @@ "lodash": "^4.0.0", | ||
"dependencies": { | ||
"bluebird": "^3.7.2", | ||
"@types/randomstring": "^1.1.6", | ||
"randomstring": "^1.1.5", | ||
"typed-error": "^2.0.0" | ||
"tslib": "^2.0.0", | ||
"typed-error": "^3.2.0" | ||
}, | ||
"peerDependencies": { | ||
"balena-request": "^10.0.0" | ||
"balena-request": "^11.0.0-11-x-0f67d2157ff70c8cfada7b6359ba4b58aeeacf3c" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29928
10
6
199
5
1
1
+ Added@types/randomstring@^1.1.6
+ Addedtslib@^2.0.0
+ Added@types/node@10.17.60(transitive)
+ Added@types/randomstring@1.3.0(transitive)
+ Addedbalena-auth@4.2.1(transitive)
+ Addedbalena-request@11.5.10(transitive)
+ Addedbalena-settings-storage@7.0.2(transitive)
+ Addedfetch-ponyfill@7.1.0(transitive)
+ Addednode-fetch@2.6.13(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removedbluebird@^3.7.2
- Removed@resin.io/types-node-localstorage@1.3.0(transitive)
- Removed@types/bluebird@3.5.42(transitive)
- Removed@types/node@8.10.66(transitive)
- Removedbalena-auth@3.1.1(transitive)
- Removedbalena-request@10.0.9(transitive)
- Removedbalena-settings-storage@5.0.2(transitive)
- Removedbluebird@3.7.2(transitive)
- Removedencoding@0.1.13(transitive)
- Removedfetch-ponyfill@4.1.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedimurmurhash@0.1.4(transitive)
- Removednode-fetch@1.7.3(transitive)
- Removednode-localstorage@1.3.1(transitive)
- Removedrindle@1.3.6(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedslide@1.1.6(transitive)
- Removedstring-to-stream@1.1.1(transitive)
- Removedtslib@1.14.1(transitive)
- Removedtyped-error@2.0.0(transitive)
- Removedwrite-file-atomic@1.3.4(transitive)
Updatedtyped-error@^3.2.0