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

@churnkey/node

v0.2.0

Published

Server-side SDK for Churnkey. Generate session tokens for use with @churnkey/react.

Readme

@churnkey/node

Server-side helper for Churnkey auth. Generate session tokens for @churnkey/react, or HMAC hashes for the hosted embed — same credentials, different wire shapes.

You only need this package when you want Churnkey to handle billing operations or when you're using the hosted embed. For analytics-only integration with @churnkey/react, a token isn't required.

Installation

npm install @churnkey/node

Generate a token

import { Churnkey } from '@churnkey/node'

const ck = new Churnkey({
  appId: process.env.CHURNKEY_APP_ID,
  apiKey: process.env.CHURNKEY_API_KEY,
})

const token = ck.createToken({ customerId: 'cus_123' })

Pass it to the frontend:

<CancelFlow
  appId="app_xxx"
  customer={{ id: 'cus_123', email: '[email protected]' }}
  session={token}
  onAccept={async (offer) => console.log('Applied:', offer)}
  onCancel={async () => router.push('/goodbye')}
/>

Token creation is a local HMAC computation. No network call, no latency.

Multi-subscription customers

Target a specific subscription:

const token = ck.createToken({
  customerId: 'cus_123',
  subscriptionId: 'sub_456',
})

Test and sandbox mode

Pass mode: 'test' to segregate staging or QA sessions from live analytics. Defaults to 'live'.

const token = ck.createToken({
  customerId: user.stripeId,
  mode: process.env.NODE_ENV === 'production' ? 'live' : 'test',
})

If your org is connected to a Stripe Sandbox rather than classic test mode, pass mode: 'sandbox' instead. Sandboxes live under a separate Stripe account ID with their own credentials, and Churnkey routes billing actions accordingly.

Using the hosted embed instead

If you're using the hosted widget (script tag churnkey.init({...})) alongside or instead of the React SDK, it expects a raw HMAC hash rather than a session token. Same credentials, different wrapper:

const authHash = ck.authHash(user.stripeId)

// Pass to the embed on the client
// churnkey.init({ appId, customerId: user.stripeId, authHash })

You can use one Churnkey instance for both — no need to duplicate HMAC plumbing.

Reference

new Churnkey({ appId, apiKey })

| Parameter | Description | |-----------|-------------| | appId | Your Churnkey app ID | | apiKey | Your Churnkey API key. Keep this on the server. |

ck.createToken({ customerId, subscriptionId?, mode? })

| Parameter | Description | |-----------|-------------| | customerId | The customer ID from your billing provider (e.g. Stripe cus_...) | | subscriptionId | Optional. Targets a specific subscription for customers with multiple. | | mode | Optional, 'live' or 'test'. Defaults to 'live'. Sessions record this on the server for analytics segregation. |

Returns a ck_-prefixed token string.

ck.authHash(customerId)

| Parameter | Description | |-----------|-------------| | customerId | The customer ID you'll pass to the hosted embed. |

Returns the hex HMAC-SHA256 string expected by churnkey.init({ authHash, ... }). Use this when you're integrating the hosted embed widget directly instead of (or alongside) the React SDK.

License

MIT