@ada-support/embed2 1.2.2 → 1.2.5

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.
@@ -19,6 +19,7 @@ export declare class FrameChannel extends Channel {
19
19
  constructor(name: string, targetWindow: Window, targetOrigin?: string);
20
20
  private static isMessageEvent;
21
21
  postMessage<T extends EmbedEvent>(eventName: T, data?: PayloadByEvent[T], id?: string, status?: FetchEventStatusType): void;
22
+ isValidMessageEvent(event: MessageEvent | object): boolean;
22
23
  addEventListener(handler: (type: string, payload?: object, id?: string, status?: FetchEventStatusType) => void): Refhandler;
23
24
  constructObjectToSend(eventName?: string, payload?: unknown, id?: string, status?: FetchEventStatusType): string;
24
25
  }
@@ -15635,7 +15635,7 @@ const client = new error_tracker_BrowserClient({
15635
15635
  },
15636
15636
 
15637
15637
  environment: "production",
15638
- release: "1.2.2-5da862d",
15638
+ release: "1.2.5-fbe96ec",
15639
15639
  sampleRate: 0.25,
15640
15640
  autoSessionTracking: false,
15641
15641
  // Integrations don't seem to work with Sentry: https://github.com/getsentry/sentry-javascript/issues/2541
@@ -15911,11 +15911,25 @@ class FrameChannel extends Channel {
15911
15911
  this.targetWindow.postMessage(this.constructObjectToSend(eventName, data, id, status), this.targetOrigin);
15912
15912
  }
15913
15913
 
15914
+ isValidMessageEvent(event) {
15915
+ if (false) {}
15916
+
15917
+ if (this.targetOrigin === "*") {
15918
+ return true;
15919
+ }
15920
+
15921
+ if (!("origin" in event)) {
15922
+ return false;
15923
+ }
15924
+
15925
+ return event.origin === this.targetOrigin;
15926
+ }
15927
+
15914
15928
  addEventListener(handler) {
15915
15929
  const handleRef = event => {
15916
15930
  let parsedData;
15917
15931
 
15918
- if ( true && this.targetOrigin !== "*" && (!("origin" in event) || this.targetOrigin.indexOf(event.origin) < 0)) {
15932
+ if (!this.isValidMessageEvent(event)) {
15919
15933
  return;
15920
15934
  }
15921
15935
 
@@ -16235,7 +16249,7 @@ function getEmbedURL(_ref) {
16235
16249
  host = "http://".concat(window.location.hostname, ":9001");
16236
16250
  }
16237
16251
 
16238
- return "".concat(host, "/embed/").concat(frameName, "/").concat("5da862d", "/index.html");
16252
+ return "".concat(host, "/embed/").concat(frameName, "/").concat("fbe96ec", "/index.html");
16239
16253
  }
16240
16254
  /**
16241
16255
  * Generate the Chat / API URL
@@ -17791,12 +17805,15 @@ async function log(message, extra, options) {
17791
17805
  service: "embed",
17792
17806
  env: "production",
17793
17807
  embedVersion: 2,
17794
- version: "1.2.2",
17808
+ version: "1.2.5",
17795
17809
  isNpm: true,
17796
- commitHash: "5da862d"
17810
+ commitHash: "fbe96ec"
17797
17811
  }))
17798
17812
  });
17799
17813
  }
17814
+ // EXTERNAL MODULE: ./node_modules/@babel/runtime-corejs3/core-js-stable/url.js
17815
+ var url = __webpack_require__(9969);
17816
+ var url_default = /*#__PURE__*/__webpack_require__.n(url);
17800
17817
  ;// CONCATENATED MODULE: ./src/client/components/IFrame/index.tsx
17801
17818
 
17802
17819
 
@@ -17805,6 +17822,8 @@ async function log(message, extra, options) {
17805
17822
 
17806
17823
 
17807
17824
 
17825
+
17826
+
17808
17827
  class IFrame extends d {
17809
17828
  constructor() {
17810
17829
  super(...arguments);
@@ -17814,6 +17833,23 @@ class IFrame extends d {
17814
17833
  _defineProperty(this, "channel", void 0);
17815
17834
  }
17816
17835
 
17836
+ getChannel() {
17837
+ const {
17838
+ name,
17839
+ store,
17840
+ messageService
17841
+ } = this.props;
17842
+
17843
+ if (this.channel) {
17844
+ return this.channel;
17845
+ }
17846
+
17847
+ const targetOrigin = new (url_default())(this.iframeRef.current.src).origin;
17848
+ const channel = messageService.registerFrameChannel(name, this.iframeRef.current.contentWindow, targetOrigin);
17849
+ store.addChannelListener(name);
17850
+ return channel;
17851
+ }
17852
+
17817
17853
  componentDidMount() {
17818
17854
  this.connectFrame();
17819
17855
  }
@@ -17824,7 +17860,7 @@ class IFrame extends d {
17824
17860
  } = this.props;
17825
17861
 
17826
17862
  if (appConnectionState === ConnectionState.Done) {
17827
- this.channel.postMessage(ALL_FRAMES_LOADED);
17863
+ this.getChannel().postMessage(ALL_FRAMES_LOADED);
17828
17864
  }
17829
17865
  }
17830
17866
 
@@ -17843,6 +17879,11 @@ class IFrame extends d {
17843
17879
  domain,
17844
17880
  cluster
17845
17881
  } = this.props;
17882
+
17883
+ if (!handle) {
17884
+ throw new AdaEmbedError("`handle` is undefined");
17885
+ }
17886
+
17846
17887
  return getEmbedURL({
17847
17888
  frameName: name,
17848
17889
  handle,
@@ -17854,13 +17895,10 @@ class IFrame extends d {
17854
17895
  async connectFrame() {
17855
17896
  const {
17856
17897
  name,
17857
- store,
17858
17898
  setState,
17859
- messageService,
17860
17899
  setConnectionState
17861
17900
  } = this.props;
17862
- this.channel = messageService.registerFrameChannel(name, this.iframeRef.current.contentWindow, this.iframeRef.current.src);
17863
- store.addChannelListener(name);
17901
+ this.channel = this.getChannel();
17864
17902
  await setConnectionState({
17865
17903
  [name]: ConnectionState.Loading
17866
17904
  });
@@ -17870,9 +17908,9 @@ class IFrame extends d {
17870
17908
  const initMessageHandler = (type, payload) => {
17871
17909
  (async () => {
17872
17910
  if (type === "".concat(name, "_INIT")) {
17873
- this.channel.removeEventListener(handlerRef);
17874
- this.channel.clearTrackedTimeout(timeout);
17875
- this.channel.isConnected = true;
17911
+ this.getChannel().removeEventListener(handlerRef);
17912
+ this.getChannel().clearTrackedTimeout(timeout);
17913
+ this.getChannel().isConnected = true;
17876
17914
  /**
17877
17915
  * Set initial state (if any).
17878
17916
  * This is mostly useful for XStorage to set state based on storage values
@@ -17890,7 +17928,7 @@ class IFrame extends d {
17890
17928
  };
17891
17929
 
17892
17930
  timeout = window.setTimeout(() => {
17893
- this.channel.removeEventListener(handlerRef);
17931
+ this.getChannel().removeEventListener(handlerRef);
17894
17932
  setConnectionState({
17895
17933
  [name]: ConnectionState.Failure
17896
17934
  });
@@ -18067,9 +18105,6 @@ function ButtonFrame_mapStateToProps(storeState) {
18067
18105
  }
18068
18106
 
18069
18107
  /* harmony default export */ var components_ButtonFrame = (connect(ButtonFrame_mapStateToProps)(ButtonFrame));
18070
- // EXTERNAL MODULE: ./node_modules/@babel/runtime-corejs3/core-js-stable/url.js
18071
- var url = __webpack_require__(9969);
18072
- var url_default = /*#__PURE__*/__webpack_require__.n(url);
18073
18108
  ;// CONCATENATED MODULE: ./src/common/constants/timeouts.ts
18074
18109
  const ANIMATION_DELAY = 50;
18075
18110
  ;// CONCATENATED MODULE: ./src/common/helpers/is-mobile.ts
@@ -18124,7 +18159,8 @@ class ChatFrame extends d {
18124
18159
  } = this.props;
18125
18160
  this.rememberInitialPageStyle();
18126
18161
  setChatHasBeenRendered();
18127
- this.channel = messageService.registerFrameChannel("chat", this.iframeRef.current.contentWindow, this.iframeRef.current.src);
18162
+ const targetOrigin = new (url_default())(this.iframeRef.current.src).origin;
18163
+ this.channel = messageService.registerFrameChannel("chat", this.iframeRef.current.contentWindow, targetOrigin);
18128
18164
  store.addChannelListener("chat");
18129
18165
  this.bindChatEventHandlers();
18130
18166
  this.handleScrollLock(); // We use this log to track number of chat impressions (times when users see chat iFrame render first time).
@@ -18198,7 +18234,7 @@ class ChatFrame extends d {
18198
18234
  const hostPageUrlParams = new (url_default())(window.location.href).searchParams;
18199
18235
  const smsToken = hostPageUrlParams.get("adaSMSToken");
18200
18236
  const queryParams = {
18201
- embedVersion: "5da862d".slice(0, 7),
18237
+ embedVersion: "fbe96ec".slice(0, 7),
18202
18238
  greeting,
18203
18239
  language,
18204
18240
  skipGreeting,
@@ -20342,7 +20378,7 @@ class Embed {
20342
20378
 
20343
20379
  }
20344
20380
 
20345
- _defineProperty(Embed, "embed2Version", "5da862d");
20381
+ _defineProperty(Embed, "embed2Version", "fbe96ec");
20346
20382
  ;// CONCATENATED MODULE: ./src/common/helpers/startup.ts
20347
20383
 
20348
20384
 
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@ada-support/embed2",
3
- "version": "1.2.2",
3
+ "version": "1.2.5",
4
4
  "description": "",
5
5
  "main": "dist/npm-entry",
6
- "typings": "dist/npm-entry/index.d.ts",
6
+ "typings": "dist/npm-entry/index-npm.d.ts",
7
7
  "engines": {
8
8
  "node": ">=16"
9
9
  },
@@ -45,7 +45,6 @@
45
45
  "author": "",
46
46
  "license": "ISC",
47
47
  "devDependencies": {
48
- "@ada-support/embed-types": "^1.1.0",
49
48
  "@ada-support/eslint-config-ada": "^1.2.1",
50
49
  "@testing-library/preact": "^2.0.1",
51
50
  "@types/enzyme": "^3.10.11",
@@ -83,6 +82,7 @@
83
82
  "webpack-dev-server": "^4.3.1"
84
83
  },
85
84
  "dependencies": {
85
+ "@ada-support/embed-types": "^1.1.1",
86
86
  "@babel/core": "^7.16.12",
87
87
  "@babel/plugin-proposal-class-properties": "^7.16.7",
88
88
  "@babel/plugin-proposal-numeric-separator": "^7.16.7",