bitwarden_exporters/
exporter_client.rs

1use 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    /// Credential Exchange Format (CXF)
41    ///
42    /// *Warning:* Expect this API to be unstable, and it will change in the future.
43    ///
44    /// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
45    /// Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
46    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    /// Credential Exchange Format (CXF)
55    ///
56    /// *Warning:* Expect this API to be unstable, and it will change in the future.
57    ///
58    /// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
59    /// Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
60    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}