bitwarden_wasm_internal/platform/
mod.rs1use bitwarden_core::Client;
2use serde::{Deserialize, Serialize};
3use tsify::Tsify;
4use wasm_bindgen::{JsValue, prelude::wasm_bindgen};
5
6use crate::platform::repository::create_wasm_repositories;
7
8mod repository;
9pub mod token_provider;
10
11#[derive(Serialize, Deserialize, Tsify)]
13#[tsify(into_wasm_abi, from_wasm_abi)]
14pub struct FeatureFlags {
15 #[serde(flatten)]
17 flags: std::collections::HashMap<String, bool>,
18}
19
20#[wasm_bindgen]
21pub struct PlatformClient(Client);
22
23impl PlatformClient {
24 pub fn new(client: Client) -> Self {
25 Self(client)
26 }
27}
28
29#[wasm_bindgen]
30impl PlatformClient {
31 pub fn state(&self) -> StateClient {
32 StateClient::new(self.0.clone())
33 }
34
35 pub async fn load_flags(&self, flags: FeatureFlags) -> Result<(), JsValue> {
37 self.0.flags().load(flags.flags).await;
38 Ok(())
39 }
40}
41
42#[wasm_bindgen]
43pub struct StateClient(Client);
44
45impl StateClient {
46 pub fn new(client: Client) -> Self {
47 Self(client)
48 }
49}
50
51bitwarden_pm::create_client_managed_repositories!(Repositories, create_wasm_repositories);
52
53#[wasm_bindgen]
54impl StateClient {
55 pub fn register_client_managed_repositories(&self, repositories: Repositories) {
56 repositories.register_all(&self.0.platform().state());
57 }
58}