Requirements
- Node.js 18+ (or any edge runtime with Web Crypto API)
- TypeScript 5.0+ (optional but recommended)
Install
npm install @vgpprasad91/churnkit-sdk
Set your API key
Add your key to your environment:
CHURNKIT_API_KEY=ck_live_your_key_here
Use ck_test_ keys in development and CI. Test keys are completely isolated from production data.
Basic setup
import ChurnKit from '@vgpprasad91/churnkit-sdk'
const churn = new ChurnKit({
apiKey: process.env.CHURNKIT_API_KEY!,
})
Next.js setup
Create a shared client file so you don’t instantiate on every request:
import ChurnKit from '@vgpprasad91/churnkit-sdk'
// Module-level singleton — instantiated once per server process
export const churn = new ChurnKit({
apiKey: process.env.CHURNKIT_API_KEY!,
})
Then import churn in your Server Actions, Route Handlers, or API routes:
app/api/checkout/route.ts
import { churn } from '@/lib/churnkit'
export async function POST(req: Request) {
const { userId } = await req.json()
await churn.event(userId, 'checkout_started')
// ...
}
Cloudflare Workers / Edge
The SDK uses only Web-standard APIs (fetch, crypto.subtle) and works on Cloudflare Workers, Vercel Edge Functions, and Deno Deploy with no modifications:
import ChurnKit from '@vgpprasad91/churnkit-sdk'
export default {
async fetch(request: Request, env: Env) {
const churn = new ChurnKit({ apiKey: env.CHURNKIT_API_KEY })
await churn.event('user_123', 'page_viewed')
return new Response('ok')
},
}
The package ships both ESM and CJS:
| Format | Entry point |
|---|
| ESM | dist/index.mjs |
| CJS | dist/index.cjs |
| Types | dist/index.d.ts |
import and require both work out of the box.