@transcend-io/cli 8.31.1 → 8.32.6
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-5UWKWV3X.cjs +2 -0
- package/dist/chunk-5UWKWV3X.cjs.map +1 -0
- package/dist/chunk-CDX243U3.cjs +2 -0
- package/dist/{chunk-Q2RJZGYW.cjs.map → chunk-CDX243U3.cjs.map} +1 -1
- package/dist/{chunk-XXFLFF7Q.cjs → chunk-GJ6V5BHG.cjs} +2 -2
- package/dist/{chunk-XXFLFF7Q.cjs.map → chunk-GJ6V5BHG.cjs.map} +1 -1
- package/dist/{chunk-ALOB5SWZ.cjs → chunk-I6GMLKI6.cjs} +2 -2
- package/dist/{chunk-ALOB5SWZ.cjs.map → chunk-I6GMLKI6.cjs.map} +1 -1
- package/dist/chunk-LE6FS55Q.cjs +12 -0
- package/dist/chunk-LE6FS55Q.cjs.map +1 -0
- package/dist/chunk-MLH6KKUK.cjs +12 -0
- package/dist/chunk-MLH6KKUK.cjs.map +1 -0
- package/dist/chunk-NZEATKWL.cjs +2 -0
- package/dist/chunk-NZEATKWL.cjs.map +1 -0
- package/dist/chunk-O7SJYOEK.cjs +3 -0
- package/dist/chunk-O7SJYOEK.cjs.map +1 -0
- package/dist/{chunk-M7OVJJGB.cjs → chunk-PCK2N4IA.cjs} +4 -4
- package/dist/{chunk-M7OVJJGB.cjs.map → chunk-PCK2N4IA.cjs.map} +1 -1
- package/dist/{chunk-7H4ALAHC.cjs → chunk-SFPZ6GEN.cjs} +4 -4
- package/dist/chunk-SFPZ6GEN.cjs.map +1 -0
- package/dist/chunk-SZ7K447J.cjs +4 -0
- package/dist/{chunk-SKOTYI3A.cjs.map → chunk-SZ7K447J.cjs.map} +1 -1
- package/dist/chunk-VWN5MN3U.cjs +3001 -0
- package/dist/chunk-VWN5MN3U.cjs.map +1 -0
- package/dist/{chunk-DIB7IOEX.cjs → chunk-WJ3RFUZV.cjs} +2 -2
- package/dist/{chunk-DIB7IOEX.cjs.map → chunk-WJ3RFUZV.cjs.map} +1 -1
- package/dist/{chunk-MXT7N555.cjs → chunk-X2P2BWT7.cjs} +22 -22
- package/dist/chunk-X2P2BWT7.cjs.map +1 -0
- package/dist/impl-56QEHP2B.cjs +6 -0
- package/dist/impl-56QEHP2B.cjs.map +1 -0
- package/dist/{impl-JQVCW52V.cjs → impl-575YOEHZ.cjs} +2 -2
- package/dist/{impl-JQVCW52V.cjs.map → impl-575YOEHZ.cjs.map} +1 -1
- package/dist/{impl-PHBUSAGS.cjs → impl-5LMTXEQA.cjs} +2 -2
- package/dist/{impl-PHBUSAGS.cjs.map → impl-5LMTXEQA.cjs.map} +1 -1
- package/dist/impl-7DIFXY6N.cjs +6 -0
- package/dist/impl-7DIFXY6N.cjs.map +1 -0
- package/dist/{impl-WMI46UXI.cjs → impl-C6TDBSVQ.cjs} +2 -2
- package/dist/{impl-WMI46UXI.cjs.map → impl-C6TDBSVQ.cjs.map} +1 -1
- package/dist/impl-CL5OTH3R.cjs +2 -0
- package/dist/impl-CL5OTH3R.cjs.map +1 -0
- package/dist/{impl-VXOHC45F.cjs → impl-CV6MBTAL.cjs} +2 -2
- package/dist/{impl-VXOHC45F.cjs.map → impl-CV6MBTAL.cjs.map} +1 -1
- package/dist/{impl-Q3P6DGHG.cjs → impl-D7RH4J5E.cjs} +2 -2
- package/dist/{impl-Q3P6DGHG.cjs.map → impl-D7RH4J5E.cjs.map} +1 -1
- package/dist/{impl-NK42TN4C.cjs → impl-DGZB5IDM.cjs} +2 -2
- package/dist/{impl-NK42TN4C.cjs.map → impl-DGZB5IDM.cjs.map} +1 -1
- package/dist/impl-DNVWNGPJ.cjs +2 -0
- package/dist/{impl-SRI65ZIC.cjs.map → impl-DNVWNGPJ.cjs.map} +1 -1
- package/dist/{impl-YGVW4RTA.cjs → impl-DVIXGQJR.cjs} +2 -2
- package/dist/{impl-YGVW4RTA.cjs.map → impl-DVIXGQJR.cjs.map} +1 -1
- package/dist/impl-EAI3VXKU.cjs +7 -0
- package/dist/{impl-BQNXMBQ4.cjs.map → impl-EAI3VXKU.cjs.map} +1 -1
- package/dist/impl-G422JWSA.cjs +16 -0
- package/dist/impl-G422JWSA.cjs.map +1 -0
- package/dist/{impl-VT3C6SP4.cjs → impl-G7YD5U53.cjs} +2 -2
- package/dist/{impl-VT3C6SP4.cjs.map → impl-G7YD5U53.cjs.map} +1 -1
- package/dist/impl-IC4KAL33.cjs +2 -0
- package/dist/impl-IC4KAL33.cjs.map +1 -0
- package/dist/impl-JT7MI4YS.cjs +2 -0
- package/dist/impl-JT7MI4YS.cjs.map +1 -0
- package/dist/{impl-542SIWQ2.cjs → impl-LJBAH4YS.cjs} +2 -2
- package/dist/{impl-542SIWQ2.cjs.map → impl-LJBAH4YS.cjs.map} +1 -1
- package/dist/{impl-GEEPG7OH.cjs → impl-M2JWCIOX.cjs} +2 -2
- package/dist/{impl-GEEPG7OH.cjs.map → impl-M2JWCIOX.cjs.map} +1 -1
- package/dist/impl-MCIWWT2M.cjs +2 -0
- package/dist/{impl-V3MXFXZF.cjs.map → impl-MCIWWT2M.cjs.map} +1 -1
- package/dist/{impl-6ANYWCOV.cjs → impl-MO2EAW2B.cjs} +2 -2
- package/dist/{impl-6ANYWCOV.cjs.map → impl-MO2EAW2B.cjs.map} +1 -1
- package/dist/{impl-5VMEZB7F.cjs → impl-PHHRQWTE.cjs} +2 -2
- package/dist/{impl-5VMEZB7F.cjs.map → impl-PHHRQWTE.cjs.map} +1 -1
- package/dist/{impl-KQYINEBI.cjs → impl-PHXT2QG7.cjs} +2 -2
- package/dist/{impl-KQYINEBI.cjs.map → impl-PHXT2QG7.cjs.map} +1 -1
- package/dist/{impl-T67PUM7X.cjs → impl-QMDXFUAO.cjs} +2 -2
- package/dist/{impl-T67PUM7X.cjs.map → impl-QMDXFUAO.cjs.map} +1 -1
- package/dist/impl-R5PX6MIE.cjs +9 -0
- package/dist/impl-R5PX6MIE.cjs.map +1 -0
- package/dist/{impl-PKWSORXX.cjs → impl-RAZVKALS.cjs} +2 -2
- package/dist/{impl-PKWSORXX.cjs.map → impl-RAZVKALS.cjs.map} +1 -1
- package/dist/{impl-XLL66FXK.cjs → impl-RZSXBVAC.cjs} +2 -2
- package/dist/{impl-XLL66FXK.cjs.map → impl-RZSXBVAC.cjs.map} +1 -1
- package/dist/{impl-VUAC7AYF.cjs → impl-SA4YQJID.cjs} +2 -2
- package/dist/{impl-VUAC7AYF.cjs.map → impl-SA4YQJID.cjs.map} +1 -1
- package/dist/{impl-55GTRVMZ.cjs → impl-SUS5VKKB.cjs} +2 -2
- package/dist/{impl-55GTRVMZ.cjs.map → impl-SUS5VKKB.cjs.map} +1 -1
- package/dist/{impl-K2D3GTZG.cjs → impl-T3KGRFUR.cjs} +2 -2
- package/dist/{impl-K2D3GTZG.cjs.map → impl-T3KGRFUR.cjs.map} +1 -1
- package/dist/{impl-4CWCLU5Z.cjs → impl-T6FTWSLY.cjs} +2 -2
- package/dist/{impl-4CWCLU5Z.cjs.map → impl-T6FTWSLY.cjs.map} +1 -1
- package/dist/{impl-JFYHXSOV.cjs → impl-TXBSRO6N.cjs} +2 -2
- package/dist/{impl-JFYHXSOV.cjs.map → impl-TXBSRO6N.cjs.map} +1 -1
- package/dist/{impl-PWYKAVK4.cjs → impl-UKTKLJSZ.cjs} +2 -2
- package/dist/{impl-PWYKAVK4.cjs.map → impl-UKTKLJSZ.cjs.map} +1 -1
- package/dist/{impl-A7XL5O4W.cjs → impl-UU5CW4E4.cjs} +2 -2
- package/dist/{impl-A7XL5O4W.cjs.map → impl-UU5CW4E4.cjs.map} +1 -1
- package/dist/{impl-REKQO7ZI.cjs → impl-UYKI3NKQ.cjs} +2 -2
- package/dist/{impl-REKQO7ZI.cjs.map → impl-UYKI3NKQ.cjs.map} +1 -1
- package/dist/{impl-RD5UOJY6.cjs → impl-VVICNSEP.cjs} +2 -2
- package/dist/{impl-RD5UOJY6.cjs.map → impl-VVICNSEP.cjs.map} +1 -1
- package/dist/impl-WY3A5X7O.cjs +2 -0
- package/dist/{impl-JSXYZHX4.cjs.map → impl-WY3A5X7O.cjs.map} +1 -1
- package/dist/{impl-OQAP7YDW.cjs → impl-XOHK7EPT.cjs} +2 -2
- package/dist/{impl-OQAP7YDW.cjs.map → impl-XOHK7EPT.cjs.map} +1 -1
- package/dist/{impl-XJBUIDZP.cjs → impl-XT4Q54W2.cjs} +2 -2
- package/dist/{impl-XJBUIDZP.cjs.map → impl-XT4Q54W2.cjs.map} +1 -1
- package/dist/{impl-D2HENZNO.cjs → impl-Y6ENZCUI.cjs} +2 -2
- package/dist/{impl-D2HENZNO.cjs.map → impl-Y6ENZCUI.cjs.map} +1 -1
- package/dist/{impl-KRJNBGJ6.cjs → impl-YQXGFOOO.cjs} +2 -2
- package/dist/{impl-KRJNBGJ6.cjs.map → impl-YQXGFOOO.cjs.map} +1 -1
- package/dist/{impl-TCR3Y3J2.cjs → impl-ZUAB2R6X.cjs} +2 -2
- package/dist/{impl-TCR3Y3J2.cjs.map → impl-ZUAB2R6X.cjs.map} +1 -1
- package/dist/{impl-VL3CJ2OT.cjs → impl-ZV7OZ5BN.cjs} +2 -2
- package/dist/{impl-VL3CJ2OT.cjs.map → impl-ZV7OZ5BN.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,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkGJ6V5BHGcjs = require('./chunk-GJ6V5BHG.cjs');function f(p,{adTechPurposes:m=["SaleOfInfo"],serviceToTitle:s,serviceToSupportedIntegration:r}){let e=[],i=[],n={};p.forEach(t=>{let{service:a,attributes:c=[]}=t;if(!a||a==="internalService")return;let u=c.find(o=>o.key==="Found on Domain");u&&(n[a]||(n[a]=[]),n[a].push(...u.values.map(o=>o.replace("https://","").replace("http://",""))),n[a]=[...new Set(n[a])]),_chunkGJ6V5BHGcjs.i.call(void 0, t.trackingPurposes,m).length>0?(i.push(a),e.includes(a)&&(e=e.filter(o=>o!==a))):i.includes(a)||e.push(a)});let h=[...new Set(i)].map(t=>({title:s[t],...r[t]?{integrationName:t}:{integrationName:"promptAPerson","outer-type":t},attributes:[{key:"Tech Type",values:["Ad Tech"]},{key:"Found On Domain",values:n[t]||[]}]}));return{siteTechDataSilos:[...new Set(e)].map(t=>({title:s[t],...r[t]?{integrationName:t}:{integrationName:"promptAPerson",outerType:t},attributes:[{key:"Tech Type",values:["Site Tech"]},{key:"Found On Domain",values:n[t]||[]}]})),adTechDataSilos:h}}exports.a = f;
|
|
2
|
+
//# sourceMappingURL=chunk-I6GMLKI6.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/cli/cli/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/chunk-I6GMLKI6.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":"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","file":"/home/runner/work/cli/cli/dist/chunk-I6GMLKI6.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 _chunkVWN5MN3Ucjs = require('./chunk-VWN5MN3U.cjs');var _chunkZUNVPK23cjs = require('./chunk-ZUNVPK23.cjs');var _chunkGJ6V5BHGcjs = require('./chunk-GJ6V5BHG.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 _chunkVWN5MN3Ucjs.$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=_chunkGJ6V5BHGcjs.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 _chunkVWN5MN3Ucjs.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=_chunkVWN5MN3Ucjs.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=_chunkGJ6V5BHGcjs.j.call(void 0, p.map(m=>Object.keys(m)).flat()),d=_chunkGJ6V5BHGcjs.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=_chunkGJ6V5BHGcjs.j.call(void 0, p.map(o=>Object.keys(o)).flat()),d=_chunkGJ6V5BHGcjs.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 _chunkVWN5MN3Ucjs.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=_chunkGJ6V5BHGcjs.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 _chunkVWN5MN3Ucjs.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=_chunkGJ6V5BHGcjs.j.call(void 0, p.map(i=>Object.keys(i)).flat()),s=_chunkGJ6V5BHGcjs.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 _chunkVWN5MN3Ucjs.b.call(void 0, s,async i=>{let n=_chunkGJ6V5BHGcjs.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 _chunkVWN5MN3Ucjs.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=_chunkVWN5MN3Ucjs.rc.call(void 0, r);await _chunkVWN5MN3Ucjs.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=_chunkVWN5MN3Ucjs.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=_chunkGJ6V5BHGcjs.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=_chunkVWN5MN3Ucjs.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=_chunkVWN5MN3Ucjs.zc.call(void 0, r,p),[C,T,me]=await Promise.all([_chunkVWN5MN3Ucjs.Ac.call(void 0, r,p,t),_chunkVWN5MN3Ucjs.id.call(void 0, P),_chunkVWN5MN3Ucjs.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=_chunkGJ6V5BHGcjs.b.call(void 0, ne,o?100:10);oe.start(ne.length,0),await _chunkVWN5MN3Ucjs.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.")),_chunkVWN5MN3Ucjs.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((_chunkVWN5MN3Ucjs.lg.call(void 0, new Date).getTime()-_chunkVWN5MN3Ucjs.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=_chunkVWN5MN3Ucjs.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.")),_chunkVWN5MN3Ucjs.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=_chunkVWN5MN3Ucjs.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=_chunkVWN5MN3Ucjs.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=_chunkVWN5MN3Ucjs.kg.call(void 0, d),w=[];return await _chunkVWN5MN3Ucjs.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=_chunkVWN5MN3Ucjs.uc.call(void 0, f,Qe),o=_chunkGJ6V5BHGcjs.b.call(void 0, s,m);return(await _chunkVWN5MN3Ucjs.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-LE6FS55Q.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/chunk-LE6FS55Q.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-LE6FS55Q.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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
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 _chunkABKDAPPRcjs = require('./chunk-ABKDAPPR.cjs');var _chunkVWN5MN3Ucjs = require('./chunk-VWN5MN3U.cjs');var _chunkZUNVPK23cjs = require('./chunk-ZUNVPK23.cjs');var _chunkGJ6V5BHGcjs = require('./chunk-GJ6V5BHG.cjs');var _privacytypes = require('@transcend-io/privacy-types');var _colors = require('colors'); var _colors2 = _interopRequireDefault(_colors);async function nt({auth:e,deploy:s=!1,transcendUrl:o=_chunkGJ6V5BHGcjs.r,bundleTypes:t=Object.values(_privacytypes.ConsentBundleType)}){let a=_chunkVWN5MN3Ucjs.zc.call(void 0, o,e),n=await _chunkVWN5MN3Ucjs.Tc.call(void 0, a);await _chunkVWN5MN3Ucjs.b.call(void 0, t,async i=>{_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Update Consent Manager bundle with ID "${n}" and type "${i}" to latest version...`)),await _chunkVWN5MN3Ucjs.Dc.call(void 0, a,{id:n,bundleType:i}),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Updated Consent Manager bundle with ID "${n}" and type "${i}" to latest version!`))}),s&&await _chunkVWN5MN3Ucjs.b.call(void 0, t,async i=>{_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Deploying Consent Manager bundle with ID "${n}" and type "${i}"...`)),await _chunkVWN5MN3Ucjs.Cc.call(void 0, a,{id:n,bundleType:i}),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Deployed Consent Manager bundle with ID "${n}" and type "${i}"!`))})}var H=["ID","Activity","Encounters","Last Seen At","Has Native Do Not Sell/Share Support","IAB USP API Support","Service Description","Website URL","Categories of Recipients"];async function ft({auth:e,trackerStatus:s,file:o,classifyService:t=!1,transcendUrl:a=_chunkGJ6V5BHGcjs.r}){let n=_chunkVWN5MN3Ucjs.zc.call(void 0, a,e);_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Reading "${o}" from disk`));let l=_chunkVWN5MN3Ucjs.uc.call(void 0, o,_chunkABKDAPPRcjs.ja).map(({Type:S,Notes:p,Service:m,Purpose:C,Status:f,Owners:E,Teams:T,"Connections Made To":A,...I})=>({value:A,type:S,description:p,trackingPurposes:_chunkVWN5MN3Ucjs.rc.call(void 0, C),status:f||s,owners:E?_chunkVWN5MN3Ucjs.rc.call(void 0, E):void 0,teams:T?_chunkVWN5MN3Ucjs.rc.call(void 0, T):void 0,attributes:Object.entries(I).filter(([y])=>!H.includes(y)).map(([y,B])=>({key:y,values:_chunkVWN5MN3Ucjs.rc.call(void 0, B)}))}));await _chunkVWN5MN3Ucjs._e.call(void 0, n,l,t)||(_chunkZUNVPK23cjs.a.error(_colors2.default.red("Encountered error(s) syncing data flows from CSV, see logs above for more info. ")),process.exit(1))}var Y=["ID","Activity","Encounters","Last Seen At","Has Native Do Not Sell/Share Support","IAB USP API Support","Service Description","Website URL","Categories of Recipients"];async function Mt({auth:e,trackerStatus:s,file:o,transcendUrl:t=_chunkGJ6V5BHGcjs.r}){let a=_chunkVWN5MN3Ucjs.zc.call(void 0, t,e);_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Reading "${o}" from disk`));let i=_chunkVWN5MN3Ucjs.uc.call(void 0, o,_chunkABKDAPPRcjs.ka).map(({"Is Regex?":c,Notes:S,Service:p,Purpose:m,Status:C,Owners:f,Teams:E,Name:T,...A})=>({...typeof c=="string"?{isRegex:c.toLowerCase()==="true"}:{},name:T,description:S,trackingPurposes:_chunkVWN5MN3Ucjs.rc.call(void 0, m),status:C||s,owners:f?_chunkVWN5MN3Ucjs.rc.call(void 0, f):void 0,teams:E?_chunkVWN5MN3Ucjs.rc.call(void 0, E):void 0,attributes:Object.entries(A).filter(([I])=>!Y.includes(I)).map(([I,y])=>({key:I,values:_chunkVWN5MN3Ucjs.rc.call(void 0, y)}))}));await _chunkVWN5MN3Ucjs.Ue.call(void 0, a,i)||(_chunkZUNVPK23cjs.a.error(_colors2.default.red("Encountered error(s) syncing cookies from CSV, see logs above for more info. ")),process.exit(1))}var j=1e3,Q=60*j,V=60*Q,X=24*V,K=7*X;async function Rt(e,{bin:s,start:o,end:t=new Date}){let a=await _chunkVWN5MN3Ucjs.Tc.call(void 0, e),n=Math.floor(o.getTime()/1e3),i=Math.floor(t.getTime()/1e3);if(n>i)throw new Error('Received "end" date that happened before "start" date');if(s==="1h"&&t.getTime()-o.getTime()>K*2)throw new Error("When using bin=1h, start and end time can be no more than 2 weeks apart");let l=o.toISOString(),c=t.toISOString(),[S,p,m]=await Promise.all([_chunkVWN5MN3Ucjs.Wc.call(void 0, e,{dataSource:"PRIVACY_SIGNAL_TIMESERIES",startDate:l,endDate:c,forceRefetch:!0,airgapBundleId:a,binInterval:s,smoothTimeseries:!1}),_chunkVWN5MN3Ucjs.Wc.call(void 0, e,{dataSource:"CONSENT_CHANGES_TIMESERIES",startDate:l,endDate:c,forceRefetch:!0,airgapBundleId:a,binInterval:s,smoothTimeseries:!1}),_chunkVWN5MN3Ucjs.Wc.call(void 0, e,{dataSource:"CONSENT_SESSIONS_BY_REGIME",startDate:l,endDate:c,forceRefetch:!0,airgapBundleId:a,binInterval:s,smoothTimeseries:!1})]);return{PRIVACY_SIGNAL_TIMESERIES:S,CONSENT_CHANGES_TIMESERIES:p,CONSENT_SESSIONS_BY_REGIME:m}}var $=e=>new URL(`https://${e}`).hostname.split(".").slice(-2).join(".");var W=/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;async function Gt(e,{xdiLocation:s,transcendUrl:o=_chunkGJ6V5BHGcjs.r,removeIpAddresses:t=!0,domainBlockList:a=["localhost"],xdiAllowedCommands:n="ConsentManager:Sync"}){let i=Array.isArray(e)?e:[{apiKey:e,organizationId:"",organizationName:""}],l=await _chunkVWN5MN3Ucjs.a.call(void 0, i,async p=>{_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Pulling consent metadata for organization - ${p.organizationName}`));let m=_chunkVWN5MN3Ucjs.zc.call(void 0, o,p.apiKey);return await _chunkVWN5MN3Ucjs.Sc.call(void 0, m)},{concurrency:5}),c={};return l.forEach(p=>{let m=_optionalChain([p, 'access', _2 => _2.partition, 'optionalAccess', _3 => _3.partition])||p.bundleURL.split("/").reverse()[1];c[m]||(c[m]=[]);let C=_chunkGJ6V5BHGcjs.c.call(void 0, p.configuration.domains.filter(f=>!t||!W.test(f)).map(f=>$(f)),a);c[m]=[...new Set([...c[m]||[],...C])]}),{html:`
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<script
|
|
4
|
+
src="${s}"
|
|
5
|
+
data-sync-groups='${JSON.stringify(c,null,2)}'
|
|
6
|
+
data-xdi-commands="${n}"
|
|
7
|
+
></script>
|
|
8
|
+
`,syncGroups:c}}function Ft(e){let s=e.map(({name:o,input:t})=>({title:o.replace(".yml",""),attributes:[..._optionalChain([t, 'optionalAccess', _4 => _4.domains])?[{key:"Transcend Domain List",values:[...new Set(t.domains)]}]:[],..._optionalChain([t, 'optionalAccess', _5 => _5.bundleUrls])?[{key:"Airgap Production URL",values:[t.bundleUrls.PRODUCTION]},{key:"Airgap Test URL",values:[t.bundleUrls.TEST]},{key:"Airgap XDI URL",values:[t.bundleUrls.PRODUCTION.replace("airgap.js","xdi.js")]}]:[],..._optionalChain([t, 'optionalAccess', _6 => _6.partition])?[{key:"Consent Partition Key",values:[t.partition]}]:[]]}));return _chunkZUNVPK23cjs.a.info(`
|
|
9
|
+
|
|
10
|
+
~~~~~~~~~~~
|
|
11
|
+
Airgap scripts to host:`),s.forEach(({attributes:o,title:t},a)=>{_optionalChain([o, 'optionalAccess', _7 => _7.find, 'call', _8 => _8(n=>n.key==="Airgap Production URL"), 'optionalAccess', _9 => _9.values, 'optionalAccess', _10 => _10.forEach, 'call', _11 => _11(n=>{_chunkZUNVPK23cjs.a.info(`${a}) ${t} - ${n}`)})])}),s}exports.a = nt; exports.b = ft; exports.c = Mt; exports.d = Rt; exports.e = $; exports.f = W; exports.g = Gt; exports.h = Ft;
|
|
12
|
+
//# sourceMappingURL=chunk-MLH6KKUK.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/chunk-MLH6KKUK.cjs","../src/lib/consent-manager/updateConsentManagerVersionToLatest.ts","../src/lib/consent-manager/uploadDataFlowsFromCsv.ts","../src/lib/consent-manager/uploadCookiesFromCsv.ts","../src/lib/consent-manager/pullConsentManagerMetrics.ts","../src/lib/consent-manager/domainToHost.ts","../src/lib/consent-manager/buildXdiSyncEndpoint.ts","../src/lib/consent-manager/consentManagersToBusinessEntities.ts"],"names":["updateConsentManagerVersionToLatest","auth","deploy","transcendUrl","DEFAULT_TRANSCEND_API","bundleTypes","ConsentBundleType","client","buildTranscendGraphQLClient","consentManagerId","fetchConsentManagerId","mapSeries","bundleType","logger","colors","updateConsentManagerToLatest","deployConsentManager","OMIT_COLUMNS","uploadDataFlowsFromCsv","trackerStatus","file","classifyService","validatedDataFlowInputs","readCsv","DataFlowCsvInput","Type","Notes","Service","Purpose","Status","Owners","Teams","value","rest","splitCsvToList","key","syncDataFlows","uploadCookiesFromCsv","validatedCookieInputs","CookieCsvInput","isRegex","Name","syncCookies","ONE_SECOND","ONE_MINUTE","ONE_HOUR","ONE_DAY","ONE_WEEK","pullConsentManagerMetrics","bin","start","end","airgapBundleId","startTime","endTime","startDate","endDate","privacySignalData","consentChangesData","consentSessionsByRegimeData","fetchConsentManagerAnalyticsData","domainToHost","domain"],"mappings":"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","file":"/home/runner/work/cli/cli/dist/chunk-MLH6KKUK.cjs","sourcesContent":[null,"import { ConsentBundleType } from '@transcend-io/privacy-types';\nimport { mapSeries } from '../bluebird';\nimport {\n updateConsentManagerToLatest,\n buildTranscendGraphQLClient,\n fetchConsentManagerId,\n deployConsentManager,\n} from '../graphql';\nimport colors from 'colors';\n\nimport { logger } from '../../logger';\nimport { DEFAULT_TRANSCEND_API } from '../../constants';\n\n/**\n * Update the consent manager to latest version\n *\n * @param options - Options\n */\nexport async function updateConsentManagerVersionToLatest({\n auth,\n deploy = false,\n transcendUrl = DEFAULT_TRANSCEND_API,\n bundleTypes = Object.values(ConsentBundleType),\n}: {\n /** Transcend API key authentication */\n auth: string;\n /** API URL for Transcend backend */\n transcendUrl?: string;\n /** Deploy consent manager with this update */\n deploy?: boolean;\n /** The bundle types to update and deploy */\n bundleTypes?: ConsentBundleType[];\n}): Promise<void> {\n // Find all requests made before createdAt that are in a removing data state\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n // Grab Consent Manager ID\n const consentManagerId = await fetchConsentManagerId(client);\n\n // Update each bundle type to latest version\n await mapSeries(bundleTypes, async (bundleType) => {\n logger.info(\n colors.magenta(\n `Update Consent Manager bundle with ID \"${consentManagerId}\" and type \"${bundleType}\" to latest version...`,\n ),\n );\n await updateConsentManagerToLatest(client, {\n id: consentManagerId,\n bundleType,\n });\n logger.info(\n colors.green(\n `Updated Consent Manager bundle with ID \"${consentManagerId}\" and type \"${bundleType}\" to latest version!`,\n ),\n );\n });\n\n // deploy Consent Managers\n if (deploy) {\n // Update each bundle type to latest version\n await mapSeries(bundleTypes, async (bundleType) => {\n logger.info(\n colors.magenta(\n `Deploying Consent Manager bundle with ID \"${consentManagerId}\" and type \"${bundleType}\"...`,\n ),\n );\n await deployConsentManager(client, {\n id: consentManagerId,\n bundleType,\n });\n logger.info(\n colors.green(\n `Deployed Consent Manager bundle with ID \"${consentManagerId}\" and type \"${bundleType}\"!`,\n ),\n );\n });\n }\n}\n","import colors from 'colors';\nimport { logger } from '../../logger';\nimport { ConsentTrackerStatus } from '@transcend-io/privacy-types';\nimport { buildTranscendGraphQLClient, syncDataFlows } from '../graphql';\nimport { readCsv } from '../requests/readCsv';\nimport { DataFlowInput, DataFlowCsvInput } from '../../codecs';\nimport { splitCsvToList } from '../requests';\nimport { DEFAULT_TRANSCEND_API } from '../../constants';\n\nconst OMIT_COLUMNS = [\n 'ID',\n 'Activity',\n 'Encounters',\n 'Last Seen At',\n 'Has Native Do Not Sell/Share Support',\n 'IAB USP API Support',\n 'Service Description',\n 'Website URL',\n 'Categories of Recipients',\n];\n\n/**\n * Upload a set of data flows from CSV\n *\n * @param options - Options\n */\nexport async function uploadDataFlowsFromCsv({\n auth,\n trackerStatus,\n file,\n classifyService = false,\n transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n /** CSV file path */\n file: string;\n /** Transcend API key authentication */\n auth: string;\n /** Sombra API key authentication */\n trackerStatus: ConsentTrackerStatus;\n /** classify data flow service if missing */\n classifyService?: boolean;\n /** API URL for Transcend backend */\n transcendUrl?: string;\n}): Promise<void> {\n // Build a GraphQL client\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n // Read from CSV the set of data flow inputs\n logger.info(colors.magenta(`Reading \"${file}\" from disk`));\n const dataFlowInputs = readCsv(file, DataFlowCsvInput);\n\n // Convert these data flow inputs into a format that the other function can use\n const validatedDataFlowInputs = dataFlowInputs.map(\n ({\n Type,\n Notes,\n // TODO: https://transcend.height.app/T-26391 - export in CSV\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Service,\n Purpose,\n Status,\n Owners,\n Teams,\n 'Connections Made To': value,\n ...rest\n }): DataFlowInput => ({\n value,\n type: Type,\n description: Notes,\n trackingPurposes: splitCsvToList(Purpose),\n // TODO: https://transcend.height.app/T-26391\n // service: Service,\n // Apply the trackerStatus to all values in the CSV -> allows for customer to define tracker status\n // on a row by row basis if needed\n status: Status || trackerStatus,\n owners: Owners ? splitCsvToList(Owners) : undefined,\n teams: Teams ? splitCsvToList(Teams) : undefined,\n // all remaining options are attribute\n attributes: Object.entries(rest)\n // filter out native columns that are exported from the admin dashboard\n // but not custom attributes\n .filter(([key]) => !OMIT_COLUMNS.includes(key))\n .map(([key, value]) => ({\n key,\n values: splitCsvToList(value),\n })),\n }),\n );\n\n // Upload the data flows into Transcend dashboard\n const syncedDataFlows = await syncDataFlows(\n client,\n validatedDataFlowInputs,\n classifyService,\n );\n\n // Log errors\n if (!syncedDataFlows) {\n logger.error(\n colors.red(\n 'Encountered error(s) syncing data flows from CSV, see logs above for more info. ',\n ),\n );\n process.exit(1);\n }\n}\n","import colors from 'colors';\nimport { logger } from '../../logger';\nimport { ConsentTrackerStatus } from '@transcend-io/privacy-types';\nimport { buildTranscendGraphQLClient, syncCookies } from '../graphql';\nimport { readCsv } from '../requests/readCsv';\nimport { CookieInput, CookieCsvInput } from '../../codecs';\nimport { splitCsvToList } from '../requests';\nimport { DEFAULT_TRANSCEND_API } from '../../constants';\n\nconst OMIT_COLUMNS = [\n 'ID',\n 'Activity',\n 'Encounters',\n 'Last Seen At',\n 'Has Native Do Not Sell/Share Support',\n 'IAB USP API Support',\n 'Service Description',\n 'Website URL',\n 'Categories of Recipients',\n];\n\n/**\n * Upload a set of cookies from CSV\n *\n * @param options - Options\n */\nexport async function uploadCookiesFromCsv({\n auth,\n trackerStatus,\n file,\n transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n /** CSV file path */\n file: string;\n /** Transcend API key authentication */\n auth: string;\n /** Sombra API key authentication */\n trackerStatus: ConsentTrackerStatus;\n /** API URL for Transcend backend */\n transcendUrl?: string;\n}): Promise<void> {\n // Build a GraphQL client\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n // Read from CSV the set of cookie inputs\n logger.info(colors.magenta(`Reading \"${file}\" from disk`));\n const cookieInputs = readCsv(file, CookieCsvInput);\n\n // Convert these inputs into a format that the other function can use\n const validatedCookieInputs = cookieInputs.map(\n ({\n 'Is Regex?': isRegex,\n Notes,\n // TODO: https://transcend.height.app/T-26391 - export in CSV\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n Service,\n Purpose,\n Status,\n Owners,\n Teams,\n Name,\n ...rest\n }): CookieInput => ({\n ...(typeof isRegex === 'string'\n ? { isRegex: isRegex.toLowerCase() === 'true' }\n : {}),\n name: Name,\n description: Notes,\n trackingPurposes: splitCsvToList(Purpose),\n // TODO: https://transcend.height.app/T-26391\n // service: Service,\n // Apply the trackerStatus to all values in the CSV -> allows for customer to define tracker status\n // on a row by row basis if needed\n status: Status || trackerStatus,\n owners: Owners ? splitCsvToList(Owners) : undefined,\n teams: Teams ? splitCsvToList(Teams) : undefined,\n // all remaining options are attribute\n attributes: Object.entries(rest)\n // filter out native columns that are exported from the admin dashboard\n // but not custom attributes\n .filter(([key]) => !OMIT_COLUMNS.includes(key))\n .map(([key, value]) => ({\n key,\n values: splitCsvToList(value),\n })),\n }),\n );\n\n // Upload the cookies into Transcend dashboard\n const syncedCookies = await syncCookies(client, validatedCookieInputs);\n\n // Log errors\n if (!syncedCookies) {\n logger.error(\n colors.red(\n 'Encountered error(s) syncing cookies from CSV, see logs above for more info. ',\n ),\n );\n process.exit(1);\n }\n}\n","import type { GraphQLClient } from 'graphql-request';\nimport {\n ConsentManagerMetric,\n ConsentManagerMetricBin,\n fetchConsentManagerAnalyticsData,\n fetchConsentManagerId,\n} from '../graphql';\n\n/**\n * One second of time in ms\n */\nconst ONE_SECOND = 1000;\nconst ONE_MINUTE = 60 * ONE_SECOND;\nconst ONE_HOUR = 60 * ONE_MINUTE;\nconst ONE_DAY = 24 * ONE_HOUR;\nconst ONE_WEEK = 7 * ONE_DAY;\n\n/**\n * Pull consent manager metrics in an organization\n *\n * @param client - GraphQL client\n * @param options - Options\n * @returns The consent manager metrics\n */\nexport async function pullConsentManagerMetrics(\n client: GraphQLClient,\n {\n bin,\n start,\n end = new Date(),\n }: {\n /** Start date to pull metrics from */\n start: Date;\n /** End date to pull metrics from (assumes now) */\n end?: Date;\n /** Bin size to pull metrics */\n bin: ConsentManagerMetricBin;\n },\n): Promise<{\n /** Privacy signal data */\n PRIVACY_SIGNAL_TIMESERIES: ConsentManagerMetric[];\n /** Consent changes data */\n CONSENT_CHANGES_TIMESERIES: ConsentManagerMetric[];\n /** Consent sessions by regime */\n CONSENT_SESSIONS_BY_REGIME: ConsentManagerMetric[];\n}> {\n // Grab the bundleId associated with this API key\n const airgapBundleId = await fetchConsentManagerId(client);\n\n // convert start and end to times\n const startTime = Math.floor(start.getTime() / 1000);\n const endTime = Math.floor(end.getTime() / 1000);\n if (startTime > endTime) {\n throw new Error('Received \"end\" date that happened before \"start\" date');\n }\n\n // do not allow hourly bins greater than 2 weeks\n if (bin === '1h' && end.getTime() - start.getTime() > ONE_WEEK * 2) {\n throw new Error(\n 'When using bin=1h, start and end time can be no more than 2 weeks apart',\n );\n }\n\n // Pull in the metrics\n const startDate = start.toISOString();\n const endDate = end.toISOString();\n const [privacySignalData, consentChangesData, consentSessionsByRegimeData] =\n await Promise.all([\n fetchConsentManagerAnalyticsData(client, {\n dataSource: 'PRIVACY_SIGNAL_TIMESERIES',\n startDate,\n endDate,\n forceRefetch: true,\n airgapBundleId,\n binInterval: bin,\n smoothTimeseries: false,\n }),\n fetchConsentManagerAnalyticsData(client, {\n dataSource: 'CONSENT_CHANGES_TIMESERIES',\n startDate,\n endDate,\n forceRefetch: true,\n airgapBundleId,\n binInterval: bin,\n smoothTimeseries: false,\n }),\n fetchConsentManagerAnalyticsData(client, {\n dataSource: 'CONSENT_SESSIONS_BY_REGIME',\n startDate,\n endDate,\n forceRefetch: true,\n airgapBundleId,\n binInterval: bin,\n smoothTimeseries: false,\n }),\n ]);\n\n return {\n PRIVACY_SIGNAL_TIMESERIES: privacySignalData,\n CONSENT_CHANGES_TIMESERIES: consentChangesData,\n CONSENT_SESSIONS_BY_REGIME: consentSessionsByRegimeData,\n };\n}\n","/**\n * Convert a domain to host\n *\n * @param domain - e.g. test.acme.com\n * @returns Host acme.com\n */\nexport const domainToHost = (domain: string): string =>\n new URL(`https://${domain}`).hostname.split('.').slice(-2).join('.');\n","import colors from 'colors';\n\nimport { buildTranscendGraphQLClient, fetchConsentManager } from '../graphql';\nimport { difference } from 'lodash-es';\nimport { map } from '../bluebird';\nimport { StoredApiKey } from '../../codecs';\nimport { DEFAULT_TRANSCEND_API } from '../../constants';\nimport { logger } from '../../logger';\nimport { domainToHost } from './domainToHost';\n\n/**\n * Sync group configuration mapping\n * e.g.\n * {\n * \"abdb5e78-0d69-4554-a3bd-84b72ca3b3d9\": [\n * \"test.com\"\n * ],\n * \"f6b3ba87-c9df-444f-b420-6fac49e35910\": [\n * \"blue.com\"\n * ]\n * }\n */\nexport type XdiSyncGroups = { [k in string]: string[] };\n\n/** Regular expression for IP addresses - remove these from sync endpoint */\nexport const IP_ADDRESS_REGEX =\n // eslint-disable-next-line max-len\n /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;\n\n/**\n * Build the sync endpoint definition for a set of Transcend accounts\n *\n * @param apiKeys - The API keys that will be used to pull down configurations for\n * @param options - Options\n * @returns The XDI configuration\n */\nexport async function buildXdiSyncEndpoint(\n apiKeys: string | StoredApiKey[],\n {\n xdiLocation,\n transcendUrl = DEFAULT_TRANSCEND_API,\n removeIpAddresses = true,\n domainBlockList = ['localhost'],\n xdiAllowedCommands = 'ConsentManager:Sync',\n }: {\n /** The file location where the XDI file is hosted */\n xdiLocation: string;\n /** URL of Transcend API */\n transcendUrl?: string;\n /** When true, remove IP addresses (defaults to true) */\n removeIpAddresses?: boolean;\n /** Block list of domains to omit from sync endpoint - includes `localhost` by default */\n domainBlockList?: string[];\n /** Allows XDI commands */\n xdiAllowedCommands?: string;\n },\n): Promise<{\n /** Sync group configurations */\n syncGroups: XdiSyncGroups;\n /** The HTML string */\n html: string;\n}> {\n // Convert API keys to list\n const apiKeysAsList = Array.isArray(apiKeys)\n ? apiKeys\n : [{ apiKey: apiKeys, organizationId: '', organizationName: '' }];\n\n // Fetch configuration for each account\n const consentManagers = await map(\n apiKeysAsList,\n async (apiKey) => {\n logger.info(\n colors.magenta(\n `Pulling consent metadata for organization - ${apiKey.organizationName}`,\n ),\n );\n\n // Create a GraphQL client\n const client = buildTranscendGraphQLClient(transcendUrl, apiKey.apiKey);\n\n // Grab consent manager\n const consentManager = await fetchConsentManager(client);\n return consentManager;\n },\n { concurrency: 5 },\n );\n\n // construct the sync groups\n const syncGroups: XdiSyncGroups = {};\n consentManagers.forEach((consentManager) => {\n // grab the partition key\n const partitionKey =\n // take explicit key first\n consentManager.partition?.partition ||\n // fallback to bundle ID\n consentManager.bundleURL.split('/').reverse()[1];\n\n // Ensure that partition exists in the sync groups\n if (!syncGroups[partitionKey]) {\n syncGroups[partitionKey] = [];\n }\n\n // Map domain list to a host list\n const hosts = difference(\n consentManager.configuration.domains\n .filter(\n // ignore IP addresses\n (domain) => !removeIpAddresses || !IP_ADDRESS_REGEX.test(domain),\n )\n .map((domain) => domainToHost(domain)),\n // ignore block list\n domainBlockList,\n );\n // merge existing sync group with hosts for this consent manager\n syncGroups[partitionKey] = [\n ...new Set([...(syncGroups[partitionKey] || []), ...hosts]),\n ];\n });\n\n // Construct the HTML\n const syncEndpointHtml = `\n<!DOCTYPE html>\n<script\nsrc=\"${xdiLocation}\"\ndata-sync-groups='${JSON.stringify(syncGroups, null, 2)}'\ndata-xdi-commands=\"${xdiAllowedCommands}\"\n></script>\n`;\n\n return {\n html: syncEndpointHtml,\n syncGroups,\n };\n}\n","import { BusinessEntityInput, ConsentManagerInput } from '../../codecs';\nimport { logger } from '../../logger';\n\n/**\n * Combine multiple consent manager configurations into a list of business entity configurations\n *\n * @param inputs - Consent manager configurations to combine\n * @returns Business entity configuration input\n */\nexport function consentManagersToBusinessEntities(\n inputs: {\n /** Name of business entity */\n name: string;\n /** Consent manager input */\n input?: ConsentManagerInput;\n }[],\n): BusinessEntityInput[] {\n // Construct the business entities YAML definition\n const businessEntities = inputs.map(\n ({ name, input }): BusinessEntityInput => ({\n // Title of Transcend Instance\n title: name.replace('.yml', ''),\n attributes: [\n // Sync domain list\n ...(input?.domains\n ? [\n {\n key: 'Transcend Domain List',\n values: [...new Set(input.domains)],\n },\n ]\n : []),\n // Sync bundle URLs\n ...(input?.bundleUrls\n ? [\n {\n key: 'Airgap Production URL',\n values: [input.bundleUrls.PRODUCTION],\n },\n {\n key: 'Airgap Test URL',\n values: [input.bundleUrls.TEST],\n },\n {\n key: 'Airgap XDI URL',\n values: [\n input.bundleUrls.PRODUCTION.replace('airgap.js', 'xdi.js'),\n ],\n },\n ]\n : []),\n // Sync partition keys\n ...(input?.partition\n ? [\n {\n key: 'Consent Partition Key',\n values: [input.partition],\n },\n ]\n : []),\n ],\n }),\n );\n\n // Log out info on airgap scripts to host\n logger.info('\\n\\n~~~~~~~~~~~\\nAirgap scripts to host:');\n businessEntities.forEach(({ attributes, title }, ind) => {\n attributes\n ?.find((attr) => attr.key === 'Airgap Production URL')\n ?.values?.forEach((url) => {\n logger.info(`${ind}) ${title} - ${url}`);\n });\n });\n\n return businessEntities;\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 _chunkVWN5MN3Ucjs = require('./chunk-VWN5MN3U.cjs');var _chunkZUNVPK23cjs = require('./chunk-ZUNVPK23.cjs');var _chunkGJ6V5BHGcjs = require('./chunk-GJ6V5BHG.cjs');var _crypto = require('crypto'); var $ = _interopRequireWildcard(_crypto);var _jsonwebtoken = require('jsonwebtoken'); var A = _interopRequireWildcard(_jsonwebtoken);function B(c,p,t){let n=Buffer.from(t,"base64"),u=Buffer.from(p,"base64"),f="id-aes256-wrap-pad",l=Buffer.from("A65959A6","hex"),o=$.createCipheriv(f,u,l),s={encryptedIdentifier:Buffer.concat([o.update(c),o.final()]).toString("base64")};return A.sign(s,n,{algorithm:"HS384"})}var _colors = require('colors'); var _colors2 = _interopRequireDefault(_colors);var _iots = require('io-ts'); var r = _interopRequireWildcard(_iots);var _cliprogress = require('cli-progress'); var _cliprogress2 = _interopRequireDefault(_cliprogress);var _typeutils = require('@transcend-io/type-utils');var I=/^[0-9][Y|N]([Y|N])[Y|N]$/,R= exports.c =r.record(r.string,r.union([r.boolean,r.literal("Auto")]));async function q({base64EncryptionKey:c,base64SigningKey:p,preferences:t,partition:n,concurrency:u=100,transcendUrl:f=_chunkGJ6V5BHGcjs.s}){let l=_chunkVWN5MN3Ucjs.Bc.call(void 0, f),o=t.filter(e=>e.usp&&!I.test(e.usp));if(o.length>0)throw new Error(`Received invalid usp strings: ${JSON.stringify(o,null,2)}`);let d=t.map((e,g)=>[e,g]).filter(([e])=>{if(!e.purposes)return!1;try{return _typeutils.decodeCodec.call(void 0, R,e.purposes),!1}catch (e2){return!0}});if(d.length>0)throw new Error(`Received invalid purpose maps: ${JSON.stringify(d,null,2)}`);let s=t.filter(e=>!e.usp&&!e.purposes);if(s.length>0)throw new Error(`Received invalid inputs, expected either purposes or usp to be defined: ${JSON.stringify(s,null,2)}`);_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Uploading ${t.length} user preferences to partition ${n}`));let S=new Date().getTime(),m=new _cliprogress2.default.SingleBar({},_cliprogress2.default.Presets.shades_classic),v=0;m.start(t.length,0),await _chunkVWN5MN3Ucjs.a.call(void 0, t,async({userId:e,confirmed:g="true",updated:C,prompted:P,purposes:N,...i})=>{let _=B(e,c,p),[,j]=i.usp?I.exec(i.usp)||[]:[],k={token:_,partition:n,consent:{confirmed:g==="true",purposes:N?_typeutils.decodeCodec.call(void 0, R,N):i.usp?{SaleOfInfo:j==="Y"}:{},...C?{updated:C==="true"}:{},...P?{prompted:P==="true"}:{},...i}};try{await l.post("sync",{json:k}).json()}catch(y){try{let h=JSON.parse(_optionalChain([y, 'optionalAccess', _2 => _2.response, 'optionalAccess', _3 => _3.body])||"{}");h.error&&_chunkZUNVPK23cjs.a.error(_colors2.default.red(`Error: ${h.error}`))}catch (e3){}throw new Error(`Received an error from server: ${_optionalChain([y, 'optionalAccess', _4 => _4.response, 'optionalAccess', _5 => _5.body])||_optionalChain([y, 'optionalAccess', _6 => _6.message])}`)}v+=1,m.update(v)},{concurrency:u}),m.stop();let O=new Date().getTime()-S;_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Successfully uploaded ${t.length} user preferences to partition ${n} in "${O/1e3}" seconds!`))}exports.a = B; exports.b = I; exports.c = R; exports.d = q;
|
|
2
|
+
//# sourceMappingURL=chunk-NZEATKWL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/chunk-NZEATKWL.cjs","../src/lib/consent-manager/createConsentToken.ts","../src/lib/consent-manager/uploadConsents.ts"],"names":["createConsentToken","userId","base64EncryptionKey","base64SigningKey","signingKey","encryptionKey","encryptionAlgorithm","iv","cipher","jwtPayload","USP_STRING_REGEX","PurposeMap","uploadConsents","preferences","partition","concurrency","transcendUrl","DEFAULT_TRANSCEND_CONSENT_API","transcendConsentApi","createTranscendConsentGotInstance","invalidUspStrings","pref"],"mappings":"AAAA,u/BAAgD,wDAAoC,wDAAyC,0ECArG,4FACH,SAWLA,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACQ,CAER,IAAMC,CAAAA,CAAa,MAAA,CAAO,IAAA,CAAKD,CAAAA,CAAkB,QAAQ,CAAA,CACnDE,CAAAA,CAAgB,MAAA,CAAO,IAAA,CAAKH,CAAAA,CAAqB,QAAQ,CAAA,CAGzDI,CAAAA,CAAsB,oBAAA,CAEtBC,CAAAA,CAAK,MAAA,CAAO,IAAA,CAAK,UAAA,CAAY,KAAK,CAAA,CAElCC,CAAAA,CAAgB,CAAA,CAAA,cAAA,CAAeF,CAAAA,CAAqBD,CAAAA,CAAeE,CAAE,CAAA,CAYrEE,CAAAA,CAAa,CACjB,mBAAA,CAV0B,MAAA,CAAO,MAAA,CAAO,CACxCD,CAAAA,CAAO,MAAA,CAAOP,CAAM,CAAA,CACpBO,CAAAA,CAAO,KAAA,CAAM,CACf,CAAC,CAAA,CAAE,QAAA,CAAS,QAAQ,CAQpB,CAAA,CAOA,OAJyB,CAAA,CAAA,IAAA,CAAKC,CAAAA,CAAYL,CAAAA,CAAY,CACpD,SAAA,CAAW,OACb,CAAC,CAGH,CC/CA,gFAAmB,qEACA,qGAKK,qDACI,IAIfM,CAAAA,CAAmB,0BAAA,CAEnBC,CAAAA,aAAe,CAAA,CAAA,MAAA,CACxB,CAAA,CAAA,MAAA,CACA,CAAA,CAAA,KAAA,CAAM,CAAG,CAAA,CAAA,OAAA,CAAW,CAAA,CAAA,OAAA,CAAQ,MAAM,CAAC,CAAC,CACxC,CAAA,CAOA,MAAA,SAAsBC,CAAAA,CAAe,CACnC,mBAAA,CAAAV,CAAAA,CACA,gBAAA,CAAAC,CAAAA,CACA,WAAA,CAAAU,CAAAA,CACA,SAAA,CAAAC,CAAAA,CACA,WAAA,CAAAC,CAAAA,CAAc,GAAA,CACd,YAAA,CAAAC,CAAAA,CAAeC,mBACjB,CAAA,CAakB,CAEhB,IAAMC,CAAAA,CAAsBC,kCAAAA,CAA8C,CAAA,CAGpEC,CAAAA,CAAoBP,CAAAA,CAAY,MAAA,CACnCQ,CAAAA,EAASA,CAAAA,CAAK,GAAA,EAAO,CAACX,CAAAA,CAAiB,IAAA,CAAKW,CAAAA,CAAK,GAAG,CACvD,CAAA,CACA,EAAA,CAAID,CAAAA,CAAkB,MAAA,CAAS,CAAA,CAC7B,MAAM,IAAI,KAAA,CACR,CAAA,8BAAA,EAAiC,IAAA,CAAK,SAAA,CACpCA,CAAAA,CACA,IAAA,CACA,CACF,CAAC,CAAA,CAAA","file":"/home/runner/work/cli/cli/dist/chunk-NZEATKWL.cjs","sourcesContent":[null,"import * as crypto from 'crypto';\nimport * as jwt from 'jsonwebtoken';\n\n/**\n * Function to create a consent manager token\n *\n * @see https://docs.transcend.io/docs/consent/reference/managed-consent-database\n * @param userId - User ID\n * @param base64EncryptionKey - Encryption key\n * @param base64SigningKey - Signing key\n * @returns Token\n */\nexport function createConsentToken(\n userId: string,\n base64EncryptionKey: string,\n base64SigningKey: string,\n): string {\n // Read on for where to find these keys\n const signingKey = Buffer.from(base64SigningKey, 'base64');\n const encryptionKey = Buffer.from(base64EncryptionKey, 'base64');\n\n // NIST's AES-KWP implementation { aes 48 } - see https://tools.ietf.org/html/rfc5649\n const encryptionAlgorithm = 'id-aes256-wrap-pad';\n // Initial Value for AES-KWP integrity check - see https://tools.ietf.org/html/rfc5649#section-3\n const iv = Buffer.from('A65959A6', 'hex');\n // Set up encryption algorithm\n const cipher = crypto.createCipheriv(encryptionAlgorithm, encryptionKey, iv);\n\n // Encrypt the userId and base64-encode the result\n const encryptedIdentifier = Buffer.concat([\n cipher.update(userId),\n cipher.final(),\n ]).toString('base64');\n\n // Create the JWT content - jwt.sign will add a 'iat' (issued at) field to the payload\n // If you wanted to add something manually, consider\n // const issued: Date = new Date();\n // const isoDate = issued.toISOString();\n const jwtPayload = {\n encryptedIdentifier,\n };\n\n // Create a JSON web token and HMAC it with SHA-384\n const consentToken = jwt.sign(jwtPayload, signingKey, {\n algorithm: 'HS384',\n });\n\n return consentToken;\n}\n","import { createTranscendConsentGotInstance } from '../graphql';\nimport colors from 'colors';\nimport * as t from 'io-ts';\nimport { DEFAULT_TRANSCEND_CONSENT_API } from '../../constants';\nimport { map } from '../bluebird';\nimport { createConsentToken } from './createConsentToken';\nimport { logger } from '../../logger';\nimport cliProgress from 'cli-progress';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport type { ConsentPreferenceUpload } from './types';\nimport { ConsentPreferencesBody } from '@transcend-io/airgap.js-types';\n\nexport const USP_STRING_REGEX = /^[0-9][Y|N]([Y|N])[Y|N]$/;\n\nexport const PurposeMap = t.record(\n t.string,\n t.union([t.boolean, t.literal('Auto')]),\n);\n\n/**\n * Upload a set of consent preferences\n *\n * @param options - Options\n */\nexport async function uploadConsents({\n base64EncryptionKey,\n base64SigningKey,\n preferences,\n partition,\n concurrency = 100,\n transcendUrl = DEFAULT_TRANSCEND_CONSENT_API,\n}: {\n /** base64 encryption key */\n base64EncryptionKey: string;\n /** base64 signing key */\n base64SigningKey: string;\n /** Partition key */\n partition: string;\n /** Sombra API key authentication */\n preferences: ConsentPreferenceUpload[];\n /** API URL for Transcend backend */\n transcendUrl?: string;\n /** Concurrency limit for approving */\n concurrency?: number;\n}): Promise<void> {\n // Create connection to API\n const transcendConsentApi = createTranscendConsentGotInstance(transcendUrl);\n\n // Ensure usp strings are valid\n const invalidUspStrings = preferences.filter(\n (pref) => pref.usp && !USP_STRING_REGEX.test(pref.usp),\n );\n if (invalidUspStrings.length > 0) {\n throw new Error(\n `Received invalid usp strings: ${JSON.stringify(\n invalidUspStrings,\n null,\n 2,\n )}`,\n );\n }\n\n // Ensure purpose maps are valid\n const invalidPurposeMaps = preferences\n .map((pref, ind) => [pref, ind] as [ConsentPreferenceUpload, number])\n .filter(([pref]) => {\n if (!pref.purposes) {\n return false;\n }\n try {\n decodeCodec(PurposeMap, pref.purposes);\n return false;\n } catch {\n return true;\n }\n });\n if (invalidPurposeMaps.length > 0) {\n throw new Error(\n `Received invalid purpose maps: ${JSON.stringify(\n invalidPurposeMaps,\n null,\n 2,\n )}`,\n );\n }\n\n // Ensure usp or preferences are provided\n const invalidInputs = preferences.filter(\n (pref) => !pref.usp && !pref.purposes,\n );\n if (invalidInputs.length > 0) {\n throw new Error(\n `Received invalid inputs, expected either purposes or usp to be defined: ${JSON.stringify(\n invalidInputs,\n null,\n 2,\n )}`,\n );\n }\n\n logger.info(\n colors.magenta(\n `Uploading ${preferences.length} user preferences to partition ${partition}`,\n ),\n );\n\n // Time duration\n const t0 = new Date().getTime();\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 progressBar.start(preferences.length, 0);\n await map(\n preferences,\n async ({\n userId,\n confirmed = 'true',\n updated,\n prompted,\n purposes,\n ...consent\n }) => {\n const token = createConsentToken(\n userId,\n base64EncryptionKey,\n base64SigningKey,\n );\n\n // parse usp string\n const [, saleStatus] = consent.usp\n ? USP_STRING_REGEX.exec(consent.usp) || []\n : [];\n\n const input = {\n token,\n partition,\n consent: {\n confirmed: confirmed === 'true',\n purposes: purposes\n ? decodeCodec(PurposeMap, purposes)\n : consent.usp\n ? { SaleOfInfo: saleStatus === 'Y' }\n : {},\n ...(updated ? { updated: updated === 'true' } : {}),\n ...(prompted ? { prompted: prompted === 'true' } : {}),\n ...consent,\n },\n } as ConsentPreferencesBody;\n\n // Make the request\n try {\n await transcendConsentApi\n .post('sync', {\n json: input,\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 throw new Error(\n `Received an error from server: ${\n err?.response?.body || err?.message\n }`,\n );\n }\n\n total += 1;\n progressBar.update(total);\n },\n { concurrency },\n );\n\n progressBar.stop();\n const t1 = new Date().getTime();\n const totalTime = t1 - t0;\n\n logger.info(\n colors.green(\n `Successfully uploaded ${\n preferences.length\n } user preferences to partition ${partition} in \"${\n totalTime / 1000\n }\" seconds!`,\n ),\n );\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
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 }; }var _chunkVWN5MN3Ucjs = require('./chunk-VWN5MN3U.cjs');var _chunkZUNVPK23cjs = require('./chunk-ZUNVPK23.cjs');var _chunkGJ6V5BHGcjs = require('./chunk-GJ6V5BHG.cjs');var _privacytypes = require('@transcend-io/privacy-types');var _colors = require('colors'); var _colors2 = _interopRequireDefault(_colors);async function re({file:u,auth:s,sombraAuth:g,requestActions:f=[],concurrency:p=100,transcendUrl:n=_chunkGJ6V5BHGcjs.r}){let o=_chunkVWN5MN3Ucjs.zc.call(void 0, n,s),e=await _chunkVWN5MN3Ucjs.Ac.call(void 0, n,s,g);_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Pulling manual enrichment requests, filtered for actions: ${f.join(",")}`));let d=await _chunkVWN5MN3Ucjs.qd.call(void 0, o,{actions:f,statuses:[_privacytypes.RequestStatus.Enriching]}),i=[];await _chunkVWN5MN3Ucjs.a.call(void 0, d,async t=>{let c=await _chunkVWN5MN3Ucjs.kd.call(void 0, o,{requestId:t.id});if(c.filter(({status:m})=>m==="ACTION_REQUIRED")){let m=await _chunkVWN5MN3Ucjs.nd.call(void 0, o,e,{requestId:t.id});i.push({...t,requestIdentifiers:m,requestEnrichers:c})}},{concurrency:p});let l=i.map(({attributeValues:t,requestIdentifiers:c,requestEnrichers:I,...m})=>({...m,...Object.entries(_chunkGJ6V5BHGcjs.d.call(void 0, c,"name")).reduce((P,[$,C])=>Object.assign(P,{[$]:C.map(({value:A})=>A).join(",")}),{}),...Object.entries(_chunkGJ6V5BHGcjs.d.call(void 0, t,"attributeKey.name")).reduce((P,[$,C])=>Object.assign(P,{[$]:C.map(({name:A})=>A).join(",")}),{})})),a=_chunkGJ6V5BHGcjs.j.call(void 0, l.map(t=>Object.keys(t)).flat());return await _chunkVWN5MN3Ucjs.tg.call(void 0, u,l,a),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Successfully wrote ${i.length} requests to file "${u}"`)),i}var _iots = require('io-ts'); var R = _interopRequireWildcard(_iots);var j="https://app.transcend.io/privacy-requests/incoming-requests/",M= exports.b =R.record(R.string,R.string);async function N(u,{id:s,...g},f,p){if(!s){let e=`Request ID must be provided to enricher request.${p?` Found error in row: ${p}`:""}`;throw _chunkZUNVPK23cjs.a.error(_colors2.default.red(e)),new Error(e)}let n=s.toLowerCase(),o=Object.entries(g).reduce((e,[d,i])=>_chunkGJ6V5BHGcjs.j.call(void 0, _chunkVWN5MN3Ucjs.rc.call(void 0, i)).length===0?e:Object.assign(e,{[d]:_chunkGJ6V5BHGcjs.j.call(void 0, _chunkVWN5MN3Ucjs.rc.call(void 0, i)).map(a=>({value:d==="email"?a.toLowerCase():a}))}),{});try{return await u.post("v1/enrich-identifiers",{headers:{"x-transcend-request-id":n,"x-transcend-enricher-id":f},json:{enrichedIdentifiers:o}}).json(),_chunkZUNVPK23cjs.a.error(_colors2.default.green(`Successfully enriched request: ${j}${n}`)),!0}catch(e){if(typeof e.response.body=="string"&&e.response.body.includes("Cannot update a resolved RequestEnricher"))return _chunkZUNVPK23cjs.a.warn(_colors2.default.magenta(`Skipped enrichment for request: ${j}${n}, request is no longer in the enriching phase.`)),!1;throw _chunkZUNVPK23cjs.a.error(_colors2.default.red(`Failed to enricher identifiers for request with id: ${j}${n} - ${e.message} - ${e.response.body}`)),e}}async function he({file:u,auth:s,sombraAuth:g,enricherId:f,markSilent:p,concurrency:n=100,transcendUrl:o=_chunkGJ6V5BHGcjs.r}){let e=await _chunkVWN5MN3Ucjs.Ac.call(void 0, o,s,g),d=_chunkVWN5MN3Ucjs.zc.call(void 0, o,s);_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Reading "${u}" from disk`));let i=_chunkVWN5MN3Ucjs.uc.call(void 0, u,M);_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Enriching "${i.length}" privacy requests.`));let l=0,a=0,t=0;if(await _chunkVWN5MN3Ucjs.a.call(void 0, i,async(c,I)=>{try{p&&(await _chunkVWN5MN3Ucjs.wg.call(void 0, d,_chunkVWN5MN3Ucjs.$,{input:{id:c.id,isSilent:!0}}),_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Mark request as silent mode - ${c.id}`))),await N(e,c,f,I)?l+=1:a+=1}catch (e2){t+=1}},{concurrency:n}),_chunkZUNVPK23cjs.a.info(_colors2.default.green(`Successfully notified Transcend!
|
|
2
|
+
Success count: ${l}.`)),a>0&&_chunkZUNVPK23cjs.a.info(_colors2.default.magenta(`Skipped count: ${a}.`)),t>0)throw _chunkZUNVPK23cjs.a.info(_colors2.default.red(`Error Count: ${t}.`)),new Error(`Failed to enrich: ${t} requests.`);return i.length}exports.a = re; exports.b = M; exports.c = N; exports.d = he;
|
|
3
|
+
//# sourceMappingURL=chunk-O7SJYOEK.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/cli/cli/dist/chunk-O7SJYOEK.cjs","../src/lib/manual-enrichment/pullManualEnrichmentIdentifiersToCsv.ts","../src/lib/manual-enrichment/pushManualEnrichmentIdentifiersFromCsv.ts"],"names":["pullManualEnrichmentIdentifiersToCsv","file","auth","sombraAuth","requestActions","concurrency","transcendUrl","DEFAULT_TRANSCEND_API","client","buildTranscendGraphQLClient","sombra","createSombraGotInstance","logger","colors"],"mappings":"AAAA,mfAAuH,wDAAyC,wDAAuD,2DCA1K,gFAE1B,MA6BnB,SAAsBA,EAAAA,CAAqC,CACzD,IAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CAAAA,CACA,UAAA,CAAAC,CAAAA,CACA,cAAA,CAAAC,CAAAA,CAAiB,CAAC,CAAA,CAClB,WAAA,CAAAC,CAAAA,CAAc,GAAA,CACd,YAAA,CAAAC,CAAAA,CAAeC,mBACjB,CAAA,CAa6C,CAE3C,IAAMC,CAAAA,CAASC,kCAAAA,CAA4BH,CAAcJ,CAAI,CAAA,CACvDQ,CAAAA,CAAS,MAAMC,kCAAAA,CAAwBL,CAAcJ,CAAAA,CAAMC,CAAU,CAAA,CAE3ES,mBAAAA,CAAO,IAAA,CACLC,gBAAAA,CAAO,OAAA,CACL,CAAA,0DAAA,EAA6DT,CAAAA,CAAe,IAAA,CAC1E,GACF,CAAC,CAAA,CAAA;ACuDP,gBAAA","file":"/home/runner/work/cli/cli/dist/chunk-O7SJYOEK.cjs","sourcesContent":[null,"import { RequestAction, RequestStatus } from '@transcend-io/privacy-types';\nimport { map } from '../bluebird';\nimport colors from 'colors';\nimport { groupBy, uniq } from 'lodash-es';\nimport { DEFAULT_TRANSCEND_API } from '../../constants';\nimport { writeCsv } from '../helpers/writeCsv';\nimport {\n PrivacyRequest,\n RequestEnricher,\n RequestIdentifier,\n buildTranscendGraphQLClient,\n createSombraGotInstance,\n fetchAllRequestEnrichers,\n fetchAllRequestIdentifiers,\n fetchAllRequests,\n} from '../graphql';\nimport { logger } from '../../logger';\n\nexport interface PrivacyRequestWithIdentifiers extends PrivacyRequest {\n /** Request Enrichers */\n requestEnrichers: RequestEnricher[];\n /** Request Identifiers */\n requestIdentifiers: RequestIdentifier[];\n}\n\n/**\n * Pull the set of manual enrichment jobs to CSV\n *\n * @param options - Options\n * @returns List of requests with identifiers\n */\nexport async function pullManualEnrichmentIdentifiersToCsv({\n file,\n auth,\n sombraAuth,\n requestActions = [],\n concurrency = 100,\n transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n /** CSV file path */\n file: string;\n /** Transcend API key authentication */\n auth: string;\n /** Sombra API key */\n sombraAuth?: string;\n /** Concurrency */\n concurrency?: number;\n /** The request actions to fetch */\n requestActions?: RequestAction[];\n /** API URL for Transcend backend */\n transcendUrl?: string;\n}): Promise<PrivacyRequestWithIdentifiers[]> {\n // Find all requests made before createdAt that are in a removing data state\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n const sombra = await createSombraGotInstance(transcendUrl, auth, sombraAuth);\n\n logger.info(\n colors.magenta(\n `Pulling manual enrichment requests, filtered for actions: ${requestActions.join(\n ',',\n )}`,\n ),\n );\n\n // Pull all privacy requests\n const allRequests = await fetchAllRequests(client, {\n actions: requestActions,\n statuses: [RequestStatus.Enriching],\n });\n\n // Requests to save\n const savedRequests: PrivacyRequestWithIdentifiers[] = [];\n\n // Filter down requests to what is needed\n await map(\n allRequests,\n async (request) => {\n // Fetch enrichers\n const requestEnrichers = await fetchAllRequestEnrichers(client, {\n requestId: request.id,\n });\n\n // Check if manual enrichment exists for that request\n const hasManualEnrichment = requestEnrichers.filter(\n ({ status }) => status === 'ACTION_REQUIRED',\n );\n\n // Save request to queue\n if (hasManualEnrichment) {\n const requestIdentifiers = await fetchAllRequestIdentifiers(\n client,\n sombra,\n {\n requestId: request.id,\n },\n );\n savedRequests.push({\n ...request,\n requestIdentifiers,\n requestEnrichers,\n });\n }\n },\n {\n concurrency,\n },\n );\n\n const data = savedRequests.map(\n ({\n attributeValues,\n requestIdentifiers,\n requestEnrichers, // eslint-disable-line @typescript-eslint/no-unused-vars\n ...request\n }) => ({\n ...request,\n // flatten identifiers\n ...Object.entries(groupBy(requestIdentifiers, 'name')).reduce(\n (acc, [key, values]) =>\n Object.assign(acc, {\n [key]: values.map(({ value }) => value).join(','),\n }),\n {},\n ),\n // flatten attributes\n ...Object.entries(groupBy(attributeValues, 'attributeKey.name')).reduce(\n (acc, [key, values]) =>\n Object.assign(acc, {\n [key]: values.map(({ name }) => name).join(','),\n }),\n {},\n ),\n }),\n );\n\n // Write out to CSV\n const headers = uniq(data.map((d) => Object.keys(d)).flat());\n await writeCsv(file, data, headers);\n\n logger.info(\n colors.green(\n `Successfully wrote ${savedRequests.length} requests to file \"${file}\"`,\n ),\n );\n\n return savedRequests;\n}\n","import colors from 'colors';\nimport { map } from '../bluebird';\nimport { logger } from '../../logger';\nimport {\n UPDATE_PRIVACY_REQUEST,\n buildTranscendGraphQLClient,\n createSombraGotInstance,\n makeGraphQLRequest,\n} from '../graphql';\nimport {\n enrichPrivacyRequest,\n EnrichPrivacyRequest,\n} from './enrichPrivacyRequest';\nimport { readCsv } from '../requests';\nimport { DEFAULT_TRANSCEND_API } from '../../constants';\n\n/**\n * Push a CSV of enriched requests back into Transcend\n *\n * @param options - Options\n * @returns Number of items processed\n */\nexport async function pushManualEnrichmentIdentifiersFromCsv({\n file,\n auth,\n sombraAuth,\n enricherId,\n markSilent,\n concurrency = 100,\n transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n /** CSV file path */\n file: string;\n /** Transcend API key authentication */\n auth: string;\n /** ID of enricher being uploaded to */\n enricherId: string;\n /** Sombra API key authentication */\n sombraAuth?: string;\n /** Concurrency */\n concurrency?: number;\n /** API URL for Transcend backend */\n transcendUrl?: string;\n /** Mark requests in silent mode before enriching */\n markSilent?: boolean;\n}): Promise<number> {\n // Create sombra instance to communicate with\n const sombra = await createSombraGotInstance(transcendUrl, auth, sombraAuth);\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n // Read from CSV\n logger.info(colors.magenta(`Reading \"${file}\" from disk`));\n const activeResults = readCsv(file, EnrichPrivacyRequest);\n\n // Notify Transcend\n logger.info(\n colors.magenta(`Enriching \"${activeResults.length}\" privacy requests.`),\n );\n\n let successCount = 0;\n let skippedCount = 0;\n let errorCount = 0;\n\n await map(\n activeResults,\n async (request, index) => {\n try {\n // Mark requests in silent mode before a certain date\n if (markSilent) {\n await makeGraphQLRequest(client, UPDATE_PRIVACY_REQUEST, {\n input: {\n id: request.id,\n isSilent: true,\n },\n });\n\n logger.info(\n colors.magenta(`Mark request as silent mode - ${request.id}`),\n );\n }\n\n const result = await enrichPrivacyRequest(\n sombra,\n request,\n enricherId,\n index,\n );\n if (result) {\n successCount += 1;\n } else {\n skippedCount += 1;\n }\n } catch (err) {\n errorCount += 1;\n }\n },\n { concurrency },\n );\n\n logger.info(\n colors.green(\n `Successfully notified Transcend! \\n Success count: ${successCount}.`,\n ),\n );\n\n if (skippedCount > 0) {\n logger.info(colors.magenta(`Skipped count: ${skippedCount}.`));\n }\n\n if (errorCount > 0) {\n logger.info(colors.red(`Error Count: ${errorCount}.`));\n throw new Error(`Failed to enrich: ${errorCount} requests.`);\n }\n\n return activeResults.length;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
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
|
|
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 _chunkVWN5MN3Ucjs = require('./chunk-VWN5MN3U.cjs');var _chunkZUNVPK23cjs = require('./chunk-ZUNVPK23.cjs');var _chunkGJ6V5BHGcjs = require('./chunk-GJ6V5BHG.cjs');var _os = require('os');function Kt(e,t){let o=Math.max(1,_nullishCoalesce(_optionalChain([_os.availableParallelism, 'optionalCall', _2 => _2()]), () => (1)));return{poolSize:typeof e=="number"&&e>0?Math.min(e,t):Math.min(o,t),cpuCount:o}}var _child_process = require('child_process');var _path = require('path');var _fs = require('fs');var _colors = require('colors'); var _colors2 = _interopRequireDefault(_colors);function rt(e){return`'${String(e).replace(/'/g,"'\\''")}'`}function ot(e,t,o=!1){if(o)return;let r=_os.platform.call(void 0, );try{if(r==="darwin"){let l=e.map(rt).join(" -f "),s=`
|
|
2
2
|
tell application "Terminal"
|
|
3
3
|
activate
|
|
4
4
|
do script "printf '\\e]0;${t}\\a'; tail -n +1 -f ${l}"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
`):L.write(`${k}
|
|
12
12
|
`)}catch (e6){}});i.stderr.on("data",x)}return i[at]={structuredPath:a,outPath:f,errPath:m,infoPath:c,warnPath:d,errorPath:g},n&&ot([a,f,m,c,d,g],`worker-${t}`,l),p.on("error",()=>{}),h.on("error",()=>{}),T.on("error",()=>{}),L.on("error",()=>{}),$.on("error",()=>{}),i}var _readline = require('readline'); var q = _interopRequireWildcard(_readline); var gt = _interopRequireWildcard(_readline);var ut="",Ft=(e,t)=>{let o=Math.min(e-1,9),r=e<=1?"0":`0-${o}`,n=e>10?" (Tab/Shift+Tab for \u226510)":"";return t?_colors2.default.dim("Run complete \u2014 digits to view logs \u2022 Tab/Shift+Tab cycle \u2022 Esc/Ctrl+] detach \u2022 q to quit"):_colors2.default.dim(`Hotkeys: [${r}] attach${n} \u2022 e=errors \u2022 w=warnings \u2022 i=info \u2022 l=logs \u2022 Tab/Shift+Tab \u2022 Esc/Ctrl+] detach \u2022 Ctrl+C exit`)};function ue(e,t,o=!1){let r=[...t.renderHeader(e),"",...t.renderWorkers(e),...o?[]:["",Ft(e.poolSize,e.final)],...t.renderExtras?[""].concat(t.renderExtras(e)):[]].join(`
|
|
13
13
|
`);!e.final&&r===ut||(ut=r,e.final?process.stdout.write("\x1B[?25h"):(process.stdout.write("\x1B[?25l"),q.cursorTo(process.stdout,0,0),q.clearScreenDown(process.stdout)),process.stdout.write(`${r}
|
|
14
|
-
`))}function J(e,t,o){let r=t.get(e);if(O(r))try{let n=K(r);if(n!=null)return n}catch (e7){}return o.get(e)}async function dt(e,t,o){await new Promise(r=>{try{let n=_fs.statSync.call(void 0, e),l=Math.max(0,n.size-t),s=_fs.createReadStream.call(void 0, e,{start:l,encoding:"utf8"});s.on("data",a=>o(a)),s.on("end",r),s.on("error",r)}catch (e8){r(void 0)}})}function pt(e,t,o){if(t.ctrl&&t.name==="c")return{type:"CTRL_C"};if(o==="dashboard")return t.name&&/^[0-9]$/.test(t.name)?{type:"ATTACH",id:Number(t.name)}:t.name==="tab"&&!t.shift?{type:"CYCLE",delta:1}:t.name==="tab"&&t.shift?{type:"CYCLE",delta:-1}:t.name==="q"?{type:"QUIT"}:null;if(t.name==="escape"||t.ctrl&&t.name==="]")return{type:"DETACH"};if(t.ctrl&&t.name==="d")return{type:"CTRL_D"};let r=_nullishCoalesce(_nullishCoalesce(t.sequence, () => (e)), () => (""));return r?{type:"FORWARD",sequence:r}:null}function ft(e){return[...e.keys()].sort((t,o)=>t-o)}function mt(e,t,o){if(!e.length)return null;let r=_nullishCoalesce(t, () => (e[0])),n=e.indexOf(r);return n===-1&&(n=0),n=(n+o+e.length)%e.length,e[n]}function ht(e){let{workers:t,onAttach:o,onDetach:r,onCtrlC:n,getLogPaths:l,replayBytes:s=200*1024,replayWhich:a=["out","err"],onEnterAttachScreen:f,ports:m}=e,c=_nullishCoalesce(_optionalChain([m, 'optionalAccess', _17 => _17.stdin]), () => (process.stdin)),d=_nullishCoalesce(_optionalChain([m, 'optionalAccess', _18 => _18.stdout]), () => (process.stdout)),g=_nullishCoalesce(_optionalChain([m, 'optionalAccess', _19 => _19.stderr]), () => (process.stderr)),i=(...b)=>{if(
|
|
14
|
+
`))}function J(e,t,o){let r=t.get(e);if(O(r))try{let n=K(r);if(n!=null)return n}catch (e7){}return o.get(e)}async function dt(e,t,o){await new Promise(r=>{try{let n=_fs.statSync.call(void 0, e),l=Math.max(0,n.size-t),s=_fs.createReadStream.call(void 0, e,{start:l,encoding:"utf8"});s.on("data",a=>o(a)),s.on("end",r),s.on("error",r)}catch (e8){r(void 0)}})}function pt(e,t,o){if(t.ctrl&&t.name==="c")return{type:"CTRL_C"};if(o==="dashboard")return t.name&&/^[0-9]$/.test(t.name)?{type:"ATTACH",id:Number(t.name)}:t.name==="tab"&&!t.shift?{type:"CYCLE",delta:1}:t.name==="tab"&&t.shift?{type:"CYCLE",delta:-1}:t.name==="q"?{type:"QUIT"}:null;if(t.name==="escape"||t.ctrl&&t.name==="]")return{type:"DETACH"};if(t.ctrl&&t.name==="d")return{type:"CTRL_D"};let r=_nullishCoalesce(_nullishCoalesce(t.sequence, () => (e)), () => (""));return r?{type:"FORWARD",sequence:r}:null}function ft(e){return[...e.keys()].sort((t,o)=>t-o)}function mt(e,t,o){if(!e.length)return null;let r=_nullishCoalesce(t, () => (e[0])),n=e.indexOf(r);return n===-1&&(n=0),n=(n+o+e.length)%e.length,e[n]}function ht(e){let{workers:t,onAttach:o,onDetach:r,onCtrlC:n,getLogPaths:l,replayBytes:s=200*1024,replayWhich:a=["out","err"],onEnterAttachScreen:f,ports:m}=e,c=_nullishCoalesce(_optionalChain([m, 'optionalAccess', _17 => _17.stdin]), () => (process.stdin)),d=_nullishCoalesce(_optionalChain([m, 'optionalAccess', _18 => _18.stdout]), () => (process.stdout)),g=_nullishCoalesce(_optionalChain([m, 'optionalAccess', _19 => _19.stderr]), () => (process.stderr)),i=(...b)=>{if(_chunkGJ6V5BHGcjs.z)try{(_nullishCoalesce(_optionalChain([m, 'optionalAccess', _20 => _20.stderr]), () => (process.stderr))).write(`[keys] ${b.map(String).join(" ")}
|
|
15
15
|
`)}catch (e9){}};if(!c.isTTY)return()=>{};gt.emitKeypressEvents(c),_optionalChain([c, 'access', _21 => _21.setRawMode, 'optionalCall', _22 => _22(!0)]);let p="dashboard",h=null,T=null,L=null;async function $(b){if(!l)return;let y=l(b);if(!y)return;let S=[];for(let w of a)w==="out"&&S.push(y.outPath),w==="err"&&S.push(y.errPath),w==="structured"&&S.push(y.structuredPath);if(S.length){d.write(`
|
|
16
16
|
------------ replay ------------
|
|
17
17
|
`);for(let w of S)d.write(`
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
`),await dt(w,s,R=>d.write(R));d.write(`
|
|
20
20
|
--------------------------------
|
|
21
21
|
|
|
22
|
-
`)}}let E=async b=>{i("attach()",`id=${b}`);let y=t.get(b);if(!y)return;p==="attached"&&x(),p="attached",h=b,_optionalChain([f, 'optionalCall', _23 => _23(b)]),_optionalChain([o, 'optionalCall', _24 => _24(b)]),await $(b),T=w=>d.write(w),L=w=>g.write(w),_optionalChain([y, 'access', _25 => _25.stdout, 'optionalAccess', _26 => _26.on, 'call', _27 => _27("data",T)]),_optionalChain([y, 'access', _28 => _28.stderr, 'optionalAccess', _29 => _29.on, 'call', _30 => _30("data",L)]);let S=()=>{h===b&&x()};y.once("exit",S)},x=()=>{if(i("detach()",`id=${h}`),h==null)return;let b=h,y=t.get(b);y&&(T&&_optionalChain([y, 'access', _31 => _31.stdout, 'optionalAccess', _32 => _32.off, 'call', _33 => _33("data",T)]),L&&_optionalChain([y, 'access', _34 => _34.stderr, 'optionalAccess', _35 => _35.off, 'call', _36 => _36("data",L)])),T=null,L=null,h=null,p="dashboard",_optionalChain([r, 'optionalCall', _37 => _37()])},k=(b,y)=>{i("keypress",JSON.stringify({str:b,name:y.name,seq:y.sequence,ctrl:y.ctrl,meta:y.meta,shift:y.shift,mode:p}));let S=pt(b,y,p);if(i("mapped",JSON.stringify(S)),!!S)switch(S.type){case"CTRL_C":{if(i("CTRL_C"),p==="attached"&&h!=null){let w=t.get(h);try{_optionalChain([w, 'optionalAccess', _38 => _38.kill, 'call', _39 => _39("SIGINT")])}catch (e10){}x();return}_optionalChain([n, 'optionalCall', _40 => _40()]);return}case"ATTACH":{if(i("ATTACH",`id=${S.id}`,`has=${t.has(S.id)}`),p!=="dashboard")return;t.has(S.id)&&E(S.id);return}case"CYCLE":{if(i("CYCLE",`delta=${S.delta}`),p!=="dashboard")return;let w=mt(ft(t),h,S.delta);w!=null&&E(w);return}case"QUIT":{if(p!=="dashboard")return;_optionalChain([n, 'optionalCall', _41 => _41()]);return}case"DETACH":{i("DETACH"),p==="attached"&&x();return}case"CTRL_D":{if(p==="attached"&&h!=null){let w=t.get(h);try{_optionalChain([w, 'optionalAccess', _42 => _42.stdin, 'optionalAccess', _43 => _43.end, 'call', _44 => _44()])}catch (e11){}}return}case"FORWARD":if(p==="attached"&&h!=null){let w=t.get(h);try{_optionalChain([w, 'optionalAccess', _45 => _45.stdin, 'optionalAccess', _46 => _46.write, 'call', _47 => _47(S.sequence)])}catch (e12){}}}},A=b=>{if(p==="attached"&&h!=null){let y=t.get(h);try{_optionalChain([y, 'optionalAccess', _48 => _48.stdin, 'optionalAccess', _49 => _49.write, 'call', _50 => _50(b)])}catch (e13){}}},j=()=>{c.off("keypress",k),c.off("data",A),_optionalChain([c, 'access', _51 => _51.setRawMode, 'optionalCall', _52 => _52(!1)]),d.write("\x1B[?25h")};return c.on("keypress",k),c.on("data",A),j}async function Re(e){let{title:t,baseDir:o,poolSize:r,cpuCount:n,render:l,childModulePath:s,hooks:a,filesTotal:f,childFlag:m,viewerMode:c=!1}=e,d=_nullishCoalesce(e.openLogWindows, () => (!c)),g=_nullishCoalesce(e.isSilent, () => (!0)),i=Date.now(),p=it(o),h=new Map,T=new Map,L=new Map,$=new
|
|
22
|
+
`)}}let E=async b=>{i("attach()",`id=${b}`);let y=t.get(b);if(!y)return;p==="attached"&&x(),p="attached",h=b,_optionalChain([f, 'optionalCall', _23 => _23(b)]),_optionalChain([o, 'optionalCall', _24 => _24(b)]),await $(b),T=w=>d.write(w),L=w=>g.write(w),_optionalChain([y, 'access', _25 => _25.stdout, 'optionalAccess', _26 => _26.on, 'call', _27 => _27("data",T)]),_optionalChain([y, 'access', _28 => _28.stderr, 'optionalAccess', _29 => _29.on, 'call', _30 => _30("data",L)]);let S=()=>{h===b&&x()};y.once("exit",S)},x=()=>{if(i("detach()",`id=${h}`),h==null)return;let b=h,y=t.get(b);y&&(T&&_optionalChain([y, 'access', _31 => _31.stdout, 'optionalAccess', _32 => _32.off, 'call', _33 => _33("data",T)]),L&&_optionalChain([y, 'access', _34 => _34.stderr, 'optionalAccess', _35 => _35.off, 'call', _36 => _36("data",L)])),T=null,L=null,h=null,p="dashboard",_optionalChain([r, 'optionalCall', _37 => _37()])},k=(b,y)=>{i("keypress",JSON.stringify({str:b,name:y.name,seq:y.sequence,ctrl:y.ctrl,meta:y.meta,shift:y.shift,mode:p}));let S=pt(b,y,p);if(i("mapped",JSON.stringify(S)),!!S)switch(S.type){case"CTRL_C":{if(i("CTRL_C"),p==="attached"&&h!=null){let w=t.get(h);try{_optionalChain([w, 'optionalAccess', _38 => _38.kill, 'call', _39 => _39("SIGINT")])}catch (e10){}x();return}_optionalChain([n, 'optionalCall', _40 => _40()]);return}case"ATTACH":{if(i("ATTACH",`id=${S.id}`,`has=${t.has(S.id)}`),p!=="dashboard")return;t.has(S.id)&&E(S.id);return}case"CYCLE":{if(i("CYCLE",`delta=${S.delta}`),p!=="dashboard")return;let w=mt(ft(t),h,S.delta);w!=null&&E(w);return}case"QUIT":{if(p!=="dashboard")return;_optionalChain([n, 'optionalCall', _41 => _41()]);return}case"DETACH":{i("DETACH"),p==="attached"&&x();return}case"CTRL_D":{if(p==="attached"&&h!=null){let w=t.get(h);try{_optionalChain([w, 'optionalAccess', _42 => _42.stdin, 'optionalAccess', _43 => _43.end, 'call', _44 => _44()])}catch (e11){}}return}case"FORWARD":if(p==="attached"&&h!=null){let w=t.get(h);try{_optionalChain([w, 'optionalAccess', _45 => _45.stdin, 'optionalAccess', _46 => _46.write, 'call', _47 => _47(S.sequence)])}catch (e12){}}}},A=b=>{if(p==="attached"&&h!=null){let y=t.get(h);try{_optionalChain([y, 'optionalAccess', _48 => _48.stdin, 'optionalAccess', _49 => _49.write, 'call', _50 => _50(b)])}catch (e13){}}},j=()=>{c.off("keypress",k),c.off("data",A),_optionalChain([c, 'access', _51 => _51.setRawMode, 'optionalCall', _52 => _52(!1)]),d.write("\x1B[?25h")};return c.on("keypress",k),c.on("data",A),j}async function Re(e){let{title:t,baseDir:o,poolSize:r,cpuCount:n,render:l,childModulePath:s,hooks:a,filesTotal:f,childFlag:m,viewerMode:c=!1}=e,d=_nullishCoalesce(e.openLogWindows, () => (!c)),g=_nullishCoalesce(e.isSilent, () => (!0)),i=Date.now(),p=it(o),h=new Map,T=new Map,L=new Map,$=new _chunkVWN5MN3Ucjs.dg,x=_nullishCoalesce(_optionalChain([a, 'access', _53 => _53.initTotals, 'optionalCall', _54 => _54()]), () => ({})),k=0,A=0,j=0,b=null,y=!1,S=!1,w=null,R=(u=!1)=>{S||l({title:t,poolSize:r,cpuCount:n,filesTotal:f,filesCompleted:A,filesFailed:j,workerState:T,totals:x,final:u,exportStatus:_optionalChain([a, 'access', _55 => _55.exportStatus, 'optionalCall', _56 => _56()]),throughput:{successSoFar:A,r10s:$.rate(1e4),r60s:$.rate(6e4)}})},U=u=>{let v=a.nextTask();if(!v)return!1;let F=h.get(u),P=a.taskLabel(v),W=_optionalChain([a, 'access', _57 => _57.initSlotProgress, 'optionalCall', _58 => _58(v)]);return T.set(u,{busy:!0,file:P,startedAt:Date.now(),lastLevel:"ok",progress:W}),G(F,{type:"task",payload:v}),R(),!0};for(let u=0;u<r;u+=1){let v=lt({id:u,modulePath:s,logDir:p,openLogWindows:d,isSilent:g,childFlag:m});h.set(u,v),T.set(u,{busy:!1,file:null,startedAt:null,lastLevel:"ok"}),L.set(u,K(v)),k+=1;let F=I(P=>{let W=_(P);if(!W)return;let H=T.get(u);H.lastLevel!==W&&(T.set(u,{...H,lastLevel:W}),R())});_optionalChain([v, 'access', _59 => _59.stderr, 'optionalAccess', _60 => _60.on, 'call', _61 => _61("data",F)]),v.on("message",P=>{if(!(!P||typeof P!="object")){if(P.type==="ready"){y||(y=!0,b=setInterval(()=>R(!1),350)),U(u);return}if(P.type==="progress"){x=a.onProgress(x,P.payload);let W=T.get(u);T.set(u,{...W,progress:P.payload}),R();return}if(P.type==="result"){let W=T.get(u),{totals:H,ok:X}=a.onResult(x,P.payload);x=H,X?(A+=1,$.add(1)):j+=1,T.set(u,{...W,busy:!1,file:null,progress:void 0,lastLevel:X?"ok":"error"}),!U(u)&&O(v)&&G(v,{type:"shutdown"}),R()}}}),v.on("exit",()=>{k-=1,k===0&&(b&&clearInterval(b),R(!0))})}let z=()=>{},Y=()=>{try{_optionalChain([process, 'access', _62 => _62.stdin, 'access', _63 => _63.setRawMode, 'optionalCall', _64 => _64(!1)])}catch (e14){}try{process.stdin.pause()}catch (e15){}},Q=()=>{if(b&&clearInterval(b),_optionalChain([z, 'optionalCall', _65 => _65()]),w)try{process.stdin.off("data",w)}catch (e16){}Y(),process.stdout.write(`
|
|
23
23
|
Stopping workers...
|
|
24
24
|
`);for(let[,u]of h){O(u)&&G(u,{type:"shutdown"});try{_optionalChain([u, 'optionalAccess', _66 => _66.kill, 'call', _67 => _67("SIGTERM")])}catch (e17){}}process.exit(130)},V=u=>{S=!0,process.stdout.write("\x1B[2J\x1B[H"),process.stdout.write(`Attached to worker ${u}. (Esc/Ctrl+] detach \u2022 Ctrl+D EOF \u2022 Ctrl+C SIGINT)
|
|
25
25
|
`)},St=()=>{S=!1,R()};if(process.once("SIGINT",Q),!c){if(process.stdin.isTTY){try{process.stdin.setRawMode(!0)}catch (e18){process.stdout.write(_colors2.default.yellow(`Warning: Unable to enable raw mode for interactive key handling.
|
|
@@ -35,4 +35,4 @@ Press Esc/Ctrl+] to return to dashboard.
|
|
|
35
35
|
`),(async()=>{try{await wt(t,g,i)}catch (e21){m=!1,r(!1),o()}})())},d=(g,i)=>{if(n)try{let p=n.exportCombinedLogs(t,g);a(`
|
|
36
36
|
Wrote combined ${i} logs to: ${p}`),f(g,p)}catch (e22){a(`
|
|
37
37
|
Failed to write combined ${i} logs`)}};return g=>{let i=g.toString("utf8");if(i==="e"){c(["err"],"error");return}if(i==="w"){c(["warn","err"],"warn");return}if(i==="i"){c(["info"],"all");return}if(i==="l"){c(["out","err","structured"],"all");return}if(i==="E"){d("error","error");return}if(i==="W"){d("warn","warn");return}if(i==="I"){d("info","info");return}if(i==="A"){d("all","ALL");return}let p=_optionalChain([s, 'optionalAccess', _78 => _78[i]]);if(p){p({noteExport:f,say:a});return}(i==="\x1B"||i==="")&&(m=!1,r(!1),o())}}var _events = require('events');var _url = require('url');function B(e){return typeof e=="number"?e.toLocaleString():"0"}function yt(e,t=40){let o=Math.max(0,Math.min(100,Math.floor(e))),r=Math.floor(o/100*t);return"\u2588".repeat(r)+"\u2591".repeat(t-r)}function Nt(e){let t=[...e.workerState.values()].filter(n=>n.busy).length,o=e.filesCompleted+e.filesFailed,r=e.filesTotal===0?100:Math.floor(o/Math.max(1,e.filesTotal)*100);return{done:o,inProgress:t,pct:r}}function or(e,t=[]){let{title:o,poolSize:r,cpuCount:n,filesTotal:l,filesCompleted:s,filesFailed:a,throughput:f}=e,{inProgress:m,pct:c}=Nt(e),d=[`${_colors2.default.bold(o)} \u2014 ${r} workers ${_colors2.default.dim(`(CPU avail: ${n})`)}`,`${_colors2.default.dim("Files")} ${B(l)} ${_colors2.default.dim("Completed")} ${B(s)} ${_colors2.default.dim("Failed")} ${a?_colors2.default.red(B(a)):B(a)} ${_colors2.default.dim("In-flight")} ${B(m)}`,`[${yt(c)}] ${c}%`];if(f){let g=Math.round(f.r10s*3600).toLocaleString(),i=Math.round(f.r60s*3600).toLocaleString(),p=_optionalChain([e, 'access', _79 => _79.throughput, 'optionalAccess', _80 => _80.successSoFar])!=null?` Newly uploaded: ${B(e.throughput.successSoFar)}`:"";d.push(_colors2.default.cyan(`Throughput: ${g}/hr (1h: ${i}/hr)${p}`))}return t.length?d.concat(t):d}function nr(e,t=o=>o?_path.basename.call(void 0, o):"-"){return[...e.workerState.entries()].map(([r,n])=>{let l=n.lastLevel==="error"?_colors2.default.red("ERROR "):n.lastLevel==="warn"?_colors2.default.yellow("WARN "):n.busy?_colors2.default.green("WORKING"):_colors2.default.dim("IDLE "),s=t(n.file),a=n.startedAt?`${Math.floor((Date.now()-n.startedAt)/1e3)}s`:"-",f=_nullishCoalesce(_optionalChain([n, 'access', _81 => _81.progress, 'optionalAccess', _82 => _82.processed]), () => (0)),m=_nullishCoalesce(_optionalChain([n, 'access', _83 => _83.progress, 'optionalAccess', _84 => _84.total]), () => (0)),c=m>0?Math.floor(f/m*100):0,d=m>0?yt(c,18):" ".repeat(18),g=m>0?`${f.toLocaleString()}/${m.toLocaleString()} (${c}%)`:_colors2.default.dim("\u2014");return` [w${r}] ${l} | ${s} | ${a} | [${d}] ${g}`})}exports.a = Kt; exports.b = Bt; exports.c = ue; exports.d = or; exports.e = nr; exports.f = Re; exports.g = Oe;
|
|
38
|
-
//# sourceMappingURL=chunk-
|
|
38
|
+
//# sourceMappingURL=chunk-PCK2N4IA.cjs.map
|