bitwarden_vault/
vault_client.rs1use bitwarden_core::Client;
2#[cfg(feature = "wasm")]
3use wasm_bindgen::prelude::*;
4
5use crate::{
6 sync::{sync, SyncError},
7 AttachmentsClient, CiphersClient, CollectionsClient, FoldersClient, PasswordHistoryClient,
8 SyncRequest, SyncResponse, 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 #[allow(missing_docs)]
24 pub async fn sync(&self, input: &SyncRequest) -> Result<SyncResponse, SyncError> {
25 sync(&self.client, input).await
26 }
27
28 pub fn collections(&self) -> CollectionsClient {
30 CollectionsClient {
31 client: self.client.clone(),
32 }
33 }
34
35 pub fn password_history(&self) -> PasswordHistoryClient {
37 PasswordHistoryClient {
38 client: self.client.clone(),
39 }
40 }
41}
42
43#[cfg_attr(feature = "wasm", wasm_bindgen)]
44impl VaultClient {
45 pub fn attachments(&self) -> AttachmentsClient {
47 AttachmentsClient {
48 client: self.client.clone(),
49 }
50 }
51
52 pub fn ciphers(&self) -> CiphersClient {
54 CiphersClient {
55 client: self.client.clone(),
56 }
57 }
58
59 pub fn folders(&self) -> FoldersClient {
61 FoldersClient {
62 client: self.client.clone(),
63 }
64 }
65
66 pub fn totp(&self) -> TotpClient {
68 TotpClient {
69 client: self.client.clone(),
70 }
71 }
72}
73
74#[allow(missing_docs)]
75pub trait VaultClientExt {
76 fn vault(&self) -> VaultClient;
77}
78
79impl VaultClientExt for Client {
80 fn vault(&self) -> VaultClient {
81 VaultClient::new(self.clone())
82 }
83}