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

@nodii/capacity-contract

v0.4.1

Published

Dimension Capacity contract — the band-aware subscription capacity-replica projection (over capacity is admitted and charged, S08-29), the capacity quote DTO, and the deprecated AT_CAPACITY body.

Readme

@nodii/capacity-contract (TS)

The shared Dimension Capacity contract: one dialect spoken by CRM / HR / ticketing / FE for reading a tenant's per-dimension band from the capacity replica, and for the capacity quote.

Zero runtime dependencies — pure types, pure functions, hand-rolled runtime guards.

The same contract ships as nodii-capacity-contract (Python, python/capacity-contract) and nodii.co/nodii-libs/go/capacity-contract (Go, go/capacity-contract). All three ports assert the shared vectors in scripts/parity/capacity-contract-cases.json, and the parity fence in synthetic-consumers/capacity-contract checks that they answer every vector identically.

The band model: over capacity is admitted, never refused

A roster owner MUST NOT refuse an assignment because the dimension is over capacity. Over-capacity intake is admitted and charged under the band model, with no holding pen (S08-29). Going past the band is overage, charged through tenant-service's CapacityService. The only refusal on the assignment path is the one CapacityService answers, 409 OVERAGE_BLOCKED (an enforcing budget, or a wallet that cannot pay with negative balance off; S08-26).

So nothing in this package is a gate. capacityFor tells you where the band ceiling is; it never tells you to say no.

What it carries

1. The capacity-replica projection spec

The per-(subscription, dimension) row a roster owner projects from the subscription replication stream it already consumes:

import {
  capacityFor,
  bandReplicaViewFor,
  remainingCapacity,
  type CapacityReplicaRow, // { tenant_id, subscription_id, dimension_key,
                           //   capacity, source_entity_version,
                           //   module_key?, entitled? }
} from "@nodii/capacity-contract";

// The add-on that carries the dimension is the module key (D1154 §5, D1301).
const ceiling = capacityFor(replicaRows, "collectors", "crm.collector");
const insideBand = remainingCapacity(ceiling, rosterCount);
// insideBand === 0 ⇒ the next add is overage: admit it and charge it through
// tenant-service. Do NOT refuse it.

How capacityFor(rows, dimensionKey, moduleKey) reads the band. Each module bills by dimensions, and each dimension has a band the tenant picked; no capacity record exists without a module (Q-231).

  1. Malformed rows, rows of other dimensions and rows of other modules are ignored.
  2. A row of this dimension without module_key is not capacity. It is never summed, never used as a ceiling, and never evicts a row of this module. It is reported as a defect: once per reading, every such row goes to options.onModuleLessRows. The default, warnModuleLessRows, logs one console.warn with MODULE_LESS_ROW_DEFECT for each (tenant, subscription, dimension) not yet named in the process. Pass a handler to send the report to your own logger or metrics.
  3. Last-Writer-Wins per subscription on source_entity_version. At an equal version an entitled row, then the larger ceiling, wins, so the reading never depends on row order.
  4. Across subscriptions an entitled row beats an unentitled one, then the larger ceiling wins (one module is one subscription, D1301, so more than one is not expected).
  5. entitled: false (the module is not subscribed) gives 0.
  6. No matching row gives 0.

bandReplicaViewFor returns the same reading with its subscription, module and entitlement, or null when nothing matches. moduleKey must be a non-empty string; anything else throws a TypeError.

2. The capacity quote DTO (D615)

What tenant-service returns from POST /commerce/capacity/quote, and what the confirm-with-charge dialog renders:

import { isCapacityQuote, type CapacityQuote } from "@nodii/capacity-contract";
// { amount_minor, currency, wallet_balance_minor, wallet_covers,
//   topup_required_minor, minimum_applied }

Integer minor units; currency an ISO-4217 code. wallet_balance_minor MAY be negative: a prepaid wallet can sit below zero under a mandate plus acknowledgement (S08-34), and tenant sends billing's balance unclamped. wallet_covers true ⇒ "it just works" (no charge). topup_required_minor > 0 ⇒ embedded top-up. minimum_applied ⇒ the platform-minimum floor was hit.

3. Deprecated: the legacy AT_CAPACITY body

AT_CAPACITY_CODE, AtCapacityError and isAtCapacityError are deprecated. Never produce an AT_CAPACITY refusal (S08-29). The atCapacityError builder is removed, so the package cannot produce one. The guard stays only so a consumer can read a body from an older producer while it moves off it. These exports are removed in a later major release.