UNPKG

balena-cli

Version:

The official balena Command Line Interface

39 lines 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDeviceAndMaybeAppFromUUID = exports.getDeviceAndAppFromUUID = exports.serviceIdToName = void 0; const _ = require("lodash"); const lazy_1 = require("./lazy"); const errors_1 = require("../errors"); exports.serviceIdToName = _.memoize(async (sdk, serviceId) => { const serviceName = await sdk.pine.get({ resource: 'service', id: serviceId, options: { $select: 'service_name', }, }); if (serviceName != null) { return serviceName.service_name; } return; }, (_sdk, id) => id.toString()); const deviceOptions = { $select: ['id', 'uuid'], $expand: { belongs_to__application: { $select: ['slug'] } }, }; exports.getDeviceAndAppFromUUID = _.memoize(async (deviceUUID) => { const [device, app] = await (0, exports.getDeviceAndMaybeAppFromUUID)(deviceUUID); if (app == null) { throw new errors_1.ExpectedError((0, lazy_1.stripIndent) ` Unable to access the fleet that device ${deviceUUID} belongs to. Hint: check whether the fleet owner withdrew access to it. `); } return [device, app]; }); exports.getDeviceAndMaybeAppFromUUID = _.memoize(async (deviceUUID) => { const { getDevice } = await Promise.resolve().then(() => require('./sdk')); const device = await getDevice(deviceUUID, deviceOptions); return [device, device.belongs_to__application[0]]; }); //# sourceMappingURL=cloud.js.map