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

@usethrottle/cart

v3.1.0

Published

Typed REST client for the Throttle Cart API.

Downloads

554

Readme

@usethrottle/cart

Typed Node.js REST client for the Throttle Cart API.

Install

npm install @usethrottle/cart

Quickstart

End-to-end: create a cart, build it out, and convert it to an order.

import { CartClient } from '@usethrottle/cart';

const client = new CartClient({ apiKey: process.env.THROTTLE_API_KEY! });

// 1. Create a cart
const cart = await client.carts.create({
  storeId: 'store_abc',
  currency: 'USD',
  netN: 45,
});

// 2. Add a line item
await client.items.add(cart.id, {
  type: 'product',
  name: 'Premium Widget',
  unitPrice: 2999,
  quantity: 2,
});

// 3. Select a shipping method
await client.shipping.select(cart.id, {
  methodId: 'fedex_ground',
  displayName: 'FedEx Ground',
  rateAmount: 599,
});

// 4. Apply a discount code
await client.discounts.apply(cart.id, 'SAVE10');

// 5. Set tax lines
await client.taxLines.set(cart.id, [
  { lineItemId: '...', jurisdictionCode: 'US-NY', taxType: 'sales', rate: 0.04, amount: 400 },
]);

// 6. Checkout → Order
const order = await client.carts.checkout(cart.id, { paymentMethod: 'card' });
console.log(order.id, order.status);

applicationId is accepted as an alias for storeId when your integration already uses the newer application naming.

All monetary values are integers in the smallest currency unit (cents for USD).

Net-N invoice terms

Cart-level invoice terms are optional. Pass netN on cart create or update to set the cart override, or null to clear it. The final invoice term is resolved when the buyer completes checkout with Invoice Terms:

customer.netN ?? cart.netN ?? DEFAULT_NET_N

allowedMethods only controls which payment methods can appear in checkout; it does not change the Net-N day count. For hosted/embed checkout, create a cart with netN and then create a checkout session for that cart.

Shipping and tax

Use the secret-key client on your backend to calculate and persist cart totals with Throttle's native engine:

const estimate = await client.shippingTax.calculateCart(cart.id, {
  kind: 'cart_estimate',
});

const locked = await client.shippingTax.calculateCart(cart.id, {
  kind: 'checkout_final',
  selectedShippingMethodId: estimate.shipping.selectedMethod?.id,
});

External stores can also request read-only storefront quotes with a publishable pk_ quote token. Create one from the dashboard Shipping & Tax page or with POST /api/v1/shipping-tax/quote-tokens.

import { StorefrontQuoteClient } from '@usethrottle/cart';

const quotes = new StorefrontQuoteClient({
  applicationId: 'application_uuid',
  quoteToken: 'pk_publishable_quote_token',
});

const estimate = await quotes.quote({
  currency: 'USD',
  items: [
    {
      id: 'sku_123',
      quantity: 1,
      subtotalAmount: 12900,
      requiresShipping: true,
      taxCategory: 'standard',
    },
  ],
  addresses: {
    shipping: { countryCode: 'US', stateProvince: 'CA', postalCode: '90001' },
  },
});

For provider-owned totals, set the store to byo mode on the shipping or tax axis (or both) and push the final snapshot through /api/v1/shipping-tax/external-snapshots. Throttle accepts external pushes when at least one axis is in byo mode:

await client.shippingTax.pushExternalSnapshot({
  storeId: 'store_uuid',
  cartId: cart.id,
  currency: 'USD',
  totals: {
    subtotal: 12900,
    discountTotal: 0,
    shippingTotal: 600,
    taxTotal: 1215,
    total: 14715,
  },
});

Subscriptions

Pass type: 'subscription' and a recurring block on the line item:

await client.items.add(cart.id, {
  type: 'subscription',
  name: 'Pro Plan',
  unitPrice: 1900,
  quantity: 1,
  recurring: { interval: 'month', count: null }, // count: null = until cancelled
});

Then call client.carts.checkout as normal. Set count to a number to cap the billing cycles.

Events

Every mutation appends an immutable event to the cart's event log. Fetch it with:

const events = await client.events.list(cart.id);
// [{ eventType: 'cart.created', sequence: 1, ... }, ...]

// Poll only new events since the last sequence you saw
const newEvents = await client.events.list(cart.id, { sinceSequence: 5, limit: 50 });

For real-time delivery, subscribe to Throttle's outbound webhooks from your merchant dashboard. Webhooks are signed with HMAC-SHA256 and fire from Throttle's servers to your backend over HTTPS.

Errors

All non-2xx responses throw ThrottleApiError. Inspect code for the machine-readable reason and statusCode for the HTTP status:

import { ThrottleApiError } from '@usethrottle/cart';

try {
  await client.discounts.apply(cart.id, 'EXPIRED');
} catch (e) {
  if (e instanceof ThrottleApiError && e.code === 'discount_invalid') {
    // surface a user-friendly message
  }
  if (e instanceof ThrottleApiError) {
    console.error(e.statusCode, e.code, e.message);
  }
}

Client options

| Option | Default | Description | | ----------- | ----------------------------- | ----------------------------------------------------------- | | apiKey | — | Required. Your Throttle secret key (sk_…). | | baseUrl | https://api.usethrottle.dev | Optional override for a dedicated Throttle API environment. | | timeoutMs | 30000 | Per-request abort timeout in ms. | | fetch | globalThis.fetch | Custom fetch implementation (e.g. node-fetch). |

See also