domani 0.3.11 → 0.3.12

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 (2) hide show
  1. package/dist/domani.cjs +172 -66
  2. package/package.json +1 -1
package/dist/domani.cjs CHANGED
@@ -1,96 +1,202 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var Tn=Object.create;var Ni=Object.defineProperty;var Pn=Object.getOwnPropertyDescriptor;var Dn=Object.getOwnPropertyNames;var Nn=Object.getPrototypeOf,Fn=Object.prototype.hasOwnProperty;var Se=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Vn=(e,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Dn(t))!Fn.call(e,n)&&n!==i&&Ni(e,n,{get:()=>t[n],enumerable:!(s=Pn(t,n))||s.enumerable});return e};var P=(e,t,i)=>(i=e!=null?Tn(Nn(e)):{},Vn(t||!e||!e.__esModule?Ni(i,"default",{value:e,enumerable:!0}):i,e));var Xe=Se(Ht=>{var ct=class extends Error{constructor(t,i,s){super(s),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=i,this.exitCode=t,this.nestedError=void 0}},Wt=class extends ct{constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};Ht.CommanderError=ct;Ht.InvalidArgumentError=Wt});var ut=Se(Gt=>{var{InvalidArgumentError:Mn}=Xe(),Jt=class{constructor(t,i){switch(this.description=i||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case"<":this.required=!0,this._name=t.slice(1,-1);break;case"[":this.required=!1,this._name=t.slice(1,-1);break;default:this.required=!0,this._name=t;break}this._name.length>3&&this._name.slice(-3)==="..."&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_concatValue(t,i){return i===this.defaultValue||!Array.isArray(i)?[t]:i.concat(t)}default(t,i){return this.defaultValue=t,this.defaultValueDescription=i,this}argParser(t){return this.parseArg=t,this}choices(t){return this.argChoices=t.slice(),this.parseArg=(i,s)=>{if(!this.argChoices.includes(i))throw new Mn(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(i,s):i},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function Un(e){let t=e.name()+(e.variadic===!0?"...":"");return e.required?"<"+t+">":"["+t+"]"}Gt.Argument=Jt;Gt.humanReadableArgName=Un});var Yt=Se(Kt=>{var{humanReadableArgName:Ln}=ut(),Bt=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(t){this.helpWidth=this.helpWidth??t.helpWidth??80}visibleCommands(t){let i=t.commands.filter(n=>!n._hidden),s=t._getHelpCommand();return s&&!s._hidden&&i.push(s),this.sortSubcommands&&i.sort((n,r)=>n.name().localeCompare(r.name())),i}compareOptions(t,i){let s=n=>n.short?n.short.replace(/^-/,""):n.long.replace(/^--/,"");return s(t).localeCompare(s(i))}visibleOptions(t){let i=t.options.filter(n=>!n.hidden),s=t._getHelpOption();if(s&&!s.hidden){let n=s.short&&t._findOption(s.short),r=s.long&&t._findOption(s.long);!n&&!r?i.push(s):s.long&&!r?i.push(t.createOption(s.long,s.description)):s.short&&!n&&i.push(t.createOption(s.short,s.description))}return this.sortOptions&&i.sort(this.compareOptions),i}visibleGlobalOptions(t){if(!this.showGlobalOptions)return[];let i=[];for(let s=t.parent;s;s=s.parent){let n=s.options.filter(r=>!r.hidden);i.push(...n)}return this.sortOptions&&i.sort(this.compareOptions),i}visibleArguments(t){return t._argsDescription&&t.registeredArguments.forEach(i=>{i.description=i.description||t._argsDescription[i.name()]||""}),t.registeredArguments.find(i=>i.description)?t.registeredArguments:[]}subcommandTerm(t){let i=t.registeredArguments.map(s=>Ln(s)).join(" ");return t._name+(t._aliases[0]?"|"+t._aliases[0]:"")+(t.options.length?" [options]":"")+(i?" "+i:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,i){return i.visibleCommands(t).reduce((s,n)=>Math.max(s,this.displayWidth(i.styleSubcommandTerm(i.subcommandTerm(n)))),0)}longestOptionTermLength(t,i){return i.visibleOptions(t).reduce((s,n)=>Math.max(s,this.displayWidth(i.styleOptionTerm(i.optionTerm(n)))),0)}longestGlobalOptionTermLength(t,i){return i.visibleGlobalOptions(t).reduce((s,n)=>Math.max(s,this.displayWidth(i.styleOptionTerm(i.optionTerm(n)))),0)}longestArgumentTermLength(t,i){return i.visibleArguments(t).reduce((s,n)=>Math.max(s,this.displayWidth(i.styleArgumentTerm(i.argumentTerm(n)))),0)}commandUsage(t){let i=t._name;t._aliases[0]&&(i=i+"|"+t._aliases[0]);let s="";for(let n=t.parent;n;n=n.parent)s=n.name()+" "+s;return s+i+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){let i=[];return t.argChoices&&i.push(`choices: ${t.argChoices.map(s=>JSON.stringify(s)).join(", ")}`),t.defaultValue!==void 0&&(t.required||t.optional||t.isBoolean()&&typeof t.defaultValue=="boolean")&&i.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),t.presetArg!==void 0&&t.optional&&i.push(`preset: ${JSON.stringify(t.presetArg)}`),t.envVar!==void 0&&i.push(`env: ${t.envVar}`),i.length>0?`${t.description} (${i.join(", ")})`:t.description}argumentDescription(t){let i=[];if(t.argChoices&&i.push(`choices: ${t.argChoices.map(s=>JSON.stringify(s)).join(", ")}`),t.defaultValue!==void 0&&i.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),i.length>0){let s=`(${i.join(", ")})`;return t.description?`${t.description} ${s}`:s}return t.description}formatHelp(t,i){let s=i.padWidth(t,i),n=i.helpWidth??80;function r(u,y){return i.formatItem(u,s,y,i)}let o=[`${i.styleTitle("Usage:")} ${i.styleUsage(i.commandUsage(t))}`,""],a=i.commandDescription(t);a.length>0&&(o=o.concat([i.boxWrap(i.styleCommandDescription(a),n),""]));let l=i.visibleArguments(t).map(u=>r(i.styleArgumentTerm(i.argumentTerm(u)),i.styleArgumentDescription(i.argumentDescription(u))));l.length>0&&(o=o.concat([i.styleTitle("Arguments:"),...l,""]));let m=i.visibleOptions(t).map(u=>r(i.styleOptionTerm(i.optionTerm(u)),i.styleOptionDescription(i.optionDescription(u))));if(m.length>0&&(o=o.concat([i.styleTitle("Options:"),...m,""])),i.showGlobalOptions){let u=i.visibleGlobalOptions(t).map(y=>r(i.styleOptionTerm(i.optionTerm(y)),i.styleOptionDescription(i.optionDescription(y))));u.length>0&&(o=o.concat([i.styleTitle("Global Options:"),...u,""]))}let d=i.visibleCommands(t).map(u=>r(i.styleSubcommandTerm(i.subcommandTerm(u)),i.styleSubcommandDescription(i.subcommandDescription(u))));return d.length>0&&(o=o.concat([i.styleTitle("Commands:"),...d,""])),o.join(`
3
- `)}displayWidth(t){return Fi(t).length}styleTitle(t){return t}styleUsage(t){return t.split(" ").map(i=>i==="[options]"?this.styleOptionText(i):i==="[command]"?this.styleSubcommandText(i):i[0]==="["||i[0]==="<"?this.styleArgumentText(i):this.styleCommandText(i)).join(" ")}styleCommandDescription(t){return this.styleDescriptionText(t)}styleOptionDescription(t){return this.styleDescriptionText(t)}styleSubcommandDescription(t){return this.styleDescriptionText(t)}styleArgumentDescription(t){return this.styleDescriptionText(t)}styleDescriptionText(t){return t}styleOptionTerm(t){return this.styleOptionText(t)}styleSubcommandTerm(t){return t.split(" ").map(i=>i==="[options]"?this.styleOptionText(i):i[0]==="["||i[0]==="<"?this.styleArgumentText(i):this.styleSubcommandText(i)).join(" ")}styleArgumentTerm(t){return this.styleArgumentText(t)}styleOptionText(t){return t}styleArgumentText(t){return t}styleSubcommandText(t){return t}styleCommandText(t){return t}padWidth(t,i){return Math.max(i.longestOptionTermLength(t,i),i.longestGlobalOptionTermLength(t,i),i.longestSubcommandTermLength(t,i),i.longestArgumentTermLength(t,i))}preformatted(t){return/\n[^\S\r\n]/.test(t)}formatItem(t,i,s,n){let o=" ".repeat(2);if(!s)return o+t;let a=t.padEnd(i+t.length-n.displayWidth(t)),l=2,d=(this.helpWidth??80)-i-l-2,u;return d<this.minWidthToWrap||n.preformatted(s)?u=s:u=n.boxWrap(s,d).replace(/\n/g,`
4
- `+" ".repeat(i+l)),o+a+" ".repeat(l)+u.replace(/\n/g,`
5
- ${o}`)}boxWrap(t,i){if(i<this.minWidthToWrap)return t;let s=t.split(/\r\n|\n/),n=/[\s]*[^\s]+/g,r=[];return s.forEach(o=>{let a=o.match(n);if(a===null){r.push("");return}let l=[a.shift()],m=this.displayWidth(l[0]);a.forEach(d=>{let u=this.displayWidth(d);if(m+u<=i){l.push(d),m+=u;return}r.push(l.join(""));let y=d.trimStart();l=[y],m=this.displayWidth(y)}),r.push(l.join(""))}),r.join(`
6
- `)}};function Fi(e){let t=/\x1b\[\d*(;\d*)*m/g;return e.replace(t,"")}Kt.Help=Bt;Kt.stripColor=Fi});var Qt=Se(Zt=>{var{InvalidArgumentError:qn}=Xe(),zt=class{constructor(t,i){this.flags=t,this.description=i||"",this.required=t.includes("<"),this.optional=t.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(t),this.mandatory=!1;let s=Wn(t);this.short=s.shortFlag,this.long=s.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith("--no-")),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0}default(t,i){return this.defaultValue=t,this.defaultValueDescription=i,this}preset(t){return this.presetArg=t,this}conflicts(t){return this.conflictsWith=this.conflictsWith.concat(t),this}implies(t){let i=t;return typeof t=="string"&&(i={[t]:!0}),this.implied=Object.assign(this.implied||{},i),this}env(t){return this.envVar=t,this}argParser(t){return this.parseArg=t,this}makeOptionMandatory(t=!0){return this.mandatory=!!t,this}hideHelp(t=!0){return this.hidden=!!t,this}_concatValue(t,i){return i===this.defaultValue||!Array.isArray(i)?[t]:i.concat(t)}choices(t){return this.argChoices=t.slice(),this.parseArg=(i,s)=>{if(!this.argChoices.includes(i))throw new qn(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(i,s):i},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?Vi(this.name().replace(/^no-/,"")):Vi(this.name())}is(t){return this.short===t||this.long===t}isBoolean(){return!this.required&&!this.optional&&!this.negate}},Xt=class{constructor(t){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,t.forEach(i=>{i.negate?this.negativeOptions.set(i.attributeName(),i):this.positiveOptions.set(i.attributeName(),i)}),this.negativeOptions.forEach((i,s)=>{this.positiveOptions.has(s)&&this.dualOptions.add(s)})}valueFromOption(t,i){let s=i.attributeName();if(!this.dualOptions.has(s))return!0;let n=this.negativeOptions.get(s).presetArg,r=n!==void 0?n:!1;return i.negate===(r===t)}};function Vi(e){return e.split("-").reduce((t,i)=>t+i[0].toUpperCase()+i.slice(1))}function Wn(e){let t,i,s=/^-[^-]$/,n=/^--[^-]/,r=e.split(/[ |,]+/).concat("guard");if(s.test(r[0])&&(t=r.shift()),n.test(r[0])&&(i=r.shift()),!t&&s.test(r[0])&&(t=r.shift()),!t&&n.test(r[0])&&(t=i,i=r.shift()),r[0].startsWith("-")){let o=r[0],a=`option creation failed due to '${o}' in option flags '${e}'`;throw/^-[^-][^-]/.test(o)?new Error(`${a}
2
+ "use strict";var to=Object.create;var Fi=Object.defineProperty;var io=Object.getOwnPropertyDescriptor;var so=Object.getOwnPropertyNames;var no=Object.getPrototypeOf,ro=Object.prototype.hasOwnProperty;var Ee=(e,t)=>()=>(e&&(t=e(e=0)),t);var Ze=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),xt=(e,t)=>{for(var i in t)Fi(e,i,{get:t[i],enumerable:!0})},oo=(e,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of so(t))!ro.call(e,n)&&n!==i&&Fi(e,n,{get:()=>t[n],enumerable:!(s=io(t,n))||s.enumerable});return e};var M=(e,t,i)=>(i=e!=null?to(no(e)):{},oo(t||!e||!e.__esModule?Fi(i,"default",{value:e,enumerable:!0}):i,e));var Pt=Ze(Mi=>{var Kt=class extends Error{constructor(t,i,s){super(s),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=i,this.exitCode=t,this.nestedError=void 0}},Vi=class extends Kt{constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};Mi.CommanderError=Kt;Mi.InvalidArgumentError=Vi});var Yt=Ze(Li=>{var{InvalidArgumentError:ao}=Pt(),Ui=class{constructor(t,i){switch(this.description=i||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case"<":this.required=!0,this._name=t.slice(1,-1);break;case"[":this.required=!1,this._name=t.slice(1,-1);break;default:this.required=!0,this._name=t;break}this._name.length>3&&this._name.slice(-3)==="..."&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_concatValue(t,i){return i===this.defaultValue||!Array.isArray(i)?[t]:i.concat(t)}default(t,i){return this.defaultValue=t,this.defaultValueDescription=i,this}argParser(t){return this.parseArg=t,this}choices(t){return this.argChoices=t.slice(),this.parseArg=(i,s)=>{if(!this.argChoices.includes(i))throw new ao(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(i,s):i},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function lo(e){let t=e.name()+(e.variadic===!0?"...":"");return e.required?"<"+t+">":"["+t+"]"}Li.Argument=Ui;Li.humanReadableArgName=lo});var Hi=Ze(Wi=>{var{humanReadableArgName:co}=Yt(),qi=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(t){this.helpWidth=this.helpWidth??t.helpWidth??80}visibleCommands(t){let i=t.commands.filter(n=>!n._hidden),s=t._getHelpCommand();return s&&!s._hidden&&i.push(s),this.sortSubcommands&&i.sort((n,r)=>n.name().localeCompare(r.name())),i}compareOptions(t,i){let s=n=>n.short?n.short.replace(/^-/,""):n.long.replace(/^--/,"");return s(t).localeCompare(s(i))}visibleOptions(t){let i=t.options.filter(n=>!n.hidden),s=t._getHelpOption();if(s&&!s.hidden){let n=s.short&&t._findOption(s.short),r=s.long&&t._findOption(s.long);!n&&!r?i.push(s):s.long&&!r?i.push(t.createOption(s.long,s.description)):s.short&&!n&&i.push(t.createOption(s.short,s.description))}return this.sortOptions&&i.sort(this.compareOptions),i}visibleGlobalOptions(t){if(!this.showGlobalOptions)return[];let i=[];for(let s=t.parent;s;s=s.parent){let n=s.options.filter(r=>!r.hidden);i.push(...n)}return this.sortOptions&&i.sort(this.compareOptions),i}visibleArguments(t){return t._argsDescription&&t.registeredArguments.forEach(i=>{i.description=i.description||t._argsDescription[i.name()]||""}),t.registeredArguments.find(i=>i.description)?t.registeredArguments:[]}subcommandTerm(t){let i=t.registeredArguments.map(s=>co(s)).join(" ");return t._name+(t._aliases[0]?"|"+t._aliases[0]:"")+(t.options.length?" [options]":"")+(i?" "+i:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,i){return i.visibleCommands(t).reduce((s,n)=>Math.max(s,this.displayWidth(i.styleSubcommandTerm(i.subcommandTerm(n)))),0)}longestOptionTermLength(t,i){return i.visibleOptions(t).reduce((s,n)=>Math.max(s,this.displayWidth(i.styleOptionTerm(i.optionTerm(n)))),0)}longestGlobalOptionTermLength(t,i){return i.visibleGlobalOptions(t).reduce((s,n)=>Math.max(s,this.displayWidth(i.styleOptionTerm(i.optionTerm(n)))),0)}longestArgumentTermLength(t,i){return i.visibleArguments(t).reduce((s,n)=>Math.max(s,this.displayWidth(i.styleArgumentTerm(i.argumentTerm(n)))),0)}commandUsage(t){let i=t._name;t._aliases[0]&&(i=i+"|"+t._aliases[0]);let s="";for(let n=t.parent;n;n=n.parent)s=n.name()+" "+s;return s+i+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){let i=[];return t.argChoices&&i.push(`choices: ${t.argChoices.map(s=>JSON.stringify(s)).join(", ")}`),t.defaultValue!==void 0&&(t.required||t.optional||t.isBoolean()&&typeof t.defaultValue=="boolean")&&i.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),t.presetArg!==void 0&&t.optional&&i.push(`preset: ${JSON.stringify(t.presetArg)}`),t.envVar!==void 0&&i.push(`env: ${t.envVar}`),i.length>0?`${t.description} (${i.join(", ")})`:t.description}argumentDescription(t){let i=[];if(t.argChoices&&i.push(`choices: ${t.argChoices.map(s=>JSON.stringify(s)).join(", ")}`),t.defaultValue!==void 0&&i.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),i.length>0){let s=`(${i.join(", ")})`;return t.description?`${t.description} ${s}`:s}return t.description}formatHelp(t,i){let s=i.padWidth(t,i),n=i.helpWidth??80;function r(f,p){return i.formatItem(f,s,p,i)}let o=[`${i.styleTitle("Usage:")} ${i.styleUsage(i.commandUsage(t))}`,""],a=i.commandDescription(t);a.length>0&&(o=o.concat([i.boxWrap(i.styleCommandDescription(a),n),""]));let l=i.visibleArguments(t).map(f=>r(i.styleArgumentTerm(i.argumentTerm(f)),i.styleArgumentDescription(i.argumentDescription(f))));l.length>0&&(o=o.concat([i.styleTitle("Arguments:"),...l,""]));let c=i.visibleOptions(t).map(f=>r(i.styleOptionTerm(i.optionTerm(f)),i.styleOptionDescription(i.optionDescription(f))));if(c.length>0&&(o=o.concat([i.styleTitle("Options:"),...c,""])),i.showGlobalOptions){let f=i.visibleGlobalOptions(t).map(p=>r(i.styleOptionTerm(i.optionTerm(p)),i.styleOptionDescription(i.optionDescription(p))));f.length>0&&(o=o.concat([i.styleTitle("Global Options:"),...f,""]))}let u=i.visibleCommands(t).map(f=>r(i.styleSubcommandTerm(i.subcommandTerm(f)),i.styleSubcommandDescription(i.subcommandDescription(f))));return u.length>0&&(o=o.concat([i.styleTitle("Commands:"),...u,""])),o.join(`
3
+ `)}displayWidth(t){return Ys(t).length}styleTitle(t){return t}styleUsage(t){return t.split(" ").map(i=>i==="[options]"?this.styleOptionText(i):i==="[command]"?this.styleSubcommandText(i):i[0]==="["||i[0]==="<"?this.styleArgumentText(i):this.styleCommandText(i)).join(" ")}styleCommandDescription(t){return this.styleDescriptionText(t)}styleOptionDescription(t){return this.styleDescriptionText(t)}styleSubcommandDescription(t){return this.styleDescriptionText(t)}styleArgumentDescription(t){return this.styleDescriptionText(t)}styleDescriptionText(t){return t}styleOptionTerm(t){return this.styleOptionText(t)}styleSubcommandTerm(t){return t.split(" ").map(i=>i==="[options]"?this.styleOptionText(i):i[0]==="["||i[0]==="<"?this.styleArgumentText(i):this.styleSubcommandText(i)).join(" ")}styleArgumentTerm(t){return this.styleArgumentText(t)}styleOptionText(t){return t}styleArgumentText(t){return t}styleSubcommandText(t){return t}styleCommandText(t){return t}padWidth(t,i){return Math.max(i.longestOptionTermLength(t,i),i.longestGlobalOptionTermLength(t,i),i.longestSubcommandTermLength(t,i),i.longestArgumentTermLength(t,i))}preformatted(t){return/\n[^\S\r\n]/.test(t)}formatItem(t,i,s,n){let o=" ".repeat(2);if(!s)return o+t;let a=t.padEnd(i+t.length-n.displayWidth(t)),l=2,u=(this.helpWidth??80)-i-l-2,f;return u<this.minWidthToWrap||n.preformatted(s)?f=s:f=n.boxWrap(s,u).replace(/\n/g,`
4
+ `+" ".repeat(i+l)),o+a+" ".repeat(l)+f.replace(/\n/g,`
5
+ ${o}`)}boxWrap(t,i){if(i<this.minWidthToWrap)return t;let s=t.split(/\r\n|\n/),n=/[\s]*[^\s]+/g,r=[];return s.forEach(o=>{let a=o.match(n);if(a===null){r.push("");return}let l=[a.shift()],c=this.displayWidth(l[0]);a.forEach(u=>{let f=this.displayWidth(u);if(c+f<=i){l.push(u),c+=f;return}r.push(l.join(""));let p=u.trimStart();l=[p],c=this.displayWidth(p)}),r.push(l.join(""))}),r.join(`
6
+ `)}};function Ys(e){let t=/\x1b\[\d*(;\d*)*m/g;return e.replace(t,"")}Wi.Help=qi;Wi.stripColor=Ys});var zi=Ze(Gi=>{var{InvalidArgumentError:uo}=Pt(),Ji=class{constructor(t,i){this.flags=t,this.description=i||"",this.required=t.includes("<"),this.optional=t.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(t),this.mandatory=!1;let s=mo(t);this.short=s.shortFlag,this.long=s.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith("--no-")),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0}default(t,i){return this.defaultValue=t,this.defaultValueDescription=i,this}preset(t){return this.presetArg=t,this}conflicts(t){return this.conflictsWith=this.conflictsWith.concat(t),this}implies(t){let i=t;return typeof t=="string"&&(i={[t]:!0}),this.implied=Object.assign(this.implied||{},i),this}env(t){return this.envVar=t,this}argParser(t){return this.parseArg=t,this}makeOptionMandatory(t=!0){return this.mandatory=!!t,this}hideHelp(t=!0){return this.hidden=!!t,this}_concatValue(t,i){return i===this.defaultValue||!Array.isArray(i)?[t]:i.concat(t)}choices(t){return this.argChoices=t.slice(),this.parseArg=(i,s)=>{if(!this.argChoices.includes(i))throw new uo(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(i,s):i},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?Zs(this.name().replace(/^no-/,"")):Zs(this.name())}is(t){return this.short===t||this.long===t}isBoolean(){return!this.required&&!this.optional&&!this.negate}},Bi=class{constructor(t){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,t.forEach(i=>{i.negate?this.negativeOptions.set(i.attributeName(),i):this.positiveOptions.set(i.attributeName(),i)}),this.negativeOptions.forEach((i,s)=>{this.positiveOptions.has(s)&&this.dualOptions.add(s)})}valueFromOption(t,i){let s=i.attributeName();if(!this.dualOptions.has(s))return!0;let n=this.negativeOptions.get(s).presetArg,r=n!==void 0?n:!1;return i.negate===(r===t)}};function Zs(e){return e.split("-").reduce((t,i)=>t+i[0].toUpperCase()+i.slice(1))}function mo(e){let t,i,s=/^-[^-]$/,n=/^--[^-]/,r=e.split(/[ |,]+/).concat("guard");if(s.test(r[0])&&(t=r.shift()),n.test(r[0])&&(i=r.shift()),!t&&s.test(r[0])&&(t=r.shift()),!t&&n.test(r[0])&&(t=i,i=r.shift()),r[0].startsWith("-")){let o=r[0],a=`option creation failed due to '${o}' in option flags '${e}'`;throw/^-[^-][^-]/.test(o)?new Error(`${a}
7
7
  - a short flag is a single dash and a single character
8
8
  - either use a single dash and a single character (for a short flag)
9
9
  - or use a double dash for a long option (and can have two, like '--ws, --workspace')`):s.test(o)?new Error(`${a}
10
10
  - too many short flags`):n.test(o)?new Error(`${a}
11
11
  - too many long flags`):new Error(`${a}
12
- - unrecognised flag format`)}if(t===void 0&&i===void 0)throw new Error(`option creation failed due to no flags found in '${e}'.`);return{shortFlag:t,longFlag:i}}Zt.Option=zt;Zt.DualOptions=Xt});var Ui=Se(Mi=>{function Hn(e,t){if(Math.abs(e.length-t.length)>3)return Math.max(e.length,t.length);let i=[];for(let s=0;s<=e.length;s++)i[s]=[s];for(let s=0;s<=t.length;s++)i[0][s]=s;for(let s=1;s<=t.length;s++)for(let n=1;n<=e.length;n++){let r=1;e[n-1]===t[s-1]?r=0:r=1,i[n][s]=Math.min(i[n-1][s]+1,i[n][s-1]+1,i[n-1][s-1]+r),n>1&&s>1&&e[n-1]===t[s-2]&&e[n-2]===t[s-1]&&(i[n][s]=Math.min(i[n][s],i[n-2][s-2]+1))}return i[e.length][t.length]}function Jn(e,t){if(!t||t.length===0)return"";t=Array.from(new Set(t));let i=e.startsWith("--");i&&(e=e.slice(2),t=t.map(o=>o.slice(2)));let s=[],n=3,r=.4;return t.forEach(o=>{if(o.length<=1)return;let a=Hn(e,o),l=Math.max(e.length,o.length);(l-a)/l>r&&(a<n?(n=a,s=[o]):a===n&&s.push(o))}),s.sort((o,a)=>o.localeCompare(a)),i&&(s=s.map(o=>`--${o}`)),s.length>1?`
12
+ - unrecognised flag format`)}if(t===void 0&&i===void 0)throw new Error(`option creation failed due to no flags found in '${e}'.`);return{shortFlag:t,longFlag:i}}Gi.Option=Ji;Gi.DualOptions=Bi});var Qs=Ze(Xs=>{function fo(e,t){if(Math.abs(e.length-t.length)>3)return Math.max(e.length,t.length);let i=[];for(let s=0;s<=e.length;s++)i[s]=[s];for(let s=0;s<=t.length;s++)i[0][s]=s;for(let s=1;s<=t.length;s++)for(let n=1;n<=e.length;n++){let r=1;e[n-1]===t[s-1]?r=0:r=1,i[n][s]=Math.min(i[n-1][s]+1,i[n][s-1]+1,i[n-1][s-1]+r),n>1&&s>1&&e[n-1]===t[s-2]&&e[n-2]===t[s-1]&&(i[n][s]=Math.min(i[n][s],i[n-2][s-2]+1))}return i[e.length][t.length]}function ho(e,t){if(!t||t.length===0)return"";t=Array.from(new Set(t));let i=e.startsWith("--");i&&(e=e.slice(2),t=t.map(o=>o.slice(2)));let s=[],n=3,r=.4;return t.forEach(o=>{if(o.length<=1)return;let a=fo(e,o),l=Math.max(e.length,o.length);(l-a)/l>r&&(a<n?(n=a,s=[o]):a===n&&s.push(o))}),s.sort((o,a)=>o.localeCompare(a)),i&&(s=s.map(o=>`--${o}`)),s.length>1?`
13
13
  (Did you mean one of ${s.join(", ")}?)`:s.length===1?`
14
- (Did you mean ${s[0]}?)`:""}Mi.suggestSimilar=Jn});var Hi=Se(ni=>{var Gn=require("node:events").EventEmitter,ei=require("node:child_process"),ke=require("node:path"),dt=require("node:fs"),W=require("node:process"),{Argument:Bn,humanReadableArgName:Kn}=ut(),{CommanderError:ti}=Xe(),{Help:Yn,stripColor:zn}=Yt(),{Option:Li,DualOptions:Xn}=Qt(),{suggestSimilar:qi}=Ui(),ii=class e extends Gn{constructor(t){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=t||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:i=>W.stdout.write(i),writeErr:i=>W.stderr.write(i),outputError:(i,s)=>s(i),getOutHelpWidth:()=>W.stdout.isTTY?W.stdout.columns:void 0,getErrHelpWidth:()=>W.stderr.isTTY?W.stderr.columns:void 0,getOutHasColors:()=>si()??(W.stdout.isTTY&&W.stdout.hasColors?.()),getErrHasColors:()=>si()??(W.stderr.isTTY&&W.stderr.hasColors?.()),stripColor:i=>zn(i)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={}}copyInheritedSettings(t){return this._outputConfiguration=t._outputConfiguration,this._helpOption=t._helpOption,this._helpCommand=t._helpCommand,this._helpConfiguration=t._helpConfiguration,this._exitCallback=t._exitCallback,this._storeOptionsAsProperties=t._storeOptionsAsProperties,this._combineFlagAndOptionalValue=t._combineFlagAndOptionalValue,this._allowExcessArguments=t._allowExcessArguments,this._enablePositionalOptions=t._enablePositionalOptions,this._showHelpAfterError=t._showHelpAfterError,this._showSuggestionAfterError=t._showSuggestionAfterError,this}_getCommandAndAncestors(){let t=[];for(let i=this;i;i=i.parent)t.push(i);return t}command(t,i,s){let n=i,r=s;typeof n=="object"&&n!==null&&(r=n,n=null),r=r||{};let[,o,a]=t.match(/([^ ]+) *(.*)/),l=this.createCommand(o);return n&&(l.description(n),l._executableHandler=!0),r.isDefault&&(this._defaultCommandName=l._name),l._hidden=!!(r.noHelp||r.hidden),l._executableFile=r.executableFile||null,a&&l.arguments(a),this._registerCommand(l),l.parent=this,l.copyInheritedSettings(this),n?this:l}createCommand(t){return new e(t)}createHelp(){return Object.assign(new Yn,this.configureHelp())}configureHelp(t){return t===void 0?this._helpConfiguration:(this._helpConfiguration=t,this)}configureOutput(t){return t===void 0?this._outputConfiguration:(Object.assign(this._outputConfiguration,t),this)}showHelpAfterError(t=!0){return typeof t!="string"&&(t=!!t),this._showHelpAfterError=t,this}showSuggestionAfterError(t=!0){return this._showSuggestionAfterError=!!t,this}addCommand(t,i){if(!t._name)throw new Error(`Command passed to .addCommand() must have a name
15
- - specify the name in Command constructor or using .name()`);return i=i||{},i.isDefault&&(this._defaultCommandName=t._name),(i.noHelp||i.hidden)&&(t._hidden=!0),this._registerCommand(t),t.parent=this,t._checkForBrokenPassThrough(),this}createArgument(t,i){return new Bn(t,i)}argument(t,i,s,n){let r=this.createArgument(t,i);return typeof s=="function"?r.default(n).argParser(s):r.default(s),this.addArgument(r),this}arguments(t){return t.trim().split(/ +/).forEach(i=>{this.argument(i)}),this}addArgument(t){let i=this.registeredArguments.slice(-1)[0];if(i&&i.variadic)throw new Error(`only the last argument can be variadic '${i.name()}'`);if(t.required&&t.defaultValue!==void 0&&t.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${t.name()}'`);return this.registeredArguments.push(t),this}helpCommand(t,i){if(typeof t=="boolean")return this._addImplicitHelpCommand=t,this;t=t??"help [command]";let[,s,n]=t.match(/([^ ]+) *(.*)/),r=i??"display help for command",o=this.createCommand(s);return o.helpOption(!1),n&&o.arguments(n),r&&o.description(r),this._addImplicitHelpCommand=!0,this._helpCommand=o,this}addHelpCommand(t,i){return typeof t!="object"?(this.helpCommand(t,i),this):(this._addImplicitHelpCommand=!0,this._helpCommand=t,this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(this._helpCommand===void 0&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(t,i){let s=["preSubcommand","preAction","postAction"];if(!s.includes(t))throw new Error(`Unexpected value for event passed to hook : '${t}'.
16
- Expecting one of '${s.join("', '")}'`);return this._lifeCycleHooks[t]?this._lifeCycleHooks[t].push(i):this._lifeCycleHooks[t]=[i],this}exitOverride(t){return t?this._exitCallback=t:this._exitCallback=i=>{if(i.code!=="commander.executeSubCommandAsync")throw i},this}_exit(t,i,s){this._exitCallback&&this._exitCallback(new ti(t,i,s)),W.exit(t)}action(t){let i=s=>{let n=this.registeredArguments.length,r=s.slice(0,n);return this._storeOptionsAsProperties?r[n]=this:r[n]=this.opts(),r.push(this),t.apply(this,r)};return this._actionHandler=i,this}createOption(t,i){return new Li(t,i)}_callParseArg(t,i,s,n){try{return t.parseArg(i,s)}catch(r){if(r.code==="commander.invalidArgument"){let o=`${n} ${r.message}`;this.error(o,{exitCode:r.exitCode,code:r.code})}throw r}}_registerOption(t){let i=t.short&&this._findOption(t.short)||t.long&&this._findOption(t.long);if(i){let s=t.long&&this._findOption(t.long)?t.long:t.short;throw new Error(`Cannot add option '${t.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${s}'
17
- - already used by option '${i.flags}'`)}this.options.push(t)}_registerCommand(t){let i=n=>[n.name()].concat(n.aliases()),s=i(t).find(n=>this._findCommand(n));if(s){let n=i(this._findCommand(s)).join("|"),r=i(t).join("|");throw new Error(`cannot add command '${r}' as already have command '${n}'`)}this.commands.push(t)}addOption(t){this._registerOption(t);let i=t.name(),s=t.attributeName();if(t.negate){let r=t.long.replace(/^--no-/,"--");this._findOption(r)||this.setOptionValueWithSource(s,t.defaultValue===void 0?!0:t.defaultValue,"default")}else t.defaultValue!==void 0&&this.setOptionValueWithSource(s,t.defaultValue,"default");let n=(r,o,a)=>{r==null&&t.presetArg!==void 0&&(r=t.presetArg);let l=this.getOptionValue(s);r!==null&&t.parseArg?r=this._callParseArg(t,r,l,o):r!==null&&t.variadic&&(r=t._concatValue(r,l)),r==null&&(t.negate?r=!1:t.isBoolean()||t.optional?r=!0:r=""),this.setOptionValueWithSource(s,r,a)};return this.on("option:"+i,r=>{let o=`error: option '${t.flags}' argument '${r}' is invalid.`;n(r,o,"cli")}),t.envVar&&this.on("optionEnv:"+i,r=>{let o=`error: option '${t.flags}' value '${r}' from env '${t.envVar}' is invalid.`;n(r,o,"env")}),this}_optionEx(t,i,s,n,r){if(typeof i=="object"&&i instanceof Li)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let o=this.createOption(i,s);if(o.makeOptionMandatory(!!t.mandatory),typeof n=="function")o.default(r).argParser(n);else if(n instanceof RegExp){let a=n;n=(l,m)=>{let d=a.exec(l);return d?d[0]:m},o.default(r).argParser(n)}else o.default(n);return this.addOption(o)}option(t,i,s,n){return this._optionEx({},t,i,s,n)}requiredOption(t,i,s,n){return this._optionEx({mandatory:!0},t,i,s,n)}combineFlagAndOptionalValue(t=!0){return this._combineFlagAndOptionalValue=!!t,this}allowUnknownOption(t=!0){return this._allowUnknownOption=!!t,this}allowExcessArguments(t=!0){return this._allowExcessArguments=!!t,this}enablePositionalOptions(t=!0){return this._enablePositionalOptions=!!t,this}passThroughOptions(t=!0){return this._passThroughOptions=!!t,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(t=!0){if(this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw new Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!t,this}getOptionValue(t){return this._storeOptionsAsProperties?this[t]:this._optionValues[t]}setOptionValue(t,i){return this.setOptionValueWithSource(t,i,void 0)}setOptionValueWithSource(t,i,s){return this._storeOptionsAsProperties?this[t]=i:this._optionValues[t]=i,this._optionValueSources[t]=s,this}getOptionValueSource(t){return this._optionValueSources[t]}getOptionValueSourceWithGlobals(t){let i;return this._getCommandAndAncestors().forEach(s=>{s.getOptionValueSource(t)!==void 0&&(i=s.getOptionValueSource(t))}),i}_prepareUserArgs(t,i){if(t!==void 0&&!Array.isArray(t))throw new Error("first parameter to parse must be array or undefined");if(i=i||{},t===void 0&&i.from===void 0){W.versions?.electron&&(i.from="electron");let n=W.execArgv??[];(n.includes("-e")||n.includes("--eval")||n.includes("-p")||n.includes("--print"))&&(i.from="eval")}t===void 0&&(t=W.argv),this.rawArgs=t.slice();let s;switch(i.from){case void 0:case"node":this._scriptPath=t[1],s=t.slice(2);break;case"electron":W.defaultApp?(this._scriptPath=t[1],s=t.slice(2)):s=t.slice(1);break;case"user":s=t.slice(0);break;case"eval":s=t.slice(1);break;default:throw new Error(`unexpected parse option { from: '${i.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",s}parse(t,i){this._prepareForParse();let s=this._prepareUserArgs(t,i);return this._parseCommand([],s),this}async parseAsync(t,i){this._prepareForParse();let s=this._prepareUserArgs(t,i);return await this._parseCommand([],s),this}_prepareForParse(){this._savedState===null?this.saveStateBeforeParse():this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
18
- - either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(t,i,s){if(dt.existsSync(t))return;let n=i?`searched for local subcommand relative to directory '${i}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",r=`'${t}' does not exist
14
+ (Did you mean ${s[0]}?)`:""}Xs.suggestSimilar=ho});var nn=Ze(Qi=>{var po=require("node:events").EventEmitter,Ki=require("node:child_process"),Xe=require("node:path"),Zt=require("node:fs"),ee=require("node:process"),{Argument:go,humanReadableArgName:$o}=Yt(),{CommanderError:Yi}=Pt(),{Help:yo,stripColor:bo}=Hi(),{Option:en,DualOptions:vo}=zi(),{suggestSimilar:tn}=Qs(),Zi=class e extends po{constructor(t){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=t||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:i=>ee.stdout.write(i),writeErr:i=>ee.stderr.write(i),outputError:(i,s)=>s(i),getOutHelpWidth:()=>ee.stdout.isTTY?ee.stdout.columns:void 0,getErrHelpWidth:()=>ee.stderr.isTTY?ee.stderr.columns:void 0,getOutHasColors:()=>Xi()??(ee.stdout.isTTY&&ee.stdout.hasColors?.()),getErrHasColors:()=>Xi()??(ee.stderr.isTTY&&ee.stderr.hasColors?.()),stripColor:i=>bo(i)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={}}copyInheritedSettings(t){return this._outputConfiguration=t._outputConfiguration,this._helpOption=t._helpOption,this._helpCommand=t._helpCommand,this._helpConfiguration=t._helpConfiguration,this._exitCallback=t._exitCallback,this._storeOptionsAsProperties=t._storeOptionsAsProperties,this._combineFlagAndOptionalValue=t._combineFlagAndOptionalValue,this._allowExcessArguments=t._allowExcessArguments,this._enablePositionalOptions=t._enablePositionalOptions,this._showHelpAfterError=t._showHelpAfterError,this._showSuggestionAfterError=t._showSuggestionAfterError,this}_getCommandAndAncestors(){let t=[];for(let i=this;i;i=i.parent)t.push(i);return t}command(t,i,s){let n=i,r=s;typeof n=="object"&&n!==null&&(r=n,n=null),r=r||{};let[,o,a]=t.match(/([^ ]+) *(.*)/),l=this.createCommand(o);return n&&(l.description(n),l._executableHandler=!0),r.isDefault&&(this._defaultCommandName=l._name),l._hidden=!!(r.noHelp||r.hidden),l._executableFile=r.executableFile||null,a&&l.arguments(a),this._registerCommand(l),l.parent=this,l.copyInheritedSettings(this),n?this:l}createCommand(t){return new e(t)}createHelp(){return Object.assign(new yo,this.configureHelp())}configureHelp(t){return t===void 0?this._helpConfiguration:(this._helpConfiguration=t,this)}configureOutput(t){return t===void 0?this._outputConfiguration:(Object.assign(this._outputConfiguration,t),this)}showHelpAfterError(t=!0){return typeof t!="string"&&(t=!!t),this._showHelpAfterError=t,this}showSuggestionAfterError(t=!0){return this._showSuggestionAfterError=!!t,this}addCommand(t,i){if(!t._name)throw new Error(`Command passed to .addCommand() must have a name
15
+ - specify the name in Command constructor or using .name()`);return i=i||{},i.isDefault&&(this._defaultCommandName=t._name),(i.noHelp||i.hidden)&&(t._hidden=!0),this._registerCommand(t),t.parent=this,t._checkForBrokenPassThrough(),this}createArgument(t,i){return new go(t,i)}argument(t,i,s,n){let r=this.createArgument(t,i);return typeof s=="function"?r.default(n).argParser(s):r.default(s),this.addArgument(r),this}arguments(t){return t.trim().split(/ +/).forEach(i=>{this.argument(i)}),this}addArgument(t){let i=this.registeredArguments.slice(-1)[0];if(i&&i.variadic)throw new Error(`only the last argument can be variadic '${i.name()}'`);if(t.required&&t.defaultValue!==void 0&&t.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${t.name()}'`);return this.registeredArguments.push(t),this}helpCommand(t,i){if(typeof t=="boolean")return this._addImplicitHelpCommand=t,this;t=t??"help [command]";let[,s,n]=t.match(/([^ ]+) *(.*)/),r=i??"display help for command",o=this.createCommand(s);return o.helpOption(!1),n&&o.arguments(n),r&&o.description(r),this._addImplicitHelpCommand=!0,this._helpCommand=o,this}addHelpCommand(t,i){return typeof t!="object"?(this.helpCommand(t,i),this):(this._addImplicitHelpCommand=!0,this._helpCommand=t,this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(this._helpCommand===void 0&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(t,i){let s=["preSubcommand","preAction","postAction"];if(!s.includes(t))throw new Error(`Unexpected value for event passed to hook : '${t}'.
16
+ Expecting one of '${s.join("', '")}'`);return this._lifeCycleHooks[t]?this._lifeCycleHooks[t].push(i):this._lifeCycleHooks[t]=[i],this}exitOverride(t){return t?this._exitCallback=t:this._exitCallback=i=>{if(i.code!=="commander.executeSubCommandAsync")throw i},this}_exit(t,i,s){this._exitCallback&&this._exitCallback(new Yi(t,i,s)),ee.exit(t)}action(t){let i=s=>{let n=this.registeredArguments.length,r=s.slice(0,n);return this._storeOptionsAsProperties?r[n]=this:r[n]=this.opts(),r.push(this),t.apply(this,r)};return this._actionHandler=i,this}createOption(t,i){return new en(t,i)}_callParseArg(t,i,s,n){try{return t.parseArg(i,s)}catch(r){if(r.code==="commander.invalidArgument"){let o=`${n} ${r.message}`;this.error(o,{exitCode:r.exitCode,code:r.code})}throw r}}_registerOption(t){let i=t.short&&this._findOption(t.short)||t.long&&this._findOption(t.long);if(i){let s=t.long&&this._findOption(t.long)?t.long:t.short;throw new Error(`Cannot add option '${t.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${s}'
17
+ - already used by option '${i.flags}'`)}this.options.push(t)}_registerCommand(t){let i=n=>[n.name()].concat(n.aliases()),s=i(t).find(n=>this._findCommand(n));if(s){let n=i(this._findCommand(s)).join("|"),r=i(t).join("|");throw new Error(`cannot add command '${r}' as already have command '${n}'`)}this.commands.push(t)}addOption(t){this._registerOption(t);let i=t.name(),s=t.attributeName();if(t.negate){let r=t.long.replace(/^--no-/,"--");this._findOption(r)||this.setOptionValueWithSource(s,t.defaultValue===void 0?!0:t.defaultValue,"default")}else t.defaultValue!==void 0&&this.setOptionValueWithSource(s,t.defaultValue,"default");let n=(r,o,a)=>{r==null&&t.presetArg!==void 0&&(r=t.presetArg);let l=this.getOptionValue(s);r!==null&&t.parseArg?r=this._callParseArg(t,r,l,o):r!==null&&t.variadic&&(r=t._concatValue(r,l)),r==null&&(t.negate?r=!1:t.isBoolean()||t.optional?r=!0:r=""),this.setOptionValueWithSource(s,r,a)};return this.on("option:"+i,r=>{let o=`error: option '${t.flags}' argument '${r}' is invalid.`;n(r,o,"cli")}),t.envVar&&this.on("optionEnv:"+i,r=>{let o=`error: option '${t.flags}' value '${r}' from env '${t.envVar}' is invalid.`;n(r,o,"env")}),this}_optionEx(t,i,s,n,r){if(typeof i=="object"&&i instanceof en)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let o=this.createOption(i,s);if(o.makeOptionMandatory(!!t.mandatory),typeof n=="function")o.default(r).argParser(n);else if(n instanceof RegExp){let a=n;n=(l,c)=>{let u=a.exec(l);return u?u[0]:c},o.default(r).argParser(n)}else o.default(n);return this.addOption(o)}option(t,i,s,n){return this._optionEx({},t,i,s,n)}requiredOption(t,i,s,n){return this._optionEx({mandatory:!0},t,i,s,n)}combineFlagAndOptionalValue(t=!0){return this._combineFlagAndOptionalValue=!!t,this}allowUnknownOption(t=!0){return this._allowUnknownOption=!!t,this}allowExcessArguments(t=!0){return this._allowExcessArguments=!!t,this}enablePositionalOptions(t=!0){return this._enablePositionalOptions=!!t,this}passThroughOptions(t=!0){return this._passThroughOptions=!!t,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(t=!0){if(this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw new Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!t,this}getOptionValue(t){return this._storeOptionsAsProperties?this[t]:this._optionValues[t]}setOptionValue(t,i){return this.setOptionValueWithSource(t,i,void 0)}setOptionValueWithSource(t,i,s){return this._storeOptionsAsProperties?this[t]=i:this._optionValues[t]=i,this._optionValueSources[t]=s,this}getOptionValueSource(t){return this._optionValueSources[t]}getOptionValueSourceWithGlobals(t){let i;return this._getCommandAndAncestors().forEach(s=>{s.getOptionValueSource(t)!==void 0&&(i=s.getOptionValueSource(t))}),i}_prepareUserArgs(t,i){if(t!==void 0&&!Array.isArray(t))throw new Error("first parameter to parse must be array or undefined");if(i=i||{},t===void 0&&i.from===void 0){ee.versions?.electron&&(i.from="electron");let n=ee.execArgv??[];(n.includes("-e")||n.includes("--eval")||n.includes("-p")||n.includes("--print"))&&(i.from="eval")}t===void 0&&(t=ee.argv),this.rawArgs=t.slice();let s;switch(i.from){case void 0:case"node":this._scriptPath=t[1],s=t.slice(2);break;case"electron":ee.defaultApp?(this._scriptPath=t[1],s=t.slice(2)):s=t.slice(1);break;case"user":s=t.slice(0);break;case"eval":s=t.slice(1);break;default:throw new Error(`unexpected parse option { from: '${i.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",s}parse(t,i){this._prepareForParse();let s=this._prepareUserArgs(t,i);return this._parseCommand([],s),this}async parseAsync(t,i){this._prepareForParse();let s=this._prepareUserArgs(t,i);return await this._parseCommand([],s),this}_prepareForParse(){this._savedState===null?this.saveStateBeforeParse():this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
18
+ - either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(t,i,s){if(Zt.existsSync(t))return;let n=i?`searched for local subcommand relative to directory '${i}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",r=`'${t}' does not exist
19
19
  - if '${s}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
20
20
  - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
21
- - ${n}`;throw new Error(r)}_executeSubCommand(t,i){i=i.slice();let s=!1,n=[".js",".ts",".tsx",".mjs",".cjs"];function r(d,u){let y=ke.resolve(d,u);if(dt.existsSync(y))return y;if(n.includes(ke.extname(u)))return;let k=n.find(g=>dt.existsSync(`${y}${g}`));if(k)return`${y}${k}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let o=t._executableFile||`${this._name}-${t._name}`,a=this._executableDir||"";if(this._scriptPath){let d;try{d=dt.realpathSync(this._scriptPath)}catch{d=this._scriptPath}a=ke.resolve(ke.dirname(d),a)}if(a){let d=r(a,o);if(!d&&!t._executableFile&&this._scriptPath){let u=ke.basename(this._scriptPath,ke.extname(this._scriptPath));u!==this._name&&(d=r(a,`${u}-${t._name}`))}o=d||o}s=n.includes(ke.extname(o));let l;W.platform!=="win32"?s?(i.unshift(o),i=Wi(W.execArgv).concat(i),l=ei.spawn(W.argv[0],i,{stdio:"inherit"})):l=ei.spawn(o,i,{stdio:"inherit"}):(this._checkForMissingExecutable(o,a,t._name),i.unshift(o),i=Wi(W.execArgv).concat(i),l=ei.spawn(W.execPath,i,{stdio:"inherit"})),l.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(u=>{W.on(u,()=>{l.killed===!1&&l.exitCode===null&&l.kill(u)})});let m=this._exitCallback;l.on("close",d=>{d=d??1,m?m(new ti(d,"commander.executeSubCommandAsync","(close)")):W.exit(d)}),l.on("error",d=>{if(d.code==="ENOENT")this._checkForMissingExecutable(o,a,t._name);else if(d.code==="EACCES")throw new Error(`'${o}' not executable`);if(!m)W.exit(1);else{let u=new ti(1,"commander.executeSubCommandAsync","(error)");u.nestedError=d,m(u)}}),this.runningCommand=l}_dispatchSubcommand(t,i,s){let n=this._findCommand(t);n||this.help({error:!0}),n._prepareForParse();let r;return r=this._chainOrCallSubCommandHook(r,n,"preSubcommand"),r=this._chainOrCall(r,()=>{if(n._executableHandler)this._executeSubCommand(n,i.concat(s));else return n._parseCommand(i,s)}),r}_dispatchHelpCommand(t){t||this.help();let i=this._findCommand(t);return i&&!i._executableHandler&&i.help(),this._dispatchSubcommand(t,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((t,i)=>{t.required&&this.args[i]==null&&this.missingArgument(t.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let t=(s,n,r)=>{let o=n;if(n!==null&&s.parseArg){let a=`error: command-argument value '${n}' is invalid for argument '${s.name()}'.`;o=this._callParseArg(s,n,r,a)}return o};this._checkNumberOfArguments();let i=[];this.registeredArguments.forEach((s,n)=>{let r=s.defaultValue;s.variadic?n<this.args.length?(r=this.args.slice(n),s.parseArg&&(r=r.reduce((o,a)=>t(s,a,o),s.defaultValue))):r===void 0&&(r=[]):n<this.args.length&&(r=this.args[n],s.parseArg&&(r=t(s,r,s.defaultValue))),i[n]=r}),this.processedArgs=i}_chainOrCall(t,i){return t&&t.then&&typeof t.then=="function"?t.then(()=>i()):i()}_chainOrCallHooks(t,i){let s=t,n=[];return this._getCommandAndAncestors().reverse().filter(r=>r._lifeCycleHooks[i]!==void 0).forEach(r=>{r._lifeCycleHooks[i].forEach(o=>{n.push({hookedCommand:r,callback:o})})}),i==="postAction"&&n.reverse(),n.forEach(r=>{s=this._chainOrCall(s,()=>r.callback(r.hookedCommand,this))}),s}_chainOrCallSubCommandHook(t,i,s){let n=t;return this._lifeCycleHooks[s]!==void 0&&this._lifeCycleHooks[s].forEach(r=>{n=this._chainOrCall(n,()=>r(this,i))}),n}_parseCommand(t,i){let s=this.parseOptions(i);if(this._parseOptionsEnv(),this._parseOptionsImplied(),t=t.concat(s.operands),i=s.unknown,this.args=t.concat(i),t&&this._findCommand(t[0]))return this._dispatchSubcommand(t[0],t.slice(1),i);if(this._getHelpCommand()&&t[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(t[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(i),this._dispatchSubcommand(this._defaultCommandName,t,i);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(s.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let n=()=>{s.unknown.length>0&&this.unknownOption(s.unknown[0])},r=`command:${this.name()}`;if(this._actionHandler){n(),this._processArguments();let o;return o=this._chainOrCallHooks(o,"preAction"),o=this._chainOrCall(o,()=>this._actionHandler(this.processedArgs)),this.parent&&(o=this._chainOrCall(o,()=>{this.parent.emit(r,t,i)})),o=this._chainOrCallHooks(o,"postAction"),o}if(this.parent&&this.parent.listenerCount(r))n(),this._processArguments(),this.parent.emit(r,t,i);else if(t.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",t,i);this.listenerCount("command:*")?this.emit("command:*",t,i):this.commands.length?this.unknownCommand():(n(),this._processArguments())}else this.commands.length?(n(),this.help({error:!0})):(n(),this._processArguments())}_findCommand(t){if(t)return this.commands.find(i=>i._name===t||i._aliases.includes(t))}_findOption(t){return this.options.find(i=>i.is(t))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(t=>{t.options.forEach(i=>{i.mandatory&&t.getOptionValue(i.attributeName())===void 0&&t.missingMandatoryOptionValue(i)})})}_checkForConflictingLocalOptions(){let t=this.options.filter(s=>{let n=s.attributeName();return this.getOptionValue(n)===void 0?!1:this.getOptionValueSource(n)!=="default"});t.filter(s=>s.conflictsWith.length>0).forEach(s=>{let n=t.find(r=>s.conflictsWith.includes(r.attributeName()));n&&this._conflictingOption(s,n)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(t=>{t._checkForConflictingLocalOptions()})}parseOptions(t){let i=[],s=[],n=i,r=t.slice();function o(l){return l.length>1&&l[0]==="-"}let a=null;for(;r.length;){let l=r.shift();if(l==="--"){n===s&&n.push(l),n.push(...r);break}if(a&&!o(l)){this.emit(`option:${a.name()}`,l);continue}if(a=null,o(l)){let m=this._findOption(l);if(m){if(m.required){let d=r.shift();d===void 0&&this.optionMissingArgument(m),this.emit(`option:${m.name()}`,d)}else if(m.optional){let d=null;r.length>0&&!o(r[0])&&(d=r.shift()),this.emit(`option:${m.name()}`,d)}else this.emit(`option:${m.name()}`);a=m.variadic?m:null;continue}}if(l.length>2&&l[0]==="-"&&l[1]!=="-"){let m=this._findOption(`-${l[1]}`);if(m){m.required||m.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${m.name()}`,l.slice(2)):(this.emit(`option:${m.name()}`),r.unshift(`-${l.slice(2)}`));continue}}if(/^--[^=]+=/.test(l)){let m=l.indexOf("="),d=this._findOption(l.slice(0,m));if(d&&(d.required||d.optional)){this.emit(`option:${d.name()}`,l.slice(m+1));continue}}if(o(l)&&(n=s),(this._enablePositionalOptions||this._passThroughOptions)&&i.length===0&&s.length===0){if(this._findCommand(l)){i.push(l),r.length>0&&s.push(...r);break}else if(this._getHelpCommand()&&l===this._getHelpCommand().name()){i.push(l),r.length>0&&i.push(...r);break}else if(this._defaultCommandName){s.push(l),r.length>0&&s.push(...r);break}}if(this._passThroughOptions){n.push(l),r.length>0&&n.push(...r);break}n.push(l)}return{operands:i,unknown:s}}opts(){if(this._storeOptionsAsProperties){let t={},i=this.options.length;for(let s=0;s<i;s++){let n=this.options[s].attributeName();t[n]=n===this._versionOptionName?this._version:this[n]}return t}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((t,i)=>Object.assign(t,i.opts()),{})}error(t,i){this._outputConfiguration.outputError(`${t}
21
+ - ${n}`;throw new Error(r)}_executeSubCommand(t,i){i=i.slice();let s=!1,n=[".js",".ts",".tsx",".mjs",".cjs"];function r(u,f){let p=Xe.resolve(u,f);if(Zt.existsSync(p))return p;if(n.includes(Xe.extname(f)))return;let v=n.find($=>Zt.existsSync(`${p}${$}`));if(v)return`${p}${v}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let o=t._executableFile||`${this._name}-${t._name}`,a=this._executableDir||"";if(this._scriptPath){let u;try{u=Zt.realpathSync(this._scriptPath)}catch{u=this._scriptPath}a=Xe.resolve(Xe.dirname(u),a)}if(a){let u=r(a,o);if(!u&&!t._executableFile&&this._scriptPath){let f=Xe.basename(this._scriptPath,Xe.extname(this._scriptPath));f!==this._name&&(u=r(a,`${f}-${t._name}`))}o=u||o}s=n.includes(Xe.extname(o));let l;ee.platform!=="win32"?s?(i.unshift(o),i=sn(ee.execArgv).concat(i),l=Ki.spawn(ee.argv[0],i,{stdio:"inherit"})):l=Ki.spawn(o,i,{stdio:"inherit"}):(this._checkForMissingExecutable(o,a,t._name),i.unshift(o),i=sn(ee.execArgv).concat(i),l=Ki.spawn(ee.execPath,i,{stdio:"inherit"})),l.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(f=>{ee.on(f,()=>{l.killed===!1&&l.exitCode===null&&l.kill(f)})});let c=this._exitCallback;l.on("close",u=>{u=u??1,c?c(new Yi(u,"commander.executeSubCommandAsync","(close)")):ee.exit(u)}),l.on("error",u=>{if(u.code==="ENOENT")this._checkForMissingExecutable(o,a,t._name);else if(u.code==="EACCES")throw new Error(`'${o}' not executable`);if(!c)ee.exit(1);else{let f=new Yi(1,"commander.executeSubCommandAsync","(error)");f.nestedError=u,c(f)}}),this.runningCommand=l}_dispatchSubcommand(t,i,s){let n=this._findCommand(t);n||this.help({error:!0}),n._prepareForParse();let r;return r=this._chainOrCallSubCommandHook(r,n,"preSubcommand"),r=this._chainOrCall(r,()=>{if(n._executableHandler)this._executeSubCommand(n,i.concat(s));else return n._parseCommand(i,s)}),r}_dispatchHelpCommand(t){t||this.help();let i=this._findCommand(t);return i&&!i._executableHandler&&i.help(),this._dispatchSubcommand(t,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((t,i)=>{t.required&&this.args[i]==null&&this.missingArgument(t.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let t=(s,n,r)=>{let o=n;if(n!==null&&s.parseArg){let a=`error: command-argument value '${n}' is invalid for argument '${s.name()}'.`;o=this._callParseArg(s,n,r,a)}return o};this._checkNumberOfArguments();let i=[];this.registeredArguments.forEach((s,n)=>{let r=s.defaultValue;s.variadic?n<this.args.length?(r=this.args.slice(n),s.parseArg&&(r=r.reduce((o,a)=>t(s,a,o),s.defaultValue))):r===void 0&&(r=[]):n<this.args.length&&(r=this.args[n],s.parseArg&&(r=t(s,r,s.defaultValue))),i[n]=r}),this.processedArgs=i}_chainOrCall(t,i){return t&&t.then&&typeof t.then=="function"?t.then(()=>i()):i()}_chainOrCallHooks(t,i){let s=t,n=[];return this._getCommandAndAncestors().reverse().filter(r=>r._lifeCycleHooks[i]!==void 0).forEach(r=>{r._lifeCycleHooks[i].forEach(o=>{n.push({hookedCommand:r,callback:o})})}),i==="postAction"&&n.reverse(),n.forEach(r=>{s=this._chainOrCall(s,()=>r.callback(r.hookedCommand,this))}),s}_chainOrCallSubCommandHook(t,i,s){let n=t;return this._lifeCycleHooks[s]!==void 0&&this._lifeCycleHooks[s].forEach(r=>{n=this._chainOrCall(n,()=>r(this,i))}),n}_parseCommand(t,i){let s=this.parseOptions(i);if(this._parseOptionsEnv(),this._parseOptionsImplied(),t=t.concat(s.operands),i=s.unknown,this.args=t.concat(i),t&&this._findCommand(t[0]))return this._dispatchSubcommand(t[0],t.slice(1),i);if(this._getHelpCommand()&&t[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(t[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(i),this._dispatchSubcommand(this._defaultCommandName,t,i);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(s.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let n=()=>{s.unknown.length>0&&this.unknownOption(s.unknown[0])},r=`command:${this.name()}`;if(this._actionHandler){n(),this._processArguments();let o;return o=this._chainOrCallHooks(o,"preAction"),o=this._chainOrCall(o,()=>this._actionHandler(this.processedArgs)),this.parent&&(o=this._chainOrCall(o,()=>{this.parent.emit(r,t,i)})),o=this._chainOrCallHooks(o,"postAction"),o}if(this.parent&&this.parent.listenerCount(r))n(),this._processArguments(),this.parent.emit(r,t,i);else if(t.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",t,i);this.listenerCount("command:*")?this.emit("command:*",t,i):this.commands.length?this.unknownCommand():(n(),this._processArguments())}else this.commands.length?(n(),this.help({error:!0})):(n(),this._processArguments())}_findCommand(t){if(t)return this.commands.find(i=>i._name===t||i._aliases.includes(t))}_findOption(t){return this.options.find(i=>i.is(t))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(t=>{t.options.forEach(i=>{i.mandatory&&t.getOptionValue(i.attributeName())===void 0&&t.missingMandatoryOptionValue(i)})})}_checkForConflictingLocalOptions(){let t=this.options.filter(s=>{let n=s.attributeName();return this.getOptionValue(n)===void 0?!1:this.getOptionValueSource(n)!=="default"});t.filter(s=>s.conflictsWith.length>0).forEach(s=>{let n=t.find(r=>s.conflictsWith.includes(r.attributeName()));n&&this._conflictingOption(s,n)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(t=>{t._checkForConflictingLocalOptions()})}parseOptions(t){let i=[],s=[],n=i,r=t.slice();function o(l){return l.length>1&&l[0]==="-"}let a=null;for(;r.length;){let l=r.shift();if(l==="--"){n===s&&n.push(l),n.push(...r);break}if(a&&!o(l)){this.emit(`option:${a.name()}`,l);continue}if(a=null,o(l)){let c=this._findOption(l);if(c){if(c.required){let u=r.shift();u===void 0&&this.optionMissingArgument(c),this.emit(`option:${c.name()}`,u)}else if(c.optional){let u=null;r.length>0&&!o(r[0])&&(u=r.shift()),this.emit(`option:${c.name()}`,u)}else this.emit(`option:${c.name()}`);a=c.variadic?c:null;continue}}if(l.length>2&&l[0]==="-"&&l[1]!=="-"){let c=this._findOption(`-${l[1]}`);if(c){c.required||c.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${c.name()}`,l.slice(2)):(this.emit(`option:${c.name()}`),r.unshift(`-${l.slice(2)}`));continue}}if(/^--[^=]+=/.test(l)){let c=l.indexOf("="),u=this._findOption(l.slice(0,c));if(u&&(u.required||u.optional)){this.emit(`option:${u.name()}`,l.slice(c+1));continue}}if(o(l)&&(n=s),(this._enablePositionalOptions||this._passThroughOptions)&&i.length===0&&s.length===0){if(this._findCommand(l)){i.push(l),r.length>0&&s.push(...r);break}else if(this._getHelpCommand()&&l===this._getHelpCommand().name()){i.push(l),r.length>0&&i.push(...r);break}else if(this._defaultCommandName){s.push(l),r.length>0&&s.push(...r);break}}if(this._passThroughOptions){n.push(l),r.length>0&&n.push(...r);break}n.push(l)}return{operands:i,unknown:s}}opts(){if(this._storeOptionsAsProperties){let t={},i=this.options.length;for(let s=0;s<i;s++){let n=this.options[s].attributeName();t[n]=n===this._versionOptionName?this._version:this[n]}return t}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((t,i)=>Object.assign(t,i.opts()),{})}error(t,i){this._outputConfiguration.outputError(`${t}
22
22
  `,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
23
23
  `):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
24
- `),this.outputHelp({error:!0}));let s=i||{},n=s.exitCode||1,r=s.code||"commander.error";this._exit(n,r,t)}_parseOptionsEnv(){this.options.forEach(t=>{if(t.envVar&&t.envVar in W.env){let i=t.attributeName();(this.getOptionValue(i)===void 0||["default","config","env"].includes(this.getOptionValueSource(i)))&&(t.required||t.optional?this.emit(`optionEnv:${t.name()}`,W.env[t.envVar]):this.emit(`optionEnv:${t.name()}`))}})}_parseOptionsImplied(){let t=new Xn(this.options),i=s=>this.getOptionValue(s)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(s));this.options.filter(s=>s.implied!==void 0&&i(s.attributeName())&&t.valueFromOption(this.getOptionValue(s.attributeName()),s)).forEach(s=>{Object.keys(s.implied).filter(n=>!i(n)).forEach(n=>{this.setOptionValueWithSource(n,s.implied[n],"implied")})})}missingArgument(t){let i=`error: missing required argument '${t}'`;this.error(i,{code:"commander.missingArgument"})}optionMissingArgument(t){let i=`error: option '${t.flags}' argument missing`;this.error(i,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(t){let i=`error: required option '${t.flags}' not specified`;this.error(i,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(t,i){let s=o=>{let a=o.attributeName(),l=this.getOptionValue(a),m=this.options.find(u=>u.negate&&a===u.attributeName()),d=this.options.find(u=>!u.negate&&a===u.attributeName());return m&&(m.presetArg===void 0&&l===!1||m.presetArg!==void 0&&l===m.presetArg)?m:d||o},n=o=>{let a=s(o),l=a.attributeName();return this.getOptionValueSource(l)==="env"?`environment variable '${a.envVar}'`:`option '${a.flags}'`},r=`error: ${n(t)} cannot be used with ${n(i)}`;this.error(r,{code:"commander.conflictingOption"})}unknownOption(t){if(this._allowUnknownOption)return;let i="";if(t.startsWith("--")&&this._showSuggestionAfterError){let n=[],r=this;do{let o=r.createHelp().visibleOptions(r).filter(a=>a.long).map(a=>a.long);n=n.concat(o),r=r.parent}while(r&&!r._enablePositionalOptions);i=qi(t,n)}let s=`error: unknown option '${t}'${i}`;this.error(s,{code:"commander.unknownOption"})}_excessArguments(t){if(this._allowExcessArguments)return;let i=this.registeredArguments.length,s=i===1?"":"s",r=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${i} argument${s} but got ${t.length}.`;this.error(r,{code:"commander.excessArguments"})}unknownCommand(){let t=this.args[0],i="";if(this._showSuggestionAfterError){let n=[];this.createHelp().visibleCommands(this).forEach(r=>{n.push(r.name()),r.alias()&&n.push(r.alias())}),i=qi(t,n)}let s=`error: unknown command '${t}'${i}`;this.error(s,{code:"commander.unknownCommand"})}version(t,i,s){if(t===void 0)return this._version;this._version=t,i=i||"-V, --version",s=s||"output the version number";let n=this.createOption(i,s);return this._versionOptionName=n.attributeName(),this._registerOption(n),this.on("option:"+n.name(),()=>{this._outputConfiguration.writeOut(`${t}
25
- `),this._exit(0,"commander.version",t)}),this}description(t,i){return t===void 0&&i===void 0?this._description:(this._description=t,i&&(this._argsDescription=i),this)}summary(t){return t===void 0?this._summary:(this._summary=t,this)}alias(t){if(t===void 0)return this._aliases[0];let i=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(i=this.commands[this.commands.length-1]),t===i._name)throw new Error("Command alias can't be the same as its name");let s=this.parent?._findCommand(t);if(s){let n=[s.name()].concat(s.aliases()).join("|");throw new Error(`cannot add alias '${t}' to command '${this.name()}' as already have command '${n}'`)}return i._aliases.push(t),this}aliases(t){return t===void 0?this._aliases:(t.forEach(i=>this.alias(i)),this)}usage(t){if(t===void 0){if(this._usage)return this._usage;let i=this.registeredArguments.map(s=>Kn(s));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?i:[]).join(" ")}return this._usage=t,this}name(t){return t===void 0?this._name:(this._name=t,this)}nameFromFilename(t){return this._name=ke.basename(t,ke.extname(t)),this}executableDir(t){return t===void 0?this._executableDir:(this._executableDir=t,this)}helpInformation(t){let i=this.createHelp(),s=this._getOutputContext(t);i.prepareContext({error:s.error,helpWidth:s.helpWidth,outputHasColors:s.hasColors});let n=i.formatHelp(this,i);return s.hasColors?n:this._outputConfiguration.stripColor(n)}_getOutputContext(t){t=t||{};let i=!!t.error,s,n,r;return i?(s=a=>this._outputConfiguration.writeErr(a),n=this._outputConfiguration.getErrHasColors(),r=this._outputConfiguration.getErrHelpWidth()):(s=a=>this._outputConfiguration.writeOut(a),n=this._outputConfiguration.getOutHasColors(),r=this._outputConfiguration.getOutHelpWidth()),{error:i,write:a=>(n||(a=this._outputConfiguration.stripColor(a)),s(a)),hasColors:n,helpWidth:r}}outputHelp(t){let i;typeof t=="function"&&(i=t,t=void 0);let s=this._getOutputContext(t),n={error:s.error,write:s.write,command:this};this._getCommandAndAncestors().reverse().forEach(o=>o.emit("beforeAllHelp",n)),this.emit("beforeHelp",n);let r=this.helpInformation({error:s.error});if(i&&(r=i(r),typeof r!="string"&&!Buffer.isBuffer(r)))throw new Error("outputHelp callback must return a string or a Buffer");s.write(r),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",n),this._getCommandAndAncestors().forEach(o=>o.emit("afterAllHelp",n))}helpOption(t,i){return typeof t=="boolean"?(t?this._helpOption=this._helpOption??void 0:this._helpOption=null,this):(t=t??"-h, --help",i=i??"display help for command",this._helpOption=this.createOption(t,i),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(t){return this._helpOption=t,this}help(t){this.outputHelp(t);let i=Number(W.exitCode??0);i===0&&t&&typeof t!="function"&&t.error&&(i=1),this._exit(i,"commander.help","(outputHelp)")}addHelpText(t,i){let s=["beforeAll","before","after","afterAll"];if(!s.includes(t))throw new Error(`Unexpected value for position to addHelpText.
24
+ `),this.outputHelp({error:!0}));let s=i||{},n=s.exitCode||1,r=s.code||"commander.error";this._exit(n,r,t)}_parseOptionsEnv(){this.options.forEach(t=>{if(t.envVar&&t.envVar in ee.env){let i=t.attributeName();(this.getOptionValue(i)===void 0||["default","config","env"].includes(this.getOptionValueSource(i)))&&(t.required||t.optional?this.emit(`optionEnv:${t.name()}`,ee.env[t.envVar]):this.emit(`optionEnv:${t.name()}`))}})}_parseOptionsImplied(){let t=new vo(this.options),i=s=>this.getOptionValue(s)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(s));this.options.filter(s=>s.implied!==void 0&&i(s.attributeName())&&t.valueFromOption(this.getOptionValue(s.attributeName()),s)).forEach(s=>{Object.keys(s.implied).filter(n=>!i(n)).forEach(n=>{this.setOptionValueWithSource(n,s.implied[n],"implied")})})}missingArgument(t){let i=`error: missing required argument '${t}'`;this.error(i,{code:"commander.missingArgument"})}optionMissingArgument(t){let i=`error: option '${t.flags}' argument missing`;this.error(i,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(t){let i=`error: required option '${t.flags}' not specified`;this.error(i,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(t,i){let s=o=>{let a=o.attributeName(),l=this.getOptionValue(a),c=this.options.find(f=>f.negate&&a===f.attributeName()),u=this.options.find(f=>!f.negate&&a===f.attributeName());return c&&(c.presetArg===void 0&&l===!1||c.presetArg!==void 0&&l===c.presetArg)?c:u||o},n=o=>{let a=s(o),l=a.attributeName();return this.getOptionValueSource(l)==="env"?`environment variable '${a.envVar}'`:`option '${a.flags}'`},r=`error: ${n(t)} cannot be used with ${n(i)}`;this.error(r,{code:"commander.conflictingOption"})}unknownOption(t){if(this._allowUnknownOption)return;let i="";if(t.startsWith("--")&&this._showSuggestionAfterError){let n=[],r=this;do{let o=r.createHelp().visibleOptions(r).filter(a=>a.long).map(a=>a.long);n=n.concat(o),r=r.parent}while(r&&!r._enablePositionalOptions);i=tn(t,n)}let s=`error: unknown option '${t}'${i}`;this.error(s,{code:"commander.unknownOption"})}_excessArguments(t){if(this._allowExcessArguments)return;let i=this.registeredArguments.length,s=i===1?"":"s",r=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${i} argument${s} but got ${t.length}.`;this.error(r,{code:"commander.excessArguments"})}unknownCommand(){let t=this.args[0],i="";if(this._showSuggestionAfterError){let n=[];this.createHelp().visibleCommands(this).forEach(r=>{n.push(r.name()),r.alias()&&n.push(r.alias())}),i=tn(t,n)}let s=`error: unknown command '${t}'${i}`;this.error(s,{code:"commander.unknownCommand"})}version(t,i,s){if(t===void 0)return this._version;this._version=t,i=i||"-V, --version",s=s||"output the version number";let n=this.createOption(i,s);return this._versionOptionName=n.attributeName(),this._registerOption(n),this.on("option:"+n.name(),()=>{this._outputConfiguration.writeOut(`${t}
25
+ `),this._exit(0,"commander.version",t)}),this}description(t,i){return t===void 0&&i===void 0?this._description:(this._description=t,i&&(this._argsDescription=i),this)}summary(t){return t===void 0?this._summary:(this._summary=t,this)}alias(t){if(t===void 0)return this._aliases[0];let i=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(i=this.commands[this.commands.length-1]),t===i._name)throw new Error("Command alias can't be the same as its name");let s=this.parent?._findCommand(t);if(s){let n=[s.name()].concat(s.aliases()).join("|");throw new Error(`cannot add alias '${t}' to command '${this.name()}' as already have command '${n}'`)}return i._aliases.push(t),this}aliases(t){return t===void 0?this._aliases:(t.forEach(i=>this.alias(i)),this)}usage(t){if(t===void 0){if(this._usage)return this._usage;let i=this.registeredArguments.map(s=>$o(s));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?i:[]).join(" ")}return this._usage=t,this}name(t){return t===void 0?this._name:(this._name=t,this)}nameFromFilename(t){return this._name=Xe.basename(t,Xe.extname(t)),this}executableDir(t){return t===void 0?this._executableDir:(this._executableDir=t,this)}helpInformation(t){let i=this.createHelp(),s=this._getOutputContext(t);i.prepareContext({error:s.error,helpWidth:s.helpWidth,outputHasColors:s.hasColors});let n=i.formatHelp(this,i);return s.hasColors?n:this._outputConfiguration.stripColor(n)}_getOutputContext(t){t=t||{};let i=!!t.error,s,n,r;return i?(s=a=>this._outputConfiguration.writeErr(a),n=this._outputConfiguration.getErrHasColors(),r=this._outputConfiguration.getErrHelpWidth()):(s=a=>this._outputConfiguration.writeOut(a),n=this._outputConfiguration.getOutHasColors(),r=this._outputConfiguration.getOutHelpWidth()),{error:i,write:a=>(n||(a=this._outputConfiguration.stripColor(a)),s(a)),hasColors:n,helpWidth:r}}outputHelp(t){let i;typeof t=="function"&&(i=t,t=void 0);let s=this._getOutputContext(t),n={error:s.error,write:s.write,command:this};this._getCommandAndAncestors().reverse().forEach(o=>o.emit("beforeAllHelp",n)),this.emit("beforeHelp",n);let r=this.helpInformation({error:s.error});if(i&&(r=i(r),typeof r!="string"&&!Buffer.isBuffer(r)))throw new Error("outputHelp callback must return a string or a Buffer");s.write(r),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",n),this._getCommandAndAncestors().forEach(o=>o.emit("afterAllHelp",n))}helpOption(t,i){return typeof t=="boolean"?(t?this._helpOption=this._helpOption??void 0:this._helpOption=null,this):(t=t??"-h, --help",i=i??"display help for command",this._helpOption=this.createOption(t,i),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(t){return this._helpOption=t,this}help(t){this.outputHelp(t);let i=Number(ee.exitCode??0);i===0&&t&&typeof t!="function"&&t.error&&(i=1),this._exit(i,"commander.help","(outputHelp)")}addHelpText(t,i){let s=["beforeAll","before","after","afterAll"];if(!s.includes(t))throw new Error(`Unexpected value for position to addHelpText.
26
26
  Expecting one of '${s.join("', '")}'`);let n=`${t}Help`;return this.on(n,r=>{let o;typeof i=="function"?o=i({error:r.error,command:r.command}):o=i,o&&r.write(`${o}
27
- `)}),this}_outputHelpIfRequested(t){let i=this._getHelpOption();i&&t.find(n=>i.is(n))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}};function Wi(e){return e.map(t=>{if(!t.startsWith("--inspect"))return t;let i,s="127.0.0.1",n="9229",r;return(r=t.match(/^(--inspect(-brk)?)$/))!==null?i=r[1]:(r=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(i=r[1],/^\d+$/.test(r[3])?n=r[3]:s=r[3]):(r=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(i=r[1],s=r[3],n=r[4]),i&&n!=="0"?`${i}=${s}:${parseInt(n)+1}`:t})}function si(){if(W.env.NO_COLOR||W.env.FORCE_COLOR==="0"||W.env.FORCE_COLOR==="false")return!1;if(W.env.FORCE_COLOR||W.env.CLICOLOR_FORCE!==void 0)return!0}ni.Command=ii;ni.useColor=si});var Ki=Se(me=>{var{Argument:Ji}=ut(),{Command:ri}=Hi(),{CommanderError:Zn,InvalidArgumentError:Gi}=Xe(),{Help:Qn}=Yt(),{Option:Bi}=Qt();me.program=new ri;me.createCommand=e=>new ri(e);me.createOption=(e,t)=>new Bi(e,t);me.createArgument=(e,t)=>new Ji(e,t);me.Command=ri;me.Option=Bi;me.Argument=Ji;me.Help=Qn;me.CommanderError=Zn;me.InvalidArgumentError=Gi;me.InvalidOptionArgumentError=Gi});var U=Se((ma,oi)=>{var ft=process||{},Xi=ft.argv||[],mt=ft.env||{},er=!(mt.NO_COLOR||Xi.includes("--no-color"))&&(!!mt.FORCE_COLOR||Xi.includes("--color")||ft.platform==="win32"||(ft.stdout||{}).isTTY&&mt.TERM!=="dumb"||!!mt.CI),tr=(e,t,i=e)=>s=>{let n=""+s,r=n.indexOf(t,e.length);return~r?e+ir(n,t,i,r)+t:e+n+t},ir=(e,t,i,s)=>{let n="",r=0;do n+=e.substring(r,s)+i,r=s+t.length,s=e.indexOf(t,r);while(~s);return n+e.substring(r)},Zi=(e=er)=>{let t=e?tr:()=>String;return{isColorSupported:e,reset:t("\x1B[0m","\x1B[0m"),bold:t("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:t("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:t("\x1B[3m","\x1B[23m"),underline:t("\x1B[4m","\x1B[24m"),inverse:t("\x1B[7m","\x1B[27m"),hidden:t("\x1B[8m","\x1B[28m"),strikethrough:t("\x1B[9m","\x1B[29m"),black:t("\x1B[30m","\x1B[39m"),red:t("\x1B[31m","\x1B[39m"),green:t("\x1B[32m","\x1B[39m"),yellow:t("\x1B[33m","\x1B[39m"),blue:t("\x1B[34m","\x1B[39m"),magenta:t("\x1B[35m","\x1B[39m"),cyan:t("\x1B[36m","\x1B[39m"),white:t("\x1B[37m","\x1B[39m"),gray:t("\x1B[90m","\x1B[39m"),bgBlack:t("\x1B[40m","\x1B[49m"),bgRed:t("\x1B[41m","\x1B[49m"),bgGreen:t("\x1B[42m","\x1B[49m"),bgYellow:t("\x1B[43m","\x1B[49m"),bgBlue:t("\x1B[44m","\x1B[49m"),bgMagenta:t("\x1B[45m","\x1B[49m"),bgCyan:t("\x1B[46m","\x1B[49m"),bgWhite:t("\x1B[47m","\x1B[49m"),blackBright:t("\x1B[90m","\x1B[39m"),redBright:t("\x1B[91m","\x1B[39m"),greenBright:t("\x1B[92m","\x1B[39m"),yellowBright:t("\x1B[93m","\x1B[39m"),blueBright:t("\x1B[94m","\x1B[39m"),magentaBright:t("\x1B[95m","\x1B[39m"),cyanBright:t("\x1B[96m","\x1B[39m"),whiteBright:t("\x1B[97m","\x1B[39m"),bgBlackBright:t("\x1B[100m","\x1B[49m"),bgRedBright:t("\x1B[101m","\x1B[49m"),bgGreenBright:t("\x1B[102m","\x1B[49m"),bgYellowBright:t("\x1B[103m","\x1B[49m"),bgBlueBright:t("\x1B[104m","\x1B[49m"),bgMagentaBright:t("\x1B[105m","\x1B[49m"),bgCyanBright:t("\x1B[106m","\x1B[49m"),bgWhiteBright:t("\x1B[107m","\x1B[49m")}};oi.exports=Zi();oi.exports.createColors=Zi});var ci=Se((ga,ls)=>{"use strict";var li={to(e,t){return t?`\x1B[${t+1};${e+1}H`:`\x1B[${e+1}G`},move(e,t){let i="";return e<0?i+=`\x1B[${-e}D`:e>0&&(i+=`\x1B[${e}C`),t<0?i+=`\x1B[${-t}A`:t>0&&(i+=`\x1B[${t}B`),i},up:(e=1)=>`\x1B[${e}A`,down:(e=1)=>`\x1B[${e}B`,forward:(e=1)=>`\x1B[${e}C`,backward:(e=1)=>`\x1B[${e}D`,nextLine:(e=1)=>"\x1B[E".repeat(e),prevLine:(e=1)=>"\x1B[F".repeat(e),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},or={up:(e=1)=>"\x1B[S".repeat(e),down:(e=1)=>"\x1B[T".repeat(e)},ar={screen:"\x1B[2J",up:(e=1)=>"\x1B[1J".repeat(e),down:(e=1)=>"\x1B[J".repeat(e),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(e){let t="";for(let i=0;i<e;i++)t+=this.line+(i<e-1?li.up():"");return e&&(t+=li.left),t}};ls.exports={cursor:li,scroll:or,erase:ar,beep:"\x07"}});var Yi=P(Ki(),1),{program:ta,createCommand:ia,createArgument:sa,createOption:na,CommanderError:ra,InvalidArgumentError:oa,InvalidOptionArgumentError:aa,Command:zi,Argument:la,Option:ca,Help:ua}=Yi.default;var Fe=P(U(),1);var Ee=P(require("fs"),1),pt=P(require("path"),1),es=P(require("os"),1);var Be="domani.run",Qi=`https://${Be}`;var gt=pt.default.join(es.default.homedir(),".domani"),ai=pt.default.join(gt,"config.json"),ts;function is(e){ts=e}var ss=pt.default.join(gt,"version-check.json"),sr=1440*60*1e3;function Me(){try{let e=Ee.default.readFileSync(ai,"utf-8");return JSON.parse(e)}catch{return{}}}function ns(e){Ee.default.mkdirSync(gt,{recursive:!0,mode:448}),Ee.default.writeFileSync(ai,JSON.stringify(e,null,2),{mode:384})}function rs(){try{Ee.default.unlinkSync(ai)}catch{}}function Te(){return ts||Me().api_url||Qi}function Ze(){return process.env.DOMANI_API_KEY||Me().token}function os(){let e=Ze();return e||(process.argv.includes("--json")||!process.stdout.isTTY?console.log(JSON.stringify({error:"Not logged in",code:"auth_required",hint:"Run 'domani login' or set DOMANI_API_KEY environment variable",fix_command:"domani login"},null,2)):console.error("Not logged in. Run: domani login"),process.exit(1)),e}var te="0.3.9";function nr(){try{let e=Ee.default.readFileSync(ss,"utf-8");return JSON.parse(e)}catch{return null}}function rr(e){try{Ee.default.mkdirSync(gt,{recursive:!0,mode:448}),Ee.default.writeFileSync(ss,JSON.stringify(e),{mode:384})}catch{}}function ht(e,t){let i=e.split(".").map(Number),s=t.split(".").map(Number);for(let n=0;n<3;n++){if((i[n]||0)>(s[n]||0))return 1;if((i[n]||0)<(s[n]||0))return-1}return 0}async function as(){let e=nr();if(e&&Date.now()-e.checkedAt<sr)return ht(e.version,te)>0?{update:e.version,forced:ht(te,e.min)<0}:null;try{let t=Te(),i=await fetch(`${t}/api/cli/version`,{signal:AbortSignal.timeout(3e3)});if(!i.ok)return null;let s=await i.json();if(rr({version:s.version,min:s.min,checkedAt:Date.now()}),ht(s.version,te)>0)return{update:s.version,forced:ht(te,s.min)<0}}catch{}return null}var We=P(U(),1);var N=P(U(),1),Es=require("child_process");var ms=require("node:util"),Ue=require("node:process"),Pe=P(require("node:readline"),1),fs=P(require("node:readline"),1),re=P(ci(),1),fi=require("node:tty");function wt(e,t,i){if(!i.some(o=>!o.disabled))return e;let s=e+t,n=Math.max(i.length-1,0),r=s<0?n:s>n?0:s;return i[r].disabled?wt(r,t<0?-1:1,i):r}var lr=e=>e===161||e===164||e===167||e===168||e===170||e===173||e===174||e>=176&&e<=180||e>=182&&e<=186||e>=188&&e<=191||e===198||e===208||e===215||e===216||e>=222&&e<=225||e===230||e>=232&&e<=234||e===236||e===237||e===240||e===242||e===243||e>=247&&e<=250||e===252||e===254||e===257||e===273||e===275||e===283||e===294||e===295||e===299||e>=305&&e<=307||e===312||e>=319&&e<=322||e===324||e>=328&&e<=331||e===333||e===338||e===339||e===358||e===359||e===363||e===462||e===464||e===466||e===468||e===470||e===472||e===474||e===476||e===593||e===609||e===708||e===711||e>=713&&e<=715||e===717||e===720||e>=728&&e<=731||e===733||e===735||e>=768&&e<=879||e>=913&&e<=929||e>=931&&e<=937||e>=945&&e<=961||e>=963&&e<=969||e===1025||e>=1040&&e<=1103||e===1105||e===8208||e>=8211&&e<=8214||e===8216||e===8217||e===8220||e===8221||e>=8224&&e<=8226||e>=8228&&e<=8231||e===8240||e===8242||e===8243||e===8245||e===8251||e===8254||e===8308||e===8319||e>=8321&&e<=8324||e===8364||e===8451||e===8453||e===8457||e===8467||e===8470||e===8481||e===8482||e===8486||e===8491||e===8531||e===8532||e>=8539&&e<=8542||e>=8544&&e<=8555||e>=8560&&e<=8569||e===8585||e>=8592&&e<=8601||e===8632||e===8633||e===8658||e===8660||e===8679||e===8704||e===8706||e===8707||e===8711||e===8712||e===8715||e===8719||e===8721||e===8725||e===8730||e>=8733&&e<=8736||e===8739||e===8741||e>=8743&&e<=8748||e===8750||e>=8756&&e<=8759||e===8764||e===8765||e===8776||e===8780||e===8786||e===8800||e===8801||e>=8804&&e<=8807||e===8810||e===8811||e===8814||e===8815||e===8834||e===8835||e===8838||e===8839||e===8853||e===8857||e===8869||e===8895||e===8978||e>=9312&&e<=9449||e>=9451&&e<=9547||e>=9552&&e<=9587||e>=9600&&e<=9615||e>=9618&&e<=9621||e===9632||e===9633||e>=9635&&e<=9641||e===9650||e===9651||e===9654||e===9655||e===9660||e===9661||e===9664||e===9665||e>=9670&&e<=9672||e===9675||e>=9678&&e<=9681||e>=9698&&e<=9701||e===9711||e===9733||e===9734||e===9737||e===9742||e===9743||e===9756||e===9758||e===9792||e===9794||e===9824||e===9825||e>=9827&&e<=9829||e>=9831&&e<=9834||e===9836||e===9837||e===9839||e===9886||e===9887||e===9919||e>=9926&&e<=9933||e>=9935&&e<=9939||e>=9941&&e<=9953||e===9955||e===9960||e===9961||e>=9963&&e<=9969||e===9972||e>=9974&&e<=9977||e===9979||e===9980||e===9982||e===9983||e===10045||e>=10102&&e<=10111||e>=11094&&e<=11097||e>=12872&&e<=12879||e>=57344&&e<=63743||e>=65024&&e<=65039||e===65533||e>=127232&&e<=127242||e>=127248&&e<=127277||e>=127280&&e<=127337||e>=127344&&e<=127373||e===127375||e===127376||e>=127387&&e<=127404||e>=917760&&e<=917999||e>=983040&&e<=1048573||e>=1048576&&e<=1114109,cr=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,ur=e=>e>=4352&&e<=4447||e===8986||e===8987||e===9001||e===9002||e>=9193&&e<=9196||e===9200||e===9203||e===9725||e===9726||e===9748||e===9749||e>=9800&&e<=9811||e===9855||e===9875||e===9889||e===9898||e===9899||e===9917||e===9918||e===9924||e===9925||e===9934||e===9940||e===9962||e===9970||e===9971||e===9973||e===9978||e===9981||e===9989||e===9994||e===9995||e===10024||e===10060||e===10062||e>=10067&&e<=10069||e===10071||e>=10133&&e<=10135||e===10160||e===10175||e===11035||e===11036||e===11088||e===11093||e>=11904&&e<=11929||e>=11931&&e<=12019||e>=12032&&e<=12245||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12353&&e<=12438||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=19968&&e<=42124||e>=42128&&e<=42182||e>=43360&&e<=43388||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=94176&&e<=94180||e===94192||e===94193||e>=94208&&e<=100343||e>=100352&&e<=101589||e>=101632&&e<=101640||e>=110576&&e<=110579||e>=110581&&e<=110587||e===110589||e===110590||e>=110592&&e<=110882||e===110898||e>=110928&&e<=110930||e===110933||e>=110948&&e<=110951||e>=110960&&e<=111355||e===126980||e===127183||e===127374||e>=127377&&e<=127386||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e===127568||e===127569||e>=127584&&e<=127589||e>=127744&&e<=127776||e>=127789&&e<=127797||e>=127799&&e<=127868||e>=127870&&e<=127891||e>=127904&&e<=127946||e>=127951&&e<=127955||e>=127968&&e<=127984||e===127988||e>=127992&&e<=128062||e===128064||e>=128066&&e<=128252||e>=128255&&e<=128317||e>=128331&&e<=128334||e>=128336&&e<=128359||e===128378||e===128405||e===128406||e===128420||e>=128507&&e<=128591||e>=128640&&e<=128709||e===128716||e>=128720&&e<=128722||e>=128725&&e<=128727||e>=128732&&e<=128735||e===128747||e===128748||e>=128756&&e<=128764||e>=128992&&e<=129003||e===129008||e>=129292&&e<=129338||e>=129340&&e<=129349||e>=129351&&e<=129535||e>=129648&&e<=129660||e>=129664&&e<=129672||e>=129680&&e<=129725||e>=129727&&e<=129733||e>=129742&&e<=129755||e>=129760&&e<=129768||e>=129776&&e<=129784||e>=131072&&e<=196605||e>=196608&&e<=262141,ui=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y,$t=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,yt=/\t{1,1000}/y,di=new RegExp("[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F\\u20E3?))*","yu"),bt=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,dr=new RegExp("\\p{M}+","gu"),mr={limit:1/0,ellipsis:""},hs=(e,t={},i={})=>{let s=t.limit??1/0,n=t.ellipsis??"",r=t?.ellipsisWidth??(n?hs(n,mr,i).width:0),o=i.ansiWidth??0,a=i.controlWidth??0,l=i.tabWidth??8,m=i.ambiguousWidth??1,d=i.emojiWidth??2,u=i.fullWidthWidth??2,y=i.regularWidth??1,k=i.wideWidth??2,g=0,p=0,$=e.length,_=0,A=!1,T=$,M=Math.max(0,s-r),F=0,R=0,C=0,I=0;e:for(;;){if(R>F||p>=$&&p>g){let G=e.slice(F,R)||e.slice(g,p);_=0;for(let J of G.replaceAll(dr,"")){let le=J.codePointAt(0)||0;if(cr(le)?I=u:ur(le)?I=k:m!==y&&lr(le)?I=m:I=y,C+I>M&&(T=Math.min(T,Math.max(F,g)+_)),C+I>s){A=!0;break e}_+=J.length,C+=I}F=R=0}if(p>=$)break;if(bt.lastIndex=p,bt.test(e)){if(_=bt.lastIndex-p,I=_*y,C+I>M&&(T=Math.min(T,p+Math.floor((M-C)/y))),C+I>s){A=!0;break}C+=I,F=g,R=p,p=g=bt.lastIndex;continue}if(ui.lastIndex=p,ui.test(e)){if(C+o>M&&(T=Math.min(T,p)),C+o>s){A=!0;break}C+=o,F=g,R=p,p=g=ui.lastIndex;continue}if($t.lastIndex=p,$t.test(e)){if(_=$t.lastIndex-p,I=_*a,C+I>M&&(T=Math.min(T,p+Math.floor((M-C)/a))),C+I>s){A=!0;break}C+=I,F=g,R=p,p=g=$t.lastIndex;continue}if(yt.lastIndex=p,yt.test(e)){if(_=yt.lastIndex-p,I=_*l,C+I>M&&(T=Math.min(T,p+Math.floor((M-C)/l))),C+I>s){A=!0;break}C+=I,F=g,R=p,p=g=yt.lastIndex;continue}if(di.lastIndex=p,di.test(e)){if(C+d>M&&(T=Math.min(T,p)),C+d>s){A=!0;break}C+=d,F=g,R=p,p=g=di.lastIndex;continue}p+=1}return{width:A?M:C,index:A?T:$,truncated:A,ellipsed:A&&s>=r}},fr={limit:1/0,ellipsis:"",ellipsisWidth:0},Qe=(e,t={})=>hs(e,fr,t).width,kt="\x1B",ps="\x9B",hr=39,gi="\x07",gs="[",pr="]",$s="m",$i=`${pr}8;;`,cs=new RegExp(`(?:\\${gs}(?<code>\\d+)m|\\${$i}(?<uri>.*)${gi})`,"y"),gr=e=>{if(e>=30&&e<=37||e>=90&&e<=97)return 39;if(e>=40&&e<=47||e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0},us=e=>`${kt}${gs}${e}${$s}`,ds=e=>`${kt}${$i}${e}${gi}`,$r=e=>e.map(t=>Qe(t)),mi=(e,t,i)=>{let s=t[Symbol.iterator](),n=!1,r=!1,o=e.at(-1),a=o===void 0?0:Qe(o),l=s.next(),m=s.next(),d=0;for(;!l.done;){let u=l.value,y=Qe(u);a+y<=i?e[e.length-1]+=u:(e.push(u),a=0),(u===kt||u===ps)&&(n=!0,r=t.startsWith($i,d+1)),n?r?u===gi&&(n=!1,r=!1):u===$s&&(n=!1):(a+=y,a===i&&!m.done&&(e.push(""),a=0)),l=m,m=s.next(),d+=u.length}o=e.at(-1),!a&&o!==void 0&&o.length>0&&e.length>1&&(e[e.length-2]+=e.pop())},yr=e=>{let t=e.split(" "),i=t.length;for(;i>0&&!(Qe(t[i-1])>0);)i--;return i===t.length?e:t.slice(0,i).join(" ")+t.slice(i).join("")},br=(e,t,i={})=>{if(i.trim!==!1&&e.trim()==="")return"";let s="",n,r,o=e.split(" "),a=$r(o),l=[""];for(let[g,p]of o.entries()){i.trim!==!1&&(l[l.length-1]=(l.at(-1)??"").trimStart());let $=Qe(l.at(-1)??"");if(g!==0&&($>=t&&(i.wordWrap===!1||i.trim===!1)&&(l.push(""),$=0),($>0||i.trim===!1)&&(l[l.length-1]+=" ",$++)),i.hard&&a[g]>t){let _=t-$,A=1+Math.floor((a[g]-_-1)/t);Math.floor((a[g]-1)/t)<A&&l.push(""),mi(l,p,t);continue}if($+a[g]>t&&$>0&&a[g]>0){if(i.wordWrap===!1&&$<t){mi(l,p,t);continue}l.push("")}if($+a[g]>t&&i.wordWrap===!1){mi(l,p,t);continue}l[l.length-1]+=p}i.trim!==!1&&(l=l.map(g=>yr(g)));let m=l.join(`
28
- `),d=m[Symbol.iterator](),u=d.next(),y=d.next(),k=0;for(;!u.done;){let g=u.value,p=y.value;if(s+=g,g===kt||g===ps){cs.lastIndex=k+1;let _=cs.exec(m)?.groups;if(_?.code!==void 0){let A=Number.parseFloat(_.code);n=A===hr?void 0:A}else _?.uri!==void 0&&(r=_.uri.length===0?void 0:_.uri)}let $=n?gr(n):void 0;p===`
29
- `?(r&&(s+=ds("")),n&&$&&(s+=us($))):g===`
30
- `&&(n&&$&&(s+=us(n)),r&&(s+=ds(r))),k+=g.length,u=y,y=d.next()}return s};function hi(e,t,i){return String(e).normalize().replaceAll(`\r
27
+ `)}),this}_outputHelpIfRequested(t){let i=this._getHelpOption();i&&t.find(n=>i.is(n))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}};function sn(e){return e.map(t=>{if(!t.startsWith("--inspect"))return t;let i,s="127.0.0.1",n="9229",r;return(r=t.match(/^(--inspect(-brk)?)$/))!==null?i=r[1]:(r=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(i=r[1],/^\d+$/.test(r[3])?n=r[3]:s=r[3]):(r=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(i=r[1],s=r[3],n=r[4]),i&&n!=="0"?`${i}=${s}:${parseInt(n)+1}`:t})}function Xi(){if(ee.env.NO_COLOR||ee.env.FORCE_COLOR==="0"||ee.env.FORCE_COLOR==="false")return!1;if(ee.env.FORCE_COLOR||ee.env.CLICOLOR_FORCE!==void 0)return!0}Qi.Command=Zi;Qi.useColor=Xi});var ln=Ze(Me=>{var{Argument:rn}=Yt(),{Command:es}=nn(),{CommanderError:wo,InvalidArgumentError:on}=Pt(),{Help:_o}=Hi(),{Option:an}=zi();Me.program=new es;Me.createCommand=e=>new es(e);Me.createOption=(e,t)=>new an(e,t);Me.createArgument=(e,t)=>new rn(e,t);Me.Command=es;Me.Option=an;Me.Argument=rn;Me.Help=_o;Me.CommanderError=wo;Me.InvalidArgumentError=on;Me.InvalidOptionArgumentError=on});var Z=Ze((tc,ts)=>{var Qt=process||{},un=Qt.argv||[],Xt=Qt.env||{},xo=!(Xt.NO_COLOR||un.includes("--no-color"))&&(!!Xt.FORCE_COLOR||un.includes("--color")||Qt.platform==="win32"||(Qt.stdout||{}).isTTY&&Xt.TERM!=="dumb"||!!Xt.CI),ko=(e,t,i=e)=>s=>{let n=""+s,r=n.indexOf(t,e.length);return~r?e+So(n,t,i,r)+t:e+n+t},So=(e,t,i,s)=>{let n="",r=0;do n+=e.substring(r,s)+i,r=s+t.length,s=e.indexOf(t,r);while(~s);return n+e.substring(r)},mn=(e=xo)=>{let t=e?ko:()=>String;return{isColorSupported:e,reset:t("\x1B[0m","\x1B[0m"),bold:t("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:t("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:t("\x1B[3m","\x1B[23m"),underline:t("\x1B[4m","\x1B[24m"),inverse:t("\x1B[7m","\x1B[27m"),hidden:t("\x1B[8m","\x1B[28m"),strikethrough:t("\x1B[9m","\x1B[29m"),black:t("\x1B[30m","\x1B[39m"),red:t("\x1B[31m","\x1B[39m"),green:t("\x1B[32m","\x1B[39m"),yellow:t("\x1B[33m","\x1B[39m"),blue:t("\x1B[34m","\x1B[39m"),magenta:t("\x1B[35m","\x1B[39m"),cyan:t("\x1B[36m","\x1B[39m"),white:t("\x1B[37m","\x1B[39m"),gray:t("\x1B[90m","\x1B[39m"),bgBlack:t("\x1B[40m","\x1B[49m"),bgRed:t("\x1B[41m","\x1B[49m"),bgGreen:t("\x1B[42m","\x1B[49m"),bgYellow:t("\x1B[43m","\x1B[49m"),bgBlue:t("\x1B[44m","\x1B[49m"),bgMagenta:t("\x1B[45m","\x1B[49m"),bgCyan:t("\x1B[46m","\x1B[49m"),bgWhite:t("\x1B[47m","\x1B[49m"),blackBright:t("\x1B[90m","\x1B[39m"),redBright:t("\x1B[91m","\x1B[39m"),greenBright:t("\x1B[92m","\x1B[39m"),yellowBright:t("\x1B[93m","\x1B[39m"),blueBright:t("\x1B[94m","\x1B[39m"),magentaBright:t("\x1B[95m","\x1B[39m"),cyanBright:t("\x1B[96m","\x1B[39m"),whiteBright:t("\x1B[97m","\x1B[39m"),bgBlackBright:t("\x1B[100m","\x1B[49m"),bgRedBright:t("\x1B[101m","\x1B[49m"),bgGreenBright:t("\x1B[102m","\x1B[49m"),bgYellowBright:t("\x1B[103m","\x1B[49m"),bgBlueBright:t("\x1B[104m","\x1B[49m"),bgMagentaBright:t("\x1B[105m","\x1B[49m"),bgCyanBright:t("\x1B[106m","\x1B[49m"),bgWhiteBright:t("\x1B[107m","\x1B[49m")}};ts.exports=mn();ts.exports.createColors=mn});var kt,fn,ei=Ee(()=>{"use strict";kt="domani.run",fn=`https://${kt}`});function gn(e){pn=e}function dt(){try{let e=rt.default.readFileSync(is,"utf-8");return JSON.parse(e)}catch{return{}}}function ni(e){rt.default.mkdirSync(si,{recursive:!0,mode:448}),rt.default.writeFileSync(is,JSON.stringify(e,null,2),{mode:384})}function yn(){try{rt.default.unlinkSync(is)}catch{}}function ot(){return pn||dt().api_url||fn}function Tt(){return process.env.DOMANI_API_KEY||dt().token}function bn(){let e=Tt();return e||(process.argv.includes("--json")||!process.stdout.isTTY?console.log(JSON.stringify({error:"Not logged in",code:"auth_required",hint:"Run 'domani login' or set DOMANI_API_KEY environment variable",fix_command:"domani login"},null,2)):console.error("Not logged in. Run: domani login"),process.exit(1)),e}function Co(){try{let e=rt.default.readFileSync($n,"utf-8");return JSON.parse(e)}catch{return null}}function Oo(e){try{rt.default.mkdirSync(si,{recursive:!0,mode:448}),rt.default.writeFileSync($n,JSON.stringify(e),{mode:384})}catch{}}function ti(e,t){let i=e.split(".").map(Number),s=t.split(".").map(Number);for(let n=0;n<3;n++){if((i[n]||0)>(s[n]||0))return 1;if((i[n]||0)<(s[n]||0))return-1}return 0}async function vn(){let e=Co();if(e&&Date.now()-e.checkedAt<jo)return ti(e.version,be)>0?{update:e.version,forced:ti(be,e.min)<0}:null;try{let t=ot(),i=await fetch(`${t}/api/cli/version`,{signal:AbortSignal.timeout(3e3)});if(!i.ok)return null;let s=await i.json();if(Oo({version:s.version,min:s.min,checkedAt:Date.now()}),ti(s.version,be)>0)return{update:s.version,forced:ti(be,s.min)<0}}catch{}return null}var rt,ii,hn,si,is,pn,$n,jo,be,ut=Ee(()=>{"use strict";rt=M(require("fs"),1),ii=M(require("path"),1),hn=M(require("os"),1);ei();si=process.env.DOMANI_CONFIG_DIR||ii.default.join(hn.default.homedir(),".domani"),is=ii.default.join(si,"config.json");$n=ii.default.join(si,"version-check.json"),jo=1440*60*1e3;be="0.3.12"});var ns=Ze((rc,wn)=>{"use strict";var ss={to(e,t){return t?`\x1B[${t+1};${e+1}H`:`\x1B[${e+1}G`},move(e,t){let i="";return e<0?i+=`\x1B[${-e}D`:e>0&&(i+=`\x1B[${e}C`),t<0?i+=`\x1B[${-t}A`:t>0&&(i+=`\x1B[${t}B`),i},up:(e=1)=>`\x1B[${e}A`,down:(e=1)=>`\x1B[${e}B`,forward:(e=1)=>`\x1B[${e}C`,backward:(e=1)=>`\x1B[${e}D`,nextLine:(e=1)=>"\x1B[E".repeat(e),prevLine:(e=1)=>"\x1B[F".repeat(e),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},Ao={up:(e=1)=>"\x1B[S".repeat(e),down:(e=1)=>"\x1B[T".repeat(e)},Ro={screen:"\x1B[2J",up:(e=1)=>"\x1B[1J".repeat(e),down:(e=1)=>"\x1B[J".repeat(e),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(e){let t="";for(let i=0;i<e;i++)t+=this.line+(i<e-1?ss.up():"");return e&&(t+=ss.left),t}};wn.exports={cursor:ss,scroll:Ao,erase:Ro,beep:"\x07"}});function Qe(e,t,i){if(!i.some(o=>!o.disabled))return e;let s=e+t,n=Math.max(i.length-1,0),r=s<0?n:s>n?0:s;return i[r].disabled?Qe(r,t<0?-1:1,i):r}function cs(e,t,i){return String(e).normalize().replaceAll(`\r
31
28
  `,`
32
29
  `).split(`
33
- `).map(s=>br(s,t,i)).join(`
34
- `)}var vr=["up","down","left","right","space","enter","cancel"],fe={actions:new Set(vr),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0};function yi(e,t){if(typeof e=="string")return fe.aliases.get(e)===t;for(let i of e)if(i!==void 0&&yi(i,t))return!0;return!1}function wr(e,t){if(e===t)return;let i=e.split(`
30
+ `).map(s=>qo(s,t,i)).join(`
31
+ `)}function Rn(e){if(e.aliases!==void 0){let t=e.aliases;for(let i in t){if(!Object.hasOwn(t,i))continue;let s=t[i];re.actions.has(s)&&(re.aliases.has(i)||re.aliases.set(i,s))}}if(e.messages!==void 0){let t=e.messages;t.cancel!==void 0&&(re.messages.cancel=t.cancel),t.error!==void 0&&(re.messages.error=t.error)}e.withGuide!==void 0&&(re.withGuide=e.withGuide!==!1)}function fs(e,t){if(typeof e=="string")return re.aliases.get(e)===t;for(let i of e)if(i!==void 0&&fs(i,t))return!0;return!1}function Ho(e,t){if(e===t)return;let i=e.split(`
35
32
  `),s=t.split(`
36
- `),n=Math.max(i.length,s.length),r=[];for(let o=0;o<n;o++)i[o]!==s[o]&&r.push(o);return{lines:r,numLinesBefore:i.length,numLinesAfter:s.length,numLines:n}}var _r=globalThis.process.platform.startsWith("win"),pi=Symbol("clack:cancel");function Q(e){return e===pi}function vt(e,t){let i=e;i.isTTY&&i.setRawMode(t)}function ys({input:e=Ue.stdin,output:t=Ue.stdout,overwrite:i=!0,hideCursor:s=!0}={}){let n=Pe.createInterface({input:e,output:t,prompt:"",tabSize:1});Pe.emitKeypressEvents(e,n),e instanceof fi.ReadStream&&e.isTTY&&e.setRawMode(!0);let r=(o,{name:a,sequence:l})=>{let m=String(o);if(yi([m,a,l],"cancel")){s&&t.write(re.cursor.show),process.exit(0);return}if(!i)return;Pe.moveCursor(t,a==="return"?0:-1,a==="return"?-1:0,()=>{Pe.clearLine(t,1,()=>{e.once("keypress",r)})})};return s&&t.write(re.cursor.hide),e.once("keypress",r),()=>{e.off("keypress",r),s&&t.write(re.cursor.show),e instanceof fi.ReadStream&&e.isTTY&&!_r&&e.setRawMode(!1),n.terminal=!1,n.close()}}var jt=e=>"columns"in e&&typeof e.columns=="number"?e.columns:80,bi=e=>"rows"in e&&typeof e.rows=="number"?e.rows:20;function Ct(e,t,i,s=i){let n=jt(e??Ue.stdout);return hi(t,n-i.length,{hard:!0,trim:!1}).split(`
33
+ `),n=Math.max(i.length,s.length),r=[];for(let o=0;o<n;o++)i[o]!==s[o]&&r.push(o);return{lines:r,numLinesBefore:i.length,numLinesAfter:s.length,numLines:n}}function oe(e){return e===ds}function li(e,t){let i=e;i.isTTY&&i.setRawMode(t)}function In({input:e=mt.stdin,output:t=mt.stdout,overwrite:i=!0,hideCursor:s=!0}={}){let n=at.createInterface({input:e,output:t,prompt:"",tabSize:1});at.emitKeypressEvents(e,n),e instanceof ls.ReadStream&&e.isTTY&&e.setRawMode(!0);let r=(o,{name:a,sequence:l})=>{let c=String(o);if(fs([c,a,l],"cancel")){s&&t.write(xe.cursor.show),process.exit(0);return}if(!i)return;at.moveCursor(t,a==="return"?0:-1,a==="return"?-1:0,()=>{at.clearLine(t,1,()=>{e.once("keypress",r)})})};return s&&t.write(xe.cursor.hide),e.once("keypress",r),()=>{e.off("keypress",r),s&&t.write(xe.cursor.show),e instanceof ls.ReadStream&&e.isTTY&&!Jo&&e.setRawMode(!1),n.terminal=!1,n.close()}}function Ge(e,t,i,s=i){let n=ft(e??mt.stdout);return cs(t,n-i.length,{hard:!0,trim:!1}).split(`
37
34
  `).map((r,o)=>`${o===0?s:i}${r}`).join(`
38
- `)}var et=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(t,i=!0){let{input:s=Ue.stdin,output:n=Ue.stdout,render:r,signal:o,...a}=t;this.opts=a,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=r.bind(this),this._track=i,this._abortSignal=o,this.input=s,this.output=n}unsubscribe(){this._subscribers.clear()}setSubscriber(t,i){let s=this._subscribers.get(t)??[];s.push(i),this._subscribers.set(t,s)}on(t,i){this.setSubscriber(t,{cb:i})}once(t,i){this.setSubscriber(t,{cb:i,once:!0})}emit(t,...i){let s=this._subscribers.get(t)??[],n=[];for(let r of s)r.cb(...i),r.once&&n.push(()=>s.splice(s.indexOf(r),1));for(let r of n)r()}prompt(){return new Promise(t=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),t(pi);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=fs.default.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),vt(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(re.cursor.show),this.output.off("resize",this.render),vt(this.input,!1),t(this.value)}),this.once("cancel",()=>{this.output.write(re.cursor.show),this.output.off("resize",this.render),vt(this.input,!1),t(pi)})})}_isActionKey(t,i){return t===" "}_setValue(t){this.value=t,this.emit("value",this.value)}_setUserInput(t,i){this.userInput=t??"",this.emit("userInput",this.userInput),i&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}onKeypress(t,i){if(this._track&&i.name!=="return"&&(i.name&&this._isActionKey(t,i)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),i?.name&&(!this._track&&fe.aliases.has(i.name)&&this.emit("cursor",fe.aliases.get(i.name)),fe.actions.has(i.name)&&this.emit("cursor",i.name)),t&&(t.toLowerCase()==="y"||t.toLowerCase()==="n")&&this.emit("confirm",t.toLowerCase()==="y"),this.emit("key",t?.toLowerCase(),i),i?.name==="return"){if(this.opts.validate){let s=this.opts.validate(this.value);s&&(this.error=s instanceof Error?s.message:s,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}yi([t,i?.name,i?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
39
- `),vt(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let t=hi(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
40
- `).length-1;this.output.write(re.cursor.move(-999,t*-1))}render(){let t=hi(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(t!==this._prevFrame){if(this.state==="initial")this.output.write(re.cursor.hide);else{let i=wr(this._prevFrame,t),s=bi(this.output);if(this.restoreCursor(),i){let n=Math.max(0,i.numLinesAfter-s),r=Math.max(0,i.numLinesBefore-s),o=i.lines.find(a=>a>=n);if(o===void 0){this._prevFrame=t;return}if(i.lines.length===1){this.output.write(re.cursor.move(0,o-r)),this.output.write(re.erase.lines(1));let a=t.split(`
41
- `);this.output.write(a[o]),this._prevFrame=t,this.output.write(re.cursor.move(0,a.length-o-1));return}else if(i.lines.length>1){if(n<r)o=n;else{let l=o-r;l>0&&this.output.write(re.cursor.move(0,l))}this.output.write(re.erase.down());let a=t.split(`
35
+ `)}function Bo(e,t){if(e===void 0||t.length===0)return 0;let i=t.findIndex(s=>s.value===e);return i!==-1?i:0}function Go(e,t){return(t.label??String(t.value)).toLowerCase().includes(e.toLowerCase())}function zo(e,t){if(t)return e?t:t[0]}var St,mt,at,Sn,xe,ls,Io,Eo,Po,rs,ri,oi,os,ai,To,Do,jn,No,Dt,pi,Cn,Fo,us,On,Vo,An,ms,_n,Mo,xn,kn,Uo,as,Lo,qo,Wo,re,Jo,ds,ft,hs,Be,Nt,ci,di,En,ui,mi,fi,hi,ps=Ee(()=>{St=require("node:util"),mt=require("node:process"),at=M(require("node:readline"),1),Sn=M(require("node:readline"),1),xe=M(ns(),1),ls=require("node:tty");Io=e=>e===161||e===164||e===167||e===168||e===170||e===173||e===174||e>=176&&e<=180||e>=182&&e<=186||e>=188&&e<=191||e===198||e===208||e===215||e===216||e>=222&&e<=225||e===230||e>=232&&e<=234||e===236||e===237||e===240||e===242||e===243||e>=247&&e<=250||e===252||e===254||e===257||e===273||e===275||e===283||e===294||e===295||e===299||e>=305&&e<=307||e===312||e>=319&&e<=322||e===324||e>=328&&e<=331||e===333||e===338||e===339||e===358||e===359||e===363||e===462||e===464||e===466||e===468||e===470||e===472||e===474||e===476||e===593||e===609||e===708||e===711||e>=713&&e<=715||e===717||e===720||e>=728&&e<=731||e===733||e===735||e>=768&&e<=879||e>=913&&e<=929||e>=931&&e<=937||e>=945&&e<=961||e>=963&&e<=969||e===1025||e>=1040&&e<=1103||e===1105||e===8208||e>=8211&&e<=8214||e===8216||e===8217||e===8220||e===8221||e>=8224&&e<=8226||e>=8228&&e<=8231||e===8240||e===8242||e===8243||e===8245||e===8251||e===8254||e===8308||e===8319||e>=8321&&e<=8324||e===8364||e===8451||e===8453||e===8457||e===8467||e===8470||e===8481||e===8482||e===8486||e===8491||e===8531||e===8532||e>=8539&&e<=8542||e>=8544&&e<=8555||e>=8560&&e<=8569||e===8585||e>=8592&&e<=8601||e===8632||e===8633||e===8658||e===8660||e===8679||e===8704||e===8706||e===8707||e===8711||e===8712||e===8715||e===8719||e===8721||e===8725||e===8730||e>=8733&&e<=8736||e===8739||e===8741||e>=8743&&e<=8748||e===8750||e>=8756&&e<=8759||e===8764||e===8765||e===8776||e===8780||e===8786||e===8800||e===8801||e>=8804&&e<=8807||e===8810||e===8811||e===8814||e===8815||e===8834||e===8835||e===8838||e===8839||e===8853||e===8857||e===8869||e===8895||e===8978||e>=9312&&e<=9449||e>=9451&&e<=9547||e>=9552&&e<=9587||e>=9600&&e<=9615||e>=9618&&e<=9621||e===9632||e===9633||e>=9635&&e<=9641||e===9650||e===9651||e===9654||e===9655||e===9660||e===9661||e===9664||e===9665||e>=9670&&e<=9672||e===9675||e>=9678&&e<=9681||e>=9698&&e<=9701||e===9711||e===9733||e===9734||e===9737||e===9742||e===9743||e===9756||e===9758||e===9792||e===9794||e===9824||e===9825||e>=9827&&e<=9829||e>=9831&&e<=9834||e===9836||e===9837||e===9839||e===9886||e===9887||e===9919||e>=9926&&e<=9933||e>=9935&&e<=9939||e>=9941&&e<=9953||e===9955||e===9960||e===9961||e>=9963&&e<=9969||e===9972||e>=9974&&e<=9977||e===9979||e===9980||e===9982||e===9983||e===10045||e>=10102&&e<=10111||e>=11094&&e<=11097||e>=12872&&e<=12879||e>=57344&&e<=63743||e>=65024&&e<=65039||e===65533||e>=127232&&e<=127242||e>=127248&&e<=127277||e>=127280&&e<=127337||e>=127344&&e<=127373||e===127375||e===127376||e>=127387&&e<=127404||e>=917760&&e<=917999||e>=983040&&e<=1048573||e>=1048576&&e<=1114109,Eo=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,Po=e=>e>=4352&&e<=4447||e===8986||e===8987||e===9001||e===9002||e>=9193&&e<=9196||e===9200||e===9203||e===9725||e===9726||e===9748||e===9749||e>=9800&&e<=9811||e===9855||e===9875||e===9889||e===9898||e===9899||e===9917||e===9918||e===9924||e===9925||e===9934||e===9940||e===9962||e===9970||e===9971||e===9973||e===9978||e===9981||e===9989||e===9994||e===9995||e===10024||e===10060||e===10062||e>=10067&&e<=10069||e===10071||e>=10133&&e<=10135||e===10160||e===10175||e===11035||e===11036||e===11088||e===11093||e>=11904&&e<=11929||e>=11931&&e<=12019||e>=12032&&e<=12245||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12353&&e<=12438||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=19968&&e<=42124||e>=42128&&e<=42182||e>=43360&&e<=43388||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=94176&&e<=94180||e===94192||e===94193||e>=94208&&e<=100343||e>=100352&&e<=101589||e>=101632&&e<=101640||e>=110576&&e<=110579||e>=110581&&e<=110587||e===110589||e===110590||e>=110592&&e<=110882||e===110898||e>=110928&&e<=110930||e===110933||e>=110948&&e<=110951||e>=110960&&e<=111355||e===126980||e===127183||e===127374||e>=127377&&e<=127386||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e===127568||e===127569||e>=127584&&e<=127589||e>=127744&&e<=127776||e>=127789&&e<=127797||e>=127799&&e<=127868||e>=127870&&e<=127891||e>=127904&&e<=127946||e>=127951&&e<=127955||e>=127968&&e<=127984||e===127988||e>=127992&&e<=128062||e===128064||e>=128066&&e<=128252||e>=128255&&e<=128317||e>=128331&&e<=128334||e>=128336&&e<=128359||e===128378||e===128405||e===128406||e===128420||e>=128507&&e<=128591||e>=128640&&e<=128709||e===128716||e>=128720&&e<=128722||e>=128725&&e<=128727||e>=128732&&e<=128735||e===128747||e===128748||e>=128756&&e<=128764||e>=128992&&e<=129003||e===129008||e>=129292&&e<=129338||e>=129340&&e<=129349||e>=129351&&e<=129535||e>=129648&&e<=129660||e>=129664&&e<=129672||e>=129680&&e<=129725||e>=129727&&e<=129733||e>=129742&&e<=129755||e>=129760&&e<=129768||e>=129776&&e<=129784||e>=131072&&e<=196605||e>=196608&&e<=262141,rs=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y,ri=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,oi=/\t{1,1000}/y,os=new RegExp("[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F\\u20E3?))*","yu"),ai=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,To=new RegExp("\\p{M}+","gu"),Do={limit:1/0,ellipsis:""},jn=(e,t={},i={})=>{let s=t.limit??1/0,n=t.ellipsis??"",r=t?.ellipsisWidth??(n?jn(n,Do,i).width:0),o=i.ansiWidth??0,a=i.controlWidth??0,l=i.tabWidth??8,c=i.ambiguousWidth??1,u=i.emojiWidth??2,f=i.fullWidthWidth??2,p=i.regularWidth??1,v=i.wideWidth??2,$=0,m=0,y=e.length,w=0,S=!1,A=y,F=Math.max(0,s-r),N=0,H=0,R=0,P=0;e:for(;;){if(H>N||m>=y&&m>$){let T=e.slice(N,H)||e.slice($,m);w=0;for(let J of T.replaceAll(To,"")){let Y=J.codePointAt(0)||0;if(Eo(Y)?P=f:Po(Y)?P=v:c!==p&&Io(Y)?P=c:P=p,R+P>F&&(A=Math.min(A,Math.max(N,$)+w)),R+P>s){S=!0;break e}w+=J.length,R+=P}N=H=0}if(m>=y)break;if(ai.lastIndex=m,ai.test(e)){if(w=ai.lastIndex-m,P=w*p,R+P>F&&(A=Math.min(A,m+Math.floor((F-R)/p))),R+P>s){S=!0;break}R+=P,N=$,H=m,m=$=ai.lastIndex;continue}if(rs.lastIndex=m,rs.test(e)){if(R+o>F&&(A=Math.min(A,m)),R+o>s){S=!0;break}R+=o,N=$,H=m,m=$=rs.lastIndex;continue}if(ri.lastIndex=m,ri.test(e)){if(w=ri.lastIndex-m,P=w*a,R+P>F&&(A=Math.min(A,m+Math.floor((F-R)/a))),R+P>s){S=!0;break}R+=P,N=$,H=m,m=$=ri.lastIndex;continue}if(oi.lastIndex=m,oi.test(e)){if(w=oi.lastIndex-m,P=w*l,R+P>F&&(A=Math.min(A,m+Math.floor((F-R)/l))),R+P>s){S=!0;break}R+=P,N=$,H=m,m=$=oi.lastIndex;continue}if(os.lastIndex=m,os.test(e)){if(R+u>F&&(A=Math.min(A,m)),R+u>s){S=!0;break}R+=u,N=$,H=m,m=$=os.lastIndex;continue}m+=1}return{width:S?F:R,index:S?A:y,truncated:S,ellipsed:S&&s>=r}},No={limit:1/0,ellipsis:"",ellipsisWidth:0},Dt=(e,t={})=>jn(e,No,t).width,pi="\x1B",Cn="\x9B",Fo=39,us="\x07",On="[",Vo="]",An="m",ms=`${Vo}8;;`,_n=new RegExp(`(?:\\${On}(?<code>\\d+)m|\\${ms}(?<uri>.*)${us})`,"y"),Mo=e=>{if(e>=30&&e<=37||e>=90&&e<=97)return 39;if(e>=40&&e<=47||e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0},xn=e=>`${pi}${On}${e}${An}`,kn=e=>`${pi}${ms}${e}${us}`,Uo=e=>e.map(t=>Dt(t)),as=(e,t,i)=>{let s=t[Symbol.iterator](),n=!1,r=!1,o=e.at(-1),a=o===void 0?0:Dt(o),l=s.next(),c=s.next(),u=0;for(;!l.done;){let f=l.value,p=Dt(f);a+p<=i?e[e.length-1]+=f:(e.push(f),a=0),(f===pi||f===Cn)&&(n=!0,r=t.startsWith(ms,u+1)),n?r?f===us&&(n=!1,r=!1):f===An&&(n=!1):(a+=p,a===i&&!c.done&&(e.push(""),a=0)),l=c,c=s.next(),u+=f.length}o=e.at(-1),!a&&o!==void 0&&o.length>0&&e.length>1&&(e[e.length-2]+=e.pop())},Lo=e=>{let t=e.split(" "),i=t.length;for(;i>0&&!(Dt(t[i-1])>0);)i--;return i===t.length?e:t.slice(0,i).join(" ")+t.slice(i).join("")},qo=(e,t,i={})=>{if(i.trim!==!1&&e.trim()==="")return"";let s="",n,r,o=e.split(" "),a=Uo(o),l=[""];for(let[$,m]of o.entries()){i.trim!==!1&&(l[l.length-1]=(l.at(-1)??"").trimStart());let y=Dt(l.at(-1)??"");if($!==0&&(y>=t&&(i.wordWrap===!1||i.trim===!1)&&(l.push(""),y=0),(y>0||i.trim===!1)&&(l[l.length-1]+=" ",y++)),i.hard&&a[$]>t){let w=t-y,S=1+Math.floor((a[$]-w-1)/t);Math.floor((a[$]-1)/t)<S&&l.push(""),as(l,m,t);continue}if(y+a[$]>t&&y>0&&a[$]>0){if(i.wordWrap===!1&&y<t){as(l,m,t);continue}l.push("")}if(y+a[$]>t&&i.wordWrap===!1){as(l,m,t);continue}l[l.length-1]+=m}i.trim!==!1&&(l=l.map($=>Lo($)));let c=l.join(`
36
+ `),u=c[Symbol.iterator](),f=u.next(),p=u.next(),v=0;for(;!f.done;){let $=f.value,m=p.value;if(s+=$,$===pi||$===Cn){_n.lastIndex=v+1;let w=_n.exec(c)?.groups;if(w?.code!==void 0){let S=Number.parseFloat(w.code);n=S===Fo?void 0:S}else w?.uri!==void 0&&(r=w.uri.length===0?void 0:w.uri)}let y=n?Mo(n):void 0;m===`
37
+ `?(r&&(s+=kn("")),n&&y&&(s+=xn(y))):$===`
38
+ `&&(n&&y&&(s+=xn(n)),r&&(s+=kn(r))),v+=$.length,f=p,p=u.next()}return s};Wo=["up","down","left","right","space","enter","cancel"],re={actions:new Set(Wo),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0};Jo=globalThis.process.platform.startsWith("win"),ds=Symbol("clack:cancel");ft=e=>"columns"in e&&typeof e.columns=="number"?e.columns:80,hs=e=>"rows"in e&&typeof e.rows=="number"?e.rows:20;Be=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(t,i=!0){let{input:s=mt.stdin,output:n=mt.stdout,render:r,signal:o,...a}=t;this.opts=a,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=r.bind(this),this._track=i,this._abortSignal=o,this.input=s,this.output=n}unsubscribe(){this._subscribers.clear()}setSubscriber(t,i){let s=this._subscribers.get(t)??[];s.push(i),this._subscribers.set(t,s)}on(t,i){this.setSubscriber(t,{cb:i})}once(t,i){this.setSubscriber(t,{cb:i,once:!0})}emit(t,...i){let s=this._subscribers.get(t)??[],n=[];for(let r of s)r.cb(...i),r.once&&n.push(()=>s.splice(s.indexOf(r),1));for(let r of n)r()}prompt(){return new Promise(t=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),t(ds);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=Sn.default.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),li(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(xe.cursor.show),this.output.off("resize",this.render),li(this.input,!1),t(this.value)}),this.once("cancel",()=>{this.output.write(xe.cursor.show),this.output.off("resize",this.render),li(this.input,!1),t(ds)})})}_isActionKey(t,i){return t===" "}_setValue(t){this.value=t,this.emit("value",this.value)}_setUserInput(t,i){this.userInput=t??"",this.emit("userInput",this.userInput),i&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}onKeypress(t,i){if(this._track&&i.name!=="return"&&(i.name&&this._isActionKey(t,i)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),i?.name&&(!this._track&&re.aliases.has(i.name)&&this.emit("cursor",re.aliases.get(i.name)),re.actions.has(i.name)&&this.emit("cursor",i.name)),t&&(t.toLowerCase()==="y"||t.toLowerCase()==="n")&&this.emit("confirm",t.toLowerCase()==="y"),this.emit("key",t?.toLowerCase(),i),i?.name==="return"){if(this.opts.validate){let s=this.opts.validate(this.value);s&&(this.error=s instanceof Error?s.message:s,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}fs([t,i?.name,i?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
39
+ `),li(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let t=cs(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
40
+ `).length-1;this.output.write(xe.cursor.move(-999,t*-1))}render(){let t=cs(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(t!==this._prevFrame){if(this.state==="initial")this.output.write(xe.cursor.hide);else{let i=Ho(this._prevFrame,t),s=hs(this.output);if(this.restoreCursor(),i){let n=Math.max(0,i.numLinesAfter-s),r=Math.max(0,i.numLinesBefore-s),o=i.lines.find(a=>a>=n);if(o===void 0){this._prevFrame=t;return}if(i.lines.length===1){this.output.write(xe.cursor.move(0,o-r)),this.output.write(xe.erase.lines(1));let a=t.split(`
41
+ `);this.output.write(a[o]),this._prevFrame=t,this.output.write(xe.cursor.move(0,a.length-o-1));return}else if(i.lines.length>1){if(n<r)o=n;else{let l=o-r;l>0&&this.output.write(xe.cursor.move(0,l))}this.output.write(xe.erase.down());let a=t.split(`
42
42
  `).slice(o);this.output.write(a.join(`
43
- `)),this._prevFrame=t;return}}this.output.write(re.erase.down())}this.output.write(t),this.state==="initial"&&(this.state="active"),this._prevFrame=t}}};var _t=class extends et{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(t){super(t,!1),this.value=!!t.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",i=>{this.output.write(re.cursor.move(0,-1)),this.value=i,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}};var xt=class extends et{options;cursor=0;get _selectedValue(){return this.options[this.cursor]}changeValue(){this.value=this._selectedValue.value}constructor(t){super(t,!1),this.options=t.options;let i=this.options.findIndex(({value:n})=>n===t.initialValue),s=i===-1?0:i;this.cursor=this.options[s].disabled?wt(s,1,this.options):s,this.changeValue(),this.on("cursor",n=>{switch(n){case"left":case"up":this.cursor=wt(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=wt(this.cursor,1,this.options);break}this.changeValue()})}};var St=class extends et{get userInputWithCursor(){if(this.state==="submit")return this.userInput;let t=this.userInput;if(this.cursor>=t.length)return`${this.userInput}\u2588`;let i=t.slice(0,this.cursor),[s,...n]=t.slice(this.cursor);return`${i}${(0,ms.styleText)("inverse",s)}${n.join("")}`}get cursor(){return this._cursor}constructor(t){super({...t,initialUserInput:t.initialUserInput??t.initialValue}),this.on("userInput",i=>{this._setValue(i)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}};var O=require("node:util"),he=P(require("node:process"),1);var tt=P(ci(),1);function xr(){return he.default.platform!=="win32"?he.default.env.TERM!=="linux":!!he.default.env.CI||!!he.default.env.WT_SESSION||!!he.default.env.TERMINUS_SUBLIME||he.default.env.ConEmuTask==="{cmd::Cmder}"||he.default.env.TERM_PROGRAM==="Terminus-Sublime"||he.default.env.TERM_PROGRAM==="vscode"||he.default.env.TERM==="xterm-256color"||he.default.env.TERM==="alacritty"||he.default.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var xi=xr(),Sr=()=>process.env.CI==="true";var B=(e,t)=>xi?e:t,kr=B("\u25C6","*"),_s=B("\u25A0","x"),xs=B("\u25B2","x"),Ss=B("\u25C7","o"),ka=B("\u250C","T"),X=B("\u2502","|"),Et=B("\u2514","\u2014"),ja=B("\u2510","T"),Ca=B("\u2518","\u2014"),Si=B("\u25CF",">"),Tt=B("\u25CB"," "),Oa=B("\u25FB","[\u2022]"),Aa=B("\u25FC","[+]"),Ra=B("\u25FB","[ ]"),Ia=B("\u25AA","\u2022"),Ea=B("\u2500","-"),Ta=B("\u256E","+"),Pa=B("\u251C","+"),Da=B("\u256F","+"),Na=B("\u2570","+"),Fa=B("\u256D","+"),Va=B("\u25CF","\u2022"),Ma=B("\u25C6","*"),Ua=B("\u25B2","!"),La=B("\u25A0","x"),ji=e=>{switch(e){case"initial":case"active":return(0,O.styleText)("cyan",kr);case"cancel":return(0,O.styleText)("red",_s);case"error":return(0,O.styleText)("yellow",xs);case"submit":return(0,O.styleText)("green",Ss)}},jr=e=>{switch(e){case"initial":case"active":return(0,O.styleText)("cyan",X);case"cancel":return(0,O.styleText)("red",X);case"error":return(0,O.styleText)("yellow",X);case"submit":return(0,O.styleText)("green",X)}},Cr=e=>e===161||e===164||e===167||e===168||e===170||e===173||e===174||e>=176&&e<=180||e>=182&&e<=186||e>=188&&e<=191||e===198||e===208||e===215||e===216||e>=222&&e<=225||e===230||e>=232&&e<=234||e===236||e===237||e===240||e===242||e===243||e>=247&&e<=250||e===252||e===254||e===257||e===273||e===275||e===283||e===294||e===295||e===299||e>=305&&e<=307||e===312||e>=319&&e<=322||e===324||e>=328&&e<=331||e===333||e===338||e===339||e===358||e===359||e===363||e===462||e===464||e===466||e===468||e===470||e===472||e===474||e===476||e===593||e===609||e===708||e===711||e>=713&&e<=715||e===717||e===720||e>=728&&e<=731||e===733||e===735||e>=768&&e<=879||e>=913&&e<=929||e>=931&&e<=937||e>=945&&e<=961||e>=963&&e<=969||e===1025||e>=1040&&e<=1103||e===1105||e===8208||e>=8211&&e<=8214||e===8216||e===8217||e===8220||e===8221||e>=8224&&e<=8226||e>=8228&&e<=8231||e===8240||e===8242||e===8243||e===8245||e===8251||e===8254||e===8308||e===8319||e>=8321&&e<=8324||e===8364||e===8451||e===8453||e===8457||e===8467||e===8470||e===8481||e===8482||e===8486||e===8491||e===8531||e===8532||e>=8539&&e<=8542||e>=8544&&e<=8555||e>=8560&&e<=8569||e===8585||e>=8592&&e<=8601||e===8632||e===8633||e===8658||e===8660||e===8679||e===8704||e===8706||e===8707||e===8711||e===8712||e===8715||e===8719||e===8721||e===8725||e===8730||e>=8733&&e<=8736||e===8739||e===8741||e>=8743&&e<=8748||e===8750||e>=8756&&e<=8759||e===8764||e===8765||e===8776||e===8780||e===8786||e===8800||e===8801||e>=8804&&e<=8807||e===8810||e===8811||e===8814||e===8815||e===8834||e===8835||e===8838||e===8839||e===8853||e===8857||e===8869||e===8895||e===8978||e>=9312&&e<=9449||e>=9451&&e<=9547||e>=9552&&e<=9587||e>=9600&&e<=9615||e>=9618&&e<=9621||e===9632||e===9633||e>=9635&&e<=9641||e===9650||e===9651||e===9654||e===9655||e===9660||e===9661||e===9664||e===9665||e>=9670&&e<=9672||e===9675||e>=9678&&e<=9681||e>=9698&&e<=9701||e===9711||e===9733||e===9734||e===9737||e===9742||e===9743||e===9756||e===9758||e===9792||e===9794||e===9824||e===9825||e>=9827&&e<=9829||e>=9831&&e<=9834||e===9836||e===9837||e===9839||e===9886||e===9887||e===9919||e>=9926&&e<=9933||e>=9935&&e<=9939||e>=9941&&e<=9953||e===9955||e===9960||e===9961||e>=9963&&e<=9969||e===9972||e>=9974&&e<=9977||e===9979||e===9980||e===9982||e===9983||e===10045||e>=10102&&e<=10111||e>=11094&&e<=11097||e>=12872&&e<=12879||e>=57344&&e<=63743||e>=65024&&e<=65039||e===65533||e>=127232&&e<=127242||e>=127248&&e<=127277||e>=127280&&e<=127337||e>=127344&&e<=127373||e===127375||e===127376||e>=127387&&e<=127404||e>=917760&&e<=917999||e>=983040&&e<=1048573||e>=1048576&&e<=1114109,Or=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,Ar=e=>e>=4352&&e<=4447||e===8986||e===8987||e===9001||e===9002||e>=9193&&e<=9196||e===9200||e===9203||e===9725||e===9726||e===9748||e===9749||e>=9800&&e<=9811||e===9855||e===9875||e===9889||e===9898||e===9899||e===9917||e===9918||e===9924||e===9925||e===9934||e===9940||e===9962||e===9970||e===9971||e===9973||e===9978||e===9981||e===9989||e===9994||e===9995||e===10024||e===10060||e===10062||e>=10067&&e<=10069||e===10071||e>=10133&&e<=10135||e===10160||e===10175||e===11035||e===11036||e===11088||e===11093||e>=11904&&e<=11929||e>=11931&&e<=12019||e>=12032&&e<=12245||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12353&&e<=12438||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=19968&&e<=42124||e>=42128&&e<=42182||e>=43360&&e<=43388||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=94176&&e<=94180||e===94192||e===94193||e>=94208&&e<=100343||e>=100352&&e<=101589||e>=101632&&e<=101640||e>=110576&&e<=110579||e>=110581&&e<=110587||e===110589||e===110590||e>=110592&&e<=110882||e===110898||e>=110928&&e<=110930||e===110933||e>=110948&&e<=110951||e>=110960&&e<=111355||e===126980||e===127183||e===127374||e>=127377&&e<=127386||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e===127568||e===127569||e>=127584&&e<=127589||e>=127744&&e<=127776||e>=127789&&e<=127797||e>=127799&&e<=127868||e>=127870&&e<=127891||e>=127904&&e<=127946||e>=127951&&e<=127955||e>=127968&&e<=127984||e===127988||e>=127992&&e<=128062||e===128064||e>=128066&&e<=128252||e>=128255&&e<=128317||e>=128331&&e<=128334||e>=128336&&e<=128359||e===128378||e===128405||e===128406||e===128420||e>=128507&&e<=128591||e>=128640&&e<=128709||e===128716||e>=128720&&e<=128722||e>=128725&&e<=128727||e>=128732&&e<=128735||e===128747||e===128748||e>=128756&&e<=128764||e>=128992&&e<=129003||e===129008||e>=129292&&e<=129338||e>=129340&&e<=129349||e>=129351&&e<=129535||e>=129648&&e<=129660||e>=129664&&e<=129672||e>=129680&&e<=129725||e>=129727&&e<=129733||e>=129742&&e<=129755||e>=129760&&e<=129768||e>=129776&&e<=129784||e>=131072&&e<=196605||e>=196608&&e<=262141,vi=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y,Ot=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,At=/\t{1,1000}/y,wi=new RegExp("[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F\\u20E3?))*","yu"),Rt=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Rr=new RegExp("\\p{M}+","gu"),Ir={limit:1/0,ellipsis:""},ks=(e,t={},i={})=>{let s=t.limit??1/0,n=t.ellipsis??"",r=t?.ellipsisWidth??(n?ks(n,Ir,i).width:0),o=i.ansiWidth??0,a=i.controlWidth??0,l=i.tabWidth??8,m=i.ambiguousWidth??1,d=i.emojiWidth??2,u=i.fullWidthWidth??2,y=i.regularWidth??1,k=i.wideWidth??2,g=0,p=0,$=e.length,_=0,A=!1,T=$,M=Math.max(0,s-r),F=0,R=0,C=0,I=0;e:for(;;){if(R>F||p>=$&&p>g){let G=e.slice(F,R)||e.slice(g,p);_=0;for(let J of G.replaceAll(Rr,"")){let le=J.codePointAt(0)||0;if(Or(le)?I=u:Ar(le)?I=k:m!==y&&Cr(le)?I=m:I=y,C+I>M&&(T=Math.min(T,Math.max(F,g)+_)),C+I>s){A=!0;break e}_+=J.length,C+=I}F=R=0}if(p>=$)break;if(Rt.lastIndex=p,Rt.test(e)){if(_=Rt.lastIndex-p,I=_*y,C+I>M&&(T=Math.min(T,p+Math.floor((M-C)/y))),C+I>s){A=!0;break}C+=I,F=g,R=p,p=g=Rt.lastIndex;continue}if(vi.lastIndex=p,vi.test(e)){if(C+o>M&&(T=Math.min(T,p)),C+o>s){A=!0;break}C+=o,F=g,R=p,p=g=vi.lastIndex;continue}if(Ot.lastIndex=p,Ot.test(e)){if(_=Ot.lastIndex-p,I=_*a,C+I>M&&(T=Math.min(T,p+Math.floor((M-C)/a))),C+I>s){A=!0;break}C+=I,F=g,R=p,p=g=Ot.lastIndex;continue}if(At.lastIndex=p,At.test(e)){if(_=At.lastIndex-p,I=_*l,C+I>M&&(T=Math.min(T,p+Math.floor((M-C)/l))),C+I>s){A=!0;break}C+=I,F=g,R=p,p=g=At.lastIndex;continue}if(wi.lastIndex=p,wi.test(e)){if(C+d>M&&(T=Math.min(T,p)),C+d>s){A=!0;break}C+=d,F=g,R=p,p=g=wi.lastIndex;continue}p+=1}return{width:A?M:C,index:A?T:$,truncated:A,ellipsed:A&&s>=r}},Er={limit:1/0,ellipsis:"",ellipsisWidth:0},it=(e,t={})=>ks(e,Er,t).width,Pt="\x1B",js="\x9B",Tr=39,Ci="\x07",Cs="[",Pr="]",Os="m",Oi=`${Pr}8;;`,bs=new RegExp(`(?:\\${Cs}(?<code>\\d+)m|\\${Oi}(?<uri>.*)${Ci})`,"y"),Dr=e=>{if(e>=30&&e<=37||e>=90&&e<=97)return 39;if(e>=40&&e<=47||e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0},vs=e=>`${Pt}${Cs}${e}${Os}`,ws=e=>`${Pt}${Oi}${e}${Ci}`,Nr=e=>e.map(t=>it(t)),_i=(e,t,i)=>{let s=t[Symbol.iterator](),n=!1,r=!1,o=e.at(-1),a=o===void 0?0:it(o),l=s.next(),m=s.next(),d=0;for(;!l.done;){let u=l.value,y=it(u);a+y<=i?e[e.length-1]+=u:(e.push(u),a=0),(u===Pt||u===js)&&(n=!0,r=t.startsWith(Oi,d+1)),n?r?u===Ci&&(n=!1,r=!1):u===Os&&(n=!1):(a+=y,a===i&&!m.done&&(e.push(""),a=0)),l=m,m=s.next(),d+=u.length}o=e.at(-1),!a&&o!==void 0&&o.length>0&&e.length>1&&(e[e.length-2]+=e.pop())},Fr=e=>{let t=e.split(" "),i=t.length;for(;i>0&&!(it(t[i-1])>0);)i--;return i===t.length?e:t.slice(0,i).join(" ")+t.slice(i).join("")},Vr=(e,t,i={})=>{if(i.trim!==!1&&e.trim()==="")return"";let s="",n,r,o=e.split(" "),a=Nr(o),l=[""];for(let[g,p]of o.entries()){i.trim!==!1&&(l[l.length-1]=(l.at(-1)??"").trimStart());let $=it(l.at(-1)??"");if(g!==0&&($>=t&&(i.wordWrap===!1||i.trim===!1)&&(l.push(""),$=0),($>0||i.trim===!1)&&(l[l.length-1]+=" ",$++)),i.hard&&a[g]>t){let _=t-$,A=1+Math.floor((a[g]-_-1)/t);Math.floor((a[g]-1)/t)<A&&l.push(""),_i(l,p,t);continue}if($+a[g]>t&&$>0&&a[g]>0){if(i.wordWrap===!1&&$<t){_i(l,p,t);continue}l.push("")}if($+a[g]>t&&i.wordWrap===!1){_i(l,p,t);continue}l[l.length-1]+=p}i.trim!==!1&&(l=l.map(g=>Fr(g)));let m=l.join(`
44
- `),d=m[Symbol.iterator](),u=d.next(),y=d.next(),k=0;for(;!u.done;){let g=u.value,p=y.value;if(s+=g,g===Pt||g===js){bs.lastIndex=k+1;let _=bs.exec(m)?.groups;if(_?.code!==void 0){let A=Number.parseFloat(_.code);n=A===Tr?void 0:A}else _?.uri!==void 0&&(r=_.uri.length===0?void 0:_.uri)}let $=n?Dr(n):void 0;p===`
45
- `?(r&&(s+=ws("")),n&&$&&(s+=vs($))):g===`
46
- `&&(n&&$&&(s+=vs(n)),r&&(s+=ws(r))),k+=g.length,u=y,y=d.next()}return s};function ki(e,t,i){return String(e).normalize().replaceAll(`\r
43
+ `)),this._prevFrame=t;return}}this.output.write(xe.erase.down())}this.output.write(t),this.state==="initial"&&(this.state="active"),this._prevFrame=t}}};Nt=class extends Be{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#e=0;#i="";#s;#t;get cursor(){return this.#e}get userInputWithCursor(){if(!this.userInput)return(0,St.styleText)(["inverse","hidden"],"_");if(this._cursor>=this.userInput.length)return`${this.userInput}\u2588`;let t=this.userInput.slice(0,this._cursor),[i,...s]=this.userInput.slice(this._cursor);return`${t}${(0,St.styleText)("inverse",i)}${s.join("")}`}get options(){return typeof this.#t=="function"?this.#t():this.#t}constructor(t){super(t),this.#t=t.options;let i=this.options;this.filteredOptions=[...i],this.multiple=t.multiple===!0,this.#s=t.filter??Go;let s;if(t.initialValue&&Array.isArray(t.initialValue)?this.multiple?s=t.initialValue:s=t.initialValue.slice(0,1):!this.multiple&&this.options.length>0&&(s=[this.options[0].value]),s)for(let n of s){let r=i.findIndex(o=>o.value===n);r!==-1&&(this.toggleSelected(n),this.#e=r)}this.focusedValue=this.options[this.#e]?.value,this.on("key",(n,r)=>this.#n(n,r)),this.on("userInput",n=>this.#r(n))}_isActionKey(t,i){return t===" "||this.multiple&&this.isNavigating&&i.name==="space"&&t!==void 0&&t!==""}#n(t,i){let s=i.name==="up",n=i.name==="down",r=i.name==="return";s||n?(this.#e=Qe(this.#e,s?-1:1,this.filteredOptions),this.focusedValue=this.filteredOptions[this.#e]?.value,this.multiple||(this.selectedValues=[this.focusedValue]),this.isNavigating=!0):r?this.value=zo(this.multiple,this.selectedValues):this.multiple?this.focusedValue!==void 0&&(i.name==="tab"||this.isNavigating&&i.name==="space")?this.toggleSelected(this.focusedValue):this.isNavigating=!1:(this.focusedValue&&(this.selectedValues=[this.focusedValue]),this.isNavigating=!1)}deselectAll(){this.selectedValues=[]}toggleSelected(t){this.filteredOptions.length!==0&&(this.multiple?this.selectedValues.includes(t)?this.selectedValues=this.selectedValues.filter(i=>i!==t):this.selectedValues=[...this.selectedValues,t]:this.selectedValues=[t])}#r(t){if(t!==this.#i){this.#i=t;let i=this.options;t?this.filteredOptions=i.filter(r=>this.#s(t,r)):this.filteredOptions=[...i];let s=Bo(this.focusedValue,this.filteredOptions);this.#e=Qe(s,0,this.filteredOptions);let n=this.filteredOptions[this.#e];n&&!n.disabled?this.focusedValue=n.value:this.focusedValue=void 0,this.multiple||(this.focusedValue!==void 0?this.toggleSelected(this.focusedValue):this.deselectAll())}}},ci=class extends Be{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(t){super(t,!1),this.value=!!t.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",i=>{this.output.write(xe.cursor.move(0,-1)),this.value=i,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}},di=class extends Be{options;cursor=0;#e;getGroupItems(t){return this.options.filter(i=>i.group===t)}isGroupSelected(t){let i=this.getGroupItems(t),s=this.value;return s===void 0?!1:i.every(n=>s.includes(n.value))}toggleValue(){let t=this.options[this.cursor];if(this.value===void 0&&(this.value=[]),t.group===!0){let i=t.value,s=this.getGroupItems(i);this.isGroupSelected(i)?this.value=this.value.filter(n=>s.findIndex(r=>r.value===n)===-1):this.value=[...this.value,...s.map(n=>n.value)],this.value=Array.from(new Set(this.value))}else{let i=this.value.includes(t.value);this.value=i?this.value.filter(s=>s!==t.value):[...this.value,t.value]}}constructor(t){super(t,!1);let{options:i}=t;this.#e=t.selectableGroups!==!1,this.options=Object.entries(i).flatMap(([s,n])=>[{value:s,group:!0,label:s},...n.map(r=>({...r,group:s}))]),this.value=[...t.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:s})=>s===t.cursorAt),this.#e?0:1),this.on("cursor",s=>{switch(s){case"left":case"up":{this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;let n=this.options[this.cursor]?.group===!0;!this.#e&&n&&(this.cursor=this.cursor===0?this.options.length-1:this.cursor-1);break}case"down":case"right":{this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;let n=this.options[this.cursor]?.group===!0;!this.#e&&n&&(this.cursor=this.cursor===this.options.length-1?0:this.cursor+1);break}case"space":this.toggleValue();break}})}},En=class extends Be{options;cursor=0;get _value(){return this.options[this.cursor].value}get _enabledOptions(){return this.options.filter(e=>e.disabled!==!0)}toggleAll(){let e=this._enabledOptions,t=this.value!==void 0&&this.value.length===e.length;this.value=t?[]:e.map(i=>i.value)}toggleInvert(){let e=this.value;if(!e)return;let t=this._enabledOptions.filter(i=>!e.includes(i.value));this.value=t.map(i=>i.value)}toggleValue(){this.value===void 0&&(this.value=[]);let e=this.value.includes(this._value);this.value=e?this.value.filter(t=>t!==this._value):[...this.value,this._value]}constructor(e){super(e,!1),this.options=e.options,this.value=[...e.initialValues??[]];let t=Math.max(this.options.findIndex(({value:i})=>i===e.cursorAt),0);this.cursor=this.options[t].disabled?Qe(t,1,this.options):t,this.on("key",i=>{i==="a"&&this.toggleAll(),i==="i"&&this.toggleInvert()}),this.on("cursor",i=>{switch(i){case"left":case"up":this.cursor=Qe(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=Qe(this.cursor,1,this.options);break;case"space":this.toggleValue();break}})}},ui=class extends Be{_mask="\u2022";get cursor(){return this._cursor}get masked(){return this.userInput.replaceAll(/./g,this._mask)}get userInputWithCursor(){if(this.state==="submit"||this.state==="cancel")return this.masked;let t=this.userInput;if(this.cursor>=t.length)return`${this.masked}${(0,St.styleText)(["inverse","hidden"],"_")}`;let i=this.masked,s=i.slice(0,this.cursor),n=i.slice(this.cursor);return`${s}${(0,St.styleText)("inverse",n[0])}${n.slice(1)}`}clear(){this._clearUserInput()}constructor({mask:t,...i}){super(i),this._mask=t??"\u2022",this.on("userInput",s=>{this._setValue(s)})}},mi=class extends Be{options;cursor=0;get _selectedValue(){return this.options[this.cursor]}changeValue(){this.value=this._selectedValue.value}constructor(t){super(t,!1),this.options=t.options;let i=this.options.findIndex(({value:n})=>n===t.initialValue),s=i===-1?0:i;this.cursor=this.options[s].disabled?Qe(s,1,this.options):s,this.changeValue(),this.on("cursor",n=>{switch(n){case"left":case"up":this.cursor=Qe(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=Qe(this.cursor,1,this.options);break}this.changeValue()})}},fi=class extends Be{options;cursor=0;constructor(t){super(t,!1),this.options=t.options;let i=t.caseSensitive===!0,s=this.options.map(({value:[n]})=>i?n:n?.toLowerCase());this.cursor=Math.max(s.indexOf(t.initialValue),0),this.on("key",(n,r)=>{if(!n)return;let o=i&&r.shift?n.toUpperCase():n;if(!s.includes(o))return;let a=this.options.find(({value:[l]})=>i?l===o:l?.toLowerCase()===n);a&&(this.value=a.value,this.state="submit",this.emit("submit"))})}},hi=class extends Be{get userInputWithCursor(){if(this.state==="submit")return this.userInput;let t=this.userInput;if(this.cursor>=t.length)return`${this.userInput}\u2588`;let i=t.slice(0,this.cursor),[s,...n]=t.slice(this.cursor);return`${i}${(0,St.styleText)("inverse",s)}${n.join("")}`}get cursor(){return this._cursor}constructor(t){super({...t,initialUserInput:t.initialUserInput??t.initialValue}),this.on("userInput",i=>{this._setValue(i)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}}});var Ps={};xt(Ps,{S_BAR:()=>O,S_BAR_END:()=>$e,S_BAR_END_RIGHT:()=>Wn,S_BAR_H:()=>_i,S_BAR_START:()=>_s,S_BAR_START_RIGHT:()=>qn,S_CHECKBOX_ACTIVE:()=>wi,S_CHECKBOX_INACTIVE:()=>Ct,S_CHECKBOX_SELECTED:()=>pt,S_CONNECT_LEFT:()=>Jn,S_CORNER_BOTTOM_LEFT:()=>Ss,S_CORNER_BOTTOM_RIGHT:()=>ks,S_CORNER_TOP_LEFT:()=>Bn,S_CORNER_TOP_RIGHT:()=>xs,S_ERROR:()=>As,S_INFO:()=>js,S_PASSWORD_MASK:()=>Hn,S_RADIO_ACTIVE:()=>Mt,S_RADIO_INACTIVE:()=>$t,S_STEP_ACTIVE:()=>Ln,S_STEP_CANCEL:()=>vs,S_STEP_ERROR:()=>ws,S_STEP_SUBMIT:()=>yt,S_SUCCESS:()=>Cs,S_WARN:()=>Os,autocomplete:()=>Xn,autocompleteMultiselect:()=>da,box:()=>ha,cancel:()=>$a,confirm:()=>Ue,group:()=>pa,groupMultiselect:()=>ga,intro:()=>ya,isCI:()=>bs,isCancel:()=>oe,isTTY:()=>Un,limitOptions:()=>At,log:()=>Te,multiselect:()=>va,note:()=>xa,outro:()=>ba,password:()=>ka,path:()=>Sa,progress:()=>Ca,select:()=>We,selectKey:()=>Oa,settings:()=>re,spinner:()=>Ut,stream:()=>ht,symbol:()=>qe,symbolBar:()=>Rs,taskLog:()=>Ia,tasks:()=>Aa,text:()=>Re,unicode:()=>vi,unicodeOr:()=>se,updateSettings:()=>Rn});function Ko(){return Pe.default.platform!=="win32"?Pe.default.env.TERM!=="linux":!!Pe.default.env.CI||!!Pe.default.env.WT_SESSION||!!Pe.default.env.TERMINUS_SUBLIME||Pe.default.env.ConEmuTask==="{cmd::Cmder}"||Pe.default.env.TERM_PROGRAM==="Terminus-Sublime"||Pe.default.env.TERM_PROGRAM==="vscode"||Pe.default.env.TERM==="xterm-256color"||Pe.default.env.TERM==="alacritty"||Pe.default.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}function Ot(e,t,i){return String(e).normalize().replaceAll(`\r
47
44
  `,`
48
45
  `).split(`
49
- `).map(s=>Vr(s,t,i)).join(`
50
- `)}var Mr=(e,t,i,s,n)=>{let r=t,o=0;for(let a=i;a<s;a++){let l=e[a];if(r=r-l.length,o++,r<=n)break}return{lineCount:r,removals:o}},Ur=({cursor:e,options:t,style:i,output:s=process.stdout,maxItems:n=Number.POSITIVE_INFINITY,columnPadding:r=0,rowPadding:o=4})=>{let a=jt(s)-r,l=bi(s),m=(0,O.styleText)("dim","..."),d=Math.max(l-o,0),u=Math.max(Math.min(n,d),5),y=0;e>=u-3&&(y=Math.max(Math.min(e-u+3,t.length-u),0));let k=u<t.length&&y>0,g=u<t.length&&y+u<t.length,p=Math.min(y+u,t.length),$=[],_=0;k&&_++,g&&_++;let A=y+(k?1:0),T=p-(g?1:0);for(let F=A;F<T;F++){let R=ki(i(t[F],F===e),a,{hard:!0,trim:!1}).split(`
51
- `);$.push(R),_+=R.length}if(_>d){let F=0,R=0,C=_,I=e-A,G=(J,le)=>Mr($,C,J,le,d);k?({lineCount:C,removals:F}=G(0,I),C>d&&({lineCount:C,removals:R}=G(I+1,$.length))):({lineCount:C,removals:R}=G(I+1,$.length),C>d&&({lineCount:C,removals:F}=G(0,I))),F>0&&(k=!0,$.splice(0,F)),R>0&&(g=!0,$.splice($.length-R,R))}let M=[];k&&M.push(m);for(let F of $)for(let R of F)M.push(R);return g&&M.push(m),M};var je=e=>{let t=e.active??"Yes",i=e.inactive??"No";return new _t({active:t,inactive:i,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue??!0,render(){let s=e.withGuide??fe.withGuide,n=`${s?`${(0,O.styleText)("gray",X)}
52
- `:""}${ji(this.state)} ${e.message}
53
- `,r=this.value?t:i;switch(this.state){case"submit":{let o=s?`${(0,O.styleText)("gray",X)} `:"";return`${n}${o}${(0,O.styleText)("dim",r)}`}case"cancel":{let o=s?`${(0,O.styleText)("gray",X)} `:"";return`${n}${o}${(0,O.styleText)(["strikethrough","dim"],r)}${s?`
54
- ${(0,O.styleText)("gray",X)}`:""}`}default:{let o=s?`${(0,O.styleText)("cyan",X)} `:"",a=s?(0,O.styleText)("cyan",Et):"";return`${n}${o}${this.value?`${(0,O.styleText)("green",Si)} ${t}`:`${(0,O.styleText)("dim",Tt)} ${(0,O.styleText)("dim",t)}`}${e.vertical?s?`
55
- ${(0,O.styleText)("cyan",X)} `:`
56
- `:` ${(0,O.styleText)("dim","/")} `}${this.value?`${(0,O.styleText)("dim",Tt)} ${(0,O.styleText)("dim",i)}`:`${(0,O.styleText)("green",Si)} ${i}`}
46
+ `).map(s=>aa(s,t,i)).join(`
47
+ `)}function Nn(e){return e.label??String(e.value??"")}function Zn(e,t){if(!e)return!0;let i=(t.label??String(t.value??"")).toLowerCase(),s=(t.hint??"").toLowerCase(),n=String(t.value).toLowerCase(),r=e.toLowerCase();return i.includes(r)||s.includes(r)||n.includes(r)}function ca(e,t){let i=[];for(let s of t)e.includes(s.value)&&i.push(s);return i}function Fn(e,t,i,s){let n=i,r=i;return s==="center"?n=Math.floor((t-e)/2):s==="right"&&(n=t-e-i),r=t-n-e,[n,r]}function Ca({style:e="heavy",max:t=100,size:i=40,...s}={}){let n=Ut(s),r=0,o="",a=Math.max(1,t),l=Math.max(1,i),c=v=>{switch(v){case"initial":case"active":return $=>(0,d.styleText)("magenta",$);case"error":case"cancel":return $=>(0,d.styleText)("red",$);case"submit":return $=>(0,d.styleText)("green",$);default:return $=>(0,d.styleText)("magenta",$)}},u=(v,$)=>{let m=Math.floor(r/a*l);return`${c(v)(Vn[e].repeat(m))}${(0,d.styleText)("dim",Vn[e].repeat(l-m))} ${$}`},f=(v="")=>{o=v,n.start(u("initial",v))},p=(v=1,$)=>{r=Math.min(a,v+r),n.message(u("active",$??o)),o=$??o};return{start:f,stop:n.stop,cancel:n.cancel,error:n.error,clear:n.clear,advance:p,isCancelled:n.isCancelled,message:v=>p(0,v)}}var d,Pe,gt,Vt,jt,vi,bs,Un,se,Ln,vs,ws,yt,_s,O,$e,qn,Wn,Mt,$t,wi,pt,Ct,Hn,_i,xs,Jn,ks,Ss,Bn,js,Cs,Os,As,qe,Rs,Yo,Zo,Xo,gs,gi,$i,$s,yi,Qo,ea,Gn,ta,Ce,xi,zn,ia,Is,Kn,sa,Yn,Es,Pn,na,Tn,Dn,ra,ys,oa,aa,la,At,Xn,da,ua,ma,fa,ha,Ue,pa,ga,Te,$a,ya,ba,Ft,va,wa,_a,xa,ka,Sa,ja,Ut,Vn,bi,We,Oa,Mn,ht,Aa,Ra,Ia,Re,Oe=Ee(()=>{ps();ps();d=require("node:util"),Pe=M(require("node:process"),1),gt=require("node:fs"),Vt=require("node:path"),jt=M(ns(),1);vi=Ko(),bs=()=>process.env.CI==="true",Un=e=>e.isTTY===!0,se=(e,t)=>vi?e:t,Ln=se("\u25C6","*"),vs=se("\u25A0","x"),ws=se("\u25B2","x"),yt=se("\u25C7","o"),_s=se("\u250C","T"),O=se("\u2502","|"),$e=se("\u2514","\u2014"),qn=se("\u2510","T"),Wn=se("\u2518","\u2014"),Mt=se("\u25CF",">"),$t=se("\u25CB"," "),wi=se("\u25FB","[\u2022]"),pt=se("\u25FC","[+]"),Ct=se("\u25FB","[ ]"),Hn=se("\u25AA","\u2022"),_i=se("\u2500","-"),xs=se("\u256E","+"),Jn=se("\u251C","+"),ks=se("\u256F","+"),Ss=se("\u2570","+"),Bn=se("\u256D","+"),js=se("\u25CF","\u2022"),Cs=se("\u25C6","*"),Os=se("\u25B2","!"),As=se("\u25A0","x"),qe=e=>{switch(e){case"initial":case"active":return(0,d.styleText)("cyan",Ln);case"cancel":return(0,d.styleText)("red",vs);case"error":return(0,d.styleText)("yellow",ws);case"submit":return(0,d.styleText)("green",yt)}},Rs=e=>{switch(e){case"initial":case"active":return(0,d.styleText)("cyan",O);case"cancel":return(0,d.styleText)("red",O);case"error":return(0,d.styleText)("yellow",O);case"submit":return(0,d.styleText)("green",O)}},Yo=e=>e===161||e===164||e===167||e===168||e===170||e===173||e===174||e>=176&&e<=180||e>=182&&e<=186||e>=188&&e<=191||e===198||e===208||e===215||e===216||e>=222&&e<=225||e===230||e>=232&&e<=234||e===236||e===237||e===240||e===242||e===243||e>=247&&e<=250||e===252||e===254||e===257||e===273||e===275||e===283||e===294||e===295||e===299||e>=305&&e<=307||e===312||e>=319&&e<=322||e===324||e>=328&&e<=331||e===333||e===338||e===339||e===358||e===359||e===363||e===462||e===464||e===466||e===468||e===470||e===472||e===474||e===476||e===593||e===609||e===708||e===711||e>=713&&e<=715||e===717||e===720||e>=728&&e<=731||e===733||e===735||e>=768&&e<=879||e>=913&&e<=929||e>=931&&e<=937||e>=945&&e<=961||e>=963&&e<=969||e===1025||e>=1040&&e<=1103||e===1105||e===8208||e>=8211&&e<=8214||e===8216||e===8217||e===8220||e===8221||e>=8224&&e<=8226||e>=8228&&e<=8231||e===8240||e===8242||e===8243||e===8245||e===8251||e===8254||e===8308||e===8319||e>=8321&&e<=8324||e===8364||e===8451||e===8453||e===8457||e===8467||e===8470||e===8481||e===8482||e===8486||e===8491||e===8531||e===8532||e>=8539&&e<=8542||e>=8544&&e<=8555||e>=8560&&e<=8569||e===8585||e>=8592&&e<=8601||e===8632||e===8633||e===8658||e===8660||e===8679||e===8704||e===8706||e===8707||e===8711||e===8712||e===8715||e===8719||e===8721||e===8725||e===8730||e>=8733&&e<=8736||e===8739||e===8741||e>=8743&&e<=8748||e===8750||e>=8756&&e<=8759||e===8764||e===8765||e===8776||e===8780||e===8786||e===8800||e===8801||e>=8804&&e<=8807||e===8810||e===8811||e===8814||e===8815||e===8834||e===8835||e===8838||e===8839||e===8853||e===8857||e===8869||e===8895||e===8978||e>=9312&&e<=9449||e>=9451&&e<=9547||e>=9552&&e<=9587||e>=9600&&e<=9615||e>=9618&&e<=9621||e===9632||e===9633||e>=9635&&e<=9641||e===9650||e===9651||e===9654||e===9655||e===9660||e===9661||e===9664||e===9665||e>=9670&&e<=9672||e===9675||e>=9678&&e<=9681||e>=9698&&e<=9701||e===9711||e===9733||e===9734||e===9737||e===9742||e===9743||e===9756||e===9758||e===9792||e===9794||e===9824||e===9825||e>=9827&&e<=9829||e>=9831&&e<=9834||e===9836||e===9837||e===9839||e===9886||e===9887||e===9919||e>=9926&&e<=9933||e>=9935&&e<=9939||e>=9941&&e<=9953||e===9955||e===9960||e===9961||e>=9963&&e<=9969||e===9972||e>=9974&&e<=9977||e===9979||e===9980||e===9982||e===9983||e===10045||e>=10102&&e<=10111||e>=11094&&e<=11097||e>=12872&&e<=12879||e>=57344&&e<=63743||e>=65024&&e<=65039||e===65533||e>=127232&&e<=127242||e>=127248&&e<=127277||e>=127280&&e<=127337||e>=127344&&e<=127373||e===127375||e===127376||e>=127387&&e<=127404||e>=917760&&e<=917999||e>=983040&&e<=1048573||e>=1048576&&e<=1114109,Zo=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,Xo=e=>e>=4352&&e<=4447||e===8986||e===8987||e===9001||e===9002||e>=9193&&e<=9196||e===9200||e===9203||e===9725||e===9726||e===9748||e===9749||e>=9800&&e<=9811||e===9855||e===9875||e===9889||e===9898||e===9899||e===9917||e===9918||e===9924||e===9925||e===9934||e===9940||e===9962||e===9970||e===9971||e===9973||e===9978||e===9981||e===9989||e===9994||e===9995||e===10024||e===10060||e===10062||e>=10067&&e<=10069||e===10071||e>=10133&&e<=10135||e===10160||e===10175||e===11035||e===11036||e===11088||e===11093||e>=11904&&e<=11929||e>=11931&&e<=12019||e>=12032&&e<=12245||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12353&&e<=12438||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=19968&&e<=42124||e>=42128&&e<=42182||e>=43360&&e<=43388||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=94176&&e<=94180||e===94192||e===94193||e>=94208&&e<=100343||e>=100352&&e<=101589||e>=101632&&e<=101640||e>=110576&&e<=110579||e>=110581&&e<=110587||e===110589||e===110590||e>=110592&&e<=110882||e===110898||e>=110928&&e<=110930||e===110933||e>=110948&&e<=110951||e>=110960&&e<=111355||e===126980||e===127183||e===127374||e>=127377&&e<=127386||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e===127568||e===127569||e>=127584&&e<=127589||e>=127744&&e<=127776||e>=127789&&e<=127797||e>=127799&&e<=127868||e>=127870&&e<=127891||e>=127904&&e<=127946||e>=127951&&e<=127955||e>=127968&&e<=127984||e===127988||e>=127992&&e<=128062||e===128064||e>=128066&&e<=128252||e>=128255&&e<=128317||e>=128331&&e<=128334||e>=128336&&e<=128359||e===128378||e===128405||e===128406||e===128420||e>=128507&&e<=128591||e>=128640&&e<=128709||e===128716||e>=128720&&e<=128722||e>=128725&&e<=128727||e>=128732&&e<=128735||e===128747||e===128748||e>=128756&&e<=128764||e>=128992&&e<=129003||e===129008||e>=129292&&e<=129338||e>=129340&&e<=129349||e>=129351&&e<=129535||e>=129648&&e<=129660||e>=129664&&e<=129672||e>=129680&&e<=129725||e>=129727&&e<=129733||e>=129742&&e<=129755||e>=129760&&e<=129768||e>=129776&&e<=129784||e>=131072&&e<=196605||e>=196608&&e<=262141,gs=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y,gi=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,$i=/\t{1,1000}/y,$s=new RegExp("[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F\\u20E3?))*","yu"),yi=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Qo=new RegExp("\\p{M}+","gu"),ea={limit:1/0,ellipsis:""},Gn=(e,t={},i={})=>{let s=t.limit??1/0,n=t.ellipsis??"",r=t?.ellipsisWidth??(n?Gn(n,ea,i).width:0),o=i.ansiWidth??0,a=i.controlWidth??0,l=i.tabWidth??8,c=i.ambiguousWidth??1,u=i.emojiWidth??2,f=i.fullWidthWidth??2,p=i.regularWidth??1,v=i.wideWidth??2,$=0,m=0,y=e.length,w=0,S=!1,A=y,F=Math.max(0,s-r),N=0,H=0,R=0,P=0;e:for(;;){if(H>N||m>=y&&m>$){let T=e.slice(N,H)||e.slice($,m);w=0;for(let J of T.replaceAll(Qo,"")){let Y=J.codePointAt(0)||0;if(Zo(Y)?P=f:Xo(Y)?P=v:c!==p&&Yo(Y)?P=c:P=p,R+P>F&&(A=Math.min(A,Math.max(N,$)+w)),R+P>s){S=!0;break e}w+=J.length,R+=P}N=H=0}if(m>=y)break;if(yi.lastIndex=m,yi.test(e)){if(w=yi.lastIndex-m,P=w*p,R+P>F&&(A=Math.min(A,m+Math.floor((F-R)/p))),R+P>s){S=!0;break}R+=P,N=$,H=m,m=$=yi.lastIndex;continue}if(gs.lastIndex=m,gs.test(e)){if(R+o>F&&(A=Math.min(A,m)),R+o>s){S=!0;break}R+=o,N=$,H=m,m=$=gs.lastIndex;continue}if(gi.lastIndex=m,gi.test(e)){if(w=gi.lastIndex-m,P=w*a,R+P>F&&(A=Math.min(A,m+Math.floor((F-R)/a))),R+P>s){S=!0;break}R+=P,N=$,H=m,m=$=gi.lastIndex;continue}if($i.lastIndex=m,$i.test(e)){if(w=$i.lastIndex-m,P=w*l,R+P>F&&(A=Math.min(A,m+Math.floor((F-R)/l))),R+P>s){S=!0;break}R+=P,N=$,H=m,m=$=$i.lastIndex;continue}if($s.lastIndex=m,$s.test(e)){if(R+u>F&&(A=Math.min(A,m)),R+u>s){S=!0;break}R+=u,N=$,H=m,m=$=$s.lastIndex;continue}m+=1}return{width:S?F:R,index:S?A:y,truncated:S,ellipsed:S&&s>=r}},ta={limit:1/0,ellipsis:"",ellipsisWidth:0},Ce=(e,t={})=>Gn(e,ta,t).width,xi="\x1B",zn="\x9B",ia=39,Is="\x07",Kn="[",sa="]",Yn="m",Es=`${sa}8;;`,Pn=new RegExp(`(?:\\${Kn}(?<code>\\d+)m|\\${Es}(?<uri>.*)${Is})`,"y"),na=e=>{if(e>=30&&e<=37||e>=90&&e<=97)return 39;if(e>=40&&e<=47||e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0},Tn=e=>`${xi}${Kn}${e}${Yn}`,Dn=e=>`${xi}${Es}${e}${Is}`,ra=e=>e.map(t=>Ce(t)),ys=(e,t,i)=>{let s=t[Symbol.iterator](),n=!1,r=!1,o=e.at(-1),a=o===void 0?0:Ce(o),l=s.next(),c=s.next(),u=0;for(;!l.done;){let f=l.value,p=Ce(f);a+p<=i?e[e.length-1]+=f:(e.push(f),a=0),(f===xi||f===zn)&&(n=!0,r=t.startsWith(Es,u+1)),n?r?f===Is&&(n=!1,r=!1):f===Yn&&(n=!1):(a+=p,a===i&&!c.done&&(e.push(""),a=0)),l=c,c=s.next(),u+=f.length}o=e.at(-1),!a&&o!==void 0&&o.length>0&&e.length>1&&(e[e.length-2]+=e.pop())},oa=e=>{let t=e.split(" "),i=t.length;for(;i>0&&!(Ce(t[i-1])>0);)i--;return i===t.length?e:t.slice(0,i).join(" ")+t.slice(i).join("")},aa=(e,t,i={})=>{if(i.trim!==!1&&e.trim()==="")return"";let s="",n,r,o=e.split(" "),a=ra(o),l=[""];for(let[$,m]of o.entries()){i.trim!==!1&&(l[l.length-1]=(l.at(-1)??"").trimStart());let y=Ce(l.at(-1)??"");if($!==0&&(y>=t&&(i.wordWrap===!1||i.trim===!1)&&(l.push(""),y=0),(y>0||i.trim===!1)&&(l[l.length-1]+=" ",y++)),i.hard&&a[$]>t){let w=t-y,S=1+Math.floor((a[$]-w-1)/t);Math.floor((a[$]-1)/t)<S&&l.push(""),ys(l,m,t);continue}if(y+a[$]>t&&y>0&&a[$]>0){if(i.wordWrap===!1&&y<t){ys(l,m,t);continue}l.push("")}if(y+a[$]>t&&i.wordWrap===!1){ys(l,m,t);continue}l[l.length-1]+=m}i.trim!==!1&&(l=l.map($=>oa($)));let c=l.join(`
48
+ `),u=c[Symbol.iterator](),f=u.next(),p=u.next(),v=0;for(;!f.done;){let $=f.value,m=p.value;if(s+=$,$===xi||$===zn){Pn.lastIndex=v+1;let w=Pn.exec(c)?.groups;if(w?.code!==void 0){let S=Number.parseFloat(w.code);n=S===ia?void 0:S}else w?.uri!==void 0&&(r=w.uri.length===0?void 0:w.uri)}let y=n?na(n):void 0;m===`
49
+ `?(r&&(s+=Dn("")),n&&y&&(s+=Tn(y))):$===`
50
+ `&&(n&&y&&(s+=Tn(n)),r&&(s+=Dn(r))),v+=$.length,f=p,p=u.next()}return s};la=(e,t,i,s,n)=>{let r=t,o=0;for(let a=i;a<s;a++){let l=e[a];if(r=r-l.length,o++,r<=n)break}return{lineCount:r,removals:o}},At=({cursor:e,options:t,style:i,output:s=process.stdout,maxItems:n=Number.POSITIVE_INFINITY,columnPadding:r=0,rowPadding:o=4})=>{let a=ft(s)-r,l=hs(s),c=(0,d.styleText)("dim","..."),u=Math.max(l-o,0),f=Math.max(Math.min(n,u),5),p=0;e>=f-3&&(p=Math.max(Math.min(e-f+3,t.length-f),0));let v=f<t.length&&p>0,$=f<t.length&&p+f<t.length,m=Math.min(p+f,t.length),y=[],w=0;v&&w++,$&&w++;let S=p+(v?1:0),A=m-($?1:0);for(let N=S;N<A;N++){let H=Ot(i(t[N],N===e),a,{hard:!0,trim:!1}).split(`
51
+ `);y.push(H),w+=H.length}if(w>u){let N=0,H=0,R=w,P=e-S,T=(J,Y)=>la(y,R,J,Y,u);v?({lineCount:R,removals:N}=T(0,P),R>u&&({lineCount:R,removals:H}=T(P+1,y.length))):({lineCount:R,removals:H}=T(P+1,y.length),R>u&&({lineCount:R,removals:N}=T(0,P))),N>0&&(v=!0,y.splice(0,N)),H>0&&($=!0,y.splice(y.length-H,H))}let F=[];v&&F.push(c);for(let N of y)for(let H of N)F.push(H);return $&&F.push(c),F};Xn=e=>new Nt({options:e.options,initialValue:e.initialValue?[e.initialValue]:void 0,initialUserInput:e.initialUserInput,filter:e.filter??((t,i)=>Zn(t,i)),signal:e.signal,input:e.input,output:e.output,validate:e.validate,render(){let t=e.withGuide??re.withGuide,i=t?[`${(0,d.styleText)("gray",O)}`,`${qe(this.state)} ${e.message}`]:[`${qe(this.state)} ${e.message}`],s=this.userInput,n=this.options,r=e.placeholder,o=s===""&&r!==void 0,a=(l,c)=>{let u=Nn(l),f=l.hint&&l.value===this.focusedValue?(0,d.styleText)("dim",` (${l.hint})`):"";switch(c){case"active":return`${(0,d.styleText)("green",Mt)} ${u}${f}`;case"inactive":return`${(0,d.styleText)("dim",$t)} ${(0,d.styleText)("dim",u)}`;case"disabled":return`${(0,d.styleText)("gray",$t)} ${(0,d.styleText)(["strikethrough","gray"],u)}`}};switch(this.state){case"submit":{let l=ca(this.selectedValues,n),c=l.length>0?` ${(0,d.styleText)("dim",l.map(Nn).join(", "))}`:"",u=t?(0,d.styleText)("gray",O):"";return`${i.join(`
52
+ `)}
53
+ ${u}${c}`}case"cancel":{let l=s?` ${(0,d.styleText)(["strikethrough","dim"],s)}`:"",c=t?(0,d.styleText)("gray",O):"";return`${i.join(`
54
+ `)}
55
+ ${c}${l}`}default:{let l=this.state==="error"?"yellow":"cyan",c=t?`${(0,d.styleText)(l,O)} `:"",u=t?(0,d.styleText)(l,$e):"",f="";if(this.isNavigating||o){let S=o?r:s;f=S!==""?` ${(0,d.styleText)("dim",S)}`:""}else f=` ${this.userInputWithCursor}`;let p=this.filteredOptions.length!==n.length?(0,d.styleText)("dim",` (${this.filteredOptions.length} match${this.filteredOptions.length===1?"":"es"})`):"",v=this.filteredOptions.length===0&&s?[`${c}${(0,d.styleText)("yellow","No matches found")}`]:[],$=this.state==="error"?[`${c}${(0,d.styleText)("yellow",this.error)}`]:[];t&&i.push(`${c.trimEnd()}`),i.push(`${c}${(0,d.styleText)("dim","Search:")}${f}${p}`,...v,...$);let m=[`${(0,d.styleText)("dim","\u2191/\u2193")} to select`,`${(0,d.styleText)("dim","Enter:")} confirm`,`${(0,d.styleText)("dim","Type:")} to search`],y=[`${c}${m.join(" \u2022 ")}`,u],w=this.filteredOptions.length===0?[]:At({cursor:this.cursor,options:this.filteredOptions,columnPadding:t?3:0,rowPadding:i.length+y.length,style:(S,A)=>a(S,S.disabled?"disabled":A?"active":"inactive"),maxItems:e.maxItems,output:e.output});return[...i,...w.map(S=>`${c}${S}`),...y].join(`
56
+ `)}}}}).prompt(),da=e=>{let t=(s,n,r,o)=>{let a=r.includes(s.value),l=s.label??String(s.value??""),c=s.hint&&o!==void 0&&s.value===o?(0,d.styleText)("dim",` (${s.hint})`):"",u=a?(0,d.styleText)("green",pt):(0,d.styleText)("dim",Ct);return s.disabled?`${(0,d.styleText)("gray",Ct)} ${(0,d.styleText)(["strikethrough","gray"],l)}`:n?`${u} ${l}${c}`:`${u} ${(0,d.styleText)("dim",l)}`},i=new Nt({options:e.options,multiple:!0,filter:e.filter??((s,n)=>Zn(s,n)),validate:()=>{if(e.required&&i.selectedValues.length===0)return"Please select at least one item"},initialValue:e.initialValues,signal:e.signal,input:e.input,output:e.output,render(){let s=`${(0,d.styleText)("gray",O)}
57
+ ${qe(this.state)} ${e.message}
58
+ `,n=this.userInput,r=e.placeholder,o=n===""&&r!==void 0,a=this.isNavigating||o?(0,d.styleText)("dim",o?r:n):this.userInputWithCursor,l=this.options,c=this.filteredOptions.length!==l.length?(0,d.styleText)("dim",` (${this.filteredOptions.length} match${this.filteredOptions.length===1?"":"es"})`):"";switch(this.state){case"submit":return`${s}${(0,d.styleText)("gray",O)} ${(0,d.styleText)("dim",`${this.selectedValues.length} items selected`)}`;case"cancel":return`${s}${(0,d.styleText)("gray",O)} ${(0,d.styleText)(["strikethrough","dim"],n)}`;default:{let u=this.state==="error"?"yellow":"cyan",f=[`${(0,d.styleText)("dim","\u2191/\u2193")} to navigate`,`${(0,d.styleText)("dim",this.isNavigating?"Space/Tab:":"Tab:")} select`,`${(0,d.styleText)("dim","Enter:")} confirm`,`${(0,d.styleText)("dim","Type:")} to search`],p=this.filteredOptions.length===0&&n?[`${(0,d.styleText)(u,O)} ${(0,d.styleText)("yellow","No matches found")}`]:[],v=this.state==="error"?[`${(0,d.styleText)(u,O)} ${(0,d.styleText)("yellow",this.error)}`]:[],$=[...`${s}${(0,d.styleText)(u,O)}`.split(`
59
+ `),`${(0,d.styleText)(u,O)} ${(0,d.styleText)("dim","Search:")} ${a}${c}`,...p,...v],m=[`${(0,d.styleText)(u,O)} ${f.join(" \u2022 ")}`,(0,d.styleText)(u,$e)],y=At({cursor:this.cursor,options:this.filteredOptions,style:(w,S)=>t(w,S,this.selectedValues,this.focusedValue),maxItems:e.maxItems,output:e.output,rowPadding:$.length+m.length});return[...$,...y.map(w=>`${(0,d.styleText)(u,O)} ${w}`),...m].join(`
60
+ `)}}}});return i.prompt()},ua=[Bn,xs,Ss,ks],ma=[_s,qn,$e,Wn];fa=e=>e,ha=(e="",t="",i)=>{let s=i?.output??process.stdout,n=ft(s),r=2,o=i?.titlePadding??1,a=i?.contentPadding??2,l=i?.width===void 0||i.width==="auto"?1:Math.min(1,i.width),c=i?.withGuide??re.withGuide?`${O} `:"",u=i?.formatBorder??fa,f=(i?.rounded?ua:ma).map(u),p=u(_i),v=u(O),$=Ce(c),m=Ce(t),y=n-$,w=Math.floor(n*l)-$;if(i?.width==="auto"){let T=e.split(`
61
+ `),J=m+o*2;for(let q of T){let ie=Ce(q)+a*2;ie>J&&(J=ie)}let Y=J+r;Y<w&&(w=Y)}w%2!==0&&(w<y?w++:w--);let S=w-r,A=S-o*2,F=m>A?`${t.slice(0,A-3)}...`:t,[N,H]=Fn(Ce(F),S,o,i?.titleAlign),R=Ot(e,S-a*2,{hard:!0,trim:!1});s.write(`${c}${f[0]}${p.repeat(N)}${F}${p.repeat(H)}${f[1]}
62
+ `);let P=R.split(`
63
+ `);for(let T of P){let[J,Y]=Fn(Ce(T),S,a,i?.contentAlign);s.write(`${c}${v}${" ".repeat(J)}${T}${" ".repeat(Y)}${v}
64
+ `)}s.write(`${c}${f[2]}${p.repeat(S)}${f[3]}
65
+ `)},Ue=e=>{let t=e.active??"Yes",i=e.inactive??"No";return new ci({active:t,inactive:i,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue??!0,render(){let s=e.withGuide??re.withGuide,n=`${s?`${(0,d.styleText)("gray",O)}
66
+ `:""}${qe(this.state)} ${e.message}
67
+ `,r=this.value?t:i;switch(this.state){case"submit":{let o=s?`${(0,d.styleText)("gray",O)} `:"";return`${n}${o}${(0,d.styleText)("dim",r)}`}case"cancel":{let o=s?`${(0,d.styleText)("gray",O)} `:"";return`${n}${o}${(0,d.styleText)(["strikethrough","dim"],r)}${s?`
68
+ ${(0,d.styleText)("gray",O)}`:""}`}default:{let o=s?`${(0,d.styleText)("cyan",O)} `:"",a=s?(0,d.styleText)("cyan",$e):"";return`${n}${o}${this.value?`${(0,d.styleText)("green",Mt)} ${t}`:`${(0,d.styleText)("dim",$t)} ${(0,d.styleText)("dim",t)}`}${e.vertical?s?`
69
+ ${(0,d.styleText)("cyan",O)} `:`
70
+ `:` ${(0,d.styleText)("dim","/")} `}${this.value?`${(0,d.styleText)("dim",$t)} ${(0,d.styleText)("dim",i)}`:`${(0,d.styleText)("green",Mt)} ${i}`}
57
71
  ${a}
58
- `}}}}).prompt()};var Lr=e=>(0,O.styleText)("magenta",e),As=({indicator:e="dots",onCancel:t,output:i=process.stdout,cancelMessage:s,errorMessage:n,frames:r=xi?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:o=xi?80:120,signal:a,...l}={})=>{let m=Sr(),d,u,y=!1,k=!1,g="",p,$=performance.now(),_=jt(i),A=l?.styleFrame??Lr,T=Y=>{let ce=Y>1?n??fe.messages.error:s??fe.messages.cancel;k=Y===1,y&&(Ve(ce,Y),k&&typeof t=="function"&&t())},M=()=>T(2),F=()=>T(1),R=()=>{process.on("uncaughtExceptionMonitor",M),process.on("unhandledRejection",M),process.on("SIGINT",F),process.on("SIGTERM",F),process.on("exit",T),a&&a.addEventListener("abort",F)},C=()=>{process.removeListener("uncaughtExceptionMonitor",M),process.removeListener("unhandledRejection",M),process.removeListener("SIGINT",F),process.removeListener("SIGTERM",F),process.removeListener("exit",T),a&&a.removeEventListener("abort",F)},I=()=>{if(p===void 0)return;m&&i.write(`
59
- `);let Y=ki(p,_,{hard:!0,trim:!1}).split(`
60
- `);Y.length>1&&i.write(tt.cursor.up(Y.length-1)),i.write(tt.cursor.to(0)),i.write(tt.erase.down())},G=Y=>Y.replace(/\.+$/,""),J=Y=>{let ce=(performance.now()-Y)/1e3,_e=Math.floor(ce/60),xe=Math.floor(ce%60);return _e>0?`[${_e}m ${xe}s]`:`[${xe}s]`},le=l.withGuide??fe.withGuide,Ge=(Y="")=>{y=!0,d=ys({output:i}),g=G(Y),$=performance.now(),le&&i.write(`${(0,O.styleText)("gray",X)}
61
- `);let ce=0,_e=0;R(),u=setInterval(()=>{if(m&&g===p)return;I(),p=g;let xe=A(r[ce]),lt;if(m)lt=`${xe} ${g}...`;else if(e==="timer")lt=`${xe} ${g} ${J($)}`;else{let En=".".repeat(Math.floor(_e)).slice(0,3);lt=`${xe} ${g}${En}`}let In=ki(lt,_,{hard:!0,trim:!1});i.write(In),ce=ce+1<r.length?ce+1:0,_e=_e<4?_e+.125:0},o)},Ve=(Y="",ce=0,_e=!1)=>{if(!y)return;y=!1,clearInterval(u),I();let xe=ce===0?(0,O.styleText)("green",Ss):ce===1?(0,O.styleText)("red",_s):(0,O.styleText)("red",xs);g=Y??g,_e||(e==="timer"?i.write(`${xe} ${g} ${J($)}
62
- `):i.write(`${xe} ${g}
63
- `)),C(),d()};return{start:Ge,stop:(Y="")=>Ve(Y,0),message:(Y="")=>{g=G(Y??g)},cancel:(Y="")=>Ve(Y,1),error:(Y="")=>Ve(Y,2),clear:()=>Ve("",0,!0),get isCancelled(){return k}}},qa={light:B("\u2500","-"),heavy:B("\u2501","="),block:B("\u2588","#")};var It=(e,t)=>e.includes(`
72
+ `}}}}).prompt()},pa=async(e,t)=>{let i={},s=Object.keys(e);for(let n of s){let r=e[n],o=await r({results:i})?.catch(a=>{throw a});if(typeof t?.onCancel=="function"&&oe(o)){i[n]="canceled",t.onCancel({results:i});continue}i[n]=o}return i},ga=e=>{let{selectableGroups:t=!0,groupSpacing:i=0}=e,s=(r,o,a=[])=>{let l=r.label??String(r.value),c=typeof r.group=="string",u=c&&(a[a.indexOf(r)+1]??{group:!0}),f=c&&u&&u.group===!0,p=c?t?`${f?$e:O} `:" ":"",v="";if(i>0&&!c){let m=`
73
+ ${(0,d.styleText)("cyan",O)}`;v=`${m.repeat(i-1)}${m} `}if(o==="active")return`${v}${(0,d.styleText)("dim",p)}${(0,d.styleText)("cyan",wi)} ${l}${r.hint?` ${(0,d.styleText)("dim",`(${r.hint})`)}`:""}`;if(o==="group-active")return`${v}${p}${(0,d.styleText)("cyan",wi)} ${(0,d.styleText)("dim",l)}`;if(o==="group-active-selected")return`${v}${p}${(0,d.styleText)("green",pt)} ${(0,d.styleText)("dim",l)}`;if(o==="selected"){let m=c||t?(0,d.styleText)("green",pt):"";return`${v}${(0,d.styleText)("dim",p)}${m} ${(0,d.styleText)("dim",l)}${r.hint?` ${(0,d.styleText)("dim",`(${r.hint})`)}`:""}`}if(o==="cancelled")return`${(0,d.styleText)(["strikethrough","dim"],l)}`;if(o==="active-selected")return`${v}${(0,d.styleText)("dim",p)}${(0,d.styleText)("green",pt)} ${l}${r.hint?` ${(0,d.styleText)("dim",`(${r.hint})`)}`:""}`;if(o==="submitted")return`${(0,d.styleText)("dim",l)}`;let $=c||t?(0,d.styleText)("dim",Ct):"";return`${v}${(0,d.styleText)("dim",p)}${$} ${(0,d.styleText)("dim",l)}`},n=e.required??!0;return new di({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValues:e.initialValues,required:n,cursorAt:e.cursorAt,selectableGroups:t,validate(r){if(n&&(r===void 0||r.length===0))return`Please select at least one option.
74
+ ${(0,d.styleText)("reset",(0,d.styleText)("dim",`Press ${(0,d.styleText)(["gray","bgWhite","inverse"]," space ")} to select, ${(0,d.styleText)("gray",(0,d.styleText)(["bgWhite","inverse"]," enter "))} to submit`))}`},render(){let r=`${(0,d.styleText)("gray",O)}
75
+ ${qe(this.state)} ${e.message}
76
+ `,o=this.value??[];switch(this.state){case"submit":{let a=this.options.filter(({value:c})=>o.includes(c)).map(c=>s(c,"submitted")),l=a.length===0?"":` ${a.join((0,d.styleText)("dim",", "))}`;return`${r}${(0,d.styleText)("gray",O)}${l}`}case"cancel":{let a=this.options.filter(({value:l})=>o.includes(l)).map(l=>s(l,"cancelled")).join((0,d.styleText)("dim",", "));return`${r}${(0,d.styleText)("gray",O)} ${a.trim()?`${a}
77
+ ${(0,d.styleText)("gray",O)}`:""}`}case"error":{let a=this.error.split(`
78
+ `).map((l,c)=>c===0?`${(0,d.styleText)("yellow",$e)} ${(0,d.styleText)("yellow",l)}`:` ${l}`).join(`
79
+ `);return`${r}${(0,d.styleText)("yellow",O)} ${this.options.map((l,c,u)=>{let f=o.includes(l.value)||l.group===!0&&this.isGroupSelected(`${l.value}`),p=c===this.cursor;return!p&&typeof l.group=="string"&&this.options[this.cursor].value===l.group?s(l,f?"group-active-selected":"group-active",u):p&&f?s(l,"active-selected",u):f?s(l,"selected",u):s(l,p?"active":"inactive",u)}).join(`
80
+ ${(0,d.styleText)("yellow",O)} `)}
81
+ ${a}
82
+ `}default:{let a=this.options.map((c,u,f)=>{let p=o.includes(c.value)||c.group===!0&&this.isGroupSelected(`${c.value}`),v=u===this.cursor,$=!v&&typeof c.group=="string"&&this.options[this.cursor].value===c.group,m="";return $?m=s(c,p?"group-active-selected":"group-active",f):v&&p?m=s(c,"active-selected",f):p?m=s(c,"selected",f):m=s(c,v?"active":"inactive",f),`${u!==0&&!m.startsWith(`
83
+ `)?" ":""}${m}`}).join(`
84
+ ${(0,d.styleText)("cyan",O)}`),l=a.startsWith(`
85
+ `)?"":" ";return`${r}${(0,d.styleText)("cyan",O)}${l}${a}
86
+ ${(0,d.styleText)("cyan",$e)}
87
+ `}}}}).prompt()},Te={message:(e=[],{symbol:t=(0,d.styleText)("gray",O),secondarySymbol:i=(0,d.styleText)("gray",O),output:s=process.stdout,spacing:n=1,withGuide:r}={})=>{let o=[],a=r??re.withGuide,l=a?i:"",c=a?`${t} `:"",u=a?`${i} `:"";for(let p=0;p<n;p++)o.push(l);let f=Array.isArray(e)?e:e.split(`
88
+ `);if(f.length>0){let[p,...v]=f;p.length>0?o.push(`${c}${p}`):o.push(a?t:"");for(let $ of v)$.length>0?o.push(`${u}${$}`):o.push(a?i:"")}s.write(`${o.join(`
89
+ `)}
90
+ `)},info:(e,t)=>{Te.message(e,{...t,symbol:(0,d.styleText)("blue",js)})},success:(e,t)=>{Te.message(e,{...t,symbol:(0,d.styleText)("green",Cs)})},step:(e,t)=>{Te.message(e,{...t,symbol:(0,d.styleText)("green",yt)})},warn:(e,t)=>{Te.message(e,{...t,symbol:(0,d.styleText)("yellow",Os)})},warning:(e,t)=>{Te.warn(e,t)},error:(e,t)=>{Te.message(e,{...t,symbol:(0,d.styleText)("red",As)})}},$a=(e="",t)=>{let i=t?.output??process.stdout,s=t?.withGuide??re.withGuide?`${(0,d.styleText)("gray",$e)} `:"";i.write(`${s}${(0,d.styleText)("red",e)}
91
+
92
+ `)},ya=(e="",t)=>{let i=t?.output??process.stdout,s=t?.withGuide??re.withGuide?`${(0,d.styleText)("gray",_s)} `:"";i.write(`${s}${e}
93
+ `)},ba=(e="",t)=>{let i=t?.output??process.stdout,s=t?.withGuide??re.withGuide?`${(0,d.styleText)("gray",O)}
94
+ ${(0,d.styleText)("gray",$e)} `:"";i.write(`${s}${e}
95
+
96
+ `)},Ft=(e,t)=>e.split(`
97
+ `).map(i=>t(i)).join(`
98
+ `),va=e=>{let t=(s,n)=>{let r=s.label??String(s.value);return n==="disabled"?`${(0,d.styleText)("gray",Ct)} ${Ft(r,o=>(0,d.styleText)(["strikethrough","gray"],o))}${s.hint?` ${(0,d.styleText)("dim",`(${s.hint??"disabled"})`)}`:""}`:n==="active"?`${(0,d.styleText)("cyan",wi)} ${r}${s.hint?` ${(0,d.styleText)("dim",`(${s.hint})`)}`:""}`:n==="selected"?`${(0,d.styleText)("green",pt)} ${Ft(r,o=>(0,d.styleText)("dim",o))}${s.hint?` ${(0,d.styleText)("dim",`(${s.hint})`)}`:""}`:n==="cancelled"?`${Ft(r,o=>(0,d.styleText)(["strikethrough","dim"],o))}`:n==="active-selected"?`${(0,d.styleText)("green",pt)} ${r}${s.hint?` ${(0,d.styleText)("dim",`(${s.hint})`)}`:""}`:n==="submitted"?`${Ft(r,o=>(0,d.styleText)("dim",o))}`:`${(0,d.styleText)("dim",Ct)} ${Ft(r,o=>(0,d.styleText)("dim",o))}`},i=e.required??!0;return new En({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValues:e.initialValues,required:i,cursorAt:e.cursorAt,validate(s){if(i&&(s===void 0||s.length===0))return`Please select at least one option.
99
+ ${(0,d.styleText)("reset",(0,d.styleText)("dim",`Press ${(0,d.styleText)(["gray","bgWhite","inverse"]," space ")} to select, ${(0,d.styleText)("gray",(0,d.styleText)("bgWhite",(0,d.styleText)("inverse"," enter ")))} to submit`))}`},render(){let s=Ge(e.output,e.message,`${Rs(this.state)} `,`${qe(this.state)} `),n=`${(0,d.styleText)("gray",O)}
100
+ ${s}
101
+ `,r=this.value??[],o=(a,l)=>{if(a.disabled)return t(a,"disabled");let c=r.includes(a.value);return l&&c?t(a,"active-selected"):c?t(a,"selected"):t(a,l?"active":"inactive")};switch(this.state){case"submit":{let a=this.options.filter(({value:c})=>r.includes(c)).map(c=>t(c,"submitted")).join((0,d.styleText)("dim",", "))||(0,d.styleText)("dim","none"),l=Ge(e.output,a,`${(0,d.styleText)("gray",O)} `);return`${n}${l}`}case"cancel":{let a=this.options.filter(({value:c})=>r.includes(c)).map(c=>t(c,"cancelled")).join((0,d.styleText)("dim",", "));if(a.trim()==="")return`${n}${(0,d.styleText)("gray",O)}`;let l=Ge(e.output,a,`${(0,d.styleText)("gray",O)} `);return`${n}${l}
102
+ ${(0,d.styleText)("gray",O)}`}case"error":{let a=`${(0,d.styleText)("yellow",O)} `,l=this.error.split(`
103
+ `).map((f,p)=>p===0?`${(0,d.styleText)("yellow",$e)} ${(0,d.styleText)("yellow",f)}`:` ${f}`).join(`
104
+ `),c=n.split(`
105
+ `).length,u=l.split(`
106
+ `).length+1;return`${n}${a}${At({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:a.length,rowPadding:c+u,style:o}).join(`
107
+ ${a}`)}
108
+ ${l}
109
+ `}default:{let a=`${(0,d.styleText)("cyan",O)} `,l=n.split(`
110
+ `).length;return`${n}${a}${At({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:a.length,rowPadding:l+2,style:o}).join(`
111
+ ${a}`)}
112
+ ${(0,d.styleText)("cyan",$e)}
113
+ `}}}}).prompt()},wa=e=>(0,d.styleText)("dim",e),_a=(e,t,i)=>{let s={hard:!0,trim:!1},n=Ot(e,t,s).split(`
114
+ `),r=n.reduce((l,c)=>Math.max(Ce(c),l),0),o=n.map(i).reduce((l,c)=>Math.max(Ce(c),l),0),a=t-(o-r);return Ot(e,a,s)},xa=(e="",t="",i)=>{let s=i?.output??Pe.default.stdout,n=i?.withGuide??re.withGuide,r=i?.format??wa,o=["",..._a(e,ft(s)-6,r).split(`
115
+ `).map(r),""],a=Ce(t),l=Math.max(o.reduce((p,v)=>{let $=Ce(v);return $>p?$:p},0),a)+2,c=o.map(p=>`${(0,d.styleText)("gray",O)} ${p}${" ".repeat(l-Ce(p))}${(0,d.styleText)("gray",O)}`).join(`
116
+ `),u=n?`${(0,d.styleText)("gray",O)}
117
+ `:"",f=n?Jn:Ss;s.write(`${u}${(0,d.styleText)("green",yt)} ${(0,d.styleText)("reset",t)} ${(0,d.styleText)("gray",_i.repeat(Math.max(l-a-1,1))+xs)}
118
+ ${c}
119
+ ${(0,d.styleText)("gray",f+_i.repeat(l+2)+ks)}
120
+ `)},ka=e=>new ui({validate:e.validate,mask:e.mask??Hn,signal:e.signal,input:e.input,output:e.output,render(){let t=e.withGuide??re.withGuide,i=`${t?`${(0,d.styleText)("gray",O)}
121
+ `:""}${qe(this.state)} ${e.message}
122
+ `,s=this.userInputWithCursor,n=this.masked;switch(this.state){case"error":{let r=t?`${(0,d.styleText)("yellow",O)} `:"",o=t?`${(0,d.styleText)("yellow",$e)} `:"",a=n??"";return e.clearOnError&&this.clear(),`${i.trim()}
123
+ ${r}${a}
124
+ ${o}${(0,d.styleText)("yellow",this.error)}
125
+ `}case"submit":{let r=t?`${(0,d.styleText)("gray",O)} `:"",o=n?(0,d.styleText)("dim",n):"";return`${i}${r}${o}`}case"cancel":{let r=t?`${(0,d.styleText)("gray",O)} `:"",o=n?(0,d.styleText)(["strikethrough","dim"],n):"";return`${i}${r}${o}${n&&t?`
126
+ ${(0,d.styleText)("gray",O)}`:""}`}default:{let r=t?`${(0,d.styleText)("cyan",O)} `:"",o=t?(0,d.styleText)("cyan",$e):"";return`${i}${r}${s}
127
+ ${o}
128
+ `}}}}).prompt(),Sa=e=>{let t=e.validate;return Xn({...e,initialUserInput:e.initialValue??e.root??process.cwd(),maxItems:5,validate(i){if(!Array.isArray(i)){if(!i)return"Please select a path";if(t)return t(i)}},options(){let i=this.userInput;if(i==="")return[];try{let s;return(0,gt.existsSync)(i)?(0,gt.lstatSync)(i).isDirectory()?s=i:s=(0,Vt.dirname)(i):s=(0,Vt.dirname)(i),(0,gt.readdirSync)(s).map(n=>{let r=(0,Vt.join)(s,n),o=(0,gt.lstatSync)(r);return{name:n,path:r,isDirectory:o.isDirectory()}}).filter(({path:n,isDirectory:r})=>n.startsWith(i)&&(e.directory||!r)).map(n=>({value:n.path}))}catch{return[]}}})},ja=e=>(0,d.styleText)("magenta",e),Ut=({indicator:e="dots",onCancel:t,output:i=process.stdout,cancelMessage:s,errorMessage:n,frames:r=vi?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:o=vi?80:120,signal:a,...l}={})=>{let c=bs(),u,f,p=!1,v=!1,$="",m,y=performance.now(),w=ft(i),S=l?.styleFrame??ja,A=z=>{let ae=z>1?n??re.messages.error:s??re.messages.cancel;v=z===1,p&&(ie(ae,z),v&&typeof t=="function"&&t())},F=()=>A(2),N=()=>A(1),H=()=>{process.on("uncaughtExceptionMonitor",F),process.on("unhandledRejection",F),process.on("SIGINT",N),process.on("SIGTERM",N),process.on("exit",A),a&&a.addEventListener("abort",N)},R=()=>{process.removeListener("uncaughtExceptionMonitor",F),process.removeListener("unhandledRejection",F),process.removeListener("SIGINT",N),process.removeListener("SIGTERM",N),process.removeListener("exit",A),a&&a.removeEventListener("abort",N)},P=()=>{if(m===void 0)return;c&&i.write(`
129
+ `);let z=Ot(m,w,{hard:!0,trim:!1}).split(`
130
+ `);z.length>1&&i.write(jt.cursor.up(z.length-1)),i.write(jt.cursor.to(0)),i.write(jt.erase.down())},T=z=>z.replace(/\.+$/,""),J=z=>{let ae=(performance.now()-z)/1e3,L=Math.floor(ae/60),B=Math.floor(ae%60);return L>0?`[${L}m ${B}s]`:`[${B}s]`},Y=l.withGuide??re.withGuide,q=(z="")=>{p=!0,u=In({output:i}),$=T(z),y=performance.now(),Y&&i.write(`${(0,d.styleText)("gray",O)}
131
+ `);let ae=0,L=0;H(),f=setInterval(()=>{if(c&&$===m)return;P(),m=$;let B=S(r[ae]),ce;if(c)ce=`${B} ${$}...`;else if(e==="timer")ce=`${B} ${$} ${J(y)}`;else{let je=".".repeat(Math.floor(L)).slice(0,3);ce=`${B} ${$}${je}`}let ue=Ot(ce,w,{hard:!0,trim:!1});i.write(ue),ae=ae+1<r.length?ae+1:0,L=L<4?L+.125:0},o)},ie=(z="",ae=0,L=!1)=>{if(!p)return;p=!1,clearInterval(f),P();let B=ae===0?(0,d.styleText)("green",yt):ae===1?(0,d.styleText)("red",vs):(0,d.styleText)("red",ws);$=z??$,L||(e==="timer"?i.write(`${B} ${$} ${J(y)}
132
+ `):i.write(`${B} ${$}
133
+ `)),R(),u()};return{start:q,stop:(z="")=>ie(z,0),message:(z="")=>{$=T(z??$)},cancel:(z="")=>ie(z,1),error:(z="")=>ie(z,2),clear:()=>ie("",0,!0),get isCancelled(){return v}}},Vn={light:se("\u2500","-"),heavy:se("\u2501","="),block:se("\u2588","#")};bi=(e,t)=>e.includes(`
64
134
  `)?e.split(`
65
135
  `).map(i=>t(i)).join(`
66
- `):t(e),Le=e=>{let t=(i,s)=>{let n=i.label??String(i.value);switch(s){case"disabled":return`${(0,O.styleText)("gray",Tt)} ${It(n,r=>(0,O.styleText)("gray",r))}${i.hint?` ${(0,O.styleText)("dim",`(${i.hint??"disabled"})`)}`:""}`;case"selected":return`${It(n,r=>(0,O.styleText)("dim",r))}`;case"active":return`${(0,O.styleText)("green",Si)} ${n}${i.hint?` ${(0,O.styleText)("dim",`(${i.hint})`)}`:""}`;case"cancelled":return`${It(n,r=>(0,O.styleText)(["strikethrough","dim"],r))}`;default:return`${(0,O.styleText)("dim",Tt)} ${It(n,r=>(0,O.styleText)("dim",r))}`}};return new xt({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue,render(){let i=e.withGuide??fe.withGuide,s=`${ji(this.state)} `,n=`${jr(this.state)} `,r=Ct(e.output,e.message,n,s),o=`${i?`${(0,O.styleText)("gray",X)}
136
+ `):t(e),We=e=>{let t=(i,s)=>{let n=i.label??String(i.value);switch(s){case"disabled":return`${(0,d.styleText)("gray",$t)} ${bi(n,r=>(0,d.styleText)("gray",r))}${i.hint?` ${(0,d.styleText)("dim",`(${i.hint??"disabled"})`)}`:""}`;case"selected":return`${bi(n,r=>(0,d.styleText)("dim",r))}`;case"active":return`${(0,d.styleText)("green",Mt)} ${n}${i.hint?` ${(0,d.styleText)("dim",`(${i.hint})`)}`:""}`;case"cancelled":return`${bi(n,r=>(0,d.styleText)(["strikethrough","dim"],r))}`;default:return`${(0,d.styleText)("dim",$t)} ${bi(n,r=>(0,d.styleText)("dim",r))}`}};return new mi({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue,render(){let i=e.withGuide??re.withGuide,s=`${qe(this.state)} `,n=`${Rs(this.state)} `,r=Ge(e.output,e.message,n,s),o=`${i?`${(0,d.styleText)("gray",O)}
67
137
  `:""}${r}
68
- `;switch(this.state){case"submit":{let a=i?`${(0,O.styleText)("gray",X)} `:"",l=Ct(e.output,t(this.options[this.cursor],"selected"),a);return`${o}${l}`}case"cancel":{let a=i?`${(0,O.styleText)("gray",X)} `:"",l=Ct(e.output,t(this.options[this.cursor],"cancelled"),a);return`${o}${l}${i?`
69
- ${(0,O.styleText)("gray",X)}`:""}`}default:{let a=i?`${(0,O.styleText)("cyan",X)} `:"",l=i?(0,O.styleText)("cyan",Et):"",m=o.split(`
70
- `).length,d=i?2:1;return`${o}${a}${Ur({output:e.output,cursor:this.cursor,options:this.options,maxItems:e.maxItems,columnPadding:a.length,rowPadding:m+d,style:(u,y)=>t(u,u.disabled?"disabled":y?"active":"inactive")}).join(`
138
+ `;switch(this.state){case"submit":{let a=i?`${(0,d.styleText)("gray",O)} `:"",l=Ge(e.output,t(this.options[this.cursor],"selected"),a);return`${o}${l}`}case"cancel":{let a=i?`${(0,d.styleText)("gray",O)} `:"",l=Ge(e.output,t(this.options[this.cursor],"cancelled"),a);return`${o}${l}${i?`
139
+ ${(0,d.styleText)("gray",O)}`:""}`}default:{let a=i?`${(0,d.styleText)("cyan",O)} `:"",l=i?(0,d.styleText)("cyan",$e):"",c=o.split(`
140
+ `).length,u=i?2:1;return`${o}${a}${At({output:e.output,cursor:this.cursor,options:this.options,maxItems:e.maxItems,columnPadding:a.length,rowPadding:c+u,style:(f,p)=>t(f,f.disabled?"disabled":p?"active":"inactive")}).join(`
71
141
  ${a}`)}
72
142
  ${l}
73
- `}}}}).prompt()};var Wa=`${(0,O.styleText)("gray",X)} `;var pe=e=>new St({validate:e.validate,placeholder:e.placeholder,defaultValue:e.defaultValue,initialValue:e.initialValue,output:e.output,signal:e.signal,input:e.input,render(){let t=e?.withGuide??fe.withGuide,i=`${`${t?`${(0,O.styleText)("gray",X)}
74
- `:""}${ji(this.state)} `}${e.message}
75
- `,s=e.placeholder?(0,O.styleText)("inverse",e.placeholder[0])+(0,O.styleText)("dim",e.placeholder.slice(1)):(0,O.styleText)(["inverse","hidden"],"_"),n=this.userInput?this.userInputWithCursor:s,r=this.value??"";switch(this.state){case"error":{let o=this.error?` ${(0,O.styleText)("yellow",this.error)}`:"",a=t?`${(0,O.styleText)("yellow",X)} `:"",l=t?(0,O.styleText)("yellow",Et):"";return`${i.trim()}
143
+ `}}}}).prompt()},Oa=e=>{let t=(i,s="inactive")=>{let n=i.label??String(i.value);return s==="selected"?`${(0,d.styleText)("dim",n)}`:s==="cancelled"?`${(0,d.styleText)(["strikethrough","dim"],n)}`:s==="active"?`${(0,d.styleText)(["bgCyan","gray"],` ${i.value} `)} ${n}${i.hint?` ${(0,d.styleText)("dim",`(${i.hint})`)}`:""}`:`${(0,d.styleText)(["gray","bgWhite","inverse"],` ${i.value} `)} ${n}${i.hint?` ${(0,d.styleText)("dim",`(${i.hint})`)}`:""}`};return new fi({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue,caseSensitive:e.caseSensitive,render(){let i=e.withGuide??re.withGuide,s=`${i?`${(0,d.styleText)("gray",O)}
144
+ `:""}${qe(this.state)} ${e.message}
145
+ `;switch(this.state){case"submit":{let n=i?`${(0,d.styleText)("gray",O)} `:"",r=this.options.find(a=>a.value===this.value)??e.options[0],o=Ge(e.output,t(r,"selected"),n);return`${s}${o}`}case"cancel":{let n=i?`${(0,d.styleText)("gray",O)} `:"",r=Ge(e.output,t(this.options[0],"cancelled"),n);return`${s}${r}${i?`
146
+ ${(0,d.styleText)("gray",O)}`:""}`}default:{let n=i?`${(0,d.styleText)("cyan",O)} `:"",r=i?(0,d.styleText)("cyan",$e):"",o=this.options.map((a,l)=>Ge(e.output,t(a,l===this.cursor?"active":"inactive"),n)).join(`
147
+ `);return`${s}${o}
148
+ ${r}
149
+ `}}}}).prompt()},Mn=`${(0,d.styleText)("gray",O)} `,ht={message:async(e,{symbol:t=(0,d.styleText)("gray",O)}={})=>{process.stdout.write(`${(0,d.styleText)("gray",O)}
150
+ ${t} `);let i=3;for await(let s of e){s=s.replace(/\n/g,`
151
+ ${Mn}`),s.includes(`
152
+ `)&&(i=3+(0,d.stripVTControlCharacters)(s.slice(s.lastIndexOf(`
153
+ `))).length);let n=(0,d.stripVTControlCharacters)(s).length;i+n<process.stdout.columns?(i+=n,process.stdout.write(s)):(process.stdout.write(`
154
+ ${Mn}${s.trimStart()}`),i=3+(0,d.stripVTControlCharacters)(s.trimStart()).length)}process.stdout.write(`
155
+ `)},info:e=>ht.message(e,{symbol:(0,d.styleText)("blue",js)}),success:e=>ht.message(e,{symbol:(0,d.styleText)("green",Cs)}),step:e=>ht.message(e,{symbol:(0,d.styleText)("green",yt)}),warn:e=>ht.message(e,{symbol:(0,d.styleText)("yellow",Os)}),warning:e=>ht.warn(e),error:e=>ht.message(e,{symbol:(0,d.styleText)("red",As)})},Aa=async(e,t)=>{for(let i of e){if(i.enabled===!1)continue;let s=Ut(t);s.start(i.title);let n=await i.task(s.message);s.stop(n||i.title)}},Ra=e=>e.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g,""),Ia=e=>{let t=e.output??process.stdout,i=ft(t),s=(0,d.styleText)("gray",O),n=e.spacing??1,r=3,o=e.retainLog===!0,a=!bs()&&Un(t);t.write(`${s}
156
+ `),t.write(`${(0,d.styleText)("green",yt)} ${e.title}
157
+ `);for(let y=0;y<n;y++)t.write(`${s}
158
+ `);let l=[{value:"",full:""}],c=!1,u=y=>{if(l.length===0)return;let w=0;y&&(w+=n+2);for(let S of l){let{value:A,result:F}=S,N=F?.message??A;if(N.length===0)continue;F===void 0&&S.header!==void 0&&S.header!==""&&(N+=`
159
+ ${S.header}`);let H=N.split(`
160
+ `).reduce((R,P)=>P===""?R+1:R+Math.ceil((P.length+r)/i),0);w+=H}w>0&&(w+=1,t.write(jt.erase.lines(w)))},f=(y,w,S)=>{let A=S?`${y.full}
161
+ ${y.value}`:y.value;y.header!==void 0&&y.header!==""&&Te.message(y.header.split(`
162
+ `).map(F=>(0,d.styleText)("bold",F)),{output:t,secondarySymbol:s,symbol:s,spacing:0}),Te.message(A.split(`
163
+ `).map(F=>(0,d.styleText)("dim",F)),{output:t,secondarySymbol:s,symbol:s,spacing:w??n})},p=()=>{for(let y of l){let{header:w,value:S,full:A}=y;(w===void 0||w.length===0)&&S.length===0||f(y,void 0,o===!0&&A.length>0)}},v=(y,w,S)=>{if(u(!1),(S?.raw!==!0||!c)&&y.value!==""&&(y.value+=`
164
+ `),y.value+=Ra(w),c=S?.raw===!0,e.limit!==void 0){let A=y.value.split(`
165
+ `),F=A.length-e.limit;if(F>0){let N=A.splice(0,F);o&&(y.full+=(y.full===""?"":`
166
+ `)+N.join(`
167
+ `))}y.value=A.join(`
168
+ `)}a&&$()},$=()=>{for(let y of l)y.result?y.result.status==="error"?Te.error(y.result.message,{output:t,secondarySymbol:s,spacing:0}):Te.success(y.result.message,{output:t,secondarySymbol:s,spacing:0}):y.value!==""&&f(y,0)},m=(y,w)=>{u(!1),y.result=w,a&&$()};return{message(y,w){v(l[0],y,w)},group(y){let w={header:y,value:"",full:""};return l.push(w),{message(S,A){v(w,S,A)},error(S){m(w,{status:"error",message:S})},success(S){m(w,{status:"success",message:S})}}},error(y,w){u(!0),Te.error(y,{output:t,secondarySymbol:s,spacing:1}),w?.showLog!==!1&&p(),l.splice(1,l.length-1),l[0].value="",l[0].full=""},success(y,w){u(!0),Te.success(y,{output:t,secondarySymbol:s,spacing:1}),w?.showLog===!0&&p(),l.splice(1,l.length-1),l[0].value="",l[0].full=""}}},Re=e=>new hi({validate:e.validate,placeholder:e.placeholder,defaultValue:e.defaultValue,initialValue:e.initialValue,output:e.output,signal:e.signal,input:e.input,render(){let t=e?.withGuide??re.withGuide,i=`${`${t?`${(0,d.styleText)("gray",O)}
169
+ `:""}${qe(this.state)} `}${e.message}
170
+ `,s=e.placeholder?(0,d.styleText)("inverse",e.placeholder[0])+(0,d.styleText)("dim",e.placeholder.slice(1)):(0,d.styleText)(["inverse","hidden"],"_"),n=this.userInput?this.userInputWithCursor:s,r=this.value??"";switch(this.state){case"error":{let o=this.error?` ${(0,d.styleText)("yellow",this.error)}`:"",a=t?`${(0,d.styleText)("yellow",O)} `:"",l=t?(0,d.styleText)("yellow",$e):"";return`${i.trim()}
76
171
  ${a}${n}
77
172
  ${l}${o}
78
- `}case"submit":{let o=r?` ${(0,O.styleText)("dim",r)}`:"",a=t?(0,O.styleText)("gray",X):"";return`${i}${a}${o}`}case"cancel":{let o=r?` ${(0,O.styleText)(["strikethrough","dim"],r)}`:"",a=t?(0,O.styleText)("gray",X):"";return`${i}${a}${o}${r.trim()?`
79
- ${a}`:""}`}default:{let o=t?`${(0,O.styleText)("cyan",X)} `:"",a=t?(0,O.styleText)("cyan",Et):"";return`${i}${o}${n}
173
+ `}case"submit":{let o=r?` ${(0,d.styleText)("dim",r)}`:"",a=t?(0,d.styleText)("gray",O):"";return`${i}${a}${o}`}case"cancel":{let o=r?` ${(0,d.styleText)(["strikethrough","dim"],r)}`:"",a=t?(0,d.styleText)("gray",O):"";return`${i}${a}${o}${r.trim()?`
174
+ ${a}`:""}`}default:{let o=t?`${(0,d.styleText)("cyan",O)} `:"",a=t?(0,d.styleText)("cyan",$e):"";return`${i}${o}${n}
80
175
  ${a}
81
- `}}}}).prompt();var ye=process.stdout.isTTY??!1;function qr(e){return!!(e.json||!ye)}var b={success:N.default.green("\u2713"),error:N.default.red("\u2717"),warning:N.default.yellow("!"),info:N.default.cyan("\u25CF"),arrow:N.default.dim("\u2192"),dot:N.default.dim("\xB7"),dash:N.default.dim("\u2500")},v={domain:e=>N.default.bold(N.default.white(e)),price:e=>N.default.green(`$${e}`),label:e=>N.default.dim(e),value:e=>N.default.white(e),dim:e=>N.default.dim(e),bold:e=>N.default.bold(e),success:e=>N.default.green(e),error:e=>N.default.red(e),warn:e=>N.default.yellow(e),cyan:e=>N.default.cyan(e),url:e=>`\x1B]8;;${e}\x1B\\${N.default.underline(N.default.cyan(e))}\x1B]8;;\x1B\\`};function j(e,t=50){console.log(),console.log(` ${N.default.bold(e)}`),console.log(` ${N.default.dim("\u2500".repeat(t))}`)}function h(e,t,i=2){let s=" ".repeat(i);console.log(`${s}${N.default.dim(e.padEnd(16))} ${t}`)}function c(){console.log()}function Ke(e){console.log(` ${N.default.dim(e)}`)}function E(e,t){console.log(` ${N.default.dim(e)} ${N.default.cyan(t)}`)}function Ts(e){return e.split(/(https?:\/\/[^\s]+)/g).map(i=>/^https?:\/\//.test(i)?`\x1B]8;;${i}\x1B\\${N.default.underline(N.default.cyan(i))}\x1B]8;;\x1B\\`:N.default.dim(i)).join("")}function Ri(e,t){console.error(` ${b.error} ${N.default.red(e)}`),t&&console.error(` ${Ts(t)}`)}var Wr={start:()=>{},stop:()=>{},message:()=>{}};function x(e=!0){return e?As():Wr}var Hr=/\x1b\]8;;[^\x1b]*\x1b\\|\x1b\[[0-9;]*m/g;function Ps(e){return e.replace(Hr,"")}function Dt(e,t){let i=Ps(e).length,s=Math.max(0,t-i);return e+" ".repeat(s)}function ee(e,t,i){let s=i||e.map((o,a)=>{let l=t.reduce((m,d)=>Math.max(m,Ps(d[a]||"").length),0);return Math.max(o.length,l)+2}),n=e.map((o,a)=>N.default.dim(o.padEnd(s[a]))).join(" "),r=s.map(o=>N.default.dim("\u2500".repeat(o))).join(" ");console.log(` ${n}`),console.log(` ${r}`);for(let o of t){let a=o.map((l,m)=>Dt(l,s[m])).join(" ");console.log(` ${a}`)}}function Jr(e){return e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}function Ai(e){if(Array.isArray(e))return e.map(Ai);if(e&&typeof e=="object"&&!(e instanceof Date)){let t={};for(let[i,s]of Object.entries(e))t[Jr(i)]=Ai(s);return t}return e}function w(e,t){let i=Ai(e);if(!t){console.log(JSON.stringify(i,null,2));return}let s=t.split(",").map(n=>n.trim()).filter(Boolean);if(Array.isArray(i)){let n=i.map(r=>Rs(r,s));console.log(JSON.stringify(n,null,2))}else console.log(JSON.stringify(i&&typeof i=="object"?Rs(i,s):i,null,2))}function Rs(e,t){let i={};for(let s of t)s in e&&(i[s]=e[s]);if(Object.keys(i).length===0){for(let[s,n]of Object.entries(e))if(Array.isArray(n)&&n.length>0&&typeof n[0]=="object"){let r=n.map(o=>{let a={};for(let l of t)l in o&&(a[l]=o[l]);return a});Object.keys(r[0]).length>0&&(i[s]=r)}}return i}function qe(e){return!!(e.yes||qr(e))}function V(e,t,i,s){if(i){w({dry_run:!0,action:e,...t},s);return}console.log(),console.log(` ${N.default.yellow("\u25B8 DRY RUN")} ${N.default.dim("\u2014 no changes made")}`),console.log(` ${N.default.dim("Action:")} ${N.default.bold(e)}`);for(let[n,r]of Object.entries(t))r!=null&&(Array.isArray(r)?console.log(` ${N.default.dim(n+":")} ${r.map(String).join(", ")}`):console.log(typeof r=="object"?` ${N.default.dim(n+":")} ${JSON.stringify(r)}`:` ${N.default.dim(n+":")} ${String(r)}`));console.log()}var Gr={auth_required:"domani login",payment_required:"domani billing",contact_required:"domani contact set"};function Br(e,t,i){return t===401||t===403?"auth_required":i?"payment_required":t===404?"not_found":t===409?"conflict":t===422?"validation_error":t===429?"rate_limited":/contact/i.test(e)?"contact_required":"error"}function f(e,t){let i=e||`Request failed${t?.status?` (${t.status})`:""}`,s=t?.code||Br(i,t?.status,t?.fixUrl),n=t?.fixCommand||Gr[s];if(t?.json){let r={error:i,code:s};t.hint&&(r.hint=t.hint),n&&(r.fix_command=n),t.fixUrl&&(r.fix_url=t.fixUrl),w(r,t.fields)}else{let r=t?.hint;if(t?.fixUrl){let o=`Add a payment method at ${t.fixUrl}`;r=r?`${r}
82
- ${Ts(o)}`:o}Ri(i,r)}process.exit(1)}function Nt(e){let t=process.platform==="darwin"?"open":process.platform==="win32"?"start":"xdg-open";(0,Es.execFile)(t,[e])}function st(e){return new Promise(t=>setTimeout(t,e))}var Is=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function Ye(e,t,i,s=!0){let n=process.stdout.isTTY??!1;if(!s)return{start(){},markDone(y,k){},stop(){}};let r=0,o=null,a=2+t.length;function l(){let y=" "+e.map((p,$)=>N.default.dim(p.padEnd(i[$]))).join(" "),k=" "+i.map(p=>N.default.dim("\u2500".repeat(p))).join(" "),g=[y,k];for(let p of t){let $=p.status==="done"?p.icon??b.success:N.default.cyan(Is[r%Is.length]),_=p.cells.map((A,T)=>Dt(A,i[T])).join(" ");g.push(` ${$} ${_}`)}return g}let m=!1,d=()=>process.stdout.write("\x1B[?25h");function u(){let y=l();if(m&&n){process.stdout.write(`\x1B[${a}A`);for(let k of y)process.stdout.write(`\x1B[2K${k}
83
- `)}else{for(let k of y)console.log(k);m=!0}}return{start(){n&&(process.stdout.write("\x1B[?25l"),process.on("exit",d)),u(),n&&(o=setInterval(()=>{r++,u()},80))},markDone(y,k){t[y].status="done",k!==void 0&&(t[y].icon=k),n&&u()},stop(){o&&clearInterval(o);for(let y of t)y.status="done";u(),n&&(process.stdout.write("\x1B[?25h"),process.removeListener("exit",d))}}}async function Ds(e){let t=Te(),i=x(!e.json),s=Me();if(s.token){i.start("Checking session");try{let m=await fetch(`${t}/api/me`,{headers:{Authorization:`Bearer ${s.token}`}});if(m.ok){let d=await m.json();i.stop(`Already logged in as ${We.default.bold(d.email)}`),e.json&&w({status:"already_logged_in",email:d.email});return}}catch{}i.stop("Session expired, re-authenticating"),c()}i.start("Requesting auth code");let n=await fetch(`${t}/api/auth/cli`,{method:"POST",headers:{"Content-Type":"application/json"}});if(!n.ok){i.stop("Failed to initiate login");try{let m=await n.json();f(m.error||m.message||`Server error (${n.status})`,{hint:m.hint,code:"login_failed",json:e.json})}catch{f(`Could not reach ${t}. Check your connection and try again.`,{code:"network_error",json:e.json})}}let{code:r,auth_url:o,expires_in:a}=await n.json();if(i.stop("Auth code received"),e.json){w({status:"awaiting_approval",code:r,auth_url:o,expires_in:a});return}c(),console.log(` ${We.default.dim("Verification code:")} ${We.default.bold(We.default.cyan(r))}`),console.log(` ${We.default.dim("Opening browser")} ${b.arrow} ${v.url(o)}`),c(),Nt(o),i.start("Waiting for approval");let l=120;for(let m=0;m<l;m++){await new Promise(y=>setTimeout(y,5e3));let d=await fetch(`${t}/api/auth/cli/poll?code=${r}`);!d.ok&&d.status!==202&&(i.stop("Login failed"),f(`Server error (${d.status})`,{code:"login_failed"}));let u=await d.json();if(u.status==="complete"){ns({...Me(),token:u.token,email:u.email,api_url:t}),i.stop(`Logged in as ${We.default.bold(u.email)}`),c(),E("Get started:","domani search"),c();return}u.error&&(i.stop("Login failed"),f(u.error||u.message,{hint:u.hint,code:"login_failed"}))}i.stop("Login timed out"),f("No approval received within 10 minutes",{hint:"Run 'domani login' to try again",code:"timeout"})}var Ii=P(U(),1);async function Ns(e){let t=Me();if(!t.token){e.json?w({status:"not_logged_in"}):console.log(` ${Ii.default.dim("Not logged in.")}`);return}rs(),e.json?w({status:"logged_out",email:t.email||null}):console.log(` ${b.success} Logged out${t.email?` ${Ii.default.dim(`(${t.email})`)}`:""}`)}function Fs(e){let t=e.json.bind(e);return e.json=async()=>{let i=await e.clone().text();try{return JSON.parse(i)}catch{return{error:`Server error (${e.status})`,hint:"The server returned an unexpected response. Try again later."}}},e}async function S(e,t={}){let i=os(),s=`${Te()}${e}`,n=await fetch(s,{...t,headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json","User-Agent":`domani-cli/${te}`,...t.headers}});return Fs(n)}async function oe(e,t={}){let i=`${Te()}${e}`,s=Ze(),n=await fetch(i,{...t,headers:{"Content-Type":"application/json","User-Agent":`domani-cli/${te}`,...s?{Authorization:`Bearer ${s}`}:{},...t.headers}});return Fs(n)}var nt=P(U(),1);async function Vs(e){let t=await S("/api/me"),i=await t.json();if(t.ok||f(i.error||i.message,{hint:i.hint,status:t.status,json:e.json,fields:e.fields}),e.json){w(i,e.fields);return}j("Account"),h("Email",nt.default.bold(i.email)),h("Payment",i.has_payment_method?`${b.success} ${nt.default.green("active")}`:`${b.error} ${nt.default.dim("none")}`),h("Domains",String(i.domain_count)),h("API tokens",String(i.token_count)),h("Referral code",i.referral_code||nt.default.dim("-")),h("Created",new Date(i.created_at).toLocaleDateString()),c()}var ge=P(U(),1);var Kr=/[\x00-\x08\x0b\x0c\x0e-\x1f]/,Yr=/\.\.[/\\]/,zr=/[?#]/,Xr=/%[0-9a-fA-F]{2}/,Zr=/^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.?$/,Qr=/^\.?[a-zA-Z]{2,63}$/,Ms=253;function De(){return{ok:!0}}function Ce(e,t,i){return{ok:!1,error:{message:e,code:t,hint:i}}}function Us(e){return Kr.test(e)?Ce("Input contains control characters","invalid_input","Remove non-printable characters from the input"):De()}function eo(e){return Yr.test(e)?Ce("Input contains path traversal","invalid_input","Domain names cannot contain '../' or '..\\'"):De()}function to(e){return zr.test(e)?Ce("Input contains query string or fragment","invalid_input","Remove '?' or '#' from the domain name"):De()}function io(e){return Xr.test(e)?Ce("Input contains percent-encoded characters","invalid_input","Use plain text, not URL-encoded values (e.g. 'example.com' not 'example%2Ecom')"):De()}function Ls(e){if(!e)return Ce("Domain name is required","validation_error");if(e.length>Ms)return Ce(`Domain name too long (${e.length} chars, max ${Ms})`,"validation_error");for(let t of[Us,eo,to,io]){let i=t(e);if(!i.ok)return i}return Zr.test(e)?De():Ce(`Invalid domain name: ${e}`,"validation_error","Domain names can only contain letters, digits, hyphens, and dots")}function so(e){if(!e)return Ce("TLD is required","validation_error");let t=Us(e);return t.ok?Qr.test(e)?De():Ce(`Invalid TLD: ${e}`,"validation_error","TLDs contain only letters (e.g. 'com', '.dev', 'ai')"):t}function no(e){for(let t of e){let i=Ls(t);if(!i.ok)return i}return De()}function ro(e){for(let t of e){let i=so(t);if(!i.ok)return i}return De()}function q(e,t){let i=Ls(e);i.ok||f(i.error.message,{code:i.error.code,hint:i.error.hint,json:t?.json,fields:t?.fields})}function qs(e,t){let i=no(e);i.ok||f(i.error.message,{code:i.error.code,hint:i.error.hint,json:t?.json,fields:t?.fields})}function Ft(e,t){let i=ro(e);i.ok||f(i.error.message,{code:i.error.code,hint:i.error.hint,json:t?.json,fields:t?.fields})}var Ws=["com","io","dev","ai","sh","co","net","org","app","xyz"],oo=[...Ws,"tech","run","cloud","so","code","software","pro","one","biz","design","studio","art","space","lol","site","gg","cc","me","tv","fm","1"];async function Hs(e,t,i){if(!e){ye||f("Missing required argument: domain",{hint:"Usage: domani search <domain> [tlds...]",code:"missing_argument",json:i.json});let R=await pe({message:"Search for a domain",placeholder:"e.g. myapp or myapp.dev"});(Q(R)||!R)&&process.exit(0),e=R}let s=t.map(R=>R.replace(/^\./,"")),n=i.tlds?.split(",").map(R=>R.trim())||[],r=[...new Set([...s,...n])];if(r.length>0&&Ft(r,i),q(e,i),e.includes(".")&&r.length===0){let R=x(!i.json);R.start(`Checking ${v.domain(e)}`);let[C,I]=await Promise.all([oe(`/api/domains/search?q=${encodeURIComponent(e)}`),oe(`/api/domains/${encodeURIComponent(e)}/og`).catch(()=>null)]),G=await C.json();if(C.ok||(R.stop("Search failed"),f(G.error||G.message,{hint:G.hint,status:C.status,json:i.json,fields:i.fields})),i.json){let J=G.domain.split(".")[0];w({name:J,results:[G],total:1,available:G.available?1:0},i.fields);return}if(G.available)R.stop(`${b.success} ${v.domain(G.domain)} ${b.dot} available ${b.dot} ${v.price(G.price)}/yr`),c(),E("Register it:",`domani buy ${G.domain}`),c();else{let J;try{if(I?.ok){let Ge=await I.json();Ge?.title&&(J=Ge.title)}}catch{}let le=J?` ${b.dot} ${ge.default.dim(`"${J}"`)}`:"";R.stop(`${b.error} ${v.domain(G.domain)} ${b.dot} ${ge.default.red("taken")}${le}`)}return}let o=e.split(".")[0],l=(r.length>0?r:i.expand?oo:Ws).map(R=>`${o}.${R}`),m=new URLSearchParams;m.set("domains",l.join(",")),i.maxPrice&&m.set("max_price",i.maxPrice);let d=x(!i.json);d.start(`Searching available domains for ${ge.default.bold(o)}`);let u=await oe(`/api/domains/search?${m}`,{headers:{Accept:"text/event-stream"}});if(!u.ok){d.stop("Search failed");try{let R=await u.json();f(R.error||R.message||`Server error (${u.status})`,{hint:R.hint,status:u.status,json:i.json,fields:i.fields})}catch{f(`Server error (${u.status})`,{status:u.status,json:i.json,fields:i.fields})}}let y=[],k=!1,g=0,p=i.all??!1;function $(){k||(k=!0,d.stop(`Checking TLDs for ${ge.default.bold(o)}`),c())}function _(R){$(),R.available?console.log(` ${b.success} ${v.domain(R.domain).padEnd(37)} ${v.price(R.price)}${ge.default.dim("/yr")}`):console.log(` ${b.error} ${ge.default.dim(R.domain.padEnd(38))} ${ge.default.red("taken")}`)}function A(){k||d.message(`Checking TLDs for ${ge.default.bold(o)} ${ge.default.dim(`(${g} checked)`)}`)}let T=u.body;T||(d.stop("Search failed"),f("Empty response",{code:"error",json:i.json,fields:i.fields}));let M=new TextDecoder,F="";for await(let R of T){F+=M.decode(R,{stream:!0});let C=F.split(`
84
- `);F=C.pop()??"";let I="";for(let G of C)if(G.startsWith("event: "))I=G.slice(7);else if(G.startsWith("data: ")){let J=JSON.parse(G.slice(6));if(I==="result")g++,J.available||p?(i.json||_(J),y.push(J)):i.json||A();else if(I==="done"){if(i.json){y.sort((Y,ce)=>Y.price-ce.price),w({name:o,results:y,total:J.total,available:J.available},i.fields);return}k&&console.log(` ${ge.default.dim("\u2500".repeat(50))}`);let le=J.total-J.available,Ge=J.total>=5&&le/J.total>=.5,Ve=`Checked ${J.total} TLDs \xB7 ${J.available} available${Ge?" \xB7 popular name":""}`;console.log(` ${ge.default.dim(Ve)}`),J.available===0&&!i.expand&&r.length===0&&(c(),E("Try more TLDs:",`domani search ${o} --expand`))}}}c()}var $e=P(U(),1);async function ao(e,t){q(e,t);let i=x(!t.json);i.start(`Checking ${v.domain(e)}`);let s=await S(`/api/domains/search?q=${encodeURIComponent(e)}`),n=await s.json();if(s.ok||(i.stop("Search failed"),f(n.error,{hint:n.hint,status:s.status,json:t.json,fields:t.fields})),n.available||(i.stop(`${b.error} ${v.domain(e)} is not available`),f(`${e} is not available`,{code:"not_available",json:t.json,fields:t.fields})),i.stop(`${b.success} ${v.domain(e)} ${b.dot} available ${b.dot} ${v.price(n.price)}/yr`),t.dryRun)return V("buy",{domain:e,available:!0,price:n.price,currency:n.currency||"USD"},t.json,t.fields);if(!qe(t)){c();let l=await je({message:`Purchase ${$e.default.bold(e)} for ${v.price(n.price)}/yr?`});if(!l||typeof l=="symbol"){console.log(` ${$e.default.dim("Cancelled.")}`);return}}let r=x(!t.json);r.start("Purchasing");let o=await S("/api/domains/buy",{method:"POST",body:JSON.stringify({domain:e})}),a=await o.json();if(o.ok||(r.stop("Purchase failed"),f(a.error||a.message,{hint:a.hint,fixUrl:a.setup_url,status:o.status,json:t.json,fields:t.fields})),r.stop(`${b.success} ${v.domain(a.domain)} is yours!`),t.json){w(a,t.fields);return}j(a.domain),h("Status",v.success("Active")),h("Expires",new Date(a.expires).toLocaleDateString()),a.price&&h("Price",v.price(a.price)+$e.default.dim(` ${a.currency||"USD"}`)),c(),E("Configure DNS:",`domani dns ${a.domain}`),c()}async function lo(e,t){qs(e,t);let i=!!t.json,s=x(!i);s.start(`Checking ${e.length} domains`);let n=await Promise.all(e.map(async $=>{try{let _=await S(`/api/domains/search?q=${encodeURIComponent($)}`),A=await _.json();return{domain:$,available:_.ok&&A.available,price:A.price}}catch{return{domain:$,available:!1,price:void 0}}})),r=n.filter($=>$.available),o=n.filter($=>!$.available);r.length===0&&(s.stop(`${b.error} None of the ${e.length} domains are available`),process.exit(1));let a=r.reduce(($,_)=>$+(_.price||0),0);if(s.stop(`${b.success} ${r.length}/${e.length} available ${b.dot} ${v.price(a.toFixed(2))} total`),o.length>0)for(let $ of o)console.log(` ${b.error} ${v.domain($.domain)} ${$e.default.dim("not available")}`);if(t.dryRun)return V("buy_bulk",{domains:r.map($=>({domain:$.domain,price:$.price})),unavailable:o.map($=>$.domain),total_price:parseFloat(a.toFixed(2))},t.json,t.fields);if(!qe(t)){c();let $=await je({message:`Purchase ${$e.default.bold(String(r.length))} domain${r.length>1?"s":""} for ${v.price(a.toFixed(2))}?`});if(!$||typeof $=="symbol"){console.log(` ${$e.default.dim("Cancelled.")}`);return}}c();let l=r.map($=>({cells:[v.domain($.domain),$.price?`${v.price($.price.toFixed(2))}/yr`:""],status:"pending"})),m=Ye(["Domain","Price"],l,[30,12],!i);m.start();let u=await(await S("/api/domains/buy",{method:"POST",body:JSON.stringify({domains:r.map($=>$.domain)})})).json(),y=new Set((u.results||[]).map($=>$.domain)),k=new Map((u.errors||[]).map($=>[$.domain,$.error]));for(let $=0;$<r.length;$++){let _=r[$].domain.toLowerCase().trim();y.has(_)?m.markDone($,b.success):m.markDone($,b.error)}if(m.stop(),i){w(u,t.fields);return}c();let g=u.summary?.succeeded??0,p=u.summary?.failed??0;if(g>0&&console.log(` ${b.success} ${$e.default.green(`${g} domain${g>1?"s":""} registered`)}`),p>0){console.log(` ${b.error} ${$e.default.red(`${p} failed`)}`);for(let $ of u.errors||[])console.log(` ${$e.default.dim("\u2500")} ${v.domain($.domain)}: ${$e.default.dim($.error)}${$.hint?` ${$e.default.dim(`(${$.hint})`)}`:""}`)}c(),g>0&&(E("Configure DNS:","domani dns <domain>"),c())}async function Js(e,t){let i=e.filter(Boolean);if(i.length===0){ye||f("Missing required argument: domain(s)",{hint:"Usage: domani buy <domain> [domain2 ...]",code:"missing_argument",json:t.json});let s=await pe({message:"Domain to purchase",placeholder:"e.g. myapp.dev (space-separated for multiple)"});(Q(s)||!s)&&process.exit(0),i=s.split(/\s+/).filter(Boolean)}return i.length===1?ao(i[0],t):lo(i,t)}var Oe=P(U(),1);async function Gs(e){let t=x(!e.json);t.start("Loading domains");let i=await S("/api/domains"),s=await i.json();if(i.ok||(t.stop("Failed"),f(s.error||s.message,{hint:s.hint,status:i.status,json:e.json,fields:e.fields})),t.stop(`${s.domains.length} domain(s)`),e.json){w({...s,count:s.domains.length},e.fields);return}if(s.domains.length===0){c(),console.log(` ${Oe.default.dim("No domains yet.")} Use: ${Oe.default.cyan("domani buy <domain>")}`),c();return}let n=[30,12,12,14];j(`Your Domains (${s.domains.length})`,n.reduce((o,a)=>o+a,0)+n.length-1);let r=s.domains.map(o=>{let a=new Date(o.expiresAt).toLocaleDateString(),l=o.status==="active"?Oe.default.green:o.status==="pending"?Oe.default.yellow:Oe.default.red,m=o.autoRenew?Oe.default.green("on"):Oe.default.dim("off");return[v.domain(o.domain),l(o.status),m,Oe.default.dim(a)]});ee(["Domain","Status","Auto-renew","Expires"],r,n),c()}var ie=P(U(),1);var Ei=P(U(),1);async function z(){ye||f("Missing required argument: domain",{hint:"Pass the domain as an argument, e.g. 'domani settings example.com'",code:"missing_argument",json:!0});let e=x(!0);e.start("Loading your domains");let t=await S("/api/domains"),i=await t.json();t.ok||(e.stop("Failed"),Ri(i.error,i.hint),process.exit(1));let s=i.domains||[];s.length===0&&(e.stop("No domains"),c(),console.log(` ${Ei.default.dim("No domains yet.")} Use: ${Ei.default.cyan("domani buy <domain>")}`),c(),process.exit(0)),e.stop(`${s.length} domain(s)`);let n=await Le({message:"Which domain?",options:s.map(r=>({value:r.domain,label:r.domain,hint:r.status!=="active"?r.status:void 0}))});return Q(n)&&process.exit(0),n}var Vt=require("node:fs"),Ti=require("node:path");async function Bs(e,t,i,s,n,r){e||(e=await z()),q(e,r);let o=r?.json??!1,a=r?.type||i,l=r?.name||s,m=r?.value||n;if(!t||t==="get"){let d=x(!o);d.start(`Loading DNS for ${v.domain(e)}`);let u=await S(`/api/domains/${encodeURIComponent(e)}/dns`),y=await u.json();if(u.ok||(d.stop("Failed"),f(y.error||y.message,{hint:y.hint,status:u.status,json:o,fields:r?.fields})),d.stop(`${y.records.length} record(s)`),o){w(y,r?.fields);return}if(y.records.length===0){c(),console.log(` ${ie.default.dim(`No DNS records for ${e}`)}`),c(),E("Auto-configure DNS:",`domani connect ${e}`),c();return}let k=[8,24,40,8];j(`DNS ${v.domain(e)}`,k.reduce((p,$)=>p+$,0)+k.length-1);let g=y.records.map(p=>{let $=p.priority?ie.default.dim(` pri=${p.priority}`):"";return[ie.default.yellow(p.type),p.name,ie.default.cyan(p.value)+$,ie.default.dim(String(p.ttl))]});ee(["Type","Name","Value","TTL"],g,k),c();return}if(t==="set"){if((!a||!l||!m)&&f("Missing arguments for dns set",{hint:"Usage: domani dns <domain> set --type A --name www --value 1.2.3.4",code:"validation_error",json:o,fields:r?.fields}),r?.dryRun)return V("dns_set",{domain:e,record:{type:a.toUpperCase(),name:l,value:m,ttl:3600}},o,r?.fields);let d=x(!o);d.start(`Setting ${ie.default.yellow(a.toUpperCase())} record`);let u=await S(`/api/domains/${encodeURIComponent(e)}/dns`),y=await u.json(),g=(u.ok?y.records:[]).filter(_=>!(_.type===a.toUpperCase()&&_.name===l));g.push({type:a.toUpperCase(),name:l,value:m,ttl:3600});let p=await S(`/api/domains/${encodeURIComponent(e)}/dns`,{method:"PUT",body:JSON.stringify({records:g})}),$=await p.json();p.ok||(d.stop("Failed"),f($.error||$.message,{hint:$.hint,status:p.status,json:o,fields:r?.fields})),d.stop(`${b.success} ${ie.default.yellow(a.toUpperCase())} ${l} ${b.arrow} ${ie.default.cyan(m)}`),o?w($,r?.fields):(c(),E("Check propagation:",`domani status ${e}`),c());return}if(t==="delete"){if((!a||!l)&&f("Missing arguments for dns delete",{hint:"Usage: domani dns <domain> delete --type A --name www",code:"validation_error",json:o,fields:r?.fields}),r?.dryRun)return V("dns_delete",{domain:e,record:{type:a.toUpperCase(),name:l}},o,r?.fields);let d=x(!o);d.start(`Deleting ${ie.default.yellow(a.toUpperCase())} ${l}`);let u=await S(`/api/domains/${encodeURIComponent(e)}/dns?type=${encodeURIComponent(a.toUpperCase())}&name=${encodeURIComponent(l)}`,{method:"DELETE"}),y=await u.json();u.ok||(d.stop("Failed"),f(y.error||y.message,{hint:y.hint,status:u.status,json:o,fields:r?.fields})),d.stop(`${b.success} Deleted ${ie.default.yellow(a.toUpperCase())} ${l}`),o?w(y,r?.fields):(c(),E("Check propagation:",`domani status ${e}`),c());return}if(t==="snapshot"){if(r?.dryRun)return V("dns_snapshot",{domain:e},o,r?.fields);let d=x(!o);d.start(`Capturing DNS snapshot for ${v.domain(e)}`);let u=await S(`/api/domains/${encodeURIComponent(e)}/dns/snapshot`,{method:"POST"}),y=await u.json();u.ok||(d.stop("Failed"),f(y.error||y.message,{hint:y.hint,status:u.status,json:o,fields:r?.fields}));let k=y.records?.length??0;if(d.stop(`${b.success} Captured ${k} record(s)`),o){w(y,r?.fields);return}let g=`${e}.dns.json`,p=(0,Ti.resolve)(process.cwd(),g);(0,Vt.writeFileSync)(p,JSON.stringify(y,null,2)+`
85
- `),j("DNS Snapshot"),h("Domain",v.domain(y.domain)),h("Records",String(k)),h("Subdomains",String(y.subdomains?.length??0)),h("Sources",(y.sources||[]).join(", ")||"none"),h("Captured",y.capturedAt||y.captured_at||"now"),h("Saved to",ie.default.cyan(g)),c(),E("Restore from this snapshot:",`domani dns ${e} restore --file ${g}`),c();return}if(t==="restore"){if(r?.dryRun)return V("dns_restore",{domain:e,source:r?.file||"server_backup"},o,r?.fields);let d=x(!o),u;if(r?.file){let g=(0,Ti.resolve)(process.cwd(),r.file);g.startsWith(process.cwd())||f("File path must be within the current directory",{hint:`Got: ${r.file}`,code:"validation_error",json:o,fields:r?.fields});try{let p=(0,Vt.readFileSync)(g,"utf-8"),$=JSON.parse(p);u=JSON.stringify({snapshot:$}),d.start(`Restoring DNS for ${v.domain(e)} from ${ie.default.cyan(r.file)}`)}catch(p){f(`Failed to read snapshot file: ${p instanceof Error?p.message:"unknown"}`,{hint:`Make sure ${r.file} exists and contains valid JSON.`,code:"validation_error",json:o,fields:r?.fields})}}else d.start(`Restoring DNS for ${v.domain(e)} from server backup`);let y=await S(`/api/domains/${encodeURIComponent(e)}/dns/restore`,{method:"POST",...u?{body:u}:{}}),k=await y.json();if(y.ok||(d.stop("Failed"),f(k.error||k.message,{hint:k.hint,status:y.status,json:o,fields:r?.fields})),d.stop(`${b.success} Restored DNS`),o){w(k,r?.fields);return}if(j("DNS Restored"),h("Domain",v.domain(k.domain)),h("Applied",ie.default.green(String(k.applied??0))),h("Skipped",ie.default.dim(String(k.skipped??0))),k.errors?.length>0){h("Errors",ie.default.red(String(k.errors.length)));for(let g of k.errors)console.log(` ${ie.default.red("\u2022")} ${g}`)}c(),E("Verify DNS records:",`domani dns ${e}`),c();return}f(`Unknown action: ${t}`,{hint:"Use 'get', 'set', 'delete', 'snapshot', or 'restore'.",code:"validation_error",json:o,fields:r?.fields})}var He=P(U(),1);async function Ks(e){let t=new URLSearchParams;e.maxPrice&&t.set("max_price",e.maxPrice),e.minPrice&&t.set("min_price",e.minPrice),e.sort&&t.set("sort",e.sort),e.search&&t.set("search",e.search),e.limit&&t.set("limit",e.limit),t.set("order","asc");let i=x(!e.json);i.start("Loading TLDs");let s=await oe(`/api/tlds?${t}`),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${n.total} TLDs loaded`),e.json){w(n,e.fields);return}let r=n.tlds;if(r.length===0){c(),console.log(` ${He.default.dim("No TLDs match your filters.")}`),c();return}j("TLD Pricing");let o=r.map(a=>[He.default.bold(`.${a.tld}`),v.price(a.registration.toFixed(2))+He.default.dim("/yr"),He.default.dim("renew ")+v.price(a.renewal.toFixed(2))+He.default.dim("/yr")]);ee(["TLD","Register","Renewal"],o,[22,16,20]),c(),console.log(` ${He.default.dim(`${n.total} TLDs total`)}`),c()}var se=P(U(),1);async function Ys(e,t){q(e,t);let i=x(!t.json);i.start(`Looking up ${v.domain(e)}`);let[s,n]=await Promise.all([oe(`/api/domains/whois?q=${encodeURIComponent(e)}`),oe(`/api/domains/${encodeURIComponent(e)}/og`).catch(()=>null)]),r=await s.json(),o=null;try{n?.ok&&(o=await n.json())}catch{}if(s.ok||(i.stop("Lookup failed"),f(r.error||r.message,{hint:r.hint,status:s.status,json:t.json,fields:t.fields})),i.stop("WHOIS data retrieved"),t.json){w({...r,...o?{og:o}:{}},t.fields);return}if(j(`WHOIS ${v.domain(r.domain)}`),!r.registered){h("Status",`${b.success} ${se.default.green("not registered")}`),c(),E("Register it:",`domani buy ${r.domain}`),c();return}if(h("Status",`${b.error} ${se.default.red("registered")}`),(o?.title||o?.description)&&(c(),console.log(` ${se.default.bold("Website preview")}`),console.log(` ${se.default.dim("\u2500".repeat(50))}`),o.title&&h("Title",o.title),o.description&&h("Description",se.default.dim(o.description.length>80?o.description.slice(0,80)+"\u2026":o.description)),c()),r.registrar&&h("Registrar",r.registrar),r.created&&h("Created",r.created),r.expires&&h("Expires",r.expires),r.days_until_expiry!=null){let l=r.days_until_expiry,m=l<30?se.default.red:l<90?se.default.yellow:se.default.green;h("Days left",m(String(l)))}r.updated&&h("Updated",r.updated),h("DNSSEC",r.dnssec?se.default.green("yes"):se.default.dim("no")),r.nameservers?.length>0&&h("Nameservers",r.nameservers.map(l=>se.default.cyan(l)).join(se.default.dim(", "))),r.status?.length>0&&h("Status codes",se.default.dim(r.status.join(", ")));let a=r.contacts?.registrant;a&&!r.redacted?(c(),console.log(` ${se.default.bold("Registrant")}`),console.log(` ${se.default.dim("\u2500".repeat(50))}`),a.name&&h("Name",a.name),a.organization&&h("Organization",a.organization),a.email&&h("Email",v.url(a.email)),a.country&&h("Country",a.country)):r.redacted&&h("Contact",se.default.dim("redacted (WHOIS privacy)")),c()}var Ae=P(U(),1);async function zs(e,t){if(!e){ye||f("Missing required argument: prompt",{hint:'Usage: domani suggest "describe your project"',code:"missing_argument",json:t.json});let g=await pe({message:"Describe your project or idea",placeholder:"e.g. AI coding assistant, pet food delivery..."});(Q(g)||!g)&&process.exit(0),e=g}let i=new URLSearchParams({prompt:e});if(t.count&&i.set("count",t.count),t.tlds&&i.set("tlds",t.tlds),t.tlds&&Ft(t.tlds.split(",").map(g=>g.trim()),t),t.style&&i.set("style",t.style),t.lang&&i.set("lang",t.lang),t.json){let g=x(!1);g.start("Finding available domains");let p=t.timeout?parseInt(t.timeout,10)*1e3:6e4,$;try{$=await oe(`/api/domains/suggest?${i}`,{signal:AbortSignal.timeout(p)})}catch{g.stop("Failed"),f("Request timed out",{hint:"Suggest took too long. Try --timeout <seconds> to increase.",code:"timeout",json:t.json,fields:t.fields})}let _=await $.json();$.ok||(g.stop("Failed"),f(_.error||_.message,{hint:_.hint,status:$.status,json:t.json,fields:t.fields})),w(_,t.fields);return}let s=x(!0);s.start("Finding available domains");let n=t.timeout?parseInt(t.timeout,10)*1e3:6e4,r;try{r=await oe(`/api/domains/suggest?${i}`,{headers:{Accept:"text/event-stream"},signal:AbortSignal.timeout(n)})}catch{s.stop("Failed"),f("Request timed out",{hint:"Suggest took too long. Try --timeout <seconds> to increase.",code:"timeout"})}if(!r.ok){s.stop("Failed");try{let g=await r.json();f(g.error||g.message||`Server error (${r.status})`,{hint:g.hint,status:r.status})}catch{f(`Server error (${r.status})`,{status:r.status})}}let o=r.body;o||(s.stop("Failed"),f("Empty response"));let a=[],l=[],m=!1,d=0;function u(){m||(m=!0,s.stop("Finding available domains"),c())}let y=new TextDecoder,k="";for await(let g of o){k+=y.decode(g,{stream:!0});let p=k.split(`
86
- `);k=p.pop()??"";let $="";for(let _ of p)if(_.startsWith("event: "))$=_.slice(7);else if(_.startsWith("data: "))try{let A=JSON.parse(_.slice(6));if($==="result")d++,A.available?a.push(A):l.push(A),m||s.message(`Finding available domains ${Ae.default.dim(`(${d} checked, ${a.length} available)`)}`);else if($==="iteration")m||s.message(`Finding available domains ${Ae.default.dim(`(round ${A.n})`)}`);else if($==="done"){u();for(let T of a){let M=T.reason?` ${Ae.default.dim(T.reason)}`:"";console.log(` ${b.success} ${v.domain(T.domain).padEnd(37)} ${v.price(T.price)}${Ae.default.dim("/yr")}${M}`)}for(let T of l)console.log(` ${b.error} ${Ae.default.dim(T.domain.padEnd(38))} ${Ae.default.red("taken")}`);console.log(` ${Ae.default.dim("\u2500".repeat(50))}`),console.log(` ${Ae.default.dim(`Found ${A.total} available \xB7 checked ${A.checked} \xB7 ${A.iterations} round${A.iterations>1?"s":""}`)}`)}else $==="error"&&(m||s.stop("Failed"),f(A.message))}catch{}}a.length===0&&l.length===0&&(m||s.stop("No results"),f("Could not find available domains for this prompt.")),c(),a.length>0&&(E("Register one:",`domani buy ${a[0].domain}`),c())}var K=P(U(),1);async function Zs(e,t,i){e||(e=await z()),q(e,i);let s;if(t&&!i.provider?t.includes(".")?s=t:i.provider=t:s=t,!s&&!i.provider&&!i.list&&i.dryRun)return V("connect",{domain:e,note:"No provider specified. Pass --provider <name> to connect."},i.json,i.fields);if(!s&&!i.provider&&!i.list){let n=x(!i.json);n.start(`Loading providers for ${v.domain(e)}`);let r=await S(`/api/domains/${encodeURIComponent(e)}/connect`),o=await r.json();if(r.ok||(n.stop("Failed"),f(o.error||o.message,{hint:o.hint,status:r.status,json:i.json,fields:i.fields})),n.stop("Providers loaded"),i.json){w(o,i.fields);return}let a=[];for(let p of["hosting","email"]){let $=o.providers?.[p]||[];for(let _ of $)a.push({value:`${p}:${_.name}`,label:_.name,hint:p})}a.length===0&&f("No providers available",{code:"not_found",json:i.json,fields:i.fields});let l=await Le({message:"Choose a provider",options:a});Q(l)&&process.exit(0);let[m,d]=l.split(":"),y=(o.providers?.[m]||[]).find(p=>p.name===d),k;if(y&&y.methods.length>1){let p=await Le({message:"Choose a method",options:y.methods.map($=>({value:$.name,label:$.name,hint:$.default?"default":void 0}))});Q(p)&&process.exit(0),k=p}let g;if(m==="hosting"&&y?.requires_target){y.notes?.setup&&Ke(y.notes.setup);let p=await pe({message:"Target hostname or IP"});Q(p)&&process.exit(0),g=p.trim()}return Xs(e,{target:g,provider:d,method:k,dryRun:i.dryRun,json:!1})}if(i.list){let n=x(!i.json);n.start(`Loading providers for ${v.domain(e)}`);let r=await S(`/api/domains/${encodeURIComponent(e)}/connect`),o=await r.json();if(r.ok||(n.stop("Failed"),f(o.error||o.message,{hint:o.hint,status:r.status,json:i.json,fields:i.fields})),n.stop("Providers loaded"),i.json){w(o,i.fields);return}j(`Providers for ${v.domain(o.domain)}`);for(let a of["hosting","email"]){let l=o.providers?.[a];if(l?.length){c(),console.log(` ${K.default.bold(a.toUpperCase())}`);for(let m of l){let d=m.methods.map(u=>u.default?K.default.green(`${u.name} (default)`):K.default.dim(u.name)).join(K.default.dim(", "));console.log(` ${K.default.cyan(m.name.padEnd(20))} ${d}`)}}}c();return}return Xs(e,i)}async function Xs(e,t){let i={};if(t.target&&(i.target=t.target),t.provider&&(i.provider=t.provider),t.method&&(i.method=t.method),t.dryRun)return V("connect",{domain:e,...i},t.json,t.fields);let s=x(!t.json);s.start(`Connecting ${v.domain(e)}`);let n=await S(`/api/domains/${encodeURIComponent(e)}/connect`,{method:"POST",body:JSON.stringify(i)}),r=await n.json();n.ok||(s.stop("Connection failed"),f(r.error||r.message,{hint:r.hint,status:n.status,json:t.json,fields:t.fields}));let o=r.status==="manual_setup_required";if(s.stop(o?`${b.success} DNS instructions for ${K.default.cyan(r.provider)}`:`${b.success} Connected to ${K.default.cyan(r.provider)}`),t.json){w(r,t.fields);return}if(j(o?`Add these records at your registrar for ${v.domain(r.domain)}`:`Connected ${v.domain(r.domain)}`),h("Provider",K.default.cyan(r.provider)),h("Method",r.method),r.records?.length){let a=[8,22,40];c(),console.log(` ${K.default.bold("DNS Records")}`);let l=["Type","Name","Value"].map((d,u)=>K.default.dim(d.padEnd(a[u]))).join(" "),m=a.map(d=>K.default.dim("\u2500".repeat(d))).join(" ");console.log(` ${l}`),console.log(` ${m}`);for(let d of r.records){let u=d.record,y=d.status!=="already_set";process.stdout.isTTY&&y&&await st(50);let g=[K.default.yellow(u.type),u.name,K.default.cyan(u.value)+(u.priority?K.default.dim(` pri=${u.priority}`):"")].map((_,A)=>Dt(_,a[A])).join(" "),p=d.status==="already_set"?K.default.dim("\u2713"):d.status==="updated"?K.default.yellow("\u21BA"):d.status==="pending"?K.default.yellow("\u2192"):b.success,$=d.status==="already_set"?K.default.dim(" already set"):d.status==="updated"?K.default.dim(" updated"):d.status==="pending"?K.default.dim(" add this"):"";console.log(` ${p} ${g}${$}`)}}c(),r.next_steps?.length?(console.log(` ${K.default.bold("Next steps")}`),r.next_steps.forEach((a,l)=>{console.log(` ${K.default.dim(`${l+1}.`)} ${a}`)})):r.hint&&console.log(` ${K.default.dim(r.hint)}`),r.docs&&console.log(` ${K.default.dim("Docs:")} ${v.url(r.docs)}`),c()}var be=P(U(),1);function co(e){return[be.default.yellow(e.type),e.name,be.default.cyan(e.value)+(e.priority?be.default.dim(` pri=${e.priority}`):"")]}function uo(e){if(j(`Status ${v.domain(e.domain)}`),e.expires){let t=new Date(e.expires).toLocaleDateString(),i=e.days_until_expiry,s=i!=null&&i<30?be.default.red:i!=null&&i<90?be.default.yellow:be.default.green;h("Expires",`${t} ${be.default.dim("(")}${s(`${i} days`)}${be.default.dim(")")}`)}}async function Qs(e,t){if(e||(e=await z()),q(e,t),t.json){let d=x(!1),u=await S(`/api/domains/${encodeURIComponent(e)}/status`),y=await u.json();u.ok||f(y.error||y.message,{hint:y.hint,status:u.status,json:t.json,fields:t.fields}),w(y,t.fields);return}let i=x(!0);i.start(`Checking ${v.domain(e)}`);let s;try{s=await S(`/api/domains/${encodeURIComponent(e)}/status`,{headers:{Accept:"text/event-stream"},signal:AbortSignal.timeout(t.timeout?parseInt(t.timeout,10)*1e3:3e4)})}catch{i.stop("Failed"),f("Request timed out",{hint:"The status check took too long. Try again.",code:"timeout",json:t.json,fields:t.fields})}if(!s.ok){i.stop("Failed");try{let d=await s.json();f(d.error||d.message,{hint:d.hint,status:s.status,json:t.json,fields:t.fields})}catch{f(`Server error (${s.status})`,{status:s.status,json:t.json,fields:t.fields})}}let n=s.body;n||(i.stop("Failed"),f("Empty response"));let r=new TextDecoder,o="",a=null,l=[],m=!1;try{for await(let d of n){o+=r.decode(d,{stream:!0});let u=o.split(`
87
- `);o=u.pop()??"";let y="";for(let k of u)if(k.startsWith("event: "))y=k.slice(7);else if(k.startsWith("data: ")){let g=JSON.parse(k.slice(6));if(y==="info"&&(i.stop("Status retrieved"),m=!0,uo(g)),y==="records")if(l=g,l.length>0){c(),console.log(` ${be.default.bold("DNS Records")}`);let p=[8,10,34];a=Ye(["Type","Name","Value"],l.map($=>({cells:co($),status:"pending"})),p),a.start()}else c(),h("DNS",be.default.dim("no records")),E("Auto-configure DNS:",`domani connect ${e}`);if(y==="propagation"&&a){let{index:p,propagated:$}=g,_=$?b.success:`${b.warning}`;a.markDone(p,_)}y==="done"&&a&&a.stop(),y==="error"&&(m||i.stop("Failed"),a&&a.stop(),f(g.message||"Status check failed"))}}}catch{m||i.stop("Failed"),a&&a.stop(),f("Connection lost",{hint:"The status check was interrupted. Try again.",code:"connection_lost",json:t.json,fields:t.fields})}m||i.stop("Done"),c()}var ze=P(U(),1);async function en(e,t){if(q(e,t),!t.authCode){(t.json||!process.stdout.isTTY)&&f("--auth-code is required",{hint:"Get the EPP/auth code from your current registrar.",code:"validation_error",json:t.json,fields:t.fields});let a=await pe({message:"Enter the EPP/auth code from your current registrar:",validate:l=>!l||l.trim().length===0?"Auth code is required":void 0});Q(a)&&process.exit(0),t.authCode=a}let i=x(!t.json);i.start(`Checking transfer eligibility for ${v.domain(e)}`);let s=await S(`/api/domains/transfer-check?domain=${encodeURIComponent(e)}`),n=await s.json();if(s.ok||(i.stop("Check failed"),f(n.error,{hint:n.hint,status:s.status,json:t.json,fields:t.fields})),n.eligible||(i.stop(`${b.error} Not eligible`),f(n.reason||"Domain is not eligible for transfer.",{hint:n.hint,code:"not_eligible",json:t.json,fields:t.fields})),i.stop(`${b.success} Eligible for transfer`),t.dryRun)return V("transfer",{domain:e,eligible:!0,price:n.price,currency:n.currency||"USD",includes_renewal:!0},t.json,t.fields);if(!qe(t)){c();let a=n.price!=null?` for ${v.price(n.price.toFixed(2))}`:"",l=await je({message:`Transfer ${ze.default.bold(e)} to ${Be}${a}? (includes 1 year renewal)`});if(!l||typeof l=="symbol"){console.log(` ${ze.default.dim("Cancelled.")}`);return}}i.start(`Initiating transfer for ${v.domain(e)}`);let r=await S("/api/domains/transfer",{method:"POST",body:JSON.stringify({domain:e,auth_code:t.authCode})}),o=await r.json();if(r.ok||(i.stop("Transfer failed"),f(o.error||o.message,{hint:o.hint,fixUrl:o.setup_url,status:r.status,json:t.json,fields:t.fields})),i.stop(`${b.success} Transfer initiated`),t.json){w(o,t.fields);return}j("Transfer Initiated"),h("Domain",v.domain(o.domain)),h("Status",ze.default.yellow(o.status||"pending")),o.price&&h("Price",v.price(o.price)+ze.default.dim(` ${o.currency||"USD"}`)),o.payment_method&&h("Payment",o.payment_method),o.expires&&h("Expires",new Date(o.expires).toLocaleDateString()),o.hint&&(c(),console.log(` ${ze.default.dim(o.hint)}`)),c(),E("Check transfer progress:",`domani status ${o.domain}`),c()}var Mt=P(U(),1);async function tn(e,t){e||(e=await z()),q(e,t);let i=t.years?parseInt(t.years,10):1;if((isNaN(i)||i<1||i>10)&&f("--years must be between 1 and 10",{code:"validation_error",json:t.json,fields:t.fields}),t.dryRun)return V("renew",{domain:e,years:i},t.json,t.fields);if(!qe(t)){c();let o=await je({message:`Renew ${Mt.default.bold(e)} for ${i} year${i>1?"s":""}? You will be charged.`});if(!o||typeof o=="symbol"){console.log(` ${Mt.default.dim("Cancelled.")}`);return}}let s=x(!t.json);s.start(`Renewing ${v.domain(e)}`);let n=await S(`/api/domains/${encodeURIComponent(e)}/renew`,{method:"POST",body:JSON.stringify({years:i})}),r=await n.json();if(n.ok||(s.stop("Renewal failed"),f(r.error||r.message,{hint:r.hint,fixUrl:r.setup_url,status:n.status,json:t.json,fields:t.fields})),s.stop(`${b.success} Domain renewed`),t.json){w(r,t.fields);return}j("Renewal Complete"),h("Domain",v.domain(r.domain)),h("Years",String(r.renewed_years)),h("New expiry",new Date(r.new_expiry).toLocaleDateString()),r.price&&h("Price",v.price(r.price)+Mt.default.dim(` ${r.currency||"USD"}`)),r.payment_method&&h("Payment",r.payment_method),c(),E("Verify renewal:",`domani status ${r.domain}`),c()}var we=P(U(),1);async function sn(e,t){e||f("Domain is required",{hint:`Usage: domani import <domain>
88
- domani import <domain> --verify`,code:"validation_error",json:t.json,fields:t.fields}),q(e,t);let i=t.verify?"/api/domains/import/verify":"/api/domains/import",s=x(!t.json);s.start(t.verify?`Verifying ownership of ${v.domain(e)}`:`Initiating import for ${v.domain(e)}`);let n=await S(i,{method:"POST",body:JSON.stringify({domain:e})}),r=await n.json();if(n.ok||(s.stop(t.verify?"Verification failed":"Import failed"),f(r.error||r.message,{hint:r.hint,status:n.status,json:t.json,fields:t.fields})),t.json){s.stop(""),w(r,t.fields);return}t.verify?(s.stop(`${b.success} ${v.domain(e)} imported!`),j("Domain Imported"),h("Domain",v.domain(r.domain)),h("Status",we.default.green(r.status||"active")),r.expires_at&&h("Expires",new Date(r.expires_at).toLocaleDateString()),r.registrar&&h("Registrar",r.registrar),c(),E("Check domain health:",`domani status ${r.domain}`),c()):(s.stop(`${b.success} Verification record ready`),j("Import Domain"),h("Domain",v.domain(r.domain)),h("Status",we.default.yellow("pending verification")),c(),console.log(" Add this TXT record at your DNS provider:"),c(),console.log(` ${we.default.dim("Type:")} ${we.default.bold("TXT")}`),console.log(` ${we.default.dim("Name:")} ${we.default.bold(r.txt_record?.name||"@")}`),console.log(` ${we.default.dim("Value:")} ${we.default.bold(r.txt_record?.value||`domani-verify=${r.token}`)}`),c(),console.log(` ${we.default.dim("DNS propagation may take a few minutes to 48 hours.")}`),c(),E("Once the record is set, verify:",`domani import ${e} --verify`),c())}var D=P(U(),1);var mo=["setup","status","remove","list","create","delete","send","inbox","webhook","forward","check","connect"],fo={"google-workspace":"Google Workspace",fastmail:"Fastmail",proton:"Proton Mail"};function ho(e){return[D.default.yellow(e.type),e.name,D.default.cyan(e.value)+(e.priority?D.default.dim(` pri=${e.priority}`):"")]}function Pi(e){return fo[e]||e}function po(e,t){if(e&&e.includes("@")){let[i,s]=e.split("@",2);!t.slug&&i&&(t.slug=i),!t.domain&&s&&(t.domain=s)}}async function Re(e){return e.domain?(q(e.domain,e),e.domain):z()}async function an(e,t,i){if(e&&e.includes(".")&&!mo.includes(e))return i.check?rn(e,!!i.json,i.fields):t?on(e,t,!!i.json,i.fields):ln(e,!!i.json,i.fields);if(po(t,i),i.body&&!i.text&&(i.text=i.body),i.from&&i.from.includes("@")){let[s,n]=i.from.split("@",2);!i.slug&&s&&(i.slug=s),!i.domain&&n&&(i.domain=n)}switch(e){case void 0:return nn(i);case"list":return nn(i);case"inbox":return _o(i);case"setup":return go(i);case"status":return $o(i);case"remove":return yo(i);case"create":return bo(i);case"delete":return vo(i);case"send":return wo(i);case"webhook":return xo(i);case"forward":return So(i);case"check":return rn(i.domain||await z(),!!i.json,i.fields);case"connect":return on(i.domain||await z(),t||void 0,!!i.json,i.fields);default:f(`Unknown action: ${e}`,{hint:"Actions: list, inbox, create, delete, send, forward, webhook, setup, status, check, connect",code:"validation_error",json:i.json,fields:i.fields})}}async function go(e){let t=await Re(e);if(e.dryRun)return V("email_setup",{domain:t},e.json,e.fields);let i=x(!e.json);i.start(`Setting up email on ${v.domain(t)}`);let s=await S(`/api/domains/${encodeURIComponent(t)}/email/setup`,{method:"POST"}),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${b.success} Email ${n.status==="already_configured"?"already configured":"configured"}`),e.json){w(n,e.fields);return}if(n.records?.length){c(),j(`Email DNS Records ${v.domain(t)}`);let r=n.records.map(o=>[D.default.yellow(o.type),o.name,o.value.length>40?o.value.slice(0,40)+"...":o.value,o.status==="verified"||o.status==="created"?D.default.green(o.status):D.default.yellow(o.status)]);ee(["Type","Name","Value","Status"],r,[8,28,44,12])}c(),n.hint&&Ke(n.hint),E("Check status:",`domani email status --domain ${t}`),c()}async function $o(e){let t=await Re(e),i=x(!e.json);i.start(`Checking email status for ${v.domain(t)}`);let s=await S(`/api/domains/${encodeURIComponent(t)}/email/status`),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${b.success} Status loaded`),e.json){w(n,e.fields);return}if(j(`Email ${v.domain(t)}`),h("Enabled",n.enabled?D.default.green("yes"):D.default.dim("no")),n.enabled&&(h("Verified",n.verified?D.default.green("yes"):D.default.yellow("pending")),h("Mailboxes",String(n.mailbox_count))),c(),!n.enabled)E("Set up email:",`domani email setup --domain ${t}`),c();else if(!n.verified&&n.records?.length){console.log(` ${D.default.yellow("!")} Add these DNS records to verify:`);for(let r of n.records)console.log(` ${D.default.yellow(r.type)} ${r.name} ${D.default.dim("\u2192")} ${r.value.length>50?r.value.slice(0,50)+"...":r.value}`);c()}}async function yo(e){let t=await Re(e);if(e.dryRun)return V("email_remove",{domain:t},e.json,e.fields);let i=x(!e.json);i.start(`Removing email from ${v.domain(t)}`);let s=await S(`/api/domains/${encodeURIComponent(t)}/email/setup`,{method:"DELETE"}),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${b.success} Email disabled`),e.json){w(n,e.fields);return}n.mailboxes_deleted>0&&console.log(` ${D.default.dim(`${n.mailboxes_deleted} mailbox(es) deleted.`)}`),c()}async function nn(e){let t=x(!e.json);t.start("Loading mailboxes");let i=e.domain?`/api/domains/${encodeURIComponent(e.domain)}/email`:"/api/email",s=await S(i),n=await s.json();s.ok||(t.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields}));let r=n.mailboxes||[];if(t.stop(`${b.success} ${r.length} mailbox(es)`),e.json){w(n,e.fields);return}if(r.length===0){c(),console.log(` ${D.default.dim("No mailboxes.")}`),c(),E("Create one:","domani email create hello@example.com"),c();return}c(),j("Mailboxes");let o=r.map(a=>[D.default.cyan(a.address),String(a.message_count),a.webhook_url?v.url(a.webhook_url):D.default.dim("-"),D.default.dim(new Date(a.created_at).toLocaleDateString())]);ee(["Address","Messages","Webhook","Created"],o,[32,10,36,14]),c()}async function bo(e){let t=await Re(e);if(e.dryRun)return V("email_create_mailbox",{domain:t,slug:e.slug},e.json,e.fields);let i=x(!e.json);i.start("Creating mailbox");let s={};e.slug&&(s.slug=e.slug);let n=await S(`/api/domains/${encodeURIComponent(t)}/email`,{method:"POST",body:JSON.stringify(s)}),r=await n.json();if(n.ok||(i.stop("Failed"),f(r.error||r.message,{hint:r.hint,status:n.status,json:e.json,fields:e.fields})),i.stop(`${b.success} Mailbox created`),e.json){w(r,e.fields);return}j("Mailbox Created"),h("Address",D.default.cyan(r.address)),h("Domain",r.domain),r.webhook_url&&h("Webhook",v.url(r.webhook_url)),c()}async function vo(e){let t=await Re(e);if(e.slug||f("Slug required",{hint:"Usage: domani email delete hello@example.com",code:"validation_error",json:e.json,fields:e.fields}),e.dryRun)return V("email_delete_mailbox",{domain:t,address:`${e.slug}@${t}`},e.json,e.fields);let i=x(!e.json);i.start(`Deleting ${e.slug}@${t}`);let s=await S(`/api/domains/${encodeURIComponent(t)}/email/${encodeURIComponent(e.slug)}`,{method:"DELETE"}),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${b.success} Mailbox deleted`),e.json){w(n,e.fields);return}console.log(` ${D.default.dim(`${n.address} and all messages deleted.`)}`),c()}async function wo(e){let t=await Re(e);if(e.slug||f("Slug required",{hint:'Usage: domani email send hello@example.com --to user@test.com --subject "Hi" --body "Hello"',code:"validation_error",json:e.json,fields:e.fields}),e.to||f("Recipient required",{hint:"Usage: domani email send hello@example.com --to user@test.com",code:"validation_error",json:e.json,fields:e.fields}),e.dryRun)return V("email_send",{from:`${e.slug}@${t}`,to:e.to,subject:e.subject},e.json,e.fields);let i=x(!e.json);i.start(`Sending from ${e.slug}@${t}`);let s={to:e.to};e.cc&&(s.cc=e.cc),e.bcc&&(s.bcc=e.bcc),e.subject&&(s.subject=e.subject),e.text&&(s.text=e.text),e.inReplyTo&&(s.in_reply_to=e.inReplyTo),e.references&&(s.references=e.references);let n=await S(`/api/domains/${encodeURIComponent(t)}/email/${encodeURIComponent(e.slug)}/send`,{method:"POST",body:JSON.stringify(s)}),r=await n.json();if(n.ok||(i.stop("Failed"),f(r.error||r.message,{hint:r.hint,status:n.status,json:e.json,fields:e.fields})),i.stop(`${b.success} Email sent`),e.json){w(r,e.fields);return}j("Email Sent"),h("From",r.from),h("To",r.to),r.subject&&h("Subject",r.subject),h("Status",D.default.green(r.status)),c()}async function _o(e){let t=await Re(e);e.slug||f("Slug required",{hint:"Usage: domani email inbox hello@example.com [--direction in|out] [--limit 20]",code:"validation_error",json:e.json,fields:e.fields});let i=new URLSearchParams;e.direction&&i.set("direction",e.direction),e.limit&&i.set("limit",e.limit);let s=i.toString()?`?${i}`:"",n=x(!e.json);n.start(`Loading messages for ${e.slug}@${t}`);let r=await S(`/api/domains/${encodeURIComponent(t)}/email/${encodeURIComponent(e.slug)}/messages${s}`),o=await r.json();r.ok||(n.stop("Failed"),f(o.error||o.message,{hint:o.hint,status:r.status,json:e.json,fields:e.fields}));let a=o.messages||[];if(n.stop(`${b.success} ${a.length} message(s)`),e.json){w(o,e.fields);return}if(a.length===0){c(),console.log(` ${D.default.dim("No messages.")}`),c();return}c(),j(`Messages ${e.slug}@${t}`);let l=a.map(m=>[m.direction==="in"?D.default.green("in"):D.default.blue("out"),m.direction==="in"?m.from:m.to,m.subject?m.subject.length>30?m.subject.slice(0,30)+"...":m.subject:D.default.dim("(no subject)"),D.default.dim(new Date(m.created_at).toLocaleString())]);ee(["Dir","From/To","Subject","Date"],l,[5,28,34,22]),o.next_cursor&&(c(),Ke("More messages available. Use --limit to paginate.")),c()}async function xo(e){let t=await Re(e);if(e.slug||f("Slug required",{hint:"Usage: domani email webhook hello@example.com --url https://...",code:"validation_error",json:e.json,fields:e.fields}),e.dryRun)return V("email_webhook",{address:`${e.slug}@${t}`,webhook_url:e.url||null},e.json,e.fields);let i=x(!e.json);i.start(`Updating webhook for ${e.slug}@${t}`);let s=await S(`/api/domains/${encodeURIComponent(t)}/email/${encodeURIComponent(e.slug)}`,{method:"PATCH",body:JSON.stringify({webhook_url:e.url||null})}),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${b.success} Webhook ${e.url?"set":"removed"}`),e.json){w(n,e.fields);return}j(`Mailbox ${n.address}`),h("Webhook",n.webhook_url?v.url(n.webhook_url):D.default.dim("none")),c()}async function So(e){let t=await Re(e);if(e.slug||f("Slug required",{hint:"Usage: domani email forward hello@example.com --forward-to me@gmail.com",code:"validation_error",json:e.json,fields:e.fields}),e.dryRun)return V("email_forward",{address:`${e.slug}@${t}`,forward_to:e.forwardTo||null},e.json,e.fields);let i=x(!e.json),s=e.forwardTo||null;i.start(`Updating forward for ${e.slug}@${t}`);let n=await S(`/api/domains/${encodeURIComponent(t)}/email/${encodeURIComponent(e.slug)}`,{method:"PATCH",body:JSON.stringify({forward_to:s})}),r=await n.json();if(n.ok||(i.stop("Failed"),f(r.error||r.message,{hint:r.hint,status:n.status,json:e.json,fields:e.fields})),i.stop(`${b.success} Forward ${s?"set":"removed"}`),e.json){w(r,e.fields);return}j(`Mailbox ${r.address}`),h("Forward to",r.forward_to?D.default.cyan(r.forward_to):D.default.dim("none")),c()}async function rn(e,t,i){let s=x(!t);s.start(`Checking email health for ${v.domain(e)}`);let n=await S(`/api/domains/${encodeURIComponent(e)}/email/check`),r=await n.json();if(n.ok||(s.stop("Failed"),f(r.error||r.message,{hint:r.hint,status:n.status,json:t,fields:i})),s.stop("Email health checked"),t){w(r,i);return}if(j(`Email Health ${v.domain(r.domain)}`),r.provider?h("Provider",D.default.cyan(Pi(r.provider))):h("Provider",D.default.dim("unknown")),r.mx.configured?h("MX",`${b.success} ${D.default.green("propagated")} ${D.default.dim(`(${r.mx.records.length} record${r.mx.records.length!==1?"s":""})`)}`):h("MX",`${b.error} ${D.default.red("not configured")}`),r.spf.configured?h("SPF",`${b.success} ${D.default.green(r.spf.value)}`):h("SPF",`${b.error} ${D.default.red("missing")}`),r.dmarc.configured){let o=r.dmarc.value.length>50?r.dmarc.value.slice(0,50)+"...":r.dmarc.value;h("DMARC",`${b.success} ${D.default.green(o)}`)}else h("DMARC",`${b.error} ${D.default.red("missing")}`);r.dkim.configured?h("DKIM",`${b.success} ${D.default.green("found")} ${D.default.dim(`(${r.dkim.selectors.join(", ")})`)}`):h("DKIM",`${b.warning} ${D.default.yellow("not found")}`),c(),r.mx.configured?(!r.spf.configured||!r.dmarc.configured)&&(Ke("SPF and DMARC protect against email spoofing. Re-run email setup to add them."),c()):(E("Set up email:",`domani email ${e} google`),c())}async function on(e,t,i,s){return t?cn(e,t,i,s):ln(e,i,s)}async function ln(e,t,i){let s=x(!t);s.start("Loading email providers");let n=await S(`/api/domains/${encodeURIComponent(e)}/connect`),r=await n.json();n.ok||(s.stop("Failed"),f(r.error||r.message,{hint:r.hint,status:n.status,json:t,fields:i})),s.stop("Providers loaded");let o=r.providers?.email||[];o.length===0&&f("No email providers available",{code:"not_found",json:t,fields:i});let a=await Le({message:"Choose an email provider",options:o.map(l=>({value:l.name,label:Pi(l.name)}))});return Q(a)&&process.exit(0),cn(e,a,t,i)}async function cn(e,t,i,s){if(i){let m=await S(`/api/domains/${encodeURIComponent(e)}/connect`,{method:"POST",body:JSON.stringify({target:t})}),d=await m.json();m.ok||f(d.error||d.message,{hint:d.hint,status:m.status,json:i,fields:s}),w(d,s);return}let n=await S(`/api/domains/${encodeURIComponent(e)}/connect?provider=${encodeURIComponent(t)}`);if(!n.ok){let m=await n.json();f(m.error||m.message,{hint:m.hint,status:n.status,json:i,fields:s})}let r=await n.json(),o=r.preview?.records??[],a=r.preview?.provider??t,l=Pi(a);if(j(`Email ${v.domain(e)}`),h("Provider",D.default.cyan(l)),o.length){c(),console.log(` ${D.default.bold("DNS Records")}`);let m=[8,24,40],d=Ye(["Type","Name","Value"],o.map(_=>({cells:ho(_),status:"pending"})),m);d.start();let u=await S(`/api/domains/${encodeURIComponent(e)}/connect`,{method:"POST",body:JSON.stringify({target:t})}),y=await u.json();u.ok||(d.stop(),c(),f(y.error||y.message,{hint:y.hint,status:u.status,json:i,fields:s}));let k=y.records||[];for(let _=0;_<o.length;_++)k.find(T=>T.record.type===o[_].type&&T.record.name===o[_].name&&T.record.value===o[_].value)?.status==="already_set"||await st(60),d.markDone(_);await st(80),d.stop();let g=k.filter(_=>_.status==="created"||_.status==="updated").length,p=k.filter(_=>_.status==="already_set").length,$;p===k.length?$=`All ${p} records already set`:p>0?$=`${g} created, ${p} already set`:$=`${g} DNS records set`,c(),console.log(` ${b.success} ${D.default.green(`Email configured - ${$}`)}`)}else{let m=x(!0);m.start("Setting DNS records");let d=await S(`/api/domains/${encodeURIComponent(e)}/connect`,{method:"POST",body:JSON.stringify({target:t})}),u=await d.json();d.ok||(m.stop("Failed"),f(u.error||u.message,{hint:u.hint,status:d.status,json:i,fields:s})),m.stop(`${b.success} Email configured via ${D.default.cyan(l)}`)}c(),E("Verify propagation:",`domani email ${e} --check`),c()}function un(e){let t=Ze();t||(c(),f("Not logged in",{hint:"Run 'domani login' first",code:"auth_required",json:e.json})),e.json?w({token:t}):console.log(t)}var ue=P(U(),1);async function dn(e,t){switch(e){case void 0:case"list":return ko(t.json,t.fields);case"create":return jo(t);case"revoke":return Co(t);default:f(`Unknown action: ${e}`,{hint:"Actions: list, create, revoke",code:"validation_error",json:t.json,fields:t.fields})}}async function ko(e,t){let i=x(!e);i.start("Loading tokens");let s=await S("/api/tokens"),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e,fields:t})),i.stop(`${b.success} ${n.tokens.length} token(s)`),e){w(n,t);return}if(n.tokens.length===0){c(),console.log(` ${ue.default.dim("No tokens.")}`),c(),E("Create one:",'domani tokens create --name "My App"'),c();return}c(),j("API Tokens");let r=n.tokens.map(o=>{let a;o.expired?a=ue.default.red("Expired"):o.expiresAt?a=ue.default.dim(`Expires ${new Date(o.expiresAt).toLocaleDateString()}`):a=ue.default.dim("No expiration");let l=o.scopes.includes("*")?ue.default.dim("all"):ue.default.dim(o.scopes.join(", "));return[ue.default.dim(o.id),ue.default.bold(o.name),l,a]});ee(["ID","Name","Scopes","Expiration"],r,[28,16,32,20]),c()}async function jo(e){let t={};if(e.name&&(t.name=e.name),e.scopes&&(t.scopes=e.scopes.split(",").map(r=>r.trim())),e.expiresIn){let r=Number(e.expiresIn);(isNaN(r)||r<3600||r>31536e3)&&f("Invalid --expires-in value",{hint:"Must be between 3600 (1 hour) and 31536000 (1 year) seconds",code:"validation_error",json:e.json,fields:e.fields}),t.expires_in=r}let i=x(!e.json);i.start("Creating token");let s=await S("/api/tokens",{method:"POST",body:JSON.stringify(t)}),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${b.success} Token created`),e.json){w(n,e.fields);return}c(),j("Token Created"),h("ID",n.id),h("Name",n.name),h("Scopes",n.scopes?.includes("*")?"All (full access)":n.scopes?.join(", ")||"All"),h("Expires",n.expiresAt?new Date(n.expiresAt).toLocaleString():"Never"),c(),console.log(` ${ue.default.yellow("!")} ${ue.default.bold("Key:")} ${n.key}`),console.log(` ${ue.default.dim("Save this key \u2014 it will not be shown again.")}`),c()}async function Co(e){e.tokenId||f("Token ID required",{hint:`Usage: domani tokens revoke --token-id <id>
89
- Run 'domani tokens list' to see your tokens.`,code:"validation_error",json:e.json,fields:e.fields});let t=x(!e.json);t.start("Revoking token");let i=await S(`/api/tokens/${encodeURIComponent(e.tokenId)}`,{method:"DELETE"}),s=await i.json();if(i.ok||(t.stop("Failed"),f(s.error||s.message,{hint:s.hint,status:i.status,json:e.json,fields:e.fields})),t.stop(`${b.success} Token revoked`),e.json){w(s,e.fields);return}console.log(` ${ue.default.dim("Any applications using this key will need a new one.")}`),c()}var ne=P(U(),1);async function mn(e,t){e||(e=await z()),q(e,t);let i=t.autoRenew!==void 0,s=t.whoisPrivacy!==void 0,n=t.securityLock!==void 0;if(!i&&!s&&!n)return Oo(e,t.json,t.fields);let r={};if(i){let m=Di(t.autoRenew);m===null&&f("--auto-renew must be on or off",{code:"validation_error",json:t.json,fields:t.fields}),r.auto_renew=m}if(s){let m=Di(t.whoisPrivacy);m===null&&f("--whois-privacy must be on or off",{code:"validation_error",json:t.json,fields:t.fields}),r.whois_privacy=m}if(n){let m=Di(t.securityLock);m===null&&f("--security-lock must be on or off",{code:"validation_error",json:t.json,fields:t.fields}),r.security_lock=m}if(t.dryRun)return V("settings_update",{domain:e,...r},t.json,t.fields);let o=x(!t.json);o.start(`Updating ${v.domain(e)}`);let a=await S(`/api/domains/${encodeURIComponent(e)}/settings`,{method:"PUT",body:JSON.stringify(r)}),l=await a.json();if(a.ok||(o.stop("Failed"),f(l.error||l.message,{hint:l.hint,status:a.status,json:t.json,fields:t.fields})),o.stop(`${b.success} Settings updated`),t.json){w(l,t.fields);return}j("Settings Updated"),h("Domain",v.domain(l.domain)),l.auto_renew!==void 0&&h("Auto-renew",l.auto_renew?ne.default.green("on"):ne.default.dim("off")),l.whois_privacy!==void 0&&h("WHOIS privacy",l.whois_privacy?ne.default.green("on"):ne.default.dim("off")),l.security_lock!==void 0&&h("Security lock",l.security_lock?ne.default.green("locked"):ne.default.dim("unlocked")),l.hint&&h("",ne.default.dim(l.hint)),c()}async function Oo(e,t,i){let s=x(!t);s.start(`Loading ${v.domain(e)}`);let n=await S(`/api/domains/${encodeURIComponent(e)}`),r=await n.json();if(n.ok||(s.stop("Failed"),f(r.error||r.message,{hint:r.hint,status:n.status,json:t,fields:i})),s.stop(`${b.success} ${v.domain(e)}`),t){w(r,i);return}j("Domain Settings"),h("Domain",v.domain(r.domain)),h("Status",r.status==="active"?ne.default.green(r.status):ne.default.yellow(r.status)),h("Auto-renew",r.auto_renew?ne.default.green("on"):ne.default.dim("off")),r.registrar&&(h("WHOIS privacy",r.registrar.whois_privacy?ne.default.green("on"):ne.default.dim("off")),h("Security lock",r.registrar.security_lock?ne.default.green("locked"):ne.default.dim("unlocked"))),h("Expires",new Date(r.expires_at).toLocaleDateString()+ne.default.dim(` (${r.days_until_expiry} days)`)),c(),E("Toggle auto-renew:",`domani settings ${e} --auto-renew off`),E("Toggle WHOIS privacy:",`domani settings ${e} --whois-privacy off`),E("Toggle security lock:",`domani settings ${e} --security-lock off`),E("Get transfer auth code:",`domani auth-code ${e}`),c()}function Di(e){let t=e.toLowerCase();return t==="on"||t==="true"||t==="1"||t==="enable"?!0:t==="off"||t==="false"||t==="0"||t==="disable"?!1:null}var Je=P(U(),1);async function fn(e,t){e||(e=await z()),q(e,t);let i=x(!t.json);i.start(`Getting auth code for ${v.domain(e)}`);let s=await S(`/api/domains/${encodeURIComponent(e)}/auth-code`),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:t.json,fields:t.fields})),i.stop(`${b.success} Auth code retrieved`),t.json){w(n,t.fields);return}if(j("Auth Code"),h("Domain",v.domain(n.domain)),h("Auth code",Je.default.bold(Je.default.green(n.auth_code))),n.was_unlocked&&h("",Je.default.yellow("Domain was automatically unlocked to allow transfer.")),n.hint&&(c(),console.log(` ${Je.default.dim(n.hint)}`)),n.next_steps?.length){c();for(let r of n.next_steps)console.log(` ${Je.default.dim("\u2192")} ${Je.default.dim(r)}`)}c(),E("Check transfer status:",`domani transfer-away ${e}`),E("Re-lock domain:",`domani settings ${e} --security-lock on`),c()}var Ie=P(U(),1);var Ao={none:Ie.default.dim,pending:Ie.default.yellow,approved:Ie.default.yellow,completed:Ie.default.green,rejected:Ie.default.red,expired:Ie.default.red};async function hn(e,t){e||(e=await z()),q(e,t);let i=x(!t.json);i.start(`Checking transfer status for ${v.domain(e)}`);let s=await S(`/api/domains/${encodeURIComponent(e)}/transfer-away`),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:t.json,fields:t.fields})),i.stop(`${b.success} ${v.domain(e)}`),t.json){w(n,t.fields);return}j("Transfer Away Status"),h("Domain",v.domain(n.domain));let r=Ao[n.status]||Ie.default.dim;h("Status",r(n.status)),n.gaining_registrar&&h("New registrar",n.gaining_registrar),n.request_date&&h("Requested",new Date(n.request_date).toLocaleDateString()),n.hint&&(c(),console.log(` ${Ie.default.dim(n.hint)}`)),c(),n.status==="none"&&E("Get auth code to start:",`domani auth-code ${e}`),c()}var Ut=P(U(),1);async function pn(e,t){return e==="set"?Io(t):Ro(t)}async function Ro(e){let t=x(!e.json);t.start("Loading contact info");let i=await S("/api/me/contact"),s=await i.json();if(i.ok||(t.stop("Failed"),f(s.error||s.message,{hint:s.hint,status:i.status,json:e.json,fields:e.fields})),t.stop(`${b.success} Contact info`),e.json){w(s,e.fields);return}if(j("Contact Info"),!s.has_contact){console.log(` ${b.warning} ${Ut.default.yellow("No contact info set.")} Run ${Ut.default.bold("domani contact set")} to add.`),c(),console.log(` ${Ut.default.dim("Contact info is required before purchasing domains.")}`),c();return}let n=s.contact;h("Name",`${n.first_name} ${n.last_name}`),n.org_name&&h("Organization",n.org_name),h("Address",n.address1),n.address2&&h("",n.address2),h("",`${n.city}, ${n.state} ${n.postal_code}`),h("Country",n.country),h("Phone",n.phone),h("Email",n.email),c()}async function Io(e){let t={},i=e.firstName||e.lastName||e.address1;if(!ye&&!i&&f("Missing required flags for contact set",{hint:"Usage: domani contact set --first-name John --last-name Doe --address1 '123 Main St' --city SF --state CA --postal-code 94105 --country US --phone +1.5551234567 --email john@example.com",code:"missing_argument",json:e.json}),i){let a=["firstName","lastName","address1","city","state","postalCode","country","phone","email"],l={firstName:"first_name",lastName:"last_name",orgName:"org_name",address1:"address1",address2:"address2",city:"city",state:"state",postalCode:"postal_code",country:"country",phone:"phone",email:"email"},m=a.filter(d=>!e[d]);m.length>0&&f(`Missing required flags: ${m.map(d=>`--${d.replace(/[A-Z]/g,u=>`-${u.toLowerCase()}`)}`).join(", ")}`,{code:"missing_argument",json:e.json});for(let[d,u]of Object.entries(l)){let y=e[d];y&&(t[u]=y)}}else{let a=await S("/api/me/contact"),m=(a.ok?await a.json():null)?.contact,d=[{key:"first_name",message:"First name",placeholder:"John",required:!0},{key:"last_name",message:"Last name",placeholder:"Doe",required:!0},{key:"org_name",message:"Organization (optional, press Enter to skip)",placeholder:"Acme Inc.",required:!1},{key:"address1",message:"Address line 1",placeholder:"123 Main St",required:!0},{key:"address2",message:"Address line 2 (optional)",placeholder:"Suite 100",required:!1},{key:"city",message:"City",placeholder:"San Francisco",required:!0},{key:"state",message:"State / Province",placeholder:"CA",required:!0},{key:"postal_code",message:"Postal / ZIP code",placeholder:"94105",required:!0},{key:"country",message:"Country code (ISO 3166-1 alpha-2)",placeholder:"US",required:!0},{key:"phone",message:"Phone (+CC.NUMBER)",placeholder:"+1.5551234567",required:!0},{key:"email",message:"Contact email",placeholder:"john@example.com",required:!0}];for(let u of d){let y=m?.[u.key]||"",k=await pe({message:u.message,placeholder:u.placeholder,defaultValue:y,validate:u.required?p=>p?.trim()?void 0:`${u.message} is required`:void 0});Q(k)&&process.exit(0);let g=k.trim();g&&(t[u.key]=g)}}if(e.dryRun)return V("contact_set",t,e.json,e.fields);let s=x(!e.json);s.start("Saving contact info");let n=await S("/api/me/contact",{method:"PUT",body:JSON.stringify(t)}),r=await n.json();if(n.ok||(s.stop("Failed"),f(r.error||r.message,{hint:r.hint,status:n.status,json:e.json,fields:e.fields})),s.stop(`${b.success} Contact info saved`),e.json){w(r,e.fields);return}j("Contact Saved");let o=r.contact;h("Name",`${o.first_name} ${o.last_name}`),o.org_name&&h("Organization",o.org_name),h("Address",o.address1),o.address2&&h("",o.address2),h("",`${o.city}, ${o.state} ${o.postal_code}`),h("Country",o.country),h("Phone",o.phone),h("Email",o.email),c()}var ae=P(U(),1);async function yn(e,t,i,s){if(e||(e=await z()),q(e,s),!t)return Eo(e,s.json,s.fields);switch(t){case"enable":case"on":return s.dryRun?V("parking_enable",{domain:e},s.json,s.fields):gn(e,!0,s.json,s.fields);case"disable":case"off":return s.dryRun?V("parking_disable",{domain:e},s.json,s.fields):gn(e,!1,s.json,s.fields);case"price":{i||f("Price required",{hint:"Usage: domani parking <domain> price <amount>",code:"validation_error",json:s.json,fields:s.fields});let n=parseFloat(i);return(isNaN(n)||n<=0)&&f("Price must be a positive number",{hint:`Got: "${i}"`,code:"validation_error",json:s.json,fields:s.fields}),s.dryRun?V("parking_price",{domain:e,price:n},s.json,s.fields):$n(e,n,s.json,s.fields)}case"unprice":case"unlist":return s.dryRun?V("parking_unlist",{domain:e},s.json,s.fields):$n(e,null,s.json,s.fields);default:f(`Unknown action: ${t}`,{hint:"Actions: enable, disable, price <amount>, unprice",code:"validation_error",json:s.json,fields:s.fields})}}async function Eo(e,t,i){let s=x(!t);s.start(`Loading ${v.domain(e)}`);let n=await S(`/api/domains/${encodeURIComponent(e)}`),r=await n.json();if(n.ok||(s.stop("Failed"),f(r.error||r.message,{hint:r.hint,status:n.status,json:t,fields:i})),s.stop(`${b.success} ${v.domain(e)}`),t){w({domain:r.domain,parking_enabled:r.parking_enabled,listing_price:r.listing_price},i);return}j("Parking"),h("Domain",v.domain(r.domain)),h("Parking",r.parking_enabled?ae.default.green("enabled"):ae.default.dim("disabled")),h("Listing",r.listing_price?`${v.price(r.listing_price)} ${ae.default.dim("(for sale)")}`:ae.default.dim("not listed")),c(),E("Enable parking:",`domani parking ${e} enable`),E("Set sale price:",`domani parking ${e} price 499`),E("View analytics:",`domani analytics ${e}`),c()}async function gn(e,t,i,s){let n=x(!i);n.start(`${t?"Enabling":"Disabling"} parking for ${v.domain(e)}`);let r=await S(`/api/domains/${encodeURIComponent(e)}/parking`,{method:"PUT",body:JSON.stringify({enabled:t})}),o=await r.json();if(r.status===409&&o.requires_confirmation){if(n.stop(`${b.warning} DNS records will be replaced`),i){w(o,s);return}console.log(`
90
- ${ae.default.yellow("Enabling parking will replace these DNS records:")}`);for(let a of o.existing_dns||[])console.log(` ${ae.default.dim(a.type)} ${a.name} ${ae.default.dim("\u2192")} ${a.value}`);console.log(`
91
- ${ae.default.dim("Run again with --confirm to proceed (not implemented yet).")}`),console.log(` ${ae.default.dim("Or use the dashboard to confirm.")}`),c();return}if(r.ok||(n.stop("Failed"),f(o.error||o.message,{hint:o.hint,status:r.status,json:i,fields:s})),n.stop(`${b.success} Parking ${t?"enabled":"disabled"}`),i){w(o,s);return}j("Parking Updated"),h("Domain",v.domain(o.domain)),h("Parking",o.parking_enabled?ae.default.green("enabled"):ae.default.dim("disabled")),o.hint&&h("",ae.default.dim(o.hint)),c()}async function $n(e,t,i,s){let n=x(!i);n.start(t!==null?`Setting price for ${v.domain(e)} to ${v.price(t)}`:`Removing listing for ${v.domain(e)}`);let r=await S(`/api/domains/${encodeURIComponent(e)}/parking`,{method:"PUT",body:JSON.stringify({listing_price:t})}),o=await r.json();if(r.ok||(n.stop("Failed"),f(o.error||o.message,{hint:o.hint,status:r.status,json:i,fields:s})),n.stop(`${b.success} ${t!==null?"Price set":"Listing removed"}`),i){w(o,s);return}j("Listing Updated"),h("Domain",v.domain(o.domain)),h("Listing",o.listing_price?`${v.price(o.listing_price)} ${ae.default.dim("(for sale)")}`:ae.default.dim("not listed")),o.hint&&h("",ae.default.dim(o.hint)),c()}var de=P(U(),1);var To=" \u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function Po(e){let t=Math.max(...e,1);return e.map(i=>To[Math.min(Math.round(i/t*8),8)]).join("")}async function bn(e,t){e||(e=await z()),q(e,t);let i=x(!t.json);i.start(`Loading analytics for ${v.domain(e)}`);let s=await S(`/api/domains/${encodeURIComponent(e)}/analytics`),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:t.json,fields:t.fields})),i.stop("Analytics loaded"),t.json){w(n,t.fields);return}if(c(),j(`Analytics: ${v.domain(e)}`),h("Views (7d)",de.default.cyan(n.views_7d.toLocaleString())),h("Views (30d)",de.default.cyan(n.views_30d.toLocaleString())),h("Inquiries",de.default.cyan(String(n.inquiries_30d))),h("Conversion",n.conversion_rate>0?de.default.green(`${n.conversion_rate}%`):de.default.dim("0%")),n.daily_views&&n.daily_views.length>0){let r=n.daily_views.map(m=>m.views),o=Po(r),a=n.daily_views[0].date.slice(5),l=n.daily_views[n.daily_views.length-1].date.slice(5);c(),console.log(` ${de.default.dim(a)} ${de.default.cyan(o)} ${de.default.dim(l)}`)}if(n.recent_inquiries&&n.recent_inquiries.length>0){c(),console.log(` ${de.default.bold("Recent Inquiries")}`);let r=n.recent_inquiries.map(o=>[de.default.dim(o.email),o.offer?v.price(o.offer):de.default.dim("-"),de.default.dim(new Date(o.date).toLocaleDateString())]);ee(["Email","Offer","Date"],r,[30,12,14])}c()}var Z=P(U(),1);async function vn(e,t){switch(e){case void 0:case"list":return Do(t.json,t.fields);case"create":return No(t);case"update":return Fo(t);case"delete":return Vo(t);case"deliveries":return Mo(t);case"events":return Uo(t.json,t.fields);default:f(`Unknown action: ${e}`,{hint:"Actions: list, create, update, delete, deliveries, events",code:"validation_error",json:t.json,fields:t.fields})}}async function Do(e,t){let i=x(!e);i.start("Loading webhooks");let s=await S("/api/webhooks"),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e,fields:t})),i.stop(`${b.success} ${n.webhooks.length} webhook(s)`),e){w(n,t);return}if(n.webhooks.length===0){c(),console.log(` ${Z.default.dim("No webhooks configured.")}`),c(),E("Create one:","domani webhooks create --url https://... --events domain.purchased,dns.updated"),E("List events:","domani webhooks events"),c();return}c(),j("Webhooks");let r=n.webhooks.map(o=>[Z.default.dim(o.id),v.url(o.url),o.events.length<=3?o.events.join(", "):`${o.events.length} events`,o.active?Z.default.green("active"):Z.default.dim("paused")]);ee(["ID","URL","Events","Status"],r,[28,40,24,10]),c()}async function No(e){e.url||f("URL required",{hint:"Usage: domani webhooks create --url https://example.com/hook --events domain.purchased,dns.updated",code:"validation_error",json:e.json,fields:e.fields}),e.events||f("Events required",{hint:`Usage: domani webhooks create --url https://... --events domain.purchased,dns.updated
92
- Run 'domani webhooks events' to see available event types.`,code:"validation_error",json:e.json,fields:e.fields});let t=e.events.split(",").map(r=>r.trim());if(e.dryRun)return V("webhook_create",{url:e.url,events:t},e.json,e.fields);let i=x(!e.json);i.start("Creating webhook");let s=await S("/api/webhooks",{method:"POST",body:JSON.stringify({url:e.url,events:t})}),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${b.success} Webhook created`),e.json){w(n,e.fields);return}c(),j("Webhook Created"),h("ID",n.id),h("URL",v.url(n.url)),h("Events",n.events.join(", ")),h("Status",Z.default.green("active")),c(),console.log(` ${Z.default.yellow("!")} ${Z.default.bold("Secret:")} ${n.secret}`),console.log(` ${Z.default.dim("Save this secret - it won't be shown again.")}`),console.log(` ${Z.default.dim("Use it to verify payloads with HMAC-SHA256.")}`),c()}async function Fo(e){e.webhookId||f("Webhook ID required",{hint:"Usage: domani webhooks update --webhook-id <id> [--url ...] [--events ...] [--active on|off]",code:"validation_error",json:e.json,fields:e.fields});let t={};if(e.url&&(t.url=e.url),e.events&&(t.events=e.events.split(",").map(r=>r.trim())),e.active!==void 0&&(t.active=e.active==="on"||e.active==="true"),e.dryRun)return V("webhook_update",{webhook_id:e.webhookId,...t},e.json,e.fields);let i=x(!e.json);i.start("Updating webhook");let s=await S(`/api/webhooks/${encodeURIComponent(e.webhookId)}`,{method:"PATCH",body:JSON.stringify(t)}),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${b.success} Webhook updated`),e.json){w(n,e.fields);return}j("Webhook Updated"),h("ID",n.id),h("URL",v.url(n.url)),h("Events",n.events.join(", ")),h("Status",n.active?Z.default.green("active"):Z.default.dim("paused")),c()}async function Vo(e){if(e.webhookId||f("Webhook ID required",{hint:"Usage: domani webhooks delete --webhook-id <id>",code:"validation_error",json:e.json,fields:e.fields}),e.dryRun)return V("webhook_delete",{webhook_id:e.webhookId},e.json,e.fields);let t=x(!e.json);t.start("Deleting webhook");let i=await S(`/api/webhooks/${encodeURIComponent(e.webhookId)}`,{method:"DELETE"}),s=await i.json();if(i.ok||(t.stop("Failed"),f(s.error||s.message,{hint:s.hint,status:i.status,json:e.json,fields:e.fields})),t.stop(`${b.success} Webhook deleted`),e.json){w(s,e.fields);return}console.log(` ${Z.default.dim("Pending deliveries have been cancelled.")}`),c()}async function Mo(e){e.webhookId||f("Webhook ID required",{hint:"Usage: domani webhooks deliveries --webhook-id <id> [--limit 20]",code:"validation_error",json:e.json,fields:e.fields});let t=e.limit?`?limit=${e.limit}`:"",i=x(!e.json);i.start("Loading deliveries");let s=await S(`/api/webhooks/${encodeURIComponent(e.webhookId)}/deliveries${t}`),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${b.success} ${n.deliveries.length} delivery(ies)`),e.json){w(n,e.fields);return}if(n.deliveries.length===0){c(),console.log(` ${Z.default.dim("No deliveries yet.")}`),c();return}c(),j("Deliveries");let r=n.deliveries.map(o=>{let a=o.status==="delivered"?Z.default.green("delivered"):o.status==="failed"?Z.default.red("failed"):Z.default.yellow("pending");return[o.event_type,a,o.http_status?String(o.http_status):Z.default.dim("-"),String(o.attempts),Z.default.dim(new Date(o.created_at).toLocaleString())]});ee(["Event","Status","HTTP","Tries","Date"],r,[22,12,6,6,22]),c()}async function Uo(e,t){let i=x(!e);i.start("Loading event types");let s=await oe("/api/webhooks/events"),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:e,fields:t})),i.stop(`${b.success} ${n.events.length} event type(s)`),e){w(n,t);return}c(),j("Webhook Event Types");let r=n.events.map(o=>[Z.default.cyan(o.type),Z.default.dim(o.description)]);ee(["Event","Description"],r,[24,50]),c()}var Ne=P(U(),1);async function wn(e){let t=e.limit?Number(e.limit):20,i=await S(`/api/billing/invoices?limit=${t}`),s=await i.json();if(i.ok||f(s.error||s.message,{hint:s.hint,status:i.status,json:e.json,fields:e.fields}),e.json){w({...s,count:s.invoices.length},e.fields);return}if(s.invoices.length===0){console.log(` ${Ne.default.dim("No invoices yet.")}`);return}j(`Invoices (${s.invoices.length})`),c();for(let n of s.invoices){let r=`$${(n.amount_paid/100).toFixed(2)}`,o=new Date(n.created).toLocaleDateString(),a=n.number||n.id;console.log(` ${b.success} ${Ne.default.bold(a)} ${Ne.default.green(r)} ${Ne.default.dim(o)}`),n.description&&console.log(` ${Ne.default.dim(n.description)}`),n.hosted_invoice_url&&console.log(` ${Ne.default.dim(n.hosted_invoice_url)}`)}c(),s.has_more&&(console.log(` ${Ne.default.dim(`Showing ${s.invoices.length} most recent. Use --limit to see more.`)}`),c())}var rt=P(U(),1);async function _n(e){let t=x(!e?.json);t.start("Setting up billing session");let i=await S("/api/billing/setup",{method:"POST",body:JSON.stringify({mode:"checkout"})}),s=await i.json();if(i.ok||(t.stop("Failed"),f(s.error||s.message,{hint:s.hint,status:i.status,json:e?.json})),s.url||(t.stop("Failed"),f("No checkout URL returned",{hint:"Try again or add a payment method at the dashboard.",json:e?.json})),t.stop("Checkout ready"),e?.json){w({url:s.url});return}c(),console.log(` ${rt.default.dim("Opening browser")} ${b.arrow} ${v.url(s.url)}`),c(),Nt(s.url),console.log(` ${b.info} ${rt.default.dim("Complete payment setup in your browser.")}`),console.log(` ${rt.default.dim(" After setup, you can purchase domains with")} ${rt.default.cyan("domani buy")}`),c()}var ve=P(U(),1);async function xn(e,t,i){e||(e=await z()),q(e,i);let s=[];if(t?.length&&s.push(...t),i.set&&s.push(...i.set.split(",").map(n=>n.trim()).filter(Boolean)),s.length>0||i.reset){await qo(e,s,i);return}await Lo(e,i)}async function Lo(e,t){let i=x(!t.json);i.start(`Fetching nameservers for ${v.domain(e)}`);let s=await S(`/api/domains/${encodeURIComponent(e)}/nameservers`),n=await s.json();if(s.ok||(i.stop("Failed"),f(n.error||n.message,{hint:n.hint,status:s.status,json:t.json,fields:t.fields})),i.stop(`Nameservers for ${v.domain(e)}`),t.json){w(n,t.fields);return}if(c(),n.nameservers.length===0)console.log(` ${b.warning} ${ve.default.yellow("No nameservers configured.")}`),console.log(` ${ve.default.dim("DNS operations (parking, email, connect) will not work.")}`),c(),E("Set default nameservers:",`domani nameservers ${e} --reset`);else{j("Nameservers");for(let r of n.nameservers)console.log(` ${b.success} ${ve.default.cyan(r)}`);n.default_nameservers&&n.nameservers.length===n.default_nameservers.length&&n.nameservers.every(o=>n.default_nameservers.includes(o))&&(c(),console.log(` ${ve.default.dim("Using default nameservers.")}`))}n.default_nameservers?.length&&(c(),h("Defaults",n.default_nameservers.map(r=>ve.default.dim(r)).join(ve.default.dim(", ")))),c()}async function qo(e,t,i){let s=x(!i.json);if(i.reset){s.start(`Fetching default nameservers for ${v.domain(e)}`);let o=await S(`/api/domains/${encodeURIComponent(e)}/nameservers`),a=await o.json();o.ok||(s.stop("Failed"),f(a.error,{hint:a.hint,status:o.status,json:i.json,fields:i.fields})),a.default_nameservers?.length||(s.stop("No defaults"),f("No default nameservers available for this domain's registrar.",{code:"not_found",json:i.json,fields:i.fields})),t=a.default_nameservers,s.stop(`Using defaults: ${t.map(l=>ve.default.cyan(l)).join(ve.default.dim(", "))}`)}if(t.length<2&&f("At least 2 nameservers required.",{hint:"Example: domani nameservers example.com ns1.dns.com ns2.dns.com",code:"validation_error",json:i.json,fields:i.fields}),i.dryRun)return V("nameservers_set",{domain:e,nameservers:t},i.json,i.fields);s.start(`Setting nameservers for ${v.domain(e)}`);let n=await S(`/api/domains/${encodeURIComponent(e)}/nameservers`,{method:"PUT",body:JSON.stringify({nameservers:t})}),r=await n.json();if(n.ok||(s.stop("Failed"),f(r.error||r.message,{hint:r.hint,status:n.status,json:i.json,fields:i.fields})),s.stop(`${b.success} Nameservers updated`),i.json){w(r,i.fields);return}c();for(let o of r.nameservers)console.log(` ${b.success} ${ve.default.cyan(o)}`);c(),console.log(` ${ve.default.dim("Changes may take up to 48 hours to propagate.")}`),c()}var Sn=require("crypto"),Lt=P(require("fs"),1);var ot=P(U(),1);function Wo(e,t){let i=e.split(".").map(Number),s=t.split(".").map(Number);for(let n=0;n<3;n++){if((i[n]||0)>(s[n]||0))return 1;if((i[n]||0)<(s[n]||0))return-1}return 0}async function kn(e){let t=x(!e?.json);t.start("Checking for updates");let i=Te();try{let s=await fetch(`${i}/api/cli/version`);s.ok||(t.stop("Failed"),f("Could not check for updates"));let n=await s.json(),r=n.version,o=n.sha256;if(Wo(r,te)<=0){t.stop(`${b.success} Already up to date (v${te})`),e?.json&&w({current:te,latest:r,up_to_date:!0});return}if(e?.json){t.stop(""),w({current:te,latest:r,up_to_date:!1,hint:"Run `domani update` to upgrade."});return}t.stop(`New version available: ${ot.default.cyan(te)} ${b.arrow} ${ot.default.green(r)}`);let a=x();a.start("Downloading update");let l=`${i}/cli/domani.js`,m=await fetch(l);m.ok||(a.stop("Download failed"),f(`Failed to download from ${l}`));let d=await m.text();o&&(0,Sn.createHash)("sha256").update(d).digest("hex")!==o&&(a.stop("Integrity check failed"),f("Downloaded file does not match expected hash - update aborted"));let u=process.argv[1];u||(a.stop("Failed"),f("Could not determine binary path"));let y=Lt.default.realpathSync(u),k=y+".tmp";Lt.default.writeFileSync(k,d,{mode:493}),Lt.default.renameSync(k,y),a.stop(`${b.success} Updated to v${r}`),c(),console.log(` ${ot.default.dim("Restart your terminal or run")} domani --version ${ot.default.dim("to verify")}`),c()}catch(s){f(`Update failed: ${s instanceof Error?s.message:String(s)}`)}}var qt=P(require("fs"),1),jn=P(require("path"),1),Cn=P(require("os"),1);var at=P(U(),1);async function On(){let e=process.argv[1],t=e?qt.default.realpathSync(e):null,i=jn.default.join(Cn.default.homedir(),".domani");if(c(),console.log(` ${at.default.bold("This will remove:")}`),t&&console.log(` ${b.dot} CLI binary: ${at.default.dim(t)}`),console.log(` ${b.dot} Config dir: ${at.default.dim(i)}`),c(),await je({message:"Uninstall domani?"})!==!0){console.log(` ${at.default.dim("Cancelled.")}`);return}qt.default.rmSync(i,{recursive:!0,force:!0}),t&&qt.default.unlinkSync(t),c(),console.log(` ${b.success} domani uninstalled.`),c()}var H=P(U(),1);async function Rn(e,t){let i=t?.json,s=t?.fields,n=e?`/api/schema?command=${encodeURIComponent(e)}`:"/api/schema",r=x(!i);r.start("Loading schema");let o=await oe(n),a=await o.json();if(o.ok||(r.stop("Failed"),f(a.error||a.message,{hint:a.hint,status:o.status,json:i,fields:s})),r.stop("Schema loaded"),i){w(a,s);return}e?Jo(e,a):Ho(a.commands)}function Ho(e){j("Commands");let t=Object.entries(e).map(([i,s])=>[H.default.bold(H.default.cyan(i)),s.description]);ee(["Command","Description"],t,[20,50]),c(),console.log(` ${H.default.dim("Run")} ${H.default.cyan("domani schema <command>")} ${H.default.dim("for full details")}`),c()}function Jo(e,t){if(j(`domani ${e}`),console.log(` ${t.description}`),c(),console.log(` ${v.label("Usage:")} ${H.default.cyan(t.usage)}`),t.arguments&&Object.keys(t.arguments).length>0){c(),console.log(` ${H.default.bold("Arguments")}`);for(let[i,s]of Object.entries(t.arguments)){let n=s.required?H.default.red("*"):"",r=H.default.dim(`(${s.type}${s.variadic?", variadic":""})`);console.log(` ${H.default.cyan(i)}${n} ${r}`),s.description&&console.log(` ${H.default.dim(s.description)}`)}}if(t.options&&Object.keys(t.options).length>0){c(),console.log(` ${H.default.bold("Options")}`);for(let[i,s]of Object.entries(t.options)){let n=s.required?H.default.red("*"):"",r=H.default.dim(`(${s.type})`),o=s.choices?H.default.dim(` [${s.choices.join(", ")}]`):"";console.log(` ${H.default.cyan(`--${i}`)}${n} ${r}${o}`),console.log(` ${H.default.dim(s.description)}`)}}if(t.api)if(c(),console.log(` ${H.default.bold("API")}`),Go(t.api))An(t.api);else for(let[i,s]of Object.entries(t.api))console.log(` ${H.default.bold(H.default.yellow(i))}`),An(s,6);t.errors&&t.errors.length>0&&(c(),console.log(` ${H.default.bold("Errors")}`),console.log(` ${t.errors.map(i=>H.default.dim(i)).join(H.default.dim(", "))}`)),c()}function Go(e){return typeof e=="object"&&e!==null&&"method"in e&&"path"in e}function An(e,t=4){let i=" ".repeat(t);if(console.log(`${i}${H.default.green(e.method)} ${H.default.white(e.path)}`),e.parameters&&Object.keys(e.parameters).length>0)for(let[s,n]of Object.entries(e.parameters)){let r=n.required?H.default.red("*"):"",o=[n.type];n.enum&&o.push(`enum: ${n.enum.join(", ")}`),n.minimum!==void 0&&o.push(`min: ${n.minimum}`),n.maximum!==void 0&&o.push(`max: ${n.maximum}`),n.maxItems!==void 0&&o.push(`maxItems: ${n.maxItems}`),n.items&&o.push(`items: ${n.items}`),n.in==="path"&&o.push("in: path");let a=H.default.dim(`(${o.join(", ")})`);console.log(`${i} ${H.default.cyan(s)}${r} ${a}`),n.description&&console.log(`${i} ${H.default.dim(n.description)}`)}}var L=new zi;L.name("domani").description(`Domain names for developers and AI agents - ${Be}`).version(te).option("--api-url <url>","Override API base URL").hook("preAction",(e,t)=>{let i=e.opts();i.apiUrl&&is(i.apiUrl),process.stdout.isTTY||t.options.some(n=>n.long==="--json")&&t.setOptionValue("json",!0)});L.command("login").description(`Log in to ${Be} (opens browser)`).option("--json","Output as JSON (returns auth_url for non-interactive approval)").action(Ds);L.command("logout").description("Clear saved credentials").option("--json","Output as JSON").action(Ns);L.command("me").description("Show account info").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Vs);L.command("invoices").description("List payment invoices").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").option("--limit <n>","Max invoices to show (default 20)").action(wn);L.command("billing").description("Add or update payment method (opens browser)").option("--json","Output as JSON (returns checkout URL)").action(_n);L.command("token").description("Print your API key").option("--json","Output as JSON").action(un);L.command("tokens [action]").description("Manage API tokens (list/create/revoke)").option("--name <name>","Token name (for create)").option("--scopes <scopes>","Comma-separated permission scopes (for create)").option("--expires-in <seconds>","Token lifetime in seconds (for create, min 3600)").option("--token-id <id>","Token ID (for revoke)").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(dn);L.command("search [domain] [tlds...]").description("Check availability - domani search myapp .io .fm .xyz").option("--tlds <tlds>","Comma-separated TLDs (e.g. com,io,dev)").option("--max-price <price>","Maximum price filter").option("--all","Show taken domains too").option("--expand","Check 30+ TLDs including creative/exotic extensions").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Hs);L.command("tlds").description("List all TLDs with pricing").option("--max-price <price>","Maximum registration price").option("--min-price <price>","Minimum registration price").option("--sort <field>","Sort by: price, tld, renewal (default: tld)").option("--search <term>","Filter TLDs by name").option("--limit <n>","Limit results").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Ks);L.command("whois <domain>").description("WHOIS/RDAP lookup for any domain").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Ys);L.command("suggest [prompt]").description("AI-powered domain name suggestions").option("--count <n>","Number of suggestions (1-20, default 10)").option("--tlds <tlds>","Preferred TLDs, comma-separated (e.g. com,dev,ai)").option("--style <style>","Name style: single, creative, short, brandable, keyword").option("--lang <lang>","Language inspiration: japanese, spanish, french, italian, latin, nordic, arabic, sanskrit").option("--timeout <seconds>","Request timeout in seconds (default: 60)").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(zs);L.command("buy [domains...]").description("Purchase one or more domains").option("--yes","Skip confirmation prompt").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Js);L.command("transfer <domain>").description("Transfer a domain from another registrar").option("--auth-code <code>","EPP/auth code from current registrar").option("--yes","Skip confirmation prompt").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(en);L.command("renew [domain]").description("Renew a domain").option("--years <n>","Number of years (1-10, default: 1)").option("--yes","Skip confirmation prompt").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(tn);L.command("import <domain>").description("Import a domain you own at another registrar").option("--verify","Verify DNS ownership and complete import").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(sn);L.command("list").description("List your domains").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Gs);L.command("status [domain]").description("Check domain health (DNS, SSL, email, expiry)").option("--timeout <seconds>","Request timeout in seconds (default: 30)").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Qs);L.command("connect [domain] [target]").description("Connect domain to a hosting/email provider").option("--provider <name>","Provider name (e.g. vercel, google-workspace)").option("--method <name>","Connection method (e.g. cname-only)").option("--list","List available providers").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Zs);L.command("email [action] [arg2]").description("Manage email: list, inbox, create, delete, send, forward, webhook, setup, status, check, connect").option("--domain <domain>","Domain name").option("--slug <slug>","Mailbox slug (local part before @)").option("--from <email>","Sender address user@domain (alternative to --domain + --slug)").option("--to <email>","Recipient email address (for send)").option("--cc <emails>","CC recipients, comma-separated (for send)").option("--bcc <emails>","BCC recipients, comma-separated (for send)").option("--subject <s>","Email subject (for send)").option("--text <t>","Email body text (for send)").option("--body <t>","Email body text (alias for --text)").option("--in-reply-to <message-id>","Message-ID of email being replied to (for threading)").option("--references <message-ids>","Space-separated Message-ID chain (for threading)").option("--url <url>","Webhook URL (for webhook)").option("--forward-to <email>","Email address to forward inbound emails to (for forward)").option("--direction <dir>","Filter messages: in or out").option("--limit <n>","Limit results").option("--check","Verify email DNS health (MX, SPF, DKIM, DMARC)").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(an);L.command("dns [domain] [action] [type] [name] [value]").description("Manage DNS records (get/set/delete/snapshot/restore)").option("--type <type>","Record type: A, AAAA, CNAME, MX, TXT, NS, SRV").option("--name <name>","Record name (e.g. www, @, _dmarc)").option("--value <value>","Record value").option("--file <path>","Snapshot file path (for restore)").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Bs);L.command("nameservers [domain] [ns...]").description("Get or set nameservers (--reset for defaults)").option("--set <ns>","Comma-separated nameservers to set").option("--reset","Reset to registrar default nameservers").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(xn);L.command("settings [domain]").description("View or update domain settings (auto-renew, WHOIS privacy, security lock)").option("--auto-renew <on|off>","Enable or disable auto-renew").option("--whois-privacy <on|off>","Enable or disable WHOIS privacy").option("--security-lock <on|off>","Lock or unlock domain transfers").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(mn);L.command("auth-code [domain]").description("Get EPP auth code to transfer domain to another registrar").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(fn);L.command("transfer-away [domain]").description("Check status of an outbound domain transfer").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(hn);L.command("contact [action]").description("View or set WHOIS contact info (required for purchases)").option("--first-name <name>","First name (for set)").option("--last-name <name>","Last name (for set)").option("--org-name <name>","Organization name (for set, optional)").option("--address1 <addr>","Address line 1 (for set)").option("--address2 <addr>","Address line 2 (for set, optional)").option("--city <city>","City (for set)").option("--state <state>","State/Province (for set)").option("--postal-code <code>","Postal/ZIP code (for set)").option("--country <code>","Country code ISO 3166-1 alpha-2 (for set)").option("--phone <phone>","Phone +CC.NUMBER (for set)").option("--email <email>","Contact email (for set)").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(pn);L.command("parking [domain] [action] [value]").description("Manage parking page (enable/disable/price)").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(yn);L.command("analytics [domain]").description("View parking analytics (views, inquiries, conversion)").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(bn);L.command("webhooks [action]").alias("webhook").description("Manage webhook endpoints (list/create/update/delete/deliveries/events)").option("--url <url>","Webhook HTTPS URL").option("--events <events>","Comma-separated event types").option("--webhook-id <id>","Webhook ID (for update/delete/deliveries)").option("--active <on|off>","Enable or disable webhook").option("--limit <n>","Limit deliveries returned").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(vn);L.command("schema [command]").description("Show command schemas for AI agent integration").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Rn);L.command("update").description("Update domani CLI to the latest version").option("--json","Output as JSON (check version without updating)").action(kn);L.command("uninstall").description("Remove domani CLI and config from this machine").action(On);(async()=>{let e=as();await L.parseAsync();let t=await e;t?.forced?(console.error(`
93
- ${Fe.default.red("!")} CLI v${te} is no longer supported. Run ${Fe.default.bold("domani update")} to upgrade to v${t.update}
176
+ `}}}}).prompt()});function Ea(e){return!!(e.json||!ke)}function E(e,t=50){console.log(),console.log(` ${U.default.bold(e)}`),console.log(` ${U.default.dim("\u2500".repeat(t))}`)}function b(e,t,i=2){let s=" ".repeat(i);console.log(`${s}${U.default.dim(e.padEnd(16))} ${t}`)}function h(){console.log()}function Lt(e){console.log(` ${U.default.dim(e)}`)}function I(e,t){console.log(` ${U.default.dim(e)} ${U.default.cyan(t)}`)}function ir(e){return e.split(/(https?:\/\/[^\s]+)/g).map(i=>/^https?:\/\//.test(i)?`\x1B]8;;${i}\x1B\\${U.default.underline(U.default.cyan(i))}\x1B]8;;\x1B\\`:U.default.dim(i)).join("")}function Ds(e,t){console.error(` ${_.error} ${U.default.red(e)}`),t&&console.error(` ${ir(t)}`)}function j(e=!0){return e?Ut():Pa}function sr(e){return e.replace(Ta,"")}function ki(e,t){let i=sr(e).length,s=Math.max(0,t-i);return e+" ".repeat(s)}function ge(e,t,i){let s=i||e.map((o,a)=>{let l=t.reduce((c,u)=>Math.max(c,sr(u[a]||"").length),0);return Math.max(o.length,l)+2}),n=e.map((o,a)=>U.default.dim(o.padEnd(s[a]))).join(" "),r=s.map(o=>U.default.dim("\u2500".repeat(o))).join(" ");console.log(` ${n}`),console.log(` ${r}`);for(let o of t){let a=o.map((l,c)=>ki(l,s[c])).join(" ");console.log(` ${a}`)}}function Da(e){return e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}function Ts(e){if(Array.isArray(e))return e.map(Ts);if(e&&typeof e=="object"&&!(e instanceof Date)){let t={};for(let[i,s]of Object.entries(e))t[Da(i)]=Ts(s);return t}return e}function k(e,t){let i=Ts(e);if(!t){console.log(JSON.stringify(i,null,2));return}let s=t.split(",").map(n=>n.trim()).filter(Boolean);if(Array.isArray(i)){let n=i.map(r=>Qn(r,s));console.log(JSON.stringify(n,null,2))}else console.log(JSON.stringify(i&&typeof i=="object"?Qn(i,s):i,null,2))}function Qn(e,t){let i={};for(let s of t)s in e&&(i[s]=e[s]);if(Object.keys(i).length===0){for(let[s,n]of Object.entries(e))if(Array.isArray(n)&&n.length>0&&typeof n[0]=="object"){let r=n.map(o=>{let a={};for(let l of t)l in o&&(a[l]=o[l]);return a});Object.keys(r[0]).length>0&&(i[s]=r)}}return i}function bt(e){return!!(e.yes||Ea(e))}function G(e,t,i,s){if(i){k({dry_run:!0,action:e,...t},s);return}console.log(),console.log(` ${U.default.yellow("\u25B8 DRY RUN")} ${U.default.dim("- no changes made")}`),console.log(` ${U.default.dim("Action:")} ${U.default.bold(e)}`);for(let[n,r]of Object.entries(t))r!=null&&(Array.isArray(r)?console.log(` ${U.default.dim(n+":")} ${r.map(String).join(", ")}`):console.log(typeof r=="object"?` ${U.default.dim(n+":")} ${JSON.stringify(r)}`:` ${U.default.dim(n+":")} ${String(r)}`));console.log()}function Fa(e,t,i){return t===401||t===403?"auth_required":t===402||i?"payment_required":t===404?"not_found":t===409?"conflict":t===422?"validation_error":t===429?"rate_limited":/contact/i.test(e)?"contact_required":"error"}function g(e,t){let i=e||`Request failed${t?.status?` (${t.status})`:""}`,s=t?.code||Fa(i,t?.status,t?.fixUrl),n=t?.fixCommand||Na[s];if(t?.json){let r={error:i,code:s};t.hint&&(r.hint=t.hint),n&&(r.fix_command=n),t.fixUrl&&(r.fix_url=t.fixUrl),k(r,t.fields)}else Ds(i,t?.hint),n?console.error(` ${U.default.dim("Or run:")} ${U.default.cyan(n)}`):t?.fixUrl&&console.error(` ${ir(`Add a payment method at ${t.fixUrl}`)}`);process.exit(1)}function Rt(e){let t=process.platform==="darwin"?"open":process.platform==="win32"?"start":"xdg-open";(0,tr.execFile)(t,[e])}function qt(e){return new Promise(t=>setTimeout(t,e))}function It(e,t,i,s=!0){let n=process.stdout.isTTY??!1;if(!s)return{start(){},markDone(){},stop(){}};let r=0,o=null,a=2+t.length;function l(){let p=" "+e.map((m,y)=>U.default.dim(m.padEnd(i[y]))).join(" "),v=" "+i.map(m=>U.default.dim("\u2500".repeat(m))).join(" "),$=[p,v];for(let m of t){let y=m.status==="done"?m.icon??_.success:U.default.cyan(er[r%er.length]),w=m.cells.map((S,A)=>ki(S,i[A])).join(" ");$.push(` ${y} ${w}`)}return $}let c=!1,u=()=>process.stdout.write("\x1B[?25h");function f(){let p=l();if(c&&n){process.stdout.write(`\x1B[${a}A`);for(let v of p)process.stdout.write(`\x1B[2K${v}
177
+ `)}else{for(let v of p)console.log(v);c=!0}}return{start(){n&&(process.stdout.write("\x1B[?25l"),process.on("exit",u)),f(),n&&(o=setInterval(()=>{r++,f()},80))},markDone(p,v){t[p].status="done",v!==void 0&&(t[p].icon=v),n&&f()},stop(){o&&clearInterval(o);for(let p of t)p.status="done";f(),n&&(process.stdout.write("\x1B[?25h"),process.removeListener("exit",u))}}}var U,tr,ke,_,x,Pa,Ta,Na,er,X=Ee(()=>{"use strict";U=M(Z(),1),tr=require("child_process");Oe();ke=process.stdout.isTTY??!1;_={success:U.default.green("\u2713"),error:U.default.red("\u2717"),warning:U.default.yellow("!"),info:U.default.cyan("\u25CF"),arrow:U.default.dim("\u2192"),dot:U.default.dim("\xB7"),dash:U.default.dim("\u2500")},x={domain:e=>U.default.bold(U.default.white(e)),price:e=>U.default.green(`$${e}`),label:e=>U.default.dim(e),value:e=>U.default.white(e),dim:e=>U.default.dim(e),bold:e=>U.default.bold(e),success:e=>U.default.green(e),error:e=>U.default.red(e),warn:e=>U.default.yellow(e),cyan:e=>U.default.cyan(e),url:e=>`\x1B]8;;${e}\x1B\\${U.default.underline(U.default.cyan(e))}\x1B]8;;\x1B\\`};Pa={start:()=>{},stop:()=>{},message:()=>{}};Ta=/\x1b\]8;;[^\x1b]*\x1b\\|\x1b\[[0-9;]*m/g;Na={auth_required:"domani login",payment_required:"domani card add",contact_required:"domani contact set"};er=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]});function or(e){return e.json=async()=>{let t=await e.clone().text();try{return JSON.parse(t)}catch{return{error:`Server error (${e.status})`,hint:"The server returned an unexpected response. Try again later."}}},e}async function C(e,t={}){let i=bn(),s=`${ot()}${e}`,n=await fetch(s,{...t,headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json","User-Agent":`domani-cli/${be}`,...t.headers}});return or(n)}async function he(e,t={}){let i=`${ot()}${e}`,s=Tt(),n=await fetch(i,{...t,headers:{"Content-Type":"application/json","User-Agent":`domani-cli/${be}`,...s?{Authorization:`Bearer ${s}`}:{},...t.headers}});return or(n)}var ne=Ee(()=>{"use strict";ut()});function lt(){return{ok:!0}}function et(e,t,i){return{ok:!1,error:{message:e,code:t,hint:i}}}function cr(e){return Va.test(e)?et("Input contains control characters","invalid_input","Remove non-printable characters from the input"):lt()}function Ha(e){return Ma.test(e)?et("Input contains path traversal","invalid_input","Domain names cannot contain '../' or '..\\'"):lt()}function Ja(e){return Ua.test(e)?et("Input contains query string or fragment","invalid_input","Remove '?' or '#' from the domain name"):lt()}function Ba(e){return La.test(e)?et("Input contains percent-encoded characters","invalid_input","Use plain text, not URL-encoded values (e.g. 'example.com' not 'example%2Ecom')"):lt()}function dr(e){if(!e)return et("Domain name is required","validation_error");if(e.length>lr)return et(`Domain name too long (${e.length} chars, max ${lr})`,"validation_error");for(let t of[cr,Ha,Ja,Ba]){let i=t(e);if(!i.ok)return i}return qa.test(e)?lt():et(`Invalid domain name: ${e}`,"validation_error","Domain names can only contain letters, digits, hyphens, and dots")}function Ga(e){if(!e)return et("TLD is required","validation_error");let t=cr(e);return t.ok?Wa.test(e)?lt():et(`Invalid TLD: ${e}`,"validation_error","TLDs contain only letters (e.g. 'com', '.dev', 'ai')"):t}function za(e){for(let t of e){let i=dr(t);if(!i.ok)return i}return lt()}function Ka(e){for(let t of e){let i=Ga(t);if(!i.ok)return i}return lt()}function Q(e,t){let i=dr(e);i.ok||g(i.error.message,{code:i.error.code,hint:i.error.hint,json:t?.json,fields:t?.fields})}function ur(e,t){let i=za(e);i.ok||g(i.error.message,{code:i.error.code,hint:i.error.hint,json:t?.json,fields:t?.fields})}function Si(e,t){let i=Ka(e);i.ok||g(i.error.message,{code:i.error.code,hint:i.error.hint,json:t?.json,fields:t?.fields})}var Va,Ma,Ua,La,qa,Wa,lr,ye=Ee(()=>{"use strict";X();Va=/[\x00-\x08\x0b\x0c\x0e-\x1f]/,Ma=/\.\.[/\\]/,Ua=/[?#]/,La=/%[0-9a-fA-F]{2}/,qa=/^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.?$/,Wa=/^\.?[a-zA-Z]{2,63}$/,lr=253});async function de(){ke||g("Missing required argument: domain",{hint:"Pass the domain as an argument, e.g. 'domani settings example.com'",code:"missing_argument",json:!0});let e=j(!0);e.start("Loading your domains");let t=await C("/api/domains"),i=await t.json();t.ok||(e.stop("Failed"),Ds(i.error,i.hint),process.exit(1));let s=i.domains||[];s.length===0&&(e.stop("No domains"),h(),console.log(` ${Fs.default.dim("No domains yet.")} Use: ${Fs.default.cyan("domani buy <domain>")}`),h(),process.exit(0)),e.stop(`${s.length} domain(s)`);let n=await We({message:"Which domain?",options:s.map(r=>({value:r.domain,label:r.domain,hint:r.status!=="active"?r.status:void 0}))});return oe(n)&&process.exit(0),n}var Fs,Le=Ee(()=>{"use strict";ne();Oe();Fs=M(Z(),1);X()});var fr={};xt(fr,{connect:()=>Vs});async function Vs(e,t,i){e||(e=await de()),Q(e,i);let s;if(t&&!i.provider?t.includes(".")?s=t:i.provider=t:s=t,!s&&!i.provider&&!i.list&&i.dryRun)return G("connect",{domain:e,note:"No provider specified. Pass --provider <name> to connect."},i.json,i.fields);if(!s&&!i.provider&&!i.list){let n=j(!i.json);n.start(`Loading providers for ${x.domain(e)}`);let r=await C(`/api/domains/${encodeURIComponent(e)}/connect`),o=await r.json();if(r.ok||(n.stop("Failed"),g(o.error||o.message,{hint:o.hint,status:r.status,json:i.json,fields:i.fields})),n.stop("Providers loaded"),i.json){k(o,i.fields);return}let a=[];for(let m of["hosting","email"]){let y=o.providers?.[m]||[];for(let w of y)a.push({value:`${m}:${w.name}`,label:w.name,hint:m})}a.length===0&&g("No providers available",{code:"not_found",json:i.json,fields:i.fields});let l=await We({message:"Choose a provider",options:a});oe(l)&&process.exit(0);let[c,u]=l.split(":"),p=(o.providers?.[c]||[]).find(m=>m.name===u),v;if(p&&p.methods.length>1){let m=await We({message:"Choose a method",options:p.methods.map(y=>({value:y.name,label:y.name,hint:y.default?"default":void 0}))});oe(m)&&process.exit(0),v=m}let $;if(c==="hosting"&&p?.requires_target){p.notes?.setup&&Lt(p.notes.setup);let m=await Re({message:"Target hostname or IP"});oe(m)&&process.exit(0),$=m.trim()}return mr(e,{target:$,provider:u,method:v,dryRun:i.dryRun,json:!1})}if(i.list){let n=j(!i.json);n.start(`Loading providers for ${x.domain(e)}`);let r=await C(`/api/domains/${encodeURIComponent(e)}/connect`),o=await r.json();if(r.ok||(n.stop("Failed"),g(o.error||o.message,{hint:o.hint,status:r.status,json:i.json,fields:i.fields})),n.stop("Providers loaded"),i.json){k(o,i.fields);return}E(`Providers for ${x.domain(o.domain)}`);for(let a of["hosting","email"]){let l=o.providers?.[a];if(l?.length){h(),console.log(` ${le.default.bold(a.toUpperCase())}`);for(let c of l){let u=c.methods.map(f=>f.default?le.default.green(`${f.name} (default)`):le.default.dim(f.name)).join(le.default.dim(", "));console.log(` ${le.default.cyan(c.name.padEnd(20))} ${u}`)}}}h();return}return mr(e,i)}async function mr(e,t){let i={};if(t.target&&(i.target=t.target),t.provider&&(i.provider=t.provider),t.method&&(i.method=t.method),t.dryRun)return G("connect",{domain:e,...i},t.json,t.fields);let s=j(!t.json);s.start(`Connecting ${x.domain(e)}`);let n=await C(`/api/domains/${encodeURIComponent(e)}/connect`,{method:"POST",body:JSON.stringify(i)}),r=await n.json();n.ok||(s.stop("Connection failed"),g(r.error||r.message,{hint:r.hint,status:n.status,json:t.json,fields:t.fields}));let o=r.status==="manual_setup_required";if(s.stop(o?`${_.success} DNS instructions for ${le.default.cyan(r.provider)}`:`${_.success} Connected to ${le.default.cyan(r.provider)}`),t.json){k(r,t.fields);return}if(E(o?`Add these records at your registrar for ${x.domain(r.domain)}`:`Connected ${x.domain(r.domain)}`),b("Provider",le.default.cyan(r.provider)),b("Method",r.method),r.records?.length){let a=[8,22,40];h(),console.log(` ${le.default.bold("DNS Records")}`);let l=["Type","Name","Value"].map((u,f)=>le.default.dim(u.padEnd(a[f]))).join(" "),c=a.map(u=>le.default.dim("\u2500".repeat(u))).join(" ");console.log(` ${l}`),console.log(` ${c}`);for(let u of r.records){let f=u.record,p=u.status!=="already_set";process.stdout.isTTY&&p&&await qt(50);let $=[le.default.yellow(f.type),f.name,le.default.cyan(f.value)+(f.priority?le.default.dim(` pri=${f.priority}`):"")].map((w,S)=>ki(w,a[S])).join(" "),m=u.status==="already_set"?le.default.dim("\u2713"):u.status==="updated"?le.default.yellow("\u21BA"):u.status==="pending"?le.default.yellow("\u2192"):_.success,y=u.status==="already_set"?le.default.dim(" already set"):u.status==="updated"?le.default.dim(" updated"):u.status==="pending"?le.default.dim(" add this"):"";console.log(` ${m} ${$}${y}`)}}h(),r.next_steps?.length?(console.log(` ${le.default.bold("Next steps")}`),r.next_steps.forEach((a,l)=>{console.log(` ${le.default.dim(`${l+1}.`)} ${a}`)})):r.hint&&console.log(` ${le.default.dim(r.hint)}`),r.docs&&console.log(` ${le.default.dim("Docs:")} ${x.url(r.docs)}`),h()}var le,Ms=Ee(()=>{"use strict";ne();le=M(Z(),1);Oe();X();ye();Le()});var br={};xt(br,{email:()=>Ht});function Xa(e){return[V.default.yellow(e.type),e.name,V.default.cyan(e.value)+(e.priority?V.default.dim(` pri=${e.priority}`):"")]}function Us(e){return Za[e]||e}function Qa(e,t){if(e&&e.includes("@")){let[i,s]=e.split("@",2);!t.slug&&i&&(t.slug=i),!t.domain&&s&&(t.domain=s)}}async function tt(e){return e.domain?(Q(e.domain,e),e.domain):de()}async function Ht(e,t,i){if(e&&e.includes(".")&&!Ya.includes(e))return i.check?pr(e,!!i.json,i.fields):t?gr(e,t,!!i.json,i.fields):$r(e,!!i.json,i.fields);if(Qa(t,i),i.body&&!i.text&&(i.text=i.body),i.title&&!i.subject&&(i.subject=i.title),i.from&&i.from.includes("@")){let[s,n]=i.from.split("@",2);!i.slug&&s&&(i.slug=s),!i.domain&&n&&(i.domain=n)}switch(e){case void 0:return hr(i);case"list":return hr(i);case"inbox":return ol(i);case"setup":return el(i);case"status":return tl(i);case"remove":return il(i);case"create":return sl(i);case"delete":return nl(i);case"send":return rl(i);case"webhook":return al(i);case"forward":return ll(i);case"check":return pr(i.domain||await de(),!!i.json,i.fields);case"connect":return gr(i.domain||await de(),t||void 0,!!i.json,i.fields);default:g(`Unknown action: ${e}`,{hint:"Actions: list, inbox, create, delete, send, forward, webhook, setup, status, check, connect",code:"validation_error",json:i.json,fields:i.fields})}}async function el(e){let t=await tt(e);if(e.dryRun)return G("email_setup",{domain:t},e.json,e.fields);let i=j(!e.json);i.start(`Setting up email on ${x.domain(t)}`);let s=await C(`/api/domains/${encodeURIComponent(t)}/email/setup`,{method:"POST"}),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${_.success} Email ${n.status==="already_configured"?"already configured":"configured"}`),e.json){k(n,e.fields);return}if(n.records?.length){h(),E(`Email DNS Records ${x.domain(t)}`);let r=n.records.map(o=>[V.default.yellow(o.type),o.name,o.value.length>40?o.value.slice(0,40)+"...":o.value,o.status==="verified"||o.status==="created"?V.default.green(o.status):V.default.yellow(o.status)]);ge(["Type","Name","Value","Status"],r,[8,28,44,12])}h(),n.hint&&Lt(n.hint),I("Check status:",`domani email status --domain ${t}`),h()}async function tl(e){let t=await tt(e),i=j(!e.json);i.start(`Checking email status for ${x.domain(t)}`);let s=await C(`/api/domains/${encodeURIComponent(t)}/email/status`),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${_.success} Status loaded`),e.json){k(n,e.fields);return}if(E(`Email ${x.domain(t)}`),b("Enabled",n.enabled?V.default.green("yes"):V.default.dim("no")),n.enabled&&(b("Verified",n.verified?V.default.green("yes"):V.default.yellow("pending")),b("Mailboxes",String(n.mailbox_count))),h(),!n.enabled)I("Set up email:",`domani email setup --domain ${t}`),h();else if(!n.verified&&n.records?.length){console.log(` ${V.default.yellow("!")} Add these DNS records to verify:`);for(let r of n.records)console.log(` ${V.default.yellow(r.type)} ${r.name} ${V.default.dim("\u2192")} ${r.value.length>50?r.value.slice(0,50)+"...":r.value}`);h()}}async function il(e){let t=await tt(e);if(e.dryRun)return G("email_remove",{domain:t},e.json,e.fields);let i=j(!e.json);i.start(`Removing email from ${x.domain(t)}`);let s=await C(`/api/domains/${encodeURIComponent(t)}/email/setup`,{method:"DELETE"}),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${_.success} Email disabled`),e.json){k(n,e.fields);return}n.mailboxes_deleted>0&&console.log(` ${V.default.dim(`${n.mailboxes_deleted} mailbox(es) deleted.`)}`),h()}async function hr(e){let t=j(!e.json);t.start("Loading mailboxes");let i=e.domain?`/api/domains/${encodeURIComponent(e.domain)}/email`:"/api/email",s=await C(i),n=await s.json();s.ok||(t.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields}));let r=n.mailboxes||[];if(t.stop(`${_.success} ${r.length} mailbox(es)`),e.json){k(n,e.fields);return}if(r.length===0){h(),console.log(` ${V.default.dim("No mailboxes.")}`),h(),I("Create one:","domani email create hello@example.com"),h();return}h(),E("Mailboxes");let o=r.map(a=>[V.default.cyan(a.address),String(a.message_count),a.webhook_url?x.url(a.webhook_url):V.default.dim("-"),V.default.dim(new Date(a.created_at).toLocaleDateString())]);ge(["Address","Messages","Webhook","Created"],o,[32,10,36,14]),h()}async function sl(e){let t=await tt(e);if(e.dryRun)return G("email_create_mailbox",{domain:t,slug:e.slug},e.json,e.fields);let i=j(!e.json);i.start("Creating mailbox");let s={};e.slug&&(s.slug=e.slug);let n=await C(`/api/domains/${encodeURIComponent(t)}/email`,{method:"POST",body:JSON.stringify(s)}),r=await n.json();if(n.ok||(i.stop("Failed"),g(r.error||r.message,{hint:r.hint,status:n.status,json:e.json,fields:e.fields})),i.stop(`${_.success} ${V.default.cyan(r.address)} ready`),e.json){k(r,e.fields);return}}async function nl(e){let t=await tt(e);if(e.slug||g("Slug required",{hint:"Usage: domani email delete hello@example.com",code:"validation_error",json:e.json,fields:e.fields}),e.dryRun)return G("email_delete_mailbox",{domain:t,address:`${e.slug}@${t}`},e.json,e.fields);let i=j(!e.json);i.start(`Deleting ${e.slug}@${t}`);let s=await C(`/api/domains/${encodeURIComponent(t)}/email/${encodeURIComponent(e.slug)}`,{method:"DELETE"}),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${_.success} Mailbox deleted`),e.json){k(n,e.fields);return}console.log(` ${V.default.dim(`${n.address} and all messages deleted.`)}`),h()}async function rl(e){let t=await tt(e);if(e.slug||g("Slug required",{hint:'Usage: domani email send hello@example.com --to user@test.com --subject "Hi" --body "Hello"',code:"validation_error",json:e.json,fields:e.fields}),e.to||g("Recipient required",{hint:"Usage: domani email send hello@example.com --to user@test.com",code:"validation_error",json:e.json,fields:e.fields}),e.dryRun)return G("email_send",{from:`${e.slug}@${t}`,to:e.to,subject:e.subject},e.json,e.fields);let i=j(!e.json);i.start(`Sending from ${e.slug}@${t}`);let s={to:e.to};e.cc&&(s.cc=e.cc),e.bcc&&(s.bcc=e.bcc),e.subject&&(s.subject=e.subject),e.text&&(s.text=e.text),e.inReplyTo&&(s.in_reply_to=e.inReplyTo),e.references&&(s.references=e.references);let n=await C(`/api/domains/${encodeURIComponent(t)}/email/${encodeURIComponent(e.slug)}/send`,{method:"POST",body:JSON.stringify(s)}),r=await n.json();n.ok||(i.stop("Failed"),g(r.error||r.message,{hint:r.hint,status:n.status,json:e.json,fields:e.fields}));let o=Array.isArray(r.to)?r.to.join(", "):r.to;if(i.stop(`${_.success} Sent to ${V.default.cyan(o)}`),e.json){k(r,e.fields);return}}async function ol(e){let t=await tt(e);e.slug||g("Slug required",{hint:"Usage: domani email inbox hello@example.com [--direction in|out] [--limit 20]",code:"validation_error",json:e.json,fields:e.fields});let i=new URLSearchParams;e.direction&&i.set("direction",e.direction),e.limit&&i.set("limit",e.limit);let s=i.toString()?`?${i}`:"",n=j(!e.json);n.start(`Loading messages for ${e.slug}@${t}`);let r=await C(`/api/domains/${encodeURIComponent(t)}/email/${encodeURIComponent(e.slug)}/messages${s}`),o=await r.json();r.ok||(n.stop("Failed"),g(o.error||o.message,{hint:o.hint,status:r.status,json:e.json,fields:e.fields}));let a=o.messages||[];if(e.json){n.stop(`${_.success} ${a.length} message(s)`),k(o,e.fields);return}if(a.length===0){n.stop(`${V.default.dim("No messages")}`);return}let l=a.length>1?"s":"";n.stop(`${_.success} ${V.default.cyan(`${e.slug}@${t}`)} ${V.default.dim("\xB7 "+a.length+" message"+l)}`);for(let c of a){let u=c.direction==="in"?V.default.green("in "):V.default.dim("out"),f=c.direction==="in"?c.from:c.to,p=c.subject||"(no subject)",v=V.default.dim(new Date(c.created_at).toLocaleString()),$=p;if(c.text){let m=c.text.replace(/\s+/g," ").trim(),y=m.length>60?m.slice(0,60)+"\u2026":m;$=`${p} ${V.default.dim("\u2014 "+y)}`}console.log(` ${u} ${f.padEnd(30)} ${$} ${v}`)}o.next_cursor&&console.log(` ${V.default.dim("\u2026 more available, use --limit to paginate")}`)}async function al(e){let t=await tt(e);if(e.slug||g("Slug required",{hint:"Usage: domani email webhook hello@example.com --url https://...",code:"validation_error",json:e.json,fields:e.fields}),e.dryRun)return G("email_webhook",{address:`${e.slug}@${t}`,webhook_url:e.url||null},e.json,e.fields);let i=j(!e.json);i.start(`Updating webhook for ${e.slug}@${t}`);let s=await C(`/api/domains/${encodeURIComponent(t)}/email/${encodeURIComponent(e.slug)}`,{method:"PATCH",body:JSON.stringify({webhook_url:e.url||null})}),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${_.success} Webhook ${e.url?"set":"removed"}`),e.json){k(n,e.fields);return}E(`Mailbox ${n.address}`),b("Webhook",n.webhook_url?x.url(n.webhook_url):V.default.dim("none")),h()}async function ll(e){let t=await tt(e);if(e.slug||g("Slug required",{hint:"Usage: domani email forward hello@example.com --forward-to me@gmail.com",code:"validation_error",json:e.json,fields:e.fields}),e.dryRun)return G("email_forward",{address:`${e.slug}@${t}`,forward_to:e.forwardTo||null},e.json,e.fields);let i=j(!e.json),s=e.forwardTo||null;i.start(`Updating forward for ${e.slug}@${t}`);let n=await C(`/api/domains/${encodeURIComponent(t)}/email/${encodeURIComponent(e.slug)}`,{method:"PATCH",body:JSON.stringify({forward_to:s})}),r=await n.json();if(n.ok||(i.stop("Failed"),g(r.error||r.message,{hint:r.hint,status:n.status,json:e.json,fields:e.fields})),i.stop(`${_.success} Forward ${s?"set":"removed"}`),e.json){k(r,e.fields);return}E(`Mailbox ${r.address}`),b("Forward to",r.forward_to?V.default.cyan(r.forward_to):V.default.dim("none")),h()}async function pr(e,t,i){let s=j(!t);s.start(`Checking email health for ${x.domain(e)}`);let n=await C(`/api/domains/${encodeURIComponent(e)}/email/check`),r=await n.json();if(n.ok||(s.stop("Failed"),g(r.error||r.message,{hint:r.hint,status:n.status,json:t,fields:i})),s.stop("Email health checked"),t){k(r,i);return}if(E(`Email Health ${x.domain(r.domain)}`),r.provider?b("Provider",V.default.cyan(Us(r.provider))):b("Provider",V.default.dim("unknown")),r.mx.configured?b("MX",`${_.success} ${V.default.green("propagated")} ${V.default.dim(`(${r.mx.records.length} record${r.mx.records.length!==1?"s":""})`)}`):b("MX",`${_.error} ${V.default.red("not configured")}`),r.spf.configured?b("SPF",`${_.success} ${V.default.green(r.spf.value)}`):b("SPF",`${_.error} ${V.default.red("missing")}`),r.dmarc.configured){let o=r.dmarc.value.length>50?r.dmarc.value.slice(0,50)+"...":r.dmarc.value;b("DMARC",`${_.success} ${V.default.green(o)}`)}else b("DMARC",`${_.error} ${V.default.red("missing")}`);r.dkim.configured?b("DKIM",`${_.success} ${V.default.green("found")} ${V.default.dim(`(${r.dkim.selectors.join(", ")})`)}`):b("DKIM",`${_.warning} ${V.default.yellow("not found")}`),h(),r.mx.configured?(!r.spf.configured||!r.dmarc.configured)&&(Lt("SPF and DMARC protect against email spoofing. Re-run email setup to add them."),h()):(I("Set up email:",`domani email ${e} google`),h())}async function gr(e,t,i,s){return t?yr(e,t,i,s):$r(e,i,s)}async function $r(e,t,i){let s=j(!t);s.start("Loading email providers");let n=await C(`/api/domains/${encodeURIComponent(e)}/connect`),r=await n.json();n.ok||(s.stop("Failed"),g(r.error||r.message,{hint:r.hint,status:n.status,json:t,fields:i})),s.stop("Providers loaded");let o=r.providers?.email||[];o.length===0&&g("No email providers available",{code:"not_found",json:t,fields:i});let a=await We({message:"Choose an email provider",options:o.map(l=>({value:l.name,label:Us(l.name)}))});return oe(a)&&process.exit(0),yr(e,a,t,i)}async function yr(e,t,i,s){if(i){let c=await C(`/api/domains/${encodeURIComponent(e)}/connect`,{method:"POST",body:JSON.stringify({target:t})}),u=await c.json();c.ok||g(u.error||u.message,{hint:u.hint,status:c.status,json:i,fields:s}),k(u,s);return}let n=await C(`/api/domains/${encodeURIComponent(e)}/connect?provider=${encodeURIComponent(t)}`);if(!n.ok){let c=await n.json();g(c.error||c.message,{hint:c.hint,status:n.status,json:i,fields:s})}let r=await n.json(),o=r.preview?.records??[],a=r.preview?.provider??t,l=Us(a);if(E(`Email ${x.domain(e)}`),b("Provider",V.default.cyan(l)),o.length){h(),console.log(` ${V.default.bold("DNS Records")}`);let c=[8,24,40],u=It(["Type","Name","Value"],o.map(w=>({cells:Xa(w),status:"pending"})),c);u.start();let f=await C(`/api/domains/${encodeURIComponent(e)}/connect`,{method:"POST",body:JSON.stringify({target:t})}),p=await f.json();f.ok||(u.stop(),h(),g(p.error||p.message,{hint:p.hint,status:f.status,json:i,fields:s}));let v=p.records||[];for(let w=0;w<o.length;w++)v.find(A=>A.record.type===o[w].type&&A.record.name===o[w].name&&A.record.value===o[w].value)?.status==="already_set"||await qt(60),u.markDone(w);await qt(80),u.stop();let $=v.filter(w=>w.status==="created"||w.status==="updated").length,m=v.filter(w=>w.status==="already_set").length,y;m===v.length?y=`All ${m} records already set`:m>0?y=`${$} created, ${m} already set`:y=`${$} DNS records set`,h(),console.log(` ${_.success} ${V.default.green(`Email configured - ${y}`)}`)}else{let c=j(!0);c.start("Setting DNS records");let u=await C(`/api/domains/${encodeURIComponent(e)}/connect`,{method:"POST",body:JSON.stringify({target:t})}),f=await u.json();u.ok||(c.stop("Failed"),g(f.error||f.message,{hint:f.hint,status:u.status,json:i,fields:s})),c.stop(`${_.success} Email configured via ${V.default.cyan(l)}`)}h(),I("Verify propagation:",`domani email ${e} --check`),h()}var V,Ya,Za,Ls=Ee(()=>{"use strict";ne();V=M(Z(),1);Oe();X();ye();Le();Ya=["setup","status","remove","list","create","delete","send","inbox","webhook","forward","check","connect"],Za={"google-workspace":"Google Workspace",fastmail:"Fastmail",proton:"Proton Mail"}});var vr={};xt(vr,{dns:()=>Ws});async function Ws(e,t,i,s,n,r){e||(e=await de()),Q(e,r);let o=r?.json??!1,a=r?.type||i,l=r?.name||s,c=r?.value||n;if(!t||t==="get"){let u=j(!o);u.start(`Loading DNS for ${x.domain(e)}`);let f=await C(`/api/domains/${encodeURIComponent(e)}/dns`),p=await f.json();if(f.ok||(u.stop("Failed"),g(p.error||p.message,{hint:p.hint,status:f.status,json:o,fields:r?.fields})),u.stop(`${p.records.length} record(s)`),o){k(p,r?.fields);return}if(p.records.length===0){h(),console.log(` ${ve.default.dim(`No DNS records for ${e}`)}`),h(),I("Auto-configure DNS:",`domani connect ${e}`),h();return}let v=[8,24,40,8];E(`DNS ${x.domain(e)}`,v.reduce((m,y)=>m+y,0)+v.length-1);let $=p.records.map(m=>{let y=m.priority?ve.default.dim(` pri=${m.priority}`):"";return[ve.default.yellow(m.type),m.name,ve.default.cyan(m.value)+y,ve.default.dim(String(m.ttl))]});ge(["Type","Name","Value","TTL"],$,v),h();return}if(t==="set"){if((!a||!l||!c)&&g("Missing arguments for dns set",{hint:"Usage: domani dns <domain> set --type A --name www --value 1.2.3.4",code:"validation_error",json:o,fields:r?.fields}),r?.dryRun)return G("dns_set",{domain:e,record:{type:a.toUpperCase(),name:l,value:c,ttl:3600}},o,r?.fields);let u=j(!o);u.start(`Setting ${ve.default.yellow(a.toUpperCase())} record`);let f=await C(`/api/domains/${encodeURIComponent(e)}/dns`),p=await f.json(),$=(f.ok?p.records:[]).filter(w=>!(w.type===a.toUpperCase()&&w.name===l));$.push({type:a.toUpperCase(),name:l,value:c,ttl:3600});let m=await C(`/api/domains/${encodeURIComponent(e)}/dns`,{method:"PUT",body:JSON.stringify({records:$})}),y=await m.json();m.ok||(u.stop("Failed"),g(y.error||y.message,{hint:y.hint,status:m.status,json:o,fields:r?.fields})),u.stop(`${_.success} ${ve.default.yellow(a.toUpperCase())} ${l} ${_.arrow} ${ve.default.cyan(c)}`),o?k(y,r?.fields):(h(),I("Check propagation:",`domani status ${e}`),h());return}if(t==="delete"){if((!a||!l)&&g("Missing arguments for dns delete",{hint:"Usage: domani dns <domain> delete --type A --name www",code:"validation_error",json:o,fields:r?.fields}),r?.dryRun)return G("dns_delete",{domain:e,record:{type:a.toUpperCase(),name:l}},o,r?.fields);let u=j(!o);u.start(`Deleting ${ve.default.yellow(a.toUpperCase())} ${l}`);let f=await C(`/api/domains/${encodeURIComponent(e)}/dns?type=${encodeURIComponent(a.toUpperCase())}&name=${encodeURIComponent(l)}`,{method:"DELETE"}),p=await f.json();f.ok||(u.stop("Failed"),g(p.error||p.message,{hint:p.hint,status:f.status,json:o,fields:r?.fields})),u.stop(`${_.success} Deleted ${ve.default.yellow(a.toUpperCase())} ${l}`),o?k(p,r?.fields):(h(),I("Check propagation:",`domani status ${e}`),h());return}if(t==="snapshot"){if(r?.dryRun)return G("dns_snapshot",{domain:e},o,r?.fields);let u=j(!o);u.start(`Capturing DNS snapshot for ${x.domain(e)}`);let f=await C(`/api/domains/${encodeURIComponent(e)}/dns/snapshot`,{method:"POST"}),p=await f.json();f.ok||(u.stop("Failed"),g(p.error||p.message,{hint:p.hint,status:f.status,json:o,fields:r?.fields}));let v=p.records?.length??0;if(u.stop(`${_.success} Captured ${v} record(s)`),o){k(p,r?.fields);return}let $=`${e}.dns.json`,m=(0,qs.resolve)(process.cwd(),$);(0,ji.writeFileSync)(m,JSON.stringify(p,null,2)+`
178
+ `),E("DNS Snapshot"),b("Domain",x.domain(p.domain)),b("Records",String(v)),b("Subdomains",String(p.subdomains?.length??0)),b("Sources",(p.sources||[]).join(", ")||"none"),b("Captured",p.capturedAt||p.captured_at||"now"),b("Saved to",ve.default.cyan($)),h(),I("Restore from this snapshot:",`domani dns ${e} restore --file ${$}`),h();return}if(t==="restore"){if(r?.dryRun)return G("dns_restore",{domain:e,source:r?.file||"server_backup"},o,r?.fields);let u=j(!o),f;if(r?.file){let $=(0,qs.resolve)(process.cwd(),r.file);$.startsWith(process.cwd())||g("File path must be within the current directory",{hint:`Got: ${r.file}`,code:"validation_error",json:o,fields:r?.fields});try{let m=(0,ji.readFileSync)($,"utf-8"),y=JSON.parse(m);f=JSON.stringify({snapshot:y}),u.start(`Restoring DNS for ${x.domain(e)} from ${ve.default.cyan(r.file)}`)}catch(m){g(`Failed to read snapshot file: ${m instanceof Error?m.message:"unknown"}`,{hint:`Make sure ${r.file} exists and contains valid JSON.`,code:"validation_error",json:o,fields:r?.fields})}}else u.start(`Restoring DNS for ${x.domain(e)} from server backup`);let p=await C(`/api/domains/${encodeURIComponent(e)}/dns/restore`,{method:"POST",...f?{body:f}:{}}),v=await p.json();if(p.ok||(u.stop("Failed"),g(v.error||v.message,{hint:v.hint,status:p.status,json:o,fields:r?.fields})),u.stop(`${_.success} Restored DNS`),o){k(v,r?.fields);return}if(E("DNS Restored"),b("Domain",x.domain(v.domain)),b("Applied",ve.default.green(String(v.applied??0))),b("Skipped",ve.default.dim(String(v.skipped??0))),v.errors?.length>0){b("Errors",ve.default.red(String(v.errors.length)));for(let $ of v.errors)console.log(` ${ve.default.red("\u2022")} ${$}`)}h(),I("Verify DNS records:",`domani dns ${e}`),h();return}g(`Unknown action: ${t}`,{hint:"Use 'get', 'set', 'delete', 'snapshot', or 'restore'.",code:"validation_error",json:o,fields:r?.fields})}var ve,ji,qs,Hs=Ee(()=>{"use strict";ne();ve=M(Z(),1);X();ye();Le();ji=require("node:fs"),qs=require("node:path")});var wr={};xt(wr,{status:()=>Js});function cl(e){return[He.default.yellow(e.type),e.name,He.default.cyan(e.value)+(e.priority?He.default.dim(` pri=${e.priority}`):"")]}function dl(e){if(E(`Status ${x.domain(e.domain)}`),e.expires){let t=new Date(e.expires).toLocaleDateString(),i=e.days_until_expiry,s=i!=null&&i<30?He.default.red:i!=null&&i<90?He.default.yellow:He.default.green;b("Expires",`${t} ${He.default.dim("(")}${s(`${i} days`)}${He.default.dim(")")}`)}}async function Js(e,t){if(e||(e=await de()),Q(e,t),t.json){let f=await C(`/api/domains/${encodeURIComponent(e)}/status`),p=await f.json();f.ok||g(p.error||p.message,{hint:p.hint,status:f.status,json:t.json,fields:t.fields}),k(p,t.fields);return}let i=j(!0);i.start(`Checking ${x.domain(e)}`);let s;try{s=await C(`/api/domains/${encodeURIComponent(e)}/status`,{headers:{Accept:"text/event-stream"},signal:AbortSignal.timeout(t.timeout?parseInt(t.timeout,10)*1e3:3e4)})}catch{i.stop("Failed"),g("Request timed out",{hint:"The status check took too long. Try again.",code:"timeout",json:t.json,fields:t.fields})}if(!s.ok){i.stop("Failed");try{let f=await s.json();g(f.error||f.message,{hint:f.hint,status:s.status,json:t.json,fields:t.fields})}catch{g(`Server error (${s.status})`,{status:s.status,json:t.json,fields:t.fields})}}let n=s.body;n||(i.stop("Failed"),g("Empty response"));let r=new TextDecoder,o="",a=null,l=[],c=!1,u="";try{for await(let f of n){o+=r.decode(f,{stream:!0});let p=o.split(`
179
+ `);o=p.pop()??"";for(let v of p)if(v.startsWith("event: "))u=v.slice(7);else if(v.startsWith("data: ")){let $=JSON.parse(v.slice(6));if(u==="info"&&(i.stop("Status retrieved"),c=!0,dl($)),u==="records")if(l=$,l.length>0){h(),console.log(` ${He.default.bold("DNS Records")}`);let m=[8,10,34];a=It(["Type","Name","Value"],l.map(y=>({cells:cl(y),status:"pending"})),m),a.start()}else h(),b("DNS",He.default.dim("no records")),I("Auto-configure DNS:",`domani connect ${e}`);if(u==="propagation"&&a){let{index:m,propagated:y}=$,w=y?_.success:`${_.warning}`;a.markDone(m,w)}u==="done"&&a&&a.stop(),u==="error"&&(c||i.stop("Failed"),a&&a.stop(),g($.message||"Status check failed"))}}}catch{c||i.stop("Failed"),a&&a.stop(),g("Connection lost",{hint:"The status check was interrupted. Try again.",code:"connection_lost",json:t.json,fields:t.fields})}c||i.stop("Done"),h()}var He,Bs=Ee(()=>{"use strict";ne();He=M(Z(),1);X();ye();Le()});var Ci={};xt(Ci,{buy:()=>zs});async function Gs(e){let t=await We({message:`What's next for ${Ae.default.cyan(e)}?`,options:[{value:"connect",label:"Connect to a service",hint:"domani connect"},{value:"email",label:"Set up email",hint:"domani email setup"},{value:"dns",label:"Configure DNS",hint:"domani dns"},{value:"status",label:"Check status & DNS propagation",hint:"domani status"},{value:"done",label:"Done"}]});if(oe(t)||t==="done"){h();return}if(h(),t==="connect"){let{connect:i}=await Promise.resolve().then(()=>(Ms(),fr));await i(e,void 0,{})}else if(t==="email"){let i=await Re({message:`Mailbox name for ${Ae.default.cyan(e)}`,placeholder:"e.g. hey, hello, contact"});if(oe(i)||!i){h();return}h();let{email:s}=await Promise.resolve().then(()=>(Ls(),br));await s("create",void 0,{domain:e,slug:i})}else if(t==="dns"){let{dns:i}=await Promise.resolve().then(()=>(Hs(),vr));await i(e)}else if(t==="status"){let{status:i}=await Promise.resolve().then(()=>(Bs(),wr));await i(e,{})}}async function ul(e,t){Q(e,t);let i;if(t.preChecked)i={available:!0,...t.preChecked};else{let u=j(!t.json);u.start(`Checking ${x.domain(e)}`);let f=await C(`/api/domains/search?q=${encodeURIComponent(e)}`);i=await f.json(),f.ok||(u.stop("Search failed"),g(i.error,{hint:i.hint,status:f.status,json:t.json,fields:t.fields})),i.available||(u.stop(`${_.error} ${x.domain(e)} is not available`),g(`${e} is not available`,{code:"not_available",json:t.json,fields:t.fields})),u.stop(`${_.success} ${x.domain(e)} ${_.dot} available ${_.dot} ${x.price(i.price)}/yr`)}if(t.dryRun)return G("buy",{domain:e,available:!0,price:i.price,currency:i.currency||"USD"},t.json,t.fields);if(!bt(t)){let u=await Ue({message:`Purchase ${Ae.default.bold(e)} for ${x.price(i.price)}/yr?`});if(!u||typeof u=="symbol"){console.log(` ${Ae.default.dim("Cancelled.")}`);return}}let s=j(!t.json);s.start("Purchasing");let n=await C("/api/domains/buy",{method:"POST",headers:{Accept:"text/event-stream"},body:JSON.stringify({domain:e})});if(!n.ok||!n.body){s.stop("Purchase failed");let u=await n.json().catch(()=>({}));g(u.error||u.message,{hint:u.hint,fixUrl:u.setup_url||u.payment_options?.card?.setup_url,status:n.status,json:t.json,fields:t.fields})}let r={},o=new TextDecoder,a="",l="";for await(let u of n.body){a+=o.decode(u,{stream:!0});let f=a.split(`
180
+ `);a=f.pop()??"";for(let p of f)if(p.startsWith("event: "))l=p.slice(7).trim();else if(p.startsWith("data: ")){let v=JSON.parse(p.slice(6));l==="checking"?s.message(`Checking ${x.domain(v.domain)}`):l==="payment"?s.message(`Charging ${x.price(v.total)}`):l==="registering"?s.message(`Registering ${x.domain(v.domain)}`):l==="registered"?r=v:l==="error"&&(s.stop("Purchase failed"),g(v.error,{hint:v.hint,fixUrl:v.setup_url,status:n.status,json:t.json,fields:t.fields}))}}let c=r.expires?Ae.default.dim(` \xB7 expires ${new Date(r.expires).toLocaleDateString()}`):"";if(s.stop(`${_.success} ${x.domain(r.domain)} is yours!${c}`),t.json){k(r,t.fields);return}ke?await Gs(r.domain):(I("Connect to a service:",`domani connect ${r.domain}`),I("Set up email:",`domani email setup ${r.domain}`),I("Configure DNS:",`domani dns ${r.domain}`),h())}async function ml(e,t){ur(e,t);let i=!!t.json,s=j(!i);s.start(`Checking ${e.length} domains`);let n=await Promise.all(e.map(async m=>{try{let y=await C(`/api/domains/search?q=${encodeURIComponent(m)}`),w=await y.json();return{domain:m,available:y.ok&&w.available,price:w.price}}catch{return{domain:m,available:!1,price:void 0}}})),r=n.filter(m=>m.available),o=n.filter(m=>!m.available);r.length===0&&(s.stop(`${_.error} None of the ${e.length} domains are available`),process.exit(1));let a=r.reduce((m,y)=>m+(y.price||0),0);if(s.stop(`${_.success} ${r.length}/${e.length} available ${_.dot} ${x.price(a.toFixed(2))} total`),o.length>0)for(let m of o)console.log(` ${_.error} ${x.domain(m.domain)} ${Ae.default.dim("not available")}`);if(t.dryRun)return G("buy_bulk",{domains:r.map(m=>({domain:m.domain,price:m.price})),unavailable:o.map(m=>m.domain),total_price:parseFloat(a.toFixed(2))},t.json,t.fields);if(!bt(t)){let m=await Ue({message:`Purchase ${Ae.default.bold(String(r.length))} domain${r.length>1?"s":""} for ${x.price(a.toFixed(2))}?`});if(!m||typeof m=="symbol"){console.log(` ${Ae.default.dim("Cancelled.")}`);return}}h();let l=r.map(m=>({cells:[x.domain(m.domain),m.price?`${x.price(m.price.toFixed(2))}/yr`:""],status:"pending"})),c=It(["Domain","Price"],l,[30,12],!i);c.start();let f=await(await C("/api/domains/buy",{method:"POST",body:JSON.stringify({domains:r.map(m=>m.domain)})})).json(),p=new Set((f.results||[]).map(m=>m.domain));for(let m=0;m<r.length;m++){let y=r[m].domain.toLowerCase().trim();p.has(y)?c.markDone(m,_.success):c.markDone(m,_.error)}if(c.stop(),i){k(f,t.fields);return}h();let v=f.summary?.succeeded??0,$=f.summary?.failed??0;if(v>0&&console.log(` ${_.success} ${Ae.default.green(`${v} domain${v>1?"s":""} registered`)}`),$>0){console.log(` ${_.error} ${Ae.default.red(`${$} failed`)}`);for(let m of f.errors||[])console.log(` ${Ae.default.dim("\u2500")} ${x.domain(m.domain)}: ${Ae.default.dim(m.error)}${m.hint?` ${Ae.default.dim(`(${m.hint})`)}`:""}`)}if(h(),v>0&&ke){let m=(f.results||[]).filter(y=>y.success).map(y=>y.domain);if(m.length===1)await Gs(m[0]);else{let y=await We({message:"Set up one of your new domains?",options:[...m.map(w=>({value:w,label:Ae.default.cyan(w)})),{value:"done",label:"Done"}]});!oe(y)&&y!=="done"?(h(),await Gs(y)):h()}}else v>0&&(I("Connect to a service:","domani connect <domain>"),I("Set up email:","domani email setup <domain>"),h())}async function zs(e,t){let i=e.filter(Boolean);if(i.length===0){ke||g("Missing required argument: domain(s)",{hint:"Usage: domani buy <domain> [domain2 ...]",code:"missing_argument",json:t.json});let s=await Re({message:"Domain to purchase",placeholder:"e.g. myapp.dev (space-separated for multiple)"});(oe(s)||!s)&&process.exit(0),i=s.split(/\s+/).filter(Boolean)}return i.length===1?ul(i[0],t):ml(i,t)}var Ae,Jt=Ee(()=>{"use strict";ne();Oe();Ae=M(Z(),1);X();ye()});var cn=M(ln(),1),{program:Hl,createCommand:Jl,createArgument:Bl,createOption:Gl,CommanderError:zl,InvalidArgumentError:Kl,InvalidOptionArgumentError:Yl,Command:dn,Argument:Zl,Option:Xl,Help:Ql}=cn.default;var Ke=M(Z(),1);ut();ei();ut();var vt=M(Z(),1);X();async function nr(e){let t=ot(),i=j(!e.json),s=dt();if(s.token){i.start("Checking session");try{let c=await fetch(`${t}/api/me`,{headers:{Authorization:`Bearer ${s.token}`}});if(c.ok){let u=await c.json();i.stop(`Already logged in as ${vt.default.bold(u.email)}`),e.json&&k({status:"already_logged_in",email:u.email});return}}catch{}i.stop("Session expired, re-authenticating"),h()}i.start("Requesting auth code");let n=await fetch(`${t}/api/auth/cli`,{method:"POST",headers:{"Content-Type":"application/json"}});if(!n.ok){i.stop("Failed to initiate login");try{let c=await n.json();g(c.error||c.message||`Server error (${n.status})`,{hint:c.hint,code:"login_failed",json:e.json})}catch{g(`Could not reach ${t}. Check your connection and try again.`,{code:"network_error",json:e.json})}}let{code:r,auth_url:o,expires_in:a}=await n.json();if(i.stop("Auth code received"),e.json){k({status:"awaiting_approval",code:r,auth_url:o,expires_in:a});return}h(),console.log(` ${vt.default.dim("Verification code:")} ${vt.default.bold(vt.default.cyan(r))}`),console.log(` ${vt.default.dim("Opening browser")} ${_.arrow} ${x.url(o)}`),h(),Rt(o),i.start("Waiting for approval");let l=120;for(let c=0;c<l;c++){await new Promise(p=>setTimeout(p,5e3));let u=await fetch(`${t}/api/auth/cli/poll?code=${r}`);!u.ok&&u.status!==202&&(i.stop("Login failed"),g(`Server error (${u.status})`,{code:"login_failed"}));let f=await u.json();if(f.status==="complete"){ni({...dt(),token:f.token,email:f.email,api_url:t}),i.stop(`Logged in as ${vt.default.bold(f.email)}`),h(),I("Get started:","domani search"),h();return}f.error&&(i.stop("Login failed"),g(f.error||f.message,{hint:f.hint,code:"login_failed"}))}i.stop("Login timed out"),g("No approval received within 10 minutes",{hint:"Run 'domani login' to try again",code:"timeout"})}ut();var Ns=M(Z(),1);X();async function rr(e){let t=dt();if(!t.token){e.json?k({status:"not_logged_in"}):console.log(` ${Ns.default.dim("Not logged in.")}`);return}let{api_url:i}=t;yn(),i&&ni({api_url:i}),e.json?k({status:"logged_out",email:t.email||null}):console.log(` ${_.success} Logged out${t.email?` ${Ns.default.dim(`(${t.email})`)}`:""}`)}ne();var Wt=M(Z(),1);X();async function ar(e){let t=await C("/api/me"),i=await t.json();if(t.ok||g(i.error||i.message,{hint:i.hint,status:t.status,json:e.json,fields:e.fields}),e.json){k(i,e.fields);return}E("Account"),b("Email",Wt.default.bold(i.email)),b("Payment",i.has_payment_method?`${_.success} ${Wt.default.green("active")}`:`${_.error} ${Wt.default.dim("none")}`),b("Domains",String(i.domain_count)),b("API tokens",String(i.token_count)),b("Referral code",i.referral_code||Wt.default.dim("-")),b("Created",new Date(i.created_at).toLocaleDateString()),h()}ne();Oe();var D=M(Z(),1);X();ye();var De=10,Oi=["com","io","ai","dev","app","co","net","org","xyz","sh","me","cc","tech","run","cloud","so","gg","fm","tv","pro","one","inc","ltd","llc","biz","group","global","ventures","capital","fund","agency","store","shop","market","sale","deals","auction","trade","studio","design","art","space","style","fashion","luxury","brand","media","digital","site","online","live","show","world","zone","land","place","city","town","blog","news","social","chat","link","page","fun","lol","meme","wtf","tools","build","works","work","team","solutions","services","systems","network","software","music","video","photo","photos","game","games","club","stream","film","movie","pizza","coffee","beer","bar","pub","restaurant","cafe","kitchen","food","wine","health","care","clinic","dental","fitness","yoga","bio","life","lifestyle","finance","money","legal","law","cash","academy","university","education","training","courses","science","wiki","guide","us","uk","eu","ca","au","de","fr","it","es","nl","jp","sg","nz","mx","house","homes","realty","estate","garden","nyc","london","berlin","paris","guru","ninja","rocks","fail","party","vip","gold","black","pink","red","events","travel","sport","jobs","careers","consulting","energy","eco","green","support","help","info","new","now","today","day"],Ai=null;async function _r(){if(Ai)return Ai;try{let e=await he("/api/tlds?sort=price&order=asc&limit=1000");if(e.ok){let i=(await e.json()).tlds.map(s=>s.tld);if(i.length>0){let s=new Set(Oi),n=new Set(i),r=[...Oi.filter(o=>n.has(o)),...i.filter(o=>!s.has(o))];return Ai=r,r}}}catch{}return Ai=Oi,Oi}async function fl(e,t,i,s,n){let r=[],o=[],a=De,l=0,c=!0,u=0,f=0,p=0,v=0,$=!1,m=!1,y=null,w="",S=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],A=0,F=setInterval(()=>{m||!c||(A=(A+1)%S.length,J())},80);function N(){u>0&&(process.stdout.write(`\x1B[${u}A\x1B[0J`),u=0)}function H(){if(c)return[];let L=De+v*De;return r.length>a||s&&L<n.length?["more","new","skip"]:["new","skip"]}function R(){return r.slice(0,a)}function P(){let L=H();return Math.max(0,R().length+L.length-1)}let T=6;function J(){N();let L=[],B=R(),ce=!c&&B.length===0&&o.length>0,ue=ce?o.slice(0,T):B,je=ue.reduce((me,W)=>Math.max(me,W.domain.length),0),Ve=H();for(let me=0;me<ue.length;me++){let W=ue[me];if(ce)L.push(`${D.default.dim("\u2502")} ${D.default.dim("\u2715")} ${D.default.dim(W.domain.padEnd(je))} ${D.default.dim("taken")}`);else{let pe=me===l,Ye=pe?D.default.green("\u25CF"):D.default.dim("\u25CB"),Ti=W.domain.padEnd(je),Di=pe?D.default.bold(D.default.cyan(Ti)):Ti,Ni=D.default.dim(`$${W.price}/yr`);L.push(`${D.default.dim("\u2502")} ${Ye} ${Di} ${Ni}`)}}if(ce&&o.length>T&&L.push(`${D.default.dim("\u2502")} ${D.default.dim(`\u2026 and ${o.length-T} more taken`)}`),c){let me=w?D.default.dim(`checking ${w}\u2026`):D.default.dim("searching\u2026");L.push(`${D.default.dim("\u2502")} ${D.default.cyan(S[A])} ${me}`)}else{let me=De+v*De;s&&me>=n.length&&L.push(`${D.default.dim("\u2502")} ${D.default.dim(`All ${Math.min(me,n.length)} TLDs searched`)}`);for(let pe=0;pe<Ve.length;pe++){let Di=R().length+pe===l?D.default.green("\u25CF"):D.default.dim("\u25CB"),Ni=Ve[pe]==="more"?D.default.dim("More \u2192"):Ve[pe]==="new"?D.default.dim("New search \u2192"):D.default.dim("Skip");L.push(`${D.default.dim("\u2502")} ${Di} ${Ni}`)}L.push(D.default.dim("\u2514"))}process.stdout.write(L.join(`
181
+ `)+`
182
+ `),u=L.length}process.stdout.write(`${D.default.cyan("\u25C6")} Register a domain?
183
+ `),process.stdout.write("\x1B[?25l"),process.stdin.setRawMode(!0),process.stdin.resume();let Y=L=>{let B=L.toString();if(B==="\x1B[A")l=Math.max(0,l-1),J();else if(B==="\x1B[B")l=Math.min(P(),l+1),J();else if(B==="\r"){let ce=R();if(c&&ce.length===0)return;if(l<ce.length)y=ce[l]?.domain??null,m=!0;else{let je=H()[l-ce.length];je==="more"?(a+=De,r.length<a?$=!0:(l=Math.min(l,P()),J())):(je==="new"&&(y="__new__"),m=!0)}}else(B===""||B==="\x1B")&&(m=!0)};process.stdin.on("data",Y),J();async function q(L){let B=new TextDecoder,ce="",ue="";for await(let je of L){if(m)break;ce+=B.decode(je,{stream:!0});let Ve=ce.split(`
184
+ `);ce=Ve.pop()??"";for(let me of Ve)if(me.startsWith("event: "))ue=me.slice(7);else if(me.startsWith("data: ")){let W=JSON.parse(me.slice(6));if(ue==="result"&&(w=W.domain),ue==="result"&&(W.available||i)){if(v===0){let pe=r.findIndex(Ye=>Ye.price>W.price);pe===-1?r.push(W):(r.splice(pe,0,W),pe<=l&&l++)}else r.push(W);J()}else if(ue==="result"&&!W.available&&!W.error)o.length<8&&o.push(W);else if(ue==="done"){f+=W.total,p+=W.available,c=!1,l=Math.min(l,P());let pe=De+v*De;r.length<a&&s&&pe<n.length&&($=!0),$||J()}}}c=!1}for(await q(e);!m;)if(await new Promise(L=>{let B=setInterval(()=>{(m||$)&&(clearInterval(B),L())},16)}),$&&!m){$=!1;let L=De+v*De,B=n.slice(L,L+De);v++,c=!0,l=Math.min(l,Math.max(0,r.length-1)),J();let ce=new URLSearchParams;ce.set("domains",B.map(ue=>`${t}.${ue}`).join(","));try{let ue=await he(`/api/domains/search?${ce}`,{headers:{Accept:"text/event-stream"}});ue.ok&&ue.body?await q(ue.body):(c=!1,J())}catch{c=!1,J()}}clearInterval(F),process.stdin.removeListener("data",Y),process.stdin.isTTY&&process.stdin.setRawMode(!1),process.stdin.pause(),process.stdout.write("\x1B[?25h"),N();let ie=y==="__new__",z=ie?null:y,ae=z?r.find(L=>L.domain===z)??null:null;return z?process.stdout.write(`${D.default.dim("\u25C7")} Register a domain?
185
+ ${D.default.dim("\u2502")} ${D.default.bold(D.default.cyan(z))}
186
+ ${D.default.dim("\u2514")}
187
+ `):process.stdout.write(`${D.default.dim("\u2514")}
188
+ `),{chosen:z,chosenResult:ae,searchAgain:ie,allTaken:r.length===0&&o.length>0,expanded:v>0}}async function xr(e,t,i){if(!e){ke||g("Missing required argument: domain",{hint:"Usage: domani search <domain> [tlds...]",code:"missing_argument",json:i.json});let T=await Re({message:"Search for a domain",placeholder:"e.g. myapp or myapp.dev"});(oe(T)||!T)&&process.exit(0),e=T}let s=t.map(T=>T.replace(/^\./,"")),n=i.tlds?.split(",").map(T=>T.trim())||[],r=[...new Set([...s,...n])];if(r.length>0&&Si(r,i),Q(e,i),e.includes(".")&&r.length===0){let T=j(!i.json);T.start(`Checking ${x.domain(e)}`);let[J,Y]=await Promise.all([he(`/api/domains/search?q=${encodeURIComponent(e)}`),he(`/api/domains/${encodeURIComponent(e)}/og`).catch(()=>null)]),q=await J.json();if(J.ok||(T.stop("Search failed"),g(q.error||q.message,{hint:q.hint,status:J.status,json:i.json,fields:i.fields})),i.json){let ie=q.domain.split(".")[0];k({name:ie,results:[q],total:1,available:q.available?1:0},i.fields);return}if(q.available)if(T.stop(`${_.success} ${x.domain(q.domain)} ${_.dot} available ${_.dot} ${x.price(q.price)}/yr`),ke&&!i.json){let{buy:ie}=await Promise.resolve().then(()=>(Jt(),Ci));await ie([q.domain],{preChecked:{price:q.price,currency:q.currency}})}else h(),I("Register it:",`domani buy ${q.domain}`),h();else if(q.error)T.stop(`${D.default.dim("?")} ${x.domain(q.domain)} ${_.dot} ${D.default.dim("lookup failed")}`);else{let ie;try{if(Y?.ok){let ae=await Y.json();ae?.title&&(ie=ae.title)}}catch{}let z=ie?` ${_.dot} ${D.default.dim(`"${ie}"`)}`:"";T.stop(`${_.error} ${x.domain(q.domain)} ${_.dot} ${D.default.red("taken")}${z}`)}return}let o=e.split(".")[0];if(ke&&!i.json&&r.length>0){let T=new URLSearchParams;T.set("domains",r.map(W=>`${o}.${W}`).join(",")),i.maxPrice&&T.set("max_price",i.maxPrice);let J=await he(`/api/domains/search?${T}`,{headers:{Accept:"text/event-stream"}});if(!J.ok||!J.body){g("Search failed",{json:i.json});return}let Y=[],q=new TextDecoder,ie="",z="",ae=j(!0);ae.start(`Checking ${r.length} TLD${r.length>1?"s":""}`);for await(let W of J.body){ie+=q.decode(W,{stream:!0});let pe=ie.split(`
189
+ `);ie=pe.pop()??"";for(let Ye of pe)Ye.startsWith("event: ")?z=Ye.slice(7):Ye.startsWith("data: ")&&z==="result"&&Y.push(JSON.parse(Ye.slice(6)))}ae.stop("");let L=Math.max(...r.map(W=>`${o}.${W}`.length))+2,B=Y.filter(W=>W.available),ce=Y.filter(W=>!W.available&&!W.error);for(let W of[...B,...ce])W.available?console.log(` ${D.default.green("\u2713")} ${D.default.bold(D.default.white(W.domain.padEnd(L)))} ${D.default.green(x.price(W.price)+"/yr")}`):console.log(` ${D.default.dim("\u2717")} ${D.default.dim(W.domain.padEnd(L))} ${D.default.dim("taken")}`);if(B.length===0){console.log(` ${D.default.dim("No domains available")}`),h();return}let{buy:ue}=await Promise.resolve().then(()=>(Jt(),Ci));if(B.length===1){await ue([B[0].domain],{preChecked:{price:B[0].price,currency:B[0].currency}});return}let{select:je,isCancel:Ve}=await Promise.resolve().then(()=>(Oe(),Ps)),me=await je({message:"Register one?",options:[...B.map(W=>({value:W.domain,label:x.domain(W.domain),hint:x.price(W.price)+"/yr"})),{value:"__skip__",label:"Skip"}]});if(!Ve(me)&&me!=="__skip__"){h();let W=B.find(pe=>pe.domain===me);await ue([me],{preChecked:W?{price:W.price,currency:W.currency}:void 0})}else h();return}if(ke&&!i.json){let T=await _r();for(;;){let J=i.expand?T:T.slice(0,De),Y=new URLSearchParams;Y.set("domains",J.map(Ve=>`${o}.${Ve}`).join(",")),i.maxPrice&&Y.set("max_price",i.maxPrice);let q=j(!0);q.start(`Searching available domains for ${D.default.bold(o)}`);let ie=await he(`/api/domains/search?${Y}`,{headers:{Accept:"text/event-stream"}});if(!ie.ok||!ie.body){q.stop("Search failed");break}q.stop("");let z=!i.expand,{chosen:ae,chosenResult:L,searchAgain:B}=await fl(ie.body,o,i.all??!1,z,T);if(ae){h();let{buy:Ve}=await Promise.resolve().then(()=>(Jt(),Ci)),me=L?{price:L.price,currency:L.currency}:void 0;await Ve([ae],{preChecked:me});return}if(!B)break;let{text:ce,isCancel:ue}=await Promise.resolve().then(()=>(Oe(),Ps)),je=await ce({message:"Search for a domain",placeholder:"e.g. myapp or myapp.dev"});if(ue(je)||!je)break;o=je.split(".")[0]}h();return}let a=o,l=await _r(),u=(r.length>0?r:i.expand?l:l.slice(0,De)).map(T=>`${a}.${T}`),f=new URLSearchParams;f.set("domains",u.join(",")),i.maxPrice&&f.set("max_price",i.maxPrice);let p=j(!i.json);p.start(`Searching available domains for ${D.default.bold(a)}`);let v=await he(`/api/domains/search?${f}`,{headers:{Accept:"text/event-stream"}});if(!v.ok){p.stop("Search failed");try{let T=await v.json();g(T.error||T.message||`Server error (${v.status})`,{hint:T.hint,status:v.status,json:i.json,fields:i.fields})}catch{g(`Server error (${v.status})`,{status:v.status,json:i.json,fields:i.fields})}}let $=v.body;$||(p.stop("Search failed"),g("Empty response",{code:"error",json:i.json,fields:i.fields}));let m=[],y=!1,w=0,S=i.all??!1;function A(){y||(y=!0,p.stop(`Checking TLDs for ${D.default.bold(a)}`),h())}function F(T){A(),T.available?console.log(` ${_.success} ${x.domain(T.domain).padEnd(37)} ${x.price(T.price)}${D.default.dim("/yr")}`):T.error||console.log(` ${_.error} ${D.default.dim(T.domain.padEnd(38))} ${D.default.red("taken")}`)}function N(){y||p.message(`Checking TLDs for ${D.default.bold(a)} ${D.default.dim(`(${w} checked)`)}`)}let H=new TextDecoder,R="",P="";for await(let T of $){R+=H.decode(T,{stream:!0});let J=R.split(`
190
+ `);R=J.pop()??"";for(let Y of J)if(Y.startsWith("event: "))P=Y.slice(7);else if(Y.startsWith("data: ")){let q=JSON.parse(Y.slice(6));if(P==="result")w++,q.available||S?(i.json||F(q),m.push(q)):i.json||N();else if(P==="done"){if(i.json){m.sort((L,B)=>L.price-B.price),k({name:a,results:m,total:q.total,available:q.available},i.fields);return}y&&console.log(` ${D.default.dim("\u2500".repeat(50))}`);let ie=q.total-q.available,z=q.total>=5&&ie/q.total>=.5,ae=`Checked ${q.total} TLDs \xB7 ${q.available} available${z?" \xB7 popular name":""}`;console.log(` ${D.default.dim(ae)}`),q.available===0&&!i.expand&&r.length===0&&(h(),I("Try more TLDs:",`domani search ${a} --expand`))}}}h()}Jt();ne();var it=M(Z(),1);X();async function kr(e){let t=j(!e.json);t.start("Loading domains");let i=await C("/api/domains"),s=await i.json();if(i.ok||(t.stop("Failed"),g(s.error||s.message,{hint:s.hint,status:i.status,json:e.json,fields:e.fields})),t.stop(`${s.domains.length} domain(s)`),e.json){k({...s,count:s.domains.length},e.fields);return}if(s.domains.length===0){h(),console.log(` ${it.default.dim("No domains yet.")} Use: ${it.default.cyan("domani buy <domain>")}`),h();return}let n=[30,12,12,14];E(`Your Domains (${s.domains.length})`,n.reduce((o,a)=>o+a,0)+n.length-1);let r=s.domains.map(o=>{let a=new Date(o.expiresAt).toLocaleDateString(),l=o.status==="active"?it.default.green:o.status==="pending"?it.default.yellow:it.default.red,c=o.autoRenew?it.default.green("on"):it.default.dim("off");return[x.domain(o.domain),l(o.status),c,it.default.dim(a)]});ge(["Domain","Status","Auto-renew","Expires"],r,n),h()}Hs();ne();var wt=M(Z(),1);X();async function Sr(e){let t=new URLSearchParams;e.maxPrice&&t.set("max_price",e.maxPrice),e.minPrice&&t.set("min_price",e.minPrice),e.sort&&t.set("sort",e.sort),e.search&&t.set("search",e.search),e.limit&&t.set("limit",e.limit),t.set("order","asc");let i=j(!e.json);i.start("Loading TLDs");let s=await he(`/api/tlds?${t}`),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${n.total} TLDs loaded`),e.json){k(n,e.fields);return}let r=n.tlds;if(r.length===0){h(),console.log(` ${wt.default.dim("No TLDs match your filters.")}`),h();return}E("TLD Pricing");let o=r.map(a=>[wt.default.bold(`.${a.tld}`),x.price(a.registration.toFixed(2))+wt.default.dim("/yr"),wt.default.dim("renew ")+x.price(a.renewal.toFixed(2))+wt.default.dim("/yr")]);ge(["TLD","Register","Renewal"],o,[22,16,20]),h(),console.log(` ${wt.default.dim(`${n.total} TLDs total`)}`),h()}ne();var we=M(Z(),1);X();ye();async function jr(e,t){Q(e,t);let i=j(!t.json);i.start(`Looking up ${x.domain(e)}`);let[s,n]=await Promise.all([he(`/api/domains/whois?q=${encodeURIComponent(e)}`),he(`/api/domains/${encodeURIComponent(e)}/og`).catch(()=>null)]),r=await s.json(),o=null;try{n?.ok&&(o=await n.json())}catch{}if(s.ok||(i.stop("Lookup failed"),g(r.error||r.message,{hint:r.hint,status:s.status,json:t.json,fields:t.fields})),i.stop("WHOIS data retrieved"),t.json){k({...r,...o?{og:o}:{}},t.fields);return}if(E(`WHOIS ${x.domain(r.domain)}`),!r.registered){b("Status",`${_.success} ${we.default.green("not registered")}`),h(),I("Register it:",`domani buy ${r.domain}`),h();return}if(b("Status",`${_.error} ${we.default.red("registered")}`),(o?.title||o?.description)&&(h(),console.log(` ${we.default.bold("Website preview")}`),console.log(` ${we.default.dim("\u2500".repeat(50))}`),o.title&&b("Title",o.title),o.description&&b("Description",we.default.dim(o.description.length>80?o.description.slice(0,80)+"\u2026":o.description)),h()),r.registrar&&b("Registrar",r.registrar),r.created&&b("Created",r.created),r.expires&&b("Expires",r.expires),r.days_until_expiry!=null){let l=r.days_until_expiry,c=l<30?we.default.red:l<90?we.default.yellow:we.default.green;b("Days left",c(String(l)))}r.updated&&b("Updated",r.updated),b("DNSSEC",r.dnssec?we.default.green("yes"):we.default.dim("no")),r.nameservers?.length>0&&b("Nameservers",r.nameservers.map(l=>we.default.cyan(l)).join(we.default.dim(", "))),r.status?.length>0&&b("Status codes",we.default.dim(r.status.join(", ")));let a=r.contacts?.registrant;a&&!r.redacted?(h(),console.log(` ${we.default.bold("Registrant")}`),console.log(` ${we.default.dim("\u2500".repeat(50))}`),a.name&&b("Name",a.name),a.organization&&b("Organization",a.organization),a.email&&b("Email",x.url(a.email)),a.country&&b("Country",a.country)):r.redacted&&b("Contact",we.default.dim("redacted (WHOIS privacy)")),h()}ne();Oe();var st=M(Z(),1);X();ye();async function Cr(e,t){if(!e){ke||g("Missing required argument: prompt",{hint:'Usage: domani suggest "describe your project"',code:"missing_argument",json:t.json});let m=await Re({message:"Describe your project or idea",placeholder:"e.g. AI coding assistant, pet food delivery..."});(oe(m)||!m)&&process.exit(0),e=m}let i=new URLSearchParams({prompt:e});if(t.count&&i.set("count",t.count),t.tlds&&i.set("tlds",t.tlds),t.tlds&&Si(t.tlds.split(",").map(m=>m.trim()),t),t.style&&i.set("style",t.style),t.lang&&i.set("lang",t.lang),t.json){let m=j(!1);m.start("Finding available domains");let y=t.timeout?parseInt(t.timeout,10)*1e3:6e4,w;try{w=await he(`/api/domains/suggest?${i}`,{signal:AbortSignal.timeout(y)})}catch{m.stop("Failed"),g("Request timed out",{hint:"Suggest took too long. Try --timeout <seconds> to increase.",code:"timeout",json:t.json,fields:t.fields})}let S=await w.json();w.ok||(m.stop("Failed"),g(S.error||S.message,{hint:S.hint,status:w.status,json:t.json,fields:t.fields})),k(S,t.fields);return}let s=j(!0);s.start("Finding available domains");let n=t.timeout?parseInt(t.timeout,10)*1e3:6e4,r;try{r=await he(`/api/domains/suggest?${i}`,{headers:{Accept:"text/event-stream"},signal:AbortSignal.timeout(n)})}catch{s.stop("Failed"),g("Request timed out",{hint:"Suggest took too long. Try --timeout <seconds> to increase.",code:"timeout"})}if(!r.ok){s.stop("Failed");try{let m=await r.json();g(m.error||m.message||`Server error (${r.status})`,{hint:m.hint,status:r.status})}catch{g(`Server error (${r.status})`,{status:r.status})}}let o=r.body;o||(s.stop("Failed"),g("Empty response"));let a=[],l=[],c=!1,u=0;function f(){c||(c=!0,s.stop("Finding available domains"),h())}let p=new TextDecoder,v="",$="";for await(let m of o){v+=p.decode(m,{stream:!0});let y=v.split(`
191
+ `);v=y.pop()??"";for(let w of y)if(w.startsWith("event: "))$=w.slice(7);else if(w.startsWith("data: "))try{let S=JSON.parse(w.slice(6));if($==="result")u++,S.available?a.push(S):l.push(S),c||s.message(`Finding available domains ${st.default.dim(`(${u} checked, ${a.length} available)`)}`);else if($==="iteration")c||s.message(`Finding available domains ${st.default.dim(`(round ${S.n})`)}`);else if($==="done"){f();for(let A of a){let F=A.reason?` ${st.default.dim(A.reason)}`:"";console.log(` ${_.success} ${x.domain(A.domain).padEnd(37)} ${x.price(A.price)}${st.default.dim("/yr")}${F}`)}for(let A of l)console.log(` ${_.error} ${st.default.dim(A.domain.padEnd(38))} ${st.default.red("taken")}`);console.log(` ${st.default.dim("\u2500".repeat(50))}`),console.log(` ${st.default.dim(`Found ${S.total} available \xB7 checked ${S.checked} \xB7 ${S.iterations} round${S.iterations>1?"s":""}`)}`)}else $==="error"&&(c||s.stop("Failed"),g(S.message))}catch{}}a.length===0&&l.length===0&&(c||s.stop("No results"),g("Could not find available domains for this prompt.")),h(),a.length>0&&(I("Register one:",`domani buy ${a[0].domain}`),h())}Ms();Bs();ne();Oe();var Et=M(Z(),1);X();ye();ei();async function Or(e,t){if(Q(e,t),!t.authCode){(t.json||!process.stdout.isTTY)&&g("--auth-code is required",{hint:"Get the EPP/auth code from your current registrar.",code:"validation_error",json:t.json,fields:t.fields});let a=await Re({message:"Enter the EPP/auth code from your current registrar:",validate:l=>!l||l.trim().length===0?"Auth code is required":void 0});oe(a)&&process.exit(0),t.authCode=a}let i=j(!t.json);i.start(`Checking transfer eligibility for ${x.domain(e)}`);let s=await C(`/api/domains/transfer-check?domain=${encodeURIComponent(e)}`),n=await s.json();if(s.ok||(i.stop("Check failed"),g(n.error,{hint:n.hint,status:s.status,json:t.json,fields:t.fields})),n.eligible||(i.stop(`${_.error} Not eligible`),g(n.reason||"Domain is not eligible for transfer.",{hint:n.hint,code:"not_eligible",json:t.json,fields:t.fields})),i.stop(`${_.success} Eligible for transfer`),t.dryRun)return G("transfer",{domain:e,eligible:!0,price:n.price,currency:n.currency||"USD",includes_renewal:!0},t.json,t.fields);if(!bt(t)){let a=n.price!=null?` for ${x.price(n.price.toFixed(2))}`:"",l=await Ue({message:`Transfer ${Et.default.bold(e)} to ${kt}${a}? (includes 1 year renewal)`});if(!l||typeof l=="symbol"){console.log(` ${Et.default.dim("Cancelled.")}`);return}}i.start(`Initiating transfer for ${x.domain(e)}`);let r=await C("/api/domains/transfer",{method:"POST",body:JSON.stringify({domain:e,auth_code:t.authCode})}),o=await r.json();if(r.ok||(i.stop("Transfer failed"),g(o.error||o.message,{hint:o.hint,fixUrl:o.setup_url||o.payment_options?.card?.setup_url,status:r.status,json:t.json,fields:t.fields})),i.stop(`${_.success} Transfer initiated`),t.json){k(o,t.fields);return}E("Transfer Initiated"),b("Domain",x.domain(o.domain)),b("Status",Et.default.yellow(o.status||"pending")),o.price&&b("Price",x.price(o.price)+Et.default.dim(` ${o.currency||"USD"}`)),o.payment_method&&b("Payment",o.payment_method),o.expires&&b("Expires",new Date(o.expires).toLocaleDateString()),o.hint&&(h(),console.log(` ${Et.default.dim(o.hint)}`)),h(),I("Check transfer progress:",`domani status ${o.domain}`),h()}ne();Oe();var Ri=M(Z(),1);X();ye();Le();async function Ar(e,t){e||(e=await de()),Q(e,t);let i=t.years?parseInt(t.years,10):1;if((isNaN(i)||i<1||i>10)&&g("--years must be between 1 and 10",{code:"validation_error",json:t.json,fields:t.fields}),t.dryRun)return G("renew",{domain:e,years:i},t.json,t.fields);if(!bt(t)){let o=await Ue({message:`Renew ${Ri.default.bold(e)} for ${i} year${i>1?"s":""}? You will be charged.`});if(!o||typeof o=="symbol"){console.log(` ${Ri.default.dim("Cancelled.")}`);return}}let s=j(!t.json);s.start(`Renewing ${x.domain(e)}`);let n=await C(`/api/domains/${encodeURIComponent(e)}/renew`,{method:"POST",body:JSON.stringify({years:i})}),r=await n.json();if(n.ok||(s.stop("Renewal failed"),g(r.error||r.message,{hint:r.hint,fixUrl:r.setup_url||r.payment_options?.card?.setup_url,status:n.status,json:t.json,fields:t.fields})),s.stop(`${_.success} Domain renewed`),t.json){k(r,t.fields);return}E("Renewal Complete"),b("Domain",x.domain(r.domain)),b("Years",String(r.renewed_years)),b("New expiry",new Date(r.new_expiry).toLocaleDateString()),r.price&&b("Price",x.price(r.price)+Ri.default.dim(` ${r.currency||"USD"}`)),r.payment_method&&b("Payment",r.payment_method),h(),I("Verify renewal:",`domani status ${r.domain}`),h()}ne();var ze=M(Z(),1);X();ye();async function Rr(e,t){e||g("Domain is required",{hint:`Usage: domani import <domain>
192
+ domani import <domain> --verify`,code:"validation_error",json:t.json,fields:t.fields}),Q(e,t);let i=t.verify?"/api/domains/import/verify":"/api/domains/import",s=j(!t.json);s.start(t.verify?`Verifying ownership of ${x.domain(e)}`:`Initiating import for ${x.domain(e)}`);let n=await C(i,{method:"POST",body:JSON.stringify({domain:e})}),r=await n.json();if(n.ok||(s.stop(t.verify?"Verification failed":"Import failed"),g(r.error||r.message,{hint:r.hint,status:n.status,json:t.json,fields:t.fields})),t.json){s.stop(""),k(r,t.fields);return}t.verify?(s.stop(`${_.success} ${x.domain(e)} imported!`),E("Domain Imported"),b("Domain",x.domain(r.domain)),b("Status",ze.default.green(r.status||"active")),r.expires_at&&b("Expires",new Date(r.expires_at).toLocaleDateString()),r.registrar&&b("Registrar",r.registrar),h(),I("Check domain health:",`domani status ${r.domain}`),h()):(s.stop(`${_.success} Verification record ready`),E("Import Domain"),b("Domain",x.domain(r.domain)),b("Status",ze.default.yellow("pending verification")),h(),console.log(" Add this TXT record at your DNS provider:"),h(),console.log(` ${ze.default.dim("Type:")} ${ze.default.bold("TXT")}`),console.log(` ${ze.default.dim("Name:")} ${ze.default.bold(r.txt_record?.name||"@")}`),console.log(` ${ze.default.dim("Value:")} ${ze.default.bold(r.txt_record?.value||`domani-verify=${r.token}`)}`),h(),console.log(` ${ze.default.dim("DNS propagation may take a few minutes to 48 hours.")}`),h(),I("Once the record is set, verify:",`domani import ${e} --verify`),h())}Ls();ut();X();function Ir(e){let t=Tt();t||(h(),g("Not logged in",{hint:"Run 'domani login' first",code:"auth_required",json:e.json})),e.json?k({token:t}):console.log(t)}ne();var Ne=M(Z(),1);X();async function Er(e,t){switch(e){case void 0:case"list":return hl(t.json,t.fields);case"create":return pl(t);case"revoke":return gl(t);default:g(`Unknown action: ${e}`,{hint:"Actions: list, create, revoke",code:"validation_error",json:t.json,fields:t.fields})}}async function hl(e,t){let i=j(!e);i.start("Loading tokens");let s=await C("/api/tokens"),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e,fields:t})),i.stop(`${_.success} ${n.tokens.length} token(s)`),e){k(n,t);return}if(n.tokens.length===0){h(),console.log(` ${Ne.default.dim("No tokens.")}`),h(),I("Create one:",'domani tokens create --name "My App"'),h();return}h(),E("API Tokens");let r=n.tokens.map(o=>{let a;o.expired?a=Ne.default.red("Expired"):o.expiresAt?a=Ne.default.dim(`Expires ${new Date(o.expiresAt).toLocaleDateString()}`):a=Ne.default.dim("No expiration");let l=o.scopes.includes("*")?Ne.default.dim("all"):Ne.default.dim(o.scopes.join(", "));return[Ne.default.dim(o.id),Ne.default.bold(o.name),l,a]});ge(["ID","Name","Scopes","Expiration"],r,[28,16,32,20]),h()}async function pl(e){let t={};if(e.name&&(t.name=e.name),e.scopes&&(t.scopes=e.scopes.split(",").map(r=>r.trim())),e.expiresIn){let r=Number(e.expiresIn);(isNaN(r)||r<3600||r>31536e3)&&g("Invalid --expires-in value",{hint:"Must be between 3600 (1 hour) and 31536000 (1 year) seconds",code:"validation_error",json:e.json,fields:e.fields}),t.expires_in=r}let i=j(!e.json);i.start("Creating token");let s=await C("/api/tokens",{method:"POST",body:JSON.stringify(t)}),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${_.success} Token created`),e.json){k(n,e.fields);return}h(),E("Token Created"),b("ID",n.id),b("Name",n.name),b("Scopes",n.scopes?.includes("*")?"All (full access)":n.scopes?.join(", ")||"All"),b("Expires",n.expiresAt?new Date(n.expiresAt).toLocaleString():"Never"),h(),console.log(` ${Ne.default.yellow("!")} ${Ne.default.bold("Key:")} ${n.key}`),console.log(` ${Ne.default.dim("Save this key - it will not be shown again.")}`),h()}async function gl(e){e.tokenId||g("Token ID required",{hint:`Usage: domani tokens revoke --token-id <id>
193
+ Run 'domani tokens list' to see your tokens.`,code:"validation_error",json:e.json,fields:e.fields});let t=j(!e.json);t.start("Revoking token");let i=await C(`/api/tokens/${encodeURIComponent(e.tokenId)}`,{method:"DELETE"}),s=await i.json();if(i.ok||(t.stop("Failed"),g(s.error||s.message,{hint:s.hint,status:i.status,json:e.json,fields:e.fields})),t.stop(`${_.success} Token revoked`),e.json){k(s,e.fields);return}console.log(` ${Ne.default.dim("Any applications using this key will need a new one.")}`),h()}ne();var _e=M(Z(),1);X();ye();Le();async function Pr(e,t){e||(e=await de()),Q(e,t);let i=t.autoRenew!==void 0,s=t.whoisPrivacy!==void 0,n=t.securityLock!==void 0;if(!i&&!s&&!n)return $l(e,t.json,t.fields);let r={};if(i){let c=Ks(t.autoRenew);c===null&&g("--auto-renew must be on or off",{code:"validation_error",json:t.json,fields:t.fields}),r.auto_renew=c}if(s){let c=Ks(t.whoisPrivacy);c===null&&g("--whois-privacy must be on or off",{code:"validation_error",json:t.json,fields:t.fields}),r.whois_privacy=c}if(n){let c=Ks(t.securityLock);c===null&&g("--security-lock must be on or off",{code:"validation_error",json:t.json,fields:t.fields}),r.security_lock=c}if(t.dryRun)return G("settings_update",{domain:e,...r},t.json,t.fields);let o=j(!t.json);o.start(`Updating ${x.domain(e)}`);let a=await C(`/api/domains/${encodeURIComponent(e)}/settings`,{method:"PUT",body:JSON.stringify(r)}),l=await a.json();if(a.ok||(o.stop("Failed"),g(l.error||l.message,{hint:l.hint,status:a.status,json:t.json,fields:t.fields})),o.stop(`${_.success} Settings updated`),t.json){k(l,t.fields);return}E("Settings Updated"),b("Domain",x.domain(l.domain)),l.auto_renew!==void 0&&b("Auto-renew",l.auto_renew?_e.default.green("on"):_e.default.dim("off")),l.whois_privacy!==void 0&&b("WHOIS privacy",l.whois_privacy?_e.default.green("on"):_e.default.dim("off")),l.security_lock!==void 0&&b("Security lock",l.security_lock?_e.default.green("locked"):_e.default.dim("unlocked")),l.hint&&b("",_e.default.dim(l.hint)),h()}async function $l(e,t,i){let s=j(!t);s.start(`Loading ${x.domain(e)}`);let n=await C(`/api/domains/${encodeURIComponent(e)}`),r=await n.json();if(n.ok||(s.stop("Failed"),g(r.error||r.message,{hint:r.hint,status:n.status,json:t,fields:i})),s.stop(`${_.success} ${x.domain(e)}`),t){k(r,i);return}E("Domain Settings"),b("Domain",x.domain(r.domain)),b("Status",r.status==="active"?_e.default.green(r.status):_e.default.yellow(r.status)),b("Auto-renew",r.auto_renew?_e.default.green("on"):_e.default.dim("off")),r.registrar&&(b("WHOIS privacy",r.registrar.whois_privacy?_e.default.green("on"):_e.default.dim("off")),b("Security lock",r.registrar.security_lock?_e.default.green("locked"):_e.default.dim("unlocked"))),b("Expires",new Date(r.expires_at).toLocaleDateString()+_e.default.dim(` (${r.days_until_expiry} days)`)),h(),I("Toggle auto-renew:",`domani settings ${e} --auto-renew off`),I("Toggle WHOIS privacy:",`domani settings ${e} --whois-privacy off`),I("Toggle security lock:",`domani settings ${e} --security-lock off`),I("Get transfer auth code:",`domani auth-code ${e}`),h()}function Ks(e){let t=e.toLowerCase();return t==="on"||t==="true"||t==="1"||t==="enable"?!0:t==="off"||t==="false"||t==="0"||t==="disable"?!1:null}ne();var _t=M(Z(),1);X();ye();Le();async function Tr(e,t){e||(e=await de()),Q(e,t);let i=j(!t.json);i.start(`Getting auth code for ${x.domain(e)}`);let s=await C(`/api/domains/${encodeURIComponent(e)}/auth-code`),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:t.json,fields:t.fields})),i.stop(`${_.success} Auth code retrieved`),t.json){k(n,t.fields);return}if(E("Auth Code"),b("Domain",x.domain(n.domain)),b("Auth code",_t.default.bold(_t.default.green(n.auth_code))),n.was_unlocked&&b("",_t.default.yellow("Domain was automatically unlocked to allow transfer.")),n.hint&&(h(),console.log(` ${_t.default.dim(n.hint)}`)),n.next_steps?.length){h();for(let r of n.next_steps)console.log(` ${_t.default.dim("\u2192")} ${_t.default.dim(r)}`)}h(),I("Check transfer status:",`domani transfer-away ${e}`),I("Re-lock domain:",`domani settings ${e} --security-lock on`),h()}ne();var nt=M(Z(),1);X();ye();Le();var yl={none:nt.default.dim,pending:nt.default.yellow,approved:nt.default.yellow,completed:nt.default.green,rejected:nt.default.red,expired:nt.default.red};async function Dr(e,t){e||(e=await de()),Q(e,t);let i=j(!t.json);i.start(`Checking transfer status for ${x.domain(e)}`);let s=await C(`/api/domains/${encodeURIComponent(e)}/transfer-away`),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:t.json,fields:t.fields})),i.stop(`${_.success} ${x.domain(e)}`),t.json){k(n,t.fields);return}E("Transfer Away Status"),b("Domain",x.domain(n.domain));let r=yl[n.status]||nt.default.dim;b("Status",r(n.status)),n.gaining_registrar&&b("New registrar",n.gaining_registrar),n.request_date&&b("Requested",new Date(n.request_date).toLocaleDateString()),n.hint&&(h(),console.log(` ${nt.default.dim(n.hint)}`)),h(),n.status==="none"?I("Get auth code to start:",`domani auth-code ${e}`):n.status==="pending"||n.status==="approved"?I("Check again later:",`domani transfer-away ${e}`):n.status==="completed"?I("Search for a new domain:","domani search <name>"):(n.status==="rejected"||n.status==="expired")&&I("Retry with a new auth code:",`domani auth-code ${e}`),h()}ne();Oe();var Ii=M(Z(),1);X();async function Nr(e,t){return e==="set"?vl(t):bl(t)}async function bl(e){let t=j(!e.json);t.start("Loading contact info");let i=await C("/api/me/contact"),s=await i.json();if(i.ok||(t.stop("Failed"),g(s.error||s.message,{hint:s.hint,status:i.status,json:e.json,fields:e.fields})),t.stop(`${_.success} Contact info`),e.json){k(s,e.fields);return}if(E("Contact Info"),!s.has_contact){console.log(` ${_.warning} ${Ii.default.yellow("No contact info set.")} Run ${Ii.default.bold("domani contact set")} to add.`),h(),console.log(` ${Ii.default.dim("Contact info is required before purchasing domains.")}`),h();return}let n=s.contact;b("Name",`${n.first_name} ${n.last_name}`),n.org_name&&b("Organization",n.org_name),b("Address",n.address1),n.address2&&b("",n.address2),b("",`${n.city}, ${n.state} ${n.postal_code}`),b("Country",n.country),b("Phone",n.phone),b("Email",n.email),h()}async function vl(e){let t={},i=e.firstName||e.lastName||e.address1;if(!ke&&!i&&g("Missing required flags for contact set",{hint:"Usage: domani contact set --first-name John --last-name Doe --address1 '123 Main St' --city SF --state CA --postal-code 94105 --country US --phone +1.5551234567 --email john@example.com",code:"missing_argument",json:e.json}),i){let a=["firstName","lastName","address1","city","state","postalCode","country","phone","email"],l={firstName:"first_name",lastName:"last_name",orgName:"org_name",address1:"address1",address2:"address2",city:"city",state:"state",postalCode:"postal_code",country:"country",phone:"phone",email:"email"},c=a.filter(u=>!e[u]);c.length>0&&g(`Missing required flags: ${c.map(u=>`--${u.replace(/[A-Z]/g,f=>`-${f.toLowerCase()}`)}`).join(", ")}`,{code:"missing_argument",json:e.json});for(let[u,f]of Object.entries(l)){let p=e[u];p&&(t[f]=p)}}else{let a=await C("/api/me/contact"),c=(a.ok?await a.json():null)?.contact,u=[{key:"first_name",message:"First name",placeholder:"John",required:!0},{key:"last_name",message:"Last name",placeholder:"Doe",required:!0},{key:"org_name",message:"Organization (optional, press Enter to skip)",placeholder:"Acme Inc.",required:!1},{key:"address1",message:"Address line 1",placeholder:"123 Main St",required:!0},{key:"address2",message:"Address line 2 (optional)",placeholder:"Suite 100",required:!1},{key:"city",message:"City",placeholder:"San Francisco",required:!0},{key:"state",message:"State / Province",placeholder:"CA",required:!0},{key:"postal_code",message:"Postal / ZIP code",placeholder:"94105",required:!0},{key:"country",message:"Country code (ISO 3166-1 alpha-2)",placeholder:"US",required:!0},{key:"phone",message:"Phone (+CC.NUMBER)",placeholder:"+1.5551234567",required:!0},{key:"email",message:"Contact email",placeholder:"john@example.com",required:!0}];for(let f of u){let p=c?.[f.key]||"",v=await Re({message:f.message,placeholder:f.placeholder,defaultValue:p,validate:f.required?m=>m?.trim()?void 0:`${f.message} is required`:void 0});oe(v)&&process.exit(0);let $=v.trim();$&&(t[f.key]=$)}}if(e.dryRun)return G("contact_set",t,e.json,e.fields);let s=j(!e.json);s.start("Saving contact info");let n=await C("/api/me/contact",{method:"PUT",body:JSON.stringify(t)}),r=await n.json();if(n.ok||(s.stop("Failed"),g(r.error||r.message,{hint:r.hint,status:n.status,json:e.json,fields:e.fields})),s.stop(`${_.success} Contact info saved`),e.json){k(r,e.fields);return}E("Contact Saved");let o=r.contact;b("Name",`${o.first_name} ${o.last_name}`),o.org_name&&b("Organization",o.org_name),b("Address",o.address1),o.address2&&b("",o.address2),b("",`${o.city}, ${o.state} ${o.postal_code}`),b("Country",o.country),b("Phone",o.phone),b("Email",o.email),h(),I("Search for a domain:","domani search <name>"),h()}ne();var Se=M(Z(),1);X();ye();Le();async function Mr(e,t,i,s){if(e||(e=await de()),Q(e,s),!t)return wl(e,s.json,s.fields);switch(t){case"enable":case"on":return s.dryRun?G("parking_enable",{domain:e},s.json,s.fields):Fr(e,!0,s.json,s.fields);case"disable":case"off":return s.dryRun?G("parking_disable",{domain:e},s.json,s.fields):Fr(e,!1,s.json,s.fields);case"price":{i||g("Price required",{hint:"Usage: domani parking <domain> price <amount>",code:"validation_error",json:s.json,fields:s.fields});let n=parseFloat(i);return(isNaN(n)||n<=0)&&g("Price must be a positive number",{hint:`Got: "${i}"`,code:"validation_error",json:s.json,fields:s.fields}),s.dryRun?G("parking_price",{domain:e,price:n},s.json,s.fields):Vr(e,n,s.json,s.fields)}case"unprice":case"unlist":return s.dryRun?G("parking_unlist",{domain:e},s.json,s.fields):Vr(e,null,s.json,s.fields);default:g(`Unknown action: ${t}`,{hint:"Actions: enable, disable, price <amount>, unprice",code:"validation_error",json:s.json,fields:s.fields})}}async function wl(e,t,i){let s=j(!t);s.start(`Loading ${x.domain(e)}`);let n=await C(`/api/domains/${encodeURIComponent(e)}`),r=await n.json();if(n.ok||(s.stop("Failed"),g(r.error||r.message,{hint:r.hint,status:n.status,json:t,fields:i})),s.stop(`${_.success} ${x.domain(e)}`),t){k({domain:r.domain,parking_enabled:r.parking_enabled,listing_price:r.listing_price},i);return}E("Parking"),b("Domain",x.domain(r.domain)),b("Parking",r.parking_enabled?Se.default.green("enabled"):Se.default.dim("disabled")),b("Listing",r.listing_price?`${x.price(r.listing_price)} ${Se.default.dim("(for sale)")}`:Se.default.dim("not listed")),h(),I("Enable parking:",`domani parking ${e} enable`),I("Set sale price:",`domani parking ${e} price 499`),I("View analytics:",`domani analytics ${e}`),h()}async function Fr(e,t,i,s){let n=j(!i);n.start(`${t?"Enabling":"Disabling"} parking for ${x.domain(e)}`);let r=await C(`/api/domains/${encodeURIComponent(e)}/parking`,{method:"PUT",body:JSON.stringify({enabled:t})}),o=await r.json();if(r.status===409&&o.requires_confirmation){if(n.stop(`${_.warning} DNS records will be replaced`),i){k(o,s);return}console.log(`
194
+ ${Se.default.yellow("Enabling parking will replace these DNS records:")}`);for(let a of o.existing_dns||[])console.log(` ${Se.default.dim(a.type)} ${a.name} ${Se.default.dim("\u2192")} ${a.value}`);console.log(`
195
+ ${Se.default.dim("Run again with --confirm to proceed (not implemented yet).")}`),console.log(` ${Se.default.dim("Or use the dashboard to confirm.")}`),h();return}if(r.ok||(n.stop("Failed"),g(o.error||o.message,{hint:o.hint,status:r.status,json:i,fields:s})),n.stop(`${_.success} Parking ${t?"enabled":"disabled"}`),i){k(o,s);return}E("Parking Updated"),b("Domain",x.domain(o.domain)),b("Parking",o.parking_enabled?Se.default.green("enabled"):Se.default.dim("disabled")),o.hint&&b("",Se.default.dim(o.hint)),h()}async function Vr(e,t,i,s){let n=j(!i);n.start(t!==null?`Setting price for ${x.domain(e)} to ${x.price(t)}`:`Removing listing for ${x.domain(e)}`);let r=await C(`/api/domains/${encodeURIComponent(e)}/parking`,{method:"PUT",body:JSON.stringify({listing_price:t})}),o=await r.json();if(r.ok||(n.stop("Failed"),g(o.error||o.message,{hint:o.hint,status:r.status,json:i,fields:s})),n.stop(`${_.success} ${t!==null?"Price set":"Listing removed"}`),i){k(o,s);return}E("Listing Updated"),b("Domain",x.domain(o.domain)),b("Listing",o.listing_price?`${x.price(o.listing_price)} ${Se.default.dim("(for sale)")}`:Se.default.dim("not listed")),o.hint&&b("",Se.default.dim(o.hint)),h()}ne();var Fe=M(Z(),1);X();ye();Le();var _l=" \u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function xl(e){let t=Math.max(...e,1);return e.map(i=>_l[Math.min(Math.round(i/t*8),8)]).join("")}async function Ur(e,t){e||(e=await de()),Q(e,t);let i=j(!t.json);i.start(`Loading analytics for ${x.domain(e)}`);let s=await C(`/api/domains/${encodeURIComponent(e)}/analytics`),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:t.json,fields:t.fields})),i.stop("Analytics loaded"),t.json){k(n,t.fields);return}if(h(),E(`Analytics: ${x.domain(e)}`),b("Views (7d)",Fe.default.cyan(n.views_7d.toLocaleString())),b("Views (30d)",Fe.default.cyan(n.views_30d.toLocaleString())),b("Inquiries",Fe.default.cyan(String(n.inquiries_30d))),b("Conversion",n.conversion_rate>0?Fe.default.green(`${n.conversion_rate}%`):Fe.default.dim("0%")),n.daily_views&&n.daily_views.length>0){let r=n.daily_views.map(c=>c.views),o=xl(r),a=n.daily_views[0].date.slice(5),l=n.daily_views[n.daily_views.length-1].date.slice(5);h(),console.log(` ${Fe.default.dim(a)} ${Fe.default.cyan(o)} ${Fe.default.dim(l)}`)}if(n.recent_inquiries&&n.recent_inquiries.length>0){h(),console.log(` ${Fe.default.bold("Recent Inquiries")}`);let r=n.recent_inquiries.map(o=>[Fe.default.dim(o.email),o.offer?x.price(o.offer):Fe.default.dim("-"),Fe.default.dim(new Date(o.date).toLocaleDateString())]);ge(["Email","Offer","Date"],r,[30,12,14])}h(),I("Set a listing price:",`domani parking ${e} price <amount>`),I("Set up email:",`domani email setup ${e}`),I("Domain settings:",`domani settings ${e}`),h()}ne();var fe=M(Z(),1);X();async function Lr(e,t){switch(e){case void 0:case"list":return kl(t.json,t.fields);case"create":return Sl(t);case"update":return jl(t);case"delete":return Cl(t);case"deliveries":return Ol(t);case"events":return Al(t.json,t.fields);default:g(`Unknown action: ${e}`,{hint:"Actions: list, create, update, delete, deliveries, events",code:"validation_error",json:t.json,fields:t.fields})}}async function kl(e,t){let i=j(!e);i.start("Loading webhooks");let s=await C("/api/webhooks"),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e,fields:t})),i.stop(`${_.success} ${n.webhooks.length} webhook(s)`),e){k(n,t);return}if(n.webhooks.length===0){h(),console.log(` ${fe.default.dim("No webhooks configured.")}`),h(),I("Create one:","domani webhooks create --url https://... --events domain.purchased,dns.updated"),I("List events:","domani webhooks events"),h();return}h(),E("Webhooks");let r=n.webhooks.map(o=>[fe.default.dim(o.id),x.url(o.url),o.events.length<=3?o.events.join(", "):`${o.events.length} events`,o.active?fe.default.green("active"):fe.default.dim("paused")]);ge(["ID","URL","Events","Status"],r,[28,40,24,10]),h()}async function Sl(e){e.url||g("URL required",{hint:"Usage: domani webhooks create --url https://example.com/hook --events domain.purchased,dns.updated",code:"validation_error",json:e.json,fields:e.fields}),e.events||g("Events required",{hint:`Usage: domani webhooks create --url https://... --events domain.purchased,dns.updated
196
+ Run 'domani webhooks events' to see available event types.`,code:"validation_error",json:e.json,fields:e.fields});let t=e.events.split(",").map(r=>r.trim());if(e.dryRun)return G("webhook_create",{url:e.url,events:t},e.json,e.fields);let i=j(!e.json);i.start("Creating webhook");let s=await C("/api/webhooks",{method:"POST",body:JSON.stringify({url:e.url,events:t})}),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${_.success} Webhook created`),e.json){k(n,e.fields);return}h(),E("Webhook Created"),b("ID",n.id),b("URL",x.url(n.url)),b("Events",n.events.join(", ")),b("Status",fe.default.green("active")),h(),console.log(` ${fe.default.yellow("!")} ${fe.default.bold("Secret:")} ${n.secret}`),console.log(` ${fe.default.dim("Save this secret - it won't be shown again.")}`),console.log(` ${fe.default.dim("Use it to verify payloads with HMAC-SHA256.")}`),h()}async function jl(e){e.webhookId||g("Webhook ID required",{hint:"Usage: domani webhooks update --webhook-id <id> [--url ...] [--events ...] [--active on|off]",code:"validation_error",json:e.json,fields:e.fields});let t={};if(e.url&&(t.url=e.url),e.events&&(t.events=e.events.split(",").map(r=>r.trim())),e.active!==void 0&&(t.active=e.active==="on"||e.active==="true"),e.dryRun)return G("webhook_update",{webhook_id:e.webhookId,...t},e.json,e.fields);let i=j(!e.json);i.start("Updating webhook");let s=await C(`/api/webhooks/${encodeURIComponent(e.webhookId)}`,{method:"PATCH",body:JSON.stringify(t)}),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${_.success} Webhook updated`),e.json){k(n,e.fields);return}E("Webhook Updated"),b("ID",n.id),b("URL",x.url(n.url)),b("Events",n.events.join(", ")),b("Status",n.active?fe.default.green("active"):fe.default.dim("paused")),h()}async function Cl(e){if(e.webhookId||g("Webhook ID required",{hint:"Usage: domani webhooks delete --webhook-id <id>",code:"validation_error",json:e.json,fields:e.fields}),e.dryRun)return G("webhook_delete",{webhook_id:e.webhookId},e.json,e.fields);let t=j(!e.json);t.start("Deleting webhook");let i=await C(`/api/webhooks/${encodeURIComponent(e.webhookId)}`,{method:"DELETE"}),s=await i.json();if(i.ok||(t.stop("Failed"),g(s.error||s.message,{hint:s.hint,status:i.status,json:e.json,fields:e.fields})),t.stop(`${_.success} Webhook deleted`),e.json){k(s,e.fields);return}console.log(` ${fe.default.dim("Pending deliveries have been cancelled.")}`),h()}async function Ol(e){e.webhookId||g("Webhook ID required",{hint:"Usage: domani webhooks deliveries --webhook-id <id> [--limit 20]",code:"validation_error",json:e.json,fields:e.fields});let t=e.limit?`?limit=${e.limit}`:"",i=j(!e.json);i.start("Loading deliveries");let s=await C(`/api/webhooks/${encodeURIComponent(e.webhookId)}/deliveries${t}`),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e.json,fields:e.fields})),i.stop(`${_.success} ${n.deliveries.length} delivery(ies)`),e.json){k(n,e.fields);return}if(n.deliveries.length===0){h(),console.log(` ${fe.default.dim("No deliveries yet.")}`),h();return}h(),E("Deliveries");let r=n.deliveries.map(o=>{let a=o.status==="delivered"?fe.default.green("delivered"):o.status==="failed"?fe.default.red("failed"):fe.default.yellow("pending");return[o.event_type,a,o.http_status?String(o.http_status):fe.default.dim("-"),String(o.attempts),fe.default.dim(new Date(o.created_at).toLocaleString())]});ge(["Event","Status","HTTP","Tries","Date"],r,[22,12,6,6,22]),h()}async function Al(e,t){let i=j(!e);i.start("Loading event types");let s=await he("/api/webhooks/events"),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:e,fields:t})),i.stop(`${_.success} ${n.events.length} event type(s)`),e){k(n,t);return}h(),E("Webhook Event Types");let r=n.events.map(o=>[fe.default.cyan(o.type),fe.default.dim(o.description)]);ge(["Event","Description"],r,[24,50]),h()}ne();var ct=M(Z(),1);X();async function qr(e){let t=e.limit?Number(e.limit):20,i=await C(`/api/billing/invoices?limit=${t}`),s=await i.json();if(i.ok||g(s.error||s.message,{hint:s.hint,status:i.status,json:e.json,fields:e.fields}),e.json){k({...s,count:s.invoices.length},e.fields);return}if(s.invoices.length===0){console.log(` ${ct.default.dim("No invoices yet.")}`);return}E(`Invoices (${s.invoices.length})`),h();for(let n of s.invoices){let r=`$${(n.amount_paid/100).toFixed(2)}`,o=new Date(n.created).toLocaleDateString(),a=n.number||n.id;console.log(` ${_.success} ${ct.default.bold(a)} ${ct.default.green(r)} ${ct.default.dim(o)}`),n.description&&console.log(` ${ct.default.dim(n.description)}`),n.hosted_invoice_url&&console.log(` ${ct.default.dim(n.hosted_invoice_url)}`)}h(),s.has_more&&(console.log(` ${ct.default.dim(`Showing ${s.invoices.length} most recent. Use --limit to see more.`)}`),h())}ne();var Bt=M(Z(),1);X();async function Wr(e){let t=j(!e?.json);t.start("Setting up billing session");let i=await C("/api/billing/setup",{method:"POST",body:JSON.stringify({mode:"checkout"})}),s=await i.json();if(i.ok||(t.stop("Failed"),g(s.error||s.message,{hint:s.hint,status:i.status,json:e?.json})),s.url||(t.stop("Failed"),g("No checkout URL returned",{hint:"Try again or add a payment method at the dashboard.",json:e?.json})),t.stop("Checkout ready"),e?.json){k({url:s.url});return}h(),console.log(` ${Bt.default.dim("Opening browser")} ${_.arrow} ${x.url(s.url)}`),h(),Rt(s.url),console.log(` ${_.info} ${Bt.default.dim("Complete payment setup in your browser.")}`),console.log(` ${Bt.default.dim(" After setup, you can purchase domains with")} ${Bt.default.cyan("domani buy")}`),h()}ne();var Je=M(Z(),1);X();ye();Le();async function Hr(e,t,i){e||(e=await de()),Q(e,i);let s=[];if(t?.length&&s.push(...t),i.set&&s.push(...i.set.split(",").map(n=>n.trim()).filter(Boolean)),s.length>0||i.reset){await Il(e,s,i);return}await Rl(e,i)}async function Rl(e,t){let i=j(!t.json);i.start(`Fetching nameservers for ${x.domain(e)}`);let s=await C(`/api/domains/${encodeURIComponent(e)}/nameservers`),n=await s.json();if(s.ok||(i.stop("Failed"),g(n.error||n.message,{hint:n.hint,status:s.status,json:t.json,fields:t.fields})),i.stop(`Nameservers for ${x.domain(e)}`),t.json){k(n,t.fields);return}if(h(),n.nameservers.length===0)console.log(` ${_.warning} ${Je.default.yellow("No nameservers configured.")}`),console.log(` ${Je.default.dim("DNS operations (parking, email, connect) will not work.")}`),h(),I("Set default nameservers:",`domani nameservers ${e} --reset`);else{E("Nameservers");for(let r of n.nameservers)console.log(` ${_.success} ${Je.default.cyan(r)}`);n.default_nameservers&&n.nameservers.length===n.default_nameservers.length&&n.nameservers.every(o=>n.default_nameservers.includes(o))&&(h(),console.log(` ${Je.default.dim("Using default nameservers.")}`))}n.default_nameservers?.length&&(h(),b("Defaults",n.default_nameservers.map(r=>Je.default.dim(r)).join(Je.default.dim(", ")))),h()}async function Il(e,t,i){let s=j(!i.json);if(i.reset){s.start(`Fetching default nameservers for ${x.domain(e)}`);let o=await C(`/api/domains/${encodeURIComponent(e)}/nameservers`),a=await o.json();o.ok||(s.stop("Failed"),g(a.error,{hint:a.hint,status:o.status,json:i.json,fields:i.fields})),a.default_nameservers?.length||(s.stop("No defaults"),g("No default nameservers available for this domain's registrar.",{code:"not_found",json:i.json,fields:i.fields})),t=a.default_nameservers,s.stop(`Using defaults: ${t.map(l=>Je.default.cyan(l)).join(Je.default.dim(", "))}`)}if(t.length<2&&g("At least 2 nameservers required.",{hint:"Example: domani nameservers example.com ns1.dns.com ns2.dns.com",code:"validation_error",json:i.json,fields:i.fields}),i.dryRun)return G("nameservers_set",{domain:e,nameservers:t},i.json,i.fields);s.start(`Setting nameservers for ${x.domain(e)}`);let n=await C(`/api/domains/${encodeURIComponent(e)}/nameservers`,{method:"PUT",body:JSON.stringify({nameservers:t})}),r=await n.json();if(n.ok||(s.stop("Failed"),g(r.error||r.message,{hint:r.hint,status:n.status,json:i.json,fields:i.fields})),s.stop(`${_.success} Nameservers updated`),i.json){k(r,i.fields);return}h();for(let o of r.nameservers)console.log(` ${_.success} ${Je.default.cyan(o)}`);h(),console.log(` ${Je.default.dim("Changes may take up to 48 hours to propagate.")}`),h(),I("Check propagation:",`domani status ${e}`),h()}var Jr=require("crypto"),Ei=M(require("fs"),1);ut();var Gt=M(Z(),1);X();function El(e,t){let i=e.split(".").map(Number),s=t.split(".").map(Number);for(let n=0;n<3;n++){if((i[n]||0)>(s[n]||0))return 1;if((i[n]||0)<(s[n]||0))return-1}return 0}async function Br(e){let t=j(!e?.json);t.start("Checking for updates");let i=ot();try{let s=await fetch(`${i}/api/cli/version`);s.ok||(t.stop("Failed"),g("Could not check for updates"));let n=await s.json(),r=n.version,o=n.sha256;if(El(r,be)<=0){t.stop(`${_.success} Already up to date (v${be})`),e?.json&&k({current:be,latest:r,up_to_date:!0});return}if(e?.json){t.stop(""),k({current:be,latest:r,up_to_date:!1,hint:"Run `domani update` to upgrade."});return}t.stop(`New version available: ${Gt.default.cyan(be)} ${_.arrow} ${Gt.default.green(r)}`);let a=j();a.start("Downloading update");let l=`${i}/cli/domani.js`,c=await fetch(l);c.ok||(a.stop("Download failed"),g(`Failed to download from ${l}`));let u=await c.text();o&&(0,Jr.createHash)("sha256").update(u).digest("hex")!==o&&(a.stop("Integrity check failed"),g("Downloaded file does not match expected hash - update aborted"));let f=process.argv[1];f||(a.stop("Failed"),g("Could not determine binary path"));let p=Ei.default.realpathSync(f),v=p+".tmp";Ei.default.writeFileSync(v,u,{mode:493}),Ei.default.renameSync(v,p),a.stop(`${_.success} Updated to v${r}`),h(),console.log(` ${Gt.default.dim("Restart your terminal or run")} domani --version ${Gt.default.dim("to verify")}`),h()}catch(s){g(`Update failed: ${s instanceof Error?s.message:String(s)}`)}}var Pi=M(require("fs"),1),Gr=M(require("path"),1),zr=M(require("os"),1);Oe();var zt=M(Z(),1);X();async function Kr(){let e=process.argv[1],t=e?Pi.default.realpathSync(e):null,i=Gr.default.join(zr.default.homedir(),".domani");if(h(),console.log(` ${zt.default.bold("This will remove:")}`),t&&console.log(` ${_.dot} CLI binary: ${zt.default.dim(t)}`),console.log(` ${_.dot} Config dir: ${zt.default.dim(i)}`),h(),await Ue({message:"Uninstall domani?"})!==!0){console.log(` ${zt.default.dim("Cancelled.")}`);return}Pi.default.rmSync(i,{recursive:!0,force:!0}),t&&Pi.default.unlinkSync(t),h(),console.log(` ${_.success} domani uninstalled.`),h()}ne();var te=M(Z(),1);X();async function Zr(e,t){let i=t?.json,s=t?.fields,n=e?`/api/schema?command=${encodeURIComponent(e)}`:"/api/schema",r=j(!i);r.start("Loading schema");let o=await he(n),a=await o.json();if(o.ok||(r.stop("Failed"),g(a.error||a.message,{hint:a.hint,status:o.status,json:i,fields:s})),r.stop("Schema loaded"),i){k(a,s);return}e?Tl(e,a):Pl(a.commands)}function Pl(e){E("Commands");let t=Object.entries(e).map(([i,s])=>[te.default.bold(te.default.cyan(i)),s.description]);ge(["Command","Description"],t,[20,50]),h(),console.log(` ${te.default.dim("Run")} ${te.default.cyan("domani schema <command>")} ${te.default.dim("for full details")}`),h()}function Tl(e,t){if(E(`domani ${e}`),console.log(` ${t.description}`),h(),console.log(` ${x.label("Usage:")} ${te.default.cyan(t.usage)}`),t.arguments&&Object.keys(t.arguments).length>0){h(),console.log(` ${te.default.bold("Arguments")}`);for(let[i,s]of Object.entries(t.arguments)){let n=s.required?te.default.red("*"):"",r=te.default.dim(`(${s.type}${s.variadic?", variadic":""})`);console.log(` ${te.default.cyan(i)}${n} ${r}`),s.description&&console.log(` ${te.default.dim(s.description)}`)}}if(t.options&&Object.keys(t.options).length>0){h(),console.log(` ${te.default.bold("Options")}`);for(let[i,s]of Object.entries(t.options)){let n=s.required?te.default.red("*"):"",r=te.default.dim(`(${s.type})`),o=s.choices?te.default.dim(` [${s.choices.join(", ")}]`):"";console.log(` ${te.default.cyan(`--${i}`)}${n} ${r}${o}`),console.log(` ${te.default.dim(s.description)}`)}}if(t.api)if(h(),console.log(` ${te.default.bold("API")}`),Dl(t.api))Yr(t.api);else for(let[i,s]of Object.entries(t.api))console.log(` ${te.default.bold(te.default.yellow(i))}`),Yr(s,6);t.errors&&t.errors.length>0&&(h(),console.log(` ${te.default.bold("Errors")}`),console.log(` ${t.errors.map(i=>te.default.dim(i)).join(te.default.dim(", "))}`)),h()}function Dl(e){return typeof e=="object"&&e!==null&&"method"in e&&"path"in e}function Yr(e,t=4){let i=" ".repeat(t);if(console.log(`${i}${te.default.green(e.method)} ${te.default.white(e.path)}`),e.parameters&&Object.keys(e.parameters).length>0)for(let[s,n]of Object.entries(e.parameters)){let r=n.required?te.default.red("*"):"",o=[n.type];n.enum&&o.push(`enum: ${n.enum.join(", ")}`),n.minimum!==void 0&&o.push(`min: ${n.minimum}`),n.maximum!==void 0&&o.push(`max: ${n.maximum}`),n.maxItems!==void 0&&o.push(`maxItems: ${n.maxItems}`),n.items&&o.push(`items: ${n.items}`),n.in==="path"&&o.push("in: path");let a=te.default.dim(`(${o.join(", ")})`);console.log(`${i} ${te.default.cyan(s)}${r} ${a}`),n.description&&console.log(`${i} ${te.default.dim(n.description)}`)}}ne();var Ie=M(Z(),1);Oe();X();async function Xr(e){let t=j(!e.json);t.start("Loading payment method");let i=await C("/api/me"),s=await i.json();if(i.ok||(t.stop("Failed"),g(s.error||s.message,{hint:s.hint,status:i.status,json:e.json,fields:e.fields})),e.json){t.stop(""),k(s.card?{has_payment_method:s.has_payment_method,card:s.card}:{has_payment_method:!1},e.fields);return}if(!s.has_payment_method||!s.card){t.stop("No payment method on file"),h(),console.log(` ${Ie.default.dim("Add a card with")} ${Ie.default.cyan("domani card add")}`),h();return}let{brand:n,last4:r,exp_month:o,exp_year:a}=s.card,l=`${String(o).padStart(2,"0")}/${a}`,c=n.charAt(0).toUpperCase()+n.slice(1);t.stop("Payment method loaded"),E("Payment method"),b("Card",`${Ie.default.bold(c)} \u2022\u2022\u2022\u2022 ${Ie.default.bold(r)}`),b("Expires",l),h(),console.log(` ${Ie.default.dim("Update with")} ${Ie.default.cyan("domani card add")}`),h()}async function Qr(e){let t=j(!e?.json);t.start("Setting up payment session");let i=await C("/api/billing/setup",{method:"POST",body:JSON.stringify({mode:"checkout"})}),s=await i.json();if(i.ok||(t.stop("Failed"),g(s.error||s.message,{hint:s.hint,status:i.status,json:e?.json})),s.url||(t.stop("Failed"),g("No checkout URL returned",{json:e?.json})),t.stop("Checkout ready"),e?.json){k({url:s.url});return}h(),console.log(` ${Ie.default.dim("Opening browser")} ${_.arrow} ${x.url(s.url)}`),h(),Rt(s.url),console.log(` ${_.info} ${Ie.default.dim("Complete payment setup in your browser.")}`),console.log(` ${Ie.default.dim(" After setup, you can purchase domains with")} ${Ie.default.cyan("domani buy")}`),h()}async function eo(e){if(!e?.yes&&!e?.json){let n=await Ue({message:"Remove your saved payment method?"});(oe(n)||!n)&&(console.log(` ${Ie.default.dim("Cancelled.")}`),process.exit(0))}let t=j(!e?.json);t.start("Removing payment method");let i=await C("/api/billing/card",{method:"DELETE"}),s=await i.json();if(i.ok||(t.stop("Failed"),g(s.error||s.message,{hint:s.hint,status:i.status,json:e?.json})),t.stop(`${_.success} Payment method removed`),e?.json){k({removed:!0});return}h(),console.log(` ${Ie.default.dim("Add a new card with")} ${Ie.default.cyan("domani card add")}`),h()}var K=new dn;K.name("domani").description(`Domain names for developers and AI agents - ${kt}`).version(be).option("--api-url <url>","Override API base URL").configureOutput({outputError:(e,t)=>{let i=e.replace(/^error:\s*/i,"").trimEnd();if(t(`${Ke.default.red("\u2717")} ${i}
197
+ `),/unknown option|missing required|expected argument/i.test(i)){let s=process.argv[2],n=s&&!s.startsWith("-")?`domani ${s} --help`:"domani --help";t(`${Ke.default.dim(` Run \`${n}\` to see available options.`)}
198
+ `)}}}).hook("preAction",(e,t)=>{let i=e.opts();i.apiUrl&&gn(i.apiUrl),process.stdout.isTTY||t.options.some(n=>n.long==="--json")&&t.setOptionValue("json",!0)});K.command("login").description(`Log in to ${kt} (opens browser)`).option("--json","Output as JSON (returns auth_url for non-interactive approval)").action(nr);K.command("logout").description("Clear saved credentials").option("--json","Output as JSON").action(rr);K.command("me").description("Show account info").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(ar);K.command("invoices").description("List payment invoices").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").option("--limit <n>","Max invoices to show (default 20)").action(qr);K.command("card [action]").description("Manage payment methods (list, add, remove)").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").option("--yes","Skip confirmation prompt (for remove)").action(async(e,t)=>{if(!e||e==="list")return Xr(t);if(e==="add")return Qr(t);if(e==="remove")return eo(t);fail(`Unknown action: ${e}`,{hint:"Use: domani card list, domani card add, or domani card remove"})});K.command("billing",{hidden:!0}).option("--json","Output as JSON (returns checkout URL)").action(Wr);K.command("token").description("Print your API key").option("--json","Output as JSON").action(Ir);K.command("tokens [action]").description("Manage API tokens (list/create/revoke)").option("--name <name>","Token name (for create)").option("--scopes <scopes>","Comma-separated permission scopes (for create)").option("--expires-in <seconds>","Token lifetime in seconds (for create, min 3600)").option("--token-id <id>","Token ID (for revoke)").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Er);K.command("search [domain] [tlds...]").description("Check availability - domani search myapp .io .fm .xyz").option("--tlds <tlds>","Comma-separated TLDs (e.g. com,io,dev)").option("--max-price <price>","Maximum price filter").option("--all","Show taken domains too").option("--expand","Check 30+ TLDs including creative/exotic extensions").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(xr);K.command("tlds").description("List all TLDs with pricing").option("--max-price <price>","Maximum registration price").option("--min-price <price>","Minimum registration price").option("--sort <field>","Sort by: price, tld, renewal (default: tld)").option("--search <term>","Filter TLDs by name").option("--limit <n>","Limit results").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Sr);K.command("whois <domain>").description("WHOIS/RDAP lookup for any domain").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(jr);K.command("suggest [prompt]").description("AI-powered domain name suggestions").option("--count <n>","Number of suggestions (1-20, default 10)").option("--tlds <tlds>","Preferred TLDs, comma-separated (e.g. com,dev,ai)").option("--style <style>","Name style: single, creative, short, brandable, keyword").option("--lang <lang>","Language inspiration: japanese, spanish, french, italian, latin, nordic, arabic, sanskrit").option("--timeout <seconds>","Request timeout in seconds (default: 60)").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Cr);K.command("buy [domains...]").description("Purchase one or more domains").option("--yes","Skip confirmation prompt").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(zs);K.command("transfer <domain>").description("Transfer a domain from another registrar").option("--auth-code <code>","EPP/auth code from current registrar").option("--yes","Skip confirmation prompt").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Or);K.command("renew [domain]").description("Renew a domain").option("--years <n>","Number of years (1-10, default: 1)").option("--yes","Skip confirmation prompt").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Ar);K.command("import <domain>").description("Import a domain you own at another registrar").option("--verify","Verify DNS ownership and complete import").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Rr);K.command("list").description("List your domains").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(kr);K.command("status [domain]").description("Check domain health (DNS, SSL, email, expiry)").option("--timeout <seconds>","Request timeout in seconds (default: 30)").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Js);K.command("connect [domain] [target]").description("Connect domain to a hosting/email provider").option("--provider <name>","Provider name (e.g. vercel, google-workspace)").option("--method <name>","Connection method (e.g. cname-only)").option("--list","List available providers").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Vs);K.command("email [action] [arg2]").description("Manage email: list, inbox, create, delete, send, forward, webhook, setup, status, check, connect").option("--domain <domain>","Domain name").option("--slug <slug>","Mailbox slug (local part before @)").option("--from <email>","Sender address user@domain (alternative to --domain + --slug)").option("--to <email>","Recipient email address (for send)").option("--cc <emails>","CC recipients, comma-separated (for send)").option("--bcc <emails>","BCC recipients, comma-separated (for send)").option("--subject <s>","Email subject (for send)").option("--title <s>","Email subject (alias for --subject)").option("--text <t>","Email body text (for send)").option("--body <t>","Email body text (alias for --text)").option("--in-reply-to <message-id>","Message-ID of email being replied to (for threading)").option("--references <message-ids>","Space-separated Message-ID chain (for threading)").option("--url <url>","Webhook URL (for webhook)").option("--forward-to <email>","Email address to forward inbound emails to (for forward)").option("--direction <dir>","Filter messages: in or out").option("--limit <n>","Limit results").option("--check","Verify email DNS health (MX, SPF, DKIM, DMARC)").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Ht);K.command("dns [domain] [action] [type] [name] [value]").description("Manage DNS records (get/set/delete/snapshot/restore)").option("--type <type>","Record type: A, AAAA, CNAME, MX, TXT, NS, SRV").option("--name <name>","Record name (e.g. www, @, _dmarc)").option("--value <value>","Record value").option("--file <path>","Snapshot file path (for restore)").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Ws);K.command("nameservers [domain] [ns...]").alias("ns").description("Get or set nameservers (--reset for defaults)").option("--set <ns>","Comma-separated nameservers to set").option("--reset","Reset to registrar default nameservers").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Hr);K.command("settings [domain]").description("View or update domain settings (auto-renew, WHOIS privacy, security lock)").option("--auto-renew <on|off>","Enable or disable auto-renew").option("--whois-privacy <on|off>","Enable or disable WHOIS privacy").option("--security-lock <on|off>","Lock or unlock domain transfers").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Pr);K.command("auth-code [domain]").description("Get EPP auth code to transfer domain to another registrar").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Tr);K.command("transfer-away [domain]").description("Check status of an outbound domain transfer").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Dr);K.command("contact [action]").description("View or set WHOIS contact info (required for purchases)").option("--first-name <name>","First name (for set)").option("--last-name <name>","Last name (for set)").option("--org-name <name>","Organization name (for set, optional)").option("--address1 <addr>","Address line 1 (for set)").option("--address2 <addr>","Address line 2 (for set, optional)").option("--city <city>","City (for set)").option("--state <state>","State/Province (for set)").option("--postal-code <code>","Postal/ZIP code (for set)").option("--country <code>","Country code ISO 3166-1 alpha-2 (for set)").option("--phone <phone>","Phone +CC.NUMBER (for set)").option("--email <email>","Contact email (for set)").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Nr);K.command("parking [domain] [action] [value]").description("Manage parking page (enable/disable/price)").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Mr);K.command("analytics [domain]").alias("stats").description("View parking analytics (views, inquiries, conversion)").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Ur);K.command("webhooks [action]").alias("webhook").description("Manage webhook endpoints (list/create/update/delete/deliveries/events)").option("--url <url>","Webhook HTTPS URL").option("--events <events>","Comma-separated event types").option("--webhook-id <id>","Webhook ID (for update/delete/deliveries)").option("--active <on|off>","Enable or disable webhook").option("--limit <n>","Limit deliveries returned").option("--dry-run","Show what would happen without executing").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Lr);K.command("send [arg2]").description("Send an email \u2014 shortcut for: domani email send").option("--from <email>","Sender address user@domain").option("--to <email>","Recipient email address").option("--cc <emails>","CC recipients, comma-separated").option("--bcc <emails>","BCC recipients, comma-separated").option("--subject <s>","Email subject").option("--title <s>","Email subject (alias for --subject)").option("--text <t>","Email body text").option("--body <t>","Email body text (alias for --text)").option("--in-reply-to <message-id>","Message-ID of email being replied to").option("--references <message-ids>","Space-separated Message-ID chain").option("--domain <domain>","Domain name").option("--slug <slug>","Mailbox slug").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action((e,t)=>Ht("send",e,t));K.command("inbox [arg2]").description("View email inbox \u2014 shortcut for: domani email inbox").option("--from <email>","Sender address user@domain").option("--domain <domain>","Domain name").option("--slug <slug>","Mailbox slug").option("--direction <dir>","Filter messages: in or out").option("--limit <n>","Limit results").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action((e,t)=>Ht("inbox",e,t));K.command("schema [command]").description("Show command schemas for AI agent integration").option("--json","Output as JSON").option("--fields <fields>","Filter JSON output fields (comma-separated)").action(Zr);K.command("update").description("Update domani CLI to the latest version").option("--json","Output as JSON (check version without updating)").action(Br);K.command("uninstall").description("Remove domani CLI and config from this machine").action(Kr);(async()=>{let e=vn();await K.parseAsync();let t=await e;t?.forced?(console.error(`
199
+ ${Ke.default.red("!")} CLI v${be} is no longer supported. Run ${Ke.default.bold("domani update")} to upgrade to v${t.update}
94
200
  `),process.exit(1)):t?.update&&console.error(`
95
- ${Fe.default.yellow("!")} Update available: ${Fe.default.dim(te)} ${Fe.default.dim("\u2192")} ${Fe.default.green(t.update)} Run ${Fe.default.bold("domani update")}
201
+ ${Ke.default.yellow("!")} Update available: ${Ke.default.dim(be)} ${Ke.default.dim("\u2192")} ${Ke.default.green(t.update)} Run ${Ke.default.bold("domani update")}
96
202
  `)})();