@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
UsecreateStorefront() 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
First-party SSR wrappers
Use the framework wrapper instead of configuring browser and server storage manually.
Example Next.js configuration:
lib/storefront.ts
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.
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
UseBrowserTokenStorage only for browser SPAs using the base createStorefront() factory.
SSR token storage
First-party wrappers use cookie-backed storage automatically throughtokenStorageOptions.
@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, useMemoryTokenStorage. 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
publicStorefront(), clientStorefront(), and the framework’s server accessor. Never use a session accessor in build-time or prerender code.
Default headers
UsedefaultHeaders for store-wide request context such as B2B customer-group pricing.
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:
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.