diff --git a/packages/common/dataCache/DistributedCache/client.ts b/packages/common/dataCache/DistributedCache/client.ts index 3488d825c..9897c5f90 100644 --- a/packages/common/dataCache/DistributedCache/client.ts +++ b/packages/common/dataCache/DistributedCache/client.ts @@ -1,4 +1,3 @@ -import { env } from "../../env/server" import { cacheOrGet } from "./cacheOrGet" import { deleteKey } from "./deleteKey" import { get } from "./get" @@ -6,7 +5,6 @@ import { set } from "./set" import type { DataCache } from "../Cache" -export const API_KEY = env.REDIS_API_KEY ?? "" export async function createDistributedCache(): Promise { return { type: "redis", diff --git a/packages/common/dataCache/DistributedCache/deleteKey.ts b/packages/common/dataCache/DistributedCache/deleteKey.ts index 8dd83f6e8..957a8b0b9 100644 --- a/packages/common/dataCache/DistributedCache/deleteKey.ts +++ b/packages/common/dataCache/DistributedCache/deleteKey.ts @@ -1,11 +1,11 @@ import * as Sentry from "@sentry/nextjs" -import { safeTry } from "@scandic-hotels/common/utils/safeTry" - +import { env } from "../../env/server" +import { safeTry } from "../../utils/safeTry" import { cacheLogger } from "../logger" -import { API_KEY } from "./client" import { getCacheEndpoint } from "./endpoints" +const API_KEY = env.REDIS_API_KEY ?? "" export async function deleteKey(key: string, opts?: { fuzzy?: boolean }) { const perf = performance.now() const endpoint = getCacheEndpoint(key) diff --git a/packages/common/dataCache/DistributedCache/get.ts b/packages/common/dataCache/DistributedCache/get.ts index 807164336..d0e4457ae 100644 --- a/packages/common/dataCache/DistributedCache/get.ts +++ b/packages/common/dataCache/DistributedCache/get.ts @@ -1,12 +1,12 @@ import * as Sentry from "@sentry/nextjs" -import { safeTry } from "@scandic-hotels/common/utils/safeTry" - +import { env } from "../../env/server" +import { safeTry } from "../../utils/safeTry" import { cacheLogger } from "../logger" -import { API_KEY } from "./client" import { deleteKey } from "./deleteKey" import { getCacheEndpoint } from "./endpoints" +const API_KEY = env.REDIS_API_KEY ?? "" export async function get(key: string) { const perf = performance.now() diff --git a/packages/common/dataCache/DistributedCache/set.ts b/packages/common/dataCache/DistributedCache/set.ts index bd1435f2b..0a63cbb9c 100644 --- a/packages/common/dataCache/DistributedCache/set.ts +++ b/packages/common/dataCache/DistributedCache/set.ts @@ -1,11 +1,11 @@ import * as Sentry from "@sentry/nextjs" -import { safeTry } from "@scandic-hotels/common/utils/safeTry" - +import { env } from "../../env/server" +import { safeTry } from "../../utils/safeTry" import { type CacheTime, getCacheTimeInSeconds } from "../Cache" -import { API_KEY } from "./client" import { getCacheEndpoint } from "./endpoints" +const API_KEY = env.REDIS_API_KEY ?? "" export async function set(key: string, value: T, ttl: CacheTime) { const [response, error] = await safeTry( fetch(getCacheEndpoint(key), { diff --git a/packages/common/env/server.ts b/packages/common/env/server.ts index eb5701113..3634eeb51 100644 --- a/packages/common/env/server.ts +++ b/packages/common/env/server.ts @@ -7,7 +7,7 @@ export const env = createEnv({ * and Netlify running Deno, window is never "undefined" * https://github.com/t3-oss/t3-env/issues/154 */ - isServer: true, + isServer: typeof window === "undefined" || "Deno" in window, server: { NODE_ENV: z.enum(["development", "test", "production"]), REDIS_API_HOST: z.string().optional(),