bitwarden_vault/
vault_client.rs

1use bitwarden_core::Client;
2#[cfg(feature = "wasm")]
3use wasm_bindgen::prelude::*;
4
5use crate::{
6    AttachmentsClient, CipherRiskClient, CiphersClient, FoldersClient, PasswordHistoryClient,
7    TotpClient, collection_client::CollectionsClient,
8};
9
10#[allow(missing_docs)]
11#[derive(Clone)]
12#[cfg_attr(feature = "wasm", wasm_bindgen)]
13pub struct VaultClient {
14    pub(crate) client: Client,
15}
16
17impl VaultClient {
18    fn new(client: Client) -> Self {
19        Self { client }
20    }
21
22    /// Password history related operations.
23    pub fn password_history(&self) -> PasswordHistoryClient {
24        PasswordHistoryClient {
25            client: self.client.clone(),
26        }
27    }
28}
29
30#[cfg_attr(feature = "wasm", wasm_bindgen)]
31impl VaultClient {
32    /// Attachment related operations.
33    pub fn attachments(&self) -> AttachmentsClient {
34        AttachmentsClient {
35            client: self.client.clone(),
36        }
37    }
38
39    /// Cipher related operations.
40    pub fn ciphers(&self) -> CiphersClient {
41        CiphersClient {
42            client: self.client.clone(),
43        }
44    }
45
46    /// Folder related operations.
47    pub fn folders(&self) -> FoldersClient {
48        FoldersClient {
49            client: self.client.clone(),
50        }
51    }
52
53    /// TOTP related operations.
54    pub fn totp(&self) -> TotpClient {
55        TotpClient {
56            client: self.client.clone(),
57        }
58    }
59
60    /// Collection related operations.
61    pub fn collections(&self) -> CollectionsClient {
62        CollectionsClient {
63            client: self.client.clone(),
64        }
65    }
66
67    /// Cipher risk evaluation operations.
68    pub fn cipher_risk(&self) -> CipherRiskClient {
69        CipherRiskClient {
70            client: self.client.clone(),
71        }
72    }
73}
74
75#[allow(missing_docs)]
76pub trait VaultClientExt {
77    fn vault(&self) -> VaultClient;
78}
79
80impl VaultClientExt for Client {
81    fn vault(&self) -> VaultClient {
82        VaultClient::new(self.clone())
83    }
84}