UNPKG

@eristack/idempotency

Version:

Idempotency-Key guard with Drizzle store, scoped keys, lease, Express/Nest/client adapters

34 lines (32 loc) • 1.08 kB
// src/core/errors.ts var IdempotencyConflictError = class extends Error { constructor(key) { super(`Idempotency key already in progress: ${key}`); this.key = key; this.name = "IdempotencyConflictError"; } key; code = "IDEMPOTENCY_CONFLICT"; }; var IdempotencyRequestMismatchError = class extends Error { constructor(key) { super(`Idempotency key reused with different request body: ${key}`); this.key = key; this.name = "IdempotencyRequestMismatchError"; } key; code = "IDEMPOTENCY_REQUEST_MISMATCH"; }; // src/core/request-hash.ts async function hashIdempotencyRequest(body) { const text = body === void 0 || body === null ? "" : typeof body === "string" ? body : JSON.stringify(body); const bytes = new TextEncoder().encode(text); const digest = await crypto.subtle.digest("SHA-256", bytes); return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join(""); } export { IdempotencyConflictError, IdempotencyRequestMismatchError, hashIdempotencyRequest }; //# sourceMappingURL=chunk-UR7ALJYJ.js.map