@dashnex/cli 0.5.2 → 0.5.4

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.
Files changed (50) hide show
  1. package/dist/cli.d.ts +2 -0
  2. package/dist/cli.js +1 -161
  3. package/dist/client.d.ts +3 -0
  4. package/dist/client.js +1 -12
  5. package/dist/commands/create.d.ts +7 -0
  6. package/dist/commands/create.js +1 -134
  7. package/dist/commands/delete.d.ts +4 -0
  8. package/dist/commands/delete.js +1 -51
  9. package/dist/commands/index.d.ts +3 -0
  10. package/dist/commands/index.js +1 -68
  11. package/dist/commands/login.d.ts +8 -0
  12. package/dist/commands/login.js +1 -262
  13. package/dist/commands/logout.d.ts +4 -0
  14. package/dist/commands/logout.js +1 -16
  15. package/dist/commands/pull.d.ts +4 -0
  16. package/dist/commands/pull.js +1 -102
  17. package/dist/commands/push.d.ts +4 -0
  18. package/dist/commands/push.js +1 -108
  19. package/dist/commands/version.d.ts +5 -0
  20. package/dist/commands/version.js +1 -10
  21. package/dist/commands/whoami.d.ts +4 -0
  22. package/dist/commands/whoami.js +1 -52
  23. package/dist/dashnex.json.js +1 -5
  24. package/dist/lib/api.d.ts +7 -0
  25. package/dist/lib/api.js +1 -23
  26. package/dist/lib/debug.d.ts +3 -0
  27. package/dist/lib/debug.js +1 -45
  28. package/dist/package.json.js +1 -15
  29. package/dist/server.d.ts +3 -0
  30. package/dist/server.js +1 -12
  31. package/dist/services/auth.d.ts +10 -0
  32. package/dist/services/auth.js +1 -116
  33. package/package.json +3 -3
  34. package/dist/cli.js.map +0 -1
  35. package/dist/client.js.map +0 -1
  36. package/dist/commands/create.js.map +0 -1
  37. package/dist/commands/delete.js.map +0 -1
  38. package/dist/commands/index.js.map +0 -1
  39. package/dist/commands/login.js.map +0 -1
  40. package/dist/commands/logout.js.map +0 -1
  41. package/dist/commands/pull.js.map +0 -1
  42. package/dist/commands/push.js.map +0 -1
  43. package/dist/commands/version.js.map +0 -1
  44. package/dist/commands/whoami.js.map +0 -1
  45. package/dist/dashnex.json.js.map +0 -1
  46. package/dist/lib/api.js.map +0 -1
  47. package/dist/lib/debug.js.map +0 -1
  48. package/dist/package.json.js.map +0 -1
  49. package/dist/server.js.map +0 -1
  50. package/dist/services/auth.js.map +0 -1
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js CHANGED
@@ -1,162 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from "commander";
3
- import chalk from "chalk";
4
- import fs from "fs-extra";
5
- import path from "path";
6
- import dotenv from "dotenv";
7
- import packageJson from "./package.json.js";
8
- const program = new Command();
9
- const { name, version, description } = packageJson;
10
- program.name(name).description(description).version(version);
11
- function getModuleRoot(module, appDir) {
12
- const appPackageJsonPath = path.join(appDir, "package.json");
13
- if (fs.existsSync(appPackageJsonPath)) {
14
- try {
15
- const appPackageJson = JSON.parse(fs.readFileSync(appPackageJsonPath, "utf8"));
16
- if (appPackageJson.name === module) {
17
- return appDir;
18
- }
19
- } catch {
20
- }
21
- }
22
- return path.join(appDir, "node_modules", module);
23
- }
24
- async function discoverModuleCommands(module, appDir) {
25
- const discoveredCommands = [];
26
- try {
27
- const moduleRoot = getModuleRoot(module, appDir);
28
- const modulePath = path.join(moduleRoot, "dist", "commands", "index.js");
29
- if (fs.existsSync(modulePath)) {
30
- const module2 = await import(modulePath);
31
- let moduleCommands = [];
32
- if (module2.default) {
33
- moduleCommands = Array.isArray(module2.default) ? module2.default : [];
34
- } else if (module2.commands) {
35
- moduleCommands = Array.isArray(module2.commands) ? module2.commands : [];
36
- }
37
- if (moduleCommands.length > 0) {
38
- discoveredCommands.push(...moduleCommands);
39
- }
40
- }
41
- } catch (error) {
42
- if (process.env.DEBUG) {
43
- const errorMessage = error instanceof Error ? error.message : String(error);
44
- console.log(chalk.yellow(`Module ${module} has no commands or failed to load: ${errorMessage}`));
45
- }
46
- }
47
- return discoveredCommands;
48
- }
49
- async function discoverDashnexModules(appDir) {
50
- try {
51
- const dashnexModules = [];
52
- const seen = /* @__PURE__ */ new Set();
53
- const addIfNew = (name2) => {
54
- if (!seen.has(name2)) {
55
- seen.add(name2);
56
- dashnexModules.push(name2);
57
- }
58
- };
59
- const appDashnexPath = path.join(appDir, "dashnex.json");
60
- if (fs.existsSync(appDashnexPath)) {
61
- const appPackageJsonPath2 = path.join(appDir, "package.json");
62
- if (fs.existsSync(appPackageJsonPath2)) {
63
- const appPackageJson2 = JSON.parse(fs.readFileSync(appPackageJsonPath2, "utf8"));
64
- if (appPackageJson2.name) {
65
- addIfNew(appPackageJson2.name);
66
- }
67
- }
68
- }
69
- const appPackageJsonPath = path.join(appDir, "package.json");
70
- if (!fs.existsSync(appPackageJsonPath)) {
71
- return dashnexModules;
72
- }
73
- const appPackageJson = JSON.parse(fs.readFileSync(appPackageJsonPath, "utf8"));
74
- const allDependencies = {
75
- ...appPackageJson.dependencies,
76
- ...appPackageJson.devDependencies,
77
- ...appPackageJson.optionalDependencies
78
- };
79
- for (const [module] of Object.entries(allDependencies)) {
80
- const moduleRoot = path.join(appDir, "node_modules", module);
81
- if (fs.existsSync(path.join(moduleRoot, "dashnex.json"))) {
82
- addIfNew(module);
83
- }
84
- }
85
- return dashnexModules;
86
- } catch (error) {
87
- if (process.env.DEBUG) {
88
- const errorMessage = error instanceof Error ? error.message : String(error);
89
- console.log("⚠ Error reading app package.json:", errorMessage);
90
- }
91
- return [];
92
- }
93
- }
94
- function registerCommand(parentCommand, dashnexCommand, parentOptions = {}) {
95
- const cmd = parentCommand.command(dashnexCommand.name).description(dashnexCommand.description);
96
- if (dashnexCommand.options) {
97
- dashnexCommand.options.forEach((option) => {
98
- if (option.defaultValue !== void 0) {
99
- if (typeof option.defaultValue === "number") {
100
- cmd.option(option.flags, option.description, String(option.defaultValue));
101
- } else {
102
- cmd.option(option.flags, option.description, option.defaultValue);
103
- }
104
- } else {
105
- cmd.option(option.flags, option.description);
106
- }
107
- });
108
- }
109
- if (dashnexCommand.subcommands) {
110
- dashnexCommand.subcommands.forEach((subcommand) => {
111
- registerCommand(cmd, subcommand, { ...parentOptions, ...dashnexCommand.options });
112
- });
113
- }
114
- cmd.action(async (options, actionCommand) => {
115
- try {
116
- const mergedOptions = { ...parentOptions, ...options };
117
- await dashnexCommand.handler.execute(mergedOptions);
118
- } catch (error) {
119
- console.error(chalk.red(`❌ Command failed in ${dashnexCommand.name}:`), error);
120
- process.exit(1);
121
- }
122
- });
123
- }
124
- async function main() {
125
- dotenv.config({ quiet: true });
126
- process.env.DASHNEX_CLI = "1";
127
- let appDir = process.cwd();
128
- if (process.env.DEBUG) {
129
- console.log(`CLI started from directory: ${appDir}`);
130
- }
131
- const moduleNames = await discoverDashnexModules(appDir);
132
- if (process.env.DEBUG) {
133
- console.log(`Discovered modules: ${moduleNames.join(", ")}`);
134
- }
135
- for (const moduleName of moduleNames) {
136
- const moduleCommands = await discoverModuleCommands(moduleName, appDir);
137
- for (const command of moduleCommands) {
138
- registerCommand(program, command);
139
- }
140
- }
141
- try {
142
- const { default: applicationCommands } = await import(path.join(appDir, "dist", "commands", "index.js"));
143
- if (applicationCommands && Array.isArray(applicationCommands)) {
144
- for (const command of applicationCommands) {
145
- registerCommand(program, command);
146
- }
147
- }
148
- } catch (error) {
149
- if (process.env.DEBUG) {
150
- console.error(chalk.yellow("⚠ Failed to discover application commands"));
151
- }
152
- }
153
- program.parse(process.argv);
154
- if (!process.argv.slice(2).length) {
155
- program.outputHelp();
156
- }
157
- }
158
- main().catch((error) => {
159
- console.error(chalk.red("❌ CLI failed:"), error);
160
- process.exit(1);
161
- });
162
- //# sourceMappingURL=cli.js.map
2
+ import{Command as o}from"commander";import e from"chalk";import n from"fs-extra";import s from"path";import t from"dotenv";import r from"./package.json.js";const c=new o,{name:a,version:i,description:d}=r;async function p(o,t){const r=[];try{const e=function(o,e){const t=s.join(e,"package.json");if(n.existsSync(t))try{if(JSON.parse(n.readFileSync(t,"utf8")).name===o)return e}catch{}return s.join(e,"node_modules",o)}(o,t),c=s.join(e,"dist","commands","index.js");if(n.existsSync(c)){const o=await import(c);let e=[];o.default?e=Array.isArray(o.default)?o.default:[]:o.commands&&(e=Array.isArray(o.commands)?o.commands:[]),e.length>0&&r.push(...e)}}catch(c){if(process.env.DEBUG){const n=c instanceof Error?c.message:String(c);console.log(e.yellow(`Module ${o} has no commands or failed to load: ${n}`))}}return r}function f(o,n,s={}){const t=o.command(n.name).description(n.description);n.options&&n.options.forEach(o=>{void 0!==o.defaultValue?"number"==typeof o.defaultValue?t.option(o.flags,o.description,String(o.defaultValue)):t.option(o.flags,o.description,o.defaultValue):t.option(o.flags,o.description)}),n.subcommands&&n.subcommands.forEach(o=>{f(t,o,{...s,...n.options})}),t.action(async(o,t)=>{try{const e={...s,...o};await n.handler.execute(e)}catch(r){console.error(e.red(`❌ Command failed in ${n.name}:`),r),process.exit(1)}})}c.name(a).description(d).version(i),async function(){t.config({quiet:!0}),process.env.DASHNEX_CLI="1";let o=process.cwd();process.env.DEBUG&&console.log(`CLI started from directory: ${o}`);const r=await async function(o){try{const e=[],t=/* @__PURE__ */new Set,r=o=>{t.has(o)||(t.add(o),e.push(o))},c=s.join(o,"dashnex.json");if(n.existsSync(c)){const e=s.join(o,"package.json");if(n.existsSync(e)){const o=JSON.parse(n.readFileSync(e,"utf8"));o.name&&r(o.name)}}const a=s.join(o,"package.json");if(!n.existsSync(a))return e;const i=JSON.parse(n.readFileSync(a,"utf8")),d={...i.dependencies,...i.devDependencies,...i.optionalDependencies};for(const[p]of Object.entries(d)){const e=s.join(o,"node_modules",p);n.existsSync(s.join(e,"dashnex.json"))&&r(p)}return e}catch(e){if(process.env.DEBUG){const o=e instanceof Error?e.message:String(e);console.log("⚠ Error reading app package.json:",o)}return[]}}(o);process.env.DEBUG&&console.log(`Discovered modules: ${r.join(", ")}`);for(const e of r){const n=await p(e,o);for(const o of n)f(c,o)}try{const{default:e}=await import(s.join(o,"dist","commands","index.js"));if(e&&Array.isArray(e))for(const o of e)f(c,o)}catch(a){process.env.DEBUG&&console.error(e.yellow("⚠ Failed to discover application commands"))}c.parse(process.argv),process.argv.slice(2).length||c.outputHelp()}().catch(o=>{console.error(e.red("❌ CLI failed:"),o),process.exit(1)});
@@ -0,0 +1,3 @@
1
+ import { ModuleConfig } from '@dashnex/types';
2
+ declare const _default: ModuleConfig;
3
+ export default _default;
package/dist/client.js CHANGED
@@ -1,12 +1 @@
1
- import packageJson from "./package.json.js";
2
- import dashnexConfig from "./dashnex.json.js";
3
- const client = {
4
- name: packageJson.name,
5
- version: packageJson.version,
6
- description: packageJson.description,
7
- ...dashnexConfig
8
- };
9
- export {
10
- client as default
11
- };
12
- //# sourceMappingURL=client.js.map
1
+ import o from"./package.json.js";import s from"./dashnex.json.js";const e={name:o.name,version:o.version,description:o.description,...s};export{e as default};
@@ -0,0 +1,7 @@
1
+ import { CliCommand } from '@dashnex/types';
2
+ export interface CreateCommandOptions {
3
+ template?: string;
4
+ }
5
+ export declare class CreateCommand implements CliCommand {
6
+ execute(options?: CreateCommandOptions): Promise<void>;
7
+ }
@@ -1,134 +1 @@
1
- import inquirer from "inquirer";
2
- import chalk from "chalk";
3
- import { debug, debugError } from "../lib/debug.js";
4
- import { getBusinessApiBase } from "../lib/api.js";
5
- import { ensureLoggedIn } from "../services/auth.js";
6
- const extractErrorMessage = (body) => {
7
- if (Array.isArray(body.message) && body.message.length > 0) {
8
- return body.message.join(" ");
9
- }
10
- if (typeof body.message === "string") return body.message;
11
- if (typeof body.error === "string") return body.error;
12
- return void 0;
13
- };
14
- const SUCCESS_MESSAGE = "Application is created successfully. Use 'npx dashnex pull' to pull it to your computer or 'npx dashnex deploy' to deploy it to the cloud.";
15
- class CreateCommand {
16
- async execute(options = {}) {
17
- debug("Create flow started");
18
- const session = await ensureLoggedIn();
19
- if (!session) return;
20
- debug("Auth valid, checking if business already has application");
21
- const applicationsUrl = `${getBusinessApiBase()}/business/v1/applications`;
22
- debug(`GET ${applicationsUrl}`);
23
- try {
24
- const appsResponse = await fetch(applicationsUrl, {
25
- headers: { Authorization: `Bearer ${session.token}` }
26
- });
27
- debug(`Applications response: ${appsResponse.status}`);
28
- if (appsResponse.status !== 404) {
29
- console.error(
30
- chalk.red(
31
- "Business already has an application. Run 'npx dashnex pull' to pull the existing one."
32
- )
33
- );
34
- process.exit(1);
35
- }
36
- } catch (error) {
37
- debugError(error);
38
- if (error instanceof Error && error.message.startsWith("EXIT:")) throw error;
39
- console.error(chalk.red("Could not reach DashNex API. Check your connection and try again."));
40
- process.exit(1);
41
- }
42
- debug("No existing application, proceeding to subdomain prompt");
43
- let subdomain;
44
- const checkSubdomainUrl = (sub) => `${getBusinessApiBase()}/business/v1/applications/check-subdomain?subdomain=${encodeURIComponent(sub)}`;
45
- while (true) {
46
- const { sub } = await inquirer.prompt([
47
- {
48
- type: "input",
49
- name: "sub",
50
- message: "Pick your subdomain:",
51
- validate: (input) => input.trim() ? true : "Subdomain is required"
52
- }
53
- ]);
54
- subdomain = sub.trim();
55
- debug(`Checking subdomain: ${subdomain}`);
56
- try {
57
- const checkResponse = await fetch(checkSubdomainUrl(subdomain), {
58
- headers: { Authorization: `Bearer ${session.token}` }
59
- });
60
- debug(`Check subdomain response: ${checkResponse.status}`);
61
- if (!checkResponse.ok) {
62
- const contentType = checkResponse.headers.get("content-type") ?? "";
63
- let message = "Failed to check subdomain availability.";
64
- if (checkResponse.status === 401 || checkResponse.status === 403) {
65
- message = "Please run 'npx dashnex login' to authenticate.";
66
- console.error(chalk.red(message));
67
- process.exit(1);
68
- }
69
- if (contentType.includes("application/json")) {
70
- const body = await checkResponse.json().catch(() => ({}));
71
- const apiMessage = extractErrorMessage(body);
72
- if (apiMessage) message = apiMessage;
73
- }
74
- console.error(chalk.red(message));
75
- continue;
76
- }
77
- const checkBody = await checkResponse.json();
78
- if (checkBody.available) {
79
- debug(`Subdomain ${subdomain} is available`);
80
- break;
81
- }
82
- console.error(chalk.red("Subdomain is not available. Please choose a different one."));
83
- } catch (error) {
84
- debugError(error);
85
- if (error instanceof Error && error.message.startsWith("EXIT:")) throw error;
86
- console.error(chalk.red("Could not reach DashNex API. Check your connection and try again."));
87
- process.exit(1);
88
- }
89
- }
90
- const createUrl = `${getBusinessApiBase()}/business/v1/cli/create`;
91
- debug(`POST ${createUrl}`);
92
- const createBody = { subdomain };
93
- if (options.template) {
94
- createBody.template = options.template;
95
- debug(`Template: ${options.template}`);
96
- }
97
- try {
98
- const createResponse = await fetch(createUrl, {
99
- method: "POST",
100
- headers: {
101
- Authorization: `Bearer ${session.token}`,
102
- "Content-Type": "application/json"
103
- },
104
- body: JSON.stringify(createBody)
105
- });
106
- debug(`Create response: ${createResponse.status}`);
107
- if (!createResponse.ok) {
108
- const contentType = createResponse.headers.get("content-type") ?? "";
109
- let message = "Failed to create application.";
110
- if (createResponse.status === 401 || createResponse.status === 403) {
111
- message = "Please run 'npx dashnex login' to authenticate.";
112
- } else if (contentType.includes("application/json")) {
113
- const body = await createResponse.json().catch(() => ({}));
114
- debug(`Create response body: ${JSON.stringify(body)}`);
115
- const apiMessage = extractErrorMessage(body);
116
- if (apiMessage) message = apiMessage;
117
- }
118
- console.error(chalk.red(message));
119
- process.exit(1);
120
- }
121
- debug("Application created successfully");
122
- console.log(chalk.green(SUCCESS_MESSAGE));
123
- } catch (error) {
124
- debugError(error);
125
- if (error instanceof Error && error.message.startsWith("EXIT:")) throw error;
126
- console.error(chalk.red("Could not reach DashNex API. Check your connection and try again."));
127
- process.exit(1);
128
- }
129
- }
130
- }
131
- export {
132
- CreateCommand
133
- };
134
- //# sourceMappingURL=create.js.map
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 n}from"../services/auth.js";const i=e=>Array.isArray(e.message)&&e.message.length>0?e.message.join(" "):"string"==typeof e.message?e.message:"string"==typeof e.error?e.error:void 0;class r{async execute(r={}){o("Create flow started");const c=await n();if(!c)return;o("Auth valid, checking if business already has application");const l=`${a()}/business/v1/applications`;o(`GET ${l}`);try{const e=await fetch(l,{headers:{Authorization:`Bearer ${c.token}`}});o(`Applications response: ${e.status}`),404!==e.status&&(console.error(t.red("Business already has an application. Run 'npx dashnex pull' to pull the existing one.")),process.exit(1))}catch(m){if(s(m),m instanceof Error&&m.message.startsWith("EXIT:"))throw m;console.error(t.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}let p;o("No existing application, proceeding to subdomain prompt");const u=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"}]);p=a.trim(),o(`Checking subdomain: ${p}`);try{const e=await fetch(u(p),{headers:{Authorization:`Bearer ${c.token}`}});if(o(`Check subdomain response: ${e.status}`),!e.ok){const o=e.headers.get("content-type")??"";let s="Failed to check subdomain availability.";if(401!==e.status&&403!==e.status||(s="Please run 'npx dashnex login' to authenticate.",console.error(t.red(s)),process.exit(1)),o.includes("application/json")){const t=await e.json().catch(()=>({})),o=i(t);o&&(s=o)}console.error(t.red(s));continue}if((await e.json()).available){o(`Subdomain ${p} is available`);break}console.error(t.red("Subdomain is not available. Please choose a different one."))}catch(m){if(s(m),m instanceof Error&&m.message.startsWith("EXIT:"))throw m;console.error(t.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}const d=`${a()}/business/v1/cli/create`;o(`POST ${d}`);const h={subdomain:p};r.template&&(h.template=r.template,o(`Template: ${r.template}`));try{const e=await fetch(d,{method:"POST",headers:{Authorization:`Bearer ${c.token}`,"Content-Type":"application/json"},body:JSON.stringify(h)});if(o(`Create response: ${e.status}`),!e.ok){const s=e.headers.get("content-type")??"";let a="Failed to create application.";if(401===e.status||403===e.status)a="Please run 'npx dashnex login' to authenticate.";else if(s.includes("application/json")){const t=await e.json().catch(()=>({}));o(`Create response body: ${JSON.stringify(t)}`);const s=i(t);s&&(a=s)}console.error(t.red(a)),process.exit(1)}o("Application created successfully"),console.log(t.green("Application is created successfully. Use 'npx dashnex pull' to pull it to your computer or 'npx dashnex deploy' to deploy it to the cloud."))}catch(m){if(s(m),m instanceof Error&&m.message.startsWith("EXIT:"))throw m;console.error(t.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}}export{r as CreateCommand};
@@ -0,0 +1,4 @@
1
+ import { CliCommand } from '@dashnex/types';
2
+ export declare class DeleteCommand implements CliCommand {
3
+ execute(): Promise<void>;
4
+ }
@@ -1,51 +1 @@
1
- import chalk from "chalk";
2
- import { debug, debugError } from "../lib/debug.js";
3
- import { getBusinessApiBase } from "../lib/api.js";
4
- import { ensureLoggedIn } from "../services/auth.js";
5
- const extractErrorMessage = (body) => {
6
- if (typeof body.error === "string") return body.error;
7
- if (typeof body.message === "string") return body.message;
8
- return void 0;
9
- };
10
- class DeleteCommand {
11
- async execute() {
12
- debug("Delete flow started");
13
- const session = await ensureLoggedIn();
14
- if (!session) return;
15
- const url = `${getBusinessApiBase()}/business/v1/applications`;
16
- debug(`DELETE ${url}`);
17
- try {
18
- const response = await fetch(url, {
19
- method: "DELETE",
20
- headers: { Authorization: `Bearer ${session.token}` }
21
- });
22
- debug(`Response: ${response.status}`);
23
- if (!response.ok) {
24
- const contentType = response.headers.get("content-type") ?? "";
25
- let message = "Failed to delete application.";
26
- if (response.status === 401 || response.status === 403) {
27
- message = "Please run 'npx dashnex login' to authenticate.";
28
- } else if (contentType.includes("application/json")) {
29
- const body2 = await response.json().catch(() => ({}));
30
- const apiMessage = extractErrorMessage(body2);
31
- if (apiMessage) message = apiMessage;
32
- }
33
- console.error(chalk.red(message));
34
- process.exit(1);
35
- }
36
- const body = await response.json().catch(() => ({}));
37
- const successMessage = typeof body.message === "string" ? body.message : "Application deleted successfully.";
38
- debug("Application deleted successfully");
39
- console.log(chalk.green(successMessage));
40
- } catch (error) {
41
- debugError(error);
42
- if (error instanceof Error && error.message.startsWith("EXIT:")) throw error;
43
- console.error(chalk.red("Could not reach DashNex API. Check your connection and try again."));
44
- process.exit(1);
45
- }
46
- }
47
- }
48
- export {
49
- DeleteCommand
50
- };
51
- //# sourceMappingURL=delete.js.map
1
+ import e from"chalk";import{debug as t,debugError as s}from"../lib/debug.js";import{getBusinessApiBase as o}from"../lib/api.js";import{ensureLoggedIn as a}from"../services/auth.js";class r{async execute(){t("Delete flow started");const r=await a();if(!r)return;const i=`${o()}/business/v1/applications`;t(`DELETE ${i}`);try{const s=await fetch(i,{method:"DELETE",headers:{Authorization:`Bearer ${r.token}`}});if(t(`Response: ${s.status}`),!s.ok){const t=s.headers.get("content-type")??"";let o="Failed to delete application.";if(401===s.status||403===s.status)o="Please run 'npx 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 s.json().catch(()=>({})));e&&(o=e)}console.error(e.red(o)),process.exit(1)}const o=await s.json().catch(()=>({})),a="string"==typeof o.message?o.message:"Application deleted successfully.";t("Application deleted successfully"),console.log(e.green(a))}catch(n){if(s(n),n instanceof Error&&n.message.startsWith("EXIT:"))throw n;console.error(e.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}}}export{r as DeleteCommand};
@@ -0,0 +1,3 @@
1
+ import { CliCommandConfig } from '@dashnex/types';
2
+ declare const commands: CliCommandConfig[];
3
+ export default commands;
@@ -1,68 +1 @@
1
- import VersionCommand from "./version.js";
2
- import { LoginCommand } from "./login.js";
3
- import { LogoutCommand } from "./logout.js";
4
- import { CreateCommand } from "./create.js";
5
- import { PullCommand } from "./pull.js";
6
- import { PushCommand } from "./push.js";
7
- import { DeleteCommand } from "./delete.js";
8
- import { WhoamiCommand } from "./whoami.js";
9
- const commands = [
10
- {
11
- name: "version",
12
- description: "Display the version of the CLI",
13
- handler: new VersionCommand(),
14
- options: []
15
- },
16
- {
17
- name: "login",
18
- description: "Log in to your DashNex account",
19
- handler: new LoginCommand(),
20
- options: []
21
- },
22
- {
23
- name: "logout",
24
- description: "Log out and remove local credentials",
25
- handler: new LogoutCommand(),
26
- options: []
27
- },
28
- {
29
- name: "create",
30
- description: "Create a new DashNex application",
31
- handler: new CreateCommand(),
32
- options: [
33
- {
34
- flags: "-t, --template <template>",
35
- description: "Template (name@branch-or-tag)",
36
- defaultValue: "webapp-base@live"
37
- }
38
- ]
39
- },
40
- {
41
- name: "pull",
42
- description: "Pull existing application to current folder",
43
- handler: new PullCommand(),
44
- options: []
45
- },
46
- {
47
- name: "push",
48
- description: "Push local application to DashNex",
49
- handler: new PushCommand(),
50
- options: []
51
- },
52
- {
53
- name: "delete",
54
- description: "Delete application from DashNex",
55
- handler: new DeleteCommand(),
56
- options: []
57
- },
58
- {
59
- name: "whoami",
60
- description: "Show current logged-in business and user",
61
- handler: new WhoamiCommand(),
62
- options: []
63
- }
64
- ];
65
- export {
66
- commands as default
67
- };
68
- //# sourceMappingURL=index.js.map
1
+ import e from"./version.js";import{LoginCommand as o}from"./login.js";import{LogoutCommand as n}from"./logout.js";import{CreateCommand as t}from"./create.js";import{PullCommand as i}from"./pull.js";import{PushCommand as a}from"./push.js";import{DeleteCommand as r}from"./delete.js";import{WhoamiCommand as s}from"./whoami.js";const p=[{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:"create",description:"Create a new DashNex application",handler:new t,options:[{flags:"-t, --template <template>",description:"Template (name@branch-or-tag)",defaultValue:"webapp-base@live"}]},{name:"pull",description:"Pull existing application to current folder",handler:new i,options:[]},{name:"push",description:"Push local application to DashNex",handler:new a,options:[]},{name:"delete",description:"Delete application from DashNex",handler:new r,options:[]},{name:"whoami",description:"Show current logged-in business and user",handler:new s,options:[]}];export{p as default};
@@ -0,0 +1,8 @@
1
+ import { CliCommand } from '@dashnex/types';
2
+ export declare class LoginCommand implements CliCommand {
3
+ execute(): Promise<void>;
4
+ private handle2FA;
5
+ private completeLogin;
6
+ private parseBusinesses;
7
+ private ensureGitignore;
8
+ }