@celonis/content-cli 1.13.1 → 1.14.1

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 (88) hide show
  1. package/README.md +17 -5
  2. package/commands/action-flows/action-flow/action-flow.service.js +9 -9
  3. package/commands/action-flows/module.js +2 -1
  4. package/commands/asset-registry/asset-registry-api.js +1 -30
  5. package/commands/asset-registry/asset-registry.service.js +20 -67
  6. package/commands/asset-registry/module.js +0 -26
  7. package/commands/bookmarks/bookmarks-api.js +49 -0
  8. package/commands/bookmarks/bookmarks-command.service.js +48 -0
  9. package/{core/utils/path.js → commands/bookmarks/bookmarks.interfaces.js} +0 -5
  10. package/commands/bookmarks/module.js +49 -0
  11. package/commands/configuration-management/api/node-api.js +17 -0
  12. package/commands/configuration-management/branch/api/branch.api.js +88 -0
  13. package/commands/configuration-management/branch/branch-export-import.command.service.js +283 -0
  14. package/commands/configuration-management/branch/branch.command.service.js +182 -0
  15. package/commands/configuration-management/branch/interfaces/branch.interfaces.js +41 -0
  16. package/commands/configuration-management/metadata.service.js +9 -5
  17. package/commands/configuration-management/module.js +170 -6
  18. package/commands/configuration-management/node-dependency.service.js +5 -3
  19. package/commands/configuration-management/node-diff.service.js +10 -6
  20. package/commands/configuration-management/node.service.js +14 -10
  21. package/commands/configuration-management/package-validation.service.js +11 -5
  22. package/commands/configuration-management/package-version.service.js +7 -5
  23. package/commands/configuration-management/single-package-export.service.js +6 -6
  24. package/commands/configuration-management/single-package-import.service.js +28 -24
  25. package/commands/configuration-management/staging-package.service.js +9 -5
  26. package/commands/configuration-management/variable.service.js +11 -7
  27. package/commands/data-pipeline/connection/connection.commands.js +4 -2
  28. package/commands/data-pipeline/data-pool/data-pool-service.js +13 -9
  29. package/commands/data-pipeline/data-pool/data-pool.commands.js +2 -1
  30. package/commands/deployment/deployment.service.js +15 -13
  31. package/commands/deployment/module.js +4 -7
  32. package/commands/studio/manager/space.manager.js +21 -10
  33. package/commands/studio/service/asset-service.js +5 -4
  34. package/commands/studio/service/package.service.js +9 -5
  35. package/commands/t2tc/diff.service.js +15 -9
  36. package/commands/t2tc/t2tc-package.service.js +25 -23
  37. package/content-cli.js +4 -0
  38. package/core/command/module-handler.js +8 -1
  39. package/core/feature-flag/feature-disabled-error.js +52 -0
  40. package/core/http/http-client.js +18 -0
  41. package/core/http/http-shared/base.manager.js +35 -59
  42. package/core/utils/branches.js +10 -0
  43. package/core/utils/cui-api.js +52 -0
  44. package/core/utils/cui-file-service.js +106 -0
  45. package/core/utils/file-service.js +7 -13
  46. package/lib/commands/action-flows/action-flow/action-flow.service.d.ts +1 -0
  47. package/lib/commands/asset-registry/asset-registry-api.d.ts +2 -6
  48. package/lib/commands/asset-registry/asset-registry.interfaces.d.ts +0 -17
  49. package/lib/commands/asset-registry/asset-registry.service.d.ts +3 -6
  50. package/lib/commands/asset-registry/module.d.ts +0 -2
  51. package/lib/commands/bookmarks/bookmarks-api.d.ts +8 -0
  52. package/lib/commands/bookmarks/bookmarks-command.service.d.ts +8 -0
  53. package/lib/commands/bookmarks/bookmarks.interfaces.d.ts +34 -0
  54. package/lib/commands/bookmarks/module.d.ts +8 -0
  55. package/lib/commands/configuration-management/api/node-api.d.ts +1 -0
  56. package/lib/commands/configuration-management/branch/api/branch.api.d.ts +12 -0
  57. package/lib/commands/configuration-management/branch/branch-export-import.command.service.d.ts +37 -0
  58. package/lib/commands/configuration-management/branch/branch.command.service.d.ts +19 -0
  59. package/lib/commands/configuration-management/branch/interfaces/branch.interfaces.d.ts +139 -0
  60. package/lib/commands/configuration-management/interfaces/package-validation.interfaces.d.ts +1 -1
  61. package/lib/commands/configuration-management/metadata.service.d.ts +1 -0
  62. package/lib/commands/configuration-management/module.d.ts +8 -0
  63. package/lib/commands/configuration-management/node-dependency.service.d.ts +1 -0
  64. package/lib/commands/configuration-management/node-diff.service.d.ts +1 -0
  65. package/lib/commands/configuration-management/node.service.d.ts +2 -1
  66. package/lib/commands/configuration-management/package-validation.service.d.ts +1 -0
  67. package/lib/commands/configuration-management/package-version.service.d.ts +1 -0
  68. package/lib/commands/configuration-management/single-package-export.service.d.ts +1 -0
  69. package/lib/commands/configuration-management/single-package-import.service.d.ts +6 -3
  70. package/lib/commands/configuration-management/staging-package.service.d.ts +1 -0
  71. package/lib/commands/configuration-management/variable.service.d.ts +1 -0
  72. package/lib/commands/data-pipeline/data-pool/data-pool-service.d.ts +1 -0
  73. package/lib/commands/deployment/deployment.service.d.ts +1 -0
  74. package/lib/commands/studio/service/asset-service.d.ts +1 -0
  75. package/lib/commands/studio/service/package.service.d.ts +1 -0
  76. package/lib/commands/t2tc/diff.service.d.ts +1 -0
  77. package/lib/commands/t2tc/t2tc-package.service.d.ts +1 -0
  78. package/lib/core/command/module-handler.d.ts +4 -4
  79. package/lib/core/feature-flag/feature-disabled-error.d.ts +16 -0
  80. package/lib/core/http/http-client.d.ts +4 -0
  81. package/lib/core/http/http-shared/base.manager.d.ts +7 -5
  82. package/lib/core/http/http-shared/manager-config.interface.d.ts +1 -1
  83. package/lib/core/utils/branches.d.ts +3 -0
  84. package/lib/core/utils/cui-api.d.ts +26 -0
  85. package/lib/core/utils/cui-file-service.d.ts +19 -0
  86. package/lib/core/utils/file-service.d.ts +0 -1
  87. package/package.json +3 -3
  88. package/lib/core/utils/path.d.ts +0 -1
@@ -13,7 +13,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  if (v !== undefined) module.exports = v;
14
14
  }
15
15
  else if (typeof define === "function" && define.amd) {
16
- define(["require", "exports", "adm-zip", "stream", "form-data", "uuid", "../../core/utils/logger", "../../core/utils/file-service", "./api/diff-api"], factory);
16
+ define(["require", "exports", "adm-zip", "stream", "form-data", "uuid", "../../core/utils/logger", "../../core/utils/file-service", "../../core/utils/cui-file-service", "./api/diff-api"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
@@ -25,10 +25,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
25
25
  const uuid_1 = require("uuid");
26
26
  const logger_1 = require("../../core/utils/logger");
27
27
  const file_service_1 = require("../../core/utils/file-service");
28
+ const cui_file_service_1 = require("../../core/utils/cui-file-service");
28
29
  const diff_api_1 = require("./api/diff-api");
29
30
  class DiffService {
30
31
  constructor(context) {
31
32
  this.diffApi = new diff_api_1.DiffApi(context);
33
+ this.cuiFileService = new cui_file_service_1.CuiFileService(context);
32
34
  }
33
35
  diffPackages(file, hasChanges, baseVersion, jsonResponse) {
34
36
  return __awaiter(this, void 0, void 0, function* () {
@@ -46,7 +48,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
46
48
  const formData = this.buildBodyForDiff(packages);
47
49
  const returnedHasChangesData = yield this.diffApi.hasChanges(baseVersion, formData);
48
50
  if (jsonResponse) {
49
- this.exportListOfPackageDiffMetadata(returnedHasChangesData);
51
+ yield this.exportListOfPackageDiffMetadata(returnedHasChangesData);
50
52
  }
51
53
  else {
52
54
  logger_1.logger.info(this.buildStringResponseForPackageDiffMetadataList(returnedHasChangesData));
@@ -59,7 +61,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
59
61
  const formData = this.buildBodyForDiff(packages);
60
62
  const returnedHasChangesData = yield this.diffApi.diffPackages(baseVersion, formData);
61
63
  if (jsonResponse) {
62
- this.exportListOfPackageDiffs(returnedHasChangesData);
64
+ yield this.exportListOfPackageDiffs(returnedHasChangesData);
63
65
  }
64
66
  else {
65
67
  logger_1.logger.info(this.buildStringResponseForPackageDiffs(returnedHasChangesData));
@@ -81,14 +83,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
81
83
  });
82
84
  }
83
85
  exportListOfPackageDiffs(packageDiffs) {
84
- const filename = (0, uuid_1.v4)() + ".json";
85
- file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(packageDiffs), filename);
86
- logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + filename);
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ const filename = (0, uuid_1.v4)() + ".json";
88
+ const writtenFilename = yield this.cuiFileService.writeToFileWithGivenName(JSON.stringify(packageDiffs), filename);
89
+ logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + writtenFilename);
90
+ });
87
91
  }
88
92
  exportListOfPackageDiffMetadata(packageDiffMetadata) {
89
- const filename = (0, uuid_1.v4)() + ".json";
90
- file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(packageDiffMetadata), filename);
91
- logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + filename);
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ const filename = (0, uuid_1.v4)() + ".json";
95
+ const writtenFilename = yield this.cuiFileService.writeToFileWithGivenName(JSON.stringify(packageDiffMetadata), filename);
96
+ logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + writtenFilename);
97
+ });
92
98
  }
93
99
  buildStringResponseForPackageDiffs(packageDiffs) {
94
100
  return "\n" + JSON.stringify(packageDiffs, null, 2);
@@ -13,7 +13,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  if (v !== undefined) module.exports = v;
14
14
  }
15
15
  else if (typeof define === "function" && define.amd) {
16
- define(["require", "exports", "uuid", "form-data", "stream", "adm-zip", "./batch-export-import.constants", "../../core/utils/file-service", "../../core/utils/logger", "../../core/utils/json", "../studio/api/package-api", "./api/t2tc-package-api", "../configuration-management/api/variable-api", "../configuration-management/connection-variable.helper", "./studio.service", "../../core/git-profile/git/git.service", "fs", "../../core/utils/file.constants", "node:path"], factory);
16
+ define(["require", "exports", "uuid", "form-data", "stream", "adm-zip", "./batch-export-import.constants", "../../core/utils/file-service", "../../core/utils/cui-file-service", "../../core/utils/logger", "../../core/utils/json", "../studio/api/package-api", "./api/t2tc-package-api", "../configuration-management/api/variable-api", "../configuration-management/connection-variable.helper", "./studio.service", "../../core/git-profile/git/git.service", "fs", "../../core/utils/file.constants"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
@@ -25,6 +25,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
25
25
  const AdmZip = require("adm-zip");
26
26
  const batch_export_import_constants_1 = require("./batch-export-import.constants");
27
27
  const file_service_1 = require("../../core/utils/file-service");
28
+ const cui_file_service_1 = require("../../core/utils/cui-file-service");
28
29
  const logger_1 = require("../../core/utils/logger");
29
30
  const json_1 = require("../../core/utils/json");
30
31
  const package_api_1 = require("../studio/api/package-api");
@@ -35,7 +36,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
35
36
  const git_service_1 = require("../../core/git-profile/git/git.service");
36
37
  const fs = require("fs");
37
38
  const file_constants_1 = require("../../core/utils/file.constants");
38
- const node_path_1 = require("node:path");
39
39
  class T2tcPackageService {
40
40
  constructor(context) {
41
41
  this.t2tcPackageApi = new t2tc_package_api_1.T2tcPackageApi(context);
@@ -43,6 +43,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
43
43
  this.studioPackageApi = new package_api_1.PackageApi(context);
44
44
  this.studioService = new studio_service_1.StudioService(context);
45
45
  this.gitService = new git_service_1.GitService(context);
46
+ this.cuiFileService = new cui_file_service_1.CuiFileService(context);
46
47
  }
47
48
  listActivePackages(flavors, includeBranches) {
48
49
  return __awaiter(this, void 0, void 0, function* () {
@@ -65,7 +66,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
65
66
  packagesToExport = yield this.t2tcPackageApi.findAllActivePackages(flavors, withDependencies, includeBranches);
66
67
  }
67
68
  packagesToExport = yield this.studioService.getExportPackagesWithStudioData(packagesToExport, withDependencies);
68
- this.exportListOfPackages(packagesToExport);
69
+ yield this.exportListOfPackages(packagesToExport);
69
70
  });
70
71
  }
71
72
  listPackagesByKeysWithVersion(keysByVersion, withDependencies) {
@@ -112,7 +113,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
112
113
  fs.rmSync(extractedDirectory, { recursive: true });
113
114
  }
114
115
  else {
115
- this.downloadZip(exportedPackagesZip, unzip);
116
+ yield this.downloadZip(exportedPackagesZip, unzip);
116
117
  }
117
118
  });
118
119
  }
@@ -143,15 +144,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
143
144
  }
144
145
  fs.rmSync(sourceToBeImported);
145
146
  const reportFileName = "config_import_report_" + (0, uuid_1.v4)() + ".json";
146
- file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(postPackageImportData), reportFileName);
147
- logger_1.logger.info("Config import report file: " + reportFileName);
147
+ const writtenFilename = yield this.cuiFileService.writeToFileWithGivenName(JSON.stringify(postPackageImportData), reportFileName);
148
+ logger_1.logger.info("Config import report file: " + writtenFilename);
148
149
  });
149
150
  }
150
151
  findAndExportListOfActivePackagesByVariableValue(flavors, variableValue, variableType, includeBranches) {
151
152
  return __awaiter(this, void 0, void 0, function* () {
152
153
  let packagesToExport = yield this.t2tcPackageApi.findActivePackagesByVariableValue(flavors, variableValue, variableType, includeBranches);
153
154
  packagesToExport = yield this.studioService.getExportPackagesWithStudioData(packagesToExport, false);
154
- this.exportListOfPackages(packagesToExport);
155
+ yield this.exportListOfPackages(packagesToExport);
155
156
  });
156
157
  }
157
158
  listActivePackagesByVariableValue(flavors, variableValue, variableType, includeBranches) {
@@ -163,9 +164,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
163
164
  });
164
165
  }
165
166
  exportListOfPackages(packages) {
166
- const filename = (0, uuid_1.v4)() + ".json";
167
- file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(packages), filename);
168
- logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + filename);
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ const filename = (0, uuid_1.v4)() + ".json";
169
+ const writtenFilename = yield this.cuiFileService.writeToFileWithGivenName(JSON.stringify(packages), filename);
170
+ logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + writtenFilename);
171
+ });
169
172
  }
170
173
  getVersionsByPackageKey(manifests) {
171
174
  const versionsByPackageKey = new Map();
@@ -221,19 +224,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
221
224
  return null;
222
225
  }
223
226
  downloadZip(exportedZip, unzip) {
224
- if (unzip) {
225
- const fileDownloadedMessage = "Successful download. Downloaded directory: ";
226
- const targetDirectoryName = `export_${(0, uuid_1.v4)()}`;
227
- file_service_1.fileService.extractExportedZipWithNestedZipsToDir(exportedZip, targetDirectoryName);
228
- logger_1.logger.info(fileDownloadedMessage + targetDirectoryName);
229
- }
230
- else {
231
- const fileDownloadedMessage = "File downloaded successfully. New filename: ";
232
- const filename = `export_${(0, uuid_1.v4)()}.zip`;
233
- const fullFilePath = (0, node_path_1.resolve)(process.cwd(), filename);
234
- exportedZip.writeZip(fullFilePath, () => fs.chmodSync(fullFilePath, file_constants_1.FileConstants.DEFAULT_FILE_PERMISSIONS));
235
- logger_1.logger.info(fileDownloadedMessage + filename);
236
- }
227
+ return __awaiter(this, void 0, void 0, function* () {
228
+ if (unzip) {
229
+ const fileDownloadedMessage = "Successful download. Downloaded directory: ";
230
+ const directoryName = yield this.cuiFileService.writeDirectoryWithGivenName(targetDir => file_service_1.fileService.extractExportedZipWithNestedZipsToDir(exportedZip, targetDir), `export_${(0, uuid_1.v4)()}`);
231
+ logger_1.logger.info(fileDownloadedMessage + directoryName);
232
+ }
233
+ else {
234
+ const fileDownloadedMessage = "File downloaded successfully. New filename: ";
235
+ const filename = yield this.cuiFileService.writeZipToFileWithGivenName(exportedZip.toBuffer(), `export_${(0, uuid_1.v4)()}.zip`);
236
+ logger_1.logger.info(fileDownloadedMessage + filename);
237
+ }
238
+ });
237
239
  }
238
240
  }
239
241
  exports.T2tcPackageService = T2tcPackageService;
package/content-cli.js CHANGED
@@ -75,6 +75,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
75
75
  */
76
76
  function configureRootCommands(configurator) {
77
77
  configurator.command("list").description("Commands to list content.").alias("ls");
78
+ configurator.command("export").description("Export resource: action flow or data pool");
79
+ configurator.command("import").description("Import resource: action flow or data pool");
80
+ configurator.command("pull").description("Pull resource: skill, bookmark, view bookmark, data pool or asset");
81
+ configurator.command("push").description("Push resource: asset, skill, bookmark, view bookmark, CTP or data pool");
78
82
  }
79
83
  function run() {
80
84
  return __awaiter(this, void 0, void 0, function* () {
@@ -13,7 +13,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  if (v !== undefined) module.exports = v;
14
14
  }
15
15
  else if (typeof define === "function" && define.amd) {
16
- define(["require", "exports", "path", "fs", "commander", "../utils/logger", "chalk"], factory);
16
+ define(["require", "exports", "path", "fs", "commander", "../utils/logger", "../feature-flag/feature-disabled-error", "chalk"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
@@ -23,6 +23,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
23
  const fs = require("fs");
24
24
  const commander_1 = require("commander");
25
25
  const logger_1 = require("../utils/logger");
26
+ const feature_disabled_error_1 = require("../feature-flag/feature-disabled-error");
26
27
  const chalk = require("chalk");
27
28
  class IModule {
28
29
  }
@@ -204,6 +205,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
204
205
  logger_1.logger.error(error.message);
205
206
  return;
206
207
  }
208
+ // Backend gates early-access features; translate its "feature disabled"
209
+ // rejection into a clear message instead of a raw error.
210
+ if ((0, feature_disabled_error_1.isFeatureDisabledError)(error)) {
211
+ logger_1.logger.error(`'${this.cmd.name()}' is not enabled for your team. Contact support to request access.`);
212
+ return;
213
+ }
207
214
  logger_1.logger.error(`An unexpected error occured executing a command: ${error}`);
208
215
  process.exitCode = 1;
209
216
  }
@@ -0,0 +1,52 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isFeatureDisabledError = exports.FEATURE_DISABLED_CODE = void 0;
13
+ /**
14
+ * Recognizes the backend's "feature not enabled" response so the CLI can surface a
15
+ * clear message instead of a raw error. Enforcement stays entirely in the backend
16
+ * (pacman); the CLI only translates the response — it never decides entitlement.
17
+ *
18
+ * The backend rejects a flag-gated request with 403 and a machine-readable body:
19
+ * {"errorCode":"feature-disabled", ...} (pacman's standard ErrorTransport). Keying
20
+ * off the stable code (rather than a free-text message) keeps this robust.
21
+ */
22
+ exports.FEATURE_DISABLED_CODE = "feature-disabled";
23
+ /**
24
+ * True when the given error represents a backend "feature disabled" rejection.
25
+ * HttpClient rejects with the stringified response body (often wrapped as
26
+ * "FatalError: {json}"), so we extract and parse the embedded JSON payload.
27
+ */
28
+ function isFeatureDisabledError(error) {
29
+ return extractErrorCode(error) === exports.FEATURE_DISABLED_CODE;
30
+ }
31
+ exports.isFeatureDisabledError = isFeatureDisabledError;
32
+ function extractErrorCode(error) {
33
+ let text = "";
34
+ if (error instanceof Error) {
35
+ text = error.message;
36
+ }
37
+ else if (typeof error === "string") {
38
+ text = error;
39
+ }
40
+ const jsonStart = text.indexOf("{");
41
+ if (jsonStart === -1) {
42
+ return undefined;
43
+ }
44
+ try {
45
+ const payload = JSON.parse(text.slice(jsonStart));
46
+ return typeof payload.errorCode === "string" ? payload.errorCode : undefined;
47
+ }
48
+ catch (_a) {
49
+ return undefined;
50
+ }
51
+ }
52
+ });
@@ -53,6 +53,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
53
53
  });
54
54
  });
55
55
  }
56
+ getStatusAndData(url) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const fullUrl = this.resolveUrl(url);
59
+ logger_1.logger.debug(`HttpClient - GET ${fullUrl}`);
60
+ return this.axios.get(fullUrl, {
61
+ headers: this.buildHeaders(),
62
+ validateStatus: () => true,
63
+ }).then(response => {
64
+ logger_1.logger.debug(`Response ${response.status}`);
65
+ return { status: response.status, data: response.data };
66
+ }).catch(err => {
67
+ if (err.response) {
68
+ return { status: err.response.status, data: err.response.data };
69
+ }
70
+ throw new logger_1.FatalError(err);
71
+ });
72
+ });
73
+ }
56
74
  getFile(url) {
57
75
  return __awaiter(this, void 0, void 0, function* () {
58
76
  return new Promise((resolve, reject) => {
@@ -13,59 +13,44 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  if (v !== undefined) module.exports = v;
14
14
  }
15
15
  else if (typeof define === "function" && define.amd) {
16
- define(["require", "exports", "fs", "path", "../../utils/logger", "../../utils/file.constants"], factory);
16
+ define(["require", "exports", "../../utils/logger", "../../utils/cui-file-service"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.BaseManager = void 0;
22
- const fs = require("fs");
23
- const path = require("path");
24
22
  const logger_1 = require("../../utils/logger");
25
- const file_constants_1 = require("../../utils/file.constants");
23
+ const cui_file_service_1 = require("../../utils/cui-file-service");
26
24
  class BaseManager {
27
25
  constructor(context) {
28
26
  this.fileDownloadedMessage = "File downloaded successfully. New filename: ";
29
27
  this.httpClient = () => context.httpClient;
28
+ this.cuiFileService = new cui_file_service_1.CuiFileService(context);
30
29
  }
31
30
  pull() {
32
31
  return __awaiter(this, void 0, void 0, function* () {
33
- return new Promise((resolve, reject) => {
34
- this.httpClient()
35
- .get(this.getConfig().pullUrl)
36
- .then(data => {
37
- try {
38
- const filename = this.writeToFile(data);
39
- logger_1.logger.info(this.fileDownloadedMessage + filename);
40
- resolve();
41
- }
42
- catch (e) {
43
- logger_1.logger.error(new logger_1.FatalError(e));
44
- reject();
45
- }
46
- })
47
- .catch(err => {
48
- logger_1.logger.error(new logger_1.FatalError(err));
49
- reject();
50
- });
51
- });
32
+ try {
33
+ const data = yield this.httpClient().get(this.getConfig().pullUrl);
34
+ const filename = yield this.writeToFile(data);
35
+ logger_1.logger.info(this.fileDownloadedMessage + filename);
36
+ }
37
+ catch (err) {
38
+ logger_1.logger.error(new logger_1.FatalError(err));
39
+ throw err;
40
+ }
52
41
  });
53
42
  }
54
43
  pullFile() {
55
44
  return __awaiter(this, void 0, void 0, function* () {
56
- return new Promise((resolve, reject) => {
57
- this.httpClient()
58
- .downloadFile(this.getConfig().pullUrl)
59
- .then(data => {
60
- const filename = this.writeStreamToFile(data);
61
- logger_1.logger.info(this.fileDownloadedMessage + filename);
62
- resolve();
63
- })
64
- .catch(err => {
65
- logger_1.logger.error(new logger_1.FatalError(err));
66
- reject();
67
- });
68
- });
45
+ try {
46
+ const data = yield this.httpClient().downloadFile(this.getConfig().pullUrl);
47
+ const filename = yield this.writeStreamToFile(data);
48
+ logger_1.logger.info(this.fileDownloadedMessage + filename);
49
+ }
50
+ catch (err) {
51
+ logger_1.logger.error(new logger_1.FatalError(err));
52
+ throw err;
53
+ }
69
54
  });
70
55
  }
71
56
  push() {
@@ -102,34 +87,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
102
87
  }
103
88
  findAll() {
104
89
  return __awaiter(this, void 0, void 0, function* () {
105
- return new Promise((resolve, reject) => {
106
- this.httpClient()
107
- .get(this.getConfig().findAllUrl)
108
- .then(data => {
109
- this.getConfig().onFindAll(data);
110
- resolve(data);
111
- })
112
- .catch(err => {
113
- logger_1.logger.error(new logger_1.FatalError(err));
114
- reject();
115
- });
116
- });
90
+ try {
91
+ const data = yield this.httpClient().get(this.getConfig().findAllUrl);
92
+ yield this.getConfig().onFindAll(data);
93
+ return data;
94
+ }
95
+ catch (err) {
96
+ logger_1.logger.error(new logger_1.FatalError(err));
97
+ throw err;
98
+ }
117
99
  });
118
100
  }
119
101
  writeToFile(data) {
120
- const filename = this.getConfig().exportFileName;
121
- this.writeToFileWithGivenName(data, filename);
122
- return filename;
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ return this.cuiFileService.writeToFileWithGivenName(this.getSerializedFileContent(data), this.getConfig().exportFileName);
104
+ });
123
105
  }
124
106
  writeStreamToFile(data) {
125
- const filename = this.getConfig().exportFileName;
126
- fs.writeFileSync(filename, data, { mode: file_constants_1.FileConstants.DEFAULT_FILE_PERMISSIONS });
127
- return filename;
128
- }
129
- writeToFileWithGivenName(data, filename) {
130
- fs.writeFileSync(path.resolve(process.cwd(), filename), this.getSerializedFileContent(data), {
131
- encoding: "utf-8",
132
- mode: file_constants_1.FileConstants.DEFAULT_FILE_PERMISSIONS,
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ return this.cuiFileService.writeZipToFileWithGivenName(data, this.getConfig().exportFileName);
133
109
  });
134
110
  }
135
111
  }
@@ -17,7 +17,17 @@
17
17
  }
18
18
  return packageKey.includes(BranchUtils.BRANCH_SEPARATOR);
19
19
  }
20
+ static constructBranchKey(projectKey, branchKey) {
21
+ return `${projectKey}${BranchUtils.BRANCH_SEPARATOR}${branchKey}`;
22
+ }
23
+ static extractProjectKey(packageKey) {
24
+ if (!BranchUtils.isBranchPackageKey(packageKey)) {
25
+ return packageKey;
26
+ }
27
+ return packageKey.substring(0, packageKey.indexOf(BranchUtils.BRANCH_SEPARATOR));
28
+ }
20
29
  }
21
30
  exports.BranchUtils = BranchUtils;
31
+ BranchUtils.MAIN_BRANCH_KEY = "main";
22
32
  BranchUtils.BRANCH_SEPARATOR = "@";
23
33
  });
@@ -0,0 +1,52 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ (function (factory) {
11
+ if (typeof module === "object" && typeof module.exports === "object") {
12
+ var v = factory(require, exports);
13
+ if (v !== undefined) module.exports = v;
14
+ }
15
+ else if (typeof define === "function" && define.amd) {
16
+ define(["require", "exports", "./logger"], factory);
17
+ }
18
+ })(function (require, exports) {
19
+ "use strict";
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.CuiApi = exports.CuiMarking = exports.CUI_MARKING_FAILED_MESSAGE = void 0;
22
+ const logger_1 = require("./logger");
23
+ exports.CUI_MARKING_FAILED_MESSAGE = "Could not resolve CUI marking. No file was written";
24
+ var CuiMarking;
25
+ (function (CuiMarking) {
26
+ CuiMarking["DISABLED"] = "DISABLED";
27
+ CuiMarking["CLASSIFIED"] = "CLASSIFIED";
28
+ })(CuiMarking || (exports.CuiMarking = CuiMarking = {}));
29
+ class CuiApi {
30
+ constructor(context) {
31
+ this.httpClient = () => context.httpClient;
32
+ }
33
+ getCuiMarking() {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const { status, data } = yield this.httpClient().getStatusAndData(CuiApi.CUI_PDF_COVER_SHEET_URL);
36
+ if (status === CuiApi.STATUS_FORBIDDEN) {
37
+ logger_1.logger.debug("CUI marking does not apply, the feature flag is disabled");
38
+ return { marking: CuiMarking.DISABLED };
39
+ }
40
+ if (status === CuiApi.STATUS_OK && data) {
41
+ return { marking: CuiMarking.CLASSIFIED, cover: data };
42
+ }
43
+ logger_1.logger.debug(`The CUI cover call answered with status ${status}`);
44
+ throw new logger_1.FatalError(exports.CUI_MARKING_FAILED_MESSAGE);
45
+ });
46
+ }
47
+ }
48
+ exports.CuiApi = CuiApi;
49
+ CuiApi.CUI_PDF_COVER_SHEET_URL = "/api/team/cui-settings/cui-pdf-cover";
50
+ CuiApi.STATUS_OK = 200;
51
+ CuiApi.STATUS_FORBIDDEN = 403;
52
+ });
@@ -0,0 +1,106 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ (function (factory) {
11
+ if (typeof module === "object" && typeof module.exports === "object") {
12
+ var v = factory(require, exports);
13
+ if (v !== undefined) module.exports = v;
14
+ }
15
+ else if (typeof define === "function" && define.amd) {
16
+ define(["require", "exports", "node:path", "adm-zip", "./cui-api", "./file-service", "./file.constants", "./logger"], factory);
17
+ }
18
+ })(function (require, exports) {
19
+ "use strict";
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.CuiFileService = void 0;
22
+ const path = require("node:path");
23
+ const AdmZip = require("adm-zip");
24
+ const cui_api_1 = require("./cui-api");
25
+ const file_service_1 = require("./file-service");
26
+ const file_constants_1 = require("./file.constants");
27
+ const logger_1 = require("./logger");
28
+ class CuiFileService {
29
+ constructor(context) {
30
+ this.cuiApi = new cui_api_1.CuiApi(context);
31
+ }
32
+ writeToFileWithGivenName(data, filename) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return this.writeWithCoverHandling(name => file_service_1.fileService.writeToFileWithGivenName(data, name), filename, cover => this.writeClassifiedArchive(filename, data, cover));
35
+ });
36
+ }
37
+ writeZipToFileWithGivenName(zipData, filename) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ return this.writeWithCoverHandling(name => file_service_1.fileService.writeBufferToFileWithGivenName(zipData, name), filename, cover => {
40
+ const zip = new AdmZip(zipData);
41
+ this.addCoverPage(zip, cover);
42
+ return this.writeArchive(zip, filename);
43
+ });
44
+ });
45
+ }
46
+ writeDirectoryWithGivenName(write, directoryName) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return this.writeWithCoverHandling(write, directoryName, cover => {
49
+ const coverSheet = this.decodeCoverPage(cover);
50
+ const classifiedName = this.prefixFileName(directoryName, CuiFileService.CLASSIFIED_PREFIX);
51
+ write(classifiedName);
52
+ file_service_1.fileService.writeBufferToFileWithGivenName(coverSheet, path.join(classifiedName, CuiFileService.COVER_SHEET_FILE_NAME));
53
+ return classifiedName;
54
+ });
55
+ });
56
+ }
57
+ writeWithCoverHandling(write, filename, onClassified) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const decision = yield this.cuiApi.getCuiMarking();
60
+ if (decision.marking === cui_api_1.CuiMarking.DISABLED) {
61
+ write(filename);
62
+ return filename;
63
+ }
64
+ return onClassified(decision.cover);
65
+ });
66
+ }
67
+ writeClassifiedArchive(filename, data, cover) {
68
+ const zip = new AdmZip();
69
+ zip.addFile(path.basename(filename), Buffer.from(data, "utf-8"), "", file_constants_1.FileConstants.DEFAULT_FILE_PERMISSIONS);
70
+ this.addCoverPage(zip, cover);
71
+ return this.writeArchive(zip, filename);
72
+ }
73
+ addCoverPage(zip, cover) {
74
+ zip.addFile(CuiFileService.COVER_SHEET_FILE_NAME, this.decodeCoverPage(cover), "", file_constants_1.FileConstants.DEFAULT_FILE_PERMISSIONS);
75
+ }
76
+ writeArchive(zip, filename) {
77
+ const archiveName = this.buildClassifiedArchiveName(filename);
78
+ file_service_1.fileService.writeBufferToFileWithGivenName(zip.toBuffer(), archiveName);
79
+ return archiveName;
80
+ }
81
+ decodeCoverPage(cover) {
82
+ const coverPage = cover.coverPage;
83
+ if (!(coverPage === null || coverPage === void 0 ? void 0 : coverPage.pdfContent)) {
84
+ logger_1.logger.debug("CUI marking applies but the response contained no cover page");
85
+ throw new logger_1.FatalError(cui_api_1.CUI_MARKING_FAILED_MESSAGE);
86
+ }
87
+ if (coverPage.encoding !== CuiFileService.BASE64_ENCODING) {
88
+ logger_1.logger.debug(`Unsupported CUI cover page encoding: ${coverPage.encoding}`);
89
+ throw new logger_1.FatalError(cui_api_1.CUI_MARKING_FAILED_MESSAGE);
90
+ }
91
+ return Buffer.from(coverPage.pdfContent, CuiFileService.BASE64_ENCODING);
92
+ }
93
+ buildClassifiedArchiveName(filename) {
94
+ const baseName = path.basename(filename);
95
+ const nameWithoutExtension = baseName.slice(0, baseName.length - path.extname(baseName).length);
96
+ return path.join(path.dirname(filename), `${CuiFileService.CLASSIFIED_PREFIX}${nameWithoutExtension}.zip`);
97
+ }
98
+ prefixFileName(filename, prefix) {
99
+ return path.join(path.dirname(filename), `${prefix}${path.basename(filename)}`);
100
+ }
101
+ }
102
+ exports.CuiFileService = CuiFileService;
103
+ CuiFileService.COVER_SHEET_FILE_NAME = "CUI_Cover_Sheet.pdf";
104
+ CuiFileService.CLASSIFIED_PREFIX = "CUI - ";
105
+ CuiFileService.BASE64_ENCODING = "base64";
106
+ });