supabase_functions 2.31.0__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.31.0 → supabase_functions-2.32.0}/PKG-INFO +1 -1
- {supabase_functions-2.31.0 → supabase_functions-2.32.0}/pyproject.toml +1 -1
- {supabase_functions-2.31.0 → supabase_functions-2.32.0}/src/supabase_functions/_async/functions_client.py +20 -11
- {supabase_functions-2.31.0 → supabase_functions-2.32.0}/src/supabase_functions/_sync/functions_client.py +20 -11
- {supabase_functions-2.31.0 → 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.31.0/src/supabase_functions/version.py +0 -1
- {supabase_functions-2.31.0 → supabase_functions-2.32.0}/README.md +0 -0
- {supabase_functions-2.31.0 → supabase_functions-2.32.0}/src/supabase_functions/__init__.py +0 -0
- {supabase_functions-2.31.0 → supabase_functions-2.32.0}/src/supabase_functions/_async/__init__.py +0 -0
- {supabase_functions-2.31.0 → supabase_functions-2.32.0}/src/supabase_functions/_sync/__init__.py +0 -0
- {supabase_functions-2.31.0 → supabase_functions-2.32.0}/src/supabase_functions/py.typed +0 -0
- {supabase_functions-2.31.0 → 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__(
|
|
@@ -77,20 +79,19 @@ class AsyncFunctionsClient:
|
|
|
77
79
|
|
|
78
80
|
async def _request(
|
|
79
81
|
self,
|
|
80
|
-
method:
|
|
82
|
+
method: HTTPMethod,
|
|
81
83
|
path: list[str],
|
|
82
84
|
headers: Optional[Dict[str, str]] = None,
|
|
83
|
-
json: Optional[Dict[Any, Any]] = None,
|
|
85
|
+
json: Optional[Union[Dict[Any, Any], str, bytes]] = None,
|
|
84
86
|
params: Optional[QueryParams] = None,
|
|
85
87
|
) -> Response:
|
|
86
88
|
url = self.url.joinpath(*path)
|
|
87
|
-
headers = headers or
|
|
88
|
-
headers.update(self.headers)
|
|
89
|
+
headers = {**self.headers, **(headers or {})}
|
|
89
90
|
response = (
|
|
90
91
|
await self._client.request(
|
|
91
|
-
method, str(url),
|
|
92
|
+
method, str(url), content=json, headers=headers, params=params
|
|
92
93
|
)
|
|
93
|
-
if isinstance(json, str)
|
|
94
|
+
if isinstance(json, (str, bytes))
|
|
94
95
|
else await self._client.request(
|
|
95
96
|
method, str(url), json=json, headers=headers, params=params
|
|
96
97
|
)
|
|
@@ -103,7 +104,7 @@ class AsyncFunctionsClient:
|
|
|
103
104
|
status_code = response.status_code
|
|
104
105
|
|
|
105
106
|
raise FunctionsHttpError(
|
|
106
|
-
response
|
|
107
|
+
_error_message_from(response)
|
|
107
108
|
or f"An error occurred while requesting your edge function at {exc.request.url!r}.",
|
|
108
109
|
status_code,
|
|
109
110
|
) from exc
|
|
@@ -132,17 +133,20 @@ class AsyncFunctionsClient:
|
|
|
132
133
|
invoke_options : object with the following properties
|
|
133
134
|
`headers`: object representing the headers to send with the request
|
|
134
135
|
`body`: the body of the request
|
|
136
|
+
`method`: the HTTP method to invoke the function with. The default is `POST`
|
|
135
137
|
`responseType`: how the response should be parsed. The default is `json`
|
|
136
138
|
"""
|
|
137
139
|
if not is_valid_str_arg(function_name):
|
|
138
140
|
raise ValueError("function_name must a valid string value.")
|
|
139
|
-
headers =
|
|
141
|
+
headers: Dict[str, str] = {}
|
|
140
142
|
params = QueryParams()
|
|
141
143
|
body = None
|
|
144
|
+
method: HTTPMethod = "POST"
|
|
142
145
|
response_type = "text/plain"
|
|
143
146
|
|
|
144
147
|
if invoke_options is not None:
|
|
145
148
|
headers.update(invoke_options.get("headers", {}))
|
|
149
|
+
method = invoke_options.get("method", "POST")
|
|
146
150
|
response_type = invoke_options.get("responseType", "text/plain")
|
|
147
151
|
|
|
148
152
|
region = invoke_options.get("region")
|
|
@@ -161,14 +165,19 @@ class AsyncFunctionsClient:
|
|
|
161
165
|
headers["Content-Type"] = "text/plain"
|
|
162
166
|
elif isinstance(body, dict):
|
|
163
167
|
headers["Content-Type"] = "application/json"
|
|
168
|
+
elif isinstance(body, bytes):
|
|
169
|
+
headers["Content-Type"] = "application/octet-stream"
|
|
164
170
|
|
|
165
171
|
response = await self._request(
|
|
166
|
-
|
|
172
|
+
method, [function_name], headers=headers, json=body, params=params
|
|
167
173
|
)
|
|
168
174
|
is_relay_error = response.headers.get("x-relay-header")
|
|
169
175
|
|
|
170
176
|
if is_relay_error and is_relay_error == "true":
|
|
171
|
-
raise FunctionsRelayError(
|
|
177
|
+
raise FunctionsRelayError(
|
|
178
|
+
_error_message_from(response)
|
|
179
|
+
or "An error occurred while relaying your edge function request."
|
|
180
|
+
)
|
|
172
181
|
|
|
173
182
|
if response_type == "json":
|
|
174
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__(
|
|
@@ -77,20 +79,19 @@ class SyncFunctionsClient:
|
|
|
77
79
|
|
|
78
80
|
def _request(
|
|
79
81
|
self,
|
|
80
|
-
method:
|
|
82
|
+
method: HTTPMethod,
|
|
81
83
|
path: list[str],
|
|
82
84
|
headers: Optional[Dict[str, str]] = None,
|
|
83
|
-
json: Optional[Dict[Any, Any]] = None,
|
|
85
|
+
json: Optional[Union[Dict[Any, Any], str, bytes]] = None,
|
|
84
86
|
params: Optional[QueryParams] = None,
|
|
85
87
|
) -> Response:
|
|
86
88
|
url = self.url.joinpath(*path)
|
|
87
|
-
headers = headers or
|
|
88
|
-
headers.update(self.headers)
|
|
89
|
+
headers = {**self.headers, **(headers or {})}
|
|
89
90
|
response = (
|
|
90
91
|
self._client.request(
|
|
91
|
-
method, str(url),
|
|
92
|
+
method, str(url), content=json, headers=headers, params=params
|
|
92
93
|
)
|
|
93
|
-
if isinstance(json, str)
|
|
94
|
+
if isinstance(json, (str, bytes))
|
|
94
95
|
else self._client.request(
|
|
95
96
|
method, str(url), json=json, headers=headers, params=params
|
|
96
97
|
)
|
|
@@ -103,7 +104,7 @@ class SyncFunctionsClient:
|
|
|
103
104
|
status_code = response.status_code
|
|
104
105
|
|
|
105
106
|
raise FunctionsHttpError(
|
|
106
|
-
response
|
|
107
|
+
_error_message_from(response)
|
|
107
108
|
or f"An error occurred while requesting your edge function at {exc.request.url!r}.",
|
|
108
109
|
status_code,
|
|
109
110
|
) from exc
|
|
@@ -132,17 +133,20 @@ class SyncFunctionsClient:
|
|
|
132
133
|
invoke_options : object with the following properties
|
|
133
134
|
`headers`: object representing the headers to send with the request
|
|
134
135
|
`body`: the body of the request
|
|
136
|
+
`method`: the HTTP method to invoke the function with. The default is `POST`
|
|
135
137
|
`responseType`: how the response should be parsed. The default is `json`
|
|
136
138
|
"""
|
|
137
139
|
if not is_valid_str_arg(function_name):
|
|
138
140
|
raise ValueError("function_name must a valid string value.")
|
|
139
|
-
headers =
|
|
141
|
+
headers: Dict[str, str] = {}
|
|
140
142
|
params = QueryParams()
|
|
141
143
|
body = None
|
|
144
|
+
method: HTTPMethod = "POST"
|
|
142
145
|
response_type = "text/plain"
|
|
143
146
|
|
|
144
147
|
if invoke_options is not None:
|
|
145
148
|
headers.update(invoke_options.get("headers", {}))
|
|
149
|
+
method = invoke_options.get("method", "POST")
|
|
146
150
|
response_type = invoke_options.get("responseType", "text/plain")
|
|
147
151
|
|
|
148
152
|
region = invoke_options.get("region")
|
|
@@ -161,14 +165,19 @@ class SyncFunctionsClient:
|
|
|
161
165
|
headers["Content-Type"] = "text/plain"
|
|
162
166
|
elif isinstance(body, dict):
|
|
163
167
|
headers["Content-Type"] = "application/json"
|
|
168
|
+
elif isinstance(body, bytes):
|
|
169
|
+
headers["Content-Type"] = "application/octet-stream"
|
|
164
170
|
|
|
165
171
|
response = self._request(
|
|
166
|
-
|
|
172
|
+
method, [function_name], headers=headers, json=body, params=params
|
|
167
173
|
)
|
|
168
174
|
is_relay_error = response.headers.get("x-relay-header")
|
|
169
175
|
|
|
170
176
|
if is_relay_error and is_relay_error == "true":
|
|
171
|
-
raise FunctionsRelayError(
|
|
177
|
+
raise FunctionsRelayError(
|
|
178
|
+
_error_message_from(response)
|
|
179
|
+
or "An error occurred while relaying your edge function request."
|
|
180
|
+
)
|
|
172
181
|
|
|
173
182
|
if response_type == "json":
|
|
174
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.31.0" # {x-release-please-version}
|
|
File without changes
|
|
File without changes
|
{supabase_functions-2.31.0 → supabase_functions-2.32.0}/src/supabase_functions/_async/__init__.py
RENAMED
|
File without changes
|
{supabase_functions-2.31.0 → supabase_functions-2.32.0}/src/supabase_functions/_sync/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|