{"_id":"@drewsepsi/billing-sdk","_rev":"2-3faa48486b49530e010a43a577737742","name":"@drewsepsi/billing-sdk","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@drewsepsi/billing-sdk","version":"1.0.0","keywords":["stripe","billing","subscriptions","saas","payments","usage-based","entitlements"],"author":{"name":"Drew"},"license":"MIT","_id":"@drewsepsi/billing-sdk@1.0.0","maintainers":[{"name":"drewsepsi","email":"novaraeex@gmail.com"}],"homepage":"https://github.com/drew/billing#readme","bugs":{"url":"https://github.com/drew/billing/issues"},"dist":{"shasum":"f6d9bbb1094764e3f0fdf8e821b594950f0ec157","tarball":"https://registry.npmjs.org/@drewsepsi/billing-sdk/-/billing-sdk-1.0.0.tgz","fileCount":10,"integrity":"sha512-8K4ec+co+MTp0QwD7vJTBAsO2vbkvfM6E+QWow54PTQwbKtPKPRDw4zklVBdYyjmQXhxDh86rlssUHnqLcdW8Q==","signatures":[{"sig":"MEYCIQD6aRqWtkB7k9bWVIFDFpo0ClQLOi7F0dS5h4WcCPs92QIhAJQjXqGJUrklmhRzT5BZSxadBnhX1gJ4omVrVpv4O5Nw","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":50477},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./react":{"types":"./dist/react/index.d.ts","import":"./dist/react/index.js"},"./server":{"types":"./dist/server/index.d.ts","import":"./dist/server/index.js"},"./sandbox":{"types":"./dist/sandbox/index.d.ts","import":"./dist/sandbox/index.js"}},"gitHead":"9798afce6bce45f7d9ef03bcb520cace687885c0","scripts":{"dev":"tsup src/index.ts src/react/index.tsx src/server/index.ts src/sandbox/index.ts --format esm --dts --watch","lint":"eslint src","test":"vitest","build":"tsup src/index.ts src/react/index.tsx src/server/index.ts src/sandbox/index.ts --format esm --dts --clean","typecheck":"tsc --noEmit","prepublishOnly":"npm run build"},"_npmUser":{"name":"drewsepsi","email":"novaraeex@gmail.com"},"repository":{"url":"git+https://github.com/drew/billing.git","type":"git","directory":"packages/sdk"},"_npmVersion":"11.11.0","description":"TypeScript SDK for @drewsepsi/billing - Add subscriptions and usage billing to your app","directories":{},"_nodeVersion":"24.14.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","react":"^18.2.0","vitest":"^1.0.0","react-dom":"^18.2.0","typescript":"^5.3.0","@types/react":"^18.2.0","@types/react-dom":"^18.2.0"},"peerDependencies":{"react":">=18.0.0","react-dom":">=18.0.0"},"peerDependenciesMeta":{"react":{"optional":true},"react-dom":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/billing-sdk_1.0.0_1775767448543_0.40801187173336007","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@drewsepsi/billing-sdk","version":"1.0.1","description":"TypeScript SDK for @drewsepsi/billing - Add subscriptions and usage billing to your app","type":"module","main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/index.js","types":"./dist/index.d.ts"},"./react":{"import":"./dist/react/index.js","types":"./dist/react/index.d.ts"},"./server":{"import":"./dist/server/index.js","types":"./dist/server/index.d.ts"},"./sandbox":{"import":"./dist/sandbox/index.js","types":"./dist/sandbox/index.d.ts"}},"publishConfig":{"access":"public"},"scripts":{"build":"tsup src/index.ts src/react/index.tsx src/server/index.ts src/sandbox/index.ts --format esm --dts --clean","dev":"tsup src/index.ts src/react/index.tsx src/server/index.ts src/sandbox/index.ts --format esm --dts --watch","typecheck":"tsc --noEmit","test":"vitest","lint":"eslint src","prepublishOnly":"npm run build"},"keywords":["stripe","billing","subscriptions","saas","payments","usage-based","entitlements"],"author":{"name":"Drew"},"license":"MIT","peerDependencies":{"react":">=18.0.0","react-dom":">=18.0.0"},"peerDependenciesMeta":{"react":{"optional":true},"react-dom":{"optional":true}},"devDependencies":{"@types/react":"^18.2.0","@types/react-dom":"^18.2.0","react":"^18.2.0","react-dom":"^18.2.0","tsup":"^8.0.0","typescript":"^5.3.0","vitest":"^1.0.0"},"engines":{"node":">=18"},"repository":{"type":"git","url":"git+https://github.com/drew/billing.git","directory":"packages/sdk"},"gitHead":"9798afce6bce45f7d9ef03bcb520cace687885c0","_id":"@drewsepsi/billing-sdk@1.0.1","bugs":{"url":"https://github.com/drew/billing/issues"},"homepage":"https://github.com/drew/billing#readme","_nodeVersion":"24.14.1","_npmVersion":"11.11.0","dist":{"integrity":"sha512-SGv0E8EF19yKvLqnmfDVOtDyp2ByS8eV0NaNQ2VXwJOlCyffW4gH9J/Wfms+RV03DMxrTiwL80O4gxvB/mDImA==","shasum":"7dfcd9f1bb2bd730d96bbdb969c02c6955821bdc","tarball":"https://registry.npmjs.org/@drewsepsi/billing-sdk/-/billing-sdk-1.0.1.tgz","fileCount":11,"unpackedSize":56164,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBIi271dwvXfyJhw4Fct60ixlGm24HsPkeUrvLRnVW02AiAG/6nsBD4bxj2Y8buQBh6nNCD1zBhuGVI7qtxNbZaaqA=="}]},"_npmUser":{"name":"drewsepsi","email":"novaraeex@gmail.com"},"directories":{},"maintainers":[{"name":"drewsepsi","email":"novaraeex@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/billing-sdk_1.0.1_1775768689110_0.9393942028020588"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-09T20:44:08.444Z","modified":"2026-04-09T21:04:49.371Z","1.0.0":"2026-04-09T20:44:08.718Z","1.0.1":"2026-04-09T21:04:49.244Z"},"bugs":{"url":"https://github.com/drew/billing/issues"},"author":{"name":"Drew"},"license":"MIT","homepage":"https://github.com/drew/billing#readme","keywords":["stripe","billing","subscriptions","saas","payments","usage-based","entitlements"],"repository":{"type":"git","url":"git+https://github.com/drew/billing.git","directory":"packages/sdk"},"description":"TypeScript SDK for @drewsepsi/billing - Add subscriptions and usage billing to your app","maintainers":[{"name":"drewsepsi","email":"novaraeex@gmail.com"}],"readme":"# @drewsepsi/billing-sdk\n\nTypeScript SDK for adding subscriptions and usage billing to your Next.js app. Integrate with Stripe in minutes, not days.\n\n## Quick Start\n\n```bash\nnpm install @drewsepsi/billing-sdk\n```\n\n```typescript\nimport { BillingSDK } from \"@drewsepsi/billing-sdk\";\n\nconst billing = new BillingSDK({\n  baseUrl: process.env.NEXT_PUBLIC_API_URL,\n});\n\n// Create a checkout session\nconst url = await billing.createCheckout({\n  priceId: \"price_pro\",\n  userId: \"user_123\",\n});\n\n// Redirect user to Stripe\nwindow.location.href = url;\n```\n\n## Features\n\n- ⚡ **One-line checkout** - Create Stripe checkout sessions instantly\n- 📊 **Usage tracking** - Built-in metering for usage-based billing\n- 🔐 **License validation** - Verify SDK licenses with tier-based features\n- 🎨 **React hooks** - Ready-to-use `useSubscription`, `useBilling` hooks\n- 🧪 **Sandbox mode** - Test billing flows without real charges\n- 📝 **TypeScript** - Full type safety out of the box\n\n## Installation\n\n```bash\nnpm install @drewsepsi/billing-sdk\n# or\nyarn add @drewsepsi/billing-sdk\n# or\npnpm add @drewsepsi/billing-sdk\n```\n\n## Basic Usage\n\n### 1. Initialize the SDK\n\n```typescript\nimport { BillingSDK } from \"@drewsepsi/billing-sdk\";\n\nconst billing = new BillingSDK({\n  baseUrl: process.env.NEXT_PUBLIC_API_URL || \"http://localhost:3000\",\n  license: {\n    licenseKey: process.env.DREW_BILLING_LICENSE_KEY, // Optional: for SDK features\n  },\n});\n```\n\n### 2. Create a Checkout\n\n```typescript\nconst checkout = await billing.createCheckout({\n  priceId: \"price_pro_monthly\",\n  userId: \"user_123\",\n  successUrl: \"/dashboard?success=true\",\n  cancelUrl: \"/pricing?canceled=true\",\n});\n\n// Redirect to Stripe\nwindow.location.href = checkout.url;\n```\n\n### 3. Check Subscription Status\n\n```typescript\nconst subscription = await billing.getSubscription(\"user_123\");\n\nif (subscription.status === \"active\") {\n  // Grant premium access\n}\n```\n\n### 4. Track Usage\n\n```typescript\n// Record an API call or feature usage\nawait billing.trackUsage({\n  userId: \"user_123\",\n  event: \"api_call\",\n  quantity: 1,\n});\n\n// Check remaining quota\nconst usage = await billing.getUsage(\"user_123\");\nconsole.log(`Used ${usage.current} of ${usage.limit}`);\n```\n\n## React Integration\n\n### Provider Setup\n\n```tsx\nimport { BillingProvider } from \"@drewsepsi/billing-sdk/react\";\n\nfunction App() {\n  return (\n    <BillingProvider\n      config={{\n        baseUrl: process.env.NEXT_PUBLIC_API_URL,\n      }}\n    >\n      <YourApp />\n    </BillingProvider>\n  );\n}\n```\n\n### Use Subscription Hook\n\n```tsx\nimport { useSubscription } from \"@drewsepsi/billing-sdk/react\";\n\nfunction Dashboard() {\n  const { subscription, isLoading, isActive } = useSubscription(\"user_123\");\n\n  if (isLoading) return <Spinner />;\n\n  return (\n    <div>\n      <h1>Dashboard</h1>\n      {isActive ? (\n        <PremiumFeatures />\n      ) : (\n        <UpgradePrompt />\n      )}\n    </div>\n  );\n}\n```\n\n## Server-Side Usage\n\nFor API routes and server components:\n\n```typescript\nimport { BillingSDK } from \"@drewsepsi/billing-sdk/server\";\n\n// Server-side SDK (no React dependencies)\nconst billing = new BillingSDK({\n  baseUrl: process.env.API_URL,\n  apiKey: process.env.BILLING_API_KEY,\n});\n\n// Validate a license key\nconst license = await billing.validateLicense(\"license_key_here\");\n\nif (license.valid && license.tier === \"pro\") {\n  // Grant pro features\n}\n```\n\n## Sandbox Mode\n\nTest your billing integration without real charges:\n\n```typescript\nimport { createSandboxBilling } from \"@drewsepsi/billing-sdk/sandbox\";\n\nconst billing = createSandboxBilling({\n  baseUrl: \"http://localhost:3000\",\n});\n\n// All operations work without hitting Stripe\nconst checkout = await billing.createCheckout({\n  priceId: \"test_price\",\n  userId: \"test_user\",\n});\n```\n\n## License Validation (SDK Customers)\n\nIf you've purchased a Drew Billing SDK license, validate it to unlock features:\n\n```typescript\nconst billing = new BillingSDK({\n  baseUrl: \"https://your-app.com\",\n  license: {\n    licenseKey: process.env.DREW_BILLING_LICENSE_KEY,\n  },\n});\n\n// The SDK automatically validates on initialization\n// and enables features based on your tier (Pro/Team/Enterprise)\n```\n\n## API Reference\n\n### `BillingSDK`\n\nMain SDK class for billing operations.\n\n| Method | Description |\n|--------|-------------|\n| `createCheckout(options)` | Create a Stripe checkout session |\n| `getSubscription(userId)` | Get user's subscription status |\n| `getUsage(userId)` | Get usage statistics |\n| `trackUsage(event)` | Track a usage event |\n| `validateLicense(key)` | Validate a license key |\n| `createCustomerPortal(userId)` | Create customer portal session |\n\n### React Hooks\n\n| Hook | Description |\n|------|-------------|\n| `useSubscription(userId)` | Get subscription state |\n| `useBilling()` | Access SDK instance |\n| `useUsage(userId)` | Track and display usage |\n\n## Environment Variables\n\n```bash\n# Required\nNEXT_PUBLIC_API_URL=https://your-app.com\n\n# Optional (for SDK license validation)\nDREW_BILLING_LICENSE_KEY=your-license-key-here\n\n# Optional (for server-side)\nBILLING_API_KEY=your-api-key\n```\n\n## Examples\n\n### SaaS Starter\n\n```bash\nnpx @drewsepsi/billing-cli init --template saas\n```\n\n### API Product with Usage\n\n```bash\nnpx @drewsepsi/billing-cli init --template api\n```\n\n### AI Credits System\n\n```bash\nnpx @drewsepsi/billing-cli init --template ai-credits\n```\n\n## Documentation\n\n- [Full Documentation](https://monetize-two.vercel.app/docs)\n- [API Reference](https://monetize-two.vercel.app/docs/api)\n- [CLI Guide](https://monetize-two.vercel.app/docs/cli)\n- [GitHub Repo](https://github.com/drew/billing)\n\n## License\n\nMIT © [Drew](https://github.com/drew)\n\n---\n\nBuilt with ❤️ by Drew Billing\n","readmeFilename":"README.md"}