@celonis/content-cli 1.14.0 → 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 (58) hide show
  1. package/commands/action-flows/action-flow/action-flow.service.js +9 -9
  2. package/commands/asset-registry/asset-registry.service.js +20 -16
  3. package/commands/bookmarks/bookmarks-command.service.js +5 -3
  4. package/commands/configuration-management/api/node-api.js +17 -0
  5. package/commands/configuration-management/branch/branch-export-import.command.service.js +31 -24
  6. package/commands/configuration-management/branch/branch.command.service.js +14 -10
  7. package/commands/configuration-management/metadata.service.js +9 -5
  8. package/commands/configuration-management/module.js +6 -5
  9. package/commands/configuration-management/node-dependency.service.js +5 -3
  10. package/commands/configuration-management/node-diff.service.js +10 -6
  11. package/commands/configuration-management/node.service.js +14 -10
  12. package/commands/configuration-management/package-validation.service.js +11 -5
  13. package/commands/configuration-management/package-version.service.js +7 -5
  14. package/commands/configuration-management/single-package-export.service.js +6 -6
  15. package/commands/configuration-management/single-package-import.service.js +22 -18
  16. package/commands/configuration-management/staging-package.service.js +9 -5
  17. package/commands/configuration-management/variable.service.js +11 -7
  18. package/commands/data-pipeline/data-pool/data-pool-service.js +13 -9
  19. package/commands/deployment/deployment.service.js +15 -13
  20. package/commands/studio/manager/space.manager.js +21 -10
  21. package/commands/studio/service/asset-service.js +5 -4
  22. package/commands/studio/service/package.service.js +9 -5
  23. package/commands/t2tc/diff.service.js +15 -9
  24. package/commands/t2tc/t2tc-package.service.js +25 -23
  25. package/core/http/http-client.js +18 -0
  26. package/core/http/http-shared/base.manager.js +35 -59
  27. package/core/utils/cui-api.js +52 -0
  28. package/core/utils/cui-file-service.js +106 -0
  29. package/core/utils/file-service.js +7 -6
  30. package/lib/commands/action-flows/action-flow/action-flow.service.d.ts +1 -0
  31. package/lib/commands/asset-registry/asset-registry.service.d.ts +1 -0
  32. package/lib/commands/bookmarks/bookmarks-command.service.d.ts +1 -0
  33. package/lib/commands/configuration-management/api/node-api.d.ts +1 -0
  34. package/lib/commands/configuration-management/branch/branch-export-import.command.service.d.ts +2 -1
  35. package/lib/commands/configuration-management/branch/branch.command.service.d.ts +2 -1
  36. package/lib/commands/configuration-management/interfaces/package-validation.interfaces.d.ts +1 -1
  37. package/lib/commands/configuration-management/metadata.service.d.ts +1 -0
  38. package/lib/commands/configuration-management/node-dependency.service.d.ts +1 -0
  39. package/lib/commands/configuration-management/node-diff.service.d.ts +1 -0
  40. package/lib/commands/configuration-management/node.service.d.ts +2 -1
  41. package/lib/commands/configuration-management/package-validation.service.d.ts +1 -0
  42. package/lib/commands/configuration-management/package-version.service.d.ts +1 -0
  43. package/lib/commands/configuration-management/single-package-export.service.d.ts +1 -0
  44. package/lib/commands/configuration-management/single-package-import.service.d.ts +1 -0
  45. package/lib/commands/configuration-management/staging-package.service.d.ts +1 -0
  46. package/lib/commands/configuration-management/variable.service.d.ts +1 -0
  47. package/lib/commands/data-pipeline/data-pool/data-pool-service.d.ts +1 -0
  48. package/lib/commands/deployment/deployment.service.d.ts +1 -0
  49. package/lib/commands/studio/service/asset-service.d.ts +1 -0
  50. package/lib/commands/studio/service/package.service.d.ts +1 -0
  51. package/lib/commands/t2tc/diff.service.d.ts +1 -0
  52. package/lib/commands/t2tc/t2tc-package.service.d.ts +1 -0
  53. package/lib/core/http/http-client.d.ts +4 -0
  54. package/lib/core/http/http-shared/base.manager.d.ts +7 -5
  55. package/lib/core/http/http-shared/manager-config.interface.d.ts +1 -1
  56. package/lib/core/utils/cui-api.d.ts +26 -0
  57. package/lib/core/utils/cui-file-service.d.ts +19 -0
  58. package/package.json +1 -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", "uuid", "../api/asset-api", "../../../core/utils/logger", "../../../core/utils/file-service"], factory);
16
+ define(["require", "exports", "uuid", "../api/asset-api", "../../../core/utils/logger", "../../../core/utils/cui-file-service"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
@@ -22,11 +22,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  const uuid_1 = require("uuid");
23
23
  const asset_api_1 = require("../api/asset-api");
24
24
  const logger_1 = require("../../../core/utils/logger");
25
- const file_service_1 = require("../../../core/utils/file-service");
25
+ const cui_file_service_1 = require("../../../core/utils/cui-file-service");
26
26
  class AssetService {
27
27
  constructor(context) {
28
28
  this.fileDownloadedMessage = "File downloaded successfully. New filename: ";
29
29
  this.assetApi = new asset_api_1.AssetApi(context);
30
+ this.cuiFileService = new cui_file_service_1.CuiFileService(context);
30
31
  }
31
32
  listAssets(assetType) {
32
33
  return __awaiter(this, void 0, void 0, function* () {
@@ -41,8 +42,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
41
42
  const fieldsToInclude = ["key", "name", "assetType", "rootNodeKey", "activatedDraftId"];
42
43
  const nodes = yield this.assetApi.findAllAssets(assetType);
43
44
  const filename = (0, uuid_1.v4)() + ".json";
44
- file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(nodes, fieldsToInclude), filename);
45
- logger_1.logger.info(this.fileDownloadedMessage + filename);
45
+ const writtenFilename = yield this.cuiFileService.writeToFileWithGivenName(JSON.stringify(nodes, fieldsToInclude), filename);
46
+ logger_1.logger.info(this.fileDownloadedMessage + writtenFilename);
46
47
  });
47
48
  }
48
49
  }
@@ -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", "../api/package-api", "../../../core/utils/logger", "../interfaces/package-manager.interfaces", "../../../core/utils/file-service", "../api/package-dependencies-api", "./data-model.service", "./studio-variable.service"], factory);
16
+ define(["require", "exports", "uuid", "../api/package-api", "../../../core/utils/logger", "../interfaces/package-manager.interfaces", "../../../core/utils/file-service", "../../../core/utils/cui-file-service", "../api/package-dependencies-api", "./data-model.service", "./studio-variable.service"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
@@ -24,6 +24,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
24
24
  const logger_1 = require("../../../core/utils/logger");
25
25
  const package_manager_interfaces_1 = require("../interfaces/package-manager.interfaces");
26
26
  const file_service_1 = require("../../../core/utils/file-service");
27
+ const cui_file_service_1 = require("../../../core/utils/cui-file-service");
27
28
  const package_dependencies_api_1 = require("../api/package-dependencies-api");
28
29
  const data_model_service_1 = require("./data-model.service");
29
30
  const studio_variable_service_1 = require("./studio-variable.service");
@@ -34,6 +35,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
34
35
  this.packageDependenciesApi = new package_dependencies_api_1.PackageDependenciesApi(context);
35
36
  this.dataModelService = new data_model_service_1.DataModelService(context);
36
37
  this.variableService = new studio_variable_service_1.StudioVariableService(context);
38
+ this.cuiFileService = new cui_file_service_1.CuiFileService(context);
37
39
  }
38
40
  listPackages() {
39
41
  return __awaiter(this, void 0, void 0, function* () {
@@ -70,7 +72,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
70
72
  return nodeToExport;
71
73
  });
72
74
  }
73
- this.exportListOfPackages(nodesListToExport, fieldsToInclude);
75
+ yield this.exportListOfPackages(nodesListToExport, fieldsToInclude);
74
76
  });
75
77
  }
76
78
  getNodesWithActiveVersion(nodes) {
@@ -88,9 +90,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
88
90
  });
89
91
  }
90
92
  exportListOfPackages(nodes, fieldsToInclude) {
91
- const filename = (0, uuid_1.v4)() + ".json";
92
- file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(nodes, fieldsToInclude), filename);
93
- 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(nodes, fieldsToInclude), filename);
96
+ logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + writtenFilename);
97
+ });
94
98
  }
95
99
  }
96
100
  exports.PackageService = PackageService;
@@ -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;
@@ -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
  }
@@ -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
+ });
@@ -57,11 +57,12 @@
57
57
  return this.extractExportedZipWithNestedZipsToDir(zipFile, tempDir);
58
58
  }
59
59
  extractExportedZipWithNestedZipsToDir(zipFile, targetDir) {
60
- this.mkdirRecursive(targetDir);
61
- zipFile.extractAllTo(targetDir, true, true);
62
- const files = fs.readdirSync(targetDir);
60
+ const targetPath = path.resolve(process.cwd(), targetDir);
61
+ this.mkdirRecursive(targetPath);
62
+ zipFile.extractAllTo(targetPath, true, true);
63
+ const files = fs.readdirSync(targetPath);
63
64
  for (const file of files) {
64
- const innerZipPath = path.join(targetDir, file);
65
+ const innerZipPath = path.join(targetPath, file);
65
66
  if (file.endsWith(".zip")) {
66
67
  const nestedZip = new AdmZip(innerZipPath);
67
68
  const nestedDir = innerZipPath.replace(/\.zip$/, "");
@@ -70,8 +71,8 @@
70
71
  fs.rmSync(innerZipPath); // Optionally remove the inner zip
71
72
  }
72
73
  }
73
- this.restrictFilePermissions(targetDir);
74
- return targetDir;
74
+ this.restrictFilePermissions(targetPath);
75
+ return targetPath;
75
76
  }
76
77
  isDirectory(sourcePath) {
77
78
  var _a;
@@ -2,6 +2,7 @@ import { Context } from "../../../core/command/cli-context";
2
2
  export declare class ActionFlowService {
3
3
  static readonly METADATA_FILE_NAME = "metadata.json";
4
4
  private actionFlowApi;
5
+ private readonly cuiFileService;
5
6
  constructor(context: Context);
6
7
  exportActionFlows(packageId: string, metadataFilePath: string): Promise<void>;
7
8
  analyzeActionFlows(packageId: string, outputToJsonFile: boolean): Promise<void>;
@@ -2,6 +2,7 @@ import { ValidateOptions } from "./asset-registry.interfaces";
2
2
  import { Context } from "../../core/command/cli-context";
3
3
  export declare class AssetRegistryService {
4
4
  private readonly api;
5
+ private readonly cuiFileService;
5
6
  constructor(context: Context);
6
7
  listTypes(jsonResponse: boolean): Promise<void>;
7
8
  getType(assetType: string, jsonResponse: boolean): Promise<void>;