-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathedge_functions.py
More file actions
147 lines (119 loc) · 5.67 KB
/
edge_functions.py
File metadata and controls
147 lines (119 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from typing import Any, Dict, List, Optional
from ._service import SupabaseService
class SupabaseEdgeFunctionsService(SupabaseService):
"""
Service for interacting with Supabase Edge Functions.
This class provides methods for invoking Edge Functions deployed to Supabase.
Note: Creating, listing, and deleting functions requires the Supabase CLI or Dashboard.
"""
def invoke_function(self,
function_name: str,
invoke_method: str = "POST",
body: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, str]] = None,
auth_token: Optional[str] = None,
is_admin: bool = False) -> Any:
"""
Invoke a Supabase Edge Function.
Args:
function_name: Name of the function to invoke
invoke_method: HTTP method to use (GET, POST, etc.)
body: Optional request body
headers: Optional additional headers
auth_token: Optional JWT token for authenticated requests
is_admin: Whether to use admin privileges
Returns:
Function response
"""
endpoint = f"/functions/v1/{function_name}"
# Get default headers and merge with any additional headers
request_headers = self._get_headers(auth_token, is_admin)
if headers:
request_headers.update(headers)
return self._make_request(
method=invoke_method,
endpoint=endpoint,
auth_token=auth_token,
is_admin=is_admin,
data=body,
headers=request_headers
)
# Note: The following methods are placeholders that would normally require the Supabase Management API
# For testing purposes, we'll mock these in the tests
def list_functions(self) -> List[Dict[str, Any]]:
"""
List all Edge Functions in the Supabase project.
Note: This operation requires access to the Supabase Management API,
which is not available through the standard API keys.
In a real-world scenario, you would use the Supabase CLI or Dashboard.
Returns:
List of edge functions
"""
# For testing purposes, we'll return a mock response
return []
def create_function(self,
name: str,
source_code: str,
verify_jwt: bool = True,
import_map: Optional[Dict[str, str]] = None) -> Dict[str, Any]:
"""
Create a new Edge Function in the Supabase project.
Note: This operation requires access to the Supabase Management API,
which is not available through the standard API keys.
In a real-world scenario, you would use the Supabase CLI or Dashboard.
Args:
name: Name of the function to create
source_code: JavaScript/TypeScript source code for the function
verify_jwt: Whether to verify JWT tokens in requests to this function
import_map: Optional import map for dependencies
Returns:
Created function details
"""
# For testing purposes, we'll return a mock response
return {"name": name, "status": "MOCK_CREATED"}
def delete_function(self, function_name: str) -> Dict[str, Any]:
"""
Delete an Edge Function from the Supabase project.
Note: This operation requires access to the Supabase Management API,
which is not available through the standard API keys.
In a real-world scenario, you would use the Supabase CLI or Dashboard.
Args:
function_name: Name of the function to delete
Returns:
Response confirming deletion
"""
# For testing purposes, we'll return a mock response
return {"name": function_name, "status": "MOCK_DELETED"}
def get_function(self, function_name: str) -> Dict[str, Any]:
"""
Get details of a specific Edge Function.
Note: This operation requires access to the Supabase Management API,
which is not available through the standard API keys.
In a real-world scenario, you would use the Supabase CLI or Dashboard.
Args:
function_name: Name of the function to get
Returns:
Function details
"""
# For testing purposes, we'll return a mock response
return {"name": function_name, "status": "MOCK_ACTIVE"}
def update_function(self,
function_name: str,
source_code: Optional[str] = None,
verify_jwt: Optional[bool] = None,
import_map: Optional[Dict[str, str]] = None) -> Dict[str, Any]:
"""
Update an existing Edge Function.
Note: This operation requires access to the Supabase Management API,
which is not available through the standard API keys.
In a real-world scenario, you would use the Supabase CLI or Dashboard.
Args:
function_name: Name of the function to update
source_code: Optional new JavaScript/TypeScript source code
verify_jwt: Optional setting to verify JWT tokens
import_map: Optional import map for dependencies
Returns:
Updated function details
"""
# For testing purposes, we'll return a mock response
return {"name": function_name, "status": "MOCK_UPDATED"}