{"version":3,"file":"impl-BnzPrDmM.mjs","names":[],"sources":["../src/commands/inventory/consent-manager-service-json-to-yml/impl.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\n\nimport { ConsentTrackerStatus, DataFlowScope } from '@transcend-io/privacy-types';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport colors from 'colors';\nimport * as t from 'io-ts';\n\nimport { ConsentManagerServiceMetadata, CookieInput, DataFlowInput } from '../../../codecs.js';\nimport type { LocalContext } from '../../../context.js';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation.js';\nimport { writeTranscendYaml } from '../../../lib/readTranscendYaml.js';\nimport { logger } from '../../../logger.js';\n\nexport interface ConsentManagerServiceJsonToYmlCommandFlags {\n  file: string;\n  output: string;\n}\n\nexport function consentManagerServiceJsonToYml(\n  this: LocalContext,\n  { file, output }: ConsentManagerServiceJsonToYmlCommandFlags,\n): void {\n  doneInputValidation(this.process.exit);\n\n  // Ensure files exist\n  if (!existsSync(file)) {\n    logger.error(colors.red(`File does not exist: --file=\"${file}\"`));\n    this.process.exit(1);\n  }\n\n  // Read in each consent manager configuration\n  const services = decodeCodec(t.array(ConsentManagerServiceMetadata), readFileSync(file, 'utf-8'));\n\n  // Create data flows and cookie configurations\n  const dataFlows: DataFlowInput[] = [];\n  const cookies: CookieInput[] = [];\n  services.forEach((service) => {\n    service.dataFlows\n      .filter(({ type }) => type !== DataFlowScope.CSP)\n      .forEach((dataFlow) => {\n        dataFlows.push({\n          value: dataFlow.value,\n          type: dataFlow.type,\n          status: ConsentTrackerStatus.Live,\n          trackingPurposes: dataFlow.trackingPurposes,\n        });\n      });\n\n    service.cookies.forEach((cookie) => {\n      cookies.push({\n        name: cookie.name,\n        status: ConsentTrackerStatus.Live,\n        trackingPurposes: cookie.trackingPurposes,\n      });\n    });\n  });\n\n  // write to disk\n  writeTranscendYaml(output, {\n    'data-flows': dataFlows,\n    cookies,\n  });\n\n  logger.info(\n    colors.green(\n      `Successfully wrote ${dataFlows.length} data flows and ${cookies.length} cookies to file \"${output}\"`,\n    ),\n  );\n}\n"],"mappings":"obAkBA,SAAgB,EAEd,CAAE,OAAM,UACF,CACN,EAAoB,KAAK,QAAQ,KAAK,CAGjC,EAAW,EAAK,GACnB,EAAO,MAAM,EAAO,IAAI,gCAAgC,EAAK,GAAG,CAAC,CACjE,KAAK,QAAQ,KAAK,EAAE,EAItB,IAAM,EAAW,EAAY,EAAE,MAAM,EAA8B,CAAE,EAAa,EAAM,QAAQ,CAAC,CAG3F,EAA6B,EAAE,CAC/B,EAAyB,EAAE,CACjC,EAAS,QAAS,GAAY,CAC5B,EAAQ,UACL,QAAQ,CAAE,UAAW,IAAS,EAAc,IAAI,CAChD,QAAS,GAAa,CACrB,EAAU,KAAK,CACb,MAAO,EAAS,MAChB,KAAM,EAAS,KACf,OAAQ,EAAqB,KAC7B,iBAAkB,EAAS,iBAC5B,CAAC,EACF,CAEJ,EAAQ,QAAQ,QAAS,GAAW,CAClC,EAAQ,KAAK,CACX,KAAM,EAAO,KACb,OAAQ,EAAqB,KAC7B,iBAAkB,EAAO,iBAC1B,CAAC,EACF,EACF,CAGF,EAAmB,EAAQ,CACzB,aAAc,EACd,UACD,CAAC,CAEF,EAAO,KACL,EAAO,MACL,sBAAsB,EAAU,OAAO,kBAAkB,EAAQ,OAAO,oBAAoB,EAAO,GACpG,CACF"}