{"version":3,"file":"dataFlowsToDataSilos-DRuAfwIn.mjs","names":[],"sources":["../src/lib/consent-manager/dataFlowsToDataSilos.ts"],"sourcesContent":["import { type IndexedCatalogs } from '@transcend-io/sdk';\nimport { union } from 'lodash-es';\n\nimport { DataFlowInput, DataSiloInput } from '../../codecs.js';\n\n/**\n * Convert data flow configurations into a set of data silo configurations\n *\n * @param inputs - Data flow input to convert to data silos\n * @param options - Additional options\n * @returns Business entity configuration input\n */\nexport function dataFlowsToDataSilos(\n  inputs: DataFlowInput[],\n  {\n    adTechPurposes = ['SaleOfInfo'],\n    serviceToTitle,\n    serviceToSupportedIntegration,\n  }: IndexedCatalogs & {\n    /** List of purposes that are considered \"Ad Tech\"  */\n    adTechPurposes?: string[];\n  },\n): {\n  /** List of data silo configurations for site-tech services */\n  siteTechDataSilos: DataSiloInput[];\n  /** List of data silo configurations for ad-tech services */\n  adTechDataSilos: DataSiloInput[];\n} {\n  // List of site tech integrations\n  let siteTechIntegrations: string[] = [];\n\n  // List of ad tech integrations\n  const adTechIntegrations: string[] = [];\n\n  // Mapping from service name to list of\n  const serviceToFoundOnDomain: { [k in string]: string[] } = {};\n\n  // iterate over each flow\n  inputs.forEach((flow) => {\n    // process data flows with services\n    const { service, attributes = [] } = flow;\n    if (!service || service === 'internalService') {\n      return;\n    }\n\n    // create mapping to found on domain\n    const foundOnDomain = attributes.find((attr) => attr.key === 'Found on Domain');\n\n    // Create a list of all domains where the data flow was found\n    if (foundOnDomain) {\n      if (!serviceToFoundOnDomain[service]) {\n        serviceToFoundOnDomain[service] = [];\n      }\n      serviceToFoundOnDomain[service]!.push(\n        ...foundOnDomain.values.map((v) => v.replace('https://', '').replace('http://', '')),\n      );\n      serviceToFoundOnDomain[service] = [...new Set(serviceToFoundOnDomain[service])];\n    }\n\n    // Keep track of ad tech\n    if (union(flow.trackingPurposes, adTechPurposes).length > 0) {\n      // add service to ad tech list\n      adTechIntegrations.push(service);\n\n      // remove from site tech list\n      if (siteTechIntegrations.includes(service)) {\n        siteTechIntegrations = siteTechIntegrations.filter((s) => s !== service);\n      }\n    } else if (!adTechIntegrations.includes(service)) {\n      // add to site tech list\n      siteTechIntegrations.push(service);\n    }\n  });\n\n  // create the list of ad tech integrations\n  const adTechDataSilos = [...new Set(adTechIntegrations)].map((service) => ({\n    title: serviceToTitle[service],\n    ...(serviceToSupportedIntegration[service]\n      ? { integrationName: service }\n      : { integrationName: 'promptAPerson', 'outer-type': service }),\n    attributes: [\n      {\n        key: 'Tech Type',\n        values: ['Ad Tech'],\n      },\n      {\n        key: 'Found On Domain',\n        values: serviceToFoundOnDomain[service] || [],\n      },\n    ],\n  }));\n\n  // create the list of site tech integrations\n  const siteTechDataSilos = [...new Set(siteTechIntegrations)].map((service) => ({\n    title: serviceToTitle[service],\n    ...(serviceToSupportedIntegration[service]\n      ? { integrationName: service }\n      : { integrationName: 'promptAPerson', outerType: service }),\n    attributes: [\n      {\n        key: 'Tech Type',\n        values: ['Site Tech'],\n      },\n      {\n        key: 'Found On Domain',\n        values: serviceToFoundOnDomain[service] || [],\n      },\n    ],\n  }));\n\n  return {\n    siteTechDataSilos,\n    adTechDataSilos,\n  };\n}\n"],"mappings":"kCAYA,SAAgB,EACd,EACA,CACE,iBAAiB,CAAC,aAAa,CAC/B,iBACA,iCAUF,CAEA,IAAI,EAAiC,EAAE,CAGjC,EAA+B,EAAE,CAGjC,EAAsD,EAAE,CAG9D,EAAO,QAAS,GAAS,CAEvB,GAAM,CAAE,UAAS,aAAa,EAAE,EAAK,EACrC,GAAI,CAAC,GAAW,IAAY,kBAC1B,OAIF,IAAM,EAAgB,EAAW,KAAM,GAAS,EAAK,MAAQ,kBAAkB,CAG3E,IACG,EAAuB,KAC1B,EAAuB,GAAW,EAAE,EAEtC,EAAuB,GAAU,KAC/B,GAAG,EAAc,OAAO,IAAK,GAAM,EAAE,QAAQ,WAAY,GAAG,CAAC,QAAQ,UAAW,GAAG,CAAC,CACrF,CACD,EAAuB,GAAW,CAAC,GAAG,IA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