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    }
52
53    /// Collection related operations.
54    ///
55    /// This nested accessor is kept for backwards compatibility. New callers should prefer the
56    /// `collections()` accessor registered directly on the top-level Password Manager client.
57    pub fn collections(&self) -> CollectionsClient {
58        CollectionsClient::from_client(&self.client)
59    }
60
61    /// Cipher risk evaluation operations.
62    pub fn cipher_risk(&self) -> CipherRiskClient {
63        CipherRiskClient {
64            client: self.client.clone(),
65        }
66    }
67}
68
69#[allow(missing_docs)]
70pub trait VaultClientExt {
71    fn vault(&self) -> VaultClient;
72}
73
74impl VaultClientExt for Client {
75    fn vault(&self) -> VaultClient {
76        VaultClient::new(self.clone())
77    }
78}