@bigid/apps-infrastructure-node-js 0.2.0 → 1.180.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.
- package/.github/workflows/bigid_config +3 -0
- package/.github/workflows/npmjs_config +3 -0
- package/.github/workflows/{build-and-push.yml → private-registry-publish.yml} +5 -2
- package/.github/workflows/public-registry-publish.yml +17 -0
- package/CODEOWNERS +1 -0
- package/README.md +31 -2
- package/jsdoc.json +14 -0
- package/lib/abstractProviders/configureProvider.d.ts +10 -0
- package/lib/abstractProviders/configureProvider.js +19 -0
- package/lib/abstractProviders/index.d.ts +1 -0
- package/lib/abstractProviders/index.js +3 -1
- package/lib/abstractProviders/logsProvider.js +9 -1
- package/lib/abstractProviders/manifestProvider.d.ts +2 -1
- package/lib/dto/actionResponseDetails.d.ts +3 -1
- package/lib/dto/actionResponseDetails.js +2 -1
- package/lib/dto/executionContext.d.ts +8 -4
- package/lib/dto/index.d.ts +1 -1
- package/lib/dto/subExecutionItem.d.ts +7 -0
- package/lib/dto/subExecutionItem.js +12 -0
- package/lib/dto/tenantRegistration.d.ts +5 -0
- package/lib/dto/tenantRegistration.js +2 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +16 -2
- package/lib/server.d.ts +10 -6
- package/lib/server.js +14 -9
- package/lib/services/actionsHubService.d.ts +45 -0
- package/lib/services/actionsHubService.js +105 -0
- package/lib/services/batchProcessManager.d.ts +2 -0
- package/lib/services/batchProcessManager.js +45 -0
- package/lib/services/bigidProxyService.d.ts +18 -2
- package/lib/services/bigidProxyService.js +34 -14
- package/lib/services/dataSourceService.d.ts +4 -0
- package/lib/services/dataSourceService.js +26 -0
- package/lib/services/encryptionService.d.ts +1 -0
- package/lib/services/encryptionService.js +67 -0
- package/lib/services/index.d.ts +3 -0
- package/lib/services/index.js +12 -1
- package/lib/services/schedulerService.d.ts +11 -0
- package/lib/services/schedulerService.js +41 -0
- package/lib/utils/appLogger.d.ts +10 -1
- package/lib/utils/appLogger.js +38 -7
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +15 -3
- package/lib/utils/tokenUtil.d.ts +3 -0
- package/lib/utils/tokenUtil.js +62 -0
- package/package.json +11 -4
- package/src/abstractProviders/configureProvider.ts +15 -0
- package/src/abstractProviders/index.ts +1 -0
- package/src/abstractProviders/logsProvider.ts +11 -3
- package/src/abstractProviders/manifestProvider.ts +3 -1
- package/src/dto/actionResponseDetails.ts +5 -1
- package/src/dto/executionContext.ts +9 -4
- package/src/dto/index.ts +2 -2
- package/src/dto/subExecutionItem.ts +13 -0
- package/src/dto/tenantRegistration.ts +5 -0
- package/src/index.ts +17 -1
- package/src/server.ts +33 -20
- package/src/services/actionsHubService.ts +141 -0
- package/src/services/batchProcessManager.ts +39 -0
- package/src/services/bigidProxyService.ts +48 -24
- package/src/services/dataSourceService.ts +20 -0
- package/src/services/encryptionService.ts +44 -0
- package/src/services/index.ts +5 -1
- package/src/services/schedulerService.ts +39 -0
- package/src/utils/appLogger.ts +44 -6
- package/src/utils/index.ts +1 -1
- package/src/utils/tokenUtil.ts +65 -0
- package/.dcignore +0 -1547
- package/.idea/apps-infrastructure-node-js.iml +0 -9
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/prettier.xml +0 -7
- package/.idea/runConfigurations.xml +0 -10
- package/.idea/snyk.project.settings.xml +0 -6
- package/.idea/vcs.xml +0 -6
|
@@ -12,21 +12,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.saveInStorage = exports.getValueFromAppStorage = exports.getAppStorage = exports.uploadAttachment = exports.executeHttpPut = exports.executeHttpPost = exports.executeHttpGet = exports.updateActionStatusToBigID = void 0;
|
|
15
|
+
exports.saveInStorage = exports.sendBiEvent = exports.deleteKeyFromAppStorage = exports.getValueFromAppStorage = exports.getAppStorage = exports.uploadAttachment = exports.executeHttpDelete = exports.executeHttpPut = exports.executeHttpPost = exports.executeHttpGet = exports.updateActionStatusToBigID = exports.doCallToUrl = exports.getTenantRegistrations = exports.RequestMethod = void 0;
|
|
16
16
|
const fs_1 = require("fs");
|
|
17
17
|
const https_1 = require("https");
|
|
18
18
|
const form_data_1 = __importDefault(require("form-data"));
|
|
19
19
|
const axios_1 = __importDefault(require("axios"));
|
|
20
20
|
const utils_1 = require("../utils");
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
var RequestMethod;
|
|
22
|
+
(function (RequestMethod) {
|
|
23
|
+
RequestMethod["POST"] = "post";
|
|
24
|
+
RequestMethod["GET"] = "get";
|
|
25
|
+
RequestMethod["PUT"] = "put";
|
|
26
|
+
RequestMethod["PATCH"] = "patch";
|
|
27
|
+
RequestMethod["DELETE"] = "delete";
|
|
28
|
+
})(RequestMethod || (exports.RequestMethod = RequestMethod = {}));
|
|
29
|
+
const getTenantRegistrations = (bigidToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
const { data: { data: { tenants }, }, } = yield (0, exports.doCallToUrl)(bigidToken, RequestMethod.GET, `${process.env.BIGID_BASE_URL}/api/v1/tenant-service/applications/registrations`);
|
|
31
|
+
return tenants;
|
|
32
|
+
});
|
|
33
|
+
exports.getTenantRegistrations = getTenantRegistrations;
|
|
28
34
|
const doCallToUrl = (bigidToken, requestMethod, endpoint, bodyJson) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
-
utils_1.
|
|
35
|
+
(0, utils_1.logInfo)(`--> bigid-proxy::callBigIdApi: [${requestMethod}] endpoint: ${endpoint}`);
|
|
30
36
|
try {
|
|
31
37
|
const headers = {
|
|
32
38
|
Accept: 'application/json, text/plain, */*',
|
|
@@ -45,19 +51,20 @@ const doCallToUrl = (bigidToken, requestMethod, endpoint, bodyJson) => __awaiter
|
|
|
45
51
|
requestObj.data = bodyJson;
|
|
46
52
|
}
|
|
47
53
|
const res = yield (0, axios_1.default)(requestObj);
|
|
48
|
-
utils_1.
|
|
54
|
+
(0, utils_1.logInfo)(`<-- bigid-proxy::callBigIdApi: ${endpoint} success`);
|
|
49
55
|
return res;
|
|
50
56
|
}
|
|
51
57
|
catch (error) {
|
|
52
|
-
utils_1.
|
|
53
|
-
utils_1.
|
|
58
|
+
(0, utils_1.logInfo)(`<-- bigid-proxy::callBigIdApi: error calling bigID on endpoint: ${endpoint}, error: ${error}`);
|
|
59
|
+
(0, utils_1.logError)(error.message);
|
|
54
60
|
return error === null || error === void 0 ? void 0 : error.message;
|
|
55
61
|
}
|
|
56
62
|
});
|
|
63
|
+
exports.doCallToUrl = doCallToUrl;
|
|
57
64
|
function callBigIdApi(executionContext, requestMethod, endpoint, bodyJson, useEndpointWithoutBigIdBasePath) {
|
|
58
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
66
|
const url = useEndpointWithoutBigIdBasePath ? endpoint : executionContext.bigidBaseUrl + endpoint;
|
|
60
|
-
return yield doCallToUrl(executionContext.bigidToken, requestMethod, url, bodyJson);
|
|
67
|
+
return yield (0, exports.doCallToUrl)(executionContext.bigidToken, requestMethod, url, bodyJson);
|
|
61
68
|
});
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
@@ -81,13 +88,18 @@ exports.executeHttpGet = executeHttpGet;
|
|
|
81
88
|
/**
|
|
82
89
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
83
90
|
*/
|
|
84
|
-
const executeHttpPost = (executionContext, endpoint,
|
|
91
|
+
const executeHttpPost = (executionContext, endpoint, obj) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.POST, endpoint, obj); });
|
|
85
92
|
exports.executeHttpPost = executeHttpPost;
|
|
86
93
|
/**
|
|
87
94
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
88
95
|
*/
|
|
89
96
|
const executeHttpPut = (executionContext, endpoint, obj) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.PUT, endpoint, obj); });
|
|
90
97
|
exports.executeHttpPut = executeHttpPut;
|
|
98
|
+
/**
|
|
99
|
+
* the endpoint in BigID, used for DELETE requests.
|
|
100
|
+
*/
|
|
101
|
+
const executeHttpDelete = (executionContext, endpoint) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.DELETE, endpoint); });
|
|
102
|
+
exports.executeHttpDelete = executeHttpDelete;
|
|
91
103
|
const uploadAttachment = (executionContext, filePathToUpload) => {
|
|
92
104
|
const formData = new form_data_1.default();
|
|
93
105
|
formData.append('file', (0, fs_1.createReadStream)(filePathToUpload));
|
|
@@ -114,6 +126,14 @@ const getValueFromAppStorage = (executionContext, key) => __awaiter(void 0, void
|
|
|
114
126
|
return data === 'Key not found' ? null : data.value;
|
|
115
127
|
});
|
|
116
128
|
exports.getValueFromAppStorage = getValueFromAppStorage;
|
|
129
|
+
const deleteKeyFromAppStorage = (executionContext, key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
130
|
+
yield (0, exports.executeHttpDelete)(executionContext, `tpa/${executionContext.tpaId}/storage/key/${key}`);
|
|
131
|
+
});
|
|
132
|
+
exports.deleteKeyFromAppStorage = deleteKeyFromAppStorage;
|
|
133
|
+
const sendBiEvent = (executionContext, eventType, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
134
|
+
return (0, exports.executeHttpPost)(executionContext, 'bi-events', { event_type: eventType, data: data });
|
|
135
|
+
});
|
|
136
|
+
exports.sendBiEvent = sendBiEvent;
|
|
117
137
|
const saveInStorage = (executionContext, keyToStore, valueToStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
138
|
return yield (0, exports.executeHttpPut)(executionContext, `/tpa/${executionContext.tpaId}/storage`, {
|
|
119
139
|
keysValues: [
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.fetchDataSourceCredentials = void 0;
|
|
13
|
+
const encryptionService_1 = require("./encryptionService");
|
|
14
|
+
const bigidProxyService_1 = require("./bigidProxyService");
|
|
15
|
+
const fetchDataSourceCredentials = (executionContext, dataSourceName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const res = yield (0, bigidProxyService_1.executeHttpGet)(executionContext, '/tpa/' + executionContext.tpaId + '/credentials/' + dataSourceName.replace(' ', '%20'));
|
|
17
|
+
const resData = res.data;
|
|
18
|
+
return Object.keys(resData).reduce((acc, key) => {
|
|
19
|
+
var _a;
|
|
20
|
+
const credentialObject = resData[key];
|
|
21
|
+
const credentialValue = (_a = credentialObject.value) === null || _a === void 0 ? void 0 : _a.toString();
|
|
22
|
+
acc[key] = credentialObject.encrypted ? (0, encryptionService_1.decrypt)(credentialValue) : credentialValue;
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
});
|
|
26
|
+
exports.fetchDataSourceCredentials = fetchDataSourceCredentials;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const decrypt: (encryptedText: string) => string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.decrypt = void 0;
|
|
27
|
+
const crypto = __importStar(require("crypto"));
|
|
28
|
+
var Defaults;
|
|
29
|
+
(function (Defaults) {
|
|
30
|
+
Defaults["SHA_ALGORITHM"] = "sha256";
|
|
31
|
+
Defaults["AES_ALGORITHM"] = "aes-256-cbc";
|
|
32
|
+
Defaults["IV"] = "4e5Wa71fYoT7MFEX";
|
|
33
|
+
Defaults["BASE64_ENC"] = "base64";
|
|
34
|
+
Defaults["UTF8_ENC"] = "utf8";
|
|
35
|
+
Defaults["DOLLAR_DEL"] = "$";
|
|
36
|
+
Defaults["SECRET_KEY"] = "SECRET_KEY";
|
|
37
|
+
})(Defaults || (Defaults = {}));
|
|
38
|
+
const decrypt = (encryptedText) => {
|
|
39
|
+
const ivAndText = getAndUseOldIvOrNew(encryptedText);
|
|
40
|
+
const decipher = crypto.createDecipheriv(Defaults.AES_ALGORITHM, makeKey(), ivAndText.iv);
|
|
41
|
+
let decryptedData = decipher.update(ivAndText.cleanText, Defaults.BASE64_ENC, Defaults.UTF8_ENC);
|
|
42
|
+
decryptedData += decipher.final(Defaults.UTF8_ENC);
|
|
43
|
+
return decryptedData;
|
|
44
|
+
};
|
|
45
|
+
exports.decrypt = decrypt;
|
|
46
|
+
const makeKey = () => {
|
|
47
|
+
var _a;
|
|
48
|
+
const md = crypto.createHash(Defaults.SHA_ALGORITHM);
|
|
49
|
+
try {
|
|
50
|
+
const secretKey = (_a = process.env.APPLICATION_CREDENTIALS_KEY) !== null && _a !== void 0 ? _a : '';
|
|
51
|
+
const key = md.update(secretKey).digest();
|
|
52
|
+
return key;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
throw new Error("Can't create a key. Check for APPLICATION_CREDENTIALS_KEY in your environment variables.");
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const getAndUseOldIvOrNew = (text) => {
|
|
59
|
+
const ivAndText = { iv: Defaults.IV, cleanText: text };
|
|
60
|
+
if (text.includes(Defaults.DOLLAR_DEL)) {
|
|
61
|
+
const [cipher_blob, ...cipher_blob2] = text.split(Defaults.DOLLAR_DEL);
|
|
62
|
+
const cipherBlobPartTwo = cipher_blob2.join(Defaults.DOLLAR_DEL);
|
|
63
|
+
ivAndText.iv = Buffer.from(cipher_blob, Defaults.BASE64_ENC);
|
|
64
|
+
ivAndText.cleanText = Buffer.from(cipherBlobPartTwo, Defaults.BASE64_ENC);
|
|
65
|
+
}
|
|
66
|
+
return ivAndText;
|
|
67
|
+
};
|
package/lib/services/index.d.ts
CHANGED
package/lib/services/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -10,4 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.unscheduleFunction = exports.unscheduleAllFunctions = exports.scheduleFunction = void 0;
|
|
13
18
|
__exportStar(require("./bigidProxyService"), exports);
|
|
19
|
+
__exportStar(require("./dataSourceService"), exports);
|
|
20
|
+
__exportStar(require("./actionsHubService"), exports);
|
|
21
|
+
var schedulerService_1 = require("./schedulerService");
|
|
22
|
+
Object.defineProperty(exports, "scheduleFunction", { enumerable: true, get: function () { return schedulerService_1.scheduleFunction; } });
|
|
23
|
+
Object.defineProperty(exports, "unscheduleAllFunctions", { enumerable: true, get: function () { return schedulerService_1.unscheduleAllFunctions; } });
|
|
24
|
+
Object.defineProperty(exports, "unscheduleFunction", { enumerable: true, get: function () { return schedulerService_1.unscheduleFunction; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BatchFunction } from './batchProcessManager';
|
|
2
|
+
/**
|
|
3
|
+
* use this method to call a function execution according to a cron expression.
|
|
4
|
+
*
|
|
5
|
+
* @param batchUN - name for the job.
|
|
6
|
+
* @param cronExpression - the cron expression for the function call.
|
|
7
|
+
* @param callback - the function that will be called.
|
|
8
|
+
*/
|
|
9
|
+
export declare const scheduleFunction: (batchUN: string, cronExpression: string, callback: BatchFunction) => void;
|
|
10
|
+
export declare const unscheduleFunction: (batchUN: string) => void;
|
|
11
|
+
export declare const unscheduleAllFunctions: () => void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.unscheduleAllFunctions = exports.unscheduleFunction = exports.scheduleFunction = void 0;
|
|
13
|
+
const batchProcessManager_1 = require("./batchProcessManager");
|
|
14
|
+
const node_schedule_1 = require("node-schedule");
|
|
15
|
+
const tokenUtil_1 = require("../utils/tokenUtil");
|
|
16
|
+
const scheduleSingleTenantProcess = (batchUN, cronExpression, callback) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
if (!process.env.BIGID_BASE_URL || !process.env.BIGID_REFRESH_TOKEN)
|
|
18
|
+
throw new Error('Please make sure to fill out BIGID_BASE_URL && BIGID_REFRESH_TOKEN environment variables.');
|
|
19
|
+
const bigidAccessToken = yield (0, tokenUtil_1.getAccessTokenFromRefreshToken)(process.env.BIGID_REFRESH_TOKEN);
|
|
20
|
+
(0, node_schedule_1.scheduleJob)(batchUN, cronExpression, () => callback('SINGLE_TENANT', process.env.BIGID_BASE_URL, bigidAccessToken));
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* use this method to call a function execution according to a cron expression.
|
|
24
|
+
*
|
|
25
|
+
* @param batchUN - name for the job.
|
|
26
|
+
* @param cronExpression - the cron expression for the function call.
|
|
27
|
+
* @param callback - the function that will be called.
|
|
28
|
+
*/
|
|
29
|
+
const scheduleFunction = (batchUN, cronExpression, callback) => {
|
|
30
|
+
process.env.MULTI_TENANT_MODE
|
|
31
|
+
? (0, node_schedule_1.scheduleJob)(batchUN, cronExpression, () => (0, batchProcessManager_1.handleBatchProcess)(callback))
|
|
32
|
+
: scheduleSingleTenantProcess(batchUN, cronExpression, callback);
|
|
33
|
+
};
|
|
34
|
+
exports.scheduleFunction = scheduleFunction;
|
|
35
|
+
const unscheduleFunction = (batchUN) => {
|
|
36
|
+
const jobToCancel = node_schedule_1.scheduledJobs[batchUN];
|
|
37
|
+
jobToCancel.cancel();
|
|
38
|
+
};
|
|
39
|
+
exports.unscheduleFunction = unscheduleFunction;
|
|
40
|
+
const unscheduleAllFunctions = () => Object.keys(node_schedule_1.scheduledJobs).forEach(jobName => node_schedule_1.scheduledJobs[jobName].cancel());
|
|
41
|
+
exports.unscheduleAllFunctions = unscheduleAllFunctions;
|
package/lib/utils/appLogger.d.ts
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
type LogMetadata = {
|
|
2
|
+
tenantId: string;
|
|
3
|
+
functionName: string;
|
|
4
|
+
scriptName: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const logInfo: (message: string, logMetadata?: LogMetadata) => void;
|
|
7
|
+
export declare const logError: (message: string, logMetadata?: LogMetadata) => void;
|
|
8
|
+
export declare const logWarn: (message: string, logMetadata?: LogMetadata) => void;
|
|
9
|
+
export declare const logDebug: (message: string, logMetadata?: LogMetadata) => void;
|
|
10
|
+
export {};
|
package/lib/utils/appLogger.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.logDebug = exports.logWarn = exports.logError = exports.logInfo = void 0;
|
|
4
4
|
const log4js_1 = require("log4js");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
|
+
const USER_LOG_BACKUPS = parseInt(process.env.LOG_BACKUPS + "") || 3;
|
|
7
|
+
const MAX_BACKUPS = 10;
|
|
6
8
|
(0, log4js_1.configure)({
|
|
7
9
|
appenders: {
|
|
8
10
|
console: { type: 'stdout', layout: { type: 'colored' } },
|
|
@@ -11,12 +13,41 @@ const constants_1 = require("./constants");
|
|
|
11
13
|
layout: { type: 'basic' },
|
|
12
14
|
filename: constants_1.LOGS_PATH,
|
|
13
15
|
compress: true,
|
|
14
|
-
|
|
15
|
-
keepFileExt: true
|
|
16
|
-
}
|
|
16
|
+
numBackups: USER_LOG_BACKUPS > MAX_BACKUPS ? MAX_BACKUPS : USER_LOG_BACKUPS,
|
|
17
|
+
keepFileExt: true,
|
|
18
|
+
},
|
|
17
19
|
},
|
|
18
20
|
categories: {
|
|
19
|
-
default: { appenders: ['console', 'dateFile'], level: process.env.LOG_LEVEL || 'info' }
|
|
20
|
-
}
|
|
21
|
+
default: { appenders: ['console', 'dateFile'], level: process.env.LOG_LEVEL || 'info' },
|
|
22
|
+
},
|
|
21
23
|
});
|
|
22
|
-
|
|
24
|
+
const appLogger = (0, log4js_1.getLogger)();
|
|
25
|
+
const formatLog = (message, logMetadata) => {
|
|
26
|
+
if (!logMetadata)
|
|
27
|
+
return message;
|
|
28
|
+
const params = Object.entries(logMetadata)
|
|
29
|
+
.filter(([value]) => value)
|
|
30
|
+
.map(([key, value]) => `[${key}: ${value}]`)
|
|
31
|
+
.join(' ');
|
|
32
|
+
return `${params} ${message}`;
|
|
33
|
+
};
|
|
34
|
+
const logInfo = (message, logMetadata) => {
|
|
35
|
+
const logMessage = formatLog(message, logMetadata);
|
|
36
|
+
appLogger.info(logMessage);
|
|
37
|
+
};
|
|
38
|
+
exports.logInfo = logInfo;
|
|
39
|
+
const logError = (message, logMetadata) => {
|
|
40
|
+
const logMessage = formatLog(message, logMetadata);
|
|
41
|
+
appLogger.error(logMessage);
|
|
42
|
+
};
|
|
43
|
+
exports.logError = logError;
|
|
44
|
+
const logWarn = (message, logMetadata) => {
|
|
45
|
+
const logMessage = formatLog(message, logMetadata);
|
|
46
|
+
appLogger.warn(logMessage);
|
|
47
|
+
};
|
|
48
|
+
exports.logWarn = logWarn;
|
|
49
|
+
const logDebug = (message, logMetadata) => {
|
|
50
|
+
const logMessage = formatLog(message, logMetadata);
|
|
51
|
+
appLogger.debug(logMessage);
|
|
52
|
+
};
|
|
53
|
+
exports.logDebug = logDebug;
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './appLogger';
|
package/lib/utils/index.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
var appLogger_1 = require("./appLogger");
|
|
5
|
-
Object.defineProperty(exports, "appLogger", { enumerable: true, get: function () { return appLogger_1.appLogger; } });
|
|
17
|
+
__exportStar(require("./appLogger"), exports);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.tokenExchange = exports.getAuth0Token = exports.getAccessTokenFromRefreshToken = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const https_1 = require("https");
|
|
18
|
+
const services_1 = require("../services");
|
|
19
|
+
const auth0Payload = {
|
|
20
|
+
client_id: process.env.CLIENT_ID,
|
|
21
|
+
client_secret: process.env.CLIENT_SECRET,
|
|
22
|
+
audience: process.env.AUTH0_AUDIENCE || 'bigid-api-v1',
|
|
23
|
+
grant_type: 'client_credentials',
|
|
24
|
+
};
|
|
25
|
+
let auth0Token;
|
|
26
|
+
let accessToken;
|
|
27
|
+
const getAccessTokenFromRefreshToken = (refreshToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
if (canUseLocalToken(accessToken))
|
|
29
|
+
return accessToken;
|
|
30
|
+
const bigidBaseUrl = process.env.BIGID_BASE_URL;
|
|
31
|
+
const { data: { systemToken }, } = yield (0, services_1.doCallToUrl)(refreshToken, services_1.RequestMethod.GET, new URL('api/v1/refresh-access-token', bigidBaseUrl).toString());
|
|
32
|
+
accessToken = systemToken;
|
|
33
|
+
return accessToken;
|
|
34
|
+
});
|
|
35
|
+
exports.getAccessTokenFromRefreshToken = getAccessTokenFromRefreshToken;
|
|
36
|
+
const getAuth0Token = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
var _a;
|
|
38
|
+
if (canUseLocalToken(auth0Token))
|
|
39
|
+
return auth0Token;
|
|
40
|
+
const auth0Domain = (_a = process.env.AUTH0_DOMAIN) === null || _a === void 0 ? void 0 : _a.replace(/\/$/, '');
|
|
41
|
+
const { data: { access_token }, } = yield axios_1.default.post(`${auth0Domain}/oauth/token`, auth0Payload);
|
|
42
|
+
auth0Token = access_token;
|
|
43
|
+
return access_token;
|
|
44
|
+
});
|
|
45
|
+
exports.getAuth0Token = getAuth0Token;
|
|
46
|
+
const tokenExchange = (auth0Token, tenantId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
const { data: { data }, } = yield axios_1.default.post(`${process.env.BIGID_BASE_URL}/api/v1/token-exchange`, { tenantId }, {
|
|
48
|
+
headers: { authorization: auth0Token },
|
|
49
|
+
httpsAgent: new https_1.Agent({
|
|
50
|
+
rejectUnauthorized: false,
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
return data[0];
|
|
54
|
+
});
|
|
55
|
+
exports.tokenExchange = tokenExchange;
|
|
56
|
+
const getTokenPayloadAsJson = (token) => JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
|
|
57
|
+
const canUseLocalToken = (token) => {
|
|
58
|
+
if (!token)
|
|
59
|
+
return false;
|
|
60
|
+
const { exp } = getTokenPayloadAsJson(token);
|
|
61
|
+
return Date.now() < exp * 1000;
|
|
62
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigid/apps-infrastructure-node-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.180.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"docs": "npx tsc && ./node_modules/.bin/jsdoc -c jsdoc.json"
|
|
8
|
+
},
|
|
6
9
|
"types": "lib/index.d.ts",
|
|
7
10
|
"repository": {
|
|
8
11
|
"type": "git",
|
|
@@ -14,6 +17,7 @@
|
|
|
14
17
|
"@types/express": "^4.17.13",
|
|
15
18
|
"@types/http-errors": "^1.8.1",
|
|
16
19
|
"@types/node": "^16.11.10",
|
|
20
|
+
"@types/node-schedule": "^2.1.0",
|
|
17
21
|
"@typescript-eslint/eslint-plugin": "4.6.1",
|
|
18
22
|
"@typescript-eslint/parser": "4.6.1",
|
|
19
23
|
"eslint": "7.12.1",
|
|
@@ -24,10 +28,13 @@
|
|
|
24
28
|
"typescript": "^4.5.2"
|
|
25
29
|
},
|
|
26
30
|
"dependencies": {
|
|
27
|
-
"axios": "
|
|
28
|
-
"
|
|
31
|
+
"axios": "0.24.0",
|
|
32
|
+
"follow-redirects": "1.15.2",
|
|
33
|
+
"express": "4.17.3",
|
|
29
34
|
"form-data": "^4.0.0",
|
|
30
35
|
"http-errors": "^1.8.1",
|
|
31
|
-
"
|
|
36
|
+
"jsdoc": "4.0.2",
|
|
37
|
+
"log4js": "^6.4.0",
|
|
38
|
+
"node-schedule": "2.1.1"
|
|
32
39
|
}
|
|
33
40
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
|
|
3
|
+
export type ConfigurePayload = {
|
|
4
|
+
tenantId: string;
|
|
5
|
+
bigidBaseUrl?: string;
|
|
6
|
+
isDeleted?: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const handleTenantConfigure = async (req: Request, res: Response, configureProvider: ConfigureProvider) => {
|
|
10
|
+
await configureProvider.configureTenant(req.body, res);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export abstract class ConfigureProvider {
|
|
14
|
+
public abstract configureTenant(configurePayload: ConfigurePayload, res: Response): Promise<void> | void;
|
|
15
|
+
}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
3
|
import { LOGS_PATH } from '../utils/constants';
|
|
4
4
|
|
|
5
|
-
export const fetchLogs = (req: Request, res: Response) =>
|
|
6
|
-
|
|
5
|
+
export const fetchLogs = (req: Request, res: Response) => {
|
|
6
|
+
const tenantId = req.headers.tenantid;
|
|
7
|
+
const data = readFileSync(LOGS_PATH, { encoding: 'utf8' });
|
|
8
|
+
const lines = data.split('\n');
|
|
9
|
+
const tenantLogLines = lines
|
|
10
|
+
.filter(line => line.includes(`[tenantId: ${tenantId}`) || !line.includes('[tenantId: '))
|
|
11
|
+
.join('\n');
|
|
12
|
+
|
|
13
|
+
return res.send(tenantLogLines);
|
|
14
|
+
};
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
import { SubExecutionItem } from "./subExecutionItem";
|
|
2
|
+
|
|
1
3
|
export class ActionResponseDetails {
|
|
2
4
|
executionId: string;
|
|
3
5
|
statusEnum: string;
|
|
4
6
|
progress: number;
|
|
5
7
|
message: string;
|
|
6
8
|
additionalData?: any;
|
|
9
|
+
subExecutionItems?: SubExecutionItem[];
|
|
7
10
|
|
|
8
|
-
constructor(executionId: string, statusEnum: string, progress: number, message: string, additionalData?: any) {
|
|
11
|
+
constructor(executionId: string, statusEnum: string, progress: number, message: string, additionalData?: any, subExecutionItems?: SubExecutionItem[]) {
|
|
9
12
|
this.executionId = executionId;
|
|
10
13
|
this.statusEnum = statusEnum;
|
|
11
14
|
this.progress = progress;
|
|
12
15
|
this.message = message;
|
|
13
16
|
this.additionalData = additionalData;
|
|
17
|
+
this.subExecutionItems = subExecutionItems;
|
|
14
18
|
}
|
|
15
19
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type ExecutionContext = {
|
|
2
2
|
actionName: string;
|
|
3
3
|
executionId: string;
|
|
4
|
-
globalParams:
|
|
5
|
-
actionParams:
|
|
4
|
+
globalParams: Array<GeneralParam>;
|
|
5
|
+
actionParams: Array<GeneralParam>;
|
|
6
6
|
bigidBaseUrl: string;
|
|
7
7
|
bigidToken: string;
|
|
8
8
|
updateResultCallback: any;
|
|
9
9
|
tpaId: string;
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type GeneralParam = {
|
|
13
|
+
paramName: string;
|
|
14
|
+
paramValue: string;
|
|
15
|
+
};
|
package/src/dto/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { ExecutionContext } from './executionContext';
|
|
2
|
-
export { ActionResponseDetails } from './actionResponseDetails';
|
|
1
|
+
export { ExecutionContext, GeneralParam } from './executionContext';
|
|
2
|
+
export { ActionResponseDetails } from './actionResponseDetails';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class SubExecutionItem {
|
|
2
|
+
name: string;
|
|
3
|
+
statusEnum: string;
|
|
4
|
+
message?: string;
|
|
5
|
+
errorCode?: string;
|
|
6
|
+
|
|
7
|
+
constructor(name: string, statusEnum: string, message?: string, errorCode?: string) {
|
|
8
|
+
this.name = name;
|
|
9
|
+
this.statusEnum = statusEnum;
|
|
10
|
+
this.message = message;
|
|
11
|
+
this.errorCode = errorCode;
|
|
12
|
+
}
|
|
13
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
export * from './abstractProviders';
|
|
2
2
|
export * from './dto';
|
|
3
3
|
export * from './utils';
|
|
4
|
-
export {
|
|
4
|
+
export {
|
|
5
|
+
updateActionStatusToBigID,
|
|
6
|
+
uploadAttachment,
|
|
7
|
+
getValueFromAppStorage,
|
|
8
|
+
saveInStorage,
|
|
9
|
+
executeHttpGet,
|
|
10
|
+
scheduleFunction,
|
|
11
|
+
unscheduleFunction,
|
|
12
|
+
unscheduleAllFunctions,
|
|
13
|
+
deleteKeyFromAppStorage,
|
|
14
|
+
sendBiEvent,
|
|
15
|
+
getCommandsRegistrations,
|
|
16
|
+
executeCommand,
|
|
17
|
+
getExecutionStatus,
|
|
18
|
+
registerActionAsCommand,
|
|
19
|
+
fetchDataSourceCredentials,
|
|
20
|
+
} from './services';
|
|
5
21
|
export { deployServer, ServerInit } from './server';
|