Skip to main content

bitwarden_vault/
vault_client.rs

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