chayns-api 1.0.1 → 1.0.2

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 (211) hide show
  1. package/dist/cjs/calls/dialogs/alert.js +0 -2
  2. package/dist/cjs/calls/dialogs/chaynsDialog.js +2 -8
  3. package/dist/cjs/calls/dialogs/close.js +0 -2
  4. package/dist/cjs/calls/dialogs/communication.js +1 -16
  5. package/dist/cjs/calls/dialogs/confirm.js +0 -4
  6. package/dist/cjs/calls/dialogs/date.js +36 -53
  7. package/dist/cjs/calls/dialogs/dropUpAlert.js +0 -3
  8. package/dist/cjs/calls/dialogs/fileSelect.js +0 -10
  9. package/dist/cjs/calls/dialogs/iFrame.js +0 -8
  10. package/dist/cjs/calls/dialogs/index.js +0 -27
  11. package/dist/cjs/calls/dialogs/input.js +0 -6
  12. package/dist/cjs/calls/dialogs/mediaSelect.js +0 -7
  13. package/dist/cjs/calls/dialogs/open.js +0 -2
  14. package/dist/cjs/calls/dialogs/select.js +0 -9
  15. package/dist/cjs/calls/dialogs/signature.js +0 -5
  16. package/dist/cjs/calls/dialogs/toast.js +0 -3
  17. package/dist/cjs/calls/dialogs/utils/callback.js +0 -2
  18. package/dist/cjs/calls/dialogs/utils/environment.js +10 -0
  19. package/dist/cjs/calls/dialogs/utils/is.js +0 -4
  20. package/dist/cjs/calls/getUserInfo.js +0 -11
  21. package/dist/cjs/calls/index.js +3 -155
  22. package/dist/cjs/calls/sendMessage.js +0 -26
  23. package/dist/cjs/calls/visibilityChangeListener.js +1 -12
  24. package/dist/cjs/components/ChaynsContext.js +2 -4
  25. package/dist/cjs/components/ChaynsProvider.js +6 -28
  26. package/dist/cjs/components/WaitUntil.js +0 -5
  27. package/dist/cjs/components/withCompatMode.js +1 -16
  28. package/dist/cjs/helper/apiListenerHelper.js +0 -9
  29. package/dist/cjs/hooks/geoLocationListener.js +2 -11
  30. package/dist/cjs/hooks/index.js +6 -16
  31. package/dist/cjs/hooks/scrollListener.js +4 -23
  32. package/dist/cjs/hooks/useAccessToken.js +0 -5
  33. package/dist/cjs/hooks/useCurrentPage.js +0 -4
  34. package/dist/cjs/hooks/useCustomData.js +0 -4
  35. package/dist/cjs/hooks/useDevice.js +0 -4
  36. package/dist/cjs/hooks/useEnvironment.js +0 -4
  37. package/dist/cjs/hooks/useFunctions.js +0 -4
  38. package/dist/cjs/hooks/useIsAdminMode.js +0 -5
  39. package/dist/cjs/hooks/useLanguage.js +0 -4
  40. package/dist/cjs/hooks/usePages.js +22 -14
  41. package/dist/cjs/hooks/useParameters.js +0 -4
  42. package/dist/cjs/hooks/useSite.js +0 -4
  43. package/dist/cjs/hooks/useUser.js +0 -5
  44. package/dist/cjs/hooks/useValues.js +0 -4
  45. package/dist/cjs/hooks/windowMetricsListener.js +2 -12
  46. package/dist/cjs/host/ChaynsHost.js +0 -10
  47. package/dist/cjs/host/iframe/HostIframe.js +23 -30
  48. package/dist/cjs/host/iframe/utils/useUpdateData.js +0 -3
  49. package/dist/cjs/host/module/ModuleHost.js +3 -13
  50. package/dist/cjs/host/{HostIframe.js → module/PagemakerFrame.js} +23 -75
  51. package/dist/cjs/host/module/utils/loadComponent.js +1 -18
  52. package/dist/cjs/host/module/utils/useDynamicScript.js +0 -18
  53. package/dist/cjs/index.js +0 -19
  54. package/dist/cjs/types/IChaynsReact.js +27 -48
  55. package/dist/cjs/util/appCall.js +1 -4
  56. package/dist/cjs/util/deviceHelper.js +4 -21
  57. package/dist/cjs/util/heightHelper.js +0 -9
  58. package/dist/cjs/util/postIframeForm.js +0 -5
  59. package/dist/cjs/wrapper/AppWrapper.js +318 -159
  60. package/dist/cjs/wrapper/FrameWrapper.js +215 -248
  61. package/dist/cjs/wrapper/ModuleFederationWrapper.js +2 -27
  62. package/dist/cjs/wrapper/SsrWrapper.js +0 -8
  63. package/dist/esm/calls/dialogs/alert.js +4 -4
  64. package/dist/esm/calls/dialogs/chaynsDialog.js +7 -11
  65. package/dist/esm/calls/dialogs/communication.js +15 -26
  66. package/dist/esm/calls/dialogs/confirm.js +5 -8
  67. package/dist/esm/calls/dialogs/date.js +85 -94
  68. package/dist/esm/calls/dialogs/dropUpAlert.js +1 -1
  69. package/dist/esm/calls/dialogs/fileSelect.js +23 -62
  70. package/dist/esm/calls/dialogs/iFrame.js +7 -10
  71. package/dist/esm/calls/dialogs/input.js +2 -5
  72. package/dist/esm/calls/dialogs/mediaSelect.js +18 -55
  73. package/dist/esm/calls/dialogs/open.js +2 -2
  74. package/dist/esm/calls/dialogs/select.js +5 -9
  75. package/dist/esm/calls/dialogs/signature.js +0 -2
  76. package/dist/esm/calls/dialogs/toast.js +6 -11
  77. package/dist/esm/calls/dialogs/utils/callback.js +3 -5
  78. package/dist/esm/calls/dialogs/utils/environment.js +3 -0
  79. package/dist/esm/calls/dialogs/utils/is.js +1 -3
  80. package/dist/esm/calls/getUserInfo.js +32 -92
  81. package/dist/esm/calls/index.js +124 -276
  82. package/dist/esm/calls/sendMessage.js +91 -221
  83. package/dist/esm/calls/visibilityChangeListener.js +10 -15
  84. package/dist/esm/components/ChaynsContext.js +3 -3
  85. package/dist/esm/components/ChaynsProvider.js +45 -86
  86. package/dist/esm/components/WaitUntil.js +21 -86
  87. package/dist/esm/components/withCompatMode.js +35 -77
  88. package/dist/esm/helper/apiListenerHelper.js +10 -15
  89. package/dist/esm/hooks/geoLocationListener.js +20 -46
  90. package/dist/esm/hooks/index.js +1 -1
  91. package/dist/esm/hooks/scrollListener.js +50 -86
  92. package/dist/esm/hooks/useAccessToken.js +6 -28
  93. package/dist/esm/hooks/useCurrentPage.js +2 -6
  94. package/dist/esm/hooks/useCustomData.js +2 -6
  95. package/dist/esm/hooks/useDevice.js +1 -6
  96. package/dist/esm/hooks/useEnvironment.js +1 -6
  97. package/dist/esm/hooks/useFunctions.js +2 -5
  98. package/dist/esm/hooks/useIsAdminMode.js +2 -6
  99. package/dist/esm/hooks/useLanguage.js +1 -6
  100. package/dist/esm/hooks/usePages.js +34 -27
  101. package/dist/esm/hooks/useParameters.js +1 -6
  102. package/dist/esm/hooks/useSite.js +1 -6
  103. package/dist/esm/hooks/useUser.js +1 -7
  104. package/dist/esm/hooks/useValues.js +2 -5
  105. package/dist/esm/hooks/windowMetricsListener.js +18 -44
  106. package/dist/esm/host/ChaynsHost.js +22 -29
  107. package/dist/esm/host/iframe/HostIframe.js +86 -142
  108. package/dist/esm/host/iframe/utils/useUpdateData.js +4 -6
  109. package/dist/esm/host/module/ModuleHost.js +42 -49
  110. package/dist/esm/host/module/PagemakerFrame.js +97 -0
  111. package/dist/esm/host/module/utils/loadComponent.js +47 -85
  112. package/dist/esm/host/module/utils/useDynamicScript.js +27 -74
  113. package/dist/esm/types/IChaynsReact.js +37 -61
  114. package/dist/esm/util/appCall.js +2 -4
  115. package/dist/esm/util/deviceHelper.js +12 -36
  116. package/dist/esm/util/heightHelper.js +10 -13
  117. package/dist/esm/util/postIframeForm.js +25 -57
  118. package/dist/esm/wrapper/AppWrapper.js +380 -781
  119. package/dist/esm/wrapper/FrameWrapper.js +258 -1509
  120. package/dist/esm/wrapper/ModuleFederationWrapper.js +47 -284
  121. package/dist/esm/wrapper/SsrWrapper.js +19 -65
  122. package/dist/types/calls/dialogs/confirm.d.ts +1 -1
  123. package/dist/types/calls/dialogs/date.d.ts +4 -4
  124. package/dist/types/calls/dialogs/dropUpAlert.d.ts +1 -1
  125. package/dist/types/calls/dialogs/fileSelect.d.ts +1 -1
  126. package/dist/types/calls/dialogs/iFrame.d.ts +1 -1
  127. package/dist/types/calls/dialogs/input.d.ts +1 -1
  128. package/dist/types/calls/dialogs/mediaSelect.d.ts +1 -1
  129. package/dist/types/calls/dialogs/signature.d.ts +1 -1
  130. package/dist/types/calls/dialogs/utils/environment.d.ts +3 -0
  131. package/dist/types/calls/index.d.ts +0 -6
  132. package/dist/types/components/ChaynsProvider.d.ts +1 -1
  133. package/dist/types/components/WaitUntil.d.ts +1 -1
  134. package/dist/types/components/withCompatMode.d.ts +1 -1
  135. package/dist/types/hooks/index.d.ts +1 -1
  136. package/dist/types/hooks/useAccessToken.d.ts +1 -1
  137. package/dist/types/hooks/usePages.d.ts +4 -0
  138. package/dist/types/host/ChaynsHost.d.ts +1 -1
  139. package/dist/types/host/iframe/HostIframe.d.ts +1 -1
  140. package/dist/types/host/module/ModuleHost.d.ts +2 -2
  141. package/dist/types/host/{HostIframe.d.ts → module/PagemakerFrame.d.ts} +7 -5
  142. package/dist/types/types/IChaynsReact.d.ts +55 -24
  143. package/dist/types/util/deviceHelper.d.ts +2 -2
  144. package/dist/types/wrapper/AppWrapper.d.ts +6 -4
  145. package/package.json +1 -1
  146. package/dist/cjs/bootstrap.js +0 -11
  147. package/dist/cjs/calls/abstractApiListener.js +0 -40
  148. package/dist/cjs/calls/apiEventListener.js +0 -40
  149. package/dist/cjs/calls/setVisibilityChangeListener.js +0 -1
  150. package/dist/cjs/calls/windowMetricsListener.js +0 -18
  151. package/dist/cjs/components/App.js +0 -32
  152. package/dist/cjs/components/App.spec.js +0 -16
  153. package/dist/cjs/components/Button.js +0 -32
  154. package/dist/cjs/components/ChaynsProviderExposed.js +0 -16
  155. package/dist/cjs/components/TestProvider.js +0 -236
  156. package/dist/cjs/components/Title.js +0 -162
  157. package/dist/cjs/functions/addApiListener.js +0 -37
  158. package/dist/cjs/functions/addGeoLocationListener.js +0 -26
  159. package/dist/cjs/functions/addScrollListener.js +0 -26
  160. package/dist/cjs/functions/addWindowMetricsListener.js +0 -37
  161. package/dist/cjs/helper/cssLoader.js +0 -28
  162. package/dist/cjs/hooks/addGeoLocationListener.js +0 -26
  163. package/dist/cjs/hooks/addScrollListener.js +0 -26
  164. package/dist/cjs/hooks/addWindowMetricsListener.js +0 -37
  165. package/dist/cjs/hooks/geoLocation.js +0 -48
  166. package/dist/cjs/hooks/useAddGeoLocationListener.js +0 -26
  167. package/dist/cjs/hooks/useAddScrollListener.js +0 -48
  168. package/dist/cjs/hooks/useAddWindowMetricsListener.js +0 -45
  169. package/dist/cjs/hooks/useAdddScrollListener.js +0 -26
  170. package/dist/cjs/hooks/windowMetrics.js +0 -45
  171. package/dist/cjs/host/ModuleHost.js +0 -11
  172. package/dist/cjs/host/module/utils.js +0 -25
  173. package/dist/cjs/index.example.js +0 -7
  174. package/dist/cjs/index2.js +0 -64
  175. package/dist/cjs/types/DynamicImport.d.js +0 -5
  176. package/dist/cjs/types/chayns-components.d.js +0 -1
  177. package/dist/cjs/types/chayns-logger.d.js +0 -1
  178. package/dist/cjs/types/chayns.d.js +0 -1
  179. package/dist/cjs/types/tobit-websocket-service-client.d.js +0 -1
  180. package/dist/cjs/types/toolkit-types.d.js +0 -1
  181. package/dist/cjs/util/useFunctionsContext.js +0 -16
  182. package/dist/cjs/util/useIsAdminMode.js +0 -18
  183. package/dist/cjs/util/useUser.js +0 -16
  184. package/dist/esm/bootstrap.js +0 -4
  185. package/dist/esm/components/App.js +0 -35
  186. package/dist/esm/components/App.spec.js +0 -9
  187. package/dist/esm/components/Button.js +0 -34
  188. package/dist/esm/components/ChaynsProviderExposed.js +0 -3
  189. package/dist/esm/components/TestProvider.js +0 -308
  190. package/dist/esm/components/Title.js +0 -210
  191. package/dist/esm/helper/cssLoader.js +0 -21
  192. package/dist/esm/hooks/useAddGeoLocationListener.js +0 -18
  193. package/dist/esm/hooks/useAddScrollListener.js +0 -18
  194. package/dist/esm/hooks/useAddWindowMetricsListener.js +0 -18
  195. package/dist/esm/host/HostIframe.js +0 -153
  196. package/dist/esm/index.example.js +0 -1
  197. package/dist/esm/index2.js +0 -5
  198. package/dist/esm/types/DynamicImport.d.js +0 -1
  199. package/dist/esm/types/chayns-components.d.js +0 -0
  200. package/dist/esm/types/chayns-logger.d.js +0 -0
  201. package/dist/esm/types/chayns.d.js +0 -0
  202. package/dist/esm/types/tobit-websocket-service-client.d.js +0 -0
  203. package/dist/esm/types/toolkit-types.d.js +0 -0
  204. package/dist/esm/util/useIsAdminMode.js +0 -9
  205. package/dist/esm/util/useUser.js +0 -7
  206. package/dist/types/bootstrap.d.ts +0 -1
  207. package/dist/types/components/App.d.ts +0 -5
  208. package/dist/types/components/Button.d.ts +0 -8
  209. package/dist/types/components/ChaynsProviderExposed.d.ts +0 -13
  210. package/dist/types/components/Title.d.ts +0 -3
  211. 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';
1
+ const INTERCOM_URL = 'https://sub54.tobit.com/rest/api';
6
2
  /**
7
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
- }();
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
+ };
89
37
  /**
90
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
- }();
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
+ };
164
69
  /**
165
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
- }();
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
+ };
228
99
  /**
229
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
  };
8
+
9
9
  /**
10
10
  * @category Event listener
11
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
-
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
22
  /**
26
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;