bdy 1.16.11-master → 1.16.11-sbs-1
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/distTs/package.json +4 -3
- package/distTs/src/api/client.js +78 -2
- package/distTs/src/command/login.js +280 -0
- package/distTs/src/command/logout.js +15 -0
- package/distTs/src/command/package/download.js +259 -0
- package/distTs/src/command/package/publish.js +231 -0
- package/distTs/src/command/package.js +14 -0
- package/distTs/src/command/project/list.js +61 -0
- package/distTs/src/command/project/set.js +85 -0
- package/distTs/src/command/project.js +14 -0
- package/distTs/src/command/sandbox/command/kill.js +35 -0
- package/distTs/src/command/sandbox/command/list.js +54 -0
- package/distTs/src/command/sandbox/command/logs.js +133 -0
- package/distTs/src/command/sandbox/command/status.js +44 -0
- package/distTs/src/command/sandbox/command.js +18 -0
- package/distTs/src/command/sandbox/cp.js +123 -0
- package/distTs/src/command/sandbox/create.js +99 -0
- package/distTs/src/command/sandbox/destroy.js +35 -0
- package/distTs/src/command/sandbox/endpoint/add.js +91 -0
- package/distTs/src/command/sandbox/endpoint/delete.js +46 -0
- package/distTs/src/command/sandbox/endpoint/get.js +58 -0
- package/distTs/src/command/sandbox/endpoint/list.js +51 -0
- package/distTs/src/command/sandbox/endpoint/update.js +85 -0
- package/distTs/src/command/sandbox/endpoint.js +20 -0
- package/distTs/src/command/sandbox/exec.js +127 -0
- package/distTs/src/command/sandbox/get.js +51 -0
- package/distTs/src/command/sandbox/list.js +41 -0
- package/distTs/src/command/sandbox/restart.js +49 -0
- package/distTs/src/command/sandbox/snapshot/create.js +68 -0
- package/distTs/src/command/sandbox/snapshot/delete.js +42 -0
- package/distTs/src/command/sandbox/snapshot/get.js +54 -0
- package/distTs/src/command/sandbox/snapshot/list.js +48 -0
- package/distTs/src/command/sandbox/snapshot.js +18 -0
- package/distTs/src/command/sandbox/start.js +49 -0
- package/distTs/src/command/sandbox/status.js +35 -0
- package/distTs/src/command/sandbox/stop.js +49 -0
- package/distTs/src/command/sandbox.js +36 -0
- package/distTs/src/command/workspace/list.js +57 -0
- package/distTs/src/command/workspace/set.js +81 -0
- package/distTs/src/command/workspace.js +14 -0
- package/distTs/src/index.js +10 -0
- package/distTs/src/input.js +15 -4
- package/distTs/src/texts.js +155 -1
- package/distTs/src/tunnel/cfg.js +38 -0
- package/package.json +4 -3
- package/distTs/src/command/agent/standalone/kill.js +0 -22
- package/distTs/src/command/agent/standalone.js +0 -136
- package/distTs/src/command/vt/scrap.js +0 -193
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const texts_1 = require("../../texts");
|
|
8
|
+
const input_1 = __importDefault(require("../../input"));
|
|
9
|
+
const client_1 = __importDefault(require("../../api/client"));
|
|
10
|
+
const output_1 = __importDefault(require("../../output"));
|
|
11
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
12
|
+
const fflate_1 = __importDefault(require("fflate"));
|
|
13
|
+
const fs_1 = __importDefault(require("fs"));
|
|
14
|
+
const path_1 = require("path");
|
|
15
|
+
const uuid_1 = require("uuid");
|
|
16
|
+
const commandPackagePublish = (0, utils_1.newCommand)('publish', texts_1.DESC_COMMAND_PACKAGE_PUBLISH);
|
|
17
|
+
commandPackagePublish.alias('pub');
|
|
18
|
+
commandPackagePublish.option('-t, --token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
19
|
+
commandPackagePublish.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
20
|
+
commandPackagePublish.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
21
|
+
commandPackagePublish.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
22
|
+
commandPackagePublish.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
23
|
+
commandPackagePublish.option('-c, --create', texts_1.OPTION_PACKAGE_PUBLISH_CREATE);
|
|
24
|
+
commandPackagePublish.option('-f, --force', texts_1.OPTION_PACKAGE_PUBLISH_OVERWRITE_VERSION);
|
|
25
|
+
commandPackagePublish.argument('<identifier>', texts_1.OPTION_PACKAGE_ID);
|
|
26
|
+
commandPackagePublish.argument('<directory>', texts_1.OPTION_PACKAGE_PUBLISH_PATH);
|
|
27
|
+
commandPackagePublish.action(async (id, path, options) => {
|
|
28
|
+
let dirPath = input_1.default.resolvePath(path);
|
|
29
|
+
const token = input_1.default.restApiToken(options.token);
|
|
30
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
31
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
32
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
33
|
+
// eslint-disable-next-line prefer-const
|
|
34
|
+
let { identifier, version } = input_1.default.packageSplitIdentifier(id);
|
|
35
|
+
if (!version)
|
|
36
|
+
version = (0, uuid_1.v4)();
|
|
37
|
+
const client = new client_1.default(baseUrl, token);
|
|
38
|
+
const data = await client.getPackageVersionByIdentifier(workspace, project, identifier, version);
|
|
39
|
+
if (!data || !data.domain) {
|
|
40
|
+
output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_FOUND);
|
|
41
|
+
}
|
|
42
|
+
if (project && !data.project_identifier) {
|
|
43
|
+
output_1.default.exitError(texts_1.ERR_PROJECT_NOT_FOUND);
|
|
44
|
+
}
|
|
45
|
+
let packageId = data.pkg_id;
|
|
46
|
+
if (!packageId) {
|
|
47
|
+
if (options.create) {
|
|
48
|
+
const d = await client.postPackage(workspace, project, identifier);
|
|
49
|
+
packageId = d.id;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_PUBLISH_NOT_FOUND);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
let packageVersionId = data.pkg_version_id;
|
|
56
|
+
let url;
|
|
57
|
+
if (packageVersionId && !options.force) {
|
|
58
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_VERSION_EXISTS);
|
|
59
|
+
}
|
|
60
|
+
if (!packageVersionId) {
|
|
61
|
+
const d = await client.postPackageVersion(workspace, packageId, version);
|
|
62
|
+
url = d.version_url;
|
|
63
|
+
packageVersionId = d.id;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const d = await client.getPackageVersion(workspace, packageId, packageVersionId);
|
|
67
|
+
url = d.version_url;
|
|
68
|
+
}
|
|
69
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_SCANNING_DIR, false);
|
|
70
|
+
const stat = fs_1.default.statSync(dirPath);
|
|
71
|
+
let entries;
|
|
72
|
+
if (stat.isDirectory()) {
|
|
73
|
+
entries = fs_1.default.readdirSync(dirPath, {
|
|
74
|
+
withFileTypes: true,
|
|
75
|
+
recursive: true,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const parentPath = (0, path_1.dirname)(dirPath);
|
|
80
|
+
entries = [
|
|
81
|
+
{
|
|
82
|
+
isDirectory: () => stat.isDirectory(),
|
|
83
|
+
isFile: () => stat.isFile(),
|
|
84
|
+
isBlockDevice: () => stat.isBlockDevice(),
|
|
85
|
+
isCharacterDevice: () => stat.isCharacterDevice(),
|
|
86
|
+
isFIFO: () => stat.isFIFO(),
|
|
87
|
+
isSocket: () => stat.isSocket(),
|
|
88
|
+
isSymbolicLink: () => stat.isSymbolicLink(),
|
|
89
|
+
name: (0, path_1.basename)(dirPath),
|
|
90
|
+
parentPath,
|
|
91
|
+
path: parentPath,
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
dirPath = parentPath;
|
|
95
|
+
}
|
|
96
|
+
if (!entries.length) {
|
|
97
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_NO_ENTRIES_FOUND);
|
|
98
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_PUBLISHED)(url));
|
|
99
|
+
}
|
|
100
|
+
else if (entries.length === 1) {
|
|
101
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_ONE_ENTRY_FOUND);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_ENTRIES_FOUND)(entries.length));
|
|
105
|
+
}
|
|
106
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_ZIP_ENTRIES)(0));
|
|
107
|
+
const zipPath = (0, path_1.join)((0, utils_1.getHomeDirectory)(), `${(0, uuid_1.v4)()}.zip`);
|
|
108
|
+
const clearZip = () => {
|
|
109
|
+
try {
|
|
110
|
+
fs_1.default.rmSync(zipPath);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// do nothing
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
let blob;
|
|
117
|
+
try {
|
|
118
|
+
let proc = 0;
|
|
119
|
+
await createZip(dirPath, zipPath, entries, () => {
|
|
120
|
+
proc += 1;
|
|
121
|
+
output_1.default.clearPreviousLine();
|
|
122
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_ZIP_ENTRIES)(proc));
|
|
123
|
+
});
|
|
124
|
+
output_1.default.clearPreviousLine();
|
|
125
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_ZIPPED);
|
|
126
|
+
blob = await fs_1.default.openAsBlob(zipPath);
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
logger_1.default.error(err);
|
|
130
|
+
clearZip();
|
|
131
|
+
output_1.default.exitError(texts_1.ERR_SWW);
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UPLOADING);
|
|
135
|
+
await client.postPackageVersionZip(workspace, packageId, packageVersionId, blob);
|
|
136
|
+
output_1.default.clearPreviousLine();
|
|
137
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UPLOADED);
|
|
138
|
+
clearZip();
|
|
139
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_PUBLISHED)(url));
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
clearZip();
|
|
143
|
+
logger_1.default.error(err);
|
|
144
|
+
output_1.default.exitError(err);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
const addEntryToZip = (dirPath, zip, entry) => {
|
|
148
|
+
return new Promise((resolve, reject) => {
|
|
149
|
+
const isDir = entry.isDirectory();
|
|
150
|
+
let name = (0, path_1.join)(entry.parentPath.replace(dirPath, ''), entry.name);
|
|
151
|
+
if (isDir)
|
|
152
|
+
name += '/';
|
|
153
|
+
const file = new fflate_1.default.AsyncZipDeflate(name, {
|
|
154
|
+
level: 9,
|
|
155
|
+
});
|
|
156
|
+
zip.add(file);
|
|
157
|
+
if (isDir) {
|
|
158
|
+
file.push(new Uint8Array(0), true);
|
|
159
|
+
resolve();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const fullPath = (0, path_1.join)(entry.parentPath, entry.name);
|
|
163
|
+
const rs = fs_1.default.createReadStream(fullPath);
|
|
164
|
+
const finish = (err) => {
|
|
165
|
+
try {
|
|
166
|
+
rs.removeAllListeners();
|
|
167
|
+
rs.close();
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
// do nothing
|
|
171
|
+
}
|
|
172
|
+
if (err)
|
|
173
|
+
reject(err);
|
|
174
|
+
else
|
|
175
|
+
resolve();
|
|
176
|
+
};
|
|
177
|
+
rs.on('data', (chunk) => {
|
|
178
|
+
file.push(chunk, false);
|
|
179
|
+
});
|
|
180
|
+
rs.on('error', (err) => {
|
|
181
|
+
finish(err);
|
|
182
|
+
});
|
|
183
|
+
rs.on('end', () => {
|
|
184
|
+
file.push(new Uint8Array(0), true);
|
|
185
|
+
finish();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
const addEntriesToZip = async (dirPath, zip, entries, onEntry) => {
|
|
190
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
191
|
+
await addEntryToZip(dirPath, zip, entries[i]);
|
|
192
|
+
onEntry();
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const createZip = (dirPath, zipPath, entries, onEntry) => {
|
|
196
|
+
return new Promise((resolve, reject) => {
|
|
197
|
+
const ws = fs_1.default.createWriteStream(zipPath);
|
|
198
|
+
let wasError = false;
|
|
199
|
+
const zip = new fflate_1.default.Zip((err, data, final) => {
|
|
200
|
+
if (wasError) {
|
|
201
|
+
// do nothing
|
|
202
|
+
}
|
|
203
|
+
else if (err) {
|
|
204
|
+
wasError = true;
|
|
205
|
+
ws.close();
|
|
206
|
+
reject(err);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
ws.write(data);
|
|
210
|
+
if (final) {
|
|
211
|
+
ws.close((err) => {
|
|
212
|
+
if (err)
|
|
213
|
+
reject(err);
|
|
214
|
+
else
|
|
215
|
+
resolve();
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
addEntriesToZip(dirPath, zip, entries, onEntry)
|
|
221
|
+
.then(() => {
|
|
222
|
+
zip.end();
|
|
223
|
+
})
|
|
224
|
+
.catch((err) => {
|
|
225
|
+
ws.close(() => {
|
|
226
|
+
reject(err);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
exports.default = commandPackagePublish;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const texts_1 = require("../texts");
|
|
8
|
+
const publish_1 = __importDefault(require("./package/publish"));
|
|
9
|
+
const download_1 = __importDefault(require("./package/download"));
|
|
10
|
+
const commandPackage = (0, utils_1.newCommand)('package', texts_1.DESC_COMMAND_PACKAGE);
|
|
11
|
+
commandPackage.alias('pkg');
|
|
12
|
+
commandPackage.addCommand(publish_1.default);
|
|
13
|
+
commandPackage.addCommand(download_1.default);
|
|
14
|
+
exports.default = commandPackage;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const cfg_1 = __importDefault(require("../../tunnel/cfg"));
|
|
7
|
+
const output_1 = __importDefault(require("../../output"));
|
|
8
|
+
const client_1 = __importDefault(require("../../api/client"));
|
|
9
|
+
const texts_1 = require("../../texts");
|
|
10
|
+
const utils_1 = require("../../utils");
|
|
11
|
+
const commandProjectList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_PROJECT_LIST);
|
|
12
|
+
commandProjectList.alias('ls');
|
|
13
|
+
commandProjectList.action(async () => {
|
|
14
|
+
const token = cfg_1.default.getToken();
|
|
15
|
+
if (!token) {
|
|
16
|
+
output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_LOGGED_IN);
|
|
17
|
+
}
|
|
18
|
+
const workspace = cfg_1.default.getWorkspace();
|
|
19
|
+
if (!workspace) {
|
|
20
|
+
output_1.default.exitError(texts_1.TXT_WORKSPACE_NONE);
|
|
21
|
+
}
|
|
22
|
+
const baseUrl = cfg_1.default.getBaseUrl();
|
|
23
|
+
const region = cfg_1.default.getRegion();
|
|
24
|
+
const currentProject = cfg_1.default.getProject();
|
|
25
|
+
let apiUrl;
|
|
26
|
+
if (baseUrl) {
|
|
27
|
+
apiUrl = baseUrl;
|
|
28
|
+
}
|
|
29
|
+
else if (region?.toLowerCase() === 'eu') {
|
|
30
|
+
apiUrl = 'api.eu.buddy.works';
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
apiUrl = 'api.buddy.works';
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const client = new client_1.default(new URL(`https://${apiUrl}`), token);
|
|
37
|
+
const response = await client.getProjects(workspace);
|
|
38
|
+
if (!response.projects || response.projects.length === 0) {
|
|
39
|
+
output_1.default.exitError(texts_1.ERR_PROJECT_NO_PROJECTS);
|
|
40
|
+
}
|
|
41
|
+
const data = [['NAME', 'DISPLAY NAME', 'STATUS', '']];
|
|
42
|
+
for (const proj of response.projects) {
|
|
43
|
+
const isCurrent = proj.name === currentProject;
|
|
44
|
+
data.push([
|
|
45
|
+
proj.name,
|
|
46
|
+
proj.display_name,
|
|
47
|
+
proj.status,
|
|
48
|
+
isCurrent ? '(current)' : '',
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
51
|
+
output_1.default.table(data);
|
|
52
|
+
if (currentProject) {
|
|
53
|
+
output_1.default.normal(`\n${(0, texts_1.TXT_PROJECT_CURRENT)(currentProject)}`);
|
|
54
|
+
}
|
|
55
|
+
process.exit(0);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
output_1.default.exitError(err);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
exports.default = commandProjectList;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
const termkit_no_lazy_require_1 = __importDefault(require("terminal-kit/lib/termkit-no-lazy-require"));
|
|
8
|
+
const cfg_1 = __importDefault(require("../../tunnel/cfg"));
|
|
9
|
+
const output_1 = __importDefault(require("../../output"));
|
|
10
|
+
const client_1 = __importDefault(require("../../api/client"));
|
|
11
|
+
const texts_1 = require("../../texts");
|
|
12
|
+
const utils_1 = require("../../utils");
|
|
13
|
+
const terminal = termkit_no_lazy_require_1.default.terminal;
|
|
14
|
+
// Handle Ctrl+C and ESC
|
|
15
|
+
terminal.on('key', (key) => {
|
|
16
|
+
if (key === 'CTRL_C' || key === 'ESCAPE') {
|
|
17
|
+
terminal.grabInput(false);
|
|
18
|
+
terminal('\nCanceled\n');
|
|
19
|
+
process.exit(0);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
async function selectProject(projects, currentName) {
|
|
23
|
+
terminal(`${texts_1.TXT_PROJECT_SELECT}\n`);
|
|
24
|
+
const items = projects.map((p) => {
|
|
25
|
+
const isCurrent = p.name === currentName;
|
|
26
|
+
return `${p.display_name} (${p.name})${isCurrent ? ' (current)' : ''}`;
|
|
27
|
+
});
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
terminal.singleColumnMenu(items, (error, response) => {
|
|
30
|
+
terminal('\n');
|
|
31
|
+
resolve(projects[response.selectedIndex]);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const commandProjectSet = (0, utils_1.newCommand)('set', texts_1.DESC_COMMAND_PROJECT_SET);
|
|
36
|
+
commandProjectSet.argument('[project]', 'Project name to set');
|
|
37
|
+
commandProjectSet.action(async (projectName) => {
|
|
38
|
+
const token = cfg_1.default.getToken();
|
|
39
|
+
if (!token) {
|
|
40
|
+
output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_LOGGED_IN);
|
|
41
|
+
}
|
|
42
|
+
const workspace = cfg_1.default.getWorkspace();
|
|
43
|
+
if (!workspace) {
|
|
44
|
+
output_1.default.exitError(texts_1.TXT_WORKSPACE_NONE);
|
|
45
|
+
}
|
|
46
|
+
const baseUrl = cfg_1.default.getBaseUrl();
|
|
47
|
+
const region = cfg_1.default.getRegion();
|
|
48
|
+
const currentProject = cfg_1.default.getProject();
|
|
49
|
+
let apiUrl;
|
|
50
|
+
if (baseUrl) {
|
|
51
|
+
apiUrl = baseUrl;
|
|
52
|
+
}
|
|
53
|
+
else if (region?.toLowerCase() === 'eu') {
|
|
54
|
+
apiUrl = 'api.eu.buddy.works';
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
apiUrl = 'api.buddy.works';
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const client = new client_1.default(new URL(`https://${apiUrl}`), token);
|
|
61
|
+
const response = await client.getProjects(workspace);
|
|
62
|
+
if (!response.projects || response.projects.length === 0) {
|
|
63
|
+
output_1.default.exitError(texts_1.ERR_PROJECT_NO_PROJECTS);
|
|
64
|
+
}
|
|
65
|
+
let selectedProject;
|
|
66
|
+
if (projectName) {
|
|
67
|
+
// Project provided as argument
|
|
68
|
+
const found = response.projects.find((p) => p.name === projectName);
|
|
69
|
+
if (!found) {
|
|
70
|
+
output_1.default.exitError((0, texts_1.ERR_PROJECT_NOT_FOUND)(projectName));
|
|
71
|
+
}
|
|
72
|
+
selectedProject = found;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// Interactive selection
|
|
76
|
+
selectedProject = await selectProject(response.projects, currentProject);
|
|
77
|
+
}
|
|
78
|
+
cfg_1.default.setProject(selectedProject.name);
|
|
79
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PROJECT_SET_SUCCESS)(selectedProject.name));
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
output_1.default.exitError(err);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
exports.default = commandProjectSet;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const texts_1 = require("../texts");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const list_1 = __importDefault(require("./project/list"));
|
|
9
|
+
const set_1 = __importDefault(require("./project/set"));
|
|
10
|
+
const commandProject = (0, utils_1.newCommand)('project', texts_1.DESC_COMMAND_PROJECT);
|
|
11
|
+
commandProject.alias('proj');
|
|
12
|
+
commandProject.addCommand(list_1.default);
|
|
13
|
+
commandProject.addCommand(set_1.default);
|
|
14
|
+
exports.default = commandProject;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const client_1 = __importDefault(require("../../../api/client"));
|
|
11
|
+
const commandSandboxCommandKill = (0, utils_1.newCommand)('kill', texts_1.DESC_COMMAND_SANDBOX_COMMAND_KILL);
|
|
12
|
+
commandSandboxCommandKill.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
13
|
+
commandSandboxCommandKill.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
14
|
+
commandSandboxCommandKill.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
15
|
+
commandSandboxCommandKill.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
16
|
+
commandSandboxCommandKill.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
17
|
+
commandSandboxCommandKill.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
18
|
+
commandSandboxCommandKill.argument('<command-id>', texts_1.OPTION_SANDBOX_COMMAND_ID);
|
|
19
|
+
commandSandboxCommandKill.action(async (identifier, commandId, options) => {
|
|
20
|
+
const token = input_1.default.restApiToken(options.token);
|
|
21
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
22
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
23
|
+
const project = input_1.default.restApiProject(options.project);
|
|
24
|
+
const client = new client_1.default(baseUrl, token);
|
|
25
|
+
// Find sandbox by identifier
|
|
26
|
+
const result = await client.listSandboxes(workspace, project);
|
|
27
|
+
const sandboxes = result.sandboxes || [];
|
|
28
|
+
const found = sandboxes.find((s) => s.identifier === identifier);
|
|
29
|
+
if (!found) {
|
|
30
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
31
|
+
}
|
|
32
|
+
await client.terminateSandboxCommand(workspace, found.id, commandId);
|
|
33
|
+
output_1.default.exitSuccess((0, texts_1.TXT_SANDBOX_COMMAND_KILLED)(commandId));
|
|
34
|
+
});
|
|
35
|
+
exports.default = commandSandboxCommandKill;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const client_1 = __importDefault(require("../../../api/client"));
|
|
11
|
+
const commandSandboxCommandList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_SANDBOX_COMMAND_LIST);
|
|
12
|
+
commandSandboxCommandList.alias('ls');
|
|
13
|
+
commandSandboxCommandList.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
14
|
+
commandSandboxCommandList.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
15
|
+
commandSandboxCommandList.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
16
|
+
commandSandboxCommandList.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
17
|
+
commandSandboxCommandList.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
18
|
+
commandSandboxCommandList.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
19
|
+
commandSandboxCommandList.action(async (identifier, options) => {
|
|
20
|
+
const token = input_1.default.restApiToken(options.token);
|
|
21
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
22
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
23
|
+
const project = input_1.default.restApiProject(options.project);
|
|
24
|
+
const client = new client_1.default(baseUrl, token);
|
|
25
|
+
// Find sandbox by identifier
|
|
26
|
+
const result = await client.listSandboxes(workspace, project);
|
|
27
|
+
const sandboxes = result.sandboxes || [];
|
|
28
|
+
const found = sandboxes.find((s) => s.identifier === identifier);
|
|
29
|
+
if (!found) {
|
|
30
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
31
|
+
}
|
|
32
|
+
const commandsResult = await client.listSandboxCommands(workspace, found.id);
|
|
33
|
+
const commands = commandsResult.commands || [];
|
|
34
|
+
if (commands.length === 0) {
|
|
35
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NO_COMMANDS);
|
|
36
|
+
}
|
|
37
|
+
// Sort by ID descending (IDs are timestamp-based, so newest first)
|
|
38
|
+
commands.sort((a, b) => (b.id || '').localeCompare(a.id || ''));
|
|
39
|
+
const data = [
|
|
40
|
+
['ID', 'COMMAND', 'STATUS', 'EXIT CODE', 'RUNTIME'],
|
|
41
|
+
];
|
|
42
|
+
for (const cmd of commands) {
|
|
43
|
+
data.push([
|
|
44
|
+
cmd.id || '-',
|
|
45
|
+
(cmd.command || '-').substring(0, 40) + (cmd.command?.length > 40 ? '...' : ''),
|
|
46
|
+
cmd.status || '-',
|
|
47
|
+
cmd.exit_code !== undefined ? String(cmd.exit_code) : '-',
|
|
48
|
+
cmd.runtime || 'BASH',
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
51
|
+
output_1.default.table(data);
|
|
52
|
+
output_1.default.exitNormal();
|
|
53
|
+
});
|
|
54
|
+
exports.default = commandSandboxCommandList;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const client_1 = __importDefault(require("../../../api/client"));
|
|
11
|
+
const commandSandboxCommandLogs = (0, utils_1.newCommand)('logs', texts_1.DESC_COMMAND_SANDBOX_COMMAND_LOGS);
|
|
12
|
+
commandSandboxCommandLogs.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
13
|
+
commandSandboxCommandLogs.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
14
|
+
commandSandboxCommandLogs.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
15
|
+
commandSandboxCommandLogs.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
16
|
+
commandSandboxCommandLogs.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
17
|
+
commandSandboxCommandLogs.option('-f, --follow', texts_1.OPTION_SANDBOX_COMMAND_FOLLOW);
|
|
18
|
+
commandSandboxCommandLogs.option('-l, --last', texts_1.OPTION_SANDBOX_COMMAND_LAST);
|
|
19
|
+
commandSandboxCommandLogs.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
20
|
+
commandSandboxCommandLogs.argument('[command-id]', texts_1.OPTION_SANDBOX_COMMAND_ID);
|
|
21
|
+
commandSandboxCommandLogs.action(async (identifier, commandId, options) => {
|
|
22
|
+
const token = input_1.default.restApiToken(options.token);
|
|
23
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
24
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
25
|
+
const project = input_1.default.restApiProject(options.project);
|
|
26
|
+
const client = new client_1.default(baseUrl, token);
|
|
27
|
+
// Find sandbox by identifier
|
|
28
|
+
const result = await client.listSandboxes(workspace, project);
|
|
29
|
+
const sandboxes = result.sandboxes || [];
|
|
30
|
+
const found = sandboxes.find((s) => s.identifier === identifier);
|
|
31
|
+
if (!found) {
|
|
32
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
33
|
+
}
|
|
34
|
+
// If --last flag is used or no command-id provided, get the most recent command
|
|
35
|
+
let resolvedCommandId = commandId || '';
|
|
36
|
+
if (options.last || !commandId) {
|
|
37
|
+
const commandsResult = await client.listSandboxCommands(workspace, found.id);
|
|
38
|
+
const commands = commandsResult.commands || [];
|
|
39
|
+
if (commands.length === 0) {
|
|
40
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NO_COMMANDS);
|
|
41
|
+
}
|
|
42
|
+
// Sort by ID descending (IDs are timestamp-based, so newest first)
|
|
43
|
+
commands.sort((a, b) => (b.id || '').localeCompare(a.id || ''));
|
|
44
|
+
resolvedCommandId = commands[0].id;
|
|
45
|
+
}
|
|
46
|
+
const logsUrl = await client.getSandboxCommandLogsUrl(workspace, found.id, resolvedCommandId);
|
|
47
|
+
try {
|
|
48
|
+
const response = await fetch(logsUrl, {
|
|
49
|
+
method: 'GET',
|
|
50
|
+
headers: {
|
|
51
|
+
Accept: 'application/jsonl',
|
|
52
|
+
Authorization: `Bearer ${token}`,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
if (response.ok && response.body) {
|
|
56
|
+
if (options.follow) {
|
|
57
|
+
// Streaming mode - read and output as data arrives
|
|
58
|
+
const reader = response.body.getReader();
|
|
59
|
+
const decoder = new TextDecoder();
|
|
60
|
+
let buffer = '';
|
|
61
|
+
while (true) {
|
|
62
|
+
const { done, value } = await reader.read();
|
|
63
|
+
if (done)
|
|
64
|
+
break;
|
|
65
|
+
buffer += decoder.decode(value, { stream: true });
|
|
66
|
+
const lines = buffer.split('\n');
|
|
67
|
+
buffer = lines.pop() || '';
|
|
68
|
+
for (const line of lines) {
|
|
69
|
+
if (!line.trim())
|
|
70
|
+
continue;
|
|
71
|
+
try {
|
|
72
|
+
const logEntry = JSON.parse(line);
|
|
73
|
+
const content = logEntry.data ?? logEntry.message ?? '';
|
|
74
|
+
if (content) {
|
|
75
|
+
if (logEntry.stream === 'stderr' || logEntry.type === 'STDERR') {
|
|
76
|
+
process.stderr.write(content + '\n');
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
process.stdout.write(content + '\n');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
process.stdout.write(line + '\n');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Process remaining buffer
|
|
89
|
+
if (buffer.trim()) {
|
|
90
|
+
try {
|
|
91
|
+
const logEntry = JSON.parse(buffer);
|
|
92
|
+
const content = logEntry.data ?? logEntry.message ?? '';
|
|
93
|
+
if (content) {
|
|
94
|
+
process.stdout.write(content + '\n');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
process.stdout.write(buffer + '\n');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Default mode - fetch all and output at once
|
|
104
|
+
const text = await response.text();
|
|
105
|
+
const lines = text.split('\n');
|
|
106
|
+
for (const line of lines) {
|
|
107
|
+
if (!line.trim())
|
|
108
|
+
continue;
|
|
109
|
+
try {
|
|
110
|
+
const logEntry = JSON.parse(line);
|
|
111
|
+
const content = logEntry.data ?? logEntry.message ?? '';
|
|
112
|
+
if (content) {
|
|
113
|
+
if (logEntry.stream === 'stderr' || logEntry.type === 'STDERR') {
|
|
114
|
+
process.stderr.write(content + '\n');
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
process.stdout.write(content + '\n');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
process.stdout.write(line + '\n');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
output_1.default.exitError(err);
|
|
130
|
+
}
|
|
131
|
+
output_1.default.exitNormal();
|
|
132
|
+
});
|
|
133
|
+
exports.default = commandSandboxCommandLogs;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const client_1 = __importDefault(require("../../../api/client"));
|
|
11
|
+
const commandSandboxCommandStatus = (0, utils_1.newCommand)('status', texts_1.DESC_COMMAND_SANDBOX_COMMAND_STATUS);
|
|
12
|
+
commandSandboxCommandStatus.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
13
|
+
commandSandboxCommandStatus.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
14
|
+
commandSandboxCommandStatus.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
15
|
+
commandSandboxCommandStatus.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
16
|
+
commandSandboxCommandStatus.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
17
|
+
commandSandboxCommandStatus.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
18
|
+
commandSandboxCommandStatus.argument('<command-id>', texts_1.OPTION_SANDBOX_COMMAND_ID);
|
|
19
|
+
commandSandboxCommandStatus.action(async (identifier, commandId, options) => {
|
|
20
|
+
const token = input_1.default.restApiToken(options.token);
|
|
21
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
22
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
23
|
+
const project = input_1.default.restApiProject(options.project);
|
|
24
|
+
const client = new client_1.default(baseUrl, token);
|
|
25
|
+
// Find sandbox by identifier
|
|
26
|
+
const result = await client.listSandboxes(workspace, project);
|
|
27
|
+
const sandboxes = result.sandboxes || [];
|
|
28
|
+
const found = sandboxes.find((s) => s.identifier === identifier);
|
|
29
|
+
if (!found) {
|
|
30
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
31
|
+
}
|
|
32
|
+
const cmd = await client.getSandboxCommand(workspace, found.id, commandId);
|
|
33
|
+
const data = [
|
|
34
|
+
['Property', 'Value'],
|
|
35
|
+
['Command ID', cmd.id || '-'],
|
|
36
|
+
['Command', cmd.command || '-'],
|
|
37
|
+
['Runtime', cmd.runtime || 'BASH'],
|
|
38
|
+
['Status', cmd.status || '-'],
|
|
39
|
+
['Exit Code', cmd.exit_code !== undefined ? String(cmd.exit_code) : '-'],
|
|
40
|
+
];
|
|
41
|
+
output_1.default.table(data);
|
|
42
|
+
output_1.default.exitNormal();
|
|
43
|
+
});
|
|
44
|
+
exports.default = commandSandboxCommandStatus;
|