@celonis/content-cli 0.11.0 → 0.11.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.
@@ -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", "../services/http-client-service.v2", "../util/logger"], factory);
17
+ }
18
+ })(function (require, exports) {
19
+ "use strict";
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.actionFlowApi = void 0;
22
+ const http_client_service_v2_1 = require("../services/http-client-service.v2");
23
+ const logger_1 = require("../util/logger");
24
+ class ActionFlowApi {
25
+ exportRawAssets(packageId) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return http_client_service_v2_1.httpClientV2.getFile(`/ems-automation/api/root/${packageId}/export/assets`).catch(e => {
28
+ throw new logger_1.FatalError(`Problem getting Action Flow assets: ${e}`);
29
+ });
30
+ });
31
+ }
32
+ analyzeAssets(packageId) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return http_client_service_v2_1.httpClientV2.get(`/ems-automation/api/root/${packageId}/export/assets/analyze`).catch(e => {
35
+ throw new logger_1.FatalError(`Problem analyzing Action Flow assets: ${e}`);
36
+ });
37
+ });
38
+ }
39
+ importAssets(packageId, data, dryRun) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const params = {
42
+ dryRun: dryRun,
43
+ };
44
+ return http_client_service_v2_1.httpClientV2.postFile(`/ems-automation/api/root/${packageId}/import/assets`, data, params).catch(e => {
45
+ throw new logger_1.FatalError(`Problem importing Action Flow assets: ${e}`);
46
+ });
47
+ });
48
+ }
49
+ }
50
+ ActionFlowApi.INSTANCE = new ActionFlowApi();
51
+ exports.actionFlowApi = ActionFlowApi.INSTANCE;
52
+ });
@@ -0,0 +1,41 @@
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", "../services/action-flow/action-flow-service"], factory);
17
+ }
18
+ })(function (require, exports) {
19
+ "use strict";
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.ActionFlowCommand = void 0;
22
+ const action_flow_service_1 = require("../services/action-flow/action-flow-service");
23
+ class ActionFlowCommand {
24
+ exportActionFlows(packageId, metadataFile) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ yield action_flow_service_1.actionFlowService.exportActionFlows(packageId, metadataFile);
27
+ });
28
+ }
29
+ analyzeActionFlows(packageId, outputToJsonFile) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ yield action_flow_service_1.actionFlowService.analyzeActionFlows(packageId, outputToJsonFile);
32
+ });
33
+ }
34
+ importActionFlows(packageId, filePath, dryRun, outputToJsonFile) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ yield action_flow_service_1.actionFlowService.importActionFlows(packageId, filePath, dryRun, outputToJsonFile);
37
+ });
38
+ }
39
+ }
40
+ exports.ActionFlowCommand = ActionFlowCommand;
41
+ });
@@ -0,0 +1,56 @@
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", "./util/context-initializer", "./util/logger", "./commands/action-flow.command", "commander"], factory);
17
+ }
18
+ })(function (require, exports) {
19
+ "use strict";
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ const context_initializer_1 = require("./util/context-initializer");
22
+ const logger_1 = require("./util/logger");
23
+ const action_flow_command_1 = require("./commands/action-flow.command");
24
+ const commander = require("commander");
25
+ class Analyze {
26
+ static actionFlows(program) {
27
+ program
28
+ .command("action-flows")
29
+ .description("Analyze Action Flows dependencies for a certain package")
30
+ .option("-p, --profile <profile>", "Profile which you want to use to analyze Action Flows")
31
+ .requiredOption("--packageId <packageId>", "ID of the package from which you want to export Action Flows")
32
+ .option("-o, --outputToJsonFile", "Output the analyze result in a JSON file")
33
+ .action((cmd) => __awaiter(this, void 0, void 0, function* () {
34
+ yield new action_flow_command_1.ActionFlowCommand().analyzeActionFlows(cmd.packageId, cmd.outputToJsonFile);
35
+ process.exit();
36
+ }));
37
+ return program;
38
+ }
39
+ }
40
+ const loadCommands = () => {
41
+ getAllCommands();
42
+ };
43
+ context_initializer_1.ContextInitializer.initContext()
44
+ .then(loadCommands, loadCommands)
45
+ .catch(e => {
46
+ logger_1.logger.error(e);
47
+ });
48
+ if (!process.argv.slice(2).length) {
49
+ commander.outputHelp();
50
+ process.exit(1);
51
+ }
52
+ function getAllCommands() {
53
+ Analyze.actionFlows(commander);
54
+ commander.parse(process.argv);
55
+ }
56
+ });
@@ -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", "commander", "./commands/package.command", "./util/logger", "./commands/data-pool.command", "./util/context-initializer"], factory);
16
+ define(["require", "exports", "commander", "./commands/package.command", "./util/logger", "./commands/data-pool.command", "./util/context-initializer", "./commands/action-flow.command"], 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("./util/logger");
25
25
  const data_pool_command_1 = require("./commands/data-pool.command");
26
26
  const context_initializer_1 = require("./util/context-initializer");
27
+ const action_flow_command_1 = require("./commands/action-flow.command");
27
28
  class Export {
28
29
  static packages(program) {
29
30
  program
@@ -53,6 +54,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
53
54
  }));
54
55
  return program;
55
56
  }
57
+ static actionFlows(program) {
58
+ program
59
+ .command("action-flows")
60
+ .description("Command to export all Action Flows in a package with their objects and dependencies")
61
+ .option("-p, --profile <profile>", "Profile which you want to use to export Action Flows")
62
+ .requiredOption("--packageId <packageId>", "ID of the package from which you want to export Action Flows")
63
+ .option("-f, --file <file>", "Action flows metadata file (relative path)")
64
+ .action((cmd) => __awaiter(this, void 0, void 0, function* () {
65
+ yield new action_flow_command_1.ActionFlowCommand().exportActionFlows(cmd.packageId, cmd.file);
66
+ process.exit();
67
+ }));
68
+ return program;
69
+ }
56
70
  }
57
71
  exports.Export = Export;
58
72
  const loadCommands = () => {
@@ -70,6 +84,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
70
84
  function getAllCommands() {
71
85
  Export.packages(commander);
72
86
  Export.dataPool(commander);
87
+ Export.actionFlows(commander);
73
88
  commander.parse(process.argv);
74
89
  }
75
90
  });
@@ -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", "commander", "./commands/package.command", "./commands/data-pool.command", "./util/context-initializer", "./util/logger"], factory);
16
+ define(["require", "exports", "commander", "./commands/package.command", "./commands/data-pool.command", "./util/context-initializer", "./util/logger", "./commands/action-flow.command"], 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 data_pool_command_1 = require("./commands/data-pool.command");
25
25
  const context_initializer_1 = require("./util/context-initializer");
26
26
  const logger_1 = require("./util/logger");
27
+ const action_flow_command_1 = require("./commands/action-flow.command");
27
28
  class Import {
28
29
  static packages(program) {
29
30
  program
@@ -54,6 +55,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
54
55
  }));
55
56
  return program;
56
57
  }
58
+ static actionFlows(program) {
59
+ program
60
+ .command("action-flows")
61
+ .description("Command to import all Action Flows in a package with their objects and dependencies")
62
+ .option("-p, --profile <profile>", "Profile which you want to use to import Action Flows")
63
+ .requiredOption("--packageId <packageId>", "ID of the package to which you want to export Action Flows")
64
+ .requiredOption("-f, --file <file>", "Exported Action Flows file (relative path)")
65
+ .requiredOption("-d, --dryRun <dryRun>", "Execute the import on dry run mode")
66
+ .option("-o, --outputToJsonFile", "Output the import result in a JSON file")
67
+ .action((cmd) => __awaiter(this, void 0, void 0, function* () {
68
+ yield new action_flow_command_1.ActionFlowCommand().importActionFlows(cmd.packageId, cmd.file, cmd.dryRun, cmd.outputToJsonFile);
69
+ process.exit();
70
+ }));
71
+ return program;
72
+ }
57
73
  }
58
74
  exports.Import = Import;
59
75
  const loadCommands = () => {
@@ -71,6 +87,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
71
87
  function getAllCommands() {
72
88
  Import.packages(commander);
73
89
  Import.dataPools(commander);
90
+ Import.actionFlows(commander);
74
91
  commander.parse(process.argv);
75
92
  }
76
93
  });
package/content-cli.js CHANGED
@@ -22,13 +22,14 @@
22
22
  program.command("profile", "Commands related to profiles.");
23
23
  program.command("pull", "Commands to pull content.");
24
24
  program.command("export", "Commands to export content.");
25
- program.command("import", "Commands to export content.");
25
+ program.command("import", "Commands to import content.");
26
26
  program.command("push", "Commands to push content.");
27
27
  program.command("update", "Commands to update content.");
28
28
  program.command("list", "Commands to list content.").alias("ls");
29
29
  program.command("get", "Commands to get configuration properties.");
30
30
  program.command("set", "Commands to set configuration properties.");
31
31
  program.command("config", "Commands related to config management.");
32
+ program.command("analyze", "Commands to analyze assets dependencies.");
32
33
  program.version(version_1.VersionUtils.getCurrentCliVersion());
33
34
  program.parse(process.argv);
34
35
  if (!process.argv.slice(2).length) {
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ import * as FormData from "form-data";
3
+ declare class ActionFlowApi {
4
+ static readonly INSTANCE: ActionFlowApi;
5
+ exportRawAssets(packageId: string): Promise<Buffer>;
6
+ analyzeAssets(packageId: string): Promise<any>;
7
+ importAssets(packageId: string, data: FormData, dryRun: boolean): Promise<any>;
8
+ }
9
+ export declare const actionFlowApi: ActionFlowApi;
10
+ export {};
@@ -0,0 +1,5 @@
1
+ export declare class ActionFlowCommand {
2
+ exportActionFlows(packageId: string, metadataFile: string): Promise<void>;
3
+ analyzeActionFlows(packageId: string, outputToJsonFile: boolean): Promise<void>;
4
+ importActionFlows(packageId: string, filePath: string, dryRun: boolean, outputToJsonFile: boolean): Promise<void>;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -2,4 +2,5 @@ import { CommanderStatic } from "commander";
2
2
  export declare class Export {
3
3
  static packages(program: CommanderStatic): CommanderStatic;
4
4
  static dataPool(program: CommanderStatic): CommanderStatic;
5
+ static actionFlows(program: CommanderStatic): CommanderStatic;
5
6
  }
@@ -2,4 +2,5 @@ import { CommanderStatic } from "commander";
2
2
  export declare class Import {
3
3
  static packages(program: CommanderStatic): CommanderStatic;
4
4
  static dataPools(program: CommanderStatic): CommanderStatic;
5
+ static actionFlows(program: CommanderStatic): CommanderStatic;
5
6
  }
@@ -0,0 +1,11 @@
1
+ declare class ActionFlowService {
2
+ static readonly METADATA_FILE_NAME = "metadata.json";
3
+ exportActionFlows(packageId: string, metadataFilePath: string): Promise<void>;
4
+ analyzeActionFlows(packageId: string, outputToJsonFile: boolean): Promise<void>;
5
+ importActionFlows(packageId: string, filePath: string, dryRun: boolean, outputToJsonFile: boolean): Promise<void>;
6
+ private createBodyForImport;
7
+ private attachMetadataFile;
8
+ }
9
+ export declare const actionFlowService: ActionFlowService;
10
+ export declare const metadataFileName = "metadata.json";
11
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celonis/content-cli",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "CLI Tool to help manage content in Celonis EMS",
5
5
  "main": "content-cli.js",
6
6
  "bin": {
@@ -0,0 +1,90 @@
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", "../../util/logger", "uuid", "../file-service", "../../api/action-flow-api", "adm-zip", "form-data", "fs"], factory);
17
+ }
18
+ })(function (require, exports) {
19
+ "use strict";
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.metadataFileName = exports.actionFlowService = void 0;
22
+ const logger_1 = require("../../util/logger");
23
+ const uuid_1 = require("uuid");
24
+ const file_service_1 = require("../file-service");
25
+ const action_flow_api_1 = require("../../api/action-flow-api");
26
+ const AdmZip = require("adm-zip");
27
+ const FormData = require("form-data");
28
+ const fs = require("fs");
29
+ class ActionFlowService {
30
+ exportActionFlows(packageId, metadataFilePath) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const exportedActionFlowsData = yield action_flow_api_1.actionFlowApi.exportRawAssets(packageId);
33
+ const tmpZip = new AdmZip(exportedActionFlowsData);
34
+ const zip = new AdmZip();
35
+ tmpZip.getEntries().forEach(entry => {
36
+ zip.addFile(entry.entryName, entry.getData());
37
+ });
38
+ if (metadataFilePath) {
39
+ this.attachMetadataFile(metadataFilePath, zip);
40
+ }
41
+ const fileName = "action-flows_export_" + (0, uuid_1.v4)() + ".zip";
42
+ zip.writeZip(fileName);
43
+ logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + fileName);
44
+ });
45
+ }
46
+ analyzeActionFlows(packageId, outputToJsonFile) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const actionFlowsMetadata = yield action_flow_api_1.actionFlowApi.analyzeAssets(packageId);
49
+ const actionFlowsMetadataString = JSON.stringify(actionFlowsMetadata, null, 4);
50
+ if (outputToJsonFile) {
51
+ const metadataFileName = "action-flows_metadata_" + (0, uuid_1.v4)() + ".json";
52
+ file_service_1.fileService.writeToFileWithGivenName(actionFlowsMetadataString, metadataFileName);
53
+ logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + metadataFileName);
54
+ }
55
+ else {
56
+ logger_1.logger.info("Action flows analyze metadata: \n" + actionFlowsMetadataString);
57
+ }
58
+ });
59
+ }
60
+ importActionFlows(packageId, filePath, dryRun, outputToJsonFile) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const actionFlowsZip = this.createBodyForImport(filePath);
63
+ const eventLog = yield action_flow_api_1.actionFlowApi.importAssets(packageId, actionFlowsZip, dryRun);
64
+ const eventLogString = JSON.stringify(eventLog, null, 4);
65
+ if (outputToJsonFile) {
66
+ const eventLogFileName = "action-flows_import_event_log_" + (0, uuid_1.v4)() + ".json";
67
+ file_service_1.fileService.writeToFileWithGivenName(eventLogString, eventLogFileName);
68
+ logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + eventLogFileName);
69
+ }
70
+ else {
71
+ logger_1.logger.info("Action flows import event log: \n" + eventLogString);
72
+ }
73
+ });
74
+ }
75
+ createBodyForImport(fileName) {
76
+ fileName = fileName + (fileName.endsWith(".zip") ? "" : ".zip");
77
+ const formData = new FormData();
78
+ formData.append("file", fs.createReadStream(fileName, { encoding: null }), { filename: fileName });
79
+ return formData;
80
+ }
81
+ attachMetadataFile(fileName, zip) {
82
+ fileName = fileName + (fileName.endsWith(".json") ? "" : ".json");
83
+ const metadata = file_service_1.fileService.readFile(fileName);
84
+ zip.addFile(ActionFlowService.METADATA_FILE_NAME, Buffer.from(metadata));
85
+ }
86
+ }
87
+ ActionFlowService.METADATA_FILE_NAME = "metadata.json";
88
+ exports.actionFlowService = new ActionFlowService();
89
+ exports.metadataFileName = ActionFlowService.METADATA_FILE_NAME;
90
+ });