chayns-api 3.5.0 → 3.6.0-beta.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.
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DefaultTrustedDomains = void 0;
7
+ const DefaultTrustedDomains = exports.DefaultTrustedDomains = ['.tobit.com', '.chayns.net', '.tobit.cloud', '.chayns-static.space', '.az-chayns.space', '.tobit.ag', 'localhost', '127.0.0.1', '::1'];
@@ -135,6 +135,12 @@ Object.defineProperty(exports, "useFunctions", {
135
135
  return _useFunctions.useFunctions;
136
136
  }
137
137
  });
138
+ Object.defineProperty(exports, "useFunctionsWithOverrides", {
139
+ enumerable: true,
140
+ get: function () {
141
+ return _useFunctionsWithOverrides.useFunctionsWithOverrides;
142
+ }
143
+ });
138
144
  Object.defineProperty(exports, "useGeoLocation", {
139
145
  enumerable: true,
140
146
  get: function () {
@@ -270,6 +276,7 @@ var _useEnvironment = require("./useEnvironment");
270
276
  var _useLanguage = require("./useLanguage");
271
277
  var _useValues = require("./useValues");
272
278
  var _useFunctions = require("./useFunctions");
279
+ var _useFunctionsWithOverrides = require("./useFunctionsWithOverrides");
273
280
  var _useCurrentPage = require("./useCurrentPage");
274
281
  var _useCustomData = require("./useCustomData");
275
282
  var _useDialogState = require("./useDialogState");
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useFunctionsWithOverrides = void 0;
7
+ var _reactCompilerRuntime = require("react-compiler-runtime");
8
+ var _react = require("react");
9
+ var _useFunctions = require("./useFunctions");
10
+ const useFunctionsWithOverrides = overrideFactory => {
11
+ const $ = (0, _reactCompilerRuntime.c)(12);
12
+ const base = (0, _useFunctions.useFunctions)();
13
+ let t0;
14
+ if ($[0] !== base || $[1] !== overrideFactory) {
15
+ t0 = overrideFactory(base);
16
+ $[0] = base;
17
+ $[1] = overrideFactory;
18
+ $[2] = t0;
19
+ } else {
20
+ t0 = $[2];
21
+ }
22
+ const overrides = t0;
23
+ let t1;
24
+ if ($[3] !== base || $[4] !== overrides) {
25
+ t1 = {
26
+ base,
27
+ overrides
28
+ };
29
+ $[3] = base;
30
+ $[4] = overrides;
31
+ $[5] = t1;
32
+ } else {
33
+ t1 = $[5];
34
+ }
35
+ const stateRef = (0, _react.useRef)(t1);
36
+ let t2;
37
+ let t3;
38
+ if ($[6] !== base || $[7] !== overrides) {
39
+ t2 = () => {
40
+ stateRef.current = {
41
+ base,
42
+ overrides
43
+ };
44
+ };
45
+ t3 = [base, overrides];
46
+ $[6] = base;
47
+ $[7] = overrides;
48
+ $[8] = t2;
49
+ $[9] = t3;
50
+ } else {
51
+ t2 = $[8];
52
+ t3 = $[9];
53
+ }
54
+ (0, _react.useEffect)(t2, t3);
55
+ let functions;
56
+ if ($[10] !== base) {
57
+ functions = {};
58
+ for (const key of Object.keys(base)) {
59
+ functions[key] = (...t4) => {
60
+ var _stateRef$current$ove;
61
+ const args = t4;
62
+ const functionKey = key;
63
+ const implementation = (_stateRef$current$ove = stateRef.current.overrides[functionKey]) !== null && _stateRef$current$ove !== void 0 ? _stateRef$current$ove : stateRef.current.base[functionKey];
64
+ return implementation(...args);
65
+ };
66
+ }
67
+ $[10] = base;
68
+ $[11] = functions;
69
+ } else {
70
+ functions = $[11];
71
+ }
72
+ return functions;
73
+ };
74
+ exports.useFunctionsWithOverrides = useFunctionsWithOverrides;
@@ -8,10 +8,12 @@ var _lodash = _interopRequireDefault(require("lodash.throttle"));
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
9
  const setTappHeight = setHeight => {
10
10
  document.documentElement.style.overflow = 'hidden';
11
- let oldHeight = Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
11
+ let oldHeight = document.body.offsetHeight;
12
12
  void setHeight(oldHeight);
13
13
  const handleResize = () => {
14
- const offsetHeight = Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
14
+ const {
15
+ offsetHeight
16
+ } = document.body;
15
17
  if (oldHeight !== offsetHeight) {
16
18
  void setHeight(offsetHeight);
17
19
  oldHeight = offsetHeight;
@@ -8,6 +8,7 @@ var _lodash = _interopRequireDefault(require("lodash.throttle"));
8
8
  var _getUserInfo = _interopRequireDefault(require("../calls/getUserInfo"));
9
9
  var _sendMessage = require("../calls/sendMessage");
10
10
  var _constants = require("../constants");
11
+ var _trustedDomains = require("../constants/trustedDomains");
11
12
  var _languages = require("../constants/languages");
12
13
  var _DialogHandler = _interopRequireDefault(require("../handler/DialogHandler"));
13
14
  var _apiListener = require("../utils/apiListener");
@@ -23,6 +24,7 @@ class AppWrapper {
23
24
  history = null;
24
25
  accessToken = '';
25
26
  latestAppleSafeArea = null;
27
+ trustedDomains = _trustedDomains.DefaultTrustedDomains;
26
28
  listeners = [];
27
29
  customFunctions = {};
28
30
  nextDialogEventId = 0;
@@ -41,6 +43,24 @@ class AppWrapper {
41
43
  }
42
44
  return undefined;
43
45
  }
46
+ async loadTrustedDomains() {
47
+ try {
48
+ var _AbortSignal$timeout2, _AbortSignal2;
49
+ const res = await fetch('https://service-rpc.chayns.net/ConfigurationSettings/TrustedDomains', {
50
+ signal: (_AbortSignal$timeout2 = (_AbortSignal2 = AbortSignal).timeout) === null || _AbortSignal$timeout2 === void 0 ? void 0 : _AbortSignal$timeout2.call(_AbortSignal2, 5000)
51
+ });
52
+ if (res.status === 200) {
53
+ const {
54
+ trustedDomains
55
+ } = await res.json();
56
+ return trustedDomains;
57
+ }
58
+ console.error(`[chayns-api] failed to load trusted domains with status code: ${res.status}`);
59
+ } catch (ex) {
60
+ console.error('[chayns-api] failed to load trusted domains', ex);
61
+ }
62
+ return _trustedDomains.DefaultTrustedDomains;
63
+ }
44
64
  mapOldApiToNew(retVal) {
45
65
  var _window, _window2, _AppInfo$TappSelected;
46
66
  const {
@@ -395,6 +415,14 @@ class AppWrapper {
395
415
  };
396
416
  (0, _appCall.default)(callObj);
397
417
  },
418
+ isTrustedUrl: async url => {
419
+ try {
420
+ const parsedUrl = new URL(url);
421
+ return this.trustedDomains.some(domain => parsedUrl.hostname.endsWith(domain));
422
+ } catch {
423
+ return false;
424
+ }
425
+ },
398
426
  login: async (value = {}, callback, closeCallback) => {
399
427
  const {
400
428
  result,
@@ -765,7 +793,7 @@ class AppWrapper {
765
793
  dialogs = [];
766
794
  async init() {
767
795
  this.values = this.mapOldApiToNew(await this.appCall(18));
768
- this.values.styleSettings = await this.loadStyleSettings(this.values.site.id);
796
+ [this.values.styleSettings, this.trustedDomains] = await Promise.all([this.loadStyleSettings(this.values.site.id), this.loadTrustedDomains()]);
769
797
  document.documentElement.classList.add('chayns-api--app');
770
798
  this.appCall(66, {
771
799
  enabled: true
@@ -107,6 +107,10 @@ class FrameWrapper {
107
107
  if (!this.initialized) await this.ready;
108
108
  return this.exposedFunctions.invokeDialogCall(value, callback && comlink.proxy(result => callback(result)));
109
109
  },
110
+ isTrustedUrl: async url => {
111
+ if (!this.initialized) await this.ready;
112
+ return this.exposedFunctions.isTrustedUrl(url);
113
+ },
110
114
  login: async (value, callback, closeCallback) => {
111
115
  if (!this.initialized) await this.ready;
112
116
  return this.exposedFunctions.login(value, callback && comlink.proxy(result => callback(result)), closeCallback && comlink.proxy(() => closeCallback()));
@@ -0,0 +1 @@
1
+ export const DefaultTrustedDomains = ['.tobit.com', '.chayns.net', '.tobit.cloud', '.chayns-static.space', '.az-chayns.space', '.tobit.ag', 'localhost', '127.0.0.1', '::1'];
@@ -13,6 +13,7 @@ export { useEnvironment } from './useEnvironment';
13
13
  export { useLanguage } from './useLanguage';
14
14
  export { useValues } from './useValues';
15
15
  export { useFunctions } from './useFunctions';
16
+ export { useFunctionsWithOverrides } from './useFunctionsWithOverrides';
16
17
  export { useCurrentPage } from './useCurrentPage';
17
18
  export { useCustomData } from './useCustomData';
18
19
  export { useDialogState, useDialogData } from './useDialogState';
@@ -0,0 +1,67 @@
1
+ import { c as _c } from "react-compiler-runtime";
2
+ import { useEffect, useMemo, useRef } from 'react';
3
+ import { useFunctions } from './useFunctions';
4
+ export const useFunctionsWithOverrides = overrideFactory => {
5
+ const $ = _c(12);
6
+ const base = useFunctions();
7
+ let t0;
8
+ if ($[0] !== base || $[1] !== overrideFactory) {
9
+ t0 = overrideFactory(base);
10
+ $[0] = base;
11
+ $[1] = overrideFactory;
12
+ $[2] = t0;
13
+ } else {
14
+ t0 = $[2];
15
+ }
16
+ const overrides = t0;
17
+ let t1;
18
+ if ($[3] !== base || $[4] !== overrides) {
19
+ t1 = {
20
+ base,
21
+ overrides
22
+ };
23
+ $[3] = base;
24
+ $[4] = overrides;
25
+ $[5] = t1;
26
+ } else {
27
+ t1 = $[5];
28
+ }
29
+ const stateRef = useRef(t1);
30
+ let t2;
31
+ let t3;
32
+ if ($[6] !== base || $[7] !== overrides) {
33
+ t2 = () => {
34
+ stateRef.current = {
35
+ base,
36
+ overrides
37
+ };
38
+ };
39
+ t3 = [base, overrides];
40
+ $[6] = base;
41
+ $[7] = overrides;
42
+ $[8] = t2;
43
+ $[9] = t3;
44
+ } else {
45
+ t2 = $[8];
46
+ t3 = $[9];
47
+ }
48
+ useEffect(t2, t3);
49
+ let functions;
50
+ if ($[10] !== base) {
51
+ functions = {};
52
+ for (const key of Object.keys(base)) {
53
+ functions[key] = (...t4) => {
54
+ var _stateRef$current$ove;
55
+ const args = t4;
56
+ const functionKey = key;
57
+ const implementation = (_stateRef$current$ove = stateRef.current.overrides[functionKey]) !== null && _stateRef$current$ove !== void 0 ? _stateRef$current$ove : stateRef.current.base[functionKey];
58
+ return implementation(...args);
59
+ };
60
+ }
61
+ $[10] = base;
62
+ $[11] = functions;
63
+ } else {
64
+ functions = $[11];
65
+ }
66
+ return functions;
67
+ };
@@ -1,10 +1,12 @@
1
1
  import throttle from 'lodash.throttle';
2
2
  export const setTappHeight = setHeight => {
3
3
  document.documentElement.style.overflow = 'hidden';
4
- let oldHeight = Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
4
+ let oldHeight = document.body.offsetHeight;
5
5
  void setHeight(oldHeight);
6
6
  const handleResize = () => {
7
- const offsetHeight = Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
7
+ const {
8
+ offsetHeight
9
+ } = document.body;
8
10
  if (oldHeight !== offsetHeight) {
9
11
  void setHeight(offsetHeight);
10
12
  oldHeight = offsetHeight;
@@ -5,6 +5,7 @@ import throttle from 'lodash.throttle';
5
5
  import getUserInfo from '../calls/getUserInfo';
6
6
  import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
7
7
  import { DefaultLoginDialogOptions } from '../constants';
8
+ import { DefaultTrustedDomains } from '../constants/trustedDomains';
8
9
  import { DeviceLanguage } from '../constants/languages';
9
10
  import DialogHandler from '../handler/DialogHandler';
10
11
  import { addApiListener, dispatchApiEvent, removeApiListener } from '../utils/apiListener';
@@ -29,6 +30,24 @@ export class AppWrapper {
29
30
  }
30
31
  return undefined;
31
32
  }
33
+ async loadTrustedDomains() {
34
+ try {
35
+ var _AbortSignal$timeout2, _AbortSignal2;
36
+ const res = await fetch('https://service-rpc.chayns.net/ConfigurationSettings/TrustedDomains', {
37
+ signal: (_AbortSignal$timeout2 = (_AbortSignal2 = AbortSignal).timeout) === null || _AbortSignal$timeout2 === void 0 ? void 0 : _AbortSignal$timeout2.call(_AbortSignal2, 5000)
38
+ });
39
+ if (res.status === 200) {
40
+ const {
41
+ trustedDomains
42
+ } = await res.json();
43
+ return trustedDomains;
44
+ }
45
+ console.error(`[chayns-api] failed to load trusted domains with status code: ${res.status}`);
46
+ } catch (ex) {
47
+ console.error('[chayns-api] failed to load trusted domains', ex);
48
+ }
49
+ return DefaultTrustedDomains;
50
+ }
32
51
  mapOldApiToNew(retVal) {
33
52
  var _window, _window2, _AppInfo$TappSelected;
34
53
  const {
@@ -149,6 +168,7 @@ export class AppWrapper {
149
168
  _defineProperty(this, "history", null);
150
169
  _defineProperty(this, "accessToken", '');
151
170
  _defineProperty(this, "latestAppleSafeArea", null);
171
+ _defineProperty(this, "trustedDomains", DefaultTrustedDomains);
152
172
  _defineProperty(this, "listeners", []);
153
173
  _defineProperty(this, "customFunctions", {});
154
174
  _defineProperty(this, "nextDialogEventId", 0);
@@ -358,6 +378,14 @@ export class AppWrapper {
358
378
  };
359
379
  invokeAppCall(callObj);
360
380
  },
381
+ isTrustedUrl: async url => {
382
+ try {
383
+ const parsedUrl = new URL(url);
384
+ return this.trustedDomains.some(domain => parsedUrl.hostname.endsWith(domain));
385
+ } catch {
386
+ return false;
387
+ }
388
+ },
361
389
  login: async (value = {}, callback, closeCallback) => {
362
390
  const {
363
391
  result,
@@ -771,7 +799,7 @@ export class AppWrapper {
771
799
  }
772
800
  async init() {
773
801
  this.values = this.mapOldApiToNew(await this.appCall(18));
774
- this.values.styleSettings = await this.loadStyleSettings(this.values.site.id);
802
+ [this.values.styleSettings, this.trustedDomains] = await Promise.all([this.loadStyleSettings(this.values.site.id), this.loadTrustedDomains()]);
775
803
  document.documentElement.classList.add('chayns-api--app');
776
804
  this.appCall(66, {
777
805
  enabled: true
@@ -103,6 +103,10 @@ export class FrameWrapper {
103
103
  if (!this.initialized) await this.ready;
104
104
  return this.exposedFunctions.invokeDialogCall(value, callback && comlink.proxy(result => callback(result)));
105
105
  },
106
+ isTrustedUrl: async url => {
107
+ if (!this.initialized) await this.ready;
108
+ return this.exposedFunctions.isTrustedUrl(url);
109
+ },
106
110
  login: async (value, callback, closeCallback) => {
107
111
  if (!this.initialized) await this.ready;
108
112
  return this.exposedFunctions.login(value, callback && comlink.proxy(result => callback(result)), closeCallback && comlink.proxy(() => closeCallback()));
@@ -28,6 +28,7 @@ class StaticChaynsApi {
28
28
  _defineProperty(this, "invokeCall", void 0);
29
29
  _defineProperty(this, "invokePaymentCall", void 0);
30
30
  _defineProperty(this, "invokeDialogCall", void 0);
31
+ _defineProperty(this, "isTrustedUrl", void 0);
31
32
  _defineProperty(this, "login", void 0);
32
33
  _defineProperty(this, "logout", void 0);
33
34
  _defineProperty(this, "navigateBack", void 0);
@@ -0,0 +1 @@
1
+ export declare const DefaultTrustedDomains: string[];
@@ -13,6 +13,7 @@ export { useEnvironment } from './useEnvironment';
13
13
  export { useLanguage } from './useLanguage';
14
14
  export { useValues } from './useValues';
15
15
  export { useFunctions } from './useFunctions';
16
+ export { useFunctionsWithOverrides } from './useFunctionsWithOverrides';
16
17
  export { useCurrentPage } from './useCurrentPage';
17
18
  export { useCustomData } from './useCustomData';
18
19
  export { useDialogState, useDialogData } from './useDialogState';
@@ -0,0 +1,4 @@
1
+ import { ChaynsReactFunctions } from '../types/IChaynsReact';
2
+ type FunctionsOverrideFactory = (base: ChaynsReactFunctions) => Partial<ChaynsReactFunctions>;
3
+ export declare const useFunctionsWithOverrides: (overrideFactory: FunctionsOverrideFactory) => ChaynsReactFunctions;
4
+ export {};
@@ -168,7 +168,7 @@ export interface DialogInput {
168
168
  * Not supported in app environments due to security reasons.
169
169
  * @param input
170
170
  */
171
- formatter?: (input: string) => string;
171
+ formatter?: (input: string) => Promise<string> | string;
172
172
  regex?: string;
173
173
  autoComplete?: string;
174
174
  inputMode?: HTMLAttributes<HTMLInputElement>["inputMode"];
@@ -446,6 +446,7 @@ export interface ChaynsReactFunctions {
446
446
  invokeCall: (value: InvokeCall, callback?: (result: any) => void) => Promise<any>;
447
447
  invokePaymentCall: <T>(value: InvokeCall, callback?: (result: T) => void) => Promise<T>;
448
448
  invokeDialogCall: (value: InvokeCall, callback?: (result: any) => void) => Promise<any>;
449
+ isTrustedUrl: (url: string) => Promise<boolean>;
449
450
  login: (value?: Login, callback?: (result: boolean) => void, closeCallback?: () => void) => Promise<LoginResult>;
450
451
  logout: () => Promise<void>;
451
452
  navigateBack: () => Promise<void>;
@@ -4,10 +4,12 @@ export declare class AppWrapper implements IChaynsReact {
4
4
  history: IChaynsReact['history'];
5
5
  accessToken: string;
6
6
  latestAppleSafeArea: null;
7
+ private trustedDomains;
7
8
  listeners: (() => void)[];
8
9
  customFunctions: {};
9
10
  nextDialogEventId: number;
10
11
  loadStyleSettings(siteId: string): Promise<ChaynsStyleSettings | undefined>;
12
+ loadTrustedDomains(): Promise<string[]>;
11
13
  mapOldApiToNew(retVal: any): ChaynsReactValues;
12
14
  constructor();
13
15
  chaynsApiId: string;
@@ -18,6 +18,7 @@ declare class StaticChaynsApi implements ChaynsReactFunctions {
18
18
  invokeCall: ChaynsReactFunctions['invokeCall'];
19
19
  invokePaymentCall: ChaynsReactFunctions['invokePaymentCall'];
20
20
  invokeDialogCall: ChaynsReactFunctions['invokeDialogCall'];
21
+ isTrustedUrl: ChaynsReactFunctions['isTrustedUrl'];
21
22
  login: ChaynsReactFunctions['login'];
22
23
  logout: ChaynsReactFunctions['logout'];
23
24
  navigateBack: ChaynsReactFunctions['navigateBack'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "3.5.0",
3
+ "version": "3.6.0-beta.0",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",