supabase_functions 2.30.1__tar.gz → 2.32.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {supabase_functions-2.30.1 → supabase_functions-2.32.0}/PKG-INFO +1 -1
- {supabase_functions-2.30.1 → supabase_functions-2.32.0}/pyproject.toml +1 -1
- {supabase_functions-2.30.1 → supabase_functions-2.32.0}/src/supabase_functions/_async/functions_client.py +27 -16
- {supabase_functions-2.30.1 → supabase_functions-2.32.0}/src/supabase_functions/_sync/functions_client.py +27 -16
- {supabase_functions-2.30.1 → supabase_functions-2.32.0}/src/supabase_functions/errors.py +19 -1
- supabase_functions-2.32.0/src/supabase_functions/version.py +1 -0
- supabase_functions-2.30.1/src/supabase_functions/version.py +0 -1
- {supabase_functions-2.30.1 → supabase_functions-2.32.0}/README.md +0 -0
- {supabase_functions-2.30.1 → supabase_functions-2.32.0}/src/supabase_functions/__init__.py +0 -0
- {supabase_functions-2.30.1 → supabase_functions-2.32.0}/src/supabase_functions/_async/__init__.py +0 -0
- {supabase_functions-2.30.1 → supabase_functions-2.32.0}/src/supabase_functions/_sync/__init__.py +0 -0
- {supabase_functions-2.30.1 → supabase_functions-2.32.0}/src/supabase_functions/py.typed +0 -0
- {supabase_functions-2.30.1 → supabase_functions-2.32.0}/src/supabase_functions/utils.py +0 -0
|
@@ -6,7 +6,7 @@ from warnings import warn
|
|
|
6
6
|
from httpx import AsyncClient, HTTPError, QueryParams, Response
|
|
7
7
|
from yarl import URL
|
|
8
8
|
|
|
9
|
-
from ..errors import FunctionsHttpError, FunctionsRelayError
|
|
9
|
+
from ..errors import FunctionsHttpError, FunctionsRelayError, _error_message_from
|
|
10
10
|
from ..utils import (
|
|
11
11
|
FunctionRegion,
|
|
12
12
|
is_http_url,
|
|
@@ -14,6 +14,8 @@ from ..utils import (
|
|
|
14
14
|
)
|
|
15
15
|
from ..version import __version__
|
|
16
16
|
|
|
17
|
+
HTTPMethod = Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"]
|
|
18
|
+
|
|
17
19
|
|
|
18
20
|
class AsyncFunctionsClient:
|
|
19
21
|
def __init__(
|
|
@@ -29,11 +31,13 @@ class AsyncFunctionsClient:
|
|
|
29
31
|
raise ValueError("url must be a valid HTTP URL string")
|
|
30
32
|
self.url = URL(url)
|
|
31
33
|
self.headers = {
|
|
32
|
-
"X-Client-Info":
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
"X-Client-Info": (
|
|
35
|
+
f"supabase-py/supabase_functions v{__version__}"
|
|
36
|
+
f"; platform={platform.system()}"
|
|
37
|
+
f"; platform-version={platform.release()}"
|
|
38
|
+
f"; runtime=python"
|
|
39
|
+
f"; runtime-version={platform.python_version()}"
|
|
40
|
+
),
|
|
37
41
|
**headers,
|
|
38
42
|
}
|
|
39
43
|
|
|
@@ -75,20 +79,19 @@ class AsyncFunctionsClient:
|
|
|
75
79
|
|
|
76
80
|
async def _request(
|
|
77
81
|
self,
|
|
78
|
-
method:
|
|
82
|
+
method: HTTPMethod,
|
|
79
83
|
path: list[str],
|
|
80
84
|
headers: Optional[Dict[str, str]] = None,
|
|
81
|
-
json: Optional[Dict[Any, Any]] = None,
|
|
85
|
+
json: Optional[Union[Dict[Any, Any], str, bytes]] = None,
|
|
82
86
|
params: Optional[QueryParams] = None,
|
|
83
87
|
) -> Response:
|
|
84
88
|
url = self.url.joinpath(*path)
|
|
85
|
-
headers = headers or
|
|
86
|
-
headers.update(self.headers)
|
|
89
|
+
headers = {**self.headers, **(headers or {})}
|
|
87
90
|
response = (
|
|
88
91
|
await self._client.request(
|
|
89
|
-
method, str(url),
|
|
92
|
+
method, str(url), content=json, headers=headers, params=params
|
|
90
93
|
)
|
|
91
|
-
if isinstance(json, str)
|
|
94
|
+
if isinstance(json, (str, bytes))
|
|
92
95
|
else await self._client.request(
|
|
93
96
|
method, str(url), json=json, headers=headers, params=params
|
|
94
97
|
)
|
|
@@ -101,7 +104,7 @@ class AsyncFunctionsClient:
|
|
|
101
104
|
status_code = response.status_code
|
|
102
105
|
|
|
103
106
|
raise FunctionsHttpError(
|
|
104
|
-
response
|
|
107
|
+
_error_message_from(response)
|
|
105
108
|
or f"An error occurred while requesting your edge function at {exc.request.url!r}.",
|
|
106
109
|
status_code,
|
|
107
110
|
) from exc
|
|
@@ -130,17 +133,20 @@ class AsyncFunctionsClient:
|
|
|
130
133
|
invoke_options : object with the following properties
|
|
131
134
|
`headers`: object representing the headers to send with the request
|
|
132
135
|
`body`: the body of the request
|
|
136
|
+
`method`: the HTTP method to invoke the function with. The default is `POST`
|
|
133
137
|
`responseType`: how the response should be parsed. The default is `json`
|
|
134
138
|
"""
|
|
135
139
|
if not is_valid_str_arg(function_name):
|
|
136
140
|
raise ValueError("function_name must a valid string value.")
|
|
137
|
-
headers =
|
|
141
|
+
headers: Dict[str, str] = {}
|
|
138
142
|
params = QueryParams()
|
|
139
143
|
body = None
|
|
144
|
+
method: HTTPMethod = "POST"
|
|
140
145
|
response_type = "text/plain"
|
|
141
146
|
|
|
142
147
|
if invoke_options is not None:
|
|
143
148
|
headers.update(invoke_options.get("headers", {}))
|
|
149
|
+
method = invoke_options.get("method", "POST")
|
|
144
150
|
response_type = invoke_options.get("responseType", "text/plain")
|
|
145
151
|
|
|
146
152
|
region = invoke_options.get("region")
|
|
@@ -159,14 +165,19 @@ class AsyncFunctionsClient:
|
|
|
159
165
|
headers["Content-Type"] = "text/plain"
|
|
160
166
|
elif isinstance(body, dict):
|
|
161
167
|
headers["Content-Type"] = "application/json"
|
|
168
|
+
elif isinstance(body, bytes):
|
|
169
|
+
headers["Content-Type"] = "application/octet-stream"
|
|
162
170
|
|
|
163
171
|
response = await self._request(
|
|
164
|
-
|
|
172
|
+
method, [function_name], headers=headers, json=body, params=params
|
|
165
173
|
)
|
|
166
174
|
is_relay_error = response.headers.get("x-relay-header")
|
|
167
175
|
|
|
168
176
|
if is_relay_error and is_relay_error == "true":
|
|
169
|
-
raise FunctionsRelayError(
|
|
177
|
+
raise FunctionsRelayError(
|
|
178
|
+
_error_message_from(response)
|
|
179
|
+
or "An error occurred while relaying your edge function request."
|
|
180
|
+
)
|
|
170
181
|
|
|
171
182
|
if response_type == "json":
|
|
172
183
|
data = response.json()
|
|
@@ -6,7 +6,7 @@ from warnings import warn
|
|
|
6
6
|
from httpx import Client, HTTPError, QueryParams, Response
|
|
7
7
|
from yarl import URL
|
|
8
8
|
|
|
9
|
-
from ..errors import FunctionsHttpError, FunctionsRelayError
|
|
9
|
+
from ..errors import FunctionsHttpError, FunctionsRelayError, _error_message_from
|
|
10
10
|
from ..utils import (
|
|
11
11
|
FunctionRegion,
|
|
12
12
|
is_http_url,
|
|
@@ -14,6 +14,8 @@ from ..utils import (
|
|
|
14
14
|
)
|
|
15
15
|
from ..version import __version__
|
|
16
16
|
|
|
17
|
+
HTTPMethod = Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"]
|
|
18
|
+
|
|
17
19
|
|
|
18
20
|
class SyncFunctionsClient:
|
|
19
21
|
def __init__(
|
|
@@ -29,11 +31,13 @@ class SyncFunctionsClient:
|
|
|
29
31
|
raise ValueError("url must be a valid HTTP URL string")
|
|
30
32
|
self.url = URL(url)
|
|
31
33
|
self.headers = {
|
|
32
|
-
"X-Client-Info":
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
"X-Client-Info": (
|
|
35
|
+
f"supabase-py/supabase_functions v{__version__}"
|
|
36
|
+
f"; platform={platform.system()}"
|
|
37
|
+
f"; platform-version={platform.release()}"
|
|
38
|
+
f"; runtime=python"
|
|
39
|
+
f"; runtime-version={platform.python_version()}"
|
|
40
|
+
),
|
|
37
41
|
**headers,
|
|
38
42
|
}
|
|
39
43
|
|
|
@@ -75,20 +79,19 @@ class SyncFunctionsClient:
|
|
|
75
79
|
|
|
76
80
|
def _request(
|
|
77
81
|
self,
|
|
78
|
-
method:
|
|
82
|
+
method: HTTPMethod,
|
|
79
83
|
path: list[str],
|
|
80
84
|
headers: Optional[Dict[str, str]] = None,
|
|
81
|
-
json: Optional[Dict[Any, Any]] = None,
|
|
85
|
+
json: Optional[Union[Dict[Any, Any], str, bytes]] = None,
|
|
82
86
|
params: Optional[QueryParams] = None,
|
|
83
87
|
) -> Response:
|
|
84
88
|
url = self.url.joinpath(*path)
|
|
85
|
-
headers = headers or
|
|
86
|
-
headers.update(self.headers)
|
|
89
|
+
headers = {**self.headers, **(headers or {})}
|
|
87
90
|
response = (
|
|
88
91
|
self._client.request(
|
|
89
|
-
method, str(url),
|
|
92
|
+
method, str(url), content=json, headers=headers, params=params
|
|
90
93
|
)
|
|
91
|
-
if isinstance(json, str)
|
|
94
|
+
if isinstance(json, (str, bytes))
|
|
92
95
|
else self._client.request(
|
|
93
96
|
method, str(url), json=json, headers=headers, params=params
|
|
94
97
|
)
|
|
@@ -101,7 +104,7 @@ class SyncFunctionsClient:
|
|
|
101
104
|
status_code = response.status_code
|
|
102
105
|
|
|
103
106
|
raise FunctionsHttpError(
|
|
104
|
-
response
|
|
107
|
+
_error_message_from(response)
|
|
105
108
|
or f"An error occurred while requesting your edge function at {exc.request.url!r}.",
|
|
106
109
|
status_code,
|
|
107
110
|
) from exc
|
|
@@ -130,17 +133,20 @@ class SyncFunctionsClient:
|
|
|
130
133
|
invoke_options : object with the following properties
|
|
131
134
|
`headers`: object representing the headers to send with the request
|
|
132
135
|
`body`: the body of the request
|
|
136
|
+
`method`: the HTTP method to invoke the function with. The default is `POST`
|
|
133
137
|
`responseType`: how the response should be parsed. The default is `json`
|
|
134
138
|
"""
|
|
135
139
|
if not is_valid_str_arg(function_name):
|
|
136
140
|
raise ValueError("function_name must a valid string value.")
|
|
137
|
-
headers =
|
|
141
|
+
headers: Dict[str, str] = {}
|
|
138
142
|
params = QueryParams()
|
|
139
143
|
body = None
|
|
144
|
+
method: HTTPMethod = "POST"
|
|
140
145
|
response_type = "text/plain"
|
|
141
146
|
|
|
142
147
|
if invoke_options is not None:
|
|
143
148
|
headers.update(invoke_options.get("headers", {}))
|
|
149
|
+
method = invoke_options.get("method", "POST")
|
|
144
150
|
response_type = invoke_options.get("responseType", "text/plain")
|
|
145
151
|
|
|
146
152
|
region = invoke_options.get("region")
|
|
@@ -159,14 +165,19 @@ class SyncFunctionsClient:
|
|
|
159
165
|
headers["Content-Type"] = "text/plain"
|
|
160
166
|
elif isinstance(body, dict):
|
|
161
167
|
headers["Content-Type"] = "application/json"
|
|
168
|
+
elif isinstance(body, bytes):
|
|
169
|
+
headers["Content-Type"] = "application/octet-stream"
|
|
162
170
|
|
|
163
171
|
response = self._request(
|
|
164
|
-
|
|
172
|
+
method, [function_name], headers=headers, json=body, params=params
|
|
165
173
|
)
|
|
166
174
|
is_relay_error = response.headers.get("x-relay-header")
|
|
167
175
|
|
|
168
176
|
if is_relay_error and is_relay_error == "true":
|
|
169
|
-
raise FunctionsRelayError(
|
|
177
|
+
raise FunctionsRelayError(
|
|
178
|
+
_error_message_from(response)
|
|
179
|
+
or "An error occurred while relaying your edge function request."
|
|
180
|
+
)
|
|
170
181
|
|
|
171
182
|
if response_type == "json":
|
|
172
183
|
data = response.json()
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import TypedDict
|
|
3
|
+
from typing import TYPE_CHECKING, TypedDict
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from httpx import Response
|
|
4
7
|
|
|
5
8
|
|
|
6
9
|
class FunctionsApiErrorDict(TypedDict):
|
|
@@ -42,3 +45,18 @@ class FunctionsRelayError(FunctionsError):
|
|
|
42
45
|
"FunctionsRelayError",
|
|
43
46
|
400 if code is None else code,
|
|
44
47
|
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _error_message_from(response: Response) -> str | None:
|
|
51
|
+
"""Best-effort extraction of an error message from an edge function response.
|
|
52
|
+
|
|
53
|
+
An edge function may reply with a plain-text or empty body, so a failed JSON
|
|
54
|
+
decode must not mask the underlying HTTP error.
|
|
55
|
+
"""
|
|
56
|
+
try:
|
|
57
|
+
body = response.json()
|
|
58
|
+
except ValueError:
|
|
59
|
+
return response.text or None
|
|
60
|
+
if isinstance(body, dict):
|
|
61
|
+
return body.get("error")
|
|
62
|
+
return response.text or None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.32.0" # {x-release-please-version}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.30.1" # {x-release-please-version}
|
|
File without changes
|
|
File without changes
|
{supabase_functions-2.30.1 → supabase_functions-2.32.0}/src/supabase_functions/_async/__init__.py
RENAMED
|
File without changes
|
{supabase_functions-2.30.1 → supabase_functions-2.32.0}/src/supabase_functions/_sync/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|