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#[allow(missing_docs)]
12#[cfg_attr(feature = "wasm", wasm_bindgen)]
13pub struct ExporterClient {
14    client: Client,
15}
16
17#[cfg_attr(feature = "wasm", wasm_bindgen)]
18impl ExporterClient {
19    fn new(client: Client) -> Self {
20        Self { client }
21    }
22
23    #[allow(missing_docs)]
24    pub fn export_vault(
25        &self,
26        folders: Vec<Folder>,
27        ciphers: Vec<Cipher>,
28        format: ExportFormat,
29    ) -> Result<String, ExportError> {
30        export_vault(&self.client, folders, ciphers, format)
31    }
32
33    #[allow(missing_docs)]
34    pub fn export_organization_vault(
35        &self,
36        collections: Vec<Collection>,
37        ciphers: Vec<Cipher>,
38        format: ExportFormat,
39    ) -> Result<String, ExportError> {
40        export_organization_vault(collections, ciphers, format)
41    }
42
43    /// Credential Exchange Format (CXF)
44    ///
45    /// *Warning:* Expect this API to be unstable, and it will change in the future.
46    ///
47    /// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
48    /// Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
49    pub fn export_cxf(
50        &self,
51        account: Account,
52        ciphers: Vec<Cipher>,
53    ) -> Result<String, ExportError> {
54        export_cxf(&self.client, account, ciphers)
55    }
56
57    /// Credential Exchange Format (CXF)
58    ///
59    /// *Warning:* Expect this API to be unstable, and it will change in the future.
60    ///
61    /// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
62    /// Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
63    pub fn import_cxf(&self, payload: String) -> Result<Vec<Cipher>, ExportError> {
64        import_cxf(&self.client, payload)
65    }
66}
67
68#[allow(missing_docs)]
69pub trait ExporterClientExt {
70    fn exporters(&self) -> ExporterClient;
71}
72
73impl ExporterClientExt for Client {
74    fn exporters(&self) -> ExporterClient {
75        ExporterClient::new(self.clone())
76    }
77}