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

@webmate-studio/shop-sdk

v0.3.0

Published

Lightweight JavaScript SDK for Webmate Studio Shop API

Downloads

386

Readme

@webmate-studio/shop-sdk

Lightweight JavaScript SDK for the Webmate Studio Shop API. Zero dependencies, ~3KB gzipped.

Installation

npm install @webmate-studio/shop-sdk

Quick Start

import { createShopClient } from '@webmate-studio/shop-sdk';

// Create client - API URL is automatically detected from meta tag
const shop = createShopClient();

// Or with explicit configuration (overrides meta tag)
const shop = createShopClient({
  apiUrl: 'https://your-tenant.cms.example.com',
  tenantId: 'tenant-uuid' // Only needed for cross-origin requests
});

Configuration

The SDK automatically detects the API URL from the <meta name="webmate-api"> tag in the document:

<meta name="webmate-api" content="https://your-tenant.cms.example.com">

This meta tag is automatically set by:

  • CMS Preview (/preview/[uuid]/)
  • Webmate CLI Preview (wm dev)
  • Website Build (generated HTML files)

If no meta tag is found and no apiUrl is provided, the SDK will throw an error.

Products

// List products
const products = await shop.products.list({
  collection: 'new-arrivals',  // Filter by collection slug
  search: 'shirt',             // Search in title, description
  tag: 'summer',               // Filter by tag
  productType: 'PHYSICAL',     // PHYSICAL or DIGITAL
  limit: 12,                   // Results per page (max 100)
  cursor: 'abc123'             // For pagination
});

// Get single product
const product = await shop.products.getBySlug('blue-t-shirt');

Collections

// List all collections
const collections = await shop.collections.list();

// Get collection with products
const collection = await shop.collections.getBySlug('summer-sale', {
  limit: 24
});

Cart

Cart session is managed automatically via localStorage.

// Get current cart (creates new one if needed)
const cart = await shop.cart.get();

// Add item to cart
const cart = await shop.cart.addItem({
  variantId: 'variant-uuid',
  quantity: 2
});

// Update item quantity
const cart = await shop.cart.updateItem('item-id', { quantity: 3 });

// Remove item
const cart = await shop.cart.removeItem('item-id');

// Apply discount code
const cart = await shop.cart.applyDiscount('SUMMER20');

// Remove discount
const cart = await shop.cart.removeDiscount();

// Clear cart completely
shop.cart.clear();

Checkout

// Get available payment providers
const providers = await shop.checkout.getPaymentProviders();

// Get shipping rates
const rates = await shop.checkout.getShippingRates({
  shippingAddress: {
    firstName: 'Max',
    lastName: 'Mustermann',
    address1: 'Musterstr. 1',
    city: 'Berlin',
    zip: '10115',
    country: 'DE'
  }
});

// Create checkout
const checkout = await shop.checkout.create({
  shippingAddress: { ... },
  billingAddress: { ... },      // Optional, defaults to shipping
  shippingRateId: 'rate-uuid',
  paymentProvider: 'stripe',    // stripe, paypal, manual
  email: '[email protected]' // For guest checkout
});

// After payment (e.g., Stripe confirmation)
const order = await shop.checkout.complete({
  orderId: checkout.orderId,
  paymentIntentId: 'pi_xxx'     // From Stripe
});

Customer Authentication

Customer tokens are managed automatically via localStorage.

// Check login status
if (shop.customers.isLoggedIn()) {
  console.log('Customer is logged in');
}

// Register
await shop.customers.register({
  email: '[email protected]',
  password: 'secure123',
  firstName: 'Max',
  lastName: 'Mustermann',
  acceptsMarketing: true
});

// Login
await shop.customers.login({
  email: '[email protected]',
  password: 'secure123'
});

// Logout (clears all session data)
shop.customers.logout();

// Get profile
const customer = await shop.customers.getMe();

// Update profile
await shop.customers.updateMe({
  firstName: 'Maximilian'
});

// Get orders
const orders = await shop.customers.getOrders({ limit: 10 });

// Password reset
await shop.customers.forgotPassword('[email protected]');
await shop.customers.resetPassword({
  token: 'token-from-email',
  password: 'newpassword123'
});

Addresses

// Get all addresses
const addresses = await shop.customers.getAddresses();

// Add address
const address = await shop.customers.addAddress({
  firstName: 'Max',
  lastName: 'Mustermann',
  address1: 'Musterstr. 1',
  address2: 'Apt 4',
  city: 'Berlin',
  zip: '10115',
  country: 'DE',
  isDefault: true
});

// Update address
await shop.customers.updateAddress('address-id', { city: 'Hamburg' });

// Delete address
await shop.customers.deleteAddress('address-id');

Error Handling

import { createShopClient, ShopAPIError } from '@webmate-studio/shop-sdk';

try {
  await shop.cart.addItem({ variantId: 'invalid' });
} catch (error) {
  if (error instanceof ShopAPIError) {
    console.log(error.message);  // "Product variant not found"
    console.log(error.status);   // 404
    console.log(error.data);     // Full error response
  }
}

Session Management

For advanced use cases, you can access session utilities directly:

import {
  getCartToken,
  setCartToken,
  getCustomerToken,
  setCustomerToken,
  clearSession
} from '@webmate-studio/shop-sdk';

// Or via the client
shop.session.getCartToken();
shop.session.clearSession();

Usage in Components

Vanilla JavaScript

<script type="module">
  import { createShopClient } from '@webmate-studio/shop-sdk';

  const shop = createShopClient();

  document.getElementById('add-to-cart').addEventListener('click', async () => {
    const variantId = this.dataset.variantId;
    const cart = await shop.cart.addItem({ variantId, quantity: 1 });
    updateCartUI(cart);
  });
</script>

Svelte

<script>
  import { createShopClient } from '@webmate-studio/shop-sdk';
  import { onMount } from 'svelte';

  const shop = createShopClient();
  let cart = null;

  onMount(async () => {
    cart = await shop.cart.get();
  });

  async function addToCart(variantId) {
    cart = await shop.cart.addItem({ variantId, quantity: 1 });
  }
</script>

Browser Support

Works in all modern browsers with ES Module support. Requires fetch and localStorage.

License

MIT