@dashnex/cli 0.5.40 → 0.5.41
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/dist/commands/check.js +1 -1
- package/dist/package.json.js +1 -1
- package/dist/services/auth.js +1 -1
- package/package.json +1 -1
package/dist/commands/check.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{spawn as e}from"child_process";import o from"chalk";import{debug as n,debugError as r}from"../lib/debug.js";const s=(o,s)=>new Promise((
|
|
1
|
+
import{spawn as e}from"child_process";import o from"chalk";import{debug as n,debugError as r}from"../lib/debug.js";const s=(o,s)=>{const c=`${o} ${s.join(" ")}`;return new Promise((s,t)=>{n(`Running: ${c}`);const a=e(c,{stdio:"inherit",cwd:process.cwd(),shell:!0});a.on("error",e=>{r(e),t(e)}),a.on("close",e=>{n(`${o} exited with code ${e}`),s(null===e?1:e)})})},c=o=>new Promise(n=>{const r=e(`${o} --version`,{stdio:"ignore",shell:!0});r.on("error",()=>n(!1)),r.on("close",e=>n(0===e))}),t=[{name:"TypeScript",command:"npx",args:["tsc","--noEmit"],notFoundMessage:"TypeScript is not available. Please install it with: npm install -D typescript"}];class a{async execute(){n("Check flow started"),n(`Running ${t.length} check(s)`);for(const a of t){n(`Running check: ${a.name}`);await c(a.command)||(console.error(o.red(a.notFoundMessage)),process.exit(1));try{0!==await s(a.command,a.args)&&(console.error(o.red("Check failed.")),process.exit(1))}catch(e){r(e),console.error(o.red(a.notFoundMessage)),process.exit(1)}}console.log(o.green("All checks passed."))}async run(){n("Running checks (called from deploy)");for(const a of t){n(`Running check: ${a.name}`);if(!(await c(a.command)))return console.error(o.red(a.notFoundMessage)),!1;try{if(0!==await s(a.command,a.args))return!1}catch(e){return r(e),console.error(o.red(a.notFoundMessage)),!1}}return console.log(o.green("All checks passed.")),!0}}export{a as CheckCommand};
|
package/dist/package.json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e="@dashnex/cli",a="0.5.
|
|
1
|
+
const e="@dashnex/cli",a="0.5.41",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/dist/services/auth.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"chalk";import
|
|
1
|
+
import e from"chalk";import n from"fs-extra";import r from"path";import{debug as s,debugError as t,debugJson as o}from"../lib/debug.js";import{getApiBase as a,apiFetch as i}from"../lib/api.js";const u=()=>{console.error(e.red("Please run 'dashnex login' to authenticate.")),console.error(e.dim("If you don't have a business account yet, create one at "+("qa"===(process.env.APPLICATION_ENV??"")?"https://business.qa.dashnex.com/":"https://business.dashnex.com/")))},h=async(e,r)=>{s(`POST ${a()}/auth/v1/token/refresh`);const{response:t,body:u}=await i(`${a()}/auth/v1/token/refresh`,{method:"POST",body:JSON.stringify({refreshToken:e})});if(s(`Response: ${t.status}`),o("Refresh response",u),!t.ok)return s("Token refresh failed"),null;const h=u;if(!h.token||!h.refreshToken)return s("Refresh response missing tokens"),null;const f=await n.readJson(r);return f.token=h.token,f.refreshToken=h.refreshToken,await n.writeJson(r,f,{spaces:2}),s("Updated .dashnex with new tokens"),l(h.token,h.refreshToken,r,{...f,token:h.token,refreshToken:h.refreshToken})},l=async(e,n,r,u)=>{if(((e,n=30)=>{try{const r=e.split(".");if(3!==r.length)return!1;const t=JSON.parse(Buffer.from(r[1],"base64url").toString());if("number"!=typeof t.exp)return!1;const o=Math.floor(Date.now()/1e3),a=t.exp-n<=o;return a&&s(`Token expired or expiring soon (exp: ${t.exp}, now: ${o})`),a}catch{return!1}})(e)){if(!n)return s("Token expired, no refreshToken available"),null;s("Token expired, refreshing proactively");try{return await h(n,r)}catch(l){return t(l),null}}s(`GET ${a()}/users/v1/`);try{const{response:t,body:l}=await i(`${a()}/users/v1/`,{headers:{Authorization:`Bearer ${e}`}});if(s(`Response: ${t.status}`),o("Users response",l),t.ok){const n=l;if("string"==typeof n.name&&u.businessId)return s(`Token valid, Already logged in as ${n.name}`),{token:e,businessId:u.businessId,userName:n.name}}return n?(s("Users API rejected token, refreshing"),await h(n,r)):(s("Token invalid, no refreshToken available"),null)}catch(l){return t(l),null}},f=async(e={})=>{const{exitOnFailure:t=!0,dashnexPath:o}=e,a=o??await(async e=>{let s=r.resolve(e);for(;;){const e=r.join(s,".dashnex");if(await n.pathExists(e))return e;const t=r.dirname(s);if(t===s)return null;s=t}})(process.cwd());if(!a||!(await n.pathExists(a)))return s(".dashnex not found"),t&&(u(),process.exit(1)),null;let i;s(`Found .dashnex at ${a}`);try{i=await n.readJson(a)}catch{return s(".dashnex parse failed"),t&&(u(),process.exit(1)),null}const{token:h,refreshToken:f,businessId:c}=i;if(!h)return s(".dashnex missing token"),t&&(u(),process.exit(1)),null;const d=await l(h,f,a,i);return d||(t&&(u(),process.exit(1)),null)};export{f as ensureLoggedIn};
|
package/package.json
CHANGED