@ada-support/embed2 1.2.3 → 1.2.6

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.3-01ab840",
15638
+ release: "1.2.6-0d8278e",
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("01ab840", "/index.html");
16252
+ return "".concat(host, "/embed/").concat(frameName, "/").concat("0d8278e", "/index.html");
16239
16253
  }
16240
16254
  /**
16241
16255
  * Generate the Chat / API URL
@@ -17179,11 +17193,16 @@ function triggerCampaignImpl(_ref) {
17179
17193
  const body = campaign.message_text[language];
17180
17194
  const duration = campaign.message_duration;
17181
17195
  const responseId = campaign.follow_up_response_id;
17182
- localChannel === null || localChannel === void 0 ? void 0 : localChannel.postMessage(CREATE_PROACTIVE, {
17183
- body,
17184
- duration,
17185
- responseId
17186
- });
17196
+
17197
+ if (body) {
17198
+ localChannel === null || localChannel === void 0 ? void 0 : localChannel.postMessage(CREATE_PROACTIVE, {
17199
+ body,
17200
+ duration,
17201
+ responseId
17202
+ });
17203
+ } else {
17204
+ warn("No translation for this campaign (campaign_key: ".concat(campaign.campaign_key, ") is defined for the language: ").concat(language));
17205
+ }
17187
17206
  } else {
17188
17207
  const url = getURL({
17189
17208
  name: "api",
@@ -17791,12 +17810,15 @@ async function log(message, extra, options) {
17791
17810
  service: "embed",
17792
17811
  env: "production",
17793
17812
  embedVersion: 2,
17794
- version: "1.2.3",
17813
+ version: "1.2.6",
17795
17814
  isNpm: true,
17796
- commitHash: "01ab840"
17815
+ commitHash: "0d8278e"
17797
17816
  }))
17798
17817
  });
17799
17818
  }
17819
+ // EXTERNAL MODULE: ./node_modules/@babel/runtime-corejs3/core-js-stable/url.js
17820
+ var url = __webpack_require__(9969);
17821
+ var url_default = /*#__PURE__*/__webpack_require__.n(url);
17800
17822
  ;// CONCATENATED MODULE: ./src/client/components/IFrame/index.tsx
17801
17823
 
17802
17824
 
@@ -17805,6 +17827,8 @@ async function log(message, extra, options) {
17805
17827
 
17806
17828
 
17807
17829
 
17830
+
17831
+
17808
17832
  class IFrame extends d {
17809
17833
  constructor() {
17810
17834
  super(...arguments);
@@ -17814,6 +17838,23 @@ class IFrame extends d {
17814
17838
  _defineProperty(this, "channel", void 0);
17815
17839
  }
17816
17840
 
17841
+ getChannel() {
17842
+ const {
17843
+ name,
17844
+ store,
17845
+ messageService
17846
+ } = this.props;
17847
+
17848
+ if (this.channel) {
17849
+ return this.channel;
17850
+ }
17851
+
17852
+ const targetOrigin = new (url_default())(this.iframeRef.current.src).origin;
17853
+ const channel = messageService.registerFrameChannel(name, this.iframeRef.current.contentWindow, targetOrigin);
17854
+ store.addChannelListener(name);
17855
+ return channel;
17856
+ }
17857
+
17817
17858
  componentDidMount() {
17818
17859
  this.connectFrame();
17819
17860
  }
@@ -17824,7 +17865,7 @@ class IFrame extends d {
17824
17865
  } = this.props;
17825
17866
 
17826
17867
  if (appConnectionState === ConnectionState.Done) {
17827
- this.channel.postMessage(ALL_FRAMES_LOADED);
17868
+ this.getChannel().postMessage(ALL_FRAMES_LOADED);
17828
17869
  }
17829
17870
  }
17830
17871
 
@@ -17843,6 +17884,11 @@ class IFrame extends d {
17843
17884
  domain,
17844
17885
  cluster
17845
17886
  } = this.props;
17887
+
17888
+ if (!handle) {
17889
+ throw new AdaEmbedError("`handle` is undefined");
17890
+ }
17891
+
17846
17892
  return getEmbedURL({
17847
17893
  frameName: name,
17848
17894
  handle,
@@ -17854,13 +17900,10 @@ class IFrame extends d {
17854
17900
  async connectFrame() {
17855
17901
  const {
17856
17902
  name,
17857
- store,
17858
17903
  setState,
17859
- messageService,
17860
17904
  setConnectionState
17861
17905
  } = this.props;
17862
- this.channel = messageService.registerFrameChannel(name, this.iframeRef.current.contentWindow, this.iframeRef.current.src);
17863
- store.addChannelListener(name);
17906
+ this.channel = this.getChannel();
17864
17907
  await setConnectionState({
17865
17908
  [name]: ConnectionState.Loading
17866
17909
  });
@@ -17870,9 +17913,9 @@ class IFrame extends d {
17870
17913
  const initMessageHandler = (type, payload) => {
17871
17914
  (async () => {
17872
17915
  if (type === "".concat(name, "_INIT")) {
17873
- this.channel.removeEventListener(handlerRef);
17874
- this.channel.clearTrackedTimeout(timeout);
17875
- this.channel.isConnected = true;
17916
+ this.getChannel().removeEventListener(handlerRef);
17917
+ this.getChannel().clearTrackedTimeout(timeout);
17918
+ this.getChannel().isConnected = true;
17876
17919
  /**
17877
17920
  * Set initial state (if any).
17878
17921
  * This is mostly useful for XStorage to set state based on storage values
@@ -17890,7 +17933,7 @@ class IFrame extends d {
17890
17933
  };
17891
17934
 
17892
17935
  timeout = window.setTimeout(() => {
17893
- this.channel.removeEventListener(handlerRef);
17936
+ this.getChannel().removeEventListener(handlerRef);
17894
17937
  setConnectionState({
17895
17938
  [name]: ConnectionState.Failure
17896
17939
  });
@@ -18067,9 +18110,6 @@ function ButtonFrame_mapStateToProps(storeState) {
18067
18110
  }
18068
18111
 
18069
18112
  /* 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
18113
  ;// CONCATENATED MODULE: ./src/common/constants/timeouts.ts
18074
18114
  const ANIMATION_DELAY = 50;
18075
18115
  ;// CONCATENATED MODULE: ./src/common/helpers/is-mobile.ts
@@ -18124,7 +18164,8 @@ class ChatFrame extends d {
18124
18164
  } = this.props;
18125
18165
  this.rememberInitialPageStyle();
18126
18166
  setChatHasBeenRendered();
18127
- this.channel = messageService.registerFrameChannel("chat", this.iframeRef.current.contentWindow, this.iframeRef.current.src);
18167
+ const targetOrigin = new (url_default())(this.iframeRef.current.src).origin;
18168
+ this.channel = messageService.registerFrameChannel("chat", this.iframeRef.current.contentWindow, targetOrigin);
18128
18169
  store.addChannelListener("chat");
18129
18170
  this.bindChatEventHandlers();
18130
18171
  this.handleScrollLock(); // We use this log to track number of chat impressions (times when users see chat iFrame render first time).
@@ -18198,7 +18239,7 @@ class ChatFrame extends d {
18198
18239
  const hostPageUrlParams = new (url_default())(window.location.href).searchParams;
18199
18240
  const smsToken = hostPageUrlParams.get("adaSMSToken");
18200
18241
  const queryParams = {
18201
- embedVersion: "01ab840".slice(0, 7),
18242
+ embedVersion: "0d8278e".slice(0, 7),
18202
18243
  greeting,
18203
18244
  language,
18204
18245
  skipGreeting,
@@ -20342,7 +20383,7 @@ class Embed {
20342
20383
 
20343
20384
  }
20344
20385
 
20345
- _defineProperty(Embed, "embed2Version", "01ab840");
20386
+ _defineProperty(Embed, "embed2Version", "0d8278e");
20346
20387
  ;// CONCATENATED MODULE: ./src/common/helpers/startup.ts
20347
20388
 
20348
20389
 
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@ada-support/embed2",
3
- "version": "1.2.3",
3
+ "version": "1.2.6",
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",