From 37257b1bbb9d74a5e433652a16bf64ce776fe719 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Tue, 26 Nov 2024 13:21:16 -0300 Subject: [PATCH 01/10] feat: rewriting enumerated literals as Enums --- supabase_auth/types.py | 109 ++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 46 deletions(-) diff --git a/supabase_auth/types.py b/supabase_auth/types.py index 86bda3e2..2b695463 100644 --- a/supabase_auth/types.py +++ b/supabase_auth/types.py @@ -1,11 +1,18 @@ from __future__ import annotations +import sys + from datetime import datetime from time import time from typing import Any, Callable, Dict, List, Optional, Union from pydantic import BaseModel, ConfigDict +if sys.version_info >= (3, 11): + from enum import StrEnum +else: + from strenum import StrEnum + try: # > 2 from pydantic import model_validator @@ -19,48 +26,56 @@ from typing_extensions import Literal, NotRequired, TypedDict -Provider = Literal[ - "apple", - "azure", - "bitbucket", - "discord", - "facebook", - "figma", - "fly", - "github", - "gitlab", - "google", - "kakao", - "keycloak", - "linkedin", - "linkedin_oidc", - "notion", - "slack", - "slack_oidc", - "spotify", - "twitch", - "twitter", - "workos", - "zoom", -] -EmailOtpType = Literal[ - "signup", "invite", "magiclink", "recovery", "email_change", "email" -] +class Provider(StrEnum): + Apple = "apple" + Azure = "azure" + Bitbucket = "bitbucket" + Discord = "discord" + Facebook = "facebook" + Figman = "figma" + Fly = "fly" + Github = "github" + Gitlab = "gitlab" + Google = "google" + Kakao = "kakao" + Keycloak = "keycloak" + Linkedin = "linkedin" + Linkedin_oidc = "linkedin_oidc" + Notion = "notion" + Slack = "slack" + Slack_oidc = "slack_oidc" + Spotify = "spotify" + Twitch = "twitch" + Twitter = "twitter" + Workos = "workos" + + +class EmailOtpType(StrEnum): + Signup = "signup" + Invite = "invite" + Magiclink = "magiclink" + Recovery = "recovery" + Email_change = "email_change" + Email = "email" + AuthChangeEventMFA = Literal["MFA_CHALLENGE_VERIFIED"] -AuthFlowType = Literal["pkce", "implicit"] -AuthChangeEvent = Literal[ - "PASSWORD_RECOVERY", - "SIGNED_IN", - "SIGNED_OUT", - "TOKEN_REFRESHED", - "USER_UPDATED", - "USER_DELETED", - AuthChangeEventMFA, -] +class AuthFlowType(StrEnum): + Pkce = "pkce" + Implicit = "implicit" + + +class AuthChangeEvent(StrEnum): + Password_Recovery = "PASSWORD_RECOVERY" + Signed_in = "SIGNED_IN" + Signed_out = "SIGNED_OUT" + Token_refreshed = "TOKEN_REFRESHED" + User_updated = "USER_UPDATED" + User_deleted = "USER_DELETED" + AuthChangeEventMFA = AuthChangeEventMFA class AMREntry(BaseModel): @@ -510,14 +525,13 @@ class GenerateEmailChangeLinkParams(TypedDict): GenerateEmailChangeLinkParams, ] -GenerateLinkType = Literal[ - "signup", - "invite", - "magiclink", - "recovery", - "email_change_current", - "email_change_new", -] + +class GenerateLinkType(StrEnum): + Signup = "signup" + Invite = "invite" + Magiclink = "magiclink" + Recovery = "recovery" + EmailChangeCurrent = "email_change_current" class MFAEnrollParams(TypedDict): @@ -782,7 +796,10 @@ class DecodedJWTDict(TypedDict): amr: NotRequired[Optional[List[AMREntry]]] -SignOutScope = Literal["global", "local", "others"] +class SignOutScope(StrEnum): + Global = "global" + Local = "local" + Others = "others" class SignOutOptions(TypedDict): From a1ee364d0108f354c225d6767c517092e7c29751 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Tue, 26 Nov 2024 13:21:45 -0300 Subject: [PATCH 02/10] feat: rewriting enumerated literals as Enums --- supabase_auth/types.py | 75 +++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/supabase_auth/types.py b/supabase_auth/types.py index 2b695463..386a467a 100644 --- a/supabase_auth/types.py +++ b/supabase_auth/types.py @@ -1,7 +1,6 @@ from __future__ import annotations import sys - from datetime import datetime from time import time from typing import Any, Callable, Dict, List, Optional, Union @@ -28,53 +27,53 @@ class Provider(StrEnum): - Apple = "apple" - Azure = "azure" - Bitbucket = "bitbucket" - Discord = "discord" - Facebook = "facebook" - Figman = "figma" - Fly = "fly" - Github = "github" - Gitlab = "gitlab" - Google = "google" - Kakao = "kakao" - Keycloak = "keycloak" - Linkedin = "linkedin" + Apple = "apple" + Azure = "azure" + Bitbucket = "bitbucket" + Discord = "discord" + Facebook = "facebook" + Figman = "figma" + Fly = "fly" + Github = "github" + Gitlab = "gitlab" + Google = "google" + Kakao = "kakao" + Keycloak = "keycloak" + Linkedin = "linkedin" Linkedin_oidc = "linkedin_oidc" - Notion = "notion" - Slack = "slack" - Slack_oidc = "slack_oidc" - Spotify = "spotify" - Twitch = "twitch" - Twitter = "twitter" - Workos = "workos" + Notion = "notion" + Slack = "slack" + Slack_oidc = "slack_oidc" + Spotify = "spotify" + Twitch = "twitch" + Twitter = "twitter" + Workos = "workos" class EmailOtpType(StrEnum): - Signup = "signup" - Invite = "invite" - Magiclink = "magiclink" - Recovery = "recovery" + Signup = "signup" + Invite = "invite" + Magiclink = "magiclink" + Recovery = "recovery" Email_change = "email_change" - Email = "email" + Email = "email" AuthChangeEventMFA = Literal["MFA_CHALLENGE_VERIFIED"] class AuthFlowType(StrEnum): - Pkce = "pkce" + Pkce = "pkce" Implicit = "implicit" class AuthChangeEvent(StrEnum): - Password_Recovery = "PASSWORD_RECOVERY" - Signed_in = "SIGNED_IN" - Signed_out = "SIGNED_OUT" - Token_refreshed = "TOKEN_REFRESHED" - User_updated = "USER_UPDATED" - User_deleted = "USER_DELETED" + Password_Recovery = "PASSWORD_RECOVERY" + Signed_in = "SIGNED_IN" + Signed_out = "SIGNED_OUT" + Token_refreshed = "TOKEN_REFRESHED" + User_updated = "USER_UPDATED" + User_deleted = "USER_DELETED" AuthChangeEventMFA = AuthChangeEventMFA @@ -527,10 +526,10 @@ class GenerateEmailChangeLinkParams(TypedDict): class GenerateLinkType(StrEnum): - Signup = "signup" - Invite = "invite" - Magiclink = "magiclink" - Recovery = "recovery" + Signup = "signup" + Invite = "invite" + Magiclink = "magiclink" + Recovery = "recovery" EmailChangeCurrent = "email_change_current" @@ -798,7 +797,7 @@ class DecodedJWTDict(TypedDict): class SignOutScope(StrEnum): Global = "global" - Local = "local" + Local = "local" Others = "others" From 2b7c5eb2f29a6da9635f4713500c13ce64811131 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Tue, 26 Nov 2024 13:35:30 -0300 Subject: [PATCH 03/10] feat: rewriting enumerated literals as Enums --- supabase_auth/types.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/supabase_auth/types.py b/supabase_auth/types.py index 386a467a..2193d032 100644 --- a/supabase_auth/types.py +++ b/supabase_auth/types.py @@ -26,7 +26,7 @@ from typing_extensions import Literal, NotRequired, TypedDict -class Provider(StrEnum): +class Provider(StrEnum, str): Apple = "apple" Azure = "azure" Bitbucket = "bitbucket" @@ -50,7 +50,7 @@ class Provider(StrEnum): Workos = "workos" -class EmailOtpType(StrEnum): +class EmailOtpType(StrEnum, str): Signup = "signup" Invite = "invite" Magiclink = "magiclink" @@ -62,12 +62,12 @@ class EmailOtpType(StrEnum): AuthChangeEventMFA = Literal["MFA_CHALLENGE_VERIFIED"] -class AuthFlowType(StrEnum): +class AuthFlowType(StrEnum, str): Pkce = "pkce" Implicit = "implicit" -class AuthChangeEvent(StrEnum): +class AuthChangeEvent(StrEnum, str): Password_Recovery = "PASSWORD_RECOVERY" Signed_in = "SIGNED_IN" Signed_out = "SIGNED_OUT" @@ -525,7 +525,7 @@ class GenerateEmailChangeLinkParams(TypedDict): ] -class GenerateLinkType(StrEnum): +class GenerateLinkType(StrEnum, str): Signup = "signup" Invite = "invite" Magiclink = "magiclink" @@ -795,7 +795,7 @@ class DecodedJWTDict(TypedDict): amr: NotRequired[Optional[List[AMREntry]]] -class SignOutScope(StrEnum): +class SignOutScope(StrEnum, str): Global = "global" Local = "local" Others = "others" From b609d34a6275a3bb6f1d8265bf18f9cf9b54ee39 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Tue, 26 Nov 2024 13:40:05 -0300 Subject: [PATCH 04/10] feat: rewriting enumerated literals as Enums --- supabase_auth/types.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/supabase_auth/types.py b/supabase_auth/types.py index 2193d032..386a467a 100644 --- a/supabase_auth/types.py +++ b/supabase_auth/types.py @@ -26,7 +26,7 @@ from typing_extensions import Literal, NotRequired, TypedDict -class Provider(StrEnum, str): +class Provider(StrEnum): Apple = "apple" Azure = "azure" Bitbucket = "bitbucket" @@ -50,7 +50,7 @@ class Provider(StrEnum, str): Workos = "workos" -class EmailOtpType(StrEnum, str): +class EmailOtpType(StrEnum): Signup = "signup" Invite = "invite" Magiclink = "magiclink" @@ -62,12 +62,12 @@ class EmailOtpType(StrEnum, str): AuthChangeEventMFA = Literal["MFA_CHALLENGE_VERIFIED"] -class AuthFlowType(StrEnum, str): +class AuthFlowType(StrEnum): Pkce = "pkce" Implicit = "implicit" -class AuthChangeEvent(StrEnum, str): +class AuthChangeEvent(StrEnum): Password_Recovery = "PASSWORD_RECOVERY" Signed_in = "SIGNED_IN" Signed_out = "SIGNED_OUT" @@ -525,7 +525,7 @@ class GenerateEmailChangeLinkParams(TypedDict): ] -class GenerateLinkType(StrEnum, str): +class GenerateLinkType(StrEnum): Signup = "signup" Invite = "invite" Magiclink = "magiclink" @@ -795,7 +795,7 @@ class DecodedJWTDict(TypedDict): amr: NotRequired[Optional[List[AMREntry]]] -class SignOutScope(StrEnum, str): +class SignOutScope(StrEnum): Global = "global" Local = "local" Others = "others" From 10a2943f71954c2afa9edbbb9d6d7ea4546d8ba6 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Tue, 26 Nov 2024 18:06:09 -0300 Subject: [PATCH 05/10] feat: rewriting str as Enums --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 37e46d37..455ee0df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,7 @@ classifiers = [ [tool.poetry.dependencies] python = "^3.9" httpx = {version = ">=0.26,<0.28", extras = ["http2"]} +strenum = "^0.4.15" pydantic = ">=1.10,<3" [tool.poetry.dev-dependencies] From 4a4036fb5152eedb6bcddcf9592d863c1992e179 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Tue, 26 Nov 2024 18:06:13 -0300 Subject: [PATCH 06/10] feat: rewriting str as Enums --- poetry.lock | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/poetry.lock b/poetry.lock index 88bc250a..527a5b1d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "annotated-types" @@ -1271,6 +1271,22 @@ files = [ {file = "sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc"}, ] +[[package]] +name = "strenum" +version = "0.4.15" +description = "An Enum that inherits from str." +optional = false +python-versions = "*" +files = [ + {file = "StrEnum-0.4.15-py3-none-any.whl", hash = "sha256:a30cda4af7cc6b5bf52c8055bc4bf4b2b6b14a93b574626da33df53cf7740659"}, + {file = "StrEnum-0.4.15.tar.gz", hash = "sha256:878fb5ab705442070e4dd1929bb5e2249511c0bcf2b0eeacf3bcd80875c82eff"}, +] + +[package.extras] +docs = ["myst-parser[linkify]", "sphinx", "sphinx-rtd-theme"] +release = ["twine"] +test = ["pylint", "pytest", "pytest-black", "pytest-cov", "pytest-pylint"] + [[package]] name = "tomli" version = "2.0.2" @@ -1459,4 +1475,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "4afe910b8aa228db43554e76e9cf058b7f0db1fe88ca3244d68dcb9f73be7f0a" +content-hash = "7533d0d8a225fdf22f692ec81fc4efac36967d9268f91284534545899a62f769" From 3f002b895e22b9096e892a6e8e0036329a236681 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Tue, 26 Nov 2024 18:14:18 -0300 Subject: [PATCH 07/10] feat: rewriting str as Enums --- supabase_auth/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supabase_auth/types.py b/supabase_auth/types.py index 386a467a..407c14e6 100644 --- a/supabase_auth/types.py +++ b/supabase_auth/types.py @@ -74,7 +74,7 @@ class AuthChangeEvent(StrEnum): Token_refreshed = "TOKEN_REFRESHED" User_updated = "USER_UPDATED" User_deleted = "USER_DELETED" - AuthChangeEventMFA = AuthChangeEventMFA + AuthChangeEventMFA = "MFA_CHALLENGE_VERIFIED" class AMREntry(BaseModel): From 1cc92804c38ba72d375a66f4cbc3d6d860d17b8e Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Wed, 27 Nov 2024 18:57:30 -0300 Subject: [PATCH 08/10] fix: Add missing enum constant --- supabase_auth/types.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/supabase_auth/types.py b/supabase_auth/types.py index 407c14e6..8f5da564 100644 --- a/supabase_auth/types.py +++ b/supabase_auth/types.py @@ -48,6 +48,7 @@ class Provider(StrEnum): Twitch = "twitch" Twitter = "twitter" Workos = "workos" + Zoom = "zoom" class EmailOtpType(StrEnum): @@ -531,6 +532,7 @@ class GenerateLinkType(StrEnum): Magiclink = "magiclink" Recovery = "recovery" EmailChangeCurrent = "email_change_current" + EmailChangeNew = "email_change_new" class MFAEnrollParams(TypedDict): From 942f3e87c4d7cfcfec190b7d0cb70fa85cbcf31a Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Fri, 13 Dec 2024 14:04:15 -0300 Subject: [PATCH 09/10] Update supabase_auth/types.py Co-authored-by: Joel Lee --- supabase_auth/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supabase_auth/types.py b/supabase_auth/types.py index 8f5da564..e53bf770 100644 --- a/supabase_auth/types.py +++ b/supabase_auth/types.py @@ -32,7 +32,7 @@ class Provider(StrEnum): Bitbucket = "bitbucket" Discord = "discord" Facebook = "facebook" - Figman = "figma" + Figma = "figma" Fly = "fly" Github = "github" Gitlab = "gitlab" From 61bfb0cb94d86aa4654eecdd0281dde642222ffc Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Fri, 13 Dec 2024 14:27:54 -0300 Subject: [PATCH 10/10] fix: update poetry lock --- poetry.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index cfc0387d..922fdcdb 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1475,4 +1475,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "1b49be078db3ecff8effb4c1e8d0fca2d939c33a2c186ae3bd3509a4830f01f9" +content-hash = "420daf08a4ba90d75c3d89f471e99fd4747fa84911528593f381687d7fdcb9af"