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

caselaw-access

v0.5.0

Published

TypeScript client for the Case Law Explorer shared access service.

Downloads

44

Readme

caselaw-access

TypeScript client for the Case Law Explorer access service. One call decides authentication, endpoint scope, and rate limit, so a product implements none of them itself.

Install

npm install caselaw-access

The package ships raw TypeScript with no build step (same praxis as caselaw-ui), so it expects a bundler or a TS-aware runtime.

Configuration

Everything comes from the environment:

| Variable | Meaning | Default | | --- | --- | --- | | ACCESS_SERVICE_URL | Base URL of the access service. Empty disables all checks. | — | | ACCESS_PROJECT | Project slug registered in the console. No default. | — | | ACCESS_SERVICE_TIMEOUT_SECONDS | Per-check timeout. | 5 | | ACCESS_FAIL_OPEN | Waive quota for already-validated credentials when the service is unreachable. Never waives authentication. | false | | REQUIRE_AUTH / ACCESS_ENFORCE | Master switch for enforcement. Unset on a connected deployment is an error, not an opt-out. | unset | | ACCESS_IDENTITY_CACHE_SECONDS | How long a validated credential stays eligible for fail-open. | 300 |

Checks are only sent when the service URL is set and enforcement is on. That combination is what lets a service run locally, and its tests run in CI, without the control plane.

Direct use

import { AccessClient, RateLimited, PermissionDenied } from "caselaw-access";

const client = AccessClient.fromEnv();

try {
  const decision = await client.check(token, { endpoint: "echr", method: "POST" });
  // decision.plan, decision.scopes, decision.headers()
} catch (error) {
  if (error instanceof RateLimited) { /* 429, error.headers() has Retry-After */ }
  if (error instanceof PermissionDenied) { /* 403 */ }
}

Express

import { AccessClient, createGuard } from "caselaw-access";

const guard = createGuard(AccessClient.fromEnv());

app.post("/api/echr", guard.middleware("echr"), (req, res) => {
  // req.accessDecision is set; quota headers are already on the response
});

A denial is answered before your handler runs, with the right status, { error: code } body, and Retry-After / X-RateLimit-Remaining-* headers.

Failure semantics

| Situation | Result | | --- | --- | | No or malformed Authorization header | 401, service never called | | ACCESS_PROJECT unset while enforcing | 503, service never called, not subject to fail-open | | Service answers 401 | 401 with the service's code | | Service answers 403, or allowed: false with a scope error | 403 | | Service answers 429, or allowed: false with rate_limit_exceeded | 429 with Retry-After | | Service unreachable, times out, or answers something it cannot decide on | 503, or allowed when ACCESS_FAIL_OPEN=true and this credential was recently validated for this endpoint |

Connection failures are retried because the request provably never arrived. Read timeouts are not retried: the service may already have counted the call against the caller's quota, and a retry would charge them twice.

Tests

npm ci && npm run check && npm test

The suite drives the shared conformance cases in ../contract, the same file the Python client runs, so the two cannot drift.

Releasing

Released by GitHub Actions via npm trusted publishing — no token anywhere. Bump version in package.json, commit, push, then:

git tag js-v0.2.0 && git push origin js-v0.2.0

The workflow refuses to publish if the tag and package.json disagree. See ../README.md for the full procedure.

Framework adapters

The client is framework-agnostic — check() takes a token and returns a decision. These wrap it so guarding a route is one import and one call. None of them adds a dependency: each is typed structurally against the small part of its framework it touches.

import { protect } from "caselaw-access/express";   // app.get(p, protect("search"), handler)
import { protect } from "caselaw-access/fastify";   // { preHandler: protect("search") }
import { protect } from "caselaw-access/koa";       // app.use(protect("search"))
import { protect } from "caselaw-access/hono";      // app.get(p, protect("search"), handler)
import { protect } from "caselaw-access/fetch";     // export const GET = protect("search", handler)
import { protect } from "caselaw-access/sveltekit"; // export const GET = protect("search", handler)
import { protect } from "caselaw-access/nuxt";      // defineEventHandler(protect("search", handler))

caselaw-access/fetch wraps a (Request) => Response handler, which covers Next.js route handlers, Cloudflare Workers, Deno and Bun. SvelteKit gets its own entry only because its endpoints take an event rather than a bare request.

caselaw-access/nuxt (also exported as /h3) is for Nuxt server routes and Nitro. H3 is the odd one out: a handler returns a value H3 serialises rather than a Response it builds, so a denial is thrown as an H3 error. Quota headers need a response handle, which the Node preset Nuxt uses by default provides; an edge preset keeps the status and the body but not those headers.

The endpoints a project guards are declared in the access console, not by the client. Rate limits are configured before any traffic exists, so the list has to exist then too — and the console verifies it by probing each route with no credential, which proves the guard is actually on the handler rather than just that a client started.

On a denial the response is already written when the handler is skipped: status, JSON body, and the Retry-After and X-RateLimit-* headers. Those headers are the part hand-written glue reliably drops, because nothing fails when they are missing — the caller simply never learns when to retry.

What fail-open does, and does not, do

/v1/check answers two questions at once: who is this caller, and do they have quota left. Waiving both during an outage means any non-empty bearer string is admitted — an authentication bypass dressed up as an availability feature.

So ACCESS_FAIL_OPEN=true waives quota only, and only for a credential this process has already watched the service accept for that same endpoint within ACCESS_IDENTITY_CACHE_SECONDS. Anything else is denied exactly as if the policy were fail-closed.

In practice: an outage does not interrupt traffic that was already flowing, and does not let anything new in. The cost is that a credential revoked during an outage keeps working until its cache entry expires — set ACCESS_IDENTITY_CACHE_SECONDS=0 to disable the mechanism entirely, which makes ACCESS_FAIL_OPEN a no-op.

The pair is keyed on credential and endpoint on purpose. Keying on the credential alone would let an outage promote a caller onto an endpoint they were never entitled to, turning a quota waiver into an authorization bypass.

Enforcement must be stated

Leaving REQUIRE_AUTH / ACCESS_ENFORCE unset while a project and a secret are configured raises access_enforcement_not_configured rather than running inert. A project secret is issued once, by hand, for a specific deployment, so carrying one is unambiguous intent — an absent flag is a forgotten variable, and guessing wrong means enforcing nothing while looking fully configured.

Set it explicitly to false to run inert on purpose.