| 10 | * @returns Figma frame information |
| 11 | */ |
| 12 | export const fetchFigmaNode = async (fileId: string, nodeId: string, token: string): Promise<FigmaFrameInfo | undefined> => { |
| 13 | const url = `https://api.figma.com/v1/files/${fileId}/nodes?ids=${nodeId}`; |
| 14 | try { |
| 15 | const data = await get<{ nodes: Record<string, { document: FigmaFrameInfo }> }>(url, { |
| 16 | headers: { |
| 17 | 'X-Figma-Token': token, |
| 18 | }, |
| 19 | }); |
| 20 | // format node id to match the format in the response |
| 21 | const resData = data.nodes?.[nodeId]; |
| 22 | return resData?.document; |
| 23 | } catch (error) { |
| 24 | logger.printErrorLog(`Failed to fetch Figma node: ${error instanceof Error ? error.message : 'Unknown error'}`); |
| 25 | return undefined; |
| 26 | } |
| 27 | }; |
| 28 | |
| 29 | /** |
| 30 | * Fetch Figma image by fileId and nodeId |