feat(SW-2859): Create trpc package * Add isEdge, safeTry and dataCache to new common package * Add eslint and move prettier config * Clean up tests * Create trpc package and move initialization * Move errors and a few procedures * Move telemetry to common package * Move tokenManager to common package * Add Sentry to procedures * Clean up procedures * Fix self-referencing imports * Add exports to packages and lint rule to prevent relative imports * Add env to trpc package * Add eslint to trpc package * Apply lint rules * Use direct imports from trpc package * Add lint-staged config to trpc * Move lang enum to common * Restructure trpc package folder structure * Fix lang imports Approved-by: Linus Flood
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { Lang } from "@scandic-hotels/common/constants/language"
|
|
|
|
export function getLiveStatus(
|
|
internalEnv:
|
|
| {
|
|
NEW_SITE_LIVE_FOR_LANGS: string[]
|
|
}
|
|
| {
|
|
NEXT_PUBLIC_NEW_SITE_LIVE_FOR_LANGS: string[]
|
|
}
|
|
): "ALL_LANGUAGES_LIVE" | "SOME_LANGUAGES_LIVE" | "NOT_LIVE" {
|
|
const configuredLangs = getConfiguredLangs(internalEnv)
|
|
if (!configuredLangs) {
|
|
return "NOT_LIVE"
|
|
}
|
|
|
|
const allLangs = Object.keys(Lang)
|
|
const liveLangs = allLangs.filter((lang) => configuredLangs.includes(lang))
|
|
if (liveLangs.length === 0) {
|
|
return "NOT_LIVE"
|
|
}
|
|
|
|
if (
|
|
liveLangs.length === allLangs.length &&
|
|
allLangs.every((lang) => liveLangs.includes(lang))
|
|
) {
|
|
return "ALL_LANGUAGES_LIVE"
|
|
}
|
|
|
|
return "SOME_LANGUAGES_LIVE"
|
|
}
|
|
|
|
function getConfiguredLangs<T extends {}>(env: T): string[] | undefined {
|
|
if (
|
|
!(
|
|
"NEW_SITE_LIVE_FOR_LANGS" in env ||
|
|
"NEXT_PUBLIC_NEW_SITE_LIVE_FOR_LANGS" in env
|
|
)
|
|
) {
|
|
return undefined
|
|
}
|
|
|
|
const configuredLangs =
|
|
"NEW_SITE_LIVE_FOR_LANGS" in env
|
|
? env.NEW_SITE_LIVE_FOR_LANGS
|
|
: env.NEXT_PUBLIC_NEW_SITE_LIVE_FOR_LANGS
|
|
|
|
if (!Array.isArray(configuredLangs)) {
|
|
throw new Error("Misconfigured environment variable, expected array")
|
|
}
|
|
|
|
return configuredLangs
|
|
}
|