bdy 1.25.34-beta → 1.25.34-dev-pr

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 (99) hide show
  1. package/distTs/package.json +2 -1
  2. package/distTs/src/api/client.js +191 -1
  3. package/distTs/src/autocomplete.js +90 -0
  4. package/distTs/src/cliError.js +5 -0
  5. package/distTs/src/cliIndex.js +3 -0
  6. package/distTs/src/command/artifact/downloadDir.js +110 -0
  7. package/distTs/src/command/autocomplete/install.js +16 -0
  8. package/distTs/src/command/autocomplete/uninstall.js +16 -0
  9. package/distTs/src/command/autocomplete.js +14 -0
  10. package/distTs/src/command/environment/resolve.js +39 -0
  11. package/distTs/src/command/package/create.js +64 -0
  12. package/distTs/src/command/package/delete.js +38 -0
  13. package/distTs/src/command/package/docker/login.js +26 -0
  14. package/distTs/src/command/package/docker.js +11 -0
  15. package/distTs/src/command/package/download.js +138 -0
  16. package/distTs/src/command/package/get.js +36 -0
  17. package/distTs/src/command/package/list.js +31 -0
  18. package/distTs/src/command/package/publish.js +241 -0
  19. package/distTs/src/command/package/version/delete.js +39 -0
  20. package/distTs/src/command/package/version/get.js +45 -0
  21. package/distTs/src/command/package/version/list.js +47 -0
  22. package/distTs/src/command/package/version.js +16 -0
  23. package/distTs/src/command/package.js +26 -0
  24. package/distTs/src/command/pipeline/run/apply.js +62 -0
  25. package/distTs/src/command/pr/comment/add.js +66 -0
  26. package/distTs/src/command/pr/comment/list.js +169 -0
  27. package/distTs/src/command/pr/comment/status.js +48 -0
  28. package/distTs/src/command/pr/comment.js +19 -0
  29. package/distTs/src/command/pr/create.js +43 -0
  30. package/distTs/src/command/pr/diff.js +227 -0
  31. package/distTs/src/command/pr/file/list.js +124 -0
  32. package/distTs/src/command/pr/file/mark.js +45 -0
  33. package/distTs/src/command/pr/file.js +16 -0
  34. package/distTs/src/command/pr/get.js +29 -0
  35. package/distTs/src/command/pr/list.js +79 -0
  36. package/distTs/src/command/pr/merge.js +66 -0
  37. package/distTs/src/command/pr/review/request.js +29 -0
  38. package/distTs/src/command/pr/review/start.js +29 -0
  39. package/distTs/src/command/pr/review/verdict.js +81 -0
  40. package/distTs/src/command/pr/review.js +18 -0
  41. package/distTs/src/command/pr/shared.js +595 -0
  42. package/distTs/src/command/pr/state.js +38 -0
  43. package/distTs/src/command/pr/summary.js +316 -0
  44. package/distTs/src/command/pr/update.js +54 -0
  45. package/distTs/src/command/pr/updateBranch.js +22 -0
  46. package/distTs/src/command/pr/versions.js +42 -0
  47. package/distTs/src/command/pr.js +39 -0
  48. package/distTs/src/command/scrape/validation.js +154 -0
  49. package/distTs/src/command/scrape.js +144 -0
  50. package/distTs/src/command/suiteLink.js +14 -0
  51. package/distTs/src/command/tests/visual/result/download.js +31 -0
  52. package/distTs/src/command/tests/visual/result/get.js +68 -0
  53. package/distTs/src/command/tests/visual/result/list.js +49 -0
  54. package/distTs/src/command/tests/visual/result.js +23 -0
  55. package/distTs/src/command/tests/visual/session/get.js +70 -0
  56. package/distTs/src/command/tests/visual/session/list.js +69 -0
  57. package/distTs/src/command/tests/visual/session/open.js +22 -0
  58. package/distTs/src/command/tests/visual/session/reviewUrl.js +37 -0
  59. package/distTs/src/command/tests/visual/session/update.js +26 -0
  60. package/distTs/src/command/tests/visual/shared/context.js +144 -0
  61. package/distTs/src/command/tests/visual/shared/diffRegions.js +172 -0
  62. package/distTs/src/command/tests/visual/shared/format.js +21 -0
  63. package/distTs/src/command/tests/visual/shared/lookup.js +107 -0
  64. package/distTs/src/command/tests/visual/shared/options.js +90 -0
  65. package/distTs/src/command/tests/visual/shared/review.js +146 -0
  66. package/distTs/src/command/tests/visual/shared/reviewUrl.js +62 -0
  67. package/distTs/src/command/tests/visual/shared/session.js +217 -0
  68. package/distTs/src/command/tests/visual/snapshot/get.js +46 -0
  69. package/distTs/src/command/tests/visual/snapshot/list.js +68 -0
  70. package/distTs/src/command/tests/visual/snapshot/open.js +26 -0
  71. package/distTs/src/command/tests/visual/snapshot/reviewUrl.js +48 -0
  72. package/distTs/src/command/tests/visual/snapshot.js +28 -0
  73. package/distTs/src/command/tests/visual/suite/create.js +38 -0
  74. package/distTs/src/command/tests/visual/suite/delete.js +29 -0
  75. package/distTs/src/command/tests/visual/suite/get.js +43 -0
  76. package/distTs/src/command/tests/visual/suite/list.js +35 -0
  77. package/distTs/src/command/tests/visual/suite/open.js +20 -0
  78. package/distTs/src/command/tests/visual/suite/update.js +47 -0
  79. package/distTs/src/command/tests/visual/suite.js +30 -0
  80. package/distTs/src/command/ut/upload.js +86 -0
  81. package/distTs/src/command/ut.js +12 -0
  82. package/distTs/src/command/vt/close.js +27 -0
  83. package/distTs/src/command/vt/compare/validation.js +46 -0
  84. package/distTs/src/command/vt/compare.js +100 -0
  85. package/distTs/src/command/vt/exec.js +82 -0
  86. package/distTs/src/command/vt/installBrowser.js +20 -0
  87. package/distTs/src/command/vt/shared/validation.js +145 -0
  88. package/distTs/src/command/vt/storybook.js +138 -0
  89. package/distTs/src/command/vt.js +20 -0
  90. package/distTs/src/command/yaml/agents.js +88 -0
  91. package/distTs/src/command/yaml/init.js +110 -0
  92. package/distTs/src/main.js +190 -0
  93. package/distTs/src/output.js +41 -1
  94. package/distTs/src/texts.js +450 -1
  95. package/distTs/src/types/options.js +2 -0
  96. package/distTs/src/types/scrape.js +2 -0
  97. package/distTs/src/types/visualTests.js +2 -0
  98. package/distTs/src/utils.js +133 -3
  99. package/package.json +2 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.25.34-beta",
4
+ "version": "1.25.34-dev-pr",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",
@@ -32,6 +32,7 @@
32
32
  "e2e:target": "vitest run --config e2e/vitest.config.mts e2e/modules/target/",
33
33
  "e2e:environment": "vitest run --config e2e/vitest.config.mts e2e/modules/environment/",
34
34
  "e2e:yaml": "vitest run --config e2e/vitest.config.mts e2e/modules/yaml/",
35
+ "e2e:pr": "vitest run --config e2e/vitest.config.mts e2e/modules/pr/",
35
36
  "unit": "vitest run --config vitest.config.mts"
36
37
  },
37
38
  "files": [
@@ -253,6 +253,7 @@ class ApiClient {
253
253
  else {
254
254
  let message;
255
255
  let nonJsonBody = false;
256
+ let errorBody;
256
257
  try {
257
258
  const json = await responseBody.json();
258
259
  logger_1.default.debug('API CLIENT PARSED RESPONSE:');
@@ -261,6 +262,7 @@ class ApiClient {
261
262
  const value = json?.errors?.[0]?.message ?? json?.error_description ?? json?.error;
262
263
  if (typeof value === 'string')
263
264
  message = value;
265
+ errorBody = json;
264
266
  }
265
267
  catch (err) {
266
268
  nonJsonBody = true;
@@ -269,7 +271,10 @@ class ApiClient {
269
271
  // Edge/WAF throttling uses 403 with an HTML body. Preserve the legacy
270
272
  // rate-limit classification; JSON 403 responses still report API errors.
271
273
  const error = (0, texts_1.ERR_API_DETAILS)(status === 403 && nonJsonBody ? 429 : status, message, path, this.baseUrl, rateLimitReset);
272
- throw new cliError_1.default(error.code, error.message, error.hint);
274
+ const cliError = new cliError_1.default(error.code, error.message, error.hint);
275
+ cliError.status = status;
276
+ cliError.body = errorBody;
277
+ throw cliError;
273
278
  }
274
279
  }
275
280
  // Set by the CLI bootstrap (Input.restApiTokenClient); the transport layer
@@ -811,6 +816,191 @@ class ApiClient {
811
816
  parseResponseBody: false,
812
817
  });
813
818
  }
819
+ // Pull request methods (Buddy-hosted repositories)
820
+ pullsPath(workspace, project, number) {
821
+ const base = `/workspaces/${encodeURIComponent(workspace)}/projects/${encodeURIComponent(project)}/repository/pulls`;
822
+ return number === undefined ? base : `${base}/${encodeURIComponent(number)}`;
823
+ }
824
+ static compactQuery(query) {
825
+ const result = {};
826
+ for (const [key, value] of Object.entries(query)) {
827
+ if (value !== undefined && value !== null && value !== '') {
828
+ result[key] = String(value);
829
+ }
830
+ }
831
+ return result;
832
+ }
833
+ async getPullRequests(workspace, project, query = {}) {
834
+ return await this.request({
835
+ method: 'GET',
836
+ path: this.pullsPath(workspace, project),
837
+ query: ApiClient.compactQuery(query),
838
+ parseResponseBody: true,
839
+ });
840
+ }
841
+ async getPullRequest(workspace, project, number) {
842
+ return await this.request({
843
+ method: 'GET',
844
+ path: this.pullsPath(workspace, project, number),
845
+ parseResponseBody: true,
846
+ });
847
+ }
848
+ async createPullRequest(workspace, project, body) {
849
+ return await this.request({
850
+ method: 'POST',
851
+ path: this.pullsPath(workspace, project),
852
+ body,
853
+ parseResponseBody: true,
854
+ });
855
+ }
856
+ async updatePullRequest(workspace, project, number, body) {
857
+ return await this.request({
858
+ method: 'PATCH',
859
+ path: this.pullsPath(workspace, project, number),
860
+ body,
861
+ parseResponseBody: true,
862
+ });
863
+ }
864
+ async mergePullRequest(workspace, project, number, body) {
865
+ return await this.request({
866
+ method: 'PUT',
867
+ path: `${this.pullsPath(workspace, project, number)}/merge`,
868
+ body,
869
+ parseResponseBody: true,
870
+ });
871
+ }
872
+ async updatePullRequestBranch(workspace, project, number) {
873
+ return await this.request({
874
+ method: 'PUT',
875
+ path: `${this.pullsPath(workspace, project, number)}/update-branch`,
876
+ parseResponseBody: true,
877
+ });
878
+ }
879
+ async getPullRequestVersions(workspace, project, number) {
880
+ return await this.request({
881
+ method: 'GET',
882
+ path: `${this.pullsPath(workspace, project, number)}/versions`,
883
+ parseResponseBody: true,
884
+ });
885
+ }
886
+ async getPullRequestFiles(workspace, project, number, query = {}) {
887
+ return await this.request({
888
+ method: 'GET',
889
+ path: `${this.pullsPath(workspace, project, number)}/files`,
890
+ query: ApiClient.compactQuery(query),
891
+ parseResponseBody: true,
892
+ });
893
+ }
894
+ async markPullRequestFilesViewed(workspace, project, number, body) {
895
+ return await this.request({
896
+ method: 'POST',
897
+ path: `${this.pullsPath(workspace, project, number)}/files/viewed`,
898
+ body,
899
+ parseResponseBody: true,
900
+ });
901
+ }
902
+ async getPullRequestDiff(workspace, project, number, query) {
903
+ return await this.request({
904
+ method: 'GET',
905
+ path: `${this.pullsPath(workspace, project, number)}/diff`,
906
+ query: ApiClient.compactQuery(query),
907
+ parseResponseBody: true,
908
+ });
909
+ }
910
+ async getPullRequestReview(workspace, project, number) {
911
+ return await this.request({
912
+ method: 'GET',
913
+ path: `${this.pullsPath(workspace, project, number)}/review`,
914
+ parseResponseBody: true,
915
+ });
916
+ }
917
+ async startPullRequestReview(workspace, project, number, version) {
918
+ return await this.request({
919
+ method: 'POST',
920
+ path: `${this.pullsPath(workspace, project, number)}/review`,
921
+ body: { version },
922
+ parseResponseBody: true,
923
+ });
924
+ }
925
+ async submitPullRequestVerdict(workspace, project, number, body) {
926
+ return await this.request({
927
+ method: 'PUT',
928
+ path: `${this.pullsPath(workspace, project, number)}/review`,
929
+ body,
930
+ parseResponseBody: true,
931
+ });
932
+ }
933
+ async getPullRequestReviews(workspace, project, number) {
934
+ return await this.request({
935
+ method: 'GET',
936
+ path: `${this.pullsPath(workspace, project, number)}/reviews`,
937
+ parseResponseBody: true,
938
+ });
939
+ }
940
+ async requestPullRequestReview(workspace, project, number, reviewers) {
941
+ return await this.request({
942
+ method: 'POST',
943
+ path: `${this.pullsPath(workspace, project, number)}/reviewers`,
944
+ body: { reviewers },
945
+ parseResponseBody: true,
946
+ });
947
+ }
948
+ async getPullRequestActivity(workspace, project, number, since) {
949
+ return await this.request({
950
+ method: 'GET',
951
+ path: `${this.pullsPath(workspace, project, number)}/activity`,
952
+ query: ApiClient.compactQuery({ since }),
953
+ parseResponseBody: true,
954
+ });
955
+ }
956
+ async addPullRequestComment(workspace, project, number, comment) {
957
+ return await this.request({
958
+ method: 'POST',
959
+ path: `${this.pullsPath(workspace, project, number)}/comments`,
960
+ body: { comment },
961
+ parseResponseBody: true,
962
+ });
963
+ }
964
+ async getPullRequestThreads(workspace, project, number, query = {}) {
965
+ return await this.request({
966
+ method: 'GET',
967
+ path: `${this.pullsPath(workspace, project, number)}/threads`,
968
+ query: ApiClient.compactQuery(query),
969
+ parseResponseBody: true,
970
+ });
971
+ }
972
+ async getPullRequestThread(workspace, project, number, threadId, version) {
973
+ return await this.request({
974
+ method: 'GET',
975
+ path: `${this.pullsPath(workspace, project, number)}/threads/${encodeURIComponent(threadId)}`,
976
+ query: ApiClient.compactQuery({ version }),
977
+ parseResponseBody: true,
978
+ });
979
+ }
980
+ async addPullRequestThread(workspace, project, number, body) {
981
+ return await this.request({
982
+ method: 'POST',
983
+ path: `${this.pullsPath(workspace, project, number)}/threads`,
984
+ body,
985
+ parseResponseBody: true,
986
+ });
987
+ }
988
+ async addPullRequestThreadComment(workspace, project, number, threadId, comment) {
989
+ return await this.request({
990
+ method: 'POST',
991
+ path: `${this.pullsPath(workspace, project, number)}/threads/${encodeURIComponent(threadId)}/comments`,
992
+ body: { comment },
993
+ parseResponseBody: true,
994
+ });
995
+ }
996
+ async updatePullRequestThread(workspace, project, number, threadId, body) {
997
+ return await this.request({
998
+ method: 'PATCH',
999
+ path: `${this.pullsPath(workspace, project, number)}/threads/${encodeURIComponent(threadId)}`,
1000
+ body,
1001
+ parseResponseBody: true,
1002
+ });
1003
+ }
814
1004
  // Environment methods
815
1005
  async getEnvironments(workspace, project) {
816
1006
  const query = {};
@@ -0,0 +1,90 @@
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 logger_1 = __importDefault(require("./logger"));
7
+ class Autocomplete {
8
+ getCommandsMap(command) {
9
+ const commands = {};
10
+ command.commands.forEach((c) => {
11
+ const map = this.getCommandsMap(c);
12
+ const name = c.name() || 'bdy';
13
+ commands[name] = map;
14
+ c.aliases().forEach((a) => {
15
+ commands[a] = map;
16
+ });
17
+ });
18
+ command.options.forEach((o) => {
19
+ const name = `--${o.name()}`;
20
+ commands[name] = {};
21
+ });
22
+ let lastArg = commands;
23
+ command.registeredArguments.forEach((a) => {
24
+ logger_1.default.info(a);
25
+ let name;
26
+ if (a.required) {
27
+ name = `<${a.name()}>`;
28
+ }
29
+ else {
30
+ name = `[${a.name()}]`;
31
+ }
32
+ name = name.replaceAll(':', '꞉'); // U+A789 MODIFIER LETTER COLON - looks like : but doesn't trigger tabtab delimiter
33
+ lastArg[name] = {};
34
+ lastArg = lastArg[name];
35
+ });
36
+ return commands;
37
+ }
38
+ init(rootCommand) {
39
+ // COMP_LINE is set by all shells (bash natively, zsh/fish via tabtab scripts) when invoking completion
40
+ if (!process.env.COMP_LINE)
41
+ return false;
42
+ const tabtab = require('tabtab');
43
+ const env = tabtab.parseEnv(process.env);
44
+ if (!env.complete)
45
+ return false;
46
+ let map = {
47
+ bdy: this.getCommandsMap(rootCommand)
48
+ };
49
+ const s = (env.partial || '').trim().split(' ').filter((n) => !n.startsWith('--'));
50
+ const last = s[s.length - 1];
51
+ for (let i = 0; i < s.length - 1; i += 1) {
52
+ const name = s[i];
53
+ if (!map[name]) {
54
+ const arg = Object.keys(map).find((k) => k.startsWith('<') || k.startsWith('['));
55
+ if (arg) {
56
+ map = map[arg];
57
+ }
58
+ else {
59
+ return true;
60
+ }
61
+ }
62
+ else {
63
+ map = map[name];
64
+ }
65
+ }
66
+ if (map[last])
67
+ map = map[last];
68
+ else {
69
+ const arg = Object.keys(map).find((k) => k.startsWith('<') || k.startsWith('['));
70
+ if (arg)
71
+ map = map[arg];
72
+ }
73
+ tabtab.log(Object.keys(map));
74
+ return true;
75
+ }
76
+ async install() {
77
+ const tabtab = require('tabtab');
78
+ await tabtab.install({
79
+ name: process.title,
80
+ completer: process.title
81
+ });
82
+ }
83
+ async uninstall() {
84
+ const tabtab = require('tabtab');
85
+ await tabtab.uninstall({
86
+ name: process.title
87
+ });
88
+ }
89
+ }
90
+ exports.default = new Autocomplete();
@@ -13,6 +13,11 @@ var SemanticExitCode;
13
13
  class CliError extends Error {
14
14
  code;
15
15
  hint;
16
+ // Set by ApiClient for API errors: the HTTP status and the parsed JSON body,
17
+ // so a command can read fields the API sends next to `errors` (e.g. the
18
+ // current version in a 409 of a pull request verdict).
19
+ status;
20
+ body;
16
21
  constructor(code, message, hint = null, options) {
17
22
  super(message, options);
18
23
  this.code = code;
@@ -33,6 +33,7 @@ const register_1 = __importDefault(require("./command/register"));
33
33
  const mcp_1 = __importDefault(require("./command/mcp"));
34
34
  const discover_1 = __importDefault(require("./command/discover"));
35
35
  const context_1 = __importDefault(require("./command/context"));
36
+ const pr_1 = __importDefault(require("./command/pr"));
36
37
  const input_1 = __importDefault(require("./input"));
37
38
  const cliCommand_1 = __importDefault(require("./cliCommand"));
38
39
  const client_1 = __importDefault(require("./api/client"));
@@ -50,6 +51,7 @@ function cliIndex() {
50
51
  program.hook('preAction', pre_1.default);
51
52
  program.configureHelp({
52
53
  formatHelp: utils_1.formatHelp,
54
+ subcommandTerm: utils_1.subcommandTerm,
53
55
  });
54
56
  // root options must come before the subcommand, so -v here can't
55
57
  // shadow subcommand flags like `sandbox create -v <variable>`
@@ -76,6 +78,7 @@ function cliIndex() {
76
78
  program.addCommand(logout_1.default);
77
79
  program.addCommand(workspace_1.default);
78
80
  program.addCommand(project_1.default);
81
+ program.addCommand(pr_1.default);
79
82
  program.addCommand(yaml_1.default);
80
83
  program.addCommand(api_1.default);
81
84
  program.addCommand(mcp_1.default);
@@ -0,0 +1,110 @@
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
+ exports.prepareDownloadDirectory = prepareDownloadDirectory;
7
+ exports.downloadArtifactVersionToDirectory = downloadArtifactVersionToDirectory;
8
+ const utils_1 = require("../../utils");
9
+ const texts_1 = require("../../texts");
10
+ const output_1 = __importDefault(require("../../output"));
11
+ const logger_1 = __importDefault(require("../../logger"));
12
+ const path_1 = require("path");
13
+ const fs_1 = __importDefault(require("fs"));
14
+ const promises_1 = __importDefault(require("node:stream/promises"));
15
+ /**
16
+ * Makes sure `path` is a directory the artifact can be unpacked into: created
17
+ * when missing, wiped with `replace`, and otherwise required to be empty
18
+ * unless `merge` is set. Returns the absolute path.
19
+ */
20
+ function prepareDownloadDirectory(path, options) {
21
+ const dirPath = (0, path_1.resolve)(path);
22
+ const exists = fs_1.default.existsSync(dirPath);
23
+ if (!exists) {
24
+ try {
25
+ fs_1.default.mkdirSync(dirPath, {
26
+ recursive: true,
27
+ });
28
+ }
29
+ catch (err) {
30
+ logger_1.default.error(err);
31
+ output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_MKDIR)(dirPath));
32
+ }
33
+ }
34
+ else if (options.replace) {
35
+ try {
36
+ fs_1.default.rmSync(dirPath, {
37
+ recursive: true,
38
+ force: true,
39
+ });
40
+ fs_1.default.mkdirSync(dirPath, {
41
+ recursive: true,
42
+ });
43
+ }
44
+ catch (err) {
45
+ logger_1.default.error(err);
46
+ output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_REPLACE)(dirPath));
47
+ }
48
+ }
49
+ try {
50
+ const stat = fs_1.default.statSync(dirPath);
51
+ if (!stat.isDirectory()) {
52
+ output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_IS_FILE)(dirPath));
53
+ }
54
+ }
55
+ catch (err) {
56
+ logger_1.default.error(err);
57
+ output_1.default.exitError(texts_1.ERR_SWW);
58
+ }
59
+ let empty = true;
60
+ try {
61
+ const entries = fs_1.default.readdirSync(dirPath);
62
+ empty = !entries.length;
63
+ }
64
+ catch (err) {
65
+ logger_1.default.error(err);
66
+ output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_READDIR)(dirPath));
67
+ }
68
+ if (!empty && !options.merge) {
69
+ output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_NOT_EMPTY_DIR)(dirPath));
70
+ }
71
+ return dirPath;
72
+ }
73
+ // Returns the number of files unpacked.
74
+ async function downloadArtifactVersionToDirectory(client, workspace, artifactId, versionId, dirPath, quiet = false) {
75
+ const { v4 } = require('uuid');
76
+ const ArchiverExtract = require('../../unzipper').default;
77
+ const { UNZIPPER_FORMAT } = require('../../unzipper');
78
+ const zipPath = (0, path_1.join)((0, utils_1.getHomeDirectory)(), `${v4()}.zip`);
79
+ const clearZip = () => {
80
+ try {
81
+ fs_1.default.rmSync(zipPath);
82
+ }
83
+ catch {
84
+ // do nothing
85
+ }
86
+ };
87
+ // Progress rewrites the previous line, which only works on a terminal; a
88
+ // piped stdout would otherwise get one line per extracted file.
89
+ const say = output_1.default.progress(quiet || !output_1.default.isStdOutTTY());
90
+ say(texts_1.TXT_ARTIFACT_DOWNLOADING_ZIP);
91
+ const body = await client.downloadArtifactVersion(workspace, artifactId, versionId);
92
+ let count = 0;
93
+ try {
94
+ await promises_1.default.pipeline(body, fs_1.default.createWriteStream(zipPath));
95
+ say(texts_1.TXT_ARTIFACT_DOWNLOADED_ZIP, true, true);
96
+ say(texts_1.TXT_ARTIFACT_UNZIPPING);
97
+ await ArchiverExtract.extract(UNZIPPER_FORMAT.ZIP, zipPath, dirPath, async () => {
98
+ count += 1;
99
+ say((0, texts_1.TXT_ARTIFACT_UNZIPPING_COUNT)(count), true, true);
100
+ });
101
+ clearZip();
102
+ say(texts_1.TXT_ARTIFACT_UNZIPPED, true, true);
103
+ }
104
+ catch (err) {
105
+ logger_1.default.error(err);
106
+ clearZip();
107
+ output_1.default.exitError(texts_1.ERR_SWW);
108
+ }
109
+ return count;
110
+ }
@@ -0,0 +1,16 @@
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 autocomplete_1 = __importDefault(require("../../autocomplete"));
8
+ const texts_1 = require("../../texts");
9
+ const output_1 = __importDefault(require("../../output"));
10
+ const commandAutocompleteInstall = (0, utils_1.newCommand)('install', texts_1.DESC_COMMAND_AUTOCOMPLETE_INSTALL);
11
+ commandAutocompleteInstall.alias('i');
12
+ commandAutocompleteInstall.action(async () => {
13
+ await autocomplete_1.default.install();
14
+ output_1.default.exitSuccess(texts_1.TXT_AUTOCOMPLETE_INSTALLED);
15
+ });
16
+ exports.default = commandAutocompleteInstall;
@@ -0,0 +1,16 @@
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 autocomplete_1 = __importDefault(require("../../autocomplete"));
8
+ const texts_1 = require("../../texts");
9
+ const output_1 = __importDefault(require("../../output"));
10
+ const commandAutocompleteUninstall = (0, utils_1.newCommand)('uninstall', texts_1.DESC_COMMAND_AUTOCOMPLETE_UNINSTALL);
11
+ commandAutocompleteUninstall.alias('u');
12
+ commandAutocompleteUninstall.action(async () => {
13
+ await autocomplete_1.default.uninstall();
14
+ output_1.default.exitSuccess(texts_1.TXT_AUTOCOMPLETE_UNINSTALLED);
15
+ });
16
+ exports.default = commandAutocompleteUninstall;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../utils");
7
+ const install_1 = __importDefault(require("./autocomplete/install"));
8
+ const uninstall_1 = __importDefault(require("./autocomplete/uninstall"));
9
+ const texts_1 = require("../texts");
10
+ const commandAutocomplete = (0, utils_1.newCommand)('autocomplete', texts_1.DESC_COMMAND_AUTOCOMPLETE);
11
+ commandAutocomplete.alias('ac');
12
+ commandAutocomplete.addCommand(install_1.default);
13
+ commandAutocomplete.addCommand(uninstall_1.default);
14
+ exports.default = commandAutocomplete;
@@ -0,0 +1,39 @@
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
+ exports.resolveEnvironmentId = void 0;
7
+ const texts_1 = require("../../texts");
8
+ const output_1 = __importDefault(require("../../output"));
9
+ const input_1 = __importDefault(require("../../input"));
10
+ // Shared resolve preamble for commands taking an environment identifier:
11
+ // project context from flags/env -> /identifiers -> hash id, exiting on a
12
+ // miss. Without a project the identifier resolves as a workspace
13
+ // environment; with one, along the project line.
14
+ //
15
+ // strictProject is for mutating commands (update/delete): an explicit -p is
16
+ // a statement "the environment of this project", so the resolved environment
17
+ // must actually live there. Without it /identifiers silently falls back to
18
+ // the workspace environment of the same identifier and the write lands on a
19
+ // workspace-wide resource. Reads keep the fallback - that is how workspace
20
+ // environments stay addressable from inside a project context.
21
+ const resolveEnvironmentId = async (client, workspace, identifier, options, strictProject = false) => {
22
+ const project = input_1.default.restApiProject(options.project, true);
23
+ const resolved = await client.getEnvironmentByIdentifier(workspace, identifier, project);
24
+ // A nonexistent project is rejected by the API client
25
+ // (getResourceByIdentifier); here only the environment itself can miss.
26
+ if (!resolved.environment_id) {
27
+ output_1.default.exitError(texts_1.ERR_ENVIRONMENT_NOT_FOUND);
28
+ }
29
+ if (strictProject && options.project) {
30
+ const environment = await client.getEnvironment(workspace, resolved.environment_id);
31
+ // a workspace environment carries no project, so this also fails the
32
+ // workspace-fallback case
33
+ if (environment.project?.name !== resolved.project_identifier) {
34
+ output_1.default.exitError(texts_1.ERR_ENVIRONMENT_NOT_FOUND);
35
+ }
36
+ }
37
+ return resolved.environment_id;
38
+ };
39
+ exports.resolveEnvironmentId = resolveEnvironmentId;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const input_1 = __importDefault(require("../../input"));
9
+ const output_1 = __importDefault(require("../../output"));
10
+ const commandPackageCreate = (0, utils_1.newCommand)('create', texts_1.DESC_COMMAND_PACKAGE_CREATE);
11
+ commandPackageCreate.alias('add');
12
+ commandPackageCreate.option('-i, --identifier <identifier>', texts_1.OPT_COMMAND_PACKAGE_CREATE_IDENTIFIER);
13
+ commandPackageCreate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
14
+ commandPackageCreate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
15
+ commandPackageCreate.option('-t, --type <type>', texts_1.OPT_COMMAND_PACKAGE_TYPE, utils_1.PACKAGE_TYPE.FILE);
16
+ commandPackageCreate.option('-b, --buddy', texts_1.OPTION_HTTP_AUTH_BUDDY);
17
+ commandPackageCreate.option('-a, --auth <user:pass>', texts_1.OPTION_HTTP_AUTH);
18
+ commandPackageCreate.argument('[name]', texts_1.OPT_COMMAND_PACKAGE_NAME);
19
+ commandPackageCreate.addHelpText('after', texts_1.EXAMPLE_PACKAGE_CREATE);
20
+ commandPackageCreate.action(async (name, options) => {
21
+ const humanId = require('human-id').default;
22
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
23
+ const project = input_1.default.restApiProject(options.project, true);
24
+ const client = input_1.default.restApiTokenClient();
25
+ const type = input_1.default.packageType(options.type);
26
+ const scope = input_1.default.packageScope(project);
27
+ if (!name) {
28
+ if (options.identifier)
29
+ name = options.identifier;
30
+ else
31
+ name = humanId({ separator: '-', capitalize: false });
32
+ }
33
+ const data = {
34
+ name,
35
+ type,
36
+ scope,
37
+ authorization: {
38
+ type: utils_1.PACKAGE_AUTH_TYPE.NONE,
39
+ },
40
+ };
41
+ if (project) {
42
+ data.project = {
43
+ name: project,
44
+ };
45
+ }
46
+ if (options.identifier)
47
+ data.identifier = options.identifier;
48
+ if (options.auth) {
49
+ const { password, login } = input_1.default.auth(options.auth);
50
+ data.authorization = {
51
+ type: utils_1.PACKAGE_AUTH_TYPE.BASIC,
52
+ user: login,
53
+ password,
54
+ };
55
+ }
56
+ else if (options.buddy) {
57
+ data.authorization = {
58
+ type: utils_1.PACKAGE_AUTH_TYPE.BUDDY,
59
+ };
60
+ }
61
+ const result = await client.createPackage(workspace, data);
62
+ output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_CREATED)(client.baseUrl, workspace, result));
63
+ });
64
+ exports.default = commandPackageCreate;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const input_1 = __importDefault(require("../../input"));
9
+ const output_1 = __importDefault(require("../../output"));
10
+ const commandPackageDelete = (0, utils_1.newCommand)('delete', texts_1.DESC_COMMAND_PACKAGE_DELETE);
11
+ commandPackageDelete.alias('rm');
12
+ commandPackageDelete.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
13
+ commandPackageDelete.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
14
+ commandPackageDelete.option('-f, --force', texts_1.OPTION_CONFIRM_FORCE);
15
+ commandPackageDelete.argument('<identifier>', texts_1.OPT_COMMAND_PACKAGE_IDENTIFIER);
16
+ commandPackageDelete.addHelpText('after', texts_1.EXAMPLE_PACKAGE_DELETE);
17
+ commandPackageDelete.action(async (identifier, options) => {
18
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
19
+ const project = input_1.default.restApiProject(options.project);
20
+ const client = input_1.default.restApiTokenClient();
21
+ const data = await client.getPackageVersionByIdentifier(workspace, project, identifier);
22
+ if (!data || !data.domain) {
23
+ output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_FOUND);
24
+ }
25
+ if (!data.pkg_id) {
26
+ output_1.default.exitError(texts_1.ERR_PACKAGE_NOT_FOUND);
27
+ }
28
+ const confirmed = options.force ||
29
+ (await output_1.default.confirm((0, texts_1.TXT_PACKAGE_DELETE_CONFIRM)(identifier)));
30
+ if (confirmed) {
31
+ await client.deletePackage(workspace, data.pkg_id);
32
+ output_1.default.exitSuccess(texts_1.TXT_PACKAGE_DELETED);
33
+ }
34
+ else {
35
+ output_1.default.exitNormal();
36
+ }
37
+ });
38
+ exports.default = commandPackageDelete;