mirror of
https://github.com/bitwarden/jslib
synced 2025-12-27 13:43:14 +00:00
[refactor] Extract, rename, and expand StorageServiceOptions
* Pulled StorageServiceOptions into its own file * Renamed StorageServiceOptions to StorageOptions * Pulled KeySuffixOpptions into its own file * Converted KeySuffixOptions into an enum from a union type
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
import { StorageOptions } from '../models/domain/storageOptions';
|
||||
|
||||
export abstract class StorageService {
|
||||
get: <T>(key: string, options?: StorageServiceOptions) => Promise<T>;
|
||||
has: (key: string, options?: StorageServiceOptions) => Promise<boolean>;
|
||||
save: (key: string, obj: any, options?: StorageServiceOptions) => Promise<any>;
|
||||
remove: (key: string, options?: StorageServiceOptions) => Promise<any>;
|
||||
get: <T>(key: string, options?: StorageOptions) => Promise<T>;
|
||||
has: (key: string, options?: StorageOptions) => Promise<boolean>;
|
||||
save: (key: string, obj: any, options?: StorageOptions) => Promise<any>;
|
||||
remove: (key: string, options?: StorageOptions) => Promise<any>;
|
||||
}
|
||||
|
||||
export interface StorageServiceOptions {
|
||||
keySuffix: KeySuffixOptions;
|
||||
}
|
||||
|
||||
export type KeySuffixOptions = 'auto' | 'biometric';
|
||||
|
||||
4
common/src/enums/keySuffixOptions.ts
Normal file
4
common/src/enums/keySuffixOptions.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export enum KeySuffixOptions {
|
||||
Auto = 'auto',
|
||||
Biometric = 'biometric',
|
||||
}
|
||||
5
common/src/enums/storageLocation.ts
Normal file
5
common/src/enums/storageLocation.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export enum StorageLocation {
|
||||
Both = 'both',
|
||||
Disk = 'disk',
|
||||
Memory = 'memory',
|
||||
}
|
||||
9
common/src/models/domain/storageOptions.ts
Normal file
9
common/src/models/domain/storageOptions.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { KeySuffixOptions } from '../../enums/keySuffixOptions';
|
||||
import { StorageLocation } from '../../enums/storageLocation';
|
||||
|
||||
export type StorageOptions = {
|
||||
keySuffix?: KeySuffixOptions;
|
||||
storageLocation?: StorageLocation;
|
||||
useSecureStorage?: boolean;
|
||||
userId?: string;
|
||||
};
|
||||
@@ -1,9 +1,11 @@
|
||||
import { ipcRenderer } from 'electron';
|
||||
|
||||
import { StorageService, StorageServiceOptions } from 'jslib-common/abstractions/storage.service';
|
||||
import { StorageService } from 'jslib-common/abstractions/storage.service';
|
||||
|
||||
import { StorageOptions } from 'jslib-common/models/domain/storageOptions';
|
||||
|
||||
export class ElectronRendererSecureStorageService implements StorageService {
|
||||
async get<T>(key: string, options?: StorageServiceOptions): Promise<T> {
|
||||
async get<T>(key: string, options?: StorageOptions): Promise<T> {
|
||||
const val = ipcRenderer.sendSync('keytar', {
|
||||
action: 'getPassword',
|
||||
key: key,
|
||||
@@ -12,7 +14,7 @@ export class ElectronRendererSecureStorageService implements StorageService {
|
||||
return Promise.resolve(val != null ? JSON.parse(val) as T : null);
|
||||
}
|
||||
|
||||
async has(key: string, options?: StorageServiceOptions): Promise<boolean> {
|
||||
async has(key: string, options?: StorageOptions): Promise<boolean> {
|
||||
const val = ipcRenderer.sendSync('keytar', {
|
||||
action: 'hasPassword',
|
||||
key: key,
|
||||
@@ -21,7 +23,7 @@ export class ElectronRendererSecureStorageService implements StorageService {
|
||||
return Promise.resolve(!!val);
|
||||
}
|
||||
|
||||
async save(key: string, obj: any, options?: StorageServiceOptions): Promise<any> {
|
||||
async save(key: string, obj: any, options?: StorageOptions): Promise<any> {
|
||||
ipcRenderer.sendSync('keytar', {
|
||||
action: 'setPassword',
|
||||
key: key,
|
||||
@@ -31,7 +33,7 @@ export class ElectronRendererSecureStorageService implements StorageService {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async remove(key: string, options?: StorageServiceOptions): Promise<any> {
|
||||
async remove(key: string, options?: StorageOptions): Promise<any> {
|
||||
ipcRenderer.sendSync('keytar', {
|
||||
action: 'deletePassword',
|
||||
key: key,
|
||||
|
||||
Reference in New Issue
Block a user