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

@drewsepsi/billing-sdk

v1.0.1

Published

TypeScript SDK for @drewsepsi/billing - Add subscriptions and usage billing to your app

Readme

@drewsepsi/billing-sdk

TypeScript SDK for adding subscriptions and usage billing to your Next.js app. Integrate with Stripe in minutes, not days.

Quick Start

npm install @drewsepsi/billing-sdk
import { BillingSDK } from "@drewsepsi/billing-sdk";

const billing = new BillingSDK({
  baseUrl: process.env.NEXT_PUBLIC_API_URL,
});

// Create a checkout session
const url = await billing.createCheckout({
  priceId: "price_pro",
  userId: "user_123",
});

// Redirect user to Stripe
window.location.href = url;

Features

  • One-line checkout - Create Stripe checkout sessions instantly
  • 📊 Usage tracking - Built-in metering for usage-based billing
  • 🔐 License validation - Verify SDK licenses with tier-based features
  • 🎨 React hooks - Ready-to-use useSubscription, useBilling hooks
  • 🧪 Sandbox mode - Test billing flows without real charges
  • 📝 TypeScript - Full type safety out of the box

Installation

npm install @drewsepsi/billing-sdk
# or
yarn add @drewsepsi/billing-sdk
# or
pnpm add @drewsepsi/billing-sdk

Basic Usage

1. Initialize the SDK

import { BillingSDK } from "@drewsepsi/billing-sdk";

const billing = new BillingSDK({
  baseUrl: process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000",
  license: {
    licenseKey: process.env.DREW_BILLING_LICENSE_KEY, // Optional: for SDK features
  },
});

2. Create a Checkout

const checkout = await billing.createCheckout({
  priceId: "price_pro_monthly",
  userId: "user_123",
  successUrl: "/dashboard?success=true",
  cancelUrl: "/pricing?canceled=true",
});

// Redirect to Stripe
window.location.href = checkout.url;

3. Check Subscription Status

const subscription = await billing.getSubscription("user_123");

if (subscription.status === "active") {
  // Grant premium access
}

4. Track Usage

// Record an API call or feature usage
await billing.trackUsage({
  userId: "user_123",
  event: "api_call",
  quantity: 1,
});

// Check remaining quota
const usage = await billing.getUsage("user_123");
console.log(`Used ${usage.current} of ${usage.limit}`);

React Integration

Provider Setup

import { BillingProvider } from "@drewsepsi/billing-sdk/react";

function App() {
  return (
    <BillingProvider
      config={{
        baseUrl: process.env.NEXT_PUBLIC_API_URL,
      }}
    >
      <YourApp />
    </BillingProvider>
  );
}

Use Subscription Hook

import { useSubscription } from "@drewsepsi/billing-sdk/react";

function Dashboard() {
  const { subscription, isLoading, isActive } = useSubscription("user_123");

  if (isLoading) return <Spinner />;

  return (
    <div>
      <h1>Dashboard</h1>
      {isActive ? (
        <PremiumFeatures />
      ) : (
        <UpgradePrompt />
      )}
    </div>
  );
}

Server-Side Usage

For API routes and server components:

import { BillingSDK } from "@drewsepsi/billing-sdk/server";

// Server-side SDK (no React dependencies)
const billing = new BillingSDK({
  baseUrl: process.env.API_URL,
  apiKey: process.env.BILLING_API_KEY,
});

// Validate a license key
const license = await billing.validateLicense("license_key_here");

if (license.valid && license.tier === "pro") {
  // Grant pro features
}

Sandbox Mode

Test your billing integration without real charges:

import { createSandboxBilling } from "@drewsepsi/billing-sdk/sandbox";

const billing = createSandboxBilling({
  baseUrl: "http://localhost:3000",
});

// All operations work without hitting Stripe
const checkout = await billing.createCheckout({
  priceId: "test_price",
  userId: "test_user",
});

License Validation (SDK Customers)

If you've purchased a Drew Billing SDK license, validate it to unlock features:

const billing = new BillingSDK({
  baseUrl: "https://your-app.com",
  license: {
    licenseKey: process.env.DREW_BILLING_LICENSE_KEY,
  },
});

// The SDK automatically validates on initialization
// and enables features based on your tier (Pro/Team/Enterprise)

API Reference

BillingSDK

Main SDK class for billing operations.

| Method | Description | |--------|-------------| | createCheckout(options) | Create a Stripe checkout session | | getSubscription(userId) | Get user's subscription status | | getUsage(userId) | Get usage statistics | | trackUsage(event) | Track a usage event | | validateLicense(key) | Validate a license key | | createCustomerPortal(userId) | Create customer portal session |

React Hooks

| Hook | Description | |------|-------------| | useSubscription(userId) | Get subscription state | | useBilling() | Access SDK instance | | useUsage(userId) | Track and display usage |

Environment Variables

# Required
NEXT_PUBLIC_API_URL=https://your-app.com

# Optional (for SDK license validation)
DREW_BILLING_LICENSE_KEY=your-license-key-here

# Optional (for server-side)
BILLING_API_KEY=your-api-key

Examples

SaaS Starter

npx @drewsepsi/billing-cli init --template saas

API Product with Usage

npx @drewsepsi/billing-cli init --template api

AI Credits System

npx @drewsepsi/billing-cli init --template ai-credits

Documentation

License

MIT © Drew


Built with ❤️ by Drew Billing