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

@nightnetwork/plus-client

v1.0.0

Published

Night+ authentication client with Enigma WebSocket protocol interceptor

Readme

Night+ Auth Client

WebSocket authentication for Night+ using Enigma protocol injection.

How It Works

Since browsers block custom WebSocket headers, authentication data is passed via the protocols parameter:

  1. Session token is stored in IndexedDB (NightPlus database)
  2. Enigma module reads token and encodes as base64 JSON
  3. Token is injected into WebSocket protocols array
  4. Reverse proxy decodes protocol and validates token

Installation

npm install @nightnetwork/plus-client localforage

Usage

As Enigma Module (Recommended)

Load the module via Enigma for automatic authentication injection:

import { BareMuxConnection } from '@mercuryworkshop/bare-mux';
import { authenticate } from '@nightnetwork/plus-client';

const accessToken = '...';
await authenticate(accessToken, '/auth');

const connection = new BareMuxConnection('/baremux/worker.js');
await connection.setTransport('/enigma/index.mjs', {
  base: '/epoxy/index.mjs',
  wisp: 'wss://wisp.example.com/',
  modules: [
    '/plusClient/module.mjs'
  ]
});

As JavaScript Import

Import functions directly for manual token management:

import { setSessionToken, getSessionToken, clearSessionToken, createPlusAuthModule } from '@nightnetwork/plus-client';

const accessToken = '...';
await authenticate(accessToken, '/auth');

const connection = new BareMuxConnection('/baremux/worker.js');
await connection.setTransport('/enigma/index.mjs', {
  base: '/epoxy/index.mjs',
  wisp: 'wss://wisp.example.com/',
  modules: [
    createPlusAuthModule()
  ]
});

// Set token
await setSessionToken('your-session-token');

// Get token
const token = await getSessionToken();

// Clear token
await clearSessionToken();

Validate Session

import { validateSession } from '@nightnetwork/plus-client';

const isValid = await validateSession('/validate');
if (!isValid) {
  // Re-authenticate
  await authenticate(accessToken);
}

API

authenticate(accessToken, authUrl?)

Exchanges access token for session token. Stores in IndexedDB.

  • accessToken: JWT access token from login
  • authUrl: Auth endpoint (default: /auth)
  • Returns: Promise<string> - Session token

setSessionToken(token)

Stores session token in IndexedDB (NightPlus database).

  • token: Session token string
  • Returns: Promise<void>

getSessionToken()

Retrieves session token from IndexedDB.

  • Returns: Promise<string | null>

clearSessionToken()

Removes session token from IndexedDB.

  • Returns: Promise<void>

validateSession(validateUrl?)

Checks if current session token is valid.

  • validateUrl: Validation endpoint (default: /validate)
  • Returns: Promise<boolean>

createPlusAuthModule()

Creates Enigma module for WebSocket protocol injection.

  • Returns: EnigmaModule

Protocol Format

Authentication data is encoded as:

const authData = { "Night-Auth": "session-token" };
const protocol = btoa(JSON.stringify(authData));

The reverse proxy decodes this:

const decoded = JSON.parse(atob(protocol));
const token = decoded['Night-Auth'];

Storage

Uses localforage with IndexedDB:

  • Database: NightPlus
  • Store: session
  • Key: token

Works in web workers - NO localStorage dependency.

Example: Full Flow

import BareMux from '@mercuryworkshop/bare-mux';
import { authenticate, createPlusAuthModule, validateSession } from '@nightnetwork/plus-client';

// 1. Login to get access token
const loginRes = await fetch('https://auth.night-x.com/login', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ email: '[email protected]', password: 'pass' })
});
const { access_token } = await loginRes.json();

// 2. Exchange for session token
await authenticate(access_token, 'http://localhost:8081/auth');

// 3. Setup transport with auth module
const connection = new BareMux.BareClient();
await connection.setTransport('/enigma/index.mjs', {
  base: '/epoxy/index.mjs',
  modules: [createPlusAuthModule()]
});

// 4. WebSockets are now authenticated
const ws = new WebSocket('wss://api.example.com/ws');

// 5. Handle session expiry
ws.addEventListener('close', async (event) => {
  if (event.code === 1008) { // Unauthorized
    await authenticate(access_token);
    // Retry connection
  }
});

Session Expiry

Sessions expire 15 minutes after inactivity. When expired:

  • Server closes WebSocket with code 1008
  • Client must re-authenticate
  • New session token is issued and stored