import { createClient } from '@supabase/supabase-js';
const SUPABASE_URL = 'https://supabase.optihost.pro';
const SUPABASE_ANON_KEY = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBhYmFzZSIsImlhdCI6MTc2MTUwNDEyMCwiZXhwIjo0OTE3MTc3NzIwLCJyb2xlIjoiYW5vbiJ9.C4vBY34QJYZatdT-H0W7yJGJMuf6lqIdzAypystFsPo';
const SUPABASE_SERVICE_KEY = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBhYmFzZSIsImlhdCI6MTc2MTUwNDEyMCwiZXhwIjo0OTE3MTc3NzIwLCJyb2xlIjoic2VydmljZV9yb2xlIn0.5ZmcIfyFQhA6SxjGIcWetGId951s2Wih5qvonr6Kthk';
export class SupabaseManager {
anonClient;
serviceClient;
constructor() {
this.anonClient = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
this.serviceClient = createClient(SUPABASE_URL, SUPABASE_SERVICE_KEY, {
auth: {
autoRefreshToken: false,
persistSession: false
}
});
}
/**
* Get the anonymous client for regular operations
*/
getAnonClient() {
return this.anonClient;
}
/**
* Get the service client for admin operations (seeding, etc.)
*/
getServiceClient() {
return this.serviceClient;
}
/**
* Test database connection
*/
async testConnection() {
try {
const { data, error } = await this.anonClient
.from('profiles')
.select('count', { count: 'exact', head: true });
if (error) {
console.error('Connection test failed:', error);
return false;
}
console.log('✅ Database connection successful');
return true;
}
catch (error) {
console.error('Connection test error:', error);
return false;
}
}
/**
* Check if required tables exist
*/
async checkTables() {
const requiredTables = [
'design_styles',
'design_palettes',
'style_palette_compatibility'
];
const exists = [];
const missing = [];
for (const table of requiredTables) {
try {
const { error } = await this.anonClient
.from(table)
.select('count', { count: 'exact', head: true });
if (error) {
missing.push(table);
}
else {
exists.push(table);
}
}
catch {
missing.push(table);
}
}
return { exists, missing };
}
/**
* Log an operation with timestamp
*/
log(message, level = 'info') {
const timestamp = new Date().toISOString();
const prefix = level === 'error' ? '❌' : level === 'warn' ? '⚠️' : '🔵';
console.log(`${prefix} [${timestamp}] ${message}`);
}
}
// Singleton instance
export const supabase = new SupabaseManager();
//# sourceMappingURL=client.js.map