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

Every method is typed against the REST API it wraps — see the API Reference for parameters and response shapes.

CategoryMethods
StoremeGet, socialsGet
ProductsproductBrowse, productGet, productCreate, productUpdate, productDelete, productBatch, productFilters
VariantsvariantGet, variantCreate, variantUpdate, variantDelete
InventoryinventoryBrowse, inventoryAdjust
CollectionscollectionBrowse, collectionGet, collectionCreate, collectionUpdate, collectionDelete, collectionImportMemberships
CategoriescategoriesBrowse, categoryGet, categoryCreate, categoryUpdate, categoryDelete
BrandsbrandBrowse, brandGet, brandCreate, brandUpdate, brandDelete, brandAssignProducts
Searchsearch
ReviewsproductReviewsBrowse, productReviewCreate
CartcartUpsert, cartGet, cartAddBundle, cartRemoveItem, cartDelete
OrdersorderBrowse, orderGet, orderUpdate, orderRefundsBrowse, orderRefundGet
CustomerscustomerBrowse, customerGet, customerUpdate, customerAddressCreate, customerAddressDelete, customerOrdersBrowse
CouponscouponBrowse, couponGet, couponCreate, couponUpdate, couponDelete
Events & ticketseventBrowse, eventGet, eventCreate, eventUpdate, eventAttendeesBrowse, ticketsGet, ticketsUpdate, ticketAttendeeGet
BlogpostBrowse, postGet, postCreate, postUpdate, postDelete, postCommentsBrowse, postCommentCreate, blogCategoryBrowse, blogCategoryGet, blogCategoryCreate, blogCategoryUpdate, blogCategoryDelete
MarketingsubscriberCreate, subscriberDelete, contactMessageCreate
Legal pageslegalPageBrowse, legalPageGet, legalPageCreate, legalPageUpdate
SupportsupportCaseBrowse, supportCaseGet, supportCaseCreate, supportCaseUpdate, supportCaseReply
Add-onsinstaviewImagesBrowse
Utilityrequest

Browse methods list and paginate, Get fetches one record, and Create/Update/Delete do what they say.

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" },
});