π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
add storage package
Abhinav483e137c8a75
diff --git a/packages/storage/.eslintrc.js b/packages/storage/.eslintrc.jsnew file mode 100644index 0000000000..60466d6e16--- /dev/null+++ b/packages/storage/.eslintrc.js@@ -0,0 +1,13 @@+module.exports = {+ // When root is set to true, ESLint will stop looking for configuration files in parent directories.+ // This is required here to ensure desktop picks the right eslint config, where this app is+ // packaged as a submodule.+ root: true,+ extends: ['@ente/eslint-config'],+ parser: '@typescript-eslint/parser',+ parserOptions: {+ tsconfigRootDir: __dirname,+ project: './tsconfig.json',+ },+ ignorePatterns: ['.eslintrc.js'],+};diff --git a/packages/storage/cache.ts b/packages/storage/cache.tsnew file mode 100644index 0000000000..1bf2746639--- /dev/null+++ b/packages/storage/cache.ts@@ -0,0 +1,48 @@+import { CACHES } from 'constants/cache';+import { CacheStorageService } from 'services/cache/cacheStorageService';+import { logError } from 'utils/sentry';++export async function cached(+ cacheName: string,+ id: string,+ get: () => Promise<Blob>+): Promise<Blob> {+ const cache = await CacheStorageService.open(cacheName);+ const cacheResponse = await cache.match(id);++ let result: Blob;+ if (cacheResponse) {+ result = await cacheResponse.blob();+ } else {+ result = await get();++ try {+ await cache.put(id, new Response(result));+ } catch (e) {+ // TODO: handle storage full exception.+ console.error('Error while storing file to cache: ', id);+ }+ }++ return result;+}++export async function getBlobFromCache(+ cacheName: string,+ url: string+): Promise<Blob> {+ const cache = await CacheStorageService.open(cacheName);+ const response = await cache.match(url);++ return response.blob();+}++export async function deleteAllCache() {+ try {+ await CacheStorageService.delete(CACHES.THUMBS);+ await CacheStorageService.delete(CACHES.FACE_CROPS);+ await CacheStorageService.delete(CACHES.FILES);+ } catch (e) {+ logError(e, 'deleteAllCache failed'); // log and ignore+ }+}diff --git a/packages/storage/index.ts b/packages/storage/index.tsnew file mode 100644index 0000000000..87e858d43c--- /dev/null+++ b/packages/storage/index.ts@@ -0,0 +1,40 @@+import { Language } from 'constants/locale';+import { getData, LS_KEYS, setData } from './localStorage';++export const isFirstLogin = () =>+ getData(LS_KEYS.IS_FIRST_LOGIN)?.status ?? false;++export function setIsFirstLogin(status) {+ setData(LS_KEYS.IS_FIRST_LOGIN, { status });+}++export const justSignedUp = () =>+ getData(LS_KEYS.JUST_SIGNED_UP)?.status ?? false;++export function setJustSignedUp(status) {+ setData(LS_KEYS.JUST_SIGNED_UP, { status });+}++export function getLivePhotoInfoShownCount() {+ return getData(LS_KEYS.LIVE_PHOTO_INFO_SHOWN_COUNT)?.count ?? 0;+}++export function setLivePhotoInfoShownCount(count) {+ setData(LS_KEYS.LIVE_PHOTO_INFO_SHOWN_COUNT, { count });+}++export function getUserLocale(): Language {+ return getData(LS_KEYS.LOCALE)?.value;+}++export function getLocalMapEnabled(): boolean {+ return getData(LS_KEYS.MAP_ENABLED)?.value ?? false;+}++export function setLocalMapEnabled(value: boolean) {+ setData(LS_KEYS.MAP_ENABLED, { value });+}++export function getHasOptedOutOfCrashReports(): boolean {+ return getData(LS_KEYS.OPT_OUT_OF_CRASH_REPORTS)?.value ?? false;+}diff --git a/packages/storage/localForage.ts b/packages/storage/localForage.tsnew file mode 100644index 0000000000..b807318a61--- /dev/null+++ b/packages/storage/localForage.ts@@ -0,0 +1,12 @@+import { runningInBrowser } from 'utils/common';++import localForage from 'localforage';++if (runningInBrowser()) {+ localForage.config({+ name: 'ente-files',+ version: 1.0,+ storeName: 'files',+ });+}+export default localForage;diff --git a/packages/storage/localStorage.ts b/packages/storage/localStorage.tsnew file mode 100644index 0000000000..1c1ce575ca--- /dev/null+++ b/packages/storage/localStorage.ts@@ -0,0 +1,67 @@+import { logError } from 'utils/sentry';++export enum LS_KEYS {+ USER = 'user',+ SESSION = 'session',+ KEY_ATTRIBUTES = 'keyAttributes',+ ORIGINAL_KEY_ATTRIBUTES = 'originalKeyAttributes',+ SUBSCRIPTION = 'subscription',+ FAMILY_DATA = 'familyData',+ PLANS = 'plans',+ IS_FIRST_LOGIN = 'isFirstLogin',+ JUST_SIGNED_UP = 'justSignedUp',+ SHOW_BACK_BUTTON = 'showBackButton',+ EXPORT = 'export',+ AnonymizedUserID = 'anonymizedUserID',+ THUMBNAIL_FIX_STATE = 'thumbnailFixState',+ LIVE_PHOTO_INFO_SHOWN_COUNT = 'livePhotoInfoShownCount',+ LOGS = 'logs',+ USER_DETAILS = 'userDetails',+ COLLECTION_SORT_BY = 'collectionSortBy',+ THEME = 'theme',+ WAIT_TIME = 'waitTime',+ API_ENDPOINT = 'apiEndpoint',+ LOCALE = 'locale',+ MAP_ENABLED = 'mapEnabled',+ SRP_SETUP_ATTRIBUTES = 'srpSetupAttributes',+ SRP_ATTRIBUTES = 'srpAttributes',+ OPT_OUT_OF_CRASH_REPORTS = 'optOutOfCrashReports',+}++export const setData = (key: LS_KEYS, value: object) => {+ if (typeof localStorage === 'undefined') {+ return null;+ }+ localStorage.setItem(key, JSON.stringify(value));+};++export const removeData = (key: LS_KEYS) => {+ if (typeof localStorage === 'undefined') {+ return null;+ }+ localStorage.removeItem(key);+};++export const getData = (key: LS_KEYS) => {+ try {+ if (+ typeof localStorage === 'undefined' ||+ typeof key === 'undefined' ||+ typeof localStorage.getItem(key) === 'undefined' ||+ localStorage.getItem(key) === 'undefined'+ ) {+ return null;+ }+ const data = localStorage.getItem(key);+ return data && JSON.parse(data);+ } catch (e) {+ logError(e, 'Failed to Parse JSON for key ' + key);+ }+};++export const clearData = () => {+ if (typeof localStorage === 'undefined') {+ return null;+ }+ localStorage.clear();+};diff --git a/packages/storage/mlIDbStorage.ts b/packages/storage/mlIDbStorage.tsnew file mode 100644index 0000000000..2abdd5d241--- /dev/null+++ b/packages/storage/mlIDbStorage.ts@@ -0,0 +1,506 @@+import {+ DEFAULT_ML_SEARCH_CONFIG,+ DEFAULT_ML_SYNC_CONFIG,+ DEFAULT_ML_SYNC_JOB_CONFIG,+ MAX_ML_SYNC_ERROR_COUNT,+} from 'constants/mlConfig';+import {+ openDB,+ deleteDB,+ DBSchema,+ IDBPDatabase,+ IDBPTransaction,+ StoreNames,+} from 'idb';+import { Config } from 'types/common/config';+import {+ Face,+ MlFileData,+ MLLibraryData,+ Person,+ RealWorldObject,+ Thing,+} from 'types/machineLearning';+import { IndexStatus } from 'types/machineLearning/ui';+import { runningInBrowser, runningInElectron } from 'utils/common';+import { addLogLine } from 'utils/logging';+import { logError } from 'utils/sentry';++export const ML_SYNC_JOB_CONFIG_NAME = 'ml-sync-job';+export const ML_SYNC_CONFIG_NAME = 'ml-sync';+export const ML_SEARCH_CONFIG_NAME = 'ml-search';++const MLDATA_DB_NAME = 'mldata';+interface MLDb extends DBSchema {+ files: {+ key: number;+ value: MlFileData;+ indexes: { mlVersion: [number, number] };+ };+ people: {+ key: number;+ value: Person;+ };+ things: {+ key: number;+ value: Thing;+ };+ versions: {+ key: string;+ value: number;+ };+ library: {+ key: string;+ value: MLLibraryData;+ };+ configs: {+ key: string;+ value: Config;+ };+}++class MLIDbStorage {+ public _db: Promise<IDBPDatabase<MLDb>>;++ constructor() {+ if (!runningInBrowser() || !runningInElectron()) {+ return;+ }++ this.db;+ }++ private openDB(): Promise<IDBPDatabase<MLDb>> {+ return openDB<MLDb>(MLDATA_DB_NAME, 3, {+ terminated: async () => {+ console.error('ML Indexed DB terminated');+ logError(new Error(), 'ML Indexed DB terminated');+ this._db = undefined;+ // TODO: remove if there is chance of this going into recursion in some case+ await this.db;+ },+ blocked() {+ // TODO: make sure we dont allow multiple tabs of app+ console.error('ML Indexed DB blocked');+ logError(new Error(), 'ML Indexed DB blocked');+ },+ blocking() {+ // TODO: make sure we dont allow multiple tabs of app+ console.error('ML Indexed DB blocking');+ logError(new Error(), 'ML Indexed DB blocking');+ },+ async upgrade(db, oldVersion, newVersion, tx) {+ if (oldVersion < 1) {+ const filesStore = db.createObjectStore('files', {+ keyPath: 'fileId',+ });+ filesStore.createIndex('mlVersion', [+ 'mlVersion',+ 'errorCount',+ ]);++ db.createObjectStore('people', {+ keyPath: 'id',+ });++ db.createObjectStore('things', {+ keyPath: 'id',+ });++ db.createObjectStore('versions');++ db.createObjectStore('library');+ }+ if (oldVersion < 2) {+ // TODO: update configs if version is updated in defaults+ db.createObjectStore('configs');++ await tx+ .objectStore('configs')+ .add(+ DEFAULT_ML_SYNC_JOB_CONFIG,+ ML_SYNC_JOB_CONFIG_NAME+ );+ await tx+ .objectStore('configs')+ .add(DEFAULT_ML_SYNC_CONFIG, ML_SYNC_CONFIG_NAME);+ }+ if (oldVersion < 3) {+ await tx+ .objectStore('configs')+ .add(DEFAULT_ML_SEARCH_CONFIG, ML_SEARCH_CONFIG_NAME);+ }+ addLogLine(+ `Ml DB upgraded to version: ${newVersion} from version: ${oldVersion}`+ );+ },+ });+ }++ public get db(): Promise<IDBPDatabase<MLDb>> {+ if (!this._db) {+ this._db = this.openDB();+ addLogLine('Opening Ml DB');+ }++ return this._db;+ }++ public async clearMLDB() {+ const db = await this.db;+ db.close();+ await deleteDB(MLDATA_DB_NAME);+ addLogLine('Cleared Ml DB');+ this._db = undefined;+ await this.db;+ }++ public async getAllFileIds() {+ const db = await this.db;+ return db.getAllKeys('files');+ }++ public async putAllFilesInTx(mlFiles: Array<MlFileData>) {+ const db = await this.db;+ const tx = db.transaction('files', 'readwrite');+ await Promise.all(mlFiles.map((mlFile) => tx.store.put(mlFile)));+ await tx.done;+ }++ public async removeAllFilesInTx(fileIds: Array<number>) {+ const db = await this.db;+ const tx = db.transaction('files', 'readwrite');++ await Promise.all(fileIds.map((fileId) => tx.store.delete(fileId)));+ await tx.done;+ }++ public async newTransaction<+ Name extends StoreNames<MLDb>,+ Mode extends IDBTransactionMode = 'readonly'+ >(storeNames: Name, mode?: Mode) {+ const db = await this.db;+ return db.transaction(storeNames, mode);+ }++ public async commit(tx: IDBPTransaction<MLDb>) {+ return tx.done;+ }++ public async getAllFileIdsForUpdate(+ tx: IDBPTransaction<MLDb, ['files'], 'readwrite'>+ ) {+ return tx.store.getAllKeys();+ }++ public async getFileIds(+ count: number,+ limitMlVersion: number,+ maxErrorCount: number+ ) {+ const db = await this.db;+ const tx = db.transaction('files', 'readonly');+ const index = tx.store.index('mlVersion');+ let cursor = await index.openKeyCursor(+ IDBKeyRange.upperBound([limitMlVersion], true)+ );++ const fileIds: number[] = [];+ while (cursor && fileIds.length < count) {+ if (+ cursor.key[0] < limitMlVersion &&+ cursor.key[1] <= maxErrorCount+ ) {+ fileIds.push(cursor.primaryKey);+ }+ cursor = await cursor.continue();+ }+ await tx.done;++ return fileIds;+ }++ public async getFile(fileId: number) {+ const db = await this.db;+ return db.get('files', fileId);+ }++ public async getAllFiles() {+ const db = await this.db;+ return db.getAll('files');+ }++ public async putFile(mlFile: MlFileData) {+ const db = await this.db;+ return db.put('files', mlFile);+ }++ public async upsertFileInTx(+ fileId: number,+ upsert: (mlFile: MlFileData) => MlFileData+ ) {+ const db = await this.db;+ const tx = db.transaction('files', 'readwrite');+ const existing = await tx.store.get(fileId);+ const updated = upsert(existing);+ await tx.store.put(updated);+ await tx.done;++ return updated;+ }++ public async putAllFiles(+ mlFiles: Array<MlFileData>,+ tx: IDBPTransaction<MLDb, ['files'], 'readwrite'>+ ) {+ await Promise.all(mlFiles.map((mlFile) => tx.store.put(mlFile)));+ }++ public async removeAllFiles(+ fileIds: Array<number>,+ tx: IDBPTransaction<MLDb, ['files'], 'readwrite'>+ ) {+ await Promise.all(fileIds.map((fileId) => tx.store.delete(fileId)));+ }++ public async getAllFacesMap() {+ const startTime = Date.now();+ const db = await this.db;+ const allFiles = await db.getAll('files');+ const allFacesMap = new Map<number, Array<Face>>();+ allFiles.forEach(+ (mlFileData) =>+ mlFileData.faces &&+ allFacesMap.set(mlFileData.fileId, mlFileData.faces)+ );+ addLogLine('getAllFacesMap', Date.now() - startTime, 'ms');++ return allFacesMap;+ }++ public async updateFaces(allFacesMap: Map<number, Face[]>) {+ const startTime = Date.now();+ const db = await this.db;+ const tx = db.transaction('files', 'readwrite');+ let cursor = await tx.store.openCursor();+ while (cursor) {+ if (allFacesMap.has(cursor.key)) {+ const mlFileData = { ...cursor.value };+ mlFileData.faces = allFacesMap.get(cursor.key);+ cursor.update(mlFileData);+ }+ cursor = await cursor.continue();+ }+ await tx.done;+ addLogLine('updateFaces', Date.now() - startTime, 'ms');+ }++ public async getAllObjectsMap() {+ const startTime = Date.now();+ const db = await this.db;+ const allFiles = await db.getAll('files');+ const allObjectsMap = new Map<number, Array<RealWorldObject>>();+ allFiles.forEach(+ (mlFileData) =>+ mlFileData.objects &&+ allObjectsMap.set(mlFileData.fileId, mlFileData.objects)+ );+ addLogLine('allObjectsMap', Date.now() - startTime, 'ms');++ return allObjectsMap;+ }++ public async getPerson(id: number) {+ const db = await this.db;+ return db.get('people', id);+ }++ public async getAllPeople() {+ const db = await this.db;+ return db.getAll('people');+ }++ public async putPerson(person: Person) {+ const db = await this.db;+ return db.put('people', person);+ }++ public async clearAllPeople() {+ const db = await this.db;+ return db.clear('people');+ }++ public async getAllThings() {+ const db = await this.db;+ return db.getAll('things');+ }+ public async putThing(thing: Thing) {+ const db = await this.db;+ return db.put('things', thing);+ }++ public async clearAllThings() {+ const db = await this.db;+ return db.clear('things');+ }++ public async getIndexVersion(index: string) {+ const db = await this.db;+ return db.get('versions', index);+ }++ public async incrementIndexVersion(index: StoreNames<MLDb>) {+ if (index === 'versions') {+ throw new Error('versions store can not be versioned');+ }+ const db = await this.db;+ const tx = db.transaction(['versions', index], 'readwrite');+ let version = await tx.objectStore('versions').get(index);+ version = (version || 0) + 1;+ tx.objectStore('versions').put(version, index);+ await tx.done;++ return version;+ }++ public async setIndexVersion(index: string, version: number) {+ const db = await this.db;+ return db.put('versions', version, index);+ }++ public async getLibraryData() {+ const db = await this.db;+ return db.get('library', 'data');+ }++ public async putLibraryData(data: MLLibraryData) {+ const db = await this.db;+ return db.put('library', data, 'data');+ }++ public async getConfig<T extends Config>(name: string, def: T) {+ const db = await this.db;+ const tx = db.transaction('configs', 'readwrite');+ let config = (await tx.store.get(name)) as T;+ if (!config) {+ config = def;+ await tx.store.put(def, name);+ }+ await tx.done;++ return config;+ }++ public async putConfig(name: string, data: Config) {+ const db = await this.db;+ return db.put('configs', data, name);+ }++ public async getIndexStatus(latestMlVersion: number): Promise<IndexStatus> {+ const db = await this.db;+ const tx = db.transaction(['files', 'versions'], 'readonly');+ const mlVersionIdx = tx.objectStore('files').index('mlVersion');++ let outOfSyncCursor = await mlVersionIdx.openKeyCursor(+ IDBKeyRange.upperBound([latestMlVersion], true)+ );+ let outOfSyncFilesExists = false;+ while (outOfSyncCursor && !outOfSyncFilesExists) {+ if (+ outOfSyncCursor.key[0] < latestMlVersion &&+ outOfSyncCursor.key[1] <= MAX_ML_SYNC_ERROR_COUNT+ ) {+ outOfSyncFilesExists = true;+ }+ outOfSyncCursor = await outOfSyncCursor.continue();+ }++ const nSyncedFiles = await mlVersionIdx.count(+ IDBKeyRange.lowerBound([latestMlVersion])+ );+ const nTotalFiles = await mlVersionIdx.count();++ const filesIndexVersion = await tx.objectStore('versions').get('files');+ const peopleIndexVersion = await tx+ .objectStore('versions')+ .get('people');+ const filesIndexVersionExists =+ filesIndexVersion !== null && filesIndexVersion !== undefined;+ const peopleIndexVersionExists =+ peopleIndexVersion !== null && peopleIndexVersion !== undefined;++ await tx.done;++ return {+ outOfSyncFilesExists,+ nSyncedFiles,+ nTotalFiles,+ localFilesSynced: filesIndexVersionExists,+ peopleIndexSynced:+ peopleIndexVersionExists &&+ peopleIndexVersion === filesIndexVersion,+ };+ }++ // for debug purpose+ public async getAllMLData() {+ const db = await this.db;+ const tx = db.transaction(db.objectStoreNames, 'readonly');+ const allMLData: any = {};+ for (const store of tx.objectStoreNames) {+ const keys = await tx.objectStore(store).getAllKeys();+ const data = await tx.objectStore(store).getAll();++ allMLData[store] = {};+ for (let i = 0; i < keys.length; i++) {+ allMLData[store][keys[i]] = data[i];+ }+ }+ await tx.done;++ const files = allMLData['files'];+ for (const fileId of Object.keys(files)) {+ const fileData = files[fileId];+ fileData.faces?.forEach(+ (f) => (f.embedding = Array.from(f.embedding))+ );+ }++ return allMLData;+ }++ // for debug purpose, this will overwrite all data+ public async putAllMLData(allMLData: Map<string, any>) {+ const db = await this.db;+ const tx = db.transaction(db.objectStoreNames, 'readwrite');+ for (const store of tx.objectStoreNames) {+ const records = allMLData[store];+ if (!records) {+ continue;+ }+ const txStore = tx.objectStore(store);++ if (store === 'files') {+ const files = records;+ for (const fileId of Object.keys(files)) {+ const fileData = files[fileId];+ fileData.faces?.forEach(+ (f) => (f.embedding = Float32Array.from(f.embedding))+ );+ }+ }++ await txStore.clear();+ for (const key of Object.keys(records)) {+ if (txStore.keyPath) {+ txStore.put(records[key]);+ } else {+ txStore.put(records[key], key);+ }+ }+ }+ await tx.done;+ }+}++export default new MLIDbStorage();diff --git a/packages/storage/mlStorage.ts b/packages/storage/mlStorage.tsnew file mode 100644index 0000000000..60ef01a87b--- /dev/null+++ b/packages/storage/mlStorage.ts@@ -0,0 +1,97 @@+import { EnteFile } from 'types/file';+import {+ Face,+ MlFileData,+ MLIndex,+ MLSyncContext,+} from 'types/machineLearning';+import localForage from './localForage';++export const mlFilesStore = localForage.createInstance({+ driver: localForage.INDEXEDDB,+ name: 'ml-data',+ version: 1.0,+ storeName: 'files',+});++export const mlPeopleStore = localForage.createInstance({+ driver: localForage.INDEXEDDB,+ name: 'ml-data',+ version: 1.0,+ storeName: 'people',+});++export const mlLibraryStore = localForage.createInstance({+ driver: localForage.INDEXEDDB,+ name: 'ml-data',+ version: 1.0,+ storeName: 'library',+});++export const mlVersionStore = localForage.createInstance({+ driver: localForage.INDEXEDDB,+ name: 'ml-data',+ version: 1.0,+ storeName: 'versions',+});++export async function clearMLStorage() {+ await mlFilesStore.clear();+ await mlPeopleStore.clear();+ await mlLibraryStore.clear();+ await mlVersionStore.clear();+}++export async function getIndexVersion(index: MLIndex): Promise<number> {+ return ((await mlVersionStore.getItem(`${index}`)) as number) || 0;+}++export async function setIndexVersion(+ index: MLIndex,+ version: number+): Promise<number> {+ await mlVersionStore.setItem(`${index}`, version);++ return version;+}++export async function incrementIndexVersion(index: MLIndex): Promise<number> {+ let currentVersion = await getIndexVersion(index);+ currentVersion = currentVersion + 1;+ await setIndexVersion(index, currentVersion);++ return currentVersion;+}++export async function isVersionOutdated(index: MLIndex, thanIndex: MLIndex) {+ const indexVersion = await getIndexVersion(index);+ const thanIndexVersion = await getIndexVersion(thanIndex);++ return indexVersion < thanIndexVersion;+}++export function newMlData(+ syncContext: MLSyncContext,+ enteFile: EnteFile+): MlFileData {+ return {+ fileId: enteFile.id,+ imageSource: syncContext.config.imageSource,+ faceDetectionMethod: syncContext.faceDetectionService.method,+ faceCropMethod: syncContext.faceCropService.method,+ faceAlignmentMethod: syncContext.faceAlignmentService.method,+ faceEmbeddingMethod: syncContext.faceEmbeddingService.method,+ errorCount: 0,+ mlVersion: 0,+ };+}++export async function getAllFacesMap() {+ const allSyncedFacesMap = new Map<number, Array<Face>>();+ await mlFilesStore.iterate((mlFileData: MlFileData) => {+ mlFileData.faces &&+ allSyncedFacesMap.set(mlFileData.fileId, mlFileData.faces);+ });++ return allSyncedFacesMap;+}diff --git a/packages/storage/package.json b/packages/storage/package.jsonnew file mode 100644index 0000000000..fbb1992c5f--- /dev/null+++ b/packages/storage/package.json@@ -0,0 +1,15 @@+{+ "name": "@ente/storage",+ "version": "0.0.0",+ "scripts": {+ "lint": "eslint .",+ "build": "yarn lint"+ },+ "dependencies": {},+ "devDependencies": {+ "@ente/eslint-config": "*",+ "@typescript-eslint/parser": "^5.59.2",+ "eslint": "^8.28.0",+ "typescript": "^5.1.3"+ }+}diff --git a/packages/storage/sessionStorage.ts b/packages/storage/sessionStorage.tsnew file mode 100644index 0000000000..bad871f760--- /dev/null+++ b/packages/storage/sessionStorage.ts@@ -0,0 +1,32 @@+export enum SESSION_KEYS {+ ENCRYPTION_KEY = 'encryptionKey',+ KEY_ENCRYPTION_KEY = 'keyEncryptionKey',+}++export const setKey = (key: SESSION_KEYS, value: object) => {+ if (typeof sessionStorage === 'undefined') {+ return null;+ }+ sessionStorage.setItem(key, JSON.stringify(value));+};++export const getKey = (key: SESSION_KEYS) => {+ if (typeof sessionStorage === 'undefined') {+ return null;+ }+ return JSON.parse(sessionStorage.getItem(key));+};++export const removeKey = (key: SESSION_KEYS) => {+ if (typeof sessionStorage === 'undefined') {+ return null;+ }+ sessionStorage.removeItem(key);+};++export const clearKeys = () => {+ if (typeof sessionStorage === 'undefined') {+ return null;+ }+ sessionStorage.clear();+};diff --git a/packages/storage/tsconfig.json b/packages/storage/tsconfig.jsonnew file mode 100644index 0000000000..02ec15ac42--- /dev/null+++ b/packages/storage/tsconfig.json@@ -0,0 +1,3 @@+{+ "extends": "../../tsconfig.base.json"+}