Per-user, per-app key-value storage with @elata-biosciences/app-state.
@elata-biosciences/app-state is not published to npm yet. Until it is, you can call Elata directly with the elata:state:* messages shown below; Elata already supports them.
Overview
@elata-biosciences/app-state stores small JSON values per user and per app:
save games, settings, progress. You don’t need a backend, and the bridge does not disclose the user’s account credentials. Values follow the user across devices.
# Not on npm yet. This command works after the first release.npm install @elata-biosciences/app-state
import { getState, setState, deleteState } from '@elata-biosciences/app-state';// null if nothing was ever storedconst save = await getState('save_slot_1');await setState('save_slot_1', { level: 7, hp: 100 });// idempotent: no error if the key was never setawait deleteState('save_slot_1');
Limits
Limit
Value
Key
1 to 256 characters from A-Z a-z 0-9 . _ : / -
Value
Any JSON-serializable value, up to 64 KB once encoded
Scope
One namespace per (user, app). Apps can’t read each other’s data.
Errors
All three functions reject with AppStateError, which has a code:
Code
Where it comes from
Meaning
no_parent
Local
Not running inside Elata’s frame
timeout
Local
No reply in time
invalid_input
Local or Elata
Bad key or value
not_authenticated
Elata
The user isn’t signed in
value_too_large
Elata
Value is over 64 KB
fetch_failed
Elata
Elata couldn’t reach storage
Players who aren’t signed in get not_authenticated. Keep a local fallback,
such as localStorage, and sync to app-state once they sign in.
Without the package
Elata answers these messages directly. Send them to window.parent with a unique requestId and wait for the matching …:result reply: