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