@transcend-io/cli 8.31.1 → 8.32.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -0
- package/dist/bin/bash-complete.cjs +1 -1
- package/dist/bin/cli.cjs +1 -1
- package/dist/bin/deprecated-command.cjs +2 -2
- package/dist/{chunk-M7OVJJGB.cjs → chunk-22KX2NM4.cjs} +4 -4
- package/dist/{chunk-M7OVJJGB.cjs.map → chunk-22KX2NM4.cjs.map} +1 -1
- package/dist/chunk-56QKBG2R.cjs +3001 -0
- package/dist/chunk-56QKBG2R.cjs.map +1 -0
- package/dist/chunk-6TKTYQIF.cjs +3 -0
- package/dist/chunk-6TKTYQIF.cjs.map +1 -0
- package/dist/{chunk-DIB7IOEX.cjs → chunk-BPOXNSPY.cjs} +2 -2
- package/dist/{chunk-DIB7IOEX.cjs.map → chunk-BPOXNSPY.cjs.map} +1 -1
- package/dist/chunk-CM7VJEOY.cjs +4 -0
- package/dist/{chunk-SKOTYI3A.cjs.map → chunk-CM7VJEOY.cjs.map} +1 -1
- package/dist/chunk-D3VRD5F5.cjs +2 -0
- package/dist/chunk-D3VRD5F5.cjs.map +1 -0
- package/dist/{chunk-XXFLFF7Q.cjs → chunk-DQCPGPXG.cjs} +2 -2
- package/dist/{chunk-XXFLFF7Q.cjs.map → chunk-DQCPGPXG.cjs.map} +1 -1
- package/dist/{chunk-MXT7N555.cjs → chunk-DYBVUGHH.cjs} +22 -22
- package/dist/chunk-DYBVUGHH.cjs.map +1 -0
- package/dist/chunk-IHUCIK5T.cjs +2 -0
- package/dist/{chunk-Q2RJZGYW.cjs.map → chunk-IHUCIK5T.cjs.map} +1 -1
- package/dist/{chunk-7H4ALAHC.cjs → chunk-LQUVB4MI.cjs} +4 -4
- package/dist/chunk-LQUVB4MI.cjs.map +1 -0
- package/dist/chunk-P5GD5LAK.cjs +2 -0
- package/dist/chunk-P5GD5LAK.cjs.map +1 -0
- package/dist/chunk-PGO2YKRX.cjs +12 -0
- package/dist/chunk-PGO2YKRX.cjs.map +1 -0
- package/dist/{chunk-ALOB5SWZ.cjs → chunk-VCPZG4FJ.cjs} +2 -2
- package/dist/{chunk-ALOB5SWZ.cjs.map → chunk-VCPZG4FJ.cjs.map} +1 -1
- package/dist/chunk-VUQAH7YK.cjs +12 -0
- package/dist/chunk-VUQAH7YK.cjs.map +1 -0
- package/dist/{impl-VXOHC45F.cjs → impl-2JA6BPE7.cjs} +2 -2
- package/dist/{impl-VXOHC45F.cjs.map → impl-2JA6BPE7.cjs.map} +1 -1
- package/dist/{impl-PKWSORXX.cjs → impl-4AI7T6RD.cjs} +2 -2
- package/dist/{impl-PKWSORXX.cjs.map → impl-4AI7T6RD.cjs.map} +1 -1
- package/dist/impl-4LAJNPQ4.cjs +16 -0
- package/dist/impl-4LAJNPQ4.cjs.map +1 -0
- package/dist/{impl-4CWCLU5Z.cjs → impl-4YFJOKCA.cjs} +2 -2
- package/dist/{impl-4CWCLU5Z.cjs.map → impl-4YFJOKCA.cjs.map} +1 -1
- package/dist/{impl-WMI46UXI.cjs → impl-5RX3NB6C.cjs} +2 -2
- package/dist/{impl-WMI46UXI.cjs.map → impl-5RX3NB6C.cjs.map} +1 -1
- package/dist/{impl-VUAC7AYF.cjs → impl-66CDS7IN.cjs} +2 -2
- package/dist/{impl-VUAC7AYF.cjs.map → impl-66CDS7IN.cjs.map} +1 -1
- package/dist/{impl-542SIWQ2.cjs → impl-ADPBEB3N.cjs} +2 -2
- package/dist/{impl-542SIWQ2.cjs.map → impl-ADPBEB3N.cjs.map} +1 -1
- package/dist/{impl-REKQO7ZI.cjs → impl-B6DTQRYV.cjs} +2 -2
- package/dist/{impl-REKQO7ZI.cjs.map → impl-B6DTQRYV.cjs.map} +1 -1
- package/dist/impl-BHA2L6BP.cjs +2 -0
- package/dist/{impl-V3MXFXZF.cjs.map → impl-BHA2L6BP.cjs.map} +1 -1
- package/dist/impl-BLGX7DMN.cjs +6 -0
- package/dist/impl-BLGX7DMN.cjs.map +1 -0
- package/dist/{impl-XJBUIDZP.cjs → impl-DA7AASRR.cjs} +2 -2
- package/dist/{impl-XJBUIDZP.cjs.map → impl-DA7AASRR.cjs.map} +1 -1
- package/dist/{impl-OQAP7YDW.cjs → impl-EXHOBCQW.cjs} +2 -2
- package/dist/{impl-OQAP7YDW.cjs.map → impl-EXHOBCQW.cjs.map} +1 -1
- package/dist/{impl-D2HENZNO.cjs → impl-FRWZLZ2V.cjs} +2 -2
- package/dist/{impl-D2HENZNO.cjs.map → impl-FRWZLZ2V.cjs.map} +1 -1
- package/dist/impl-GA6T4SCB.cjs +2 -0
- package/dist/impl-GA6T4SCB.cjs.map +1 -0
- package/dist/{impl-RD5UOJY6.cjs → impl-GG3S2VBT.cjs} +2 -2
- package/dist/{impl-RD5UOJY6.cjs.map → impl-GG3S2VBT.cjs.map} +1 -1
- package/dist/impl-GZNNNSYW.cjs +7 -0
- package/dist/{impl-BQNXMBQ4.cjs.map → impl-GZNNNSYW.cjs.map} +1 -1
- package/dist/{impl-5VMEZB7F.cjs → impl-IOS3QLTX.cjs} +2 -2
- package/dist/{impl-5VMEZB7F.cjs.map → impl-IOS3QLTX.cjs.map} +1 -1
- package/dist/{impl-PHBUSAGS.cjs → impl-IQGUF37H.cjs} +2 -2
- package/dist/{impl-PHBUSAGS.cjs.map → impl-IQGUF37H.cjs.map} +1 -1
- package/dist/impl-IZIXOMMN.cjs +2 -0
- package/dist/impl-IZIXOMMN.cjs.map +1 -0
- package/dist/{impl-VT3C6SP4.cjs → impl-J5PWNHKL.cjs} +2 -2
- package/dist/{impl-VT3C6SP4.cjs.map → impl-J5PWNHKL.cjs.map} +1 -1
- package/dist/impl-JI6COVDW.cjs +2 -0
- package/dist/{impl-SRI65ZIC.cjs.map → impl-JI6COVDW.cjs.map} +1 -1
- package/dist/{impl-XLL66FXK.cjs → impl-JY7YM3QH.cjs} +2 -2
- package/dist/{impl-XLL66FXK.cjs.map → impl-JY7YM3QH.cjs.map} +1 -1
- package/dist/{impl-YGVW4RTA.cjs → impl-LKX6OLE2.cjs} +2 -2
- package/dist/{impl-YGVW4RTA.cjs.map → impl-LKX6OLE2.cjs.map} +1 -1
- package/dist/impl-MRC5UI22.cjs +2 -0
- package/dist/impl-MRC5UI22.cjs.map +1 -0
- package/dist/{impl-KQYINEBI.cjs → impl-NW57RBBR.cjs} +2 -2
- package/dist/{impl-KQYINEBI.cjs.map → impl-NW57RBBR.cjs.map} +1 -1
- package/dist/impl-QOCEM2K5.cjs +2 -0
- package/dist/{impl-JSXYZHX4.cjs.map → impl-QOCEM2K5.cjs.map} +1 -1
- package/dist/{impl-K2D3GTZG.cjs → impl-QPLTL2SO.cjs} +2 -2
- package/dist/{impl-K2D3GTZG.cjs.map → impl-QPLTL2SO.cjs.map} +1 -1
- package/dist/impl-R35FW4U7.cjs +9 -0
- package/dist/impl-R35FW4U7.cjs.map +1 -0
- package/dist/{impl-6ANYWCOV.cjs → impl-RMPDHVAH.cjs} +2 -2
- package/dist/{impl-6ANYWCOV.cjs.map → impl-RMPDHVAH.cjs.map} +1 -1
- package/dist/{impl-JQVCW52V.cjs → impl-S64WVKSC.cjs} +2 -2
- package/dist/{impl-JQVCW52V.cjs.map → impl-S64WVKSC.cjs.map} +1 -1
- package/dist/{impl-55GTRVMZ.cjs → impl-SE32ARTN.cjs} +2 -2
- package/dist/{impl-55GTRVMZ.cjs.map → impl-SE32ARTN.cjs.map} +1 -1
- package/dist/{impl-PWYKAVK4.cjs → impl-SSBP4ONX.cjs} +2 -2
- package/dist/{impl-PWYKAVK4.cjs.map → impl-SSBP4ONX.cjs.map} +1 -1
- package/dist/{impl-T67PUM7X.cjs → impl-UA7V6YEM.cjs} +2 -2
- package/dist/{impl-T67PUM7X.cjs.map → impl-UA7V6YEM.cjs.map} +1 -1
- package/dist/{impl-NK42TN4C.cjs → impl-WTGAAEUZ.cjs} +2 -2
- package/dist/{impl-NK42TN4C.cjs.map → impl-WTGAAEUZ.cjs.map} +1 -1
- package/dist/{impl-Q3P6DGHG.cjs → impl-WVOFYJLG.cjs} +2 -2
- package/dist/{impl-Q3P6DGHG.cjs.map → impl-WVOFYJLG.cjs.map} +1 -1
- package/dist/{impl-TCR3Y3J2.cjs → impl-X23VUODX.cjs} +2 -2
- package/dist/{impl-TCR3Y3J2.cjs.map → impl-X23VUODX.cjs.map} +1 -1
- package/dist/{impl-KRJNBGJ6.cjs → impl-XU54KM62.cjs} +2 -2
- package/dist/{impl-KRJNBGJ6.cjs.map → impl-XU54KM62.cjs.map} +1 -1
- package/dist/{impl-A7XL5O4W.cjs → impl-XYHIS7X5.cjs} +2 -2
- package/dist/{impl-A7XL5O4W.cjs.map → impl-XYHIS7X5.cjs.map} +1 -1
- package/dist/{impl-VL3CJ2OT.cjs → impl-Y3MY5EKD.cjs} +2 -2
- package/dist/{impl-VL3CJ2OT.cjs.map → impl-Y3MY5EKD.cjs.map} +1 -1
- package/dist/impl-YIPC6MAR.cjs +6 -0
- package/dist/impl-YIPC6MAR.cjs.map +1 -0
- package/dist/{impl-JFYHXSOV.cjs → impl-Z54SB7SM.cjs} +2 -2
- package/dist/{impl-JFYHXSOV.cjs.map → impl-Z54SB7SM.cjs.map} +1 -1
- package/dist/{impl-GEEPG7OH.cjs → impl-ZTEP5CYM.cjs} +2 -2
- package/dist/{impl-GEEPG7OH.cjs.map → impl-ZTEP5CYM.cjs.map} +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/package.json +2 -2
- package/dist/chunk-52MA7ZLS.cjs +0 -12
- package/dist/chunk-52MA7ZLS.cjs.map +0 -1
- package/dist/chunk-55B57ZAY.cjs +0 -3001
- package/dist/chunk-55B57ZAY.cjs.map +0 -1
- package/dist/chunk-7H4ALAHC.cjs.map +0 -1
- package/dist/chunk-G522ZIHS.cjs +0 -3
- package/dist/chunk-G522ZIHS.cjs.map +0 -1
- package/dist/chunk-HCEZRZHV.cjs +0 -12
- package/dist/chunk-HCEZRZHV.cjs.map +0 -1
- package/dist/chunk-M3Y6JH6I.cjs +0 -2
- package/dist/chunk-M3Y6JH6I.cjs.map +0 -1
- package/dist/chunk-MXT7N555.cjs.map +0 -1
- package/dist/chunk-NC6VWOMN.cjs +0 -2
- package/dist/chunk-NC6VWOMN.cjs.map +0 -1
- package/dist/chunk-Q2RJZGYW.cjs +0 -2
- package/dist/chunk-SKOTYI3A.cjs +0 -4
- package/dist/impl-BQNXMBQ4.cjs +0 -7
- package/dist/impl-CFYRFABZ.cjs +0 -9
- package/dist/impl-CFYRFABZ.cjs.map +0 -1
- package/dist/impl-JSXYZHX4.cjs +0 -2
- package/dist/impl-RI3WQFOE.cjs +0 -6
- package/dist/impl-RI3WQFOE.cjs.map +0 -1
- package/dist/impl-SRI65ZIC.cjs +0 -2
- package/dist/impl-U46BMUFL.cjs +0 -2
- package/dist/impl-U46BMUFL.cjs.map +0 -1
- package/dist/impl-UVQJ7HSK.cjs +0 -6
- package/dist/impl-UVQJ7HSK.cjs.map +0 -1
- package/dist/impl-V3MXFXZF.cjs +0 -2
- package/dist/impl-ZAKPYQ32.cjs +0 -2
- package/dist/impl-ZAKPYQ32.cjs.map +0 -1
- package/dist/impl-ZTYQ3IB5.cjs +0 -2
- package/dist/impl-ZTYQ3IB5.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/cli/cli/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/chunk-VCPZG4FJ.cjs","../src/lib/consent-manager/dataFlowsToDataSilos.ts"],"names":["dataFlowsToDataSilos","inputs","adTechPurposes","serviceToTitle","serviceToSupportedIntegration","siteTechIntegrations","adTechIntegrations","serviceToFoundOnDomain","flow","service","attributes","foundOnDomain","attr","v","union_default","s","adTechDataSilos"],"mappings":"AAAA,iIAAwC,SCWxBA,CAAAA,CACdC,CAAAA,CACA,CACE,cAAA,CAAAC,CAAAA,CAAiB,CAAC,YAAY,CAAA,CAC9B,cAAA,CAAAC,CAAAA,CACA,6BAAA,CAAAC,CACF,CAAA,CASA,CAEA,IAAIC,CAAAA,CAAiC,CAAC,CAAA,CAGhCC,CAAAA,CAA+B,CAAC,CAAA,CAGhCC,CAAAA,CAAsD,CAAC,CAAA,CAG7DN,CAAAA,CAAO,OAAA,CAASO,CAAAA,EAAS,CAEvB,GAAM,CAAE,OAAA,CAAAC,CAAAA,CAAS,UAAA,CAAAC,CAAAA,CAAa,CAAC,CAAE,CAAA,CAAIF,CAAAA,CACrC,EAAA,CAAI,CAACC,CAAAA,EAAWA,CAAAA,GAAY,iBAAA,CAC1B,MAAA,CAIF,IAAME,CAAAA,CAAgBD,CAAAA,CAAW,IAAA,CAC9BE,CAAAA,EAASA,CAAAA,CAAK,GAAA,GAAQ,iBACzB,CAAA,CAGID,CAAAA,EAAAA,CACGJ,CAAAA,CAAuBE,CAAO,CAAA,EAAA,CACjCF,CAAAA,CAAuBE,CAAO,CAAA,CAAI,CAAC,CAAA,CAAA,CAErCF,CAAAA,CAAuBE,CAAO,CAAA,CAAG,IAAA,CAC/B,GAAGE,CAAAA,CAAc,MAAA,CAAO,GAAA,CAAKE,CAAAA,EAC3BA,CAAAA,CAAE,OAAA,CAAQ,UAAA,CAAY,EAAE,CAAA,CAAE,OAAA,CAAQ,SAAA,CAAW,EAAE,CACjD,CACF,CAAA,CACAN,CAAAA,CAAuBE,CAAO,CAAA,CAAI,CAChC,GAAG,IAAI,GAAA,CAAIF,CAAAA,CAAuBE,CAAO,CAAC,CAC5C,CAAA,CAAA,CAIEK,iCAAAA,CAAMN,CAAK,gBAAA,CAAkBN,CAAc,CAAA,CAAE,MAAA,CAAS,CAAA,CAAA,CAExDI,CAAAA,CAAmB,IAAA,CAAKG,CAAO,CAAA,CAG3BJ,CAAAA,CAAqB,QAAA,CAASI,CAAO,CAAA,EAAA,CACvCJ,CAAAA,CAAuBA,CAAAA,CAAqB,MAAA,CACzCU,CAAAA,EAAMA,CAAAA,GAAMN,CACf,CAAA,CAAA,CAAA,CAEQH,CAAAA,CAAmB,QAAA,CAASG,CAAO,CAAA,EAE7CJ,CAAAA,CAAqB,IAAA,CAAKI,CAAO,CAErC,CAAC,CAAA,CAGD,IAAMO,CAAAA,CAAkB,CAAC,GAAG,IAAI,GAAA,CAAIV,CAAkB,CAAC,CAAA,CAAE,GAAA,CAAKG,CAAAA,EAAAA,CAAa,CACzE,KAAA,CAAON,CAAAA,CAAeM,CAAO,CAAA,CAC7B,GAAIL,CAAAA,CAA8BK,CAAO,CAAA,CACrC,CAAE,eAAA,CAAiBA,CAAQ,CAAA,CAC3B,CAAE,eAAA,CAAiB,eAAA,CAAiB,YAAA,CAAcA,CAAQ,CAAA,CAC9D,UAAA,CAAY,CACV,CACE,GAAA,CAAK,WAAA,CACL,MAAA,CAAQ,CAAC,SAAS,CACpB,CAAA,CACA,CACE,GAAA,CAAK,iBAAA,CACL,MAAA,CAAQF,CAAAA,CAAuBE,CAAO,CAAA,EAAK,CAAC,CAC9C,CACF,CACF,CAAA,CAAE,CAAA,CAsBF,MAAO,CACL,iBAAA,CApBwB,CAAC,GAAG,IAAI,GAAA,CAAIJ,CAAoB,CAAC,CAAA,CAAE,GAAA,CAC1DI,CAAAA,EAAAA,CAAa,CACZ,KAAA,CAAON,CAAAA,CAAeM,CAAO,CAAA,CAC7B,GAAIL,CAAAA,CAA8BK,CAAO,CAAA,CACrC,CAAE,eAAA,CAAiBA,CAAQ,CAAA,CAC3B,CAAE,eAAA,CAAiB,eAAA,CAAiB,SAAA,CAAWA,CAAQ,CAAA,CAC3D,UAAA,CAAY,CACV,CACE,GAAA,CAAK,WAAA,CACL,MAAA,CAAQ,CAAC,WAAW,CACtB,CAAA,CACA,CACE,GAAA,CAAK,iBAAA,CACL,MAAA,CAAQF,CAAAA,CAAuBE,CAAO,CAAA,EAAK,CAAC,CAC9C,CACF,CACF,CAAA,CACF,CAAA,CAIE,eAAA,CAAAO,CACF,CACF,CAAA,cAAA","file":"/home/runner/work/cli/cli/dist/chunk-VCPZG4FJ.cjs","sourcesContent":[null,"import { DataFlowInput, DataSiloInput } from '../../codecs';\nimport { union } from 'lodash-es';\nimport { IndexedCatalogs } from '../graphql';\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(\n (attr) => attr.key === 'Found on Domain',\n );\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) =>\n v.replace('https://', '').replace('http://', ''),\n ),\n );\n serviceToFoundOnDomain[service] = [\n ...new Set(serviceToFoundOnDomain[service]),\n ];\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(\n (s) => s !== service,\n );\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(\n (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\n return {\n siteTechDataSilos,\n adTechDataSilos,\n };\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunk56QKBG2Rcjs = require('./chunk-56QKBG2R.cjs');var _chunkZUNVPK23cjs = require('./chunk-ZUNVPK23.cjs');var _chunkDQCPGPXGcjs = require('./chunk-DQCPGPXG.cjs');var _colors = require('colors'); var _colors2 = _interopRequireDefault(_colors);var _cliprogress = require('cli-progress'); var _cliprogress2 = _interopRequireDefault(_cliprogress);var _persistedstate = require('@transcend-io/persisted-state');var _iots = require('io-ts'); var L = _interopRequireWildcard(_iots); var M = _interopRequireWildcard(_iots); var e = _interopRequireWildcard(_iots);var _typeutils = require('@transcend-io/type-utils');var He=["ENOTFOUND","ECONNRESET","ETIMEDOUT","502 Bad Gateway","504 Gateway Time-out","429","Rate limit exceeded","Task timed out after","unknown request error"].map(p=>p.toLowerCase());async function x(p,t,{maxAttempts:f=3,baseDelayMs:d=250,isRetryable:m=(s,o)=>He.some(i=>o.toLowerCase().includes(i)),onRetry:u}={}){let s=0;for(;;){s+=1;try{return await t()}catch(o){let i=_nullishCoalesce((o&&(_optionalChain([o, 'access', _2 => _2.response, 'optionalAccess', _3 => _3.body])||o.message)), () => (String(_nullishCoalesce(o, () => ("Unknown error")))));if(!(s<f&&m(o,i)))throw new Error(`${p} failed after ${s} attempt(s): ${i}`);_optionalChain([u, 'optionalCall', _4 => _4(s,o,i)]);let a=d*2**(s-1),r=Math.floor(Math.random()*d),l=a+r;_chunkZUNVPK23cjs.a.warn(_colors2.default.yellow(`[retry] attempt ${s}/${f-1}; backing off ${l}ms: ${i}`)),await _chunk56QKBG2Rcjs.$f.call(void 0, l)}}}var _privacytypes = require('@transcend-io/privacy-types');var V=M.intersection([M.type({nodes:M.array(_privacytypes.PreferenceQueryResponseItem)}),M.partial({cursor:M.string})]);async function Se(p,{identifiers:t,partitionKey:f,skipLogging:d=!1,concurrency:m=40}){let u=[],s=_chunkDQCPGPXGcjs.b.call(void 0, t,100),o=new Date().getTime(),i=new _cliprogress2.default.SingleBar({},_cliprogress2.default.Presets.shades_classic);d||i.start(t.length,0);let n=0;await _chunk56QKBG2Rcjs.a.call(void 0, s,async l=>{let y=await x("Preference Query",()=>p.post(`v1/preferences/${f}/query`,{json:{filter:{identifiers:l},limit:l.length}}).json(),{onRetry:(h,b,w)=>{_chunkZUNVPK23cjs.a.warn(_colors2.default.yellow(`[RETRY] group size=${l.length} partition=${f} attempt=${h}: ${w}`))}}),g=_typeutils.decodeCodec.call(void 0, V,y);u.push(...g.nodes),n+=l.length,i.update(n)},{concurrency:m}),i.stop();let r=new Date().getTime()-o;return d||_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Completed download in "${r/1e3}" seconds.`)),u}function X({row:p,columnToPurposeName:t,purposeSlugs:f,preferenceTopics:d}){let m={};return Object.entries(t).forEach(([u,{purpose:s,preference:o,valueMapping:i}])=>{if(!f.includes(s))throw new Error(`Invalid purpose slug: ${s}, expected: ${f.join(", ")}`);let n=p[u];if(o){let a=d.find(r=>r.slug===o&&r.purpose.trackingType===s);if(!a){let r=d.filter(l=>l.purpose.trackingType===s).map(l=>l.slug);throw new Error(`Invalid preference slug: ${o} for purpose: ${s}. Allowed preference slugs for purpose are: ${r.join(",")}`)}switch(m[s]||(m[s]={preferences:[]}),m[s].preferences||(m[s].preferences=[]),a.type){case _privacytypes.PreferenceTopicType.Boolean:{let r=i[n];if(r===void 0&&n!=="")throw new Error(`No preference mapping found for value "${n}" in column "${u}" (purpose=${s}, preference=${o})`);if(r==null)return;if(typeof r!="boolean")throw new Error(`Invalid value for boolean preference: ${o}, expected boolean, got: ${n}`);m[s].preferences.push({topic:o,choice:{booleanValue:r}});break}case _privacytypes.PreferenceTopicType.Select:{let r=i[n];if(r===void 0&&n!=="")throw new Error(`No preference mapping found for value "${n}" in column "${u}" (purpose=${s}, preference=${o})`);if(r==null)return;if(typeof r!="string")throw new Error(`Invalid value for select preference: ${o}, expected string, got: ${n}`);let l=r.trim()||null;if(l&&!a.preferenceOptionValues.map(({slug:y})=>y).includes(l))throw new Error(`Invalid value for select preference: ${o}, expected one of: ${a.preferenceOptionValues.map(({slug:y})=>y).join(", ")}, got: ${n}`);m[s].preferences.push({topic:o,choice:{selectValue:l}});break}case _privacytypes.PreferenceTopicType.MultiSelect:{if(typeof n!="string")throw new Error(`Invalid value for multi select preference: ${o}, expected string, got: ${n}`);let r=_chunk56QKBG2Rcjs.rc.call(void 0, n).map(l=>{let y=i[l];if(y===void 0&&n!=="")throw new Error(`No preference mapping found for multi select token "${n}" in column "${u}" (purpose=${s}, preference=${o})`);if(y==null)return null;if(typeof y!="string")throw new Error(`Invalid value for multi select preference: ${o}, expected one of: ${a.preferenceOptionValues.map(({slug:g})=>g).join(", ")}, got: ${l}`);return y}).filter(l=>l!==null).sort((l,y)=>l.localeCompare(y));r.length>0&&m[s].preferences.push({topic:o,choice:{selectValues:r}});break}default:throw new Error(`Unknown preference type: ${a.type}`)}}else{let a=i[n];if(a===void 0&&n!=="")throw new Error(`No preference mapping found for value "${n}" in column "${u}" (purpose=${s}, preference=\u2205)`);if(a===null)return;m[s]?m[s].enabled=a===!0:m[s]={enabled:a===!0}}}),_typeutils.apply.call(void 0, m,(u,s)=>{if(typeof u.enabled!="boolean")throw new Error(`No mapping provided for purpose.enabled=true/false value: ${s}`);return{...u,enabled:u.enabled}})}var _inquirer = require('inquirer'); var _inquirer2 = _interopRequireDefault(_inquirer);var Z="[NONE]";async function Me(p,t){let f=_chunkDQCPGPXGcjs.j.call(void 0, p.map(m=>Object.keys(m)).flat()),d=_chunkDQCPGPXGcjs.c.call(void 0, f,[...t.identifierColumn?[t.identifierColumn]:[],...Object.keys(t.columnToPurposeName)]);if(!t.timestampColum){let{timestampName:m}=await _inquirer2.default.prompt([{name:"timestampName",message:"Choose the column that will be used as the timestamp of last preference update",type:"list",default:d.find(u=>u.toLowerCase().includes("date"))||d.find(u=>u.toLowerCase().includes("time"))||d[0],choices:[...d,Z]}]);t.timestampColum=m}if(_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Using timestamp column "${t.timestampColum}"`)),t.timestampColum!==Z){let m=p.map((u,s)=>u[t.timestampColum]?null:[s]).filter(u=>!!u).flat();if(m.length>0)throw new Error(`The timestamp column "${t.timestampColum}" is missing a value for the following rows: ${m.join(`
|
|
2
|
+
`)}`);_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`The timestamp column "${t.timestampColum}" is present for all row`))}return t}async function xe(p,t){let f=_chunkDQCPGPXGcjs.j.call(void 0, p.map(o=>Object.keys(o)).flat()),d=_chunkDQCPGPXGcjs.c.call(void 0, f,[...t.identifierColumn?[t.identifierColumn]:[],...Object.keys(t.columnToPurposeName)]);if(!t.identifierColumn){let{identifierName:o}=await _inquirer2.default.prompt([{name:"identifierName",message:"Choose the column that will be used as the identifier to upload consent preferences by",type:"list",default:d.find(i=>i.toLowerCase().includes("email"))||d[0],choices:d}]);t.identifierColumn=o}_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Using identifier column "${t.identifierColumn}"`));let m=p.map((o,i)=>o[t.identifierColumn]?null:[i]).filter(o=>!!o).flat();if(m.length>0){let o=`The identifier column "${t.identifierColumn}" is missing a value for the following rows: ${m.join(", ")}`;if(_chunkZUNVPK23cjs.a.warn(_colors2.default.yellow(o)),!await _chunk56QKBG2Rcjs.Vf.call(void 0, {message:"Would you like to skip rows missing an identifier?"}))throw new Error(o);let n=p.length;p=p.filter(a=>a[t.identifierColumn]),_chunkZUNVPK23cjs.a.info(_colors2.default.yellow(`Skipped ${n-p.length} rows missing an identifier`))}_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`The identifier column "${t.identifierColumn}" is present for all rows`));let u=_chunkDQCPGPXGcjs.d.call(void 0, p,t.identifierColumn),s=Object.entries(u).filter(([,o])=>o.length>1);if(s.length>0){let o=`The identifier column "${t.identifierColumn}" has duplicate values for the following rows: ${s.slice(0,10).map(([n,a])=>`${n} (${a.length})`).join(`
|
|
3
|
+
`)}`;if(_chunkZUNVPK23cjs.a.warn(_colors2.default.yellow(o)),!await _chunk56QKBG2Rcjs.Vf.call(void 0, {message:"Would you like to automatically take the latest update?"}))throw new Error(o);p=Object.entries(u).map(([,n])=>n.sort((r,l)=>new Date(l[t.timestampColum]).getTime()-new Date(r[t.timestampColum]).getTime())[0]).filter(n=>n)}return{currentState:t,preferences:p}}async function Ie(p,t,{purposeSlugs:f,preferenceTopics:d,forceTriggerWorkflows:m}){let u=_chunkDQCPGPXGcjs.j.call(void 0, p.map(i=>Object.keys(i)).flat()),s=_chunkDQCPGPXGcjs.c.call(void 0, u,[...t.identifierColumn?[t.identifierColumn]:[],...t.timestampColum?[t.timestampColum]:[]]);if(s.length===0){if(m)return t;throw new Error("No other columns to process")}let o=[...f,...d.map(i=>`${i.purpose.trackingType}->${i.slug}`)];return await _chunk56QKBG2Rcjs.b.call(void 0, s,async i=>{let n=_chunkDQCPGPXGcjs.j.call(void 0, p.map(r=>r[i])),a=t.columnToPurposeName[i];if(a)_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Column "${i}" is associated with purpose "${a.purpose}"`));else{let{purposeName:r}=await _inquirer2.default.prompt([{name:"purposeName",message:`Choose the purpose that column ${i} is associated with`,type:"list",default:o.find(g=>g.startsWith(f[0])),choices:o}]),[l,y]=r.split("->");a={purpose:l,preference:y||null,valueMapping:{}}}await _chunk56QKBG2Rcjs.b.call(void 0, n,async r=>{if(a.valueMapping[r]!==void 0){_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Value "${r}" is associated with purpose value "${a.valueMapping[r]}"`));return}if(a.preference===null){let{purposeValue:l}=await _inquirer2.default.prompt([{name:"purposeValue",message:`Choose the purpose value for value "${r}" associated with purpose "${a.purpose}"`,type:"confirm",default:r!=="false"}]);a.valueMapping[r]=l}if(a.preference!==null){let l=d.find(g=>g.slug===a.preference);if(!l){_chunkZUNVPK23cjs.a.error(_colors2.default.red(`Preference topic "${a.preference}" not found`));return}let y=l.preferenceOptionValues.map(({slug:g})=>g);if(l.type===_privacytypes.PreferenceTopicType.Boolean){let{preferenceValue:g}=await _inquirer2.default.prompt([{name:"preferenceValue",message:`Choose the preference value for "${l.slug}" value "${r}" associated with purpose "${a.purpose}"`,type:"confirm",default:r!=="false"}]);a.valueMapping[r]=g;return}if(l.type===_privacytypes.PreferenceTopicType.Select){let{preferenceValue:g}=await _inquirer2.default.prompt([{name:"preferenceValue",message:`Choose the preference value for "${l.slug}" value "${r}" associated with purpose "${a.purpose}"`,type:"list",choices:y,default:y.find(h=>h===r)}]);a.valueMapping[r]=g;return}if(l.type===_privacytypes.PreferenceTopicType.MultiSelect){let g=_chunk56QKBG2Rcjs.rc.call(void 0, r);await _chunk56QKBG2Rcjs.b.call(void 0, g,async h=>{if(a.valueMapping[h]!==void 0)return;let{preferenceValue:b}=await _inquirer2.default.prompt([{name:"preferenceValue",message:`Choose the preference value for "${l.slug}" value "${h}" associated with purpose "${a.purpose}"`,type:"list",choices:y,default:y.find(w=>w===h)}]);a.valueMapping[h]=b});return}throw new Error(`Unknown preference topic type: ${l.type}`)}}),t.columnToPurposeName[i]=a}),t}function Oe({currentConsentRecord:p,pendingUpdates:t,preferenceTopics:f}){return Object.entries(t).every(([d,{preferences:m=[],enabled:u}])=>{let s=p.purposes.find(i=>i.purpose===d);return!!s&&s.enabled===u?m.every(({topic:i,choice:n})=>s.preferences&&s.preferences.find(a=>{if(a.topic!==i)return!1;let r=f.find(l=>l.slug===i&&l.purpose.trackingType===d);if(!r)throw new Error(`Could not find preference topic for ${i}`);switch(r.type){case _privacytypes.PreferenceTopicType.Boolean:return a.choice.booleanValue===n.booleanValue;case _privacytypes.PreferenceTopicType.Select:return a.choice.selectValue===n.selectValue;case _privacytypes.PreferenceTopicType.MultiSelect:let l=(a.choice.selectValues||[]).sort(),y=(n.selectValues||[]).sort();return l.length===y.length&&l.every((g,h)=>g===y[h]);default:throw new Error(`Unknown preference topic type: ${r.type}`)}})):!1})}function Fe({currentConsentRecord:p,pendingUpdates:t,preferenceTopics:f,log:d}){return!!Object.entries(t).find(([m,{preferences:u=[],enabled:s}])=>{let o=p.purposes.find(i=>i.purpose===m);return o?o.enabled!==s?(d&&_chunkZUNVPK23cjs.a.warn(`Purpose ${m} enabled value conflict for user ${p.userId}. Pending Value: ${s}, Current Value: ${o.enabled}`),!0):!!u.find(({topic:i,choice:n})=>{let a=(o.preferences||[]).find(g=>g.topic===i);if(!a)return d&&_chunkZUNVPK23cjs.a.warn(`No existing preference found for topic ${i} in purpose ${m} for user ${p.userId}.`),!1;let r=f.find(g=>g.slug===i&&g.purpose.trackingType===m);if(!r)throw new Error(`Could not find preference topic for ${i}`);let l,y;switch(r.type){case _privacytypes.PreferenceTopicType.Boolean:return l=a.choice.booleanValue!==n.booleanValue,d&&_chunkZUNVPK23cjs.a.warn(`Preference topic ${i} boolean value conflict for user ${p.userId}. Expected: ${n.booleanValue}, Found: ${a.choice.booleanValue}`),l;case _privacytypes.PreferenceTopicType.Select:return y=a.choice.selectValue!==n.selectValue,d&&_chunkZUNVPK23cjs.a.warn(`Preference topic ${i} select value conflict for user ${p.userId}. Expected: ${n.selectValue}, Found: ${a.choice.selectValue}`),y;case _privacytypes.PreferenceTopicType.MultiSelect:let g=(a.choice.selectValues||[]).sort(),h=(n.selectValues||[]).sort();return y=g.length!==h.length||!g.every((b,w)=>b===h[w]),d&&_chunkZUNVPK23cjs.a.warn(`Preference topic ${i} multi-select value conflict for user ${p.userId}. Expected: ${h.join(", ")}, Found: ${g.join(", ")}`),y;default:throw new Error(`Unknown preference topic type: ${r.type}`)}}):(d&&_chunkZUNVPK23cjs.a.warn(`No existing purpose found for ${m} in consent record for ${p.userId}.`),!1)})}async function De({file:p,sombra:t,purposeSlugs:f,preferenceTopics:d,partitionKey:m,skipExistingRecordCheck:u,forceTriggerWorkflows:s},o){let i=new Date().getTime(),n=o.getValue("fileMetadata");_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Reading in file: "${p}"`));let a=_chunk56QKBG2Rcjs.uc.call(void 0, p,L.record(L.string,L.string)),r={columnToPurposeName:{},pendingSafeUpdates:{},pendingConflictUpdates:{},skippedUpdates:{},...n[p]||{},lastFetchedAt:new Date().toISOString()};r=await Me(a,r),n[p]=r,await o.setValue(n,"fileMetadata");let l=await xe(a,r);r=l.currentState,a=l.preferences,n[p]=r,await o.setValue(n,"fileMetadata"),r=await Ie(a,r,{preferenceTopics:d,purposeSlugs:f,forceTriggerWorkflows:s}),n[p]=r,await o.setValue(n,"fileMetadata");let y=a.map(w=>w[r.identifierColumn]),g=u?[]:await Se(t,{identifiers:y.map(w=>({value:w})),partitionKey:m}),h=_chunkDQCPGPXGcjs.e.call(void 0, g,"userId");r.pendingConflictUpdates={},r.pendingSafeUpdates={},r.skippedUpdates={},a.forEach(w=>{let P=w[r.identifierColumn],C=X({row:w,columnToPurposeName:r.columnToPurposeName,preferenceTopics:d,purposeSlugs:f}),T=h[P];if(s&&!T)throw new Error(`No existing consent record found for user with id: ${P}.
|
|
4
|
+
When 'forceTriggerWorkflows' is set all the user identifiers should contain a consent record`);if(T&&Oe({currentConsentRecord:T,pendingUpdates:C,preferenceTopics:d})&&!s){r.skippedUpdates[P]=w;return}if(T&&Fe({currentConsentRecord:T,pendingUpdates:C,preferenceTopics:d})){r.pendingConflictUpdates[P]={row:w,record:T};return}r.pendingSafeUpdates[P]=w}),n[p]=r,await o.setValue(n,"fileMetadata");let b=new Date().getTime();_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Successfully pre-processed file: "${p}" in ${(b-i)/1e3}s`))}var Ee=e.type({purpose:e.string,preference:e.union([e.string,e.null]),valueMapping:e.record(e.string,e.union([e.string,e.boolean,e.null,e.undefined]))}),Rr=e.record(e.string,Ee),ot=e.type({name:e.string,isUniqueOnPreferenceStore:e.boolean}),Tr=e.record(e.string,ot),nt=e.intersection([e.type({columnToPurposeName:e.record(e.string,Ee),lastFetchedAt:e.string,pendingSafeUpdates:e.record(e.string,e.record(e.string,e.string)),pendingConflictUpdates:e.record(e.string,e.type({record:_privacytypes.PreferenceQueryResponseItem,row:e.record(e.string,e.string)})),skippedUpdates:e.record(e.string,e.record(e.string,e.string))}),e.partial({identifierColumn:e.string,timestampColum:e.string})]),Sr=e.record(e.string,e.union([e.boolean,_privacytypes.PreferenceUpdateItem])),kr=e.record(e.string,e.union([e.boolean,e.record(e.string,e.string)])),Mr=e.record(e.string,e.type({uploadedAt:e.string,error:e.string,update:_privacytypes.PreferenceUpdateItem})),xr=e.record(e.string,e.type({record:_privacytypes.PreferenceQueryResponseItem,row:e.record(e.string,e.string)})),Ir=e.record(e.string,e.record(e.string,e.string)),Ve=e.type({fileMetadata:e.record(e.string,nt),failingUpdates:e.record(e.string,e.type({uploadedAt:e.string,error:e.string,update:_privacytypes.PreferenceUpdateItem})),pendingUpdates:e.record(e.string,_privacytypes.PreferenceUpdateItem)}),Or=e.type({records:e.array(e.type({anchorIdentifier:_privacytypes.PreferenceStoreIdentifier,timestamp:e.string}))}),Ae=e.intersection([e.type({records:e.array(e.intersection([e.type({success:e.boolean}),e.partial({errorMessage:e.string})])),failures:e.array(e.type({index:e.number,error:e.string}))}),e.partial({errors:e.array(e.string)})]),Qe=e.type({name:e.string,value:e.string});async function Wr({auth:p,sombraAuth:t,receiptFilepath:f,file:d,partition:m,isSilent:u=!0,dryRun:s=!1,skipWorkflowTriggers:o=!1,skipConflictUpdates:i=!1,skipExistingRecordCheck:n=!1,attributes:a=[],transcendUrl:r,forceTriggerWorkflows:l=!1}){let y=_chunk56QKBG2Rcjs.tc.call(void 0, a),g=new (0, _persistedstate.PersistedState)(f,Ve,{fileMetadata:{},failingUpdates:{},pendingUpdates:{}}),h=g.getValue("failingUpdates"),b=g.getValue("pendingUpdates"),w=g.getValue("fileMetadata");_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Restored cache, there are:
|
|
5
|
+
${Object.values(h).length} failing requests to be retried
|
|
6
|
+
${Object.values(b).length} pending requests to be processed
|
|
7
|
+
The following files are stored in cache and will be used:
|
|
8
|
+
${Object.keys(w).map(S=>S).join(`
|
|
9
|
+
`)}
|
|
10
|
+
The following file will be processed: ${d}
|
|
11
|
+
`));let P=_chunk56QKBG2Rcjs.zc.call(void 0, r,p),[C,T,me]=await Promise.all([_chunk56QKBG2Rcjs.Ac.call(void 0, r,p,t),_chunk56QKBG2Rcjs.id.call(void 0, P),_chunk56QKBG2Rcjs.ed.call(void 0, P)]);await De({file:d,purposeSlugs:T.map(S=>S.trackingType),preferenceTopics:me,sombra:C,partitionKey:m,skipExistingRecordCheck:n,forceTriggerWorkflows:l},g);let j={};w=g.getValue("fileMetadata");let F=w[d];if(_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Found ${Object.entries(F.pendingSafeUpdates).length} safe updates in ${d}`)),_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Found ${Object.entries(F.pendingConflictUpdates).length} conflict updates in ${d}`)),_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Found ${Object.entries(F.skippedUpdates).length} skipped updates in ${d}`)),Object.entries({...F.pendingSafeUpdates,...i?{}:_typeutils.apply.call(void 0, F.pendingConflictUpdates,({row:S})=>S)}).forEach(([S,k])=>{let z=F.timestampColum===Z?new Date:new Date(k[F.timestampColum]),D=X({row:k,columnToPurposeName:F.columnToPurposeName,preferenceTopics:me,purposeSlugs:T.map(B=>B.trackingType)});j[S]={userId:S,partition:m,timestamp:z.toISOString(),purposes:Object.entries(D).map(([B,Ye])=>({...Ye,purpose:B,workflowSettings:{attributes:y,isSilent:u,skipWorkflowTrigger:o,...l?{forceTriggerWorkflow:l}:{}}}))}}),await g.setValue(j,"pendingUpdates"),await g.setValue({},"failingUpdates"),s){_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Dry run complete, exiting. ${Object.values(j).length} pending updates. Check file: ${f}`));return}_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Uploading ${Object.values(j).length} preferences to partition: ${m}`));let We=new Date().getTime(),oe=new _cliprogress2.default.SingleBar({},_cliprogress2.default.Presets.shades_classic),le=0,ne=Object.entries(j),_e=_chunkDQCPGPXGcjs.b.call(void 0, ne,o?100:10);oe.start(ne.length,0),await _chunk56QKBG2Rcjs.a.call(void 0, _e,async S=>{try{await C.put("v1/preferences",{json:{records:S.map(([,k])=>k),skipWorkflowTriggers:o}}).json()}catch(k){try{let D=JSON.parse(_optionalChain([k, 'optionalAccess', _5 => _5.response, 'optionalAccess', _6 => _6.body])||"{}");D.error&&_chunkZUNVPK23cjs.a.error(_colors2.default.red(`Error: ${D.error}`))}catch (e2){}_chunkZUNVPK23cjs.a.error(_colors2.default.red(`Failed to upload ${S.length} user preferences to partition ${m}: ${_optionalChain([k, 'optionalAccess', _7 => _7.response, 'optionalAccess', _8 => _8.body])||_optionalChain([k, 'optionalAccess', _9 => _9.message])}`));let z=g.getValue("failingUpdates");S.forEach(([D,B])=>{z[D]={uploadedAt:new Date().toISOString(),update:B,error:_optionalChain([k, 'optionalAccess', _10 => _10.response, 'optionalAccess', _11 => _11.body])||_optionalChain([k, 'optionalAccess', _12 => _12.message])||"Unknown error"}}),await g.setValue(z,"failingUpdates")}le+=S.length,oe.update(le)},{concurrency:40}),oe.stop();let ze=new Date().getTime()-We;_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Successfully uploaded ${ne.length} user preferences to partition ${m} in "${ze/1e3}" seconds!`))}function zr({identifiers:p=[],purposes:t=[],metadata:f=[],consentManagement:d={},system:m={decryptionStatus:"DECRYPTED"},...u}){let s={...u,...m,...d};if(Array.isArray(p)){let o=new Map;for(let{name:i,value:n}of p)o.has(i)||o.set(i,new Set),n&&o.get(i).add(n);for(let[i,n]of o.entries())s[i]=Array.from(n).join(",")}if(Array.isArray(f)&&(s.metadata=JSON.stringify(f.reduce((o,{key:i,value:n})=>(o[i]=n,o),{}))),Array.isArray(t)){for(let{purpose:o,preferences:i,enabled:n}of t)if(s[o]=!!n,Array.isArray(i))for(let{topic:a,choice:r}of i){let l=`${o}_${a}`,y=null;typeof r.booleanValue=="boolean"?y=r.booleanValue:r.selectValue?y=r.selectValue:Array.isArray(r.selectValues)?y=r.selectValues.filter(h=>h.length>0).join(","):y=null,s[l]=y}}return s}async function*te(p,t,f,d){let m;for(;;){let u={limit:d};f&&Object.keys(f).length&&(u.filter=f),m&&(u.cursor=m);let s=await x("Preference Query",()=>p.post(`v1/preferences/${t}/query`,{json:u}).json(),{onRetry:(n,a,r)=>{_chunkZUNVPK23cjs.a.warn(_colors2.default.yellow(`Retry attempt ${n} for fetchConsentPreferences due to error: ${r}`))}}),{nodes:o,cursor:i}=_typeutils.decodeCodec.call(void 0, V,s);if(!_optionalChain([o, 'optionalAccess', _13 => _13.length])||(yield o,!i))break;m=i}}function re(p){return!!p.timestampAfter||!!p.timestampBefore?"timestamp":"updated"}function A(p,t){return p==="timestamp"?new Date(t.timestamp):_optionalChain([t, 'access', _14 => _14.system, 'optionalAccess', _15 => _15.updatedAt])?new Date(t.system.updatedAt):new Date}function je(p,t){if(p==="timestamp")return{after:t.timestampAfter?new Date(t.timestampAfter):void 0,before:t.timestampBefore?new Date(t.timestampBefore):void 0};let f=_nullishCoalesce(t.system, () => ({}));return{after:f.updatedAfter?new Date(f.updatedAfter):void 0,before:f.updatedBefore?new Date(f.updatedBefore):void 0}}function W(p,t,f){return p==="timestamp"?{...t,timestampBefore:_nullishCoalesce(f, () => (t.timestampBefore))}:{...t,system:{...t.system||{},...f?{updatedBefore:f}:{}},timestampAfter:void 0,timestampBefore:void 0}}async function _(p,t,f){_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Single-record probe with filter: ${JSON.stringify(f)}`));let m=await te(p,t,f,1).next();if(m.done||!m.value||m.value.length===0)return _chunkZUNVPK23cjs.a.info(_colors2.default.yellow("Probe result: no record")),null;let u=m.value[0];return _chunkZUNVPK23cjs.a.info(_colors2.default.green(`Probe result: found record at ${A(re(f),u).toISOString()}`)),u}async function Be(p,t){let{partition:f,mode:d,baseFilter:m,maxLookbackDays:u=3650}=t,s=await _(p,f,W(d,m));if(!s)return _chunkZUNVPK23cjs.a.info(_colors2.default.yellow("No records found; defaulting earliest day to today.")),_chunk56QKBG2Rcjs.lg.call(void 0, new Date);let o=A(d,s);_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Newest instant: ${o.toISOString()}`));let i=[1,7,30],n=0,a=i[0]*864e5,r=o,l=null;for(;;){let w=n<i.length?new Date(o.getTime()-i[n]*864e5):new Date(o.getTime()-a);if((_chunk56QKBG2Rcjs.lg.call(void 0, new Date).getTime()-_chunk56QKBG2Rcjs.lg.call(void 0, w).getTime())/864e5>u){_chunkZUNVPK23cjs.a.warn(_colors2.default.yellow(`Exponential jump exceeded maxLookbackDays=${u}. Using current bounds.`)),l=w;break}_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Probing before=${w.toISOString()} (jump step ${n<i.length?`${i[n]}d`:`${Math.round(a/864e5)}d`})\u2026`));let C=await _(p,f,W(d,m,w.toISOString()));if(C){r=A(d,C),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Found older record at ${r.toISOString()} \u2014 continue jumping back.`)),n<i.length-1?(n+=1,a=i[n]*864e5):n===i.length-1?(n+=1,a=i[i.length-1]*2*864e5):a*=2;continue}l=w,_chunkZUNVPK23cjs.a.info(_colors2.default.green(`No record before ${w.toISOString()} \u2014 established empty lower bound.`));break}l||(l=new Date(r.getTime()-864e5));let y=l,g=r,h=Math.max(864e5,Math.floor((g.getTime()-y.getTime())/64));_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Exponential forward-from-empty start: empty=${y.toISOString()} found=${g.toISOString()} step=${Math.round(h/864e5)}d`));for(let w=0;w<8;w+=1){let P=new Date(y.getTime()+h);if(P.getTime()>=g.getTime())break;_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Forward gallop probe before=${P.toISOString()}\u2026`));let C=await _(p,f,W(d,m,P.toISOString()));if(C?(g=A(d,C),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Gallop hit at ${g.toISOString()} \u2014 tightening found bound. Next step halves.`)),h=Math.max(864e5,Math.floor(h/2))):(y.setTime(P.getTime()),_chunkZUNVPK23cjs.a.info(_colors2.default.yellow(`Gallop miss \u2014 advancing empty bound to ${y.toISOString()}. Next step doubles.`)),h=Math.min(g.getTime()-y.getTime(),h*2),h<864e5&&(h=864e5)),g.getTime()-y.getTime()<=864e5)break}for(;g.getTime()-y.getTime()>864e5;){let w=new Date(y.getTime()+Math.floor((g.getTime()-y.getTime())/2));_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Binary probe before=${w.toISOString()}\u2026`));let P=await _(p,f,W(d,m,w.toISOString()));if(P){let C=A(d,P);_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Binary probe found record at ${C.toISOString()}.`)),g=C}else _chunkZUNVPK23cjs.a.info(_colors2.default.yellow("Binary probe found no record.")),y=w}let b=_chunk56QKBG2Rcjs.lg.call(void 0, g);return _chunkZUNVPK23cjs.a.info(_colors2.default.green(`Earliest day (UTC) resolved to ${b.toISOString()} (instant \u2248 ${g.toISOString()}).`)),b}async function Ge(p,t){let{partition:f,mode:d,baseFilter:m}=t;_chunkZUNVPK23cjs.a.info(_colors2.default.magenta("Latest-day discovery: probing newest record\u2026"));let u=await _(p,f,W(d,m));if(!u)return _chunkZUNVPK23cjs.a.info(_colors2.default.yellow("No records found at all; defaulting latest day to today.")),_chunk56QKBG2Rcjs.lg.call(void 0, new Date);let s=A(d,u);_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Newest record instant is ${s.toISOString()}.`));let o=_chunk56QKBG2Rcjs.lg.call(void 0, s);return _chunkZUNVPK23cjs.a.info(_colors2.default.green(`Latest day (UTC) resolved to ${o.toISOString()} from instant ${s.toISOString()}.`)),o}function qe(p,t,f,d=5e3){let m=Math.max(0,f.getTime()-t.getTime());if(m===0)return[];let u=new Date(Math.floor(t.getTime()/3e5)*3e5),s=Math.ceil(m/Math.max(1,d)),o=Math.max(3e5,s),i=Math.ceil((f.getTime()-u.getTime())/o),n=[];for(let a=0;a<i;a+=1){let r=u.getTime()+a*o,y=Math.min(f.getTime(),r+o)-1,g=Math.max(r,y),h=new Date(r).toISOString(),b=new Date(g).toISOString();p==="timestamp"?n.push({timestampAfter:h,timestampBefore:b}):n.push({system:{updatedAfter:h,updatedBefore:b}})}return n}function ft(p,t,f){return p==="timestamp"?{...t,timestampAfter:_nullishCoalesce(f.timestampAfter, () => (t.timestampAfter)),timestampBefore:_nullishCoalesce(f.timestampBefore, () => (t.timestampBefore)),system:void 0}:{...t,system:{...t.system||{},..._optionalChain([f, 'access', _16 => _16.system, 'optionalAccess', _17 => _17.updatedAfter])?{updatedAfter:f.system.updatedAfter}:{},..._optionalChain([f, 'access', _18 => _18.system, 'optionalAccess', _19 => _19.updatedBefore])?{updatedBefore:f.system.updatedBefore}:{}},timestampAfter:void 0,timestampBefore:void 0}}async function Ro(p,{partition:t,filterBy:f={},limit:d=50,windowConcurrency:m=25,maxChunks:u=5e3,maxLookbackDays:s=3650,onItems:o}){let i=re(f);_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Fetching consent preferences in chunks by ${i==="timestamp"?"timestamp":"system.updatedAt"}...`));let{after:n,before:a}=je(i,f);if(_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Initial bounds: after=${_nullishCoalesce(_optionalChain([n, 'optionalAccess', _20 => _20.toISOString, 'call', _21 => _21()]), () => ("undefined"))} before=${_nullishCoalesce(_optionalChain([a, 'optionalAccess', _22 => _22.toISOString, 'call', _23 => _23()]), () => ("undefined"))}`)),(!n||!a)&&(n||(_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Discovering earliest day with data for partition ${t}...`)),n=await Be(p,{partition:t,mode:i,baseFilter:f,maxLookbackDays:s}),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Discovered earliest day with data: ${n.toISOString()}`))),!a)){_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Discovering latest day with data for partition ${t}...`));let P=await Ge(p,{partition:t,mode:i,baseFilter:f,earliest:n});a=_chunk56QKBG2Rcjs.og.call(void 0, P,1),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Discovered latest day with data: ${P.toISOString()}`))}_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Final bounds (UTC): after=${n.toISOString()} before=${a.toISOString()}`));let r=qe(i,n,a,u);_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Fetching consent preferences from partition ${t} in ${r.length} chunks...`));let l=new _cliprogress2.default.SingleBar({format:"Downloading [{bar}] {percentage}% | chunks {value}/{total} | fetched {fetched}"},_cliprogress2.default.Presets.shades_classic),y=0,g=0;l.start(r.length,0,{fetched:g});let h=Date.now(),b=_chunk56QKBG2Rcjs.kg.call(void 0, d),w=[];return await _chunk56QKBG2Rcjs.a.call(void 0, r.map((P,C)=>({windowFilter:P,idx:C})),async({windowFilter:P})=>{let C=ft(i,f,P);for await(let T of te(p,t,C,b))g+=T.length,l.update(y,{fetched:g}),o?await o(T):w.push(...T);y+=1,l.update(y,{fetched:g})},{concurrency:Math.max(1,m)}),l.update(y,{fetched:g}),l.stop(),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Fetched ${g} consent preference records from partition ${t} in ${(Date.now()-h)/1e3}s.`)),o?[]:w}async function Fo(p,{partition:t,filterBy:f={},limit:d=50,onItems:m}){let u=[],s,o=f&&(Object.keys(f).length>0||f.system&&Object.keys(f.system).length>0),i=Math.max(1,Math.min(50,_nullishCoalesce(d, () => (50))));for(;;){let n={limit:i};o&&(n.filter=f),s&&(n.cursor=s);let a=await x("Preference Query",()=>p.post(`v1/preferences/${t}/query`,{json:n}).json(),{onRetry:(y,g,h)=>{_chunkZUNVPK23cjs.a.warn(_colors2.default.yellow(`Retry attempt ${y} for fetchConsentPreferences due to error: ${h}`))}}),{nodes:r,cursor:l}=_typeutils.decodeCodec.call(void 0, V,a);if(!r||r.length===0||(m?await m(r):u.push(...r),!l))break;s=l}return m?[]:u}async function ut(p,{partition:t,identifierChunk:f,timestamp:d}){try{let m=await x("Delete Preference Records",()=>p.post(`v1/preferences/${t}/delete`,{json:{records:f.map(s=>({anchorIdentifier:s,timestamp:d.toISOString()}))}}).json(),{maxAttempts:3,onRetry:(s,o,i)=>{_chunkZUNVPK23cjs.a.debug(_colors2.default.yellow(`Attempt ${s} to delete preference records failed: ${i}`))}}),{failures:u}=_typeutils.decodeCodec.call(void 0, Ae,m);return u.length>0?u.map(({index:s,error:o})=>({...f[s],error:o})):[]}catch(m){return f.map(u=>({...u,error:m.message}))}}async function Bo(p,{partition:t,filePath:f,timestamp:d,maxItemsInChunk:m,maxConcurrency:u}){let s=_chunk56QKBG2Rcjs.uc.call(void 0, f,Qe),o=_chunkDQCPGPXGcjs.b.call(void 0, s,m);return(await _chunk56QKBG2Rcjs.a.call(void 0, o,async n=>await ut(p,{partition:t,identifierChunk:n,timestamp:d}),{concurrency:u})).flat()}exports.a = Wr; exports.b = zr; exports.c = Ro; exports.d = Fo; exports.e = Bo;
|
|
12
|
+
//# sourceMappingURL=chunk-VUQAH7YK.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/chunk-VUQAH7YK.cjs","../src/lib/preference-management/uploadPreferenceManagementPreferencesInteractive.ts","../src/lib/preference-management/parsePreferenceManagementCsv.ts","../src/lib/preference-management/getPreferencesForIdentifiers.ts","../src/lib/preference-management/withPreferenceRetry.ts","../src/lib/preference-management/parsePreferenceIdentifiersFromCsv.ts","../src/lib/preference-management/parsePreferenceAndPurposeValuesFromCsv.ts","../src/lib/preference-management/codecs.ts"],"names":["RETRY_PREFERENCE_MSGS","s","withPreferenceRetry","name","fn","maxAttempts","baseDelayMs","isRetryable","_err","msg","m","onRetry","attempt","err"],"mappings":"AAAA,2lCAAwK,wDAAyC,wDAAuE,gFCMrQ,qGAIK,+DAEO,qJCTZ,qDCES,ICGfA,EAAAA,CAAkC,CAC7C,WAAA,CACA,YAAA,CACA,WAAA,CACA,iBAAA,CACA,sBAAA,CACA,KAAA,CACA,qBAAA,CACA,sBAAA,CACA,uBACF,CAAA,CAAE,GAAA,CAAKC,CAAAA,EAAMA,CAAAA,CAAE,WAAA,CAAY,CAAC,CAAA,CAyB5B,MAAA,SAAsBC,CAAAA,CACpBC,CAAAA,CACAC,CAAAA,CACA,CACE,WAAA,CAAAC,CAAAA,CAAc,CAAA,CACd,WAAA,CAAAC,CAAAA,CAAc,GAAA,CACd,WAAA,CAAAC,CAAAA,CAAc,CAACC,CAAAA,CAAMC,CAAAA,CAAAA,EACnBT,EAAAA,CAAsB,IAAA,CAAMU,CAAAA,EAAMD,CAAAA,CAAI,WAAA,CAAY,CAAA,CAAE,QAAA,CAASC,CAAC,CAAC,CAAA,CACjE,OAAA,CAAAC,CACF,CAAA,CAAkB,CAAC,CAAA,CACP,CACZ,IAAIC,CAAAA,CAAU,CAAA,CAEd,GAAA,CAAA,CAAA,CAAA,CAAa,CACXA,CAAAA,EAAW,CAAA,CACX,GAAI,CACF,OAAO,MAAMR,CAAAA,CAAG,CAElB,CAAA,KAAA,CAASS,CAAAA,CAAU,CACjB,IAAMJ,CAAAA,kBAAAA,CACHI,CAAAA,EAAAA,iBAAQA,CAAAA,qBAAI,QAAA,6BAAU,MAAA,EAAQA,CAAAA,CAAI,OAAA,CAAA,CAAA,SACnC,MAAA,kBAAOA,CAAAA,SAAO,iBAAe,GAAA,CAE/B,EAAA,CAAI,CAAA,CADcD,CAAAA,CAAUP,CAAAA,EAAeE,CAAAA,CAAYM,CAAAA,CAAKJ,CAAG,CAAA,CAAA,CAE7D,MAAM,IAAI,KAAA,CAAM,CAAA,EAAA;ACuBX;ACbM;ACkBO,oGAAA;ANPlB;AAGA;AAAA;AAKQ;AAAK;AACgC,sCAAA;AAwFrC","file":"/home/runner/work/cli/cli/dist/chunk-VUQAH7YK.cjs","sourcesContent":[null,"import {\n buildTranscendGraphQLClient,\n createSombraGotInstance,\n fetchAllPurposes,\n fetchAllPreferenceTopics,\n} from '../graphql';\nimport colors from 'colors';\nimport { map } from '../bluebird';\nimport { chunk } from 'lodash-es';\nimport { logger } from '../../logger';\nimport cliProgress from 'cli-progress';\nimport { parseAttributesFromString } from '../requests';\nimport { PersistedState } from '@transcend-io/persisted-state';\nimport { parsePreferenceManagementCsvWithCache } from './parsePreferenceManagementCsv';\nimport { PreferenceState } from './codecs';\nimport { PreferenceUpdateItem } from '@transcend-io/privacy-types';\nimport { apply } from '@transcend-io/type-utils';\nimport { NONE_PREFERENCE_MAP } from './parsePreferenceTimestampsFromCsv';\nimport { getPreferenceUpdatesFromRow } from './getPreferenceUpdatesFromRow';\n\n/**\n * Upload a set of consent preferences\n *\n * @param options - Options\n */\nexport async function uploadPreferenceManagementPreferencesInteractive({\n auth,\n sombraAuth,\n receiptFilepath,\n file,\n partition,\n isSilent = true,\n dryRun = false,\n skipWorkflowTriggers = false,\n skipConflictUpdates = false,\n skipExistingRecordCheck = false,\n attributes = [],\n transcendUrl,\n forceTriggerWorkflows = false,\n}: {\n /** The Transcend API key */\n auth: string;\n /** Sombra API key authentication */\n sombraAuth?: string;\n /** Partition key */\n partition: string;\n /** File where to store receipt and continue from where left off */\n receiptFilepath: string;\n /** The file to process */\n file: string;\n /** API URL for Transcend backend */\n transcendUrl: string;\n /** Whether to do a dry run */\n dryRun?: boolean;\n /** Whether to upload as isSilent */\n isSilent?: boolean;\n /** Attributes string pre-parse. In format Key:Value */\n attributes?: string[];\n /** Skip workflow triggers */\n skipWorkflowTriggers?: boolean;\n /**\n * When true, only update preferences that do not conflict with existing\n * preferences. When false, update all preferences in CSV based on timestamp.\n */\n skipConflictUpdates?: boolean;\n /** Whether to skip the check for existing records. SHOULD ONLY BE USED FOR INITIAL UPLOAD */\n skipExistingRecordCheck?: boolean;\n /** Whether to force trigger workflows */\n forceTriggerWorkflows?: boolean;\n}): Promise<void> {\n // Parse out the extra attributes to apply to all requests uploaded\n const parsedAttributes = parseAttributesFromString(attributes);\n\n // Create a new state file to store the requests from this run\n const preferenceState = new PersistedState(receiptFilepath, PreferenceState, {\n fileMetadata: {},\n failingUpdates: {},\n pendingUpdates: {},\n });\n const failingRequests = preferenceState.getValue('failingUpdates');\n const pendingRequests = preferenceState.getValue('pendingUpdates');\n let fileMetadata = preferenceState.getValue('fileMetadata');\n\n logger.info(\n colors.magenta(\n 'Restored cache, there are: \\n' +\n `${\n Object.values(failingRequests).length\n } failing requests to be retried\\n` +\n `${\n Object.values(pendingRequests).length\n } pending requests to be processed\\n` +\n `The following files are stored in cache and will be used:\\n${Object.keys(\n fileMetadata,\n )\n .map((x) => x)\n .join('\\n')}\\n` +\n `The following file will be processed: ${file}\\n`,\n ),\n );\n\n // Create GraphQL client to connect to Transcend backend\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n const [sombra, purposes, preferenceTopics] = await Promise.all([\n // Create sombra instance to communicate with\n createSombraGotInstance(transcendUrl, auth, sombraAuth),\n // get all purposes and topics\n fetchAllPurposes(client),\n fetchAllPreferenceTopics(client),\n ]);\n\n // Process the file\n await parsePreferenceManagementCsvWithCache(\n {\n file,\n purposeSlugs: purposes.map((x) => x.trackingType),\n preferenceTopics,\n sombra,\n partitionKey: partition,\n skipExistingRecordCheck,\n forceTriggerWorkflows,\n },\n preferenceState,\n );\n\n // Construct the pending updates\n const pendingUpdates: Record<string, PreferenceUpdateItem> = {};\n fileMetadata = preferenceState.getValue('fileMetadata');\n const metadata = fileMetadata[file];\n\n logger.info(\n colors.magenta(\n `Found ${\n Object.entries(metadata.pendingSafeUpdates).length\n } safe updates in ${file}`,\n ),\n );\n logger.info(\n colors.magenta(\n `Found ${\n Object.entries(metadata.pendingConflictUpdates).length\n } conflict updates in ${file}`,\n ),\n );\n logger.info(\n colors.magenta(\n `Found ${\n Object.entries(metadata.skippedUpdates).length\n } skipped updates in ${file}`,\n ),\n );\n\n // Update either safe updates only or safe + conflict\n Object.entries({\n ...metadata.pendingSafeUpdates,\n ...(skipConflictUpdates\n ? {}\n : apply(metadata.pendingConflictUpdates, ({ row }) => row)),\n }).forEach(([userId, update]) => {\n // Determine timestamp\n const timestamp =\n metadata.timestampColum === NONE_PREFERENCE_MAP\n ? new Date()\n : new Date(update[metadata.timestampColum!]);\n\n // Determine updates\n const updates = getPreferenceUpdatesFromRow({\n row: update,\n columnToPurposeName: metadata.columnToPurposeName,\n preferenceTopics,\n purposeSlugs: purposes.map((x) => x.trackingType),\n });\n pendingUpdates[userId] = {\n userId,\n partition,\n timestamp: timestamp.toISOString(),\n purposes: Object.entries(updates).map(([purpose, value]) => ({\n ...value,\n purpose,\n workflowSettings: {\n attributes: parsedAttributes,\n isSilent,\n skipWorkflowTrigger: skipWorkflowTriggers,\n ...(forceTriggerWorkflows\n ? { forceTriggerWorkflow: forceTriggerWorkflows }\n : {}),\n },\n })),\n };\n });\n await preferenceState.setValue(pendingUpdates, 'pendingUpdates');\n await preferenceState.setValue({}, 'failingUpdates');\n\n // Exist early if dry run\n if (dryRun) {\n logger.info(\n colors.green(\n `Dry run complete, exiting. ${\n Object.values(pendingUpdates).length\n } pending updates. Check file: ${receiptFilepath}`,\n ),\n );\n return;\n }\n\n logger.info(\n colors.magenta(\n `Uploading ${\n Object.values(pendingUpdates).length\n } preferences to partition: ${partition}`,\n ),\n );\n\n // Time duration\n const t0 = new Date().getTime();\n\n // create a new progress bar instance and use shades_classic theme\n const progressBar = new cliProgress.SingleBar(\n {},\n cliProgress.Presets.shades_classic,\n );\n\n // Build a GraphQL client\n let total = 0;\n const updatesToRun = Object.entries(pendingUpdates);\n const chunkedUpdates = chunk(updatesToRun, skipWorkflowTriggers ? 100 : 10);\n progressBar.start(updatesToRun.length, 0);\n await map(\n chunkedUpdates,\n async (currentChunk) => {\n // Make the request\n try {\n await sombra\n .put('v1/preferences', {\n json: {\n records: currentChunk.map(([, update]) => update),\n skipWorkflowTriggers,\n },\n })\n .json();\n } catch (err) {\n try {\n const parsed = JSON.parse(err?.response?.body || '{}');\n if (parsed.error) {\n logger.error(colors.red(`Error: ${parsed.error}`));\n }\n } catch (e) {\n // continue\n }\n logger.error(\n colors.red(\n `Failed to upload ${\n currentChunk.length\n } user preferences to partition ${partition}: ${\n err?.response?.body || err?.message\n }`,\n ),\n );\n const failingUpdates = preferenceState.getValue('failingUpdates');\n currentChunk.forEach(([userId, update]) => {\n failingUpdates[userId] = {\n uploadedAt: new Date().toISOString(),\n update,\n error: err?.response?.body || err?.message || 'Unknown error',\n };\n });\n await preferenceState.setValue(failingUpdates, 'failingUpdates');\n }\n\n total += currentChunk.length;\n progressBar.update(total);\n },\n {\n concurrency: 40,\n },\n );\n\n progressBar.stop();\n const t1 = new Date().getTime();\n const totalTime = t1 - t0;\n logger.info(\n colors.green(\n `Successfully uploaded ${\n updatesToRun.length\n } user preferences to partition ${partition} in \"${\n totalTime / 1000\n }\" seconds!`,\n ),\n );\n}\n","import { PersistedState } from '@transcend-io/persisted-state';\nimport type { Got } from 'got';\nimport { keyBy } from 'lodash-es';\nimport * as t from 'io-ts';\nimport colors from 'colors';\nimport { FileMetadataState, PreferenceState } from './codecs';\nimport { logger } from '../../logger';\nimport { readCsv } from '../requests';\nimport { getPreferencesForIdentifiers } from './getPreferencesForIdentifiers';\nimport { PreferenceTopic } from '../graphql';\nimport { getPreferenceUpdatesFromRow } from './getPreferenceUpdatesFromRow';\nimport { parsePreferenceTimestampsFromCsv } from './parsePreferenceTimestampsFromCsv';\nimport { parsePreferenceIdentifiersFromCsv } from './parsePreferenceIdentifiersFromCsv';\nimport { parsePreferenceAndPurposeValuesFromCsv } from './parsePreferenceAndPurposeValuesFromCsv';\nimport { checkIfPendingPreferenceUpdatesAreNoOp } from './checkIfPendingPreferenceUpdatesAreNoOp';\nimport { checkIfPendingPreferenceUpdatesCauseConflict } from './checkIfPendingPreferenceUpdatesCauseConflict';\n\n/**\n * Parse a file into the cache\n *\n *\n * @param options - Options\n * @param cache - The cache to store the parsed file in\n * @returns The cache with the parsed file\n */\nexport async function parsePreferenceManagementCsvWithCache(\n {\n file,\n sombra,\n purposeSlugs,\n preferenceTopics,\n partitionKey,\n skipExistingRecordCheck,\n forceTriggerWorkflows,\n }: {\n /** File to parse */\n file: string;\n /** The purpose slugs that are allowed to be updated */\n purposeSlugs: string[];\n /** The preference topics */\n preferenceTopics: PreferenceTopic[];\n /** Sombra got instance */\n sombra: Got;\n /** Partition key */\n partitionKey: string;\n /** Whether to skip the check for existing records. SHOULD ONLY BE USED FOR INITIAL UPLOAD */\n skipExistingRecordCheck: boolean;\n /** Whether to force workflow triggers */\n forceTriggerWorkflows: boolean;\n },\n cache: PersistedState<typeof PreferenceState>,\n): Promise<void> {\n // Start the timer\n const t0 = new Date().getTime();\n\n // Get the current metadata\n const fileMetadata = cache.getValue('fileMetadata');\n\n // Read in the file\n logger.info(colors.magenta(`Reading in file: \"${file}\"`));\n let preferences = readCsv(file, t.record(t.string, t.string));\n\n // start building the cache, can use previous cache as well\n let currentState: FileMetadataState = {\n columnToPurposeName: {},\n pendingSafeUpdates: {},\n pendingConflictUpdates: {},\n skippedUpdates: {},\n // Load in the last fetched time\n ...((fileMetadata[file] || {}) as Partial<FileMetadataState>),\n lastFetchedAt: new Date().toISOString(),\n };\n\n // Validate that all timestamps are present in the file\n currentState = await parsePreferenceTimestampsFromCsv(\n preferences,\n currentState,\n );\n fileMetadata[file] = currentState;\n await cache.setValue(fileMetadata, 'fileMetadata');\n\n // Validate that all identifiers are present and unique\n const result = await parsePreferenceIdentifiersFromCsv(\n preferences,\n currentState,\n );\n currentState = result.currentState;\n preferences = result.preferences;\n fileMetadata[file] = currentState;\n await cache.setValue(fileMetadata, 'fileMetadata');\n\n // Ensure all other columns are mapped to purpose and preference\n // slug values\n currentState = await parsePreferenceAndPurposeValuesFromCsv(\n preferences,\n currentState,\n {\n preferenceTopics,\n purposeSlugs,\n forceTriggerWorkflows,\n },\n );\n fileMetadata[file] = currentState;\n await cache.setValue(fileMetadata, 'fileMetadata');\n\n // Grab existing preference store records\n const identifiers = preferences.map(\n (pref) => pref[currentState.identifierColumn!],\n );\n const existingConsentRecords = skipExistingRecordCheck\n ? []\n : await getPreferencesForIdentifiers(sombra, {\n identifiers: identifiers.map((x) => ({ value: x })),\n partitionKey,\n });\n const consentRecordByIdentifier = keyBy(existingConsentRecords, 'userId');\n\n // Clear out previous updates\n currentState.pendingConflictUpdates = {};\n currentState.pendingSafeUpdates = {};\n currentState.skippedUpdates = {};\n\n // Process each row\n preferences.forEach((pref) => {\n // Grab unique Id for the user\n const userId = pref[currentState.identifierColumn!];\n\n // determine updates for user\n const pendingUpdates = getPreferenceUpdatesFromRow({\n row: pref,\n columnToPurposeName: currentState.columnToPurposeName,\n preferenceTopics,\n purposeSlugs,\n });\n\n // Grab current state of the update\n const currentConsentRecord = consentRecordByIdentifier[userId];\n if (forceTriggerWorkflows && !currentConsentRecord) {\n throw new Error(\n `No existing consent record found for user with id: ${userId}.\n When 'forceTriggerWorkflows' is set all the user identifiers should contain a consent record`,\n );\n }\n // Check if the update can be skipped\n // this is the case if a record exists, and the purpose\n // and preference values are all in sync\n if (\n currentConsentRecord &&\n checkIfPendingPreferenceUpdatesAreNoOp({\n currentConsentRecord,\n pendingUpdates,\n preferenceTopics,\n }) &&\n !forceTriggerWorkflows\n ) {\n currentState.skippedUpdates[userId] = pref;\n return;\n }\n\n // Determine if there are any conflicts\n if (\n currentConsentRecord &&\n checkIfPendingPreferenceUpdatesCauseConflict({\n currentConsentRecord,\n pendingUpdates,\n preferenceTopics,\n })\n ) {\n currentState.pendingConflictUpdates[userId] = {\n row: pref,\n record: currentConsentRecord,\n };\n return;\n }\n\n // Add to pending updates\n currentState.pendingSafeUpdates[userId] = pref;\n });\n\n // Read in the file\n fileMetadata[file] = currentState;\n await cache.setValue(fileMetadata, 'fileMetadata');\n const t1 = new Date().getTime();\n logger.info(\n colors.green(\n `Successfully pre-processed file: \"${file}\" in ${(t1 - t0) / 1000}s`,\n ),\n );\n}\n","import { PreferenceQueryResponseItem } from '@transcend-io/privacy-types';\nimport type { Got } from 'got';\nimport colors from 'colors';\nimport cliProgress from 'cli-progress';\nimport { chunk } from 'lodash-es';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport { map } from '../bluebird';\nimport { logger } from '../../logger';\nimport { withPreferenceRetry } from './withPreferenceRetry';\nimport { ConsentPreferenceResponse } from './types';\n\n/**\n * Grab the current consent preference values for a list of identifiers\n *\n * @param sombra - Backend to make API call to\n * @param options - Options\n * @returns Plaintext context information\n */\nexport async function getPreferencesForIdentifiers(\n sombra: Got,\n {\n identifiers,\n partitionKey,\n skipLogging = false,\n concurrency = 40,\n }: {\n /** The list of identifiers to look up */\n identifiers: {\n /** The value of the identifier */\n value: string;\n }[];\n /** The partition key to look up */\n partitionKey: string;\n /** Whether to skip logging */\n skipLogging?: boolean;\n /** Concurrency for requests (default 40) */\n concurrency?: number;\n },\n): Promise<PreferenceQueryResponseItem[]> {\n const results: PreferenceQueryResponseItem[] = [];\n const groupedIdentifiers = chunk(identifiers, 100);\n\n // create a new progress bar instance and use shades_classic theme\n const t0 = new Date().getTime();\n const progressBar = new cliProgress.SingleBar(\n {},\n cliProgress.Presets.shades_classic,\n );\n if (!skipLogging) {\n progressBar.start(identifiers.length, 0);\n }\n\n let total = 0;\n await map(\n groupedIdentifiers,\n async (group) => {\n const rawResult = await withPreferenceRetry(\n 'Preference Query',\n () =>\n sombra\n .post(`v1/preferences/${partitionKey}/query`, {\n json: {\n filter: { identifiers: group },\n limit: group.length,\n },\n })\n .json(),\n {\n onRetry: (attempt, _err, msg) => {\n logger.warn(\n colors.yellow(\n `[RETRY] group size=${group.length} partition=${partitionKey} attempt=${attempt}: ${msg}`,\n ),\n );\n },\n },\n );\n\n const result = decodeCodec(ConsentPreferenceResponse, rawResult);\n results.push(...result.nodes);\n total += group.length;\n progressBar.update(total);\n },\n {\n concurrency,\n },\n );\n\n progressBar.stop();\n const t1 = new Date().getTime();\n const totalTime = t1 - t0;\n\n if (!skipLogging) {\n // Log completion time\n logger.info(\n colors.green(`Completed download in \"${totalTime / 1000}\" seconds.`),\n );\n }\n\n return results;\n}\n","import colors from 'colors';\nimport { logger } from '../../logger';\nimport { sleepPromise } from '../helpers';\n\n/**\n * Transient network / platform errors that merit a retry.\n * Keep this list short and specific to avoid masking real failures.\n */\nexport const RETRY_PREFERENCE_MSGS: string[] = [\n 'ENOTFOUND',\n 'ECONNRESET',\n 'ETIMEDOUT',\n '502 Bad Gateway',\n '504 Gateway Time-out',\n '429',\n 'Rate limit exceeded',\n 'Task timed out after',\n 'unknown request error',\n].map((s) => s.toLowerCase());\n\n/**\n * Options for retrying preference operations.\n */\nexport type RetryOptions = {\n /** Max attempts including the first try (default 3) */\n maxAttempts?: number;\n /** Initial backoff in ms (default 250) */\n baseDelayMs?: number;\n /** Optional custom predicate to decide if an error is retryable */\n isRetryable?: (err: unknown, message: string) => boolean;\n /** Optional hook to log on each retry */\n onRetry?: (attempt: number, err: unknown, message: string) => void;\n};\n\n/**\n * Run an async function with standardized retry behavior for preference operations.\n * Exponential backoff with jitter; only retries on known-transient messages.\n *\n * @param name - Name of the operation (for logging)\n * @param fn - Function to run\n * @param options - Retry options\n * @returns Result of the function\n */\nexport async function withPreferenceRetry<T>(\n name: string,\n fn: () => Promise<T>,\n {\n maxAttempts = 3,\n baseDelayMs = 250,\n isRetryable = (_err, msg) =>\n RETRY_PREFERENCE_MSGS.some((m) => msg.toLowerCase().includes(m)),\n onRetry,\n }: RetryOptions = {},\n): Promise<T> {\n let attempt = 0;\n // eslint-disable-next-line no-constant-condition\n while (true) {\n attempt += 1;\n try {\n return await fn();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (err: any) {\n const msg: string =\n (err && (err.response?.body || err.message)) ??\n String(err ?? 'Unknown error');\n const willRetry = attempt < maxAttempts && isRetryable(err, msg);\n if (!willRetry) {\n throw new Error(`${name} failed after ${attempt} attempt(s): ${msg}`);\n }\n onRetry?.(attempt, err, msg);\n\n const backoff = baseDelayMs * 2 ** (attempt - 1);\n const jitter = Math.floor(Math.random() * baseDelayMs);\n const delay = backoff + jitter;\n logger.warn(\n colors.yellow(\n `[retry] attempt ${attempt}/${\n maxAttempts - 1\n }; backing off ${delay}ms: ${msg}`,\n ),\n );\n await sleepPromise(delay);\n }\n }\n}\n","import { uniq, groupBy, difference } from 'lodash-es';\nimport colors from 'colors';\nimport inquirer from 'inquirer';\nimport { FileMetadataState } from './codecs';\nimport { logger } from '../../logger';\nimport { inquirerConfirmBoolean } from '../helpers';\n\n/* eslint-disable no-param-reassign */\n\n/**\n * Parse identifiers from a CSV list of preferences\n *\n * Ensures that all rows have a valid identifier\n * and that all identifiers are unique.\n *\n * @param preferences - List of preferences\n * @param currentState - The current file metadata state for parsing this list\n * @returns The updated file metadata state\n */\nexport async function parsePreferenceIdentifiersFromCsv(\n preferences: Record<string, string>[],\n currentState: FileMetadataState,\n): Promise<{\n /** The updated state */\n currentState: FileMetadataState;\n /** The updated preferences */\n preferences: Record<string, string>[];\n}> {\n // Determine columns to map\n const columnNames = uniq(preferences.map((x) => Object.keys(x)).flat());\n\n // Determine the columns that could potentially be used for identifier\n const remainingColumnsForIdentifier = difference(columnNames, [\n ...(currentState.identifierColumn ? [currentState.identifierColumn] : []),\n ...Object.keys(currentState.columnToPurposeName),\n ]);\n\n // Determine the identifier column to work off of\n if (!currentState.identifierColumn) {\n const { identifierName } = await inquirer.prompt<{\n /** Identifier name */\n identifierName: string;\n }>([\n {\n name: 'identifierName',\n message:\n 'Choose the column that will be used as the identifier to upload consent preferences by',\n type: 'list',\n default:\n remainingColumnsForIdentifier.find((col) =>\n col.toLowerCase().includes('email'),\n ) || remainingColumnsForIdentifier[0],\n choices: remainingColumnsForIdentifier,\n },\n ]);\n currentState.identifierColumn = identifierName;\n }\n logger.info(\n colors.magenta(\n `Using identifier column \"${currentState.identifierColumn}\"`,\n ),\n );\n\n // Validate that the identifier column is present for all rows and unique\n const identifierColumnsMissing = preferences\n .map((pref, ind) => (pref[currentState.identifierColumn!] ? null : [ind]))\n .filter((x): x is number[] => !!x)\n .flat();\n if (identifierColumnsMissing.length > 0) {\n const msg = `The identifier column \"${\n currentState.identifierColumn\n }\" is missing a value for the following rows: ${identifierColumnsMissing.join(\n ', ',\n )}`;\n logger.warn(colors.yellow(msg));\n\n // Ask user if they would like to skip rows missing an identifier\n const skip = await inquirerConfirmBoolean({\n message: 'Would you like to skip rows missing an identifier?',\n });\n if (!skip) {\n throw new Error(msg);\n }\n\n // Filter out rows missing an identifier\n const previous = preferences.length;\n preferences = preferences.filter(\n (pref) => pref[currentState.identifierColumn!],\n );\n logger.info(\n colors.yellow(\n `Skipped ${previous - preferences.length} rows missing an identifier`,\n ),\n );\n }\n logger.info(\n colors.magenta(\n `The identifier column \"${currentState.identifierColumn}\" is present for all rows`,\n ),\n );\n\n // Validate that all identifiers are unique\n const rowsByUserId = groupBy(preferences, currentState.identifierColumn);\n const duplicateIdentifiers = Object.entries(rowsByUserId).filter(\n ([, rows]) => rows.length > 1,\n );\n if (duplicateIdentifiers.length > 0) {\n const msg = `The identifier column \"${\n currentState.identifierColumn\n }\" has duplicate values for the following rows: ${duplicateIdentifiers\n .slice(0, 10)\n .map(([userId, rows]) => `${userId} (${rows.length})`)\n .join('\\n')}`;\n logger.warn(colors.yellow(msg));\n\n // Ask user if they would like to take the most recent update\n // for each duplicate identifier\n const skip = await inquirerConfirmBoolean({\n message: 'Would you like to automatically take the latest update?',\n });\n if (!skip) {\n throw new Error(msg);\n }\n preferences = Object.entries(rowsByUserId)\n .map(([, rows]) => {\n const sorted = rows.sort(\n (a, b) =>\n new Date(b[currentState.timestampColum!]).getTime() -\n new Date(a[currentState.timestampColum!]).getTime(),\n );\n return sorted[0];\n })\n .filter((x) => x);\n }\n\n return { currentState, preferences };\n}\n/* eslint-enable no-param-reassign */\n","import { uniq, difference } from 'lodash-es';\nimport colors from 'colors';\nimport inquirer from 'inquirer';\nimport { FileMetadataState } from './codecs';\nimport { logger } from '../../logger';\nimport { mapSeries } from '../bluebird';\nimport { PreferenceTopic } from '../graphql';\nimport { PreferenceTopicType } from '@transcend-io/privacy-types';\nimport { splitCsvToList } from '../requests';\n\n/* eslint-disable no-param-reassign */\n\n/**\n * Parse out the purpose.enabled and preference values from a CSV file\n *\n * @param preferences - List of preferences\n * @param currentState - The current file metadata state for parsing this list\n * @param options - Options\n * @returns The updated file metadata state\n */\nexport async function parsePreferenceAndPurposeValuesFromCsv(\n preferences: Record<string, string>[],\n currentState: FileMetadataState,\n {\n purposeSlugs,\n preferenceTopics,\n forceTriggerWorkflows,\n }: {\n /** The purpose slugs that are allowed to be updated */\n purposeSlugs: string[];\n /** The preference topics */\n preferenceTopics: PreferenceTopic[];\n /** Force workflow triggers */\n forceTriggerWorkflows: boolean;\n },\n): Promise<FileMetadataState> {\n // Determine columns to map\n const columnNames = uniq(preferences.map((x) => Object.keys(x)).flat());\n\n // Determine the columns that could potentially be used for identifier\n const otherColumns = difference(columnNames, [\n ...(currentState.identifierColumn ? [currentState.identifierColumn] : []),\n ...(currentState.timestampColum ? [currentState.timestampColum] : []),\n ]);\n if (otherColumns.length === 0) {\n if (forceTriggerWorkflows) {\n return currentState;\n }\n throw new Error('No other columns to process');\n }\n\n // The purpose and preferences to map to\n const purposeNames = [\n ...purposeSlugs,\n ...preferenceTopics.map((x) => `${x.purpose.trackingType}->${x.slug}`),\n ];\n\n // Ensure all columns are accounted for\n await mapSeries(otherColumns, async (col) => {\n // Determine the unique values to map in this column\n const uniqueValues = uniq(preferences.map((x) => x[col]));\n\n // Map the column to a purpose\n let purposeMapping = currentState.columnToPurposeName[col];\n if (purposeMapping) {\n logger.info(\n colors.magenta(\n `Column \"${col}\" is associated with purpose \"${purposeMapping.purpose}\"`,\n ),\n );\n } else {\n const { purposeName } = await inquirer.prompt<{\n /** purpose name */\n purposeName: string;\n }>([\n {\n name: 'purposeName',\n message: `Choose the purpose that column ${col} is associated with`,\n type: 'list',\n default: purposeNames.find((x) => x.startsWith(purposeSlugs[0])),\n choices: purposeNames,\n },\n ]);\n const [purposeSlug, preferenceSlug] = purposeName.split('->');\n purposeMapping = {\n purpose: purposeSlug,\n preference: preferenceSlug || null,\n valueMapping: {},\n };\n }\n\n // map each value to the purpose value\n await mapSeries(uniqueValues, async (value) => {\n if (purposeMapping.valueMapping[value] !== undefined) {\n logger.info(\n colors.magenta(\n `Value \"${value}\" is associated with purpose value \"${purposeMapping.valueMapping[value]}\"`,\n ),\n );\n return;\n }\n // if preference is null, this column is just for the purpose\n if (purposeMapping.preference === null) {\n const { purposeValue } = await inquirer.prompt<{\n /** purpose value */\n purposeValue: boolean;\n }>([\n {\n name: 'purposeValue',\n message: `Choose the purpose value for value \"${value}\" associated with purpose \"${purposeMapping.purpose}\"`,\n type: 'confirm',\n default: value !== 'false',\n },\n ]);\n purposeMapping.valueMapping[value] = purposeValue;\n }\n\n // if preference is not null, this column is for a specific preference\n if (purposeMapping.preference !== null) {\n const preferenceTopic = preferenceTopics.find(\n (x) => x.slug === purposeMapping.preference,\n );\n if (!preferenceTopic) {\n logger.error(\n colors.red(\n `Preference topic \"${purposeMapping.preference}\" not found`,\n ),\n );\n return;\n }\n const preferenceOptions = preferenceTopic.preferenceOptionValues.map(\n ({ slug }) => slug,\n );\n\n if (preferenceTopic.type === PreferenceTopicType.Boolean) {\n const { preferenceValue } = await inquirer.prompt<{\n /** purpose value */\n preferenceValue: boolean;\n }>([\n {\n name: 'preferenceValue',\n message:\n // eslint-disable-next-line max-len\n `Choose the preference value for \"${preferenceTopic.slug}\" value \"${value}\" associated with purpose \"${purposeMapping.purpose}\"`,\n type: 'confirm',\n default: value !== 'false',\n },\n ]);\n purposeMapping.valueMapping[value] = preferenceValue;\n return;\n }\n\n if (preferenceTopic.type === PreferenceTopicType.Select) {\n const { preferenceValue } = await inquirer.prompt<{\n /** purpose value */\n preferenceValue: boolean;\n }>([\n {\n name: 'preferenceValue',\n // eslint-disable-next-line max-len\n message: `Choose the preference value for \"${preferenceTopic.slug}\" value \"${value}\" associated with purpose \"${purposeMapping.purpose}\"`,\n type: 'list',\n choices: preferenceOptions,\n default: preferenceOptions.find((x) => x === value),\n },\n ]);\n purposeMapping.valueMapping[value] = preferenceValue;\n return;\n }\n\n if (preferenceTopic.type === PreferenceTopicType.MultiSelect) {\n const parsedValues = splitCsvToList(value);\n // need to do this serially\n await mapSeries(parsedValues, async (parsedValue) => {\n // if we already have a value, skip re-processing it again\n if (purposeMapping.valueMapping[parsedValue] !== undefined) {\n return;\n }\n const { preferenceValue } = await inquirer.prompt<{\n /** purpose value */\n preferenceValue: boolean;\n }>([\n {\n name: 'preferenceValue',\n // eslint-disable-next-line max-len\n message: `Choose the preference value for \"${preferenceTopic.slug}\" value \"${parsedValue}\" associated with purpose \"${purposeMapping.purpose}\"`,\n type: 'list',\n choices: preferenceOptions,\n default: preferenceOptions.find((x) => x === parsedValue),\n },\n ]);\n purposeMapping.valueMapping[parsedValue] = preferenceValue;\n });\n return;\n }\n\n throw new Error(\n `Unknown preference topic type: ${preferenceTopic.type}`,\n );\n }\n });\n\n currentState.columnToPurposeName[col] = purposeMapping;\n });\n\n return currentState;\n}\n/* eslint-enable no-param-reassign */\n","import {\n PreferenceQueryResponseItem,\n PreferenceStoreIdentifier,\n PreferenceUpdateItem,\n} from '@transcend-io/privacy-types';\nimport * as t from 'io-ts';\n\nexport const PurposeRowMapping = t.type({\n /**\n * The slug or trackingType of the purpose to map to\n *\n * e.g. `Marketing`\n */\n purpose: t.string,\n /**\n * If the column maps to a preference instead of a purpose\n * this is the slug of the purpose.\n *\n * null value indicates that this column maps to the true/false\n * value of the purpose\n */\n preference: t.union([t.string, t.null]),\n /**\n * The mapping between each row value and purpose/preference value.\n *\n * e.g. for a boolean preference or purpose\n * {\n * 'true': true,\n * 'false': false,\n * '': true,\n * }\n *\n * or for a single or multi select preference\n * {\n * '': true,\n * 'value1': 'Value1',\n * 'value2': 'Value2',\n * }\n */\n valueMapping: t.record(\n t.string,\n t.union([t.string, t.boolean, t.null, t.undefined]),\n ),\n});\n\n/** Override type */\nexport type PurposeRowMapping = t.TypeOf<typeof PurposeRowMapping>;\n\n/**\n * Mapping of column name to purpose row mapping.\n * This is used to map each column in the CSV to the relevant purpose and preference definitions in\n * transcend.\n */\nexport const ColumnPurposeMap = t.record(t.string, PurposeRowMapping);\n\n/** Override type */\nexport type ColumnPurposeMap = t.TypeOf<typeof ColumnPurposeMap>;\n\nexport const IdentifierMetadataForPreference = t.type({\n /** The identifier name */\n name: t.string,\n /** Is unique on preference store */\n isUniqueOnPreferenceStore: t.boolean,\n});\n\n/** Override type */\nexport type IdentifierMetadataForPreference = t.TypeOf<\n typeof IdentifierMetadataForPreference\n>;\n\n/**\n * Mapping of identifier name to the column name in the CSV file.\n * This is used to map each identifier name to the column in the CSV file.\n */\nexport const ColumnIdentifierMap = t.record(\n t.string,\n IdentifierMetadataForPreference,\n);\n\n/** Override type */\nexport type ColumnIdentifierMap = t.TypeOf<typeof ColumnIdentifierMap>;\n\nexport const FileMetadataState = t.intersection([\n t.type({\n /**\n * Definition of how to map each column in the CSV to\n * the relevant purpose and preference definitions in transcend\n */\n columnToPurposeName: t.record(t.string, PurposeRowMapping),\n /** Last time the file was last parsed at */\n lastFetchedAt: t.string,\n /**\n * Mapping of userId to the rows in the file that need to be uploaded\n * These uploads are overwriting non-existent preferences and are safe\n */\n pendingSafeUpdates: t.record(t.string, t.record(t.string, t.string)),\n /**\n * Mapping of userId to the rows in the file that need to be uploaded\n * these records have conflicts with existing consent preferences\n */\n pendingConflictUpdates: t.record(\n t.string,\n t.type({\n record: PreferenceQueryResponseItem,\n row: t.record(t.string, t.string),\n }),\n ),\n /**\n * Mapping of userId to the rows in the file that can be skipped because\n * their preferences are already in the store\n */\n skippedUpdates: t.record(t.string, t.record(t.string, t.string)),\n }),\n t.partial({\n /** Determine which column name in file maps to consent record identifier to upload on */\n identifierColumn: t.string,\n /** Determine which column name in file maps to the timestamp */\n timestampColum: t.string,\n }),\n]);\n\n/** Override type */\nexport type FileMetadataState = t.TypeOf<typeof FileMetadataState>;\n\n/**\n * This is the type of the receipts that are stored in the file\n * that is used to track the state of the upload process.\n * It is used to resume the upload process from where it left off.\n * It is used to persist the state of the upload process across multiple runs.\n */\nexport const PreferenceUpdateMap = t.record(\n t.string,\n // This can either be true to indicate the record is pending\n // or it can be an object showing the object\n // We only return a fixed number of results to avoid\n // making the JSON file too large\n t.union([t.boolean, PreferenceUpdateItem]),\n);\n\n/** Override type */\nexport type PreferenceUpdateMap = t.TypeOf<typeof PreferenceUpdateMap>;\n\n/**\n * This is the type of the pending updates that are safe to run without\n * conflicts with existing consent preferences.\n *\n * Key is primaryKey of the record in the file.\n * The value is the row in the file that is safe to upload.\n */\nexport const PendingSafePreferenceUpdates = t.record(\n t.string,\n // This can either be true to indicate the record is safe\n // or it can be an object showing the object\n // We only return a fixed number of results to avoid\n // making the JSON file too large\n t.union([t.boolean, t.record(t.string, t.string)]),\n);\n\n/** Override type */\nexport type PendingSafePreferenceUpdates = t.TypeOf<\n typeof PendingSafePreferenceUpdates\n>;\n\n/**\n * These are the updates that failed to be uploaded to the API.\n */\nexport const FailingPreferenceUpdates = t.record(\n t.string,\n t.type({\n /** Time upload ran at */\n uploadedAt: t.string,\n /** Attempts to upload that resulted in an error */\n error: t.string,\n /** The update body */\n update: PreferenceUpdateItem,\n }),\n);\n\n/** Override type */\nexport type FailingPreferenceUpdates = t.TypeOf<\n typeof FailingPreferenceUpdates\n>;\n\n/**\n * This is the type of the pending updates that are in conflict with existing consent preferences.\n *\n * Key is primaryKey of the record in the file.\n * The value is the row in the file that is pending upload.\n */\nexport const PendingWithConflictPreferenceUpdates = t.record(\n t.string,\n // We always return the conflicts for investigation\n t.type({\n /** Record to be inserted to transcend v1/preferences API */\n record: PreferenceQueryResponseItem,\n /** The row in the file that is pending upload */\n row: t.record(t.string, t.string),\n }),\n);\n\n/** Override type */\nexport type PendingWithConflictPreferenceUpdates = t.TypeOf<\n typeof PendingWithConflictPreferenceUpdates\n>;\n\n/**\n * The set of preference updates that are skipped\n * Key is primaryKey and value is the row in the CSV\n * that is skipped.\n *\n * This is usually because the preferences are already in the store\n * or there are duplicate rows in the CSV file that are identical.\n */\nexport const SkippedPreferenceUpdates = t.record(\n t.string,\n t.record(t.string, t.string),\n);\n\n/** Override type */\nexport type SkippedPreferenceUpdates = t.TypeOf<\n typeof SkippedPreferenceUpdates\n>;\n\n/** Persist this data between runs of the script */\nexport const PreferenceState = t.type({\n /**\n * Store a cache of previous files read in\n */\n fileMetadata: t.record(t.string, FileMetadataState),\n /**\n * The set of successful uploads to Transcend\n * Mapping from userId to the upload metadata\n */\n failingUpdates: t.record(\n t.string,\n t.type({\n /** Time upload ran at */\n uploadedAt: t.string,\n /** Attempts to upload that resulted in an error */\n error: t.string,\n /** The update body */\n update: PreferenceUpdateItem,\n }),\n ),\n /**\n * The set of pending uploads to Transcend\n * Mapping from userId to the upload metadata\n */\n pendingUpdates: t.record(t.string, PreferenceUpdateItem),\n});\n\n/** Override type */\nexport type PreferenceState = t.TypeOf<typeof PreferenceState>;\n\nexport const DeletePreferenceRecordsInput = t.type({\n /** Array of consent preference records to delete */\n records: t.array(\n t.type({\n /** The anchor identifier to locate the consent record */\n anchorIdentifier: PreferenceStoreIdentifier,\n /** The ISO 8601 timestamp of when the deletion is requested */\n timestamp: t.string,\n }),\n ),\n});\n\n/** Override type */\nexport type DeletePreferenceRecordsInput = t.TypeOf<\n typeof DeletePreferenceRecordsInput\n>;\n\nexport const DeletePreferenceRecordsResponse = t.intersection([\n t.type({\n /** Array of results for each preference record deletion */\n records: t.array(\n t.intersection([\n t.type({\n /** Whether the deletion was successful */\n success: t.boolean,\n }),\n t.partial({\n /** An error message if the deletion failed */\n errorMessage: t.string,\n }),\n ]),\n ),\n /** The list of failed deletions with their respective errors */\n failures: t.array(\n t.type({\n /** The index of the failed update in the original request */\n index: t.number,\n /** The error message associated with the failure */\n error: t.string,\n }),\n ),\n }),\n t.partial({\n /** Any general errors that occurred during the operation */\n errors: t.array(t.string),\n }),\n]);\n\n/** Override type */\nexport type DeletePreferenceRecordsResponse = t.TypeOf<\n typeof DeletePreferenceRecordsResponse\n>;\n\n/** CLI CSV Row for deleting preference records */\nexport const DeletePreferenceRecordCliCsvRow = t.type({\n /** The name of the identifier type (e.g., email, userId) */\n name: t.string,\n /** The value of the identifier */\n value: t.string,\n});\n\n/** Override type */\nexport type DeletePreferenceRecordCliCsvRow = t.TypeOf<\n typeof DeletePreferenceRecordCliCsvRow\n>;\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkP5GD5LAKcjs = require('./chunk-P5GD5LAK.cjs');require('./chunk-ABKDAPPR.cjs');var _chunkWKCTKYN4cjs = require('./chunk-WKCTKYN4.cjs');require('./chunk-56QKBG2R.cjs');require('./chunk-TSJTXXLZ.cjs');require('./chunk-ZUNVPK23.cjs');var _chunkDQCPGPXGcjs = require('./chunk-DQCPGPXG.cjs');require('./chunk-7PB6LVSE.cjs');var _fs = require('fs');async function N({email:o,password:r,apiKeyTitle:n,file:s,scopes:a,deleteExistingApiKey:p,createNewApiKey:m,parentOrganizationId:c,transcendUrl:l}){_chunkWKCTKYN4cjs.a.call(void 0, this.process.exit);let g=a.map(d=>_chunkDQCPGPXGcjs.w[d].name),{errors:y,apiKeys:f}=await _chunkP5GD5LAKcjs.a.call(void 0, {transcendUrl:l,password:r,email:o,parentOrganizationId:c,deleteExistingApiKey:p,createNewApiKey:m,apiKeyTitle:n,scopes:g});_fs.writeFileSync.call(void 0, s,`${JSON.stringify(f,null,2)}
|
|
2
2
|
`),y.length>0&&this.process.exit(1)}exports.generateApiKeys = N;
|
|
3
|
-
//# sourceMappingURL=impl-
|
|
3
|
+
//# sourceMappingURL=impl-2JA6BPE7.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-2JA6BPE7.cjs","../src/commands/admin/generate-api-keys/impl.ts"],"names":["generateApiKeys","email","password","apiKeyTitle","file","scopes","deleteExistingApiKey","createNewApiKey","parentOrganizationId","transcendUrl","doneInputValidation","scopeNames","scopeTitle","SCOPES_BY_TITLE","errors","apiKeys","generateCrossAccountApiKeys","writeFileSync"],"mappings":"AAAA,iIAAwC,gCAA6B,wDAAyC,gCAA6B,gCAA6B,gCAA6B,wDAAyC,gCAA6B,wBCC7O,MAsB9B,SAAsBA,CAAAA,CAEpB,CACE,KAAA,CAAAC,CAAAA,CACA,QAAA,CAAAC,CAAAA,CACA,WAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,CAAAA,CACA,oBAAA,CAAAC,CAAAA,CACA,eAAA,CAAAC,CAAAA,CACA,oBAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CACF,CAAA,CACe,CACfC,iCAAAA,IAAoB,CAAK,OAAA,CAAQ,IAAI,CAAA,CAErC,IAAMC,CAAAA,CAAaN,CAAAA,CAAO,GAAA,CACvBO,CAAAA,EAAeC,mBAAAA,CAAgBD,CAAU,CAAA,CAAE,IAC9C,CAAA,CAGM,CAAE,MAAA,CAAAE,CAAAA,CAAQ,OAAA,CAAAC,CAAQ,CAAA,CAAI,MAAMC,iCAAAA,CAChC,YAAA,CAAAP,CAAAA,CACA,QAAA,CAAAP,CAAAA,CACA,KAAA,CAAAD,CAAAA,CACA,oBAAA,CAAAO,CAAAA,CACA,oBAAA,CAAAF,CAAAA,CACA,eAAA,CAAAC,CAAAA,CACA,WAAA,CAAAJ,CAAAA,CACA,MAAA,CAAQQ,CACV,CAAC,CAAA,CAGDM,+BAAAA,CAAcb,CAAM,CAAA,EAAA;AAItB","file":"/home/runner/work/cli/cli/dist/impl-2JA6BPE7.cjs","sourcesContent":[null,"import type { LocalContext } from '../../../context';\nimport { writeFileSync } from 'node:fs';\n\nimport { ScopeName } from '@transcend-io/privacy-types';\n\nimport { generateCrossAccountApiKeys } from '../../../lib/api-keys';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation';\nimport { SCOPES_BY_TITLE } from '../../../constants';\n\n// Command flag interface\nexport interface GenerateApiKeysCommandFlags {\n email: string;\n password: string;\n apiKeyTitle: string;\n file: string;\n scopes: string[];\n deleteExistingApiKey: boolean;\n createNewApiKey: boolean;\n parentOrganizationId?: string;\n transcendUrl: string;\n}\n\n// Command implementation\nexport async function generateApiKeys(\n this: LocalContext,\n {\n email,\n password,\n apiKeyTitle,\n file,\n scopes,\n deleteExistingApiKey,\n createNewApiKey,\n parentOrganizationId,\n transcendUrl,\n }: GenerateApiKeysCommandFlags,\n): Promise<void> {\n doneInputValidation(this.process.exit);\n\n const scopeNames = scopes.map(\n (scopeTitle) => SCOPES_BY_TITLE[scopeTitle].name as ScopeName,\n );\n\n // Upload privacy requests\n const { errors, apiKeys } = await generateCrossAccountApiKeys({\n transcendUrl,\n password,\n email,\n parentOrganizationId,\n deleteExistingApiKey,\n createNewApiKey,\n apiKeyTitle,\n scopes: scopeNames,\n });\n\n // Write to disk\n writeFileSync(file, `${JSON.stringify(apiKeys, null, 2)}\\n`);\n if (errors.length > 0) {\n this.process.exit(1);\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunkCM7VJEOYcjs = require('./chunk-CM7VJEOY.cjs');require('./chunk-P5GD5LAK.cjs');require('./chunk-ABKDAPPR.cjs');var _chunkWKCTKYN4cjs = require('./chunk-WKCTKYN4.cjs');var _chunk56QKBG2Rcjs = require('./chunk-56QKBG2R.cjs');require('./chunk-TSJTXXLZ.cjs');var _chunkZUNVPK23cjs = require('./chunk-ZUNVPK23.cjs');var _chunkDQCPGPXGcjs = require('./chunk-DQCPGPXG.cjs');require('./chunk-7PB6LVSE.cjs');var _querystring = require('query-string');var _colors = require('colors'); var _colors2 = _interopRequireDefault(_colors);var _fastglob = require('fast-glob'); var _fastglob2 = _interopRequireDefault(_fastglob);async function m({scanPath:t,fileGlobs:e,ignoreDirs:g,config:p}){let{ignoreDirs:f,supportedFiles:s,scanFunction:a}=p,n=e===""?s:s.concat(e.split(",")),l=[...g.split(","),...f].filter(o=>o.length>0);try{let o=await _fastglob2.default.call(void 0, `${t}/**/${n.join("|")}`,{ignore:l.map(i=>`${t}/**/${i}`),unique:!0,onlyFiles:!0});_chunkZUNVPK23cjs.a.info(`Scanning: ${o.length} files`);let I=o.map(i=>a(i)).flat().map(i=>i.softwareDevelopmentKits||[]).flat(),d=[...new Set(I.map(i=>i.name))];return _chunkZUNVPK23cjs.a.info(`Found: ${d.length} unique dependencies`),d.map(i=>({name:i,resourceId:`${t}/**/${i}`,useStrictClassifier:!0}))}catch(o){throw new Error(`Error scanning globs ${m} with error: ${o}`)}}async function P({scanPath:t,dataSiloId:e,auth:g,fileGlobs:p,ignoreDirs:f,transcendUrl:s}){_chunkWKCTKYN4cjs.a.call(void 0, this.process.exit);let a=_chunk56QKBG2Rcjs.zc.call(void 0, s,g),n=await _chunk56QKBG2Rcjs.Ec.call(void 0, a,e),l=_chunkCM7VJEOYcjs.a[n.dataSilo.type];l||(_chunkZUNVPK23cjs.a.error(_colors2.default.red(`This plugin "${n.dataSilo.type}" is not supported for offline silo discovery.`)),this.process.exit(1));let o=await m({scanPath:t,fileGlobs:p,ignoreDirs:f,config:l});await _chunk56QKBG2Rcjs.qf.call(void 0, a,n.id,o);let c=new URL(_chunkDQCPGPXGcjs.o);c.pathname="/data-map/data-inventory/silo-discovery/triage",c.search=_querystring.stringify.call(void 0, {filters:JSON.stringify({pluginIds:[n.id]})}),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Scan found ${o.length} potential data silos at ${t}! View at '${c.href}'
|
|
2
2
|
|
|
3
3
|
NOTE: it may take 2-3 minutes for scan results to appear in the UI.`))}exports.discoverSilos = P;
|
|
4
|
-
//# sourceMappingURL=impl-
|
|
4
|
+
//# sourceMappingURL=impl-4AI7T6RD.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-4AI7T6RD.cjs","../src/commands/inventory/discover-silos/impl.ts","../src/lib/code-scanning/findFilesToScan.ts"],"names":["findFilesToScan","scanPath","fileGlobs","ignoreDirs","config","IGNORE_DIRS","supportedFiles","scanFunction","globsToSupport","dirsToIgnore","dir","filesToScan","fastGlob"],"mappings":"AAAA,iOAAwC,gCAA6B,gCAA6B,wDAAyC,wDAA0D,gCAA6B,wDAAyC,wDAAyC,gCAA6B,2CCCvT,gFAEP,yFCHE,MAsBrB,SAAsBA,CAAAA,CAAgB,CACpC,QAAA,CAAAC,CAAAA,CACA,SAAA,CAAAC,CAAAA,CACA,UAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,CACF,CAAA,CASuC,CACrC,GAAM,CAAE,UAAA,CAAYC,CAAAA,CAAa,cAAA,CAAAC,CAAAA,CAAgB,YAAA,CAAAC,CAAa,CAAA,CAAIH,CAAAA,CAC5DI,CAAAA,CACJN,CAAAA,GAAc,EAAA,CACVI,CAAAA,CACAA,CAAAA,CAAe,MAAA,CAAOJ,CAAAA,CAAU,KAAA,CAAM,GAAG,CAAC,CAAA,CAC1CO,CAAAA,CAAe,CAAC,GAAGN,CAAAA,CAAW,KAAA,CAAM,GAAG,CAAA,CAAG,GAAGE,CAAW,CAAA,CAAE,MAAA,CAC7DK,CAAAA,EAAQA,CAAAA,CAAI,MAAA,CAAS,CACxB,CAAA,CACA,GAAI,CACF,IAAMC,CAAAA,CAAwB,MAAMC,gCAAAA,CAClC,EAAA;ADuByB;AAI/B,oEAAA","file":"/home/runner/work/cli/cli/dist/impl-4AI7T6RD.cjs","sourcesContent":[null,"import type { LocalContext } from '../../../context';\nimport { stringify } from 'query-string';\nimport { logger } from '../../../logger';\nimport colors from 'colors';\nimport { ADMIN_DASH } from '../../../constants';\nimport {\n fetchActiveSiloDiscoPlugin,\n buildTranscendGraphQLClient,\n uploadSiloDiscoveryResults,\n} from '../../../lib/graphql';\nimport { findFilesToScan } from '../../../lib/code-scanning/findFilesToScan';\nimport { SILO_DISCOVERY_CONFIGS } from '../../../lib/code-scanning';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation';\n\nexport interface DiscoverSilosCommandFlags {\n scanPath: string;\n dataSiloId: string;\n auth: string;\n fileGlobs: string;\n ignoreDirs: string;\n transcendUrl: string;\n}\n\nexport async function discoverSilos(\n this: LocalContext,\n {\n scanPath,\n dataSiloId,\n auth,\n fileGlobs,\n ignoreDirs,\n transcendUrl,\n }: DiscoverSilosCommandFlags,\n): Promise<void> {\n doneInputValidation(this.process.exit);\n\n // Create a GraphQL client\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n const plugin = await fetchActiveSiloDiscoPlugin(client, dataSiloId);\n\n const config = SILO_DISCOVERY_CONFIGS[plugin.dataSilo.type];\n if (!config) {\n logger.error(\n colors.red(\n `This plugin \"${plugin.dataSilo.type}\" is not supported for offline silo discovery.`,\n ),\n );\n this.process.exit(1);\n }\n\n const results = await findFilesToScan({\n scanPath,\n fileGlobs,\n ignoreDirs,\n config,\n });\n\n await uploadSiloDiscoveryResults(client, plugin.id, results);\n\n const newUrl = new URL(ADMIN_DASH);\n newUrl.pathname = '/data-map/data-inventory/silo-discovery/triage';\n newUrl.search = stringify({\n filters: JSON.stringify({ pluginIds: [plugin.id] }),\n });\n\n // Indicate success\n logger.info(\n colors.green(\n `Scan found ${results.length} potential data silos at ${scanPath}! ` +\n `View at '${newUrl.href}' ` +\n '\\n\\n NOTE: it may take 2-3 minutes for scan results to appear in the UI.',\n ),\n );\n}\n","import fastGlob from 'fast-glob';\nimport { logger } from '../../logger';\nimport { CodeScanningConfig } from './types';\n\nexport interface SiloDiscoveryRawResults {\n /** The name of the potential data silo entry */\n name: string;\n /** A unique UUID (represents the same resource across different silo discovery runs) */\n resourceId: string;\n /** Any hosts associated with the entry */\n host?: string;\n /** Type of data silo */\n type?: string | undefined;\n}\n\n/**\n * Helper to scan for data silos in all package.json files that it can find in a directory\n *\n * @deprecated TODO: https://transcend.height.app/T-32325 - use code scanning instead\n * @param options - Options\n * @returns the list of integrations\n */\nexport async function findFilesToScan({\n scanPath,\n fileGlobs,\n ignoreDirs,\n config,\n}: {\n /** Where to look for package.json files */\n scanPath: string;\n /** Globs to look for */\n fileGlobs: string;\n /** The directories to ignore (excludes node_modules and serverless-build) */\n ignoreDirs: string;\n /** Silo Discovery configuration */\n config: CodeScanningConfig;\n}): Promise<SiloDiscoveryRawResults[]> {\n const { ignoreDirs: IGNORE_DIRS, supportedFiles, scanFunction } = config;\n const globsToSupport =\n fileGlobs === ''\n ? supportedFiles\n : supportedFiles.concat(fileGlobs.split(','));\n const dirsToIgnore = [...ignoreDirs.split(','), ...IGNORE_DIRS].filter(\n (dir) => dir.length > 0,\n );\n try {\n const filesToScan: string[] = await fastGlob(\n `${scanPath}/**/${globsToSupport.join('|')}`,\n {\n ignore: dirsToIgnore.map((dir: string) => `${scanPath}/**/${dir}`),\n unique: true,\n onlyFiles: true,\n },\n );\n logger.info(`Scanning: ${filesToScan.length} files`);\n const allPackages = filesToScan\n .map((filePath: string) => scanFunction(filePath))\n .flat();\n const allSdks = allPackages\n .map((appPackage) => appPackage.softwareDevelopmentKits || [])\n .flat();\n const uniqueDeps = new Set(allSdks.map((sdk) => sdk.name));\n const deps = [...uniqueDeps];\n logger.info(`Found: ${deps.length} unique dependencies`);\n return deps.map((dep) => ({\n name: dep,\n resourceId: `${scanPath}/**/${dep}`,\n useStrictClassifier: true,\n }));\n } catch (error) {\n throw new Error(\n `Error scanning globs ${findFilesToScan} with error: ${error}`,\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunkVUQAH7YKcjs = require('./chunk-VUQAH7YK.cjs');var _chunkWKCTKYN4cjs = require('./chunk-WKCTKYN4.cjs');var _chunk56QKBG2Rcjs = require('./chunk-56QKBG2R.cjs');require('./chunk-TSJTXXLZ.cjs');var _chunkZUNVPK23cjs = require('./chunk-ZUNVPK23.cjs');require('./chunk-DQCPGPXG.cjs');require('./chunk-7PB6LVSE.cjs');var _colors = require('colors'); var _colors2 = _interopRequireDefault(_colors);var _fs = require('fs');var _path = require('path');var _cliprogress = require('cli-progress'); var _cliprogress2 = _interopRequireDefault(_cliprogress);async function G({auth:b,partition:f,sombraAuth:x,file:n="",directory:t,transcendUrl:v,timestamp:$,maxConcurrency:C,maxItemsInChunk:D,receiptDirectory:F,fileConcurrency:R}){t&&n&&(_chunkZUNVPK23cjs.a.error(_colors2.default.red("Cannot provide both a directory and a file. Please provide only one.")),this.process.exit(1)),!n&&!t&&(_chunkZUNVPK23cjs.a.error(_colors2.default.red("A file or directory must be provided. Please provide one using --file=./preferences.csv or --directory=./preferences")),this.process.exit(1)),_chunkWKCTKYN4cjs.a.call(void 0, this.process.exit);let o=[];if(t)try{let i=_fs.readdirSync.call(void 0, t).filter(m=>m.endsWith(".csv"));i.length===0&&(_chunkZUNVPK23cjs.a.error(_colors2.default.red(`No CSV files found in directory: ${t}`)),this.process.exit(1)),o.push(...i.map(m=>_path.join.call(void 0, t,m)))}catch(s){_chunkZUNVPK23cjs.a.error(_colors2.default.red(`Failed to read directory: ${t}`)),_chunkZUNVPK23cjs.a.error(_colors2.default.red(s.message)),this.process.exit(1)}else try{n.endsWith(".csv")||(_chunkZUNVPK23cjs.a.error(_colors2.default.red("File must be a CSV file")),this.process.exit(1)),o.push(n)}catch(s){_chunkZUNVPK23cjs.a.error(_colors2.default.red(`Failed to access file: ${n}`)),_chunkZUNVPK23cjs.a.error(_colors2.default.red(s.message)),this.process.exit(1)}_chunkZUNVPK23cjs.a.debug(_colors2.default.green(`Processing ${o.length} consent preferences files for partition: ${f}`)),_chunkZUNVPK23cjs.a.debug(`
|
|
2
|
+
Files to process: ${o.join(", ")}
|
|
3
|
+
`);let w=await _chunk56QKBG2Rcjs.Ac.call(void 0, v,b,x),a=new _cliprogress2.default.SingleBar({format:`Deletion Progress |${_colors2.default.cyan("[{bar}]")}| Duration: ${_colors2.default.red("{duration_formatted}")} | {value}/{total} Files Processed `},_cliprogress2.default.Presets.shades_classic);a.start(o.length,0);let I=await _chunk56QKBG2Rcjs.a.call(void 0, o,async s=>{let i=await _chunkVUQAH7YKcjs.e.call(void 0, w,{partition:f,filePath:s,timestamp:$,maxItemsInChunk:D,maxConcurrency:C});return a.increment(),i},{concurrency:R});a.stop();let c=I.flat(),l="";c.length>0&&(l=_path.join.call(void 0, F,`deletion-failures-${Date.now()}.csv`),_chunk56QKBG2Rcjs.tg.call(void 0, l,c,!0)),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`
|
|
4
|
+
|
|
5
|
+
==================================
|
|
6
|
+
|
|
7
|
+
`)),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`
|
|
8
|
+
#### Deletion Summary Report #####
|
|
9
|
+
`)),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`\u{1F4C1} Total Files Processed: ${o.length}
|
|
10
|
+
\u274C Errors: ${c.length}
|
|
11
|
+
\u{1F4DD} Receipt Path: ${l||"N/A"}`)),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`
|
|
12
|
+
|
|
13
|
+
==================================
|
|
14
|
+
|
|
15
|
+
`))}exports.deletePreferenceRecords = G;
|
|
16
|
+
//# sourceMappingURL=impl-4LAJNPQ4.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-4LAJNPQ4.cjs","../src/commands/consent/delete-preference-records/impl.ts"],"names":["deletePreferenceRecords","auth","partition","sombraAuth","file","directory","transcendUrl","timestamp","maxConcurrency","maxItemsInChunk","receiptDirectory","fileConcurrency","logger","colors","doneInputValidation","files","csvFiles","readdirSync"],"mappings":"AAAA,iOAAwC,wDAAyC,wDAAyD,gCAA6B,wDAAyC,gCAA6B,gCAA6B,gFCCvP,wBAKS,4BACP,qGAGG,MA4BxB,SAAsBA,CAAAA,CAEpB,CACE,IAAA,CAAAC,CAAAA,CACA,SAAA,CAAAC,CAAAA,CACA,UAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CAAAA,CAAO,EAAA,CACP,SAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,SAAA,CAAAC,CAAAA,CACA,cAAA,CAAAC,CAAAA,CACA,eAAA,CAAAC,CAAAA,CACA,gBAAA,CAAAC,CAAAA,CACA,eAAA,CAAAC,CACF,CAAA,CACe,CACTN,CAAAA,EAAeD,CAAAA,EAAAA,CACnBQ,mBAAAA,CAAO,KAAA,CACLC,gBAAAA,CAAO,GAAA,CACL,sEACF,CACF,CAAA,CACA,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA,CAAA,CAGjB,CAACT,CAAAA,EAAQ,CAACC,CAAAA,EAAAA,CACZO,mBAAAA,CAAO,KAAA,CACLC,gBAAAA,CAAO,GAAA,CACL,sHACF,CACF,CAAA,CACA,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA,CAAA,CAErBC,iCAAAA,IAAoB,CAAK,OAAA,CAAQ,IAAI,CAAA,CAErC,IAAMC,CAAAA,CAAkB,CAAC,CAAA,CAEzB,EAAA,CAAIV,CAAAA,CACF,GAAI,CAEF,IAAMW,CAAAA,CADmBC,6BAAAA,CAAqB,CAAA,CACZ,MAAA,CAAQb,CAAAA,EAASA,CAAAA,CAAK,QAAA,CAAS,MAAM,CAAC,CAAA,CAEpEY,CAAAA,CAAS,MAAA,GAAW,CAAA,EAAA,CACtBJ,mBAAAA,CAAO,KAAA,CACLC,gBAAAA,CAAO,GAAA,CAAI,CAAA,iCAAA,EAAoCR,CAAS,CAAA,CAAA;AAgCZ,kBAAA;AA0C3B;AAAA;AAAA;AAAA;AACA;AAAA;AAGoB;AACN,eAAA;AAId,wBAAA;AAAA;AAAA;AAAA;AAC3B","file":"/home/runner/work/cli/cli/dist/impl-4LAJNPQ4.cjs","sourcesContent":[null,"import type { LocalContext } from '../../../context';\nimport colors from 'colors';\n\nimport { createSombraGotInstance } from '../../../lib/graphql';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation';\nimport { logger } from '../../../logger';\nimport { readdirSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { map } from '../../../lib/bluebird';\nimport { bulkDeletePreferenceRecords } from '../../../lib/preference-management';\nimport cliProgress from 'cli-progress';\nimport { writeCsv } from '../../../lib/helpers';\n\nexport interface DeletePreferenceRecordsCommandFlags {\n /** Transcend API key for authentication */\n auth: string;\n /** Partition ID to delete preference records from */\n partition: string;\n /** Optional Sombra internal key for self-hosted instances */\n sombraAuth?: string;\n /** Path to the CSV file used to identify preference records to delete */\n file?: string;\n /** Path to the directory of CSV files to load preferences from */\n directory?: string;\n /** Base URL for the Transcend API */\n transcendUrl: string;\n /** The timestamp when the deletion operation is made. Used for logging purposes. */\n timestamp: Date;\n /** Maximum items to include in each deletion chunk */\n maxItemsInChunk: number;\n /** Maximum concurrency for deletion requests */\n maxConcurrency: number;\n /** Directory to write receipts of failed deletions to */\n receiptDirectory: string;\n /** Number of files to process concurrently when deleting preference records from multiple files */\n fileConcurrency: number;\n}\n\nexport async function deletePreferenceRecords(\n this: LocalContext,\n {\n auth,\n partition,\n sombraAuth,\n file = '',\n directory,\n transcendUrl,\n timestamp,\n maxConcurrency,\n maxItemsInChunk,\n receiptDirectory,\n fileConcurrency,\n }: DeletePreferenceRecordsCommandFlags,\n): Promise<void> {\n if (!!directory && !!file) {\n logger.error(\n colors.red(\n 'Cannot provide both a directory and a file. Please provide only one.',\n ),\n );\n this.process.exit(1);\n }\n\n if (!file && !directory) {\n logger.error(\n colors.red(\n 'A file or directory must be provided. Please provide one using --file=./preferences.csv or --directory=./preferences',\n ),\n );\n this.process.exit(1);\n }\n doneInputValidation(this.process.exit);\n\n const files: string[] = [];\n\n if (directory) {\n try {\n const filesInDirectory = readdirSync(directory);\n const csvFiles = filesInDirectory.filter((file) => file.endsWith('.csv'));\n\n if (csvFiles.length === 0) {\n logger.error(\n colors.red(`No CSV files found in directory: ${directory}`),\n );\n this.process.exit(1);\n }\n\n // Add full paths for each CSV file\n files.push(...csvFiles.map((file) => join(directory, file)));\n } catch (err) {\n logger.error(colors.red(`Failed to read directory: ${directory}`));\n logger.error(colors.red((err as Error).message));\n this.process.exit(1);\n }\n } else {\n try {\n // Verify file exists and is a CSV\n if (!file.endsWith('.csv')) {\n logger.error(colors.red('File must be a CSV file'));\n this.process.exit(1);\n }\n files.push(file);\n } catch (err) {\n logger.error(colors.red(`Failed to access file: ${file}`));\n logger.error(colors.red((err as Error).message));\n this.process.exit(1);\n }\n }\n\n logger.debug(\n colors.green(\n `Processing ${files.length} consent preferences files for partition: ${partition}`,\n ),\n );\n logger.debug(`\\nFiles to process: ${files.join(', ')}\\n`);\n\n // Create sombra instance to communicate with\n const sombra = await createSombraGotInstance(transcendUrl, auth, sombraAuth);\n const globalProgressBar = new cliProgress.SingleBar(\n {\n format: `Deletion Progress |${colors.cyan(\n '[{bar}]',\n )}| Duration: ${colors.red(\n '{duration_formatted}',\n )} | {value}/{total} Files Processed `,\n },\n cliProgress.Presets.shades_classic,\n );\n globalProgressBar.start(files.length, 0);\n\n // Process batch of files with concurrency\n const failedResultsArrays = await map(\n files,\n async (filePath) => {\n const result = await bulkDeletePreferenceRecords(sombra, {\n partition,\n filePath,\n timestamp,\n maxItemsInChunk,\n maxConcurrency,\n });\n globalProgressBar.increment();\n return result;\n },\n { concurrency: fileConcurrency },\n );\n globalProgressBar.stop();\n const failedResults = failedResultsArrays.flat();\n\n // Check for failed results and write receipt if any\n let receiptPath = '';\n if (failedResults.length > 0) {\n receiptPath = join(receiptDirectory, `deletion-failures-${Date.now()}.csv`);\n writeCsv(receiptPath, failedResults, true);\n }\n\n logger.info(colors.green('\\n\\n ================================== \\n\\n'));\n logger.info(colors.green('\\n#### Deletion Summary Report #####\\n'));\n logger.info(\n colors.green(\n `📁 Total Files Processed: ${files.length} \\n` +\n `❌ Errors: ${failedResults.length} \\n` +\n `📝 Receipt Path: ${receiptPath || 'N/A'}`,\n ),\n );\n logger.info(colors.green('\\n\\n==================================\\n\\n'));\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkWKCTKYN4cjs = require('./chunk-WKCTKYN4.cjs');var
|
|
2
|
-
//# sourceMappingURL=impl-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkWKCTKYN4cjs = require('./chunk-WKCTKYN4.cjs');var _chunk56QKBG2Rcjs = require('./chunk-56QKBG2R.cjs');require('./chunk-TSJTXXLZ.cjs');require('./chunk-ZUNVPK23.cjs');require('./chunk-DQCPGPXG.cjs');require('./chunk-7PB6LVSE.cjs');async function c({auth:o,dataSiloId:a,actions:r,transcendUrl:s}){_chunkWKCTKYN4cjs.a.call(void 0, this.process.exit),await _chunk56QKBG2Rcjs.Rf.call(void 0, {requestActions:r,transcendUrl:s,auth:o,dataSiloId:a})}exports.retryRequestDataSilos = c;
|
|
2
|
+
//# sourceMappingURL=impl-4YFJOKCA.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-4YFJOKCA.cjs","../src/commands/request/system/retry-request-data-silos/impl.ts"],"names":["retryRequestDataSilos","auth","dataSiloId","actions","transcendUrl","doneInputValidation"],"mappings":"AAAA,iIAAwC,wDAA0C,gCAA6B,gCAA6B,gCAA6B,gCAA6B,MCYtM,SAAsBA,CAAAA,CAEpB,CACE,IAAA,CAAAC,CAAAA,CACA,UAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CACF,CAAA,CACe,CACfC,iCAAAA,IAAoB,CAAK,OAAA,CAAQ,IAAI,CAAA,CAErC,MAAML,kCAAAA,CACJ,cAAA,CAAgBG,CAAAA,CAChB,YAAA,CAAAC,CAAAA,CACA,IAAA,CAAAH,CAAAA,CACA,UAAA,CAAAC,CACF,CAAC,CACH,CAAA,kCAAA","file":"/home/runner/work/cli/cli/dist/impl-4YFJOKCA.cjs","sourcesContent":[null,"import type { LocalContext } from '../../../../context';\nimport type { RequestAction } from '@transcend-io/privacy-types';\nimport { retryRequestDataSilos as retryRequestDataSilosHelper } from '../../../../lib/requests';\nimport { doneInputValidation } from '../../../../lib/cli/done-input-validation';\n\nexport interface RetryRequestDataSilosCommandFlags {\n auth: string;\n dataSiloId: string;\n actions: RequestAction[];\n transcendUrl: string;\n}\n\nexport async function retryRequestDataSilos(\n this: LocalContext,\n {\n auth,\n dataSiloId,\n actions,\n transcendUrl,\n }: RetryRequestDataSilosCommandFlags,\n): Promise<void> {\n doneInputValidation(this.process.exit);\n\n await retryRequestDataSilosHelper({\n requestActions: actions,\n transcendUrl,\n auth,\n dataSiloId,\n });\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkWKCTKYN4cjs = require('./chunk-WKCTKYN4.cjs');var
|
|
2
|
-
//# sourceMappingURL=impl-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkWKCTKYN4cjs = require('./chunk-WKCTKYN4.cjs');var _chunk56QKBG2Rcjs = require('./chunk-56QKBG2R.cjs');require('./chunk-TSJTXXLZ.cjs');require('./chunk-ZUNVPK23.cjs');require('./chunk-DQCPGPXG.cjs');require('./chunk-7PB6LVSE.cjs');async function d({auth:r,transcendUrl:n,actions:o,statuses:s,requestIds:a,createdAtBefore:i,createdAtAfter:c,concurrency:m}){_chunkWKCTKYN4cjs.a.call(void 0, this.process.exit),await _chunk56QKBG2Rcjs.rf.call(void 0, {transcendUrl:n,requestActions:o,auth:r,requestIds:a,statuses:s,concurrency:m,createdAtBefore:i,createdAtAfter:c})}exports.markSilent = d;
|
|
2
|
+
//# sourceMappingURL=impl-5RX3NB6C.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-5RX3NB6C.cjs","../src/commands/request/mark-silent/impl.ts"],"names":["markSilent","auth","transcendUrl","actions","statuses","requestIds","createdAtBefore","createdAtAfter","concurrency","doneInputValidation","markSilentPrivacyRequests"],"mappings":"AAAA,iIAAwC,wDAA0C,gCAA6B,gCAA6B,gCAA6B,gCAA6B,MCgBtM,SAAsBA,CAAAA,CAEpB,CACE,IAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,QAAA,CAAAC,CAAAA,CACA,UAAA,CAAAC,CAAAA,CACA,eAAA,CAAAC,CAAAA,CACA,cAAA,CAAAC,CAAAA,CACA,WAAA,CAAAC,CACF,CAAA,CACe,CACfC,iCAAAA,IAAoB,CAAK,OAAA,CAAQ,IAAI,CAAA,CAErC,MAAMC,kCAAAA,CACJ,YAAA,CAAAR,CAAAA,CACA,cAAA,CAAgBC,CAAAA,CAChB,IAAA,CAAAF,CAAAA,CACA,UAAA,CAAAI,CAAAA,CACA,QAAA,CAAAD,CAAAA,CACA,WAAA,CAAAI,CAAAA,CACA,eAAA,CAAAF,CAAAA,CACA,cAAA,CAAAC,CACF,CAAC,CACH,CAAA,uBAAA","file":"/home/runner/work/cli/cli/dist/impl-5RX3NB6C.cjs","sourcesContent":[null,"import type { LocalContext } from '../../../context';\nimport { markSilentPrivacyRequests } from '../../../lib/requests';\nimport type { RequestAction, RequestStatus } from '@transcend-io/privacy-types';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation';\n\nexport interface MarkSilentCommandFlags {\n auth: string;\n actions: RequestAction[];\n statuses?: RequestStatus[];\n requestIds?: string[];\n createdAtBefore?: Date;\n createdAtAfter?: Date;\n transcendUrl: string;\n concurrency: number;\n}\n\nexport async function markSilent(\n this: LocalContext,\n {\n auth,\n transcendUrl,\n actions,\n statuses,\n requestIds,\n createdAtBefore,\n createdAtAfter,\n concurrency,\n }: MarkSilentCommandFlags,\n): Promise<void> {\n doneInputValidation(this.process.exit);\n\n await markSilentPrivacyRequests({\n transcendUrl,\n requestActions: actions,\n auth,\n requestIds,\n statuses,\n concurrency,\n createdAtBefore,\n createdAtAfter,\n });\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var
|
|
2
|
-
//# sourceMappingURL=impl-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkLQUVB4MIcjs = require('./chunk-LQUVB4MI.cjs');var _chunkWKCTKYN4cjs = require('./chunk-WKCTKYN4.cjs');var _chunk56QKBG2Rcjs = require('./chunk-56QKBG2R.cjs');require('./chunk-TSJTXXLZ.cjs');var _chunkZUNVPK23cjs = require('./chunk-ZUNVPK23.cjs');var _chunkDQCPGPXGcjs = require('./chunk-DQCPGPXG.cjs');require('./chunk-7PB6LVSE.cjs');var _colors = require('colors'); var _colors2 = _interopRequireDefault(_colors);async function v({auth:y,file:a,transcendUrl:C,dataSiloIds:f,includeAttributes:D,includeGuessedCategories:P,parentCategories:b,subCategories:h=[]}){_chunkWKCTKYN4cjs.a.call(void 0, this.process.exit);try{let o=_chunk56QKBG2Rcjs.zc.call(void 0, C,y),$=await _chunkLQUVB4MIcjs.a.call(void 0, o,{dataSiloIds:f,includeGuessedCategories:P,parentCategories:b,includeAttributes:D,subCategories:h});_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Writing datapoints to file "${a}"...`));let s=[],j=$.map(t=>{let n={"Property ID":t.id,"Data Silo":t.dataSilo.title,Object:t.dataPoint.name,"Object Path":t.dataPoint.path.join("."),Property:t.name,"Property Description":t.description,"Data Categories":t.categories.map(e=>`${e.category}:${e.name}`).join(", "),"Guessed Category":_optionalChain([t, 'access', _ => _.pendingCategoryGuesses, 'optionalAccess', _2 => _2[0]])?`${t.pendingCategoryGuesses[0].category.category}:${t.pendingCategoryGuesses[0].category.name}`:"","Processing Purposes":t.purposes.map(e=>`${e.purpose}:${e.name}`).join(", "),...Object.entries(_chunkDQCPGPXGcjs.d.call(void 0, t.attributeValues||[],({attributeKey:e})=>e.name)).reduce((e,[x,A])=>(e[x]=A.map(G=>G.name).join(","),e),{})};return s=_chunkDQCPGPXGcjs.j.call(void 0, [...s,...Object.keys(n)]),n});await _chunk56QKBG2Rcjs.vg.call(void 0, a,j,s)}catch(o){_chunkZUNVPK23cjs.a.error(_colors2.default.red(`An error occurred syncing the datapoints: ${o.message}`)),this.process.exit(1)}_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Successfully synced datapoints to disk at ${a}! View at ${_chunkDQCPGPXGcjs.q}`))}exports.pullDatapoints = v;
|
|
2
|
+
//# sourceMappingURL=impl-66CDS7IN.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-66CDS7IN.cjs","../src/commands/inventory/pull-datapoints/impl.ts"],"names":["pullDatapoints","auth","file","transcendUrl","dataSiloIds","includeAttributes","includeGuessedCategories","parentCategories","subCategories","doneInputValidation","client","buildTranscendGraphQLClient","dataPoints","pullAllDatapoints","logger","colors","headers","inputs","point","result","category"],"mappings":"AAAA,quBAAwC,wDAAyC,wDAAkD,gCAA6B,wDAAyC,wDAAuD,gCAA6B,gFCI1Q,MAmBnB,SAAsBA,CAAAA,CAEpB,CACE,IAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,WAAA,CAAAC,CAAAA,CACA,iBAAA,CAAAC,CAAAA,CACA,wBAAA,CAAAC,CAAAA,CACA,gBAAA,CAAAC,CAAAA,CACA,aAAA,CAAAC,CAAAA,CAAgB,CAAC,CACnB,CAAA,CACe,CACfC,iCAAAA,IAAoB,CAAK,OAAA,CAAQ,IAAI,CAAA,CAErC,GAAI,CAEF,IAAMC,CAAAA,CAASC,kCAAAA,CAA4BR,CAAcF,CAAI,CAAA,CAEvDW,CAAAA,CAAa,MAAMC,iCAAAA,CAAkBH,CAAQ,CACjD,WAAA,CAAAN,CAAAA,CACA,wBAAA,CAAAE,CAAAA,CACA,gBAAA,CAAAC,CAAAA,CACA,iBAAA,CAAAF,CAAAA,CACA,aAAA,CAAAG,CACF,CAAC,CAAA,CAEDM,mBAAAA,CAAO,IAAA,CAAKC,gBAAAA,CAAO,OAAA,CAAQ,CAAA,4BAAA,EAA+Bb,CAAI,CAAA,IAAA,CAAM,CAAC,CAAA,CACrE,IAAIc,CAAAA,CAAoB,CAAC,CAAA,CACnBC,CAAAA,CAASL,CAAAA,CAAW,GAAA,CAAKM,CAAAA,EAAU,CACvC,IAAMC,CAAAA,CAAS,CACb,aAAA,CAAeD,CAAAA,CAAM,EAAA,CACrB,WAAA,CAAaA,CAAAA,CAAM,QAAA,CAAS,KAAA,CAC5B,MAAA,CAAQA,CAAAA,CAAM,SAAA,CAAU,IAAA,CACxB,aAAA,CAAeA,CAAAA,CAAM,SAAA,CAAU,IAAA,CAAK,IAAA,CAAK,GAAG,CAAA,CAC5C,QAAA,CAAUA,CAAAA,CAAM,IAAA,CAChB,sBAAA,CAAwBA,CAAAA,CAAM,WAAA,CAC9B,iBAAA,CAAmBA,CAAAA,CAAM,UAAA,CACtB,GAAA,CAAKE,CAAAA,EAAa,CAAA,EAAA","file":"/home/runner/work/cli/cli/dist/impl-66CDS7IN.cjs","sourcesContent":[null,"import type { LocalContext } from '../../../context';\nimport { uniq, groupBy } from 'lodash-es';\n\nimport { logger } from '../../../logger';\nimport colors from 'colors';\nimport { buildTranscendGraphQLClient } from '../../../lib/graphql';\nimport { ADMIN_DASH_DATAPOINTS } from '../../../constants';\nimport { pullAllDatapoints } from '../../../lib/data-inventory';\nimport { DataCategoryType } from '@transcend-io/privacy-types';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation';\nimport { writeLargeCsv } from '../../../lib/helpers';\n\nexport interface PullDatapointsCommandFlags {\n auth: string;\n file: string;\n transcendUrl: string;\n dataSiloIds?: string[];\n includeAttributes: boolean;\n includeGuessedCategories: boolean;\n parentCategories?: DataCategoryType[];\n subCategories?: string[];\n}\n\nexport async function pullDatapoints(\n this: LocalContext,\n {\n auth,\n file,\n transcendUrl,\n dataSiloIds,\n includeAttributes,\n includeGuessedCategories,\n parentCategories,\n subCategories = [],\n }: PullDatapointsCommandFlags,\n): Promise<void> {\n doneInputValidation(this.process.exit);\n\n try {\n // Create a GraphQL client\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n const dataPoints = await pullAllDatapoints(client, {\n dataSiloIds,\n includeGuessedCategories,\n parentCategories,\n includeAttributes,\n subCategories, // TODO: https://transcend.height.app/T-40482 - do by name not ID\n });\n\n logger.info(colors.magenta(`Writing datapoints to file \"${file}\"...`));\n let headers: string[] = [];\n const inputs = dataPoints.map((point) => {\n const result = {\n 'Property ID': point.id,\n 'Data Silo': point.dataSilo.title,\n Object: point.dataPoint.name,\n 'Object Path': point.dataPoint.path.join('.'),\n Property: point.name,\n 'Property Description': point.description,\n 'Data Categories': point.categories\n .map((category) => `${category.category}:${category.name}`)\n .join(', '),\n 'Guessed Category': point.pendingCategoryGuesses?.[0]\n ? `${point.pendingCategoryGuesses![0]!.category.category}:${\n point.pendingCategoryGuesses![0]!.category.name\n }`\n : '',\n 'Processing Purposes': point.purposes\n .map((purpose) => `${purpose.purpose}:${purpose.name}`)\n .join(', '),\n ...Object.entries(\n groupBy(\n point.attributeValues || [],\n ({ attributeKey }) => attributeKey.name,\n ),\n ).reduce((acc, [key, values]) => {\n acc[key] = values.map((value) => value.name).join(',');\n return acc;\n }, {} as Record<string, string>),\n };\n headers = uniq([...headers, ...Object.keys(result)]);\n return result;\n });\n await writeLargeCsv(file, inputs, headers);\n } catch (err) {\n logger.error(\n colors.red(`An error occurred syncing the datapoints: ${err.message}`),\n );\n this.process.exit(1);\n }\n\n // Indicate success\n logger.info(\n colors.green(\n `Successfully synced datapoints to disk at ${file}! View at ${ADMIN_DASH_DATAPOINTS}`,\n ),\n );\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkWKCTKYN4cjs = require('./chunk-WKCTKYN4.cjs');var
|
|
2
|
-
//# sourceMappingURL=impl-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkWKCTKYN4cjs = require('./chunk-WKCTKYN4.cjs');var _chunk56QKBG2Rcjs = require('./chunk-56QKBG2R.cjs');require('./chunk-TSJTXXLZ.cjs');require('./chunk-ZUNVPK23.cjs');require('./chunk-DQCPGPXG.cjs');require('./chunk-7PB6LVSE.cjs');async function p({auth:r,actions:s,statuses:i=[],requestIds:c,silentModeBefore:e,createdAtBefore:t,createdAtAfter:n,cancellationTitle:u,transcendUrl:d,concurrency:l}){_chunkWKCTKYN4cjs.a.call(void 0, this.process.exit),await _chunk56QKBG2Rcjs.Jf.call(void 0, {transcendUrl:d,requestActions:s,auth:r,cancellationTitle:u,requestIds:c,statuses:i,concurrency:l,silentModeBefore:e?new Date(e):void 0,createdAtBefore:t?new Date(t):void 0,createdAtAfter:n?new Date(n):void 0})}exports.cancel = p;
|
|
2
|
+
//# sourceMappingURL=impl-ADPBEB3N.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-ADPBEB3N.cjs","../src/commands/request/cancel/impl.ts"],"names":["cancel","auth","actions","statuses","requestIds","silentModeBefore","createdAtBefore","createdAtAfter","cancellationTitle","transcendUrl","concurrency","doneInputValidation","cancelPrivacyRequests"],"mappings":"AAAA,iIAAwC,wDAA0C,gCAA6B,gCAA6B,gCAA6B,gCAA6B,MCkBtM,SAAsBA,CAAAA,CAEpB,CACE,IAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,QAAA,CAAAC,CAAAA,CAAW,CAAC,CAAA,CACZ,UAAA,CAAAC,CAAAA,CACA,gBAAA,CAAAC,CAAAA,CACA,eAAA,CAAAC,CAAAA,CACA,cAAA,CAAAC,CAAAA,CACA,iBAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,WAAA,CAAAC,CACF,CAAA,CACe,CACfC,iCAAAA,IAAoB,CAAK,OAAA,CAAQ,IAAI,CAAA,CAErC,MAAMC,kCAAAA,CACJ,YAAA,CAAAH,CAAAA,CACA,cAAA,CAAgBP,CAAAA,CAChB,IAAA,CAAAD,CAAAA,CACA,iBAAA,CAAAO,CAAAA,CACA,UAAA,CAAAJ,CAAAA,CACA,QAAA,CAAAD,CAAAA,CACA,WAAA,CAAAO,CAAAA,CACA,gBAAA,CAAkBL,CAAAA,CAAmB,IAAI,IAAA,CAAKA,CAAgB,CAAA,CAAI,KAAA,CAAA,CAClE,eAAA,CAAiBC,CAAAA,CAAkB,IAAI,IAAA,CAAKA,CAAe,CAAA,CAAI,KAAA,CAAA,CAC/D,cAAA,CAAgBC,CAAAA,CAAiB,IAAI,IAAA,CAAKA,CAAc,CAAA,CAAI,KAAA,CAC9D,CAAC,CACH,CAAA,mBAAA","file":"/home/runner/work/cli/cli/dist/impl-ADPBEB3N.cjs","sourcesContent":[null,"import type { LocalContext } from '../../../context';\nimport { RequestAction, RequestStatus } from '@transcend-io/privacy-types';\nimport { cancelPrivacyRequests } from '../../../lib/requests';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation';\n\nexport interface CancelCommandFlags {\n auth: string;\n actions: RequestAction[];\n statuses?: RequestStatus[];\n requestIds?: string[];\n silentModeBefore?: Date;\n createdAtBefore?: Date;\n createdAtAfter?: Date;\n cancellationTitle: string;\n transcendUrl: string;\n concurrency: number;\n}\n\nexport async function cancel(\n this: LocalContext,\n {\n auth,\n actions,\n statuses = [],\n requestIds,\n silentModeBefore,\n createdAtBefore,\n createdAtAfter,\n cancellationTitle,\n transcendUrl,\n concurrency,\n }: CancelCommandFlags,\n): Promise<void> {\n doneInputValidation(this.process.exit);\n\n await cancelPrivacyRequests({\n transcendUrl,\n requestActions: actions,\n auth,\n cancellationTitle,\n requestIds,\n statuses,\n concurrency,\n silentModeBefore: silentModeBefore ? new Date(silentModeBefore) : undefined,\n createdAtBefore: createdAtBefore ? new Date(createdAtBefore) : undefined,\n createdAtAfter: createdAtAfter ? new Date(createdAtAfter) : undefined,\n });\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkWKCTKYN4cjs = require('./chunk-WKCTKYN4.cjs');var
|
|
2
|
-
//# sourceMappingURL=impl-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkWKCTKYN4cjs = require('./chunk-WKCTKYN4.cjs');var _chunk56QKBG2Rcjs = require('./chunk-56QKBG2R.cjs');require('./chunk-TSJTXXLZ.cjs');var _chunkZUNVPK23cjs = require('./chunk-ZUNVPK23.cjs');require('./chunk-DQCPGPXG.cjs');require('./chunk-7PB6LVSE.cjs');var _iots = require('io-ts'); var c = _interopRequireWildcard(_iots);var _colors = require('colors'); var _colors2 = _interopRequireDefault(_colors);var _fs = require('fs');var _cliprogress = require('cli-progress'); var _cliprogress2 = _interopRequireDefault(_cliprogress);var _privacytypes = require('@transcend-io/privacy-types');async function U({auth:k,file:s,transcendUrl:$,duration:A,subjectType:P,emailColumnName:a,coreIdentifierColumnName:r}){_chunkWKCTKYN4cjs.a.call(void 0, this.process.exit),_fs.existsSync.call(void 0, s)||(_chunkZUNVPK23cjs.a.error(_colors2.default.red(`File does not exist: "${s}". Please provide a valid path to a CSV file.`)),this.process.exit(1));try{let p=_chunk56QKBG2Rcjs.zc.call(void 0, $,k),b=c.type({[a]:c.string,...r?{[r]:c.string}:{}}),n=_chunk56QKBG2Rcjs.uc.call(void 0, s,b);if(!n.length)throw new Error("Input CSV is empty.");let h=n.map((e,t)=>[e,t]).filter(([e])=>!_optionalChain([e, 'access', _ => _[a], 'optionalAccess', _2 => _2.trim, 'call', _3 => _3()]));if(h.length){let e=h.map(([,t])=>t+2).join(", ");throw new Error(`The following rows are missing the required "${a}" column: ${e}`)}if(r){let e=n.map((t,o)=>[t,o]).filter(([t])=>!_optionalChain([t, 'access', _4 => _4[r], 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()]));if(e.length){let t=e.map(([,o])=>o+2).join(", ");throw new Error(`The following rows are missing the required "${r}" column: ${t}`)}}let I=Math.max(1,Math.floor(A/1e3)),d=n.map((e,t)=>{let o=e[a].trim(),f=r?_optionalChain([e, 'access', _7 => _7[r], 'optionalAccess', _8 => _8.trim, 'call', _9 => _9()]):void 0,j=[_privacytypes.SombraStandardScope.PreferenceManagement];return{subjectType:P,scopes:j,expiresIn:I,email:o,...f?{coreIdentifier:f}:{},index:t}}),m=new _cliprogress2.default.SingleBar({},_cliprogress2.default.Presets.shades_classic);m.start(d.length,0);let v=Date.now(),l=await _chunk56QKBG2Rcjs.Mc.call(void 0, p,d,e=>{m.update(e)});m.update(d.length),m.stop();let E=l.map(({accessToken:e,input:t})=>{if(typeof t.index!="number")throw new Error("Internal error: missing input index.");return{...n[t.index],token:e}});_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Writing access tokens to file "${s}"...`)),await _chunk56QKBG2Rcjs.tg.call(void 0, s,E,!0);let M=Math.round((Date.now()-v)/1e3);_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Successfully generated ${l.length} access tokens to "${s}" in ${M}s!`))}catch(p){_chunkZUNVPK23cjs.a.error(_colors2.default.red(`An error occurred while generating access tokens: ${_optionalChain([p, 'optionalAccess', _10 => _10.message])||String(p)}`)),this.process.exit(1)}}exports.generateAccessTokens = U;
|
|
2
|
+
//# sourceMappingURL=impl-B6DTQRYV.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/impl-B6DTQRYV.cjs","../src/commands/consent/generate-access-tokens/impl.ts"],"names":["generateAccessTokens","auth","file","transcendUrl","duration","subjectType","emailColumnName","coreIdentifierColumnName","doneInputValidation","existsSync","logger","colors","client","buildTranscendGraphQLClient","codec","rows","readCsv","missingEmail","r","i","rowNumbers"],"mappings":"AAAA,u/BAAwC,wDAAkE,gCAA6B,wDAAyC,gCAA6B,gCAA6B,qECCvN,gFACA,wBAGQ,qGACH,2DAOY,MA4BpC,SAAsBA,CAAAA,CAEpB,CACE,IAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,QAAA,CAAAC,CAAAA,CACA,WAAA,CAAAC,CAAAA,CACA,eAAA,CAAAC,CAAAA,CACA,wBAAA,CAAAC,CACF,CAAA,CACe,CACfC,iCAAAA,IAAoB,CAAK,OAAA,CAAQ,IAAI,CAAA,CAChCC,4BAAAA,CAAe,CAAA,EAAA,CAClBC,mBAAAA,CAAO,KAAA,CACLC,gBAAAA,CAAO,GAAA,CACL,CAAA,sBAAA,EAAyBT,CAAI,CAAA,6CAAA,CAC/B,CACF,CAAA,CACA,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA,CAAA,CAGrB,GAAI,CAEF,IAAMU,CAAAA,CAASC,kCAAAA,CAA4BV,CAAcF,CAAI,CAAA,CAGvDa,CAAAA,CAAU,CAAA,CAAA,IAAA,CAAK,CACnB,CAACR,CAAe,CAAA,CAAK,CAAA,CAAA,MAAA,CACrB,GAAIC,CAAAA,CACA,CAAE,CAACA,CAAwB,CAAA,CAAK,CAAA,CAAA,MAAO,CAAA,CACvC,CAAC,CACP,CAAC,CAAA,CACKQ,CAAAA,CAAsCC,kCAAAA,CAAQd,CAAMY,CAAK,CAAA,CAC/D,EAAA,CAAI,CAACC,CAAAA,CAAK,MAAA,CACR,MAAM,IAAI,KAAA,CAAM,qBAAqB,CAAA,CAIvC,IAAME,CAAAA,CAAeF,CAAAA,CAClB,GAAA,CAAI,CAACG,CAAAA,CAAGC,CAAAA,CAAAA,EAAM,CAACD,CAAAA,CAAGC,CAAC,CAAU,CAAA,CAC7B,MAAA,CAAO,CAAC,CAACD,CAAC,CAAA,CAAA,EAAM,iBAACA,CAAAA,mBAAEZ,CAAe,CAAA,6BAAG,IAAA,mBAAK,GAAC,CAAA,CAC9C,EAAA,CAAIW,CAAAA,CAAa,MAAA,CAAQ,CACvB,IAAMG,CAAAA,CAAaH,CAAAA,CAChB,GAAA,CAAI,CAAC,CAAC,CAAEE,CAAC,CAAA,CAAA,EAAMA,CAAAA,CAAI,CAAC,CAAA,CACpB,IAAA,CAAK,IAAI,CAAA,CACZ,MAAM,IAAI,KAAA,CACR,CAAA,6CAAA,EAAgDb,CAAe,CAAA,UAAA,EAAac,CAAU,CAAA,CAAA","file":"/home/runner/work/cli/cli/dist/impl-B6DTQRYV.cjs","sourcesContent":[null,"import type { LocalContext } from '../../../context';\nimport * as t from 'io-ts';\nimport colors from 'colors';\nimport { logger } from '../../../logger';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation';\nimport { existsSync } from 'node:fs';\nimport cliProgress from 'cli-progress';\nimport {\n buildTranscendGraphQLClient,\n createPreferenceAccessTokens,\n type PreferenceAccessTokenInputWithIndex,\n} from '../../../lib/graphql';\nimport { readCsv } from '../../../lib/requests';\nimport { SombraStandardScope } from '@transcend-io/privacy-types';\nimport { writeCsv } from '../../../lib/helpers';\n\n/**\n * CLI flags accepted by the `generate-access-tokens` command.\n *\n * These are passed down from the CLI parser into the parent process.\n */\nexport type GenerateAccessTokenCommandFlags = {\n auth: string;\n file: string;\n duration: number;\n transcendUrl: string;\n subjectType: string;\n emailColumnName: string;\n coreIdentifierColumnName?: string;\n};\n\n/**\n * Take in a CSV of user identifiers and generate access tokens for each user.\n *\n * Expected CSV columns:\n * - [emailColumnName] (required)\n * - [coreIdentifierColumnName] (optional)\n *\n * @param this - Bound CLI context (provides process exit + logging).\n * @param flags - CLI options for the run.\n */\nexport async function generateAccessTokens(\n this: LocalContext,\n {\n auth,\n file,\n transcendUrl,\n duration,\n subjectType,\n emailColumnName,\n coreIdentifierColumnName,\n }: GenerateAccessTokenCommandFlags,\n): Promise<void> {\n doneInputValidation(this.process.exit);\n if (!existsSync(file)) {\n logger.error(\n colors.red(\n `File does not exist: \"${file}\". Please provide a valid path to a CSV file.`,\n ),\n );\n this.process.exit(1);\n }\n\n try {\n // Create a GraphQL client\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n // Read + parse CSV\n const codec = t.type({\n [emailColumnName]: t.string,\n ...(coreIdentifierColumnName\n ? { [coreIdentifierColumnName]: t.string }\n : {}),\n });\n const rows: Array<Record<string, string>> = readCsv(file, codec);\n if (!rows.length) {\n throw new Error('Input CSV is empty.');\n }\n\n // Ensure emails and core identifiers exist\n const missingEmail = rows\n .map((r, i) => [r, i] as const)\n .filter(([r]) => !r[emailColumnName]?.trim());\n if (missingEmail.length) {\n const rowNumbers = missingEmail\n .map(([, i]) => i + 2) // +2 to account for header row and 0-indexing\n .join(', ');\n throw new Error(\n `The following rows are missing the required \"${emailColumnName}\" column: ${rowNumbers}`,\n );\n }\n if (coreIdentifierColumnName) {\n const missingCoreId = rows\n .map((r, i) => [r, i] as const)\n .filter(([r]) => !r[coreIdentifierColumnName]?.trim());\n if (missingCoreId.length) {\n const rowNumbers = missingCoreId\n .map(([, i]) => i + 2) // +2 to account for header row and 0-indexing\n .join(', ');\n throw new Error(\n `The following rows are missing the required \"${coreIdentifierColumnName}\" column: ${rowNumbers}`,\n );\n }\n }\n\n // Duration provided by CLI is in ms; GraphQL expects seconds\n const expiresInSeconds = Math.max(1, Math.floor(duration / 1000));\n\n // Build inputs for GraphQL\n const inputs = rows.map((r, index): PreferenceAccessTokenInputWithIndex => {\n const email = r[emailColumnName].trim();\n const coreIdentifier = coreIdentifierColumnName\n ? r[coreIdentifierColumnName]?.trim()\n : undefined;\n const scopes = [SombraStandardScope.PreferenceManagement];\n return {\n subjectType,\n scopes,\n expiresIn: expiresInSeconds,\n email,\n ...(coreIdentifier ? { coreIdentifier } : {}),\n index,\n };\n });\n\n // Progress bar\n const progressBar = new cliProgress.SingleBar(\n {},\n cliProgress.Presets.shades_classic,\n );\n progressBar.start(inputs.length, 0);\n\n // Kick off token creation (batched internally)\n const t0 = Date.now();\n const results = await createPreferenceAccessTokens(\n client,\n inputs,\n (progress) => {\n progressBar.update(progress);\n },\n );\n progressBar.update(inputs.length);\n progressBar.stop();\n\n // Prepare output CSV rows\n const outputRows = results.map(({ accessToken, input }) => {\n if (typeof input.index !== 'number') {\n throw new Error('Internal error: missing input index.');\n }\n return {\n ...rows[input.index],\n token: accessToken,\n };\n });\n\n logger.info(colors.magenta(`Writing access tokens to file \"${file}\"...`));\n await writeCsv(file, outputRows, true);\n\n const totalTimeSec = Math.round((Date.now() - t0) / 1000);\n logger.info(\n colors.green(\n `Successfully generated ${results.length} access tokens to \"${file}\" in ${totalTimeSec}s!`,\n ),\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (err: any) {\n logger.error(\n colors.red(\n `An error occurred while generating access tokens: ${\n err?.message || String(err)\n }`,\n ),\n );\n this.process.exit(1);\n }\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunk22KX2NM4cjs = require('./chunk-22KX2NM4.cjs');var _chunkWKCTKYN4cjs = require('./chunk-WKCTKYN4.cjs');var _chunk56QKBG2Rcjs = require('./chunk-56QKBG2R.cjs');require('./chunk-TSJTXXLZ.cjs');var _chunkZUNVPK23cjs = require('./chunk-ZUNVPK23.cjs');require('./chunk-DQCPGPXG.cjs');require('./chunk-7PB6LVSE.cjs');var _colors = require('colors'); var _colors2 = _interopRequireDefault(_colors);var _path = require('path');var _fs = require('fs');function H(r,e){r||(_chunkZUNVPK23cjs.a.error(_colors2.default.red("A --directory must be provided.")),e.process.exit(1));let n=[];try{n=_fs.readdirSync.call(void 0, r).filter(s=>s.endsWith(".csv")).map(s=>_path.join.call(void 0, r,s)).filter(s=>{try{return _fs.statSync.call(void 0, s).isFile()}catch (e2){return!1}})}catch(i){_chunkZUNVPK23cjs.a.error(_colors2.default.red(`Failed to read directory: ${r}`)),_chunkZUNVPK23cjs.a.error(_colors2.default.red(i.message)),e.process.exit(1)}return n.length===0&&(_chunkZUNVPK23cjs.a.error(_colors2.default.red(`No CSV files found in directory: ${r}`)),e.process.exit(1)),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Found: ${n.join(", ")} CSV files`)),n}var _promises = require('fs/promises');var _promises3 = require('stream/promises');var _stream = require('stream');var _events = require('events');var _csvparse = require('csv-parse');var _fastcsv = require('fast-csv'); var K = _interopRequireWildcard(_fastcsv);function M(r,e){let n=_fs.createWriteStream.call(void 0, r),i=K.format({headers:e,writeHeaders:!0,objectMode:!0});return i.pipe(n),{async write(s){i.write(s)||await _events.once.call(void 0, i,"drain")},async end(){let s=Promise.all([_events.once.call(void 0, n,"finish")]);i.end(),await s}}}function me(r){return String(r).padStart(4,"0")}function fe(r){return Buffer.byteLength(Object.values(r).map(e=>e==null?"":String(e)).join(","),"utf8")}async function N(r){let{filePath:e,outputDir:n,clearOutputDir:i,chunkSizeMB:s,onProgress:f,reportEveryMs:g=500}=r,{size:l}=await _promises.stat.call(void 0, e),u=0;_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Chunking ${e} into ~${s}MB files...`));let C=Math.floor(s*1024*1024),w=_path.basename.call(void 0, e,".csv"),d=n||_path.dirname.call(void 0, e);if(_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Output directory: ${d}`)),await _promises.mkdir.call(void 0, d,{recursive:!0}),i){_chunkZUNVPK23cjs.a.warn(_colors2.default.yellow(`Clearing output directory: ${d}`));let a=await _promises.readdir.call(void 0, d);await Promise.all(a.filter(m=>m.startsWith(`${w}_chunk_`)&&m.endsWith(".csv")).map(m=>_promises.unlink.call(void 0, _path.join.call(void 0, d,m))))}let t=null,h=null,c=0,P=1,v=0,G=new (0, _csvparse.Parser)({columns:!1,skip_empty_lines:!0}),O=0,b=0,S=()=>{let a=b>0?O/b:0,m=a>0?Math.max(c,Math.ceil(l/a)):void 0;f(c,m),u=Date.now()};S();let p=null,$=()=>_path.join.call(void 0, d,`${w}_chunk_${me(P)}.csv`),U=new (0, _stream.Transform)({objectMode:!0,async transform(a,m,T){try{if(!t){t=a.slice(0),h=t.length,p=M($(),t),T();return}h!==null&&a.length!==h&&_chunkZUNVPK23cjs.a.warn(_colors2.default.yellow(`Row has ${a.length} cols; expected ${h}`)),c+=1,c%25e4===0&&f(c);let x=Object.fromEntries(t.map((Q,X)=>[Q,a[X]])),D=fe(x);O+=D,b+=1,Date.now()-u>=g&&S(),p&&v>0&&v+D>C&&(await p.end(),P+=1,v=0,_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Rolling to chunk ${P} after ${c.toLocaleString()} rows.`)),p=M($(),t)),p||(p=M($(),t)),await p.write(x),v+=D,T()}catch(x){T(x)}},async flush(a){try{p&&(await p.end(),p=null),S(),a()}catch(m){a(m)}}}),J=_fs.createReadStream.call(void 0, e);await _promises3.pipeline.call(void 0, J,G,U),f(c),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Chunked ${e} into ${P} file(s); processed ${c.toLocaleString()} rows.`))}async function A(){let r=Number(process.env.WORKER_ID||"0");_chunkZUNVPK23cjs.a.info(`[w${r}] ready pid=${process.pid}`),_optionalChain([process, 'access', _2 => _2.send, 'optionalCall', _3 => _3({type:"ready"})]),process.on("message",async e=>{if(!e||typeof e!="object"||(e.type==="shutdown"&&process.exit(0),e.type!=="task"))return;let{filePath:n,options:i}=e.payload,{outputDir:s,clearOutputDir:f,chunkSizeMB:g}=i;try{await N({filePath:n,outputDir:s,clearOutputDir:f,chunkSizeMB:g,onProgress:(l,u)=>_optionalChain([process, 'access', _4 => _4.send, 'optionalCall', _5 => _5({type:"progress",payload:{filePath:n,processed:l,total:u}})])}),_optionalChain([process, 'access', _6 => _6.send, 'optionalCall', _7 => _7({type:"result",payload:{ok:!0,filePath:n}})])}catch(l){let u=_chunk56QKBG2Rcjs._f.call(void 0, l);_chunkZUNVPK23cjs.a.error(`[w${r}] ERROR ${n}: ${u}`),_optionalChain([process, 'access', _8 => _8.send, 'optionalCall', _9 => _9({type:"result",payload:{ok:!1,filePath:n,error:u}})])}}),await new Promise(()=>{})}function de(r){return _chunk22KX2NM4cjs.d.call(void 0, r)}function he(r){return _chunk22KX2NM4cjs.e.call(void 0, r)}var q={renderHeader:de,renderWorkers:he};function ke(){return typeof __filename<"u"?__filename:process.argv[1]}async function Ue(r){_chunkWKCTKYN4cjs.a.call(void 0, this.process.exit);let{directory:e,outputDir:n,clearOutputDir:i,chunkSizeMB:s,concurrency:f,viewerMode:g}=r,l=H(e,this),{poolSize:u,cpuCount:C}=_chunk22KX2NM4cjs.a.call(void 0, f,l.length);_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Chunking ${l.length} CSV file(s) with pool size ${u} (CPU=${C})`));let w=l.map(t=>({filePath:t,options:{outputDir:n,clearOutputDir:i,chunkSizeMB:s}})),d={nextTask:()=>w.shift(),taskLabel:t=>t.filePath,initTotals:()=>({}),initSlotProgress:()=>{},onProgress:t=>t,onResult:(t,h)=>({totals:t,ok:!!h.ok}),postProcess:async()=>{}};await _chunk22KX2NM4cjs.f.call(void 0, {title:`Chunk CSV - ${e}`,baseDir:e||n||process.cwd(),childFlag:_chunk22KX2NM4cjs.b,childModulePath:ke(),poolSize:u,cpuCount:C,filesTotal:l.length,hooks:d,viewerMode:g,render:t=>_chunk22KX2NM4cjs.c.call(void 0, t,q,g),extraKeyHandler:({logsBySlot:t,repaint:h,setPaused:c})=>_chunk22KX2NM4cjs.g.call(void 0, {logsBySlot:t,repaint:h,setPaused:c})})}process.argv.includes(_chunk22KX2NM4cjs.b)&&A().catch(r=>{_chunkZUNVPK23cjs.a.error(r),process.exit(1)});exports.chunkCsv = Ue;
|
|
2
|
+
//# sourceMappingURL=impl-BHA2L6BP.cjs.map
|