latest
This commit is contained in:
@@ -14,14 +14,13 @@ class CreateBucketOptions(TypedDict, total=False):
|
||||
allowed_mime_types: List[str]
|
||||
name: str
|
||||
|
||||
def _create_base_client(url: str, key: str, options: Optional[Dict[str, Any]] = None, access_token: Optional[str] = None) -> Client:
|
||||
def _create_base_client(url: str, key: str, options: Optional[Dict[str, Any]] = None) -> Client:
|
||||
"""Create a base Supabase client with given configuration."""
|
||||
client_options = SyncClientOptions(
|
||||
schema="public",
|
||||
storage=SyncMemoryStorage(),
|
||||
headers={
|
||||
"apikey": key,
|
||||
"Authorization": f"Bearer {access_token if access_token else key}"
|
||||
"Authorization": f"Bearer {key}"
|
||||
}
|
||||
)
|
||||
return create_client(url, key, options=client_options)
|
||||
@@ -29,16 +28,16 @@ def _create_base_client(url: str, key: str, options: Optional[Dict[str, Any]] =
|
||||
class SupabaseServiceRoleClient:
|
||||
"""Supabase client for making authenticated requests using the service role key"""
|
||||
|
||||
def __init__(self, url: Optional[str] = None, service_role_key: Optional[str] = None, access_token: Optional[str] = None):
|
||||
def __init__(self, url: Optional[str] = None, service_role_key: Optional[str] = None):
|
||||
"""Initialize the Supabase client with URL and service role key"""
|
||||
self.url = url or os.environ.get("SUPABASE_URL", "http://kong:8000")
|
||||
self.url = url or os.environ.get("SUPABASE_URL", "http://localhost:8000")
|
||||
self.service_role_key = service_role_key or os.environ.get("SERVICE_ROLE_KEY")
|
||||
|
||||
if not self.url or not self.service_role_key:
|
||||
raise ValueError("SUPABASE_URL and SERVICE_ROLE_KEY must be provided")
|
||||
|
||||
# Initialize Supabase client with service role key and optional access token
|
||||
self.supabase = _create_base_client(self.url, self.service_role_key, access_token=access_token)
|
||||
self.supabase = _create_base_client(self.url, self.service_role_key)
|
||||
|
||||
def create_bucket(self, id: str, options: Optional[CreateBucketOptions] = None) -> Dict[str, Any]:
|
||||
"""Create a storage bucket with the given ID and options"""
|
||||
@@ -48,17 +47,12 @@ class SupabaseServiceRoleClient:
|
||||
options['name'] = id # Use ID as default name if not provided
|
||||
return self.supabase.storage.create_bucket(id, options=options)
|
||||
|
||||
@classmethod
|
||||
def for_admin(cls, access_token: str) -> 'SupabaseServiceRoleClient':
|
||||
"""Create a client instance for the super admin using their access token"""
|
||||
return cls(access_token=access_token)
|
||||
|
||||
class SupabaseAnonClient:
|
||||
"""Supabase client for making authenticated requests using the anon key"""
|
||||
|
||||
def __init__(self, url: Optional[str] = None, anon_key: Optional[str] = None, access_token: Optional[str] = None):
|
||||
"""Initialize the Supabase client with URL and anon key"""
|
||||
self.url = url or os.environ.get("SUPABASE_URL", "http://kong:8000")
|
||||
self.url = url or os.environ.get("SUPABASE_URL", "http://localhost:8000")
|
||||
self.anon_key = anon_key or os.environ.get("ANON_KEY")
|
||||
|
||||
if not self.url or not self.anon_key:
|
||||
|
||||
Reference in New Issue
Block a user