UNPKG

alwaysai

Version:

The alwaysAI command-line interface (CLI)

60 lines 2.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addDeviceToProject = void 0; const alwayscli_1 = require("@alwaysai/alwayscli"); const constants_1 = require("../../constants"); const infrastructure_1 = require("../../infrastructure"); const util_1 = require("../../util"); const check_for_project_id_1 = require("./check-for-project-id"); async function checkDeviceLimit(deviceMode, project) { const teamLimits = await (0, infrastructure_1.CliRpcClient)().checkTeamLimits({ team_id: project.team_id }); if (!teamLimits.enforce_limits) { return; } let deviceLimits; switch (deviceMode) { case 'development': { deviceLimits = teamLimits.dev_devices; break; } case 'production': { deviceLimits = teamLimits.prod_devices; break; } default: util_1.logger.error(`Invalid device mode (${deviceMode}).`); throw new alwayscli_1.CliTerseError(`Invalid device mode (${deviceMode}). ${constants_1.PLEASE_REPORT_THIS_ERROR_MESSAGE}`); } const devicesUsed = deviceLimits.used; const devicesLimit = deviceLimits.limit; if (devicesLimit !== null && devicesUsed >= devicesLimit) { throw new alwayscli_1.CliTerseError(`You've reached your limit of ${deviceMode} devices for this project. Please upgrade to continue: ${await (0, check_for_project_id_1.getUpgradeUrl)()}`); } } async function addDeviceToProject(props) { const { device, projectId } = props; const client = (0, infrastructure_1.CliRpcClient)(); const project = await client.getProjectByUUID({ uuid: projectId }); const projectDevices = await client.getProjectDevices({ project_id: project.id }); let deviceInProject = false; for (const d of projectDevices) { if (d.id === device.id) { deviceInProject = true; break; } } if (deviceInProject === true) { return; } await checkDeviceLimit(device.mode, project); await client.addProjectDevice({ device_id: device.id, project_id: project.id }); } exports.addDeviceToProject = addDeviceToProject; //# sourceMappingURL=add-device-to-project.js.map