@ada-support/embed2 1.3.3 → 1.4.2

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";
@@ -1,3 +1,4 @@
1
+ import type { LanguageKey } from "common/types/languages";
1
2
  /**
2
3
  * Gets a language code from the browser. Stolen from `chat` repo
3
4
  *
@@ -11,5 +12,6 @@
11
12
  *
12
13
  * I'M SO SORRY.
13
14
  */
14
- declare const getBrowserLanguage: () => string;
15
+ export declare function isSupportedLanguageCode(languageCode: string): boolean;
16
+ declare const getBrowserLanguage: () => LanguageKey;
15
17
  export default getBrowserLanguage;
@@ -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;
@@ -1,4 +1,51 @@
1
- export declare type LanguageKey = "en" | "da" | "de" | "es" | "fi" | "fr" | "hi" | "ht" | "id" | "it" | "ja" | "km" | "ko" | "ms" | "my" | "no" | "nl" | "pa" | "pt" | "ru" | "sv" | "ta" | "th" | "tl" | "tr" | "vi" | "zh" | "zh-tw" | "bg" | "ro" | "el" | "hu" | "pl" | "cs" | "et" | "hr" | "lt" | "lv" | "sl" | "sk" | "is" | "ar" | "he";
1
+ export declare const Languages: {
2
+ readonly en: "en";
3
+ readonly be: "be";
4
+ readonly da: "da";
5
+ readonly de: "de";
6
+ readonly es: "es";
7
+ readonly fi: "fi";
8
+ readonly fr: "fr";
9
+ readonly hi: "hi";
10
+ readonly ht: "ht";
11
+ readonly id: "id";
12
+ readonly it: "it";
13
+ readonly ja: "ja";
14
+ readonly km: "km";
15
+ readonly ko: "ko";
16
+ readonly ms: "ms";
17
+ readonly my: "my";
18
+ readonly no: "no";
19
+ readonly nl: "nl";
20
+ readonly pa: "pa";
21
+ readonly pt: "pt";
22
+ readonly ru: "ru";
23
+ readonly sv: "sv";
24
+ readonly ta: "ta";
25
+ readonly th: "th";
26
+ readonly tl: "tl";
27
+ readonly tr: "tr";
28
+ readonly uk: "uk";
29
+ readonly vi: "vi";
30
+ readonly zh: "zh";
31
+ readonly "zh-tw": "zh-tw";
32
+ readonly bg: "bg";
33
+ readonly ro: "ro";
34
+ readonly el: "el";
35
+ readonly hu: "hu";
36
+ readonly pl: "pl";
37
+ readonly cs: "cs";
38
+ readonly et: "et";
39
+ readonly hr: "hr";
40
+ readonly lt: "lt";
41
+ readonly lv: "lv";
42
+ readonly sl: "sl";
43
+ readonly sk: "sk";
44
+ readonly is: "is";
45
+ readonly ar: "ar";
46
+ readonly he: "he";
47
+ };
48
+ export declare type LanguageKey = keyof typeof Languages;
2
49
  export declare type LanguageMap = {
3
50
  [K in LanguageKey]?: string;
4
51
  };
@@ -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.3-00bd7ec",
15814
+ release: "1.4.2-7dfe147",
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("00bd7ec", "/index.html");
16435
+ return "".concat(host, "/embed/").concat(frameName, "/").concat("7dfe147", "/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,
@@ -17264,8 +17266,104 @@ const getEventsToTrigger = businessEvents => {
17264
17266
  const eventsToTrigger = businessEvents.filter(businessEvent => businessEvent.trigger_conditions.some(triggerCondition => evalTriggerCondition(triggerCondition)));
17265
17267
  return eventsToTrigger;
17266
17268
  };
17269
+ ;// CONCATENATED MODULE: ./src/common/types/languages.ts
17270
+ const Languages = {
17271
+ en: "en",
17272
+ // English
17273
+ be: "be",
17274
+ // Belarusian
17275
+ da: "da",
17276
+ // Danish
17277
+ de: "de",
17278
+ // German
17279
+ es: "es",
17280
+ // Spanish
17281
+ fi: "fi",
17282
+ // Finnish
17283
+ fr: "fr",
17284
+ // French
17285
+ hi: "hi",
17286
+ // Hindi
17287
+ ht: "ht",
17288
+ // Haitian Creole
17289
+ id: "id",
17290
+ // Indonesian
17291
+ it: "it",
17292
+ // Italian
17293
+ ja: "ja",
17294
+ // Japanese
17295
+ km: "km",
17296
+ // Khmer
17297
+ ko: "ko",
17298
+ // Korean
17299
+ ms: "ms",
17300
+ // Malay
17301
+ my: "my",
17302
+ // Burmese
17303
+ no: "no",
17304
+ // Norwegian
17305
+ nl: "nl",
17306
+ // Dutch
17307
+ pa: "pa",
17308
+ // Punjabi
17309
+ pt: "pt",
17310
+ // Portuguese
17311
+ ru: "ru",
17312
+ // Russian
17313
+ sv: "sv",
17314
+ // Swedish
17315
+ ta: "ta",
17316
+ // Tamil
17317
+ th: "th",
17318
+ // Thai
17319
+ tl: "tl",
17320
+ // Tagalog
17321
+ tr: "tr",
17322
+ // Turkish
17323
+ uk: "uk",
17324
+ // Ukrainian
17325
+ vi: "vi",
17326
+ // Vietnamese
17327
+ zh: "zh",
17328
+ // Chinese simplified
17329
+ "zh-tw": "zh-tw",
17330
+ // Chinese traditional
17331
+ bg: "bg",
17332
+ // Bulgarian
17333
+ ro: "ro",
17334
+ // Romanian
17335
+ el: "el",
17336
+ // Greek
17337
+ hu: "hu",
17338
+ // Hungarian
17339
+ pl: "pl",
17340
+ // Polish
17341
+ cs: "cs",
17342
+ // Czech
17343
+ et: "et",
17344
+ // Estonian
17345
+ hr: "hr",
17346
+ // Croatian
17347
+ lt: "lt",
17348
+ // Lithuanian
17349
+ lv: "lv",
17350
+ // Latvian
17351
+ sl: "sl",
17352
+ // Slovenian
17353
+ sk: "sk",
17354
+ // Slovak
17355
+ is: "is",
17356
+ // Icelandic
17357
+ ar: "ar",
17358
+ // Arabic
17359
+ he: "he" // Hebrew
17360
+
17361
+ };
17267
17362
  ;// CONCATENATED MODULE: ./src/common/helpers/get-browser-language.ts
17363
+
17364
+
17268
17365
  const DEFAULT_LANGUAGE_CODE = "en";
17366
+ const SUPPORTED_LANGUAGES = [...Object.values(Languages)];
17269
17367
  /**
17270
17368
  * Gets a language code from the browser. Stolen from `chat` repo
17271
17369
  *
@@ -17280,7 +17378,29 @@ const DEFAULT_LANGUAGE_CODE = "en";
17280
17378
  * I'M SO SORRY.
17281
17379
  */
17282
17380
 
17283
- const get_browser_language_getBrowserLanguage = () => (navigator.languages && navigator.languages[0] || navigator.language || navigator.userLanguage || navigator.browserLanguage || navigator.systemLanguage || DEFAULT_LANGUAGE_CODE).split("-")[0];
17381
+ function isSupportedLanguageCode(languageCode) {
17382
+ return includes_default()(SUPPORTED_LANGUAGES).call(SUPPORTED_LANGUAGES, languageCode);
17383
+ }
17384
+
17385
+ const get_browser_language_getBrowserLanguage = () => {
17386
+ const browserLanguageString = (navigator.languages && navigator.languages[0] || navigator.language || navigator.userLanguage || navigator.browserLanguage || navigator.systemLanguage || DEFAULT_LANGUAGE_CODE).toLowerCase();
17387
+
17388
+ if (isSupportedLanguageCode(browserLanguageString)) {
17389
+ return browserLanguageString;
17390
+ }
17391
+
17392
+ if (includes_default()(browserLanguageString).call(browserLanguageString, "-")) {
17393
+ // an unsupported, hyphenated language code was received so return the main locale
17394
+ // if it is supported
17395
+ const mainLocale = browserLanguageString.split("-")[0];
17396
+
17397
+ if (isSupportedLanguageCode(mainLocale)) {
17398
+ return mainLocale;
17399
+ }
17400
+ }
17401
+
17402
+ return browserLanguageString;
17403
+ };
17284
17404
 
17285
17405
  /* harmony default export */ var get_browser_language = (get_browser_language_getBrowserLanguage);
17286
17406
  ;// CONCATENATED MODULE: ./src/services/helpers.ts
@@ -17998,6 +18118,15 @@ function retrieveStorage(key, client, privateMode) {
17998
18118
 
17999
18119
  return null;
18000
18120
  }
18121
+ function setBrowserStorageItem(key, value, persistenceSetting) {
18122
+ if (persistenceSetting === PERSISTENCE_NORMAL) {
18123
+ safeLocalStorage.setItem(key, value);
18124
+ }
18125
+
18126
+ if (persistenceSetting === PERSISTENCE_SESSION) {
18127
+ safeSessionStorage.setItem(key, value);
18128
+ }
18129
+ }
18001
18130
  ;// CONCATENATED MODULE: ./src/services/persistence/index.ts
18002
18131
  const persistence = {
18003
18132
  get: item => {
@@ -18170,9 +18299,9 @@ async function log(message, extra, options) {
18170
18299
  service: "embed",
18171
18300
  env: "production",
18172
18301
  embedVersion: 2,
18173
- version: "1.3.3",
18302
+ version: "1.4.2",
18174
18303
  isNpm: true,
18175
- commitHash: "00bd7ec"
18304
+ commitHash: "7dfe147"
18176
18305
  }))
18177
18306
  });
18178
18307
  }
@@ -18468,6 +18597,30 @@ function ButtonFrame_mapStateToProps(storeState) {
18468
18597
  const ANIMATION_DELAY = 50;
18469
18598
  ;// CONCATENATED MODULE: ./src/common/helpers/is-mobile.ts
18470
18599
  const isMobile = /(iPhone)|(iPod)|(android)|(webOS)/i.exec(navigator.userAgent) !== null;
18600
+ ;// CONCATENATED MODULE: ./src/client/components/ChatFrame/chatFrameEvents/chatterEvent/index.ts
18601
+
18602
+
18603
+ function storeChatterEventDataInBrowser(client, payload) {
18604
+ const {
18605
+ persistence,
18606
+ features
18607
+ } = client; // TODO: CHATX-1618 please remove the line below - the ff won't be needed anymore
18608
+
18609
+ const isChatSessionAuthEnabled = features.chat_session_auth;
18610
+ const {
18611
+ chatter,
18612
+ created,
18613
+ sessionToken
18614
+ } = payload;
18615
+ setBrowserStorageItem(CHATTER_STORAGE_KEY, chatter, persistence);
18616
+ 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
18617
+
18618
+ if (isChatSessionAuthEnabled && Boolean(sessionToken)) {
18619
+ setBrowserStorageItem(SESSION_AUTH_TOKEN_STORAGE_KEY, sessionToken, persistence);
18620
+ }
18621
+ }
18622
+ ;// CONCATENATED MODULE: ./src/client/components/ChatFrame/chatFrameEvents/index.ts
18623
+
18471
18624
  ;// CONCATENATED MODULE: ./src/client/components/ChatFrame/index.tsx
18472
18625
 
18473
18626
 
@@ -18486,6 +18639,7 @@ const isMobile = /(iPhone)|(iPod)|(android)|(webOS)/i.exec(navigator.userAgent)
18486
18639
 
18487
18640
 
18488
18641
 
18642
+
18489
18643
  class ChatFrame extends d {
18490
18644
  constructor() {
18491
18645
  super(...arguments);
@@ -18589,7 +18743,7 @@ class ChatFrame extends d {
18589
18743
  const hostPageUrlParams = new (url_default())(window.location.href).searchParams;
18590
18744
  const smsToken = hostPageUrlParams.get("adaSMSToken");
18591
18745
  const queryParams = {
18592
- embedVersion: "00bd7ec".slice(0, 7),
18746
+ embedVersion: "7dfe147".slice(0, 7),
18593
18747
  greeting,
18594
18748
  language,
18595
18749
  skipGreeting,
@@ -18893,7 +19047,8 @@ class ChatFrame extends d {
18893
19047
  } = this.props;
18894
19048
  const {
18895
19049
  chatter,
18896
- created
19050
+ created,
19051
+ sessionToken
18897
19052
  } = payload;
18898
19053
  const {
18899
19054
  chatterTokenCallback
@@ -18903,27 +19058,17 @@ class ChatFrame extends d {
18903
19058
  throw new AdaEmbedError("`client` is undefined");
18904
19059
  }
18905
19060
 
18906
- await setState({
18907
- chatterToken: chatter,
18908
- chatterCreated: created
18909
- });
18910
- /**
18911
- * Store the token so when embed loads in the future, it doesn't have to wait for it to
18912
- * come from chat. This is important for campaign and business event triggers.
18913
- */
18914
-
18915
- if (client.persistence === PERSISTENCE_NORMAL) {
18916
- safeLocalStorage.setItem(CHATTER_STORAGE_KEY, chatter);
18917
- safeLocalStorage.setItem(CHATTER_CREATED_STORAGE_KEY, created);
18918
- } else if (client.persistence === PERSISTENCE_SESSION) {
18919
- safeSessionStorage.setItem(CHATTER_STORAGE_KEY, chatter);
18920
- safeSessionStorage.setItem(CHATTER_CREATED_STORAGE_KEY, created);
18921
- }
19061
+ storeChatterEventDataInBrowser(client, payload);
18922
19062
 
18923
19063
  if (chatterTokenCallback) {
18924
19064
  chatterTokenCallback(chatter);
18925
19065
  }
18926
19066
 
19067
+ await setState({
19068
+ chatterToken: chatter,
19069
+ chatterCreated: created,
19070
+ sessionToken
19071
+ });
18927
19072
  break;
18928
19073
  }
18929
19074
 
@@ -20779,7 +20924,7 @@ class Embed {
20779
20924
 
20780
20925
  }
20781
20926
 
20782
- _defineProperty(Embed, "embed2Version", "00bd7ec");
20927
+ _defineProperty(Embed, "embed2Version", "7dfe147");
20783
20928
  ;// CONCATENATED MODULE: ./src/common/helpers/startup.ts
20784
20929
 
20785
20930
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ada-support/embed2",
3
- "version": "1.3.3",
3
+ "version": "1.4.2",
4
4
  "description": "",
5
5
  "main": "dist/npm-entry",
6
6
  "typings": "dist/npm-entry/index-npm.d.ts",
@@ -73,6 +73,7 @@
73
73
  "lint-staged": "^11.2.3",
74
74
  "mock-xmlhttprequest": "^7.0.4",
75
75
  "npm-run-all": "^4.1.5",
76
+ "prettier": "2.7.1",
76
77
  "start-server-and-test": "^1.14.0",
77
78
  "testcafe": "^1.18.4",
78
79
  "testcafe-browser-provider-lambdatest": "^2.0.18",
@@ -97,6 +98,7 @@
97
98
  "babel-loader": "^8.2.3",
98
99
  "babel-preset-preact": "^2.0.0",
99
100
  "dotenv": "^8.2.0",
101
+ "eslint-config-prettier": "^8.5.0",
100
102
  "focus-visible": "^5.2.0",
101
103
  "html-webpack-plugin": "^5.5.0",
102
104
  "json-stable-stringify": "^1.0.1",