Skip to main content

bitwarden_vault/
vault_client.rs

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