@bigid/apps-infrastructure-node-js 0.1.0 → 0.2.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/build-and-push.yml +13 -0
- package/lib/abstractProviders/executionProvider.d.ts +3 -2
- package/lib/abstractProviders/executionProvider.js +5 -10
- package/lib/dto/executionContext.d.ts +1 -2
- package/lib/dto/executionContext.js +0 -14
- package/lib/dto/index.js +1 -3
- package/lib/server.d.ts +3 -3
- package/lib/server.js +3 -4
- package/lib/services/bigidProxyService.d.ts +12 -13
- package/lib/services/bigidProxyService.js +36 -44
- package/package.json +1 -1
- package/src/abstractProviders/executionProvider.ts +5 -7
- package/src/dto/executionContext.ts +1 -21
- package/src/services/bigidProxyService.ts +46 -48
- package/lib/appTypes/actionResponseDetails.d.ts +0 -6
- package/lib/appTypes/actionResponseDetails.js +0 -2
- 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/routes/router.js +0 -15
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Request, Response } from 'express';
|
|
2
|
+
import { ExecutionContext } from '../dto';
|
|
2
3
|
export declare const StatusEnum: {
|
|
3
4
|
COMPLETED: string;
|
|
4
5
|
IN_PROGRESS: string;
|
|
@@ -6,8 +7,8 @@ export declare const StatusEnum: {
|
|
|
6
7
|
};
|
|
7
8
|
export declare const handleExecution: (req: Request, res: Response, executionProvider: ExecutionProvider) => Promise<void>;
|
|
8
9
|
export declare abstract class ExecutionProvider {
|
|
9
|
-
abstract executeAction(
|
|
10
|
+
abstract executeAction(executionContext: ExecutionContext, res: Response): Promise<void>;
|
|
10
11
|
generateSyncSuccessMessage: (res: Response, executionId: string, message: string) => Response<any, Record<string, any>>;
|
|
11
12
|
generateAsyncSuccessMessage: (res: Response, executionId: string, message: string) => Response<any, Record<string, any>>;
|
|
12
|
-
generateFailedResponse: (res: Response, executionId: string,
|
|
13
|
+
generateFailedResponse: (res: Response, executionId: string, errorMessage: string) => Response<any, Record<string, any>>;
|
|
13
14
|
}
|
|
@@ -10,26 +10,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ExecutionProvider = exports.handleExecution = exports.StatusEnum = void 0;
|
|
13
|
-
const
|
|
14
|
-
const services_1 = require("../services");
|
|
13
|
+
const dto_1 = require("../dto");
|
|
15
14
|
exports.StatusEnum = {
|
|
16
15
|
COMPLETED: 'COMPLETED',
|
|
17
16
|
IN_PROGRESS: 'IN_PROGRESS',
|
|
18
17
|
ERROR: 'ERROR',
|
|
19
18
|
};
|
|
20
19
|
const handleExecution = (req, res, executionProvider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
|
|
22
|
-
yield executionProvider.executeAction(req, res);
|
|
20
|
+
yield executionProvider.executeAction(req.body, res);
|
|
23
21
|
});
|
|
24
22
|
exports.handleExecution = handleExecution;
|
|
25
23
|
class ExecutionProvider {
|
|
26
24
|
constructor() {
|
|
27
|
-
this.generateSyncSuccessMessage = (res, executionId, message) => res.status(200)
|
|
28
|
-
|
|
29
|
-
this.
|
|
30
|
-
.json(new actionResponseDetails_1.ActionResponseDetails(executionId, exports.StatusEnum.IN_PROGRESS, 0, message));
|
|
31
|
-
this.generateFailedResponse = (res, executionId, e) => res.status(400)
|
|
32
|
-
.json(new actionResponseDetails_1.ActionResponseDetails(executionId, exports.StatusEnum.ERROR, 0, e.message));
|
|
25
|
+
this.generateSyncSuccessMessage = (res, executionId, message) => res.status(200).json(new dto_1.ActionResponseDetails(executionId, exports.StatusEnum.COMPLETED, 1, message));
|
|
26
|
+
this.generateAsyncSuccessMessage = (res, executionId, message) => res.status(202).json(new dto_1.ActionResponseDetails(executionId, exports.StatusEnum.IN_PROGRESS, 0, message));
|
|
27
|
+
this.generateFailedResponse = (res, executionId, errorMessage) => res.status(400).json(new dto_1.ActionResponseDetails(executionId, exports.StatusEnum.ERROR, 0, errorMessage));
|
|
33
28
|
}
|
|
34
29
|
}
|
|
35
30
|
exports.ExecutionProvider = ExecutionProvider;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface ExecutionContext {
|
|
2
2
|
actionName: string;
|
|
3
3
|
executionId: string;
|
|
4
4
|
globalParams: Record<string, string>;
|
|
@@ -7,5 +7,4 @@ export declare class ExecutionContext {
|
|
|
7
7
|
bigidToken: string;
|
|
8
8
|
updateResultCallback: any;
|
|
9
9
|
tpaId: string;
|
|
10
|
-
constructor(actionName: string, executionId: string, globalParams: Record<string, string>, actionParams: Record<string, string>, bigidBaseUrl: string, bigidToken: string, updateResultCallback: any, tpaId: string);
|
|
11
10
|
}
|
|
@@ -1,16 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExecutionContext = void 0;
|
|
4
|
-
class ExecutionContext {
|
|
5
|
-
constructor(actionName, executionId, globalParams, actionParams, bigidBaseUrl, bigidToken, updateResultCallback, tpaId) {
|
|
6
|
-
this.actionName = actionName;
|
|
7
|
-
this.executionId = executionId;
|
|
8
|
-
this.globalParams = globalParams;
|
|
9
|
-
this.actionParams = actionParams;
|
|
10
|
-
this.bigidBaseUrl = bigidBaseUrl;
|
|
11
|
-
this.bigidToken = bigidToken;
|
|
12
|
-
this.updateResultCallback = updateResultCallback;
|
|
13
|
-
this.tpaId = tpaId;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.ExecutionContext = ExecutionContext;
|
package/lib/dto/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ActionResponseDetails =
|
|
4
|
-
var executionContext_1 = require("./executionContext");
|
|
5
|
-
Object.defineProperty(exports, "ExecutionContext", { enumerable: true, get: function () { return executionContext_1.ExecutionContext; } });
|
|
3
|
+
exports.ActionResponseDetails = void 0;
|
|
6
4
|
var actionResponseDetails_1 = require("./actionResponseDetails");
|
|
7
5
|
Object.defineProperty(exports, "ActionResponseDetails", { enumerable: true, get: function () { return actionResponseDetails_1.ActionResponseDetails; } });
|
package/lib/server.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ManifestProvider } from
|
|
2
|
-
import { IconsProviders } from
|
|
3
|
-
import { ExecutionProvider } from
|
|
1
|
+
import { ManifestProvider } from './abstractProviders/manifestProvider';
|
|
2
|
+
import { IconsProviders } from './abstractProviders/iconsProviders';
|
|
3
|
+
import { ExecutionProvider } from './abstractProviders/executionProvider';
|
|
4
4
|
export interface ServerInit {
|
|
5
5
|
manifestController: ManifestProvider;
|
|
6
6
|
iconsController: IconsProviders;
|
package/lib/server.js
CHANGED
|
@@ -18,7 +18,6 @@ const appLogger_1 = require("./utils/appLogger");
|
|
|
18
18
|
const executionProvider_1 = require("./abstractProviders/executionProvider");
|
|
19
19
|
const logsProvider_1 = require("./abstractProviders/logsProvider");
|
|
20
20
|
const http_errors_1 = __importDefault(require("http-errors"));
|
|
21
|
-
;
|
|
22
21
|
const app = (0, express_1.default)();
|
|
23
22
|
const deployServer = (serverInit) => {
|
|
24
23
|
app.use(express_1.default.json());
|
|
@@ -28,7 +27,7 @@ const deployServer = (serverInit) => {
|
|
|
28
27
|
app.get('/manifest', serverInit.manifestController.getManifest);
|
|
29
28
|
app.post('/execute', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, executionProvider_1.handleExecution)(req, res, serverInit.executionController); }));
|
|
30
29
|
app.get('/logs', logsProvider_1.fetchLogs);
|
|
31
|
-
app.listen(
|
|
30
|
+
app.listen(process.env.PORT || serverInit.serverPort, () => appLogger_1.appLogger.info(`Started server at port ${process.env.PORT || serverInit.serverPort}`));
|
|
32
31
|
// catch 404 and forward to error handler
|
|
33
32
|
app.use((req, res, next) => next((0, http_errors_1.default)(404)));
|
|
34
33
|
// error handler
|
|
@@ -39,9 +38,9 @@ const deployServer = (serverInit) => {
|
|
|
39
38
|
res.locals.error = req.app.get('env') === 'development' ? err : {};
|
|
40
39
|
res.status(status || 500);
|
|
41
40
|
res.json({
|
|
42
|
-
status:
|
|
41
|
+
status: 'error',
|
|
43
42
|
statusCode: status || 500,
|
|
44
|
-
message
|
|
43
|
+
message,
|
|
45
44
|
});
|
|
46
45
|
});
|
|
47
46
|
};
|
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
import { ExecutionContext } from
|
|
2
|
-
import { ActionResponseDetails } from '../dto/actionResponseDetails';
|
|
3
|
-
export declare const initBigIDProxy: (bigIdUrl: string, callBackUrl: string, bigIdToken: string, tpaId: string) => void;
|
|
1
|
+
import { ExecutionContext, ActionResponseDetails } from '../dto';
|
|
4
2
|
/**
|
|
5
3
|
* This method receives a message object to update BigID regarding the current state of the action execution
|
|
6
4
|
* (should be used in case of an async actions)
|
|
7
|
-
* @param
|
|
5
|
+
* @param executionContext
|
|
6
|
+
* @param actionResponseDetails
|
|
8
7
|
*/
|
|
9
|
-
export declare const updateActionStatusToBigID: (actionResponseDetails: ActionResponseDetails) => Promise<any>;
|
|
8
|
+
export declare const updateActionStatusToBigID: (executionContext: ExecutionContext, actionResponseDetails: ActionResponseDetails) => Promise<any>;
|
|
10
9
|
/**
|
|
11
10
|
*
|
|
11
|
+
* @param executionContext
|
|
12
12
|
* @param endpoint - the endpoint in BigID, used for GET request. e.g - {BigIDBaseUrl}/ds_connections
|
|
13
13
|
* @return - String containing the response from BigID
|
|
14
14
|
*/
|
|
15
|
-
export declare const executeHttpGet: (endpoint: string) => Promise<any>;
|
|
15
|
+
export declare const executeHttpGet: (executionContext: ExecutionContext, endpoint: string) => Promise<any>;
|
|
16
16
|
/**
|
|
17
17
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
18
18
|
*/
|
|
19
|
-
export declare const executeHttpPost: (endpoint: string, actionResponseDetails: ActionResponseDetails) => Promise<any>;
|
|
19
|
+
export declare const executeHttpPost: (executionContext: ExecutionContext, endpoint: string, actionResponseDetails: ActionResponseDetails) => Promise<any>;
|
|
20
20
|
/**
|
|
21
21
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
22
22
|
*/
|
|
23
|
-
export declare const executeHttpPut: (endpoint: string, obj: any) => Promise<any>;
|
|
24
|
-
export declare const uploadAttachment: (filePathToUpload: string) => import("axios").AxiosPromise<any>;
|
|
25
|
-
export declare const getAppStorage: () => Promise<any>;
|
|
26
|
-
export declare const getValueFromAppStorage: (key: string) => Promise<
|
|
27
|
-
export declare const saveInStorage: (keyToStore: any, valueToStore: any) => Promise<
|
|
28
|
-
export declare const setValuesForBigIDProxy: (executionContext: ExecutionContext) => void;
|
|
23
|
+
export declare const executeHttpPut: (executionContext: ExecutionContext, endpoint: string, obj: any) => Promise<any>;
|
|
24
|
+
export declare const uploadAttachment: (executionContext: ExecutionContext, filePathToUpload: string) => import("axios").AxiosPromise<any>;
|
|
25
|
+
export declare const getAppStorage: (executionContext: ExecutionContext) => Promise<any>;
|
|
26
|
+
export declare const getValueFromAppStorage: (executionContext: ExecutionContext, key: string) => Promise<string>;
|
|
27
|
+
export declare const saveInStorage: (executionContext: ExecutionContext, keyToStore: any, valueToStore: any) => Promise<void>;
|
|
@@ -12,7 +12,7 @@ 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.getValueFromAppStorage = exports.getAppStorage = exports.uploadAttachment = exports.executeHttpPut = exports.executeHttpPost = exports.executeHttpGet = exports.updateActionStatusToBigID = 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"));
|
|
@@ -25,32 +25,21 @@ const RequestMethod = {
|
|
|
25
25
|
PATCH: 'patch',
|
|
26
26
|
DELETE: 'delete',
|
|
27
27
|
};
|
|
28
|
-
|
|
29
|
-
let bigidUpdateStatusUrl;
|
|
30
|
-
let bigidToken;
|
|
31
|
-
let proxyTpaId;
|
|
32
|
-
const initBigIDProxy = (bigIdUrl, callBackUrl, bigIdToken, tpaId) => {
|
|
33
|
-
bigidUrl = bigIdUrl;
|
|
34
|
-
bigidUpdateStatusUrl = callBackUrl;
|
|
35
|
-
bigidToken = bigIdToken;
|
|
36
|
-
proxyTpaId = tpaId;
|
|
37
|
-
};
|
|
38
|
-
exports.initBigIDProxy = initBigIDProxy;
|
|
39
|
-
const doCallToUrl = (requestMethod, endpoint, bodyJson) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
const doCallToUrl = (bigidToken, requestMethod, endpoint, bodyJson) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
29
|
utils_1.appLogger.info('--> bigid-proxy::callBigIdApi: [%s] %s', requestMethod, endpoint);
|
|
41
30
|
try {
|
|
42
31
|
const headers = {
|
|
43
|
-
|
|
32
|
+
Accept: 'application/json, text/plain, */*',
|
|
44
33
|
'Content-Type': 'application/json',
|
|
45
|
-
|
|
34
|
+
Authorization: bigidToken,
|
|
46
35
|
};
|
|
47
36
|
const requestObj = {
|
|
48
37
|
method: requestMethod,
|
|
49
38
|
url: endpoint,
|
|
50
39
|
headers: headers,
|
|
51
40
|
httpsAgent: new https_1.Agent({
|
|
52
|
-
rejectUnauthorized: false
|
|
53
|
-
})
|
|
41
|
+
rejectUnauthorized: false,
|
|
42
|
+
}),
|
|
54
43
|
};
|
|
55
44
|
if (bodyJson && Object.keys(bodyJson).length > 0) {
|
|
56
45
|
requestObj.data = bodyJson;
|
|
@@ -65,71 +54,74 @@ const doCallToUrl = (requestMethod, endpoint, bodyJson) => __awaiter(void 0, voi
|
|
|
65
54
|
return error === null || error === void 0 ? void 0 : error.message;
|
|
66
55
|
}
|
|
67
56
|
});
|
|
68
|
-
function callBigIdApi(requestMethod, endpoint, bodyJson, useEndpointWithoutBigIdBasePath) {
|
|
57
|
+
function callBigIdApi(executionContext, requestMethod, endpoint, bodyJson, useEndpointWithoutBigIdBasePath) {
|
|
69
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
const url = useEndpointWithoutBigIdBasePath ? endpoint :
|
|
71
|
-
return yield doCallToUrl(requestMethod, url, bodyJson);
|
|
59
|
+
const url = useEndpointWithoutBigIdBasePath ? endpoint : executionContext.bigidBaseUrl + endpoint;
|
|
60
|
+
return yield doCallToUrl(executionContext.bigidToken, requestMethod, url, bodyJson);
|
|
72
61
|
});
|
|
73
62
|
}
|
|
74
63
|
/**
|
|
75
64
|
* This method receives a message object to update BigID regarding the current state of the action execution
|
|
76
65
|
* (should be used in case of an async actions)
|
|
77
|
-
* @param
|
|
66
|
+
* @param executionContext
|
|
67
|
+
* @param actionResponseDetails
|
|
78
68
|
*/
|
|
79
|
-
const updateActionStatusToBigID = (actionResponseDetails) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
-
return yield callBigIdApi(RequestMethod.PUT,
|
|
69
|
+
const updateActionStatusToBigID = (executionContext, actionResponseDetails) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
return yield callBigIdApi(executionContext, RequestMethod.PUT, executionContext.updateResultCallback, actionResponseDetails, true);
|
|
81
71
|
});
|
|
82
72
|
exports.updateActionStatusToBigID = updateActionStatusToBigID;
|
|
83
73
|
/**
|
|
84
74
|
*
|
|
75
|
+
* @param executionContext
|
|
85
76
|
* @param endpoint - the endpoint in BigID, used for GET request. e.g - {BigIDBaseUrl}/ds_connections
|
|
86
77
|
* @return - String containing the response from BigID
|
|
87
78
|
*/
|
|
88
|
-
const executeHttpGet = (endpoint) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(RequestMethod.GET, endpoint); });
|
|
79
|
+
const executeHttpGet = (executionContext, endpoint) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.GET, endpoint); });
|
|
89
80
|
exports.executeHttpGet = executeHttpGet;
|
|
90
81
|
/**
|
|
91
82
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
92
83
|
*/
|
|
93
|
-
const executeHttpPost = (endpoint, actionResponseDetails) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(RequestMethod.POST, endpoint, actionResponseDetails); });
|
|
84
|
+
const executeHttpPost = (executionContext, endpoint, actionResponseDetails) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.POST, endpoint, actionResponseDetails); });
|
|
94
85
|
exports.executeHttpPost = executeHttpPost;
|
|
95
86
|
/**
|
|
96
87
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
97
88
|
*/
|
|
98
|
-
const executeHttpPut = (endpoint, obj) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(RequestMethod.PUT, endpoint, obj); });
|
|
89
|
+
const executeHttpPut = (executionContext, endpoint, obj) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.PUT, endpoint, obj); });
|
|
99
90
|
exports.executeHttpPut = executeHttpPut;
|
|
100
|
-
const uploadAttachment = (filePathToUpload) => {
|
|
91
|
+
const uploadAttachment = (executionContext, filePathToUpload) => {
|
|
101
92
|
const formData = new form_data_1.default();
|
|
102
93
|
formData.append('file', (0, fs_1.createReadStream)(filePathToUpload));
|
|
103
94
|
const headers = {
|
|
104
95
|
'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`,
|
|
105
|
-
|
|
96
|
+
Authorization: executionContext.bigidToken,
|
|
106
97
|
};
|
|
107
98
|
const requestObj = {
|
|
108
99
|
method: RequestMethod.POST,
|
|
109
|
-
url: `${
|
|
100
|
+
url: `${executionContext.updateResultCallback}/attachment`,
|
|
110
101
|
headers: headers,
|
|
111
102
|
httpsAgent: new https_1.Agent({
|
|
112
|
-
rejectUnauthorized: false
|
|
113
|
-
})
|
|
103
|
+
rejectUnauthorized: false,
|
|
104
|
+
}),
|
|
114
105
|
};
|
|
115
106
|
requestObj.data = formData;
|
|
116
107
|
return (0, axios_1.default)(requestObj);
|
|
117
108
|
};
|
|
118
109
|
exports.uploadAttachment = uploadAttachment;
|
|
119
|
-
const getAppStorage = () => (0, exports.executeHttpGet)(`tpa/${
|
|
110
|
+
const getAppStorage = (executionContext) => (0, exports.executeHttpGet)(executionContext, `tpa/${executionContext.tpaId}/storage`);
|
|
120
111
|
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 ===
|
|
112
|
+
const getValueFromAppStorage = (executionContext, key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
const { data } = yield (0, exports.executeHttpGet)(executionContext, `tpa/${executionContext.tpaId}/storage/key/${key}`);
|
|
114
|
+
return data === 'Key not found' ? null : data.value;
|
|
124
115
|
});
|
|
125
116
|
exports.getValueFromAppStorage = getValueFromAppStorage;
|
|
126
|
-
const saveInStorage = (keyToStore, valueToStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
const saveInStorage = (executionContext, keyToStore, valueToStore) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
return yield (0, exports.executeHttpPut)(executionContext, `/tpa/${executionContext.tpaId}/storage`, {
|
|
119
|
+
keysValues: [
|
|
120
|
+
{
|
|
121
|
+
key: keyToStore,
|
|
122
|
+
value: valueToStore,
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
127
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Request, Response } from 'express';
|
|
2
|
-
import { ActionResponseDetails } from '../dto
|
|
3
|
-
import { setValuesForBigIDProxy } from '../services';
|
|
2
|
+
import { ActionResponseDetails, ExecutionContext } from '../dto';
|
|
4
3
|
|
|
5
4
|
export const StatusEnum = {
|
|
6
5
|
COMPLETED: 'COMPLETED',
|
|
@@ -9,12 +8,11 @@ export const StatusEnum = {
|
|
|
9
8
|
};
|
|
10
9
|
|
|
11
10
|
export const handleExecution = async (req: Request, res: Response, executionProvider: ExecutionProvider) => {
|
|
12
|
-
|
|
13
|
-
await executionProvider.executeAction(req, res);
|
|
11
|
+
await executionProvider.executeAction(req.body, res);
|
|
14
12
|
};
|
|
15
13
|
|
|
16
14
|
export abstract class ExecutionProvider {
|
|
17
|
-
public abstract executeAction(
|
|
15
|
+
public abstract executeAction(executionContext: ExecutionContext, res: Response): Promise<void>;
|
|
18
16
|
|
|
19
17
|
generateSyncSuccessMessage = (res: Response, executionId: string, message: string) =>
|
|
20
18
|
res.status(200).json(new ActionResponseDetails(executionId, StatusEnum.COMPLETED, 1, message));
|
|
@@ -22,6 +20,6 @@ export abstract class ExecutionProvider {
|
|
|
22
20
|
generateAsyncSuccessMessage = (res: Response, executionId: string, message: string) =>
|
|
23
21
|
res.status(202).json(new ActionResponseDetails(executionId, StatusEnum.IN_PROGRESS, 0, message));
|
|
24
22
|
|
|
25
|
-
generateFailedResponse = (res: Response, executionId: string,
|
|
26
|
-
res.status(400).json(new ActionResponseDetails(executionId, StatusEnum.ERROR, 0,
|
|
23
|
+
generateFailedResponse = (res: Response, executionId: string, errorMessage: string) =>
|
|
24
|
+
res.status(400).json(new ActionResponseDetails(executionId, StatusEnum.ERROR, 0, errorMessage));
|
|
27
25
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface ExecutionContext {
|
|
2
2
|
actionName: string;
|
|
3
3
|
executionId: string;
|
|
4
4
|
globalParams: Record<string, string>;
|
|
@@ -7,24 +7,4 @@ export class ExecutionContext {
|
|
|
7
7
|
bigidToken: string;
|
|
8
8
|
updateResultCallback: any;
|
|
9
9
|
tpaId: string;
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
12
|
-
actionName: string,
|
|
13
|
-
executionId: string,
|
|
14
|
-
globalParams: Record<string, string>,
|
|
15
|
-
actionParams: Record<string, string>,
|
|
16
|
-
bigidBaseUrl: string,
|
|
17
|
-
bigidToken: string,
|
|
18
|
-
updateResultCallback: any,
|
|
19
|
-
tpaId: string,
|
|
20
|
-
) {
|
|
21
|
-
this.actionName = actionName;
|
|
22
|
-
this.executionId = executionId;
|
|
23
|
-
this.globalParams = globalParams;
|
|
24
|
-
this.actionParams = actionParams;
|
|
25
|
-
this.bigidBaseUrl = bigidBaseUrl;
|
|
26
|
-
this.bigidToken = bigidToken;
|
|
27
|
-
this.updateResultCallback = updateResultCallback;
|
|
28
|
-
this.tpaId = tpaId;
|
|
29
|
-
}
|
|
30
10
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createReadStream } from 'fs';
|
|
2
2
|
import { Agent } from 'https';
|
|
3
|
-
import { ExecutionContext } from '../dto';
|
|
3
|
+
import { ExecutionContext, ActionResponseDetails } from '../dto';
|
|
4
4
|
import FormData from 'form-data';
|
|
5
5
|
|
|
6
6
|
import axios from 'axios';
|
|
7
|
-
import { ActionResponseDetails } from '../dto/actionResponseDetails';
|
|
8
7
|
import { appLogger } from '../utils';
|
|
9
8
|
|
|
10
9
|
const RequestMethod = {
|
|
@@ -15,19 +14,12 @@ const RequestMethod = {
|
|
|
15
14
|
DELETE: 'delete',
|
|
16
15
|
};
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
bigidUrl = bigIdUrl;
|
|
25
|
-
bigidUpdateStatusUrl = callBackUrl;
|
|
26
|
-
bigidToken = bigIdToken;
|
|
27
|
-
proxyTpaId = tpaId;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const doCallToUrl = async (requestMethod: string, endpoint: string, bodyJson?: ActionResponseDetails) => {
|
|
17
|
+
const doCallToUrl = async (
|
|
18
|
+
bigidToken: string,
|
|
19
|
+
requestMethod: string,
|
|
20
|
+
endpoint: string,
|
|
21
|
+
bodyJson?: ActionResponseDetails,
|
|
22
|
+
) => {
|
|
31
23
|
appLogger.info('--> bigid-proxy::callBigIdApi: [%s] %s', requestMethod, endpoint);
|
|
32
24
|
try {
|
|
33
25
|
const headers = {
|
|
@@ -61,53 +53,69 @@ const doCallToUrl = async (requestMethod: string, endpoint: string, bodyJson?: A
|
|
|
61
53
|
};
|
|
62
54
|
|
|
63
55
|
async function callBigIdApi(
|
|
56
|
+
executionContext: ExecutionContext,
|
|
64
57
|
requestMethod: string,
|
|
65
58
|
endpoint: string,
|
|
66
59
|
bodyJson?: ActionResponseDetails,
|
|
67
60
|
useEndpointWithoutBigIdBasePath?: boolean,
|
|
68
61
|
) {
|
|
69
|
-
const url = useEndpointWithoutBigIdBasePath ? endpoint :
|
|
70
|
-
return await doCallToUrl(requestMethod, url, bodyJson);
|
|
62
|
+
const url = useEndpointWithoutBigIdBasePath ? endpoint : executionContext.bigidBaseUrl + endpoint;
|
|
63
|
+
return await doCallToUrl(executionContext.bigidToken, requestMethod, url, bodyJson);
|
|
71
64
|
}
|
|
72
65
|
|
|
73
66
|
/**
|
|
74
67
|
* This method receives a message object to update BigID regarding the current state of the action execution
|
|
75
68
|
* (should be used in case of an async actions)
|
|
76
|
-
* @param
|
|
69
|
+
* @param executionContext
|
|
70
|
+
* @param actionResponseDetails
|
|
77
71
|
*/
|
|
78
|
-
export const updateActionStatusToBigID = async (
|
|
79
|
-
|
|
72
|
+
export const updateActionStatusToBigID = async (
|
|
73
|
+
executionContext: ExecutionContext,
|
|
74
|
+
actionResponseDetails: ActionResponseDetails,
|
|
75
|
+
) =>
|
|
76
|
+
await callBigIdApi(
|
|
77
|
+
executionContext,
|
|
78
|
+
RequestMethod.PUT,
|
|
79
|
+
executionContext.updateResultCallback,
|
|
80
|
+
actionResponseDetails,
|
|
81
|
+
true,
|
|
82
|
+
);
|
|
80
83
|
|
|
81
84
|
/**
|
|
82
85
|
*
|
|
86
|
+
* @param executionContext
|
|
83
87
|
* @param endpoint - the endpoint in BigID, used for GET request. e.g - {BigIDBaseUrl}/ds_connections
|
|
84
88
|
* @return - String containing the response from BigID
|
|
85
89
|
*/
|
|
86
|
-
export const executeHttpGet = async (endpoint: string) =>
|
|
90
|
+
export const executeHttpGet = async (executionContext: ExecutionContext, endpoint: string) =>
|
|
91
|
+
await callBigIdApi(executionContext, RequestMethod.GET, endpoint);
|
|
87
92
|
|
|
88
93
|
/**
|
|
89
94
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
90
95
|
*/
|
|
91
|
-
export const executeHttpPost = async (
|
|
92
|
-
|
|
96
|
+
export const executeHttpPost = async (
|
|
97
|
+
executionContext: ExecutionContext,
|
|
98
|
+
endpoint: string,
|
|
99
|
+
actionResponseDetails: ActionResponseDetails,
|
|
100
|
+
) => await callBigIdApi(executionContext, RequestMethod.POST, endpoint, actionResponseDetails);
|
|
93
101
|
|
|
94
102
|
/**
|
|
95
103
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
96
104
|
*/
|
|
97
|
-
export const executeHttpPut = async (endpoint: string, obj: any) =>
|
|
98
|
-
await callBigIdApi(RequestMethod.PUT, endpoint, obj);
|
|
105
|
+
export const executeHttpPut = async (executionContext: ExecutionContext, endpoint: string, obj: any) =>
|
|
106
|
+
await callBigIdApi(executionContext, RequestMethod.PUT, endpoint, obj);
|
|
99
107
|
|
|
100
|
-
export const uploadAttachment = (filePathToUpload: string) => {
|
|
108
|
+
export const uploadAttachment = (executionContext: ExecutionContext, filePathToUpload: string) => {
|
|
101
109
|
const formData = new FormData();
|
|
102
110
|
formData.append('file', createReadStream(filePathToUpload));
|
|
103
111
|
|
|
104
112
|
const headers = {
|
|
105
113
|
'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`,
|
|
106
|
-
Authorization: bigidToken,
|
|
114
|
+
Authorization: executionContext.bigidToken,
|
|
107
115
|
};
|
|
108
116
|
const requestObj: Record<string, any> = {
|
|
109
117
|
method: RequestMethod.POST,
|
|
110
|
-
url: `${
|
|
118
|
+
url: `${executionContext.updateResultCallback}/attachment`,
|
|
111
119
|
headers: headers,
|
|
112
120
|
httpsAgent: new Agent({
|
|
113
121
|
rejectUnauthorized: false,
|
|
@@ -117,15 +125,20 @@ export const uploadAttachment = (filePathToUpload: string) => {
|
|
|
117
125
|
return axios(requestObj);
|
|
118
126
|
};
|
|
119
127
|
|
|
120
|
-
export const getAppStorage = () =>
|
|
128
|
+
export const getAppStorage = (executionContext: ExecutionContext) =>
|
|
129
|
+
executeHttpGet(executionContext, `tpa/${executionContext.tpaId}/storage`);
|
|
121
130
|
|
|
122
|
-
export const getValueFromAppStorage = async (key: string) => {
|
|
123
|
-
const { data } = await executeHttpGet(`tpa/${
|
|
131
|
+
export const getValueFromAppStorage = async (executionContext: ExecutionContext, key: string): Promise<string> => {
|
|
132
|
+
const { data } = await executeHttpGet(executionContext, `tpa/${executionContext.tpaId}/storage/key/${key}`);
|
|
124
133
|
return data === 'Key not found' ? null : data.value;
|
|
125
134
|
};
|
|
126
135
|
|
|
127
|
-
export const saveInStorage = async (
|
|
128
|
-
|
|
136
|
+
export const saveInStorage = async (
|
|
137
|
+
executionContext: ExecutionContext,
|
|
138
|
+
keyToStore: any,
|
|
139
|
+
valueToStore: any,
|
|
140
|
+
): Promise<void> =>
|
|
141
|
+
await executeHttpPut(executionContext, `/tpa/${executionContext.tpaId}/storage`, {
|
|
129
142
|
keysValues: [
|
|
130
143
|
{
|
|
131
144
|
key: keyToStore,
|
|
@@ -133,18 +146,3 @@ export const saveInStorage = async (keyToStore: any, valueToStore: any) =>
|
|
|
133
146
|
},
|
|
134
147
|
],
|
|
135
148
|
});
|
|
136
|
-
|
|
137
|
-
export const setValuesForBigIDProxy = (executionContext: ExecutionContext) => {
|
|
138
|
-
if (!executionContext.bigidBaseUrl || !executionContext.bigidToken) {
|
|
139
|
-
appLogger.error(
|
|
140
|
-
`Missing bigidUrl and/or bigidToken. bigidUrl=${executionContext.bigidBaseUrl}, bigidToken=${executionContext.bigidToken}`,
|
|
141
|
-
);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
initBigIDProxy(
|
|
145
|
-
executionContext.bigidBaseUrl,
|
|
146
|
-
executionContext.updateResultCallback,
|
|
147
|
-
executionContext.bigidToken,
|
|
148
|
-
executionContext.tpaId,
|
|
149
|
-
);
|
|
150
|
-
};
|
package/lib/appTypes/index.d.ts
DELETED
package/lib/appTypes/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
class KeysValuesToStore {
|
|
3
|
-
constructor(key, paramValue) {
|
|
4
|
-
this.keysValues = [];
|
|
5
|
-
this.addKeyValue(key, paramValue);
|
|
6
|
-
}
|
|
7
|
-
addKeyValue(key, value) {
|
|
8
|
-
this.keysValues.push(new KeyValue(key, value));
|
|
9
|
-
}
|
|
10
|
-
getValue(key) {
|
|
11
|
-
for (const keyValue of keysValues) {
|
|
12
|
-
if (keyValue.key === key) {
|
|
13
|
-
return keyValue.value;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return '';
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
module.exports = KeysValuesToStore;
|
package/lib/routes/router.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const router: () => Promise<void>;
|
package/lib/routes/router.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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.router = void 0;
|
|
13
|
-
const router = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
-
});
|
|
15
|
-
exports.router = router;
|