Skip to main content

bitwarden_pm/
debug.rs

1//! Dev-only debug-capability tree, rooted on [`PasswordManagerClient`].
2//!
3//! Mirrors the public client tree, but each node exposes only debug
4//! capabilities. A node hands back a handle authored in the crate that owns the
5//! state it reaches into, so that crate's internals stay reachable. Compiled
6//! only under the `debug-capabilities` feature.
7
8use bitwarden_core::Client;
9use bitwarden_state::debug::StateRegistryDebugExt as _;
10#[cfg(feature = "wasm")]
11use wasm_bindgen::prelude::*;
12
13use crate::PasswordManagerClient;
14
15/// Root of the debug-capability tree. Routes to per-crate capability handles.
16#[cfg_attr(feature = "wasm", wasm_bindgen)]
17pub struct DebugClient {
18    client: Client,
19}
20
21impl PasswordManagerClient {
22    /// Entry point for dev-only debug capabilities (bypass the public API).
23    pub fn debug(&self) -> DebugClient {
24        // The wasm and mobile bindings build a memory-backed registry that never
25        // runs the SDK-managed migrations, so their debug index would otherwise
26        // omit SDK-managed types (e.g. `Setting`). Registering here (idempotent)
27        // makes the browse cover them wherever the tree is reachable.
28        self.0
29            .internal
30            .state_registry()
31            .debug_register_migrations(&crate::migrations::get_sdk_managed_migrations());
32        DebugClient {
33            client: self.0.clone(),
34        }
35    }
36}
37
38#[cfg_attr(feature = "wasm", wasm_bindgen)]
39impl DebugClient {
40    /// Persisted-state debug capabilities (browse the SDK's state registry).
41    /// Authored in `bitwarden-state`, where the registry lives.
42    pub fn state(&self) -> bitwarden_state::debug::StateDebug {
43        self.client.internal.state_registry().debug()
44    }
45}