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

@shopifylabs/ajax

v0.1.1

Published

Shopify AJAX API wrapper with typed responses

Readme

@shopifylabs/ajax

A fully typed Shopify AJAX API wrapper. Built on native fetch, async/await, and designed for Shopify cart endpoints.

Installation

npm install @shopifylabs/ajax

API Reference

Cart API

import { cart } from '@shopifylabs/ajax';

cart.add(item)

Adds one or more items to the Shopify cart.

// Single item
await cart.add({ id: 44012345, quantity: 1 });

// With line item properties
await cart.add({
  id: 44012345,
  quantity: 1,
  properties: { 'Engraving': 'Happy Birthday' },
});

// Multiple items
await cart.add([
  { id: 44012345, quantity: 1 },
  { id: 44012346, quantity: 2 },
]);

| Param | Type | Description | |-------|------|-------------| | item | CartItem \| CartItem[] | Single item or array |

cart.update(updates)

Updates item quantities. Set to 0 to remove.

await cart.update({
  44012345: 3,   // Set quantity to 3
  44012346: 0,   // Remove item
});

| Param | Type | Description | |-------|------|-------------| | updates | Record<number, number> | Variant ID to quantity map |

cart.clear()

Clears the entire cart.

await cart.clear();

cart.get()

Fetches the current cart state.

const currentCart = await cart.get();
console.log(`Items: ${currentCart.item_count}`);
console.log(`Total: $${(currentCart.total_price / 100).toFixed(2)}`);

Low-Level Fetch

request(url, options?)

Lightweight fetch wrapper with JSON defaults. Available for custom Shopify API calls.

import { request } from '@shopifylabs/ajax';

const data = await request('/recommendations/products.json?product_id=123&limit=4');
const results = await request('/search/suggest.json?q=shirt');

Types

interface CartItem {
  id: number;
  quantity: number;
  properties?: Record<string, string>;
}

interface CartResponse {
  token: string;
  note: string | null;
  attributes: Record<string, string>;
  total_price: number;       // In cents
  total_weight: number;
  item_count: number;
  items: CartLineItem[];
  requires_shipping: boolean;
  currency: string;
}

interface CartLineItem {
  id: number;
  quantity: number;
  title: string;
  price: number;
  line_price: number;
  variant_id: number;
  product_id: number;
  image: string;
  url: string;
  properties: Record<string, string>;
}

Full Workflow Example

import { cart } from '@shopifylabs/ajax';

// Add to cart
await cart.add({ id: 44012345, quantity: 1 });

// Check cart
const current = await cart.get();
console.log(`${current.item_count} items`);

// Update quantity
await cart.update({ 44012345: 3 });

// Clear cart
await cart.clear();

Error Handling

try {
  await cart.add({ id: 999999999, quantity: 1 });
} catch (error) {
  // "[ShopifyLabs] Request failed: 422 Unprocessable Entity — ..."
  console.error(error.message);
}

License

MIT © ShopifyLabs