supabase_functions 0.7.0__tar.gz → 0.9.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-0.7.0 → supabase_functions-0.9.0}/PKG-INFO +2 -1
- {supabase_functions-0.7.0 → supabase_functions-0.9.0}/pyproject.toml +2 -1
- {supabase_functions-0.7.0 → supabase_functions-0.9.0}/supabase_functions/__init__.py +1 -0
- {supabase_functions-0.7.0 → supabase_functions-0.9.0}/supabase_functions/_async/functions_client.py +18 -3
- {supabase_functions-0.7.0 → supabase_functions-0.9.0}/supabase_functions/_sync/functions_client.py +18 -3
- supabase_functions-0.9.0/supabase_functions/utils.py +69 -0
- supabase_functions-0.9.0/supabase_functions/version.py +1 -0
- supabase_functions-0.7.0/supabase_functions/utils.py +0 -19
- supabase_functions-0.7.0/supabase_functions/version.py +0 -1
- {supabase_functions-0.7.0 → supabase_functions-0.9.0}/LICENSE +0 -0
- {supabase_functions-0.7.0 → supabase_functions-0.9.0}/README.md +0 -0
- {supabase_functions-0.7.0 → supabase_functions-0.9.0}/supabase_functions/_async/__init__.py +0 -0
- {supabase_functions-0.7.0 → supabase_functions-0.9.0}/supabase_functions/_sync/__init__.py +0 -0
- {supabase_functions-0.7.0 → supabase_functions-0.9.0}/supabase_functions/errors.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: supabase_functions
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: Library for Supabase Functions
|
|
5
5
|
Home-page: https://github.com/supabase/functions-py
|
|
6
6
|
License: MIT
|
|
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
16
|
Requires-Dist: httpx[http2] (>=0.26,<0.28)
|
|
17
|
+
Requires-Dist: strenum (>=0.4.15,<0.5.0)
|
|
17
18
|
Project-URL: Repository, https://github.com/supabase/functions-py
|
|
18
19
|
Description-Content-Type: text/markdown
|
|
19
20
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "supabase_functions"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.9.0" # {x-release-please-version}
|
|
4
4
|
description = "Library for Supabase Functions"
|
|
5
5
|
authors = [
|
|
6
6
|
"Joel Lee <joel@joellee.org>",
|
|
@@ -13,6 +13,7 @@ repository = "https://github.com/supabase/functions-py"
|
|
|
13
13
|
[tool.poetry.dependencies]
|
|
14
14
|
python = "^3.9"
|
|
15
15
|
httpx = {version = ">=0.26,<0.28", extras = ["http2"]}
|
|
16
|
+
strenum = "^0.4.15"
|
|
16
17
|
|
|
17
18
|
[tool.poetry.group.dev.dependencies]
|
|
18
19
|
black = ">=23.9.1,<25.0.0"
|
{supabase_functions-0.7.0 → supabase_functions-0.9.0}/supabase_functions/_async/functions_client.py
RENAMED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
from typing import Any, Dict, Literal, Optional, Union
|
|
2
|
+
from warnings import warn
|
|
2
3
|
|
|
3
4
|
from httpx import HTTPError, Response
|
|
4
5
|
|
|
5
6
|
from ..errors import FunctionsHttpError, FunctionsRelayError
|
|
6
|
-
from ..utils import
|
|
7
|
+
from ..utils import (
|
|
8
|
+
AsyncClient,
|
|
9
|
+
FunctionRegion,
|
|
10
|
+
is_http_url,
|
|
11
|
+
is_valid_jwt,
|
|
12
|
+
is_valid_str_arg,
|
|
13
|
+
)
|
|
7
14
|
from ..version import __version__
|
|
8
15
|
|
|
9
16
|
|
|
@@ -60,6 +67,9 @@ class AsyncFunctionsClient:
|
|
|
60
67
|
the new jwt token sent in the authorization header
|
|
61
68
|
"""
|
|
62
69
|
|
|
70
|
+
if not is_valid_jwt(token):
|
|
71
|
+
ValueError("token must be a valid JWT authorization token string.")
|
|
72
|
+
|
|
63
73
|
self.headers["Authorization"] = f"Bearer {token}"
|
|
64
74
|
|
|
65
75
|
async def invoke(
|
|
@@ -85,8 +95,13 @@ class AsyncFunctionsClient:
|
|
|
85
95
|
response_type = invoke_options.get("responseType", "text/plain")
|
|
86
96
|
|
|
87
97
|
region = invoke_options.get("region")
|
|
88
|
-
if region
|
|
89
|
-
|
|
98
|
+
if region:
|
|
99
|
+
if not isinstance(region, FunctionRegion):
|
|
100
|
+
warn(f"Use FunctionRegion({region})")
|
|
101
|
+
region = FunctionRegion(region)
|
|
102
|
+
|
|
103
|
+
if region.value != "any":
|
|
104
|
+
headers["x-region"] = region.value
|
|
90
105
|
|
|
91
106
|
body = invoke_options.get("body")
|
|
92
107
|
if isinstance(body, str):
|
{supabase_functions-0.7.0 → supabase_functions-0.9.0}/supabase_functions/_sync/functions_client.py
RENAMED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
from typing import Any, Dict, Literal, Optional, Union
|
|
2
|
+
from warnings import warn
|
|
2
3
|
|
|
3
4
|
from httpx import HTTPError, Response
|
|
4
5
|
|
|
5
6
|
from ..errors import FunctionsHttpError, FunctionsRelayError
|
|
6
|
-
from ..utils import
|
|
7
|
+
from ..utils import (
|
|
8
|
+
FunctionRegion,
|
|
9
|
+
SyncClient,
|
|
10
|
+
is_http_url,
|
|
11
|
+
is_valid_jwt,
|
|
12
|
+
is_valid_str_arg,
|
|
13
|
+
)
|
|
7
14
|
from ..version import __version__
|
|
8
15
|
|
|
9
16
|
|
|
@@ -60,6 +67,9 @@ class SyncFunctionsClient:
|
|
|
60
67
|
the new jwt token sent in the authorization header
|
|
61
68
|
"""
|
|
62
69
|
|
|
70
|
+
if not is_valid_jwt(token):
|
|
71
|
+
ValueError("token must be a valid JWT authorization token string.")
|
|
72
|
+
|
|
63
73
|
self.headers["Authorization"] = f"Bearer {token}"
|
|
64
74
|
|
|
65
75
|
def invoke(
|
|
@@ -85,8 +95,13 @@ class SyncFunctionsClient:
|
|
|
85
95
|
response_type = invoke_options.get("responseType", "text/plain")
|
|
86
96
|
|
|
87
97
|
region = invoke_options.get("region")
|
|
88
|
-
if region
|
|
89
|
-
|
|
98
|
+
if region:
|
|
99
|
+
if not isinstance(region, FunctionRegion):
|
|
100
|
+
warn(f"Use FunctionRegion({region})")
|
|
101
|
+
region = FunctionRegion(region)
|
|
102
|
+
|
|
103
|
+
if region.value != "any":
|
|
104
|
+
headers["x-region"] = region.value
|
|
90
105
|
|
|
91
106
|
body = invoke_options.get("body")
|
|
92
107
|
if isinstance(body, str):
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import sys
|
|
3
|
+
from urllib.parse import urlparse
|
|
4
|
+
|
|
5
|
+
from httpx import AsyncClient as AsyncClient # noqa: F401
|
|
6
|
+
from httpx import Client as BaseClient
|
|
7
|
+
|
|
8
|
+
if sys.version_info >= (3, 11):
|
|
9
|
+
from enum import StrEnum
|
|
10
|
+
else:
|
|
11
|
+
from strenum import StrEnum
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
DEFAULT_FUNCTION_CLIENT_TIMEOUT = 5
|
|
15
|
+
BASE64URL_REGEX = r"^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}$|[a-z0-9_-]{2}$)$"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class FunctionRegion(StrEnum):
|
|
19
|
+
Any = "any"
|
|
20
|
+
ApNortheast1 = "ap-northeast-1"
|
|
21
|
+
ApNortheast2 = "ap-northeast-2"
|
|
22
|
+
ApSouth1 = "ap-south-1"
|
|
23
|
+
ApSoutheast1 = "ap-southeast-1"
|
|
24
|
+
ApSoutheast2 = "ap-southeast-2"
|
|
25
|
+
CaCentral1 = "ca-central-1"
|
|
26
|
+
EuCentral1 = "eu-central-1"
|
|
27
|
+
EuWest1 = "eu-west-1"
|
|
28
|
+
EuWest2 = "eu-west-2"
|
|
29
|
+
EuWest3 = "eu-west-3"
|
|
30
|
+
SaEast1 = "sa-east-1"
|
|
31
|
+
UsEast1 = "us-east-1"
|
|
32
|
+
UsWest1 = "us-west-1"
|
|
33
|
+
UsWest2 = "us-west-2"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class SyncClient(BaseClient):
|
|
37
|
+
def aclose(self) -> None:
|
|
38
|
+
self.close()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def is_valid_str_arg(target: str) -> bool:
|
|
42
|
+
return isinstance(target, str) and len(target.strip()) > 0
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def is_http_url(url: str) -> bool:
|
|
46
|
+
return urlparse(url).scheme in {"https", "http"}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def is_valid_jwt(value: str) -> bool:
|
|
50
|
+
"""Checks if value looks like a JWT, does not do any extra parsing."""
|
|
51
|
+
if not isinstance(value, str):
|
|
52
|
+
return False
|
|
53
|
+
|
|
54
|
+
# Remove trailing whitespaces if any.
|
|
55
|
+
value = value.strip()
|
|
56
|
+
|
|
57
|
+
# Remove "Bearer " prefix if any.
|
|
58
|
+
if value.startswith("Bearer "):
|
|
59
|
+
value = value[7:]
|
|
60
|
+
|
|
61
|
+
# Valid JWT must have 2 dots (Header.Paylod.Signature)
|
|
62
|
+
if value.count(".") != 2:
|
|
63
|
+
return False
|
|
64
|
+
|
|
65
|
+
for part in value.split("."):
|
|
66
|
+
if not re.search(BASE64URL_REGEX, part, re.IGNORECASE):
|
|
67
|
+
return False
|
|
68
|
+
|
|
69
|
+
return True
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.9.0" # {x-release-please-version}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
from urllib.parse import urlparse
|
|
2
|
-
|
|
3
|
-
from httpx import AsyncClient as AsyncClient # noqa: F401
|
|
4
|
-
from httpx import Client as BaseClient
|
|
5
|
-
|
|
6
|
-
DEFAULT_FUNCTION_CLIENT_TIMEOUT = 5
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class SyncClient(BaseClient):
|
|
10
|
-
def aclose(self) -> None:
|
|
11
|
-
self.close()
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def is_valid_str_arg(target: str) -> bool:
|
|
15
|
-
return isinstance(target, str) and len(target.strip()) > 0
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def is_http_url(url: str) -> bool:
|
|
19
|
-
return urlparse(url).scheme in {"https", "http"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.7.0" # {x-release-please-version}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|