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

@warp-lang/commerce-metrics

v0.1.0

Published

Structured metrics for Warp's commerce-integrity guardrail — wrap the published guardAction and count the blocks it returns, by rule (I-1..I-6 and guard rules) and by scope. An observability layer only: it composes @warp-lang/commerce-types and tallies ve

Readme

@warp-lang/commerce-metrics

Structured metrics for Warp's commerce-integrity guardrail.

Wrap the published @warp-lang/commerce-types guardAction with withMetrics, and every block the guard returns is counted — by rule (the invariant ids I-1..I-6, plus the guard's own rules such as version-conflict) and by scope (by default the proposed target state type, e.g. Refunded, Cancelled).

This package is an observability layer only. The wrapper calls the published guardAction and returns its verdict unchanged; it records the verdict it sees. It does not change, re-derive, or weaken any invariant, transition, or guard logic. If you remove the wrapper, the verdicts are byte-for-byte the same.

Install

npm install @warp-lang/commerce-metrics

It depends on @warp-lang/commerce-types@^1.3.0.

Use

import { guardAction } from "@warp-lang/commerce-types";
import { withMetrics, MetricsCollector } from "@warp-lang/commerce-metrics";

const collector = new MetricsCollector();
const guard = withMetrics(guardAction, collector);

// `guard` has the SAME signature and returns the SAME verdict as guardAction.
const verdict = guard(world, action);
if (!verdict.ok) {
  // verdict.violations — the guard's own actionable reasons, untouched
}

// Read the tally at any time:
collector.snapshot();
// {
//   totalAllowed: 12,
//   totalBlocks: 3,
//   byRule:  { "I-1": 2, "I-2": 1 },
//   byScope: { "Refunded": 2, "Draft": 1 },
// }

withMetrics(guard?, collector?, options?):

  • guard — the guard function to wrap; defaults to the published guardAction.
  • collector — the MetricsCollector to record into; defaults to a fresh one. The returned function also carries it as .collector.
  • options.scopeOf(world, action) — derive the scope label; defaults to the action's target state type.

A block that cites more than one rule increments each cited rule, so the sum of byRule can exceed totalBlocks. Each block increments exactly one byScope bucket.

What it does not do

  • It does not produce verdicts — it observes the wrapped guard's verdicts.
  • It does not persist, export, or aggregate over time. MetricsCollector is an in-memory, process-local tally; a caller that needs a time series or an exporter can read snapshot() and forward it.
  • It makes no network calls and holds no credentials.

Example

npm install
npm run build
node examples/metrics.mjs

Runs several actions (valid refunds, an I-1 over-refund, an I-2 illegal backward move) through the wrapped guard and prints the tally by rule and scope.

Develop

npm install
npm run build      # tsup -> dist (esm + cjs + d.ts)
npm test           # vitest
npm run typecheck  # tsc --noEmit