{"version":3,"file":"resolveBundleIdByName-By5Vl8Iz.mjs","names":[],"sources":["../src/commands/policy/helpers/resolveBundleIdByName.ts"],"sourcesContent":["import type { Got } from 'got';\n\nimport type { PolicyBundle, PolicyBundleListResponse } from '../types.js';\nimport { policyEngineRequest } from './formatPolicyEngineRequestError.js';\n\n/**\n * Resolves a bundle name to its parent record by scanning offset-paginated listings.\n *\n * @param client - Policy Engine REST client\n * @param bundleName - Bundle name to resolve\n * @returns Matching bundle when found\n */\nexport async function resolveBundleByName(\n  client: Got,\n  bundleName: string,\n): Promise<PolicyBundle | undefined> {\n  const limit = 100;\n  let offset = 0;\n\n  while (true) {\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    const match = body.nodes.find((bundle) => bundle.bundleName === bundleName);\n    if (match) {\n      return match;\n    }\n\n    offset += body.nodes.length;\n    if (offset >= body.totalCount || body.nodes.length === 0) {\n      return undefined;\n    }\n  }\n}\n\n/**\n * Resolves a bundle name to its UUID by scanning offset-paginated bundle listings.\n *\n * @param client - Policy Engine REST client\n * @param bundleName - Bundle name to resolve\n * @returns Bundle UUID when found\n */\nexport async function resolveBundleIdByName(\n  client: Got,\n  bundleName: string,\n): Promise<string | undefined> {\n  const bundle = await resolveBundleByName(client, bundleName);\n  return bundle?.id;\n}\n"],"mappings":"+CAYA,eAAsB,EACpB,EACA,EACmC,CACnC,IACI,EAAS,EAEb,OAAa,CACX,IAAM,EAAO,MAAM,EACjB,EACG,IAAI,kCAAmC,CACtC,aAAc,CAAE,UAAO,SAAQ,CAChC,CAAC,CACD,MAAgC,CACpC,CAEK,EAAQ,EAAK,MAAM,KAAM,GAAW,EAAO,aAAe,EAAW,CAC3E,GAAI,EACF,OAAO,EAIT,GADA,GAAU,EAAK,MAAM,OACjB,GAAU,EAAK,YAAc,EAAK,MAAM,SAAW,EACrD,QAYN,eAAsB,EACpB,EACA,EAC6B,CAE7B,OAAO,MADc,EAAoB,EAAQ,EAAW,GAC7C"}