From 7a278c4c3b5bc1409a074a6675ae7e83f1b35901 Mon Sep 17 00:00:00 2001 From: Thomas Cristina de Carvalho Date: Sat, 3 Feb 2024 16:15:32 -0500 Subject: [PATCH] Fix type --- app/lib/env.server.ts | 4 +--- app/lib/sanity/sanity.server.ts | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/lib/env.server.ts b/app/lib/env.server.ts index e66920d..d254488 100644 --- a/app/lib/env.server.ts +++ b/app/lib/env.server.ts @@ -4,13 +4,11 @@ */ export function envVariables(contextEnv: Env) { - let env: Env | NodeJS.ProcessEnv; + let env: Env | NodeJS.ProcessEnv = contextEnv; if (typeof process !== 'undefined') { // Process is accessible in Vercel environment env = process.env; - } else { - env = contextEnv; } return { diff --git a/app/lib/sanity/sanity.server.ts b/app/lib/sanity/sanity.server.ts index a6be6ae..b354d5b 100644 --- a/app/lib/sanity/sanity.server.ts +++ b/app/lib/sanity/sanity.server.ts @@ -16,12 +16,12 @@ import {loadQuery, queryStore} from './sanity.loader'; type CreateSanityClientOptions = { cache: Cache; config: { - apiVersion: string; - dataset: string; - projectId: string; - studioUrl: string; - useCdn: boolean; - useStega: string; + apiVersion: string | undefined; + dataset: string | undefined; + projectId: string | undefined; + studioUrl: string | undefined; + useCdn: boolean | undefined; + useStega: string | undefined; }; waitUntil: ExecutionContext['waitUntil']; }; @@ -52,6 +52,17 @@ export function createSanityClient(options: CreateSanityClientOptions) { const {cache, config, waitUntil} = options; const {apiVersion, dataset, projectId, studioUrl, useCdn, useStega} = config; + if ( + typeof projectId === 'undefined' || + typeof apiVersion === 'undefined' || + typeof dataset === 'undefined' || + typeof studioUrl === 'undefined' || + typeof useCdn === 'undefined' || + typeof useStega === 'undefined' + ) { + throw new Error('Missing required configuration for Sanity client'); + } + const {client} = getSanityClient({ apiVersion, dataset,