Skip to content

Tools/pm 31067/move sends api calls to sdk 2#756

Open
adudek-bw wants to merge 22 commits intomainfrom
tools/pm-31067/move-sends-api-calls-to-sdk-2
Open

Tools/pm 31067/move sends api calls to sdk 2#756
adudek-bw wants to merge 22 commits intomainfrom
tools/pm-31067/move-sends-api-calls-to-sdk-2

Conversation

@adudek-bw
Copy link
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-31067

📔 Objective

Add calls to the SendClient that adds/edits/gets/lists sends via API calls.

🚨 Breaking Changes

@github-actions
Copy link
Contributor

github-actions bot commented Feb 12, 2026

Logo
Checkmarx One – Scan Summary & Details0f86bf0a-1d13-4942-a498-122da0e24bcd

Great job! No new security vulnerabilities introduced in this pull request

@adudek-bw adudek-bw marked this pull request as ready for review February 12, 2026 14:10
@adudek-bw adudek-bw requested review from a team as code owners February 12, 2026 14:10
@adudek-bw adudek-bw requested a review from djsmith85 February 12, 2026 14:10
Copy link
Contributor

@harr1424 harr1424 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall! I've added some suggestions to update comments and also the return type you noticed on the call earlier.

@djsmith85 djsmith85 removed their request for review February 13, 2026 07:59
adudek-bw and others added 2 commits February 13, 2026 09:10
Co-authored-by: Daniel García <dani-garcia@users.noreply.github.com>
Co-authored-by: John Harrington <84741727+harr1424@users.noreply.github.com>
@adudek-bw adudek-bw requested a review from coroiu February 19, 2026 14:43
Copy link
Contributor

@coroiu coroiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't had a change to review the whole PR yet but I wanted to post my response regarding Oscars comments

Comment on lines +166 to +172
edit_send(
key_store,
&config.api_client,
repository.as_ref(),
send_id,
request,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: don't split out implementation into separate functions like this. If you need to organize the code into multiple files then you can create multiple impl SendClient { blocks (on in each file)

@adudek-bw adudek-bw requested review from coroiu and harr1424 March 3, 2026 13:39
@adudek-bw adudek-bw requested review from Hinton and dani-garcia March 3, 2026 13:39
harr1424
harr1424 previously approved these changes Mar 3, 2026
@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 90.27778% with 70 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.94%. Comparing base (ccc5015) to head (2b18323).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
crates/bitwarden-send/src/send_client.rs 0.00% 40 Missing ⚠️
crates/bitwarden-send/src/edit.rs 95.95% 12 Missing ⚠️
crates/bitwarden-send/src/create.rs 96.09% 8 Missing ⚠️
crates/bitwarden-send/src/send.rs 41.66% 7 Missing ⚠️
crates/bitwarden-wasm-internal/src/client.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #756      +/-   ##
==========================================
+ Coverage   81.59%   81.94%   +0.34%     
==========================================
  Files         343      347       +4     
  Lines       40624    41835    +1211     
==========================================
+ Hits        33149    34283    +1134     
- Misses       7475     7552      +77     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coroiu coroiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broken wasm build :)

@Hinton
Copy link
Member

Hinton commented Mar 5, 2026

To resolve the linting errors related to cargo fmt you can run it locally with cargo +nightly fmt.

Comment on lines +55 to +59
/// Email addresses for OTP authentication.
/// **Note**: Mutually exclusive with `new_password`. If both are set,
/// only password authentication will be used.
pub emails: Vec<String>,
pub auth_type: AuthType,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new view_type is nice. Can we do the same for auth state?

pub enum SendAuthType {
  None,
  Password(String),
  Emails(Vec<String>),
}

Comment on lines +76 to +105
let file = if let SendViewType::File(f) = self.view_type.clone() {
Some(Box::new(bitwarden_api_api::models::SendFileModel {
id: f.id.clone(),
file_name: Some(f.file_name.encrypt(ctx, send_key)?.to_string()),
size: f.size.as_ref().and_then(|s| s.parse::<i64>().ok()),
size_name: f.size_name.clone(),
}))
} else {
None
};

let text = if let SendViewType::Text(t) = self.view_type.clone() {
Some(Box::new(bitwarden_api_api::models::SendTextModel {
text: t
.text
.as_ref()
.map(|txt| txt.encrypt(ctx, send_key))
.transpose()?
.map(|e| e.to_string()),
hidden: Some(t.hidden),
}))
} else {
None
};

let t = if let SendViewType::File(_) = self.view_type {
bitwarden_api_api::models::SendType::File
} else {
bitwarden_api_api::models::SendType::Text
};
Copy link
Member

@Hinton Hinton Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I think using a match that returns a tuple would be nicer here.

The main reason is to improve readability. It's easier to reason about one branch than it is to reason about 3 "different" branches.

let (send_type, file, text) = match self.view_type.clone() {
    SendViewType::File(f) => (
        bitwarden_api_api::models::SendType::File,
        Some(Box::new(bitwarden_api_api::models::SendFileModel {
            id: f.id.clone(),
            file_name: Some(f.file_name.encrypt(ctx, send_key)?.to_string()),
            size: f.size.as_ref().and_then(|s| s.parse::<i64>().ok()),
            size_name: f.size_name.clone(),
        })),
        None,
    ),
    SendViewType::Text(t) => (
        bitwarden_api_api::models::SendType::Text,
        None,
        Some(Box::new(bitwarden_api_api::models::SendTextModel {
            text: t
                .text
                .as_ref()
                .map(|txt| txt.encrypt(ctx, send_key))
                .transpose()?
                .map(|e| e.to_string()),
            hidden: Some(t.hidden),
        })),
    ),
};

Since it's used in both create and edit it can be extracted into a method on SendViewType to ensure consistent behaviour.

deletion_date: self.deletion_date.to_rfc3339(),
file,
text,
password: self.password.clone(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: The password should go through pbkdf2 right?

This is the code fo the current encrypt_composite in SendView

self.new_password.as_ref().map(|password| {
    let password = bitwarden_crypto::pbkdf2(password.as_bytes(), &k, SEND_ITERATIONS);
    B64::from(password.as_slice()).to_string()
}),

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 5, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants