@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
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { CustomActionTask, CustomActionTaskParams, CustomScript, RequestHandler, ResponseHandler } from '@reltio/mdm-sdk';
|
|
2
|
+
export declare const isValidCustomScript: (config?: CustomScript) => boolean;
|
|
3
|
+
export declare const isURLtoProcess: (url: string, processApi?: string[]) => boolean;
|
|
2
4
|
export declare const getWorkerURL: (uiPath: string, tenant: string) => string;
|
|
5
|
+
export declare const getRequestFakeUrl: (url: string, apiPath: string, reltioPath: string, tenant: string) => string;
|
|
6
|
+
export declare const getResponseFakeUrl: (url: string, apiPath: string, reltioPath: string) => string;
|
|
7
|
+
export declare const getProcessedTask: (task: CustomActionTask, apiPath: string, reltioPath: string, tenant: string) => CustomActionTask;
|
|
3
8
|
export declare const getFilesWithArrayBuffer: (files: FileList) => Promise<unknown[]>;
|
|
4
9
|
type ResetHTMLParams = {
|
|
5
10
|
worker: Worker;
|
|
@@ -10,18 +15,6 @@ type ResetHTMLParams = {
|
|
|
10
15
|
setHtml: any;
|
|
11
16
|
};
|
|
12
17
|
export declare const resetHtml: ({ worker, setTooltip, innerText, html, setListenersToReset, setHtml }: ResetHTMLParams) => void;
|
|
13
|
-
export declare const setUpQooxdooRequestInterceptor: ({ workerRef, setRequestListeners }: {
|
|
14
|
-
workerRef: any;
|
|
15
|
-
setRequestListeners: any;
|
|
16
|
-
}) => {
|
|
17
|
-
processApiRequest: (url: any, method: any, headers: any, data: any, next: any) => void;
|
|
18
|
-
};
|
|
19
|
-
export declare const setUpQooxdooResponseInterceptor: ({ workerRef, setResponseListeners }: {
|
|
20
|
-
workerRef: any;
|
|
21
|
-
setResponseListeners: any;
|
|
22
|
-
}) => {
|
|
23
|
-
processApiResponse: (url: any, method: any, data: any, next: any) => void;
|
|
24
|
-
};
|
|
25
18
|
export declare const setUpRequestInterceptor: ({ apiPath, reltioPath, tenant, processApiRequest, workerRef, setRequestListeners }: {
|
|
26
19
|
apiPath: any;
|
|
27
20
|
reltioPath: any;
|
|
@@ -29,24 +22,12 @@ export declare const setUpRequestInterceptor: ({ apiPath, reltioPath, tenant, pr
|
|
|
29
22
|
processApiRequest: any;
|
|
30
23
|
workerRef: any;
|
|
31
24
|
setRequestListeners: any;
|
|
32
|
-
}) =>
|
|
33
|
-
next: (url: string, options: RequestInit) => void;
|
|
34
|
-
abort?: (error: Error) => void;
|
|
35
|
-
resolve: (data: unknown) => void;
|
|
36
|
-
url: string;
|
|
37
|
-
options: RequestInit;
|
|
38
|
-
}) => void;
|
|
25
|
+
}) => RequestHandler<RequestInit & CustomActionTaskParams>;
|
|
39
26
|
export declare const setUpResponseInterceptor: ({ reltioPath, apiPath, processApiResponse, workerRef, setResponseListeners }: {
|
|
40
27
|
reltioPath: any;
|
|
41
28
|
apiPath: any;
|
|
42
29
|
processApiResponse: any;
|
|
43
30
|
workerRef: any;
|
|
44
31
|
setResponseListeners: any;
|
|
45
|
-
}) =>
|
|
46
|
-
url: any;
|
|
47
|
-
response: any;
|
|
48
|
-
next: any;
|
|
49
|
-
options: any;
|
|
50
|
-
abort: any;
|
|
51
|
-
}) => void;
|
|
32
|
+
}) => ResponseHandler<RequestInit & CustomActionTaskParams>;
|
|
52
33
|
export {};
|
|
@@ -9,17 +9,37 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
import { CustomScriptPlatform, RequestAction, isEmptyValue } from '@reltio/mdm-sdk';
|
|
12
13
|
import { nanoid } from 'nanoid';
|
|
13
|
-
export var
|
|
14
|
-
|
|
14
|
+
export var isValidCustomScript = function (config) {
|
|
15
|
+
var _a = config || {}, files = _a.files, platform = _a.platform;
|
|
16
|
+
return !isEmptyValue(files) && platform !== CustomScriptPlatform.CLASSIC;
|
|
17
|
+
};
|
|
18
|
+
export var isURLtoProcess = function (url, processApi) {
|
|
19
|
+
if (processApi === void 0) { processApi = []; }
|
|
20
|
+
return processApi.some(function (request) {
|
|
21
|
+
var regExp = new RegExp("^".concat(request, "$"));
|
|
22
|
+
return request.replace(/\/*$/, '') === url || (request && regExp.test(url));
|
|
23
|
+
});
|
|
15
24
|
};
|
|
16
25
|
export var getWorkerURL = function (uiPath, tenant) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
return "".concat(uiPath.replace("".concat(tenant, "/"), ''), "worker_api.js");
|
|
27
|
+
};
|
|
28
|
+
export var getRequestFakeUrl = function (url, apiPath, reltioPath, tenant) {
|
|
29
|
+
return url.startsWith(apiPath) ? "".concat(reltioPath).concat(url.replace(apiPath, '')) : "".concat(reltioPath, "/api/").concat(tenant).concat(url);
|
|
30
|
+
};
|
|
31
|
+
export var getResponseFakeUrl = function (url, apiPath, reltioPath) {
|
|
32
|
+
return "".concat(reltioPath).concat(url.replace(apiPath, ''));
|
|
33
|
+
};
|
|
34
|
+
export var getProcessedTask = function (task, apiPath, reltioPath, tenant) {
|
|
35
|
+
var _a = task.params, url = _a.url, name = _a.name;
|
|
36
|
+
if (!url) {
|
|
37
|
+
return task;
|
|
22
38
|
}
|
|
39
|
+
var isApiAction = name === RequestAction.API;
|
|
40
|
+
var isGlobalUrl = url.startsWith('/') && !url.startsWith(apiPath);
|
|
41
|
+
var newUrl = isGlobalUrl && isApiAction ? "".concat(apiPath, "/api/").concat(tenant).concat(url) : url.replace(reltioPath, apiPath);
|
|
42
|
+
return __assign(__assign({}, task), { params: __assign(__assign({}, task.params), { url: newUrl, validationUrl: url }) });
|
|
23
43
|
};
|
|
24
44
|
export var getFilesWithArrayBuffer = function (files) {
|
|
25
45
|
var readFilePromises = Array.from(files).map(function (file) {
|
|
@@ -88,54 +108,12 @@ export var resetHtml = function (_a) {
|
|
|
88
108
|
setListenersToReset(handlersToReset);
|
|
89
109
|
setHtml(docBlock);
|
|
90
110
|
};
|
|
91
|
-
var isURLtoProcess = function (processApi, url) {
|
|
92
|
-
return (processApi || []).some(function (request) {
|
|
93
|
-
var regExp = new RegExp("^".concat(request, "$"));
|
|
94
|
-
return request.replace(/\/*$/, '') === url || (request && regExp.test(url));
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
export var setUpQooxdooRequestInterceptor = function (_a) {
|
|
98
|
-
var workerRef = _a.workerRef, setRequestListeners = _a.setRequestListeners;
|
|
99
|
-
return ({
|
|
100
|
-
processApiRequest: function (url, method, headers, data, next) {
|
|
101
|
-
var requestId = nanoid();
|
|
102
|
-
var options = { url: url, method: method, headers: headers, noRequestProcessor: true };
|
|
103
|
-
setRequestListeners(options, next, requestId);
|
|
104
|
-
workerRef.current.postMessage({
|
|
105
|
-
action: 'apiRequest',
|
|
106
|
-
id: requestId,
|
|
107
|
-
url: url,
|
|
108
|
-
method: method,
|
|
109
|
-
headers: headers,
|
|
110
|
-
data: data
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
export var setUpQooxdooResponseInterceptor = function (_a) {
|
|
116
|
-
var workerRef = _a.workerRef, setResponseListeners = _a.setResponseListeners;
|
|
117
|
-
return ({
|
|
118
|
-
processApiResponse: function (url, method, data, next) {
|
|
119
|
-
var responseId = nanoid();
|
|
120
|
-
setResponseListeners(next, responseId);
|
|
121
|
-
workerRef.current.postMessage({
|
|
122
|
-
action: 'apiResponse',
|
|
123
|
-
id: responseId,
|
|
124
|
-
url: url,
|
|
125
|
-
method: method,
|
|
126
|
-
data: data
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
111
|
export var setUpRequestInterceptor = function (_a) {
|
|
132
112
|
var apiPath = _a.apiPath, reltioPath = _a.reltioPath, tenant = _a.tenant, processApiRequest = _a.processApiRequest, workerRef = _a.workerRef, setRequestListeners = _a.setRequestListeners;
|
|
133
113
|
return function (_a) {
|
|
134
|
-
var _b = _a.options, options = _b === void 0 ? {} : _b
|
|
135
|
-
var fakeURL = url
|
|
136
|
-
|
|
137
|
-
: "".concat(reltioPath).concat(url.replace(apiPath, ''));
|
|
138
|
-
var isProcessableUrl = isURLtoProcess(processApiRequest, fakeURL);
|
|
114
|
+
var url = _a.url, next = _a.next, resolve = _a.resolve, _b = _a.options, options = _b === void 0 ? {} : _b;
|
|
115
|
+
var fakeURL = getRequestFakeUrl(url, apiPath, reltioPath, tenant);
|
|
116
|
+
var isProcessableUrl = isURLtoProcess(fakeURL, processApiRequest);
|
|
139
117
|
if (isProcessableUrl) {
|
|
140
118
|
var requestId = nanoid();
|
|
141
119
|
setRequestListeners(options, next, requestId, resolve);
|
|
@@ -144,7 +122,7 @@ export var setUpRequestInterceptor = function (_a) {
|
|
|
144
122
|
id: requestId,
|
|
145
123
|
url: fakeURL,
|
|
146
124
|
method: options.method,
|
|
147
|
-
headers:
|
|
125
|
+
headers: options.headers,
|
|
148
126
|
data: options.body
|
|
149
127
|
});
|
|
150
128
|
}
|
|
@@ -156,19 +134,21 @@ export var setUpRequestInterceptor = function (_a) {
|
|
|
156
134
|
export var setUpResponseInterceptor = function (_a) {
|
|
157
135
|
var reltioPath = _a.reltioPath, apiPath = _a.apiPath, processApiResponse = _a.processApiResponse, workerRef = _a.workerRef, setResponseListeners = _a.setResponseListeners;
|
|
158
136
|
return function (_a) {
|
|
159
|
-
var _b;
|
|
160
137
|
var url = _a.url, response = _a.response, next = _a.next, options = _a.options, abort = _a.abort;
|
|
161
|
-
|
|
138
|
+
var fakeURL = getResponseFakeUrl(url, apiPath, reltioPath);
|
|
139
|
+
var isProcessableUrl = isURLtoProcess(fakeURL, processApiResponse);
|
|
140
|
+
if (isProcessableUrl) {
|
|
141
|
+
var responseId_1 = nanoid();
|
|
162
142
|
response
|
|
163
143
|
.json()
|
|
164
144
|
.then(function (data) {
|
|
165
|
-
|
|
166
|
-
setResponseListeners(next, options.headers.requestId);
|
|
145
|
+
setResponseListeners(next, responseId_1);
|
|
167
146
|
workerRef.current.postMessage({
|
|
168
|
-
action: '
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
147
|
+
action: 'apiResponse',
|
|
148
|
+
id: responseId_1,
|
|
149
|
+
url: fakeURL,
|
|
150
|
+
method: options.method,
|
|
151
|
+
data: data
|
|
172
152
|
});
|
|
173
153
|
})
|
|
174
154
|
.catch(function (error) {
|
|
@@ -176,29 +156,7 @@ export var setUpResponseInterceptor = function (_a) {
|
|
|
176
156
|
});
|
|
177
157
|
}
|
|
178
158
|
else {
|
|
179
|
-
|
|
180
|
-
var isProcessableUrl = isURLtoProcess(processApiResponse, fakeURL_1);
|
|
181
|
-
if (isProcessableUrl) {
|
|
182
|
-
var responseId_1 = nanoid();
|
|
183
|
-
response
|
|
184
|
-
.json()
|
|
185
|
-
.then(function (data) {
|
|
186
|
-
setResponseListeners(next, responseId_1);
|
|
187
|
-
workerRef.current.postMessage({
|
|
188
|
-
action: 'apiResponse',
|
|
189
|
-
id: responseId_1,
|
|
190
|
-
url: fakeURL_1,
|
|
191
|
-
method: options.method,
|
|
192
|
-
data: data
|
|
193
|
-
});
|
|
194
|
-
})
|
|
195
|
-
.catch(function (error) {
|
|
196
|
-
abort(error);
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
next(response);
|
|
201
|
-
}
|
|
159
|
+
next(response);
|
|
202
160
|
}
|
|
203
161
|
};
|
|
204
162
|
};
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { CustomActionTask, CustomActionTaskParams, CustomActionExtension, CustomActionViewConfig, CustomScriptExtension,
|
|
1
|
+
import { CustomActionTask, CustomActionTaskParams, CustomActionExtension, CustomActionViewConfig, CustomScriptExtension, Entity } from '@reltio/mdm-sdk';
|
|
2
2
|
export type ProcessRequestParams = {
|
|
3
|
-
|
|
4
|
-
paramObject: {
|
|
5
|
-
params: CustomActionTaskParams;
|
|
6
|
-
};
|
|
3
|
+
params: CustomActionTaskParams;
|
|
7
4
|
permissions?: string[];
|
|
8
5
|
worker: Worker;
|
|
9
6
|
metadata: any;
|
|
10
7
|
config: CustomActionExtension | CustomActionViewConfig | CustomScriptExtension;
|
|
11
8
|
user: any;
|
|
12
9
|
apiPath: string;
|
|
13
|
-
workflowPath
|
|
10
|
+
workflowPath?: string;
|
|
14
11
|
environment: string;
|
|
15
12
|
entity: any;
|
|
16
13
|
tenant: any;
|
|
@@ -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
|
|
16
|
-
import {
|
|
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,
|
|
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
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
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
|
|
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
|
|
147
|
-
|
|
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:
|
|
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:
|
|
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 =
|
|
207
|
-
interceptHandlers &&
|
|
195
|
+
var needDelayedRequestForInterceptors = interceptHandlers &&
|
|
208
196
|
!isEmptyValue(config.action) &&
|
|
209
|
-
|
|
210
|
-
(
|
|
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 (
|
|
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
|
-
|
|
248
|
-
|
|
249
|
-
(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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,
|
|
35
|
+
import { CustomAction, initializeWebWorker, isEmptyValue } from '@reltio/mdm-sdk';
|
|
36
36
|
import { nanoid } from 'nanoid';
|
|
37
|
-
import {
|
|
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 {
|
|
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
|
|
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
|
|
96
|
-
|
|
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
|
|
144
|
-
var fakeURL = url
|
|
145
|
-
|
|
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(
|
|
150
|
-
})
|
|
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), {
|
|
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
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
11
|
-
"@reltio/mdm-sdk": "^1.4.
|
|
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",
|