clerk_fapi_rs/apis/
web3_wallets_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 [`attempt_web3_wallet_verification`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum AttemptWeb3WalletVerificationError {
20    Status400(models::ClerkErrors),
21    Status401(models::ClerkErrors),
22    Status403(models::ClerkErrors),
23    Status404(models::ClerkErrors),
24    Status422(models::ClerkErrors),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`delete_web3_wallet`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DeleteWeb3WalletError {
32    Status400(models::ClerkErrors),
33    Status401(models::ClerkErrors),
34    Status403(models::ClerkErrors),
35    Status404(models::ClerkErrors),
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_web3_wallets`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetWeb3WalletsError {
43    Status401(models::ClerkErrors),
44    Status403(models::ClerkErrors),
45    Status404(models::ClerkErrors),
46    UnknownValue(serde_json::Value),
47}
48
49/// struct for typed errors of method [`post_web3_wallets`]
50#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum PostWeb3WalletsError {
53    Status401(models::ClerkErrors),
54    Status403(models::ClerkErrors),
55    Status404(models::ClerkErrors),
56    Status422(models::ClerkErrors),
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`prepare_web3_wallet_verification`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum PrepareWeb3WalletVerificationError {
64    Status401(models::ClerkErrors),
65    Status403(models::ClerkErrors),
66    Status404(models::ClerkErrors),
67    Status422(models::ClerkErrors),
68    UnknownValue(serde_json::Value),
69}
70
71/// struct for typed errors of method [`read_web3_wallet`]
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum ReadWeb3WalletError {
75    Status401(models::ClerkErrors),
76    Status403(models::ClerkErrors),
77    Status404(models::ClerkErrors),
78    UnknownValue(serde_json::Value),
79}
80
81/// Attempts to verify the provided web3 wallet.
82pub async fn attempt_web3_wallet_verification(
83    configuration: &configuration::Configuration,
84    web3_wallet_id: &str,
85    signature: &str,
86    origin: Option<&str>,
87) -> Result<models::ClientClientWrappedWeb3Wallet, Error<AttemptWeb3WalletVerificationError>> {
88    // add a prefix to parameters to efficiently prevent name collisions
89    let p_path_web3_wallet_id = web3_wallet_id;
90    let p_form_signature = signature;
91    let p_header_origin = origin;
92
93    let uri_str = format!(
94        "{}/v1/me/web3_wallets/{web3_wallet_id}/attempt_verification",
95        configuration.base_path,
96        web3_wallet_id = crate::apis::urlencode(p_path_web3_wallet_id)
97    );
98    let mut req_builder = configuration
99        .client
100        .request(reqwest::Method::POST, &uri_str);
101
102    if let Some(ref apikey) = configuration.api_key {
103        let key = apikey.key.clone();
104        let value = match apikey.prefix {
105            Some(ref prefix) => format!("{prefix} {key}"),
106            None => key,
107        };
108        req_builder = req_builder.query(&[("__dev_session", value)]);
109    }
110    if let Some(ref user_agent) = configuration.user_agent {
111        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112    }
113    if let Some(param_value) = p_header_origin {
114        req_builder = req_builder.header("Origin", param_value.to_string());
115    }
116    if let Some(ref apikey) = configuration.api_key {
117        let key = apikey.key.clone();
118        let value = match apikey.prefix {
119            Some(ref prefix) => format!("{prefix} {key}"),
120            None => key,
121        };
122        req_builder = req_builder.header("__session", value);
123    };
124    let mut multipart_form_params = std::collections::HashMap::new();
125    multipart_form_params.insert("signature", p_form_signature.to_string());
126    req_builder = req_builder.form(&multipart_form_params);
127
128    let req = req_builder.build()?;
129    let resp = configuration.client.execute(req).await?;
130
131    let status = resp.status();
132    let content_type = resp
133        .headers()
134        .get("content-type")
135        .and_then(|v| v.to_str().ok())
136        .unwrap_or("application/octet-stream");
137    let content_type = super::ContentType::from(content_type);
138
139    if !status.is_client_error() && !status.is_server_error() {
140        let content = resp.text().await?;
141        match content_type {
142            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
143            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedWeb3Wallet`"))),
144            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedWeb3Wallet`")))),
145        }
146    } else {
147        let content = resp.text().await?;
148        let entity: Option<AttemptWeb3WalletVerificationError> =
149            serde_json::from_str(&content).ok();
150        Err(Error::ResponseError(ResponseContent {
151            status,
152            content,
153            entity,
154        }))
155    }
156}
157
158/// Delete a web3 wallet by id.
159pub async fn delete_web3_wallet(
160    configuration: &configuration::Configuration,
161    web3_wallet_id: &str,
162) -> Result<models::ClientClientWrappedDeletedObject, Error<DeleteWeb3WalletError>> {
163    // add a prefix to parameters to efficiently prevent name collisions
164    let p_path_web3_wallet_id = web3_wallet_id;
165
166    let uri_str = format!(
167        "{}/v1/me/web3_wallets/{web3_wallet_id}",
168        configuration.base_path,
169        web3_wallet_id = crate::apis::urlencode(p_path_web3_wallet_id)
170    );
171    let mut req_builder = configuration
172        .client
173        .request(reqwest::Method::DELETE, &uri_str);
174
175    if let Some(ref apikey) = configuration.api_key {
176        let key = apikey.key.clone();
177        let value = match apikey.prefix {
178            Some(ref prefix) => format!("{prefix} {key}"),
179            None => key,
180        };
181        req_builder = req_builder.query(&[("__dev_session", value)]);
182    }
183    if let Some(ref user_agent) = configuration.user_agent {
184        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
185    }
186    if let Some(ref apikey) = configuration.api_key {
187        let key = apikey.key.clone();
188        let value = match apikey.prefix {
189            Some(ref prefix) => format!("{prefix} {key}"),
190            None => key,
191        };
192        req_builder = req_builder.header("__session", value);
193    };
194
195    let req = req_builder.build()?;
196    let resp = configuration.client.execute(req).await?;
197
198    let status = resp.status();
199    let content_type = resp
200        .headers()
201        .get("content-type")
202        .and_then(|v| v.to_str().ok())
203        .unwrap_or("application/octet-stream");
204    let content_type = super::ContentType::from(content_type);
205
206    if !status.is_client_error() && !status.is_server_error() {
207        let content = resp.text().await?;
208        match content_type {
209            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
210            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedDeletedObject`"))),
211            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedDeletedObject`")))),
212        }
213    } else {
214        let content = resp.text().await?;
215        let entity: Option<DeleteWeb3WalletError> = serde_json::from_str(&content).ok();
216        Err(Error::ResponseError(ResponseContent {
217            status,
218            content,
219            entity,
220        }))
221    }
222}
223
224/// Retrieve all web3 wallets associated with the current user.
225pub async fn get_web3_wallets(
226    configuration: &configuration::Configuration,
227    _clerk_session_id: Option<&str>,
228) -> Result<Vec<models::ClientWeb3Wallet>, Error<GetWeb3WalletsError>> {
229    // add a prefix to parameters to efficiently prevent name collisions
230    let p_query_clerk_session_id = _clerk_session_id;
231
232    let uri_str = format!("{}/v1/me/web3_wallets", configuration.base_path);
233    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
234
235    if let Some(ref param_value) = p_query_clerk_session_id {
236        req_builder = req_builder.query(&[("_clerk_session_id", &param_value.to_string())]);
237    }
238    if let Some(ref apikey) = configuration.api_key {
239        let key = apikey.key.clone();
240        let value = match apikey.prefix {
241            Some(ref prefix) => format!("{prefix} {key}"),
242            None => key,
243        };
244        req_builder = req_builder.query(&[("__dev_session", value)]);
245    }
246    if let Some(ref user_agent) = configuration.user_agent {
247        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
248    }
249    if let Some(ref apikey) = configuration.api_key {
250        let key = apikey.key.clone();
251        let value = match apikey.prefix {
252            Some(ref prefix) => format!("{prefix} {key}"),
253            None => key,
254        };
255        req_builder = req_builder.header("__session", value);
256    };
257
258    let req = req_builder.build()?;
259    let resp = configuration.client.execute(req).await?;
260
261    let status = resp.status();
262    let content_type = resp
263        .headers()
264        .get("content-type")
265        .and_then(|v| v.to_str().ok())
266        .unwrap_or("application/octet-stream");
267    let content_type = super::ContentType::from(content_type);
268
269    if !status.is_client_error() && !status.is_server_error() {
270        let content = resp.text().await?;
271        match content_type {
272            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
273            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::ClientWeb3Wallet&gt;`"))),
274            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::ClientWeb3Wallet&gt;`")))),
275        }
276    } else {
277        let content = resp.text().await?;
278        let entity: Option<GetWeb3WalletsError> = serde_json::from_str(&content).ok();
279        Err(Error::ResponseError(ResponseContent {
280            status,
281            content,
282            entity,
283        }))
284    }
285}
286
287/// Create a new web3 wallet.
288pub async fn post_web3_wallets(
289    configuration: &configuration::Configuration,
290    web3_wallet: &str,
291    _clerk_session_id: Option<&str>,
292) -> Result<models::ClientClientWrappedWeb3Wallet, Error<PostWeb3WalletsError>> {
293    // add a prefix to parameters to efficiently prevent name collisions
294    let p_form_web3_wallet = web3_wallet;
295    let p_query_clerk_session_id = _clerk_session_id;
296
297    let uri_str = format!("{}/v1/me/web3_wallets", configuration.base_path);
298    let mut req_builder = configuration
299        .client
300        .request(reqwest::Method::POST, &uri_str);
301
302    if let Some(ref param_value) = p_query_clerk_session_id {
303        req_builder = req_builder.query(&[("_clerk_session_id", &param_value.to_string())]);
304    }
305    if let Some(ref apikey) = configuration.api_key {
306        let key = apikey.key.clone();
307        let value = match apikey.prefix {
308            Some(ref prefix) => format!("{prefix} {key}"),
309            None => key,
310        };
311        req_builder = req_builder.query(&[("__dev_session", value)]);
312    }
313    if let Some(ref user_agent) = configuration.user_agent {
314        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
315    }
316    if let Some(ref apikey) = configuration.api_key {
317        let key = apikey.key.clone();
318        let value = match apikey.prefix {
319            Some(ref prefix) => format!("{prefix} {key}"),
320            None => key,
321        };
322        req_builder = req_builder.header("__session", value);
323    };
324    let mut multipart_form_params = std::collections::HashMap::new();
325    multipart_form_params.insert("web3_wallet", p_form_web3_wallet.to_string());
326    req_builder = req_builder.form(&multipart_form_params);
327
328    let req = req_builder.build()?;
329    let resp = configuration.client.execute(req).await?;
330
331    let status = resp.status();
332    let content_type = resp
333        .headers()
334        .get("content-type")
335        .and_then(|v| v.to_str().ok())
336        .unwrap_or("application/octet-stream");
337    let content_type = super::ContentType::from(content_type);
338
339    if !status.is_client_error() && !status.is_server_error() {
340        let content = resp.text().await?;
341        match content_type {
342            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
343            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedWeb3Wallet`"))),
344            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedWeb3Wallet`")))),
345        }
346    } else {
347        let content = resp.text().await?;
348        let entity: Option<PostWeb3WalletsError> = serde_json::from_str(&content).ok();
349        Err(Error::ResponseError(ResponseContent {
350            status,
351            content,
352            entity,
353        }))
354    }
355}
356
357/// Prepares verification for the provided web3 wallet.
358pub async fn prepare_web3_wallet_verification(
359    configuration: &configuration::Configuration,
360    web3_wallet_id: &str,
361    strategy: &str,
362    origin: Option<&str>,
363    redirect_url: Option<&str>,
364) -> Result<models::ClientClientWrappedWeb3Wallet, Error<PrepareWeb3WalletVerificationError>> {
365    // add a prefix to parameters to efficiently prevent name collisions
366    let p_path_web3_wallet_id = web3_wallet_id;
367    let p_form_strategy = strategy;
368    let p_header_origin = origin;
369    let p_form_redirect_url = redirect_url;
370
371    let uri_str = format!(
372        "{}/v1/me/web3_wallets/{web3_wallet_id}/prepare_verification",
373        configuration.base_path,
374        web3_wallet_id = crate::apis::urlencode(p_path_web3_wallet_id)
375    );
376    let mut req_builder = configuration
377        .client
378        .request(reqwest::Method::POST, &uri_str);
379
380    if let Some(ref apikey) = configuration.api_key {
381        let key = apikey.key.clone();
382        let value = match apikey.prefix {
383            Some(ref prefix) => format!("{prefix} {key}"),
384            None => key,
385        };
386        req_builder = req_builder.query(&[("__dev_session", value)]);
387    }
388    if let Some(ref user_agent) = configuration.user_agent {
389        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
390    }
391    if let Some(param_value) = p_header_origin {
392        req_builder = req_builder.header("Origin", param_value.to_string());
393    }
394    if let Some(ref apikey) = configuration.api_key {
395        let key = apikey.key.clone();
396        let value = match apikey.prefix {
397            Some(ref prefix) => format!("{prefix} {key}"),
398            None => key,
399        };
400        req_builder = req_builder.header("__session", value);
401    };
402    let mut multipart_form_params = std::collections::HashMap::new();
403    multipart_form_params.insert("strategy", p_form_strategy.to_string());
404    if let Some(param_value) = p_form_redirect_url {
405        multipart_form_params.insert("redirect_url", param_value.to_string());
406    }
407    req_builder = req_builder.form(&multipart_form_params);
408
409    let req = req_builder.build()?;
410    let resp = configuration.client.execute(req).await?;
411
412    let status = resp.status();
413    let content_type = resp
414        .headers()
415        .get("content-type")
416        .and_then(|v| v.to_str().ok())
417        .unwrap_or("application/octet-stream");
418    let content_type = super::ContentType::from(content_type);
419
420    if !status.is_client_error() && !status.is_server_error() {
421        let content = resp.text().await?;
422        match content_type {
423            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
424            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedWeb3Wallet`"))),
425            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedWeb3Wallet`")))),
426        }
427    } else {
428        let content = resp.text().await?;
429        let entity: Option<PrepareWeb3WalletVerificationError> =
430            serde_json::from_str(&content).ok();
431        Err(Error::ResponseError(ResponseContent {
432            status,
433            content,
434            entity,
435        }))
436    }
437}
438
439/// Retrieve all properties associated a specific web3 wallet.
440pub async fn read_web3_wallet(
441    configuration: &configuration::Configuration,
442    web3_wallet_id: &str,
443) -> Result<models::ClientClientWrappedWeb3Wallet, Error<ReadWeb3WalletError>> {
444    // add a prefix to parameters to efficiently prevent name collisions
445    let p_path_web3_wallet_id = web3_wallet_id;
446
447    let uri_str = format!(
448        "{}/v1/me/web3_wallets/{web3_wallet_id}",
449        configuration.base_path,
450        web3_wallet_id = crate::apis::urlencode(p_path_web3_wallet_id)
451    );
452    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
453
454    if let Some(ref apikey) = configuration.api_key {
455        let key = apikey.key.clone();
456        let value = match apikey.prefix {
457            Some(ref prefix) => format!("{prefix} {key}"),
458            None => key,
459        };
460        req_builder = req_builder.query(&[("__dev_session", value)]);
461    }
462    if let Some(ref user_agent) = configuration.user_agent {
463        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
464    }
465    if let Some(ref apikey) = configuration.api_key {
466        let key = apikey.key.clone();
467        let value = match apikey.prefix {
468            Some(ref prefix) => format!("{prefix} {key}"),
469            None => key,
470        };
471        req_builder = req_builder.header("__session", value);
472    };
473
474    let req = req_builder.build()?;
475    let resp = configuration.client.execute(req).await?;
476
477    let status = resp.status();
478    let content_type = resp
479        .headers()
480        .get("content-type")
481        .and_then(|v| v.to_str().ok())
482        .unwrap_or("application/octet-stream");
483    let content_type = super::ContentType::from(content_type);
484
485    if !status.is_client_error() && !status.is_server_error() {
486        let content = resp.text().await?;
487        match content_type {
488            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
489            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedWeb3Wallet`"))),
490            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedWeb3Wallet`")))),
491        }
492    } else {
493        let content = resp.text().await?;
494        let entity: Option<ReadWeb3WalletError> = serde_json::from_str(&content).ok();
495        Err(Error::ResponseError(ResponseContent {
496            status,
497            content,
498            entity,
499        }))
500    }
501}