bitwarden_exporters/
exporter_client.rs1use bitwarden_core::Client;
2use bitwarden_vault::{Cipher, Collection, Folder};
3#[cfg(feature = "wasm")]
4use wasm_bindgen::prelude::*;
5
6use crate::{
7 export::{export_cxf, export_organization_vault, export_vault, import_cxf},
8 Account, ExportError, ExportFormat,
9};
10
11#[cfg_attr(feature = "wasm", wasm_bindgen)]
12pub struct ExporterClient {
13 client: Client,
14}
15
16#[cfg_attr(feature = "wasm", wasm_bindgen)]
17impl ExporterClient {
18 fn new(client: Client) -> Self {
19 Self { client }
20 }
21
22 pub fn export_vault(
23 &self,
24 folders: Vec<Folder>,
25 ciphers: Vec<Cipher>,
26 format: ExportFormat,
27 ) -> Result<String, ExportError> {
28 export_vault(&self.client, folders, ciphers, format)
29 }
30
31 pub fn export_organization_vault(
32 &self,
33 collections: Vec<Collection>,
34 ciphers: Vec<Cipher>,
35 format: ExportFormat,
36 ) -> Result<String, ExportError> {
37 export_organization_vault(collections, ciphers, format)
38 }
39
40 pub fn export_cxf(
47 &self,
48 account: Account,
49 ciphers: Vec<Cipher>,
50 ) -> Result<String, ExportError> {
51 export_cxf(&self.client, account, ciphers)
52 }
53
54 pub fn import_cxf(&self, payload: String) -> Result<Vec<Cipher>, ExportError> {
61 import_cxf(&self.client, payload)
62 }
63}
64
65pub trait ExporterClientExt {
66 fn exporters(&self) -> ExporterClient;
67}
68
69impl ExporterClientExt for Client {
70 fn exporters(&self) -> ExporterClient {
71 ExporterClient::new(self.clone())
72 }
73}