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

@afauthhq/worker

v0.1.1

Published

AFAuth Cloudflare Workers bindings — createWorker, DurableObjectNonceStore, KvNonceStore, D1AccountStore

Downloads

360

Readme

@afauthhq/worker

Cloudflare Workers bindings for the AFAuth Protocol. Wraps @afauthhq/server in a Worker-native router and provides storage implementations backed by Durable Objects, KV, and D1.

Quickstart

import {
  AFAuthNonceDO,
  createNonceDurableObject,
  createWorker,
  DurableObjectNonceStore,
  KvRevocationList,
} from "@afauthhq/worker";
import {
  consoleEmailHandler,
  MemoryAccountStore,
  type DiscoveryDocument,
} from "@afauthhq/server";

// Re-export the nonce DO base class under whatever class_name your
// wrangler.toml binding declares (default: `AFAuthNonceDO`).
export class AFAuthNonceDO extends createNonceDurableObject() {}

interface Env {
  AFAUTH_NONCE_DO: DurableObjectNamespace;
  AFAUTH_REVOCATIONS: KVNamespace;
}

const discovery: DiscoveryDocument = { /* ... */ };
const accounts = new MemoryAccountStore(); // replace with durable impl

export default {
  fetch(req, env: Env, ctx) {
    const handler = createWorker({
      nonceStore: new DurableObjectNonceStore(env.AFAUTH_NONCE_DO),
      revocationList: new KvRevocationList(env.AFAUTH_REVOCATIONS),
      serviceDid: discovery.service_did,
      accounts,
      recipients: { email: consoleEmailHandler },
      discovery,
      baseUrl: "https://api.example.com",
      extractOwnerSession: async (req) => /* your session extraction */ null,
    });
    return handler.fetch!(req, env, ctx);
  },
};

wrangler.toml binding for the DO:

[[durable_objects.bindings]]
name       = "AFAUTH_NONCE_DO"
class_name = "AFAuthNonceDO"

[[migrations]]
tag         = "v1"
new_classes = ["AFAuthNonceDO"]

Nonce store: pick DO, not KV

§5.6 requires the seen-nonce set be shared and atomic across verifier instances. Cloudflare KV is shared but offers no atomic check-and-set: a get-then-put window admits cross-isolate replay during the freshness window.

| Store | Atomic? | Shared? | When to use | |---|---|---|---| | DurableObjectNonceStore | yes | yes | recommended for production | | KvNonceStore | no | yes | dev only, or single-region low-value deployments where the trade-off is documented | | MemoryNonceStore (from @afauthhq/server) | yes | no | tests only |

DurableObjectNonceStore partitions by keyid so unrelated agents fan out across distinct actor instances; only requests from the same agent share an actor and serialize against each other.

Exports

  • createWorker(opts) — returns an ExportedHandler routing the five AFAuth endpoints to @afauthhq/server handlers. Routing is done with a small in-house router (ADR-0002).
  • createNonceDurableObject() — factory that returns a Durable-Object base class implementing the §5.6 atomic check-and-set protocol. Subclass it in your Worker module and register the subclass in wrangler.toml.
  • DurableObjectNonceStoreNonceStore that delegates to the DO above. Spec-compliant atomic insert; recommended for production.
  • KvNonceStoreNonceStore backed by Cloudflare KV. Has a known eventual-consistency replay window; see the JSDoc on the class. Suitable for dev/low-value deployments only.
  • KvRevocationListRevocationList backed by Cloudflare KV (§8.3). Durable; no TTL.
  • KvRateLimiterRateLimiter backed by Cloudflare KV (§11.3). Fixed-window counter per key; eventually-consistent reads mean racing isolates may over-count (fail-safe per §11.3), never under-count.
  • D1AccountStoreAccountStore backed by Cloudflare D1 (§6 + §7.3). Every ADR-0004 named atomic op uses D1.batch() for transactional grouping. The schema lives at migrations/0001_init.sql; apply via wrangler d1 migrations apply <db-name> before first use. Schema is portable to standard Postgres/MySQL with minor syntactic changes.
  • WorkerOptions — extends ServerOptions with the required extractOwnerSession callback for the claim-completion route.

See also

  • AFAuthHQ/spec — protocol spec.
  • @afauthhq/server — the handlers createWorker dispatches to.
  • examples/worker/ — runnable reference Worker that prefers DO when its binding is configured and falls back to KV (with a warning) otherwise.