bitwarden_importers/
importer_client.rs1use bitwarden_core::Client;
2#[cfg(feature = "wasm")]
3use wasm_bindgen::prelude::*;
4
5use crate::{
6 Credentials, ImportError, ImportOptions, ImportSummary, OnePasswordTwoFactorUi,
7 import::{import_kdbx, import_onepassword},
8};
9
10#[allow(missing_docs)]
11#[cfg_attr(feature = "wasm", wasm_bindgen)]
12pub struct ImporterClient {
13 client: Client,
14}
15
16#[cfg_attr(feature = "wasm", wasm_bindgen)]
17impl ImporterClient {
18 fn new(client: Client) -> Self {
19 Self { client }
20 }
21
22 pub async fn import_kdbx(
29 &self,
30 file: Vec<u8>,
31 password: Option<String>,
32 key_file: Option<Vec<u8>>,
33 options: ImportOptions,
34 ) -> Result<ImportSummary, ImportError> {
35 import_kdbx(&self.client, file, password, key_file, options).await
36 }
37}
38
39impl ImporterClient {
41 pub async fn import_onepassword(
48 &self,
49 credentials: Credentials,
50 two_factor: &dyn OnePasswordTwoFactorUi,
51 options: ImportOptions,
52 ) -> Result<ImportSummary, ImportError> {
53 import_onepassword(&self.client, credentials, two_factor, options).await
54 }
55}
56
57#[allow(missing_docs)]
58pub trait ImporterClientExt {
59 fn importers(&self) -> ImporterClient;
60}
61
62impl ImporterClientExt for Client {
63 fn importers(&self) -> ImporterClient {
64 ImporterClient::new(self.clone())
65 }
66}