bdy 1.25.40-dev → 1.25.42-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 (51) hide show
  1. package/distTs/package.json +1 -1
  2. package/distTs/src/api/client.js +129 -60
  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/distro/create.js +11 -6
  28. package/distTs/src/command/distro/delete.js +6 -13
  29. package/distTs/src/command/distro/get.js +6 -13
  30. package/distTs/src/command/distro/list.js +6 -6
  31. package/distTs/src/command/distro/open.js +5 -10
  32. package/distTs/src/command/distro/route/create.js +6 -14
  33. package/distTs/src/command/distro/route/delete.js +6 -13
  34. package/distTs/src/command/distro/route/get.js +9 -14
  35. package/distTs/src/command/distro/route/list.js +6 -13
  36. package/distTs/src/command/distro/route/open.js +5 -10
  37. package/distTs/src/command/distro/route/purge.js +42 -0
  38. package/distTs/src/command/distro/route/update.js +8 -15
  39. package/distTs/src/command/distro/route.js +3 -0
  40. package/distTs/src/command/distro/scope.js +77 -0
  41. package/distTs/src/command/distro/update.js +5 -13
  42. package/distTs/src/command/distro.js +1 -0
  43. package/distTs/src/command/pre.js +2 -1
  44. package/distTs/src/format.js +6 -0
  45. package/distTs/src/input.js +33 -10
  46. package/distTs/src/output.js +16 -0
  47. package/distTs/src/texts.js +273 -31
  48. package/distTs/src/tunnel/output/interactive/tunnel.js +67 -8
  49. package/distTs/src/tunnel/output/noninteractive/tunnel.js +8 -0
  50. package/distTs/src/types/serverAgent.js +2 -0
  51. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.25.40-dev",
4
+ "version": "1.25.42-dev",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",
@@ -216,7 +216,7 @@ class ApiClient {
216
216
  }
217
217
  throw new cliError_1.default('unauthorized', texts_1.ERR_REST_API_UNAUTHORIZED, texts_1.TXT_CLI_LOGIN_HINT);
218
218
  }
219
- if ([200, 201].includes(status)) {
219
+ if ([200, 201, 202].includes(status)) {
220
220
  if (parseResponseBody) {
221
221
  try {
222
222
  const b = await responseBody.json();
@@ -529,122 +529,191 @@ class ApiClient {
529
529
  });
530
530
  }
531
531
  // Distro methods
532
+ // An environment-scoped distribution is found only with its environment
533
+ // (`environment_id`), which then decides alone - the backend ignores the
534
+ // project next to it, so it is not sent.
535
+ distroQuery(scope) {
536
+ const query = {};
537
+ if (scope.environmentId)
538
+ query.environment_id = scope.environmentId;
539
+ else if (scope.project)
540
+ query.project_name = scope.project;
541
+ return query;
542
+ }
543
+ distroPath(workspace, distributionId) {
544
+ let path = `/workspaces/${encodeURIComponent(workspace)}/distributions`;
545
+ if (distributionId)
546
+ path += `/${encodeURIComponent(distributionId)}`;
547
+ return path;
548
+ }
549
+ routePath(workspace, distributionId, routeId) {
550
+ let path = `${this.distroPath(workspace, distributionId)}/routes`;
551
+ if (routeId)
552
+ path += `/${encodeURIComponent(routeId)}`;
553
+ return path;
554
+ }
532
555
  async createDistro(workspace, body) {
533
556
  return await this.request({
534
557
  method: 'POST',
535
- path: `/workspaces/${encodeURIComponent(workspace)}/distributions`,
558
+ path: this.distroPath(workspace),
536
559
  body,
537
560
  parseResponseBody: true,
538
561
  });
539
562
  }
540
- async deleteRoute(workspace, project, distributionId, routeId) {
541
- const query = {};
542
- if (project)
543
- query.project_name = project;
563
+ async deleteRoute(workspace, scope, distributionId, routeId) {
544
564
  return await this.request({
545
565
  method: 'DELETE',
546
- path: `/workspaces/${encodeURIComponent(workspace)}/distributions/${encodeURIComponent(distributionId)}/routes/${encodeURIComponent(routeId)}`,
547
- query,
566
+ path: this.routePath(workspace, distributionId, routeId),
567
+ query: this.distroQuery(scope),
548
568
  });
549
569
  }
550
- async listRoutes(workspace, project, distributionId) {
551
- const query = {};
552
- if (project)
553
- query.project_name = project;
570
+ async listRoutes(workspace, scope, distributionId) {
554
571
  return await this.request({
555
572
  method: 'GET',
556
- path: `/workspaces/${encodeURIComponent(workspace)}/distributions/${encodeURIComponent(distributionId)}/routes`,
557
- query,
573
+ path: this.routePath(workspace, distributionId),
574
+ query: this.distroQuery(scope),
558
575
  parseResponseBody: true,
559
576
  });
560
577
  }
561
- async getRoute(workspace, project, distributionId, routeId) {
562
- const query = {};
563
- if (project)
564
- query.project_name = project;
578
+ async getRoute(workspace, scope, distributionId, routeId) {
565
579
  return await this.request({
566
580
  method: 'GET',
567
- path: `/workspaces/${encodeURIComponent(workspace)}/distributions/${encodeURIComponent(distributionId)}/routes/${encodeURIComponent(routeId)}`,
568
- query,
581
+ path: this.routePath(workspace, distributionId, routeId),
582
+ query: this.distroQuery(scope),
569
583
  parseResponseBody: true,
570
584
  });
571
585
  }
572
- async updateRoute(workspace, project, distributionId, routeId, body) {
573
- const query = {};
574
- if (project)
575
- query.project_name = project;
586
+ async updateRoute(workspace, scope, distributionId, routeId, body) {
576
587
  return await this.request({
577
588
  method: 'PUT',
578
- path: `/workspaces/${encodeURIComponent(workspace)}/distributions/${encodeURIComponent(distributionId)}/routes/${encodeURIComponent(routeId)}`,
579
- query,
589
+ path: this.routePath(workspace, distributionId, routeId),
590
+ query: this.distroQuery(scope),
580
591
  body,
581
592
  parseResponseBody: true,
582
593
  });
583
594
  }
584
- async createRoute(workspace, project, distributionId, body) {
585
- const query = {};
586
- if (project)
587
- query.project_name = project;
595
+ async createRoute(workspace, scope, distributionId, body) {
588
596
  return await this.request({
589
597
  method: 'POST',
590
- path: `/workspaces/${encodeURIComponent(workspace)}/distributions/${encodeURIComponent(distributionId)}/routes`,
591
- query,
598
+ path: this.routePath(workspace, distributionId),
599
+ query: this.distroQuery(scope),
592
600
  body,
593
601
  parseResponseBody: true,
594
602
  });
595
603
  }
596
- async deleteDistribution(workspace, project, distributionId) {
597
- const query = {};
598
- if (project)
599
- query.project_name = project;
604
+ async purgeRouteCache(workspace, scope, distributionId, routeId, body) {
605
+ return await this.request({
606
+ method: 'POST',
607
+ path: `${this.routePath(workspace, distributionId, routeId)}/cache`,
608
+ query: this.distroQuery(scope),
609
+ body,
610
+ });
611
+ }
612
+ async deleteDistribution(workspace, scope, distributionId) {
600
613
  return await this.request({
601
614
  method: 'DELETE',
602
- path: `/workspaces/${encodeURIComponent(workspace)}/distributions/${encodeURIComponent(distributionId)}`,
603
- query,
615
+ path: this.distroPath(workspace, distributionId),
616
+ query: this.distroQuery(scope),
604
617
  });
605
618
  }
606
- async updateDistribution(workspace, project, distributionId, body) {
607
- const query = {};
608
- if (project)
609
- query.project_name = project;
619
+ async updateDistribution(workspace, scope, distributionId, body) {
610
620
  return await this.request({
611
621
  method: 'PATCH',
612
- path: `/workspaces/${encodeURIComponent(workspace)}/distributions/${encodeURIComponent(distributionId)}`,
613
- query,
622
+ path: this.distroPath(workspace, distributionId),
623
+ query: this.distroQuery(scope),
614
624
  body,
615
625
  parseResponseBody: true,
616
626
  });
617
627
  }
618
- async getDistribution(workspace, project, distributionId) {
619
- const query = {};
620
- if (project)
621
- query.project_name = project;
628
+ async getDistribution(workspace, scope, distributionId) {
622
629
  return await this.request({
623
630
  method: 'GET',
624
- path: `/workspaces/${encodeURIComponent(workspace)}/distributions/${encodeURIComponent(distributionId)}`,
625
- query,
631
+ path: this.distroPath(workspace, distributionId),
632
+ query: this.distroQuery(scope),
626
633
  parseResponseBody: true,
627
634
  });
628
635
  }
629
- async getDistributions(workspace, project) {
630
- const query = {};
631
- if (project)
632
- query.project_name = project;
636
+ // Exact scope: with an environment only its distributions, with a project
637
+ // only the project's, else only the workspace's.
638
+ async getDistributions(workspace, scope) {
633
639
  return await this.request({
634
640
  method: 'GET',
635
- path: `/workspaces/${encodeURIComponent(workspace)}/distributions`,
636
- query,
641
+ path: this.distroPath(workspace),
642
+ query: this.distroQuery(scope),
637
643
  parseResponseBody: true,
638
644
  });
639
645
  }
640
- async getDistributionByIdentifier(workspace, project, identifier) {
646
+ // `environment` is the environment's identifier (it narrows the lookup to
647
+ // that environment's distributions); `project` narrows the environment, or
648
+ // the distribution itself when no environment is given.
649
+ async getDistributionByIdentifier(workspace, line, identifier) {
641
650
  const q = {
642
651
  distribution: identifier,
643
652
  };
644
- if (project)
645
- q.project = project;
653
+ if (line.project)
654
+ q.project = line.project;
655
+ if (line.environment)
656
+ q.environment = line.environment;
646
657
  return await this.getResourceByIdentifier(workspace, q);
647
658
  }
659
+ // Server agent methods (REST API; the local agent is reached through
660
+ // tunnel/api/agent.ts)
661
+ async getServerAgent(workspace, agentId) {
662
+ return await this.request({
663
+ method: 'GET',
664
+ path: `/workspaces/${encodeURIComponent(workspace)}/server-agents/${encodeURIComponent(agentId)}`,
665
+ parseResponseBody: true,
666
+ });
667
+ }
668
+ // Partial: an omitted field is left unchanged.
669
+ async updateServerAgent(workspace, agentId, body) {
670
+ return await this.request({
671
+ method: 'PATCH',
672
+ path: `/workspaces/${encodeURIComponent(workspace)}/server-agents/${encodeURIComponent(agentId)}`,
673
+ body,
674
+ parseResponseBody: true,
675
+ });
676
+ }
677
+ // The predefined SSH tunnel of the agent is not listed.
678
+ async getServerAgentTunnels(workspace, agentId) {
679
+ return await this.request({
680
+ method: 'GET',
681
+ path: `/workspaces/${encodeURIComponent(workspace)}/server-agents/${encodeURIComponent(agentId)}/tunnels`,
682
+ parseResponseBody: true,
683
+ });
684
+ }
685
+ async getServerAgentTunnel(workspace, agentId, tunnelId) {
686
+ return await this.request({
687
+ method: 'GET',
688
+ path: `/workspaces/${encodeURIComponent(workspace)}/server-agents/${encodeURIComponent(agentId)}/tunnels/${encodeURIComponent(tunnelId)}`,
689
+ parseResponseBody: true,
690
+ });
691
+ }
692
+ // Answers the new tunnel with its domain, subdomain and endpoint_url.
693
+ async createServerAgentTunnel(workspace, agentId, body) {
694
+ return await this.request({
695
+ method: 'POST',
696
+ path: `/workspaces/${encodeURIComponent(workspace)}/server-agents/${encodeURIComponent(agentId)}/tunnels`,
697
+ body,
698
+ parseResponseBody: true,
699
+ });
700
+ }
701
+ // The predefined SSH tunnel cannot be deleted (400).
702
+ async deleteServerAgentTunnel(workspace, agentId, tunnelId) {
703
+ return await this.request({
704
+ method: 'DELETE',
705
+ path: `/workspaces/${encodeURIComponent(workspace)}/server-agents/${encodeURIComponent(agentId)}/tunnels/${encodeURIComponent(tunnelId)}`,
706
+ });
707
+ }
708
+ // 202 with the agent once queued; 409 while another action is pending.
709
+ async createServerAgentAction(workspace, agentId, type) {
710
+ return await this.request({
711
+ method: 'POST',
712
+ path: `/workspaces/${encodeURIComponent(workspace)}/server-agents/${encodeURIComponent(agentId)}/actions`,
713
+ body: { type },
714
+ parseResponseBody: true,
715
+ });
716
+ }
648
717
  // Target methods
649
718
  targetScopeQuery(scope) {
650
719
  const query = {};
@@ -1741,7 +1810,7 @@ class ApiClient {
1741
1810
  case notes_1.PARENT_NOTE_TYPE.ARTIFACT:
1742
1811
  return await this.getArtifact(workspace, id);
1743
1812
  case notes_1.PARENT_NOTE_TYPE.DISTRIBUTION:
1744
- return await this.getDistribution(workspace, ref.project || null, id);
1813
+ return await this.getDistribution(workspace, { project: ref.project, environmentId: ref.environmentId }, id);
1745
1814
  }
1746
1815
  }
1747
1816
  // Notes of the parents, closest first, each on its own and skipped when it
@@ -6,10 +6,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const utils_1 = require("../../utils");
7
7
  const texts_1 = require("../../texts");
8
8
  const output_1 = __importDefault(require("../../output"));
9
- const commandAgentDebug = (0, utils_1.newCommand)('debug', texts_1.DESC_COMMAND_AGENT_DEBUG, { requiredScopes: [] });
9
+ const cliError_1 = __importDefault(require("../../cliError"));
10
+ const remote_1 = require("./remote");
11
+ const commandAgentDebug = (0, utils_1.newCommand)('debug', texts_1.DESC_COMMAND_AGENT_DEBUG, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_DEBUG });
10
12
  commandAgentDebug.argument('<on/off>');
11
13
  commandAgentDebug.option('--format <text|json>', texts_1.OPTION_FORMAT);
14
+ (0, remote_1.addRemoteAgentOptions)(commandAgentDebug);
12
15
  commandAgentDebug.action(async (debug, options) => {
16
+ // anything but on/off is a typo, not "off": with --agent it would queue an
17
+ // action that blocks the next one (409) until the agent picks it up
18
+ if (debug !== 'on' && debug !== 'off') {
19
+ output_1.default.exitError(new cliError_1.default('usage_error', (0, texts_1.ERR_AGENT_DEBUG_INVALID)(debug)));
20
+ }
21
+ // --agent: requested through the REST API; the agent switches its log level
22
+ // (and saves it) when it gets the action, so no rights are needed here
23
+ let requested = null;
24
+ try {
25
+ requested = await (0, remote_1.remoteAgentAction)(options, debug === 'on' ? 'DEBUG_ON' : 'DEBUG_OFF');
26
+ }
27
+ catch (err) {
28
+ output_1.default.exitError(err);
29
+ }
30
+ if (requested) {
31
+ output_1.default.exitResult(options.format === 'json', { debug: debug === 'on' }, debug === 'on' ? texts_1.TXT_AGENT_DEBUG_ON_REQUESTED : texts_1.TXT_AGENT_DEBUG_OFF_REQUESTED);
32
+ return;
33
+ }
13
34
  const AgentManager = require('../../agent/manager').default;
14
35
  const ApiAgent = require('../../tunnel/api/agent').default;
15
36
  const hasRights = await AgentManager.system.hasRightsToManage();
@@ -6,9 +6,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const utils_1 = require("../../utils");
7
7
  const texts_1 = require("../../texts");
8
8
  const output_1 = __importDefault(require("../../output"));
9
- const commandAgentDisable = (0, utils_1.newCommand)('disable', texts_1.DESC_COMMAND_AGENT_DISABLE, { requiredScopes: [] });
9
+ const remote_1 = require("./remote");
10
+ const commandAgentDisable = (0, utils_1.newCommand)('disable', texts_1.DESC_COMMAND_AGENT_DISABLE, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_DISABLE });
10
11
  commandAgentDisable.option('--format <text|json>', texts_1.OPTION_FORMAT);
12
+ (0, remote_1.addRemoteAgentOptions)(commandAgentDisable);
11
13
  commandAgentDisable.action(async (options) => {
14
+ const json = options.format === 'json';
15
+ let enabled = null;
16
+ try {
17
+ const remote = await (0, remote_1.resolveRemoteAgent)(options);
18
+ if (remote) {
19
+ // the agent gets the change pushed, or on its next connection
20
+ const agent = await remote.client.updateServerAgent(remote.workspace, remote.agentId, { disabled: true });
21
+ enabled = !agent.disabled;
22
+ }
23
+ }
24
+ catch (err) {
25
+ output_1.default.exitError(err);
26
+ }
27
+ if (enabled !== null) {
28
+ output_1.default.exitResult(json, { enabled }, texts_1.TXT_AGENT_REMOTE_DISABLED);
29
+ return;
30
+ }
12
31
  const ApiAgent = require('../../tunnel/api/agent').default;
13
32
  if (!commandAgentDisable.agentInstalled) {
14
33
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
@@ -19,7 +38,7 @@ commandAgentDisable.action(async (options) => {
19
38
  try {
20
39
  const api = new ApiAgent(commandAgentDisable.agentPort || 0);
21
40
  await api.disableAgent();
22
- output_1.default.exitResult(options.format === 'json', { enabled: false }, texts_1.TXT_AGENT_STOPPED);
41
+ output_1.default.exitResult(json, { enabled: false }, texts_1.TXT_AGENT_STOPPED);
23
42
  }
24
43
  catch (err) {
25
44
  output_1.default.exitError(err);
@@ -6,9 +6,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const utils_1 = require("../../utils");
7
7
  const texts_1 = require("../../texts");
8
8
  const output_1 = __importDefault(require("../../output"));
9
- const commandAgentEnable = (0, utils_1.newCommand)('enable', texts_1.DESC_COMMAND_AGENT_ENABLE, { requiredScopes: [] });
9
+ const remote_1 = require("./remote");
10
+ const commandAgentEnable = (0, utils_1.newCommand)('enable', texts_1.DESC_COMMAND_AGENT_ENABLE, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_ENABLE });
10
11
  commandAgentEnable.option('--format <text|json>', texts_1.OPTION_FORMAT);
12
+ (0, remote_1.addRemoteAgentOptions)(commandAgentEnable);
11
13
  commandAgentEnable.action(async (options) => {
14
+ const json = options.format === 'json';
15
+ let enabled = null;
16
+ try {
17
+ const remote = await (0, remote_1.resolveRemoteAgent)(options);
18
+ if (remote) {
19
+ // the agent gets the change pushed, or on its next connection
20
+ const agent = await remote.client.updateServerAgent(remote.workspace, remote.agentId, { disabled: false });
21
+ enabled = !agent.disabled;
22
+ }
23
+ }
24
+ catch (err) {
25
+ output_1.default.exitError(err);
26
+ }
27
+ if (enabled !== null) {
28
+ output_1.default.exitResult(json, { enabled }, texts_1.TXT_AGENT_REMOTE_ENABLED);
29
+ return;
30
+ }
12
31
  const ApiAgent = require('../../tunnel/api/agent').default;
13
32
  if (!commandAgentEnable.agentInstalled) {
14
33
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
@@ -19,7 +38,7 @@ commandAgentEnable.action(async (options) => {
19
38
  try {
20
39
  const api = new ApiAgent(commandAgentEnable.agentPort || 0);
21
40
  await api.enableAgent();
22
- output_1.default.exitResult(options.format === 'json', { enabled: true }, texts_1.TXT_AGENT_STARTED);
41
+ output_1.default.exitResult(json, { enabled: true }, texts_1.TXT_AGENT_STARTED);
23
42
  }
24
43
  catch (err) {
25
44
  output_1.default.exitError(err);
@@ -6,9 +6,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const utils_1 = require("../../../utils");
7
7
  const texts_1 = require("../../../texts");
8
8
  const output_1 = __importDefault(require("../../../output"));
9
- const commandAgentProxyDisable = (0, utils_1.newCommand)('disable', texts_1.DESC_COMMAND_AGENT_PROXY_DISABLE, { requiredScopes: [] });
9
+ const remote_1 = require("../remote");
10
+ const commandAgentProxyDisable = (0, utils_1.newCommand)('disable', texts_1.DESC_COMMAND_AGENT_PROXY_DISABLE, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_PROXY_DISABLE });
10
11
  commandAgentProxyDisable.option('--format <text|json>', texts_1.OPTION_FORMAT);
12
+ (0, remote_1.addRemoteAgentOptions)(commandAgentProxyDisable);
11
13
  commandAgentProxyDisable.action(async (options) => {
14
+ const json = options.format === 'json';
15
+ let remote = null;
16
+ try {
17
+ remote = await (0, remote_1.remoteAgentFlag)(options, 'proxy', false);
18
+ }
19
+ catch (err) {
20
+ output_1.default.exitError(err);
21
+ }
22
+ if (remote !== null) {
23
+ output_1.default.exitResult(json, { proxy: remote }, texts_1.TXT_AGENT_PROXY_DISABLED);
24
+ return;
25
+ }
12
26
  const ApiAgent = require('../../../tunnel/api/agent').default;
13
27
  if (!commandAgentProxyDisable.agentInstalled) {
14
28
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
@@ -19,7 +33,7 @@ commandAgentProxyDisable.action(async (options) => {
19
33
  try {
20
34
  const api = new ApiAgent(commandAgentProxyDisable.agentPort || 0);
21
35
  await api.disableAgentProxy();
22
- output_1.default.exitResult(options.format === 'json', { proxy: false }, texts_1.TXT_AGENT_PROXY_DISABLED);
36
+ output_1.default.exitResult(json, { proxy: false }, texts_1.TXT_AGENT_PROXY_DISABLED);
23
37
  }
24
38
  catch (err) {
25
39
  output_1.default.exitError(err);
@@ -6,9 +6,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const utils_1 = require("../../../utils");
7
7
  const texts_1 = require("../../../texts");
8
8
  const output_1 = __importDefault(require("../../../output"));
9
- const commandAgentProxyEnable = (0, utils_1.newCommand)('enable', texts_1.DESC_COMMAND_AGENT_PROXY_ENABLE, { requiredScopes: [] });
9
+ const remote_1 = require("../remote");
10
+ const commandAgentProxyEnable = (0, utils_1.newCommand)('enable', texts_1.DESC_COMMAND_AGENT_PROXY_ENABLE, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_PROXY_ENABLE });
10
11
  commandAgentProxyEnable.option('--format <text|json>', texts_1.OPTION_FORMAT);
12
+ (0, remote_1.addRemoteAgentOptions)(commandAgentProxyEnable);
11
13
  commandAgentProxyEnable.action(async (options) => {
14
+ const json = options.format === 'json';
15
+ let remote = null;
16
+ try {
17
+ remote = await (0, remote_1.remoteAgentFlag)(options, 'proxy', true);
18
+ }
19
+ catch (err) {
20
+ output_1.default.exitError(err);
21
+ }
22
+ if (remote !== null) {
23
+ output_1.default.exitResult(json, { proxy: remote }, texts_1.TXT_AGENT_PROXY_ENABLED);
24
+ return;
25
+ }
12
26
  const ApiAgent = require('../../../tunnel/api/agent').default;
13
27
  if (!commandAgentProxyEnable.agentInstalled) {
14
28
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
@@ -19,7 +33,7 @@ commandAgentProxyEnable.action(async (options) => {
19
33
  try {
20
34
  const api = new ApiAgent(commandAgentProxyEnable.agentPort || 0);
21
35
  await api.enableAgentProxy();
22
- output_1.default.exitResult(options.format === 'json', { proxy: true }, texts_1.TXT_AGENT_PROXY_ENABLED);
36
+ output_1.default.exitResult(json, { proxy: true }, texts_1.TXT_AGENT_PROXY_ENABLED);
23
37
  }
24
38
  catch (err) {
25
39
  output_1.default.exitError(err);
@@ -6,9 +6,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const utils_1 = require("../../../utils");
7
7
  const texts_1 = require("../../../texts");
8
8
  const output_1 = __importDefault(require("../../../output"));
9
+ const remote_1 = require("../remote");
9
10
  const commandAgentProxyStatus = (0, utils_1.newCommand)('status', texts_1.DESC_COMMAND_AGENT_PROXY_STATUS, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_PROXY_STATUS });
10
11
  commandAgentProxyStatus.option('--format <text|json>', texts_1.OPTION_FORMAT);
12
+ (0, remote_1.addRemoteAgentOptions)(commandAgentProxyStatus);
13
+ // a disabled proxy is a non-zero exit, in text and JSON alike
14
+ const output = (data, json) => {
15
+ if (json) {
16
+ output_1.default.json(data);
17
+ if (!data.proxy)
18
+ output_1.default.exitError(texts_1.TXT_AGENT_PROXY_DISABLED);
19
+ output_1.default.exitNormal();
20
+ }
21
+ if (data.proxy) {
22
+ output_1.default.exitSuccess(texts_1.TXT_AGENT_PROXY_ENABLED);
23
+ }
24
+ else {
25
+ output_1.default.exitError(texts_1.TXT_AGENT_PROXY_DISABLED);
26
+ }
27
+ };
11
28
  commandAgentProxyStatus.action(async (options) => {
29
+ const json = options.format === 'json';
30
+ let remote = null;
31
+ try {
32
+ remote = await (0, remote_1.remoteAgentFlag)(options, 'proxy');
33
+ }
34
+ catch (err) {
35
+ output_1.default.exitError(err);
36
+ }
37
+ if (remote !== null) {
38
+ output({ proxy: remote }, json);
39
+ return;
40
+ }
12
41
  const ApiAgent = require('../../../tunnel/api/agent').default;
13
42
  if (!commandAgentProxyStatus.agentInstalled) {
14
43
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
@@ -16,24 +45,14 @@ commandAgentProxyStatus.action(async (options) => {
16
45
  if (!commandAgentProxyStatus.agentStatus) {
17
46
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
18
47
  }
48
+ let data;
19
49
  try {
20
50
  const api = new ApiAgent(commandAgentProxyStatus.agentPort || 0);
21
- const data = await api.fetchAgentProxy();
22
- if (options.format === 'json') {
23
- output_1.default.json(data);
24
- if (!data.proxy)
25
- output_1.default.exitError(texts_1.TXT_AGENT_PROXY_DISABLED);
26
- output_1.default.exitNormal();
27
- }
28
- if (data.proxy) {
29
- output_1.default.exitSuccess(texts_1.TXT_AGENT_PROXY_ENABLED);
30
- }
31
- else {
32
- output_1.default.exitError(texts_1.TXT_AGENT_PROXY_DISABLED);
33
- }
51
+ data = await api.fetchAgentProxy();
34
52
  }
35
53
  catch (err) {
36
54
  output_1.default.exitError(err);
37
55
  }
56
+ output(data, json);
38
57
  });
39
58
  exports.default = commandAgentProxyStatus;