{"version":3,"file":"impl-DLWhxaMi.mjs","names":[],"sources":["../src/commands/policy/bundles/impl.ts"],"sourcesContent":["import colors from 'colors';\n\nimport type { LocalContext } from '../../../context.js';\nimport { doneInputValidation } from '../../../lib/cli/done-input-validation.js';\nimport { logger } from '../../../logger.js';\nimport { EMPTY_CELL } from '../constants.js';\nimport {\n  buildPolicyEngineClient,\n  policyEngineRequest,\n  printResult,\n  renderTable,\n  setPolicyEngineCliDebug,\n} from '../helpers/index.js';\nimport type { PolicyBundleListResponse } from '../types.js';\n\n/** CLI flags for `transcend policy bundles`. */\nexport interface BundlesCommandFlags {\n  /** Transcend API key */\n  auth: string;\n  /** Transcend API URL */\n  'transcend-url': string;\n  /** Page size */\n  limit: number;\n  /** Number of records to skip */\n  offset: number;\n  /** Print raw JSON response */\n  json: boolean;\n  /** Include technical error details when a command fails */\n  debug?: boolean;\n}\n\n/**\n * List policy bundles for the current organization.\n *\n * @param this - CLI context\n * @param flags - Command flags\n */\nexport async function bundles(\n  this: LocalContext,\n  { auth, 'transcend-url': transcendUrl, limit, offset, json, debug = false }: BundlesCommandFlags,\n): Promise<void> {\n  doneInputValidation(this.process.exit);\n  setPolicyEngineCliDebug(debug);\n\n  const client = buildPolicyEngineClient(transcendUrl, auth);\n\n  logger.info(colors.green('Listing policy bundles...'));\n\n  const body = await policyEngineRequest(\n    client\n      .get('v1/policy-engine/policy-bundles', {\n        searchParams: { limit, offset },\n      })\n      .json<PolicyBundleListResponse>(),\n  );\n\n  printResult(this.process.stdout, {\n    json,\n    data: body,\n    renderTable: () => {\n      if (body.nodes.length === 0) {\n        return 'No policy bundles found.';\n      }\n\n      const rows = body.nodes.map((bundle) => [\n        bundle.id,\n        bundle.bundleName,\n        bundle.activeVersionId ?? EMPTY_CELL,\n        bundle.lastActivatedAt ?? EMPTY_CELL,\n        bundle.createdAt,\n      ]);\n\n      let table = renderTable(\n        ['id', 'bundleName', 'activeVersionId', 'lastActivatedAt', 'createdAt'],\n        rows,\n      );\n      table += `\\n\\ntotalCount: ${body.totalCount}`;\n      if (offset + body.nodes.length < body.totalCount) {\n        table += `\\nnextOffset: ${offset + body.nodes.length}`;\n      }\n      return table;\n    },\n  });\n}\n"],"mappings":"wRAqCA,eAAsB,EAEpB,CAAE,OAAM,gBAAiB,EAAc,QAAO,SAAQ,OAAM,QAAQ,IACrD,CACf,EAAoB,KAAK,QAAQ,KAAK,CACtC,EAAwB,EAAM,CAE9B,IAAM,EAAS,EAAwB,EAAc,EAAK,CAE1D,EAAO,KAAK,EAAO,MAAM,4BAA4B,CAAC,CAEtD,IAAM,EAAO,MAAM,EACjB,EACG,IAAI,kCAAmC,CACtC,aAAc,CAAE,QAAO,SAAQ,CAChC,CAAC,CACD,MAAgC,CACpC,CAED,EAAY,KAAK,QAAQ,OAAQ,CAC/B,OACA,KAAM,EACN,gBAAmB,CACjB,GAAI,EAAK,MAAM,SAAW,EACxB,MAAO,2BAWT,IAAI,EAAQ,EACV,CAAC,KAAM,aAAc,kBAAmB,kBAAmB,YAAY,CAT5D,EAAK,MAAM,IAAK,GAAW,CACtC,EAAO,GACP,EAAO,WACP,EAAO,iBAAA,IACP,EAAO,iBAAA,IACP,EAAO,UACR,CAIK,CACL,CAKD,MAJA,IAAS,mBAAmB,EAAK,aAC7B,EAAS,EAAK,MAAM,OAAS,EAAK,aACpC,GAAS,iBAAiB,EAAS,EAAK,MAAM,UAEzC,GAEV,CAAC"}