Skip to main content

bitwarden_wasm_internal/platform/
mod.rs

1use bitwarden_core::Client;
2use serde::{Deserialize, Serialize};
3use wasm_bindgen::{JsValue, prelude::wasm_bindgen};
4
5use crate::platform::repository::create_wasm_repositories;
6
7mod repository;
8pub mod token_provider;
9
10/// Active feature flags for the SDK.
11#[bitwarden_ffi::wasm_record]
12#[derive(Serialize, Deserialize)]
13pub struct FeatureFlags {
14    /// We intentionally use a loose type here to allow for future flags without breaking changes.
15    #[serde(flatten)]
16    flags: std::collections::HashMap<String, bool>,
17}
18
19#[bitwarden_ffi::wasm_object]
20pub struct PlatformClient(Client);
21
22impl PlatformClient {
23    pub fn new(client: Client) -> Self {
24        Self(client)
25    }
26}
27
28#[bitwarden_ffi::wasm_export]
29impl PlatformClient {
30    pub fn state(&self) -> StateClient {
31        StateClient::new(self.0.clone())
32    }
33
34    /// Load feature flags into the client
35    pub async fn load_flags(&self, flags: FeatureFlags) -> Result<(), JsValue> {
36        self.0.flags().load(flags.flags).await;
37        Ok(())
38    }
39}
40
41#[bitwarden_ffi::wasm_object]
42pub struct StateClient(Client);
43
44impl StateClient {
45    pub fn new(client: Client) -> Self {
46        Self(client)
47    }
48}
49
50bitwarden_pm::create_client_managed_repositories!(Repositories, create_wasm_repositories);
51
52#[bitwarden_ffi::wasm_export]
53impl StateClient {
54    pub fn register_client_managed_repositories(&self, repositories: Repositories) {
55        repositories.register_all(&self.0.platform().state());
56    }
57}