Update idempotency key handling in edge functions

Read idempotency key from headers in process-selective-approval and process-selective-rejection, remove it from request bodies, add header validation, and redeploy edge functions to fix idempotency flow.
This commit is contained in:
gpt-engineer-app[bot]
2025-11-11 02:43:51 +00:00
parent 7642ac435b
commit 60c749c715
2 changed files with 32 additions and 4 deletions

View File

@@ -45,7 +45,6 @@ console.log('Edge function initialized successfully', {
interface ApprovalRequest {
submissionId: string;
itemIds: string[];
idempotencyKey: string;
}
// Main handler function
@@ -144,7 +143,22 @@ const handler = async (req: Request) => {
// STEP 2: Parse request
addSpanEvent(rootSpan, 'validation_start');
const body: ApprovalRequest = await req.json();
const { submissionId, itemIds, idempotencyKey } = body;
const { submissionId, itemIds } = body;
const idempotencyKey = req.headers.get('x-idempotency-key');
if (!idempotencyKey) {
addSpanEvent(rootSpan, 'validation_failed', { reason: 'missing_idempotency_key' });
edgeLogger.warn('Missing idempotency key', { requestId });
endSpan(rootSpan, 'error');
logSpan(rootSpan);
return new Response(
JSON.stringify({ error: 'Missing X-Idempotency-Key header' }),
{
status: 400,
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
}
);
}
if (!submissionId || !itemIds || itemIds.length === 0) {
addSpanEvent(rootSpan, 'validation_failed', {