@nestbox-ai/cli 1.0.21 → 1.0.23
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/agent.js +6 -2
- package/dist/commands/agent.js.map +1 -1
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/compute.js +4 -12
- package/dist/commands/compute.js.map +1 -1
- package/dist/commands/document.js +8 -15
- package/dist/commands/document.js.map +1 -1
- package/dist/commands/image.js +40 -69
- package/dist/commands/image.js.map +1 -1
- package/dist/commands/projects.js +23 -41
- package/dist/commands/projects.js.map +1 -1
- package/dist/utils/api.d.ts +20 -0
- package/dist/utils/api.js +67 -0
- package/dist/utils/api.js.map +1 -0
- package/package.json +1 -1
- package/src/commands/agent.ts +6 -4
- package/src/commands/auth.ts +1 -1
- package/src/commands/compute.ts +5 -14
- package/src/commands/document.ts +9 -19
- package/src/commands/image.ts +40 -77
- package/src/commands/projects.ts +25 -52
- package/src/utils/api.ts +64 -0
|
@@ -17,11 +17,10 @@ exports.readNestboxConfig = readNestboxConfig;
|
|
|
17
17
|
exports.writeNestboxConfig = writeNestboxConfig;
|
|
18
18
|
exports.registerProjectCommands = registerProjectCommands;
|
|
19
19
|
const chalk_1 = __importDefault(require("chalk"));
|
|
20
|
-
const error_1 = require("../utils/error");
|
|
21
20
|
const fs_1 = __importDefault(require("fs"));
|
|
22
21
|
const path_1 = __importDefault(require("path"));
|
|
23
|
-
const auth_1 = require("../utils/auth");
|
|
24
22
|
const admin_1 = require("@nestbox-ai/admin");
|
|
23
|
+
const api_1 = require("../utils/api");
|
|
25
24
|
// Utility functions for project configuration
|
|
26
25
|
function getNestboxConfigPath() {
|
|
27
26
|
return path_1.default.join(process.cwd(), '.nestboxrc');
|
|
@@ -44,22 +43,12 @@ function writeNestboxConfig(config) {
|
|
|
44
43
|
fs_1.default.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
45
44
|
}
|
|
46
45
|
function registerProjectCommands(program) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const configuration = new admin_1.Configuration({
|
|
54
|
-
basePath: authToken.serverUrl,
|
|
55
|
-
baseOptions: {
|
|
56
|
-
headers: {
|
|
57
|
-
"Authorization": authToken.token,
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
return new admin_1.ProjectsApi(configuration);
|
|
62
|
-
};
|
|
46
|
+
const authResult = (0, api_1.setupAuthAndConfig)();
|
|
47
|
+
if (!authResult) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const { authToken, configuration } = authResult;
|
|
51
|
+
const projectsApi = new admin_1.ProjectsApi(configuration);
|
|
63
52
|
// Create the main project command
|
|
64
53
|
const projectCommand = program
|
|
65
54
|
.command('project')
|
|
@@ -73,20 +62,21 @@ function registerProjectCommands(program) {
|
|
|
73
62
|
const config = readNestboxConfig();
|
|
74
63
|
config.projects = config.projects || {};
|
|
75
64
|
config.projects.default = projectName;
|
|
76
|
-
let projectsApi = createProjectsApi();
|
|
77
|
-
// Use withTokenRefresh wrapper for automatic retry
|
|
78
|
-
const response = yield (0, error_1.withTokenRefresh)(() => __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
return yield projectsApi.projectControllerGetAllProjects();
|
|
80
|
-
}),
|
|
81
|
-
// Recreate the API client after token refresh
|
|
82
|
-
() => {
|
|
83
|
-
projectsApi = createProjectsApi();
|
|
84
|
-
});
|
|
85
65
|
// Check if the project exists
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
66
|
+
try {
|
|
67
|
+
const response = yield projectsApi.projectControllerGetAllProjects();
|
|
68
|
+
const projectExists = response.data.data.projects.some((project) => project.name === projectName);
|
|
69
|
+
if (!projectExists) {
|
|
70
|
+
console.error(chalk_1.default.red(`Project '${projectName}' does not exist.`));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (error.response && error.response.status === 401) {
|
|
76
|
+
console.error(chalk_1.default.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
throw error;
|
|
90
80
|
}
|
|
91
81
|
// Write the configuration
|
|
92
82
|
writeNestboxConfig(config);
|
|
@@ -110,7 +100,6 @@ function registerProjectCommands(program) {
|
|
|
110
100
|
.description('Add a project with optional alias')
|
|
111
101
|
.action((projectName, alias) => {
|
|
112
102
|
try {
|
|
113
|
-
const authToken = (0, auth_1.getAuthToken)();
|
|
114
103
|
if (!authToken) {
|
|
115
104
|
console.error(chalk_1.default.red('No authentication token found. Please log in first.'));
|
|
116
105
|
return;
|
|
@@ -151,15 +140,8 @@ function registerProjectCommands(program) {
|
|
|
151
140
|
.description('List all projects')
|
|
152
141
|
.action(() => __awaiter(this, void 0, void 0, function* () {
|
|
153
142
|
try {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const response = yield (0, error_1.withTokenRefresh)(() => __awaiter(this, void 0, void 0, function* () {
|
|
157
|
-
return yield projectsApi.projectControllerGetAllProjects();
|
|
158
|
-
}),
|
|
159
|
-
// Recreate the API client after token refresh
|
|
160
|
-
() => {
|
|
161
|
-
projectsApi = createProjectsApi();
|
|
162
|
-
});
|
|
143
|
+
// Get projects from API
|
|
144
|
+
const response = yield projectsApi.projectControllerGetAllProjects();
|
|
163
145
|
const apiProjects = response.data.data.projects;
|
|
164
146
|
if (!apiProjects || apiProjects.length === 0) {
|
|
165
147
|
console.log(chalk_1.default.yellow('No projects found.'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/commands/projects.ts"],"names":[],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/commands/projects.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAkBA,oDAEC;AAED,8CAWC;AA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
|
4
|
+
token: string;
|
|
5
|
+
serverUrl: string;
|
|
6
|
+
accessToken?: string;
|
|
7
|
+
};
|
|
8
|
+
configuration: Configuration;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Common authentication and configuration setup
|
|
12
|
+
* Returns authentication token and configured API client
|
|
13
|
+
* Exits the process if authentication fails
|
|
14
|
+
*/
|
|
15
|
+
export declare function setupAuthAndConfig(): AuthResult | null;
|
|
16
|
+
/**
|
|
17
|
+
* Wrapper function that ensures authentication is set up before executing a callback
|
|
18
|
+
* Automatically handles authentication errors and provides configured API instances
|
|
19
|
+
*/
|
|
20
|
+
export declare function withAuth<T>(callback: (authResult: AuthResult) => Promise<T>): Promise<T | void>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.setupAuthAndConfig = setupAuthAndConfig;
|
|
16
|
+
exports.withAuth = withAuth;
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
const admin_1 = require("@nestbox-ai/admin");
|
|
19
|
+
const auth_1 = require("./auth");
|
|
20
|
+
/**
|
|
21
|
+
* Common authentication and configuration setup
|
|
22
|
+
* Returns authentication token and configured API client
|
|
23
|
+
* Exits the process if authentication fails
|
|
24
|
+
*/
|
|
25
|
+
function setupAuthAndConfig() {
|
|
26
|
+
const authToken = (0, auth_1.getAuthToken)();
|
|
27
|
+
if (!authToken) {
|
|
28
|
+
console.error(chalk_1.default.red('No authentication token found. Please login first.'));
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const configuration = new admin_1.Configuration({
|
|
32
|
+
basePath: authToken.serverUrl,
|
|
33
|
+
baseOptions: {
|
|
34
|
+
headers: {
|
|
35
|
+
"Authorization": authToken.token,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
authToken,
|
|
41
|
+
configuration
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Wrapper function that ensures authentication is set up before executing a callback
|
|
46
|
+
* Automatically handles authentication errors and provides configured API instances
|
|
47
|
+
*/
|
|
48
|
+
function withAuth(callback) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const authResult = setupAuthAndConfig();
|
|
51
|
+
if (!authResult) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
return yield callback(authResult);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error.response && error.response.status === 401) {
|
|
59
|
+
console.error(chalk_1.default.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw error; // Re-throw non-auth errors
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/utils/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAkBA,gDAqBC;AAMD,4BAkBC;AA/DD,kDAA0B;AAC1B,6CAAkD;AAClD,iCAAsC;AAWtC;;;;GAIG;AACH,SAAgB,kBAAkB;IAChC,MAAM,SAAS,GAAG,IAAA,mBAAY,GAAE,CAAC;IAEjC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAC,CAAC;QAC/E,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,aAAa,GAAG,IAAI,qBAAa,CAAC;QACtC,QAAQ,EAAE,SAAS,CAAC,SAAS;QAC7B,WAAW,EAAE;YACX,OAAO,EAAE;gBACP,eAAe,EAAE,SAAS,CAAC,KAAK;aACjC;SACF;KACF,CAAC,CAAC;IAEH,OAAO;QACL,SAAS;QACT,aAAa;KACd,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAsB,QAAQ,CAC5B,QAAgD;;QAEhD,MAAM,UAAU,GAAG,kBAAkB,EAAE,CAAC;QAExC,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,OAAO,MAAM,QAAQ,CAAC,UAAU,CAAC,CAAC;QACpC,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBACpD,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,sFAAsF,CAAC,CAAC,CAAC;YACnH,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,CAAC,CAAC,2BAA2B;YAC1C,CAAC;QACH,CAAC;IACH,CAAC;CAAA"}
|
package/package.json
CHANGED
package/src/commands/agent.ts
CHANGED
|
@@ -570,10 +570,12 @@ export function registerAgentCommands(program: Command): void {
|
|
|
570
570
|
console.log(chalk.blue(` - [${line.type} ${line.timestamp}] ${line.message} `));
|
|
571
571
|
});
|
|
572
572
|
}
|
|
573
|
-
spinner.succeed(
|
|
574
|
-
|
|
575
|
-
);
|
|
576
|
-
console.log(chalk.
|
|
573
|
+
spinner.succeed("Successfully deployed");
|
|
574
|
+
console.log(chalk.green(`${resourceType} deployed successfully!`));
|
|
575
|
+
console.log(chalk.cyan(`📍 Instance: ${instanceName}`));
|
|
576
|
+
console.log(chalk.cyan(`🤖 Agent: ${agentName} (${agentId})`));
|
|
577
|
+
console.log(chalk.cyan(`⚙️ Entry: ${resolvedEntry}`));
|
|
578
|
+
console.log(chalk.cyan(`🔄 Process: ${res.data.processName}`));
|
|
577
579
|
} catch (error: any) {
|
|
578
580
|
spinner.fail(`Failed to deploy ${resourceType.toLowerCase()}`);
|
|
579
581
|
throw error;
|
package/src/commands/auth.ts
CHANGED
|
@@ -7,7 +7,7 @@ import fs from 'fs';
|
|
|
7
7
|
import os from 'os';
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import { getAuthToken, listCredentials, removeCredentials } from '../utils/auth';
|
|
10
|
-
import { AuthApi, Configuration, OAuthLoginRequestDTOTypeEnum
|
|
10
|
+
import { AuthApi, Configuration, OAuthLoginRequestDTOTypeEnum } from '@nestbox-ai/admin';
|
|
11
11
|
import axios from 'axios';
|
|
12
12
|
|
|
13
13
|
|
package/src/commands/compute.ts
CHANGED
|
@@ -2,30 +2,21 @@ import { Command } from "commander";
|
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import ora from "ora";
|
|
4
4
|
import Table from "cli-table3";
|
|
5
|
-
import {
|
|
6
|
-
import { Configuration, ProjectsApi, MachineInstancesApi, MiscellaneousApi } from "@nestbox-ai/admin";
|
|
5
|
+
import { ProjectsApi, MachineInstancesApi, MiscellaneousApi } from "@nestbox-ai/admin";
|
|
7
6
|
import { resolveProject } from "../utils/project";
|
|
7
|
+
import { setupAuthAndConfig } from "../utils/api";
|
|
8
8
|
import inquirer from "inquirer";
|
|
9
9
|
import axios from "axios";
|
|
10
10
|
import { userData } from "../utils/user";
|
|
11
11
|
|
|
12
12
|
export function registerComputeProgram(program: Command): void {
|
|
13
|
-
const
|
|
13
|
+
const authResult = setupAuthAndConfig();
|
|
14
14
|
|
|
15
|
-
if (!
|
|
16
|
-
console.error(chalk.red('No authentication token found. Please login first.'));
|
|
15
|
+
if (!authResult) {
|
|
17
16
|
return;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
const configuration = new Configuration({
|
|
21
|
-
basePath: authToken.serverUrl,
|
|
22
|
-
baseOptions: {
|
|
23
|
-
headers: {
|
|
24
|
-
"Authorization": authToken.token,
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
18
|
|
|
19
|
+
const { authToken, configuration } = authResult;
|
|
29
20
|
const machineInstanceApi = new MachineInstancesApi(configuration);
|
|
30
21
|
const miscellaneousApi = new MiscellaneousApi(configuration);
|
|
31
22
|
const projectsApi = new ProjectsApi(configuration);
|
package/src/commands/document.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import ora from 'ora';
|
|
4
|
-
import {
|
|
5
|
-
import { Configuration, DocumentsApi, ProjectsApi } from '@nestbox-ai/admin';
|
|
6
|
-
import { readNestboxConfig } from './projects';
|
|
4
|
+
import { DocumentsApi, ProjectsApi } from '@nestbox-ai/admin';
|
|
7
5
|
import { resolveProject } from '../utils/project';
|
|
8
|
-
import {
|
|
6
|
+
import { setupAuthAndConfig } from '../utils/api';
|
|
9
7
|
|
|
10
8
|
|
|
11
9
|
/**
|
|
@@ -24,8 +22,9 @@ async function executeCommand<T>(
|
|
|
24
22
|
return result;
|
|
25
23
|
} catch (error: any) {
|
|
26
24
|
spinner.fail('Operation failed');
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
if (error.response && error.response.status === 401) {
|
|
26
|
+
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
27
|
+
} else if (error.response?.data?.message) {
|
|
29
28
|
console.error(chalk.red('API Error:'), error.response.data.message);
|
|
30
29
|
} else {
|
|
31
30
|
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
@@ -35,22 +34,13 @@ async function executeCommand<T>(
|
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
export function registerDocumentCommands(program: Command): void {
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
if (!
|
|
41
|
-
console.error(chalk.red('No authentication token found. Please login first.'));
|
|
37
|
+
const authResult = setupAuthAndConfig();
|
|
38
|
+
|
|
39
|
+
if (!authResult) {
|
|
42
40
|
return;
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
const configuration =
|
|
46
|
-
basePath: authToken.serverUrl,
|
|
47
|
-
baseOptions: {
|
|
48
|
-
headers: {
|
|
49
|
-
Authorization: authToken.token,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
|
|
43
|
+
const { authToken, configuration } = authResult;
|
|
54
44
|
const documentsApi = new DocumentsApi(configuration);
|
|
55
45
|
const projectsApi = new ProjectsApi(configuration);
|
|
56
46
|
|
package/src/commands/image.ts
CHANGED
|
@@ -2,33 +2,20 @@ import { Command } from 'commander';
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import ora from 'ora';
|
|
4
4
|
import Table from 'cli-table3';
|
|
5
|
-
import {
|
|
6
|
-
import { Configuration, MiscellaneousApi, ProjectsApi } from '@nestbox-ai/admin';
|
|
5
|
+
import { MiscellaneousApi, ProjectsApi } from '@nestbox-ai/admin';
|
|
7
6
|
import { resolveProject } from '../utils/project';
|
|
8
|
-
import {
|
|
7
|
+
import { setupAuthAndConfig } from '../utils/api';
|
|
9
8
|
|
|
10
9
|
export function registerImageCommands(program: Command): void {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const configuration = new Configuration({
|
|
19
|
-
basePath: authToken.serverUrl,
|
|
20
|
-
baseOptions: {
|
|
21
|
-
headers: {
|
|
22
|
-
Authorization: authToken.token,
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
});
|
|
10
|
+
const authResult = setupAuthAndConfig();
|
|
11
|
+
|
|
12
|
+
if (!authResult) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
};
|
|
16
|
+
const { configuration } = authResult;
|
|
17
|
+
const miscellaneousApi = new MiscellaneousApi(configuration);
|
|
18
|
+
const projectsApi = new ProjectsApi(configuration);
|
|
32
19
|
|
|
33
20
|
const imageCommand = program.command('image').description('Manage Nestbox images');
|
|
34
21
|
|
|
@@ -38,49 +25,43 @@ export function registerImageCommands(program: Command): void {
|
|
|
38
25
|
.description('List images for a project')
|
|
39
26
|
.option('--project <projectId>', 'Project ID or name (defaults to the current project)')
|
|
40
27
|
.action(async (options) => {
|
|
41
|
-
const spinner = ora('Processing...').start();
|
|
42
|
-
|
|
43
28
|
try {
|
|
44
|
-
|
|
29
|
+
// Resolve project using the shared utility
|
|
30
|
+
const project = await resolveProject(projectsApi, options);
|
|
45
31
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
...options,
|
|
53
|
-
showSpinner: false // Disable resolveProject's spinner
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// Fetch images
|
|
57
|
-
spinner.text = `Listing images for project ${project.name}...`;
|
|
58
|
-
const response = await apis.miscellaneousApi.miscellaneousControllerGetData();
|
|
59
|
-
|
|
60
|
-
return { project, images: response.data };
|
|
61
|
-
},
|
|
62
|
-
() => {
|
|
63
|
-
// Recreate APIs after token refresh
|
|
64
|
-
apis = createApis();
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
spinner.succeed('Successfully retrieved images');
|
|
32
|
+
const spinner = ora(`Listing images for project ${project.name}...`).start();
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const response = await miscellaneousApi.miscellaneousControllerGetData();
|
|
36
|
+
|
|
37
|
+
spinner.succeed('Successfully retrieved images');
|
|
69
38
|
|
|
70
|
-
|
|
71
|
-
const images: any = result.images;
|
|
39
|
+
const images: any = response.data;
|
|
72
40
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
41
|
+
if (!images || images.length === 0) {
|
|
42
|
+
console.log(chalk.yellow(`No images found for project ${project.name}.`));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
77
45
|
|
|
78
|
-
|
|
79
|
-
|
|
46
|
+
// Create and display the table
|
|
47
|
+
displayImagesTable(images);
|
|
80
48
|
|
|
49
|
+
} catch (error: any) {
|
|
50
|
+
spinner.fail('Failed to retrieve images');
|
|
51
|
+
if (error.response && error.response.status === 401) {
|
|
52
|
+
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
53
|
+
} else if (error.response) {
|
|
54
|
+
console.error(chalk.red('API Error:'), error.response.data?.message || 'Unknown error');
|
|
55
|
+
} else {
|
|
56
|
+
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
81
59
|
} catch (error: any) {
|
|
82
|
-
|
|
83
|
-
|
|
60
|
+
if (error.response && error.response.status === 401) {
|
|
61
|
+
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
62
|
+
} else {
|
|
63
|
+
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
64
|
+
}
|
|
84
65
|
}
|
|
85
66
|
});
|
|
86
67
|
|
|
@@ -126,22 +107,4 @@ function displayImagesTable(images: any[]): void {
|
|
|
126
107
|
});
|
|
127
108
|
|
|
128
109
|
console.log(table.toString());
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Helper function to handle errors
|
|
132
|
-
function handleError(error: any): void {
|
|
133
|
-
if (error.message) {
|
|
134
|
-
if (error.message.includes('Authentication')) {
|
|
135
|
-
console.error(chalk.red(error.message));
|
|
136
|
-
} else if (error.message.includes('No project')) {
|
|
137
|
-
// Project-related errors are already well-formatted
|
|
138
|
-
console.error(chalk.red(error.message));
|
|
139
|
-
} else {
|
|
140
|
-
console.error(chalk.red('Error:'), error.message);
|
|
141
|
-
}
|
|
142
|
-
} else if (error.response?.data?.message) {
|
|
143
|
-
console.error(chalk.red('API Error:'), error.response.data.message);
|
|
144
|
-
} else {
|
|
145
|
-
console.error(chalk.red('Error:'), 'Unknown error occurred');
|
|
146
|
-
}
|
|
147
110
|
}
|
package/src/commands/projects.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import { withTokenRefresh } from '../utils/error';
|
|
4
3
|
import fs from 'fs';
|
|
5
4
|
import path from 'path';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { ProjectsApi } from '@nestbox-ai/admin';
|
|
6
|
+
import { setupAuthAndConfig } from '../utils/api';
|
|
8
7
|
|
|
9
8
|
// Define a type for the projects configuration
|
|
10
9
|
interface ProjectsConfig {
|
|
@@ -40,24 +39,14 @@ export function writeNestboxConfig(config: NestboxConfig): void {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
export function registerProjectCommands(program: Command): void {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
basePath: authToken.serverUrl,
|
|
52
|
-
baseOptions: {
|
|
53
|
-
headers: {
|
|
54
|
-
"Authorization": authToken.token,
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
return new ProjectsApi(configuration);
|
|
60
|
-
};
|
|
42
|
+
const authResult = setupAuthAndConfig();
|
|
43
|
+
|
|
44
|
+
if (!authResult) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const { authToken, configuration } = authResult;
|
|
49
|
+
const projectsApi = new ProjectsApi(configuration);
|
|
61
50
|
|
|
62
51
|
// Create the main project command
|
|
63
52
|
const projectCommand = program
|
|
@@ -74,24 +63,20 @@ export function registerProjectCommands(program: Command): void {
|
|
|
74
63
|
config.projects = config.projects || {};
|
|
75
64
|
config.projects.default = projectName;
|
|
76
65
|
|
|
77
|
-
let projectsApi = createProjectsApi();
|
|
78
|
-
|
|
79
|
-
// Use withTokenRefresh wrapper for automatic retry
|
|
80
|
-
const response = await withTokenRefresh(
|
|
81
|
-
async () => {
|
|
82
|
-
return await projectsApi.projectControllerGetAllProjects();
|
|
83
|
-
},
|
|
84
|
-
// Recreate the API client after token refresh
|
|
85
|
-
() => {
|
|
86
|
-
projectsApi = createProjectsApi();
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
|
|
90
66
|
// Check if the project exists
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
67
|
+
try {
|
|
68
|
+
const response = await projectsApi.projectControllerGetAllProjects();
|
|
69
|
+
const projectExists = response.data.data.projects.some((project: any) => project.name === projectName);
|
|
70
|
+
if (!projectExists) {
|
|
71
|
+
console.error(chalk.red(`Project '${projectName}' does not exist.`));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
} catch (error: any) {
|
|
75
|
+
if (error.response && error.response.status === 401) {
|
|
76
|
+
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
throw error;
|
|
95
80
|
}
|
|
96
81
|
|
|
97
82
|
// Write the configuration
|
|
@@ -114,7 +99,6 @@ export function registerProjectCommands(program: Command): void {
|
|
|
114
99
|
.description('Add a project with optional alias')
|
|
115
100
|
.action((projectName: string, alias?: string) => {
|
|
116
101
|
try {
|
|
117
|
-
const authToken = getAuthToken();
|
|
118
102
|
if (!authToken) {
|
|
119
103
|
console.error(chalk.red('No authentication token found. Please log in first.'));
|
|
120
104
|
return;
|
|
@@ -158,19 +142,8 @@ export function registerProjectCommands(program: Command): void {
|
|
|
158
142
|
.description('List all projects')
|
|
159
143
|
.action(async () => {
|
|
160
144
|
try {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// Use withTokenRefresh wrapper for automatic retry
|
|
164
|
-
const response = await withTokenRefresh(
|
|
165
|
-
async () => {
|
|
166
|
-
return await projectsApi.projectControllerGetAllProjects();
|
|
167
|
-
},
|
|
168
|
-
// Recreate the API client after token refresh
|
|
169
|
-
() => {
|
|
170
|
-
projectsApi = createProjectsApi();
|
|
171
|
-
}
|
|
172
|
-
);
|
|
173
|
-
|
|
145
|
+
// Get projects from API
|
|
146
|
+
const response = await projectsApi.projectControllerGetAllProjects();
|
|
174
147
|
const apiProjects = response.data.data.projects;
|
|
175
148
|
|
|
176
149
|
if (!apiProjects || apiProjects.length === 0) {
|