supabase_functions 0.6.2__tar.gz → 0.8.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: supabase_functions
3
- Version: 0.6.2
3
+ Version: 0.8.0
4
4
  Summary: Library for Supabase Functions
5
5
  Home-page: https://github.com/supabase/functions-py
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "supabase_functions"
3
- version = "0.6.2" # {x-release-please-version}
3
+ version = "0.8.0" # {x-release-please-version}
4
4
  description = "Library for Supabase Functions"
5
5
  authors = [
6
6
  "Joel Lee <joel@joellee.org>",
@@ -20,7 +20,7 @@ isort = "^5.12.0"
20
20
  pre-commit = ">=3.4,<5.0"
21
21
  pyjwt = "^2.8.0"
22
22
  pytest = ">=7.4.2,<9.0.0"
23
- pytest-cov = ">=4,<6"
23
+ pytest-cov = ">=4,<7"
24
24
  unasync-cli = "^0.0.9"
25
25
  pytest-asyncio = ">=0.21.1,<0.25.0"
26
26
  respx = ">=0.20.2,<0.22.0"
@@ -3,7 +3,7 @@ from typing import Any, Dict, Literal, Optional, Union
3
3
  from httpx import HTTPError, Response
4
4
 
5
5
  from ..errors import FunctionsHttpError, FunctionsRelayError
6
- from ..utils import AsyncClient
6
+ from ..utils import AsyncClient, is_http_url, is_valid_jwt, is_valid_str_arg
7
7
  from ..version import __version__
8
8
 
9
9
 
@@ -16,6 +16,8 @@ class AsyncFunctionsClient:
16
16
  verify: bool = True,
17
17
  proxy: Optional[str] = None,
18
18
  ):
19
+ if not is_http_url(url):
20
+ ValueError("url must be a valid HTTP URL string")
19
21
  self.url = url
20
22
  self.headers = {
21
23
  "User-Agent": f"supabase-py/functions-py v{__version__}",
@@ -25,7 +27,7 @@ class AsyncFunctionsClient:
25
27
  base_url=self.url,
26
28
  headers=self.headers,
27
29
  verify=bool(verify),
28
- timeout=timeout,
30
+ timeout=int(abs(timeout)),
29
31
  proxy=proxy,
30
32
  follow_redirects=True,
31
33
  http2=True,
@@ -58,6 +60,9 @@ class AsyncFunctionsClient:
58
60
  the new jwt token sent in the authorization header
59
61
  """
60
62
 
63
+ if not is_valid_jwt(token):
64
+ ValueError("token must be a valid JWT authorization token string.")
65
+
61
66
  self.headers["Authorization"] = f"Bearer {token}"
62
67
 
63
68
  async def invoke(
@@ -73,6 +78,8 @@ class AsyncFunctionsClient:
73
78
  `body`: the body of the request
74
79
  `responseType`: how the response should be parsed. The default is `json`
75
80
  """
81
+ if not is_valid_str_arg(function_name):
82
+ raise ValueError("function_name must a valid string value.")
76
83
  headers = self.headers
77
84
  body = None
78
85
  response_type = "text/plain"
@@ -3,7 +3,7 @@ from typing import Any, Dict, Literal, Optional, Union
3
3
  from httpx import HTTPError, Response
4
4
 
5
5
  from ..errors import FunctionsHttpError, FunctionsRelayError
6
- from ..utils import SyncClient
6
+ from ..utils import SyncClient, is_http_url, is_valid_jwt, is_valid_str_arg
7
7
  from ..version import __version__
8
8
 
9
9
 
@@ -16,6 +16,8 @@ class SyncFunctionsClient:
16
16
  verify: bool = True,
17
17
  proxy: Optional[str] = None,
18
18
  ):
19
+ if not is_http_url(url):
20
+ ValueError("url must be a valid HTTP URL string")
19
21
  self.url = url
20
22
  self.headers = {
21
23
  "User-Agent": f"supabase-py/functions-py v{__version__}",
@@ -25,7 +27,7 @@ class SyncFunctionsClient:
25
27
  base_url=self.url,
26
28
  headers=self.headers,
27
29
  verify=bool(verify),
28
- timeout=timeout,
30
+ timeout=int(abs(timeout)),
29
31
  proxy=proxy,
30
32
  follow_redirects=True,
31
33
  http2=True,
@@ -58,6 +60,9 @@ class SyncFunctionsClient:
58
60
  the new jwt token sent in the authorization header
59
61
  """
60
62
 
63
+ if not is_valid_jwt(token):
64
+ ValueError("token must be a valid JWT authorization token string.")
65
+
61
66
  self.headers["Authorization"] = f"Bearer {token}"
62
67
 
63
68
  def invoke(
@@ -73,6 +78,8 @@ class SyncFunctionsClient:
73
78
  `body`: the body of the request
74
79
  `responseType`: how the response should be parsed. The default is `json`
75
80
  """
81
+ if not is_valid_str_arg(function_name):
82
+ raise ValueError("function_name must a valid string value.")
76
83
  headers = self.headers
77
84
  body = None
78
85
  response_type = "text/plain"
@@ -0,0 +1,44 @@
1
+ import re
2
+ from urllib.parse import urlparse
3
+
4
+ from httpx import AsyncClient as AsyncClient # noqa: F401
5
+ from httpx import Client as BaseClient
6
+
7
+ DEFAULT_FUNCTION_CLIENT_TIMEOUT = 5
8
+ BASE64URL_REGEX = r"^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}$|[a-z0-9_-]{2}$)$"
9
+
10
+
11
+ class SyncClient(BaseClient):
12
+ def aclose(self) -> None:
13
+ self.close()
14
+
15
+
16
+ def is_valid_str_arg(target: str) -> bool:
17
+ return isinstance(target, str) and len(target.strip()) > 0
18
+
19
+
20
+ def is_http_url(url: str) -> bool:
21
+ return urlparse(url).scheme in {"https", "http"}
22
+
23
+
24
+ def is_valid_jwt(value: str) -> bool:
25
+ """Checks if value looks like a JWT, does not do any extra parsing."""
26
+ if not isinstance(value, str):
27
+ return False
28
+
29
+ # Remove trailing whitespaces if any.
30
+ value = value.strip()
31
+
32
+ # Remove "Bearer " prefix if any.
33
+ if value.startswith("Bearer "):
34
+ value = value[7:]
35
+
36
+ # Valid JWT must have 2 dots (Header.Paylod.Signature)
37
+ if value.count(".") != 2:
38
+ return False
39
+
40
+ for part in value.split("."):
41
+ if not re.search(BASE64URL_REGEX, part, re.IGNORECASE):
42
+ return False
43
+
44
+ return True
@@ -0,0 +1 @@
1
+ __version__ = "0.8.0" # {x-release-please-version}
@@ -1,9 +0,0 @@
1
- from httpx import AsyncClient as AsyncClient # noqa: F401
2
- from httpx import Client as BaseClient
3
-
4
- DEFAULT_FUNCTION_CLIENT_TIMEOUT = 5
5
-
6
-
7
- class SyncClient(BaseClient):
8
- def aclose(self) -> None:
9
- self.close()
@@ -1 +0,0 @@
1
- __version__ = "0.6.2" # {x-release-please-version}