supabase_functions 2.33.0__tar.gz → 2.34.1__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.33.0 → supabase_functions-2.34.1}/PKG-INFO +8 -3
- {supabase_functions-2.33.0 → supabase_functions-2.34.1}/README.md +6 -0
- {supabase_functions-2.33.0 → supabase_functions-2.34.1}/pyproject.toml +5 -6
- {supabase_functions-2.33.0 → supabase_functions-2.34.1}/src/supabase_functions/__init__.py +2 -2
- {supabase_functions-2.33.0 → supabase_functions-2.34.1}/src/supabase_functions/_async/functions_client.py +58 -23
- {supabase_functions-2.33.0 → supabase_functions-2.34.1}/src/supabase_functions/_sync/functions_client.py +58 -23
- {supabase_functions-2.33.0 → supabase_functions-2.34.1}/src/supabase_functions/utils.py +2 -8
- supabase_functions-2.34.1/src/supabase_functions/version.py +1 -0
- supabase_functions-2.33.0/src/supabase_functions/version.py +0 -1
- {supabase_functions-2.33.0 → supabase_functions-2.34.1}/src/supabase_functions/_async/__init__.py +0 -0
- {supabase_functions-2.33.0 → supabase_functions-2.34.1}/src/supabase_functions/_sync/__init__.py +0 -0
- {supabase_functions-2.33.0 → supabase_functions-2.34.1}/src/supabase_functions/errors.py +0 -0
- {supabase_functions-2.33.0 → supabase_functions-2.34.1}/src/supabase_functions/py.typed +0 -0
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: supabase-functions
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.34.1
|
|
4
4
|
Summary: Library for Supabase Functions
|
|
5
5
|
Author: Joel Lee, Andrew Smith
|
|
6
6
|
Author-email: Joel Lee <joel@joellee.org>, Andrew Smith <a.smith@silentworks.co.uk>
|
|
7
7
|
License-Expression: MIT
|
|
8
8
|
Requires-Dist: httpx[http2]>=0.26,<0.29
|
|
9
|
-
Requires-Dist: strenum>=0.4.15
|
|
10
9
|
Requires-Dist: yarl>=1.20.1
|
|
11
10
|
Maintainer: Leonardo Santiago
|
|
12
11
|
Maintainer-email: Leonardo Santiago <leonardo.santiago@supabase.io>
|
|
13
|
-
Requires-Python: >=3.
|
|
12
|
+
Requires-Python: >=3.11
|
|
14
13
|
Project-URL: changelog, https://github.com/supabase/supabase-py/tree/main/CHANGELOG.md
|
|
15
14
|
Project-URL: homepage, https://github.com/supabase/supabase-py/tree/main/src/functions
|
|
16
15
|
Project-URL: repository, https://github.com/supabase/supabase-py
|
|
@@ -33,6 +32,12 @@ uv add supabase_functions
|
|
|
33
32
|
poetry add supabase_functions
|
|
34
33
|
```
|
|
35
34
|
|
|
35
|
+
## Supabase Service Compatibility
|
|
36
|
+
|
|
37
|
+
`supabase_functions` only guarantees compatibility with the [latest Supabase Edge Runtime release](https://github.com/supabase/edge-runtime/releases). Older Supabase Edge Runtime releases are supported on a best-effort basis, but compatibility is not guaranteed.
|
|
38
|
+
|
|
39
|
+
If you self-host the Supabase Edge Runtime, we recommend upgrading to the latest release when upgrading this SDK.
|
|
40
|
+
|
|
36
41
|
## Usage
|
|
37
42
|
|
|
38
43
|
Deploy your Edge Function following the [Supabase Functions documentation](https://supabase.com/docs/guides/functions).
|
|
@@ -15,6 +15,12 @@ uv add supabase_functions
|
|
|
15
15
|
poetry add supabase_functions
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
## Supabase Service Compatibility
|
|
19
|
+
|
|
20
|
+
`supabase_functions` only guarantees compatibility with the [latest Supabase Edge Runtime release](https://github.com/supabase/edge-runtime/releases). Older Supabase Edge Runtime releases are supported on a best-effort basis, but compatibility is not guaranteed.
|
|
21
|
+
|
|
22
|
+
If you self-host the Supabase Edge Runtime, we recommend upgrading to the latest release when upgrading this SDK.
|
|
23
|
+
|
|
18
24
|
## Usage
|
|
19
25
|
|
|
20
26
|
Deploy your Edge Function following the [Supabase Functions documentation](https://supabase.com/docs/guides/functions).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "supabase_functions"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.34.1" # {x-release-please-version}
|
|
4
4
|
description = "Library for Supabase Functions"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Joel Lee", email = "joel@joellee.org" },
|
|
@@ -11,10 +11,9 @@ maintainers = [
|
|
|
11
11
|
]
|
|
12
12
|
license = "MIT"
|
|
13
13
|
readme = "README.md"
|
|
14
|
-
requires-python = ">=3.
|
|
14
|
+
requires-python = ">=3.11"
|
|
15
15
|
dependencies = [
|
|
16
16
|
"httpx[http2] >=0.26,<0.29",
|
|
17
|
-
"strenum >=0.4.15",
|
|
18
17
|
"yarl>=1.20.1",
|
|
19
18
|
]
|
|
20
19
|
|
|
@@ -26,10 +25,10 @@ changelog = "https://github.com/supabase/supabase-py/tree/main/CHANGELOG.md"
|
|
|
26
25
|
|
|
27
26
|
[dependency-groups]
|
|
28
27
|
tests = [
|
|
29
|
-
"pyjwt>=2.15.
|
|
30
|
-
"pytest >=
|
|
28
|
+
"pyjwt>=2.15.1",
|
|
29
|
+
"pytest >=9.0.3",
|
|
31
30
|
"pytest-cov >=4,<7",
|
|
32
|
-
"pytest-asyncio >=
|
|
31
|
+
"pytest-asyncio >=1.3.0",
|
|
33
32
|
]
|
|
34
33
|
lints = [
|
|
35
34
|
"unasync>=0.6.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import Literal,
|
|
3
|
+
from typing import Literal, overload
|
|
4
4
|
|
|
5
5
|
from ._async.functions_client import AsyncFunctionsClient
|
|
6
6
|
from ._sync.functions_client import SyncFunctionsClient
|
|
@@ -40,7 +40,7 @@ def create_client(
|
|
|
40
40
|
*,
|
|
41
41
|
is_async: bool,
|
|
42
42
|
verify: bool = True,
|
|
43
|
-
) ->
|
|
43
|
+
) -> AsyncFunctionsClient | SyncFunctionsClient:
|
|
44
44
|
if is_async:
|
|
45
45
|
return AsyncFunctionsClient(url, headers, verify=verify)
|
|
46
46
|
else:
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import platform
|
|
2
|
-
import
|
|
3
|
-
from typing import Any, Dict, Literal, Optional, Union
|
|
2
|
+
from typing import Any, Literal
|
|
4
3
|
from warnings import warn
|
|
5
4
|
|
|
6
|
-
from httpx import
|
|
5
|
+
from httpx import URL as HttpxURL
|
|
6
|
+
from httpx import AsyncClient, Headers, HTTPError, QueryParams, Request, Response
|
|
7
7
|
from yarl import URL
|
|
8
8
|
|
|
9
9
|
from ..errors import FunctionsHttpError, FunctionsRelayError, _error_message_from
|
|
@@ -17,15 +17,51 @@ from ..version import __version__
|
|
|
17
17
|
HTTPMethod = Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"]
|
|
18
18
|
|
|
19
19
|
|
|
20
|
+
def _port_or_default(url: HttpxURL) -> int | None:
|
|
21
|
+
if url.port is not None:
|
|
22
|
+
return url.port
|
|
23
|
+
return {"http": 80, "https": 443}.get(url.scheme)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _keeps_credentials(source: HttpxURL, target: HttpxURL) -> bool:
|
|
27
|
+
if source.host != target.host:
|
|
28
|
+
return False
|
|
29
|
+
if source.scheme == target.scheme:
|
|
30
|
+
return _port_or_default(source) == _port_or_default(target)
|
|
31
|
+
return (
|
|
32
|
+
source.scheme == "http"
|
|
33
|
+
and _port_or_default(source) == 80
|
|
34
|
+
and target.scheme == "https"
|
|
35
|
+
and _port_or_default(target) == 443
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class _RedirectGuardClient(AsyncClient):
|
|
40
|
+
"""Drops the ``apiKey`` header on redirects that leave the origin.
|
|
41
|
+
|
|
42
|
+
httpx only strips ``Authorization`` on such redirects, so the project key
|
|
43
|
+
(the ``service_role`` key in server side usage) would otherwise be sent to
|
|
44
|
+
whatever host an invoked edge function redirects to.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
def _redirect_headers(
|
|
48
|
+
self, request: Request, url: HttpxURL, method: str
|
|
49
|
+
) -> Headers:
|
|
50
|
+
headers = super()._redirect_headers(request, url, method)
|
|
51
|
+
if not _keeps_credentials(request.url, url):
|
|
52
|
+
headers.pop("apiKey", None)
|
|
53
|
+
return headers
|
|
54
|
+
|
|
55
|
+
|
|
20
56
|
class AsyncFunctionsClient:
|
|
21
57
|
def __init__(
|
|
22
58
|
self,
|
|
23
59
|
url: str,
|
|
24
|
-
headers:
|
|
25
|
-
timeout:
|
|
26
|
-
verify:
|
|
27
|
-
proxy:
|
|
28
|
-
http_client:
|
|
60
|
+
headers: dict,
|
|
61
|
+
timeout: int | None = None,
|
|
62
|
+
verify: bool | None = None,
|
|
63
|
+
proxy: str | None = None,
|
|
64
|
+
http_client: AsyncClient | None = None,
|
|
29
65
|
) -> None:
|
|
30
66
|
if not is_http_url(url):
|
|
31
67
|
raise ValueError("url must be a valid HTTP URL string")
|
|
@@ -43,13 +79,6 @@ class AsyncFunctionsClient:
|
|
|
43
79
|
)
|
|
44
80
|
self.headers.update(headers)
|
|
45
81
|
|
|
46
|
-
if sys.version_info < (3, 10):
|
|
47
|
-
warn(
|
|
48
|
-
"Python versions below 3.10 are deprecated and will not be supported in future versions. Please upgrade to Python 3.10 or newer.",
|
|
49
|
-
DeprecationWarning,
|
|
50
|
-
stacklevel=2,
|
|
51
|
-
)
|
|
52
|
-
|
|
53
82
|
if timeout is not None:
|
|
54
83
|
warn(
|
|
55
84
|
"The 'timeout' parameter is deprecated. Please configure it in the http client instead.",
|
|
@@ -71,7 +100,7 @@ class AsyncFunctionsClient:
|
|
|
71
100
|
|
|
72
101
|
self.verify = bool(verify) if verify is not None else True
|
|
73
102
|
self.timeout = int(abs(timeout)) if timeout is not None else 60
|
|
74
|
-
self._client = http_client or
|
|
103
|
+
self._client = http_client or _RedirectGuardClient(
|
|
75
104
|
verify=self.verify,
|
|
76
105
|
timeout=self.timeout,
|
|
77
106
|
proxy=proxy,
|
|
@@ -84,8 +113,8 @@ class AsyncFunctionsClient:
|
|
|
84
113
|
method: HTTPMethod,
|
|
85
114
|
path: list[str],
|
|
86
115
|
headers: Headers,
|
|
87
|
-
json:
|
|
88
|
-
params:
|
|
116
|
+
json: dict[Any, Any] | str | bytes | None = None,
|
|
117
|
+
params: QueryParams | None = None,
|
|
89
118
|
) -> Response:
|
|
90
119
|
url = self.url.joinpath(*path)
|
|
91
120
|
response = (
|
|
@@ -127,13 +156,14 @@ class AsyncFunctionsClient:
|
|
|
127
156
|
self.headers["Authorization"] = f"Bearer {token}"
|
|
128
157
|
|
|
129
158
|
async def invoke(
|
|
130
|
-
self, function_name: str, invoke_options:
|
|
131
|
-
) ->
|
|
159
|
+
self, function_name: str, invoke_options: dict | None = None
|
|
160
|
+
) -> dict | bytes:
|
|
132
161
|
"""Invokes a function
|
|
133
162
|
|
|
134
163
|
Parameters
|
|
135
164
|
----------
|
|
136
|
-
function_name : the name of the function to invoke
|
|
165
|
+
function_name : the name of the function to invoke. It may carry a query
|
|
166
|
+
string, as in `hello?name=bob`. A `#fragment` is dropped.
|
|
137
167
|
invoke_options : object with the following properties
|
|
138
168
|
`headers`: object representing the headers to send with the request
|
|
139
169
|
`body`: the body of the request
|
|
@@ -142,8 +172,13 @@ class AsyncFunctionsClient:
|
|
|
142
172
|
"""
|
|
143
173
|
if not is_valid_str_arg(function_name):
|
|
144
174
|
raise ValueError("function_name must a valid string value.")
|
|
175
|
+
# Like a URL, a name such as "hello?name=bob" carries query params and
|
|
176
|
+
# the fragment is never sent.
|
|
177
|
+
path, _, query = function_name.split("#", 1)[0].partition("?")
|
|
178
|
+
if not is_valid_str_arg(path):
|
|
179
|
+
raise ValueError("function_name must a valid string value.")
|
|
145
180
|
headers = Headers(self.headers)
|
|
146
|
-
params = QueryParams()
|
|
181
|
+
params = QueryParams(query)
|
|
147
182
|
body = None
|
|
148
183
|
method: HTTPMethod = "POST"
|
|
149
184
|
response_type = "text/plain"
|
|
@@ -174,7 +209,7 @@ class AsyncFunctionsClient:
|
|
|
174
209
|
headers["Content-Type"] = "application/octet-stream"
|
|
175
210
|
|
|
176
211
|
response = await self._request(
|
|
177
|
-
method, [
|
|
212
|
+
method, [path], headers=headers, json=body, params=params
|
|
178
213
|
)
|
|
179
214
|
if response_type == "json":
|
|
180
215
|
data = response.json()
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import platform
|
|
2
|
-
import
|
|
3
|
-
from typing import Any, Dict, Literal, Optional, Union
|
|
2
|
+
from typing import Any, Literal
|
|
4
3
|
from warnings import warn
|
|
5
4
|
|
|
6
|
-
from httpx import
|
|
5
|
+
from httpx import URL as HttpxURL
|
|
6
|
+
from httpx import Client, Headers, HTTPError, QueryParams, Request, Response
|
|
7
7
|
from yarl import URL
|
|
8
8
|
|
|
9
9
|
from ..errors import FunctionsHttpError, FunctionsRelayError, _error_message_from
|
|
@@ -17,15 +17,51 @@ from ..version import __version__
|
|
|
17
17
|
HTTPMethod = Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"]
|
|
18
18
|
|
|
19
19
|
|
|
20
|
+
def _port_or_default(url: HttpxURL) -> int | None:
|
|
21
|
+
if url.port is not None:
|
|
22
|
+
return url.port
|
|
23
|
+
return {"http": 80, "https": 443}.get(url.scheme)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _keeps_credentials(source: HttpxURL, target: HttpxURL) -> bool:
|
|
27
|
+
if source.host != target.host:
|
|
28
|
+
return False
|
|
29
|
+
if source.scheme == target.scheme:
|
|
30
|
+
return _port_or_default(source) == _port_or_default(target)
|
|
31
|
+
return (
|
|
32
|
+
source.scheme == "http"
|
|
33
|
+
and _port_or_default(source) == 80
|
|
34
|
+
and target.scheme == "https"
|
|
35
|
+
and _port_or_default(target) == 443
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class _RedirectGuardClient(Client):
|
|
40
|
+
"""Drops the ``apiKey`` header on redirects that leave the origin.
|
|
41
|
+
|
|
42
|
+
httpx only strips ``Authorization`` on such redirects, so the project key
|
|
43
|
+
(the ``service_role`` key in server side usage) would otherwise be sent to
|
|
44
|
+
whatever host an invoked edge function redirects to.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
def _redirect_headers(
|
|
48
|
+
self, request: Request, url: HttpxURL, method: str
|
|
49
|
+
) -> Headers:
|
|
50
|
+
headers = super()._redirect_headers(request, url, method)
|
|
51
|
+
if not _keeps_credentials(request.url, url):
|
|
52
|
+
headers.pop("apiKey", None)
|
|
53
|
+
return headers
|
|
54
|
+
|
|
55
|
+
|
|
20
56
|
class SyncFunctionsClient:
|
|
21
57
|
def __init__(
|
|
22
58
|
self,
|
|
23
59
|
url: str,
|
|
24
|
-
headers:
|
|
25
|
-
timeout:
|
|
26
|
-
verify:
|
|
27
|
-
proxy:
|
|
28
|
-
http_client:
|
|
60
|
+
headers: dict,
|
|
61
|
+
timeout: int | None = None,
|
|
62
|
+
verify: bool | None = None,
|
|
63
|
+
proxy: str | None = None,
|
|
64
|
+
http_client: Client | None = None,
|
|
29
65
|
) -> None:
|
|
30
66
|
if not is_http_url(url):
|
|
31
67
|
raise ValueError("url must be a valid HTTP URL string")
|
|
@@ -43,13 +79,6 @@ class SyncFunctionsClient:
|
|
|
43
79
|
)
|
|
44
80
|
self.headers.update(headers)
|
|
45
81
|
|
|
46
|
-
if sys.version_info < (3, 10):
|
|
47
|
-
warn(
|
|
48
|
-
"Python versions below 3.10 are deprecated and will not be supported in future versions. Please upgrade to Python 3.10 or newer.",
|
|
49
|
-
DeprecationWarning,
|
|
50
|
-
stacklevel=2,
|
|
51
|
-
)
|
|
52
|
-
|
|
53
82
|
if timeout is not None:
|
|
54
83
|
warn(
|
|
55
84
|
"The 'timeout' parameter is deprecated. Please configure it in the http client instead.",
|
|
@@ -71,7 +100,7 @@ class SyncFunctionsClient:
|
|
|
71
100
|
|
|
72
101
|
self.verify = bool(verify) if verify is not None else True
|
|
73
102
|
self.timeout = int(abs(timeout)) if timeout is not None else 60
|
|
74
|
-
self._client = http_client or
|
|
103
|
+
self._client = http_client or _RedirectGuardClient(
|
|
75
104
|
verify=self.verify,
|
|
76
105
|
timeout=self.timeout,
|
|
77
106
|
proxy=proxy,
|
|
@@ -84,8 +113,8 @@ class SyncFunctionsClient:
|
|
|
84
113
|
method: HTTPMethod,
|
|
85
114
|
path: list[str],
|
|
86
115
|
headers: Headers,
|
|
87
|
-
json:
|
|
88
|
-
params:
|
|
116
|
+
json: dict[Any, Any] | str | bytes | None = None,
|
|
117
|
+
params: QueryParams | None = None,
|
|
89
118
|
) -> Response:
|
|
90
119
|
url = self.url.joinpath(*path)
|
|
91
120
|
response = (
|
|
@@ -127,13 +156,14 @@ class SyncFunctionsClient:
|
|
|
127
156
|
self.headers["Authorization"] = f"Bearer {token}"
|
|
128
157
|
|
|
129
158
|
def invoke(
|
|
130
|
-
self, function_name: str, invoke_options:
|
|
131
|
-
) ->
|
|
159
|
+
self, function_name: str, invoke_options: dict | None = None
|
|
160
|
+
) -> dict | bytes:
|
|
132
161
|
"""Invokes a function
|
|
133
162
|
|
|
134
163
|
Parameters
|
|
135
164
|
----------
|
|
136
|
-
function_name : the name of the function to invoke
|
|
165
|
+
function_name : the name of the function to invoke. It may carry a query
|
|
166
|
+
string, as in `hello?name=bob`. A `#fragment` is dropped.
|
|
137
167
|
invoke_options : object with the following properties
|
|
138
168
|
`headers`: object representing the headers to send with the request
|
|
139
169
|
`body`: the body of the request
|
|
@@ -142,8 +172,13 @@ class SyncFunctionsClient:
|
|
|
142
172
|
"""
|
|
143
173
|
if not is_valid_str_arg(function_name):
|
|
144
174
|
raise ValueError("function_name must a valid string value.")
|
|
175
|
+
# Like a URL, a name such as "hello?name=bob" carries query params and
|
|
176
|
+
# the fragment is never sent.
|
|
177
|
+
path, _, query = function_name.split("#", 1)[0].partition("?")
|
|
178
|
+
if not is_valid_str_arg(path):
|
|
179
|
+
raise ValueError("function_name must a valid string value.")
|
|
145
180
|
headers = Headers(self.headers)
|
|
146
|
-
params = QueryParams()
|
|
181
|
+
params = QueryParams(query)
|
|
147
182
|
body = None
|
|
148
183
|
method: HTTPMethod = "POST"
|
|
149
184
|
response_type = "text/plain"
|
|
@@ -174,7 +209,7 @@ class SyncFunctionsClient:
|
|
|
174
209
|
headers["Content-Type"] = "application/octet-stream"
|
|
175
210
|
|
|
176
211
|
response = self._request(
|
|
177
|
-
method, [
|
|
212
|
+
method, [path], headers=headers, json=body, params=params
|
|
178
213
|
)
|
|
179
214
|
if response_type == "json":
|
|
180
215
|
data = response.json()
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
from enum import StrEnum
|
|
2
2
|
from urllib.parse import urlparse
|
|
3
3
|
|
|
4
|
-
from httpx import AsyncClient as AsyncClient
|
|
5
|
-
|
|
6
|
-
if sys.version_info >= (3, 11):
|
|
7
|
-
from enum import StrEnum
|
|
8
|
-
else:
|
|
9
|
-
from strenum import StrEnum
|
|
10
|
-
|
|
4
|
+
from httpx import AsyncClient as AsyncClient
|
|
11
5
|
|
|
12
6
|
DEFAULT_FUNCTION_CLIENT_TIMEOUT = 5
|
|
13
7
|
BASE64URL_REGEX = r"^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}$|[a-z0-9_-]{2}$)$"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.34.1" # {x-release-please-version}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.33.0" # {x-release-please-version}
|
{supabase_functions-2.33.0 → supabase_functions-2.34.1}/src/supabase_functions/_async/__init__.py
RENAMED
|
File without changes
|
{supabase_functions-2.33.0 → supabase_functions-2.34.1}/src/supabase_functions/_sync/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|