@ada-support/embed2 1.7.29 → 1.7.32

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.
@@ -8,6 +8,7 @@ export interface EmbedRequestPayloadByEvent {
8
8
  CREATE_PROACTIVE: {
9
9
  body: string;
10
10
  duration: number | null;
11
+ delay?: number;
11
12
  responseId?: string | null;
12
13
  };
13
14
  DELETE_HISTORY: undefined;
@@ -13949,7 +13949,7 @@ const client = new BrowserClient({
13949
13949
  return event;
13950
13950
  },
13951
13951
  environment: "production",
13952
- release: "1.7.29-6752092",
13952
+ release: "1.7.32-26543c8",
13953
13953
  sampleRate: 0.25,
13954
13954
  autoSessionTracking: false,
13955
13955
  // Integrations don't seem to work with Sentry: https://github.com/getsentry/sentry-javascript/issues/2541
@@ -14523,7 +14523,7 @@ function getEmbedURL(_ref) {
14523
14523
  } else {
14524
14524
  host = `http://${handle}.localhost:9001`;
14525
14525
  }
14526
- return `${host}/embed/${frameName}/${"6752092"}/index.html`;
14526
+ return `${host}/embed/${frameName}/${"26543c8"}/index.html`;
14527
14527
  }
14528
14528
  function constructQueryString(query) {
14529
14529
  return Object.keys(query).map(key => {
@@ -14928,7 +14928,7 @@ class StoreProxy {
14928
14928
  }
14929
14929
  }
14930
14930
  ;// CONCATENATED MODULE: ./src/client/helpers/local-notifications/index.ts
14931
- const browserHasNotificationSupport = ("Notification" in window);
14931
+ const browserHasNotificationSupport = "Notification" in window;
14932
14932
  function checkIfUserHasGivenPermission() {
14933
14933
  if (!browserHasNotificationSupport) {
14934
14934
  return false;
@@ -15467,7 +15467,6 @@ function triggerCampaignImpl(_ref) {
15467
15467
  }).catch(NO_OP_FUNCTION); // we don't want to log errors here, it may fail because of rate limiting
15468
15468
  }
15469
15469
  }
15470
-
15471
15470
  const getCampaignToTrigger = (adaSettings, marketingCampaigns, options, onlyBasic) => {
15472
15471
  const {
15473
15472
  ignoreStatus = false,
@@ -15702,9 +15701,9 @@ async function log(message, extra, options) {
15702
15701
  service: "embed",
15703
15702
  env: "production",
15704
15703
  embedVersion: 2,
15705
- version: "1.7.29",
15704
+ version: "1.7.32",
15706
15705
  isNpm: true,
15707
- commitHash: "6752092"
15706
+ commitHash: "26543c8"
15708
15707
  }))
15709
15708
  });
15710
15709
  }
@@ -16229,6 +16228,98 @@ function setBrowserStorageItem(key, value, persistenceSetting) {
16229
16228
  dist/* adaSessionStorage */.ad.setItem(key, value);
16230
16229
  }
16231
16230
  }
16231
+ ;// CONCATENATED MODULE: ./src/proactiveConversations/proactiveConversation.ts
16232
+
16233
+ function proactiveConversation_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; }
16234
+ function proactiveConversation_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? proactiveConversation_ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : proactiveConversation_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16235
+
16236
+
16237
+
16238
+ function proactiveShownWithinFrequency(proactiveConversationKey, frequency, handle) {
16239
+ switch (frequency) {
16240
+ case "always":
16241
+ return false;
16242
+ case "session":
16243
+ {
16244
+ const storageValue = dist/* adaSessionStorage */.ad.getFnItem("marketing_campaigns_shown");
16245
+ const perSessionProactives = storageValue ? (storageValue[handle] || "").split(",") : [];
16246
+ return perSessionProactives.includes(proactiveConversationKey);
16247
+ }
16248
+ default:
16249
+ return false;
16250
+ }
16251
+ }
16252
+ function addProactiveToStorageString(oldStorageValue, proactiveConversationId) {
16253
+ return oldStorageValue ? `${oldStorageValue},${proactiveConversationId}` : proactiveConversationId;
16254
+ }
16255
+ function recordProactiveTrigger(proactiveConversationKey, frequency, handle) {
16256
+ switch (frequency) {
16257
+ case "always":
16258
+ break;
16259
+ case "session":
16260
+ {
16261
+ const currentStorageValue = dist/* adaSessionStorage */.ad.getFnItem("marketing_campaigns_shown");
16262
+ const newStorageValue = addProactiveToStorageString(currentStorageValue ? currentStorageValue[handle] || "" : "", proactiveConversationKey);
16263
+ dist/* adaSessionStorage */.ad.setFnItem("marketing_campaigns_shown", proactiveConversation_objectSpread(proactiveConversation_objectSpread({}, currentStorageValue), {}, {
16264
+ [handle]: newStorageValue
16265
+ }));
16266
+ break;
16267
+ }
16268
+ default:
16269
+ break;
16270
+ }
16271
+ }
16272
+ function proactiveTriggerImpl(_ref) {
16273
+ let {
16274
+ proactiveConversation,
16275
+ messageKey,
16276
+ adaSettings,
16277
+ messageService,
16278
+ clearProactiveMessage
16279
+ } = _ref;
16280
+ const {
16281
+ handle
16282
+ } = adaSettings;
16283
+ const {
16284
+ duration,
16285
+ delay,
16286
+ frequency
16287
+ } = proactiveConversation.modality_config.chat;
16288
+
16289
+ // Check if the proactive message has been shown within the specified frequency
16290
+ const doesPassFrequencyCheck = !proactiveShownWithinFrequency(messageKey, frequency, handle);
16291
+ if (!doesPassFrequencyCheck) {
16292
+ return;
16293
+ }
16294
+
16295
+ // Record the proactive message as being shown
16296
+ recordProactiveTrigger(messageKey, frequency, handle);
16297
+ clearProactiveMessage();
16298
+ const localChannel = messageService.getChannel("local");
16299
+ const lang = adaSettings.language || get_browser_language();
16300
+ const message = proactiveConversation.messages[lang][0];
16301
+ localChannel.postMessage(CREATE_PROACTIVE, {
16302
+ body: message,
16303
+ duration,
16304
+ delay
16305
+ });
16306
+ }
16307
+ function evaluateUrlTriggerConditions(conditions, url) {
16308
+ return conditions.every(condition => {
16309
+ switch (condition.type) {
16310
+ case "equals":
16311
+ return url === condition.value;
16312
+ case "ends-with":
16313
+ return url.endsWith(condition.value);
16314
+ case "regex":
16315
+ return new RegExp(condition.value).test(url);
16316
+ case "contains":
16317
+ return url.includes(condition.value);
16318
+ default:
16319
+ return false;
16320
+ }
16321
+ });
16322
+ }
16232
16323
  ;// CONCATENATED MODULE: ./src/services/chat-versioning/manifest.ts
16233
16324
 
16234
16325
 
@@ -16751,7 +16842,7 @@ class ChatFrame extends d {
16751
16842
  const hostPageUrlParams = new URL(window.location.href).searchParams;
16752
16843
  const smsToken = hostPageUrlParams.get("adaSMSToken");
16753
16844
  const queryParams = {
16754
- embedVersion: "6752092".slice(0, 7),
16845
+ embedVersion: "26543c8".slice(0, 7),
16755
16846
  greeting,
16756
16847
  language,
16757
16848
  skipGreeting,
@@ -17605,6 +17696,7 @@ function Container_objectSpread(e) { for (var r = 1; r < arguments.length; r++)
17605
17696
 
17606
17697
 
17607
17698
 
17699
+
17608
17700
 
17609
17701
 
17610
17702
  class Container extends d {
@@ -17621,7 +17713,8 @@ class Container extends d {
17621
17713
  hideIntroOverride: false,
17622
17714
  followUpResponseId: null,
17623
17715
  chatVersion: undefined,
17624
- readyToRenderChatFrame: false
17716
+ readyToRenderChatFrame: false,
17717
+ proactiveConversation: null
17625
17718
  });
17626
17719
  _defineProperty(this, "resetChatBound", this.resetChat.bind(this));
17627
17720
  _defineProperty(this, "locationChangeHandlerBound", this.locationChangeHandler.bind(this));
@@ -17735,7 +17828,8 @@ class Container extends d {
17735
17828
  const {
17736
17829
  campaignToTrigger,
17737
17830
  campaignTriggerOptions,
17738
- followUpResponseId
17831
+ followUpResponseId,
17832
+ proactiveConversation
17739
17833
  } = this.state;
17740
17834
 
17741
17835
  /* We wait for all necessary preconditions (e.g. necessary connections established) to be true,
@@ -17761,6 +17855,17 @@ class Container extends d {
17761
17855
  messageService
17762
17856
  });
17763
17857
  }
17858
+ if (proactiveConversation && appConnectionState === ConnectionState.Done) {
17859
+ proactiveTriggerImpl({
17860
+ proactiveConversation,
17861
+ messageKey: proactiveConversation.key,
17862
+ adaSettings,
17863
+ messageService,
17864
+ clearProactiveMessage: () => this.setState({
17865
+ proactiveConversation: null
17866
+ })
17867
+ });
17868
+ }
17764
17869
 
17765
17870
  // If a follow-up response has been queued by a triggered Campaign, tell chat to show it
17766
17871
  if (isChatWebsocketConnected && isDrawerOpen && followUpResponseId) {
@@ -17787,6 +17892,7 @@ class Container extends d {
17787
17892
  // Wait for client to be available, then set campaign to trigger
17788
17893
  if (client && !prevProps.client) {
17789
17894
  this.evaluateCampaignConditions({}, true);
17895
+ this.evaluateProactiveConversationConditions();
17790
17896
  }
17791
17897
 
17792
17898
  /**
@@ -17983,6 +18089,28 @@ class Container extends d {
17983
18089
  }
17984
18090
  }
17985
18091
  }
18092
+ evaluateProactiveConversationConditions() {
18093
+ const {
18094
+ client
18095
+ } = this.props;
18096
+ if (!client) {
18097
+ throw new AdaEmbedError("`client` is not defined");
18098
+ }
18099
+ const proactiveConversations = client.proactive_conversations;
18100
+ if (!proactiveConversations) {
18101
+ return;
18102
+ }
18103
+ const currentUrl = window.location.href;
18104
+ Object.entries(proactiveConversations).forEach(_ref => {
18105
+ let [key, conversation] = _ref;
18106
+ const chatConfig = conversation.modality_config.chat;
18107
+ if (chatConfig.active && evaluateUrlTriggerConditions(chatConfig.url_trigger_conditions, currentUrl)) {
18108
+ this.handleProactiveTrigger(Container_objectSpread({
18109
+ key
18110
+ }, conversation));
18111
+ }
18112
+ });
18113
+ }
17986
18114
  async handleSettingDeviceToken(localChannel, payload, id) {
17987
18115
  const {
17988
18116
  setGlobalState,
@@ -18004,6 +18132,17 @@ class Container extends d {
18004
18132
  });
18005
18133
  localChannel.postMessage(SET_DEVICE_TOKEN_RESPONSE, null, id);
18006
18134
  }
18135
+ handleProactiveTrigger(proactiveConversation) {
18136
+ const {
18137
+ isDrawerOpen
18138
+ } = this.props;
18139
+ if (isDrawerOpen) {
18140
+ return;
18141
+ }
18142
+ this.setState({
18143
+ proactiveConversation
18144
+ });
18145
+ }
18007
18146
  async handleEmbedAction(type, payload, id) {
18008
18147
  const {
18009
18148
  client,
@@ -18200,7 +18339,8 @@ class Container extends d {
18200
18339
  }
18201
18340
  const {
18202
18341
  body,
18203
- duration
18342
+ duration,
18343
+ delay
18204
18344
  } = payload;
18205
18345
  const EXTRA_PROACTIVE_DELAY = 1000;
18206
18346
  this.setState({
@@ -18212,7 +18352,7 @@ class Container extends d {
18212
18352
  const newClient = new Client(Container_objectSpread(Container_objectSpread({}, client), {}, {
18213
18353
  intro: {
18214
18354
  body,
18215
- delay: 0,
18355
+ delay: delay || 0,
18216
18356
  // Not just duration || null because we want to preserve 0 duration
18217
18357
  duration: duration || duration === 0 ? duration : null,
18218
18358
  style: "Text",
@@ -18251,17 +18391,18 @@ class Container extends d {
18251
18391
  if (!client) {
18252
18392
  throw new AdaEmbedError("`client` is not defined");
18253
18393
  }
18254
- const language = adaSettings.language || get_browser_language();
18255
18394
  const {
18256
18395
  messageKey
18257
18396
  } = payload;
18258
18397
  if ((_client$proactive_con = client.proactive_conversations) !== null && _client$proactive_con !== void 0 && _client$proactive_con[messageKey]) {
18259
- // eslint-disable-next-line no-console
18260
- console.log("Proactive message: ", client.proactive_conversations[messageKey].messages[language]);
18398
+ const proactiveConversation = client.proactive_conversations[messageKey];
18399
+ this.handleProactiveTrigger(Container_objectSpread(Container_objectSpread({}, proactiveConversation), {}, {
18400
+ key: messageKey
18401
+ }));
18261
18402
  } else {
18262
- // eslint-disable-next-line no-console
18263
- console.log("Proactive message not found");
18403
+ warn(`Proactive message with key ${messageKey} not found`);
18264
18404
  }
18405
+ localChannel.postMessage(TRIGGER_PROACTIVE_RESPONSE, null, id);
18265
18406
  break;
18266
18407
  }
18267
18408
  default:
@@ -18292,6 +18433,7 @@ class Container extends d {
18292
18433
  });
18293
18434
  this.evaluateCampaignConditions({}, true);
18294
18435
  this.evaluateBusinessEventConditions();
18436
+ this.evaluateProactiveConversationConditions();
18295
18437
  });
18296
18438
  });
18297
18439
  }
@@ -0,0 +1,11 @@
1
+ import type { StartOptions } from "@ada-support/embed-types";
2
+ import type { MessageService } from "client/lib/message-service";
3
+ import type { ProactiveConversation, UrlTriggerCondition } from "./types";
4
+ export declare function proactiveTriggerImpl({ proactiveConversation, messageKey, adaSettings, messageService, clearProactiveMessage, }: {
5
+ proactiveConversation: ProactiveConversation;
6
+ messageKey: string;
7
+ adaSettings: StartOptions;
8
+ messageService: MessageService;
9
+ clearProactiveMessage: () => void;
10
+ }): void;
11
+ export declare function evaluateUrlTriggerConditions(conditions: UrlTriggerCondition[], url: string): boolean;
@@ -1,16 +1,24 @@
1
- export interface ProactiveConversations {
2
- [messageKey: string]: {
3
- messages: {
4
- [language: string]: string[];
5
- };
6
- modality_config: {
7
- [modality: string]: {
8
- active: boolean;
9
- url_trigger_conditions: string[];
10
- delay: number;
11
- duration: number;
12
- frequency: string;
13
- };
1
+ export interface ProactiveConversation {
2
+ messages: {
3
+ [language: string]: string[];
4
+ };
5
+ modality_config: {
6
+ [modality: string]: {
7
+ active: boolean;
8
+ url_trigger_conditions: UrlTriggerCondition[];
9
+ delay: number;
10
+ duration: number;
11
+ frequency: ProactiveConversationFrequency;
14
12
  };
15
13
  };
14
+ key?: string;
15
+ }
16
+ export interface ProactiveConversations {
17
+ [messageKey: string]: ProactiveConversation;
18
+ }
19
+ export declare type ProactiveConversationFrequency = "always" | "session";
20
+ export declare type ProactiveConversationUrlTriggerConditionType = "equals" | "ends-with" | "regex" | "contains";
21
+ export interface UrlTriggerCondition {
22
+ type: ProactiveConversationUrlTriggerConditionType;
23
+ value: string;
16
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ada-support/embed2",
3
- "version": "1.7.29",
3
+ "version": "1.7.32",
4
4
  "description": "",
5
5
  "main": "dist/npm-entry",
6
6
  "typings": "dist/npm-entry/index-npm.d.ts",
@@ -43,6 +43,15 @@
43
43
  "license": "ISC",
44
44
  "devDependencies": {
45
45
  "@ada-support/eslint-config-ada": "^1.2.5",
46
+ "@babel/core": "^7.23.2",
47
+ "@babel/plugin-proposal-class-properties": "^7.16.7",
48
+ "@babel/plugin-proposal-numeric-separator": "^7.16.7",
49
+ "@babel/plugin-proposal-object-rest-spread": "^7.16.7",
50
+ "@babel/plugin-proposal-optional-chaining": "^7.16.7",
51
+ "@babel/plugin-transform-react-jsx": "^7.16.7",
52
+ "@babel/plugin-transform-runtime": "^7.16.10",
53
+ "@babel/preset-env": "^7.23.2",
54
+ "@babel/preset-typescript": "^7.23.2",
46
55
  "@testing-library/preact": "^2.0.1",
47
56
  "@types/enzyme": "^3.10.11",
48
57
  "@types/jest": "^27.0.2",
@@ -54,9 +63,12 @@
54
63
  "@types/webpack": "^5.28.0",
55
64
  "@types/webpack-bundle-analyzer": "^4.4.1",
56
65
  "@types/webpack-dev-server": "^4.7.2",
66
+ "babel-loader": "9.1.2",
67
+ "babel-preset-preact": "^2.0.0",
57
68
  "browserslist": "^4.17.4",
58
69
  "cypress": "^9.6.1",
59
70
  "depcheck": "^1.4.3",
71
+ "dotenv": "^8.2.0",
60
72
  "enzyme": "^3.11.0",
61
73
  "enzyme-adapter-preact-pure": "^4.0.1",
62
74
  "eslint": "^8.8.0",
@@ -66,6 +78,7 @@
66
78
  "eslint-plugin-cypress": "^2.12.1",
67
79
  "eslint-plugin-sonarjs": "^0.11.0",
68
80
  "husky": "^7.0.0",
81
+ "html-webpack-plugin": "^5.5.0",
69
82
  "jest": "^27.5.1",
70
83
  "jest-localstorage-mock": "^2.4.0",
71
84
  "lint-staged": "^11.2.3",
@@ -75,38 +88,25 @@
75
88
  "start-server-and-test": "^2.0.4",
76
89
  "ts-node": "^10.2.1",
77
90
  "tsconfig-paths": "^3.11.0",
91
+ "typescript": "^4.6.2",
92
+ "webpack": "^5.76.0",
78
93
  "webpack-bundle-analyzer": "^4.5.0",
79
- "webpack-dev-server": "^4.3.1"
94
+ "webpack-cli": "^5.1.4",
95
+ "webpack-dev-server": "^4.3.1",
96
+ "webpack-merge": "^5.8.0"
80
97
  },
81
98
  "dependencies": {
82
99
  "@ada-support/embed-types": "^1.8.0",
83
100
  "@ada-support/web-storage": "^1.2.6",
84
- "@babel/core": "^7.23.2",
85
- "@babel/plugin-proposal-class-properties": "^7.16.7",
86
- "@babel/plugin-proposal-numeric-separator": "^7.16.7",
87
- "@babel/plugin-proposal-object-rest-spread": "^7.16.7",
88
- "@babel/plugin-proposal-optional-chaining": "^7.16.7",
89
- "@babel/plugin-transform-react-jsx": "^7.16.7",
90
- "@babel/plugin-transform-runtime": "^7.16.10",
91
- "@babel/preset-env": "^7.23.2",
92
- "@babel/preset-typescript": "^7.23.2",
93
101
  "@babel/runtime-corejs3": "^7.15.4",
94
102
  "@sentry/browser": "^8.33.0",
95
103
  "@sentry/types": "^8.33.1",
96
- "babel-loader": "9.1.2",
97
- "babel-preset-preact": "^2.0.0",
98
- "dotenv": "^8.2.0",
99
104
  "focus-visible": "^5.2.0",
100
- "html-webpack-plugin": "^5.5.0",
101
105
  "json-stable-stringify": "^1.0.1",
102
106
  "lodash.debounce": "^4.0.8",
103
107
  "lodash.memoize": "^4.1.2",
104
108
  "preact": "10.4.5",
105
- "typescript": "^4.6.2",
106
- "uniqid": "^5.3.0",
107
- "webpack": "^5.76.0",
108
- "webpack-cli": "^5.1.4",
109
- "webpack-merge": "^5.8.0"
109
+ "uniqid": "^5.3.0"
110
110
  },
111
111
  "resolutions": {
112
112
  "@lambdatest/node-tunnel": ">=3.0.2",