bdy 1.25.36-stage → 1.25.38-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 (34) hide show
  1. package/distTs/package.json +1 -1
  2. package/distTs/src/agent/agent.js +65 -6
  3. package/distTs/src/api/client.js +121 -0
  4. package/distTs/src/command/artifact/get.js +2 -1
  5. package/distTs/src/command/artifact/update.js +55 -0
  6. package/distTs/src/command/artifact/version/get.js +5 -1
  7. package/distTs/src/command/artifact/version/update.js +59 -0
  8. package/distTs/src/command/artifact/version.js +2 -0
  9. package/distTs/src/command/artifact.js +2 -0
  10. package/distTs/src/command/distro/get.js +2 -1
  11. package/distTs/src/command/distro/route/get.js +9 -1
  12. package/distTs/src/command/integration/update.js +50 -0
  13. package/distTs/src/command/integration.js +2 -0
  14. package/distTs/src/command/pipeline/list.js +15 -16
  15. package/distTs/src/command/pipeline/run/execution.js +12 -0
  16. package/distTs/src/command/pipeline/run/list.js +16 -16
  17. package/distTs/src/command/pipeline/run/status.js +7 -1
  18. package/distTs/src/command/sandbox/get.js +2 -1
  19. package/distTs/src/command/target/get.js +2 -1
  20. package/distTs/src/command/tunnel/http.js +1 -1
  21. package/distTs/src/command/tunnel/start.js +1 -1
  22. package/distTs/src/command/tunnel/tcp.js +1 -1
  23. package/distTs/src/command/tunnel/tls.js +1 -1
  24. package/distTs/src/command/variable/get.js +8 -1
  25. package/distTs/src/output/pipeline.js +12 -3
  26. package/distTs/src/output.js +11 -4
  27. package/distTs/src/texts.js +62 -14
  28. package/distTs/src/tunnel/output/interactive/tunnel.js +14 -1
  29. package/distTs/src/tunnel/output/noninteractive/tunnel.js +14 -0
  30. package/distTs/src/tunnel/output/noninteractive/tunnelJsonl.js +8 -0
  31. package/distTs/src/types/notes.js +14 -0
  32. package/distTs/src/types/tunnel.js +6 -1
  33. package/distTs/src/utils.js +4 -3
  34. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.25.36-stage",
4
+ "version": "1.25.38-dev",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",
@@ -26,6 +26,9 @@ class Agent extends events_1.default {
26
26
  socket;
27
27
  manager;
28
28
  updateStatusExpiry;
29
+ replaceTunnelExpiry;
30
+ replacedTunnelId;
31
+ replacementTunnelId;
29
32
  onRefresh;
30
33
  constructor(id, host, token, service, target, tunneling, proxy, tags, api, disabled) {
31
34
  super();
@@ -43,6 +46,9 @@ class Agent extends events_1.default {
43
46
  this.api = api;
44
47
  this.manager = null;
45
48
  this.updateStatusExpiry = null;
49
+ this.replaceTunnelExpiry = null;
50
+ this.replacedTunnelId = null;
51
+ this.replacementTunnelId = null;
46
52
  this.onRefresh = null;
47
53
  this.socket = new client_1.default(host, id, token);
48
54
  this.socket.on(tunnel_1.TUNNEL_SOCKET_EVENT.FETCH_SUCCESS, (data) => this._onSocketFetch(data));
@@ -62,6 +68,7 @@ class Agent extends events_1.default {
62
68
  if (this.updateStatusExpiry)
63
69
  clearTimeout(this.updateStatusExpiry);
64
70
  this.updateStatusExpiry = null;
71
+ this.clearTunnelReplacement();
65
72
  this.manager = null;
66
73
  this.onRefresh = null;
67
74
  this.api = null;
@@ -70,11 +77,25 @@ class Agent extends events_1.default {
70
77
  }
71
78
  _onSocketTunnel(data, action) {
72
79
  if (action === 'DEL') {
73
- this.destroyTunnel(data.id);
74
- if (!this.service && this.tunnels.length <= 0)
75
- output_1.default.exitError(texts_1.ERR_TUNNEL_REMOVED);
80
+ if (this.service) {
81
+ this.destroyTunnel(data.id);
82
+ return;
83
+ }
84
+ // A rename or a region change arrives as DEL of the old tunnel and ADD of its
85
+ // replacement. The session survives it: the old tunnel stops quietly and waits for
86
+ // the ADD; without one in time the tunnel was deleted for good.
87
+ if (!this.destroyTunnel(data.id, false))
88
+ return;
89
+ if (this.tunnels.length > 0)
90
+ return;
91
+ this.awaitTunnelReplacement(data.id);
76
92
  }
77
93
  else {
94
+ // The ADD names the replacement - the fetch alone cannot tell it from any other
95
+ // tunnel of the agent
96
+ if (this.replacedTunnelId && action === 'ADD' && data.id !== this.replacedTunnelId) {
97
+ this.replacementTunnelId = data.id;
98
+ }
78
99
  logger_1.default.debug('Socket fetch tunnel after sync push');
79
100
  if (this.socket) {
80
101
  this.socket.fetch(!this.disabled, null, null, false, [], false, 1000);
@@ -141,7 +162,10 @@ class Agent extends events_1.default {
141
162
  await this.makeAction(data.agent.action);
142
163
  this.reclearLostUpdateStatus(data.agent.action);
143
164
  const filtered = (data.tunnels || []).filter((t) => !!t.domain);
144
- this.refreshTunnels(filtered);
165
+ if (this.replacedTunnelId)
166
+ this.resolveTunnelReplacement(filtered);
167
+ else
168
+ this.refreshTunnels(filtered);
145
169
  }
146
170
  catch (err) {
147
171
  logger_1.default.error('Fetch error');
@@ -483,14 +507,49 @@ class Agent extends events_1.default {
483
507
  tunnel.on(tunnel_1.TUNNEL_EVENT.STOPPED, () => this.update());
484
508
  tunnel.on(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, (t, logRequest) => this.httpRequest(t.id, logRequest));
485
509
  }
486
- destroyTunnel(id) {
510
+ destroyTunnel(id, emitStopped = true) {
487
511
  const tunnel = this.tunnels.find((t) => t.id === id);
488
512
  if (!tunnel)
489
513
  return null;
490
514
  this.tunnels = this.tunnels.filter((t) => t.id !== tunnel.id);
491
- tunnel.stop();
515
+ tunnel.stop(emitStopped);
492
516
  tunnel.removeAllListeners();
493
517
  return tunnel;
494
518
  }
519
+ // No fetch of its own: the ADD that names the replacement triggers one.
520
+ awaitTunnelReplacement(id) {
521
+ this.clearTunnelReplacement();
522
+ this.replacedTunnelId = id;
523
+ this.replaceTunnelExpiry = setTimeout(() => this.tunnelRemoved(), utils_1.AGENT_TUNNEL_REPLACE_TIMEOUT_MS);
524
+ }
525
+ resolveTunnelReplacement(tunnels) {
526
+ // A fetch answered before the ADD (one from the refresh loop, a stale one listing the
527
+ // old tunnel, or one that caught the backend between the delete and the create)
528
+ // decides nothing - only the one listing the tunnel the ADD named does.
529
+ const replacementId = this.replacementTunnelId;
530
+ if (!replacementId || !tunnels.some((t) => t.id === replacementId))
531
+ return;
532
+ const replacedId = this.replacedTunnelId;
533
+ this.clearTunnelReplacement();
534
+ this.refreshTunnels(tunnels.filter((t) => t.id !== replacedId));
535
+ const replacement = this.tunnels.find((t) => t.id === replacementId);
536
+ if (!replacement)
537
+ return this.tunnelRemoved();
538
+ this.emit(tunnel_1.AGENT_EVENT.TUNNEL_REPLACED, replacement);
539
+ }
540
+ // Ends the session the way a stopped tunnel always has (the output's own exit, a
541
+ // `stopped` record in jsonl); the error exit is only for a session nothing renders.
542
+ tunnelRemoved() {
543
+ this.clearTunnelReplacement();
544
+ if (!this.emit(tunnel_1.AGENT_EVENT.TUNNEL_REMOVED))
545
+ output_1.default.exitError(texts_1.ERR_TUNNEL_REMOVED);
546
+ }
547
+ clearTunnelReplacement() {
548
+ if (this.replaceTunnelExpiry)
549
+ clearTimeout(this.replaceTunnelExpiry);
550
+ this.replaceTunnelExpiry = null;
551
+ this.replacedTunnelId = null;
552
+ this.replacementTunnelId = null;
553
+ }
495
554
  }
496
555
  exports.default = Agent;
@@ -10,6 +10,7 @@ const logger_1 = __importDefault(require("../logger"));
10
10
  const utils_1 = require("../utils");
11
11
  const node_fs_1 = __importDefault(require("node:fs"));
12
12
  const cfg_1 = __importDefault(require("../tunnel/cfg"));
13
+ const notes_1 = require("../types/notes");
13
14
  // Resolved on first use rather than imported. Loading undici costs ~0.25s of the CLI's ~0.33s
14
15
  // startup, and this file is on the import path of nearly every command - including the ones that
15
16
  // never make a request (`--help`, local config, anything that exits on a validation error). Every
@@ -1431,6 +1432,15 @@ class ApiClient {
1431
1432
  parseResponseBody: true,
1432
1433
  });
1433
1434
  }
1435
+ // PATCH is partial: credentials and settings left out of the body stay
1436
+ async updateIntegration(workspace, hashId, body) {
1437
+ return await this.request({
1438
+ method: 'PATCH',
1439
+ path: `/workspaces/${encodeURIComponent(workspace)}/integrations/${encodeURIComponent(hashId)}`,
1440
+ body,
1441
+ parseResponseBody: true,
1442
+ });
1443
+ }
1434
1444
  async deleteIntegration(workspace, hashId) {
1435
1445
  return await this.request({
1436
1446
  method: 'DELETE',
@@ -1655,6 +1665,117 @@ class ApiClient {
1655
1665
  parseResponseBody: true,
1656
1666
  });
1657
1667
  }
1668
+ // PATCH is partial: fields left out of the body stay
1669
+ async updateArtifact(workspace, artifactId, body) {
1670
+ return await this.request({
1671
+ method: 'PATCH',
1672
+ path: `/workspaces/${encodeURIComponent(workspace)}/artifacts/${encodeURIComponent(artifactId)}`,
1673
+ body,
1674
+ parseResponseBody: true,
1675
+ });
1676
+ }
1677
+ // a PUT, but partial all the same: fields left out of the body stay
1678
+ // (pinned by e2e/modules/artifact/notes.e2e.ts)
1679
+ async updateArtifactVersion(workspace, artifactId, versionId, body) {
1680
+ return await this.request({
1681
+ method: 'PUT',
1682
+ path: `/workspaces/${encodeURIComponent(workspace)}/artifacts/${encodeURIComponent(artifactId)}/versions/${encodeURIComponent(versionId)}`,
1683
+ body,
1684
+ parseResponseBody: true,
1685
+ });
1686
+ }
1687
+ // The parents a resource names in its own JSON, closest first. The embedded
1688
+ // objects carry ids only - no notes, although the spec lists them on
1689
+ // ShortPipelineView - so each parent is read on its own.
1690
+ static parentRefs(resource) {
1691
+ const refs = [];
1692
+ if (!resource)
1693
+ return refs;
1694
+ const pipeline = resource.pipeline;
1695
+ if (pipeline?.id) {
1696
+ // a pipeline-scoped target has no `project`, only the pipeline's url
1697
+ const project = resource.project?.name ||
1698
+ pipeline.project?.name ||
1699
+ /\/projects\/([^/]+)\/pipelines\//.exec(pipeline.url || '')?.[1];
1700
+ if (project)
1701
+ refs.push({
1702
+ type: notes_1.PARENT_NOTE_TYPE.PIPELINE,
1703
+ id: pipeline.id,
1704
+ project: decodeURIComponent(project),
1705
+ });
1706
+ }
1707
+ if (resource.sandbox?.id)
1708
+ refs.push({ type: notes_1.PARENT_NOTE_TYPE.SANDBOX, id: resource.sandbox.id });
1709
+ if (resource.environment?.id)
1710
+ refs.push({
1711
+ type: notes_1.PARENT_NOTE_TYPE.ENVIRONMENT,
1712
+ id: resource.environment.id,
1713
+ });
1714
+ return refs;
1715
+ }
1716
+ async _getParent(workspace, ref) {
1717
+ const id = String(ref.id);
1718
+ switch (ref.type) {
1719
+ case notes_1.PARENT_NOTE_TYPE.PIPELINE:
1720
+ return await this.getPipeline(workspace, ref.project || '', Number(id));
1721
+ case notes_1.PARENT_NOTE_TYPE.ENVIRONMENT:
1722
+ return await this.getEnvironment(workspace, id);
1723
+ case notes_1.PARENT_NOTE_TYPE.SANDBOX:
1724
+ return await this.getSandbox(workspace, id);
1725
+ case notes_1.PARENT_NOTE_TYPE.ARTIFACT:
1726
+ return await this.getArtifact(workspace, id);
1727
+ case notes_1.PARENT_NOTE_TYPE.DISTRIBUTION:
1728
+ return await this.getDistribution(workspace, ref.project || null, id);
1729
+ }
1730
+ }
1731
+ // Notes of the parents, closest first, each on its own and skipped when it
1732
+ // has none. A parent that cannot be read - most often a token scoped to the
1733
+ // resource alone - is skipped too: the notes are a hint and never fail the
1734
+ // command that asked for the resource.
1735
+ async getParentNotes(workspace, refs) {
1736
+ const notes = [];
1737
+ const queue = [...refs];
1738
+ const seen = new Set();
1739
+ while (queue.length) {
1740
+ const ref = queue.shift();
1741
+ const key = `${ref.type}:${ref.id}`;
1742
+ if (seen.has(key))
1743
+ continue;
1744
+ seen.add(key);
1745
+ let parent;
1746
+ try {
1747
+ parent = await this._getParent(workspace, ref);
1748
+ }
1749
+ catch {
1750
+ continue;
1751
+ }
1752
+ if (!parent)
1753
+ continue;
1754
+ if (parent.note || parent.agent_note) {
1755
+ const entry = {
1756
+ type: ref.type,
1757
+ identifier: parent.identifier || String(ref.id),
1758
+ };
1759
+ if (parent.note)
1760
+ entry.note = parent.note;
1761
+ if (parent.agent_note)
1762
+ entry.agent_note = parent.agent_note;
1763
+ notes.push(entry);
1764
+ }
1765
+ queue.push(...ApiClient.parentRefs(parent));
1766
+ }
1767
+ return notes;
1768
+ }
1769
+ // The JSON of a 'get': the API's object as it is, plus `parent_notes`
1770
+ // unless --no-parent-notes turned it off.
1771
+ async withParentNotes(workspace, resource, enabled, refs = ApiClient.parentRefs(resource)) {
1772
+ if (!enabled)
1773
+ return resource;
1774
+ return {
1775
+ ...resource,
1776
+ parent_notes: await this.getParentNotes(workspace, refs),
1777
+ };
1778
+ }
1658
1779
  async getArtifactLatest(workspace, artifactId) {
1659
1780
  const res = await this.request({
1660
1781
  method: 'GET',
@@ -16,6 +16,7 @@ commandArtifactGet.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WO
16
16
  commandArtifactGet.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE);
17
17
  commandArtifactGet.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
18
18
  commandArtifactGet.option('--format <text|json>', texts_1.OPTION_FORMAT);
19
+ commandArtifactGet.option('--no-parent-notes', texts_1.OPTION_NO_PARENT_NOTES);
19
20
  commandArtifactGet.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
20
21
  commandArtifactGet.action(async (identifier, options) => {
21
22
  const workspace = input_1.default.restApiWorkspace(options.workspace);
@@ -31,7 +32,7 @@ commandArtifactGet.action(async (identifier, options) => {
31
32
  }
32
33
  const art = await client.getArtifact(workspace, data.artifact_id);
33
34
  if (options.format === 'json') {
34
- output_1.default.json(art);
35
+ output_1.default.json(await client.withParentNotes(workspace, art, options.parentNotes));
35
36
  output_1.default.exitNormal();
36
37
  }
37
38
  else {
@@ -0,0 +1,55 @@
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 cliError_1 = __importDefault(require("../../cliError"));
7
+ const utils_1 = require("../../utils");
8
+ const texts_1 = require("../../texts");
9
+ const input_1 = __importDefault(require("../../input"));
10
+ const output_1 = __importDefault(require("../../output"));
11
+ const distro_1 = require("../../types/distro");
12
+ const commandArtifactUpdate = (0, utils_1.newCommand)('update', texts_1.DESC_COMMAND_ARTIFACT_UPDATE, {
13
+ requiredScopes: [utils_1.REST_API_SCOPE.ARTIFACT_WRITE],
14
+ examples: texts_1.EXAMPLE_ARTIFACT_UPDATE,
15
+ });
16
+ commandArtifactUpdate.alias('edit');
17
+ commandArtifactUpdate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
18
+ commandArtifactUpdate.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE);
19
+ commandArtifactUpdate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
20
+ commandArtifactUpdate.option('--note <note>', texts_1.OPT_COMMAND_NOTE);
21
+ commandArtifactUpdate.option('--agent-note <note>', texts_1.OPT_COMMAND_AGENT_NOTE);
22
+ commandArtifactUpdate.option('--format <text|json>', texts_1.OPTION_FORMAT);
23
+ commandArtifactUpdate.argument('<identifier>', texts_1.OPT_COMMAND_ARTIFACT_IDENTIFIER);
24
+ commandArtifactUpdate.action(async (identifier, options) => {
25
+ const body = {};
26
+ // an empty value clears the note
27
+ if (options.note !== undefined)
28
+ body.note = options.note;
29
+ if (options.agentNote !== undefined)
30
+ body.agent_note = options.agentNote;
31
+ if (!Object.keys(body).length)
32
+ output_1.default.exitError(texts_1.ERR_COMMAND_NO_UPDATE);
33
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
34
+ const project = input_1.default.restApiProject(options.project, true);
35
+ const scope = input_1.default.scope(project, options.scope);
36
+ const client = input_1.default.restApiTokenClient();
37
+ const data = await client.getArtifactVersionByIdentifier(workspace, scope === distro_1.SCOPE.PROJECT ? project : null, identifier);
38
+ if (!data || !data.domain) {
39
+ output_1.default.exitError(new cliError_1.default('not_found', texts_1.ERR_WORKSPACE_NOT_FOUND, texts_1.HINT_WORKSPACE_LIST));
40
+ }
41
+ if (!data || !data.artifact_id) {
42
+ output_1.default.exitError(new cliError_1.default('not_found', texts_1.ERR_ARTIFACT_NOT_FOUND, texts_1.HINT_ARTIFACT_LIST));
43
+ }
44
+ const result = await client.updateArtifact(workspace, data.artifact_id, body);
45
+ if (options.format === 'json') {
46
+ output_1.default.json(result);
47
+ output_1.default.exitNormal();
48
+ }
49
+ output_1.default.identifier(result.identifier);
50
+ if (result.html_url)
51
+ output_1.default.cyan(result.html_url);
52
+ output_1.default.green(texts_1.TXT_ARTIFACT_UPDATED);
53
+ output_1.default.exitNormal();
54
+ });
55
+ exports.default = commandArtifactUpdate;
@@ -9,6 +9,7 @@ const texts_1 = require("../../../texts");
9
9
  const input_1 = __importDefault(require("../../../input"));
10
10
  const output_1 = __importDefault(require("../../../output"));
11
11
  const distro_1 = require("../../../types/distro");
12
+ const notes_1 = require("../../../types/notes");
12
13
  const commandArtifactVersionGet = (0, utils_1.newCommand)('get', texts_1.DESC_COMMAND_ARTIFACT_VERSION_GET, {
13
14
  requiredScopes: [utils_1.REST_API_SCOPE.ARTIFACT_READ],
14
15
  examples: texts_1.EXAMPLE_ARTIFACT_VERSION_GET,
@@ -16,6 +17,7 @@ const commandArtifactVersionGet = (0, utils_1.newCommand)('get', texts_1.DESC_CO
16
17
  commandArtifactVersionGet.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
17
18
  commandArtifactVersionGet.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
18
19
  commandArtifactVersionGet.option('--format <text|json>', texts_1.OPTION_FORMAT);
20
+ commandArtifactVersionGet.option('--no-parent-notes', texts_1.OPTION_NO_PARENT_NOTES);
19
21
  commandArtifactVersionGet.argument('<identifier>', texts_1.OPT_COMMAND_ARTIFACT_IDENTIFIER);
20
22
  commandArtifactVersionGet.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE);
21
23
  commandArtifactVersionGet.argument('<version>', texts_1.OPT_COMMAND_ARTIFACT_VERSION);
@@ -36,7 +38,9 @@ commandArtifactVersionGet.action(async (identifier, version, options) => {
36
38
  }
37
39
  const result = await client.getArtifactVersion(workspace, data.artifact_id, data.artifact_version_id);
38
40
  if (options.format === 'json') {
39
- output_1.default.json(result);
41
+ output_1.default.json(await client.withParentNotes(workspace, result, options.parentNotes, [
42
+ { type: notes_1.PARENT_NOTE_TYPE.ARTIFACT, id: data.artifact_id },
43
+ ]));
40
44
  output_1.default.exitNormal();
41
45
  }
42
46
  else {
@@ -0,0 +1,59 @@
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 cliError_1 = __importDefault(require("../../../cliError"));
7
+ const utils_1 = require("../../../utils");
8
+ const texts_1 = require("../../../texts");
9
+ const input_1 = __importDefault(require("../../../input"));
10
+ const output_1 = __importDefault(require("../../../output"));
11
+ const distro_1 = require("../../../types/distro");
12
+ const commandArtifactVersionUpdate = (0, utils_1.newCommand)('update', texts_1.DESC_COMMAND_ARTIFACT_VERSION_UPDATE, {
13
+ requiredScopes: [utils_1.REST_API_SCOPE.ARTIFACT_WRITE],
14
+ examples: texts_1.EXAMPLE_ARTIFACT_VERSION_UPDATE,
15
+ });
16
+ commandArtifactVersionUpdate.alias('edit');
17
+ commandArtifactVersionUpdate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
18
+ commandArtifactVersionUpdate.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE);
19
+ commandArtifactVersionUpdate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
20
+ commandArtifactVersionUpdate.option('--note <note>', texts_1.OPT_COMMAND_NOTE);
21
+ commandArtifactVersionUpdate.option('--agent-note <note>', texts_1.OPT_COMMAND_AGENT_NOTE);
22
+ commandArtifactVersionUpdate.option('--format <text|json>', texts_1.OPTION_FORMAT);
23
+ commandArtifactVersionUpdate.argument('<identifier>', texts_1.OPT_COMMAND_ARTIFACT_IDENTIFIER);
24
+ commandArtifactVersionUpdate.argument('<version>', texts_1.OPT_COMMAND_ARTIFACT_VERSION);
25
+ commandArtifactVersionUpdate.action(async (identifier, version, options) => {
26
+ const body = {};
27
+ // an empty value clears the note
28
+ if (options.note !== undefined)
29
+ body.note = options.note;
30
+ if (options.agentNote !== undefined)
31
+ body.agent_note = options.agentNote;
32
+ if (!Object.keys(body).length)
33
+ output_1.default.exitError(texts_1.ERR_COMMAND_NO_UPDATE);
34
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
35
+ const project = input_1.default.restApiProject(options.project, true);
36
+ const scope = input_1.default.scope(project, options.scope);
37
+ const client = input_1.default.restApiTokenClient();
38
+ const data = await client.getArtifactVersionByIdentifier(workspace, scope === distro_1.SCOPE.PROJECT ? project : null, identifier, version);
39
+ if (!data || !data.domain) {
40
+ output_1.default.exitError(new cliError_1.default('not_found', texts_1.ERR_WORKSPACE_NOT_FOUND, texts_1.HINT_WORKSPACE_LIST));
41
+ }
42
+ if (!data || !data.artifact_id) {
43
+ output_1.default.exitError(new cliError_1.default('not_found', texts_1.ERR_ARTIFACT_NOT_FOUND, texts_1.HINT_ARTIFACT_LIST));
44
+ }
45
+ if (!data || !data.artifact_version_id) {
46
+ output_1.default.exitError(new cliError_1.default('not_found', texts_1.ERR_ARTIFACT_VERSION_NOT_FOUND, texts_1.HINT_ARTIFACT_VERSION_LIST));
47
+ }
48
+ const result = await client.updateArtifactVersion(workspace, data.artifact_id, data.artifact_version_id, body);
49
+ if (options.format === 'json') {
50
+ output_1.default.json(result);
51
+ output_1.default.exitNormal();
52
+ }
53
+ output_1.default.cyan(result.version);
54
+ if (result.html_url)
55
+ output_1.default.cyan(result.html_url);
56
+ output_1.default.green(texts_1.TXT_ARTIFACT_VERSION_UPDATED);
57
+ output_1.default.exitNormal();
58
+ });
59
+ exports.default = commandArtifactVersionUpdate;
@@ -7,6 +7,7 @@ const utils_1 = require("../../utils");
7
7
  const list_1 = __importDefault(require("./version/list"));
8
8
  const texts_1 = require("../../texts");
9
9
  const get_1 = __importDefault(require("./version/get"));
10
+ const update_1 = __importDefault(require("./version/update"));
10
11
  const delete_1 = __importDefault(require("./version/delete"));
11
12
  const create_1 = __importDefault(require("./version/create"));
12
13
  const open_1 = __importDefault(require("./version/open"));
@@ -14,6 +15,7 @@ const commandArtifactVersion = (0, utils_1.newCommand)('version', texts_1.DESC_C
14
15
  commandArtifactVersion.alias('ver');
15
16
  commandArtifactVersion.addCommand(list_1.default);
16
17
  commandArtifactVersion.addCommand(get_1.default);
18
+ commandArtifactVersion.addCommand(update_1.default);
17
19
  commandArtifactVersion.addCommand(open_1.default);
18
20
  commandArtifactVersion.addCommand(delete_1.default);
19
21
  commandArtifactVersion.addCommand(create_1.default);
@@ -11,6 +11,7 @@ const list_1 = __importDefault(require("./artifact/list"));
11
11
  const create_1 = __importDefault(require("./artifact/create"));
12
12
  const delete_1 = __importDefault(require("./artifact/delete"));
13
13
  const get_1 = __importDefault(require("./artifact/get"));
14
+ const update_1 = __importDefault(require("./artifact/update"));
14
15
  const version_1 = __importDefault(require("./artifact/version"));
15
16
  const docker_1 = __importDefault(require("./artifact/docker"));
16
17
  const composer_1 = __importDefault(require("./artifact/composer"));
@@ -20,6 +21,7 @@ commandArtifact.alias('art');
20
21
  commandArtifact.addCommand(list_1.default);
21
22
  commandArtifact.addCommand(create_1.default);
22
23
  commandArtifact.addCommand(get_1.default);
24
+ commandArtifact.addCommand(update_1.default);
23
25
  commandArtifact.addCommand(open_1.default);
24
26
  commandArtifact.addCommand(delete_1.default);
25
27
  commandArtifact.addCommand(publish_1.default);
@@ -17,6 +17,7 @@ commandDistroGet.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORK
17
17
  commandDistroGet.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE);
18
18
  commandDistroGet.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
19
19
  commandDistroGet.option('--format <text|json>', texts_1.OPTION_FORMAT);
20
+ commandDistroGet.option('--no-parent-notes', texts_1.OPTION_NO_PARENT_NOTES);
20
21
  commandDistroGet.argument('<identifier>', texts_1.OPT_COMMAND_DISTRO_IDENTIFIER);
21
22
  commandDistroGet.action(async (identifier, options) => {
22
23
  const workspace = input_1.default.restApiWorkspace(options.workspace);
@@ -32,7 +33,7 @@ commandDistroGet.action(async (identifier, options) => {
32
33
  }
33
34
  const distro = await client.getDistribution(workspace, scope === distro_1.SCOPE.PROJECT ? project : null, data.distribution_id);
34
35
  if (options.format === 'json') {
35
- output_1.default.json(distro);
36
+ output_1.default.json(await client.withParentNotes(workspace, distro, options.parentNotes));
36
37
  }
37
38
  else {
38
39
  const table = [
@@ -7,6 +7,7 @@ const cliError_1 = __importDefault(require("../../../cliError"));
7
7
  const utils_1 = require("../../../utils");
8
8
  const texts_1 = require("../../../texts");
9
9
  const input_1 = __importDefault(require("../../../input"));
10
+ const notes_1 = require("../../../types/notes");
10
11
  const output_1 = __importDefault(require("../../../output"));
11
12
  const distro_1 = require("../../../types/distro");
12
13
  const targetText = (target) => {
@@ -26,6 +27,7 @@ commandDistroRouteGet.option('-w, --workspace <domain>', texts_1.OPTION_REST_API
26
27
  commandDistroRouteGet.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE);
27
28
  commandDistroRouteGet.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
28
29
  commandDistroRouteGet.option('--format <text|json>', texts_1.OPTION_FORMAT);
30
+ commandDistroRouteGet.option('--no-parent-notes', texts_1.OPTION_NO_PARENT_NOTES);
29
31
  commandDistroRouteGet.argument('<identifier>', texts_1.OPT_COMMAND_DISTRO_IDENTIFIER);
30
32
  commandDistroRouteGet.argument('<route-id>', texts_1.OPT_COMMAND_ROUTE_ID);
31
33
  commandDistroRouteGet.action(async (identifier, routeId, options) => {
@@ -42,7 +44,13 @@ commandDistroRouteGet.action(async (identifier, routeId, options) => {
42
44
  }
43
45
  const route = await client.getRoute(workspace, scope === distro_1.SCOPE.PROJECT ? project : null, data.distribution_id, routeId);
44
46
  if (options.format === 'json') {
45
- output_1.default.json(route);
47
+ output_1.default.json(await client.withParentNotes(workspace, route, options.parentNotes, [
48
+ {
49
+ type: notes_1.PARENT_NOTE_TYPE.DISTRIBUTION,
50
+ id: data.distribution_id,
51
+ project: scope === distro_1.SCOPE.PROJECT ? project : null,
52
+ },
53
+ ]));
46
54
  }
47
55
  else {
48
56
  const table = [
@@ -0,0 +1,50 @@
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 scope_1 = require("./scope");
11
+ // Only the notes: integrations hold credentials, which the CLI never takes
12
+ // (see `integration add`). The PATCH is partial, so the rest stays as it is.
13
+ const commandIntegrationUpdate = (0, utils_1.newCommand)('update', texts_1.DESC_COMMAND_INTEGRATION_UPDATE, {
14
+ requiredScopes: [utils_1.REST_API_SCOPE.INTEGRATION_MANAGE],
15
+ examples: texts_1.EXAMPLE_INTEGRATION_UPDATE,
16
+ });
17
+ commandIntegrationUpdate.alias('edit');
18
+ commandIntegrationUpdate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
19
+ commandIntegrationUpdate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
20
+ commandIntegrationUpdate.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE_ENVIRONMENT);
21
+ commandIntegrationUpdate.option('--environment <identifier>', texts_1.OPTION_INTEGRATION_ENVIRONMENT);
22
+ commandIntegrationUpdate.option('--note <note>', texts_1.OPT_COMMAND_NOTE);
23
+ commandIntegrationUpdate.option('--agent-note <note>', texts_1.OPT_COMMAND_AGENT_NOTE);
24
+ commandIntegrationUpdate.option('--format <text|json>', texts_1.OPTION_FORMAT);
25
+ commandIntegrationUpdate.argument('<identifier>', texts_1.OPTION_INTEGRATION_IDENTIFIER);
26
+ commandIntegrationUpdate.action(async (identifier, options) => {
27
+ const body = {};
28
+ // an empty value clears the note
29
+ if (options.note !== undefined)
30
+ body.note = options.note;
31
+ if (options.agentNote !== undefined)
32
+ body.agent_note = options.agentNote;
33
+ if (!Object.keys(body).length)
34
+ output_1.default.exitError(texts_1.ERR_COMMAND_NO_UPDATE);
35
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
36
+ const client = input_1.default.restApiTokenClient();
37
+ const hash_id = await (0, scope_1.resolveIntegrationId)(client, workspace, identifier, options,
38
+ /* strictLine */ true);
39
+ const result = await client.updateIntegration(workspace, hash_id, body);
40
+ if (options.format === 'json') {
41
+ output_1.default.json(result);
42
+ output_1.default.exitNormal();
43
+ }
44
+ output_1.default.identifier(result.identifier);
45
+ if (result.html_url)
46
+ output_1.default.cyan(result.html_url);
47
+ output_1.default.green(texts_1.TXT_INTEGRATION_UPDATED);
48
+ output_1.default.exitNormal();
49
+ });
50
+ exports.default = commandIntegrationUpdate;
@@ -7,6 +7,7 @@ const utils_1 = require("../utils");
7
7
  const texts_1 = require("../texts");
8
8
  const list_1 = __importDefault(require("./integration/list"));
9
9
  const get_1 = __importDefault(require("./integration/get"));
10
+ const update_1 = __importDefault(require("./integration/update"));
10
11
  const add_1 = __importDefault(require("./integration/add"));
11
12
  const delete_1 = __importDefault(require("./integration/delete"));
12
13
  const types_1 = __importDefault(require("./integration/types"));
@@ -15,6 +16,7 @@ const commandIntegration = (0, utils_1.newCommand)('integration', texts_1.DESC_C
15
16
  commandIntegration.alias('int');
16
17
  commandIntegration.addCommand(list_1.default);
17
18
  commandIntegration.addCommand(get_1.default);
19
+ commandIntegration.addCommand(update_1.default);
18
20
  commandIntegration.addCommand(add_1.default);
19
21
  commandIntegration.addCommand(delete_1.default);
20
22
  commandIntegration.addCommand(types_1.default);
@@ -24,26 +24,25 @@ commandPipelineList.action(async (options) => {
24
24
  const project = input_1.default.restApiProject(options.project);
25
25
  const client = input_1.default.restApiTokenClient();
26
26
  const r = await client.getPipelines(workspace, project, page, perPage);
27
- if (!r.pipelines.length) {
28
- output_1.default.exitNormal(texts_1.TXT_PIPELINES_NOT_FOUND);
29
- }
30
27
  if (options.format === 'json') {
31
28
  output_1.default.json(r.pipelines);
29
+ output_1.default.exitNormal();
30
+ }
31
+ if (!r.pipelines.length) {
32
+ output_1.default.exitNormal(texts_1.TXT_PIPELINES_NOT_FOUND);
32
33
  }
33
- else {
34
- const data = [['NAME', 'STATUS', 'ID', 'IDENTIFIER', 'URL']];
35
- const OutputPipeline = require('../../output/pipeline').default;
36
- for (const pipeline of r.pipelines) {
37
- data.push([
38
- pipeline.name || '-',
39
- OutputPipeline.runStatusText(pipeline.last_execution_status || '-'),
40
- String(pipeline.id || '-'),
41
- pipeline.identifier || '-',
42
- pipeline.html_url || '-',
43
- ]);
44
- }
45
- output_1.default.table(data);
34
+ const data = [['NAME', 'STATUS', 'ID', 'IDENTIFIER', 'URL']];
35
+ const OutputPipeline = require('../../output/pipeline').default;
36
+ for (const pipeline of r.pipelines) {
37
+ data.push([
38
+ pipeline.name || '-',
39
+ OutputPipeline.runStatusText(pipeline.last_execution_status || '-'),
40
+ String(pipeline.id || '-'),
41
+ pipeline.identifier || '-',
42
+ pipeline.html_url || '-',
43
+ ]);
46
44
  }
45
+ output_1.default.table(data);
47
46
  output_1.default.exitNormal();
48
47
  });
49
48
  exports.default = commandPipelineList;
@@ -3,9 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.pipelineParentNotes = pipelineParentNotes;
6
7
  exports.resolvePipelineId = resolvePipelineId;
7
8
  const cliError_1 = __importDefault(require("../../../cliError"));
8
9
  const texts_1 = require("../../../texts");
10
+ const notes_1 = require("../../../types/notes");
11
+ // The notes of the pipeline for the JSONL parent_notes record, read once and
12
+ // not on every poll: what the pipeline is for explains its failure. Never
13
+ // rejects - a pipeline the token cannot read just has no record.
14
+ function pipelineParentNotes(client, workspace, project, pipelineId) {
15
+ return client
16
+ .getParentNotes(workspace, [
17
+ { type: notes_1.PARENT_NOTE_TYPE.PIPELINE, id: pipelineId, project },
18
+ ])
19
+ .catch(() => []);
20
+ }
9
21
  /** Resolve and validate the execution's parent resources. */
10
22
  async function resolvePipelineId(client, workspace, project, identifier) {
11
23
  const data = await client.getPipelineByIdentifier(workspace, project, identifier);