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 _;
9use bitwarden_core::client::internal::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        Self(bitwarden_core::Client::new(settings))
40    }
41
42    /// Initialize a new instance of the SDK client with client-managed tokens
43    pub fn new_with_client_tokens(
44        settings: Option<bitwarden_core::ClientSettings>,
45        tokens: Arc<dyn ClientManagedTokens>,
46    ) -> Self {
47        Self(bitwarden_core::Client::new_with_client_tokens(
48            settings, tokens,
49        ))
50    }
51
52    /// Platform operations
53    pub fn platform(&self) -> bitwarden_core::platform::PlatformClient {
54        self.0.platform()
55    }
56
57    /// Auth operations
58    pub fn auth(&self) -> bitwarden_auth::AuthClient {
59        self.0.auth_new()
60    }
61
62    /// Bitwarden licensed operations
63    #[cfg(feature = "bitwarden-license")]
64    pub fn commercial(&self) -> CommercialPasswordManagerClient {
65        CommercialPasswordManagerClient::new(self.0.clone())
66    }
67
68    /// Crypto operations
69    pub fn crypto(&self) -> bitwarden_core::key_management::CryptoClient {
70        self.0.crypto()
71    }
72
73    /// Operations that manage the cryptographic machinery of a user account, including key-rotation
74    pub fn user_crypto_management(
75        &self,
76    ) -> bitwarden_user_crypto_management::UserCryptoManagementClient {
77        self.0.user_crypto_management()
78    }
79
80    /// Vault item operations
81    pub fn vault(&self) -> bitwarden_vault::VaultClient {
82        self.0.vault()
83    }
84
85    /// Exporter operations
86    pub fn exporters(&self) -> bitwarden_exporters::ExporterClient {
87        self.0.exporters()
88    }
89
90    /// Generator operations
91    pub fn generator(&self) -> bitwarden_generators::GeneratorClient {
92        self.0.generator()
93    }
94
95    /// Send operations
96    pub fn sends(&self) -> bitwarden_send::SendClient {
97        self.0.sends()
98    }
99}