{"version":3,"file":"impl-BuMucaCY2.mjs","names":[],"sources":["../src/commands/request/cron/pull-identifiers/impl.ts"],"sourcesContent":["import { RequestAction } from '@transcend-io/privacy-types';\nimport colors from 'colors';\nimport { uniq } from 'lodash-es';\n\nimport type { LocalContext } from '../../../../context.js';\nimport { doneInputValidation } from '../../../../lib/cli/done-input-validation.js';\nimport {\n  CsvFormattedIdentifier,\n  pullChunkedCustomSiloOutstandingIdentifiers,\n} from '../../../../lib/cron/index.js';\nimport { parseFilePath, writeLargeCsv } from '../../../../lib/helpers/index.js';\nimport { logger } from '../../../../logger.js';\n\nexport interface PullIdentifiersCommandFlags {\n  file: string;\n  transcendUrl: string;\n  auth: string;\n  sombraAuth?: string;\n  dataSiloId: string;\n  actions: RequestAction[];\n  pageLimit: number;\n  skipRequestCount: boolean;\n  chunkSize: number;\n}\n\nexport async function pullIdentifiers(\n  this: LocalContext,\n  {\n    file,\n    transcendUrl,\n    auth,\n    sombraAuth,\n    dataSiloId,\n    actions,\n    pageLimit,\n    skipRequestCount,\n    chunkSize,\n  }: PullIdentifiersCommandFlags,\n): Promise<void> {\n  if (skipRequestCount) {\n    logger.info(\n      colors.yellow('Skipping request count as requested. This may help speed up the call.'),\n    );\n  }\n\n  if (Number.isNaN(chunkSize) || chunkSize <= 0 || chunkSize % pageLimit !== 0) {\n    logger.error(\n      colors.red(\n        `Invalid chunk size: \"${chunkSize}\". Must be a positive integer that is a multiple of ${pageLimit}.`,\n      ),\n    );\n    this.process.exit(1);\n  }\n\n  doneInputValidation(this.process.exit);\n\n  const { baseName, extension } = parseFilePath(file);\n  let fileCount = 0;\n\n  const onSave = async (chunk: CsvFormattedIdentifier[]): Promise<void> => {\n    const numberedFileName = `${baseName}-${fileCount}${extension}`;\n    logger.info(colors.blue(`Saving ${chunk.length} identifiers to file \"${numberedFileName}\"`));\n\n    const headers = uniq(chunk.map((d) => Object.keys(d)).flat());\n    await writeLargeCsv(numberedFileName, chunk, headers);\n    logger.info(\n      colors.green(`Successfully wrote ${chunk.length} identifiers to file \"${numberedFileName}\"`),\n    );\n    fileCount += 1;\n    return Promise.resolve();\n  };\n\n  // Pull down outstanding identifiers\n  await pullChunkedCustomSiloOutstandingIdentifiers({\n    transcendUrl,\n    apiPageSize: pageLimit,\n    savePageSize: chunkSize,\n    onSave,\n    actions,\n    auth,\n    sombraAuth,\n    dataSiloId,\n    skipRequestCount,\n  });\n}\n"],"mappings":"uRAyBA,eAAsB,EAEpB,CACE,OACA,eACA,OACA,aACA,aACA,UACA,YACA,mBACA,aAEa,CACX,GACF,EAAO,KACL,EAAO,OAAO,wEAAwE,CACvF,EAGC,OAAO,MAAM,EAAU,EAAI,GAAa,GAAK,EAAY,IAAc,KACzE,EAAO,MACL,EAAO,IACL,wBAAwB,EAAU,sDAAsD,EAAU,GACnG,CACF,CACD,KAAK,QAAQ,KAAK,EAAE,EAGtB,EAAoB,KAAK,QAAQ,KAAK,CAEtC,GAAM,CAAE,WAAU,aAAc,EAAc,EAAK,CAC/C,EAAY,EAgBhB,MAAM,EAA4C,CAChD,eACA,YAAa,EACb,aAAc,EACd,YAlBoB,IAAmD,CACvE,IAAM,EAAmB,GAAG,EAAS,GAAG,IAAY,IASpD,OARA,EAAO,KAAK,EAAO,KAAK,UAAU,EAAM,OAAO,wBAAwB,EAAiB,GAAG,CAAC,CAG5F,MAAM,EAAc,EAAkB,EADtB,EAAK,EAAM,IAAK,GAAM,OAAO,KAAK,EAAE,CAAC,CAAC,MAAM,CACR,CAAC,CACrD,EAAO,KACL,EAAO,MAAM,sBAAsB,EAAM,OAAO,wBAAwB,EAAiB,GAAG,CAC7F,CACD,GAAa,EACN,QAAQ,SAAS,EASxB,UACA,OACA,aACA,aACA,mBACD,CAAC"}