@ada-support/embed2 1.11.0 → 1.11.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.
@@ -15919,7 +15919,7 @@ const client = new BrowserClient({
15919
15919
  return event;
15920
15920
  },
15921
15921
  environment: "production",
15922
- release: "1.11.0-67295d0",
15922
+ release: "1.11.2-6ffecd9",
15923
15923
  sampleRate: 0.25,
15924
15924
  autoSessionTracking: false,
15925
15925
  // Integrations don't seem to work with Sentry: https://github.com/getsentry/sentry-javascript/issues/2541
@@ -16368,45 +16368,22 @@ let ActionTypes = /*#__PURE__*/function (ActionTypes) {
16368
16368
  ActionTypes["FOCUS_OFF_ADA_TYPE"] = "FOCUS_OFF_ADA";
16369
16369
  return ActionTypes;
16370
16370
  }({});
16371
- ;// CONCATENATED MODULE: ./src/client/helpers/event-subscriptions/index.ts
16372
- let subscriptions = [];
16373
- const getNextUniqueId = (() => {
16374
- let lastId = 0;
16375
- return () => {
16376
- lastId += 1;
16377
- return lastId;
16378
- };
16379
- })();
16380
- function unsubscribeEvent(id) {
16381
- subscriptions = subscriptions.filter(s => s.id !== id);
16382
- }
16383
- function subscribeEvent(eventKey, callback) {
16384
- const id = getNextUniqueId();
16385
- subscriptions.push({
16386
- eventKey,
16387
- callback,
16388
- id
16389
- });
16390
- return id;
16391
- }
16392
- function publishEvent(eventKey, data) {
16393
- subscriptions.forEach(subscription => {
16394
- // Using startsWith instead of === allows subscribing to a specific event OR a namespace,
16395
- // e.g. ada:campaigns subscribes to ada:campaigns:opened, ada:campaigns:engaged, and
16396
- // ada:campaigns:shown. Broadcasting this way simultaneously reaches subscriptions
16397
- // that have subscribed to a specific event, and those that have subscribed to a namespace
16398
- if (eventKey.startsWith(subscription.eventKey)) {
16399
- // try/catch to guard against missing or bad callbacks
16400
- try {
16401
- subscription.callback(data, {
16402
- eventKey
16403
- });
16404
- } catch {
16405
- // silently fail and proceed with remaining callbacks
16406
- }
16407
- }
16408
- });
16371
+ ;// CONCATENATED MODULE: ./src/services/helpers.ts
16372
+ const NO_OP_FUNCTION = () => {
16373
+ // Do nothing
16374
+ };
16375
+ function isStartOptions(input) {
16376
+ if (!(typeof input === "object")) {
16377
+ return false;
16378
+ }
16379
+ if (input === null) {
16380
+ return false;
16381
+ }
16382
+ return typeof input.handle === "string";
16409
16383
  }
16384
+ // EXTERNAL MODULE: ./node_modules/lodash.memoize/index.js
16385
+ var lodash_memoize = __webpack_require__(7654);
16386
+ var lodash_memoize_default = /*#__PURE__*/__webpack_require__.n(lodash_memoize);
16410
16387
  ;// CONCATENATED MODULE: ./src/common/helpers/http.ts
16411
16388
  /**
16412
16389
  * Vanilla HTTP request. Returns a Promise.
@@ -16451,6 +16428,102 @@ function httpRequest(obj) {
16451
16428
  xhr.send(obj.body);
16452
16429
  });
16453
16430
  }
16431
+ ;// CONCATENATED MODULE: ./src/services/logger/index.ts
16432
+
16433
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16434
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16435
+
16436
+
16437
+ const DEFAULT_LOG_SAMPLE_RATE = 0.01;
16438
+ const DD_BASE_URL = "https://browser-http-intake.logs.datadoghq.com/v1/input/";
16439
+ const DD_TOKEN = "pubfe23baedd2ea322bebb5ed2020fa2fa1";
16440
+
16441
+ // We need memoization to ensure consistency of logs
16442
+ const shouldLog = lodash_memoize_default()(sampleRate => {
16443
+ if (!DD_TOKEN || sampleRate === 0) {
16444
+ return false;
16445
+ }
16446
+ return Math.random() < (sampleRate || DEFAULT_LOG_SAMPLE_RATE);
16447
+ });
16448
+
16449
+ /**
16450
+ * Sends log to Datadog
16451
+ */
16452
+ async function log(message, extra, options) {
16453
+ if (!shouldLog(options === null || options === void 0 ? void 0 : options.sampleRate)) {
16454
+ return;
16455
+ }
16456
+ await httpRequest({
16457
+ url: `${DD_BASE_URL}${DD_TOKEN}?ddsource=browser&ddtags=version:1.5.0,env:${"production"}`,
16458
+ method: "POST",
16459
+ body: JSON.stringify(_objectSpread(_objectSpread({
16460
+ message
16461
+ }, extra), {}, {
16462
+ level: (options === null || options === void 0 ? void 0 : options.level) || "info",
16463
+ sampleRate: (options === null || options === void 0 ? void 0 : options.sampleRate) || DEFAULT_LOG_SAMPLE_RATE,
16464
+ service: "embed",
16465
+ env: "production",
16466
+ embedVersion: 2,
16467
+ version: "1.11.2",
16468
+ isNpm: true,
16469
+ commitHash: "6ffecd9"
16470
+ }))
16471
+ });
16472
+ }
16473
+ ;// CONCATENATED MODULE: ./src/client/helpers/event-subscriptions/index.ts
16474
+
16475
+
16476
+ let subscriptions = [];
16477
+ const getNextUniqueId = (() => {
16478
+ let lastId = 0;
16479
+ return () => {
16480
+ lastId += 1;
16481
+ return lastId;
16482
+ };
16483
+ })();
16484
+ function unsubscribeEvent(id) {
16485
+ subscriptions = subscriptions.filter(s => s.id !== id);
16486
+ }
16487
+ function subscribeEvent(eventKey, callback) {
16488
+ const id = getNextUniqueId();
16489
+
16490
+ // Log chat_frame_timeout event subscriptions
16491
+ if (eventKey === "ada:chat_frame_timeout") {
16492
+ var _document$getElementB;
16493
+ const domHandle = (_document$getElementB = document.getElementById("__ada")) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.getAttribute("data-handle");
16494
+ log("Client subscribed to chat_frame_timeout event", {
16495
+ handle: domHandle || (isStartOptions(window.adaSettings) ? window.adaSettings.handle : undefined),
16496
+ hostPage: window.location.href
16497
+ }, {
16498
+ sampleRate: 0.1,
16499
+ level: "info"
16500
+ });
16501
+ }
16502
+ subscriptions.push({
16503
+ eventKey,
16504
+ callback,
16505
+ id
16506
+ });
16507
+ return id;
16508
+ }
16509
+ function publishEvent(eventKey, data) {
16510
+ subscriptions.forEach(subscription => {
16511
+ // Using startsWith instead of === allows subscribing to a specific event OR a namespace,
16512
+ // e.g. ada:campaigns subscribes to ada:campaigns:opened, ada:campaigns:engaged, and
16513
+ // ada:campaigns:shown. Broadcasting this way simultaneously reaches subscriptions
16514
+ // that have subscribed to a specific event, and those that have subscribed to a namespace
16515
+ if (eventKey.startsWith(subscription.eventKey)) {
16516
+ // try/catch to guard against missing or bad callbacks
16517
+ try {
16518
+ subscription.callback(data, {
16519
+ eventKey
16520
+ });
16521
+ } catch {
16522
+ // silently fail and proceed with remaining callbacks
16523
+ }
16524
+ }
16525
+ });
16526
+ }
16454
16527
  ;// CONCATENATED MODULE: ./src/common/helpers/config-info.ts
16455
16528
  const isProduction = "production" === "production";
16456
16529
  ;// CONCATENATED MODULE: ./src/common/helpers/url/constants.ts
@@ -16468,8 +16541,8 @@ const ports = {
16468
16541
  };
16469
16542
  ;// CONCATENATED MODULE: ./src/common/helpers/url/index.ts
16470
16543
 
16471
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16472
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16544
+ function url_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16545
+ function url_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? url_ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : url_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16473
16546
 
16474
16547
 
16475
16548
  const DEFAULT_ADA_DOMAIN = "ada";
@@ -16496,7 +16569,7 @@ function getEmbedURL(_ref) {
16496
16569
  } else {
16497
16570
  host = `http://${handle}.localhost:9001`;
16498
16571
  }
16499
- return `${host}/embed/${frameName}/${"67295d0"}/index.html`;
16572
+ return `${host}/embed/${frameName}/${"6ffecd9"}/index.html`;
16500
16573
  }
16501
16574
  function constructQueryString(query) {
16502
16575
  return Object.keys(query).map(key => {
@@ -16544,7 +16617,7 @@ function getChatURL(_ref3) {
16544
16617
  domain,
16545
16618
  qp
16546
16619
  } = _ref3;
16547
- const queryParams = _objectSpread(_objectSpread({}, qp), {}, {
16620
+ const queryParams = url_objectSpread(url_objectSpread({}, qp), {}, {
16548
16621
  version
16549
16622
  });
16550
16623
  const queryString = constructQueryString(queryParams);
@@ -17303,19 +17376,6 @@ const get_browser_language_getBrowserLanguage = () => {
17303
17376
  return browserLanguageString;
17304
17377
  };
17305
17378
  /* harmony default export */ var get_browser_language = (get_browser_language_getBrowserLanguage);
17306
- ;// CONCATENATED MODULE: ./src/services/helpers.ts
17307
- const NO_OP_FUNCTION = () => {
17308
- // Do nothing
17309
- };
17310
- function isStartOptions(input) {
17311
- if (!(typeof input === "object")) {
17312
- return false;
17313
- }
17314
- if (input === null) {
17315
- return false;
17316
- }
17317
- return typeof input.handle === "string";
17318
- }
17319
17379
  ;// CONCATENATED MODULE: ./src/campaigns/campaign.ts
17320
17380
 
17321
17381
  function campaign_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -17638,51 +17698,6 @@ function getButtonText(client) {
17638
17698
  }
17639
17699
  return buttonTextMap[languageKey];
17640
17700
  }
17641
- // EXTERNAL MODULE: ./node_modules/lodash.memoize/index.js
17642
- var lodash_memoize = __webpack_require__(7654);
17643
- var lodash_memoize_default = /*#__PURE__*/__webpack_require__.n(lodash_memoize);
17644
- ;// CONCATENATED MODULE: ./src/services/logger/index.ts
17645
-
17646
- function logger_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17647
- function logger_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? logger_ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : logger_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17648
-
17649
-
17650
- const DEFAULT_LOG_SAMPLE_RATE = 0.01; // 1% of logs will go through
17651
-
17652
- const DD_BASE_URL = "https://browser-http-intake.logs.datadoghq.com/v1/input/";
17653
- const DD_TOKEN = "pubfe23baedd2ea322bebb5ed2020fa2fa1";
17654
-
17655
- // We need memoization to ensure consistency of logs
17656
- const shouldLog = lodash_memoize_default()(sampleRate => {
17657
- if (!DD_TOKEN || sampleRate === 0) {
17658
- return false;
17659
- }
17660
- return Math.random() < (sampleRate || DEFAULT_LOG_SAMPLE_RATE);
17661
- });
17662
-
17663
- /**
17664
- * Sends log to Datadog
17665
- */
17666
- async function log(message, extra, options) {
17667
- if (!shouldLog(options === null || options === void 0 ? void 0 : options.sampleRate)) {
17668
- return;
17669
- }
17670
- await httpRequest({
17671
- url: `${DD_BASE_URL}${DD_TOKEN}?ddsource=browser&ddtags=version:1.5.0,env:${"production"}`,
17672
- method: "POST",
17673
- body: JSON.stringify(logger_objectSpread(logger_objectSpread({
17674
- message
17675
- }, extra), {}, {
17676
- sampleRate: (options === null || options === void 0 ? void 0 : options.sampleRate) || DEFAULT_LOG_SAMPLE_RATE,
17677
- service: "embed",
17678
- env: "production",
17679
- embedVersion: 2,
17680
- version: "1.11.0",
17681
- isNpm: true,
17682
- commitHash: "67295d0"
17683
- }))
17684
- });
17685
- }
17686
17701
  ;// CONCATENATED MODULE: ./src/client/helpers/alternative-bot-rollout/index.ts
17687
17702
 
17688
17703
  function alternative_bot_rollout_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -18334,12 +18349,26 @@ const CHAT_MANIFEST_PATH = "https://static.ada.support/chat-manifest.json";
18334
18349
  const loadChatManifest = async () => {
18335
18350
  try {
18336
18351
  const r = await fetch(CHAT_MANIFEST_PATH);
18352
+ if (!r.ok) {
18353
+ log(`Failed to load chat manifest - HTTP ${r.status}`, {
18354
+ hostPage: window.location.href,
18355
+ manifestUrl: CHAT_MANIFEST_PATH
18356
+ }, {
18357
+ level: "error",
18358
+ sampleRate: 1.0
18359
+ });
18360
+ return undefined;
18361
+ }
18337
18362
  return r.json();
18338
18363
  } catch (e) {
18339
18364
  // handling cases where r is undefined / other fetch errors
18340
18365
  // by returning undefined, we tell the server to load the unversioned index.html file for chat
18341
18366
  log("Failed to load chat manifest", {
18342
- hostPage: window.location.href
18367
+ hostPage: window.location.href,
18368
+ manifestUrl: CHAT_MANIFEST_PATH
18369
+ }, {
18370
+ level: "error",
18371
+ sampleRate: 1.0
18343
18372
  });
18344
18373
  return undefined;
18345
18374
  }
@@ -18930,6 +18959,8 @@ class ChatFrame extends d {
18930
18959
  // We use this log to track number of chat impressions (times when users see chat iFrame render first time).
18931
18960
  log("Chat frame mount", {
18932
18961
  handle,
18962
+ chatUrl: this.url,
18963
+ embedVersion: "6ffecd9".slice(0, 7),
18933
18964
  embedSettings: adaSettings
18934
18965
  });
18935
18966
 
@@ -19013,7 +19044,7 @@ class ChatFrame extends d {
19013
19044
  const hostPageUrlParams = new URL(window.location.href).searchParams;
19014
19045
  const smsToken = hostPageUrlParams.get("adaSMSToken");
19015
19046
  const queryParams = {
19016
- embedVersion: "67295d0".slice(0, 7),
19047
+ embedVersion: "6ffecd9".slice(0, 7),
19017
19048
  greeting,
19018
19049
  language,
19019
19050
  skipGreeting,
@@ -19615,6 +19646,15 @@ class ChatFrame extends d {
19615
19646
  this.clearFallbackTimeout();
19616
19647
  this.chatRenderTimeout = window.setTimeout(() => {
19617
19648
  var _this$channel;
19649
+ log(`Chat frame took over ${CHAT_FALLBACK_DELAY_MS / 1000} seconds to respond`, {
19650
+ handle,
19651
+ chatUrl: this.url,
19652
+ embedVersion: "6ffecd9".slice(0, 7),
19653
+ embedSettings: adaSettings
19654
+ }, {
19655
+ level: "error",
19656
+ sampleRate: 1.0
19657
+ });
19618
19658
  const {
19619
19659
  isDrawerOpen: drawerIsOpen
19620
19660
  } = this.props;
@@ -5,4 +5,5 @@ export declare const shouldLog: ((sampleRate?: number) => boolean) & import("lod
5
5
  */
6
6
  export declare function log(message: string, extra?: Record<string, unknown>, options?: {
7
7
  sampleRate?: number;
8
+ level?: "error" | "warn" | "info" | "debug";
8
9
  }): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ada-support/embed2",
3
- "version": "1.11.0",
3
+ "version": "1.11.2",
4
4
  "description": "",
5
5
  "main": "dist/npm-entry",
6
6
  "typings": "dist/npm-entry/index-npm.d.ts",