@ada-support/embed2 1.0.62 → 1.0.65

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.
@@ -1,5 +1,5 @@
1
- import { TrackEventParams } from "common/types";
2
- import { StartOptions } from "common/types/store-state";
3
- import { BusinessEvent } from "./types";
1
+ import type { TrackEventParams } from "common/types";
2
+ import type { StartOptions } from "common/types/store-state";
3
+ import type { BusinessEvent } from "./types";
4
4
  export declare function trackEventImpl(adaSettings: StartOptions, chatterToken: string, params: TrackEventParams): void;
5
5
  export declare const getEventsToTrigger: (businessEvents: BusinessEvent[]) => BusinessEvent[];
@@ -1,17 +1,8 @@
1
- export interface URLMatchTriggerCondition {
2
- type: "url-match";
3
- conditions_any: [
4
- {
5
- type: "ends-with" | "contains" | "equals" | "regex";
6
- value: string;
7
- }
8
- ];
9
- }
10
- export declare type TriggerCondition = URLMatchTriggerCondition;
1
+ import type { URLMatchTriggerCondition } from "common/types/helpers";
11
2
  export interface BusinessEvent {
12
3
  event_key: string;
13
4
  value: number;
14
- trigger_conditions: TriggerCondition[];
5
+ trigger_conditions: URLMatchTriggerCondition[];
15
6
  }
16
7
  export interface BusinessEventsResponse {
17
8
  business_events: BusinessEvent[];
@@ -1,22 +1,5 @@
1
- export declare type TriggerCondition = URLMatchTriggerCondition | DateTimeTriggerCondition;
1
+ import type { TriggerCondition } from "common/types/helpers";
2
2
  export declare type GoalEvent = unknown;
3
- export interface URLMatchTriggerCondition {
4
- type: "url-match";
5
- conditions_any: [
6
- {
7
- type: "ends-with" | "contains" | "equals" | "regex";
8
- value: string;
9
- }
10
- ];
11
- }
12
- export interface DateTimeTriggerCondition {
13
- type: "datetime";
14
- timezone: string;
15
- condition: {
16
- operator: "before-exclusive" | "after-inclusive";
17
- datetime: string;
18
- };
19
- }
20
3
  export declare type CampaignFrequency = "every-time" | "once-per-session" | "once-per-user";
21
4
  export interface MarketingCampaign {
22
5
  _id: string;
@@ -38,4 +38,5 @@ export declare class Embed {
38
38
  createProactive(body: string, duration: number, responseId?: string): Promise<void>;
39
39
  subscribeEvent(eventKey: string, callback: EventSubscriptionCallback): number;
40
40
  unsubscribeEvent(id: number): void;
41
+ closeCampaign(): Promise<void>;
41
42
  }
@@ -72,6 +72,8 @@ export declare const TRIGGER_CAMPAIGN = "TRIGGER_CAMPAIGN";
72
72
  export declare const TRIGGER_CAMPAIGN_RESPONSE = "TRIGGER_CAMPAIGN_RESPONSE";
73
73
  export declare const EVAL_CAMPAIGN_CONDITIONS = "EVAL_CAMPAIGN_CONDITIONS";
74
74
  export declare const EVAL_CAMPAIGN_CONDITIONS_RESPONSE = "EVAL_CAMPAIGN_CONDITIONS_RESPONSE";
75
+ export declare const CLOSE_CAMPAIGN = "CLOSE_CAMPAIGN";
76
+ export declare const CLOSE_CAMPAIGN_RESPONSE = "CLOSE_CAMPAIGN_RESPONSE";
75
77
  export declare const SEND_GREETING = "SEND_GREETING";
76
78
  /**
77
79
  * Fetch Event Status
@@ -1,4 +1,4 @@
1
- import { DateTimeTriggerCondition, TriggerCondition, URLMatchTriggerCondition } from "./types";
1
+ import type { DateTimeTriggerCondition, TriggerCondition, URLMatchTriggerCondition } from "common/types/helpers";
2
2
  export declare const evalUrlMatchTriggerCondition: (triggerCondition: URLMatchTriggerCondition, url: string) => boolean;
3
3
  export declare const evalDatetimeTriggerCondition: (triggerCondition: DateTimeTriggerCondition, currentDateTime: Date) => boolean;
4
4
  export declare const evalTriggerCondition: (triggerCondition: TriggerCondition) => boolean;
@@ -23,6 +23,7 @@ export interface EmbedRequestPayloadByEvent {
23
23
  TRIGGER_CAMPAIGN: unknown;
24
24
  TRACK_EVENT: TrackEventParams;
25
25
  SEND_GREETING: SendGreetingParams;
26
+ CLOSE_CAMPAIGN: unknown;
26
27
  }
27
28
  export declare type EmbedRequestEvent = keyof EmbedRequestPayloadByEvent;
28
29
  export interface EmbedResponsePayloadByEvent {
@@ -47,6 +48,7 @@ export interface EmbedResponsePayloadByEvent {
47
48
  TOGGLE_RESPONSE: unknown;
48
49
  TRACK_EVENT_RESPONSE: string;
49
50
  TRIGGER_CAMPAIGN_RESPONSE: string;
51
+ CLOSE_CAMPAIGN_RESPONSE: unknown;
50
52
  entry_INIT: unknown;
51
53
  client_INIT: unknown;
52
54
  button_INIT: unknown;
@@ -1,3 +1,21 @@
1
1
  export declare type PartialRecord<K extends keyof any, T> = {
2
2
  [P in K]?: T;
3
3
  };
4
+ export declare type TriggerCondition = URLMatchTriggerCondition | DateTimeTriggerCondition;
5
+ export interface URLMatchTriggerCondition {
6
+ type: "url-match";
7
+ conditions_any: [
8
+ {
9
+ type: "ends-with" | "contains" | "equals" | "regex";
10
+ value: string;
11
+ }
12
+ ];
13
+ }
14
+ export interface DateTimeTriggerCondition {
15
+ type: "datetime";
16
+ timezone: string;
17
+ condition: {
18
+ operator: "before-exclusive" | "after-inclusive";
19
+ datetime: string;
20
+ };
21
+ }
@@ -20,7 +20,6 @@ export interface Features {
20
20
  developer_proactive?: boolean;
21
21
  afm_business_events?: boolean;
22
22
  afm_proactive_messaging?: boolean;
23
- afm_dont_show_proactive_messages_in_chat?: boolean;
24
23
  embed_test_bot?: boolean;
25
24
  translations?: boolean;
26
25
  }
@@ -30,7 +30,6 @@ export interface TrackEventParams {
30
30
  }
31
31
  export interface SendGreetingParams {
32
32
  responseId?: string;
33
- isChatEmpty?: boolean;
34
33
  }
35
34
  export interface TriggerCampaignParams {
36
35
  campaignKey: string;
@@ -570,7 +570,7 @@ var browserPerformanceTimeOrigin = (function () {
570
570
 
571
571
  /***/ }),
572
572
 
573
- /***/ 9262:
573
+ /***/ 5265:
574
574
  /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
575
575
 
576
576
  "use strict";
@@ -8788,7 +8788,7 @@ var client = new error_tracker_BrowserClient({
8788
8788
  return event;
8789
8789
  },
8790
8790
  environment: "production",
8791
- release: "1.0.62-e5d1f99",
8791
+ release: "1.0.65-8e64b86",
8792
8792
  sampleRate: 0.25,
8793
8793
  autoSessionTracking: false,
8794
8794
  // Integrations don't seem to work with Sentry: https://github.com/getsentry/sentry-javascript/issues/2541
@@ -8925,7 +8925,9 @@ var TRACK_EVENT_RESPONSE = "TRACK_EVENT_RESPONSE";
8925
8925
  var TRIGGER_CAMPAIGN = "TRIGGER_CAMPAIGN";
8926
8926
  var TRIGGER_CAMPAIGN_RESPONSE = "TRIGGER_CAMPAIGN_RESPONSE";
8927
8927
  var EVAL_CAMPAIGN_CONDITIONS = "EVAL_CAMPAIGN_CONDITIONS";
8928
- var EVAL_CAMPAIGN_CONDITIONS_RESPONSE = "EVAL_CAMPAIGN_CONDITIONS_RESPONSE"; // Tells chat to send a greeting
8928
+ var EVAL_CAMPAIGN_CONDITIONS_RESPONSE = "EVAL_CAMPAIGN_CONDITIONS_RESPONSE";
8929
+ var CLOSE_CAMPAIGN = "CLOSE_CAMPAIGN";
8930
+ var CLOSE_CAMPAIGN_RESPONSE = "CLOSE_CAMPAIGN_RESPONSE"; // Tells chat to send a greeting
8929
8931
 
8930
8932
  var SEND_GREETING = "SEND_GREETING";
8931
8933
  /**
@@ -9488,7 +9490,7 @@ function getEmbedURL(_ref) {
9488
9490
  polyfillVersionString = "legacy";
9489
9491
  }
9490
9492
 
9491
- return concat_default()(_context5 = concat_default()(_context6 = concat_default()(_context7 = "".concat(host, "/embed/")).call(_context7, polyfillVersionString, "/")).call(_context6, frameName, "/")).call(_context5, "e5d1f99", "/index.html");
9493
+ return concat_default()(_context5 = concat_default()(_context6 = concat_default()(_context7 = "".concat(host, "/embed/")).call(_context7, polyfillVersionString, "/")).call(_context6, frameName, "/")).call(_context5, "8e64b86", "/index.html");
9492
9494
  }
9493
9495
  /**
9494
9496
  * Generate the Chat / API URL
@@ -10201,7 +10203,38 @@ var ends_with_default = /*#__PURE__*/__webpack_require__.n(ends_with);
10201
10203
  // EXTERNAL MODULE: ./node_modules/@babel/runtime-corejs3/core-js-stable/instance/slice.js
10202
10204
  var slice = __webpack_require__(3649);
10203
10205
  var slice_default = /*#__PURE__*/__webpack_require__.n(slice);
10204
- ;// CONCATENATED MODULE: ./src/businessEvents/TriggerConditionEvaluator.ts
10206
+ // EXTERNAL MODULE: ./node_modules/@babel/runtime-corejs3/core-js-stable/instance/trim.js
10207
+ var trim = __webpack_require__(5843);
10208
+ var trim_default = /*#__PURE__*/__webpack_require__.n(trim);
10209
+ ;// CONCATENATED MODULE: ./src/common/helpers/get-intro-for-url.ts
10210
+
10211
+
10212
+ function getProcessedPath(path) {
10213
+ var regex = /^http(s)?:\/\/(www.)?/;
10214
+ return trim_default()(path).call(path).replace(regex, "");
10215
+ }
10216
+ function getPathSearchRegex(path) {
10217
+ var params = path.split("?");
10218
+
10219
+ if (params.length > 1) {
10220
+ var _context;
10221
+
10222
+ var escapedParams = encodeURI(params[1]);
10223
+ return new RegExp(concat_default()(_context = "^".concat(params[0], "\\?")).call(_context, escapedParams, "$"));
10224
+ }
10225
+
10226
+ var newPath = path.replace("*", ".*");
10227
+ return new RegExp("^".concat(newPath, "$"));
10228
+ }
10229
+ function doesUrlMatchPath(url, path) {
10230
+ var processedUrl = getProcessedPath(url);
10231
+ var processedPath = getProcessedPath(path);
10232
+ var pathRegex = getPathSearchRegex(processedPath);
10233
+ var matches = pathRegex.exec(processedUrl);
10234
+ return matches !== null;
10235
+ }
10236
+ ;// CONCATENATED MODULE: ./src/common/helpers/TriggerConditionEvaluator.ts
10237
+
10205
10238
 
10206
10239
 
10207
10240
 
@@ -10233,7 +10266,9 @@ var evalUrlMatchTriggerCondition = function evalUrlMatchTriggerCondition(trigger
10233
10266
  return includes_default()(url).call(url, condition.value);
10234
10267
 
10235
10268
  case "equals":
10236
- return urlWithoutQueryParams === condition.value;
10269
+ {
10270
+ return doesUrlMatchPath(urlWithoutQueryParams, condition.value);
10271
+ }
10237
10272
 
10238
10273
  case "regex":
10239
10274
  {
@@ -10247,11 +10282,29 @@ var evalUrlMatchTriggerCondition = function evalUrlMatchTriggerCondition(trigger
10247
10282
  }
10248
10283
  });
10249
10284
  };
10285
+ var evalDatetimeTriggerCondition = function evalDatetimeTriggerCondition(triggerCondition, currentDateTime) {
10286
+ var conditionDatetime = new Date(triggerCondition.condition.datetime);
10287
+
10288
+ switch (triggerCondition.condition.operator) {
10289
+ case "before-exclusive":
10290
+ return currentDateTime < conditionDatetime;
10291
+
10292
+ case "after-inclusive":
10293
+ return currentDateTime >= conditionDatetime;
10294
+ // If an unknown comparator is found, ignore the trigger condition - do not block campaign
10295
+
10296
+ default:
10297
+ return true;
10298
+ }
10299
+ };
10250
10300
  var evalTriggerCondition = function evalTriggerCondition(triggerCondition) {
10251
10301
  switch (triggerCondition.type) {
10252
10302
  case "url-match":
10253
10303
  return evalUrlMatchTriggerCondition(triggerCondition, window.location.href);
10254
- // If an unknown trigger type is found, ignore the trigger condition - do not block event
10304
+
10305
+ case "datetime":
10306
+ return evalDatetimeTriggerCondition(triggerCondition, new Date());
10307
+ // If an unknown trigger type is found, ignore the trigger condition - do not block campaign
10255
10308
 
10256
10309
  default:
10257
10310
  return true;
@@ -10346,113 +10399,6 @@ var get_browser_language_getBrowserLanguage = function getBrowserLanguage() {
10346
10399
  ;// CONCATENATED MODULE: ./src/services/helpers.ts
10347
10400
  var NO_OP_FUNCTION = function NO_OP_FUNCTION() {// Do nothing
10348
10401
  };
10349
- // EXTERNAL MODULE: ./node_modules/@babel/runtime-corejs3/core-js-stable/instance/trim.js
10350
- var trim = __webpack_require__(5843);
10351
- var trim_default = /*#__PURE__*/__webpack_require__.n(trim);
10352
- ;// CONCATENATED MODULE: ./src/common/helpers/get-intro-for-url.ts
10353
-
10354
-
10355
- function getProcessedPath(path) {
10356
- var regex = /^http(s)?:\/\/(www.)?/;
10357
- return trim_default()(path).call(path).replace(regex, "");
10358
- }
10359
- function getPathSearchRegex(path) {
10360
- var params = path.split("?");
10361
-
10362
- if (params.length > 1) {
10363
- var _context;
10364
-
10365
- var escapedParams = encodeURI(params[1]);
10366
- return new RegExp(concat_default()(_context = "^".concat(params[0], "\\?")).call(_context, escapedParams, "$"));
10367
- }
10368
-
10369
- var newPath = path.replace("*", ".*");
10370
- return new RegExp("^".concat(newPath, "$"));
10371
- }
10372
- function doesUrlMatchPath(url, path) {
10373
- var processedUrl = getProcessedPath(url);
10374
- var processedPath = getProcessedPath(path);
10375
- var pathRegex = getPathSearchRegex(processedPath);
10376
- var matches = pathRegex.exec(processedUrl);
10377
- return matches !== null;
10378
- }
10379
- ;// CONCATENATED MODULE: ./src/campaigns/TriggerConditionEvaluator.ts
10380
-
10381
-
10382
-
10383
-
10384
-
10385
- var TriggerConditionEvaluator_stripTrailingSlash = function stripTrailingSlash(url) {
10386
- return ends_with_default()(url).call(url, "/") ? slice_default()(url).call(url, 0, -1) : url;
10387
- };
10388
-
10389
- var TriggerConditionEvaluator_evalUrlMatchTriggerCondition = function evalUrlMatchTriggerCondition(triggerCondition, url) {
10390
- /**
10391
- * Behaviour
10392
- * regex Regex match (as per javascript string .match) over the whole string including
10393
- * query params
10394
- * ends-with Match only the URL without query params. Match including trailing slashes
10395
- * contains Match substring including query params
10396
- * equals Matches the exact URL, without query params
10397
- */
10398
- var urlWithoutQueryParams = url.split("?")[0];
10399
- return triggerCondition.conditions_any.some(function (condition) {
10400
- switch (condition.type) {
10401
- case "ends-with":
10402
- {
10403
- var _context;
10404
-
10405
- return ends_with_default()(urlWithoutQueryParams).call(urlWithoutQueryParams, condition.value) || ends_with_default()(_context = TriggerConditionEvaluator_stripTrailingSlash(urlWithoutQueryParams)).call(_context, condition.value);
10406
- }
10407
-
10408
- case "contains":
10409
- return includes_default()(url).call(url, condition.value);
10410
-
10411
- case "equals":
10412
- {
10413
- return doesUrlMatchPath(urlWithoutQueryParams, condition.value);
10414
- }
10415
-
10416
- case "regex":
10417
- {
10418
- var rx = new RegExp(condition.value);
10419
- return Boolean(rx.exec(url));
10420
- }
10421
- // If an unknown URL match type is found, ignore it - one of the others will have to match
10422
-
10423
- default:
10424
- return false;
10425
- }
10426
- });
10427
- };
10428
- var evalDatetimeTriggerCondition = function evalDatetimeTriggerCondition(triggerCondition, currentDateTime) {
10429
- var conditionDatetime = new Date(triggerCondition.condition.datetime);
10430
-
10431
- switch (triggerCondition.condition.operator) {
10432
- case "before-exclusive":
10433
- return currentDateTime < conditionDatetime;
10434
-
10435
- case "after-inclusive":
10436
- return currentDateTime >= conditionDatetime;
10437
- // If an unknown comparator is found, ignore the trigger condition - do not block campaign
10438
-
10439
- default:
10440
- return true;
10441
- }
10442
- };
10443
- var TriggerConditionEvaluator_evalTriggerCondition = function evalTriggerCondition(triggerCondition) {
10444
- switch (triggerCondition.type) {
10445
- case "url-match":
10446
- return TriggerConditionEvaluator_evalUrlMatchTriggerCondition(triggerCondition, window.location.href);
10447
-
10448
- case "datetime":
10449
- return evalDatetimeTriggerCondition(triggerCondition, new Date());
10450
- // If an unknown trigger type is found, ignore the trigger condition - do not block campaign
10451
-
10452
- default:
10453
- return true;
10454
- }
10455
- };
10456
10402
  ;// CONCATENATED MODULE: ./src/campaigns/campaign.ts
10457
10403
 
10458
10404
 
@@ -10627,7 +10573,7 @@ var getCampaignToTrigger = function getCampaignToTrigger(adaSettings, marketingC
10627
10573
  }
10628
10574
 
10629
10575
  var conditionsMet = campaign.trigger_conditions.every(function (tc) {
10630
- return TriggerConditionEvaluator_evalTriggerCondition(tc);
10576
+ return evalTriggerCondition(tc);
10631
10577
  });
10632
10578
  var doesPassFrequencyCheck = ignoreFrequency || !campaignShownWithinFrequency(campaign, handle);
10633
10579
  return conditionsMet && doesPassFrequencyCheck;
@@ -13043,7 +12989,7 @@ var Container = /*#__PURE__*/function (_Component) {
13043
12989
  }, {
13044
12990
  key: "triggerCampaign",
13045
12991
  value: function triggerCampaign(params) {
13046
- var _client$marketing_cam;
12992
+ var _client$marketing_cam, _campaign$follow_up_r;
13047
12993
 
13048
12994
  var _this$props7 = this.props,
13049
12995
  client = _this$props7.client,
@@ -13066,15 +13012,11 @@ var Container = /*#__PURE__*/function (_Component) {
13066
13012
  throw new errors/* AdaEmbedError */.S("Could not find campaign with key: ".concat(campaignKey));
13067
13013
  }
13068
13014
 
13069
- var followUpResponseId = campaign.follow_up_response_id;
13070
-
13071
- if (client !== null && client !== void 0 && client.features.afm_dont_show_proactive_messages_in_chat && !followUpResponseId) {
13072
- followUpResponseId = campaign.response_id;
13073
- }
13074
-
13015
+ var followUpResponseId = (_campaign$follow_up_r = campaign.follow_up_response_id) !== null && _campaign$follow_up_r !== void 0 ? _campaign$follow_up_r : campaign.response_id;
13075
13016
  setState({
13076
13017
  latestCampaignKey: campaignKey,
13077
- hasChatOpenedAfterProactiveMessagesShown: false
13018
+ hasChatOpenedAfterProactiveMessagesShown: false,
13019
+ wasCampaignShownButNowClosed: false
13078
13020
  });
13079
13021
  this.setState({
13080
13022
  // Only need to load chat for engage campaigns, not free tier (message_text) campaigns
@@ -13118,7 +13060,7 @@ var Container = /*#__PURE__*/function (_Component) {
13118
13060
  var _handleEmbedAction = (0,asyncToGenerator/* default */.Z)( /*#__PURE__*/regenerator_default().mark(function _callee2(type, payload, id) {
13119
13061
  var _this5 = this;
13120
13062
 
13121
- var _this$props9, client, messageService, adaSettings, parentElement, localChannel, xStorageChannel, toggleChat, _this$props10, isDrawerOpen, drawerHasBeenOpened, chatterToken, contentToReturn, _this$props11, metaFields, setState, metaData, newMetaFields, _this$props12, sensitiveMetaFields, _setState, _ref, greeting, language, _newMetaFields, _sensitiveMetaFields, _ref$resetChatHistory, resetChatHistory, _setState2, chatHasBeenRendered, newState, _setState3, _ref2, body, duration, EXTRA_PROACTIVE_DELAY;
13063
+ var _this$props9, client, messageService, adaSettings, parentElement, localChannel, xStorageChannel, chatChannel, toggleChat, _this$props10, isDrawerOpen, drawerHasBeenOpened, chatterToken, contentToReturn, _this$props11, metaFields, setState, metaData, newMetaFields, _this$props12, sensitiveMetaFields, _setState, _ref, greeting, language, _newMetaFields, _sensitiveMetaFields, _ref$resetChatHistory, resetChatHistory, _setState2, chatHasBeenRendered, newState, _setState3, _ref2, body, duration, EXTRA_PROACTIVE_DELAY;
13122
13064
 
13123
13065
  return regenerator_default().wrap(function _callee2$(_context3) {
13124
13066
  while (1) {
@@ -13128,68 +13070,69 @@ var Container = /*#__PURE__*/function (_Component) {
13128
13070
  parentElement = adaSettings.parentElement;
13129
13071
  localChannel = messageService.getChannel("local");
13130
13072
  xStorageChannel = messageService.getChannel(XSTORAGE_IFRAME);
13073
+ chatChannel = messageService.getChannel(CHAT_IFRAME);
13131
13074
 
13132
13075
  if (localChannel) {
13133
- _context3.next = 6;
13076
+ _context3.next = 7;
13134
13077
  break;
13135
13078
  }
13136
13079
 
13137
13080
  throw new errors/* AdaEmbedError */.S("`localChannel` is null");
13138
13081
 
13139
- case 6:
13082
+ case 7:
13140
13083
  _context3.t0 = type;
13141
- _context3.next = _context3.t0 === TRACK_EVENT ? 9 : _context3.t0 === TRIGGER_CAMPAIGN ? 14 : _context3.t0 === EVAL_CAMPAIGN_CONDITIONS ? 19 : _context3.t0 === TOGGLE ? 24 : _context3.t0 === GET_INFO ? 29 : _context3.t0 === SET_META_FIELDS ? 33 : _context3.t0 === "SET_SENSITIVE_META_FIELDS" ? 40 : _context3.t0 === STOP ? 45 : _context3.t0 === RESET ? 48 : _context3.t0 === DELETE_HISTORY ? 66 : _context3.t0 === CREATE_PROACTIVE ? 78 : 87;
13084
+ _context3.next = _context3.t0 === TRACK_EVENT ? 10 : _context3.t0 === TRIGGER_CAMPAIGN ? 15 : _context3.t0 === EVAL_CAMPAIGN_CONDITIONS ? 20 : _context3.t0 === TOGGLE ? 25 : _context3.t0 === GET_INFO ? 30 : _context3.t0 === SET_META_FIELDS ? 34 : _context3.t0 === "SET_SENSITIVE_META_FIELDS" ? 41 : _context3.t0 === STOP ? 46 : _context3.t0 === RESET ? 49 : _context3.t0 === DELETE_HISTORY ? 67 : _context3.t0 === CREATE_PROACTIVE ? 79 : _context3.t0 === CLOSE_CAMPAIGN ? 88 : 91;
13142
13085
  break;
13143
13086
 
13144
- case 9:
13087
+ case 10:
13145
13088
  if (client.features.afm_business_events) {
13146
- _context3.next = 12;
13089
+ _context3.next = 13;
13147
13090
  break;
13148
13091
  }
13149
13092
 
13150
13093
  localChannel.postMessage(TRACK_EVENT_RESPONSE, "Ada Embed - business events not available in your feature set.", id, FetchEventStatus.Failure);
13151
13094
  return _context3.abrupt("return");
13152
13095
 
13153
- case 12:
13096
+ case 13:
13154
13097
  this.trackEvent(payload);
13155
- return _context3.abrupt("break", 87);
13098
+ return _context3.abrupt("break", 91);
13156
13099
 
13157
- case 14:
13100
+ case 15:
13158
13101
  if (client.features.afm_proactive_messaging) {
13159
- _context3.next = 17;
13102
+ _context3.next = 18;
13160
13103
  break;
13161
13104
  }
13162
13105
 
13163
13106
  localChannel.postMessage(TRIGGER_CAMPAIGN_RESPONSE, "Ada Embed - proactive campaigns not available in your feature set.", id, FetchEventStatus.Failure);
13164
13107
  return _context3.abrupt("return");
13165
13108
 
13166
- case 17:
13109
+ case 18:
13167
13110
  this.triggerCampaign(payload);
13168
- return _context3.abrupt("break", 87);
13111
+ return _context3.abrupt("break", 91);
13169
13112
 
13170
- case 19:
13113
+ case 20:
13171
13114
  if (client.features.afm_proactive_messaging) {
13172
- _context3.next = 22;
13115
+ _context3.next = 23;
13173
13116
  break;
13174
13117
  }
13175
13118
 
13176
13119
  localChannel.postMessage(TRIGGER_CAMPAIGN_RESPONSE, "Ada Embed - proactive campaigns not available in your feature set.", id, FetchEventStatus.Failure);
13177
13120
  return _context3.abrupt("return");
13178
13121
 
13179
- case 22:
13122
+ case 23:
13180
13123
  this.evaluateCampaignConditions(payload);
13181
- return _context3.abrupt("break", 87);
13124
+ return _context3.abrupt("break", 91);
13182
13125
 
13183
- case 24:
13126
+ case 25:
13184
13127
  toggleChat = this.props.toggleChat;
13185
- _context3.next = 27;
13128
+ _context3.next = 28;
13186
13129
  return toggleChat();
13187
13130
 
13188
- case 27:
13131
+ case 28:
13189
13132
  localChannel.postMessage(TOGGLE_RESPONSE, null, id);
13190
- return _context3.abrupt("break", 87);
13133
+ return _context3.abrupt("break", 91);
13191
13134
 
13192
- case 29:
13135
+ case 30:
13193
13136
  _this$props10 = this.props, isDrawerOpen = _this$props10.isDrawerOpen, drawerHasBeenOpened = _this$props10.drawerHasBeenOpened, chatterToken = _this$props10.chatterToken;
13194
13137
  contentToReturn = {
13195
13138
  isDrawerOpen: isDrawerOpen,
@@ -13198,38 +13141,38 @@ var Container = /*#__PURE__*/function (_Component) {
13198
13141
  hasClosedChat: drawerHasBeenOpened && !isDrawerOpen
13199
13142
  };
13200
13143
  localChannel.postMessage(GET_INFO_RESPONSE, contentToReturn, id);
13201
- return _context3.abrupt("break", 87);
13144
+ return _context3.abrupt("break", 91);
13202
13145
 
13203
- case 33:
13146
+ case 34:
13204
13147
  _this$props11 = this.props, metaFields = _this$props11.metaFields, setState = _this$props11.setState;
13205
13148
  metaData = payload;
13206
13149
  newMetaFields = Container_objectSpread(Container_objectSpread({}, metaFields), metaData);
13207
- _context3.next = 38;
13150
+ _context3.next = 39;
13208
13151
  return setState({
13209
13152
  metaFields: newMetaFields
13210
13153
  });
13211
13154
 
13212
- case 38:
13155
+ case 39:
13213
13156
  localChannel.postMessage(SET_META_FIELDS_RESPONSE, null, id);
13214
- return _context3.abrupt("break", 87);
13157
+ return _context3.abrupt("break", 91);
13215
13158
 
13216
- case 40:
13159
+ case 41:
13217
13160
  _this$props12 = this.props, sensitiveMetaFields = _this$props12.sensitiveMetaFields, _setState = _this$props12.setState;
13218
- _context3.next = 43;
13161
+ _context3.next = 44;
13219
13162
  return _setState({
13220
13163
  sensitiveMetaFields: Container_objectSpread(Container_objectSpread({}, sensitiveMetaFields), payload)
13221
13164
  });
13222
13165
 
13223
- case 43:
13166
+ case 44:
13224
13167
  localChannel.postMessage("SET_SENSITIVE_META_FIELDS_RESPONSE", null, id);
13225
- return _context3.abrupt("break", 87);
13168
+ return _context3.abrupt("break", 91);
13226
13169
 
13227
- case 45:
13170
+ case 46:
13228
13171
  localChannel.postMessage(STOP_RESPONSE, null, id);
13229
13172
  this.unmount();
13230
- return _context3.abrupt("break", 87);
13173
+ return _context3.abrupt("break", 91);
13231
13174
 
13232
- case 48:
13175
+ case 49:
13233
13176
  _ref = payload, greeting = _ref.greeting, language = _ref.language, _newMetaFields = _ref.metaFields, _sensitiveMetaFields = _ref.sensitiveMetaFields, _ref$resetChatHistory = _ref.resetChatHistory, resetChatHistory = _ref$resetChatHistory === void 0 ? true : _ref$resetChatHistory;
13234
13177
  _setState2 = this.props.setState;
13235
13178
  chatHasBeenRendered = this.state.chatHasBeenRendered;
@@ -13241,18 +13184,18 @@ var Container = /*#__PURE__*/function (_Component) {
13241
13184
  };
13242
13185
 
13243
13186
  if (!resetChatHistory) {
13244
- _context3.next = 61;
13187
+ _context3.next = 62;
13245
13188
  break;
13246
13189
  }
13247
13190
 
13248
13191
  if (xStorageChannel) {
13249
- _context3.next = 55;
13192
+ _context3.next = 56;
13250
13193
  break;
13251
13194
  }
13252
13195
 
13253
13196
  throw new errors/* AdaEmbedError */.S("`xStorageChannel` is null");
13254
13197
 
13255
- case 55:
13198
+ case 56:
13256
13199
  xStorageChannel.postMessage(DELETE_HISTORY_EVENT); // Clear chatter data from local storage
13257
13200
 
13258
13201
  safeLocalStorage.removeItem(CHATTER_TOKEN_STORAGE_KEY);
@@ -13265,11 +13208,11 @@ var Container = /*#__PURE__*/function (_Component) {
13265
13208
  chatterCreated: null
13266
13209
  });
13267
13210
 
13268
- case 61:
13269
- _context3.next = 63;
13211
+ case 62:
13212
+ _context3.next = 64;
13270
13213
  return _setState2(newState);
13271
13214
 
13272
- case 63:
13215
+ case 64:
13273
13216
  if (chatHasBeenRendered) {
13274
13217
  this.setState({
13275
13218
  hideChatOverride: true
@@ -13281,48 +13224,48 @@ var Container = /*#__PURE__*/function (_Component) {
13281
13224
  }
13282
13225
 
13283
13226
  localChannel.postMessage(RESET_RESPONSE, null, id);
13284
- return _context3.abrupt("break", 87);
13227
+ return _context3.abrupt("break", 91);
13285
13228
 
13286
- case 66:
13229
+ case 67:
13287
13230
  _setState3 = this.props.setState;
13288
13231
 
13289
13232
  if (xStorageChannel) {
13290
- _context3.next = 69;
13233
+ _context3.next = 70;
13291
13234
  break;
13292
13235
  }
13293
13236
 
13294
13237
  throw new errors/* AdaEmbedError */.S("`xStorageChannel` is null");
13295
13238
 
13296
- case 69:
13239
+ case 70:
13297
13240
  // Clear chatter data from local storage
13298
13241
  safeLocalStorage.removeItem(CHATTER_TOKEN_STORAGE_KEY);
13299
13242
  safeSessionStorage.removeItem(CHATTER_TOKEN_STORAGE_KEY);
13300
13243
  safeLocalStorage.removeItem(CHATTER_CREATED_STORAGE_KEY);
13301
13244
  safeSessionStorage.removeItem(CHATTER_CREATED_STORAGE_KEY); // And from state
13302
13245
 
13303
- _context3.next = 75;
13246
+ _context3.next = 76;
13304
13247
  return _setState3({
13305
13248
  chatterToken: null,
13306
13249
  chatterCreated: null
13307
13250
  });
13308
13251
 
13309
- case 75:
13252
+ case 76:
13310
13253
  xStorageChannel.postMessage(DELETE_HISTORY_EVENT);
13311
13254
  localChannel.postMessage(DELETE_HISTORY_RESPONSE, null, id);
13312
- return _context3.abrupt("break", 87);
13255
+ return _context3.abrupt("break", 91);
13313
13256
 
13314
- case 78:
13257
+ case 79:
13315
13258
  _ref2 = payload, body = _ref2.body, duration = _ref2.duration;
13316
13259
  EXTRA_PROACTIVE_DELAY = 1000;
13317
13260
 
13318
13261
  if (client) {
13319
- _context3.next = 82;
13262
+ _context3.next = 83;
13320
13263
  break;
13321
13264
  }
13322
13265
 
13323
13266
  throw new errors/* AdaEmbedError */.S("`client` is not defined");
13324
13267
 
13325
- case 82:
13268
+ case 83:
13326
13269
  // Do not feature flag gate this behind the developer_proactive flag
13327
13270
  // It's also used for free-tier campaigns, which are available to all clients
13328
13271
  this.setState({
@@ -13362,14 +13305,22 @@ var Container = /*#__PURE__*/function (_Component) {
13362
13305
  }
13363
13306
  }, _callee);
13364
13307
  })));
13365
- _context3.next = 85;
13308
+ _context3.next = 86;
13366
13309
  return wait(duration * 1000 + EXTRA_PROACTIVE_DELAY);
13367
13310
 
13368
- case 85:
13311
+ case 86:
13369
13312
  localChannel.postMessage(CREATE_PROACTIVE_RESPONSE, null, id);
13370
- return _context3.abrupt("break", 87);
13313
+ return _context3.abrupt("break", 91);
13371
13314
 
13372
- case 87:
13315
+ case 88:
13316
+ if (chatChannel) {
13317
+ chatChannel.postMessage(CLOSE_CAMPAIGN);
13318
+ }
13319
+
13320
+ localChannel.postMessage(CLOSE_CAMPAIGN_RESPONSE, null, id);
13321
+ return _context3.abrupt("break", 91);
13322
+
13323
+ case 91:
13373
13324
  case "end":
13374
13325
  return _context3.stop();
13375
13326
  }
@@ -14343,6 +14294,35 @@ var Embed = /*#__PURE__*/function () {
14343
14294
  value: function unsubscribeEvent(id) {
14344
14295
  event_subscriptions_unsubscribeEvent(id);
14345
14296
  }
14297
+ }, {
14298
+ key: "closeCampaign",
14299
+ value: function () {
14300
+ var _closeCampaign = (0,asyncToGenerator/* default */.Z)( /*#__PURE__*/regenerator_default().mark(function _callee13() {
14301
+ return regenerator_default().wrap(function _callee13$(_context13) {
14302
+ while (1) {
14303
+ switch (_context13.prev = _context13.next) {
14304
+ case 0:
14305
+ _context13.next = 2;
14306
+ return this.initialized;
14307
+
14308
+ case 2:
14309
+ _context13.next = 4;
14310
+ return this.localChannel.fetch(CLOSE_CAMPAIGN, CLOSE_CAMPAIGN_RESPONSE);
14311
+
14312
+ case 4:
14313
+ case "end":
14314
+ return _context13.stop();
14315
+ }
14316
+ }
14317
+ }, _callee13, this);
14318
+ }));
14319
+
14320
+ function closeCampaign() {
14321
+ return _closeCampaign.apply(this, arguments);
14322
+ }
14323
+
14324
+ return closeCampaign;
14325
+ }()
14346
14326
  }]);
14347
14327
 
14348
14328
  return Embed;
@@ -14368,7 +14348,7 @@ window.__AdaEmbedConstructor = Embed;
14368
14348
  /* harmony export */ });
14369
14349
  var isModern = new RegExp("((CPU[ +]OS|iPhone[ +]OS|CPU[ +]iPhone|CPU IPhone OS)[ +]+(15|(1[6-9]|[2-9]\\d|\\d{3,}))[_.]\\d+(?:[_.]\\d+)?)|((Chromium|Chrome)\\/(97|(9[8-9]|\\d{3,}))\\.\\d+(?:\\.\\d+)?)|(Version\\/(15|(1[6-9]|[2-9]\\d|\\d{3,}))\\.\\d+(?:\\.\\d+)? Safari\\/)|(Firefox\\/(96|(9[7-9]|\\d{3,}))\\.\\d+\\.\\d+)|(Firefox\\/(96|(9[7-9]|\\d{3,}))\\.\\d+(pre|[ab]\\d+[a-z]*)?)").test(navigator.userAgent);
14370
14350
  var isProduction = "production" === "production";
14371
- var embed2Version = "e5d1f99";
14351
+ var embed2Version = "8e64b86";
14372
14352
 
14373
14353
  /***/ }),
14374
14354
 
@@ -14714,9 +14694,9 @@ function _log() {
14714
14694
  service: "embed",
14715
14695
  env: "production",
14716
14696
  embedVersion: 2,
14717
- version: "1.0.62",
14697
+ version: "1.0.65",
14718
14698
  isNpm: true,
14719
- commitHash: "e5d1f99"
14699
+ commitHash: "8e64b86"
14720
14700
  }))
14721
14701
  });
14722
14702
 
@@ -25639,12 +25619,12 @@ function loadEmbed(_x) {
25639
25619
 
25640
25620
 
25641
25621
  function _loadEmbed() {
25642
- _loadEmbed = (0,asyncToGenerator/* default */.Z)( /*#__PURE__*/regenerator_default().mark(function _callee16(adaSettings) {
25643
- var embedScriptSource, _context16, _context17, polyfillVersionString, host, clientScriptExists;
25622
+ _loadEmbed = (0,asyncToGenerator/* default */.Z)( /*#__PURE__*/regenerator_default().mark(function _callee17(adaSettings) {
25623
+ var embedScriptSource, _context17, _context18, polyfillVersionString, host, clientScriptExists;
25644
25624
 
25645
- return regenerator_default().wrap(function _callee16$(_context18) {
25625
+ return regenerator_default().wrap(function _callee17$(_context19) {
25646
25626
  while (1) {
25647
- switch (_context18.prev = _context18.next) {
25627
+ switch (_context19.prev = _context19.next) {
25648
25628
  case 0:
25649
25629
  if (adaSettings.customDomains) {
25650
25630
  embedScriptSource = config_info/* isModern */.pX ? adaSettings.customDomains.embedModern : adaSettings.customDomains.embedLegacy;
@@ -25657,7 +25637,7 @@ function _loadEmbed() {
25657
25637
  polyfillVersionString = "legacy";
25658
25638
  }
25659
25639
 
25660
- embedScriptSource = concat_default()(_context16 = concat_default()(_context17 = "".concat(host, "/embed/")).call(_context17, polyfillVersionString, "/client/")).call(_context16, "e5d1f99", "/index.js");
25640
+ embedScriptSource = concat_default()(_context17 = concat_default()(_context18 = "".concat(host, "/embed/")).call(_context18, polyfillVersionString, "/client/")).call(_context17, "8e64b86", "/index.js");
25661
25641
  }
25662
25642
 
25663
25643
  clientScriptExists = Boolean( true || // The client script is bundled with npm module
@@ -25667,23 +25647,23 @@ function _loadEmbed() {
25667
25647
  */
25668
25648
 
25669
25649
  if (clientScriptExists) {
25670
- _context18.next = 11;
25650
+ _context19.next = 11;
25671
25651
  break;
25672
25652
  }
25673
25653
 
25674
- _context18.prev = 3;
25675
- _context18.next = 6;
25654
+ _context19.prev = 3;
25655
+ _context19.next = 6;
25676
25656
  return loadScript({
25677
25657
  src: embedScriptSource
25678
25658
  });
25679
25659
 
25680
25660
  case 6:
25681
- _context18.next = 11;
25661
+ _context19.next = 11;
25682
25662
  break;
25683
25663
 
25684
25664
  case 8:
25685
- _context18.prev = 8;
25686
- _context18.t0 = _context18["catch"](3);
25665
+ _context19.prev = 8;
25666
+ _context19.t0 = _context19["catch"](3);
25687
25667
  console.warn("There was an issue creating the embed client script.");
25688
25668
 
25689
25669
  case 11:
@@ -25693,10 +25673,10 @@ function _loadEmbed() {
25693
25673
 
25694
25674
  case 12:
25695
25675
  case "end":
25696
- return _context18.stop();
25676
+ return _context19.stop();
25697
25677
  }
25698
25678
  }
25699
- }, _callee16, null, [[3, 8]]);
25679
+ }, _callee17, null, [[3, 8]]);
25700
25680
  }));
25701
25681
  return _loadEmbed.apply(this, arguments);
25702
25682
  }
@@ -26190,12 +26170,40 @@ function createEmbedObject() {
26190
26170
  }
26191
26171
 
26192
26172
  return unsubscribeEvent;
26173
+ }(),
26174
+ closeCampaign: function () {
26175
+ var _closeCampaign = (0,asyncToGenerator/* default */.Z)( /*#__PURE__*/regenerator_default().mark(function _callee16() {
26176
+ var _embed12;
26177
+
26178
+ return regenerator_default().wrap(function _callee16$(_context16) {
26179
+ while (1) {
26180
+ switch (_context16.prev = _context16.next) {
26181
+ case 0:
26182
+ _context16.next = 2;
26183
+ return waitForEmbedInit();
26184
+
26185
+ case 2:
26186
+ return _context16.abrupt("return", (_embed12 = embed) === null || _embed12 === void 0 ? void 0 : _embed12.closeCampaign());
26187
+
26188
+ case 3:
26189
+ case "end":
26190
+ return _context16.stop();
26191
+ }
26192
+ }
26193
+ }, _callee16);
26194
+ }));
26195
+
26196
+ function closeCampaign() {
26197
+ return _closeCampaign.apply(this, arguments);
26198
+ }
26199
+
26200
+ return closeCampaign;
26193
26201
  }()
26194
26202
  });
26195
26203
  }
26196
26204
  ;// CONCATENATED MODULE: ./src/index-npm.ts
26197
26205
 
26198
- Promise.resolve(/* import() eager */).then(__webpack_require__.bind(__webpack_require__, 9262));
26206
+ Promise.resolve(/* import() eager */).then(__webpack_require__.bind(__webpack_require__, 5265));
26199
26207
  /* harmony default export */ var index_npm = (createEmbedObject());
26200
26208
  }();
26201
26209
  module.exports = __webpack_exports__;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ada-support/embed2",
3
- "version": "1.0.62",
3
+ "version": "1.0.65",
4
4
  "description": "",
5
5
  "main": "dist/npm-entry",
6
6
  "typings": "dist/npm-entry/index.d.ts",
@@ -1,3 +0,0 @@
1
- import { TriggerCondition, URLMatchTriggerCondition } from "./types";
2
- export declare const evalUrlMatchTriggerCondition: (triggerCondition: URLMatchTriggerCondition, url: string) => boolean;
3
- export declare const evalTriggerCondition: (triggerCondition: TriggerCondition) => boolean;