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

@prudra/express

v0.2.2

Published

Prudra Express adapter — wallet, payment, vault middleware

Readme

@prudra/express

Express adapter for Prudra — provides walletMiddleware, payMiddleware, and vaultMiddleware for building paid async agent APIs.

Installation

npm install @prudra/express express

Prerequisites

  • Call initialise() from @prudra/core before any middleware runs
  • Express 5 (express@^5.0.0)

1. Quick Start

import express from 'express';
import { initialise } from '@prudra/core';
import { walletMiddleware, payMiddleware, vaultMiddleware } from '@prudra/express';

initialise({ apiKey: process.env.PRUDRA_API_KEY! });

const app = express();
app.use(express.json());

app.post(
  '/analyse',
  walletMiddleware(),
  payMiddleware({ price: '0.01', description: 'Analyse a document' }),
  vaultMiddleware(),
  async (req, res) => {
    const { vault, payment } = req;

    // Return 202 immediately — work happens in background
    res.status(202).json({
      vaultId: vault!.id,
      vaultUrl: vault!.vaultUrl,
      eventsUrl: vault!.eventsUrl,
    });

    // Background work
    await vault!.emit('status', { step: 'processing' });
    const result = { summary: 'Analysis complete' };
    await vault!.addDocument(result, 'result.json');
    await vault!.seal('Document analysis complete');
  },
);

app.listen(3000);

2. walletMiddleware()

Provisions a wallet for the organisation and attaches it to req.wallet. Idempotent — the wallet is cached at module scope after the first request, so subsequent requests don't incur an extra API call.

The cache is invalidated automatically if an authentication error occurs (e.g., rotated API key), triggering a fresh provision on the next request.

app.use(walletMiddleware());

3. payMiddleware()

Enforces payment on a route. Supports both x402 and MPP protocols simultaneously.

app.use(payMiddleware({
  price: '0.01',           // USD decimal string
  description: 'Run job',  // Shown in 402 challenge
  acceptX402: true,         // Default: true
  acceptMPP: true,          // Default: true
  acceptSessions: false,    // Default: false
}));

Dual-protocol support: When a request arrives without payment credentials, payMiddleware returns a 402 response with both WWW-Authenticate (MPP) and X-PAYMENT-REQUIREMENTS (x402) headers. Both challenges are generated atomically before any response headers are written.

Session payments: When acceptSessions: true, MPP session-based payments are accepted. One session maps to one vault — the vault created for the session's first call is reused for subsequent calls.

On successful payment, req.payment is populated:

interface PrudraPaymentContext {
  protocol: 'x402' | 'mpp';
  amount: string;
  txHash: string;
  receipt: string;
  sessionId: string | null;
  paymentId: string;
}

4. vaultMiddleware()

Creates a Vault after payment and attaches it to req.vault. Must come after payMiddleware.

app.use(vaultMiddleware({
  ttl: '48h',                            // Default: '24h'
  description: 'Analysis results',       // String or (req) => string
}));

For MPP session payments, vaultMiddleware attaches the existing session vault instead of creating a new one.

If the organisation's vault quota is exceeded, a 402 response with problem type vault-quota-exceeded is returned.

5. Error Handling

All errors from Prudra middleware are RFC 9457 Problem Details objects. They propagate through Express's error handler:

app.use((err, req, res, next) => {
  if (err.status) {
    res.status(err.status).json({
      type: err.type,
      title: err.message,
      status: err.status,
      detail: err.detail,
    });
  } else {
    res.status(500).json({ error: 'Internal error' });
  }
});

Documentation

Full documentation: docs.prudra.dev/docs/express