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

@filamentjs/idempotency

v0.1.0

Published

Atomic idempotency-key replay for FilamentJS

Readme

@filamentjs/idempotency

Atomic Idempotency-Key protection for explicitly marked POST and PATCH endpoints. Matching retries replay final response bytes, while changed or concurrent duplicates stop before the operation executes again.

Key features

  • Atomic lease acquisition and ownership-checked final response persistence.
  • Scoped fingerprints covering method, path, query, content type, and body.
  • Exact replay of bounded final bytes, including transformed and error results.
  • Bounded standalone storage plus an optional atomic Redis adapter.
  • Secure 400/401/409/500/503 behavior with no speculative re-execution.

Quick start

npm install @filamentjs/idempotency filamentjs
import { createApp, type ContextMeta as BaseContext, type FrameworkMeta } from "filamentjs";
import {
  createStandaloneStore,
  setup,
  type AppMeta,
  type ContextMeta,
} from "@filamentjs/idempotency";

const store = createStandaloneStore({ maxEntries: 100_000 });
const app = createApp<FrameworkMeta & AppMeta, BaseContext & ContextMeta>(
  { application: { maxRequestSize: "1MiB" } },
  {},
);
setup(app, {
  store,
  resolveScope: () => "replace-with-authenticated-tenant-and-principal",
});
app.post(
  "/payments",
  { idempotency: { required: true, ttlSeconds: 86_400 } },
  async (_req, res) => res.json({ accepted: true }),
);
// On shutdown: await app.close(); await store.close();

Requires Node 24+ and the exact supported peer [email protected].

How it works and options

Missing required keys return 400, changed fingerprints and concurrent duplicates return 409, and completed matching requests replay final bytes.

Keys are opaque visible ASCII up to 255 bytes. The fingerprint includes method, path, deterministically encoded query parameters, selected content type, and exact request bytes. resolveScope(req) must provide an authenticated tenant/principal namespace; no client forwarding header is trusted. Pre-execution validation/conflict responses are not stored.

Once execution begins, every completed response—including 4xx and 5xx—is retained and replayed. This prevents an ambiguous error from causing duplicate side effects. Safe representation headers are retained; Set-Cookie, hop-by-hop, date, and per-request fields are not. Protected responses are forced buffered and bounded. Register output-format before idempotency so idempotency's later transformer captures final representation bytes.

This intentionally follows a documented subset of established payment/API behavior, not an expired Internet-Draft. Bounded waiting is not implemented; in-progress duplicates receive 409 immediately.

The standalone store is bounded, process-local, and non-durable. It is not safe for multi-process double-payment protection. @filamentjs/redis includes an atomic lease/compare-and-complete Lua adapter whose contention, replay, and expiry suite passes against Redis 6.2.23. Reconnect, ambiguous-failure, and cluster-deployment tests remain before distributed-production claims. A GET followed by SET is unsafe.

Public API

| Surface | Meaning | | --- | --- | | setup(app, options) | Registers acquisition middleware, final-byte capture, and error-path finalization once. | | createStandaloneStore(options?) | Creates bounded process-local leases and records. | | IdempotencyStore | Structural atomic acquire/complete backend contract. | | AppMeta.idempotency | false, or endpoint required and ttlSeconds options. | | ContextMeta.idempotency | Internal request lease/capture state; applications should treat it as read-only. |

Resolve authentication/tenant scope before this policy. Register output-format before it so idempotency captures negotiated final bytes. Middleware can stop with 400, 401, 409, 500, or 503; replay adds Idempotency-Replayed: true. Filament 0.6 cannot prevent a handler from switching a forced-buffered response back to streaming, so protected handlers must not do so.

Development and demo

From a source checkout:

npm test
npm run example
npm run demo

The unattended demo sends the same protected POST twice, prints original and replayed responses, proves the handler executed once, then closes the server/store and exits. There is no pre-0.1 migration contract.

License

ISC