pulse-ai-utils
Version:
Utility functions and helpers for AI-powered applications
46 lines • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.supabase = void 0;
exports.getSupabaseClientSafe = getSupabaseClientSafe;
exports.getSupabaseClient = getSupabaseClient;
const supabase_js_1 = require("@supabase/supabase-js");
const supabaseUrl = 'https://joxggdztjaalkqdhshrz.supabase.co';
let supabaseInstance = null;
function getSupabaseClient() {
if (supabaseInstance) {
return supabaseInstance;
}
const supabaseKey = process.env.SUPABASE_SERVICE_ROLE_SECRET || process.env.SUPABASE_KEY;
if (!supabaseKey) {
throw new Error('SUPABASE_SERVICE_ROLE_SECRET or SUPABASE_KEY environment variable is required');
}
supabaseInstance = (0, supabase_js_1.createClient)(supabaseUrl, supabaseKey, {
auth: {
autoRefreshToken: false,
persistSession: false
}
});
return supabaseInstance;
}
// Safe getter for test environments
function getSupabaseClientSafe() {
try {
return getSupabaseClient();
}
catch (error) {
if (process.env.NODE_ENV === 'test' || !process.env.SUPABASE_KEY) {
return null;
}
throw error;
}
}
// Legacy export for backwards compatibility - lazy initialization
exports.supabase = new Proxy({}, {
get(target, prop) {
const client = getSupabaseClient();
return typeof client[prop] === 'function'
? client[prop].bind(client)
: client[prop];
}
});
//# sourceMappingURL=index.js.map