UNPKG

@supernovaio/cli

Version:

Supernova.io Command Line Interface

91 lines (89 loc) 3.69 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]="1536bd5e-2aef-5be8-912f-5323cc42f80b")}catch(e){}}(); import { z } from "zod"; const allTargetEnvs = ["demo", "development", "local", "production", "staging"]; export const TargetEnv = z.enum(allTargetEnvs); const DevTargetEnvAlias = z.enum(["dev", "develop"]); const StagingTargetEnvAlias = z.enum(["stg"]); const defaultTargetEnv = "production"; export function getTargetEnv() { if (process.env.SUPERNOVA_ENV) { const raw = process.env.SUPERNOVA_ENV.toLowerCase(); const baseParseResult = TargetEnv.safeParse(raw); if (baseParseResult.success) return baseParseResult.data; const devAliasParseResult = DevTargetEnvAlias.safeParse(raw); if (devAliasParseResult.success) return "development"; const stgAliasParseResult = StagingTargetEnvAlias.safeParse(raw); if (stgAliasParseResult.success) return "staging"; console.warn(`Incorrect value of SUPERNOVA_ENV variable, allowed options are: [${allTargetEnvs.join(",")}] `); console.warn(`Using defaut env instead (${defaultTargetEnv})`); } return defaultTargetEnv; } const authServerUrlMap = { demo: "https://auth.demo.supernova.io/api/plugin-oauth", development: "https://auth.dev.supernova.io/api/plugin-oauth", local: `https://auth.dev.supernova.io/api/plugin-oauth`, production: "https://auth.supernova.io/api/plugin-oauth", staging: "https://auth.staging.supernova.io/api/plugin-oauth", }; export function authUrlForEnvironment(env) { return authServerUrlMap[env]; } export function storybookUrlForEnvironment(env) { switch (env) { case "demo": return "https://storybook.demo.sst.supernova.io"; case "development": return "https://storybook.dev.supernova.io"; case "local": return `https://storybook.${getLocalStageName()}.sst.supernova.io`; case "production": return "https://storybook.supernova.io"; case "staging": return "https://storybook.staging.supernova.io"; } } export function appUrlForEnvironment(env) { switch (env) { case "local": case "demo": case "development": return "https://app.dev.supernova.io"; case "production": return "https://app.supernova.io"; case "staging": return "https://app.staging.supernova.io"; } } export function apiUrlForEnvironment(env, version = "v2") { let url = (() => { switch (env) { case "demo": return "https://api.demo.supernova.io"; case "development": return "https://api.dev.supernova.io"; case "local": return `https://api-5.${getLocalStageName()}.sst.supernova.io`; case "production": return "https://api.supernova.io"; case "staging": return "https://api.staging.supernova.io"; } })(); if (version) { url += `/api/${version}`; } return url; } function getLocalStageName() { const parseResult = z.string().safeParse(process.env.SUPERNOVA_STAGE_NAME); if (!parseResult.success) { throw new Error(`To use local environment, SUPERNOVA_STAGE_NAME variable must be set`); } return parseResult.data; } //# sourceMappingURL=environment.js.map //# debugId=1536bd5e-2aef-5be8-912f-5323cc42f80b