@frontic/cli 0.0.0-canary-20260121141656
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/README.md +94 -0
- package/dist/frontic.mjs +36 -0
- package/dist/src/commands/generate/templates/client.js.hbs +362 -0
- package/dist/src/commands/generate/templates/query.js.hbs +161 -0
- package/dist/src/commands/generate/templates/types.js.hbs +223 -0
- package/dist/version +1 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Frontic CLI
|
|
2
|
+
|
|
3
|
+
Frontic CLI is a command line interface for using Frontic in local development.
|
|
4
|
+
|
|
5
|
+
It allows you to login to you Frontic account, push local changes to a project or generate the API client for a project and environment.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
$ npx @frontic/cli
|
|
11
|
+
|
|
12
|
+
Frontic CLI
|
|
13
|
+
|
|
14
|
+
Options:
|
|
15
|
+
-V, --version output the version number
|
|
16
|
+
-h, --help display help for command
|
|
17
|
+
|
|
18
|
+
Commands:
|
|
19
|
+
login Connect the CLI with you Frontic account
|
|
20
|
+
logout Disconnect the CLI from your Frontic account
|
|
21
|
+
info Show information about current project and user
|
|
22
|
+
project [options] Set current project
|
|
23
|
+
generate [options] Generate a JavaScript client for your project
|
|
24
|
+
|
|
25
|
+
help [command] display help for command
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Commands
|
|
29
|
+
|
|
30
|
+
### `frontic login`
|
|
31
|
+
|
|
32
|
+
Login to your Frontic account. You will be redirected to the Frontic website to authenticate and authorize the CLI. After authorizing, you can select a project to work with using `frontic project`.
|
|
33
|
+
|
|
34
|
+
### `frontic info`
|
|
35
|
+
|
|
36
|
+
Provides information about the currently logged in user, their organization and currently selected project.
|
|
37
|
+
|
|
38
|
+
### `frontic project`
|
|
39
|
+
|
|
40
|
+
Select current working project or display all projects
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# List and select a project
|
|
44
|
+
frontic project
|
|
45
|
+
|
|
46
|
+
# Select a project by ID
|
|
47
|
+
frontic project -p a2dc8820-2e52-427a-8d58-0256f28d3db9
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### `frontic generate`
|
|
51
|
+
|
|
52
|
+
Generate a JavaScript client for your specific project and environment.
|
|
53
|
+
|
|
54
|
+
Before running this command, make sure a current working project is selected, using `frontic project`
|
|
55
|
+
|
|
56
|
+
## Development
|
|
57
|
+
|
|
58
|
+
Configs are set in the `config.ts` file. You can also control the configs using environment variables.
|
|
59
|
+
|
|
60
|
+
### Configure
|
|
61
|
+
|
|
62
|
+
By default, the CLI uses the public Frontic API instance. You can either override the URL directly
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
FRONTIC_CLI_API_ROOT=[your-url] pnpm frontic login
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
or enable dev mode (which uses the local Frontic API instance)
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
FRONTIC_CLI_DEV_MODE=1 pnpm frontic login
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Run
|
|
75
|
+
|
|
76
|
+
There are two options to run the CLI in development mode:
|
|
77
|
+
|
|
78
|
+
1. Building the app and running the built file (recommended)
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
$ pnpm frontic [command] // e.g. pnpm frontic info
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
1. Run using [tsx](https://tsx.is/) (this will compile the typescript files on the fly)
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
$ pnpm start [command] // e.g. pnpm start info
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Build
|
|
91
|
+
|
|
92
|
+
The application is built using [pkgroll](https://github.com/privatenumber/pkgroll). The CLI is exported as an ES module and compiled to a single file in the `dist` folder.
|
|
93
|
+
|
|
94
|
+
Build the file using `pnpm build` and run it using `node dist/frontic.mjs`.
|
package/dist/frontic.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var Je=Object.defineProperty;var l=(i,e)=>Je(i,"name",{value:e,configurable:!0});var N,k,H,I,F,V,x;import Be from"events";import ze from"child_process";import Qe from"path";import y,{existsSync as D,readFileSync as me,mkdirSync as Ke,writeFileSync as Ye}from"fs";import Ze from"process";import f from"chalk";import g,{join as Xe,dirname as et}from"pathe";import ge from"js-yaml";import{defu as tt}from"defu";import nt from"http";import it from"open";import E from"handlebars";import rt from"openapi-typescript";import W from"prompts";import K from"semver";import{fileURLToPath as ot}from"url";var C={},L={},P={};let _e=(N=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},l(N,"CommanderError"),N),st=(k=class extends _e{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},l(k,"InvalidArgumentError"),k);P.CommanderError=_e,P.InvalidArgumentError=st;const{InvalidArgumentError:at}=P;let ct=(H=class{constructor(e,t){switch(this.description=t||"",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}this._name.length>3&&this._name.slice(-3)==="..."&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_concatValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:t.concat(e)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new at(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(t,n):t},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}},l(H,"Argument"),H);function lt(i){const e=i.name()+(i.variadic===!0?"...":"");return i.required?"<"+e+">":"["+e+"]"}l(lt,"humanReadableArgName$2"),L.Argument=ct,L.humanReadableArgName=lt;var ye={},Y={};const{humanReadableArgName:ut}=L;let ht=(I=class{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(e){const t=e.commands.filter(r=>!r._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((r,o)=>r.name().localeCompare(o.name())),t}compareOptions(e,t){const n=l(r=>r.short?r.short.replace(/^-/,""):r.long.replace(/^--/,""),"getSortKey");return n(e).localeCompare(n(t))}visibleOptions(e){const t=e.options.filter(r=>!r.hidden),n=e._getHelpOption();if(n&&!n.hidden){const r=n.short&&e._findOption(n.short),o=n.long&&e._findOption(n.long);!r&&!o?t.push(n):n.long&&!o?t.push(e.createOption(n.long,n.description)):n.short&&!r&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];const t=[];for(let n=e.parent;n;n=n.parent){const r=n.options.filter(o=>!o.hidden);t.push(...r)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||""}),e.registeredArguments.find(t=>t.description)?e.registeredArguments:[]}subcommandTerm(e){const t=e.registeredArguments.map(n=>ut(n)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(t?" "+t:"")}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((n,r)=>Math.max(n,t.subcommandTerm(r).length),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((n,r)=>Math.max(n,t.optionTerm(r).length),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((n,r)=>Math.max(n,t.optionTerm(r).length),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((n,r)=>Math.max(n,t.argumentTerm(r).length),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+"|"+e._aliases[0]);let n="";for(let r=e.parent;r;r=r.parent)n=r.name()+" "+n;return n+t+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){const t=[];return e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue=="boolean")&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0?`${e.description} (${t.join(", ")})`:e.description}argumentDescription(e){const t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){const n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}formatHelp(e,t){const n=t.padWidth(e,t),r=t.helpWidth||80,o=2,a=2;function u(m,b){if(b){const T=`${m.padEnd(n+a)}${b}`;return t.wrap(T,r-o,n+a)}return m}l(u,"formatItem");function c(m){return m.join(`
|
|
3
|
+
`).replace(/^/gm," ".repeat(o))}l(c,"formatList");let h=[`Usage: ${t.commandUsage(e)}`,""];const s=t.commandDescription(e);s.length>0&&(h=h.concat([t.wrap(s,r,0),""]));const p=t.visibleArguments(e).map(m=>u(t.argumentTerm(m),t.argumentDescription(m)));p.length>0&&(h=h.concat(["Arguments:",c(p),""]));const d=t.visibleOptions(e).map(m=>u(t.optionTerm(m),t.optionDescription(m)));if(d.length>0&&(h=h.concat(["Options:",c(d),""])),this.showGlobalOptions){const m=t.visibleGlobalOptions(e).map(b=>u(t.optionTerm(b),t.optionDescription(b)));m.length>0&&(h=h.concat(["Global Options:",c(m),""]))}const _=t.visibleCommands(e).map(m=>u(t.subcommandTerm(m),t.subcommandDescription(m)));return _.length>0&&(h=h.concat(["Commands:",c(_),""])),h.join(`
|
|
4
|
+
`)}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}wrap(e,t,n,r=40){const o=" \\f\\t\\v\xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF",a=new RegExp(`[\\n][${o}]+`);if(e.match(a))return e;const u=t-n;if(u<r)return e;const c=e.slice(0,n),h=e.slice(n).replace(`\r
|
|
5
|
+
`,`
|
|
6
|
+
`),s=" ".repeat(n),d="\\s\u200B",_=new RegExp(`
|
|
7
|
+
|.{1,${u-1}}([${d}]|$)|[^${d}]+?([${d}]|$)`,"g"),m=h.match(_)||[];return c+m.map((b,T)=>b===`
|
|
8
|
+
`?"":(T>0?s:"")+b.trimEnd()).join(`
|
|
9
|
+
`)}},l(I,"Help"),I);Y.Help=ht;var G={};const{InvalidArgumentError:pt}=P;let ft=(F=class{constructor(e,t){this.flags=e,this.description=t||"",this.required=e.includes("<"),this.optional=e.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;const n=gt(e);this.short=n.shortFlag,this.long=n.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,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return typeof e=="string"&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),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,t){return t===this.defaultValue||!Array.isArray(t)?[e]:t.concat(e)}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new pt(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(t,n):t},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return mt(this.name().replace(/^no-/,""))}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},l(F,"Option"),F),dt=(V=class{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach(t=>{t.negate?this.negativeOptions.set(t.attributeName(),t):this.positiveOptions.set(t.attributeName(),t)}),this.negativeOptions.forEach((t,n)=>{this.positiveOptions.has(n)&&this.dualOptions.add(n)})}valueFromOption(e,t){const n=t.attributeName();if(!this.dualOptions.has(n))return!0;const r=this.negativeOptions.get(n).presetArg,o=r!==void 0?r:!1;return t.negate===(o===e)}},l(V,"DualOptions"),V);function mt(i){return i.split("-").reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}l(mt,"camelcase");function gt(i){let e,t;const n=i.split(/[ |,]+/);return n.length>1&&!/^[[<]/.test(n[1])&&(e=n.shift()),t=n.shift(),!e&&/^-[^-]$/.test(t)&&(e=t,t=void 0),{shortFlag:e,longFlag:t}}l(gt,"splitOptionFlags"),G.Option=ft,G.DualOptions=dt;var Oe={};const be=3;function _t(i,e){if(Math.abs(i.length-e.length)>be)return Math.max(i.length,e.length);const t=[];for(let n=0;n<=i.length;n++)t[n]=[n];for(let n=0;n<=e.length;n++)t[0][n]=n;for(let n=1;n<=e.length;n++)for(let r=1;r<=i.length;r++){let o=1;i[r-1]===e[n-1]?o=0:o=1,t[r][n]=Math.min(t[r-1][n]+1,t[r][n-1]+1,t[r-1][n-1]+o),r>1&&n>1&&i[r-1]===e[n-2]&&i[r-2]===e[n-1]&&(t[r][n]=Math.min(t[r][n],t[r-2][n-2]+1))}return t[i.length][e.length]}l(_t,"editDistance");function yt(i,e){if(!e||e.length===0)return"";e=Array.from(new Set(e));const t=i.startsWith("--");t&&(i=i.slice(2),e=e.map(a=>a.slice(2)));let n=[],r=be;const o=.4;return e.forEach(a=>{if(a.length<=1)return;const u=_t(i,a),c=Math.max(i.length,a.length);(c-u)/c>o&&(u<r?(r=u,n=[a]):u===r&&n.push(a))}),n.sort((a,u)=>a.localeCompare(u)),t&&(n=n.map(a=>`--${a}`)),n.length>1?`
|
|
10
|
+
(Did you mean one of ${n.join(", ")}?)`:n.length===1?`
|
|
11
|
+
(Did you mean ${n[0]}?)`:""}l(yt,"suggestSimilar$1"),Oe.suggestSimilar=yt;const Ot=Be.EventEmitter,Z=ze,v=Qe,X=y,O=Ze,{Argument:bt,humanReadableArgName:wt}=L,{CommanderError:ee}=P,{Help:Ct}=Y,{Option:we,DualOptions:At}=G,{suggestSimilar:Ce}=Oe;let $t=(x=class extends Ot{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:l(t=>O.stdout.write(t),"writeOut"),writeErr:l(t=>O.stderr.write(t),"writeErr"),getOutHelpWidth:l(()=>O.stdout.isTTY?O.stdout.columns:void 0,"getOutHelpWidth"),getErrHelpWidth:l(()=>O.stderr.isTTY?O.stderr.columns:void 0,"getErrHelpWidth"),outputError:l((t,n)=>n(t),"outputError")},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(){const e=[];for(let t=this;t;t=t.parent)e.push(t);return e}command(e,t,n){let r=t,o=n;typeof r=="object"&&r!==null&&(o=r,r=null),o=o||{};const[,a,u]=e.match(/([^ ]+) *(.*)/),c=this.createCommand(a);return r&&(c.description(r),c._executableHandler=!0),o.isDefault&&(this._defaultCommandName=c._name),c._hidden=!!(o.noHelp||o.hidden),c._executableFile=o.executableFile||null,u&&c.arguments(u),this._registerCommand(c),c.parent=this,c.copyInheritedSettings(this),r?this:c}createCommand(e){return new x(e)}createHelp(){return Object.assign(new Ct,this.configureHelp())}configureHelp(e){return e===void 0?this._helpConfiguration:(this._helpConfiguration=e,this)}configureOutput(e){return e===void 0?this._outputConfiguration:(Object.assign(this._outputConfiguration,e),this)}showHelpAfterError(e=!0){return typeof e!="string"&&(e=!!e),this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,t){if(!e._name)throw new Error(`Command passed to .addCommand() must have a name
|
|
12
|
+
- specify the name in Command constructor or using .name()`);return t=t||{},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new bt(e,t)}argument(e,t,n,r){const o=this.createArgument(e,t);return typeof n=="function"?o.default(r).argParser(n):o.default(n),this.addArgument(o),this}arguments(e){return e.trim().split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(e){const t=this.registeredArguments.slice(-1)[0];if(t&&t.variadic)throw new Error(`only the last argument can be variadic '${t.name()}'`);if(e.required&&e.defaultValue!==void 0&&e.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,t){if(typeof e=="boolean")return this._addImplicitHelpCommand=e,this;e=e??"help [command]";const[,n,r]=e.match(/([^ ]+) *(.*)/),o=t??"display help for command",a=this.createCommand(n);return a.helpOption(!1),r&&a.arguments(r),o&&a.description(o),this._addImplicitHelpCommand=!0,this._helpCommand=a,this}addHelpCommand(e,t){return typeof e!="object"?(this.helpCommand(e,t),this):(this._addImplicitHelpCommand=!0,this._helpCommand=e,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(e,t){const n=["preSubcommand","preAction","postAction"];if(!n.includes(e))throw new Error(`Unexpected value for event passed to hook : '${e}'.
|
|
13
|
+
Expecting one of '${n.join("', '")}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return e?this._exitCallback=e:this._exitCallback=t=>{if(t.code!=="commander.executeSubCommandAsync")throw t},this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new ee(e,t,n)),O.exit(e)}action(e){const t=l(n=>{const r=this.registeredArguments.length,o=n.slice(0,r);return this._storeOptionsAsProperties?o[r]=this:o[r]=this.opts(),o.push(this),e.apply(this,o)},"listener");return this._actionHandler=t,this}createOption(e,t){return new we(e,t)}_callParseArg(e,t,n,r){try{return e.parseArg(t,n)}catch(o){if(o.code==="commander.invalidArgument"){const a=`${r} ${o.message}`;this.error(a,{exitCode:o.exitCode,code:o.code})}throw o}}_registerOption(e){const t=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(t){const n=e.long&&this._findOption(e.long)?e.long:e.short;throw new Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${n}'
|
|
14
|
+
- already used by option '${t.flags}'`)}this.options.push(e)}_registerCommand(e){const t=l(r=>[r.name()].concat(r.aliases()),"knownBy"),n=t(e).find(r=>this._findCommand(r));if(n){const r=t(this._findCommand(n)).join("|"),o=t(e).join("|");throw new Error(`cannot add command '${o}' as already have command '${r}'`)}this.commands.push(e)}addOption(e){this._registerOption(e);const t=e.name(),n=e.attributeName();if(e.negate){const o=e.long.replace(/^--no-/,"--");this._findOption(o)||this.setOptionValueWithSource(n,e.defaultValue===void 0?!0:e.defaultValue,"default")}else e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,"default");const r=l((o,a,u)=>{o==null&&e.presetArg!==void 0&&(o=e.presetArg);const c=this.getOptionValue(n);o!==null&&e.parseArg?o=this._callParseArg(e,o,c,a):o!==null&&e.variadic&&(o=e._concatValue(o,c)),o==null&&(e.negate?o=!1:e.isBoolean()||e.optional?o=!0:o=""),this.setOptionValueWithSource(n,o,u)},"handleOptionValue");return this.on("option:"+t,o=>{const a=`error: option '${e.flags}' argument '${o}' is invalid.`;r(o,a,"cli")}),e.envVar&&this.on("optionEnv:"+t,o=>{const a=`error: option '${e.flags}' value '${o}' from env '${e.envVar}' is invalid.`;r(o,a,"env")}),this}_optionEx(e,t,n,r,o){if(typeof t=="object"&&t instanceof we)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");const a=this.createOption(t,n);if(a.makeOptionMandatory(!!e.mandatory),typeof r=="function")a.default(o).argParser(r);else if(r instanceof RegExp){const u=r;r=l((c,h)=>{const s=u.exec(c);return s?s[0]:h},"fn"),a.default(o).argParser(r)}else a.default(r);return this.addOption(a)}option(e,t,n,r){return this._optionEx({},e,t,n,r)}requiredOption(e,t,n,r){return this._optionEx({mandatory:!0},e,t,n,r)}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 new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(e=!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=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,n){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=n,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(n=>{n.getOptionValueSource(e)!==void 0&&(t=n.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){if(e!==void 0&&!Array.isArray(e))throw new Error("first parameter to parse must be array or undefined");t=t||{},e===void 0&&(e=O.argv,O.versions&&O.versions.electron&&(t.from="electron")),this.rawArgs=e.slice();let n;switch(t.from){case void 0:case"node":this._scriptPath=e[1],n=e.slice(2);break;case"electron":O.defaultApp?(this._scriptPath=e[1],n=e.slice(2)):n=e.slice(1);break;case"user":n=e.slice(0);break;default:throw new Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",n}parse(e,t){const n=this._prepareUserArgs(e,t);return this._parseCommand([],n),this}async parseAsync(e,t){const n=this._prepareUserArgs(e,t);return await this._parseCommand([],n),this}_executeSubCommand(e,t){t=t.slice();let n=!1;const r=[".js",".ts",".tsx",".mjs",".cjs"];function o(s,p){const d=v.resolve(s,p);if(X.existsSync(d))return d;if(r.includes(v.extname(p)))return;const _=r.find(m=>X.existsSync(`${d}${m}`));if(_)return`${d}${_}`}l(o,"findFile"),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let a=e._executableFile||`${this._name}-${e._name}`,u=this._executableDir||"";if(this._scriptPath){let s;try{s=X.realpathSync(this._scriptPath)}catch{s=this._scriptPath}u=v.resolve(v.dirname(s),u)}if(u){let s=o(u,a);if(!s&&!e._executableFile&&this._scriptPath){const p=v.basename(this._scriptPath,v.extname(this._scriptPath));p!==this._name&&(s=o(u,`${p}-${e._name}`))}a=s||a}n=r.includes(v.extname(a));let c;O.platform!=="win32"?n?(t.unshift(a),t=Ae(O.execArgv).concat(t),c=Z.spawn(O.argv[0],t,{stdio:"inherit"})):c=Z.spawn(a,t,{stdio:"inherit"}):(t.unshift(a),t=Ae(O.execArgv).concat(t),c=Z.spawn(O.execPath,t,{stdio:"inherit"})),c.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(p=>{O.on(p,()=>{c.killed===!1&&c.exitCode===null&&c.kill(p)})});const h=this._exitCallback;c.on("close",(s,p)=>{s=s??1,h?h(new ee(s,"commander.executeSubCommandAsync","(close)")):O.exit(s)}),c.on("error",s=>{if(s.code==="ENOENT"){const p=u?`searched for local subcommand relative to directory '${u}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",d=`'${a}' does not exist
|
|
15
|
+
- if '${e._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
16
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
17
|
+
- ${p}`;throw new Error(d)}else if(s.code==="EACCES")throw new Error(`'${a}' not executable`);if(!h)O.exit(1);else{const p=new ee(1,"commander.executeSubCommandAsync","(error)");p.nestedError=s,h(p)}}),this.runningCommand=c}_dispatchSubcommand(e,t,n){const r=this._findCommand(e);r||this.help({error:!0});let o;return o=this._chainOrCallSubCommandHook(o,r,"preSubcommand"),o=this._chainOrCall(o,()=>{if(r._executableHandler)this._executeSubCommand(r,t.concat(n));else return r._parseCommand(t,n)}),o}_dispatchHelpCommand(e){e||this.help();const t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){const e=l((n,r,o)=>{let a=r;if(r!==null&&n.parseArg){const u=`error: command-argument value '${r}' is invalid for argument '${n.name()}'.`;a=this._callParseArg(n,r,o,u)}return a},"myParseArg");this._checkNumberOfArguments();const t=[];this.registeredArguments.forEach((n,r)=>{let o=n.defaultValue;n.variadic?r<this.args.length?(o=this.args.slice(r),n.parseArg&&(o=o.reduce((a,u)=>e(n,u,a),n.defaultValue))):o===void 0&&(o=[]):r<this.args.length&&(o=this.args[r],n.parseArg&&(o=e(n,o,n.defaultValue))),t[r]=o}),this.processedArgs=t}_chainOrCall(e,t){return e&&e.then&&typeof e.then=="function"?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e;const r=[];return this._getCommandAndAncestors().reverse().filter(o=>o._lifeCycleHooks[t]!==void 0).forEach(o=>{o._lifeCycleHooks[t].forEach(a=>{r.push({hookedCommand:o,callback:a})})}),t==="postAction"&&r.reverse(),r.forEach(o=>{n=this._chainOrCall(n,()=>o.callback(o.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let r=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(o=>{r=this._chainOrCall(r,()=>o(this,t))}),r}_parseCommand(e,t){const n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();const r=l(()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},"checkForUnknownOptions"),o=`command:${this.name()}`;if(this._actionHandler){r(),this._processArguments();let a;return a=this._chainOrCallHooks(a,"preAction"),a=this._chainOrCall(a,()=>this._actionHandler(this.processedArgs)),this.parent&&(a=this._chainOrCall(a,()=>{this.parent.emit(o,e,t)})),a=this._chainOrCallHooks(a,"postAction"),a}if(this.parent&&this.parent.listenerCount(o))r(),this._processArguments(),this.parent.emit(o,e,t);else if(e.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",e,t);this.listenerCount("command:*")?this.emit("command:*",e,t):this.commands.length?this.unknownCommand():(r(),this._processArguments())}else this.commands.length?(r(),this.help({error:!0})):(r(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){const e=this.options.filter(n=>{const r=n.attributeName();return this.getOptionValue(r)===void 0?!1:this.getOptionValueSource(r)!=="default"});e.filter(n=>n.conflictsWith.length>0).forEach(n=>{const r=e.find(o=>n.conflictsWith.includes(o.attributeName()));r&&this._conflictingOption(n,r)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){const t=[],n=[];let r=t;const o=e.slice();function a(c){return c.length>1&&c[0]==="-"}l(a,"maybeOption");let u=null;for(;o.length;){const c=o.shift();if(c==="--"){r===n&&r.push(c),r.push(...o);break}if(u&&!a(c)){this.emit(`option:${u.name()}`,c);continue}if(u=null,a(c)){const h=this._findOption(c);if(h){if(h.required){const s=o.shift();s===void 0&&this.optionMissingArgument(h),this.emit(`option:${h.name()}`,s)}else if(h.optional){let s=null;o.length>0&&!a(o[0])&&(s=o.shift()),this.emit(`option:${h.name()}`,s)}else this.emit(`option:${h.name()}`);u=h.variadic?h:null;continue}}if(c.length>2&&c[0]==="-"&&c[1]!=="-"){const h=this._findOption(`-${c[1]}`);if(h){h.required||h.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${h.name()}`,c.slice(2)):(this.emit(`option:${h.name()}`),o.unshift(`-${c.slice(2)}`));continue}}if(/^--[^=]+=/.test(c)){const h=c.indexOf("="),s=this._findOption(c.slice(0,h));if(s&&(s.required||s.optional)){this.emit(`option:${s.name()}`,c.slice(h+1));continue}}if(a(c)&&(r=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(c)){t.push(c),o.length>0&&n.push(...o);break}else if(this._getHelpCommand()&&c===this._getHelpCommand().name()){t.push(c),o.length>0&&t.push(...o);break}else if(this._defaultCommandName){n.push(c),o.length>0&&n.push(...o);break}}if(this._passThroughOptions){r.push(c),o.length>0&&r.push(...o);break}r.push(c)}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){const e={},t=this.options.length;for(let n=0;n<t;n++){const r=this.options[n].attributeName();e[r]=r===this._versionOptionName?this._version:this[r]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}
|
|
18
|
+
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
19
|
+
`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
|
|
20
|
+
`),this.outputHelp({error:!0}));const n=t||{},r=n.exitCode||1,o=n.code||"commander.error";this._exit(r,o,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in O.env){const t=e.attributeName();(this.getOptionValue(t)===void 0||["default","config","env"].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,O.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){const e=new At(this.options),t=l(n=>this.getOptionValue(n)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(n)),"hasCustomOptionValue");this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(n=>{Object.keys(n.implied).filter(r=>!t(r)).forEach(r=>{this.setOptionValueWithSource(r,n.implied[r],"implied")})})}missingArgument(e){const t=`error: missing required argument '${e}'`;this.error(t,{code:"commander.missingArgument"})}optionMissingArgument(e){const t=`error: option '${e.flags}' argument missing`;this.error(t,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(e){const t=`error: required option '${e.flags}' not specified`;this.error(t,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(e,t){const n=l(a=>{const u=a.attributeName(),c=this.getOptionValue(u),h=this.options.find(p=>p.negate&&u===p.attributeName()),s=this.options.find(p=>!p.negate&&u===p.attributeName());return h&&(h.presetArg===void 0&&c===!1||h.presetArg!==void 0&&c===h.presetArg)?h:s||a},"findBestOptionFromValue"),r=l(a=>{const u=n(a),c=u.attributeName();return this.getOptionValueSource(c)==="env"?`environment variable '${u.envVar}'`:`option '${u.flags}'`},"getErrorMessage"),o=`error: ${r(e)} cannot be used with ${r(t)}`;this.error(o,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let r=[],o=this;do{const a=o.createHelp().visibleOptions(o).filter(u=>u.long).map(u=>u.long);r=r.concat(a),o=o.parent}while(o&&!o._enablePositionalOptions);t=Ce(e,r)}const n=`error: unknown option '${e}'${t}`;this.error(n,{code:"commander.unknownOption"})}_excessArguments(e){if(this._allowExcessArguments)return;const t=this.registeredArguments.length,n=t===1?"":"s",o=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${t} argument${n} but got ${e.length}.`;this.error(o,{code:"commander.excessArguments"})}unknownCommand(){const e=this.args[0];let t="";if(this._showSuggestionAfterError){const r=[];this.createHelp().visibleCommands(this).forEach(o=>{r.push(o.name()),o.alias()&&r.push(o.alias())}),t=Ce(e,r)}const n=`error: unknown command '${e}'${t}`;this.error(n,{code:"commander.unknownCommand"})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t=t||"-V, --version",n=n||"output the version number";const r=this.createOption(t,n);return this._versionOptionName=r.attributeName(),this._registerOption(r),this.on("option:"+r.name(),()=>{this._outputConfiguration.writeOut(`${e}
|
|
21
|
+
`),this._exit(0,"commander.version",e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw new Error("Command alias can't be the same as its name");const n=this.parent?._findCommand(e);if(n){const r=[n.name()].concat(n.aliases()).join("|");throw new Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${r}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(t=>this.alias(t)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;const t=this.registeredArguments.map(n=>wt(n));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}nameFromFilename(e){return this._name=v.basename(e,v.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){const t=this.createHelp();return t.helpWidth===void 0&&(t.helpWidth=e&&e.error?this._outputConfiguration.getErrHelpWidth():this._outputConfiguration.getOutHelpWidth()),t.formatHelp(this,t)}_getHelpContext(e){e=e||{};const t={error:!!e.error};let n;return t.error?n=l(r=>this._outputConfiguration.writeErr(r),"write"):n=l(r=>this._outputConfiguration.writeOut(r),"write"),t.write=e.write||n,t.command=this,t}outputHelp(e){let t;typeof e=="function"&&(t=e,e=void 0);const n=this._getHelpContext(e);this._getCommandAndAncestors().reverse().forEach(o=>o.emit("beforeAllHelp",n)),this.emit("beforeHelp",n);let r=this.helpInformation(n);if(t&&(r=t(r),typeof r!="string"&&!Buffer.isBuffer(r)))throw new Error("outputHelp callback must return a string or a Buffer");n.write(r),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",n),this._getCommandAndAncestors().forEach(o=>o.emit("afterAllHelp",n))}helpOption(e,t){return typeof e=="boolean"?(e?this._helpOption=this._helpOption??void 0:this._helpOption=null,this):(e=e??"-h, --help",t=t??"display help for command",this._helpOption=this.createOption(e,t),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this}help(e){this.outputHelp(e);let t=O.exitCode||0;t===0&&e&&typeof e!="function"&&e.error&&(t=1),this._exit(t,"commander.help","(outputHelp)")}addHelpText(e,t){const n=["beforeAll","before","after","afterAll"];if(!n.includes(e))throw new Error(`Unexpected value for position to addHelpText.
|
|
22
|
+
Expecting one of '${n.join("', '")}'`);const r=`${e}Help`;return this.on(r,o=>{let a;typeof t=="function"?a=t({error:o.error,command:o.command}):a=t,a&&o.write(`${a}
|
|
23
|
+
`)}),this}_outputHelpIfRequested(e){const t=this._getHelpOption();t&&e.find(r=>t.is(r))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}},l(x,"Command"),x);function Ae(i){return i.map(e=>{if(!e.startsWith("--inspect"))return e;let t,n="127.0.0.1",r="9229",o;return(o=e.match(/^(--inspect(-brk)?)$/))!==null?t=o[1]:(o=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=o[1],/^\d+$/.test(o[3])?r=o[3]:n=o[3]):(o=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=o[1],n=o[3],r=o[4]),t&&r!=="0"?`${t}=${n}:${parseInt(r)+1}`:e})}l(Ae,"incrementNodeInspectorPort"),ye.Command=$t;const{Argument:$e}=L,{Command:te}=ye,{CommanderError:Et,InvalidArgumentError:Ee}=P,{Help:vt}=Y,{Option:ve}=G;C.program=new te,C.createCommand=i=>new te(i),C.createOption=(i,e)=>new ve(i,e),C.createArgument=(i,e)=>new $e(i,e),C.Command=te,C.Option=ve,C.Argument=$e,C.Help=vt,C.CommanderError=Et,C.InvalidArgumentError=Ee,C.InvalidOptionArgumentError=Ee;const{program:di,createCommand:mi,createArgument:gi,createOption:_i,CommanderError:yi,InvalidArgumentError:Oi,InvalidOptionArgumentError:bi,Command:St,Argument:wi,Option:Ci,Help:Ai}=C,jt=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,xt=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,Tt=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function Pt(i,e){if(i==="__proto__"||i==="constructor"&&e&&typeof e=="object"&&"prototype"in e){Rt(i);return}return e}l(Pt,"jsonParseTransform");function Rt(i){console.warn(`[destr] Dropping "${i}" key to prevent prototype pollution.`)}l(Rt,"warnKeyDropped");function Nt(i,e={}){if(typeof i!="string")return i;const t=i.trim();if(i[0]==='"'&&i.endsWith('"')&&!i.includes("\\"))return t.slice(1,-1);if(t.length<=9){const n=t.toLowerCase();if(n==="true")return!0;if(n==="false")return!1;if(n==="undefined")return;if(n==="null")return null;if(n==="nan")return Number.NaN;if(n==="infinity")return Number.POSITIVE_INFINITY;if(n==="-infinity")return Number.NEGATIVE_INFINITY}if(!Tt.test(i)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return i}try{if(jt.test(i)||xt.test(i)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(i,Pt)}return JSON.parse(i)}catch(n){if(e.strict)throw n;return i}}l(Nt,"destr");const kt=/#/g,Ht=/&/g,It=/\//g,Ft=/=/g,ne=/\+/g,Vt=/%5e/gi,Dt=/%60/gi,Lt=/%7c/gi,qt=/%20/gi;function Mt(i){return encodeURI(""+i).replace(Lt,"|")}l(Mt,"encode");function ie(i){return Mt(typeof i=="string"?i:JSON.stringify(i)).replace(ne,"%2B").replace(qt,"+").replace(kt,"%23").replace(Ht,"%26").replace(Dt,"`").replace(Vt,"^").replace(It,"%2F")}l(ie,"encodeQueryValue");function re(i){return ie(i).replace(Ft,"%3D")}l(re,"encodeQueryKey");function Se(i=""){try{return decodeURIComponent(""+i)}catch{return""+i}}l(Se,"decode");function Ut(i){return Se(i.replace(ne," "))}l(Ut,"decodeQueryKey");function Wt(i){return Se(i.replace(ne," "))}l(Wt,"decodeQueryValue");function Gt(i=""){const e={};i[0]==="?"&&(i=i.slice(1));for(const t of i.split("&")){const n=t.match(/([^=]+)=?(.*)/)||[];if(n.length<2)continue;const r=Ut(n[1]);if(r==="__proto__"||r==="constructor")continue;const o=Wt(n[2]||"");e[r]===void 0?e[r]=o:Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]}return e}l(Gt,"parseQuery");function Jt(i,e){return(typeof e=="number"||typeof e=="boolean")&&(e=String(e)),e?Array.isArray(e)?e.map(t=>`${re(i)}=${ie(t)}`).join("&"):`${re(i)}=${ie(e)}`:re(i)}l(Jt,"encodeQueryItem");function Bt(i){return Object.keys(i).filter(e=>i[e]!==void 0).map(e=>Jt(e,i[e])).filter(Boolean).join("&")}l(Bt,"stringifyQuery");const zt=/^[\s\w\0+.-]{2,}:([/\\]{1,2})/,Qt=/^[\s\w\0+.-]{2,}:([/\\]{2})?/,Kt=/^([/\\]\s*){2,}[^/\\]/,Yt=/^\.?\//;function je(i,e={}){return typeof e=="boolean"&&(e={acceptRelative:e}),e.strict?zt.test(i):Qt.test(i)||(e.acceptRelative?Kt.test(i):!1)}l(je,"hasProtocol");function Zt(i="",e){return i.endsWith("/")}l(Zt,"hasTrailingSlash");function Xt(i="",e){return(Zt(i)?i.slice(0,-1):i)||"/"}l(Xt,"withoutTrailingSlash");function en(i="",e){return i.endsWith("/")?i:i+"/"}l(en,"withTrailingSlash");function tn(i,e){if(rn(e)||je(i))return i;const t=Xt(e);return i.startsWith(t)?i:sn(t,i)}l(tn,"withBase");function nn(i,e){const t=an(i),n={...Gt(t.search),...e};return t.search=Bt(n),cn(t)}l(nn,"withQuery");function rn(i){return!i||i==="/"}l(rn,"isEmptyURL");function on(i){return i&&i!=="/"}l(on,"isNonEmptyURL");function sn(i,...e){let t=i||"";for(const n of e.filter(r=>on(r)))if(t){const r=n.replace(Yt,"");t=en(t)+r}else t=n;return t}l(sn,"joinURL");const xe=Symbol.for("ufo:protocolRelative");function an(i="",e){const t=i.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);if(t){const[,p,d=""]=t;return{protocol:p.toLowerCase(),pathname:d,href:p+d,auth:"",host:"",search:"",hash:""}}if(!je(i,{acceptRelative:!0}))return Te(i);const[,n="",r,o=""]=i.replace(/\\/g,"/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/)||[];let[,a="",u=""]=o.match(/([^#/?]*)(.*)?/)||[];n==="file:"&&(u=u.replace(/\/(?=[A-Za-z]:)/,""));const{pathname:c,search:h,hash:s}=Te(u);return{protocol:n.toLowerCase(),auth:r?r.slice(0,Math.max(0,r.length-1)):"",host:a,pathname:c,search:h,hash:s,[xe]:!n}}l(an,"parseURL");function Te(i=""){const[e="",t="",n=""]=(i.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:e,search:t,hash:n}}l(Te,"parsePath");function cn(i){const e=i.pathname||"",t=i.search?(i.search.startsWith("?")?"":"?")+i.search:"",n=i.hash||"",r=i.auth?i.auth+"@":"",o=i.host||"";return(i.protocol||i[xe]?(i.protocol||"")+"//":"")+r+o+e+t+n}l(cn,"stringifyParsedURL");const le=class le extends Error{constructor(e,t){super(e,t),this.name="FetchError",t?.cause&&!this.cause&&(this.cause=t.cause)}};l(le,"FetchError");let oe=le;function ln(i){const e=i.error?.message||i.error?.toString()||"",t=i.request?.method||i.options?.method||"GET",n=i.request?.url||String(i.request)||"/",r=`[${t}] ${JSON.stringify(n)}`,o=i.response?`${i.response.status} ${i.response.statusText}`:"<no response>",a=`${r}: ${o}${e?` ${e}`:""}`,u=new oe(a,i.error?{cause:i.error}:void 0);for(const c of["request","options","response"])Object.defineProperty(u,c,{get(){return i[c]}});for(const[c,h]of[["data","_data"],["status","status"],["statusCode","status"],["statusText","statusText"],["statusMessage","statusText"]])Object.defineProperty(u,c,{get(){return i.response&&i.response[h]}});return u}l(ln,"createFetchError");const un=new Set(Object.freeze(["PATCH","POST","PUT","DELETE"]));function Pe(i="GET"){return un.has(i.toUpperCase())}l(Pe,"isPayloadMethod");function hn(i){if(i===void 0)return!1;const e=typeof i;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(i)?!0:i.buffer?!1:i.constructor&&i.constructor.name==="Object"||typeof i.toJSON=="function"}l(hn,"isJSONSerializable");const pn=new Set(["image/svg","application/xml","application/xhtml","application/html"]),fn=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function dn(i=""){if(!i)return"json";const e=i.split(";").shift()||"";return fn.test(e)?"json":pn.has(e)||e.startsWith("text/")?"text":"blob"}l(dn,"detectResponseType");function mn(i,e,t=globalThis.Headers){const n={...e,...i};if(e?.params&&i?.params&&(n.params={...e?.params,...i?.params}),e?.query&&i?.query&&(n.query={...e?.query,...i?.query}),e?.headers&&i?.headers){n.headers=new t(e?.headers||{});for(const[r,o]of new t(i?.headers||{}))n.headers.set(r,o)}return n}l(mn,"mergeFetchOptions");const gn=new Set([408,409,425,429,500,502,503,504]),_n=new Set([101,204,205,304]);function Re(i={}){const{fetch:e=globalThis.fetch,Headers:t=globalThis.Headers,AbortController:n=globalThis.AbortController}=i;async function r(u){const c=u.error&&u.error.name==="AbortError"&&!u.options.timeout||!1;if(u.options.retry!==!1&&!c){let s;typeof u.options.retry=="number"?s=u.options.retry:s=Pe(u.options.method)?0:1;const p=u.response&&u.response.status||500;if(s>0&&(Array.isArray(u.options.retryStatusCodes)?u.options.retryStatusCodes.includes(p):gn.has(p))){const d=u.options.retryDelay||0;return d>0&&await new Promise(_=>setTimeout(_,d)),o(u.request,{...u.options,retry:s-1})}}const h=ln(u);throw Error.captureStackTrace&&Error.captureStackTrace(h,o),h}l(r,"onError");const o=l(async function(c,h={}){const s={request:c,options:mn(h,i.defaults,t),response:void 0,error:void 0};s.options.method=s.options.method?.toUpperCase(),s.options.onRequest&&await s.options.onRequest(s),typeof s.request=="string"&&(s.options.baseURL&&(s.request=tn(s.request,s.options.baseURL)),(s.options.query||s.options.params)&&(s.request=nn(s.request,{...s.options.params,...s.options.query}))),s.options.body&&Pe(s.options.method)&&(hn(s.options.body)?(s.options.body=typeof s.options.body=="string"?s.options.body:JSON.stringify(s.options.body),s.options.headers=new t(s.options.headers||{}),s.options.headers.has("content-type")||s.options.headers.set("content-type","application/json"),s.options.headers.has("accept")||s.options.headers.set("accept","application/json")):("pipeTo"in s.options.body&&typeof s.options.body.pipeTo=="function"||typeof s.options.body.pipe=="function")&&("duplex"in s.options||(s.options.duplex="half")));let p;if(!s.options.signal&&s.options.timeout){const _=new n;p=setTimeout(()=>_.abort(),s.options.timeout),s.options.signal=_.signal}try{s.response=await e(s.request,s.options)}catch(_){return s.error=_,s.options.onRequestError&&await s.options.onRequestError(s),await r(s)}finally{p&&clearTimeout(p)}if(s.response.body&&!_n.has(s.response.status)&&s.options.method!=="HEAD"){const _=(s.options.parseResponse?"json":s.options.responseType)||dn(s.response.headers.get("content-type")||"");switch(_){case"json":{const m=await s.response.text(),b=s.options.parseResponse||Nt;s.response._data=b(m);break}case"stream":{s.response._data=s.response.body;break}default:s.response._data=await s.response[_]()}}return s.options.onResponse&&await s.options.onResponse(s),!s.options.ignoreResponseError&&s.response.status>=400&&s.response.status<600?(s.options.onResponseError&&await s.options.onResponseError(s),await r(s)):s.response},"$fetchRaw2"),a=l(async function(c,h){return(await o(c,h))._data},"$fetch2");return a.raw=o,a.native=(...u)=>e(...u),a.create=(u={})=>Re({...i,defaults:{...i.defaults,...u}}),a}l(Re,"createFetch");const se=function(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global;throw new Error("unable to locate global object")}(),yn=se.fetch||(()=>Promise.reject(new Error("[ofetch] global.fetch is not supported!"))),On=se.Headers,bn=se.AbortController,q=Re({fetch:yn,Headers:On,AbortController:bn});function J(){const i=[".frontstack"],e=".frontic";for(const t of i)if(D(t))return t;return e}l(J,"getOutputDirectory");function wn(){const i=[".frontstack-local"],e=".frontic-local";for(const t of i)if(D(t))return t;return e}l(wn,"getConfigDirectory");function Cn(){return D(".frontstack-local")}l(Cn,"isBackwardsCompatibility");const An={apiRoot:process.env.FRONTIC_CLI_API_ROOT||(process.env.FRONTIC_CLI_DEV_MODE=="1"?"https://backend.frontstack.test/":"https://backend.frontic.com/")},M=An.apiRoot,$n=`${M}login`,En=`${M}api/fetch-api/spec.yaml`,Ne=3008,ke=`http://localhost:${Ne}`,He=`${$n}?redirectUrl=${ke}/callback`,vn=wn()+"/",S=g.join(process.cwd(),vn),ae="api_session.jwt",Ie="project.json",R=l(()=>{const i=l(()=>{console.info("Not auth.login implemented yet")},"login"),e=l(async()=>{try{return a(),0}catch(p){console.log(p)}},"logout"),t=l(async(p=!1)=>{try{return process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTIC_CLI_DEV_MODE?"0":"1",await q(`${M}profile`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r()}`}})}catch(d){return p&&console.log(d),1}},"getProfile"),n=l(async p=>{try{if(p==null)throw new Error(`You have no project selected
|
|
24
|
+
Run ${f.hex("#7c3bed")("frontic project")} to select a Frontic project`);return process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTIC_CLI_DEV_MODE?"0":"1",await q(En,{method:"GET",headers:{"Content-Type":"application/yaml",Authorization:`Bearer ${r()}`,"FS-Project":p},parseResponse:l(_=>{try{return ge.load(_)}catch{throw new Error("Invalid API specification. The API specification must be a valid YAML file.")}},"parseResponse")})}catch(d){throw"data"in d&&"message"in d.data?new Error(`Server error: ${d.data.message}`):d}},"getFetchApiSpec"),r=l(()=>{const p=g.join(S,ae);return y.existsSync(p)?y.readFileSync(p,"utf8"):null},"getToken"),o=l(p=>(y.existsSync(S)||y.mkdirSync(S),y.writeFileSync(g.join(S,ae),p),0),"writeToken"),a=l(()=>{const p=g.join(S,ae);y.existsSync(p)&&y.unlinkSync(p)},"deleteToken"),u=l(async()=>(process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTIC_CLI_DEV_MODE?"0":"1",await q(`${M}api/project`,{method:"GET",headers:{"Content-Type":"application/yaml",Authorization:`Bearer ${r()}`},parseResponse:l(p=>JSON.parse(p),"parseResponse")})),"getProjects"),c=l(()=>{const p=g.join(S,Ie);if(!y.existsSync(p))return null;try{return JSON.parse(y.readFileSync(p,"utf8")).projectId}catch{console.error("[Error] Corrupt project file - please run 'frontic project'")}},"getProjectId");return{login:i,logout:e,getProfile:t,getFetchApiSpec:n,getToken:r,writeToken:o,deleteToken:a,getProjects:u,getProject:l(async(p=void 0)=>{try{return p===void 0&&(p=c()),p===void 0?void 0:(process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTIC_CLI_DEV_MODE?"0":"1",await q(`${M}api/project/${p}`,{method:"GET",headers:{"Content-Type":"application/yaml",Authorization:`Bearer ${r()}`},parseResponse:l(d=>JSON.parse(d),"parseResponse")}))}catch(d){return{error:d.message}}},"getProject"),getProjectId:c,writeProject:l(p=>(y.existsSync(S)||y.mkdirSync(S),y.writeFileSync(g.join(S,Ie),JSON.stringify({projectId:p})),0),"writeProject")}},"auth"),Fe=l(()=>{const i=l(t=>{const n=g.join(t,"metadata.json");if(y.existsSync(n)){const r=y.readFileSync(n,"utf8");return JSON.parse(r)}return null},"getMetadata");return{getMetadata:i,projectGuard:l(t=>{i(t)||(console.log(`${f.hex("#FFA500")("[WARNING]")} No \`${t}/metadata.json\` found, run ${f.hex("#7c3bed")("frontic generate")} to create a metadata file.`),console.log(`${f.hex("#FFA500")("[WARNING]")} Metadata files have been introduced to keep track of your generated code across multiple projects and organizations.`),console.log(`${f.hex("#FFA500")("[WARNING]")} If you only have a single project, you can ignore this message.`))},"projectGuard")}},"useMetadata"),{writeToken:Sn}=R(),jn=l(async(i,e,t=!1)=>new Promise(n=>{const r=new Set,o=nt.createServer((a,u)=>{const c=ke;if(a.url===void 0)return;const s=new URL(a.url,c).searchParams.get("token"),p=new Date().getFullYear();s&&(u.writeHead(200,{"Content-Type":"text/html"}),u.end(`<html><head><script>// window.close()<\/script></head><body style="font-family: sans-serif;"><div style="height: 100%; width: 100%; display: flex; justify-content: center; align-items: center;"><div style="text-align: center"><h1 style="color: #7c3bed;">Login Successful</h1><p>You can <a href="#" onClick="window.close()">close</a> this browser window and return to the terminal.<p style="font-size: .8rem; color: #666; text-align: left; margin-top: 20px;">© ${p} Frontic</p></div></div></html>`),u.on("finish",async()=>{for(const _ of r)_.destroy();Sn(s)!==0?(console.error("Login failed."),o.close(),n(!1)):(console.log(`${f.hex("#008000")("[SUCCESS]")} Login successful`),o.close(),n(!0)),t&&process.exit(0)}))}).listen(i,()=>{console.log(`Please continue login in your browser at ${f.hex("#7c3bed")(e)}`)});o.on("connection",a=>{r.add(a),a.on("close",()=>r.delete(a))}),setTimeout(()=>{o.close(),n(!1)},6e4)}),"login$1"),xn={processExit:!0,skipProjectGuard:!1},Ve=l(async i=>{const e=tt(i,xn);await it(He),await jn(Ne,He,!1);let t=J();if(e.skipProjectGuard){const{projectGuard:n}=Fe();n(t)}e?.processExit&&process.exit(0)},"login"),Tn=R(),Pn=l(async i=>{await Tn.logout()!==0&&(console.error("Logout failed."),process.exit(1)),console.log("Logout successful."),process.exit(0)},"logout"),{getFetchApiSpec:Rn}=R();E.registerHelper("eq",function(i,e){return i===e}),E.registerHelper("uc",function(i){return i.toUpperCase()}),E.registerHelper("and",function(i,e){return i&&e}),E.registerHelper("contains",function(i,e){return i===void 0?!1:i.includes(e)}),E.registerHelper("endsWith",function(i,e){return i===void 0?!1:i.endsWith(e)}),E.registerHelper("blockNameFromOperationId",function(i){return i.replace("get","").replace("Block","")});const ce=l(i=>i.$ref?`components['schemas']['${i.$ref.split("/").pop()}']`:i.type==="array"?`Array<${ce(i.items)}>`:i.type==="object"?`{ ${Object.keys(i.properties).map(t=>`${t}: ${ce(i.properties[t])}`).join("; ")} }`:i.type,"getSchemaType");E.registerHelper("getSchemaType",i=>ce(i)),E.registerHelper("stringInArray",function(i,e,t){return e==null||e.length===0?!1:t.fn?e.indexOf(i)>-1?t.fn(this):t.inverse(this):e.indexOf(i)>-1}),E.registerHelper("log",function(i){console.log(i)});var Nn=l(async i=>{const e=g.dirname(new URL(import.meta.url).pathname),t=g.join(e,"src/commands/generate/templates"),n=g.join(t,"types.js.hbs"),r=y.readFileSync(n,"utf8"),o=E.compile(r),a=g.join(t,"client.js.hbs"),u=y.readFileSync(a,"utf8"),c=E.compile(u),h=g.join(t,"query.js.hbs"),s=y.readFileSync(h,"utf8");let p;if(p=await Rn(i),p.error)throw new Error(`Issue fetching API specification. Check more information below.
|
|
25
|
+
`+p.error);let d="";try{d=await rt(p)}catch(b){throw new Error(`Invalid API Specification: ${b.message}`)}const _=o({paths:p.paths,components:p.components}),m=c({components:p.components,paths:p.paths,servers:p.servers,namespace:Cn()?"Frontstack":"Frontic"});return{_schemaTypes:d,_types:_,_client:m,_query:s,_specFile:p}},"generate");const{getProjects:kn,writeProject:De}=R(),Le=l(async i=>{let e=i.project??void 0,t=[];try{t=await kn()}catch{console.log(`You are not logged in. Please run ${f.hex("#7c3bed")("frontic login")} to login`);return}if(t.length<1){console.log("No projects found. Please create a new project in your Admin dashboard");return}if(e!==void 0){const o=t.find(a=>a.id===e);if(o){console.log(`Project ${f.hex("#7c3bed")(o.name)} selected`),De(o.id);return}else{console.log(`Project with ID "${e}" not found. Please select a valid project ID`);return}}const n={type:"select",name:"projectId",message:"Pick a project (Use arrow keys and Enter)",choices:t.map(o=>({title:(o.id===e?"(\u2714) ":"")+`${o.name}`,value:o.id}))};async function r(){const o=await W(n),a=t.find(u=>u.id===o.projectId);if(a===void 0){console.log(`Project with ID "${o.projectId}" not found. Please select a valid project ID`);return}console.log(`Project ${f.hex("#7c3bed")(a.name)} selected`),De(o.projectId)}l(r,"getProject"),await r()},"project"),Hn=l(async i=>{const e=i.verbose||!1,t=i.persistOas||!1,{getProject:n,getProfile:r,getProjects:o,writeProject:a}=R(),u=await r(e);if(!u||u===1){console.info("User not logged in"),await Ve({processExit:!1,skipProjectGuard:!0});const w=await r();(!w||w===1)&&(console.info(`${f.hex("#b90404")("[ERROR]")} Login failed`),process.exit(1))}let c=i.output||J(),h=await n();(!h||"error"in h)&&(console.info("No project selected"),console.info("Running project selection..."),await Le({}));const{getMetadata:s}=Fe(),p=s(c);if(h=await n(),!h||"error"in h){console.info(`${f.hex("#b90404")("[ERROR]")} frontic generate`),console.info(`${f.hex("#b90404")("[ERROR]")} Failed to generate Javascript client`);return}if(p&&p.project.id!==h.id&&!h.environments.some(w=>w.id===p.project.id)){const A=(await o()).find(Q=>Q.id===p.project.id),$=[];A&&$.push({title:`Switch to project ${f.hex("#7c3bed")(p.project.name)} and generate client`,value:"switch"}),$.push({title:`Overwrite client with project ${f.hex("#7c3bed")(h.name)} (${f.hex("#7c3bed")(h.environment)})`,value:"overwrite"}),$.push({title:"Cancel",value:"cancel"}),console.log(`${f.hex("#FFA500")("[WARNING]")} Client mismatch detected`),console.log(`${f.hex("#FFA500")("[WARNING]")} The client in ${f.hex("#7c3bed")(c)} was generated for project ${f.hex("#7c3bed")(p.project.name)}.`),console.log(`${f.hex("#FFA500")("[WARNING]")} The selected project is ${f.hex("#7c3bed")(h.name)} (${f.hex("#7c3bed")(h.environment)}).
|
|
26
|
+
`);const We={type:"select",name:"action",message:"How would you like to proceed?",choices:$},{action:U}=await W(We);if(U==="cancel"){console.info("Generation cancelled.");return}if(U==="switch"&&A&&(a(A.id),h=A,console.info(`Switched to project ${f.hex("#7c3bed")(h.name)}.`)),U==="overwrite"){const Q={type:"text",name:"confirmation",message:'This is a destructive action and will overwrite the existing client. Type "confirm" to proceed.'},{confirmation:Ge}=await W(Q);if(Ge!=="confirm"){console.info("Generation cancelled.");return}console.info(`Proceeding to generate client for project ${f.hex("#7c3bed")(h.name)}.`)}if(!U){console.info("Generation cancelled.");return}}let d=h;if(!h||"error"in h){console.info(`${f.hex("#b90404")("[ERROR]")} frontic generate`),console.info(`${f.hex("#b90404")("[ERROR]")} Failed to generate Javascript client`);return}if(i.env&&h.environments.length>0){let w;if(i.env!=="develop"){if(w=h.environments.find(A=>A.environment===i.env),!w){console.info(`${f.hex("#b90404")("[ERROR]")} frontic generate`),console.info(`${f.hex("#b90404")("[ERROR]")} Environment ${i.env} not found`);return}d=w}}if(!i.env&&h.environments.length>0){const w={type:"select",name:"projectId",message:"Pick an environment (use arrow keys and enter)",choices:[{title:`${h.name} (${h.environment})`,value:h.id},...h.environments.map($=>({title:($.id===d?.id?"(\u2714) ":"")+`${$.name} (${$.environment})`,value:$.id}))]},A=await W(w);d=h.environments.find($=>$.id===A.projectId)??h}let _,m,b,T,ue;try{e&&console.log("Generating Javascript client"),{_schemaTypes:_,_types:m,_client:b,_query:T,_specFile:ue}=await Nn(d.id)}catch(w){console.info(`${f.hex("#b90404")("[ERROR]")} frontic generate`),console.info(`${f.hex("#b90404")("[ERROR]")} Failed to generate Javascript client`),e?console.info(`${f.hex("#b90404")("[ERROR]")} ${w.message}`):(console.info("Are you..."),console.info(` * logged in using the ${f.hex("#7c3bed")("frontic login")} command?`),console.info(" * connected to the internet?"),console.info(`Alternatively, run ${f.hex("#7c3bed")("frontic generate -v")} for additional output.`));return}process.stdout.write("Generating Javascript client"),c.startsWith("/")||(c=g.join(process.cwd(),c)),c.endsWith("/")||(c+="/");const he=g.join(c,"fetch-api.d.ts"),pe=g.join(c,"generated-types.d.ts"),fe=g.join(c,"generated-client.ts"),Me=g.join(c,"query-types.ts"),de=g.join(c,"metadata.json"),Ue={project:{id:d.id,name:d.name}};if(e&&(console.log(`
|
|
27
|
+
Schema types path: ${f.dim(he)}`),console.log(`Types path: ${f.dim(pe)}`),console.log(`Client path: ${f.dim(fe)}`),console.log(`Target directory: ${f.dim(c)}`),console.log(`Metadata path: ${f.dim(de)}`)),y.mkdirSync(c,{recursive:!0}),t){const w=ge.dump(ue,{indent:2}),A=g.join(c,"fetch-api.spec.yaml");console.log(`
|
|
28
|
+
Persisting OpenAPI Specification file in ${A}`),y.writeFileSync(g.join(A),w)}y.writeFileSync(g.join(he),_),y.writeFileSync(g.join(pe),m),y.writeFileSync(g.join(fe),b),y.writeFileSync(g.join(Me),T),y.writeFileSync(g.join(de),JSON.stringify(Ue,null,2)),e?console.log(`Javascript client generated for ${f.hex("#7c3bed")(`${d.name} (${d.environment})`)}`):(process.stdout.clearLine(0),process.stdout.cursorTo(0),process.stdout.write(f.green(`Javascript client generated for ${f.hex("#7c3bed")(`${d.name} (${d.environment})`)}
|
|
29
|
+
`))),console.log(`
|
|
30
|
+
Use the following import in your project:
|
|
31
|
+
`),console.log(" "+f.hex("#7c3bed")(`import client from '${c}generated-client';`)),console.log(`
|
|
32
|
+
and use the client like this:
|
|
33
|
+
`),console.log(" "+f.hex("#7c3bed")("const productDetail = await client.block('DetailPage', { key: 'my-product-id' });")),console.log(`
|
|
34
|
+
If you make changes to your schema, run ${f.hex("#7c3bed")("frontic generate")} again to update the client.`),process.exit(0)},"generateCommand"),{getToken:In,getProfile:Fn,getProject:Vn}=R(),Dn=l(async()=>{if(In()===null){console.log("Status: Not logged in."),console.log("Run "+f.hex("#7c3bed")("frontic login")+" to login.");return}try{const e=await Fn();if(e===void 0||e===1){console.log("Status: Not logged in."),console.log("Run "+f.hex("#7c3bed")("frontic login")+" to login.");return}console.log("Logged in as "+f.hex("#7c3bed")(e.email)),console.log(`Organization: ${e.organization.name}`);const t=await Vn();if(t===void 0||"error"in t){console.log("Status: No project selected."),console.log("Run "+f.hex("#7c3bed")("frontic project")+" to select a frontic project");return}console.log(`Current Project: ${t.name??"[No active project selected]"}`)}catch(e){console.log(e)}},"info"),B=Xe(J(),"version-check-cache.json"),Ln=24*60*60*1e3,qn="https://registry.npmjs.org/@frontic/cli/latest";function Mn(i,e){const t=K.clean(i),n=K.clean(e);return!t||!n?!1:K.gt(n,t)}l(Mn,"isOutdated");function Un(){try{if(!D(B))return null;const i=me(B,"utf8"),e=JSON.parse(i);return Date.now()-e.lastChecked<Ln?e:null}catch{return null}}l(Un,"readCache");function Wn(i){try{const e=et(B);D(e)||Ke(e,{recursive:!0});const t={latestVersion:i,lastChecked:Date.now()};Ye(B,JSON.stringify(t,null,2))}catch{}}l(Wn,"writeCache");async function Gn(){try{return(await q(qn,{timeout:3e3})).version}catch{return null}}l(Gn,"fetchLatestVersion");async function Jn(i){if(!i.includes("dev"))try{let e=Un(),t;e?t=e.latestVersion:(t=await Gn(),t&&Wn(t)),t&&Mn(i,t)&&(console.log(),console.log(f.bgHex("#7c3bed").bold("Update available!")),console.log(`Current version: ${f.red(i)}`),console.log(`Latest version: ${f.green(t)}`),console.log())}catch{}}l(Jn,"checkVersion");const Bn=ot(import.meta.url),zn=g.dirname(Bn),qe=me(g.join(zn,"version"),"utf8");let z="0.0.1-dev";qe&&(z=qe.trim());const j=new St;j.name("frontic").description(`${f.bgHex("#7c3bed").bold("Frontic CLI")}
|
|
35
|
+
Manage Frontic projects from the command line.
|
|
36
|
+
${f.dim(`Version: ${z}`)}`).version(z),j.command("login").description("Login to Frontic account").action(()=>{Ve()}),j.command("logout").description("Logout from Frontic account").action(async i=>{await Pn()}),j.command("generate").description("Generate a JavaScript client for the current project").option("-o, --output <path>","Output path",J()).option("-v, --verbose","Enable verbose logging").option("-e --env <alias>",'Pass an environment alias like "develop" or "preview"').option("-s --persist-oas","Persist OpenAPI specification file").action(async i=>{await Hn(i)}),j.command("info").description("Display information about the current organization, project, and user").action(async()=>{await Dn()}),j.command("project").description("Select current working project which will be used for schema and client updates").option("-p --project <project-id>","Set current project ID").action(async i=>{await Le(i)});const Qn=l(async()=>{try{await Jn(z),j.parse(process.argv)}catch(i){console.log(i)}},"run");var Kn=Qn();export{Kn as default};
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated using the
|
|
3
|
+
* Frontic CLI, please do not edit it manually!
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ofetch } from 'ofetch'
|
|
7
|
+
|
|
8
|
+
import type { Endpoints, Responses, RequestOptions, Blocks, Listings, ListingParameters, ListingQueryFilters, ListingQuerySorts } from './generated-types'
|
|
9
|
+
|
|
10
|
+
import type { Query } from './query-types'
|
|
11
|
+
|
|
12
|
+
type Method = 'GET' | 'POST' | 'PATCH' | 'DELETE'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Global configuration options for the Frontic client
|
|
16
|
+
*/
|
|
17
|
+
export interface ClientConfig {
|
|
18
|
+
/**
|
|
19
|
+
* @description Proxy URL
|
|
20
|
+
*
|
|
21
|
+
* Optionally, provide a proxy URL path that will be concatenated with the original API path.
|
|
22
|
+
* For example, if proxyUrl is '/api' and the original request is to '/block',
|
|
23
|
+
* the request will be sent to '/api/block'.
|
|
24
|
+
* The original target URL is passed in the 'fs-target-url' header for the proxy to forward to.
|
|
25
|
+
* This is useful to prevent CORS issues when making requests from a browser.
|
|
26
|
+
* Can be overridden per-request via RequestOptions.
|
|
27
|
+
*/
|
|
28
|
+
proxyUrl?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Interface describing the Frontic client API
|
|
33
|
+
*/
|
|
34
|
+
export interface {{namespace}}Client {
|
|
35
|
+
/**
|
|
36
|
+
* Fetch a block with a key
|
|
37
|
+
*
|
|
38
|
+
* @param name The name of the block to fetch
|
|
39
|
+
* @example 'VariantCard'
|
|
40
|
+
* @param key The key identifier for the block
|
|
41
|
+
* @example '<variant-id>'
|
|
42
|
+
* @param config Further configuration options
|
|
43
|
+
*/
|
|
44
|
+
block: <ApiName extends keyof Blocks>(
|
|
45
|
+
name: ApiName,
|
|
46
|
+
key: string,
|
|
47
|
+
config?: RequestOptions
|
|
48
|
+
) => Promise<Responses[ApiName]>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Fetch a listing with optional parameters and query options
|
|
52
|
+
*
|
|
53
|
+
* @param name The name of the listing to fetch
|
|
54
|
+
* @example 'ProductList'
|
|
55
|
+
* @param parameters The parameters to pass to the listing
|
|
56
|
+
* @example { categoryId: '<category-id>' }
|
|
57
|
+
* @param config Further configuration options
|
|
58
|
+
* @example {
|
|
59
|
+
* query: {
|
|
60
|
+
* filter: [{ type: 'equals', field: 'color', value: 'Red' }],
|
|
61
|
+
* sort: [{
|
|
62
|
+
* 'field': 'publishedAt',
|
|
63
|
+
* 'order': 'asc'
|
|
64
|
+
* }]
|
|
65
|
+
* }
|
|
66
|
+
* }
|
|
67
|
+
*/
|
|
68
|
+
listing: <ApiName extends keyof Listings>(
|
|
69
|
+
name: ApiName,
|
|
70
|
+
parameters: ListingParameters[ApiName],
|
|
71
|
+
config?: {
|
|
72
|
+
/**
|
|
73
|
+
* Query parameters to pass to the listing:
|
|
74
|
+
* - `filter` accepts an array of filter objects to filter results
|
|
75
|
+
* - `sort` accepts a string, a sorting option object, or an array of sorting option objects to sort results
|
|
76
|
+
* - `search` to perform a text search
|
|
77
|
+
* - `limit` to limit the number of results returned
|
|
78
|
+
* - `page` to paginate results
|
|
79
|
+
*/
|
|
80
|
+
query?: Query<ListingQueryFilters[ApiName], ListingQuerySorts[ApiName]>
|
|
81
|
+
} & RequestOptions
|
|
82
|
+
) => Promise<Responses[ApiName]>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Fetch a page by its slug
|
|
86
|
+
* @param slug The URL slug of the page (without protocol)
|
|
87
|
+
* @example demo-shop.com/uk/women/shoes/running
|
|
88
|
+
*
|
|
89
|
+
* @returns The page data
|
|
90
|
+
* @example { data: { title: 'Running Shoes' }, type: 'ProductCategory', urls: [] }
|
|
91
|
+
*/
|
|
92
|
+
page: (
|
|
93
|
+
slug: string,
|
|
94
|
+
config?: RequestOptions
|
|
95
|
+
) => Promise<Page>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Fetch a context by its token
|
|
99
|
+
* @param token The token of the context
|
|
100
|
+
* @example 'ae0d4981-c363-4d5a-a49e-1f053d49f2f7'
|
|
101
|
+
* @param config Further configuration options
|
|
102
|
+
*
|
|
103
|
+
* @returns The context and token
|
|
104
|
+
*/
|
|
105
|
+
context: (
|
|
106
|
+
token: ContextToken,
|
|
107
|
+
config?: RequestOptions
|
|
108
|
+
) => Promise<Context>;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Fetch a list of contexts
|
|
112
|
+
* @param token The token of the context to fetch
|
|
113
|
+
* @example 'ae0d4981-c363-4d5a-a49e-1f053d49f2f7'
|
|
114
|
+
* @param config Further configuration options
|
|
115
|
+
*
|
|
116
|
+
* @returns The list of contexts and the token
|
|
117
|
+
*/
|
|
118
|
+
contextList: (
|
|
119
|
+
token?: ContextToken,
|
|
120
|
+
config?: RequestOptions
|
|
121
|
+
) => Promise<[ContextOption[], ContextToken]>;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Update a context
|
|
125
|
+
* @param context The context to update
|
|
126
|
+
* @example { region: 'uk', locale: 'en-GB' }
|
|
127
|
+
* @param token The token of the context to update
|
|
128
|
+
* @example 'ae0d4981-c363-4d5a-a49e-1f053d49f2f7'
|
|
129
|
+
* @param config Further configuration options
|
|
130
|
+
*
|
|
131
|
+
* @returns The updated context
|
|
132
|
+
*/
|
|
133
|
+
contextUpdate: (
|
|
134
|
+
context: {
|
|
135
|
+
region: string
|
|
136
|
+
locale: string
|
|
137
|
+
},
|
|
138
|
+
token: ContextToken,
|
|
139
|
+
config?: RequestOptions
|
|
140
|
+
) => Promise<Context>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const endpoints: Endpoints = {
|
|
144
|
+
{{#each paths}}
|
|
145
|
+
{{#if (endsWith this.post.operationId "Block")}}
|
|
146
|
+
{{this.summary}}: '{{@key}}',
|
|
147
|
+
{{/if}}
|
|
148
|
+
{{/each}}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const invoke = async (path: string, method: Method, payload: any, headers: any, proxyUrl?: string) => {
|
|
152
|
+
const _headers: any = {
|
|
153
|
+
'Content-Type': 'application/json',
|
|
154
|
+
'Accept': 'application/json',
|
|
155
|
+
{{#if components.parameters.FsVersionToken.required}}
|
|
156
|
+
'fs-version': '{{components.parameters.FsVersionToken.schema.enum.[0]}}',
|
|
157
|
+
{{/if}}
|
|
158
|
+
{{#if components.parameters.FsSecret.required}}
|
|
159
|
+
'fs-secret': '{{components.parameters.FsSecret.schema.enum.[0]}}',
|
|
160
|
+
{{/if}}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Merge headers
|
|
164
|
+
headers = { ..._headers, ...headers }
|
|
165
|
+
|
|
166
|
+
let options: any = {
|
|
167
|
+
method,
|
|
168
|
+
headers,
|
|
169
|
+
body: payload
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// If proxy URL is provided, concatenate it with the original path
|
|
173
|
+
if (proxyUrl) {
|
|
174
|
+
// Parse the original full URL to extract just the pathname
|
|
175
|
+
const url = new URL(path)
|
|
176
|
+
const originalPath = url.pathname
|
|
177
|
+
|
|
178
|
+
// Store the original full URL in header for the proxy to use
|
|
179
|
+
headers['fs-target-url'] = path
|
|
180
|
+
|
|
181
|
+
// Concatenate proxy URL with the original path
|
|
182
|
+
// Remove trailing slash from proxyUrl and leading slash is already in originalPath
|
|
183
|
+
const normalizedProxyUrl = proxyUrl.endsWith('/') ? proxyUrl.slice(0, -1) : proxyUrl
|
|
184
|
+
path = normalizedProxyUrl + originalPath
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return await ofetch.raw(path, options)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/* Listing servers, even though only the first one is ever used */
|
|
191
|
+
const servers = [
|
|
192
|
+
{{#each servers}}
|
|
193
|
+
{ description: '{{description}}', url: '{{url}}' },
|
|
194
|
+
{{/each}}
|
|
195
|
+
]
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Create a Frontic client with optional global configuration
|
|
199
|
+
*
|
|
200
|
+
* @param config Global configuration options for the client
|
|
201
|
+
* @example
|
|
202
|
+
* const client = createClient({ proxyUrl: '/api/frontic' })
|
|
203
|
+
*
|
|
204
|
+
* @returns A configured Frontic client instance
|
|
205
|
+
*/
|
|
206
|
+
const createClient = (config?: ClientConfig): {{namespace}}Client => {
|
|
207
|
+
const globalConfig = config || {}
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
/**
|
|
211
|
+
* Fetch a block with a key
|
|
212
|
+
*/
|
|
213
|
+
block: async (name, key, config) => {
|
|
214
|
+
if(!(name in endpoints)) {
|
|
215
|
+
throw new Error(`Block ${name} not found`)
|
|
216
|
+
}
|
|
217
|
+
let endpoint: string = `${servers[0].url}${endpoints[name]}`;
|
|
218
|
+
|
|
219
|
+
// Replace '{key}' in the endpoint
|
|
220
|
+
endpoint = endpoint.replace('{key}', key);
|
|
221
|
+
|
|
222
|
+
// No additional parameters needed for blocks
|
|
223
|
+
let payload = { param: {} };
|
|
224
|
+
|
|
225
|
+
let headers: Record<string, string> = {}
|
|
226
|
+
|
|
227
|
+
if(config?.requestUrl !== undefined) {
|
|
228
|
+
headers['fs-request-url'] = config.requestUrl
|
|
229
|
+
}
|
|
230
|
+
if (config?.contextKey !== undefined) {
|
|
231
|
+
headers["fs-context"] = config.contextKey;
|
|
232
|
+
}
|
|
233
|
+
if (config?.contextDomain !== undefined) {
|
|
234
|
+
headers["fs-domain"] = config.contextDomain;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Use per-request proxyUrl if provided, otherwise use global config
|
|
238
|
+
const proxyUrl = config?.proxyUrl ?? globalConfig.proxyUrl
|
|
239
|
+
|
|
240
|
+
return (await invoke(endpoint, 'POST', payload, headers, proxyUrl))._data
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Fetch a listing with parameters and optional query options
|
|
245
|
+
*/
|
|
246
|
+
listing: async (name, parameters, config) => {
|
|
247
|
+
if(!(name in endpoints)) {
|
|
248
|
+
throw new Error(`Listing ${name} not found`)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
let endpoint: string = `${servers[0].url}${endpoints[name]}`;
|
|
252
|
+
|
|
253
|
+
// Merge listing parameters with query
|
|
254
|
+
let payload = config && 'query' in config ? { param: {...parameters}, ...config.query } : { param: {...parameters} }
|
|
255
|
+
|
|
256
|
+
let headers: Record<string, string> = {}
|
|
257
|
+
|
|
258
|
+
if(config?.requestUrl !== undefined) {
|
|
259
|
+
headers['fs-request-url'] = config.requestUrl
|
|
260
|
+
}
|
|
261
|
+
if (config?.contextKey !== undefined) {
|
|
262
|
+
headers["fs-context"] = config.contextKey;
|
|
263
|
+
}
|
|
264
|
+
if (config?.contextDomain !== undefined) {
|
|
265
|
+
headers["fs-domain"] = config.contextDomain;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Use per-request proxyUrl if provided, otherwise use global config
|
|
269
|
+
const proxyUrl = config?.proxyUrl ?? globalConfig.proxyUrl
|
|
270
|
+
|
|
271
|
+
return (await invoke(endpoint, 'POST', payload, headers, proxyUrl))._data
|
|
272
|
+
},
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Fetch a page by its slug
|
|
276
|
+
*/
|
|
277
|
+
page: async (slug, config) => {
|
|
278
|
+
let endpoint: string = `${servers[0].url}/page/${slug}`;
|
|
279
|
+
|
|
280
|
+
let headers: Record<string, string> = {}
|
|
281
|
+
|
|
282
|
+
if(config?.requestUrl !== undefined) {
|
|
283
|
+
headers['fs-request-url'] = config.requestUrl
|
|
284
|
+
}
|
|
285
|
+
if (config?.contextKey !== undefined) {
|
|
286
|
+
headers["fs-context"] = config.contextKey;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Use per-request proxyUrl if provided, otherwise use global config
|
|
290
|
+
const proxyUrl = config?.proxyUrl ?? globalConfig.proxyUrl
|
|
291
|
+
|
|
292
|
+
return (await invoke(endpoint, 'GET', null, headers, proxyUrl))._data
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Fetch a context by its token
|
|
297
|
+
*/
|
|
298
|
+
context: async (token, config) => {
|
|
299
|
+
let endpoint: string = `${servers[0].url}/context/token`;
|
|
300
|
+
|
|
301
|
+
let headers: Record<string, string> = {
|
|
302
|
+
'fs-context': token
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Use per-request proxyUrl if provided, otherwise use global config
|
|
306
|
+
const proxyUrl = config?.proxyUrl ?? globalConfig.proxyUrl
|
|
307
|
+
|
|
308
|
+
return (await invoke(endpoint, 'GET', null, headers, proxyUrl))._data
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Fetch a list of contexts
|
|
313
|
+
*/
|
|
314
|
+
contextList: async (token, config) => {
|
|
315
|
+
let endpoint: string = `${servers[0].url}/context`;
|
|
316
|
+
|
|
317
|
+
const requestHeaders: Record<string, string> = {}
|
|
318
|
+
|
|
319
|
+
if (token) {
|
|
320
|
+
requestHeaders["fs-context"] = token;
|
|
321
|
+
}
|
|
322
|
+
if (config?.contextDomain !== undefined) {
|
|
323
|
+
requestHeaders["fs-domain"] = config.contextDomain;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Use per-request proxyUrl if provided, otherwise use global config
|
|
327
|
+
const proxyUrl = config?.proxyUrl ?? globalConfig.proxyUrl
|
|
328
|
+
|
|
329
|
+
const {
|
|
330
|
+
_data,
|
|
331
|
+
headers: responseHeaders
|
|
332
|
+
} = await invoke(endpoint, 'GET', null, requestHeaders, proxyUrl)
|
|
333
|
+
|
|
334
|
+
return [_data, responseHeaders.get('fs-context')!]
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Update a context
|
|
339
|
+
*/
|
|
340
|
+
contextUpdate: async (context, token, config) => {
|
|
341
|
+
let endpoint: string = `${servers[0].url}/context`;
|
|
342
|
+
|
|
343
|
+
let headers: Record<string, string> = {
|
|
344
|
+
'fs-context': token
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Use per-request proxyUrl if provided, otherwise use global config
|
|
348
|
+
const proxyUrl = config?.proxyUrl ?? globalConfig.proxyUrl
|
|
349
|
+
|
|
350
|
+
return (await invoke(endpoint, 'PATCH', context, headers, proxyUrl))._data
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Default client instance (without global configuration)
|
|
357
|
+
* For global configuration (e.g. proxy URL), use createClient() instead
|
|
358
|
+
*/
|
|
359
|
+
const client = createClient()
|
|
360
|
+
|
|
361
|
+
export default client
|
|
362
|
+
export { createClient, client }
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated using the
|
|
3
|
+
* Frontic CLI, please do not edit it manually!
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type Filter<T> = EqualsFilter<T> | RangeFilter<T> | ContainsFilter<T> | LogicalFilter<T>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Helper Types
|
|
10
|
+
*/
|
|
11
|
+
type NumericKeys<T> = {
|
|
12
|
+
[K in keyof T]: T[K] extends number ? K : never
|
|
13
|
+
}[keyof T];
|
|
14
|
+
|
|
15
|
+
type EnumKeys<T> = {
|
|
16
|
+
[K in keyof T]: T[K] extends string ? (string extends T[K] ? never : K) : never
|
|
17
|
+
}[keyof T];
|
|
18
|
+
|
|
19
|
+
// All string keys that are not enums
|
|
20
|
+
type StringKeys<T> = {
|
|
21
|
+
[K in keyof T]: T[K] extends string ? K : never
|
|
22
|
+
}[keyof T] & Exclude<keyof T, EnumKeys<T>>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Filter a field by equality. You can use an array of values to filter by multiple values
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* {
|
|
29
|
+
* type: 'equals',
|
|
30
|
+
* field: 'color',
|
|
31
|
+
* value: ['Red', 'Blue']
|
|
32
|
+
* }
|
|
33
|
+
*/
|
|
34
|
+
export type EqualsFilter<T> = {
|
|
35
|
+
[K in keyof T]: {
|
|
36
|
+
type: 'equals';
|
|
37
|
+
field: K;
|
|
38
|
+
value: T[K] | T[K][];
|
|
39
|
+
}
|
|
40
|
+
}[keyof T];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Filter a field by a range. You can use either from, to or both
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* {
|
|
47
|
+
* type: 'range',
|
|
48
|
+
* field: 'price',
|
|
49
|
+
* from: 10,
|
|
50
|
+
* to: 100
|
|
51
|
+
* }
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
type RangeFilterShapes<K> = {
|
|
55
|
+
from: K
|
|
56
|
+
} | {
|
|
57
|
+
to: K
|
|
58
|
+
} | {
|
|
59
|
+
from: K
|
|
60
|
+
to: K
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type RangeFilter<T> = {
|
|
64
|
+
[K in NumericKeys<T>]: {
|
|
65
|
+
type: 'range';
|
|
66
|
+
field: K;
|
|
67
|
+
} & RangeFilterShapes<T[K]>
|
|
68
|
+
}[NumericKeys<T>];
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Filter a field by a word match.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* {
|
|
75
|
+
* type: 'contains',
|
|
76
|
+
* field: 'name',
|
|
77
|
+
* value: 'Dress'
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* will match:
|
|
81
|
+
*
|
|
82
|
+
* - 'Yellow Dress'
|
|
83
|
+
*/
|
|
84
|
+
export type ContainsFilter<T> = {
|
|
85
|
+
[K in StringKeys<T>]: {
|
|
86
|
+
type: 'contains';
|
|
87
|
+
field: K;
|
|
88
|
+
value: string;
|
|
89
|
+
}
|
|
90
|
+
}[StringKeys<T>];
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Combine multiple filters with a logical operator
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* {
|
|
97
|
+
* type: 'and',
|
|
98
|
+
* filter: [
|
|
99
|
+
* {
|
|
100
|
+
* type: 'equals',
|
|
101
|
+
* field: 'color',
|
|
102
|
+
* value: 'Red'
|
|
103
|
+
* },
|
|
104
|
+
* {
|
|
105
|
+
* type: 'range',
|
|
106
|
+
* field: 'price',
|
|
107
|
+
* from: 10,
|
|
108
|
+
* to: 100
|
|
109
|
+
* }
|
|
110
|
+
* ]
|
|
111
|
+
* }
|
|
112
|
+
*/
|
|
113
|
+
export type LogicalFilter<T> = {
|
|
114
|
+
type: 'and' | 'or' | 'not';
|
|
115
|
+
filter: Filter<T>[];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export type SortField<T> = keyof T;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Sort results by a field and ordering direction
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* {
|
|
125
|
+
* field: 'publishedAt',
|
|
126
|
+
* order: 'asc'
|
|
127
|
+
* }
|
|
128
|
+
*/
|
|
129
|
+
export type Sort<T> = {
|
|
130
|
+
field: SortField<T>;
|
|
131
|
+
order: 'asc' | 'desc';
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type Query<FilterType, SortType> = {
|
|
135
|
+
/**
|
|
136
|
+
* Filter results by a set of conditions
|
|
137
|
+
*/
|
|
138
|
+
filter?: Filter<FilterType>[];
|
|
139
|
+
/**
|
|
140
|
+
* Will search fields that are marked as searchable
|
|
141
|
+
*/
|
|
142
|
+
search?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Sort results by a field and direction
|
|
145
|
+
*
|
|
146
|
+
* There are three ways to sort:
|
|
147
|
+
*
|
|
148
|
+
* * A single sort object
|
|
149
|
+
* * An array of sort objects
|
|
150
|
+
* * A single sort field string
|
|
151
|
+
*/
|
|
152
|
+
sort?: Sort<SortType> | Sort<SortType>[] | SortField<SortType>;
|
|
153
|
+
/**
|
|
154
|
+
* Limit the number of results returned
|
|
155
|
+
*/
|
|
156
|
+
limit?: number;
|
|
157
|
+
/**
|
|
158
|
+
* Paginate results
|
|
159
|
+
*/
|
|
160
|
+
page?: number;
|
|
161
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated using the
|
|
3
|
+
* Frontic CLI, please do not edit it manually!
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { components } from './fetch-api.d.ts'
|
|
7
|
+
|
|
8
|
+
type RequestOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* @description URL to the current page
|
|
11
|
+
*
|
|
12
|
+
* Optionally, Frontic accepts a URL to the current page. This is useful for tracking purposes.
|
|
13
|
+
*/
|
|
14
|
+
requestUrl?: string
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @description Context key
|
|
18
|
+
*
|
|
19
|
+
* Providing a context key will override the default context key for the request
|
|
20
|
+
*/
|
|
21
|
+
contextKey?: string
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @description Context Domain
|
|
25
|
+
* @see contextKey A context key will take precedence over this domain
|
|
26
|
+
*
|
|
27
|
+
* Providing a context domain will indicate the requested region and locale based on the domain's configuration for the request.
|
|
28
|
+
*/
|
|
29
|
+
contextDomain?: string
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @description Proxy URL
|
|
33
|
+
*
|
|
34
|
+
* Optionally, provide a proxy URL path that will be concatenated with the original API path.
|
|
35
|
+
* For example, if proxyUrl is '/api' and the original request is to '/block',
|
|
36
|
+
* the request will be sent to '/api/block'.
|
|
37
|
+
* You can provide absolute as well as relative URLs.
|
|
38
|
+
* The original target URL is passed in the 'fs-target-url' header for the proxy to forward to.
|
|
39
|
+
* This is useful to prevent CORS issues when making requests from a browser.
|
|
40
|
+
*/
|
|
41
|
+
proxyUrl?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* List of all types used to fetch block parameters */
|
|
45
|
+
|
|
46
|
+
{{#each paths}}{{#if (and (endsWith this.post.operationId "Block") (contains this.post.tags "fetch-listing"))}}export type {{this.summary}}Parameters = {
|
|
47
|
+
{{#each this.post.parameters}}
|
|
48
|
+
{{#if @first}}{{else}}
|
|
49
|
+
{{/if}}
|
|
50
|
+
/**
|
|
51
|
+
* @description {{description}}
|
|
52
|
+
*/
|
|
53
|
+
{{name}}{{#unless required}}?{{/unless}}: {{{getSchemaType schema}}};
|
|
54
|
+
{{/each}}
|
|
55
|
+
{{#if this.post.requestBody}}
|
|
56
|
+
{{#with this.post.requestBody.content.[application/json].schema.allOf.1.properties.param}}
|
|
57
|
+
{{#each properties}}
|
|
58
|
+
{{#if @first}}{{else}}
|
|
59
|
+
{{/if}}
|
|
60
|
+
/**
|
|
61
|
+
* @description {{description}}
|
|
62
|
+
*/
|
|
63
|
+
{{@key}}{{#unless (stringInArray @key ../required)}}?{{/unless}}: {{{getSchemaType this}}};
|
|
64
|
+
{{/each}}
|
|
65
|
+
{{/with}}
|
|
66
|
+
{{/if}}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
{{/if}}{{/each}}
|
|
70
|
+
/* List of all blocks, used for IDE autocompletion */
|
|
71
|
+
|
|
72
|
+
type ListingParameters = {
|
|
73
|
+
{{#each components.schemas}}
|
|
74
|
+
{{#if (contains tags "fetch-listing")}}
|
|
75
|
+
{{@key}}: {{@key}}Parameters
|
|
76
|
+
{{/if}}
|
|
77
|
+
{{/each}}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type Endpoints = {
|
|
81
|
+
[key in keyof Listings | keyof Blocks]: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* Types for split block/listing methods */
|
|
85
|
+
export type Blocks = {
|
|
86
|
+
{{#each components.schemas}}
|
|
87
|
+
{{#if (contains tags "fetch-block")}}
|
|
88
|
+
{{@key}}: never
|
|
89
|
+
{{/if}}
|
|
90
|
+
{{/each}}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export type Listings = {
|
|
94
|
+
{{#each components.schemas}}
|
|
95
|
+
{{#if (contains tags "fetch-listing")}}
|
|
96
|
+
{{@key}}: {{@key}}Parameters
|
|
97
|
+
{{/if}}
|
|
98
|
+
{{/each}}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
declare global {
|
|
102
|
+
{{#each components.schemas}}
|
|
103
|
+
{{#if (contains tags "fetch-api")}}
|
|
104
|
+
export type {{@key}} = components['schemas']['{{@key}}']
|
|
105
|
+
{{/if}}
|
|
106
|
+
{{/each}}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export type Responses = {
|
|
110
|
+
{{#each components.schemas}}
|
|
111
|
+
{{#if (contains tags "fetch-api")}}
|
|
112
|
+
{{@key}}: {{@key}}
|
|
113
|
+
{{/if}}
|
|
114
|
+
{{/each}}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export type ListingQueryFilters = {
|
|
118
|
+
{{#each components.schemas}}
|
|
119
|
+
{{#if (contains tags "fetch-listing")}}
|
|
120
|
+
{{@key}}: components['schemas']['{{@key}}QueryOptions']['filter']
|
|
121
|
+
{{/if}}
|
|
122
|
+
{{/each}}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type ListingQuerySorts = {
|
|
126
|
+
{{#each components.schemas}}
|
|
127
|
+
{{#if (contains tags "fetch-listing")}}
|
|
128
|
+
{{@key}}: components['schemas']['{{@key}}QueryOptions']['sort']
|
|
129
|
+
{{/if}}
|
|
130
|
+
{{/each}}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
type FetchMode = {
|
|
134
|
+
{{#each components.schemas}}
|
|
135
|
+
{{#if (contains tags "fetch-api")}}
|
|
136
|
+
{{@key}}: {{#if (contains tags "fetch-listing") }}'query'{{else}}'key'{{/if}};
|
|
137
|
+
{{/if}}
|
|
138
|
+
{{/each}}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
{{!-- Provide global types for page router --}}
|
|
142
|
+
declare global {
|
|
143
|
+
export type Page = components['schemas']['Page']
|
|
144
|
+
export type PageRoute = components["schemas"]["PageRoute"];
|
|
145
|
+
export type RouteMeta = components["schemas"]["RouteMeta"];
|
|
146
|
+
export type AlternateRoute = components["schemas"]["AlternateRoute"];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
{{!-- Provide global types for listing meta data --}}
|
|
150
|
+
declare global {
|
|
151
|
+
export type Pagination = components["schemas"]["_page"];
|
|
152
|
+
export type FilterData = components["schemas"]["_filter"];
|
|
153
|
+
export type FilterGroup = components["schemas"]["_filter"][string];
|
|
154
|
+
export type Filter = components["schemas"]["_filter"][string][number];
|
|
155
|
+
export type SortingGroup = components["schemas"]["_sort"];
|
|
156
|
+
export type Sorting = components["schemas"]["_sort"][number];
|
|
157
|
+
export type AggregationData = components["schemas"]["_aggregation"];
|
|
158
|
+
export type AggregationGroup = components["schemas"]["_aggregation"][string];
|
|
159
|
+
export type Aggregation = components["schemas"]["_aggregation"][string]["total"];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
{{!-- Export all composites and enums --}}
|
|
163
|
+
declare global {
|
|
164
|
+
{{#each components.schemas}}
|
|
165
|
+
{{#if (contains tags "composites")}}
|
|
166
|
+
export type {{@key}} = components['schemas']['{{@key}}']
|
|
167
|
+
{{/if}}
|
|
168
|
+
{{/each}}
|
|
169
|
+
{{#each components.schemas}}
|
|
170
|
+
{{#if (contains tags "enums")}}
|
|
171
|
+
export type {{@key}} = components['schemas']['{{@key}}']
|
|
172
|
+
{{/if}}
|
|
173
|
+
{{/each}}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
declare global {
|
|
177
|
+
export type ContextToken = string
|
|
178
|
+
|
|
179
|
+
export type Context = {
|
|
180
|
+
/**
|
|
181
|
+
* The region of the context - e.g. 'uk'
|
|
182
|
+
*/
|
|
183
|
+
region: string
|
|
184
|
+
/**
|
|
185
|
+
* The locale of the context - e.g. 'en-gb'
|
|
186
|
+
*/
|
|
187
|
+
locale: string
|
|
188
|
+
/**
|
|
189
|
+
* The scope of the context - e.g. 'b2c'
|
|
190
|
+
*/
|
|
191
|
+
scope: string
|
|
192
|
+
/**
|
|
193
|
+
* The identifier of the context
|
|
194
|
+
*/
|
|
195
|
+
token: ContextToken
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export type ContextOption = {
|
|
199
|
+
/**
|
|
200
|
+
* The region of the context - e.g. 'uk'
|
|
201
|
+
*/
|
|
202
|
+
region: string
|
|
203
|
+
/**
|
|
204
|
+
* The currency of the context - e.g. 'GBP'
|
|
205
|
+
*/
|
|
206
|
+
currency: string
|
|
207
|
+
/**
|
|
208
|
+
* List of locales of the context
|
|
209
|
+
*/
|
|
210
|
+
locales: Array<Locale>
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export type Locale = {
|
|
214
|
+
/**
|
|
215
|
+
* The key of the locale - e.g. 'en-GB'
|
|
216
|
+
*/
|
|
217
|
+
key: string
|
|
218
|
+
/**
|
|
219
|
+
* The URL configured for the locale - e.g. 'https://demo-shop.com/uk/en'
|
|
220
|
+
*/
|
|
221
|
+
url: string
|
|
222
|
+
}
|
|
223
|
+
}
|
package/dist/version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.0-canary-20260121141656
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@frontic/cli",
|
|
3
|
+
"version": "0.0.0-canary-20260121141656",
|
|
4
|
+
"description": "Frontic CLI for managing your storefront projects",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "dist/frontic.mjs",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "pkgroll --clean-dist --minify && mkdir -p dist/src/commands/generate && cp -r src/commands/generate/templates dist/src/commands/generate/ && cp version dist",
|
|
9
|
+
"start": "tsx src/frontic.ts",
|
|
10
|
+
"frontic": "pnpm build && node dist/frontic.mjs",
|
|
11
|
+
"test": "vitest",
|
|
12
|
+
"lint": "tsc",
|
|
13
|
+
"format:check": "npx prettier . --check",
|
|
14
|
+
"format": "npx prettier . --write",
|
|
15
|
+
"clean": "rm -rf dist"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [],
|
|
18
|
+
"bin": {
|
|
19
|
+
"frontic": "dist/frontic.mjs"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"author": "frontstack GmbH",
|
|
25
|
+
"optionalDependencies": {
|
|
26
|
+
"@types/js-yaml": "^4.0.9",
|
|
27
|
+
"@types/node": "^22.5.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/semver": "^7.7.1",
|
|
31
|
+
"commander": "^12.0.0",
|
|
32
|
+
"msw": "^2.2.14",
|
|
33
|
+
"ofetch": "^1.3.4",
|
|
34
|
+
"pkgroll": "^2.4.2",
|
|
35
|
+
"prettier": "^3.6.2",
|
|
36
|
+
"tsx": "^4.18.0",
|
|
37
|
+
"typescript": "^5.5.4",
|
|
38
|
+
"vitest": "^1.5.0"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@kinde-oss/kinde-nodejs-sdk": "^1.2.3",
|
|
42
|
+
"@types/prompts": "^2.4.9",
|
|
43
|
+
"chalk": "^5.3.0",
|
|
44
|
+
"defu": "^6.1.4",
|
|
45
|
+
"handlebars": "^4.7.8",
|
|
46
|
+
"js-yaml": "^4.1.0",
|
|
47
|
+
"open": "^10.1.0",
|
|
48
|
+
"openapi-typescript": "^6.7.5",
|
|
49
|
+
"pathe": "^2.0.3",
|
|
50
|
+
"prompts": "^2.4.2",
|
|
51
|
+
"semver": "^7.7.3"
|
|
52
|
+
},
|
|
53
|
+
"packageManager": "pnpm@10.20.0"
|
|
54
|
+
}
|