balena-sdk
Version:
The Balena JavaScript SDK
47 lines (46 loc) • 1.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLocalModeSupport = exports.checkLocalModeSupported = exports.LOCAL_MODE_SUPPORT_PROPERTIES = exports.LOCAL_MODE_ENV_VAR = void 0;
const tslib_1 = require("tslib");
const bSemver = tslib_1.__importStar(require("balena-semver"));
const device_1 = require("./device");
const LOCAL_MODE_MIN_OS_VER = '2.0.0';
const LOCAL_MODE_MIN_SUPERVISOR_VER = '4.0.0';
exports.LOCAL_MODE_ENV_VAR = 'RESIN_SUPERVISOR_LOCAL_MODE';
exports.LOCAL_MODE_SUPPORT_PROPERTIES = [
'os_version',
'os_variant',
'supervisor_version',
'last_connectivity_event',
];
const checkLocalModeSupported = (device) => {
if (!(0, device_1.isProvisioned)(device)) {
throw new Error('Device is not yet fully provisioned');
}
if (!bSemver.gte(device.os_version, LOCAL_MODE_MIN_OS_VER)) {
throw new Error('Device OS version does not support local mode');
}
if (!bSemver.gte(device.supervisor_version, LOCAL_MODE_MIN_SUPERVISOR_VER)) {
throw new Error('Device supervisor version does not support local mode');
}
if (device.os_variant !== 'dev') {
throw new Error('Local mode is only supported on development OS versions');
}
};
exports.checkLocalModeSupported = checkLocalModeSupported;
const getLocalModeSupport = (device) => {
try {
(0, exports.checkLocalModeSupported)(device);
return {
supported: true,
message: 'Supported',
};
}
catch (err) {
return {
supported: false,
message: err.message,
};
}
};
exports.getLocalModeSupport = getLocalModeSupport;