chayns-api 1.0.0

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 (205) hide show
  1. package/.babelrc +30 -0
  2. package/.eslintrc +17 -0
  3. package/.github/workflows/deploy_docs.yml +28 -0
  4. package/LICENSE +21 -0
  5. package/README.md +47 -0
  6. package/dist/cjs/calls/dialogs/alert.js +19 -0
  7. package/dist/cjs/calls/dialogs/chaynsDialog.js +59 -0
  8. package/dist/cjs/calls/dialogs/close.js +13 -0
  9. package/dist/cjs/calls/dialogs/communication.js +71 -0
  10. package/dist/cjs/calls/dialogs/confirm.js +33 -0
  11. package/dist/cjs/calls/dialogs/date.js +187 -0
  12. package/dist/cjs/calls/dialogs/dropUpAlert.js +12 -0
  13. package/dist/cjs/calls/dialogs/fileSelect.js +39 -0
  14. package/dist/cjs/calls/dialogs/iFrame.js +43 -0
  15. package/dist/cjs/calls/dialogs/index.js +178 -0
  16. package/dist/cjs/calls/dialogs/input.js +33 -0
  17. package/dist/cjs/calls/dialogs/mediaSelect.js +27 -0
  18. package/dist/cjs/calls/dialogs/open.js +19 -0
  19. package/dist/cjs/calls/dialogs/select.js +55 -0
  20. package/dist/cjs/calls/dialogs/signature.js +24 -0
  21. package/dist/cjs/calls/dialogs/toast.js +18 -0
  22. package/dist/cjs/calls/dialogs/utils/callback.js +12 -0
  23. package/dist/cjs/calls/dialogs/utils/environment.js +10 -0
  24. package/dist/cjs/calls/dialogs/utils/is.js +21 -0
  25. package/dist/cjs/calls/getUserInfo.js +40 -0
  26. package/dist/cjs/calls/index.js +300 -0
  27. package/dist/cjs/calls/sendMessage.js +120 -0
  28. package/dist/cjs/calls/visibilityChangeListener.js +38 -0
  29. package/dist/cjs/client.js +93 -0
  30. package/dist/cjs/components/ChaynsContext.js +12 -0
  31. package/dist/cjs/components/ChaynsModuleProvider.js +457 -0
  32. package/dist/cjs/components/ChaynsProvider.js +116 -0
  33. package/dist/cjs/components/WaitUntil.js +31 -0
  34. package/dist/cjs/components/withCompatMode.js +55 -0
  35. package/dist/cjs/helper/apiListenerHelper.js +34 -0
  36. package/dist/cjs/hooks/geoLocationListener.js +50 -0
  37. package/dist/cjs/hooks/index.js +153 -0
  38. package/dist/cjs/hooks/scrollListener.js +102 -0
  39. package/dist/cjs/hooks/useAccessToken.js +28 -0
  40. package/dist/cjs/hooks/useCurrentPage.js +13 -0
  41. package/dist/cjs/hooks/useCustomData.js +13 -0
  42. package/dist/cjs/hooks/useDevice.js +13 -0
  43. package/dist/cjs/hooks/useEnvironment.js +13 -0
  44. package/dist/cjs/hooks/useFunctions.js +16 -0
  45. package/dist/cjs/hooks/useIsAdminMode.js +16 -0
  46. package/dist/cjs/hooks/useLanguage.js +13 -0
  47. package/dist/cjs/hooks/usePages.js +38 -0
  48. package/dist/cjs/hooks/useParameters.js +13 -0
  49. package/dist/cjs/hooks/useSite.js +13 -0
  50. package/dist/cjs/hooks/useUser.js +14 -0
  51. package/dist/cjs/hooks/useValues.js +16 -0
  52. package/dist/cjs/hooks/windowMetricsListener.js +58 -0
  53. package/dist/cjs/host/ChaynsHost.js +102 -0
  54. package/dist/cjs/host/iframe/HostIframe.js +133 -0
  55. package/dist/cjs/host/iframe/utils/useUpdateData.js +21 -0
  56. package/dist/cjs/host/module/ModuleHost.js +82 -0
  57. package/dist/cjs/host/module/PagemakerFrame.js +105 -0
  58. package/dist/cjs/host/module/utils/loadComponent.js +61 -0
  59. package/dist/cjs/host/module/utils/useDynamicScript.js +61 -0
  60. package/dist/cjs/index.js +117 -0
  61. package/dist/cjs/types/DynamicApiImport.d.js +5 -0
  62. package/dist/cjs/types/IChaynsReact.js +235 -0
  63. package/dist/cjs/types/dialog.js +5 -0
  64. package/dist/cjs/util/appCall.js +23 -0
  65. package/dist/cjs/util/deviceHelper.js +71 -0
  66. package/dist/cjs/util/heightHelper.js +40 -0
  67. package/dist/cjs/util/postIframeForm.js +32 -0
  68. package/dist/cjs/wrapper/AppWrapper.js +244 -0
  69. package/dist/cjs/wrapper/FrameWrapper.js +288 -0
  70. package/dist/cjs/wrapper/ModuleFederationWrapper.js +61 -0
  71. package/dist/cjs/wrapper/SsrWrapper.js +30 -0
  72. package/dist/esm/calls/dialogs/alert.js +15 -0
  73. package/dist/esm/calls/dialogs/chaynsDialog.js +48 -0
  74. package/dist/esm/calls/dialogs/close.js +7 -0
  75. package/dist/esm/calls/dialogs/communication.js +66 -0
  76. package/dist/esm/calls/dialogs/confirm.js +30 -0
  77. package/dist/esm/calls/dialogs/date.js +211 -0
  78. package/dist/esm/calls/dialogs/dropUpAlert.js +7 -0
  79. package/dist/esm/calls/dialogs/fileSelect.js +32 -0
  80. package/dist/esm/calls/dialogs/iFrame.js +37 -0
  81. package/dist/esm/calls/dialogs/index.js +14 -0
  82. package/dist/esm/calls/dialogs/input.js +26 -0
  83. package/dist/esm/calls/dialogs/mediaSelect.js +22 -0
  84. package/dist/esm/calls/dialogs/open.js +13 -0
  85. package/dist/esm/calls/dialogs/select.js +47 -0
  86. package/dist/esm/calls/dialogs/signature.js +18 -0
  87. package/dist/esm/calls/dialogs/toast.js +13 -0
  88. package/dist/esm/calls/dialogs/utils/callback.js +7 -0
  89. package/dist/esm/calls/dialogs/utils/environment.js +3 -0
  90. package/dist/esm/calls/dialogs/utils/is.js +12 -0
  91. package/dist/esm/calls/getUserInfo.js +33 -0
  92. package/dist/esm/calls/index.js +323 -0
  93. package/dist/esm/calls/sendMessage.js +111 -0
  94. package/dist/esm/calls/visibilityChangeListener.js +30 -0
  95. package/dist/esm/client.js +8 -0
  96. package/dist/esm/components/ChaynsContext.js +4 -0
  97. package/dist/esm/components/ChaynsModuleProvider.js +517 -0
  98. package/dist/esm/components/ChaynsProvider.js +109 -0
  99. package/dist/esm/components/WaitUntil.js +25 -0
  100. package/dist/esm/components/withCompatMode.js +47 -0
  101. package/dist/esm/helper/apiListenerHelper.js +25 -0
  102. package/dist/esm/hooks/geoLocationListener.js +43 -0
  103. package/dist/esm/hooks/index.js +16 -0
  104. package/dist/esm/hooks/scrollListener.js +95 -0
  105. package/dist/esm/hooks/useAccessToken.js +22 -0
  106. package/dist/esm/hooks/useCurrentPage.js +7 -0
  107. package/dist/esm/hooks/useCustomData.js +7 -0
  108. package/dist/esm/hooks/useDevice.js +6 -0
  109. package/dist/esm/hooks/useEnvironment.js +6 -0
  110. package/dist/esm/hooks/useFunctions.js +9 -0
  111. package/dist/esm/hooks/useIsAdminMode.js +9 -0
  112. package/dist/esm/hooks/useLanguage.js +6 -0
  113. package/dist/esm/hooks/usePages.js +32 -0
  114. package/dist/esm/hooks/useParameters.js +6 -0
  115. package/dist/esm/hooks/useSite.js +6 -0
  116. package/dist/esm/hooks/useUser.js +7 -0
  117. package/dist/esm/hooks/useValues.js +9 -0
  118. package/dist/esm/hooks/windowMetricsListener.js +51 -0
  119. package/dist/esm/host/ChaynsHost.js +95 -0
  120. package/dist/esm/host/iframe/HostIframe.js +124 -0
  121. package/dist/esm/host/iframe/utils/useUpdateData.js +14 -0
  122. package/dist/esm/host/module/ModuleHost.js +74 -0
  123. package/dist/esm/host/module/PagemakerFrame.js +97 -0
  124. package/dist/esm/host/module/utils/loadComponent.js +55 -0
  125. package/dist/esm/host/module/utils/useDynamicScript.js +50 -0
  126. package/dist/esm/index.js +16 -0
  127. package/dist/esm/types/DynamicApiImport.d.js +1 -0
  128. package/dist/esm/types/IChaynsReact.js +215 -0
  129. package/dist/esm/types/dialog.js +1 -0
  130. package/dist/esm/util/appCall.js +16 -0
  131. package/dist/esm/util/deviceHelper.js +62 -0
  132. package/dist/esm/util/heightHelper.js +32 -0
  133. package/dist/esm/util/postIframeForm.js +26 -0
  134. package/dist/esm/wrapper/AppWrapper.js +241 -0
  135. package/dist/esm/wrapper/FrameWrapper.js +279 -0
  136. package/dist/esm/wrapper/ModuleFederationWrapper.js +56 -0
  137. package/dist/esm/wrapper/SsrWrapper.js +23 -0
  138. package/dist/types/calls/dialogs/alert.d.ts +1 -0
  139. package/dist/types/calls/dialogs/chaynsDialog.d.ts +24 -0
  140. package/dist/types/calls/dialogs/close.d.ts +1 -0
  141. package/dist/types/calls/dialogs/communication.d.ts +3 -0
  142. package/dist/types/calls/dialogs/confirm.d.ts +13 -0
  143. package/dist/types/calls/dialogs/date.d.ts +96 -0
  144. package/dist/types/calls/dialogs/dropUpAlert.d.ts +5 -0
  145. package/dist/types/calls/dialogs/fileSelect.d.ts +16 -0
  146. package/dist/types/calls/dialogs/iFrame.d.ts +10 -0
  147. package/dist/types/calls/dialogs/index.d.ts +14 -0
  148. package/dist/types/calls/dialogs/input.d.ts +15 -0
  149. package/dist/types/calls/dialogs/mediaSelect.d.ts +8 -0
  150. package/dist/types/calls/dialogs/open.d.ts +1 -0
  151. package/dist/types/calls/dialogs/select.d.ts +6 -0
  152. package/dist/types/calls/dialogs/signature.d.ts +7 -0
  153. package/dist/types/calls/dialogs/toast.d.ts +1 -0
  154. package/dist/types/calls/dialogs/utils/callback.d.ts +1 -0
  155. package/dist/types/calls/dialogs/utils/environment.d.ts +3 -0
  156. package/dist/types/calls/dialogs/utils/is.d.ts +4 -0
  157. package/dist/types/calls/getUserInfo.d.ts +9 -0
  158. package/dist/types/calls/index.d.ts +231 -0
  159. package/dist/types/calls/sendMessage.d.ts +13 -0
  160. package/dist/types/calls/visibilityChangeListener.d.ts +9 -0
  161. package/dist/types/client.d.ts +7 -0
  162. package/dist/types/components/ChaynsContext.d.ts +3 -0
  163. package/dist/types/components/ChaynsModuleProvider.d.ts +170 -0
  164. package/dist/types/components/ChaynsProvider.d.ts +13 -0
  165. package/dist/types/components/WaitUntil.d.ts +7 -0
  166. package/dist/types/components/withCompatMode.d.ts +13 -0
  167. package/dist/types/helper/apiListenerHelper.d.ts +6 -0
  168. package/dist/types/hooks/geoLocationListener.d.ts +18 -0
  169. package/dist/types/hooks/index.d.ts +16 -0
  170. package/dist/types/hooks/scrollListener.d.ts +28 -0
  171. package/dist/types/hooks/useAccessToken.d.ts +5 -0
  172. package/dist/types/hooks/useCurrentPage.d.ts +4 -0
  173. package/dist/types/hooks/useCustomData.d.ts +4 -0
  174. package/dist/types/hooks/useDevice.d.ts +5 -0
  175. package/dist/types/hooks/useEnvironment.d.ts +5 -0
  176. package/dist/types/hooks/useFunctions.d.ts +5 -0
  177. package/dist/types/hooks/useIsAdminMode.d.ts +4 -0
  178. package/dist/types/hooks/useLanguage.d.ts +5 -0
  179. package/dist/types/hooks/usePages.d.ts +14 -0
  180. package/dist/types/hooks/useParameters.d.ts +5 -0
  181. package/dist/types/hooks/useSite.d.ts +5 -0
  182. package/dist/types/hooks/useUser.d.ts +5 -0
  183. package/dist/types/hooks/useValues.d.ts +5 -0
  184. package/dist/types/hooks/windowMetricsListener.d.ts +11 -0
  185. package/dist/types/host/ChaynsHost.d.ts +27 -0
  186. package/dist/types/host/iframe/HostIframe.d.ts +24 -0
  187. package/dist/types/host/iframe/utils/useUpdateData.d.ts +3 -0
  188. package/dist/types/host/module/ModuleHost.d.ts +23 -0
  189. package/dist/types/host/module/PagemakerFrame.d.ts +22 -0
  190. package/dist/types/host/module/utils/loadComponent.d.ts +1 -0
  191. package/dist/types/host/module/utils/useDynamicScript.d.ts +9 -0
  192. package/dist/types/index.d.ts +16 -0
  193. package/dist/types/types/IChaynsReact.d.ts +590 -0
  194. package/dist/types/types/dialog.d.ts +41 -0
  195. package/dist/types/util/appCall.d.ts +2 -0
  196. package/dist/types/util/deviceHelper.d.ts +7 -0
  197. package/dist/types/util/heightHelper.d.ts +1 -0
  198. package/dist/types/util/postIframeForm.d.ts +1 -0
  199. package/dist/types/wrapper/AppWrapper.d.ts +16 -0
  200. package/dist/types/wrapper/FrameWrapper.d.ts +15 -0
  201. package/dist/types/wrapper/ModuleFederationWrapper.d.ts +10 -0
  202. package/dist/types/wrapper/SsrWrapper.d.ts +11 -0
  203. package/package.json +76 -0
  204. package/toolkit.config.js +52 -0
  205. package/tsconfig.json +56 -0
@@ -0,0 +1,323 @@
1
+ import { moduleWrapper } from '../components/ChaynsProvider';
2
+ /**
3
+ * This adds a listener to determine your location.
4
+ * @category Event listener
5
+ */
6
+ export const addGeoLocationListener = function () {
7
+ return moduleWrapper.current.functions.addGeoLocationListener(...arguments);
8
+ };
9
+ /**
10
+ * Adds a listener for scroll event by user.
11
+ * @category Event listener
12
+ */
13
+ export const addScrollListener = function () {
14
+ return moduleWrapper.current.functions.addScrollListener(...arguments);
15
+ };
16
+ /**
17
+ * This method will be executed when the page gets displayed or hidden.
18
+ * @category Event listener
19
+ */
20
+ export const addVisibilityChangeListener = function () {
21
+ return moduleWrapper.current.functions.addVisibilityChangeListener(...arguments);
22
+ };
23
+ /**
24
+ * This adds a listener to get the actual height of the page.
25
+ * @category Event listener
26
+ */
27
+ export const addWindowMetricsListener = function () {
28
+ return moduleWrapper.current.functions.addWindowMetricsListener(...arguments);
29
+ }; /**
30
+ * Allows a custom callback function to be defined
31
+ */
32
+ export const customCallbackFunction = function () {
33
+ return moduleWrapper.current.functions.customCallbackFunction(...arguments);
34
+ };
35
+ /**
36
+ * Get the accessToken from the user.
37
+ */
38
+ export const getAccessToken = function () {
39
+ return moduleWrapper.current.functions.getAccessToken(...arguments);
40
+ };
41
+ /**
42
+ * This method returns a list of installed share/social media apps.
43
+ */
44
+ export const getAvailableSharingServices = function () {
45
+ return moduleWrapper.current.functions.getAvailableSharingServices(...arguments);
46
+ };
47
+ /**
48
+ * This method determines your location. If you want to track a route, use addGeoLocationListener.
49
+ */
50
+ export const getGeoLocation = function () {
51
+ return moduleWrapper.current.functions.getGeoLocation(...arguments);
52
+ };
53
+ /**
54
+ * This method returns user information for a specific user.
55
+ * @category User functions
56
+ */
57
+ export const getUserInfo = function () {
58
+ return moduleWrapper.current.functions.getUserInfo(...arguments);
59
+ };
60
+ /**
61
+ * Return the current scroll position of the top frame
62
+ */
63
+ export const getScrollPosition = function () {
64
+ return moduleWrapper.current.functions.getScrollPosition(...arguments);
65
+ };
66
+ /**
67
+ * Returns the window metrics.
68
+ */
69
+ export const getWindowMetrics = function () {
70
+ return moduleWrapper.current.functions.getWindowMetrics(...arguments);
71
+ };
72
+ /** @internal */
73
+ export const invokeCall = function () {
74
+ return moduleWrapper.current.functions.invokeCall(...arguments);
75
+ };
76
+ /** @internal */
77
+ export const invokeDialogCall = function () {
78
+ return moduleWrapper.current.functions.invokeDialogCall(...arguments);
79
+ };
80
+ /**
81
+ * This method will show a login dialog where the user has the opportunity to log in.
82
+ */
83
+ export const login = function () {
84
+ return moduleWrapper.current.functions.login(...arguments);
85
+ };
86
+ /**
87
+ * This method will logout the user
88
+ */
89
+ export const logout = function () {
90
+ return moduleWrapper.current.functions.logout(...arguments);
91
+ };
92
+ /**
93
+ * This function navigates you to the previous site.
94
+ */
95
+ export const navigateBack = function () {
96
+ return moduleWrapper.current.functions.navigateBack(...arguments);
97
+ };
98
+ /**
99
+ * The images specified in the url array is shown in gallery mode.
100
+ */
101
+ export const openImage = function () {
102
+ return moduleWrapper.current.functions.openImage(...arguments);
103
+ };
104
+ /**
105
+ * Opens an URL in the chayns environment.
106
+ */
107
+ export const openUrl = function () {
108
+ return moduleWrapper.current.functions.openUrl(...arguments);
109
+ };
110
+ /**
111
+ * The video specified in the URL is shown in video mode.
112
+ */
113
+ export const openVideo = function () {
114
+ return moduleWrapper.current.functions.openVideo(...arguments);
115
+ };
116
+ /**
117
+ * Refresh badge count in navigation, user information and pages
118
+ */
119
+ export const refreshData = function () {
120
+ return moduleWrapper.current.functions.refreshData(...arguments);
121
+ };
122
+ /**
123
+ * Refresh accesstoken, should only be used when user object changes, not when token is invalid
124
+ */
125
+ export const refreshAccessToken = function () {
126
+ return moduleWrapper.current.functions.refreshAccessToken(...arguments);
127
+ };
128
+ /**
129
+ * This removes a listener to determine your location.
130
+ * @category Event listener
131
+ */
132
+ export const removeGeoLocationListener = function () {
133
+ return moduleWrapper.current.functions.removeGeoLocationListener(...arguments);
134
+ };
135
+ /**
136
+ * Removes scroll listener.
137
+ * @category Event listener
138
+ */
139
+ export const removeScrollListener = function () {
140
+ return moduleWrapper.current.functions.removeScrollListener(...arguments);
141
+ };
142
+ /**
143
+ * Removes visibility change listener.
144
+ * @category Event listener
145
+ */
146
+ export const removeVisibilityChangeListener = function () {
147
+ return moduleWrapper.current.functions.removeVisibilityChangeListener(...arguments);
148
+ };
149
+ /**
150
+ * Removes window metrics listener.
151
+ * @category Event listener
152
+ */
153
+ export const removeWindowMetricsListener = function () {
154
+ return moduleWrapper.current.functions.removeWindowMetricsListener(...arguments);
155
+ };
156
+ /**
157
+ * Select other page on chayns site.
158
+ */
159
+ export const selectPage = function () {
160
+ return moduleWrapper.current.functions.selectPage(...arguments);
161
+ };
162
+ /**
163
+ * Scrolls to specific position.
164
+ */
165
+ export const scrollToY = function () {
166
+ return moduleWrapper.current.functions.scrollToY(...arguments);
167
+ };
168
+ /**
169
+ * Sends intercom message to group.
170
+ */
171
+ export const sendMessageToGroup = function () {
172
+ return moduleWrapper.current.functions.sendMessageToGroup(...arguments);
173
+ };
174
+ /**
175
+ * Sends intercom message to page.
176
+ */
177
+ export const sendMessageToPage = function () {
178
+ return moduleWrapper.current.functions.sendMessageToPage(...arguments);
179
+ };
180
+ /**
181
+ * Sends intercom message to an user.
182
+ */
183
+ export const sendMessageToUser = function () {
184
+ return moduleWrapper.current.functions.sendMessageToUser(...arguments);
185
+ };
186
+ /**
187
+ * Switches admin mode, also toggles admin switch in top frame.
188
+ */
189
+ export const setAdminMode = function () {
190
+ return moduleWrapper.current.functions.setAdminMode(...arguments);
191
+ };
192
+ /**
193
+ * Sets the display timeout, only works in chayns App.
194
+ */
195
+ export const setDisplayTimeout = function () {
196
+ return moduleWrapper.current.functions.setDisplayTimeout(...arguments);
197
+ };
198
+ /**
199
+ * Enables or disables a button which floats over the page.
200
+ */
201
+ export const setFloatingButton = function () {
202
+ return moduleWrapper.current.functions.setFloatingButton(...arguments);
203
+ };
204
+ /**
205
+ * Sets the height of the page.
206
+ */
207
+ export const setHeight = function () {
208
+ return moduleWrapper.current.functions.setHeight(...arguments);
209
+ };
210
+ /**
211
+ * Enables or disables the ability to refresh a page
212
+ */
213
+ export const setRefreshScrollEnabled = function () {
214
+ return moduleWrapper.current.functions.setRefreshScrollEnabled(...arguments);
215
+ };
216
+ /**
217
+ * Scans a qr-code and returns the result
218
+ */
219
+ export const setScanQrCode = function () {
220
+ return moduleWrapper.current.functions.setScanQrCode(...arguments);
221
+ };
222
+ /**
223
+ * Temporarily change design settings in top frame
224
+ */
225
+ export const setTempDesignSettings = function () {
226
+ return moduleWrapper.current.functions.setTempDesignSettings(...arguments);
227
+ };
228
+ /**
229
+ * Shows or hide a waitcursor
230
+ */
231
+ export const setWaitCursor = function () {
232
+ return moduleWrapper.current.functions.setWaitCursor(...arguments);
233
+ };
234
+ /**
235
+ * Retrieves the value that is assigned to the key from a storage outside the frame
236
+ */
237
+ export const storageGetItem = function () {
238
+ return moduleWrapper.current.functions.storageGetItem(...arguments);
239
+ };
240
+ /**
241
+ * Removes the value that is assigned to the key from a storage outside the frame
242
+ */
243
+ export const storageRemoveItem = function () {
244
+ return moduleWrapper.current.functions.storageRemoveItem(...arguments);
245
+ };
246
+ /**
247
+ * Sets the value that is assigned to the key from a storage outside the frame
248
+ */
249
+ export const storageSetItem = function () {
250
+ return moduleWrapper.current.functions.storageSetItem(...arguments);
251
+ };
252
+ /**
253
+ * This method lets a smartphone vibrate for the given time.
254
+ */
255
+ export const vibrate = function () {
256
+ return moduleWrapper.current.functions.vibrate(...arguments);
257
+ };
258
+ /**
259
+ * Displays an overlay
260
+ */
261
+ export const setOverlay = function () {
262
+ return moduleWrapper.current.functions.setOverlay(...arguments);
263
+ };
264
+ /**
265
+ * Returns user information, only when user is logged in
266
+ * @category User functions
267
+ */
268
+ export const getUser = () => moduleWrapper.current.values.user;
269
+ export const getSite = () => moduleWrapper.current.values.site;
270
+ export const getDevice = () => moduleWrapper.current.values.device;
271
+ export const getLanguage = () => moduleWrapper.current.values.language;
272
+ export const getParameters = () => moduleWrapper.current.values.parameters;
273
+ export const getPages = () => moduleWrapper.current.values.pages;
274
+ export const getEnvironment = () => moduleWrapper.current.values.environment;
275
+ export const user = new Proxy({}, {
276
+ get: (target, prop) => {
277
+ var _moduleWrapper$curren;
278
+ console.warn('Deprecated user import');
279
+ return (_moduleWrapper$curren = moduleWrapper.current.values.user) === null || _moduleWrapper$curren === void 0 ? void 0 : _moduleWrapper$curren[prop];
280
+ }
281
+ });
282
+ export const site = new Proxy({}, {
283
+ get: (target, prop) => {
284
+ var _moduleWrapper$curren2;
285
+ console.warn('Deprecated site import');
286
+ return (_moduleWrapper$curren2 = moduleWrapper.current.values.site) === null || _moduleWrapper$curren2 === void 0 ? void 0 : _moduleWrapper$curren2[prop];
287
+ }
288
+ });
289
+ export const device = new Proxy({}, {
290
+ get: (target, prop) => {
291
+ var _moduleWrapper$curren3;
292
+ console.warn('Deprecated device import');
293
+ return (_moduleWrapper$curren3 = moduleWrapper.current.values.device) === null || _moduleWrapper$curren3 === void 0 ? void 0 : _moduleWrapper$curren3[prop];
294
+ }
295
+ });
296
+ export const language = new Proxy({}, {
297
+ get: (target, prop) => {
298
+ var _moduleWrapper$curren4;
299
+ console.warn('Deprecated language import');
300
+ return (_moduleWrapper$curren4 = moduleWrapper.current.values.language) === null || _moduleWrapper$curren4 === void 0 ? void 0 : _moduleWrapper$curren4[prop];
301
+ }
302
+ });
303
+ export const parameters = new Proxy({}, {
304
+ get: (target, prop) => {
305
+ var _moduleWrapper$curren5;
306
+ console.warn('Deprecated parameters import');
307
+ return (_moduleWrapper$curren5 = moduleWrapper.current.values.parameters) === null || _moduleWrapper$curren5 === void 0 ? void 0 : _moduleWrapper$curren5[prop];
308
+ }
309
+ });
310
+ export const pages = new Proxy({}, {
311
+ get: (target, prop) => {
312
+ var _moduleWrapper$curren6;
313
+ console.warn('Deprecated pages import');
314
+ return (_moduleWrapper$curren6 = moduleWrapper.current.values.pages) === null || _moduleWrapper$curren6 === void 0 ? void 0 : _moduleWrapper$curren6[prop];
315
+ }
316
+ });
317
+ export const environment = new Proxy({}, {
318
+ get: (target, prop) => {
319
+ var _moduleWrapper$curren7;
320
+ console.warn('Deprecated environment import');
321
+ return (_moduleWrapper$curren7 = moduleWrapper.current.values.environment) === null || _moduleWrapper$curren7 === void 0 ? void 0 : _moduleWrapper$curren7[prop];
322
+ }
323
+ });
@@ -0,0 +1,111 @@
1
+ const INTERCOM_URL = 'https://sub54.tobit.com/rest/api';
2
+ /**
3
+ * @category Intercom functions
4
+ */
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
39
+ */
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
71
+ */
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
101
+ */
102
+ function sendMessage(endpoint, token, body) {
103
+ return fetch(`${INTERCOM_URL}${endpoint}`, {
104
+ method: 'POST',
105
+ headers: {
106
+ authorization: `bearer ${token}`,
107
+ 'Content-Type': 'application/json'
108
+ },
109
+ body: JSON.stringify(body)
110
+ });
111
+ }
@@ -0,0 +1,30 @@
1
+ import { addApiListener, dispatchApiEvent, removeApiListener } from '../helper/apiListenerHelper';
2
+ const key = 'visibilityChangeListener';
3
+ const handleVisibilityChange = () => {
4
+ dispatchApiEvent(key, {
5
+ isVisible: !document.hidden
6
+ });
7
+ };
8
+
9
+ /**
10
+ * @category Event listener
11
+ */
12
+ export const addVisibilityChangeListener = callback => {
13
+ const {
14
+ id,
15
+ shouldInitialize
16
+ } = addApiListener(key, callback);
17
+ if (shouldInitialize) {
18
+ document.addEventListener('visibilitychange', handleVisibilityChange);
19
+ }
20
+ return id;
21
+ };
22
+ /**
23
+ * @category Event listener
24
+ */
25
+ export const removeVisibilityChangeListener = id => {
26
+ const shouldRemove = removeApiListener(key, id);
27
+ if (shouldRemove) {
28
+ document.removeEventListener('addVisibilityChangeListener', handleVisibilityChange);
29
+ }
30
+ };
@@ -0,0 +1,8 @@
1
+ export { default as ChaynsProvider } from './components/ChaynsModuleProvider';
2
+ export { default as ChaynsHost } from './host/ChaynsHost';
3
+ export { default as getDeviceInfo, getScreenSize } from './util/deviceHelper';
4
+ export * from './components/ChaynsModuleProvider';
5
+ export * from './components/withCompatMode';
6
+ import * as _dialog from './calls/dialogs/index';
7
+ export { _dialog as dialog };
8
+ export * from './types/IChaynsReact';
@@ -0,0 +1,4 @@
1
+ import { createContext } from 'use-context-selector';
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);