supabase_functions 2.31.0__tar.gz → 2.33.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.33.0}/PKG-INFO +1 -1
- {supabase_functions-2.31.0 → supabase_functions-2.33.0}/pyproject.toml +2 -2
- {supabase_functions-2.31.0 → supabase_functions-2.33.0}/src/supabase_functions/__init__.py +12 -4
- {supabase_functions-2.31.0 → supabase_functions-2.33.0}/src/supabase_functions/_async/functions_client.py +37 -31
- {supabase_functions-2.31.0 → supabase_functions-2.33.0}/src/supabase_functions/_sync/functions_client.py +37 -31
- {supabase_functions-2.31.0 → supabase_functions-2.33.0}/src/supabase_functions/errors.py +19 -1
- supabase_functions-2.33.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.33.0}/README.md +0 -0
- {supabase_functions-2.31.0 → supabase_functions-2.33.0}/src/supabase_functions/_async/__init__.py +0 -0
- {supabase_functions-2.31.0 → supabase_functions-2.33.0}/src/supabase_functions/_sync/__init__.py +0 -0
- {supabase_functions-2.31.0 → supabase_functions-2.33.0}/src/supabase_functions/py.typed +0 -0
- {supabase_functions-2.31.0 → supabase_functions-2.33.0}/src/supabase_functions/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "supabase_functions"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.33.0" # {x-release-please-version}
|
|
4
4
|
description = "Library for Supabase Functions"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Joel Lee", email = "joel@joellee.org" },
|
|
@@ -26,7 +26,7 @@ changelog = "https://github.com/supabase/supabase-py/tree/main/CHANGELOG.md"
|
|
|
26
26
|
|
|
27
27
|
[dependency-groups]
|
|
28
28
|
tests = [
|
|
29
|
-
"pyjwt
|
|
29
|
+
"pyjwt>=2.15.0",
|
|
30
30
|
"pytest >=7.4.2,<9.0.0",
|
|
31
31
|
"pytest-cov >=4,<7",
|
|
32
32
|
"pytest-asyncio >=0.21.1,<1.2.0",
|
|
@@ -16,13 +16,21 @@ __all__ = [
|
|
|
16
16
|
|
|
17
17
|
@overload
|
|
18
18
|
def create_client(
|
|
19
|
-
url: str,
|
|
19
|
+
url: str,
|
|
20
|
+
headers: dict[str, str],
|
|
21
|
+
*,
|
|
22
|
+
is_async: Literal[True],
|
|
23
|
+
verify: bool = ...,
|
|
20
24
|
) -> AsyncFunctionsClient: ...
|
|
21
25
|
|
|
22
26
|
|
|
23
27
|
@overload
|
|
24
28
|
def create_client(
|
|
25
|
-
url: str,
|
|
29
|
+
url: str,
|
|
30
|
+
headers: dict[str, str],
|
|
31
|
+
*,
|
|
32
|
+
is_async: Literal[False],
|
|
33
|
+
verify: bool = ...,
|
|
26
34
|
) -> SyncFunctionsClient: ...
|
|
27
35
|
|
|
28
36
|
|
|
@@ -34,6 +42,6 @@ def create_client(
|
|
|
34
42
|
verify: bool = True,
|
|
35
43
|
) -> Union[AsyncFunctionsClient, SyncFunctionsClient]:
|
|
36
44
|
if is_async:
|
|
37
|
-
return AsyncFunctionsClient(url, headers, verify)
|
|
45
|
+
return AsyncFunctionsClient(url, headers, verify=verify)
|
|
38
46
|
else:
|
|
39
|
-
return SyncFunctionsClient(url, headers, verify)
|
|
47
|
+
return SyncFunctionsClient(url, headers, verify=verify)
|
|
@@ -3,10 +3,10 @@ import sys
|
|
|
3
3
|
from typing import Any, Dict, Literal, Optional, Union
|
|
4
4
|
from warnings import warn
|
|
5
5
|
|
|
6
|
-
from httpx import AsyncClient, HTTPError, QueryParams, Response
|
|
6
|
+
from httpx import AsyncClient, Headers, 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__(
|
|
@@ -28,16 +30,18 @@ class AsyncFunctionsClient:
|
|
|
28
30
|
if not is_http_url(url):
|
|
29
31
|
raise ValueError("url must be a valid HTTP URL string")
|
|
30
32
|
self.url = URL(url)
|
|
31
|
-
self.headers =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
self.headers = Headers(
|
|
34
|
+
{
|
|
35
|
+
"X-Client-Info": (
|
|
36
|
+
f"supabase-py/supabase_functions v{__version__}"
|
|
37
|
+
f"; platform={platform.system()}"
|
|
38
|
+
f"; platform-version={platform.release()}"
|
|
39
|
+
f"; runtime=python"
|
|
40
|
+
f"; runtime-version={platform.python_version()}"
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
self.headers.update(headers)
|
|
41
45
|
|
|
42
46
|
if sys.version_info < (3, 10):
|
|
43
47
|
warn(
|
|
@@ -77,24 +81,25 @@ class AsyncFunctionsClient:
|
|
|
77
81
|
|
|
78
82
|
async def _request(
|
|
79
83
|
self,
|
|
80
|
-
method:
|
|
84
|
+
method: HTTPMethod,
|
|
81
85
|
path: list[str],
|
|
82
|
-
headers:
|
|
83
|
-
json: Optional[Dict[Any, Any]] = None,
|
|
86
|
+
headers: Headers,
|
|
87
|
+
json: Optional[Union[Dict[Any, Any], str, bytes]] = None,
|
|
84
88
|
params: Optional[QueryParams] = None,
|
|
85
89
|
) -> Response:
|
|
86
90
|
url = self.url.joinpath(*path)
|
|
87
|
-
headers = headers or dict()
|
|
88
|
-
headers.update(self.headers)
|
|
89
91
|
response = (
|
|
90
92
|
await self._client.request(
|
|
91
|
-
method, str(url),
|
|
93
|
+
method, str(url), content=json, headers=headers, params=params
|
|
92
94
|
)
|
|
93
|
-
if isinstance(json, str)
|
|
95
|
+
if isinstance(json, (str, bytes))
|
|
94
96
|
else await self._client.request(
|
|
95
97
|
method, str(url), json=json, headers=headers, params=params
|
|
96
98
|
)
|
|
97
99
|
)
|
|
100
|
+
# Relay failures set this header even on non-2xx responses.
|
|
101
|
+
if response.headers.get("x-relay-error") == "true":
|
|
102
|
+
raise FunctionsRelayError(response.text, response.status_code)
|
|
98
103
|
try:
|
|
99
104
|
response.raise_for_status()
|
|
100
105
|
except HTTPError as exc:
|
|
@@ -103,7 +108,7 @@ class AsyncFunctionsClient:
|
|
|
103
108
|
status_code = response.status_code
|
|
104
109
|
|
|
105
110
|
raise FunctionsHttpError(
|
|
106
|
-
response
|
|
111
|
+
_error_message_from(response)
|
|
107
112
|
or f"An error occurred while requesting your edge function at {exc.request.url!r}.",
|
|
108
113
|
status_code,
|
|
109
114
|
) from exc
|
|
@@ -132,17 +137,20 @@ class AsyncFunctionsClient:
|
|
|
132
137
|
invoke_options : object with the following properties
|
|
133
138
|
`headers`: object representing the headers to send with the request
|
|
134
139
|
`body`: the body of the request
|
|
140
|
+
`method`: the HTTP method to invoke the function with. The default is `POST`
|
|
135
141
|
`responseType`: how the response should be parsed. The default is `json`
|
|
136
142
|
"""
|
|
137
143
|
if not is_valid_str_arg(function_name):
|
|
138
144
|
raise ValueError("function_name must a valid string value.")
|
|
139
|
-
headers = self.headers
|
|
145
|
+
headers = Headers(self.headers)
|
|
140
146
|
params = QueryParams()
|
|
141
147
|
body = None
|
|
148
|
+
method: HTTPMethod = "POST"
|
|
142
149
|
response_type = "text/plain"
|
|
143
150
|
|
|
144
151
|
if invoke_options is not None:
|
|
145
152
|
headers.update(invoke_options.get("headers", {}))
|
|
153
|
+
method = invoke_options.get("method", "POST")
|
|
146
154
|
response_type = invoke_options.get("responseType", "text/plain")
|
|
147
155
|
|
|
148
156
|
region = invoke_options.get("region")
|
|
@@ -157,19 +165,17 @@ class AsyncFunctionsClient:
|
|
|
157
165
|
params = params.set("forceFunctionRegion", region.value)
|
|
158
166
|
|
|
159
167
|
body = invoke_options.get("body")
|
|
160
|
-
if
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
168
|
+
if headers.get("content-type", None) is None:
|
|
169
|
+
if isinstance(body, str):
|
|
170
|
+
headers["Content-Type"] = "text/plain"
|
|
171
|
+
elif isinstance(body, dict):
|
|
172
|
+
headers["Content-Type"] = "application/json"
|
|
173
|
+
elif isinstance(body, bytes):
|
|
174
|
+
headers["Content-Type"] = "application/octet-stream"
|
|
164
175
|
|
|
165
176
|
response = await self._request(
|
|
166
|
-
|
|
177
|
+
method, [function_name], headers=headers, json=body, params=params
|
|
167
178
|
)
|
|
168
|
-
is_relay_error = response.headers.get("x-relay-header")
|
|
169
|
-
|
|
170
|
-
if is_relay_error and is_relay_error == "true":
|
|
171
|
-
raise FunctionsRelayError(response.json().get("error"))
|
|
172
|
-
|
|
173
179
|
if response_type == "json":
|
|
174
180
|
data = response.json()
|
|
175
181
|
else:
|
|
@@ -3,10 +3,10 @@ import sys
|
|
|
3
3
|
from typing import Any, Dict, Literal, Optional, Union
|
|
4
4
|
from warnings import warn
|
|
5
5
|
|
|
6
|
-
from httpx import Client, HTTPError, QueryParams, Response
|
|
6
|
+
from httpx import Client, Headers, 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__(
|
|
@@ -28,16 +30,18 @@ class SyncFunctionsClient:
|
|
|
28
30
|
if not is_http_url(url):
|
|
29
31
|
raise ValueError("url must be a valid HTTP URL string")
|
|
30
32
|
self.url = URL(url)
|
|
31
|
-
self.headers =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
self.headers = Headers(
|
|
34
|
+
{
|
|
35
|
+
"X-Client-Info": (
|
|
36
|
+
f"supabase-py/supabase_functions v{__version__}"
|
|
37
|
+
f"; platform={platform.system()}"
|
|
38
|
+
f"; platform-version={platform.release()}"
|
|
39
|
+
f"; runtime=python"
|
|
40
|
+
f"; runtime-version={platform.python_version()}"
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
self.headers.update(headers)
|
|
41
45
|
|
|
42
46
|
if sys.version_info < (3, 10):
|
|
43
47
|
warn(
|
|
@@ -77,24 +81,25 @@ class SyncFunctionsClient:
|
|
|
77
81
|
|
|
78
82
|
def _request(
|
|
79
83
|
self,
|
|
80
|
-
method:
|
|
84
|
+
method: HTTPMethod,
|
|
81
85
|
path: list[str],
|
|
82
|
-
headers:
|
|
83
|
-
json: Optional[Dict[Any, Any]] = None,
|
|
86
|
+
headers: Headers,
|
|
87
|
+
json: Optional[Union[Dict[Any, Any], str, bytes]] = None,
|
|
84
88
|
params: Optional[QueryParams] = None,
|
|
85
89
|
) -> Response:
|
|
86
90
|
url = self.url.joinpath(*path)
|
|
87
|
-
headers = headers or dict()
|
|
88
|
-
headers.update(self.headers)
|
|
89
91
|
response = (
|
|
90
92
|
self._client.request(
|
|
91
|
-
method, str(url),
|
|
93
|
+
method, str(url), content=json, headers=headers, params=params
|
|
92
94
|
)
|
|
93
|
-
if isinstance(json, str)
|
|
95
|
+
if isinstance(json, (str, bytes))
|
|
94
96
|
else self._client.request(
|
|
95
97
|
method, str(url), json=json, headers=headers, params=params
|
|
96
98
|
)
|
|
97
99
|
)
|
|
100
|
+
# Relay failures set this header even on non-2xx responses.
|
|
101
|
+
if response.headers.get("x-relay-error") == "true":
|
|
102
|
+
raise FunctionsRelayError(response.text, response.status_code)
|
|
98
103
|
try:
|
|
99
104
|
response.raise_for_status()
|
|
100
105
|
except HTTPError as exc:
|
|
@@ -103,7 +108,7 @@ class SyncFunctionsClient:
|
|
|
103
108
|
status_code = response.status_code
|
|
104
109
|
|
|
105
110
|
raise FunctionsHttpError(
|
|
106
|
-
response
|
|
111
|
+
_error_message_from(response)
|
|
107
112
|
or f"An error occurred while requesting your edge function at {exc.request.url!r}.",
|
|
108
113
|
status_code,
|
|
109
114
|
) from exc
|
|
@@ -132,17 +137,20 @@ class SyncFunctionsClient:
|
|
|
132
137
|
invoke_options : object with the following properties
|
|
133
138
|
`headers`: object representing the headers to send with the request
|
|
134
139
|
`body`: the body of the request
|
|
140
|
+
`method`: the HTTP method to invoke the function with. The default is `POST`
|
|
135
141
|
`responseType`: how the response should be parsed. The default is `json`
|
|
136
142
|
"""
|
|
137
143
|
if not is_valid_str_arg(function_name):
|
|
138
144
|
raise ValueError("function_name must a valid string value.")
|
|
139
|
-
headers = self.headers
|
|
145
|
+
headers = Headers(self.headers)
|
|
140
146
|
params = QueryParams()
|
|
141
147
|
body = None
|
|
148
|
+
method: HTTPMethod = "POST"
|
|
142
149
|
response_type = "text/plain"
|
|
143
150
|
|
|
144
151
|
if invoke_options is not None:
|
|
145
152
|
headers.update(invoke_options.get("headers", {}))
|
|
153
|
+
method = invoke_options.get("method", "POST")
|
|
146
154
|
response_type = invoke_options.get("responseType", "text/plain")
|
|
147
155
|
|
|
148
156
|
region = invoke_options.get("region")
|
|
@@ -157,19 +165,17 @@ class SyncFunctionsClient:
|
|
|
157
165
|
params = params.set("forceFunctionRegion", region.value)
|
|
158
166
|
|
|
159
167
|
body = invoke_options.get("body")
|
|
160
|
-
if
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
168
|
+
if headers.get("content-type", None) is None:
|
|
169
|
+
if isinstance(body, str):
|
|
170
|
+
headers["Content-Type"] = "text/plain"
|
|
171
|
+
elif isinstance(body, dict):
|
|
172
|
+
headers["Content-Type"] = "application/json"
|
|
173
|
+
elif isinstance(body, bytes):
|
|
174
|
+
headers["Content-Type"] = "application/octet-stream"
|
|
164
175
|
|
|
165
176
|
response = self._request(
|
|
166
|
-
|
|
177
|
+
method, [function_name], headers=headers, json=body, params=params
|
|
167
178
|
)
|
|
168
|
-
is_relay_error = response.headers.get("x-relay-header")
|
|
169
|
-
|
|
170
|
-
if is_relay_error and is_relay_error == "true":
|
|
171
|
-
raise FunctionsRelayError(response.json().get("error"))
|
|
172
|
-
|
|
173
179
|
if response_type == "json":
|
|
174
180
|
data = response.json()
|
|
175
181
|
else:
|
|
@@ -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.33.0" # {x-release-please-version}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.31.0" # {x-release-please-version}
|
|
File without changes
|
{supabase_functions-2.31.0 → supabase_functions-2.33.0}/src/supabase_functions/_async/__init__.py
RENAMED
|
File without changes
|
{supabase_functions-2.31.0 → supabase_functions-2.33.0}/src/supabase_functions/_sync/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|