Skip to main content
Node.js integrations usually fall into two categories:
  1. Public backend reads that do not carry an end-user session
  2. Session-bound requests that must preserve one specific user’s Commerce Engine tokens
Do not use one globally shared mutable session SDK for concurrent users.

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
MemoryTokenStorage is process-local mutable state. Create it per request or per isolated job/user context. A singleton can leak one user’s session into another request.
For durable BFF sessions, implement a 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
Do not trust a user ID supplied by the browser when the SDK can resolve the current identity from the token.

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
This is a different architecture from the browser-managed SDK wrappers. Choose one deliberately rather than combining parts of both.

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
express.raw() cannot recover the original bytes after express.json() has parsed the request. Register this webhook route before the global JSON middleware, as shown in the Express setup above. An alternative is to explicitly exclude this path from the global parser, but do not run both parsers for the webhook request.
Make processing idempotent and tolerate duplicate or out-of-order deliveries. Retrieve the exact current event payload from the LLM-first webhook reference before implementing a handler.

Health checks

A health endpoint should not create an end-user session. Use a public operation and distinguish service health from catalog emptiness.
Do not include API keys, tokens, full upstream responses, or customer data in health output.

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
Never log:
  • 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
For storefront frameworks, prefer the first-party framework wrapper and the starter’s deployment adapter over recreating an SSR binding in a generic Express layer.

Production checklist

Webhook skill and reference

Install the Commerce Engine skills package and retrieve exact webhook payload contracts from the LLM-first reference.