|
10 | 10 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
11 | 11 | # License for the specific language governing permissions and limitations
|
12 | 12 | # under the License.
|
13 |
| -from typing import Any, Dict, Union, Optional |
14 |
| - |
15 |
| -from supertokens_python.recipe.emailverification.interfaces import ( |
16 |
| - GetEmailForUserIdOkResult, |
17 |
| - EmailDoesNotExistError, |
18 |
| - CreateEmailVerificationTokenEmailAlreadyVerifiedError, |
19 |
| - UnverifyEmailOkResult, |
20 |
| - CreateEmailVerificationTokenOkResult, |
21 |
| - RevokeEmailVerificationTokensOkResult, |
| 13 | +from __future__ import annotations |
| 14 | + |
| 15 | +from typing import Any, Dict, Union, Optional, TYPE_CHECKING |
| 16 | + |
| 17 | +from ..interfaces import ( |
| 18 | + TenantConfig, |
| 19 | + CreateOrUpdateTenantOkResult, |
| 20 | + DeleteTenantOkResult, |
| 21 | + GetTenantOkResult, |
| 22 | + ListAllTenantsOkResult, |
| 23 | + CreateOrUpdateThirdPartyConfigOkResult, |
| 24 | + DeleteThirdPartyConfigOkResult, |
| 25 | + AssociateUserToTenantOkResult, |
| 26 | + AssociateUserToTenantUnknownUserIdError, |
| 27 | + AssociateUserToTenantEmailAlreadyExistsError, |
| 28 | + AssociateUserToTenantPhoneNumberAlreadyExistsError, |
| 29 | + AssociateUserToTenantThirdPartyUserAlreadyExistsError, |
| 30 | + DisassociateUserFromTenantOkResult, |
22 | 31 | )
|
23 |
| -from supertokens_python.recipe.emailverification.types import EmailTemplateVars |
24 |
| -from supertokens_python.recipe.emailverification.recipe import EmailVerificationRecipe |
| 32 | +from ..recipe import MultitenancyRecipe |
25 | 33 |
|
| 34 | +if TYPE_CHECKING: |
| 35 | + from ..interfaces import ProviderConfig |
26 | 36 |
|
27 |
| -async def create_email_verification_token( |
28 |
| - user_id: str, |
29 |
| - email: Optional[str] = None, |
30 |
| - user_context: Union[None, Dict[str, Any]] = None, |
31 |
| -) -> Union[ |
32 |
| - CreateEmailVerificationTokenOkResult, |
33 |
| - CreateEmailVerificationTokenEmailAlreadyVerifiedError, |
34 |
| -]: |
| 37 | + |
| 38 | +async def create_or_update_tenant( |
| 39 | + tenant_id: Optional[str], |
| 40 | + config: TenantConfig, |
| 41 | + user_context: Optional[Dict[str, Any]] = None, |
| 42 | +) -> CreateOrUpdateTenantOkResult: |
35 | 43 | if user_context is None:
|
36 | 44 | user_context = {}
|
37 |
| - recipe = EmailVerificationRecipe.get_instance() |
38 |
| - if email is None: |
39 |
| - email_info = await recipe.get_email_for_user_id(user_id, user_context) |
40 |
| - if isinstance(email_info, GetEmailForUserIdOkResult): |
41 |
| - email = email_info.email |
42 |
| - elif isinstance(email_info, EmailDoesNotExistError): |
43 |
| - return CreateEmailVerificationTokenEmailAlreadyVerifiedError() |
44 |
| - else: |
45 |
| - raise Exception("Unknown User ID provided without email") |
46 |
| - |
47 |
| - return await recipe.recipe_implementation.create_email_verification_token( |
48 |
| - user_id, email, user_context |
| 45 | + recipe = MultitenancyRecipe.get_instance() |
| 46 | + |
| 47 | + return await recipe.recipe_implementation.create_or_update_tenant( |
| 48 | + tenant_id, config, user_context |
49 | 49 | )
|
50 | 50 |
|
51 | 51 |
|
52 |
| -async def verify_email_using_token( |
53 |
| - token: str, user_context: Union[None, Dict[str, Any]] = None |
54 |
| -): |
| 52 | +async def delete_tenant( |
| 53 | + tenant_id: str, user_context: Optional[Dict[str, Any]] = None |
| 54 | +) -> DeleteTenantOkResult: |
55 | 55 | if user_context is None:
|
56 | 56 | user_context = {}
|
57 |
| - return await EmailVerificationRecipe.get_instance().recipe_implementation.verify_email_using_token( |
58 |
| - token, user_context |
59 |
| - ) |
| 57 | + recipe = MultitenancyRecipe.get_instance() |
60 | 58 |
|
| 59 | + return await recipe.recipe_implementation.delete_tenant(tenant_id, user_context) |
61 | 60 |
|
62 |
| -async def is_email_verified( |
63 |
| - user_id: str, |
64 |
| - email: Optional[str] = None, |
65 |
| - user_context: Union[None, Dict[str, Any]] = None, |
66 |
| -): |
| 61 | + |
| 62 | +async def get_tenant( |
| 63 | + tenant_id: Optional[str], user_context: Optional[Dict[str, Any]] = None |
| 64 | +) -> GetTenantOkResult: |
| 65 | + if user_context is None: |
| 66 | + user_context = {} |
| 67 | + recipe = MultitenancyRecipe.get_instance() |
| 68 | + |
| 69 | + return await recipe.recipe_implementation.get_tenant(tenant_id, user_context) |
| 70 | + |
| 71 | + |
| 72 | +async def list_all_tenants( |
| 73 | + user_context: Optional[Dict[str, Any]] = None |
| 74 | +) -> ListAllTenantsOkResult: |
| 75 | + if user_context is None: |
| 76 | + user_context = {} |
| 77 | + |
| 78 | + recipe = MultitenancyRecipe.get_instance() |
| 79 | + |
| 80 | + return await recipe.recipe_implementation.list_all_tenants(user_context) |
| 81 | + |
| 82 | + |
| 83 | +async def create_or_update_third_party_config( |
| 84 | + tenant_id: Optional[str], |
| 85 | + config: ProviderConfig, |
| 86 | + skip_validation: Optional[bool] = None, |
| 87 | + user_context: Optional[Dict[str, Any]] = None, |
| 88 | +) -> CreateOrUpdateThirdPartyConfigOkResult: |
67 | 89 | if user_context is None:
|
68 | 90 | user_context = {}
|
69 | 91 |
|
70 |
| - recipe = EmailVerificationRecipe.get_instance() |
71 |
| - if email is None: |
72 |
| - email_info = await recipe.get_email_for_user_id(user_id, user_context) |
73 |
| - if isinstance(email_info, GetEmailForUserIdOkResult): |
74 |
| - email = email_info.email |
75 |
| - elif isinstance(email_info, EmailDoesNotExistError): |
76 |
| - return True |
77 |
| - else: |
78 |
| - raise Exception("Unknown User ID provided without email") |
79 |
| - |
80 |
| - return await recipe.recipe_implementation.is_email_verified( |
81 |
| - user_id, email, user_context |
| 92 | + recipe = MultitenancyRecipe.get_instance() |
| 93 | + |
| 94 | + return await recipe.recipe_implementation.create_or_update_third_party_config( |
| 95 | + tenant_id, config, skip_validation, user_context |
82 | 96 | )
|
83 | 97 |
|
84 | 98 |
|
85 |
| -async def revoke_email_verification_tokens( |
86 |
| - user_id: str, |
87 |
| - email: Optional[str] = None, |
| 99 | +async def delete_third_party_config( |
| 100 | + tenant_id: Optional[str], |
| 101 | + third_party_id: str, |
88 | 102 | user_context: Optional[Dict[str, Any]] = None,
|
89 |
| -) -> RevokeEmailVerificationTokensOkResult: |
| 103 | +) -> DeleteThirdPartyConfigOkResult: |
90 | 104 | if user_context is None:
|
91 | 105 | user_context = {}
|
92 | 106 |
|
93 |
| - recipe = EmailVerificationRecipe.get_instance() |
94 |
| - if email is None: |
95 |
| - email_info = await recipe.get_email_for_user_id(user_id, user_context) |
96 |
| - if isinstance(email_info, GetEmailForUserIdOkResult): |
97 |
| - email = email_info.email |
98 |
| - elif isinstance(email_info, EmailDoesNotExistError): |
99 |
| - return RevokeEmailVerificationTokensOkResult() |
100 |
| - else: |
101 |
| - raise Exception("Unknown User ID provided without email") |
102 |
| - |
103 |
| - return await EmailVerificationRecipe.get_instance().recipe_implementation.revoke_email_verification_tokens( |
104 |
| - user_id, email, user_context |
| 107 | + recipe = MultitenancyRecipe.get_instance() |
| 108 | + |
| 109 | + return await recipe.recipe_implementation.delete_third_party_config( |
| 110 | + tenant_id, third_party_id, user_context |
105 | 111 | )
|
106 | 112 |
|
107 | 113 |
|
108 |
| -async def unverify_email( |
| 114 | +async def associate_user_to_tenant( |
| 115 | + tenant_id: Optional[str], |
109 | 116 | user_id: str,
|
110 |
| - email: Optional[str] = None, |
111 |
| - user_context: Union[None, Dict[str, Any]] = None, |
112 |
| -): |
| 117 | + user_context: Optional[Dict[str, Any]] = None, |
| 118 | +) -> Union[ |
| 119 | + AssociateUserToTenantOkResult, |
| 120 | + AssociateUserToTenantUnknownUserIdError, |
| 121 | + AssociateUserToTenantEmailAlreadyExistsError, |
| 122 | + AssociateUserToTenantPhoneNumberAlreadyExistsError, |
| 123 | + AssociateUserToTenantThirdPartyUserAlreadyExistsError, |
| 124 | +]: |
113 | 125 | if user_context is None:
|
114 | 126 | user_context = {}
|
115 | 127 |
|
116 |
| - recipe = EmailVerificationRecipe.get_instance() |
117 |
| - if email is None: |
118 |
| - email_info = await recipe.get_email_for_user_id(user_id, user_context) |
119 |
| - if isinstance(email_info, GetEmailForUserIdOkResult): |
120 |
| - email = email_info.email |
121 |
| - elif isinstance(email_info, EmailDoesNotExistError): |
122 |
| - # Here we are returning OK since that's how it used to work, but a later call |
123 |
| - # to is_verified will still return true |
124 |
| - return UnverifyEmailOkResult |
125 |
| - else: |
126 |
| - raise Exception("Unknown User ID provided without email") |
127 |
| - |
128 |
| - return await EmailVerificationRecipe.get_instance().recipe_implementation.unverify_email( |
129 |
| - user_id, email, user_context |
| 128 | + recipe = MultitenancyRecipe.get_instance() |
| 129 | + |
| 130 | + return await recipe.recipe_implementation.associate_user_to_tenant( |
| 131 | + tenant_id, user_id, user_context |
130 | 132 | )
|
131 | 133 |
|
132 | 134 |
|
133 |
| -async def send_email( |
134 |
| - input_: EmailTemplateVars, user_context: Union[None, Dict[str, Any]] = None |
135 |
| -): |
| 135 | +async def dissociate_user_from_tenant( |
| 136 | + tenant_id: Optional[str], |
| 137 | + user_id: str, |
| 138 | + user_context: Optional[Dict[str, Any]] = None, |
| 139 | +) -> DisassociateUserFromTenantOkResult: |
136 | 140 | if user_context is None:
|
137 | 141 | user_context = {}
|
138 |
| - return await EmailVerificationRecipe.get_instance().email_delivery.ingredient_interface_impl.send_email( |
139 |
| - input_, user_context |
| 142 | + |
| 143 | + recipe = MultitenancyRecipe.get_instance() |
| 144 | + |
| 145 | + return await recipe.recipe_implementation.dissociate_user_from_tenant( |
| 146 | + tenant_id, user_id, user_context |
140 | 147 | )
|
0 commit comments