{"version":3,"file":"impl-BmQR1Pae.mjs","names":[],"sources":["../src/commands/policy/deactivate/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  printResult,\n  resolveBundleIdByName,\n  setPolicyEngineCliDebug,\n  throwPolicyEngineRequestError,\n  PolicyEngineCliError,\n} from '../helpers/index.js';\nimport type { DeactivatePolicyBundleResponse } from '../types.js';\n\n/** CLI flags for `transcend policy deactivate`. */\nexport interface DeactivateCommandFlags {\n  /** Logical bundle name to deactivate */\n  'bundle-name': string;\n  /** Transcend API key */\n  auth: string;\n  /** Transcend API URL */\n  'transcend-url': string;\n  /** Print raw JSON response */\n  json: boolean;\n  /** Include technical error details when a command fails */\n  debug?: boolean;\n}\n\n/**\n * Deactivate the currently active version of a policy bundle.\n *\n * Resolves `--bundle-name` to the parent bundle UUID internally, then calls the\n * Policy Engine deactivate 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 deactivate(\n  this: LocalContext,\n  {\n    'bundle-name': bundleName,\n    auth,\n    'transcend-url': transcendUrl,\n    json,\n    debug = false,\n  }: DeactivateCommandFlags,\n): Promise<void> {\n  doneInputValidation(this.process.exit);\n  setPolicyEngineCliDebug(debug);\n\n  const client = buildPolicyEngineClient(transcendUrl, auth);\n\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\n  logger.info(colors.green(`Deactivating active version for bundle \"${bundleName}\"...`));\n\n  let body: DeactivatePolicyBundleResponse;\n  try {\n    body = await client\n      .post(`v1/policy-engine/policy-bundles/${resolvedBundleId}/deactivate`)\n      .json<DeactivatePolicyBundleResponse>();\n  } catch (err) {\n    // The monolith 409 references the internal bundle UUID; rewrite it to the\n    // user-supplied bundle name so the error is actionable.\n    const statusCode = (err as { response?: { statusCode?: number } })?.response?.statusCode;\n    if (statusCode === 409) {\n      throw new PolicyEngineCliError(`Policy bundle \"${bundleName}\" has no active version.`, {\n        cause: err,\n      });\n    }\n    throwPolicyEngineRequestError(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(colors.green('Policy bundle version deactivated.'));\n}\n"],"mappings":"wWAwCA,eAAsB,EAEpB,CACE,cAAe,EACf,OACA,gBAAiB,EACjB,OACA,QAAQ,IAEK,CACf,EAAoB,KAAK,QAAQ,KAAK,CACtC,EAAwB,EAAM,CAE9B,IAAM,EAAS,EAAwB,EAAc,EAAK,CAEpD,EAAmB,MAAM,EAAsB,EAAQ,EAAW,CACxE,GAAI,CAAC,EACH,MAAU,MAAM,kBAAkB,EAAW,wCAAwC,CAGvF,EAAO,KAAK,EAAO,MAAM,2CAA2C,EAAW,MAAM,CAAC,CAEtF,IAAI,EACJ,GAAI,CACF,EAAO,MAAM,EACV,KAAK,mCAAmC,EAAiB,aAAa,CACtE,MAAsC,OAClC,EAAK,CAIZ,GADoB,GAAgD,UAAU,aAC3D,IACjB,MAAM,IAAI,EAAqB,kBAAkB,EAAW,0BAA2B,CACrF,MAAO,EACR,CAAC,CAEJ,EAA8B,EAAI,CAGpC,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,KAAK,EAAO,MAAM,qCAAqC,CAAC"}