@celonis/content-cli 0.5.5 → 0.6.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.
- package/api/asset-api.js +1 -0
- package/api/compute-pool-api.js +1 -0
- package/api/data-pool-api.js +1 -0
- package/api/node-api.js +1 -0
- package/api/package-api.js +1 -0
- package/api/package-dependencies-api.js +1 -0
- package/api/space-api.js +1 -0
- package/api/variable-assignment-apis.js +1 -0
- package/api/variables-api.js +1 -0
- package/commands/analysis-bookmarks.command.js +1 -0
- package/commands/analysis.command.js +1 -0
- package/commands/asset.command.js +1 -0
- package/commands/connection.command.js +1 -0
- package/commands/ctp.command.js +1 -0
- package/commands/data-pool.command.js +1 -0
- package/commands/objective.command.js +1 -0
- package/commands/package.command.js +1 -0
- package/commands/profile.command.js +1 -0
- package/commands/skill.command.js +1 -0
- package/commands/space.command.js +1 -0
- package/commands/variable.command.js +1 -0
- package/commands/widget-sourcemaps.command.js +1 -0
- package/commands/widget.command.js +1 -0
- package/content/factory/analysis-bookmarks-manager.factory.js +1 -0
- package/content/factory/analysis-manager.factory.js +1 -0
- package/content/factory/asset-manager.factory.js +1 -0
- package/content/factory/ctp-manager.factory.js +1 -0
- package/content/factory/data-pool-manager.factory.js +1 -0
- package/content/factory/objective-manager.factory.js +1 -0
- package/content/factory/package-manager.factory.js +1 -0
- package/content/factory/skill-manager.factory.js +1 -0
- package/content/factory/space-manager.factory.js +1 -0
- package/content/factory/widget-manager.factory.js +3 -2
- package/content/factory/widget-sourcemaps-manager.factory.js +1 -0
- package/content/manager/analysis-bookmarks.manager.js +6 -6
- package/content/manager/analysis.manager.js +7 -7
- package/content/manager/asset.manager.js +4 -5
- package/content/manager/base.manager.js +1 -0
- package/content/manager/ctp.analysis.manager.js +8 -8
- package/content/manager/ctp.datamodel.manager.js +1 -0
- package/content/manager/ctp.manager.js +1 -0
- package/content/manager/data-pool.manager.js +3 -6
- package/content/manager/objective.manager.js +3 -4
- package/content/manager/package.manager.js +6 -6
- package/content/manager/skill.manager.js +6 -6
- package/content/manager/space.manager.js +2 -1
- package/content/manager/widget-sourcemaps.manager.js +3 -2
- package/content/manager/widget.manager.js +6 -6
- package/content-cli-export.js +1 -0
- package/content-cli-import.js +1 -0
- package/content-cli-list.js +1 -0
- package/content-cli-push.js +1 -1
- package/interfaces/package-manager.interfaces.js +2 -1
- package/interfaces/profile.interface.js +1 -0
- package/lib/content-cli-list.d.ts +1 -1
- package/lib/interfaces/data-pool-manager.interfaces.d.ts +1 -1
- package/lib/interfaces/profile.interface.d.ts +1 -1
- package/lib/services/http-client-service.v2.d.ts +1 -3
- package/lib/services/http-client.service.d.ts +2 -3
- package/lib/validators/profile.validator.d.ts +1 -1
- package/package.json +6 -7
- package/services/connection/connection.service.js +1 -0
- package/services/content.service.js +1 -0
- package/services/context.service.js +1 -0
- package/services/data-pool/data-pool-service.js +4 -3
- package/services/file-service.js +2 -1
- package/services/http-client-service.v2.js +60 -54
- package/services/http-client.service.js +55 -45
- package/services/package-manager/asset-service.js +2 -1
- package/services/package-manager/datamodel-service.js +1 -0
- package/services/package-manager/package-service.js +5 -4
- package/services/package-manager/space-service.js +2 -1
- package/services/package-manager/variable-service.js +2 -1
- package/services/profile.service.js +1 -0
- package/services/question.service.js +1 -0
- package/util/context-initializer.js +1 -0
- package/util/logger.js +1 -0
- package/util/semantic-versioning.js +1 -0
- package/util/tracing.js +1 -0
- package/util/version.js +1 -0
- package/util/yaml.js +1 -0
- package/validators/profile.validator.js +31 -33
|
@@ -13,20 +13,30 @@ 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", "
|
|
16
|
+
define(["require", "exports", "../interfaces/profile.interface", "../util/logger", "axios", "form-data"], factory);
|
|
17
17
|
}
|
|
18
18
|
})(function (require, exports) {
|
|
19
19
|
"use strict";
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.HttpClientService = void 0;
|
|
21
22
|
const profile_interface_1 = require("../interfaces/profile.interface");
|
|
22
23
|
const logger_1 = require("../util/logger");
|
|
23
|
-
const
|
|
24
|
+
const axios_1 = require("axios");
|
|
25
|
+
const FormData = require("form-data");
|
|
24
26
|
class HttpClientService {
|
|
25
27
|
pushData(url, profile, body) {
|
|
26
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
29
|
return new Promise((resolve, reject) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
const headers = this.buildAuthorizationHeaders(profile);
|
|
31
|
+
if (body instanceof FormData) {
|
|
32
|
+
headers["Content-Type"] = "multipart/form-data";
|
|
33
|
+
}
|
|
34
|
+
axios_1.default.post(url, body, {
|
|
35
|
+
headers
|
|
36
|
+
}).then(response => {
|
|
37
|
+
this.handleResponse(response, resolve, reject);
|
|
38
|
+
}).catch(err => {
|
|
39
|
+
this.handleError(err, resolve, reject);
|
|
30
40
|
});
|
|
31
41
|
});
|
|
32
42
|
});
|
|
@@ -34,8 +44,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
34
44
|
pullData(url, profile) {
|
|
35
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
46
|
return new Promise((resolve, reject) => {
|
|
37
|
-
|
|
38
|
-
this.
|
|
47
|
+
axios_1.default.get(url, {
|
|
48
|
+
headers: this.buildAuthorizationHeaders(profile)
|
|
49
|
+
}).then(response => {
|
|
50
|
+
this.handleResponse(response, resolve, reject);
|
|
51
|
+
}).catch(err => {
|
|
52
|
+
this.handleError(err, resolve, reject);
|
|
39
53
|
});
|
|
40
54
|
});
|
|
41
55
|
});
|
|
@@ -43,31 +57,37 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
43
57
|
pullFileData(url, profile) {
|
|
44
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
59
|
return new Promise((resolve, reject) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
axios_1.default.post(url, null, {
|
|
61
|
+
headers: this.buildAuthorizationHeaders(profile),
|
|
62
|
+
responseType: "stream"
|
|
63
|
+
}).then(response => {
|
|
49
64
|
const data = [];
|
|
50
|
-
response.on("data", (chunk) => {
|
|
65
|
+
response.data.on("data", (chunk) => {
|
|
51
66
|
data.push(chunk);
|
|
52
67
|
});
|
|
53
|
-
response.on("end", () => {
|
|
54
|
-
if (this.checkBadRequest(response.
|
|
55
|
-
this.handleBadRequest(response.
|
|
68
|
+
response.data.on("end", () => {
|
|
69
|
+
if (this.checkBadRequest(response.status)) {
|
|
70
|
+
this.handleBadRequest(response.status, data.toString(), reject);
|
|
56
71
|
}
|
|
57
72
|
else {
|
|
58
73
|
this.handleResponseStreamData(Buffer.concat(data), resolve, reject);
|
|
59
74
|
}
|
|
60
75
|
});
|
|
61
|
-
})
|
|
62
|
-
.
|
|
76
|
+
}).catch(err => {
|
|
77
|
+
this.handleError(err, resolve, reject);
|
|
78
|
+
});
|
|
63
79
|
});
|
|
64
80
|
});
|
|
65
81
|
}
|
|
66
82
|
updateData(url, profile, body) {
|
|
67
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
84
|
return new Promise((resolve, reject) => {
|
|
69
|
-
|
|
70
|
-
this.
|
|
85
|
+
axios_1.default.put(url, body, {
|
|
86
|
+
headers: this.buildAuthorizationHeaders(profile)
|
|
87
|
+
}).then(response => {
|
|
88
|
+
this.handleResponse(response, resolve, reject);
|
|
89
|
+
}).catch(err => {
|
|
90
|
+
this.handleError(err, resolve, reject);
|
|
71
91
|
});
|
|
72
92
|
});
|
|
73
93
|
});
|
|
@@ -75,29 +95,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
75
95
|
findAll(url, profile) {
|
|
76
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
97
|
return new Promise((resolve, reject) => {
|
|
78
|
-
|
|
79
|
-
this.
|
|
98
|
+
axios_1.default.get(url, {
|
|
99
|
+
headers: this.buildAuthorizationHeaders(profile)
|
|
100
|
+
}).then(response => {
|
|
101
|
+
this.handleResponse(response, resolve, reject);
|
|
102
|
+
}).catch(err => {
|
|
103
|
+
this.handleError(err, resolve, reject);
|
|
80
104
|
});
|
|
81
105
|
});
|
|
82
106
|
});
|
|
83
107
|
}
|
|
84
|
-
makeOptions(profile, body = {}) {
|
|
85
|
-
const options = {
|
|
86
|
-
headers: this.buildAuthorizationHeaders(profile),
|
|
87
|
-
};
|
|
88
|
-
return Object.assign(options, body);
|
|
89
|
-
}
|
|
90
|
-
makeFileDownloadOptions(profile) {
|
|
91
|
-
return {
|
|
92
|
-
headers: this.buildAuthorizationHeaders(profile),
|
|
93
|
-
responseType: "binary",
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
108
|
buildAuthorizationHeaders(profile) {
|
|
97
109
|
const authenticationType = profile.authenticationType || profile_interface_1.AuthenticationType.BEARER;
|
|
98
110
|
return {
|
|
99
|
-
|
|
100
|
-
"
|
|
111
|
+
Authorization: `${authenticationType} ${profile.apiToken}`,
|
|
112
|
+
"Content-Type": "application/json",
|
|
101
113
|
};
|
|
102
114
|
}
|
|
103
115
|
// tslint:disable-next-line:typedef
|
|
@@ -111,21 +123,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
111
123
|
}
|
|
112
124
|
// tslint:disable-next-line:typedef
|
|
113
125
|
handleResponse(res, resolve, reject) {
|
|
114
|
-
if (this.checkBadRequest(res.
|
|
115
|
-
this.handleBadRequest(res.
|
|
126
|
+
if (this.checkBadRequest(res.status)) {
|
|
127
|
+
this.handleBadRequest(res.status, res.data, reject);
|
|
116
128
|
return;
|
|
117
129
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
130
|
+
resolve(res.data);
|
|
131
|
+
}
|
|
132
|
+
handleError(err, resolve, reject) {
|
|
133
|
+
if (err.response) {
|
|
134
|
+
this.handleResponse(err.response, resolve, reject);
|
|
123
135
|
}
|
|
124
|
-
|
|
125
|
-
reject(
|
|
126
|
-
return;
|
|
136
|
+
else {
|
|
137
|
+
reject(err.message);
|
|
127
138
|
}
|
|
128
|
-
resolve(body);
|
|
129
139
|
}
|
|
130
140
|
checkBadRequest(statusCode) {
|
|
131
141
|
return statusCode >= 400;
|
|
@@ -133,7 +143,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
133
143
|
// tslint:disable-next-line:typedef
|
|
134
144
|
handleBadRequest(statusCode, data, reject) {
|
|
135
145
|
if (data) {
|
|
136
|
-
reject(data);
|
|
146
|
+
reject(JSON.stringify(data));
|
|
137
147
|
}
|
|
138
148
|
else {
|
|
139
149
|
reject("Backend responded with status code " + statusCode);
|
|
@@ -18,6 +18,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
18
|
})(function (require, exports) {
|
|
19
19
|
"use strict";
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.assetService = void 0;
|
|
21
22
|
const logger_1 = require("../../util/logger");
|
|
22
23
|
const asset_api_1 = require("../../api/asset-api");
|
|
23
24
|
const uuid_1 = require("uuid");
|
|
@@ -38,7 +39,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
38
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
40
|
const fieldsToInclude = ["key", "name", "assetType", "rootNodeKey", "activatedDraftId"];
|
|
40
41
|
const nodes = yield asset_api_1.assetApi.findAllAssets(assetType);
|
|
41
|
-
const filename = uuid_1.v4() + ".json";
|
|
42
|
+
const filename = (0, uuid_1.v4)() + ".json";
|
|
42
43
|
file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(nodes, fieldsToInclude), filename);
|
|
43
44
|
logger_1.logger.info(this.fileDownloadedMessage + filename);
|
|
44
45
|
});
|
|
@@ -18,6 +18,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
18
|
})(function (require, exports) {
|
|
19
19
|
"use strict";
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.dataModelService = void 0;
|
|
21
22
|
const compute_pool_api_1 = require("../../api/compute-pool-api");
|
|
22
23
|
class DataModelService {
|
|
23
24
|
getDataModelDetailsForPackages(packagesWithDataModelVariables) {
|
|
@@ -18,6 +18,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
18
|
})(function (require, exports) {
|
|
19
19
|
"use strict";
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.packageService = void 0;
|
|
21
22
|
const logger_1 = require("../../util/logger");
|
|
22
23
|
const package_api_1 = require("../../api/package-api");
|
|
23
24
|
const uuid_1 = require("uuid");
|
|
@@ -82,7 +83,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
82
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
84
|
exportedPackagesFile = exportedPackagesFile + (exportedPackagesFile.includes(".zip") ? "" : ".zip");
|
|
84
85
|
const zip = new AdmZip(exportedPackagesFile);
|
|
85
|
-
const importedFilePath = path.resolve(os_1.tmpdir(), "export_" + uuid_1.v4());
|
|
86
|
+
const importedFilePath = path.resolve((0, os_1.tmpdir)(), "export_" + (0, uuid_1.v4)());
|
|
86
87
|
yield fs.mkdirSync(importedFilePath);
|
|
87
88
|
yield zip.extractAllTo(importedFilePath);
|
|
88
89
|
const manifestNodes = yield file_service_1.fileService.readManifestFile(importedFilePath);
|
|
@@ -384,7 +385,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
384
385
|
return nodePath.includes(nodeKey + ":" + version);
|
|
385
386
|
}
|
|
386
387
|
exportListOfPackages(nodes, fieldsToInclude) {
|
|
387
|
-
const filename = uuid_1.v4() + ".json";
|
|
388
|
+
const filename = (0, uuid_1.v4)() + ".json";
|
|
388
389
|
file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(nodes, fieldsToInclude), filename);
|
|
389
390
|
logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + filename);
|
|
390
391
|
}
|
|
@@ -407,11 +408,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
407
408
|
const manifestNodes = this.exportManifestOfPackages(nodes, versionsByNodeKey);
|
|
408
409
|
const packageZips = yield this.exportPackagesAndAssets(nodes);
|
|
409
410
|
const zip = new AdmZip();
|
|
410
|
-
zip.addFile("manifest.yml", Buffer.from(yaml_1.stringify(manifestNodes), "utf8"));
|
|
411
|
+
zip.addFile("manifest.yml", Buffer.from((0, yaml_1.stringify)(manifestNodes), "utf8"));
|
|
411
412
|
for (const packageZip of packageZips) {
|
|
412
413
|
zip.addFile(`${packageZip.packageKey}_${packageZip.version}.zip`, packageZip.data);
|
|
413
414
|
}
|
|
414
|
-
const fileName = "export_" + uuid_1.v4() + ".zip";
|
|
415
|
+
const fileName = "export_" + (0, uuid_1.v4)() + ".zip";
|
|
415
416
|
zip.writeZip(fileName);
|
|
416
417
|
logger_1.logger.info(this.fileDownloadedMessage + fileName);
|
|
417
418
|
});
|
|
@@ -18,6 +18,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
18
|
})(function (require, exports) {
|
|
19
19
|
"use strict";
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.spaceService = void 0;
|
|
21
22
|
const space_api_1 = require("../../api/space-api");
|
|
22
23
|
const uuid_1 = require("uuid");
|
|
23
24
|
class SpaceService {
|
|
@@ -39,7 +40,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
39
40
|
createSpace(spaceName, spaceIcon) {
|
|
40
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
42
|
const newSpace = yield space_api_1.spaceApi.createSpace({
|
|
42
|
-
id: uuid_1.v4(),
|
|
43
|
+
id: (0, uuid_1.v4)(),
|
|
43
44
|
name: spaceName,
|
|
44
45
|
iconReference: spaceIcon
|
|
45
46
|
});
|
|
@@ -18,6 +18,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
18
|
})(function (require, exports) {
|
|
19
19
|
"use strict";
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.variableService = void 0;
|
|
21
22
|
const package_api_1 = require("../../api/package-api");
|
|
22
23
|
const variables_api_1 = require("../../api/variables-api");
|
|
23
24
|
const uuid_1 = require("uuid");
|
|
@@ -48,7 +49,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
48
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
50
|
const parsedParams = this.parseParams(params);
|
|
50
51
|
const assignments = yield variables_api_1.variablesApi.getCandidateAssignments(type, parsedParams);
|
|
51
|
-
const filename = uuid_1.v4() + ".json";
|
|
52
|
+
const filename = (0, uuid_1.v4)() + ".json";
|
|
52
53
|
file_service_1.fileService.writeToFileWithGivenName(JSON.stringify(assignments), filename);
|
|
53
54
|
logger_1.logger.info(file_service_1.FileService.fileDownloadedMessage + filename);
|
|
54
55
|
});
|
|
@@ -18,6 +18,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
18
|
})(function (require, exports) {
|
|
19
19
|
"use strict";
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.profileService = exports.ProfileService = void 0;
|
|
21
22
|
const profile_interface_1 = require("../interfaces/profile.interface");
|
|
22
23
|
const profile_validator_1 = require("../validators/profile.validator");
|
|
23
24
|
const path = require("path");
|
|
@@ -18,6 +18,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
18
|
})(function (require, exports) {
|
|
19
19
|
"use strict";
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.QuestionService = void 0;
|
|
21
22
|
const readline = require("readline");
|
|
22
23
|
class QuestionService {
|
|
23
24
|
static ask(question) {
|
|
@@ -18,6 +18,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
18
|
})(function (require, exports) {
|
|
19
19
|
"use strict";
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.ContextInitializer = void 0;
|
|
21
22
|
const logger_1 = require("./logger");
|
|
22
23
|
const context_service_1 = require("../services/context.service");
|
|
23
24
|
const commander = require("commander");
|
package/util/logger.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.GracefulError = exports.FatalError = exports.logger = void 0;
|
|
12
13
|
const winston = require("winston");
|
|
13
14
|
const Transport = require("winston-transport");
|
|
14
15
|
class CustomTransport extends Transport {
|
package/util/tracing.js
CHANGED
package/util/version.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.VersionUtils = void 0;
|
|
12
13
|
// tslint:disable-next-line:no-var-requires
|
|
13
14
|
const { version } = require("./../package.json");
|
|
14
15
|
class VersionUtils {
|
package/util/yaml.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.parse = exports.stringify = void 0;
|
|
12
13
|
const YAML = require("yaml");
|
|
13
14
|
function stringify(data) {
|
|
14
15
|
return YAML.stringify(data, { doubleQuotedAsJSON: true, indent: 2, lineWidth: 200 });
|
|
@@ -13,19 +13,20 @@ 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", "
|
|
16
|
+
define(["require", "exports", "../interfaces/profile.interface", "../util/logger", "valid-url", "axios"], factory);
|
|
17
17
|
}
|
|
18
18
|
})(function (require, exports) {
|
|
19
19
|
"use strict";
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.ProfileValidator = void 0;
|
|
21
22
|
const profile_interface_1 = require("../interfaces/profile.interface");
|
|
22
23
|
const logger_1 = require("../util/logger");
|
|
23
24
|
const validUrl = require("valid-url");
|
|
24
|
-
const
|
|
25
|
+
const axios_1 = require("axios");
|
|
25
26
|
class ProfileValidator {
|
|
26
27
|
static validateProfile(profile) {
|
|
27
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
return new Promise((resolve, reject) => {
|
|
29
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
29
30
|
if (profile.name == null) {
|
|
30
31
|
logger_1.logger.error(new logger_1.FatalError("The name can not be empty"));
|
|
31
32
|
}
|
|
@@ -38,40 +39,37 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
38
39
|
if (!validUrl.isUri(profile.team)) {
|
|
39
40
|
logger_1.logger.error(new logger_1.FatalError("The provided url is not a valid url."));
|
|
40
41
|
}
|
|
41
|
-
const options = {
|
|
42
|
-
headers: {
|
|
43
|
-
authorization: `${profile_interface_1.AuthenticationType.BEARER} ${profile.apiToken}`,
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
42
|
const url = profile.team.replace(/\/?$/, "/api/cloud/team");
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
else {
|
|
57
|
-
logger_1.logger.error(new logger_1.FatalError("The provided team or api key is wrong."));
|
|
58
|
-
reject();
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
resolve(profile_interface_1.AuthenticationType.BEARER);
|
|
64
|
-
}
|
|
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
|
+
});
|
|
65
52
|
});
|
|
66
|
-
});
|
|
53
|
+
}));
|
|
67
54
|
});
|
|
68
55
|
}
|
|
69
|
-
static
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
});
|
|
72
|
+
});
|
|
75
73
|
}
|
|
76
74
|
}
|
|
77
75
|
exports.ProfileValidator = ProfileValidator;
|