declare global { // oxlint-disable-next-line no-underscore-dangle -- established flag name var __SANITY_STAGING__: boolean | undefined; } /** * Returns the Sanity domain based on the `__SANITY_STAGING__` runtime-time flag. * If the flag is set to `true`, the staging domain is returned. * Otherwise, the production domain is returned. * * @public */ export function getSanityDomain(): string { if (getSanityEnv() === "staging") { return "sanity.work"; } return "sanity.io"; } /** * Returns the API host based on the `__SANITY_STAGING__` runtime-time flag. * If the flag is set to `true`, the staging API host is returned. * Otherwise, the production API host is returned. * * @public */ export function getApiHost(): string | undefined { return `https://api.${getSanityDomain()}`; } /** * Returns the domain brett applications are served from — an application * deployed through the new `/applications` API lives at `-apps-`, * a different URL from the legacy studio domain. * * @public */ export function getApplicationDomain(): string { return getSanityEnv() === "production" ? "sanity.run" : "run.sanity.work"; } /** * Returns the current Sanity environment based on the `__SANITY_STAGING__` runtime-time flag. * If the flag is set to `true`, "staging" is returned. * Otherwise, "production" is returned. * * @public */ export function getSanityEnv(): "staging" | "production" { // Read via globalThis on purpose: bundler `define` inlines a bare // `__SANITY_STAGING__`, locking chunks to the env they were built in // rather than the one the host page runs in. // oxlint-disable-next-line no-underscore-dangle -- established flag name return globalThis.__SANITY_STAGING__ === true ? "staging" : "production"; }