"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IdempotencyStore = void 0;
exports.deriveIdempotencyKey = deriveIdempotencyKey;
const crypto_1 = require("crypto");
function deriveIdempotencyKey(input) {
    const canonical = JSON.stringify({
        tenantId: input.tenantId,
        entityId: input.entityId,
        operation: input.operation,
        resourceId: input.resourceId ?? '',
        payload: input.payload ?? {},
    });
    return (0, crypto_1.createHash)('sha256').update(canonical).digest('hex');
}
class IdempotencyStore {
    keys = new Set();
    has(key) {
        return this.keys.has(key);
    }
    record(key) {
        if (this.keys.has(key))
            return false;
        this.keys.add(key);
        return true;
    }
}
exports.IdempotencyStore = IdempotencyStore;
