Skip to content

Commit 4813492

Browse files
authored
[PM-24243] Add load_flags method to wasm PlatformClient (#369)
## 🎟️ Tracking [PM-24243](https://bitwarden.atlassian.net/browse/PM-24243) ## 📔 Objective Add `load_flags` method to the wasm `PlatformClient` to match parity with the uniffi `PlatformClient` so that the TS clients can set the SDK flags dynamically. Related Clients PR: bitwarden/clients#15855 ~Added a `FlagsInput` struct that mimics the internal `Flags` struct but with tsify bindings.~ ~Another potential option is to make the internal `Flags` struct public with wasm bindings to avoid duplicating the struct.~ ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes [PM-24243]: https://bitwarden.atlassian.net/browse/PM-24243?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 9fe3aed commit 4813492

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

crates/bitwarden-core/src/client/flags.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
#[derive(Debug, Default, Clone, serde::Deserialize)]
1+
/// Feature flags for the Bitwarden SDK client.
2+
#[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
3+
#[cfg_attr(
4+
feature = "wasm",
5+
derive(tsify::Tsify),
6+
tsify(into_wasm_abi, from_wasm_abi)
7+
)]
28
pub struct Flags {
9+
/// Enable cipher key encryption within the `CipherClient`
310
#[serde(default, rename = "enableCipherKeyEncryption")]
411
pub enable_cipher_key_encryption: bool,
512
}
613

714
impl Flags {
15+
/// Create a new `Flags` instance from a map of flag names and values.
816
pub fn load_from_map(map: std::collections::HashMap<String, bool>) -> Self {
917
let map = map
1018
.into_iter()

crates/bitwarden-core/src/client/internal.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ impl InternalClient {
116116
*self.flags.write().expect("RwLock is not poisoned") = Flags::load_from_map(flags);
117117
}
118118

119+
#[allow(missing_docs)]
120+
#[cfg(feature = "internal")]
121+
pub fn set_flags(&self, flags: &Flags) {
122+
*self.flags.write().expect("RwLock is not poisoned") = flags.clone();
123+
}
124+
119125
#[allow(missing_docs)]
120126
#[cfg(feature = "internal")]
121127
pub fn get_flags(&self) -> Flags {

crates/bitwarden-core/src/client/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ mod flags;
1919

2020
pub use client::Client;
2121
pub use client_settings::{ClientSettings, DeviceType};
22+
#[cfg(feature = "internal")]
23+
pub use flags::Flags;
2224

2325
#[allow(missing_docs)]
2426
#[cfg(feature = "internal")]

crates/bitwarden-core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub mod secrets_manager;
2424
mod util;
2525

2626
pub use bitwarden_crypto::ZeroizingAllocator;
27+
#[cfg(feature = "internal")]
28+
pub use client::Flags;
2729
pub use client::{Client, ClientSettings, DeviceType};
2830

2931
mod ids;

crates/bitwarden-wasm-internal/src/platform/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use bitwarden_core::Client;
1+
use bitwarden_core::{Client, Flags};
22
use bitwarden_vault::{Cipher, Folder};
3-
use wasm_bindgen::prelude::wasm_bindgen;
3+
use wasm_bindgen::prelude::*;
44

55
mod repository;
66
pub mod token_provider;
@@ -19,6 +19,12 @@ impl PlatformClient {
1919
pub fn state(&self) -> StateClient {
2020
StateClient::new(self.0.clone())
2121
}
22+
23+
/// Load feature flags into the client
24+
pub fn load_flags(&self, flags: Flags) -> Result<(), JsValue> {
25+
self.0.internal.set_flags(&flags);
26+
Ok(())
27+
}
2228
}
2329

2430
#[wasm_bindgen]

0 commit comments

Comments
 (0)