Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Tweak app error codes and cleanup (#2159)
Leendert de Borstaa0d2f31daae
diff --git a/apps/browser-extension/src/utils/constants/storageKeys.ts b/apps/browser-extension/src/utils/constants/storageKeys.tsindex aafa112b5..002fc9ce6 100644--- a/apps/browser-extension/src/utils/constants/storageKeys.ts+++ b/apps/browser-extension/src/utils/constants/storageKeys.ts@@ -12,7 +12,7 @@ import {import { LEGACY_VAULT_DATA_STORAGE_KEYS } from '@/utils/constants/legacyStorageKeys';-export { bucketRevisionKey, dirtyScopeStorageKey, type StorageKey } from '@aliasvault/client/constants/StorageKeys';+export { dirtyScopeStorageKey, type StorageKey } from '@aliasvault/client/constants/StorageKeys';export const StorageKeys = {...CoreStorageKeys,diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyFormFragment.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyFormFragment.ktindex 69785af47..b56fd379b 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyFormFragment.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyFormFragment.kt@@ -988,7 +988,7 @@ class PasskeyFormFragment : Fragment() {}is net.aliasvault.app.vaultstore.AppError.NetworkError,- is net.aliasvault.app.vaultstore.AppError.Timeout,+ is net.aliasvault.app.vaultstore.AppError.VaultSyncTimeout,-> {title = getString(R.string.network_error_title)message = getString(R.string.network_error_message)diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/RustCoreDispatcher.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/RustCoreDispatcher.ktindex 2302f0dfa..a35ca6607 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/RustCoreDispatcher.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/RustCoreDispatcher.kt@@ -19,7 +19,6 @@ import uniffi.aliasvault_core.getIdentityAgeRangesimport uniffi.aliasvault_core.getIdentityLanguagesimport uniffi.aliasvault_core.getPruneTableQueriesimport uniffi.aliasvault_core.getSyncableTableNames-import uniffi.aliasvault_core.mergeCanonicalJsonimport uniffi.aliasvault_core.parseEmailSourceimport uniffi.aliasvault_core.pruneVaultJsonimport uniffi.aliasvault_core.selectFaviconTarget@@ -100,7 +99,6 @@ object RustCoreDispatcher {}"getSyncableTableNames" -> json(getSyncableTableNames())- "mergeCanonicalJson" -> mergeCanonicalJson(args.string(0))"pruneVaultJson" -> pruneVaultJson(args.string(0))"getPruneTableQueries" -> {val queries = JSONArray()diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/AppError.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/AppError.ktindex 21d0003b4..02465aefc 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/AppError.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/AppError.kt@@ -55,14 +55,6 @@ sealed class AppError(message: String, cause: Throwable? = null) : Exception(mesval underlyingError: Throwable,) : AppError("Network error: ${underlyingError.message}", underlyingError)- /**- * Error indicating request timeout.- */- class Timeout(- message: String = "Request timeout",- cause: Throwable? = null,- ) : AppError(message, cause)-/*** Error indicating the server answered a request with an unexpected HTTP failure.*/@@ -334,6 +326,14 @@ sealed class AppError(message: String, cause: Throwable? = null) : Exception(mescause: Throwable? = null,) : AppError(message, cause)+ /**+ * Error indicating a vault transfer exceeded its request timeout (large vault or slow connection).+ */+ class VaultSyncTimeout(+ message: String = "Vault sync timed out",+ cause: Throwable? = null,+ ) : AppError(message, cause)+/*** Error indicating max sync retries reached.*/@@ -414,7 +414,6 @@ sealed class AppError(message: String, cause: Throwable? = null) : Exception(mesis PasswordChanged -> "E-103"is ServerUnavailable -> "E-201"is NetworkError -> "E-202"- is Timeout -> "E-203"is ServerError -> "E-204"is ClientVersionNotSupported -> "E-301"is ServerVersionNotSupported -> "E-302"@@ -448,6 +447,7 @@ sealed class AppError(message: String, cause: Throwable? = null) : Exception(mesis MergeUploadFailed -> "E-705"is VaultUploadFailed -> "E-801"is VaultTooLarge -> "E-804"+ is VaultSyncTimeout -> "E-805"is MaxRetriesReached -> "E-901"is MigrationCheckFailed -> "E-903"is UnknownError -> "E-001"diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultSync.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultSync.ktindex bb7b698b0..444cbbec8 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultSync.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultSync.kt@@ -223,7 +223,7 @@ class VaultSync(// The engine's message is diagnostic detail; the code decides what the user sees.val message = result.optString("error", "Vault sync failed")return when (result.optString("errorCode")) {- "E-805" -> AppError.Timeout()+ "E-805" -> AppError.VaultSyncTimeout()"E-804" -> AppError.VaultTooLarge()"E-903" -> AppError.ServerUpdateRequired()"E-901" -> AppError.MigrationCheckFailed(message)diff --git a/apps/mobile-app/hooks/useVaultSync.ts b/apps/mobile-app/hooks/useVaultSync.tsindex fac0d2d0b..178e3c9bc 100644--- a/apps/mobile-app/hooks/useVaultSync.ts+++ b/apps/mobile-app/hooks/useVaultSync.ts@@ -300,8 +300,7 @@ async function handleSyncError(await app.logout(messageWithCode);return false;- // Network errors - set offline mode, don't logout.- case AppErrorCode.SERVER_UNAVAILABLE:+ // Server unreachable: offline mode, don't logout.case AppErrorCode.NETWORK_ERROR:await dbContext.setIsOffline(true);onOffline?.();diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swiftindex abbc72744..4f3c1909d 100644--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift@@ -600,7 +600,7 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlletitle = NSLocalizedString("server_unavailable_title", comment: "Server Unavailable")message = NSLocalizedString("server_unavailable_message", comment: "The server is currently unavailable. Please try again later.")- case .networkError, .timeout:+ case .networkError, .vaultSyncTimeout:title = NSLocalizedString("network_error_title", comment: "Network Error")message = NSLocalizedString("network_error_message", comment: "A network error occurred. Please check your connection and try again.")diff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swiftindex 47f688fd8..eb024c34a 100644--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift@@ -1571,7 +1571,6 @@ private enum RustCoreDispatcher {return try json(["proof": session.proof, "key": session.key])case "getSyncableTableNames": return try json(RustCoreFramework.getSyncableTableNames())- case "mergeCanonicalJson": return try RustCoreFramework.mergeCanonicalJson(inputJson: try args.string(0))case "pruneVaultJson": return try RustCoreFramework.pruneVaultJson(inputJson: try args.string(0))case "getPruneTableQueries": return try json(RustCoreFramework.getPruneTableQueries().map { ["name": $0.name, "query": $0.query] })diff --git a/apps/mobile-app/ios/VaultStoreKit/Enums/AppError.swift b/apps/mobile-app/ios/VaultStoreKit/Enums/AppError.swiftindex bdbfb6c55..b649f389d 100644--- a/apps/mobile-app/ios/VaultStoreKit/Enums/AppError.swift+++ b/apps/mobile-app/ios/VaultStoreKit/Enums/AppError.swift@@ -11,7 +11,6 @@ public enum AppError: Error {// Network/connectivity errorscase serverUnavailable(statusCode: Int)case networkError(underlyingError: Error)- case timeoutcase serverError(message: String)// Version/compatibility errors@@ -61,6 +60,9 @@ public enum AppError: Error {/// exceeds the configured MAX_UPLOAD_SIZE_MB limit on the server.case vaultTooLarge+ /// A vault transfer exceeded its request timeout (large vault or slow connection).+ case vaultSyncTimeout+// Retry errorscase maxRetriesReachedcase migrationCheckFailed(message: String)@@ -99,8 +101,6 @@ public enum AppError: Error {return "E-201"case .networkError:return "E-202"- case .timeout:- return "E-203"case .serverError:return "E-204"case .clientVersionNotSupported:@@ -167,6 +167,8 @@ public enum AppError: Error {return "E-801"case .vaultTooLarge:return "E-804"+ case .vaultSyncTimeout:+ return "E-805"case .maxRetriesReached:return "E-901"case .migrationCheckFailed:@@ -197,8 +199,6 @@ public enum AppError: Error {return "Server unavailable (status: \(statusCode))"case .networkError(let error):return "Network error: \(error.localizedDescription)"- case .timeout:- return "Request timeout"case .serverError(let message):return "Server error: \(message)"case .clientVersionNotSupported:@@ -265,6 +265,8 @@ public enum AppError: Error {return "Vault upload failed: \(message)"case .vaultTooLarge:return "Vault too large for server"+ case .vaultSyncTimeout:+ return "Vault sync timed out"case .maxRetriesReached:return "Max sync retries reached"case .migrationCheckFailed(let message):diff --git a/apps/mobile-app/ios/VaultStoreKit/Services/VaultSync.swift b/apps/mobile-app/ios/VaultStoreKit/Services/VaultSync.swiftindex 2a5dc350d..85a7eeb5c 100644--- a/apps/mobile-app/ios/VaultStoreKit/Services/VaultSync.swift+++ b/apps/mobile-app/ios/VaultStoreKit/Services/VaultSync.swift@@ -219,7 +219,7 @@ internal final class VaultSync {"E-702": { _ in .maxRetriesReached },"E-801": { .vaultUploadFailed(message: $0) },"E-804": { _ in .vaultTooLarge },- "E-805": { _ in .timeout },+ "E-805": { _ in .vaultSyncTimeout },"E-901": { .migrationCheckFailed(message: $0) },"E-903": { _ in .serverUpdateRequired }]diff --git a/apps/mobile-app/utils/types/errors/AppErrorCodes.ts b/apps/mobile-app/utils/types/errors/AppErrorCodes.tsindex 9602ec06b..166a4f791 100644--- a/apps/mobile-app/utils/types/errors/AppErrorCodes.ts+++ b/apps/mobile-app/utils/types/errors/AppErrorCodes.ts@@ -36,7 +36,6 @@ export enum AppErrorCode {// Network/connectivity errors (E-2xx) - from AppError.ktSERVER_UNAVAILABLE = 'E-201',NETWORK_ERROR = 'E-202',- TIMEOUT = 'E-203',SERVER_ERROR = 'E-204', // The server answered a sync request with an unexpected HTTP failure// Version/compatibility errors (E-3xx) - from AppError.kt@@ -83,6 +82,7 @@ export enum AppErrorCode {// Upload errors (E-8xx) - from VaultSync.ktUPLOAD_FAILED = 'E-801', // AppError: vault upload failedUPLOAD_TOO_LARGE = 'E-804', // Server rejected upload with HTTP 413 (vault exceeds MAX_UPLOAD_SIZE_MB)+ UPLOAD_TIMEOUT = 'E-805', // Sync engine: a vault transfer exceeded its request timeout (large vault or slow connection)// Native module/retry errors (E-9xx)MAX_RETRIES_REACHED = 'E-901', // AppError: max sync retries reached@@ -218,7 +218,6 @@ export function getErrorTranslationKey(code: AppErrorCode): string {// Network errors[AppErrorCode.SERVER_UNAVAILABLE]: 'auth.errors.serverError',[AppErrorCode.NETWORK_ERROR]: 'auth.errors.networkError',- [AppErrorCode.TIMEOUT]: 'auth.errors.networkError',[AppErrorCode.SERVER_ERROR]: 'auth.errors.serverError',// Version errors@@ -256,6 +255,7 @@ export function getErrorTranslationKey(code: AppErrorCode): string {[AppErrorCode.STORAGE_WRITE_FAILED]: 'common.errors.unknownErrorTryAgain',[AppErrorCode.DATABASE_INIT_FAILED]: 'common.errors.unknownErrorTryAgain',[AppErrorCode.VAULT_STORE_FAILED]: 'common.errors.unknownErrorTryAgain',+ [AppErrorCode.MANIFEST_NOT_RECORDED]: 'common.errors.unknownErrorTryAgain',// Merge errors[AppErrorCode.MERGE_FAILED]: 'common.errors.unknownErrorTryAgain',@@ -264,6 +264,7 @@ export function getErrorTranslationKey(code: AppErrorCode): string {// Upload errors[AppErrorCode.UPLOAD_FAILED]: 'common.errors.unknownErrorTryAgain',[AppErrorCode.UPLOAD_TOO_LARGE]: 'common.errors.vaultTooLarge',+ [AppErrorCode.UPLOAD_TIMEOUT]: 'common.errors.vaultSyncTimeout',// Native module/retry errors[AppErrorCode.MAX_RETRIES_REACHED]: 'common.errors.unknownErrorTryAgain',diff --git a/core/client/src/constants/StorageKeys.ts b/core/client/src/constants/StorageKeys.tsindex 0d8cd9eda..8a449e437 100644--- a/core/client/src/constants/StorageKeys.ts+++ b/core/client/src/constants/StorageKeys.ts@@ -104,13 +104,6 @@ export const StorageKeys = {*/export const dirtyScopeStorageKey = (scope: VaultMutationScope): `local:${string}` => `local:dirtyScope:${scope}`;-/**- * Record key of one data bucket's revision inside {@link StorageKeys.VAULT_BUCKET_REVISIONS}, addressed by the manifest that owns it and the category.- * @param manifestId - the id of the manifest that owns the bucket- * @param category - the data bucket category- */-export const bucketRevisionKey = (manifestId: string, category: string): string => `${manifestId}:${category}`;-/** Keys that hold auth tokens, ephemeral error state and account-scoped server state. Cleared on any logout. */export const AUTH_STORAGE_KEYS: readonly StorageKey[] = [StorageKeys.ACCESS_TOKEN,diff --git a/core/client/src/rust/RustCore.ts b/core/client/src/rust/RustCore.tsindex cfb594b4c..de618be23 100644--- a/core/client/src/rust/RustCore.ts+++ b/core/client/src/rust/RustCore.ts@@ -26,13 +26,6 @@ export function rustCore(): IRustCore {return getPlatform().rustCore;}-/**- * Initialize the Rust core.- */-export function initRustCore(): Promise<void> {- return rustCore().init();-}-/*** Extract the host (subdomain + domain) from a URL.* Example: `https://www.example.com/path` > `example.com`.diff --git a/core/client/src/sync/LegacyStorageModelMigration.ts b/core/client/src/sync/LegacyStorageModelMigration.tsindex 7940539bf..f161539f5 100644--- a/core/client/src/sync/LegacyStorageModelMigration.ts+++ b/core/client/src/sync/LegacyStorageModelMigration.ts@@ -1,18 +1,11 @@/*** Legacy storage model migration specific logic.- *+ ** TODO: these methods and file can be deleted later once all users have migrated from sqlite-blob to manifest-v1.*/-import { ApiRequestError } from '../api/errors/ApiRequestError';import { ServerUpdateRequiredError } from '../api/errors/ServerUpdateRequiredError';import { VaultKeyService } from '../auth/VaultKeyService';-import { StorageKeys } from '../constants/StorageKeys';-import { createAccountKeyHierarchy, type AccountKeyBlobs } from '../crypto/AccountKeys';-import { getPlatform } from '../platform/ClientPlatform';-import { devLog } from '../platform/Logger';--import { replaceManifestRevisions } from './ManifestRevisions';/** -- 1. Servers predating the v2 vault API --@@ -21,15 +14,6 @@ import { replaceManifestRevisions } from './ManifestRevisions';/** How long the legacy-API probe may take before we stop blaming the server version. */const V1_PROBE_TIMEOUT_MS = 3000;-/**- * True when an error from WebApiService is an HTTP 404. Every non-2xx response from authFetch surfaces as an- * {@link ApiRequestError} carrying the status code.- * @param e - the caught error- */-function isNotFoundError(e: unknown): boolean {- return e instanceof ApiRequestError && e.statusCode === 404;-}-/*** Probe whether the configured server answers on the v1 API while v2 does not respond.* @param apiBaseUrl - the configured API base URL, without a version segment@@ -66,119 +50,9 @@ export async function throwIfServerPredatesV2Api(status: number, apiBaseUrl: str}}-/**- * Run a v2 API call, translating the outdated-server 404 into {@link ServerUpdateRequiredError}.- * @param fn - the call to run- */-export async function withOutdatedServerGuard<T>(fn: () => Promise<T>): Promise<T> {- try {- return await fn();- } catch (e) {- if (isNotFoundError(e)) {- throw new ServerUpdateRequiredError();- }- throw e;- }-}-/*- * -- 2. The sqlite-blob storage model --- */--/** Numeric value of the server StorageFormat enum for the manifest-v1 format (SqliteBlob = 0, Manifest = 1). */-const STORAGE_FORMAT_MANIFEST = 1;--/**- * The GET /v2/Vault fields that only a legacy sqlite-blob response carries. Structurally satisfied by the full- * snapshot type, so callers pass the snapshot itself.- */-export type LegacySqliteBlobSnapshot = {- /** The server's storage format (0 = sqlite-blob, 1 = manifest-v1). Absent on servers predating the field. */- storageFormat?: number;- /** The legacy encrypted SQLite blob. */- legacyVaultBlob?: string | null;- /** The legacy sqlite-blob revision. */- legacyRevision?: number | null;- /** Data-model version string of the legacy blob. */- version?: string | null;- /** The manifest id the server has already reserved for this user's personal manifest. */- personalManifestId?: string | null;-};--/** The already-encrypted blob to store locally, plus the metadata a VaultResponse needs alongside it. */-export type LegacySqliteBlobPassthrough = {- encryptedBlob: string;- version: string;- revision: number;-};--/**- * Whether the server answered with anything other than manifest-v1, which means the legacy sqlite-blob format- * (including a server too old to report the field at all).- * @param snapshot - the raw GET /v2/Vault response+ * -- 2. The missing KEK/VEK account key hierarchy --*/-export function isLegacySqliteBlobSnapshot(snapshot: LegacySqliteBlobSnapshot): boolean {- return snapshot.storageFormat !== STORAGE_FORMAT_MANIFEST;-}--/**- * Take a legacy snapshot apart for local storage. The blob is already in the stored format (encrypted SQLite),- * so it passes through untouched and the on-open schema upgrade handles the rest; this only resets the local- * state that manifest-v1 owns and records the manifest id the migration push will stamp rows with.- * @param snapshot - the raw GET /v2/Vault response- */-export async function openLegacySqliteBlobSnapshot(snapshot: LegacySqliteBlobSnapshot): Promise<LegacySqliteBlobPassthrough> {- // There is no manifest-v1 server state behind this snapshot, so any content fingerprint we hold is stale.- await getPlatform().storage.remove(StorageKeys.VAULT_CONTENT_FINGERPRINTS);-- const revision = typeof snapshot.legacyRevision === 'number' ? snapshot.legacyRevision : 0;-- /*- * The vault has never been materialized, so it carries no record of which manifest is ours. Persist the- * server's id for it so the first migration canonicalize can stamp rows with it, and seed the revision map- * with it: a legacy vault is one logical manifest, and every pull path (this one included) must leave the- * per-manifest baselines matching what it fetched.- */- if (snapshot.personalManifestId) {- await getPlatform().storage.set(StorageKeys.VAULT_PERSONAL_MANIFEST_ID, snapshot.personalManifestId);- await replaceManifestRevisions({ [snapshot.personalManifestId]: revision });- }-- devLog('[V2Pull] Legacy sqlite-blob pass-through (user not yet migrated), returning the blob as-is.');-- return {- encryptedBlob: snapshot.legacyVaultBlob ?? '',- version: snapshot.version ?? '',- revision,- };-}--/**- * Canonicalize options that adopt rows carrying no ManifestId into the personal manifest. Only the one-time- * migration of a legacy sqlite-blob vault may pass these: every other canonicalize must reject unstamped rows- * rather than silently claim them (see `claim_manifest_scope` in the Rust codec).- * @param personalManifestId - the manifest unstamped rows are adopted into- */-export function legacyUnstampedRowAdoption(personalManifestId: string): { adoptUnstampedInto: string } {- return { adoptUnstampedInto: personalManifestId };-}--/*- * -- 3. The missing KEK/VEK account key hierarchy --- */--/**- * The freshly generated key hierarchy for one migration push. Held across the push so- * {@link completeLegacyAccountKeyMigration} can cache exactly what the server committed.- */-export type LegacyAccountKeyMigration = {- /** The new VEK: everything this push writes is encrypted with it, and the caller adopts it as the session key. */- contentKey: string;- /** The whole hierarchy, sent as-is in the write payload. */- accountKeys: AccountKeyBlobs;- /** Plaintext private half of the new account keypair, staged into the session once the push commits. */- accountPrivateKey: string;-};/*** Whether this vault still has to run the migration, answered entirely from local state: no cached vault key@@ -187,21 +61,3 @@ export type LegacyAccountKeyMigration = {export async function requiresLegacyAccountKeyMigration(): Promise<boolean> {return !await VaultKeyService.hasLocalVaultKey();}--/**- * Generate the account key hierarchy for a migration push.- * @param kek - the password-derived key this vault is currently encrypted with, which becomes the KEK- */-export async function prepareLegacyAccountKeyMigration(kek: string): Promise<LegacyAccountKeyMigration> {- const hierarchy = await createAccountKeyHierarchy(kek);- return { contentKey: hierarchy.vaultEncryptionKey, accountKeys: hierarchy.accountKeys, accountPrivateKey: hierarchy.accountPrivateKey };-}--/**- * Adopt the hierarchy the migration push just committed: cache the whole encrypted blob chain for offline unlock- * and stage the account private key into the session.- * @param migration - the hierarchy that was pushed- */-export async function completeLegacyAccountKeyMigration(migration: LegacyAccountKeyMigration): Promise<void> {- await VaultKeyService.adoptLocalAccountKeys({ ...migration.accountKeys, accountPrivateKey: migration.accountPrivateKey });-}diff --git a/core/client/src/sync/ManifestRevisions.ts b/core/client/src/sync/ManifestRevisions.tsindex 6bd2f35a2..56ab377b8 100644--- a/core/client/src/sync/ManifestRevisions.ts+++ b/core/client/src/sync/ManifestRevisions.ts@@ -1,109 +1,25 @@/*** ManifestRevisions.*- * The client's last-known server revisions: one per manifest, plus one per data bucket split out of a manifest.- * The two counters advance independently, so both are compared before deciding a pull.+ * The client's last-known server revision per manifest.*/-import { bucketRevisionKey, StorageKeys } from '../constants/StorageKeys';+import { StorageKeys } from '../constants/StorageKeys';import { getPlatform } from '../platform/ClientPlatform';-import type { BucketRevision, ManifestRevision } from '@aliasvault/models/webapi';--/**- * Index a revision list as reported by the server (status call) by manifest id.- * @param revisions - the per-manifest revisions from the server- */-export function toManifestRevisionMap(revisions: ManifestRevision[] | null | undefined): Record<string, number> {- return Object.fromEntries((revisions ?? []).map(m => [m.manifestId, m.revision]));-}--/**- * Index a data-bucket revision list as reported by the server (status call) by {@link bucketRevisionKey}.- * @param revisions - the per-bucket revisions from the server- */-export function toBucketRevisionMap(revisions: BucketRevision[] | null | undefined): Record<string, number> {- return Object.fromEntries((revisions ?? []).map(b => [bucketRevisionKey(b.manifestId, b.category), b.revision]));-}--/**- * The manifests whose local state no longer matches what the server reports, so the client has to pull and- * re-materialize. Every manifest is judged on its own, the personal one included: the server reports it by id like- * any other, and with shared folders in play only some of them move at a time.- *- * Idempotent: right after a successful materialize both maps match, so this returns nothing until the next change.- * @param serverRevisions - the server's current revision per manifest- * @param localRevisions - the client's last-known revision per manifest- */-export function manifestsRequiringPull(serverRevisions: Record<string, number>, localRevisions: Record<string, number>): string[] {- const requiringPull = Object.keys(serverRevisions).filter(manifestId => localRevisions[manifestId] !== serverRevisions[manifestId]);-- // A manifest the client still tracks but the server no longer lists was removed or revoked; re-materializing drops it.- requiringPull.push(...Object.keys(localRevisions).filter(manifestId => !(manifestId in serverRevisions)));-- return requiringPull;-}--/**- * The data buckets whose local state no longer matches what the server reports.- *- * Same shape and idempotence as the manifest comparison; keys are {@link bucketRevisionKey}.- * @param serverRevisions - the server's current revision per data bucket- * @param localRevisions - the client's last-known revision per data bucket- */-export function bucketsRequiringPull(serverRevisions: Record<string, number>, localRevisions: Record<string, number>): string[] {- const requiringPull = Object.keys(serverRevisions).filter(key => localRevisions[key] !== serverRevisions[key]);-- // A bucket the client still tracks but the server no longer lists was removed or revoked; re-materializing drops it.- requiringPull.push(...Object.keys(localRevisions).filter(key => !(key in serverRevisions)));-- return requiringPull;-}-/*** Every manifest's last-known server revision, keyed by manifest id; empty when nothing has been pulled yet.*/-export async function getManifestRevisions(): Promise<Record<string, number>> {+async function getManifestRevisions(): Promise<Record<string, number>> {return ((await getPlatform().storage.get(StorageKeys.SERVER_MANIFEST_REVISIONS)) as Record<string, number> | null) ?? {};}-/**- * Replace with new data (from server).- * @param revisions - the full set of manifest revisions from the snapshot- */-export async function replaceManifestRevisions(revisions: Record<string, number>): Promise<void> {- await getPlatform().storage.set(StorageKeys.SERVER_MANIFEST_REVISIONS, revisions);-}-/*** Merge new revisions into the stored map, used after a write where only the manifests actually written advanced.* @param revisions - the manifest revisions to record*/export async function recordManifestRevisions(revisions: Record<string, number>): Promise<void> {- await replaceManifestRevisions({ ...await getManifestRevisions(), ...revisions });-}--/**- * Every data bucket's last-known server revision, keyed by {@link bucketRevisionKey}; empty when nothing has been pulled yet.- */-export async function getBucketRevisions(): Promise<Record<string, number>> {- return ((await getPlatform().storage.get(StorageKeys.VAULT_BUCKET_REVISIONS)) as Record<string, number> | null) ?? {};-}--/**- * Replace with new data (from a pull snapshot), so the buckets of a manifest that is gone drop out with it.- * @param revisions - the full set of bucket revisions from the snapshot- */-export async function replaceBucketRevisions(revisions: Record<string, number>): Promise<void> {- await getPlatform().storage.set(StorageKeys.VAULT_BUCKET_REVISIONS, revisions);-}--/**- * Merge new revisions into the stored map, used after a write where only the buckets actually written advanced.- * @param revisions - the bucket revisions to record- */-export async function recordBucketRevisions(revisions: Record<string, number>): Promise<void> {- await replaceBucketRevisions({ ...await getBucketRevisions(), ...revisions });+ await getPlatform().storage.set(StorageKeys.SERVER_MANIFEST_REVISIONS, { ...await getManifestRevisions(), ...revisions });}/**diff --git a/core/client/src/sync/VaultCodec.ts b/core/client/src/sync/VaultCodec.tsindex d65d4e12b..a3e8a10f5 100644--- a/core/client/src/sync/VaultCodec.ts+++ b/core/client/src/sync/VaultCodec.ts@@ -10,28 +10,16 @@ import type SqliteClient from '../database/SqliteClient';import type { ISqliteDatabase, ISqliteStatement, SqliteValue } from '../platform/SqliteEngine';import type {CodecManifest,- CodecDataBucket,CodecMaterialized,CodecTableData,} from '../rust/RustCore';/** A single table's rows, byte columns rendered as `{ __b64 }`. */-export type TableData = CodecTableData;+type TableData = CodecTableData;/** Manifest-v1 manifest. */export type VaultManifest = CodecManifest;-/** A manifest-v1 data bucket. */-export type VaultDataBucket = CodecDataBucket;--/**- * A decoded blob entry held platform-side during upload: kind + plaintext bytes.- */-export type BlobEntry = {- kind: 'favicon' | 'attachment';- bytes: Uint8Array;-};-/*** Marker for an extracted blob reference inside a materialized row.*/@@ -43,7 +31,7 @@ type BlobRef = {/*** The stamp a row carries while it belongs to no manifest yet.*/-export const UNSTAMPED_MANIFEST_ID = '00000000-0000-0000-0000-000000000000';+const UNSTAMPED_MANIFEST_ID = '00000000-0000-0000-0000-000000000000';/*** Column sets already derived from a schema, keyed by the schema SQL that produced them.@@ -54,18 +42,10 @@ const schemaColumnsCache = new Map<string, Promise<Record<string, string[]>>>();* Whether a stamp names no manifest, so it must never be mistaken for one the vault holds rows for.* @param manifestId - the stamp as the row carries it*/-export function isUnstampedScope(manifestId: string | null | undefined): boolean {+function isUnstampedScope(manifestId: string | null | undefined): boolean {return !manifestId || manifestId.toLowerCase() === UNSTAMPED_MANIFEST_ID;}-/**- * The comparison key of a manifest id, force it to lowercase to ensure cross-platform compatibility.- * @param manifestId - the manifest id in any casing- */-export function manifestIdKey(manifestId: string): string {- return manifestId.toLowerCase();-}-/*** VaultCodec: SQLite read/insert methods, on whichever engine the host provides.*/diff --git a/core/rust/src/uniffi_api.rs b/core/rust/src/uniffi_api.rsindex af717c7e5..5c3cf400b 100644--- a/core/rust/src/uniffi_api.rs+++ b/core/rust/src/uniffi_api.rs@@ -15,13 +15,6 @@ pub fn get_syncable_table_names() -> Vec<String> {crate::vault_model::SYNCABLE_TABLE_NAMES.iter().map(|s| s.to_string()).collect()}-/// Merge the local canonical vault onto the server canonical vault (manifest-v1 format), one-/// manifest at a time, rows out. Input: `CanonicalMergeInput` JSON. Output: `CanonicalMergeOutput` JSON.-#[uniffi::export]-pub fn merge_canonical_json(input_json: String) -> Result<String, VaultError> {- json_call(&input_json, crate::vault_merge::merge_canonical)-}-/// Prune expired items from trash (items with DeletedAt older than retention_days, default 30)./// Input: `PruneInput` JSON. Output: `PruneOutput` JSON.#[uniffi::export]