66from pydantic import TypeAdapter
77
88from ..helpers import (
9- is_valid_uuid ,
9+ validate_uuid ,
1010 model_validate ,
1111 parse_link_response ,
1212 parse_user_response ,
13- validate_uuid ,
1413)
1514from ..http_clients import SyncClient
1615from ..types import (
@@ -152,7 +151,7 @@ def get_user_by_id(self, uid: str) -> UserResponse:
152151 This function should only be called on a server.
153152 Never expose your `service_role` key in the browser.
154153 """
155- self . _validate_uuid (uid )
154+ validate_uuid (uid )
156155
157156 response = self ._request (
158157 "GET" ,
@@ -171,7 +170,7 @@ def update_user_by_id(
171170 This function should only be called on a server.
172171 Never expose your `service_role` key in the browser.
173172 """
174- self . _validate_uuid (uid )
173+ validate_uuid (uid )
175174 response = self ._request (
176175 "PUT" ,
177176 f"admin/users/{ uid } " ,
@@ -186,15 +185,15 @@ def delete_user(self, id: str, should_soft_delete: bool = False) -> None:
186185 This function should only be called on a server.
187186 Never expose your `service_role` key in the browser.
188187 """
189- self . _validate_uuid (id )
188+ validate_uuid (id )
190189 body = {"should_soft_delete" : should_soft_delete }
191190 self ._request ("DELETE" , f"admin/users/{ id } " , body = body )
192191
193192 def _list_factors (
194193 self ,
195194 params : AuthMFAAdminListFactorsParams ,
196195 ) -> AuthMFAAdminListFactorsResponse :
197- self . _validate_uuid (params .get ("user_id" ))
196+ validate_uuid (params .get ("user_id" ))
198197 response = self ._request (
199198 "GET" ,
200199 f"admin/users/{ params .get ('user_id' )} /factors" ,
@@ -205,20 +204,14 @@ def _delete_factor(
205204 self ,
206205 params : AuthMFAAdminDeleteFactorParams ,
207206 ) -> AuthMFAAdminDeleteFactorResponse :
208- self . _validate_uuid (params .get ("user_id" ))
209- self . _validate_uuid (params .get ("id" ))
207+ validate_uuid (params .get ("user_id" ))
208+ validate_uuid (params .get ("id" ))
210209 response = self ._request (
211210 "DELETE" ,
212211 f"admin/users/{ params .get ('user_id' )} /factors/{ params .get ('id' )} " ,
213212 )
214213 return model_validate (AuthMFAAdminDeleteFactorResponse , response .content )
215214
216- def _validate_uuid (self , id : str | None ) -> None :
217- if id is None :
218- raise ValueError ("Invalid id, id cannot be none" )
219- if not is_valid_uuid (id ):
220- raise ValueError (f"Invalid id, '{ id } ' is not a valid uuid" )
221-
222215 def _list_oauth_clients (
223216 self ,
224217 params : PageParams | None = None ,
@@ -230,13 +223,10 @@ def _list_oauth_clients(
230223 This function should only be called on a server.
231224 Never expose your `service_role` key in the browser.
232225 """
233- query = {}
234226 if params :
235- if params .page is not None :
236- query ["page" ] = str (params .page )
237- if params .per_page is not None :
238- query ["per_page" ] = str (params .per_page )
239-
227+ query = QueryParams (page = params .page , per_page = params .per_page )
228+ else :
229+ query = None
240230 response = self ._request (
241231 "GET" ,
242232 "admin/oauth/clients" ,
@@ -284,15 +274,15 @@ def _create_oauth_client(
284274 This function should only be called on a server.
285275 Never expose your `service_role` key in the browser.
286276 """
287- return self ._request (
277+ response = self ._request (
288278 "POST" ,
289279 "admin/oauth/clients" ,
290280 body = params ,
291- xform = lambda data : OAuthClientResponse (
292- client = model_validate (OAuthClient , data )
293- ),
294281 )
295282
283+ return OAuthClientResponse (
284+ client = model_validate (OAuthClient , response .content )
285+ )
296286 def _get_oauth_client (
297287 self ,
298288 client_id : str ,
@@ -305,14 +295,13 @@ def _get_oauth_client(
305295 Never expose your `service_role` key in the browser.
306296 """
307297 validate_uuid (client_id )
308- return self ._request (
298+ response = self ._request (
309299 "GET" ,
310300 f"admin/oauth/clients/{ client_id } " ,
311- xform = lambda data : OAuthClientResponse (
312- client = model_validate (OAuthClient , data )
313- ),
314301 )
315-
302+ return OAuthClientResponse (
303+ client = model_validate (OAuthClient , response .content )
304+ )
316305 def _delete_oauth_client (
317306 self ,
318307 client_id : str ,
@@ -325,12 +314,12 @@ def _delete_oauth_client(
325314 Never expose your `service_role` key in the browser.
326315 """
327316 validate_uuid (client_id )
328- return self ._request (
317+ response = self ._request (
329318 "DELETE" ,
330319 f"admin/oauth/clients/{ client_id } " ,
331- xform = lambda data : OAuthClientResponse (
332- client = model_validate ( OAuthClient , data ) if data else None
333- ),
320+ )
321+ return OAuthClientResponse (
322+ client = model_validate ( OAuthClient , response . content ) if response . content else None
334323 )
335324
336325 def _regenerate_oauth_client_secret (
@@ -345,10 +334,10 @@ def _regenerate_oauth_client_secret(
345334 Never expose your `service_role` key in the browser.
346335 """
347336 validate_uuid (client_id )
348- return self ._request (
337+ response = self ._request (
349338 "POST" ,
350339 f"admin/oauth/clients/{ client_id } /regenerate_secret" ,
351- xform = lambda data : OAuthClientResponse (
352- client = model_validate ( OAuthClient , data )
353- ),
340+ )
341+ return OAuthClientResponse (
342+ client = model_validate ( OAuthClient , response . content )
354343 )
0 commit comments