What problem does it solve?
Adds full storefront commerce capabilities to static sites and simple frontends without requiring a heavy backend or a full e-commerce platform, enabling product display, cart lifecycle management, and payment capture with minimal infrastructure.
Core Features & Use Cases
- Product fetching and display: list products, retrieve single products by permalink, and render structured product metadata and images.
- Cart lifecycle management: create/retrieve carts, add/update/remove line items, empty and refresh carts, and surface total item counts for UI badges.
- Secure checkout flow: generate time-limited checkout tokens, fetch live shipping options, capture orders server-side using the secret key, refresh the cart after successful capture, and integrate Stripe as the payment gateway.
- Developer patterns: single module-level Commerce client, public key usage on client, secret key usage on server, HTML sanitization for rich product descriptions, and Next.js-compatible examples for static rendering and API routes.
- Use case: ideal for MVPs, portfolio projects, or small catalogs (under ~1,000 products) where teams want headless commerce without operating a complex backend.
Quick Start
Create a Next.js product page that lists products with the Commerce.js public key, uses the client to manage a cart, generates a checkout token before checkout, and captures the order server-side with the secret key.