import { parse } from 'yaml'; import fs from 'fs'; import path from 'path'; import os from 'os'; const HEXASYNC_CONNECTOR_CONFIG = path.join( os.homedir(), 'hexasync/connectorConfig', ); export interface IConnector { name: string; slug: string; tags?: Array; description?: string; connectorId: string; } export interface IConnection { id: string; name: string; description?: string; providerId: string; } export function getConnectorConfig(): any { try { if (!fs.existsSync(HEXASYNC_CONNECTOR_CONFIG)) { fs.writeFileSync(HEXASYNC_CONNECTOR_CONFIG, 'connectors: []', 'utf-8'); } const fileContent = fs.readFileSync(HEXASYNC_CONNECTOR_CONFIG, 'utf-8'); const cfg = parse(fileContent) as { connectors: IConnector[] }; if (!cfg.connectors || !Array.isArray(cfg.connectors)) { throw new Error('Invalid connector configuration format.'); } return cfg; } catch (error) { console.error('Error reading connector configuration:', error); return { connectors: [] }; } } export function getConnectors(): Array { let cfg = getConnectorConfig(); return cfg['connectors']; } // export const getConnectors = (): Array => [ // { // name: "Authorized API", // slug: "aapi", // connectorId: "34cd201a-4565-49ef-a35f-19a655e17568", // }, // { // name: "BigCommerce", // slug: "bcm", // connectorId: "1d887e81-8cf1-4843-a456-7a279a05a7e5", // }, // { // name: "MariaDB", // tags: ["Mysql", "MariaDB"], // slug: "madb", // connectorId: "45d975c1-c973-40fb-bc9b-c552ccf1d939", // }, // { // name: "MySQL", // slug: "mdb", // connectorId: "c7c439c6-162b-40b8-a3d8-3417a8f907b1", // }, // { // name: "SQLServer", // tags: ["Microsoft SQL Server"], // slug: "msdb", // connectorId: "617ab38b-1118-45ce-a08b-3988860c4f1e", // }, // { // name: "Postgres", // slug: "pgdb", // connectorId: "c77e1450-9cc2-4dd8-9e80-ce12de4abceb", // }, // { // name: "Anonymous API", // tags: ["anonymous", "generic", "unauthorized"], // slug: "anoapi", // connectorId: "a387242b-024b-402f-a828-d3c3f6bf01c9", // }, // { // name: "Basic Authentication API", // slug: "bapi", // connectorId: "bd8077be-803b-4259-9ee6-87cb21877e83", // }, // { // name: "Google Sheets", // slug: "ggsheet", // connectorId: "8f70c5df-797a-4b3c-97a3-1afdcdb36c81", // }, // { // name: "Haravan", // slug: "hrv", // connectorId: "934de5d2-8b4a-4dda-a50f-15da79dd5984", // }, // { // name: "SapoOmni", // slug: "spo", // connectorId: "9d7358e1-97dc-45f0-a631-29db28e612ea", // }, // { // name: "Hubspot", // slug: "hp", // connectorId: "32a1263d-a0e9-4fed-9d40-11bf5eef9560", // }, // { // name: "KiotViet", // slug: "kv", // connectorId: "90dd6d06-46e4-474f-9f41-442ed71ac70e", // }, // { // name: "Microsoft Dynamics 365", // slug: "ms365", // connectorId: "40ab4cff-1885-41f8-84a7-a35a25b26bcb", // }, // { // name: "Microsoft Dynamics 365 Business Central", // slug: "msdbc", // connectorId: "7c43ebf7-ac78-4b1a-8792-2e1d77eed629", // }, // { // name: "Microsoft Dynamics 365 Finance & Operations", // slug: "msdfo", // connectorId: "10eb17bd-0afc-4fc2-b5b1-8ac83ac01d6d", // }, // { // name: "Misa AMIS", // slug: "misaa", // connectorId: "391e049f-310c-4236-8f63-c18edb935e3c", // }, // { // name: "Bravo ERP", // slug: "bravo", // tags: ["bravo", "erp"], // connectorId: "bce670ea-adc8-4c6d-b458-47cb6ef92ace", // }, // { // name: "Acumatica Basic Authentication", // slug: "acumatica", // tags: ["acumatica", "basic", "authentication"], // connectorId: "a68d1264-8460-43f0-9eff-38c1a2c23987", // }, // { // name: "Quickbooks Online", // slug: "qbo", // tags: ["quickbooks", "qbo", "onl", "online"], // connectorId: "2a6cd7a5-4c41-4c50-88e6-5d5a3dda421a", // }, // { // name: "Shopee", // slug: "spe", // connectorId: "d63fd5a7-b062-450e-ac7c-a1b246aed768", // }, // { // name: "Shopify", // tags: ["spf"], // slug: "spf", // connectorId: "5fc11272-2212-4ea4-939d-21a00d585fd8", // }, // { // name: "Shopify Basic", // description: "Connect to Shopify using Access Token", // tags: ["spf"], // slug: "spf", // connectorId: "38eaceb7-1a6e-4a78-ae75-79f6783f0bd2", // }, // { // name: "Tiktokshop", // tags: ["tts"], // slug: "tts", // connectorId: "3d3a2fa0-9b76-475f-88cd-799d6a2cc643", // }, // { // name: "Magento 2x", // tags: ["Magento"], // slug: "mgt", // connectorId: "aeea9834-ace4-4ddb-8e3b-fdb44aca34e0", // }, // { // name: "Lazada", // slug: "lzd", // connectorId: "1d97c436-19d4-48dd-868a-3000cf5b7a0b", // }, // ]; export function getConnectorById(connectorId: string): IConnector | null { return getConnectors().find((x) => x.connectorId === connectorId) || null; }