Skip to content

Format WASM generator code to be in line with other clients #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/bitwarden-generators/src/generator_client.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
use bitwarden_core::Client;
#[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*;

use crate::{
passphrase::passphrase, password::password, username::username, PassphraseError,
PassphraseGeneratorRequest, PasswordError, PasswordGeneratorRequest, UsernameError,
UsernameGeneratorRequest,
};

#[cfg_attr(feature = "wasm", wasm_bindgen)]
pub struct GeneratorClient {
client: Client,
}

#[cfg_attr(feature = "wasm", wasm_bindgen)]
impl GeneratorClient {
fn new(client: Client) -> Self {
Self { client }
Expand Down Expand Up @@ -68,7 +72,9 @@ impl GeneratorClient {
pub fn passphrase(&self, input: PassphraseGeneratorRequest) -> Result<String, PassphraseError> {
passphrase(input)
}
}

impl GeneratorClient {
/// Generates a random username.
/// There are different username generation strategies, which can be customized using the
/// `input` parameter.
Expand Down
7 changes: 7 additions & 0 deletions crates/bitwarden-generators/src/username.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bitwarden_crypto::EFF_LONG_WORD_LIST;
use bitwarden_error::bitwarden_error;
use rand::{distributions::Distribution, seq::SliceRandom, Rng, RngCore};
use reqwest::StatusCode;
use schemars::JsonSchema;
Expand All @@ -7,6 +8,7 @@

use crate::util::capitalize_first_letter;

#[bitwarden_error(flat)]

Check warning on line 11 in crates/bitwarden-generators/src/username.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-generators/src/username.rs#L11

Added line #L11 was not covered by tests
#[derive(Debug, Error)]
pub enum UsernameError {
#[error("Invalid API Key")]
Expand Down Expand Up @@ -66,6 +68,11 @@
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
#[cfg_attr(
feature = "wasm",
derive(tsify_next::Tsify),
tsify(into_wasm_abi, from_wasm_abi)
)]
pub enum UsernameGeneratorRequest {
/// Generates a single word username
Word {
Expand Down
7 changes: 4 additions & 3 deletions crates/bitwarden-wasm-internal/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
use bitwarden_core::{Client, ClientSettings};
use bitwarden_error::bitwarden_error;
use bitwarden_exporters::ExporterClientExt;
use bitwarden_generators::GeneratorClientsExt;
use bitwarden_vault::VaultClientExt;
use wasm_bindgen::prelude::*;

use crate::{CryptoClient, GeneratorClient, VaultClient};
use crate::{CryptoClient, VaultClient};

#[wasm_bindgen]
pub struct BitwardenClient(pub(crate) Client);
Expand Down Expand Up @@ -49,8 +50,8 @@
}

/// Constructs a specific client for generating passwords and passphrases
pub fn generator(&self) -> GeneratorClient {
GeneratorClient::new(self.0.clone())
pub fn generator(&self) -> bitwarden_generators::GeneratorClient {
self.0.generator()

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

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/client.rs#L53-L54

Added lines #L53 - L54 were not covered by tests
}

pub fn exporters(&self) -> bitwarden_exporters::ExporterClient {
Expand Down
54 changes: 0 additions & 54 deletions crates/bitwarden-wasm-internal/src/generators.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/bitwarden-wasm-internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
mod client;
mod crypto;
mod custom_types;
mod generators;
mod init;
mod pure_crypto;
mod ssh;
Expand All @@ -12,6 +11,5 @@ mod vault;
pub use bitwarden_ipc::wasm::*;
pub use client::BitwardenClient;
pub use crypto::CryptoClient;
pub use generators::GeneratorClient;
pub use init::init_sdk;
pub use vault::{folders::FoldersClient, VaultClient};