From 66c95217d5c68b3915ee4ba534f6496d7dbd7dfc Mon Sep 17 00:00:00 2001 From: Alex Patterson Date: Fri, 23 Oct 2026 14:53:38 -0400 Subject: [PATCH] fix(syndication): include Cookie header for AWS Builder and check existing syndication docs --- apps/sanity/functions/syndicate-content/index.ts | 1 + scripts/run-syndicate-post.mjs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/sanity/functions/syndicate-content/index.ts b/apps/sanity/functions/syndicate-content/index.ts index 7dccd510..0f3eb1da 100644 --- a/apps/sanity/functions/syndicate-content/index.ts +++ b/apps/sanity/functions/syndicate-content/index.ts @@ -560,6 +560,7 @@ export const handler = documentEventHandler( "Content-Type": "application/json", Accept: "application/json", "builder-session-token": awsSessionToken, + Cookie: `builder-session-token=${awsSessionToken}`, }; const existingSyndication = await client diff --git a/scripts/run-syndicate-post.mjs b/scripts/run-syndicate-post.mjs index bb9b91ff..25aa3492 100644 --- a/scripts/run-syndicate-post.mjs +++ b/scripts/run-syndicate-post.mjs @@ -318,6 +318,7 @@ async function run() { "Content-Type": "application/json", Accept: "application/json", "builder-session-token": awsSessionToken, + Cookie: `builder-session-token=${awsSessionToken}`, }; try { @@ -457,7 +458,11 @@ async function run() { // --- LINK SYNDICATION REFERENCES ON PARENT --- try { const platforms = ["devto", "hashnode", ...(shouldSyndicateAws ? ["awsbuilder"] : [])]; - const expectedRefs = platforms.map((p) => `syndication.${doc._id}.${p}`); + const candidateRefs = platforms.map((p) => `syndication.${doc._id}.${p}`); + const existingSynDocs = await Promise.all( + candidateRefs.map((ref) => client.getDocument(ref).catch(() => null)) + ); + const expectedRefs = candidateRefs.filter((_, idx) => Boolean(existingSynDocs[idx])); const latestDoc = await client.getDocument(doc._id); const existingRefs = (latestDoc?.syndications || []).map((s) => s._ref);