bdy 1.25.3-dev → 1.25.5-dev

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 (47) hide show
  1. package/distTs/package.json +2 -1
  2. package/distTs/src/agent/socket/tunnel.js +2 -0
  3. package/distTs/src/api/client.js +22 -55
  4. package/distTs/src/cliCommand.js +52 -0
  5. package/distTs/src/cliError.js +34 -0
  6. package/distTs/src/cliIndex.js +3 -1
  7. package/distTs/src/command/agent/proxy/status.js +9 -2
  8. package/distTs/src/command/agent/status.js +22 -6
  9. package/distTs/src/command/agent/tags/get.js +9 -2
  10. package/distTs/src/command/agent/target/status.js +9 -2
  11. package/distTs/src/command/agent/tunnel/list.js +6 -1
  12. package/distTs/src/command/agent/tunnel/status.js +13 -1
  13. package/distTs/src/command/agent/version.js +7 -2
  14. package/distTs/src/command/api/info.js +50 -2
  15. package/distTs/src/command/api/list.js +18 -2
  16. package/distTs/src/command/artifact/create.js +5 -0
  17. package/distTs/src/command/artifact/publish.js +20 -22
  18. package/distTs/src/command/artifact/version/create.js +5 -0
  19. package/distTs/src/command/config/get/tunnel.js +8 -3
  20. package/distTs/src/command/config/get/tunnels.js +8 -3
  21. package/distTs/src/command/discover.js +9 -11
  22. package/distTs/src/command/distro/create.js +5 -0
  23. package/distTs/src/command/distro/route/create.js +5 -0
  24. package/distTs/src/command/distro/route/update.js +5 -0
  25. package/distTs/src/command/distro/update.js +5 -0
  26. package/distTs/src/command/domain/search.js +31 -10
  27. package/distTs/src/command/environment/create.js +5 -0
  28. package/distTs/src/command/environment/update.js +5 -0
  29. package/distTs/src/command/sandbox/app/add.js +7 -1
  30. package/distTs/src/command/sandbox/app/logs.js +9 -4
  31. package/distTs/src/command/sandbox/create.js +13 -5
  32. package/distTs/src/command/sandbox/endpoint/add.js +5 -0
  33. package/distTs/src/command/sandbox/exec/command.js +15 -30
  34. package/distTs/src/command/sandbox/exec/logs.js +4 -29
  35. package/distTs/src/command/sandbox/finishExec.js +34 -0
  36. package/distTs/src/command/sandbox/logs.js +14 -1
  37. package/distTs/src/command/sandbox/snapshot/create.js +9 -1
  38. package/distTs/src/command/target/create.js +5 -0
  39. package/distTs/src/command/target/exec/logs.js +15 -2
  40. package/distTs/src/command/target/update.js +5 -0
  41. package/distTs/src/command/yaml/validate.js +111 -52
  42. package/distTs/src/index.js +6 -1
  43. package/distTs/src/input.js +12 -11
  44. package/distTs/src/openapi.js +8 -1
  45. package/distTs/src/output.js +55 -13
  46. package/distTs/src/texts.js +272 -59
  47. package/package.json +2 -1
@@ -25,8 +25,10 @@ commandArtifactPublish.option('--agent-note <note>', texts_1.OPTION_ARTIFACT_VER
25
25
  commandArtifactPublish.option('-f, --force', texts_1.OPTION_ARTIFACT_PUBLISH_OVERWRITE_VERSION);
26
26
  commandArtifactPublish.argument('<identifier>', texts_1.OPTION_ARTIFACT_ID);
27
27
  commandArtifactPublish.argument('<directory>', texts_1.OPTION_ARTIFACT_PUBLISH_PATH);
28
+ commandArtifactPublish.option('--format <text|json>', texts_1.OPTION_FORMAT);
28
29
  commandArtifactPublish.action(async (id, path, options) => {
29
30
  const { v4 } = require('uuid');
31
+ const say = output_1.default.progress(options.format === 'json');
30
32
  let dirPath = input_1.default.resolvePath(path);
31
33
  const workspace = input_1.default.restApiWorkspace(options.workspace);
32
34
  const project = input_1.default.restApiProject(options.project, true);
@@ -66,20 +68,15 @@ commandArtifactPublish.action(async (id, path, options) => {
66
68
  }
67
69
  }
68
70
  let artifactVersionId = data.artifact_version_id;
69
- let url;
70
71
  if (artifactVersionId && !options.force) {
71
72
  output_1.default.exitError(texts_1.ERR_ARTIFACT_VERSION_EXISTS);
72
73
  }
73
- if (!artifactVersionId) {
74
- const d = await client.createArtifactVersion(workspace, artifactId, version, options.note, options.agentNote);
75
- url = d.version_url;
76
- artifactVersionId = d.id;
77
- }
78
- else {
79
- const d = await client.getArtifactVersion(workspace, artifactId, artifactVersionId);
80
- url = d.version_url;
81
- }
82
- output_1.default.normal(texts_1.TXT_ARTIFACT_SCANNING_DIR, false);
74
+ const artifactVersion = !artifactVersionId
75
+ ? await client.createArtifactVersion(workspace, artifactId, version, options.note, options.agentNote)
76
+ : await client.getArtifactVersion(workspace, artifactId, artifactVersionId);
77
+ const url = artifactVersion.version_url;
78
+ artifactVersionId = artifactVersion.id;
79
+ say(texts_1.TXT_ARTIFACT_SCANNING_DIR, false);
83
80
  const stat = fs_1.default.statSync(dirPath);
84
81
  let entries;
85
82
  if (stat.isDirectory()) {
@@ -106,6 +103,10 @@ commandArtifactPublish.action(async (id, path, options) => {
106
103
  dirPath = parentPath;
107
104
  }
108
105
  const outputSuccess = () => {
106
+ if (options.format === 'json') {
107
+ output_1.default.json(artifactVersion);
108
+ output_1.default.exitNormal();
109
+ }
109
110
  output_1.default.object({
110
111
  Version: `${identifier}:${version}`,
111
112
  URL: url || '-',
@@ -114,16 +115,16 @@ commandArtifactPublish.action(async (id, path, options) => {
114
115
  output_1.default.exitNormal();
115
116
  };
116
117
  if (!entries.length) {
117
- output_1.default.normal(texts_1.TXT_ARTIFACT_NO_ENTRIES_FOUND);
118
+ say(texts_1.TXT_ARTIFACT_NO_ENTRIES_FOUND);
118
119
  outputSuccess();
119
120
  }
120
121
  else if (entries.length === 1) {
121
- output_1.default.normal(texts_1.TXT_ARTIFACT_ONE_ENTRY_FOUND);
122
+ say(texts_1.TXT_ARTIFACT_ONE_ENTRY_FOUND);
122
123
  }
123
124
  else {
124
- output_1.default.normal((0, texts_1.TXT_ARTIFACT_ENTRIES_FOUND)(entries.length));
125
+ say((0, texts_1.TXT_ARTIFACT_ENTRIES_FOUND)(entries.length));
125
126
  }
126
- output_1.default.normal((0, texts_1.TXT_ARTIFACT_ZIP_ENTRIES)(0));
127
+ say((0, texts_1.TXT_ARTIFACT_ZIP_ENTRIES)(0));
127
128
  const zipPath = (0, path_1.join)((0, utils_1.getHomeDirectory)(), `${v4()}.zip`);
128
129
  const clearZip = () => {
129
130
  try {
@@ -138,11 +139,9 @@ commandArtifactPublish.action(async (id, path, options) => {
138
139
  let proc = 0;
139
140
  await (0, utils_1.createZip)(dirPath, zipPath, entries, () => {
140
141
  proc += 1;
141
- output_1.default.clearPreviousLine();
142
- output_1.default.normal((0, texts_1.TXT_ARTIFACT_ZIP_ENTRIES)(proc));
142
+ say((0, texts_1.TXT_ARTIFACT_ZIP_ENTRIES)(proc), true, true);
143
143
  });
144
- output_1.default.clearPreviousLine();
145
- output_1.default.normal(texts_1.TXT_ARTIFACT_ZIPPED);
144
+ say(texts_1.TXT_ARTIFACT_ZIPPED, true, true);
146
145
  blob = await fs_1.default.openAsBlob(zipPath);
147
146
  }
148
147
  catch (err) {
@@ -151,10 +150,9 @@ commandArtifactPublish.action(async (id, path, options) => {
151
150
  output_1.default.exitError(texts_1.ERR_SWW);
152
151
  }
153
152
  try {
154
- output_1.default.normal(texts_1.TXT_ARTIFACT_UPLOADING);
153
+ say(texts_1.TXT_ARTIFACT_UPLOADING);
155
154
  await client.createArtifactVersionZip(workspace, artifactId, artifactVersionId, blob);
156
- output_1.default.clearPreviousLine();
157
- output_1.default.normal(texts_1.TXT_ARTIFACT_UPLOADED);
155
+ say(texts_1.TXT_ARTIFACT_UPLOADED, true, true);
158
156
  clearZip();
159
157
  outputSuccess();
160
158
  }
@@ -21,6 +21,7 @@ commandArtifactVersionCreate.option('--note <note>', texts_1.OPTION_ARTIFACT_VER
21
21
  commandArtifactVersionCreate.option('--agent-note <note>', texts_1.OPTION_ARTIFACT_VERSION_AGENT_NOTE);
22
22
  commandArtifactVersionCreate.option('--from <version>', texts_1.OPTION_ARTIFACT_VERSION_FROM);
23
23
  commandArtifactVersionCreate.argument('<identifier>', texts_1.OPTION_ARTIFACT_ID);
24
+ commandArtifactVersionCreate.option('--format <text|json>', texts_1.OPTION_FORMAT);
24
25
  commandArtifactVersionCreate.action(async (id, options) => {
25
26
  const workspace = input_1.default.restApiWorkspace(options.workspace);
26
27
  const project = input_1.default.restApiProject(options.project, true);
@@ -64,6 +65,10 @@ commandArtifactVersionCreate.action(async (id, options) => {
64
65
  output_1.default.exitError(texts_1.ERR_ARTIFACT_VERSION_EXISTS_NO_FORCE);
65
66
  }
66
67
  const d = await client.createArtifactVersion(workspace, artifactId, version, options.note, options.agentNote, options.from);
68
+ if (options.format === 'json') {
69
+ output_1.default.json(d);
70
+ output_1.default.exitNormal();
71
+ }
67
72
  const url = d.version_url;
68
73
  output_1.default.object({
69
74
  Version: `${identifier}:${version}`,
@@ -7,13 +7,18 @@ const cfg_1 = __importDefault(require("../../../tunnel/cfg"));
7
7
  const output_1 = __importDefault(require("../../../output"));
8
8
  const texts_1 = require("../../../texts");
9
9
  const utils_1 = require("../../../utils");
10
- const commandConfigGetTunnel = (0, utils_1.newCommand)('tunnel', texts_1.DESC_COMMAND_CONFIG_GET_TUNNEL);
10
+ const commandConfigGetTunnel = (0, utils_1.newCommand)('tunnel', texts_1.DESC_COMMAND_CONFIG_GET_TUNNEL, { examples: texts_1.EXAMPLE_CONFIG_GET_TUNNEL });
11
11
  commandConfigGetTunnel.argument('<name>', texts_1.OPTION_NAME);
12
- commandConfigGetTunnel.action((name) => {
12
+ commandConfigGetTunnel.option('--format <text|json>', texts_1.OPTION_FORMAT);
13
+ commandConfigGetTunnel.action((name, options) => {
13
14
  if (!cfg_1.default.hasTunnel(name)) {
14
15
  output_1.default.exitError((0, texts_1.ERR_TUNNEL_NOT_FOUND)(name));
15
16
  }
16
- output_1.default.configTunnel(cfg_1.default.getTunnel(name));
17
+ if (options.format === 'json') {
18
+ output_1.default.json(cfg_1.default.getTunnel(name));
19
+ }
20
+ else
21
+ output_1.default.configTunnel(cfg_1.default.getTunnel(name));
17
22
  output_1.default.exitNormal();
18
23
  });
19
24
  exports.default = commandConfigGetTunnel;
@@ -7,9 +7,14 @@ const cfg_1 = __importDefault(require("../../../tunnel/cfg"));
7
7
  const output_1 = __importDefault(require("../../../output"));
8
8
  const texts_1 = require("../../../texts");
9
9
  const utils_1 = require("../../../utils");
10
- const commandConfigGetTunnels = (0, utils_1.newCommand)('tunnels', texts_1.DESC_COMMAND_CONFIG_GET_TUNNELS);
11
- commandConfigGetTunnels.action(() => {
12
- output_1.default.configTunnels(cfg_1.default.getTunnels());
10
+ const commandConfigGetTunnels = (0, utils_1.newCommand)('tunnels', texts_1.DESC_COMMAND_CONFIG_GET_TUNNELS, { examples: texts_1.EXAMPLE_CONFIG_GET_TUNNELS });
11
+ commandConfigGetTunnels.option('--format <text|json>', texts_1.OPTION_FORMAT);
12
+ commandConfigGetTunnels.action((options) => {
13
+ if (options.format === 'json') {
14
+ output_1.default.json(cfg_1.default.getTunnels());
15
+ }
16
+ else
17
+ output_1.default.configTunnels(cfg_1.default.getTunnels());
13
18
  output_1.default.exitNormal();
14
19
  });
15
20
  exports.default = commandConfigGetTunnels;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const discovery_1 = require("../discovery");
7
7
  const output_1 = __importDefault(require("../output"));
8
+ const cliError_1 = __importDefault(require("../cliError"));
8
9
  const texts_1 = require("../texts");
9
10
  const utils_1 = require("../utils");
10
11
  const commandDiscover = (0, utils_1.newCommand)('discover', texts_1.DESC_COMMAND_DISCOVER, {
@@ -13,22 +14,19 @@ const commandDiscover = (0, utils_1.newCommand)('discover', texts_1.DESC_COMMAND
13
14
  helpText: texts_1.HELP_COMMAND_DISCOVER,
14
15
  });
15
16
  commandDiscover.skipPre = true;
17
+ commandDiscover.defaultErrorFormat = 'json';
16
18
  commandDiscover.showSuggestionAfterError(false);
17
- commandDiscover.configureOutput({
18
- outputError: (message) => output_1.default.json({
19
- error: {
20
- code: 'usage_error',
21
- message: message.trim(),
22
- hint: texts_1.TXT_DISCOVER_USAGE_HINT,
23
- },
24
- }),
25
- });
26
19
  commandDiscover.argument('[command...]', texts_1.OPTION_DISCOVER_COMMAND);
27
20
  commandDiscover.option('--full', texts_1.OPTION_DISCOVER_FULL);
28
21
  commandDiscover.action((path, options, command) => {
29
22
  const result = (0, discovery_1.discoverCommands)(command.parent, path, (0, utils_1.getVersion)(), options.full);
30
- output_1.default.json(result);
31
- if ('error' in result)
23
+ if (result.error) {
24
+ const { code, message, hint } = result.error;
25
+ output_1.default.writeError(new cliError_1.default(code, message, hint), 'json');
32
26
  process.exitCode = 1;
27
+ }
28
+ else {
29
+ output_1.default.json(result);
30
+ }
33
31
  });
34
32
  exports.default = commandDiscover;
@@ -20,6 +20,7 @@ commandDistroCreate.option('-i, --identifier <identifier>', texts_1.OPT_COMMAND_
20
20
  commandDistroCreate.option('-n, --name <name>', texts_1.OPT_COMMAND_DISTRO_NAME);
21
21
  commandDistroCreate.option('--note <note>', texts_1.OPT_COMMAND_DISTRO_NOTE);
22
22
  commandDistroCreate.option('--agent-note <note>', texts_1.OPT_COMMAND_DISTRO_AGENT_NOTE);
23
+ commandDistroCreate.option('--format <text|json>', texts_1.OPTION_FORMAT);
23
24
  commandDistroCreate.action(async (options) => {
24
25
  const humanId = require('human-id').default;
25
26
  const workspace = input_1.default.restApiWorkspace(options.workspace);
@@ -43,6 +44,10 @@ commandDistroCreate.action(async (options) => {
43
44
  if (project && scope === distro_1.SCOPE.PROJECT)
44
45
  body.project_name = project;
45
46
  const result = await client.createDistro(workspace, body);
47
+ if (options.format === 'json') {
48
+ output_1.default.json(result);
49
+ output_1.default.exitNormal();
50
+ }
46
51
  output_1.default.identifier(result.identifier);
47
52
  output_1.default.cyan(result.html_url);
48
53
  output_1.default.green(texts_1.TXT_COMMAND_DISTRO_CREATED);
@@ -24,6 +24,7 @@ commandDistroRouteCreate.option('--note <note>', texts_1.OPT_COMMAND_ROUTE_NOTE)
24
24
  commandDistroRouteCreate.option('--agent-note <note>', texts_1.OPT_COMMAND_ROUTE_AGENT_NOTE);
25
25
  commandDistroRouteCreate.option('--target <targets...>', texts_1.OPT_COMMAND_ROUTE_TARGET);
26
26
  commandDistroRouteCreate.argument('<identifier>', texts_1.OPT_COMMAND_DISTRO_IDENTIFIER);
27
+ commandDistroRouteCreate.option('--format <text|json>', texts_1.OPTION_FORMAT);
27
28
  commandDistroRouteCreate.action(async (identifier, options) => {
28
29
  const workspace = input_1.default.restApiWorkspace(options.workspace);
29
30
  const project = input_1.default.restApiProject(options.project, true);
@@ -53,6 +54,10 @@ commandDistroRouteCreate.action(async (identifier, options) => {
53
54
  }
54
55
  body.targets = await input_1.default.routeTarget(client, workspace, scope === distro_1.SCOPE.PROJECT ? project : null, options.target);
55
56
  const result = await client.createRoute(workspace, scope === distro_1.SCOPE.PROJECT ? project : null, data.distribution_id, body);
57
+ if (options.format === 'json') {
58
+ output_1.default.json(result);
59
+ output_1.default.exitNormal();
60
+ }
56
61
  output_1.default.id(result.id);
57
62
  output_1.default.cyan(result.html_url);
58
63
  output_1.default.green(texts_1.TXT_COMMAND_ROUTE_CREATED);
@@ -25,6 +25,7 @@ commandDistroRouteUpdate.option('--agent-note <note>', texts_1.OPT_COMMAND_ROUTE
25
25
  commandDistroRouteUpdate.option('--target <targets...>', texts_1.OPT_COMMAND_ROUTE_TARGET);
26
26
  commandDistroRouteUpdate.argument('<identifier>', texts_1.OPT_COMMAND_DISTRO_IDENTIFIER);
27
27
  commandDistroRouteUpdate.argument('<route-id>', texts_1.OPT_COMMAND_ROUTE_ID);
28
+ commandDistroRouteUpdate.option('--format <text|json>', texts_1.OPTION_FORMAT);
28
29
  commandDistroRouteUpdate.action(async (identifier, routeId, options) => {
29
30
  const workspace = input_1.default.restApiWorkspace(options.workspace);
30
31
  const project = input_1.default.restApiProject(options.project, true);
@@ -82,6 +83,10 @@ commandDistroRouteUpdate.action(async (identifier, routeId, options) => {
82
83
  output_1.default.exitError(texts_1.ERR_COMMAND_NO_UPDATE);
83
84
  }
84
85
  const result = await client.updateRoute(workspace, scope === distro_1.SCOPE.PROJECT ? project : null, data.distribution_id, routeId, body);
86
+ if (options.format === 'json') {
87
+ output_1.default.json(result);
88
+ output_1.default.exitNormal();
89
+ }
85
90
  output_1.default.id(result.id);
86
91
  output_1.default.cyan(result.html_url);
87
92
  output_1.default.green(texts_1.TXT_COMMAND_ROUTE_UPDATED);
@@ -22,6 +22,7 @@ commandDistroUpdate.option('--agent-note <note>', texts_1.OPT_COMMAND_DISTRO_AGE
22
22
  commandDistroUpdate.option('--enable', texts_1.OPT_COMMAND_DISTRO_ENABLE);
23
23
  commandDistroUpdate.option('--disable', texts_1.OPT_COMMAND_DISTRO_DISABLE);
24
24
  commandDistroUpdate.argument('<identifier>', texts_1.OPT_COMMAND_DISTRO_IDENTIFIER);
25
+ commandDistroUpdate.option('--format <text|json>', texts_1.OPTION_FORMAT);
25
26
  commandDistroUpdate.action(async (identifier, options) => {
26
27
  if (options.enable && options.disable) {
27
28
  output_1.default.exitError(texts_1.ERR_COMMAND_DISTRO_ENABLE_DISABLE);
@@ -59,6 +60,10 @@ commandDistroUpdate.action(async (identifier, options) => {
59
60
  output_1.default.exitError(texts_1.ERR_COMMAND_DISTRO_NOT_FOUND);
60
61
  }
61
62
  const result = await client.updateDistribution(workspace, scope === distro_1.SCOPE.PROJECT ? project : null, data.distribution_id, body);
63
+ if (options.format === 'json') {
64
+ output_1.default.json(result);
65
+ output_1.default.exitNormal();
66
+ }
62
67
  output_1.default.identifier(result.identifier);
63
68
  output_1.default.cyan(result.html_url);
64
69
  output_1.default.green(texts_1.TXT_COMMAND_DISTRO_UPDATED);
@@ -20,12 +20,16 @@ const sort = (arr, sort) => {
20
20
  return 0;
21
21
  });
22
22
  };
23
- const commandDomainSearch = (0, utils_1.newCommand)('search', texts_1.DESC_COMMAND_DOMAIN_SEARCH);
23
+ const commandDomainSearch = (0, utils_1.newCommand)('search', texts_1.DESC_COMMAND_DOMAIN_SEARCH, {
24
+ helpText: texts_1.HELP_DOMAIN_SEARCH_JSON,
25
+ examples: texts_1.EXAMPLE_DOMAIN_SEARCH,
26
+ });
24
27
  commandDomainSearch.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
25
28
  commandDomainSearch.option('-d, --tld <tld...>', texts_1.OPT_COMMAND_DOMAIN_BUY_TLD);
26
29
  commandDomainSearch.option('-s, --sort <name|price>', texts_1.OPT_COMMAND_DOMAIN_SORT);
27
30
  commandDomainSearch.option('-a, --only-available', texts_1.OPT_COMMAND_DOMAIN_ONLY_AVAILABLE);
28
31
  commandDomainSearch.argument('[domain|prompt]', texts_1.OPT_COMMAND_DOMAIN_PHRASE);
32
+ commandDomainSearch.option('--format <text|json>', texts_1.OPTION_FORMAT);
29
33
  commandDomainSearch.action(async (text, options) => {
30
34
  const onlyAvailable = options.onlyAvailable;
31
35
  const workspace = input_1.default.restApiWorkspace(options.workspace);
@@ -38,12 +42,17 @@ commandDomainSearch.action(async (text, options) => {
38
42
  if (!prompt) {
39
43
  output_1.default.exitError(texts_1.TXT_COMMAND_DOMAIN_PROMPT_REQUIRED);
40
44
  }
41
- output_1.default.arrowSign();
42
- output_1.default.normal(`Searching...`);
45
+ let searchResponse = null;
46
+ let claimsResponse = null;
47
+ if (options.format !== 'json') {
48
+ output_1.default.arrowSign();
49
+ output_1.default.normal(`Searching...`);
50
+ }
43
51
  const matched = [];
44
52
  if ((0, utils_1.isValidDomain)(prompt)) {
45
53
  const subdomain = (0, utils_1.getSubdomain)(prompt);
46
54
  const claims = await client.domainClaimable(workspace, subdomain);
55
+ claimsResponse = claims;
47
56
  const claimable = claims.domains.find((c) => `${subdomain}.${c.domain}` === prompt);
48
57
  if (claimable && (!onlyAvailable || claimable.available)) {
49
58
  matched.push({
@@ -54,6 +63,7 @@ commandDomainSearch.action(async (text, options) => {
54
63
  }
55
64
  else {
56
65
  const search = await client.domainSearch(workspace, [prompt]);
66
+ searchResponse = search;
57
67
  const buyable = search.domains.find((d) => d.name === prompt);
58
68
  if (buyable &&
59
69
  (!onlyAvailable || buyable.available)) {
@@ -67,6 +77,7 @@ commandDomainSearch.action(async (text, options) => {
67
77
  }
68
78
  else if ((0, utils_1.isValidSubdomain)(prompt)) {
69
79
  const claims = await client.domainClaimable(workspace, prompt);
80
+ claimsResponse = claims;
70
81
  const domains = [];
71
82
  const popularTlds = (0, utils_1.getPopularTlds)();
72
83
  const searchTlds = tlds.length > 0 ? tlds : popularTlds;
@@ -74,13 +85,15 @@ commandDomainSearch.action(async (text, options) => {
74
85
  domains.push(`${prompt}.${tld}`);
75
86
  });
76
87
  const search = await client.domainSearch(workspace, domains);
77
- search.domains = search.domains.sort((a, b) => {
78
- const aTld = (0, utils_1.getDomainTld)(a.name);
79
- const bTld = (0, utils_1.getDomainTld)(b.name);
80
- const aIdx = popularTlds.indexOf(aTld);
81
- const bIdx = popularTlds.indexOf(bTld);
82
- return aIdx < bIdx ? -1 : 1;
83
- });
88
+ searchResponse = search;
89
+ if (options.format !== 'json')
90
+ search.domains = search.domains.sort((a, b) => {
91
+ const aTld = (0, utils_1.getDomainTld)(a.name);
92
+ const bTld = (0, utils_1.getDomainTld)(b.name);
93
+ const aIdx = popularTlds.indexOf(aTld);
94
+ const bIdx = popularTlds.indexOf(bTld);
95
+ return aIdx < bIdx ? -1 : 1;
96
+ });
84
97
  claims.domains.forEach((c) => {
85
98
  if (!onlyAvailable || c.available) {
86
99
  const name = `${prompt}.${c.domain}`;
@@ -103,6 +116,14 @@ commandDomainSearch.action(async (text, options) => {
103
116
  });
104
117
  }
105
118
  const result = await client.domainSuggest(workspace, prompt, tlds, 5);
119
+ if (options.format === 'json') {
120
+ output_1.default.json({
121
+ search: searchResponse,
122
+ claims: claimsResponse,
123
+ suggestions: result,
124
+ });
125
+ output_1.default.exitNormal();
126
+ }
106
127
  output_1.default.clearPreviousLine();
107
128
  let hasAny = false;
108
129
  if (matched.length > 0) {
@@ -20,6 +20,7 @@ commandEnvironmentCreate.option('--icon <icon>', texts_1.OPTION_ENVIRONMENT_ICON
20
20
  commandEnvironmentCreate.option('--note <note>', texts_1.OPT_COMMAND_NOTE);
21
21
  commandEnvironmentCreate.option('--agent-note <note>', texts_1.OPT_COMMAND_AGENT_NOTE);
22
22
  commandEnvironmentCreate.argument('[name]', texts_1.OPTION_ENVIRONMENT_NAME);
23
+ commandEnvironmentCreate.option('--format <text|json>', texts_1.OPTION_FORMAT);
23
24
  commandEnvironmentCreate.action(async (name, options) => {
24
25
  const humanId = require('human-id').default;
25
26
  const workspace = input_1.default.restApiWorkspace(options.workspace);
@@ -64,6 +65,10 @@ commandEnvironmentCreate.action(async (name, options) => {
64
65
  }
65
66
  const client = input_1.default.restApiTokenClient();
66
67
  const result = await client.createEnvironment(workspace, data);
68
+ if (options.format === 'json') {
69
+ output_1.default.json(result);
70
+ output_1.default.exitNormal();
71
+ }
67
72
  output_1.default.exitSuccess((0, texts_1.TXT_ENVIRONMENT_CREATED)(result.identifier, result.html_url));
68
73
  });
69
74
  exports.default = commandEnvironmentCreate;
@@ -18,6 +18,7 @@ commandEnvironmentUpdate.option('--icon <icon>', texts_1.OPTION_ENVIRONMENT_ICON
18
18
  commandEnvironmentUpdate.option('--note <note>', texts_1.OPT_COMMAND_NOTE);
19
19
  commandEnvironmentUpdate.option('--agent-note <note>', texts_1.OPT_COMMAND_AGENT_NOTE);
20
20
  commandEnvironmentUpdate.argument('<identifier>', texts_1.OPTION_ENVIRONMENT_IDENTIFIER);
21
+ commandEnvironmentUpdate.option('--format <text|json>', texts_1.OPTION_FORMAT);
21
22
  commandEnvironmentUpdate.action(async (identifier, options) => {
22
23
  const workspace = input_1.default.restApiWorkspace(options.workspace);
23
24
  const body = {};
@@ -53,6 +54,10 @@ commandEnvironmentUpdate.action(async (identifier, options) => {
53
54
  const environment_id = await input_1.default.environmentId(client, workspace, identifier, options,
54
55
  /* strictProject */ true);
55
56
  const result = await client.updateEnvironment(workspace, environment_id, body);
57
+ if (options.format === 'json') {
58
+ output_1.default.json(result);
59
+ output_1.default.exitNormal();
60
+ }
56
61
  output_1.default.exitSuccess((0, texts_1.TXT_ENVIRONMENT_UPDATED)(result.identifier, result.html_url));
57
62
  });
58
63
  exports.default = commandEnvironmentUpdate;
@@ -9,10 +9,12 @@ const input_1 = __importDefault(require("../../../input"));
9
9
  const output_1 = __importDefault(require("../../../output"));
10
10
  const commandSandboxAppAdd = (0, utils_1.newCommand)('add', texts_1.DESC_COMMAND_SANDBOX_APP_ADD, {
11
11
  examples: texts_1.EXAMPLE_SANDBOX_APP_ADD,
12
+ helpText: texts_1.HELP_SANDBOX_APP_ADD_JSON,
12
13
  });
13
14
  (0, utils_1.sandboxScopeOptions)(commandSandboxAppAdd);
14
15
  commandSandboxAppAdd.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
15
16
  commandSandboxAppAdd.argument('<app-command>', texts_1.OPTION_SANDBOX_APP_COMMAND);
17
+ commandSandboxAppAdd.option('--format <text|json>', texts_1.OPTION_FORMAT);
16
18
  commandSandboxAppAdd.action(async (identifier, app, options) => {
17
19
  const workspace = input_1.default.restApiWorkspace(options.workspace);
18
20
  const client = input_1.default.restApiTokenClient();
@@ -20,9 +22,13 @@ commandSandboxAppAdd.action(async (identifier, app, options) => {
20
22
  const sandbox = await client.getSandbox(workspace, sandboxId);
21
23
  const apps = sandbox.apps || [];
22
24
  apps.push(app);
23
- await client.updateSandbox(workspace, sandboxId, {
25
+ const updated = await client.updateSandbox(workspace, sandboxId, {
24
26
  apps,
25
27
  });
28
+ if (options.format === 'json') {
29
+ output_1.default.json(updated);
30
+ output_1.default.exitNormal();
31
+ }
26
32
  output_1.default.exitSuccess(texts_1.TXT_SANDBOX_APP_ADDED);
27
33
  });
28
34
  exports.default = commandSandboxAppAdd;
@@ -20,18 +20,23 @@ const fetchLogsWithLimit = async (client, workspace, sandboxId, appId, limit) =>
20
20
  const { cursor, logs } = await client.getSandboxAppLogs(workspace, sandboxId, appId, c);
21
21
  l = l.concat(logs);
22
22
  if (l.length > limit)
23
- return l.slice(0, limit).join('\n');
23
+ return l.slice(0, limit);
24
24
  if (!cursor || !logs.length)
25
- return l.join('\n');
25
+ return l;
26
26
  c = cursor;
27
27
  } while (c != null);
28
- return l.join('\n');
28
+ return l;
29
29
  };
30
+ commandSandboxAppLogs.option('--format <text|jsonl>', texts_1.OPTION_FORMAT_JSONL);
30
31
  commandSandboxAppLogs.action(async (identifier, appId, options) => {
31
32
  const workspace = input_1.default.restApiWorkspace(options.workspace);
32
33
  const client = input_1.default.restApiTokenClient();
33
34
  const sandboxId = await input_1.default.sandboxId(client, workspace, options, identifier);
34
35
  const logs = await fetchLogsWithLimit(client, workspace, sandboxId, appId, options.limit || 100);
35
- output_1.default.exitNormal(logs);
36
+ if (options.format === 'jsonl') {
37
+ logs.forEach((data) => output_1.default.json({ type: 'log', data }));
38
+ output_1.default.exitNormal();
39
+ }
40
+ output_1.default.exitNormal(logs.join('\n'));
36
41
  });
37
42
  exports.default = commandSandboxAppLogs;
@@ -51,8 +51,10 @@ commandSandboxCreate.option('--yaml <content|@path>', texts_1.OPTION_SANDBOX_YAM
51
51
  commandSandboxCreate.option('--wait-for-running [seconds]', texts_1.OPTION_SANDBOX_WAIT_RUNNING);
52
52
  commandSandboxCreate.option('--wait-for-configured [seconds]', texts_1.OPTION_SANDBOX_WAIT_CONFIGURED);
53
53
  commandSandboxCreate.option('--wait-for-apps [seconds]', texts_1.OPTION_SANDBOX_WAIT_APPS);
54
+ commandSandboxCreate.option('--format <text|json>', texts_1.OPTION_FORMAT);
54
55
  commandSandboxCreate.action(async (options) => {
55
56
  const humanId = require('human-id').default;
57
+ const say = output_1.default.progress(options.format === 'json');
56
58
  const workspace = input_1.default.restApiWorkspace(options.workspace);
57
59
  const project = input_1.default.restApiProject(options.project, true);
58
60
  const scope = input_1.default.scope(project, options.scope, options.environment, true);
@@ -78,7 +80,7 @@ commandSandboxCreate.action(async (options) => {
78
80
  const body = {
79
81
  yaml: Buffer.from(yaml, 'utf8').toString('base64'),
80
82
  };
81
- output_1.default.normal((0, texts_1.TXT_SANDBOX_CREATING)());
83
+ say((0, texts_1.TXT_SANDBOX_CREATING)());
82
84
  result = await client.createSandboxByYaml(workspace, scope === distro_1.SCOPE.PROJECT ? project : null, body, environmentId);
83
85
  }
84
86
  else {
@@ -143,12 +145,12 @@ commandSandboxCreate.action(async (options) => {
143
145
  if (options.appDir) {
144
146
  body.app_dir = options.appDir;
145
147
  }
146
- output_1.default.normal((0, texts_1.TXT_SANDBOX_CREATING)(body.name, body.identifier));
148
+ say((0, texts_1.TXT_SANDBOX_CREATING)(body.name, body.identifier));
147
149
  result = await client.createSandbox(workspace, scope === distro_1.SCOPE.PROJECT ? project : null, body);
148
150
  }
149
151
  const sandboxId = result.id;
150
152
  if (options.waitForRunning) {
151
- output_1.default.normal(texts_1.TXT_SANDBOX_WAITING_RUNNING);
153
+ say(texts_1.TXT_SANDBOX_WAITING_RUNNING);
152
154
  const timeout = parseInt(options.waitForRunning, 10) || 300;
153
155
  try {
154
156
  const status = await client.sandboxWaitForRunning(workspace, sandboxId, timeout);
@@ -161,7 +163,7 @@ commandSandboxCreate.action(async (options) => {
161
163
  }
162
164
  }
163
165
  if (options.waitForConfigured) {
164
- output_1.default.normal(texts_1.TXT_SANDBOX_WAITING_SETUP);
166
+ say(texts_1.TXT_SANDBOX_WAITING_SETUP);
165
167
  const timeout = parseInt(options.waitForConfigured, 10) || 300;
166
168
  try {
167
169
  const status = await client.sandboxWaitForConfigured(workspace, sandboxId, timeout);
@@ -174,7 +176,7 @@ commandSandboxCreate.action(async (options) => {
174
176
  }
175
177
  }
176
178
  if (options.waitForApps) {
177
- output_1.default.normal(texts_1.TXT_SANDBOX_WAITING_APPS);
179
+ say(texts_1.TXT_SANDBOX_WAITING_APPS);
178
180
  const timeout = parseInt(options.waitForApps, 10) || 300;
179
181
  try {
180
182
  const status = await client.sandboxWaitForApps(workspace, sandboxId, timeout);
@@ -195,6 +197,12 @@ commandSandboxCreate.action(async (options) => {
195
197
  output_1.default.exitError(texts_1.ERR_SANDBOX_RUNNING_TIMEOUT);
196
198
  }
197
199
  }
200
+ if (options.format === 'json') {
201
+ if (options.waitForRunning || options.waitForConfigured || options.waitForApps)
202
+ result = await client.getSandbox(workspace, sandboxId);
203
+ output_1.default.json(result);
204
+ output_1.default.exitNormal();
205
+ }
198
206
  output_1.default.dim('Identifier: ', false);
199
207
  output_1.default.cyan(result.identifier);
200
208
  output_1.default.dim('SSH: ', false);
@@ -10,6 +10,7 @@ const input_1 = __importDefault(require("../../../input"));
10
10
  const tunnel_1 = require("../../../types/tunnel");
11
11
  const commandSandboxEndpointAdd = (0, utils_1.getBasicCommandSandboxEndpoint)('add', texts_1.DESC_COMMAND_SANDBOX_ENDPOINT_ADD, { examples: texts_1.EXAMPLE_SANDBOX_ENDPOINT_CREATE });
12
12
  commandSandboxEndpointAdd.alias('create');
13
+ commandSandboxEndpointAdd.option('--format <text|json>', texts_1.OPTION_FORMAT);
13
14
  commandSandboxEndpointAdd.action(async (identifier, options) => {
14
15
  const humanId = require('human-id').default;
15
16
  let name = options.name;
@@ -32,6 +33,10 @@ commandSandboxEndpointAdd.action(async (identifier, options) => {
32
33
  endpoints: updatedEndpoints,
33
34
  });
34
35
  const addedEndpoint = (updatedSandbox.endpoints || []).find((ep) => ep.name === name);
36
+ if (options.format === 'json') {
37
+ output_1.default.json(addedEndpoint);
38
+ output_1.default.exitNormal();
39
+ }
35
40
  output_1.default.object({
36
41
  Name: name,
37
42
  Url: addedEndpoint.endpoint_url || '-',
@@ -7,13 +7,18 @@ const texts_1 = require("../../../texts");
7
7
  const utils_1 = require("../../../utils");
8
8
  const output_1 = __importDefault(require("../../../output"));
9
9
  const input_1 = __importDefault(require("../../../input"));
10
- const commandSandboxExecCommand = (0, utils_1.newCommand)('command', texts_1.DESC_COMMAND_SANDBOX_EXEC_COMMAND, { examples: texts_1.EXAMPLE_SANDBOX_EXEC_COMMAND });
10
+ const finishExec_1 = require("../finishExec");
11
+ const commandSandboxExecCommand = (0, utils_1.newCommand)('command', texts_1.DESC_COMMAND_SANDBOX_EXEC_COMMAND, {
12
+ helpText: texts_1.HELP_SANDBOX_EXEC_COMMAND_JSONL,
13
+ examples: texts_1.EXAMPLE_SANDBOX_EXEC_COMMAND,
14
+ });
11
15
  commandSandboxExecCommand.alias('cmd');
12
16
  (0, utils_1.sandboxScopeOptions)(commandSandboxExecCommand);
13
17
  commandSandboxExecCommand.option('--runtime <runtime>', texts_1.OPTION_SANDBOX_RUNTIME);
14
18
  commandSandboxExecCommand.option('--wait', texts_1.OPTION_SANDBOX_WAIT);
15
19
  commandSandboxExecCommand.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
16
20
  commandSandboxExecCommand.argument('<command>');
21
+ commandSandboxExecCommand.option('--format <text|jsonl>', texts_1.OPTION_FORMAT_JSONL);
17
22
  commandSandboxExecCommand.action(async (identifier, command, options) => {
18
23
  output_1.default.handleSignals();
19
24
  const workspace = input_1.default.restApiWorkspace(options.workspace);
@@ -24,39 +29,19 @@ commandSandboxExecCommand.action(async (identifier, command, options) => {
24
29
  command,
25
30
  runtime,
26
31
  });
27
- output_1.default.gray((0, texts_1.TXT_SANDBOX_EXEC_ID)(cmdResult.id));
32
+ if (options.format === 'jsonl') {
33
+ output_1.default.json({ type: 'command', command: cmdResult });
34
+ }
35
+ else {
36
+ output_1.default.gray((0, texts_1.TXT_SANDBOX_EXEC_ID)(cmdResult.id));
37
+ }
28
38
  if (!options.wait) {
39
+ if (options.format === 'jsonl')
40
+ output_1.default.exitNormal();
29
41
  output_1.default.exitSuccess((0, texts_1.TXT_SANDBOX_EXEC_BACKGROUND)(identifier, cmdResult.id));
30
42
  }
31
43
  else {
32
- const body = await client.streamSandboxCommandLogs(workspace, sandboxId, cmdResult.id);
33
- body.on('data', (data) => {
34
- if (data) {
35
- try {
36
- const str = data.toString('utf8').split('\n');
37
- str.forEach((s) => {
38
- const json = JSON.parse(s);
39
- if (json.data)
40
- output_1.default.data(json.data);
41
- });
42
- }
43
- catch {
44
- // do nothing
45
- }
46
- }
47
- });
48
- body.on('close', async () => {
49
- const cmdExit = await client.getSandboxCommand(workspace, sandboxId, cmdResult.id);
50
- if (cmdExit.status === utils_1.SANDBOX_EXEC_STATUS.SUCCESSFUL) {
51
- output_1.default.exitSuccess((0, texts_1.TXT_SANDBOX_EXEC_SUCCESS)(identifier, cmdResult.id));
52
- }
53
- else if (cmdExit.status === utils_1.SANDBOX_EXEC_STATUS.INPROGRESS) {
54
- output_1.default.exitNormal((0, texts_1.TXT_SANDBOX_EXEC_INPROGRESS)(identifier, cmdResult.id));
55
- }
56
- else {
57
- output_1.default.exitError((0, texts_1.TXT_SANDBOX_EXEC_FAILED)(identifier, cmdResult.id));
58
- }
59
- });
44
+ await (0, finishExec_1.finishExec)(client, workspace, sandboxId, identifier, cmdResult.id, true, options.format === 'jsonl');
60
45
  }
61
46
  });
62
47
  exports.default = commandSandboxExecCommand;