@dashnex/cli 0.5.26 → 0.5.32

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 CHANGED
@@ -24,7 +24,6 @@ dashnex <command> [options]
24
24
  | `login` | Log in to your DashNex account |
25
25
  | `logout` | Log out and remove local credentials |
26
26
  | `whoami` | Show current logged-in business and user |
27
- | `select` | Switch to a different business |
28
27
  | `app create` | Create a new DashNex application |
29
28
  | `app pull` | Pull existing application to specified folder |
30
29
  | `app push` | Push local application to DashNex |
@@ -36,4 +35,21 @@ dashnex <command> [options]
36
35
 
37
36
  ### Options
38
37
 
39
- - **app create**: `-t, --template <template>` — Template (name@branch-or-tag, default: webapp-base@live)
38
+ **login**:
39
+ - `--email <email>` — Email address
40
+ - `--password <password>` — Password
41
+ - `--code <code>` — 2FA code
42
+ - `--business <id>` — Business ID to select
43
+
44
+ **app create**:
45
+ - `--subdomain <subdomain>` — Subdomain
46
+ - `-t, --template <template>` — Template, optional (name@branch-or-tag)
47
+
48
+ **app pull**:
49
+ - `-y, --yes` — Skip prompts and child commands
50
+
51
+ **app push**:
52
+ - `--deploy` / `--no-deploy` — Auto-deploy or skip deploy after push
53
+
54
+ **app delete**:
55
+ - `-y, --yes` — Skip confirmation prompt
@@ -1 +1 @@
1
- import e from"inquirer";import t from"chalk";import{debug as o,debugError as s}from"../../lib/debug.js";import{getBusinessApiBase as a}from"../../lib/api.js";import{ensureLoggedIn as i}from"../../services/auth.js";import{createSpinner as r}from"../../lib/spinner.js";import{isUserInterrupt as n,INTERRUPTED_MESSAGE as l}from"../../lib/errors.js";import{PullCommand as c}from"./pull.js";const p=e=>Array.isArray(e.message)&&e.message.length>0?e.message.join("\n"):"string"==typeof e.message?e.message:"string"==typeof e.error?e.error:void 0,u=e=>new Promise(t=>setTimeout(t,e));class d{async pollApplicationCreated(e,t,a=5e3,i=6e4){const r=Date.now();let n=0;for(;Date.now()-r<i;){n++,o(`Polling application status (attempt ${n})...`);try{const s=await fetch(e,{headers:{Authorization:`Bearer ${t}`}});if(o(`Poll response: ${s.status}`),200===s.status){const e=await s.json();if(o(`Poll response body status: ${e.status}`),"creating"!==e.status)return o(`Application status is "${e.status}", creation complete`),{ready:!0,status:e.status};o('Application status is still "creating", continuing to poll...')}}catch(l){s(l),o(`Poll attempt ${n} failed with network error`)}await u(a)}return{ready:!1}}async execute(u={}){o("Create flow started");const d=await i();if(!d)return;o("Auth valid, checking if business already has application");const h=r(),m=`${a()}/business/v1/applications`;o(`GET ${m}`),h.start("Checking application status...");try{const e=await fetch(m,{headers:{Authorization:`Bearer ${d.token}`}});h.stop(),o(`Applications response: ${e.status}`);const s=await e.text();o(`Applications response body: ${s}`),404!==e.status&&(console.error(t.red("Business already has an application. Run 'dashnex app pull' to pull the existing one.")),process.exit(1))}catch($){if(h.stop(),s($),$ instanceof Error&&$.message.startsWith("EXIT:"))throw $;if(n($))return void console.log(t.yellow(l));console.error(t.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}let f;o("No existing application, proceeding to subdomain prompt");const y=e=>`${a()}/business/v1/applications/check-subdomain?subdomain=${encodeURIComponent(e)}`;for(;;){const{sub:a}=await e.prompt([{type:"input",name:"sub",message:"Pick your subdomain:",validate:e=>!!e.trim()||"Subdomain is required"}]);f=a.trim(),o(`Checking subdomain: ${f}`);const i=y(f);o(`GET ${i}`),h.start("Checking subdomain...");try{const e=await fetch(i,{headers:{Authorization:`Bearer ${d.token}`}});h.stop(),o(`Check subdomain response: ${e.status}`);const s=await e.text();if(o(`Check subdomain response body: ${s}`),!e.ok){const a=e.headers.get("content-type")??"";let i="Failed to check subdomain availability.";if(401!==e.status&&403!==e.status||(i="Please run 'dashnex login' to authenticate.",console.error(t.red(i)),process.exit(1)),a.includes("application/json")){const e=JSON.parse(s);o(`Check subdomain error body: ${JSON.stringify(e)}`);const t=p(e);t&&(i=t)}console.error(t.red(i));continue}const a=JSON.parse(s);if(o(`Check subdomain parsed body: ${JSON.stringify(a)}`),a.available){o(`Subdomain ${f} is available`);break}console.error(t.red("Subdomain is not available. Please choose a different one."))}catch($){if(h.stop(),s($),$ instanceof Error&&$.message.startsWith("EXIT:"))throw $;if(n($))return void console.log(t.yellow(l));console.error(t.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}const g=`${a()}/business/v1/cli/create`;o(`POST ${g}`);const b={subdomain:f};u.template&&(b.template=u.template,o(`Template: ${u.template}`));const w=JSON.stringify(b);o(`Create request body: ${w}`),h.start("Creating application...");try{const i=await fetch(g,{method:"POST",headers:{Authorization:`Bearer ${d.token}`,"Content-Type":"application/json"},body:w});h.stop(),o(`Create response: ${i.status}`);const r=await i.text();if(o(`Create response body: ${r}`),503===i.status){o("Create returned 503, polling for application creation..."),console.log(t.yellow("Application is being created, please wait..."));const e=`${a()}/business/v1/applications`,s=await this.pollApplicationCreated(e,d.token);s.ready||(console.error(t.red("Application creation is taking longer than expected. Try again later or run 'dashnex app pull' to check.")),process.exit(1)),"failed"===s.status&&(console.error(t.red("Application creation failed. Please try again.")),process.exit(1)),o("Application found after polling")}else if(!i.ok){const e=i.headers.get("content-type")??"";let s="Failed to create application.";if(401===i.status||403===i.status)s="Please run 'dashnex login' to authenticate.";else if(e.includes("application/json")){const e=JSON.parse(r);o(`Create error body parsed: ${JSON.stringify(e)}`);const t=p(e);t&&(s=t)}console.error(t.red(s)),process.exit(1)}o("Application created successfully");const{pull:u}=await e.prompt([{type:"confirm",name:"pull",message:"Pull the application locally?",default:!0}]);if(o(`User chose to pull: ${u}`),u){o("Running pull flow");try{const e=new c;await e.execute()}catch($){if(s($),$ instanceof Error&&$.message.startsWith("EXIT:"))throw $;if(n($))return void console.log(t.yellow(l));console.error(t.red("Failed to pull application."))}}else console.log(t.green("Application is created successfully. Run 'dashnex app pull' to pull it to your computer or 'dashnex app deploy' to deploy it to the cloud."))}catch($){if(h.stop(),s($),$ instanceof Error&&$.message.startsWith("EXIT:"))throw $;if(n($))return void console.log(t.yellow(l));console.error(t.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}}export{d as CreateCommand};
1
+ import e from"inquirer";import t from"chalk";import{debug as o,debugError as s}from"../../lib/debug.js";import{getBusinessApiBase as a}from"../../lib/api.js";import{ensureLoggedIn as i}from"../../services/auth.js";import{createSpinner as r}from"../../lib/spinner.js";import{isUserInterrupt as n,INTERRUPTED_MESSAGE as l}from"../../lib/errors.js";import{PullCommand as c}from"./pull.js";const p=e=>Array.isArray(e.message)&&e.message.length>0?e.message.join("\n"):"string"==typeof e.message?e.message:"string"==typeof e.error?e.error:void 0,u=e=>new Promise(t=>setTimeout(t,e));class d{async pollApplicationCreated(e,t,a=5e3,i=6e4){const r=Date.now();let n=0;for(;Date.now()-r<i;){n++,o(`Polling application status (attempt ${n})...`);try{const s=await fetch(e,{headers:{Authorization:`Bearer ${t}`}});if(o(`Poll response: ${s.status}`),200===s.status){const e=await s.json();if(o(`Poll response body status: ${e.status}`),"creating"!==e.status)return o(`Application status is "${e.status}", creation complete`),{ready:!0,status:e.status};o('Application status is still "creating", continuing to poll...')}}catch(l){s(l),o(`Poll attempt ${n} failed with network error`)}await u(a)}return{ready:!1}}async execute(u={}){o("Create flow started");const d=await i();if(!d)return;o("Auth valid, checking if business already has application");const h=r(),m=`${a()}/business/v1/applications`;o(`GET ${m}`),h.start("Checking application status...");try{const e=await fetch(m,{headers:{Authorization:`Bearer ${d.token}`}});h.stop(),o(`Applications response: ${e.status}`);const s=await e.text();o(`Applications response body: ${s}`),404!==e.status&&(console.error(t.red("Business already has an application. Run 'dashnex app pull' to pull the existing one.")),process.exit(1))}catch(k){if(h.stop(),s(k),k instanceof Error&&k.message.startsWith("EXIT:"))throw k;if(n(k))return void console.log(t.yellow(l));console.error(t.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}let f;o("No existing application, proceeding to subdomain prompt");const g=e=>`${a()}/business/v1/applications/check-subdomain?subdomain=${encodeURIComponent(e)}`,y=void 0!==u.subdomain;let b=u.subdomain?.trim();for(;;){if(b)f=b,b=void 0,o(`Subdomain provided via flag: ${f}`);else{if(y)return console.error(t.red("Subdomain is not available.")),void process.exit(1);{const{sub:t}=await e.prompt([{type:"input",name:"sub",message:"Pick your subdomain:",validate:e=>!!e.trim()||"Subdomain is required"}]);f=t.trim()}}o(`Checking subdomain: ${f}`);const a=g(f);o(`GET ${a}`),h.start("Checking subdomain...");try{const e=await fetch(a,{headers:{Authorization:`Bearer ${d.token}`}});h.stop(),o(`Check subdomain response: ${e.status}`);const s=await e.text();if(o(`Check subdomain response body: ${s}`),!e.ok){const a=e.headers.get("content-type")??"";let i="Failed to check subdomain availability.";if(401!==e.status&&403!==e.status||(i="Please run 'dashnex login' to authenticate.",console.error(t.red(i)),process.exit(1)),a.includes("application/json")){const e=JSON.parse(s);o(`Check subdomain error body: ${JSON.stringify(e)}`);const t=p(e);t&&(i=t)}console.error(t.red(i));continue}const i=JSON.parse(s);if(o(`Check subdomain parsed body: ${JSON.stringify(i)}`),i.available){o(`Subdomain ${f} is available`);break}console.error(t.red("Subdomain is not available. Please choose a different one."))}catch(k){if(h.stop(),s(k),k instanceof Error&&k.message.startsWith("EXIT:"))throw k;if(n(k))return void console.log(t.yellow(l));console.error(t.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}const w=`${a()}/business/v1/cli/create`;o(`POST ${w}`);const $={subdomain:f};u.template&&($.template=u.template,o(`Template: ${u.template}`));const x=JSON.stringify($);o(`Create request body: ${x}`),h.start("Creating application...");try{const i=await fetch(w,{method:"POST",headers:{Authorization:`Bearer ${d.token}`,"Content-Type":"application/json"},body:x});h.stop(),o(`Create response: ${i.status}`);const r=await i.text();if(o(`Create response body: ${r}`),503===i.status){o("Create returned 503, polling for application creation..."),console.log(t.yellow("Application is being created, please wait..."));const e=`${a()}/business/v1/applications`,s=await this.pollApplicationCreated(e,d.token);s.ready||(console.error(t.red("Application creation is taking longer than expected. Try again later or run 'dashnex app pull' to check.")),process.exit(1)),"failed"===s.status&&(console.error(t.red("Application creation failed. Please try again.")),process.exit(1)),o("Application found after polling")}else if(!i.ok){const e=i.headers.get("content-type")??"";let s="Failed to create application.";if(401===i.status||403===i.status)s="Please run 'dashnex login' to authenticate.";else if(e.includes("application/json")){const e=JSON.parse(r);o(`Create error body parsed: ${JSON.stringify(e)}`);const t=p(e);t&&(s=t)}console.error(t.red(s)),process.exit(1)}let u;if(o("Application created successfully"),y)u=!1,o("CI mode (--subdomain), skipping pull");else{u=(await e.prompt([{type:"confirm",name:"pull",message:"Pull the application locally?",default:!0}])).pull,o(`User chose to pull: ${u}`)}if(u){o("Running pull flow");try{const e=new c;await e.execute()}catch(k){if(s(k),k instanceof Error&&k.message.startsWith("EXIT:"))throw k;if(n(k))return void console.log(t.yellow(l));console.error(t.red("Failed to pull application."))}}else console.log(t.green("Application is created successfully. Run 'dashnex app pull' to pull it to your computer or 'dashnex app deploy' to deploy it to the cloud."))}catch(k){if(h.stop(),s(k),k instanceof Error&&k.message.startsWith("EXIT:"))throw k;if(n(k))return void console.log(t.yellow(l));console.error(t.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}}export{d as CreateCommand};
@@ -1 +1 @@
1
- import e from"inquirer";import t from"chalk";import{debug as o,debugError as s}from"../../lib/debug.js";import{getBusinessApiBase as r}from"../../lib/api.js";import{ensureLoggedIn as i}from"../../services/auth.js";import{createSpinner as n}from"../../lib/spinner.js";import{isUserInterrupt as a,INTERRUPTED_MESSAGE as c}from"../../lib/errors.js";class l{async execute(){o("Delete flow started");const{confirm:l}=await e.prompt([{type:"confirm",name:"confirm",message:"Are you sure you want to delete this application? This action cannot be undone.",default:!1}]);if(!l)return o("User cancelled deletion"),void console.log(t.yellow("Deletion cancelled."));const p=await i();if(!p)return;const d=`${r()}/business/v1/applications`;o(`DELETE ${d}`);const f=n();f.start("Deleting application...");try{const e=await fetch(d,{method:"DELETE",headers:{Authorization:`Bearer ${p.token}`}});if(f.stop(),o(`Response: ${e.status}`),!e.ok){const o=e.headers.get("content-type")??"";let s="Failed to delete application.";if(401===e.status||403===e.status)s="Please run 'dashnex login' to authenticate.";else if(o.includes("application/json")){const t=(e=>"string"==typeof e.error?e.error:"string"==typeof e.message?e.message:void 0)(await e.json().catch(()=>({})));t&&(s=t)}console.error(t.red(s)),process.exit(1)}const s=await e.json().catch(()=>({})),r="string"==typeof s.message?s.message:"Application deleted successfully.";o("Application deleted successfully"),console.log(t.green(r))}catch(m){if(f.stop(),s(m),m instanceof Error&&m.message.startsWith("EXIT:"))throw m;if(a(m))return void console.log(t.yellow(c));console.error(t.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}}export{l as DeleteCommand};
1
+ import e from"inquirer";import t from"chalk";import{debug as o,debugError as s}from"../../lib/debug.js";import{getBusinessApiBase as r}from"../../lib/api.js";import{ensureLoggedIn as i}from"../../services/auth.js";import{createSpinner as n}from"../../lib/spinner.js";import{isUserInterrupt as a,INTERRUPTED_MESSAGE as c}from"../../lib/errors.js";class l{async execute(l={}){if(o("Delete flow started"),!l.yes){const{confirm:s}=await e.prompt([{type:"confirm",name:"confirm",message:"Are you sure you want to delete this application? This action cannot be undone.",default:!1}]);if(!s)return o("User cancelled deletion"),void console.log(t.yellow("Deletion cancelled."))}const p=await i();if(!p)return;const f=`${r()}/business/v1/applications`;o(`DELETE ${f}`);const d=n();d.start("Deleting application...");try{const e=await fetch(f,{method:"DELETE",headers:{Authorization:`Bearer ${p.token}`}});if(d.stop(),o(`Response: ${e.status}`),!e.ok){const o=e.headers.get("content-type")??"";let s="Failed to delete application.";if(401===e.status||403===e.status)s="Please run 'dashnex login' to authenticate.";else if(o.includes("application/json")){const t=(e=>"string"==typeof e.error?e.error:"string"==typeof e.message?e.message:void 0)(await e.json().catch(()=>({})));t&&(s=t)}console.error(t.red(s)),process.exit(1)}const s=await e.json().catch(()=>({})),r="string"==typeof s.message?s.message:"Application deleted successfully.";o("Application deleted successfully"),console.log(t.green(r))}catch(m){if(d.stop(),s(m),m instanceof Error&&m.message.startsWith("EXIT:"))throw m;if(a(m))return void console.log(t.yellow(c));console.error(t.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}}export{l as DeleteCommand};
@@ -1 +1 @@
1
- import e from"chalk";import{debug as t,debugError as o}from"../../lib/debug.js";import{getDeployerBase as s}from"../../lib/api.js";import{ensureLoggedIn as r}from"../../services/auth.js";import{createSpinner as n}from"../../lib/spinner.js";import{isUserInterrupt as a,INTERRUPTED_MESSAGE as i}from"../../lib/errors.js";const c=3e5,l=99,p=e=>new Promise(t=>setTimeout(t,e)),d=async(s,r,n,a)=>{const i=await fetch(s,{method:"GET",headers:{Authorization:`Bearer ${r}`,Accept:"text/event-stream"}});if(t(`SSE connection opened: ${i.status}`),!i.ok){const t=i.status;let o="Failed to start deployment.";if(401===t||403===t)o="Please run 'dashnex login' to authenticate.";else try{const e=await i.text(),t=JSON.parse(e);"string"==typeof t.error?o=t.error:"string"==typeof t.message&&(o=t.message)}catch{}throw console.error(e.red(o)),new Error(`HTTP ${t}: ${o}`)}if(!i.body)throw new Error("Response body is null");t("SSE connection established successfully"),a?.();const c=i.body.getReader();try{for await(const e of async function*(e){const t=new TextDecoder("utf-8");let o="";for(;;){const{value:s,done:r}=await e.read();if(r)break;o+=t.decode(s,{stream:!0});const n=o.split("\n");o=n.pop()||"";let a="";for(const e of n)e.startsWith("data: ")?a=e.slice(6):""===e&&a&&(yield{data:a},a="")}if(o.startsWith("data: ")){const e=o.slice(6);e&&(yield{data:e})}}(c))try{if(!e.data){t("Received empty SSE event");continue}const o=JSON.parse(e.data);t(`SSE message received: ${JSON.stringify(o)}`),n(o)}catch(l){o(l),t(`Failed to parse SSE event data: ${e.data}`)}}finally{c.releaseLock()}};class f{async execute(){t("Deploy flow started");const f=await r();if(!f)return;const m=`${s()}/business/v1/applications/deploy`;t(`GET ${m} (SSE)`);let y=0,u="",g=!1,h=0,w=!1;const S=n();let $=0,v=0,x=null;const b=(e,t)=>{const o=Math.round(e);S.text(`[${o}%] ${t}`)},E=()=>{D();const e=y,t=Date.now(),o=c*((l-e)/l);x=setInterval(()=>{const s=Date.now()-t;let r;if(v>t){const e=Date.now()-v,t=l-$,o=t*3030.3030303030305;r=Math.min($+e/o*t,l)}else r=Math.min(e+s/o*(l-e),l);r>y&&(y=r,b(y,u))},200)},D=()=>{x&&(clearInterval(x),x=null)};let T=!1;const M=t=>{if(w=!0,"string"==typeof t.error)return D(),S.stop(),console.error(e.red(t.error)),g=!0,void(T=!0);if("string"==typeof t.message&&(u=t.message),"number"==typeof t.progress&&($=t.progress,v=Date.now(),t.progress>y&&(y=t.progress)),"string"==typeof t.message||"number"==typeof t.progress)if(y>=100){D(),S.stop();const t=u||"Application is deployed";process.stdout.write(`${e.green(t)}\n`),g=!0}else b(y,u)};for(;h<=5;)try{return w?b(y,u):S.start("Connecting..."),E(),await d(m,f.token,M,()=>{w||(S.text(`[${Math.round(y)}%] Deployment in progress...`),u="Deployment in progress...")}),D(),S.stop(),t("SSE connection closed"),void(T&&process.exit(1))}catch(k){if(D(),o(k),t(`SSE connection error: ${k}`),g)return S.stop(),void(T&&process.exit(1));if(a(k))return S.stop(),void console.log(e.yellow(i));k instanceof Error&&k.message.startsWith("HTTP")&&(S.stop(),console.error(e.red("Could not complete deployment. Check your connection and try again.")),process.exit(1)),h++,h>5&&(S.stop(),console.error(e.red("Deployment failed. Maximum reconnection attempts exceeded.")),process.exit(1));const s=Math.min(1e3*Math.pow(2,h-1),3e4);t(`Connection error. Reconnecting in ${s/1e3}s... (attempt ${h}/5)`),await p(s)}}}export{f as DeployCommand};
1
+ import e from"chalk";import{debug as t,debugError as o}from"../../lib/debug.js";import{getDeployerBase as s,getBusinessApiBase as r}from"../../lib/api.js";import{ensureLoggedIn as n}from"../../services/auth.js";import{createSpinner as a}from"../../lib/spinner.js";import{isUserInterrupt as i,INTERRUPTED_MESSAGE as c}from"../../lib/errors.js";import{getApplicationUrl as l}from"../../lib/app-url.js";const p=3e5,d=99,m=e=>new Promise(t=>setTimeout(t,e)),f=async(s,r,n,a)=>{const i=await fetch(s,{method:"GET",headers:{Authorization:`Bearer ${r}`,Accept:"text/event-stream"}});if(t(`SSE connection opened: ${i.status}`),!i.ok){const t=i.status;let o="Failed to start deployment.";if(401===t||403===t)o="Please run 'dashnex login' to authenticate.";else try{const e=await i.text(),t=JSON.parse(e);"string"==typeof t.error?o=t.error:"string"==typeof t.message&&(o=t.message)}catch{}throw console.error(e.red(o)),new Error(`HTTP ${t}: ${o}`)}if(!i.body)throw new Error("Response body is null");t("SSE connection established successfully"),a?.();const c=i.body.getReader();try{for await(const e of async function*(e){const t=new TextDecoder("utf-8");let o="";for(;;){const{value:s,done:r}=await e.read();if(r)break;o+=t.decode(s,{stream:!0});const n=o.split("\n");o=n.pop()||"";let a="";for(const e of n)e.startsWith("data: ")?a=e.slice(6):""===e&&a&&(yield{data:a},a="")}if(o.startsWith("data: ")){const e=o.slice(6);e&&(yield{data:e})}}(c))try{if(!e.data){t("Received empty SSE event");continue}const o=JSON.parse(e.data);t(`SSE message received: ${JSON.stringify(o)}`),n(o)}catch(l){o(l),t(`Failed to parse SSE event data: ${e.data}`)}}finally{c.releaseLock()}};class u{async execute(){t("Deploy flow started");const r=await n();if(!r)return;const l=`${s()}/business/v1/applications/deploy`;t(`GET ${l} (SSE)`);let u=0,y="",h=!1,g=0,w=!1;const S=a();let $=0,b=0,v=null;const x=(e,t)=>{const o=Math.round(e);S.text(`[${o}%] ${t}`)},E=()=>{D();const e=u,t=Date.now(),o=p*((d-e)/d);v=setInterval(()=>{const s=Date.now()-t;let r;if(b>t){const e=Date.now()-b,t=d-$,o=t*3030.3030303030305;r=Math.min($+e/o*t,d)}else r=Math.min(e+s/o*(d-e),d);r>u&&(u=r,x(u,y))},200)},D=()=>{v&&(clearInterval(v),v=null)};let T=!1;const k=t=>{if(w=!0,"string"==typeof t.error)return D(),S.stop(),console.error(e.red(t.error)),h=!0,void(T=!0);if("string"==typeof t.message&&(y=t.message),"number"==typeof t.progress&&($=t.progress,b=Date.now(),t.progress>u&&(u=t.progress)),"string"==typeof t.message||"number"==typeof t.progress)if(u>=100){D(),S.stop();const t=y||"Application is deployed";process.stdout.write(`${e.green(t)}\n`),h=!0}else x(u,y)};for(;g<=5;)try{return w?x(u,y):S.start("Connecting..."),E(),await f(l,r.token,k,()=>{w||(S.text(`[${Math.round(u)}%] Deployment in progress...`),y="Deployment in progress...")}),D(),S.stop(),t("SSE connection closed"),T&&process.exit(1),void(h&&await this.showDeployedUrl(r.token))}catch(j){if(D(),o(j),t(`SSE connection error: ${j}`),h)return S.stop(),void(T&&process.exit(1));if(i(j))return S.stop(),void console.log(e.yellow(c));j instanceof Error&&j.message.startsWith("HTTP")&&(S.stop(),console.error(e.red("Could not complete deployment. Check your connection and try again.")),process.exit(1)),g++,g>5&&(S.stop(),console.error(e.red("Deployment failed. Maximum reconnection attempts exceeded.")),process.exit(1));const s=Math.min(1e3*Math.pow(2,g-1),3e4);t(`Connection error. Reconnecting in ${s/1e3}s... (attempt ${g}/5)`),await m(s)}}async showDeployedUrl(s){try{const o=`${r()}/business/v1/applications`;t(`GET ${o} (for deployed URL)`);const n=await fetch(o,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)return;const a=await n.json().catch(()=>({})),i=l({subdomain:a.subdomain,appFullCustomDomain:a.appFullCustomDomain});i&&console.log(`Application is deployed to ${e.cyan(i)}`)}catch(n){o(n)}}}export{u as DeployCommand};
@@ -1 +1 @@
1
- import{CreateCommand as e}from"./create.js";import{PullCommand as a}from"./pull.js";import{PushCommand as t}from"./push.js";import{DeleteCommand as o}from"./delete.js";import{DeployCommand as n}from"./deploy.js";import{StatusCommand as p}from"./status.js";const i={name:"app",description:"Manage DashNex applications",handler:{execute:async()=>{}},options:[],subcommands:[{name:"create",description:"Create a new DashNex application",handler:new e,options:[{flags:"-t, --template <template>",description:"Template (name@branch-or-tag)",defaultValue:"webapp-base@live"}]},{name:"pull",description:"Pull existing application to specified folder",handler:new a,options:[]},{name:"push",description:"Push local application to DashNex",handler:new t,options:[]},{name:"delete",description:"Delete application from DashNex",handler:new o,options:[]},{name:"deploy",description:"Deploy application to DashNex",handler:new n,options:[]},{name:"status",description:"Show current application status",handler:new p,options:[]}]};export{i as default};
1
+ import{CreateCommand as e}from"./create.js";import{PullCommand as o}from"./pull.js";import{PushCommand as p}from"./push.js";import{DeleteCommand as a}from"./delete.js";import{DeployCommand as t}from"./deploy.js";import{StatusCommand as i}from"./status.js";const s={name:"app",description:"Manage DashNex applications",handler:{execute:async()=>{}},options:[],subcommands:[{name:"create",description:"Create a new DashNex application",handler:new e,options:[{flags:"-t, --template <template>",description:"Template (name@branch-or-tag)",defaultValue:"webapp-base@live"},{flags:"--subdomain <subdomain>",description:"Subdomain (CI mode, skip prompts)"}]},{name:"pull",description:"Pull existing application to specified folder",handler:new o,options:[{flags:"-y, --yes",description:"Skip prompts and child commands (CI mode)"}]},{name:"push",description:"Push local application to DashNex",handler:new p,options:[{flags:"--deploy",description:"Auto-deploy after push (skip prompt)"},{flags:"--no-deploy",description:"Skip deploy prompt"}]},{name:"delete",description:"Delete application from DashNex",handler:new a,options:[{flags:"-y, --yes",description:"Skip confirmation prompt"}]},{name:"deploy",description:"Deploy application to DashNex",handler:new t,options:[]},{name:"status",description:"Show current application status",handler:new i,options:[]}]};export{s as default};
@@ -1 +1 @@
1
- import e from"chalk";import t from"fs-extra";import o from"path";import r from"os";import{spawn as i}from"child_process";import n from"inquirer";import a from"adm-zip";import{debug as s,debugError as l}from"../../lib/debug.js";import{getBusinessApiBase as c}from"../../lib/api.js";import{ensureLoggedIn as d}from"../../services/auth.js";import{createSpinner as p}from"../../lib/spinner.js";import{isUserInterrupt as m,INTERRUPTED_MESSAGE as f}from"../../lib/errors.js";const u=(e,t)=>new Promise((o,r)=>{const n=i(t,{cwd:e,shell:!0,stdio:"inherit"});n.on("error",e=>{l(e),r(e)}),n.on("close",e=>{o(null===e?0:e)})}),g=async(t,r)=>{const{install:a}=await n.prompt([{type:"confirm",name:"install",message:"Install dependencies?",default:!0}]);if(!a){if(o.resolve(t)!==o.resolve(r)){const i=o.relative(r,t);console.log(e.cyan(`Run "cd ${i}" to change to the application folder.`))}return}if(a){const o=await(async()=>{const e=e=>new Promise(t=>{const o=i(e,["--version"],{stdio:"ignore",shell:!0});o.on("error",()=>t(!1)),o.on("close",e=>t(0===e))});return await e("pnpm")?"pnpm":(await e("npm"),"npm")})();s(`Running ${o} install in ${t}`);try{const e=await u(t,`${o} install`);if(0!==e)return void s(`${o} install exited with code ${e}`)}catch(p){return l(p),void console.error(e.red(`Failed to run ${o} install.`))}}const{migrate:c}=await n.prompt([{type:"confirm",name:"migrate",message:"Create local database?",default:!0}]);if(c){s(`Running dashnex db migrate in ${t}`);try{const e=await u(t,"dashnex db migrate");if(0!==e)return void s(`dashnex db migrate exited with code ${e}`)}catch(p){return l(p),void console.error(e.red("Failed to run dashnex db migrate."))}}const{dev:d}=await n.prompt([{type:"confirm",name:"dev",message:"Run development server?",default:!0}]);if(d){s(`Running npm run dev in ${t}`);try{await u(t,"npm run dev")}catch(p){l(p),console.error(e.red("Failed to run dev server."))}}},h='Application is successfully pulled. Run "npm install" or "pnpm install" to install dependencies and then "dashnex dev" to run it';class w{async execute(i={}){s("Pull flow started");const u=await d();if(!u)return;const w=process.cwd();let v;if(i.folder)v=i.folder.trim()||".",s(`Folder argument provided: ${v}`);else{s("No folder argument, prompting user");const{folder:e}=await n.prompt([{type:"input",name:"folder",message:"Which folder to pull the application to?",default:"."}]);v=e.trim()||"."}const y=o.resolve(w,v);s(`Target folder resolved: ${y}`);const x=await t.pathExists(y);let $=!1;if(x)try{$=(await t.readdir(y)).length>0,s(`Folder exists: ${x}, has files: ${$}`)}catch(R){s(`Error reading folder: ${R}`)}if($){const{confirm:t}=await n.prompt([{type:"confirm",name:"confirm",message:"Existing files will be overwritten. Continue?",default:!0}]);if(!t)return s("User declined confirmation, exiting"),void console.log(e.yellow("Pull cancelled."));s("User confirmed overwrite")}await t.ensureDir(y),s(`Target folder ensured: ${y}`);const b=`${c()}/business/v1/cli/pull`;s(`GET ${b}`);const j=o.join(r.tmpdir(),`dashnex-pull-${Date.now()}-${Math.random().toString(36).slice(2)}.zip`),E=p();E.start("Pulling application...");try{const r=await fetch(b,{headers:{Authorization:`Bearer ${u.token}`}});if(s(`Response: ${r.status}`),!r.ok){E.stop();const t=r.headers.get("content-type")??"";let o="Failed to pull application.";if(401===r.status||403===r.status)o="Please run 'dashnex login' to authenticate.";else if(404===r.status)o="Business has no application. Run 'dashnex app create' to create one.";else if(t.includes("application/json")){const e=(e=>"string"==typeof e.error?e.error:"string"==typeof e.message?e.message:void 0)(await r.json().catch(()=>({})));e&&(o=e)}console.error(e.red(o)),process.exit(1)}E.text("Downloading...");const i=Buffer.from(await r.arrayBuffer());await t.writeFile(j,i),s("Zip written to temp file"),E.text("Extracting...");new a(j).extractAllTo(y,!0),E.stop(),s("Extracted to target folder"),o.resolve(y)!==o.resolve(w)?(console.log(e.green(((e,t)=>o.resolve(e)===o.resolve(t)?h:`Application is successfully pulled into ${o.relative(t,e)}.`)(y,w))),process.chdir(y),s(`Changed working directory to ${y}`)):console.log(e.green(h)),await g(y,w)}catch(R){if(E.stop(),l(R),R instanceof Error&&R.message.startsWith("EXIT:"))throw R;if(m(R))return void console.log(e.yellow(f));console.error(e.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}finally{await t.remove(j).catch(()=>{}),s("Temp zip removed")}}}export{w as PullCommand};
1
+ import e from"chalk";import t from"fs-extra";import o from"path";import r from"os";import{spawn as i}from"child_process";import n from"inquirer";import s from"adm-zip";import{debug as a,debugError as l}from"../../lib/debug.js";import{getBusinessApiBase as c}from"../../lib/api.js";import{ensureLoggedIn as d}from"../../services/auth.js";import{createSpinner as p}from"../../lib/spinner.js";import{isUserInterrupt as m,INTERRUPTED_MESSAGE as f}from"../../lib/errors.js";const u=(e,t)=>new Promise((o,r)=>{const n=i(t,{cwd:e,shell:!0,stdio:"inherit"});n.on("error",e=>{l(e),r(e)}),n.on("close",e=>{o(null===e?0:e)})}),g=async(t,r)=>{const{install:s}=await n.prompt([{type:"confirm",name:"install",message:"Install dependencies?",default:!0}]);if(!s){if(o.resolve(t)!==o.resolve(r)){const i=o.relative(r,t);console.log(e.cyan(`Run "cd ${i}" to change to the application folder.`))}return}const c=await(async()=>{const e=e=>new Promise(t=>{const o=i(e,["--version"],{stdio:"ignore",shell:!0});o.on("error",()=>t(!1)),o.on("close",e=>t(0===e))});return await e("pnpm")?"pnpm":(await e("npm"),"npm")})();a(`Running ${c} install in ${t}`);try{const e=await u(t,`${c} install`);if(0!==e)return void a(`${c} install exited with code ${e}`)}catch(m){return l(m),void console.error(e.red(`Failed to run ${c} install.`))}const{migrate:d}=await n.prompt([{type:"confirm",name:"migrate",message:"Create local database?",default:!0}]);if(d){a(`Running dashnex db migrate in ${t}`);try{const e=await u(t,"dashnex db migrate");if(0!==e)return void a(`dashnex db migrate exited with code ${e}`)}catch(m){return l(m),void console.error(e.red("Failed to run dashnex db migrate."))}}const{dev:p}=await n.prompt([{type:"confirm",name:"dev",message:"Run development server?",default:!0}]);if(p){a(`Running npm run dev in ${t}`);try{await u(t,"npm run dev")}catch(m){l(m),console.error(e.red("Failed to run dev server."))}}},h='Application is successfully pulled. Run "npm install" or "pnpm install" to install dependencies and then "dashnex dev" to run it';class w{async execute(i={}){a("Pull flow started");const u=await d();if(!u)return;const w=process.cwd();let v;if(i.folder)v=i.folder.trim()||".",a(`Folder argument provided: ${v}`);else{a("No folder argument, prompting user");const{folder:e}=await n.prompt([{type:"input",name:"folder",message:"Which folder to pull the application to?",default:"."}]);v=e.trim()||"."}const y=o.resolve(w,v);a(`Target folder resolved: ${y}`);const x=await t.pathExists(y);let $=!1;if(x)try{$=(await t.readdir(y)).length>0,a(`Folder exists: ${x}, has files: ${$}`)}catch(R){a(`Error reading folder: ${R}`)}if($&&!i.yes){const{confirm:t}=await n.prompt([{type:"confirm",name:"confirm",message:"Existing files will be overwritten. Continue?",default:!0}]);if(!t)return a("User declined confirmation, exiting"),void console.log(e.yellow("Pull cancelled."));a("User confirmed overwrite")}await t.ensureDir(y),a(`Target folder ensured: ${y}`);const b=`${c()}/business/v1/cli/pull`;a(`GET ${b}`);const j=o.join(r.tmpdir(),`dashnex-pull-${Date.now()}-${Math.random().toString(36).slice(2)}.zip`),E=p();E.start("Pulling application...");try{const r=await fetch(b,{headers:{Authorization:`Bearer ${u.token}`}});if(a(`Response: ${r.status}`),!r.ok){E.stop();const t=r.headers.get("content-type")??"";let o="Failed to pull application.";if(401===r.status||403===r.status)o="Please run 'dashnex login' to authenticate.";else if(404===r.status)o="Business has no application. Run 'dashnex app create' to create one.";else if(t.includes("application/json")){const e=(e=>"string"==typeof e.error?e.error:"string"==typeof e.message?e.message:void 0)(await r.json().catch(()=>({})));e&&(o=e)}console.error(e.red(o)),process.exit(1)}E.text("Downloading...");const n=Buffer.from(await r.arrayBuffer());await t.writeFile(j,n),a("Zip written to temp file"),E.text("Extracting...");new s(j).extractAllTo(y,!0),E.stop(),a("Extracted to target folder"),o.resolve(y)!==o.resolve(w)?(console.log(e.green(((e,t)=>o.resolve(e)===o.resolve(t)?h:`Application is successfully pulled into ${o.relative(t,e)}.`)(y,w))),process.chdir(y),a(`Changed working directory to ${y}`)):console.log(e.green(h)),i.yes?a("CI mode (--yes), skipping post-pull child commands"):await g(y,w)}catch(R){if(E.stop(),l(R),R instanceof Error&&R.message.startsWith("EXIT:"))throw R;if(m(R))return void console.log(e.yellow(f));console.error(e.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}finally{await t.remove(j).catch(()=>{}),a("Temp zip removed")}}}export{w as PullCommand};
@@ -1 +1 @@
1
- import e from"chalk";import t from"fs-extra";import o from"path";import i from"os";import s from"adm-zip";import r from"ignore";import n from"inquirer";import{debug as a,debugError as c}from"../../lib/debug.js";import{getBusinessApiBase as p}from"../../lib/api.js";import{ensureLoggedIn as l}from"../../services/auth.js";import{createSpinner as d}from"../../lib/spinner.js";import{isUserInterrupt as m,INTERRUPTED_MESSAGE as f}from"../../lib/errors.js";import{DeployCommand as h}from"./deploy.js";const u=[".dashnex",".git"],w=async(e,i)=>{const s=[],r=await t.readdir(e,{withFileTypes:!0});for(const t of r){const r=o.relative(process.cwd(),o.join(e,t.name)).split(o.sep).join("/");if(u.some(e=>r===e||r.startsWith(`${e}/`)))continue;if(i.ignores(r))continue;const n=o.join(e,t.name);if(t.isDirectory()){const e=await w(n,i);s.push(...e)}else t.isFile()&&s.push(n)}return s};class g{async execute(){a("Push flow started");const g=await l();if(!g)return;const y=process.cwd(),j=o.join(y,".gitignore"),x=r();if(x.add(u),await t.pathExists(j)){const e=await t.readFile(j,"utf8");x.add(e)}a("Building file list");const $=await w(y,x);a(`Including ${$.length} files`);const b=new s;for(const e of $){const t=o.relative(y,e).split(o.sep).join("/"),i="."===o.dirname(t)?"":o.dirname(t),s=o.basename(t);b.addLocalFile(e,i,s)}const v=o.join(i.tmpdir(),`dashnex-push-${Date.now()}-${Math.random().toString(36).slice(2)}.zip`),F=d();try{F.start("Packaging application..."),b.writeZip(v),a(`Zip written to ${v}`);const o=`${p()}/business/v1/cli/push`;a(`POST ${o}`);const i=await t.readFile(v),s=new Blob([i],{type:"application/zip"}),r=new FormData;r.append("file",s,"archive.zip");const c=new Headers;c.set("Authorization",`Bearer ${g.token}`),F.text("Uploading...");const l=await fetch(o,{method:"POST",headers:c,body:r});if(F.stop(),a(`Response: ${l.status}`),!l.ok){const t=l.headers.get("content-type")??"";let o="Failed to push application.";if(401===l.status||403===l.status)o="Please run 'dashnex login' to authenticate.";else if(t.includes("application/json")){const e=(e=>"string"==typeof e.error?e.error:"string"==typeof e.message?e.message:void 0)(await l.json().catch(()=>({})));e&&(o=e)}console.error(e.red(o)),process.exit(1)}console.log(e.green("Application pushed successfully."));const{deploy:d}=await n.prompt([{type:"confirm",name:"deploy",message:"Deploy the application?",default:!0}]);if(a(`User chose to deploy: ${d}`),d){a("Running deploy flow");const e=new h;await e.execute()}}catch(z){if(F.stop(),c(z),z instanceof Error&&z.message.startsWith("EXIT:"))throw z;if(m(z))return void console.log(e.yellow(f));console.error(e.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}finally{await t.remove(v).catch(()=>{}),a("Temp zip removed")}}}export{g as PushCommand};
1
+ import e from"chalk";import o from"fs-extra";import t from"path";import i from"os";import s from"adm-zip";import r from"ignore";import a from"inquirer";import{debug as n,debugError as p}from"../../lib/debug.js";import{getBusinessApiBase as c}from"../../lib/api.js";import{ensureLoggedIn as l}from"../../services/auth.js";import{createSpinner as d}from"../../lib/spinner.js";import{isUserInterrupt as m,INTERRUPTED_MESSAGE as f}from"../../lib/errors.js";import{DeployCommand as h}from"./deploy.js";const u=[".dashnex",".git",".next",".wrangler"],g=async(e,i)=>{const s=[],r=await o.readdir(e,{withFileTypes:!0});for(const o of r){const r=t.relative(process.cwd(),t.join(e,o.name)).split(t.sep).join("/");if(u.some(e=>r===e||r.startsWith(`${e}/`)))continue;if(i.ignores(r))continue;const a=t.join(e,o.name);if(o.isDirectory()){const e=await g(a,i);s.push(...e)}else o.isFile()&&s.push(a)}return s};class w{async execute(w={}){n("Push flow started");const y=await l();if(!y)return;const j=process.cwd(),x=t.join(j,".gitignore"),v=r();if(v.add(u),await o.pathExists(x)){const e=await o.readFile(x,"utf8");v.add(e)}n("Building file list");const $=await g(j,v);n(`Including ${$.length} files`);const b=new s;for(const e of $){const o=t.relative(j,e).split(t.sep).join("/"),i="."===t.dirname(o)?"":t.dirname(o),s=t.basename(o);b.addLocalFile(e,i,s)}const F=t.join(i.tmpdir(),`dashnex-push-${Date.now()}-${Math.random().toString(36).slice(2)}.zip`),z=d();try{z.start("Packaging application..."),b.writeZip(F),n(`Zip written to ${F}`);const t=`${c()}/business/v1/cli/push`;n(`POST ${t}`);const i=await o.readFile(F),s=new Blob([i],{type:"application/zip"}),r=new FormData;r.append("file",s,"archive.zip");const p=new Headers;p.set("Authorization",`Bearer ${y.token}`),z.text("Uploading...");const l=await fetch(t,{method:"POST",headers:p,body:r});if(z.stop(),n(`Response: ${l.status}`),!l.ok){const o=l.headers.get("content-type")??"";let t="Failed to push application.";if(401===l.status||403===l.status)t="Please run 'dashnex login' to authenticate.";else if(o.includes("application/json")){const e=(e=>"string"==typeof e.error?e.error:"string"==typeof e.message?e.message:void 0)(await l.json().catch(()=>({})));e&&(t=e)}console.error(e.red(t)),process.exit(1)}let d;if(console.log(e.green("Application pushed successfully.")),void 0!==w.deploy)d=w.deploy,n(`Deploy decided via flag: ${d}`);else{d=(await a.prompt([{type:"confirm",name:"deploy",message:"Deploy the application?",default:!0}])).deploy,n(`User chose to deploy: ${d}`)}if(d){n("Running deploy flow");const e=new h;await e.execute()}}catch(D){if(z.stop(),p(D),D instanceof Error&&D.message.startsWith("EXIT:"))throw D;if(m(D))return void console.log(e.yellow(f));console.error(e.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}finally{await o.remove(F).catch(()=>{}),n("Temp zip removed")}}}export{w as PushCommand};
@@ -1 +1 @@
1
- import t from"chalk";import{debug as o,debugError as s}from"../../lib/debug.js";import{getBusinessApiBase as e}from"../../lib/api.js";import{ensureLoggedIn as a}from"../../services/auth.js";import{createSpinner as n}from"../../lib/spinner.js";import{isUserInterrupt as r,INTERRUPTED_MESSAGE as i}from"../../lib/errors.js";class c{async execute(){o("Status flow started");const c=await a();if(!c)return;const l=`${e()}/business/v1/applications`;o(`GET ${l}`);const p=n();p.start("Fetching application status...");try{const s=await fetch(l,{headers:{Authorization:`Bearer ${c.token}`}});if(p.stop(),o(`Response: ${s.status}`),404===s.status)return void console.log(t.yellow("Application not created"));if(!s.ok){const o=s.headers.get("content-type")??"";let e="Failed to fetch application status.";if(401===s.status||403===s.status)e="Please run 'dashnex login' to authenticate.";else if(o.includes("application/json")){const t=await s.json().catch(()=>({}));"string"==typeof t.error?e=t.error:"string"==typeof t.message&&(e=t.message)}console.error(t.red(e)),process.exit(1)}const e=await s.json().catch(()=>({}));o(`Application body: ${JSON.stringify(e)}`);const a=e.status??"unknown";console.log(`Status: ${t.cyan(a)}`);const n=(t=>t.appFullCustomDomain?t.appFullCustomDomain:t.subdomain?"qa"===(process.env.APPLICATION_ENV??"")?`https://${t.subdomain}.dashnex.dev`:`https://${t.subdomain}.dashnexcloud.com`:null)(e);n&&console.log(`URL: ${t.cyan(n)}`)}catch(u){if(p.stop(),s(u),u instanceof Error&&u.message.startsWith("EXIT:"))throw u;if(r(u))return void console.log(t.yellow(i));console.error(t.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}}export{c as StatusCommand};
1
+ import t from"chalk";import{debug as o,debugError as s}from"../../lib/debug.js";import{getBusinessApiBase as e}from"../../lib/api.js";import{ensureLoggedIn as r}from"../../services/auth.js";import{createSpinner as a}from"../../lib/spinner.js";import{isUserInterrupt as n,INTERRUPTED_MESSAGE as i}from"../../lib/errors.js";import{getApplicationUrl as c}from"../../lib/app-url.js";class l{async execute(){o("Status flow started");const l=await r();if(!l)return;const p=`${e()}/business/v1/applications`;o(`GET ${p}`);const u=a();u.start("Fetching application status...");try{const s=await fetch(p,{headers:{Authorization:`Bearer ${l.token}`}});if(u.stop(),o(`Response: ${s.status}`),404===s.status)return void console.log(t.yellow("Application not created"));if(!s.ok){const o=s.headers.get("content-type")??"";let e="Failed to fetch application status.";if(401===s.status||403===s.status)e="Please run 'dashnex login' to authenticate.";else if(o.includes("application/json")){const t=await s.json().catch(()=>({}));"string"==typeof t.error?e=t.error:"string"==typeof t.message&&(e=t.message)}console.error(t.red(e)),process.exit(1)}const e=await s.json().catch(()=>({}));o(`Application body: ${JSON.stringify(e)}`);const r=e.status??"unknown";console.log(`Status: ${t.cyan(r)}`);const a=c(e);a&&console.log(`URL: ${t.cyan(a)}`)}catch(f){if(u.stop(),s(f),f instanceof Error&&f.message.startsWith("EXIT:"))throw f;if(n(f))return void console.log(t.yellow(i));console.error(t.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}}export{l as StatusCommand};
@@ -1 +1 @@
1
- import e from"./version.js";import{LoginCommand as o}from"./login.js";import{LogoutCommand as n}from"./logout.js";import{WhoamiCommand as i}from"./whoami.js";import{InstallCommand as s}from"./install.js";import{DevCommand as r}from"./dev.js";import{SelectCommand as t}from"./select.js";import p from"./app/index.js";const a=[{name:"version",description:"Display the version of the CLI",handler:new e,options:[]},{name:"login",description:"Log in to your DashNex account",handler:new o,options:[]},{name:"logout",description:"Log out and remove local credentials",handler:new n,options:[]},{name:"whoami",description:"Show current logged-in business and user",handler:new i,options:[]},p,{name:"install",description:"Install dependencies using pnpm or npm",handler:new s,options:[]},{name:"dev",description:"Run the development server",handler:new r,options:[]},{name:"select",description:"Switch to a different business",handler:new t,options:[]}];export{a as default};
1
+ import o from"./version.js";import{LoginCommand as e}from"./login.js";import{LogoutCommand as s}from"./logout.js";import{WhoamiCommand as n}from"./whoami.js";import{InstallCommand as i}from"./install.js";import{DevCommand as r}from"./dev.js";import p from"./app/index.js";const t=[{name:"version",description:"Display the version of the CLI",handler:new o,options:[]},{name:"login",description:"Log in to your DashNex account",handler:new e,options:[{flags:"--email <email>",description:"Email address (skip prompt)"},{flags:"--password <password>",description:"Password (skip prompt)"},{flags:"--code <code>",description:"2FA code (skip prompt)"},{flags:"--business <id>",description:"Business ID to select (skip prompt)"}]},{name:"logout",description:"Log out and remove local credentials",handler:new s,options:[]},{name:"whoami",description:"Show current logged-in business and user",handler:new n,options:[]},p,{name:"install",description:"Install dependencies using pnpm or npm",handler:new i,options:[]},{name:"dev",description:"Run the development server",handler:new r,options:[]}];export{t as default};
@@ -1 +1 @@
1
- import e from"inquirer";import s from"chalk";import r from"fs-extra";import t from"path";import{debug as o,debugJson as n,debugError as a}from"../lib/debug.js";import{getApiBase as i,apiFetch as c}from"../lib/api.js";import{ensureLoggedIn as u}from"../services/auth.js";import{createSpinner as l}from"../lib/spinner.js";import{isUserInterrupt as d,INTERRUPTED_MESSAGE as m}from"../lib/errors.js";const p=(e,r,t)=>{const o=(e=>"string"==typeof e.error?e.error:"string"==typeof e.message?e.message:void 0)(r);let n=t;429===e.status?n="Too many requests. Please wait a moment and try again.":e.status>=500?n="DashNex API is temporarily unavailable. Please try again later.":o&&(n=o),console.error(s.red(n)),process.exit(1)};class h{async execute(){o("Login flow started");const r=process.cwd(),h=t.join(r,".dashnex"),f=await u({exitOnFailure:!1,dashnexPath:h});if(f)console.log(s.green(`Already logged in as ${f.userName??"user"}`));else try{const{username:r,password:t}=await e.prompt([{type:"input",name:"username",message:"Email:",validate:e=>!!e.trim()||"Email is required"},{type:"password",name:"password",message:"Password:",mask:"*",validate:e=>!!e||"Password is required"}]),u=r.trim();o("Email provided");const d=l();d.start("Logging in..."),o(`POST ${i()}/auth/v1/login`);const{response:m,body:f}=await c(`${i()}/auth/v1/login`,{method:"POST",body:JSON.stringify({username:u,password:t})});d.stop(),o(`Response: ${m.status}`),n("Login response",f),m.ok||(a(new Error(`Login failed: ${m.status} ${JSON.stringify(f)}`)),401===m.status&&(console.error(s.red("Invalid username or password.")),process.exit(1)),p(m,f,"Login failed. Please try again."));const g=f;if(g.two_fa_required&&g.token){o(`2FA required, type: ${g.type||"unknown"}`);const e=await this.handle2FA(g.token,g.type);e||process.exit(1),await this.completeLogin(e,h)}else g.token&&g.refreshToken?await this.completeLogin({token:g.token,refreshToken:g.refreshToken},h):(console.error(s.red("Invalid response from server. Please try again.")),process.exit(1))}catch(g){if(a(g),d(g))return void console.log(s.yellow(m));console.error(s.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}async handle2FA(r,t){if("sms"===t){o(`POST ${i()}/auth/v1/two-fa/sms`);try{const{response:e}=await c(`${i()}/auth/v1/two-fa/sms`,{method:"POST",headers:{Authorization:`Bearer ${r}`},body:JSON.stringify({})});o(`Response: ${e.status}`)}catch(l){return a(l),console.error(s.red("Could not send SMS code. Check your connection and try again.")),null}}const u="sms"===t?"Check your phone for the code":"Check your authenticator app for the code";for(let h=1;h<=3;h++){const{auth_code:t}=await e.prompt([{type:"input",name:"auth_code",message:`Enter code (${u}):`,validate:e=>!!e.trim()||"Code is required"}]);o(`POST ${i()}/auth/v1/2fa-check`);try{const{response:a,body:u}=await c(`${i()}/auth/v1/2fa-check`,{method:"POST",headers:{Authorization:`Bearer ${r}`},body:JSON.stringify({auth_code:t.trim()})});if(o(`Response: ${a.status}`),n("2FA check response",u),a.ok){const e=u;if(e.token&&e.refreshToken)return{token:e.token,refreshToken:e.refreshToken}}if(a.status>=400&&a.status<500){if(console.error(s.red("Invalid code. Please try again.")),h<3){const{retry:s}=await e.prompt([{type:"confirm",name:"retry",message:"Try again?",default:!0}]);if(!s)return null}continue}p(a,u,"2FA verification failed. Please try again.")}catch(l){return a(l),d(l)?(console.log(s.yellow(m)),null):(console.error(s.red("Could not reach DashNex API. Check your connection and try again.")),null)}}return null}async completeLogin(t,u){const d=l();d.start("Fetching businesses..."),o(`GET ${i()}/users/v1/business/my`);const{response:m,body:h}=await c(`${i()}/users/v1/business/my`,{headers:{Authorization:`Bearer ${t.token}`}});d.stop(),o(`Response: ${m.status}`),n("Businesses response",h),m.ok||(a(new Error(`Business fetch failed: ${m.status}`)),p(m,h,"Failed to fetch businesses. Please try again."));const f=this.parseBusinesses(h);let g;if(o(`Businesses: ${f.length}`),0===f.length&&(console.error(s.red("No businesses found for your account.")),process.exit(1)),1===f.length)g=f[0],o(`Selected business: ${g.id} ${g.name}`);else{const{businessId:s}=await e.prompt([{type:"select",name:"businessId",message:"Select business:",choices:f.map(e=>({name:e.name,value:e.id}))}]);g=f.find(e=>e.id===s)||f[0],o(`Selected business: ${g.id} ${g.name}`)}d.start("Switching business..."),o(`GET ${i()}/business/v1/login?_switch_business=${g.id}`);const{response:y,body:w}=await c(`${i()}/business/v1/login?_switch_business=${g.id}`,{headers:{Authorization:`Bearer ${t.token}`}});d.stop(),o(`Response: ${y.status}`),n("Business login response",w),y.ok||(a(new Error(`Business login failed: ${y.status}`)),p(y,w,"Failed to switch to business. Please try again."));const k=w;k.token&&k.refreshToken||(console.error(s.red("Invalid response from server. Please try again.")),process.exit(1));const b={token:k.token,refreshToken:k.refreshToken,businessId:g.id};await r.writeJson(u,b,{spaces:2}),o("Saved credentials to .dashnex"),this.ensureGitignore(),console.log(s.green(`Logged in as ${g.name}`))}parseBusinesses(e){const s=Array.isArray(e)?e:e.items??e.data??e.businesses??[];return Array.isArray(s)?s.map(e=>{if(e&&"object"==typeof e){const s=e,r=String(s.id??s.business_id??"").trim(),t=String(s.name??s.companyName??s.business_name??"Unknown").trim();if(r)return{id:r,name:t}}return null}).filter(e=>null!==e):[]}async ensureGitignore(){const e=t.join(process.cwd(),".gitignore");if(!(await r.pathExists(e)))return;let s=await r.readFile(e,"utf8");s.includes(".dashnex")||(s=s.trimEnd(),s.endsWith("\n")||(s+="\n"),s+="\n.dashnex\n",await r.writeFile(e,s))}}export{h as LoginCommand};
1
+ import e from"inquirer";import s from"chalk";import r from"fs-extra";import o from"path";import{debug as t,debugJson as n,debugError as i}from"../lib/debug.js";import{getApiBase as a,apiFetch as d}from"../lib/api.js";import{ensureLoggedIn as l}from"../services/auth.js";import{createSpinner as c}from"../lib/spinner.js";import{isUserInterrupt as u,INTERRUPTED_MESSAGE as p}from"../lib/errors.js";const m=(e,r,o)=>{const t=(e=>"string"==typeof e.error?e.error:"string"==typeof e.message?e.message:void 0)(r);let n=o;429===e.status?n="Too many requests. Please wait a moment and try again.":e.status>=500?n="DashNex API is temporarily unavailable. Please try again later.":t&&(n=t),console.error(s.red(n)),process.exit(1)};class h{async execute(r={}){t("Login flow started");const h=process.cwd(),f=o.join(h,".dashnex"),g=await l({exitOnFailure:!1,dashnexPath:f});if(g)console.log(s.green(`Already logged in as ${g.userName??"user"}`));else try{let o,l;if(r.email&&r.password)o=r.email.trim(),l=r.password,t("Email and password provided via flags");else{const{username:s,password:r}=await e.prompt([{type:"input",name:"username",message:"Email:",validate:e=>!!e.trim()||"Email is required"},{type:"password",name:"password",message:"Password:",mask:"*",validate:e=>!!e||"Password is required"}]);o=s.trim(),l=r}t("Email provided");const u=c();u.start("Logging in..."),t(`POST ${a()}/auth/v1/login`);const{response:p,body:h}=await d(`${a()}/auth/v1/login`,{method:"POST",body:JSON.stringify({username:o,password:l})});u.stop(),t(`Response: ${p.status}`),n("Login response",h),p.ok||(i(new Error(`Login failed: ${p.status} ${JSON.stringify(h)}`)),401===p.status&&(console.error(s.red("Invalid username or password.")),process.exit(1)),m(p,h,"Login failed. Please try again."));const g=h;if(g.two_fa_required&&g.token){t(`2FA required, type: ${g.type||"unknown"}`);const e=await this.handle2FA(g.token,g.type,r.code);e||process.exit(1),await this.completeLogin(e,f,r.business)}else g.token&&g.refreshToken?await this.completeLogin({token:g.token,refreshToken:g.refreshToken},f,r.business):(console.error(s.red("Invalid response from server. Please try again.")),process.exit(1))}catch(y){if(i(y),u(y))return void console.log(s.yellow(p));console.error(s.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}async handle2FA(r,o,l){if("sms"===o){t(`POST ${a()}/auth/v1/two-fa/sms`);try{const{response:e}=await d(`${a()}/auth/v1/two-fa/sms`,{method:"POST",headers:{Authorization:`Bearer ${r}`},body:JSON.stringify({})});t(`Response: ${e.status}`)}catch(f){return i(f),console.error(s.red("Could not send SMS code. Check your connection and try again.")),null}}const c="sms"===o?"Check your phone for the code":"Check your authenticator app for the code",h=l?1:3;for(let g=1;g<=h;g++){let o;if(l&&1===g)o=l,t("2FA code provided via flag");else{o=(await e.prompt([{type:"input",name:"auth_code",message:`Enter code (${c}):`,validate:e=>!!e.trim()||"Code is required"}])).auth_code}t(`POST ${a()}/auth/v1/2fa-check`);try{const{response:i,body:l}=await d(`${a()}/auth/v1/2fa-check`,{method:"POST",headers:{Authorization:`Bearer ${r}`},body:JSON.stringify({auth_code:o.trim()})});if(t(`Response: ${i.status}`),n("2FA check response",l),i.ok){const e=l;if(e.token&&e.refreshToken)return{token:e.token,refreshToken:e.refreshToken}}if(i.status>=400&&i.status<500){if(console.error(s.red("Invalid code. Please try again.")),g<h){const{retry:s}=await e.prompt([{type:"confirm",name:"retry",message:"Try again?",default:!0}]);if(!s)return null}continue}m(i,l,"2FA verification failed. Please try again.")}catch(f){return i(f),u(f)?(console.log(s.yellow(p)),null):(console.error(s.red("Could not reach DashNex API. Check your connection and try again.")),null)}}return null}async completeLogin(o,l,u){const p=c();p.start("Fetching businesses..."),t(`GET ${a()}/users/v1/business/my`);const{response:h,body:f}=await d(`${a()}/users/v1/business/my`,{headers:{Authorization:`Bearer ${o.token}`}});p.stop(),t(`Response: ${h.status}`),n("Businesses response",f),h.ok||(i(new Error(`Business fetch failed: ${h.status}`)),m(h,f,"Failed to fetch businesses. Please try again."));const g=this.parseBusinesses(f);let y;if(t(`Businesses: ${g.length}`),0===g.length&&(console.error(s.red("No businesses found for your account.")),process.exit(1)),u){const e=g.find(e=>e.id===u);e||(console.error(s.red(`Business "${u}" not found.`)),process.exit(1)),y=e,t(`Selected business via flag: ${y.id} ${y.name}`)}else if(1===g.length)y=g[0],t(`Selected business: ${y.id} ${y.name}`);else{const{businessId:s}=await e.prompt([{type:"select",name:"businessId",message:"Select business:",choices:g.map(e=>({name:e.name,value:e.id}))}]);y=g.find(e=>e.id===s)||g[0],t(`Selected business: ${y.id} ${y.name}`)}p.start("Switching business..."),t(`GET ${a()}/business/v1/login?_switch_business=${y.id}`);const{response:w,body:k}=await d(`${a()}/business/v1/login?_switch_business=${y.id}`,{headers:{Authorization:`Bearer ${o.token}`}});p.stop(),t(`Response: ${w.status}`),n("Business login response",k),w.ok||(i(new Error(`Business login failed: ${w.status}`)),m(w,k,"Failed to switch to business. Please try again."));const b=k;b.token&&b.refreshToken||(console.error(s.red("Invalid response from server. Please try again.")),process.exit(1));const $={token:b.token,refreshToken:b.refreshToken,businessId:y.id};await r.writeJson(l,$,{spaces:2}),t("Saved credentials to .dashnex"),this.ensureGitignore(),console.log(s.green(`Logged in as ${y.name}`))}parseBusinesses(e){const s=Array.isArray(e)?e:e.items??e.data??e.businesses??[];return Array.isArray(s)?s.map(e=>{if(e&&"object"==typeof e){const s=e,r=String(s.id??s.business_id??"").trim(),o=String(s.name??s.companyName??s.business_name??"Unknown").trim();if(r)return{id:r,name:o}}return null}).filter(e=>null!==e):[]}async ensureGitignore(){const e=o.join(process.cwd(),".gitignore");if(!(await r.pathExists(e)))return;let s=await r.readFile(e,"utf8");s.includes(".dashnex")||(s=s.trimEnd(),s.endsWith("\n")||(s+="\n"),s+="\n.dashnex\n",await r.writeFile(e,s))}}export{h as LoginCommand};
@@ -0,0 +1 @@
1
+ const n=n=>{if(n.appFullCustomDomain)return n.appFullCustomDomain;if(!n.subdomain)return null;return"qa"===(process.env.APPLICATION_ENV??"")?`https://${n.subdomain}.dashnex.dev`:`https://${n.subdomain}.dashnexcloud.com`};export{n as getApplicationUrl};
@@ -1 +1 @@
1
- const e="@dashnex/cli",a="0.5.26",n="Command-line interface for DashNex framework",o={name:e,version:a,description:n};export{o as default,n as description,e as name,a as version};
1
+ const e="@dashnex/cli",a="0.5.32",n="Command-line interface for DashNex framework",o={name:e,version:a,description:n};export{o as default,n as description,e as name,a as version};
@@ -1,6 +1,7 @@
1
1
  import { CliCommand } from '@dashnex/types';
2
2
  export interface CreateCommandOptions {
3
3
  template?: string;
4
+ subdomain?: string;
4
5
  }
5
6
  export declare class CreateCommand implements CliCommand {
6
7
  pollApplicationCreated(applicationsUrl: string, token: string, interval?: number, timeout?: number): Promise<{
@@ -1,4 +1,7 @@
1
1
  import { CliCommand } from '@dashnex/types';
2
+ export interface DeleteCommandOptions {
3
+ yes?: boolean;
4
+ }
2
5
  export declare class DeleteCommand implements CliCommand {
3
- execute(): Promise<void>;
6
+ execute(options?: DeleteCommandOptions): Promise<void>;
4
7
  }
@@ -1,4 +1,5 @@
1
1
  import { CliCommand } from '@dashnex/types';
2
2
  export declare class DeployCommand implements CliCommand {
3
3
  execute(): Promise<void>;
4
+ private showDeployedUrl;
4
5
  }
@@ -1,6 +1,8 @@
1
1
  import { CliCommand } from '@dashnex/types';
2
+ export interface PullCommandOptions {
3
+ folder?: string;
4
+ yes?: boolean;
5
+ }
2
6
  export declare class PullCommand implements CliCommand {
3
- execute(options?: {
4
- folder?: string;
5
- }): Promise<void>;
7
+ execute(options?: PullCommandOptions): Promise<void>;
6
8
  }
@@ -1,4 +1,7 @@
1
1
  import { CliCommand } from '@dashnex/types';
2
+ export interface PushCommandOptions {
3
+ deploy?: boolean;
4
+ }
2
5
  export declare class PushCommand implements CliCommand {
3
- execute(): Promise<void>;
6
+ execute(options?: PushCommandOptions): Promise<void>;
4
7
  }
@@ -1,6 +1,12 @@
1
1
  import { CliCommand } from '@dashnex/types';
2
+ export interface LoginCommandOptions {
3
+ email?: string;
4
+ password?: string;
5
+ code?: string;
6
+ business?: string;
7
+ }
2
8
  export declare class LoginCommand implements CliCommand {
3
- execute(): Promise<void>;
9
+ execute(options?: LoginCommandOptions): Promise<void>;
4
10
  private handle2FA;
5
11
  private completeLogin;
6
12
  private parseBusinesses;
@@ -0,0 +1,5 @@
1
+ export interface ApplicationInfo {
2
+ subdomain?: string;
3
+ appFullCustomDomain?: string | null;
4
+ }
5
+ export declare const getApplicationUrl: (app: ApplicationInfo) => string | null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@dashnex/cli",
4
- "version": "0.5.26",
4
+ "version": "0.5.32",
5
5
  "description": "Command-line interface for DashNex framework",
6
6
  "homepage": "https://dashnex.io",
7
7
  "type": "module",
@@ -1 +0,0 @@
1
- import e from"inquirer";import s from"chalk";import r from"fs-extra";import o from"path";import{debug as n,debugJson as t,debugError as i}from"../lib/debug.js";import{getApiBase as a,apiFetch as l}from"../lib/api.js";import{ensureLoggedIn as c}from"../services/auth.js";import{createSpinner as u}from"../lib/spinner.js";import{isUserInterrupt as d,INTERRUPTED_MESSAGE as m}from"../lib/errors.js";const p=e=>"string"==typeof e.error?e.error:"string"==typeof e.message?e.message:void 0;class f{async execute(){n("Select flow started");const f=await c();if(!f)return;const h=await(async e=>{let s=o.resolve(e);for(;;){const e=o.join(s,".dashnex");if(await r.pathExists(e))return e;const n=o.dirname(s);if(n===s)return null;s=n}})(process.cwd());if(!h)return console.error(s.red("Please run 'dashnex login' to authenticate.")),void process.exit(1);const b=u();try{b.start("Fetching businesses..."),n(`GET ${a()}/users/v1/business/my`);const{response:o,body:i}=await l(`${a()}/users/v1/business/my`,{headers:{Authorization:`Bearer ${f.token}`}});if(b.stop(),n(`Response: ${o.status}`),t("Businesses response",i),!o.ok){const e=p(i),r=o.status>=500?"DashNex API is temporarily unavailable. Please try again later.":e||"Failed to fetch businesses. Please try again.";console.error(s.red(r)),process.exit(1)}const c=(e=>{const s=Array.isArray(e)?e:e.items??e.data??e.businesses??[];return Array.isArray(s)?s.map(e=>{if(e&&"object"==typeof e){const s=e,r=String(s.id??s.business_id??"").trim(),o=String(s.name??s.companyName??s.business_name??"Unknown").trim();if(r)return{id:r,name:o}}return null}).filter(e=>null!==e):[]})(i);if(n(`Businesses: ${c.length}`),0===c.length&&(console.error(s.red("No businesses found for your account.")),process.exit(1)),1===c.length)return void console.log(s.yellow(`No other businesses available. You are on ${c[0].name}.`));const{businessId:u}=await e.prompt([{type:"select",name:"businessId",message:"Select business:",choices:c.map(e=>({name:e.id===f.businessId?`${e.name} (current)`:e.name,value:e.id}))}]),d=c.find(e=>e.id===u)||c[0];if(n(`Selected business: ${d.id} ${d.name}`),d.id===f.businessId)return void console.log(s.yellow(`Already on ${d.name}.`));b.start("Switching business..."),n(`GET ${a()}/business/v1/login?_switch_business=${d.id}`);const{response:m,body:y}=await l(`${a()}/business/v1/login?_switch_business=${d.id}`,{headers:{Authorization:`Bearer ${f.token}`}});if(b.stop(),n(`Response: ${m.status}`),t("Business login response",y),!m.ok){const e=p(y),r=m.status>=500?"DashNex API is temporarily unavailable. Please try again later.":e||"Failed to switch to business. Please try again.";console.error(s.red(r)),process.exit(1)}const g=y;g.token&&g.refreshToken||(console.error(s.red("Invalid response from server. Please try again.")),process.exit(1));const w={token:g.token,refreshToken:g.refreshToken,businessId:d.id};await r.writeJson(h,w,{spaces:2}),n("Saved credentials to .dashnex"),console.log(s.green(`Switched to ${d.name}.`))}catch(y){if(b.stop(),i(y),y instanceof Error&&y.message.startsWith("EXIT:"))throw y;if(d(y))return void console.log(s.yellow(m));console.error(s.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}}export{f as SelectCommand};
@@ -1,4 +0,0 @@
1
- import { CliCommand } from '@dashnex/types';
2
- export declare class SelectCommand implements CliCommand {
3
- execute(): Promise<void>;
4
- }