Skip to main content

TypeScript SDK

A 100% type-safe TypeScript SDK for the CommerceEngine Storefront API — automatic token management, universal compatibility (browser, Node.js, Next.js, TanStack Start), and production-ready error handling.

Package

@commercengine/storefront

Universal TypeScript SDK with first-class bindings for React, Next.js, TanStack Start, and Node.js.

Pick your integration

Installation

npm install @commercengine/storefront

Quick Start

1

Initialize the SDK

lib/storefront.ts
import { createStorefront, Environment, BrowserTokenStorage } from "@commercengine/storefront";

const storefront = createStorefront({
  storeId: "your-store-id",
  environment: Environment.Staging, // or Environment.Production
  apiKey: "your-api-key",
  session: {
    tokenStorage: new BrowserTokenStorage("myapp_"),
  },
});
2

Browse products (public — no auth needed)

const { data, error } = await storefront.public().catalog.listProducts({
  page: 1,
  limit: 20,
});

if (error) {
  console.error("Failed:", error.message);
} else {
  console.log(`Found ${data?.products.length} products`);
}
3

Start a session for cart, auth, and orders

const sdk = storefront.session();
await sdk.ensureAccessToken(); // Bootstraps anonymous session

const { data: cart } = await sdk.cart.createCart({
  items: [{ product_id: "prod_123", variant_id: null, quantity: 1 }],
});
console.log("Cart created:", cart?.cart.id);
That’s it — you’re making API calls. The SDK handles token refresh, error typing, and session management automatically.

Learn More