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#[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 pub async fn sync(&self, input: &SyncRequest) -> Result<SyncResponse, SyncError> {
23 sync(&self.client, input).await
24 }
25
26 pub fn collections(&self) -> CollectionsClient {
28 CollectionsClient {
29 client: self.client.clone(),
30 }
31 }
32
33 pub fn password_history(&self) -> PasswordHistoryClient {
35 PasswordHistoryClient {
36 client: self.client.clone(),
37 }
38 }
39}
40
41#[cfg_attr(feature = "wasm", wasm_bindgen)]
42impl VaultClient {
43 pub fn attachments(&self) -> AttachmentsClient {
45 AttachmentsClient {
46 client: self.client.clone(),
47 }
48 }
49
50 pub fn ciphers(&self) -> CiphersClient {
52 CiphersClient {
53 client: self.client.clone(),
54 }
55 }
56
57 pub fn folders(&self) -> FoldersClient {
59 FoldersClient {
60 client: self.client.clone(),
61 }
62 }
63
64 pub fn totp(&self) -> TotpClient {
66 TotpClient {
67 client: self.client.clone(),
68 }
69 }
70}
71
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}