Skip to content

Commit

Permalink
Tweak sdk-internal to work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Sep 27, 2024
1 parent 6c6e7f6 commit 8214f82
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 45 deletions.
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ bitwarden-send = { path = "crates/bitwarden-send", version = "=1.0.0" }
bitwarden-sm = { path = "crates/bitwarden-sm", version = "=1.0.0" }
bitwarden-vault = { path = "crates/bitwarden-vault", version = "=1.0.0" }

wasm-bindgen = { version = ">=0.2.91, <0.3", features = ["serde-serialize"] }
tsify-next = { version = ">=0.5.4, <0.6", features = [
"js",
], default-features = false }

[workspace.lints.clippy]
unused_async = "deny"
unwrap_used = "deny"
Expand Down
3 changes: 3 additions & 0 deletions crates/bitwarden-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ no-memory-hardening = [
] # Disable memory hardening features
uniffi = ["bitwarden-crypto/uniffi", "dep:uniffi"] # Uniffi bindings
secrets = [] # Secrets manager API
wasm = ["dep:wasm-bindgen", "dep:tsify-next"] # WASM support

[dependencies]
base64 = ">=0.22.1, <0.23"
Expand Down Expand Up @@ -51,8 +52,10 @@ thiserror = ">=1.0.40, <2.0"
uniffi = { version = "=0.28.1", optional = true, features = ["tokio"] }
uuid = { version = ">=1.3.3, <2.0", features = ["serde"] }
validator = { version = "0.18.1", features = ["derive"] }
wasm-bindgen = { workspace = true, optional = true }
zeroize = { version = ">=1.7.0, <2.0", features = ["derive", "aarch64"] }
zxcvbn = { version = ">=3.0.1, <4.0", optional = true }
tsify-next = { workspace = true, optional = true }

[target.'cfg(not(target_arch="wasm32"))'.dependencies]
# By default, we use rustls as the TLS stack and rust-platform-verifier to support user-installed root certificates
Expand Down
10 changes: 10 additions & 0 deletions crates/bitwarden-core/src/client/client_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(default, rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
#[cfg_attr(
feature = "wasm",
derive(tsify_next::Tsify),

Check warning on line 24 in crates/bitwarden-core/src/client/client_settings.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-core/src/client/client_settings.rs#L24

Added line #L24 was not covered by tests
tsify(into_wasm_abi, from_wasm_abi)
)]
pub struct ClientSettings {
/// The identity url of the targeted Bitwarden instance. Defaults to `https://identity.bitwarden.com`
pub identity_url: String,
Expand All @@ -44,6 +49,11 @@ impl Default for ClientSettings {
#[allow(non_camel_case_types)]
#[derive(Serialize, Deserialize, Copy, Clone, Debug, JsonSchema)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
#[cfg_attr(
feature = "wasm",
derive(tsify_next::Tsify),

Check warning on line 54 in crates/bitwarden-core/src/client/client_settings.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-core/src/client/client_settings.rs#L54

Added line #L54 was not covered by tests
tsify(into_wasm_abi, from_wasm_abi)
)]
pub enum DeviceType {
Android = 0,
iOS = 1,
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-wasm-internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ keywords.workspace = true
crate-type = ["cdylib"]

[dependencies]
bitwarden = { workspace = true }
bitwarden = { workspace = true, features = ["internal", "wasm"] }
console_error_panic_hook = "0.1.7"
console_log = { version = "1.0.0", features = ["color"] }
js-sys = "0.3.68"
Expand Down
16 changes: 2 additions & 14 deletions crates/bitwarden-wasm-internal/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ pub struct BitwardenClient(Rc<Client>);
#[wasm_bindgen]

Check warning on line 32 in crates/bitwarden-wasm-internal/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/client.rs#L32

Added line #L32 was not covered by tests
impl BitwardenClient {
#[wasm_bindgen(constructor)]
pub fn new(settings_input: Option<String>, log_level: Option<LogLevel>) -> Self {
pub fn new(settings: Option<ClientSettings>, log_level: Option<LogLevel>) -> Self {
console_error_panic_hook::set_once();
let log_level = convert_level(log_level.unwrap_or(LogLevel::Info));
if let Err(_e) = console_log::init_with_level(log_level) {
set_max_level(log_level.to_level_filter())
}

Check warning on line 40 in crates/bitwarden-wasm-internal/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/client.rs#L35-L40

Added lines #L35 - L40 were not covered by tests

Self(Rc::new(Client::new(Self::parse_settings(settings_input))))
Self(Rc::new(Client::new(settings)))
}

Check warning on line 43 in crates/bitwarden-wasm-internal/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/client.rs#L42-L43

Added lines #L42 - L43 were not covered by tests

/// Test method, echoes back the input
Expand All @@ -54,16 +54,4 @@ impl BitwardenClient {

res.text().await.map_err(|e| e.to_string())
}

Check warning on line 56 in crates/bitwarden-wasm-internal/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/client.rs#L55-L56

Added lines #L55 - L56 were not covered by tests

fn parse_settings(settings_input: Option<String>) -> Option<ClientSettings> {
if let Some(input) = settings_input.as_ref() {
match serde_json::from_str(input) {
Ok(settings) => return Some(settings),
Err(e) => {
log::error!("Failed to parse settings: {}", e);
}
}
}
None
}
}
7 changes: 6 additions & 1 deletion crates/bitwarden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ uniffi = [
"bitwarden-send/uniffi",
"bitwarden-vault/uniffi",
] # Uniffi bindings
secrets = ["bitwarden-core/secrets", "dep:bitwarden-sm", "dep:bitwarden-generators"] # Secrets manager API
secrets = [
"bitwarden-core/secrets",
"dep:bitwarden-sm",
"dep:bitwarden-generators",
] # Secrets manager API
wasm = ["bitwarden-core/wasm"] # WASM support

[dependencies]
bitwarden-api-api = { workspace = true }
Expand Down
28 changes: 0 additions & 28 deletions languages/js/sdk-internal/fallback.js

This file was deleted.

7 changes: 7 additions & 0 deletions languages/js/sdk-internal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { __wbg_set_wasm } from "./bitwarden_wasm_internal_bg.js";

export function init(wasm) {
__wbg_set_wasm(wasm);
}

export * from "./bitwarden_wasm_internal_bg.js";
2 changes: 1 addition & 1 deletion languages/js/sdk-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"node/bitwarden_wasm_internal.js"
],
"main": "node/bitwarden_wasm_internal.js",
"module": "bitwarden_wasm_internal.js",
"module": "index.js",
"types": "bitwarden_wasm_internal.d.ts",
"scripts": {},
"sideEffects": [
Expand Down

0 comments on commit 8214f82

Please sign in to comment.