@ada-support/embed2 1.2.13 → 1.2.16

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.
@@ -8,7 +8,7 @@ export declare class StoreProxy implements StoreProxyInterface {
8
8
  localChannel: CustomEventChannel;
9
9
  store: Store;
10
10
  registeredCallbacks: ((payload: StoreState) => void)[];
11
- constructor(messageService: MessageService);
11
+ constructor(initialState: StoreState, messageService: MessageService);
12
12
  get: <K extends keyof StoreState>(key: K) => Promise<StoreState[K]>;
13
13
  getState: () => Promise<StoreState>;
14
14
  dispatch: (actionKey: string, payload?: {}) => Promise<StoreState>;
@@ -5,7 +5,7 @@ export declare class Store {
5
5
  state: StoreState;
6
6
  defaultState: StoreState;
7
7
  messageService: MessageService;
8
- constructor(messageService: MessageService);
8
+ constructor(initialState: StoreState, messageService: MessageService);
9
9
  addChannelListener(name: keyof Channels): void;
10
10
  private handleEvents;
11
11
  private getEventHandler;
@@ -1,2 +1,3 @@
1
+ import type { StartOptions } from "@ada-support/embed-types";
1
2
  import type { StoreState } from "common/types/store-state";
2
- export declare const defaultState: StoreState;
3
+ export declare const getInitialState: (adaSettings: StartOptions) => StoreState;
@@ -42,7 +42,7 @@ export interface StoreState extends StartOptionsNoFunction {
42
42
  deviceToken: string | null;
43
43
  }
44
44
  export interface StartOptionsNoFunction {
45
- handle?: string;
45
+ handle: string;
46
46
  lazy?: boolean;
47
47
  styles?: string;
48
48
  embedStyles?: string;
@@ -15811,7 +15811,7 @@ const client = new error_tracker_BrowserClient({
15811
15811
  },
15812
15812
 
15813
15813
  environment: "production",
15814
- release: "1.2.13-9f1e1a1",
15814
+ release: "1.2.16-cdd3a2e",
15815
15815
  sampleRate: 0.25,
15816
15816
  autoSessionTracking: false,
15817
15817
  // Integrations don't seem to work with Sentry: https://github.com/getsentry/sentry-javascript/issues/2541
@@ -16426,7 +16426,7 @@ function getEmbedURL(_ref) {
16426
16426
  host = "http://".concat(window.location.hostname, ":9001");
16427
16427
  }
16428
16428
 
16429
- return "".concat(host, "/embed/").concat(frameName, "/").concat("9f1e1a1", "/index.html");
16429
+ return "".concat(host, "/embed/").concat(frameName, "/").concat("cdd3a2e", "/index.html");
16430
16430
  }
16431
16431
  /**
16432
16432
  * Generate the Chat / API URL
@@ -16776,122 +16776,6 @@ const mutations = (state, action) => {
16776
16776
  };
16777
16777
 
16778
16778
  /* harmony default export */ var store_mutations = (mutations);
16779
- ;// CONCATENATED MODULE: ./src/client/helpers/local-notifications/index.ts
16780
- const browserHasNotificationSupport = ("Notification" in window);
16781
- function checkIfUserHasGivenPermission() {
16782
- if (!browserHasNotificationSupport) {
16783
- return false;
16784
- }
16785
-
16786
- return Notification.permission === "granted";
16787
- }
16788
- function requestNotificationPermission() {
16789
- if (!browserHasNotificationSupport) {
16790
- return null;
16791
- }
16792
-
16793
- return Notification.requestPermission();
16794
- }
16795
- function createNotification(title, isChatOpen, onClickHandler, options) {
16796
- if (!checkIfUserHasGivenPermission() || !document.hidden && isChatOpen) {
16797
- return null;
16798
- }
16799
-
16800
- const notification = new Notification(title, options);
16801
-
16802
- notification.onclick = () => {
16803
- if (onClickHandler) {
16804
- onClickHandler();
16805
- }
16806
-
16807
- notification.close();
16808
- };
16809
-
16810
- return notification;
16811
- }
16812
-
16813
- function notificationPermissionGuard(state) {
16814
- if (state === "granted" || state === "denied") {
16815
- return state;
16816
- }
16817
-
16818
- return "default";
16819
- }
16820
- /**
16821
- * Used to listen for changes in Notification permission state
16822
- */
16823
-
16824
-
16825
- function notificationPermListener(notificationPermChangeHandler) {
16826
- if (!("permissions" in navigator)) {
16827
- return;
16828
- }
16829
-
16830
- navigator.permissions.query({
16831
- name: "notifications"
16832
- }).then(notificationPerm => {
16833
- // eslint-disable-next-line no-param-reassign
16834
- notificationPerm.onchange = () => {
16835
- notificationPermChangeHandler(notificationPermissionGuard(notificationPerm.state));
16836
- };
16837
- });
16838
- }
16839
- ;// CONCATENATED MODULE: ./src/client/store/state.ts
16840
-
16841
-
16842
-
16843
-
16844
-
16845
- function getValueFromStorage(key) {
16846
- return safeLocalStorage.getItem(key) || safeSessionStorage.getItem(key);
16847
- }
16848
-
16849
- const defaultState = {
16850
- handle: undefined,
16851
- styles: undefined,
16852
- domain: undefined,
16853
- cluster: undefined,
16854
- language: undefined,
16855
- greeting: undefined,
16856
- crossWindowPersistence: true,
16857
- hideMask: true,
16858
- metaFields: {},
16859
- sensitiveMetaFields: {},
16860
- parentElement: undefined,
16861
- isDrawerOpen: false,
16862
- drawerHasBeenOpened: false,
16863
- client: undefined,
16864
- isIntroShown: false,
16865
- wasIntroShown: false,
16866
- isButtonShown: false,
16867
- introDimensions: {},
16868
- unreadMessageCount: 0,
16869
- initialURL: undefined,
16870
- privateMode: false,
16871
- rolloutOverride: undefined,
16872
- chatterToken: getValueFromStorage(CHATTER_TOKEN_STORAGE_KEY) || undefined,
16873
- chatterCreated: getValueFromStorage(CHATTER_CREATED_STORAGE_KEY) || undefined,
16874
- zdSessionId: getValueFromStorage(ZD_SESSION_STORAGE_KEY) || undefined,
16875
- zdPreviousTags: getValueFromStorage(ZD_PREVIOUS_TAGS_STORAGE_KEY) || undefined,
16876
- zdMessagingExternalUserId: getValueFromStorage(ZD_MESSAGING_EXTERNAL_USER_ID_STORAGE_KEY) || null,
16877
- zdMessagingChatterCreated: getValueFromStorage(ZD_MESSAGING_CHATTER_CREATED_STORAGE_KEY) || null,
16878
- connections: {},
16879
- appConnectionState: ConnectionState.Uninitiated,
16880
- testMode: false,
16881
- embedStyles: undefined,
16882
- notificationsPermission: browserHasNotificationSupport ? Notification.permission : undefined,
16883
- browserHasNotificationSupport: browserHasNotificationSupport,
16884
- preload: false,
16885
- chatDimensions: undefined,
16886
- isChatWebsocketConnected: false,
16887
- latestCampaignKey: undefined,
16888
- hasChatOpenedAfterProactiveMessagesShown: false,
16889
- chatterInLiveChat: false,
16890
- adaSettings: {},
16891
- wasCampaignShownButNowClosed: false,
16892
- proactiveCampaignHadMessages: false,
16893
- deviceToken: null
16894
- };
16895
16779
  ;// CONCATENATED MODULE: ./src/client/store/index.ts
16896
16780
 
16897
16781
 
@@ -16906,17 +16790,16 @@ function store_objectSpread(target) { for (var i = 1; i < arguments.length; i++)
16906
16790
 
16907
16791
 
16908
16792
 
16909
-
16910
16793
  class Store {
16911
- constructor(messageService) {
16794
+ constructor(initialState, messageService) {
16912
16795
  _defineProperty(this, "state", void 0);
16913
16796
 
16914
16797
  _defineProperty(this, "defaultState", void 0);
16915
16798
 
16916
16799
  _defineProperty(this, "messageService", void 0);
16917
16800
 
16918
- this.defaultState = defaultState;
16919
- this.state = defaultState;
16801
+ this.defaultState = initialState;
16802
+ this.state = initialState;
16920
16803
  this.messageService = messageService;
16921
16804
  }
16922
16805
 
@@ -17038,7 +16921,7 @@ class Store {
17038
16921
 
17039
16922
 
17040
16923
  class StoreProxy {
17041
- constructor(messageService) {
16924
+ constructor(initialState, messageService) {
17042
16925
  _defineProperty(this, "localChannel", void 0);
17043
16926
 
17044
16927
  _defineProperty(this, "store", void 0);
@@ -17063,7 +16946,7 @@ class StoreProxy {
17063
16946
  _defineProperty(this, "addChannelListener", name => this.store.addChannelListener(name));
17064
16947
 
17065
16948
  this.localChannel = messageService.channels.local;
17066
- this.store = new Store(messageService);
16949
+ this.store = new Store(initialState, messageService);
17067
16950
  this.store.addChannelListener("local");
17068
16951
  this.localChannel.addEventListener((type, payload) => {
17069
16952
  if (type === STATE_CHANGE_EVENT) {
@@ -17075,6 +16958,122 @@ class StoreProxy {
17075
16958
  }
17076
16959
 
17077
16960
  }
16961
+ ;// CONCATENATED MODULE: ./src/client/helpers/local-notifications/index.ts
16962
+ const browserHasNotificationSupport = ("Notification" in window);
16963
+ function checkIfUserHasGivenPermission() {
16964
+ if (!browserHasNotificationSupport) {
16965
+ return false;
16966
+ }
16967
+
16968
+ return Notification.permission === "granted";
16969
+ }
16970
+ function requestNotificationPermission() {
16971
+ if (!browserHasNotificationSupport) {
16972
+ return null;
16973
+ }
16974
+
16975
+ return Notification.requestPermission();
16976
+ }
16977
+ function createNotification(title, isChatOpen, onClickHandler, options) {
16978
+ if (!checkIfUserHasGivenPermission() || !document.hidden && isChatOpen) {
16979
+ return null;
16980
+ }
16981
+
16982
+ const notification = new Notification(title, options);
16983
+
16984
+ notification.onclick = () => {
16985
+ if (onClickHandler) {
16986
+ onClickHandler();
16987
+ }
16988
+
16989
+ notification.close();
16990
+ };
16991
+
16992
+ return notification;
16993
+ }
16994
+
16995
+ function notificationPermissionGuard(state) {
16996
+ if (state === "granted" || state === "denied") {
16997
+ return state;
16998
+ }
16999
+
17000
+ return "default";
17001
+ }
17002
+ /**
17003
+ * Used to listen for changes in Notification permission state
17004
+ */
17005
+
17006
+
17007
+ function notificationPermListener(notificationPermChangeHandler) {
17008
+ if (!("permissions" in navigator)) {
17009
+ return;
17010
+ }
17011
+
17012
+ navigator.permissions.query({
17013
+ name: "notifications"
17014
+ }).then(notificationPerm => {
17015
+ // eslint-disable-next-line no-param-reassign
17016
+ notificationPerm.onchange = () => {
17017
+ notificationPermChangeHandler(notificationPermissionGuard(notificationPerm.state));
17018
+ };
17019
+ });
17020
+ }
17021
+ ;// CONCATENATED MODULE: ./src/client/store/state.ts
17022
+
17023
+
17024
+
17025
+
17026
+
17027
+ function getValueFromStorage(key) {
17028
+ return safeLocalStorage.getItem(key) || safeSessionStorage.getItem(key);
17029
+ }
17030
+
17031
+ const getInitialState = adaSettings => ({
17032
+ adaSettings,
17033
+ handle: adaSettings.handle,
17034
+ styles: undefined,
17035
+ domain: undefined,
17036
+ cluster: undefined,
17037
+ language: undefined,
17038
+ greeting: undefined,
17039
+ crossWindowPersistence: true,
17040
+ hideMask: true,
17041
+ metaFields: {},
17042
+ sensitiveMetaFields: {},
17043
+ parentElement: undefined,
17044
+ isDrawerOpen: false,
17045
+ drawerHasBeenOpened: false,
17046
+ client: undefined,
17047
+ isIntroShown: false,
17048
+ wasIntroShown: false,
17049
+ isButtonShown: false,
17050
+ introDimensions: {},
17051
+ unreadMessageCount: 0,
17052
+ initialURL: undefined,
17053
+ privateMode: false,
17054
+ rolloutOverride: undefined,
17055
+ chatterToken: getValueFromStorage(CHATTER_TOKEN_STORAGE_KEY) || undefined,
17056
+ chatterCreated: getValueFromStorage(CHATTER_CREATED_STORAGE_KEY) || undefined,
17057
+ zdSessionId: getValueFromStorage(ZD_SESSION_STORAGE_KEY) || undefined,
17058
+ zdPreviousTags: getValueFromStorage(ZD_PREVIOUS_TAGS_STORAGE_KEY) || undefined,
17059
+ zdMessagingExternalUserId: getValueFromStorage(ZD_MESSAGING_EXTERNAL_USER_ID_STORAGE_KEY) || null,
17060
+ zdMessagingChatterCreated: getValueFromStorage(ZD_MESSAGING_CHATTER_CREATED_STORAGE_KEY) || null,
17061
+ connections: {},
17062
+ appConnectionState: ConnectionState.Uninitiated,
17063
+ testMode: false,
17064
+ embedStyles: undefined,
17065
+ notificationsPermission: browserHasNotificationSupport ? Notification.permission : undefined,
17066
+ browserHasNotificationSupport: browserHasNotificationSupport,
17067
+ preload: false,
17068
+ chatDimensions: undefined,
17069
+ isChatWebsocketConnected: false,
17070
+ latestCampaignKey: undefined,
17071
+ hasChatOpenedAfterProactiveMessagesShown: false,
17072
+ chatterInLiveChat: false,
17073
+ wasCampaignShownButNowClosed: false,
17074
+ proactiveCampaignHadMessages: false,
17075
+ deviceToken: null
17076
+ });
17078
17077
  ;// CONCATENATED MODULE: ./src/common/helpers/get-intro-for-url.ts
17079
17078
  function getProcessedPath(path) {
17080
17079
  const regex = /^http(s)?:\/\/(www.)?/;
@@ -18002,9 +18001,9 @@ async function log(message, extra, options) {
18002
18001
  service: "embed",
18003
18002
  env: "production",
18004
18003
  embedVersion: 2,
18005
- version: "1.2.13",
18004
+ version: "1.2.16",
18006
18005
  isNpm: true,
18007
- commitHash: "9f1e1a1"
18006
+ commitHash: "cdd3a2e"
18008
18007
  }))
18009
18008
  });
18010
18009
  }
@@ -18020,7 +18019,6 @@ var url_default = /*#__PURE__*/__webpack_require__.n(url);
18020
18019
 
18021
18020
 
18022
18021
 
18023
-
18024
18022
  class IFrame extends d {
18025
18023
  constructor() {
18026
18024
  super(...arguments);
@@ -18076,11 +18074,6 @@ class IFrame extends d {
18076
18074
  domain,
18077
18075
  cluster
18078
18076
  } = this.props;
18079
-
18080
- if (!handle) {
18081
- throw new AdaEmbedError("`handle` is undefined");
18082
- }
18083
-
18084
18077
  return getEmbedURL({
18085
18078
  frameName: name,
18086
18079
  handle,
@@ -18421,17 +18414,12 @@ class ChatFrame extends d {
18421
18414
  privateMode,
18422
18415
  testMode,
18423
18416
  adaSettings
18424
- } = this.props;
18425
-
18426
- if (!handle) {
18427
- throw new AdaEmbedError("`handle` is not defined");
18428
- } // check the host page URL for an adaSMSToken and add it as a chatterToken query param for chat's iframe URL
18429
-
18417
+ } = this.props; // check the host page URL for an adaSMSToken and add it as a chatterToken query param for chat's iframe URL
18430
18418
 
18431
18419
  const hostPageUrlParams = new (url_default())(window.location.href).searchParams;
18432
18420
  const smsToken = hostPageUrlParams.get("adaSMSToken");
18433
18421
  const queryParams = {
18434
- embedVersion: "9f1e1a1".slice(0, 7),
18422
+ embedVersion: "cdd3a2e".slice(0, 7),
18435
18423
  greeting,
18436
18424
  language,
18437
18425
  skipGreeting,
@@ -19699,6 +19687,28 @@ class Container extends d {
19699
19687
  }
19700
19688
  }
19701
19689
 
19690
+ async handleSettingDeviceToken(localChannel, payload, id) {
19691
+ const {
19692
+ setState,
19693
+ sensitiveMetaFields,
19694
+ metaFields
19695
+ } = this.props;
19696
+ const sdkType = (metaFields === null || metaFields === void 0 ? void 0 : metaFields.sdkType) || "WEB"; // If using react native then send os type as android since react native uses Firebase Cloud Messaging
19697
+
19698
+ const deviceOS = sdkType === "REACTNATIVE" ? "ANDROID" : sdkType;
19699
+ const {
19700
+ token
19701
+ } = payload;
19702
+ await setState({
19703
+ deviceToken: token,
19704
+ sensitiveMetaFields: Container_objectSpread(Container_objectSpread({}, sensitiveMetaFields), {}, {
19705
+ device_token: token,
19706
+ device_os: deviceOS
19707
+ })
19708
+ });
19709
+ localChannel.postMessage(SET_DEVICE_TOKEN_RESPONSE, null, id);
19710
+ }
19711
+
19702
19712
  async handleEmbedAction(type, payload, id) {
19703
19713
  const {
19704
19714
  client,
@@ -19954,16 +19964,7 @@ class Container extends d {
19954
19964
 
19955
19965
  case SET_DEVICE_TOKEN:
19956
19966
  {
19957
- const {
19958
- setState
19959
- } = this.props;
19960
- const {
19961
- token
19962
- } = payload;
19963
- await setState({
19964
- deviceToken: token
19965
- });
19966
- localChannel.postMessage(SET_DEVICE_TOKEN_RESPONSE, null, id);
19967
+ this.handleSettingDeviceToken(localChannel, payload, id);
19967
19968
  break;
19968
19969
  }
19969
19970
 
@@ -20365,6 +20366,7 @@ function embed_objectSpread(target) { for (var i = 1; i < arguments.length; i++)
20365
20366
 
20366
20367
 
20367
20368
 
20369
+
20368
20370
  class Embed {
20369
20371
  constructor(adaSettings, unmountCallback) {
20370
20372
  var _this = this;
@@ -20396,7 +20398,8 @@ class Embed {
20396
20398
  this.adaSettings = adaSettings;
20397
20399
  this.unmountCallback = unmountCallback;
20398
20400
  this.messageService = new MessageService();
20399
- this.store = new StoreProxy(this.messageService);
20401
+ const initialState = getInitialState(adaSettings);
20402
+ this.store = new StoreProxy(initialState, this.messageService);
20400
20403
  this.localChannel = this.messageService.channels.local;
20401
20404
  this.initialized = new Promise((resolve, reject) => {
20402
20405
  this.initializationResolve = resolve;
@@ -20575,7 +20578,7 @@ class Embed {
20575
20578
 
20576
20579
  }
20577
20580
 
20578
- _defineProperty(Embed, "embed2Version", "9f1e1a1");
20581
+ _defineProperty(Embed, "embed2Version", "cdd3a2e");
20579
20582
  ;// CONCATENATED MODULE: ./src/common/helpers/startup.ts
20580
20583
 
20581
20584
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ada-support/embed2",
3
- "version": "1.2.13",
3
+ "version": "1.2.16",
4
4
  "description": "",
5
5
  "main": "dist/npm-entry",
6
6
  "typings": "dist/npm-entry/index-npm.d.ts",
@@ -11,7 +11,7 @@
11
11
  "build": "TS_NODE_PROJECT=wp.tsconfig.json NODE_ENV=production npx webpack --config webpack.prod.ts",
12
12
  "build:npm-types": "tsc --project tsconfig.npm.json --declaration --outDir dist/npm-entry --emitDeclarationOnly --allowJs false --checkJs false",
13
13
  "build:npm": "./npm-build.sh",
14
- "lint": "tsc --noEmit --strict false && ./node_modules/.bin/eslint --report-unused-disable-directives --ext .js,.jsx,.ts,.tsx . --max-warnings 24",
14
+ "lint": "tsc --noEmit --strict false && ./node_modules/.bin/eslint --report-unused-disable-directives --ext .js,.jsx,.ts,.tsx . --max-warnings 23",
15
15
  "lint:fix": "yarn lint --fix",
16
16
  "test": "jest",
17
17
  "check-types": "./node_modules/typescript/bin/tsc --project ./tsconfig.json --noEmit --strict false",