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.
Files changed (263) hide show
  1. package/.babelrc +30 -30
  2. package/.eslintrc +17 -17
  3. package/.github/workflows/deploy_docs.yml +28 -28
  4. package/.github/workflows/publish.yml +21 -0
  5. package/LICENSE +21 -21
  6. package/README.md +47 -47
  7. package/dist/cjs/calls/dialogs/alert.js +0 -2
  8. package/dist/cjs/calls/dialogs/chaynsDialog.js +2 -8
  9. package/dist/cjs/calls/dialogs/close.js +0 -2
  10. package/dist/cjs/calls/dialogs/communication.js +1 -16
  11. package/dist/cjs/calls/dialogs/confirm.js +0 -4
  12. package/dist/cjs/calls/dialogs/date.js +46 -63
  13. package/dist/cjs/calls/dialogs/dropUpAlert.js +0 -3
  14. package/dist/cjs/calls/dialogs/fileSelect.js +0 -10
  15. package/dist/cjs/calls/dialogs/iFrame.js +0 -8
  16. package/dist/cjs/calls/dialogs/index.js +0 -27
  17. package/dist/cjs/calls/dialogs/input.js +0 -6
  18. package/dist/cjs/calls/dialogs/mediaSelect.js +0 -7
  19. package/dist/cjs/calls/dialogs/open.js +0 -2
  20. package/dist/cjs/calls/dialogs/select.js +0 -9
  21. package/dist/cjs/calls/dialogs/signature.js +0 -5
  22. package/dist/cjs/calls/dialogs/toast.js +0 -3
  23. package/dist/cjs/calls/dialogs/utils/callback.js +0 -2
  24. package/dist/cjs/calls/dialogs/utils/is.js +0 -4
  25. package/dist/cjs/calls/getUserInfo.js +0 -11
  26. package/dist/cjs/calls/index.js +95 -247
  27. package/dist/cjs/calls/sendMessage.js +8 -34
  28. package/dist/cjs/calls/visibilityChangeListener.js +5 -16
  29. package/dist/cjs/components/ChaynsContext.js +2 -4
  30. package/dist/cjs/components/ChaynsProvider.js +6 -28
  31. package/dist/cjs/components/WaitUntil.js +0 -5
  32. package/dist/cjs/components/withCompatMode.js +1 -16
  33. package/dist/cjs/helper/apiListenerHelper.js +0 -9
  34. package/dist/cjs/hooks/geoLocationListener.js +6 -15
  35. package/dist/cjs/hooks/index.js +6 -16
  36. package/dist/cjs/hooks/scrollListener.js +12 -31
  37. package/dist/cjs/hooks/useAccessToken.js +2 -7
  38. package/dist/cjs/hooks/useCurrentPage.js +2 -6
  39. package/dist/cjs/hooks/useCustomData.js +2 -6
  40. package/dist/cjs/hooks/useDevice.js +2 -6
  41. package/dist/cjs/hooks/useEnvironment.js +2 -6
  42. package/dist/cjs/hooks/useFunctions.js +2 -6
  43. package/dist/cjs/hooks/useIsAdminMode.js +2 -7
  44. package/dist/cjs/hooks/useLanguage.js +2 -6
  45. package/dist/cjs/hooks/usePages.js +26 -18
  46. package/dist/cjs/hooks/useParameters.js +2 -6
  47. package/dist/cjs/hooks/useSite.js +2 -6
  48. package/dist/cjs/hooks/useUser.js +2 -7
  49. package/dist/cjs/hooks/useValues.js +2 -6
  50. package/dist/cjs/hooks/windowMetricsListener.js +6 -16
  51. package/dist/cjs/host/ChaynsHost.js +0 -10
  52. package/dist/cjs/host/iframe/HostIframe.js +23 -30
  53. package/dist/cjs/host/iframe/utils/useUpdateData.js +0 -3
  54. package/dist/cjs/host/module/ModuleHost.js +3 -13
  55. package/dist/cjs/host/module/utils/loadComponent.js +1 -18
  56. package/dist/cjs/host/module/utils/useDynamicScript.js +0 -18
  57. package/dist/cjs/index.js +0 -19
  58. package/dist/cjs/types/IChaynsReact.js +27 -48
  59. package/dist/cjs/util/appCall.js +1 -4
  60. package/dist/cjs/util/deviceHelper.js +5 -22
  61. package/dist/cjs/util/heightHelper.js +0 -9
  62. package/dist/cjs/util/postIframeForm.js +0 -5
  63. package/dist/cjs/wrapper/AppWrapper.js +323 -159
  64. package/dist/cjs/wrapper/FrameWrapper.js +219 -248
  65. package/dist/cjs/wrapper/ModuleFederationWrapper.js +2 -27
  66. package/dist/cjs/wrapper/SsrWrapper.js +0 -8
  67. package/dist/esm/calls/dialogs/alert.js +4 -4
  68. package/dist/esm/calls/dialogs/chaynsDialog.js +7 -11
  69. package/dist/esm/calls/dialogs/communication.js +15 -26
  70. package/dist/esm/calls/dialogs/confirm.js +5 -8
  71. package/dist/esm/calls/dialogs/date.js +119 -128
  72. package/dist/esm/calls/dialogs/dropUpAlert.js +1 -1
  73. package/dist/esm/calls/dialogs/fileSelect.js +23 -62
  74. package/dist/esm/calls/dialogs/iFrame.js +7 -10
  75. package/dist/esm/calls/dialogs/input.js +2 -5
  76. package/dist/esm/calls/dialogs/mediaSelect.js +18 -55
  77. package/dist/esm/calls/dialogs/open.js +2 -2
  78. package/dist/esm/calls/dialogs/select.js +5 -9
  79. package/dist/esm/calls/dialogs/signature.js +0 -2
  80. package/dist/esm/calls/dialogs/toast.js +6 -11
  81. package/dist/esm/calls/dialogs/utils/callback.js +3 -5
  82. package/dist/esm/calls/dialogs/utils/is.js +1 -3
  83. package/dist/esm/calls/getUserInfo.js +32 -92
  84. package/dist/esm/calls/index.js +297 -449
  85. package/dist/esm/calls/sendMessage.js +99 -229
  86. package/dist/esm/calls/visibilityChangeListener.js +14 -19
  87. package/dist/esm/components/ChaynsContext.js +3 -3
  88. package/dist/esm/components/ChaynsProvider.js +45 -86
  89. package/dist/esm/components/WaitUntil.js +21 -86
  90. package/dist/esm/components/withCompatMode.js +35 -77
  91. package/dist/esm/helper/apiListenerHelper.js +10 -15
  92. package/dist/esm/hooks/geoLocationListener.js +24 -50
  93. package/dist/esm/hooks/index.js +1 -1
  94. package/dist/esm/hooks/scrollListener.js +58 -94
  95. package/dist/esm/hooks/useAccessToken.js +8 -30
  96. package/dist/esm/hooks/useCurrentPage.js +4 -8
  97. package/dist/esm/hooks/useCustomData.js +4 -8
  98. package/dist/esm/hooks/useDevice.js +3 -8
  99. package/dist/esm/hooks/useEnvironment.js +3 -8
  100. package/dist/esm/hooks/useFunctions.js +4 -7
  101. package/dist/esm/hooks/useIsAdminMode.js +4 -8
  102. package/dist/esm/hooks/useLanguage.js +3 -8
  103. package/dist/esm/hooks/usePages.js +38 -31
  104. package/dist/esm/hooks/useParameters.js +3 -8
  105. package/dist/esm/hooks/useSite.js +3 -8
  106. package/dist/esm/hooks/useUser.js +3 -9
  107. package/dist/esm/hooks/useValues.js +4 -7
  108. package/dist/esm/hooks/windowMetricsListener.js +22 -48
  109. package/dist/esm/host/ChaynsHost.js +22 -29
  110. package/dist/esm/host/iframe/HostIframe.js +86 -142
  111. package/dist/esm/host/iframe/utils/useUpdateData.js +4 -6
  112. package/dist/esm/host/module/ModuleHost.js +42 -49
  113. package/dist/esm/host/module/utils/loadComponent.js +47 -85
  114. package/dist/esm/host/module/utils/useDynamicScript.js +27 -74
  115. package/dist/esm/types/IChaynsReact.js +37 -61
  116. package/dist/esm/util/appCall.js +2 -4
  117. package/dist/esm/util/deviceHelper.js +13 -37
  118. package/dist/esm/util/heightHelper.js +10 -13
  119. package/dist/esm/util/postIframeForm.js +25 -57
  120. package/dist/esm/wrapper/AppWrapper.js +385 -781
  121. package/dist/esm/wrapper/FrameWrapper.js +262 -1509
  122. package/dist/esm/wrapper/ModuleFederationWrapper.js +47 -284
  123. package/dist/esm/wrapper/SsrWrapper.js +19 -65
  124. package/dist/types/calls/dialogs/alert.d.ts +1 -1
  125. package/dist/types/calls/dialogs/chaynsDialog.d.ts +24 -24
  126. package/dist/types/calls/dialogs/close.d.ts +1 -1
  127. package/dist/types/calls/dialogs/communication.d.ts +3 -3
  128. package/dist/types/calls/dialogs/confirm.d.ts +13 -13
  129. package/dist/types/calls/dialogs/date.d.ts +96 -96
  130. package/dist/types/calls/dialogs/dropUpAlert.d.ts +5 -5
  131. package/dist/types/calls/dialogs/fileSelect.d.ts +16 -16
  132. package/dist/types/calls/dialogs/iFrame.d.ts +10 -10
  133. package/dist/types/calls/dialogs/index.d.ts +14 -14
  134. package/dist/types/calls/dialogs/input.d.ts +15 -15
  135. package/dist/types/calls/dialogs/mediaSelect.d.ts +8 -8
  136. package/dist/types/calls/dialogs/open.d.ts +1 -1
  137. package/dist/types/calls/dialogs/select.d.ts +6 -6
  138. package/dist/types/calls/dialogs/signature.d.ts +7 -7
  139. package/dist/types/calls/dialogs/toast.d.ts +1 -1
  140. package/dist/types/calls/dialogs/utils/callback.d.ts +1 -1
  141. package/dist/types/calls/dialogs/utils/is.d.ts +4 -4
  142. package/dist/types/calls/getUserInfo.d.ts +9 -9
  143. package/dist/types/calls/index.d.ts +225 -231
  144. package/dist/types/calls/sendMessage.d.ts +13 -13
  145. package/dist/types/calls/visibilityChangeListener.d.ts +9 -9
  146. package/dist/types/components/ChaynsContext.d.ts +3 -3
  147. package/dist/types/components/ChaynsProvider.d.ts +13 -13
  148. package/dist/types/components/WaitUntil.d.ts +7 -7
  149. package/dist/types/components/withCompatMode.d.ts +13 -13
  150. package/dist/types/helper/apiListenerHelper.d.ts +6 -6
  151. package/dist/types/hooks/geoLocationListener.d.ts +18 -18
  152. package/dist/types/hooks/index.d.ts +16 -16
  153. package/dist/types/hooks/scrollListener.d.ts +28 -28
  154. package/dist/types/hooks/useAccessToken.d.ts +5 -5
  155. package/dist/types/hooks/useCurrentPage.d.ts +4 -4
  156. package/dist/types/hooks/useCustomData.d.ts +4 -4
  157. package/dist/types/hooks/useDevice.d.ts +5 -5
  158. package/dist/types/hooks/useEnvironment.d.ts +5 -5
  159. package/dist/types/hooks/useFunctions.d.ts +5 -5
  160. package/dist/types/hooks/useIsAdminMode.d.ts +4 -4
  161. package/dist/types/hooks/useLanguage.d.ts +5 -5
  162. package/dist/types/hooks/usePages.d.ts +18 -14
  163. package/dist/types/hooks/useParameters.d.ts +5 -5
  164. package/dist/types/hooks/useSite.d.ts +5 -5
  165. package/dist/types/hooks/useUser.d.ts +5 -5
  166. package/dist/types/hooks/useValues.d.ts +5 -5
  167. package/dist/types/hooks/windowMetricsListener.d.ts +11 -11
  168. package/dist/types/host/ChaynsHost.d.ts +28 -28
  169. package/dist/types/host/iframe/HostIframe.d.ts +24 -24
  170. package/dist/types/host/iframe/utils/useUpdateData.d.ts +3 -3
  171. package/dist/types/host/module/ModuleHost.d.ts +23 -23
  172. package/dist/types/host/module/utils/loadComponent.d.ts +1 -1
  173. package/dist/types/host/module/utils/useDynamicScript.d.ts +9 -9
  174. package/dist/types/index.d.ts +16 -16
  175. package/dist/types/types/IChaynsReact.d.ts +622 -590
  176. package/dist/types/types/dialog.d.ts +41 -41
  177. package/dist/types/util/appCall.d.ts +2 -2
  178. package/dist/types/util/deviceHelper.d.ts +7 -7
  179. package/dist/types/util/heightHelper.d.ts +1 -1
  180. package/dist/types/util/postIframeForm.d.ts +1 -1
  181. package/dist/types/wrapper/AppWrapper.d.ts +18 -16
  182. package/dist/types/wrapper/FrameWrapper.d.ts +15 -15
  183. package/dist/types/wrapper/ModuleFederationWrapper.d.ts +10 -10
  184. package/dist/types/wrapper/SsrWrapper.d.ts +11 -11
  185. package/package.json +76 -76
  186. package/toolkit.config.js +52 -52
  187. package/tsconfig.json +56 -56
  188. package/dist/cjs/bootstrap.js +0 -11
  189. package/dist/cjs/calls/abstractApiListener.js +0 -40
  190. package/dist/cjs/calls/apiEventListener.js +0 -40
  191. package/dist/cjs/calls/setVisibilityChangeListener.js +0 -1
  192. package/dist/cjs/calls/windowMetricsListener.js +0 -18
  193. package/dist/cjs/client.js +0 -93
  194. package/dist/cjs/components/App.js +0 -32
  195. package/dist/cjs/components/App.spec.js +0 -16
  196. package/dist/cjs/components/Button.js +0 -32
  197. package/dist/cjs/components/ChaynsModuleProvider.js +0 -457
  198. package/dist/cjs/components/ChaynsProviderExposed.js +0 -16
  199. package/dist/cjs/components/TestProvider.js +0 -236
  200. package/dist/cjs/components/Title.js +0 -162
  201. package/dist/cjs/functions/addApiListener.js +0 -37
  202. package/dist/cjs/functions/addGeoLocationListener.js +0 -26
  203. package/dist/cjs/functions/addScrollListener.js +0 -26
  204. package/dist/cjs/functions/addWindowMetricsListener.js +0 -37
  205. package/dist/cjs/helper/cssLoader.js +0 -28
  206. package/dist/cjs/hooks/addGeoLocationListener.js +0 -26
  207. package/dist/cjs/hooks/addScrollListener.js +0 -26
  208. package/dist/cjs/hooks/addWindowMetricsListener.js +0 -37
  209. package/dist/cjs/hooks/geoLocation.js +0 -48
  210. package/dist/cjs/hooks/useAddGeoLocationListener.js +0 -26
  211. package/dist/cjs/hooks/useAddScrollListener.js +0 -48
  212. package/dist/cjs/hooks/useAddWindowMetricsListener.js +0 -45
  213. package/dist/cjs/hooks/useAdddScrollListener.js +0 -26
  214. package/dist/cjs/hooks/windowMetrics.js +0 -45
  215. package/dist/cjs/host/HostIframe.js +0 -157
  216. package/dist/cjs/host/ModuleHost.js +0 -11
  217. package/dist/cjs/host/module/utils.js +0 -25
  218. package/dist/cjs/index.example.js +0 -7
  219. package/dist/cjs/index2.js +0 -64
  220. package/dist/cjs/types/DynamicApiImport.d.js +0 -5
  221. package/dist/cjs/types/DynamicImport.d.js +0 -5
  222. package/dist/cjs/types/chayns-components.d.js +0 -1
  223. package/dist/cjs/types/chayns-logger.d.js +0 -1
  224. package/dist/cjs/types/chayns.d.js +0 -1
  225. package/dist/cjs/types/tobit-websocket-service-client.d.js +0 -1
  226. package/dist/cjs/types/toolkit-types.d.js +0 -1
  227. package/dist/cjs/util/useFunctionsContext.js +0 -16
  228. package/dist/cjs/util/useIsAdminMode.js +0 -18
  229. package/dist/cjs/util/useUser.js +0 -16
  230. package/dist/esm/bootstrap.js +0 -4
  231. package/dist/esm/client.js +0 -8
  232. package/dist/esm/components/App.js +0 -35
  233. package/dist/esm/components/App.spec.js +0 -9
  234. package/dist/esm/components/Button.js +0 -34
  235. package/dist/esm/components/ChaynsModuleProvider.js +0 -517
  236. package/dist/esm/components/ChaynsProviderExposed.js +0 -3
  237. package/dist/esm/components/TestProvider.js +0 -308
  238. package/dist/esm/components/Title.js +0 -210
  239. package/dist/esm/helper/cssLoader.js +0 -21
  240. package/dist/esm/hooks/useAddGeoLocationListener.js +0 -18
  241. package/dist/esm/hooks/useAddScrollListener.js +0 -18
  242. package/dist/esm/hooks/useAddWindowMetricsListener.js +0 -18
  243. package/dist/esm/host/HostIframe.js +0 -153
  244. package/dist/esm/index.example.js +0 -1
  245. package/dist/esm/index2.js +0 -5
  246. package/dist/esm/types/DynamicApiImport.d.js +0 -1
  247. package/dist/esm/types/DynamicImport.d.js +0 -1
  248. package/dist/esm/types/chayns-components.d.js +0 -0
  249. package/dist/esm/types/chayns-logger.d.js +0 -0
  250. package/dist/esm/types/chayns.d.js +0 -0
  251. package/dist/esm/types/tobit-websocket-service-client.d.js +0 -0
  252. package/dist/esm/types/toolkit-types.d.js +0 -0
  253. package/dist/esm/util/useIsAdminMode.js +0 -9
  254. package/dist/esm/util/useUser.js +0 -7
  255. package/dist/types/bootstrap.d.ts +0 -1
  256. package/dist/types/client.d.ts +0 -7
  257. package/dist/types/components/App.d.ts +0 -5
  258. package/dist/types/components/Button.d.ts +0 -8
  259. package/dist/types/components/ChaynsModuleProvider.d.ts +0 -170
  260. package/dist/types/components/ChaynsProviderExposed.d.ts +0 -13
  261. package/dist/types/components/Title.d.ts +0 -3
  262. package/dist/types/host/HostIframe.d.ts +0 -20
  263. package/dist/types/index.example.d.ts +0 -0
@@ -1,239 +1,109 @@
1
- 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); } }
2
-
3
- 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); }); }; }
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
- export var sendMessageToUser = /*#__PURE__*/function () {
11
- var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(api, object, receiverUserId) {
12
- var _api$values$user;
13
-
14
- var senderUserId, _yield$api$functions$, accessToken, images;
15
-
16
- return regeneratorRuntime.wrap(function _callee$(_context) {
17
- while (1) {
18
- switch (_context.prev = _context.next) {
19
- case 0:
20
- if (object.text) {
21
- _context.next = 2;
22
- break;
23
- }
24
-
25
- return _context.abrupt("return", Promise.reject(new Error('no text specified')));
26
-
27
- case 2:
28
- senderUserId = (_api$values$user = api.values.user) === null || _api$values$user === void 0 ? void 0 : _api$values$user.userId;
29
-
30
- if (!(senderUserId === undefined)) {
31
- _context.next = 5;
32
- break;
33
- }
34
-
35
- return _context.abrupt("return", Promise.reject(new Error('missing sender user id')));
36
-
37
- case 5:
38
- _context.next = 7;
39
- return api.functions.getAccessToken();
40
-
41
- case 7:
42
- _yield$api$functions$ = _context.sent;
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
- export var sendMessageToPage = /*#__PURE__*/function () {
94
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(api, object) {
95
- var _api$values$user2;
96
-
97
- var senderUserId, _yield$api$functions$2, accessToken, images;
98
-
99
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
100
- while (1) {
101
- switch (_context2.prev = _context2.next) {
102
- case 0:
103
- if (object.text) {
104
- _context2.next = 2;
105
- break;
106
- }
107
-
108
- return _context2.abrupt("return", Promise.reject(new Error('no text specified')));
109
-
110
- case 2:
111
- senderUserId = (_api$values$user2 = api.values.user) === null || _api$values$user2 === void 0 ? void 0 : _api$values$user2.userId;
112
-
113
- if (!(senderUserId === undefined)) {
114
- _context2.next = 5;
115
- break;
116
- }
117
-
118
- return _context2.abrupt("return", Promise.reject(new Error('missing sender user id')));
119
-
120
- case 5:
121
- _context2.next = 7;
122
- return api.functions.getAccessToken();
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
- export var sendMessageToGroup = /*#__PURE__*/function () {
169
- var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(api, object, groupId) {
170
- var _yield$api$functions$3, accessToken, locationId, images;
171
-
172
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
173
- while (1) {
174
- switch (_context3.prev = _context3.next) {
175
- case 0:
176
- if (object.text) {
177
- _context3.next = 2;
178
- break;
179
- }
180
-
181
- return _context3.abrupt("return", Promise.reject(new Error('no text specified')));
182
-
183
- case 2:
184
- _context3.next = 4;
185
- return api.functions.getAccessToken();
186
-
187
- case 4:
188
- _yield$api$functions$3 = _context3.sent;
189
- accessToken = _yield$api$functions$3.accessToken;
190
- locationId = api.values.site.locationId;
191
-
192
- if (accessToken) {
193
- _context3.next = 9;
194
- break;
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("".concat(INTERCOM_URL).concat(endpoint), {
103
+ return fetch(`${INTERCOM_URL}${endpoint}`, {
234
104
  method: 'POST',
235
105
  headers: {
236
- authorization: "bearer ".concat(token),
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
- var key = 'visibilityChangeListener';
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
- export var removeVisibilityChangeListener = function removeVisibilityChangeListener(id) {
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 var ChaynsContext = createContext(null); // @ts-expect-error Functions cant be null, implementation of default values is redundant
3
-
4
- export var ChaynsFunctionsContext = createContext(null);
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'; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
9
+ import { ChaynsContext, ChaynsFunctionsContext } from './ChaynsContext';
32
10
 
33
- export var moduleWrapper = {
11
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12
+ export const moduleWrapper = {
34
13
  current: undefined
35
14
  };
36
- var isServer = typeof window === 'undefined';
37
- var InitialDataProvider = /*#__PURE__*/React.memo(function (_ref) {
38
- var data = _ref.data,
39
- renderedByServer = _ref.renderedByServer;
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
- }, function () {
53
- return true;
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
- var children = _ref2.children,
60
- data = _ref2.data,
61
- functions = _ref2.functions,
62
- renderedByServer = _ref2.renderedByServer,
63
- isModule = _ref2.isModule;
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
- var customWrapper = useRef(null);
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
- var deviceInfo = getDeviceInfo(navigator.userAgent, ''); // load framewrapper in Chaynsweb in app (window.self === window.top)
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
- var _useState = 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),
96
- _useState2 = _slicedToArray(_useState, 2),
97
- state = _useState2[0],
98
- setState = _useState2[1];
99
-
100
- useEffect(function () {
101
- void _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
102
- return regeneratorRuntime.wrap(function _callee$(_context) {
103
- while (1) {
104
- switch (_context.prev = _context.next) {
105
- case 0:
106
- _context.next = 2;
107
- return customWrapper.current.init();
108
-
109
- case 2:
110
- customWrapper.current.addDataListener(function (_ref4) {
111
- var type = _ref4.type,
112
- value = _ref4.value;
113
- setState(function (oldState) {
114
- if (oldState) return _objectSpread(_objectSpread({}, oldState), {}, _defineProperty({}, type, value));
115
- return undefined;
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(function () {
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;