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

@puzzle-ui/session

v0.12.0

Published

Secure, database-independent session management for Puzzle Auth.

Readme

@puzzle-ui/session

Secure, database-independent session management for Puzzle Auth.

Documentation: https://puzzle-ui.com/docs/auth

@puzzle-ui/session issues, validates, rotates, and revokes server-side sessions on top of any @puzzle-ui/storage adapter. @puzzle-ui/auth and @puzzle-ui/fullstack use it for their session handling; use it directly when you need sessions without the full authentication stack, such as anonymous carts or custom sign-in flows.

Features

  • Cryptographically secure opaque session tokens.
  • SHA-256 token hashing.
  • Anonymous and authenticated sessions.
  • Idle and absolute expiration.
  • Session rotation and revocation.
  • Session listing and device metadata.
  • Maximum active session policy.
  • Namespaced session data with TTL.
  • Allowlisted anonymous session migration.
  • Secure cookie serialization.
  • Origin validation and CSRF protection.

Requirements

The storage adapter must support:

  • Unique constraints.
  • Conditional writes.
  • Atomic batches.

Session management fails closed when these capabilities are unavailable.

Installation

npm install @puzzle-ui/session
# or
bun add @puzzle-ui/session
# or
pnpm add @puzzle-ui/session
# or
yarn add @puzzle-ui/session

Initialization

import {
  StorageSessionManager,
  initializeSessionStorage,
} from "@puzzle-ui/session";

const sessions = new StorageSessionManager(storage, {
  lifetime: {
    idleTimeoutSeconds: 60 * 60 * 24 * 7,
    absoluteLifetimeSeconds: 60 * 60 * 24 * 30,
  },
  maximumSessionsPerUser: 10,
});

await initializeSessionStorage(storage);
await sessions.initialize();

Create an anonymous session

const result = await sessions.create({
  kind: "anonymous",
  userId: null,
});

console.log(result.session.id);
console.log(result.token);

The token must only be delivered through a secure HttpOnly cookie.

Create an authenticated session

const result = await sessions.create({
  kind: "authenticated",
  userId: user.id,
  metadata: {
    userAgent: request.headers.get("user-agent"),
  },
});

Validate a session

const session = await sessions.validate(token);

if (!session) {
  // Unauthenticated request.
}

Rotate a session

const rotated = await sessions.rotate({
  sessionId: session.id,
});

The old session is revoked as part of the atomic rotation.

Revoke sessions

await sessions.revoke(session.id);
await sessions.revokeAll(user.id);

List devices

const devices = await sessions.list(user.id, session.id);

Session data

const data = new SessionDataManager(storage, {
  allowedNamespaces: ["cart", "checkout"],
});

await data.initialize();

await data.set(
  session.id,
  "cart",
  "items",
  [{ productId: "product-1", quantity: 2 }],
  60 * 60,
);

const cart = await data.get(session.id, "cart", "items");

Security

  • Raw tokens are never persisted.
  • Session validation always checks durable storage.
  • Session expiration is enforced server-side.
  • Anonymous sessions cannot be converted by changing their user ID.
  • Migration creates a new identity-bound session.
  • Session data namespaces must be explicitly allowlisted.
  • Cookie configuration does not expose session tokens to JavaScript.
  • Security-critical operations require atomic storage support. In-memory storage is intended exclusively for development and tests.