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

idem-key

v0.1.0

Published

http idempotency keys done right. fingerprints the request, dedups in flight, replays the original response

Readme

idem-key

http idempotency keys done right. fingerprints the request, dedups in flight, replays the original response.

npm i idem-key

why

"retry the payment" is the most dangerous line in any api client. the standard answer is an idempotency key, and almost every implementation gets one of these wrong:

  • the same key with a different body runs anyway — a client bug becomes a double charge
  • two concurrent retries both run — the check and the write are not atomic
  • a failure gets cached — the retry replays an error forever
  • only the body is stored — the replay loses the status code

use

import { Idempotency } from 'idem-key'

const idem = new Idempotency()

const out = await idem.run(key, { method: 'POST', path: '/charges', body }, async () => {
  const charge = await stripe.charges.create(body)
  return { status: 201, body: charge }
})

out.replayed   // false the first time, true after
out.response   // the same response either way

same key, different request

await idem.run('k1', { body: { amount: 100 } }, work)
await idem.run('k1', { body: { amount: 999999 } }, work)
// IdempotencyError: key k1 was already used with a different request  (KEY_REUSED)

the work does not run. that is the whole point — the key is a promise that this exact request happens once.

key order in the body does not count as a different request:

{ a: 1, b: 2 }  ===  { b: 2, a: 1 }   // same fingerprint

concurrent retries

const a = idem.run('k1', req, slowWork)   // runs
const b = idem.run('k1', req, slowWork)   // IdempotencyError: in progress (IN_PROGRESS)

the gate is store.create(), which must only write when the key is absent and report whether it won. that is a single atomic operation — INSERT … ON CONFLICT DO NOTHING, SETNX, or a unique index. no read-then-write race.

failures are not results

await idem.run('k1', req, failing)   // throws
await idem.run('k1', req, working)   // runs again, not replayed

a thrown error deletes the record. only a returned response is stored.

stuck records

if a process dies mid-request the record would block the key forever. after leaseMs (default 60s) the next caller takes it over.

express

import { middleware } from 'idem-key'

app.post('/charges', middleware({ required: true }), handler)

reads Idempotency-Key, sets Idempotent-Replay: true on a replay, returns 409 for in-progress and 422 for a reused key.

your own store

const idem = new Idempotency({
  store: {
    async get (key) { … },
    async create (record) { /* must be atomic, return false if it exists */ },
    async update (record) { … },
    async delete (key) { … }
  }
})

create is the only method that has to be atomic. everything else is ordinary.

api

| | | |---|---| | new Idempotency({ store?, ttlMs?, leaseMs?, now? }) | ttl 24h, lease 60s | | .run(key, request, work) | { replayed, response } | | middleware({ header?, required?, … }) | express style | | fingerprint(request) | sha256 of method + path + canonical body | | MemoryStore | for tests and single process |

zero dependencies. node crypto only. types included.

licence

MIT