{"version":3,"file":"impl-Chska4J8.mjs","names":[],"sources":["../src/commands/policy/activate/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 {\n  buildPolicyEngineClient,\n  formatPolicyBundleVersionSummary,\n  policyEngineRequest,\n  PolicyEngineCliError,\n  printResult,\n  resolveBundleIdByName,\n  resolvePolicyBundleVersion,\n  setPolicyEngineCliDebug,\n} from '../helpers/index.js';\nimport type { ActivatePolicyBundleVersionResponse } from '../types.js';\n\n/** CLI flags for `transcend policy activate`. */\nexport interface ActivateCommandFlags {\n  /** Logical bundle name to activate */\n  'bundle-name': string;\n  /** Caller-supplied version label to activate */\n  version?: string;\n  /** Transcend API key */\n  auth: string;\n  /** Transcend API URL */\n  'transcend-url': string;\n  /** Validate activation without flipping */\n  'dry-run': boolean;\n  /** Print raw JSON response */\n  json: boolean;\n  /** Include technical error details when a command fails */\n  debug?: boolean;\n}\n\n/**\n * Activate an uploaded policy bundle version.\n *\n * Resolves `--bundle-name` to the parent bundle UUID internally, then calls the\n * Policy Engine activate endpoint. The bundle is addressed by name only -- the\n * UUID is never exposed to the operator.\n *\n * @param this - CLI context\n * @param flags - Command flags\n */\nexport async function activate(\n  this: LocalContext,\n  {\n    'bundle-name': bundleName,\n    version,\n    auth,\n    'transcend-url': transcendUrl,\n    'dry-run': dryRun,\n    json,\n    debug = false,\n  }: ActivateCommandFlags,\n): Promise<void> {\n  doneInputValidation(this.process.exit);\n  setPolicyEngineCliDebug(debug);\n\n  const client = buildPolicyEngineClient(transcendUrl, auth);\n  const resolvedBundleId = await resolveBundleIdByName(client, bundleName);\n  if (!resolvedBundleId) {\n    throw new Error(`Policy bundle \"${bundleName}\" was not found for this organization.`);\n  }\n  const resolvedVersion = await resolvePolicyBundleVersion(client, resolvedBundleId, { version });\n\n  logger.info(\n    colors.green(\n      dryRun\n        ? `Validating activation for version \"${resolvedVersion.version}\"...`\n        : `Activating version \"${resolvedVersion.version}\"...`,\n    ),\n  );\n\n  let body: ActivatePolicyBundleVersionResponse;\n  try {\n    body = await policyEngineRequest(\n      client\n        .post(\n          `v1/policy-engine/policy-bundles/${resolvedBundleId}/versions/${resolvedVersion.id}/activate`,\n          {\n            json: dryRun ? { dryRun: true } : {},\n          },\n        )\n        .json<ActivatePolicyBundleVersionResponse>(),\n    );\n  } catch (err) {\n    // A 409 here means the requested version is already the active version --\n    // surface that specifically (referencing the operator-facing bundle name\n    // and version label) rather than the generic conflict fallback.\n    const statusCode = (\n      err instanceof PolicyEngineCliError\n        ? (err.cause as { response?: { statusCode?: number } } | undefined)\n        : undefined\n    )?.response?.statusCode;\n    if (statusCode === 409) {\n      throw new PolicyEngineCliError(\n        `Version \"${resolvedVersion.version}\" of policy bundle \"${bundleName}\" is already the active version.`,\n        { cause: err },\n      );\n    }\n    throw err;\n  }\n\n  printResult(this.process.stdout, {\n    json,\n    data: body,\n    renderTable: () =>\n      [\n        `bundleId    ${body.bundle.id}`,\n        `bundleName  ${body.bundle.bundleName}`,\n        formatPolicyBundleVersionSummary(body.version),\n      ].join('\\n'),\n  });\n\n  logger.info(\n    colors.green(dryRun ? 'Activation validation succeeded.' : 'Policy bundle version activated.'),\n  );\n}\n"],"mappings":"2aA6CA,eAAsB,EAEpB,CACE,cAAe,EACf,UACA,OACA,gBAAiB,EACjB,UAAW,EACX,OACA,QAAQ,IAEK,CACf,EAAoB,KAAK,QAAQ,KAAK,CACtC,EAAwB,EAAM,CAE9B,IAAM,EAAS,EAAwB,EAAc,EAAK,CACpD,EAAmB,MAAM,EAAsB,EAAQ,EAAW,CACxE,GAAI,CAAC,EACH,MAAU,MAAM,kBAAkB,EAAW,wCAAwC,CAEvF,IAAM,EAAkB,MAAM,EAA2B,EAAQ,EAAkB,CAAE,UAAS,CAAC,CAE/F,EAAO,KACL,EAAO,MACL,EACI,sCAAsC,EAAgB,QAAQ,MAC9D,uBAAuB,EAAgB,QAAQ,MACpD,CACF,CAED,IAAI,EACJ,GAAI,CACF,EAAO,MAAM,EACX,EACG,KACC,mCAAmC,EAAiB,YAAY,EAAgB,GAAG,WACnF,CACE,KAAM,EAAS,CAAE,OAAQ,GAAM,CAAG,EAAE,CACrC,CACF,CACA,MAA2C,CAC/C,OACM,EAAK,CAeZ,MAVE,aAAe,EACV,EAAI,MACL,IAAA,KACH,UAAU,aACM,IACX,IAAI,EACR,YAAY,EAAgB,QAAQ,sBAAsB,EAAW,kCACrE,CAAE,MAAO,EAAK,CACf,CAEG,EAGR,EAAY,KAAK,QAAQ,OAAQ,CAC/B,OACA,KAAM,EACN,gBACE,CACE,eAAe,EAAK,OAAO,KAC3B,eAAe,EAAK,OAAO,aAC3B,EAAiC,EAAK,QAAQ,CAC/C,CAAC,KAAK;EAAK,CACf,CAAC,CAEF,EAAO,KACL,EAAO,MAAM,EAAS,mCAAqC,mCAAmC,CAC/F"}