bitwarden_pm/
lib.rs

1#![doc = include_str!("../README.md")]
2
3#[cfg(feature = "bitwarden-license")]
4mod commercial;
5
6use std::sync::Arc;
7
8use bitwarden_auth::{AuthClientExt as _, token_management::PasswordManagerTokenHandler};
9use bitwarden_core::auth::{ClientManagedTokenHandler, ClientManagedTokens};
10use bitwarden_exporters::ExporterClientExt as _;
11use bitwarden_generators::GeneratorClientsExt as _;
12use bitwarden_send::SendClientExt as _;
13use bitwarden_user_crypto_management::UserCryptoManagementClientExt;
14use bitwarden_vault::VaultClientExt as _;
15
16#[cfg(feature = "uniffi")]
17uniffi::setup_scaffolding!();
18
19/// Re-export subclients for easier access
20pub mod clients {
21    pub use bitwarden_auth::AuthClient;
22    pub use bitwarden_core::key_management::CryptoClient;
23    pub use bitwarden_exporters::ExporterClient;
24    pub use bitwarden_generators::GeneratorClient;
25    pub use bitwarden_send::SendClient;
26    pub use bitwarden_vault::VaultClient;
27}
28#[cfg(feature = "bitwarden-license")]
29pub use commercial::CommercialPasswordManagerClient;
30
31pub mod migrations;
32
33/// The main entry point for the Bitwarden Password Manager SDK
34pub struct PasswordManagerClient(pub bitwarden_core::Client);
35
36impl PasswordManagerClient {
37    /// Initialize a new instance of the SDK client
38    pub fn new(settings: Option<bitwarden_core::ClientSettings>) -> Self {
39        let token_handler = Arc::new(PasswordManagerTokenHandler::default());
40        Self(bitwarden_core::Client::new_with_token_handler(
41            settings,
42            token_handler,
43        ))
44    }
45
46    /// Initialize a new instance of the SDK client with client-managed tokens
47    pub fn new_with_client_tokens(
48        settings: Option<bitwarden_core::ClientSettings>,
49        tokens: Arc<dyn ClientManagedTokens>,
50    ) -> Self {
51        Self(bitwarden_core::Client::new_with_token_handler(
52            settings,
53            ClientManagedTokenHandler::new(tokens),
54        ))
55    }
56
57    /// Platform operations
58    pub fn platform(&self) -> bitwarden_core::platform::PlatformClient {
59        self.0.platform()
60    }
61
62    /// Auth operations
63    pub fn auth(&self) -> bitwarden_auth::AuthClient {
64        self.0.auth_new()
65    }
66
67    /// Bitwarden licensed operations
68    #[cfg(feature = "bitwarden-license")]
69    pub fn commercial(&self) -> CommercialPasswordManagerClient {
70        CommercialPasswordManagerClient::new(self.0.clone())
71    }
72
73    /// Crypto operations
74    pub fn crypto(&self) -> bitwarden_core::key_management::CryptoClient {
75        self.0.crypto()
76    }
77
78    /// Operations that manage the cryptographic machinery of a user account, including key-rotation
79    pub fn user_crypto_management(
80        &self,
81    ) -> bitwarden_user_crypto_management::UserCryptoManagementClient {
82        self.0.user_crypto_management()
83    }
84
85    /// Vault item operations
86    pub fn vault(&self) -> bitwarden_vault::VaultClient {
87        self.0.vault()
88    }
89
90    /// Exporter operations
91    pub fn exporters(&self) -> bitwarden_exporters::ExporterClient {
92        self.0.exporters()
93    }
94
95    /// Generator operations
96    pub fn generator(&self) -> bitwarden_generators::GeneratorClient {
97        self.0.generator()
98    }
99
100    /// Send operations
101    pub fn sends(&self) -> bitwarden_send::SendClient {
102        self.0.sends()
103    }
104}