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

@engjts/mysql-adapter

v1.0.0

Published

MySQL session store adapter for @engjts/auth (JTS - Janus Token System)

Readme

@engjts/mysql-adapter

A MySQL session store adapter for @engjts/auth (JTS - Janus Token System).

Installation

npm install @engjts/mysql-adapter mysql2

Usage

import mysql from 'mysql2/promise';
import { JTSAuthServer } from '@engjts/auth';
import { MySQLSessionStore } from '@engjts/mysql-adapter';

// Create a MySQL pool
const pool = mysql.createPool({
  host: 'localhost',
  port: 3306,
  user: 'root',
  password: 'password',
  database: 'myapp',
});

// Create a session store
const sessionStore = new MySQLSessionStore({ pool });

// Initialize the table (run once)
await sessionStore.initialize();

// Use with JTSAuthServer
const authServer = new JTSAuthServer({
  profile: 'JTS-S/v1',
  signingKey: mySigningKey,
  sessionStore,
});

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | pool | MySQLPool | required | A mysql2/promise pool instance | | tableName | string | 'jts_sessions' | The table name for sessions | | database | string | undefined | The database name (optional) | | rotationGraceWindow | number | 10 | The grace window in seconds | | defaultSessionLifetime | number | 604800 | The session lifetime (7 days) |

API

MySQLSessionStore

initialize(): Promise<void>

Creates the sessions table if it doesn't exist.

createSession(input: CreateSessionInput): Promise<JTSSession>

Creates a new session.

getSessionByAid(aid: string): Promise<JTSSession | null>

Retrieves a session by its AID (Authentication ID).

getSessionByStateProof(stateProof: string): Promise<SessionValidationResult>

Validates a state proof and returns the associated session.

rotateStateProof(aid: string, newStateProof?: string): Promise<JTSSession>

Rotates the state proof for a session.

touchSession(aid: string): Promise<void>

Updates the last active timestamp for a session.

deleteSession(aid: string): Promise<boolean>

Deletes a session by its AID.

deleteAllSessionsForPrincipal(prn: string): Promise<number>

Deletes all sessions for a principal (user).

getSessionsForPrincipal(prn: string): Promise<JTSSession[]>

Gets all active sessions for a principal.

countSessionsForPrincipal(prn: string): Promise<number>

Counts active sessions for a principal.

deleteOldestSessionForPrincipal(prn: string): Promise<boolean>

Deletes the oldest session for a principal (useful for session limits).

cleanupExpiredSessions(): Promise<number>

Removes expired sessions from the database.

healthCheck(): Promise<boolean>

Checks if the database connection is healthy.

close(): Promise<void>

Closes the database connection pool.

Database Schema

The adapter automatically creates the following table structure:

CREATE TABLE jts_sessions (
  aid VARCHAR(64) PRIMARY KEY,
  prn VARCHAR(256) NOT NULL,
  current_state_proof VARCHAR(256) NOT NULL,
  previous_state_proof VARCHAR(256),
  state_proof_version INT DEFAULT 1,
  rotation_timestamp DATETIME(3),
  device_fingerprint VARCHAR(128),
  created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
  expires_at DATETIME(3) NOT NULL,
  last_active DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
  user_agent TEXT,
  ip_address VARCHAR(45),
  metadata JSON,
  
  INDEX idx_prn (prn),
  INDEX idx_current_sp (current_state_proof),
  INDEX idx_previous_sp (previous_state_proof),
  INDEX idx_expires (expires_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

Requirements

  • Node.js >= 18.0.0
  • MySQL >= 5.7 or MariaDB >= 10.2
  • @engjts/auth >= 1.0.0
  • mysql2 >= 3.0.0

Testing

# Set up environment variables
export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=root
export MYSQL_PASSWORD=password
export MYSQL_DATABASE=jts_test

# Run tests
npm test

License

MIT