Js
A collection of skills for AI coding agents. SDK setup and integration guidance for headless WooCommerce development.
npx -y skills add cocart-headless/cocart-skills --skill jsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
CoCart TypeScript/JavaScript SDK patterns for headless WooCommerce. Use when setting up CoCart in JS/TS projects including Astro, Next.js, Nuxt, SvelteKit, Remix, Hono, Elysia.js, Fastify, Deno, Framer, or Webflow.
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
4.9 KB, ~1.0k tokens by cl100k_base, as published. Nobody here has run it
CoCart JS/TS SDK Skill
You are an expert in CoCart — the headless WooCommerce REST API — and its official TypeScript/JavaScript SDK (@cocartheadless/sdk).
Language Routing
Detect the user's language or runtime from their project context and apply the correct skill:
- TypeScript / JavaScript / Node.js / Astro / Next.js / Nuxt / SvelteKit / Remix / Hono / Deno / Bun / Framer / Webflow → use this skill (
js) - PHP / Laravel / Symfony / WordPress → use
php - Python / Django / FastAPI / Flask → use
python - Go / net/http / Gin / Echo / Fiber → use
go - Flutter / Dart → use
flutter - Swift / iOS / macOS / watchOS / tvOS / visionOS → use
swift
If the language is ambiguous, default to this skill (JS/TS) and mention the other SDKs are available.
Installation
# npm
npm install @cocartheadless/sdk
# yarn
yarn add @cocartheadless/sdk
# pnpm
pnpm add @cocartheadless/sdk
# bun
bun add @cocartheadless/sdk
# CDN (Framer, Webflow, plain HTML — no npm required)
# <script src="https://cdn.jsdelivr.net/npm/@cocartheadless/sdk/dist/index.global.js"></script>
Requirements: Node.js 20+, CoCart plugin installed on WooCommerce store. TypeScript 5.0+ recommended.
Quick Start
import { CoCart } from '@cocartheadless/sdk';
const client = new CoCart('https://your-store.com');
// Browse products (no auth required)
const products = await client.products().all({ per_page: '12' });
// Add to cart (guest session created automatically)
await client.cart().addItem(123, 2);
// Get cart with dot-notation access
const cart = await client.cart().get();
console.log(cart.get('totals.total'));
console.log(cart.getItems());
// Fluent configuration
const client = new CoCart('https://your-store.com')
.setTimeout(15000)
.setMaxRetries(2)
.addHeader('X-Custom', 'value');
Environment Variables
Always keep store credentials server-side. Suggested .env pattern:
# Public (safe to expose to browser)
NEXT_PUBLIC_STORE_URL=https://your-store.com # Next.js
PUBLIC_STORE_URL=https://your-store.com # Astro / SvelteKit / Vite
# Private (server-side only)
STORE_URL=https://your-store.com
COCART_CONSUMER_KEY=ck_xxx
COCART_CONSUMER_SECRET=cs_xxx
COCART_ENCRYPTION_KEY=your-32-char-secret-key
Common Mistakes
- Using cookies for cart state — CoCart passes cart state via HTTP headers, not cookies. This avoids GDPR consent issues and CORS restrictions. Never set
document.cookiefor cart keys. - Forgetting
restoreSession()in browser adapters — Always callawait client.restoreSession()before making cart calls in browser/client components, or the guest session will be lost on page reload. - Exposing consumer keys to the browser — Consumer keys (
ck_xxx,cs_xxx) are server-side only. UseNEXT_PUBLIC_orPUBLIC_prefixed env vars only for the store URL. - Not handling JWT token expiry — Use
client.jwt().withAutoRefresh()instead of manually managing tokens. The SDK handles refresh transparently. - Passing numbers where strings are expected — The Products API params like
per_pageandpageare strings:{ per_page: '12' }, not{ per_page: 12 }.
When to Load References
- Setting up a framework adapter (Astro, Next.js, Nuxt, SvelteKit, Remix, Hono, etc.) → references/adapters.md
- Configuring authentication (guest, Basic Auth, consumer keys, JWT) → references/authentication.md
- Working with cart operations (add, update, remove, coupons, currency formatting) → references/cart.md
- Querying products (list, search, filter, single product) → references/products.md
WordPress / WooCommerce Requirements
- WooCommerce installed and active
- CoCart plugin installed (free tier available)
- CoCart Plus for advanced features (Checkout API, extended Sessions, etc.)
- Optional: CoCart JWT Authentication for JWT auth
What ships with it: 4 files
8.4 KB alongside SKILL.md
references/
- adapters.md4.5 KB
- authentication.md1.0 KB
- cart.md1.9 KB
- products.md945 B