Search Documentation

Search for a documentation page...

Commerce SDK Overview

The Commerce SDK is a typed TypeScript client for the YNS API. Zero-config setup, full type safety.

What is the Commerce SDK?

The Commerce SDK (commerce-kit) is a lightweight TypeScript client that wraps the YNS REST API. It provides typed methods for every endpoint, automatic environment detection, and zero-config initialization.

Installation

npm install commerce-kit

Quick Start

import { Commerce } from "commerce-kit";

const commerce = Commerce();

// Browse products
const products = await commerce.productBrowse({ limit: 10 });

// Get a single product
const product = await commerce.productGet({ idOrSlug: "classic-tee" });

// Create a cart
const cart = await commerce.cartUpsert({
items: [{ variantId: "var_123", quantity: 1 }],
});

Configuration

The SDK reads YNS_API_KEY from your environment by default:

// Zero-config — reads from process.env.YNS_API_KEY
const commerce = Commerce();

// Explicit configuration
const commerce = Commerce({
token: "sk-your-api-key",
endpoint: "https://yns.store",
});

Environment Detection

The SDK automatically detects staging vs production based on your API key prefix:

  • sk-... connects to yns.store (production)
  • sk-s-... connects to yns.cx (staging/sandbox)

Available Methods

CategoryMethods
ProductsproductBrowse, productGet, productCreate, productUpdate, productDelete
CartcartUpsert, cartGet, cartRemoveItem
OrdersorderBrowse, orderGet, orderUpdate
CollectionscollectionBrowse, collectionGet, collectionCreate
CategoriescategoriesBrowse, categoryGet, categoryCreate, categoryUpdate
CustomerscustomerBrowse, customerGet, customerUpdate, customerAddressCreate, customerAddressDelete, customerOrdersBrowse
PostspostBrowse, postGet, postCreate, postUpdate, postDelete
InventoryinventoryBrowse, inventoryAdjust
VariantsvariantGet, variantCreate, variantUpdate, variantDelete
SubscriberssubscriberCreate, subscriberDelete
UtilitymeGet, request

Raw Requests

For endpoints not yet wrapped, use the escape hatch:

const result = await commerce.request<MyType>("/v1/custom-endpoint", {
method: "POST",
body: { key: "value" },
});