@dashnex/cli 0.5.56 → 0.5.57
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.
|
@@ -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";import{ensureAgreements as p}from"../../services/agreements.js";const u=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,d=e=>new Promise(t=>setTimeout(t,e));class m{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 d(a)}return{ready:!1}}async execute(d={}){o("Create flow started");const m=await i();if(!m)return;o("Auth valid, checking if business already has application");const h=r(),f=`${a()}/business/v1/applications`;o(`GET ${f}`),h.start("Checking application status...");try{const e=await fetch(f,{headers:{Authorization:`Bearer ${m.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(C){if(h.stop(),s(C),C instanceof Error&&C.message.startsWith("EXIT:"))throw C;if(n(C))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)}o("No existing application, checking agreements");const g=void 0!==d.subdomain;if(!(await p(m.token,{ciMode:g})))return;let y;o("Agreements checked, proceeding to subdomain prompt");const b=e=>`${a()}/business/v1/applications/check-subdomain?subdomain=${encodeURIComponent(e)}`;let
|
|
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";import{ensureAgreements as p}from"../../services/agreements.js";const u=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,d=e=>new Promise(t=>setTimeout(t,e));class m{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 d(a)}return{ready:!1}}async execute(d={}){o("Create flow started");const m=await i();if(!m)return;o("Auth valid, checking if business already has application");const h=r(),f=`${a()}/business/v1/applications`;o(`GET ${f}`),h.start("Checking application status...");try{const e=await fetch(f,{headers:{Authorization:`Bearer ${m.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(C){if(h.stop(),s(C),C instanceof Error&&C.message.startsWith("EXIT:"))throw C;if(n(C))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)}o("No existing application, checking agreements");const g=void 0!==d.subdomain;if(!(await p(m.token,{ciMode:g})))return;let y;o("Agreements checked, proceeding to subdomain prompt");const b=e=>`${a()}/business/v1/applications/check-subdomain?subdomain=${encodeURIComponent(e)}`;let $=d.subdomain?.trim();for(;;){if($)y=$,$=void 0,o(`Subdomain provided via flag: ${y}`);else{if(g)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"}]);y=t.trim()}}o(`Checking subdomain: ${y}`);const a=b(y);o(`GET ${a}`),h.start("Checking subdomain...");try{const e=await fetch(a,{headers:{Authorization:`Bearer ${m.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=u(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 ${y} is available`);break}console.error(t.red("Subdomain is not available. Please choose a different one."))}catch(C){if(h.stop(),s(C),C instanceof Error&&C.message.startsWith("EXIT:"))throw C;if(n(C))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 k={subdomain:y};d.template&&(k.template=d.template,o(`Template: ${d.template}`));const x=JSON.stringify(k);o(`Create request body: ${x}`),h.start("Creating application...");try{const i=await fetch(w,{method:"POST",headers:{Authorization:`Bearer ${m.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..."),h.start("Waiting for application to be ready...");const e=`${a()}/business/v1/applications`,s=await this.pollApplicationCreated(e,m.token);h.stop(),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=u(e);t&&(s=t)}console.error(t.red(s)),process.exit(1)}let p;if(o("Application created successfully"),g)p=!1,o("CI mode (--subdomain), skipping pull");else{p=(await e.prompt([{type:"confirm",name:"pull",message:"Pull the application locally?",default:!0}])).pull,o(`User chose to pull: ${p}`)}if(p){o("Running pull flow");try{const e=new c;await e.execute()}catch(C){if(s(C),C instanceof Error&&C.message.startsWith("EXIT:"))throw C;if(n(C))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(C){if(h.stop(),s(C),C instanceof Error&&C.message.startsWith("EXIT:"))throw C;if(n(C))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{m as CreateCommand};
|
package/dist/package.json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e="@dashnex/cli",a="0.5.
|
|
1
|
+
const e="@dashnex/cli",a="0.5.57",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};
|
package/package.json
CHANGED