(
fileId: string,
nodeIds: string,
token: string,
format?: FigmaImageFormat
)
| 35 | * @returns Figma image |
| 36 | */ |
| 37 | export const fetchFigmaImages = async ( |
| 38 | fileId: string, |
| 39 | nodeIds: string, |
| 40 | token: string, |
| 41 | format?: FigmaImageFormat |
| 42 | ): Promise<Record<string, string>> => { |
| 43 | const url = `https://api.figma.com/v1/images/${fileId}`; |
| 44 | try { |
| 45 | const data = await get<{ images: Record<string, string> }>(url, { |
| 46 | headers: { |
| 47 | 'X-Figma-Token': token, |
| 48 | }, |
| 49 | params: { |
| 50 | ids: nodeIds, |
| 51 | format: format || 'png', |
| 52 | }, |
| 53 | }); |
| 54 | const images = data.images || {}; |
| 55 | // format node id to match the format from response to request |
| 56 | return Object.fromEntries(Object.entries(images)); |
| 57 | } catch (error) { |
| 58 | logger.printErrorLog(`Failed to fetch Figma images: ${error instanceof Error ? error.message : 'Unknown error'}`); |
| 59 | return {}; |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | /** |
| 64 | * Clean Figma node and children. Remove invisible nodes and children. |
no outgoing calls
no test coverage detected