Moving a database to an account
Turn an existing database into a vault.
importVault turns a database the user already has (a local .kdbx, or one synced with a self-hosted
server) into a new vault in their account. This is Move to account in the desktop and web apps.
import { VaultUploadError, decryptKdbx } from "@openvireo/sdk";
const { vault: localDb } = await decryptKdbx(fileBytes, password);try { const vault = await account.importVault(localDb, { name: "Home" }); // or { name, orgId } for an org vault} catch (e) { if (!(e instanceof VaultUploadError)) throw e; await e.vault.sync(); // the vault exists but its first upload failed: retry it later}- The original database is never changed. A copy is re-keyed to a fresh vault key (the database’s password
no longer opens it) and uploaded as a new vault with
If-None-Match: *. - The copy’s root group takes the vault name (by default, the root group’s current name), and its sync server settings are dropped. The rest of its database custom data comes along.
- In an organisation, the vault is sealed to every confirmed owner and admin, like any new org vault.
Tell the user the old file and the new vault are now separate: edits to one don’t reach the other.
Importing into a vault you already have
Section titled “Importing into a vault you already have”To bring a .kdbx’s entries into an existing vault (or any open database) instead, use importInto or
importAsCopies from @openvireo/sdk/merge on vault.vault (the core Vault), then sync() as after any other change:
import { decryptKdbx } from "@openvireo/sdk";import { importAsCopies, importInto } from "@openvireo/sdk/merge";
const { vault: file } = await decryptKdbx(fileBytes, password);const { added, updated, unchanged } = importInto(file, vault.vault);// or: importAsCopies(file, vault.vault, groupUuid), with importTargets(vault.vault) listing the groups to offerawait vault.sync();importIntomerges by entry and group UUID and keeps the newer version of each entry (the older goes into its history). It deletes nothing, so importing the same file twice changes nothing, and a file exported from the vault earlier just updates it.importAsCopiesputs the file’s tree, named after its root group, under the chosen group with fresh UUIDs for every entry and group; references between the copied entries ({REF:…@I:…}) follow them. Importing twice gives two copies.- Both leave out the file’s recycle bin and never change the vault’s root group, which holds its name. The file itself is not changed.
importIntoalso brings the file’s database custom data items the vault doesn’t have yet (browser integration keys, plugin settings), but never its sync server settings (KPXC_REMOTE_SYNC_SETTINGS) or generated items.importAsCopiesbrings no custom data.