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

@dcl/http-commons

v1.0.2

Published

http server common utils

Readme

@dcl/http-commons

Common middlewares and utilities for HTTP servers built on top of @well-known-components. Provides reusable error types, request handlers, and helpers for paginated endpoints, JSON parsing, and Ethereum address handling.

Installation

pnpm add @dcl/http-commons

Prerequisites

  • Node.js: >=22.0.0
  • Peer-style usage with @well-known-components/interfaces (already a dependency)

Errors

Typed exceptions intended to be thrown from controllers/logic and translated to HTTP responses by the errorHandler middleware.

import {
  InvalidRequestError,
  NotFoundError,
  NotAuthorizedError,
  HTTPResponseError
} from '@dcl/http-commons'

| Error | Mapped status (via errorHandler) | |-------|------------------------------------| | InvalidRequestError | 400 Bad request | | NotFoundError | 404 Not Found | | NotAuthorizedError | 401 Not Authorized | | HTTPResponseError | wraps a node-fetch Response for outbound HTTP failures |

Anything else thrown is logged and returned as 500 Internal Server Error.

Middlewares

errorHandler

Catches typed errors from downstream handlers and converts them into structured HTTP responses. Requires a logs component on the request context.

import { errorHandler } from '@dcl/http-commons'

router.use(errorHandler)

bearerTokenMiddleware

Validates the Authorization: Bearer <token> header against a shared secret using a constant-time comparison. Throws NotAuthorizedError on missing or invalid tokens.

import { bearerTokenMiddleware } from '@dcl/http-commons'

router.use('/internal', bearerTokenMiddleware(process.env.AUTH_SECRET!))

ethAddressNormalizerMiddleware

Lowercases any URL parameter whose value is a valid Ethereum address, so route handlers don't have to normalize addresses themselves.

import { ethAddressNormalizerMiddleware } from '@dcl/http-commons'

router.use(ethAddressNormalizerMiddleware())

Utilities

getPaginationParams

Parses limit and offset from a URLSearchParams. limit must be a positive integer ≤ 100; missing, zero, negative, or out-of-range values fall back to 100. offset defaults to 0 if missing or negative.

import { getPaginationParams } from '@dcl/http-commons'

const { limit, offset } = getPaginationParams(new URL(ctx.url).searchParams)

parseJson

Reads and parses a JSON body, throwing InvalidRequestError('Invalid body') on failure (so it surfaces as 400 via errorHandler).

import { parseJson } from '@dcl/http-commons'

const payload = await parseJson<MyDto>(ctx.request)

generateRandomWalletAddress / generateRandomWalletAddresses

Generates one or many random 0x-prefixed 20-byte addresses. Useful for tests and fixtures.

import { generateRandomWalletAddress, generateRandomWalletAddresses } from '@dcl/http-commons'

const address = generateRandomWalletAddress()
const addresses = generateRandomWalletAddresses(5)

Project Structure

src/
├── index.ts                   # Public entry point
├── errors.ts                  # Typed HTTP errors
├── types.ts                   # Shared context types
├── adapters/
│   └── pagination.ts          # getPaginationParams
├── controllers/
│   └── handlers/
│       ├── error-handler.ts             # errorHandler
│       ├── bearer-token-middleware.ts   # bearerTokenMiddleware
│       └── eth-address-normalizer-middleware.ts
└── utils/
    ├── parsing.ts             # parseJson
    └── wallet.ts              # generateRandomWalletAddress(es)

Development

From the monorepo root:

pnpm install
pnpm --filter @dcl/http-commons build
pnpm --filter @dcl/http-commons test