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