@transcend-io/cli 8.38.2 → 9.0.1

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.
Files changed (278) hide show
  1. package/dist/api-keys-CxvKdj2v.mjs +2 -0
  2. package/dist/api-keys-CxvKdj2v.mjs.map +1 -0
  3. package/dist/app-BKMxG7RO.mjs +131 -0
  4. package/dist/app-BKMxG7RO.mjs.map +1 -0
  5. package/dist/bin/bash-complete.mjs +3 -0
  6. package/dist/bin/bash-complete.mjs.map +1 -0
  7. package/dist/bin/cli.mjs +3 -0
  8. package/dist/bin/cli.mjs.map +1 -0
  9. package/dist/bin/deprecated-command.mjs +5 -0
  10. package/dist/bin/deprecated-command.mjs.map +1 -0
  11. package/dist/buildAIIntegrationType-Bk0EbFKV.mjs +2 -0
  12. package/dist/buildAIIntegrationType-Bk0EbFKV.mjs.map +1 -0
  13. package/dist/code-scanning-Cx1kpssH.mjs +4 -0
  14. package/dist/code-scanning-Cx1kpssH.mjs.map +1 -0
  15. package/dist/codecs-TR6p48v3.mjs +2 -0
  16. package/dist/codecs-TR6p48v3.mjs.map +1 -0
  17. package/dist/command-Bzyj3M2G.mjs +9 -0
  18. package/dist/command-Bzyj3M2G.mjs.map +1 -0
  19. package/dist/consent-manager-c4bgQF1N.mjs +12 -0
  20. package/dist/consent-manager-c4bgQF1N.mjs.map +1 -0
  21. package/dist/constants-CnLQtIBn.mjs +2 -0
  22. package/dist/constants-CnLQtIBn.mjs.map +1 -0
  23. package/dist/context-bkKpii_t.mjs +2 -0
  24. package/dist/{context-_8xfl0dt.cjs.map → context-bkKpii_t.mjs.map} +1 -1
  25. package/dist/cron-BvxWyvDu.mjs +2 -0
  26. package/dist/cron-BvxWyvDu.mjs.map +1 -0
  27. package/dist/data-inventory-CkS_kmus.mjs +75 -0
  28. package/dist/data-inventory-CkS_kmus.mjs.map +1 -0
  29. package/dist/dataFlowsToDataSilos-RAhfPV0l.mjs +2 -0
  30. package/dist/dataFlowsToDataSilos-RAhfPV0l.mjs.map +1 -0
  31. package/dist/done-input-validation-CcZtaz03.mjs +2 -0
  32. package/dist/{done-input-validation-DGckEJ5a.cjs.map → done-input-validation-CcZtaz03.mjs.map} +1 -1
  33. package/dist/enums-CyFTrzXY.mjs +2 -0
  34. package/dist/{enums-BZulhPFa.cjs.map → enums-CyFTrzXY.mjs.map} +1 -1
  35. package/dist/impl-8dOatHnF.mjs +2 -0
  36. package/dist/{impl-BN8N7BHo.cjs.map → impl-8dOatHnF.mjs.map} +1 -1
  37. package/dist/impl-Ah-1lwzr.mjs +2 -0
  38. package/dist/impl-Ah-1lwzr.mjs.map +1 -0
  39. package/dist/impl-B5lTeRbn.mjs +2 -0
  40. package/dist/impl-B5lTeRbn.mjs.map +1 -0
  41. package/dist/impl-B6UhzQcY2.mjs +2 -0
  42. package/dist/impl-B6UhzQcY2.mjs.map +1 -0
  43. package/dist/impl-BFf_CotE2.mjs +2 -0
  44. package/dist/impl-BFf_CotE2.mjs.map +1 -0
  45. package/dist/impl-BGQ0EGS0.mjs +2 -0
  46. package/dist/impl-BGQ0EGS0.mjs.map +1 -0
  47. package/dist/impl-BYBNi68b.mjs +5 -0
  48. package/dist/impl-BYBNi68b.mjs.map +1 -0
  49. package/dist/impl-B__p3_wC.mjs +2 -0
  50. package/dist/impl-B__p3_wC.mjs.map +1 -0
  51. package/dist/impl-BcayRe6a.mjs +2 -0
  52. package/dist/{impl-CA7X_TDD.cjs.map → impl-BcayRe6a.mjs.map} +1 -1
  53. package/dist/impl-BkYKsEVG2.mjs +2 -0
  54. package/dist/impl-BkYKsEVG2.mjs.map +1 -0
  55. package/dist/impl-Bl2yVgh0.mjs +4 -0
  56. package/dist/impl-Bl2yVgh0.mjs.map +1 -0
  57. package/dist/impl-BmAMgEEM.mjs +12 -0
  58. package/dist/impl-BmAMgEEM.mjs.map +1 -0
  59. package/dist/impl-BsttzxTN2.mjs +2 -0
  60. package/dist/impl-BsttzxTN2.mjs.map +1 -0
  61. package/dist/impl-BtnySmbi.mjs +2 -0
  62. package/dist/impl-BtnySmbi.mjs.map +1 -0
  63. package/dist/impl-BwX-evfW2.mjs +4 -0
  64. package/dist/impl-BwX-evfW2.mjs.map +1 -0
  65. package/dist/impl-C-wzeAib2.mjs +2 -0
  66. package/dist/impl-C-wzeAib2.mjs.map +1 -0
  67. package/dist/impl-C61PYfk12.mjs +2 -0
  68. package/dist/impl-C61PYfk12.mjs.map +1 -0
  69. package/dist/impl-CAuNpuF2.mjs +2 -0
  70. package/dist/impl-CAuNpuF2.mjs.map +1 -0
  71. package/dist/impl-CSKrBIuV.mjs +2 -0
  72. package/dist/impl-CSKrBIuV.mjs.map +1 -0
  73. package/dist/impl-CZP2l3Ds.mjs +3 -0
  74. package/dist/impl-CZP2l3Ds.mjs.map +1 -0
  75. package/dist/impl-CiJ8hE5W2.mjs +2 -0
  76. package/dist/impl-CiJ8hE5W2.mjs.map +1 -0
  77. package/dist/impl-Cj3H-m2Z.mjs +2 -0
  78. package/dist/impl-Cj3H-m2Z.mjs.map +1 -0
  79. package/dist/impl-CkY0wfCz.mjs +2 -0
  80. package/dist/impl-CkY0wfCz.mjs.map +1 -0
  81. package/dist/impl-Cm8pUfBU2.mjs +2 -0
  82. package/dist/impl-Cm8pUfBU2.mjs.map +1 -0
  83. package/dist/impl-CpzS9LVu2.mjs +2 -0
  84. package/dist/impl-CpzS9LVu2.mjs.map +1 -0
  85. package/dist/impl-CwfamZ1c.mjs +2 -0
  86. package/dist/{impl-BO1fP5DL.cjs.map → impl-CwfamZ1c.mjs.map} +1 -1
  87. package/dist/impl-D81et1Yb2.mjs +2 -0
  88. package/dist/impl-D81et1Yb2.mjs.map +1 -0
  89. package/dist/impl-D92PTNk3.mjs +2 -0
  90. package/dist/impl-D92PTNk3.mjs.map +1 -0
  91. package/dist/impl-DTXDVeo6.mjs +2 -0
  92. package/dist/impl-DTXDVeo6.mjs.map +1 -0
  93. package/dist/impl-DWoysXup.mjs +2 -0
  94. package/dist/impl-DWoysXup.mjs.map +1 -0
  95. package/dist/impl-DX3JHZ4v2.mjs +2 -0
  96. package/dist/impl-DX3JHZ4v2.mjs.map +1 -0
  97. package/dist/impl-DhuUrzxQ.mjs +2 -0
  98. package/dist/impl-DhuUrzxQ.mjs.map +1 -0
  99. package/dist/impl-DqMYLKjU.mjs +2 -0
  100. package/dist/impl-DqMYLKjU.mjs.map +1 -0
  101. package/dist/impl-DqQ6CIj0.mjs +2 -0
  102. package/dist/impl-DqQ6CIj0.mjs.map +1 -0
  103. package/dist/impl-Duaq6iWI2.mjs +2 -0
  104. package/dist/impl-Duaq6iWI2.mjs.map +1 -0
  105. package/dist/impl-O5gz8qcm.mjs +2 -0
  106. package/dist/impl-O5gz8qcm.mjs.map +1 -0
  107. package/dist/impl-PH0AoC7i.mjs +2 -0
  108. package/dist/impl-PH0AoC7i.mjs.map +1 -0
  109. package/dist/impl-S8p6toVb2.mjs +2 -0
  110. package/dist/impl-S8p6toVb2.mjs.map +1 -0
  111. package/dist/impl-X2MSb8Ij.mjs +2 -0
  112. package/dist/impl-X2MSb8Ij.mjs.map +1 -0
  113. package/dist/impl-bo95wZIU2.mjs +2 -0
  114. package/dist/impl-bo95wZIU2.mjs.map +1 -0
  115. package/dist/impl-cfdCesro.mjs +2 -0
  116. package/dist/impl-cfdCesro.mjs.map +1 -0
  117. package/dist/impl-iZoXu4nV.mjs +2 -0
  118. package/dist/{impl-DZMWJNLE.cjs.map → impl-iZoXu4nV.mjs.map} +1 -1
  119. package/dist/impl-lebl6Zek2.mjs +2 -0
  120. package/dist/impl-lebl6Zek2.mjs.map +1 -0
  121. package/dist/impl-p0YN9e2e.mjs +2 -0
  122. package/dist/impl-p0YN9e2e.mjs.map +1 -0
  123. package/dist/{index.d.cts → index.d.mts} +1704 -3463
  124. package/dist/index.mjs +5 -0
  125. package/dist/index.mjs.map +1 -0
  126. package/dist/logger-Bj782ZYD.mjs +2 -0
  127. package/dist/logger-Bj782ZYD.mjs.map +1 -0
  128. package/dist/manual-enrichment-B6lW5kAX.mjs +2 -0
  129. package/dist/manual-enrichment-B6lW5kAX.mjs.map +1 -0
  130. package/dist/mergeTranscendInputs-Coj_e2N3.mjs +2 -0
  131. package/dist/{mergeTranscendInputs-BIBCYbug.cjs.map → mergeTranscendInputs-Coj_e2N3.mjs.map} +1 -1
  132. package/dist/pooling-CazydwlD.mjs +23 -0
  133. package/dist/pooling-CazydwlD.mjs.map +1 -0
  134. package/dist/preference-management-8gj7aSJB.mjs +7 -0
  135. package/dist/preference-management-8gj7aSJB.mjs.map +1 -0
  136. package/dist/readTranscendYaml-DhKG1ViI.mjs +4 -0
  137. package/dist/readTranscendYaml-DhKG1ViI.mjs.map +1 -0
  138. package/dist/syncConfigurationToTranscend-VJd0PnaZ.mjs +3010 -0
  139. package/dist/syncConfigurationToTranscend-VJd0PnaZ.mjs.map +1 -0
  140. package/dist/uploadConsents-C1S-BNzw.mjs +2 -0
  141. package/dist/uploadConsents-C1S-BNzw.mjs.map +1 -0
  142. package/package.json +46 -49
  143. package/dist/api-keys-DMPYZTne.cjs +0 -2
  144. package/dist/api-keys-DMPYZTne.cjs.map +0 -1
  145. package/dist/app-bPlpZQj_.cjs +0 -131
  146. package/dist/app-bPlpZQj_.cjs.map +0 -1
  147. package/dist/bin/bash-complete.cjs +0 -3
  148. package/dist/bin/bash-complete.cjs.map +0 -1
  149. package/dist/bin/cli.cjs +0 -3
  150. package/dist/bin/cli.cjs.map +0 -1
  151. package/dist/bin/deprecated-command.cjs +0 -5
  152. package/dist/bin/deprecated-command.cjs.map +0 -1
  153. package/dist/buildAIIntegrationType-BwuCYR-o.cjs +0 -2
  154. package/dist/buildAIIntegrationType-BwuCYR-o.cjs.map +0 -1
  155. package/dist/chunk-Bmb41Sf3.cjs +0 -1
  156. package/dist/code-scanning-D6YstOWo.cjs +0 -4
  157. package/dist/code-scanning-D6YstOWo.cjs.map +0 -1
  158. package/dist/codecs-Bvmb8o9R.cjs +0 -2
  159. package/dist/codecs-Bvmb8o9R.cjs.map +0 -1
  160. package/dist/command-C39HGpGR.cjs +0 -9
  161. package/dist/command-C39HGpGR.cjs.map +0 -1
  162. package/dist/consent-manager-C3UVAKd_.cjs +0 -12
  163. package/dist/consent-manager-C3UVAKd_.cjs.map +0 -1
  164. package/dist/constants-gJm1eQH0.cjs +0 -2
  165. package/dist/constants-gJm1eQH0.cjs.map +0 -1
  166. package/dist/context-_8xfl0dt.cjs +0 -2
  167. package/dist/cron-NLlyCiml.cjs +0 -2
  168. package/dist/cron-NLlyCiml.cjs.map +0 -1
  169. package/dist/data-inventory-a9Nz9lUO.cjs +0 -75
  170. package/dist/data-inventory-a9Nz9lUO.cjs.map +0 -1
  171. package/dist/dataFlowsToDataSilos-BJh0hzJI.cjs +0 -2
  172. package/dist/dataFlowsToDataSilos-BJh0hzJI.cjs.map +0 -1
  173. package/dist/done-input-validation-DGckEJ5a.cjs +0 -2
  174. package/dist/enums-BZulhPFa.cjs +0 -2
  175. package/dist/impl--RUTvJko.cjs +0 -2
  176. package/dist/impl--RUTvJko.cjs.map +0 -1
  177. package/dist/impl-6vrF2_M3.cjs +0 -2
  178. package/dist/impl-6vrF2_M3.cjs.map +0 -1
  179. package/dist/impl-73q3K0b_.cjs +0 -2
  180. package/dist/impl-73q3K0b_.cjs.map +0 -1
  181. package/dist/impl-BAZ34gSp.cjs +0 -2
  182. package/dist/impl-BAZ34gSp.cjs.map +0 -1
  183. package/dist/impl-BAs-7neS.cjs +0 -12
  184. package/dist/impl-BAs-7neS.cjs.map +0 -1
  185. package/dist/impl-BF44h4oH.cjs +0 -2
  186. package/dist/impl-BF44h4oH.cjs.map +0 -1
  187. package/dist/impl-BKXkRTVx.cjs +0 -2
  188. package/dist/impl-BKXkRTVx.cjs.map +0 -1
  189. package/dist/impl-BN8N7BHo.cjs +0 -2
  190. package/dist/impl-BO1fP5DL.cjs +0 -2
  191. package/dist/impl-BRAiiMt3.cjs +0 -2
  192. package/dist/impl-BRAiiMt3.cjs.map +0 -1
  193. package/dist/impl-BRNha4nQ.cjs +0 -2
  194. package/dist/impl-BRNha4nQ.cjs.map +0 -1
  195. package/dist/impl-Ba1d91O1.cjs +0 -2
  196. package/dist/impl-Ba1d91O1.cjs.map +0 -1
  197. package/dist/impl-Bgp_TuxN.cjs +0 -2
  198. package/dist/impl-Bgp_TuxN.cjs.map +0 -1
  199. package/dist/impl-BreaZGaV.cjs +0 -2
  200. package/dist/impl-BreaZGaV.cjs.map +0 -1
  201. package/dist/impl-BzAwMfNS.cjs +0 -2
  202. package/dist/impl-BzAwMfNS.cjs.map +0 -1
  203. package/dist/impl-C0eKnbO8.cjs +0 -4
  204. package/dist/impl-C0eKnbO8.cjs.map +0 -1
  205. package/dist/impl-C2kTLgRr.cjs +0 -2
  206. package/dist/impl-C2kTLgRr.cjs.map +0 -1
  207. package/dist/impl-CA7X_TDD.cjs +0 -2
  208. package/dist/impl-CC0T0jNd.cjs +0 -2
  209. package/dist/impl-CC0T0jNd.cjs.map +0 -1
  210. package/dist/impl-CJT35FpG.cjs +0 -2
  211. package/dist/impl-CJT35FpG.cjs.map +0 -1
  212. package/dist/impl-CTXPMoXc.cjs +0 -3
  213. package/dist/impl-CTXPMoXc.cjs.map +0 -1
  214. package/dist/impl-CUScCLAS.cjs +0 -2
  215. package/dist/impl-CUScCLAS.cjs.map +0 -1
  216. package/dist/impl-CYmPZogW.cjs +0 -2
  217. package/dist/impl-CYmPZogW.cjs.map +0 -1
  218. package/dist/impl-Ccd0FaOU.cjs +0 -2
  219. package/dist/impl-Ccd0FaOU.cjs.map +0 -1
  220. package/dist/impl-CmKWcYiV.cjs +0 -2
  221. package/dist/impl-CmKWcYiV.cjs.map +0 -1
  222. package/dist/impl-CqshC7my.cjs +0 -2
  223. package/dist/impl-CqshC7my.cjs.map +0 -1
  224. package/dist/impl-Cru4riTc.cjs +0 -5
  225. package/dist/impl-Cru4riTc.cjs.map +0 -1
  226. package/dist/impl-Cypfgm4t.cjs +0 -2
  227. package/dist/impl-Cypfgm4t.cjs.map +0 -1
  228. package/dist/impl-D2SWeIGe.cjs +0 -2
  229. package/dist/impl-D2SWeIGe.cjs.map +0 -1
  230. package/dist/impl-DLwIQVA6.cjs +0 -2
  231. package/dist/impl-DLwIQVA6.cjs.map +0 -1
  232. package/dist/impl-DMm4lt-A.cjs +0 -2
  233. package/dist/impl-DMm4lt-A.cjs.map +0 -1
  234. package/dist/impl-DRsuGuRx.cjs +0 -2
  235. package/dist/impl-DRsuGuRx.cjs.map +0 -1
  236. package/dist/impl-DSrvfkVp.cjs +0 -2
  237. package/dist/impl-DSrvfkVp.cjs.map +0 -1
  238. package/dist/impl-DZMWJNLE.cjs +0 -2
  239. package/dist/impl-DbqAvW7X.cjs +0 -2
  240. package/dist/impl-DbqAvW7X.cjs.map +0 -1
  241. package/dist/impl-Dl78xJu6.cjs +0 -2
  242. package/dist/impl-Dl78xJu6.cjs.map +0 -1
  243. package/dist/impl-Dvpc-Qa5.cjs +0 -2
  244. package/dist/impl-Dvpc-Qa5.cjs.map +0 -1
  245. package/dist/impl-DySeNL1m.cjs +0 -2
  246. package/dist/impl-DySeNL1m.cjs.map +0 -1
  247. package/dist/impl-Fj-Esff-.cjs +0 -2
  248. package/dist/impl-Fj-Esff-.cjs.map +0 -1
  249. package/dist/impl-W6tVmm8N.cjs +0 -2
  250. package/dist/impl-W6tVmm8N.cjs.map +0 -1
  251. package/dist/impl-WphnR0cX.cjs +0 -2
  252. package/dist/impl-WphnR0cX.cjs.map +0 -1
  253. package/dist/impl-YNAicr-z.cjs +0 -2
  254. package/dist/impl-YNAicr-z.cjs.map +0 -1
  255. package/dist/impl-jEpWgC2N.cjs +0 -2
  256. package/dist/impl-jEpWgC2N.cjs.map +0 -1
  257. package/dist/impl-x2P-_Pk2.cjs +0 -4
  258. package/dist/impl-x2P-_Pk2.cjs.map +0 -1
  259. package/dist/index.cjs +0 -5
  260. package/dist/index.cjs.map +0 -1
  261. package/dist/logger-DQwEYtSS.cjs +0 -2
  262. package/dist/logger-DQwEYtSS.cjs.map +0 -1
  263. package/dist/manual-enrichment-DTVJo7hP.cjs +0 -2
  264. package/dist/manual-enrichment-DTVJo7hP.cjs.map +0 -1
  265. package/dist/mergeTranscendInputs-BIBCYbug.cjs +0 -2
  266. package/dist/pooling-C-TYBnHI.cjs +0 -23
  267. package/dist/pooling-C-TYBnHI.cjs.map +0 -1
  268. package/dist/preference-management-Ch77Yxod.cjs +0 -7
  269. package/dist/preference-management-Ch77Yxod.cjs.map +0 -1
  270. package/dist/readTranscendYaml-Cycz6RxW.cjs +0 -4
  271. package/dist/readTranscendYaml-Cycz6RxW.cjs.map +0 -1
  272. package/dist/syncConfigurationToTranscend-s-cjtUI3.cjs +0 -3010
  273. package/dist/syncConfigurationToTranscend-s-cjtUI3.cjs.map +0 -1
  274. package/dist/uploadConsents-CDkk_sWY.cjs +0 -2
  275. package/dist/uploadConsents-CDkk_sWY.cjs.map +0 -1
  276. /package/dist/bin/{bash-complete.d.cts → bash-complete.d.mts} +0 -0
  277. /package/dist/bin/{cli.d.cts → cli.d.mts} +0 -0
  278. /package/dist/bin/{deprecated-command.d.cts → deprecated-command.d.mts} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"impl-x2P-_Pk2.cjs","names":["OneTrustPullResource","OneTrustGetListOfAssessmentsResponse","OneTrustGetAssessmentResponse","OneTrustGetRiskResponse","OneTrustGetUserResponse","keyBy","makeGraphQLRequest","IMPORT_ONE_TRUST_ASSESSMENT_FORMS","mapSeries","map","uniq","OneTrustEnrichedAssessment","OneTrustFileFormat","OneTrustPullSource","buildTranscendGraphQLClient","OneTrustPullResource"],"sources":["../src/lib/oneTrust/createOneTrustGotInstance.ts","../src/lib/oneTrust/helpers/parseCliSyncOtArguments.ts","../src/lib/oneTrust/helpers/oneTrustAssessmentToJson.ts","../src/lib/oneTrust/helpers/syncOneTrustAssessmentToDisk.ts","../src/lib/oneTrust/endpoints/getListOfOneTrustAssessments.ts","../src/lib/oneTrust/endpoints/getOneTrustAssessment.ts","../src/lib/oneTrust/endpoints/getOneTrustRisk.ts","../src/lib/oneTrust/endpoints/getOneTrustUser.ts","../src/lib/oneTrust/helpers/enrichOneTrustAssessment.ts","../src/lib/oneTrust/helpers/syncOneTrustAssessmentToTranscend.ts","../src/lib/oneTrust/helpers/syncOneTrustAssessmentsFromOneTrust.ts","../src/lib/oneTrust/helpers/syncOneTrustAssessmentsFromFile.ts","../src/commands/migration/sync-ot/impl.ts"],"sourcesContent":["import got, { Got } from 'got';\n\n/**\n * Instantiate an instance of got that is capable of making requests to OneTrust\n *\n * @param param - information about the OneTrust URL\n * @returns The instance of got that is capable of making requests to the customer ingress\n */\nexport const createOneTrustGotInstance = ({\n hostname,\n auth,\n}: {\n /** Hostname of the OneTrust API */\n hostname: string;\n /** The OAuth access token */\n auth: string;\n}): Got =>\n got.extend({\n prefixUrl: `https://${hostname}`,\n headers: {\n accept: 'application/json',\n 'content-type': 'application/json',\n authorization: `Bearer ${auth}`,\n },\n });\n","import { logger } from '../../../logger';\nimport colors from 'colors';\nimport yargs from 'yargs-parser';\nimport {\n OneTrustFileFormat,\n OneTrustPullResource,\n OneTrustPullSource,\n} from '../../../enums';\n\nconst VALID_RESOURCES = Object.values(OneTrustPullResource);\n\ninterface OneTrustCliArguments {\n /** The name of the file to write the resources to */\n file: string;\n /** The OneTrust hostname to send the requests to */\n hostname?: string;\n /** The OAuth Bearer token used to authenticate the requests to OneTrust */\n oneTrustAuth?: string;\n /** The Transcend API key to authenticate the requests to Transcend */\n transcendAuth: string;\n /** The Transcend URL where to forward requests */\n transcendUrl: string;\n /** The resource to pull from OneTrust */\n resource: OneTrustPullResource;\n /** Whether to enable debugging while reporting errors */\n debug: boolean;\n /** Whether to export the resource into a file rather than push to transcend */\n dryRun: boolean;\n /** Where to read the OneTrust resource from */\n source: OneTrustPullSource;\n}\n\n/**\n * Parse the command line arguments\n *\n * @returns the parsed arguments\n */\nexport const parseCliSyncOtArguments = (): OneTrustCliArguments => {\n const {\n file,\n hostname,\n oneTrustAuth,\n resource,\n debug,\n dryRun,\n transcendAuth,\n transcendUrl,\n source,\n } = yargs(process.argv.slice(2), {\n string: [\n 'file',\n 'hostname',\n 'oneTrustAuth',\n 'resource',\n 'dryRun',\n 'transcendAuth',\n 'transcendUrl',\n 'source',\n ],\n boolean: ['debug', 'dryRun'],\n default: {\n resource: OneTrustPullResource.Assessments,\n debug: false,\n dryRun: false,\n transcendUrl: 'https://api.transcend.io',\n source: OneTrustPullSource.OneTrust,\n },\n });\n\n // Must be able to authenticate to transcend to sync resources to it\n if (!dryRun && !transcendAuth) {\n logger.error(\n colors.red(\n // eslint-disable-next-line no-template-curly-in-string\n 'Must specify a \"transcendAuth\" parameter to sync resources to Transcend. e.g. --transcendAuth=${TRANSCEND_API_KEY}',\n ),\n );\n return process.exit(1);\n }\n if (!dryRun && !transcendUrl) {\n logger.error(\n colors.red(\n // eslint-disable-next-line max-len\n 'Must specify a \"transcendUrl\" parameter to sync resources to Transcend. e.g. --transcendUrl=https://api.transcend.io',\n ),\n );\n return process.exit(1);\n }\n\n // If trying to sync to disk, must specify a file path\n if (dryRun && !file) {\n logger.error(\n colors.red(\n 'Must set a \"file\" parameter when \"dryRun\" is \"true\". e.g. --file=./oneTrustAssessments.json',\n ),\n );\n return process.exit(1);\n }\n\n if (file) {\n const splitFile = file.split('.');\n if (splitFile.length < 2) {\n logger.error(\n colors.red(\n 'The \"file\" parameter has an invalid format. Expected a path with extensions. e.g. --file=./pathToFile.json.',\n ),\n );\n return process.exit(1);\n }\n if (splitFile.at(-1) !== OneTrustFileFormat.Json) {\n logger.error(\n colors.red(\n `Expected the format of the \"file\" parameters '${file}' to be '${\n OneTrustFileFormat.Json\n }', but got '${splitFile.at(-1)}'.`,\n ),\n );\n return process.exit(1);\n }\n }\n\n // if reading assessments from a OneTrust\n if (source === OneTrustPullSource.OneTrust) {\n // must specify the OneTrust hostname\n if (!hostname) {\n logger.error(\n colors.red(\n 'Missing required parameter \"hostname\". e.g. --hostname=customer.my.onetrust.com',\n ),\n );\n return process.exit(1);\n }\n // must specify the OneTrust auth\n if (!oneTrustAuth) {\n logger.error(\n colors.red(\n 'Missing required parameter \"oneTrustAuth\". e.g. --oneTrustAuth=$ONE_TRUST_AUTH_TOKEN',\n ),\n );\n return process.exit(1);\n }\n } else {\n // if reading the assessments from a file, must specify a file to read from\n if (!file) {\n logger.error(\n colors.red(\n 'Must specify a \"file\" parameter to read the OneTrust assessments from. e.g. --source=./oneTrustAssessments.json',\n ),\n );\n return process.exit(1);\n }\n\n // Cannot try reading from file and save assessments to a file simultaneously\n if (dryRun) {\n logger.error(\n colors.red(\n 'Cannot read and write to a file simultaneously.' +\n ` Emit the \"source\" parameter or set it to ${OneTrustPullSource.OneTrust} if \"dryRun\" is enabled.`,\n ),\n );\n return process.exit(1);\n }\n }\n\n if (!VALID_RESOURCES.includes(resource)) {\n logger.error(\n colors.red(\n `Received invalid resource value: \"${resource}\". Allowed: ${VALID_RESOURCES.join(\n ',',\n )}`,\n ),\n );\n return process.exit(1);\n }\n\n return {\n file,\n ...(hostname && { hostname }),\n ...(oneTrustAuth && { oneTrustAuth }),\n resource,\n debug,\n dryRun,\n transcendAuth,\n transcendUrl,\n source,\n };\n};\n","import { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';\n\n/**\n * Converts the assessment into a json entry.\n *\n * @param param - information about the assessment and amount of entries\n * @returns a stringified json entry ready to be appended to a file\n */\nexport const oneTrustAssessmentToJson = ({\n assessment,\n index,\n total,\n wrap = true,\n}: {\n /** The assessment to convert */\n assessment: OneTrustEnrichedAssessment;\n /** The position of the assessment in the final Json object */\n index: number;\n /** The total amount of the assessments in the final Json object */\n total?: number;\n /** Whether to wrap every entry in brackets */\n wrap?: boolean;\n}): string => {\n let jsonEntry = '';\n // start with an opening bracket\n if (index === 0 || wrap) {\n jsonEntry = '[\\n';\n }\n\n const stringifiedAssessment = JSON.stringify(assessment);\n\n // Add comma for all items except the last one\n const comma = total && index < total - 1 && !wrap ? ',' : '';\n\n // write to file\n jsonEntry = `${jsonEntry + stringifiedAssessment + comma}\\n`;\n\n // end with closing bracket\n if ((total && index === total - 1) || wrap) {\n jsonEntry += '\\n]';\n }\n\n return jsonEntry;\n};\n","import { logger } from '../../../logger';\nimport colors from 'colors';\nimport fs from 'node:fs';\nimport { oneTrustAssessmentToJson } from './oneTrustAssessmentToJson';\nimport { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';\n\n/**\n * Write the assessment to disk at the specified file path.\n *\n *\n * @param param - information about the assessment to write\n */\nexport const syncOneTrustAssessmentToDisk = ({\n file,\n assessment,\n index,\n total,\n}: {\n /** The file path to write the assessment to */\n file: string;\n /** The basic assessment */\n assessment: OneTrustEnrichedAssessment;\n /** The index of the assessment being written to the file */\n index: number;\n /** The total amount of assessments that we will write */\n total: number;\n}): void => {\n logger.info(\n colors.magenta(\n `Writing enriched assessment ${\n index + 1\n } of ${total} to file \"${file}\"...`,\n ),\n );\n\n if (index === 0) {\n fs.writeFileSync(\n file,\n oneTrustAssessmentToJson({\n assessment,\n index,\n total,\n wrap: false,\n }),\n );\n } else {\n fs.appendFileSync(\n file,\n oneTrustAssessmentToJson({\n assessment,\n index,\n total,\n wrap: false,\n }),\n );\n }\n};\n","import { Got } from 'got';\nimport { logger } from '../../../logger';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport {\n OneTrustAssessment,\n OneTrustGetListOfAssessmentsResponse,\n} from '@transcend-io/privacy-types';\n\n/**\n * Fetch a list of all assessments from the OneTrust client.\n * ref: https://developer.onetrust.com/onetrust/reference/getallassessmentbasicdetailsusingget\n *\n * @param param - the information about the OneTrust client\n * @returns a list of OneTrustAssessment\n */\nexport const getListOfOneTrustAssessments = async ({\n oneTrust,\n}: {\n /** The OneTrust client instance */\n oneTrust: Got;\n}): Promise<OneTrustAssessment[]> => {\n let currentPage = 0;\n let totalPages = 1;\n let totalElements = 0;\n\n const allAssessments: OneTrustAssessment[] = [];\n\n while (currentPage < totalPages) {\n const { body } = await oneTrust.get(\n `api/assessment/v2/assessments?page=${currentPage}&size=2000`,\n );\n\n const { page, content } = decodeCodec(\n OneTrustGetListOfAssessmentsResponse,\n body,\n );\n allAssessments.push(...(content ?? []));\n if (currentPage === 0) {\n totalPages = page?.totalPages ?? 0;\n totalElements = page?.totalElements ?? 0;\n }\n currentPage += 1;\n\n // log progress\n logger.info(\n `Fetched ${allAssessments.length} of ${totalElements} assessments.`,\n );\n }\n\n return allAssessments;\n};\n","import { Got } from 'got';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport { OneTrustGetAssessmentResponse } from '@transcend-io/privacy-types';\n\n/**\n * Retrieve details about a particular assessment.\n * ref: https://developer.onetrust.com/onetrust/reference/exportassessmentusingget\n *\n * @param param - the information about the OneTrust client and assessment to retrieve\n * @returns details about the assessment\n */\nexport const getOneTrustAssessment = async ({\n oneTrust,\n assessmentId,\n}: {\n /** The OneTrust client instance */\n oneTrust: Got;\n /** The ID of the assessment to retrieve */\n assessmentId: string;\n}): Promise<OneTrustGetAssessmentResponse> => {\n const { body } = await oneTrust.get(\n `api/assessment/v2/assessments/${assessmentId}/export?ExcludeSkippedQuestions=false`,\n );\n\n return decodeCodec(OneTrustGetAssessmentResponse, body);\n};\n","import { Got } from 'got';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport { OneTrustGetRiskResponse } from '@transcend-io/privacy-types';\n\n/**\n * Retrieve details about a particular risk.\n * ref: https://developer.onetrust.com/onetrust/reference/getriskusingget\n *\n * @param param - the information about the OneTrust client and risk to retrieve\n * @returns the OneTrust risk\n */\nexport const getOneTrustRisk = async ({\n oneTrust,\n riskId,\n}: {\n /** The OneTrust client instance */\n oneTrust: Got;\n /** The ID of the OneTrust risk to retrieve */\n riskId: string;\n}): Promise<OneTrustGetRiskResponse> => {\n const { body } = await oneTrust.get(`api/risk/v2/risks/${riskId}`);\n\n return decodeCodec(OneTrustGetRiskResponse, body);\n};\n","import { Got } from 'got';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport { OneTrustGetUserResponse } from '@transcend-io/privacy-types';\n\n/**\n * Retrieve details about a particular user.\n * ref: https://developer.onetrust.com/onetrust/reference/getriskusingget\n *\n * @param param - the information about the OneTrust client and risk to retrieve\n * @returns the OneTrust risk\n */\nexport const getOneTrustUser = async ({\n oneTrust,\n userId,\n}: {\n /** The OneTrust client instance */\n oneTrust: Got;\n /** The ID of the OneTrust user to retrieve */\n userId: string;\n}): Promise<OneTrustGetUserResponse> => {\n const { body } = await oneTrust.get(`api/scim/v2/Users/${userId}`);\n\n return decodeCodec(OneTrustGetUserResponse, body);\n};\n","import {\n OneTrustAssessment,\n OneTrustEnrichedAssessment,\n OneTrustGetAssessmentResponse,\n OneTrustGetRiskResponse,\n OneTrustGetUserResponse,\n} from '@transcend-io/privacy-types';\nimport { keyBy } from 'lodash-es';\n\n/**\n * Merge the assessment, assessmentDetails, and riskDetails into one object.\n *\n * @param param - the assessment and risk information\n * @returns the assessment enriched with details and risk information\n */\nexport const enrichOneTrustAssessment = ({\n assessment,\n assessmentDetails,\n riskDetails,\n creatorDetails,\n approversDetails,\n respondentsDetails,\n}: {\n /** The OneTrust risk details */\n riskDetails: OneTrustGetRiskResponse[];\n /** The OneTrust assessment as returned from Get List of Assessments endpoint */\n assessment: OneTrustAssessment;\n /** The OneTrust assessment details */\n assessmentDetails: OneTrustGetAssessmentResponse;\n /** The OneTrust assessment creator details */\n creatorDetails: OneTrustGetUserResponse;\n /** The OneTrust assessment approvers details */\n approversDetails: OneTrustGetUserResponse[];\n /** The OneTrust assessment internal respondents details */\n respondentsDetails: OneTrustGetUserResponse[];\n}): OneTrustEnrichedAssessment => {\n const riskDetailsById = keyBy(riskDetails, 'id');\n const { sections, createdBy, ...restAssessmentDetails } = assessmentDetails;\n const sectionsWithEnrichedRisk = sections.map((section) => {\n const { questions, ...restSection } = section;\n const enrichedQuestions = questions.map((question) => {\n const { risks, ...restQuestion } = question;\n const enrichedRisks = (risks ?? []).map((risk) => {\n const details = riskDetailsById[risk.riskId];\n return {\n ...risk,\n ...details,\n level: risk.level,\n impactLevel: risk.impactLevel ?? 0,\n };\n });\n return {\n ...restQuestion,\n risks: enrichedRisks,\n };\n });\n return {\n ...restSection,\n questions: enrichedQuestions,\n };\n });\n\n // grab creator details\n const enrichedCreatedBy = {\n ...createdBy,\n active: creatorDetails?.active ?? false,\n userType: creatorDetails?.userType ?? 'Internal',\n emails: creatorDetails?.emails ?? [],\n title: creatorDetails?.title ?? null,\n givenName: creatorDetails?.name.givenName ?? null,\n familyName: creatorDetails?.name.familyName ?? null,\n };\n\n // grab approvers details\n const approverDetailsById = keyBy(approversDetails, 'id');\n const enrichedApprovers = assessmentDetails.approvers.flatMap(\n (originalApprover) =>\n approverDetailsById[originalApprover.id]\n ? [\n {\n ...originalApprover,\n approver: {\n ...originalApprover.approver,\n active: approverDetailsById[originalApprover.id].active,\n userType: approverDetailsById[originalApprover.id].userType,\n emails: approverDetailsById[originalApprover.id].emails,\n title: approverDetailsById[originalApprover.id].title,\n givenName:\n approverDetailsById[originalApprover.id].name.givenName ??\n null,\n familyName:\n approverDetailsById[originalApprover.id].name.familyName ??\n null,\n },\n },\n ]\n : [],\n );\n\n // grab respondents details\n const respondentsDetailsById = keyBy(respondentsDetails, 'id');\n const enrichedRespondents = assessmentDetails.respondents\n .filter((r) => !r.name.includes('@')) // search only internal respondents\n .flatMap((respondent) =>\n respondentsDetailsById[respondent.id]\n ? [\n {\n ...respondent,\n active: respondentsDetailsById[respondent.id].active,\n userType: respondentsDetailsById[respondent.id].userType,\n emails: respondentsDetailsById[respondent.id].emails,\n title: respondentsDetailsById[respondent.id].title,\n givenName:\n respondentsDetailsById[respondent.id].name.givenName ?? null,\n familyName:\n respondentsDetailsById[respondent.id].name.familyName ?? null,\n },\n ]\n : [],\n );\n\n // combine everything into a single enriched assessment\n return {\n ...assessment,\n ...restAssessmentDetails,\n approvers: enrichedApprovers,\n respondents: enrichedRespondents,\n createdBy: enrichedCreatedBy,\n sections: sectionsWithEnrichedRisk,\n };\n};\n","import { logger } from '../../../logger';\nimport colors from 'colors';\nimport { GraphQLClient } from 'graphql-request';\nimport {\n IMPORT_ONE_TRUST_ASSESSMENT_FORMS,\n makeGraphQLRequest,\n} from '../../graphql';\nimport { ImportOnetrustAssessmentsInput } from '../../../codecs';\nimport { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';\nimport { oneTrustAssessmentToJson } from './oneTrustAssessmentToJson';\n\nexport interface AssessmentForm {\n /** ID of Assessment Form */\n id: string;\n /** Title of Assessment Form */\n name: string;\n}\n\n/**\n * Write the assessment to a Transcend instance.\n *\n *\n * @param param - information about the assessment and Transcend instance to write to\n */\nexport const syncOneTrustAssessmentToTranscend = async ({\n transcend,\n assessment,\n total,\n index,\n}: {\n /** the Transcend client instance */\n transcend: GraphQLClient;\n /** the assessment to sync to Transcend */\n assessment: OneTrustEnrichedAssessment;\n /** The index of the assessment being written to the file */\n index: number;\n /** The total amount of assessments that we will write */\n total?: number;\n}): Promise<void> => {\n logger.info(\n colors.magenta(\n `Writing enriched assessment ${index + 1} ${\n total ? `of ${total} ` : ' '\n }to Transcend...`,\n ),\n );\n\n // convert the OneTrust assessment object into a json record\n const json = oneTrustAssessmentToJson({\n assessment,\n index,\n total,\n });\n\n // transform the json record into a valid input to the mutation\n const input: ImportOnetrustAssessmentsInput = {\n json,\n };\n\n try {\n await makeGraphQLRequest<{\n /** the importOneTrustAssessmentForms mutation */\n importOneTrustAssessmentForms: {\n /** Created Assessment Forms */\n assessmentForms: AssessmentForm[];\n };\n }>(transcend, IMPORT_ONE_TRUST_ASSESSMENT_FORMS, {\n input,\n });\n } catch (e) {\n logger.error(\n colors.red(\n `Failed to sync assessment ${index + 1} ${\n total ? `of ${total} ` : ' '\n }to Transcend.\\n` +\n `\\tAssessment Title: ${assessment.name}. Template Title: ${assessment.template.name}\\n`,\n ),\n );\n }\n};\n","import type { Got } from 'got';\nimport colors from 'colors';\nimport {\n getListOfOneTrustAssessments,\n getOneTrustAssessment,\n getOneTrustRisk,\n getOneTrustUser,\n} from '../endpoints';\nimport { mapSeries, map } from '../../bluebird';\nimport { logger } from '../../../logger';\nimport {\n OneTrustAssessmentQuestion,\n OneTrustAssessmentSection,\n OneTrustEnrichedAssessment,\n OneTrustGetRiskResponse,\n OneTrustGetUserResponse,\n} from '@transcend-io/privacy-types';\nimport { uniq } from 'lodash-es';\nimport { enrichOneTrustAssessment } from './enrichOneTrustAssessment';\nimport { syncOneTrustAssessmentToDisk } from './syncOneTrustAssessmentToDisk';\nimport { GraphQLClient } from 'graphql-request';\nimport { syncOneTrustAssessmentToTranscend } from './syncOneTrustAssessmentToTranscend';\n\nexport interface AssessmentForm {\n /** ID of Assessment Form */\n id: string;\n /** Title of Assessment Form */\n name: string;\n}\n\n/**\n * Reads all the assessments from a OneTrust instance and syncs them to Transcend or to Disk.\n *\n * @param param - the information about the assessment, its OneTrust source, and destination (disk or Transcend)\n */\nexport const syncOneTrustAssessmentsFromOneTrust = async ({\n oneTrust,\n file,\n dryRun,\n transcend,\n}: {\n /** the OneTrust client instance */\n oneTrust: Got;\n /** the Transcend client instance */\n transcend?: GraphQLClient;\n /** Whether to write to file instead of syncing to Transcend */\n dryRun: boolean;\n /** the path to the file in case dryRun is true */\n file?: string;\n}): Promise<void> => {\n // fetch the list of all assessments in the OneTrust organization\n logger.info('Getting list of all assessments from OneTrust...');\n const assessments = await getListOfOneTrustAssessments({ oneTrust });\n\n // a cache of OneTrust users so we avoid requesting already fetched users\n const oneTrustCachedUsers: Record<string, OneTrustGetUserResponse> = {};\n\n // split all assessments in batches, so we can process some of steps in parallel\n const BATCH_SIZE = 5;\n const assessmentBatches = Array.from(\n {\n length: Math.ceil(assessments.length / BATCH_SIZE),\n },\n (_, i) => assessments.slice(i * BATCH_SIZE, (i + 1) * BATCH_SIZE),\n );\n\n // process each batch and sync the batch right away so it's garbage collected and we don't run out of memory\n await mapSeries(assessmentBatches, async (assessmentBatch, batch) => {\n const batchEnrichedAssessments: OneTrustEnrichedAssessment[] = [];\n\n // fetch assessment details from OneTrust in parallel\n await map(\n assessmentBatch,\n async (assessment, index) => {\n const assessmentNumber = BATCH_SIZE * batch + index + 1;\n logger.info(\n `[assessment ${assessmentNumber} of ${assessments.length}]: fetching details...`,\n );\n const { templateName, assessmentId } = assessment;\n const assessmentDetails = await getOneTrustAssessment({\n oneTrust,\n assessmentId,\n });\n // fetch assessment's creator information\n const creatorId = assessmentDetails.createdBy.id;\n let creator = oneTrustCachedUsers[creatorId];\n if (!creator) {\n logger.info(\n `[assessment ${assessmentNumber} of ${assessments.length}]: fetching creator...`,\n );\n try {\n creator = await getOneTrustUser({\n oneTrust,\n userId: creatorId,\n });\n oneTrustCachedUsers[creatorId] = creator;\n } catch (e) {\n logger.warn(\n colors.yellow(\n `[assessment ${assessmentNumber} of ${assessments.length}]: failed to fetch form creator.` +\n `\\tcreatorId: ${creatorId}. Assessment Title: ${assessment.name}. Template Title: ${templateName}`,\n ),\n );\n }\n }\n\n // fetch assessment approvers information\n const { approvers } = assessmentDetails;\n let approversDetails: OneTrustGetUserResponse[][] = [];\n if (approvers.length > 0) {\n logger.info(\n `[assessment ${assessmentNumber} of ${assessments.length}]: fetching approvers...`,\n );\n approversDetails = await map(\n approvers.map(({ id }) => id),\n async (userId) => {\n try {\n let approver = oneTrustCachedUsers[userId];\n if (!approver) {\n approver = await getOneTrustUser({ oneTrust, userId });\n oneTrustCachedUsers[userId] = approver;\n }\n return [approver];\n } catch (e) {\n logger.warn(\n colors.yellow(\n `[assessment ${assessmentNumber} of ${assessments.length}]: failed to fetch a form approver.` +\n `\\tapproverId: ${userId}. Assessment Title: ${assessment.name}. Template Title: ${templateName}`,\n ),\n );\n return [];\n }\n },\n { concurrency: 5 },\n );\n }\n\n // fetch assessment internal respondents information\n const { respondents } = assessmentDetails;\n // if a user is an internal respondents, their 'name' field can't be an email.\n const internalRespondents = respondents.filter(\n (r) => !r.name.includes('@'),\n );\n let respondentsDetails: OneTrustGetUserResponse[][] = [];\n if (internalRespondents.length > 0) {\n logger.info(\n `[assessment ${assessmentNumber} of ${assessments.length}]: fetching respondents...`,\n );\n respondentsDetails = await map(\n internalRespondents.map(({ id }) => id),\n async (userId) => {\n try {\n let respondent = oneTrustCachedUsers[userId];\n if (!respondent) {\n respondent = await getOneTrustUser({ oneTrust, userId });\n oneTrustCachedUsers[userId] = respondent;\n }\n return [respondent];\n } catch (e) {\n logger.warn(\n colors.yellow(\n `[assessment ${assessmentNumber} of ${assessments.length}]: failed to fetch a respondent.` +\n `\\trespondentId: ${userId}. Assessment Title: ${assessment.name}. Template Title: ${templateName}`,\n ),\n );\n return [];\n }\n },\n { concurrency: 5 },\n );\n }\n\n // fetch assessment risk information\n let riskDetails: OneTrustGetRiskResponse[] = [];\n const riskIds = uniq(\n assessmentDetails.sections.flatMap((s: OneTrustAssessmentSection) =>\n s.questions.flatMap((q: OneTrustAssessmentQuestion) =>\n (q.risks ?? []).flatMap((r) => r.riskId),\n ),\n ),\n );\n if (riskIds.length > 0) {\n logger.info(\n `[assessment ${assessmentNumber} of ${assessments.length}]: fetching risks...`,\n );\n riskDetails = await map(\n riskIds,\n (riskId) => getOneTrustRisk({ oneTrust, riskId: riskId as string }),\n {\n concurrency: 5,\n },\n );\n }\n\n // enrich the assessments with user and risk details\n const enrichedAssessment = enrichOneTrustAssessment({\n assessment,\n assessmentDetails,\n riskDetails,\n creatorDetails: creator,\n approversDetails: approversDetails.flat(),\n respondentsDetails: respondentsDetails.flat(),\n });\n\n batchEnrichedAssessments.push(enrichedAssessment);\n },\n { concurrency: BATCH_SIZE },\n );\n\n // sync assessments in series to avoid concurrency bugs\n await mapSeries(\n batchEnrichedAssessments,\n async (enrichedAssessment, index) => {\n // the assessment's global index takes its batch into consideration\n const globalIndex = batch * BATCH_SIZE + index;\n\n if (dryRun && file) {\n // sync to file\n syncOneTrustAssessmentToDisk({\n assessment: enrichedAssessment,\n index: globalIndex,\n total: assessments.length,\n file,\n });\n } else if (transcend) {\n // sync to transcend\n await syncOneTrustAssessmentToTranscend({\n assessment: enrichedAssessment,\n transcend,\n total: assessments.length,\n index: globalIndex,\n });\n }\n },\n );\n });\n};\n","import { decodeCodec } from '@transcend-io/type-utils';\nimport colors from 'colors';\nimport { logger } from '../../../logger';\nimport JSONStream from 'JSONStream';\n\nimport { createReadStream } from 'node:fs';\nimport { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';\nimport { syncOneTrustAssessmentToTranscend } from './syncOneTrustAssessmentToTranscend';\nimport { GraphQLClient } from 'graphql-request';\n\n/**\n * Reads assessments from a file and syncs them to Transcend.\n *\n * @param param - the information about the source file and Transcend instance to write them to.\n */\nexport const syncOneTrustAssessmentsFromFile = ({\n transcend,\n file,\n}: {\n /** the Transcend client instance */\n transcend: GraphQLClient;\n /** The name of the file from which to read the OneTrust assessments */\n file: string;\n}): Promise<void> => {\n logger.info(`Getting list of all assessments from file ${file}...`);\n\n return new Promise((resolve, reject) => {\n // Create a readable stream from the file\n const fileStream = createReadStream(file, {\n encoding: 'utf-8',\n highWaterMark: 64 * 1024, // 64KB chunks\n });\n\n // Create a JSONStream parser to parse the array of OneTrust assessments from the file\n const parser = JSONStream.parse('*'); // '*' matches each element in the root array\n\n let index = 0;\n\n // Pipe the file stream into the JSON parser\n fileStream.pipe(parser);\n\n // Handle each parsed assessment object\n parser.on('data', async (assessment) => {\n try {\n // Pause the stream while processing to avoid overwhelming memory\n parser.pause();\n\n // Decode and validate the assessment\n const parsedAssessment = decodeCodec(\n OneTrustEnrichedAssessment,\n assessment,\n );\n\n // Sync the assessment to transcend\n await syncOneTrustAssessmentToTranscend({\n assessment: parsedAssessment,\n transcend,\n index,\n });\n\n index += 1;\n\n // Resume the stream after processing\n parser.resume();\n } catch (e) {\n // if failed to parse a line, report error and continue\n logger.error(\n colors.red(\n `Failed to parse the assessment ${index} from file '${file}': ${e.message}.`,\n ),\n );\n }\n });\n\n // Handle completion\n parser.on('end', () => {\n logger.info(`Finished processing ${index} assessments from file ${file}`);\n resolve();\n });\n\n // Handle stream or parsing errors\n parser.on('error', (error) => {\n logger.error(\n colors.red(`Error parsing file '${file}': ${error.message}`),\n );\n reject(error);\n });\n\n fileStream.on('error', (error) => {\n logger.error(\n colors.red(`Error reading file '${file}': ${error.message}`),\n );\n reject(error);\n });\n });\n};\n","import type { LocalContext } from '../../../context';\nimport { logger } from '../../../logger';\nimport colors from 'colors';\nimport { createOneTrustGotInstance } from '../../../lib/oneTrust';\nimport {\n OneTrustFileFormat,\n OneTrustPullResource,\n OneTrustPullSource,\n} from '../../../enums';\nimport { buildTranscendGraphQLClient } from '../../../lib/graphql';\nimport {\n syncOneTrustAssessmentsFromFile,\n syncOneTrustAssessmentsFromOneTrust,\n} from '../../../lib/oneTrust/helpers';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation';\n\n// Command flag interface\nexport interface SyncOtCommandFlags {\n hostname?: string;\n oneTrustAuth?: string;\n source: OneTrustPullSource;\n transcendAuth?: string;\n transcendUrl: string;\n file?: string;\n resource: OneTrustPullResource;\n dryRun: boolean;\n debug: boolean;\n}\n\n// Command implementation\nexport async function syncOt(\n this: LocalContext,\n {\n hostname,\n oneTrustAuth,\n source,\n transcendAuth,\n transcendUrl,\n resource,\n file,\n dryRun,\n debug,\n }: SyncOtCommandFlags,\n): Promise<void> {\n // Must be able to authenticate to transcend to sync resources to it\n if (!dryRun && !transcendAuth) {\n throw new Error(\n // eslint-disable-next-line no-template-curly-in-string\n 'Must specify a \"transcendAuth\" parameter to sync resources to Transcend. e.g. --transcendAuth=${TRANSCEND_API_KEY}',\n );\n }\n\n // If trying to sync to disk, must specify a file path\n if (dryRun && !file) {\n throw new Error(\n 'Must set a \"file\" parameter when \"dryRun\" is \"true\". e.g. --file=./oneTrustAssessments.json',\n );\n }\n\n if (file) {\n const splitFile = file.split('.');\n if (splitFile.length < 2) {\n throw new Error(\n 'The \"file\" parameter has an invalid format. Expected a path with extensions. e.g. --file=./pathToFile.json.',\n );\n }\n if (splitFile.at(-1) !== OneTrustFileFormat.Json) {\n throw new Error(\n `Expected the format of the \"file\" parameters '${file}' to be '${\n OneTrustFileFormat.Json\n }', but got '${splitFile.at(-1)}'.`,\n );\n }\n }\n\n // if reading assessments from a OneTrust\n if (source === OneTrustPullSource.OneTrust) {\n // must specify the OneTrust hostname\n if (!hostname) {\n throw new Error(\n 'Missing required parameter \"hostname\". e.g. --hostname=customer.my.onetrust.com',\n );\n }\n // must specify the OneTrust auth\n if (!oneTrustAuth) {\n throw new Error(\n 'Missing required parameter \"oneTrustAuth\". e.g. --oneTrustAuth=$ONE_TRUST_AUTH_TOKEN',\n );\n }\n } else {\n // if reading the assessments from a file, must specify a file to read from\n if (!file) {\n throw new Error(\n 'Must specify a \"file\" parameter to read the OneTrust assessments from. e.g. --source=./oneTrustAssessments.json',\n );\n }\n\n // Cannot try reading from file and save assessments to a file simultaneously\n if (dryRun) {\n throw new Error(\n 'Cannot read and write to a file simultaneously.' +\n ` Emit the \"source\" parameter or set it to ${OneTrustPullSource.OneTrust} if \"dryRun\" is enabled.`,\n );\n }\n }\n\n doneInputValidation(this.process.exit);\n\n // instantiate a client to talk to OneTrust\n const oneTrust =\n hostname && oneTrustAuth\n ? createOneTrustGotInstance({\n hostname,\n auth: oneTrustAuth,\n })\n : undefined;\n\n // instantiate a client to talk to Transcend\n const transcend =\n transcendUrl && transcendAuth\n ? buildTranscendGraphQLClient(transcendUrl, transcendAuth)\n : undefined;\n\n try {\n if (resource === OneTrustPullResource.Assessments) {\n if (source === OneTrustPullSource.OneTrust && oneTrust) {\n await syncOneTrustAssessmentsFromOneTrust({\n oneTrust,\n file,\n dryRun,\n ...(transcend && { transcend }),\n });\n } else if (source === OneTrustPullSource.File && file && transcend) {\n await syncOneTrustAssessmentsFromFile({ file, transcend });\n }\n }\n } catch (err) {\n throw new Error(\n `An error occurred syncing the resource ${resource} from OneTrust: ${\n debug ? err.stack : err.message\n }`,\n );\n }\n\n // Indicate success\n logger.info(\n colors.green(\n `Successfully synced OneTrust ${resource} to ${\n dryRun ? `disk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CAAC,QAGvD,EAAK,CACZ,MAAU,MACR,0CAA0C,EAAS,kBACjD,EAAQ,EAAI,MAAQ,EAAI,UAE3B,CAIH,EAAA,EAAO,KACL,EAAA,QAAO,MACL,gCAAgC,EAAS,MACvC,EAAS,YAAY,EAAK,GAAK,YAChC,GACF,CACF"}
package/dist/index.cjs DELETED
@@ -1,5 +0,0 @@
1
- const e=require(`./chunk-Bmb41Sf3.cjs`),t=require(`./constants-gJm1eQH0.cjs`),n=require(`./syncConfigurationToTranscend-s-cjtUI3.cjs`),r=require(`./enums-BZulhPFa.cjs`);require(`./logger-DQwEYtSS.cjs`);const i=require(`./buildAIIntegrationType-BwuCYR-o.cjs`),a=require(`./codecs-Bvmb8o9R.cjs`),o=require(`./readTranscendYaml-Cycz6RxW.cjs`),s=require(`./mergeTranscendInputs-BIBCYbug.cjs`),c=require(`./consent-manager-C3UVAKd_.cjs`),l=require(`./uploadConsents-CDkk_sWY.cjs`),u=require(`./cron-NLlyCiml.cjs`),d=require(`./api-keys-DMPYZTne.cjs`),f=require(`./data-inventory-a9Nz9lUO.cjs`),p=require(`./manual-enrichment-DTVJo7hP.cjs`);let m=require(`@transcend-io/privacy-types`),h=require(`@transcend-io/type-utils`),g=require(`@transcend-io/handlebars-utils`),_=require(`fast-glob`);_=e.t(_);let v=require(`child_process`);const y=20;async function b(e){let t=[],r=0,i=!1;do{let{largeLanguageModels:{nodes:a}}=await n.i(e,n.Xi,{first:20,offset:r});t.push(...a),r+=20,i=a.length===20}while(i);return t.sort((e,t)=>e.name.localeCompare(t.name))}function x(e){return RegExp(`<${e}>([\\s\\S]+?)<\\/${e}>`)}function S(e){return e}const C=e=>{try{return JSON.parse(e)}catch{return e}};var w=class{prompts;handlebarsOptions;promptContentMap;largeLanguageModels=[];agentsByName={};agentsByAgentId={};graphQLClient;defaultVariables;variables;handlebars;transcendApiKey;transcendUrl;requireApproval;cacheDuration;lastUpdatedAt;constructor({prompts:e,handlebarsOptions:r={},transcendUrl:i=t.a,transcendApiKey:a,requireApproval:o=!0,cacheDuration:s,defaultVariables:c={}}){this.prompts=e,this.transcendUrl=i,this.transcendApiKey=a,this.variables=c,this.defaultVariables=c,this.graphQLClient=n.ai(i,typeof a==`object`?a.release():a),this.requireApproval=o,this.cacheDuration=s,this.handlebarsOptions=r,this.handlebars=(0,g.createHandlebarsWithHelpers)(r)}async fetchPromptsAndMetadata(){let e=(0,h.getValues)(this.prompts),r=e.map(({id:e})=>e).filter(e=>!!e),i=e.map(({title:e})=>e).filter(e=>!!e),a=n.Ms(e.map(({agentNames:e})=>e||[]).flat()),[o,s,c]=await Promise.all([n.Qn(this.graphQLClient,{promptIds:r,promptTitles:i}),b(this.graphQLClient),n.Yr(this.graphQLClient,{names:a})]);this.agentsByName=t.g(c,`name`),this.agentsByAgentId=t.g(c,`agentId`),this.largeLanguageModels=s.filter(e=>e.isTranscendHosted===!1);let l=t.g(o.prompts,`title`),u=t.g(o.prompts,`id`);return this.variables={...o.calculatedVariables.reduce((e,t)=>Object.assign(e,{[t.name]:t.data?JSON.parse(t.data):t.data}),{}),...this.defaultVariables},this.handlebars=(0,g.createHandlebarsWithHelpers)({...this.handlebarsOptions,templates:[...this.handlebarsOptions.templates||[],...o.promptPartials.map(e=>({name:e.slug,content:e.content}))]}),this.promptContentMap=(0,h.apply)(this.prompts,({id:e,title:t})=>{let n=e?u[e]:t?l[t]:void 0;if(!n)throw Error(`Failed to find prompt with title: "${t}" and id: "${e}"`);return n}),this.lastUpdatedAt=new Date,o}async getAgentByName(e){let t=this.agentsByName[e];if(t)return t;let[r]=await n.Yr(this.graphQLClient,{names:[e]});if(r)return this.agentsByName[r.name]=r,this.agentsByAgentId[r.agentId]=r,r}async getPromptThreadBySlackTs(e){let[t]=await n.Xn(this.graphQLClient,{slackMessageTs:[e]});return t}async getAgentsByName(e){if(e.length<1)throw Error(`Expected at least one name to be provided`);let{hasCache:t=[],missingCache:r=[]}=n.Fs(e,e=>this.agentsByName[e]?`hasCache`:`missingCache`),i=t.map(e=>this.agentsByName[e]);if(r.length===0)return i;let a=n.Rs(r,50),o=[];return await n.js(a,async e=>{let t=await n.Yr(this.graphQLClient,{names:e});t.forEach(e=>{this.agentsByName[e.name]=e,this.agentsByAgentId[e.agentId]=e}),o.push(...t)}),[...i,...o]}getAgentFiles(e){return n.Zr(this.graphQLClient,e)}getLargeLanguageModel(e){let t=this.largeLanguageModels.find(t=>typeof e==`string`?t.id===e:t.name===e.name&&t.client===e.client);if(!t)throw Error(`Failed to find model matching: ${typeof e==`string`?e:JSON.stringify(e)}`);return t}async getPromptDefinition(e){(!this.lastUpdatedAt||this.cacheDuration===0||this.cacheDuration&&Date.now()-this.lastUpdatedAt.getTime()>this.cacheDuration)&&await this.fetchPromptsAndMetadata();let{promptContentMap:t}=this;if(!t)throw Error(`Expected this.promptContentMap to be defined`);let n=t[e];if(!n)throw Error(`Expected this.promptContentMap[${e}] to be defined`);return n}async compilePrompt(e,t){let n=await this.getPromptDefinition(e),r=this.prompts[e];if(!r)throw Error(`Expected this.prompts[${e}] to be defined`);if(this.requireApproval&&n.status!==m.PromptStatus.Approved)throw Error(`Assessment "${n.title}" cannot be used because its in status: "${n.status}"`);if(n.status===m.PromptStatus.Rejected)throw Error(`Assessment "${n.title}" cannot be used because it's in status: "${n.status}"`);return(0,h.decodeCodec)(r.paramCodec,t),this.handlebars.compile(n.content)({currentDate:new Date().toISOString(),...this.variables,...t})}parseAiResponse(e,t){let n=this.prompts[e];if(!n)throw Error(`Expected this.prompts[${e}] to be defined`);let r=n.extractFromTag&&(x(n.extractFromTag).exec(t)||[])[1]||t;return(0,h.decodeCodec)(n.outputCodec,C(r),!1)}async reportAndParsePromptRun(e,{largeLanguageModel:t,...r}){(!this.lastUpdatedAt||this.cacheDuration===0||this.cacheDuration&&Date.now()-this.lastUpdatedAt.getTime()>this.cacheDuration)&&await this.fetchPromptsAndMetadata();let i=r.name||`@transcend-io/cli-prompt-run-${new Date().toISOString()}`;if(!this.promptContentMap)throw Error(`Expected this.promptContentMap to be defined`);let a=this.promptContentMap[e];if(!a)throw Error(`Expected this.prompts[${e}] to be defined`);if(r.promptRunMessages.length===0)throw Error(`promptRunMessages is expected to have length > 0`);if(r.promptRunMessages[0].role!==m.ChatCompletionRole.System)throw Error(`promptRunMessages[0].role is expected to be = ${m.ChatCompletionRole.System}`);if(r.promptRunMessages[r.promptRunMessages.length-1].role!==m.ChatCompletionRole.Assistant)throw Error(`promptRunMessages[${r.promptRunMessages.length-1}].role is expected to be = ${m.ChatCompletionRole.Assistant}`);let o=r.promptRunMessages[r.promptRunMessages.length-1].content,s;try{s=this.parseAiResponse(e,o)}catch(e){throw await n._n(this.graphQLClient,{productArea:m.PromptRunProductArea.PromptManager,...r,name:i,error:e.message,status:m.QueueStatus.Error,...typeof t==`string`?{largeLanguageModelId:t}:{largeLanguageModelName:t.name,largeLanguageModelClient:t.client},promptId:a.id,promptRunMessages:r.promptRunMessages.map((e,t)=>({...e,...t===0?{template:a.content}:{}}))}),e}let c=await n._n(this.graphQLClient,{productArea:m.PromptRunProductArea.PromptManager,...r,name:i,status:m.QueueStatus.Resolved,...typeof t==`string`?{largeLanguageModelId:t}:{largeLanguageModelName:t.name,largeLanguageModelClient:t.client},promptId:a.id,promptRunMessages:r.promptRunMessages.map((e,t)=>({...e,...t===0?{template:a.content}:{}}))});return{result:s,promptRunId:c,promptRunUrl:`https://app.transcend.io/prompts/runs/${c}`}}async reportPromptRunError(e,{largeLanguageModel:t,...r}){(!this.lastUpdatedAt||this.cacheDuration===0||this.cacheDuration&&Date.now()-this.lastUpdatedAt.getTime()>this.cacheDuration)&&await this.fetchPromptsAndMetadata();let i=r.name||`@transcend-io/cli-prompt-run-${new Date().toISOString()}`;if(!this.promptContentMap)throw Error(`Expected this.promptContentMap to be defined`);let a=this.promptContentMap[e];if(!a)throw Error(`Expected this.prompts[${e}] to be defined`);if(r.promptRunMessages.length===0)throw Error(`promptRunMessages is expected to have length > 0`);if(r.promptRunMessages[0].role!==m.ChatCompletionRole.System)throw Error(`promptRunMessages[0].role is expected to be = ${m.ChatCompletionRole.System}`);let o=await n._n(this.graphQLClient,{productArea:m.PromptRunProductArea.PromptManager,...r,name:i,status:m.QueueStatus.Error,...typeof t==`string`?{largeLanguageModelId:t}:{largeLanguageModelName:t.name,largeLanguageModelClient:t.client},promptId:a.id,promptRunMessages:r.promptRunMessages.map((e,t)=>({...e,...t===0?{template:a.content}:{}}))});return{promptRunId:o,promptRunUrl:`https://app.transcend.io/prompts/runs/${o}`}}};function T(e){return e.replace(/(https?:\/\/[^\s]+)/g,`<link-omitted>`)}function E(e){return Object.entries(e).reduce((e,[t,n])=>n!=null&&n!==``&&!(Array.isArray(n)&&n.length===0)&&!(typeof n==`object`&&Object.keys(n).length===0)?Object.assign(e,{[t]:n}):e,{})}function D({baseBranch:e,rootDirectory:t,githubRepo:r,excludedGlob:i=[],fileBlockList:a=[]}){(0,v.execSync)(`git fetch origin ${e}`);let o=(0,v.execSync)(`git ls-remote ${r} "refs/heads/${e}" | cut -f 1`,{encoding:`utf-8`}).split(`
2
- `)[0],s=(0,v.execSync)(`git rev-parse HEAD`,{encoding:`utf-8`}).split(`
3
- `)[0];if(!o||!s)throw Error(`FAILED TO FIND COMMIT RANGE`);let c=n.Is((0,v.execSync)(`git fetch && git diff --name-only "${e||o}...${s}" -- ${t}`,{encoding:`utf-8`}).split(`
4
- `).filter(e=>e),a),l=i.length>0?_.default.sync(c,{ignore:i}):c,u={};return l.forEach(e=>{u[e]=(0,v.execSync)(`git show ${s}:${e}`,{encoding:`utf-8`})}),{changedFiles:c,fileDiffs:u,repoName:r.split(`/`).pop().split(`.`)[0],commit:s}}exports.ACTIONS=n.sa,exports.ADD_MESSAGES_TO_PROMPT_RUN=n.Ya,exports.ADD_SILO_DISCOVERY_RESULTS=n.Yo,exports.ADMIN_DASH=t.t,exports.ADMIN_DASH_DATAPOINTS=t.n,exports.ADMIN_DASH_INTEGRATIONS=t.r,exports.AGENTS=n.qi,exports.AGENT_FILES=n.Wi,exports.AGENT_FUNCTIONS=n.Vi,exports.API_KEYS=n.Qo,exports.APPROVE_PRIVACY_REQUEST=n.Ao,exports.ASSESSMENTS=n.So,exports.ASSESSMENT_SECTION_FIELDS=n.Co,exports.ASSESSMENT_TEMPLATES=n.yo,exports.ASSUME_ROLE=n.Zi,exports.ATTRIBUTES=n.Ra,exports.ATTRIBUTE_KEYS_REQUESTS=n.Go,exports.ATTRIBUTE_VALUES=n.za,exports.ActionInput=a.t,exports.ActionItemCollectionInput=a.n,exports.ActionItemInput=a.r,exports.AgentFileInput=a.i,exports.AgentFunctionInput=a.a,exports.AgentInput=a.o,exports.ApiKeyInput=a.s,exports.AssessmentAction=n.Fn,exports.AssessmentAnswerOptionInput=a.c,exports.AssessmentDisplayLogicInput=a.l,exports.AssessmentInput=a.u,exports.AssessmentNestedRule=n.In,exports.AssessmentNestedRuleInput=a.d,exports.AssessmentResourceInput=a.f,exports.AssessmentRetentionScheduleInput=a.p,exports.AssessmentRiskLogic=n.Nn,exports.AssessmentRule=n.Ln,exports.AssessmentRuleInput=a.m,exports.AssessmentRuleWithOperands=n.Rn,exports.AssessmentRuleWithoutOperands=n.zn,exports.AssessmentSectionInput=a.h,exports.AssessmentSectionQuestionInput=a.g,exports.AssessmentTemplateInput=a._,exports.AttestedExtraIdentifiers=n.at,exports.AttributeInput=a.v,exports.AttributePreview=a.y,exports.AttributeValueInput=a.b,exports.BLANK=n._i,exports.BULK_APPLY=n.vi,exports.BULK_REQUEST_FILES=n.Za,exports.BUSINESS_ENTITIES=n.la,exports.BusinessEntityInput=a.x,exports.CANCEL_PRIVACY_REQUEST=n.jo,exports.CAN_APPLY_IN_BULK=n.yi,exports.CATALOGS=n.fs,exports.CHANGE_REQUEST_DATA_SILO_STATUS=n.ao,exports.CODE_PACKAGES=n.zo,exports.CONSENT_MANAGER_ANALYTICS_DATA=n.fa,exports.CONSENT_PARTITIONS=n.pa,exports.COOKIES=n.ma,exports.CREATE_ACTION_ITEMS=n.ia,exports.CREATE_ACTION_ITEM_COLLECTION=n.Ka,exports.CREATE_AGENT=n.Ji,exports.CREATE_AGENT_FILE=n.Gi,exports.CREATE_AGENT_FUNCTION=n.Hi,exports.CREATE_API_KEY=n.$o,exports.CREATE_ATTRIBUTE=n.Ba,exports.CREATE_ATTRIBUTE_VALUES=n.Va,exports.CREATE_BUSINESS_ENTITY=n.ua,exports.CREATE_CODE_PACKAGE=n.Bo,exports.CREATE_CONSENT_EXPERIENCE=n.ha,exports.CREATE_CONSENT_MANAGER=n.ga,exports.CREATE_CONSENT_PARTITION=n._a,exports.CREATE_DATA_FLOWS=n.va,exports.CREATE_DATA_SILOS=n._s,exports.CREATE_DATA_SUBJECT=n.is,exports.CREATE_DATA_SUB_CATEGORY=n.Fi,exports.CREATE_ENRICHER=n.ps,exports.CREATE_IDENTIFIER=n.cs,exports.CREATE_PREFERENCE_ACCESS_TOKENS=n.Zo,exports.CREATE_PROCESSING_ACTIVITY=n.ki,exports.CREATE_PROCESSING_PURPOSE_SUB_CATEGORY=n.Mi,exports.CREATE_PROMPT=n.lo,exports.CREATE_PROMPT_GROUP=n.uo,exports.CREATE_PROMPT_PARTIAL=n.do,exports.CREATE_REPOSITORY=n.ts,exports.CREATE_SOFTWARE_DEVELOPMENT_KIT=n.Ho,exports.CREATE_TEAM=n.no,exports.CREATE_TEMPLATE=n.qo,exports.CREATE_VENDOR=n.Ri,exports.CachedFileState=n.bi,exports.CachedRequestState=n.xi,exports.CodePackageInput=a.S,exports.CodePackageSdk=a.C,exports.ColumnName=n.Si,exports.ConsentManageExperienceInput=a.w,exports.ConsentManagerInput=a.T,exports.ConsentManagerMetricBin=n.Fr,exports.ConsentManagerServiceMetadata=a.E,exports.ConsentPreferenceTopic=a.D,exports.ConsentPreferenceTopicOptionValue=a.O,exports.ConsentPurpose=a.k,exports.CookieCsvInput=a.A,exports.CookieInput=a.j,exports.CronIdentifier=u.o,exports.CronIdentifierPush=u.i,exports.DATAPOINT_EXPORT=n.Cs,exports.DATA_FLOWS=n.ya,exports.DATA_POINTS=n.ws,exports.DATA_POINT_COUNT=n.Ts,exports.DATA_SILOS=n.vs,exports.DATA_SILOS_ENRICHED=n.ys,exports.DATA_SILO_EXPORT=n.bs,exports.DATA_SUBJECTS=n.as,exports.DATA_SUB_CATEGORIES=n.Ii,exports.DAY_MS=n.f,exports.DEBUG=t.i,exports.DEFAULT_TRANSCEND_API=t.a,exports.DEFAULT_TRANSCEND_CONSENT_API=t.o,exports.DEFAULT_TRANSCEND_PULL_RESOURCES=n.vn,exports.DELETE_API_KEY=n.es,exports.DELETE_ATTRIBUTE_VALUE=n.Ha,exports.DEPLOYED_PRIVACY_CENTER_URL=n.ea,exports.DEPLOY_CONSENT_MANAGER=n.ba,exports.DETERMINE_LOGIN_METHOD=n.Qi,exports.DataCategoryGuessInput=a.M,exports.DataCategoryInput=a.N,exports.DataCategoryPreviewInput=a.P,exports.DataCategoryRecommendationInput=a.F,exports.DataFlowCsvInput=a.I,exports.DataFlowInput=a.L,exports.DataSiloInput=a.R,exports.DataSubjectInput=a.z,exports.DatapointInput=a.B,exports.ENABLED_PLUGINS=n.Xo,exports.ENRICHERS=n.ms,exports.ENTRY_COUNT=n.Ss,exports.EXPERIENCES=n.xa,exports.EnrichPrivacyRequest=p.n,exports.EnricherInput=a.V,exports.FETCH_CONSENT_MANAGER=n.Sa,exports.FETCH_CONSENT_MANAGER_ID=n.Ca,exports.FETCH_CONSENT_MANAGER_THEME=n.wa,exports.FETCH_PRIVACY_CENTER_ID=n.ta,exports.FIVE_MIN_MS=n.p,exports.FieldInput=a.H,exports.GLOBAL_ACTION_ITEMS=n.aa,exports.GLOBAL_ACTION_ITEM_COLLECTIONS=n.qa,exports.HOUR_MS=n.m,exports.IDENTIFIERS=n.ls,exports.IDENTIFIER_BLOCK_LIST=n.Ci,exports.IMPORT_ONE_TRUST_ASSESSMENT_FORMS=n.wo,exports.INITIALIZER=n.hs,exports.IP_ADDRESS_REGEX=c.n,exports.IS_REQUIRED=n.wi,exports.IdentifierInput=a.U,exports.ImportOnetrustAssessmentsInput=a.W,exports.IntlMessage=n.tt,exports.IntlMessageInput=a.G,exports.LARGE_LANGUAGE_MODELS=n.Xi,exports.LOGIN=n.$i,exports.MESSAGES=n.Oo,exports.NEW_IDENTIFIER_TYPES=n.us,exports.NONE=n.Ti,exports.NOTIFY_ADDITIONAL_TIME=n.Mo,exports.ORGANIZATION=n.Ko,exports.OneTrustFileFormat=r.t,exports.OneTrustPullResource=r.n,exports.OneTrustPullSource=r.r,exports.OpenAIEnabledRoute=a.K,exports.OpenAIEnabledRoutes=a.q,exports.OpenAIIntegration=a.J,exports.OpenAIRouteName=r.i,exports.POLICIES=n.Io,exports.PREFERENCE_TOPICS=n.bo,exports.PRIVACY_CENTER=n.na,exports.PROCESSING_ACTIVITIES=n.Ai,exports.PROCESSING_PURPOSE_SUB_CATEGORIES=n.Ni,exports.PROMPTS=n.fo,exports.PROMPTS_WITH_VARIABLES=n.po,exports.PROMPT_GROUPS=n.mo,exports.PROMPT_PARTIALS=n.ho,exports.PROMPT_THREADS=n.Ro,exports.PURPOSES=n.xo,exports.ParsedAttributeInput=n.di,exports.PartitionInput=a.Y,exports.PathfinderPolicy=a.X,exports.PathfinderPolicyName=r.a,exports.PathfinderPolicyNameC=a.Z,exports.PathfinderPromptRunMetadata=a.Q,exports.PolicyInput=a.$,exports.PrivacyCenterInput=a.et,exports.PrivacyRequest=n.fr,exports.PrivacyRequestInput=n.ot,exports.PrivacyRequestResponse=n.Z,exports.ProcessingActivityInput=a.tt,exports.ProcessingPurposeInput=a.nt,exports.ProcessingPurposePreviewInput=a.rt,exports.PromptAVendorEmailSettings=a.it,exports.PromptGroupInput=a.at,exports.PromptInput=a.ot,exports.PromptPartialInput=a.st,exports.PurposeMap=l.t,exports.REDUCED_REQUESTS_FOR_DATA_SILO_COUNT=n.oo,exports.REMOVE_REQUEST_IDENTIFIERS=n.eo,exports.REPORT_PROMPT_RUN=n.Xa,exports.REPOSITORIES=n.ns,exports.REQUESTS=n.No,exports.REQUESTS_COUNT=n.Po,exports.REQUEST_DATA_SILOS=n.so,exports.REQUEST_ENRICHERS=n.To,exports.REQUEST_FILES=n.Qa,exports.REQUEST_IDENTIFIERS=n.to,exports.RETRYABLE_BATCH_STATUSES=t.s,exports.RETRY_REQUEST_DATA_SILO=n.co,exports.RETRY_REQUEST_ENRICHER=n.Eo,exports.RateCounter=n.C,exports.RegionInput=a.ct,exports.RepositoryInput=a.lt,exports.RequestFileMetadata=n.nt,exports.RequestFileMetadataResponse=n.rt,exports.RequestIdentifiersResponse=n.gr,exports.RequestPurposeTrigger=n.pr,exports.RiskAssignmentInput=a.ut,exports.RiskLogicInput=a.dt,exports.SCOPES_BY_TITLE=t.c,exports.SCOPE_TITLES=t.l,exports.SET_RESOURCE_ATTRIBUTES=n.Ua,exports.SILO_DISCOVERY_RESULTS=n.Di,exports.SKIP_REQUEST_ENRICHER=n.Do,exports.SOFTWARE_DEVELOPMENT_KITS=n.Uo,exports.SOMBRA_VERSION=n.Oi,exports.SUB_DATA_POINTS=n.Es,exports.SUB_DATA_POINTS_COUNT=n.Ds,exports.SUB_DATA_POINTS_WITH_GUESSES=n.Os,exports.SYNC_ATTRIBUTE_TYPES=n.Hr,exports.SiloDiscoveryResultInput=a.ft,exports.SoftwareDevelopmentKitInput=a.pt,exports.StoredApiKey=a.mt,exports.SuccessfulRequest=n.Ei,exports.TEAMS=n.ro,exports.TEMPLATES=n.Jo,exports.TOGGLE_CONSENT_PRECEDENCE=n.Ta,exports.TOGGLE_DATA_SUBJECT=n.os,exports.TOGGLE_TELEMETRY_PARTITION_STRATEGY=n.Ea,exports.TOGGLE_UNKNOWN_COOKIE_POLICY=n.Da,exports.TOGGLE_UNKNOWN_REQUEST_POLICY=n.Oa,exports.TR_PULL_RESOURCE_SCOPE_MAP=t.u,exports.TR_PUSH_RESOURCE_SCOPE_MAP=t.d,exports.TR_YML_RESOURCE_TO_FIELD_NAME=t.f,exports.TeamInput=a.ht,exports.TemplateInput=a.gt,exports.TranscendInput=a._t,exports.TranscendPromptManager=w,exports.TranscendPullResource=r.o,exports.UPDATE_ACTION=n.ca,exports.UPDATE_ACTION_ITEMS=n.oa,exports.UPDATE_ACTION_ITEM_COLLECTION=n.Ja,exports.UPDATE_AGENTS=n.Yi,exports.UPDATE_AGENT_FILES=n.Ki,exports.UPDATE_AGENT_FUNCTIONS=n.Ui,exports.UPDATE_ATTRIBUTE=n.Wa,exports.UPDATE_ATTRIBUTE_VALUES=n.Ga,exports.UPDATE_BUSINESS_ENTITIES=n.da,exports.UPDATE_CODE_PACKAGES=n.Vo,exports.UPDATE_CONSENT_EXPERIENCE=n.ka,exports.UPDATE_CONSENT_MANAGER_DOMAINS=n.Aa,exports.UPDATE_CONSENT_MANAGER_PARTITION=n.ja,exports.UPDATE_CONSENT_MANAGER_THEME=n.Ma,exports.UPDATE_CONSENT_MANAGER_TO_LATEST=n.Na,exports.UPDATE_CONSENT_MANAGER_VERSION=n.Pa,exports.UPDATE_DATA_FLOWS=n.Fa,exports.UPDATE_DATA_SILOS=n.xs,exports.UPDATE_DATA_SUBJECT=n.ss,exports.UPDATE_DATA_SUB_CATEGORIES=n.Li,exports.UPDATE_ENRICHER=n.gs,exports.UPDATE_IDENTIFIER=n.ds,exports.UPDATE_INTL_MESSAGES=n.ko,exports.UPDATE_LOAD_OPTIONS=n.Ia,exports.UPDATE_OR_CREATE_COOKIES=n.La,exports.UPDATE_OR_CREATE_DATA_POINT=n.ks,exports.UPDATE_POLICIES=n.Lo,exports.UPDATE_PRIVACY_CENTER=n.ra,exports.UPDATE_PRIVACY_REQUEST=n.Fo,exports.UPDATE_PROCESSING_ACTIVITIES=n.ji,exports.UPDATE_PROCESSING_PURPOSE_SUB_CATEGORIES=n.Pi,exports.UPDATE_PROMPTS=n.go,exports.UPDATE_PROMPT_GROUPS=n._o,exports.UPDATE_PROMPT_PARTIALS=n.vo,exports.UPDATE_REPOSITORIES=n.rs,exports.UPDATE_SOFTWARE_DEVELOPMENT_KITS=n.Wo,exports.UPDATE_TEAM=n.io,exports.UPDATE_VENDORS=n.zi,exports.USERS=n.$a,exports.USP_STRING_REGEX=l.n,exports.VARIABLE_PARAMETERS_NAME=o.t,exports.VARIABLE_PARAMETERS_REGEXP=o.n,exports.VENDORS=n.Bi,exports.VendorInput=a.vt,exports.WebhookHeader=a.yt,exports.addDaysUtc=n.h,exports.addMessagesToPromptRun=n.si,exports.addMs=n.g,exports.appendCsvRowsOrdered=n.a,exports.appendCsvSync=n.o,exports.approvePrivacyRequests=n.X,exports.assumeRole=n.Un,exports.buildAIIntegrationType=i.t,exports.buildEnabledRouteType=i.n,exports.buildTranscendGraphQLClient=n.ai,exports.buildTranscendGraphQLClientGeneric=n.oi,exports.buildXdiSyncEndpoint=c.r,exports.bulkRestartRequests=n.H,exports.bulkRetryEnrichers=n.B,exports.cancelPrivacyRequests=n.q,exports.clampPageSize=n._,exports.collectParquetFilesOrExit=n.x,exports.consentManagersToBusinessEntities=c.t,exports.convertToDataSubjectAllowlist=n.tr,exports.convertToDataSubjectBlockList=n.nr,exports.createActionItemCollection=n.dn,exports.createActionItems=n.cn,exports.createAgent=n.$t,exports.createAgentFile=n.an,exports.createAgentFunction=n.nn,exports.createApiKey=n.Vn,exports.createBusinessEntity=n.Yt,exports.createCodePackage=n.Bt,exports.createConsentToken=l.i,exports.createDataCategory=n.Nt,exports.createDataFlows=n.At,exports.createPreferenceAccessTokens=n.Kr,exports.createProcessingPurpose=n.yt,exports.createPrompt=n.gt,exports.createRegexForTag=x,exports.createRepository=n.Ut,exports.createSoftwareDevelopmentKit=n.Kt,exports.createSombraGotInstance=n.ii,exports.createTranscendConsentGotInstance=n.ri,exports.createVendor=n.pt,exports.defineTranscendPrompts=S,exports.deleteApiKey=n.Hn,exports.deployConsentManager=n.ti,Object.defineProperty(exports,`description`,{enumerable:!0,get:function(){return t.m}}),exports.domainToHost=c.i,exports.downloadPrivacyRequestFiles=n.$,exports.enrichPrivacyRequest=p.r,exports.ensureAllDataSubjectsExist=n.rr,exports.extractClientError=n.G,exports.extractErrorMessage=n.O,exports.fetchActiveSiloDiscoPlugin=n.ei,exports.fetchAllActionItems=n.$r,exports.fetchAllActions=n.Qr,exports.fetchAllAgentFiles=n.Zr,exports.fetchAllAgentFunctions=n.Xr,exports.fetchAllAgents=n.Yr,exports.fetchAllApiKeys=n.sr,exports.fetchAllAssessmentTemplates=n.qr,exports.fetchAllAssessments=n.Jr,exports.fetchAllAttributeValues=n.Ur,exports.fetchAllAttributes=n.Wr,exports.fetchAllBusinessEntities=n.Vr,exports.fetchAllCatalogs=n.ar,exports.fetchAllCookies=n.Pr,exports.fetchAllDataCategories=n.Nr,exports.fetchAllDataFlows=n.Mr,exports.fetchAllDataPoints=n.Dn,exports.fetchAllDataSilos=n.On,exports.fetchAllDataSubjects=n.ir,exports.fetchAllEnrichers=n.Tn,exports.fetchAllIdentifiers=n.n,exports.fetchAllMessages=n.jr,exports.fetchAllPolicies=n.Or,exports.fetchAllPreferenceTopics=n.Er,exports.fetchAllPrivacyCenters=n.Tr,exports.fetchAllProcessingActivities=n.wr,exports.fetchAllProcessingPurposes=n.Cr,exports.fetchAllPromptGroups=n.er,exports.fetchAllPromptPartials=n.$n,exports.fetchAllPromptThreads=n.Xn,exports.fetchAllPrompts=n.Zn,exports.fetchAllPurposes=n.Sr,exports.fetchAllPurposesAndPreferences=n.xr,exports.fetchAllRequestAttributeKeys=n.Gr,exports.fetchAllRequestEnrichers=n.br,exports.fetchAllRequestIdentifierMetadata=n.yr,exports.fetchAllRequestIdentifiers=n._r,exports.fetchAllRequests=n.mr,exports.fetchAllSiloDiscoveryResults=n.bn,exports.fetchAllSubDataPoints=n.kn,exports.fetchAllTeams=n.dr,exports.fetchAllTemplates=n.Cn,exports.fetchAllUsers=n.ur,exports.fetchAllVendors=n.lr,exports.fetchAndIndexCatalogs=n.or,exports.fetchApiKeys=n.cr,exports.fetchConsentManager=n.Ir,exports.fetchConsentManagerAnalyticsData=n.Lr,exports.fetchConsentManagerExperiences=n.Rr,exports.fetchConsentManagerId=n.zr,exports.fetchConsentManagerTheme=n.Br,exports.fetchEnrichedDataSilos=n.An,exports.fetchIdentifiersAndCreateMissing=n.r,exports.fetchPartitions=n.xn,exports.fetchPrivacyCenterId=n.kr,exports.fetchPrivacyCenterUrl=n.Ar,exports.fetchPromptsWithVariables=n.Qn,exports.fetchRequestDataSilo=n.qn,exports.fetchRequestDataSiloActiveCount=n.Kn,exports.fetchRequestDataSilos=n.Jn,exports.fetchRequestDataSilosCount=n.Yn,exports.fetchRequestFilesForRequest=n.Gn,exports.fetchRequestsTotalCount=n.hr,exports.filterNullishValuesFromObject=E,exports.filterRows=n.ci,exports.formatAttributeValues=n.Dr,exports.formatRequestForCsv=n.R,exports.fuzzyMatchColumns=n.hi,exports.fuzzySearch=n.gi,exports.generateCrossAccountApiKeys=d.i,exports.getErrorStatus=n.k,exports.getFileMetadataForPrivacyRequests=n.it,exports.getGitFilesThatChanged=D,exports.getUniqueValuesForColumn=n.li,exports.initCsvFile=n.s,exports.inquirerAutoComplete=n.j,exports.inquirerConfirmBoolean=n.M,exports.inquirerConfirmText=n.N,exports.limitRecords=n.w,exports.listDirectories=d.t,exports.listFiles=d.n,exports.loginUser=n.Wn,exports.makeGraphQLRequest=n.i,exports.mapColumnsToAttributes=n.K,exports.mapColumnsToIdentifiers=n.J,exports.mapCsvColumnsToApi=n.ut,exports.mapCsvRowsToRequestInputs=n.st,exports.mapEnumValues=n.mi,exports.mapRequestEnumValues=n.lt,exports.markCronIdentifierCompleted=u.a,exports.markRequestDataSiloIdsCompleted=u.n,exports.markSilentPrivacyRequests=n.dt,exports.mergeTranscendInputs=s.t,exports.name=t.p,exports.normalizeIdentifierValue=n.ct,exports.notifyPrivacyRequestsAdditionalTime=n.Y,exports.parquetToCsvOneFile=n.b,exports.parseAssessmentDisplayLogic=n.Bn,exports.parseAssessmentRiskLogic=n.Pn,exports.parseAttributesFromString=n.fi,exports.parseFilePath=n.c,exports.parseVariablesFromString=n.A,exports.pullAllDatapoints=f.n,exports.pullChunkedCustomSiloOutstandingIdentifiers=u.t,exports.pullConsentManagerMetrics=c.a,exports.pullCronPageOfIdentifiers=u.s,exports.pullManualEnrichmentIdentifiersToCsv=p.i,exports.pullPrivacyRequests=n.L,exports.pullTranscendConfiguration=n.yn,exports.pullUnstructuredSubDataPointRecommendations=f.t,exports.pushCronIdentifiersFromCsv=u.r,exports.pushManualEnrichmentIdentifiersFromCsv=p.t,exports.readCsv=n.ui,exports.readSafe=n.S,exports.readTranscendYaml=o.r,exports.removeLinks=T,exports.removeUnverifiedRequestIdentifiers=n.P,exports.replaceVariablesInYaml=o.i,exports.reportPromptRun=n._n,exports.restartPrivacyRequest=n.U,exports.retryRequestDataSilos=n.z,exports.retryRequestEnricher=n.gn,exports.retrySamePromise=n.T,exports.setResourceAttributes=n.hn,exports.skipPreflightJobs=n.V,exports.skipRequestDataSilos=n.F,exports.sleepPromise=n.D,exports.splitCsvToList=n.pi,exports.splitInHalf=n.E,exports.startOfHour=n.v,exports.startOfUtcDay=n.y,exports.streamPrivacyRequestFiles=n.et,exports.streamPrivacyRequestsToCsv=n.I,exports.submitPrivacyRequest=n.Q,exports.syncAction=n.mn,exports.syncActionItemCollections=n.fn,exports.syncActionItems=n.ln,exports.syncAgentFiles=n.on,exports.syncAgentFunctions=n.rn,exports.syncAgents=n.en,exports.syncAttribute=n.Qt,exports.syncBusinessEntities=n.Xt,exports.syncCodePackages=n.Vt,exports.syncConfigurationToTranscend=n.t,exports.syncConsentManager=n.Rt,exports.syncConsentManagerExperiences=n.zt,exports.syncCookies=n.It,exports.syncDataCategories=n.Pt,exports.syncDataFlows=n.jt,exports.syncDataSiloDependencies=n.jn,exports.syncDataSilos=n.Mn,exports.syncDataSubject=n.kt,exports.syncEnricher=n.En,exports.syncIdentifier=n.Ot,exports.syncIntlMessages=n.Et,exports.syncPartitions=n.Sn,exports.syncPolicies=n.wt,exports.syncPrivacyCenter=n.Ct,exports.syncProcessingActivities=n.St,exports.syncProcessingPurposes=n.bt,exports.syncPrompts=n._t,exports.syncRepositories=n.Wt,exports.syncSoftwareDevelopmentKits=n.qt,exports.syncTemplate=n.wn,exports.syncVendors=n.mt,exports.updateActionItem=n.un,exports.updateActionItemCollection=n.pn,exports.updateAgentFiles=n.sn,exports.updateAgentFunctions=n.in,exports.updateAgents=n.tn,exports.updateBusinessEntities=n.Zt,exports.updateCodePackages=n.Ht,exports.updateConsentManagerToLatest=n.ni,exports.updateConsentManagerVersionToLatest=c.c,exports.updateDataCategories=n.Ft,exports.updateDataFlows=n.Mt,exports.updateIntlMessages=n.Dt,exports.updateOrCreateCookies=n.Lt,exports.updatePolicies=n.Tt,exports.updateProcessingPurposes=n.xt,exports.updatePrompts=n.vt,exports.updateRepositories=n.Gt,exports.updateSoftwareDevelopmentKits=n.Jt,exports.updateVendors=n.ht,exports.uploadConsents=l.r,exports.uploadCookiesFromCsv=c.o,exports.uploadDataFlowsFromCsv=c.s,exports.uploadPrivacyRequestsFromCsv=n.W,exports.uploadSiloDiscoveryResults=n.ft,exports.validateSombraVersion=n.vr,exports.validateTranscendAuth=d.r,Object.defineProperty(exports,`version`,{enumerable:!0,get:function(){return t.h}}),exports.writeCsv=n.l,exports.writeCsvSync=n.u,exports.writeLargeCsv=n.d,exports.writeTranscendYaml=o.a;
5
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","names":["makeGraphQLRequest","LARGE_LANGUAGE_MODELS","DEFAULT_TRANSCEND_API","buildTranscendGraphQLClient","uniq","agentNames","fetchPromptsWithVariables","fetchAllAgents","keyBy","name","fetchAllPromptThreads","groupBy","chunk","mapSeries","fetchAllAgentFiles","PromptStatus","ChatCompletionRole","reportPromptRun","PromptRunProductArea","QueueStatus","difference","fastGlob"],"sources":["../src/lib/graphql/fetchLargeLanguageModels.ts","../src/lib/ai/TranscendPromptManager.ts","../src/lib/ai/removeLinks.ts","../src/lib/ai/filterNullishValuesFromObject.ts","../src/lib/ai/getGitFilesThatChanged.ts"],"sourcesContent":["import { GraphQLClient } from 'graphql-request';\nimport { LargeLanguageModelClient } from '@transcend-io/privacy-types';\nimport { LARGE_LANGUAGE_MODELS } from './gqls';\nimport { makeGraphQLRequest } from './makeGraphQLRequest';\n\nexport interface LargeLanguageModel {\n /** ID of prompts */\n id: string;\n /** The name of the large language model. */\n name: string;\n /** The content of the prompt template. */\n client: LargeLanguageModelClient;\n /** Whether hosted by Transcend or not */\n isTranscendHosted: boolean;\n}\n\nconst PAGE_SIZE = 20;\n\n/**\n * Fetch all LargeLanguageModels in the organization\n *\n * @param client - GraphQL client\n * @returns All LargeLanguageModels in the organization\n */\nexport async function fetchAllLargeLanguageModels(\n client: GraphQLClient,\n): Promise<LargeLanguageModel[]> {\n const largeLanguageModels: LargeLanguageModel[] = [];\n let offset = 0;\n\n // Whether to continue looping\n let shouldContinue = false;\n do {\n const {\n largeLanguageModels: { nodes },\n } = await makeGraphQLRequest<{\n /** LargeLanguageModels */\n largeLanguageModels: {\n /** List */\n nodes: LargeLanguageModel[];\n };\n }>(client, LARGE_LANGUAGE_MODELS, {\n first: PAGE_SIZE,\n offset,\n });\n largeLanguageModels.push(...nodes);\n offset += PAGE_SIZE;\n shouldContinue = nodes.length === PAGE_SIZE;\n } while (shouldContinue);\n\n return largeLanguageModels.sort((a, b) => a.name.localeCompare(b.name));\n}\n","/* eslint-disable max-lines */\nimport {\n Optionalize,\n Requirize,\n apply,\n decodeCodec,\n getValues,\n} from '@transcend-io/type-utils';\nimport type { Handlebars } from '@transcend-io/handlebars-utils';\nimport { Secret } from '@transcend-io/secret-value';\nimport * as t from 'io-ts';\nimport { DEFAULT_TRANSCEND_API } from '../../constants';\nimport {\n Agent,\n AgentFile,\n AgentFileFilterBy,\n ReportPromptRunInput,\n buildTranscendGraphQLClient,\n fetchAllAgentFiles,\n fetchAllAgents,\n reportPromptRun,\n} from '../graphql';\nimport {\n HandlebarsInput,\n createHandlebarsWithHelpers,\n} from '@transcend-io/handlebars-utils';\nimport {\n TranscendPromptTemplated,\n TranscendPromptsAndVariables,\n fetchPromptsWithVariables,\n} from '../graphql/fetchPrompts';\nimport { GraphQLClient } from 'graphql-request';\nimport {\n PromptStatus,\n ChatCompletionRole,\n PromptRunProductArea,\n QueueStatus,\n LargeLanguageModelClient,\n} from '@transcend-io/privacy-types';\nimport {\n LargeLanguageModel,\n fetchAllLargeLanguageModels,\n} from '../graphql/fetchLargeLanguageModels';\nimport { groupBy, keyBy, uniq, chunk } from 'lodash-es';\nimport { mapSeries } from '../bluebird';\nimport {\n PromptThread,\n fetchAllPromptThreads,\n} from '../graphql/fetchPromptThreads';\n\n/**\n * An LLM Prompt definition\n */\nexport type TranscendPrompt<\n TInputParams extends t.Any,\n TOutputCodec extends t.Any,\n> = (\n | {\n /** ID of the prompt */\n id: string;\n /** Title of the prompt */\n title?: string;\n }\n | {\n /** ID of the prompt */\n id?: string;\n /** Title of the prompt */\n title: string;\n }\n) & {\n /** The names of the agents that should be loaded along with the prompt */\n agentNames?: string[];\n /** Codec to validate runtime input shape */\n paramCodec: TInputParams;\n /** Codec to validate output response */\n outputCodec: TOutputCodec;\n /**\n * If the output that needs to be parsed is returned within a tag\n * e.g. <tag> or <json> - this is the name of the tag\n */\n extractFromTag?: string;\n};\n\nexport interface PromptRunResult {\n /** The ID of the prompt run created on Transcend */\n promptRunId: string;\n /** The URL of the prompt run on Transcend */\n promptRunUrl: string;\n}\n\n/**\n * Create a regex to extract data from a tag\n *\n * Input:\n * \"here is some data <tag>Data</tag>...\"\n *\n * @param tagName - Name of tag\n * @returns Data within the tag\n */\nexport function createRegexForTag(tagName: string): RegExp {\n return new RegExp(`<${tagName}>([\\\\s\\\\S]+?)<\\\\/${tagName}>`);\n}\n\n/**\n * Helper function to declare prompts\n *\n * @param prompts - Prompt config\n * @returns Prompts as identity function - but type enforced\n */\nexport function defineTranscendPrompts<\n TPromptNames extends string,\n TPrompts extends { [k in TPromptNames]: TranscendPrompt<t.Any, t.Any> },\n>(prompts: TPrompts): TPrompts {\n return prompts;\n}\n\n/**\n * Helper to get the type of the parameter for a given prompt\n */\nexport type GetPromptParamType<\n TPromptName extends keyof TPrompts,\n TPrompts extends { [k in TPromptName]: TranscendPrompt<t.Any, t.Any> },\n> = t.TypeOf<TPrompts[TPromptName]['paramCodec']>;\n\n/**\n * Helper to get the type of the parameter for a given prompt\n */\nexport type GetPromptResponseType<\n TPromptName extends keyof TPrompts,\n TPrompts extends { [k in TPromptName]: TranscendPrompt<t.Any, t.Any> },\n> = t.TypeOf<TPrompts[TPromptName]['outputCodec']>;\n\n/**\n * Input for reporting a prompt run\n */\nexport interface ReportPromptRunOptions\n extends Optionalize<\n Omit<ReportPromptRunInput, 'status' | 'promptId' | 'largeLanguageModelId'>,\n 'name' | 'productArea'\n > {\n /** The large language model being run. Either the ID of the LLM or the client/name pairing */\n largeLanguageModel:\n | string\n | {\n /** Name of client */\n client: LargeLanguageModelClient;\n /** Name of the model */\n name: string;\n };\n}\n\nconst jsonParseSafe = (obj: string): unknown => {\n try {\n return JSON.parse(obj);\n } catch (e) {\n return obj;\n }\n};\n\n/**\n * A class that is capable of loading and insert variables into prompts from\n * Transcend's Prompt Manager\n */\nexport class TranscendPromptManager<\n TPromptNames extends string,\n TPrompts extends { [k in TPromptNames]: TranscendPrompt<t.Any, t.Any> },\n> {\n /** Prompt definitions */\n public prompts: TPrompts;\n\n /** Options for configuring handlebars */\n public handlebarsOptions!: HandlebarsInput;\n\n /** Prompt name -> content map, populated by call to Transcend API */\n public promptContentMap?: { [k in TPromptNames]: TranscendPromptTemplated };\n\n /** The large language models that are registered to this organization for reporting */\n public largeLanguageModels: LargeLanguageModel[] = [];\n\n /** The agent definitions registered to this organization */\n private agentsByName: { [name in string]: Agent } = {};\n\n /** The agent definitions registered to this organization */\n private agentsByAgentId: { [id in string]: Agent } = {};\n\n /** The GraphQL client that can be used to call Transcend */\n public graphQLClient: GraphQLClient;\n\n /** The set of variables to expose in handlebars context specified at class initiation */\n public defaultVariables: { [k in string]: unknown };\n\n /**\n * The set of variables to expose in handlebars context,\n * merges defaults with calculated variables from the inventory\n */\n public variables: { [k in string]: unknown };\n\n /** Handlebars compiler */\n public handlebars: typeof Handlebars;\n\n /** The Transcend API key */\n public transcendApiKey: string | Secret<string>;\n\n /** API of Transcend to call */\n public transcendUrl: string;\n\n /** When true, throw an error if the prompt is not approved */\n public requireApproval: boolean;\n\n /**\n * The cache duration in ms for how long prompts and associated metadata should be cached\n * When undefined - prompts are cached indefinitely unless explicitly re-requested\n * When 0, prompts and metadata are fetched every time (not recommended)\n * Setting this to be an hour is a good rate that optimizes for performance and keeping up to date\n */\n public cacheDuration?: number;\n\n /**\n * The last time the metadata was fetched\n */\n public lastUpdatedAt?: Date;\n\n /**\n * Constructor\n *\n * @param options - Options\n */\n constructor({\n prompts,\n handlebarsOptions = {},\n transcendUrl = DEFAULT_TRANSCEND_API,\n transcendApiKey,\n requireApproval = true,\n cacheDuration,\n defaultVariables = {},\n }: {\n /** Prompt definitions to load */\n prompts: TPrompts;\n /** Options for configuring handlebars */\n handlebarsOptions?: HandlebarsInput;\n /** The Transcend API key */\n transcendApiKey: string | Secret<string>;\n /** API of Transcend to call */\n transcendUrl?: string;\n /** When true, throw an error if the prompt is not approved */\n requireApproval?: boolean;\n /** The set of variables to expose in handlebars context specified at class initiation */\n defaultVariables?: { [k in string]: unknown };\n /**\n * The cache duration in ms for how long prompts and associated metadata should be cached\n * When undefined - prompts are cached indefinitely unless explicitly re-requested\n * When 0, prompts and metadata are fetched every time (not recommended)\n * Setting this to be an hour is a good rate that optimizes for performance and keeping up to date\n */\n cacheDuration?: number;\n }) {\n this.prompts = prompts;\n this.transcendUrl = transcendUrl;\n this.transcendApiKey = transcendApiKey;\n this.variables = defaultVariables;\n this.defaultVariables = defaultVariables;\n this.graphQLClient = buildTranscendGraphQLClient(\n transcendUrl,\n typeof transcendApiKey === 'object'\n ? transcendApiKey.release()\n : transcendApiKey,\n );\n this.requireApproval = requireApproval;\n this.cacheDuration = cacheDuration;\n this.handlebarsOptions = handlebarsOptions;\n this.handlebars = createHandlebarsWithHelpers(handlebarsOptions);\n }\n\n /**\n * Fetch prompt metadata from Transcend and cache to the class definition\n *\n * @returns A function that can be used to call the prompt\n */\n async fetchPromptsAndMetadata(): Promise<TranscendPromptsAndVariables> {\n // Determine what to fetch\n const promptDefinitions = getValues(this.prompts) as TranscendPrompt<\n t.Any,\n t.Any\n >[];\n const promptIds = promptDefinitions\n .map(({ id }) => id)\n .filter((x): x is string => !!x);\n const promptTitles = promptDefinitions\n .map(({ title }) => title)\n .filter((x): x is string => !!x);\n const agentNames = uniq(\n promptDefinitions.map(({ agentNames }) => agentNames || []).flat(),\n );\n\n // Fetch prompts and data\n const [response, largeLanguageModels, agents] = await Promise.all([\n fetchPromptsWithVariables(this.graphQLClient, {\n promptIds,\n promptTitles,\n }),\n fetchAllLargeLanguageModels(this.graphQLClient),\n fetchAllAgents(this.graphQLClient, { names: agentNames }),\n ]);\n this.agentsByName = keyBy(agents, 'name');\n this.agentsByAgentId = keyBy(agents, 'agentId');\n this.largeLanguageModels = largeLanguageModels.filter(\n (model) => model.isTranscendHosted === false,\n );\n\n // Lookup prompts by id/title\n const promptByTitle = keyBy(response.prompts, 'title');\n const promptById = keyBy(response.prompts, 'id');\n\n // Update variables\n this.variables = {\n ...response.calculatedVariables.reduce(\n (acc, v) =>\n Object.assign(acc, {\n [v.name]: v.data ? JSON.parse(v.data) : v.data,\n }),\n {},\n ),\n ...this.defaultVariables,\n };\n\n // Update partials\n this.handlebars = createHandlebarsWithHelpers({\n ...this.handlebarsOptions,\n templates: [\n ...(this.handlebarsOptions.templates || []),\n ...response.promptPartials.map((partial) => ({\n name: partial.slug,\n content: partial.content,\n })),\n ],\n });\n\n // Create mapping from prompt to content\n this.promptContentMap = apply(this.prompts, ({ id, title }) => {\n const result = id\n ? promptById[id]\n : title\n ? promptByTitle[title]\n : undefined;\n if (!result) {\n throw new Error(\n `Failed to find prompt with title: \"${title}\" and id: \"${id}\"`,\n );\n }\n return result;\n });\n\n // For cache\n this.lastUpdatedAt = new Date();\n\n return response;\n }\n\n /**\n * Get an agent definition by name\n *\n * @param name - Name of the agent to grab\n * @returns Large language model configuration\n */\n async getAgentByName(name: string): Promise<Agent | undefined> {\n const agent = this.agentsByName[name];\n if (agent) {\n return agent;\n }\n const [remoteAgent] = await fetchAllAgents(this.graphQLClient, {\n names: [name],\n });\n if (!remoteAgent) {\n return undefined;\n }\n this.agentsByName[remoteAgent.name] = remoteAgent;\n this.agentsByAgentId[remoteAgent.agentId] = remoteAgent;\n return remoteAgent;\n }\n\n /**\n * Get a prompt thread by ts\n *\n * @param ts - the slack message timestamp to look up thread for\n * @returns Large language model configuration\n */\n async getPromptThreadBySlackTs(\n ts: string,\n ): Promise<PromptThread | undefined> {\n const [thread] = await fetchAllPromptThreads(this.graphQLClient, {\n slackMessageTs: [ts],\n });\n return thread;\n }\n\n /**\n * Get a list of agent definitions by name.\n * Pulls from cache and may return less agents\n * than requested if some are not found\n *\n * @param names - Names of agents to fetch\n * @returns The agents that were found matching the names\n */\n async getAgentsByName(names: string[]): Promise<Agent[]> {\n if (names.length < 1) {\n throw new Error('Expected at least one name to be provided');\n }\n const { hasCache = [], missingCache = [] } = groupBy(names, (name) =>\n this.agentsByName[name] ? 'hasCache' : 'missingCache',\n );\n const cachedAgents = hasCache.map((name) => this.agentsByName[name]);\n if (missingCache.length === 0) {\n return cachedAgents;\n }\n const chunkedNames = chunk(missingCache, 50);\n const remoteAgents: Agent[] = [];\n await mapSeries(chunkedNames, async (chunkedName) => {\n const pageOfAgents = await fetchAllAgents(this.graphQLClient, {\n names: chunkedName,\n });\n pageOfAgents.forEach((agent) => {\n this.agentsByName[agent.name] = agent;\n this.agentsByAgentId[agent.agentId] = agent;\n });\n remoteAgents.push(...pageOfAgents);\n });\n return [...cachedAgents, ...remoteAgents];\n }\n\n /**\n * Fetch metadata on agent files\n *\n * @param filterBy - Filter by parameters\n * @returns The files found matching the filter\n */\n getAgentFiles(filterBy: AgentFileFilterBy): Promise<AgentFile[]> {\n return fetchAllAgentFiles(this.graphQLClient, filterBy);\n }\n\n /**\n * Look up the large language model to report on\n *\n * @param largeLanguageModel - Input\n * @returns Large language model configuration\n */\n getLargeLanguageModel(\n largeLanguageModel: ReportPromptRunOptions['largeLanguageModel'],\n ): LargeLanguageModel {\n const matching = this.largeLanguageModels.find((model) =>\n typeof largeLanguageModel === 'string'\n ? model.id === largeLanguageModel\n : model.name === largeLanguageModel.name &&\n model.client === largeLanguageModel.client,\n );\n if (!matching) {\n throw new Error(\n `Failed to find model matching: ${\n typeof largeLanguageModel === 'string'\n ? largeLanguageModel\n : JSON.stringify(largeLanguageModel)\n }`,\n );\n }\n return matching;\n }\n\n /**\n * Get a prompt definition by name\n *\n * @param promptName - Prompt to compile\n * @returns Parsed content\n */\n async getPromptDefinition<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n ): Promise<TranscendPromptTemplated> {\n // Determine if prompts need to be fetched\n if (\n // never been fetched\n !this.lastUpdatedAt ||\n // fetch every run\n this.cacheDuration === 0 ||\n // If cache duration met\n (this.cacheDuration &&\n Date.now() - this.lastUpdatedAt.getTime() > this.cacheDuration)\n ) {\n await this.fetchPromptsAndMetadata();\n }\n\n // Lookup prompt\n const { promptContentMap } = this;\n if (!promptContentMap) {\n throw new Error('Expected this.promptContentMap to be defined');\n }\n const promptTemplate = promptContentMap[promptName];\n if (!promptTemplate) {\n throw new Error(\n `Expected this.promptContentMap[${promptName}] to be defined`,\n );\n }\n return promptTemplate;\n }\n\n /**\n * Validate the shape of the response from AI\n *\n * @param promptName - Prompt to compile\n * @param params - Runtime parameters\n * @returns Parsed content\n */\n async compilePrompt<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n params: t.TypeOf<TPrompts[TPromptName]['paramCodec']>,\n ): Promise<string> {\n // Grab the prompt\n const promptTemplate = await this.getPromptDefinition(promptName);\n const promptInput = this.prompts[promptName];\n if (!promptInput) {\n throw new Error(`Expected this.prompts[${promptName}] to be defined`);\n }\n\n // Ensure prompt is approved\n if (\n this.requireApproval &&\n promptTemplate.status !== PromptStatus.Approved\n ) {\n throw new Error(\n `Assessment \"${promptTemplate.title}\" cannot be used because its in status: \"${promptTemplate.status}\"`,\n );\n }\n\n // If prompt is rejected, throw error\n if (promptTemplate.status === PromptStatus.Rejected) {\n throw new Error(\n `Assessment \"${promptTemplate.title}\" cannot be used because it's in status: \"${promptTemplate.status}\"`,\n );\n }\n\n // Validate params\n decodeCodec(promptInput.paramCodec, params);\n\n // Compile prompt and template\n return this.handlebars.compile(promptTemplate.content)({\n // template in currentDate by default\n currentDate: new Date().toISOString(),\n ...this.variables,\n ...params,\n });\n }\n\n /**\n * Validate the shape of the response from AI\n *\n * @param promptName - Prompt to parse\n * @param response - AI response as string\n * @returns Parsed content\n */\n parseAiResponse<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n response: string,\n ): t.TypeOf<TPrompts[TPromptName]['outputCodec']> {\n // Look up prompt info\n const promptInput = this.prompts[promptName];\n if (!promptInput) {\n throw new Error(`Expected this.prompts[${promptName}] to be defined`);\n }\n\n // Extract from tag if needed\n const extracted = promptInput.extractFromTag\n ? (createRegexForTag(promptInput.extractFromTag).exec(response) ||\n [])[1] || response\n : response;\n\n // Parse via codec\n return decodeCodec(\n promptInput.outputCodec,\n jsonParseSafe(extracted),\n false,\n );\n }\n\n /**\n * Parse the AI response and report back to Transcend\n *\n * @param promptName - Prompt to parse\n * @param options - Options for reporting\n * @returns Parsed content\n */\n async reportAndParsePromptRun<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n { largeLanguageModel, ...options }: ReportPromptRunOptions,\n ): Promise<\n PromptRunResult & {\n /** Resulting prompt run */\n result: t.TypeOf<TPrompts[TPromptName]['outputCodec']>;\n }\n > {\n // Determine if prompts need to be fetched\n if (\n // never been fetched\n !this.lastUpdatedAt ||\n // fetch every run\n this.cacheDuration === 0 ||\n // If cache duration met\n (this.cacheDuration &&\n Date.now() - this.lastUpdatedAt.getTime() > this.cacheDuration)\n ) {\n await this.fetchPromptsAndMetadata();\n }\n\n const name =\n options.name ||\n `@transcend-io/cli-prompt-run-${new Date().toISOString()}`;\n\n if (!this.promptContentMap) {\n throw new Error('Expected this.promptContentMap to be defined');\n }\n // Look up prompt info\n const promptInput = this.promptContentMap[promptName];\n if (!promptInput) {\n throw new Error(`Expected this.prompts[${promptName}] to be defined`);\n }\n\n // Ensure the first message in `promptRunMessages` is of type=system\n if (options.promptRunMessages.length === 0) {\n throw new Error('promptRunMessages is expected to have length > 0');\n }\n if (options.promptRunMessages[0].role !== ChatCompletionRole.System) {\n throw new Error(\n `promptRunMessages[0].role is expected to be = ${ChatCompletionRole.System}`,\n );\n }\n if (\n options.promptRunMessages[options.promptRunMessages.length - 1].role !==\n ChatCompletionRole.Assistant\n ) {\n throw new Error(\n `promptRunMessages[${\n options.promptRunMessages.length - 1\n }].role is expected to be = ${ChatCompletionRole.Assistant}`,\n );\n }\n const response =\n options.promptRunMessages[options.promptRunMessages.length - 1].content;\n\n let parsed: t.TypeOf<TPrompts[TPromptName]['outputCodec']>;\n try {\n // Parse the response\n parsed = this.parseAiResponse(promptName, response);\n } catch (err) {\n await reportPromptRun(this.graphQLClient, {\n productArea: PromptRunProductArea.PromptManager,\n ...options,\n name,\n error: err.message,\n status: QueueStatus.Error,\n ...(typeof largeLanguageModel === 'string'\n ? { largeLanguageModelId: largeLanguageModel }\n : {\n largeLanguageModelName: largeLanguageModel.name,\n largeLanguageModelClient: largeLanguageModel.client,\n }),\n promptId: promptInput.id,\n promptRunMessages: options.promptRunMessages.map((message, ind) => ({\n ...message,\n ...(ind === 0 ? { template: promptInput.content } : {}),\n })),\n });\n throw err;\n }\n\n // report successful run\n const promptRunId = await reportPromptRun(this.graphQLClient, {\n productArea: PromptRunProductArea.PromptManager,\n ...options,\n name,\n status: QueueStatus.Resolved,\n ...(typeof largeLanguageModel === 'string'\n ? { largeLanguageModelId: largeLanguageModel }\n : {\n largeLanguageModelName: largeLanguageModel.name,\n largeLanguageModelClient: largeLanguageModel.client,\n }),\n promptId: promptInput.id,\n promptRunMessages: options.promptRunMessages.map((message, ind) => ({\n ...message,\n ...(ind === 0 ? { template: promptInput.content } : {}),\n })),\n });\n\n return {\n result: parsed,\n promptRunId,\n promptRunUrl: `https://app.transcend.io/prompts/runs/${promptRunId}`,\n };\n }\n\n /**\n * Report an error for a particular prompt\n *\n * @param promptName - Prompt to parse\n * @param options - Options for reporting\n * @returns Parsed content\n */\n async reportPromptRunError<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n {\n largeLanguageModel,\n ...options\n }: Requirize<ReportPromptRunOptions, 'error'>,\n ): Promise<PromptRunResult> {\n // Determine if prompts need to be fetched\n if (\n // never been fetched\n !this.lastUpdatedAt ||\n // fetch every run\n this.cacheDuration === 0 ||\n // If cache duration met\n (this.cacheDuration &&\n Date.now() - this.lastUpdatedAt.getTime() > this.cacheDuration)\n ) {\n await this.fetchPromptsAndMetadata();\n }\n\n const name =\n options.name ||\n `@transcend-io/cli-prompt-run-${new Date().toISOString()}`;\n\n if (!this.promptContentMap) {\n throw new Error('Expected this.promptContentMap to be defined');\n }\n // Look up prompt info\n const promptInput = this.promptContentMap[promptName];\n if (!promptInput) {\n throw new Error(`Expected this.prompts[${promptName}] to be defined`);\n }\n\n // Ensure the first message in `promptRunMessages` is of type=system\n if (options.promptRunMessages.length === 0) {\n throw new Error('promptRunMessages is expected to have length > 0');\n }\n if (options.promptRunMessages[0].role !== ChatCompletionRole.System) {\n throw new Error(\n `promptRunMessages[0].role is expected to be = ${ChatCompletionRole.System}`,\n );\n }\n\n const promptRunId = await reportPromptRun(this.graphQLClient, {\n productArea: PromptRunProductArea.PromptManager,\n ...options,\n name,\n status: QueueStatus.Error,\n ...(typeof largeLanguageModel === 'string'\n ? { largeLanguageModelId: largeLanguageModel }\n : {\n largeLanguageModelName: largeLanguageModel.name,\n largeLanguageModelClient: largeLanguageModel.client,\n }),\n promptId: promptInput.id,\n promptRunMessages: options.promptRunMessages.map((message, ind) => ({\n ...message,\n ...(ind === 0 ? { template: promptInput.content } : {}),\n })),\n });\n\n return {\n promptRunId,\n promptRunUrl: `https://app.transcend.io/prompts/runs/${promptRunId}`,\n };\n }\n}\n/* eslint-enable max-lines */\n","/**\n * Remove links from a string\n *\n * @param inputString - String\n * @returns String without links\n */\nexport function removeLinks(inputString: string): string {\n const regex = /(https?:\\/\\/[^\\s]+)/g;\n return inputString.replace(regex, '<link-omitted>');\n}\n","import { ObjByString } from '@transcend-io/type-utils';\n\n/**\n * Given an object, remove all keys that are null-ish\n *\n * @param obj - Object\n * @returns Object with null-ish values removed\n */\nexport function filterNullishValuesFromObject<T extends ObjByString>(\n obj: T,\n): T {\n return Object.entries(obj).reduce(\n (acc, [k, v]) =>\n v !== null &&\n v !== undefined &&\n v !== '' &&\n !(Array.isArray(v) && v.length === 0) &&\n !(typeof v === 'object' && Object.keys(v).length === 0)\n ? Object.assign(acc, { [k]: v })\n : acc,\n {} as T,\n );\n}\n","import { difference } from 'lodash-es';\nimport fastGlob from 'fast-glob';\nimport { execSync } from 'child_process';\n\n/**\n * Function thats gets the git files that have changed\n * and returns the code\n *\n * @param options - Options\n * @returns Changes files and diffs\n */\nexport function getGitFilesThatChanged({\n baseBranch,\n rootDirectory,\n githubRepo,\n excludedGlob = [],\n fileBlockList = [],\n}: {\n /** Base branch */\n baseBranch: string;\n /** Github repo name */\n githubRepo: string;\n /** Root directory */\n rootDirectory: string;\n /** A glob that excludes files */\n excludedGlob?: string[];\n /** Block list of files to not process */\n fileBlockList?: string[];\n}): {\n /** The list of files that changed */\n changedFiles: string[];\n /** Github repo name */\n repoName: string;\n /** Current commit */\n commit: string;\n /** File diffs */\n fileDiffs: { [k in string]: string };\n} {\n // Pull base branch\n execSync(`git fetch origin ${baseBranch}`);\n\n // Latest commit on base branch. If we are on the base branch, we take the prior commit\n const latestBasedCommit = execSync(\n `git ls-remote ${githubRepo} \"refs/heads/${baseBranch}\" | cut -f 1`,\n { encoding: 'utf-8' },\n ).split('\\n')[0];\n\n // This commit\n const latestThisCommit = execSync('git rev-parse HEAD', {\n encoding: 'utf-8',\n }).split('\\n')[0];\n\n // Ensure commits are present\n if (!latestBasedCommit || !latestThisCommit) {\n throw new Error('FAILED TO FIND COMMIT RANGE');\n }\n\n // Get the diff between the given branch and base branch\n const diff = execSync(\n `git fetch && git diff --name-only \"${\n baseBranch || latestBasedCommit\n }...${latestThisCommit}\" -- ${rootDirectory}`,\n { encoding: 'utf-8' },\n );\n\n // Filter out block list\n const changedFiles = difference(\n diff.split('\\n').filter((f) => f),\n fileBlockList,\n );\n\n // Filter out globs\n const filteredChanges =\n excludedGlob.length > 0\n ? fastGlob.sync(changedFiles, { ignore: excludedGlob })\n : changedFiles;\n\n // Get the contents of only the changed files\n const fileDiffs: { [k in string]: string } = {};\n filteredChanges.forEach((file) => {\n const contents = execSync(`git show ${latestThisCommit}:${file}`, {\n encoding: 'utf-8',\n });\n fileDiffs[file] = contents;\n });\n\n // Pull the github repo name\n const repoName = githubRepo.split('/').pop()!.split('.')[0];\n\n return {\n changedFiles,\n fileDiffs,\n repoName,\n commit: latestThisCommit,\n };\n}\n"],"mappings":"yzBAgBA,MAAM,EAAY,GAQlB,eAAsB,EACpB,EAC+B,CAC/B,IAAM,EAA4C,EAAE,CAChD,EAAS,EAGT,EAAiB,GACrB,EAAG,CACD,GAAM,CACJ,oBAAqB,CAAE,UACrB,MAAMA,EAAAA,EAMP,EAAQC,EAAAA,GAAuB,CAChC,MAAO,GACP,SACD,CAAC,CACF,EAAoB,KAAK,GAAG,EAAM,CAClC,GAAU,GACV,EAAiB,EAAM,SAAW,SAC3B,GAET,OAAO,EAAoB,MAAM,EAAG,IAAM,EAAE,KAAK,cAAc,EAAE,KAAK,CAAC,CCiDzE,SAAgB,EAAkB,EAAyB,CACzD,OAAW,OAAO,IAAI,EAAQ,mBAAmB,EAAQ,GAAG,CAS9D,SAAgB,EAGd,EAA6B,C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js`);let t=require(`colors`);t=e.t(t);let n=require(`global-agent`),r=require(`undici`),i=require(`yargs-parser`);i=e.t(i);const a=console,{httpProxy:o=process.env.http_proxy}=(0,i.default)(process.argv.slice(2));o&&(a.info(t.default.green(`Initializing proxy: ${o}`)),process.env.GLOBAL_AGENT_HTTP_PROXY=o,(0,n.bootstrap)(),(0,r.setGlobalDispatcher)(new r.ProxyAgent(o))),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return a}});
2
- //# sourceMappingURL=logger-DQwEYtSS.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger-DQwEYtSS.cjs","names":["ProxyAgent"],"sources":["../src/logger.ts"],"sourcesContent":["import colors from 'colors';\nimport { bootstrap } from 'global-agent';\nimport { ProxyAgent, setGlobalDispatcher } from 'undici';\nimport yargs from 'yargs-parser';\n\nexport const logger = console;\n\n// When the proxy env var of flag is specified, initiate the proxy\nconst { httpProxy = process.env.http_proxy } = yargs(process.argv.slice(2));\nif (httpProxy) {\n logger.info(colors.green(`Initializing proxy: ${httpProxy}`));\n\n // Use global-agent, which overrides `request` based requests\n process.env.GLOBAL_AGENT_HTTP_PROXY = httpProxy;\n bootstrap();\n\n // Use undici, which overrides `fetch` based requests\n setGlobalDispatcher(new ProxyAgent(httpProxy));\n}\n"],"mappings":"8JAKA,MAAa,EAAS,QAGhB,CAAE,YAAY,QAAQ,IAAI,aAAA,EAAA,EAAA,SAAqB,QAAQ,KAAK,MAAM,EAAE,CAAC,CACvE,IACF,EAAO,KAAK,EAAA,QAAO,MAAM,uBAAuB,IAAY,CAAC,CAG7D,QAAQ,IAAI,wBAA0B,GACtC,EAAA,EAAA,YAAW,EAGX,EAAA,EAAA,qBAAoB,IAAIA,EAAAA,WAAW,EAAU,CAAC"}
@@ -1,2 +0,0 @@
1
- const e=require(`./chunk-Bmb41Sf3.cjs`),t=require(`./constants-gJm1eQH0.cjs`),n=require(`./syncConfigurationToTranscend-s-cjtUI3.cjs`),r=require(`./logger-DQwEYtSS.cjs`);let i=require(`@transcend-io/privacy-types`),a=require(`colors`);a=e.t(a);let o=require(`io-ts`);o=e.t(o);async function s({file:e,auth:o,sombraAuth:s,requestActions:c=[],concurrency:l=100,transcendUrl:u=t.a}){let d=n.ai(u,o),f=await n.ii(u,o,s);r.t.info(a.default.magenta(`Pulling manual enrichment requests, filtered for actions: ${c.join(`,`)}`));let p=await n.mr(d,{actions:c,statuses:[i.RequestStatus.Enriching]});await n.vr(d);let m=[];await n.As(p,async e=>{let t=await n.br(d,{requestId:e.id});if(t.filter(({status:e})=>e===`ACTION_REQUIRED`)){let r=await n._r(d,f,{requestId:e.id,skipSombraCheck:!0});m.push({...e,requestIdentifiers:r,requestEnrichers:t})}},{concurrency:l});let h=m.map(({attributeValues:e,requestIdentifiers:t,requestEnrichers:r,...i})=>({...i,...Object.entries(n.Fs(t,`name`)).reduce((e,[t,n])=>Object.assign(e,{[t]:n.map(({value:e})=>e).join(`,`)}),{}),...Object.entries(n.Fs(e,`attributeKey.name`)).reduce((e,[t,n])=>Object.assign(e,{[t]:n.map(({name:e})=>e).join(`,`)}),{})}));return await n.l(e,h,n.Ms(h.map(e=>Object.keys(e)).flat())),r.t.info(a.default.green(`Successfully wrote ${m.length} requests to file "${e}"`)),m}const c=`https://app.transcend.io/privacy-requests/incoming-requests/`,l=o.record(o.string,o.string);async function u(e,{id:t,...i},o,s){if(!t){let e=`Request ID must be provided to enricher request.${s?` Found error in row: ${s}`:``}`;throw r.t.error(a.default.red(e)),Error(e)}let l=t.toLowerCase(),u=Object.entries(i).reduce((e,[t,r])=>n.Ms(n.pi(r)).length===0?e:Object.assign(e,{[t]:n.Ms(n.pi(r)).map(e=>({value:t===`email`?e.toLowerCase():e}))}),{});try{return await e.post(`v1/enrich-identifiers`,{headers:{"x-transcend-request-id":l,"x-transcend-enricher-id":o},json:{enrichedIdentifiers:u}}).json(),r.t.error(a.default.green(`Successfully enriched request: ${c}${l}`)),!0}catch(e){if(typeof e.response.body==`string`&&e.response.body.includes(`Cannot update a resolved RequestEnricher`))return r.t.warn(a.default.magenta(`Skipped enrichment for request: ${c}${l}, request is no longer in the enriching phase.`)),!1;throw r.t.error(a.default.red(`Failed to enricher identifiers for request with id: ${c}${l} - ${e.message} - ${e.response.body}`)),e}}async function d({file:e,auth:i,sombraAuth:o,enricherId:s,markSilent:c,concurrency:d=100,transcendUrl:f=t.a}){let p=await n.ii(f,i,o),m=n.ai(f,i);r.t.info(a.default.magenta(`Reading "${e}" from disk`));let h=n.ui(e,l);r.t.info(a.default.magenta(`Enriching "${h.length}" privacy requests.`));let g=0,_=0,v=0;if(await n.As(h,async(e,t)=>{try{c&&(await n.i(m,n.Fo,{input:{id:e.id,isSilent:!0}}),r.t.info(a.default.magenta(`Mark request as silent mode - ${e.id}`))),await u(p,e,s,t)?g+=1:_+=1}catch{v+=1}},{concurrency:d}),r.t.info(a.default.green(`Successfully notified Transcend! \n Success count: ${g}.`)),_>0&&r.t.info(a.default.magenta(`Skipped count: ${_}.`)),v>0)throw r.t.info(a.default.red(`Error Count: ${v}.`)),Error(`Failed to enrich: ${v} requests.`);return h.length}Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return d}});
2
- //# sourceMappingURL=manual-enrichment-DTVJo7hP.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manual-enrichment-DTVJo7hP.cjs","names":["DEFAULT_TRANSCEND_API","buildTranscendGraphQLClient","createSombraGotInstance","fetchAllRequests","RequestStatus","validateSombraVersion","map","fetchAllRequestEnrichers","fetchAllRequestIdentifiers","groupBy","writeCsv","uniq","t","uniq","splitCsvToList","DEFAULT_TRANSCEND_API","createSombraGotInstance","buildTranscendGraphQLClient","readCsv","map","makeGraphQLRequest","UPDATE_PRIVACY_REQUEST"],"sources":["../src/lib/manual-enrichment/pullManualEnrichmentIdentifiersToCsv.ts","../src/lib/manual-enrichment/enrichPrivacyRequest.ts","../src/lib/manual-enrichment/pushManualEnrichmentIdentifiersFromCsv.ts"],"sourcesContent":["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 validateSombraVersion,\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 await validateSombraVersion(client);\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 skipSombraCheck: true,\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 type { Got } from 'got';\nimport * as t from 'io-ts';\nimport { logger } from '../../logger';\nimport { uniq } from 'lodash-es';\nimport colors from 'colors';\nimport { splitCsvToList } from '../requests/splitCsvToList';\n\nconst ADMIN_URL =\n 'https://app.transcend.io/privacy-requests/incoming-requests/';\n/**\n * Minimal set required to mark as completed\n */\nexport const EnrichPrivacyRequest = t.record(t.string, t.string);\n\n/** Type override */\nexport type EnrichPrivacyRequest = t.TypeOf<typeof EnrichPrivacyRequest>;\n\n/**\n * Upload identifiers to a privacy request or mark request as\n *\n * @param sombra - Sombra instance configured to make requests\n * @param request - Request to enricher\n * @param enricherId - The ID of the enricher being uploaded to\n * @param index - Index of request ID\n * @returns True if enriched successfully, false if skipped, throws error if failed\n */\nexport async function enrichPrivacyRequest(\n sombra: Got,\n { id: rawId, ...rest }: EnrichPrivacyRequest,\n enricherId: string,\n index?: number,\n): Promise<boolean> {\n if (!rawId) {\n // error\n const msg = `Request ID must be provided to enricher request.${\n index ? ` Found error in row: ${index}` : ''\n }`;\n logger.error(colors.red(msg));\n throw new Error(msg);\n }\n\n const id = rawId.toLowerCase();\n\n // Pull out the identifiers\n const enrichedIdentifiers = Object.entries(rest).reduce(\n (acc, [key, value]) => {\n const values = uniq(splitCsvToList(value));\n return values.length === 0\n ? acc\n : Object.assign(acc, {\n [key]: uniq(splitCsvToList(value)).map((val) => ({\n value: key === 'email' ? val.toLowerCase() : val,\n })),\n });\n },\n {} as Record<string, string[]>,\n );\n\n // Make the GraphQL request\n try {\n await sombra\n .post('v1/enrich-identifiers', {\n headers: {\n 'x-transcend-request-id': id,\n 'x-transcend-enricher-id': enricherId,\n },\n json: {\n enrichedIdentifiers,\n },\n })\n .json();\n\n logger.error(\n colors.green(`Successfully enriched request: ${ADMIN_URL}${id}`),\n );\n return true;\n } catch (err) {\n // skip if already enriched\n if (\n typeof err.response.body === 'string' &&\n err.response.body.includes('Cannot update a resolved RequestEnricher')\n ) {\n logger.warn(\n colors.magenta(\n `Skipped enrichment for request: ${ADMIN_URL}${id}, request is no longer in the enriching phase.`,\n ),\n );\n return false;\n }\n\n // error\n logger.error(\n colors.red(\n `Failed to enricher identifiers for request with id: ${ADMIN_URL}${id} - ${err.message} - ${err.response.body}`,\n ),\n );\n throw err;\n }\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"],"mappings":"oRAgCA,eAAsB,EAAqC,CACzD,OACA,OACA,aACA,iBAAiB,EAAE,CACnB,cAAc,IACd,eAAeA,EAAAA,GAc4B,CAE3C,IAAM,EAASC,EAAAA,GAA4B,EAAc,EAAK,CACxD,EAAS,MAAMC,EAAAA,GAAwB,EAAc,EAAM,EAAW,CAE5E,EAAA,EAAO,KACL,EAAA,QAAO,QACL,6DAA6D,EAAe,KAC1E,IACD,GACF,CACF,CAGD,IAAM,EAAc,MAAMC,EAAAA,GAAiB,EAAQ,CACjD,QAAS,EACT,SAAU,CAACC,EAAAA,cAAc,UAAU,CACpC,CAAC,CAEF,MAAMC,EAAAA,GAAsB,EAAO,CAGnC,IAAM,EAAiD,EAAE,CAGzD,MAAMC,EAAAA,GACJ,EACA,KAAO,IAAY,CAEjB,IAAM,EAAmB,MAAMC,EAAAA,GAAyB,EAAQ,CAC9D,UAAW,EAAQ,GACpB,CAAC,CAQF,GAL4B,EAAiB,QAC1C,CAAE,YAAa,IAAW,kBAC5B,CAGwB,CACvB,IAAM,EAAqB,MAAMC,EAAAA,GAC/B,EACA,EACA,CACE,UAAW,EAAQ,GACnB,gBAAiB,GAClB,CACF,CACD,EAAc,KAAK,CACjB,GAAG,EACH,qBACA,mBACD,CAAC,GAGN,CACE,cACD,CACF,CAED,IAAM,EAAO,EAAc,KACxB,CACC,kBACA,qBACA,mBACA,GAAG,MACE,CACL,GAAG,EAEH,GAAG,OAAO,QAAQC,EAAAA,GAAQ,EAAoB,OAAO,CAAC,CAAC,QACpD,EAAK,CAAC,EAAK,KACV,OAAO,OAAO,EAAK,EAChB,GAAM,EAAO,KAAK,CAAE,WAAY,EAAM,CAAC,KAAK,IAAI,CACl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,QAAO,QAAQ,kBAAkB,EAAa,GAAG,CAAC,CAG5D,EAAa,EAEf,MADA,EAAA,EAAO,KAAK,EAAA,QAAO,IAAI,gBAAgB,EAAW,GAAG,CAAC,CAC5C,MAAM,qBAAqB,EAAW,YAAY,CAG9D,OAAO,EAAc"}
@@ -1,2 +0,0 @@
1
- const e=require(`./chunk-Bmb41Sf3.cjs`);let t=require(`@transcend-io/type-utils`);function n(e,...n){let r=JSON.parse(JSON.stringify(e));return n.forEach(e=>{(0,t.getEntries)(e).forEach(([e,t])=>{r[e]===void 0?r[e]=t:Array.isArray(t)?r[e]=[...r[e],...t]:r[e]=t})}),r}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n}});
2
- //# sourceMappingURL=mergeTranscendInputs-BIBCYbug.cjs.map
@@ -1,23 +0,0 @@
1
- const e=require(`./chunk-Bmb41Sf3.cjs`),t=require(`./constants-gJm1eQH0.cjs`),n=require(`./syncConfigurationToTranscend-s-cjtUI3.cjs`),r=require(`./logger-DQwEYtSS.cjs`);let i=require(`node:fs`),a=require(`node:os`),o=require(`node:path`),s=require(`colors`);s=e.t(s);let c=require(`node:child_process`),l=require(`node:readline`);l=e.t(l);function u(e,t){let n=Math.max(1,a.availableParallelism?.()??1);return{poolSize:typeof e==`number`&&e>0?Math.min(e,t):Math.min(n,t),cpuCount:n}}function d(e){return`'${String(e).replace(/'/g,`'\\''`)}'`}function f(e,t,n=!1){if(n)return;let i=(0,a.platform)();try{if(i===`darwin`){(0,c.spawn)(`osascript`,[`-e`,`
2
- tell application "Terminal"
3
- activate
4
- do script "printf '\\e]0;${t}\\a'; tail -n +1 -f ${e.map(d).join(` -f `)}"
5
- end tell
6
- `],{stdio:`ignore`,detached:!0});return}if(i===`win32`){(0,c.spawn)(`cmd.exe`,[`/c`,`start`,...[`powershell`,`-NoExit`,`-Command`,`Write-Host '${t}'; $paths = ${`@(${e.map(e=>`'${e.replace(/'/g,`''`)}'`).join(`,`)})`}; Get-Content -Path $paths -Tail 200 -Wait`]],{stdio:`ignore`,detached:!0}).unref();return}let n=e.map(d).join(` -f `);try{(0,c.spawn)(`gnome-terminal`,[`--`,`bash`,`-lc`,`printf '\\e]0;${t}\\a'; tail -n +1 -f ${n}`],{stdio:`ignore`,detached:!0}).unref()}catch{(0,c.spawn)(`xterm`,[`-title`,t,`-e`,`tail -n +1 -f ${e.join(` `)}`],{stdio:`ignore`,detached:!0}).unref()}}catch(e){throw r.t.error(s.default.red(`Failed to open terminal window for tailing logs: ${e instanceof Error?e.message:String(e)}`)),e}}function p(e){(0,i.existsSync)(e)||(0,i.closeSync)((0,i.openSync)(e,`a`))}function m(e,t){let n=[/worker-\d+\.log$/,/worker-\d+\.out\.log$/,/worker-\d+\.err\.log$/,/worker-\d+\.warn\.log$/,/worker-\d+\.info\.log$/];for(let r of(0,i.readdirSync)(e)){if(!n.some(e=>e.test(r)))continue;let a=(0,o.join)(e,r);try{t===`delete`&&(0,i.existsSync)(a)?(0,i.unlinkSync)(a):(0,i.writeFileSync)(a,``)}catch{}}process.stdout.write(s.default.dim(`Logs have been ${t===`delete`?`deleted`:`truncated`} in ${e}\n`))}function h(e){let t=e.replace(/\x1B\[[0-9;]*m/g,``),n=/\[w\d+\]\s+(ERROR|WARN)\b/i.exec(t);if(n)return n[1].toLowerCase();if(/^\s*(ERROR|ERR|FATAL)\b/i.test(t))return`error`;if(/^\s*(WARN|WARNING)\b/.test(t)||/^\s*\(node:\d+\)\s*Warning:/i.test(t)||/^\s*DeprecationWarning:/i.test(t))return`warn`;try{let e=JSON.parse(t)?.level;if(typeof e==`number`){if(e>=50)return`error`;if(e>=40)return`warn`}else if(typeof e==`string`){let t=e.toLowerCase();if(t===`error`||t===`fatal`)return`error`;if(t===`warn`||t===`warning`)return`warn`}}catch{}let r=/\[w\d+\].*\b(WARN|WARNING|ERROR|FATAL)\b/i.exec(t);if(r){let e=r[1].toUpperCase();return e===`ERROR`||e===`FATAL`?`error`:`warn`}return null}function g(e){let t=``;return n=>{t+=n.toString(`utf8`);let r;for(;(r=t.indexOf(`
7
- `))!==-1;)e(t.slice(0,r)),t=t.slice(r+1)}}function _(e){let t=(0,o.join)(e,`logs`);return(0,i.mkdirSync)(t,{recursive:!0}),m(t,process.env.RESET_LOGS??`truncate`),t}const v=`--as-child`,y=Symbol(`workerLogPaths`);function b(e){return e[y]}function x(e){let t=e&&e.channel;return!!(e&&e.connected&&t&&!t.destroyed)}function S(e,t){if(!x(e))return!1;try{return e.send?.(t),!0}catch(e){if(e?.code===`ERR_IPC_CHANNEL_CLOSED`||e?.code===`EPIPE`||e?.errno===-32)return!1;throw e}}function C(e){let{id:t,modulePath:n,logDir:r,openLogWindows:a,isSilent:s,childFlag:l=v}=e,u=(0,o.join)(r,`worker-${t}.log`),d=(0,o.join)(r,`worker-${t}.out.log`),m=(0,o.join)(r,`worker-${t}.err.log`),_=(0,o.join)(r,`worker-${t}.info.log`),b=(0,o.join)(r,`worker-${t}.warn.log`),x=(0,o.join)(r,`worker-${t}.error.log`);[u,d,m,_,b,x].forEach(p);let S=(0,c.fork)(n,[l],{stdio:[`pipe`,`pipe`,`pipe`,`ipc`],env:{...process.env,WORKER_ID:String(t),WORKER_LOG:u},execArgv:process.execArgv,silent:s}),C=(0,i.createWriteStream)(d,{flags:`a`}),w=(0,i.createWriteStream)(m,{flags:`a`}),T=(0,i.createWriteStream)(_,{flags:`a`}),E=(0,i.createWriteStream)(b,{flags:`a`}),D=(0,i.createWriteStream)(x,{flags:`a`});S.stdout?.pipe(C),S.stderr?.pipe(w);let O=e=>`[parent] ${e} capture active for w${t} (pid ${S.pid})\n`;if(C.write(O(`stdout`)),w.write(O(`stderr`)),T.write(O(`info`)),E.write(O(`warn`)),D.write(O(`error`)),S.stdout){let e=g(e=>{if(e)try{T.write(`${e}\n`)}catch{}});S.stdout.on(`data`,e)}if(S.stderr){let e=g(e=>{if(!e)return;let t=h(e);try{t===`error`?D.write(`${e}\n`):E.write(`${e}\n`)}catch{}});S.stderr.on(`data`,e)}return S[y]={structuredPath:u,outPath:d,errPath:m,infoPath:_,warnPath:b,errorPath:x},a&&f([u,d,m,_,b,x],`worker-${t}`,s),C.on(`error`,()=>{}),w.on(`error`,()=>{}),T.on(`error`,()=>{}),E.on(`error`,()=>{}),D.on(`error`,()=>{}),S}function w(e,t,n){process.stdout.write(`\x1B[2J\x1B[H`);let r=e=>/\b(ERROR|uncaughtException|unhandledRejection)\b/i.test(e),a=e=>/\b(WARN|WARNING)\b/i.test(e),o=[];for(let[,s]of e){if(!s)continue;let e=[];for(let n of t)n===`out`&&s.outPath&&e.push({path:s.outPath,src:`out`}),n===`err`&&s.errPath&&e.push({path:s.errPath,src:`err`}),n===`structured`&&s.structuredPath&&e.push({path:s.structuredPath,src:`structured`}),s.warnPath&&n===`warn`&&e.push({path:s.warnPath,src:`warn`}),s.infoPath&&n===`info`&&e.push({path:s.infoPath,src:`info`});for(let{path:t,src:s}of e){let e=``;try{e=(0,i.readFileSync)(t,`utf8`)}catch{continue}for(let t of e.split(`
8
- `)){if(!t)continue;let e=t.replace(/\x1B\[[0-9;]*m/g,``);if(n===`all`){o.push(t);continue}if(n===`error`){r(e)&&o.push(t);continue}if(a(e)||s===`err`&&!r(e)){o.push(t);continue}}}}o.sort((e,t)=>{let n=e.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/)?.[0]??``,r=t.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/)?.[0]??``;return n.localeCompare(r)}),process.stdout.write(`${o.join(`
9
- `)}\n`),process.stdout.write(`
10
- Press Esc/Ctrl+] to return to dashboard.
11
- `)}async function T(e,t,n){await new Promise(r=>{try{let a=(0,i.statSync)(e),o=(0,i.createReadStream)(e,{start:Math.max(0,a.size-t),encoding:`utf8`});o.on(`data`,e=>n(e)),o.on(`end`,r),o.on(`error`,r)}catch{r(void 0)}})}function E(e,t,n){if(t.ctrl&&t.name===`c`)return{type:`CTRL_C`};if(n===`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=t.sequence??e??``;return r?{type:`FORWARD`,sequence:r}:null}function D(e){return[...e.keys()].sort((e,t)=>e-t)}function O(e,t,n){if(!e.length)return null;let r=t??e[0],i=e.indexOf(r);return i===-1&&(i=0),i=(i+n+e.length)%e.length,e[i]}function k(e){let{workers:n,onAttach:r,onDetach:i,onCtrlC:a,getLogPaths:o,replayBytes:s=200*1024,replayWhich:c=[`out`,`err`],onEnterAttachScreen:u,ports:d}=e,f=d?.stdin??process.stdin,p=d?.stdout??process.stdout,m=d?.stderr??process.stderr,h=(...e)=>{if(t.i)try{(d?.stderr??process.stderr).write(`[keys] ${e.map(String).join(` `)}\n`)}catch{}};if(!f.isTTY)return()=>{};l.emitKeypressEvents(f),f.setRawMode?.(!0);let g=`dashboard`,_=null,v=null,y=null;async function b(e){if(!o)return;let t=o(e);if(!t)return;let n=[];for(let e of c)e===`out`&&n.push(t.outPath),e===`err`&&n.push(t.errPath),e===`structured`&&n.push(t.structuredPath);if(n.length){p.write(`
12
- ------------ replay ------------
13
- `);for(let e of n)p.write(`\n--- ${e} (last ~${Math.floor(s/1024)}KB) ---\n`),await T(e,s,e=>p.write(e));p.write(`
14
- --------------------------------
15
-
16
- `)}}let x=async e=>{h(`attach()`,`id=${e}`);let t=n.get(e);t&&(g===`attached`&&S(),g=`attached`,_=e,u?.(e),r?.(e),await b(e),v=e=>p.write(e),y=e=>m.write(e),t.stdout?.on(`data`,v),t.stderr?.on(`data`,y),t.once(`exit`,()=>{_===e&&S()}))},S=()=>{if(h(`detach()`,`id=${_}`),_==null)return;let e=_,t=n.get(e);t&&(v&&t.stdout?.off(`data`,v),y&&t.stderr?.off(`data`,y)),v=null,y=null,_=null,g=`dashboard`,i?.()},C=(e,t)=>{h(`keypress`,JSON.stringify({str:e,name:t.name,seq:t.sequence,ctrl:t.ctrl,meta:t.meta,shift:t.shift,mode:g}));let r=E(e,t,g);if(h(`mapped`,JSON.stringify(r)),r)switch(r.type){case`CTRL_C`:if(h(`CTRL_C`),g===`attached`&&_!=null){let e=n.get(_);try{e?.kill(`SIGINT`)}catch{}S();return}a?.();return;case`ATTACH`:if(h(`ATTACH`,`id=${r.id}`,`has=${n.has(r.id)}`),g!==`dashboard`)return;n.has(r.id)&&x(r.id);return;case`CYCLE`:{if(h(`CYCLE`,`delta=${r.delta}`),g!==`dashboard`)return;let e=O(D(n),_,r.delta);e!=null&&x(e);return}case`QUIT`:if(g!==`dashboard`)return;a?.();return;case`DETACH`:h(`DETACH`),g===`attached`&&S();return;case`CTRL_D`:if(g===`attached`&&_!=null){let e=n.get(_);try{e?.stdin?.end()}catch{}}return;case`FORWARD`:if(g===`attached`&&_!=null){let e=n.get(_);try{e?.stdin?.write(r.sequence)}catch{}}}},w=e=>{if(g===`attached`&&_!=null){let t=n.get(_);try{t?.stdin?.write(e)}catch{}}};return f.on(`keypress`,C),f.on(`data`,w),()=>{f.off(`keypress`,C),f.off(`data`,w),f.setRawMode?.(!1),p.write(`\x1B[?25h`)}}let A=``;const j=(e,t)=>{let n=Math.min(e-1,9),r=e<=1?`0`:`0-${n}`,i=e>10?` (Tab/Shift+Tab for ≥10)`:``;return t?s.default.dim(`Run complete — digits to view logs • Tab/Shift+Tab cycle • Esc/Ctrl+] detach • q to quit`):s.default.dim(`Hotkeys: [${r}] attach${i} • e=errors • w=warnings • i=info • l=logs • Tab/Shift+Tab • Esc/Ctrl+] detach • Ctrl+C exit`)};function M(e,t,n=!1){let r=[...t.renderHeader(e),``,...t.renderWorkers(e),...n?[]:[``,j(e.poolSize,e.final)],...t.renderExtras?[``].concat(t.renderExtras(e)):[]].join(`
17
- `);!e.final&&r===A||(A=r,e.final?process.stdout.write(`\x1B[?25h`):(process.stdout.write(`\x1B[?25l`),l.cursorTo(process.stdout,0,0),l.clearScreenDown(process.stdout)),process.stdout.write(`${r}\n`))}function N(e,t,n){let r=t.get(e);if(x(r))try{let e=b(r);if(e!=null)return e}catch{}return n.get(e)}function P(e){return typeof e==`number`?e.toLocaleString():`0`}function F(e,t=40){let n=Math.max(0,Math.min(100,Math.floor(e))),r=Math.floor(n/100*t);return`█`.repeat(r)+`░`.repeat(t-r)}function I(e){let t=[...e.workerState.values()].filter(e=>e.busy).length,n=e.filesCompleted+e.filesFailed;return{done:n,inProgress:t,pct:e.filesTotal===0?100:Math.floor(n/Math.max(1,e.filesTotal)*100)}}function L(e,t=[]){let{title:n,poolSize:r,cpuCount:i,filesTotal:a,filesCompleted:o,filesFailed:c,throughput:l}=e,{inProgress:u,pct:d}=I(e),f=[`${s.default.bold(n)} — ${r} workers ${s.default.dim(`(CPU avail: ${i})`)}`,`${s.default.dim(`Files`)} ${P(a)} ${s.default.dim(`Completed`)} ${P(o)} ${s.default.dim(`Failed`)} ${c?s.default.red(P(c)):P(c)} ${s.default.dim(`In-flight`)} ${P(u)}`,`[${F(d)}] ${d}%`];if(l){let t=l.jobsR10s>0||l.jobsR60s>0,n=Math.round((t?l.jobsR10s:l.r10s)*3600).toLocaleString(),r=Math.round((t?l.jobsR60s:l.r60s)*3600).toLocaleString(),i=t?`rec`:`files`,a=e.throughput?.successSoFar==null?``:` Newly uploaded: ${P(e.throughput.successSoFar)}`;f.push(s.default.cyan(`Throughput: ${n} ${i}/hr (1h: ${r} ${i}/hr)${a}`))}return t.length?f.concat(t):f}function R(e,t=e=>e?(0,o.basename)(e):`-`){return[...e.workerState.entries()].map(([e,n])=>{let r=n.lastLevel===`error`?s.default.red(`ERROR `):n.lastLevel===`warn`?s.default.yellow(`WARN `):n.busy?s.default.green(`WORKING`):s.default.dim(`IDLE `),i=t(n.file),a=n.startedAt?`${Math.floor((Date.now()-n.startedAt)/1e3)}s`:`-`,o=n.progress?.processed??0,c=n.progress?.total??0,l=c>0?Math.floor(o/c*100):0;return` [w${e}] ${r} | ${i} | ${a} | [${c>0?F(l,18):` `.repeat(18)}] ${c>0?`${o.toLocaleString()}/${c.toLocaleString()} (${l}%)`:s.default.dim(`—`)}`})}async function z(e){let{title:t,baseDir:r,poolSize:i,cpuCount:a,render:o,childModulePath:c,hooks:l,filesTotal:u,childFlag:d,viewerMode:f=!1}=e,p=e.openLogWindows??!f,m=e.isSilent??!0,v=Date.now(),y=_(r),w=new Map,T=new Map,E=new Map,D=new n.C,O=new n.C,A=new Map,j=l.initTotals?.()??{},M=0,P=0,F=0,I=null,L=!1,R=!1,z=null,B=(e=!1)=>{R||o({title:t,poolSize:i,cpuCount:a,filesTotal:u,filesCompleted:P,filesFailed:F,workerState:T,totals:j,final:e,exportStatus:l.exportStatus?.(),throughput:{successSoFar:P,r10s:D.rate(1e4),r60s:D.rate(6e4),jobsR10s:O.rate(1e4),jobsR60s:O.rate(6e4)}})},V=e=>{let t=l.nextTask();if(!t)return!1;let n=w.get(e),r=l.taskLabel(t),i=l.initSlotProgress?.(t);return T.set(e,{busy:!0,file:r,startedAt:Date.now(),lastLevel:`ok`,progress:i}),S(n,{type:`task`,payload:t}),B(),!0};for(let e=0;e<i;e+=1){let t=C({id:e,modulePath:c,logDir:y,openLogWindows:p,isSilent:m,childFlag:d});w.set(e,t),T.set(e,{busy:!1,file:null,startedAt:null,lastLevel:`ok`}),E.set(e,b(t)),M+=1;let n=g(t=>{let n=h(t);if(!n)return;let r=T.get(e);r.lastLevel!==n&&(T.set(e,{...r,lastLevel:n}),B())});t.stderr?.on(`data`,n),t.on(`message`,n=>{if(!(!n||typeof n!=`object`)){if(n.type===`ready`){L||(L=!0,I=setInterval(()=>B(!1),350)),V(e);return}if(n.type===`progress`){j=l.onProgress(j,n.payload);let t=T.get(e);T.set(e,{...t,progress:n.payload});let r=n.payload;if(typeof r?.processed==`number`){let t=A.get(e)??0,n=r.processed-t;n>0&&O.add(n),A.set(e,r.processed)}B();return}if(n.type===`result`){let r=T.get(e),{totals:i,ok:a}=l.onResult(j,n.payload);j=i,a?(P+=1,D.add(1)):F+=1,T.set(e,{...r,busy:!1,file:null,progress:void 0,lastLevel:a?`ok`:`error`}),A.delete(e),!V(e)&&x(t)&&S(t,{type:`shutdown`}),B()}}}),t.on(`exit`,()=>{--M,M===0&&(I&&clearInterval(I),B(!0))})}let H=()=>{},U=()=>{try{process.stdin.setRawMode?.(!1)}catch{}try{process.stdin.pause()}catch{}},W=()=>{if(I&&clearInterval(I),H?.(),z)try{process.stdin.off(`data`,z)}catch{}U(),process.stdout.write(`
18
- Stopping workers...
19
- `);for(let[,e]of w){x(e)&&S(e,{type:`shutdown`});try{e?.kill(`SIGTERM`)}catch{}}process.exit(130)},G=e=>{R=!0,process.stdout.write(`\x1B[2J\x1B[H`),process.stdout.write(`Attached to worker ${e}. (Esc/Ctrl+] detach • Ctrl+D EOF • Ctrl+C SIGINT)\n`)},K=()=>{R=!1,B()};if(process.once(`SIGINT`,W),!f){if(process.stdin.isTTY){try{process.stdin.setRawMode(!0)}catch{process.stdout.write(s.default.yellow(`Warning: Unable to enable raw mode for interactive key handling.
20
- `))}process.stdin.resume()}H=k({workers:w,onAttach:G,onDetach:K,onCtrlC:W,getLogPaths:e=>N(e,w,E),replayBytes:200*1024,replayWhich:[`out`,`err`],onEnterAttachScreen:G}),e.extraKeyHandler&&(z=e.extraKeyHandler({logsBySlot:E,repaint:()=>B(),setPaused:e=>{R=e}}),process.stdin.on(`data`,z))}await new Promise(e=>{let t=setInterval(async()=>{if(M===0){if(clearInterval(t),I&&clearInterval(I),H(),z)try{process.stdin.off(`data`,z)}catch{}U();let n=Date.now();try{await l.postProcess?.({slots:T,totals:j,logDir:y,logsBySlot:E,startedAt:v,finishedAt:n,viewerMode:f,getLogPathsForSlot:e=>N(e,w,E)})}catch(e){let t=e?.stack??String(e);process.stdout.write(s.default.red(`postProcess error: ${t}\n`))}e()}},300)})}function B(e){let{logsBySlot:t,repaint:n,setPaused:r,exportMgr:i,exportStatus:a,custom:o}=e,s=e=>{process.stdout.write(`${e}\n`)},c=(e,t)=>{let r=Date.now(),i=a?.[e]??{path:t};a&&(a[e]={path:t||i.path,savedAt:r,exported:!0},n())},l=!1,u=(e,i)=>{l||(l=!0,r(!0),process.stdout.write(`\x1B[2J\x1B[H`),process.stdout.write(`Combined logs viewer (press Esc or Ctrl+] to return)
21
-
22
- `),(async()=>{try{await w(t,e,i)}catch{l=!1,r(!1),n()}})())},d=(e,n)=>{if(i)try{let r=i.exportCombinedLogs(t,e);s(`\nWrote combined ${n} logs to: ${r}`),c(e,r)}catch{s(`\nFailed to write combined ${n} logs`)}};return e=>{let t=e.toString(`utf8`);if(t===`e`){u([`err`],`error`);return}if(t===`w`){u([`warn`,`err`],`warn`);return}if(t===`i`){u([`info`],`all`);return}if(t===`l`){u([`out`,`err`,`structured`],`all`);return}if(t===`E`){d(`error`,`error`);return}if(t===`W`){d(`warn`,`warn`);return}if(t===`I`){d(`info`,`info`);return}if(t===`A`){d(`all`,`ALL`);return}let i=o?.[t];if(i){i({noteExport:c,say:s});return}(t===`\x1B`||t===``)&&(l=!1,r(!1),n())}}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return B}});
23
- //# sourceMappingURL=pooling-C-TYBnHI.cjs.map