@celonis/content-cli 0.4.2 → 0.4.4

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.
@@ -28,6 +28,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
28
28
  });
29
29
  });
30
30
  }
31
+ executeDataPoolsBatchImport(importRequest) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ return http_client_service_v2_1.httpClientV2.post("/integration/api/pool/batch-import", importRequest).catch(e => {
34
+ throw new logger_1.FatalError(`Data Pool batch import failed: : ${e}`);
35
+ });
36
+ });
37
+ }
38
+ exportDataPool(poolId) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return http_client_service_v2_1.httpClientV2.get(`/integration/api/pools/${poolId}/v2/export`).catch(e => {
41
+ throw new logger_1.FatalError(`Data Pool export failed: : ${e}`);
42
+ });
43
+ });
44
+ }
31
45
  }
32
46
  DataPoolApi.INSTANCE = new DataPoolApi();
33
47
  exports.dataPoolApi = DataPoolApi.INSTANCE;
@@ -36,11 +36,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
36
36
  yield this.contentService.push(profile, this.dataPoolManagerFactory.createManager(null, filename));
37
37
  });
38
38
  }
39
+ exportDataPool(poolId, outputToJsonFile) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ yield data_pool_service_1.dataPoolService.exportDataPool(poolId, outputToJsonFile);
42
+ });
43
+ }
39
44
  pushDataPools(profile) {
40
45
  return __awaiter(this, void 0, void 0, function* () {
41
46
  yield this.contentService.batchPush(profile, this.dataPoolManagerFactory.createManagers());
42
47
  });
43
48
  }
49
+ batchImportDataPools(requestFile, outputToJsonFile) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ yield data_pool_service_1.dataPoolService.batchImportDataPools(requestFile, outputToJsonFile);
52
+ });
53
+ }
44
54
  updateDataPool(profile, id, filename) {
45
55
  return __awaiter(this, void 0, void 0, function* () {
46
56
  yield this.contentService.update(profile, this.dataPoolManagerFactory.createManager(id, filename));
@@ -13,15 +13,16 @@ 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", "./commands/package.command", "./util/logger", "./services/context.service", "commander"], factory);
16
+ define(["require", "exports", "commander", "./commands/package.command", "./util/logger", "./commands/data-pool.command", "./util/context-initializer"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
+ const commander = require("commander");
21
22
  const package_command_1 = require("./commands/package.command");
22
23
  const logger_1 = require("./util/logger");
23
- const context_service_1 = require("./services/context.service");
24
- const commander = require("commander");
24
+ const data_pool_command_1 = require("./commands/data-pool.command");
25
+ const context_initializer_1 = require("./util/context-initializer");
25
26
  class Export {
26
27
  static packages(program) {
27
28
  program
@@ -36,19 +37,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
36
37
  }));
37
38
  return program;
38
39
  }
40
+ static dataPool(program) {
41
+ program
42
+ .command("data-pool")
43
+ .description("Command to export a data pool")
44
+ .option("-p, --profile <profile>", "Profile which you want to use to export the data pool")
45
+ .requiredOption("--id <id>", "ID of the data pool you want to export")
46
+ .option("--outputToJsonFile", "Output the exported data pool to a JSON file")
47
+ .action((cmd) => __awaiter(this, void 0, void 0, function* () {
48
+ yield new data_pool_command_1.DataPoolCommand().exportDataPool(cmd.id, cmd.outputToJsonFile);
49
+ process.exit();
50
+ }));
51
+ return program;
52
+ }
39
53
  }
40
54
  exports.Export = Export;
41
- const options = commander.parseOptions(process.argv);
42
- const indexOfProfileOption = options.unknown.indexOf('-p') !== -1 ? options.unknown.indexOf('-p') : options.unknown.indexOf('--profile');
43
- process.on("unhandledRejection", (e, promise) => {
44
- logger_1.logger.error(e.toString());
45
- });
46
- context_service_1.contextService.resolveProfile(options.unknown[indexOfProfileOption + 1]).then(() => {
47
- getAllCommands();
48
- }, () => {
55
+ const loadCommands = () => {
49
56
  getAllCommands();
50
- }).catch(e => {
51
- console.log(e);
57
+ };
58
+ context_initializer_1.ContextInitializer.initContext()
59
+ .then(loadCommands, loadCommands)
60
+ .catch(e => {
61
+ logger_1.logger.error(e);
52
62
  });
53
63
  if (!process.argv.slice(2).length) {
54
64
  commander.outputHelp();
@@ -56,6 +66,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
56
66
  }
57
67
  function getAllCommands() {
58
68
  Export.packages(commander);
69
+ Export.dataPool(commander);
59
70
  commander.parse(process.argv);
60
71
  }
61
72
  });
@@ -13,15 +13,16 @@ 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", "./commands/package.command", "./util/logger", "./services/context.service", "commander"], factory);
16
+ define(["require", "exports", "commander", "./commands/package.command", "./commands/data-pool.command", "./util/context-initializer", "./util/logger"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
+ const commander = require("commander");
21
22
  const package_command_1 = require("./commands/package.command");
23
+ const data_pool_command_1 = require("./commands/data-pool.command");
24
+ const context_initializer_1 = require("./util/context-initializer");
22
25
  const logger_1 = require("./util/logger");
23
- const context_service_1 = require("./services/context.service");
24
- const commander = require("commander");
25
26
  class Import {
26
27
  static packages(program) {
27
28
  program
@@ -36,19 +37,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
36
37
  }));
37
38
  return program;
38
39
  }
40
+ static dataPools(program) {
41
+ program
42
+ .command("data-pools")
43
+ .description("Command to batch import multiple data pools with their objects and dependencies")
44
+ .option("-p, --profile <profile>", "Profile which you want to use to import the data pools")
45
+ .requiredOption("-f, --jsonFile <file>", "The file with the JSON data pool batch import request")
46
+ .option("--outputToJsonFile", "Output the batch import result in a JSON file")
47
+ .action((cmd) => __awaiter(this, void 0, void 0, function* () {
48
+ yield new data_pool_command_1.DataPoolCommand().batchImportDataPools(cmd.jsonFile, cmd.outputToJsonFile);
49
+ process.exit();
50
+ }));
51
+ return program;
52
+ }
39
53
  }
40
54
  exports.Import = Import;
41
- const options = commander.parseOptions(process.argv);
42
- const indexOfProfileOption = options.unknown.indexOf('-p') !== -1 ? options.unknown.indexOf('-p') : options.unknown.indexOf('--profile');
43
- process.on("unhandledRejection", (e, promise) => {
44
- logger_1.logger.error(e.toString());
45
- });
46
- context_service_1.contextService.resolveProfile(options.unknown[indexOfProfileOption + 1]).then(() => {
47
- getAllCommands();
48
- }, () => {
55
+ const loadCommands = () => {
49
56
  getAllCommands();
50
- }).catch(e => {
51
- console.log(e);
57
+ };
58
+ context_initializer_1.ContextInitializer.initContext()
59
+ .then(loadCommands, loadCommands)
60
+ .catch(e => {
61
+ logger_1.logger.error(e);
52
62
  });
53
63
  if (!process.argv.slice(2).length) {
54
64
  commander.outputHelp();
@@ -56,6 +66,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
56
66
  }
57
67
  function getAllCommands() {
58
68
  Import.packages(commander);
69
+ Import.dataPools(commander);
59
70
  commander.parse(process.argv);
60
71
  }
61
72
  });
@@ -1,7 +1,9 @@
1
- import { DataPoolPageTransport } from "../interfaces/data-pool-manager.interfaces";
1
+ import { DataPoolInstallVersionReport, DataPoolPageTransport } from "../interfaces/data-pool-manager.interfaces";
2
2
  declare class DataPoolApi {
3
3
  static readonly INSTANCE: DataPoolApi;
4
4
  findAllPagedPools(limit: string, page: string): Promise<DataPoolPageTransport>;
5
+ executeDataPoolsBatchImport(importRequest: string): Promise<DataPoolInstallVersionReport>;
6
+ exportDataPool(poolId: string): Promise<string>;
5
7
  }
6
8
  export declare const dataPoolApi: DataPoolApi;
7
9
  export {};
@@ -3,7 +3,9 @@ export declare class DataPoolCommand {
3
3
  private dataPoolManagerFactory;
4
4
  pullDataPool(profile: string, id: string): Promise<void>;
5
5
  pushDataPool(profile: string, filename: string): Promise<void>;
6
+ exportDataPool(poolId: string, outputToJsonFile: boolean): Promise<void>;
6
7
  pushDataPools(profile: string): Promise<void>;
8
+ batchImportDataPools(requestFile: string, outputToJsonFile: boolean): Promise<void>;
7
9
  updateDataPool(profile: string, id: string, filename: string): Promise<any>;
8
10
  listDataPools(profile: string, jsonResponse: boolean): Promise<any>;
9
11
  }
@@ -1,4 +1,5 @@
1
1
  import { CommanderStatic } from "commander";
2
2
  export declare class Export {
3
3
  static packages(program: CommanderStatic): CommanderStatic;
4
+ static dataPool(program: CommanderStatic): CommanderStatic;
4
5
  }
@@ -1,4 +1,5 @@
1
1
  import { CommanderStatic } from "commander";
2
2
  export declare class Import {
3
3
  static packages(program: CommanderStatic): CommanderStatic;
4
+ static dataPools(program: CommanderStatic): CommanderStatic;
4
5
  }
@@ -22,3 +22,6 @@ export declare class DataPoolPageTransport {
22
22
  pageNumber: number;
23
23
  totalCount: number;
24
24
  }
25
+ export declare class DataPoolInstallVersionReport {
26
+ dataModelIdMappings: Map<String, String>;
27
+ }
@@ -1,4 +1,6 @@
1
1
  declare class DataPoolService {
2
+ batchImportDataPools(requestFilePath: string, outputToJsonFile: boolean): Promise<void>;
3
+ exportDataPool(poolId: string, outputToJsonFile: boolean): Promise<void>;
2
4
  listDataPools(): Promise<void>;
3
5
  findAndExportAllPools(): Promise<void>;
4
6
  private findAllPools;
@@ -4,6 +4,7 @@ export declare class FileService {
4
4
  writeToFileWithGivenName(data: any, filename: string): void;
5
5
  createDirectoryWithGivenName(dirName: string): void;
6
6
  readManifestFile(importedFileName: string): Promise<ManifestNodeTransport[]>;
7
+ readFile(filename: string): string;
7
8
  private getSerializedFileContent;
8
9
  }
9
10
  export declare const fileService: FileService;
@@ -0,0 +1,3 @@
1
+ export declare class ContextInitializer {
2
+ static initContext(): Promise<void>;
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celonis/content-cli",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "CLI Tool to help manage content in Celonis EMS",
5
5
  "main": "content-cli.js",
6
6
  "bin": {
@@ -23,6 +23,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
23
  const uuid_1 = require("uuid");
24
24
  const file_service_1 = require("../file-service");
25
25
  class DataPoolService {
26
+ batchImportDataPools(requestFilePath, outputToJsonFile) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const requestFileContent = file_service_1.fileService.readFile(requestFilePath);
29
+ const importReport = yield data_pool_api_1.dataPoolApi.executeDataPoolsBatchImport(requestFileContent);
30
+ const importReportString = JSON.stringify(importReport, null, 4);
31
+ if (outputToJsonFile) {
32
+ const reportFileName = "batch_import_report_" + uuid_1.v4() + ".json";
33
+ file_service_1.fileService.writeToFileWithGivenName(importReportString, reportFileName);
34
+ logger_1.logger.info("Batch import report file: " + reportFileName);
35
+ }
36
+ else {
37
+ logger_1.logger.info("Batch import report: \n" + importReportString);
38
+ }
39
+ });
40
+ }
41
+ exportDataPool(poolId, outputToJsonFile) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const exportedDataPool = yield data_pool_api_1.dataPoolApi.exportDataPool(poolId);
44
+ const exportedDataPoolString = JSON.stringify(exportedDataPool, null, 4);
45
+ if (outputToJsonFile) {
46
+ const reportFileName = uuid_1.v4() + "data_pool_" + poolId + ".json";
47
+ file_service_1.fileService.writeToFileWithGivenName(exportedDataPoolString, reportFileName);
48
+ logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + reportFileName);
49
+ }
50
+ else {
51
+ logger_1.logger.info("Exported Data Pool: \n" + exportedDataPoolString);
52
+ }
53
+ });
54
+ }
26
55
  listDataPools() {
27
56
  return __awaiter(this, void 0, void 0, function* () {
28
57
  const dataPools = yield this.findAllPools();
@@ -4,7 +4,7 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "fs", "path", "yaml"], factory);
7
+ define(["require", "exports", "fs", "path", "yaml", "../util/logger"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
@@ -12,6 +12,7 @@
12
12
  const fs = require("fs");
13
13
  const path = require("path");
14
14
  const YAML = require("yaml");
15
+ const logger_1 = require("../util/logger");
15
16
  class FileService {
16
17
  writeToFileWithGivenName(data, filename) {
17
18
  fs.writeFileSync(path.resolve(process.cwd(), filename), this.getSerializedFileContent(data), {
@@ -25,6 +26,12 @@
25
26
  const manifest = YAML.parse(fs.readFileSync(path.resolve(importedFileName + "/manifest.yml"), { encoding: "utf-8" }));
26
27
  return Promise.all(manifest);
27
28
  }
29
+ readFile(filename) {
30
+ if (!fs.existsSync(path.resolve(process.cwd(), filename))) {
31
+ logger_1.logger.error(new logger_1.FatalError(`The provided file '${filename}' does not exit`));
32
+ }
33
+ return fs.readFileSync(path.resolve(process.cwd(), filename), { encoding: "utf-8" });
34
+ }
28
35
  getSerializedFileContent(data) {
29
36
  return data;
30
37
  }
@@ -49,7 +49,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
49
49
  post(url, body) {
50
50
  return __awaiter(this, void 0, void 0, function* () {
51
51
  return new Promise((resolve, reject) => {
52
- request.post(this.resolveUrl(url), this.makeOptionsJson(context_service_1.contextService.getContext().profile, JSON.stringify(body), "application/json;charset=utf-8"), (err, res) => {
52
+ request.post(this.resolveUrl(url), this.makeOptionsJson(context_service_1.contextService.getContext().profile, typeof body === "string" || body instanceof String ? body : JSON.stringify(body), "application/json;charset=utf-8"), (err, res) => {
53
53
  this.handleResponse(res, resolve, reject);
54
54
  });
55
55
  }).catch(e => {
@@ -157,7 +157,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
157
157
  makeOptionsJson(profile, body, contentType) {
158
158
  return {
159
159
  headers: this.buildAuthorizationHeaders(profile, contentType),
160
- body: body
160
+ body: body,
161
161
  };
162
162
  }
163
163
  buildAuthorizationHeaders(profile, contentType) {
@@ -0,0 +1,38 @@
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", "../services/context.service", "commander"], factory);
17
+ }
18
+ })(function (require, exports) {
19
+ "use strict";
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ const logger_1 = require("./logger");
22
+ const context_service_1 = require("../services/context.service");
23
+ const commander = require("commander");
24
+ class ContextInitializer {
25
+ static initContext() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const options = commander.parseOptions(process.argv);
28
+ const pOptionIndex = options.unknown.indexOf("-p");
29
+ const indexOfProfileOption = pOptionIndex !== -1 ? pOptionIndex : options.unknown.indexOf("--profile");
30
+ process.on("unhandledRejection", (e, promise) => {
31
+ logger_1.logger.error(e.toString());
32
+ });
33
+ yield context_service_1.contextService.resolveProfile(options.unknown[indexOfProfileOption + 1]);
34
+ });
35
+ }
36
+ }
37
+ exports.ContextInitializer = ContextInitializer;
38
+ });