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

@dytsou/pattern

v1.0.7

Published

Edge PAT auth for Cloudflare Workers — path×method ACL, hierarchical issuance, exact revoke

Readme

pattern

Personal Access Token Through Edge-based Rules and Nested Delegation: A Personal Access Token (PAT) auth for Cloudflare Workers: path × method allowlists, hierarchical issuance, and exact jti revocation.

Install

pnpm add @dytsou/pattern
pnpm add hono

Imports:

import { createPattern, D1TokenStore, MemoryTokenStore } from "@dytsou/pattern";
import { patternMiddleware, createIntrospectHandler } from "@dytsou/pattern/hono";

Quick start (Hono on Workers)

import { Hono } from "hono";
import { createPattern, D1TokenStore } from "@dytsou/pattern";
import { patternMiddleware } from "@dytsou/pattern/hono";

type Env = { PATTERN_SECRET: string; DB: D1Database };

const app = new Hono<{ Bindings: Env }>();

app.use("*", async (c, next) => {
  const pattern = await createPattern({
    secret: c.env.PATTERN_SECRET,
    store: new D1TokenStore(c.env.DB),
    roots: [
      {
        name: "root",
        kind: "delegation",
        grants: [
          { method: "GET", path: "/docs/**" },
          { method: "GET", path: "/api/**" },
        ],
        // what this token may pass to children
        delegatable: [{ method: "GET", path: "/docs/**" }],
      },
    ],
  });

  // Log once at boot if you need the minted root token:
  // console.log(pattern.roots[0]?.token);

  return patternMiddleware(pattern)(c, next);
});

app.get("/docs/hello", (c) => c.text("hello"));

export default app;

Call your API with:

Authorization: Bearer <token>

Without a matching grant (or with a missing/invalid/revoked token), the middleware responds 401 and { "error": "<reason>" }.

Concepts

| Idea | Meaning | | --- | --- | | Grant | One allowed (method, path-pattern) pair | | Access token | Can call APIs that match grants; cannot issue children | | Delegation token | Can call APIs and issue narrower children via delegatable | | Attenuation | Children cannot gain methods/paths or a longer expiry than the parent | | Revoke | Exact jti; cascade revokes descendants by default |

Path patterns:

| Pattern | Matches | | --- | --- | | /docs | Exact path | | /docs/* | One segment (/docs/a, not /docs/a/b) | | /docs/** | Prefix and all descendants |

Create a Pattern instance

const pattern = await createPattern({
  secret: env.PATTERN_SECRET, // long random string
  store: new MemoryTokenStore(), // default if omitted
  roots: [
    /* optional StaticRoot[] minted at create time */
  ],
});

pattern exposes:

| Method | Use | | --- | --- | | verify(raw) | Validate signature, expiry, revocation | | decide(raw, method, path) | Verify + allowlist check | | issue({ parent, grants, expiresAt, ... }) | Mint a child under a parent token | | revoke(jti, { cascade? }) | Revoke (cascade defaults to true) | | mintRoot(root) | Mint another root after create | | roots | Roots minted from createPattern({ roots }) |

Issue a child token

Only a delegation parent can issue. Child grants must be covered by the parent's delegatable (or grants when used as the delegation set), and expiresAt must be ≤ parent exp.

const child = await pattern.issue({
  parent: rootToken, // raw Bearer token string
  kind: "access", // or "delegation"
  grants: [{ method: "GET", path: "/docs/*" }],
  expiresAt: Math.floor(Date.now() / 1000) + 3600,
});

if (!child.ok) {
  // child.reason, optional child.diff (excessGrants, expiryTooLong, …)
  throw new Error(child.reason);
}

// child.token → give to the client
// child.claims.jti → keep if you need to revoke later

Revoke

await pattern.revoke(child.claims.jti);
// await pattern.revoke(jti, { cascade: false }); // this jti only

Later requests with that token fail with revoked.

Exact jti mesh (MemoryTokenStore / D1TokenStore) is the default. For ultra-minimal deploys, EpochTokenStore stamps claims.epoch and treats any revoke as a global generation bump (all prior tokens die). Persist store.state yourself if you need durability across isolates.

import { createPattern, EpochTokenStore } from "@dytsou/pattern";

const store = new EpochTokenStore(); // or new EpochTokenStore({ epoch: n }) from KV
const pattern = await createPattern({ secret, store, roots: [/* … */] });
await pattern.revoke("any-jti"); // bumps epoch — cascade is irrelevant

MemoryTokenStore also exposes stats() / list() for light operator visibility (counts and in-memory rows — not an admin product).

Persist with D1

  1. Apply migrations/0001_init.sql to your D1 database.
  2. Pass D1TokenStore:
import { createPattern, D1TokenStore } from "@dytsou/pattern";

const pattern = await createPattern({
  secret: env.PATTERN_SECRET,
  store: new D1TokenStore(env.DB),
  roots: [
    /* ... */
  ],
});

For local tests or ephemeral Workers, omit store (uses MemoryTokenStore).

Without middleware

Pass the raw token string (the part after Bearer ):

const decision = await pattern.decide(rawToken, "GET", "/docs/hello");

if (!decision.allow) {
  // decision.reason: missing_token | invalid_token | expired | revoked |
  //                   method_not_allowed | path_not_allowed | …
}

Optional introspect endpoint

Mount only behind your own auth expectations (handler requires a delegation Bearer):

import { createIntrospectHandler } from "@dytsou/pattern/hono";

app.post("/pat/introspect", createIntrospectHandler(pattern));

Request body: { "token", "method", "path" }. See openapi.yaml for the HTTP shape.

Property corpus

Shipped invariants (peer fast-check):

import { runPropertyCorpus } from "@dytsou/pattern/properties";

await runPropertyCorpus(); // or call propDenyByDefault, propRevokePropagates, …

Examples

| Path | Runtime | | --- | --- | | examples/hono-worker | Cloudflare Workers + Hono + D1 | | examples/runtimes/smoke.ts | Node 20+ / Bun / Deno (Web Crypto) |

Traditional Chinese overview: README.zh-TW.md (English remains canonical).

AI agents (Cursor, Claude Code, Codex, OpenCode, Kimi, …)

This repo ships an Agent Skill so coding agents can wire pattern correctly:

| Layout | Agents | | --- | --- | | .agents/skills/pattern/ | Cursor, Codex, OpenCode, Kimi, AGI, other agentskills clients | | .claude/skills/pattern/ | Claude Code (symlink) | | .cursor/skills/, .codex/skills/, .opencode/skills/ | Extra discovery paths (symlinks) |

Project pointer: AGENTS.md. The published package includes .agents/ + AGENTS.md — copy node_modules/@dytsou/pattern/.agents/skills/pattern into your app’s .agents/skills/pattern if you consume via npm.

License

See LICENSE for details.