clerk_fapi_rs/
clerk_fapi.rs

1use crate::apis::*;
2use crate::clerk_http_client::ClerkHttpClient;
3use crate::clerk_state::ClerkState;
4use crate::configuration::{ClerkFapiConfiguration, ClientKind, DefaultStore, Store};
5use crate::models::*;
6use dev_browser_api::DevBrowser;
7use log::error;
8use parking_lot::{Mutex, RwLock};
9use reqwest::header::{HeaderMap, HeaderValue};
10use reqwest::{Client, Request, Response};
11use serde_json::Value as JsonValue;
12use std::borrow::BorrowMut;
13use std::collections::HashMap;
14use std::ops::Deref;
15use std::sync::Arc;
16
17/// The main client for interacting with Clerk's Frontend API
18#[derive(Clone)]
19pub struct ClerkFapiClient {
20    client: Arc<ClerkHttpClient>,
21    config: ClerkFapiConfiguration,
22    state: Arc<RwLock<ClerkState>>,
23}
24
25impl ClerkFapiClient {
26    /// Creates a new ClerkFapiClient with the provided configuration
27    pub fn new(
28        config: ClerkFapiConfiguration,
29        state: Arc<RwLock<ClerkState>>,
30    ) -> Result<Self, String> {
31        // Create default headers
32        let mut headers = HeaderMap::new();
33        if config.kind == ClientKind::NonBrowser {
34            headers.insert("x-mobile", HeaderValue::from_static("1"));
35            headers.insert("x-no-origin", HeaderValue::from_static("1"));
36        }
37
38        // Create client with default headers
39        let http_client = Client::builder()
40            .default_headers(headers)
41            .user_agent(&config.user_agent)
42            .build()
43            .map_err(|e| format!("Failed to create HTTP client: {e}"))?;
44
45        // Create custom client
46        let client = ClerkHttpClient::new(http_client, state.clone(), config.kind);
47
48        Ok(Self {
49            client: Arc::new(client),
50            config,
51            state,
52        })
53    }
54
55    fn clerk_config(&self) -> ApiConfiguration {
56        self.config.into_api_configuration(self.client.clone())
57    }
58
59    pub fn set_dev_browser_token_id(&self, token_id: String) {
60        self.client.set_dev_browser_token_id(token_id);
61    }
62
63    fn handle_client_update(&self, client: ClientClient) {
64        let should_emit = self
65            .state
66            .read()
67            .should_emit_client_change(client.clone())
68            .unwrap_or(true);
69        {
70            // we anyways write the new state always
71            // minimize write lock time
72            let mut state = self.state.write();
73            state.set_client(client);
74        }
75        // Emit only if needed
76        if should_emit {
77            let state = self.state.read();
78            state.emit_state();
79        }
80    }
81
82    // Active Sessions API methods
83    pub async fn get_sessions(
84        &self,
85        clerk_session_id: Option<&str>,
86    ) -> Result<Vec<ClientActiveSession>, Error<GetSessionsError>> {
87        active_sessions_api::get_sessions(&self.clerk_config(), clerk_session_id).await
88    }
89
90    pub async fn get_users_sessions(
91        &self,
92        clerk_session_id: Option<&str>,
93    ) -> Result<Vec<ClientSession>, Error<GetUsersSessionsError>> {
94        active_sessions_api::get_users_sessions(&self.clerk_config(), clerk_session_id).await
95    }
96
97    pub async fn revoke_session(
98        &self,
99        session_id: &str,
100        clerk_session_id: Option<&str>,
101    ) -> Result<ClientSession, Error<RevokeSessionError>> {
102        let response =
103            active_sessions_api::revoke_session(&self.clerk_config(), session_id, clerk_session_id)
104                .await?;
105        if let Some(client) = response.client.clone() {
106            self.handle_client_update(*client);
107        }
108        Ok(*response.response)
109    }
110
111    // Backup Codes API methods
112    pub async fn create_backup_codes(&self) -> Result<BackupCodes, Error<CreateBackupCodesError>> {
113        let response = backup_codes_api::create_backup_codes(&self.clerk_config()).await?;
114        self.handle_client_update(*response.client.clone());
115        Ok(*response.response)
116    }
117
118    // Client API methods
119    pub async fn delete_client_sessions(
120        &self,
121    ) -> Result<ClientDeleteSession, Error<DeleteClientSessionsError>> {
122        let response = client_api::delete_client_sessions(&self.clerk_config()).await?;
123        if let Some(client) = response.response.clone() {
124            self.handle_client_update(*client);
125        }
126        Ok(response)
127    }
128
129    pub async fn get_client(&self) -> Result<Option<ClientClient>, Error<GetClientError>> {
130        let response = client_api::get_client(&self.clerk_config()).await?;
131        if let Some(client) = response.client.clone() {
132            self.handle_client_update(*client);
133        }
134        Ok(response.response.map(|c| *c))
135    }
136
137    pub async fn handshake_client(
138        &self,
139        clerk_proxy_url: Option<&str>,
140        clerk_secret_key: Option<&str>,
141        redirect_url: Option<&str>,
142        format: Option<&str>,
143        organization_id: Option<&str>,
144        satellite_fapi: Option<&str>,
145    ) -> Result<(), Error<HandshakeClientError>> {
146        client_api::handshake_client(
147            &self.clerk_config(),
148            clerk_proxy_url,
149            clerk_secret_key,
150            redirect_url,
151            format,
152            organization_id,
153            satellite_fapi,
154        )
155        .await
156    }
157
158    pub async fn post_client(&self) -> Result<Option<ClientClient>, Error<PostClientError>> {
159        let response = client_api::post_client(&self.clerk_config()).await?;
160        if let Some(client) = response.client.clone() {
161            self.handle_client_update(*client);
162        }
163        Ok(response.response.map(|c| *c))
164    }
165
166    pub async fn put_client(&self) -> Result<Option<ClientClient>, Error<PutClientError>> {
167        let response = client_api::put_client(&self.clerk_config()).await?;
168        if let Some(client) = response.client.clone() {
169            self.handle_client_update(*client);
170        }
171        Ok(response.response.map(|c| *c))
172    }
173
174    // Default API methods
175    pub async fn clear_site_data(&self) -> Result<(), Error<ClearSiteDataError>> {
176        default_api::clear_site_data(&self.clerk_config()).await
177    }
178
179    pub async fn get_account_portal(
180        &self,
181    ) -> Result<ClientAccountPortal, Error<GetAccountPortalError>> {
182        default_api::get_account_portal(&self.clerk_config()).await
183    }
184
185    pub async fn get_dev_browser_init(
186        &self,
187        origin: Option<&str>,
188    ) -> Result<(), Error<GetDevBrowserInitError>> {
189        default_api::get_dev_browser_init(&self.clerk_config(), origin).await
190    }
191
192    pub async fn get_proxy_health(
193        &self,
194        domain_id: &str,
195        clerk_proxy_url: &str,
196        clerk_secret_key: &str,
197        x_forwarded_for: &str,
198    ) -> Result<GetProxyHealth200Response, Error<GetProxyHealthError>> {
199        default_api::get_proxy_health(
200            &self.clerk_config(),
201            domain_id,
202            clerk_proxy_url,
203            clerk_secret_key,
204            x_forwarded_for,
205        )
206        .await
207    }
208
209    pub async fn link_client(
210        &self,
211        clerk_token: Option<&str>,
212    ) -> Result<(), Error<LinkClientError>> {
213        default_api::link_client(&self.clerk_config(), clerk_token).await
214    }
215
216    pub async fn post_dev_browser_init_set_cookie(
217        &self,
218    ) -> Result<(), Error<PostDevBrowserInitSetCookieError>> {
219        default_api::post_dev_browser_init_set_cookie(&self.clerk_config()).await
220    }
221
222    pub async fn sync_client(
223        &self,
224        link_domain: Option<&str>,
225        redirect_url: Option<&str>,
226    ) -> Result<(), Error<SyncClientError>> {
227        default_api::sync_client(&self.clerk_config(), link_domain, redirect_url).await
228    }
229
230    // Dev Browser API methods
231    pub async fn create_dev_browser(&self) -> Result<DevBrowser, Error<CreateDevBrowserError>> {
232        dev_browser_api::create_dev_browser(&self.clerk_config()).await
233    }
234
235    // Domains API methods
236    pub async fn attempt_organization_domain_verification(
237        &self,
238        organization_id: &str,
239        domain_id: &str,
240        code: &str,
241    ) -> Result<ClientOrganizationDomain, Error<AttemptOrganizationDomainVerificationError>> {
242        let response = domains_api::attempt_organization_domain_verification(
243            &self.clerk_config(),
244            organization_id,
245            domain_id,
246            code,
247        )
248        .await?;
249        self.handle_client_update(*response.client.clone());
250        Ok(*response.response)
251    }
252
253    pub async fn create_organization_domain(
254        &self,
255        organization_id: &str,
256        name: &str,
257    ) -> Result<ClientOrganizationDomain, Error<CreateOrganizationDomainError>> {
258        let response =
259            domains_api::create_organization_domain(&self.clerk_config(), organization_id, name)
260                .await?;
261        self.handle_client_update(*response.client.clone());
262        Ok(*response.response)
263    }
264
265    pub async fn delete_organization_domain(
266        &self,
267        organization_id: &str,
268        domain_id: &str,
269    ) -> Result<ClientDeletedObject, Error<DeleteOrganizationDomainError>> {
270        let response = domains_api::delete_organization_domain(
271            &self.clerk_config(),
272            organization_id,
273            domain_id,
274        )
275        .await?;
276        if let Some(client) = response.client.clone() {
277            self.handle_client_update(*client)
278        }
279        Ok(*response.response)
280    }
281
282    pub async fn get_organization_domain(
283        &self,
284        organization_id: &str,
285        domain_id: &str,
286    ) -> Result<ClientOrganizationDomain, Error<domains_api::GetOrganizationDomainError>> {
287        let response =
288            domains_api::get_organization_domain(&self.clerk_config(), organization_id, domain_id)
289                .await?;
290        self.handle_client_update(*response.client.clone());
291        Ok(*response.response)
292    }
293
294    pub async fn list_organization_domains(
295        &self,
296        organization_id: &str,
297        limit: Option<i64>,
298        offset: Option<i64>,
299        verified: Option<bool>,
300        enrollment_mode: Option<&str>,
301    ) -> Result<ClientClientWrappedOrganizationDomainsResponse, Error<ListOrganizationDomainsError>>
302    {
303        let response = domains_api::list_organization_domains(
304            &self.clerk_config(),
305            organization_id,
306            limit,
307            offset,
308            verified,
309            enrollment_mode,
310        )
311        .await?;
312        self.handle_client_update(*response.client.clone());
313        Ok(*response.response)
314    }
315
316    pub async fn prepare_organization_domain_verification(
317        &self,
318        organization_id: &str,
319        domain_id: &str,
320        affiliation_email_address: &str,
321    ) -> Result<ClientOrganizationDomain, Error<PrepareOrganizationDomainVerificationError>> {
322        let response = domains_api::prepare_organization_domain_verification(
323            &self.clerk_config(),
324            organization_id,
325            domain_id,
326            affiliation_email_address,
327        )
328        .await?;
329        self.handle_client_update(*response.client.clone());
330        Ok(*response.response)
331    }
332
333    pub async fn update_organization_domain_enrollment_mode(
334        &self,
335        organization_id: &str,
336        domain_id: &str,
337        enrollment_mode: &str,
338        delete_pending: Option<bool>,
339    ) -> Result<ClientOrganizationDomain, Error<UpdateOrganizationDomainEnrollmentModeError>> {
340        let response = domains_api::update_organization_domain_enrollment_mode(
341            &self.clerk_config(),
342            organization_id,
343            domain_id,
344            enrollment_mode,
345            delete_pending,
346        )
347        .await?;
348        self.handle_client_update(*response.client.clone());
349        Ok(*response.response)
350    }
351
352    // Email Addresses API methods
353    pub async fn create_email_addresses(
354        &self,
355        email_address: &str,
356        _clerk_session_id: Option<&str>,
357    ) -> Result<ClientEmailAddress, Error<CreateEmailAddressesError>> {
358        let response = email_addresses_api::create_email_addresses(
359            &self.clerk_config(),
360            email_address,
361            _clerk_session_id,
362        )
363        .await?;
364        self.handle_client_update(*response.client.clone());
365        Ok(*response.response)
366    }
367
368    pub async fn delete_email_address(
369        &self,
370        email_id: &str,
371        clerk_session_id: Option<&str>,
372    ) -> Result<ClientDeletedObject, Error<DeleteEmailAddressError>> {
373        let response = email_addresses_api::delete_email_address(
374            &self.clerk_config(),
375            email_id,
376            clerk_session_id,
377        )
378        .await?;
379        if let Some(client) = response.client.clone() {
380            self.handle_client_update(*client)
381        }
382        Ok(*response.response)
383    }
384
385    pub async fn get_email_address(
386        &self,
387        email_id: &str,
388        clerk_session_id: Option<&str>,
389    ) -> Result<ClientEmailAddress, Error<GetEmailAddressError>> {
390        let response = email_addresses_api::get_email_address(
391            &self.clerk_config(),
392            email_id,
393            clerk_session_id,
394        )
395        .await?;
396        self.handle_client_update(*response.client.clone());
397        Ok(*response.response)
398    }
399
400    pub async fn get_email_addresses(
401        &self,
402        clerk_session_id: Option<&str>,
403    ) -> Result<Vec<ClientEmailAddress>, Error<GetEmailAddressesError>> {
404        email_addresses_api::get_email_addresses(&self.clerk_config(), clerk_session_id).await
405    }
406
407    pub async fn send_verification_email(
408        &self,
409        email_id: &str,
410        strategy: &str,
411        _clerk_session_id: Option<&str>,
412        redirect_url: Option<&str>,
413        action_complete_redirect_url: Option<&str>,
414    ) -> Result<ClientEmailAddress, Error<SendVerificationEmailError>> {
415        let response = email_addresses_api::send_verification_email(
416            &self.clerk_config(),
417            email_id,
418            strategy,
419            _clerk_session_id,
420            redirect_url,
421            action_complete_redirect_url,
422        )
423        .await?;
424        self.handle_client_update(*response.client.clone());
425        Ok(*response.response)
426    }
427
428    pub async fn verify_email_address(
429        &self,
430        email_id: &str,
431        code: &str,
432        _clerk_session_id: Option<&str>,
433    ) -> Result<ClientEmailAddress, Error<VerifyEmailAddressError>> {
434        let response = email_addresses_api::verify_email_address(
435            &self.clerk_config(),
436            email_id,
437            code,
438            _clerk_session_id,
439        )
440        .await?;
441        self.handle_client_update(*response.client.clone());
442        Ok(*response.response)
443    }
444
445    // Environment API methods
446    pub async fn get_environment(&self) -> Result<ClientEnvironment, Error<GetEnvironmentError>> {
447        environment_api::get_environment(&self.clerk_config()).await
448    }
449
450    pub async fn update_environment(
451        &self,
452        origin: &str,
453    ) -> Result<ClientEnvironment, Error<UpdateEnvironmentError>> {
454        environment_api::update_environment(&self.clerk_config(), origin).await
455    }
456
457    // External Accounts API methods
458    pub async fn delete_external_account(
459        &self,
460        external_account_id: &str,
461    ) -> Result<ClientDeletedObject, Error<DeleteExternalAccountError>> {
462        let response = external_accounts_api::delete_external_account(
463            &self.clerk_config(),
464            external_account_id,
465        )
466        .await?;
467        if let Some(client) = response.client.clone() {
468            self.handle_client_update(*client)
469        }
470        Ok(*response.response)
471    }
472
473    pub async fn post_o_auth_accounts(
474        &self,
475        strategy: &str,
476        origin: Option<&str>,
477        redirect_url: Option<&str>,
478        action_complete_redirect_url: Option<&str>,
479        additional_scope: Option<&str>,
480        code: Option<&str>,
481        token: Option<&str>,
482        oidc_login_hint: Option<&str>,
483        oidc_prompt: Option<&str>,
484    ) -> Result<ExternalAccountWithVerification, Error<PostOAuthAccountsError>> {
485        let response = external_accounts_api::post_o_auth_accounts(
486            &self.clerk_config(),
487            strategy,
488            origin,
489            redirect_url,
490            action_complete_redirect_url,
491            additional_scope,
492            code,
493            token,
494            oidc_login_hint,
495            oidc_prompt,
496        )
497        .await?;
498        self.handle_client_update(*response.client.clone());
499        Ok(response.response)
500    }
501
502    pub async fn reauthorize_external_account(
503        &self,
504        external_account_id: &str,
505        redirect_url: &str,
506        additional_scope: Option<Vec<String>>,
507        action_complete_redirect_url: Option<&str>,
508        oidc_login_hint: Option<&str>,
509        oidc_prompt: Option<&str>,
510    ) -> Result<ExternalAccountWithVerification, Error<ReauthorizeExternalAccountError>> {
511        let response = external_accounts_api::reauthorize_external_account(
512            &self.clerk_config(),
513            external_account_id,
514            redirect_url,
515            additional_scope,
516            action_complete_redirect_url,
517            oidc_login_hint,
518            oidc_prompt,
519        )
520        .await?;
521        self.handle_client_update(*response.client.clone());
522        Ok(response.response)
523    }
524
525    pub async fn revoke_external_account_tokens(
526        &self,
527        external_account_id: &str,
528    ) -> Result<ClientUser, Error<RevokeExternalAccountTokensError>> {
529        let response = external_accounts_api::revoke_external_account_tokens(
530            &self.clerk_config(),
531            external_account_id,
532        )
533        .await?;
534        self.handle_client_update(*response.client.clone());
535        Ok(*response.response)
536    }
537
538    // Health API methods
539    pub async fn get_health(&self) -> Result<GetHealth200Response, Error<GetHealthError>> {
540        health_api::get_health(&self.clerk_config()).await
541    }
542
543    // Invitations API methods
544    pub async fn bulk_create_organization_invitations(
545        &self,
546        organization_id: &str,
547        email_address: Vec<String>,
548        role: &str,
549    ) -> Result<Vec<ClientOrganizationInvitation>, Error<BulkCreateOrganizationInvitationsError>>
550    {
551        let response = invitations_api::bulk_create_organization_invitations(
552            &self.clerk_config(),
553            organization_id,
554            email_address,
555            role,
556        )
557        .await?;
558        self.handle_client_update(*response.client.clone());
559
560        let res = match *response.response {
561            ClientClientWrappedOrganizationInvitationsResponse::ArrayVecmodelsClientOrganizationInvitation(res) => res,
562            ClientClientWrappedOrganizationInvitationsResponse::ClientClientWrappedOrganizationInvitationsResponseOneOf(res) => {
563                res.data.unwrap_or(Vec::new())
564            }
565        };
566
567        Ok(res)
568    }
569
570    pub async fn create_organization_invitations(
571        &self,
572        organization_id: &str,
573        email_address: &str,
574        role: &str,
575    ) -> Result<ClientOrganizationInvitation, Error<CreateOrganizationInvitationsError>> {
576        let response = invitations_api::create_organization_invitations(
577            &self.clerk_config(),
578            organization_id,
579            email_address,
580            role,
581        )
582        .await?;
583        self.handle_client_update(*response.client.clone());
584        Ok(*response.response)
585    }
586
587    pub async fn get_all_pending_organization_invitations(
588        &self,
589        organization_id: &str,
590    ) -> Result<Vec<ClientOrganizationInvitation>, Error<GetAllPendingOrganizationInvitationsError>>
591    {
592        let response = invitations_api::get_all_pending_organization_invitations(
593            &self.clerk_config(),
594            organization_id,
595        )
596        .await?;
597        self.handle_client_update(*response.client.clone());
598        let res = match *response.response {
599            ClientClientWrappedOrganizationInvitationsResponse::ArrayVecmodelsClientOrganizationInvitation(res) => res,
600            ClientClientWrappedOrganizationInvitationsResponse::ClientClientWrappedOrganizationInvitationsResponseOneOf(res) => {
601                res.data.unwrap_or(Vec::new())
602            }
603        };
604        Ok(res)
605    }
606
607    pub async fn get_organization_invitations(
608        &self,
609        organization_id: &str,
610        limit: Option<i64>,
611        offset: Option<i64>,
612        status: Option<&str>,
613    ) -> Result<Vec<ClientOrganizationInvitation>, Error<GetOrganizationInvitationsError>> {
614        let response = invitations_api::get_organization_invitations(
615            &self.clerk_config(),
616            organization_id,
617            limit,
618            offset,
619            status,
620        )
621        .await?;
622        self.handle_client_update(*response.client.clone());
623
624        let res = match *response.response {
625            ClientClientWrappedOrganizationInvitationsResponse::ArrayVecmodelsClientOrganizationInvitation(res) => res,
626            ClientClientWrappedOrganizationInvitationsResponse::ClientClientWrappedOrganizationInvitationsResponseOneOf(res) => {
627                res.data.unwrap_or(Vec::new())
628            }
629        };
630        Ok(res)
631    }
632
633    pub async fn revoke_pending_organization_invitation(
634        &self,
635        organization_id: &str,
636        invitation_id: &str,
637    ) -> Result<ClientOrganizationInvitation, Error<RevokePendingOrganizationInvitationError>> {
638        let response = invitations_api::revoke_pending_organization_invitation(
639            &self.clerk_config(),
640            organization_id,
641            invitation_id,
642        )
643        .await?;
644        self.handle_client_update(*response.client.clone());
645        Ok(*response.response)
646    }
647
648    // Members API methods
649    pub async fn create_organization_membership(
650        &self,
651        organization_id: &str,
652        user_id: Option<&str>,
653        role: Option<&str>,
654    ) -> Result<ClientOrganizationMembership, Error<CreateOrganizationMembershipError>> {
655        let response = members_api::create_organization_membership(
656            &self.clerk_config(),
657            organization_id,
658            user_id,
659            role,
660        )
661        .await?;
662        self.handle_client_update(*response.client.clone());
663        Ok(*response.response)
664    }
665
666    pub async fn list_organization_memberships(
667        &self,
668        organization_id: &str,
669        limit: Option<i64>,
670        offset: Option<i64>,
671        paginated: Option<bool>,
672        query: Option<&str>,
673        role: Option<&str>,
674    ) -> Result<Vec<ClientOrganizationMembership>, Error<ListOrganizationMembershipsError>> {
675        let response = members_api::list_organization_memberships(
676            &self.clerk_config(),
677            organization_id,
678            limit,
679            offset,
680            paginated,
681            query,
682            role,
683        )
684        .await?;
685        self.handle_client_update(*response.client.clone());
686        let res = match *response.response {
687            ClientClientWrappedOrganizationMembershipsResponse::ArrayVecmodelsClientOrganizationMembership(res) => res,
688            ClientClientWrappedOrganizationMembershipsResponse::ClientClientWrappedOrganizationMembershipsResponseOneOf(res) => {
689                res.data.unwrap_or(Vec::new())
690            }
691        };
692        Ok(res)
693    }
694
695    pub async fn remove_organization_member(
696        &self,
697        organization_id: &str,
698        user_id: &str,
699    ) -> Result<ClientOrganizationMembership, Error<RemoveOrganizationMemberError>> {
700        let response =
701            members_api::remove_organization_member(&self.clerk_config(), organization_id, user_id)
702                .await?;
703        self.handle_client_update(*response.client.clone());
704        Ok(*response.response)
705    }
706
707    pub async fn update_organization_membership(
708        &self,
709        organization_id: &str,
710        user_id: &str,
711        role: Option<&str>,
712    ) -> Result<ClientOrganizationMembership, Error<UpdateOrganizationMembershipError>> {
713        let response = members_api::update_organization_membership(
714            &self.clerk_config(),
715            organization_id,
716            user_id,
717            role,
718        )
719        .await?;
720        self.handle_client_update(*response.client.clone());
721        Ok(*response.response)
722    }
723
724    // Membership Requests API methods
725    pub async fn accept_organization_membership_request(
726        &self,
727        organization_id: &str,
728        request_id: &str,
729    ) -> Result<ClientOrganizationMembershipRequest, Error<AcceptOrganizationMembershipRequestError>>
730    {
731        let response = membership_requests_api::accept_organization_membership_request(
732            &self.clerk_config(),
733            organization_id,
734            request_id,
735        )
736        .await?;
737        self.handle_client_update(*response.client.clone());
738        Ok(*response.response)
739    }
740
741    pub async fn list_organization_membership_requests(
742        &self,
743        organization_id: &str,
744        limit: Option<i64>,
745        offset: Option<i64>,
746        status: Option<&str>,
747    ) -> Result<
748        ClientClientWrappedOrganizationMembershipRequestsResponse,
749        Error<ListOrganizationMembershipRequestsError>,
750    > {
751        let response = membership_requests_api::list_organization_membership_requests(
752            &self.clerk_config(),
753            organization_id,
754            limit,
755            offset,
756            status,
757        )
758        .await?;
759        self.handle_client_update(*response.client.clone());
760        Ok(*response.response)
761    }
762
763    pub async fn reject_organization_membership_request(
764        &self,
765        organization_id: &str,
766        request_id: &str,
767    ) -> Result<ClientOrganizationMembershipRequest, Error<RejectOrganizationMembershipRequestError>>
768    {
769        let response = membership_requests_api::reject_organization_membership_request(
770            &self.clerk_config(),
771            organization_id,
772            request_id,
773        )
774        .await?;
775        self.handle_client_update(*response.client.clone());
776        Ok(*response.response)
777    }
778
779    // OAuth2 Callbacks API methods
780    pub async fn get_oauth_callback(
781        &self,
782        scope: Option<&str>,
783        code: Option<&str>,
784        state: Option<&str>,
785        error: Option<&str>,
786    ) -> Result<(), Error<GetOauthCallbackError>> {
787        o_auth2_callbacks_api::get_oauth_callback(&self.clerk_config(), scope, code, state, error)
788            .await
789    }
790
791    pub async fn post_oauth_callback(
792        &self,
793        code: Option<&str>,
794        scope: Option<&str>,
795        state: Option<&str>,
796        error: Option<&str>,
797    ) -> Result<(), Error<PostOauthCallbackError>> {
798        o_auth2_callbacks_api::post_oauth_callback(&self.clerk_config(), code, scope, state, error)
799            .await
800    }
801
802    // OAuth2 Identity Provider API methods
803    pub async fn get_o_auth_consent(
804        configuration: &configuration::Configuration,
805        client_id: &str,
806        _clerk_session_id: Option<&str>,
807    ) -> Result<OAuthConsentInfo, Error<GetOAuthConsentError>> {
808        o_auth2_identify_provider_api::get_o_auth_consent(
809            configuration,
810            client_id,
811            _clerk_session_id,
812        )
813        .await
814    }
815
816    pub async fn get_o_auth_token(&self) -> Result<OAuthToken, Error<GetOAuthTokenError>> {
817        o_auth2_identify_provider_api::get_o_auth_token(&self.clerk_config()).await
818    }
819
820    pub async fn get_o_auth_token_info(
821        &self,
822        token: &str,
823        token_type_hint: Option<&str>,
824        scope: Option<&str>,
825    ) -> Result<OAuthTokenInfo, Error<GetOAuthTokenInfoError>> {
826        o_auth2_identify_provider_api::get_o_auth_token_info(
827            &self.clerk_config(),
828            token,
829            token_type_hint,
830            scope,
831        )
832        .await
833    }
834
835    pub async fn get_o_auth_user_info(
836        &self,
837    ) -> Result<OAuthUserInfo, Error<GetOAuthUserInfoError>> {
838        o_auth2_identify_provider_api::get_o_auth_user_info(&self.clerk_config()).await
839    }
840
841    pub async fn get_o_auth_user_info_post(
842        &self,
843    ) -> Result<OAuthUserInfo, Error<GetOAuthUserInfoPostError>> {
844        o_auth2_identify_provider_api::get_o_auth_user_info_post(&self.clerk_config()).await
845    }
846
847    pub async fn request_o_auth_authorize(&self) -> Result<(), Error<RequestOAuthAuthorizeError>> {
848        o_auth2_identify_provider_api::request_o_auth_authorize(&self.clerk_config()).await
849    }
850
851    pub async fn request_o_auth_authorize_post(
852        &self,
853    ) -> Result<(), Error<RequestOAuthAuthorizePostError>> {
854        o_auth2_identify_provider_api::request_o_auth_authorize_post(&self.clerk_config()).await
855    }
856
857    pub async fn revoke_o_auth_token(
858        &self,
859        token: Option<&str>,
860        token_type_hint: Option<&str>,
861    ) -> Result<(), Error<RevokeOAuthTokenError>> {
862        o_auth2_identify_provider_api::revoke_o_auth_token(
863            &self.clerk_config(),
864            token,
865            token_type_hint,
866        )
867        .await
868    }
869
870    // Organization API methods
871    pub async fn create_organization(
872        &self,
873        name: Option<&str>,
874    ) -> Result<ClientOrganization, Error<CreateOrganizationError>> {
875        let response = organization_api::create_organization(&self.clerk_config(), name).await?;
876        self.handle_client_update(*response.client.clone());
877        Ok(*response.response)
878    }
879
880    pub async fn delete_organization(
881        &self,
882        organization_id: &str,
883    ) -> Result<ClientDeletedObject, Error<DeleteOrganizationError>> {
884        let response =
885            organization_api::delete_organization(&self.clerk_config(), organization_id).await?;
886        if let Some(client) = response.client.clone() {
887            self.handle_client_update(*client)
888        }
889        Ok(*response.response)
890    }
891
892    pub async fn delete_organization_logo(
893        &self,
894        organization_id: &str,
895    ) -> Result<ClientDeletedObject, Error<DeleteOrganizationLogoError>> {
896        let response =
897            organization_api::delete_organization_logo(&self.clerk_config(), organization_id)
898                .await?;
899        if let Some(client) = response.client.clone() {
900            self.handle_client_update(*client)
901        }
902        Ok(*response.response)
903    }
904
905    pub async fn get_organization(
906        &self,
907        organization_id: &str,
908    ) -> Result<ClientOrganization, Error<GetOrganizationError>> {
909        let response =
910            organization_api::get_organization(&self.clerk_config(), organization_id).await?;
911        self.handle_client_update(*response.client.clone());
912        Ok(*response.response)
913    }
914
915    pub async fn update_organization(
916        &self,
917        organization_id: &str,
918        name: Option<&str>,
919        slug: Option<&str>,
920    ) -> Result<ClientOrganization, Error<UpdateOrganizationError>> {
921        let response = organization_api::update_organization(
922            &self.clerk_config(),
923            organization_id,
924            name,
925            slug,
926        )
927        .await?;
928        self.handle_client_update(*response.client.clone());
929        Ok(*response.response)
930    }
931
932    pub async fn update_organization_logo(
933        &self,
934        organization_id: &str,
935        file: FileData,
936    ) -> Result<ClientOrganization, Error<UpdateOrganizationLogoError>> {
937        let response =
938            organization_api::update_organization_logo(&self.clerk_config(), organization_id, file)
939                .await?;
940        self.handle_client_update((*response.client.clone()).into());
941        Ok(*response.response)
942    }
943
944    // Organization Memberships API methods
945    pub async fn accept_organization_invitation(
946        &self,
947        invitation_id: &str,
948    ) -> Result<ClientOrganizationInvitationUserContext, Error<AcceptOrganizationInvitationError>>
949    {
950        let response = organizations_memberships_api::accept_organization_invitation(
951            &self.clerk_config(),
952            invitation_id,
953        )
954        .await?;
955        self.handle_client_update(*response.client.clone());
956        Ok(*response.response)
957    }
958
959    pub async fn accept_organization_suggestion(
960        &self,
961        suggestion_id: &str,
962    ) -> Result<ClientOrganizationSuggestion, Error<AcceptOrganizationSuggestionError>> {
963        let response = organizations_memberships_api::accept_organization_suggestion(
964            &self.clerk_config(),
965            suggestion_id,
966        )
967        .await?;
968        self.handle_client_update(*response.client.clone());
969        Ok(*response.response)
970    }
971
972    pub async fn delete_organization_memberships(
973        &self,
974        organization_id: &str,
975    ) -> Result<ClientDeletedObject, Error<DeleteOrganizationMembershipsError>> {
976        let response = organizations_memberships_api::delete_organization_memberships(
977            &self.clerk_config(),
978            organization_id,
979        )
980        .await?;
981        if let Some(client) = response.client.clone() {
982            self.handle_client_update(*client)
983        }
984        Ok(*response.response)
985    }
986
987    pub async fn get_organization_memberships(
988        &self,
989        limit: Option<i64>,
990        offset: Option<i64>,
991        paginated: Option<bool>,
992    ) -> Result<Vec<ClientOrganizationMembership>, Error<GetOrganizationMembershipsError>> {
993        let response = organizations_memberships_api::get_organization_memberships(
994            &self.clerk_config(),
995            limit,
996            offset,
997            paginated,
998        )
999        .await?;
1000        self.handle_client_update(*response.client.clone());
1001        let res = match *response.response {
1002            ClientClientWrappedOrganizationMembershipsResponse::ArrayVecmodelsClientOrganizationMembership(res) => res,
1003            ClientClientWrappedOrganizationMembershipsResponse::ClientClientWrappedOrganizationMembershipsResponseOneOf(res) => {
1004                res.data.unwrap_or(Vec::new())
1005            }
1006        };
1007        Ok(res)
1008    }
1009
1010    pub async fn get_organization_suggestions(
1011        &self,
1012        limit: Option<i64>,
1013        offset: Option<i64>,
1014        status: Option<&str>,
1015    ) -> Result<
1016        ClientClientWrappedOrganizationSuggestionsResponse,
1017        Error<GetOrganizationSuggestionsError>,
1018    > {
1019        let response = organizations_memberships_api::get_organization_suggestions(
1020            &self.clerk_config(),
1021            limit,
1022            offset,
1023            status,
1024        )
1025        .await?;
1026        self.handle_client_update(*response.client.clone());
1027        Ok(*response.response)
1028    }
1029
1030    pub async fn get_users_organization_invitations(
1031        &self,
1032        limit: Option<i64>,
1033        offset: Option<i64>,
1034        status: Option<&str>,
1035    ) -> Result<
1036        ClientClientWrappedOrganizationInvitationsUserContextResponse,
1037        Error<GetUsersOrganizationInvitationsError>,
1038    > {
1039        let response = organizations_memberships_api::get_users_organization_invitations(
1040            &self.clerk_config(),
1041            limit,
1042            offset,
1043            status,
1044        )
1045        .await?;
1046        self.handle_client_update(*response.client.clone());
1047        Ok(*response.response)
1048    }
1049
1050    // Passkeys API methods
1051    pub async fn attempt_passkey_verification(
1052        &self,
1053        passkey_id: &str,
1054        origin: Option<&str>,
1055        strategy: Option<&str>,
1056        public_key_credential: Option<&str>,
1057    ) -> Result<ClientPasskey, Error<AttemptPasskeyVerificationError>> {
1058        let response = passkeys_api::attempt_passkey_verification(
1059            &self.clerk_config(),
1060            passkey_id,
1061            origin,
1062            strategy,
1063            public_key_credential,
1064        )
1065        .await?;
1066        self.handle_client_update(*response.client.clone());
1067        Ok(*response.response)
1068    }
1069
1070    pub async fn delete_passkey(
1071        &self,
1072        passkey_id: &str,
1073    ) -> Result<ClientDeletedObject, Error<DeletePasskeyError>> {
1074        let response = passkeys_api::delete_passkey(&self.clerk_config(), passkey_id).await?;
1075        if let Some(client) = response.client.clone() {
1076            self.handle_client_update(*client)
1077        }
1078        Ok(*response.response)
1079    }
1080
1081    pub async fn patch_passkey(
1082        &self,
1083        passkey_id: &str,
1084        name: Option<&str>,
1085    ) -> Result<ClientPasskey, Error<PatchPasskeyError>> {
1086        let response = passkeys_api::patch_passkey(&self.clerk_config(), passkey_id, name).await?;
1087        self.handle_client_update(*response.client.clone());
1088        Ok(*response.response)
1089    }
1090
1091    pub async fn post_passkey(
1092        &self,
1093        _clerk_session_id: Option<&str>,
1094        origin: Option<&str>,
1095        x_original_host: Option<&str>,
1096    ) -> Result<ClientPasskey, Error<PostPasskeyError>> {
1097        let response = passkeys_api::post_passkey(
1098            &self.clerk_config(),
1099            _clerk_session_id,
1100            origin,
1101            x_original_host,
1102        )
1103        .await?;
1104        self.handle_client_update(*response.client.clone());
1105        Ok(*response.response)
1106    }
1107
1108    pub async fn read_passkey(
1109        &self,
1110        passkey_id: &str,
1111    ) -> Result<ClientPasskey, Error<ReadPasskeyError>> {
1112        let response = passkeys_api::read_passkey(&self.clerk_config(), passkey_id).await?;
1113        self.handle_client_update(*response.client.clone());
1114        Ok(*response.response)
1115    }
1116
1117    // Phone Numbers API methods
1118    pub async fn delete_phone_number(
1119        &self,
1120        phone_number_id: &str,
1121        clerk_session_id: Option<&str>,
1122    ) -> Result<ClientDeletedObject, Error<DeletePhoneNumberError>> {
1123        let response = phone_numbers_api::delete_phone_number(
1124            &self.clerk_config(),
1125            phone_number_id,
1126            clerk_session_id,
1127        )
1128        .await?;
1129        if let Some(client) = response.client.clone() {
1130            self.handle_client_update(*client)
1131        }
1132        Ok(*response.response)
1133    }
1134
1135    pub async fn get_phone_numbers(
1136        &self,
1137        clerk_session_id: Option<&str>,
1138    ) -> Result<Vec<ClientPhoneNumber>, Error<GetPhoneNumbersError>> {
1139        phone_numbers_api::get_phone_numbers(&self.clerk_config(), clerk_session_id).await
1140    }
1141
1142    pub async fn post_phone_numbers(
1143        &self,
1144        phone_number: &str,
1145        _clerk_session_id: Option<&str>,
1146        reserved_for_second_factor: Option<bool>,
1147    ) -> Result<ClientPhoneNumber, Error<PostPhoneNumbersError>> {
1148        let response = phone_numbers_api::post_phone_numbers(
1149            &self.clerk_config(),
1150            phone_number,
1151            _clerk_session_id,
1152            reserved_for_second_factor,
1153        )
1154        .await?;
1155        self.handle_client_update(*response.client.clone());
1156        Ok(*response.response)
1157    }
1158
1159    pub async fn read_phone_number(
1160        &self,
1161        phone_number_id: &str,
1162        clerk_session_id: Option<&str>,
1163    ) -> Result<ClientPhoneNumber, Error<ReadPhoneNumberError>> {
1164        let response = phone_numbers_api::read_phone_number(
1165            &self.clerk_config(),
1166            phone_number_id,
1167            clerk_session_id,
1168        )
1169        .await?;
1170        self.handle_client_update(*response.client.clone());
1171        Ok(*response.response)
1172    }
1173
1174    pub async fn send_verification_sms(
1175        &self,
1176        phone_number_id: &str,
1177        strategy: &str,
1178        _clerk_session_id: Option<&str>,
1179    ) -> Result<ClientPhoneNumber, Error<SendVerificationSmsError>> {
1180        let response = phone_numbers_api::send_verification_sms(
1181            &self.clerk_config(),
1182            phone_number_id,
1183            strategy,
1184            _clerk_session_id,
1185        )
1186        .await?;
1187        self.handle_client_update(*response.client.clone());
1188        Ok(*response.response)
1189    }
1190
1191    pub async fn update_phone_number(
1192        &self,
1193        phone_number_id: &str,
1194        clerk_session_id: Option<&str>,
1195        reserved_for_second_factor: Option<bool>,
1196        default_second_factor: Option<bool>,
1197    ) -> Result<ClientPhoneNumber, Error<UpdatePhoneNumberError>> {
1198        let response = phone_numbers_api::update_phone_number(
1199            &self.clerk_config(),
1200            phone_number_id,
1201            clerk_session_id,
1202            reserved_for_second_factor,
1203            default_second_factor,
1204        )
1205        .await?;
1206        self.handle_client_update(*response.client.clone());
1207        Ok(*response.response)
1208    }
1209
1210    pub async fn verify_phone_number(
1211        &self,
1212        phone_number_id: &str,
1213        code: &str,
1214        _clerk_session_id: Option<&str>,
1215    ) -> Result<ClientPhoneNumber, Error<VerifyPhoneNumberError>> {
1216        let response = phone_numbers_api::verify_phone_number(
1217            &self.clerk_config(),
1218            phone_number_id,
1219            code,
1220            _clerk_session_id,
1221        )
1222        .await?;
1223        self.handle_client_update(*response.client.clone());
1224        Ok(*response.response)
1225    }
1226
1227    // Redirect API methods
1228    pub async fn redirect_to_url(
1229        &self,
1230        redirect_url: Option<&str>,
1231    ) -> Result<(), Error<RedirectToUrlError>> {
1232        redirect_api::redirect_to_url(&self.clerk_config(), redirect_url).await
1233    }
1234
1235    // Roles API methods
1236    pub async fn list_organization_roles(
1237        &self,
1238        organization_id: &str,
1239        limit: Option<i64>,
1240        offset: Option<i64>,
1241    ) -> Result<ClientClientWrappedRolesResponse, Error<ListOrganizationRolesError>> {
1242        let response = roles_api::list_organization_roles(
1243            &self.clerk_config(),
1244            organization_id,
1245            limit,
1246            offset,
1247        )
1248        .await?;
1249        self.handle_client_update(*response.client.clone());
1250        Ok(*response.response)
1251    }
1252
1253    // SAML API methods
1254    pub async fn acs(&self, saml_connection_id: &str) -> Result<(), Error<AcsError>> {
1255        saml_api::acs(&self.clerk_config(), saml_connection_id).await
1256    }
1257
1258    pub async fn saml_metadata(
1259        &self,
1260        saml_connection_id: &str,
1261    ) -> Result<(), Error<SamlMetadataError>> {
1262        saml_api::saml_metadata(&self.clerk_config(), saml_connection_id).await
1263    }
1264
1265    // Sessions API methods
1266    pub async fn attempt_session_reverification_first_factor(
1267        &self,
1268        session_id: &str,
1269        strategy: &str,
1270        origin: Option<&str>,
1271        code: Option<&str>,
1272        password: Option<&str>,
1273        public_key_credential: Option<&str>,
1274    ) -> Result<ClientSessionReverification, Error<AttemptSessionReverificationFirstFactorError>>
1275    {
1276        let response = sessions_api::attempt_session_reverification_first_factor(
1277            &self.clerk_config(),
1278            session_id,
1279            strategy,
1280            origin,
1281            code,
1282            password,
1283            public_key_credential,
1284        )
1285        .await?;
1286        if let Some(client) = response.client.clone() {
1287            self.handle_client_update(*client);
1288        }
1289        Ok(*response.response)
1290    }
1291
1292    pub async fn attempt_session_reverification_second_factor(
1293        &self,
1294        session_id: &str,
1295        strategy: Option<&str>,
1296        code: Option<&str>,
1297    ) -> Result<ClientSessionReverification, Error<AttemptSessionReverificationSecondFactorError>>
1298    {
1299        let response = sessions_api::attempt_session_reverification_second_factor(
1300            &self.clerk_config(),
1301            session_id,
1302            strategy,
1303            code,
1304        )
1305        .await?;
1306        if let Some(client) = response.client.clone() {
1307            self.handle_client_update(*client);
1308        }
1309        Ok(*response.response)
1310    }
1311
1312    pub async fn create_session_token(
1313        &self,
1314        session_id: &str,
1315        organization_id: Option<&str>,
1316    ) -> Result<CreateSessionToken200Response, Error<CreateSessionTokenError>> {
1317        sessions_api::create_session_token(&self.clerk_config(), session_id, organization_id).await
1318    }
1319
1320    pub async fn create_session_token_with_template(
1321        &self,
1322        session_id: &str,
1323        template_name: &str,
1324    ) -> Result<CreateSessionToken200Response, Error<CreateSessionTokenWithTemplateError>> {
1325        sessions_api::create_session_token_with_template(
1326            &self.clerk_config(),
1327            session_id,
1328            template_name,
1329        )
1330        .await
1331    }
1332
1333    pub async fn end_session(
1334        &self,
1335        session_id: &str,
1336    ) -> Result<ClientSession, Error<EndSessionError>> {
1337        let response = sessions_api::end_session(&self.clerk_config(), session_id).await?;
1338        if let Some(client) = response.client.clone() {
1339            self.handle_client_update(*client);
1340        }
1341        Ok(*response.response)
1342    }
1343
1344    pub async fn get_session(
1345        &self,
1346        session_id: &str,
1347    ) -> Result<ClientSession, Error<GetSessionError>> {
1348        let response = sessions_api::get_session(&self.clerk_config(), session_id).await?;
1349        if let Some(client) = response.client.clone() {
1350            self.handle_client_update(*client);
1351        }
1352        Ok(*response.response)
1353    }
1354
1355    pub async fn prepare_session_reverification_first_factor(
1356        &self,
1357        session_id: &str,
1358        origin: Option<&str>,
1359        strategy: Option<&str>,
1360        email_address_id: Option<&str>,
1361        phone_number_id: Option<&str>,
1362    ) -> Result<ClientSessionReverification, Error<PrepareSessionReverificationFirstFactorError>>
1363    {
1364        let response = sessions_api::prepare_session_reverification_first_factor(
1365            &self.clerk_config(),
1366            session_id,
1367            origin,
1368            strategy,
1369            email_address_id,
1370            phone_number_id,
1371        )
1372        .await?;
1373        if let Some(client) = response.client.clone() {
1374            self.handle_client_update(*client);
1375        }
1376        Ok(*response.response)
1377    }
1378
1379    pub async fn prepare_session_reverification_second_factor(
1380        &self,
1381        session_id: &str,
1382        strategy: Option<&str>,
1383        phone_number_id: Option<&str>,
1384    ) -> Result<ClientSessionReverification, Error<PrepareSessionReverificationSecondFactorError>>
1385    {
1386        let response = sessions_api::prepare_session_reverification_second_factor(
1387            &self.clerk_config(),
1388            session_id,
1389            strategy,
1390            phone_number_id,
1391        )
1392        .await?;
1393        if let Some(client) = response.client.clone() {
1394            self.handle_client_update(*client);
1395        }
1396        Ok(*response.response)
1397    }
1398
1399    pub async fn remove_client_sessions_and_retain_cookie(
1400        &self,
1401    ) -> Result<Option<ClientClient>, Error<RemoveClientSessionsAndRetainCookieError>> {
1402        let response =
1403            sessions_api::remove_client_sessions_and_retain_cookie(&self.clerk_config()).await?;
1404        if let Some(client) = response.response.clone() {
1405            self.handle_client_update(*client);
1406        }
1407        Ok(response.response.map(|s| *s))
1408    }
1409
1410    pub async fn remove_session(
1411        &self,
1412        session_id: &str,
1413    ) -> Result<ClientSession, Error<RemoveSessionError>> {
1414        let response = sessions_api::remove_session(&self.clerk_config(), session_id).await?;
1415        if let Some(client) = response.client.clone() {
1416            self.handle_client_update(*client);
1417        }
1418        Ok(*response.response)
1419    }
1420
1421    pub async fn start_session_reverification(
1422        &self,
1423        session_id: &str,
1424        level: &str,
1425    ) -> Result<ClientSessionReverification, Error<StartSessionReverificationError>> {
1426        let response =
1427            sessions_api::start_session_reverification(&self.clerk_config(), session_id, level)
1428                .await?;
1429        if let Some(client) = response.client.clone() {
1430            self.handle_client_update(*client);
1431        }
1432        Ok(*response.response)
1433    }
1434
1435    pub async fn touch_session(
1436        &self,
1437        session_id: &str,
1438        active_organization_id: Option<&str>,
1439    ) -> Result<ClientSession, Error<TouchSessionError>> {
1440        let response =
1441            sessions_api::touch_session(&self.clerk_config(), session_id, active_organization_id)
1442                .await?;
1443        if let Some(client) = response.client.clone() {
1444            self.handle_client_update(*client);
1445        }
1446        Ok(*response.response)
1447    }
1448
1449    // Sign Ins API methods
1450    pub async fn accept_ticket(
1451        &self,
1452        ticket: &str,
1453    ) -> Result<(), Error<sign_ins_api::AcceptTicketError>> {
1454        sign_ins_api::accept_ticket(&self.clerk_config(), ticket).await
1455    }
1456
1457    pub async fn attempt_sign_in_factor_one(
1458        &self,
1459        sign_in_id: &str,
1460        strategy: &str,
1461        origin: Option<&str>,
1462        code: Option<&str>,
1463        password: Option<&str>,
1464        signature: Option<&str>,
1465        token: Option<&str>,
1466        ticket: Option<&str>,
1467        public_key_credential: Option<&str>,
1468    ) -> Result<ClientSignIn, Error<AttemptSignInFactorOneError>> {
1469        let response = sign_ins_api::attempt_sign_in_factor_one(
1470            &self.clerk_config(),
1471            sign_in_id,
1472            strategy,
1473            origin,
1474            code,
1475            password,
1476            signature,
1477            token,
1478            ticket,
1479            public_key_credential,
1480        )
1481        .await?;
1482        if let Some(client) = response.client.clone() {
1483            self.handle_client_update(*client);
1484        }
1485        Ok(*response.response)
1486    }
1487
1488    pub async fn attempt_sign_in_factor_two(
1489        &self,
1490        sign_in_id: &str,
1491        strategy: Option<&str>,
1492        code: Option<&str>,
1493    ) -> Result<ClientSignIn, Error<AttemptSignInFactorTwoError>> {
1494        let response = sign_ins_api::attempt_sign_in_factor_two(
1495            &self.clerk_config(),
1496            sign_in_id,
1497            strategy,
1498            code,
1499        )
1500        .await?;
1501
1502        if let Some(client) = response.client.clone() {
1503            self.handle_client_update(*client);
1504        };
1505        Ok(*response.response)
1506    }
1507
1508    pub async fn create_sign_in(
1509        &self,
1510        origin: Option<&str>,
1511        strategy: Option<&str>,
1512        identifier: Option<&str>,
1513        password: Option<&str>,
1514        ticket: Option<&str>,
1515        redirect_url: Option<&str>,
1516        action_complete_redirect_url: Option<&str>,
1517        transfer: Option<bool>,
1518        code: Option<&str>,
1519        token: Option<&str>,
1520        oidc_login_hint: Option<&str>,
1521        oidc_prompt: Option<&str>,
1522    ) -> Result<ClientSignIn, Error<CreateSignInError>> {
1523        let response = sign_ins_api::create_sign_in(
1524            &self.clerk_config(),
1525            origin,
1526            strategy,
1527            identifier,
1528            password,
1529            ticket,
1530            redirect_url,
1531            action_complete_redirect_url,
1532            transfer,
1533            code,
1534            token,
1535            oidc_login_hint,
1536            oidc_prompt,
1537        )
1538        .await?;
1539        if let Some(client) = response.client.clone() {
1540            self.handle_client_update(*client);
1541        };
1542        Ok(*response.response)
1543    }
1544
1545    pub async fn get_sign_in(
1546        &self,
1547        sign_in_id: &str,
1548    ) -> Result<ClientSignIn, Error<GetSignInError>> {
1549        let response = sign_ins_api::get_sign_in(&self.clerk_config(), sign_in_id).await?;
1550        if let Some(client) = response.client.clone() {
1551            self.handle_client_update(*client);
1552        };
1553        Ok(*response.response)
1554    }
1555
1556    pub async fn prepare_sign_in_factor_one(
1557        &self,
1558        sign_in_id: &str,
1559        strategy: &str,
1560        origin: Option<&str>,
1561        email_address_id: Option<&str>,
1562        phone_number_id: Option<&str>,
1563        web3_wallet_id: Option<&str>,
1564        passkey_id: Option<&str>,
1565        redirect_url: Option<&str>,
1566        action_complete_redirect_url: Option<&str>,
1567        oidc_login_hint: Option<&str>,
1568        oidc_prompt: Option<&str>,
1569    ) -> Result<ClientSignIn, Error<PrepareSignInFactorOneError>> {
1570        let response = sign_ins_api::prepare_sign_in_factor_one(
1571            &self.clerk_config(),
1572            sign_in_id,
1573            strategy,
1574            origin,
1575            email_address_id,
1576            phone_number_id,
1577            web3_wallet_id,
1578            passkey_id,
1579            redirect_url,
1580            action_complete_redirect_url,
1581            oidc_login_hint,
1582            oidc_prompt,
1583        )
1584        .await?;
1585        if let Some(client) = response.client.clone() {
1586            self.handle_client_update(*client);
1587        };
1588        Ok(*response.response)
1589    }
1590
1591    pub async fn prepare_sign_in_factor_two(
1592        &self,
1593        sign_in_id: &str,
1594        strategy: Option<&str>,
1595        phone_number_id: Option<&str>,
1596    ) -> Result<ClientSignIn, Error<PrepareSignInFactorTwoError>> {
1597        let response = sign_ins_api::prepare_sign_in_factor_two(
1598            &self.clerk_config(),
1599            sign_in_id,
1600            strategy,
1601            phone_number_id,
1602        )
1603        .await?;
1604        if let Some(client) = response.client.clone() {
1605            self.handle_client_update(*client);
1606        };
1607        Ok(*response.response)
1608    }
1609
1610    pub async fn reset_password(
1611        &self,
1612        sign_in_id: &str,
1613        password: &str,
1614        sign_out_of_other_sessions: Option<bool>,
1615    ) -> Result<ClientSignIn, Error<ResetPasswordError>> {
1616        let response = sign_ins_api::reset_password(
1617            &self.clerk_config(),
1618            sign_in_id,
1619            password,
1620            sign_out_of_other_sessions,
1621        )
1622        .await?;
1623        if let Some(client) = response.client.clone() {
1624            self.handle_client_update((*client).into());
1625        };
1626        Ok(*response.response)
1627    }
1628
1629    pub async fn verify(&self, token: &str) -> Result<(), Error<VerifyError>> {
1630        sign_ins_api::verify(&self.clerk_config(), token).await
1631    }
1632
1633    // Sign Ups API methods
1634    pub async fn attempt_sign_ups_verification(
1635        &self,
1636        sign_up_id: &str,
1637        origin: Option<&str>,
1638        strategy: Option<&str>,
1639        code: Option<&str>,
1640        signature: Option<&str>,
1641        token: Option<&str>,
1642    ) -> Result<ClientSignUp, Error<AttemptSignUpsVerificationError>> {
1643        let response = sign_ups_api::attempt_sign_ups_verification(
1644            &self.clerk_config(),
1645            sign_up_id,
1646            origin,
1647            strategy,
1648            code,
1649            signature,
1650            token,
1651        )
1652        .await?;
1653        if let Some(client) = response.client.clone() {
1654            self.handle_client_update(*client);
1655        };
1656        Ok(*response.response)
1657    }
1658
1659    pub async fn create_sign_ups(
1660        &self,
1661        origin: Option<&str>,
1662        transfer: Option<bool>,
1663        password: Option<&str>,
1664        first_name: Option<&str>,
1665        last_name: Option<&str>,
1666        username: Option<&str>,
1667        email_address: Option<&str>,
1668        phone_number: Option<&str>,
1669        email_address_or_phone_number: Option<&str>,
1670        unsafe_metadata: Option<&str>,
1671        strategy: Option<&str>,
1672        action_complete_redirect_url: Option<&str>,
1673        redirect_url: Option<&str>,
1674        ticket: Option<&str>,
1675        web3_wallet: Option<&str>,
1676        token: Option<&str>,
1677        code: Option<&str>,
1678        captcha_token: Option<&str>,
1679        captcha_error: Option<&str>,
1680        captcha_widget_type: Option<&str>,
1681        legal_accepted: Option<bool>,
1682        oidc_login_hint: Option<&str>,
1683        oidc_prompt: Option<&str>,
1684    ) -> Result<ClientSignUp, Error<CreateSignUpsError>> {
1685        let response = sign_ups_api::create_sign_ups(
1686            &self.clerk_config(),
1687            origin,
1688            transfer,
1689            password,
1690            first_name,
1691            last_name,
1692            username,
1693            email_address,
1694            phone_number,
1695            email_address_or_phone_number,
1696            unsafe_metadata,
1697            strategy,
1698            action_complete_redirect_url,
1699            redirect_url,
1700            ticket,
1701            web3_wallet,
1702            token,
1703            code,
1704            captcha_token,
1705            captcha_error,
1706            captcha_widget_type,
1707            legal_accepted,
1708            oidc_login_hint,
1709            oidc_prompt,
1710        )
1711        .await?;
1712        if let Some(client) = response.client.clone() {
1713            self.handle_client_update(*client);
1714        };
1715        Ok(*response.response)
1716    }
1717
1718    pub async fn get_sign_ups(
1719        &self,
1720        sign_up_id: &str,
1721    ) -> Result<ClientSignUp, Error<GetSignUpsError>> {
1722        let response = sign_ups_api::get_sign_ups(&self.clerk_config(), sign_up_id).await?;
1723        if let Some(client) = response.client.clone() {
1724            self.handle_client_update(*client);
1725        };
1726        Ok(*response.response)
1727    }
1728
1729    pub async fn prepare_sign_ups_verification(
1730        &self,
1731        sign_up_id: &str,
1732        origin: Option<&str>,
1733        strategy: Option<&str>,
1734        redirect_url: Option<&str>,
1735        action_complete_redirect_url: Option<&str>,
1736        oidc_login_hint: Option<&str>,
1737        oidc_prompt: Option<&str>,
1738    ) -> Result<ClientSignUp, Error<PrepareSignUpsVerificationError>> {
1739        let response = sign_ups_api::prepare_sign_ups_verification(
1740            &self.clerk_config(),
1741            sign_up_id,
1742            origin,
1743            strategy,
1744            redirect_url,
1745            action_complete_redirect_url,
1746            oidc_login_hint,
1747            oidc_prompt,
1748        )
1749        .await?;
1750        if let Some(client) = response.client.clone() {
1751            self.handle_client_update(*client);
1752        };
1753        Ok(*response.response)
1754    }
1755
1756    pub async fn update_sign_ups(
1757        &self,
1758        sign_up_id: &str,
1759        origin: Option<&str>,
1760        password: Option<&str>,
1761        first_name: Option<&str>,
1762        last_name: Option<&str>,
1763        username: Option<&str>,
1764        email_address: Option<&str>,
1765        phone_number: Option<&str>,
1766        email_address_or_phone_number: Option<&str>,
1767        unsafe_metadata: Option<&str>,
1768        strategy: Option<&str>,
1769        redirect_url: Option<&str>,
1770        action_complete_redirect_url: Option<&str>,
1771        ticket: Option<&str>,
1772        web3_wallet: Option<&str>,
1773        token: Option<&str>,
1774        code: Option<&str>,
1775        legal_accepted: Option<bool>,
1776        oidc_login_hint: Option<&str>,
1777        oidc_prompt: Option<&str>,
1778    ) -> Result<ClientSignUp, Error<UpdateSignUpsError>> {
1779        let response = sign_ups_api::update_sign_ups(
1780            &self.clerk_config(),
1781            sign_up_id,
1782            origin,
1783            password,
1784            first_name,
1785            last_name,
1786            username,
1787            email_address,
1788            phone_number,
1789            email_address_or_phone_number,
1790            unsafe_metadata,
1791            strategy,
1792            redirect_url,
1793            action_complete_redirect_url,
1794            ticket,
1795            web3_wallet,
1796            token,
1797            code,
1798            legal_accepted,
1799            oidc_login_hint,
1800            oidc_prompt,
1801        )
1802        .await?;
1803        if let Some(client) = response.client.clone() {
1804            self.handle_client_update(*client);
1805        };
1806        Ok(*response.response)
1807    }
1808
1809    // TOTP API methods
1810    pub async fn delete_totp(&self) -> Result<ClientDeletedObject, Error<DeleteTotpError>> {
1811        let response = totp_api::delete_totp(&self.clerk_config()).await?;
1812        if let Some(client) = response.client.clone() {
1813            self.handle_client_update(*client)
1814        }
1815        Ok(*response.response)
1816    }
1817
1818    pub async fn post_totp(&self) -> Result<Totp, Error<PostTotpError>> {
1819        let response = totp_api::post_totp(&self.clerk_config()).await?;
1820        self.handle_client_update(*response.client.clone());
1821        Ok(response.response)
1822    }
1823
1824    pub async fn verify_totp(&self, code: Option<&str>) -> Result<Totp, Error<VerifyTotpError>> {
1825        let response = totp_api::verify_totp(&self.clerk_config(), code).await?;
1826        self.handle_client_update(*response.client.clone());
1827        Ok(response.response)
1828    }
1829
1830    // User API methods
1831    pub async fn change_password(
1832        &self,
1833        current_password: Option<&str>,
1834        new_password: Option<&str>,
1835        sign_out_of_other_sessions: Option<bool>,
1836    ) -> Result<ClientUser, Error<ChangePasswordError>> {
1837        let response = user_api::change_password(
1838            &self.clerk_config(),
1839            current_password,
1840            new_password,
1841            sign_out_of_other_sessions,
1842        )
1843        .await?;
1844        self.handle_client_update((*response.client.clone()).into());
1845        Ok(*response.response)
1846    }
1847
1848    pub async fn create_service_token(
1849        &self,
1850        service: &str,
1851        _clerk_session_id: Option<&str>,
1852    ) -> Result<Token, Error<CreateServiceTokenError>> {
1853        user_api::create_service_token(&self.clerk_config(), service, _clerk_session_id).await
1854    }
1855
1856    pub async fn delete_profile_image(
1857        &self,
1858    ) -> Result<ClientDeletedObject, Error<DeleteProfileImageError>> {
1859        let response = user_api::delete_profile_image(&self.clerk_config()).await?;
1860        if let Some(client) = response.client.clone() {
1861            self.handle_client_update(*client)
1862        }
1863        Ok(*response.response)
1864    }
1865
1866    pub async fn delete_user(&self) -> Result<ClientDeletedObject, Error<DeleteUserError>> {
1867        let response = user_api::delete_user(&self.clerk_config()).await?;
1868        if let Some(client) = response.client.clone() {
1869            self.handle_client_update(*client)
1870        }
1871        Ok(*response.response)
1872    }
1873
1874    pub async fn get_user(&self) -> Result<ClientUser, Error<GetUserError>> {
1875        let response = user_api::get_user(&self.clerk_config()).await?;
1876        self.handle_client_update(*response.client.clone());
1877        Ok(*response.response)
1878    }
1879
1880    pub async fn patch_user(
1881        &self,
1882        username: Option<&str>,
1883        first_name: Option<&str>,
1884        last_name: Option<&str>,
1885        primary_email_address_id: Option<&str>,
1886        primary_phone_number_id: Option<&str>,
1887        primary_web3_wallet_id: Option<&str>,
1888        unsafe_metadata: Option<&str>,
1889    ) -> Result<ClientUser, Error<PatchUserError>> {
1890        let response = user_api::patch_user(
1891            &self.clerk_config(),
1892            username,
1893            first_name,
1894            last_name,
1895            primary_email_address_id,
1896            primary_phone_number_id,
1897            primary_web3_wallet_id,
1898            unsafe_metadata,
1899        )
1900        .await?;
1901        self.handle_client_update(*response.client.clone());
1902        Ok(*response.response)
1903    }
1904
1905    pub async fn remove_password(
1906        &self,
1907        current_password: Option<&str>,
1908    ) -> Result<ClientUser, Error<RemovePasswordError>> {
1909        let response = user_api::remove_password(&self.clerk_config(), current_password).await?;
1910        self.handle_client_update((*response.client.clone()).into());
1911        Ok(*response.response)
1912    }
1913
1914    /// Does not work, file upload not implemented yet
1915    pub async fn update_profile_image(
1916        &self,
1917        file: FileData,
1918    ) -> Result<Image, Error<UpdateProfileImageError>> {
1919        let response = user_api::update_profile_image(&self.clerk_config(), file).await?;
1920        if let Some(client) = response.client.clone() {
1921            self.handle_client_update((*client).into());
1922        }
1923        Ok(*response.response)
1924    }
1925
1926    // Waitlist API methods
1927    pub async fn join_waitlist(
1928        &self,
1929        email_address: &str,
1930    ) -> Result<ClientWaitlistEntry, Error<JoinWaitlistError>> {
1931        waitlist_api::join_waitlist(&self.clerk_config(), email_address).await
1932    }
1933
1934    // Web3 Wallets API methods
1935    pub async fn attempt_web3_wallet_verification(
1936        &self,
1937        web3_wallet_id: &str,
1938        signature: &str,
1939        origin: Option<&str>,
1940    ) -> Result<ClientWeb3Wallet, Error<AttemptWeb3WalletVerificationError>> {
1941        let response = web3_wallets_api::attempt_web3_wallet_verification(
1942            &self.clerk_config(),
1943            web3_wallet_id,
1944            signature,
1945            origin,
1946        )
1947        .await?;
1948        self.handle_client_update(*response.client.clone());
1949        Ok(*response.response)
1950    }
1951
1952    pub async fn delete_web3_wallet(
1953        &self,
1954        web3_wallet_id: &str,
1955    ) -> Result<ClientDeletedObject, Error<DeleteWeb3WalletError>> {
1956        let response =
1957            web3_wallets_api::delete_web3_wallet(&self.clerk_config(), web3_wallet_id).await?;
1958        if let Some(client) = response.client.clone() {
1959            self.handle_client_update(*client)
1960        }
1961        Ok(*response.response)
1962    }
1963
1964    pub async fn get_web3_wallets(
1965        &self,
1966        clerk_session_id: Option<&str>,
1967    ) -> Result<Vec<ClientWeb3Wallet>, Error<GetWeb3WalletsError>> {
1968        web3_wallets_api::get_web3_wallets(&self.clerk_config(), clerk_session_id).await
1969    }
1970
1971    pub async fn post_web3_wallets(
1972        &self,
1973        web3_wallet: &str,
1974        _clerk_session_id: Option<&str>,
1975    ) -> Result<ClientWeb3Wallet, Error<PostWeb3WalletsError>> {
1976        let response = web3_wallets_api::post_web3_wallets(
1977            &self.clerk_config(),
1978            web3_wallet,
1979            _clerk_session_id,
1980        )
1981        .await?;
1982        self.handle_client_update(*response.client.clone());
1983        Ok(*response.response)
1984    }
1985
1986    pub async fn prepare_web3_wallet_verification(
1987        &self,
1988        web3_wallet_id: &str,
1989        strategy: &str,
1990        origin: Option<&str>,
1991        redirect_url: Option<&str>,
1992    ) -> Result<ClientWeb3Wallet, Error<PrepareWeb3WalletVerificationError>> {
1993        let response = web3_wallets_api::prepare_web3_wallet_verification(
1994            &self.clerk_config(),
1995            web3_wallet_id,
1996            strategy,
1997            origin,
1998            redirect_url,
1999        )
2000        .await?;
2001        self.handle_client_update(*response.client.clone());
2002        Ok(*response.response)
2003    }
2004
2005    pub async fn read_web3_wallet(
2006        &self,
2007        web3_wallet_id: &str,
2008    ) -> Result<ClientWeb3Wallet, Error<ReadWeb3WalletError>> {
2009        let response =
2010            web3_wallets_api::read_web3_wallet(&self.clerk_config(), web3_wallet_id).await?;
2011        self.handle_client_update(*response.client.clone());
2012        Ok(*response.response)
2013    }
2014
2015    // Well Known API methods
2016    pub async fn get_android_asset_links(
2017        &self,
2018    ) -> Result<Vec<serde_json::Value>, Error<GetAndroidAssetLinksError>> {
2019        well_known_api::get_android_asset_links(&self.clerk_config()).await
2020    }
2021
2022    pub async fn get_apple_app_site_association(
2023        &self,
2024    ) -> Result<WellKnownAppleAppSiteAssociation, Error<GetAppleAppSiteAssociationError>> {
2025        well_known_api::get_apple_app_site_association(&self.clerk_config()).await
2026    }
2027
2028    pub async fn get_jwks(&self) -> Result<Jwks, Error<GetJwksError>> {
2029        well_known_api::get_jwks(&self.clerk_config()).await
2030    }
2031
2032    pub async fn get_o_auth2_authorization_server_metadata(
2033        &self,
2034    ) -> Result<
2035        WellKnownOAuth2AuthorizationServerMetadata,
2036        Error<GetOAuth2AuthorizationServerMetadataError>,
2037    > {
2038        well_known_api::get_o_auth2_authorization_server_metadata(&self.clerk_config()).await
2039    }
2040
2041    pub async fn get_open_id_configuration(
2042        &self,
2043    ) -> Result<WellKnownOpenIdConfiguration, Error<GetOpenIdConfigurationError>> {
2044        well_known_api::get_open_id_configuration(&self.clerk_config()).await
2045    }
2046}