Files
web/apps/scandic-web/env/getLiveStatus.ts
Anton Gunnarsson 846fd904a6 Merged in feat/sw-2859-set-up-shared-trpc-package (pull request #2319)
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
2025-06-18 12:14:20 +00:00

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
}