4242 SuperTokensPlugin ,
4343 SuperTokensPublicPlugin ,
4444)
45+ from supertokens_python .types .base import UserContext
4546from supertokens_python .types .response import CamelCaseBaseModel
4647
4748from .constants import FDI_KEY_HEADER , RID_KEY_HEADER , USER_COUNT
@@ -181,13 +182,13 @@ def __init__(
181182 self .mode = mode
182183
183184 def get_top_level_website_domain (
184- self , request : Optional [BaseRequest ], user_context : Dict [ str , Any ]
185+ self , request : Optional [BaseRequest ], user_context : UserContext
185186 ) -> str :
186187 return get_top_level_domain_for_same_site_resolution (
187188 self .get_origin (request , user_context ).get_as_string_dangerous ()
188189 )
189190
190- def get_origin (self , request : Optional [BaseRequest ], user_context : Dict [ str , Any ] ):
191+ def get_origin (self , request : Optional [BaseRequest ], user_context : UserContext ):
191192 origin = self .__origin
192193 if origin is None :
193194 origin = self .__website_domain
@@ -211,7 +212,7 @@ def defaultImpl(o: Any):
211212
212213
213214def manage_session_post_response (
214- session : SessionContainer , response : BaseResponse , user_context : Dict [ str , Any ]
215+ session : SessionContainer , response : BaseResponse , user_context : UserContext
215216):
216217 # Something similar happens in handle_error of session/recipe.py
217218 for mutator in session .response_mutators :
@@ -577,7 +578,7 @@ async def get_user_count(
577578 self ,
578579 include_recipe_ids : Union [None , List [str ]],
579580 tenant_id : Optional [str ] = None ,
580- user_context : Optional [Dict [ str , Any ] ] = None ,
581+ user_context : Optional [UserContext ] = None ,
581582 ) -> int :
582583 querier = Querier .get_instance (None )
583584 include_recipe_ids_str = None
@@ -601,7 +602,7 @@ async def create_user_id_mapping(
601602 external_user_id : str ,
602603 external_user_id_info : Optional [str ],
603604 force : Optional [bool ],
604- user_context : Optional [Dict [ str , Any ] ],
605+ user_context : Optional [UserContext ],
605606 ) -> Union [
606607 CreateUserIdMappingOkResult ,
607608 UnknownSupertokensUserIDError ,
@@ -641,7 +642,7 @@ async def get_user_id_mapping(
641642 self ,
642643 user_id : str ,
643644 user_id_type : Optional [UserIDTypes ],
644- user_context : Optional [Dict [ str , Any ] ],
645+ user_context : Optional [UserContext ],
645646 ) -> Union [GetUserIdMappingOkResult , UnknownMappingError ]:
646647 querier = Querier .get_instance (None )
647648
@@ -676,7 +677,7 @@ async def delete_user_id_mapping(
676677 user_id : str ,
677678 user_id_type : Optional [UserIDTypes ],
678679 force : Optional [bool ],
679- user_context : Optional [Dict [ str , Any ] ],
680+ user_context : Optional [UserContext ],
680681 ) -> DeleteUserIdMappingOkResult :
681682 querier = Querier .get_instance (None )
682683
@@ -708,7 +709,7 @@ async def update_or_delete_user_id_mapping_info(
708709 user_id : str ,
709710 user_id_type : Optional [UserIDTypes ],
710711 external_user_id_info : Optional [str ],
711- user_context : Optional [Dict [ str , Any ] ],
712+ user_context : Optional [UserContext ],
712713 ) -> Union [UpdateOrDeleteUserIdMappingInfoOkResult , UnknownMappingError ]:
713714 querier = Querier .get_instance (None )
714715
@@ -734,7 +735,7 @@ async def update_or_delete_user_id_mapping_info(
734735 raise_general_exception ("Please upgrade the SuperTokens core to >= 3.15.0" )
735736
736737 async def middleware (
737- self , request : BaseRequest , response : BaseResponse , user_context : Dict [ str , Any ]
738+ self , request : BaseRequest , response : BaseResponse , user_context : UserContext
738739 ) -> Union [BaseResponse , None ]:
739740 from supertokens_python .recipe .session .recipe import SessionRecipe
740741
@@ -907,7 +908,7 @@ async def handle_supertokens_error(
907908 request : BaseRequest ,
908909 err : Exception ,
909910 response : BaseResponse ,
910- user_context : Dict [ str , Any ] ,
911+ user_context : UserContext ,
911912 ) -> Optional [BaseResponse ]:
912913 log_debug_message ("errorHandler: Started" )
913914 log_debug_message (
@@ -935,7 +936,7 @@ async def handle_supertokens_error(
935936
936937 def get_request_from_user_context (
937938 self ,
938- user_context : Optional [Dict [ str , Any ] ] = None ,
939+ user_context : Optional [UserContext ] = None ,
939940 ) -> Optional [BaseRequest ]:
940941 if user_context is None :
941942 return None
@@ -948,20 +949,22 @@ def get_request_from_user_context(
948949
949950 return user_context .get ("_default" , {}).get ("request" )
950951
951- @staticmethod
952- def is_recipe_initialized (recipe_id : str ) -> bool :
952+ def is_recipe_initialized (self , recipe_id : str ) -> bool :
953953 """
954954 Check if a recipe is initialized.
955955 :param recipe_id: The ID of the recipe to check.
956956 :return: Whether the recipe is initialized.
957957 """
958958 return any (
959- recipe .get_recipe_id () == recipe_id
960- for recipe in Supertokens .get_instance ().recipe_modules
959+ recipe .get_recipe_id () == recipe_id for recipe in self .recipe_modules
961960 )
962961
963962
964963def get_request_from_user_context (
965- user_context : Optional [Dict [ str , Any ] ],
964+ user_context : Optional [UserContext ],
966965) -> Optional [BaseRequest ]:
967966 return Supertokens .get_instance ().get_request_from_user_context (user_context )
967+
968+
969+ def is_recipe_initialized (recipe_id : str ) -> bool :
970+ return Supertokens .get_instance ().is_recipe_initialized (recipe_id )
0 commit comments