Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rewrite enumerated literals as Enums #633

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
108 changes: 62 additions & 46 deletions supabase_auth/types.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,48 +25,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",
juancarlospaco marked this conversation as resolved.
Show resolved Hide resolved
]

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 = "MFA_CHALLENGE_VERIFIED"


class AMREntry(BaseModel):
Expand Down Expand Up @@ -510,14 +524,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):
Expand Down Expand Up @@ -782,7 +795,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):
Expand Down