chayns-api 1.0.7 → 1.0.9

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.
@@ -27,7 +27,8 @@ const ChaynsHost = ({
27
27
  device,
28
28
  parameters,
29
29
  customData,
30
- environment
30
+ environment,
31
+ preventStagingReplacement
31
32
  }) => {
32
33
  switch (type) {
33
34
  case 'client-iframe':
@@ -45,7 +46,8 @@ const ChaynsHost = ({
45
46
  language: language,
46
47
  parameters: parameters,
47
48
  environment: environment,
48
- customData: customData
49
+ customData: customData,
50
+ preventStagingReplacement: preventStagingReplacement
49
51
  });
50
52
  case 'client-module':
51
53
  return /*#__PURE__*/_react.default.createElement(_ModuleHost.default, {
@@ -61,7 +63,8 @@ const ChaynsHost = ({
61
63
  language: language,
62
64
  parameters: parameters,
63
65
  customData: customData,
64
- environment: environment
66
+ environment: environment,
67
+ preventStagingReplacement: preventStagingReplacement
65
68
  });
66
69
  case 'server-iframe':
67
70
  return /*#__PURE__*/_react.default.createElement(_HostIframe.default, {
@@ -79,7 +82,8 @@ const ChaynsHost = ({
79
82
  language: language,
80
83
  parameters: parameters,
81
84
  environment: environment,
82
- customData: customData
85
+ customData: customData,
86
+ preventStagingReplacement: preventStagingReplacement
83
87
  });
84
88
  case 'server-module':
85
89
  return /*#__PURE__*/_react.default.createElement(_ModuleHost.default, {
@@ -94,7 +98,8 @@ const ChaynsHost = ({
94
98
  language: language,
95
99
  parameters: parameters,
96
100
  customData: customData,
97
- environment: environment
101
+ environment: environment,
102
+ preventStagingReplacement: preventStagingReplacement
98
103
  }, children);
99
104
  default:
100
105
  return null;
@@ -8,6 +8,7 @@ var _react = _interopRequireWildcard(require("react"));
8
8
  var comlink = _interopRequireWildcard(require("comlink"));
9
9
  var _postIframeForm = _interopRequireDefault(require("../../util/postIframeForm"));
10
10
  var _useUpdateData = _interopRequireDefault(require("./utils/useUpdateData"));
11
+ var _url = require("../../util/url");
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -28,7 +29,8 @@ const HostIframe = ({
28
29
  language,
29
30
  parameters,
30
31
  environment,
31
- customData
32
+ customData,
33
+ preventStagingReplacement
32
34
  }) => {
33
35
  const eventTarget = (0, _react.useRef)();
34
36
  const ref = (0, _react.useRef)();
@@ -66,7 +68,7 @@ const HostIframe = ({
66
68
  if (postForm) {
67
69
  var _await$functions$getA;
68
70
  const accessToken = (_await$functions$getA = await functions.getAccessToken()) !== null && _await$functions$getA !== void 0 ? _await$functions$getA : {};
69
- void (0, _postIframeForm.default)(src, JSON.stringify({
71
+ void (0, _postIframeForm.default)((0, _url.replaceStagingUrl)(preventStagingReplacement, src, environment.runtimeEnvironment), JSON.stringify({
70
72
  ...initialData,
71
73
  pages: undefined,
72
74
  ...accessToken
@@ -126,7 +128,7 @@ const HostIframe = ({
126
128
  },
127
129
  title: " "
128
130
  }, iFrameProps, {
129
- src: postForm ? undefined : src
131
+ src: postForm ? undefined : (0, _url.replaceStagingUrl)(preventStagingReplacement, src, environment.runtimeEnvironment)
130
132
  }));
131
133
  };
132
134
  var _default = HostIframe;
@@ -7,6 +7,7 @@ exports.default = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _useDynamicScript = _interopRequireDefault(require("./utils/useDynamicScript"));
9
9
  var _loadComponent = _interopRequireDefault(require("./utils/loadComponent"));
10
+ var _url = require("../../util/url");
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
13
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -49,7 +50,8 @@ const ModuleHost = ({
49
50
  language,
50
51
  parameters,
51
52
  customData,
52
- environment
53
+ environment,
54
+ preventStagingReplacement
53
55
  }) => {
54
56
  // region initialData
55
57
  const initialData = {
@@ -71,7 +73,11 @@ const ModuleHost = ({
71
73
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
72
74
  className: "module-css"
73
75
  }), /*#__PURE__*/_react.default.createElement(System, {
74
- system: system,
76
+ system: {
77
+ scope: system.scope,
78
+ url: (0, _url.replaceStagingUrl)(preventStagingReplacement, system.url, environment.runtimeEnvironment),
79
+ module: system.module
80
+ },
75
81
  data: initialData,
76
82
  functions: functions,
77
83
  fallback: children,
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.replaceStagingUrl = void 0;
7
+ var _IChaynsReact = require("../types/IChaynsReact");
8
+ const replaceStagingUrl = (prevent, url, environment) => {
9
+ if (prevent) return url;
10
+ let replacedUrl = url;
11
+ if (environment === _IChaynsReact.Environment.Qa || environment === _IChaynsReact.Environment.Development) {
12
+ replacedUrl = replacedUrl.replace('tapp.chayns-static.space', 'tapp-dev.chayns-static.space');
13
+ }
14
+ if (environment === _IChaynsReact.Environment.Staging) {
15
+ replacedUrl = replacedUrl.replace('tapp.chayns-static.space', 'tapp-staging.chayns-static.space');
16
+ }
17
+ return replacedUrl;
18
+ };
19
+ exports.replaceStagingUrl = replaceStagingUrl;
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.AppWrapper = void 0;
7
+ var _lodash = _interopRequireDefault(require("lodash.throttle"));
7
8
  var _IChaynsReact = require("../types/IChaynsReact");
8
9
  var _appCall = _interopRequireDefault(require("../util/appCall"));
9
10
  var _deviceHelper = _interopRequireWildcard(require("../util/deviceHelper"));
10
- var _visibilityChangeListener = require("../calls/visibilityChangeListener");
11
11
  var _getUserInfo = _interopRequireDefault(require("../calls/getUserInfo"));
12
12
  var _sendMessage = require("../calls/sendMessage");
13
13
  var _apiListenerHelper = require("../helper/apiListenerHelper");
@@ -19,7 +19,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
19
 
20
20
  class AppWrapper {
21
21
  values = null;
22
- accessToken = "";
22
+ accessToken = '';
23
23
  mapOldApiToNew(retVal) {
24
24
  var _window, _window2, _AppInfo$TappSelected;
25
25
  const {
@@ -122,7 +122,7 @@ class AppWrapper {
122
122
  }
123
123
  resolve((_v$retVal2 = v === null || v === void 0 ? void 0 : v.retVal) !== null && _v$retVal2 !== void 0 ? _v$retVal2 : v);
124
124
  };
125
- value.callback = "window." + callbackName;
125
+ value.callback = 'window.' + callbackName;
126
126
  (0, _appCall.default)({
127
127
  action,
128
128
  value
@@ -133,50 +133,83 @@ class AppWrapper {
133
133
  getAccessToken: async () => ({
134
134
  accessToken: this.accessToken
135
135
  }),
136
- // addGeoLocationListener: async (value , callback) => {
137
- // return invokeAppCall({
138
- // 'action': 14,
139
- // 'value': {
140
- // 'permanent': false,
141
- // callback: callback
142
- // }
143
- // });
144
- // },
145
- // addScrollListener: async (value, callback) => {
146
- //
147
- // },
136
+ addGeoLocationListener: async (value, callback) => {
137
+ const {
138
+ id,
139
+ shouldInitialize
140
+ } = (0, _apiListenerHelper.addApiListener)('geoLocationListener', callback);
141
+ if (shouldInitialize) {
142
+ this.appCall(14, {
143
+ permanent: true
144
+ }, {
145
+ callback: v => {
146
+ var _v$accuracy, _v$code;
147
+ (0, _apiListenerHelper.dispatchApiEvent)('geoLocationListener', {
148
+ latitude: v.latitude,
149
+ longitude: v.longitude,
150
+ accuracy: (_v$accuracy = v.accuracy) !== null && _v$accuracy !== void 0 ? _v$accuracy : null,
151
+ speed: v.speed,
152
+ code: (_v$code = v.code) !== null && _v$code !== void 0 ? _v$code : null
153
+ });
154
+ }
155
+ });
156
+ }
157
+ return id;
158
+ },
159
+ addScrollListener: async (value, callback) => {
160
+ let throttledCallback = callback;
161
+ if (value.throttle) {
162
+ throttledCallback = (0, _lodash.default)(callback, value.throttle);
163
+ }
164
+ const {
165
+ id,
166
+ shouldInitialize
167
+ } = (0, _apiListenerHelper.addApiListener)('scrollListener', throttledCallback);
168
+ if (shouldInitialize) {
169
+ window.addEventListener('scroll', this.scrollListener = () => {
170
+ void (async () => {
171
+ (0, _apiListenerHelper.dispatchApiEvent)('scrollListener', {
172
+ scrollX: window.scrollX,
173
+ scrollY: window.scrollY
174
+ });
175
+ })();
176
+ });
177
+ }
178
+ return id;
179
+ },
148
180
  addVisibilityChangeListener: async callback => {
181
+ const {
182
+ id,
183
+ shouldInitialize
184
+ } = (0, _apiListenerHelper.addApiListener)('visibilityChangeListener', callback);
185
+ if (shouldInitialize) {
186
+ this.appCall(60, {}, {
187
+ callback: v => {
188
+ (0, _apiListenerHelper.dispatchApiEvent)('visibilityChangeListener', {
189
+ isVisible: v.tappEvent === _IChaynsReact.TappEvent.OnShow,
190
+ tappEvent: v.tappEvent
191
+ });
192
+ }
193
+ });
194
+ }
195
+ return id;
196
+ },
197
+ addWindowMetricsListener: async callback => {
149
198
  const {
150
199
  id,
151
200
  shouldInitialize
152
201
  } = (0, _apiListenerHelper.addApiListener)('windowMetricsListener', callback);
153
- this.appCall(60, {}, {
154
- callback: v => {
155
- console.log("v", v);
156
- (0, _apiListenerHelper.dispatchApiEvent)("windowMetricsListener", {
157
- isVisible: v.tappEvent === _IChaynsReact.TappEvent.OnShow,
158
- tappEvent: v.tappEvent
159
- });
160
- }
161
- });
202
+ if (shouldInitialize) {
203
+ window.addEventListener('resize', this.resizeListener = () => {
204
+ void (async () => {
205
+ (0, _apiListenerHelper.dispatchApiEvent)('windowMetricsListener', await this.functions.getWindowMetrics());
206
+ })();
207
+ });
208
+ }
162
209
  return id;
163
210
  },
164
- // addWindowMetricsListener: async (callback) => {
165
- // const { id, shouldInitialize } = addApiListener('windowMetricsListener', callback);
166
- //
167
- // if (shouldInitialize) {
168
- // window.addEventListener('resize', this.resizeListener = () => {
169
- // void (async() => {
170
- // dispatchApiEvent('windowMetricsListener', {
171
- //
172
- // });
173
- // })();
174
- // })
175
- // }
176
- // return id;
177
- // },
178
211
  customCallbackFunction: async () => {
179
- this.notImplemented("customCallbackFunction");
212
+ this.notImplemented('customCallbackFunction');
180
213
  },
181
214
  getAvailableSharingServices: async () => {
182
215
  const res = await this.appCall(79);
@@ -264,9 +297,9 @@ class AppWrapper {
264
297
  awaitResult: false
265
298
  });
266
299
  },
267
- // openUrl: async (value) => {
268
- //
269
- // },
300
+ openUrl: async value => {
301
+ window.open(value.url);
302
+ },
270
303
  openVideo: async value => {
271
304
  this.appCall(15, {
272
305
  url: value.url
@@ -280,19 +313,41 @@ class AppWrapper {
280
313
  });
281
314
  },
282
315
  refreshData: async value => {
283
- this.notImplemented("refreshData");
284
- },
285
- // removeGeoLocationListener: async (id) => {
286
- // },
287
- // removeScrollListener: async (id) => {
288
- // },
289
- removeVisibilityChangeListener(number) {
290
- (0, _visibilityChangeListener.removeVisibilityChangeListener)(number);
291
- return Promise.resolve();
292
- },
293
- // removeWindowMetricsListener: async (id) => {
294
- //
295
- // },
316
+ this.notImplemented('refreshData');
317
+ },
318
+ removeGeoLocationListener: async id => {
319
+ const {
320
+ shouldRemove
321
+ } = (0, _apiListenerHelper.removeApiListener)('geoLocationListener', id);
322
+ if (shouldRemove) {
323
+ // App does not support removal of request geo location call with permanent true which makes this a no-op
324
+ }
325
+ },
326
+ removeScrollListener: async id => {
327
+ const {
328
+ shouldRemove
329
+ } = (0, _apiListenerHelper.removeApiListener)('scrollListener', id);
330
+ if (shouldRemove && this.scrollListener) {
331
+ window.removeEventListener('scroll', this.scrollListener);
332
+ this.scrollListener = null;
333
+ }
334
+ },
335
+ removeVisibilityChangeListener: async id => {
336
+ const {
337
+ shouldRemove
338
+ } = (0, _apiListenerHelper.removeApiListener)('visibilityChangeListener', id);
339
+ if (shouldRemove) {
340
+ // App does not support removal of onActivate callback which makes this a no-op
341
+ }
342
+ },
343
+ removeWindowMetricsListener: async id => {
344
+ const shouldRemove = (0, _apiListenerHelper.removeApiListener)('windowMetricsListener', id);
345
+ if (shouldRemove) {
346
+ void this.exposedFunctions.removeWindowMetricsListener(id);
347
+ if (this.resizeListener) window.removeEventListener('resize', this.resizeListener);
348
+ this.resizeListener = null;
349
+ }
350
+ },
296
351
  selectPage: async options => {
297
352
  void this.appCall(2, {
298
353
  id: options.id,
@@ -323,7 +378,7 @@ class AppWrapper {
323
378
  return (0, _sendMessage.sendMessageToUser)(this, message, userId);
324
379
  },
325
380
  setAdminMode: async () => {
326
- this.notImplemented("setAdminMode");
381
+ this.notImplemented('setAdminMode');
327
382
  },
328
383
  setDisplayTimeout: async enabled => {
329
384
  this.appCall(94, {
@@ -348,10 +403,10 @@ class AppWrapper {
348
403
  }, callback));
349
404
  },
350
405
  setHeight: async () => {
351
- this.notImplemented("setOverlay");
406
+ this.notImplemented('setOverlay');
352
407
  },
353
408
  setOverlay: async () => {
354
- this.notImplemented("setOverlay");
409
+ this.notImplemented('setOverlay');
355
410
  },
356
411
  setRefreshScrollEnabled: async isEnabled => {
357
412
  this.appCall(0, {
@@ -367,7 +422,7 @@ class AppWrapper {
367
422
  return await this.appCall(34, value);
368
423
  },
369
424
  setTempDesignSettings: async () => {
370
- this.notImplemented("setTempDesignSettings");
425
+ this.notImplemented('setTempDesignSettings');
371
426
  },
372
427
  setWaitCursor: async value => {
373
428
  void this.appCall(1, {
@@ -21,7 +21,8 @@ const ChaynsHost = _ref => {
21
21
  device,
22
22
  parameters,
23
23
  customData,
24
- environment
24
+ environment,
25
+ preventStagingReplacement
25
26
  } = _ref;
26
27
  switch (type) {
27
28
  case 'client-iframe':
@@ -39,7 +40,8 @@ const ChaynsHost = _ref => {
39
40
  language: language,
40
41
  parameters: parameters,
41
42
  environment: environment,
42
- customData: customData
43
+ customData: customData,
44
+ preventStagingReplacement: preventStagingReplacement
43
45
  });
44
46
  case 'client-module':
45
47
  return /*#__PURE__*/React.createElement(ModuleHost, {
@@ -55,7 +57,8 @@ const ChaynsHost = _ref => {
55
57
  language: language,
56
58
  parameters: parameters,
57
59
  customData: customData,
58
- environment: environment
60
+ environment: environment,
61
+ preventStagingReplacement: preventStagingReplacement
59
62
  });
60
63
  case 'server-iframe':
61
64
  return /*#__PURE__*/React.createElement(HostIframe, {
@@ -73,7 +76,8 @@ const ChaynsHost = _ref => {
73
76
  language: language,
74
77
  parameters: parameters,
75
78
  environment: environment,
76
- customData: customData
79
+ customData: customData,
80
+ preventStagingReplacement: preventStagingReplacement
77
81
  });
78
82
  case 'server-module':
79
83
  return /*#__PURE__*/React.createElement(ModuleHost, {
@@ -88,7 +92,8 @@ const ChaynsHost = _ref => {
88
92
  language: language,
89
93
  parameters: parameters,
90
94
  customData: customData,
91
- environment: environment
95
+ environment: environment,
96
+ preventStagingReplacement: preventStagingReplacement
92
97
  }, children);
93
98
  default:
94
99
  return null;
@@ -3,6 +3,7 @@ import React, { useEffect, useRef } from 'react';
3
3
  import * as comlink from 'comlink';
4
4
  import postIframeForm from '../../util/postIframeForm';
5
5
  import useUpdateData from './utils/useUpdateData';
6
+ import { replaceStagingUrl } from "../../util/url";
6
7
  const HostIframe = _ref => {
7
8
  let {
8
9
  iFrameProps,
@@ -20,7 +21,8 @@ const HostIframe = _ref => {
20
21
  language,
21
22
  parameters,
22
23
  environment,
23
- customData
24
+ customData,
25
+ preventStagingReplacement
24
26
  } = _ref;
25
27
  const eventTarget = useRef();
26
28
  const ref = useRef();
@@ -58,7 +60,7 @@ const HostIframe = _ref => {
58
60
  if (postForm) {
59
61
  var _await$functions$getA;
60
62
  const accessToken = (_await$functions$getA = await functions.getAccessToken()) !== null && _await$functions$getA !== void 0 ? _await$functions$getA : {};
61
- void postIframeForm(src, JSON.stringify({
63
+ void postIframeForm(replaceStagingUrl(preventStagingReplacement, src, environment.runtimeEnvironment), JSON.stringify({
62
64
  ...initialData,
63
65
  pages: undefined,
64
66
  ...accessToken
@@ -118,7 +120,7 @@ const HostIframe = _ref => {
118
120
  },
119
121
  title: " "
120
122
  }, iFrameProps, {
121
- src: postForm ? undefined : src
123
+ src: postForm ? undefined : replaceStagingUrl(preventStagingReplacement, src, environment.runtimeEnvironment)
122
124
  }));
123
125
  };
124
126
  export default HostIframe;
@@ -1,6 +1,7 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import useDynamicScript from './utils/useDynamicScript';
3
3
  import loadComponent from './utils/loadComponent';
4
+ import { replaceStagingUrl } from "../../util/url";
4
5
  const System = _ref => {
5
6
  let {
6
7
  system,
@@ -42,7 +43,8 @@ const ModuleHost = _ref2 => {
42
43
  language,
43
44
  parameters,
44
45
  customData,
45
- environment
46
+ environment,
47
+ preventStagingReplacement
46
48
  } = _ref2;
47
49
  // region initialData
48
50
  const initialData = {
@@ -64,7 +66,11 @@ const ModuleHost = _ref2 => {
64
66
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
65
67
  className: "module-css"
66
68
  }), /*#__PURE__*/React.createElement(System, {
67
- system: system,
69
+ system: {
70
+ scope: system.scope,
71
+ url: replaceStagingUrl(preventStagingReplacement, system.url, environment.runtimeEnvironment),
72
+ module: system.module
73
+ },
68
74
  data: initialData,
69
75
  functions: functions,
70
76
  fallback: children,
@@ -0,0 +1,12 @@
1
+ import { Environment } from "../types/IChaynsReact";
2
+ export const replaceStagingUrl = (prevent, url, environment) => {
3
+ if (prevent) return url;
4
+ let replacedUrl = url;
5
+ if (environment === Environment.Qa || environment === Environment.Development) {
6
+ replacedUrl = replacedUrl.replace('tapp.chayns-static.space', 'tapp-dev.chayns-static.space');
7
+ }
8
+ if (environment === Environment.Staging) {
9
+ replacedUrl = replacedUrl.replace('tapp.chayns-static.space', 'tapp-staging.chayns-static.space');
10
+ }
11
+ return replacedUrl;
12
+ };
@@ -2,13 +2,13 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
2
2
  /* eslint-disable */
3
3
  // @ts-nocheck
4
4
 
5
+ import throttle from 'lodash.throttle';
5
6
  import { Environment, Font, Gender, IconType, RuntimeEnviroment, TappEvent } from '../types/IChaynsReact';
6
- import invokeAppCall from "../util/appCall";
7
- import getDeviceInfo, { getScreenSize } from "../util/deviceHelper";
8
- import { removeVisibilityChangeListener } from "../calls/visibilityChangeListener";
9
- import getUserInfo from "../calls/getUserInfo";
10
- import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from "../calls/sendMessage";
11
- import { addApiListener, dispatchApiEvent } from "../helper/apiListenerHelper";
7
+ import invokeAppCall from '../util/appCall';
8
+ import getDeviceInfo, { getScreenSize } from '../util/deviceHelper';
9
+ import getUserInfo from '../calls/getUserInfo';
10
+ import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
11
+ import { addApiListener, dispatchApiEvent, removeApiListener } from '../helper/apiListenerHelper';
12
12
  export class AppWrapper {
13
13
  mapOldApiToNew(retVal) {
14
14
  var _window, _window2, _AppInfo$TappSelected;
@@ -86,56 +86,89 @@ export class AppWrapper {
86
86
  }
87
87
  constructor() {
88
88
  _defineProperty(this, "values", null);
89
- _defineProperty(this, "accessToken", "");
89
+ _defineProperty(this, "accessToken", '');
90
90
  _defineProperty(this, "counter", 0);
91
91
  _defineProperty(this, "functions", {
92
92
  getAccessToken: async () => ({
93
93
  accessToken: this.accessToken
94
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
- // },
95
+ addGeoLocationListener: async (value, callback) => {
96
+ const {
97
+ id,
98
+ shouldInitialize
99
+ } = addApiListener('geoLocationListener', callback);
100
+ if (shouldInitialize) {
101
+ this.appCall(14, {
102
+ permanent: true
103
+ }, {
104
+ callback: v => {
105
+ var _v$accuracy, _v$code;
106
+ dispatchApiEvent('geoLocationListener', {
107
+ latitude: v.latitude,
108
+ longitude: v.longitude,
109
+ accuracy: (_v$accuracy = v.accuracy) !== null && _v$accuracy !== void 0 ? _v$accuracy : null,
110
+ speed: v.speed,
111
+ code: (_v$code = v.code) !== null && _v$code !== void 0 ? _v$code : null
112
+ });
113
+ }
114
+ });
115
+ }
116
+ return id;
117
+ },
118
+ addScrollListener: async (value, callback) => {
119
+ let throttledCallback = callback;
120
+ if (value.throttle) {
121
+ throttledCallback = throttle(callback, value.throttle);
122
+ }
123
+ const {
124
+ id,
125
+ shouldInitialize
126
+ } = addApiListener('scrollListener', throttledCallback);
127
+ if (shouldInitialize) {
128
+ window.addEventListener('scroll', this.scrollListener = () => {
129
+ void (async () => {
130
+ dispatchApiEvent('scrollListener', {
131
+ scrollX: window.scrollX,
132
+ scrollY: window.scrollY
133
+ });
134
+ })();
135
+ });
136
+ }
137
+ return id;
138
+ },
107
139
  addVisibilityChangeListener: async callback => {
140
+ const {
141
+ id,
142
+ shouldInitialize
143
+ } = addApiListener('visibilityChangeListener', callback);
144
+ if (shouldInitialize) {
145
+ this.appCall(60, {}, {
146
+ callback: v => {
147
+ dispatchApiEvent('visibilityChangeListener', {
148
+ isVisible: v.tappEvent === TappEvent.OnShow,
149
+ tappEvent: v.tappEvent
150
+ });
151
+ }
152
+ });
153
+ }
154
+ return id;
155
+ },
156
+ addWindowMetricsListener: async callback => {
108
157
  const {
109
158
  id,
110
159
  shouldInitialize
111
160
  } = addApiListener('windowMetricsListener', callback);
112
- this.appCall(60, {}, {
113
- callback: v => {
114
- console.log("v", v);
115
- dispatchApiEvent("windowMetricsListener", {
116
- isVisible: v.tappEvent === TappEvent.OnShow,
117
- tappEvent: v.tappEvent
118
- });
119
- }
120
- });
161
+ if (shouldInitialize) {
162
+ window.addEventListener('resize', this.resizeListener = () => {
163
+ void (async () => {
164
+ dispatchApiEvent('windowMetricsListener', await this.functions.getWindowMetrics());
165
+ })();
166
+ });
167
+ }
121
168
  return id;
122
169
  },
123
- // addWindowMetricsListener: async (callback) => {
124
- // const { id, shouldInitialize } = addApiListener('windowMetricsListener', callback);
125
- //
126
- // if (shouldInitialize) {
127
- // window.addEventListener('resize', this.resizeListener = () => {
128
- // void (async() => {
129
- // dispatchApiEvent('windowMetricsListener', {
130
- //
131
- // });
132
- // })();
133
- // })
134
- // }
135
- // return id;
136
- // },
137
170
  customCallbackFunction: async () => {
138
- this.notImplemented("customCallbackFunction");
171
+ this.notImplemented('customCallbackFunction');
139
172
  },
140
173
  getAvailableSharingServices: async () => {
141
174
  const res = await this.appCall(79);
@@ -224,9 +257,9 @@ export class AppWrapper {
224
257
  awaitResult: false
225
258
  });
226
259
  },
227
- // openUrl: async (value) => {
228
- //
229
- // },
260
+ openUrl: async value => {
261
+ window.open(value.url);
262
+ },
230
263
  openVideo: async value => {
231
264
  this.appCall(15, {
232
265
  url: value.url
@@ -240,19 +273,41 @@ export class AppWrapper {
240
273
  });
241
274
  },
242
275
  refreshData: async value => {
243
- this.notImplemented("refreshData");
244
- },
245
- // removeGeoLocationListener: async (id) => {
246
- // },
247
- // removeScrollListener: async (id) => {
248
- // },
249
- removeVisibilityChangeListener(number) {
250
- removeVisibilityChangeListener(number);
251
- return Promise.resolve();
252
- },
253
- // removeWindowMetricsListener: async (id) => {
254
- //
255
- // },
276
+ this.notImplemented('refreshData');
277
+ },
278
+ removeGeoLocationListener: async id => {
279
+ const {
280
+ shouldRemove
281
+ } = removeApiListener('geoLocationListener', id);
282
+ if (shouldRemove) {
283
+ // App does not support removal of request geo location call with permanent true which makes this a no-op
284
+ }
285
+ },
286
+ removeScrollListener: async id => {
287
+ const {
288
+ shouldRemove
289
+ } = removeApiListener('scrollListener', id);
290
+ if (shouldRemove && this.scrollListener) {
291
+ window.removeEventListener('scroll', this.scrollListener);
292
+ this.scrollListener = null;
293
+ }
294
+ },
295
+ removeVisibilityChangeListener: async id => {
296
+ const {
297
+ shouldRemove
298
+ } = removeApiListener('visibilityChangeListener', id);
299
+ if (shouldRemove) {
300
+ // App does not support removal of onActivate callback which makes this a no-op
301
+ }
302
+ },
303
+ removeWindowMetricsListener: async id => {
304
+ const shouldRemove = removeApiListener('windowMetricsListener', id);
305
+ if (shouldRemove) {
306
+ void this.exposedFunctions.removeWindowMetricsListener(id);
307
+ if (this.resizeListener) window.removeEventListener('resize', this.resizeListener);
308
+ this.resizeListener = null;
309
+ }
310
+ },
256
311
  selectPage: async options => {
257
312
  void this.appCall(2, {
258
313
  id: options.id,
@@ -283,7 +338,7 @@ export class AppWrapper {
283
338
  return sendMessageToUser(this, message, userId);
284
339
  },
285
340
  setAdminMode: async () => {
286
- this.notImplemented("setAdminMode");
341
+ this.notImplemented('setAdminMode');
287
342
  },
288
343
  setDisplayTimeout: async enabled => {
289
344
  this.appCall(94, {
@@ -308,10 +363,10 @@ export class AppWrapper {
308
363
  }, callback));
309
364
  },
310
365
  setHeight: async () => {
311
- this.notImplemented("setOverlay");
366
+ this.notImplemented('setOverlay');
312
367
  },
313
368
  setOverlay: async () => {
314
- this.notImplemented("setOverlay");
369
+ this.notImplemented('setOverlay');
315
370
  },
316
371
  setRefreshScrollEnabled: async isEnabled => {
317
372
  this.appCall(0, {
@@ -327,7 +382,7 @@ export class AppWrapper {
327
382
  return await this.appCall(34, value);
328
383
  },
329
384
  setTempDesignSettings: async () => {
330
- this.notImplemented("setTempDesignSettings");
385
+ this.notImplemented('setTempDesignSettings');
331
386
  },
332
387
  setWaitCursor: async value => {
333
388
  void this.appCall(1, {
@@ -401,7 +456,7 @@ export class AppWrapper {
401
456
  }
402
457
  resolve((_v$retVal2 = v === null || v === void 0 ? void 0 : v.retVal) !== null && _v$retVal2 !== void 0 ? _v$retVal2 : v);
403
458
  };
404
- value.callback = "window." + callbackName;
459
+ value.callback = 'window.' + callbackName;
405
460
  invokeAppCall({
406
461
  action,
407
462
  value
@@ -23,6 +23,7 @@ type ChaynsHostType = {
23
23
  parameters: ChaynsReactValues["parameters"];
24
24
  customData: any;
25
25
  environment: ChaynsReactValues["environment"];
26
+ preventStagingReplacement?: boolean;
26
27
  };
27
28
  declare const ChaynsHost: FC<ChaynsHostType>;
28
29
  export default ChaynsHost;
@@ -19,6 +19,7 @@ type HostIframeProps = {
19
19
  parameters: ChaynsReactValues["parameters"];
20
20
  environment: ChaynsReactValues["environment"];
21
21
  customData: ChaynsReactValues["customData"];
22
+ preventStagingReplacement?: boolean;
22
23
  };
23
24
  declare const HostIframe: FC<HostIframeProps>;
24
25
  export default HostIframe;
@@ -18,6 +18,7 @@ type ModulePropTypes = {
18
18
  parameters: ChaynsReactValues["parameters"];
19
19
  customData: any;
20
20
  environment: ChaynsReactValues["environment"];
21
+ preventStagingReplacement?: boolean;
21
22
  };
22
23
  declare const ModuleHost: FC<ModulePropTypes>;
23
24
  export default ModuleHost;
@@ -0,0 +1 @@
1
+ export declare const replaceStagingUrl: (prevent: any, url: any, environment: any) => any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",