Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add bucket scope aware vault upload paths (#2159)
Leendert de Borste1f55af79135
diff --git a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultMutate.ts b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultMutate.tsindex c6b164297..bd38d17bf 100644--- a/apps/browser-extension/src/entrypoints/popup/hooks/useVaultMutate.ts+++ b/apps/browser-extension/src/entrypoints/popup/hooks/useVaultMutate.ts@@ -5,6 +5,7 @@ import { useDb } from '@/entrypoints/popup/context/DbContext';import { devLog } from '@/utils/DevLogger';import { EncryptionUtility } from '@/utils/EncryptionUtility';import { sendMessage } from '@/utils/messaging/ExtensionMessaging';+import type { VaultMutationOptions, VaultMutationScope } from '@/utils/types/VaultMutationScope';/*** Hook to execute a vault mutation.@@ -23,7 +24,7 @@ import { sendMessage } from '@/utils/messaging/ExtensionMessaging';* even if the popup closes. This ensures vault changes are always synced to the server.*/export function useVaultMutate(): {- executeVaultMutationAsync: (operation: () => Promise<void>) => Promise<void>;+ executeVaultMutationAsync: (operation: () => Promise<void>, options?: VaultMutationOptions) => Promise<void>;} {const dbContext = useDb();const pollIntervalRef = useRef<NodeJS.Timeout | null>(null);@@ -32,7 +33,7 @@ export function useVaultMutate(): {* Execute the provided operation and save locally.* Atomically increments mutation sequence and marks dirty.*/- const saveLocally = useCallback(async (operation: () => Promise<void>): Promise<void> => {+ const saveLocally = useCallback(async (operation: () => Promise<void>, scope?: VaultMutationScope): Promise<void> => {// Execute the provided operation (e.g. create/update/delete credential)await operation();@@ -44,10 +45,15 @@ export function useVaultMutate(): {encryptionKey);- // Store the updated vault locally, mark dirty, increment mutation sequence+ /*+ * Store the updated vault locally, mark dirty, increment mutation sequence. The scope records what+ * changed: bucket-scoped mutations (e.g. 'Settings') let the background sync push just that data bucket+ * instead of the full vault manifest.+ */await sendMessage('STORE_ENCRYPTED_VAULT', {vaultBlob: encryptedVaultBlob,- markDirty: true+ markDirty: true,+ scope});// Refresh the sync state in React@@ -147,12 +153,15 @@ export function useVaultMutate(): {/*** Execute a vault mutation asynchronously: save locally immediately, then* trigger sync in background. This doesn't block the UI.+ * Pass `options.scope` for mutations that only touch bucket-scoped data (e.g. 'Settings') so the sync+ * pushes just that data bucket instead of the full vault.*/const executeVaultMutationAsync = useCallback(async (- operation: () => Promise<void>+ operation: () => Promise<void>,+ options?: VaultMutationOptions): Promise<void> => {// 1. Execute mutation and save locally (fast, doesn't block)- await saveLocally(operation);+ await saveLocally(operation, options?.scope);// 2. Trigger sync in background (fire-and-forget, continues even if popup closes)triggerBackgroundSync();diff --git a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsxindex 991ee17e8..c2345efc0 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx@@ -829,7 +829,7 @@ const ItemsList: React.FC = () => {// Save to settings and trigger vault syncawait executeVaultMutationAsync(async () => {dbContext.sqliteClient?.settings.setCredentialsSortOrder(option.value);- });+ }, { scope: 'Settings' });}}className={`w-full text-left px-4 py-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-700 flex items-center gap-2 ${sortOrder === option.value ? 'text-orange-600 dark:text-orange-400' : 'text-gray-700 dark:text-gray-300'diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/IdentityGeneratorSettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/IdentityGeneratorSettings.tsxindex b23f62d58..0958a1a59 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/settings/IdentityGeneratorSettings.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/IdentityGeneratorSettings.tsx@@ -63,7 +63,7 @@ const IdentityGeneratorSettings: React.FC = () => {if (dbContext?.sqliteClient) {await executeVaultMutationAsync(async () => {dbContext.sqliteClient!.settings.updateSetting('DefaultIdentityLanguage', newLanguage);- });+ }, { scope: 'Settings' });}}, [dbContext?.sqliteClient, executeVaultMutationAsync]);@@ -75,7 +75,7 @@ const IdentityGeneratorSettings: React.FC = () => {if (dbContext?.sqliteClient) {await executeVaultMutationAsync(async () => {dbContext.sqliteClient!.settings.updateSetting('DefaultIdentityGender', newGender);- });+ }, { scope: 'Settings' });}}, [dbContext?.sqliteClient, executeVaultMutationAsync]);@@ -87,7 +87,7 @@ const IdentityGeneratorSettings: React.FC = () => {if (dbContext?.sqliteClient) {await executeVaultMutationAsync(async () => {dbContext.sqliteClient!.settings.updateSetting('DefaultIdentityAgeRange', newAgeRange);- });+ }, { scope: 'Settings' });}}, [dbContext?.sqliteClient, executeVaultMutationAsync]);diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/PasswordGeneratorSettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/PasswordGeneratorSettings.tsxindex 2d1b20926..0d7089c27 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/settings/PasswordGeneratorSettings.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/PasswordGeneratorSettings.tsx@@ -107,7 +107,7 @@ const PasswordGeneratorSettings: React.FC = () => {if (dbContext?.sqliteClient) {void executeVaultMutationAsync(async () => {dbContext.sqliteClient!.settings.setPasswordSettings(next);- });+ }, { scope: 'Settings' });}}, [dbContext?.sqliteClient, executeVaultMutationAsync]);diff --git a/apps/browser-extension/src/utils/messaging/ExtensionMessaging.ts b/apps/browser-extension/src/utils/messaging/ExtensionMessaging.tsindex 445525bf2..86e1cf5cd 100644--- a/apps/browser-extension/src/utils/messaging/ExtensionMessaging.ts+++ b/apps/browser-extension/src/utils/messaging/ExtensionMessaging.ts@@ -23,6 +23,7 @@ import type { SaveLoginResponse } from '@/utils/types/messaging/SaveLoginResponsimport type { StringResponse } from '@/utils/types/messaging/StringResponse';import type { VaultResponse } from '@/utils/types/messaging/VaultResponse';import type { VaultUploadResponse } from '@/utils/types/messaging/VaultUploadResponse';+import type { VaultMutationScope } from '@/utils/types/VaultMutationScope';/* eslint-disable @typescript-eslint/no-explicit-any *//**@@ -93,7 +94,7 @@ export interface IExtensionMessageProtocol {SET_CLIPBOARD_CLEAR_TIMEOUT(data: number): boolean;SET_LOGIN_SAVE_ENABLED(data: boolean): BoolResponse;SET_RECENTLY_SELECTED(data: { itemId: string; domain: string }): { success: boolean };- STORE_ENCRYPTED_VAULT(data: { vaultBlob: string; markDirty?: boolean; serverRevision?: number; expectedMutationSeq?: number }): { success: boolean; mutationSequence: number };+ STORE_ENCRYPTED_VAULT(data: { vaultBlob: string; markDirty?: boolean; serverRevision?: number; expectedMutationSeq?: number; scope?: VaultMutationScope }): { success: boolean; mutationSequence: number };STORE_ENCRYPTION_KEY(data: string): BoolResponse;STORE_ENCRYPTION_KEY_DERIVATION_PARAMS(data: EncryptionKeyDerivationParams): BoolResponse;STORE_LAST_AUTOFILLED(data: LastAutofilledCredential): { success: boolean };diff --git a/apps/browser-extension/src/utils/types/VaultMutationScope.ts b/apps/browser-extension/src/utils/types/VaultMutationScope.tsnew file mode 100644index 000000000..2ac424ac5--- /dev/null+++ b/apps/browser-extension/src/utils/types/VaultMutationScope.ts@@ -0,0 +1,41 @@+/**+ * Scope of a local vault mutation. It tells the sync layer what actually changed so it can decide between a+ * full manifest push and a more efficient bucket-only push.+ */++export type VaultManifestScope = 'Main';++export type VaultBucketScope = 'Settings';++export type VaultMutationScope = VaultManifestScope | VaultBucketScope;++export const ALL_VAULT_MANIFEST_SCOPES: readonly VaultManifestScope[] = ['Main'];++export const ALL_VAULT_BUCKET_SCOPES: readonly VaultBucketScope[] = ['Settings'];++export const ALL_VAULT_MUTATION_SCOPES: readonly VaultMutationScope[] = [...ALL_VAULT_MANIFEST_SCOPES, ...ALL_VAULT_BUCKET_SCOPES];++export const DEFAULT_VAULT_MUTATION_SCOPE: VaultMutationScope = 'Main';++/**+ * True when a scope is a manifest category (i.e. a dirty flag on it requires a full manifest push, not a+ * bucket-only push).+ * @param scope - the mutation scope+ */+export const isManifestScope = (scope: VaultMutationScope): scope is VaultManifestScope =>+ (ALL_VAULT_MANIFEST_SCOPES as readonly string[]).includes(scope);++/**+ * Storage key holding the dirty flag for a single scope. Each scope gets its OWN boolean key so a mutation+ * marks exactly its scope dirty via an idempotent write.+ * @param scope - the mutation scope+ */+export const dirtyScopeStorageKey = (scope: VaultMutationScope): `local:${string}` => `local:dirtyScope:${scope}`;++/**+ * Options for executing a vault mutation.+ */+export type VaultMutationOptions = {+ /** What the mutation touches. Defaults to 'Main' (full manifest push) when omitted. */+ scope?: VaultMutationScope;+};