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

@lessly/users

v0.1.0

Published

Server SDK for the Lessly Users toolkit — local JWT verification, code exchange, refresh and middleware

Downloads

96

Readme

@lessly/users

The server SDK for the Lessly Users toolkit. It runs on a Product's backend, holds the product server key (usk_…), and exists so that adopting Lessly Users never requires hand-rolling JWT handling.

import { createUsersClient } from '@lessly/users';

const users = createUsersClient({
  productId: process.env.LESSLY_PRODUCT_ID!,
  serverKey: process.env.LESSLY_USERS_SERVER_KEY!, // usk_…  — never ships to a browser
});

Environments

The default base URL is production: https://public.lessly.com, from which the SDK derives https://public.lessly.com/{productId}/users for both the API and the issuer it pins.

Keys and environments do not mix. A key minted against the production console works only against public.lessly.com; a key from the dev console only against the dev edge. A mismatch is indistinguishable from an unknown key on the wire, so every 401 the SDK raises carries a factual hint naming the URL it actually called.

const users = createUsersClient({
  productId,
  serverKey,
  baseUrl: 'https://public.lessly.dev', // a different edge
  // or, for a local stack that is not behind an edge at all:
  apiUrl: 'http://localhost:3100',
  issuer: `http://localhost:3100/${productId}/users`,
  headers: { 'x-gateway-product-id': productId, 'x-gateway-public-endpoint': 'true' },
});

verifyToken(jwt, { checkRevoked })

Local verification against the product's published JWKS — no call to us on your hot path. It implements the toolkit's verification contract exactly:

  • iss must equal the configured issuer; it is never derived from the token.
  • jku, x5u and an embedded jwk header are ignored.
  • kid is resolved only within the configured product's key set.
  • ES256 only; aud required and equal to productId; ±60s clock skew.
  • JWKS cached for ≤10 minutes, refreshed on an unknown kid (with a cooldown, so forged kids cannot turn into a request flood).
const claims = await users.verifyToken(accessToken);
claims.sub; // end user id
claims.sid; // session id
claims.isImpersonated; // true while an operator is impersonating this user

{ checkRevoked: true } additionally asks /sessions/introspect, which answers off Postgres — the only way to see a revocation before the ≤10 minute access TTL runs out. It throws SessionRevokedError.

Errors are one family: UsersError with code, plus TokenExpiredError, TokenInvalidError, SessionRevokedError, AuthenticationError, RateLimitedError (retryAfter in seconds), CodeExchangeError, RefreshError, UsersApiError.

exchangeCode(code, codeVerifier, { redirectUri })

The backend half of the hardened code handoff: your callback receives a one-time code by form POST, and this exchanges it — with the PKCE verifier, the exact callback and your server key — for { accessToken, refreshToken, expiresIn, session }.

refresh(refreshToken)

Rotation. Concurrent calls with the same token are coalesced into a single request, so an SSR page that wakes ten handlers at once performs one rotation. 429s surface as RateLimitedError with retryAfter.

Middleware

import { expressMiddleware, requireAuth } from '@lessly/users';

app.use('/api', expressMiddleware(users)); // sets req.auth
app.use('/admin', expressMiddleware(users, { checkRevoked: true }));

// or framework-agnostic:
const guard = requireAuth(users, (ctx) => ctx.cookies.session);
const claims = await guard(ctx);

express is not a dependency — the adapter is typed structurally, so it works with anything Express-shaped.