@reltio/components 1.4.1579 → 1.4.1580
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/cjs/hooks/useAPI/API.d.ts +1 -1
- package/cjs/hooks/useAPI/API.js +101 -121
- package/cjs/hooks/useAPI/helpers.d.ts +8 -27
- package/cjs/hooks/useAPI/helpers.js +49 -89
- package/cjs/hooks/useAPI/types.d.ts +3 -6
- package/cjs/hooks/useAPI/useAPI.js +29 -53
- package/cjs/hooks/useCustomScripts.js +26 -61
- package/esm/hooks/useAPI/API.d.ts +1 -1
- package/esm/hooks/useAPI/API.js +101 -121
- package/esm/hooks/useAPI/helpers.d.ts +8 -27
- package/esm/hooks/useAPI/helpers.js +42 -84
- package/esm/hooks/useAPI/types.d.ts +3 -6
- package/esm/hooks/useAPI/useAPI.js +32 -56
- package/esm/hooks/useCustomScripts.js +29 -64
- package/package.json +3 -3
|
@@ -46,15 +46,15 @@ var contexts_1 = require("../../contexts");
|
|
|
46
46
|
var API_1 = require("./API");
|
|
47
47
|
var helpers_1 = require("./helpers");
|
|
48
48
|
var useAPI = function (config) {
|
|
49
|
-
var _a, _b, _c, _d;
|
|
50
49
|
if (config === void 0) { config = {}; }
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
var
|
|
50
|
+
var _a = config.action || {}, processApiRequest = _a.processApiRequest, processApiResponse = _a.processApiResponse, platform = _a.platform;
|
|
51
|
+
var _b = (0, react_1.useState)(), html = _b[0], setHtml = _b[1];
|
|
52
|
+
var _c = (0, react_1.useState)([]), listenersToReset = _c[0], setListenersToReset = _c[1];
|
|
53
|
+
var _d = (0, react_1.useState)([]), popupListenersToReset = _d[0], setPopupListenersToReset = _d[1];
|
|
54
|
+
var _e = (0, react_1.useState)(true), visible = _e[0], setVisible = _e[1];
|
|
55
|
+
var _f = (0, react_1.useState)(), popup = _f[0], setPopup = _f[1];
|
|
56
|
+
var _g = (0, react_1.useState)(null), tooltip = _g[0], setTooltip = _g[1];
|
|
57
|
+
var _h = (0, react_1.useState)({}), customStyles = _h[0], setCustomStyles = _h[1];
|
|
58
58
|
var workerRef = (0, react_1.useRef)();
|
|
59
59
|
var requestListeners = (0, react_1.useRef)({});
|
|
60
60
|
var responseListeners = (0, react_1.useRef)({});
|
|
@@ -77,10 +77,8 @@ var useAPI = function (config) {
|
|
|
77
77
|
var entityUri = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getEntityUri);
|
|
78
78
|
var isEditableMode = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getIsEditableMode);
|
|
79
79
|
var environment = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getWorkflowEnvironmentUrl);
|
|
80
|
-
var
|
|
80
|
+
var _j = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getSearchProviderData) || {}, typeSearch = _j.type, search = _j.data;
|
|
81
81
|
var searchQuery = typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null;
|
|
82
|
-
var isOldUI = !(0, helpers_1.isNewUI)(servicesPath);
|
|
83
|
-
var supportedInterceptHandlers = isOldUI ? qxApi.interceptors : interceptHandlers;
|
|
84
82
|
var openSearch = function (search) { return dispatch(mdm_module_1.ui.actions.openSearch(search)); };
|
|
85
83
|
var innerText = '';
|
|
86
84
|
var popupText = '';
|
|
@@ -169,15 +167,8 @@ var useAPI = function (config) {
|
|
|
169
167
|
break;
|
|
170
168
|
}
|
|
171
169
|
case mdm_sdk_1.CustomAction.REQUEST: {
|
|
172
|
-
var
|
|
173
|
-
|
|
174
|
-
!(0, ramda_1.startsWith)(apiPath, (0, ramda_1.pathOr)('', ['params', 'url'], task));
|
|
175
|
-
var isApiAction = (0, ramda_1.pathEq)(['params', 'name'], mdm_sdk_1.RequestAction.API, task);
|
|
176
|
-
var processedParams = (0, ramda_1.pipe)((0, ramda_1.evolve)({
|
|
177
|
-
url: (0, ramda_1.ifElse)((0, ramda_1.both)((0, ramda_1.always)(isGlobalUrl), (0, ramda_1.always)(isApiAction)), (0, ramda_1.concat)("".concat(processedApiPath, "/api/").concat(tenant)), (0, ramda_1.replace)(reltioPath, apiPath))
|
|
178
|
-
}), (0, ramda_1.when)((0, ramda_1.has)('url'), (0, ramda_1.assocPath)(['validationUrl'], task.params.url)))(task.params);
|
|
179
|
-
var processedTask = __assign(__assign({}, task), { params: processedParams });
|
|
180
|
-
(0, API_1.processRequest)(__assign({ name: processedTask.params.name, paramObject: processedTask, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, servicesPath: servicesPath, apiPath: reltioPath, tenant: tenant, workflowPath: workflowPath, entity: entity, entityUri: entityUri, environment: environment, query: searchQuery, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
|
|
170
|
+
var processedTask = (0, helpers_1.getProcessedTask)(task, apiPath, reltioPath, tenant);
|
|
171
|
+
(0, API_1.processRequest)(__assign({ params: processedTask.params, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, servicesPath: servicesPath, apiPath: reltioPath, tenant: tenant, workflowPath: workflowPath, entity: entity, entityUri: entityUri, environment: environment, query: searchQuery, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
|
|
181
172
|
break;
|
|
182
173
|
}
|
|
183
174
|
case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_RESPONSE: {
|
|
@@ -207,20 +198,18 @@ var useAPI = function (config) {
|
|
|
207
198
|
var _a;
|
|
208
199
|
responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[responseId] = { next: next }, _a));
|
|
209
200
|
};
|
|
210
|
-
var qooxdooRequestInterceptor = (0, helpers_1.setUpQooxdooRequestInterceptor)({ workerRef: workerRef, setRequestListeners: setRequestListeners });
|
|
211
|
-
var qooxdooResponseInterceptor = (0, helpers_1.setUpQooxdooResponseInterceptor)({ workerRef: workerRef, setResponseListeners: setResponseListeners });
|
|
212
201
|
var requestInterceptor = (0, helpers_1.setUpRequestInterceptor)({
|
|
213
202
|
apiPath: apiPath,
|
|
214
203
|
reltioPath: reltioPath,
|
|
215
204
|
tenant: tenant,
|
|
216
|
-
processApiRequest:
|
|
205
|
+
processApiRequest: processApiRequest,
|
|
217
206
|
workerRef: workerRef,
|
|
218
207
|
setRequestListeners: setRequestListeners
|
|
219
208
|
});
|
|
220
209
|
var responseInterceptor = (0, helpers_1.setUpResponseInterceptor)({
|
|
221
210
|
reltioPath: reltioPath,
|
|
222
211
|
apiPath: apiPath,
|
|
223
|
-
processApiResponse:
|
|
212
|
+
processApiResponse: processApiResponse,
|
|
224
213
|
workerRef: workerRef,
|
|
225
214
|
setResponseListeners: setResponseListeners
|
|
226
215
|
});
|
|
@@ -229,11 +218,10 @@ var useAPI = function (config) {
|
|
|
229
218
|
(_a = workerRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({ action: 'event', type: type, data: data });
|
|
230
219
|
};
|
|
231
220
|
var pendingInterceptors = (0, react_1.useRef)(false);
|
|
232
|
-
var needDelayedRequestForInterceptors =
|
|
233
|
-
interceptHandlers &&
|
|
221
|
+
var needDelayedRequestForInterceptors = interceptHandlers &&
|
|
234
222
|
!(0, mdm_sdk_1.isEmptyValue)(config.action) &&
|
|
235
|
-
|
|
236
|
-
(
|
|
223
|
+
platform !== mdm_sdk_1.CustomScriptPlatform.CLASSIC &&
|
|
224
|
+
(processApiRequest || processApiResponse);
|
|
237
225
|
if (needDelayedRequestForInterceptors) {
|
|
238
226
|
if (!pendingInterceptors.current && !workerRef.current) {
|
|
239
227
|
interceptHandlers.startInterceptorInit();
|
|
@@ -241,7 +229,7 @@ var useAPI = function (config) {
|
|
|
241
229
|
}
|
|
242
230
|
}
|
|
243
231
|
(0, react_1.useEffect)(function () {
|
|
244
|
-
if (
|
|
232
|
+
if ((0, helpers_1.isValidCustomScript)(config.action)) {
|
|
245
233
|
workerRef.current = (0, mdm_sdk_1.initializeWebWorker)(workerUrl, process, config);
|
|
246
234
|
if (pendingInterceptors.current) {
|
|
247
235
|
interceptHandlers.finishInterceptorInit();
|
|
@@ -270,30 +258,18 @@ var useAPI = function (config) {
|
|
|
270
258
|
postEventMessage('execute', null);
|
|
271
259
|
}, [config]);
|
|
272
260
|
(0, react_1.useEffect)(function () {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
addInternalRequestInterceptor(requestInterceptor);
|
|
287
|
-
addInternalResponseInterceptor(responseInterceptor);
|
|
288
|
-
workerRef.current.onerror = function () {
|
|
289
|
-
removeInternalRequestInterceptor_1(requestInterceptor);
|
|
290
|
-
removeInternalResponseInterceptor_1(responseInterceptor);
|
|
291
|
-
};
|
|
292
|
-
return function () {
|
|
293
|
-
removeInternalRequestInterceptor_1(requestInterceptor);
|
|
294
|
-
removeInternalResponseInterceptor_1(responseInterceptor);
|
|
295
|
-
};
|
|
296
|
-
}
|
|
261
|
+
if (!(0, mdm_sdk_1.isEmptyValue)(interceptHandlers) && (processApiRequest || processApiResponse)) {
|
|
262
|
+
var addInternalRequestInterceptor = interceptHandlers.addInternalRequestInterceptor, addInternalResponseInterceptor = interceptHandlers.addInternalResponseInterceptor, removeInternalRequestInterceptor_1 = interceptHandlers.removeInternalRequestInterceptor, removeInternalResponseInterceptor_1 = interceptHandlers.removeInternalResponseInterceptor;
|
|
263
|
+
addInternalRequestInterceptor(requestInterceptor);
|
|
264
|
+
addInternalResponseInterceptor(responseInterceptor);
|
|
265
|
+
workerRef.current.onerror = function () {
|
|
266
|
+
removeInternalRequestInterceptor_1(requestInterceptor);
|
|
267
|
+
removeInternalResponseInterceptor_1(responseInterceptor);
|
|
268
|
+
};
|
|
269
|
+
return function () {
|
|
270
|
+
removeInternalRequestInterceptor_1(requestInterceptor);
|
|
271
|
+
removeInternalResponseInterceptor_1(responseInterceptor);
|
|
272
|
+
};
|
|
297
273
|
}
|
|
298
274
|
}, [config]);
|
|
299
275
|
return { html: html, visible: visible, tooltip: tooltip, customStyles: customStyles, onClick: onClick, popup: popup };
|
|
@@ -65,12 +65,6 @@ var workflow_1 = require("../components/workflow");
|
|
|
65
65
|
var contexts_1 = require("../contexts");
|
|
66
66
|
var useAPI_1 = require("./useAPI");
|
|
67
67
|
var helpers_1 = require("./useAPI/helpers");
|
|
68
|
-
var isURLtoProcess = function (processApi, url) {
|
|
69
|
-
return (processApi || []).some(function (request) {
|
|
70
|
-
var regExp = new RegExp("^".concat(request, "$"));
|
|
71
|
-
return request.replace(/\/*$/, '') === url || (request && regExp.test(url));
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
68
|
var getCustomViewConfig = function (config) {
|
|
75
69
|
var processApiResponse = config.processApiResponse, processApiRequest = config.processApiRequest, permissions = config.permissions, files = config.files, otherProps = __rest(config, ["processApiResponse", "processApiRequest", "permissions", "files"]);
|
|
76
70
|
return __assign({ action: { processApiResponse: processApiResponse, processApiRequest: processApiRequest, permissions: permissions, files: files } }, otherProps);
|
|
@@ -78,7 +72,7 @@ var getCustomViewConfig = function (config) {
|
|
|
78
72
|
var useCustomScripts = function (config) {
|
|
79
73
|
var _a;
|
|
80
74
|
var customScripts = config.reduce(function (acc, customScript) {
|
|
81
|
-
if (
|
|
75
|
+
if ((0, helpers_1.isValidCustomScript)(customScript)) {
|
|
82
76
|
return __spreadArray(__spreadArray([], acc, true), [__assign(__assign({}, customScript), { actionId: (0, nanoid_1.nanoid)() })], false);
|
|
83
77
|
}
|
|
84
78
|
return acc;
|
|
@@ -118,16 +112,8 @@ var useCustomScripts = function (config) {
|
|
|
118
112
|
break;
|
|
119
113
|
}
|
|
120
114
|
case mdm_sdk_1.CustomAction.REQUEST: {
|
|
121
|
-
var
|
|
122
|
-
|
|
123
|
-
var isGlobalUrl = (0, ramda_1.startsWith)('/', (0, ramda_1.pathOr)('', ['params', 'url'], task)) &&
|
|
124
|
-
!(0, ramda_1.startsWith)(apiPath, (0, ramda_1.pathOr)('', ['params', 'url'], task));
|
|
125
|
-
var isApiAction = (0, ramda_1.pathEq)(['params', 'name'], mdm_sdk_1.RequestAction.API, task);
|
|
126
|
-
var processedParams = (0, ramda_1.pipe)((0, ramda_1.evolve)({
|
|
127
|
-
url: (0, ramda_1.ifElse)((0, ramda_1.both)((0, ramda_1.always)(isGlobalUrl), (0, ramda_1.always)(isApiAction)), (0, ramda_1.concat)("".concat(processedApiPath, "/api/").concat(tenant)), (0, ramda_1.replace)(reltioPath, apiPath))
|
|
128
|
-
}), (0, ramda_1.when)((0, ramda_1.has)('url'), (0, ramda_1.assocPath)(['validationUrl'], task.params.url)))(task.params);
|
|
129
|
-
var processedTask = __assign(__assign({}, task), { params: processedParams });
|
|
130
|
-
(0, useAPI_1.processRequest)(__assign({ name: processedTask.params.name, paramObject: processedTask, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, apiPath: reltioPath, servicesPath: servicesPath, tenant: tenant, workflowPath: workflowPath, entity: entity, entityUri: entityUri, environment: environment, query: typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
|
|
115
|
+
var processedTask = (0, helpers_1.getProcessedTask)(task, apiPath, reltioPath, tenant);
|
|
116
|
+
(0, useAPI_1.processRequest)(__assign({ params: processedTask.params, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, apiPath: reltioPath, servicesPath: servicesPath, tenant: tenant, workflowPath: workflowPath, entity: entity, entityUri: entityUri, environment: environment, query: typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
|
|
131
117
|
break;
|
|
132
118
|
}
|
|
133
119
|
case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_RESPONSE: {
|
|
@@ -166,14 +152,13 @@ var useCustomScripts = function (config) {
|
|
|
166
152
|
}, [config, metadata]);
|
|
167
153
|
var customScriptRequestInterceptor = function (_a) {
|
|
168
154
|
var _b;
|
|
169
|
-
var
|
|
170
|
-
var fakeURL =
|
|
171
|
-
|
|
172
|
-
: "".concat(reltioPath).concat(url.replace(apiPath, ''));
|
|
173
|
-
var actionId = (0, ramda_1.pipe)((0, ramda_1.map)((0, ramda_1.pick)(['actionId', 'processApiRequest'])), (0, ramda_1.find)(function (_a) {
|
|
155
|
+
var url = _a.url, next = _a.next, resolve = _a.resolve, options = _a.options;
|
|
156
|
+
var fakeURL = (0, helpers_1.getRequestFakeUrl)(url, apiPath, reltioPath, tenant);
|
|
157
|
+
var customScript = customScripts.find(function (_a) {
|
|
174
158
|
var processApiRequest = _a.processApiRequest;
|
|
175
|
-
return isURLtoProcess(
|
|
176
|
-
})
|
|
159
|
+
return (0, helpers_1.isURLtoProcess)(fakeURL, processApiRequest);
|
|
160
|
+
});
|
|
161
|
+
var actionId = customScript === null || customScript === void 0 ? void 0 : customScript.actionId;
|
|
177
162
|
if (actionId) {
|
|
178
163
|
var requestId = (0, nanoid_1.nanoid)();
|
|
179
164
|
requestListeners.current = __assign(__assign({}, requestListeners.current), (_b = {}, _b[requestId] = { options: options, next: next, id: requestId, resolve: resolve }, _b));
|
|
@@ -182,7 +167,7 @@ var useCustomScripts = function (config) {
|
|
|
182
167
|
id: requestId,
|
|
183
168
|
url: fakeURL,
|
|
184
169
|
method: options.method,
|
|
185
|
-
headers: __assign(__assign({}, options.headers), {
|
|
170
|
+
headers: __assign(__assign({}, options.headers), { actionId: actionId }),
|
|
186
171
|
data: options.body || options.data
|
|
187
172
|
});
|
|
188
173
|
}
|
|
@@ -191,20 +176,26 @@ var useCustomScripts = function (config) {
|
|
|
191
176
|
}
|
|
192
177
|
};
|
|
193
178
|
var customScriptResponseInterceptor = function (_a) {
|
|
194
|
-
var _b;
|
|
195
179
|
var url = _a.url, response = _a.response, next = _a.next, options = _a.options, abort = _a.abort;
|
|
196
|
-
|
|
180
|
+
var fakeURL = (0, helpers_1.getResponseFakeUrl)(url, apiPath, reltioPath);
|
|
181
|
+
var customScript = customScripts.find(function (_a) {
|
|
182
|
+
var processApiResponse = _a.processApiResponse;
|
|
183
|
+
return (0, helpers_1.isURLtoProcess)(fakeURL, processApiResponse);
|
|
184
|
+
});
|
|
185
|
+
var actionId = customScript === null || customScript === void 0 ? void 0 : customScript.actionId;
|
|
186
|
+
if (actionId) {
|
|
187
|
+
var responseId_1 = (0, nanoid_1.nanoid)();
|
|
197
188
|
response
|
|
198
189
|
.json()
|
|
199
190
|
.then(function (data) {
|
|
200
191
|
var _a;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
192
|
+
responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[responseId_1] = { next: next }, _a));
|
|
193
|
+
workers.current[actionId].postMessage({
|
|
194
|
+
action: 'apiResponse',
|
|
195
|
+
id: responseId_1,
|
|
196
|
+
url: fakeURL,
|
|
197
|
+
method: options.method,
|
|
198
|
+
data: data
|
|
208
199
|
});
|
|
209
200
|
})
|
|
210
201
|
.catch(function (error) {
|
|
@@ -212,33 +203,7 @@ var useCustomScripts = function (config) {
|
|
|
212
203
|
});
|
|
213
204
|
}
|
|
214
205
|
else {
|
|
215
|
-
|
|
216
|
-
var actionId_1 = (0, ramda_1.pipe)((0, ramda_1.map)((0, ramda_1.pick)(['actionId', 'processApiResponse'])), (0, ramda_1.find)(function (_a) {
|
|
217
|
-
var processApiResponse = _a.processApiResponse;
|
|
218
|
-
return isURLtoProcess(processApiResponse, fakeURL_1);
|
|
219
|
-
}), (0, ramda_1.prop)('actionId'))(customScripts);
|
|
220
|
-
if (actionId_1) {
|
|
221
|
-
var responseId_1 = (0, nanoid_1.nanoid)();
|
|
222
|
-
response
|
|
223
|
-
.json()
|
|
224
|
-
.then(function (data) {
|
|
225
|
-
var _a;
|
|
226
|
-
responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[responseId_1] = { next: next }, _a));
|
|
227
|
-
workers.current[actionId_1].postMessage({
|
|
228
|
-
action: 'apiResponse',
|
|
229
|
-
id: responseId_1,
|
|
230
|
-
url: fakeURL_1,
|
|
231
|
-
method: options.method,
|
|
232
|
-
data: data
|
|
233
|
-
});
|
|
234
|
-
})
|
|
235
|
-
.catch(function (error) {
|
|
236
|
-
abort(error);
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
next(response);
|
|
241
|
-
}
|
|
206
|
+
next(response);
|
|
242
207
|
}
|
|
243
208
|
};
|
|
244
209
|
(0, react_1.useEffect)(function () {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ProcessRequestParams } from './types';
|
|
2
|
-
export declare const processRequest: ({
|
|
2
|
+
export declare const processRequest: ({ params, permissions, worker, metadata, config, apiPath, servicesPath, user, workflowPath, entity, tenant, entityUri, query, openSearch, environment, getCurrentPerspectiveId, showPerspective, workflowCheckPermission, setEntityUri }: ProcessRequestParams) => void;
|
package/esm/hooks/useAPI/API.js
CHANGED
|
@@ -46,95 +46,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
import { getAccessToken, RequestAction, sendRequestFromCustomSandbox, sendWorkflowRequest, startProcessFromQuery } from '@reltio/mdm-sdk';
|
|
49
|
-
|
|
50
|
-
var processFromQuery = function (params, permissions, workflowPath, tenant, environment) {
|
|
51
|
-
if (!params.processDefinitionId) {
|
|
52
|
-
return new Promise(function (resolve) { return resolve({ errorMessage: 'processDefinitionId is empty' }); });
|
|
53
|
-
}
|
|
54
|
-
if (!params.searchString) {
|
|
55
|
-
return new Promise(function (resolve) { return resolve({ errorMessage: 'searchString is empty' }); });
|
|
56
|
-
}
|
|
57
|
-
if (!workflowPath) {
|
|
58
|
-
return new Promise(function (resolve) { return resolve({ errorMessage: 'Workflow path is not defined' }); });
|
|
59
|
-
}
|
|
60
|
-
var errors = validateParams(__assign({ validationUrl: '/processInstances/_generateFromQuery' }, params), permissions);
|
|
61
|
-
if (errors) {
|
|
62
|
-
return new Promise(function (resolve) { return resolve(errors); });
|
|
63
|
-
}
|
|
64
|
-
return startProcessFromQuery({
|
|
65
|
-
workflowPath: workflowPath,
|
|
66
|
-
processType: params.processDefinitionId,
|
|
67
|
-
searchString: params.searchString,
|
|
68
|
-
tenant: tenant,
|
|
69
|
-
environment: environment
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
var getHeaders = function (params, signHandler) { return __awaiter(void 0, void 0, void 0, function () {
|
|
73
|
-
var accessToken;
|
|
74
|
-
return __generator(this, function (_a) {
|
|
75
|
-
switch (_a.label) {
|
|
76
|
-
case 0: return [4 /*yield*/, (signHandler === null || signHandler === void 0 ? void 0 : signHandler())];
|
|
77
|
-
case 1:
|
|
78
|
-
accessToken = (_a.sent()).accessToken;
|
|
79
|
-
return [2 /*return*/, accessToken
|
|
80
|
-
? __assign(__assign({}, params.headers), { Authorization: "Bearer ".concat(accessToken) }) : params.headers];
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}); };
|
|
84
|
-
var workflowRequest = function (params, permissions, workflowPath, tenant, signHandler) { return __awaiter(void 0, void 0, void 0, function () {
|
|
85
|
-
var url, errors, isExternalUrl, headers;
|
|
86
|
-
return __generator(this, function (_a) {
|
|
87
|
-
switch (_a.label) {
|
|
88
|
-
case 0:
|
|
89
|
-
url = params.url;
|
|
90
|
-
errors = validateParams(params, permissions);
|
|
91
|
-
if (errors) {
|
|
92
|
-
return [2 /*return*/, errors];
|
|
93
|
-
}
|
|
94
|
-
isExternalUrl = url.includes('http:') || url.includes('https:');
|
|
95
|
-
if (!workflowPath && !isExternalUrl) {
|
|
96
|
-
return [2 /*return*/, { errorMessage: 'Workflow path is not defined' }];
|
|
97
|
-
}
|
|
98
|
-
return [4 /*yield*/, getHeaders(params, signHandler)];
|
|
99
|
-
case 1:
|
|
100
|
-
headers = _a.sent();
|
|
101
|
-
return [4 /*yield*/, sendWorkflowRequest({
|
|
102
|
-
url: url,
|
|
103
|
-
method: params.method || 'GET',
|
|
104
|
-
data: params.data,
|
|
105
|
-
tenant: tenant,
|
|
106
|
-
headers: headers,
|
|
107
|
-
workflowPath: workflowPath
|
|
108
|
-
})];
|
|
109
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}); };
|
|
113
|
-
var sendApiRequest = function (params, permissions, signHandler) { return __awaiter(void 0, void 0, void 0, function () {
|
|
114
|
-
var errors, headers;
|
|
115
|
-
return __generator(this, function (_a) {
|
|
116
|
-
switch (_a.label) {
|
|
117
|
-
case 0:
|
|
118
|
-
errors = validateParams(params, permissions);
|
|
119
|
-
if (errors) {
|
|
120
|
-
return [2 /*return*/, Promise.reject(errors)];
|
|
121
|
-
}
|
|
122
|
-
return [4 /*yield*/, getHeaders(params, signHandler)];
|
|
123
|
-
case 1:
|
|
124
|
-
headers = _a.sent();
|
|
125
|
-
return [4 /*yield*/, sendRequestFromCustomSandbox({
|
|
126
|
-
url: params.url,
|
|
127
|
-
method: params.method,
|
|
128
|
-
data: params.data,
|
|
129
|
-
headers: headers,
|
|
130
|
-
noRequestProcessor: true
|
|
131
|
-
})];
|
|
132
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}); };
|
|
136
|
-
var validateParams = function (params, permissions) {
|
|
137
|
-
var validationUrl = params.validationUrl;
|
|
49
|
+
var validateParams = function (validationUrl, permissions) {
|
|
138
50
|
if (!validationUrl)
|
|
139
51
|
return { errorMessage: 'URL is empty' };
|
|
140
52
|
var allowed = permissions === null || permissions === void 0 ? void 0 : permissions.some(function (permission) {
|
|
@@ -152,48 +64,116 @@ var validateParams = function (params, permissions) {
|
|
|
152
64
|
}
|
|
153
65
|
return false;
|
|
154
66
|
};
|
|
67
|
+
var getAuthHeaders = function (headers, servicesPath) { return __awaiter(void 0, void 0, void 0, function () {
|
|
68
|
+
var accessToken;
|
|
69
|
+
return __generator(this, function (_a) {
|
|
70
|
+
switch (_a.label) {
|
|
71
|
+
case 0: return [4 /*yield*/, getAccessToken({ servicesPath: servicesPath })];
|
|
72
|
+
case 1:
|
|
73
|
+
accessToken = (_a.sent()).accessToken;
|
|
74
|
+
return [2 /*return*/, accessToken ? __assign(__assign({}, headers), { Authorization: "Bearer ".concat(accessToken) }) : headers];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}); };
|
|
155
78
|
export var processRequest = function (_a) {
|
|
156
|
-
var
|
|
79
|
+
var params = _a.params, permissions = _a.permissions, worker = _a.worker, metadata = _a.metadata, config = _a.config, apiPath = _a.apiPath, servicesPath = _a.servicesPath, user = _a.user, workflowPath = _a.workflowPath, entity = _a.entity, tenant = _a.tenant, entityUri = _a.entityUri, query = _a.query, openSearch = _a.openSearch, environment = _a.environment, getCurrentPerspectiveId = _a.getCurrentPerspectiveId, showPerspective = _a.showPerspective, workflowCheckPermission = _a.workflowCheckPermission, setEntityUri = _a.setEntityUri;
|
|
80
|
+
var name = params.name, url = params.url, data = params.data, method = params.method, validationUrl = params.validationUrl;
|
|
81
|
+
var processFromQuery = function () {
|
|
82
|
+
if (!params.processDefinitionId) {
|
|
83
|
+
return new Promise(function (resolve) { return resolve({ errorMessage: 'processDefinitionId is empty' }); });
|
|
84
|
+
}
|
|
85
|
+
if (!params.searchString) {
|
|
86
|
+
return new Promise(function (resolve) { return resolve({ errorMessage: 'searchString is empty' }); });
|
|
87
|
+
}
|
|
88
|
+
if (!workflowPath) {
|
|
89
|
+
return new Promise(function (resolve) { return resolve({ errorMessage: 'Workflow path is not defined' }); });
|
|
90
|
+
}
|
|
91
|
+
var errors = validateParams('/processInstances/_generateFromQuery', permissions);
|
|
92
|
+
if (errors) {
|
|
93
|
+
return new Promise(function (resolve) { return resolve(errors); });
|
|
94
|
+
}
|
|
95
|
+
return startProcessFromQuery({
|
|
96
|
+
workflowPath: workflowPath,
|
|
97
|
+
processType: params.processDefinitionId,
|
|
98
|
+
searchString: params.searchString,
|
|
99
|
+
tenant: tenant,
|
|
100
|
+
environment: environment
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
var workflowRequest = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
104
|
+
var errors, isExternalUrl, headers;
|
|
105
|
+
return __generator(this, function (_a) {
|
|
106
|
+
switch (_a.label) {
|
|
107
|
+
case 0:
|
|
108
|
+
errors = validateParams(validationUrl, permissions);
|
|
109
|
+
if (errors) {
|
|
110
|
+
return [2 /*return*/, errors];
|
|
111
|
+
}
|
|
112
|
+
isExternalUrl = url.includes('http:') || url.includes('https:');
|
|
113
|
+
if (!workflowPath && !isExternalUrl) {
|
|
114
|
+
return [2 /*return*/, { errorMessage: 'Workflow path is not defined' }];
|
|
115
|
+
}
|
|
116
|
+
return [4 /*yield*/, getAuthHeaders(params.headers, servicesPath)];
|
|
117
|
+
case 1:
|
|
118
|
+
headers = _a.sent();
|
|
119
|
+
return [4 /*yield*/, sendWorkflowRequest({ url: url, method: method, data: data, tenant: tenant, headers: headers, workflowPath: workflowPath })];
|
|
120
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}); };
|
|
124
|
+
var sendApiRequest = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
125
|
+
var errors, headers;
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
switch (_a.label) {
|
|
128
|
+
case 0:
|
|
129
|
+
errors = validateParams(validationUrl, permissions);
|
|
130
|
+
if (errors) {
|
|
131
|
+
return [2 /*return*/, Promise.reject(errors)];
|
|
132
|
+
}
|
|
133
|
+
return [4 /*yield*/, getAuthHeaders(params.headers, servicesPath)];
|
|
134
|
+
case 1:
|
|
135
|
+
headers = _a.sent();
|
|
136
|
+
return [4 /*yield*/, sendRequestFromCustomSandbox({ url: url, method: method, data: data, headers: headers, noRequestProcessor: true })];
|
|
137
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}); };
|
|
157
141
|
var handleRequest = function (request) {
|
|
158
142
|
request
|
|
159
143
|
.then(function (response) { return (response.json ? response.json() : response); })
|
|
160
144
|
.then(function (data) {
|
|
161
145
|
worker.postMessage(__assign({ action: 'response', result: {
|
|
162
146
|
data: JSON.parse(JSON.stringify(data)),
|
|
163
|
-
headers:
|
|
147
|
+
headers: params.headers,
|
|
164
148
|
status: 200
|
|
165
|
-
} },
|
|
149
|
+
} }, params));
|
|
166
150
|
})
|
|
167
151
|
.catch(function (error) {
|
|
168
152
|
worker.postMessage(__assign({ action: 'response', result: {
|
|
169
153
|
data: JSON.parse(JSON.stringify(error)),
|
|
170
|
-
headers:
|
|
154
|
+
headers: params.headers,
|
|
171
155
|
status: 0
|
|
172
|
-
} },
|
|
156
|
+
} }, params));
|
|
173
157
|
});
|
|
174
158
|
};
|
|
175
|
-
var shouldSignRequest = isNewUI(servicesPath);
|
|
176
|
-
var signHandler = shouldSignRequest
|
|
177
|
-
? function () { return getAccessToken({ servicesPath: servicesPath }); }
|
|
178
|
-
: function () { return Promise.resolve({ accessToken: '' }); };
|
|
179
159
|
switch (name) {
|
|
180
160
|
case RequestAction.API: {
|
|
181
|
-
var request = sendApiRequest(
|
|
161
|
+
var request = sendApiRequest();
|
|
182
162
|
handleRequest(request);
|
|
183
163
|
break;
|
|
184
164
|
}
|
|
185
165
|
case RequestAction.WORKFLOW: {
|
|
186
|
-
var request = workflowRequest(
|
|
166
|
+
var request = workflowRequest();
|
|
187
167
|
handleRequest(request);
|
|
188
168
|
break;
|
|
189
169
|
}
|
|
190
170
|
case RequestAction.WORKFLOW_START_PROCESS_FROM_QUERY: {
|
|
191
|
-
var request = processFromQuery(
|
|
171
|
+
var request = processFromQuery();
|
|
192
172
|
handleRequest(request);
|
|
193
173
|
break;
|
|
194
174
|
}
|
|
195
175
|
case RequestAction.GET_CONFIGURATION: {
|
|
196
|
-
worker.postMessage(__assign({ action: 'response', result: metadata },
|
|
176
|
+
worker.postMessage(__assign({ action: 'response', result: metadata }, params));
|
|
197
177
|
break;
|
|
198
178
|
}
|
|
199
179
|
case RequestAction.GET_UI_CONFIGURATION: {
|
|
@@ -201,77 +181,77 @@ export var processRequest = function (_a) {
|
|
|
201
181
|
if (response.action.permissions) {
|
|
202
182
|
delete response.action.permissions;
|
|
203
183
|
}
|
|
204
|
-
worker.postMessage(__assign({ action: 'response', result: response },
|
|
184
|
+
worker.postMessage(__assign({ action: 'response', result: response }, params));
|
|
205
185
|
break;
|
|
206
186
|
}
|
|
207
187
|
case RequestAction.SET_ENTITY_URI: {
|
|
208
188
|
var listener = function (newEntity) {
|
|
209
|
-
return worker.postMessage(__assign({ action: 'response', result: newEntity },
|
|
189
|
+
return worker.postMessage(__assign({ action: 'response', result: newEntity }, params));
|
|
210
190
|
};
|
|
211
|
-
setEntityUri(
|
|
191
|
+
setEntityUri(params.entityUri, listener);
|
|
212
192
|
break;
|
|
213
193
|
}
|
|
214
194
|
case RequestAction.SET_PERSPECTIVE: {
|
|
215
|
-
showPerspective(
|
|
216
|
-
worker.postMessage(__assign({ action: 'response', result: getCurrentPerspectiveId() },
|
|
195
|
+
showPerspective(params.perspective);
|
|
196
|
+
worker.postMessage(__assign({ action: 'response', result: getCurrentPerspectiveId() }, params));
|
|
217
197
|
break;
|
|
218
198
|
}
|
|
219
199
|
case RequestAction.GET_PERSPECTIVE: {
|
|
220
200
|
if (getCurrentPerspectiveId) {
|
|
221
|
-
worker.postMessage(__assign({ action: 'response', result: getCurrentPerspectiveId() },
|
|
201
|
+
worker.postMessage(__assign({ action: 'response', result: getCurrentPerspectiveId() }, params));
|
|
222
202
|
}
|
|
223
203
|
break;
|
|
224
204
|
}
|
|
225
205
|
case RequestAction.WORKFLOW_CHECK_PERMISSION: {
|
|
226
|
-
worker.postMessage(__assign({ action: 'response', result: workflowCheckPermission(
|
|
206
|
+
worker.postMessage(__assign({ action: 'response', result: workflowCheckPermission(params.permission) }, params));
|
|
227
207
|
break;
|
|
228
208
|
}
|
|
229
209
|
case RequestAction.GET_SEARCH_QUERY: {
|
|
230
|
-
worker.postMessage(__assign({ action: 'response', result: query },
|
|
210
|
+
worker.postMessage(__assign({ action: 'response', result: query }, params));
|
|
231
211
|
break;
|
|
232
212
|
}
|
|
233
213
|
case RequestAction.OPEN_SEARCH: {
|
|
234
|
-
openSearch({ viewId: config.id, searchState:
|
|
214
|
+
openSearch({ viewId: config.id, searchState: params.searchState || {} });
|
|
235
215
|
break;
|
|
236
216
|
}
|
|
237
217
|
case RequestAction.GET_ENTITY_URI: {
|
|
238
|
-
worker.postMessage(__assign({ action: 'response', result: entityUri },
|
|
218
|
+
worker.postMessage(__assign({ action: 'response', result: entityUri }, params));
|
|
239
219
|
break;
|
|
240
220
|
}
|
|
241
221
|
case RequestAction.GET_ENTITY: {
|
|
242
|
-
worker.postMessage(__assign({ action: 'response', result: entity },
|
|
222
|
+
worker.postMessage(__assign({ action: 'response', result: entity }, params));
|
|
243
223
|
break;
|
|
244
224
|
}
|
|
245
225
|
case RequestAction.GET_API_PATH: {
|
|
246
|
-
worker.postMessage(__assign({ action: 'response', result: apiPath },
|
|
226
|
+
worker.postMessage(__assign({ action: 'response', result: apiPath }, params));
|
|
247
227
|
break;
|
|
248
228
|
}
|
|
249
229
|
case RequestAction.WORKFLOW_GET_WORKFLOW_PATH: {
|
|
250
|
-
worker.postMessage(__assign({ action: 'response', result: workflowPath },
|
|
230
|
+
worker.postMessage(__assign({ action: 'response', result: workflowPath }, params));
|
|
251
231
|
break;
|
|
252
232
|
}
|
|
253
233
|
case RequestAction.GET_TENANT: {
|
|
254
|
-
worker.postMessage(__assign({ action: 'response', result: tenant },
|
|
234
|
+
worker.postMessage(__assign({ action: 'response', result: tenant }, params));
|
|
255
235
|
break;
|
|
256
236
|
}
|
|
257
237
|
case RequestAction.GET_USER: {
|
|
258
|
-
worker.postMessage(__assign({ action: 'response', result: user },
|
|
238
|
+
worker.postMessage(__assign({ action: 'response', result: user }, params));
|
|
259
239
|
break;
|
|
260
240
|
}
|
|
261
241
|
case RequestAction.ALERT: {
|
|
262
|
-
worker.postMessage(__assign({ action: 'response', result: window.alert(
|
|
242
|
+
worker.postMessage(__assign({ action: 'response', result: window.alert(params.text) }, params));
|
|
263
243
|
break;
|
|
264
244
|
}
|
|
265
245
|
case RequestAction.CONFIRM: {
|
|
266
|
-
worker.postMessage(__assign({ action: 'response', result: window.confirm(
|
|
246
|
+
worker.postMessage(__assign({ action: 'response', result: window.confirm(params.text) }, params));
|
|
267
247
|
break;
|
|
268
248
|
}
|
|
269
249
|
case RequestAction.PROMPT: {
|
|
270
|
-
worker.postMessage(__assign({ action: 'response', result: window.prompt(
|
|
250
|
+
worker.postMessage(__assign({ action: 'response', result: window.prompt(params.text, params.defaultText || '') }, params));
|
|
271
251
|
break;
|
|
272
252
|
}
|
|
273
253
|
case RequestAction.OPEN_WINDOW: {
|
|
274
|
-
window.open(
|
|
254
|
+
window.open(params.url, '_blank');
|
|
275
255
|
break;
|
|
276
256
|
}
|
|
277
257
|
case RequestAction.RELOAD_PAGE: {
|