/home/techb158/cosmic-risk.abdallabala.com/src/lib
Edit: /home/techb158/cosmic-risk.abdallabala.com/src/lib/idempotency.js (570B)
const { redisGet, redisSet } = require('./redis');
const TTL_MS = 86_400_000;
async function withIdempotency(key, handler) {
if (!key) return handler();
const existing = await redisGet(`idemp:${key}`);
if (existing) return JSON.parse(existing);
const result = await handler();
await redisSet(`idemp:${key}`, JSON.stringify(result), TTL_MS);
return result;
}
function getIdempotencyKey(request) {
return request.headers.get("Idempotency-Key") || request.headers.get("idempotency-key") || null;
}
module.exports = { withIdempotency, getIdempotencyKey };