@ada-support/embed2 1.4.0 → 1.4.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.
@@ -4,7 +4,7 @@ import type { MessagePayload } from "common/types/events";
4
4
  import type { DirectDispatch } from "common/types/store";
5
5
  import type { StoreState } from "common/types/store-state";
6
6
  export declare const actions: {
7
- [key in ActionCreators]: ({ currentState, payload, dispatch }: {
7
+ [key in ActionCreators]: ({ currentState, payload, dispatch, }: {
8
8
  payload?: MessagePayload;
9
9
  currentState: StoreState;
10
10
  dispatch: DirectDispatch;
@@ -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;
@@ -63,8 +63,8 @@ export interface EmbedResponsePayloadByEvent {
63
63
  SET_DEVICE_TOKEN_RESPONSE: unknown;
64
64
  }
65
65
  export declare type EmbedResponseEvent = keyof EmbedResponsePayloadByEvent;
66
- export declare type EmbedEvent = (EmbedRequestEvent | EmbedResponseEvent);
67
- export declare type PayloadByEvent = (EmbedRequestPayloadByEvent & EmbedResponsePayloadByEvent);
66
+ export declare type EmbedEvent = EmbedRequestEvent | EmbedResponseEvent;
67
+ export declare type PayloadByEvent = EmbedRequestPayloadByEvent & EmbedResponsePayloadByEvent;
68
68
  export declare abstract class Channel {
69
69
  protected abstract trackedListeners: Set<Refhandler>;
70
70
  protected abstract trackedTimeouts: Set<number>;
@@ -18,10 +18,10 @@ export interface PublishEventPayload<K extends AdaEventKey> {
18
18
  eventKey: K;
19
19
  data: AdaEventDataKeyedByEvent[K];
20
20
  }
21
- export interface AdaCustomEvent<E extends (EmbedEvent | string) = string> {
21
+ export interface AdaCustomEvent<E extends EmbedEvent | string = string> {
22
22
  type: E;
23
23
  payload?: E extends keyof PayloadByEvent ? PayloadByEvent[E] : unknown;
24
24
  id?: string;
25
25
  status?: FetchEventStatusType;
26
26
  }
27
- export declare type Refhandler<E extends (EmbedRequestEvent | string) = string> = (handleEvent: MessageEvent | CustomEventInit<AdaCustomEvent<E>>) => void;
27
+ export declare type Refhandler<E extends EmbedRequestEvent | string = string> = (handleEvent: MessageEvent | CustomEventInit<AdaCustomEvent<E>>) => void;
@@ -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
  };
@@ -5,4 +5,4 @@ export declare const INTRO_IFRAME = "intro";
5
5
  export declare const BUTTON_IFRAME = "button";
6
6
  export declare const MASK_IFRAME = "drawer-mask";
7
7
  export declare const XSTORAGE_IFRAME = "x-storage";
8
- export declare type Module = (typeof CHAT_IFRAME | typeof ENTRY_SCRIPT | typeof EMBED_SCRIPT | typeof INTRO_IFRAME | typeof BUTTON_IFRAME | typeof MASK_IFRAME | typeof XSTORAGE_IFRAME);
8
+ export declare type Module = typeof CHAT_IFRAME | typeof ENTRY_SCRIPT | typeof EMBED_SCRIPT | typeof INTRO_IFRAME | typeof BUTTON_IFRAME | typeof MASK_IFRAME | typeof XSTORAGE_IFRAME;
@@ -14,10 +14,10 @@ export interface StorageValueByKey {
14
14
  [ZD_PREVIOUS_TAGS_STORAGE_KEY]: string;
15
15
  [ZD_MESSAGING_EXTERNAL_USER_ID_STORAGE_KEY]: string;
16
16
  [ZD_MESSAGING_CHATTER_CREATED_STORAGE_KEY]: string;
17
- "liveChatPending": boolean;
17
+ liveChatPending: boolean;
18
18
  "ada-embed_is-drawer-open": boolean;
19
19
  "[handle]_marketing_campaigns_shown": string;
20
- "test": string;
20
+ test: string;
21
21
  }
22
22
  export declare type StorageKey = keyof StorageValueByKey;
23
23
  /**
@@ -15811,7 +15811,7 @@ const client = new error_tracker_BrowserClient({
15811
15811
  },
15812
15812
 
15813
15813
  environment: "production",
15814
- release: "1.4.0-29cbcb3",
15814
+ release: "1.4.3-2730999",
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
@@ -16384,15 +16384,15 @@ function httpRequest(obj) {
16384
16384
  const isProduction = "production" === "production";
16385
16385
  ;// CONCATENATED MODULE: ./src/common/helpers/url/constants.ts
16386
16386
  const ports = {
16387
- "localhost": {
16388
- "api": 8000,
16389
- "chat": 8002,
16390
- "default": 9001
16387
+ localhost: {
16388
+ api: 8000,
16389
+ chat: 8002,
16390
+ default: 9001
16391
16391
  },
16392
- "e2ereference": {
16393
- "api": 8000,
16394
- "chat": 8002,
16395
- "default": 9001
16392
+ e2ereference: {
16393
+ api: 8000,
16394
+ chat: 8002,
16395
+ default: 9001
16396
16396
  }
16397
16397
  };
16398
16398
  ;// CONCATENATED MODULE: ./src/common/helpers/url/index.ts
@@ -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("29cbcb3", "/index.html");
16435
+ return "".concat(host, "/embed/").concat(frameName, "/").concat("2730999", "/index.html");
16436
16436
  }
16437
16437
 
16438
16438
  function constructQueryString(query) {
@@ -17266,8 +17266,104 @@ const getEventsToTrigger = businessEvents => {
17266
17266
  const eventsToTrigger = businessEvents.filter(businessEvent => businessEvent.trigger_conditions.some(triggerCondition => evalTriggerCondition(triggerCondition)));
17267
17267
  return eventsToTrigger;
17268
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
+ };
17269
17362
  ;// CONCATENATED MODULE: ./src/common/helpers/get-browser-language.ts
17363
+
17364
+
17270
17365
  const DEFAULT_LANGUAGE_CODE = "en";
17366
+ const SUPPORTED_LANGUAGES = [...Object.values(Languages)];
17271
17367
  /**
17272
17368
  * Gets a language code from the browser. Stolen from `chat` repo
17273
17369
  *
@@ -17282,7 +17378,29 @@ const DEFAULT_LANGUAGE_CODE = "en";
17282
17378
  * I'M SO SORRY.
17283
17379
  */
17284
17380
 
17285
- 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
+ };
17286
17404
 
17287
17405
  /* harmony default export */ var get_browser_language = (get_browser_language_getBrowserLanguage);
17288
17406
  ;// CONCATENATED MODULE: ./src/services/helpers.ts
@@ -17495,8 +17613,8 @@ const popStateListener = dispatchEvent.bind(undefined, "locationchange");
17495
17613
  */
17496
17614
 
17497
17615
  function bindLocationChangeOverrides() {
17498
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17499
- window.history.pushState = (f => function pushState() {
17616
+ window.history.pushState = (f => // eslint-disable-next-line @typescript-eslint/no-explicit-any
17617
+ function pushState() {
17500
17618
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
17501
17619
  args[_key] = arguments[_key];
17502
17620
  }
@@ -17505,10 +17623,10 @@ function bindLocationChangeOverrides() {
17505
17623
  dispatchEvent("pushstate");
17506
17624
  dispatchEvent("locationchange");
17507
17625
  return ret;
17508
- })(window.history.pushState); // eslint-disable-next-line @typescript-eslint/no-explicit-any
17509
-
17626
+ })(window.history.pushState);
17510
17627
 
17511
- window.history.replaceState = (f => function replaceState() {
17628
+ window.history.replaceState = (f => // eslint-disable-next-line @typescript-eslint/no-explicit-any
17629
+ function replaceState() {
17512
17630
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
17513
17631
  args[_key2] = arguments[_key2];
17514
17632
  }
@@ -18181,9 +18299,9 @@ async function log(message, extra, options) {
18181
18299
  service: "embed",
18182
18300
  env: "production",
18183
18301
  embedVersion: 2,
18184
- version: "1.4.0",
18302
+ version: "1.4.3",
18185
18303
  isNpm: true,
18186
- commitHash: "29cbcb3"
18304
+ commitHash: "2730999"
18187
18305
  }))
18188
18306
  });
18189
18307
  }
@@ -18411,7 +18529,7 @@ class ButtonFrame extends d {
18411
18529
  let styles = "\n position: fixed;\n bottom: ".concat(buttonPosition, "px;\n ").concat(getAlignment(adaSettings), ": ").concat(buttonPosition, "px;\n z-index: 10000;\n height: ").concat(buttonSizeWithBuffer, "px;\n width: ").concat(buttonSizeWithBuffer, "px;\n overflow: hidden;\n visibility: ").concat(this.isShown ? "visible" : "hidden", ";\n opacity: ").concat(this.isShown ? "1" : "0", ";\n transition: visibility 200ms ease, opacity 200ms ease;\n ");
18412
18530
 
18413
18531
  if (client.features.chat_ui_v2) {
18414
- styles += "\n transform: translate(0, 10%);\n transition: visibility 250ms ease, opacity 250ms ease, transform 250ms ease;\n ".concat(getAlignment(adaSettings), ": 0;\n bottom: 0;\n \n ").concat(this.isShown ? "transform: translate(0, 0);" : "", "\n ");
18532
+ styles += "\n transform: translate(0, 10%);\n transition: visibility 250ms ease, opacity 250ms ease, transform 250ms ease;\n ".concat(getAlignment(adaSettings), ": 0;\n bottom: 0;\n\n ").concat(this.isShown ? "transform: translate(0, 0);" : "", "\n ");
18415
18533
 
18416
18534
  if (buttonStyle === "text") {
18417
18535
  styles += "\n width: ".concat(frameWidth, "px;\n height: ").concat(textFrameHeight, "px;\n ");
@@ -18625,7 +18743,7 @@ class ChatFrame extends d {
18625
18743
  const hostPageUrlParams = new (url_default())(window.location.href).searchParams;
18626
18744
  const smsToken = hostPageUrlParams.get("adaSMSToken");
18627
18745
  const queryParams = {
18628
- embedVersion: "29cbcb3".slice(0, 7),
18746
+ embedVersion: "2730999".slice(0, 7),
18629
18747
  greeting,
18630
18748
  language,
18631
18749
  skipGreeting,
@@ -18883,7 +19001,7 @@ class ChatFrame extends d {
18883
19001
  clearTimeout(this.chatRenderTimeout);
18884
19002
  this.channel.isConnected = true;
18885
19003
  setConnectionState({
18886
- "chat": ConnectionState.Done
19004
+ chat: ConnectionState.Done
18887
19005
  });
18888
19006
  break;
18889
19007
  }
@@ -20806,7 +20924,7 @@ class Embed {
20806
20924
 
20807
20925
  }
20808
20926
 
20809
- _defineProperty(Embed, "embed2Version", "29cbcb3");
20927
+ _defineProperty(Embed, "embed2Version", "2730999");
20810
20928
  ;// CONCATENATED MODULE: ./src/common/helpers/startup.ts
20811
20929
 
20812
20930
 
@@ -1,4 +1,4 @@
1
- declare type PersistenceKey = ("ada-embed_chat-manifest-cache" | "ada-embed_chat-assigned-version");
1
+ declare type PersistenceKey = "ada-embed_chat-manifest-cache" | "ada-embed_chat-assigned-version";
2
2
  export declare const persistence: {
3
3
  get: (item: PersistenceKey) => string;
4
4
  set: (item: PersistenceKey, value: string) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ada-support/embed2",
3
- "version": "1.4.0",
3
+ "version": "1.4.3",
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",