StorageAdapter Interface
TheStorageAdapter interface is simple and synchronous:
get()returnsnullif the key doesn’t existset()andremove()are fire-and-forget (no return value)- All methods are synchronous
- Values are always strings (the engine handles JSON serialization)
Storage Keys
The engine uses three keys internally:unlocked- Array of unlocked achievement IDsprogress- Object mapping achievement IDs to progress valuesitems- Object mapping achievement IDs to arrays of collected items
:hash suffix for integrity verification.
Built-in Adapters
The package includes three adapters you can reference:LocalStorage Adapter
- Optional prefix to namespace keys
- SSR-safe (checks for
window) - Silent error handling (quota exceeded, privacy mode, etc.)
In-Memory Adapter
- Testing
- Temporary sessions
- Server-side rendering
Custom Adapter Examples
IndexedDB Adapter
For larger datasets or offline-first apps:Cookie Adapter
For simple persistence with server-side access:- 4KB size limit per cookie
- Not suitable for large achievement lists
Remote API Adapter
For server-backed achievement systems:- Cache provides synchronous reads while API call is in flight
- Consider adding debouncing for frequent writes
- Handle authentication tokens as needed
SessionStorage Adapter
For tab-scoped persistence:Best Practices
1. Use a Cache Layer
For async storage backends, maintain a synchronous cache:2. Handle Errors Gracefully
Always wrap storage operations in try-catch:3. Support SSR
Check for browser APIs before using them:4. Add Prefixes
Namespace your keys to avoid collisions:5. Consider Migration
Handle version changes in your storage format:Testing Your Adapter
Create a simple test suite:Next Steps
- Vanilla JS Guide - Learn core achievement system usage
- React Integration Guide - Use with React
- Custom Hash Guide - Implement custom hash adapters
