← All packages

@lacspace/idempotency

v1.0.2Backend Kit0 deps

Make any operation exactly-once with an idempotency key — replay stored results on retries, safe under concurrency, with optional request fingerprinting. Framework-agnostic, pluggable store, zero-dependency, isomorphic.

npm i @lacspace/idempotency

Usage

idempotency.ts
import { idempotent } from "@lacspace/idempotency";

// in a POST handler — the client sends an Idempotency-Key header
const key = request.headers.get("idempotency-key")!;

const { value, replayed } = await idempotent(key, () => chargeCard(order));
// first request: runs chargeCard, stores the result   → replayed: false
// any retry with the same key: returns the SAME result → replayed: true (no second charge)

return Response.json(value);

Exports 7

IdempotencyIdempotencyConflictErrorIdempotencyKeyReuseErrorMemoryIdempotencyStoreReplayedErrorfingerprintidempotent

Keywords

idempotencyidempotency-keyidempotentexactly-oncededuplicationdedupe

More in Backend Kit