npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sanity-plugin-simple-commerce

v1.1.3

Published

Sanity plugin for simple ecommerce with Stripe integration

Readme

sanity-plugin-simple-commerce

A Sanity v3 plugin for simple ecommerce with Stripe integration.

Installation

From npm (once published)

npm install sanity-plugin-simple-commerce

From GitHub

For projects before npm publication, install directly from GitHub:

{
  "dependencies": {
    "sanity-plugin-simple-commerce": "github:cn-d/simple-commerce"
  }
}

Then run npm install.

Usage

// sanity.config.ts
import { defineConfig } from 'sanity'
import { simpleCommerce } from 'sanity-plugin-simple-commerce'

export default defineConfig({
  // ...
  plugins: [
    simpleCommerce({
      prefix: 'STORE',      // Prefix for SKUs and order IDs
      currency: 'GBP',      // 'GBP' | 'USD' | 'EUR'
    }),
  ],
})

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | prefix | string | required | Prefix for SKUs and order IDs | | currency | 'GBP' \| 'USD' \| 'EUR' | 'GBP' | Currency for price display | | priceValidation | object | { minPrice: 0 } | Price validation rules (minPrice, maxPrice) | | orderFields | object | { trackingUrl: true, trackingCode: true, dispatchedAt: true } | Optional order fields | | maxVariantsWarning | number | 50 | Show warning when variants exceed this count |

Price Format

All prices are stored in the smallest currency unit (pence for GBP, cents for USD/EUR). This matches Stripe's unit_amount format directly, so no conversion is needed when creating checkout sessions.

For example, to set a price of £29.99, enter 2999 in Sanity Studio.

What's Included

Schemas

  • Product - Product catalog with variant support
  • Order - Order management with status tracking

Document Actions

  • Generate Variants - Auto-generate variant combinations from options
  • Dispatch Order - Mark order as dispatched (triggers webhook for email)
  • Retry Dispatch Email - Re-trigger webhook if dispatch email failed
  • Clear Dispatch Pending - Recovery action when webhook fails to clear pending state

GROQ Queries

Import queries from the /queries subpath. This is a lightweight import that works in Next.js Server Components without pulling in React dependencies.

import { queries } from 'sanity-plugin-simple-commerce/queries'

// Available queries:
// - queries.PRODUCTS_LIST
// - queries.PRODUCT_BY_SLUG
// - queries.ORDER_BY_ID
// - queries.VARIANT_STOCK
// - queries.VARIANT_WITH_PRICE
// - queries.PRODUCT_ID_BY_SLUG
// - queries.PENDING_ORDERS
// - queries.DISPATCHED_ORDERS

Helper Functions

Import helpers from the /helpers subpath for use in API routes and webhooks.

import {
  createOrderDocument,
  decrementVariantStock,
  checkVariantStock,
  getProductBySku,
} from 'sanity-plugin-simple-commerce/helpers'

// Create order from Stripe checkout session (use in webhook)
const order = await createOrderDocument({
  client: sanityClient,
  session: stripeCheckoutSession,
  prefix: 'STORE',
})

// Decrement stock with automatic retry on concurrent modification
const result = await decrementVariantStock({
  client: sanityClient,
  slug: 'product-slug',
  sku: 'SKU-123',
  maxRetries: 3, // default: 3, with exponential backoff
})
if (!result.success) {
  console.error(result.error)
} else {
  console.log(`Updated in ${result.attempts} attempt(s)`)
}

// Check stock availability
const { available, stock } = await checkVariantStock({
  client: sanityClient,
  slug: 'product-slug',
  sku: 'SKU-123',
})

Types

import type {
  Product,
  ProductVariant,
  Order,
  OrderItem,
  ShippingAddress,
} from 'sanity-plugin-simple-commerce'

Documentation

Development

See CONTRIBUTING.md for detailed development workflow.

Quick Start

# Install dependencies
npm install

# Build
npm run build

# Watch mode
npm run watch

# Link to test project with yalc
npm run link-watch

Local Development with yalc

When developing the plugin alongside a project that uses it:

# In this plugin directory
yalc publish

# In your project directory
yalc link sanity-plugin-simple-commerce

This creates a local override without changing the project's package.json.

License

MIT