@dotlabshq/driptab-sdk
v0.1.0
Published
TypeScript SDK for the Driptab billing API
Readme
@dotlabshq/driptab-sdk
TypeScript SDK for the Driptab billing API.
Works in Node.js, Cloudflare Workers, Deno, and modern browsers. Zero runtime dependencies.
Installation
npm install @dotlabshq/driptab-sdkQuick start
import { DriptabClient } from '@dotlabshq/driptab-sdk';
const client = new DriptabClient({
token: process.env.DRIPTAB_TOKEN!,
projectId: process.env.DRIPTAB_PROJECT_ID!,
});
// Onboard a user on the free plan
const { customer, subscription } = await client.customers.getOrCreate(
{ external_id: user.id, name: user.name, email: user.email },
{ plan: 'starter' },
);
// Check limits locally — no extra API call
const limits = client.limits({
starter: { mail_out: 100, storage_gb: 1, domains: 1 },
pro: { mail_out: 5000, storage_gb: 10, domains: 10 },
agent: { mail_out: null, storage_gb: null, domains: null },
});
const result = limits.check(subscription!.plan_code, 'mail_out', user.mailCount);
if (!result.allowed) throw new Error('Limit reached. Please upgrade.');
// After payment — upgrade plan
const proPlan = await client.plans.getByCode('pro');
await client.subscriptions.changePlan(subscription!.id, proPlan!.id);Documentation
License
MIT
