{"version":3,"file":"impl-BohgbWOH.mjs","names":[],"sources":["../src/commands/inventory/derive-data-silos-from-data-flows/impl.ts"],"sourcesContent":["import { existsSync, lstatSync } from 'node:fs';\nimport { join } from 'node:path';\n\nimport { buildTranscendGraphQLClient, fetchAndIndexCatalogs } from '@transcend-io/sdk';\nimport colors from 'colors';\n\nimport { DataFlowInput } from '../../../codecs.js';\nimport type { LocalContext } from '../../../context.js';\nimport { listFiles } from '../../../lib/api-keys/index.js';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation.js';\nimport { dataFlowsToDataSilos } from '../../../lib/consent-manager/dataFlowsToDataSilos.js';\nimport { readTranscendYaml, writeTranscendYaml } from '../../../lib/readTranscendYaml.js';\nimport { logger } from '../../../logger.js';\n\nexport interface DeriveDataSilosFromDataFlowsCommandFlags {\n  auth: string;\n  dataFlowsYmlFolder: string;\n  dataSilosYmlFolder: string;\n  ignoreYmls?: string[];\n  transcendUrl: string;\n}\n\nexport async function deriveDataSilosFromDataFlows(\n  this: LocalContext,\n  {\n    auth,\n    dataFlowsYmlFolder,\n    dataSilosYmlFolder,\n    ignoreYmls = [],\n    transcendUrl,\n  }: DeriveDataSilosFromDataFlowsCommandFlags,\n): Promise<void> {\n  doneInputValidation(this.process.exit);\n\n  // Ensure folder is passed\n  if (!existsSync(dataFlowsYmlFolder) || !lstatSync(dataFlowsYmlFolder).isDirectory()) {\n    logger.error(colors.red(`Folder does not exist: \"${dataFlowsYmlFolder}\"`));\n    this.process.exit(1);\n  }\n\n  // Ensure folder is passed\n  if (!existsSync(dataSilosYmlFolder) || !lstatSync(dataSilosYmlFolder).isDirectory()) {\n    logger.error(colors.red(`Folder does not exist: \"${dataSilosYmlFolder}\"`));\n    this.process.exit(1);\n  }\n\n  // Fetch all integrations in the catalog\n  const client = buildTranscendGraphQLClient(transcendUrl, auth);\n  const { serviceToTitle, serviceToSupportedIntegration } = await fetchAndIndexCatalogs(client, {\n    logger,\n  });\n\n  // List of each data flow yml file\n  listFiles(dataFlowsYmlFolder).forEach((directory) => {\n    // read in the data flows for a specific instance\n    const { 'data-flows': dataFlows = [] } = readTranscendYaml(join(dataFlowsYmlFolder, directory));\n\n    // map the data flows to data silos\n    const { adTechDataSilos, siteTechDataSilos } = dataFlowsToDataSilos(\n      dataFlows as DataFlowInput[],\n      {\n        serviceToSupportedIntegration,\n        serviceToTitle,\n      },\n    );\n\n    // combine and write to yml file\n    const dataSilos = [...adTechDataSilos, ...siteTechDataSilos];\n    logger.log(`Total Services: ${dataSilos.length}`);\n    logger.log(`Ad Tech Services: ${adTechDataSilos.length}`);\n    logger.log(`Site Tech Services: ${siteTechDataSilos.length}`);\n    writeTranscendYaml(join(dataSilosYmlFolder, directory), {\n      'data-silos': ignoreYmls.includes(directory) ? [] : dataSilos,\n    });\n  });\n}\n"],"mappings":"0cAsBA,eAAsB,EAEpB,CACE,OACA,qBACA,qBACA,aAAa,EAAE,CACf,gBAEa,CACf,EAAoB,KAAK,QAAQ,KAAK,EAGlC,CAAC,EAAW,EAAmB,EAAI,CAAC,EAAU,EAAmB,CAAC,aAAa,IACjF,EAAO,MAAM,EAAO,IAAI,2BAA2B,EAAmB,GAAG,CAAC,CAC1E,KAAK,QAAQ,KAAK,EAAE,GAIlB,CAAC,EAAW,EAAmB,EAAI,CAAC,EAAU,EAAmB,CAAC,aAAa,IACjF,EAAO,MAAM,EAAO,IAAI,2BAA2B,EAAmB,GAAG,CAAC,CAC1E,KAAK,QAAQ,KAAK,EAAE,EAKtB,GAAM,CAAE,iBAAgB,iCAAkC,MAAM,EADjD,EAA4B,EAAc,EACmC,CAAE,CAC5F,SACD,CAAC,CAGF,EAAU,EAAmB,CAAC,QAAS,GAAc,CAEnD,GAAM,CAAE,aAAc,EAAY,EAAE,EAAK,EAAkB,EAAK,EAAoB,EAAU,CAAC,CAGzF,CAAE,kBAAiB,qBAAsB,EAC7C,EACA,CACE,gCACA,iBACD,CACF,CAGK,EAAY,CAAC,GAAG,EAAiB,GAAG,EAAkB,CAC5D,EAAO,IAAI,mBAAmB,EAAU,SAAS,CACjD,EAAO,IAAI,qBAAqB,EAAgB,SAAS,CACzD,EAAO,IAAI,uBAAuB,EAAkB,SAAS,CAC7D,EAAmB,EAAK,EAAoB,EAAU,CAAE,CACtD,aAAc,EAAW,SAAS,EAAU,CAAG,EAAE,CAAG,EACrD,CAAC,EACF"}