@frontstackdev/cli 0.0.0-canary-20241004210640 → 0.0.0-canary-20241007160625

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.
@@ -20,7 +20,7 @@ Expecting one of '${n.join("', '")}'`);return this._lifeCycleHooks[e]?this._life
20
20
  `),this.outputHelp({error:!0}));const n=t||{},r=n.exitCode||1,i=n.code||"commander.error";this._exit(r,i,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in _.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()}`,_.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){const e=new ze(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),p=this.options.find(h=>h.negate&&u===h.attributeName()),o=this.options.find(h=>!h.negate&&u===h.attributeName());return p&&(p.presetArg===void 0&&c===!1||p.presetArg!==void 0&&c===p.presetArg)?p:o||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"),i=`error: ${r(e)} cannot be used with ${r(t)}`;this.error(i,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let r=[],i=this;do{const a=i.createHelp().visibleOptions(i).filter(u=>u.long).map(u=>u.long);r=r.concat(a),i=i.parent}while(i&&!i._enablePositionalOptions);t=ie(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",i=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${t} argument${n} but got ${e.length}.`;this.error(i,{code:"commander.excessArguments"})}unknownCommand(){const e=this.args[0];let t="";if(this._showSuggestionAfterError){const r=[];this.createHelp().visibleCommands(this).forEach(i=>{r.push(i.name()),i.alias()&&r.push(i.alias())}),t=ie(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
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=>Be(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=w.basename(e,w.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(i=>i.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(i=>i.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=_.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
22
  Expecting one of '${n.join("', '")}'`);const r=`${e}Help`;return this.on(r,i=>{let a;typeof t=="function"?a=t({error:i.error,command:i.command}):a=t,a&&i.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(S,"Command"),S);function oe(s){return s.map(e=>{if(!e.startsWith("--inspect"))return e;let t,n="127.0.0.1",r="9229",i;return(i=e.match(/^(--inspect(-brk)?)$/))!==null?t=i[1]:(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=i[1],/^\d+$/.test(i[3])?r=i[3]:n=i[3]):(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=i[1],n=i[3],r=i[4]),t&&r!=="0"?`${t}=${n}:${parseInt(r)+1}`:e})}l(oe,"incrementNodeInspectorPort"),te.Command=Qe;const{Argument:ae}=R,{Command:W}=te,{CommanderError:Ye,InvalidArgumentError:ce}=T,{Help:Ze}=L,{Option:le}=V;b.program=new W,b.createCommand=s=>new W(s),b.createOption=(s,e)=>new le(s,e),b.createArgument=(s,e)=>new ae(s,e),b.Command=W,b.Option=le,b.Argument=ae,b.Help=Ze,b.CommanderError=Ye,b.InvalidArgumentError=ce,b.InvalidOptionArgumentError=ce;const{program:Tn,createCommand:vn,createArgument:jn,createOption:kn,CommanderError:xn,InvalidArgumentError:Pn,InvalidOptionArgumentError:Hn,Command:Xe,Argument:Rn,Option:In,Help:Nn}=b,et=/"(?:_|\\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*:/,tt=/"(?: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*:/,nt=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function rt(s,e){if(s==="__proto__"||s==="constructor"&&e&&typeof e=="object"&&"prototype"in e){st(s);return}return e}l(rt,"jsonParseTransform");function st(s){console.warn(`[destr] Dropping "${s}" key to prevent prototype pollution.`)}l(st,"warnKeyDropped");function it(s,e={}){if(typeof s!="string")return s;const t=s.trim();if(s[0]==='"'&&s.endsWith('"')&&!s.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(!nt.test(s)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return s}try{if(et.test(s)||tt.test(s)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(s,rt)}return JSON.parse(s)}catch(n){if(e.strict)throw n;return s}}l(it,"destr");const ot=/#/g,at=/&/g,ct=/\//g,lt=/=/g,G=/\+/g,ut=/%5e/gi,ht=/%60/gi,pt=/%7c/gi,dt=/%20/gi;function ft(s){return encodeURI(""+s).replace(pt,"|")}l(ft,"encode");function J(s){return ft(typeof s=="string"?s:JSON.stringify(s)).replace(G,"%2B").replace(dt,"+").replace(ot,"%23").replace(at,"%26").replace(ht,"`").replace(ut,"^").replace(ct,"%2F")}l(J,"encodeQueryValue");function B(s){return J(s).replace(lt,"%3D")}l(B,"encodeQueryKey");function ue(s=""){try{return decodeURIComponent(""+s)}catch{return""+s}}l(ue,"decode");function mt(s){return ue(s.replace(G," "))}l(mt,"decodeQueryKey");function gt(s){return ue(s.replace(G," "))}l(gt,"decodeQueryValue");function _t(s=""){const e={};s[0]==="?"&&(s=s.slice(1));for(const t of s.split("&")){const n=t.match(/([^=]+)=?(.*)/)||[];if(n.length<2)continue;const r=mt(n[1]);if(r==="__proto__"||r==="constructor")continue;const i=gt(n[2]||"");e[r]===void 0?e[r]=i:Array.isArray(e[r])?e[r].push(i):e[r]=[e[r],i]}return e}l(_t,"parseQuery");function yt(s,e){return(typeof e=="number"||typeof e=="boolean")&&(e=String(e)),e?Array.isArray(e)?e.map(t=>`${B(s)}=${J(t)}`).join("&"):`${B(s)}=${J(e)}`:B(s)}l(yt,"encodeQueryItem");function Ot(s){return Object.keys(s).filter(e=>s[e]!==void 0).map(e=>yt(e,s[e])).filter(Boolean).join("&")}l(Ot,"stringifyQuery");const bt=/^[\s\w\0+.-]{2,}:([/\\]{1,2})/,Ct=/^[\s\w\0+.-]{2,}:([/\\]{2})?/,wt=/^([/\\]\s*){2,}[^/\\]/,At=/^\.?\//;function he(s,e={}){return typeof e=="boolean"&&(e={acceptRelative:e}),e.strict?bt.test(s):Ct.test(s)||(e.acceptRelative?wt.test(s):!1)}l(he,"hasProtocol");function Et(s="",e){return s.endsWith("/")}l(Et,"hasTrailingSlash");function $t(s="",e){return(Et(s)?s.slice(0,-1):s)||"/"}l($t,"withoutTrailingSlash");function St(s="",e){return s.endsWith("/")?s:s+"/"}l(St,"withTrailingSlash");function Tt(s,e){if(jt(e)||he(s))return s;const t=$t(e);return s.startsWith(t)?s:xt(t,s)}l(Tt,"withBase");function vt(s,e){const t=Pt(s),n={..._t(t.search),...e};return t.search=Ot(n),Ht(t)}l(vt,"withQuery");function jt(s){return!s||s==="/"}l(jt,"isEmptyURL");function kt(s){return s&&s!=="/"}l(kt,"isNonEmptyURL");function xt(s,...e){let t=s||"";for(const n of e.filter(r=>kt(r)))if(t){const r=n.replace(At,"");t=St(t)+r}else t=n;return t}l(xt,"joinURL");const pe=Symbol.for("ufo:protocolRelative");function Pt(s="",e){const t=s.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);if(t){const[,h,d=""]=t;return{protocol:h.toLowerCase(),pathname:d,href:h+d,auth:"",host:"",search:"",hash:""}}if(!he(s,{acceptRelative:!0}))return de(s);const[,n="",r,i=""]=s.replace(/\\/g,"/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/)||[],[,a="",u=""]=i.match(/([^#/?]*)(.*)?/)||[],{pathname:c,search:p,hash:o}=de(u.replace(/\/(?=[A-Za-z]:)/,""));return{protocol:n.toLowerCase(),auth:r?r.slice(0,Math.max(0,r.length-1)):"",host:a,pathname:c,search:p,hash:o,[pe]:!n}}l(Pt,"parseURL");function de(s=""){const[e="",t="",n=""]=(s.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:e,search:t,hash:n}}l(de,"parsePath");function Ht(s){const e=s.pathname||"",t=s.search?(s.search.startsWith("?")?"":"?")+s.search:"",n=s.hash||"",r=s.auth?s.auth+"@":"",i=s.host||"";return(s.protocol||s[pe]?(s.protocol||"")+"//":"")+r+i+e+t+n}l(Ht,"stringifyParsedURL");const X=class X extends Error{constructor(e,t){super(e,t),this.name="FetchError",t?.cause&&!this.cause&&(this.cause=t.cause)}};l(X,"FetchError");let K=X;function Rt(s){const e=s.error?.message||s.error?.toString()||"",t=s.request?.method||s.options?.method||"GET",n=s.request?.url||String(s.request)||"/",r=`[${t}] ${JSON.stringify(n)}`,i=s.response?`${s.response.status} ${s.response.statusText}`:"<no response>",a=`${r}: ${i}${e?` ${e}`:""}`,u=new K(a,s.error?{cause:s.error}:void 0);for(const c of["request","options","response"])Object.defineProperty(u,c,{get(){return s[c]}});for(const[c,p]of[["data","_data"],["status","status"],["statusCode","status"],["statusText","statusText"],["statusMessage","statusText"]])Object.defineProperty(u,c,{get(){return s.response&&s.response[p]}});return u}l(Rt,"createFetchError");const It=new Set(Object.freeze(["PATCH","POST","PUT","DELETE"]));function fe(s="GET"){return It.has(s.toUpperCase())}l(fe,"isPayloadMethod");function Nt(s){if(s===void 0)return!1;const e=typeof s;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(s)?!0:s.buffer?!1:s.constructor&&s.constructor.name==="Object"||typeof s.toJSON=="function"}l(Nt,"isJSONSerializable");const Vt=new Set(["image/svg","application/xml","application/xhtml","application/html"]),Ft=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function Dt(s=""){if(!s)return"json";const e=s.split(";").shift()||"";return Ft.test(e)?"json":Vt.has(e)||e.startsWith("text/")?"text":"blob"}l(Dt,"detectResponseType");function Lt(s,e,t=globalThis.Headers){const n={...e,...s};if(e?.params&&s?.params&&(n.params={...e?.params,...s?.params}),e?.query&&s?.query&&(n.query={...e?.query,...s?.query}),e?.headers&&s?.headers){n.headers=new t(e?.headers||{});for(const[r,i]of new t(s?.headers||{}))n.headers.set(r,i)}return n}l(Lt,"mergeFetchOptions");const qt=new Set([408,409,425,429,500,502,503,504]),Ut=new Set([101,204,205,304]);function me(s={}){const{fetch:e=globalThis.fetch,Headers:t=globalThis.Headers,AbortController:n=globalThis.AbortController}=s;async function r(u){const c=u.error&&u.error.name==="AbortError"&&!u.options.timeout||!1;if(u.options.retry!==!1&&!c){let o;typeof u.options.retry=="number"?o=u.options.retry:o=fe(u.options.method)?0:1;const h=u.response&&u.response.status||500;if(o>0&&(Array.isArray(u.options.retryStatusCodes)?u.options.retryStatusCodes.includes(h):qt.has(h))){const d=u.options.retryDelay||0;return d>0&&await new Promise(O=>setTimeout(O,d)),i(u.request,{...u.options,retry:o-1})}}const p=Rt(u);throw Error.captureStackTrace&&Error.captureStackTrace(p,i),p}l(r,"onError");const i=l(async function(c,p={}){const o={request:c,options:Lt(p,s.defaults,t),response:void 0,error:void 0};o.options.method=o.options.method?.toUpperCase(),o.options.onRequest&&await o.options.onRequest(o),typeof o.request=="string"&&(o.options.baseURL&&(o.request=Tt(o.request,o.options.baseURL)),(o.options.query||o.options.params)&&(o.request=vt(o.request,{...o.options.params,...o.options.query}))),o.options.body&&fe(o.options.method)&&(Nt(o.options.body)?(o.options.body=typeof o.options.body=="string"?o.options.body:JSON.stringify(o.options.body),o.options.headers=new t(o.options.headers||{}),o.options.headers.has("content-type")||o.options.headers.set("content-type","application/json"),o.options.headers.has("accept")||o.options.headers.set("accept","application/json")):("pipeTo"in o.options.body&&typeof o.options.body.pipeTo=="function"||typeof o.options.body.pipe=="function")&&("duplex"in o.options||(o.options.duplex="half")));let h;if(!o.options.signal&&o.options.timeout){const O=new n;h=setTimeout(()=>O.abort(),o.options.timeout),o.options.signal=O.signal}try{o.response=await e(o.request,o.options)}catch(O){return o.error=O,o.options.onRequestError&&await o.options.onRequestError(o),await r(o)}finally{h&&clearTimeout(h)}if(o.response.body&&!Ut.has(o.response.status)&&o.options.method!=="HEAD"){const O=(o.options.parseResponse?"json":o.options.responseType)||Dt(o.response.headers.get("content-type")||"");switch(O){case"json":{const f=await o.response.text(),C=o.options.parseResponse||it;o.response._data=C(f);break}case"stream":{o.response._data=o.response.body;break}default:o.response._data=await o.response[O]()}}return o.options.onResponse&&await o.options.onResponse(o),!o.options.ignoreResponseError&&o.response.status>=400&&o.response.status<600?(o.options.onResponseError&&await o.options.onResponseError(o),await r(o)):o.response},"$fetchRaw2"),a=l(async function(c,p){return(await i(c,p))._data},"$fetch2");return a.raw=i,a.native=(...u)=>e(...u),a.create=(u={})=>me({...s,defaults:{...s.defaults,...u}}),a}l(me,"createFetch");const z=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")}(),Mt=z.fetch||(()=>Promise.reject(new Error("[ofetch] global.fetch is not supported!"))),Wt=z.Headers,Gt=z.AbortController,F=me({fetch:Mt,Headers:Wt,AbortController:Gt}),Jt={apiRoot:process.env.FRONTSTACK_CLI_API_ROOT||(process.env.FRONTSTACK_CLI_DEV_MODE=="1"?"https://backend.frontstack.test/":"https://backend.frontlab.dev/")},I=Jt.apiRoot,Bt=`${I}login`,Kt=`${I}api/fetch-api/spec.yaml`,ge=3008,_e=`http://localhost:${ge}`,ye=`${Bt}?redirectUrl=${_e}/callback`,zt=".frontstack-local/",A=g.join(process.cwd(),zt),Q="api_session.jwt",Oe="project.json",N=l(()=>{const s=l(()=>{console.info("Not auth.login implemented yet")},"login"),e=l(async()=>{try{return a(),0}catch(h){console.log(h)}},"logout"),t=l(async(h=void 0)=>{try{return process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await F(`${I}profile`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${h||r()}`}})}catch(d){return console.log(d),1}},"getProfile"),n=l(async(h=void 0)=>{try{const d=c();if(d==null)throw new Error(`You have no project selected
23
+ `)}),this}_outputHelpIfRequested(e){const t=this._getHelpOption();t&&e.find(r=>t.is(r))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}},l(S,"Command"),S);function oe(s){return s.map(e=>{if(!e.startsWith("--inspect"))return e;let t,n="127.0.0.1",r="9229",i;return(i=e.match(/^(--inspect(-brk)?)$/))!==null?t=i[1]:(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=i[1],/^\d+$/.test(i[3])?r=i[3]:n=i[3]):(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=i[1],n=i[3],r=i[4]),t&&r!=="0"?`${t}=${n}:${parseInt(r)+1}`:e})}l(oe,"incrementNodeInspectorPort"),te.Command=Qe;const{Argument:ae}=R,{Command:W}=te,{CommanderError:Ye,InvalidArgumentError:ce}=T,{Help:Ze}=L,{Option:le}=V;b.program=new W,b.createCommand=s=>new W(s),b.createOption=(s,e)=>new le(s,e),b.createArgument=(s,e)=>new ae(s,e),b.Command=W,b.Option=le,b.Argument=ae,b.Help=Ze,b.CommanderError=Ye,b.InvalidArgumentError=ce,b.InvalidOptionArgumentError=ce;const{program:Tn,createCommand:vn,createArgument:jn,createOption:kn,CommanderError:xn,InvalidArgumentError:Pn,InvalidOptionArgumentError:Hn,Command:Xe,Argument:Rn,Option:In,Help:Nn}=b,et=/"(?:_|\\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*:/,tt=/"(?: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*:/,nt=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function rt(s,e){if(s==="__proto__"||s==="constructor"&&e&&typeof e=="object"&&"prototype"in e){st(s);return}return e}l(rt,"jsonParseTransform");function st(s){console.warn(`[destr] Dropping "${s}" key to prevent prototype pollution.`)}l(st,"warnKeyDropped");function it(s,e={}){if(typeof s!="string")return s;const t=s.trim();if(s[0]==='"'&&s.endsWith('"')&&!s.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(!nt.test(s)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return s}try{if(et.test(s)||tt.test(s)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(s,rt)}return JSON.parse(s)}catch(n){if(e.strict)throw n;return s}}l(it,"destr");const ot=/#/g,at=/&/g,ct=/\//g,lt=/=/g,G=/\+/g,ut=/%5e/gi,ht=/%60/gi,pt=/%7c/gi,dt=/%20/gi;function ft(s){return encodeURI(""+s).replace(pt,"|")}l(ft,"encode");function J(s){return ft(typeof s=="string"?s:JSON.stringify(s)).replace(G,"%2B").replace(dt,"+").replace(ot,"%23").replace(at,"%26").replace(ht,"`").replace(ut,"^").replace(ct,"%2F")}l(J,"encodeQueryValue");function B(s){return J(s).replace(lt,"%3D")}l(B,"encodeQueryKey");function ue(s=""){try{return decodeURIComponent(""+s)}catch{return""+s}}l(ue,"decode");function mt(s){return ue(s.replace(G," "))}l(mt,"decodeQueryKey");function gt(s){return ue(s.replace(G," "))}l(gt,"decodeQueryValue");function _t(s=""){const e={};s[0]==="?"&&(s=s.slice(1));for(const t of s.split("&")){const n=t.match(/([^=]+)=?(.*)/)||[];if(n.length<2)continue;const r=mt(n[1]);if(r==="__proto__"||r==="constructor")continue;const i=gt(n[2]||"");e[r]===void 0?e[r]=i:Array.isArray(e[r])?e[r].push(i):e[r]=[e[r],i]}return e}l(_t,"parseQuery");function yt(s,e){return(typeof e=="number"||typeof e=="boolean")&&(e=String(e)),e?Array.isArray(e)?e.map(t=>`${B(s)}=${J(t)}`).join("&"):`${B(s)}=${J(e)}`:B(s)}l(yt,"encodeQueryItem");function Ot(s){return Object.keys(s).filter(e=>s[e]!==void 0).map(e=>yt(e,s[e])).filter(Boolean).join("&")}l(Ot,"stringifyQuery");const bt=/^[\s\w\0+.-]{2,}:([/\\]{1,2})/,Ct=/^[\s\w\0+.-]{2,}:([/\\]{2})?/,wt=/^([/\\]\s*){2,}[^/\\]/,At=/^\.?\//;function he(s,e={}){return typeof e=="boolean"&&(e={acceptRelative:e}),e.strict?bt.test(s):Ct.test(s)||(e.acceptRelative?wt.test(s):!1)}l(he,"hasProtocol");function Et(s="",e){return s.endsWith("/")}l(Et,"hasTrailingSlash");function $t(s="",e){return(Et(s)?s.slice(0,-1):s)||"/"}l($t,"withoutTrailingSlash");function St(s="",e){return s.endsWith("/")?s:s+"/"}l(St,"withTrailingSlash");function Tt(s,e){if(jt(e)||he(s))return s;const t=$t(e);return s.startsWith(t)?s:xt(t,s)}l(Tt,"withBase");function vt(s,e){const t=Pt(s),n={..._t(t.search),...e};return t.search=Ot(n),Ht(t)}l(vt,"withQuery");function jt(s){return!s||s==="/"}l(jt,"isEmptyURL");function kt(s){return s&&s!=="/"}l(kt,"isNonEmptyURL");function xt(s,...e){let t=s||"";for(const n of e.filter(r=>kt(r)))if(t){const r=n.replace(At,"");t=St(t)+r}else t=n;return t}l(xt,"joinURL");const pe=Symbol.for("ufo:protocolRelative");function Pt(s="",e){const t=s.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);if(t){const[,h,d=""]=t;return{protocol:h.toLowerCase(),pathname:d,href:h+d,auth:"",host:"",search:"",hash:""}}if(!he(s,{acceptRelative:!0}))return de(s);const[,n="",r,i=""]=s.replace(/\\/g,"/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/)||[],[,a="",u=""]=i.match(/([^#/?]*)(.*)?/)||[],{pathname:c,search:p,hash:o}=de(u.replace(/\/(?=[A-Za-z]:)/,""));return{protocol:n.toLowerCase(),auth:r?r.slice(0,Math.max(0,r.length-1)):"",host:a,pathname:c,search:p,hash:o,[pe]:!n}}l(Pt,"parseURL");function de(s=""){const[e="",t="",n=""]=(s.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:e,search:t,hash:n}}l(de,"parsePath");function Ht(s){const e=s.pathname||"",t=s.search?(s.search.startsWith("?")?"":"?")+s.search:"",n=s.hash||"",r=s.auth?s.auth+"@":"",i=s.host||"";return(s.protocol||s[pe]?(s.protocol||"")+"//":"")+r+i+e+t+n}l(Ht,"stringifyParsedURL");const X=class X extends Error{constructor(e,t){super(e,t),this.name="FetchError",t?.cause&&!this.cause&&(this.cause=t.cause)}};l(X,"FetchError");let K=X;function Rt(s){const e=s.error?.message||s.error?.toString()||"",t=s.request?.method||s.options?.method||"GET",n=s.request?.url||String(s.request)||"/",r=`[${t}] ${JSON.stringify(n)}`,i=s.response?`${s.response.status} ${s.response.statusText}`:"<no response>",a=`${r}: ${i}${e?` ${e}`:""}`,u=new K(a,s.error?{cause:s.error}:void 0);for(const c of["request","options","response"])Object.defineProperty(u,c,{get(){return s[c]}});for(const[c,p]of[["data","_data"],["status","status"],["statusCode","status"],["statusText","statusText"],["statusMessage","statusText"]])Object.defineProperty(u,c,{get(){return s.response&&s.response[p]}});return u}l(Rt,"createFetchError");const It=new Set(Object.freeze(["PATCH","POST","PUT","DELETE"]));function fe(s="GET"){return It.has(s.toUpperCase())}l(fe,"isPayloadMethod");function Nt(s){if(s===void 0)return!1;const e=typeof s;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(s)?!0:s.buffer?!1:s.constructor&&s.constructor.name==="Object"||typeof s.toJSON=="function"}l(Nt,"isJSONSerializable");const Vt=new Set(["image/svg","application/xml","application/xhtml","application/html"]),Ft=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function Dt(s=""){if(!s)return"json";const e=s.split(";").shift()||"";return Ft.test(e)?"json":Vt.has(e)||e.startsWith("text/")?"text":"blob"}l(Dt,"detectResponseType");function Lt(s,e,t=globalThis.Headers){const n={...e,...s};if(e?.params&&s?.params&&(n.params={...e?.params,...s?.params}),e?.query&&s?.query&&(n.query={...e?.query,...s?.query}),e?.headers&&s?.headers){n.headers=new t(e?.headers||{});for(const[r,i]of new t(s?.headers||{}))n.headers.set(r,i)}return n}l(Lt,"mergeFetchOptions");const qt=new Set([408,409,425,429,500,502,503,504]),Ut=new Set([101,204,205,304]);function me(s={}){const{fetch:e=globalThis.fetch,Headers:t=globalThis.Headers,AbortController:n=globalThis.AbortController}=s;async function r(u){const c=u.error&&u.error.name==="AbortError"&&!u.options.timeout||!1;if(u.options.retry!==!1&&!c){let o;typeof u.options.retry=="number"?o=u.options.retry:o=fe(u.options.method)?0:1;const h=u.response&&u.response.status||500;if(o>0&&(Array.isArray(u.options.retryStatusCodes)?u.options.retryStatusCodes.includes(h):qt.has(h))){const d=u.options.retryDelay||0;return d>0&&await new Promise(O=>setTimeout(O,d)),i(u.request,{...u.options,retry:o-1})}}const p=Rt(u);throw Error.captureStackTrace&&Error.captureStackTrace(p,i),p}l(r,"onError");const i=l(async function(c,p={}){const o={request:c,options:Lt(p,s.defaults,t),response:void 0,error:void 0};o.options.method=o.options.method?.toUpperCase(),o.options.onRequest&&await o.options.onRequest(o),typeof o.request=="string"&&(o.options.baseURL&&(o.request=Tt(o.request,o.options.baseURL)),(o.options.query||o.options.params)&&(o.request=vt(o.request,{...o.options.params,...o.options.query}))),o.options.body&&fe(o.options.method)&&(Nt(o.options.body)?(o.options.body=typeof o.options.body=="string"?o.options.body:JSON.stringify(o.options.body),o.options.headers=new t(o.options.headers||{}),o.options.headers.has("content-type")||o.options.headers.set("content-type","application/json"),o.options.headers.has("accept")||o.options.headers.set("accept","application/json")):("pipeTo"in o.options.body&&typeof o.options.body.pipeTo=="function"||typeof o.options.body.pipe=="function")&&("duplex"in o.options||(o.options.duplex="half")));let h;if(!o.options.signal&&o.options.timeout){const O=new n;h=setTimeout(()=>O.abort(),o.options.timeout),o.options.signal=O.signal}try{o.response=await e(o.request,o.options)}catch(O){return o.error=O,o.options.onRequestError&&await o.options.onRequestError(o),await r(o)}finally{h&&clearTimeout(h)}if(o.response.body&&!Ut.has(o.response.status)&&o.options.method!=="HEAD"){const O=(o.options.parseResponse?"json":o.options.responseType)||Dt(o.response.headers.get("content-type")||"");switch(O){case"json":{const f=await o.response.text(),C=o.options.parseResponse||it;o.response._data=C(f);break}case"stream":{o.response._data=o.response.body;break}default:o.response._data=await o.response[O]()}}return o.options.onResponse&&await o.options.onResponse(o),!o.options.ignoreResponseError&&o.response.status>=400&&o.response.status<600?(o.options.onResponseError&&await o.options.onResponseError(o),await r(o)):o.response},"$fetchRaw2"),a=l(async function(c,p){return(await i(c,p))._data},"$fetch2");return a.raw=i,a.native=(...u)=>e(...u),a.create=(u={})=>me({...s,defaults:{...s.defaults,...u}}),a}l(me,"createFetch");const z=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")}(),Mt=z.fetch||(()=>Promise.reject(new Error("[ofetch] global.fetch is not supported!"))),Wt=z.Headers,Gt=z.AbortController,F=me({fetch:Mt,Headers:Wt,AbortController:Gt}),Jt={apiRoot:process.env.FRONTSTACK_CLI_API_ROOT||(process.env.FRONTSTACK_CLI_DEV_MODE=="1"?"https://backend.frontstack.test/":"https://backend.frontstack.dev/")},I=Jt.apiRoot,Bt=`${I}login`,Kt=`${I}api/fetch-api/spec.yaml`,ge=3008,_e=`http://localhost:${ge}`,ye=`${Bt}?redirectUrl=${_e}/callback`,zt=".frontstack-local/",A=g.join(process.cwd(),zt),Q="api_session.jwt",Oe="project.json",N=l(()=>{const s=l(()=>{console.info("Not auth.login implemented yet")},"login"),e=l(async()=>{try{return a(),0}catch(h){console.log(h)}},"logout"),t=l(async(h=void 0)=>{try{return process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await F(`${I}profile`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${h||r()}`}})}catch(d){return console.log(d),1}},"getProfile"),n=l(async(h=void 0)=>{try{const d=c();if(d==null)throw new Error(`You have no project selected
24
24
  Run ${m.hex("#7c3bed")("frontstack project")} to select a Frontstack project`);return process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await F(Kt,{method:"GET",headers:{"Content-Type":"application/yaml",Authorization:`Bearer ${h||r()}`,"FS-Project":d},parseResponse:l(f=>{try{return Te.load(f)}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 h=g.join(A,Q);return y.existsSync(h)?y.readFileSync(h,"utf8"):null},"getToken"),i=l(h=>(y.existsSync(A)||y.mkdirSync(A),y.writeFileSync(g.join(A,Q),h),0),"writeToken"),a=l(()=>{const h=g.join(A,Q);y.existsSync(h)&&y.unlinkSync(h)},"deleteToken"),u=l(async()=>(process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await F(`${I}api/project`,{method:"GET",headers:{"Content-Type":"application/yaml",Authorization:`Bearer ${r()}`},parseResponse:l(h=>JSON.parse(h),"parseResponse")})),"getProjects"),c=l(()=>{const h=g.join(A,Oe);if(!y.existsSync(h))return null;try{return JSON.parse(y.readFileSync(h,"utf8")).projectId}catch{console.error("[Error] Corrupt project file - please run 'frontstack project'")}},"getProjectId");return{login:s,logout:e,getProfile:t,getFetchApiSpec:n,getToken:r,writeToken:i,deleteToken:a,getProjects:u,getProject:l(async()=>{try{const h=c();return h===void 0?void 0:(process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await F(`${I}api/project/${h}`,{method:"GET",headers:{"Content-Type":"application/yaml",Authorization:`Bearer ${r()}`},parseResponse:l(d=>JSON.parse(d),"parseResponse")}))}catch(h){return{error:h.message}}},"getProject"),getProjectId:c,writeProject:l(h=>(y.existsSync(A)||y.mkdirSync(A),y.writeFileSync(g.join(A,Oe),JSON.stringify({projectId:h})),0),"writeProject")}},"auth"),{writeToken:Qt}=N(),Yt=l(async(s,e)=>{const t=new Set,n=ve.createServer((r,i)=>{const a=_e;if(r.url===void 0)return;const c=new URL(r.url,a).searchParams.get("token");c&&(i.writeHead(200,{"Content-Type":"text/html"}),i.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;">&copy; 2024 frontstack</p></div></div></html>'),i.on("finish",async()=>{for(const o of t)o.destroy();Qt(c)!==0&&(console.error("Login failed."),n.close(),process.exit(1)),console.log(`${m.hex("#008000")("[SUCCESS]")} Login successful`),n.close(),process.exit(0)}))}).listen(s,()=>{console.log(`Please continue login in your browser at ${m.hex("#7c3bed")(e)}`)});n.on("connection",r=>{t.add(r),r.on("close",()=>t.delete(r))}),setTimeout(()=>{n.close()},6e4)},"login$1"),Zt=l(async()=>{await je(ye),await Yt(ge,ye)},"login"),Xt=N(),en=l(async s=>{await Xt.logout()!==0&&(console.error("Logout failed."),process.exit(1)),console.log("Logout successful."),process.exit(0)},"logout"),{getFetchApiSpec:tn}=N();E.registerHelper("eq",function(s,e,t){return s===e}),E.registerHelper("uc",function(s){return s.toUpperCase()}),E.registerHelper("contains",function(s,e,t){return s===void 0?!1:s.includes(e)}),E.registerHelper("endsWith",function(s,e,t){return s===void 0?!1:s.endsWith(e)}),E.registerHelper("blockNameFromOperationId",function(s){return s.replace("get","").replace("Block","")});const Y=l((s,e=!1)=>s.$ref?`components['schemas']['${s.$ref.split("/").pop()}']`:s.type==="array"?`Array<${Y(s.items,!0)}>`:s.type==="object"?`{ ${Object.keys(s.properties).map(n=>`${n}: ${Y(s.properties[n])}`).join("; ")} }`:s.type,"getSchemaType");E.registerHelper("getSchemaType",s=>Y(s));var nn=l(async()=>{const s=g.dirname(new URL(import.meta.url).pathname),e=g.join(s,"src/commands/generate/templates"),t=g.join(e,"types.js.hbs"),n=y.readFileSync(t,"utf8"),r=E.compile(n),i=g.join(e,"client.js.hbs"),a=y.readFileSync(i,"utf8"),u=E.compile(a),c=g.join(e,"query.js.hbs"),p=y.readFileSync(c,"utf8");let o;if(o=await tn(),o.error)throw new Error(`Issue fetching API specification. Check more information below.
25
25
  `+o.error);let h="";try{h=await ke(o)}catch(f){throw new Error(`Invalid API Specification: ${f.message}`)}const d=r({paths:o.paths,components:o.components}),O=u({paths:o.paths,servers:o.servers});return{_schemaTypes:h,_types:d,_client:O,_query:p}},"generate");const rn=l(async s=>{const e=s.verbose||!1;let t,n,r,i;try{e&&console.log("Generating Javascript client"),{_schemaTypes:t,_types:n,_client:r,_query:i}=await nn()}catch(h){console.error(`${m.hex("#b90404")("[ERROR]")} frontstack generate`),console.error(`${m.hex("#b90404")("[ERROR]")} Failed to generate Javascript client`),e?console.error(`${m.hex("#b90404")("[ERROR]")} ${h.message}`):(console.error("Are you..."),console.error(` * logged in using the ${m.hex("#7c3bed")("frontstack login")} command?`),console.error(" * connected to the internet?"),console.error(`Alternatively, run ${m.hex("#7c3bed")("frontstack generate -v")} for additional output.`));return}let a=s.output||".frontstack";process.stdout.write("Generating Javascript client"),a.startsWith("/")||(a=g.join(process.cwd(),a)),a.endsWith("/")||(a+="/");const u=g.join(a,"fetch-api.d.ts"),c=g.join(a,"generated-types.d.ts"),p=g.join(a,"generated-client.ts"),o=g.join(a,"query-types.ts");e&&(console.log(`
26
26
  Schema types path: ${m.dim(u)}`),console.log(`Types path: ${m.dim(c)}`),console.log(`Client path: ${m.dim(p)}`),console.log(`Target directory: ${m.dim(a)}`)),y.mkdirSync(a,{recursive:!0}),y.writeFileSync(g.join(u),t),y.writeFileSync(g.join(c),n),y.writeFileSync(g.join(p),r),y.writeFileSync(g.join(o),i),e?console.log(`Javascript client generated
package/dist/version CHANGED
@@ -1 +1 @@
1
- 0.0.0-canary-20241004210640
1
+ 0.0.0-canary-20241007160625
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontstackdev/cli",
3
- "version": "0.0.0-canary-20241004210640",
3
+ "version": "0.0.0-canary-20241007160625",
4
4
  "description": "Frontstack CLI for managing projects",
5
5
  "type": "module",
6
6
  "module": "dist/frontstack.mjs",