import { readFile, writeFile } from "node:fs/promises"; // Extend the AP syndicator checkin guard to cover both `location` and // `checkin` properties. The upstream package only checks `location`; a // checkin coming in without coordinates (no `location` property) would slip // through. This patch makes both cases explicit. const candidates = [ "node_modules/@rmdes/indiekit-endpoint-activitypub/lib/syndicator.js", ]; const oldSnippet = ` // Skip location checkins — they have a JF2 \`location\` property. if (properties.location) { console.info(\`[ActivityPub] Skipping syndication for location checkin: \${properties.url}\`); return undefined; }`; const newSnippet = ` // Skip location checkins — they have a JF2 \`location\` or \`checkin\` property. if (properties.location || properties.checkin) { console.info(\`[ActivityPub] Skipping syndication for location checkin: \${properties.url}\`); return undefined; }`; for (const filePath of candidates) { let source; try { source = await readFile(filePath, "utf8"); } catch { console.log(`[postinstall] patch-ap-syndicator-checkin-guard: ${filePath} not found, skipping`); continue; } if (source.includes("properties.checkin")) { console.log("[postinstall] patch-ap-syndicator-checkin-guard: already patched"); continue; } if (!source.includes(oldSnippet)) { console.log("[postinstall] patch-ap-syndicator-checkin-guard: target snippet not found, skipping"); continue; } await writeFile(filePath, source.replace(oldSnippet, newSnippet), "utf8"); console.log("[postinstall] patch-ap-syndicator-checkin-guard: patched syndicator.js"); }