sessionStorage — the same Web Storage API you already know from the browser. Use it to share data between functions across a shopper’s session, so work one function already did can be reused by the functions that run after it, instead of being repeated.
It works automatically: the runtime exposes a sessionStorage global to every function, loads it with the session’s current values before your function runs, and saves any changes back when it finishes. You don’t import it, configure it, or return it.
What it’s for
The main win is avoiding redundant requests. Without shared storage, every function that needs the same data ends up calling the same upstream API again. WithsessionStorage, the first function fetches it once, caches it on the session, and every later function in that session reads it straight from storage — no extra round-trips.
The common shape is resolver → enricher:
- A resolver function calls the API (or computes a result) once and caches it on the session.
- One or more enricher functions later read that cache and use it — without hitting the API again.
How to use it
Use it exactly like browsersessionStorage. Because the runtime injects it as a global, declare its type locally so TypeScript is happy:
Notes
- Persists across the session. Values stay available across function invocations within the same shopper’s session — that’s what makes the resolver’s result reusable downstream. They’re never shared between shoppers.
- Strings only. Store objects with
JSON.stringifyand read them back withJSON.parse.