- Public backend reads that do not carry an end-user session
- Session-bound requests that must preserve one specific user’s Commerce Engine tokens
Installation
Shared public client
A public client has no user token state and can be shared by the process.src/lib/public-storefront.ts
Request-isolated session client
A backend route acting on behalf of a browser user should receive or retrieve that user’s token and construct a session isolated to the request.src/lib/session-storefront.ts
TokenStorage bound to the authenticated application session—for example, a database or Redis record keyed by your server-side session ID. The storage instance must still be scoped to one user.
Express route example
src/server.ts
Backend-for-frontend token ownership
A BFF can keep Commerce Engine tokens out of browser JavaScript by storing them in a server-side session and exposing only your own HttpOnly session cookie. In that architecture:- the browser calls your BFF
- the BFF loads the user’s CE token pair from server-side storage
- a request-bound Storefront session SDK performs the operation
- token updates are persisted back to the same server-side session
- Hosted Checkout cannot directly share those tokens unless you intentionally expose a secure synchronization mechanism
Background jobs
A background job should use credentials that belong to the job’s intended context. Do not use an arbitrary storefront customer’s token for system-level fulfilment work. For order, payment, and shipment integrations, prefer Commerce Engine webhooks as the trigger. The storefront SDK can retrieve session-owned order data only when the job has a valid customer session. Administrative workflows may require a separate admin integration outside the Storefront SDK.Webhook endpoint
Webhook verification must use the raw request body. Return success quickly and move heavy work to a queue.src/server.ts
Health checks
A health endpoint should not create an end-user session. Use a public operation and distinguish service health from catalog emptiness.Timeouts and cancellation
Set request timeouts according to the application’s latency budget and propagate client cancellation where the SDK operation supports the underlying fetch signal. Do not blindly retry validation, authorization, cart mutation, or order-creation requests. For idempotent public reads, a bounded retry at the application layer may be appropriate. For mutations, understand the operation’s idempotency semantics before retrying.Logging and observability
Log:- operation name
- duration
- HTTP status
- Commerce Engine request ID when available
- application request ID
- error code/message after redaction
- access or refresh tokens
- API credentials beyond non-sensitive store identifiers
- card or payment authentication data
- full customer addresses or contact details
Deployment runtime
Node.js APIs are not automatically portable to every edge runtime. Check the selected framework/platform:- Vercel Node functions support Node APIs
- Cloudflare Workers use the workerd runtime and may require framework-specific adapters or API replacements
- Netlify supports Node and edge execution with different capability sets
Production checklist
Webhook skill and reference
Install the Commerce Engine skills package and retrieve exact webhook payload contracts from the LLM-first reference.