Registry / web-framework / express-idempotency-middleware

express-idempotency-middleware

JSON →
library1.0.2jsnpmunverified

Express middleware for idempotent POST requests using Idempotency-Key header (version 1.0.2, stable release, active development). Provides pluggable stores (Memory, Redis, Postgres), in-flight concurrency control with wait or reject strategies, and safe response replay with header whitelist. TypeScript-first, ESM-only, requires Node ≥18 and Express 4 or 5. Differentiators: built-in in-flight handling via wait timeout polling, stable response fingerprinting, and separate replay header whitelist for security-aware caching of location headers without cookies or auth tokens. Designed for payment, order, and webhook idempotency scenarios.

web-frameworkhttp-networking
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ESM-only package; CommonJS require is not supported

import { idempotencyMiddleware } from 'express-idempotency-middleware'

MemoryStore is a named export, not a default export or subpath

import { MemoryStore } from 'express-idempotency-middleware'

Type-only import for TypeScript; requires 'type' keyword for runtime efficiency

import type { IdemOptions } from 'express-idempotency-middleware'

Creates an Express app with idempotency middleware on POST /payments, using MemoryStore, wait strategy for in-flight requests, and replay header whitelist.

import express from 'express'; import { idempotencyMiddleware, MemoryStore } from 'express-idempotency-middleware'; const app = express(); app.use(express.json()); const store = new MemoryStore(); app.post( '/payments', idempotencyMiddleware({ store, ttlMs: 24 * 60 * 60 * 1000, inFlight: { strategy: 'wait', waitTimeoutMs: 3000, pollMs: 100 }, replay: { headerWhitelist: ['location'] } }), async (req, res) => { const orderId = 'ord_' + Math.random().toString(36).slice(2); res.setHeader('Location', `/orders/${orderId}`); res.status(201).json({ orderId }); } ); app.listen(3000);
Debug
Known footguns
breakingESM-only package: require() throws ERR_REQUIRE_ESM
gotchaMemoryStore does not persist across server restarts; use Redis or Postgres store in production
gotchaIdempotency-Key is case-sensitive and must be a string; omit or empty key with requireKey:false returns 400
deprecatedNode.js <18 is not supported; engines field specifies >=18.0.0
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
11 hits · last 30 days
gptbot
4
ahrefsbot
4
script
1
Resources