chayns-api 3.6.0-beta.2 → 3.6.0-beta.3

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.
@@ -5,20 +5,30 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.TrustedDomainsPlugin = void 0;
7
7
  exports.isTrustedDomainsError = isTrustedDomainsError;
8
+ var _loadTrustedDomains = require("../utils/loadTrustedDomains");
8
9
  class TrustedDomainsError extends Error {
9
10
  name = 'TrustedDomainsError';
10
11
  constructor(entry) {
11
12
  super('Remote entry ' + entry + ' is not in trusted domains');
12
13
  }
13
14
  }
14
- const TrustedDomainsPlugin = (trustedDomains = []) => {
15
+ const TrustedDomainsPlugin = trustedDomains => {
16
+ let trustedDomainsPromise;
17
+ const getTrustedDomains = () => {
18
+ if (trustedDomains) {
19
+ return trustedDomains;
20
+ }
21
+ trustedDomainsPromise !== null && trustedDomainsPromise !== void 0 ? trustedDomainsPromise : trustedDomainsPromise = (0, _loadTrustedDomains.loadTrustedDomains)();
22
+ return trustedDomainsPromise;
23
+ };
15
24
  return {
16
25
  name: 'trusted-domains',
17
- beforeRequest(args) {
26
+ async beforeRequest(args) {
27
+ const domains = await getTrustedDomains();
18
28
  args.options.remotes.forEach(remote => {
19
29
  if ('entry' in remote) {
20
30
  const parsed = new URL(remote.entry);
21
- if (!trustedDomains.some(domain => parsed.hostname.endsWith(domain))) {
31
+ if (!domains.some(domain => parsed.hostname.endsWith(domain))) {
22
32
  throw new TrustedDomainsError(remote.entry);
23
33
  }
24
34
  }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadTrustedDomains = void 0;
7
+ var _trustedDomains = require("../constants/trustedDomains");
8
+ const TRUSTED_DOMAINS_URL = 'https://service-rpc.chayns.net/ConfigurationSettings/TrustedDomains';
9
+ const loadTrustedDomains = async () => {
10
+ try {
11
+ var _AbortSignal$timeout, _AbortSignal;
12
+ const response = await fetch(TRUSTED_DOMAINS_URL, {
13
+ signal: (_AbortSignal$timeout = (_AbortSignal = AbortSignal).timeout) === null || _AbortSignal$timeout === void 0 ? void 0 : _AbortSignal$timeout.call(_AbortSignal, 5000)
14
+ });
15
+ if (response.status === 200) {
16
+ const {
17
+ trustedDomains
18
+ } = await response.json();
19
+ return trustedDomains;
20
+ }
21
+ } catch {
22
+ return _trustedDomains.DefaultTrustedDomains;
23
+ }
24
+ return _trustedDomains.DefaultTrustedDomains;
25
+ };
26
+ exports.loadTrustedDomains = loadTrustedDomains;
@@ -9,6 +9,7 @@ var _getUserInfo = _interopRequireDefault(require("../calls/getUserInfo"));
9
9
  var _sendMessage = require("../calls/sendMessage");
10
10
  var _constants = require("../constants");
11
11
  var _trustedDomains = require("../constants/trustedDomains");
12
+ var _loadTrustedDomains = require("../utils/loadTrustedDomains");
12
13
  var _languages = require("../constants/languages");
13
14
  var _DialogHandler = _interopRequireDefault(require("../handler/DialogHandler"));
14
15
  var _apiListener = require("../utils/apiListener");
@@ -43,24 +44,6 @@ class AppWrapper {
43
44
  }
44
45
  return undefined;
45
46
  }
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
- }
64
47
  mapOldApiToNew(retVal) {
65
48
  var _window, _window2, _AppInfo$TappSelected;
66
49
  const {
@@ -793,7 +776,7 @@ class AppWrapper {
793
776
  dialogs = [];
794
777
  async init() {
795
778
  this.values = this.mapOldApiToNew(await this.appCall(18));
796
- [this.values.styleSettings, this.trustedDomains] = await Promise.all([this.loadStyleSettings(this.values.site.id), this.loadTrustedDomains()]);
779
+ [this.values.styleSettings, this.trustedDomains] = await Promise.all([this.loadStyleSettings(this.values.site.id), (0, _loadTrustedDomains.loadTrustedDomains)()]);
797
780
  document.documentElement.classList.add('chayns-api--app');
798
781
  this.appCall(66, {
799
782
  enabled: true
@@ -1,20 +1,30 @@
1
1
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
2
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
3
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
+ import { loadTrustedDomains } from '../utils/loadTrustedDomains';
4
5
  class TrustedDomainsError extends Error {
5
6
  constructor(entry) {
6
7
  super('Remote entry ' + entry + ' is not in trusted domains');
7
8
  _defineProperty(this, "name", 'TrustedDomainsError');
8
9
  }
9
10
  }
10
- export const TrustedDomainsPlugin = (trustedDomains = []) => {
11
+ export const TrustedDomainsPlugin = trustedDomains => {
12
+ let trustedDomainsPromise;
13
+ const getTrustedDomains = () => {
14
+ if (trustedDomains) {
15
+ return trustedDomains;
16
+ }
17
+ trustedDomainsPromise !== null && trustedDomainsPromise !== void 0 ? trustedDomainsPromise : trustedDomainsPromise = loadTrustedDomains();
18
+ return trustedDomainsPromise;
19
+ };
11
20
  return {
12
21
  name: 'trusted-domains',
13
- beforeRequest(args) {
22
+ async beforeRequest(args) {
23
+ const domains = await getTrustedDomains();
14
24
  args.options.remotes.forEach(remote => {
15
25
  if ('entry' in remote) {
16
26
  const parsed = new URL(remote.entry);
17
- if (!trustedDomains.some(domain => parsed.hostname.endsWith(domain))) {
27
+ if (!domains.some(domain => parsed.hostname.endsWith(domain))) {
18
28
  throw new TrustedDomainsError(remote.entry);
19
29
  }
20
30
  }
@@ -0,0 +1,19 @@
1
+ import { DefaultTrustedDomains } from '../constants/trustedDomains';
2
+ const TRUSTED_DOMAINS_URL = 'https://service-rpc.chayns.net/ConfigurationSettings/TrustedDomains';
3
+ export const loadTrustedDomains = async () => {
4
+ try {
5
+ var _AbortSignal$timeout, _AbortSignal;
6
+ const response = await fetch(TRUSTED_DOMAINS_URL, {
7
+ signal: (_AbortSignal$timeout = (_AbortSignal = AbortSignal).timeout) === null || _AbortSignal$timeout === void 0 ? void 0 : _AbortSignal$timeout.call(_AbortSignal, 5000)
8
+ });
9
+ if (response.status === 200) {
10
+ const {
11
+ trustedDomains
12
+ } = await response.json();
13
+ return trustedDomains;
14
+ }
15
+ } catch {
16
+ return DefaultTrustedDomains;
17
+ }
18
+ return DefaultTrustedDomains;
19
+ };
@@ -6,6 +6,7 @@ import getUserInfo from '../calls/getUserInfo';
6
6
  import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
7
7
  import { DefaultLoginDialogOptions } from '../constants';
8
8
  import { DefaultTrustedDomains } from '../constants/trustedDomains';
9
+ import { loadTrustedDomains } from '../utils/loadTrustedDomains';
9
10
  import { DeviceLanguage } from '../constants/languages';
10
11
  import DialogHandler from '../handler/DialogHandler';
11
12
  import { addApiListener, dispatchApiEvent, removeApiListener } from '../utils/apiListener';
@@ -30,24 +31,6 @@ export class AppWrapper {
30
31
  }
31
32
  return undefined;
32
33
  }
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
- }
51
34
  mapOldApiToNew(retVal) {
52
35
  var _window, _window2, _AppInfo$TappSelected;
53
36
  const {
@@ -799,7 +782,7 @@ export class AppWrapper {
799
782
  }
800
783
  async init() {
801
784
  this.values = this.mapOldApiToNew(await this.appCall(18));
802
- [this.values.styleSettings, this.trustedDomains] = await Promise.all([this.loadStyleSettings(this.values.site.id), this.loadTrustedDomains()]);
785
+ [this.values.styleSettings, this.trustedDomains] = await Promise.all([this.loadStyleSettings(this.values.site.id), loadTrustedDomains()]);
803
786
  document.documentElement.classList.add('chayns-api--app');
804
787
  this.appCall(66, {
805
788
  enabled: true
@@ -0,0 +1 @@
1
+ export declare const loadTrustedDomains: () => Promise<string[]>;
@@ -9,7 +9,6 @@ export declare class AppWrapper implements IChaynsReact {
9
9
  customFunctions: {};
10
10
  nextDialogEventId: number;
11
11
  loadStyleSettings(siteId: string): Promise<ChaynsStyleSettings | undefined>;
12
- loadTrustedDomains(): Promise<string[]>;
13
12
  mapOldApiToNew(retVal: any): ChaynsReactValues;
14
13
  constructor();
15
14
  chaynsApiId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "3.6.0-beta.2",
3
+ "version": "3.6.0-beta.3",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",