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

node-legal-docs-client

v1.0.0

Published

Server-side client for the Case Law Explorer API. Holds an API key, so it belongs on a server and never in a browser.

Readme

node-legal-docs-client

A client for the Case Law Explorer API, for TypeScript on a server.

npm install node-legal-docs-client

Server-side only

This holds an API key. Do not import it into browser code.

A key given to a page is readable by anyone who opens developer tools — and, worse, usable by them to make whatever calls they like against your quota. Hiding it behind a bundler does not help: import.meta.env.VITE_* is replaced with the literal value at build time, so the key ends up compiled into the JavaScript you ship.

Browser code should call your server. Your server calls this.

browser ──▶ your server ──▶ Case Law Explorer API
             (holds the key)

If you only need the shapes — to build a query in a form, or render a document — import legal-docs-types instead. It has no client and cannot make a request, so it is safe anywhere.

Use

import { createLegalDocsClient } from "node-legal-docs-client";

const client = createLegalDocsClient({
  apiKey: process.env.CITATIONS_API_KEY,
});

const results = await client.fetchRechtspraak({
  degreesSource: 1,
  degreesTarget: 1,
  keywords: ["huurrecht"],
});

In a Nuxt or Next server route

// server/api/legal-docs/search.post.ts
import { createLegalDocsClient } from "node-legal-docs-client";

const client = createLegalDocsClient({ apiKey: process.env.CITATIONS_API_KEY });

export default defineEventHandler(async (event) => {
  const query = await readBody(event);
  return query.dataset === "ECHR"
    ? client.fetchEchr(query.params)
    : client.fetchRechtspraak(query.params);
});

What it supports

| Method | Endpoint | |---|---| | fetchRechtspraak(query, computeStatistics?) | POST /rechtspraak | | fetchEchr(query, computeStatistics?) | POST /echr | | computeStatistics(docs) | POST /statistics | | getRechtspraakFullText(eclis) | POST /rechtspraak/text | | getEchrFullText(eclis, language?) | POST /echr/text | | fetchLaws(query) | GET /links/laws?q= |

setApiKey(key) and setHeaders(headers) change them after construction.

Errors

Failures throw ApiError, carrying the HTTP status and the response body.

import { ApiError } from "node-legal-docs-client";

try {
  await client.fetchRechtspraak(query);
} catch (err) {
  if (err instanceof ApiError && err.isAuthFailure) {
    // Your key, not their query. Do not show this to the person searching.
  } else if (err instanceof ApiError && err.status === 400) {
    // Their query. err.body says which filter was wrong.
  }
}

status is undefined when nothing answered at all — a timeout, a refused connection — so an absent status is never mistaken for the API's verdict.

Getting a token

https://api.caselawexplorer.tech/login.html?next=/account.html

Types

Every request and response shape comes from legal-docs-types, and is re-exported here so a server needs only this package in its dependencies. Browser code should depend on legal-docs-types directly and never on this.

The Go equivalent is go-legal-docs-client, which carries its own types: nothing in Go needs the shapes without the client, so there is no reason to split them there.

Development

npm install
npm link ../legal-docs-types   # to work against unreleased changes to the types
npm run build