mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:51:14 -05:00
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:
@@ -45,7 +45,6 @@ console.log('Edge function initialized successfully', {
|
|||||||
interface ApprovalRequest {
|
interface ApprovalRequest {
|
||||||
submissionId: string;
|
submissionId: string;
|
||||||
itemIds: string[];
|
itemIds: string[];
|
||||||
idempotencyKey: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main handler function
|
// Main handler function
|
||||||
@@ -144,7 +143,22 @@ const handler = async (req: Request) => {
|
|||||||
// STEP 2: Parse request
|
// STEP 2: Parse request
|
||||||
addSpanEvent(rootSpan, 'validation_start');
|
addSpanEvent(rootSpan, 'validation_start');
|
||||||
const body: ApprovalRequest = await req.json();
|
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) {
|
if (!submissionId || !itemIds || itemIds.length === 0) {
|
||||||
addSpanEvent(rootSpan, 'validation_failed', {
|
addSpanEvent(rootSpan, 'validation_failed', {
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ interface RejectionRequest {
|
|||||||
submissionId: string;
|
submissionId: string;
|
||||||
itemIds: string[];
|
itemIds: string[];
|
||||||
rejectionReason: string;
|
rejectionReason: string;
|
||||||
idempotencyKey: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main handler function
|
// Main handler function
|
||||||
@@ -107,7 +106,22 @@ const handler = async (req: Request) => {
|
|||||||
// STEP 2: Parse request
|
// STEP 2: Parse request
|
||||||
addSpanEvent(rootSpan, 'validation_start');
|
addSpanEvent(rootSpan, 'validation_start');
|
||||||
const body: RejectionRequest = await req.json();
|
const body: RejectionRequest = await req.json();
|
||||||
const { submissionId, itemIds, rejectionReason, idempotencyKey } = body;
|
const { submissionId, itemIds, rejectionReason } = 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 || !rejectionReason) {
|
if (!submissionId || !itemIds || itemIds.length === 0 || !rejectionReason) {
|
||||||
addSpanEvent(rootSpan, 'validation_failed', {
|
addSpanEvent(rootSpan, 'validation_failed', {
|
||||||
|
|||||||
Reference in New Issue
Block a user