@bigid/apps-infrastructure-node-js 0.1.0 → 1.180.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/.github/workflows/bigid_config +3 -0
- package/.github/workflows/npmjs_config +3 -0
- package/.github/workflows/private-registry-publish.yml +16 -0
- package/.github/workflows/public-registry-publish.yml +14 -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/{routes/router.js → abstractProviders/configureProvider.js} +7 -3
- package/lib/abstractProviders/executionProvider.d.ts +3 -2
- package/lib/abstractProviders/executionProvider.js +5 -10
- 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 -5
- package/lib/dto/executionContext.js +0 -14
- package/lib/dto/index.d.ts +1 -1
- package/lib/dto/index.js +1 -3
- 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/index.d.ts +1 -1
- package/lib/index.js +16 -2
- package/lib/server.d.ts +11 -7
- package/lib/server.js +16 -12
- 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 +28 -13
- package/lib/services/bigidProxyService.js +67 -55
- 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/executionProvider.ts +5 -7
- 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 +8 -23
- 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 +84 -62
- 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
- package/lib/appTypes/actionResponseDetails.d.ts +0 -6
- package/lib/appTypes/executionContext.d.ts +0 -10
- package/lib/appTypes/executionContext.js +0 -2
- package/lib/appTypes/index.d.ts +0 -2
- package/lib/appTypes/index.js +0 -2
- package/lib/dto/keysValuesToStore.d.ts +0 -5
- package/lib/dto/keysValuesToStore.js +0 -19
- package/lib/routes/router.d.ts +0 -1
- /package/lib/{appTypes/actionResponseDetails.js → dto/tenantRegistration.js} +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
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.handleBatchProcess = void 0;
|
|
13
|
+
const tokenUtil_1 = require("../utils/tokenUtil");
|
|
14
|
+
const bigidProxyService_1 = require("./bigidProxyService");
|
|
15
|
+
const utils_1 = require("../utils");
|
|
16
|
+
const path_1 = require("path");
|
|
17
|
+
const scriptName = (0, path_1.basename)(__filename).replace('.ts', '');
|
|
18
|
+
const handleBatchProcess = (callback) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
try {
|
|
20
|
+
(0, utils_1.logInfo)(`Starting scheduled process: ${callback.name}`);
|
|
21
|
+
const auth0Token = yield (0, tokenUtil_1.getAuth0Token)();
|
|
22
|
+
const bigidToken = yield (0, tokenUtil_1.tokenExchange)(auth0Token);
|
|
23
|
+
const appRegistrations = yield (0, bigidProxyService_1.getTenantRegistrations)(bigidToken);
|
|
24
|
+
appRegistrations.forEach(tenantRegistration => executeBatchForTenant(auth0Token, tenantRegistration, callback));
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
(0, utils_1.logError)(`Problem occurred while fetching registrations info: ${err.message}`);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
exports.handleBatchProcess = handleBatchProcess;
|
|
31
|
+
const executeBatchForTenant = (auth0Token, tenantRegistration, callback) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
const { tenantId, tenantDomain, companyName } = tenantRegistration;
|
|
33
|
+
try {
|
|
34
|
+
(0, utils_1.logInfo)(`Fetching token for scheduled process`, { tenantId, functionName: executeBatchForTenant.name, scriptName });
|
|
35
|
+
const tenantToken = yield (0, tokenUtil_1.tokenExchange)(auth0Token, tenantId);
|
|
36
|
+
callback(tenantId, tenantDomain, tenantToken);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
(0, utils_1.logError)(`Problem occurred while starting scheduled process for tenant: ${companyName}. error: ${err.message}`, {
|
|
40
|
+
tenantId,
|
|
41
|
+
functionName: executeBatchForTenant.name,
|
|
42
|
+
scriptName,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
@@ -1,28 +1,43 @@
|
|
|
1
|
-
import { ExecutionContext } from
|
|
2
|
-
import {
|
|
3
|
-
export declare
|
|
1
|
+
import { ActionResponseDetails, ExecutionContext } from '../dto';
|
|
2
|
+
import { TenantRegistration } from '../dto/tenantRegistration';
|
|
3
|
+
export declare enum RequestMethod {
|
|
4
|
+
POST = "post",
|
|
5
|
+
GET = "get",
|
|
6
|
+
PUT = "put",
|
|
7
|
+
PATCH = "patch",
|
|
8
|
+
DELETE = "delete"
|
|
9
|
+
}
|
|
10
|
+
export declare const getTenantRegistrations: (bigidToken: string) => Promise<TenantRegistration[]>;
|
|
11
|
+
export declare const doCallToUrl: (bigidToken: string, requestMethod: RequestMethod, endpoint: string, bodyJson?: Record<string, any>) => Promise<any>;
|
|
4
12
|
/**
|
|
5
13
|
* This method receives a message object to update BigID regarding the current state of the action execution
|
|
6
14
|
* (should be used in case of an async actions)
|
|
7
|
-
* @param
|
|
15
|
+
* @param executionContext
|
|
16
|
+
* @param actionResponseDetails
|
|
8
17
|
*/
|
|
9
|
-
export declare const updateActionStatusToBigID: (actionResponseDetails: ActionResponseDetails) => Promise<any>;
|
|
18
|
+
export declare const updateActionStatusToBigID: (executionContext: ExecutionContext, actionResponseDetails: ActionResponseDetails) => Promise<any>;
|
|
10
19
|
/**
|
|
11
20
|
*
|
|
21
|
+
* @param executionContext
|
|
12
22
|
* @param endpoint - the endpoint in BigID, used for GET request. e.g - {BigIDBaseUrl}/ds_connections
|
|
13
23
|
* @return - String containing the response from BigID
|
|
14
24
|
*/
|
|
15
|
-
export declare const executeHttpGet: (endpoint: string) => Promise<any>;
|
|
25
|
+
export declare const executeHttpGet: (executionContext: ExecutionContext, endpoint: string) => Promise<any>;
|
|
16
26
|
/**
|
|
17
27
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
18
28
|
*/
|
|
19
|
-
export declare const executeHttpPost: (endpoint: string,
|
|
29
|
+
export declare const executeHttpPost: (executionContext: ExecutionContext, endpoint: string, obj: any) => Promise<any>;
|
|
20
30
|
/**
|
|
21
31
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
22
32
|
*/
|
|
23
|
-
export declare const executeHttpPut: (endpoint: string, obj: any) => Promise<any>;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export declare const
|
|
28
|
-
export declare const
|
|
33
|
+
export declare const executeHttpPut: (executionContext: ExecutionContext, endpoint: string, obj: any) => Promise<any>;
|
|
34
|
+
/**
|
|
35
|
+
* the endpoint in BigID, used for DELETE requests.
|
|
36
|
+
*/
|
|
37
|
+
export declare const executeHttpDelete: (executionContext: ExecutionContext, endpoint: string) => Promise<any>;
|
|
38
|
+
export declare const uploadAttachment: (executionContext: ExecutionContext, filePathToUpload: string) => import("axios").AxiosPromise<any>;
|
|
39
|
+
export declare const getAppStorage: (executionContext: ExecutionContext) => Promise<any>;
|
|
40
|
+
export declare const getValueFromAppStorage: (executionContext: ExecutionContext, key: string) => Promise<string>;
|
|
41
|
+
export declare const deleteKeyFromAppStorage: (executionContext: ExecutionContext, key: string) => Promise<void>;
|
|
42
|
+
export declare const sendBiEvent: (executionContext: ExecutionContext, eventType: string, data: Object) => Promise<any>;
|
|
43
|
+
export declare const saveInStorage: (executionContext: ExecutionContext, keyToStore: any, valueToStore: any) => Promise<void>;
|
|
@@ -12,124 +12,136 @@ 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.
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
proxyTpaId = tpaId;
|
|
37
|
-
};
|
|
38
|
-
exports.initBigIDProxy = initBigIDProxy;
|
|
39
|
-
const doCallToUrl = (requestMethod, endpoint, bodyJson) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
utils_1.appLogger.info('--> bigid-proxy::callBigIdApi: [%s] %s', requestMethod, endpoint);
|
|
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;
|
|
34
|
+
const doCallToUrl = (bigidToken, requestMethod, endpoint, bodyJson) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
(0, utils_1.logInfo)(`--> bigid-proxy::callBigIdApi: [${requestMethod}] endpoint: ${endpoint}`);
|
|
41
36
|
try {
|
|
42
37
|
const headers = {
|
|
43
|
-
|
|
38
|
+
Accept: 'application/json, text/plain, */*',
|
|
44
39
|
'Content-Type': 'application/json',
|
|
45
|
-
|
|
40
|
+
Authorization: bigidToken,
|
|
46
41
|
};
|
|
47
42
|
const requestObj = {
|
|
48
43
|
method: requestMethod,
|
|
49
44
|
url: endpoint,
|
|
50
45
|
headers: headers,
|
|
51
46
|
httpsAgent: new https_1.Agent({
|
|
52
|
-
rejectUnauthorized: false
|
|
53
|
-
})
|
|
47
|
+
rejectUnauthorized: false,
|
|
48
|
+
}),
|
|
54
49
|
};
|
|
55
50
|
if (bodyJson && Object.keys(bodyJson).length > 0) {
|
|
56
51
|
requestObj.data = bodyJson;
|
|
57
52
|
}
|
|
58
53
|
const res = yield (0, axios_1.default)(requestObj);
|
|
59
|
-
utils_1.
|
|
54
|
+
(0, utils_1.logInfo)(`<-- bigid-proxy::callBigIdApi: ${endpoint} success`);
|
|
60
55
|
return res;
|
|
61
56
|
}
|
|
62
57
|
catch (error) {
|
|
63
|
-
utils_1.
|
|
64
|
-
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);
|
|
65
60
|
return error === null || error === void 0 ? void 0 : error.message;
|
|
66
61
|
}
|
|
67
62
|
});
|
|
68
|
-
|
|
63
|
+
exports.doCallToUrl = doCallToUrl;
|
|
64
|
+
function callBigIdApi(executionContext, requestMethod, endpoint, bodyJson, useEndpointWithoutBigIdBasePath) {
|
|
69
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
const url = useEndpointWithoutBigIdBasePath ? endpoint :
|
|
71
|
-
return yield doCallToUrl(requestMethod, url, bodyJson);
|
|
66
|
+
const url = useEndpointWithoutBigIdBasePath ? endpoint : executionContext.bigidBaseUrl + endpoint;
|
|
67
|
+
return yield (0, exports.doCallToUrl)(executionContext.bigidToken, requestMethod, url, bodyJson);
|
|
72
68
|
});
|
|
73
69
|
}
|
|
74
70
|
/**
|
|
75
71
|
* This method receives a message object to update BigID regarding the current state of the action execution
|
|
76
72
|
* (should be used in case of an async actions)
|
|
77
|
-
* @param
|
|
73
|
+
* @param executionContext
|
|
74
|
+
* @param actionResponseDetails
|
|
78
75
|
*/
|
|
79
|
-
const updateActionStatusToBigID = (actionResponseDetails) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
-
return yield callBigIdApi(RequestMethod.PUT,
|
|
76
|
+
const updateActionStatusToBigID = (executionContext, actionResponseDetails) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
+
return yield callBigIdApi(executionContext, RequestMethod.PUT, executionContext.updateResultCallback, actionResponseDetails, true);
|
|
81
78
|
});
|
|
82
79
|
exports.updateActionStatusToBigID = updateActionStatusToBigID;
|
|
83
80
|
/**
|
|
84
81
|
*
|
|
82
|
+
* @param executionContext
|
|
85
83
|
* @param endpoint - the endpoint in BigID, used for GET request. e.g - {BigIDBaseUrl}/ds_connections
|
|
86
84
|
* @return - String containing the response from BigID
|
|
87
85
|
*/
|
|
88
|
-
const executeHttpGet = (endpoint) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(RequestMethod.GET, endpoint); });
|
|
86
|
+
const executeHttpGet = (executionContext, endpoint) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.GET, endpoint); });
|
|
89
87
|
exports.executeHttpGet = executeHttpGet;
|
|
90
88
|
/**
|
|
91
89
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
92
90
|
*/
|
|
93
|
-
const executeHttpPost = (endpoint,
|
|
91
|
+
const executeHttpPost = (executionContext, endpoint, obj) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.POST, endpoint, obj); });
|
|
94
92
|
exports.executeHttpPost = executeHttpPost;
|
|
95
93
|
/**
|
|
96
94
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
97
95
|
*/
|
|
98
|
-
const executeHttpPut = (endpoint, obj) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(RequestMethod.PUT, endpoint, obj); });
|
|
96
|
+
const executeHttpPut = (executionContext, endpoint, obj) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.PUT, endpoint, obj); });
|
|
99
97
|
exports.executeHttpPut = executeHttpPut;
|
|
100
|
-
|
|
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;
|
|
103
|
+
const uploadAttachment = (executionContext, filePathToUpload) => {
|
|
101
104
|
const formData = new form_data_1.default();
|
|
102
105
|
formData.append('file', (0, fs_1.createReadStream)(filePathToUpload));
|
|
103
106
|
const headers = {
|
|
104
107
|
'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`,
|
|
105
|
-
|
|
108
|
+
Authorization: executionContext.bigidToken,
|
|
106
109
|
};
|
|
107
110
|
const requestObj = {
|
|
108
111
|
method: RequestMethod.POST,
|
|
109
|
-
url: `${
|
|
112
|
+
url: `${executionContext.updateResultCallback}/attachment`,
|
|
110
113
|
headers: headers,
|
|
111
114
|
httpsAgent: new https_1.Agent({
|
|
112
|
-
rejectUnauthorized: false
|
|
113
|
-
})
|
|
115
|
+
rejectUnauthorized: false,
|
|
116
|
+
}),
|
|
114
117
|
};
|
|
115
118
|
requestObj.data = formData;
|
|
116
119
|
return (0, axios_1.default)(requestObj);
|
|
117
120
|
};
|
|
118
121
|
exports.uploadAttachment = uploadAttachment;
|
|
119
|
-
const getAppStorage = () => (0, exports.executeHttpGet)(`tpa/${
|
|
122
|
+
const getAppStorage = (executionContext) => (0, exports.executeHttpGet)(executionContext, `tpa/${executionContext.tpaId}/storage`);
|
|
120
123
|
exports.getAppStorage = getAppStorage;
|
|
121
|
-
const getValueFromAppStorage = (key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
122
|
-
const { data } = yield (0, exports.executeHttpGet)(`tpa/${
|
|
123
|
-
return data ===
|
|
124
|
+
const getValueFromAppStorage = (executionContext, key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
const { data } = yield (0, exports.executeHttpGet)(executionContext, `tpa/${executionContext.tpaId}/storage/key/${key}`);
|
|
126
|
+
return data === 'Key not found' ? null : data.value;
|
|
124
127
|
});
|
|
125
128
|
exports.getValueFromAppStorage = getValueFromAppStorage;
|
|
126
|
-
const
|
|
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;
|
|
137
|
+
const saveInStorage = (executionContext, keyToStore, valueToStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
|
+
return yield (0, exports.executeHttpPut)(executionContext, `/tpa/${executionContext.tpaId}/storage`, {
|
|
139
|
+
keysValues: [
|
|
140
|
+
{
|
|
141
|
+
key: keyToStore,
|
|
142
|
+
value: valueToStore,
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
});
|
|
146
|
+
});
|
|
127
147
|
exports.saveInStorage = saveInStorage;
|
|
128
|
-
const setValuesForBigIDProxy = (executionContext) => {
|
|
129
|
-
if (!executionContext.bigidBaseUrl || !executionContext.bigidToken) {
|
|
130
|
-
utils_1.appLogger.error(`Missing bigidUrl and/or bigidToken. bigidUrl=${executionContext.bigidBaseUrl}, bigidToken=${executionContext.bigidToken}`);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
(0, exports.initBigIDProxy)(executionContext.bigidBaseUrl, executionContext.updateResultCallback, executionContext.bigidToken, executionContext.tpaId);
|
|
134
|
-
};
|
|
135
|
-
exports.setValuesForBigIDProxy = setValuesForBigIDProxy;
|
|
@@ -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);
|