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

@authn-sh/sdk-node

v0.7.1

Published

Node.js / Edge runtime backend SDK for authn.sh — BAPI resource managers, JWT verification, webhook signature verification. Mirrors @authn-sh/sdk-php.

Readme

@authn-sh/sdk-node

Node.js / Edge-runtime backend SDK for authn.sh.

Mirrors @authn-sh/sdk-php — BAPI resource managers, session-JWT verification, webhook signature verification. The frontend counterpart is @authn-sh/sdk-js.

Runs anywhere fetch exists: Node 18+, Cloudflare Workers, Vercel Edge, Bun, Deno.

Install

npm install @authn-sh/sdk-node

BAPI client

import { Authn } from '@authn-sh/sdk-node';

const authn = new Authn({ secretKey: process.env.AUTHN_SECRET_KEY! });

// Users
const user = await authn.users.get('user_01HXYZ');
await authn.users.ban('user_01HXYZ');
const fresh = await authn.users.create({ first_name: 'Alice', email_addresses: ['[email protected]'] });

// Sessions
const session = await authn.sessions.get('sess_01HXYZ');
const jwt = await authn.sessions.getToken('sess_01HXYZ', 'my-jwt-template');

// Organizations + nested managers
const org = await authn.organizations.create({ name: 'Acme', slug: 'acme' });
await authn.organizations.members(org.id).create({ userId: user.id, role: 'org:admin' });
await authn.organizations.invitations(org.id).create({ email_address: '[email protected]', role: 'org:member' });
await authn.organizations.domains(org.id).create('acme.com', 'automatic_invitation');

// Social providers + phone numbers + external accounts + SMS templates
await authn.oauthProviders.list();
await authn.phoneNumbers.list({ userId: user.id } as any);
await authn.externalAccounts.list({ userId: user.id } as any);
await authn.smsTemplates.get('verification_code');

// Instance settings
const instance = await authn.instance.get();
await authn.instance.update({ multi_factor: { phone_code: { enabled: true } } });

Errors from the API surface as AuthnHttpError (status, code, requestId, errors[]).

Session-JWT verification

import { TokenVerifier } from '@authn-sh/sdk-node';

const verifier = new TokenVerifier({ publishableKey: process.env.AUTHN_PUBLISHABLE_KEY! });

// In your auth middleware:
const cookie = req.cookies['__session'];
const claims = await verifier.verify(cookie);  // throws AuthnTokenInvalidError on bad token

console.log(claims.sub);                        // user_…
console.log(claims.organization?.role);         // 'org:admin'
console.log(claims.hasPermission('org:billing:read'));
console.log(claims.hasVerifiedPhoneNumber());
console.log(claims.preferredSecondFactor());    // 'totp' | 'phone_code' | 'backup_code' | null

For "best-effort" auth that falls back to unauthenticated, use tryVerify() — returns null instead of throwing.

The verifier resolves the FAPI host from the publishableKey; pass frontendApiUrl explicitly when self-hosting on a custom domain. JWKS is fetched once and cached in memory (default 10 min TTL).

Webhook signature verification

import express from 'express';
import { WebhookSignatureVerifier } from '@authn-sh/sdk-node';

const app = express();
const verifier = new WebhookSignatureVerifier({
  signingSecret: process.env.AUTHN_WEBHOOK_SECRET!,
});

app.post('/webhooks/authn', express.raw({ type: 'application/json' }), (req, res) => {
  try {
    const event = verifier.verify(req.body.toString('utf8'), req.headers);
    switch (event.type) {
      case 'user.created':       /* … */; break;
      case 'phoneNumber.verified': /* … */; break;
    }
    res.status(204).end();
  } catch {
    res.status(400).end();
  }
});

To rotate the signing secret without downtime, pass an array — the verifier accepts a request if any provided signature matches any secret:

new WebhookSignatureVerifier({ signingSecret: [oldSecret, newSecret] });

Runtime support

| Runtime | Status | | ----------------- | -------------------------------------------- | | Node.js 18+ | ✓ first-class | | Cloudflare Workers | ✓ (uses globalThis.fetch + node:crypto) | | Vercel Edge | ✓ | | Bun | ✓ | | Deno | ✓ via npm: specifier |

The webhook verifier imports node:crypto. On edge runtimes that polyfill it (Workers, Vercel Edge), no action is needed.

License

AGPL-3.0-only — see LICENSE. For commercially licensed deployments, contact authn.sh.