hAPI_face2 / src /supabase.ts
deploy's picture
Deploy hAPI-face2 mediator 2025-10-07T05:24:34Z
5816640
raw
history blame contribute delete
938 Bytes
import { createClient, SupabaseClient } from '@supabase/supabase-js';
const { SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY } = process.env;
if (!SUPABASE_URL) {
throw new Error('SUPABASE_URL is required');
}
if (!SUPABASE_SERVICE_ROLE_KEY) {
throw new Error('SUPABASE_SERVICE_ROLE_KEY is required');
}
export const supabase: SupabaseClient = createClient(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, {
auth: {
autoRefreshToken: false,
persistSession: false,
},
global: {
headers: {
'X-Client-Info': 'hAPI-face2/1.0.0',
},
},
});
export function tableMissing(error: unknown): boolean {
if (!error || typeof error !== 'object') return false;
if ('code' in error && typeof error.code === 'string') {
return error.code === '42P01'; // Postgres undefined table
}
if ('message' in error && typeof error.message === 'string') {
return error.message.includes('does not exist');
}
return false;
}