@reltio/components 1.4.1578 → 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.
@@ -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, RequestAction } from '@reltio/mdm-sdk';
16
- import { always, assocPath, both, concat, evolve, has, ifElse, omit, pathEq, pathOr, pipe, replace, startsWith, when } from 'ramda';
15
+ import { CustomAction, CustomScriptPlatform, initializeWebWorker, isEmptyValue } from '@reltio/mdm-sdk';
16
+ import { omit } 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, isNewUI, resetHtml, setUpQooxdooRequestInterceptor, setUpQooxdooResponseInterceptor, setUpRequestInterceptor, setUpResponseInterceptor } from './helpers';
21
+ import { getWorkerURL, isValidCustomScript, resetHtml, getProcessedTask, setUpRequestInterceptor, setUpResponseInterceptor } from './helpers';
22
22
  export var useAPI = function (config) {
23
- var _a, _b, _c, _d;
24
23
  if (config === void 0) { config = {}; }
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];
24
+ var _a = config.action || {}, processApiRequest = _a.processApiRequest, processApiResponse = _a.processApiResponse, platform = _a.platform;
25
+ var _b = useState(), html = _b[0], setHtml = _b[1];
26
+ var _c = useState([]), listenersToReset = _c[0], setListenersToReset = _c[1];
27
+ var _d = useState([]), popupListenersToReset = _d[0], setPopupListenersToReset = _d[1];
28
+ var _e = useState(true), visible = _e[0], setVisible = _e[1];
29
+ var _f = useState(), popup = _f[0], setPopup = _f[1];
30
+ var _g = useState(null), tooltip = _g[0], setTooltip = _g[1];
31
+ var _h = useState({}), customStyles = _h[0], setCustomStyles = _h[1];
32
32
  var workerRef = useRef();
33
33
  var requestListeners = useRef({});
34
34
  var responseListeners = useRef({});
@@ -51,10 +51,8 @@ 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 _m = useSelector(mdmModule.selectors.getSearchProviderData) || {}, typeSearch = _m.type, search = _m.data;
54
+ var _j = useSelector(mdmModule.selectors.getSearchProviderData) || {}, typeSearch = _j.type, search = _j.data;
55
55
  var searchQuery = typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null;
56
- var isOldUI = !isNewUI(servicesPath);
57
- var supportedInterceptHandlers = isOldUI ? qxApi.interceptors : interceptHandlers;
58
56
  var openSearch = function (search) { return dispatch(ui.actions.openSearch(search)); };
59
57
  var innerText = '';
60
58
  var popupText = '';
@@ -143,15 +141,8 @@ export var useAPI = function (config) {
143
141
  break;
144
142
  }
145
143
  case CustomAction.REQUEST: {
146
- var processedApiPath = isOldUI ? reltioPath : apiPath;
147
- var isGlobalUrl = startsWith('/', pathOr('', ['params', 'url'], task)) &&
148
- !startsWith(apiPath, pathOr('', ['params', 'url'], task));
149
- var isApiAction = pathEq(['params', 'name'], RequestAction.API, task);
150
- var processedParams = pipe(evolve({
151
- url: ifElse(both(always(isGlobalUrl), always(isApiAction)), concat("".concat(processedApiPath, "/api/").concat(tenant)), replace(reltioPath, apiPath))
152
- }), when(has('url'), assocPath(['validationUrl'], task.params.url)))(task.params);
153
- var processedTask = __assign(__assign({}, task), { params: processedParams });
154
- 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));
144
+ var processedTask = getProcessedTask(task, apiPath, reltioPath, tenant);
145
+ 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));
155
146
  break;
156
147
  }
157
148
  case CustomAction.RETURN_PROCESSED_API_RESPONSE: {
@@ -181,20 +172,18 @@ export var useAPI = function (config) {
181
172
  var _a;
182
173
  responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[responseId] = { next: next }, _a));
183
174
  };
184
- var qooxdooRequestInterceptor = setUpQooxdooRequestInterceptor({ workerRef: workerRef, setRequestListeners: setRequestListeners });
185
- var qooxdooResponseInterceptor = setUpQooxdooResponseInterceptor({ workerRef: workerRef, setResponseListeners: setResponseListeners });
186
175
  var requestInterceptor = setUpRequestInterceptor({
187
176
  apiPath: apiPath,
188
177
  reltioPath: reltioPath,
189
178
  tenant: tenant,
190
- processApiRequest: (_a = config === null || config === void 0 ? void 0 : config.action) === null || _a === void 0 ? void 0 : _a.processApiRequest,
179
+ processApiRequest: processApiRequest,
191
180
  workerRef: workerRef,
192
181
  setRequestListeners: setRequestListeners
193
182
  });
194
183
  var responseInterceptor = setUpResponseInterceptor({
195
184
  reltioPath: reltioPath,
196
185
  apiPath: apiPath,
197
- processApiResponse: (_b = config === null || config === void 0 ? void 0 : config.action) === null || _b === void 0 ? void 0 : _b.processApiResponse,
186
+ processApiResponse: processApiResponse,
198
187
  workerRef: workerRef,
199
188
  setResponseListeners: setResponseListeners
200
189
  });
@@ -203,11 +192,10 @@ export var useAPI = function (config) {
203
192
  (_a = workerRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({ action: 'event', type: type, data: data });
204
193
  };
205
194
  var pendingInterceptors = useRef(false);
206
- var needDelayedRequestForInterceptors = !isOldUI &&
207
- interceptHandlers &&
195
+ var needDelayedRequestForInterceptors = interceptHandlers &&
208
196
  !isEmptyValue(config.action) &&
209
- config.action.platform !== CustomScriptPlatform.CLASSIC &&
210
- (((_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));
197
+ platform !== CustomScriptPlatform.CLASSIC &&
198
+ (processApiRequest || processApiResponse);
211
199
  if (needDelayedRequestForInterceptors) {
212
200
  if (!pendingInterceptors.current && !workerRef.current) {
213
201
  interceptHandlers.startInterceptorInit();
@@ -215,7 +203,7 @@ export var useAPI = function (config) {
215
203
  }
216
204
  }
217
205
  useEffect(function () {
218
- if (!isEmptyValue(config.action) && config.action.platform !== CustomScriptPlatform.CLASSIC) {
206
+ if (isValidCustomScript(config.action)) {
219
207
  workerRef.current = initializeWebWorker(workerUrl, process, config);
220
208
  if (pendingInterceptors.current) {
221
209
  interceptHandlers.finishInterceptorInit();
@@ -244,30 +232,18 @@ export var useAPI = function (config) {
244
232
  postEventMessage('execute', null);
245
233
  }, [config]);
246
234
  useEffect(function () {
247
- var _a, _b, _c, _d;
248
- if (!isEmptyValue(supportedInterceptHandlers) &&
249
- (((_a = config === null || config === void 0 ? void 0 : config.action) === null || _a === void 0 ? void 0 : _a.processApiRequest) || ((_b = config === null || config === void 0 ? void 0 : config.action) === null || _b === void 0 ? void 0 : _b.processApiResponse))) {
250
- var addInternalRequestInterceptor = supportedInterceptHandlers.addInternalRequestInterceptor, addInternalResponseInterceptor = supportedInterceptHandlers.addInternalResponseInterceptor, removeInternalRequestInterceptor_1 = supportedInterceptHandlers.removeInternalRequestInterceptor, removeInternalResponseInterceptor_1 = supportedInterceptHandlers.removeInternalResponseInterceptor;
251
- if (isOldUI) {
252
- addInternalRequestInterceptor((_c = config === null || config === void 0 ? void 0 : config.action) === null || _c === void 0 ? void 0 : _c.processApiRequest, qooxdooRequestInterceptor);
253
- addInternalResponseInterceptor((_d = config === null || config === void 0 ? void 0 : config.action) === null || _d === void 0 ? void 0 : _d.processApiResponse, qooxdooResponseInterceptor);
254
- return function () {
255
- removeInternalRequestInterceptor_1(qooxdooRequestInterceptor);
256
- removeInternalResponseInterceptor_1(qooxdooResponseInterceptor);
257
- };
258
- }
259
- else {
260
- addInternalRequestInterceptor(requestInterceptor);
261
- addInternalResponseInterceptor(responseInterceptor);
262
- workerRef.current.onerror = function () {
263
- removeInternalRequestInterceptor_1(requestInterceptor);
264
- removeInternalResponseInterceptor_1(responseInterceptor);
265
- };
266
- return function () {
267
- removeInternalRequestInterceptor_1(requestInterceptor);
268
- removeInternalResponseInterceptor_1(responseInterceptor);
269
- };
270
- }
235
+ if (!isEmptyValue(interceptHandlers) && (processApiRequest || processApiResponse)) {
236
+ var addInternalRequestInterceptor = interceptHandlers.addInternalRequestInterceptor, addInternalResponseInterceptor = interceptHandlers.addInternalResponseInterceptor, removeInternalRequestInterceptor_1 = interceptHandlers.removeInternalRequestInterceptor, removeInternalResponseInterceptor_1 = interceptHandlers.removeInternalResponseInterceptor;
237
+ addInternalRequestInterceptor(requestInterceptor);
238
+ addInternalResponseInterceptor(responseInterceptor);
239
+ workerRef.current.onerror = function () {
240
+ removeInternalRequestInterceptor_1(requestInterceptor);
241
+ removeInternalResponseInterceptor_1(responseInterceptor);
242
+ };
243
+ return function () {
244
+ removeInternalRequestInterceptor_1(requestInterceptor);
245
+ removeInternalResponseInterceptor_1(responseInterceptor);
246
+ };
271
247
  }
272
248
  }, [config]);
273
249
  return { html: html, visible: visible, tooltip: tooltip, customStyles: customStyles, onClick: onClick, popup: popup };
@@ -32,19 +32,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
32
32
  import { useContext, useEffect, useRef } from 'react';
33
33
  import { useDispatch, useSelector } from 'react-redux';
34
34
  import mdmModule, { ui } from '@reltio/mdm-module';
35
- import { CustomAction, CustomScriptPlatform, initializeWebWorker, isEmptyValue, RequestAction } from '@reltio/mdm-sdk';
35
+ import { CustomAction, initializeWebWorker, isEmptyValue } from '@reltio/mdm-sdk';
36
36
  import { nanoid } from 'nanoid';
37
- import { always, assocPath, both, concat, evolve, find, has, ifElse, map, omit, pathEq, pathOr, pick, pipe, prop, replace, startsWith, when } from 'ramda';
37
+ import { omit } from 'ramda';
38
38
  import { useWorkflowCheckPermission } from '../components/workflow';
39
39
  import { InterceptHandlersContext, SandboxAPIContext, SnackbarContext } from '../contexts';
40
40
  import { getWorkerURL, processRequest } from './useAPI';
41
- import { isNewUI } from './useAPI/helpers';
42
- var isURLtoProcess = function (processApi, url) {
43
- return (processApi || []).some(function (request) {
44
- var regExp = new RegExp("^".concat(request, "$"));
45
- return request.replace(/\/*$/, '') === url || (request && regExp.test(url));
46
- });
47
- };
41
+ import { isValidCustomScript, isURLtoProcess, getProcessedTask, getRequestFakeUrl, getResponseFakeUrl } from './useAPI/helpers';
48
42
  var getCustomViewConfig = function (config) {
49
43
  var processApiResponse = config.processApiResponse, processApiRequest = config.processApiRequest, permissions = config.permissions, files = config.files, otherProps = __rest(config, ["processApiResponse", "processApiRequest", "permissions", "files"]);
50
44
  return __assign({ action: { processApiResponse: processApiResponse, processApiRequest: processApiRequest, permissions: permissions, files: files } }, otherProps);
@@ -52,7 +46,7 @@ var getCustomViewConfig = function (config) {
52
46
  export var useCustomScripts = function (config) {
53
47
  var _a;
54
48
  var customScripts = config.reduce(function (acc, customScript) {
55
- if (customScript.platform !== CustomScriptPlatform.CLASSIC) {
49
+ if (isValidCustomScript(customScript)) {
56
50
  return __spreadArray(__spreadArray([], acc, true), [__assign(__assign({}, customScript), { actionId: nanoid() })], false);
57
51
  }
58
52
  return acc;
@@ -92,16 +86,8 @@ export var useCustomScripts = function (config) {
92
86
  break;
93
87
  }
94
88
  case CustomAction.REQUEST: {
95
- var isOldUI = !isNewUI(servicesPath);
96
- var processedApiPath = isOldUI ? reltioPath : apiPath;
97
- var isGlobalUrl = startsWith('/', pathOr('', ['params', 'url'], task)) &&
98
- !startsWith(apiPath, pathOr('', ['params', 'url'], task));
99
- var isApiAction = pathEq(['params', 'name'], RequestAction.API, task);
100
- var processedParams = pipe(evolve({
101
- url: ifElse(both(always(isGlobalUrl), always(isApiAction)), concat("".concat(processedApiPath, "/api/").concat(tenant)), replace(reltioPath, apiPath))
102
- }), when(has('url'), assocPath(['validationUrl'], task.params.url)))(task.params);
103
- var processedTask = __assign(__assign({}, task), { params: processedParams });
104
- 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));
89
+ var processedTask = getProcessedTask(task, apiPath, reltioPath, tenant);
90
+ 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));
105
91
  break;
106
92
  }
107
93
  case CustomAction.RETURN_PROCESSED_API_RESPONSE: {
@@ -140,14 +126,13 @@ export var useCustomScripts = function (config) {
140
126
  }, [config, metadata]);
141
127
  var customScriptRequestInterceptor = function (_a) {
142
128
  var _b;
143
- var _c = _a.options, options = _c === void 0 ? {} : _c, url = _a.url, next = _a.next, resolve = _a.resolve;
144
- var fakeURL = url.startsWith('/') && !url.startsWith(apiPath)
145
- ? "".concat(reltioPath, "/api/").concat(tenant).concat(url)
146
- : "".concat(reltioPath).concat(url.replace(apiPath, ''));
147
- var actionId = pipe(map(pick(['actionId', 'processApiRequest'])), find(function (_a) {
129
+ var url = _a.url, next = _a.next, resolve = _a.resolve, options = _a.options;
130
+ var fakeURL = getRequestFakeUrl(url, apiPath, reltioPath, tenant);
131
+ var customScript = customScripts.find(function (_a) {
148
132
  var processApiRequest = _a.processApiRequest;
149
- return isURLtoProcess(processApiRequest, fakeURL);
150
- }), prop('actionId'))(customScripts);
133
+ return isURLtoProcess(fakeURL, processApiRequest);
134
+ });
135
+ var actionId = customScript === null || customScript === void 0 ? void 0 : customScript.actionId;
151
136
  if (actionId) {
152
137
  var requestId = nanoid();
153
138
  requestListeners.current = __assign(__assign({}, requestListeners.current), (_b = {}, _b[requestId] = { options: options, next: next, id: requestId, resolve: resolve }, _b));
@@ -156,7 +141,7 @@ export var useCustomScripts = function (config) {
156
141
  id: requestId,
157
142
  url: fakeURL,
158
143
  method: options.method,
159
- headers: __assign(__assign({}, options.headers), { origin: 'ui', requestId: requestId, actionId: actionId }),
144
+ headers: __assign(__assign({}, options.headers), { actionId: actionId }),
160
145
  data: options.body || options.data
161
146
  });
162
147
  }
@@ -165,20 +150,26 @@ export var useCustomScripts = function (config) {
165
150
  }
166
151
  };
167
152
  var customScriptResponseInterceptor = function (_a) {
168
- var _b;
169
153
  var url = _a.url, response = _a.response, next = _a.next, options = _a.options, abort = _a.abort;
170
- if (((_b = options === null || options === void 0 ? void 0 : options.headers) === null || _b === void 0 ? void 0 : _b.origin) === 'ui') {
154
+ var fakeURL = getResponseFakeUrl(url, apiPath, reltioPath);
155
+ var customScript = customScripts.find(function (_a) {
156
+ var processApiResponse = _a.processApiResponse;
157
+ return isURLtoProcess(fakeURL, processApiResponse);
158
+ });
159
+ var actionId = customScript === null || customScript === void 0 ? void 0 : customScript.actionId;
160
+ if (actionId) {
161
+ var responseId_1 = nanoid();
171
162
  response
172
163
  .json()
173
164
  .then(function (data) {
174
165
  var _a;
175
- var _b, _c, _d;
176
- responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[options.headers.requestId] = { next: next }, _a));
177
- workers.current[(_b = options.headers) === null || _b === void 0 ? void 0 : _b.actionId].postMessage({
178
- action: 'response',
179
- result: { data: data, status: response.status },
180
- id: options === null || options === void 0 ? void 0 : options.id,
181
- 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
166
+ responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[responseId_1] = { next: next }, _a));
167
+ workers.current[actionId].postMessage({
168
+ action: 'apiResponse',
169
+ id: responseId_1,
170
+ url: fakeURL,
171
+ method: options.method,
172
+ data: data
182
173
  });
183
174
  })
184
175
  .catch(function (error) {
@@ -186,33 +177,7 @@ export var useCustomScripts = function (config) {
186
177
  });
187
178
  }
188
179
  else {
189
- var fakeURL_1 = "".concat(reltioPath).concat(url.replace(apiPath, ''));
190
- var actionId_1 = pipe(map(pick(['actionId', 'processApiResponse'])), find(function (_a) {
191
- var processApiResponse = _a.processApiResponse;
192
- return isURLtoProcess(processApiResponse, fakeURL_1);
193
- }), prop('actionId'))(customScripts);
194
- if (actionId_1) {
195
- var responseId_1 = nanoid();
196
- response
197
- .json()
198
- .then(function (data) {
199
- var _a;
200
- responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[responseId_1] = { next: next }, _a));
201
- workers.current[actionId_1].postMessage({
202
- action: 'apiResponse',
203
- id: responseId_1,
204
- url: fakeURL_1,
205
- method: options.method,
206
- data: data
207
- });
208
- })
209
- .catch(function (error) {
210
- abort(error);
211
- });
212
- }
213
- else {
214
- next(response);
215
- }
180
+ next(response);
216
181
  }
217
182
  };
218
183
  useEffect(function () {
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.1578",
3
+ "version": "1.4.1580",
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.1578",
11
- "@reltio/mdm-sdk": "^1.4.1578",
10
+ "@reltio/mdm-module": "^1.4.1580",
11
+ "@reltio/mdm-sdk": "^1.4.1580",
12
12
  "classnames": "^2.2.5",
13
13
  "d3-cloud": "^1.2.5",
14
14
  "d3-geo": "^2.0.1",