@transcend-io/cli 10.0.0 → 10.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.
- package/dist/{app-By_zDIkK.mjs → app-BfTrk2nc.mjs} +19 -19
- package/dist/{app-By_zDIkK.mjs.map → app-BfTrk2nc.mjs.map} +1 -1
- package/dist/{approvePrivacyRequests-1cguqGqq.mjs → approvePrivacyRequests-CWGZR2N6.mjs} +2 -2
- package/dist/{approvePrivacyRequests-1cguqGqq.mjs.map → approvePrivacyRequests-CWGZR2N6.mjs.map} +1 -1
- package/dist/bin/bash-complete.mjs +1 -1
- package/dist/bin/cli.mjs +1 -1
- package/dist/bin/deprecated-command.mjs +1 -1
- package/dist/{buildXdiSyncEndpoint-BMaMHO7Z.mjs → buildXdiSyncEndpoint-Cb-pvpak.mjs} +2 -2
- package/dist/{buildXdiSyncEndpoint-BMaMHO7Z.mjs.map → buildXdiSyncEndpoint-Cb-pvpak.mjs.map} +1 -1
- package/dist/{bulkRestartRequests-DEPSHov-.mjs → bulkRestartRequests-CKF_xpN0.mjs} +2 -2
- package/dist/{bulkRestartRequests-DEPSHov-.mjs.map → bulkRestartRequests-CKF_xpN0.mjs.map} +1 -1
- package/dist/{bulkRetryEnrichers-BLkcFKXC.mjs → bulkRetryEnrichers-B-Szmin-.mjs} +2 -2
- package/dist/{bulkRetryEnrichers-BLkcFKXC.mjs.map → bulkRetryEnrichers-B-Szmin-.mjs.map} +1 -1
- package/dist/{cancelPrivacyRequests-C8MZQvsq.mjs → cancelPrivacyRequests-DNiL13E_.mjs} +2 -2
- package/dist/{cancelPrivacyRequests-C8MZQvsq.mjs.map → cancelPrivacyRequests-DNiL13E_.mjs.map} +1 -1
- package/dist/{command-BUnCUxva.mjs → command-BXxoAjFo.mjs} +2 -2
- package/dist/{command-BUnCUxva.mjs.map → command-BXxoAjFo.mjs.map} +1 -1
- package/dist/{createExtraKeyHandler-C_0EVj10.mjs → createExtraKeyHandler-tubeaEjA.mjs} +2 -2
- package/dist/createExtraKeyHandler-tubeaEjA.mjs.map +1 -0
- package/dist/{createPreferenceAccessTokens-6WLr6z-l.mjs → createPreferenceAccessTokens-DqmFctn3.mjs} +2 -2
- package/dist/{createPreferenceAccessTokens-6WLr6z-l.mjs.map → createPreferenceAccessTokens-DqmFctn3.mjs.map} +1 -1
- package/dist/{createSombraGotInstance-CahOgD6V.mjs → createSombraGotInstance-D1Il9zUE.mjs} +2 -2
- package/dist/{createSombraGotInstance-CahOgD6V.mjs.map → createSombraGotInstance-D1Il9zUE.mjs.map} +1 -1
- package/dist/{downloadPrivacyRequestFiles-B2yduagB.mjs → downloadPrivacyRequestFiles-DlpgxqHF.mjs} +2 -2
- package/dist/{downloadPrivacyRequestFiles-B2yduagB.mjs.map → downloadPrivacyRequestFiles-DlpgxqHF.mjs.map} +1 -1
- package/dist/{fetchAllActions-C0l3wjQV.mjs → fetchAllActions-BJsPdnxy.mjs} +2 -2
- package/dist/{fetchAllActions-C0l3wjQV.mjs.map → fetchAllActions-BJsPdnxy.mjs.map} +1 -1
- package/dist/{fetchAllDataFlows-AQ9j_NRa.mjs → fetchAllDataFlows-D248lO6_.mjs} +2 -2
- package/dist/{fetchAllDataFlows-AQ9j_NRa.mjs.map → fetchAllDataFlows-D248lO6_.mjs.map} +1 -1
- package/dist/{fetchAllPreferenceTopics-Bn9PG-rO.mjs → fetchAllPreferenceTopics-ForE9GpZ.mjs} +2 -2
- package/dist/{fetchAllPreferenceTopics-Bn9PG-rO.mjs.map → fetchAllPreferenceTopics-ForE9GpZ.mjs.map} +1 -1
- package/dist/{fetchAllPurposes-CykSkZRY.mjs → fetchAllPurposes-ZdkO2fMp.mjs} +2 -2
- package/dist/{fetchAllPurposes-CykSkZRY.mjs.map → fetchAllPurposes-ZdkO2fMp.mjs.map} +1 -1
- package/dist/fetchAllPurposesAndPreferences-DD6OyA5t.mjs +2 -0
- package/dist/{fetchAllPurposesAndPreferences-Dog6N9L2.mjs.map → fetchAllPurposesAndPreferences-DD6OyA5t.mjs.map} +1 -1
- package/dist/{fetchAllRequestEnrichers-q34mRuE5.mjs → fetchAllRequestEnrichers-CK-kk5eg.mjs} +2 -2
- package/dist/{fetchAllRequestEnrichers-q34mRuE5.mjs.map → fetchAllRequestEnrichers-CK-kk5eg.mjs.map} +1 -1
- package/dist/{fetchAllRequestIdentifiers-YP-geTV4.mjs → fetchAllRequestIdentifiers-DrFFOt0m.mjs} +2 -2
- package/dist/{fetchAllRequestIdentifiers-YP-geTV4.mjs.map → fetchAllRequestIdentifiers-DrFFOt0m.mjs.map} +1 -1
- package/dist/{fetchAllRequests-DEPTEUbi.mjs → fetchAllRequests-DNQQsY4s.mjs} +2 -2
- package/dist/{fetchAllRequests-DEPTEUbi.mjs.map → fetchAllRequests-DNQQsY4s.mjs.map} +1 -1
- package/dist/{fetchApiKeys-DkBco7W0.mjs → fetchApiKeys-DjOr44xA.mjs} +2 -2
- package/dist/{fetchApiKeys-DkBco7W0.mjs.map → fetchApiKeys-DjOr44xA.mjs.map} +1 -1
- package/dist/{fetchCatalogs-CBk871k6.mjs → fetchCatalogs-BM4FCbcS.mjs} +2 -2
- package/dist/{fetchCatalogs-CBk871k6.mjs.map → fetchCatalogs-BM4FCbcS.mjs.map} +1 -1
- package/dist/{fetchConsentManagerId-DHDA5Py9.mjs → fetchConsentManagerId-CFkg3-RS.mjs} +2 -2
- package/dist/{fetchConsentManagerId-DHDA5Py9.mjs.map → fetchConsentManagerId-CFkg3-RS.mjs.map} +1 -1
- package/dist/{fetchIdentifiers-DjqjUnaw.mjs → fetchIdentifiers-pjQV4vUg.mjs} +2 -2
- package/dist/{fetchIdentifiers-DjqjUnaw.mjs.map → fetchIdentifiers-pjQV4vUg.mjs.map} +1 -1
- package/dist/{fetchRequestDataSilo-CF6XOTQ-.mjs → fetchRequestDataSilo-P4yA7Lyc.mjs} +2 -2
- package/dist/{fetchRequestDataSilo-CF6XOTQ-.mjs.map → fetchRequestDataSilo-P4yA7Lyc.mjs.map} +1 -1
- package/dist/{fetchRequestFilesForRequest-DrHGOdih.mjs → fetchRequestFilesForRequest-BbxrEKFK.mjs} +2 -2
- package/dist/{fetchRequestFilesForRequest-DrHGOdih.mjs.map → fetchRequestFilesForRequest-BbxrEKFK.mjs.map} +1 -1
- package/dist/{generateCrossAccountApiKeys-F11uqpc5.mjs → generateCrossAccountApiKeys-Bxc_dzMG.mjs} +2 -2
- package/dist/{generateCrossAccountApiKeys-F11uqpc5.mjs.map → generateCrossAccountApiKeys-Bxc_dzMG.mjs.map} +1 -1
- package/dist/{impl-0ooudQ_J2.mjs → impl-4ltdSmpl2.mjs} +2 -2
- package/dist/{impl-0ooudQ_J2.mjs.map → impl-4ltdSmpl2.mjs.map} +1 -1
- package/dist/{impl-BzupMfJi.mjs → impl-B19fH75P.mjs} +2 -2
- package/dist/{impl-BzupMfJi.mjs.map → impl-B19fH75P.mjs.map} +1 -1
- package/dist/{impl-CdoTu8TH.mjs → impl-BBMjv5YQ.mjs} +2 -2
- package/dist/{impl-CdoTu8TH.mjs.map → impl-BBMjv5YQ.mjs.map} +1 -1
- package/dist/{impl-Cwj9LeEI.mjs → impl-BKH3QRLi.mjs} +2 -2
- package/dist/{impl-Cwj9LeEI.mjs.map → impl-BKH3QRLi.mjs.map} +1 -1
- package/dist/{impl-KV3yZaHz2.mjs → impl-BOUm7wly2.mjs} +2 -2
- package/dist/{impl-KV3yZaHz2.mjs.map → impl-BOUm7wly2.mjs.map} +1 -1
- package/dist/{impl-r8tHyAHB.mjs → impl-BUC4ZelU.mjs} +2 -2
- package/dist/{impl-r8tHyAHB.mjs.map → impl-BUC4ZelU.mjs.map} +1 -1
- package/dist/{impl-dEQtD5uE.mjs → impl-BhTCp0kg.mjs} +2 -2
- package/dist/{impl-dEQtD5uE.mjs.map → impl-BhTCp0kg.mjs.map} +1 -1
- package/dist/{impl-f4UPMoS_2.mjs → impl-BlHU1bbJ2.mjs} +2 -2
- package/dist/{impl-f4UPMoS_2.mjs.map → impl-BlHU1bbJ2.mjs.map} +1 -1
- package/dist/{impl-CXK-D84c.mjs → impl-BwjguKHC.mjs} +2 -2
- package/dist/{impl-CXK-D84c.mjs.map → impl-BwjguKHC.mjs.map} +1 -1
- package/dist/{impl-VHp2K2bg.mjs → impl-C2o0eDzJ.mjs} +2 -2
- package/dist/{impl-VHp2K2bg.mjs.map → impl-C2o0eDzJ.mjs.map} +1 -1
- package/dist/{impl-2FbPcOv_2.mjs → impl-C8HKnjw82.mjs} +2 -2
- package/dist/{impl-2FbPcOv_2.mjs.map → impl-C8HKnjw82.mjs.map} +1 -1
- package/dist/{impl-CMX0qQr_2.mjs → impl-CCUsnhoW2.mjs} +2 -2
- package/dist/{impl-CMX0qQr_2.mjs.map → impl-CCUsnhoW2.mjs.map} +1 -1
- package/dist/{impl-B8iVBYdg.mjs → impl-CCc-wXqD.mjs} +2 -2
- package/dist/{impl-B8iVBYdg.mjs.map → impl-CCc-wXqD.mjs.map} +1 -1
- package/dist/{impl-ArGeiHuz.mjs → impl-CMmyv1cl.mjs} +2 -2
- package/dist/{impl-ArGeiHuz.mjs.map → impl-CMmyv1cl.mjs.map} +1 -1
- package/dist/{impl-1U4QBT_L.mjs → impl-CNez1OAw.mjs} +2 -2
- package/dist/impl-CNez1OAw.mjs.map +1 -0
- package/dist/{impl-DZnSlfwn2.mjs → impl-CNykdy3e2.mjs} +2 -2
- package/dist/{impl-DZnSlfwn2.mjs.map → impl-CNykdy3e2.mjs.map} +1 -1
- package/dist/{impl--Lmj1RHh2.mjs → impl-CSChmq_t2.mjs} +2 -2
- package/dist/{impl--Lmj1RHh2.mjs.map → impl-CSChmq_t2.mjs.map} +1 -1
- package/dist/{impl-dlRlTYAQ.mjs → impl-Ce9K4OCp.mjs} +2 -2
- package/dist/{impl-dlRlTYAQ.mjs.map → impl-Ce9K4OCp.mjs.map} +1 -1
- package/dist/{impl-CoLIqiH-2.mjs → impl-ChCqHkOc2.mjs} +2 -2
- package/dist/{impl-CoLIqiH-2.mjs.map → impl-ChCqHkOc2.mjs.map} +1 -1
- package/dist/{impl-DXWN22xV.mjs → impl-CqEwwWeD.mjs} +2 -2
- package/dist/{impl-DXWN22xV.mjs.map → impl-CqEwwWeD.mjs.map} +1 -1
- package/dist/{impl-CeLfAnyA2.mjs → impl-CqXFyvgV2.mjs} +2 -2
- package/dist/{impl-CeLfAnyA2.mjs.map → impl-CqXFyvgV2.mjs.map} +1 -1
- package/dist/{impl-ph0q6K3i.mjs → impl-CxLSJk2P.mjs} +2 -2
- package/dist/{impl-ph0q6K3i.mjs.map → impl-CxLSJk2P.mjs.map} +1 -1
- package/dist/{impl-DhIyASha.mjs → impl-CzU9WTiW.mjs} +2 -2
- package/dist/{impl-DhIyASha.mjs.map → impl-CzU9WTiW.mjs.map} +1 -1
- package/dist/{impl-BpUksm1b2.mjs → impl-D9NjIwEi2.mjs} +2 -2
- package/dist/{impl-BpUksm1b2.mjs.map → impl-D9NjIwEi2.mjs.map} +1 -1
- package/dist/{impl-BkyC7nnu.mjs → impl-DEWXA_QC.mjs} +2 -2
- package/dist/{impl-BkyC7nnu.mjs.map → impl-DEWXA_QC.mjs.map} +1 -1
- package/dist/{impl-DgyjJ8RY2.mjs → impl-DGiPB5Vq2.mjs} +2 -2
- package/dist/{impl-DgyjJ8RY2.mjs.map → impl-DGiPB5Vq2.mjs.map} +1 -1
- package/dist/{impl-CyJBbyuF.mjs → impl-DGuwD_qz.mjs} +2 -2
- package/dist/{impl-CyJBbyuF.mjs.map → impl-DGuwD_qz.mjs.map} +1 -1
- package/dist/{impl-D6nwGrO8.mjs → impl-DGzvE8aJ.mjs} +2 -2
- package/dist/{impl-D6nwGrO8.mjs.map → impl-DGzvE8aJ.mjs.map} +1 -1
- package/dist/{impl-Bc8Es_bT.mjs → impl-DTp9OQIZ.mjs} +2 -2
- package/dist/{impl-Bc8Es_bT.mjs.map → impl-DTp9OQIZ.mjs.map} +1 -1
- package/dist/{impl-DGRuk3AB.mjs → impl-DhscnXSw.mjs} +2 -2
- package/dist/{impl-DGRuk3AB.mjs.map → impl-DhscnXSw.mjs.map} +1 -1
- package/dist/{impl-BWjBYTQZ.mjs → impl-Dk7MdX-1.mjs} +2 -2
- package/dist/{impl-BWjBYTQZ.mjs.map → impl-Dk7MdX-1.mjs.map} +1 -1
- package/dist/{impl-Dny1LX9A.mjs → impl-DsNPvet4.mjs} +2 -2
- package/dist/{impl-Dny1LX9A.mjs.map → impl-DsNPvet4.mjs.map} +1 -1
- package/dist/{impl-DcC8_dCy.mjs → impl-DxUFb0vv.mjs} +2 -2
- package/dist/{impl-DcC8_dCy.mjs.map → impl-DxUFb0vv.mjs.map} +1 -1
- package/dist/{impl-y1I9Muyc2.mjs → impl-JThkrXiI2.mjs} +2 -2
- package/dist/{impl-y1I9Muyc2.mjs.map → impl-JThkrXiI2.mjs.map} +1 -1
- package/dist/{impl-Cq_RqK0_2.mjs → impl-KDuBh4bu2.mjs} +2 -2
- package/dist/{impl-Cq_RqK0_2.mjs.map → impl-KDuBh4bu2.mjs.map} +1 -1
- package/dist/{impl-C05tQHSq.mjs → impl-MpkLBntW.mjs} +2 -2
- package/dist/{impl-C05tQHSq.mjs.map → impl-MpkLBntW.mjs.map} +1 -1
- package/dist/{impl-Zr8uLP_n.mjs → impl-P_NDC3cX.mjs} +2 -2
- package/dist/{impl-Zr8uLP_n.mjs.map → impl-P_NDC3cX.mjs.map} +1 -1
- package/dist/{impl-D-ldjJzl2.mjs → impl-c7rUQYDc2.mjs} +2 -2
- package/dist/{impl-D-ldjJzl2.mjs.map → impl-c7rUQYDc2.mjs.map} +1 -1
- package/dist/{impl-G1brwI4o.mjs → impl-fqOKTw5J.mjs} +2 -2
- package/dist/{impl-G1brwI4o.mjs.map → impl-fqOKTw5J.mjs.map} +1 -1
- package/dist/{impl-Dfc_yQML2.mjs → impl-oiBTZqQS2.mjs} +2 -2
- package/dist/{impl-Dfc_yQML2.mjs.map → impl-oiBTZqQS2.mjs.map} +1 -1
- package/dist/{impl-CWHnw3oX.mjs → impl-tbGnvKFm.mjs} +2 -2
- package/dist/{impl-CWHnw3oX.mjs.map → impl-tbGnvKFm.mjs.map} +1 -1
- package/dist/index.d.mts +3397 -3397
- package/dist/index.mjs +1 -1
- package/dist/{makeGraphQLRequest-G078PsEL.mjs → makeGraphQLRequest-Cq26A_Lq.mjs} +2 -2
- package/dist/{makeGraphQLRequest-G078PsEL.mjs.map → makeGraphQLRequest-Cq26A_Lq.mjs.map} +1 -1
- package/dist/{markRequestDataSiloIdsCompleted-DmAz-R0M.mjs → markRequestDataSiloIdsCompleted-DzqJ5MNY.mjs} +2 -2
- package/dist/{markRequestDataSiloIdsCompleted-DmAz-R0M.mjs.map → markRequestDataSiloIdsCompleted-DzqJ5MNY.mjs.map} +1 -1
- package/dist/{markSilentPrivacyRequests-s7_aBROE.mjs → markSilentPrivacyRequests-BKQUu6Ep.mjs} +2 -2
- package/dist/{markSilentPrivacyRequests-s7_aBROE.mjs.map → markSilentPrivacyRequests-BKQUu6Ep.mjs.map} +1 -1
- package/dist/{mergeTranscendInputs-C64BJsse.mjs → mergeTranscendInputs-DGC4xUGu.mjs} +2 -2
- package/dist/{mergeTranscendInputs-C64BJsse.mjs.map → mergeTranscendInputs-DGC4xUGu.mjs.map} +1 -1
- package/dist/{notifyPrivacyRequestsAdditionalTime-BvXIXZYu.mjs → notifyPrivacyRequestsAdditionalTime-TEHAJe4C.mjs} +2 -2
- package/dist/{notifyPrivacyRequestsAdditionalTime-BvXIXZYu.mjs.map → notifyPrivacyRequestsAdditionalTime-TEHAJe4C.mjs.map} +1 -1
- package/dist/package-C4J38oR1.mjs +2 -0
- package/dist/package-C4J38oR1.mjs.map +1 -0
- package/dist/{pullAllDatapoints-DiMWp8a7.mjs → pullAllDatapoints-Cntwuzw7.mjs} +2 -2
- package/dist/{pullAllDatapoints-DiMWp8a7.mjs.map → pullAllDatapoints-Cntwuzw7.mjs.map} +1 -1
- package/dist/{pullChunkedCustomSiloOutstandingIdentifiers-DgWgggQt.mjs → pullChunkedCustomSiloOutstandingIdentifiers-BT-GZpT1.mjs} +2 -2
- package/dist/{pullChunkedCustomSiloOutstandingIdentifiers-DgWgggQt.mjs.map → pullChunkedCustomSiloOutstandingIdentifiers-BT-GZpT1.mjs.map} +1 -1
- package/dist/{pullConsentManagerMetrics-pFRPXTHJ.mjs → pullConsentManagerMetrics-FnhPEszu.mjs} +2 -2
- package/dist/{pullConsentManagerMetrics-pFRPXTHJ.mjs.map → pullConsentManagerMetrics-FnhPEszu.mjs.map} +1 -1
- package/dist/{pullManualEnrichmentIdentifiersToCsv-DA_4rIzW.mjs → pullManualEnrichmentIdentifiersToCsv-B_4REnga.mjs} +2 -2
- package/dist/{pullManualEnrichmentIdentifiersToCsv-DA_4rIzW.mjs.map → pullManualEnrichmentIdentifiersToCsv-B_4REnga.mjs.map} +1 -1
- package/dist/{pullTranscendConfiguration-D2cYlu6V.mjs → pullTranscendConfiguration-CqsgEf9A.mjs} +2 -2
- package/dist/{pullTranscendConfiguration-D2cYlu6V.mjs.map → pullTranscendConfiguration-CqsgEf9A.mjs.map} +1 -1
- package/dist/{pullUnstructuredSubDataPointRecommendations-C4aVhH-W.mjs → pullUnstructuredSubDataPointRecommendations-DZd2q6S2.mjs} +2 -2
- package/dist/{pullUnstructuredSubDataPointRecommendations-C4aVhH-W.mjs.map → pullUnstructuredSubDataPointRecommendations-DZd2q6S2.mjs.map} +1 -1
- package/dist/{pushCronIdentifiersFromCsv-C34TB9tG.mjs → pushCronIdentifiersFromCsv-D2saGR5i.mjs} +2 -2
- package/dist/{pushCronIdentifiersFromCsv-C34TB9tG.mjs.map → pushCronIdentifiersFromCsv-D2saGR5i.mjs.map} +1 -1
- package/dist/{pushManualEnrichmentIdentifiersFromCsv-CGS9E3Ft.mjs → pushManualEnrichmentIdentifiersFromCsv-DOvAzMyt.mjs} +2 -2
- package/dist/{pushManualEnrichmentIdentifiersFromCsv-CGS9E3Ft.mjs.map → pushManualEnrichmentIdentifiersFromCsv-DOvAzMyt.mjs.map} +1 -1
- package/dist/{removeUnverifiedRequestIdentifiers-pGGOFbfE.mjs → removeUnverifiedRequestIdentifiers-ChlwRmhd.mjs} +2 -2
- package/dist/{removeUnverifiedRequestIdentifiers-pGGOFbfE.mjs.map → removeUnverifiedRequestIdentifiers-ChlwRmhd.mjs.map} +1 -1
- package/dist/{retryRequestDataSilos-DXwN5uPw.mjs → retryRequestDataSilos-DnwXA1YZ.mjs} +2 -2
- package/dist/{retryRequestDataSilos-DXwN5uPw.mjs.map → retryRequestDataSilos-DnwXA1YZ.mjs.map} +1 -1
- package/dist/{skipPreflightJobs-BNQhuPZ8.mjs → skipPreflightJobs-jK5lNlmv.mjs} +2 -2
- package/dist/{skipPreflightJobs-BNQhuPZ8.mjs.map → skipPreflightJobs-jK5lNlmv.mjs.map} +1 -1
- package/dist/{skipRequestDataSilos-C39ji4lO.mjs → skipRequestDataSilos-DQGroOos.mjs} +2 -2
- package/dist/{skipRequestDataSilos-C39ji4lO.mjs.map → skipRequestDataSilos-DQGroOos.mjs.map} +1 -1
- package/dist/{streamPrivacyRequestsToCsv-C8lquiyd.mjs → streamPrivacyRequestsToCsv-BK07Bm-T.mjs} +2 -2
- package/dist/{streamPrivacyRequestsToCsv-C8lquiyd.mjs.map → streamPrivacyRequestsToCsv-BK07Bm-T.mjs.map} +1 -1
- package/dist/{syncCodePackages-BHgjfXCI.mjs → syncCodePackages-F-97FNjo.mjs} +2 -2
- package/dist/{syncCodePackages-BHgjfXCI.mjs.map → syncCodePackages-F-97FNjo.mjs.map} +1 -1
- package/dist/{syncCookies-CiLtxDFf.mjs → syncCookies-BxY36BeJ.mjs} +2 -2
- package/dist/{syncCookies-CiLtxDFf.mjs.map → syncCookies-BxY36BeJ.mjs.map} +1 -1
- package/dist/{syncDataFlows-DmBUs3G_.mjs → syncDataFlows-Cx5LZCen.mjs} +2 -2
- package/dist/{syncDataFlows-DmBUs3G_.mjs.map → syncDataFlows-Cx5LZCen.mjs.map} +1 -1
- package/dist/{syncTemplates-BNu1_dmW.mjs → syncTemplates-BrH7Yr0V.mjs} +2 -2
- package/dist/{syncTemplates-BNu1_dmW.mjs.map → syncTemplates-BrH7Yr0V.mjs.map} +1 -1
- package/dist/{updateConsentManagerVersionToLatest-BBMN94Hs.mjs → updateConsentManagerVersionToLatest-C221vAAw.mjs} +2 -2
- package/dist/{updateConsentManagerVersionToLatest-BBMN94Hs.mjs.map → updateConsentManagerVersionToLatest-C221vAAw.mjs.map} +1 -1
- package/dist/{uploadCookiesFromCsv-BKZx_E_2.mjs → uploadCookiesFromCsv-roHWekOP.mjs} +2 -2
- package/dist/{uploadCookiesFromCsv-BKZx_E_2.mjs.map → uploadCookiesFromCsv-roHWekOP.mjs.map} +1 -1
- package/dist/{uploadDataFlowsFromCsv-CJFVLvCJ.mjs → uploadDataFlowsFromCsv-DcTbrsv2.mjs} +2 -2
- package/dist/{uploadDataFlowsFromCsv-CJFVLvCJ.mjs.map → uploadDataFlowsFromCsv-DcTbrsv2.mjs.map} +1 -1
- package/dist/{uploadPrivacyRequestsFromCsv-BmP1JluQ.mjs → uploadPrivacyRequestsFromCsv-BUGTS-pY.mjs} +2 -2
- package/dist/{uploadPrivacyRequestsFromCsv-BmP1JluQ.mjs.map → uploadPrivacyRequestsFromCsv-BUGTS-pY.mjs.map} +1 -1
- package/dist/{uploadSiloDiscoveryResults-XpDp2u35.mjs → uploadSiloDiscoveryResults-D2fK92WR.mjs} +2 -2
- package/dist/{uploadSiloDiscoveryResults-XpDp2u35.mjs.map → uploadSiloDiscoveryResults-D2fK92WR.mjs.map} +1 -1
- package/dist/{withPreferenceRetry-Cb5S310L.mjs → withPreferenceRetry-xLMZyTq9.mjs} +2 -2
- package/dist/{withPreferenceRetry-Cb5S310L.mjs.map → withPreferenceRetry-xLMZyTq9.mjs.map} +1 -1
- package/package.json +7 -7
- package/dist/createExtraKeyHandler-C_0EVj10.mjs.map +0 -1
- package/dist/fetchAllPurposesAndPreferences-Dog6N9L2.mjs +0 -2
- package/dist/impl-1U4QBT_L.mjs.map +0 -1
- package/dist/package-BjNQxHlz.mjs +0 -2
- package/dist/package-BjNQxHlz.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchRequestFilesForRequest-
|
|
1
|
+
{"version":3,"file":"fetchRequestFilesForRequest-BbxrEKFK.mjs","names":[],"sources":["../src/lib/graphql/gqls/requestFile.ts","../src/lib/graphql/fetchRequestFilesForRequest.ts"],"sourcesContent":["import { gql } from 'graphql-request';\n\n// TODO: https://transcend.height.app/T-27909 - enable optimizations\n// isExportCsv: true\n// useMaster: false\nexport const REQUEST_FILES = gql`\n query TranscendCliRequestFiles($first: Int!, $offset: Int!, $filterBy: RequestFileFiltersInput!) {\n requestFiles(\n filterBy: $filterBy\n first: $first\n offset: $offset\n orderBy: [{ field: createdAt, direction: ASC }, { field: id, direction: ASC }]\n ) {\n nodes {\n remoteId\n fileName\n }\n }\n }\n`;\n\nexport const BULK_REQUEST_FILES = gql`\n query TranscendCliBulkRequestFiles(\n $filterBy: BulkRequestFilesFiltersInput!\n $first: Int!\n $after: String\n ) {\n bulkRequestFiles(filterBy: $filterBy, first: $first, after: $after) {\n nodes {\n remoteId\n fileName\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n`;\n","import { GraphQLClient } from 'graphql-request';\n\nimport { BULK_REQUEST_FILES } from './gqls/index.js';\nimport { makeGraphQLRequest } from './makeGraphQLRequest.js';\n\nexport interface RequestFileCursor {\n /** The ID of the request file */\n id: string;\n /** The created at timestamp */\n createdAt: string;\n}\n\nexport interface RequestFile {\n /** The remote ID */\n remoteId: string;\n /** The file name */\n fileName: string;\n}\n\nexport interface RequestFileResponse {\n /** RequestFiles */\n bulkRequestFiles: {\n /** List */\n nodes: RequestFile[];\n /** The page info */\n pageInfo: {\n /** Whether there is a next page */\n hasNextPage: boolean;\n /** The end cursor */\n endCursor: string;\n };\n };\n}\n\n/**\n * Fetch all RequestFiles for a single request\n *\n * @param client - GraphQL client\n * @param pageSize - How many request files to fetch per API call\n * @param filterBy - Filter by\n * @returns All RequestFiles in the organization\n */\nexport async function fetchRequestFilesForRequest(\n client: GraphQLClient,\n /** How many request files to fetch per API call */\n pageSize: number,\n filterBy: {\n /** Filter by request IDs */\n requestIds: string[];\n /** Filter by data silo ID */\n dataSiloIds: string[];\n },\n): Promise<RequestFile[]> {\n const requestFiles: RequestFile[] = [];\n let cursor: string | null = null;\n\n // Whether to continue looping\n let shouldContinue = false;\n do {\n const response: RequestFileResponse = await makeGraphQLRequest<RequestFileResponse>(\n client,\n BULK_REQUEST_FILES,\n {\n filterBy: {\n ...filterBy,\n },\n first: pageSize,\n after: cursor ?? undefined,\n },\n );\n const {\n bulkRequestFiles: { nodes, pageInfo },\n } = response;\n requestFiles.push(...nodes);\n shouldContinue = pageInfo.hasNextPage;\n cursor = pageInfo.endCursor;\n } while (shouldContinue);\n\n return requestFiles.sort((a, b) => a.remoteId.localeCompare(b.remoteId));\n}\n"],"mappings":"4FAKA,MAAa,EAAgB,CAAG;;;;;;;;;;;;;;EAgBnB,EAAqB,CAAG;;;;;;;;;;;;;;;;;ECqBrC,eAAsB,EACpB,EAEA,EACA,EAMwB,CACxB,IAAM,EAA8B,EAAE,CAClC,EAAwB,KAGxB,EAAiB,GACrB,EAAG,CAYD,GAAM,CACJ,iBAAkB,CAAE,QAAO,aAZS,MAAM,EAC1C,EACA,EACA,CACE,SAAU,CACR,GAAG,EACJ,CACD,MAAO,EACP,MAAO,GAAU,IAAA,GAClB,CACF,CAID,EAAa,KAAK,GAAG,EAAM,CAC3B,EAAiB,EAAS,YAC1B,EAAS,EAAS,gBACX,GAET,OAAO,EAAa,MAAM,EAAG,IAAM,EAAE,SAAS,cAAc,EAAE,SAAS,CAAC"}
|
package/dist/{generateCrossAccountApiKeys-F11uqpc5.mjs → generateCrossAccountApiKeys-Bxc_dzMG.mjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e}from"./constants-CeMiHaHx.mjs";import{t}from"./logger-B-LXIf3U.mjs";import{n}from"./bluebird-CUitXgsY.mjs";import{a as r,i,t as a}from"./fetchApiKeys-
|
|
1
|
+
import{a as e}from"./constants-CeMiHaHx.mjs";import{t}from"./logger-B-LXIf3U.mjs";import{n}from"./bluebird-CUitXgsY.mjs";import{a as r,i,t as a}from"./fetchApiKeys-DjOr44xA.mjs";import{i as o,t as s}from"./makeGraphQLRequest-Cq26A_Lq.mjs";import c from"colors";import{gql as l}from"graphql-request";const u=l`
|
|
2
2
|
mutation TranscendCliDetermineLoginMethod($email: String!) {
|
|
3
3
|
determineLoginMethod(input: { email: $email }) {
|
|
4
4
|
loginMethod {
|
|
@@ -30,4 +30,4 @@ import{a as e}from"./constants-CeMiHaHx.mjs";import{t}from"./logger-B-LXIf3U.mjs
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
`;async function p(e,{email:t,password:n}){let{determineLoginMethod:{loginMethod:r}}=await s(e,u,{email:t}),i=await e.rawRequest(d,{email:t,password:n,publicKey:r.sombraPublicKey}),{login:{user:a}}=i.data,o=i.headers.get(`set-cookie`);if(!o||!o.includes(`laravel`))throw Error(`Failed to get login cookie in response`);return{roles:a.roles,loginCookie:o}}async function m(e,{email:t,roleId:n}){let{determineLoginMethod:{loginMethod:r}}=await s(e,u,{email:t,userId:n});await e.rawRequest(f,{id:n,publicKey:r.sombraPublicKey})}async function h(e,t){let{createApiKey:{apiKey:n}}=await s(e,i,{input:t});return n}async function g(e,t){await s(e,r,{id:t})}async function _({email:r,password:i,scopes:s,apiKeyTitle:l,parentOrganizationId:u,deleteExistingApiKey:d=!0,createNewApiKey:f=!0,transcendUrl:_=e}){let v=await o(_,{});t.info(c.magenta(`Logging in using email and password.`));let{roles:y,loginCookie:b}=await p(v,{email:r,password:i});t.info(c.green(`Successfully logged in and found ${y.length} role${y.length===1?``:`s`}!`));let x=u?y.filter(e=>e.organization.id===u||e.organization.parentOrganizationId===u):y;v.setHeaders({Cookie:b});let S=[],C=[];return t.info(c.magenta(`Generating API keys with title: ${l}, scopes: ${s.join(`,`)}.`)),await n(x,async e=>{try{await m(v,{roleId:e.id,email:r}),t.info(c.magenta(`Checking if API key already exists in organization "${e.organization.name}" with title: "${l}".`));let[n]=await a(v,[l]);if(n&&d)t.info(c.yellow(`Deleting existing API key in "${e.organization.name}" with title: "${l}".`)),await g(v,n.id),t.info(c.green(`Successfully deleted API key in "${e.organization.name}" with title: "${l}".`));else if(n)throw Error(`API key already exists with title: "${l}"`);if(f){t.info(c.magenta(`Creating API key in "${e.organization.name}" with title: "${l}".`));let{apiKey:n}=await h(v,{title:l,scopes:s});S.push({organizationName:e.organization.name,organizationId:e.organization.id,apiKey:n}),t.info(c.green(`Successfully created API key in "${e.organization.name}" with title: "${l}".`))}else S.push({organizationName:e.organization.name,organizationId:e.organization.id,apiKey:``})}catch(n){t.error(c.red(`Failed to create API key in organization "${e.organization.name}"! - ${n.message}`)),C.push({organizationName:e.organization.name,organizationId:e.organization.id,error:n.message})}}),t.info(c.green(`Successfully created ${S.length} API key${S.length===1?``:`s`}`)),C.length>0&&t.error(c.red(`Failed to create ${C.length} API key${C.length===1?``:`s`}!`)),{errors:C,apiKeys:S}}export{p as a,d as c,m as i,h as n,f as o,g as r,u as s,_ as t};
|
|
33
|
-
//# sourceMappingURL=generateCrossAccountApiKeys-
|
|
33
|
+
//# sourceMappingURL=generateCrossAccountApiKeys-Bxc_dzMG.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateCrossAccountApiKeys-F11uqpc5.mjs","names":[],"sources":["../src/lib/graphql/gqls/auth.ts","../src/lib/graphql/loginUser.ts","../src/lib/graphql/manageApiKeys.ts","../src/lib/api-keys/generateCrossAccountApiKeys.ts"],"sourcesContent":["import { gql } from 'graphql-request';\n\nexport const DETERMINE_LOGIN_METHOD = gql`\n mutation TranscendCliDetermineLoginMethod($email: String!) {\n determineLoginMethod(input: { email: $email }) {\n loginMethod {\n email\n sombraPublicKey\n }\n }\n }\n`;\n\nexport const LOGIN = gql`\n mutation TranscendCliLogin($email: String!, $password: String!, $publicKey: String!) {\n login(input: { email: $email, password: $password }, publicKey: $publicKey) {\n user {\n roles {\n id\n organization {\n name\n id\n uri\n parentOrganizationId\n }\n }\n }\n }\n }\n`;\n\nexport const ASSUME_ROLE = gql`\n mutation TranscendCliAssumeRole($id: ID!, $publicKey: String!) {\n assumeRole(id: $id, publicKey: $publicKey) {\n clientMutationId\n }\n }\n`;\n","import { GraphQLClient } from 'graphql-request';\n\nimport { DETERMINE_LOGIN_METHOD, ASSUME_ROLE, LOGIN } from './gqls/index.js';\nimport { makeGraphQLRequest } from './makeGraphQLRequest.js';\n\nexport interface OrganizationPreview {\n /** Name of organization */\n name: string;\n /** Id of organization */\n id: string;\n /** uri of organization */\n uri: string;\n /** ID of parent organization */\n parentOrganizationId?: string;\n}\n\nexport interface UserRole {\n /** ID of role */\n id: string;\n /** Related organization */\n organization: OrganizationPreview;\n}\n\n/**\n * Log in as a user\n *\n * @param client - GraphQL client\n * @param options - Email/password\n * @returns Cookie and roles\n */\nexport async function loginUser(\n client: GraphQLClient,\n {\n email,\n password,\n }: {\n /** Email of user */\n email: string;\n /** Password of user */\n password: string;\n },\n): Promise<{\n /** Cookie to be used to make subsequent requests */\n loginCookie: string;\n /** Roles of the user */\n roles: UserRole[];\n}> {\n const {\n determineLoginMethod: { loginMethod },\n } = await makeGraphQLRequest<{\n /** Determine login method */\n determineLoginMethod: {\n /** Login method info */\n loginMethod: {\n /** Email being logged in */\n email: string;\n /** Sombra public key */\n sombraPublicKey: string;\n };\n };\n }>(client, DETERMINE_LOGIN_METHOD, {\n email,\n });\n\n const res = await client.rawRequest<{\n /** Login */\n login: {\n /** User */\n user: {\n /** Roles of user */\n roles: UserRole[];\n };\n };\n }>(LOGIN, {\n email,\n password,\n publicKey: loginMethod.sombraPublicKey,\n });\n const {\n login: { user },\n } = res.data;\n\n // Get login cookie from response\n const loginCookie = res.headers.get('set-cookie');\n if (!loginCookie || !loginCookie.includes('laravel')) {\n throw new Error('Failed to get login cookie in response');\n }\n\n return {\n roles: user.roles,\n loginCookie,\n };\n}\n\n/**\n * Assume role for user into another organization\n *\n * @param client - GraphQL client\n * @param options - Email/password\n */\nexport async function assumeRole(\n client: GraphQLClient,\n {\n email,\n roleId,\n }: {\n /** Email of user */\n email: string;\n /** Role of user assuming into */\n roleId: string;\n },\n): Promise<void> {\n const {\n determineLoginMethod: { loginMethod },\n } = await makeGraphQLRequest<{\n /** Determine login method */\n determineLoginMethod: {\n /** Login method info */\n loginMethod: {\n /** Email being logged in */\n email: string;\n /** Sombra public key */\n sombraPublicKey: string;\n };\n };\n }>(client, DETERMINE_LOGIN_METHOD, {\n email,\n userId: roleId,\n });\n\n await client.rawRequest<{\n /** Assume role */\n assumeRole: {\n /** Mutation ID */\n clientMutationId: string;\n };\n }>(ASSUME_ROLE, {\n id: roleId,\n publicKey: loginMethod.sombraPublicKey,\n });\n}\n","import { ScopeName } from '@transcend-io/privacy-types';\nimport { GraphQLClient } from 'graphql-request';\n\nimport { CREATE_API_KEY, DELETE_API_KEY } from './gqls/index.js';\nimport { makeGraphQLRequest } from './makeGraphQLRequest.js';\n\nexport interface CreatedApiKey {\n /** ID of API key */\n id: string;\n /** Actual API key */\n apiKey: string;\n /** Title of the API key */\n title: string;\n}\n\n/**\n * Create an API key\n *\n * @param client - GraphQL client\n * @param input - Input\n * @returns The API key\n */\nexport async function createApiKey(\n client: GraphQLClient,\n input: {\n /** Title of API key */\n title: string;\n /** Scopes for API key */\n scopes: ScopeName[];\n },\n): Promise<CreatedApiKey> {\n const {\n createApiKey: { apiKey },\n } = await makeGraphQLRequest<{\n /** Create API key */\n createApiKey: {\n /** API key */\n apiKey: CreatedApiKey;\n };\n }>(client, CREATE_API_KEY, { input });\n\n return apiKey;\n}\n\n/**\n * Delete an API key\n *\n * @param client - GraphQL client\n * @param id - API key Id\n */\nexport async function deleteApiKey(client: GraphQLClient, id: string): Promise<void> {\n await makeGraphQLRequest(client, DELETE_API_KEY, { id });\n}\n","import { ScopeName } from '@transcend-io/privacy-types';\nimport colors from 'colors';\n\nimport { StoredApiKey } from '../../codecs.js';\nimport { DEFAULT_TRANSCEND_API } from '../../constants.js';\nimport { logger } from '../../logger.js';\nimport { mapSeries } from '../bluebird.js';\nimport {\n buildTranscendGraphQLClientGeneric,\n loginUser,\n createApiKey,\n fetchAllApiKeys,\n deleteApiKey,\n assumeRole,\n} from '../graphql/index.js';\n\nexport interface ApiKeyGenerateError {\n /** Name of instance */\n organizationName: string;\n /** Error */\n error: string;\n /** Organization ID API key is for */\n organizationId: string;\n}\n\n/**\n * Generate API keys across multiple transcend accounts\n *\n * @param options - Options\n * @returns Number of API keys created\n */\nexport async function generateCrossAccountApiKeys({\n email,\n password,\n scopes,\n apiKeyTitle,\n parentOrganizationId,\n deleteExistingApiKey = true,\n createNewApiKey = true,\n transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n /** Email address of user generating API keys */\n email: string;\n /** Password of user generating API keys */\n password: string;\n /** Filter for organizations that match this parent organization ID */\n parentOrganizationId?: string;\n /** Title of the API create to create */\n apiKeyTitle: string;\n /** Title of the API create to create */\n scopes: ScopeName[];\n /** API URL for Transcend backend */\n transcendUrl?: string;\n /** When true delete existing API keys with that title, if set to false an API key exists with that title, an error is thrown */\n deleteExistingApiKey?: boolean;\n /** When true, generate new API keys, otherwise only will delete past API keys */\n createNewApiKey?: boolean;\n}): Promise<{\n /** Successfully generated */\n apiKeys: StoredApiKey[];\n /** Error results */\n errors: ApiKeyGenerateError[];\n}> {\n // Create GraphQL client\n const client = await buildTranscendGraphQLClientGeneric(transcendUrl, {});\n\n // Login the user\n logger.info(colors.magenta('Logging in using email and password.'));\n const { roles, loginCookie } = await loginUser(client, { email, password });\n logger.info(\n colors.green(\n `Successfully logged in and found ${roles.length} role${roles.length === 1 ? '' : 's'}!`,\n ),\n );\n\n // Filter down by parentOrganizationId\n const filteredRoles = parentOrganizationId\n ? roles.filter(\n (role) =>\n role.organization.id === parentOrganizationId ||\n role.organization.parentOrganizationId === parentOrganizationId,\n )\n : roles;\n\n // Save cookie to call route subsequent times\n client.setHeaders({\n Cookie: loginCookie,\n });\n\n // Save the resulting API keys\n const results: StoredApiKey[] = [];\n const errors: ApiKeyGenerateError[] = [];\n\n // Generate API keys\n logger.info(\n colors.magenta(`Generating API keys with title: ${apiKeyTitle}, scopes: ${scopes.join(',')}.`),\n );\n\n // Map over each role\n await mapSeries(filteredRoles, async (role) => {\n try {\n // Log into the other instance\n await assumeRole(client, { roleId: role.id, email });\n\n // Grab API keys with that title\n logger.info(\n colors.magenta(\n `Checking if API key already exists in organization \"${role.organization.name}\" with title: \"${apiKeyTitle}\".`,\n ),\n );\n\n // Delete existing API key\n const [apiKeyWithTitle] = await fetchAllApiKeys(client, [apiKeyTitle]);\n if (apiKeyWithTitle && deleteExistingApiKey) {\n logger.info(\n colors.yellow(\n `Deleting existing API key in \"${role.organization.name}\" with title: \"${apiKeyTitle}\".`,\n ),\n );\n await deleteApiKey(client, apiKeyWithTitle.id);\n logger.info(\n colors.green(\n `Successfully deleted API key in \"${role.organization.name}\" with title: \"${apiKeyTitle}\".`,\n ),\n );\n } else if (apiKeyWithTitle) {\n // throw error if one exists but not configured to delete\n throw new Error(`API key already exists with title: \"${apiKeyTitle}\"`);\n }\n\n // Create the API key\n if (createNewApiKey) {\n logger.info(\n colors.magenta(\n `Creating API key in \"${role.organization.name}\" with title: \"${apiKeyTitle}\".`,\n ),\n );\n const { apiKey } = await createApiKey(client, {\n title: apiKeyTitle,\n scopes,\n });\n results.push({\n organizationName: role.organization.name,\n organizationId: role.organization.id,\n apiKey,\n });\n logger.info(\n colors.green(\n `Successfully created API key in \"${role.organization.name}\" with title: \"${apiKeyTitle}\".`,\n ),\n );\n } else {\n // Delete only\n results.push({\n organizationName: role.organization.name,\n organizationId: role.organization.id,\n apiKey: '',\n });\n }\n } catch (err) {\n logger.error(\n colors.red(\n `Failed to create API key in organization \"${role.organization.name}\"! - ${err.message}`,\n ),\n );\n errors.push({\n organizationName: role.organization.name,\n organizationId: role.organization.id,\n error: err.message,\n });\n }\n });\n logger.info(\n colors.green(\n `Successfully created ${results.length} API key${results.length === 1 ? '' : 's'}`,\n ),\n );\n\n if (errors.length > 0) {\n logger.error(\n colors.red(`Failed to create ${errors.length} API key${errors.length === 1 ? '' : 's'}!`),\n );\n }\n\n return { errors, apiKeys: results };\n}\n"],"mappings":"2SAEA,MAAa,EAAyB,CAAG;;;;;;;;;EAW5B,EAAQ,CAAG;;;;;;;;;;;;;;;;EAkBX,EAAc,CAAG;;;;;;ECD9B,eAAsB,EACpB,EACA,CACE,QACA,YAYD,CACD,GAAM,CACJ,qBAAsB,CAAE,gBACtB,MAAM,EAWP,EAAQ,EAAwB,CACjC,QACD,CAAC,CAEI,EAAM,MAAM,EAAO,WAStB,EAAO,CACR,QACA,WACA,UAAW,EAAY,gBACxB,CAAC,CACI,CACJ,MAAO,CAAE,SACP,EAAI,KAGF,EAAc,EAAI,QAAQ,IAAI,aAAa,CACjD,GAAI,CAAC,GAAe,CAAC,EAAY,SAAS,UAAU,CAClD,MAAU,MAAM,yCAAyC,CAG3D,MAAO,CACL,MAAO,EAAK,MACZ,cACD,CASH,eAAsB,EACpB,EACA,CACE,QACA,UAOa,CACf,GAAM,CACJ,qBAAsB,CAAE,gBACtB,MAAM,EAWP,EAAQ,EAAwB,CACjC,QACA,OAAQ,EACT,CAAC,CAEF,MAAM,EAAO,WAMV,EAAa,CACd,GAAI,EACJ,UAAW,EAAY,gBACxB,CAAC,CCrHJ,eAAsB,EACpB,EACA,EAMwB,CACxB,GAAM,CACJ,aAAc,CAAE,WACd,MAAM,EAMP,EAAQ,EAAgB,CAAE,QAAO,CAAC,CAErC,OAAO,EAST,eAAsB,EAAa,EAAuB,EAA2B,CACnF,MAAM,EAAmB,EAAQ,EAAgB,CAAE,KAAI,CAAC,CCpB1D,eAAsB,EAA4B,CAChD,QACA,WACA,SACA,cACA,uBACA,uBAAuB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EAAa,EAAQ,CAC5C,MAAO,EACP,SACD,CAAC,CACF,EAAQ,KAAK,CACX,iBAAkB,EAAK,aAAa,KACpC,eAAgB,EAAK,aAAa,GAClC,SACD,CAAC,CACF,EAAO,KACL,EAAO,MACL,oCAAoC,EAAK,aAAa,KAAK,iBAAiB,EAAY,IACzF,CACF,MAGD,EAAQ,KAAK,CACX,iBAAkB,EAAK,aAAa,KACpC,eAAgB,EAAK,aAAa,GAClC,OAAQ,GACT,CAAC,OAEG,EAAK,CACZ,EAAO,MACL,EAAO,IACL,6CAA6C,EAAK,aAAa,KAAK,OAAO,EAAI,UAChF,CACF,CACD,EAAO,KAAK,CACV,iBAAkB,EAAK,aAAa,KACpC,eAAgB,EAAK,aAAa,GAClC,MAAO,EAAI,QACZ,CAAC,GAEJ,CACF,EAAO,KACL,EAAO,MACL,wBAAwB,EAAQ,OAAO,UAAU,EAAQ,SAAW,EAAI,GAAK,MAC9E,CACF,CAEG,EAAO,OAAS,GAClB,EAAO,MACL,EAAO,IAAI,oBAAoB,EAAO,OAAO,UAAU,EAAO,SAAW,EAAI,GAAK,IAAI,GAAG,CAC1F,CAGI,CAAE,SAAQ,QAAS,EAAS"}
|
|
1
|
+
{"version":3,"file":"generateCrossAccountApiKeys-Bxc_dzMG.mjs","names":[],"sources":["../src/lib/graphql/gqls/auth.ts","../src/lib/graphql/loginUser.ts","../src/lib/graphql/manageApiKeys.ts","../src/lib/api-keys/generateCrossAccountApiKeys.ts"],"sourcesContent":["import { gql } from 'graphql-request';\n\nexport const DETERMINE_LOGIN_METHOD = gql`\n mutation TranscendCliDetermineLoginMethod($email: String!) {\n determineLoginMethod(input: { email: $email }) {\n loginMethod {\n email\n sombraPublicKey\n }\n }\n }\n`;\n\nexport const LOGIN = gql`\n mutation TranscendCliLogin($email: String!, $password: String!, $publicKey: String!) {\n login(input: { email: $email, password: $password }, publicKey: $publicKey) {\n user {\n roles {\n id\n organization {\n name\n id\n uri\n parentOrganizationId\n }\n }\n }\n }\n }\n`;\n\nexport const ASSUME_ROLE = gql`\n mutation TranscendCliAssumeRole($id: ID!, $publicKey: String!) {\n assumeRole(id: $id, publicKey: $publicKey) {\n clientMutationId\n }\n }\n`;\n","import { GraphQLClient } from 'graphql-request';\n\nimport { DETERMINE_LOGIN_METHOD, ASSUME_ROLE, LOGIN } from './gqls/index.js';\nimport { makeGraphQLRequest } from './makeGraphQLRequest.js';\n\nexport interface OrganizationPreview {\n /** Name of organization */\n name: string;\n /** Id of organization */\n id: string;\n /** uri of organization */\n uri: string;\n /** ID of parent organization */\n parentOrganizationId?: string;\n}\n\nexport interface UserRole {\n /** ID of role */\n id: string;\n /** Related organization */\n organization: OrganizationPreview;\n}\n\n/**\n * Log in as a user\n *\n * @param client - GraphQL client\n * @param options - Email/password\n * @returns Cookie and roles\n */\nexport async function loginUser(\n client: GraphQLClient,\n {\n email,\n password,\n }: {\n /** Email of user */\n email: string;\n /** Password of user */\n password: string;\n },\n): Promise<{\n /** Cookie to be used to make subsequent requests */\n loginCookie: string;\n /** Roles of the user */\n roles: UserRole[];\n}> {\n const {\n determineLoginMethod: { loginMethod },\n } = await makeGraphQLRequest<{\n /** Determine login method */\n determineLoginMethod: {\n /** Login method info */\n loginMethod: {\n /** Email being logged in */\n email: string;\n /** Sombra public key */\n sombraPublicKey: string;\n };\n };\n }>(client, DETERMINE_LOGIN_METHOD, {\n email,\n });\n\n const res = await client.rawRequest<{\n /** Login */\n login: {\n /** User */\n user: {\n /** Roles of user */\n roles: UserRole[];\n };\n };\n }>(LOGIN, {\n email,\n password,\n publicKey: loginMethod.sombraPublicKey,\n });\n const {\n login: { user },\n } = res.data;\n\n // Get login cookie from response\n const loginCookie = res.headers.get('set-cookie');\n if (!loginCookie || !loginCookie.includes('laravel')) {\n throw new Error('Failed to get login cookie in response');\n }\n\n return {\n roles: user.roles,\n loginCookie,\n };\n}\n\n/**\n * Assume role for user into another organization\n *\n * @param client - GraphQL client\n * @param options - Email/password\n */\nexport async function assumeRole(\n client: GraphQLClient,\n {\n email,\n roleId,\n }: {\n /** Email of user */\n email: string;\n /** Role of user assuming into */\n roleId: string;\n },\n): Promise<void> {\n const {\n determineLoginMethod: { loginMethod },\n } = await makeGraphQLRequest<{\n /** Determine login method */\n determineLoginMethod: {\n /** Login method info */\n loginMethod: {\n /** Email being logged in */\n email: string;\n /** Sombra public key */\n sombraPublicKey: string;\n };\n };\n }>(client, DETERMINE_LOGIN_METHOD, {\n email,\n userId: roleId,\n });\n\n await client.rawRequest<{\n /** Assume role */\n assumeRole: {\n /** Mutation ID */\n clientMutationId: string;\n };\n }>(ASSUME_ROLE, {\n id: roleId,\n publicKey: loginMethod.sombraPublicKey,\n });\n}\n","import { ScopeName } from '@transcend-io/privacy-types';\nimport { GraphQLClient } from 'graphql-request';\n\nimport { CREATE_API_KEY, DELETE_API_KEY } from './gqls/index.js';\nimport { makeGraphQLRequest } from './makeGraphQLRequest.js';\n\nexport interface CreatedApiKey {\n /** ID of API key */\n id: string;\n /** Actual API key */\n apiKey: string;\n /** Title of the API key */\n title: string;\n}\n\n/**\n * Create an API key\n *\n * @param client - GraphQL client\n * @param input - Input\n * @returns The API key\n */\nexport async function createApiKey(\n client: GraphQLClient,\n input: {\n /** Title of API key */\n title: string;\n /** Scopes for API key */\n scopes: ScopeName[];\n },\n): Promise<CreatedApiKey> {\n const {\n createApiKey: { apiKey },\n } = await makeGraphQLRequest<{\n /** Create API key */\n createApiKey: {\n /** API key */\n apiKey: CreatedApiKey;\n };\n }>(client, CREATE_API_KEY, { input });\n\n return apiKey;\n}\n\n/**\n * Delete an API key\n *\n * @param client - GraphQL client\n * @param id - API key Id\n */\nexport async function deleteApiKey(client: GraphQLClient, id: string): Promise<void> {\n await makeGraphQLRequest(client, DELETE_API_KEY, { id });\n}\n","import { ScopeName } from '@transcend-io/privacy-types';\nimport colors from 'colors';\n\nimport { StoredApiKey } from '../../codecs.js';\nimport { DEFAULT_TRANSCEND_API } from '../../constants.js';\nimport { logger } from '../../logger.js';\nimport { mapSeries } from '../bluebird.js';\nimport {\n buildTranscendGraphQLClientGeneric,\n loginUser,\n createApiKey,\n fetchAllApiKeys,\n deleteApiKey,\n assumeRole,\n} from '../graphql/index.js';\n\nexport interface ApiKeyGenerateError {\n /** Name of instance */\n organizationName: string;\n /** Error */\n error: string;\n /** Organization ID API key is for */\n organizationId: string;\n}\n\n/**\n * Generate API keys across multiple transcend accounts\n *\n * @param options - Options\n * @returns Number of API keys created\n */\nexport async function generateCrossAccountApiKeys({\n email,\n password,\n scopes,\n apiKeyTitle,\n parentOrganizationId,\n deleteExistingApiKey = true,\n createNewApiKey = true,\n transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n /** Email address of user generating API keys */\n email: string;\n /** Password of user generating API keys */\n password: string;\n /** Filter for organizations that match this parent organization ID */\n parentOrganizationId?: string;\n /** Title of the API create to create */\n apiKeyTitle: string;\n /** Title of the API create to create */\n scopes: ScopeName[];\n /** API URL for Transcend backend */\n transcendUrl?: string;\n /** When true delete existing API keys with that title, if set to false an API key exists with that title, an error is thrown */\n deleteExistingApiKey?: boolean;\n /** When true, generate new API keys, otherwise only will delete past API keys */\n createNewApiKey?: boolean;\n}): Promise<{\n /** Successfully generated */\n apiKeys: StoredApiKey[];\n /** Error results */\n errors: ApiKeyGenerateError[];\n}> {\n // Create GraphQL client\n const client = await buildTranscendGraphQLClientGeneric(transcendUrl, {});\n\n // Login the user\n logger.info(colors.magenta('Logging in using email and password.'));\n const { roles, loginCookie } = await loginUser(client, { email, password });\n logger.info(\n colors.green(\n `Successfully logged in and found ${roles.length} role${roles.length === 1 ? '' : 's'}!`,\n ),\n );\n\n // Filter down by parentOrganizationId\n const filteredRoles = parentOrganizationId\n ? roles.filter(\n (role) =>\n role.organization.id === parentOrganizationId ||\n role.organization.parentOrganizationId === parentOrganizationId,\n )\n : roles;\n\n // Save cookie to call route subsequent times\n client.setHeaders({\n Cookie: loginCookie,\n });\n\n // Save the resulting API keys\n const results: StoredApiKey[] = [];\n const errors: ApiKeyGenerateError[] = [];\n\n // Generate API keys\n logger.info(\n colors.magenta(`Generating API keys with title: ${apiKeyTitle}, scopes: ${scopes.join(',')}.`),\n );\n\n // Map over each role\n await mapSeries(filteredRoles, async (role) => {\n try {\n // Log into the other instance\n await assumeRole(client, { roleId: role.id, email });\n\n // Grab API keys with that title\n logger.info(\n colors.magenta(\n `Checking if API key already exists in organization \"${role.organization.name}\" with title: \"${apiKeyTitle}\".`,\n ),\n );\n\n // Delete existing API key\n const [apiKeyWithTitle] = await fetchAllApiKeys(client, [apiKeyTitle]);\n if (apiKeyWithTitle && deleteExistingApiKey) {\n logger.info(\n colors.yellow(\n `Deleting existing API key in \"${role.organization.name}\" with title: \"${apiKeyTitle}\".`,\n ),\n );\n await deleteApiKey(client, apiKeyWithTitle.id);\n logger.info(\n colors.green(\n `Successfully deleted API key in \"${role.organization.name}\" with title: \"${apiKeyTitle}\".`,\n ),\n );\n } else if (apiKeyWithTitle) {\n // throw error if one exists but not configured to delete\n throw new Error(`API key already exists with title: \"${apiKeyTitle}\"`);\n }\n\n // Create the API key\n if (createNewApiKey) {\n logger.info(\n colors.magenta(\n `Creating API key in \"${role.organization.name}\" with title: \"${apiKeyTitle}\".`,\n ),\n );\n const { apiKey } = await createApiKey(client, {\n title: apiKeyTitle,\n scopes,\n });\n results.push({\n organizationName: role.organization.name,\n organizationId: role.organization.id,\n apiKey,\n });\n logger.info(\n colors.green(\n `Successfully created API key in \"${role.organization.name}\" with title: \"${apiKeyTitle}\".`,\n ),\n );\n } else {\n // Delete only\n results.push({\n organizationName: role.organization.name,\n organizationId: role.organization.id,\n apiKey: '',\n });\n }\n } catch (err) {\n logger.error(\n colors.red(\n `Failed to create API key in organization \"${role.organization.name}\"! - ${err.message}`,\n ),\n );\n errors.push({\n organizationName: role.organization.name,\n organizationId: role.organization.id,\n error: err.message,\n });\n }\n });\n logger.info(\n colors.green(\n `Successfully created ${results.length} API key${results.length === 1 ? '' : 's'}`,\n ),\n );\n\n if (errors.length > 0) {\n logger.error(\n colors.red(`Failed to create ${errors.length} API key${errors.length === 1 ? '' : 's'}!`),\n );\n }\n\n return { errors, apiKeys: results };\n}\n"],"mappings":"2SAEA,MAAa,EAAyB,CAAG;;;;;;;;;EAW5B,EAAQ,CAAG;;;;;;;;;;;;;;;;EAkBX,EAAc,CAAG;;;;;;ECD9B,eAAsB,EACpB,EACA,CACE,QACA,YAYD,CACD,GAAM,CACJ,qBAAsB,CAAE,gBACtB,MAAM,EAWP,EAAQ,EAAwB,CACjC,QACD,CAAC,CAEI,EAAM,MAAM,EAAO,WAStB,EAAO,CACR,QACA,WACA,UAAW,EAAY,gBACxB,CAAC,CACI,CACJ,MAAO,CAAE,SACP,EAAI,KAGF,EAAc,EAAI,QAAQ,IAAI,aAAa,CACjD,GAAI,CAAC,GAAe,CAAC,EAAY,SAAS,UAAU,CAClD,MAAU,MAAM,yCAAyC,CAG3D,MAAO,CACL,MAAO,EAAK,MACZ,cACD,CASH,eAAsB,EACpB,EACA,CACE,QACA,UAOa,CACf,GAAM,CACJ,qBAAsB,CAAE,gBACtB,MAAM,EAWP,EAAQ,EAAwB,CACjC,QACA,OAAQ,EACT,CAAC,CAEF,MAAM,EAAO,WAMV,EAAa,CACd,GAAI,EACJ,UAAW,EAAY,gBACxB,CAAC,CCrHJ,eAAsB,EACpB,EACA,EAMwB,CACxB,GAAM,CACJ,aAAc,CAAE,WACd,MAAM,EAMP,EAAQ,EAAgB,CAAE,QAAO,CAAC,CAErC,OAAO,EAST,eAAsB,EAAa,EAAuB,EAA2B,CACnF,MAAM,EAAmB,EAAQ,EAAgB,CAAE,KAAI,CAAC,CCpB1D,eAAsB,EAA4B,CAChD,QACA,WACA,SACA,cACA,uBACA,uBAAuB,GACvB,kBAAkB,GAClB,eAAe,GAuBd,CAED,IAAM,EAAS,MAAM,EAAmC,EAAc,EAAE,CAAC,CAGzE,EAAO,KAAK,EAAO,QAAQ,uCAAuC,CAAC,CACnE,GAAM,CAAE,QAAO,eAAgB,MAAM,E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aAAa,KAAK,iBAAiB,EAAY,IACzF,CACF,MAGD,EAAQ,KAAK,CACX,iBAAkB,EAAK,aAAa,KACpC,eAAgB,EAAK,aAAa,GAClC,OAAQ,GACT,CAAC,OAEG,EAAK,CACZ,EAAO,MACL,EAAO,IACL,6CAA6C,EAAK,aAAa,KAAK,OAAO,EAAI,UAChF,CACF,CACD,EAAO,KAAK,CACV,iBAAkB,EAAK,aAAa,KACpC,eAAgB,EAAK,aAAa,GAClC,MAAO,EAAI,QACZ,CAAC,GAEJ,CACF,EAAO,KACL,EAAO,MACL,wBAAwB,EAAQ,OAAO,UAAU,EAAQ,SAAW,EAAI,GAAK,MAC9E,CACF,CAEG,EAAO,OAAS,GAClB,EAAO,MACL,EAAO,IAAI,oBAAoB,EAAO,OAAO,UAAU,EAAO,SAAW,EAAI,GAAK,IAAI,GAAG,CAC1F,CAGI,CAAE,SAAQ,QAAS,EAAS"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{n as e,r as t,t as n}from"./enums-CyFTrzXY.mjs";import{t as r}from"./logger-B-LXIf3U.mjs";import{n as i,t as a}from"./bluebird-CUitXgsY.mjs";import{r as o}from"./assessment-BDywVaGR.mjs";import{r as s,t as c}from"./makeGraphQLRequest-
|
|
1
|
+
import{n as e,r as t,t as n}from"./enums-CyFTrzXY.mjs";import{t as r}from"./logger-B-LXIf3U.mjs";import{n as i,t as a}from"./bluebird-CUitXgsY.mjs";import{r as o}from"./assessment-BDywVaGR.mjs";import{r as s,t as c}from"./makeGraphQLRequest-Cq26A_Lq.mjs";import{t as l}from"./done-input-validation-DLR0-MJ7.mjs";import{OneTrustEnrichedAssessment as u,OneTrustGetAssessmentResponse as d,OneTrustGetListOfAssessmentsResponse as f,OneTrustGetRiskResponse as p,OneTrustGetUserResponse as m}from"@transcend-io/privacy-types";import{keyBy as h,uniq as g}from"lodash-es";import{decodeCodec as _}from"@transcend-io/type-utils";import v,{createReadStream as y}from"node:fs";import b from"colors";import x from"got";import S from"JSONStream";const C=({assessment:e,index:t,total:n,wrap:r=!0})=>{let i=``;(t===0||r)&&(i=`[
|
|
2
2
|
`);let a=JSON.stringify(e),o=n&&t<n-1&&!r?`,`:``;return i=`${i+a+o}\n`,(n&&t===n-1||r)&&(i+=`
|
|
3
3
|
]`),i},w=({file:e,assessment:t,index:n,total:i})=>{r.info(b.magenta(`Writing enriched assessment ${n+1} of ${i} to file "${e}"...`)),n===0?v.writeFileSync(e,C({assessment:t,index:n,total:i,wrap:!1})):v.appendFileSync(e,C({assessment:t,index:n,total:i,wrap:!1}))},T=async({oneTrust:e})=>{let t=0,n=1,i=0,a=[];for(;t<n;){let{body:o}=await e.get(`api/assessment/v2/assessments?page=${t}&size=2000`),{page:s,content:c}=_(f,o);a.push(...c??[]),t===0&&(n=s?.totalPages??0,i=s?.totalElements??0),t+=1,r.info(`Fetched ${a.length} of ${i} assessments.`)}return a},E=async({oneTrust:e,assessmentId:t})=>{let{body:n}=await e.get(`api/assessment/v2/assessments/${t}/export?ExcludeSkippedQuestions=false`);return _(d,n)},D=async({oneTrust:e,riskId:t})=>{let{body:n}=await e.get(`api/risk/v2/risks/${t}`);return _(p,n)},O=async({oneTrust:e,userId:t})=>{let{body:n}=await e.get(`api/scim/v2/Users/${t}`);return _(m,n)},k=({assessment:e,assessmentDetails:t,riskDetails:n,creatorDetails:r,approversDetails:i,respondentsDetails:a})=>{let o=h(n,`id`),{sections:s,createdBy:c,...l}=t,u=s.map(e=>{let{questions:t,...n}=e,r=t.map(e=>{let{risks:t,...n}=e,r=(t??[]).map(e=>{let t=o[e.riskId];return{...e,...t,level:e.level,impactLevel:e.impactLevel??0}});return{...n,risks:r}});return{...n,questions:r}}),d={...c,active:r?.active??!1,userType:r?.userType??`Internal`,emails:r?.emails??[],title:r?.title??null,givenName:r?.name.givenName??null,familyName:r?.name.familyName??null},f=h(i,`id`),p=t.approvers.flatMap(e=>f[e.id]?[{...e,approver:{...e.approver,active:f[e.id].active,userType:f[e.id].userType,emails:f[e.id].emails,title:f[e.id].title,givenName:f[e.id].name.givenName??null,familyName:f[e.id].name.familyName??null}}]:[]),m=h(a,`id`),g=t.respondents.filter(e=>!e.name.includes(`@`)).flatMap(e=>m[e.id]?[{...e,active:m[e.id].active,userType:m[e.id].userType,emails:m[e.id].emails,title:m[e.id].title,givenName:m[e.id].name.givenName??null,familyName:m[e.id].name.familyName??null}]:[]);return{...e,...l,approvers:p,respondents:g,createdBy:d,sections:u}},A=async({transcend:e,assessment:t,total:n,index:i})=>{r.info(b.magenta(`Writing enriched assessment ${i+1} ${n?`of ${n} `:` `}to Transcend...`));let a={json:C({assessment:t,index:i,total:n})};try{await c(e,o,{input:a})}catch{r.error(b.red(`Failed to sync assessment ${i+1} ${n?`of ${n} `:` `}to Transcend.\n\tAssessment Title: ${t.name}. Template Title: ${t.template.name}\n`))}},j=async({oneTrust:e,file:t,dryRun:n,transcend:o})=>{r.info(`Getting list of all assessments from OneTrust...`);let s=await T({oneTrust:e}),c={};await i(Array.from({length:Math.ceil(s.length/5)},(e,t)=>s.slice(t*5,(t+1)*5)),async(l,u)=>{let d=[];await a(l,async(t,n)=>{let i=5*u+n+1;r.info(`[assessment ${i} of ${s.length}]: fetching details...`);let{templateName:o,assessmentId:l}=t,f=await E({oneTrust:e,assessmentId:l}),p=f.createdBy.id,m=c[p];if(!m){r.info(`[assessment ${i} of ${s.length}]: fetching creator...`);try{m=await O({oneTrust:e,userId:p}),c[p]=m}catch{r.warn(b.yellow(`[assessment ${i} of ${s.length}]: failed to fetch form creator.\tcreatorId: ${p}. Assessment Title: ${t.name}. Template Title: ${o}`))}}let{approvers:h}=f,_=[];h.length>0&&(r.info(`[assessment ${i} of ${s.length}]: fetching approvers...`),_=await a(h.map(({id:e})=>e),async n=>{try{let t=c[n];return t||(t=await O({oneTrust:e,userId:n}),c[n]=t),[t]}catch{return r.warn(b.yellow(`[assessment ${i} of ${s.length}]: failed to fetch a form approver.\tapproverId: ${n}. Assessment Title: ${t.name}. Template Title: ${o}`)),[]}},{concurrency:5}));let{respondents:v}=f,y=v.filter(e=>!e.name.includes(`@`)),x=[];y.length>0&&(r.info(`[assessment ${i} of ${s.length}]: fetching respondents...`),x=await a(y.map(({id:e})=>e),async n=>{try{let t=c[n];return t||(t=await O({oneTrust:e,userId:n}),c[n]=t),[t]}catch{return r.warn(b.yellow(`[assessment ${i} of ${s.length}]: failed to fetch a respondent.\trespondentId: ${n}. Assessment Title: ${t.name}. Template Title: ${o}`)),[]}},{concurrency:5}));let S=[],C=g(f.sections.flatMap(e=>e.questions.flatMap(e=>(e.risks??[]).flatMap(e=>e.riskId))));C.length>0&&(r.info(`[assessment ${i} of ${s.length}]: fetching risks...`),S=await a(C,t=>D({oneTrust:e,riskId:t}),{concurrency:5}));let w=k({assessment:t,assessmentDetails:f,riskDetails:S,creatorDetails:m,approversDetails:_.flat(),respondentsDetails:x.flat()});d.push(w)},{concurrency:5}),await i(d,async(e,r)=>{let i=u*5+r;n&&t?w({assessment:e,index:i,total:s.length,file:t}):o&&await A({assessment:e,transcend:o,total:s.length,index:i})})})},M=({transcend:e,file:t})=>(r.info(`Getting list of all assessments from file ${t}...`),new Promise((n,i)=>{let a=y(t,{encoding:`utf-8`,highWaterMark:64*1024}),o=S.parse(`*`),s=0;a.pipe(o),o.on(`data`,async n=>{try{o.pause(),await A({assessment:_(u,n),transcend:e,index:s}),s+=1,o.resume()}catch(e){r.error(b.red(`Failed to parse the assessment ${s} from file '${t}': ${e.message}.`))}}),o.on(`end`,()=>{r.info(`Finished processing ${s} assessments from file ${t}`),n()}),o.on(`error`,e=>{r.error(b.red(`Error parsing file '${t}': ${e.message}`)),i(e)}),a.on(`error`,e=>{r.error(b.red(`Error reading file '${t}': ${e.message}`)),i(e)})})),N=({hostname:e,auth:t})=>x.extend({prefixUrl:`https://${e}`,headers:{accept:`application/json`,"content-type":`application/json`,authorization:`Bearer ${t}`}});async function P({hostname:i,oneTrustAuth:a,source:o,transcendAuth:c,transcendUrl:u,resource:d,file:f,dryRun:p,debug:m}){if(!p&&!c)throw Error('Must specify a "transcendAuth" parameter to sync resources to Transcend. e.g. --transcendAuth=${TRANSCEND_API_KEY}');if(p&&!f)throw Error(`Must set a "file" parameter when "dryRun" is "true". e.g. --file=./oneTrustAssessments.json`);if(f){let e=f.split(`.`);if(e.length<2)throw Error(`The "file" parameter has an invalid format. Expected a path with extensions. e.g. --file=./pathToFile.json.`);if(e.at(-1)!==n.Json)throw Error(`Expected the format of the "file" parameters '${f}' to be '${n.Json}', but got '${e.at(-1)}'.`)}if(o===t.OneTrust){if(!i)throw Error(`Missing required parameter "hostname". e.g. --hostname=customer.my.onetrust.com`);if(!a)throw Error(`Missing required parameter "oneTrustAuth". e.g. --oneTrustAuth=$ONE_TRUST_AUTH_TOKEN`)}else{if(!f)throw Error(`Must specify a "file" parameter to read the OneTrust assessments from. e.g. --source=./oneTrustAssessments.json`);if(p)throw Error(`Cannot read and write to a file simultaneously. Emit the "source" parameter or set it to ${t.OneTrust} if "dryRun" is enabled.`)}l(this.process.exit);let h=i&&a?N({hostname:i,auth:a}):void 0,g=u&&c?s(u,c):void 0;try{d===e.Assessments&&(o===t.OneTrust&&h?await j({oneTrust:h,file:f,dryRun:p,...g&&{transcend:g}}):o===t.File&&f&&g&&await M({file:f,transcend:g}))}catch(e){throw Error(`An error occurred syncing the resource ${d} from OneTrust: ${m?e.stack:e.message}`)}r.info(b.green(`Successfully synced OneTrust ${d} to ${p?`disk at "${f}"`:`Transcend`}!`))}export{P as syncOt};
|
|
4
|
-
//# sourceMappingURL=impl-
|
|
4
|
+
//# sourceMappingURL=impl-4ltdSmpl2.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"impl-0ooudQ_J2.mjs","names":[],"sources":["../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/lib/oneTrust/createOneTrustGotInstance.ts","../src/commands/migration/sync-ot/impl.ts"],"sourcesContent":["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 fs from 'node:fs';\n\nimport { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';\nimport colors from 'colors';\n\nimport { logger } from '../../../logger.js';\nimport { oneTrustAssessmentToJson } from './oneTrustAssessmentToJson.js';\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(`Writing enriched assessment ${index + 1} of ${total} to file \"${file}\"...`),\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 {\n OneTrustAssessment,\n OneTrustGetListOfAssessmentsResponse,\n} from '@transcend-io/privacy-types';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport { Got } from 'got';\n\nimport { logger } from '../../../logger.js';\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(OneTrustGetListOfAssessmentsResponse, body);\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(`Fetched ${allAssessments.length} of ${totalElements} assessments.`);\n }\n\n return allAssessments;\n};\n","import { OneTrustGetAssessmentResponse } from '@transcend-io/privacy-types';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport { Got } from 'got';\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 { OneTrustGetRiskResponse } from '@transcend-io/privacy-types';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport { Got } from 'got';\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 { OneTrustGetUserResponse } from '@transcend-io/privacy-types';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport { Got } from 'got';\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((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: approverDetailsById[originalApprover.id].name.givenName ?? null,\n familyName: approverDetailsById[originalApprover.id].name.familyName ?? 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: respondentsDetailsById[respondent.id].name.givenName ?? null,\n familyName: 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 { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';\nimport colors from 'colors';\nimport { GraphQLClient } from 'graphql-request';\n\nimport { ImportOnetrustAssessmentsInput } from '../../../codecs.js';\nimport { logger } from '../../../logger.js';\nimport { IMPORT_ONE_TRUST_ASSESSMENT_FORMS, makeGraphQLRequest } from '../../graphql/index.js';\nimport { oneTrustAssessmentToJson } from './oneTrustAssessmentToJson.js';\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} ${total ? `of ${total} ` : ' '}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} ${total ? `of ${total} ` : ' '}to Transcend.\\n` +\n `\\tAssessment Title: ${assessment.name}. Template Title: ${assessment.template.name}\\n`,\n ),\n );\n }\n};\n","import {\n OneTrustAssessmentQuestion,\n OneTrustAssessmentSection,\n OneTrustEnrichedAssessment,\n OneTrustGetRiskResponse,\n OneTrustGetUserResponse,\n} from '@transcend-io/privacy-types';\nimport colors from 'colors';\nimport type { Got } from 'got';\nimport { GraphQLClient } from 'graphql-request';\nimport { uniq } from 'lodash-es';\n\nimport { logger } from '../../../logger.js';\nimport { mapSeries, map } from '../../bluebird.js';\nimport {\n getListOfOneTrustAssessments,\n getOneTrustAssessment,\n getOneTrustRisk,\n getOneTrustUser,\n} from '../endpoints/index.js';\nimport { enrichOneTrustAssessment } from './enrichOneTrustAssessment.js';\nimport { syncOneTrustAssessmentToDisk } from './syncOneTrustAssessmentToDisk.js';\nimport { syncOneTrustAssessmentToTranscend } from './syncOneTrustAssessmentToTranscend.js';\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((r) => !r.name.includes('@'));\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(batchEnrichedAssessments, 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","import { createReadStream } from 'node:fs';\n\nimport { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport colors from 'colors';\nimport { GraphQLClient } from 'graphql-request';\nimport JSONStream from 'JSONStream';\n\nimport { logger } from '../../../logger.js';\nimport { syncOneTrustAssessmentToTranscend } from './syncOneTrustAssessmentToTranscend.js';\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(OneTrustEnrichedAssessment, assessment);\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(`Failed to parse the assessment ${index} from file '${file}': ${e.message}.`),\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(colors.red(`Error parsing file '${file}': ${error.message}`));\n reject(error);\n });\n\n fileStream.on('error', (error) => {\n logger.error(colors.red(`Error reading file '${file}': ${error.message}`));\n reject(error);\n });\n });\n};\n","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 colors from 'colors';\n\nimport type { LocalContext } from '../../../context.js';\nimport { OneTrustFileFormat, OneTrustPullResource, OneTrustPullSource } from '../../../enums.js';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation.js';\nimport { buildTranscendGraphQLClient } from '../../../lib/graphql/index.js';\nimport {\n syncOneTrustAssessmentsFromFile,\n syncOneTrustAssessmentsFromOneTrust,\n} from '../../../lib/oneTrust/helpers/index.js';\nimport { createOneTrustGotInstance } from '../../../lib/oneTrust/index.js';\nimport { logger } from '../../../logger.js';\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 ${dryRun ? `disk at \"${file}\"` : 'Transcend'}!`,\n ),\n );\n}\n"],"mappings":"4tBAQA,MAAa,GAA4B,CACvC,aACA,QACA,QACA,OAAO,MAUK,CACZ,IAAI,EAAY,IAEZ,IAAU,GAAK,K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GAAG,CAAC,IACjC,CAKL,GAAI,IAAW,EAAmB,SAAU,CAE1C,GAAI,CAAC,EACH,MAAU,MACR,kFACD,CAGH,GAAI,CAAC,EACH,MAAU,MACR,uFACD,KAEE,CAEL,GAAI,CAAC,EACH,MAAU,MACR,kHACD,CAIH,GAAI,EACF,MAAU,MACR,4FAC+C,EAAmB,SAAS,0BAC5E,CAIL,EAAoB,KAAK,QAAQ,KAAK,CAGtC,IAAM,EACJ,GAAY,EACR,EAA0B,CACxB,WACA,KAAM,EACP,CAAC,CACF,IAAA,GAGA,EACJ,GAAgB,EACZ,EAA4B,EAAc,EAAc,CACxD,IAAA,GAEN,GAAI,CACE,IAAa,EAAqB,cAChC,IAAW,EAAmB,UAAY,EAC5C,MAAM,EAAoC,CACxC,WACA,OACA,SACA,GAAI,GAAa,CAAE,YAAW,CAC/B,CAAC,CACO,IAAW,EAAmB,MAAQ,GAAQ,GACvD,MAAM,EAAgC,CAAE,OAAM,YAAW,CAAC,QAGvD,EAAK,CACZ,MAAU,MACR,0CAA0C,EAAS,kBACjD,EAAQ,EAAI,MAAQ,EAAI,UAE3B,CAIH,EAAO,KACL,EAAO,MACL,gCAAgC,EAAS,MAAM,EAAS,YAAY,EAAK,GAAK,YAAY,GAC3F,CACF"}
|
|
1
|
+
{"version":3,"file":"impl-4ltdSmpl2.mjs","names":[],"sources":["../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/lib/oneTrust/createOneTrustGotInstance.ts","../src/commands/migration/sync-ot/impl.ts"],"sourcesContent":["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 fs from 'node:fs';\n\nimport { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';\nimport colors from 'colors';\n\nimport { logger } from '../../../logger.js';\nimport { oneTrustAssessmentToJson } from './oneTrustAssessmentToJson.js';\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(`Writing enriched assessment ${index + 1} of ${total} to file \"${file}\"...`),\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 {\n OneTrustAssessment,\n OneTrustGetListOfAssessmentsResponse,\n} from '@transcend-io/privacy-types';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport { Got } from 'got';\n\nimport { logger } from '../../../logger.js';\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(OneTrustGetListOfAssessmentsResponse, body);\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(`Fetched ${allAssessments.length} of ${totalElements} assessments.`);\n }\n\n return allAssessments;\n};\n","import { OneTrustGetAssessmentResponse } from '@transcend-io/privacy-types';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport { Got } from 'got';\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 { OneTrustGetRiskResponse } from '@transcend-io/privacy-types';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport { Got } from 'got';\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 { OneTrustGetUserResponse } from '@transcend-io/privacy-types';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport { Got } from 'got';\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((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: approverDetailsById[originalApprover.id].name.givenName ?? null,\n familyName: approverDetailsById[originalApprover.id].name.familyName ?? 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: respondentsDetailsById[respondent.id].name.givenName ?? null,\n familyName: 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 { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';\nimport colors from 'colors';\nimport { GraphQLClient } from 'graphql-request';\n\nimport { ImportOnetrustAssessmentsInput } from '../../../codecs.js';\nimport { logger } from '../../../logger.js';\nimport { IMPORT_ONE_TRUST_ASSESSMENT_FORMS, makeGraphQLRequest } from '../../graphql/index.js';\nimport { oneTrustAssessmentToJson } from './oneTrustAssessmentToJson.js';\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} ${total ? `of ${total} ` : ' '}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} ${total ? `of ${total} ` : ' '}to Transcend.\\n` +\n `\\tAssessment Title: ${assessment.name}. Template Title: ${assessment.template.name}\\n`,\n ),\n );\n }\n};\n","import {\n OneTrustAssessmentQuestion,\n OneTrustAssessmentSection,\n OneTrustEnrichedAssessment,\n OneTrustGetRiskResponse,\n OneTrustGetUserResponse,\n} from '@transcend-io/privacy-types';\nimport colors from 'colors';\nimport type { Got } from 'got';\nimport { GraphQLClient } from 'graphql-request';\nimport { uniq } from 'lodash-es';\n\nimport { logger } from '../../../logger.js';\nimport { mapSeries, map } from '../../bluebird.js';\nimport {\n getListOfOneTrustAssessments,\n getOneTrustAssessment,\n getOneTrustRisk,\n getOneTrustUser,\n} from '../endpoints/index.js';\nimport { enrichOneTrustAssessment } from './enrichOneTrustAssessment.js';\nimport { syncOneTrustAssessmentToDisk } from './syncOneTrustAssessmentToDisk.js';\nimport { syncOneTrustAssessmentToTranscend } from './syncOneTrustAssessmentToTranscend.js';\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((r) => !r.name.includes('@'));\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(batchEnrichedAssessments, 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","import { createReadStream } from 'node:fs';\n\nimport { OneTrustEnrichedAssessment } from '@transcend-io/privacy-types';\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport colors from 'colors';\nimport { GraphQLClient } from 'graphql-request';\nimport JSONStream from 'JSONStream';\n\nimport { logger } from '../../../logger.js';\nimport { syncOneTrustAssessmentToTranscend } from './syncOneTrustAssessmentToTranscend.js';\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(OneTrustEnrichedAssessment, assessment);\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(`Failed to parse the assessment ${index} from file '${file}': ${e.message}.`),\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(colors.red(`Error parsing file '${file}': ${error.message}`));\n reject(error);\n });\n\n fileStream.on('error', (error) => {\n logger.error(colors.red(`Error reading file '${file}': ${error.message}`));\n reject(error);\n });\n });\n};\n","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 colors from 'colors';\n\nimport type { LocalContext } from '../../../context.js';\nimport { OneTrustFileFormat, OneTrustPullResource, OneTrustPullSource } from '../../../enums.js';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation.js';\nimport { buildTranscendGraphQLClient } from '../../../lib/graphql/index.js';\nimport {\n syncOneTrustAssessmentsFromFile,\n syncOneTrustAssessmentsFromOneTrust,\n} from '../../../lib/oneTrust/helpers/index.js';\nimport { createOneTrustGotInstance } from '../../../lib/oneTrust/index.js';\nimport { logger } from '../../../logger.js';\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 ${dryRun ? `disk at \"${file}\"` : 'Transcend'}!`,\n ),\n );\n}\n"],"mappings":"4tBAQA,MAAa,GAA4B,CACvC,aACA,QACA,QACA,OAAO,MAUK,CACZ,IAAI,EAAY,IAEZ,IAAU,GAAK,KACjB,EAAY;GAGd,IAAM,EAAwB,KAAK,UAAU,EAAW,CAGlD,EAAQ,GAAS,EAAQ,EAAQ,GAAK,CAAC,EAAO,IAAM,GAU1D,MAPA,GAAY,GAAG,EAAY,EAAwB,EAAM,KAGpD,GAAS,IAAU,EAAQ,GAAM,KACpC,GAAa;IAGR,GC5BI,GAAgC,CAC3C,OACA,aACA,QAC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IL,EAAoB,KAAK,QAAQ,KAAK,CAGtC,IAAM,EACJ,GAAY,EACR,EAA0B,CACxB,WACA,KAAM,EACP,CAAC,CACF,IAAA,GAGA,EACJ,GAAgB,EACZ,EAA4B,EAAc,EAAc,CACxD,IAAA,GAEN,GAAI,CACE,IAAa,EAAqB,cAChC,IAAW,EAAmB,UAAY,EAC5C,MAAM,EAAoC,CACxC,WACA,OACA,SACA,GAAI,GAAa,CAAE,YAAW,CAC/B,CAAC,CACO,IAAW,EAAmB,MAAQ,GAAQ,GACvD,MAAM,EAAgC,CAAE,OAAM,YAAW,CAAC,QAGvD,EAAK,CACZ,MAAU,MACR,0CAA0C,EAAS,kBACjD,EAAQ,EAAI,MAAQ,EAAI,UAE3B,CAIH,EAAO,KACL,EAAO,MACL,gCAAgC,EAAS,MAAM,EAAS,YAAY,EAAK,GAAK,YAAY,GAC3F,CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"./logger-B-LXIf3U.mjs";import{t}from"./bluebird-CUitXgsY.mjs";import{t as n}from"./createSombraGotInstance-
|
|
1
|
+
import{t as e}from"./logger-B-LXIf3U.mjs";import{t}from"./bluebird-CUitXgsY.mjs";import{t as n}from"./createSombraGotInstance-D1Il9zUE.mjs";import{t as r}from"./readCsv-CyOL7eCc.mjs";import{a as i}from"./writeCsv-B51ulrVl.mjs";import{t as a}from"./done-input-validation-DLR0-MJ7.mjs";import{n as o,t as s}from"./codecs-Dx_vGxsl.mjs";import{t as c}from"./withPreferenceRetry-xLMZyTq9.mjs";import{chunk as l}from"lodash-es";import{decodeCodec as u}from"@transcend-io/type-utils";import{readdirSync as d}from"node:fs";import{join as f}from"node:path";import p from"colors";import m from"cli-progress";async function h(t,{partition:n,identifierChunk:r,timestamp:i}){try{let{failures:a}=u(o,await c(`Delete Preference Records`,()=>t.post(`v1/preferences/${n}/delete`,{json:{records:r.map(e=>({anchorIdentifier:e,timestamp:i.toISOString()}))}}).json(),{maxAttempts:3,onRetry:(t,n,r)=>{e.warn(p.yellow(`Attempt ${t} to delete preference records failed: ${r}`))}}));return a.length>0?a.map(({index:e,error:t})=>({...r[e],error:t})):[]}catch(e){return r.map(t=>({...t,error:e.message}))}}async function g(e,{partition:n,filePath:i,timestamp:a,maxItemsInChunk:o,maxConcurrency:c}){return(await t(l(r(i,s),o),async t=>await h(e,{partition:n,identifierChunk:t,timestamp:a}),{concurrency:c})).flat()}async function _({auth:r,partition:o,sombraAuth:s,file:c=``,directory:l,transcendUrl:u,timestamp:h,maxConcurrency:_,maxItemsInChunk:v,receiptDirectory:y,fileConcurrency:b}){l&&c&&(e.error(p.red(`Cannot provide both a directory and a file. Please provide only one.`)),this.process.exit(1)),!c&&!l&&(e.error(p.red(`A file or directory must be provided. Please provide one using --file=./preferences.csv or --directory=./preferences`)),this.process.exit(1)),a(this.process.exit);let x=[];if(l)try{let t=d(l).filter(e=>e.endsWith(`.csv`));t.length===0&&(e.error(p.red(`No CSV files found in directory: ${l}`)),this.process.exit(1)),x.push(...t.map(e=>f(l,e)))}catch(t){e.error(p.red(`Failed to read directory: ${l}`)),e.error(p.red(t.message)),this.process.exit(1)}else try{c.endsWith(`.csv`)||(e.error(p.red(`File must be a CSV file`)),this.process.exit(1)),x.push(c)}catch(t){e.error(p.red(`Failed to access file: ${c}`)),e.error(p.red(t.message)),this.process.exit(1)}e.debug(p.green(`Processing ${x.length} consent preferences files for partition: ${o}`)),e.debug(`\nFiles to process: ${x.join(`, `)}\n`);let S=await n(u,r,s),C=new m.SingleBar({format:`Deletion Progress |${p.cyan(`[{bar}]`)}| Duration: ${p.red(`{duration_formatted}`)} | {value}/{total} Files Processed `},m.Presets.shades_classic);C.start(x.length,0);let w=await t(x,async e=>{let t=await g(S,{partition:o,filePath:e,timestamp:h,maxItemsInChunk:v,maxConcurrency:_});return C.increment(),t},{concurrency:b});C.stop();let T=w.flat(),E=``;T.length>0&&(E=f(y,`deletion-failures-${Date.now()}.csv`),i(E,T,!0)),e.info(p.green(`
|
|
2
2
|
|
|
3
3
|
==================================
|
|
4
4
|
|
|
@@ -9,4 +9,4 @@ import{t as e}from"./logger-B-LXIf3U.mjs";import{t}from"./bluebird-CUitXgsY.mjs"
|
|
|
9
9
|
==================================
|
|
10
10
|
|
|
11
11
|
`))}export{_ as deletePreferenceRecords};
|
|
12
|
-
//# sourceMappingURL=impl-
|
|
12
|
+
//# sourceMappingURL=impl-B19fH75P.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"impl-BzupMfJi.mjs","names":[],"sources":["../src/lib/preference-management/bulkDeletePreferenceRecords.ts","../src/commands/consent/delete-preference-records/impl.ts"],"sourcesContent":["import { decodeCodec } from '@transcend-io/type-utils';\nimport colors from 'colors';\nimport type { Got } from 'got';\nimport { chunk } from 'lodash-es';\n\nimport { logger } from '../../logger.js';\nimport { map } from '../bluebird.js';\nimport { readCsv } from '../requests/index.js';\nimport { DeletePreferenceRecordCliCsvRow, DeletePreferenceRecordsResponse } from './codecs.js';\nimport { withPreferenceRetry } from './withPreferenceRetry.js';\n\ninterface FailedResult extends DeletePreferenceRecordCliCsvRow {\n /** Error message describing the failure */\n error: string;\n}\n\ninterface DeletePreferenceRecordsRepositoryOptions {\n /** The partition to delete from */\n partition: string;\n /** Chunk of identifiers to delete */\n identifierChunk: DeletePreferenceRecordCliCsvRow[];\n /** the timestamp for the deletion operation */\n timestamp: Date;\n}\n\n/**\n * Options for deleting preference records\n */\ntype DeletePreferenceRecordsOptions = Omit<\n DeletePreferenceRecordsRepositoryOptions,\n 'identifierChunk'\n> & {\n /** The file path to read CSV rows from */\n filePath: string;\n /** Maximum items to include in each deletion chunk */\n maxItemsInChunk: number;\n /** Maximum concurrency for deletion requests */\n maxConcurrency: number;\n};\n\n/**\n *\n * Delete a chunk of preference records\n *\n * @param sombra - Sombra instance (must include auth headers)\n * @param options - Options for deletion\n * @param options.partition - The partition to delete from\n * @param options.identifierChunk - Chunk of identifiers to delete\n * @param options.timestamp - The timestamp for the deletion operation\n * @returns List of failed deletions\n */\nasync function deletePreferenceRecordsRepository(\n sombra: Got,\n { partition, identifierChunk: chunk, timestamp }: DeletePreferenceRecordsRepositoryOptions,\n): Promise<FailedResult[]> {\n try {\n const response = await withPreferenceRetry(\n 'Delete Preference Records',\n () =>\n sombra\n .post(`v1/preferences/${partition}/delete`, {\n json: {\n records: chunk.map((record) => ({\n anchorIdentifier: record,\n timestamp: timestamp.toISOString(),\n })),\n },\n })\n .json(),\n {\n maxAttempts: 3,\n onRetry: (attempt, _err, msg) => {\n logger.warn(\n colors.yellow(`Attempt ${attempt} to delete preference records failed: ${msg}`),\n );\n },\n },\n );\n const { failures } = decodeCodec(DeletePreferenceRecordsResponse, response);\n if (failures.length > 0) {\n return failures.map(({ index, error }) => ({\n ...chunk[index],\n error,\n }));\n }\n return [];\n } catch (err) {\n return chunk.map((record) => ({\n ...record,\n error: (err as Error).message,\n }));\n }\n}\n\n/**\n * Delete consent preferences for the managed consent database (delete endpoint)\n *\n * Uses POST /v1/preferences/{partition}/delete.\n *\n *\n * @param sombra - Sombra instance (must include auth headers)\n * @param options - Query options\n * @returns All nodes (only when onItems is not provided)\n */\nexport async function bulkDeletePreferenceRecords(\n sombra: Got,\n {\n partition,\n filePath,\n timestamp,\n maxItemsInChunk,\n maxConcurrency,\n }: DeletePreferenceRecordsOptions,\n): Promise<FailedResult[]> {\n const anchorIdentifiers = readCsv(filePath, DeletePreferenceRecordCliCsvRow);\n const chunks = chunk(anchorIdentifiers, maxItemsInChunk);\n\n const failedResults = await map(\n chunks,\n async (identifierChunk) => {\n const failedResults = await deletePreferenceRecordsRepository(sombra, {\n partition,\n identifierChunk,\n timestamp,\n });\n return failedResults;\n },\n { concurrency: maxConcurrency },\n );\n return failedResults.flat();\n}\n","import { readdirSync } from 'node:fs';\nimport { join } from 'node:path';\n\nimport cliProgress from 'cli-progress';\nimport colors from 'colors';\n\nimport type { LocalContext } from '../../../context.js';\nimport { map } from '../../../lib/bluebird.js';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation.js';\nimport { createSombraGotInstance } from '../../../lib/graphql/index.js';\nimport { writeCsv } from '../../../lib/helpers/index.js';\nimport { bulkDeletePreferenceRecords } from '../../../lib/preference-management/index.js';\nimport { logger } from '../../../logger.js';\n\nexport interface DeletePreferenceRecordsCommandFlags {\n /** Transcend API key for authentication */\n auth: string;\n /** Partition ID to delete preference records from */\n partition: string;\n /** Optional Sombra internal key for self-hosted instances */\n sombraAuth?: string;\n /** Path to the CSV file used to identify preference records to delete */\n file?: string;\n /** Path to the directory of CSV files to load preferences from */\n directory?: string;\n /** Base URL for the Transcend API */\n transcendUrl: string;\n /** The timestamp when the deletion operation is made. Used for logging purposes. */\n timestamp: Date;\n /** Maximum items to include in each deletion chunk */\n maxItemsInChunk: number;\n /** Maximum concurrency for deletion requests */\n maxConcurrency: number;\n /** Directory to write receipts of failed deletions to */\n receiptDirectory: string;\n /** Number of files to process concurrently when deleting preference records from multiple files */\n fileConcurrency: number;\n}\n\nexport async function deletePreferenceRecords(\n this: LocalContext,\n {\n auth,\n partition,\n sombraAuth,\n file = '',\n directory,\n transcendUrl,\n timestamp,\n maxConcurrency,\n maxItemsInChunk,\n receiptDirectory,\n fileConcurrency,\n }: DeletePreferenceRecordsCommandFlags,\n): Promise<void> {\n if (!!directory && !!file) {\n logger.error(\n colors.red('Cannot provide both a directory and a file. Please provide only one.'),\n );\n this.process.exit(1);\n }\n\n if (!file && !directory) {\n logger.error(\n colors.red(\n 'A file or directory must be provided. Please provide one using --file=./preferences.csv or --directory=./preferences',\n ),\n );\n this.process.exit(1);\n }\n doneInputValidation(this.process.exit);\n\n const files: string[] = [];\n\n if (directory) {\n try {\n const filesInDirectory = readdirSync(directory);\n const csvFiles = filesInDirectory.filter((file) => file.endsWith('.csv'));\n\n if (csvFiles.length === 0) {\n logger.error(colors.red(`No CSV files found in directory: ${directory}`));\n this.process.exit(1);\n }\n\n // Add full paths for each CSV file\n files.push(...csvFiles.map((file) => join(directory, file)));\n } catch (err) {\n logger.error(colors.red(`Failed to read directory: ${directory}`));\n logger.error(colors.red((err as Error).message));\n this.process.exit(1);\n }\n } else {\n try {\n // Verify file exists and is a CSV\n if (!file.endsWith('.csv')) {\n logger.error(colors.red('File must be a CSV file'));\n this.process.exit(1);\n }\n files.push(file);\n } catch (err) {\n logger.error(colors.red(`Failed to access file: ${file}`));\n logger.error(colors.red((err as Error).message));\n this.process.exit(1);\n }\n }\n\n logger.debug(\n colors.green(\n `Processing ${files.length} consent preferences files for partition: ${partition}`,\n ),\n );\n logger.debug(`\\nFiles to process: ${files.join(', ')}\\n`);\n\n // Create sombra instance to communicate with\n const sombra = await createSombraGotInstance(transcendUrl, auth, sombraAuth);\n const globalProgressBar = new cliProgress.SingleBar(\n {\n format: `Deletion Progress |${colors.cyan('[{bar}]')}| Duration: ${colors.red(\n '{duration_formatted}',\n )} | {value}/{total} Files Processed `,\n },\n cliProgress.Presets.shades_classic,\n );\n globalProgressBar.start(files.length, 0);\n\n // Process batch of files with concurrency\n const failedResultsArrays = await map(\n files,\n async (filePath) => {\n const result = await bulkDeletePreferenceRecords(sombra, {\n partition,\n filePath,\n timestamp,\n maxItemsInChunk,\n maxConcurrency,\n });\n globalProgressBar.increment();\n return result;\n },\n { concurrency: fileConcurrency },\n );\n globalProgressBar.stop();\n const failedResults = failedResultsArrays.flat();\n\n // Check for failed results and write receipt if any\n let receiptPath = '';\n if (failedResults.length > 0) {\n receiptPath = join(receiptDirectory, `deletion-failures-${Date.now()}.csv`);\n writeCsv(receiptPath, failedResults, true);\n }\n\n logger.info(colors.green('\\n\\n ================================== \\n\\n'));\n logger.info(colors.green('\\n#### Deletion Summary Report #####\\n'));\n logger.info(\n colors.green(\n `📁 Total Files Processed: ${files.length} \\n` +\n `❌ Errors: ${failedResults.length} \\n` +\n `📝 Receipt Path: ${receiptPath || 'N/A'}`,\n ),\n );\n logger.info(colors.green('\\n\\n==================================\\n\\n'));\n}\n"],"mappings":"slBAmDA,eAAe,EACb,EACA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K,EAAkB,qBAAqB,KAAK,KAAK,CAAC,MAAM,CAC3E,EAAS,EAAa,EAAe,GAAK,EAG5C,EAAO,KAAK,EAAO,MAAM;;;;EAA+C,CAAC,CACzE,EAAO,KAAK,EAAO,MAAM;;EAAyC,CAAC,CACnE,EAAO,KACL,EAAO,MACL,6BAA6B,EAAM,OAAO,eAC3B,EAAc,OAAO,sBACd,GAAe,QACtC,CACF,CACD,EAAO,KAAK,EAAO,MAAM;;;;EAA6C,CAAC"}
|
|
1
|
+
{"version":3,"file":"impl-B19fH75P.mjs","names":[],"sources":["../src/lib/preference-management/bulkDeletePreferenceRecords.ts","../src/commands/consent/delete-preference-records/impl.ts"],"sourcesContent":["import { decodeCodec } from '@transcend-io/type-utils';\nimport colors from 'colors';\nimport type { Got } from 'got';\nimport { chunk } from 'lodash-es';\n\nimport { logger } from '../../logger.js';\nimport { map } from '../bluebird.js';\nimport { readCsv } from '../requests/index.js';\nimport { DeletePreferenceRecordCliCsvRow, DeletePreferenceRecordsResponse } from './codecs.js';\nimport { withPreferenceRetry } from './withPreferenceRetry.js';\n\ninterface FailedResult extends DeletePreferenceRecordCliCsvRow {\n /** Error message describing the failure */\n error: string;\n}\n\ninterface DeletePreferenceRecordsRepositoryOptions {\n /** The partition to delete from */\n partition: string;\n /** Chunk of identifiers to delete */\n identifierChunk: DeletePreferenceRecordCliCsvRow[];\n /** the timestamp for the deletion operation */\n timestamp: Date;\n}\n\n/**\n * Options for deleting preference records\n */\ntype DeletePreferenceRecordsOptions = Omit<\n DeletePreferenceRecordsRepositoryOptions,\n 'identifierChunk'\n> & {\n /** The file path to read CSV rows from */\n filePath: string;\n /** Maximum items to include in each deletion chunk */\n maxItemsInChunk: number;\n /** Maximum concurrency for deletion requests */\n maxConcurrency: number;\n};\n\n/**\n *\n * Delete a chunk of preference records\n *\n * @param sombra - Sombra instance (must include auth headers)\n * @param options - Options for deletion\n * @param options.partition - The partition to delete from\n * @param options.identifierChunk - Chunk of identifiers to delete\n * @param options.timestamp - The timestamp for the deletion operation\n * @returns List of failed deletions\n */\nasync function deletePreferenceRecordsRepository(\n sombra: Got,\n { partition, identifierChunk: chunk, timestamp }: DeletePreferenceRecordsRepositoryOptions,\n): Promise<FailedResult[]> {\n try {\n const response = await withPreferenceRetry(\n 'Delete Preference Records',\n () =>\n sombra\n .post(`v1/preferences/${partition}/delete`, {\n json: {\n records: chunk.map((record) => ({\n anchorIdentifier: record,\n timestamp: timestamp.toISOString(),\n })),\n },\n })\n .json(),\n {\n maxAttempts: 3,\n onRetry: (attempt, _err, msg) => {\n logger.warn(\n colors.yellow(`Attempt ${attempt} to delete preference records failed: ${msg}`),\n );\n },\n },\n );\n const { failures } = decodeCodec(DeletePreferenceRecordsResponse, response);\n if (failures.length > 0) {\n return failures.map(({ index, error }) => ({\n ...chunk[index],\n error,\n }));\n }\n return [];\n } catch (err) {\n return chunk.map((record) => ({\n ...record,\n error: (err as Error).message,\n }));\n }\n}\n\n/**\n * Delete consent preferences for the managed consent database (delete endpoint)\n *\n * Uses POST /v1/preferences/{partition}/delete.\n *\n *\n * @param sombra - Sombra instance (must include auth headers)\n * @param options - Query options\n * @returns All nodes (only when onItems is not provided)\n */\nexport async function bulkDeletePreferenceRecords(\n sombra: Got,\n {\n partition,\n filePath,\n timestamp,\n maxItemsInChunk,\n maxConcurrency,\n }: DeletePreferenceRecordsOptions,\n): Promise<FailedResult[]> {\n const anchorIdentifiers = readCsv(filePath, DeletePreferenceRecordCliCsvRow);\n const chunks = chunk(anchorIdentifiers, maxItemsInChunk);\n\n const failedResults = await map(\n chunks,\n async (identifierChunk) => {\n const failedResults = await deletePreferenceRecordsRepository(sombra, {\n partition,\n identifierChunk,\n timestamp,\n });\n return failedResults;\n },\n { concurrency: maxConcurrency },\n );\n return failedResults.flat();\n}\n","import { readdirSync } from 'node:fs';\nimport { join } from 'node:path';\n\nimport cliProgress from 'cli-progress';\nimport colors from 'colors';\n\nimport type { LocalContext } from '../../../context.js';\nimport { map } from '../../../lib/bluebird.js';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation.js';\nimport { createSombraGotInstance } from '../../../lib/graphql/index.js';\nimport { writeCsv } from '../../../lib/helpers/index.js';\nimport { bulkDeletePreferenceRecords } from '../../../lib/preference-management/index.js';\nimport { logger } from '../../../logger.js';\n\nexport interface DeletePreferenceRecordsCommandFlags {\n /** Transcend API key for authentication */\n auth: string;\n /** Partition ID to delete preference records from */\n partition: string;\n /** Optional Sombra internal key for self-hosted instances */\n sombraAuth?: string;\n /** Path to the CSV file used to identify preference records to delete */\n file?: string;\n /** Path to the directory of CSV files to load preferences from */\n directory?: string;\n /** Base URL for the Transcend API */\n transcendUrl: string;\n /** The timestamp when the deletion operation is made. Used for logging purposes. */\n timestamp: Date;\n /** Maximum items to include in each deletion chunk */\n maxItemsInChunk: number;\n /** Maximum concurrency for deletion requests */\n maxConcurrency: number;\n /** Directory to write receipts of failed deletions to */\n receiptDirectory: string;\n /** Number of files to process concurrently when deleting preference records from multiple files */\n fileConcurrency: number;\n}\n\nexport async function deletePreferenceRecords(\n this: LocalContext,\n {\n auth,\n partition,\n sombraAuth,\n file = '',\n directory,\n transcendUrl,\n timestamp,\n maxConcurrency,\n maxItemsInChunk,\n receiptDirectory,\n fileConcurrency,\n }: DeletePreferenceRecordsCommandFlags,\n): Promise<void> {\n if (!!directory && !!file) {\n logger.error(\n colors.red('Cannot provide both a directory and a file. Please provide only one.'),\n );\n this.process.exit(1);\n }\n\n if (!file && !directory) {\n logger.error(\n colors.red(\n 'A file or directory must be provided. Please provide one using --file=./preferences.csv or --directory=./preferences',\n ),\n );\n this.process.exit(1);\n }\n doneInputValidation(this.process.exit);\n\n const files: string[] = [];\n\n if (directory) {\n try {\n const filesInDirectory = readdirSync(directory);\n const csvFiles = filesInDirectory.filter((file) => file.endsWith('.csv'));\n\n if (csvFiles.length === 0) {\n logger.error(colors.red(`No CSV files found in directory: ${directory}`));\n this.process.exit(1);\n }\n\n // Add full paths for each CSV file\n files.push(...csvFiles.map((file) => join(directory, file)));\n } catch (err) {\n logger.error(colors.red(`Failed to read directory: ${directory}`));\n logger.error(colors.red((err as Error).message));\n this.process.exit(1);\n }\n } else {\n try {\n // Verify file exists and is a CSV\n if (!file.endsWith('.csv')) {\n logger.error(colors.red('File must be a CSV file'));\n this.process.exit(1);\n }\n files.push(file);\n } catch (err) {\n logger.error(colors.red(`Failed to access file: ${file}`));\n logger.error(colors.red((err as Error).message));\n this.process.exit(1);\n }\n }\n\n logger.debug(\n colors.green(\n `Processing ${files.length} consent preferences files for partition: ${partition}`,\n ),\n );\n logger.debug(`\\nFiles to process: ${files.join(', ')}\\n`);\n\n // Create sombra instance to communicate with\n const sombra = await createSombraGotInstance(transcendUrl, auth, sombraAuth);\n const globalProgressBar = new cliProgress.SingleBar(\n {\n format: `Deletion Progress |${colors.cyan('[{bar}]')}| Duration: ${colors.red(\n '{duration_formatted}',\n )} | {value}/{total} Files Processed `,\n },\n cliProgress.Presets.shades_classic,\n );\n globalProgressBar.start(files.length, 0);\n\n // Process batch of files with concurrency\n const failedResultsArrays = await map(\n files,\n async (filePath) => {\n const result = await bulkDeletePreferenceRecords(sombra, {\n partition,\n filePath,\n timestamp,\n maxItemsInChunk,\n maxConcurrency,\n });\n globalProgressBar.increment();\n return result;\n },\n { concurrency: fileConcurrency },\n );\n globalProgressBar.stop();\n const failedResults = failedResultsArrays.flat();\n\n // Check for failed results and write receipt if any\n let receiptPath = '';\n if (failedResults.length > 0) {\n receiptPath = join(receiptDirectory, `deletion-failures-${Date.now()}.csv`);\n writeCsv(receiptPath, failedResults, true);\n }\n\n logger.info(colors.green('\\n\\n ================================== \\n\\n'));\n logger.info(colors.green('\\n#### Deletion Summary Report #####\\n'));\n logger.info(\n colors.green(\n `📁 Total Files Processed: ${files.length} \\n` +\n `❌ Errors: ${failedResults.length} \\n` +\n `📝 Receipt Path: ${receiptPath || 'N/A'}`,\n ),\n );\n logger.info(colors.green('\\n\\n==================================\\n\\n'));\n}\n"],"mappings":"slBAm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S,IACzB,EAAc,EAAK,EAAkB,qBAAqB,KAAK,KAAK,CAAC,MAAM,CAC3E,EAAS,EAAa,EAAe,GAAK,EAG5C,EAAO,KAAK,EAAO,MAAM;;;;EAA+C,CAAC,CACzE,EAAO,KAAK,EAAO,MAAM;;EAAyC,CAAC,CACnE,EAAO,KACL,EAAO,MACL,6BAA6B,EAAM,OAAO,eAC3B,EAAc,OAAO,sBACd,GAAe,QACtC,CACF,CACD,EAAO,KAAK,EAAO,MAAM;;;;EAA6C,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./logger-B-LXIf3U.mjs";import{a as t,r as n}from"./readTranscendYaml-D-J1ilS0.mjs";import{n as r}from"./fetchCatalogs-
|
|
2
|
-
//# sourceMappingURL=impl-
|
|
1
|
+
import{t as e}from"./logger-B-LXIf3U.mjs";import{a as t,r as n}from"./readTranscendYaml-D-J1ilS0.mjs";import{n as r}from"./fetchCatalogs-BM4FCbcS.mjs";import{r as i}from"./makeGraphQLRequest-Cq26A_Lq.mjs";import{t as a}from"./listFiles-qzyQMaYH.mjs";import{t as o}from"./done-input-validation-DLR0-MJ7.mjs";import{t as s}from"./dataFlowsToDataSilos-NhvBw1iy.mjs";import{difference as c}from"lodash-es";import{existsSync as l,lstatSync as u}from"node:fs";import{join as d}from"node:path";import f from"colors";async function p({auth:p,dataFlowsYmlFolder:m,output:h,ignoreYmls:g=[],transcendUrl:_}){o(this.process.exit),(!l(m)||!u(m).isDirectory())&&(e.error(f.red(`Folder does not exist: "${m}"`)),this.process.exit(1));let v=g.map(e=>e.split(`.`)[0]),y=a(m).map(e=>{let{"data-flows":t=[]}=n(d(m,e)),{adTechDataSilos:r,siteTechDataSilos:i}=s(t,{serviceToSupportedIntegration:T,serviceToTitle:w});return{adTechDataSilos:r,siteTechDataSilos:i,organizationName:e.split(`.`)[0]}}),b={};y.forEach(({adTechDataSilos:e,siteTechDataSilos:t,organizationName:n})=>{[...e,...t].forEach(e=>{let t=e[`outer-type`]||e.integrationName;b[t]||(b[t]=[]),b[t].push(n),b[t]=[...new Set(b[t])]})});let x=[...new Set(y.map(({adTechDataSilos:e})=>e.map(e=>e[`outer-type`]||e.integrationName)).flat())],S=c([...new Set(y.map(({siteTechDataSilos:e})=>e.map(e=>e[`outer-type`]||e.integrationName)).flat())],x),C={};y.forEach(({adTechDataSilos:e,siteTechDataSilos:t})=>{[...e,...t].forEach(e=>{let t=e[`outer-type`]||e.integrationName,n=e.attributes?.find(e=>e.key===`Found On Domain`);C[t]||(C[t]=[]),C[t].push(...n?.values||[]),C[t]=[...new Set(C[t])]})});let{serviceToTitle:w,serviceToSupportedIntegration:T}=await r(i(_,p)),E=[...x,...S].map(e=>({title:w[e],...T[e]?{integrationName:e}:{integrationName:`promptAPerson`,"outer-type":e},attributes:[{key:`Tech Type`,values:[`Ad Tech`]},{key:`Business Units`,values:c(b[e]||[],v)},{key:`Found On Domain`,values:C[e]||[]}]}));e.log(`Total Services: ${E.length}`),e.log(`Ad Tech Services: ${x.length}`),e.log(`Site Tech Services: ${S.length}`),t(h,{"data-silos":E})}export{p as deriveDataSilosFromDataFlowsCrossInstance};
|
|
2
|
+
//# sourceMappingURL=impl-BBMjv5YQ.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"impl-
|
|
1
|
+
{"version":3,"file":"impl-BBMjv5YQ.mjs","names":[],"sources":["../src/commands/inventory/derive-data-silos-from-data-flows-cross-instance/impl.ts"],"sourcesContent":["import { existsSync, lstatSync } from 'node:fs';\nimport { join } from 'node:path';\n\nimport colors from 'colors';\nimport { difference } from 'lodash-es';\n\nimport { DataFlowInput } from '../../../codecs.js';\nimport type { LocalContext } from '../../../context.js';\nimport { listFiles } from '../../../lib/api-keys/index.js';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation.js';\nimport { dataFlowsToDataSilos } from '../../../lib/consent-manager/dataFlowsToDataSilos.js';\nimport { fetchAndIndexCatalogs, buildTranscendGraphQLClient } from '../../../lib/graphql/index.js';\nimport { readTranscendYaml, writeTranscendYaml } from '../../../lib/readTranscendYaml.js';\nimport { logger } from '../../../logger.js';\n\nexport interface DeriveDataSilosFromDataFlowsCrossInstanceCommandFlags {\n auth: string;\n dataFlowsYmlFolder: string;\n output: string;\n ignoreYmls?: string[];\n transcendUrl: string;\n}\n\nexport async function deriveDataSilosFromDataFlowsCrossInstance(\n this: LocalContext,\n {\n auth,\n dataFlowsYmlFolder,\n output,\n ignoreYmls = [],\n transcendUrl,\n }: DeriveDataSilosFromDataFlowsCrossInstanceCommandFlags,\n): Promise<void> {\n doneInputValidation(this.process.exit);\n\n // Ensure folder is passed\n if (!existsSync(dataFlowsYmlFolder) || !lstatSync(dataFlowsYmlFolder).isDirectory()) {\n logger.error(colors.red(`Folder does not exist: \"${dataFlowsYmlFolder}\"`));\n this.process.exit(1);\n }\n\n // Ignore the data flows in these yml files\n const instancesToIgnore = ignoreYmls.map((x) => x.split('.')[0]);\n\n // Map over each data flow yml file and convert to data silo configurations\n const dataSiloInputs = listFiles(dataFlowsYmlFolder).map((directory) => {\n // read in the data flows for a specific instance\n const { 'data-flows': dataFlows = [] } = readTranscendYaml(join(dataFlowsYmlFolder, directory));\n\n // map the data flows to data silos\n const { adTechDataSilos, siteTechDataSilos } = dataFlowsToDataSilos(\n dataFlows as DataFlowInput[],\n {\n serviceToSupportedIntegration,\n serviceToTitle,\n },\n );\n\n return {\n adTechDataSilos,\n siteTechDataSilos,\n organizationName: directory.split('.')[0],\n };\n });\n\n // Mapping from service name to instances that have that service\n const serviceToInstance: { [k in string]: string[] } = {};\n dataSiloInputs.forEach(({ adTechDataSilos, siteTechDataSilos, organizationName }) => {\n const allDataSilos = [...adTechDataSilos, ...siteTechDataSilos];\n allDataSilos.forEach((dataSilo) => {\n const service = dataSilo['outer-type'] || dataSilo.integrationName;\n // create mapping to instance\n if (!serviceToInstance[service]) {\n serviceToInstance[service] = [];\n }\n serviceToInstance[service]!.push(organizationName);\n serviceToInstance[service] = [...new Set(serviceToInstance[service])];\n });\n });\n\n // List of ad tech integrations\n const adTechIntegrations = [\n ...new Set(\n dataSiloInputs\n .map(({ adTechDataSilos }) =>\n adTechDataSilos.map((silo) => silo['outer-type'] || silo.integrationName),\n )\n .flat(),\n ),\n ];\n\n // List of site tech integrations\n const siteTechIntegrations = difference(\n [\n ...new Set(\n dataSiloInputs\n .map(({ siteTechDataSilos }) =>\n siteTechDataSilos.map((silo) => silo['outer-type'] || silo.integrationName),\n )\n .flat(),\n ),\n ],\n adTechIntegrations,\n );\n\n // Mapping from service name to list of\n const serviceToFoundOnDomain: { [k in string]: string[] } = {};\n dataSiloInputs.forEach(({ adTechDataSilos, siteTechDataSilos }) => {\n const allDataSilos = [...adTechDataSilos, ...siteTechDataSilos];\n allDataSilos.forEach((dataSilo) => {\n const service = dataSilo['outer-type'] || dataSilo.integrationName;\n const foundOnDomain = dataSilo.attributes?.find((attr) => attr.key === 'Found On Domain');\n // create mapping to instance\n if (!serviceToFoundOnDomain[service]) {\n serviceToFoundOnDomain[service] = [];\n }\n serviceToFoundOnDomain[service]!.push(...(foundOnDomain?.values || []));\n serviceToFoundOnDomain[service] = [...new Set(serviceToFoundOnDomain[service])];\n });\n });\n\n // Fetch all integrations in the catalog\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n const { serviceToTitle, serviceToSupportedIntegration } = await fetchAndIndexCatalogs(client);\n\n // construct the aggregated data silo inputs\n const dataSilos = [...adTechIntegrations, ...siteTechIntegrations].map((service) => ({\n title: serviceToTitle[service],\n ...(serviceToSupportedIntegration[service]\n ? { integrationName: service }\n : { integrationName: 'promptAPerson', 'outer-type': service }),\n attributes: [\n {\n key: 'Tech Type',\n values: ['Ad Tech'],\n },\n {\n key: 'Business Units',\n values: difference(serviceToInstance[service] || [], instancesToIgnore),\n },\n {\n key: 'Found On Domain',\n values: serviceToFoundOnDomain[service] || [],\n },\n ],\n }));\n\n // Log output\n logger.log(`Total Services: ${dataSilos.length}`);\n logger.log(`Ad Tech Services: ${adTechIntegrations.length}`);\n logger.log(`Site Tech Services: ${siteTechIntegrations.length}`);\n\n // Write to yaml\n writeTranscendYaml(output, {\n 'data-silos': dataSilos,\n });\n}\n"],"mappings":"6fAuBA,eAAsB,EAEpB,CACE,OACA,qBACA,SACA,aAAa,EAAE,CACf,gBAEa,CACf,EAAoB,KAAK,QAAQ,KAAK,EAGlC,CAAC,EAAW,EAAmB,EAAI,CAAC,EAAU,EAAmB,CAAC,aAAa,IACjF,EAAO,MAAM,EAAO,IAAI,2BAA2B,EAAmB,GAAG,CAAC,CAC1E,KAAK,QAAQ,KAAK,EAAE,EAItB,IAAM,EAAoB,EAAW,IAAK,GAAM,EAAE,MAAM,IAAI,CAAC,GAAG,CAG1D,EAAiB,EAAU,EAAmB,CAAC,IAAK,GAAc,CAEtE,GAAM,CAAE,aAAc,EAAY,EAAE,EAAK,EAAkB,EAAK,EAAoB,EAAU,CAAC,CAGzF,CAAE,kBAAiB,qBAAsB,EAC7C,EACA,CACE,gCACA,iBACD,CACF,CAED,MAAO,CACL,kBACA,oBACA,iBAAkB,EAAU,MAAM,IAAI,CAAC,GACxC,EACD,CAGI,EAAiD,EAAE,CACzD,EAAe,SAAS,CAAE,kBAAiB,oBAAmB,sBAAuB,CAC9D,CAAC,GAAG,EAAiB,GAAG,EAAkB,CAClD,QAAS,GAAa,CACjC,IAAM,EAAU,EAAS,eAAiB,EAAS,gBAE9C,EAAkB,KACrB,EAAkB,GAAW,EAAE,EAEjC,EAAkB,GAAU,KAAK,EAAiB,CAClD,EAAkB,GAAW,CAAC,GAAG,IAAI,IAAI,EAAkB,GAAS,CAAC,EACrE,EACF,CAGF,IAAM,EAAqB,CACzB,GAAG,IAAI,IACL,EACG,KAAK,CAAE,qBACN,EAAgB,IAAK,GAAS,EAAK,eAAiB,EAAK,gBAAgB,CAC1E,CACA,MAAM,CACV,CACF,CAGK,EAAuB,EAC3B,CACE,GAAG,IAAI,IACL,EACG,KAAK,CAAE,uBACN,EAAkB,IA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
|
|
1
|
+
import{r as e}from"./constants-CeMiHaHx.mjs";import{t}from"./logger-B-LXIf3U.mjs";import{n,t as r}from"./bluebird-CUitXgsY.mjs";import{t as i}from"./fetchConsentManagerId-CFkg3-RS.mjs";import{r as a}from"./makeGraphQLRequest-Cq26A_Lq.mjs";import{a as o}from"./writeCsv-B51ulrVl.mjs";import{t as s}from"./pullConsentManagerMetrics-FnhPEszu.mjs";import{t as c}from"./validateTranscendAuth-1W1IylqE.mjs";import{t as l}from"./done-input-validation-DLR0-MJ7.mjs";import u,{existsSync as d,mkdirSync as f}from"node:fs";import{join as p}from"node:path";import m from"colors";async function h({auth:h,start:g,end:_,folder:v,bin:y,transcendUrl:b}){let x=y;Object.values(i).includes(x)||(t.error(m.red(`Failed to parse argument "bin" with value "${y}"\nExpected one of: \n${Object.values(i).join(`
|
|
2
2
|
`)}`)),this.process.exit(1));let S=new Date(g),C=_?new Date(_):new Date;Number.isNaN(S.getTime())&&(t.error(m.red(`Start date provided is invalid date. Got --start="${g}" expected --start="01/01/2023"`)),this.process.exit(1)),Number.isNaN(C.getTime())&&(t.error(m.red(`End date provided is invalid date. Got --end="${_}" expected --end="01/01/2023"`)),this.process.exit(1)),S>C&&(t.error(m.red(`Got a start date "${S.toISOString()}" that was larger than the end date "${C.toISOString()}". Start date must be before end date.`)),this.process.exit(1)),l(this.process.exit);let w=await c(h);if(u.existsSync(v)&&!u.lstatSync(v).isDirectory()&&(t.error(m.red(`The provided argument "folder" was passed a file. expected: folder="./consent-metrics/"`)),this.process.exit(1)),d(v)||f(v),t.info(m.magenta(`Pulling consent metrics from start=${S.toString()} to end=${C.toISOString()} with bin size "${y}"`)),typeof w==`string`){try{let e=await s(a(b,w),{bin:x,start:S,end:C});await r(Object.entries(e),async([e,n])=>{await r(n,async({points:n,name:r})=>{let i=p(v,`${e}_${r}.csv`);t.info(m.magenta(`Writing configuration to file "${i}"...`)),await o(i,n.map(({key:e,value:t})=>({timestamp:e,value:t})))},{concurrency:5})},{concurrency:5})}catch(e){t.error(m.red(`An error occurred syncing the schema: ${e.message}`)),this.process.exit(1)}t.info(m.green(`Successfully synced consent metrics to disk in folder "${v}"! View at ${e}`))}else{let r=[];await n(w,async(e,n)=>{let i=`[${n+1}/${w.length}][${e.organizationName}] `;t.info(m.magenta(`~~~\n\n${i}Attempting to pull consent metrics...\n\n~~~`));let c=a(b,e.apiKey);try{let n=await s(c,{bin:x,start:S,end:C}),r=p(v,e.organizationName);d(r)||f(r),Object.entries(n).forEach(([e,n])=>{n.forEach(({points:n,name:i})=>{let a=p(r,`${e}_${i}.csv`);t.info(m.magenta(`Writing configuration to file "${a}"...`)),o(a,n.map(({key:e,value:t})=>({timestamp:e,value:t})))})}),t.info(m.green(`${i}Successfully pulled configuration!`))}catch{t.error(m.red(`${i}Failed to sync configuration.`)),r.push(e.organizationName)}}),r.length>0&&(t.info(m.red(`Sync encountered errors for "${r.join(`,`)}". View output above for more information, or check out ${e}`)),this.process.exit(1))}}export{h as pullConsentMetrics};
|
|
3
|
-
//# sourceMappingURL=impl-
|
|
3
|
+
//# sourceMappingURL=impl-BKH3QRLi.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"impl-
|
|
1
|
+
{"version":3,"file":"impl-BKH3QRLi.mjs","names":[],"sources":["../src/commands/consent/pull-consent-metrics/impl.ts"],"sourcesContent":["import fs, { existsSync, mkdirSync } from 'node:fs';\nimport { join } from 'node:path';\n\nimport colors from 'colors';\n\nimport { ADMIN_DASH_INTEGRATIONS } from '../../../constants.js';\nimport type { LocalContext } from '../../../context.js';\nimport { validateTranscendAuth } from '../../../lib/api-keys/index.js';\nimport { map, mapSeries } from '../../../lib/bluebird.js';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation.js';\nimport { pullConsentManagerMetrics } from '../../../lib/consent-manager/index.js';\nimport {\n buildTranscendGraphQLClient,\n ConsentManagerMetricBin,\n} from '../../../lib/graphql/index.js';\nimport { writeCsv } from '../../../lib/helpers/index.js';\nimport { logger } from '../../../logger.js';\n\nexport interface PullConsentMetricsCommandFlags {\n auth: string;\n start: Date;\n end?: Date;\n folder: string;\n bin: string;\n transcendUrl: string;\n}\n\nexport async function pullConsentMetrics(\n this: LocalContext,\n { auth, start, end, folder, bin, transcendUrl }: PullConsentMetricsCommandFlags,\n): Promise<void> {\n // Validate bin\n const parsedBin = bin as ConsentManagerMetricBin;\n if (!Object.values(ConsentManagerMetricBin).includes(parsedBin)) {\n logger.error(\n colors.red(\n `Failed to parse argument \"bin\" with value \"${bin}\"\\n` +\n `Expected one of: \\n${Object.values(ConsentManagerMetricBin).join('\\n')}`,\n ),\n );\n this.process.exit(1);\n }\n\n // Parse the dates\n const startDate = new Date(start);\n const endDate = end ? new Date(end) : new Date();\n if (Number.isNaN(startDate.getTime())) {\n logger.error(\n colors.red(\n `Start date provided is invalid date. Got --start=\"${start}\" expected --start=\"01/01/2023\"`,\n ),\n );\n this.process.exit(1);\n }\n if (Number.isNaN(endDate.getTime())) {\n logger.error(\n colors.red(\n `End date provided is invalid date. Got --end=\"${end}\" expected --end=\"01/01/2023\"`,\n ),\n );\n this.process.exit(1);\n }\n if (startDate > endDate) {\n logger.error(\n colors.red(\n `Got a start date \"${startDate.toISOString()}\" that was larger than the end date \"${endDate.toISOString()}\". ` +\n 'Start date must be before end date.',\n ),\n );\n this.process.exit(1);\n }\n\n doneInputValidation(this.process.exit);\n\n // Parse authentication as API key or path to list of API keys\n const apiKeyOrList = await validateTranscendAuth(auth);\n\n // Ensure folder either does not exist or is not a file\n if (fs.existsSync(folder) && !fs.lstatSync(folder).isDirectory()) {\n logger.error(\n colors.red(\n 'The provided argument \"folder\" was passed a file. expected: folder=\"./consent-metrics/\"',\n ),\n );\n this.process.exit(1);\n }\n\n // Create the folder if it does not exist\n if (!existsSync(folder)) {\n mkdirSync(folder);\n }\n\n logger.info(\n colors.magenta(\n `Pulling consent metrics from start=${startDate.toString()} to end=${endDate.toISOString()} with bin size \"${bin}\"`,\n ),\n );\n\n // Sync to Disk\n if (typeof apiKeyOrList === 'string') {\n try {\n // Create a GraphQL client\n const client = buildTranscendGraphQLClient(transcendUrl, apiKeyOrList);\n\n // Pull the metrics\n const configuration = await pullConsentManagerMetrics(client, {\n bin: parsedBin,\n start: startDate,\n end: endDate,\n });\n\n // Write to file\n await map(\n Object.entries(configuration),\n async ([metricName, metrics]) => {\n await map(\n metrics,\n async ({ points, name }) => {\n const file = join(folder, `${metricName}_${name}.csv`);\n logger.info(colors.magenta(`Writing configuration to file \"${file}\"...`));\n await writeCsv(\n file,\n points.map(({ key, value }) => ({\n timestamp: key,\n value,\n })),\n );\n },\n {\n concurrency: 5,\n },\n );\n },\n { concurrency: 5 },\n );\n } catch (err) {\n logger.error(colors.red(`An error occurred syncing the schema: ${err.message}`));\n this.process.exit(1);\n }\n\n // Indicate success\n logger.info(\n colors.green(\n `Successfully synced consent metrics to disk in folder \"${folder}\"! View at ${ADMIN_DASH_INTEGRATIONS}`,\n ),\n );\n } else {\n const encounteredErrors: string[] = [];\n await mapSeries(apiKeyOrList, async (apiKey, ind) => {\n const prefix = `[${ind + 1}/${apiKeyOrList.length}][${apiKey.organizationName}] `;\n logger.info(colors.magenta(`~~~\\n\\n${prefix}Attempting to pull consent metrics...\\n\\n~~~`));\n\n // Create a GraphQL client\n const client = buildTranscendGraphQLClient(transcendUrl, apiKey.apiKey);\n\n try {\n const configuration = await pullConsentManagerMetrics(client, {\n bin: parsedBin,\n start: startDate,\n end: endDate,\n });\n\n // ensure folder exists for that organization\n const subFolder = join(folder, apiKey.organizationName);\n if (!existsSync(subFolder)) {\n mkdirSync(subFolder);\n }\n\n // Write to file\n Object.entries(configuration).forEach(([metricName, metrics]) => {\n metrics.forEach(({ points, name }) => {\n const file = join(subFolder, `${metricName}_${name}.csv`);\n logger.info(colors.magenta(`Writing configuration to file \"${file}\"...`));\n writeCsv(\n file,\n points.map(({ key, value }) => ({\n timestamp: key,\n value,\n })),\n );\n });\n });\n\n logger.info(colors.green(`${prefix}Successfully pulled configuration!`));\n } catch (err) {\n logger.error(colors.red(`${prefix}Failed to sync configuration.`));\n encounteredErrors.push(apiKey.organizationName);\n }\n });\n\n if (encounteredErrors.length > 0) {\n logger.info(\n colors.red(\n `Sync encountered errors for \"${encounteredErrors.join(\n ',',\n )}\". View output above for more information, or check out ${ADMIN_DASH_INTEGRATIONS}`,\n ),\n );\n\n this.process.exit(1);\n }\n }\n}\n"],"mappings":"wjBA2BA,eAAsB,EAEpB,CAAE,OAAM,QAAO,MAAK,SAAQ,MAAK,gBAClB,CAEf,IAAM,EAAY,EACb,OAAO,OAAO,EAAwB,CAAC,SAAS,EAAU,GAC7D,EAAO,MACL,EAAO,IACL,8CAA8C,EAAI,wBAC1B,OAAO,OAAO,EAAwB,CAAC,KAAK;EAAK,GAC1E,CACF,CACD,KAAK,QAAQ,KAAK,EAAE,EAItB,IAAM,EAAY,IAAI,KAAK,EAAM,CAC3B,EAAU,EAAM,IAAI,KAAK,EAAI,CAAG,IAAI,KACtC,OAAO,MAAM,EAAU,SAAS,CAAC,GACnC,EAAO,MACL,EAAO,IACL,qDAAqD,EAAM,iCAC5D,CACF,CACD,KAAK,QAAQ,KAAK,EAAE,EAElB,OAAO,MAAM,EAAQ,SAAS,CAAC,GACjC,EAAO,MACL,EAAO,IACL,iDAAiD,EAAI,+BACtD,CACF,CACD,KAAK,QAAQ,KAAK,EAAE,EAElB,EAAY,IACd,EAAO,MACL,EAAO,IACL,qBAAqB,EAAU,aAAa,CAAC,uCAAuC,EAAQ,aAAa,CAAC,wCAE3G,CACF,CACD,KAAK,QAAQ,KAAK,EAAE,EAGtB,EAAoB,KAAK,QAAQ,KAAK,CAGtC,IAAM,EAAe,MAAM,EAAsB,EAAK,CAwBtD,GArBI,EAAG,WAAW,EAAO,EAAI,CAAC,EAAG,UAAU,EAAO,CAAC,aAAa,GAC9D,EAAO,MACL,EAAO,IACL,0FACD,CACF,CACD,KAAK,QAAQ,KAAK,EAAE,EAIjB,EAAW,EAAO,EACrB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AAO,QAAQ,EAAc,CAAC,SAAS,CAAC,EAAY,KAAa,CAC/D,EAAQ,SAAS,CAAE,SAAQ,UAAW,CACpC,IAAM,EAAO,EAAK,EAAW,GAAG,EAAW,GAAG,EAAK,MAAM,CACzD,EAAO,KAAK,EAAO,QAAQ,kCAAkC,EAAK,MAAM,CAAC,CACzE,EACE,EACA,EAAO,KAAK,CAAE,MAAK,YAAa,CAC9B,UAAW,EACX,QACD,EAAE,CACJ,EACD,EACF,CAEF,EAAO,KAAK,EAAO,MAAM,GAAG,EAAO,oCAAoC,CAAC,MAC5D,CACZ,EAAO,MAAM,EAAO,IAAI,GAAG,EAAO,+BAA+B,CAAC,CAClE,EAAkB,KAAK,EAAO,iBAAiB,GAEjD,CAEE,EAAkB,OAAS,IAC7B,EAAO,KACL,EAAO,IACL,gCAAgC,EAAkB,KAChD,IACD,CAAC,0DAA0D,IAC7D,CACF,CAED,KAAK,QAAQ,KAAK,EAAE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./logger-B-LXIf3U.mjs";import{t}from"./streamPrivacyRequestsToCsv-
|
|
2
|
-
//# sourceMappingURL=impl-
|
|
1
|
+
import{t as e}from"./logger-B-LXIf3U.mjs";import{t}from"./streamPrivacyRequestsToCsv-BK07Bm-T.mjs";import{t as n}from"./done-input-validation-DLR0-MJ7.mjs";import r from"colors";async function i({auth:i,transcendUrl:a,file:o,pageLimit:s,concurrency:c,actions:l,sombraAuth:u,skipRequestIdentifiers:d,statuses:f,createdAtBefore:p,createdAtAfter:m,updatedAtBefore:h,updatedAtAfter:g,showTests:_}){n(this.process.exit);let{filePaths:v,totalCount:y}=await t({transcendUrl:a,concurrency:c,pageLimit:s,actions:l,statuses:f,auth:i,sombraAuth:u,skipRequestIdentifiers:d,createdAtBefore:p,createdAtAfter:m,updatedAtBefore:h,updatedAtAfter:g,isTest:_,file:o});e.info(r.green(`Successfully wrote ${y} requests to ${v.length} file(s): ${v.join(`, `)}`))}export{i as _export};
|
|
2
|
+
//# sourceMappingURL=impl-BOUm7wly2.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"impl-
|
|
1
|
+
{"version":3,"file":"impl-BOUm7wly2.mjs","names":[],"sources":["../src/commands/request/export/impl.ts"],"sourcesContent":["import type { RequestAction, RequestStatus } from '@transcend-io/privacy-types';\nimport colors from 'colors';\n\nimport type { LocalContext } from '../../../context.js';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation.js';\nimport { streamPrivacyRequestsToCsv } from '../../../lib/requests/index.js';\nimport { logger } from '../../../logger.js';\n\nexport interface ExportCommandFlags {\n auth: string;\n sombraAuth?: string;\n actions?: RequestAction[];\n statuses?: RequestStatus[];\n transcendUrl: string;\n file: string;\n concurrency: number;\n createdAtBefore?: Date;\n createdAtAfter?: Date;\n updatedAtBefore?: Date;\n updatedAtAfter?: Date;\n showTests?: boolean;\n skipRequestIdentifiers?: boolean;\n pageLimit: number;\n}\n\n// `export` is a reserved keyword, so we need to prefix it with an underscore\n// eslint-disable-next-line no-underscore-dangle\nexport async function _export(\n this: LocalContext,\n {\n auth,\n transcendUrl,\n file,\n pageLimit,\n concurrency,\n actions,\n sombraAuth,\n skipRequestIdentifiers,\n statuses,\n createdAtBefore,\n createdAtAfter,\n updatedAtBefore,\n updatedAtAfter,\n showTests,\n }: ExportCommandFlags,\n): Promise<void> {\n doneInputValidation(this.process.exit);\n\n const { filePaths, totalCount } = await streamPrivacyRequestsToCsv({\n transcendUrl,\n concurrency,\n pageLimit,\n actions,\n statuses,\n auth,\n sombraAuth,\n skipRequestIdentifiers,\n createdAtBefore,\n createdAtAfter,\n updatedAtBefore,\n updatedAtAfter,\n isTest: showTests,\n file,\n });\n\n logger.info(\n colors.green(\n `Successfully wrote ${totalCount} requests to ` +\n `${filePaths.length} file(s): ${filePaths.join(', ')}`,\n ),\n );\n}\n"],"mappings":"kLA2BA,eAAsB,EAEpB,CACE,OACA,eACA,OACA,YACA,cACA,UACA,aACA,yBACA,WACA,kBACA,iBACA,kBACA,iBACA,aAEa,CACf,EAAoB,KAAK,QAAQ,KAAK,CAEtC,GAAM,CAAE,YAAW,cAAe,MAAM,EAA2B,CACjE,eACA,cACA,YACA,UACA,WACA,OACA,aACA,yBACA,kBACA,iBACA,kBACA,iBACA,OAAQ,EACR,OACD,CAAC,CAEF,EAAO,KACL,EAAO,MACL,sBAAsB,EAAW,eAC5B,EAAU,OAAO,YAAY,EAAU,KAAK,KAAK,GACvD,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as e}from"./constants-CeMiHaHx.mjs";import{t}from"./generateCrossAccountApiKeys-
|
|
2
|
-
//# sourceMappingURL=impl-
|
|
1
|
+
import{c as e}from"./constants-CeMiHaHx.mjs";import{t}from"./generateCrossAccountApiKeys-Bxc_dzMG.mjs";import{t as n}from"./done-input-validation-DLR0-MJ7.mjs";import{writeFileSync as r}from"node:fs";async function i({email:i,password:a,apiKeyTitle:o,file:s,scopes:c,deleteExistingApiKey:l,createNewApiKey:u,parentOrganizationId:d,transcendUrl:f}){n(this.process.exit);let{errors:p,apiKeys:m}=await t({transcendUrl:f,password:a,email:i,parentOrganizationId:d,deleteExistingApiKey:l,createNewApiKey:u,apiKeyTitle:o,scopes:c.map(t=>e[t].name)});r(s,`${JSON.stringify(m,null,2)}\n`),p.length>0&&this.process.exit(1)}export{i as generateApiKeys};
|
|
2
|
+
//# sourceMappingURL=impl-BUC4ZelU.mjs.map
|