Skip to content

Commit

Permalink
merges with latest
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Sep 25, 2024
2 parents 36eaa1f + acabab0 commit 446534b
Show file tree
Hide file tree
Showing 13 changed files with 287 additions and 89 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/pre-commit-hook-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ jobs:
pr-title:
name: Pre commit hook check
runs-on: ubuntu-latest
container: rishabhpoddar/supertokens_python_driver_testing
steps:
- uses: actions/checkout@v2
- name: Set up node
uses: actions/setup-node@v1
with:
node-version: '12'
- name: Create virtual environment and install dependencies
run: |
python3 -m venv venv
source venv/bin/activate
pip install "cython<3.0.0" wheel
pip install "PyYAML==5.4.1" --no-build-isolation
make dev-install && rm -rf src
- name: Make a dummy change to README.md
run: |
echo "# Dummy change for PR check" >> README.md
- run: git init && git add --all && git -c user.name='test' -c user.email='[email protected]' commit -m 'init for pr action'
- run: make dev-install && rm -rf src
- run: ./hooks/pre-commit.sh
- run: |
source venv/bin/activate
./hooks/pre-commit.sh
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

<<<<<<< HEAD
## [0.25.0] - 2024-09-18

### Breaking changes
Expand All @@ -17,6 +18,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Session recipe's error handlers take an extra param of recipe_user_id as well
- Session recipe, removes `validate_claims_in_jwt_payload` that is exposed to the user.
- TODO..
=======
## [0.24.3] - 2024-09-24

- Adds support for form field related improvements by making fields accept any type of values
- Adds support for optional fields to properly optional
>>>>>>> 0.24
## [0.24.2] - 2024-09-03
- Makes optional input form fields truly optional instead of just being able to accept `""`.
Expand Down
2 changes: 1 addition & 1 deletion html/supertokens_python/constants.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h1 class="title">Module <code>supertokens_python.constants</code></h1>
from __future__ import annotations

SUPPORTED_CDI_VERSIONS = [&#34;3.0&#34;]
VERSION = &#34;0.24.2&#34;
VERSION = &#34;0.24.3&#34;
TELEMETRY = &#34;/telemetry&#34;
USER_COUNT = &#34;/users/count&#34;
USER_DELETE = &#34;/user/remove&#34;
Expand Down
35 changes: 32 additions & 3 deletions html/supertokens_python/recipe/emailpassword/api/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ <h1 class="title">Module <code>supertokens_python.recipe.emailpassword.api.utils
from typing import Any, Dict, List, Union

from supertokens_python.exceptions import raise_bad_input_exception
from supertokens_python.recipe.emailpassword.constants import FORM_FIELD_EMAIL_ID
from supertokens_python.recipe.emailpassword.constants import (
FORM_FIELD_EMAIL_ID,
FORM_FIELD_PASSWORD_ID,
)
from supertokens_python.recipe.emailpassword.exceptions import (
raise_form_field_exception,
)
Expand All @@ -69,7 +72,9 @@ <h1 class="title">Module <code>supertokens_python.recipe.emailpassword.api.utils
input_field: Union[None, FormField] = find_first_occurrence_in_list(
lambda x: x.id == field.id, inputs
)
is_invalid_value = input_field is None or input_field.value == &#34;&#34;
is_invalid_value = input_field is None or (
isinstance(input_field.value, str) and input_field.value == &#34;&#34;
)
if not field.optional and is_invalid_value:
validation_errors.append(ErrorFormField(field.id, &#34;Field is not optional&#34;))
continue
Expand Down Expand Up @@ -111,7 +116,18 @@ <h1 class="title">Module <code>supertokens_python.recipe.emailpassword.api.utils
raise_bad_input_exception(
&#34;All elements of formFields must contain an &#39;id&#39; and &#39;value&#39; field&#34;
)

value = current_form_field[&#34;value&#34;]
if current_form_field[&#34;id&#34;] in [
FORM_FIELD_EMAIL_ID,
FORM_FIELD_PASSWORD_ID,
] and not isinstance(value, str):
# Ensure that the type is string else we will throw a bad input
# error.
raise_bad_input_exception(
f&#34;{current_form_field[&#39;id&#39;]} value must be a string&#34;
)

if current_form_field[&#34;id&#34;] == FORM_FIELD_EMAIL_ID and isinstance(value, str):
value = value.strip()
form_fields.append(FormField(current_form_field[&#34;id&#34;], value))
Expand Down Expand Up @@ -157,7 +173,18 @@ <h2 class="section-title" id="header-functions">Functions</h2>
raise_bad_input_exception(
&#34;All elements of formFields must contain an &#39;id&#39; and &#39;value&#39; field&#34;
)

value = current_form_field[&#34;value&#34;]
if current_form_field[&#34;id&#34;] in [
FORM_FIELD_EMAIL_ID,
FORM_FIELD_PASSWORD_ID,
] and not isinstance(value, str):
# Ensure that the type is string else we will throw a bad input
# error.
raise_bad_input_exception(
f&#34;{current_form_field[&#39;id&#39;]} value must be a string&#34;
)

if current_form_field[&#34;id&#34;] == FORM_FIELD_EMAIL_ID and isinstance(value, str):
value = value.strip()
form_fields.append(FormField(current_form_field[&#34;id&#34;], value))
Expand Down Expand Up @@ -188,7 +215,9 @@ <h2 class="section-title" id="header-functions">Functions</h2>
input_field: Union[None, FormField] = find_first_occurrence_in_list(
lambda x: x.id == field.id, inputs
)
is_invalid_value = input_field is None or input_field.value == &#34;&#34;
is_invalid_value = input_field is None or (
isinstance(input_field.value, str) and input_field.value == &#34;&#34;
)
if not field.optional and is_invalid_value:
validation_errors.append(ErrorFormField(field.id, &#34;Field is not optional&#34;))
continue
Expand Down
13 changes: 7 additions & 6 deletions html/supertokens_python/recipe/emailpassword/types.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ <h1 class="title">Module <code>supertokens_python.recipe.emailpassword.types</co
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import annotations
from typing import Awaitable, Callable, List, TypeVar, Union

from typing import Any, Awaitable, Callable, List, TypeVar, Union

from supertokens_python.ingredients.emaildelivery import EmailDeliveryIngredient
from supertokens_python.ingredients.emaildelivery.types import (
Expand Down Expand Up @@ -81,9 +82,9 @@ <h1 class="title">Module <code>supertokens_python.recipe.emailpassword.types</co


class FormField:
def __init__(self, id: str, value: str): # pylint: disable=redefined-builtin
def __init__(self, id: str, value: Any): # pylint: disable=redefined-builtin
self.id: str = id
self.value: str = value
self.value: Any = value


class InputFormField:
Expand Down Expand Up @@ -197,7 +198,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
</dd>
<dt id="supertokens_python.recipe.emailpassword.types.FormField"><code class="flex name class">
<span>class <span class="ident">FormField</span></span>
<span>(</span><span>id: str, value: str)</span>
<span>(</span><span>id: str, value: Any)</span>
</code></dt>
<dd>
<div class="desc"></div>
Expand All @@ -206,9 +207,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
<span>Expand source code</span>
</summary>
<pre><code class="python">class FormField:
def __init__(self, id: str, value: str): # pylint: disable=redefined-builtin
def __init__(self, id: str, value: Any): # pylint: disable=redefined-builtin
self.id: str = id
self.value: str = value</code></pre>
self.value: Any = value</code></pre>
</details>
</dd>
<dt id="supertokens_python.recipe.emailpassword.types.InputFormField"><code class="flex name class">
Expand Down
25 changes: 8 additions & 17 deletions html/supertokens_python/recipe/emailpassword/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ <h1 class="title">Module <code>supertokens_python.recipe.emailpassword.utils</co
from __future__ import annotations

from re import fullmatch
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Union, Dict
from supertokens_python.framework import BaseRequest
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union

from supertokens_python.framework import BaseRequest
from supertokens_python.ingredients.emaildelivery.types import (
EmailDeliveryConfig,
EmailDeliveryConfigWithService,
Expand All @@ -54,17 +54,14 @@ <h1 class="title">Module <code>supertokens_python.recipe.emailpassword.utils</co
)

from .interfaces import APIInterface, RecipeInterface
from .types import InputFormField, NormalisedFormField, EmailTemplateVars
from .types import EmailTemplateVars, InputFormField, NormalisedFormField

if TYPE_CHECKING:
from supertokens_python.supertokens import AppInfo

from supertokens_python.utils import get_filtered_list

from .constants import (
FORM_FIELD_EMAIL_ID,
FORM_FIELD_PASSWORD_ID,
)
from .constants import FORM_FIELD_EMAIL_ID, FORM_FIELD_PASSWORD_ID


async def default_validator(_: str, __: str) -&gt; Union[str, None]:
Expand Down Expand Up @@ -289,11 +286,8 @@ <h1 class="title">Module <code>supertokens_python.recipe.emailpassword.utils</co
email_delivery: Union[EmailDeliveryConfig[EmailTemplateVars], None] = None,
) -&gt; EmailPasswordConfig:

if sign_up_feature is not None and not isinstance(sign_up_feature, InputSignUpFeature): # type: ignore
raise ValueError(&#34;sign_up_feature must be of type InputSignUpFeature or None&#34;)

if override is not None and not isinstance(override, InputOverrideConfig): # type: ignore
raise ValueError(&#34;override must be of type InputOverrideConfig or None&#34;)
# NOTE: We don&#39;t need to check the instance of sign_up_feature and override
# as they will always be either None or the specified type.

if override is None:
override = InputOverrideConfig()
Expand Down Expand Up @@ -607,11 +601,8 @@ <h2 class="section-title" id="header-functions">Functions</h2>
email_delivery: Union[EmailDeliveryConfig[EmailTemplateVars], None] = None,
) -&gt; EmailPasswordConfig:

if sign_up_feature is not None and not isinstance(sign_up_feature, InputSignUpFeature): # type: ignore
raise ValueError(&#34;sign_up_feature must be of type InputSignUpFeature or None&#34;)

if override is not None and not isinstance(override, InputOverrideConfig): # type: ignore
raise ValueError(&#34;override must be of type InputOverrideConfig or None&#34;)
# NOTE: We don&#39;t need to check the instance of sign_up_feature and override
# as they will always be either None or the specified type.

if override is None:
override = InputOverrideConfig()
Expand Down
20 changes: 18 additions & 2 deletions supertokens_python/recipe/emailpassword/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
from typing import Any, Dict, List, Union

from supertokens_python.exceptions import raise_bad_input_exception
from supertokens_python.recipe.emailpassword.constants import FORM_FIELD_EMAIL_ID
from supertokens_python.recipe.emailpassword.constants import (
FORM_FIELD_EMAIL_ID,
FORM_FIELD_PASSWORD_ID,
)
from supertokens_python.recipe.emailpassword.exceptions import (
raise_form_field_exception,
)
Expand All @@ -41,7 +44,9 @@ async def validate_form_or_throw_error(
input_field: Union[None, FormField] = find_first_occurrence_in_list(
lambda x: x.id == field.id, inputs
)
is_invalid_value = input_field is None or input_field.value == ""
is_invalid_value = input_field is None or (
isinstance(input_field.value, str) and input_field.value == ""
)
if not field.optional and is_invalid_value:
validation_errors.append(ErrorFormField(field.id, "Field is not optional"))
continue
Expand Down Expand Up @@ -83,7 +88,18 @@ async def validate_form_fields_or_throw_error(
raise_bad_input_exception(
"All elements of formFields must contain an 'id' and 'value' field"
)

value = current_form_field["value"]
if current_form_field["id"] in [
FORM_FIELD_EMAIL_ID,
FORM_FIELD_PASSWORD_ID,
] and not isinstance(value, str):
# Ensure that the type is string else we will throw a bad input
# error.
raise_bad_input_exception(
f"{current_form_field['id']} value must be a string"
)

if current_form_field["id"] == FORM_FIELD_EMAIL_ID and isinstance(value, str):
value = value.strip()
form_fields.append(FormField(current_form_field["id"], value))
Expand Down
6 changes: 3 additions & 3 deletions supertokens_python/recipe/emailpassword/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import annotations
from typing import Awaitable, Callable, Optional, TypeVar, Union
from typing import Awaitable, Callable, Optional, TypeVar, Union, Any

from supertokens_python.ingredients.emaildelivery import EmailDeliveryIngredient
from supertokens_python.ingredients.emaildelivery.types import (
Expand All @@ -29,9 +29,9 @@ def __init__(self, id: str, error: str): # pylint: disable=redefined-builtin


class FormField:
def __init__(self, id: str, value: str): # pylint: disable=redefined-builtin
def __init__(self, id: str, value: Any): # pylint: disable=redefined-builtin
self.id: str = id
self.value: str = value
self.value: Any = value


class InputFormField:
Expand Down
18 changes: 6 additions & 12 deletions supertokens_python/recipe/emailpassword/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from __future__ import annotations

from re import fullmatch
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Union, Dict
from supertokens_python.framework import BaseRequest
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union

from supertokens_python.framework import BaseRequest
from supertokens_python.ingredients.emaildelivery.types import (
EmailDeliveryConfig,
EmailDeliveryConfigWithService,
Expand All @@ -26,17 +26,14 @@
)

from .interfaces import APIInterface, RecipeInterface
from .types import InputFormField, NormalisedFormField, EmailTemplateVars
from .types import EmailTemplateVars, InputFormField, NormalisedFormField

if TYPE_CHECKING:
from supertokens_python.supertokens import AppInfo

from supertokens_python.utils import get_filtered_list

from .constants import (
FORM_FIELD_EMAIL_ID,
FORM_FIELD_PASSWORD_ID,
)
from .constants import FORM_FIELD_EMAIL_ID, FORM_FIELD_PASSWORD_ID


async def default_validator(_: str, __: str) -> Union[str, None]:
Expand Down Expand Up @@ -261,11 +258,8 @@ def validate_and_normalise_user_input(
email_delivery: Union[EmailDeliveryConfig[EmailTemplateVars], None] = None,
) -> EmailPasswordConfig:

if sign_up_feature is not None and not isinstance(sign_up_feature, InputSignUpFeature): # type: ignore
raise ValueError("sign_up_feature must be of type InputSignUpFeature or None")

if override is not None and not isinstance(override, InputOverrideConfig): # type: ignore
raise ValueError("override must be of type InputOverrideConfig or None")
# NOTE: We don't need to check the instance of sign_up_feature and override
# as they will always be either None or the specified type.

if override is None:
override = InputOverrideConfig()
Expand Down
Loading

0 comments on commit 446534b

Please sign in to comment.