import axios from "axios";
const FIGMA_API_BASE = "https://api.figma.com/v1";
/** Fetch a Figma document */
export async function fetchFigmaFile(fileKey, node, token) {
// Figma URLs use '-' but API expects ':'
const NODE_ID = node.replace(/-/g, ':');
console.error(`[DEBUG] Fetching node: ${NODE_ID} from file: ${fileKey}`);
console.error(`[DEBUG] Token present: ${!!token}`);
const res = await axios.get(`${FIGMA_API_BASE}/files/${fileKey}/nodes?ids=${node}`, {
headers: { "X-Figma-Token": token },
});
console.error(`[DEBUG] API Status: ${res.status}`);
console.error(`[DEBUG] Received ${res.data.nodes[NODE_ID].document.children.length} top-level frames`);
return res.data.nodes[NODE_ID].document.children;
}