Skip to main content

bitwarden_importers/
lib.rs

1#![doc = include_str!("../README.md")]
2
3use bitwarden_collections::collection::{CollectionId, CollectionType};
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;
18pub(crate) use importers::keeper;
19pub use importers::onepassword::access::{
20    Credentials, SignInAddress, SignInDomain, SignInMethods as OnePasswordSignInMethods,
21    TotpResult as OnePasswordTotpResult, TwoFactorUi as OnePasswordTwoFactorUi,
22    model::{ItemCategory, SkippedItem, SkippedReason, SkippedVault},
23};
24mod pipeline;
25#[cfg(feature = "wasm")]
26mod wasm;
27
28/// Destination options for a vault import.
29///
30/// `organization_id` selects the destination: `None` imports into the user's personal vault (groups
31/// become personal folders), `Some` imports into that organization (ciphers are encrypted with the
32/// org key). `target_folder` (personal) and `target_collection` (organization) nest the import
33/// under an existing destination, mirroring the client's import-target behavior; each carries both
34/// its id and name together so a half-specified target can't be expressed. `restricted_types` are
35/// dropped before submission.
36#[allow(missing_docs)]
37#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
38#[cfg_attr(
39    feature = "wasm",
40    derive(serde::Serialize, serde::Deserialize, tsify::Tsify),
41    tsify(from_wasm_abi)
42)]
43pub struct ImportOptions {
44    pub organization_id: Option<OrganizationId>,
45    pub target_folder: Option<ImportTargetFolder>,
46    pub target_collection: Option<ImportTargetCollection>,
47    // `VaultCipherType` is the wasm-bindgen enum exported as `CipherType`; pin the TS name so
48    // tsify doesn't emit the Rust alias.
49    #[cfg_attr(feature = "wasm", tsify(type = "CipherType[]"))]
50    pub restricted_types: Vec<VaultCipherType>,
51}
52
53/// An existing personal folder to nest a personal import under.
54#[allow(missing_docs)]
55#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
56#[cfg_attr(
57    feature = "wasm",
58    derive(serde::Serialize, serde::Deserialize, tsify::Tsify),
59    tsify(from_wasm_abi)
60)]
61pub struct ImportTargetFolder {
62    pub id: FolderId,
63    pub name: String,
64}
65
66/// An existing organization collection to assign an org import to. `type` distinguishes the
67/// "My items" default collection (import.rs converts groups to personal folders instead of
68/// nested collections) from a normal shared collection.
69#[allow(missing_docs)]
70#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
71#[cfg_attr(
72    feature = "wasm",
73    derive(serde::Serialize, serde::Deserialize, tsify::Tsify),
74    tsify(from_wasm_abi)
75)]
76pub struct ImportTargetCollection {
77    pub id: CollectionId,
78    pub name: String,
79    pub r#type: CollectionType,
80}
81
82/// Counts of what an import submitted to the server, broken down by cipher type so the client can
83/// render its per-type result table.
84#[allow(missing_docs)]
85#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
86#[cfg_attr(
87    feature = "wasm",
88    derive(serde::Serialize, serde::Deserialize, tsify::Tsify),
89    tsify(into_wasm_abi)
90)]
91pub struct ImportSummary {
92    pub ciphers: Vec<CipherTypeCount>,
93    pub folders: u32,
94    pub collections: u32,
95}
96
97/// Result of a direct 1Password import, including source data that could not be imported.
98#[allow(missing_docs)]
99#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
100#[cfg_attr(
101    feature = "wasm",
102    derive(serde::Serialize, serde::Deserialize, tsify::Tsify),
103    tsify(into_wasm_abi)
104)]
105pub struct OnePasswordImportSummary {
106    pub imported: ImportSummary,
107    pub skipped_vaults: Vec<SkippedVault>,
108    pub skipped_items: Vec<SkippedItem>,
109}
110
111/// Number of imported ciphers of a given type.
112#[allow(missing_docs)]
113#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
114#[cfg_attr(
115    feature = "wasm",
116    derive(serde::Serialize, serde::Deserialize, tsify::Tsify),
117    tsify(into_wasm_abi)
118)]
119pub struct CipherTypeCount {
120    #[cfg_attr(feature = "wasm", tsify(type = "CipherType"))]
121    pub r#type: VaultCipherType,
122    pub count: u32,
123}