{"version":3,"file":"uploadDataFlowsFromCsv-ChGxrbgU.mjs","names":[],"sources":["../src/lib/consent-manager/uploadDataFlowsFromCsv.ts"],"sourcesContent":["import { ConsentTrackerStatus } from '@transcend-io/privacy-types';\nimport { buildTranscendGraphQLClient, syncDataFlows } from '@transcend-io/sdk';\nimport { splitCsvToList } from '@transcend-io/utils';\nimport colors from 'colors';\n\nimport { DataFlowInput, DataFlowCsvInput } from '../../codecs.js';\nimport { DEFAULT_TRANSCEND_API } from '../../constants.js';\nimport { logger } from '../../logger.js';\nimport { readCsv } from '../requests/readCsv.js';\n\nconst OMIT_COLUMNS = [\n  'ID',\n  'Activity',\n  'Encounters',\n  'Last Seen At',\n  'Has Native Do Not Sell/Share Support',\n  'IAB USP API Support',\n  'Service Description',\n  'Website URL',\n  'Categories of Recipients',\n];\n\n/**\n * Upload a set of data flows from CSV\n *\n * @param options - Options\n */\nexport async function uploadDataFlowsFromCsv({\n  auth,\n  trackerStatus,\n  file,\n  classifyService = false,\n  transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n  /** CSV file path */\n  file: string;\n  /** Transcend API key authentication */\n  auth: string;\n  /** Sombra API key authentication */\n  trackerStatus: ConsentTrackerStatus;\n  /** classify data flow service if missing */\n  classifyService?: boolean;\n  /** API URL for Transcend backend */\n  transcendUrl?: string;\n}): Promise<void> {\n  // Build a GraphQL client\n  const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n  // Read from CSV the set of data flow inputs\n  logger.info(colors.magenta(`Reading \"${file}\" from disk`));\n  const dataFlowInputs = readCsv(file, DataFlowCsvInput);\n\n  // Convert these data flow inputs into a format that the other function can use\n  const validatedDataFlowInputs = dataFlowInputs.map(\n    ({\n      Type,\n      Notes,\n      // TODO: https://transcend.height.app/T-26391 - export in CSV\n      // eslint-disable-next-line @typescript-eslint/no-unused-vars\n      Service,\n      Purpose,\n      Status,\n      Owners,\n      Teams,\n      'Connections Made To': value,\n      ...rest\n    }): DataFlowInput => ({\n      value,\n      type: Type,\n      description: Notes,\n      trackingPurposes: splitCsvToList(Purpose),\n      // TODO: https://transcend.height.app/T-26391\n      // service: Service,\n      // Apply the trackerStatus to all values in the CSV -> allows for customer to define tracker status\n      // on a row by row basis if needed\n      status: Status || trackerStatus,\n      owners: Owners ? splitCsvToList(Owners) : undefined,\n      teams: Teams ? splitCsvToList(Teams) : undefined,\n      // all remaining options are attribute\n      attributes: Object.entries(rest)\n        // filter out native columns that are exported from the admin dashboard\n        // but not custom attributes\n        .filter(([key]) => !OMIT_COLUMNS.includes(key))\n        .map(([key, value]) => ({\n          key,\n          values: splitCsvToList(value),\n        })),\n    }),\n  );\n\n  // Upload the data flows into Transcend dashboard\n  const syncedDataFlows = await syncDataFlows(client, validatedDataFlowInputs, {\n    classifyService,\n    logger,\n  });\n\n  // Log errors\n  if (!syncedDataFlows) {\n    logger.error(\n      colors.red(\n        'Encountered error(s) syncing data flows from CSV, see logs above for more info. ',\n      ),\n    );\n    process.exit(1);\n  }\n}\n"],"mappings":"qUAUA,MAAM,EAAe,CACnB,KACA,WACA,aACA,eACA,uCACA,sBACA,sBACA,cACA,2BACD,CAOD,eAAsB,EAAuB,CAC3C,OACA,gBACA,OACA,kBAAkB,GAClB,eAAe,GAYC,CAEhB,IAAM,EAAS,EAA4B,EAAc,EAAK,CAG9D,EAAO,KAAK,EAAO,QAAQ,YAAY,EAAK,aAAa,CAAC,CAgDrD,MANyB,EAAc,EAzCrB,EAAQ,EAAM,EAGS,CAAC,KAC5C,CACC,OACA,QAGA,UACA,UACA,SACA,SACA,QACA,sBAAuB,EACvB,GAAG,MACiB,CACpB,QACA,KAAM,EACN,YAAa,EACb,iBAAkB,EAAe,EAAQ,CAKzC,OAAQ,GAAU,EAClB,OAAQ,EAAS,EAAe,EAAO,CAAG,IAAA,GAC1C,MAAO,EAAQ,EAAe,EAAM,CAAG,IAAA,GAEvC,WAAY,OAAO,QAAQ,EAAK,CAG7B,QAAQ,CAAC,KAAS,CAAC,EAAa,SAAS,EAAI,CAAC,CAC9C,KAAK,CAAC,EAAK,MAAY,CACtB,MACA,OAAQ,EAAe,EAAM,CAC9B,EAAE,CACN,EAIwE,CAAE,CAC3E,kBACA,SACD,CAAC,GAIA,EAAO,MACL,EAAO,IACL,mFACD,CACF,CACD,QAAQ,KAAK,EAAE"}