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C,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;gBAC/E,OAAO;oBACL,GAAG,MAAM;oBACT,uEAAuE;oBACvE,CAAC,IAAA,2BAAiB,EAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,4BAA4B,CAAC,GAAG,CAAC;iBACtE,CAAA;YACH,CAAC,EAAE,EAAE,CAAC;YACR,CAAC,CAAC,SAAS;KAChB,CAAC,CAAC,CAAA;AACL,CAAC","sourcesContent":["import { FigmaRestApi, getApiUrl, getDocument } from '../connect/figma_rest_api'\nimport {\n figmaUrlOfComponent,\n findComponentsInDocument,\n normalizePropName,\n parseFileKey,\n parseNodeIds,\n} from '../connect/helpers'\n\nexport interface ComponentInfo {\n id: string\n name: string\n fileKey: string\n figmaUrl: string\n}\n\nexport interface FigmaConnectClient {\n /**\n * Fetches components from a figma file, filtering out components that don't\n * match the provided function.\n *\n * @param fileOrNode figma URL\n * @param match a function that returns true if the component should be\n * included\n * @returns a list of components\n */\n getComponents: (fileOrNode: string) => Promise<(FigmaRestApi.Component & ComponentInfo)[]>\n}\n\nrequire('dotenv').config()\n\n/**\n * Fetch components from a figma file. If the `node-id` query parameter is used,\n * only components within those frames will be included. This is useful if your\n * file is very large, as this will speed up the query.\n *\n * @param fileOrNode a figma file URL\n * @param match a function that returns true if the component should be included\n * @returns\n */\nexport async function getComponents(fileOrNode: string) {\n if (!process.env.FIGMA_ACCESS_TOKEN) {\n throw new Error('FIGMA_ACCESS_TOKEN is not set')\n }\n\n const fileKey = parseFileKey(fileOrNode)\n if (!fileKey) {\n throw new Error(`Invalid Figma file URL: ${fileOrNode}, file key missing`)\n }\n\n const nodeIds = parseNodeIds([fileOrNode])\n let apiUrl = getApiUrl(fileOrNode ?? '') + `/files/${fileKey}`\n if (nodeIds.length > 0) {\n apiUrl += `?ids=${nodeIds.join(',')}`\n }\n\n const doc = await getDocument(apiUrl, process.env.FIGMA_ACCESS_TOKEN)\n\n // `doc` in this case will only include the top frame(s) passed via `ids`. We omit the\n // nodeIds arg here because we want to return all components within the frame(s)\n return findComponentsInDocument(doc).map((component) => ({\n ...component,\n fileKey,\n figmaUrl: figmaUrlOfComponent(component, fileKey),\n componentPropertyDefinitions:\n component.type === 'COMPONENT_SET'\n ? Object.keys(component.componentPropertyDefinitions || {}).reduce((result, key) => {\n return {\n ...result,\n // this removes the ID prefix from property names e.g #123:name -> name\n [normalizePropName(key)]: component.componentPropertyDefinitions[key],\n }\n }, {})\n : undefined,\n }))\n}\n"]}