@celonis/content-cli 0.8.4 → 0.9.0

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.
@@ -13,13 +13,14 @@ 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", "../services/question.service", "../services/profile.service", "../validators/profile.validator", "../util/logger"], factory);
16
+ define(["require", "exports", "../services/question.service", "../interfaces/profile.interface", "../services/profile.service", "../validators/profile.validator", "../util/logger"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.ProfileCommand = void 0;
22
22
  const question_service_1 = require("../services/question.service");
23
+ const profile_interface_1 = require("../interfaces/profile.interface");
23
24
  const profile_service_1 = require("../services/profile.service");
24
25
  const profile_validator_1 = require("../validators/profile.validator");
25
26
  const logger_1 = require("../util/logger");
@@ -32,8 +33,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
33
  const profile = {};
33
34
  profile.name = yield question_service_1.QuestionService.ask("Name of the profile: ");
34
35
  profile.team = yield question_service_1.QuestionService.ask("Your team (please provide the full url): ");
35
- profile.apiToken = yield question_service_1.QuestionService.ask("Your api token: ");
36
+ const type = yield question_service_1.QuestionService.ask("Profile type: OAuth Device Code (1), OAuth Client Credentials (2) or Application Key / API Key (3): ");
37
+ switch (type) {
38
+ case "1":
39
+ profile.type = profile_interface_1.ProfileType.DEVICE_CODE;
40
+ break;
41
+ case "2":
42
+ profile.type = profile_interface_1.ProfileType.CLIENT_CREDENTIALS;
43
+ profile.clientId = yield question_service_1.QuestionService.ask("Your client id: ");
44
+ profile.clientSecret = yield question_service_1.QuestionService.ask("Your client secret: ");
45
+ break;
46
+ case "3":
47
+ profile.type = profile_interface_1.ProfileType.KEY;
48
+ profile.apiToken = yield question_service_1.QuestionService.ask("Your api token: ");
49
+ break;
50
+ default:
51
+ logger_1.logger.error(new logger_1.FatalError("Invalid type"));
52
+ break;
53
+ }
36
54
  profile.authenticationType = yield profile_validator_1.ProfileValidator.validateProfile(profile);
55
+ yield this.profileService.authorizeProfile(profile);
37
56
  this.profileService.storeProfile(profile);
38
57
  if (setAsDefault) {
39
58
  yield this.makeDefaultProfile(profile.name);
@@ -53,6 +53,6 @@
53
53
  }
54
54
  }
55
55
  exports.AnalysisBookmarksManager = AnalysisBookmarksManager;
56
- AnalysisBookmarksManager.BASE_URL = "/process-analytics/api/bookmarks/";
56
+ AnalysisBookmarksManager.BASE_URL = "/process-analytics/api/bookmarks";
57
57
  AnalysisBookmarksManager.ANALYSIS_BOOKMARKS_FILE_PREFIX = "studio_analysis_bookmarks_";
58
58
  });
@@ -51,5 +51,5 @@
51
51
  }
52
52
  }
53
53
  exports.SkillManager = SkillManager;
54
- SkillManager.BASE_URL = "/action-engine/api/projects/";
54
+ SkillManager.BASE_URL = "/action-engine/api/projects";
55
55
  });
@@ -13,14 +13,13 @@ 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/analysis.command", "./commands/skill.command", "./commands/objective.command", "./commands/data-pool.command", "./commands/asset.command", "./commands/package.command", "./commands/analysis-bookmarks.command", "commander"], factory);
16
+ define(["require", "exports", "./commands/analysis.command", "./commands/skill.command", "./commands/data-pool.command", "./commands/asset.command", "./commands/package.command", "./commands/analysis-bookmarks.command", "commander"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  const analysis_command_1 = require("./commands/analysis.command");
22
22
  const skill_command_1 = require("./commands/skill.command");
23
- const objective_command_1 = require("./commands/objective.command");
24
23
  const data_pool_command_1 = require("./commands/data-pool.command");
25
24
  const asset_command_1 = require("./commands/asset.command");
26
25
  const package_command_1 = require("./commands/package.command");
@@ -66,18 +65,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
66
65
  }));
67
66
  return program;
68
67
  }
69
- static objective(program) {
70
- program
71
- .command("objective")
72
- .description("Command to pull an objective")
73
- .option("-p, --profile <profile>", "Profile which you want to use to pull the objective")
74
- .requiredOption("--id <id>", "Id of the objective you want to pull")
75
- .action((cmd) => __awaiter(this, void 0, void 0, function* () {
76
- yield new objective_command_1.ObjectiveCommand().pullObjective(cmd.profile, cmd.id);
77
- process.exit();
78
- }));
79
- return program;
80
- }
81
68
  static dataPool(program) {
82
69
  program
83
70
  .command("data-pool")
@@ -121,7 +108,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
121
108
  Pull.analysis(commander);
122
109
  Pull.analysisBookmarks(commander);
123
110
  Pull.skill(commander);
124
- Pull.objective(commander);
125
111
  Pull.dataPool(commander);
126
112
  Pull.asset(commander);
127
113
  Pull.package(commander);
@@ -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", "fs", "path", "./commands/analysis.command", "./commands/skill.command", "./commands/widget.command", "./commands/data-pool.command", "./commands/asset.command", "./commands/package.command", "./commands/ctp.command", "./commands/widget-sourcemaps.command", "./commands/analysis-bookmarks.command", "child_process", "./util/logger"], factory);
16
+ define(["require", "exports", "commander", "fs", "path", "./commands/analysis.command", "./commands/skill.command", "./commands/widget.command", "./commands/data-pool.command", "./commands/asset.command", "./commands/package.command", "./commands/ctp.command", "./commands/analysis-bookmarks.command", "child_process", "./util/logger"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
@@ -28,7 +28,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
28
28
  const asset_command_1 = require("./commands/asset.command");
29
29
  const package_command_1 = require("./commands/package.command");
30
30
  const ctp_command_1 = require("./commands/ctp.command");
31
- const widget_sourcemaps_command_1 = require("./commands/widget-sourcemaps.command");
32
31
  const analysis_bookmarks_command_1 = require("./commands/analysis-bookmarks.command");
33
32
  const child_process_1 = require("child_process");
34
33
  const logger_1 = require("./util/logger");
@@ -117,16 +116,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
117
116
  }));
118
117
  return program;
119
118
  }
120
- static widgetSourcemaps(program) {
121
- program
122
- .command("widget-sourcemaps")
123
- .description("Command to upload sourcemaps to Datadog RUM")
124
- .action(() => __awaiter(this, void 0, void 0, function* () {
125
- yield new widget_sourcemaps_command_1.WidgetSourcemapsCommand().pushSourceMaps();
126
- process.exit();
127
- }));
128
- return program;
129
- }
130
119
  static dataPool(program) {
131
120
  program
132
121
  .command("data-pool")
@@ -214,7 +203,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
214
203
  Push.assets(commander);
215
204
  Push.package(commander);
216
205
  Push.packages(commander);
217
- Push.widgetSourcemaps(commander);
218
206
  commander.parse(process.argv);
219
207
  if (!process.argv.slice(2).length) {
220
208
  commander.outputHelp();
@@ -9,10 +9,21 @@
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.AuthenticationType = void 0;
12
+ exports.ClientAuthenticationMethod = exports.ProfileType = exports.AuthenticationType = void 0;
13
13
  // tslint:disable-next-line:variable-name
14
14
  exports.AuthenticationType = {
15
15
  BEARER: "Bearer",
16
16
  APPKEY: "AppKey",
17
17
  };
18
+ // tslint:disable-next-line:variable-name
19
+ exports.ProfileType = {
20
+ DEVICE_CODE: "Device Code",
21
+ CLIENT_CREDENTIALS: "Client Credentials",
22
+ KEY: "Key"
23
+ };
24
+ // tslint:disable-next-line:variable-name
25
+ exports.ClientAuthenticationMethod = {
26
+ CLIENT_SECRET_BASIC: "client_secret_basic",
27
+ CLIENT_SECRET_POST: "client_secret_post",
28
+ };
18
29
  });
@@ -1,9 +1,9 @@
1
- import { PackageDiffTransport } from "../interfaces/diff-package.transport";
1
+ import { PackageDiffMetadata, PackageDiffTransport } from "../interfaces/diff-package.transport";
2
2
  import * as FormData from "form-data";
3
3
  declare class DiffApi {
4
4
  static readonly INSTANCE: DiffApi;
5
5
  diffPackages(data: FormData): Promise<PackageDiffTransport[]>;
6
- hasChanges(data: FormData): Promise<PackageDiffTransport[]>;
6
+ hasChanges(data: FormData): Promise<PackageDiffMetadata[]>;
7
7
  }
8
8
  export declare const diffApi: DiffApi;
9
9
  export {};
@@ -10,7 +10,10 @@ export interface NodeDiffTransport {
10
10
  }
11
11
  export interface PackageDiffTransport {
12
12
  packageKey: string;
13
- hasChanges: boolean;
14
13
  packageChanges: ConfigurationChangeTransport[];
15
14
  nodesWithChanges: NodeDiffTransport[];
16
15
  }
16
+ export interface PackageDiffMetadata {
17
+ packageKey: string;
18
+ hasChanges: boolean;
19
+ }
@@ -1,10 +1,25 @@
1
1
  export interface Profile {
2
2
  name: string;
3
3
  team: string;
4
+ type: ProfileType;
4
5
  apiToken: string;
5
6
  authenticationType: AuthenticationType;
7
+ clientId?: string;
8
+ clientSecret?: string;
9
+ scopes?: string[];
10
+ clientAuthenticationMethod?: ClientAuthenticationMethod;
11
+ refreshToken?: string;
12
+ expiresAt?: number;
6
13
  }
7
14
  export type AuthenticationType = "Bearer" | "AppKey";
15
+ export type ProfileType = "Device Code" | "Client Credentials" | "Key";
16
+ export type ClientAuthenticationMethod = "client_secret_basic" | "client_secret_post";
8
17
  export declare const AuthenticationType: {
9
18
  [key: string]: AuthenticationType;
10
19
  };
20
+ export declare const ProfileType: {
21
+ [key: string]: ProfileType;
22
+ };
23
+ export declare const ClientAuthenticationMethod: {
24
+ [key: string]: ClientAuthenticationMethod;
25
+ };
@@ -5,7 +5,9 @@ declare class DiffService {
5
5
  private buildBodyForDiff;
6
6
  private getReadableStream;
7
7
  private exportListOfPackageDiffs;
8
- private buildStringResponse;
8
+ private exportListOfPackageDiffMetadata;
9
+ private buildStringResponseForPackageDiffs;
10
+ private buildStringResponseForPackageDiffMetadataList;
9
11
  }
10
12
  export declare const diffService: DiffService;
11
13
  export {};
@@ -15,7 +15,11 @@ export declare class ProfileService {
15
15
  private constructProfileFileName;
16
16
  readAllProfiles(): Promise<string[]>;
17
17
  getAllFilesInDirectory(): string[];
18
+ authorizeProfile(profile: Profile): Promise<void>;
19
+ refreshProfile(profile: Profile): Promise<void>;
18
20
  private getProfileEnvVariables;
19
21
  private getBaseTeamUrl;
22
+ private isProfileExpired;
23
+ private tryKeyAuthentication;
20
24
  }
21
25
  export declare const profileService: ProfileService;
@@ -1,5 +1,4 @@
1
1
  import { Profile } from "../interfaces/profile.interface";
2
2
  export declare class ProfileValidator {
3
3
  static validateProfile(profile: Profile): Promise<any>;
4
- private static tryAuthenticationType;
5
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celonis/content-cli",
3
- "version": "0.8.4",
3
+ "version": "0.9.0",
4
4
  "description": "CLI Tool to help manage content in Celonis EMS",
5
5
  "main": "content-cli.js",
6
6
  "bin": {
@@ -20,6 +20,7 @@
20
20
  "axios": "1.6.2",
21
21
  "commander": "^6.0.0",
22
22
  "form-data": "4.0.0",
23
+ "openid-client": "^5.6.1",
23
24
  "hpagent": "^1.2.0",
24
25
  "semver": "^7.3.2",
25
26
  "valid-url": "^1.0.9",
@@ -43,10 +43,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
43
43
  const formData = this.buildBodyForDiff(packages);
44
44
  const returnedHasChangesData = yield diff_api_1.diffApi.hasChanges(formData);
45
45
  if (jsonResponse) {
46
- this.exportListOfPackageDiffs(returnedHasChangesData);
46
+ this.exportListOfPackageDiffMetadata(returnedHasChangesData);
47
47
  }
48
48
  else {
49
- logger_1.logger.info(this.buildStringResponse(returnedHasChangesData));
49
+ logger_1.logger.info(this.buildStringResponseForPackageDiffMetadataList(returnedHasChangesData));
50
50
  }
51
51
  });
52
52
  }
@@ -59,7 +59,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
59
59
  this.exportListOfPackageDiffs(returnedHasChangesData);
60
60
  }
61
61
  else {
62
- logger_1.logger.info(this.buildStringResponse(returnedHasChangesData));
62
+ logger_1.logger.info(this.buildStringResponseForPackageDiffs(returnedHasChangesData));
63
63
  }
64
64
  });
65
65
  }
@@ -82,9 +82,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
82
82
  file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(packageDiffs), filename);
83
83
  logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + filename);
84
84
  }
85
- buildStringResponse(packageDiffs) {
85
+ exportListOfPackageDiffMetadata(packageDiffMetadata) {
86
+ const filename = (0, uuid_1.v4)() + ".json";
87
+ file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(packageDiffMetadata), filename);
88
+ logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + filename);
89
+ }
90
+ buildStringResponseForPackageDiffs(packageDiffs) {
86
91
  return "\n" + JSON.stringify(packageDiffs, null, 2);
87
92
  }
93
+ buildStringResponseForPackageDiffMetadataList(packageDiffMetadata) {
94
+ return "\n" + JSON.stringify(packageDiffMetadata, null, 2);
95
+ }
88
96
  }
89
97
  exports.diffService = new DiffService();
90
98
  });
@@ -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", "../interfaces/profile.interface", "../validators/profile.validator", "path", "fs", "../util/logger", "os"], factory);
16
+ define(["require", "exports", "../interfaces/profile.interface", "../validators/profile.validator", "path", "fs", "../util/logger", "openid-client", "axios", "os"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
@@ -24,8 +24,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
24
24
  const path = require("path");
25
25
  const fs = require("fs");
26
26
  const logger_1 = require("../util/logger");
27
+ const openid_client_1 = require("openid-client");
28
+ const axios_1 = require("axios");
27
29
  const os = require("os");
28
30
  const homedir = os.homedir();
31
+ // use 5 seconds buffer to avoid rare cases when accessToken is just about to expire before the command is sent
32
+ const expiryBuffer = 5000;
33
+ const deviceCodeScopes = ["studio", "package-manager", "integration.data-pools", "action-engine.projects"];
34
+ const clientCredentialsScopes = ["studio", "integration.data-pools", "action-engine.projects"];
29
35
  class ProfileService {
30
36
  constructor() {
31
37
  this.profileContainerPath = path.resolve(homedir, ".celonis-content-cli-profiles");
@@ -40,7 +46,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
40
46
  }
41
47
  else {
42
48
  const file = fs.readFileSync(path.resolve(this.profileContainerPath, this.constructProfileFileName(profileName)), { encoding: "utf-8" });
43
- resolve(JSON.parse(file));
49
+ const profile = JSON.parse(file);
50
+ this.refreshProfile(profile)
51
+ .then(() => resolve(profile));
44
52
  }
45
53
  }
46
54
  catch (e) {
@@ -90,6 +98,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
90
98
  team: profileVariables.teamUrl,
91
99
  apiToken: profileVariables.apiToken,
92
100
  authenticationType: profile_interface_1.AuthenticationType.BEARER,
101
+ type: profile_interface_1.ProfileType.KEY
93
102
  };
94
103
  profile.authenticationType = yield profile_validator_1.ProfileValidator.validateProfile(profile);
95
104
  return profile;
@@ -128,6 +137,133 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
128
137
  }
129
138
  return fileNames;
130
139
  }
140
+ authorizeProfile(profile) {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ switch (profile.type) {
143
+ case profile_interface_1.ProfileType.KEY:
144
+ const url = profile.team.replace(/\/?$/, "/api/cloud/team");
145
+ try {
146
+ yield this.tryKeyAuthentication(url, profile_interface_1.AuthenticationType.BEARER, profile.apiToken);
147
+ profile.authenticationType = profile_interface_1.AuthenticationType.BEARER;
148
+ }
149
+ catch (e) {
150
+ try {
151
+ yield this.tryKeyAuthentication(url, profile_interface_1.AuthenticationType.APPKEY, profile.apiToken);
152
+ profile.authenticationType = profile_interface_1.AuthenticationType.APPKEY;
153
+ }
154
+ catch (err) {
155
+ logger_1.logger.error(new logger_1.FatalError("The provided team or api key is wrong."));
156
+ }
157
+ }
158
+ break;
159
+ case profile_interface_1.ProfileType.DEVICE_CODE:
160
+ try {
161
+ const deviceCodeIssuer = yield openid_client_1.Issuer.discover(profile.team);
162
+ const deviceCodeOAuthClient = new deviceCodeIssuer.Client({
163
+ client_id: "content-cli",
164
+ token_endpoint_auth_method: "none",
165
+ });
166
+ const deviceCodeHandle = yield deviceCodeOAuthClient.deviceAuthorization({
167
+ scope: deviceCodeScopes.join(" ")
168
+ });
169
+ logger_1.logger.info(`Continue authorization here: ${deviceCodeHandle.verification_uri_complete}`);
170
+ const deviceCodeTokenSet = yield deviceCodeHandle.poll();
171
+ profile.apiToken = deviceCodeTokenSet.access_token;
172
+ profile.refreshToken = deviceCodeTokenSet.refresh_token;
173
+ profile.expiresAt = deviceCodeTokenSet.expires_at;
174
+ }
175
+ catch (err) {
176
+ logger_1.logger.error(new logger_1.FatalError("The provided team is wrong."));
177
+ }
178
+ break;
179
+ case profile_interface_1.ProfileType.CLIENT_CREDENTIALS:
180
+ const clientCredentialsIssuer = yield openid_client_1.Issuer.discover(profile.team);
181
+ try {
182
+ // try with client secret basic
183
+ const clientCredentialsOAuthClient = new clientCredentialsIssuer.Client({
184
+ client_id: profile.clientId,
185
+ client_secret: profile.clientSecret,
186
+ token_endpoint_auth_method: profile_interface_1.ClientAuthenticationMethod.CLIENT_SECRET_BASIC,
187
+ });
188
+ const clientCredentialsTokenSet = yield clientCredentialsOAuthClient.grant({
189
+ grant_type: "client_credentials",
190
+ scope: clientCredentialsScopes.join(" ")
191
+ });
192
+ profile.clientAuthenticationMethod = profile_interface_1.ClientAuthenticationMethod.CLIENT_SECRET_BASIC;
193
+ profile.apiToken = clientCredentialsTokenSet.access_token;
194
+ profile.expiresAt = clientCredentialsTokenSet.expires_at;
195
+ }
196
+ catch (e) {
197
+ try {
198
+ // try with client secret post
199
+ const clientCredentialsOAuthClient = new clientCredentialsIssuer.Client({
200
+ client_id: profile.clientId,
201
+ client_secret: profile.clientSecret,
202
+ token_endpoint_auth_method: profile_interface_1.ClientAuthenticationMethod.CLIENT_SECRET_POST,
203
+ });
204
+ const clientCredentialsTokenSet = yield clientCredentialsOAuthClient.grant({
205
+ grant_type: "client_credentials",
206
+ scope: clientCredentialsScopes.join(" ")
207
+ });
208
+ profile.clientAuthenticationMethod = profile_interface_1.ClientAuthenticationMethod.CLIENT_SECRET_POST;
209
+ profile.apiToken = clientCredentialsTokenSet.access_token;
210
+ profile.expiresAt = clientCredentialsTokenSet.expires_at;
211
+ }
212
+ catch (err) {
213
+ logger_1.logger.error(new logger_1.FatalError("The OAuth client configuration is incorrect. " +
214
+ "Check the id, secret and scopes for correctness."));
215
+ }
216
+ }
217
+ profile.scopes = [...clientCredentialsScopes];
218
+ break;
219
+ default:
220
+ logger_1.logger.error(new logger_1.FatalError("Unsupported profile type"));
221
+ break;
222
+ }
223
+ });
224
+ }
225
+ refreshProfile(profile) {
226
+ return __awaiter(this, void 0, void 0, function* () {
227
+ if (!this.isProfileExpired(profile, expiryBuffer)) {
228
+ return;
229
+ }
230
+ const issuer = yield openid_client_1.Issuer.discover(profile.team);
231
+ if (profile.type === profile_interface_1.ProfileType.DEVICE_CODE) {
232
+ try {
233
+ const oauthClient = new issuer.Client({
234
+ client_id: "content-cli",
235
+ token_endpoint_auth_method: "none",
236
+ });
237
+ const tokenSet = yield oauthClient.refresh(profile.refreshToken);
238
+ profile.apiToken = tokenSet.access_token;
239
+ profile.expiresAt = tokenSet.expires_at;
240
+ profile.refreshToken = tokenSet.refresh_token;
241
+ }
242
+ catch (err) {
243
+ logger_1.logger.error(new logger_1.FatalError("The profile cannot be refreshed. Please retry or recreate profile."));
244
+ }
245
+ }
246
+ else {
247
+ try {
248
+ const oauthClient = new issuer.Client({
249
+ client_id: profile.clientId,
250
+ client_secret: profile.clientSecret,
251
+ token_endpoint_auth_method: profile.clientAuthenticationMethod,
252
+ });
253
+ const tokenSet = yield oauthClient.grant({
254
+ grant_type: "client_credentials",
255
+ scope: profile.scopes.join(" ")
256
+ });
257
+ profile.apiToken = tokenSet.access_token;
258
+ profile.expiresAt = tokenSet.expires_at;
259
+ }
260
+ catch (err) {
261
+ logger_1.logger.error(new logger_1.FatalError("The profile cannot be refreshed. Please retry or recreate profile."));
262
+ }
263
+ }
264
+ this.storeProfile(profile);
265
+ });
266
+ }
131
267
  getProfileEnvVariables() {
132
268
  return {
133
269
  teamUrl: this.getBaseTeamUrl(process.env.TEAM_URL),
@@ -141,6 +277,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
141
277
  const url = new URL(teamUrl);
142
278
  return url.origin;
143
279
  }
280
+ isProfileExpired(profile, buffer = 0) {
281
+ if (profile.type === null || profile.type === undefined || profile.type === profile_interface_1.ProfileType.KEY) {
282
+ return false;
283
+ }
284
+ const now = new Date();
285
+ const expirationTime = new Date(profile.expiresAt * 1000 - buffer);
286
+ return now > expirationTime;
287
+ }
288
+ tryKeyAuthentication(url, authType, apiToken) {
289
+ return new Promise((resolve, reject) => {
290
+ axios_1.default.get(url, {
291
+ headers: {
292
+ Authorization: `${authType} ${apiToken}`
293
+ }
294
+ }).then(response => {
295
+ if (response.status === 200 && response.data.domain) {
296
+ resolve();
297
+ }
298
+ else {
299
+ reject();
300
+ }
301
+ }).catch(() => {
302
+ reject();
303
+ });
304
+ });
305
+ }
144
306
  }
145
307
  exports.ProfileService = ProfileService;
146
308
  exports.profileService = new ProfileService();
@@ -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", "../interfaces/profile.interface", "../util/logger", "valid-url", "axios"], factory);
16
+ define(["require", "exports", "../interfaces/profile.interface", "../util/logger", "valid-url"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
@@ -22,53 +22,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  const profile_interface_1 = require("../interfaces/profile.interface");
23
23
  const logger_1 = require("../util/logger");
24
24
  const validUrl = require("valid-url");
25
- const axios_1 = require("axios");
26
25
  class ProfileValidator {
27
26
  static validateProfile(profile) {
28
27
  return __awaiter(this, void 0, void 0, function* () {
29
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
30
- if (profile.name == null) {
31
- logger_1.logger.error(new logger_1.FatalError("The name can not be empty"));
32
- }
33
- if (profile.team == null) {
34
- logger_1.logger.error(new logger_1.FatalError("The team can not be empty"));
35
- }
36
- if (profile.apiToken == null) {
37
- logger_1.logger.error(new logger_1.FatalError("The api token can not be empty"));
38
- }
39
- if (!validUrl.isUri(profile.team)) {
40
- logger_1.logger.error(new logger_1.FatalError("The provided url is not a valid url."));
41
- }
42
- const url = profile.team.replace(/\/?$/, "/api/cloud/team");
43
- this.tryAuthenticationType(url, profile_interface_1.AuthenticationType.BEARER, profile.apiToken).then(() => {
44
- resolve(profile_interface_1.AuthenticationType.BEARER);
45
- }).catch(() => {
46
- this.tryAuthenticationType(url, profile_interface_1.AuthenticationType.APPKEY, profile.apiToken).then(() => {
47
- resolve(profile_interface_1.AuthenticationType.APPKEY);
48
- }).catch(() => {
49
- logger_1.logger.error(new logger_1.FatalError("The provided team or api key is wrong."));
50
- reject();
51
- });
52
- });
53
- }));
54
- });
55
- }
56
- static tryAuthenticationType(url, authType, apiToken) {
57
- return new Promise((resolve, reject) => {
58
- axios_1.default.get(url, {
59
- headers: {
60
- Authorization: `${authType} ${apiToken}`
61
- }
62
- }).then(response => {
63
- if (response.status === 200 && response.data.domain) {
64
- resolve();
65
- }
66
- else {
67
- reject();
68
- }
69
- }).catch(() => {
70
- reject();
71
- });
28
+ if (profile.name == null) {
29
+ logger_1.logger.error(new logger_1.FatalError("The name can not be empty"));
30
+ }
31
+ if (profile.team == null) {
32
+ logger_1.logger.error(new logger_1.FatalError("The team can not be empty"));
33
+ }
34
+ if (profile.type === profile_interface_1.ProfileType.KEY && profile.apiToken == null) {
35
+ logger_1.logger.error(new logger_1.FatalError("The api token can not be empty for this profile type"));
36
+ }
37
+ if (profile.type === profile_interface_1.ProfileType.CLIENT_CREDENTIALS && (profile.clientId == null || profile.clientSecret == null)) {
38
+ logger_1.logger.error(new logger_1.FatalError("The client id and secret can not be empty for this profile type"));
39
+ }
40
+ if (!validUrl.isUri(profile.team)) {
41
+ logger_1.logger.error(new logger_1.FatalError("The provided url is not a valid url."));
42
+ }
72
43
  });
73
44
  }
74
45
  }
@@ -1,41 +0,0 @@
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/content.service", "../content/factory/objective-manager.factory"], factory);
17
- }
18
- })(function (require, exports) {
19
- "use strict";
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.ObjectiveCommand = void 0;
22
- const content_service_1 = require("../services/content.service");
23
- const objective_manager_factory_1 = require("../content/factory/objective-manager.factory");
24
- class ObjectiveCommand {
25
- constructor() {
26
- this.contentService = new content_service_1.ContentService();
27
- this.objectiveManagerFactory = new objective_manager_factory_1.ObjectiveManagerFactory();
28
- }
29
- pullObjective(profile, id) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- yield this.contentService.pull(profile, this.objectiveManagerFactory.createManager(id, null));
32
- });
33
- }
34
- pushObjective(profile, filename) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- yield this.contentService.push(profile, this.objectiveManagerFactory.createManager(null, filename));
37
- });
38
- }
39
- }
40
- exports.ObjectiveCommand = ObjectiveCommand;
41
- });
@@ -1,34 +0,0 @@
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", "../content/factory/widget-sourcemaps-manager.factory"], factory);
17
- }
18
- })(function (require, exports) {
19
- "use strict";
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.WidgetSourcemapsCommand = void 0;
22
- const widget_sourcemaps_manager_factory_1 = require("../content/factory/widget-sourcemaps-manager.factory");
23
- class WidgetSourcemapsCommand {
24
- constructor() {
25
- this.widgetSourcemapsFactory = new widget_sourcemaps_manager_factory_1.WidgetSourcemapsManagerFactory();
26
- }
27
- pushSourceMaps() {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- yield this.widgetSourcemapsFactory.createManager().push();
30
- });
31
- }
32
- }
33
- exports.WidgetSourcemapsCommand = WidgetSourcemapsCommand;
34
- });
@@ -1,34 +0,0 @@
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", "fs", "path", "../../util/logger", "../manager/objective.manager"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ObjectiveManagerFactory = void 0;
13
- const fs = require("fs");
14
- const path = require("path");
15
- const logger_1 = require("../../util/logger");
16
- const objective_manager_1 = require("../manager/objective.manager");
17
- class ObjectiveManagerFactory {
18
- createManager(id, filename) {
19
- const objectiveManager = new objective_manager_1.ObjectiveManager();
20
- objectiveManager.id = id;
21
- if (filename !== null) {
22
- objectiveManager.content = this.readFile(filename);
23
- }
24
- return objectiveManager;
25
- }
26
- readFile(filename) {
27
- if (!fs.existsSync(path.resolve(process.cwd(), filename))) {
28
- logger_1.logger.error(new logger_1.FatalError("The provided file does not exit"));
29
- }
30
- return fs.readFileSync(path.resolve(process.cwd(), filename), { encoding: "utf-8" });
31
- }
32
- }
33
- exports.ObjectiveManagerFactory = ObjectiveManagerFactory;
34
- });
@@ -1,35 +0,0 @@
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", "path", "../../util/logger", "../manager/widget-sourcemaps.manager", "./widget-manager.factory"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.WidgetSourcemapsManagerFactory = void 0;
13
- const path = require("path");
14
- const logger_1 = require("../../util/logger");
15
- const widget_sourcemaps_manager_1 = require("../manager/widget-sourcemaps.manager");
16
- const widget_manager_factory_1 = require("./widget-manager.factory");
17
- class WidgetSourcemapsManagerFactory {
18
- constructor() {
19
- this.widgetManagerFactory = new widget_manager_factory_1.WidgetManagerFactory();
20
- }
21
- createManager() {
22
- const widgetSourcemapsManager = new widget_sourcemaps_manager_1.WidgetSourcemapsManager();
23
- const manifest = this.widgetManagerFactory.fetchManifest();
24
- if (!manifest) {
25
- logger_1.logger.error(new logger_1.FatalError("Missing manifest file."));
26
- }
27
- this.widgetManagerFactory.validateManifest(manifest);
28
- widgetSourcemapsManager.distPath = path.resolve(process.cwd());
29
- widgetSourcemapsManager.service = manifest.key;
30
- widgetSourcemapsManager.releaseVersion = manifest.version;
31
- return widgetSourcemapsManager;
32
- }
33
- }
34
- exports.WidgetSourcemapsManagerFactory = WidgetSourcemapsManagerFactory;
35
- });
@@ -1,49 +0,0 @@
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", "./base.manager"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ObjectiveManager = void 0;
13
- const base_manager_1 = require("./base.manager");
14
- class ObjectiveManager extends base_manager_1.BaseManager {
15
- get content() {
16
- return this._content;
17
- }
18
- set content(value) {
19
- this._content = value;
20
- }
21
- get id() {
22
- return this._id;
23
- }
24
- set id(value) {
25
- this._id = value;
26
- }
27
- getConfig() {
28
- return {
29
- pushUrl: this.profile.team.replace(/\/?$/, `${ObjectiveManager.BASE_URL}/objective-kpis/import`),
30
- pullUrl: this.profile.team.replace(/\/?$/, `${ObjectiveManager.BASE_URL}/objectives/export?id=${this.id}`),
31
- exportFileName: "objective_" + this.id + ".json",
32
- onPushSuccessMessage: (data) => {
33
- return "Objective was pushed successfully. New ID: " + data.analysis.id;
34
- },
35
- };
36
- }
37
- getBody() {
38
- return {
39
- useDataModelId: "dummy",
40
- serializedObjectiveExports: this.content,
41
- };
42
- }
43
- getSerializedFileContent(data) {
44
- return JSON.stringify(data);
45
- }
46
- }
47
- exports.ObjectiveManager = ObjectiveManager;
48
- ObjectiveManager.BASE_URL = "/transformation-center/api";
49
- });
@@ -1,84 +0,0 @@
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", "child_process", "../../util/logger", "./base.manager"], factory);
17
- }
18
- })(function (require, exports) {
19
- "use strict";
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.WidgetSourcemapsManager = void 0;
22
- const child_process_1 = require("child_process");
23
- const logger_1 = require("../../util/logger");
24
- const base_manager_1 = require("./base.manager");
25
- class WidgetSourcemapsManager extends base_manager_1.BaseManager {
26
- push() {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- return this.pushWidgetSourcemaps(`assets/widgets/${this.service}`, `assets/widgets/${this.service}`);
29
- });
30
- }
31
- pushWidgetSourcemaps(sourcemapsPath, distPathPostfix) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- return new Promise((resolve, reject) => {
34
- if (!process.env.DATADOG_SITE) {
35
- logger_1.logger.error(new logger_1.GracefulError("Missing DATADOG_SITE"));
36
- }
37
- else if (!process.env.DATADOG_API_KEY) {
38
- logger_1.logger.error(new logger_1.GracefulError("Missing DATADOG_API_KEY"));
39
- }
40
- const datadogCiPath = require.resolve("@datadog/datadog-ci/dist/cli.js");
41
- const commandLines = [
42
- `node ${datadogCiPath} sourcemaps upload .`,
43
- `--service=package-manager`,
44
- `--release-version=1.0.0`,
45
- "--disable-git",
46
- ];
47
- const datadogCommandLine = [...commandLines, "--minified-path-prefix=/package-manager/"].join(" ");
48
- (0, child_process_1.exec)(datadogCommandLine, (error, stdout) => {
49
- var _a;
50
- if (error) {
51
- logger_1.logger.error(new logger_1.GracefulError(error.message));
52
- }
53
- else {
54
- logger_1.logger.info(new logger_1.GracefulError(stdout));
55
- }
56
- if (process.env.AWS_ACCESS_KEY_ID_CDN && process.env.AWS_SECRET_ACCESS_KEY_CDN) {
57
- try {
58
- const uploadSourcemapsStdout = (0, child_process_1.execSync)([
59
- ...commandLines,
60
- `--minified-path-prefix=https://static.celonis.cloud/static/package-manager/`,
61
- ].join(" "));
62
- logger_1.logger.info(uploadSourcemapsStdout);
63
- }
64
- catch (error) {
65
- logger_1.logger.error(new logger_1.GracefulError(((_a = error.stderr) === null || _a === void 0 ? void 0 : _a.toString()) || error.message));
66
- }
67
- }
68
- return resolve(error || stdout);
69
- });
70
- });
71
- });
72
- }
73
- getConfig() {
74
- return {};
75
- }
76
- getBody() {
77
- return {};
78
- }
79
- getSerializedFileContent(data) {
80
- return "";
81
- }
82
- }
83
- exports.WidgetSourcemapsManager = WidgetSourcemapsManager;
84
- });
@@ -1,6 +0,0 @@
1
- export declare class ObjectiveCommand {
2
- private contentService;
3
- private objectiveManagerFactory;
4
- pullObjective(profile: string, id: string): Promise<void>;
5
- pushObjective(profile: string, filename: string): Promise<void>;
6
- }
@@ -1,4 +0,0 @@
1
- export declare class WidgetSourcemapsCommand {
2
- private widgetSourcemapsFactory;
3
- pushSourceMaps(): Promise<void>;
4
- }
@@ -1,5 +0,0 @@
1
- import { ObjectiveManager } from "../manager/objective.manager";
2
- export declare class ObjectiveManagerFactory {
3
- createManager(id: string, filename: string): ObjectiveManager;
4
- private readFile;
5
- }
@@ -1,5 +0,0 @@
1
- import { WidgetSourcemapsManager } from "../manager/widget-sourcemaps.manager";
2
- export declare class WidgetSourcemapsManagerFactory {
3
- private widgetManagerFactory;
4
- createManager(): WidgetSourcemapsManager;
5
- }
@@ -1,14 +0,0 @@
1
- import { BaseManager } from "./base.manager";
2
- import { ManagerConfig } from "../../interfaces/manager-config.interface";
3
- export declare class ObjectiveManager extends BaseManager {
4
- private static BASE_URL;
5
- private _id;
6
- private _content;
7
- get content(): string;
8
- set content(value: string);
9
- get id(): string;
10
- set id(value: string);
11
- getConfig(): ManagerConfig;
12
- getBody(): any;
13
- protected getSerializedFileContent(data: any): string;
14
- }
@@ -1,12 +0,0 @@
1
- import { ManagerConfig } from "../../interfaces/manager-config.interface";
2
- import { BaseManager } from "./base.manager";
3
- export declare class WidgetSourcemapsManager extends BaseManager {
4
- service: string;
5
- releaseVersion: string;
6
- distPath: string;
7
- push(): Promise<any>;
8
- private pushWidgetSourcemaps;
9
- protected getConfig(): ManagerConfig;
10
- protected getBody(): object;
11
- protected getSerializedFileContent(data: any): string;
12
- }