chayns-api 1.0.1 → 1.0.3
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/.babelrc +30 -30
- package/.eslintrc +17 -17
- package/.github/workflows/deploy_docs.yml +28 -28
- package/.github/workflows/publish.yml +21 -0
- package/LICENSE +21 -21
- package/README.md +47 -47
- package/dist/cjs/calls/dialogs/alert.js +0 -2
- package/dist/cjs/calls/dialogs/chaynsDialog.js +2 -8
- package/dist/cjs/calls/dialogs/close.js +0 -2
- package/dist/cjs/calls/dialogs/communication.js +1 -16
- package/dist/cjs/calls/dialogs/confirm.js +0 -4
- package/dist/cjs/calls/dialogs/date.js +46 -63
- package/dist/cjs/calls/dialogs/dropUpAlert.js +0 -3
- package/dist/cjs/calls/dialogs/fileSelect.js +0 -10
- package/dist/cjs/calls/dialogs/iFrame.js +0 -8
- package/dist/cjs/calls/dialogs/index.js +0 -27
- package/dist/cjs/calls/dialogs/input.js +0 -6
- package/dist/cjs/calls/dialogs/mediaSelect.js +0 -7
- package/dist/cjs/calls/dialogs/open.js +0 -2
- package/dist/cjs/calls/dialogs/select.js +0 -9
- package/dist/cjs/calls/dialogs/signature.js +0 -5
- package/dist/cjs/calls/dialogs/toast.js +0 -3
- package/dist/cjs/calls/dialogs/utils/callback.js +0 -2
- package/dist/cjs/calls/dialogs/utils/is.js +0 -4
- package/dist/cjs/calls/getUserInfo.js +0 -11
- package/dist/cjs/calls/index.js +95 -247
- package/dist/cjs/calls/sendMessage.js +8 -34
- package/dist/cjs/calls/visibilityChangeListener.js +5 -16
- package/dist/cjs/components/ChaynsContext.js +2 -4
- package/dist/cjs/components/ChaynsProvider.js +6 -28
- package/dist/cjs/components/WaitUntil.js +0 -5
- package/dist/cjs/components/withCompatMode.js +1 -16
- package/dist/cjs/helper/apiListenerHelper.js +0 -9
- package/dist/cjs/hooks/geoLocationListener.js +6 -15
- package/dist/cjs/hooks/index.js +6 -16
- package/dist/cjs/hooks/scrollListener.js +12 -31
- package/dist/cjs/hooks/useAccessToken.js +2 -7
- package/dist/cjs/hooks/useCurrentPage.js +2 -6
- package/dist/cjs/hooks/useCustomData.js +2 -6
- package/dist/cjs/hooks/useDevice.js +2 -6
- package/dist/cjs/hooks/useEnvironment.js +2 -6
- package/dist/cjs/hooks/useFunctions.js +2 -6
- package/dist/cjs/hooks/useIsAdminMode.js +2 -7
- package/dist/cjs/hooks/useLanguage.js +2 -6
- package/dist/cjs/hooks/usePages.js +26 -18
- package/dist/cjs/hooks/useParameters.js +2 -6
- package/dist/cjs/hooks/useSite.js +2 -6
- package/dist/cjs/hooks/useUser.js +2 -7
- package/dist/cjs/hooks/useValues.js +2 -6
- package/dist/cjs/hooks/windowMetricsListener.js +6 -16
- package/dist/cjs/host/ChaynsHost.js +0 -10
- package/dist/cjs/host/iframe/HostIframe.js +23 -30
- package/dist/cjs/host/iframe/utils/useUpdateData.js +0 -3
- package/dist/cjs/host/module/ModuleHost.js +3 -13
- package/dist/cjs/host/module/utils/loadComponent.js +1 -18
- package/dist/cjs/host/module/utils/useDynamicScript.js +0 -18
- package/dist/cjs/index.js +0 -19
- package/dist/cjs/types/IChaynsReact.js +27 -48
- package/dist/cjs/util/appCall.js +1 -4
- package/dist/cjs/util/deviceHelper.js +5 -22
- package/dist/cjs/util/heightHelper.js +0 -9
- package/dist/cjs/util/postIframeForm.js +0 -5
- package/dist/cjs/wrapper/AppWrapper.js +323 -159
- package/dist/cjs/wrapper/FrameWrapper.js +219 -248
- package/dist/cjs/wrapper/ModuleFederationWrapper.js +2 -27
- package/dist/cjs/wrapper/SsrWrapper.js +0 -8
- package/dist/esm/calls/dialogs/alert.js +4 -4
- package/dist/esm/calls/dialogs/chaynsDialog.js +7 -11
- package/dist/esm/calls/dialogs/communication.js +15 -26
- package/dist/esm/calls/dialogs/confirm.js +5 -8
- package/dist/esm/calls/dialogs/date.js +119 -128
- package/dist/esm/calls/dialogs/dropUpAlert.js +1 -1
- package/dist/esm/calls/dialogs/fileSelect.js +23 -62
- package/dist/esm/calls/dialogs/iFrame.js +7 -10
- package/dist/esm/calls/dialogs/input.js +2 -5
- package/dist/esm/calls/dialogs/mediaSelect.js +18 -55
- package/dist/esm/calls/dialogs/open.js +2 -2
- package/dist/esm/calls/dialogs/select.js +5 -9
- package/dist/esm/calls/dialogs/signature.js +0 -2
- package/dist/esm/calls/dialogs/toast.js +6 -11
- package/dist/esm/calls/dialogs/utils/callback.js +3 -5
- package/dist/esm/calls/dialogs/utils/is.js +1 -3
- package/dist/esm/calls/getUserInfo.js +32 -92
- package/dist/esm/calls/index.js +297 -449
- package/dist/esm/calls/sendMessage.js +99 -229
- package/dist/esm/calls/visibilityChangeListener.js +14 -19
- package/dist/esm/components/ChaynsContext.js +3 -3
- package/dist/esm/components/ChaynsProvider.js +45 -86
- package/dist/esm/components/WaitUntil.js +21 -86
- package/dist/esm/components/withCompatMode.js +35 -77
- package/dist/esm/helper/apiListenerHelper.js +10 -15
- package/dist/esm/hooks/geoLocationListener.js +24 -50
- package/dist/esm/hooks/index.js +1 -1
- package/dist/esm/hooks/scrollListener.js +58 -94
- package/dist/esm/hooks/useAccessToken.js +8 -30
- package/dist/esm/hooks/useCurrentPage.js +4 -8
- package/dist/esm/hooks/useCustomData.js +4 -8
- package/dist/esm/hooks/useDevice.js +3 -8
- package/dist/esm/hooks/useEnvironment.js +3 -8
- package/dist/esm/hooks/useFunctions.js +4 -7
- package/dist/esm/hooks/useIsAdminMode.js +4 -8
- package/dist/esm/hooks/useLanguage.js +3 -8
- package/dist/esm/hooks/usePages.js +38 -31
- package/dist/esm/hooks/useParameters.js +3 -8
- package/dist/esm/hooks/useSite.js +3 -8
- package/dist/esm/hooks/useUser.js +3 -9
- package/dist/esm/hooks/useValues.js +4 -7
- package/dist/esm/hooks/windowMetricsListener.js +22 -48
- package/dist/esm/host/ChaynsHost.js +22 -29
- package/dist/esm/host/iframe/HostIframe.js +86 -142
- package/dist/esm/host/iframe/utils/useUpdateData.js +4 -6
- package/dist/esm/host/module/ModuleHost.js +42 -49
- package/dist/esm/host/module/utils/loadComponent.js +47 -85
- package/dist/esm/host/module/utils/useDynamicScript.js +27 -74
- package/dist/esm/types/IChaynsReact.js +37 -61
- package/dist/esm/util/appCall.js +2 -4
- package/dist/esm/util/deviceHelper.js +13 -37
- package/dist/esm/util/heightHelper.js +10 -13
- package/dist/esm/util/postIframeForm.js +25 -57
- package/dist/esm/wrapper/AppWrapper.js +385 -781
- package/dist/esm/wrapper/FrameWrapper.js +262 -1509
- package/dist/esm/wrapper/ModuleFederationWrapper.js +47 -284
- package/dist/esm/wrapper/SsrWrapper.js +19 -65
- package/dist/types/calls/dialogs/alert.d.ts +1 -1
- package/dist/types/calls/dialogs/chaynsDialog.d.ts +24 -24
- package/dist/types/calls/dialogs/close.d.ts +1 -1
- package/dist/types/calls/dialogs/communication.d.ts +3 -3
- package/dist/types/calls/dialogs/confirm.d.ts +13 -13
- package/dist/types/calls/dialogs/date.d.ts +96 -96
- package/dist/types/calls/dialogs/dropUpAlert.d.ts +5 -5
- package/dist/types/calls/dialogs/fileSelect.d.ts +16 -16
- package/dist/types/calls/dialogs/iFrame.d.ts +10 -10
- package/dist/types/calls/dialogs/index.d.ts +14 -14
- package/dist/types/calls/dialogs/input.d.ts +15 -15
- package/dist/types/calls/dialogs/mediaSelect.d.ts +8 -8
- package/dist/types/calls/dialogs/open.d.ts +1 -1
- package/dist/types/calls/dialogs/select.d.ts +6 -6
- package/dist/types/calls/dialogs/signature.d.ts +7 -7
- package/dist/types/calls/dialogs/toast.d.ts +1 -1
- package/dist/types/calls/dialogs/utils/callback.d.ts +1 -1
- package/dist/types/calls/dialogs/utils/is.d.ts +4 -4
- package/dist/types/calls/getUserInfo.d.ts +9 -9
- package/dist/types/calls/index.d.ts +225 -231
- package/dist/types/calls/sendMessage.d.ts +13 -13
- package/dist/types/calls/visibilityChangeListener.d.ts +9 -9
- package/dist/types/components/ChaynsContext.d.ts +3 -3
- package/dist/types/components/ChaynsProvider.d.ts +13 -13
- package/dist/types/components/WaitUntil.d.ts +7 -7
- package/dist/types/components/withCompatMode.d.ts +13 -13
- package/dist/types/helper/apiListenerHelper.d.ts +6 -6
- package/dist/types/hooks/geoLocationListener.d.ts +18 -18
- package/dist/types/hooks/index.d.ts +16 -16
- package/dist/types/hooks/scrollListener.d.ts +28 -28
- package/dist/types/hooks/useAccessToken.d.ts +5 -5
- package/dist/types/hooks/useCurrentPage.d.ts +4 -4
- package/dist/types/hooks/useCustomData.d.ts +4 -4
- package/dist/types/hooks/useDevice.d.ts +5 -5
- package/dist/types/hooks/useEnvironment.d.ts +5 -5
- package/dist/types/hooks/useFunctions.d.ts +5 -5
- package/dist/types/hooks/useIsAdminMode.d.ts +4 -4
- package/dist/types/hooks/useLanguage.d.ts +5 -5
- package/dist/types/hooks/usePages.d.ts +18 -14
- package/dist/types/hooks/useParameters.d.ts +5 -5
- package/dist/types/hooks/useSite.d.ts +5 -5
- package/dist/types/hooks/useUser.d.ts +5 -5
- package/dist/types/hooks/useValues.d.ts +5 -5
- package/dist/types/hooks/windowMetricsListener.d.ts +11 -11
- package/dist/types/host/ChaynsHost.d.ts +28 -28
- package/dist/types/host/iframe/HostIframe.d.ts +24 -24
- package/dist/types/host/iframe/utils/useUpdateData.d.ts +3 -3
- package/dist/types/host/module/ModuleHost.d.ts +23 -23
- package/dist/types/host/module/utils/loadComponent.d.ts +1 -1
- package/dist/types/host/module/utils/useDynamicScript.d.ts +9 -9
- package/dist/types/index.d.ts +16 -16
- package/dist/types/types/IChaynsReact.d.ts +622 -590
- package/dist/types/types/dialog.d.ts +41 -41
- package/dist/types/util/appCall.d.ts +2 -2
- package/dist/types/util/deviceHelper.d.ts +7 -7
- package/dist/types/util/heightHelper.d.ts +1 -1
- package/dist/types/util/postIframeForm.d.ts +1 -1
- package/dist/types/wrapper/AppWrapper.d.ts +18 -16
- package/dist/types/wrapper/FrameWrapper.d.ts +15 -15
- package/dist/types/wrapper/ModuleFederationWrapper.d.ts +10 -10
- package/dist/types/wrapper/SsrWrapper.d.ts +11 -11
- package/package.json +76 -76
- package/toolkit.config.js +52 -52
- package/tsconfig.json +56 -56
- package/dist/cjs/bootstrap.js +0 -11
- package/dist/cjs/calls/abstractApiListener.js +0 -40
- package/dist/cjs/calls/apiEventListener.js +0 -40
- package/dist/cjs/calls/setVisibilityChangeListener.js +0 -1
- package/dist/cjs/calls/windowMetricsListener.js +0 -18
- package/dist/cjs/client.js +0 -93
- package/dist/cjs/components/App.js +0 -32
- package/dist/cjs/components/App.spec.js +0 -16
- package/dist/cjs/components/Button.js +0 -32
- package/dist/cjs/components/ChaynsModuleProvider.js +0 -457
- package/dist/cjs/components/ChaynsProviderExposed.js +0 -16
- package/dist/cjs/components/TestProvider.js +0 -236
- package/dist/cjs/components/Title.js +0 -162
- package/dist/cjs/functions/addApiListener.js +0 -37
- package/dist/cjs/functions/addGeoLocationListener.js +0 -26
- package/dist/cjs/functions/addScrollListener.js +0 -26
- package/dist/cjs/functions/addWindowMetricsListener.js +0 -37
- package/dist/cjs/helper/cssLoader.js +0 -28
- package/dist/cjs/hooks/addGeoLocationListener.js +0 -26
- package/dist/cjs/hooks/addScrollListener.js +0 -26
- package/dist/cjs/hooks/addWindowMetricsListener.js +0 -37
- package/dist/cjs/hooks/geoLocation.js +0 -48
- package/dist/cjs/hooks/useAddGeoLocationListener.js +0 -26
- package/dist/cjs/hooks/useAddScrollListener.js +0 -48
- package/dist/cjs/hooks/useAddWindowMetricsListener.js +0 -45
- package/dist/cjs/hooks/useAdddScrollListener.js +0 -26
- package/dist/cjs/hooks/windowMetrics.js +0 -45
- package/dist/cjs/host/HostIframe.js +0 -157
- package/dist/cjs/host/ModuleHost.js +0 -11
- package/dist/cjs/host/module/utils.js +0 -25
- package/dist/cjs/index.example.js +0 -7
- package/dist/cjs/index2.js +0 -64
- package/dist/cjs/types/DynamicApiImport.d.js +0 -5
- package/dist/cjs/types/DynamicImport.d.js +0 -5
- package/dist/cjs/types/chayns-components.d.js +0 -1
- package/dist/cjs/types/chayns-logger.d.js +0 -1
- package/dist/cjs/types/chayns.d.js +0 -1
- package/dist/cjs/types/tobit-websocket-service-client.d.js +0 -1
- package/dist/cjs/types/toolkit-types.d.js +0 -1
- package/dist/cjs/util/useFunctionsContext.js +0 -16
- package/dist/cjs/util/useIsAdminMode.js +0 -18
- package/dist/cjs/util/useUser.js +0 -16
- package/dist/esm/bootstrap.js +0 -4
- package/dist/esm/client.js +0 -8
- package/dist/esm/components/App.js +0 -35
- package/dist/esm/components/App.spec.js +0 -9
- package/dist/esm/components/Button.js +0 -34
- package/dist/esm/components/ChaynsModuleProvider.js +0 -517
- package/dist/esm/components/ChaynsProviderExposed.js +0 -3
- package/dist/esm/components/TestProvider.js +0 -308
- package/dist/esm/components/Title.js +0 -210
- package/dist/esm/helper/cssLoader.js +0 -21
- package/dist/esm/hooks/useAddGeoLocationListener.js +0 -18
- package/dist/esm/hooks/useAddScrollListener.js +0 -18
- package/dist/esm/hooks/useAddWindowMetricsListener.js +0 -18
- package/dist/esm/host/HostIframe.js +0 -153
- package/dist/esm/index.example.js +0 -1
- package/dist/esm/index2.js +0 -5
- package/dist/esm/types/DynamicApiImport.d.js +0 -1
- package/dist/esm/types/DynamicImport.d.js +0 -1
- package/dist/esm/types/chayns-components.d.js +0 -0
- package/dist/esm/types/chayns-logger.d.js +0 -0
- package/dist/esm/types/chayns.d.js +0 -0
- package/dist/esm/types/tobit-websocket-service-client.d.js +0 -0
- package/dist/esm/types/toolkit-types.d.js +0 -0
- package/dist/esm/util/useIsAdminMode.js +0 -9
- package/dist/esm/util/useUser.js +0 -7
- package/dist/types/bootstrap.d.ts +0 -1
- package/dist/types/client.d.ts +0 -7
- package/dist/types/components/App.d.ts +0 -5
- package/dist/types/components/Button.d.ts +0 -8
- package/dist/types/components/ChaynsModuleProvider.d.ts +0 -170
- package/dist/types/components/ChaynsProviderExposed.d.ts +0 -13
- package/dist/types/components/Title.d.ts +0 -3
- package/dist/types/host/HostIframe.d.ts +0 -20
- package/dist/types/index.example.d.ts +0 -0
|
@@ -1,239 +1,109 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var INTERCOM_URL = 'https://sub54.tobit.com/rest/api';
|
|
6
|
-
/**
|
|
7
|
-
* @category Intercom functions
|
|
1
|
+
const INTERCOM_URL = 'https://sub54.tobit.com/rest/api';
|
|
2
|
+
/**
|
|
3
|
+
* @category Intercom functions
|
|
8
4
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
accessToken = _yield$api$functions$.accessToken;
|
|
44
|
-
|
|
45
|
-
if (accessToken) {
|
|
46
|
-
_context.next = 11;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return _context.abrupt("return", Promise.reject(new Error('send message requires a user to be logged in')));
|
|
51
|
-
|
|
52
|
-
case 11:
|
|
53
|
-
if (accessToken) {
|
|
54
|
-
_context.next = 13;
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return _context.abrupt("return", Promise.reject(new Error('send message requires a user to be logged in')));
|
|
59
|
-
|
|
60
|
-
case 13:
|
|
61
|
-
images = Array.isArray(object.images) ? object.images.map(function (imageUrl) {
|
|
62
|
-
return {
|
|
63
|
-
url: imageUrl
|
|
64
|
-
};
|
|
65
|
-
}) : [];
|
|
66
|
-
return _context.abrupt("return", sendMessage("/user/".concat(senderUserId, "/message"), accessToken, {
|
|
67
|
-
receivers: [{
|
|
68
|
-
tobitId: receiverUserId
|
|
69
|
-
}],
|
|
70
|
-
message: {
|
|
71
|
-
images: images,
|
|
72
|
-
text: object.text,
|
|
73
|
-
typeId: 1
|
|
74
|
-
}
|
|
75
|
-
}));
|
|
76
|
-
|
|
77
|
-
case 15:
|
|
78
|
-
case "end":
|
|
79
|
-
return _context.stop();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}, _callee);
|
|
83
|
-
}));
|
|
84
|
-
|
|
85
|
-
return function sendMessageToUser(_x, _x2, _x3) {
|
|
86
|
-
return _ref.apply(this, arguments);
|
|
87
|
-
};
|
|
88
|
-
}();
|
|
89
|
-
/**
|
|
90
|
-
* @category Intercom functions
|
|
5
|
+
export const sendMessageToUser = async (api, object, receiverUserId) => {
|
|
6
|
+
var _api$values$user;
|
|
7
|
+
if (!object.text) {
|
|
8
|
+
return Promise.reject(new Error('no text specified'));
|
|
9
|
+
}
|
|
10
|
+
const senderUserId = (_api$values$user = api.values.user) === null || _api$values$user === void 0 ? void 0 : _api$values$user.userId;
|
|
11
|
+
if (senderUserId === undefined) {
|
|
12
|
+
return Promise.reject(new Error('missing sender user id'));
|
|
13
|
+
}
|
|
14
|
+
const {
|
|
15
|
+
accessToken
|
|
16
|
+
} = await api.functions.getAccessToken();
|
|
17
|
+
if (!accessToken) {
|
|
18
|
+
return Promise.reject(new Error('send message requires a user to be logged in'));
|
|
19
|
+
}
|
|
20
|
+
if (!accessToken) {
|
|
21
|
+
return Promise.reject(new Error('send message requires a user to be logged in'));
|
|
22
|
+
}
|
|
23
|
+
const images = Array.isArray(object.images) ? object.images.map(imageUrl => ({
|
|
24
|
+
url: imageUrl
|
|
25
|
+
})) : [];
|
|
26
|
+
return sendMessage(`/user/${senderUserId}/message`, accessToken, {
|
|
27
|
+
receivers: [{
|
|
28
|
+
tobitId: receiverUserId
|
|
29
|
+
}],
|
|
30
|
+
message: {
|
|
31
|
+
images,
|
|
32
|
+
text: object.text,
|
|
33
|
+
typeId: 1
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* @category Intercom functions
|
|
91
39
|
*/
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
case 7:
|
|
125
|
-
_yield$api$functions$2 = _context2.sent;
|
|
126
|
-
accessToken = _yield$api$functions$2.accessToken;
|
|
127
|
-
|
|
128
|
-
if (accessToken) {
|
|
129
|
-
_context2.next = 11;
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return _context2.abrupt("return", Promise.reject(new Error('send message requires a user to be logged in')));
|
|
134
|
-
|
|
135
|
-
case 11:
|
|
136
|
-
images = Array.isArray(object.images) ? object.images.map(function (imageUrl) {
|
|
137
|
-
return {
|
|
138
|
-
url: imageUrl
|
|
139
|
-
};
|
|
140
|
-
}) : [];
|
|
141
|
-
return _context2.abrupt("return", sendMessage("/user/".concat(senderUserId, "/message"), accessToken, {
|
|
142
|
-
receivers: [{
|
|
143
|
-
locationId: api.values.site.locationId
|
|
144
|
-
}],
|
|
145
|
-
message: {
|
|
146
|
-
images: images,
|
|
147
|
-
text: object.text,
|
|
148
|
-
typeId: 1
|
|
149
|
-
}
|
|
150
|
-
}));
|
|
151
|
-
|
|
152
|
-
case 13:
|
|
153
|
-
case "end":
|
|
154
|
-
return _context2.stop();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}, _callee2);
|
|
158
|
-
}));
|
|
159
|
-
|
|
160
|
-
return function sendMessageToPage(_x4, _x5) {
|
|
161
|
-
return _ref2.apply(this, arguments);
|
|
162
|
-
};
|
|
163
|
-
}();
|
|
164
|
-
/**
|
|
165
|
-
* @category Intercom functions
|
|
40
|
+
export const sendMessageToPage = async (api, object) => {
|
|
41
|
+
var _api$values$user2;
|
|
42
|
+
if (!object.text) {
|
|
43
|
+
return Promise.reject(new Error('no text specified'));
|
|
44
|
+
}
|
|
45
|
+
const senderUserId = (_api$values$user2 = api.values.user) === null || _api$values$user2 === void 0 ? void 0 : _api$values$user2.userId;
|
|
46
|
+
if (senderUserId === undefined) {
|
|
47
|
+
return Promise.reject(new Error('missing sender user id'));
|
|
48
|
+
}
|
|
49
|
+
const {
|
|
50
|
+
accessToken
|
|
51
|
+
} = await api.functions.getAccessToken();
|
|
52
|
+
if (!accessToken) {
|
|
53
|
+
return Promise.reject(new Error('send message requires a user to be logged in'));
|
|
54
|
+
}
|
|
55
|
+
const images = Array.isArray(object.images) ? object.images.map(imageUrl => ({
|
|
56
|
+
url: imageUrl
|
|
57
|
+
})) : [];
|
|
58
|
+
return sendMessage(`/user/${senderUserId}/message`, accessToken, {
|
|
59
|
+
receivers: [{
|
|
60
|
+
locationId: api.values.site.locationId
|
|
61
|
+
}],
|
|
62
|
+
message: {
|
|
63
|
+
images,
|
|
64
|
+
text: object.text,
|
|
65
|
+
typeId: 1
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* @category Intercom functions
|
|
166
71
|
*/
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return _context3.abrupt("return", Promise.reject(new Error('send message requires a user to be logged in')));
|
|
198
|
-
|
|
199
|
-
case 9:
|
|
200
|
-
images = Array.isArray(object.images) ? object.images.map(function (imageUrl) {
|
|
201
|
-
return {
|
|
202
|
-
url: imageUrl
|
|
203
|
-
};
|
|
204
|
-
}) : [];
|
|
205
|
-
return _context3.abrupt("return", sendMessage("/location/".concat(locationId, "/broadcast"), accessToken, {
|
|
206
|
-
receivers: [{
|
|
207
|
-
groupId: groupId
|
|
208
|
-
}],
|
|
209
|
-
message: {
|
|
210
|
-
images: images,
|
|
211
|
-
text: object.text,
|
|
212
|
-
typeId: 6
|
|
213
|
-
}
|
|
214
|
-
}));
|
|
215
|
-
|
|
216
|
-
case 11:
|
|
217
|
-
case "end":
|
|
218
|
-
return _context3.stop();
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}, _callee3);
|
|
222
|
-
}));
|
|
223
|
-
|
|
224
|
-
return function sendMessageToGroup(_x6, _x7, _x8) {
|
|
225
|
-
return _ref3.apply(this, arguments);
|
|
226
|
-
};
|
|
227
|
-
}();
|
|
228
|
-
/**
|
|
229
|
-
* @category Intercom functions
|
|
72
|
+
export const sendMessageToGroup = async (api, object, groupId) => {
|
|
73
|
+
if (!object.text) {
|
|
74
|
+
return Promise.reject(new Error('no text specified'));
|
|
75
|
+
}
|
|
76
|
+
const {
|
|
77
|
+
accessToken
|
|
78
|
+
} = await api.functions.getAccessToken();
|
|
79
|
+
const {
|
|
80
|
+
locationId
|
|
81
|
+
} = api.values.site;
|
|
82
|
+
if (!accessToken) {
|
|
83
|
+
return Promise.reject(new Error('send message requires a user to be logged in'));
|
|
84
|
+
}
|
|
85
|
+
const images = Array.isArray(object.images) ? object.images.map(imageUrl => ({
|
|
86
|
+
url: imageUrl
|
|
87
|
+
})) : [];
|
|
88
|
+
return sendMessage(`/location/${locationId}/broadcast`, accessToken, {
|
|
89
|
+
receivers: [{
|
|
90
|
+
groupId
|
|
91
|
+
}],
|
|
92
|
+
message: {
|
|
93
|
+
images,
|
|
94
|
+
text: object.text,
|
|
95
|
+
typeId: 6
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* @category Intercom functions
|
|
230
101
|
*/
|
|
231
|
-
|
|
232
102
|
function sendMessage(endpoint, token, body) {
|
|
233
|
-
return fetch(
|
|
103
|
+
return fetch(`${INTERCOM_URL}${endpoint}`, {
|
|
234
104
|
method: 'POST',
|
|
235
105
|
headers: {
|
|
236
|
-
authorization:
|
|
106
|
+
authorization: `bearer ${token}`,
|
|
237
107
|
'Content-Type': 'application/json'
|
|
238
108
|
},
|
|
239
109
|
body: JSON.stringify(body)
|
|
@@ -1,34 +1,29 @@
|
|
|
1
1
|
import { addApiListener, dispatchApiEvent, removeApiListener } from '../helper/apiListenerHelper';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var handleVisibilityChange = function handleVisibilityChange() {
|
|
2
|
+
const key = 'visibilityChangeListener';
|
|
3
|
+
const handleVisibilityChange = () => {
|
|
5
4
|
dispatchApiEvent(key, {
|
|
6
5
|
isVisible: !document.hidden
|
|
7
6
|
});
|
|
8
7
|
};
|
|
9
|
-
/**
|
|
10
|
-
* @category Event listener
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export var addVisibilityChangeListener = function addVisibilityChangeListener(callback) {
|
|
15
|
-
var _addApiListener = addApiListener(key, callback),
|
|
16
|
-
id = _addApiListener.id,
|
|
17
|
-
shouldInitialize = _addApiListener.shouldInitialize;
|
|
18
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @category Event listener
|
|
11
|
+
*/
|
|
12
|
+
export const addVisibilityChangeListener = callback => {
|
|
13
|
+
const {
|
|
14
|
+
id,
|
|
15
|
+
shouldInitialize
|
|
16
|
+
} = addApiListener(key, callback);
|
|
19
17
|
if (shouldInitialize) {
|
|
20
18
|
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
21
19
|
}
|
|
22
|
-
|
|
23
20
|
return id;
|
|
24
21
|
};
|
|
25
|
-
/**
|
|
26
|
-
* @category Event listener
|
|
22
|
+
/**
|
|
23
|
+
* @category Event listener
|
|
27
24
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var shouldRemove = removeApiListener(key, id);
|
|
31
|
-
|
|
25
|
+
export const removeVisibilityChangeListener = id => {
|
|
26
|
+
const shouldRemove = removeApiListener(key, id);
|
|
32
27
|
if (shouldRemove) {
|
|
33
28
|
document.removeEventListener('addVisibilityChangeListener', handleVisibilityChange);
|
|
34
29
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createContext } from 'use-context-selector';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
export
|
|
2
|
+
export const ChaynsContext = createContext(null);
|
|
3
|
+
// @ts-expect-error Functions cant be null, implementation of default values is redundant
|
|
4
|
+
export const ChaynsFunctionsContext = createContext(null);
|
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
4
|
-
|
|
5
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
8
|
-
|
|
9
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
|
-
|
|
11
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
-
|
|
13
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
-
|
|
15
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
|
-
|
|
17
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
18
|
-
|
|
19
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
20
|
-
|
|
21
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
22
|
-
|
|
23
1
|
import htmlEscape from 'htmlescape';
|
|
24
2
|
import React, { useEffect, useRef, useState } from 'react';
|
|
25
3
|
import { AppName } from '../types/IChaynsReact';
|
|
@@ -28,20 +6,21 @@ import { AppWrapper } from '../wrapper/AppWrapper';
|
|
|
28
6
|
import { FrameWrapper } from '../wrapper/FrameWrapper';
|
|
29
7
|
import { ModuleFederationWrapper } from '../wrapper/ModuleFederationWrapper';
|
|
30
8
|
import { SsrWrapper } from '../wrapper/SsrWrapper';
|
|
31
|
-
import { ChaynsContext, ChaynsFunctionsContext } from './ChaynsContext';
|
|
9
|
+
import { ChaynsContext, ChaynsFunctionsContext } from './ChaynsContext';
|
|
32
10
|
|
|
33
|
-
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
12
|
+
export const moduleWrapper = {
|
|
34
13
|
current: undefined
|
|
35
14
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
15
|
+
const isServer = typeof window === 'undefined';
|
|
16
|
+
const InitialDataProvider = /*#__PURE__*/React.memo(_ref => {
|
|
17
|
+
let {
|
|
18
|
+
data,
|
|
19
|
+
renderedByServer
|
|
20
|
+
} = _ref;
|
|
41
21
|
if (!renderedByServer) {
|
|
42
22
|
return null;
|
|
43
23
|
}
|
|
44
|
-
|
|
45
24
|
return /*#__PURE__*/React.createElement("script", {
|
|
46
25
|
id: "__CHAYNS_DATA__",
|
|
47
26
|
type: "application/json",
|
|
@@ -49,21 +28,18 @@ var InitialDataProvider = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
49
28
|
__html: htmlEscape(data || {})
|
|
50
29
|
}
|
|
51
30
|
});
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
var ChaynsProvider = function ChaynsProvider(_ref2) {
|
|
31
|
+
}, () => true);
|
|
32
|
+
const ChaynsProvider = _ref2 => {
|
|
57
33
|
var _customWrapper$curren, _customWrapper$curren2, _customWrapper$curren3;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
34
|
+
let {
|
|
35
|
+
children,
|
|
36
|
+
data,
|
|
37
|
+
functions,
|
|
38
|
+
renderedByServer,
|
|
39
|
+
isModule
|
|
40
|
+
} = _ref2;
|
|
64
41
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
65
|
-
|
|
66
|
-
|
|
42
|
+
const customWrapper = useRef(null);
|
|
67
43
|
if (!customWrapper.current) {
|
|
68
44
|
if (isModule) {
|
|
69
45
|
if (data && functions) {
|
|
@@ -79,59 +55,43 @@ var ChaynsProvider = function ChaynsProvider(_ref2) {
|
|
|
79
55
|
}
|
|
80
56
|
} else {
|
|
81
57
|
var _deviceInfo$app$name, _deviceInfo$app;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
58
|
+
const deviceInfo = getDeviceInfo(navigator.userAgent, '');
|
|
59
|
+
// load framewrapper in Chaynsweb in app (window.self === window.top)
|
|
85
60
|
if ([AppName.Chayns, AppName.ChaynsLauncher].includes((_deviceInfo$app$name = (_deviceInfo$app = deviceInfo.app) === null || _deviceInfo$app === void 0 ? void 0 : _deviceInfo$app.name) !== null && _deviceInfo$app$name !== void 0 ? _deviceInfo$app$name : AppName.Unknown) && window.self === window.top) {
|
|
86
61
|
customWrapper.current = new AppWrapper();
|
|
87
62
|
} else {
|
|
88
63
|
customWrapper.current = new FrameWrapper();
|
|
89
64
|
}
|
|
90
65
|
}
|
|
91
|
-
|
|
92
66
|
moduleWrapper.current = customWrapper.current;
|
|
93
67
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
if (customWrapper.current.values) {
|
|
120
|
-
setState(_objectSpread({}, customWrapper.current.values));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
case 4:
|
|
124
|
-
case "end":
|
|
125
|
-
return _context.stop();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}, _callee);
|
|
129
|
-
}))();
|
|
68
|
+
const [state, setState] = useState((_customWrapper$curren = (_customWrapper$curren2 = customWrapper.current) === null || _customWrapper$curren2 === void 0 ? void 0 : _customWrapper$curren2.values) !== null && _customWrapper$curren !== void 0 ? _customWrapper$curren : undefined);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
void (async () => {
|
|
71
|
+
await customWrapper.current.init();
|
|
72
|
+
customWrapper.current.addDataListener(_ref3 => {
|
|
73
|
+
let {
|
|
74
|
+
type,
|
|
75
|
+
value
|
|
76
|
+
} = _ref3;
|
|
77
|
+
setState(oldState => {
|
|
78
|
+
if (oldState) return {
|
|
79
|
+
...oldState,
|
|
80
|
+
[type]: value
|
|
81
|
+
};
|
|
82
|
+
return undefined;
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
if (customWrapper.current.values) {
|
|
86
|
+
setState({
|
|
87
|
+
...customWrapper.current.values
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
})();
|
|
130
91
|
}, []);
|
|
131
|
-
useEffect(
|
|
92
|
+
useEffect(() => {
|
|
132
93
|
if (isModule) {
|
|
133
94
|
setState(data);
|
|
134
|
-
|
|
135
95
|
if (data) {
|
|
136
96
|
moduleWrapper.current.values = data;
|
|
137
97
|
}
|
|
@@ -146,5 +106,4 @@ var ChaynsProvider = function ChaynsProvider(_ref2) {
|
|
|
146
106
|
renderedByServer: renderedByServer
|
|
147
107
|
}));
|
|
148
108
|
};
|
|
149
|
-
|
|
150
109
|
export default ChaynsProvider;
|