@reltio/components 1.4.1435 → 1.4.1437

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.
@@ -20,6 +20,7 @@ var useWorkflowTasks = function (config) {
20
20
  var tenant = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getTenant);
21
21
  var entityUri = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getEntityUri);
22
22
  var isEditableMode = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getIsEditableMode);
23
+ var entityLastLoadedTime = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getProfileLastLoadedTime);
23
24
  var checkWorkflowPermission = (0, useWorkflowCheckPermission_1.useWorkflowCheckPermission)();
24
25
  var canViewTasks = checkWorkflowPermission('VIEW_TASKS');
25
26
  var enabled = !!(workflowPath && environment) && isWorkflowEnabled && canViewTasks;
@@ -51,7 +52,18 @@ var useWorkflowTasks = function (config) {
51
52
  .finally(function () {
52
53
  setLoading(false);
53
54
  });
54
- }, [entityUri, environment, safePromise, tenant, workflowPath, assignee, showClosedTasks, processTypes]);
55
+ // eslint-disable-next-line react-hooks/exhaustive-deps
56
+ }, [
57
+ entityUri,
58
+ environment,
59
+ safePromise,
60
+ tenant,
61
+ workflowPath,
62
+ assignee,
63
+ showClosedTasks,
64
+ processTypes,
65
+ entityLastLoadedTime
66
+ ]);
55
67
  (0, react_1.useEffect)(function () {
56
68
  if (entityUri && enabled && !(0, mdm_sdk_1.isTempUri)(entityUri)) {
57
69
  loadTasks();
@@ -60,7 +60,7 @@ var processFromQuery = function (params, permissions, workflowPath, tenant, envi
60
60
  if (!workflowPath) {
61
61
  return new Promise(function (resolve) { return resolve({ errorMessage: 'Workflow path is not defined' }); });
62
62
  }
63
- var errors = validateParams(__assign({ url: '/processInstances/_generateFromQuery' }, params), permissions);
63
+ var errors = validateParams(__assign({ validationUrl: '/processInstances/_generateFromQuery' }, params), permissions);
64
64
  if (errors) {
65
65
  return new Promise(function (resolve) { return resolve(errors); });
66
66
  }
@@ -120,7 +120,7 @@ var sendApiRequest = function (params, permissions, signHandler) { return __awai
120
120
  case 0:
121
121
  errors = validateParams(params, permissions);
122
122
  if (errors) {
123
- return [2 /*return*/, errors];
123
+ return [2 /*return*/, Promise.reject(errors)];
124
124
  }
125
125
  return [4 /*yield*/, getHeaders(params, signHandler)];
126
126
  case 1:
@@ -137,18 +137,18 @@ var sendApiRequest = function (params, permissions, signHandler) { return __awai
137
137
  });
138
138
  }); };
139
139
  var validateParams = function (params, permissions) {
140
- var url = params.url;
141
- if (!url)
140
+ var validationUrl = params.validationUrl;
141
+ if (!validationUrl)
142
142
  return { errorMessage: 'URL is empty' };
143
143
  var allowed = permissions === null || permissions === void 0 ? void 0 : permissions.some(function (permission) {
144
144
  var _a;
145
- var urlOrigin = (_a = url.match(/^(https?:\/\/[^:/?#]*).*$/)) === null || _a === void 0 ? void 0 : _a[1];
145
+ var urlOrigin = (_a = validationUrl.match(/^(https?:\/\/[^:/?#]*).*$/)) === null || _a === void 0 ? void 0 : _a[1];
146
146
  var permRegex = new RegExp('^' + permission + '$');
147
147
  var decodedPerm = permission.replace(/\/*$/, '');
148
- return (decodedPerm === url ||
148
+ return (decodedPerm === validationUrl ||
149
149
  (urlOrigin && urlOrigin === decodedPerm) ||
150
- ((decodedPerm === null || decodedPerm === void 0 ? void 0 : decodedPerm.startsWith('/')) && (url === null || url === void 0 ? void 0 : url.startsWith(decodedPerm))) ||
151
- (permission && permRegex.test(url)));
150
+ ((decodedPerm === null || decodedPerm === void 0 ? void 0 : decodedPerm.startsWith('/')) && (validationUrl === null || validationUrl === void 0 ? void 0 : validationUrl.startsWith(decodedPerm))) ||
151
+ (permission && permRegex.test(validationUrl)));
152
152
  });
153
153
  if (!allowed || ((permissions === null || permissions === void 0 ? void 0 : permissions.length) || 0) === 0) {
154
154
  return { errorMessage: 'Not enough permissions' };
@@ -159,8 +159,13 @@ var processRequest = function (_a) {
159
159
  var name = _a.name, paramObject = _a.paramObject, 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;
160
160
  var handleRequest = function (request) {
161
161
  request
162
+ .then(function (response) { return (response.json ? response.json() : response); })
162
163
  .then(function (data) {
163
- worker.postMessage(__assign({ action: 'response', result: { data: data, headers: paramObject.params.headers, status: 200 } }, paramObject.params));
164
+ worker.postMessage(__assign({ action: 'response', result: {
165
+ data: JSON.parse(JSON.stringify(data)),
166
+ headers: paramObject.params.headers,
167
+ status: 200
168
+ } }, paramObject.params));
164
169
  })
165
170
  .catch(function (error) {
166
171
  worker.postMessage(__assign({ action: 'response', result: { data: error, headers: paramObject.params.headers, status: 0 } }, paramObject.params));
@@ -29,9 +29,10 @@ export declare const setUpRequestInterceptor: ({ apiPath, reltioPath, tenant, pr
29
29
  processApiRequest: any;
30
30
  workerRef: any;
31
31
  setRequestListeners: any;
32
- }) => ({ options, url, next }: {
32
+ }) => ({ options, url, next, resolve }: {
33
33
  next: (url: string, options: RequestInit) => void;
34
34
  abort?: (error: Error) => void;
35
+ resolve: (data: unknown) => void;
35
36
  url: string;
36
37
  options: RequestInit;
37
38
  }) => void;
@@ -143,14 +143,14 @@ exports.setUpQooxdooResponseInterceptor = setUpQooxdooResponseInterceptor;
143
143
  var setUpRequestInterceptor = function (_a) {
144
144
  var apiPath = _a.apiPath, reltioPath = _a.reltioPath, tenant = _a.tenant, processApiRequest = _a.processApiRequest, workerRef = _a.workerRef, setRequestListeners = _a.setRequestListeners;
145
145
  return function (_a) {
146
- var _b = _a.options, options = _b === void 0 ? {} : _b, url = _a.url, next = _a.next;
146
+ var _b = _a.options, options = _b === void 0 ? {} : _b, url = _a.url, next = _a.next, resolve = _a.resolve;
147
147
  var fakeURL = url.startsWith('/') && !url.startsWith(apiPath)
148
148
  ? "".concat(reltioPath, "/api/").concat(tenant).concat(url)
149
149
  : "".concat(reltioPath).concat(url.replace(apiPath, ''));
150
150
  var isProcessableUrl = isURLtoProcess(processApiRequest, fakeURL);
151
151
  if (isProcessableUrl) {
152
152
  var requestId = (0, nanoid_1.default)();
153
- setRequestListeners(options, next, requestId);
153
+ setRequestListeners(options, next, requestId, resolve);
154
154
  workerRef.current.postMessage({
155
155
  action: 'apiRequest',
156
156
  id: requestId,
@@ -1,5 +1,5 @@
1
1
  import { CSSProperties } from 'react';
2
- import { CustomActionViewConfig, CustomActionExtension } from '@reltio/mdm-sdk';
2
+ import { CustomActionExtension, CustomActionViewConfig } from '@reltio/mdm-sdk';
3
3
  declare type Config = CustomActionViewConfig | CustomActionExtension;
4
4
  export declare const useAPI: (config?: Config) => {
5
5
  html: HTMLElement;
@@ -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;
49
+ var _a, _b, _c, _d;
50
50
  if (config === void 0) { config = {}; }
51
- var _c = (0, react_1.useState)(), html = _c[0], setHtml = _c[1];
52
- var _d = (0, react_1.useState)([]), listenersToReset = _d[0], setListenersToReset = _d[1];
53
- var _e = (0, react_1.useState)([]), popupListenersToReset = _e[0], setPopupListenersToReset = _e[1];
54
- var _f = (0, react_1.useState)(true), visible = _f[0], setVisible = _f[1];
55
- var _g = (0, react_1.useState)(), popup = _g[0], setPopup = _g[1];
56
- var _h = (0, react_1.useState)(null), tooltip = _h[0], setTooltip = _h[1];
57
- var _j = (0, react_1.useState)({}), customStyles = _j[0], setCustomStyles = _j[1];
51
+ var _e = (0, react_1.useState)(), html = _e[0], setHtml = _e[1];
52
+ var _f = (0, react_1.useState)([]), listenersToReset = _f[0], setListenersToReset = _f[1];
53
+ var _g = (0, react_1.useState)([]), popupListenersToReset = _g[0], setPopupListenersToReset = _g[1];
54
+ var _h = (0, react_1.useState)(true), visible = _h[0], setVisible = _h[1];
55
+ var _j = (0, react_1.useState)(), popup = _j[0], setPopup = _j[1];
56
+ var _k = (0, react_1.useState)(null), tooltip = _k[0], setTooltip = _k[1];
57
+ var _l = (0, react_1.useState)({}), customStyles = _l[0], setCustomStyles = _l[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,7 +77,7 @@ 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 _k = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getSearchProviderData) || {}, typeSearch = _k.type, search = _k.data;
80
+ var _m = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getSearchProviderData) || {}, typeSearch = _m.type, search = _m.data;
81
81
  var searchQuery = typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null;
82
82
  var isOldUI = !(0, helpers_1.isNewUI)(servicesPath);
83
83
  var supportedInterceptHandlers = isOldUI ? qxApi.interceptors : interceptHandlers;
@@ -85,7 +85,6 @@ var useAPI = function (config) {
85
85
  var innerText = '';
86
86
  var popupText = '';
87
87
  var process = function (_a) {
88
- var _b, _c;
89
88
  var task = _a.task, worker = _a.worker;
90
89
  if (task) {
91
90
  switch (task.action) {
@@ -169,40 +168,38 @@ var useAPI = function (config) {
169
168
  break;
170
169
  }
171
170
  case mdm_sdk_1.CustomAction.REQUEST: {
172
- if (((_c = (_b = task.params) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.origin) !== 'ui') {
173
- (0, API_1.processRequest)(__assign({ name: task.params.name, paramObject: task, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, servicesPath: servicesPath, apiPath: isOldUI ? apiPath : reltioPath, tenant: tenant, workflowPath: workflowPath, entity: entity, entityUri: entityUri, environment: environment, query: searchQuery, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
174
- }
175
- else {
176
- var _d = task.params, headers = _d.headers, id = _d.id, fakeURL = _d.url, method = _d.method, data = _d.data;
177
- var url = fakeURL.replace(reltioPath, apiPath);
178
- if (requestListeners.current[headers.requestId]) {
179
- requestListeners.current[headers.requestId].next(url, {
180
- body: data,
181
- id: id,
182
- task: task,
183
- headers: headers,
184
- method: method
185
- });
186
- requestListeners.current = (0, ramda_1.omit)([headers.requestId], requestListeners.current);
187
- }
188
- }
171
+ var processedApiPath = isOldUI ? reltioPath : apiPath;
172
+ var isGlobalUrl = (0, ramda_1.startsWith)('/', (0, ramda_1.pathOr)('', ['params', 'url'], task)) &&
173
+ !(0, ramda_1.startsWith)(apiPath, (0, ramda_1.pathOr)('', ['params', 'url'], task));
174
+ var processedParams = (0, ramda_1.pipe)((0, ramda_1.evolve)({
175
+ url: (0, ramda_1.ifElse)((0, ramda_1.both)((0, ramda_1.always)(isGlobalUrl), (0, ramda_1.always)((0, ramda_1.pathEq)(['params', 'name'], mdm_sdk_1.RequestAction.API, task))), (0, ramda_1.concat)("".concat(processedApiPath, "/api/").concat(tenant)), (0, ramda_1.replace)(reltioPath, apiPath))
176
+ }), (0, ramda_1.when)((0, ramda_1.has)('url'), (0, ramda_1.assocPath)(['validationUrl'], task.params.url)))(task.params);
177
+ var processedTask = __assign(__assign({}, task), { params: processedParams });
178
+ (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: processedApiPath, tenant: tenant, workflowPath: workflowPath, entity: entity, entityUri: entityUri, environment: environment, query: searchQuery, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
189
179
  break;
190
180
  }
191
- case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_RESPONSE:
192
- case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_REQUEST: {
193
- var _e = task.params, id = _e.id, data = _e.data;
181
+ case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_RESPONSE: {
182
+ var _b = task.params, id = _b.id, data = _b.data;
194
183
  if (responseListeners.current[id]) {
195
184
  responseListeners.current[id].next(data);
196
185
  responseListeners.current = (0, ramda_1.omit)([id], responseListeners.current);
197
186
  }
198
187
  break;
199
188
  }
189
+ case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_REQUEST: {
190
+ var _c = task.params, id = _c.id, data = _c.data;
191
+ if (requestListeners.current[id]) {
192
+ requestListeners.current[id].resolve(data);
193
+ requestListeners.current = (0, ramda_1.omit)([id], requestListeners.current);
194
+ }
195
+ break;
196
+ }
200
197
  }
201
198
  }
202
199
  };
203
- var setRequestListeners = function (options, next, requestId) {
200
+ var setRequestListeners = function (options, next, requestId, resolve) {
204
201
  var _a;
205
- requestListeners.current = __assign(__assign({}, requestListeners.current), (_a = {}, _a[requestId] = { options: options, next: next, id: requestId }, _a));
202
+ requestListeners.current = __assign(__assign({}, requestListeners.current), (_a = {}, _a[requestId] = { options: options, next: next, id: requestId, resolve: resolve }, _a));
206
203
  };
207
204
  var setResponseListeners = function (next, responseId) {
208
205
  var _a;
@@ -229,9 +226,25 @@ var useAPI = function (config) {
229
226
  var _a;
230
227
  (_a = workerRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({ action: 'event', type: type, data: data });
231
228
  };
229
+ var pendingInterceptors = (0, react_1.useRef)(false);
230
+ var needDelayedRequestForInterceptors = !isOldUI &&
231
+ interceptHandlers &&
232
+ !(0, mdm_sdk_1.isEmptyValue)(config.action) &&
233
+ config.action.platform !== mdm_sdk_1.CustomScriptPlatform.CLASSIC &&
234
+ (((_c = config === null || config === void 0 ? void 0 : config.action) === null || _c === void 0 ? void 0 : _c.processApiRequest) || ((_d = config === null || config === void 0 ? void 0 : config.action) === null || _d === void 0 ? void 0 : _d.processApiResponse));
235
+ if (needDelayedRequestForInterceptors) {
236
+ if (!pendingInterceptors.current && !workerRef.current) {
237
+ interceptHandlers.startInterceptorInit();
238
+ pendingInterceptors.current = true;
239
+ }
240
+ }
232
241
  (0, react_1.useEffect)(function () {
233
242
  if (!(0, mdm_sdk_1.isEmptyValue)(config.action) && config.action.platform !== mdm_sdk_1.CustomScriptPlatform.CLASSIC) {
234
243
  workerRef.current = (0, mdm_sdk_1.initializeWebWorker)(workerUrl, process, config);
244
+ if (pendingInterceptors.current) {
245
+ interceptHandlers.finishInterceptorInit();
246
+ pendingInterceptors.current = false;
247
+ }
235
248
  postEventMessage('updateEntity', entity);
236
249
  }
237
250
  }, [entity, config]);
@@ -270,6 +283,10 @@ var useAPI = function (config) {
270
283
  else {
271
284
  addInternalRequestInterceptor(requestInterceptor);
272
285
  addInternalResponseInterceptor(responseInterceptor);
286
+ workerRef.current.onerror = function () {
287
+ removeInternalRequestInterceptor_1(requestInterceptor);
288
+ removeInternalResponseInterceptor_1(responseInterceptor);
289
+ };
273
290
  return function () {
274
291
  removeInternalRequestInterceptor_1(requestInterceptor);
275
292
  removeInternalResponseInterceptor_1(responseInterceptor);
@@ -78,6 +78,7 @@ var getCustomViewConfig = function (config) {
78
78
  return __assign({ action: { processApiResponse: processApiResponse, processApiRequest: processApiRequest, permissions: permissions, files: files } }, otherProps);
79
79
  };
80
80
  var useCustomScripts = function (config) {
81
+ var _a;
81
82
  var customScripts = config.reduce(function (acc, customScript) {
82
83
  if (customScript.platform !== mdm_sdk_1.CustomScriptPlatform.CLASSIC) {
83
84
  return __spreadArray(__spreadArray([], acc, true), [__assign(__assign({}, customScript), { actionId: (0, nanoid_1.default)() })], false);
@@ -85,10 +86,10 @@ var useCustomScripts = function (config) {
85
86
  return acc;
86
87
  }, []);
87
88
  var showSnackbarMessage = (0, react_1.useContext)(contexts_1.SnackbarContext);
88
- var _a = (0, react_1.useContext)(contexts_1.InterceptHandlersContext), addInternalRequestInterceptor = _a.addInternalRequestInterceptor, addInternalResponseInterceptor = _a.addInternalResponseInterceptor, removeInternalRequestInterceptor = _a.removeInternalRequestInterceptor, removeInternalResponseInterceptor = _a.removeInternalResponseInterceptor;
89
+ var _b = (0, react_1.useContext)(contexts_1.InterceptHandlersContext), addInternalRequestInterceptor = _b.addInternalRequestInterceptor, addInternalResponseInterceptor = _b.addInternalResponseInterceptor, removeInternalRequestInterceptor = _b.removeInternalRequestInterceptor, removeInternalResponseInterceptor = _b.removeInternalResponseInterceptor;
89
90
  var qxApi = (0, react_1.useContext)(contexts_1.SandboxAPIContext);
90
91
  var dispatch = (0, react_redux_1.useDispatch)();
91
- var metadata = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getMetadata) || {};
92
+ var metadata = (_a = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getMetadata)) !== null && _a !== void 0 ? _a : null;
92
93
  var entity = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getEntity) || {};
93
94
  var uiPath = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getUIPath);
94
95
  var servicesPath = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getServicesPath);
@@ -101,13 +102,12 @@ var useCustomScripts = function (config) {
101
102
  var entityUri = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getEntityUri);
102
103
  var environment = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getWorkflowEnvironmentUrl);
103
104
  var workflowCheckPermission = (0, workflow_1.useWorkflowCheckPermission)();
104
- var _b = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getSearchProviderData) || {}, typeSearch = _b.type, search = _b.data;
105
+ var _c = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getSearchProviderData) || {}, typeSearch = _c.type, search = _c.data;
105
106
  var openSearch = function (search) { return dispatch(mdm_module_1.ui.actions.openSearch(search)); };
106
107
  var requestListeners = (0, react_1.useRef)({});
107
108
  var responseListeners = (0, react_1.useRef)({});
108
109
  var workers = (0, react_1.useRef)({});
109
- var process = function (_a) {
110
- var _b, _c;
110
+ var processMessageFromWorker = function (_a) {
111
111
  var task = _a.task, worker = _a.worker, config = _a.config;
112
112
  if (task) {
113
113
  switch (task.action) {
@@ -120,52 +120,50 @@ var useCustomScripts = function (config) {
120
120
  break;
121
121
  }
122
122
  case mdm_sdk_1.CustomAction.REQUEST: {
123
- if (((_c = (_b = task.params) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.origin) !== 'ui') {
124
- (0, useAPI_1.processRequest)(__assign({ name: task.params.name, paramObject: task, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, apiPath: apiPath, 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));
125
- }
126
- else {
127
- var _d = task.params, headers = _d.headers, id = _d.id, fakeURL = _d.url, method = _d.method, data = _d.data;
128
- var url = fakeURL.replace(reltioPath, apiPath);
129
- if (requestListeners.current[headers.requestId]) {
130
- requestListeners.current[headers.requestId].next(url, {
131
- body: data,
132
- id: id,
133
- task: task,
134
- headers: headers,
135
- method: method
136
- });
137
- requestListeners.current = (0, ramda_1.omit)([headers.requestId], requestListeners.current);
138
- }
139
- }
123
+ var processedParams = (0, ramda_1.pipe)((0, ramda_1.evolve)({
124
+ url: (0, ramda_1.replace)(reltioPath, apiPath)
125
+ }), (0, ramda_1.when)((0, ramda_1.has)('url'), (0, ramda_1.assocPath)(['validationUrl'], task.params.url)))(task.params);
126
+ var processedTask = __assign(__assign({}, task), { params: processedParams });
127
+ (0, useAPI_1.processRequest)(__assign({ name: processedTask.params.name, paramObject: processedTask, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, apiPath: apiPath, 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));
140
128
  break;
141
129
  }
142
- case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_RESPONSE:
143
- case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_REQUEST: {
144
- var _e = task.params, id = _e.id, data = _e.data;
130
+ case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_RESPONSE: {
131
+ var _b = task.params, id = _b.id, data = _b.data;
145
132
  if (responseListeners.current[id]) {
146
133
  responseListeners.current[id].next(data);
147
134
  responseListeners.current = (0, ramda_1.omit)([id], responseListeners.current);
148
135
  }
149
136
  break;
150
137
  }
138
+ case mdm_sdk_1.CustomAction.RETURN_PROCESSED_API_REQUEST: {
139
+ var _c = task.params, id = _c.id, data = _c.data;
140
+ if (requestListeners.current[id]) {
141
+ requestListeners.current[id].resolve(data);
142
+ requestListeners.current = (0, ramda_1.omit)([id], requestListeners.current);
143
+ }
144
+ break;
145
+ }
151
146
  }
152
147
  }
153
148
  };
154
149
  (0, react_1.useEffect)(function () {
150
+ if (metadata === null) {
151
+ return;
152
+ }
155
153
  workers.current = customScripts.reduce(function (acc, customScript) {
156
154
  var _a;
157
155
  var customViewConfig = getCustomViewConfig(customScript);
158
- return __assign(__assign({}, acc), (_a = {}, _a[customScript.actionId] = (0, mdm_sdk_1.initializeWebWorker)(workerUrl, process, customViewConfig), _a));
156
+ return __assign(__assign({}, acc), (_a = {}, _a[customScript.actionId] = (0, mdm_sdk_1.initializeWebWorker)(workerUrl, processMessageFromWorker, customViewConfig), _a));
159
157
  }, workers.current);
160
158
  return function () {
161
159
  Object.keys(workers.current).forEach(function (actionId) {
162
160
  workers.current[actionId].terminate();
163
161
  });
164
162
  };
165
- }, [config]);
163
+ }, [config, metadata]);
166
164
  var customScriptRequestInterceptor = function (_a) {
167
165
  var _b;
168
- var _c = _a.options, options = _c === void 0 ? {} : _c, url = _a.url, next = _a.next;
166
+ var _c = _a.options, options = _c === void 0 ? {} : _c, url = _a.url, next = _a.next, resolve = _a.resolve;
169
167
  var fakeURL = url.startsWith('/') && !url.startsWith(apiPath)
170
168
  ? "".concat(reltioPath, "/api/").concat(tenant).concat(url)
171
169
  : "".concat(reltioPath).concat(url.replace(apiPath, ''));
@@ -175,7 +173,7 @@ var useCustomScripts = function (config) {
175
173
  }), (0, ramda_1.prop)('actionId'))(customScripts);
176
174
  if (actionId) {
177
175
  var requestId = (0, nanoid_1.default)();
178
- requestListeners.current = __assign(__assign({}, requestListeners.current), (_b = {}, _b[requestId] = { options: options, next: next, id: requestId }, _b));
176
+ requestListeners.current = __assign(__assign({}, requestListeners.current), (_b = {}, _b[requestId] = { options: options, next: next, id: requestId, resolve: resolve }, _b));
179
177
  workers.current[actionId].postMessage({
180
178
  action: 'apiRequest',
181
179
  id: requestId,
@@ -201,7 +199,7 @@ var useCustomScripts = function (config) {
201
199
  responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[options.headers.requestId] = { next: next }, _a));
202
200
  workers.current[(_b = options.headers) === null || _b === void 0 ? void 0 : _b.actionId].postMessage({
203
201
  action: 'response',
204
- result: { data: data },
202
+ result: { data: data, status: response.status },
205
203
  id: options === null || options === void 0 ? void 0 : options.id,
206
204
  name: (_d = (_c = options === null || options === void 0 ? void 0 : options.task) === null || _c === void 0 ? void 0 : _c.params) === null || _d === void 0 ? void 0 : _d.name
207
205
  });
@@ -241,14 +239,15 @@ var useCustomScripts = function (config) {
241
239
  }
242
240
  };
243
241
  (0, react_1.useEffect)(function () {
244
- if (!(0, mdm_sdk_1.isEmptyValue)(customScripts)) {
245
- addInternalRequestInterceptor(customScriptRequestInterceptor);
246
- addInternalResponseInterceptor(customScriptResponseInterceptor);
247
- return function () {
248
- removeInternalRequestInterceptor(customScriptRequestInterceptor);
249
- removeInternalResponseInterceptor(customScriptResponseInterceptor);
250
- };
242
+ if ((0, mdm_sdk_1.isEmptyValue)(customScripts) || !metadata) {
243
+ return;
251
244
  }
252
- }, [config]);
245
+ addInternalRequestInterceptor(customScriptRequestInterceptor);
246
+ addInternalResponseInterceptor(customScriptResponseInterceptor);
247
+ return function () {
248
+ removeInternalRequestInterceptor(customScriptRequestInterceptor);
249
+ removeInternalResponseInterceptor(customScriptResponseInterceptor);
250
+ };
251
+ }, [config, metadata]);
253
252
  };
254
253
  exports.useCustomScripts = useCustomScripts;
@@ -14,6 +14,7 @@ export var useWorkflowTasks = function (config) {
14
14
  var tenant = useSelector(mdmModule.selectors.getTenant);
15
15
  var entityUri = useSelector(mdmModule.selectors.getEntityUri);
16
16
  var isEditableMode = useSelector(mdmModule.selectors.getIsEditableMode);
17
+ var entityLastLoadedTime = useSelector(mdmModule.selectors.getProfileLastLoadedTime);
17
18
  var checkWorkflowPermission = useWorkflowCheckPermission();
18
19
  var canViewTasks = checkWorkflowPermission('VIEW_TASKS');
19
20
  var enabled = !!(workflowPath && environment) && isWorkflowEnabled && canViewTasks;
@@ -45,7 +46,18 @@ export var useWorkflowTasks = function (config) {
45
46
  .finally(function () {
46
47
  setLoading(false);
47
48
  });
48
- }, [entityUri, environment, safePromise, tenant, workflowPath, assignee, showClosedTasks, processTypes]);
49
+ // eslint-disable-next-line react-hooks/exhaustive-deps
50
+ }, [
51
+ entityUri,
52
+ environment,
53
+ safePromise,
54
+ tenant,
55
+ workflowPath,
56
+ assignee,
57
+ showClosedTasks,
58
+ processTypes,
59
+ entityLastLoadedTime
60
+ ]);
49
61
  useEffect(function () {
50
62
  if (entityUri && enabled && !isTempUri(entityUri)) {
51
63
  loadTasks();
@@ -57,7 +57,7 @@ var processFromQuery = function (params, permissions, workflowPath, tenant, envi
57
57
  if (!workflowPath) {
58
58
  return new Promise(function (resolve) { return resolve({ errorMessage: 'Workflow path is not defined' }); });
59
59
  }
60
- var errors = validateParams(__assign({ url: '/processInstances/_generateFromQuery' }, params), permissions);
60
+ var errors = validateParams(__assign({ validationUrl: '/processInstances/_generateFromQuery' }, params), permissions);
61
61
  if (errors) {
62
62
  return new Promise(function (resolve) { return resolve(errors); });
63
63
  }
@@ -117,7 +117,7 @@ var sendApiRequest = function (params, permissions, signHandler) { return __awai
117
117
  case 0:
118
118
  errors = validateParams(params, permissions);
119
119
  if (errors) {
120
- return [2 /*return*/, errors];
120
+ return [2 /*return*/, Promise.reject(errors)];
121
121
  }
122
122
  return [4 /*yield*/, getHeaders(params, signHandler)];
123
123
  case 1:
@@ -134,18 +134,18 @@ var sendApiRequest = function (params, permissions, signHandler) { return __awai
134
134
  });
135
135
  }); };
136
136
  var validateParams = function (params, permissions) {
137
- var url = params.url;
138
- if (!url)
137
+ var validationUrl = params.validationUrl;
138
+ if (!validationUrl)
139
139
  return { errorMessage: 'URL is empty' };
140
140
  var allowed = permissions === null || permissions === void 0 ? void 0 : permissions.some(function (permission) {
141
141
  var _a;
142
- var urlOrigin = (_a = url.match(/^(https?:\/\/[^:/?#]*).*$/)) === null || _a === void 0 ? void 0 : _a[1];
142
+ var urlOrigin = (_a = validationUrl.match(/^(https?:\/\/[^:/?#]*).*$/)) === null || _a === void 0 ? void 0 : _a[1];
143
143
  var permRegex = new RegExp('^' + permission + '$');
144
144
  var decodedPerm = permission.replace(/\/*$/, '');
145
- return (decodedPerm === url ||
145
+ return (decodedPerm === validationUrl ||
146
146
  (urlOrigin && urlOrigin === decodedPerm) ||
147
- ((decodedPerm === null || decodedPerm === void 0 ? void 0 : decodedPerm.startsWith('/')) && (url === null || url === void 0 ? void 0 : url.startsWith(decodedPerm))) ||
148
- (permission && permRegex.test(url)));
147
+ ((decodedPerm === null || decodedPerm === void 0 ? void 0 : decodedPerm.startsWith('/')) && (validationUrl === null || validationUrl === void 0 ? void 0 : validationUrl.startsWith(decodedPerm))) ||
148
+ (permission && permRegex.test(validationUrl)));
149
149
  });
150
150
  if (!allowed || ((permissions === null || permissions === void 0 ? void 0 : permissions.length) || 0) === 0) {
151
151
  return { errorMessage: 'Not enough permissions' };
@@ -156,8 +156,13 @@ export var processRequest = function (_a) {
156
156
  var name = _a.name, paramObject = _a.paramObject, 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;
157
157
  var handleRequest = function (request) {
158
158
  request
159
+ .then(function (response) { return (response.json ? response.json() : response); })
159
160
  .then(function (data) {
160
- worker.postMessage(__assign({ action: 'response', result: { data: data, headers: paramObject.params.headers, status: 200 } }, paramObject.params));
161
+ worker.postMessage(__assign({ action: 'response', result: {
162
+ data: JSON.parse(JSON.stringify(data)),
163
+ headers: paramObject.params.headers,
164
+ status: 200
165
+ } }, paramObject.params));
161
166
  })
162
167
  .catch(function (error) {
163
168
  worker.postMessage(__assign({ action: 'response', result: { data: error, headers: paramObject.params.headers, status: 0 } }, paramObject.params));
@@ -29,9 +29,10 @@ export declare const setUpRequestInterceptor: ({ apiPath, reltioPath, tenant, pr
29
29
  processApiRequest: any;
30
30
  workerRef: any;
31
31
  setRequestListeners: any;
32
- }) => ({ options, url, next }: {
32
+ }) => ({ options, url, next, resolve }: {
33
33
  next: (url: string, options: RequestInit) => void;
34
34
  abort?: (error: Error) => void;
35
+ resolve: (data: unknown) => void;
35
36
  url: string;
36
37
  options: RequestInit;
37
38
  }) => void;
@@ -131,14 +131,14 @@ export var setUpQooxdooResponseInterceptor = function (_a) {
131
131
  export var setUpRequestInterceptor = function (_a) {
132
132
  var apiPath = _a.apiPath, reltioPath = _a.reltioPath, tenant = _a.tenant, processApiRequest = _a.processApiRequest, workerRef = _a.workerRef, setRequestListeners = _a.setRequestListeners;
133
133
  return function (_a) {
134
- var _b = _a.options, options = _b === void 0 ? {} : _b, url = _a.url, next = _a.next;
134
+ var _b = _a.options, options = _b === void 0 ? {} : _b, url = _a.url, next = _a.next, resolve = _a.resolve;
135
135
  var fakeURL = url.startsWith('/') && !url.startsWith(apiPath)
136
136
  ? "".concat(reltioPath, "/api/").concat(tenant).concat(url)
137
137
  : "".concat(reltioPath).concat(url.replace(apiPath, ''));
138
138
  var isProcessableUrl = isURLtoProcess(processApiRequest, fakeURL);
139
139
  if (isProcessableUrl) {
140
140
  var requestId = nanoid();
141
- setRequestListeners(options, next, requestId);
141
+ setRequestListeners(options, next, requestId, resolve);
142
142
  workerRef.current.postMessage({
143
143
  action: 'apiRequest',
144
144
  id: requestId,
@@ -1,5 +1,5 @@
1
1
  import { CSSProperties } from 'react';
2
- import { CustomActionViewConfig, CustomActionExtension } from '@reltio/mdm-sdk';
2
+ import { CustomActionExtension, CustomActionViewConfig } from '@reltio/mdm-sdk';
3
3
  declare type Config = CustomActionViewConfig | CustomActionExtension;
4
4
  export declare const useAPI: (config?: Config) => {
5
5
  html: HTMLElement;
@@ -12,23 +12,23 @@ var __assign = (this && this.__assign) || function () {
12
12
  import { useCallback, useContext, useEffect, useRef, useState } from 'react';
13
13
  import { useDispatch, useSelector } from 'react-redux';
14
14
  import mdmModule, { ui } from '@reltio/mdm-module';
15
- import { CustomAction, CustomScriptPlatform, initializeWebWorker, isEmptyValue } from '@reltio/mdm-sdk';
16
- import { omit } from 'ramda';
15
+ import { CustomAction, CustomScriptPlatform, initializeWebWorker, isEmptyValue, RequestAction } from '@reltio/mdm-sdk';
16
+ import { always, assocPath, both, concat, evolve, has, ifElse, omit, pathEq, pathOr, pipe, replace, startsWith, when } from 'ramda';
17
17
  import { useWorkflowCheckPermission } from '../../components/workflow';
18
18
  import { useHtmlSanitizer } from '../useHtmlSanitizer';
19
19
  import { InterceptHandlersContext, SandboxAPIContext, SnackbarContext } from '../../contexts';
20
20
  import { processRequest } from './API';
21
- import { getWorkerURL, resetHtml, isNewUI, setUpResponseInterceptor, setUpRequestInterceptor, setUpQooxdooRequestInterceptor, setUpQooxdooResponseInterceptor } from './helpers';
21
+ import { getWorkerURL, isNewUI, resetHtml, setUpQooxdooRequestInterceptor, setUpQooxdooResponseInterceptor, setUpRequestInterceptor, setUpResponseInterceptor } from './helpers';
22
22
  export var useAPI = function (config) {
23
- var _a, _b;
23
+ var _a, _b, _c, _d;
24
24
  if (config === void 0) { config = {}; }
25
- var _c = useState(), html = _c[0], setHtml = _c[1];
26
- var _d = useState([]), listenersToReset = _d[0], setListenersToReset = _d[1];
27
- var _e = useState([]), popupListenersToReset = _e[0], setPopupListenersToReset = _e[1];
28
- var _f = useState(true), visible = _f[0], setVisible = _f[1];
29
- var _g = useState(), popup = _g[0], setPopup = _g[1];
30
- var _h = useState(null), tooltip = _h[0], setTooltip = _h[1];
31
- var _j = useState({}), customStyles = _j[0], setCustomStyles = _j[1];
25
+ var _e = useState(), html = _e[0], setHtml = _e[1];
26
+ var _f = useState([]), listenersToReset = _f[0], setListenersToReset = _f[1];
27
+ var _g = useState([]), popupListenersToReset = _g[0], setPopupListenersToReset = _g[1];
28
+ var _h = useState(true), visible = _h[0], setVisible = _h[1];
29
+ var _j = useState(), popup = _j[0], setPopup = _j[1];
30
+ var _k = useState(null), tooltip = _k[0], setTooltip = _k[1];
31
+ var _l = useState({}), customStyles = _l[0], setCustomStyles = _l[1];
32
32
  var workerRef = useRef();
33
33
  var requestListeners = useRef({});
34
34
  var responseListeners = useRef({});
@@ -51,7 +51,7 @@ export var useAPI = function (config) {
51
51
  var entityUri = useSelector(mdmModule.selectors.getEntityUri);
52
52
  var isEditableMode = useSelector(mdmModule.selectors.getIsEditableMode);
53
53
  var environment = useSelector(mdmModule.selectors.getWorkflowEnvironmentUrl);
54
- var _k = useSelector(mdmModule.selectors.getSearchProviderData) || {}, typeSearch = _k.type, search = _k.data;
54
+ var _m = useSelector(mdmModule.selectors.getSearchProviderData) || {}, typeSearch = _m.type, search = _m.data;
55
55
  var searchQuery = typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null;
56
56
  var isOldUI = !isNewUI(servicesPath);
57
57
  var supportedInterceptHandlers = isOldUI ? qxApi.interceptors : interceptHandlers;
@@ -59,7 +59,6 @@ export var useAPI = function (config) {
59
59
  var innerText = '';
60
60
  var popupText = '';
61
61
  var process = function (_a) {
62
- var _b, _c;
63
62
  var task = _a.task, worker = _a.worker;
64
63
  if (task) {
65
64
  switch (task.action) {
@@ -143,40 +142,38 @@ export var useAPI = function (config) {
143
142
  break;
144
143
  }
145
144
  case CustomAction.REQUEST: {
146
- if (((_c = (_b = task.params) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.origin) !== 'ui') {
147
- processRequest(__assign({ name: task.params.name, paramObject: task, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, servicesPath: servicesPath, apiPath: isOldUI ? apiPath : reltioPath, tenant: tenant, workflowPath: workflowPath, entity: entity, entityUri: entityUri, environment: environment, query: searchQuery, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
148
- }
149
- else {
150
- var _d = task.params, headers = _d.headers, id = _d.id, fakeURL = _d.url, method = _d.method, data = _d.data;
151
- var url = fakeURL.replace(reltioPath, apiPath);
152
- if (requestListeners.current[headers.requestId]) {
153
- requestListeners.current[headers.requestId].next(url, {
154
- body: data,
155
- id: id,
156
- task: task,
157
- headers: headers,
158
- method: method
159
- });
160
- requestListeners.current = omit([headers.requestId], requestListeners.current);
161
- }
162
- }
145
+ var processedApiPath = isOldUI ? reltioPath : apiPath;
146
+ var isGlobalUrl = startsWith('/', pathOr('', ['params', 'url'], task)) &&
147
+ !startsWith(apiPath, pathOr('', ['params', 'url'], task));
148
+ var processedParams = pipe(evolve({
149
+ url: ifElse(both(always(isGlobalUrl), always(pathEq(['params', 'name'], RequestAction.API, task))), concat("".concat(processedApiPath, "/api/").concat(tenant)), replace(reltioPath, apiPath))
150
+ }), when(has('url'), assocPath(['validationUrl'], task.params.url)))(task.params);
151
+ var processedTask = __assign(__assign({}, task), { params: processedParams });
152
+ processRequest(__assign({ name: processedTask.params.name, paramObject: processedTask, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, servicesPath: servicesPath, apiPath: processedApiPath, tenant: tenant, workflowPath: workflowPath, entity: entity, entityUri: entityUri, environment: environment, query: searchQuery, openSearch: openSearch, workflowCheckPermission: workflowCheckPermission }, qxApi));
163
153
  break;
164
154
  }
165
- case CustomAction.RETURN_PROCESSED_API_RESPONSE:
166
- case CustomAction.RETURN_PROCESSED_API_REQUEST: {
167
- var _e = task.params, id = _e.id, data = _e.data;
155
+ case CustomAction.RETURN_PROCESSED_API_RESPONSE: {
156
+ var _b = task.params, id = _b.id, data = _b.data;
168
157
  if (responseListeners.current[id]) {
169
158
  responseListeners.current[id].next(data);
170
159
  responseListeners.current = omit([id], responseListeners.current);
171
160
  }
172
161
  break;
173
162
  }
163
+ case CustomAction.RETURN_PROCESSED_API_REQUEST: {
164
+ var _c = task.params, id = _c.id, data = _c.data;
165
+ if (requestListeners.current[id]) {
166
+ requestListeners.current[id].resolve(data);
167
+ requestListeners.current = omit([id], requestListeners.current);
168
+ }
169
+ break;
170
+ }
174
171
  }
175
172
  }
176
173
  };
177
- var setRequestListeners = function (options, next, requestId) {
174
+ var setRequestListeners = function (options, next, requestId, resolve) {
178
175
  var _a;
179
- requestListeners.current = __assign(__assign({}, requestListeners.current), (_a = {}, _a[requestId] = { options: options, next: next, id: requestId }, _a));
176
+ requestListeners.current = __assign(__assign({}, requestListeners.current), (_a = {}, _a[requestId] = { options: options, next: next, id: requestId, resolve: resolve }, _a));
180
177
  };
181
178
  var setResponseListeners = function (next, responseId) {
182
179
  var _a;
@@ -203,9 +200,25 @@ export var useAPI = function (config) {
203
200
  var _a;
204
201
  (_a = workerRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({ action: 'event', type: type, data: data });
205
202
  };
203
+ var pendingInterceptors = useRef(false);
204
+ var needDelayedRequestForInterceptors = !isOldUI &&
205
+ interceptHandlers &&
206
+ !isEmptyValue(config.action) &&
207
+ config.action.platform !== CustomScriptPlatform.CLASSIC &&
208
+ (((_c = config === null || config === void 0 ? void 0 : config.action) === null || _c === void 0 ? void 0 : _c.processApiRequest) || ((_d = config === null || config === void 0 ? void 0 : config.action) === null || _d === void 0 ? void 0 : _d.processApiResponse));
209
+ if (needDelayedRequestForInterceptors) {
210
+ if (!pendingInterceptors.current && !workerRef.current) {
211
+ interceptHandlers.startInterceptorInit();
212
+ pendingInterceptors.current = true;
213
+ }
214
+ }
206
215
  useEffect(function () {
207
216
  if (!isEmptyValue(config.action) && config.action.platform !== CustomScriptPlatform.CLASSIC) {
208
217
  workerRef.current = initializeWebWorker(workerUrl, process, config);
218
+ if (pendingInterceptors.current) {
219
+ interceptHandlers.finishInterceptorInit();
220
+ pendingInterceptors.current = false;
221
+ }
209
222
  postEventMessage('updateEntity', entity);
210
223
  }
211
224
  }, [entity, config]);
@@ -244,6 +257,10 @@ export var useAPI = function (config) {
244
257
  else {
245
258
  addInternalRequestInterceptor(requestInterceptor);
246
259
  addInternalResponseInterceptor(responseInterceptor);
260
+ workerRef.current.onerror = function () {
261
+ removeInternalRequestInterceptor_1(requestInterceptor);
262
+ removeInternalResponseInterceptor_1(responseInterceptor);
263
+ };
247
264
  return function () {
248
265
  removeInternalRequestInterceptor_1(requestInterceptor);
249
266
  removeInternalResponseInterceptor_1(responseInterceptor);
@@ -34,7 +34,7 @@ import { useDispatch, useSelector } from 'react-redux';
34
34
  import mdmModule, { ui } from '@reltio/mdm-module';
35
35
  import { CustomAction, CustomScriptPlatform, initializeWebWorker, isEmptyValue } from '@reltio/mdm-sdk';
36
36
  import nanoid from 'nanoid';
37
- import { find, map, omit, pick, pipe, prop } from 'ramda';
37
+ import { assocPath, evolve, find, has, map, omit, pick, pipe, prop, replace, when } from 'ramda';
38
38
  import { useWorkflowCheckPermission } from '../components/workflow';
39
39
  import { InterceptHandlersContext, SandboxAPIContext, SnackbarContext } from '../contexts';
40
40
  import { getWorkerURL, processRequest } from './useAPI';
@@ -49,6 +49,7 @@ var getCustomViewConfig = function (config) {
49
49
  return __assign({ action: { processApiResponse: processApiResponse, processApiRequest: processApiRequest, permissions: permissions, files: files } }, otherProps);
50
50
  };
51
51
  export var useCustomScripts = function (config) {
52
+ var _a;
52
53
  var customScripts = config.reduce(function (acc, customScript) {
53
54
  if (customScript.platform !== CustomScriptPlatform.CLASSIC) {
54
55
  return __spreadArray(__spreadArray([], acc, true), [__assign(__assign({}, customScript), { actionId: nanoid() })], false);
@@ -56,10 +57,10 @@ export var useCustomScripts = function (config) {
56
57
  return acc;
57
58
  }, []);
58
59
  var showSnackbarMessage = useContext(SnackbarContext);
59
- var _a = useContext(InterceptHandlersContext), addInternalRequestInterceptor = _a.addInternalRequestInterceptor, addInternalResponseInterceptor = _a.addInternalResponseInterceptor, removeInternalRequestInterceptor = _a.removeInternalRequestInterceptor, removeInternalResponseInterceptor = _a.removeInternalResponseInterceptor;
60
+ var _b = useContext(InterceptHandlersContext), addInternalRequestInterceptor = _b.addInternalRequestInterceptor, addInternalResponseInterceptor = _b.addInternalResponseInterceptor, removeInternalRequestInterceptor = _b.removeInternalRequestInterceptor, removeInternalResponseInterceptor = _b.removeInternalResponseInterceptor;
60
61
  var qxApi = useContext(SandboxAPIContext);
61
62
  var dispatch = useDispatch();
62
- var metadata = useSelector(mdmModule.selectors.getMetadata) || {};
63
+ var metadata = (_a = useSelector(mdmModule.selectors.getMetadata)) !== null && _a !== void 0 ? _a : null;
63
64
  var entity = useSelector(mdmModule.selectors.getEntity) || {};
64
65
  var uiPath = useSelector(mdmModule.selectors.getUIPath);
65
66
  var servicesPath = useSelector(mdmModule.selectors.getServicesPath);
@@ -72,13 +73,12 @@ export var useCustomScripts = function (config) {
72
73
  var entityUri = useSelector(mdmModule.selectors.getEntityUri);
73
74
  var environment = useSelector(mdmModule.selectors.getWorkflowEnvironmentUrl);
74
75
  var workflowCheckPermission = useWorkflowCheckPermission();
75
- var _b = useSelector(mdmModule.selectors.getSearchProviderData) || {}, typeSearch = _b.type, search = _b.data;
76
+ var _c = useSelector(mdmModule.selectors.getSearchProviderData) || {}, typeSearch = _c.type, search = _c.data;
76
77
  var openSearch = function (search) { return dispatch(ui.actions.openSearch(search)); };
77
78
  var requestListeners = useRef({});
78
79
  var responseListeners = useRef({});
79
80
  var workers = useRef({});
80
- var process = function (_a) {
81
- var _b, _c;
81
+ var processMessageFromWorker = function (_a) {
82
82
  var task = _a.task, worker = _a.worker, config = _a.config;
83
83
  if (task) {
84
84
  switch (task.action) {
@@ -91,52 +91,50 @@ export var useCustomScripts = function (config) {
91
91
  break;
92
92
  }
93
93
  case CustomAction.REQUEST: {
94
- if (((_c = (_b = task.params) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.origin) !== 'ui') {
95
- processRequest(__assign({ name: task.params.name, paramObject: task, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, apiPath: apiPath, 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));
96
- }
97
- else {
98
- var _d = task.params, headers = _d.headers, id = _d.id, fakeURL = _d.url, method = _d.method, data = _d.data;
99
- var url = fakeURL.replace(reltioPath, apiPath);
100
- if (requestListeners.current[headers.requestId]) {
101
- requestListeners.current[headers.requestId].next(url, {
102
- body: data,
103
- id: id,
104
- task: task,
105
- headers: headers,
106
- method: method
107
- });
108
- requestListeners.current = omit([headers.requestId], requestListeners.current);
109
- }
110
- }
94
+ var processedParams = pipe(evolve({
95
+ url: replace(reltioPath, apiPath)
96
+ }), when(has('url'), assocPath(['validationUrl'], task.params.url)))(task.params);
97
+ var processedTask = __assign(__assign({}, task), { params: processedParams });
98
+ processRequest(__assign({ name: processedTask.params.name, paramObject: processedTask, permissions: config.action.permissions, worker: worker, metadata: metadata, config: config, user: user, apiPath: apiPath, 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));
111
99
  break;
112
100
  }
113
- case CustomAction.RETURN_PROCESSED_API_RESPONSE:
114
- case CustomAction.RETURN_PROCESSED_API_REQUEST: {
115
- var _e = task.params, id = _e.id, data = _e.data;
101
+ case CustomAction.RETURN_PROCESSED_API_RESPONSE: {
102
+ var _b = task.params, id = _b.id, data = _b.data;
116
103
  if (responseListeners.current[id]) {
117
104
  responseListeners.current[id].next(data);
118
105
  responseListeners.current = omit([id], responseListeners.current);
119
106
  }
120
107
  break;
121
108
  }
109
+ case CustomAction.RETURN_PROCESSED_API_REQUEST: {
110
+ var _c = task.params, id = _c.id, data = _c.data;
111
+ if (requestListeners.current[id]) {
112
+ requestListeners.current[id].resolve(data);
113
+ requestListeners.current = omit([id], requestListeners.current);
114
+ }
115
+ break;
116
+ }
122
117
  }
123
118
  }
124
119
  };
125
120
  useEffect(function () {
121
+ if (metadata === null) {
122
+ return;
123
+ }
126
124
  workers.current = customScripts.reduce(function (acc, customScript) {
127
125
  var _a;
128
126
  var customViewConfig = getCustomViewConfig(customScript);
129
- return __assign(__assign({}, acc), (_a = {}, _a[customScript.actionId] = initializeWebWorker(workerUrl, process, customViewConfig), _a));
127
+ return __assign(__assign({}, acc), (_a = {}, _a[customScript.actionId] = initializeWebWorker(workerUrl, processMessageFromWorker, customViewConfig), _a));
130
128
  }, workers.current);
131
129
  return function () {
132
130
  Object.keys(workers.current).forEach(function (actionId) {
133
131
  workers.current[actionId].terminate();
134
132
  });
135
133
  };
136
- }, [config]);
134
+ }, [config, metadata]);
137
135
  var customScriptRequestInterceptor = function (_a) {
138
136
  var _b;
139
- var _c = _a.options, options = _c === void 0 ? {} : _c, url = _a.url, next = _a.next;
137
+ var _c = _a.options, options = _c === void 0 ? {} : _c, url = _a.url, next = _a.next, resolve = _a.resolve;
140
138
  var fakeURL = url.startsWith('/') && !url.startsWith(apiPath)
141
139
  ? "".concat(reltioPath, "/api/").concat(tenant).concat(url)
142
140
  : "".concat(reltioPath).concat(url.replace(apiPath, ''));
@@ -146,7 +144,7 @@ export var useCustomScripts = function (config) {
146
144
  }), prop('actionId'))(customScripts);
147
145
  if (actionId) {
148
146
  var requestId = nanoid();
149
- requestListeners.current = __assign(__assign({}, requestListeners.current), (_b = {}, _b[requestId] = { options: options, next: next, id: requestId }, _b));
147
+ requestListeners.current = __assign(__assign({}, requestListeners.current), (_b = {}, _b[requestId] = { options: options, next: next, id: requestId, resolve: resolve }, _b));
150
148
  workers.current[actionId].postMessage({
151
149
  action: 'apiRequest',
152
150
  id: requestId,
@@ -172,7 +170,7 @@ export var useCustomScripts = function (config) {
172
170
  responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[options.headers.requestId] = { next: next }, _a));
173
171
  workers.current[(_b = options.headers) === null || _b === void 0 ? void 0 : _b.actionId].postMessage({
174
172
  action: 'response',
175
- result: { data: data },
173
+ result: { data: data, status: response.status },
176
174
  id: options === null || options === void 0 ? void 0 : options.id,
177
175
  name: (_d = (_c = options === null || options === void 0 ? void 0 : options.task) === null || _c === void 0 ? void 0 : _c.params) === null || _d === void 0 ? void 0 : _d.name
178
176
  });
@@ -212,13 +210,14 @@ export var useCustomScripts = function (config) {
212
210
  }
213
211
  };
214
212
  useEffect(function () {
215
- if (!isEmptyValue(customScripts)) {
216
- addInternalRequestInterceptor(customScriptRequestInterceptor);
217
- addInternalResponseInterceptor(customScriptResponseInterceptor);
218
- return function () {
219
- removeInternalRequestInterceptor(customScriptRequestInterceptor);
220
- removeInternalResponseInterceptor(customScriptResponseInterceptor);
221
- };
213
+ if (isEmptyValue(customScripts) || !metadata) {
214
+ return;
222
215
  }
223
- }, [config]);
216
+ addInternalRequestInterceptor(customScriptRequestInterceptor);
217
+ addInternalResponseInterceptor(customScriptResponseInterceptor);
218
+ return function () {
219
+ removeInternalRequestInterceptor(customScriptRequestInterceptor);
220
+ removeInternalResponseInterceptor(customScriptResponseInterceptor);
221
+ };
222
+ }, [config, metadata]);
224
223
  };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.1435",
3
+ "version": "1.4.1437",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
7
7
  "dependencies": {
8
8
  "@date-io/moment": "^1.3.5",
9
9
  "@react-google-maps/api": "2.7.0",
10
- "@reltio/mdm-module": "^1.4.1435",
11
- "@reltio/mdm-sdk": "^1.4.1435",
10
+ "@reltio/mdm-module": "^1.4.1437",
11
+ "@reltio/mdm-sdk": "^1.4.1437",
12
12
  "classnames": "^2.2.5",
13
13
  "d3-cloud": "^1.2.5",
14
14
  "d3-geo": "^2.0.1",