Skip to main content
Commerce Engine uses one unified package, @commercengine/storefront, with framework-specific subpath exports. Configuration differs slightly between a browser SPA and a first-party SSR wrapper, but the architecture is the same:
  • public reads use a public accessor
  • live user flows use a session accessor
  • one storefront factory owns the configuration
  • Hosted Checkout shares the same session when both packages are installed

Core package

Vite browser SPA configuration

Use createStorefront() for React, Vue, Svelte, Solid, or vanilla browser applications. This example uses Vite environment variables; other bundlers should supply the same values through their own public environment mechanism.
lib/storefront.ts
Session configuration belongs under session. Do not place tokenStorage at the top level of createStorefront().

First-party SSR wrappers

Use the framework wrapper instead of configuring browser and server storage manually. Example Next.js configuration:
lib/storefront.ts
The wrapper aligns browser and request-cookie storage automatically. Do not add BrowserTokenStorage or CookieTokenStorage to a first-party SSR wrapper.

Next.js

App Router accessors, bootstrap, Server Actions, and SSG/ISR.

TanStack Start

Client/server entry points, route loaders, and deployment adapters.

Astro

Frontmatter, request cookies, middleware, and islands.

SvelteKit

Universal loads, server loads, form actions, and hooks.

Required configuration

storeId

The store identifier from the Commerce Engine Admin Portal.

apiKey

The publishable Storefront API key. It is intended for storefront clients and is scoped by Commerce Engine. It is not an admin secret and must not be confused with private admin, webhook, or payment-provider credentials.

environment

Use the Environment enum rather than hardcoded strings in Storefront SDK configuration.
Read runtimeEnvironment from the framework-specific variable shown in the environment table below. Do not copy a Vite-only import.meta.env expression into Next.js, SvelteKit, Astro, or Node.js.

Session configuration

Browser token storage

Use BrowserTokenStorage only for browser SPAs using the base createStorefront() factory.
The prefix prevents token-name collisions when multiple storefronts run on the same origin.

SSR token storage

First-party wrappers use cookie-backed storage automatically through tokenStorageOptions.
For a framework without a first-party wrapper, use @commercengine/ssr-utils and a request-bound ServerTokenStorage. Do not use browser cookie storage as the server-side session layer.

Node.js storage

For a short-lived, isolated server process, use MemoryTokenStorage. For multiple concurrent end users, create a request- or user-bound session instance rather than sharing one mutable token store globally. See Node.js for the request-isolation pattern.

Public versus session accessors

For SSR wrappers, use publicStorefront(), clientStorefront(), and the framework’s server accessor. Never use a session accessor in build-time or prerender code.

Default headers

Use defaultHeaders for store-wide request context such as B2B customer-group pricing.
Only set a customer group after the application has authoritative group information. Do not guess or derive group IDs from display labels.

Hosted Checkout configuration

When the application uses both @commercengine/storefront and @commercengine/checkout, the Storefront SDK is the single session owner. Checkout must use authMode: "provided" and tokens must synchronize in both directions. For a browser SPA, the SDK-to-checkout callback belongs inside session:
The exported checkout store safely ignores an SDK token callback that occurs before initCheckout() creates the underlying iframe instance. Pass the current token pair into initCheckout() for initial hydration; later token updates are forwarded through this callback. For Next.js, TanStack Start, Astro, and SvelteKit wrappers, onTokensUpdated is a top-level wrapper option. Follow the framework-specific guide rather than moving the SPA configuration unchanged.

Environment-variable conventions

Commit an .env.example containing placeholder values, never real credentials.

Configuration checklist

Exact SDK reference

Retrieve the current SDK surface and type definitions from the LLM-first reference. Use .md URLs or Accept: text/markdown for agent workflows.