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