@transcend-io/cli 10.14.0 → 10.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -47
- package/dist/app-COX_n1FP.mjs +131 -0
- package/dist/app-COX_n1FP.mjs.map +1 -0
- package/dist/{approvePrivacyRequests-BmjMLA3C.mjs → approvePrivacyRequests-DJItn7R6.mjs} +2 -2
- package/dist/{approvePrivacyRequests-BmjMLA3C.mjs.map → approvePrivacyRequests-DJItn7R6.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/{buildExamples-tZJof83F.mjs → buildExamples-CZ8kcEqO.mjs} +2 -2
- package/dist/{buildExamples-tZJof83F.mjs.map → buildExamples-CZ8kcEqO.mjs.map} +1 -1
- package/dist/{buildXdiSyncEndpoint-DsxFqz9E.mjs → buildXdiSyncEndpoint-CSGwr2H5.mjs} +2 -2
- package/dist/{buildXdiSyncEndpoint-DsxFqz9E.mjs.map → buildXdiSyncEndpoint-CSGwr2H5.mjs.map} +1 -1
- package/dist/bulkRestartRequests-D-t58SeM.mjs +2 -0
- package/dist/bulkRestartRequests-D-t58SeM.mjs.map +1 -0
- package/dist/{bulkRetryEnrichers-nBG87Q8B.mjs → bulkRetryEnrichers-BmwRLF2w.mjs} +2 -2
- package/dist/{bulkRetryEnrichers-nBG87Q8B.mjs.map → bulkRetryEnrichers-BmwRLF2w.mjs.map} +1 -1
- package/dist/{cancelPrivacyRequests-DBjBnX2p.mjs → cancelPrivacyRequests-CFCULeSv.mjs} +2 -2
- package/dist/{cancelPrivacyRequests-DBjBnX2p.mjs.map → cancelPrivacyRequests-CFCULeSv.mjs.map} +1 -1
- package/dist/{command-BDVLuBwL.mjs → command-8AnltUOG.mjs} +2 -2
- package/dist/{command-BDVLuBwL.mjs.map → command-8AnltUOG.mjs.map} +1 -1
- package/dist/{constants-Co8rkELu.mjs → constants-B7bW_WN2.mjs} +2 -2
- package/dist/{constants-Co8rkELu.mjs.map → constants-B7bW_WN2.mjs.map} +1 -1
- package/dist/{createExtraKeyHandler-CC-YNn6m.mjs → createExtraKeyHandler-DqiD609a.mjs} +2 -2
- package/dist/{createExtraKeyHandler-CC-YNn6m.mjs.map → createExtraKeyHandler-DqiD609a.mjs.map} +1 -1
- package/dist/{downloadPrivacyRequestFiles-C_60XBVX.mjs → downloadPrivacyRequestFiles-B7HNc-Y1.mjs} +2 -2
- package/dist/{downloadPrivacyRequestFiles-C_60XBVX.mjs.map → downloadPrivacyRequestFiles-B7HNc-Y1.mjs.map} +1 -1
- package/dist/formatPolicyEngineRequestError-C8g0v7nh.mjs +2 -0
- package/dist/formatPolicyEngineRequestError-C8g0v7nh.mjs.map +1 -0
- package/dist/{generateCrossAccountApiKeys-JvTpNM7h.mjs → generateCrossAccountApiKeys-kqzneWII.mjs} +2 -2
- package/dist/{generateCrossAccountApiKeys-JvTpNM7h.mjs.map → generateCrossAccountApiKeys-kqzneWII.mjs.map} +1 -1
- package/dist/impl--eayIBq5.mjs +2 -0
- package/dist/impl--eayIBq5.mjs.map +1 -0
- package/dist/{impl-TnRighiD.mjs → impl-0C9N9md8.mjs} +2 -2
- package/dist/{impl-TnRighiD.mjs.map → impl-0C9N9md8.mjs.map} +1 -1
- package/dist/{impl-CQ94Ys6i.mjs → impl-6rvA_yyd.mjs} +2 -2
- package/dist/{impl-CQ94Ys6i.mjs.map → impl-6rvA_yyd.mjs.map} +1 -1
- package/dist/{impl-pGIOCyRI.mjs → impl-B3u38Ct_.mjs} +1 -1
- package/dist/{impl-pGIOCyRI.mjs.map → impl-B3u38Ct_.mjs.map} +1 -1
- package/dist/{impl-CPZSFIEn2.mjs → impl-B9AtL5ta2.mjs} +2 -2
- package/dist/{impl-CPZSFIEn2.mjs.map → impl-B9AtL5ta2.mjs.map} +1 -1
- package/dist/{impl-BWt2WOj4.mjs → impl-BDc4D9nA.mjs} +2 -2
- package/dist/{impl-BWt2WOj4.mjs.map → impl-BDc4D9nA.mjs.map} +1 -1
- package/dist/{impl-bzESF0CN.mjs → impl-BJldWkkC.mjs} +1 -1
- package/dist/{impl-bzESF0CN.mjs.map → impl-BJldWkkC.mjs.map} +1 -1
- package/dist/{impl-Bf_Wy1-i.mjs → impl-BOXnkx44.mjs} +2 -2
- package/dist/{impl-Bf_Wy1-i.mjs.map → impl-BOXnkx44.mjs.map} +1 -1
- package/dist/{impl-CHA9Ioez2.mjs → impl-BUF6G3P32.mjs} +2 -2
- package/dist/{impl-CHA9Ioez2.mjs.map → impl-BUF6G3P32.mjs.map} +1 -1
- package/dist/{impl-DctqoksW2.mjs → impl-BVcXWJyI2.mjs} +2 -2
- package/dist/{impl-DctqoksW2.mjs.map → impl-BVcXWJyI2.mjs.map} +1 -1
- package/dist/impl-BbfuEhKu.mjs +2 -0
- package/dist/impl-BbfuEhKu.mjs.map +1 -0
- package/dist/{impl-DtjphdYd2.mjs → impl-BcIZos3y.mjs} +2 -2
- package/dist/impl-BcIZos3y.mjs.map +1 -0
- package/dist/{impl-8i-k9wal2.mjs → impl-Bkdu-3yo.mjs} +2 -2
- package/dist/impl-Bkdu-3yo.mjs.map +1 -0
- package/dist/{impl-CnfqPqKR.mjs → impl-Bq-tabdZ2.mjs} +2 -2
- package/dist/impl-Bq-tabdZ2.mjs.map +1 -0
- package/dist/{impl-BxJcoWPI.mjs → impl-Bul8gUqq.mjs} +2 -2
- package/dist/{impl-BxJcoWPI.mjs.map → impl-Bul8gUqq.mjs.map} +1 -1
- package/dist/{impl-kyicyfTy.mjs → impl-BuqBEZCk.mjs} +2 -2
- package/dist/{impl-kyicyfTy.mjs.map → impl-BuqBEZCk.mjs.map} +1 -1
- package/dist/{impl-DOp0z0s3.mjs → impl-BvOLkTWD.mjs} +2 -2
- package/dist/{impl-DOp0z0s3.mjs.map → impl-BvOLkTWD.mjs.map} +1 -1
- package/dist/{impl-DasdQVVL.mjs → impl-Bvkhu8fB.mjs} +2 -2
- package/dist/{impl-DasdQVVL.mjs.map → impl-Bvkhu8fB.mjs.map} +1 -1
- package/dist/{impl-CQcfrcc42.mjs → impl-CCSb7Pyd.mjs} +2 -2
- package/dist/impl-CCSb7Pyd.mjs.map +1 -0
- package/dist/{impl-BcP6NXxv.mjs → impl-CDNTdi62.mjs} +2 -2
- package/dist/{impl-BcP6NXxv.mjs.map → impl-CDNTdi62.mjs.map} +1 -1
- package/dist/{impl-0WH9Y-7n2.mjs → impl-CLrF-Xhp2.mjs} +2 -2
- package/dist/{impl-0WH9Y-7n2.mjs.map → impl-CLrF-Xhp2.mjs.map} +1 -1
- package/dist/impl-CX1J2iHE.mjs +2 -0
- package/dist/impl-CX1J2iHE.mjs.map +1 -0
- package/dist/{impl-vLFKOFp6.mjs → impl-C_K23xoc.mjs} +2 -2
- package/dist/{impl-vLFKOFp6.mjs.map → impl-C_K23xoc.mjs.map} +1 -1
- package/dist/{impl-DmsEZEkY2.mjs → impl-CeqMxdZm2.mjs} +2 -2
- package/dist/{impl-DmsEZEkY2.mjs.map → impl-CeqMxdZm2.mjs.map} +1 -1
- package/dist/{impl-BmB5DH95.mjs → impl-ChDwTQ3Z2.mjs} +2 -2
- package/dist/impl-ChDwTQ3Z2.mjs.map +1 -0
- package/dist/{impl-BQizHx-b.mjs → impl-CkFqqhQ-.mjs} +2 -2
- package/dist/{impl-BQizHx-b.mjs.map → impl-CkFqqhQ-.mjs.map} +1 -1
- package/dist/{impl-C9RGUYAT.mjs → impl-CkU-WD3b.mjs} +2 -2
- package/dist/{impl-C9RGUYAT.mjs.map → impl-CkU-WD3b.mjs.map} +1 -1
- package/dist/{impl-COWe0KAi.mjs → impl-Cx5U2XsV.mjs} +2 -2
- package/dist/{impl-COWe0KAi.mjs.map → impl-Cx5U2XsV.mjs.map} +1 -1
- package/dist/impl-DGm5NVUi.mjs +3 -0
- package/dist/impl-DGm5NVUi.mjs.map +1 -0
- package/dist/{impl-BcirxaFO.mjs → impl-DMbgck0i.mjs} +2 -2
- package/dist/{impl-BcirxaFO.mjs.map → impl-DMbgck0i.mjs.map} +1 -1
- package/dist/{impl-BM0EEvkt.mjs → impl-DQH1CGup.mjs} +2 -2
- package/dist/{impl-BM0EEvkt.mjs.map → impl-DQH1CGup.mjs.map} +1 -1
- package/dist/{impl-5pww5SHw.mjs → impl-DTDnN3Hn.mjs} +2 -2
- package/dist/{impl-5pww5SHw.mjs.map → impl-DTDnN3Hn.mjs.map} +1 -1
- package/dist/{impl-Cih-nyPz.mjs → impl-DYsJKLfp.mjs} +2 -2
- package/dist/{impl-Cih-nyPz.mjs.map → impl-DYsJKLfp.mjs.map} +1 -1
- package/dist/impl-DiRx33sh.mjs +2 -0
- package/dist/impl-DiRx33sh.mjs.map +1 -0
- package/dist/{impl-Cp_cXJgT2.mjs → impl-DiysQB762.mjs} +2 -2
- package/dist/{impl-Cp_cXJgT2.mjs.map → impl-DiysQB762.mjs.map} +1 -1
- package/dist/{impl-DQdzYE12.mjs → impl-DqcpxYHF.mjs} +1 -1
- package/dist/{impl-DQdzYE12.mjs.map → impl-DqcpxYHF.mjs.map} +1 -1
- package/dist/{impl-DtVfOZhs.mjs → impl-DqyYxDti.mjs} +2 -2
- package/dist/{impl-DtVfOZhs.mjs.map → impl-DqyYxDti.mjs.map} +1 -1
- package/dist/{impl-DpU2s1HR.mjs → impl-RqwgNa2O.mjs} +2 -2
- package/dist/{impl-DpU2s1HR.mjs.map → impl-RqwgNa2O.mjs.map} +1 -1
- package/dist/{impl-cro4x_eG.mjs → impl-TTeKThep2.mjs} +2 -2
- package/dist/impl-TTeKThep2.mjs.map +1 -0
- package/dist/{impl-CJIfMPOK.mjs → impl-X13pzYJN2.mjs} +2 -2
- package/dist/impl-X13pzYJN2.mjs.map +1 -0
- package/dist/{impl-B4mrbkzO.mjs → impl-e-_DWiv4.mjs} +2 -2
- package/dist/{impl-B4mrbkzO.mjs.map → impl-e-_DWiv4.mjs.map} +1 -1
- package/dist/index.d.mts +17 -13
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{markRequestDataSiloIdsCompleted-DYsj2ONd.mjs → markRequestDataSiloIdsCompleted-nAV0VLEA.mjs} +2 -2
- package/dist/{markRequestDataSiloIdsCompleted-DYsj2ONd.mjs.map → markRequestDataSiloIdsCompleted-nAV0VLEA.mjs.map} +1 -1
- package/dist/{markSilentPrivacyRequests-DQYDLnBX.mjs → markSilentPrivacyRequests-BhF4r8n9.mjs} +2 -2
- package/dist/{markSilentPrivacyRequests-DQYDLnBX.mjs.map → markSilentPrivacyRequests-BhF4r8n9.mjs.map} +1 -1
- package/dist/{notifyPrivacyRequestsAdditionalTime-BYpsssGt.mjs → notifyPrivacyRequestsAdditionalTime-B6e9SfP7.mjs} +2 -2
- package/dist/{notifyPrivacyRequestsAdditionalTime-BYpsssGt.mjs.map → notifyPrivacyRequestsAdditionalTime-B6e9SfP7.mjs.map} +1 -1
- package/dist/{pullChunkedCustomSiloOutstandingIdentifiers-aBPmYMAU.mjs → pullChunkedCustomSiloOutstandingIdentifiers-DiZTo2K_.mjs} +2 -2
- package/dist/{pullChunkedCustomSiloOutstandingIdentifiers-aBPmYMAU.mjs.map → pullChunkedCustomSiloOutstandingIdentifiers-DiZTo2K_.mjs.map} +1 -1
- package/dist/{pullManualEnrichmentIdentifiersToCsv-DGdMOzd_.mjs → pullManualEnrichmentIdentifiersToCsv--dw03arC.mjs} +2 -2
- package/dist/{pullManualEnrichmentIdentifiersToCsv-DGdMOzd_.mjs.map → pullManualEnrichmentIdentifiersToCsv--dw03arC.mjs.map} +1 -1
- package/dist/{pushCronIdentifiersFromCsv-mMGYEnWE.mjs → pushCronIdentifiersFromCsv-DdcsnXf5.mjs} +2 -2
- package/dist/{pushCronIdentifiersFromCsv-mMGYEnWE.mjs.map → pushCronIdentifiersFromCsv-DdcsnXf5.mjs.map} +1 -1
- package/dist/{pushManualEnrichmentIdentifiersFromCsv-BJtIFf35.mjs → pushManualEnrichmentIdentifiersFromCsv-BYJCQOI-.mjs} +2 -2
- package/dist/{pushManualEnrichmentIdentifiersFromCsv-BJtIFf35.mjs.map → pushManualEnrichmentIdentifiersFromCsv-BYJCQOI-.mjs.map} +1 -1
- package/dist/{removeUnverifiedRequestIdentifiers-GM1MhbRO.mjs → removeUnverifiedRequestIdentifiers-CC471vSR.mjs} +2 -2
- package/dist/{removeUnverifiedRequestIdentifiers-GM1MhbRO.mjs.map → removeUnverifiedRequestIdentifiers-CC471vSR.mjs.map} +1 -1
- package/dist/{renderTable-BgjVr6ch.mjs → renderTable-BzIh5FoT.mjs} +1 -1
- package/dist/{renderTable-BgjVr6ch.mjs.map → renderTable-BzIh5FoT.mjs.map} +1 -1
- package/dist/{resolveBundleIdByName-DdemhmTX.mjs → resolveBundleIdByName-Bxoxa8CK.mjs} +1 -1
- package/dist/{resolveBundleIdByName-DdemhmTX.mjs.map → resolveBundleIdByName-Bxoxa8CK.mjs.map} +1 -1
- package/dist/{retryRequestDataSilos-DkCW5Dap.mjs → retryRequestDataSilos-DlkJmEjH.mjs} +2 -2
- package/dist/{retryRequestDataSilos-DkCW5Dap.mjs.map → retryRequestDataSilos-DlkJmEjH.mjs.map} +1 -1
- package/dist/{skipPreflightJobs-BBfI9gnC.mjs → skipPreflightJobs-xVBZC-iI.mjs} +2 -2
- package/dist/{skipPreflightJobs-BBfI9gnC.mjs.map → skipPreflightJobs-xVBZC-iI.mjs.map} +1 -1
- package/dist/{skipRequestDataSilos-CjaWLHRh.mjs → skipRequestDataSilos-BriqhLT3.mjs} +2 -2
- package/dist/{skipRequestDataSilos-CjaWLHRh.mjs.map → skipRequestDataSilos-BriqhLT3.mjs.map} +1 -1
- package/dist/{streamPrivacyRequestsToCsv-DeBjRAo6.mjs → streamPrivacyRequestsToCsv-D8b097c1.mjs} +2 -2
- package/dist/{streamPrivacyRequestsToCsv-DeBjRAo6.mjs.map → streamPrivacyRequestsToCsv-D8b097c1.mjs.map} +1 -1
- package/dist/{updateConsentManagerVersionToLatest-2SBywtZH.mjs → updateConsentManagerVersionToLatest-w_ftOmxi.mjs} +2 -2
- package/dist/{updateConsentManagerVersionToLatest-2SBywtZH.mjs.map → updateConsentManagerVersionToLatest-w_ftOmxi.mjs.map} +1 -1
- package/dist/{uploadConsents-K3cGrF3M.mjs → uploadConsents-D8IJDaTN.mjs} +2 -2
- package/dist/{uploadConsents-K3cGrF3M.mjs.map → uploadConsents-D8IJDaTN.mjs.map} +1 -1
- package/dist/{uploadCookiesFromCsv-Cf4q-K4o.mjs → uploadCookiesFromCsv-8hq-Of_p.mjs} +2 -2
- package/dist/{uploadCookiesFromCsv-Cf4q-K4o.mjs.map → uploadCookiesFromCsv-8hq-Of_p.mjs.map} +1 -1
- package/dist/{uploadDataFlowsFromCsv-CrC_UGCw.mjs → uploadDataFlowsFromCsv-B854o0O5.mjs} +2 -2
- package/dist/{uploadDataFlowsFromCsv-CrC_UGCw.mjs.map → uploadDataFlowsFromCsv-B854o0O5.mjs.map} +1 -1
- package/dist/{uploadPrivacyRequestsFromCsv-CtLCdggr.mjs → uploadPrivacyRequestsFromCsv-D-RTgJsx.mjs} +2 -2
- package/dist/{uploadPrivacyRequestsFromCsv-CtLCdggr.mjs.map → uploadPrivacyRequestsFromCsv-D-RTgJsx.mjs.map} +1 -1
- package/package.json +2 -2
- package/dist/app-jtpjVOh5.mjs +0 -131
- package/dist/app-jtpjVOh5.mjs.map +0 -1
- package/dist/bulkRestartRequests-Cg0_c6sr.mjs +0 -2
- package/dist/bulkRestartRequests-Cg0_c6sr.mjs.map +0 -1
- package/dist/impl-8i-k9wal2.mjs.map +0 -1
- package/dist/impl-BmB5DH95.mjs.map +0 -1
- package/dist/impl-CJIfMPOK.mjs.map +0 -1
- package/dist/impl-CQcfrcc42.mjs.map +0 -1
- package/dist/impl-CnfqPqKR.mjs.map +0 -1
- package/dist/impl-DZ2ESN0W.mjs +0 -2
- package/dist/impl-DZ2ESN0W.mjs.map +0 -1
- package/dist/impl-DtjphdYd2.mjs.map +0 -1
- package/dist/impl-DxziWqbj.mjs +0 -2
- package/dist/impl-DxziWqbj.mjs.map +0 -1
- package/dist/impl-QhkS8iHU.mjs +0 -2
- package/dist/impl-QhkS8iHU.mjs.map +0 -1
- package/dist/impl-WYYi6kC-.mjs +0 -2
- package/dist/impl-WYYi6kC-.mjs.map +0 -1
- package/dist/impl-cro4x_eG.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulkRestartRequests-D-t58SeM.mjs","names":[],"sources":["../src/lib/requests/restartPrivacyRequest.ts","../src/lib/requests/bulkRestartRequests.ts"],"sourcesContent":["import { IdentifierType, RestartIdentifierStrategy } from '@transcend-io/privacy-types';\nimport type { RequestIdentifier } from '@transcend-io/sdk';\nimport { apply, decodeCodec } from '@transcend-io/type-utils';\nimport type { Got } from 'got';\nimport * as t from 'io-ts';\nimport { groupBy } from 'lodash-es';\n\nimport type { PrivacyRequest } from '../graphql/index.js';\nimport { IDENTIFIER_BLOCK_LIST } from './constants.js';\nimport { PrivacyRequestResponse } from './submitPrivacyRequest.js';\n\n/**\n * Restart a privacy request to the Transcend API\n *\n * @param sombra - Sombra instance configured to make requests\n * @param request - Request to restart\n * @param input - Request input\n * @returns Successfully submitted request\n */\nexport async function restartPrivacyRequest(\n sombra: Got,\n request: PrivacyRequest,\n {\n sendEmailReceipt = false,\n skipWaitingPeriod = false,\n emailIsVerified = true,\n requestIdentifiers = [],\n restartIdentifierStrategy,\n }: {\n /** List of request identifiers to include */\n requestIdentifiers?: RequestIdentifier[];\n /** When true, send an email receipt to data subject */\n sendEmailReceipt?: boolean;\n /** Whether the email is verified */\n emailIsVerified?: boolean;\n /** Whether to skip waiting period */\n skipWaitingPeriod?: boolean;\n /** How request identifiers should be handled when restarting */\n restartIdentifierStrategy?: RestartIdentifierStrategy;\n } = {},\n): Promise<PrivacyRequestResponse> {\n // Make the GraphQL request\n const response = await sombra\n .post('v1/data-subject-request', {\n json: {\n type: request.type,\n subject: {\n coreIdentifier: request.coreIdentifier,\n email: request.email,\n emailIsVerified,\n ...(requestIdentifiers.length > 0\n ? {\n attestedExtraIdentifiers: apply(\n groupBy(\n requestIdentifiers\n .filter(\n (ri) =>\n // these are already submitted above\n !(ri.name === 'email' && ri.value === request.email) &&\n !IDENTIFIER_BLOCK_LIST.includes(ri.name),\n )\n .map((ri) => ({\n ...ri,\n type: Object.values(IdentifierType).includes(\n ri.name as any, // eslint-disable-line @typescript-eslint/no-explicit-any\n )\n ? ri.name\n : IdentifierType.Custom,\n })),\n 'type',\n ),\n (values, type) =>\n values.map(({ name, value }) => ({\n ...(type === IdentifierType.Custom ? { name } : {}),\n value,\n })),\n ),\n }\n : {}),\n },\n requestId: request.id,\n subjectType: request.subjectType,\n isSilent: request.isSilent,\n isTest: request.isTest,\n locale: request.locale,\n skipWaitingPeriod,\n createdAt: request.createdAt,\n details: `Restarted by Transcend cli: \"tr-request-restart\" - ${request.details}`,\n skipSendingReceipt: !sendEmailReceipt,\n ...(restartIdentifierStrategy ? { restartIdentifierStrategy } : {}),\n },\n })\n .json();\n\n const { request: requestResponse } = decodeCodec(\n t.type({\n request: PrivacyRequestResponse,\n }),\n response,\n );\n return requestResponse;\n}\n","import { join, resolve } from 'node:path';\n\nimport { PersistedState } from '@transcend-io/persisted-state';\nimport {\n RequestAction,\n RequestStatus,\n RestartIdentifierStrategy,\n} from '@transcend-io/privacy-types';\nimport {\n buildTranscendGraphQLClient,\n createSombraGotInstance,\n fetchAllRequestIdentifiers,\n validateSombraVersion,\n} from '@transcend-io/sdk';\nimport { map } from '@transcend-io/utils';\nimport cliProgress from 'cli-progress';\nimport colors from 'colors';\nimport * as t from 'io-ts';\nimport { difference } from 'lodash-es';\n\nimport { DEFAULT_TRANSCEND_API } from '../../constants.js';\nimport { logger } from '../../logger.js';\nimport { fetchAllRequests } from '../graphql/index.js';\nimport { SuccessfulRequest } from './constants.js';\nimport { extractClientError } from './extractClientError.js';\nimport { restartPrivacyRequest } from './restartPrivacyRequest.js';\n\n/** Minimal state we need to keep a list of requests */\nconst ErrorRequest = t.intersection([\n SuccessfulRequest,\n t.type({\n error: t.string,\n }),\n]);\n\n/** Type override */\ntype ErrorRequest = t.TypeOf<typeof ErrorRequest>;\n\n/** Persist this data between runs of the script */\nconst CachedRequestState = t.type({\n restartedRequests: t.array(SuccessfulRequest),\n failingRequests: t.array(ErrorRequest),\n});\n\n/**\n * Upload a set of privacy requests from CSV\n *\n * @param options - Options\n */\nexport async function bulkRestartRequests({\n requestReceiptFolder,\n auth,\n sombraAuth,\n requestActions,\n requestStatuses,\n createdAtBefore,\n createdAtAfter,\n updatedAtBefore,\n updatedAtAfter,\n transcendUrl = DEFAULT_TRANSCEND_API,\n requestIds = [],\n createdAt = new Date(),\n silentModeBefore,\n sendEmailReceipt = false,\n emailIsVerified = true,\n copyIdentifiers = false,\n restartIdentifierStrategy,\n skipWaitingPeriod = false,\n concurrency = 20,\n}: {\n /** Actions to filter for */\n requestActions: RequestAction[];\n /** Statues to filter for */\n requestStatuses: RequestStatus[];\n /** File where request receipts are stored */\n requestReceiptFolder: string;\n /** Transcend API key authentication */\n auth: string;\n /** API URL for Transcend backend */\n transcendUrl?: string;\n /** Sombra API key authentication */\n sombraAuth?: string;\n /** Request IDs to filter for */\n requestIds?: string[];\n /** Whether to re-verify the email when restarting the request */\n emailIsVerified?: boolean;\n /** Filter for requests that were submitted before this date */\n createdAt?: Date;\n /** Requests that have been open for this length of time should be marked as silent mode */\n silentModeBefore?: Date;\n /** Send an email receipt to the restarted requests */\n sendEmailReceipt?: boolean;\n /** Copy over all identifiers rather than restarting the request only with the core identifier */\n copyIdentifiers?: boolean;\n /** How request identifiers should be handled when restarting */\n restartIdentifierStrategy?: RestartIdentifierStrategy;\n /** Skip the waiting period when restarting requests */\n skipWaitingPeriod?: boolean;\n /** Filter for requests created before this date */\n createdAtBefore?: Date;\n /** Filter for requests created after this date */\n createdAtAfter?: Date;\n /** Filter for requests updated before this date */\n updatedAtBefore?: Date;\n /** Filter for requests updated after this date */\n updatedAtAfter?: Date;\n /** Concurrency to upload requests at */\n concurrency?: number;\n}): Promise<void> {\n // Time duration\n const t0 = new Date().getTime();\n // create a new progress bar instance and use shades_classic theme\n const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);\n\n // Create a new state file to store the requests from this run.\n // `toISOString()` contains colons (e.g. 2026-07-06T04:33:12.345Z) which are\n // illegal characters in Windows filenames, so strip them out to keep the\n // auto-generated receipt filename cross-platform.\n const cacheFile = join(\n requestReceiptFolder,\n `tr-request-restart-${new Date().toISOString().replace(/:/g, '-')}.json`,\n );\n const state = new PersistedState(cacheFile, CachedRequestState, {\n restartedRequests: [],\n failingRequests: [],\n });\n\n // Create sombra instance to communicate with\n const sombra = await createSombraGotInstance(transcendUrl, auth, {\n logger,\n sombraApiKey: sombraAuth,\n sombraUrl: process.env.SOMBRA_URL,\n });\n\n // Find all requests made before createdAt that are in a removing data state\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n const allRequests = await fetchAllRequests(client, {\n requestIds,\n actions: requestActions,\n statuses: requestStatuses,\n createdAtBefore,\n createdAtAfter,\n updatedAtBefore,\n updatedAtAfter,\n });\n const requests = allRequests.filter((request) => new Date(request.createdAt) < createdAt);\n logger.info(`Found ${requests.length} requests to restart`);\n\n if (copyIdentifiers) {\n logger.info('copyIdentifiers detected - All Identifiers will be copied.');\n }\n if (restartIdentifierStrategy) {\n logger.info(\n `restartIdentifierStrategy detected - Using \"${restartIdentifierStrategy}\" strategy.`,\n );\n }\n if (sendEmailReceipt) {\n logger.info('sendEmailReceipt detected - Email receipts will be sent.');\n }\n if (skipWaitingPeriod) {\n logger.info('skipWaitingPeriod detected - Waiting period will be skipped.');\n }\n\n // Validate request IDs\n if (requestIds.length > 0 && requestIds.length !== requests.length) {\n const missingRequests = difference(\n requestIds,\n requests.map(({ id }) => id),\n );\n if (missingRequests.length > 0) {\n logger.error(\n colors.red(`Failed to find the following requests by ID: ${missingRequests.join(',')}.`),\n );\n process.exit(1);\n }\n }\n\n if (copyIdentifiers) {\n await validateSombraVersion(client, { logger });\n }\n\n // Map over the requests\n let total = 0;\n progressBar.start(requests.length, 0);\n await map(\n requests,\n async (request, ind) => {\n try {\n // Pull the request identifiers\n const requestIdentifiers = copyIdentifiers\n ? await fetchAllRequestIdentifiers(client, sombra, {\n filterBy: { requestId: request.id },\n skipSombraCheck: true,\n logger,\n })\n : [];\n\n // Make the GraphQL request to restart the request\n const requestResponse = await restartPrivacyRequest(\n sombra,\n {\n ...request,\n // override silent mode\n isSilent:\n !!silentModeBefore && new Date(request.createdAt) < silentModeBefore\n ? true\n : request.isSilent,\n },\n {\n requestIdentifiers,\n skipWaitingPeriod,\n sendEmailReceipt,\n emailIsVerified,\n restartIdentifierStrategy,\n },\n );\n\n // Cache successful upload\n const restartedRequests = state.getValue('restartedRequests');\n restartedRequests.push({\n id: requestResponse.id,\n link: requestResponse.link,\n rowIndex: ind,\n coreIdentifier: requestResponse.coreIdentifier,\n attemptedAt: new Date().toISOString(),\n });\n await state.setValue(restartedRequests, 'restartedRequests');\n } catch (err) {\n const msg = `${err.message} - ${JSON.stringify(err.response?.body, null, 2)}`;\n const clientError = extractClientError(msg);\n\n const failingRequests = state.getValue('failingRequests');\n failingRequests.push({\n id: request.id,\n link: request.link,\n rowIndex: ind,\n coreIdentifier: request.coreIdentifier,\n attemptedAt: new Date().toISOString(),\n error: clientError || msg,\n });\n await state.setValue(failingRequests, 'failingRequests');\n }\n total += 1;\n progressBar.update(total);\n },\n { concurrency },\n );\n\n progressBar.stop();\n const t1 = new Date().getTime();\n const totalTime = t1 - t0;\n\n // Log completion time\n logger.info(colors.green(`Completed restarting of requests in \"${totalTime / 1000}\" seconds.`));\n\n // Log errors\n if (state.getValue('failingRequests').length > 0) {\n logger.error(\n colors.red(\n `Encountered \"${state.getValue('failingRequests').length}\" errors. ` +\n `See \"${resolve(cacheFile)}\" to review the error messages and inputs.`,\n ),\n );\n process.exit(1);\n }\n}\n"],"mappings":"myBAmBA,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,kBAAkB,CAAC,OAAO,iBAC/C,EAAQ,EAAU,CAAC,4CAC9B,CACF,CACD,QAAQ,KAAK,EAAE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e}from"./constants-
|
|
2
|
-
//# sourceMappingURL=bulkRetryEnrichers-
|
|
1
|
+
import{a as e}from"./constants-B7bW_WN2.mjs";import{t}from"./logger-D1tXVwJj.mjs";import{r as n}from"./fetchAllRequests-rDVYKbqL.mjs";import{RequestEnricherStatus as r,RequestStatus as i}from"@transcend-io/privacy-types";import{difference as a}from"lodash-es";import o from"colors";import{buildTranscendGraphQLClient as s,fetchAllRequestEnrichers as c,retryRequestEnricher as l}from"@transcend-io/sdk";import{map as u}from"@transcend-io/utils";import d from"cli-progress";async function f({auth:f,requestActions:p=[],createdAtBefore:m,createdAtAfter:h,updatedAtBefore:g,updatedAtAfter:_,transcendUrl:v=e,requestEnricherStatuses:y=Object.values(r),requestIds:b=[],enricherId:x,concurrency:S=20}){let C=new Date().getTime(),w=new d.SingleBar({},d.Presets.shades_classic),T=s(v,f);t.info(o.magenta(`Fetching requests to restart...`));let E=await n(T,{actions:p,statuses:[i.Enriching],createdAtBefore:m,createdAtAfter:h,updatedAtBefore:g,updatedAtAfter:_,requestIds:b}),D=0;if(b.length>0&&b.length!==E.length){let e=a(b,E.map(({id:e})=>e));e.length>0&&(t.error(o.red(`Failed to find the following requests by ID: ${e.join(`,`)}.`)),process.exit(1))}let O=0;w.start(E.length,0),await u(E,async e=>{await u((await c(T,{filterBy:{requestId:e.id},logger:t})).filter(e=>e.enricher.id===x&&y.includes(e.status)),async e=>{await l(T,{id:e.id,logger:t}),D+=1}),O+=1,w.update(O)},{concurrency:S}),w.stop();let k=new Date().getTime()-C;t.info(o.green(`Completed restarting of ${E.length} requests and ${D} enrichers in "${k/1e3}" seconds.`))}export{f as t};
|
|
2
|
+
//# sourceMappingURL=bulkRetryEnrichers-BmwRLF2w.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulkRetryEnrichers-
|
|
1
|
+
{"version":3,"file":"bulkRetryEnrichers-BmwRLF2w.mjs","names":[],"sources":["../src/lib/requests/bulkRetryEnrichers.ts"],"sourcesContent":["import { RequestAction, RequestEnricherStatus, RequestStatus } from '@transcend-io/privacy-types';\nimport {\n buildTranscendGraphQLClient,\n fetchAllRequestEnrichers,\n retryRequestEnricher,\n} from '@transcend-io/sdk';\nimport { map } from '@transcend-io/utils';\nimport cliProgress from 'cli-progress';\nimport colors from 'colors';\nimport { difference } from 'lodash-es';\n\nimport { DEFAULT_TRANSCEND_API } from '../../constants.js';\nimport { logger } from '../../logger.js';\nimport { fetchAllRequests } from '../graphql/index.js';\n\n/**\n * Restart a bunch of request enrichers\n *\n * @param options - Options\n */\nexport async function bulkRetryEnrichers({\n auth,\n requestActions = [],\n createdAtBefore,\n createdAtAfter,\n updatedAtBefore,\n updatedAtAfter,\n transcendUrl = DEFAULT_TRANSCEND_API,\n requestEnricherStatuses = Object.values(RequestEnricherStatus),\n requestIds = [],\n enricherId,\n concurrency = 20,\n}: {\n /** Actions to filter for */\n requestActions?: RequestAction[];\n /** Request enricher statuses to restart - defaults to all statuses */\n requestEnricherStatuses?: RequestEnricherStatus[];\n /** Transcend API key authentication */\n auth: string;\n /** The ID of the enricher to restart */\n enricherId: string;\n /** API URL for Transcend backend */\n transcendUrl?: string;\n /** Request IDs to filter for */\n requestIds?: string[];\n /** Filter for requests created before this date */\n createdAtBefore?: Date;\n /** Filter for requests created after this date */\n createdAtAfter?: Date;\n /** Filter for requests updated before this date */\n updatedAtBefore?: Date;\n /** Filter for requests updated after this date */\n updatedAtAfter?: Date;\n /** Concurrency to upload requests at */\n concurrency?: number;\n}): Promise<void> {\n // Time duration\n const t0 = new Date().getTime();\n // create a new progress bar instance and use shades_classic theme\n const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);\n\n // Find all requests made before createdAt that are in a removing data state\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n logger.info(colors.magenta('Fetching requests to restart...'));\n\n const requests = await fetchAllRequests(client, {\n actions: requestActions,\n statuses: [RequestStatus.Enriching],\n createdAtBefore,\n createdAtAfter,\n updatedAtBefore,\n updatedAtAfter,\n requestIds,\n });\n\n let totalRestarted = 0;\n\n // Validate request IDs\n if (requestIds.length > 0 && requestIds.length !== requests.length) {\n const missingRequests = difference(\n requestIds,\n requests.map(({ id }) => id),\n );\n if (missingRequests.length > 0) {\n logger.error(\n colors.red(`Failed to find the following requests by ID: ${missingRequests.join(',')}.`),\n );\n process.exit(1);\n }\n }\n\n // Map over the requests\n let total = 0;\n progressBar.start(requests.length, 0);\n await map(\n requests,\n async (request) => {\n // Pull the request identifiers\n const requestEnrichers = await fetchAllRequestEnrichers(client, {\n filterBy: { requestId: request.id },\n logger,\n });\n const requestEnrichersToRestart = requestEnrichers.filter(\n (requestEnricher) =>\n requestEnricher.enricher.id === enricherId &&\n requestEnricherStatuses.includes(requestEnricher.status),\n );\n await map(requestEnrichersToRestart, async (requestEnricher) => {\n await retryRequestEnricher(client, { id: requestEnricher.id, logger });\n totalRestarted += 1;\n });\n\n // Cache successful upload\n total += 1;\n progressBar.update(total);\n },\n { concurrency },\n );\n\n progressBar.stop();\n const t1 = new Date().getTime();\n const totalTime = t1 - t0;\n\n // Log completion time\n logger.info(\n colors.green(\n `Completed restarting of ${requests.length} requests and ${totalRestarted} enrichers in \"${\n totalTime / 1000\n }\" seconds.`,\n ),\n );\n}\n"],"mappings":"wdAoBA,eAAsB,EAAmB,CACvC,OACA,iBAAiB,EAAE,CACnB,kBACA,iBACA,kBACA,iBACA,eAAe,EACf,0BAA0B,OAAO,OAAO,EAAsB,CAC9D,aAAa,EAAE,CACf,aACA,cAAc,IAwBE,CAEhB,IAAM,EAAK,IAAI,MAAM,CAAC,SAAS,CAEzB,EAAc,IAAI,EAAY,UAAU,EAAE,CAAE,EAAY,QAAQ,eAAe,CAG/E,EAAS,EAA4B,EAAc,EAAK,CAE9D,EAAO,KAAK,EAAO,QAAQ,kCAAkC,CAAC,CAE9D,IAAM,EAAW,MAAM,EAAiB,EAAQ,CAC9C,QAAS,EACT,SAAU,CAAC,EAAc,UAAU,CACnC,kBACA,iBACA,kBACA,iBACA,aACD,CAAC,CAEE,EAAiB,EAGrB,GAAI,EAAW,OAAS,GAAK,EAAW,SAAW,EAAS,OAAQ,CAClE,IAAM,EAAkB,EACtB,EACA,EAAS,KAAK,CAAE,QAAS,EAAG,CAC7B,CACG,EAAgB,OAAS,IAC3B,EAAO,MACL,EAAO,IAAI,gDAAgD,EAAgB,KAAK,IAAI,CAAC,GAAG,CACzF,CACD,QAAQ,KAAK,EAAE,EAKnB,IAAI,EAAQ,EACZ,EAAY,MAAM,EAAS,OAAQ,EAAE,CACrC,MAAM,EACJ,EACA,KAAO,IAAY,CAWjB,MAAM,GAL4B,MAJH,EAAyB,EAAQ,CAC9D,SAAU,CAAE,UAAW,EAAQ,GAAI,CACnC,SACD,CAAC,EACiD,OAChD,GACC,EAAgB,SAAS,KAAO,GAChC,EAAwB,SAAS,EAAgB,OAAO,CAEzB,CAAE,KAAO,IAAoB,CAC9D,MAAM,EAAqB,EAAQ,CAAE,GAAI,EAAgB,GAAI,SAAQ,CAAC,CACtE,GAAkB,GAClB,CAGF,GAAS,EACT,EAAY,OAAO,EAAM,EAE3B,CAAE,cAAa,CAChB,CAED,EAAY,MAAM,CAElB,IAAM,EADK,IAAI,MAAM,CAAC,SACF,CAAG,EAGvB,EAAO,KACL,EAAO,MACL,2BAA2B,EAAS,OAAO,gBAAgB,EAAe,iBACxE,EAAY,IACb,YACF,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e}from"./constants-
|
|
2
|
-
//# sourceMappingURL=cancelPrivacyRequests-
|
|
1
|
+
import{a as e}from"./constants-B7bW_WN2.mjs";import{t}from"./logger-D1tXVwJj.mjs";import{n,o as r}from"./request-CdglUNWv.mjs";import{r as i}from"./fetchAllRequests-rDVYKbqL.mjs";import{RequestStatus as a}from"@transcend-io/privacy-types";import o from"colors";import{buildTranscendGraphQLClient as s,fetchAllTemplates as c,makeGraphQLRequest as l}from"@transcend-io/sdk";import{map as u}from"@transcend-io/utils";import d from"cli-progress";async function f({requestActions:f,cancellationTitle:p,auth:m,requestIds:h,silentModeBefore:g,createdAtBefore:_,createdAtAfter:v,updatedAtBefore:y,updatedAtAfter:b,statuses:x=[a.Compiling,a.RequestMade,a.Delayed,a.Approving,a.Secondary,a.Enriching,a.Waiting,a.SecondaryApproving],concurrency:S=50,transcendUrl:C=e}){let w=s(C,m),T=new Date().getTime(),E=new d.SingleBar({},d.Presets.shades_classic),D;if(p){let e=(await c(w,{logger:t,filterBy:{title:p}})).find(e=>e.title===p);if(!e)throw Error(`Failed to find a template with title: "${p}"`);D=e}let O=await i(w,{actions:f,createdAtBefore:_,createdAtAfter:v,updatedAtBefore:y,updatedAtAfter:b,statuses:x,requestIds:h});t.info(o.magenta(`Canceling "${O.length}" requests${D?` Using template: ${D.title}`:``}.`));let k=0;E.start(O.length,0),await u(O,async e=>{g&&new Date(g)>new Date(e.createdAt)&&await l(w,r,{variables:{input:{id:e.id,isSilent:!0}},logger:t}),await l(w,n,{variables:{input:{requestId:e.id,...D?{subject:`Re: ${D.subject.defaultMessage}`,template:D.template.defaultMessage}:{}}},logger:t}),k+=1,E.update(k)},{concurrency:S}),E.stop();let A=new Date().getTime()-T;return t.info(o.green(`Successfully canceled ${k} requests in "${A/1e3}" seconds!`)),O.length}export{f as t};
|
|
2
|
+
//# sourceMappingURL=cancelPrivacyRequests-CFCULeSv.mjs.map
|
package/dist/{cancelPrivacyRequests-DBjBnX2p.mjs.map → cancelPrivacyRequests-CFCULeSv.mjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cancelPrivacyRequests-
|
|
1
|
+
{"version":3,"file":"cancelPrivacyRequests-CFCULeSv.mjs","names":[],"sources":["../src/lib/requests/cancelPrivacyRequests.ts"],"sourcesContent":["import { RequestAction, RequestStatus } from '@transcend-io/privacy-types';\nimport {\n buildTranscendGraphQLClient,\n fetchAllTemplates,\n makeGraphQLRequest,\n type Template,\n} from '@transcend-io/sdk';\nimport { map } from '@transcend-io/utils';\nimport cliProgress from 'cli-progress';\nimport colors from 'colors';\n\nimport { DEFAULT_TRANSCEND_API } from '../../constants.js';\nimport { logger } from '../../logger.js';\nimport {\n UPDATE_PRIVACY_REQUEST,\n fetchAllRequests,\n CANCEL_PRIVACY_REQUEST,\n} from '../graphql/index.js';\n\n/**\n * Cancel a set of privacy requests\n *\n * @param options - Options\n * @returns The number of requests canceled\n */\nexport async function cancelPrivacyRequests({\n requestActions,\n cancellationTitle,\n auth,\n requestIds,\n silentModeBefore,\n createdAtBefore,\n createdAtAfter,\n updatedAtBefore,\n updatedAtAfter,\n statuses = [\n RequestStatus.Compiling,\n RequestStatus.RequestMade,\n RequestStatus.Delayed,\n RequestStatus.Approving,\n RequestStatus.Secondary,\n RequestStatus.Enriching,\n RequestStatus.Waiting,\n RequestStatus.SecondaryApproving,\n ],\n concurrency = 50,\n transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n /** The request actions that should be restarted */\n requestActions: RequestAction[];\n /** Transcend API key authentication */\n auth: string;\n /** Concurrency limit for approving */\n concurrency?: number;\n /** The request statuses to cancel */\n statuses?: RequestStatus[];\n /** The set of privacy requests to cancel */\n requestIds?: string[];\n /** Mark these requests as silent mode if they were created before this date */\n silentModeBefore?: Date;\n /** Filter for requests created before this date */\n createdAtBefore?: Date;\n /** Filter for requests created after this date */\n createdAtAfter?: Date;\n /** Filter for requests updated before this date */\n updatedAtBefore?: Date;\n /** Filter for requests updated after this date */\n updatedAtAfter?: Date;\n /** API URL for Transcend backend */\n transcendUrl?: string;\n /** The email template to use when canceling the requests */\n cancellationTitle?: string;\n}): Promise<number> {\n // Find all requests made before createdAt that are in a removing data state\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n // Time duration\n const t0 = new Date().getTime();\n // create a new progress bar instance and use shades_classic theme\n const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);\n\n // Grab the template with that title\n let cancelationTemplate: Template | undefined;\n if (cancellationTitle) {\n const matchingTemplates = await fetchAllTemplates(client, {\n logger,\n filterBy: { title: cancellationTitle },\n });\n const exactTitleMatch = matchingTemplates.find(\n (template) => template.title === cancellationTitle,\n );\n if (!exactTitleMatch) {\n throw new Error(`Failed to find a template with title: \"${cancellationTitle}\"`);\n }\n cancelationTemplate = exactTitleMatch;\n }\n\n // Pull in the requests\n const allRequests = await fetchAllRequests(client, {\n actions: requestActions,\n createdAtBefore,\n createdAtAfter,\n updatedAtBefore,\n updatedAtAfter,\n statuses,\n requestIds,\n });\n\n // Notify Transcend\n logger.info(\n colors.magenta(\n `Canceling \"${allRequests.length}\" requests${\n cancelationTemplate ? ` Using template: ${cancelationTemplate.title}` : ''\n }.`,\n ),\n );\n\n let total = 0;\n progressBar.start(allRequests.length, 0);\n await map(\n allRequests,\n async (requestToCancel) => {\n // update request to silent mode if silentModeBefore is defined\n // and the request was created before silentModeBefore\n if (silentModeBefore && new Date(silentModeBefore) > new Date(requestToCancel.createdAt)) {\n await makeGraphQLRequest(client, UPDATE_PRIVACY_REQUEST, {\n variables: {\n input: {\n id: requestToCancel.id,\n isSilent: true,\n },\n },\n logger,\n });\n }\n\n // cancel the request\n await makeGraphQLRequest(client, CANCEL_PRIVACY_REQUEST, {\n variables: {\n input: {\n requestId: requestToCancel.id,\n ...(cancelationTemplate\n ? {\n subject: `Re: ${cancelationTemplate.subject.defaultMessage}`,\n template: cancelationTemplate.template.defaultMessage,\n }\n : {}),\n },\n },\n logger,\n });\n\n total += 1;\n progressBar.update(total);\n },\n { concurrency },\n );\n\n progressBar.stop();\n const t1 = new Date().getTime();\n const totalTime = t1 - t0;\n\n logger.info(\n colors.green(`Successfully canceled ${total} requests in \"${totalTime / 1000}\" seconds!`),\n );\n return allRequests.length;\n}\n"],"mappings":"0bAyBA,eAAsB,E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OAAO,EAAM,EAE3B,CAAE,cAAa,CAChB,CAED,EAAY,MAAM,CAElB,IAAM,EADK,IAAI,MAAM,CAAC,SACF,CAAG,EAKvB,OAHA,EAAO,KACL,EAAO,MAAM,yBAAyB,EAAM,gBAAgB,EAAY,IAAK,YAAY,CAC1F,CACM,EAAY"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e}from"./enums-CyFTrzXY.mjs";import{a as t,o as n,s as r}from"./constants-
|
|
1
|
+
import{o as e}from"./enums-CyFTrzXY.mjs";import{a as t,o as n,s as r}from"./constants-B7bW_WN2.mjs";import{i}from"./parsers-Bl90Wjbz.mjs";import{buildCommand as a,numberParser as o}from"@stricli/core";import{ConsentTrackerStatus as s,ScopeName as c,TRANSCEND_SCOPES as l}from"@transcend-io/privacy-types";const u=({scopes:e,requiresSiloScope:t=!1})=>{let r={kind:`parsed`,parse:String,brief:`The Transcend API key. Defaults to the TRANSCEND_API_KEY environment variable when set, so --auth may be omitted if it is exported.`,...n?{default:n}:{}};return t&&(r.brief+=` This key must be associated with the data silo(s) being operated on.`),e===`Varies`?{...r,brief:`${r.brief} The scopes required will vary depending on the operation performed. If in doubt, the ${l[c.FullAdmin].title} scope will always work.`}:e.length===0?{...r,brief:`${r.brief} No scopes are required for this command.`}:{...r,brief:`${r.brief} Requires scopes: ${e.map(e=>`"${l[e].title}"`).join(`, `)}`}},d=(e=t)=>({kind:`parsed`,parse:i,brief:`URL of the Transcend backend. Use https://api.us.transcend.io for US hosting. Defaults to the TRANSCEND_API_URL environment variable when set, so --transcendUrl may be omitted if it is exported.`,default:e}),f=(e=r)=>({kind:`parsed`,parse:i,brief:`URL of the Transcend consent backend. Use https://consent.us.transcend.io for US hosting. Defaults to the TRANSCEND_CONSENT_API_URL environment variable when set, so --consentUrl may be omitted if it is exported.`,default:e}),p=()=>({kind:`parsed`,parse:String,brief:`The Sombra internal key, use for additional authentication when self-hosting Sombra`,optional:!0}),m=[`dataSilos`,`enrichers`,`templates`,`apiKeys`],h=Object.values(s),g=a({loader:async()=>{let{pull:e}=await import(`./impl-BOXnkx44.mjs`);return e},parameters:{flags:{auth:u({scopes:`Varies`}),resources:{kind:`enum`,values:[`all`,...Object.values(e)],brief:`The different resource types to pull in. Defaults to ${m.join(`,`)}.`,variadic:`,`,optional:!0},file:{kind:`parsed`,parse:String,brief:`Path to the YAML file to pull into`,default:`./transcend.yml`},transcendUrl:d(),dataSiloIds:{kind:`parsed`,parse:String,variadic:`,`,brief:`The UUIDs of the data silos that should be pulled into the YAML file`,optional:!0},integrationNames:{kind:`parsed`,parse:String,variadic:`,`,brief:`The types of integrations to pull down`,optional:!0},trackerStatuses:{kind:`enum`,values:Object.values(s),variadic:`,`,brief:`The statuses of consent manager trackers to pull down. Defaults to all statuses.`,optional:!0},pageSize:{kind:`parsed`,parse:o,brief:`The page size to use when paginating over the API`,default:`50`},skipDatapoints:{kind:`boolean`,brief:`When true, skip pulling in datapoints alongside data silo resource`,default:!1},skipSubDatapoints:{kind:`boolean`,brief:`When true, skip pulling in subDatapoints alongside data silo resource`,default:!1},includeGuessedCategories:{kind:`boolean`,brief:`When true, included guessed data categories that came from the content classifier`,default:!1},debug:{kind:`boolean`,brief:`Set to true to include debug logs while pulling the configuration`,default:!1}}},docs:{brief:`Pull metadata from Transcend into transcend.yml`,fullDescription:`Generates a transcend.yml by pulling the configuration from your Transcend instance.
|
|
2
2
|
|
|
3
3
|
The API key needs various scopes depending on the resources being pulled (see the CLI's README for more details).
|
|
4
4
|
|
|
@@ -6,4 +6,4 @@ This command can be helpful if you are looking to:
|
|
|
6
6
|
|
|
7
7
|
- Copy your data into another instance
|
|
8
8
|
- Generate a transcend.yml file as a starting point to maintain parts of your data inventory in code.`}});export{f as a,u as i,m as n,p as o,g as r,d as s,h as t};
|
|
9
|
-
//# sourceMappingURL=command-
|
|
9
|
+
//# sourceMappingURL=command-8AnltUOG.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-
|
|
1
|
+
{"version":3,"file":"command-8AnltUOG.mjs","names":[],"sources":["../src/lib/cli/common-parameters.ts","../src/commands/inventory/pull/command.ts"],"sourcesContent":["import type { TypedFlagParameter } from '@stricli/core';\nimport { ScopeName, TRANSCEND_SCOPES } from '@transcend-io/privacy-types';\n\nimport {\n DEFAULT_TRANSCEND_API,\n DEFAULT_TRANSCEND_API_KEY,\n DEFAULT_TRANSCEND_CONSENT_API,\n} from '../../constants.js';\nimport type { LocalContext } from '../../context.js';\nimport { urlParser } from './parsers.js';\n\n/**\n * Common parameter builders for CLI commands\n * These reduce duplication and ensure consistency across commands\n */\n\n/**\n * Creates a standard authentication parameter\n *\n * @param root0 - The scopes and whether it requires a silo scope\n * @returns The parameter object\n */\nexport const createAuthParameter = ({\n scopes,\n requiresSiloScope = false,\n}: {\n /** The scopes required for the command */\n scopes: ScopeName[] | 'Varies';\n /** Whether the command requires a silo scope */\n requiresSiloScope?: boolean;\n}): TypedFlagParameter<string, LocalContext> => {\n const parameter = {\n kind: 'parsed' as const,\n parse: String,\n brief:\n 'The Transcend API key. Defaults to the TRANSCEND_API_KEY environment variable when set, so --auth may be omitted if it is exported.',\n // When TRANSCEND_API_KEY is exported, make the flag optional by seeding a\n // default. When it is unset, omit `default` so the flag stays required.\n ...(DEFAULT_TRANSCEND_API_KEY ? { default: DEFAULT_TRANSCEND_API_KEY } : {}),\n };\n\n if (requiresSiloScope) {\n parameter.brief += ' This key must be associated with the data silo(s) being operated on.';\n }\n\n if (scopes === 'Varies') {\n return {\n ...parameter,\n brief: `${\n parameter.brief\n } The scopes required will vary depending on the operation performed. If in doubt, the ${\n TRANSCEND_SCOPES[ScopeName.FullAdmin].title\n } scope will always work.`,\n };\n }\n\n if (scopes.length === 0) {\n return {\n ...parameter,\n brief: `${parameter.brief} No scopes are required for this command.`,\n };\n }\n\n return {\n ...parameter,\n brief: `${parameter.brief} Requires scopes: ${scopes\n .map((s) => `\"${TRANSCEND_SCOPES[s].title}\"`)\n .join(', ')}`,\n };\n};\n\n/**\n * Creates a standard Transcend URL parameter\n *\n * @param defaultUrl - The default URL to use if not provided\n * @returns The parameter object\n */\nexport const createTranscendUrlParameter = (\n defaultUrl = DEFAULT_TRANSCEND_API,\n): TypedFlagParameter<string, LocalContext> => ({\n kind: 'parsed',\n parse: urlParser,\n brief:\n 'URL of the Transcend backend. Use https://api.us.transcend.io for US hosting. Defaults to the TRANSCEND_API_URL environment variable when set, so --transcendUrl may be omitted if it is exported.',\n default: defaultUrl,\n});\n\n/**\n * Creates a standard Consent URL parameter\n *\n * @param defaultUrl - The default URL to use if not provided\n * @returns The parameter object\n */\nexport const createConsentUrlParameter = (\n defaultUrl = DEFAULT_TRANSCEND_CONSENT_API,\n): TypedFlagParameter<string, LocalContext> => ({\n kind: 'parsed',\n parse: urlParser,\n brief:\n 'URL of the Transcend consent backend. Use https://consent.us.transcend.io for US hosting. Defaults to the TRANSCEND_CONSENT_API_URL environment variable when set, so --consentUrl may be omitted if it is exported.',\n default: defaultUrl,\n});\n\n/**\n * Creates a standard Sombra authentication parameter\n *\n * @returns The parameter object\n */\nexport const createSombraAuthParameter = (): TypedFlagParameter<\n string | undefined,\n LocalContext\n> => ({\n kind: 'parsed',\n parse: String,\n brief: 'The Sombra internal key, use for additional authentication when self-hosting Sombra',\n optional: true,\n});\n","import { buildCommand, numberParser } from '@stricli/core';\nimport { ConsentTrackerStatus } from '@transcend-io/privacy-types';\n\nimport { TranscendPullResource } from '../../../enums.js';\nimport {\n createAuthParameter,\n createTranscendUrlParameter,\n} from '../../../lib/cli/common-parameters.js';\n\nexport const DEFAULT_TRANSCEND_PULL_RESOURCES = [\n TranscendPullResource.DataSilos,\n TranscendPullResource.Enrichers,\n TranscendPullResource.Templates,\n TranscendPullResource.ApiKeys,\n];\n\nexport const DEFAULT_CONSENT_TRACKER_STATUSES = Object.values(ConsentTrackerStatus);\n\nexport const pullCommand = buildCommand({\n loader: async () => {\n const { pull } = await import('./impl.js');\n return pull;\n },\n parameters: {\n flags: {\n auth: createAuthParameter({\n scopes: 'Varies',\n }),\n resources: {\n kind: 'enum',\n values: ['all', ...Object.values(TranscendPullResource)],\n brief: `The different resource types to pull in. Defaults to ${DEFAULT_TRANSCEND_PULL_RESOURCES.join(\n ',',\n )}.`,\n variadic: ',',\n optional: true,\n },\n file: {\n kind: 'parsed',\n parse: String,\n brief: 'Path to the YAML file to pull into',\n default: './transcend.yml',\n },\n transcendUrl: createTranscendUrlParameter(),\n dataSiloIds: {\n kind: 'parsed',\n parse: String,\n variadic: ',',\n brief: 'The UUIDs of the data silos that should be pulled into the YAML file',\n optional: true,\n },\n integrationNames: {\n kind: 'parsed',\n parse: String,\n variadic: ',',\n brief: 'The types of integrations to pull down',\n optional: true,\n },\n trackerStatuses: {\n kind: 'enum',\n values: Object.values(ConsentTrackerStatus),\n variadic: ',',\n brief: 'The statuses of consent manager trackers to pull down. Defaults to all statuses.',\n optional: true,\n },\n pageSize: {\n kind: 'parsed',\n parse: numberParser,\n brief: 'The page size to use when paginating over the API',\n default: '50',\n },\n skipDatapoints: {\n kind: 'boolean',\n brief: 'When true, skip pulling in datapoints alongside data silo resource',\n default: false,\n },\n skipSubDatapoints: {\n kind: 'boolean',\n brief: 'When true, skip pulling in subDatapoints alongside data silo resource',\n default: false,\n },\n includeGuessedCategories: {\n kind: 'boolean',\n brief: 'When true, included guessed data categories that came from the content classifier',\n default: false,\n },\n debug: {\n kind: 'boolean',\n brief: 'Set to true to include debug logs while pulling the configuration',\n default: false,\n },\n },\n },\n docs: {\n brief: 'Pull metadata from Transcend into transcend.yml',\n fullDescription: `Generates a transcend.yml by pulling the configuration from your Transcend instance.\n\nThe API key needs various scopes depending on the resources being pulled (see the CLI's README for more details).\n\nThis command can be helpful if you are looking to:\n\n- Copy your data into another instance\n- Generate a transcend.yml file as a starting point to maintain parts of your data inventory in code.`,\n },\n});\n"],"mappings":"iTAsBA,MAAa,GAAuB,CAClC,SACA,oBAAoB,MAM0B,CAC9C,IAAM,EAAY,CAChB,KAA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AQ,OAAO,OAAO,EAAqB,CAC3C,SAAU,IACV,MAAO,mFACP,SAAU,GACX,CACD,SAAU,CACR,KAAM,SACN,MAAO,EACP,MAAO,oDACP,QAAS,KACV,CACD,eAAgB,CACd,KAAM,UACN,MAAO,qEACP,QAAS,GACV,CACD,kBAAmB,CACjB,KAAM,UACN,MAAO,wEACP,QAAS,GACV,CACD,yBAA0B,CACxB,KAAM,UACN,MAAO,oFACP,QAAS,GACV,CACD,MAAO,CACL,KAAM,UACN,MAAO,oEACP,QAAS,GACV,CACF,CACF,CACD,KAAM,CACJ,MAAO,kDACP,gBAAiB;;;;;;;uGAQlB,CACF,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"./enums-CyFTrzXY.mjs";import{ScopeName as e,TRANSCEND_SCOPES as t}from"@transcend-io/privacy-types";import{keyBy as n}from"lodash-es";var r=`10.
|
|
2
|
-
//# sourceMappingURL=constants-
|
|
1
|
+
import"./enums-CyFTrzXY.mjs";import{ScopeName as e,TRANSCEND_SCOPES as t}from"@transcend-io/privacy-types";import{keyBy as n}from"lodash-es";var r=`10.16.0`,i=`A command line interface for programmatic operations across Transcend.`;const a=`transcend`,o=`https://app.transcend.io`,s=`${o}/infrastructure/integrations`,c=`${o}/data-map/data-inventory/data-points`,l=process.env.TRANSCEND_API_URL||`https://api.transcend.io`,u=process.env.TRANSCEND_API_KEY||void 0,d=process.env.TRANSCEND_CONSENT_API_URL||`https://consent.transcend.io`,f={apiKeys:[e.ViewApiKeys],templates:[e.ManageEmailTemplates],dataSilos:[e.ManageDataMap,e.ConnectDataSilos],enrichers:[e.ManageRequestIdentities],businessEntities:[e.ManageDataInventory],processingActivities:[e.ManageDataMap],identifiers:[e.ManageRequestIdentities],customFields:[e.ManageGlobalAttributes],dataFlows:[e.ManageDataFlow],cookies:[e.ManageDataFlow],consentManager:[e.ManageConsentManagerDeveloperSettings],partitions:[e.ManageConsentManagerDeveloperSettings],actions:[e.ManageDataSubjectRequestSettings],dataSubjects:[e.ManageDataSubjectRequestSettings],prompts:[e.ManagePrompts],promptPartials:[e.ManagePrompts],promptGroups:[e.ManagePrompts],agents:[e.ManagePathfinder],agentFunctions:[e.ManagePathfinder],agentFiles:[e.ManagePathfinder],vendors:[e.ManageDataInventory],dataCategories:[e.ManageDataInventory],processingPurposes:[e.ManageDataInventory],actionItems:[e.ManageAllActionItems,e.ViewGlobalAttributes],actionItemCollections:[e.ManageActionItemCollections],teams:[e.ManageAccessControl],messages:[e.ManageIntlMessages],privacyCenters:[e.ManagePrivacyCenter],policies:[e.ManagePolicies],assessments:[e.ManageAssessments],assessmentTemplates:[e.ManageAssessments],purposes:[e.ManageConsentManager,e.ManagePreferenceStoreSettings],systemDiscovery:[e.ManageDataMap]},p={apiKeys:[e.ViewApiKeys],templates:[e.ViewEmailTemplates],dataSilos:[e.ViewDataMap,e.ViewDataSubjectRequestSettings],enrichers:[e.ViewRequestIdentitySettings],businessEntities:[e.ViewDataInventory],processingActivities:[e.ViewDataInventory],identifiers:[e.ViewRequestIdentitySettings],customFields:[e.ViewGlobalAttributes],dataFlows:[e.ViewDataFlow],cookies:[e.ViewDataFlow],consentManager:[e.ViewConsentManager],partitions:[e.ViewConsentManager],actions:[e.ViewDataSubjectRequestSettings],dataSubjects:[e.ViewDataSubjectRequestSettings],prompts:[e.ViewPrompts],promptPartials:[e.ViewPrompts],promptGroups:[e.ViewPrompts],agents:[e.ViewPathfinder],agentFunctions:[e.ViewPathfinder],agentFiles:[e.ViewPathfinder],vendors:[e.ViewDataInventory],dataCategories:[e.ViewDataInventory],processingPurposes:[e.ViewDataInventory],actionItemCollections:[e.ViewAllActionItems],actionItems:[e.ViewAllActionItems],teams:[e.ViewScopes],messages:[e.ViewIntlMessages],privacyCenters:[e.ViewPrivacyCenter],policies:[e.ViewPolicies],assessments:[e.ViewAssessments],assessmentTemplates:[e.ViewAssessments],purposes:[e.ViewConsentManager,e.ViewPreferenceStoreSettings],systemDiscovery:[e.ViewDataMap]},m={apiKeys:`api-keys`,customFields:`attributes`,dataFlows:`data-flows`,cookies:`cookies`,consentManager:`consent-manager`,partitions:`partitions`,actions:`actions`,dataSubjects:`data-subjects`,businessEntities:`business-entities`,processingActivities:`processing-activities`,identifiers:`identifiers`,enrichers:`enrichers`,dataSilos:`data-silos`,templates:`templates`,prompts:`prompts`,promptPartials:`prompt-partials`,promptGroups:`prompt-groups`,agents:`agents`,agentFunctions:`agent-functions`,agentFiles:`agent-files`,vendors:`vendors`,dataCategories:`data-categories`,processingPurposes:`processing-purposes`,actionItems:`action-items`,actionItemCollections:`action-item-collections`,teams:`teams`,messages:`messages`,privacyCenters:`privacy-center`,policies:`policies`,assessments:`assessments`,assessmentTemplates:`assessment-templates`,purposes:`purposes`,systemDiscovery:`system-discovery`},h=n(Object.entries(t).map(([e,t])=>({...t,name:e})),`title`),g=Object.keys(h),_=new Set([429,502,500,504,329]),v=process.env.DEBUG===`1`;export{l as a,_ as c,p as d,f,r as g,i as h,v as i,h as l,a as m,c as n,u as o,m as p,s as r,d as s,o as t,g as u};
|
|
2
|
+
//# sourceMappingURL=constants-B7bW_WN2.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants-Co8rkELu.mjs","names":[],"sources":["../package.json","../src/constants.ts"],"sourcesContent":["","import { ScopeName, TRANSCEND_SCOPES, type ScopeDefinition } from '@transcend-io/privacy-types';\nimport { keyBy } from 'lodash-es';\n\nimport { TranscendInput } from './codecs.js';\nimport { TranscendPullResource } from './enums.js';\n\nexport { description, version } from '../package.json';\n/**\n * The name of the main binary for the CLI\n */\nexport const name = 'transcend';\n\nexport const ADMIN_DASH = 'https://app.transcend.io';\n\nexport const ADMIN_DASH_INTEGRATIONS = `${ADMIN_DASH}/infrastructure/integrations`;\nexport const ADMIN_DASH_DATAPOINTS = `${ADMIN_DASH}/data-map/data-inventory/data-points`;\n\n/**\n * Override default transcend API url using\n * TRANSCEND_API_URL=https://api.us.transcend.io transcend ...\n */\nexport const DEFAULT_TRANSCEND_API = process.env.TRANSCEND_API_URL || 'https://api.transcend.io';\n\n/**\n * Default the `--auth` flag to the `TRANSCEND_API_KEY` environment variable\n * when it is set, so callers do not need to pass `--auth` on every invocation:\n * TRANSCEND_API_KEY=... transcend policy list\n * When unset, `--auth` remains required.\n */\nexport const DEFAULT_TRANSCEND_API_KEY = process.env.TRANSCEND_API_KEY || undefined;\n\n/**\n * Override default transcend API url using\n * TRANSCEND_CONSENT_API_URL=https://consent.us.transcend.io transcend ...\n */\nexport const DEFAULT_TRANSCEND_CONSENT_API =\n process.env.TRANSCEND_CONSENT_API_URL || 'https://consent.transcend.io';\n\n/**\n * Mapping between resource type and scopes required for cli\n */\nexport const TR_PUSH_RESOURCE_SCOPE_MAP: {\n [k in TranscendPullResource]: ScopeName[];\n} = {\n [TranscendPullResource.ApiKeys]: [ScopeName.ViewApiKeys],\n [TranscendPullResource.Templates]: [ScopeName.ManageEmailTemplates],\n [TranscendPullResource.DataSilos]: [ScopeName.ManageDataMap, ScopeName.ConnectDataSilos],\n [TranscendPullResource.Enrichers]: [ScopeName.ManageRequestIdentities],\n [TranscendPullResource.BusinessEntities]: [ScopeName.ManageDataInventory],\n [TranscendPullResource.ProcessingActivities]: [ScopeName.ManageDataMap],\n [TranscendPullResource.Identifiers]: [ScopeName.ManageRequestIdentities],\n [TranscendPullResource.Attributes]: [ScopeName.ManageGlobalAttributes],\n [TranscendPullResource.DataFlows]: [ScopeName.ManageDataFlow],\n [TranscendPullResource.Cookies]: [ScopeName.ManageDataFlow],\n [TranscendPullResource.ConsentManager]: [ScopeName.ManageConsentManagerDeveloperSettings],\n [TranscendPullResource.Partitions]: [ScopeName.ManageConsentManagerDeveloperSettings],\n [TranscendPullResource.Actions]: [ScopeName.ManageDataSubjectRequestSettings],\n [TranscendPullResource.DataSubjects]: [ScopeName.ManageDataSubjectRequestSettings],\n [TranscendPullResource.Prompts]: [ScopeName.ManagePrompts],\n [TranscendPullResource.PromptPartials]: [ScopeName.ManagePrompts],\n [TranscendPullResource.PromptGroups]: [ScopeName.ManagePrompts],\n [TranscendPullResource.Agents]: [ScopeName.ManagePathfinder],\n [TranscendPullResource.AgentFunctions]: [ScopeName.ManagePathfinder],\n [TranscendPullResource.AgentFiles]: [ScopeName.ManagePathfinder],\n [TranscendPullResource.Vendors]: [ScopeName.ManageDataInventory],\n [TranscendPullResource.DataCategories]: [ScopeName.ManageDataInventory],\n [TranscendPullResource.ProcessingPurposes]: [ScopeName.ManageDataInventory],\n [TranscendPullResource.ActionItems]: [\n ScopeName.ManageAllActionItems,\n ScopeName.ViewGlobalAttributes,\n ],\n [TranscendPullResource.ActionItemCollections]: [ScopeName.ManageActionItemCollections],\n [TranscendPullResource.Teams]: [ScopeName.ManageAccessControl],\n [TranscendPullResource.Messages]: [ScopeName.ManageIntlMessages],\n [TranscendPullResource.PrivacyCenters]: [ScopeName.ManagePrivacyCenter],\n [TranscendPullResource.Policies]: [ScopeName.ManagePolicies],\n [TranscendPullResource.Assessments]: [ScopeName.ManageAssessments],\n [TranscendPullResource.AssessmentTemplates]: [ScopeName.ManageAssessments],\n [TranscendPullResource.Purposes]: [\n ScopeName.ManageConsentManager,\n ScopeName.ManagePreferenceStoreSettings,\n ],\n [TranscendPullResource.SystemDiscovery]: [ScopeName.ManageDataMap],\n};\n\n/**\n * Mapping between resource type and scopes required for cli\n */\nexport const TR_PULL_RESOURCE_SCOPE_MAP: {\n [k in TranscendPullResource]: ScopeName[];\n} = {\n [TranscendPullResource.ApiKeys]: [ScopeName.ViewApiKeys],\n [TranscendPullResource.Templates]: [ScopeName.ViewEmailTemplates],\n [TranscendPullResource.DataSilos]: [\n ScopeName.ViewDataMap,\n ScopeName.ViewDataSubjectRequestSettings,\n ],\n [TranscendPullResource.Enrichers]: [ScopeName.ViewRequestIdentitySettings],\n [TranscendPullResource.BusinessEntities]: [ScopeName.ViewDataInventory],\n [TranscendPullResource.ProcessingActivities]: [ScopeName.ViewDataInventory],\n [TranscendPullResource.Identifiers]: [ScopeName.ViewRequestIdentitySettings],\n [TranscendPullResource.Attributes]: [ScopeName.ViewGlobalAttributes],\n [TranscendPullResource.DataFlows]: [ScopeName.ViewDataFlow],\n [TranscendPullResource.Cookies]: [ScopeName.ViewDataFlow],\n [TranscendPullResource.ConsentManager]: [ScopeName.ViewConsentManager],\n [TranscendPullResource.Partitions]: [ScopeName.ViewConsentManager],\n [TranscendPullResource.Actions]: [ScopeName.ViewDataSubjectRequestSettings],\n [TranscendPullResource.DataSubjects]: [ScopeName.ViewDataSubjectRequestSettings],\n [TranscendPullResource.Prompts]: [ScopeName.ViewPrompts],\n [TranscendPullResource.PromptPartials]: [ScopeName.ViewPrompts],\n [TranscendPullResource.PromptGroups]: [ScopeName.ViewPrompts],\n [TranscendPullResource.Agents]: [ScopeName.ViewPathfinder],\n [TranscendPullResource.AgentFunctions]: [ScopeName.ViewPathfinder],\n [TranscendPullResource.AgentFiles]: [ScopeName.ViewPathfinder],\n [TranscendPullResource.Vendors]: [ScopeName.ViewDataInventory],\n [TranscendPullResource.DataCategories]: [ScopeName.ViewDataInventory],\n [TranscendPullResource.ProcessingPurposes]: [ScopeName.ViewDataInventory],\n [TranscendPullResource.ActionItemCollections]: [ScopeName.ViewAllActionItems],\n [TranscendPullResource.ActionItems]: [ScopeName.ViewAllActionItems],\n [TranscendPullResource.Teams]: [ScopeName.ViewScopes],\n [TranscendPullResource.Messages]: [ScopeName.ViewIntlMessages],\n [TranscendPullResource.PrivacyCenters]: [ScopeName.ViewPrivacyCenter],\n [TranscendPullResource.Policies]: [ScopeName.ViewPolicies],\n [TranscendPullResource.Assessments]: [ScopeName.ViewAssessments],\n [TranscendPullResource.AssessmentTemplates]: [ScopeName.ViewAssessments],\n [TranscendPullResource.Purposes]: [\n ScopeName.ViewConsentManager,\n ScopeName.ViewPreferenceStoreSettings,\n ],\n [TranscendPullResource.SystemDiscovery]: [ScopeName.ViewDataMap],\n};\n\nexport const TR_YML_RESOURCE_TO_FIELD_NAME: Record<TranscendPullResource, keyof TranscendInput> = {\n [TranscendPullResource.ApiKeys]: 'api-keys',\n [TranscendPullResource.Attributes]: 'attributes',\n [TranscendPullResource.DataFlows]: 'data-flows',\n [TranscendPullResource.Cookies]: 'cookies',\n [TranscendPullResource.ConsentManager]: 'consent-manager',\n [TranscendPullResource.Partitions]: 'partitions',\n [TranscendPullResource.Actions]: 'actions',\n [TranscendPullResource.DataSubjects]: 'data-subjects',\n [TranscendPullResource.BusinessEntities]: 'business-entities',\n [TranscendPullResource.ProcessingActivities]: 'processing-activities',\n [TranscendPullResource.Identifiers]: 'identifiers',\n [TranscendPullResource.Enrichers]: 'enrichers',\n [TranscendPullResource.DataSilos]: 'data-silos',\n [TranscendPullResource.Templates]: 'templates',\n [TranscendPullResource.Prompts]: 'prompts',\n [TranscendPullResource.PromptPartials]: 'prompt-partials',\n [TranscendPullResource.PromptGroups]: 'prompt-groups',\n [TranscendPullResource.Agents]: 'agents',\n [TranscendPullResource.AgentFunctions]: 'agent-functions',\n [TranscendPullResource.AgentFiles]: 'agent-files',\n [TranscendPullResource.Vendors]: 'vendors',\n [TranscendPullResource.DataCategories]: 'data-categories',\n [TranscendPullResource.ProcessingPurposes]: 'processing-purposes',\n [TranscendPullResource.ActionItems]: 'action-items',\n [TranscendPullResource.ActionItemCollections]: 'action-item-collections',\n [TranscendPullResource.Teams]: 'teams',\n [TranscendPullResource.Messages]: 'messages',\n [TranscendPullResource.PrivacyCenters]: 'privacy-center',\n [TranscendPullResource.Policies]: 'policies',\n [TranscendPullResource.Assessments]: 'assessments',\n [TranscendPullResource.AssessmentTemplates]: 'assessment-templates',\n [TranscendPullResource.Purposes]: 'purposes',\n [TranscendPullResource.SystemDiscovery]: 'system-discovery',\n};\n\nexport const SCOPES_BY_TITLE = keyBy(\n Object.entries(TRANSCEND_SCOPES).map(([name, value]) => ({\n ...value,\n name,\n })),\n 'title',\n) as Record<\n string,\n ScopeDefinition & {\n /** The camelCased name which identifies the scope */\n name: ScopeName;\n }\n>;\n\nexport const SCOPE_TITLES = Object.keys(SCOPES_BY_TITLE);\n\n/**\n * HTTP statuses that should be retried *in place* without splitting.\n * 429: Rate-limited\n * 502: Upstream/edge gateway error\n * 329: Reserved for custom infra (kept defensively)\n */\nexport const RETRYABLE_BATCH_STATUSES = new Set([429, 502, 500, 504, 329] as const);\n\n/**\n * Debugging\n */\nexport const DEBUG = process.env.DEBUG === '1';\n"],"mappings":"wOCUA,MAAa,EAAO,YAEP,EAAa,2BAEb,EAA0B,GAAG,EAAW,8BACxC,EAAwB,GAAG,EAAW,sCAMtC,EAAwB,QAAQ,IAAI,mBAAqB,2BAQzD,EAA4B,QAAQ,IAAI,mBAAqB,IAAA,GAM7D,EACX,QAAQ,IAAI,2BAA6B,+BAK9B,EAET,SAC+B,CAAC,EAAU,YAAY,WACrB,CAAC,EAAU,qBAAqB,WAChC,CAAC,EAAU,cAAe,EAAU,iBAAiB,WACrD,CAAC,EAAU,wBAAwB,kBAC5B,CAAC,EAAU,oBAAoB,sBAC3B,CAAC,EAAU,cAAc,aAClC,CAAC,EAAU,wBAAwB,cACpC,CAAC,EAAU,uBAAuB,WACnC,CAAC,EAAU,eAAe,SAC5B,CAAC,EAAU,eAAe,gBACnB,CAAC,EAAU,sCAAsC,YACrD,CAAC,EAAU,sCAAsC,SACpD,CAAC,EAAU,iCAAiC,cACvC,CAAC,EAAU,iCAAiC,SACjD,CAAC,EAAU,cAAc,gBAClB,CAAC,EAAU,cAAc,cAC3B,CAAC,EAAU,cAAc,QAC/B,CAAC,EAAU,iBAAiB,gBACpB,CAAC,EAAU,iBAAiB,YAChC,CAAC,EAAU,iBAAiB,SAC/B,CAAC,EAAU,oBAAoB,gBACxB,CAAC,EAAU,oBAAoB,oBAC3B,CAAC,EAAU,oBAAoB,aACtC,CACnC,EAAU,qBACV,EAAU,qBACX,uBAC8C,CAAC,EAAU,4BAA4B,OACvD,CAAC,EAAU,oBAAoB,UAC5B,CAAC,EAAU,mBAAmB,gBACxB,CAAC,EAAU,oBAAoB,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ACM,0BACN,uBACG,kCACQ,gCACX,2BACO,mBAC1C,CAEY,EAAkB,EAC7B,OAAO,QAAQ,EAAiB,CAAC,KAAK,CAAC,EAAM,MAAY,CACvD,GAAG,EACH,OACD,EAAE,CACH,QACD,CAQY,EAAe,OAAO,KAAK,EAAgB,CAQ3C,EAA2B,IAAI,IAAI,CAAC,IAAK,IAAK,IAAK,IAAK,IAAI,CAAU,CAKtE,EAAQ,QAAQ,IAAI,QAAU"}
|
|
1
|
+
{"version":3,"file":"constants-B7bW_WN2.mjs","names":[],"sources":["../package.json","../src/constants.ts"],"sourcesContent":["","import { ScopeName, TRANSCEND_SCOPES, type ScopeDefinition } from '@transcend-io/privacy-types';\nimport { keyBy } from 'lodash-es';\n\nimport { TranscendInput } from './codecs.js';\nimport { TranscendPullResource } from './enums.js';\n\nexport { description, version } from '../package.json';\n/**\n * The name of the main binary for the CLI\n */\nexport const name = 'transcend';\n\nexport const ADMIN_DASH = 'https://app.transcend.io';\n\nexport const ADMIN_DASH_INTEGRATIONS = `${ADMIN_DASH}/infrastructure/integrations`;\nexport const ADMIN_DASH_DATAPOINTS = `${ADMIN_DASH}/data-map/data-inventory/data-points`;\n\n/**\n * Override default transcend API url using\n * TRANSCEND_API_URL=https://api.us.transcend.io transcend ...\n */\nexport const DEFAULT_TRANSCEND_API = process.env.TRANSCEND_API_URL || 'https://api.transcend.io';\n\n/**\n * Default the `--auth` flag to the `TRANSCEND_API_KEY` environment variable\n * when it is set, so callers do not need to pass `--auth` on every invocation:\n * TRANSCEND_API_KEY=... transcend policy list\n * When unset, `--auth` remains required.\n */\nexport const DEFAULT_TRANSCEND_API_KEY = process.env.TRANSCEND_API_KEY || undefined;\n\n/**\n * Override default transcend API url using\n * TRANSCEND_CONSENT_API_URL=https://consent.us.transcend.io transcend ...\n */\nexport const DEFAULT_TRANSCEND_CONSENT_API =\n process.env.TRANSCEND_CONSENT_API_URL || 'https://consent.transcend.io';\n\n/**\n * Mapping between resource type and scopes required for cli\n */\nexport const TR_PUSH_RESOURCE_SCOPE_MAP: {\n [k in TranscendPullResource]: ScopeName[];\n} = {\n [TranscendPullResource.ApiKeys]: [ScopeName.ViewApiKeys],\n [TranscendPullResource.Templates]: [ScopeName.ManageEmailTemplates],\n [TranscendPullResource.DataSilos]: [ScopeName.ManageDataMap, ScopeName.ConnectDataSilos],\n [TranscendPullResource.Enrichers]: [ScopeName.ManageRequestIdentities],\n [TranscendPullResource.BusinessEntities]: [ScopeName.ManageDataInventory],\n [TranscendPullResource.ProcessingActivities]: [ScopeName.ManageDataMap],\n [TranscendPullResource.Identifiers]: [ScopeName.ManageRequestIdentities],\n [TranscendPullResource.Attributes]: [ScopeName.ManageGlobalAttributes],\n [TranscendPullResource.DataFlows]: [ScopeName.ManageDataFlow],\n [TranscendPullResource.Cookies]: [ScopeName.ManageDataFlow],\n [TranscendPullResource.ConsentManager]: [ScopeName.ManageConsentManagerDeveloperSettings],\n [TranscendPullResource.Partitions]: [ScopeName.ManageConsentManagerDeveloperSettings],\n [TranscendPullResource.Actions]: [ScopeName.ManageDataSubjectRequestSettings],\n [TranscendPullResource.DataSubjects]: [ScopeName.ManageDataSubjectRequestSettings],\n [TranscendPullResource.Prompts]: [ScopeName.ManagePrompts],\n [TranscendPullResource.PromptPartials]: [ScopeName.ManagePrompts],\n [TranscendPullResource.PromptGroups]: [ScopeName.ManagePrompts],\n [TranscendPullResource.Agents]: [ScopeName.ManagePathfinder],\n [TranscendPullResource.AgentFunctions]: [ScopeName.ManagePathfinder],\n [TranscendPullResource.AgentFiles]: [ScopeName.ManagePathfinder],\n [TranscendPullResource.Vendors]: [ScopeName.ManageDataInventory],\n [TranscendPullResource.DataCategories]: [ScopeName.ManageDataInventory],\n [TranscendPullResource.ProcessingPurposes]: [ScopeName.ManageDataInventory],\n [TranscendPullResource.ActionItems]: [\n ScopeName.ManageAllActionItems,\n ScopeName.ViewGlobalAttributes,\n ],\n [TranscendPullResource.ActionItemCollections]: [ScopeName.ManageActionItemCollections],\n [TranscendPullResource.Teams]: [ScopeName.ManageAccessControl],\n [TranscendPullResource.Messages]: [ScopeName.ManageIntlMessages],\n [TranscendPullResource.PrivacyCenters]: [ScopeName.ManagePrivacyCenter],\n [TranscendPullResource.Policies]: [ScopeName.ManagePolicies],\n [TranscendPullResource.Assessments]: [ScopeName.ManageAssessments],\n [TranscendPullResource.AssessmentTemplates]: [ScopeName.ManageAssessments],\n [TranscendPullResource.Purposes]: [\n ScopeName.ManageConsentManager,\n ScopeName.ManagePreferenceStoreSettings,\n ],\n [TranscendPullResource.SystemDiscovery]: [ScopeName.ManageDataMap],\n};\n\n/**\n * Mapping between resource type and scopes required for cli\n */\nexport const TR_PULL_RESOURCE_SCOPE_MAP: {\n [k in TranscendPullResource]: ScopeName[];\n} = {\n [TranscendPullResource.ApiKeys]: [ScopeName.ViewApiKeys],\n [TranscendPullResource.Templates]: [ScopeName.ViewEmailTemplates],\n [TranscendPullResource.DataSilos]: [\n ScopeName.ViewDataMap,\n ScopeName.ViewDataSubjectRequestSettings,\n ],\n [TranscendPullResource.Enrichers]: [ScopeName.ViewRequestIdentitySettings],\n [TranscendPullResource.BusinessEntities]: [ScopeName.ViewDataInventory],\n [TranscendPullResource.ProcessingActivities]: [ScopeName.ViewDataInventory],\n [TranscendPullResource.Identifiers]: [ScopeName.ViewRequestIdentitySettings],\n [TranscendPullResource.Attributes]: [ScopeName.ViewGlobalAttributes],\n [TranscendPullResource.DataFlows]: [ScopeName.ViewDataFlow],\n [TranscendPullResource.Cookies]: [ScopeName.ViewDataFlow],\n [TranscendPullResource.ConsentManager]: [ScopeName.ViewConsentManager],\n [TranscendPullResource.Partitions]: [ScopeName.ViewConsentManager],\n [TranscendPullResource.Actions]: [ScopeName.ViewDataSubjectRequestSettings],\n [TranscendPullResource.DataSubjects]: [ScopeName.ViewDataSubjectRequestSettings],\n [TranscendPullResource.Prompts]: [ScopeName.ViewPrompts],\n [TranscendPullResource.PromptPartials]: [ScopeName.ViewPrompts],\n [TranscendPullResource.PromptGroups]: [ScopeName.ViewPrompts],\n [TranscendPullResource.Agents]: [ScopeName.ViewPathfinder],\n [TranscendPullResource.AgentFunctions]: [ScopeName.ViewPathfinder],\n [TranscendPullResource.AgentFiles]: [ScopeName.ViewPathfinder],\n [TranscendPullResource.Vendors]: [ScopeName.ViewDataInventory],\n [TranscendPullResource.DataCategories]: [ScopeName.ViewDataInventory],\n [TranscendPullResource.ProcessingPurposes]: [ScopeName.ViewDataInventory],\n [TranscendPullResource.ActionItemCollections]: [ScopeName.ViewAllActionItems],\n [TranscendPullResource.ActionItems]: [ScopeName.ViewAllActionItems],\n [TranscendPullResource.Teams]: [ScopeName.ViewScopes],\n [TranscendPullResource.Messages]: [ScopeName.ViewIntlMessages],\n [TranscendPullResource.PrivacyCenters]: [ScopeName.ViewPrivacyCenter],\n [TranscendPullResource.Policies]: [ScopeName.ViewPolicies],\n [TranscendPullResource.Assessments]: [ScopeName.ViewAssessments],\n [TranscendPullResource.AssessmentTemplates]: [ScopeName.ViewAssessments],\n [TranscendPullResource.Purposes]: [\n ScopeName.ViewConsentManager,\n ScopeName.ViewPreferenceStoreSettings,\n ],\n [TranscendPullResource.SystemDiscovery]: [ScopeName.ViewDataMap],\n};\n\nexport const TR_YML_RESOURCE_TO_FIELD_NAME: Record<TranscendPullResource, keyof TranscendInput> = {\n [TranscendPullResource.ApiKeys]: 'api-keys',\n [TranscendPullResource.Attributes]: 'attributes',\n [TranscendPullResource.DataFlows]: 'data-flows',\n [TranscendPullResource.Cookies]: 'cookies',\n [TranscendPullResource.ConsentManager]: 'consent-manager',\n [TranscendPullResource.Partitions]: 'partitions',\n [TranscendPullResource.Actions]: 'actions',\n [TranscendPullResource.DataSubjects]: 'data-subjects',\n [TranscendPullResource.BusinessEntities]: 'business-entities',\n [TranscendPullResource.ProcessingActivities]: 'processing-activities',\n [TranscendPullResource.Identifiers]: 'identifiers',\n [TranscendPullResource.Enrichers]: 'enrichers',\n [TranscendPullResource.DataSilos]: 'data-silos',\n [TranscendPullResource.Templates]: 'templates',\n [TranscendPullResource.Prompts]: 'prompts',\n [TranscendPullResource.PromptPartials]: 'prompt-partials',\n [TranscendPullResource.PromptGroups]: 'prompt-groups',\n [TranscendPullResource.Agents]: 'agents',\n [TranscendPullResource.AgentFunctions]: 'agent-functions',\n [TranscendPullResource.AgentFiles]: 'agent-files',\n [TranscendPullResource.Vendors]: 'vendors',\n [TranscendPullResource.DataCategories]: 'data-categories',\n [TranscendPullResource.ProcessingPurposes]: 'processing-purposes',\n [TranscendPullResource.ActionItems]: 'action-items',\n [TranscendPullResource.ActionItemCollections]: 'action-item-collections',\n [TranscendPullResource.Teams]: 'teams',\n [TranscendPullResource.Messages]: 'messages',\n [TranscendPullResource.PrivacyCenters]: 'privacy-center',\n [TranscendPullResource.Policies]: 'policies',\n [TranscendPullResource.Assessments]: 'assessments',\n [TranscendPullResource.AssessmentTemplates]: 'assessment-templates',\n [TranscendPullResource.Purposes]: 'purposes',\n [TranscendPullResource.SystemDiscovery]: 'system-discovery',\n};\n\nexport const SCOPES_BY_TITLE = keyBy(\n Object.entries(TRANSCEND_SCOPES).map(([name, value]) => ({\n ...value,\n name,\n })),\n 'title',\n) as Record<\n string,\n ScopeDefinition & {\n /** The camelCased name which identifies the scope */\n name: ScopeName;\n }\n>;\n\nexport const SCOPE_TITLES = Object.keys(SCOPES_BY_TITLE);\n\n/**\n * HTTP statuses that should be retried *in place* without splitting.\n * 429: Rate-limited\n * 502: Upstream/edge gateway error\n * 329: Reserved for custom infra (kept defensively)\n */\nexport const RETRYABLE_BATCH_STATUSES = new Set([429, 502, 500, 504, 329] as const);\n\n/**\n * Debugging\n */\nexport const DEBUG = process.env.DEBUG === '1';\n"],"mappings":"wOCUA,MAAa,EAAO,YAEP,EAAa,2BAEb,EAA0B,GAAG,EAAW,8BACxC,EAAwB,GAAG,EAAW,sCAMtC,EAAwB,QAAQ,IAAI,mBAAqB,2BAQzD,EAA4B,QAAQ,IAAI,mBAAqB,IAAA,GAM7D,EACX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,gBACjB,CAAC,EAAU,mBAAmB,YAClC,CAAC,EAAU,mBAAmB,SACjC,CAAC,EAAU,+BAA+B,cACrC,CAAC,EAAU,+BAA+B,SAC/C,CAAC,EAAU,YAAY,gBAChB,CAAC,EAAU,YAAY,cACzB,CAAC,EAAU,YAAY,QAC7B,CAAC,EAAU,eAAe,gBAClB,CAAC,EAAU,eAAe,YAC9B,CAAC,EAAU,eAAe,SAC7B,CAAC,EAAU,kBAAkB,gBACtB,CAAC,EAAU,kBAAkB,oBACzB,CAAC,EAAU,kBAAkB,uBAC1B,CAAC,EAAU,mBAAmB,aACxC,CAAC,EAAU,mBAAmB,OACpC,CAAC,EAAU,WAAW,UACnB,CAAC,EAAU,iBAAiB,gBACtB,CAAC,EAAU,kBAAkB,UACnC,CAAC,EAAU,aAAa,aACrB,CAAC,EAAU,gBAAgB,qBACnB,CAAC,EAAU,gBAAgB,UACtC,CAChC,EAAU,mBACV,EAAU,4BACX,iBACwC,CAAC,EAAU,YAAY,CACjE,CAEY,EAAqF,SAC/D,wBACG,uBACD,qBACF,yBACO,6BACJ,qBACH,uBACK,iCACI,yCACI,oCACT,wBACF,sBACA,uBACA,oBACF,yBACO,+BACF,uBACN,wBACQ,6BACJ,sBACH,yBACO,qCACI,kCACP,qCACU,gCAChB,iBACG,0BACM,0BACN,uBACG,kCACQ,gCACX,2BACO,mBAC1C,CAEY,EAAkB,EAC7B,OAAO,QAAQ,EAAiB,CAAC,KAAK,CAAC,EAAM,MAAY,CACvD,GAAG,EACH,OACD,EAAE,CACH,QACD,CAQY,EAAe,OAAO,KAAK,EAAgB,CAQ3C,EAA2B,IAAI,IAAI,CAAC,IAAK,IAAK,IAAK,IAAK,IAAI,CAAU,CAKtE,EAAQ,QAAQ,IAAI,QAAU"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{i as e}from"./constants-
|
|
1
|
+
import{i as e}from"./constants-B7bW_WN2.mjs";import{createReadStream as t,readFileSync as n,statSync as r}from"node:fs";import{basename as i}from"node:path";import a from"colors";import*as o from"node:readline";function s(e,t,r){process.stdout.write(`\x1B[2J\x1B[H`);let i=e=>/\b(ERROR|uncaughtException|unhandledRejection)\b/i.test(e),a=e=>/\b(WARN|WARNING)\b/i.test(e),o=[];for(let[,s]of e){if(!s)continue;let e=[];for(let n of t)n===`out`&&s.outPath&&e.push({path:s.outPath,src:`out`}),n===`err`&&s.errPath&&e.push({path:s.errPath,src:`err`}),n===`structured`&&s.structuredPath&&e.push({path:s.structuredPath,src:`structured`}),s.warnPath&&n===`warn`&&e.push({path:s.warnPath,src:`warn`}),s.infoPath&&n===`info`&&e.push({path:s.infoPath,src:`info`});for(let{path:t,src:s}of e){let e=``;try{e=n(t,`utf8`)}catch{continue}for(let t of e.split(`
|
|
2
2
|
`)){if(!t)continue;let e=t.replace(/\x1B\[[0-9;]*m/g,``);if(r===`all`){o.push(t);continue}if(r===`error`){i(e)&&o.push(t);continue}if(a(e)||s===`err`&&!i(e)){o.push(t);continue}}}}o.sort((e,t)=>{let n=e.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/)?.[0]??``,r=t.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/)?.[0]??``;return n.localeCompare(r)}),process.stdout.write(`${o.join(`
|
|
3
3
|
`)}\n`),process.stdout.write(`
|
|
4
4
|
Press Esc/Ctrl+] to return to dashboard.
|
|
@@ -11,4 +11,4 @@ Press Esc/Ctrl+] to return to dashboard.
|
|
|
11
11
|
`);!e.final&&r===p||(p=r,e.final?process.stdout.write(`\x1B[?25h`):(process.stdout.write(`\x1B[?25l`),o.cursorTo(process.stdout,0,0),o.clearScreenDown(process.stdout)),process.stdout.write(`${r}\n`))}function g(e){return typeof e==`number`?e.toLocaleString():`0`}function _(e,t=40){let n=Math.floor(Math.max(0,Math.min(100,Math.floor(e)))/100*t);return`█`.repeat(n)+`░`.repeat(t-n)}function v(e){let t=[...e.workerState.values()].filter(e=>e.busy).length,n=e.filesCompleted+e.filesFailed;return{done:n,inProgress:t,pct:e.filesTotal===0?100:Math.floor(n/Math.max(1,e.filesTotal)*100)}}function y(e,t=[]){let{title:n,poolSize:r,cpuCount:i,filesTotal:o,filesCompleted:s,filesFailed:c,throughput:l}=e,{inProgress:u,pct:d}=v(e),f=[`${a.bold(n)} — ${r} workers ${a.dim(`(CPU avail: ${i})`)}`,`${a.dim(`Files`)} ${g(o)} ${a.dim(`Completed`)} ${g(s)} ${a.dim(`Failed`)} ${c?a.red(g(c)):g(c)} ${a.dim(`In-flight`)} ${g(u)}`,`[${_(d)}] ${d}%`];if(l){let t=l.jobsR10s>0||l.jobsR60s>0,n=Math.round((t?l.jobsR10s:l.r10s)*3600).toLocaleString(),r=Math.round((t?l.jobsR60s:l.r60s)*3600).toLocaleString(),i=t?`rec`:`files`,o=e.throughput?.successSoFar==null?``:` Newly uploaded: ${g(e.throughput.successSoFar)}`;f.push(a.cyan(`Throughput: ${n} ${i}/hr (1h: ${r} ${i}/hr)${o}`))}return t.length?f.concat(t):f}function b(e,t=e=>e?i(e):`-`){return[...e.workerState.entries()].map(([e,n])=>{let r=n.lastLevel===`error`?a.red(`ERROR `):n.lastLevel===`warn`?a.yellow(`WARN `):n.busy?a.green(`WORKING`):a.dim(`IDLE `),i=t(n.file),o=n.startedAt?`${Math.floor((Date.now()-n.startedAt)/1e3)}s`:`-`,s=n.progress?.processed??0,c=n.progress?.total??0,l=c>0?Math.floor(s/c*100):0;return` [w${e}] ${r} | ${i} | ${o} | [${c>0?_(l,18):` `.repeat(18)}] ${c>0?`${s.toLocaleString()}/${c.toLocaleString()} (${l}%)`:a.dim(`—`)}`})}function x(e){let{logsBySlot:t,repaint:n,setPaused:r,exportMgr:i,exportStatus:a,custom:o}=e,c=e=>{process.stdout.write(`${e}\n`)},l=(e,t)=>{let r=Date.now(),i=a?.[e]??{path:t};a&&(a[e]={path:t||i.path,savedAt:r,exported:!0},n())},u=!1,d=(e,i)=>{u||(u=!0,r(!0),process.stdout.write(`\x1B[2J\x1B[H`),process.stdout.write(`Combined logs viewer (press Esc or Ctrl+] to return)
|
|
12
12
|
|
|
13
13
|
`),(async()=>{try{await s(t,e,i)}catch{u=!1,r(!1),n()}})())},f=(e,n)=>{if(i)try{let r=i.exportCombinedLogs(t,e);c(`\nWrote combined ${n} logs to: ${r}`),l(e,r)}catch{c(`\nFailed to write combined ${n} logs`)}};return e=>{let t=e.toString(`utf8`);if(t===`e`){d([`err`],`error`);return}if(t===`w`){d([`warn`,`err`],`warn`);return}if(t===`i`){d([`info`],`all`);return}if(t===`l`){d([`out`,`err`,`structured`],`all`);return}if(t===`E`){f(`error`,`error`);return}if(t===`W`){f(`warn`,`warn`);return}if(t===`I`){f(`info`,`info`);return}if(t===`A`){f(`all`,`ALL`);return}let i=o?.[t];if(i){i({noteExport:l,say:c});return}(t===`\x1B`||t===``)&&(u=!1,r(!1),n())}}export{f as a,h as i,y as n,b as r,x as t};
|
|
14
|
-
//# sourceMappingURL=createExtraKeyHandler-
|
|
14
|
+
//# sourceMappingURL=createExtraKeyHandler-DqiD609a.mjs.map
|
package/dist/{createExtraKeyHandler-CC-YNn6m.mjs.map → createExtraKeyHandler-DqiD609a.mjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExtraKeyHandler-CC-YNn6m.mjs","names":[],"sources":["../src/lib/pooling/showCombinedLogs.ts","../src/lib/pooling/keymap.ts","../src/lib/pooling/replayFileTailToStdout.ts","../src/lib/pooling/workerIds.ts","../src/lib/pooling/installInteractiveSwitcher.ts","../src/lib/pooling/dashboardPlugin.ts","../src/lib/pooling/uiPlugins.ts","../src/lib/pooling/createExtraKeyHandler.ts"],"sourcesContent":["/* eslint-disable no-continue, no-control-regex */\nimport { readFileSync } from 'node:fs';\n\nimport type { WorkerLogPaths } from '@transcend-io/utils';\n\n/**\n * Log locations\n */\nexport type LogLocation = 'out' | 'err' | 'structured' | 'warn' | 'info';\n\n/**\n * Which logs to show in the combined output.\n * Can include 'out' (stdout), 'err' (stderr), 'structured' (\n */\nexport type WhichLogs = Array<LogLocation>;\n\n/**\n * Show combined logs from all worker processes.\n *\n * @param slotLogPaths - Map of worker IDs to their log file paths.\n * @param whichList - one or more sources to include (e.g., ['err','out'])\n * @param filterLevel - 'error', 'warn', or 'all' to filter log levels.\n */\nexport function showCombinedLogs(\n slotLogPaths: Map<number, WorkerLogPaths | undefined>,\n whichList: WhichLogs,\n filterLevel: 'error' | 'warn' | 'all',\n): void {\n process.stdout.write('\\x1b[2J\\x1b[H');\n\n const isError = (t: string): boolean =>\n /\\b(ERROR|uncaughtException|unhandledRejection)\\b/i.test(t);\n const isWarnTag = (t: string): boolean => /\\b(WARN|WARNING)\\b/i.test(t);\n\n const lines: string[] = [];\n\n for (const [, paths] of slotLogPaths) {\n if (!paths) continue;\n\n const files: Array<{\n /** Absolute file path to read from */\n path: string;\n /** Source type for this file, used for classification */\n src: LogLocation;\n }> = [];\n for (const which of whichList) {\n if (which === 'out' && paths.outPath) {\n files.push({ path: paths.outPath, src: 'out' });\n }\n if (which === 'err' && paths.errPath) {\n files.push({ path: paths.errPath, src: 'err' });\n }\n if (which === 'structured' && paths.structuredPath) {\n files.push({ path: paths.structuredPath, src: 'structured' });\n }\n if (paths.warnPath && which === 'warn') {\n files.push({ path: paths.warnPath, src: 'warn' });\n }\n if (paths.infoPath && which === 'info') {\n files.push({ path: paths.infoPath, src: 'info' });\n }\n }\n\n for (const { path, src } of files) {\n let text = '';\n try {\n text = readFileSync(path, 'utf8');\n } catch {\n continue;\n }\n\n for (const ln of text.split('\\n')) {\n if (!ln) continue;\n\n const clean = ln.replace(/\\x1B\\[[0-9;]*m/g, '');\n\n if (filterLevel === 'all') {\n lines.push(ln);\n continue;\n }\n\n if (filterLevel === 'error') {\n if (isError(clean)) lines.push(ln);\n continue;\n }\n\n // filterLevel === 'warn'\n // Accept:\n // - explicit WARN tag anywhere\n // - OR lines from stderr that are NOT explicit errors (many warn libs print to stderr)\n // - OR lines containing the word \"warning\" (common in some libs)\n if (isWarnTag(clean) || (src === 'err' && !isError(clean))) {\n lines.push(ln);\n continue;\n }\n }\n }\n }\n\n // simple time-sort; each worker often prefixes ISO timestamps\n lines.sort((a, b) => {\n const ta = a.match(/\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/)?.[0] ?? '';\n const tb = b.match(/\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/)?.[0] ?? '';\n return ta.localeCompare(tb);\n });\n\n process.stdout.write(`${lines.join('\\n')}\\n`);\n process.stdout.write('\\nPress Esc/Ctrl+] to return to dashboard.\\n');\n}\n/* eslint-enable no-continue, no-control-regex */\n","import type * as readline from 'node:readline';\n\n/**\n * Map a key press to an action in the interactive dashboard.\n */\nexport type Action =\n | {\n /** Indicates attaching to a session by id. */\n type: 'ATTACH';\n /** The id of the session to attach to. */\n id: number;\n }\n | {\n /** Indicates cycling through sessions. */\n type: 'CYCLE';\n /** The direction to cycle: +1 for next, -1 for previous. */\n delta: number;\n }\n | {\n /** Indicates detaching from the current session. */\n type: 'DETACH';\n }\n | {\n /** Indicates the Ctrl+C key combination was pressed. */\n type: 'CTRL_C';\n }\n | {\n /** Indicates the Ctrl+D key combination was pressed. */\n type: 'CTRL_D';\n }\n | {\n /** Indicates quitting the dashboard. */\n type: 'QUIT';\n }\n | {\n /** Forwards an unhandled key sequence. */\n type: 'FORWARD';\n /** The key sequence to forward. */\n sequence: string;\n };\n\n/**\n * Map a key press to an action in the interactive dashboard.\n *\n * @param str - The string representation of the key press.\n * @param key - The key object containing details about the key press.\n * @param mode - The current mode of the dashboard, either 'dashboard' or 'attached'.\n * @returns An Action object representing the mapped action, or null if no action is mapped.\n */\nexport function keymap(\n str: string,\n key: readline.Key,\n mode: 'dashboard' | 'attached',\n): Action | null {\n if (key.ctrl && key.name === 'c') return { type: 'CTRL_C' };\n\n if (mode === 'dashboard') {\n if (key.name && /^[0-9]$/.test(key.name)) {\n return { type: 'ATTACH', id: Number(key.name) };\n }\n if (key.name === 'tab' && !key.shift) return { type: 'CYCLE', delta: +1 };\n if (key.name === 'tab' && key.shift) return { type: 'CYCLE', delta: -1 };\n if (key.name === 'q') return { type: 'QUIT' };\n return null;\n }\n\n // attached\n if (key.name === 'escape' || (key.ctrl && key.name === ']')) {\n return { type: 'DETACH' };\n }\n if (key.ctrl && key.name === 'd') return { type: 'CTRL_D' };\n\n const sequence = key.sequence ?? str ?? '';\n return sequence ? { type: 'FORWARD', sequence } : null;\n}\n","import { createReadStream, statSync } from 'node:fs';\n\n/**\n * Replay the tail of a file to stdout.\n *\n * @param path - The absolute path to the file to read.\n * @param maxBytes - The maximum number of bytes to read from the end of the file.\n * @param write - A function to write the output to stdout.\n */\nexport async function replayFileTailToStdout(\n path: string,\n maxBytes: number,\n write: (s: string) => void,\n): Promise<void> {\n await new Promise<void>((resolve) => {\n try {\n const st = statSync(path);\n const start = Math.max(0, st.size - maxBytes);\n const stream = createReadStream(path, { start, encoding: 'utf8' });\n stream.on('data', (chunk) => write(chunk as string));\n stream.on('end', () => resolve());\n stream.on('error', () => resolve());\n } catch {\n resolve();\n }\n });\n}\n","import type { ChildProcess } from 'node:child_process';\n\n/**\n * Get the sorted list of worker IDs from a map of ChildProcess instances.\n *\n * @param m - Map of worker IDs to ChildProcess instances.\n * @returns Sorted array of worker IDs.\n */\nexport function getWorkerIds(m: Map<number, ChildProcess>): number[] {\n return [...m.keys()].sort((a, b) => a - b);\n}\n\n/**\n * Cycles through an array of numeric IDs, returning the next ID based on a delta.\n *\n * If the `current` ID is not provided or not found in the array, the first ID is used as the starting point.\n * The function then moves forward or backward in the array by `delta` positions, wrapping around if necessary.\n *\n * @param ids - Array of numeric IDs to cycle through.\n * @param current - The current ID to start cycling from. If `null` or not found, starts from the first ID.\n * @param delta - The number of positions to move forward (positive) or backward (negative) in the array.\n * @returns The next ID in the array after cycling, or `null` if the array is empty.\n */\nexport function cycleWorkers(ids: number[], current: number | null, delta: number): number | null {\n if (!ids.length) return null;\n const cur = current == null ? ids[0] : current;\n let i = ids.indexOf(cur);\n if (i === -1) i = 0;\n i = (i + delta + ids.length) % ids.length;\n return ids[i]!;\n}\n","import type { ChildProcess } from 'node:child_process';\nimport * as readline from 'node:readline';\n\nimport type { WorkerLogPaths } from '@transcend-io/utils';\n\nimport { DEBUG } from '../../constants.js';\nimport { keymap } from './keymap.js';\nimport { replayFileTailToStdout } from './replayFileTailToStdout.js';\nimport type { WhichLogs } from './showCombinedLogs.js';\nimport { cycleWorkers, getWorkerIds } from './workerIds.js';\n\n/**\n * Key action types for the interactive switcher\n */\nexport type InteractiveDashboardMode = 'dashboard' | 'attached';\n\nexport interface SwitcherPorts {\n /** Standard input stream */\n stdin: NodeJS.ReadStream;\n /** Standard output stream */\n stdout: NodeJS.WriteStream;\n /** Standard error stream */\n stderr: NodeJS.WriteStream;\n}\n\n/**\n * Install an interactive switcher for managing worker processes.\n *\n * @param opts - Options for the switcher\n * @returns A cleanup function to remove the switcher\n */\nexport function installInteractiveSwitcher(opts: {\n /** Registry of live workers by id */\n workers: Map<number, ChildProcess>;\n /** Hooks */\n onAttach?: (id: number) => void;\n /** Optional detach handler */\n onDetach?: () => void;\n /** Optional Ctrl+C handler for parent graceful shutdown in dashboard */\n onCtrlC?: () => void; // parent graceful shutdown in dashboard\n /** Provide log paths so we can replay the tail on attach */\n getLogPaths?: (id: number) => WorkerLogPaths | undefined;\n /** How many bytes to replay from the end of each file (default 200 KB) */\n replayBytes?: number;\n /** Which logs to replay first (default ['out','err']) */\n replayWhich?: WhichLogs;\n /** Print a small banner/clear screen before replaying (optional) */\n onEnterAttachScreen?: (id: number) => void;\n /** Optional stdio ports for testing; defaults to process stdio */\n ports?: SwitcherPorts;\n}): () => void {\n const {\n workers,\n onAttach,\n onDetach,\n onCtrlC,\n getLogPaths,\n replayBytes = 200 * 1024,\n replayWhich = ['out', 'err'],\n onEnterAttachScreen,\n ports,\n } = opts;\n\n const stdin = ports?.stdin ?? process.stdin;\n const stdout = ports?.stdout ?? process.stdout;\n const stderr = ports?.stderr ?? process.stderr;\n\n const d = (...a: unknown[]): void => {\n if (DEBUG) {\n try {\n (ports?.stderr ?? process.stderr).write(`[keys] ${a.map(String).join(' ')}\\n`);\n } catch {\n // noop\n }\n }\n };\n\n if (!stdin.isTTY) {\n // Not a TTY; return a no-op cleanup\n return () => {\n // noop\n };\n }\n\n readline.emitKeypressEvents(stdin);\n stdin.setRawMode?.(true);\n\n let mode: InteractiveDashboardMode = 'dashboard';\n let focus: number | null = null;\n\n // live mirroring handlers while attached\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let outHandler: ((chunk: any) => void) | null = null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let errHandler: ((chunk: any) => void) | null = null;\n\n /**\n * Cycle through worker IDs, wrapping around.\n *\n * @param id - The current worker ID to start cycling from.\n * @returns The next worker ID after cycling, or null if no workers are available.\n */\n async function replayLogs(id: number): Promise<void> {\n if (!getLogPaths) return;\n const paths = getLogPaths(id);\n if (!paths) return;\n\n const toReplay: string[] = [];\n for (const which of replayWhich) {\n if (which === 'out') toReplay.push(paths.outPath);\n if (which === 'err') toReplay.push(paths.errPath);\n if (which === 'structured') toReplay.push(paths.structuredPath);\n }\n\n if (toReplay.length) {\n stdout.write('\\n------------ replay ------------\\n');\n for (const p of toReplay) {\n stdout.write(`\\n--- ${p} (last ~${Math.floor(replayBytes / 1024)}KB) ---\\n`);\n await replayFileTailToStdout(p, replayBytes, (s) => stdout.write(s));\n }\n stdout.write('\\n--------------------------------\\n\\n');\n }\n }\n\n const attach = async (id: number): Promise<void> => {\n d('attach()', `id=${id}`); // at function entry\n\n const w = workers.get(id);\n if (!w) return;\n\n // Detach any previous focus\n if (mode === 'attached') detach();\n\n mode = 'attached';\n focus = id;\n\n // UX: clear + banner\n onEnterAttachScreen?.(id);\n\n onAttach?.(id); // prints “Attached to worker …” and clears\n await replayLogs(id); // now the tail stays visible\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n outHandler = (chunk: any) => stdout.write(chunk);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n errHandler = (chunk: any) => stderr.write(chunk);\n w.stdout?.on('data', outHandler);\n w.stderr?.on('data', errHandler);\n\n // auto-detach if child exits\n const onExit = (): void => {\n if (focus === id) detach();\n };\n w.once('exit', onExit);\n };\n\n const detach = (): void => {\n d('detach()', `id=${focus}`); // at function entry\n\n if (focus == null) return;\n const id = focus;\n const w = workers.get(id);\n if (w) {\n if (outHandler) w.stdout?.off('data', outHandler);\n if (errHandler) w.stderr?.off('data', errHandler);\n }\n outHandler = null;\n errHandler = null;\n focus = null;\n mode = 'dashboard';\n onDetach?.();\n };\n\n const onKey = (str: string, key: readline.Key): void => {\n d(\n 'keypress',\n JSON.stringify({\n str,\n name: key.name,\n seq: key.sequence,\n ctrl: key.ctrl,\n meta: key.meta,\n shift: key.shift,\n mode,\n }),\n );\n const act = keymap(str, key, mode);\n d('mapped', JSON.stringify(act));\n\n if (!act) return;\n\n // eslint-disable-next-line default-case\n switch (act.type) {\n case 'CTRL_C': {\n d('CTRL_C');\n if (mode === 'attached' && focus != null) {\n const w = workers.get(focus);\n try {\n w?.kill('SIGINT');\n } catch {\n // noop\n }\n // optional: auto-detach so second Ctrl+C exits parent\n detach();\n return;\n }\n onCtrlC?.();\n return;\n }\n\n case 'ATTACH': {\n d('ATTACH', `id=${act.id}`, `has=${workers.has(act.id)}`);\n\n if (mode !== 'dashboard') return;\n // eslint-disable-next-line no-void\n if (workers.has(act.id)) void attach(act.id);\n return;\n }\n\n case 'CYCLE': {\n d('CYCLE', `delta=${act.delta}`);\n if (mode !== 'dashboard') return;\n const next = cycleWorkers(getWorkerIds(workers), focus, act.delta);\n // eslint-disable-next-line no-void\n if (next != null) void attach(next);\n return;\n }\n\n case 'QUIT': {\n if (mode !== 'dashboard') return;\n onCtrlC?.();\n return;\n }\n\n case 'DETACH': {\n d('DETACH');\n if (mode === 'attached') detach();\n return;\n }\n\n case 'CTRL_D': {\n if (mode === 'attached' && focus != null) {\n const w = workers.get(focus);\n try {\n w?.stdin?.end();\n } catch {\n // noop\n }\n }\n return;\n }\n\n case 'FORWARD': {\n if (mode === 'attached' && focus != null) {\n const w = workers.get(focus);\n try {\n w?.stdin?.write(act.sequence);\n } catch {\n // noop\n }\n }\n }\n }\n };\n\n // Raw bytes fallback (usually not hit because keypress handles it)\n const onData = (chunk: Buffer): void => {\n if (mode === 'attached' && focus != null) {\n const w = workers.get(focus);\n try {\n w?.stdin?.write(chunk);\n } catch {\n // noop\n }\n }\n };\n\n const cleanup = (): void => {\n stdin.off('keypress', onKey);\n stdin.off('data', onData);\n stdin.setRawMode?.(false);\n stdout.write('\\x1b[?25h');\n };\n\n stdin.on('keypress', onKey);\n stdin.on('data', onData);\n\n return cleanup;\n}\n","// lib/pooling/dashboardPlugin.ts\nimport * as readline from 'node:readline';\n\nimport type { ObjByString } from '@transcend-io/type-utils';\nimport type { SlotState } from '@transcend-io/utils';\nimport colors from 'colors';\n\n/**\n * A dashboard plugin defines how to render the worker pool UI.\n * Commands can supply a plugin to customize:\n * - The header block (summary stats, title, etc.)\n * - Per-worker rows (one line per worker slot)\n * - Optional extras (artifact exports, breakdowns, footers)\n *\n * @template TTotals - The shape of the aggregate totals object maintained by the command.\n */\nexport interface DashboardPlugin<TTotals, TSlotState extends ObjByString> {\n /**\n * Render the header block of the dashboard.\n *\n * @param ctx - Context with pool/worker state, totals, and metadata.\n * @returns An array of strings, each representing one line in the header.\n */\n renderHeader: (ctx: CommonCtx<TTotals, TSlotState>) => string[];\n\n /**\n * Render per-worker rows, usually one line per worker slot.\n *\n * @param ctx - Context with pool/worker state, totals, and metadata.\n * @returns An array of strings, each representing one row in the workers section.\n */\n renderWorkers: (ctx: CommonCtx<TTotals, TSlotState>) => string[];\n\n /**\n * Render any optional extra blocks that appear after the worker rows.\n * Useful for printing export paths, aggregated metrics, breakdowns, etc.\n *\n * @param ctx - Context with pool/worker state, totals, and metadata.\n * @returns An array of strings, each representing one additional line.\n */\n renderExtras?: (ctx: CommonCtx<TTotals, TSlotState>) => string[];\n}\n\n/**\n * Shared context object passed into all render methods of a {@link DashboardPlugin}.\n *\n * @template TTotals - The shape of the aggregate totals object maintained by the command.\n */\nexport type CommonCtx<TTotals, TSlotState extends ObjByString> = {\n /** Human-readable title for the dashboard (e.g., \"Parallel uploader\"). */\n title: string;\n\n /** Number of worker processes spawned in the pool. */\n poolSize: number;\n\n /** Logical CPU count, included for informational display. */\n cpuCount: number;\n\n /** Total number of \"files\" or logical units the command expects to process. */\n filesTotal: number;\n\n /** Count of successfully completed files/tasks. */\n filesCompleted: number;\n\n /** Count of failed files/tasks. */\n filesFailed: number;\n\n /**\n * State of each worker slot, keyed by worker id.\n * Includes busy flag, file label, start time, last log badge, and progress.\n */\n workerState: Map<number, SlotState<TSlotState>>;\n\n /**\n * Aggregate totals maintained by the command’s hook logic.\n * Domain-specific metrics (e.g., rows uploaded, bytes processed) can be surfaced here.\n */\n totals: TTotals;\n\n /**\n * Throughput metrics tracked by the runner:\n * - successSoFar: convenience alias for completed count\n * - r10s: completions/sec averaged over last 10s\n * - r60s: completions/sec averaged over last 60s\n */\n throughput: {\n /** Cumulative count of successful completions so far. */\n successSoFar: number;\n /** Recent file-level throughput rate over the last 10 seconds. */\n r10s: number;\n /** Recent file-level throughput rate over the last 60 seconds. */\n r60s: number;\n /** Recent job/record-level throughput rate over the last 10 seconds. */\n jobsR10s: number;\n /** Recent job/record-level throughput rate over the last 60 seconds. */\n jobsR60s: number;\n };\n\n /** True when the pool has fully drained and all workers have exited. */\n final: boolean;\n\n /**\n * Optional export status payload provided by the command.\n * Useful for rendering artifact paths or \"latest export\" summaries.\n */\n exportStatus?: Record<string, unknown>;\n};\n\n/** The most recently rendered frame, cached to suppress flicker from duplicate renders. */\nlet lastFrame = '';\n\n/**\n * Generate the hotkeys hint string that appears at the bottom of the dashboard.\n *\n * @param poolSize - The number of worker slots in the pool.\n * @param final - Whether the run has completed.\n * @returns A dimmed string listing the supported hotkeys for attach/detach/quit.\n */\nexport const hotkeysHint = (poolSize: number, final: boolean): string => {\n const maxDigit = Math.min(poolSize - 1, 9);\n const digitRange = poolSize <= 1 ? '0' : `0-${maxDigit}`;\n const extra = poolSize > 10 ? ' (Tab/Shift+Tab for ≥10)' : '';\n return final\n ? colors.dim(\n 'Run complete — digits to view logs • Tab/Shift+Tab cycle • Esc/Ctrl+] detach • q to quit',\n )\n : colors.dim(\n `Hotkeys: [${digitRange}] attach${extra} • e=errors • w=warnings • i=info • l=logs • ` +\n 'Tab/Shift+Tab • Esc/Ctrl+] detach • Ctrl+C exit',\n );\n};\n\n/**\n * Render the dashboard using a supplied {@link DashboardPlugin}.\n *\n * The frame is composed of:\n * - Header lines\n * - A blank separator\n * - Worker rows\n * - A blank separator\n * - Hotkeys hint\n * - Optional extras (if plugin supplies them)\n *\n * Optimizations:\n * - Suppresses re-renders if the frame is identical to the previous frame (flicker-free).\n * - Hides the terminal cursor during live updates, restoring it when final.\n *\n * @param ctx - Shared context containing pool state, worker state, totals, throughput, etc.\n * @param plugin - The plugin that defines how to render the header, workers, and optional extras.\n * @param viewerMode - If true, renders in viewer mode (no ability to switch between files).\n */\nexport function dashboardPlugin<TTotals, TSlotState extends ObjByString>(\n ctx: CommonCtx<TTotals, TSlotState>,\n plugin: DashboardPlugin<TTotals, TSlotState>,\n viewerMode = false,\n): void {\n const frame = [\n ...plugin.renderHeader(ctx),\n '',\n ...plugin.renderWorkers(ctx),\n ...(viewerMode ? [] : ['', hotkeysHint(ctx.poolSize, ctx.final)]),\n ...(plugin.renderExtras ? [''].concat(plugin.renderExtras(ctx)) : []),\n ].join('\\n');\n\n // Skip duplicate renders during live runs to avoid flicker.\n if (!ctx.final && frame === lastFrame) return;\n lastFrame = frame;\n\n if (!ctx.final) {\n // Hide cursor and repaint in place\n process.stdout.write('\\x1b[?25l');\n readline.cursorTo(process.stdout, 0, 0);\n readline.clearScreenDown(process.stdout);\n } else {\n // Restore cursor on final render\n process.stdout.write('\\x1b[?25h');\n }\n process.stdout.write(`${frame}\\n`);\n}\n","import { basename } from 'node:path';\n\nimport type { ObjByString } from '@transcend-io/type-utils';\nimport colors from 'colors';\n\nimport type { CommonCtx } from './dashboardPlugin.js';\n\n/**\n * Progress snapshot for a worker slot in the chunk-csv command.\n */\nexport type ChunkSlotProgress = {\n /** Absolute path of the file being processed by this worker. */\n filePath?: string;\n /** Number of rows processed so far in this file. */\n processed?: number;\n /** Optional total number of rows in the file (if known). */\n total?: number;\n};\n\n/**\n * Format a number safely for display.\n *\n * @param n - The number to format (or `undefined`).\n * @returns A localized string representation, or \"0\".\n */\nexport function fmtNum(n: number | undefined): string {\n return typeof n === 'number' ? n.toLocaleString() : '0';\n}\n\n/**\n * Draw a horizontal bar of length `width` filled to `pct` percent.\n *\n * @param pct - Percentage 0..100.\n * @param width - Number of characters in the bar.\n * @returns A string like \"████░░░░\".\n */\nexport function pctBar(pct: number, width = 40): string {\n const clamped = Math.max(0, Math.min(100, Math.floor(pct)));\n const filled = Math.floor((clamped / 100) * width);\n return '█'.repeat(filled) + '░'.repeat(width - filled);\n}\n\n/**\n * Compute pool-wide progress values needed by headers.\n *\n * @param ctx - Dashboard context containing pool state, worker state, totals, etc.\n * @returns An object with `done`, `inProgress`, and `pct` properties.\n */\nexport function poolProgress<TTotals, TSlot extends ObjByString>(\n ctx: CommonCtx<TTotals, TSlot>,\n): {\n /** Count of successfully completed files/tasks. */\n done: number;\n /** Count of currently in-progress files/tasks. */\n inProgress: number;\n /** Percentage of completion (0-100). */\n pct: number;\n} {\n const inProgress = [...ctx.workerState.values()].filter((s) => s.busy).length;\n const done = ctx.filesCompleted + ctx.filesFailed;\n const pct = ctx.filesTotal === 0 ? 100 : Math.floor((done / Math.max(1, ctx.filesTotal)) * 100);\n return { done, inProgress, pct };\n}\n\n/**\n * Compose the common header lines (title, pool stats, progress bar, throughput).\n *\n * @param ctx - Dashboard context.\n * @param extraLines - Optional extra lines (e.g., totals block).\n * @returns Header lines.\n */\nexport function makeHeader<TTotals, TSlot extends ObjByString>(\n ctx: CommonCtx<TTotals, TSlot>,\n extraLines: string[] = [],\n): string[] {\n const { title, poolSize, cpuCount, filesTotal, filesCompleted, filesFailed, throughput } = ctx;\n const { inProgress, pct } = poolProgress(ctx);\n\n const lines: string[] = [\n `${colors.bold(title)} — ${poolSize} workers ${colors.dim(`(CPU avail: ${cpuCount})`)}`,\n `${colors.dim('Files')} ${fmtNum(filesTotal)} ${colors.dim(\n 'Completed',\n )} ${fmtNum(filesCompleted)} ${colors.dim('Failed')} ${\n filesFailed ? colors.red(fmtNum(filesFailed)) : fmtNum(filesFailed)\n } ${colors.dim('In-flight')} ${fmtNum(inProgress)}`,\n `[${pctBar(pct)}] ${pct}%`,\n ];\n\n if (throughput) {\n const jobsActive = throughput.jobsR10s > 0 || throughput.jobsR60s > 0;\n const perHour10 = Math.round(\n (jobsActive ? throughput.jobsR10s : throughput.r10s) * 3600,\n ).toLocaleString();\n const perHour60 = Math.round(\n (jobsActive ? throughput.jobsR60s : throughput.r60s) * 3600,\n ).toLocaleString();\n const unit = jobsActive ? 'rec' : 'files';\n const suffix =\n ctx.throughput?.successSoFar != null\n ? ` Newly uploaded: ${fmtNum(ctx.throughput.successSoFar)}`\n : '';\n lines.push(\n colors.cyan(`Throughput: ${perHour10} ${unit}/hr (1h: ${perHour60} ${unit}/hr)${suffix}`),\n );\n }\n\n return extraLines.length ? lines.concat(extraLines) : lines;\n}\n\n/**\n * Render per-worker rows with a compact progress bar and status badge.\n *\n * @param ctx - Dashboard context (slot progress type must have processed/total?).\n * @param getFileLabel - Optional: override how the filename is shown.\n * @returns Array of strings, each representing one worker row.\n */\nexport function makeWorkerRows<TTotals, TSlot extends Omit<ChunkSlotProgress, 'filePath'>>(\n ctx: CommonCtx<TTotals, TSlot>,\n getFileLabel: (file: string | null | undefined) => string = (file) =>\n file ? basename(file) : '-',\n): string[] {\n const miniWidth = 18;\n\n return [...ctx.workerState.entries()].map(([id, s]) => {\n const badge =\n s.lastLevel === 'error'\n ? colors.red('ERROR ')\n : s.lastLevel === 'warn'\n ? colors.yellow('WARN ')\n : s.busy\n ? colors.green('WORKING')\n : colors.dim('IDLE ');\n\n const fname = getFileLabel(s.file);\n const elapsed = s.startedAt ? `${Math.floor((Date.now() - s.startedAt) / 1000)}s` : '-';\n\n const processed = s.progress?.processed ?? 0;\n const total = s.progress?.total ?? 0;\n const pctw = total > 0 ? Math.floor((processed / total) * 100) : 0;\n const mini = total > 0 ? pctBar(pctw, miniWidth) : ' '.repeat(miniWidth);\n const miniTxt =\n total > 0\n ? `${processed.toLocaleString()}/${total.toLocaleString()} (${pctw}%)`\n : colors.dim('—');\n\n return ` [w${id}] ${badge} | ${fname} | ${elapsed} | [${mini}] ${miniTxt}`;\n });\n}\n","import type { ExportStatusMap, SlotPaths } from '@transcend-io/utils';\n\nimport { showCombinedLogs, type LogLocation } from './showCombinedLogs.js';\n\n/** Severity filter applied by the viewer. */\ntype ViewLevel = 'error' | 'warn' | 'all';\n\n/**\n * Options for {@link createExtraKeyHandler}.\n */\nexport type CreateExtraKeyHandlerOpts = {\n /**\n * Per-slot log file paths maintained by the runner; used to stream or export logs.\n */\n logsBySlot: SlotPaths;\n\n /**\n * Request an immediate dashboard repaint (e.g., after updating export status).\n */\n repaint: () => void;\n\n /**\n * Pause/unpause dashboard repainting. The handler pauses while a viewer is open\n * to prevent the dashboard from overwriting the viewer output, then resumes on exit.\n */\n setPaused: (p: boolean) => void;\n\n /**\n * Optional export manager to enable uppercase export keys:\n * - `E` (errors) • `W` (warnings) • `I` (info) • `A` (all)\n *\n * Provide this only if your command supports writing combined log files.\n */\n exportMgr?: {\n /** Destination directory for exported artifacts. */\n exportsDir: string;\n /**\n * Write a combined log file for the selected severity and return the absolute path.\n *\n * @param logs - Log paths to combine.\n * @param which - Severity selection.\n * @returns Absolute path to the written file.\n */\n exportCombinedLogs: (logs: SlotPaths, which: 'error' | 'warn' | 'info' | 'all') => string;\n };\n\n /**\n * Optional “Exports” status map. If provided, the handler updates timestamps\n * when exports are written so your dashboard panel can reflect “last saved” times.\n */\n exportStatus?: ExportStatusMap;\n\n /**\n * Optional custom key bindings for command-specific actions.\n * Each handler receives helpers to print messages and to update the exports panel.\n *\n * Example:\n * ```ts\n * custom: {\n * F: async ({ say, noteExport }) => {\n * const p = await writeFailingUpdatesCsv(...);\n * say(`Wrote failing updates to: ${p}`);\n * noteExport('failuresCsv', p);\n * }\n * }\n * ```\n */\n custom?: Record<\n string,\n (ctx: {\n /** Update {@link exportStatus} (if present) and repaint the dashboard. */\n noteExport: (slot: keyof ExportStatusMap, absPath: string) => void;\n /** Print a line to stdout, automatically newline-terminated. */\n say: (s: string) => void;\n }) => void | Promise<void>\n >;\n};\n\n/**\n * Create a keypress handler for interactive viewers/exports.\n * Shared handler for \"extra\" keyboard shortcuts used by the interactive dashboard.\n *\n * It wires:\n * - **Viewers (lowercase):** `e` (errors), `w` (warnings), `i` (info), `l` (all)\n * - **Exports (uppercase, optional):** `E` (errors), `W` (warnings), `I` (info), `A` (all)\n * - **Dismiss:** `Esc` or `Ctrl+]` exits a viewer and returns to the dashboard\n * - **Custom keys (optional):** Provide a `custom` map to handle command-specific bindings\n *\n * Usage (inside `runPool({... extraKeyHandler })`):\n * ```ts\n * extraKeyHandler: ({ logsBySlot, repaint, setPaused }) =>\n * createExtraKeyHandler({ logsBySlot, repaint, setPaused })\n * ```\n *\n * If you also want export hotkeys + an \"Exports\" panel:\n * ```ts\n * extraKeyHandler: ({ logsBySlot, repaint, setPaused }) =>\n * createExtraKeyHandler({\n * logsBySlot, repaint, setPaused,\n * exportMgr, // enables E/W/I/A\n * exportStatus, // keeps panel timestamps up to date\n * custom: { // optional, e.g. 'F' to export a CSV\n * F: async ({ say, noteExport }) => { ... }\n * }\n * })\n * ```\n *\n * @param opts - Configuration for viewers, exports, and custom keys.\n * @returns A `(buf: Buffer) => void` handler suitable for `process.stdin.on('data', ...)`.\n */\nexport function createExtraKeyHandler(opts: CreateExtraKeyHandlerOpts): (buf: Buffer) => void {\n const { logsBySlot, repaint, setPaused, exportMgr, exportStatus, custom } = opts;\n\n const say = (s: string): void => {\n process.stdout.write(`${s}\\n`);\n };\n\n /**\n * Record that an export was written and trigger a repaint so the dashboard’s\n * \"Exports\" panel shows the updated timestamp/path.\n *\n * @param slot - Slot name in {@link ExportStatusMap} (e.g., \"error\", \"warn\", etc.).\n * @param p - Absolute path to the exported file.\n */\n const noteExport = (slot: keyof ExportStatusMap, p: string): void => {\n const now = Date.now();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const cur: any = exportStatus?.[slot] ?? { path: p };\n if (exportStatus) {\n exportStatus[slot] = {\n path: p || cur.path,\n savedAt: now,\n exported: true,\n };\n repaint();\n }\n };\n\n let viewing = false; // optional guard to prevent stacking viewers\n\n /**\n * Show an inline combined log viewer for the selected sources/level.\n * Pauses dashboard repaint to keep the viewer visible until the user exits.\n *\n * @param sources - Log sources to include (e.g., \"err\", \"warn\", \"info\").\n * @param level - Severity level to filter by (e.g., \"error\", \"warn\", \"all\").\n */\n const view = (sources: LogLocation[], level: ViewLevel): void => {\n if (viewing) return;\n viewing = true;\n setPaused(true);\n\n // optional UX: clear screen and show a hint\n process.stdout.write('\\x1b[2J\\x1b[H'); // clear+home\n process.stdout.write('Combined logs viewer (press Esc or Ctrl+] to return)\\n\\n');\n\n (async () => {\n try {\n await showCombinedLogs(logsBySlot, sources, level);\n // NOTE: do NOT unpause here; ESC will handle it.\n } catch {\n // If showCombinedLogs throws, recover and unpause\n viewing = false;\n setPaused(false);\n repaint();\n }\n })();\n };\n\n /**\n * Export combined logs (if an export manager was provided).\n *\n * @param which - Severity to export (e.g., \"error\", \"warn\", \"info\", \"all\").\n * @param label - Human-readable label for the export (e.g., \"error\", \"warn\").\n */\n const exportCombined = (which: 'error' | 'warn' | 'info' | 'all', label: string): void => {\n if (!exportMgr) return;\n try {\n const p = exportMgr.exportCombinedLogs(logsBySlot, which);\n say(`\\nWrote combined ${label} logs to: ${p}`);\n noteExport(which as keyof ExportStatusMap, p);\n } catch {\n say(`\\nFailed to write combined ${label} logs`);\n }\n };\n\n // The keypress handler the runner will attach to stdin.\n return (buf: Buffer): void => {\n const s = buf.toString('utf8');\n\n // Viewers (lowercase)\n if (s === 'e') {\n view(['err'], 'error');\n return;\n }\n if (s === 'w') {\n view(['warn', 'err'], 'warn');\n return;\n }\n if (s === 'i') {\n view(['info'], 'all');\n return;\n }\n if (s === 'l') {\n view(['out', 'err', 'structured'], 'all');\n return;\n }\n\n // Exports (uppercase) — enabled only when exportMgr is present\n if (s === 'E') {\n exportCombined('error', 'error');\n return;\n }\n if (s === 'W') {\n exportCombined('warn', 'warn');\n return;\n }\n if (s === 'I') {\n exportCombined('info', 'info');\n return;\n }\n if (s === 'A') {\n exportCombined('all', 'ALL');\n return;\n }\n\n // Command-specific bindings\n const fn = custom?.[s];\n if (fn) {\n fn({ noteExport, say });\n return;\n }\n\n // Exit a viewer (Esc / Ctrl+]) — resume dashboard\n if (s === '\\x1b' || s === '\\x1d') {\n viewing = false;\n setPaused(false);\n repaint();\n }\n };\n}\n"],"mappings":"mNAuBA,SAAgB,EACd,EACA,EACA,EACM,CACN,QAAQ,OAAO,MAAM,gBAAgB,CAErC,IAAM,EAAW,GACf,oDAAoD,KAAK,EAAE,CACvD,EAAa,GAAuB,sBAAsB,KAAK,EAAE,CAEjE,EAAkB,EAAE,CAE1B,IAAK,GAAM,EAAG,KAAU,EAAc,CACpC,GAAI,CAAC,EAAO,SAEZ,IAAM,EAKD,EAAE,CACP,IAAK,IAAM,KAAS,EACd,IAAU,OAAS,EAAM,SAC3B,EAAM,KAAK,CAAE,KAAM,EAAM,QAAS,IAAK,MAAO,CAAC,CAE7C,IAAU,OAAS,EAAM,SAC3B,EAAM,KAAK,CAAE,KAAM,EAAM,QAAS,IAAK,MAAO,CAAC,CAE7C,IAAU,cAAgB,EAAM,gBAClC,EAAM,KAAK,CAAE,KAAM,EAAM,eAAgB,IAAK,aAAc,CAAC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,CAChC,OAEF,GAAI,IAAM,IAAK,CACb,EAAe,OAAQ,OAAO,CAC9B,OAEF,GAAI,IAAM,IAAK,CACb,EAAe,OAAQ,OAAO,CAC9B,OAEF,GAAI,IAAM,IAAK,CACb,EAAe,MAAO,MAAM,CAC5B,OAIF,IAAM,EAAK,IAAS,GACpB,GAAI,EAAI,CACN,EAAG,CAAE,aAAY,MAAK,CAAC,CACvB,QAIE,IAAM,QAAU,IAAM,OACxB,EAAU,GACV,EAAU,GAAM,CAChB,GAAS"}
|
|
1
|
+
{"version":3,"file":"createExtraKeyHandler-DqiD609a.mjs","names":[],"sources":["../src/lib/pooling/showCombinedLogs.ts","../src/lib/pooling/keymap.ts","../src/lib/pooling/replayFileTailToStdout.ts","../src/lib/pooling/workerIds.ts","../src/lib/pooling/installInteractiveSwitcher.ts","../src/lib/pooling/dashboardPlugin.ts","../src/lib/pooling/uiPlugins.ts","../src/lib/pooling/createExtraKeyHandler.ts"],"sourcesContent":["/* eslint-disable no-continue, no-control-regex */\nimport { readFileSync } from 'node:fs';\n\nimport type { WorkerLogPaths } from '@transcend-io/utils';\n\n/**\n * Log locations\n */\nexport type LogLocation = 'out' | 'err' | 'structured' | 'warn' | 'info';\n\n/**\n * Which logs to show in the combined output.\n * Can include 'out' (stdout), 'err' (stderr), 'structured' (\n */\nexport type WhichLogs = Array<LogLocation>;\n\n/**\n * Show combined logs from all worker processes.\n *\n * @param slotLogPaths - Map of worker IDs to their log file paths.\n * @param whichList - one or more sources to include (e.g., ['err','out'])\n * @param filterLevel - 'error', 'warn', or 'all' to filter log levels.\n */\nexport function showCombinedLogs(\n slotLogPaths: Map<number, WorkerLogPaths | undefined>,\n whichList: WhichLogs,\n filterLevel: 'error' | 'warn' | 'all',\n): void {\n process.stdout.write('\\x1b[2J\\x1b[H');\n\n const isError = (t: string): boolean =>\n /\\b(ERROR|uncaughtException|unhandledRejection)\\b/i.test(t);\n const isWarnTag = (t: string): boolean => /\\b(WARN|WARNING)\\b/i.test(t);\n\n const lines: string[] = [];\n\n for (const [, paths] of slotLogPaths) {\n if (!paths) continue;\n\n const files: Array<{\n /** Absolute file path to read from */\n path: string;\n /** Source type for this file, used for classification */\n src: LogLocation;\n }> = [];\n for (const which of whichList) {\n if (which === 'out' && paths.outPath) {\n files.push({ path: paths.outPath, src: 'out' });\n }\n if (which === 'err' && paths.errPath) {\n files.push({ path: paths.errPath, src: 'err' });\n }\n if (which === 'structured' && paths.structuredPath) {\n files.push({ path: paths.structuredPath, src: 'structured' });\n }\n if (paths.warnPath && which === 'warn') {\n files.push({ path: paths.warnPath, src: 'warn' });\n }\n if (paths.infoPath && which === 'info') {\n files.push({ path: paths.infoPath, src: 'info' });\n }\n }\n\n for (const { path, src } of files) {\n let text = '';\n try {\n text = readFileSync(path, 'utf8');\n } catch {\n continue;\n }\n\n for (const ln of text.split('\\n')) {\n if (!ln) continue;\n\n const clean = ln.replace(/\\x1B\\[[0-9;]*m/g, '');\n\n if (filterLevel === 'all') {\n lines.push(ln);\n continue;\n }\n\n if (filterLevel === 'error') {\n if (isError(clean)) lines.push(ln);\n continue;\n }\n\n // filterLevel === 'warn'\n // Accept:\n // - explicit WARN tag anywhere\n // - OR lines from stderr that are NOT explicit errors (many warn libs print to stderr)\n // - OR lines containing the word \"warning\" (common in some libs)\n if (isWarnTag(clean) || (src === 'err' && !isError(clean))) {\n lines.push(ln);\n continue;\n }\n }\n }\n }\n\n // simple time-sort; each worker often prefixes ISO timestamps\n lines.sort((a, b) => {\n const ta = a.match(/\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/)?.[0] ?? '';\n const tb = b.match(/\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/)?.[0] ?? '';\n return ta.localeCompare(tb);\n });\n\n process.stdout.write(`${lines.join('\\n')}\\n`);\n process.stdout.write('\\nPress Esc/Ctrl+] to return to dashboard.\\n');\n}\n/* eslint-enable no-continue, no-control-regex */\n","import type * as readline from 'node:readline';\n\n/**\n * Map a key press to an action in the interactive dashboard.\n */\nexport type Action =\n | {\n /** Indicates attaching to a session by id. */\n type: 'ATTACH';\n /** The id of the session to attach to. */\n id: number;\n }\n | {\n /** Indicates cycling through sessions. */\n type: 'CYCLE';\n /** The direction to cycle: +1 for next, -1 for previous. */\n delta: number;\n }\n | {\n /** Indicates detaching from the current session. */\n type: 'DETACH';\n }\n | {\n /** Indicates the Ctrl+C key combination was pressed. */\n type: 'CTRL_C';\n }\n | {\n /** Indicates the Ctrl+D key combination was pressed. */\n type: 'CTRL_D';\n }\n | {\n /** Indicates quitting the dashboard. */\n type: 'QUIT';\n }\n | {\n /** Forwards an unhandled key sequence. */\n type: 'FORWARD';\n /** The key sequence to forward. */\n sequence: string;\n };\n\n/**\n * Map a key press to an action in the interactive dashboard.\n *\n * @param str - The string representation of the key press.\n * @param key - The key object containing details about the key press.\n * @param mode - The current mode of the dashboard, either 'dashboard' or 'attached'.\n * @returns An Action object representing the mapped action, or null if no action is mapped.\n */\nexport function keymap(\n str: string,\n key: readline.Key,\n mode: 'dashboard' | 'attached',\n): Action | null {\n if (key.ctrl && key.name === 'c') return { type: 'CTRL_C' };\n\n if (mode === 'dashboard') {\n if (key.name && /^[0-9]$/.test(key.name)) {\n return { type: 'ATTACH', id: Number(key.name) };\n }\n if (key.name === 'tab' && !key.shift) return { type: 'CYCLE', delta: +1 };\n if (key.name === 'tab' && key.shift) return { type: 'CYCLE', delta: -1 };\n if (key.name === 'q') return { type: 'QUIT' };\n return null;\n }\n\n // attached\n if (key.name === 'escape' || (key.ctrl && key.name === ']')) {\n return { type: 'DETACH' };\n }\n if (key.ctrl && key.name === 'd') return { type: 'CTRL_D' };\n\n const sequence = key.sequence ?? str ?? '';\n return sequence ? { type: 'FORWARD', sequence } : null;\n}\n","import { createReadStream, statSync } from 'node:fs';\n\n/**\n * Replay the tail of a file to stdout.\n *\n * @param path - The absolute path to the file to read.\n * @param maxBytes - The maximum number of bytes to read from the end of the file.\n * @param write - A function to write the output to stdout.\n */\nexport async function replayFileTailToStdout(\n path: string,\n maxBytes: number,\n write: (s: string) => void,\n): Promise<void> {\n await new Promise<void>((resolve) => {\n try {\n const st = statSync(path);\n const start = Math.max(0, st.size - maxBytes);\n const stream = createReadStream(path, { start, encoding: 'utf8' });\n stream.on('data', (chunk) => write(chunk as string));\n stream.on('end', () => resolve());\n stream.on('error', () => resolve());\n } catch {\n resolve();\n }\n });\n}\n","import type { ChildProcess } from 'node:child_process';\n\n/**\n * Get the sorted list of worker IDs from a map of ChildProcess instances.\n *\n * @param m - Map of worker IDs to ChildProcess instances.\n * @returns Sorted array of worker IDs.\n */\nexport function getWorkerIds(m: Map<number, ChildProcess>): number[] {\n return [...m.keys()].sort((a, b) => a - b);\n}\n\n/**\n * Cycles through an array of numeric IDs, returning the next ID based on a delta.\n *\n * If the `current` ID is not provided or not found in the array, the first ID is used as the starting point.\n * The function then moves forward or backward in the array by `delta` positions, wrapping around if necessary.\n *\n * @param ids - Array of numeric IDs to cycle through.\n * @param current - The current ID to start cycling from. If `null` or not found, starts from the first ID.\n * @param delta - The number of positions to move forward (positive) or backward (negative) in the array.\n * @returns The next ID in the array after cycling, or `null` if the array is empty.\n */\nexport function cycleWorkers(ids: number[], current: number | null, delta: number): number | null {\n if (!ids.length) return null;\n const cur = current == null ? ids[0] : current;\n let i = ids.indexOf(cur);\n if (i === -1) i = 0;\n i = (i + delta + ids.length) % ids.length;\n return ids[i]!;\n}\n","import type { ChildProcess } from 'node:child_process';\nimport * as readline from 'node:readline';\n\nimport type { WorkerLogPaths } from '@transcend-io/utils';\n\nimport { DEBUG } from '../../constants.js';\nimport { keymap } from './keymap.js';\nimport { replayFileTailToStdout } from './replayFileTailToStdout.js';\nimport type { WhichLogs } from './showCombinedLogs.js';\nimport { cycleWorkers, getWorkerIds } from './workerIds.js';\n\n/**\n * Key action types for the interactive switcher\n */\nexport type InteractiveDashboardMode = 'dashboard' | 'attached';\n\nexport interface SwitcherPorts {\n /** Standard input stream */\n stdin: NodeJS.ReadStream;\n /** Standard output stream */\n stdout: NodeJS.WriteStream;\n /** Standard error stream */\n stderr: NodeJS.WriteStream;\n}\n\n/**\n * Install an interactive switcher for managing worker processes.\n *\n * @param opts - Options for the switcher\n * @returns A cleanup function to remove the switcher\n */\nexport function installInteractiveSwitcher(opts: {\n /** Registry of live workers by id */\n workers: Map<number, ChildProcess>;\n /** Hooks */\n onAttach?: (id: number) => void;\n /** Optional detach handler */\n onDetach?: () => void;\n /** Optional Ctrl+C handler for parent graceful shutdown in dashboard */\n onCtrlC?: () => void; // parent graceful shutdown in dashboard\n /** Provide log paths so we can replay the tail on attach */\n getLogPaths?: (id: number) => WorkerLogPaths | undefined;\n /** How many bytes to replay from the end of each file (default 200 KB) */\n replayBytes?: number;\n /** Which logs to replay first (default ['out','err']) */\n replayWhich?: WhichLogs;\n /** Print a small banner/clear screen before replaying (optional) */\n onEnterAttachScreen?: (id: number) => void;\n /** Optional stdio ports for testing; defaults to process stdio */\n ports?: SwitcherPorts;\n}): () => void {\n const {\n workers,\n onAttach,\n onDetach,\n onCtrlC,\n getLogPaths,\n replayBytes = 200 * 1024,\n replayWhich = ['out', 'err'],\n onEnterAttachScreen,\n ports,\n } = opts;\n\n const stdin = ports?.stdin ?? process.stdin;\n const stdout = ports?.stdout ?? process.stdout;\n const stderr = ports?.stderr ?? process.stderr;\n\n const d = (...a: unknown[]): void => {\n if (DEBUG) {\n try {\n (ports?.stderr ?? process.stderr).write(`[keys] ${a.map(String).join(' ')}\\n`);\n } catch {\n // noop\n }\n }\n };\n\n if (!stdin.isTTY) {\n // Not a TTY; return a no-op cleanup\n return () => {\n // noop\n };\n }\n\n readline.emitKeypressEvents(stdin);\n stdin.setRawMode?.(true);\n\n let mode: InteractiveDashboardMode = 'dashboard';\n let focus: number | null = null;\n\n // live mirroring handlers while attached\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let outHandler: ((chunk: any) => void) | null = null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let errHandler: ((chunk: any) => void) | null = null;\n\n /**\n * Cycle through worker IDs, wrapping around.\n *\n * @param id - The current worker ID to start cycling from.\n * @returns The next worker ID after cycling, or null if no workers are available.\n */\n async function replayLogs(id: number): Promise<void> {\n if (!getLogPaths) return;\n const paths = getLogPaths(id);\n if (!paths) return;\n\n const toReplay: string[] = [];\n for (const which of replayWhich) {\n if (which === 'out') toReplay.push(paths.outPath);\n if (which === 'err') toReplay.push(paths.errPath);\n if (which === 'structured') toReplay.push(paths.structuredPath);\n }\n\n if (toReplay.length) {\n stdout.write('\\n------------ replay ------------\\n');\n for (const p of toReplay) {\n stdout.write(`\\n--- ${p} (last ~${Math.floor(replayBytes / 1024)}KB) ---\\n`);\n await replayFileTailToStdout(p, replayBytes, (s) => stdout.write(s));\n }\n stdout.write('\\n--------------------------------\\n\\n');\n }\n }\n\n const attach = async (id: number): Promise<void> => {\n d('attach()', `id=${id}`); // at function entry\n\n const w = workers.get(id);\n if (!w) return;\n\n // Detach any previous focus\n if (mode === 'attached') detach();\n\n mode = 'attached';\n focus = id;\n\n // UX: clear + banner\n onEnterAttachScreen?.(id);\n\n onAttach?.(id); // prints “Attached to worker …” and clears\n await replayLogs(id); // now the tail stays visible\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n outHandler = (chunk: any) => stdout.write(chunk);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n errHandler = (chunk: any) => stderr.write(chunk);\n w.stdout?.on('data', outHandler);\n w.stderr?.on('data', errHandler);\n\n // auto-detach if child exits\n const onExit = (): void => {\n if (focus === id) detach();\n };\n w.once('exit', onExit);\n };\n\n const detach = (): void => {\n d('detach()', `id=${focus}`); // at function entry\n\n if (focus == null) return;\n const id = focus;\n const w = workers.get(id);\n if (w) {\n if (outHandler) w.stdout?.off('data', outHandler);\n if (errHandler) w.stderr?.off('data', errHandler);\n }\n outHandler = null;\n errHandler = null;\n focus = null;\n mode = 'dashboard';\n onDetach?.();\n };\n\n const onKey = (str: string, key: readline.Key): void => {\n d(\n 'keypress',\n JSON.stringify({\n str,\n name: key.name,\n seq: key.sequence,\n ctrl: key.ctrl,\n meta: key.meta,\n shift: key.shift,\n mode,\n }),\n );\n const act = keymap(str, key, mode);\n d('mapped', JSON.stringify(act));\n\n if (!act) return;\n\n // eslint-disable-next-line default-case\n switch (act.type) {\n case 'CTRL_C': {\n d('CTRL_C');\n if (mode === 'attached' && focus != null) {\n const w = workers.get(focus);\n try {\n w?.kill('SIGINT');\n } catch {\n // noop\n }\n // optional: auto-detach so second Ctrl+C exits parent\n detach();\n return;\n }\n onCtrlC?.();\n return;\n }\n\n case 'ATTACH': {\n d('ATTACH', `id=${act.id}`, `has=${workers.has(act.id)}`);\n\n if (mode !== 'dashboard') return;\n // eslint-disable-next-line no-void\n if (workers.has(act.id)) void attach(act.id);\n return;\n }\n\n case 'CYCLE': {\n d('CYCLE', `delta=${act.delta}`);\n if (mode !== 'dashboard') return;\n const next = cycleWorkers(getWorkerIds(workers), focus, act.delta);\n // eslint-disable-next-line no-void\n if (next != null) void attach(next);\n return;\n }\n\n case 'QUIT': {\n if (mode !== 'dashboard') return;\n onCtrlC?.();\n return;\n }\n\n case 'DETACH': {\n d('DETACH');\n if (mode === 'attached') detach();\n return;\n }\n\n case 'CTRL_D': {\n if (mode === 'attached' && focus != null) {\n const w = workers.get(focus);\n try {\n w?.stdin?.end();\n } catch {\n // noop\n }\n }\n return;\n }\n\n case 'FORWARD': {\n if (mode === 'attached' && focus != null) {\n const w = workers.get(focus);\n try {\n w?.stdin?.write(act.sequence);\n } catch {\n // noop\n }\n }\n }\n }\n };\n\n // Raw bytes fallback (usually not hit because keypress handles it)\n const onData = (chunk: Buffer): void => {\n if (mode === 'attached' && focus != null) {\n const w = workers.get(focus);\n try {\n w?.stdin?.write(chunk);\n } catch {\n // noop\n }\n }\n };\n\n const cleanup = (): void => {\n stdin.off('keypress', onKey);\n stdin.off('data', onData);\n stdin.setRawMode?.(false);\n stdout.write('\\x1b[?25h');\n };\n\n stdin.on('keypress', onKey);\n stdin.on('data', onData);\n\n return cleanup;\n}\n","// lib/pooling/dashboardPlugin.ts\nimport * as readline from 'node:readline';\n\nimport type { ObjByString } from '@transcend-io/type-utils';\nimport type { SlotState } from '@transcend-io/utils';\nimport colors from 'colors';\n\n/**\n * A dashboard plugin defines how to render the worker pool UI.\n * Commands can supply a plugin to customize:\n * - The header block (summary stats, title, etc.)\n * - Per-worker rows (one line per worker slot)\n * - Optional extras (artifact exports, breakdowns, footers)\n *\n * @template TTotals - The shape of the aggregate totals object maintained by the command.\n */\nexport interface DashboardPlugin<TTotals, TSlotState extends ObjByString> {\n /**\n * Render the header block of the dashboard.\n *\n * @param ctx - Context with pool/worker state, totals, and metadata.\n * @returns An array of strings, each representing one line in the header.\n */\n renderHeader: (ctx: CommonCtx<TTotals, TSlotState>) => string[];\n\n /**\n * Render per-worker rows, usually one line per worker slot.\n *\n * @param ctx - Context with pool/worker state, totals, and metadata.\n * @returns An array of strings, each representing one row in the workers section.\n */\n renderWorkers: (ctx: CommonCtx<TTotals, TSlotState>) => string[];\n\n /**\n * Render any optional extra blocks that appear after the worker rows.\n * Useful for printing export paths, aggregated metrics, breakdowns, etc.\n *\n * @param ctx - Context with pool/worker state, totals, and metadata.\n * @returns An array of strings, each representing one additional line.\n */\n renderExtras?: (ctx: CommonCtx<TTotals, TSlotState>) => string[];\n}\n\n/**\n * Shared context object passed into all render methods of a {@link DashboardPlugin}.\n *\n * @template TTotals - The shape of the aggregate totals object maintained by the command.\n */\nexport type CommonCtx<TTotals, TSlotState extends ObjByString> = {\n /** Human-readable title for the dashboard (e.g., \"Parallel uploader\"). */\n title: string;\n\n /** Number of worker processes spawned in the pool. */\n poolSize: number;\n\n /** Logical CPU count, included for informational display. */\n cpuCount: number;\n\n /** Total number of \"files\" or logical units the command expects to process. */\n filesTotal: number;\n\n /** Count of successfully completed files/tasks. */\n filesCompleted: number;\n\n /** Count of failed files/tasks. */\n filesFailed: number;\n\n /**\n * State of each worker slot, keyed by worker id.\n * Includes busy flag, file label, start time, last log badge, and progress.\n */\n workerState: Map<number, SlotState<TSlotState>>;\n\n /**\n * Aggregate totals maintained by the command’s hook logic.\n * Domain-specific metrics (e.g., rows uploaded, bytes processed) can be surfaced here.\n */\n totals: TTotals;\n\n /**\n * Throughput metrics tracked by the runner:\n * - successSoFar: convenience alias for completed count\n * - r10s: completions/sec averaged over last 10s\n * - r60s: completions/sec averaged over last 60s\n */\n throughput: {\n /** Cumulative count of successful completions so far. */\n successSoFar: number;\n /** Recent file-level throughput rate over the last 10 seconds. */\n r10s: number;\n /** Recent file-level throughput rate over the last 60 seconds. */\n r60s: number;\n /** Recent job/record-level throughput rate over the last 10 seconds. */\n jobsR10s: number;\n /** Recent job/record-level throughput rate over the last 60 seconds. */\n jobsR60s: number;\n };\n\n /** True when the pool has fully drained and all workers have exited. */\n final: boolean;\n\n /**\n * Optional export status payload provided by the command.\n * Useful for rendering artifact paths or \"latest export\" summaries.\n */\n exportStatus?: Record<string, unknown>;\n};\n\n/** The most recently rendered frame, cached to suppress flicker from duplicate renders. */\nlet lastFrame = '';\n\n/**\n * Generate the hotkeys hint string that appears at the bottom of the dashboard.\n *\n * @param poolSize - The number of worker slots in the pool.\n * @param final - Whether the run has completed.\n * @returns A dimmed string listing the supported hotkeys for attach/detach/quit.\n */\nexport const hotkeysHint = (poolSize: number, final: boolean): string => {\n const maxDigit = Math.min(poolSize - 1, 9);\n const digitRange = poolSize <= 1 ? '0' : `0-${maxDigit}`;\n const extra = poolSize > 10 ? ' (Tab/Shift+Tab for ≥10)' : '';\n return final\n ? colors.dim(\n 'Run complete — digits to view logs • Tab/Shift+Tab cycle • Esc/Ctrl+] detach • q to quit',\n )\n : colors.dim(\n `Hotkeys: [${digitRange}] attach${extra} • e=errors • w=warnings • i=info • l=logs • ` +\n 'Tab/Shift+Tab • Esc/Ctrl+] detach • Ctrl+C exit',\n );\n};\n\n/**\n * Render the dashboard using a supplied {@link DashboardPlugin}.\n *\n * The frame is composed of:\n * - Header lines\n * - A blank separator\n * - Worker rows\n * - A blank separator\n * - Hotkeys hint\n * - Optional extras (if plugin supplies them)\n *\n * Optimizations:\n * - Suppresses re-renders if the frame is identical to the previous frame (flicker-free).\n * - Hides the terminal cursor during live updates, restoring it when final.\n *\n * @param ctx - Shared context containing pool state, worker state, totals, throughput, etc.\n * @param plugin - The plugin that defines how to render the header, workers, and optional extras.\n * @param viewerMode - If true, renders in viewer mode (no ability to switch between files).\n */\nexport function dashboardPlugin<TTotals, TSlotState extends ObjByString>(\n ctx: CommonCtx<TTotals, TSlotState>,\n plugin: DashboardPlugin<TTotals, TSlotState>,\n viewerMode = false,\n): void {\n const frame = [\n ...plugin.renderHeader(ctx),\n '',\n ...plugin.renderWorkers(ctx),\n ...(viewerMode ? [] : ['', hotkeysHint(ctx.poolSize, ctx.final)]),\n ...(plugin.renderExtras ? [''].concat(plugin.renderExtras(ctx)) : []),\n ].join('\\n');\n\n // Skip duplicate renders during live runs to avoid flicker.\n if (!ctx.final && frame === lastFrame) return;\n lastFrame = frame;\n\n if (!ctx.final) {\n // Hide cursor and repaint in place\n process.stdout.write('\\x1b[?25l');\n readline.cursorTo(process.stdout, 0, 0);\n readline.clearScreenDown(process.stdout);\n } else {\n // Restore cursor on final render\n process.stdout.write('\\x1b[?25h');\n }\n process.stdout.write(`${frame}\\n`);\n}\n","import { basename } from 'node:path';\n\nimport type { ObjByString } from '@transcend-io/type-utils';\nimport colors from 'colors';\n\nimport type { CommonCtx } from './dashboardPlugin.js';\n\n/**\n * Progress snapshot for a worker slot in the chunk-csv command.\n */\nexport type ChunkSlotProgress = {\n /** Absolute path of the file being processed by this worker. */\n filePath?: string;\n /** Number of rows processed so far in this file. */\n processed?: number;\n /** Optional total number of rows in the file (if known). */\n total?: number;\n};\n\n/**\n * Format a number safely for display.\n *\n * @param n - The number to format (or `undefined`).\n * @returns A localized string representation, or \"0\".\n */\nexport function fmtNum(n: number | undefined): string {\n return typeof n === 'number' ? n.toLocaleString() : '0';\n}\n\n/**\n * Draw a horizontal bar of length `width` filled to `pct` percent.\n *\n * @param pct - Percentage 0..100.\n * @param width - Number of characters in the bar.\n * @returns A string like \"████░░░░\".\n */\nexport function pctBar(pct: number, width = 40): string {\n const clamped = Math.max(0, Math.min(100, Math.floor(pct)));\n const filled = Math.floor((clamped / 100) * width);\n return '█'.repeat(filled) + '░'.repeat(width - filled);\n}\n\n/**\n * Compute pool-wide progress values needed by headers.\n *\n * @param ctx - Dashboard context containing pool state, worker state, totals, etc.\n * @returns An object with `done`, `inProgress`, and `pct` properties.\n */\nexport function poolProgress<TTotals, TSlot extends ObjByString>(\n ctx: CommonCtx<TTotals, TSlot>,\n): {\n /** Count of successfully completed files/tasks. */\n done: number;\n /** Count of currently in-progress files/tasks. */\n inProgress: number;\n /** Percentage of completion (0-100). */\n pct: number;\n} {\n const inProgress = [...ctx.workerState.values()].filter((s) => s.busy).length;\n const done = ctx.filesCompleted + ctx.filesFailed;\n const pct = ctx.filesTotal === 0 ? 100 : Math.floor((done / Math.max(1, ctx.filesTotal)) * 100);\n return { done, inProgress, pct };\n}\n\n/**\n * Compose the common header lines (title, pool stats, progress bar, throughput).\n *\n * @param ctx - Dashboard context.\n * @param extraLines - Optional extra lines (e.g., totals block).\n * @returns Header lines.\n */\nexport function makeHeader<TTotals, TSlot extends ObjByString>(\n ctx: CommonCtx<TTotals, TSlot>,\n extraLines: string[] = [],\n): string[] {\n const { title, poolSize, cpuCount, filesTotal, filesCompleted, filesFailed, throughput } = ctx;\n const { inProgress, pct } = poolProgress(ctx);\n\n const lines: string[] = [\n `${colors.bold(title)} — ${poolSize} workers ${colors.dim(`(CPU avail: ${cpuCount})`)}`,\n `${colors.dim('Files')} ${fmtNum(filesTotal)} ${colors.dim(\n 'Completed',\n )} ${fmtNum(filesCompleted)} ${colors.dim('Failed')} ${\n filesFailed ? colors.red(fmtNum(filesFailed)) : fmtNum(filesFailed)\n } ${colors.dim('In-flight')} ${fmtNum(inProgress)}`,\n `[${pctBar(pct)}] ${pct}%`,\n ];\n\n if (throughput) {\n const jobsActive = throughput.jobsR10s > 0 || throughput.jobsR60s > 0;\n const perHour10 = Math.round(\n (jobsActive ? throughput.jobsR10s : throughput.r10s) * 3600,\n ).toLocaleString();\n const perHour60 = Math.round(\n (jobsActive ? throughput.jobsR60s : throughput.r60s) * 3600,\n ).toLocaleString();\n const unit = jobsActive ? 'rec' : 'files';\n const suffix =\n ctx.throughput?.successSoFar != null\n ? ` Newly uploaded: ${fmtNum(ctx.throughput.successSoFar)}`\n : '';\n lines.push(\n colors.cyan(`Throughput: ${perHour10} ${unit}/hr (1h: ${perHour60} ${unit}/hr)${suffix}`),\n );\n }\n\n return extraLines.length ? lines.concat(extraLines) : lines;\n}\n\n/**\n * Render per-worker rows with a compact progress bar and status badge.\n *\n * @param ctx - Dashboard context (slot progress type must have processed/total?).\n * @param getFileLabel - Optional: override how the filename is shown.\n * @returns Array of strings, each representing one worker row.\n */\nexport function makeWorkerRows<TTotals, TSlot extends Omit<ChunkSlotProgress, 'filePath'>>(\n ctx: CommonCtx<TTotals, TSlot>,\n getFileLabel: (file: string | null | undefined) => string = (file) =>\n file ? basename(file) : '-',\n): string[] {\n const miniWidth = 18;\n\n return [...ctx.workerState.entries()].map(([id, s]) => {\n const badge =\n s.lastLevel === 'error'\n ? colors.red('ERROR ')\n : s.lastLevel === 'warn'\n ? colors.yellow('WARN ')\n : s.busy\n ? colors.green('WORKING')\n : colors.dim('IDLE ');\n\n const fname = getFileLabel(s.file);\n const elapsed = s.startedAt ? `${Math.floor((Date.now() - s.startedAt) / 1000)}s` : '-';\n\n const processed = s.progress?.processed ?? 0;\n const total = s.progress?.total ?? 0;\n const pctw = total > 0 ? Math.floor((processed / total) * 100) : 0;\n const mini = total > 0 ? pctBar(pctw, miniWidth) : ' '.repeat(miniWidth);\n const miniTxt =\n total > 0\n ? `${processed.toLocaleString()}/${total.toLocaleString()} (${pctw}%)`\n : colors.dim('—');\n\n return ` [w${id}] ${badge} | ${fname} | ${elapsed} | [${mini}] ${miniTxt}`;\n });\n}\n","import type { ExportStatusMap, SlotPaths } from '@transcend-io/utils';\n\nimport { showCombinedLogs, type LogLocation } from './showCombinedLogs.js';\n\n/** Severity filter applied by the viewer. */\ntype ViewLevel = 'error' | 'warn' | 'all';\n\n/**\n * Options for {@link createExtraKeyHandler}.\n */\nexport type CreateExtraKeyHandlerOpts = {\n /**\n * Per-slot log file paths maintained by the runner; used to stream or export logs.\n */\n logsBySlot: SlotPaths;\n\n /**\n * Request an immediate dashboard repaint (e.g., after updating export status).\n */\n repaint: () => void;\n\n /**\n * Pause/unpause dashboard repainting. The handler pauses while a viewer is open\n * to prevent the dashboard from overwriting the viewer output, then resumes on exit.\n */\n setPaused: (p: boolean) => void;\n\n /**\n * Optional export manager to enable uppercase export keys:\n * - `E` (errors) • `W` (warnings) • `I` (info) • `A` (all)\n *\n * Provide this only if your command supports writing combined log files.\n */\n exportMgr?: {\n /** Destination directory for exported artifacts. */\n exportsDir: string;\n /**\n * Write a combined log file for the selected severity and return the absolute path.\n *\n * @param logs - Log paths to combine.\n * @param which - Severity selection.\n * @returns Absolute path to the written file.\n */\n exportCombinedLogs: (logs: SlotPaths, which: 'error' | 'warn' | 'info' | 'all') => string;\n };\n\n /**\n * Optional “Exports” status map. If provided, the handler updates timestamps\n * when exports are written so your dashboard panel can reflect “last saved” times.\n */\n exportStatus?: ExportStatusMap;\n\n /**\n * Optional custom key bindings for command-specific actions.\n * Each handler receives helpers to print messages and to update the exports panel.\n *\n * Example:\n * ```ts\n * custom: {\n * F: async ({ say, noteExport }) => {\n * const p = await writeFailingUpdatesCsv(...);\n * say(`Wrote failing updates to: ${p}`);\n * noteExport('failuresCsv', p);\n * }\n * }\n * ```\n */\n custom?: Record<\n string,\n (ctx: {\n /** Update {@link exportStatus} (if present) and repaint the dashboard. */\n noteExport: (slot: keyof ExportStatusMap, absPath: string) => void;\n /** Print a line to stdout, automatically newline-terminated. */\n say: (s: string) => void;\n }) => void | Promise<void>\n >;\n};\n\n/**\n * Create a keypress handler for interactive viewers/exports.\n * Shared handler for \"extra\" keyboard shortcuts used by the interactive dashboard.\n *\n * It wires:\n * - **Viewers (lowercase):** `e` (errors), `w` (warnings), `i` (info), `l` (all)\n * - **Exports (uppercase, optional):** `E` (errors), `W` (warnings), `I` (info), `A` (all)\n * - **Dismiss:** `Esc` or `Ctrl+]` exits a viewer and returns to the dashboard\n * - **Custom keys (optional):** Provide a `custom` map to handle command-specific bindings\n *\n * Usage (inside `runPool({... extraKeyHandler })`):\n * ```ts\n * extraKeyHandler: ({ logsBySlot, repaint, setPaused }) =>\n * createExtraKeyHandler({ logsBySlot, repaint, setPaused })\n * ```\n *\n * If you also want export hotkeys + an \"Exports\" panel:\n * ```ts\n * extraKeyHandler: ({ logsBySlot, repaint, setPaused }) =>\n * createExtraKeyHandler({\n * logsBySlot, repaint, setPaused,\n * exportMgr, // enables E/W/I/A\n * exportStatus, // keeps panel timestamps up to date\n * custom: { // optional, e.g. 'F' to export a CSV\n * F: async ({ say, noteExport }) => { ... }\n * }\n * })\n * ```\n *\n * @param opts - Configuration for viewers, exports, and custom keys.\n * @returns A `(buf: Buffer) => void` handler suitable for `process.stdin.on('data', ...)`.\n */\nexport function createExtraKeyHandler(opts: CreateExtraKeyHandlerOpts): (buf: Buffer) => void {\n const { logsBySlot, repaint, setPaused, exportMgr, exportStatus, custom } = opts;\n\n const say = (s: string): void => {\n process.stdout.write(`${s}\\n`);\n };\n\n /**\n * Record that an export was written and trigger a repaint so the dashboard’s\n * \"Exports\" panel shows the updated timestamp/path.\n *\n * @param slot - Slot name in {@link ExportStatusMap} (e.g., \"error\", \"warn\", etc.).\n * @param p - Absolute path to the exported file.\n */\n const noteExport = (slot: keyof ExportStatusMap, p: string): void => {\n const now = Date.now();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const cur: any = exportStatus?.[slot] ?? { path: p };\n if (exportStatus) {\n exportStatus[slot] = {\n path: p || cur.path,\n savedAt: now,\n exported: true,\n };\n repaint();\n }\n };\n\n let viewing = false; // optional guard to prevent stacking viewers\n\n /**\n * Show an inline combined log viewer for the selected sources/level.\n * Pauses dashboard repaint to keep the viewer visible until the user exits.\n *\n * @param sources - Log sources to include (e.g., \"err\", \"warn\", \"info\").\n * @param level - Severity level to filter by (e.g., \"error\", \"warn\", \"all\").\n */\n const view = (sources: LogLocation[], level: ViewLevel): void => {\n if (viewing) return;\n viewing = true;\n setPaused(true);\n\n // optional UX: clear screen and show a hint\n process.stdout.write('\\x1b[2J\\x1b[H'); // clear+home\n process.stdout.write('Combined logs viewer (press Esc or Ctrl+] to return)\\n\\n');\n\n (async () => {\n try {\n await showCombinedLogs(logsBySlot, sources, level);\n // NOTE: do NOT unpause here; ESC will handle it.\n } catch {\n // If showCombinedLogs throws, recover and unpause\n viewing = false;\n setPaused(false);\n repaint();\n }\n })();\n };\n\n /**\n * Export combined logs (if an export manager was provided).\n *\n * @param which - Severity to export (e.g., \"error\", \"warn\", \"info\", \"all\").\n * @param label - Human-readable label for the export (e.g., \"error\", \"warn\").\n */\n const exportCombined = (which: 'error' | 'warn' | 'info' | 'all', label: string): void => {\n if (!exportMgr) return;\n try {\n const p = exportMgr.exportCombinedLogs(logsBySlot, which);\n say(`\\nWrote combined ${label} logs to: ${p}`);\n noteExport(which as keyof ExportStatusMap, p);\n } catch {\n say(`\\nFailed to write combined ${label} logs`);\n }\n };\n\n // The keypress handler the runner will attach to stdin.\n return (buf: Buffer): void => {\n const s = buf.toString('utf8');\n\n // Viewers (lowercase)\n if (s === 'e') {\n view(['err'], 'error');\n return;\n }\n if (s === 'w') {\n view(['warn', 'err'], 'warn');\n return;\n }\n if (s === 'i') {\n view(['info'], 'all');\n return;\n }\n if (s === 'l') {\n view(['out', 'err', 'structured'], 'all');\n return;\n }\n\n // Exports (uppercase) — enabled only when exportMgr is present\n if (s === 'E') {\n exportCombined('error', 'error');\n return;\n }\n if (s === 'W') {\n exportCombined('warn', 'warn');\n return;\n }\n if (s === 'I') {\n exportCombined('info', 'info');\n return;\n }\n if (s === 'A') {\n exportCombined('all', 'ALL');\n return;\n }\n\n // Command-specific bindings\n const fn = custom?.[s];\n if (fn) {\n fn({ noteExport, say });\n return;\n }\n\n // Exit a viewer (Esc / Ctrl+]) — resume dashboard\n if (s === '\\x1b' || s === '\\x1d') {\n viewing = false;\n setPaused(false);\n repaint();\n }\n };\n}\n"],"mappings":"mNAuBA,SAAgB,EACd,EACA,EACA,EACM,CACN,QAAQ,OAAO,MAAM,gBAAgB,CAErC,IAAM,EAAW,GACf,oDAAoD,KAAK,EAAE,CACvD,EAAa,GAAuB,sBAAsB,KAAK,EAAE,CAEjE,EAAkB,EAAE,CAE1B,IAAK,GAAM,EAAG,KAAU,EAAc,CACpC,GAAI,CAAC,EAAO,SAEZ,IAAM,EAKD,EAAE,CACP,IAAK,IAAM,KAAS,EACd,IAAU,OAAS,EAAM,SAC3B,EAAM,KAAK,CAAE,KAAM,EAAM,QAAS,IAAK,MAAO,CAAC,CAE7C,IAAU,OAAS,EAAM,SAC3B,EAAM,KAAK,CAAE,KAAM,EAAM,QAAS,IAAK,MAAO,CAAC,CAE7C,IAAU,cAAgB,EAAM,gBAClC,EAAM,KAAK,CAAE,KAAM,EAAM,eAAgB,IAAK,aAAc,CAAC,CAE3D,EAAM,UAAY,IAAU,QAC9B,EAAM,KAAK,CAAE,KAAM,EAAM,SAAU,IAAK,OAAQ,CAAC,CAE/C,EAAM,UAAY,IAAU,QAC9B,EAAM,KAAK,CAAE,KAAM,EAAM,SAAU,IAAK,OAAQ,CAAC,CAIrD,IAAK,GAAM,CAAE,OAAM,SAAS,EAAO,CACjC,IAAI,EAAO,GACX,GAAI,CACF,EAAO,EAAa,EAAM,OAAO,MAC3B,CACN,SAGF,IAAK,IAAM,KAAM,EAAK,MAAM;EAAK,CAAE,CACjC,GAAI,CAAC,EAAI,SAET,IAAM,EAAQ,EAAG,QAAQ,kBAAmB,GAAG,CAE/C,GAAI,IAAgB,MAAO,CACzB,EA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
import{a as e}from"./constants-
|
|
2
|
-
//# sourceMappingURL=downloadPrivacyRequestFiles-
|
|
1
|
+
import{a as e}from"./constants-B7bW_WN2.mjs";import{t}from"./logger-D1tXVwJj.mjs";import{t as n}from"./request-CdglUNWv.mjs";import{r}from"./fetchAllRequests-rDVYKbqL.mjs";import{RequestAction as i,RequestStatus as a,TableEncryptionType as o}from"@transcend-io/privacy-types";import{decodeCodec as s,valuesOf as c}from"@transcend-io/type-utils";import{existsSync as l,mkdirSync as u,writeFileSync as d}from"node:fs";import{dirname as f,join as p}from"node:path";import m from"colors";import*as h from"io-ts";import{buildTranscendGraphQLClient as g,createSombraGotInstance as _,makeGraphQLRequest as v}from"@transcend-io/sdk";import{map as y}from"@transcend-io/utils";import b from"cli-progress";const x=h.type({defaultMessage:h.string,id:h.string}),S=h.type({downloadKey:h.string,error:h.union([h.null,h.string]),mimetype:h.string,size:h.string,fileName:h.string,dataPoint:h.type({id:h.string,title:h.union([x,h.null]),description:h.union([x,h.null]),name:h.string,slug:h.string,encryption:h.union([c(o),h.null]),dataSilo:h.type({id:h.string,title:h.string,description:h.string,type:h.string,outerType:h.union([h.string,h.null])}),path:h.array(h.string)})}),C=h.type({nodes:h.array(S),totalCount:h.number,_links:h.partial({next:h.union([h.string,h.null]),previous:h.union([h.string,h.null])})});async function w(e,{sombra:n,concurrency:r=5,limit:i=100}){t.info(m.magenta(`Pulling file metadata for ${e.length} requests`));let a=new Date().getTime(),o=new b.SingleBar({},b.Presets.shades_classic),c=0;o.start(e.length,0);let l=await y(e,async e=>{let t=[],r=!0,a=0;for(;r;){let o;try{o=s(C,await n.get(`v1/data-subject-request/${e.id}/download-keys`,{searchParams:{limit:i,offset:a}}).json()),t.push(...o.nodes),a+=i,r=!!o._links.next&&o.nodes.length===i}catch(e){throw Error(`Received an error from server: ${e?.response?.body||e?.message}`)}}return c+=1,o.update(c),[e,t]},{concurrency:r});o.stop();let u=new Date().getTime()-a;return t.info(m.green(`Successfully downloaded file metadata ${e.length} requests in "${u/1e3}" seconds!`)),l}async function T(e,{requestId:n,sombra:r,onFileDownloaded:i,concurrency:a=20}){await y(e,async e=>{try{await r.get(`v1/files`,{searchParams:{downloadKey:e.downloadKey}}).buffer().then(t=>i(e,t))}catch(r){if(r?.response?.body?.includes(`fileMetadata#verify`)){t.error(m.red(`Failed to pull file for: ${e.fileName} (request:${n}) - JWT expired. This likely means that the file is no longer available. Try restarting the request from scratch in Transcend Admin Dashboard. Skipping the download of this file.`));return}throw Error(`Received an error from server: ${r?.response?.body||r?.message}`)}},{concurrency:a})}async function E({auth:o,folderPath:s,requestIds:c,createdAtBefore:h,sombraAuth:x,createdAtAfter:S,updatedAtBefore:C,updatedAtAfter:E,statuses:D=[a.Approving,a.Downloadable],concurrency:O=5,transcendUrl:k=e,approveAfterDownload:A=!1}){let j=g(k,o),M=await _(k,o,{logger:t,sombraApiKey:x,sombraUrl:process.env.SOMBRA_URL});l(s)||u(s);let N=await r(j,{actions:[i.Access],createdAtBefore:h,createdAtAfter:S,updatedAtBefore:C,updatedAtAfter:E,statuses:D,requestIds:c}),P=await w(N,{sombra:M,concurrency:O}),F=new Date().getTime(),I=new b.SingleBar({},b.Presets.shades_classic),L=0,R=0;I.start(N.length,0),await y(P,async([e,r])=>{let i=p(s,e.id);l(i)||u(i),await T(r,{sombra:M,requestId:e.id,onFileDownloaded:(e,t)=>{let n=p(i,e.fileName),r=f(n);l(r)||u(r,{recursive:!0}),d(n,t)}}),A&&e.status===a.Approving&&(await v(j,n,{variables:{input:{requestId:e.id}},logger:t}),R+=1),L+=1,I.update(L)},{concurrency:O}),I.stop();let z=new Date().getTime()-F;return t.info(m.green(`Successfully downloaded ${L} requests in "${z/1e3}" seconds!`)),R>0&&t.info(m.green(`Approved ${R} requests in Transcend.`)),N.length}export{C as a,S as i,T as n,w as o,x as r,E as t};
|
|
2
|
+
//# sourceMappingURL=downloadPrivacyRequestFiles-B7HNc-Y1.mjs.map
|