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

browser-metered-client

v0.1.0

Published

Minimal JavaScript client library for browser-metered-proxy

Downloads

13

Readme

browser-metered-client

Minimal JavaScript client library for browser-metered-proxy. Handles the three things every browser app needs when talking to the proxy: attaching identity, signing submissions, and dispatching capabilities.

  • JWT auth — store the token after login/register, attach it automatically to every request
  • Ed25519 signing — generate and store a keypair via the Web Crypto API, sign submission payloads for tamper-proof storage
  • Capability dispatch — send requests in the correct envelope shape, return structured results

No runtime dependencies. No bundler required. Ships as an ES module.

Requirements

  • Chrome 113+, Firefox 129+, or Safari 17+ (Ed25519 via Web Crypto API)

Installation

npm install browser-metered-client

Usage

Initialize

import { createClient } from 'browser-metered-client'

const client = createClient({
  baseUrl: 'https://your-proxy.fly.dev', // required
  storage: localStorage,                  // optional, default: localStorage
})

Auth

// Register — stores JWT automatically
await client.auth.register('[email protected]', 'password', 'password')

// Login — stores JWT automatically
await client.auth.login('[email protected]', 'password')

// Set token manually (e.g. from local SQLite in a WASM app)
client.auth.setToken(jwt)

// Get current token
client.auth.getToken()

// Clear token (logout)
client.auth.clearToken()

Invoke a capability

// Basic capability — JWT attached automatically
const result = await client.invoke('verify_income', {
  external_id: 'item_abc123'
})
// { status, raw_cost_cents, markup_cents, total_charged_cents, ... }

// Signed submission — payload signed with stored Ed25519 keypair
const result = await client.invoke('submit_form', {
  data: { name: 'Jane Doe', income: 75000 },
  idempotency_key: 'application_abc123'
}, { sign: true })
// { submission_id, status, raw_cost_cents, markup_cents, total_charged_cents }

Key management

// Generate a new Ed25519 keypair and store it
await client.keys.generate()

// Check if a keypair exists
client.keys.exists()

// Get the public key as base64 (safe to send to the server)
await client.keys.publicKey()

// Clear the stored keypair
client.keys.clear()

Usage & billing

// Paginated capability log
const log = await client.usage.log({
  capability: 'verify_income', // optional
  provider: 'plaid',           // optional
  status: 'success',           // optional
  start_date: '2026-01-01',    // optional
  page: 1                      // optional
})
// { records, total, page, pages }

// Monthly summary
const summary = await client.usage.summary()
// { this_month_total_cents, this_month_raw_cost_cents, this_month_markup_cents,
//   all_time_total_cents, call_count_this_month, breakdown_by_capability,
//   breakdown_by_provider, last_12_months }

Error handling

Non-2xx responses reject with a ProxyError:

try {
  await client.invoke('verify_income', { external_id: 'item_abc' })
} catch (err) {
  err.status  // HTTP status code
  err.message // error message from proxy
}

Custom storage

Pass any object with getItem(key) and setItem(key, value) to use a storage backend other than localStorage — useful for WASM apps with SQLite-backed storage:

const client = createClient({
  baseUrl: 'https://your-proxy.fly.dev',
  storage: {
    getItem: (key) => db.query('SELECT value FROM kv WHERE key = ?', [key]),
    setItem: (key, value) => db.exec('INSERT OR REPLACE INTO kv VALUES (?, ?)', [key, value])
  }
})

Development

npm test        # run tests once
npm run test:watch  # watch mode

License

MIT