@bigid/apps-infrastructure-node-js 1.218.1 → 1.226.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/README.md +0 -3
- package/lib/services/actionsHubService.d.ts +2 -1
- package/lib/services/actionsHubService.js +4 -2
- package/lib/services/bigidProxyService.d.ts +7 -7
- package/lib/services/bigidProxyService.js +15 -19
- package/log/app.log +8 -0
- package/package.json +6 -2
- package/src/services/actionsHubService.ts +3 -0
- package/src/services/bigidProxyService.ts +49 -20
- package/test/mock.ts +31 -0
- package/test/unit/api/requests.spec.ts +44 -0
package/README.md
CHANGED
|
@@ -32,9 +32,6 @@ BIGID_REFRESH_TOKEN - refresh token that will be used to execute api calls
|
|
|
32
32
|
|
|
33
33
|
###Multi tenant mode
|
|
34
34
|
BIGID_BASE_URL - bigid url
|
|
35
|
-
|
|
36
35
|
AUTH0_DOMAIN - auth0 domain where the application configured - will be provided by BigID's application framework team
|
|
37
|
-
|
|
38
36
|
CLIENT_ID - client id of the application in auth0 - will be provided by BigID's application framework team
|
|
39
|
-
|
|
40
37
|
CLIENT_SECRET - client secret of the application - will be provided by BigID's application framework team
|
|
@@ -22,13 +22,14 @@ export declare const getCommandsRegistrations: (accessToken?: string) => Promise
|
|
|
22
22
|
*
|
|
23
23
|
* @param {string} actionName - the action name to be executed.
|
|
24
24
|
* @param {string} command - the command to be executed.
|
|
25
|
+
* @param {string} applicationName - the application name that the command to be triggered belongs to
|
|
25
26
|
* @param {string} requestorAppName - the app name of the execution requestor.
|
|
26
27
|
* @param {string} webhookEndpoint - the endpoint of the requestor app to receive execution status messages.
|
|
27
28
|
* @param {Record<string, any>} params - the relevant params of the action to be executed.
|
|
28
29
|
* @param {string} accessToken -- the access token from BigId.
|
|
29
30
|
* @return {Promise<string>} execution id of the executed action.
|
|
30
31
|
*/
|
|
31
|
-
export declare const executeCommand: (actionName: string, command: string, requestorAppName?: string, webhookEndpoint?: string, params?: Record<string, any>[], accessToken?: string) => Promise<string>;
|
|
32
|
+
export declare const executeCommand: (actionName: string, command: string, applicationName?: string, requestorAppName?: string, webhookEndpoint?: string, params?: Record<string, any>[], accessToken?: string) => Promise<string>;
|
|
32
33
|
/**
|
|
33
34
|
* use this method to poll an execution status from the action-center.
|
|
34
35
|
*
|
|
@@ -36,17 +36,19 @@ exports.getCommandsRegistrations = getCommandsRegistrations;
|
|
|
36
36
|
*
|
|
37
37
|
* @param {string} actionName - the action name to be executed.
|
|
38
38
|
* @param {string} command - the command to be executed.
|
|
39
|
+
* @param {string} applicationName - the application name that the command to be triggered belongs to
|
|
39
40
|
* @param {string} requestorAppName - the app name of the execution requestor.
|
|
40
41
|
* @param {string} webhookEndpoint - the endpoint of the requestor app to receive execution status messages.
|
|
41
42
|
* @param {Record<string, any>} params - the relevant params of the action to be executed.
|
|
42
43
|
* @param {string} accessToken -- the access token from BigId.
|
|
43
44
|
* @return {Promise<string>} execution id of the executed action.
|
|
44
45
|
*/
|
|
45
|
-
const executeCommand = (actionName, command, requestorAppName, webhookEndpoint, params, accessToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const executeCommand = (actionName, command, applicationName, requestorAppName, webhookEndpoint, params, accessToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
47
|
try {
|
|
47
48
|
const bigidToken = accessToken || (yield (0, tokenUtil_1.getBigidAccessToken)());
|
|
48
49
|
const { data: { executionId }, } = yield (0, bigidProxyService_1.doCallToUrl)(bigidToken, bigidProxyService_1.RequestMethod.POST, `${process.env.BIGID_BASE_URL}/api/v1/action-center/general-commands/execute`, Object.assign({ actionName,
|
|
49
|
-
command,
|
|
50
|
+
command,
|
|
51
|
+
applicationName, feedbackRequestorDetails: requestorAppName && webhookEndpoint
|
|
50
52
|
? {
|
|
51
53
|
requestorAppName,
|
|
52
54
|
requestorFeedbackEndpoint: webhookEndpoint,
|
|
@@ -8,7 +8,7 @@ export declare enum RequestMethod {
|
|
|
8
8
|
DELETE = "delete"
|
|
9
9
|
}
|
|
10
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>;
|
|
11
|
+
export declare const doCallToUrl: (bigidToken: string, requestMethod: RequestMethod, endpoint: string, bodyJson?: Record<string, any>, additionalHeaderFields?: Record<string, any>) => Promise<any>;
|
|
12
12
|
/**
|
|
13
13
|
* This method receives a message object to update BigID regarding the current state of the action execution
|
|
14
14
|
* (should be used in case of an async actions)
|
|
@@ -22,23 +22,23 @@ export declare const updateActionStatusToBigID: (executionContext: ExecutionCont
|
|
|
22
22
|
* @param endpoint - the endpoint in BigID, used for GET request. e.g - {BigIDBaseUrl}/ds_connections
|
|
23
23
|
* @return - String containing the response from BigID
|
|
24
24
|
*/
|
|
25
|
-
export declare const executeHttpGet: (executionContext: ExecutionContext, endpoint: string) => Promise<any>;
|
|
25
|
+
export declare const executeHttpGet: (executionContext: ExecutionContext, endpoint: string, additionalHeaderFields?: Record<string, any>) => Promise<any>;
|
|
26
26
|
/**
|
|
27
27
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
28
28
|
*/
|
|
29
|
-
export declare const executeHttpPost: (executionContext: ExecutionContext, endpoint: string, obj: any) => Promise<any>;
|
|
29
|
+
export declare const executeHttpPost: (executionContext: ExecutionContext, endpoint: string, obj: any, additionalHeaderFields?: Record<string, any>) => Promise<any>;
|
|
30
30
|
/**
|
|
31
31
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
32
32
|
*/
|
|
33
|
-
export declare const executeHttpPut: (executionContext: ExecutionContext, endpoint: string, obj: any) => Promise<any>;
|
|
33
|
+
export declare const executeHttpPut: (executionContext: ExecutionContext, endpoint: string, obj: any, additionalHeaderFields?: Record<string, any>) => Promise<any>;
|
|
34
34
|
/**
|
|
35
35
|
* the endpoint in BigID, used for DELETE requests.
|
|
36
36
|
*/
|
|
37
|
-
export declare const executeHttpDelete: (executionContext: ExecutionContext, endpoint: string) => Promise<any>;
|
|
38
|
-
export declare const executePost: (requestMethod: RequestMethod, baseUrl: string | undefined, bodyJson: Record<string, any>) => Promise<any>;
|
|
37
|
+
export declare const executeHttpDelete: (executionContext: ExecutionContext, endpoint: string, additionalHeaderFields?: Record<string, any>) => Promise<any>;
|
|
38
|
+
export declare const executePost: (requestMethod: RequestMethod, baseUrl: string | undefined, bodyJson: Record<string, any>, additionalHeaderFields?: Record<string, any>) => Promise<any>;
|
|
39
39
|
export declare const uploadAttachment: (executionContext: ExecutionContext, filePathToUpload: string) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
40
40
|
export declare const getAppStorage: (executionContext: ExecutionContext) => Promise<any>;
|
|
41
|
-
export declare const getValueFromAppStorage: (executionContext: ExecutionContext, key: string) => Promise<string>;
|
|
41
|
+
export declare const getValueFromAppStorage: (executionContext: ExecutionContext, key: string) => Promise<string | null>;
|
|
42
42
|
export declare const deleteKeyFromAppStorage: (executionContext: ExecutionContext, key: string) => Promise<void>;
|
|
43
43
|
export declare const sendBiEvent: (executionContext: ExecutionContext, eventType: string, data: Object) => Promise<any>;
|
|
44
44
|
export declare const saveInStorage: (executionContext: ExecutionContext, keyToStore: any, valueToStore: any) => Promise<void>;
|
|
@@ -31,14 +31,10 @@ const getTenantRegistrations = (bigidToken) => __awaiter(void 0, void 0, void 0,
|
|
|
31
31
|
return tenants;
|
|
32
32
|
});
|
|
33
33
|
exports.getTenantRegistrations = getTenantRegistrations;
|
|
34
|
-
const doCallToUrl = (bigidToken, requestMethod, endpoint, bodyJson) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const doCallToUrl = (bigidToken, requestMethod, endpoint, bodyJson, additionalHeaderFields) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
35
|
(0, utils_1.logInfo)(`--> bigid-proxy::callBigIdApi: [${requestMethod}] endpoint: ${endpoint}`);
|
|
36
36
|
try {
|
|
37
|
-
const headers = {
|
|
38
|
-
Accept: 'application/json, text/plain, */*',
|
|
39
|
-
'Content-Type': 'application/json',
|
|
40
|
-
Authorization: bigidToken,
|
|
41
|
-
};
|
|
37
|
+
const headers = Object.assign({ Accept: 'application/json, text/plain, */*', 'Content-Type': 'application/json', Authorization: bigidToken }, (additionalHeaderFields || {}));
|
|
42
38
|
const parsedUrl = new URL(endpoint);
|
|
43
39
|
parsedUrl.pathname = parsedUrl.pathname.replace(/\/+/g, '/');
|
|
44
40
|
const requestObj = {
|
|
@@ -63,10 +59,10 @@ const doCallToUrl = (bigidToken, requestMethod, endpoint, bodyJson) => __awaiter
|
|
|
63
59
|
}
|
|
64
60
|
});
|
|
65
61
|
exports.doCallToUrl = doCallToUrl;
|
|
66
|
-
function callBigIdApi(executionContext, requestMethod, endpoint,
|
|
62
|
+
function callBigIdApi(executionContext, requestMethod, endpoint, options) {
|
|
67
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
const url = useEndpointWithoutBigIdBasePath ? endpoint : executionContext.bigidBaseUrl + endpoint;
|
|
69
|
-
return yield (0, exports.doCallToUrl)(executionContext.bigidToken, requestMethod, url, bodyJson);
|
|
64
|
+
const url = (options === null || options === void 0 ? void 0 : options.useEndpointWithoutBigIdBasePath) ? endpoint : executionContext.bigidBaseUrl + endpoint;
|
|
65
|
+
return yield (0, exports.doCallToUrl)(executionContext.bigidToken, requestMethod, url, options === null || options === void 0 ? void 0 : options.bodyJson, options === null || options === void 0 ? void 0 : options.additionalHeaderFields);
|
|
70
66
|
});
|
|
71
67
|
}
|
|
72
68
|
/**
|
|
@@ -76,7 +72,10 @@ function callBigIdApi(executionContext, requestMethod, endpoint, bodyJson, useEn
|
|
|
76
72
|
* @param actionResponseDetails
|
|
77
73
|
*/
|
|
78
74
|
const updateActionStatusToBigID = (executionContext, actionResponseDetails) => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
-
return yield callBigIdApi(executionContext, RequestMethod.PUT, executionContext.updateResultCallback,
|
|
75
|
+
return yield callBigIdApi(executionContext, RequestMethod.PUT, executionContext.updateResultCallback, {
|
|
76
|
+
bodyJson: actionResponseDetails,
|
|
77
|
+
useEndpointWithoutBigIdBasePath: true,
|
|
78
|
+
});
|
|
80
79
|
});
|
|
81
80
|
exports.updateActionStatusToBigID = updateActionStatusToBigID;
|
|
82
81
|
/**
|
|
@@ -85,31 +84,28 @@ exports.updateActionStatusToBigID = updateActionStatusToBigID;
|
|
|
85
84
|
* @param endpoint - the endpoint in BigID, used for GET request. e.g - {BigIDBaseUrl}/ds_connections
|
|
86
85
|
* @return - String containing the response from BigID
|
|
87
86
|
*/
|
|
88
|
-
const executeHttpGet = (executionContext, endpoint) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.GET, endpoint); });
|
|
87
|
+
const executeHttpGet = (executionContext, endpoint, additionalHeaderFields) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.GET, endpoint, { additionalHeaderFields }); });
|
|
89
88
|
exports.executeHttpGet = executeHttpGet;
|
|
90
89
|
/**
|
|
91
90
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
92
91
|
*/
|
|
93
|
-
const executeHttpPost = (executionContext, endpoint, obj) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.POST, endpoint, obj); });
|
|
92
|
+
const executeHttpPost = (executionContext, endpoint, obj, additionalHeaderFields) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.POST, endpoint, { bodyJson: obj, additionalHeaderFields }); });
|
|
94
93
|
exports.executeHttpPost = executeHttpPost;
|
|
95
94
|
/**
|
|
96
95
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
97
96
|
*/
|
|
98
|
-
const executeHttpPut = (executionContext, endpoint, obj) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.PUT, endpoint, obj); });
|
|
97
|
+
const executeHttpPut = (executionContext, endpoint, obj, additionalHeaderFields) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.PUT, endpoint, { bodyJson: obj, additionalHeaderFields }); });
|
|
99
98
|
exports.executeHttpPut = executeHttpPut;
|
|
100
99
|
/**
|
|
101
100
|
* the endpoint in BigID, used for DELETE requests.
|
|
102
101
|
*/
|
|
103
|
-
const executeHttpDelete = (executionContext, endpoint) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.DELETE, endpoint); });
|
|
102
|
+
const executeHttpDelete = (executionContext, endpoint, additionalHeaderFields) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.DELETE, endpoint, { additionalHeaderFields }); });
|
|
104
103
|
exports.executeHttpDelete = executeHttpDelete;
|
|
105
|
-
const executePost = (requestMethod, baseUrl, bodyJson) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
const executePost = (requestMethod, baseUrl, bodyJson, additionalHeaderFields) => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
105
|
var _a, _b, _c, _d, _e, _f;
|
|
107
106
|
try {
|
|
108
107
|
const url = baseUrl + 'api/v1/sessions';
|
|
109
|
-
const headers = {
|
|
110
|
-
Accept: 'application/json',
|
|
111
|
-
'Content-type': 'application/json',
|
|
112
|
-
};
|
|
108
|
+
const headers = Object.assign({ Accept: 'application/json', 'Content-type': 'application/json' }, (additionalHeaderFields || {}));
|
|
113
109
|
const requestObj = {
|
|
114
110
|
method: requestMethod,
|
|
115
111
|
url: url,
|
package/log/app.log
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
[2025-04-23T11:04:36.805] [INFO] default - --> bigid-proxy::callBigIdApi: [get] endpoint: https://bigid-ui:9090/api/v1/id_connections
|
|
2
|
+
[2025-04-23T11:04:36.819] [INFO] default - <-- bigid-proxy::callBigIdApi: https://bigid-ui:9090/api/v1/id_connections success
|
|
3
|
+
[2025-04-23T11:04:36.822] [INFO] default - --> bigid-proxy::callBigIdApi: [post] endpoint: https://bigid-ui:9090/api/v1/id_connections
|
|
4
|
+
[2025-04-23T11:04:36.826] [INFO] default - <-- bigid-proxy::callBigIdApi: https://bigid-ui:9090/api/v1/id_connections success
|
|
5
|
+
[2025-04-23T11:04:36.827] [INFO] default - --> bigid-proxy::callBigIdApi: [put] endpoint: https://bigid-ui:9090/api/v1/id_connections
|
|
6
|
+
[2025-04-23T11:04:36.831] [INFO] default - <-- bigid-proxy::callBigIdApi: https://bigid-ui:9090/api/v1/id_connections success
|
|
7
|
+
[2025-04-23T11:04:36.832] [INFO] default - --> bigid-proxy::callBigIdApi: [delete] endpoint: https://bigid-ui:9090/api/v1/id_connections
|
|
8
|
+
[2025-04-23T11:04:36.834] [INFO] default - <-- bigid-proxy::callBigIdApi: https://bigid-ui:9090/api/v1/id_connections success
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigid/apps-infrastructure-node-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.226.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"docs": "npx tsc && ./node_modules/.bin/jsdoc -c jsdoc.json",
|
|
8
|
-
"test": "mocha 'test/**/*.ts'"
|
|
8
|
+
"test": "mocha --require ts-node/register --require source-map-support/register 'test/**/*.ts'"
|
|
9
9
|
},
|
|
10
10
|
"types": "lib/index.d.ts",
|
|
11
11
|
"repository": {
|
|
@@ -15,18 +15,22 @@
|
|
|
15
15
|
"author": "Shay Sheli",
|
|
16
16
|
"homepage": "https://github.com/bigexchange/apps-infrastructure-node-js#readme",
|
|
17
17
|
"devDependencies": {
|
|
18
|
+
"@types/chai": "^4.3.20",
|
|
18
19
|
"@types/express": "^4.17.13",
|
|
19
20
|
"@types/http-errors": "^1.8.1",
|
|
20
21
|
"@types/mocha": "10.0.3",
|
|
22
|
+
"@types/nock": "^11.1.0",
|
|
21
23
|
"@types/node": "^16.11.10",
|
|
22
24
|
"@types/node-schedule": "^2.1.0",
|
|
23
25
|
"@typescript-eslint/eslint-plugin": "4.6.1",
|
|
24
26
|
"@typescript-eslint/parser": "4.6.1",
|
|
27
|
+
"chai": "4.5.0",
|
|
25
28
|
"eslint": "7.12.1",
|
|
26
29
|
"eslint-config-prettier": "^6.15.0",
|
|
27
30
|
"eslint-plugin-no-only-tests": "2.4.0",
|
|
28
31
|
"eslint-plugin-prettier": "^3.1.4",
|
|
29
32
|
"jsdoc": "4.0.2",
|
|
33
|
+
"nock": "^13.5.6",
|
|
30
34
|
"prettier": "^2.4.1",
|
|
31
35
|
"typescript": "^4.5.2"
|
|
32
36
|
},
|
|
@@ -42,6 +42,7 @@ export const getCommandsRegistrations = async (accessToken?: string): Promise<Co
|
|
|
42
42
|
*
|
|
43
43
|
* @param {string} actionName - the action name to be executed.
|
|
44
44
|
* @param {string} command - the command to be executed.
|
|
45
|
+
* @param {string} applicationName - the application name that the command to be triggered belongs to
|
|
45
46
|
* @param {string} requestorAppName - the app name of the execution requestor.
|
|
46
47
|
* @param {string} webhookEndpoint - the endpoint of the requestor app to receive execution status messages.
|
|
47
48
|
* @param {Record<string, any>} params - the relevant params of the action to be executed.
|
|
@@ -51,6 +52,7 @@ export const getCommandsRegistrations = async (accessToken?: string): Promise<Co
|
|
|
51
52
|
export const executeCommand = async (
|
|
52
53
|
actionName: string,
|
|
53
54
|
command: string,
|
|
55
|
+
applicationName?: string,
|
|
54
56
|
requestorAppName?: string,
|
|
55
57
|
webhookEndpoint?: string,
|
|
56
58
|
params?: Record<string, any>[],
|
|
@@ -67,6 +69,7 @@ export const executeCommand = async (
|
|
|
67
69
|
{
|
|
68
70
|
actionName,
|
|
69
71
|
command,
|
|
72
|
+
applicationName,
|
|
70
73
|
feedbackRequestorDetails:
|
|
71
74
|
requestorAppName && webhookEndpoint
|
|
72
75
|
? {
|
|
@@ -15,6 +15,12 @@ export enum RequestMethod {
|
|
|
15
15
|
DELETE = 'delete',
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
interface BigIdApiRequestOptions {
|
|
19
|
+
bodyJson?: ActionResponseDetails;
|
|
20
|
+
useEndpointWithoutBigIdBasePath?: boolean;
|
|
21
|
+
additionalHeaderFields?: Record<string, any>;
|
|
22
|
+
}
|
|
23
|
+
|
|
18
24
|
export const getTenantRegistrations = async (bigidToken: string): Promise<TenantRegistration[]> => {
|
|
19
25
|
const {
|
|
20
26
|
data: {
|
|
@@ -32,6 +38,7 @@ export const doCallToUrl = async (
|
|
|
32
38
|
requestMethod: RequestMethod,
|
|
33
39
|
endpoint: string,
|
|
34
40
|
bodyJson?: Record<string, any>,
|
|
41
|
+
additionalHeaderFields?: Record<string, any>,
|
|
35
42
|
) => {
|
|
36
43
|
logInfo(`--> bigid-proxy::callBigIdApi: [${requestMethod}] endpoint: ${endpoint}`);
|
|
37
44
|
try {
|
|
@@ -39,6 +46,7 @@ export const doCallToUrl = async (
|
|
|
39
46
|
Accept: 'application/json, text/plain, */*',
|
|
40
47
|
'Content-Type': 'application/json',
|
|
41
48
|
Authorization: bigidToken,
|
|
49
|
+
...(additionalHeaderFields || {}),
|
|
42
50
|
};
|
|
43
51
|
const parsedUrl = new URL(endpoint);
|
|
44
52
|
parsedUrl.pathname = parsedUrl.pathname.replace(/\/+/g, '/');
|
|
@@ -71,11 +79,16 @@ async function callBigIdApi(
|
|
|
71
79
|
executionContext: ExecutionContext,
|
|
72
80
|
requestMethod: RequestMethod,
|
|
73
81
|
endpoint: string,
|
|
74
|
-
|
|
75
|
-
useEndpointWithoutBigIdBasePath?: boolean,
|
|
82
|
+
options: BigIdApiRequestOptions,
|
|
76
83
|
) {
|
|
77
|
-
const url = useEndpointWithoutBigIdBasePath ? endpoint : executionContext.bigidBaseUrl + endpoint;
|
|
78
|
-
return await doCallToUrl(
|
|
84
|
+
const url = options?.useEndpointWithoutBigIdBasePath ? endpoint : executionContext.bigidBaseUrl + endpoint;
|
|
85
|
+
return await doCallToUrl(
|
|
86
|
+
executionContext.bigidToken,
|
|
87
|
+
requestMethod,
|
|
88
|
+
url,
|
|
89
|
+
options?.bodyJson,
|
|
90
|
+
options?.additionalHeaderFields,
|
|
91
|
+
);
|
|
79
92
|
}
|
|
80
93
|
|
|
81
94
|
/**
|
|
@@ -88,13 +101,10 @@ export const updateActionStatusToBigID = async (
|
|
|
88
101
|
executionContext: ExecutionContext,
|
|
89
102
|
actionResponseDetails: ActionResponseDetails,
|
|
90
103
|
) =>
|
|
91
|
-
await callBigIdApi(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
actionResponseDetails,
|
|
96
|
-
true,
|
|
97
|
-
);
|
|
104
|
+
await callBigIdApi(executionContext, RequestMethod.PUT, executionContext.updateResultCallback, {
|
|
105
|
+
bodyJson: actionResponseDetails,
|
|
106
|
+
useEndpointWithoutBigIdBasePath: true,
|
|
107
|
+
});
|
|
98
108
|
|
|
99
109
|
/**
|
|
100
110
|
*
|
|
@@ -102,37 +112,53 @@ export const updateActionStatusToBigID = async (
|
|
|
102
112
|
* @param endpoint - the endpoint in BigID, used for GET request. e.g - {BigIDBaseUrl}/ds_connections
|
|
103
113
|
* @return - String containing the response from BigID
|
|
104
114
|
*/
|
|
105
|
-
export const executeHttpGet = async (
|
|
106
|
-
|
|
115
|
+
export const executeHttpGet = async (
|
|
116
|
+
executionContext: ExecutionContext,
|
|
117
|
+
endpoint: string,
|
|
118
|
+
additionalHeaderFields?: Record<string, any>,
|
|
119
|
+
) => await callBigIdApi(executionContext, RequestMethod.GET, endpoint, { additionalHeaderFields });
|
|
107
120
|
|
|
108
121
|
/**
|
|
109
122
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
110
123
|
*/
|
|
111
|
-
export const executeHttpPost = async (
|
|
112
|
-
|
|
124
|
+
export const executeHttpPost = async (
|
|
125
|
+
executionContext: ExecutionContext,
|
|
126
|
+
endpoint: string,
|
|
127
|
+
obj: any,
|
|
128
|
+
additionalHeaderFields?: Record<string, any>,
|
|
129
|
+
) => await callBigIdApi(executionContext, RequestMethod.POST, endpoint, { bodyJson: obj, additionalHeaderFields });
|
|
113
130
|
|
|
114
131
|
/**
|
|
115
132
|
* the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
|
|
116
133
|
*/
|
|
117
|
-
export const executeHttpPut = async (
|
|
118
|
-
|
|
134
|
+
export const executeHttpPut = async (
|
|
135
|
+
executionContext: ExecutionContext,
|
|
136
|
+
endpoint: string,
|
|
137
|
+
obj: any,
|
|
138
|
+
additionalHeaderFields?: Record<string, any>,
|
|
139
|
+
) => await callBigIdApi(executionContext, RequestMethod.PUT, endpoint, { bodyJson: obj, additionalHeaderFields });
|
|
119
140
|
|
|
120
141
|
/**
|
|
121
142
|
* the endpoint in BigID, used for DELETE requests.
|
|
122
143
|
*/
|
|
123
|
-
export const executeHttpDelete = async (
|
|
124
|
-
|
|
144
|
+
export const executeHttpDelete = async (
|
|
145
|
+
executionContext: ExecutionContext,
|
|
146
|
+
endpoint: string,
|
|
147
|
+
additionalHeaderFields?: Record<string, any>,
|
|
148
|
+
) => await callBigIdApi(executionContext, RequestMethod.DELETE, endpoint, { additionalHeaderFields });
|
|
125
149
|
|
|
126
150
|
export const executePost = async (
|
|
127
151
|
requestMethod: RequestMethod,
|
|
128
152
|
baseUrl: string | undefined,
|
|
129
153
|
bodyJson: Record<string, any>,
|
|
154
|
+
additionalHeaderFields?: Record<string, any>,
|
|
130
155
|
) => {
|
|
131
156
|
try {
|
|
132
157
|
const url = baseUrl + 'api/v1/sessions';
|
|
133
158
|
const headers = {
|
|
134
159
|
Accept: 'application/json',
|
|
135
160
|
'Content-type': 'application/json',
|
|
161
|
+
...(additionalHeaderFields || {}),
|
|
136
162
|
};
|
|
137
163
|
const requestObj: Record<string, any> = {
|
|
138
164
|
method: requestMethod,
|
|
@@ -177,7 +203,10 @@ export const uploadAttachment = (executionContext: ExecutionContext, filePathToU
|
|
|
177
203
|
export const getAppStorage = (executionContext: ExecutionContext) =>
|
|
178
204
|
executeHttpGet(executionContext, `tpa/${executionContext.tpaId}/storage`);
|
|
179
205
|
|
|
180
|
-
export const getValueFromAppStorage = async (
|
|
206
|
+
export const getValueFromAppStorage = async (
|
|
207
|
+
executionContext: ExecutionContext,
|
|
208
|
+
key: string,
|
|
209
|
+
): Promise<string | null> => {
|
|
181
210
|
const { data } = await executeHttpGet(executionContext, `tpa/${executionContext.tpaId}/storage/key/${key}`);
|
|
182
211
|
return data === 'Key not found' ? null : data?.value;
|
|
183
212
|
};
|
package/test/mock.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const mockExecutionContext = {
|
|
2
|
+
actionName: 'helloWorld',
|
|
3
|
+
executionId: '6787da8066db56a1866ccb82',
|
|
4
|
+
presetId: '6787d2a566db56a1866c8ea7',
|
|
5
|
+
globalParams: [
|
|
6
|
+
{
|
|
7
|
+
paramName: 'username',
|
|
8
|
+
paramValue: 'admin',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
paramName: 'password',
|
|
12
|
+
paramValue: 'admin',
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
actionParams: [
|
|
16
|
+
{
|
|
17
|
+
paramName: 'idConnectionName',
|
|
18
|
+
paramValue: 'identity source',
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
bigidToken:
|
|
22
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJiaWdpZC13ZWIiLCJpc0FkbWluIjp0cnVlLCJyb2xlSWRzIjpbInN5c3RlbSJdLCJ0eXBlIjoiYWNjZXNzLXRva2VuIiwidGVuYW50SWQiOiJTSU5HTEVfVEVOQU5UIiwiaWF0IjoxNzM2OTU2NTQ0LCJleHAiOjE3Mzc1NjEzNDR9.jlcHlT8uKxHA615NGAxIsM8-Cgvda3aOuy2Lji_u5hk',
|
|
23
|
+
updateResultCallback: 'https://bigid-ui:9090/api/v1/tpa/executions/6787da8066db56a1866ccb82',
|
|
24
|
+
bigidBaseUrl: 'https://bigid-ui:9090/api/v1/',
|
|
25
|
+
tpaId: '6787d2a566db56a1866c8e9d',
|
|
26
|
+
tpaName: 'Basic demo Nodejs app',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const mockBaseUrl = 'https://bigid-ui:9090/api/v1';
|
|
30
|
+
|
|
31
|
+
export const mockDataResponse = { Response: 'ok' };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import nock = require("nock");
|
|
3
|
+
import {
|
|
4
|
+
executeHttpGet,
|
|
5
|
+
executeHttpPost,
|
|
6
|
+
executeHttpPut,
|
|
7
|
+
executeHttpDelete,
|
|
8
|
+
} from '../../../src/services/bigidProxyService';
|
|
9
|
+
import { mockExecutionContext, mockBaseUrl, mockDataResponse } from '../../mock';
|
|
10
|
+
|
|
11
|
+
describe('Main api requests unit tests', () => {
|
|
12
|
+
const apiUrl = 'id_connections';
|
|
13
|
+
const modifiedHeader = { AdditionalFieldName: 'AdditionalFieldValue' };
|
|
14
|
+
const expectedFieldName = 'AdditionalFieldName';
|
|
15
|
+
const expectedFieldValue = 'AdditionalFieldValue';
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
nock.cleanAll();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('Should verify modified header for executeHttpGet request', async () => {
|
|
22
|
+
nock(mockBaseUrl).get(`/${apiUrl}`).matchHeader(expectedFieldName,expectedFieldValue).reply(200, mockDataResponse);
|
|
23
|
+
const response = await executeHttpGet(mockExecutionContext, apiUrl, modifiedHeader);
|
|
24
|
+
expect(response.data).to.deep.equal(mockDataResponse);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('Should verify modified header for executeHttpPost request', async () => {
|
|
28
|
+
nock(mockBaseUrl).post(`/${apiUrl}`).matchHeader(expectedFieldName,expectedFieldValue).reply(200, mockDataResponse);
|
|
29
|
+
const response = await executeHttpPost(mockExecutionContext, apiUrl, undefined, modifiedHeader);
|
|
30
|
+
expect(response.data).to.deep.equal(mockDataResponse);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('Should verify modified header for executeHttpPut request', async () => {
|
|
34
|
+
nock(mockBaseUrl).put(`/${apiUrl}`).matchHeader(expectedFieldName,expectedFieldValue).reply(200, mockDataResponse);
|
|
35
|
+
const response = await executeHttpPut(mockExecutionContext, apiUrl, undefined, modifiedHeader);
|
|
36
|
+
expect(response.data).to.deep.equal(mockDataResponse);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('Should verify modified header for executeHttpDelete request', async () => {
|
|
40
|
+
nock(mockBaseUrl).delete(`/${apiUrl}`).matchHeader(expectedFieldName,expectedFieldValue).reply(200, mockDataResponse);
|
|
41
|
+
const response = await executeHttpDelete(mockExecutionContext, apiUrl, modifiedHeader);
|
|
42
|
+
expect(response.data).to.deep.equal(mockDataResponse);
|
|
43
|
+
});
|
|
44
|
+
});
|