UNPKG

@supernovaio/cli

Version:

Supernova.io Command Line Interface

60 lines (58 loc) 3.02 kB
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8ba58cb6-ba43-5821-b8d7-54098b616808")}catch(e){}}(); import { createRequire } from "node:module"; import { HttpsProxyAgent } from "https-proxy-agent"; import { apiUrlForEnvironment, getTargetEnv } from "../types/environment.js"; const require = createRequire(import.meta.url); const sdkProvider = require("@supernovaio/sdk"); export async function getWritableVersion(flags) { if (!flags.apiKey || flags.apiKey.length === 0) { throw new Error(`API key must not be empty`); } if (!flags.designSystemId || flags.designSystemId.length === 0) { throw new Error(`Design System ID must not be empty`); } const apiUrl = flags.apiUrl && flags.apiUrl.length > 0 ? flags.apiUrl : apiUrlForEnvironment(getTargetEnv()); const instance = new sdkProvider.Supernova(flags.apiKey, { apiUrl, customProxyLib: flags.proxyUrl ? new HttpsProxyAgent(flags.proxyUrl) : null, }); const designSystem = await instance.designSystems.designSystem(flags.designSystemId); if (!designSystem) { throw new Error(`Design system ${flags.designSystemId} not found or not available under provided API key`); } const version = await instance.versions.getActiveVersion(flags.designSystemId); if (!version) { throw new Error(`Design system ${flags.designSystemId} writable version not found or not available under provided API key`); } const id = { designSystemId: flags.designSystemId, versionId: version.id, workspaceId: designSystem.workspaceId, }; let brand = null; if (flags.brandId) { const brands = await instance.brands.getBrands(id); brand = brands.find(brand => brand.id === flags.brandId || brand.idInVersion === flags.brandId) ?? null; if (!brand) { throw new Error(`Brand ${flags.brandId} not found in specified design system`); } } let themes = []; if (flags.themeId && flags.themeId.length > 0) { const availableThemes = await instance.tokens.getTokenThemes(id); const scopedThemes = brand ? availableThemes.filter(theme => theme.brandId === brand.id || theme.brandId === brand.idInVersion) : availableThemes; const scope = brand ? "specified brand" : "specified design system"; themes = flags.themeId.map(themeId => { const theme = scopedThemes.find(theme => theme.id === themeId || theme.idInVersion === themeId); if (!theme) { throw new Error(`Theme ${themeId} not found in ${scope}`); } return theme; }); } return { brand, designSystem, id, instance, themes, version }; } //# sourceMappingURL=sdk.js.map //# debugId=8ba58cb6-ba43-5821-b8d7-54098b616808