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,241 @@
1
+ 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; }
2
+ import { Environment, Font, Gender, IconType, RuntimeEnviroment } from '../types/IChaynsReact';
3
+ import invokeAppCall from "../util/appCall";
4
+ import getDeviceInfo from "../util/deviceHelper";
5
+ import { removeVisibilityChangeListener } from "../calls/visibilityChangeListener";
6
+ import getUserInfo from "../calls/getUserInfo";
7
+ export class AppWrapper {
8
+ mapOldApiToNew(_ref) {
9
+ var _window, _window2, _AppInfo$TappSelected;
10
+ let {
11
+ retVal
12
+ } = _ref;
13
+ const {
14
+ AppInfo,
15
+ AppUser
16
+ } = retVal;
17
+ this.accessToken = AppUser.TobitAccessToken;
18
+ return {
19
+ device: getDeviceInfo(navigator.userAgent, 'image/webp'),
20
+ environment: {
21
+ buildEnvironment: Environment.Production,
22
+ runtimeEnvironment: RuntimeEnviroment.Unknown
23
+ },
24
+ language: {
25
+ site: AppInfo.Language,
26
+ translation: null,
27
+ device: AppInfo.Language,
28
+ active: AppInfo.Language
29
+ },
30
+ // ToDo: Find better way to detect
31
+ site: {
32
+ id: AppInfo.SiteID,
33
+ locationId: AppInfo.LocationID,
34
+ url: (_window = window) === null || _window === void 0 ? void 0 : _window.location.href.split('#')[0],
35
+ layoutDisposition: {
36
+ contentWide: false,
37
+ barOnTop: false,
38
+ barWide: false,
39
+ coverDetached: false,
40
+ coverHidden: false,
41
+ coverWide: false,
42
+ docked: false
43
+ },
44
+ title: AppInfo.Title,
45
+ colorMode: AppInfo.colorMode,
46
+ color: AppInfo.color,
47
+ domain: AppInfo.domain,
48
+ font: {
49
+ id: Font.Roboto,
50
+ headlineFont: Font.Roboto,
51
+ dynamicFontSize: false
52
+ },
53
+ dynamicFontSize: false,
54
+ locationPersonId: AppInfo.LocationPersonId,
55
+ urlHash: (_window2 = window) === null || _window2 === void 0 ? void 0 : _window2.location.hash.replace('#', '')
56
+ },
57
+ parameters: [...new URLSearchParams(location.search)],
58
+ user: {
59
+ firstName: AppUser.FirstName,
60
+ lastName: AppUser.LastName,
61
+ gender: Gender.Unknown,
62
+ userId: AppUser.TobitUserID,
63
+ personId: AppUser.PersonID,
64
+ uacGroups: []
65
+ },
66
+ customData: null,
67
+ isAdminModeActive: AppUser.AdminMode,
68
+ currentPage: {
69
+ id: (_AppInfo$TappSelected = AppInfo.TappSelected) === null || _AppInfo$TappSelected === void 0 ? void 0 : _AppInfo$TappSelected.TappID,
70
+ siteId: AppInfo.SiteID
71
+ },
72
+ pages: AppInfo.Tapps.map(x => ({
73
+ id: x.TappID,
74
+ icon: '',
75
+ iconType: IconType.Font,
76
+ customUrl: '',
77
+ isExclusive: x.isExclusiveView,
78
+ isHiddenFromMenu: x.isHiddenFromMenu,
79
+ minAge: null,
80
+ name: x.ShowName,
81
+ sortId: x.SortUID
82
+ }))
83
+ };
84
+ }
85
+ constructor() {
86
+ _defineProperty(this, "values", null);
87
+ _defineProperty(this, "accessToken", "");
88
+ _defineProperty(this, "counter", 0);
89
+ _defineProperty(this, "functions", {
90
+ getAccessToken: async accessToken => {
91
+ return {
92
+ accessToken: this.accessToken
93
+ };
94
+ },
95
+ // addGeoLocationListener: async (value , callback) => {
96
+ // return invokeAppCall({
97
+ // 'action': 14,
98
+ // 'value': {
99
+ // 'permanent': false,
100
+ // callback: callback
101
+ // }
102
+ // });
103
+ // },
104
+ // addScrollListener: async (value, callback) => {
105
+ //
106
+ // },
107
+ // addVisibilityChangeListener: async (callback) => addVisibilityChangeListener(callback),
108
+ // addWindowMetricsListener: async (callback) => {
109
+ // const { id, shouldInitialize } = addApiListener('windowMetricsListener', callback);
110
+ //
111
+ // if (shouldInitialize) {
112
+ // window.addEventListener('resize', this.resizeListener = () => {
113
+ // void (async() => {
114
+ // dispatchApiEvent('windowMetricsListener', {
115
+ //
116
+ // });
117
+ // })();
118
+ // })
119
+ // }
120
+ // return id;
121
+ // },
122
+ customCallbackFunction: async (type, data) => {},
123
+ // getAvailableSharingServices: async () => {
124
+ // },
125
+ // getGeoLocation: async (value) => {
126
+ // },
127
+ getUserInfo: async query => {
128
+ return getUserInfo(this, query);
129
+ },
130
+ // getScrollPosition: async () => {
131
+ // },
132
+ // getWindowMetrics: async () => {
133
+ // },
134
+ invokeCall: async (value, callback) => {},
135
+ invokeDialogCall: async (value, callback) => {
136
+ const callbackName = `chaynsApiV5Callback_${this.counter++}`;
137
+ window[callbackName] = _ref2 => {
138
+ let {
139
+ retVal
140
+ } = _ref2;
141
+ callback === null || callback === void 0 ? void 0 : callback(retVal);
142
+ delete window[callbackName];
143
+ };
144
+ const callObj = {
145
+ ...value,
146
+ value: {
147
+ ...value.value,
148
+ callback: callbackName
149
+ }
150
+ };
151
+ invokeAppCall(callObj);
152
+ },
153
+ // login: async(value, callback, closeCallback) => {
154
+ // },
155
+ logout: async () => {},
156
+ navigateBack: async () => {},
157
+ openImage: async value => {},
158
+ openUrl: async value => {},
159
+ openVideo: async value => {},
160
+ refreshAccessToken: async () => {},
161
+ refreshData: async value => {},
162
+ removeGeoLocationListener: async id => {},
163
+ removeScrollListener: async id => {},
164
+ removeVisibilityChangeListener(number) {
165
+ removeVisibilityChangeListener(number);
166
+ return Promise.resolve();
167
+ },
168
+ removeWindowMetricsListener: async id => {},
169
+ selectPage: async options => {},
170
+ scrollToY: async (position, duration) => {},
171
+ // sendMessageToGroup: async (groupId, message) => {
172
+ // },
173
+ // sendMessageToPage: async (message) => {
174
+ // },
175
+ // sendMessageToUser: async (userId, message) => {
176
+ // },
177
+ setAdminMode: async enabled => {},
178
+ // setDisplayTimeout: async (value) => {
179
+ // },
180
+ setFloatingButton: async (value, callback) => {},
181
+ setHeight: async value => {},
182
+ setOverlay: async (value, callback) => {},
183
+ setRefreshScrollEnabled: async isEnabled => {
184
+ invokeAppCall({
185
+ action: 0,
186
+ value: {
187
+ enabled: isEnabled
188
+ }
189
+ });
190
+ return {
191
+ isEnabled
192
+ };
193
+ },
194
+ // setScanQrCode: async (value) => {
195
+ // },
196
+ setTempDesignSettings: async value => {},
197
+ setWaitCursor: async value => {},
198
+ storageGetItem: async (key, accessMode) => {},
199
+ storageRemoveItem: async (key, accessMode) => {},
200
+ storageSetItem: async (key, value, accessMode, tappIds) => {},
201
+ vibrate: async value => {}
202
+ });
203
+ }
204
+ appCall(call) {
205
+ // generate uuid just in case multiple AppWrapper in one window
206
+ call.value.callback = `window.chaynsApiV5Callback_` + this.counter++;
207
+ invokeAppCall(call);
208
+ }
209
+
210
+ // @ts-ignore
211
+
212
+ async init() {
213
+ await new Promise(resolve => {
214
+ // @ts-ignore
215
+ window.globalDataCallback = data => {
216
+ this.values = this.mapOldApiToNew(data);
217
+ resolve(data);
218
+ };
219
+ invokeAppCall({
220
+ action: 18,
221
+ value: {
222
+ callback: 'window.globalDataCallback'
223
+ }
224
+ });
225
+ });
226
+ return undefined;
227
+ }
228
+ getSSRData() {
229
+ return null;
230
+ }
231
+ addDataListener(cb) {
232
+ const listener = ev => ev.detail && cb(ev.detail);
233
+ document.addEventListener('chayns_api_data', listener);
234
+ return () => {
235
+ document.removeEventListener('chayns_api_data', listener);
236
+ };
237
+ }
238
+ getInitialData() {
239
+ return this.values;
240
+ }
241
+ }
@@ -0,0 +1,279 @@
1
+ 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; }
2
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
3
+ import * as comlink from 'comlink';
4
+ import { addVisibilityChangeListener, removeVisibilityChangeListener } from '../calls/visibilityChangeListener';
5
+ import { addApiListener, dispatchApiEvent, removeApiListener } from '../helper/apiListenerHelper';
6
+ import getUserInfo from '../calls/getUserInfo';
7
+ import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
8
+ import { setTappHeight } from '../util/heightHelper';
9
+ export class FrameWrapper {
10
+ constructor() {
11
+ _defineProperty(this, "resolve", null);
12
+ _defineProperty(this, "exposedFunctions", null);
13
+ _defineProperty(this, "resizeListener", null);
14
+ _defineProperty(this, "ready", new Promise(res => {
15
+ this.resolve = res;
16
+ }));
17
+ _defineProperty(this, "values", null);
18
+ _defineProperty(this, "functions", {
19
+ addGeoLocationListener: async (value, callback) => {
20
+ if (!this.initialized) await this.ready;
21
+ return this.exposedFunctions.addGeoLocationListener(value, callback && comlink.proxy(result => callback(result)));
22
+ },
23
+ addScrollListener: async (value, callback) => {
24
+ if (!this.initialized) await this.ready;
25
+ return this.exposedFunctions.addScrollListener(value, callback && comlink.proxy(result => callback(result)));
26
+ },
27
+ addVisibilityChangeListener: async callback => addVisibilityChangeListener(callback),
28
+ addWindowMetricsListener: async callback => {
29
+ if (!this.initialized) await this.ready;
30
+ const {
31
+ id,
32
+ shouldInitialize
33
+ } = addApiListener('windowMetricsListener', callback);
34
+ if (shouldInitialize) {
35
+ void this.exposedFunctions.addWindowMetricsListener(comlink.proxy(result => {
36
+ dispatchApiEvent('windowMetricsListener', result);
37
+ }));
38
+ window.addEventListener('resize', this.resizeListener = () => {
39
+ void (async () => {
40
+ const metrics = await this.exposedFunctions.getWindowMetrics();
41
+ dispatchApiEvent('windowMetricsListener', metrics);
42
+ })();
43
+ });
44
+ }
45
+ return id;
46
+ },
47
+ customCallbackFunction: async (type, data) => {
48
+ if (!this.initialized) await this.ready;
49
+ return this.exposedFunctions.customCallbackFunction(type, data);
50
+ },
51
+ getAvailableSharingServices: async () => {
52
+ if (!this.initialized) await this.ready;
53
+ return this.exposedFunctions.getAvailableSharingServices();
54
+ },
55
+ getAccessToken: async accessToken => {
56
+ if (!this.initialized) await this.ready;
57
+ return this.exposedFunctions.getAccessToken(accessToken);
58
+ },
59
+ getGeoLocation: async value => {
60
+ if (!this.initialized) await this.ready;
61
+ return this.exposedFunctions.getGeoLocation(value);
62
+ },
63
+ getUserInfo: async query => {
64
+ if (!this.initialized) await this.ready;
65
+ return getUserInfo(this, query);
66
+ },
67
+ getScrollPosition: async () => {
68
+ if (!this.initialized) await this.ready;
69
+ return this.exposedFunctions.getScrollPosition();
70
+ },
71
+ getWindowMetrics: async () => {
72
+ if (!this.initialized) await this.ready;
73
+ return this.exposedFunctions.getWindowMetrics();
74
+ },
75
+ invokeCall: async (value, callback) => {
76
+ if (!this.initialized) await this.ready;
77
+ return this.exposedFunctions.invokeCall(value, callback && comlink.proxy(result => callback(result)));
78
+ },
79
+ invokeDialogCall: async (value, callback) => {
80
+ if (!this.initialized) await this.ready;
81
+ return this.exposedFunctions.invokeDialogCall(value, callback && comlink.proxy(result => callback(result)));
82
+ },
83
+ login: async (value, callback, closeCallback) => {
84
+ if (!this.initialized) await this.ready;
85
+ return this.exposedFunctions.login(value, callback && comlink.proxy(result => callback(result)), closeCallback && comlink.proxy(() => closeCallback()));
86
+ },
87
+ logout: async () => {
88
+ if (!this.initialized) await this.ready;
89
+ return this.exposedFunctions.logout();
90
+ },
91
+ navigateBack: async () => {
92
+ if (!this.initialized) await this.ready;
93
+ return this.exposedFunctions.navigateBack();
94
+ },
95
+ openImage: async value => {
96
+ if (!this.initialized) await this.ready;
97
+ return this.exposedFunctions.openImage(value);
98
+ },
99
+ openUrl: async value => {
100
+ if (!this.initialized) await this.ready;
101
+ return this.exposedFunctions.openUrl(value);
102
+ },
103
+ openVideo: async value => {
104
+ if (!this.initialized) await this.ready;
105
+ return this.exposedFunctions.openVideo(value);
106
+ },
107
+ refreshAccessToken: async () => {
108
+ if (!this.initialized) await this.ready;
109
+ return this.exposedFunctions.refreshAccessToken();
110
+ },
111
+ refreshData: async value => {
112
+ if (!this.initialized) await this.ready;
113
+ return this.exposedFunctions.refreshData(value);
114
+ },
115
+ removeGeoLocationListener: async id => {
116
+ if (!this.initialized) await this.ready;
117
+ return this.exposedFunctions.removeGeoLocationListener(id);
118
+ },
119
+ removeScrollListener: async id => {
120
+ if (!this.initialized) await this.ready;
121
+ return this.exposedFunctions.removeScrollListener(id);
122
+ },
123
+ removeVisibilityChangeListener(number) {
124
+ removeVisibilityChangeListener(number);
125
+ return Promise.resolve();
126
+ },
127
+ removeWindowMetricsListener: async id => {
128
+ if (!this.initialized) await this.ready;
129
+ const shouldRemove = removeApiListener('windowMetricsListener', id);
130
+ if (shouldRemove) {
131
+ void this.exposedFunctions.removeWindowMetricsListener(id);
132
+ if (this.resizeListener) window.removeEventListener('resize', this.resizeListener);
133
+ this.resizeListener = null;
134
+ }
135
+ },
136
+ selectPage: async options => {
137
+ if (!this.initialized) await this.ready;
138
+ await this.exposedFunctions.selectPage(options);
139
+ },
140
+ scrollToY: async (position, duration) => {
141
+ if (!this.initialized) await this.ready;
142
+ await this.exposedFunctions.scrollToY(position, duration);
143
+ },
144
+ sendMessageToGroup: async (groupId, message) => {
145
+ if (!this.initialized) await this.ready;
146
+ return sendMessageToGroup(this, message, groupId);
147
+ },
148
+ sendMessageToPage: async message => {
149
+ if (!this.initialized) await this.ready;
150
+ return sendMessageToPage(this, message);
151
+ },
152
+ sendMessageToUser: async (userId, message) => {
153
+ if (!this.initialized) await this.ready;
154
+ return sendMessageToUser(this, message, userId);
155
+ },
156
+ setAdminMode: async enabled => {
157
+ if (!this.initialized) await this.ready;
158
+ return this.exposedFunctions.setAdminMode(enabled);
159
+ },
160
+ setDisplayTimeout: async value => {
161
+ if (!this.initialized) await this.ready;
162
+ return this.exposedFunctions.setDisplayTimeout(value);
163
+ },
164
+ setFloatingButton: async (value, callback) => {
165
+ var _value$items;
166
+ if (!this.initialized) await this.ready;
167
+ value.items = (_value$items = value.items) !== null && _value$items !== void 0 ? _value$items : [];
168
+ const itemClickFunctions = value.items.map(x => x.onClick);
169
+ value.items = value.items.map(x => ({
170
+ ...x,
171
+ onClick: undefined
172
+ }));
173
+ const cb = callback && comlink.proxy(data => {
174
+ if (data !== null && data !== void 0 && data.item && itemClickFunctions[data.index]) {
175
+ itemClickFunctions[data.index]();
176
+ } else {
177
+ callback();
178
+ }
179
+ });
180
+ // @ts-ignore
181
+ return this.exposedFunctions.setFloatingButton(value, cb);
182
+ },
183
+ setHeight: async value => {
184
+ if (!this.initialized) await this.ready;
185
+ return this.exposedFunctions.setHeight(value);
186
+ },
187
+ setOverlay: async (value, callback) => {
188
+ if (!this.initialized) await this.ready;
189
+ return this.exposedFunctions.setOverlay(value, callback && comlink.proxy(() => callback()));
190
+ },
191
+ setRefreshScrollEnabled: async enabled => {
192
+ if (!this.initialized) await this.ready;
193
+ return this.exposedFunctions.setRefreshScrollEnabled(enabled);
194
+ },
195
+ setScanQrCode: async value => {
196
+ if (!this.initialized) await this.ready;
197
+ return this.exposedFunctions.setScanQrCode(value !== null && value !== void 0 ? value : {
198
+ cancel: false
199
+ });
200
+ },
201
+ setTempDesignSettings: async value => {
202
+ if (!this.initialized) await this.ready;
203
+ return this.exposedFunctions.setTempDesignSettings(value);
204
+ },
205
+ setWaitCursor: async value => {
206
+ if (!this.initialized) await this.ready;
207
+ return this.exposedFunctions.setWaitCursor(value);
208
+ },
209
+ storageGetItem: async (key, accessMode) => {
210
+ if (!this.initialized) await this.ready;
211
+ return this.exposedFunctions.storageGetItem(key, accessMode);
212
+ },
213
+ storageRemoveItem: async (key, accessMode) => {
214
+ if (!this.initialized) await this.ready;
215
+ return this.exposedFunctions.storageRemoveItem(key, accessMode);
216
+ },
217
+ storageSetItem: async (key, value, accessMode, tappIds) => {
218
+ if (!this.initialized) await this.ready;
219
+ return this.exposedFunctions.storageSetItem(key, value, accessMode, tappIds);
220
+ },
221
+ vibrate: async value => {
222
+ if (!this.initialized) await this.ready;
223
+ return this.exposedFunctions.vibrate(value);
224
+ }
225
+ });
226
+ _defineProperty(this, "initialized", false);
227
+ const initialDataTag = document.querySelector('#__CHAYNS_DATA__');
228
+ if (initialDataTag) {
229
+ this.values = JSON.parse(initialDataTag.innerHTML);
230
+ }
231
+ }
232
+ async init() {
233
+ if (this.initialized) return;
234
+ const exposed = comlink.wrap(comlink.windowEndpoint(window.parent))[window.name];
235
+ const dataListener = () => exposed.addDataListener(comlink.proxy(_ref => {
236
+ let {
237
+ type,
238
+ value
239
+ } = _ref;
240
+ if (this.initialized) {
241
+ this.values[type] = value;
242
+ }
243
+ this.values[type] = value;
244
+ document.dispatchEvent(new CustomEvent('chayns_api_data', {
245
+ detail: {
246
+ type,
247
+ value
248
+ }
249
+ }));
250
+ }));
251
+ let hostReadyCallback = null;
252
+ await Promise.race([dataListener(), new Promise(resolve => {
253
+ window.addEventListener('message', hostReadyCallback = ev => {
254
+ if (ev.data === 'chayns-api-host-ready') {
255
+ void dataListener().then(resolve);
256
+ }
257
+ });
258
+ })]);
259
+ if (hostReadyCallback) window.removeEventListener('message', hostReadyCallback);
260
+ this.values = await exposed.getInitialData();
261
+ this.exposedFunctions = exposed.functions;
262
+ this.initialized = true;
263
+ this.resolve(null);
264
+ setTappHeight(this.functions.setHeight);
265
+ }
266
+ addDataListener(cb) {
267
+ const listener = ev => ev.detail && cb(ev.detail);
268
+ document.addEventListener('chayns_api_data', listener);
269
+ return () => {
270
+ document.removeEventListener('chayns_api_data', listener);
271
+ };
272
+ }
273
+ getSSRData() {
274
+ return null;
275
+ }
276
+ getInitialData() {
277
+ return this.values;
278
+ }
279
+ }
@@ -0,0 +1,56 @@
1
+ import { addVisibilityChangeListener, removeVisibilityChangeListener } from '../calls/visibilityChangeListener';
2
+ import { addApiListener, dispatchApiEvent, removeApiListener } from '../helper/apiListenerHelper';
3
+ import getUserInfo from '../calls/getUserInfo';
4
+ import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
5
+ export class ModuleFederationWrapper {
6
+ constructor(values, functions) {
7
+ this.values = values;
8
+ this.functions = {};
9
+ this.functions.addVisibilityChangeListener = async callback => addVisibilityChangeListener(callback);
10
+ this.functions.removeVisibilityChangeListener = async id => removeVisibilityChangeListener(id);
11
+ this.functions.getUserInfo = async query => getUserInfo(this, query);
12
+ this.functions.sendMessageToGroup = async (groupId, object) => sendMessageToGroup(this, object, groupId);
13
+ this.functions.sendMessageToPage = async object => sendMessageToPage(this, object);
14
+ this.functions.sendMessageToUser = async (userId, object) => sendMessageToUser(this, object, userId);
15
+ // make all functions async to be consistent with frame wrapper
16
+ Object.entries(functions).forEach(_ref => {
17
+ let [k, fn] = _ref;
18
+ // eslint-disable-next-line
19
+ this.functions[k] = async function () {
20
+ return fn(...arguments);
21
+ };
22
+ });
23
+ this.functions.addWindowMetricsListener = async callback => {
24
+ const {
25
+ id,
26
+ shouldInitialize
27
+ } = addApiListener('windowMetrics', callback);
28
+ if (shouldInitialize) {
29
+ void functions.addWindowMetricsListener(value => dispatchApiEvent('windowMetrics', value));
30
+ }
31
+ return id;
32
+ };
33
+ this.functions.removeWindowMetricsListener = async id => {
34
+ const shouldRemove = removeApiListener('windowMetrics', id);
35
+ if (shouldRemove) {
36
+ void functions.removeWindowMetricsListener(id);
37
+ }
38
+ };
39
+ }
40
+ async init() {
41
+ return undefined;
42
+ }
43
+ addDataListener(cb) {
44
+ const listener = ev => ev.detail && cb(ev.detail);
45
+ document.addEventListener('chayns_api_data', listener);
46
+ return () => {
47
+ document.removeEventListener('chayns_api_data', listener);
48
+ };
49
+ }
50
+ getSSRData() {
51
+ return null;
52
+ }
53
+ getInitialData() {
54
+ return this.values;
55
+ }
56
+ }
@@ -0,0 +1,23 @@
1
+ export class SsrWrapper {
2
+ constructor(values, functions) {
3
+ this.initialData = values;
4
+ this.values = values;
5
+ this.functions = functions;
6
+ }
7
+ async init() {
8
+ return undefined;
9
+ }
10
+ addDataListener(cb) {
11
+ const listener = ev => ev.detail && cb(ev.detail);
12
+ document.addEventListener('chayns_api_data', listener);
13
+ return () => {
14
+ document.removeEventListener('chayns_api_data', listener);
15
+ };
16
+ }
17
+ getSSRData() {
18
+ return this.initialData;
19
+ }
20
+ getInitialData() {
21
+ return this.values;
22
+ }
23
+ }
@@ -0,0 +1 @@
1
+ export declare function alert(title?: string, message?: string): Promise<any> | "unsupported";
@@ -0,0 +1,24 @@
1
+ export declare const buttonText: {
2
+ YES: string;
3
+ NO: string;
4
+ OK: string;
5
+ CANCEL: string;
6
+ };
7
+ export declare const buttonType: {
8
+ CANCEL: number;
9
+ NEGATIVE: number;
10
+ POSITIVE: number;
11
+ };
12
+ export declare const dialogAction: {
13
+ ALERT_CONFIRM: number;
14
+ INPUT: number;
15
+ SELECT: number;
16
+ DATE: number;
17
+ ADVANCED_DATE: number;
18
+ DROP_UP_ALERT: number;
19
+ MEDIA_SELECT: number;
20
+ FILE_SELECT: number;
21
+ SIGNATURE: number;
22
+ IFRAME: number;
23
+ };
24
+ export declare function chaynsDialog(config: any): Promise<any> | "unsupported";
@@ -0,0 +1 @@
1
+ export declare function close(): Promise<any>;
@@ -0,0 +1,3 @@
1
+ export declare function sendData(data: any, isApiEvent: any): Promise<any>;
2
+ export declare function addDialogDataListener(callback: any, getApiEvents?: boolean): boolean;
3
+ export declare function removeDialogDataListener(callback: any, getApiEvents?: boolean): boolean;
@@ -0,0 +1,13 @@
1
+ import { DialogButton } from "../../types/dialog";
2
+ type Confirm = {
3
+ headline?: string;
4
+ text?: string;
5
+ buttons?: DialogButton[] | {
6
+ buttons?: DialogButton[];
7
+ links?: DialogButton[];
8
+ };
9
+ links?: unknown;
10
+ select?: unknown;
11
+ };
12
+ export declare function confirm(title?: string, message?: string, config?: Confirm): Promise<any> | "unsupported";
13
+ export {};