import { createClient } from '@supabase/supabase-js'
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY
if (!supabaseUrl || !supabaseAnonKey) {
throw new Error('Missing Supabase environment variables')
}
export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
auth: {
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: true
},
realtime: {
params: {
eventsPerSecond: 10
}
}
})
// Database types (you can generate these from Supabase)
export interface Database {
public: {
Tables: {
profiles: {
Row: {
id: string
email: string | null
full_name: string | null
avatar_url: string | null
role: 'user' | 'admin' | 'agent'
tenant_id: string | null
created_at: string
updated_at: string
}
Insert: {
id: string
email?: string | null
full_name?: string | null
avatar_url?: string | null
role?: 'user' | 'admin' | 'agent'
tenant_id?: string | null
created_at?: string
updated_at?: string
}
Update: {
id?: string
email?: string | null
full_name?: string | null
avatar_url?: string | null
role?: 'user' | 'admin' | 'agent'
tenant_id?: string | null
created_at?: string
updated_at?: string
}
}
tenants: {
Row: {
id: string
name: string
domain: string | null
settings: any
created_at: string
updated_at: string
}
Insert: {
id?: string
name: string
domain?: string | null
settings?: any
created_at?: string
updated_at?: string
}
Update: {
id?: string
name?: string
domain?: string | null
settings?: any
created_at?: string
updated_at?: string
}
}
chat_messages: {
Row: {
id: string
user_id: string | null
tenant_id: string | null
message: string
response: string | null
context: any
message_type: 'text' | 'file' | 'image'
status: 'sent' | 'delivered' | 'read'
created_at: string
}
Insert: {
id?: string
user_id?: string | null
tenant_id?: string | null
message: string
response?: string | null
context?: any
message_type?: 'text' | 'file' | 'image'
status?: 'sent' | 'delivered' | 'read'
created_at?: string
}
Update: {
id?: string
user_id?: string | null
tenant_id?: string | null
message?: string
response?: string | null
context?: any
message_type?: 'text' | 'file' | 'image'
status?: 'sent' | 'delivered' | 'read'
created_at?: string
}
}
knowledge_base: {
Row: {
id: string
tenant_id: string | null
title: string
content: string
category: string | null
tags: string[] | null
created_at: string
updated_at: string
}
Insert: {
id?: string
tenant_id?: string | null
title: string
content: string
category?: string | null
tags?: string[] | null
created_at?: string
updated_at?: string
}
Update: {
id?: string
tenant_id?: string | null
title?: string
content?: string
category?: string | null
tags?: string[] | null
created_at?: string
updated_at?: string
}
}
}
}
}
export type Tables<T extends keyof Database['public']['Tables']> = Database['public']['Tables'][T]['Row']
export type InsertDto<T extends keyof Database['public']['Tables']> = Database['public']['Tables'][T]['Insert']
export type UpdateDto<T extends keyof Database['public']['Tables']> = Database['public']['Tables'][T]['Update']