From 2eea9bc76be5616c6d674595cc7e227e14936e57 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Mon, 3 Nov 2025 22:26:08 +0000 Subject: [PATCH] Fix Supabase client proxy --- src/lib/supabaseClient.ts | 120 ++------------------------------------ 1 file changed, 5 insertions(+), 115 deletions(-) diff --git a/src/lib/supabaseClient.ts b/src/lib/supabaseClient.ts index 527ed7b3..5f41aeb9 100644 --- a/src/lib/supabaseClient.ts +++ b/src/lib/supabaseClient.ts @@ -1,118 +1,8 @@ /** - * Enhanced Supabase Client with Automatic Breadcrumb Tracking - * Wraps the standard Supabase client to add automatic API call tracking + * Central Supabase Client Export + * + * All application code should import from this file instead of the base client. + * This provides a central point for potential future enhancements without breaking imports. */ -import { supabase as baseSupabase } from '@/integrations/supabase/client'; -import { breadcrumb } from './errorBreadcrumbs'; - -// Create a proxy that tracks API calls -export const supabase = new Proxy(baseSupabase, { - get(target, prop) { - const value = target[prop as keyof typeof target]; - - // Track database operations - if (prop === 'from') { - return (table: string) => { - const query = (target as any).from(table); - - // Wrap query methods to track breadcrumbs - return new Proxy(query, { - get(queryTarget, queryProp) { - const queryValue = queryTarget[queryProp as string]; - - if (typeof queryValue === 'function') { - return async (...args: any[]) => { - const method = String(queryProp).toUpperCase(); - breadcrumb.apiCall(`/table/${table}`, method); - - try { - const result = await queryValue.apply(queryTarget, args); - - if (result.error) { - breadcrumb.apiCall(`/table/${table}`, method, 400); - } - - return result; - } catch (error) { - breadcrumb.apiCall(`/table/${table}`, method, 500); - throw error; - } - }; - } - - return queryValue; - }, - }); - }; - } - - // Track RPC calls - if (prop === 'rpc') { - return async (functionName: string, params?: any) => { - breadcrumb.apiCall(`/rpc/${functionName}`, 'RPC'); - - try { - const result = await (target as any).rpc(functionName, params); - - if (result.error) { - breadcrumb.apiCall(`/rpc/${functionName}`, 'RPC', 400); - } - - return result; - } catch (error) { - breadcrumb.apiCall(`/rpc/${functionName}`, 'RPC', 500); - throw error; - } - }; - } - - // Track storage operations - if (prop === 'storage') { - const storage = (target as any).storage; - - return new Proxy(storage, { - get(storageTarget, storageProp) { - const storageValue = storageTarget[storageProp]; - - if (storageProp === 'from') { - return (bucket: string) => { - const bucketOps = storageValue.call(storageTarget, bucket); - - return new Proxy(bucketOps, { - get(bucketTarget, bucketProp) { - const bucketValue = bucketTarget[bucketProp as string]; - - if (typeof bucketValue === 'function') { - return async (...args: any[]) => { - breadcrumb.apiCall(`/storage/${bucket}`, String(bucketProp).toUpperCase()); - - try { - const result = await bucketValue.apply(bucketTarget, args); - - if (result.error) { - breadcrumb.apiCall(`/storage/${bucket}`, String(bucketProp).toUpperCase(), 400); - } - - return result; - } catch (error) { - breadcrumb.apiCall(`/storage/${bucket}`, String(bucketProp).toUpperCase(), 500); - throw error; - } - }; - } - - return bucketValue; - }, - }); - }; - } - - return storageValue; - }, - }); - } - - return value; - }, -}); +export { supabase } from '@/integrations/supabase/client';