@reltio/components 1.4.1102 → 1.4.1103

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.
Files changed (77) hide show
  1. package/cjs/components/ActionButton/styles.d.ts +1 -1
  2. package/cjs/components/AttributesFiltersButton/ActionButtons/styles.d.ts +1 -1
  3. package/cjs/components/DropDownSelector/styles.d.ts +1 -1
  4. package/cjs/components/ModeSwitcherSelect/styles.d.ts +1 -1
  5. package/cjs/components/Popper/styles.d.ts +1 -1
  6. package/cjs/components/ProfileBand/styles.d.ts +1 -1
  7. package/cjs/components/ProfileCard/styles.d.ts +1 -1
  8. package/cjs/components/ProfileMatchCard/styles.d.ts +1 -1
  9. package/cjs/components/attributes/editMode/ComplexAttribute/styles.d.ts +1 -1
  10. package/cjs/components/attributes/editMode/MoreAttributesButton/styles.d.ts +1 -1
  11. package/cjs/components/attributes/editMode/SimpleAttributeEditor/styles.d.ts +1 -1
  12. package/cjs/components/crosswalks/CrosswalkAttributes/styles.d.ts +1 -1
  13. package/cjs/components/editors/CustomDateRangeEditor/styles.d.ts +1 -1
  14. package/cjs/components/editors/DateEditor/styles.d.ts +1 -1
  15. package/cjs/components/editors/DateRangeEditor/styles.d.ts +1 -1
  16. package/cjs/components/editors/TimestampEditor/styles.d.ts +1 -1
  17. package/cjs/components/workflow/cards/GenericWorkflowTaskCard/styles.d.ts +1 -1
  18. package/cjs/components/workflow/components/AddWorkflowDialog/styles.d.ts +1 -1
  19. package/cjs/components/workflow/components/DueDateField/styles.d.ts +1 -1
  20. package/cjs/components/workflow/components/LineDecorator/styles.d.ts +1 -1
  21. package/cjs/contexts/SandboxAPIContext/index.d.ts +6 -0
  22. package/cjs/contexts/SandboxAPIContext/index.js +12 -0
  23. package/cjs/contexts/index.d.ts +1 -0
  24. package/cjs/contexts/index.js +3 -1
  25. package/cjs/hooks/index.d.ts +3 -0
  26. package/cjs/hooks/index.js +6 -1
  27. package/cjs/hooks/useAPI/API.d.ts +2 -0
  28. package/cjs/hooks/useAPI/API.js +201 -0
  29. package/cjs/hooks/useAPI/helpers.d.ts +1 -0
  30. package/cjs/hooks/useAPI/helpers.js +12 -0
  31. package/cjs/hooks/useAPI/index.d.ts +5 -0
  32. package/cjs/hooks/useAPI/index.js +11 -0
  33. package/cjs/hooks/useAPI/types.d.ts +90 -0
  34. package/cjs/hooks/useAPI/types.js +42 -0
  35. package/cjs/hooks/useAPI/useAPI.d.ts +13 -0
  36. package/cjs/hooks/useAPI/useAPI.js +192 -0
  37. package/cjs/hooks/useCustomScripts.d.ts +9 -0
  38. package/cjs/hooks/useCustomScripts.js +215 -0
  39. package/esm/components/ActionButton/styles.d.ts +1 -1
  40. package/esm/components/AttributesFiltersButton/ActionButtons/styles.d.ts +1 -1
  41. package/esm/components/DropDownSelector/styles.d.ts +1 -1
  42. package/esm/components/ModeSwitcherSelect/styles.d.ts +1 -1
  43. package/esm/components/Popper/styles.d.ts +1 -1
  44. package/esm/components/ProfileBand/styles.d.ts +1 -1
  45. package/esm/components/ProfileCard/styles.d.ts +1 -1
  46. package/esm/components/ProfileMatchCard/styles.d.ts +1 -1
  47. package/esm/components/attributes/editMode/ComplexAttribute/styles.d.ts +1 -1
  48. package/esm/components/attributes/editMode/MoreAttributesButton/styles.d.ts +1 -1
  49. package/esm/components/attributes/editMode/SimpleAttributeEditor/styles.d.ts +1 -1
  50. package/esm/components/crosswalks/CrosswalkAttributes/styles.d.ts +1 -1
  51. package/esm/components/editors/CustomDateRangeEditor/styles.d.ts +1 -1
  52. package/esm/components/editors/DateEditor/styles.d.ts +1 -1
  53. package/esm/components/editors/DateRangeEditor/styles.d.ts +1 -1
  54. package/esm/components/editors/TimestampEditor/styles.d.ts +1 -1
  55. package/esm/components/workflow/cards/GenericWorkflowTaskCard/styles.d.ts +1 -1
  56. package/esm/components/workflow/components/AddWorkflowDialog/styles.d.ts +1 -1
  57. package/esm/components/workflow/components/DueDateField/styles.d.ts +1 -1
  58. package/esm/components/workflow/components/LineDecorator/styles.d.ts +1 -1
  59. package/esm/contexts/SandboxAPIContext/index.d.ts +6 -0
  60. package/esm/contexts/SandboxAPIContext/index.js +6 -0
  61. package/esm/contexts/index.d.ts +1 -0
  62. package/esm/contexts/index.js +1 -0
  63. package/esm/hooks/index.d.ts +3 -0
  64. package/esm/hooks/index.js +2 -0
  65. package/esm/hooks/useAPI/API.d.ts +2 -0
  66. package/esm/hooks/useAPI/API.js +197 -0
  67. package/esm/hooks/useAPI/helpers.d.ts +1 -0
  68. package/esm/hooks/useAPI/helpers.js +8 -0
  69. package/esm/hooks/useAPI/index.d.ts +5 -0
  70. package/esm/hooks/useAPI/index.js +4 -0
  71. package/esm/hooks/useAPI/types.d.ts +90 -0
  72. package/esm/hooks/useAPI/types.js +39 -0
  73. package/esm/hooks/useAPI/useAPI.d.ts +13 -0
  74. package/esm/hooks/useAPI/useAPI.js +169 -0
  75. package/esm/hooks/useCustomScripts.d.ts +9 -0
  76. package/esm/hooks/useCustomScripts.js +189 -0
  77. package/package.json +3 -3
@@ -0,0 +1,189 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { useContext, useEffect, useRef } from 'react';
13
+ import { useDispatch, useSelector } from 'react-redux';
14
+ import mdmModule, { ui } from '@reltio/mdm-module';
15
+ import { initializeWebWorker, isEmptyValue } from '@reltio/mdm-sdk';
16
+ import nanoid from 'nanoid';
17
+ import { find, map, pick, pipe, prop, omit } from 'ramda';
18
+ import { useWorkflowCheckPermission } from '../components/workflow';
19
+ import { SandboxAPIContext } from '../contexts';
20
+ import { CustomAction, getWorkerURL, processRequest } from './useAPI';
21
+ var isURLtoProcess = function (processApi, url) {
22
+ return (processApi || []).some(function (request) {
23
+ var regExp = new RegExp("^" + request + "$");
24
+ return request.replace(/\/*$/, '') === url || (request && regExp.test(url));
25
+ });
26
+ };
27
+ export var useCustomScripts = function (config, _a) {
28
+ var addInternalRequestInterceptor = _a.addInternalRequestInterceptor, addInternalResponseInterceptor = _a.addInternalResponseInterceptor, removeInternalRequestInterceptor = _a.removeInternalRequestInterceptor, removeInternalResponseInterceptor = _a.removeInternalResponseInterceptor;
29
+ var customScripts = config.map(function (customScript) { return (__assign(__assign({}, customScript), { actionId: nanoid() })); });
30
+ var dispatch = useDispatch();
31
+ var metadata = useSelector(mdmModule.selectors.getMetadata) || {};
32
+ var entity = useSelector(mdmModule.selectors.getEntity) || {};
33
+ var uiPath = useSelector(mdmModule.selectors.getUIPath);
34
+ var reltioPath = useSelector(mdmModule.selectors.getReltioPath);
35
+ var tenant = useSelector(mdmModule.selectors.getTenant);
36
+ var workerUrl = getWorkerURL(uiPath, tenant);
37
+ var apiPath = useSelector(mdmModule.selectors.getApiPath);
38
+ var workflowPath = useSelector(mdmModule.selectors.getWorkflowPath);
39
+ var user = useSelector(mdmModule.selectors.getUser);
40
+ var entityUri = useSelector(mdmModule.selectors.getEntityUri);
41
+ var environment = useSelector(mdmModule.selectors.getWorkflowEnvironmentUrl);
42
+ var qxApi = useContext(SandboxAPIContext);
43
+ var workflowCheckPermission = useWorkflowCheckPermission();
44
+ var _b = useSelector(mdmModule.selectors.getSearchProviderData) || {}, typeSearch = _b.type, search = _b.data;
45
+ var openSearch = function (search) { return dispatch(ui.actions.openSearch(search)); };
46
+ var requestListeners = useRef({});
47
+ var responseListeners = useRef({});
48
+ var workers = useRef({});
49
+ var process = function (task, worker) {
50
+ var _a, _b;
51
+ if (task) {
52
+ switch (task.action) {
53
+ case CustomAction.REQUEST: {
54
+ if (((_b = (_a = task.params) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b.origin) !== 'ui') {
55
+ processRequest(__assign({ name: task.params.name, paramObject: task, permissions: customScripts[0].permissions, worker: worker,
56
+ metadata: metadata, config: { action: customScripts[0] }, user: user,
57
+ apiPath: apiPath,
58
+ tenant: tenant,
59
+ workflowPath: workflowPath,
60
+ entity: entity,
61
+ entityUri: entityUri,
62
+ environment: environment, query: typeSearch === 'search' ? search === null || search === void 0 ? void 0 : search.query : null, openSearch: openSearch,
63
+ workflowCheckPermission: workflowCheckPermission }, qxApi));
64
+ }
65
+ else {
66
+ var _c = task.params, headers = _c.headers, id = _c.id, fakeURL = _c.url, method = _c.method, data = _c.data;
67
+ var url = fakeURL.replace(reltioPath, apiPath);
68
+ if (requestListeners.current[headers.requestId]) {
69
+ requestListeners.current[headers.requestId].next(url, __assign(__assign({}, data), { id: id,
70
+ task: task,
71
+ headers: headers,
72
+ method: method }));
73
+ requestListeners.current = omit([headers.requestId], requestListeners.current);
74
+ }
75
+ }
76
+ break;
77
+ }
78
+ case CustomAction.RETURN_PROCESSED_API_RESPONSE:
79
+ case CustomAction.RETURN_PROCESSED_API_REQUEST: {
80
+ var _d = task.params, id = _d.id, data = _d.data;
81
+ if (responseListeners.current[id]) {
82
+ responseListeners.current[id].next(data);
83
+ responseListeners.current = omit([id], responseListeners.current);
84
+ }
85
+ break;
86
+ }
87
+ }
88
+ }
89
+ };
90
+ useEffect(function () {
91
+ workers.current = customScripts.reduce(function (acc, customScript) {
92
+ var _a;
93
+ acc = __assign(__assign({}, acc), (_a = {}, _a[customScript.actionId] = initializeWebWorker(workerUrl, customScript.files, process), _a));
94
+ return acc;
95
+ }, workers.current);
96
+ return function () {
97
+ Object.keys(workers.current).forEach(function (actionId) {
98
+ workers.current[actionId].terminate();
99
+ });
100
+ };
101
+ }, [config]);
102
+ var customScriptRequestInterceptor = function (_a) {
103
+ var _b;
104
+ var _c = _a.options, options = _c === void 0 ? {} : _c, url = _a.url, next = _a.next;
105
+ var fakeURL = url.startsWith('/') && !url.startsWith(apiPath)
106
+ ? reltioPath + "/api/" + tenant + url
107
+ : "" + reltioPath + url.replace(apiPath, '');
108
+ var actionId = pipe(map(pick(['actionId', 'processApiRequest'])), find(function (_a) {
109
+ var processApiRequest = _a.processApiRequest;
110
+ return isURLtoProcess(processApiRequest, fakeURL);
111
+ }), prop('actionId'))(customScripts);
112
+ if (actionId) {
113
+ var requestId = nanoid();
114
+ requestListeners.current = __assign(__assign({}, requestListeners.current), (_b = {}, _b[requestId] = { options: options, next: next, id: requestId }, _b));
115
+ workers.current[actionId].postMessage({
116
+ action: 'apiRequest',
117
+ id: requestId,
118
+ url: fakeURL,
119
+ method: options.method,
120
+ headers: __assign(__assign({}, options.headers), { origin: 'ui', requestId: requestId, actionId: actionId }),
121
+ data: options
122
+ });
123
+ }
124
+ else {
125
+ next(url, options);
126
+ }
127
+ };
128
+ var customScriptResponseInterceptor = function (_a) {
129
+ var _b;
130
+ var url = _a.url, response = _a.response, next = _a.next, options = _a.options, abort = _a.abort;
131
+ if (((_b = options === null || options === void 0 ? void 0 : options.headers) === null || _b === void 0 ? void 0 : _b.origin) === 'ui') {
132
+ response
133
+ .json()
134
+ .then(function (data) {
135
+ var _a;
136
+ var _b, _c, _d;
137
+ responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[options.headers.requestId] = { next: next }, _a));
138
+ workers.current[(_b = options.headers) === null || _b === void 0 ? void 0 : _b.actionId].postMessage({
139
+ action: 'response',
140
+ result: { data: data },
141
+ id: options === null || options === void 0 ? void 0 : options.id,
142
+ 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
143
+ });
144
+ })
145
+ .catch(function (error) {
146
+ abort(error);
147
+ });
148
+ }
149
+ else {
150
+ var fakeURL_1 = "" + reltioPath + url.replace(apiPath, '');
151
+ var actionId_1 = pipe(map(pick(['actionId', 'processApiResponse'])), find(function (_a) {
152
+ var processApiResponse = _a.processApiResponse;
153
+ return isURLtoProcess(processApiResponse, fakeURL_1);
154
+ }), prop('actionId'))(customScripts);
155
+ if (actionId_1) {
156
+ var responseId_1 = nanoid();
157
+ response
158
+ .json()
159
+ .then(function (data) {
160
+ var _a;
161
+ responseListeners.current = __assign(__assign({}, responseListeners.current), (_a = {}, _a[responseId_1] = { next: next }, _a));
162
+ workers.current[actionId_1].postMessage({
163
+ action: 'apiResponse',
164
+ id: responseId_1,
165
+ url: fakeURL_1,
166
+ method: options.method,
167
+ data: data
168
+ });
169
+ })
170
+ .catch(function (error) {
171
+ abort(error);
172
+ });
173
+ }
174
+ else {
175
+ next(response);
176
+ }
177
+ }
178
+ };
179
+ useEffect(function () {
180
+ if (!isEmptyValue(config)) {
181
+ addInternalRequestInterceptor(customScriptRequestInterceptor);
182
+ addInternalResponseInterceptor(customScriptResponseInterceptor);
183
+ return function () {
184
+ removeInternalRequestInterceptor(customScriptRequestInterceptor);
185
+ removeInternalResponseInterceptor(customScriptResponseInterceptor);
186
+ };
187
+ }
188
+ }, [config]);
189
+ };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.1102",
3
+ "version": "1.4.1103",
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.1102",
11
- "@reltio/mdm-sdk": "^1.4.1102",
10
+ "@reltio/mdm-module": "^1.4.1103",
11
+ "@reltio/mdm-sdk": "^1.4.1103",
12
12
  "classnames": "^2.2.5",
13
13
  "d3-cloud": "^1.2.5",
14
14
  "d3-geo": "^2.0.1",