Skip to main content

bitwarden_importers/
lib.rs

1#![doc = include_str!("../README.md")]
2
3use bitwarden_collections::collection::CollectionId;
4use bitwarden_core::OrganizationId;
5use bitwarden_vault::{CipherType as VaultCipherType, FolderId};
6
7#[cfg(feature = "uniffi")]
8uniffi::setup_scaffolding!();
9#[cfg(feature = "uniffi")]
10mod uniffi_support;
11
12mod error;
13pub use error::ImportError;
14mod import;
15mod importer_client;
16pub use importer_client::{ImporterClient, ImporterClientExt};
17mod importers;
18mod pipeline;
19
20/// Destination options for a vault import.
21///
22/// `organization_id` selects the destination: `None` imports into the user's personal vault (groups
23/// become personal folders), `Some` imports into that organization (ciphers are encrypted with the
24/// org key). `target_folder` (personal) and `target_collection` (organization) nest the import
25/// under an existing destination, mirroring the client's import-target behavior; each carries both
26/// its id and name together so a half-specified target can't be expressed. `restricted_types` are
27/// dropped before submission.
28#[allow(missing_docs)]
29#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
30#[cfg_attr(
31    feature = "wasm",
32    derive(serde::Serialize, serde::Deserialize, tsify::Tsify),
33    tsify(from_wasm_abi)
34)]
35pub struct ImportOptions {
36    pub organization_id: Option<OrganizationId>,
37    pub target_folder: Option<ImportTargetFolder>,
38    pub target_collection: Option<ImportTargetCollection>,
39    // `VaultCipherType` is the wasm-bindgen enum exported as `CipherType`; pin the TS name so
40    // tsify doesn't emit the Rust alias.
41    #[cfg_attr(feature = "wasm", tsify(type = "CipherType[]"))]
42    pub restricted_types: Vec<VaultCipherType>,
43}
44
45/// An existing personal folder to nest a personal import under.
46#[allow(missing_docs)]
47#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
48#[cfg_attr(
49    feature = "wasm",
50    derive(serde::Serialize, serde::Deserialize, tsify::Tsify),
51    tsify(from_wasm_abi)
52)]
53pub struct ImportTargetFolder {
54    pub id: FolderId,
55    pub name: String,
56}
57
58/// An existing organization collection to assign an org import to.
59#[allow(missing_docs)]
60#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
61#[cfg_attr(
62    feature = "wasm",
63    derive(serde::Serialize, serde::Deserialize, tsify::Tsify),
64    tsify(from_wasm_abi)
65)]
66pub struct ImportTargetCollection {
67    pub id: CollectionId,
68    pub name: String,
69}
70
71/// Counts of what an import submitted to the server, broken down by cipher type so the client can
72/// render its per-type result table.
73#[allow(missing_docs)]
74#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
75#[cfg_attr(
76    feature = "wasm",
77    derive(serde::Serialize, serde::Deserialize, tsify::Tsify),
78    tsify(into_wasm_abi)
79)]
80pub struct ImportSummary {
81    pub ciphers: Vec<CipherTypeCount>,
82    pub folders: u32,
83    pub collections: u32,
84}
85
86/// Number of imported ciphers of a given type.
87#[allow(missing_docs)]
88#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
89#[cfg_attr(
90    feature = "wasm",
91    derive(serde::Serialize, serde::Deserialize, tsify::Tsify),
92    tsify(into_wasm_abi)
93)]
94pub struct CipherTypeCount {
95    #[cfg_attr(feature = "wasm", tsify(type = "CipherType"))]
96    pub r#type: VaultCipherType,
97    pub count: u32,
98}