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

@jnode/server-account

v1.0.2

Published

Official account system for JNS.

Readme

@jnode/server-account

Official account system for JNS (Node.js). It provides a full-stack solution for user registration, authentication via signed tokens, and account management.

Installation

npm i @jnode/server-account

Quick start

Import

const { AccountManager, routerConstructors: acr, handlerConstructors: ach } = require('@jnode/server-account');
const { createServer, routerConstructors: r, handlerConstructors: h } = require('@jnode/server');

Start a basic account server

const manager = new AccountManager();

const server = createServer(
  // Use JSONErrorMessage to catch errors and return structured JSON
  acr.JSONErrorMessage(
    r.Path(404, {
      '/api/register': ach.Register(manager),
      '/api/login': ach.Login(manager),
      // Protect sensitive routes using AccountTokenVerify
      '/api/user': acr.AccountTokenVerify(
        manager,
        r.Path(null, {
          '@GET /profile': async (ctx, env) => {
            const data = await ctx.identity.account.data();
            return h.JSON({ 
              status: 200, 
              account: data.account, 
              displayName: data.displayName 
            }).handle(ctx, env);
          },
          '@POST /reset-password': ach.ResetPassword(manager),
          '@POST /delete': ach.DeleteAccount(manager)
        }),
        401 // Fail handler if not logged in
      )
    })
  )
);

server.listen(8080);

How it works?

@jnode/server-account defines a standardized account protocol:

  1. Manager: Logic core. Handles password hashing (using scrypt) and data persistence.
  2. Account: A wrapper class for specific user data access.
  3. Router: Middlewares to verify identity. AccountTokenVerify injects the Account instance into ctx.identity.account.
  4. Handler: Web controllers that consume JSON requests and interact with the Manager.

Reference

Class: account.AccountManager

The core manager for handling account lifecycle.

new account.AccountManager([data, options])

manager.register(account, email, password, displayName)

Registers a user. Performs strict format validation (see Validation Rules).

manager.login(account, password)

Verifies credentials. account can be the username or email.

manager.resetAccountPassword(id, password)

Updates password and sets securityReset to now, invalidating all old tokens.

Class: account.Account

account.data()

  • Returns: <Promise> | <Object>
    • id, account, email, displayName, createdAt, permissions, securityReset.

Web API Format (Built-in Handlers)

The following handlers expect JSON input and return JSON output.

Validation Rules

For Register and ResetPassword handlers:

  • account: 4-32 characters, alphanumeric (\w).
  • email: Standard email regex.
  • password: 8-64 characters, must include:
    • Uppercase & Lowercase letters.
    • Numbers.
    • Symbols (!@#$%^&* etc.).
  • displayName: 2-32 characters, sanitized (no control codes).

Handler: Register(manager[, options])

  • Request Method: POST (usually)

  • Request Body:

    {
      "account": "username",
      "email": "[email protected]",
      "password": "SecurePassword123!",
      "displayName": "My Name"
    }
  • Success Response: 200 OK

    {
      "status": 200,
      "id": "username",
      "account": "username",
      "displayName": "My Name",
      "createdAt": "2023-10-27T..."
    }
  • Cookie: Sets jnsat (HttpOnly).

Handler: Login(manager[, options])

  • Request Body:

    {
      "account": "username_or_email",
      "password": "SecurePassword123!"
    }
  • Success Response: Same as Register.

  • Cookie: Sets jnsat (HttpOnly).

Handler: ResetPassword(manager[, options])

Requires authentication via AccountTokenVerify.

  • Request Body:

    {
      "id": "current_user_id",
      "oldPassword": "CurrentPassword123!",
      "newPassword": "NewSecurePassword456!"
    }
  • Success Response: {"status": 200}.

  • Cookie: Refreshes jnsat with a new cre (creation) timestamp.

Handler: DeleteAccount(manager)

Requires authentication via AccountTokenVerify.

  • Request Body:

    {
      "id": "current_user_id",
      "password": "CurrentPassword123!"
    }
  • Success Response: {"status": 200}.


Built-in routers

Router: AccountTokenVerify(manager, pass, fail)

Verifies the jnsat cookie.

  • If Pass: Sets ctx.identity.account and ctx.identity.token.
  • If Fail: Calls fail handler (e.g., 401).
  • Security: Automatically rejects tokens issued before the account's last securityReset.

Router: JSONErrorMessage(next)

Catches errors thrown during routing/handling.

  • Format:

    {
      "status": 401,
      "code": "ACC_NOT_FOUND",
      "message": "Account not found."
    }

Router: TokenVerify(service, pass, fail[, by])

Generic token verifier. by can be a function to extract tokens from headers or other sources.