@suucha/storage-indexed-db
v0.1.0
Published
IndexedDB storage implementation for Suucha Web SDK
Readme
@suucha/storage-indexed-db
IndexedDB-backed storage implementation of IStorage for Suucha Web SDK.
Useful for event queues (consent buffering), large attribution payloads, and any data exceeding the ~4KB cookie / ~5MB localStorage limits.
Install
pnpm add @suucha/core @suucha/storage-indexed-dbUsage
import { suucha } from '@suucha/core';
import { IndexedDbStorage } from '@suucha/storage-indexed-db';
const storage = new IndexedDbStorage({
dbName: 'my-app',
storeName: 'suucha',
});
suucha.setStorage(storage);
await storage.set('key', { any: 'value' }, 60_000); // ttl in ms
const value = await storage.get('key');
await storage.remove('key');Options
| Option | Default | Description |
|---|---|---|
| dbName | 'suucha' | IndexedDB database name |
| storeName | 'kv' | Object store name |
| version | 1 | Database version |
TTL Behavior
When set(key, value, ttl) is called, the value is stored with an expiration timestamp. get() returns null and removes the entry if expired. Call cleanup() to iterate and remove all expired entries.
Browser Only
IndexedDB is only available in browsers. In Node.js / SSR, calling any method will reject with an error. Guard with typeof indexedDB !== 'undefined' if needed.
License
MIT © Suucha Studio
