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

@harpd/x402-logging-middleware

v0.1.0

Published

Drop-in x402 payment logging middleware for Node HTTP / Express. Structured, audit-friendly logs for every x402 interaction. Zero runtime deps.

Readme

@harpd/x402-logging-middleware

Drop-in x402 payment logging middleware for Node HTTP / Express apps. Every x402 interaction — a 402 Payment Required response, a client-attached X-Payment header, a settled transaction — is emitted as one structured, audit-friendly event. Zero runtime dependencies.

Part of Harpd's open-source agent-commerce toolkit. Pairs well with @harpd/agent-transaction-audit-schema (the event shape is compatible) and @harpd/observe (swap the sink to forward events to the Harpd collector).

Install

npm install @harpd/x402-logging-middleware

Express / Connect usage

import express from 'express'
import { createX402LoggingMiddleware } from '@harpd/x402-logging-middleware'

const app = express()
app.use(createX402LoggingMiddleware({ direction: 'inbound' }))

// A paid endpoint — the 402 + the eventual settlement both get logged.
app.get('/paid-resource', (req, res) => {
  res.setHeader('www-authenticate', JSON.stringify({
    accepts: [{ scheme: 'exact', asset: 'eip155:8453/erc20:0xUSDC', price: '10000', maxTimeoutSeconds: 60 }],
  }))
  res.status(402).end()
})

Every request through the middleware emits a JSON event:

{
  "middleware": "x402-logging-middleware",
  "version": "0.1.0",
  "direction": "inbound",
  "timestamp": "2026-07-29T...Z",
  "method": "GET",
  "path": "/paid-resource",
  "statusCode": 402,
  "asset": "eip155:8453/erc20:0xUSDC",
  "amountUsd": 0.01,
  "txHash": null,
  "x402": { "requirement": { "accepts": [ ... ] }, "payment": null, "paymentResponse": null }
}

Custom sink (forward to Harpd / your own store)

import { createX402LoggingMiddleware } from '@harpd/x402-logging-middleware'

const forwardToHarpd = (event) =>
  fetch('https://api.harpd.com/v1/events', {
    method: 'POST',
    headers: { authorization: `Bearer ${process.env.HARPD_KEY}` },
    body: JSON.stringify(event),
  })

app.use(createX402LoggingMiddleware({ sink: forwardToHarpd }))

Manual logging (clients, background jobs)

import { logX402Payment } from '@harpd/x402-logging-middleware'

logX402Payment({
  direction: 'outbound',
  resource: 'https://paid-api.example.com/v1/weather',
  asset: 'eip155:8453/erc20:0xUSDC',
  amountUsd: 0.01,
  txHash: '0xabc...',
  status: 'settled',
})

Why a middleware (not just console.log)

A payment audit trail that lives only in your app logs is fragile. This middleware gives you a single, normalized event for every x402 hop so the same record can feed dashboards, alerts, and compliance — see the audit schema package.

License

MIT © Harpd. Issues and PRs welcome at github.com/harpd-dev/x402-logging-middleware.