Skip to main content
@itemshop/sdk is the reference ItemShop SDK: zero runtime dependencies, ESM + CJS, works in browsers, Node.js 20+, Bun, Deno and Cloudflare Workers (everything except the CLI uses only fetch). The package also ships the CLI. @itemshop/sdk re-exports both the storefront and the client entry.

Installation

Storefront (no key)

Sites hosted by ItemShop get window.__ITEMSHOP__ = { shopId, apiBase, locale } injected, so no configuration is needed:
The site never touches payment data — checkout.create returns a redirectUrl to the gateway. If you omit consents.legalVersion the SDK sends the current shop.legal.version; pass the version you actually showed the buyer so a stale page gets LEGAL_DOCUMENTS_CHANGED. After CAPTCHA_REQUIRED, retry checkout with captchaToken. Types (StorefrontShop, StorefrontProduct, CheckoutResult…) are generated from the Storefront API spec.

React

  • Hooks share one request cache per provider. Nothing is fetched during SSR, and the cart renders empty on the server and during hydration.
  • useCart() returns items, count, subtotal, isEmpty, add(product, qty, variant), remove(productId, variant?) and clear(). The cart holds up to 20 lines and checkout() sends them all as one payment group.
  • useCheckout() takes the cart’s lines, sends one Idempotency-Key per attempt (a double click never creates two orders), redirects to the gateway (redirect: false opts out) and exposes validateDiscount(code).
  • Also: useRedeemVoucher(), useProduct(slug), usePaymentMethods(), useOrderStatusByNumber({ number, key }), useRecentPurchases(), useTopSpenders(), useMonthlyGoal(), useOnlinePlayers(), useStorefront() (the raw client) and useStorefrontQuery(key, fn).
  • initialData accepts the build-time snapshot (await sf.snapshot() reads /itemshop.data.json).

API client (with a key)

Server-side only — createClient refuses to start in a browser (the key would be public) unless you pass dangerouslyAllowBrowser: true. Key permissions: API with a key.
The client covers, among others, products, orders, stats, apiKeys, templates, site (files, draft, revisions, upload, builds, deployments, ai), workspace, agents, skills, scopes.

Errors, retries, cancellation

Every failure is an ItemShopError:
  • Retries: GET/HEAD and requests carrying an Idempotency-Key retry network errors, timeouts and 408/425/429/5xx (2 retries, exponential backoff with jitter, Retry-After honoured up to 5 s). Any other request retries only on 429. Configure with retry: { retries, baseDelayMs, maxDelayMs } or retry: false.
  • Idempotency: checkout.create sends a fresh key automatically; pass idempotencyKey to control it.
  • Timeouts: 30 s per attempt (timeoutMs), uploads 5 min.
  • Cancellation: every method takes { signal } as its last argument.
Options shared by both factories: apiBase (default https://itemshop.dev/api/v2), fetch, headers, timeoutMs, retry. Error codes and rate limits: Errors and limits.

Webhooks

ItemShop sends no signed outgoing webhooks — see Webhooks (Discord) and the plugin protocol for real-time order delivery.

CLI

Full reference: CLI. Running your own Vite? Add the plugin instead of itemshop dev:
vite.config.ts

CLI

init, dev, deploy, pull.

Storefront API

The endpoints under the SDK.