@mirage-cli/dataforseo-cli 0.1.2 → 0.1.3
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.
- package/dist/bin.js +687 -0
- package/dist/dfs.js +13 -15
- package/dist/index.js +18 -19
- package/package.json +4 -4
package/dist/dfs.js
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
import{createRequire as at}from"node:module";var Vo=Object.create;var{getPrototypeOf:Zo,defineProperty:we,getOwnPropertyNames:et}=Object;var ot=Object.prototype.hasOwnProperty;var tt=(e,o,t)=>{t=e!=null?Vo(Zo(e)):{};let a=o||!e||!e.__esModule?we(t,"default",{value:e,enumerable:!0}):t;for(let s of et(e))if(!ot.call(a,s))we(a,s,{get:()=>e[s],enumerable:!0});return a};var O=(e,o)=>()=>(o||e((o={exports:{}}).exports,o),o.exports);var Y=at(import.meta.url);var C=O((st)=>{class re extends Error{constructor(e,o,t){super(t);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=o,this.exitCode=e,this.nestedError=void 0}}class be extends re{constructor(e){super(1,"commander.invalidArgument",e);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}st.CommanderError=re;st.InvalidArgumentError=be});var $=O((ct)=>{var{InvalidArgumentError:nt}=C();class Te{constructor(e,o){switch(this.description=o||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case"<":this.required=!0,this._name=e.slice(1,-1);break;case"[":this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}if(this._name.length>3&&this._name.slice(-3)==="...")this.variadic=!0,this._name=this._name.slice(0,-3)}name(){return this._name}_concatValue(e,o){if(o===this.defaultValue||!Array.isArray(o))return[e];return o.concat(e)}default(e,o){return this.defaultValue=e,this.defaultValueDescription=o,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(o,t)=>{if(!this.argChoices.includes(o))throw new nt(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._concatValue(o,t);return o},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function dt(e){let o=e.name()+(e.variadic===!0?"...":"");return e.required?"<"+o+">":"["+o+"]"}ct.Argument=Te;ct.humanReadableArgName=dt});var ne=O((gt)=>{var{humanReadableArgName:ht}=$();class Ie{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(e){let o=e.commands.filter((a)=>!a._hidden),t=e._getHelpCommand();if(t&&!t._hidden)o.push(t);if(this.sortSubcommands)o.sort((a,s)=>{return a.name().localeCompare(s.name())});return o}compareOptions(e,o){let t=(a)=>{return a.short?a.short.replace(/^-/,""):a.long.replace(/^--/,"")};return t(e).localeCompare(t(o))}visibleOptions(e){let o=e.options.filter((a)=>!a.hidden),t=e._getHelpOption();if(t&&!t.hidden){let a=t.short&&e._findOption(t.short),s=t.long&&e._findOption(t.long);if(!a&&!s)o.push(t);else if(t.long&&!s)o.push(e.createOption(t.long,t.description));else if(t.short&&!a)o.push(e.createOption(t.short,t.description))}if(this.sortOptions)o.sort(this.compareOptions);return o}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let o=[];for(let t=e.parent;t;t=t.parent){let a=t.options.filter((s)=>!s.hidden);o.push(...a)}if(this.sortOptions)o.sort(this.compareOptions);return o}visibleArguments(e){if(e._argsDescription)e.registeredArguments.forEach((o)=>{o.description=o.description||e._argsDescription[o.name()]||""});if(e.registeredArguments.find((o)=>o.description))return e.registeredArguments;return[]}subcommandTerm(e){let o=e.registeredArguments.map((t)=>ht(t)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(o?" "+o:"")}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,o){return o.visibleCommands(e).reduce((t,a)=>{return Math.max(t,o.subcommandTerm(a).length)},0)}longestOptionTermLength(e,o){return o.visibleOptions(e).reduce((t,a)=>{return Math.max(t,o.optionTerm(a).length)},0)}longestGlobalOptionTermLength(e,o){return o.visibleGlobalOptions(e).reduce((t,a)=>{return Math.max(t,o.optionTerm(a).length)},0)}longestArgumentTermLength(e,o){return o.visibleArguments(e).reduce((t,a)=>{return Math.max(t,o.argumentTerm(a).length)},0)}commandUsage(e){let o=e._name;if(e._aliases[0])o=o+"|"+e._aliases[0];let t="";for(let a=e.parent;a;a=a.parent)t=a.name()+" "+t;return t+o+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let o=[];if(e.argChoices)o.push(`choices: ${e.argChoices.map((t)=>JSON.stringify(t)).join(", ")}`);if(e.defaultValue!==void 0){if(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue==="boolean")o.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`)}if(e.presetArg!==void 0&&e.optional)o.push(`preset: ${JSON.stringify(e.presetArg)}`);if(e.envVar!==void 0)o.push(`env: ${e.envVar}`);if(o.length>0)return`${e.description} (${o.join(", ")})`;return e.description}argumentDescription(e){let o=[];if(e.argChoices)o.push(`choices: ${e.argChoices.map((t)=>JSON.stringify(t)).join(", ")}`);if(e.defaultValue!==void 0)o.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`);if(o.length>0){let t=`(${o.join(", ")})`;if(e.description)return`${e.description} ${t}`;return t}return e.description}formatHelp(e,o){let t=o.padWidth(e,o),a=o.helpWidth||80,s=2,i=2;function n(S,B){if(B){let ie=`${S.padEnd(t+2)}${B}`;return o.wrap(ie,a-2,t+2)}return S}function r(S){return S.join(`
|
|
1
|
+
import{createRequire as at}from"node:module";var Vo=Object.create;var{getPrototypeOf:Zo,defineProperty:we,getOwnPropertyNames:et}=Object;var ot=Object.prototype.hasOwnProperty;var tt=(e,o,t)=>{t=e!=null?Vo(Zo(e)):{};let a=o||!e||!e.__esModule?we(t,"default",{value:e,enumerable:!0}):t;for(let s of et(e))if(!ot.call(a,s))we(a,s,{get:()=>e[s],enumerable:!0});return a};var O=(e,o)=>()=>(o||e((o={exports:{}}).exports,o),o.exports);var K=at(import.meta.url);var C=O((st)=>{class re extends Error{constructor(e,o,t){super(t);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=o,this.exitCode=e,this.nestedError=void 0}}class be extends re{constructor(e){super(1,"commander.invalidArgument",e);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}st.CommanderError=re;st.InvalidArgumentError=be});var $=O((ct)=>{var{InvalidArgumentError:nt}=C();class Te{constructor(e,o){switch(this.description=o||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case"<":this.required=!0,this._name=e.slice(1,-1);break;case"[":this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}if(this._name.length>3&&this._name.slice(-3)==="...")this.variadic=!0,this._name=this._name.slice(0,-3)}name(){return this._name}_concatValue(e,o){if(o===this.defaultValue||!Array.isArray(o))return[e];return o.concat(e)}default(e,o){return this.defaultValue=e,this.defaultValueDescription=o,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(o,t)=>{if(!this.argChoices.includes(o))throw new nt(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._concatValue(o,t);return o},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function dt(e){let o=e.name()+(e.variadic===!0?"...":"");return e.required?"<"+o+">":"["+o+"]"}ct.Argument=Te;ct.humanReadableArgName=dt});var ne=O((gt)=>{var{humanReadableArgName:ht}=$();class Ie{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(e){let o=e.commands.filter((a)=>!a._hidden),t=e._getHelpCommand();if(t&&!t._hidden)o.push(t);if(this.sortSubcommands)o.sort((a,s)=>{return a.name().localeCompare(s.name())});return o}compareOptions(e,o){let t=(a)=>{return a.short?a.short.replace(/^-/,""):a.long.replace(/^--/,"")};return t(e).localeCompare(t(o))}visibleOptions(e){let o=e.options.filter((a)=>!a.hidden),t=e._getHelpOption();if(t&&!t.hidden){let a=t.short&&e._findOption(t.short),s=t.long&&e._findOption(t.long);if(!a&&!s)o.push(t);else if(t.long&&!s)o.push(e.createOption(t.long,t.description));else if(t.short&&!a)o.push(e.createOption(t.short,t.description))}if(this.sortOptions)o.sort(this.compareOptions);return o}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let o=[];for(let t=e.parent;t;t=t.parent){let a=t.options.filter((s)=>!s.hidden);o.push(...a)}if(this.sortOptions)o.sort(this.compareOptions);return o}visibleArguments(e){if(e._argsDescription)e.registeredArguments.forEach((o)=>{o.description=o.description||e._argsDescription[o.name()]||""});if(e.registeredArguments.find((o)=>o.description))return e.registeredArguments;return[]}subcommandTerm(e){let o=e.registeredArguments.map((t)=>ht(t)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(o?" "+o:"")}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,o){return o.visibleCommands(e).reduce((t,a)=>{return Math.max(t,o.subcommandTerm(a).length)},0)}longestOptionTermLength(e,o){return o.visibleOptions(e).reduce((t,a)=>{return Math.max(t,o.optionTerm(a).length)},0)}longestGlobalOptionTermLength(e,o){return o.visibleGlobalOptions(e).reduce((t,a)=>{return Math.max(t,o.optionTerm(a).length)},0)}longestArgumentTermLength(e,o){return o.visibleArguments(e).reduce((t,a)=>{return Math.max(t,o.argumentTerm(a).length)},0)}commandUsage(e){let o=e._name;if(e._aliases[0])o=o+"|"+e._aliases[0];let t="";for(let a=e.parent;a;a=a.parent)t=a.name()+" "+t;return t+o+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let o=[];if(e.argChoices)o.push(`choices: ${e.argChoices.map((t)=>JSON.stringify(t)).join(", ")}`);if(e.defaultValue!==void 0){if(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue==="boolean")o.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`)}if(e.presetArg!==void 0&&e.optional)o.push(`preset: ${JSON.stringify(e.presetArg)}`);if(e.envVar!==void 0)o.push(`env: ${e.envVar}`);if(o.length>0)return`${e.description} (${o.join(", ")})`;return e.description}argumentDescription(e){let o=[];if(e.argChoices)o.push(`choices: ${e.argChoices.map((t)=>JSON.stringify(t)).join(", ")}`);if(e.defaultValue!==void 0)o.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`);if(o.length>0){let t=`(${o.join(", ")})`;if(e.description)return`${e.description} ${t}`;return t}return e.description}formatHelp(e,o){let t=o.padWidth(e,o),a=o.helpWidth||80,s=2,i=2;function n(S,B){if(B){let ie=`${S.padEnd(t+2)}${B}`;return o.wrap(ie,a-2,t+2)}return S}function r(S){return S.join(`
|
|
3
2
|
`).replace(/^/gm," ".repeat(2))}let d=[`Usage: ${o.commandUsage(e)}`,""],l=o.commandDescription(e);if(l.length>0)d=d.concat([o.wrap(l,a,0),""]);let _=o.visibleArguments(e).map((S)=>{return n(o.argumentTerm(S),o.argumentDescription(S))});if(_.length>0)d=d.concat(["Arguments:",r(_),""]);let b=o.visibleOptions(e).map((S)=>{return n(o.optionTerm(S),o.optionDescription(S))});if(b.length>0)d=d.concat(["Options:",r(b),""]);if(this.showGlobalOptions){let S=o.visibleGlobalOptions(e).map((B)=>{return n(o.optionTerm(B),o.optionDescription(B))});if(S.length>0)d=d.concat(["Global Options:",r(S),""])}let U=o.visibleCommands(e).map((S)=>{return n(o.subcommandTerm(S),o.subcommandDescription(S))});if(U.length>0)d=d.concat(["Commands:",r(U),""]);return d.join(`
|
|
4
3
|
`)}padWidth(e,o){return Math.max(o.longestOptionTermLength(e,o),o.longestGlobalOptionTermLength(e,o),o.longestSubcommandTermLength(e,o),o.longestArgumentTermLength(e,o))}wrap(e,o,t,a=40){let i=new RegExp(`[\\n][${" \\f\\t\\v - \uFEFF"}]+`);if(e.match(i))return e;let n=o-t;if(n<a)return e;let r=e.slice(0,t),d=e.slice(t).replace(`\r
|
|
5
4
|
`,`
|
|
6
5
|
`),l=" ".repeat(t),b=`\\s${""}`,U=new RegExp(`
|
|
7
6
|
|.{1,${n-1}}([${b}]|$)|[^${b}]+?([${b}]|$)`,"g"),S=d.match(U)||[];return r+S.map((B,ie)=>{if(B===`
|
|
8
7
|
`)return"";return(ie>0?l:"")+B.trimEnd()}).join(`
|
|
9
|
-
`)}}gt.Help=Ie});var de=O((_t)=>{var{InvalidArgumentError:ft}=C();class Se{constructor(e,o){this.flags=e,this.description=o||"",this.required=e.includes("<"),this.optional=e.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let t=vt(e);if(this.short=t.shortFlag,this.long=t.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(e,o){return this.defaultValue=e,this.defaultValueDescription=o,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let o=e;if(typeof e==="string")o={[e]:!0};return this.implied=Object.assign(this.implied||{},o),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_concatValue(e,o){if(o===this.defaultValue||!Array.isArray(o))return[e];return o.concat(e)}choices(e){return this.argChoices=e.slice(),this.parseArg=(o,t)=>{if(!this.argChoices.includes(o))throw new ft(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._concatValue(o,t);return o},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){return ut(this.name().replace(/^no-/,""))}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class Le{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach((o)=>{if(o.negate)this.negativeOptions.set(o.attributeName(),o);else this.positiveOptions.set(o.attributeName(),o)}),this.negativeOptions.forEach((o,t)=>{if(this.positiveOptions.has(t))this.dualOptions.add(t)})}valueFromOption(e,o){let t=o.attributeName();if(!this.dualOptions.has(t))return!0;let a=this.negativeOptions.get(t).presetArg,s=a!==void 0?a:!1;return o.negate===(s===e)}}function ut(e){return e.split("-").reduce((o,t)=>{return o+t[0].toUpperCase()+t.slice(1)})}function vt(e){let o,t,a=e.split(/[ |,]+/);if(a.length>1&&!/^[[<]/.test(a[1]))o=a.shift();if(t=a.shift(),!o&&/^-[^-]$/.test(t))o=t,t=void 0;return{shortFlag:o,longFlag:t}}_t.Option=Se;_t.DualOptions=Le});var
|
|
8
|
+
`)}}gt.Help=Ie});var de=O((_t)=>{var{InvalidArgumentError:ft}=C();class Se{constructor(e,o){this.flags=e,this.description=o||"",this.required=e.includes("<"),this.optional=e.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let t=vt(e);if(this.short=t.shortFlag,this.long=t.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(e,o){return this.defaultValue=e,this.defaultValueDescription=o,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let o=e;if(typeof e==="string")o={[e]:!0};return this.implied=Object.assign(this.implied||{},o),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_concatValue(e,o){if(o===this.defaultValue||!Array.isArray(o))return[e];return o.concat(e)}choices(e){return this.argChoices=e.slice(),this.parseArg=(o,t)=>{if(!this.argChoices.includes(o))throw new ft(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._concatValue(o,t);return o},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){return ut(this.name().replace(/^no-/,""))}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class Le{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach((o)=>{if(o.negate)this.negativeOptions.set(o.attributeName(),o);else this.positiveOptions.set(o.attributeName(),o)}),this.negativeOptions.forEach((o,t)=>{if(this.positiveOptions.has(t))this.dualOptions.add(t)})}valueFromOption(e,o){let t=o.attributeName();if(!this.dualOptions.has(t))return!0;let a=this.negativeOptions.get(t).presetArg,s=a!==void 0?a:!1;return o.negate===(s===e)}}function ut(e){return e.split("-").reduce((o,t)=>{return o+t[0].toUpperCase()+t.slice(1)})}function vt(e){let o,t,a=e.split(/[ |,]+/);if(a.length>1&&!/^[[<]/.test(a[1]))o=a.shift();if(t=a.shift(),!o&&/^-[^-]$/.test(t))o=t,t=void 0;return{shortFlag:o,longFlag:t}}_t.Option=Se;_t.DualOptions=Le});var Ae=O((Tt)=>{function wt(e,o){if(Math.abs(e.length-o.length)>3)return Math.max(e.length,o.length);let t=[];for(let a=0;a<=e.length;a++)t[a]=[a];for(let a=0;a<=o.length;a++)t[0][a]=a;for(let a=1;a<=o.length;a++)for(let s=1;s<=e.length;s++){let i=1;if(e[s-1]===o[a-1])i=0;else i=1;if(t[s][a]=Math.min(t[s-1][a]+1,t[s][a-1]+1,t[s-1][a-1]+i),s>1&&a>1&&e[s-1]===o[a-2]&&e[s-2]===o[a-1])t[s][a]=Math.min(t[s][a],t[s-2][a-2]+1)}return t[e.length][o.length]}function bt(e,o){if(!o||o.length===0)return"";o=Array.from(new Set(o));let t=e.startsWith("--");if(t)e=e.slice(2),o=o.map((n)=>n.slice(2));let a=[],s=3,i=0.4;if(o.forEach((n)=>{if(n.length<=1)return;let r=wt(e,n),d=Math.max(e.length,n.length);if((d-r)/d>i){if(r<s)s=r,a=[n];else if(r===s)a.push(n)}}),a.sort((n,r)=>n.localeCompare(r)),t)a=a.map((n)=>`--${n}`);if(a.length>1)return`
|
|
10
9
|
(Did you mean one of ${a.join(", ")}?)`;if(a.length===1)return`
|
|
11
|
-
(Did you mean ${a[0]}?)`;return""}Tt.suggestSimilar=bt});var De=O((Pt)=>{var St=
|
|
10
|
+
(Did you mean ${a[0]}?)`;return""}Tt.suggestSimilar=bt});var De=O((Pt)=>{var St=K("node:events").EventEmitter,ce=K("node:child_process"),D=K("node:path"),le=K("node:fs"),T=K("node:process"),{Argument:Lt,humanReadableArgName:At}=$(),{CommanderError:pe}=C(),{Help:Gt}=ne(),{Option:Ge,DualOptions:Ut}=de(),{suggestSimilar:Ue}=Ae();class he extends St{constructor(e){super();this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!0,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=e||"",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._outputConfiguration={writeOut:(o)=>T.stdout.write(o),writeErr:(o)=>T.stderr.write(o),getOutHelpWidth:()=>T.stdout.isTTY?T.stdout.columns:void 0,getErrHelpWidth:()=>T.stderr.isTTY?T.stderr.columns:void 0,outputError:(o,t)=>t(o)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={}}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._helpOption=e._helpOption,this._helpCommand=e._helpCommand,this._helpConfiguration=e._helpConfiguration,this._exitCallback=e._exitCallback,this._storeOptionsAsProperties=e._storeOptionsAsProperties,this._combineFlagAndOptionalValue=e._combineFlagAndOptionalValue,this._allowExcessArguments=e._allowExcessArguments,this._enablePositionalOptions=e._enablePositionalOptions,this._showHelpAfterError=e._showHelpAfterError,this._showSuggestionAfterError=e._showSuggestionAfterError,this}_getCommandAndAncestors(){let e=[];for(let o=this;o;o=o.parent)e.push(o);return e}command(e,o,t){let a=o,s=t;if(typeof a==="object"&&a!==null)s=a,a=null;s=s||{};let[,i,n]=e.match(/([^ ]+) *(.*)/),r=this.createCommand(i);if(a)r.description(a),r._executableHandler=!0;if(s.isDefault)this._defaultCommandName=r._name;if(r._hidden=!!(s.noHelp||s.hidden),r._executableFile=s.executableFile||null,n)r.arguments(n);if(this._registerCommand(r),r.parent=this,r.copyInheritedSettings(this),a)return this;return r}createCommand(e){return new he(e)}createHelp(){return Object.assign(new Gt,this.configureHelp())}configureHelp(e){if(e===void 0)return this._helpConfiguration;return this._helpConfiguration=e,this}configureOutput(e){if(e===void 0)return this._outputConfiguration;return Object.assign(this._outputConfiguration,e),this}showHelpAfterError(e=!0){if(typeof e!=="string")e=!!e;return this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,o){if(!e._name)throw Error(`Command passed to .addCommand() must have a name
|
|
12
11
|
- specify the name in Command constructor or using .name()`);if(o=o||{},o.isDefault)this._defaultCommandName=e._name;if(o.noHelp||o.hidden)e._hidden=!0;return this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,o){return new Lt(e,o)}argument(e,o,t,a){let s=this.createArgument(e,o);if(typeof t==="function")s.default(a).argParser(t);else s.default(t);return this.addArgument(s),this}arguments(e){return e.trim().split(/ +/).forEach((o)=>{this.argument(o)}),this}addArgument(e){let o=this.registeredArguments.slice(-1)[0];if(o&&o.variadic)throw Error(`only the last argument can be variadic '${o.name()}'`);if(e.required&&e.defaultValue!==void 0&&e.parseArg===void 0)throw Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,o){if(typeof e==="boolean")return this._addImplicitHelpCommand=e,this;e=e??"help [command]";let[,t,a]=e.match(/([^ ]+) *(.*)/),s=o??"display help for command",i=this.createCommand(t);if(i.helpOption(!1),a)i.arguments(a);if(s)i.description(s);return this._addImplicitHelpCommand=!0,this._helpCommand=i,this}addHelpCommand(e,o){if(typeof e!=="object")return this.helpCommand(e,o),this;return this._addImplicitHelpCommand=!0,this._helpCommand=e,this}_getHelpCommand(){if(this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))){if(this._helpCommand===void 0)this.helpCommand(void 0,void 0);return this._helpCommand}return null}hook(e,o){let t=["preSubcommand","preAction","postAction"];if(!t.includes(e))throw Error(`Unexpected value for event passed to hook : '${e}'.
|
|
13
|
-
Expecting one of '${t.join("', '")}'`);if(this._lifeCycleHooks[e])this._lifeCycleHooks[e].push(o);else this._lifeCycleHooks[e]=[o];return this}exitOverride(e){if(e)this._exitCallback=e;else this._exitCallback=(o)=>{if(o.code!=="commander.executeSubCommandAsync")throw o};return this}_exit(e,o,t){if(this._exitCallback)this._exitCallback(new pe(e,o,t));T.exit(e)}action(e){let o=(t)=>{let a=this.registeredArguments.length,s=t.slice(0,a);if(this._storeOptionsAsProperties)s[a]=this;else s[a]=this.opts();return s.push(this),e.apply(this,s)};return this._actionHandler=o,this}createOption(e,o){return new
|
|
14
|
-
- already used by option '${o.flags}'`)}this.options.push(e)}_registerCommand(e){let o=(a)=>{return[a.name()].concat(a.aliases())},t=o(e).find((a)=>this._findCommand(a));if(t){let a=o(this._findCommand(t)).join("|"),s=o(e).join("|");throw Error(`cannot add command '${s}' as already have command '${a}'`)}this.commands.push(e)}addOption(e){this._registerOption(e);let o=e.name(),t=e.attributeName();if(e.negate){let s=e.long.replace(/^--no-/,"--");if(!this._findOption(s))this.setOptionValueWithSource(t,e.defaultValue===void 0?!0:e.defaultValue,"default")}else if(e.defaultValue!==void 0)this.setOptionValueWithSource(t,e.defaultValue,"default");let a=(s,i,n)=>{if(s==null&&e.presetArg!==void 0)s=e.presetArg;let r=this.getOptionValue(t);if(s!==null&&e.parseArg)s=this._callParseArg(e,s,r,i);else if(s!==null&&e.variadic)s=e._concatValue(s,r);if(s==null)if(e.negate)s=!1;else if(e.isBoolean()||e.optional)s=!0;else s="";this.setOptionValueWithSource(t,s,n)};if(this.on("option:"+o,(s)=>{let i=`error: option '${e.flags}' argument '${s}' is invalid.`;a(s,i,"cli")}),e.envVar)this.on("optionEnv:"+o,(s)=>{let i=`error: option '${e.flags}' value '${s}' from env '${e.envVar}' is invalid.`;a(s,i,"env")});return this}_optionEx(e,o,t,a,s){if(typeof o==="object"&&o instanceof
|
|
12
|
+
Expecting one of '${t.join("', '")}'`);if(this._lifeCycleHooks[e])this._lifeCycleHooks[e].push(o);else this._lifeCycleHooks[e]=[o];return this}exitOverride(e){if(e)this._exitCallback=e;else this._exitCallback=(o)=>{if(o.code!=="commander.executeSubCommandAsync")throw o};return this}_exit(e,o,t){if(this._exitCallback)this._exitCallback(new pe(e,o,t));T.exit(e)}action(e){let o=(t)=>{let a=this.registeredArguments.length,s=t.slice(0,a);if(this._storeOptionsAsProperties)s[a]=this;else s[a]=this.opts();return s.push(this),e.apply(this,s)};return this._actionHandler=o,this}createOption(e,o){return new Ge(e,o)}_callParseArg(e,o,t,a){try{return e.parseArg(o,t)}catch(s){if(s.code==="commander.invalidArgument"){let i=`${a} ${s.message}`;this.error(i,{exitCode:s.exitCode,code:s.code})}throw s}}_registerOption(e){let o=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(o){let t=e.long&&this._findOption(e.long)?e.long:e.short;throw Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${t}'
|
|
13
|
+
- already used by option '${o.flags}'`)}this.options.push(e)}_registerCommand(e){let o=(a)=>{return[a.name()].concat(a.aliases())},t=o(e).find((a)=>this._findCommand(a));if(t){let a=o(this._findCommand(t)).join("|"),s=o(e).join("|");throw Error(`cannot add command '${s}' as already have command '${a}'`)}this.commands.push(e)}addOption(e){this._registerOption(e);let o=e.name(),t=e.attributeName();if(e.negate){let s=e.long.replace(/^--no-/,"--");if(!this._findOption(s))this.setOptionValueWithSource(t,e.defaultValue===void 0?!0:e.defaultValue,"default")}else if(e.defaultValue!==void 0)this.setOptionValueWithSource(t,e.defaultValue,"default");let a=(s,i,n)=>{if(s==null&&e.presetArg!==void 0)s=e.presetArg;let r=this.getOptionValue(t);if(s!==null&&e.parseArg)s=this._callParseArg(e,s,r,i);else if(s!==null&&e.variadic)s=e._concatValue(s,r);if(s==null)if(e.negate)s=!1;else if(e.isBoolean()||e.optional)s=!0;else s="";this.setOptionValueWithSource(t,s,n)};if(this.on("option:"+o,(s)=>{let i=`error: option '${e.flags}' argument '${s}' is invalid.`;a(s,i,"cli")}),e.envVar)this.on("optionEnv:"+o,(s)=>{let i=`error: option '${e.flags}' value '${s}' from env '${e.envVar}' is invalid.`;a(s,i,"env")});return this}_optionEx(e,o,t,a,s){if(typeof o==="object"&&o instanceof Ge)throw Error("To add an Option object use addOption() instead of option() or requiredOption()");let i=this.createOption(o,t);if(i.makeOptionMandatory(!!e.mandatory),typeof a==="function")i.default(s).argParser(a);else if(a instanceof RegExp){let n=a;a=(r,d)=>{let l=n.exec(r);return l?l[0]:d},i.default(s).argParser(a)}else i.default(a);return this.addOption(i)}option(e,o,t,a){return this._optionEx({},e,o,t,a)}requiredOption(e,o,t,a){return this._optionEx({mandatory:!0},e,o,t,a)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(e=!0){if(this.options.length)throw Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!e,this}getOptionValue(e){if(this._storeOptionsAsProperties)return this[e];return this._optionValues[e]}setOptionValue(e,o){return this.setOptionValueWithSource(e,o,void 0)}setOptionValueWithSource(e,o,t){if(this._storeOptionsAsProperties)this[e]=o;else this._optionValues[e]=o;return this._optionValueSources[e]=t,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let o;return this._getCommandAndAncestors().forEach((t)=>{if(t.getOptionValueSource(e)!==void 0)o=t.getOptionValueSource(e)}),o}_prepareUserArgs(e,o){if(e!==void 0&&!Array.isArray(e))throw Error("first parameter to parse must be array or undefined");if(o=o||{},e===void 0&&o.from===void 0){if(T.versions?.electron)o.from="electron";let a=T.execArgv??[];if(a.includes("-e")||a.includes("--eval")||a.includes("-p")||a.includes("--print"))o.from="eval"}if(e===void 0)e=T.argv;this.rawArgs=e.slice();let t;switch(o.from){case void 0:case"node":this._scriptPath=e[1],t=e.slice(2);break;case"electron":if(T.defaultApp)this._scriptPath=e[1],t=e.slice(2);else t=e.slice(1);break;case"user":t=e.slice(0);break;case"eval":t=e.slice(1);break;default:throw Error(`unexpected parse option { from: '${o.from}' }`)}if(!this._name&&this._scriptPath)this.nameFromFilename(this._scriptPath);return this._name=this._name||"program",t}parse(e,o){let t=this._prepareUserArgs(e,o);return this._parseCommand([],t),this}async parseAsync(e,o){let t=this._prepareUserArgs(e,o);return await this._parseCommand([],t),this}_executeSubCommand(e,o){o=o.slice();let t=!1,a=[".js",".ts",".tsx",".mjs",".cjs"];function s(l,_){let b=D.resolve(l,_);if(le.existsSync(b))return b;if(a.includes(D.extname(_)))return;let U=a.find((S)=>le.existsSync(`${b}${S}`));if(U)return`${b}${U}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let i=e._executableFile||`${this._name}-${e._name}`,n=this._executableDir||"";if(this._scriptPath){let l;try{l=le.realpathSync(this._scriptPath)}catch(_){l=this._scriptPath}n=D.resolve(D.dirname(l),n)}if(n){let l=s(n,i);if(!l&&!e._executableFile&&this._scriptPath){let _=D.basename(this._scriptPath,D.extname(this._scriptPath));if(_!==this._name)l=s(n,`${_}-${e._name}`)}i=l||i}t=a.includes(D.extname(i));let r;if(T.platform!=="win32")if(t)o.unshift(i),o=Pe(T.execArgv).concat(o),r=ce.spawn(T.argv[0],o,{stdio:"inherit"});else r=ce.spawn(i,o,{stdio:"inherit"});else o.unshift(i),o=Pe(T.execArgv).concat(o),r=ce.spawn(T.execPath,o,{stdio:"inherit"});if(!r.killed)["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((_)=>{T.on(_,()=>{if(r.killed===!1&&r.exitCode===null)r.kill(_)})});let d=this._exitCallback;r.on("close",(l)=>{if(l=l??1,!d)T.exit(l);else d(new pe(l,"commander.executeSubCommandAsync","(close)"))}),r.on("error",(l)=>{if(l.code==="ENOENT"){let _=n?`searched for local subcommand relative to directory '${n}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",b=`'${i}' does not exist
|
|
15
14
|
- if '${e._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
16
15
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
17
16
|
- ${_}`;throw Error(b)}else if(l.code==="EACCES")throw Error(`'${i}' not executable`);if(!d)T.exit(1);else{let _=new pe(1,"commander.executeSubCommandAsync","(error)");_.nestedError=l,d(_)}}),this.runningCommand=r}_dispatchSubcommand(e,o,t){let a=this._findCommand(e);if(!a)this.help({error:!0});let s;return s=this._chainOrCallSubCommandHook(s,a,"preSubcommand"),s=this._chainOrCall(s,()=>{if(a._executableHandler)this._executeSubCommand(a,o.concat(t));else return a._parseCommand(o,t)}),s}_dispatchHelpCommand(e){if(!e)this.help();let o=this._findCommand(e);if(o&&!o._executableHandler)o.help();return this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach((e,o)=>{if(e.required&&this.args[o]==null)this.missingArgument(e.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)return;if(this.args.length>this.registeredArguments.length)this._excessArguments(this.args)}_processArguments(){let e=(t,a,s)=>{let i=a;if(a!==null&&t.parseArg){let n=`error: command-argument value '${a}' is invalid for argument '${t.name()}'.`;i=this._callParseArg(t,a,s,n)}return i};this._checkNumberOfArguments();let o=[];this.registeredArguments.forEach((t,a)=>{let s=t.defaultValue;if(t.variadic){if(a<this.args.length){if(s=this.args.slice(a),t.parseArg)s=s.reduce((i,n)=>{return e(t,n,i)},t.defaultValue)}else if(s===void 0)s=[]}else if(a<this.args.length){if(s=this.args[a],t.parseArg)s=e(t,s,t.defaultValue)}o[a]=s}),this.processedArgs=o}_chainOrCall(e,o){if(e&&e.then&&typeof e.then==="function")return e.then(()=>o());return o()}_chainOrCallHooks(e,o){let t=e,a=[];if(this._getCommandAndAncestors().reverse().filter((s)=>s._lifeCycleHooks[o]!==void 0).forEach((s)=>{s._lifeCycleHooks[o].forEach((i)=>{a.push({hookedCommand:s,callback:i})})}),o==="postAction")a.reverse();return a.forEach((s)=>{t=this._chainOrCall(t,()=>{return s.callback(s.hookedCommand,this)})}),t}_chainOrCallSubCommandHook(e,o,t){let a=e;if(this._lifeCycleHooks[t]!==void 0)this._lifeCycleHooks[t].forEach((s)=>{a=this._chainOrCall(a,()=>{return s(this,o)})});return a}_parseCommand(e,o){let t=this.parseOptions(o);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(t.operands),o=t.unknown,this.args=e.concat(o),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),o);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(o),this._dispatchSubcommand(this._defaultCommandName,e,o);if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName)this.help({error:!0});this._outputHelpIfRequested(t.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let a=()=>{if(t.unknown.length>0)this.unknownOption(t.unknown[0])},s=`command:${this.name()}`;if(this._actionHandler){a(),this._processArguments();let i;if(i=this._chainOrCallHooks(i,"preAction"),i=this._chainOrCall(i,()=>this._actionHandler(this.processedArgs)),this.parent)i=this._chainOrCall(i,()=>{this.parent.emit(s,e,o)});return i=this._chainOrCallHooks(i,"postAction"),i}if(this.parent&&this.parent.listenerCount(s))a(),this._processArguments(),this.parent.emit(s,e,o);else if(e.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",e,o);if(this.listenerCount("command:*"))this.emit("command:*",e,o);else if(this.commands.length)this.unknownCommand();else a(),this._processArguments()}else if(this.commands.length)a(),this.help({error:!0});else a(),this._processArguments()}_findCommand(e){if(!e)return;return this.commands.find((o)=>o._name===e||o._aliases.includes(e))}_findOption(e){return this.options.find((o)=>o.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach((e)=>{e.options.forEach((o)=>{if(o.mandatory&&e.getOptionValue(o.attributeName())===void 0)e.missingMandatoryOptionValue(o)})})}_checkForConflictingLocalOptions(){let e=this.options.filter((t)=>{let a=t.attributeName();if(this.getOptionValue(a)===void 0)return!1;return this.getOptionValueSource(a)!=="default"});e.filter((t)=>t.conflictsWith.length>0).forEach((t)=>{let a=e.find((s)=>t.conflictsWith.includes(s.attributeName()));if(a)this._conflictingOption(t,a)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach((e)=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let o=[],t=[],a=o,s=e.slice();function i(r){return r.length>1&&r[0]==="-"}let n=null;while(s.length){let r=s.shift();if(r==="--"){if(a===t)a.push(r);a.push(...s);break}if(n&&!i(r)){this.emit(`option:${n.name()}`,r);continue}if(n=null,i(r)){let d=this._findOption(r);if(d){if(d.required){let l=s.shift();if(l===void 0)this.optionMissingArgument(d);this.emit(`option:${d.name()}`,l)}else if(d.optional){let l=null;if(s.length>0&&!i(s[0]))l=s.shift();this.emit(`option:${d.name()}`,l)}else this.emit(`option:${d.name()}`);n=d.variadic?d:null;continue}}if(r.length>2&&r[0]==="-"&&r[1]!=="-"){let d=this._findOption(`-${r[1]}`);if(d){if(d.required||d.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${d.name()}`,r.slice(2));else this.emit(`option:${d.name()}`),s.unshift(`-${r.slice(2)}`);continue}}if(/^--[^=]+=/.test(r)){let d=r.indexOf("="),l=this._findOption(r.slice(0,d));if(l&&(l.required||l.optional)){this.emit(`option:${l.name()}`,r.slice(d+1));continue}}if(i(r))a=t;if((this._enablePositionalOptions||this._passThroughOptions)&&o.length===0&&t.length===0){if(this._findCommand(r)){if(o.push(r),s.length>0)t.push(...s);break}else if(this._getHelpCommand()&&r===this._getHelpCommand().name()){if(o.push(r),s.length>0)o.push(...s);break}else if(this._defaultCommandName){if(t.push(r),s.length>0)t.push(...s);break}}if(this._passThroughOptions){if(a.push(r),s.length>0)a.push(...s);break}a.push(r)}return{operands:o,unknown:t}}opts(){if(this._storeOptionsAsProperties){let e={},o=this.options.length;for(let t=0;t<o;t++){let a=this.options[t].attributeName();e[a]=a===this._versionOptionName?this._version:this[a]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,o)=>Object.assign(e,o.opts()),{})}error(e,o){if(this._outputConfiguration.outputError(`${e}
|
|
18
17
|
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==="string")this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
19
18
|
`);else if(this._showHelpAfterError)this._outputConfiguration.writeErr(`
|
|
20
19
|
`),this.outputHelp({error:!0});let t=o||{},a=t.exitCode||1,s=t.code||"commander.error";this._exit(a,s,e)}_parseOptionsEnv(){this.options.forEach((e)=>{if(e.envVar&&e.envVar in T.env){let o=e.attributeName();if(this.getOptionValue(o)===void 0||["default","config","env"].includes(this.getOptionValueSource(o)))if(e.required||e.optional)this.emit(`optionEnv:${e.name()}`,T.env[e.envVar]);else this.emit(`optionEnv:${e.name()}`)}})}_parseOptionsImplied(){let e=new Ut(this.options),o=(t)=>{return this.getOptionValue(t)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(t))};this.options.filter((t)=>t.implied!==void 0&&o(t.attributeName())&&e.valueFromOption(this.getOptionValue(t.attributeName()),t)).forEach((t)=>{Object.keys(t.implied).filter((a)=>!o(a)).forEach((a)=>{this.setOptionValueWithSource(a,t.implied[a],"implied")})})}missingArgument(e){let o=`error: missing required argument '${e}'`;this.error(o,{code:"commander.missingArgument"})}optionMissingArgument(e){let o=`error: option '${e.flags}' argument missing`;this.error(o,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(e){let o=`error: required option '${e.flags}' not specified`;this.error(o,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(e,o){let t=(i)=>{let n=i.attributeName(),r=this.getOptionValue(n),d=this.options.find((_)=>_.negate&&n===_.attributeName()),l=this.options.find((_)=>!_.negate&&n===_.attributeName());if(d&&(d.presetArg===void 0&&r===!1||d.presetArg!==void 0&&r===d.presetArg))return d;return l||i},a=(i)=>{let n=t(i),r=n.attributeName();if(this.getOptionValueSource(r)==="env")return`environment variable '${n.envVar}'`;return`option '${n.flags}'`},s=`error: ${a(e)} cannot be used with ${a(o)}`;this.error(s,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let o="";if(e.startsWith("--")&&this._showSuggestionAfterError){let a=[],s=this;do{let i=s.createHelp().visibleOptions(s).filter((n)=>n.long).map((n)=>n.long);a=a.concat(i),s=s.parent}while(s&&!s._enablePositionalOptions);o=Ue(e,a)}let t=`error: unknown option '${e}'${o}`;this.error(t,{code:"commander.unknownOption"})}_excessArguments(e){if(this._allowExcessArguments)return;let o=this.registeredArguments.length,t=o===1?"":"s",s=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${o} argument${t} but got ${e.length}.`;this.error(s,{code:"commander.excessArguments"})}unknownCommand(){let e=this.args[0],o="";if(this._showSuggestionAfterError){let a=[];this.createHelp().visibleCommands(this).forEach((s)=>{if(a.push(s.name()),s.alias())a.push(s.alias())}),o=Ue(e,a)}let t=`error: unknown command '${e}'${o}`;this.error(t,{code:"commander.unknownCommand"})}version(e,o,t){if(e===void 0)return this._version;this._version=e,o=o||"-V, --version",t=t||"output the version number";let a=this.createOption(o,t);return this._versionOptionName=a.attributeName(),this._registerOption(a),this.on("option:"+a.name(),()=>{this._outputConfiguration.writeOut(`${e}
|
|
21
|
-
`),this._exit(0,"commander.version",e)}),this}description(e,o){if(e===void 0&&o===void 0)return this._description;if(this._description=e,o)this._argsDescription=o;return this}summary(e){if(e===void 0)return this._summary;return this._summary=e,this}alias(e){if(e===void 0)return this._aliases[0];let o=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)o=this.commands[this.commands.length-1];if(e===o._name)throw Error("Command alias can't be the same as its name");let t=this.parent?._findCommand(e);if(t){let a=[t.name()].concat(t.aliases()).join("|");throw Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${a}'`)}return o._aliases.push(e),this}aliases(e){if(e===void 0)return this._aliases;return e.forEach((o)=>this.alias(o)),this}usage(e){if(e===void 0){if(this._usage)return this._usage;let o=this.registeredArguments.map((t)=>{return
|
|
20
|
+
`),this._exit(0,"commander.version",e)}),this}description(e,o){if(e===void 0&&o===void 0)return this._description;if(this._description=e,o)this._argsDescription=o;return this}summary(e){if(e===void 0)return this._summary;return this._summary=e,this}alias(e){if(e===void 0)return this._aliases[0];let o=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)o=this.commands[this.commands.length-1];if(e===o._name)throw Error("Command alias can't be the same as its name");let t=this.parent?._findCommand(e);if(t){let a=[t.name()].concat(t.aliases()).join("|");throw Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${a}'`)}return o._aliases.push(e),this}aliases(e){if(e===void 0)return this._aliases;return e.forEach((o)=>this.alias(o)),this}usage(e){if(e===void 0){if(this._usage)return this._usage;let o=this.registeredArguments.map((t)=>{return At(t)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?o:[]).join(" ")}return this._usage=e,this}name(e){if(e===void 0)return this._name;return this._name=e,this}nameFromFilename(e){return this._name=D.basename(e,D.extname(e)),this}executableDir(e){if(e===void 0)return this._executableDir;return this._executableDir=e,this}helpInformation(e){let o=this.createHelp();if(o.helpWidth===void 0)o.helpWidth=e&&e.error?this._outputConfiguration.getErrHelpWidth():this._outputConfiguration.getOutHelpWidth();return o.formatHelp(this,o)}_getHelpContext(e){e=e||{};let o={error:!!e.error},t;if(o.error)t=(a)=>this._outputConfiguration.writeErr(a);else t=(a)=>this._outputConfiguration.writeOut(a);return o.write=e.write||t,o.command=this,o}outputHelp(e){let o;if(typeof e==="function")o=e,e=void 0;let t=this._getHelpContext(e);this._getCommandAndAncestors().reverse().forEach((s)=>s.emit("beforeAllHelp",t)),this.emit("beforeHelp",t);let a=this.helpInformation(t);if(o){if(a=o(a),typeof a!=="string"&&!Buffer.isBuffer(a))throw Error("outputHelp callback must return a string or a Buffer")}if(t.write(a),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",t),this._getCommandAndAncestors().forEach((s)=>s.emit("afterAllHelp",t))}helpOption(e,o){if(typeof e==="boolean"){if(e)this._helpOption=this._helpOption??void 0;else this._helpOption=null;return this}return e=e??"-h, --help",o=o??"display help for command",this._helpOption=this.createOption(e,o),this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption(e){return this._helpOption=e,this}help(e){this.outputHelp(e);let o=T.exitCode||0;if(o===0&&e&&typeof e!=="function"&&e.error)o=1;this._exit(o,"commander.help","(outputHelp)")}addHelpText(e,o){let t=["beforeAll","before","after","afterAll"];if(!t.includes(e))throw Error(`Unexpected value for position to addHelpText.
|
|
22
21
|
Expecting one of '${t.join("', '")}'`);let a=`${e}Help`;return this.on(a,(s)=>{let i;if(typeof o==="function")i=o({error:s.error,command:s.command});else i=o;if(i)s.write(`${i}
|
|
23
|
-
`)}),this}_outputHelpIfRequested(e){let o=this._getHelpOption();if(o&&e.find((a)=>o.is(a)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function Pe(e){return e.map((o)=>{if(!o.startsWith("--inspect"))return o;let t,a="127.0.0.1",s="9229",i;if((i=o.match(/^(--inspect(-brk)?)$/))!==null)t=i[1];else if((i=o.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(t=i[1],/^\d+$/.test(i[3]))s=i[3];else a=i[3];else if((i=o.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)t=i[1],a=i[3],s=i[4];if(t&&s!=="0")return`${t}=${a}:${parseInt(s)+1}`;return o})}Pt.Command=he});var ze=O((Et)=>{var{Argument:xe}=$(),{Command:ge}=De(),{CommanderError:xt,InvalidArgumentError:Re}=C(),{Help:Rt}=ne(),{Option:Ee}=de();Et.program=new ge;Et.createCommand=(e)=>new ge(e);Et.createOption=(e,o)=>new Ee(e,o);Et.createArgument=(e,o)=>new xe(e,o);Et.Command=ge;Et.Option=Ee;Et.Argument=xe;Et.Help=Rt;Et.CommanderError=xt;Et.InvalidArgumentError=Re;Et.InvalidOptionArgumentError=Re});var Be=tt(ze(),1),{program:
|
|
24
|
-
Either set DATAFORSEO_LOGIN and DATAFORSEO_PASSWORD env vars, or run: dfs login --login <email> --password <api_password>`)}function Ce(e){return ia(la(
|
|
22
|
+
`)}),this}_outputHelpIfRequested(e){let o=this._getHelpOption();if(o&&e.find((a)=>o.is(a)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function Pe(e){return e.map((o)=>{if(!o.startsWith("--inspect"))return o;let t,a="127.0.0.1",s="9229",i;if((i=o.match(/^(--inspect(-brk)?)$/))!==null)t=i[1];else if((i=o.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(t=i[1],/^\d+$/.test(i[3]))s=i[3];else a=i[3];else if((i=o.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)t=i[1],a=i[3],s=i[4];if(t&&s!=="0")return`${t}=${a}:${parseInt(s)+1}`;return o})}Pt.Command=he});var ze=O((Et)=>{var{Argument:xe}=$(),{Command:ge}=De(),{CommanderError:xt,InvalidArgumentError:Re}=C(),{Help:Rt}=ne(),{Option:Ee}=de();Et.program=new ge;Et.createCommand=(e)=>new ge(e);Et.createOption=(e,o)=>new Ee(e,o);Et.createArgument=(e,o)=>new xe(e,o);Et.Command=ge;Et.Option=Ee;Et.Argument=xe;Et.Help=Rt;Et.CommanderError=xt;Et.InvalidArgumentError=Re;Et.InvalidOptionArgumentError=Re});var Be=tt(ze(),1),{program:vs,createCommand:_s,createArgument:ys,createOption:ks,CommanderError:ws,InvalidArgumentError:bs,InvalidOptionArgumentError:Ts,Command:N,Argument:Is,Option:Oe,Help:Ss}=Be.default;var c=Object.freeze({NONE:"none",PATH:"path",TEXT:"text"});class p{short;long;valueKind;numericShorthand;description;defaultValue;required;constructor(e={}){this.short=e.short??null,this.long=e.long??null,this.valueKind=e.valueKind??c.NONE,this.numericShorthand=e.numericShorthand??!1,this.description=e.description??null,this.defaultValue=e.defaultValue??null,this.required=e.required??!1,Object.freeze(this)}get name(){return this.long??this.short??""}}class q{kind;name;variadic;required;constructor(e={}){this.kind=e.kind??c.PATH,this.name=e.name??"arg",this.variadic=e.variadic??!1,this.required=e.required??!0,Object.freeze(this)}}class h{options;positional;rest;ignoreTokens;description;constructor(e={}){this.options=Object.freeze([...e.options??[]]),this.positional=Object.freeze([...e.positional??[]]),this.rest=e.rest??null,this.ignoreTokens=new Set(e.ignoreTokens??[]),this.description=e.description??null,Object.freeze(this)}}class qe{flags;args;cachePaths;pathFlagValues;constructor(e){this.flags=e.flags,this.args=e.args,this.cachePaths=e.cachePaths??[],this.pathFlagValues=e.pathFlagValues??[]}paths(){return this.args.filter(([,e])=>e===c.PATH).map(([e])=>e)}routingPaths(){return[...this.paths(),...this.pathFlagValues]}texts(){return this.args.filter(([,e])=>e===c.TEXT).map(([e])=>e)}flag(e,o=null){return this.flags[e]??o}}class L{stdout;stderr;exitCode;reads;writes;cache;streamSource;constructor(e={}){this.stdout=Ye(e.stdout??null),this.stderr=Ye(e.stderr??null),this.exitCode=e.exitCode??0,this.reads=e.reads??{},this.writes=e.writes??{},this.cache=e.cache??[],this.streamSource=null}}function Ye(e){if(e===null||e===void 0)return null;if(e instanceof Uint8Array)return e;if(typeof e==="string")return new TextEncoder().encode(e);return null}function g(e){return Object.freeze({name:e.name,resource:e.resource??null,spec:e.spec,fn:e.fn,description:e.description??e.spec.description??null})}function A(e){return Object.freeze({name:e.name,description:e.description??null,commands:Object.freeze([...e.commands??[]]),groups:Object.freeze([...e.groups??[]])})}var Xt=new TextDecoder;async function Wt(e,o={}){let t=Array.isArray(o)?Me(e.spec,o):o,a={flags:t.flags??{},stdin:t.stdin??null},s=await e.fn({},t.paths??[],t.texts??[],a),[i,n]=jt(s),r=await Fe(i??n.stdout);return{bytes:r,text:Xt.decode(r),result:n}}function jt(e){if(!e)return[null,new L];return e}async function Fe(e){if(e===null)return new Uint8Array;if(e instanceof Uint8Array)return e;let o=[];for await(let i of e)o.push(i);let t=0;for(let i of o)t+=i.byteLength;let a=new Uint8Array(t),s=0;for(let i of o)a.set(i,s),s+=i.byteLength;return a}function Me(e,o){let t={},a=[];for(let r of e.options)if(r.defaultValue!==null&&r.defaultValue!==void 0)t[r.name]=r.defaultValue;else if(r.valueKind===c.NONE)t[r.name]=!1;let s=0;while(s<o.length){let r=o[s]??"";if(r==="--"){a.push(...o.slice(s+1));break}let d=Jt(e,r);if(d){s+=$t(d,r,o,s,t);continue}a.push(r),s+=1}let{paths:i,texts:n}=Qt(e,a);return{paths:i,texts:n,flags:t}}function Jt(e,o){if(o.startsWith("--")){let t=o.slice(2).split("=")[0];return e.options.find((a)=>a.long===t)}if(o.startsWith("-")&&o.length>1){let t=o[1];return e.options.find((a)=>a.short===t)}return}function $t(e,o,t,a,s){if(e.valueKind===c.NONE)return s[e.name]=!0,1;if(o.includes("="))return s[e.name]=o.slice(o.indexOf("=")+1),1;return s[e.name]=t[a+1]??"",2}function Qt(e,o){let t=[],a=[],s=0;for(let i of e.positional){if(s>=o.length)break;if(i.variadic){Q(i.kind,o.slice(s),t,a),s=o.length;break}Q(i.kind,[o[s]],t,a),s+=1}if(s<o.length&&e.rest)Q(e.rest.kind,o.slice(s),t,a);return{paths:t,texts:a}}function Q(e,o,t,a){if(e===c.PATH)t.push(...o);else if(e===c.TEXT)a.push(...o)}function x(e){let o=new N(e.name);if(e.description)o.description(e.description);return Vt(o,e.spec),o.action(async(...t)=>{let a=t[t.length-1],s=t[t.length-2],i=t.slice(0,-2),{paths:n,texts:r,flags:d}=oa(e.spec,i,s),l=await e.fn({},n,r,{flags:d}),[_,b]=l??[null,new L],U=await Fe(_??b.stdout);if(U.byteLength>0)process.stdout.write(U);if(b.stderr)process.stderr.write(b.stderr);if(b.exitCode!==0)process.exit(b.exitCode)}),o}function P(e,o){let t=new N(o.name);if(o.description)t.description(o.description);for(let a of o.groups)P(t,a);for(let a of o.commands)t.addCommand(x(a));return e.addCommand(t),t}function Vt(e,o){for(let t of o.positional){let a=t.variadic?`<${t.name}...>`:t.required?`<${t.name}>`:`[${t.name}]`;e.argument(a)}if(o.rest)e.argument(`[${o.rest.name}...]`);for(let t of o.options)e.addOption(Zt(t))}function Zt(e){let o=new Oe(ea(e),e.description??void 0);if(e.defaultValue!==null)o.default(e.defaultValue);if(e.required)o.makeOptionMandatory(!0);return o}function ea(e){let o=[];if(e.short)o.push(`-${e.short}`);if(e.long)o.push(`--${e.long}`);let t=o.join(", ");if(e.valueKind!==c.NONE)t+=` <${e.long??e.short}>`;return t}function oa(e,o,t){let a=[],s=[];e.positional.forEach((n,r)=>{let d=o[r];if(d===void 0||d===null)return;let l=Array.isArray(d)?d:[String(d)];Q(n.kind,l,a,s)});let i={};for(let n of e.options){let r=ta(n.long??n.short??"");if(r in t){let d=t[r];if(typeof d==="string"||typeof d==="boolean")i[n.name]=d}}return{paths:a,texts:s,flags:i}}function ta(e){return e.replace(/-([a-z])/g,(o,t)=>t.toUpperCase())}function aa(e,o={}){return[typeof e==="string"?new TextEncoder().encode(e):e,new L({exitCode:o.exitCode??0,stderr:o.stderr??null})]}import{existsSync as sa,mkdirSync as ia,readFileSync as ra,writeFileSync as na,chmodSync as da}from"node:fs";import{homedir as ca}from"node:os";import{dirname as la,join as pa}from"node:path";var Y=pa(ca(),".config","dataforseo","config.json");function Ke(){return Y}function H(){let e=ha();if(e)return e;if(sa(Y)){let o=ra(Y,"utf8"),t=JSON.parse(o);if(t.login&&t.password)return{login:t.login,password:t.password}}throw Error(`No DataForSEO credentials found.
|
|
23
|
+
Either set DATAFORSEO_LOGIN and DATAFORSEO_PASSWORD env vars, or run: dfs login --login <email> --password <api_password>`)}function Ce(e){return ia(la(Y),{recursive:!0}),na(Y,JSON.stringify(e,null,2)),da(Y,384),Y}function me({login:e,password:o}){return"Basic "+Buffer.from(`${e}:${o}`).toString("base64")}function ha(){let e=process.env.DATAFORSEO_LOGIN,o=process.env.DATAFORSEO_PASSWORD;if(e&&o)return{login:e,password:o};return null}var ga="https://api.dataforseo.com";async function v(e,o,t={}){let a=H(),s=Ne(e,t.baseUrl),i=ma(o,t.wrapAsTaskArray??!0),n=new AbortController,r=setTimeout(()=>n.abort(),t.timeoutMs??120000),d;try{d=await fetch(s,{method:"POST",headers:{Authorization:me(a),"Content-Type":"application/json","User-Agent":"dataforseo-cli/0.1.0"},body:i===void 0?void 0:JSON.stringify(i),signal:n.signal})}finally{clearTimeout(r)}let l=await d.text(),_;try{_=l?JSON.parse(l):{}}catch{throw Error(`HTTP ${d.status}: non-JSON response: ${l.slice(0,500)}`)}if(!d.ok){let b=_.status_message??`HTTP ${d.status}`;throw Error(`DataForSEO error: ${b}`)}return _}async function R(e,o={}){let t=H(),a=Ne(e,o.baseUrl),s=new AbortController,i=setTimeout(()=>s.abort(),o.timeoutMs??60000),n;try{n=await fetch(a,{method:"GET",headers:{Authorization:me(t),"User-Agent":"dataforseo-cli/0.1.0"},signal:s.signal})}finally{clearTimeout(i)}let r=await n.text(),d=r?JSON.parse(r):{};if(!n.ok)throw Error(`DataForSEO error: ${d.status_message??`HTTP ${n.status}`}`);return d}function Ne(e,o){let t=e.trim();if(!t.startsWith("/"))t="/"+t;if(!t.startsWith("/v3/"))t="/v3"+t;return(o??ga)+t}function ma(e,o){if(e===void 0||e===null)return;if(Array.isArray(e))return e;if(o&&typeof e==="object")return[e];return e}function He(e){let o=e.tasks??[],t=[];for(let a of o){let s=a.result;if(!Array.isArray(s))continue;for(let i of s)if(i&&typeof i==="object"&&Array.isArray(i.items))t.push(...i.items);else t.push(i)}return t}function je(e,o){if(o.format==="raw")return JSON.stringify(e,null,2);let t=o.full?e:He(e);switch(o.format){case"json":return JSON.stringify(t,null,2);case"ndjson":return Array.isArray(t)?t.map((a)=>JSON.stringify(a)).join(`
|
|
25
24
|
`):JSON.stringify(t);case"table":return fa(Xe(t),o.columns);case"csv":return ua(Xe(t),o.columns)}}function Xe(e){if(Array.isArray(e))return e.filter((o)=>o!==null&&typeof o==="object"&&!Array.isArray(o));if(e&&typeof e==="object")return[e];return[]}function fa(e,o){if(e.length===0)return"(no rows)";let t=o??Je(e),a=t.map((i)=>Math.max(i.length,...e.map((n)=>fe(n[i]).length))),s=[];s.push(t.map((i,n)=>i.padEnd(a[n]??i.length)).join(" ")),s.push(a.map((i)=>"-".repeat(i)).join(" "));for(let i of e)s.push(t.map((n,r)=>fe(i[n]).padEnd(a[r]??0)).join(" "));return s.join(`
|
|
26
25
|
`)}function ua(e,o){if(e.length===0)return"";let t=o??Je(e),a=[t.map(We).join(",")];for(let s of e)a.push(t.map((i)=>We(fe(s[i]))).join(","));return a.join(`
|
|
27
26
|
`)}function Je(e){let o=new Set;for(let t of e)for(let a of Object.keys(t))o.add(a);return[...o]}function fe(e){if(e===null||e===void 0)return"";if(typeof e==="string")return e;if(typeof e==="number"||typeof e==="boolean")return String(e);return JSON.stringify(e)}function We(e){if(/[",\n\r]/.test(e))return`"${e.replace(/"/g,'""')}"`;return e}var va=new TextEncoder,m=Object.freeze([new p({short:"o",long:"output",valueKind:c.TEXT,description:"Output format: json|ndjson|table|csv|raw (default json).",defaultValue:"json"}),new p({long:"columns",valueKind:c.TEXT,description:"Comma-separated columns for table/csv output."}),new p({long:"full",valueKind:c.NONE,description:"Emit the full response (skip the items extraction)."}),new p({long:"no-cost",valueKind:c.NONE,description:"Don't print the response cost on stderr."})]);function f(e,o){let t=o.flags??{},a=t.output??"json",s=t.full===!0,i=t["no-cost"]===!0,n=t.columns,r=typeof n==="string"?n.split(",").map((b)=>b.trim()).filter(Boolean):void 0,d=je(e,{format:a,full:s,columns:r}),l=va.encode(d.endsWith(`
|
|
28
27
|
`)?d:d+`
|
|
29
28
|
`),_=!i&&typeof e.cost==="number"&&e.cost>0?`[cost] $${e.cost.toFixed(4)}
|
|
30
|
-
`:null;return[l,new L({exitCode:0,stderr:_})]}var w=Object.freeze([new p({long:"location",valueKind:c.TEXT,description:'Location name (default "United States").',defaultValue:"United States"}),new p({long:"location-code",valueKind:c.TEXT,description:"Location code, overrides --location."}),new p({long:"language",valueKind:c.TEXT,description:'Language name (default "English").',defaultValue:"English"}),new p({long:"language-code",valueKind:c.TEXT,description:"Language code, overrides --language."})]);function k(e){let o=e.flags??{},t={},a=o["location-code"];if(typeof a==="string"&&a)t.locationCode=Number(a);else t.locationName=o.location??"United States";let s=o["language-code"];if(typeof s==="string"&&s)t.languageCode=s;else t.languageName=o.language??"English";return t}function u(e,o={}){return new
|
|
29
|
+
`:null;return[l,new L({exitCode:0,stderr:_})]}var w=Object.freeze([new p({long:"location",valueKind:c.TEXT,description:'Location name (default "United States").',defaultValue:"United States"}),new p({long:"location-code",valueKind:c.TEXT,description:"Location code, overrides --location."}),new p({long:"language",valueKind:c.TEXT,description:'Language name (default "English").',defaultValue:"English"}),new p({long:"language-code",valueKind:c.TEXT,description:"Language code, overrides --language."})]);function k(e){let o=e.flags??{},t={},a=o["location-code"];if(typeof a==="string"&&a)t.locationCode=Number(a);else t.locationName=o.location??"United States";let s=o["language-code"];if(typeof s==="string"&&s)t.languageCode=s;else t.languageName=o.language??"English";return t}function u(e,o={}){return new q({kind:c.TEXT,name:e,...o})}function y(e,o,t){let a=e.flags?.[o];return typeof a==="string"?a:t??""}function G(e,o){return e.flags?.[o]===!0}function I(e,o,t){let a=e.flags?.[o];if(typeof a==="string"&&a)return Number(a);return t}function X(e){let o={};if(e.locationCode!==void 0)o.location_code=e.locationCode;else o.location_name=e.locationName??"United States";if(e.languageCode!==void 0)o.language_code=e.languageCode;else o.language_name=e.languageName??"English";return o}var _a={chatgpt:"ai_optimization/chat_gpt/llm_responses/live",claude:"ai_optimization/claude/llm_responses/live",gemini:"ai_optimization/gemini/llm_responses/live",perplexity:"ai_optimization/perplexity/llm_responses/live"};async function $e(e){return v("ai_optimization/ai_keyword_data/keywords_search_volume/live",{...X(e),keywords:e.keywords})}async function Qe(e){return v("ai_optimization/llm_mentions/search/live",{...X(e),target:e.keywords.map((o)=>({keyword:o}))})}async function Ve(e){return v("ai_optimization/llm_mentions/top_pages/live",{...X(e),target:e.keywords.map((o)=>({keyword:o}))})}async function Ze(e){return v("ai_optimization/llm_mentions/top_domains/live",{...X(e),target:e.keywords.map((o)=>({keyword:o}))})}async function eo(e){return v("ai_optimization/llm_mentions/aggregated_metrics/live",{...X(e),target:e.keywords.map((o)=>({keyword:o}))})}async function oo(e){return v(_a[e.model],{system_message:e.systemMessage,message_chain:[{role:"user",message:e.message}],max_output_tokens:e.maxOutputTokens??512,temperature:e.temperature??0.3,top_p:e.topP??0.5})}var F="ram",ya=g({name:"search-volume",resource:F,spec:new h({description:"AI-tool search volume — how often a keyword is typed at LLMs.",positional:[u("keywords",{variadic:!0})],options:[...w,...m]}),fn:async(e,o,t,a)=>{let s=await $e({...k(a),keywords:[...t]});return f(s,a)}}),ka=g({name:"mentions",resource:F,spec:new h({description:"Search LLM mentions for one or more keyword targets.",positional:[u("keywords",{variadic:!0})],options:[...w,...m]}),fn:async(e,o,t,a)=>{let s=await Qe({...k(a),keywords:[...t]});return f(s,a)}}),wa=g({name:"top-pages",resource:F,spec:new h({description:"Top pages cited by AI for the given keyword targets.",positional:[u("keywords",{variadic:!0})],options:[...w,...m]}),fn:async(e,o,t,a)=>{let s=await Ve({...k(a),keywords:[...t]});return f(s,a)}}),ba=g({name:"top-domains",resource:F,spec:new h({description:"Top domains cited by AI for the given keyword targets.",positional:[u("keywords",{variadic:!0})],options:[...w,...m]}),fn:async(e,o,t,a)=>{let s=await Ze({...k(a),keywords:[...t]});return f(s,a)}}),Ta=g({name:"metrics",resource:F,spec:new h({description:"Aggregated LLM mention metrics (volume, sentiment) for keyword targets.",positional:[u("keywords",{variadic:!0})],options:[...w,...m]}),fn:async(e,o,t,a)=>{let s=await eo({...k(a),keywords:[...t]});return f(s,a)}}),Ia=g({name:"ask",resource:F,spec:new h({description:"Ask a specific LLM via DataForSEO's metered proxy.",positional:[u("message")],options:[new p({long:"model",valueKind:c.TEXT,description:"chatgpt | claude | gemini | perplexity.",defaultValue:"chatgpt"}),new p({long:"system",valueKind:c.TEXT,description:"Optional system message."}),new p({long:"max-tokens",valueKind:c.TEXT,description:"Max output tokens (default 512).",defaultValue:"512"}),new p({long:"temperature",valueKind:c.TEXT,description:"Sampling temperature (default 0.3).",defaultValue:"0.3"}),...m]}),fn:async(e,o,t,a)=>{let s=y(a,"model","chatgpt"),i=y(a,"system")||void 0,n=await oo({model:s,message:t[0]??"",systemMessage:i,maxOutputTokens:I(a,"max-tokens",512),temperature:Number(y(a,"temperature","0.3"))});return f(n,a)}}),to=A({name:"ai",description:"AI Optimization: LLM mentions, top pages/domains, AI search volume, LLM proxy.",commands:[ya,ka,wa,ba,Ta,Ia]});async function ao(e){return v("backlinks/summary/live",{target:e})}async function so(e){return v("backlinks/backlinks/live",{target:e.target,limit:e.limit??100,mode:e.mode??"as_is"})}async function io(e){return v("backlinks/referring_domains/live",{target:e.target,limit:e.limit??100})}async function ro(e){return v("backlinks/anchors/live",{target:e.target,limit:e.limit??100})}async function no(e){return v("backlinks/competitors/live",{target:e.target,limit:e.limit??100})}async function co(e){return v("backlinks/bulk_ranks/live",{targets:e})}var M="ram",V=new p({long:"limit",valueKind:c.TEXT,description:"Max results.",defaultValue:"100"}),Sa=g({name:"summary",resource:M,spec:new h({description:"High-level backlink summary for a target.",positional:[u("target")],options:[...m]}),fn:async(e,o,t,a)=>{let s=await ao(t[0]??"");return f(s,a)}}),La=g({name:"list",resource:M,spec:new h({description:"List individual backlinks.",positional:[u("target")],options:[V,new p({long:"mode",valueKind:c.TEXT,description:"as_is | one_per_domain | one_per_anchor.",defaultValue:"as_is"}),...m]}),fn:async(e,o,t,a)=>{let s=await so({target:t[0]??"",limit:I(a,"limit",100),mode:y(a,"mode","as_is")});return f(s,a)}}),Aa=g({name:"referring-domains",resource:M,spec:new h({description:"Referring domains pointing to a target.",positional:[u("target")],options:[V,...m]}),fn:async(e,o,t,a)=>{let s=await io({target:t[0]??"",limit:I(a,"limit",100)});return f(s,a)}}),Ga=g({name:"anchors",resource:M,spec:new h({description:"Anchor text distribution for a target.",positional:[u("target")],options:[V,...m]}),fn:async(e,o,t,a)=>{let s=await ro({target:t[0]??"",limit:I(a,"limit",100)});return f(s,a)}}),Ua=g({name:"competitors",resource:M,spec:new h({description:"Domains with similar backlink profiles.",positional:[u("target")],options:[V,...m]}),fn:async(e,o,t,a)=>{let s=await no({target:t[0]??"",limit:I(a,"limit",100)});return f(s,a)}}),Pa=g({name:"ranks",resource:M,spec:new h({description:"Bulk DataForSEO domain rank for up to 1000 targets.",positional:[u("targets",{variadic:!0})],options:[...m]}),fn:async(e,o,t,a)=>{let s=await co([...t]);return f(s,a)}}),lo=A({name:"backlinks",description:"Backlink profiles, referring domains, anchors.",commands:[Sa,La,Aa,Ga,Ua,Pa]});var po=[{path:"/v3/serp/id_list",method:"post",operationId:"IdList",tag:"Serp",description:`This endpoint is designed to provide you with a list of IDs and metadata for all SERP tasks created within the specified time period, including both successful and uncompleted tasks.
|
|
31
30
|
for more info please visit 'https://docs.dataforseo.com/v3/serp/id_list/?bash'`,docUrl:"https://docs.dataforseo.com/v3/serp/id_list/",example:[{datetime_from:"2026-04-12 04:39:39 +00:00",datetime_to:"2026-04-14 04:39:39 +00:00",limit:100,offset:0,sort:"desc",include_metadata:!0}]},{path:"/v3/serp/errors",method:"post",operationId:"Errors",tag:"Serp",description:`By calling this endpoint you will receive information about the SERP API tasks that returned an error within the past 7 days.
|
|
32
31
|
for more info please visit 'https://docs.dataforseo.com/v3/serp/errors/?bash'`,docUrl:"https://docs.dataforseo.com/v3/serp/errors/",example:[{limit:10,offset:0,filtered_function:"pingback_url"}]},{path:"/v3/serp/screenshot",method:"post",operationId:"Screenshot",tag:"Serp",description:`Using the Live Page Screenshot endpoint, you can capture a screenshot of any SERP page.
|
|
33
32
|
for more info please visit 'https://docs.dataforseo.com/v3/serp/screenshot/?bash'`,docUrl:"https://docs.dataforseo.com/v3/serp/screenshot/",example:[{task_id:"06211235-0696-0139-1000-36727fbd3c90",browser_screen_scale_factor:0.5}]},{path:"/v3/serp/ai_summary",method:"post",operationId:"AiSummary",tag:"Serp",description:`The purpose of the Live SERP API AI Summary endpoint is to provide a summary of the content found on any SERP and generate a response based on the user’s specified prompt.
|
|
@@ -659,7 +658,7 @@ for more info please visit 'https://docs.dataforseo.com/v3/appendix/user_data/?b
|
|
|
659
658
|
for more info please visit 'https://docs.dataforseo.com/v3/appendix/errors/?bash'`,docUrl:"https://docs.dataforseo.com/v3/appendix/errors/"},{path:"/v3/appendix/webhook_resend",method:"post",operationId:"WebhookResend",tag:"Appendix",description:`Using this endpoint you can resend webhooks (pingbacks and postbacks) for up to 100 specified tasks.
|
|
660
659
|
Note: Your account will not be double-charged for resending a webhook.
|
|
661
660
|
for more info please visit 'https://docs.dataforseo.com/v3/appendix/webhook_resend/?bash'`,docUrl:"https://docs.dataforseo.com/v3/appendix/webhook_resend/",example:[{id:"08161139-0001-0066-1000-06491d097ed5"}]},{path:"/v3/appendix/status",method:"get",operationId:"AppendixStatus",tag:"Appendix",description:`By calling this API you will receive detailed information about the current status of all our APIs and endpoints. You will also get a full issue description if a problem occurs.
|
|
662
|
-
for more info please visit 'https://docs.dataforseo.com/v3/appendix/status/?bash'`,docUrl:"https://docs.dataforseo.com/v3/appendix/status/"}];var ue=po;function go(){return ue}function Z(e){let o=ho(e);return ue.find((t)=>ho(t.path)===o)}function mo(e,o){let t=e.toLowerCase();return ue.filter((a)=>{if(o&&a.tag?.toLowerCase()!==o.toLowerCase())return!1;if(!t)return!0;return a.path.toLowerCase().includes(t)||a.operationId?.toLowerCase().includes(t)||a.description?.toLowerCase().includes(t)})}function ho(e){let o=e.trim();if(!o.startsWith("/"))o="/"+o;if(!o.startsWith("/v3/"))o="/v3"+o;return o.replace(/\/+$/,"")}var ve="ram",ee=new TextEncoder,xa=g({name:"list",resource:ve,spec:new h({description:"List endpoints, optionally filtered by tag and/or query.",options:[new p({short:"t",long:"tag",valueKind:c.TEXT,description:"Filter by tag."}),new p({short:"q",long:"query",valueKind:c.TEXT,description:"Substring match."}),new p({long:"json",valueKind:c.NONE,description:"Emit JSON instead of lines."})]}),fn:async(e,o,t,a)=>{let s=y(a,"tag")||void 0,i=mo(y(a,"query",""),s);if(
|
|
661
|
+
for more info please visit 'https://docs.dataforseo.com/v3/appendix/status/?bash'`,docUrl:"https://docs.dataforseo.com/v3/appendix/status/"}];var ue=po;function go(){return ue}function Z(e){let o=ho(e);return ue.find((t)=>ho(t.path)===o)}function mo(e,o){let t=e.toLowerCase();return ue.filter((a)=>{if(o&&a.tag?.toLowerCase()!==o.toLowerCase())return!1;if(!t)return!0;return a.path.toLowerCase().includes(t)||a.operationId?.toLowerCase().includes(t)||a.description?.toLowerCase().includes(t)})}function ho(e){let o=e.trim();if(!o.startsWith("/"))o="/"+o;if(!o.startsWith("/v3/"))o="/v3"+o;return o.replace(/\/+$/,"")}var ve="ram",ee=new TextEncoder,xa=g({name:"list",resource:ve,spec:new h({description:"List endpoints, optionally filtered by tag and/or query.",options:[new p({short:"t",long:"tag",valueKind:c.TEXT,description:"Filter by tag."}),new p({short:"q",long:"query",valueKind:c.TEXT,description:"Substring match."}),new p({long:"json",valueKind:c.NONE,description:"Emit JSON instead of lines."})]}),fn:async(e,o,t,a)=>{let s=y(a,"tag")||void 0,i=mo(y(a,"query",""),s);if(G(a,"json"))return[ee.encode(JSON.stringify(i,null,2)+`
|
|
663
662
|
`),new L];let n=i.map((r)=>`${r.method.toUpperCase().padEnd(4)} ${r.path}`).join(`
|
|
664
663
|
`);return[ee.encode(n+`
|
|
665
664
|
`),new L({stderr:`
|
|
@@ -676,12 +675,11 @@ example body:
|
|
|
676
675
|
${JSON.stringify(s.example,null,2)}
|
|
677
676
|
`;return[ee.encode(i),new L]}}),Ea=g({name:"tags",resource:ve,spec:new h({description:"List all tags and how many endpoints each has."}),fn:async()=>{let e=new Map;for(let a of go()){let s=a.tag??"(untagged)";e.set(s,(e.get(s)??0)+1)}let t=[...e.entries()].sort((a,s)=>s[1]-a[1]).map(([a,s])=>`${String(s).padStart(4)} ${a}`).join(`
|
|
678
677
|
`);return[ee.encode(t+`
|
|
679
|
-
`),new L]}}),fo=
|
|
678
|
+
`),new L]}}),fo=A({name:"endpoints",description:"Discover and inspect DataForSEO endpoints.",commands:[xa,Ra,Ea]});function oe(e){let o={};if(e.locationCode!==void 0)o.location_code=e.locationCode;else o.location_name=e.locationName??"United States";if(e.languageCode!==void 0)o.language_code=e.languageCode;else o.language_name=e.languageName??"English";return o}async function uo(e){return v("keywords_data/google_ads/search_volume/live",{...oe(e),keywords:e.keywords,include_serp_info:e.includeSerpInfo??!1})}async function vo(e){return v("dataforseo_labs/google/keyword_ideas/live",{...oe(e),keywords:e.keywords,limit:e.limit??100})}async function _o(e){return v("dataforseo_labs/google/keyword_suggestions/live",{...oe(e),keyword:e.keyword,limit:e.limit??100})}async function yo(e){return v("dataforseo_labs/google/ranked_keywords/live",{...oe(e),target:e.target,limit:e.limit??100})}var te="ram";function ae(e){return k(e)}var za=g({name:"search-volume",resource:te,spec:new h({description:"Get monthly search volume / CPC / competition for keywords.",positional:[u("keywords",{variadic:!0})],options:[...w,new p({long:"include-serp-info",valueKind:c.NONE,description:"Also return SERP feature snapshot."}),...m]}),fn:async(e,o,t,a)=>{let s=await uo({...ae(a),keywords:[...t],includeSerpInfo:G(a,"include-serp-info")});return f(s,a)}}),Ba=g({name:"ideas",resource:te,spec:new h({description:"Get keyword ideas (DataForSEO Labs).",positional:[u("keywords",{variadic:!0})],options:[...w,new p({long:"limit",valueKind:c.TEXT,description:"Max results.",defaultValue:"100"}),...m]}),fn:async(e,o,t,a)=>{let s=await vo({...ae(a),keywords:[...t],limit:I(a,"limit",100)});return f(s,a)}}),Oa=g({name:"suggestions",resource:te,spec:new h({description:"Get keyword suggestions for a seed keyword.",positional:[u("keyword")],options:[...w,new p({long:"limit",valueKind:c.TEXT,description:"Max results.",defaultValue:"100"}),...m]}),fn:async(e,o,t,a)=>{let s=await _o({...ae(a),keyword:t[0]??"",limit:I(a,"limit",100)});return f(s,a)}}),Ya=g({name:"ranked",resource:te,spec:new h({description:"Keywords a target domain or URL ranks for.",positional:[u("target")],options:[...w,new p({long:"limit",valueKind:c.TEXT,description:"Max results.",defaultValue:"100"}),...m]}),fn:async(e,o,t,a)=>{let s=await yo({...ae(a),target:t[0]??"",limit:I(a,"limit",100)});return f(s,a)}}),ko=A({name:"keywords",description:"Search volume, ideas, suggestions.",commands:[za,Ba,Oa,Ya]});function E(e){let o={};if(e.locationCode!==void 0)o.location_code=e.locationCode;else o.location_name=e.locationName??"United States";if(e.languageCode!==void 0)o.language_code=e.languageCode;else o.language_name=e.languageName??"English";return o}async function wo(e){return v("dataforseo_labs/google/competitors_domain/live",{...E(e),target:e.target,limit:e.limit??100})}async function bo(e){return v("dataforseo_labs/google/domain_intersection/live",{...E(e),target1:e.target1,target2:e.target2,limit:e.limit??100})}async function To(e){return v("dataforseo_labs/google/domain_rank_overview/live",{...E(e),target:e.target})}async function Io(e){return v("dataforseo_labs/google/related_keywords/live",{...E(e),keyword:e.keyword,limit:e.limit??100})}async function So(e){return v("dataforseo_labs/google/keyword_overview/live",{...E(e),keywords:e.keywords,include_serp_info:e.includeSerpInfo??!1,include_clickstream_data:e.includeClickstream??!1})}async function Lo(e){return v("dataforseo_labs/google/bulk_keyword_difficulty/live",{...E(e),keywords:e.keywords})}async function Ao(e){return v("dataforseo_labs/google/search_intent/live",{...E(e),keywords:e.keywords})}async function Go(e){return v("dataforseo_labs/google/top_searches/live",{...E(e),limit:e.limit??100})}async function Uo(e){return v("dataforseo_labs/google/historical_rank_overview/live",{...E(e),target:e.target})}var z="ram",se=new p({long:"limit",valueKind:c.TEXT,description:"Max results.",defaultValue:"100"}),qa=g({name:"competitors",resource:z,spec:new h({description:"Domains competing with the target on organic search.",positional:[u("target")],options:[...w,se,...m]}),fn:async(e,o,t,a)=>{let s=await wo({...k(a),target:t[0]??"",limit:I(a,"limit",100)});return f(s,a)}}),Fa=g({name:"intersection",resource:z,spec:new h({description:"Keyword overlap between two domains.",positional:[u("target1"),u("target2")],options:[...w,se,...m]}),fn:async(e,o,t,a)=>{let s=await bo({...k(a),target1:t[0]??"",target2:t[1]??"",limit:I(a,"limit",100)});return f(s,a)}}),Ma=g({name:"overview",resource:z,spec:new h({description:"Domain rank overview (organic + paid traffic estimates).",positional:[u("target")],options:[...w,...m]}),fn:async(e,o,t,a)=>{let s=await To({...k(a),target:t[0]??""});return f(s,a)}}),Ka=g({name:"related",resource:z,spec:new h({description:"Semantically related keywords.",positional:[u("keyword")],options:[...w,se,...m]}),fn:async(e,o,t,a)=>{let s=await Io({...k(a),keyword:t[0]??"",limit:I(a,"limit",100)});return f(s,a)}}),Ca=g({name:"keyword-overview",resource:z,spec:new h({description:"Full keyword profile: KD + volume + intent + SERP + backlinks for keywords.",positional:[u("keywords",{variadic:!0})],options:[...w,new p({long:"include-serp-info",valueKind:c.NONE,description:"Include SERP feature snapshot."}),new p({long:"include-clickstream",valueKind:c.NONE,description:"Include clickstream-derived volume."}),...m]}),fn:async(e,o,t,a)=>{let s=await So({...k(a),keywords:[...t],includeSerpInfo:G(a,"include-serp-info"),includeClickstream:G(a,"include-clickstream")});return f(s,a)}}),Na=g({name:"bulk-difficulty",resource:z,spec:new h({description:"Bulk keyword difficulty (KD) for up to 1000 keywords in one call.",positional:[u("keywords",{variadic:!0})],options:[...w,...m]}),fn:async(e,o,t,a)=>{let s=await Lo({...k(a),keywords:[...t]});return f(s,a)}}),Ha=g({name:"intent",resource:z,spec:new h({description:"Classify search intent (informational/navigational/commercial/transactional) for keywords.",positional:[u("keywords",{variadic:!0})],options:[...w,...m]}),fn:async(e,o,t,a)=>{let s=await Ao({...k(a),keywords:[...t]});return f(s,a)}}),Xa=g({name:"top-searches",resource:z,spec:new h({description:"Currently-trending top searches in a location.",options:[...w,se,...m]}),fn:async(e,o,t,a)=>{let s=await Go({...k(a),limit:I(a,"limit",100)});return f(s,a)}}),Wa=g({name:"historical",resource:z,spec:new h({description:"Historical rank overview for a domain (month-by-month position counts).",positional:[u("target")],options:[...w,...m]}),fn:async(e,o,t,a)=>{let s=await Uo({...k(a),target:t[0]??""});return f(s,a)}}),Po=A({name:"labs",description:"DataForSEO Labs: competitors, gap analysis, keyword overview, intent, historical.",commands:[qa,Fa,Ma,Ka,Ca,Na,Ha,Xa,Wa]});var Do="ram",xo=new TextEncoder,Ro=g({name:"login",resource:Do,spec:new h({description:"Save DataForSEO credentials to ~/.config/dataforseo/config.json (chmod 600).",options:[new p({short:"l",long:"login",valueKind:c.TEXT,description:"API login (email).",required:!0}),new p({short:"p",long:"password",valueKind:c.TEXT,description:"API password.",required:!0}),new p({long:"no-verify",valueKind:c.NONE,description:"Skip the verification call."})]}),fn:async(e,o,t,a)=>{let s=y(a,"login"),i=y(a,"password");if(!G(a,"no-verify")){process.env.DATAFORSEO_LOGIN=s,process.env.DATAFORSEO_PASSWORD=i;try{await R("/v3/appendix/user_data")}catch(r){return[null,new L({exitCode:1,stderr:`Credentials rejected: ${r.message}
|
|
680
679
|
Run with --no-verify to save anyway.
|
|
681
680
|
`})]}}let n=Ce({login:s,password:i});return[xo.encode(`Saved credentials to ${n}
|
|
682
681
|
`),new L]}}),Eo=g({name:"whoami",resource:Do,spec:new h({description:"Show the configured login (and verify against DataForSEO)."}),fn:async()=>{let o=`login: ${H().login}
|
|
683
682
|
config: ${Ke()}
|
|
684
683
|
`,a=(await R("/v3/appendix/user_data")).tasks?.[0]?.result?.[0];if(a?.money?.balance!==void 0)o+=`balance: $${a.money.balance.toFixed(2)}
|
|
685
|
-
`;return[xo.encode(o),new L]}});async function zo(e="serp/google"){return R(`${e}/locations`)}async function Bo(e="serp/google"){return R(`${e}/languages`)}async function Oo(){return R("/v3/appendix/user_data")}var _e="ram",Yo=g({name:"locations",resource:_e,spec:new h({description:"List supported locations for a given API.",options:[new p({long:"api",valueKind:c.TEXT,description:"API path under /v3.",defaultValue:"serp/google"}),...m]}),fn:async(e,o,t,a)=>{let s=await zo(y(a,"api","serp/google"));return f(s,a)}}),qo=g({name:"languages",resource:_e,spec:new h({description:"List supported languages for a given API.",options:[new p({long:"api",valueKind:c.TEXT,description:"API path under /v3.",defaultValue:"serp/google"}),...m]}),fn:async(e,o,t,a)=>{let s=await Bo(y(a,"api","serp/google"));return f(s,a)}}),Fo=g({name:"user",resource:_e,spec:new h({description:"Show DataForSEO account info (balance, plan, limits).",options:[...m]}),fn:async(e,o,t,a)=>{let s=await Oo();return f(s,{...a,flags:{...a.flags,full:!0}})}});import{readFileSync as ja}from"node:fs";var Ja="ram",Mo=g({name:"raw",resource:Ja,spec:new h({description:"Hit any DataForSEO endpoint by path (escape hatch over the full 437-endpoint API).",positional:[u("path")],options:[new p({short:"d",long:"data",valueKind:c.TEXT,description:"Inline JSON body."}),new p({short:"f",long:"data-file",valueKind:c.TEXT,description:"Read JSON body from file. '-' for stdin."}),new p({long:"kv",valueKind:c.TEXT,description:"Shorthand body fields, comma-separated, e.g. keyword=seo,location_code=2840."}),new p({long:"example",valueKind:c.NONE,description:"Use the spec's example body."}),new p({long:"method",valueKind:c.TEXT,description:"Override HTTP method."}),new p({long:"no-wrap",valueKind:c.NONE,description:"Don't auto-wrap a single task as [task]."}),...m],rest:new
|
|
686
|
-
`})];let i=Z(s),r=(y(a,"method")||i?.method||"post").toLowerCase(),d=await $a(a,i?.example,t.slice(1)),l;if(r==="get")l=await R(s);else l=await v(s,d,{wrapAsTaskArray:!
|
|
687
|
-
`),process.exit(1)}export{ds as buildProgram};
|
|
684
|
+
`;return[xo.encode(o),new L]}});async function zo(e="serp/google"){return R(`${e}/locations`)}async function Bo(e="serp/google"){return R(`${e}/languages`)}async function Oo(){return R("/v3/appendix/user_data")}var _e="ram",Yo=g({name:"locations",resource:_e,spec:new h({description:"List supported locations for a given API.",options:[new p({long:"api",valueKind:c.TEXT,description:"API path under /v3.",defaultValue:"serp/google"}),...m]}),fn:async(e,o,t,a)=>{let s=await zo(y(a,"api","serp/google"));return f(s,a)}}),qo=g({name:"languages",resource:_e,spec:new h({description:"List supported languages for a given API.",options:[new p({long:"api",valueKind:c.TEXT,description:"API path under /v3.",defaultValue:"serp/google"}),...m]}),fn:async(e,o,t,a)=>{let s=await Bo(y(a,"api","serp/google"));return f(s,a)}}),Fo=g({name:"user",resource:_e,spec:new h({description:"Show DataForSEO account info (balance, plan, limits).",options:[...m]}),fn:async(e,o,t,a)=>{let s=await Oo();return f(s,{...a,flags:{...a.flags,full:!0}})}});import{readFileSync as ja}from"node:fs";var Ja="ram",Mo=g({name:"raw",resource:Ja,spec:new h({description:"Hit any DataForSEO endpoint by path (escape hatch over the full 437-endpoint API).",positional:[u("path")],options:[new p({short:"d",long:"data",valueKind:c.TEXT,description:"Inline JSON body."}),new p({short:"f",long:"data-file",valueKind:c.TEXT,description:"Read JSON body from file. '-' for stdin."}),new p({long:"kv",valueKind:c.TEXT,description:"Shorthand body fields, comma-separated, e.g. keyword=seo,location_code=2840."}),new p({long:"example",valueKind:c.NONE,description:"Use the spec's example body."}),new p({long:"method",valueKind:c.TEXT,description:"Override HTTP method."}),new p({long:"no-wrap",valueKind:c.NONE,description:"Don't auto-wrap a single task as [task]."}),...m],rest:new q({kind:c.TEXT,name:"kvpairs"})}),fn:async(e,o,t,a)=>{let s=t[0]??"";if(!s)return[null,new L({exitCode:2,stderr:`raw: missing <path>
|
|
685
|
+
`})];let i=Z(s),r=(y(a,"method")||i?.method||"post").toLowerCase(),d=await $a(a,i?.example,t.slice(1)),l;if(r==="get")l=await R(s);else l=await v(s,d,{wrapAsTaskArray:!G(a,"no-wrap")});return f(l,a)}});async function $a(e,o,t){if(G(e,"example")){if(o===void 0)throw Error("No example body in spec for this endpoint.");return o}let a=y(e,"data");if(a)return JSON.parse(a);let s=y(e,"data-file");if(s){let r=s==="-"?await Za():ja(s,"utf8");return JSON.parse(r)}let i=y(e,"kv"),n=[];if(i)n.push(...i.split(","));if(n.push(...t.filter((r)=>r.includes("="))),n.length>0)return Qa(n);return}function Qa(e){let o={};for(let t of e){let a=t.indexOf("=");if(a===-1)continue;o[t.slice(0,a).trim()]=Va(t.slice(a+1))}return o}function Va(e){if(e==="true")return!0;if(e==="false")return!1;if(e==="null")return null;if(/^-?\d+$/.test(e))return Number(e);if(/^-?\d*\.\d+$/.test(e))return Number(e);if(e.startsWith("[")&&e.endsWith("]")||e.startsWith("{")&&e.endsWith("}"))try{return JSON.parse(e)}catch{return e}return e}async function Za(){let e=[];for await(let o of process.stdin)e.push(o);return Buffer.concat(e).toString("utf8")}function W(e){let o={};if(e.locationCode!==void 0)o.location_code=e.locationCode;else o.location_name=e.locationName??"United States";if(e.languageCode!==void 0)o.language_code=e.languageCode;else o.language_name=e.languageName??"English";return o}async function Ko(e){let o=e.advanced?"serp/google/organic/live/advanced":"serp/google/organic/live/regular";return v(o,{...W(e),keyword:e.keyword,device:e.device??"desktop",depth:e.depth??100})}async function Co(e){return v("serp/google/maps/live/advanced",{...W(e),keyword:e.keyword,device:e.device??"desktop",depth:e.depth??100})}async function No(e){return v("serp/youtube/organic/live/advanced",{...W(e),keyword:e.keyword,depth:e.depth??100})}async function Ho(e){return v("serp/google/news/live/advanced",{...W(e),keyword:e.keyword,device:e.device??"desktop",depth:e.depth??100})}async function Xo(e){return v("serp/google/images/live/advanced",{...W(e),keyword:e.keyword,device:e.device??"desktop",depth:e.depth??100})}var j="ram",J=[...w,new p({long:"device",valueKind:c.TEXT,description:"desktop | mobile.",defaultValue:"desktop"}),new p({long:"depth",valueKind:c.TEXT,description:"Result depth.",defaultValue:"100"})],es=g({name:"organic",resource:j,spec:new h({description:"Live Google organic SERP for a keyword.",positional:[u("keyword")],options:[...J,new p({long:"advanced",valueKind:c.NONE,description:"Use the advanced endpoint with featured snippet detail."}),...m]}),fn:async(e,o,t,a)=>{let s=await Ko({...k(a),keyword:t[0]??"",device:y(a,"device","desktop"),depth:I(a,"depth",100),advanced:G(a,"advanced")});return f(s,a)}}),os=g({name:"maps",resource:j,spec:new h({description:"Google Maps / local pack results.",positional:[u("keyword")],options:[...J,...m]}),fn:async(e,o,t,a)=>{let s=await Co({...k(a),keyword:t[0]??"",device:y(a,"device","desktop"),depth:I(a,"depth",100)});return f(s,a)}}),ts=g({name:"news",resource:j,spec:new h({description:"Google News results for a keyword.",positional:[u("keyword")],options:[...J,...m]}),fn:async(e,o,t,a)=>{let s=await Ho({...k(a),keyword:t[0]??"",device:y(a,"device","desktop"),depth:I(a,"depth",100)});return f(s,a)}}),as=g({name:"images",resource:j,spec:new h({description:"Google Images results for a keyword.",positional:[u("keyword")],options:[...J,...m]}),fn:async(e,o,t,a)=>{let s=await Xo({...k(a),keyword:t[0]??"",device:y(a,"device","desktop"),depth:I(a,"depth",100)});return f(s,a)}}),ss=g({name:"organic",resource:j,spec:new h({description:"YouTube organic search results.",positional:[u("keyword")],options:[...J,...m]}),fn:async(e,o,t,a)=>{let s=await No({...k(a),keyword:t[0]??"",depth:I(a,"depth",100)});return f(s,a)}}),Wo=A({name:"serp",description:"SERP queries against Google / YouTube.",groups:[A({name:"google",description:"Google SERPs.",commands:[es,os,ts,as]}),A({name:"youtube",description:"YouTube SERPs.",commands:[ss]})]});function ye(e){let o={};if(e.locationCode!==void 0)o.location_code=e.locationCode;else o.location_name=e.locationName??"United States";if(e.languageCode!==void 0)o.language_code=e.languageCode;return o}async function jo(e){return v("keywords_data/google_trends/explore/live",{...ye(e),keywords:e.keywords,type:e.type??"web",date_from:e.dateFrom,date_to:e.dateTo})}async function Jo(e){return v("keywords_data/dataforseo_trends/demography/live",{...ye(e),keywords:e.keywords})}async function $o(e){return v("keywords_data/dataforseo_trends/subregion_interests/live",{...ye(e),keywords:e.keywords})}var ke="ram",is=g({name:"explore",resource:ke,spec:new h({description:"Google Trends 'Explore' — popularity time series for keywords.",positional:[u("keywords",{variadic:!0})],options:[...w,new p({long:"type",valueKind:c.TEXT,description:"web | news | youtube | images | shopping.",defaultValue:"web"}),new p({long:"date-from",valueKind:c.TEXT,description:"Start date (YYYY-MM-DD)."}),new p({long:"date-to",valueKind:c.TEXT,description:"End date (YYYY-MM-DD)."}),...m]}),fn:async(e,o,t,a)=>{let s=await jo({...k(a),keywords:[...t],type:y(a,"type","web"),dateFrom:y(a,"date-from")||void 0,dateTo:y(a,"date-to")||void 0});return f(s,a)}}),rs=g({name:"demography",resource:ke,spec:new h({description:"Age/gender demographics for keyword interest (DataForSEO Trends).",positional:[u("keywords",{variadic:!0})],options:[...w,...m]}),fn:async(e,o,t,a)=>{let s=await Jo({...k(a),keywords:[...t]});return f(s,a)}}),ns=g({name:"subregion",resource:ke,spec:new h({description:"Regional popularity heatmap for keywords (DataForSEO Trends).",positional:[u("keywords",{variadic:!0})],options:[...w,...m]}),fn:async(e,o,t,a)=>{let s=await $o({...k(a),keywords:[...t]});return f(s,a)}}),Qo=A({name:"trends",description:"Google Trends + DataForSEO Trends (time series, demography, region).",commands:[is,rs,ns]});function hr(){let e=new N;return e.name("dfs").description("Ergonomic CLI for the DataForSEO API.\n\nCurated commands cover ~40 high-value endpoints.\nUse `dfs raw <path>` to hit any of the 437 endpoints by path,\nand `dfs endpoints list` / `dfs endpoints show` to discover them.").version("0.3.0"),e.addCommand(x(Ro)),e.addCommand(x(Eo)),e.addCommand(x(Yo)),e.addCommand(x(qo)),e.addCommand(x(Fo)),e.addCommand(x(Mo)),P(e,ko),P(e,Wo),P(e,lo),P(e,Po),P(e,to),P(e,Qo),P(e,fo),e}export{hr as buildProgram};
|