bdy 1.25.41-dev → 1.25.42-stage

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 (34) hide show
  1. package/distTs/package.json +1 -1
  2. package/distTs/src/api/client.js +59 -1
  3. package/distTs/src/command/agent/debug.js +22 -1
  4. package/distTs/src/command/agent/disable.js +21 -2
  5. package/distTs/src/command/agent/enable.js +21 -2
  6. package/distTs/src/command/agent/proxy/disable.js +16 -2
  7. package/distTs/src/command/agent/proxy/enable.js +16 -2
  8. package/distTs/src/command/agent/proxy/status.js +32 -13
  9. package/distTs/src/command/agent/remote.js +219 -0
  10. package/distTs/src/command/agent/status.js +78 -48
  11. package/distTs/src/command/agent/tags/get.js +37 -13
  12. package/distTs/src/command/agent/tags/set.js +30 -9
  13. package/distTs/src/command/agent/target/disable.js +16 -2
  14. package/distTs/src/command/agent/target/enable.js +16 -2
  15. package/distTs/src/command/agent/target/status.js +32 -13
  16. package/distTs/src/command/agent/tunnel/disable.js +16 -2
  17. package/distTs/src/command/agent/tunnel/enable.js +16 -2
  18. package/distTs/src/command/agent/tunnel/http.js +21 -0
  19. package/distTs/src/command/agent/tunnel/list.js +28 -6
  20. package/distTs/src/command/agent/tunnel/remove.js +29 -1
  21. package/distTs/src/command/agent/tunnel/start.js +23 -0
  22. package/distTs/src/command/agent/tunnel/status.js +50 -13
  23. package/distTs/src/command/agent/tunnel/tcp.js +21 -0
  24. package/distTs/src/command/agent/tunnel/tls.js +21 -0
  25. package/distTs/src/command/agent/update.js +17 -1
  26. package/distTs/src/command/agent/version.js +28 -5
  27. package/distTs/src/command/pre.js +2 -1
  28. package/distTs/src/format.js +6 -0
  29. package/distTs/src/output.js +16 -0
  30. package/distTs/src/texts.js +231 -31
  31. package/distTs/src/tunnel/output/interactive/tunnel.js +67 -8
  32. package/distTs/src/tunnel/output/noninteractive/tunnel.js +8 -0
  33. package/distTs/src/types/serverAgent.js +2 -0
  34. package/package.json +1 -1
@@ -7,13 +7,36 @@ const cliError_1 = __importDefault(require("../../../cliError"));
7
7
  const output_1 = __importDefault(require("../../../output"));
8
8
  const texts_1 = require("../../../texts");
9
9
  const utils_1 = require("../../../utils");
10
+ const remote_1 = require("../remote");
10
11
  const commandAgentTunnelStart = (0, utils_1.newCommand)('start', texts_1.DESC_COMMAND_AGENT_TUNNEL_START, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_TUNNEL_START });
11
12
  commandAgentTunnelStart.argument('<name>', texts_1.OPTION_NAME);
12
13
  commandAgentTunnelStart.option('--format <text|json>', texts_1.OPTION_FORMAT);
14
+ (0, remote_1.addRemoteAgentOptions)(commandAgentTunnelStart, false);
13
15
  commandAgentTunnelStart.action(async (name, options) => {
14
16
  const json = options.format === 'json';
15
17
  const ApiAgent = require('../../../tunnel/api/agent').default;
16
18
  const Cfg = require('../../../tunnel/cfg').default;
19
+ // --agent: the tunnel of this machine's config added to that agent through
20
+ // the REST API; the agent starts it when it gets it
21
+ if (options.agent) {
22
+ if (!Cfg.hasTunnel(name)) {
23
+ output_1.default.exitError(new cliError_1.default('not_found', (0, texts_1.ERR_TUNNEL_NOT_FOUND)(name), texts_1.HINT_TUNNEL_CONFIG_LIST));
24
+ }
25
+ let added = null;
26
+ try {
27
+ const remote = await (0, remote_1.resolveRemoteAgent)(options);
28
+ if (remote) {
29
+ added = await remote.client.createServerAgentTunnel(remote.workspace, remote.agentId, (0, remote_1.remoteTunnelCreate)(Cfg.getTunnel(name)));
30
+ }
31
+ }
32
+ catch (err) {
33
+ output_1.default.exitError(err);
34
+ }
35
+ if (added) {
36
+ output_1.default.exitResult(json, { id: added.id, type: added.type }, (0, texts_1.TXT_TUNNEL_ADDED_REMOTE)(added.type, added.endpoint_url));
37
+ return;
38
+ }
39
+ }
17
40
  if (!commandAgentTunnelStart.agentInstalled) {
18
41
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
19
42
  }
@@ -6,10 +6,58 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const texts_1 = require("../../../texts");
7
7
  const output_1 = __importDefault(require("../../../output"));
8
8
  const utils_1 = require("../../../utils");
9
+ const remote_1 = require("../remote");
9
10
  const commandAgentTunnelStatus = (0, utils_1.newCommand)('status', texts_1.DESC_COMMAND_AGENT_TUNNEL_STATUS, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_TUNNEL_STATUS });
10
11
  commandAgentTunnelStatus.argument('[id]', texts_1.OPTION_ID);
11
12
  commandAgentTunnelStatus.option('--format <text|json>', texts_1.OPTION_FORMAT);
13
+ (0, remote_1.addRemoteAgentOptions)(commandAgentTunnelStatus, false);
14
+ // without an id: whether the agent tunnels at all; disabled is a non-zero exit
15
+ const outputTunneling = (data, json) => {
16
+ if (json) {
17
+ output_1.default.json(data);
18
+ if (!data.tunneling)
19
+ output_1.default.exitError(texts_1.TXT_AGENT_TUNNELING_DISABLED);
20
+ output_1.default.exitNormal();
21
+ }
22
+ if (data.tunneling) {
23
+ output_1.default.exitSuccess(texts_1.TXT_AGENT_TUNNELING_ENABLED);
24
+ }
25
+ else {
26
+ output_1.default.exitError(texts_1.TXT_AGENT_TUNNELING_DISABLED);
27
+ }
28
+ };
12
29
  commandAgentTunnelStatus.action(async (id, options) => {
30
+ const json = options.format === 'json';
31
+ // --agent: the REST API. A tunnel is read once - the agent's last report,
32
+ // nothing to follow - and shown in the same view as a followed one.
33
+ let tunneling = null;
34
+ let tunnel = null;
35
+ try {
36
+ if (id) {
37
+ const remote = await (0, remote_1.resolveRemoteAgent)(options);
38
+ if (remote) {
39
+ tunnel = await remote.client.getServerAgentTunnel(remote.workspace, remote.agentId, id);
40
+ }
41
+ }
42
+ else {
43
+ tunneling = await (0, remote_1.remoteAgentFlag)(options, 'tunneling');
44
+ }
45
+ }
46
+ catch (err) {
47
+ output_1.default.exitError(err);
48
+ }
49
+ if (tunneling !== null) {
50
+ outputTunneling({ tunneling }, json);
51
+ return;
52
+ }
53
+ if (tunnel) {
54
+ if (json) {
55
+ output_1.default.json((0, remote_1.remoteTunnelStatus)(tunnel));
56
+ output_1.default.exitNormal();
57
+ }
58
+ output_1.default.tunnelSnapshot((0, remote_1.remoteTunnelView)(tunnel));
59
+ return;
60
+ }
13
61
  const ApiAgent = require('../../../tunnel/api/agent').default;
14
62
  const AgentSocketTunnel = require('../../../agent/socket/tunnel').default;
15
63
  if (!commandAgentTunnelStatus.agentInstalled) {
@@ -22,24 +70,13 @@ commandAgentTunnelStatus.action(async (id, options) => {
22
70
  const api = new ApiAgent(commandAgentTunnelStatus.agentPort || 0);
23
71
  if (!id) {
24
72
  const data = await api.fetchAgentTunneling();
25
- if (options.format === 'json') {
26
- output_1.default.json(data);
27
- if (!data.tunneling)
28
- output_1.default.exitError(texts_1.TXT_AGENT_TUNNELING_DISABLED);
29
- output_1.default.exitNormal();
30
- }
31
- if (data.tunneling) {
32
- output_1.default.exitSuccess(texts_1.TXT_AGENT_TUNNELING_ENABLED);
33
- }
34
- else {
35
- output_1.default.exitError(texts_1.TXT_AGENT_TUNNELING_DISABLED);
36
- }
73
+ outputTunneling(data, json);
37
74
  return;
38
75
  }
39
76
  const ws = await api.socketTunnel(id);
40
77
  const tunnel = new AgentSocketTunnel(ws, id);
41
78
  await tunnel.waitForReady();
42
- if (options.format === 'json') {
79
+ if (json) {
43
80
  output_1.default.json(tunnel.rawStatus);
44
81
  tunnel.close();
45
82
  output_1.default.exitNormal();
@@ -8,6 +8,7 @@ const output_1 = __importDefault(require("../../../output"));
8
8
  const cliError_1 = __importDefault(require("../../../cliError"));
9
9
  const texts_1 = require("../../../texts");
10
10
  const tunnel_1 = require("../../../types/tunnel");
11
+ const remote_1 = require("../remote");
11
12
  const commandAgentTunnelTcp = (0, utils_1.getBasicCommandTcp)({
12
13
  requiredScopes: [],
13
14
  examples: (0, texts_1.EXAMPLE_TUNNEL_TCP)(true),
@@ -15,6 +16,7 @@ const commandAgentTunnelTcp = (0, utils_1.getBasicCommandTcp)({
15
16
  commandAgentTunnelTcp.description(texts_1.DESC_COMMAND_AGENT_TUNNEL_TCP);
16
17
  commandAgentTunnelTcp.option('-f, --follow', texts_1.OPTION_FOLLOW);
17
18
  commandAgentTunnelTcp.option('--format <text|json>', texts_1.OPTION_FORMAT);
19
+ (0, remote_1.addRemoteAgentOptions)(commandAgentTunnelTcp, false);
18
20
  commandAgentTunnelTcp.argument('[host:port]', texts_1.OPTION_TARGET);
19
21
  commandAgentTunnelTcp.action(async (target, options) => {
20
22
  const ApiAgent = require('../../../tunnel/api/agent').default;
@@ -24,6 +26,25 @@ commandAgentTunnelTcp.action(async (target, options) => {
24
26
  if (json && options.follow) {
25
27
  throw new cliError_1.default('usage_error', texts_1.ERR_FOLLOW_WITH_JSON);
26
28
  }
29
+ if (options.agent && options.follow) {
30
+ throw new cliError_1.default('usage_error', texts_1.ERR_FOLLOW_WITH_AGENT);
31
+ }
32
+ // --agent: added through the REST API; the agent starts it when it gets it
33
+ let added = null;
34
+ try {
35
+ const remote = await (0, remote_1.resolveRemoteAgent)(options);
36
+ if (remote) {
37
+ const prepared = await Cfg.prepareTunnel(tunnel_1.TUNNEL_TYPE.TCP, target, options, false);
38
+ added = await remote.client.createServerAgentTunnel(remote.workspace, remote.agentId, (0, remote_1.remoteTunnelCreate)(prepared));
39
+ }
40
+ }
41
+ catch (err) {
42
+ output_1.default.exitError(err);
43
+ }
44
+ if (added) {
45
+ output_1.default.exitResult(json, { id: added.id, type: added.type }, (0, texts_1.TXT_TUNNEL_ADDED_REMOTE)(added.type, added.endpoint_url));
46
+ return;
47
+ }
27
48
  if (!commandAgentTunnelTcp.agentInstalled) {
28
49
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
29
50
  }
@@ -8,6 +8,7 @@ const output_1 = __importDefault(require("../../../output"));
8
8
  const cliError_1 = __importDefault(require("../../../cliError"));
9
9
  const texts_1 = require("../../../texts");
10
10
  const tunnel_1 = require("../../../types/tunnel");
11
+ const remote_1 = require("../remote");
11
12
  const commandAgentTunnelTls = (0, utils_1.getBasicCommandTls)({
12
13
  requiredScopes: [],
13
14
  examples: (0, texts_1.EXAMPLE_TUNNEL_TLS)(true),
@@ -15,6 +16,7 @@ const commandAgentTunnelTls = (0, utils_1.getBasicCommandTls)({
15
16
  commandAgentTunnelTls.description(texts_1.DESC_COMMAND_AGENT_TUNNEL_TLS);
16
17
  commandAgentTunnelTls.option('-f, --follow', texts_1.OPTION_FOLLOW);
17
18
  commandAgentTunnelTls.option('--format <text|json>', texts_1.OPTION_FORMAT);
19
+ (0, remote_1.addRemoteAgentOptions)(commandAgentTunnelTls, false);
18
20
  commandAgentTunnelTls.argument('[host:port]', texts_1.OPTION_TARGET);
19
21
  commandAgentTunnelTls.action(async (target, options) => {
20
22
  const ApiAgent = require('../../../tunnel/api/agent').default;
@@ -24,6 +26,25 @@ commandAgentTunnelTls.action(async (target, options) => {
24
26
  if (json && options.follow) {
25
27
  throw new cliError_1.default('usage_error', texts_1.ERR_FOLLOW_WITH_JSON);
26
28
  }
29
+ if (options.agent && options.follow) {
30
+ throw new cliError_1.default('usage_error', texts_1.ERR_FOLLOW_WITH_AGENT);
31
+ }
32
+ // --agent: added through the REST API; the agent starts it when it gets it
33
+ let added = null;
34
+ try {
35
+ const remote = await (0, remote_1.resolveRemoteAgent)(options);
36
+ if (remote) {
37
+ const prepared = await Cfg.prepareTunnel(tunnel_1.TUNNEL_TYPE.TLS, target, options, false);
38
+ added = await remote.client.createServerAgentTunnel(remote.workspace, remote.agentId, (0, remote_1.remoteTunnelCreate)(prepared));
39
+ }
40
+ }
41
+ catch (err) {
42
+ output_1.default.exitError(err);
43
+ }
44
+ if (added) {
45
+ output_1.default.exitResult(json, { id: added.id, type: added.type }, (0, texts_1.TXT_TUNNEL_ADDED_REMOTE)(added.type, added.endpoint_url));
46
+ return;
47
+ }
27
48
  if (!commandAgentTunnelTls.agentInstalled) {
28
49
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
29
50
  }
@@ -6,11 +6,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const texts_1 = require("../../texts");
7
7
  const output_1 = __importDefault(require("../../output"));
8
8
  const utils_1 = require("../../utils");
9
- const commandAgentUpdate = (0, utils_1.newCommand)('update', texts_1.DESC_COMMAND_AGENT_UPDATE, { requiredScopes: [] });
9
+ const remote_1 = require("./remote");
10
+ const commandAgentUpdate = (0, utils_1.newCommand)('update', texts_1.DESC_COMMAND_AGENT_UPDATE, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_UPDATE });
10
11
  commandAgentUpdate.hideVersionUpdate = true;
11
12
  commandAgentUpdate.option('--format <text|json>', texts_1.OPTION_FORMAT);
13
+ (0, remote_1.addRemoteAgentOptions)(commandAgentUpdate);
12
14
  commandAgentUpdate.action(async (options) => {
13
15
  const json = options.format === 'json';
16
+ // --agent: requested through the REST API and done by the agent when it gets
17
+ // it (its outcome lands in `action`, see `agent status --agent`); a pending
18
+ // action answers 409
19
+ let requested = null;
20
+ try {
21
+ requested = await (0, remote_1.remoteAgentAction)(options, 'UPDATE');
22
+ }
23
+ catch (err) {
24
+ output_1.default.exitError(err);
25
+ }
26
+ if (requested) {
27
+ output_1.default.exitResult(json, { updated: false, requested: true }, texts_1.TXT_AGENT_UPDATE_REQUESTED);
28
+ return;
29
+ }
14
30
  const AgentManager = require('../../agent/manager').default;
15
31
  const ApiAgent = require('../../tunnel/api/agent').default;
16
32
  const waitUntilAgentEnabled = require('../../agent/wait').default;
@@ -6,19 +6,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const output_1 = __importDefault(require("../../output"));
7
7
  const texts_1 = require("../../texts");
8
8
  const utils_1 = require("../../utils");
9
+ const remote_1 = require("./remote");
9
10
  const commandAgentVersion = (0, utils_1.newCommand)('version', texts_1.DESC_COMMAND_AGENT_VERSION, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_VERSION });
10
11
  commandAgentVersion.option('--format <text|json>', texts_1.OPTION_FORMAT);
12
+ (0, remote_1.addRemoteAgentOptions)(commandAgentVersion);
13
+ const output = (status, json) => {
14
+ if (json) {
15
+ output_1.default.json(status);
16
+ output_1.default.exitNormal();
17
+ }
18
+ output_1.default.exitNormal(status.version || '');
19
+ };
11
20
  commandAgentVersion.action(async (options) => {
21
+ const json = options.format === 'json';
22
+ let agent = null;
23
+ try {
24
+ const remote = await (0, remote_1.resolveRemoteAgent)(options);
25
+ if (remote) {
26
+ agent = await remote.client.getServerAgent(remote.workspace, remote.agentId);
27
+ }
28
+ }
29
+ catch (err) {
30
+ output_1.default.exitError(err);
31
+ }
32
+ if (agent) {
33
+ // the version is the agent's own report: none before it first reports
34
+ if (!agent.version)
35
+ output_1.default.exitError(texts_1.ERR_AGENT_VERSION_UNKNOWN);
36
+ output((0, remote_1.remoteAgentApiStatus)(agent), json);
37
+ return;
38
+ }
12
39
  if (!commandAgentVersion.agentInstalled) {
13
40
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
14
41
  }
15
42
  if (!commandAgentVersion.agentStatus) {
16
43
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
17
44
  }
18
- if (options.format === 'json') {
19
- output_1.default.json(commandAgentVersion.agentStatus);
20
- output_1.default.exitNormal();
21
- }
22
- output_1.default.exitNormal(commandAgentVersion.agentStatus.version);
45
+ output(commandAgentVersion.agentStatus, json);
23
46
  });
24
47
  exports.default = commandAgentVersion;
@@ -19,7 +19,8 @@ const commandPre = async (_, command) => {
19
19
  command.agentPort = 0;
20
20
  command.agentId = '';
21
21
  try {
22
- if (!(0, utils_1.isDocker)()) {
22
+ // --agent works on an agent through the REST API: the local one is not asked
23
+ if (!(0, utils_1.isDocker)() && !command.opts()?.agent) {
23
24
  const hasConfig = AgentManager.system.hasSystemConfig();
24
25
  if (hasConfig) {
25
26
  command.agentInstalled = true;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const utils_1 = require("./utils");
7
7
  const punycode_1 = __importDefault(require("punycode/"));
8
8
  const tunnel_1 = require("./types/tunnel");
9
+ const texts_1 = require("./texts");
9
10
  class Format {
10
11
  static date() {
11
12
  const dt = new Date();
@@ -132,7 +133,12 @@ class Format {
132
133
  static entryHostEncoded(tunnel) {
133
134
  return punycode_1.default.toASCII(this.entryHost(tunnel));
134
135
  }
136
+ // No ssh id yet: the tunnel has no registration on the proxy, so no address
137
+ // either (the REST view then leaves out `ssh` and `endpoint_url` alike).
135
138
  static entry(tunnel) {
139
+ if (tunnel.sshId === undefined || tunnel.sshId === null) {
140
+ return texts_1.TXT_TUNNEL_ENTRY_PENDING;
141
+ }
136
142
  let entry = '';
137
143
  if (tunnel.type === tunnel_1.TUNNEL_TYPE.HTTP)
138
144
  entry += 'https://';
@@ -421,6 +421,22 @@ class Output {
421
421
  static isTTY() {
422
422
  return this.isStdInTTY() && this.isStdOutTTY();
423
423
  }
424
+ // A tunnel read once (`agent tunnel status <id> --agent`): the same view as
425
+ // a followed one - the dashboard on a terminal, the state line otherwise -
426
+ // printed once, and the command ends.
427
+ static tunnelSnapshot(tunnel) {
428
+ this.killSpinner();
429
+ if (this.isTTY()) {
430
+ const OutputInteractiveTunnel = require('./tunnel/output/interactive/tunnel').default;
431
+ const oi = new OutputInteractiveTunnel(getTerminal(), tunnel);
432
+ getTerminal()(`${oi.snapshot()}\n`);
433
+ }
434
+ else {
435
+ const OutputNoninteractiveTunnel = require('./tunnel/output/noninteractive/tunnel').default;
436
+ new OutputNoninteractiveTunnel(getTerminal(), tunnel).snapshot();
437
+ }
438
+ this.exitNormal();
439
+ }
424
440
  static tunnelJsonl(tunnel) {
425
441
  this.killSpinner();
426
442
  const OutputJsonlTunnel = require('./tunnel/output/noninteractive/tunnelJsonl').default;