* Collect all integration entries from block definitions and write integrations.json * to the shared integrations data directory (`apps/sim/lib/integrations`). * Applies the same visibility filters as the docs generation pipeline.
(iconMapping: Record<string, string>)
| 767 | * Applies the same visibility filters as the docs generation pipeline. |
| 768 | */ |
| 769 | async function writeIntegrationsJson(iconMapping: Record<string, string>): Promise<void> { |
| 770 | try { |
| 771 | if (!fs.existsSync(INTEGRATIONS_DATA_PATH)) { |
| 772 | fs.mkdirSync(INTEGRATIONS_DATA_PATH, { recursive: true }) |
| 773 | } |
| 774 | |
| 775 | const triggerRegistry = await buildTriggerRegistry() |
| 776 | const { desc: toolDescMap, name: toolNameMap } = await buildToolDescriptionMap() |
| 777 | |
| 778 | // Hand-authored, integration-specific landing content (install walkthrough, |
| 779 | // privacy blurb), keyed by slug. Imported as pure data — its only import is |
| 780 | // type-only and erased at runtime — and baked into the entries below so the |
| 781 | // landing page reads a single source instead of augmenting at render time. |
| 782 | const landingContentModule = await import( |
| 783 | pathToFileURL(path.join(LANDING_INTEGRATIONS_DATA_PATH, 'landing-content.ts')).href |
| 784 | ) |
| 785 | const landingContentMap = (landingContentModule.INTEGRATION_LANDING_CONTENT ?? {}) as Record< |
| 786 | string, |
| 787 | Record<string, unknown> |
| 788 | > |
| 789 | |
| 790 | const integrations: IntegrationEntry[] = [] |
| 791 | const seenBaseTypes = new Set<string>() |
| 792 | const blockFiles = (await glob(`${BLOCKS_PATH}/*.ts`)).sort() |
| 793 | |
| 794 | for (const blockFile of blockFiles) { |
| 795 | const fileContent = fs.readFileSync(blockFile, 'utf-8') |
| 796 | const switchCaseMap = extractSwitchCaseToolMapping(fileContent) |
| 797 | const configs = extractAllBlockConfigs(fileContent) |
| 798 | |
| 799 | for (const config of configs) { |
| 800 | const blockType = config.type |
| 801 | |
| 802 | // Canonical integrations filter: only third-party tool blocks visible in the toolbar. |
| 803 | // `isIntegrationBlock` is the single source of truth for "is integration". |
| 804 | if (!isIntegrationBlock(config)) continue |
| 805 | |
| 806 | // Every tools-category block MUST declare an `integrationType` from the canonical |
| 807 | // 16-value enum (apps/sim/blocks/types.ts). Fail loudly so the catalog never |
| 808 | // ships a tool without a category bucket. |
| 809 | if (!config.integrationType) { |
| 810 | throw new Error( |
| 811 | `Block "${blockType}" has \`category: 'tools'\` but is missing required \`integrationType\`. ` + |
| 812 | `Add one of the IntegrationType values from apps/sim/blocks/types.ts.` |
| 813 | ) |
| 814 | } |
| 815 | if (!INTEGRATION_CATEGORY_VALUES.has(config.integrationType as IntegrationType)) { |
| 816 | throw new Error( |
| 817 | `Block "${blockType}" has unrecognised \`integrationType: "${config.integrationType}"\`. ` + |
| 818 | `Use one of: ${[...INTEGRATION_CATEGORY_VALUES].join(', ')}.` |
| 819 | ) |
| 820 | } |
| 821 | const integrationType = config.integrationType as IntegrationType |
| 822 | |
| 823 | // Deduplicate by stripped base type |
| 824 | const baseType = stripVersionSuffix(blockType) |
| 825 | if (seenBaseTypes.has(baseType)) continue |
| 826 | seenBaseTypes.add(baseType) |
no test coverage detected