clerk_fapi_rs/apis/
default_api.rs

1/*
2 * Clerk Frontend API
3 *
4 * The Clerk REST Frontend API, meant to be accessed from a browser or native environment.  This is a Form Based API and all the data must be sent and formatted according to the `application/x-www-form-urlencoded` content type.  ### Versions  When the API changes in a way that isn't compatible with older versions, a new version is released. Each version is identified by its release date, e.g. `2021-02-05`. For more information, please see [Clerk API Versions](https://clerk.com/docs/backend-requests/versioning/overview).  ### Using the Try It Console  The `Try It` feature of the docs only works for **Development Instances** when using the `DevBrowser` security scheme. To use it, first generate a dev instance token from the `/v1/dev_browser` endpoint.  Please see https://clerk.com/docs for more information.
5 *
6 * The version of the OpenAPI document: v1
7 * Contact: support@clerk.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`clear_site_data`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum ClearSiteDataError {
20    UnknownValue(serde_json::Value),
21}
22
23/// struct for typed errors of method [`get_account_portal`]
24#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum GetAccountPortalError {
27    Status400(models::ClerkErrors),
28    Status401(models::ClerkErrors),
29    Status404(models::ClerkErrors),
30    UnknownValue(serde_json::Value),
31}
32
33/// struct for typed errors of method [`get_dev_browser_init`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum GetDevBrowserInitError {
37    Status400(models::ClerkErrors),
38    Status500(models::ClerkErrors),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`get_proxy_health`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetProxyHealthError {
46    Status400(models::ClerkErrors),
47    Status503(models::GetHealth503Response),
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method [`link_client`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum LinkClientError {
55    Status400(models::ClerkErrors),
56    Status403(models::ClerkErrors),
57    Status422(models::ClerkErrors),
58    UnknownValue(serde_json::Value),
59}
60
61/// struct for typed errors of method [`post_dev_browser_init_set_cookie`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum PostDevBrowserInitSetCookieError {
65    UnknownValue(serde_json::Value),
66}
67
68/// struct for typed errors of method [`sync_client`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum SyncClientError {
72    Status403(models::ClerkErrors),
73    Status422(models::ClerkErrors),
74    UnknownValue(serde_json::Value),
75}
76
77/// Clear browsing data (cookies, storage, cache) associated with the requesting website
78pub async fn clear_site_data(
79    configuration: &configuration::Configuration,
80) -> Result<(), Error<ClearSiteDataError>> {
81    let uri_str = format!("{}/v1/clear-site-data", configuration.base_path);
82    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
83
84    if let Some(ref apikey) = configuration.api_key {
85        let key = apikey.key.clone();
86        let value = match apikey.prefix {
87            Some(ref prefix) => format!("{prefix} {key}"),
88            None => key,
89        };
90        req_builder = req_builder.query(&[("__dev_session", value)]);
91    }
92    if let Some(ref user_agent) = configuration.user_agent {
93        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
94    }
95    if let Some(ref apikey) = configuration.api_key {
96        let key = apikey.key.clone();
97        let value = match apikey.prefix {
98            Some(ref prefix) => format!("{prefix} {key}"),
99            None => key,
100        };
101        req_builder = req_builder.header("__session", value);
102    };
103
104    let req = req_builder.build()?;
105    let resp = configuration.client.execute(req).await?;
106
107    let status = resp.status();
108
109    if !status.is_client_error() && !status.is_server_error() {
110        Ok(())
111    } else {
112        let content = resp.text().await?;
113        let entity: Option<ClearSiteDataError> = serde_json::from_str(&content).ok();
114        Err(Error::ResponseError(ResponseContent {
115            status,
116            content,
117            entity,
118        }))
119    }
120}
121
122/// Get users account portal
123pub async fn get_account_portal(
124    configuration: &configuration::Configuration,
125) -> Result<models::ClientAccountPortal, Error<GetAccountPortalError>> {
126    let uri_str = format!("{}/v1/account_portal", configuration.base_path);
127    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
128
129    if let Some(ref apikey) = configuration.api_key {
130        let key = apikey.key.clone();
131        let value = match apikey.prefix {
132            Some(ref prefix) => format!("{prefix} {key}"),
133            None => key,
134        };
135        req_builder = req_builder.query(&[("__dev_session", value)]);
136    }
137    if let Some(ref user_agent) = configuration.user_agent {
138        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
139    }
140    if let Some(ref apikey) = configuration.api_key {
141        let key = apikey.key.clone();
142        let value = match apikey.prefix {
143            Some(ref prefix) => format!("{prefix} {key}"),
144            None => key,
145        };
146        req_builder = req_builder.header("__session", value);
147    };
148
149    let req = req_builder.build()?;
150    let resp = configuration.client.execute(req).await?;
151
152    let status = resp.status();
153    let content_type = resp
154        .headers()
155        .get("content-type")
156        .and_then(|v| v.to_str().ok())
157        .unwrap_or("application/octet-stream");
158    let content_type = super::ContentType::from(content_type);
159
160    if !status.is_client_error() && !status.is_server_error() {
161        let content = resp.text().await?;
162        match content_type {
163            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
164            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientAccountPortal`"))),
165            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientAccountPortal`")))),
166        }
167    } else {
168        let content = resp.text().await?;
169        let entity: Option<GetAccountPortalError> = serde_json::from_str(&content).ok();
170        Err(Error::ResponseError(ResponseContent {
171            status,
172            content,
173            entity,
174        }))
175    }
176}
177
178/// get dev_browser/init
179pub async fn get_dev_browser_init(
180    configuration: &configuration::Configuration,
181    origin: Option<&str>,
182) -> Result<(), Error<GetDevBrowserInitError>> {
183    // add a prefix to parameters to efficiently prevent name collisions
184    let p_query_origin = origin;
185
186    let uri_str = format!("{}/v1/dev_browser/init", configuration.base_path);
187    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
188
189    if let Some(ref param_value) = p_query_origin {
190        req_builder = req_builder.query(&[("origin", &param_value.to_string())]);
191    }
192    if let Some(ref apikey) = configuration.api_key {
193        let key = apikey.key.clone();
194        let value = match apikey.prefix {
195            Some(ref prefix) => format!("{prefix} {key}"),
196            None => key,
197        };
198        req_builder = req_builder.query(&[("__dev_session", value)]);
199    }
200    if let Some(ref user_agent) = configuration.user_agent {
201        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
202    }
203    if let Some(ref apikey) = configuration.api_key {
204        let key = apikey.key.clone();
205        let value = match apikey.prefix {
206            Some(ref prefix) => format!("{prefix} {key}"),
207            None => key,
208        };
209        req_builder = req_builder.header("__session", value);
210    };
211
212    let req = req_builder.build()?;
213    let resp = configuration.client.execute(req).await?;
214
215    let status = resp.status();
216
217    if !status.is_client_error() && !status.is_server_error() {
218        Ok(())
219    } else {
220        let content = resp.text().await?;
221        let entity: Option<GetDevBrowserInitError> = serde_json::from_str(&content).ok();
222        Err(Error::ResponseError(ResponseContent {
223            status,
224            content,
225            entity,
226        }))
227    }
228}
229
230/// Use this endpoint to check the validity of a proxy configuration for a domain. Pass the instance ID and domain ID as query parameters.
231pub async fn get_proxy_health(
232    configuration: &configuration::Configuration,
233    domain_id: &str,
234    clerk_proxy_url: &str,
235    clerk_secret_key: &str,
236    x_forwarded_for: &str,
237) -> Result<models::GetProxyHealth200Response, Error<GetProxyHealthError>> {
238    // add a prefix to parameters to efficiently prevent name collisions
239    let p_query_domain_id = domain_id;
240    let p_header_clerk_proxy_url = clerk_proxy_url;
241    let p_header_clerk_secret_key = clerk_secret_key;
242    let p_header_x_forwarded_for = x_forwarded_for;
243
244    let uri_str = format!("{}/v1/proxy-health", configuration.base_path);
245    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
246
247    req_builder = req_builder.query(&[("domain_id", &p_query_domain_id.to_string())]);
248    if let Some(ref apikey) = configuration.api_key {
249        let key = apikey.key.clone();
250        let value = match apikey.prefix {
251            Some(ref prefix) => format!("{prefix} {key}"),
252            None => key,
253        };
254        req_builder = req_builder.query(&[("__dev_session", value)]);
255    }
256    if let Some(ref user_agent) = configuration.user_agent {
257        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
258    }
259    req_builder = req_builder.header("Clerk-Proxy-Url", p_header_clerk_proxy_url.to_string());
260    req_builder = req_builder.header("Clerk-Secret-Key", p_header_clerk_secret_key.to_string());
261    req_builder = req_builder.header("X-Forwarded-For", p_header_x_forwarded_for.to_string());
262    if let Some(ref apikey) = configuration.api_key {
263        let key = apikey.key.clone();
264        let value = match apikey.prefix {
265            Some(ref prefix) => format!("{prefix} {key}"),
266            None => key,
267        };
268        req_builder = req_builder.header("__session", value);
269    };
270
271    let req = req_builder.build()?;
272    let resp = configuration.client.execute(req).await?;
273
274    let status = resp.status();
275    let content_type = resp
276        .headers()
277        .get("content-type")
278        .and_then(|v| v.to_str().ok())
279        .unwrap_or("application/octet-stream");
280    let content_type = super::ContentType::from(content_type);
281
282    if !status.is_client_error() && !status.is_server_error() {
283        let content = resp.text().await?;
284        match content_type {
285            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
286            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetProxyHealth200Response`"))),
287            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetProxyHealth200Response`")))),
288        }
289    } else {
290        let content = resp.text().await?;
291        let entity: Option<GetProxyHealthError> = serde_json::from_str(&content).ok();
292        Err(Error::ResponseError(ResponseContent {
293            status,
294            content,
295            entity,
296        }))
297    }
298}
299
300/// Complete a syncing process between a satellite and primary domains by linking their clients.
301pub async fn link_client(
302    configuration: &configuration::Configuration,
303    __clerk_token: Option<&str>,
304) -> Result<(), Error<LinkClientError>> {
305    // add a prefix to parameters to efficiently prevent name collisions
306    let p_query_clerk_token = __clerk_token;
307
308    let uri_str = format!("{}/v1/client/link", configuration.base_path);
309    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
310
311    if let Some(ref param_value) = p_query_clerk_token {
312        req_builder = req_builder.query(&[("__clerk_token", &param_value.to_string())]);
313    }
314    if let Some(ref apikey) = configuration.api_key {
315        let key = apikey.key.clone();
316        let value = match apikey.prefix {
317            Some(ref prefix) => format!("{prefix} {key}"),
318            None => key,
319        };
320        req_builder = req_builder.query(&[("__dev_session", value)]);
321    }
322    if let Some(ref user_agent) = configuration.user_agent {
323        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
324    }
325    if let Some(ref apikey) = configuration.api_key {
326        let key = apikey.key.clone();
327        let value = match apikey.prefix {
328            Some(ref prefix) => format!("{prefix} {key}"),
329            None => key,
330        };
331        req_builder = req_builder.header("__session", value);
332    };
333
334    let req = req_builder.build()?;
335    let resp = configuration.client.execute(req).await?;
336
337    let status = resp.status();
338
339    if !status.is_client_error() && !status.is_server_error() {
340        Ok(())
341    } else {
342        let content = resp.text().await?;
343        let entity: Option<LinkClientError> = serde_json::from_str(&content).ok();
344        Err(Error::ResponseError(ResponseContent {
345            status,
346            content,
347            entity,
348        }))
349    }
350}
351
352/// post dev_browser/set_first_party_cookie
353pub async fn post_dev_browser_init_set_cookie(
354    configuration: &configuration::Configuration,
355) -> Result<(), Error<PostDevBrowserInitSetCookieError>> {
356    let uri_str = format!(
357        "{}/v1/dev_browser/set_first_party_cookie",
358        configuration.base_path
359    );
360    let mut req_builder = configuration
361        .client
362        .request(reqwest::Method::POST, &uri_str);
363
364    if let Some(ref apikey) = configuration.api_key {
365        let key = apikey.key.clone();
366        let value = match apikey.prefix {
367            Some(ref prefix) => format!("{prefix} {key}"),
368            None => key,
369        };
370        req_builder = req_builder.query(&[("__dev_session", value)]);
371    }
372    if let Some(ref user_agent) = configuration.user_agent {
373        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
374    }
375    if let Some(ref apikey) = configuration.api_key {
376        let key = apikey.key.clone();
377        let value = match apikey.prefix {
378            Some(ref prefix) => format!("{prefix} {key}"),
379            None => key,
380        };
381        req_builder = req_builder.header("__session", value);
382    };
383
384    let req = req_builder.build()?;
385    let resp = configuration.client.execute(req).await?;
386
387    let status = resp.status();
388
389    if !status.is_client_error() && !status.is_server_error() {
390        Ok(())
391    } else {
392        let content = resp.text().await?;
393        let entity: Option<PostDevBrowserInitSetCookieError> = serde_json::from_str(&content).ok();
394        Err(Error::ResponseError(ResponseContent {
395            status,
396            content,
397            entity,
398        }))
399    }
400}
401
402/// Start the syncing process between a satellite and primary domain.
403pub async fn sync_client(
404    configuration: &configuration::Configuration,
405    link_domain: Option<&str>,
406    redirect_url: Option<&str>,
407) -> Result<(), Error<SyncClientError>> {
408    // add a prefix to parameters to efficiently prevent name collisions
409    let p_query_link_domain = link_domain;
410    let p_query_redirect_url = redirect_url;
411
412    let uri_str = format!("{}/v1/client/sync", configuration.base_path);
413    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
414
415    if let Some(ref param_value) = p_query_link_domain {
416        req_builder = req_builder.query(&[("link_domain", &param_value.to_string())]);
417    }
418    if let Some(ref param_value) = p_query_redirect_url {
419        req_builder = req_builder.query(&[("redirect_url", &param_value.to_string())]);
420    }
421    if let Some(ref apikey) = configuration.api_key {
422        let key = apikey.key.clone();
423        let value = match apikey.prefix {
424            Some(ref prefix) => format!("{prefix} {key}"),
425            None => key,
426        };
427        req_builder = req_builder.query(&[("__dev_session", value)]);
428    }
429    if let Some(ref user_agent) = configuration.user_agent {
430        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
431    }
432    if let Some(ref apikey) = configuration.api_key {
433        let key = apikey.key.clone();
434        let value = match apikey.prefix {
435            Some(ref prefix) => format!("{prefix} {key}"),
436            None => key,
437        };
438        req_builder = req_builder.header("__session", value);
439    };
440
441    let req = req_builder.build()?;
442    let resp = configuration.client.execute(req).await?;
443
444    let status = resp.status();
445
446    if !status.is_client_error() && !status.is_server_error() {
447        Ok(())
448    } else {
449        let content = resp.text().await?;
450        let entity: Option<SyncClientError> = serde_json::from_str(&content).ok();
451        Err(Error::ResponseError(ResponseContent {
452            status,
453            content,
454            entity,
455        }))
456    }
457}