@vercel/cli-support 66.2.0 → 66.3.0-snapshot-3206bcf0afd3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/chunks/{alerts-NLLCERTK.js → alerts-MDU5KBQL.js} +1 -1
  2. package/dist/chunks/{chunk-6U7TRWBO.js → chunk-HVFGIJ44.js} +2 -2
  3. package/dist/chunks/chunk-KMTHGHJV.js +8 -0
  4. package/dist/chunks/{chunk-56QPAEAW.js → chunk-LXZ45FUT.js} +1 -1
  5. package/dist/chunks/{chunk-YALFS5SH.js → chunk-PX55WGPZ.js} +1 -1
  6. package/dist/chunks/{chunk-EIBQNIN7.js → chunk-TIOZWOR5.js} +1 -1
  7. package/dist/chunks/chunk-TUB3APDV.js +7 -0
  8. package/dist/chunks/chunk-VKVH7LHB.js +7 -0
  9. package/dist/chunks/{chunk-WHL4PWDW.js → chunk-XLYO5QNG.js} +1 -1
  10. package/dist/chunks/{chunk-YON6DNQB.js → chunk-ZGATYK5C.js} +1 -1
  11. package/dist/chunks/cli-embedded-FD3CAPRY.js +84 -0
  12. package/dist/chunks/{config-BYHUSTMY.js → config-ARJS37DC.js} +1 -1
  13. package/dist/chunks/{engine-I887QHnP-RUEEKCKH.js → engine-D8YAsQS_-WNPHYRQF.js} +2 -2
  14. package/dist/chunks/{image-H4HIURNR.js → image-PJBSA7SU.js} +1 -1
  15. package/dist/chunks/serving-aOQsBok0-OL36TMZU.js +8 -0
  16. package/dist/commands/deploy/index.js +1 -1
  17. package/dist/commands/env/index.js +1 -1
  18. package/dist/commands/link/index.js +1 -1
  19. package/dist/commands/project/index.js +1 -1
  20. package/dist/commands-account.js +2 -2
  21. package/dist/commands-ai.js +1 -1
  22. package/dist/commands-blob.js +1 -1
  23. package/dist/commands-core.js +15 -11
  24. package/dist/commands-deployments.js +1 -1
  25. package/dist/commands-flags.js +1 -1
  26. package/dist/commands-integrations.js +1 -1
  27. package/dist/commands-observability.js +2 -2
  28. package/dist/commands-routing.js +15 -3
  29. package/dist/index.js +1 -1
  30. package/dist/package.json +1 -1
  31. package/dist/version.mjs +1 -1
  32. package/package.json +12 -12
  33. package/dist/chunks/chunk-MGZ3Z4PF.js +0 -8
  34. package/dist/chunks/chunk-PQSW6EAL.js +0 -7
  35. package/dist/chunks/chunk-UFCL2VBD.js +0 -7
  36. package/dist/chunks/cli-embedded-KDIRH75G.js +0 -81
  37. package/dist/chunks/serving-Bulte-NO-VPBE6F4V.js +0 -8
@@ -4,5 +4,5 @@ import { dirname as __dirname_ } from 'node:path';
4
4
  const require = __createRequire(import.meta.url);
5
5
  const __filename = __fileURLToPath(import.meta.url);
6
6
  const __dirname = __dirname_(__filename);
7
- import{loadScopeNames,printBudgetAlertsTable,scopeNameOf}from"./chunk-Q2R3VQER.js";import{organizationTarget,parseBudgetFilterOptions,rejectUnexpectedArgs,resolveBudgetFilter,resolveBudgetOwner,trackScopeOptions,typeFilter}from"./chunk-66VYZZTY.js";import"./chunk-HQWR3EDU.js";import"./chunk-ZKQ47ZXI.js";import{handleValidationError,outputError,validateOptionalIntegerRange,validateTimeBound,validateTimeOrder}from"./chunk-ZJNDLFZ7.js";import"./chunk-2AMO2VMV.js";import{INVALID_NEXT_MESSAGE}from"./chunk-C6GY2G73.js";import"./chunk-D3M2JG5C.js";import{budgetAlertJson,listBudgetAlerts,ownerJson}from"./chunk-IG5ACFU6.js";import{getSubcommand}from"./chunk-ETV3C2CV.js";import"./chunk-CJZE7647.js";import{MAX_LIST_LIMIT,getNextPageCommand,printNextPageCommand}from"./chunk-D44WCAOX.js";import{getCommandAliases}from"./chunk-6U7TRWBO.js";import"./chunk-QOLGACFD.js";import"./chunk-DDPH26ZO.js";import"./chunk-PIDEH4SJ.js";import"./chunk-IIK6GUVI.js";import{alertsListSubcommand,alertsSubcommand,isBudgetScope}from"./chunk-C35SG42R.js";import"./chunk-2GBU6ULJ.js";import"./chunk-EJLYDHT7.js";import"./chunk-DOBV3XLO.js";import"./chunk-UFCL2VBD.js";import"./chunk-BMIYC2MH.js";import"./chunk-6CJFPT4F.js";import"./chunk-ZZD5W5KT.js";import"./chunk-VHSAI6FS.js";import"./chunk-F7L5SXJM.js";import"./chunk-GLCSWIB4.js";import"./chunk-XECELSF5.js";import"./chunk-6FYPSSL4.js";import"./chunk-UQZZX2J7.js";import"./chunk-UDZJCD5W.js";import"./chunk-5ZCSFPWG.js";import"./chunk-PY4WWD6Z.js";import"./chunk-XDYVJWGX.js";import"./chunk-JALVF3C2.js";import"./chunk-BPIGFKNN.js";import"./chunk-AB4WXRCO.js";import"./chunk-SYJXONEV.js";import{printError}from"./chunk-CY5KJ42N.js";import"./chunk-KK5C7HVP.js";import"./chunk-7KCRYDGK.js";import"./chunk-GLIQ4KNY.js";import{TelemetryClient}from"./chunk-KDCODXVL.js";import"./chunk-NWGBDBZI.js";import{AGENT_REASON}from"./chunk-PNWRO3XW.js";import"./chunk-DTUEHPME.js";import{require_pluralize}from"./chunk-4HR3I3ML.js";import"./chunk-LOA7SZWH.js";import"./chunk-MXTC4ZAQ.js";import{parseArguments,takeCommand}from"./chunk-LYL26S3N.js";import"./chunk-2VBFQZ72.js";import{validateJsonOutput}from"./chunk-6GKP6VUF.js";import"./chunk-4NTBYNFR.js";import"./chunk-4SAVH3H7.js";import{isAPIError}from"./chunk-GOI2VVI7.js";import"./chunk-B4KA3ZH2.js";import"./chunk-BOJDM3O7.js";import{output_manager_default}from"./chunk-AP6DZGTK.js";import"./chunk-BLUPZPAS.js";import"./chunk-5MDNVAE6.js";import"./chunk-MCYG7CCE.js";import"./chunk-YHPPP3SF.js";import"./chunk-24SIHFEW.js";import{getFlagsSpecification}from"./chunk-CFJBDBYH.js";import"./chunk-2BKALEOP.js";import"./chunk-NB2WLB3J.js";import"./chunk-ISWW3DKF.js";import"./chunk-BRQUZ5NC.js";import"./chunk-BULSRTQE.js";import{__toESM}from"./chunk-BZENIQ7N.js";var import_pluralize=__toESM(require_pluralize(),1);function encodeBudgetAlertsCursor(value){return Buffer.from(JSON.stringify({c:value.cursor,t:value.teamId,o:value.owner==="organization"?value.owner:void 0,s:value.since,u:value.until,sc:value.selector?.scope,si:value.selector&&"scopeId"in value.selector?value.selector.scopeId:void 0})).toString("base64url")}function decodeBudgetAlertsCursor(value){if(value===void 0)return{valid:!0,value:void 0};let invalid={valid:!1,code:"INVALID_NEXT",message:INVALID_NEXT_MESSAGE},raw;try{raw=JSON.parse(Buffer.from(value,"base64url").toString("utf8"))}catch{return invalid}if(typeof raw!="object"||raw===null)return invalid;let{c,t,o,s,u,sc,si}=raw;if(typeof c!="string"||typeof t!="string"||!(o===void 0||o==="organization"&&sc==="organization"&&si===void 0)||!isOptionalMs(s)||!isOptionalMs(u)||!(sc===void 0||isBudgetScope(sc)||isScopeList(sc))||!(si===void 0||typeof si=="string"&&isBudgetScope(sc)))return invalid;let selector;return isScopeList(sc)?selector={scope:sc}:isBudgetScope(sc)&&(selector=si===void 0?{scope:sc}:{scope:sc,scopeId:si}),o==="organization"?{valid:!0,value:{cursor:c,teamId:t,owner:o,since:s,until:u,selector:{scope:"organization",orgId:t}}}:{valid:!0,value:{cursor:c,teamId:t,since:s,until:u,selector}}}function isScopeList(value){return Array.isArray(value)&&value.length>0&&value.every(isBudgetScope)}function isOptionalMs(value){return value===void 0||Number.isFinite(value)}var BudgetAlertsTelemetryClient=class extends TelemetryClient{trackCliOptionOrganization(organization){organization&&this.trackCliOption({option:"organization",value:this.redactedValue})}trackCliOptionProject(project){project&&this.trackCliOption({option:"project",value:this.redactedValue})}trackCliOptionType(types){types?.length&&this.trackCliOption({option:"type",value:types.join(",")})}trackCliOptionProduct(product){product&&this.trackCliOption({option:"product",value:this.redactedValue})}trackCliSubcommandList(actual){this.trackCliSubcommand({subcommand:"list",value:actual})}trackCliOptionSince(since){since&&this.trackCliOption({option:"since",value:this.redactedValue})}trackCliOptionUntil(until){until&&this.trackCliOption({option:"until",value:this.redactedValue})}trackCliOptionLimit(limit){limit!==void 0&&this.trackCliOption({option:"limit",value:String(limit)})}trackCliOptionNext(next){next&&this.trackCliOption({option:"next",value:this.redactedValue})}trackCliOptionFormat(format){format&&this.trackCliOption({option:"format",value:format})}trackCliFlagJson(json){json&&this.trackCliFlag("json")}};async function alerts(client,argv){let telemetry=new BudgetAlertsTelemetryClient({opts:{store:client.telemetryEventStore}}),action,parsedArgs,flagsSpecification=getFlagsSpecification(alertsSubcommand.options);try{let selected=takeCommand(argv,flagsSpecification);action=getSubcommand(selected.command?[selected.command]:[],{list:getCommandAliases(alertsListSubcommand)}),parsedArgs=parseArguments(action.subcommand?selected.args:argv,flagsSpecification)}catch(error){return printError(error),2}let{flags:opts,args}=parsedArgs;action.subcommand==="list"&&telemetry.trackCliSubcommandList(action.subcommandOriginal);let formatResult=validateJsonOutput(opts);if(!formatResult.valid)return output_manager_default.error(formatResult.error),2;let asJson=formatResult.jsonOutput;if(rejectUnexpectedArgs(args,"billing budgets alerts"))return 2;let scopeArgs=parseBudgetFilterOptions(opts);if("error"in scopeArgs)return outputError(client,asJson,"INVALID_ARGUMENTS",scopeArgs.error);trackScopeOptions(telemetry,opts),telemetry.trackCliOptionType(opts["--type"]),telemetry.trackCliOptionSince(opts["--since"]),telemetry.trackCliOptionUntil(opts["--until"]),telemetry.trackCliOptionLimit(opts["--limit"]),telemetry.trackCliOptionNext(opts["--next"]),telemetry.trackCliOptionFormat(opts["--format"]?"json":void 0),telemetry.trackCliFlagJson(opts["--json"]);let nextResult=decodeBudgetAlertsCursor(opts["--next"]);if(!nextResult.valid)return handleValidationError(nextResult,asJson,client);let cursor=nextResult.value,{types}=scopeArgs.value;if(cursor&&types&&!sameSelector(cursor.selector,{scope:types}))return outputError(client,asJson,"INVALID_NEXT",OTHER_FILTER_CURSOR);let warnings=[],limit=opts["--limit"];if(typeof limit=="number"&&Number.isInteger(limit)&&limit>MAX_LIST_LIMIT){let message=`--limit ${limit} is above the maximum of ${MAX_LIST_LIMIT}. Using ${MAX_LIST_LIMIT}.`;warnings.push({reason:AGENT_REASON.LIMIT_CLAMPED,message}),asJson||output_manager_default.warning(message),limit=MAX_LIST_LIMIT}let limitResult=validateOptionalIntegerRange(limit,{flag:"--limit",min:1,max:MAX_LIST_LIMIT});if(!limitResult.valid)return handleValidationError(limitResult,asJson,client);let sinceResult=validateTimeBound(opts["--since"]);if(!sinceResult.valid)return handleValidationError(sinceResult,asJson,client);let untilResult=validateTimeBound(opts["--until"]);if(!untilResult.valid)return handleValidationError(untilResult,asJson,client);let order=validateTimeOrder(sinceResult.value,untilResult.value);if(!order.valid)return handleValidationError(order,asJson,client);let resolvedOwner=await resolveBudgetOwner(client,scopeArgs.value.input??(cursor?.owner==="organization"?{scope:"organization",value:cursor.teamId}:null));if(!resolvedOwner)return 2;if("error"in resolvedOwner)return outputError(client,asJson,resolvedOwner.usage?"INVALID_ARGUMENTS":"API_ERROR",resolvedOwner.error);let owner=resolvedOwner.value;if(cursor&&cursor.teamId!==owner.id)return outputError(client,asJson,"INVALID_NEXT",`This --next cursor is from another team or organization, not ${owner.slug}. Use the --scope or --organization it was printed with.`);let since=cursor?cursor.since:sinceResult.value?.getTime(),until=cursor?cursor.until:untilResult.value?.getTime();output_manager_default.spinner("Fetching budget alerts\u2026");let resolved=cursor&&!scopeArgs.value.input&&!scopeArgs.value.types?{value:cursorFilter(owner,cursor.selector)}:await resolveBudgetFilter(client,owner,scopeArgs.value);if("error"in resolved)return output_manager_default.stopSpinner(),outputError(client,asJson,resolved.usage?"INVALID_ARGUMENTS":"API_ERROR",resolved.error);let filter=resolved.value;if(cursor&&!sameSelector(cursor.selector,filter.selector))return output_manager_default.stopSpinner(),outputError(client,asJson,"INVALID_NEXT",OTHER_FILTER_CURSOR);let page;try{page=await listBudgetAlerts(client,filter.selector,{since,until,limit:limitResult.value,next:cursor?.cursor})}catch(err){if(output_manager_default.stopSpinner(),isAPIError(err))return err.code==="invalid_cursor"?outputError(client,asJson,"INVALID_NEXT",INVALID_NEXT_MESSAGE):outputError(client,asJson,err.code||"API_ERROR",err.message);throw err}let names=await loadScopeNames(client,owner,page.data);output_manager_default.stopSpinner();let next=page.next?encodeBudgetAlertsCursor({cursor:page.next,teamId:owner.id,owner:owner.type,since,until,selector:filter.selector}):null;if(asJson)return client.stdout.write(`${JSON.stringify({...ownerJson(owner),...filter.selector?{filter:filter.json}:{},alerts:page.data.map(alert=>budgetAlertJson(alert,scopeNameOf(names,alert))),pagination:{next},...warnings.length>0?{warnings}:{}},null,2)}
7
+ import{loadScopeNames,printBudgetAlertsTable,scopeNameOf}from"./chunk-Q2R3VQER.js";import{organizationTarget,parseBudgetFilterOptions,rejectUnexpectedArgs,resolveBudgetFilter,resolveBudgetOwner,trackScopeOptions,typeFilter}from"./chunk-66VYZZTY.js";import"./chunk-HQWR3EDU.js";import"./chunk-ZKQ47ZXI.js";import{handleValidationError,outputError,validateOptionalIntegerRange,validateTimeBound,validateTimeOrder}from"./chunk-ZJNDLFZ7.js";import"./chunk-2AMO2VMV.js";import{INVALID_NEXT_MESSAGE}from"./chunk-C6GY2G73.js";import"./chunk-D3M2JG5C.js";import{budgetAlertJson,listBudgetAlerts,ownerJson}from"./chunk-IG5ACFU6.js";import{getSubcommand}from"./chunk-ETV3C2CV.js";import"./chunk-CJZE7647.js";import{MAX_LIST_LIMIT,getNextPageCommand,printNextPageCommand}from"./chunk-D44WCAOX.js";import{getCommandAliases}from"./chunk-HVFGIJ44.js";import"./chunk-QOLGACFD.js";import"./chunk-DDPH26ZO.js";import"./chunk-PIDEH4SJ.js";import"./chunk-IIK6GUVI.js";import{alertsListSubcommand,alertsSubcommand,isBudgetScope}from"./chunk-C35SG42R.js";import"./chunk-2GBU6ULJ.js";import"./chunk-EJLYDHT7.js";import"./chunk-DOBV3XLO.js";import"./chunk-TUB3APDV.js";import"./chunk-BMIYC2MH.js";import"./chunk-6CJFPT4F.js";import"./chunk-ZZD5W5KT.js";import"./chunk-VHSAI6FS.js";import"./chunk-F7L5SXJM.js";import"./chunk-GLCSWIB4.js";import"./chunk-XECELSF5.js";import"./chunk-6FYPSSL4.js";import"./chunk-UQZZX2J7.js";import"./chunk-UDZJCD5W.js";import"./chunk-5ZCSFPWG.js";import"./chunk-PY4WWD6Z.js";import"./chunk-XDYVJWGX.js";import"./chunk-JALVF3C2.js";import"./chunk-BPIGFKNN.js";import"./chunk-AB4WXRCO.js";import"./chunk-SYJXONEV.js";import{printError}from"./chunk-CY5KJ42N.js";import"./chunk-KK5C7HVP.js";import"./chunk-7KCRYDGK.js";import"./chunk-GLIQ4KNY.js";import{TelemetryClient}from"./chunk-KDCODXVL.js";import"./chunk-NWGBDBZI.js";import{AGENT_REASON}from"./chunk-PNWRO3XW.js";import"./chunk-DTUEHPME.js";import{require_pluralize}from"./chunk-4HR3I3ML.js";import"./chunk-LOA7SZWH.js";import"./chunk-MXTC4ZAQ.js";import{parseArguments,takeCommand}from"./chunk-LYL26S3N.js";import"./chunk-2VBFQZ72.js";import{validateJsonOutput}from"./chunk-6GKP6VUF.js";import"./chunk-4NTBYNFR.js";import"./chunk-4SAVH3H7.js";import{isAPIError}from"./chunk-GOI2VVI7.js";import"./chunk-B4KA3ZH2.js";import"./chunk-BOJDM3O7.js";import{output_manager_default}from"./chunk-AP6DZGTK.js";import"./chunk-BLUPZPAS.js";import"./chunk-5MDNVAE6.js";import"./chunk-MCYG7CCE.js";import"./chunk-YHPPP3SF.js";import"./chunk-24SIHFEW.js";import{getFlagsSpecification}from"./chunk-CFJBDBYH.js";import"./chunk-2BKALEOP.js";import"./chunk-NB2WLB3J.js";import"./chunk-ISWW3DKF.js";import"./chunk-BRQUZ5NC.js";import"./chunk-BULSRTQE.js";import{__toESM}from"./chunk-BZENIQ7N.js";var import_pluralize=__toESM(require_pluralize(),1);function encodeBudgetAlertsCursor(value){return Buffer.from(JSON.stringify({c:value.cursor,t:value.teamId,o:value.owner==="organization"?value.owner:void 0,s:value.since,u:value.until,sc:value.selector?.scope,si:value.selector&&"scopeId"in value.selector?value.selector.scopeId:void 0})).toString("base64url")}function decodeBudgetAlertsCursor(value){if(value===void 0)return{valid:!0,value:void 0};let invalid={valid:!1,code:"INVALID_NEXT",message:INVALID_NEXT_MESSAGE},raw;try{raw=JSON.parse(Buffer.from(value,"base64url").toString("utf8"))}catch{return invalid}if(typeof raw!="object"||raw===null)return invalid;let{c,t,o,s,u,sc,si}=raw;if(typeof c!="string"||typeof t!="string"||!(o===void 0||o==="organization"&&sc==="organization"&&si===void 0)||!isOptionalMs(s)||!isOptionalMs(u)||!(sc===void 0||isBudgetScope(sc)||isScopeList(sc))||!(si===void 0||typeof si=="string"&&isBudgetScope(sc)))return invalid;let selector;return isScopeList(sc)?selector={scope:sc}:isBudgetScope(sc)&&(selector=si===void 0?{scope:sc}:{scope:sc,scopeId:si}),o==="organization"?{valid:!0,value:{cursor:c,teamId:t,owner:o,since:s,until:u,selector:{scope:"organization",orgId:t}}}:{valid:!0,value:{cursor:c,teamId:t,since:s,until:u,selector}}}function isScopeList(value){return Array.isArray(value)&&value.length>0&&value.every(isBudgetScope)}function isOptionalMs(value){return value===void 0||Number.isFinite(value)}var BudgetAlertsTelemetryClient=class extends TelemetryClient{trackCliOptionOrganization(organization){organization&&this.trackCliOption({option:"organization",value:this.redactedValue})}trackCliOptionProject(project){project&&this.trackCliOption({option:"project",value:this.redactedValue})}trackCliOptionType(types){types?.length&&this.trackCliOption({option:"type",value:types.join(",")})}trackCliOptionProduct(product){product&&this.trackCliOption({option:"product",value:this.redactedValue})}trackCliSubcommandList(actual){this.trackCliSubcommand({subcommand:"list",value:actual})}trackCliOptionSince(since){since&&this.trackCliOption({option:"since",value:this.redactedValue})}trackCliOptionUntil(until){until&&this.trackCliOption({option:"until",value:this.redactedValue})}trackCliOptionLimit(limit){limit!==void 0&&this.trackCliOption({option:"limit",value:String(limit)})}trackCliOptionNext(next){next&&this.trackCliOption({option:"next",value:this.redactedValue})}trackCliOptionFormat(format){format&&this.trackCliOption({option:"format",value:format})}trackCliFlagJson(json){json&&this.trackCliFlag("json")}};async function alerts(client,argv){let telemetry=new BudgetAlertsTelemetryClient({opts:{store:client.telemetryEventStore}}),action,parsedArgs,flagsSpecification=getFlagsSpecification(alertsSubcommand.options);try{let selected=takeCommand(argv,flagsSpecification);action=getSubcommand(selected.command?[selected.command]:[],{list:getCommandAliases(alertsListSubcommand)}),parsedArgs=parseArguments(action.subcommand?selected.args:argv,flagsSpecification)}catch(error){return printError(error),2}let{flags:opts,args}=parsedArgs;action.subcommand==="list"&&telemetry.trackCliSubcommandList(action.subcommandOriginal);let formatResult=validateJsonOutput(opts);if(!formatResult.valid)return output_manager_default.error(formatResult.error),2;let asJson=formatResult.jsonOutput;if(rejectUnexpectedArgs(args,"billing budgets alerts"))return 2;let scopeArgs=parseBudgetFilterOptions(opts);if("error"in scopeArgs)return outputError(client,asJson,"INVALID_ARGUMENTS",scopeArgs.error);trackScopeOptions(telemetry,opts),telemetry.trackCliOptionType(opts["--type"]),telemetry.trackCliOptionSince(opts["--since"]),telemetry.trackCliOptionUntil(opts["--until"]),telemetry.trackCliOptionLimit(opts["--limit"]),telemetry.trackCliOptionNext(opts["--next"]),telemetry.trackCliOptionFormat(opts["--format"]?"json":void 0),telemetry.trackCliFlagJson(opts["--json"]);let nextResult=decodeBudgetAlertsCursor(opts["--next"]);if(!nextResult.valid)return handleValidationError(nextResult,asJson,client);let cursor=nextResult.value,{types}=scopeArgs.value;if(cursor&&types&&!sameSelector(cursor.selector,{scope:types}))return outputError(client,asJson,"INVALID_NEXT",OTHER_FILTER_CURSOR);let warnings=[],limit=opts["--limit"];if(typeof limit=="number"&&Number.isInteger(limit)&&limit>MAX_LIST_LIMIT){let message=`--limit ${limit} is above the maximum of ${MAX_LIST_LIMIT}. Using ${MAX_LIST_LIMIT}.`;warnings.push({reason:AGENT_REASON.LIMIT_CLAMPED,message}),asJson||output_manager_default.warning(message),limit=MAX_LIST_LIMIT}let limitResult=validateOptionalIntegerRange(limit,{flag:"--limit",min:1,max:MAX_LIST_LIMIT});if(!limitResult.valid)return handleValidationError(limitResult,asJson,client);let sinceResult=validateTimeBound(opts["--since"]);if(!sinceResult.valid)return handleValidationError(sinceResult,asJson,client);let untilResult=validateTimeBound(opts["--until"]);if(!untilResult.valid)return handleValidationError(untilResult,asJson,client);let order=validateTimeOrder(sinceResult.value,untilResult.value);if(!order.valid)return handleValidationError(order,asJson,client);let resolvedOwner=await resolveBudgetOwner(client,scopeArgs.value.input??(cursor?.owner==="organization"?{scope:"organization",value:cursor.teamId}:null));if(!resolvedOwner)return 2;if("error"in resolvedOwner)return outputError(client,asJson,resolvedOwner.usage?"INVALID_ARGUMENTS":"API_ERROR",resolvedOwner.error);let owner=resolvedOwner.value;if(cursor&&cursor.teamId!==owner.id)return outputError(client,asJson,"INVALID_NEXT",`This --next cursor is from another team or organization, not ${owner.slug}. Use the --scope or --organization it was printed with.`);let since=cursor?cursor.since:sinceResult.value?.getTime(),until=cursor?cursor.until:untilResult.value?.getTime();output_manager_default.spinner("Fetching budget alerts\u2026");let resolved=cursor&&!scopeArgs.value.input&&!scopeArgs.value.types?{value:cursorFilter(owner,cursor.selector)}:await resolveBudgetFilter(client,owner,scopeArgs.value);if("error"in resolved)return output_manager_default.stopSpinner(),outputError(client,asJson,resolved.usage?"INVALID_ARGUMENTS":"API_ERROR",resolved.error);let filter=resolved.value;if(cursor&&!sameSelector(cursor.selector,filter.selector))return output_manager_default.stopSpinner(),outputError(client,asJson,"INVALID_NEXT",OTHER_FILTER_CURSOR);let page;try{page=await listBudgetAlerts(client,filter.selector,{since,until,limit:limitResult.value,next:cursor?.cursor})}catch(err){if(output_manager_default.stopSpinner(),isAPIError(err))return err.code==="invalid_cursor"?outputError(client,asJson,"INVALID_NEXT",INVALID_NEXT_MESSAGE):outputError(client,asJson,err.code||"API_ERROR",err.message);throw err}let names=await loadScopeNames(client,owner,page.data);output_manager_default.stopSpinner();let next=page.next?encodeBudgetAlertsCursor({cursor:page.next,teamId:owner.id,owner:owner.type,since,until,selector:filter.selector}):null;if(asJson)return client.stdout.write(`${JSON.stringify({...ownerJson(owner),...filter.selector?{filter:filter.json}:{},alerts:page.data.map(alert=>budgetAlertJson(alert,scopeNameOf(names,alert))),pagination:{next},...warnings.length>0?{warnings}:{}},null,2)}
8
8
  `),0;let{where}=filter;return page.data.length===0?(output_manager_default.log(cursor?`No more budget alerts ${where}.`:`No budget alerts found ${where}.`),0):(output_manager_default.log(`${(0,import_pluralize.default)("budget alert",page.data.length,!0)} ${where}`),client.stdout.write(printBudgetAlertsTable(page.data,names)),next&&printNextPageCommand(getNextPageCommand(client.argv,next,WINDOW_FLAGS)),0)}function cursorFilter(owner,selector){if(owner.type==="organization")return organizationTarget(owner);if(!selector)return typeFilter(owner,null);if(Array.isArray(selector.scope))return typeFilter(owner,selector.scope);let{scope}=selector,scopeId="scopeId"in selector?selector.scopeId:void 0;return{selector,args:"",where:scopeId?`on ${scope} ${scopeId}`:`on ${scope}`,json:{scope,scopeId:scopeId??null,name:null}}}var OTHER_FILTER_CURSOR="This --next cursor is from a list with a different --type, --organization, --project, or --product. Use the options it was printed with.";function sameSelector(a,b){return queryKey(a)===queryKey(b)}function queryKey(query){return query?Array.isArray(query.scope)?query.scope.join(","):"scopeId"in query&&query.scopeId?`${query.scope}:${query.scopeId}`:query.scope:""}var WINDOW_FLAGS=["--since","-s","--until","-u"];export{alerts as default};