bitwarden_importers/
importer_client.rs1use bitwarden_core::Client;
2#[cfg(feature = "wasm")]
3use wasm_bindgen::prelude::*;
4
5use crate::{
6 Credentials, ImportError, ImportOptions, ImportSummary, OnePasswordImportSummary,
7 OnePasswordSignInMethods, OnePasswordTwoFactorUi, SignInAddress,
8 import::{import_kdbx, import_onepassword, onepassword_sign_in_methods},
9};
10
11#[allow(missing_docs)]
12#[cfg_attr(feature = "wasm", wasm_bindgen)]
13pub struct ImporterClient {
14 client: Client,
15}
16
17#[cfg_attr(feature = "wasm", wasm_bindgen)]
18impl ImporterClient {
19 fn new(client: Client) -> Self {
20 Self { client }
21 }
22
23 pub async fn import_kdbx(
30 &self,
31 file: Vec<u8>,
32 password: Option<String>,
33 key_file: Option<Vec<u8>>,
34 options: ImportOptions,
35 ) -> Result<ImportSummary, ImportError> {
36 import_kdbx(&self.client, file, password, key_file, options).await
37 }
38
39 pub async fn onepassword_sign_in_methods(
44 &self,
45 username: String,
46 sign_in_address: SignInAddress,
47 ) -> Result<OnePasswordSignInMethods, ImportError> {
48 onepassword_sign_in_methods(&self.client, username, sign_in_address).await
49 }
50}
51
52#[cfg(feature = "wasm")]
53#[wasm_bindgen]
54impl ImporterClient {
55 #[wasm_bindgen(js_name = import_onepassword)]
58 pub async fn import_onepassword_wasm(
59 &self,
60 credentials: Credentials,
61 two_factor: crate::wasm::RawJsOnePasswordTwoFactorUi,
62 options: ImportOptions,
63 ) -> Result<OnePasswordImportSummary, ImportError> {
64 let two_factor = crate::wasm::JsOnePasswordTwoFactorUi::new(two_factor);
65 import_onepassword(&self.client, credentials, &two_factor, options).await
66 }
67}
68
69impl ImporterClient {
71 pub async fn import_onepassword(
78 &self,
79 credentials: Credentials,
80 two_factor: &dyn OnePasswordTwoFactorUi,
81 options: ImportOptions,
82 ) -> Result<OnePasswordImportSummary, ImportError> {
83 import_onepassword(&self.client, credentials, two_factor, options).await
84 }
85}
86
87#[allow(missing_docs)]
88pub trait ImporterClientExt {
89 fn importers(&self) -> ImporterClient;
90}
91
92impl ImporterClientExt for Client {
93 fn importers(&self) -> ImporterClient {
94 ImporterClient::new(self.clone())
95 }
96}