
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
idempotency-client
Advanced tools
Generic idempotency key manager with IndexedDB storage for frontend apps
This document explains how to use the IdempotencyStore
class in the frontend. This class is designed to help manage and persist idempotency keys and responses locally (e.g., in IndexedDB) to avoid duplicate submissions or calls.
Idempotency means that repeating the same action multiple times will always result in the same outcome. In frontend applications, this ensures that retrying a request (like submitting a form) won’t cause duplication.
This utility is useful for cases like:
This library is compatible with the backend Idempotency Middleware, which ensures that the same request is processed only once and returns the same result. Read the Backend Guide
npm install idempotency-client
UUID()
- generates a unique identifierCreateKey(requestId: string, ttlMs?: number): Promise<string>
Creates a new idempotency key for a request, with optional TTL.
GetKey(requestId: string): Promise<string | null>
Returns the stored key for the given request if it's not expired.
SaveResponse(requestId: string, responseData: any): Promise<void>
Saves the response data associated with the requestId.
GetResponse(requestId: string): Promise<any>
Retrieves cached response data if it exists.
Clear(requestId: string): Promise<void>
Deletes the stored key and response for the given requestId.
ExportStore(): Promise<string>
Exports all saved data as JSON (useful for backup).
ImportStore(jsonData: string): Promise<void>
Restores data from a JSON string.
AutoCleanup(thresholdMs?: number): Promise<void>
Removes expired entries automatically (default is 7 days).
import IdempotencyStore from 'idempotency-client';
async function handleFormSubmit() {
const requestId = 'submit::formA';
const key = await IdempotencyStore.CreateKey(requestId, 60000);
const existing = await IdempotencyStore.GetResponse(requestId);
if (existing) {
renderFromCache(existing);
return;
}
const response = await fetch('/api/submit', {
method: 'POST',
headers: { 'Idempotency-Key': key },
body: JSON.stringify(data)
});
const result = await response.json();
await IdempotencyStore.SaveResponse(requestId, result);
renderResponse(result);
}
requestId
should uniquely represent the logical request.AutoCleanup()
periodically to prevent storage bloat.This store is a reliable, frontend-safe mechanism for caching request outcomes and safely retrying operations without duplication.
FAQs
Generic idempotency key manager with IndexedDB storage for frontend apps
We found that idempotency-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.