{"version":3,"file":"supabaseClient.MHiMCva5.mjs","names":["createClient"],"sources":["https:/framerusercontent.com/modules/VV4kqZdRAZLcQlvFvmx2/NxklhxoDasiArC0E4cso/supabaseClient.js"],"sourcesContent":["// User request: production-minded Supabase integration layer and Framer components using SUPABASE_URL and SUPABASE_ANON_KEY only, no mock data.\n// Replaces the hand-built REST client with the official @supabase/supabase-js SDK.\n// Public API (function/type names) kept identical so nothing importing this file needs to change.\n// @ts-ignore\nimport{createClient}from\"@supabase/supabase-js\";export function getSafeAuthContinuationPath(input,fallback=\"/member-portal\"){const raw=String(input??\"\").trim();if(!raw)return fallback;if(/[\\u0000-\\u001F\\u007F\\\\]/.test(raw))return fallback;if(!raw.startsWith(\"/\"))return fallback;if(raw.startsWith(\"//\"))return fallback;const pathOnly=raw.split(/[?#]/)[0];if(pathOnly===\"/login\"||pathOnly===\"/auth/callback\")return fallback;return raw;}// --- Environment / client bootstrap ---------------------------------------\nconst SUPABASE_URL=\"https://kbxzmprxkjfsgiwtppgt.supabase.co\";const SUPABASE_ANON_KEY=\"sb_publishable_7E8ano9Pbw62wj8jvure_g_pbPQGEr9\";let client=null;function readEnvValue(name){const globalValue=globalThis?.[name];if(typeof globalValue===\"string\"&&globalValue.trim().length>0)return globalValue.trim();if(typeof process!==\"undefined\"&&typeof process?.env?.[name]===\"string\"&&process.env[name].trim().length>0){return process.env[name].trim();}return\"\";}export function getSupabaseEnvState(){const envUrl=readEnvValue(\"SUPABASE_URL\");const envAnonKey=readEnvValue(\"SUPABASE_ANON_KEY\");const url=envUrl||SUPABASE_URL.trim();const anonKey=envAnonKey||SUPABASE_ANON_KEY.trim();const missing=[];if(!url)missing.push(\"SUPABASE_URL\");if(!anonKey)missing.push(\"SUPABASE_ANON_KEY\");const isConfigured=missing.length===0;const configuredFromEnvironment=Boolean(envUrl&&envAnonKey);const message=isConfigured?configuredFromEnvironment?\"Supabase is configured from Framer environment variables.\":\"Supabase is configured using publishable fallback values.\":`Missing environment variables: ${missing.join(\", \")}`;return{url,anonKey,isConfigured,message};}// Same storage key convention as before, so any already-signed-in visitor's\n// session in localStorage carries over without forcing a re-login.\nfunction buildStorageKey(url){return`sb-session:${url.replace(/\\/+$/,\"\")}`;}export function getSupabaseClient(){if(client)return client;const env=getSupabaseEnvState();if(!env.isConfigured)return null;client=createClient(env.url,env.anonKey,{auth:{// The SDK handles token refresh, multi-tab sync, and persistence\n// automatically — this is the behavior the old hand-rolled\n// client was missing.\npersistSession:true,autoRefreshToken:true,detectSessionInUrl:true,storageKey:buildStorageKey(env.url)}});return client;}export function requireSupabaseClient(){const instance=getSupabaseClient();if(!instance){throw new Error(getSupabaseEnvState().message);}return instance;}// --- Generic table helpers --------------------------------------------------\nexport async function fetchRows(table,options={}){const supabase=requireSupabaseClient();const{select=\"*\",limit,orderBy,ascending=false,filters={}}=options;let query=supabase.from(table).select(select);Object.entries(filters).forEach(([key,value])=>{query=query.eq(key,value);});if(orderBy)query=query.order(orderBy,{ascending});if(typeof limit===\"number\")query=query.limit(limit);const{data,error}=await query;if(error)throw error;return data??[];}export async function fetchSingleRow(table,options={}){const rows=await fetchRows(table,{...options,limit:1});return rows[0]??null;}export async function upsertRows(table,rows){const supabase=requireSupabaseClient();const{data,error}=await supabase.from(table).upsert(rows).select();if(error)throw error;return data??[];}// --- Storage helpers ---------------------------------------------------------\nexport async function getPublicStorageUrl(bucket,path){const supabase=requireSupabaseClient();const{data}=supabase.storage.from(bucket).getPublicUrl(path);return data.publicUrl;}export async function getSignedStorageUrl(bucket,path,expiresIn=3600){const supabase=requireSupabaseClient();const{data,error}=await supabase.storage.from(bucket).createSignedUrl(path,expiresIn);if(error)throw error;return data?.signedUrl??\"\";}// --- Realtime ----------------------------------------------------------------\nexport function subscribeToTableChanges(options){const supabase=getSupabaseClient();if(!supabase){options.onError?.(new Error(getSupabaseEnvState().message));return()=>{};}const channelName=`table-changes:${options.schema??\"public\"}:${options.table}`;const channel=supabase.channel(channelName).on(\"postgres_changes\",{event:options.event??\"*\",schema:options.schema??\"public\",table:options.table,filter:options.filter},payload=>{try{options.onChange(payload);}catch{}}).subscribe(status=>{if(status===\"CHANNEL_ERROR\"||status===\"TIMED_OUT\"){options.onError?.(new Error(`Realtime subscription failed: ${status}`));}});return()=>{supabase.removeChannel(channel);};}// --- Connection / health probe -----------------------------------------------\nfunction isPermissionDeniedError(error){if(!error)return false;const status=typeof error.status===\"number\"?error.status:0;const code=String(error.code??\"\").toUpperCase();const message=String(error.message??\"\").toLowerCase();if(status===401||status===403)return true;if(code===\"42501\"||code.startsWith(\"PGRST\")){if(message.includes(\"permission\")||message.includes(\"not allowed\")||message.includes(\"row-level\")){return true;}}if(message.includes(\"permission denied\")||message.includes(\"not authorized\")||message.includes(\"row-level security\")){return true;}return false;}function toUnavailableReason(error){if(!error)return\"Unknown availability error.\";const message=String(error.message??\"\").trim();if(message)return message;return\"Supabase API unavailable.\";}export async function testSupabaseConnection(){const env=getSupabaseEnvState();const tablesToProbe=[\"profiles\",\"companies\",\"bcvm_assessments\",\"oei_readings\",\"research_reports\"];if(!env.isConfigured){return{overall:\"missing\",env,clientInitialized:false,authProbe:\"missing\",tables:tablesToProbe.map(table=>({table,state:\"missing\",reachable:false,reason:env.message})),message:env.message};}const supabase=getSupabaseClient();if(!supabase){return{overall:\"missing\",env,clientInitialized:false,authProbe:\"missing\",tables:tablesToProbe.map(table=>({table,state:\"missing\",reachable:false,reason:\"Supabase client could not be initialized from environment values.\"})),message:\"Supabase client could not be initialized from environment values.\"};}const{error:authError}=await supabase.auth.getSession();let authProbe=\"connected\";if(authError){authProbe=isPermissionDeniedError(authError)?\"permission-denied\":\"unavailable\";}const tables=[];for(const table of tablesToProbe){const{error}=await supabase.from(table).select(\"id\",{head:true,count:\"exact\"}).limit(1);if(!error){tables.push({table,state:\"connected\",reachable:true,reason:\"Read-only probe succeeded.\"});continue;}if(isPermissionDeniedError(error)){tables.push({table,state:\"permission-denied\",reachable:false,reason:toUnavailableReason(error)});continue;}tables.push({table,state:\"unavailable\",reachable:false,reason:toUnavailableReason(error)});}const hasUnavailable=authProbe===\"unavailable\"||tables.some(table=>table.state===\"unavailable\");const hasPermissionDenied=authProbe===\"permission-denied\"||tables.some(table=>table.state===\"permission-denied\");let overall=\"connected\";let message=\"Supabase connection and read-only probes succeeded.\";if(hasUnavailable){overall=\"unavailable\";message=\"Supabase appears unavailable for at least one read-only probe.\";}else if(hasPermissionDenied){overall=\"permission-denied\";message=\"Supabase reachable, but at least one probe was denied by permissions/RLS.\";}else if(authProbe===\"connected\"&&tables.every(table=>table.state===\"connected\")){overall=\"connected\";message=\"Supabase connection and read-only probes succeeded.\";}else{overall=\"configured\";message=\"Supabase is configured but probe results are partial.\";}return{overall,env,clientInitialized:true,authProbe,tables,message};}\nexport const __FramerMetadata__ = {\"exports\":{\"SupabaseProbeState\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"testSupabaseConnection\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"upsertRows\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getSafeAuthContinuationPath\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getPublicStorageUrl\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"RealtimeSubscriptionOptions\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"SupabaseTableProbeResult\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"fetchSingleRow\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getSignedStorageUrl\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"QueryOptions\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"fetchRows\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"SupabaseEnvState\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"subscribeToTableChanges\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"SupabaseConnectionTestResult\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"requireSupabaseClient\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"QueryFilters\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getSupabaseClient\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getSupabaseEnvState\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./supabaseClient.map"],"mappings":"mGAKuJ,SAAS,EAAa,EAAK,CAAC,IAAM,EAAY,aAAa,GAA2O,OAAlO,OAAO,GAAc,UAAU,EAAY,KAAK,CAAC,CAAC,OAAO,EAAS,EAAY,KAAK,EAAK,OAAO,QAAU,KAAa,OAAO,SAAS,MAAM,IAAQ,UAAU,QAAQ,IAAI,EAAK,CAAC,KAAK,CAAC,CAAC,OAAO,EAAU,QAAQ,IAAI,EAAK,CAAC,KAAK,EAAS,EAAG,CAAC,SAAgB,GAAqB,CAAC,IAAM,EAAO,EAAa,cAAc,EAAQ,EAAW,EAAa,mBAAmB,EAAQ,EAAI,GAAQ,EAAa,KAAK,EAAQ,EAAQ,GAAY,EAAkB,KAAK,EAAQ,EAAQ,CAAC,EAAM,GAAI,EAAQ,KAAK,cAAc,EAAM,GAAQ,EAAQ,KAAK,mBAAmB,EAAE,IAAM,EAAa,EAAQ,SAAS,EAAkS,MAAM,CAAC,MAAI,UAAQ,eAAa,QAAtP,EAAlC,GAAQ,EAAiE,4DAA4D,4DAA4D,kCAAkC,EAAQ,KAAK,IAAI,GAA2C,CAAE,CAEtnC,SAAS,EAAgB,EAAI,CAAC,MAAM,cAAc,EAAI,QAAQ,OAAO,EAAE,GAAI,CAAC,SAAgB,GAAmB,CAAC,GAAG,EAAO,OAAO,EAAO,IAAM,EAAI,EAAoB,EAG7D,OAHmE,EAAI,cAAyB,EAAOA,EAAa,EAAI,IAAI,EAAI,QAAQ,CAAC,KAAK,CAGvP,eAAe,GAAK,iBAAiB,GAAK,mBAAmB,GAAK,WAAW,EAAgB,EAAI,GAAG,CAAC,CAAC,CAAC,EAAS,GAHoF,IAG7E,uBANxE,EACzC,EAAa,2CAAiD,EAAkB,iDAAqD,EAAO"}