1 /* eslint-disable @typescript-eslint/no-explicit-any */
2 import { VaultSession } from './types';
3 4 export abstract class BrowserSessionHandler {
5 get vaultSession(): VaultSession | undefined {
6 return this.#vaultSession;
7 }
8 9 /** @deprecated Use vaultSession instead */
10 get browserSessionData(): VaultSession | undefined {
11 return this.#vaultSession;
12 }
13 14 #vaultSession?: VaultSession;
15 16 /**
17 * Load the data from the browser session storage. It should be an empty object,
18 * if no data is available yet (e.g. because the vault (from the browser sync data)
19 * was not unlocked via password).
20 *
21 * ATTENTION: Make sure to call "setFullData(..)" afterwards to update the in-memory data.
22 */
23 abstract loadFullData(): Promise<Partial<Record<string, any>>>;
24 setFullData(data: VaultSession) {
25 this.#vaultSession = JSON.parse(JSON.stringify(data));
26 }
27 28 clearInMemoryData() {
29 this.#vaultSession = undefined;
30 }
31 32 /**
33 * Persist the full data to the session data storage.
34 *
35 * ATTENTION: Make sure to call "setFullData(..)" afterwards of before to update the in-memory data.
36 */
37 abstract saveFullData(data: VaultSession): Promise<void>;
38 39 abstract clearData(): Promise<void>;
40 }
41