@ada-support/embed2 1.3.0 → 1.3.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.
@@ -15811,7 +15811,7 @@ const client = new error_tracker_BrowserClient({
15811
15811
  },
15812
15812
 
15813
15813
  environment: "production",
15814
- release: "1.3.0-088e9f6",
15814
+ release: "1.3.3-00bd7ec",
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("088e9f6", "/index.html");
16435
+ return "".concat(host, "/embed/").concat(frameName, "/").concat("00bd7ec", "/index.html");
16436
16436
  }
16437
16437
 
16438
16438
  function constructQueryString(query) {
@@ -17998,6 +17998,23 @@ function retrieveStorage(key, client, privateMode) {
17998
17998
 
17999
17999
  return null;
18000
18000
  }
18001
+ ;// CONCATENATED MODULE: ./src/services/persistence/index.ts
18002
+ const persistence = {
18003
+ get: item => {
18004
+ try {
18005
+ return localStorage.getItem(item);
18006
+ } catch (e) {
18007
+ /* istanbul ignore next */
18008
+ return null;
18009
+ }
18010
+ },
18011
+ set: (item, value) => {
18012
+ try {
18013
+ localStorage.setItem(item, value);
18014
+ } catch (e) {// Do nothing
18015
+ }
18016
+ }
18017
+ };
18001
18018
  ;// CONCATENATED MODULE: ./src/services/chat-versioning/manifest.ts
18002
18019
 
18003
18020
  const CHAT_MANIFEST_PATH = "https://static.ada.support/chat-manifest.json";
@@ -18045,53 +18062,69 @@ const isManifest = input => {
18045
18062
  return true;
18046
18063
  };
18047
18064
  ;// 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
18065
 
18051
18066
 
18067
+ // Somewhat inefficient, but more than adequate shuffle algorithm for small arrays
18068
+
18069
+ const arrayShuffle = array => array.map(value => ({
18070
+ value,
18071
+ sort: Math.random()
18072
+ })).sort((a, b) => a.sort - b.sort).map(_ref => {
18073
+ let {
18074
+ value
18075
+ } = _ref;
18076
+ return value;
18077
+ });
18078
+
18052
18079
  const getChatVersionFromManifest = manifest => {
18053
18080
  /* istanbul ignore next */
18054
18081
  if (!isManifest(manifest)) {
18055
18082
  // This should never happen since isManifest throws an error for invalid input
18056
18083
  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
- // }
18084
+ }
18068
18085
 
18086
+ const manifestString = JSON.stringify(manifest);
18087
+ const manifestCache = persistence.get("ada-embed_chat-manifest-cache");
18088
+
18089
+ if (manifestString === manifestCache) {
18090
+ const assignedVersion = persistence.get("ada-embed_chat-assigned-version");
18091
+ /* istanbul ignore else */
18092
+
18093
+ if (assignedVersion) {
18094
+ return assignedVersion;
18095
+ }
18096
+ }
18069
18097
 
18070
18098
  const random = Math.random();
18071
18099
  const {
18072
18100
  versions
18073
- } = manifest; // Use hash from last version in array by default
18101
+ } = manifest;
18102
+ const shuffledVersions = arrayShuffle(versions); // Use hash from last version in array by default
18074
18103
 
18075
18104
  let {
18076
18105
  hash
18077
- } = versions[versions.length - 1]; // Loop through versions
18106
+ } = shuffledVersions[shuffledVersions.length - 1]; // Loop through shuffledVersions
18078
18107
 
18079
- for (let i = 0; i < versions.length; i += 1) {
18080
- const v = versions[i]; // If random falls into version weight
18108
+ for (let i = 0; i < shuffledVersions.length; i += 1) {
18109
+ const v = shuffledVersions[i]; // If random falls into version weight
18081
18110
 
18082
18111
  if (random <= v.weight) {
18083
18112
  hash = v.hash;
18084
18113
  break;
18085
18114
  }
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
-
18115
+ }
18090
18116
 
18117
+ persistence.set("ada-embed_chat-assigned-version", hash);
18118
+ persistence.set("ada-embed_chat-manifest-cache", manifestString);
18091
18119
  return hash;
18092
18120
  };
18093
18121
  const getChatVersion = async () => {
18094
18122
  const manifest = await loadChatManifest();
18123
+
18124
+ if (window.__AdaChatVersion) {
18125
+ return window.__AdaChatVersion;
18126
+ }
18127
+
18095
18128
  return getChatVersionFromManifest(manifest);
18096
18129
  };
18097
18130
  // EXTERNAL MODULE: ./node_modules/lodash.memoize/index.js
@@ -18137,9 +18170,9 @@ async function log(message, extra, options) {
18137
18170
  service: "embed",
18138
18171
  env: "production",
18139
18172
  embedVersion: 2,
18140
- version: "1.3.0",
18173
+ version: "1.3.3",
18141
18174
  isNpm: true,
18142
- commitHash: "088e9f6"
18175
+ commitHash: "00bd7ec"
18143
18176
  }))
18144
18177
  });
18145
18178
  }
@@ -18556,7 +18589,7 @@ class ChatFrame extends d {
18556
18589
  const hostPageUrlParams = new (url_default())(window.location.href).searchParams;
18557
18590
  const smsToken = hostPageUrlParams.get("adaSMSToken");
18558
18591
  const queryParams = {
18559
- embedVersion: "088e9f6".slice(0, 7),
18592
+ embedVersion: "00bd7ec".slice(0, 7),
18560
18593
  greeting,
18561
18594
  language,
18562
18595
  skipGreeting,
@@ -20746,7 +20779,7 @@ class Embed {
20746
20779
 
20747
20780
  }
20748
20781
 
20749
- _defineProperty(Embed, "embed2Version", "088e9f6");
20782
+ _defineProperty(Embed, "embed2Version", "00bd7ec");
20750
20783
  ;// CONCATENATED MODULE: ./src/common/helpers/startup.ts
20751
20784
 
20752
20785
 
@@ -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.0",
3
+ "version": "1.3.3",
4
4
  "description": "",
5
5
  "main": "dist/npm-entry",
6
6
  "typings": "dist/npm-entry/index-npm.d.ts",
@@ -13,7 +13,7 @@
13
13
  "build:npm": "./npm-build.sh",
14
14
  "lint": "tsc --noEmit --strict false && ./node_modules/.bin/eslint --report-unused-disable-directives --ext .js,.jsx,.ts,.tsx . --max-warnings 22",
15
15
  "lint:fix": "yarn lint --fix",
16
- "test": "jest",
16
+ "test": "jest --detectOpenHandles",
17
17
  "check-types": "./node_modules/typescript/bin/tsc --project ./tsconfig.json --noEmit --strict false",
18
18
  "check-types-strict": "./node_modules/typescript/bin/tsc --project ./tsconfig.json --noEmit",
19
19
  "tc": "export $(cat .env | xargs) && testcafe",