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

trustline

v0.1.1

Published

Service identity and authorization for modern JavaScript runtimes

Downloads

346

Readme

Trustline

npm version docs

Service identity and authorization for modern JavaScript runtimes.

Trustline is a machine-to-machine authentication library for internal services. It is designed around dedicated core and integration entry points:

  • trustline: provider, guard, memory storage, and shared core exports
  • trustline/client: token fetching and caching for outgoing requests
  • trustline/frameworks/*: framework adapters for receiving services
  • trustline/adapters/*: SQL storage adapters

The package now ships the first full stack: provider, client, guard, framework adapters, memory storage, and SQL storage adapters for SQLite, Postgres, and MySQL.

Installation

Trustline is intended to be consumed as the trustline package:

bun add trustline

Or with npm:

npm install trustline

Install only the integrations you use. For example, Express users install express; SQLite users install better-sqlite3 and kysely.

Example installs:

npm install trustline express
npm install trustline better-sqlite3 kysely

If you are working from this repository before package publication, build the package locally and install or link it from the repo source.

Quick start

Provider:

import { createProvider, memoryStorage } from "trustline";

const provider = createProvider({
  issuer: "https://auth.internal",
  storage: memoryStorage(),
  env: "production",
});

const service = await provider.clients.create({
  name: "order-processor",
  scopes: ["read:orders", "write:inventory"],
});

Client:

import { createClient } from "trustline/client";

const client = createClient({
  tokenUrl: "https://auth.internal/token",
  clientId: service.clientId,
  clientSecret: service.clientSecret,
  audience: "inventory-service",
});

const token = await client.getToken();

Guard:

import { createGuard } from "trustline";

const guard = createGuard({
  issuer: "https://auth.internal",
  audience: "inventory-service",
  scopes: ["read:orders"],
  env: "production",
});

const identity = await guard.verify(token);

Trustline derives the JWKS endpoint automatically for verification:

issuer: https://auth.internal
jwks:   https://auth.internal/.well-known/jwks.json

Bun

Trustline does not need a Bun-specific adapter. Bun already uses the standard Web Request and Response APIs, so use the provider's handle() method directly and call guard.verify() inside your fetch handler.

import { createGuard, createProvider, memoryStorage } from "trustline";

const provider = createProvider({
  issuer: "https://auth.internal",
  storage: memoryStorage(),
});

Bun.serve({
  port: 3000,
  fetch: provider.handle,
});

const guard = createGuard({
  issuer: "https://auth.internal",
  audience: "inventory-service",
});

Bun.serve({
  port: 4000,
  fetch: async (request) => {
    const header = request.headers.get("authorization");
    const token = header?.replace(/^Bearer\s+/, "") ?? "";
    const identity = await guard.verify(token);

    return Response.json({
      caller: identity.name ?? identity.clientId,
    });
  },
});

Express

import express from "express";
import { createGuard, createProvider, memoryStorage } from "trustline";
import {
  createExpressGuard,
  createExpressProvider,
  type TrustlineRequest,
} from "trustline/frameworks/express";

const app = express();

const provider = createProvider({
  issuer: "https://auth.internal",
  storage: memoryStorage(),
});

const guard = createGuard({
  issuer: "https://auth.internal",
  audience: "inventory-service",
});

app.use(createExpressProvider(provider));
app.use(createExpressGuard(guard));

app.get("/internal", (request: TrustlineRequest, response) => {
  response.json({
    caller: request.trustline?.name ?? request.trustline?.clientId,
  });
});

API

Current public API includes:

interface ProviderOptions {
  issuer: string;
  storage: StorageAdapter;
  signing?: {
    algorithm?: "ES256" | "RS256";
    privateKey?: string;
    keyId?: string;
  };
  token?: {
    ttl?: number;
  };
  env?: string;
}

interface GuardOptions {
  issuer: string;
  jwksUrl?: string;
  audience?: string | string[];
  scopes?: string[];
  env?: string;
  clockTolerance?: number;
}

interface ServiceIdentity {
  clientId: string;
  name: string | null;
  scopes: string[];
  env: string | null;
  raw: Record<string, unknown>;
}

Adapter surface:

  • provider.handle(request)
  • guard.verify(token)
  • createExpressProvider(provider)
  • createExpressGuard(guard)
  • createFastifyProvider(provider)
  • createFastifyGuard(guard)
  • createHonoProvider(provider)
  • createHonoGuard(guard)

Supported signing algorithms:

  • RS256
  • ES256

Bundled storage adapters via dedicated subpaths:

  • memoryStorage()
  • sqliteStorage(path | database)
  • postgresStorage(pool)
  • mysqlStorage(pool)

SQL adapters follow the Better Auth-style pattern of receiving ready-made database handles:

import Database from "better-sqlite3";
import { createPool as createMysqlPool } from "mysql2";
import { Pool as PostgresPool } from "pg";
import { mysqlStorage } from "trustline/adapters/mysql";
import { postgresStorage } from "trustline/adapters/postgres";
import { sqliteStorage } from "trustline/adapters/sqlite";

const sqlite = sqliteStorage(new Database("./trustline.sqlite"));
const postgres = postgresStorage(
  new PostgresPool({ connectionString: process.env.DATABASE_URL }),
);
const mysql = mysqlStorage(createMysqlPool(process.env.DATABASE_URL!));

Documentation

The VitePress docs site lives in docs/.

Runnable examples live under examples/. For a full Hono-based flow with a dedicated auth provider plus caller and receiver services, see examples/hono-services/.

Key pages:

  • docs/index.md
  • docs/get-started.md
  • docs/concepts.md
  • docs/middleware.md
  • docs/reference.md
  • docs/roadmap.md

To run the docs locally:

cd docs
bun run docs:dev

To build the docs:

cd docs
bun run docs:build

Development

Build the package:

bun run build

Run type checks:

bun run typecheck

Run tests:

bun run test

Run formatting and lint checks:

bun run check

License

MIT