@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 getwindow.__ITEMSHOP__ = { shopId, apiBase, locale } injected, so no configuration is needed:
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()returnsitems,count,subtotal,isEmpty,add(product, qty, variant),remove(productId, variant?)andclear(). The cart holds up to 20 lines andcheckout()sends them all as one payment group.useCheckout()takes the cart’s lines, sends oneIdempotency-Keyper attempt (a double click never creates two orders), redirects to the gateway (redirect: falseopts out) and exposesvalidateDiscount(code).- Also:
useRedeemVoucher(),useProduct(slug),usePaymentMethods(),useOrderStatusByNumber({ number, key }),useRecentPurchases(),useTopSpenders(),useMonthlyGoal(),useOnlinePlayers(),useStorefront()(the raw client) anduseStorefrontQuery(key, fn). initialDataaccepts 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.
products, orders, stats, apiKeys, templates, site (files, draft, revisions, upload, builds, deployments, ai), workspace, agents, skills, scopes.
Errors, retries, cancellation
Every failure is anItemShopError:
- Retries: GET/HEAD and requests carrying an
Idempotency-Keyretry network errors, timeouts and 408/425/429/5xx (2 retries, exponential backoff with jitter,Retry-Afterhonoured up to 5 s). Any other request retries only on 429. Configure withretry: { retries, baseDelayMs, maxDelayMs }orretry: false. - Idempotency:
checkout.createsends a fresh key automatically; passidempotencyKeyto control it. - Timeouts: 30 s per attempt (
timeoutMs), uploads 5 min. - Cancellation: every method takes
{ signal }as its last argument.
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
itemshop dev:
vite.config.ts
CLI
init, dev, deploy, pull.Storefront API
The endpoints under the SDK.