feat: replace demo storage instances with secure storage implementations across i18n and storage features
This commit is contained in:
@@ -32,36 +32,36 @@ This package provides a unified, Promise-based interface for interacting with br
|
||||
|
||||
### 1. Secure Local Storage (Tokens, Profile)
|
||||
|
||||
Use `demoSecureStorage` (or your app's configured instance) for small payloads. If the key is in `ENCRYPTED_KEYS`, it will be encrypted at rest.
|
||||
Use `secureStorage` (or your app's configured instance) for small payloads. If the key is in `ENCRYPTED_KEYS`, it will be encrypted at rest.
|
||||
|
||||
```typescript
|
||||
import { demoSecureStorage, StorageKey } from '@repo/core-storage';
|
||||
import { secureStorage, StorageKey } from '@repo/core-storage';
|
||||
import type { UserProfile } from '@/types';
|
||||
|
||||
// CREATE / UPDATE
|
||||
// If StorageKey.USER_PROFILE is in ENCRYPTED_KEYS, this is AES-encrypted automatically.
|
||||
await demoSecureStorage.setItem(StorageKey.USER_PROFILE, {
|
||||
await secureStorage.setItem(StorageKey.USER_PROFILE, {
|
||||
id: 1,
|
||||
name: 'Firman',
|
||||
role: 'admin'
|
||||
});
|
||||
|
||||
// READ
|
||||
const profile = await demoSecureStorage.getItem<UserProfile>(StorageKey.USER_PROFILE);
|
||||
const profile = await secureStorage.getItem<UserProfile>(StorageKey.USER_PROFILE);
|
||||
if (profile) {
|
||||
console.log('Welcome back,', profile.name);
|
||||
}
|
||||
|
||||
// DELETE
|
||||
await demoSecureStorage.removeItem(StorageKey.USER_PROFILE);
|
||||
await secureStorage.removeItem(StorageKey.USER_PROFILE);
|
||||
```
|
||||
|
||||
### 2. IndexedDB (Offline Data, Large Payloads)
|
||||
|
||||
Use the pre-configured `demoIndexedDB` (or instantiate your own) for large, asynchronous data. It uses the exact same API and encryption pipeline.
|
||||
Use the pre-configured `secureIndexedDB` (or instantiate your own) for large, asynchronous data. It uses the exact same API and encryption pipeline.
|
||||
|
||||
```typescript
|
||||
import { demoIndexedDB } from '@repo/core-storage';
|
||||
import { secureIndexedDB } from '@repo/core-storage';
|
||||
|
||||
interface DraftData {
|
||||
id: string;
|
||||
@@ -70,14 +70,14 @@ interface DraftData {
|
||||
}
|
||||
|
||||
// Save a large draft offline
|
||||
await demoIndexedDB.setItem('offline_draft_123', {
|
||||
await secureIndexedDB.setItem('offline_draft_123', {
|
||||
id: '123',
|
||||
content: 'Huge text content...',
|
||||
lastModified: Date.now()
|
||||
});
|
||||
|
||||
// Retrieve the draft
|
||||
const draft = await demoIndexedDB.getItem<DraftData>('offline_draft_123');
|
||||
const draft = await secureIndexedDB.getItem<DraftData>('offline_draft_123');
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -22,28 +22,27 @@ import { IndexedDBService } from './indexed-db.service';
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { demoSecureStorage, StorageKey } from '@repo/core-storage';
|
||||
* import { secureStorage, StorageKey } from '@repo/core-storage';
|
||||
*
|
||||
* await demoSecureStorage.setItem(StorageKey.ACCESS_TOKEN, 'eyJhbGci...');
|
||||
* const token = await demoSecureStorage.getItem<string>(StorageKey.ACCESS_TOKEN);
|
||||
* await secureStorage.setItem(StorageKey.ACCESS_TOKEN, 'eyJhbGci...');
|
||||
* const token = await secureStorage.getItem<string>(StorageKey.ACCESS_TOKEN);
|
||||
* ```
|
||||
*/
|
||||
export const demoSecureStorage = new LocalStorageService();
|
||||
export const secureStorage = new LocalStorageService();
|
||||
|
||||
/**
|
||||
* Default IndexedDB instance.
|
||||
*
|
||||
* Uses `app_db` database with a `kv_store` object store.
|
||||
* Sensitive keys are encrypted at rest using the same
|
||||
* `EncryptionUtils` pipeline as `demoSecureStorage`.
|
||||
* `EncryptionUtils` pipeline as `secureStorage`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { demoIndexedDB } from '@repo/core-storage';
|
||||
* import { secureIndexedDB } from '@repo/core-storage';
|
||||
*
|
||||
* await demoIndexedDB.setItem('offline_draft', { content: '...' });
|
||||
* const draft = await demoIndexedDB.getItem<Draft>('offline_draft');
|
||||
* await secureIndexedDB.setItem('offline_draft', { content: '...' });
|
||||
* const draft = await secureIndexedDB.getItem<Draft>('offline_draft');
|
||||
* ```
|
||||
*/
|
||||
export const demoIndexedDB = new IndexedDBService({ dbName: 'app_db', storeName: 'kv_store' });
|
||||
export const demoIndexedDB2 = new IndexedDBService({ dbName: 'app_db', storeName: 'kv_store_2' });
|
||||
export const secureIndexedDB = new IndexedDBService({ dbName: 'app_db', storeName: 'kv_store' });
|
||||
|
||||
Reference in New Issue
Block a user