@napps/cli 0.0.6 → 0.0.7
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 +18 -18
- package/bin/run.js +5 -5
- package/dist/index.js +2 -2
- package/package.json +55 -55
- package/bin/cloudflared.exe +0 -0
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
Napps cli
|
|
2
|
-
|
|
3
|
-
Auth and deploy your templates
|
|
4
|
-
|
|
5
|
-
## Install our global cli
|
|
6
|
-
|
|
7
|
-
> **Compatibility Note:**
|
|
8
|
-
> Requires [Node.js](https://nodejs.org/en/) version 20.19+, 22.12+.
|
|
9
|
-
|
|
10
|
-
With NPM:
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
npm install --global @napps/cli@latest
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
napps help
|
|
18
|
-
```
|
|
1
|
+
Napps cli
|
|
2
|
+
|
|
3
|
+
Auth and deploy your templates
|
|
4
|
+
|
|
5
|
+
## Install our global cli
|
|
6
|
+
|
|
7
|
+
> **Compatibility Note:**
|
|
8
|
+
> Requires [Node.js](https://nodejs.org/en/) version 20.19+, 22.12+.
|
|
9
|
+
|
|
10
|
+
With NPM:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install --global @napps/cli@latest
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
napps help
|
|
18
|
+
```
|
package/bin/run.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
process.removeAllListeners('warning');
|
|
4
|
-
|
|
5
|
-
import('../dist/index.js');
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
process.removeAllListeners('warning');
|
|
4
|
+
|
|
5
|
+
import('../dist/index.js');
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createRequire as e}from"node:module";import{program as t}from"commander";import n from"path";import*as r from"node:fs";import i,{chmodSync as a,createWriteStream as o,existsSync as s,mkdirSync as c,renameSync as l,unlinkSync as u}from"node:fs";import*as d from"node:path";import f,{basename as p,dirname as m,join as h}from"node:path";import*as g from"node:os";import{exec as _,execFileSync as v,execSync as y}from"child_process";import b,{promisify as x}from"util";import S from"node:http";import{spawn as C}from"node:child_process";import w from"chokidar";import{createSession as ee}from"better-sse";import{fileURLToPath as te}from"url";import{Writable as ne,pipeline as re}from"stream";import ie from"qrcode";import{WebSocketServer as ae}from"ws";var oe=Object.create,se=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,le=Object.getOwnPropertyNames,ue=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty,T=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),fe=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=le(t),a=0,o=i.length,s;a<o;a++)s=i[a],!de.call(e,s)&&s!==n&&se(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=ce(t,s))||r.enumerable});return e},E=(e,t,n)=>(n=e==null?{}:oe(ue(e)),fe(t||!e||!e.__esModule?se(n,`default`,{value:e,enumerable:!0}):n,e)),D=e(import.meta.url),O=class extends Error{constructor(e,t){super(e),this.response=t}};const pe=process.cwd(),k=`
|
|
1
|
+
import{createRequire as e}from"node:module";import{program as t}from"commander";import n from"path";import*as r from"node:fs";import i,{chmodSync as a,createWriteStream as o,existsSync as s,mkdirSync as c,renameSync as l,unlinkSync as u}from"node:fs";import*as d from"node:path";import f,{basename as p,dirname as m,join as h}from"node:path";import*as g from"node:os";import{exec as _,execFileSync as v,execSync as y}from"child_process";import b,{promisify as x}from"util";import S from"node:http";import{spawn as C}from"node:child_process";import w from"chokidar";import{createSession as ee}from"better-sse";import{fileURLToPath as te}from"url";import{Writable as ne,pipeline as re}from"stream";import ie from"qrcode";import{WebSocketServer as ae}from"ws";var oe=Object.create,se=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,le=Object.getOwnPropertyNames,ue=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty,T=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),fe=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=le(t),a=0,o=i.length,s;a<o;a++)s=i[a],!de.call(e,s)&&s!==n&&se(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=ce(t,s))||r.enumerable});return e},E=(e,t,n)=>(n=e==null?{}:oe(ue(e)),fe(t||!e||!e.__esModule?se(n,`default`,{value:e,enumerable:!0}):n,e)),D=e(import.meta.url),O=class extends Error{constructor(e,t){super(e),this.response=t}};const pe=process.cwd(),k=`http://localhost:10000`,A=n.join(pe,`/dist/component-extension.es.js`);async function me(e,t){let n={email:e,password:t};console.log(`Authenticating with master server at:`,k);try{let e=await fetch(`${k}/auth/admin`,{method:`POST`,body:JSON.stringify(n),credentials:`include`});if(!e.ok)throw new O(`Request failed`,e);return await e.json()}catch{console.error(`Error during authentication`);return}}async function he(e){try{let t=await fetch(`${k}/auth/admin/access`,{method:`GET`,credentials:`include`,headers:{Authorization:e}});if(!t.ok)throw new O(`Request failed`,t);return await t.json()}catch{console.error(`Error getting access token`);return}}async function ge(e){try{let t=await fetch(`${k}/admin/me`,{method:`GET`,credentials:`include`,headers:{Authorization:e}});if(!t.ok)throw new O(`Request failed`,t);return await t.json()}catch{console.error(`Error getting current user`);return}}async function _e(){if(!await K()){console.log(`You are not authenticated, please run auth command.`);return}let e=await G();if(!e){console.log(`You are not authenticated, please run auth command.`);return}return await ge(e)}var j=T(((e,t)=>{let{FORCE_COLOR:n,NODE_DISABLE_COLORS:r,TERM:i}=process.env,a={enabled:!r&&i!==`dumb`&&n!==`0`,reset:c(0,0),bold:c(1,22),dim:c(2,22),italic:c(3,23),underline:c(4,24),inverse:c(7,27),hidden:c(8,28),strikethrough:c(9,29),black:c(30,39),red:c(31,39),green:c(32,39),yellow:c(33,39),blue:c(34,39),magenta:c(35,39),cyan:c(36,39),white:c(37,39),gray:c(90,39),grey:c(90,39),bgBlack:c(40,49),bgRed:c(41,49),bgGreen:c(42,49),bgYellow:c(43,49),bgBlue:c(44,49),bgMagenta:c(45,49),bgCyan:c(46,49),bgWhite:c(47,49)};function o(e,t){let n=0,r,i=``,a=``;for(;n<e.length;n++)r=e[n],i+=r.open,a+=r.close,t.includes(r.close)&&(t=t.replace(r.rgx,r.close+r.open));return i+t+a}function s(e,t){let n={has:e,keys:t};return n.reset=a.reset.bind(n),n.bold=a.bold.bind(n),n.dim=a.dim.bind(n),n.italic=a.italic.bind(n),n.underline=a.underline.bind(n),n.inverse=a.inverse.bind(n),n.hidden=a.hidden.bind(n),n.strikethrough=a.strikethrough.bind(n),n.black=a.black.bind(n),n.red=a.red.bind(n),n.green=a.green.bind(n),n.yellow=a.yellow.bind(n),n.blue=a.blue.bind(n),n.magenta=a.magenta.bind(n),n.cyan=a.cyan.bind(n),n.white=a.white.bind(n),n.gray=a.gray.bind(n),n.grey=a.grey.bind(n),n.bgBlack=a.bgBlack.bind(n),n.bgRed=a.bgRed.bind(n),n.bgGreen=a.bgGreen.bind(n),n.bgYellow=a.bgYellow.bind(n),n.bgBlue=a.bgBlue.bind(n),n.bgMagenta=a.bgMagenta.bind(n),n.bgCyan=a.bgCyan.bind(n),n.bgWhite=a.bgWhite.bind(n),n}function c(e,t){let n={open:`\x1b[${e}m`,close:`\x1b[${t}m`,rgx:RegExp(`\\x1b\\[${t}m`,`g`)};return function(t){return this!==void 0&&this.has!==void 0?(this.has.includes(e)||(this.has.push(e),this.keys.push(n)),t===void 0?this:a.enabled?o(this.keys,t+``):t+``):t===void 0?s([e],[n]):a.enabled?o([n],t+``):t+``}}t.exports=a})),ve=T(((e,t)=>{t.exports=(e,t)=>{if(!(e.meta&&e.name!==`escape`)){if(e.ctrl){if(e.name===`a`)return`first`;if(e.name===`c`||e.name===`d`)return`abort`;if(e.name===`e`)return`last`;if(e.name===`g`)return`reset`}if(t){if(e.name===`j`)return`down`;if(e.name===`k`)return`up`}return e.name===`return`||e.name===`enter`?`submit`:e.name===`backspace`?`delete`:e.name===`delete`?`deleteForward`:e.name===`abort`?`abort`:e.name===`escape`?`exit`:e.name===`tab`?`next`:e.name===`pagedown`?`nextPage`:e.name===`pageup`?`prevPage`:e.name===`home`?`home`:e.name===`end`?`end`:e.name===`up`?`up`:e.name===`down`?`down`:e.name===`right`?`right`:e.name===`left`?`left`:!1}}})),M=T(((e,t)=>{t.exports=e=>{let t=[`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)`,`(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))`].join(`|`),n=new RegExp(t,`g`);return typeof e==`string`?e.replace(n,``):e}})),N=T(((e,t)=>{let n={to(e,t){return t?`[${t+1};${e+1}H`:`[${e+1}G`},move(e,t){let n=``;return e<0?n+=`[${-e}D`:e>0&&(n+=`[${e}C`),t<0?n+=`[${-t}A`:t>0&&(n+=`[${t}B`),n},up:(e=1)=>`[${e}A`,down:(e=1)=>`[${e}B`,forward:(e=1)=>`[${e}C`,backward:(e=1)=>`[${e}D`,nextLine:(e=1)=>`\x1B[E`.repeat(e),prevLine:(e=1)=>`\x1B[F`.repeat(e),left:`\x1B[G`,hide:`\x1B[?25l`,show:`\x1B[?25h`,save:`\x1B7`,restore:`\x1B8`};t.exports={cursor:n,scroll:{up:(e=1)=>`\x1B[S`.repeat(e),down:(e=1)=>`\x1B[T`.repeat(e)},erase:{screen:`\x1B[2J`,up:(e=1)=>`\x1B[1J`.repeat(e),down:(e=1)=>`\x1B[J`.repeat(e),line:`\x1B[2K`,lineEnd:`\x1B[K`,lineStart:`\x1B[1K`,lines(e){let t=``;for(let r=0;r<e;r++)t+=this.line+(r<e-1?n.up():``);return e&&(t+=n.left),t}},beep:`\x07`}})),ye=T(((e,t)=>{function n(e,t){var n=typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(!n){if(Array.isArray(e)||(n=r(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var i=0,a=function(){};return{s:a,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:a}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
2
2
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o=!0,s=!1,c;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,c=e},f:function(){try{!o&&n.return!=null&&n.return()}finally{if(s)throw c}}}}function r(e,t){if(e){if(typeof e==`string`)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}}function i(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}let a=M(),o=N(),s=o.erase,c=o.cursor,l=e=>[...a(e)].length;t.exports=function(e,t){if(!t)return s.line+c.to(0);let r=0;var i=n(e.split(/\r?\n/)),a;try{for(i.s();!(a=i.n()).done;){let e=a.value;r+=1+Math.floor(Math.max(l(e)-1,0)/t)}}catch(e){i.e(e)}finally{i.f()}return s.lines(r)}})),be=T(((e,t)=>{let n={arrowUp:`↑`,arrowDown:`↓`,arrowLeft:`←`,arrowRight:`→`,radioOn:`◉`,radioOff:`◯`,tick:`✔`,cross:`✖`,ellipsis:`…`,pointerSmall:`›`,line:`─`,pointer:`❯`},r={arrowUp:n.arrowUp,arrowDown:n.arrowDown,arrowLeft:n.arrowLeft,arrowRight:n.arrowRight,radioOn:`(*)`,radioOff:`( )`,tick:`√`,cross:`×`,ellipsis:`...`,pointerSmall:`»`,line:`─`,pointer:`>`};t.exports=process.platform===`win32`?r:n})),xe=T(((e,t)=>{let n=j(),r=be(),i=Object.freeze({password:{scale:1,render:e=>`*`.repeat(e.length)},emoji:{scale:2,render:e=>`😃`.repeat(e.length)},invisible:{scale:0,render:e=>``},default:{scale:1,render:e=>`${e}`}}),a=e=>i[e]||i.default,o=Object.freeze({aborted:n.red(r.cross),done:n.green(r.tick),exited:n.yellow(r.cross),default:n.cyan(`?`)});t.exports={styles:i,render:a,symbols:o,symbol:(e,t,n)=>t?o.aborted:n?o.exited:e?o.done:o.default,delimiter:e=>n.gray(e?r.ellipsis:r.pointerSmall),item:(e,t)=>n.gray(e?t?r.pointerSmall:`+`:r.line)}})),Se=T(((e,t)=>{let n=M();t.exports=function(e,t){let r=String(n(e)||``).split(/\r?\n/);return t?r.map(e=>Math.ceil(e.length/t)).reduce((e,t)=>e+t):r.length}})),Ce=T(((e,t)=>{t.exports=(e,t={})=>{let n=Number.isSafeInteger(parseInt(t.margin))?Array(parseInt(t.margin)).fill(` `).join(``):t.margin||``,r=t.width;return(e||``).split(/\r?\n/g).map(e=>e.split(/\s+/g).reduce((e,t)=>(t.length+n.length>=r||e[e.length-1].length+t.length+1<r?e[e.length-1]+=` ${t}`:e.push(`${n}${t}`),e),[n]).join(`
|
|
3
3
|
`)).join(`
|
|
4
4
|
`)}})),we=T(((e,t)=>{t.exports=(e,t,n)=>{n||=t;let r=Math.min(t-n,e-Math.floor(n/2));r<0&&(r=0);let i=Math.min(r+n,t);return{startIndex:r,endIndex:i}}})),P=T(((e,t)=>{t.exports={action:ve(),clear:ye(),style:xe(),strip:M(),figures:be(),lines:Se(),wrap:Ce(),entriesToDisplay:we()}})),F=T(((e,t)=>{let n=D(`readline`),r=P().action,i=D(`events`),a=N(),o=a.beep,s=a.cursor,c=j();t.exports=class extends i{constructor(e={}){super(),this.firstRender=!0,this.in=e.stdin||process.stdin,this.out=e.stdout||process.stdout,this.onRender=(e.onRender||(()=>void 0)).bind(this);let t=n.createInterface({input:this.in,escapeCodeTimeout:50});n.emitKeypressEvents(this.in,t),this.in.isTTY&&this.in.setRawMode(!0);let i=[`SelectPrompt`,`MultiselectPrompt`].indexOf(this.constructor.name)>-1,a=(e,t)=>{let n=r(t,i);n===!1?this._&&this._(e,t):typeof this[n]==`function`?this[n](t):this.bell()};this.close=()=>{this.out.write(s.show),this.in.removeListener(`keypress`,a),this.in.isTTY&&this.in.setRawMode(!1),t.close(),this.emit(this.aborted?`abort`:this.exited?`exit`:`submit`,this.value),this.closed=!0},this.in.on(`keypress`,a)}fire(){this.emit(`state`,{value:this.value,aborted:!!this.aborted,exited:!!this.exited})}bell(){this.out.write(o)}render(){this.onRender(c),this.firstRender&&=!1}}})),Te=T(((e,t)=>{function n(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){n(e);return}s.done?t(c):Promise.resolve(c).then(r,i)}function r(e){return function(){var t=this,r=arguments;return new Promise(function(i,a){var o=e.apply(t,r);function s(e){n(o,i,a,s,c,`next`,e)}function c(e){n(o,i,a,s,c,`throw`,e)}s(void 0)})}}let i=j(),a=F(),o=N(),s=o.erase,c=o.cursor,l=P(),u=l.style,d=l.clear,f=l.lines,p=l.figures;t.exports=class extends a{constructor(e={}){super(e),this.transform=u.render(e.style),this.scale=this.transform.scale,this.msg=e.message,this.initial=e.initial||``,this.validator=e.validate||(()=>!0),this.value=``,this.errorMsg=e.error||`Please Enter A Valid Value`,this.cursor=Number(!!this.initial),this.cursorOffset=0,this.clear=d(``,this.out.columns),this.render()}set value(e){!e&&this.initial?(this.placeholder=!0,this.rendered=i.gray(this.transform.render(this.initial))):(this.placeholder=!1,this.rendered=this.transform.render(e)),this._value=e,this.fire()}get value(){return this._value}reset(){this.value=``,this.cursor=Number(!!this.initial),this.cursorOffset=0,this.fire(),this.render()}exit(){this.abort()}abort(){this.value=this.value||this.initial,this.done=this.aborted=!0,this.error=!1,this.red=!1,this.fire(),this.render(),this.out.write(`
|
|
@@ -80,7 +80,7 @@ Instructions:
|
|
|
80
80
|
`:``}renderCurrentInput(){return`
|
|
81
81
|
Filtered results for: ${this.inputValue?this.inputValue:n.gray(`Enter something to filter`)}\n`}renderOption(e,t,r){let i;return i=t.disabled?e===r?n.gray().underline(t.title):n.strikethrough().gray(t.title):e===r?n.cyan().underline(t.title):t.title,(t.selected?n.green(s.radioOn):s.radioOff)+` `+i}renderDoneOrInstructions(){if(this.done)return this.value.filter(e=>e.selected).map(e=>e.title).join(`, `);let e=[n.gray(this.hint),this.renderInstructions(),this.renderCurrentInput()];return this.filteredOptions.length&&this.filteredOptions[this.cursor].disabled&&e.push(n.yellow(this.warn)),e.join(` `)}render(){if(this.closed)return;this.firstRender&&this.out.write(r.hide),super.render();let e=[o.symbol(this.done,this.aborted),n.bold(this.msg),o.delimiter(!1),this.renderDoneOrInstructions()].join(` `);this.showMinError&&=(e+=n.red(`You must select a minimum of ${this.minSelected} choices.`),!1),e+=this.renderOptions(this.filteredOptions),this.out.write(this.clear+e),this.clear=a(e,this.out.columns)}}})),gt=T(((e,t)=>{let n=j(),r=z(),{style:i,clear:a}=R(),{erase:o,cursor:s}=N();t.exports=class extends r{constructor(e={}){super(e),this.msg=e.message,this.value=e.initial,this.initialValue=!!e.initial,this.yesMsg=e.yes||`yes`,this.yesOption=e.yesOption||`(Y/n)`,this.noMsg=e.no||`no`,this.noOption=e.noOption||`(y/N)`,this.render()}reset(){this.value=this.initialValue,this.fire(),this.render()}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.fire(),this.render(),this.out.write(`
|
|
82
82
|
`),this.close()}submit(){this.value=this.value||!1,this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
|
|
83
|
-
`),this.close()}_(e,t){return e.toLowerCase()===`y`?(this.value=!0,this.submit()):e.toLowerCase()===`n`?(this.value=!1,this.submit()):this.bell()}render(){this.closed||(this.firstRender?this.out.write(s.hide):this.out.write(a(this.outputText,this.out.columns)),super.render(),this.outputText=[i.symbol(this.done,this.aborted),n.bold(this.msg),i.delimiter(this.done),this.done?this.value?this.yesMsg:this.noMsg:n.gray(this.initialValue?this.yesOption:this.noOption)].join(` `),this.out.write(o.line+s.to(0)+this.outputText))}}})),_t=T(((e,t)=>{t.exports={TextPrompt:$e(),SelectPrompt:et(),TogglePrompt:tt(),DatePrompt:dt(),NumberPrompt:ft(),MultiselectPrompt:pt(),AutocompletePrompt:mt(),AutocompleteMultiselectPrompt:ht(),ConfirmPrompt:gt()}})),vt=T((e=>{let t=e,n=_t(),r=e=>e;function i(e,t,i={}){return new Promise((a,o)=>{let s=new n[e](t),c=i.onAbort||r,l=i.onSubmit||r,u=i.onExit||r;s.on(`state`,t.onState||r),s.on(`submit`,e=>a(l(e))),s.on(`exit`,e=>a(u(e))),s.on(`abort`,e=>o(c(e)))})}t.text=e=>i(`TextPrompt`,e),t.password=e=>(e.style=`password`,t.text(e)),t.invisible=e=>(e.style=`invisible`,t.text(e)),t.number=e=>i(`NumberPrompt`,e),t.date=e=>i(`DatePrompt`,e),t.confirm=e=>i(`ConfirmPrompt`,e),t.list=e=>{let t=e.separator||`,`;return i(`TextPrompt`,e,{onSubmit:e=>e.split(t).map(e=>e.trim())})},t.toggle=e=>i(`TogglePrompt`,e),t.select=e=>i(`SelectPrompt`,e),t.multiselect=e=>{e.choices=[].concat(e.choices||[]);let t=e=>e.filter(e=>e.selected).map(e=>e.value);return i(`MultiselectPrompt`,e,{onAbort:t,onSubmit:t})},t.autocompleteMultiselect=e=>{e.choices=[].concat(e.choices||[]);let t=e=>e.filter(e=>e.selected).map(e=>e.value);return i(`AutocompleteMultiselectPrompt`,e,{onAbort:t,onSubmit:t})};let a=(e,t)=>Promise.resolve(t.filter(t=>t.title.slice(0,e.length).toLowerCase()===e.toLowerCase()));t.autocomplete=e=>(e.suggest=e.suggest||a,e.choices=[].concat(e.choices||[]),i(`AutocompletePrompt`,e))})),yt=T(((e,t)=>{let n=vt(),r=[`suggest`,`format`,`onState`,`validate`,`onRender`,`type`],i=()=>{};async function a(e=[],{onSubmit:t=i,onCancel:s=i}={}){let c={},l=a._override||{};e=[].concat(e);let u,d,f,p,m,h,g=async(e,t,n=!1)=>{if(!(!n&&e.validate&&e.validate(t)!==!0))return e.format?await e.format(t,c):t};for(d of e)if({name:p,type:m}=d,typeof m==`function`&&(m=await m(u,{...c},d),d.type=m),m){for(let e in d){if(r.includes(e))continue;let t=d[e];d[e]=typeof t==`function`?await t(u,{...c},h):t}if(h=d,typeof d.message!=`string`)throw Error(`prompt message is required`);if({name:p,type:m}=d,n[m]===void 0)throw Error(`prompt type (${m}) is not defined`);if(l[d.name]!==void 0&&(u=await g(d,l[d.name]),u!==void 0)){c[p]=u;continue}try{u=a._injected?o(a._injected,d.initial):await n[m](d),c[p]=u=await g(d,u,!0),f=await t(d,u,c)}catch{f=!await s(d,c)}if(f)return c}return c}function o(e,t){let n=e.shift();if(n instanceof Error)throw n;return n===void 0?t:n}function s(e){a._injected=(a._injected||[]).concat(e)}function c(e){a._override=Object.assign({},e)}t.exports=Object.assign(a,{prompt:a,prompts:n,inject:s,override:c})})),V=T(((e,t)=>{function n(e){e=(Array.isArray(e)?e:e.split(`.`)).map(Number);let t=0,n=process.versions.node.split(`.`).map(Number);for(;t<e.length;t++){if(n[t]>e[t])return!1;if(e[t]>n[t])return!0}return!1}t.exports=n(`8.6.0`)?Ge():yt()})),bt=E(V(),1);const xt=g.homedir(),H=d.join(xt,`.NAPPS`),U=d.join(H,`.auth`);let W=null;async function G(){return W?(Tt(W.accessExpiresAt)&&(W=null,await K()),W?.accessToken??null):null}async function St(e,t){if(await K())return!0;let n=e&&t,r=[{type:`text`,name:`email`,message:`Insert NAPPS email:`},{type:`password`,name:`password`,message:`Insert password:`}],i=!1,a={email:e,password:t};if(!n){let e=await(0,bt.default)(r,{onCancel:()=>{i=!0}});a.email=e.email,a.password=e.password}if(i)return!1;try{let e=await me(a.email,a.password);if(!e)return!1;await Ct(e.refreshToken,e.refreshExpiresAt),W={accessToken:e.accessToken,accessExpiresAt:new Date(e.accessExpiresAt)};let t=await ge(e.accessToken);return t?(console.log(`Authenticated as ${t.name}`),!0):(console.log(`Failed to get user info after authentication`),!1)}catch(e){console.log(`Authentication failed`,e)}return!1}async function Ct(e,t){r.existsSync(H)||r.mkdirSync(H);let n={token:e,expireAt:new Date(t)},i=JSON.stringify(n,null,2);try{r.writeFileSync(U,i)}catch(e){console.error(`Failed to save auth data`,e)}}async function K(){try{if(!r.existsSync(U))return!1;let e=r.readFileSync(U,`utf-8`),t=JSON.parse(e);if(t.expireAt=new Date(t.expireAt),Tt(t.expireAt))return r.unlinkSync(U),!1;let n=await he(t.token);return n?(W={accessToken:n.accessToken,accessExpiresAt:new Date(n.accessTokenExpiresAt)},!0):!1}catch{}return!1}async function wt(){try{return r.existsSync(U)?(r.unlinkSync(U),r.rmdirSync(H),!0):!0}catch(e){return console.error(`Failed to remove local authentication data`,e),!1}}function Tt(e){let t=new Date;return e.getTime()<t.getTime()}function Et(e){let t=f.join(e,`napps.config.json`);if(!i.existsSync(t)){console.log(`napps.config.json not found in the current directory.`);return}let n=i.readFileSync(t,`utf-8`);try{let e=JSON.parse(n);if(!Ot(e)){console.log(`napps.config.json is not valid. Aborting.`);return}return e}catch(e){console.log(`Failed to read napps.config.json`,e)}}function Dt(e,t){if(!Ot(t)){console.log(`Config data is not valid, cannot save napps.config.json.`);return}let n=f.join(e,`napps.config.json`),r=JSON.stringify(t,null,2);try{i.writeFileSync(n,r,`utf-8`)}catch(e){console.log(`Failed to save napps.config.json`,e)}}function Ot(e){if(!e.projectName||typeof e.projectName!=`string`)return console.log(`Invalid project name in napps.config.json.`),!1;if(typeof e.identifier!=`string`)return console.log(`Invalid identifier in napps.config.json`),!1;if(!Array.isArray(e.supportedPdpComponents))return console.log(`Invalid supportedPdpComponents in napps.config.json`),!1;if(!Array.isArray(e.supportedHomeComponents))return console.log(`Invalid supportedHomeComponents in napps.config.json`),!1;if(!Array.isArray(e.supportedShopBuilderComponents))return console.log(`Invalid supportedShopBuilderComponents in napps.config.json`),!1;let t=e=>e.every(e=>{if(typeof e!=`object`||!e)return!1;let t=e;return!(typeof t.componentType!=`number`||t.name!==void 0&&typeof t.name!=`string`||t.renderer!==void 0&&typeof t.renderer!=`string`)});if(!t(e.supportedPdpComponents))return console.log(`Invalid component in supportedPdpComponents`),!1;if(!t(e.supportedHomeComponents))return console.log(`Invalid component in supportedHomeComponents`),!1;if(!t(e.supportedShopBuilderComponents))return console.log(`Invalid component in supportedShopBuilderComponents`),!1;if(e.settings!==void 0){if(!Array.isArray(e.settings))return console.log(`Invalid settings in napps.config.json`),!1;if(!e.settings.every(e=>{if(typeof e!=`object`||!e)return!1;let t=e;return!(typeof t.id!=`string`||typeof t.type!=`string`||t.value!==void 0&&typeof t.value!=`string`)}))return console.log(`Invalid settings format in napps.config.json`),!1}return!0}async function kt(e,t,n,r){let i={identifier:t,sourceCode:r,manifest:n};return(await fetch(`${k}/admin/scripting`,{method:`PUT`,headers:{Authorization:e},credentials:`include`,body:JSON.stringify(i)})).ok}async function At(e,t,n,r){let i={sourceCode:t,title:n,manifest:r},a=await fetch(`${k}/admin/scripting`,{method:`POST`,headers:{Authorization:e},credentials:`include`,body:JSON.stringify(i)});if(!a.ok)throw new O(`Request failed`,a);return await a.json()}var jt=E(V(),1);const Mt=x(_),q=process.cwd();async function Nt(){let e=Et(q);if(!e)return;if(!await K()){console.log(`You are not authenticated, please run auth command.`);return}if(console.log(`Building project...`),await Mt(`npm run build`,{cwd:q}),console.log(`Project built successfully.`),!i.existsSync(A)){console.log(`Build file not found. Please make sure the file component-extension.es.js is being built into the dist folder.`);return}console.log(`Reading build file `+A+` ...`);let t=i.readFileSync(A,`utf-8`);if(e.identifier===``){if(console.log(`Project identifier is not set in napps.config.json.`),!(await(0,jt.default)({type:`confirm`,initial:!1,name:`createIdentifier`,message:`Want to create a component?`})).createIdentifier){console.log(`Deploy cancelled.`);return}await Pt(e,t);return}else await Ft(e,t)}async function Pt(e,t){try{let n=await G();if(!n){console.log(`You are not authenticated, please run auth command.`);return}let r=await At(n,t,e.projectName,{supportedPdpComponents:e.supportedPdpComponents,supportedHomeComponents:e.supportedHomeComponents,supportedShopBuilderComponents:e.supportedShopBuilderComponents,settings:e.settings});e.identifier=r.identifier,Dt(q,e),console.log(`Component created and deployed with identifier:`,r.identifier)}catch(e){console.log(`Failed to create module:`,e)}}async function Ft(e,t){let n=await G();if(!n){console.log(`You are not authenticated, please run auth command.`);return}await kt(n,e.identifier,{supportedPdpComponents:e.supportedPdpComponents,supportedHomeComponents:e.supportedHomeComponents,supportedShopBuilderComponents:e.supportedShopBuilderComponents,settings:e.settings},t)?console.log(`Component updated and deployed`):console.log(`Failed to update component`)}const It=`2024.8.2`,Lt=`https://github.com/cloudflare/cloudflared/releases/download/${It}/`,Rt={linux:{arm64:`cloudflared-linux-arm64`,arm:`cloudflared-linux-arm`,x64:`cloudflared-linux-amd64`,ia32:`cloudflared-linux-386`},darwin:{arm64:`cloudflared-darwin-arm64.tgz`,x64:`cloudflared-darwin-amd64.tgz`},win32:{x64:`cloudflared-windows-amd64.exe`,ia32:`cloudflared-windows-386.exe`,arm64:`cloudflared-windows-amd64.exe`}};function zt(e=process.platform,t=process.arch){if(!Object.keys(Rt).includes(e))throw Error(`Unsupported system platform: ${e}`);let n=Rt[e][t];if(n===void 0)throw Error(`Unsupported system arch: ${t}`);return Lt+n}function Bt(e=process.env,t=process.platform){return e.NAPPS_CLI_CLOUDFLARED_PATH?e.NAPPS_CLI_CLOUDFLARED_PATH:h(m(te(import.meta.url)),`..`,`bin`,t===`win32`?`cloudflared.exe`:`cloudflared`)}async function Vt(e=process.env,t=process.platform,n=process.arch){if(e.NAPPS_CLI_IGNORE_CLOUDFLARED){console.error(`Skipping cloudflared installation because NAPPS_CLI_IGNORE_CLOUDFLARED is set`);return}let r=zt(t,n),i=Bt(e,t);if(s(i))try{let e=v(i,[`--version`],{encoding:`utf8`}).split(` `);if(!Ht(It,e.length>2?e[2]:`0.0.0`))return}catch{console.debug(`version check failed, reinstalling`)}if(t===`linux`)await Ut(r,i);else if(t===`darwin`)await Gt(r,i);else if(t===`win32`)await Wt(r,i);else throw Error(`Unsupported platform: ${t}`)}function Ht(e,t){let[n,r,i]=e.split(`.`).map(Number),[a,o,s]=t.split(`.`).map(Number);return n===a?r===o?(i??0)>(s??0):(r??0)>(o??0):(n??0)>(a??0)}async function Ut(e,t){await J(e,t),await a(t,`755`)}async function Wt(e,t){await J(e,t)}async function Gt(e,t){await J(e,`${t}.tgz`),y(`tar -xzf ${p(`${t}.tgz`)}`,{cwd:m(t)}),u(`${t}.tgz`),await l(`${m(t)}/cloudflared`,t)}async function J(e,t){s(m(t))||c(m(t));let n=b.promisify(re),r=await fetch(e,{redirect:`follow`});if(!r.ok||!r.body)throw Error(`Couldn't download file ${e} (${r.status} ${r.statusText})`);let i=o(t);return await n(r.body,i),t}async function Kt(e,t){try{return console.log(`Attempting to start Cloudflare tunnel on port ${e}...`),await new qt(e,t).startTunnel(),!0}catch(e){let t=new en(`unknown`,e.message);return console.error(t),!1}}var qt=class{port;onComplete;provider=`napps-cli`;currentStatus={status:`not-started`};abortController=void 0;constructor(e,t){this.port=e,this.onComplete=t}async startTunnel(){try{await Vt(),this.tunnel()}catch(e){this.currentStatus={status:`error`,message:e.message,tryMessage:Y()}}}getTunnelStatus(){return this.currentStatus}stopTunnel(){this.abortController?.abort()}tunnel(e=0){this.abortController=new AbortController;let t=!1;if(e>=5){t=!0,this.currentStatus={status:`error`,message:`Could not start Cloudflare tunnel: max retries reached.`,tryMessage:Y()};return}let n=[`tunnel`,`--url`,`http://localhost:${this.port}`,`--no-autoupdate`],r=[],i=!1,a;this.currentStatus={status:`starting`},setTimeout(()=>{if(!t){t=!0;let e=[...new Set(r)].slice(-5).join(`
|
|
83
|
+
`),this.close()}_(e,t){return e.toLowerCase()===`y`?(this.value=!0,this.submit()):e.toLowerCase()===`n`?(this.value=!1,this.submit()):this.bell()}render(){this.closed||(this.firstRender?this.out.write(s.hide):this.out.write(a(this.outputText,this.out.columns)),super.render(),this.outputText=[i.symbol(this.done,this.aborted),n.bold(this.msg),i.delimiter(this.done),this.done?this.value?this.yesMsg:this.noMsg:n.gray(this.initialValue?this.yesOption:this.noOption)].join(` `),this.out.write(o.line+s.to(0)+this.outputText))}}})),_t=T(((e,t)=>{t.exports={TextPrompt:$e(),SelectPrompt:et(),TogglePrompt:tt(),DatePrompt:dt(),NumberPrompt:ft(),MultiselectPrompt:pt(),AutocompletePrompt:mt(),AutocompleteMultiselectPrompt:ht(),ConfirmPrompt:gt()}})),vt=T((e=>{let t=e,n=_t(),r=e=>e;function i(e,t,i={}){return new Promise((a,o)=>{let s=new n[e](t),c=i.onAbort||r,l=i.onSubmit||r,u=i.onExit||r;s.on(`state`,t.onState||r),s.on(`submit`,e=>a(l(e))),s.on(`exit`,e=>a(u(e))),s.on(`abort`,e=>o(c(e)))})}t.text=e=>i(`TextPrompt`,e),t.password=e=>(e.style=`password`,t.text(e)),t.invisible=e=>(e.style=`invisible`,t.text(e)),t.number=e=>i(`NumberPrompt`,e),t.date=e=>i(`DatePrompt`,e),t.confirm=e=>i(`ConfirmPrompt`,e),t.list=e=>{let t=e.separator||`,`;return i(`TextPrompt`,e,{onSubmit:e=>e.split(t).map(e=>e.trim())})},t.toggle=e=>i(`TogglePrompt`,e),t.select=e=>i(`SelectPrompt`,e),t.multiselect=e=>{e.choices=[].concat(e.choices||[]);let t=e=>e.filter(e=>e.selected).map(e=>e.value);return i(`MultiselectPrompt`,e,{onAbort:t,onSubmit:t})},t.autocompleteMultiselect=e=>{e.choices=[].concat(e.choices||[]);let t=e=>e.filter(e=>e.selected).map(e=>e.value);return i(`AutocompleteMultiselectPrompt`,e,{onAbort:t,onSubmit:t})};let a=(e,t)=>Promise.resolve(t.filter(t=>t.title.slice(0,e.length).toLowerCase()===e.toLowerCase()));t.autocomplete=e=>(e.suggest=e.suggest||a,e.choices=[].concat(e.choices||[]),i(`AutocompletePrompt`,e))})),yt=T(((e,t)=>{let n=vt(),r=[`suggest`,`format`,`onState`,`validate`,`onRender`,`type`],i=()=>{};async function a(e=[],{onSubmit:t=i,onCancel:s=i}={}){let c={},l=a._override||{};e=[].concat(e);let u,d,f,p,m,h,g=async(e,t,n=!1)=>{if(!(!n&&e.validate&&e.validate(t)!==!0))return e.format?await e.format(t,c):t};for(d of e)if({name:p,type:m}=d,typeof m==`function`&&(m=await m(u,{...c},d),d.type=m),m){for(let e in d){if(r.includes(e))continue;let t=d[e];d[e]=typeof t==`function`?await t(u,{...c},h):t}if(h=d,typeof d.message!=`string`)throw Error(`prompt message is required`);if({name:p,type:m}=d,n[m]===void 0)throw Error(`prompt type (${m}) is not defined`);if(l[d.name]!==void 0&&(u=await g(d,l[d.name]),u!==void 0)){c[p]=u;continue}try{u=a._injected?o(a._injected,d.initial):await n[m](d),c[p]=u=await g(d,u,!0),f=await t(d,u,c)}catch{f=!await s(d,c)}if(f)return c}return c}function o(e,t){let n=e.shift();if(n instanceof Error)throw n;return n===void 0?t:n}function s(e){a._injected=(a._injected||[]).concat(e)}function c(e){a._override=Object.assign({},e)}t.exports=Object.assign(a,{prompt:a,prompts:n,inject:s,override:c})})),V=T(((e,t)=>{function n(e){e=(Array.isArray(e)?e:e.split(`.`)).map(Number);let t=0,n=process.versions.node.split(`.`).map(Number);for(;t<e.length;t++){if(n[t]>e[t])return!1;if(e[t]>n[t])return!0}return!1}t.exports=n(`8.6.0`)?Ge():yt()})),bt=E(V(),1);const xt=g.homedir(),H=d.join(xt,`.NAPPS`),U=d.join(H,`.auth`);let W=null;async function G(){return W?(Tt(W.accessExpiresAt)&&(W=null,await K()),W?.accessToken??null):null}async function St(e,t){if(await K())return!0;let n=e&&t,r=[{type:`text`,name:`email`,message:`Insert NAPPS email:`},{type:`password`,name:`password`,message:`Insert password:`}],i=!1,a={email:e,password:t};if(!n){let e=await(0,bt.default)(r,{onCancel:()=>{i=!0}});a.email=e.email,a.password=e.password}if(i)return!1;try{let e=await me(a.email,a.password);if(!e)return!1;await Ct(e.refreshToken,e.refreshExpiresAt),W={accessToken:e.accessToken,accessExpiresAt:new Date(e.accessExpiresAt)};let t=await ge(e.accessToken);return t?(console.log(`Authenticated as ${t.name}`),!0):(console.log(`Failed to get user info after authentication`),!1)}catch(e){console.log(`Authentication failed`,e)}return!1}async function Ct(e,t){r.existsSync(H)||r.mkdirSync(H);let n={token:e,expireAt:new Date(t)},i=JSON.stringify(n,null,2);try{r.writeFileSync(U,i)}catch(e){console.error(`Failed to save auth data`,e)}}async function K(){try{if(!r.existsSync(U))return!1;let e=r.readFileSync(U,`utf-8`),t=JSON.parse(e);if(t.expireAt=new Date(t.expireAt),Tt(t.expireAt))return r.unlinkSync(U),!1;let n=await he(t.token);return n?(W={accessToken:n.accessToken,accessExpiresAt:new Date(n.accessTokenExpiresAt)},!0):!1}catch{}return!1}async function wt(){try{return r.existsSync(U)?(r.unlinkSync(U),r.rmdirSync(H),!0):!0}catch(e){return console.error(`Failed to remove local authentication data`,e),!1}}function Tt(e){let t=new Date;return e.getTime()<t.getTime()}function Et(e){let t=f.join(e,`napps.config.json`);if(!i.existsSync(t)){console.log(`napps.config.json not found in the current directory.`);return}let n=i.readFileSync(t,`utf-8`);try{let e=JSON.parse(n);if(!Ot(e)){console.log(`napps.config.json is not valid. Aborting.`);return}return e}catch(e){console.log(`Failed to read napps.config.json`,e)}}function Dt(e,t){if(!Ot(t)){console.log(`Config data is not valid, cannot save napps.config.json.`);return}let n=f.join(e,`napps.config.json`),r=JSON.stringify(t,null,2);try{i.writeFileSync(n,r,`utf-8`)}catch(e){console.log(`Failed to save napps.config.json`,e)}}function Ot(e){if(!e.projectName||typeof e.projectName!=`string`)return console.log(`Invalid project name in napps.config.json.`),!1;if(typeof e.identifier!=`string`)return console.log(`Invalid identifier in napps.config.json`),!1;if(!Array.isArray(e.supportedPdpComponents))return console.log(`Invalid supportedPdpComponents in napps.config.json`),!1;if(!Array.isArray(e.supportedHomeComponents))return console.log(`Invalid supportedHomeComponents in napps.config.json`),!1;if(!Array.isArray(e.supportedShopBuilderComponents))return console.log(`Invalid supportedShopBuilderComponents in napps.config.json`),!1;let t=e=>e.every(e=>{if(typeof e!=`object`||!e)return!1;let t=e;return!(typeof t.componentType!=`number`||t.name!==void 0&&typeof t.name!=`string`||t.renderer!==void 0&&typeof t.renderer!=`string`)});return t(e.supportedPdpComponents)?t(e.supportedHomeComponents)?t(e.supportedShopBuilderComponents)?!0:(console.log(`Invalid component in supportedShopBuilderComponents`),!1):(console.log(`Invalid component in supportedHomeComponents`),!1):(console.log(`Invalid component in supportedPdpComponents`),!1)}async function kt(e,t,n){try{let r={identifier:t.identifier,sourceCode:n,config:t},i=await fetch(`${k}/admin/scripting`,{method:`PUT`,headers:{Authorization:e},credentials:`include`,body:JSON.stringify(r)});return i.ok?await i.json():void 0}catch(e){console.log(`Failed to update module:`,e);return}}async function At(e,t,n){let r={sourceCode:t,title:n.projectName,config:n},i=await fetch(`${k}/admin/scripting`,{method:`POST`,headers:{Authorization:e},credentials:`include`,body:JSON.stringify(r)});if(!i.ok)throw new O(`Request failed`,i);return await i.json()}var jt=E(V(),1);const Mt=x(_),q=process.cwd();async function Nt(){let e=Et(q);if(!e)return;if(!await K()){console.log(`You are not authenticated, please run auth command.`);return}if(console.log(`Building project...`),await Mt(`npm run build`,{cwd:q}),console.log(`Project built successfully.`),!i.existsSync(A)){console.log(`Build file not found. Please make sure the file component-extension.es.js is being built into the dist folder.`);return}console.log(`Reading build file `+A+` ...`);let t=i.readFileSync(A,`utf-8`);if(e.identifier===``){if(console.log(`Project identifier is not set in napps.config.json.`),!(await(0,jt.default)({type:`confirm`,initial:!1,name:`createIdentifier`,message:`Want to create a component?`})).createIdentifier){console.log(`Deploy cancelled.`);return}await Pt(e,t);return}else await Ft(e,t)}async function Pt(e,t){try{let n=await G();if(!n){console.log(`You are not authenticated, please run auth command.`);return}let r=await At(n,t,e);e.identifier=r.identifier,Dt(q,e),console.log(`Component created and deployed with identifier:`,r.identifier)}catch(e){console.log(`Failed to create module:`,e)}}async function Ft(e,t){let n=await G();if(!n){console.log(`You are not authenticated, please run auth command.`);return}let r=await kt(n,e,t);if(console.log(r),r===void 0){console.log(`Component updated and deployed`);return}e.components=r.components,Dt(q,e)}const It=`2024.8.2`,Lt=`https://github.com/cloudflare/cloudflared/releases/download/${It}/`,Rt={linux:{arm64:`cloudflared-linux-arm64`,arm:`cloudflared-linux-arm`,x64:`cloudflared-linux-amd64`,ia32:`cloudflared-linux-386`},darwin:{arm64:`cloudflared-darwin-arm64.tgz`,x64:`cloudflared-darwin-amd64.tgz`},win32:{x64:`cloudflared-windows-amd64.exe`,ia32:`cloudflared-windows-386.exe`,arm64:`cloudflared-windows-amd64.exe`}};function zt(e=process.platform,t=process.arch){if(!Object.keys(Rt).includes(e))throw Error(`Unsupported system platform: ${e}`);let n=Rt[e][t];if(n===void 0)throw Error(`Unsupported system arch: ${t}`);return Lt+n}function Bt(e=process.env,t=process.platform){return e.NAPPS_CLI_CLOUDFLARED_PATH?e.NAPPS_CLI_CLOUDFLARED_PATH:h(m(te(import.meta.url)),`..`,`bin`,t===`win32`?`cloudflared.exe`:`cloudflared`)}async function Vt(e=process.env,t=process.platform,n=process.arch){if(e.NAPPS_CLI_IGNORE_CLOUDFLARED){console.error(`Skipping cloudflared installation because NAPPS_CLI_IGNORE_CLOUDFLARED is set`);return}let r=zt(t,n),i=Bt(e,t);if(s(i))try{let e=v(i,[`--version`],{encoding:`utf8`}).split(` `);if(!Ht(It,e.length>2?e[2]:`0.0.0`))return}catch{console.debug(`version check failed, reinstalling`)}if(t===`linux`)await Ut(r,i);else if(t===`darwin`)await Gt(r,i);else if(t===`win32`)await Wt(r,i);else throw Error(`Unsupported platform: ${t}`)}function Ht(e,t){let[n,r,i]=e.split(`.`).map(Number),[a,o,s]=t.split(`.`).map(Number);return n===a?r===o?(i??0)>(s??0):(r??0)>(o??0):(n??0)>(a??0)}async function Ut(e,t){await J(e,t),await a(t,`755`)}async function Wt(e,t){await J(e,t)}async function Gt(e,t){await J(e,`${t}.tgz`),y(`tar -xzf ${p(`${t}.tgz`)}`,{cwd:m(t)}),u(`${t}.tgz`),await l(`${m(t)}/cloudflared`,t)}async function J(e,t){s(m(t))||c(m(t));let n=b.promisify(re),r=await fetch(e,{redirect:`follow`});if(!r.ok||!r.body)throw Error(`Couldn't download file ${e} (${r.status} ${r.statusText})`);let i=o(t);return await n(r.body,i),t}async function Kt(e,t){try{return console.log(`Attempting to start Cloudflare tunnel on port ${e}...`),await new qt(e,t).startTunnel(),!0}catch(e){let t=new en(`unknown`,e.message);return console.error(t),!1}}var qt=class{port;onComplete;provider=`napps-cli`;currentStatus={status:`not-started`};abortController=void 0;constructor(e,t){this.port=e,this.onComplete=t}async startTunnel(){try{await Vt(),this.tunnel()}catch(e){this.currentStatus={status:`error`,message:e.message,tryMessage:Y()}}}getTunnelStatus(){return this.currentStatus}stopTunnel(){this.abortController?.abort()}tunnel(e=0){this.abortController=new AbortController;let t=!1;if(e>=5){t=!0,this.currentStatus={status:`error`,message:`Could not start Cloudflare tunnel: max retries reached.`,tryMessage:Y()};return}let n=[`tunnel`,`--url`,`http://localhost:${this.port}`,`--no-autoupdate`],r=[],i=!1,a;this.currentStatus={status:`starting`},setTimeout(()=>{if(!t){t=!0;let e=[...new Set(r)].slice(-5).join(`
|
|
84
84
|
`);e===``?this.currentStatus={status:`error`,message:`Could not start Cloudflare tunnel: unknown error.`,tryMessage:Y()}:this.currentStatus={status:`error`,message:e,tryMessage:Y()},this.abortController?.abort()}},40*1e3);let o=this,s=new ne({write(e,n,s){if(t)return;a||=Jt(e),Zt(e)&&(i=!0),i&&(a?(t=!0,o.currentStatus={status:`connected`,url:a},o.onComplete?.(a)):o.currentStatus={status:`error`,message:`Could not start Cloudflare tunnel: URL not found.`});let c=Yt(e);c&&r.push(c),s()}}),c=C(Qt(),n,{signal:this.abortController.signal});c.stdout.pipe(s),c.stderr.pipe(s),c.on(`error`,async n=>{if(t)throw Error(`Could not start Cloudflare tunnel: process crashed after stablishing a connection: ${n.message}`);console.debug(`Cloudflare tunnel crashed: ${n.message}, restarting...`),await new Promise(e=>setTimeout(e,1*1e3)),this.tunnel(e+1)})}};function Y(){return`You can run the command again`}function Jt(e){let t=RegExp(`(https:\\/\\/[^\\s]+\\.${$t()})`),n=e.toString().match(t)??void 0;return n&&n[1]}function Yt(e){if([/failed to request quick Tunnel/,/failed to unmarshal quick Tunnel/,/failed to parse quick Tunnel ID/,/failed to provision routing/,/ERR Couldn't start tunnel/,/ERR Failed to serve quic connection/,/ERR Failed to create new quic connection error/].some(t=>t.test(e.toString())))return`Could not start Cloudflare tunnel: ${Xt(e.toString())}`}function Xt(e){return e.replace(/^[0-9TZ:-]+ (ERR )?/g,``).replace(/connIndex.*/g,``)}function Zt(e){let t=e.toString().match(/(INF Registered tunnel connection|INF Connection)/)??void 0;return t&&t[0]}function Qt(){return process.env.NAPPS_CLI_CLOUDFLARED_PATH?process.env.NAPPS_CLI_CLOUDFLARED_PATH:h(m(te(import.meta.url)),`..`,`bin`,process.platform===`win32`?`cloudflared.exe`:`cloudflared`)}function $t(){return process.env.NAPPS_CLI_CLOUDFLARED_DOMAIN??`trycloudflare.com`}var en=class{type;constructor(e,t){this.type=e}};const tn=e=>e.action(e.port,e.onComplete);let X=null,Z={},Q=``,$={},nn=1,rn={};function an(e,t){let n=e.headers.host;n?.startsWith(`[::1]`)==1&&(n=`localhost:3000`);let r=Object.keys(Z).map(e=>Z[e]).map(e=>({description:e.description,devtoolsFrontendUrl:`/devtools/inspector.html?ws=${n}/ws/devtools?targetID=${e.id}`,devtoolsFrontendUrlCompat:`/devtools/inspector.html?ws=${n}/ws/devtools?targetID=${e.id}`,id:e.id,title:e.title,type:`napps`,url:`http://${n}/ws/devtools?targetID=${e.id}`,webSocketDebuggerUrl:`ws://${n}/ws/devtools?targetID=${e.id}`})),i=JSON.stringify(r);t.end(i)}function on(e,t){let n={Browser:`NAPPS`,"Protocol-Version":`1.3`,"User-Agent":`V8-CDP-Bridge/1.0`,"V8-Version":Q,"WebKit-Version":`V8-CDP-Bridge/1.0`};t.end(JSON.stringify(n))}function sn(e){let t=new ae({noServer:!0,path:`/ws/devtools`,perMessageDeflate:{zlibDeflateOptions:{chunkSize:1024,memLevel:7,level:3},zlibInflateOptions:{chunkSize:10*1024},clientNoContextTakeover:!0,serverNoContextTakeover:!0,serverMaxWindowBits:10,concurrencyLimit:10,threshold:1024}});return e.on(`upgrade`,async(e,n,r)=>{if(e.url?.startsWith(`/ws/devtools`)===!0){let i=URL.parse(`https://server`+e.url),a=i?.searchParams.get(`isMobile`)==`true`;if(a&&X){console.log(`New WebSocket connection on mobile with one already connected, ignoring new connection.`),n.write(`HTTP/1.1 429 Too Many Requests\r
|
|
85
85
|
\r
|
|
86
86
|
`),n.destroy();return}else if(a)t.handleUpgrade(e,n,r,n=>{t.emit(`appsConnection`,n,e)});else{let a=i?.searchParams.get(`targetID`);if(!a){n.destroy();return}let o=nn+++``,s={id:o,event:ln,payload:{targetID:a}};if(!X){console.log(`Attempt to connect DevTools without mobile app connected.`);return}X?.send(JSON.stringify(s));let c,l=new Promise((e,t)=>{let n=2e4;c=setTimeout(()=>{t(Error(`Promise timed out after ${n} ms`))},n),$[o]={resolve:t=>{clearTimeout(c),e(t)},reject:e=>{clearTimeout(c),t(e)}}});try{let i=await l;clearTimeout(c),delete $[o],t.handleUpgrade(e,n,r,n=>{t.emit(`devToolsConnection`,n,e,i,a)})}catch{console.log(`DevTools connect pending request failed`),delete $[o];return}}}else n.destroy()}),t.on(`appsConnection`,e=>{dn(e)}),t.on(`devToolsConnection`,(e,t,n,r)=>{un(e,t,n,r)}),()=>Q}const cn=`devtools.message`,ln=`devtools.connect`;function un(e,t,n,r){console.log(`DevTools WebSocket client connected`),rn[n]=t=>{e.send(t)},e.on(`message`,(e,t)=>{let i={event:cn,payload:{msg:e.toString(`utf8`),targetID:r},sessionID:n};X?.send(JSON.stringify(i))}),e.on(`error`,e=>{console.error(`DevTools WebSocket Error:`,e)}),e.on(`close`,(e,t)=>{console.log(`WebSocket devtools client disconnected.`),delete rn[n];let i={event:`devtools.disconnect`,payload:{targetID:r},sessionID:n};X?.send(JSON.stringify(i))})}function dn(e){X=e,console.log(`Mobile App WebSocket client connected`);let t=JSON.stringify({event:`ping`,payload:{}}),n=setInterval(()=>{e.send(t)},2e3);e.on(`message`,(e,t)=>{if(t){console.error(`Received unexpected binary data`);return}let n=e.toString(`utf8`),r=JSON.parse(n);if(r.event===`Target.created`){let e=r.payload.targetInfo,t={description:e.description,devtoolsFrontendUrl:``,devtoolsFrontendUrlCompat:``,id:e.id,title:e.title,type:`NAPPSApp`,url:``,webSocketDebuggerUrl:``};Z[e.id]=t,console.log(`DevTools target was added`)}else if(r.event===`Target.destroyed`){let e=r.payload.targetID;delete Z[e],console.log(`DevTools target was removed`)}else if(r.event===cn){let e=r.sessionID;if(!e){console.error(`Receive App message to devtools with invalid sessionID`,e);return}let t=rn[e];if(!t){console.error(`Receive App message to devtools with not way to send message`,e);return}t(r.payload.msg)}else if(r.event===`devtools.connected`){if(!r.id){console.log(`Received DevTools connected message without message ID`);return}let e=r.payload.sessionID;$[r.id]?.resolve(e)}else r.event===`devtools.disconnected`||(r.event===`version`?Q=r.payload.version:r.event!==`pong`&&console.error(`Received unexpected message with event`,r.event))}),e.on(`error`,e=>{console.error(`WebSocket Error:`,e)}),e.on(`close`,(e,t)=>{clearInterval(n),X=null,console.log(`Mobile App WebSocket client disconnected.`),Z={}})}var fn=E(V(),1);const pn=new Set;let mn=-1,hn=``;function gn(){let e=JSON.stringify(On);console.log(`Broadcasting update to clients...`);for(let t of pn)t.push(e,`update`)}const _n={type:`select`,name:`componentType`,message:`Pick Page Type:`,choices:[{title:`PDP`,description:`Product detail page`,value:`pdp`}],initial:0},vn=[{type:`select`,name:`componentType`,message:`Select PDP Component Type:`,choices:[{title:`Extra Info`,description:``,value:9},{title:`Text Block`,description:``,value:24},{title:`Product Grid`,description:``,value:25},{title:`Product Linking`,description:``,value:26},{title:`Store Locator`,description:``,value:27},{title:`Table`,description:``,value:28},{title:`Product Stories`,description:``,value:30},{title:`Text Product Linking`,description:``,value:32},{title:`Product Insights`,description:``,value:33},{title:`Product Info Grid`,description:``,value:34},{title:`Product Card Carousel`,description:``,value:35},{title:`Technical Information`,description:``,value:36},{title:`Product Attribute Carousel`,description:``,value:38},{title:`Faqs`,description:``,value:43}]}];async function yn(){let e=!1,t=await(0,fn.default)(_n,{onCancel:()=>{e=!0}});if(e)return;if(hn=t.componentType,hn!==`pdp`){console.log(`Selected page type is not supported yet.`);return}let n=await(0,fn.default)(vn,{onCancel:()=>{e=!0}});if(e)return;mn=n.componentType,console.log(`Running NAPPS Component in development mode...`);let r=S.createServer((e,t)=>Cn(mn,e,t));r.keepAliveTimeout=0,r.headersTimeout=0,r.requestTimeout=0,Sn(),sn(r),r.listen(3e3,()=>{console.log(`Development server is running at http://localhost:3000`),tn({provider:`napps-cli`,port:3e3,action:Kt,onComplete:e=>{globalThis.tunnelUrl=e,console.log(`✅ Cloudflare tunnel established at:`,e),bn(e)}})})}function bn(e){let t=e;ie.toString(t,{type:`terminal`,small:!0},(e,t)=>{if(e){console.error(`Error occurred:`,e);return}console.log(t)})}function xn(e){C(`npm`,[`run`,`build`],{stdio:`inherit`,shell:!0,timeout:5e3}).on(`exit`,t=>{t===0?(console.log(`✅ Build complete`),e(!0)):(console.log(`❌ Build failed with exit code ${t}`),e(!1))})}function Sn(){let e=process.cwd(),t=n.join(e,`src`);console.log(`Starting file watcher in:`,t),w.watch(t,{ignoreInitial:!0}).on(`all`,(e,t)=>{xn(e=>{console.log(`Build ended`),e&&gn()})}),console.log(`👀 Watching for changes...`)}async function Cn(e,t,n){let{url:r,method:i}=t;if(i!==`GET`){n.statusCode=405,n.end(`Method Not Allowed`);return}r===`/updates`?await En(t,n):r===`/info`?Tn(e,t,n):r===`/file`?wn(t,n):r===`/json`||r===`/json/list`?an(t,n):r===`/json/version`?on(t,n):(n.statusCode=404,n.end(`Not Found`))}function wn(e,t){i.stat(A,(e,n)=>{if(e||!n.isFile()){t.writeHead(404,{"Content-Type":`text/plain`}),t.end(`404 Not Found`);return}t.writeHead(200,{"Content-Type":`application/json`,"Content-Length":n.size});let r=i.createReadStream(A);r.on(`error`,e=>{console.error(`File stream error:`,e),t.end()}),r.pipe(t)})}function Tn(e,t,n){n.writeHead(200,{"Content-Type":`application/json`});let r={pageType:hn,componentTypeID:e,status:`running`,timestamp:new Date().toISOString()};n.end(JSON.stringify(r))}async function En(e,t){let n=await ee(e,t);console.log(`Client connected to receive component updates`),pn.add(n),n.push(JSON.stringify(Dn),`connect`);let r=setInterval(()=>{n.push(`PING`,`PING`)},2e3);e.on(`close`,()=>{clearInterval(r),pn.delete(n),console.log(`Client disconnected. Stopped streaming.`)})}const Dn={event:`connected`,data:`You are connected to NAPPS dev server.`},On={event:`updated`,data:`Code updated`};t.version(`0.0.1`).name(`NAPPS CLI`).description(`CLI to manage NAPPS components`),t.command(`auth`).description(`Authenticate into your NAPPS account`).argument(`[username]`,`NAPPS account email`).argument(`[password]`,`NAPPS account password`).action(async(e,t)=>{if(await K()){console.log(`You are already authenticated, run logout if want to login into a different account.`);return}await St(e,t)?console.log(`Authenticated with success!`):console.log(`Authenticated failed!`)}),t.command(`me`).description(`Show authenticated user info`).action(async()=>{let e=await _e();e&&console.log(`You are authenticated as: ${e.name} <${e.email}>`)}),t.command(`logout`).description(`Remove authentication data`).action(async()=>{await wt()}),t.command(`deploy`).description(`Deploy NAPPS component`).action(async()=>{await Nt()}),t.command(`dev`).description(`Run NAPPS component in development mode`).action(async()=>{await yn()}),await t.parseAsync(process.argv);export{};
|
package/package.json
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@napps/cli",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"private": false,
|
|
5
|
-
"engines": {
|
|
6
|
-
"node": "^20.19.0 || >=22.12.0"
|
|
7
|
-
},
|
|
8
|
-
"keywords": [
|
|
9
|
-
"napps"
|
|
10
|
-
],
|
|
11
|
-
"type": "module",
|
|
12
|
-
"exports": {
|
|
13
|
-
".": {
|
|
14
|
-
"import": "./dist/index.js",
|
|
15
|
-
"types": "./dist/index.d.ts"
|
|
16
|
-
},
|
|
17
|
-
"./package.json": "./package.json"
|
|
18
|
-
},
|
|
19
|
-
"main": "index.js",
|
|
20
|
-
"module": "index.js",
|
|
21
|
-
"bin": {
|
|
22
|
-
"napps": "./bin/run.js"
|
|
23
|
-
},
|
|
24
|
-
"files": [
|
|
25
|
-
"/dist",
|
|
26
|
-
"/bin"
|
|
27
|
-
],
|
|
28
|
-
"scripts": {
|
|
29
|
-
"type-check": "tsc --noEmit",
|
|
30
|
-
"build": "tsc --noEmit && tsdown --env-file=.env",
|
|
31
|
-
"build-staging": "tsc --noEmit && tsdown --env-file=.env.staging",
|
|
32
|
-
"build-prod": "tsc --noEmit && tsdown --env-file=.env.prod",
|
|
33
|
-
"prepublishOnly": "npm run build"
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@types/node": "^24.5.9",
|
|
37
|
-
"@types/prompts": "^2.4.9",
|
|
38
|
-
"@types/qrcode": "^1.5.6",
|
|
39
|
-
"dotenv": "^17.2.3",
|
|
40
|
-
"prompts": "^2.4.2",
|
|
41
|
-
"tsdown": "^0.16.6",
|
|
42
|
-
"typescript": "^5.2.2"
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {
|
|
45
|
-
"@types/ws": "^8.18.1",
|
|
46
|
-
"better-sse": "^0.15.1",
|
|
47
|
-
"bufferutil": "^4.0.9",
|
|
48
|
-
"chalk": "^5.6.2",
|
|
49
|
-
"chokidar": "^5.0.0",
|
|
50
|
-
"commander": "^14.0.2",
|
|
51
|
-
"qrcode": "^1.5.4",
|
|
52
|
-
"ts-error": "^1.0.6",
|
|
53
|
-
"ws": "^8.18.3"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@napps/cli",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"private": false,
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [
|
|
9
|
+
"napps"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"main": "index.js",
|
|
20
|
+
"module": "index.js",
|
|
21
|
+
"bin": {
|
|
22
|
+
"napps": "./bin/run.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"/dist",
|
|
26
|
+
"/bin"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"type-check": "tsc --noEmit",
|
|
30
|
+
"build": "tsc --noEmit && tsdown --env-file=.env",
|
|
31
|
+
"build-staging": "tsc --noEmit && tsdown --env-file=.env.staging",
|
|
32
|
+
"build-prod": "tsc --noEmit && tsdown --env-file=.env.prod",
|
|
33
|
+
"prepublishOnly": "npm run build"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^24.5.9",
|
|
37
|
+
"@types/prompts": "^2.4.9",
|
|
38
|
+
"@types/qrcode": "^1.5.6",
|
|
39
|
+
"dotenv": "^17.2.3",
|
|
40
|
+
"prompts": "^2.4.2",
|
|
41
|
+
"tsdown": "^0.16.6",
|
|
42
|
+
"typescript": "^5.2.2"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@types/ws": "^8.18.1",
|
|
46
|
+
"better-sse": "^0.15.1",
|
|
47
|
+
"bufferutil": "^4.0.9",
|
|
48
|
+
"chalk": "^5.6.2",
|
|
49
|
+
"chokidar": "^5.0.0",
|
|
50
|
+
"commander": "^14.0.2",
|
|
51
|
+
"qrcode": "^1.5.4",
|
|
52
|
+
"ts-error": "^1.0.6",
|
|
53
|
+
"ws": "^8.18.3"
|
|
54
|
+
}
|
|
55
|
+
}
|
package/bin/cloudflared.exe
DELETED
|
Binary file
|