diff --git a/poetry.lock b/poetry.lock index fcaef973..922fdcdb 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 = "1b49be078db3ecff8effb4c1e8d0fca2d939c33a2c186ae3bd3509a4830f01f9" +content-hash = "420daf08a4ba90d75c3d89f471e99fd4747fa84911528593f381687d7fdcb9af" diff --git a/pyproject.toml b/pyproject.toml index eb2b1e6f..76db6b38 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] diff --git a/supabase_auth/types.py b/supabase_auth/types.py index 86bda3e2..e53bf770 100644 --- a/supabase_auth/types.py +++ b/supabase_auth/types.py @@ -1,11 +1,17 @@ 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 +25,57 @@ 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" + Figma = "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" + Zoom = "zoom" + + +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 = "MFA_CHALLENGE_VERIFIED" class AMREntry(BaseModel): @@ -510,14 +525,14 @@ 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" + EmailChangeNew = "email_change_new" class MFAEnrollParams(TypedDict): @@ -782,7 +797,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):