mirror of
https://github.com/bitwarden/browser
synced 2026-02-25 00:53:22 +00:00
Add updates$ stream to existing storageServices
This commit is contained in:
@@ -19,7 +19,7 @@ const retries: OperationOptions = {
|
||||
factor: 2,
|
||||
};
|
||||
|
||||
export class LowdbStorageService implements AbstractStorageService {
|
||||
export class LowdbStorageService extends AbstractStorageService {
|
||||
protected dataFilePath: string;
|
||||
private db: lowdb.LowdbSync<any>;
|
||||
private defaults: any;
|
||||
@@ -32,6 +32,7 @@ export class LowdbStorageService implements AbstractStorageService {
|
||||
private allowCache = false,
|
||||
private requireLock = false
|
||||
) {
|
||||
super();
|
||||
this.defaults = defaults;
|
||||
}
|
||||
|
||||
@@ -119,21 +120,23 @@ export class LowdbStorageService implements AbstractStorageService {
|
||||
return this.get(key).then((v) => v != null);
|
||||
}
|
||||
|
||||
async save(key: string, obj: any): Promise<any> {
|
||||
async save(key: string, obj: any): Promise<void> {
|
||||
await this.waitForReady();
|
||||
return this.lockDbFile(() => {
|
||||
this.readForNoCache();
|
||||
this.db.set(key, obj).write();
|
||||
this.updatesSubject.next({ key, value: obj, updateType: "save" });
|
||||
this.logService.debug(`Successfully wrote ${key} to db`);
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
async remove(key: string): Promise<any> {
|
||||
async remove(key: string): Promise<void> {
|
||||
await this.waitForReady();
|
||||
return this.lockDbFile(() => {
|
||||
this.readForNoCache();
|
||||
this.db.unset(key).write();
|
||||
this.updatesSubject.next({ key, value: null, updateType: "remove" });
|
||||
this.logService.debug(`Successfully removed ${key} from db`);
|
||||
return;
|
||||
});
|
||||
|
||||
@@ -5,12 +5,14 @@ import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
import { EncArrayBuffer } from "@bitwarden/common/platform/models/domain/enc-array-buffer";
|
||||
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
|
||||
|
||||
export class NodeEnvSecureStorageService implements AbstractStorageService {
|
||||
export class NodeEnvSecureStorageService extends AbstractStorageService {
|
||||
constructor(
|
||||
private storageService: AbstractStorageService,
|
||||
private logService: LogService,
|
||||
private cryptoService: () => CryptoService
|
||||
) {}
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async get<T>(key: string): Promise<T> {
|
||||
const value = await this.storageService.get<string>(this.makeProtectedStorageKey(key));
|
||||
@@ -25,7 +27,7 @@ export class NodeEnvSecureStorageService implements AbstractStorageService {
|
||||
return (await this.get(key)) != null;
|
||||
}
|
||||
|
||||
async save(key: string, obj: any): Promise<any> {
|
||||
async save(key: string, obj: any): Promise<void> {
|
||||
if (obj == null) {
|
||||
return this.remove(key);
|
||||
}
|
||||
@@ -35,10 +37,13 @@ export class NodeEnvSecureStorageService implements AbstractStorageService {
|
||||
}
|
||||
const protectedObj = await this.encrypt(obj);
|
||||
await this.storageService.save(this.makeProtectedStorageKey(key), protectedObj);
|
||||
this.updatesSubject.next({ key, value: obj, updateType: "save" });
|
||||
}
|
||||
|
||||
remove(key: string): Promise<any> {
|
||||
return this.storageService.remove(this.makeProtectedStorageKey(key));
|
||||
async remove(key: string): Promise<void> {
|
||||
await this.storageService.remove(this.makeProtectedStorageKey(key));
|
||||
this.updatesSubject.next({ key, value: null, updateType: "remove" });
|
||||
return;
|
||||
}
|
||||
|
||||
private async encrypt(plainValue: string): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user