@ada-support/embed2 1.3.1 → 1.4.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,3 @@
1
+ import type { Client } from "common/models/client";
2
+ import type { MessagePayload } from "common/types/events";
3
+ export declare function storeChatterEventDataInBrowser(client: Client, payload: MessagePayload): void;
@@ -0,0 +1 @@
1
+ export * from "./chatterEvent";
@@ -1,5 +1,6 @@
1
1
  export declare const CHATTER_TOKEN_STORAGE_KEY = "chatter";
2
2
  export declare const CHATTER_CREATED_STORAGE_KEY = "ada-embed_chatter-created";
3
+ export declare const SESSION_AUTH_TOKEN_STORAGE_KEY = "session_token";
3
4
  export declare const IN_LIVE_CHAT_STORAGE_KEY = "inLiveChat";
4
5
  export declare const ZD_SESSION_STORAGE_KEY = "ada-embed_zd-session-id";
5
6
  export declare const ZD_PREVIOUS_TAGS_STORAGE_KEY = "ada-embed_zd-previous-tags";
@@ -22,6 +22,7 @@ export interface Features {
22
22
  afm_proactive_messaging?: boolean;
23
23
  embed_test_bot?: boolean;
24
24
  translations?: boolean;
25
+ chat_session_auth?: boolean;
25
26
  }
26
27
  export interface ClientObject {
27
28
  handle: string;
@@ -4,6 +4,7 @@ import type { Client } from "common/models/client";
4
4
  export interface StoreState extends StartOptionsNoFunction {
5
5
  chatterCreated?: string | null;
6
6
  chatterToken?: string | null;
7
+ sessionToken?: string | null;
7
8
  client?: Client;
8
9
  isDrawerOpen: boolean;
9
10
  zdSessionId?: string | null;
@@ -7,3 +7,4 @@ export declare const PERSISTENCE_SESSION = "session";
7
7
  * persistence setting. If privateMode is set, it returns null.
8
8
  */
9
9
  export declare function retrieveStorage<T extends StorageKey>(key: T, client: Client, privateMode?: boolean): StorageValueByKey[T] | null;
10
+ export declare function setBrowserStorageItem<T extends StorageKey>(key: T, value: StorageValueByKey[T], persistenceSetting: Client["persistence"]): void;
@@ -1,4 +1,4 @@
1
- import type { CHATTER_CREATED_STORAGE_KEY, CHATTER_TOKEN_STORAGE_KEY, IN_LIVE_CHAT_STORAGE_KEY, ZD_MESSAGING_CHATTER_CREATED_STORAGE_KEY, ZD_MESSAGING_EXTERNAL_USER_ID_STORAGE_KEY, ZD_PREVIOUS_TAGS_STORAGE_KEY, ZD_SESSION_STORAGE_KEY } from "common/constants/storage-keys";
1
+ import type { CHATTER_CREATED_STORAGE_KEY, CHATTER_TOKEN_STORAGE_KEY, IN_LIVE_CHAT_STORAGE_KEY, SESSION_AUTH_TOKEN_STORAGE_KEY, ZD_MESSAGING_CHATTER_CREATED_STORAGE_KEY, ZD_MESSAGING_EXTERNAL_USER_ID_STORAGE_KEY, ZD_PREVIOUS_TAGS_STORAGE_KEY, ZD_SESSION_STORAGE_KEY } from "common/constants/storage-keys";
2
2
  export declare enum StorageTypes {
3
3
  Local = "local",
4
4
  Session = "session"
@@ -8,6 +8,7 @@ export declare type StorageValueType = string | number | boolean | unknown[];
8
8
  export interface StorageValueByKey {
9
9
  [CHATTER_CREATED_STORAGE_KEY]: string;
10
10
  [CHATTER_TOKEN_STORAGE_KEY]: string;
11
+ [SESSION_AUTH_TOKEN_STORAGE_KEY]: string;
11
12
  [IN_LIVE_CHAT_STORAGE_KEY]: boolean;
12
13
  [ZD_SESSION_STORAGE_KEY]: string;
13
14
  [ZD_PREVIOUS_TAGS_STORAGE_KEY]: string;
@@ -15811,7 +15811,7 @@ const client = new error_tracker_BrowserClient({
15811
15811
  },
15812
15812
 
15813
15813
  environment: "production",
15814
- release: "1.3.1-512664b",
15814
+ release: "1.4.0-29cbcb3",
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
@@ -16432,7 +16432,7 @@ function getEmbedURL(_ref) {
16432
16432
  host = "http://".concat(window.location.hostname, ":9001");
16433
16433
  }
16434
16434
 
16435
- return "".concat(host, "/embed/").concat(frameName, "/").concat("512664b", "/index.html");
16435
+ return "".concat(host, "/embed/").concat(frameName, "/").concat("29cbcb3", "/index.html");
16436
16436
  }
16437
16437
 
16438
16438
  function constructQueryString(query) {
@@ -16631,6 +16631,7 @@ const actions = {
16631
16631
  ;// CONCATENATED MODULE: ./src/common/constants/storage-keys.ts
16632
16632
  const CHATTER_TOKEN_STORAGE_KEY = "chatter";
16633
16633
  const CHATTER_CREATED_STORAGE_KEY = "ada-embed_chatter-created";
16634
+ const SESSION_AUTH_TOKEN_STORAGE_KEY = "session_token";
16634
16635
  const IN_LIVE_CHAT_STORAGE_KEY = "inLiveChat";
16635
16636
  const ZD_SESSION_STORAGE_KEY = "ada-embed_zd-session-id";
16636
16637
  const ZD_PREVIOUS_TAGS_STORAGE_KEY = "ada-embed_zd-previous-tags";
@@ -17094,6 +17095,7 @@ const getInitialState = adaSettings => ({
17094
17095
  rolloutOverride: undefined,
17095
17096
  chatterToken: getValueFromStorage(CHATTER_TOKEN_STORAGE_KEY) || undefined,
17096
17097
  chatterCreated: getValueFromStorage(CHATTER_CREATED_STORAGE_KEY) || undefined,
17098
+ sessionToken: getValueFromStorage(SESSION_AUTH_TOKEN_STORAGE_KEY || undefined),
17097
17099
  zdSessionId: getValueFromStorage(ZD_SESSION_STORAGE_KEY) || undefined,
17098
17100
  zdPreviousTags: getValueFromStorage(ZD_PREVIOUS_TAGS_STORAGE_KEY) || undefined,
17099
17101
  zdMessagingExternalUserId: getValueFromStorage(ZD_MESSAGING_EXTERNAL_USER_ID_STORAGE_KEY) || null,
@@ -17998,6 +18000,32 @@ function retrieveStorage(key, client, privateMode) {
17998
18000
 
17999
18001
  return null;
18000
18002
  }
18003
+ function setBrowserStorageItem(key, value, persistenceSetting) {
18004
+ if (persistenceSetting === PERSISTENCE_NORMAL) {
18005
+ safeLocalStorage.setItem(key, value);
18006
+ }
18007
+
18008
+ if (persistenceSetting === PERSISTENCE_SESSION) {
18009
+ safeSessionStorage.setItem(key, value);
18010
+ }
18011
+ }
18012
+ ;// CONCATENATED MODULE: ./src/services/persistence/index.ts
18013
+ const persistence = {
18014
+ get: item => {
18015
+ try {
18016
+ return localStorage.getItem(item);
18017
+ } catch (e) {
18018
+ /* istanbul ignore next */
18019
+ return null;
18020
+ }
18021
+ },
18022
+ set: (item, value) => {
18023
+ try {
18024
+ localStorage.setItem(item, value);
18025
+ } catch (e) {// Do nothing
18026
+ }
18027
+ }
18028
+ };
18001
18029
  ;// CONCATENATED MODULE: ./src/services/chat-versioning/manifest.ts
18002
18030
 
18003
18031
  const CHAT_MANIFEST_PATH = "https://static.ada.support/chat-manifest.json";
@@ -18045,53 +18073,69 @@ const isManifest = input => {
18045
18073
  return true;
18046
18074
  };
18047
18075
  ;// CONCATENATED MODULE: ./src/services/chat-versioning/index.ts
18048
- // TODO CHATX-1613: Turn on persistence when we're allowed to
18049
- // import { persistence } from "services/persistence";
18050
18076
 
18051
18077
 
18078
+ // Somewhat inefficient, but more than adequate shuffle algorithm for small arrays
18079
+
18080
+ const arrayShuffle = array => array.map(value => ({
18081
+ value,
18082
+ sort: Math.random()
18083
+ })).sort((a, b) => a.sort - b.sort).map(_ref => {
18084
+ let {
18085
+ value
18086
+ } = _ref;
18087
+ return value;
18088
+ });
18089
+
18052
18090
  const getChatVersionFromManifest = manifest => {
18053
18091
  /* istanbul ignore next */
18054
18092
  if (!isManifest(manifest)) {
18055
18093
  // This should never happen since isManifest throws an error for invalid input
18056
18094
  throw new AdaEmbedError(MANIFEST_VALIDATION_ERROR_MESSAGE);
18057
- } // TODO CHATX-1613: Turn on persistence when we're allowed to
18058
- // const manifestString = JSON.stringify(manifest);
18059
- // const manifestCache = persistence.get("ada-embed_chat-manifest-cache");
18060
- // if (manifestString === manifestCache) {
18061
- // const assignedVersion = persistence.get("ada-embed_chat-assigned-version");
18062
- //
18063
- // /* istanbul ignore else */
18064
- // if (assignedVersion) {
18065
- // return assignedVersion;
18066
- // }
18067
- // }
18095
+ }
18096
+
18097
+ const manifestString = JSON.stringify(manifest);
18098
+ const manifestCache = persistence.get("ada-embed_chat-manifest-cache");
18068
18099
 
18100
+ if (manifestString === manifestCache) {
18101
+ const assignedVersion = persistence.get("ada-embed_chat-assigned-version");
18102
+ /* istanbul ignore else */
18103
+
18104
+ if (assignedVersion) {
18105
+ return assignedVersion;
18106
+ }
18107
+ }
18069
18108
 
18070
18109
  const random = Math.random();
18071
18110
  const {
18072
18111
  versions
18073
- } = manifest; // Use hash from last version in array by default
18112
+ } = manifest;
18113
+ const shuffledVersions = arrayShuffle(versions); // Use hash from last version in array by default
18074
18114
 
18075
18115
  let {
18076
18116
  hash
18077
- } = versions[versions.length - 1]; // Loop through versions
18117
+ } = shuffledVersions[shuffledVersions.length - 1]; // Loop through shuffledVersions
18078
18118
 
18079
- for (let i = 0; i < versions.length; i += 1) {
18080
- const v = versions[i]; // If random falls into version weight
18119
+ for (let i = 0; i < shuffledVersions.length; i += 1) {
18120
+ const v = shuffledVersions[i]; // If random falls into version weight
18081
18121
 
18082
18122
  if (random <= v.weight) {
18083
18123
  hash = v.hash;
18084
18124
  break;
18085
18125
  }
18086
- } // TODO CHATX-1613: Turn on persistence when we're allowed to
18087
- // persistence.set("ada-embed_chat-assigned-version", hash);
18088
- // persistence.set("ada-embed_chat-manifest-cache", manifestString);
18089
-
18126
+ }
18090
18127
 
18128
+ persistence.set("ada-embed_chat-assigned-version", hash);
18129
+ persistence.set("ada-embed_chat-manifest-cache", manifestString);
18091
18130
  return hash;
18092
18131
  };
18093
18132
  const getChatVersion = async () => {
18094
18133
  const manifest = await loadChatManifest();
18134
+
18135
+ if (window.__AdaChatVersion) {
18136
+ return window.__AdaChatVersion;
18137
+ }
18138
+
18095
18139
  return getChatVersionFromManifest(manifest);
18096
18140
  };
18097
18141
  // EXTERNAL MODULE: ./node_modules/lodash.memoize/index.js
@@ -18137,9 +18181,9 @@ async function log(message, extra, options) {
18137
18181
  service: "embed",
18138
18182
  env: "production",
18139
18183
  embedVersion: 2,
18140
- version: "1.3.1",
18184
+ version: "1.4.0",
18141
18185
  isNpm: true,
18142
- commitHash: "512664b"
18186
+ commitHash: "29cbcb3"
18143
18187
  }))
18144
18188
  });
18145
18189
  }
@@ -18435,6 +18479,30 @@ function ButtonFrame_mapStateToProps(storeState) {
18435
18479
  const ANIMATION_DELAY = 50;
18436
18480
  ;// CONCATENATED MODULE: ./src/common/helpers/is-mobile.ts
18437
18481
  const isMobile = /(iPhone)|(iPod)|(android)|(webOS)/i.exec(navigator.userAgent) !== null;
18482
+ ;// CONCATENATED MODULE: ./src/client/components/ChatFrame/chatFrameEvents/chatterEvent/index.ts
18483
+
18484
+
18485
+ function storeChatterEventDataInBrowser(client, payload) {
18486
+ const {
18487
+ persistence,
18488
+ features
18489
+ } = client; // TODO: CHATX-1618 please remove the line below - the ff won't be needed anymore
18490
+
18491
+ const isChatSessionAuthEnabled = features.chat_session_auth;
18492
+ const {
18493
+ chatter,
18494
+ created,
18495
+ sessionToken
18496
+ } = payload;
18497
+ setBrowserStorageItem(CHATTER_STORAGE_KEY, chatter, persistence);
18498
+ setBrowserStorageItem(CHATTER_CREATED_STORAGE_KEY, created, persistence); // TODO: CHATX-1618 please remove the check for isChatSessionAuthEnabled - the Boolean(sessionToken) is still needed so we don't store falsy values
18499
+
18500
+ if (isChatSessionAuthEnabled && Boolean(sessionToken)) {
18501
+ setBrowserStorageItem(SESSION_AUTH_TOKEN_STORAGE_KEY, sessionToken, persistence);
18502
+ }
18503
+ }
18504
+ ;// CONCATENATED MODULE: ./src/client/components/ChatFrame/chatFrameEvents/index.ts
18505
+
18438
18506
  ;// CONCATENATED MODULE: ./src/client/components/ChatFrame/index.tsx
18439
18507
 
18440
18508
 
@@ -18453,6 +18521,7 @@ const isMobile = /(iPhone)|(iPod)|(android)|(webOS)/i.exec(navigator.userAgent)
18453
18521
 
18454
18522
 
18455
18523
 
18524
+
18456
18525
  class ChatFrame extends d {
18457
18526
  constructor() {
18458
18527
  super(...arguments);
@@ -18556,7 +18625,7 @@ class ChatFrame extends d {
18556
18625
  const hostPageUrlParams = new (url_default())(window.location.href).searchParams;
18557
18626
  const smsToken = hostPageUrlParams.get("adaSMSToken");
18558
18627
  const queryParams = {
18559
- embedVersion: "512664b".slice(0, 7),
18628
+ embedVersion: "29cbcb3".slice(0, 7),
18560
18629
  greeting,
18561
18630
  language,
18562
18631
  skipGreeting,
@@ -18860,7 +18929,8 @@ class ChatFrame extends d {
18860
18929
  } = this.props;
18861
18930
  const {
18862
18931
  chatter,
18863
- created
18932
+ created,
18933
+ sessionToken
18864
18934
  } = payload;
18865
18935
  const {
18866
18936
  chatterTokenCallback
@@ -18870,27 +18940,17 @@ class ChatFrame extends d {
18870
18940
  throw new AdaEmbedError("`client` is undefined");
18871
18941
  }
18872
18942
 
18873
- await setState({
18874
- chatterToken: chatter,
18875
- chatterCreated: created
18876
- });
18877
- /**
18878
- * Store the token so when embed loads in the future, it doesn't have to wait for it to
18879
- * come from chat. This is important for campaign and business event triggers.
18880
- */
18881
-
18882
- if (client.persistence === PERSISTENCE_NORMAL) {
18883
- safeLocalStorage.setItem(CHATTER_STORAGE_KEY, chatter);
18884
- safeLocalStorage.setItem(CHATTER_CREATED_STORAGE_KEY, created);
18885
- } else if (client.persistence === PERSISTENCE_SESSION) {
18886
- safeSessionStorage.setItem(CHATTER_STORAGE_KEY, chatter);
18887
- safeSessionStorage.setItem(CHATTER_CREATED_STORAGE_KEY, created);
18888
- }
18943
+ storeChatterEventDataInBrowser(client, payload);
18889
18944
 
18890
18945
  if (chatterTokenCallback) {
18891
18946
  chatterTokenCallback(chatter);
18892
18947
  }
18893
18948
 
18949
+ await setState({
18950
+ chatterToken: chatter,
18951
+ chatterCreated: created,
18952
+ sessionToken
18953
+ });
18894
18954
  break;
18895
18955
  }
18896
18956
 
@@ -20746,7 +20806,7 @@ class Embed {
20746
20806
 
20747
20807
  }
20748
20808
 
20749
- _defineProperty(Embed, "embed2Version", "512664b");
20809
+ _defineProperty(Embed, "embed2Version", "29cbcb3");
20750
20810
  ;// CONCATENATED MODULE: ./src/common/helpers/startup.ts
20751
20811
 
20752
20812
 
@@ -0,0 +1,6 @@
1
+ declare type PersistenceKey = ("ada-embed_chat-manifest-cache" | "ada-embed_chat-assigned-version");
2
+ export declare const persistence: {
3
+ get: (item: PersistenceKey) => string;
4
+ set: (item: PersistenceKey, value: string) => void;
5
+ };
6
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ada-support/embed2",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "",
5
5
  "main": "dist/npm-entry",
6
6
  "typings": "dist/npm-entry/index-npm.d.ts",