@ada-support/embed2 1.6.24 → 1.6.26

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,39 +1,22 @@
1
- import type { AdaEventKey, AdaEventSubscriptionCallback, CampaignParams, ResetParams, StartOptions, WindowInfo } from "@ada-support/embed-types";
1
+ import type { CampaignParams, ResetParams, StartOptions, WindowInfo } from "@ada-support/embed-types";
2
2
  import { MessageService } from "client/lib/message-service";
3
- import { StoreProxy } from "client/lib/store-proxy";
4
3
  import "client/lib/error-tracker";
5
- import type { Client } from "common/models/client";
6
4
  import type { MetaFieldPayload } from "common/types/store";
7
- import type { CustomEventChannel } from "./lib/ce";
8
- export declare class Embed {
9
- client?: Client;
10
- storage?: Storage;
11
- localChannel: CustomEventChannel;
12
- store: StoreProxy;
13
- messageService: MessageService;
14
- adaSettings: StartOptions;
15
- initialized: Promise<void>;
16
- entryContainer?: HTMLElement;
17
- initializationReject?: (error: Error) => void;
18
- initializationResolve?: () => void;
19
- private debounceCampaignTrigger;
20
- static embed2Version: string;
21
- constructor(adaSettings: StartOptions);
22
- renderPreactApp(): void;
23
- setUpFrameParent(): HTMLElement | null;
24
- toggle(): Promise<void>;
25
- getInfo(): Promise<WindowInfo>;
26
- setMetaFields(options: MetaFieldPayload): Promise<void>;
27
- setSensitiveMetaFields(options: MetaFieldPayload): Promise<void>;
28
- stop(): Promise<void>;
29
- deleteHistory(): Promise<void>;
30
- reset(resetParams?: ResetParams): Promise<void>;
31
- trackEvent(eventKey: string, value: number, meta?: {}): Promise<void>;
32
- triggerCampaign(campaignKey: string, triggerCampaignParams?: {}): Promise<void>;
33
- evaluateCampaignConditions(options: CampaignParams): Promise<void>;
34
- createProactive(body: string, duration: number, responseId?: string): Promise<void>;
35
- subscribeEvent<K extends AdaEventKey>(eventKey: K, callback: AdaEventSubscriptionCallback<K>): number;
36
- unsubscribeEvent(id: number): void;
37
- closeCampaign(): Promise<void>;
38
- setDeviceToken(token: string): Promise<void>;
39
- }
5
+ export declare function createEmbed(adaSettings: StartOptions): {
6
+ readonly initialized: Promise<void>;
7
+ readonly messageService: MessageService;
8
+ readonly toggle: () => Promise<void>;
9
+ readonly getInfo: () => Promise<WindowInfo>;
10
+ readonly setMetaFields: (options: MetaFieldPayload) => Promise<void>;
11
+ readonly setSensitiveMetaFields: (options: MetaFieldPayload) => Promise<void>;
12
+ readonly stop: () => Promise<void>;
13
+ readonly deleteHistory: () => Promise<void>;
14
+ readonly reset: (resetParams?: ResetParams) => Promise<void>;
15
+ readonly trackEvent: (eventKey: string, value: number, meta?: {}) => Promise<void>;
16
+ readonly triggerCampaign: (campaignKey: string, triggerCampaignParams?: {}) => Promise<void>;
17
+ readonly evaluateCampaignConditions: (options: CampaignParams) => Promise<void>;
18
+ readonly createProactive: (body: string, duration: number, responseId?: string) => Promise<void>;
19
+ readonly closeCampaign: () => Promise<void>;
20
+ readonly setDeviceToken: (token: string) => Promise<void>;
21
+ };
22
+ export declare type Embed = ReturnType<typeof createEmbed>;
@@ -7508,46 +7508,6 @@ var lodash_debounce_default = /*#__PURE__*/__webpack_require__.n(lodash_debounce
7508
7508
  var n,l,u,i,t,r,o,f={},e=[],c=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function s(n,l){for(var u in l)n[u]=l[u];return n}function a(n){var l=n.parentNode;l&&l.removeChild(n)}function v(n,l,u){var i,t=arguments,r={};for(i in l)"key"!==i&&"ref"!==i&&(r[i]=l[i]);if(arguments.length>3)for(u=[u],i=3;i<arguments.length;i++)u.push(t[i]);if(null!=u&&(r.children=u),"function"==typeof n&&null!=n.defaultProps)for(i in n.defaultProps)void 0===r[i]&&(r[i]=n.defaultProps[i]);return h(n,r,l&&l.key,l&&l.ref,null)}function h(l,u,i,t,r){var o={type:l,props:u,key:i,ref:t,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,constructor:void 0,__v:r};return null==r&&(o.__v=o),n.vnode&&n.vnode(o),o}function y(){return{current:null}}function p(n){return n.children}function d(n,l){this.props=n,this.context=l}function _(n,l){if(null==l)return n.__?_(n.__,n.__.__k.indexOf(n)+1):null;for(var u;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e)return u.__e;return"function"==typeof n.type?_(n):null}function k(n){var l,u;if(null!=(n=n.__)&&null!=n.__c){for(n.__e=n.__c.base=null,l=0;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e){n.__e=n.__c.base=u.__e;break}return k(n)}}function w(l){(!l.__d&&(l.__d=!0)&&u.push(l)&&!m.__r++||t!==n.debounceRendering)&&((t=n.debounceRendering)||i)(m)}function m(){for(var n;m.__r=u.length;)n=u.sort(function(n,l){return n.__v.__b-l.__v.__b}),u=[],n.some(function(n){var l,u,i,t,r,o,f;n.__d&&(o=(r=(l=n).__v).__e,(f=l.__P)&&(u=[],(i=s({},r)).__v=i,t=T(f,r,i,l.__n,void 0!==f.ownerSVGElement,null,u,null==o?_(r):o),$(u,r),t!=o&&k(r)))})}function g(n,l,u,i,t,r,o,c,s,v){var y,d,k,w,m,g,b,A=i&&i.__k||e,P=A.length;for(s==f&&(s=null!=o?o[0]:P?_(i,0):null),u.__k=[],y=0;y<l.length;y++)if(null!=(w=u.__k[y]=null==(w=l[y])||"boolean"==typeof w?null:"string"==typeof w||"number"==typeof w?h(null,w,null,null,w):Array.isArray(w)?h(p,{children:w},null,null,null):null!=w.__e||null!=w.__c?h(w.type,w.props,w.key,null,w.__v):w)){if(w.__=u,w.__b=u.__b+1,null===(k=A[y])||k&&w.key==k.key&&w.type===k.type)A[y]=void 0;else for(d=0;d<P;d++){if((k=A[d])&&w.key==k.key&&w.type===k.type){A[d]=void 0;break}k=null}m=T(n,w,k=k||f,t,r,o,c,s,v),(d=w.ref)&&k.ref!=d&&(b||(b=[]),k.ref&&b.push(k.ref,null,w),b.push(d,w.__c||m,w)),null!=m?(null==g&&(g=m),s=x(n,w,k,A,o,m,s),"option"==u.type?n.value="":"function"==typeof u.type&&(u.__d=s)):s&&k.__e==s&&s.parentNode!=n&&(s=_(k))}if(u.__e=g,null!=o&&"function"!=typeof u.type)for(y=o.length;y--;)null!=o[y]&&a(o[y]);for(y=P;y--;)null!=A[y]&&I(A[y],A[y]);if(b)for(y=0;y<b.length;y++)H(b[y],b[++y],b[++y])}function b(n){return null==n||"boolean"==typeof n?[]:Array.isArray(n)?e.concat.apply([],n.map(b)):[n]}function x(n,l,u,i,t,r,o){var f,e,c;if(void 0!==l.__d)f=l.__d,l.__d=void 0;else if(t==u||r!=o||null==r.parentNode)n:if(null==o||o.parentNode!==n)n.appendChild(r),f=null;else{for(e=o,c=0;(e=e.nextSibling)&&c<i.length;c+=2)if(e==r)break n;n.insertBefore(r,o),f=o}return void 0!==f?f:r.nextSibling}function A(n,l,u,i,t){var r;for(r in u)"children"===r||"key"===r||r in l||C(n,r,null,u[r],i);for(r in l)t&&"function"!=typeof l[r]||"children"===r||"key"===r||"value"===r||"checked"===r||u[r]===l[r]||C(n,r,l[r],u[r],i)}function P(n,l,u){"-"===l[0]?n.setProperty(l,u):n[l]="number"==typeof u&&!1===c.test(l)?u+"px":null==u?"":u}function C(n,l,u,i,t){var r,o,f,e,c;if(t?"className"===l&&(l="class"):"class"===l&&(l="className"),"style"===l)if(r=n.style,"string"==typeof u)r.cssText=u;else{if("string"==typeof i&&(r.cssText="",i=null),i)for(e in i)u&&e in u||P(r,e,"");if(u)for(c in u)i&&u[c]===i[c]||P(r,c,u[c])}else"o"===l[0]&&"n"===l[1]?(o=l!==(l=l.replace(/Capture$/,"")),f=l.toLowerCase(),l=(f in n?f:l).slice(2),u?(i||n.addEventListener(l,N,o),(n.l||(n.l={}))[l]=u):n.removeEventListener(l,N,o)):"list"!==l&&"tagName"!==l&&"form"!==l&&"type"!==l&&"size"!==l&&!t&&l in n?n[l]=null==u?"":u:"function"!=typeof u&&"dangerouslySetInnerHTML"!==l&&(l!==(l=l.replace(/^xlink:?/,""))?null==u||!1===u?n.removeAttributeNS("http://www.w3.org/1999/xlink",l.toLowerCase()):n.setAttributeNS("http://www.w3.org/1999/xlink",l.toLowerCase(),u):null==u||!1===u&&!/^ar/.test(l)?n.removeAttribute(l):n.setAttribute(l,u))}function N(l){this.l[l.type](n.event?n.event(l):l)}function z(n,l,u){var i,t;for(i=0;i<n.__k.length;i++)(t=n.__k[i])&&(t.__=n,t.__e&&("function"==typeof t.type&&t.__k.length>1&&z(t,l,u),l=x(u,t,t,n.__k,null,t.__e,l),"function"==typeof n.type&&(n.__d=l)))}function T(l,u,i,t,r,o,f,e,c){var a,v,h,y,_,k,w,m,b,x,A,P=u.type;if(void 0!==u.constructor)return null;(a=n.__b)&&a(u);try{n:if("function"==typeof P){if(m=u.props,b=(a=P.contextType)&&t[a.__c],x=a?b?b.props.value:a.__:t,i.__c?w=(v=u.__c=i.__c).__=v.__E:("prototype"in P&&P.prototype.render?u.__c=v=new P(m,x):(u.__c=v=new d(m,x),v.constructor=P,v.render=L),b&&b.sub(v),v.props=m,v.state||(v.state={}),v.context=x,v.__n=t,h=v.__d=!0,v.__h=[]),null==v.__s&&(v.__s=v.state),null!=P.getDerivedStateFromProps&&(v.__s==v.state&&(v.__s=s({},v.__s)),s(v.__s,P.getDerivedStateFromProps(m,v.__s))),y=v.props,_=v.state,h)null==P.getDerivedStateFromProps&&null!=v.componentWillMount&&v.componentWillMount(),null!=v.componentDidMount&&v.__h.push(v.componentDidMount);else{if(null==P.getDerivedStateFromProps&&m!==y&&null!=v.componentWillReceiveProps&&v.componentWillReceiveProps(m,x),!v.__e&&null!=v.shouldComponentUpdate&&!1===v.shouldComponentUpdate(m,v.__s,x)||u.__v===i.__v){v.props=m,v.state=v.__s,u.__v!==i.__v&&(v.__d=!1),v.__v=u,u.__e=i.__e,u.__k=i.__k,v.__h.length&&f.push(v),z(u,e,l);break n}null!=v.componentWillUpdate&&v.componentWillUpdate(m,v.__s,x),null!=v.componentDidUpdate&&v.__h.push(function(){v.componentDidUpdate(y,_,k)})}v.context=x,v.props=m,v.state=v.__s,(a=n.__r)&&a(u),v.__d=!1,v.__v=u,v.__P=l,a=v.render(v.props,v.state,v.context),v.state=v.__s,null!=v.getChildContext&&(t=s(s({},t),v.getChildContext())),h||null==v.getSnapshotBeforeUpdate||(k=v.getSnapshotBeforeUpdate(y,_)),A=null!=a&&a.type==p&&null==a.key?a.props.children:a,g(l,Array.isArray(A)?A:[A],u,i,t,r,o,f,e,c),v.base=u.__e,v.__h.length&&f.push(v),w&&(v.__E=v.__=null),v.__e=!1}else null==o&&u.__v===i.__v?(u.__k=i.__k,u.__e=i.__e):u.__e=j(i.__e,u,i,t,r,o,f,c);(a=n.diffed)&&a(u)}catch(l){u.__v=null,n.__e(l,u,i)}return u.__e}function $(l,u){n.__c&&n.__c(u,l),l.some(function(u){try{l=u.__h,u.__h=[],l.some(function(n){n.call(u)})}catch(l){n.__e(l,u.__v)}})}function j(n,l,u,i,t,r,o,c){var s,a,v,h,y,p=u.props,d=l.props;if(t="svg"===l.type||t,null!=r)for(s=0;s<r.length;s++)if(null!=(a=r[s])&&((null===l.type?3===a.nodeType:a.localName===l.type)||n==a)){n=a,r[s]=null;break}if(null==n){if(null===l.type)return document.createTextNode(d);n=t?document.createElementNS("http://www.w3.org/2000/svg",l.type):document.createElement(l.type,d.is&&{is:d.is}),r=null,c=!1}if(null===l.type)p!==d&&n.data!=d&&(n.data=d);else{if(null!=r&&(r=e.slice.call(n.childNodes)),v=(p=u.props||f).dangerouslySetInnerHTML,h=d.dangerouslySetInnerHTML,!c){if(null!=r)for(p={},y=0;y<n.attributes.length;y++)p[n.attributes[y].name]=n.attributes[y].value;(h||v)&&(h&&v&&h.__html==v.__html||(n.innerHTML=h&&h.__html||""))}A(n,d,p,t,c),h?l.__k=[]:(s=l.props.children,g(n,Array.isArray(s)?s:[s],l,u,i,"foreignObject"!==l.type&&t,r,o,f,c)),c||("value"in d&&void 0!==(s=d.value)&&s!==n.value&&C(n,"value",s,p.value,!1),"checked"in d&&void 0!==(s=d.checked)&&s!==n.checked&&C(n,"checked",s,p.checked,!1))}return n}function H(l,u,i){try{"function"==typeof l?l(u):l.current=u}catch(l){n.__e(l,i)}}function I(l,u,i){var t,r,o;if(n.unmount&&n.unmount(l),(t=l.ref)&&(t.current&&t.current!==l.__e||H(t,null,u)),i||"function"==typeof l.type||(i=null!=(r=l.__e)),l.__e=l.__d=void 0,null!=(t=l.__c)){if(t.componentWillUnmount)try{t.componentWillUnmount()}catch(l){n.__e(l,u)}t.base=t.__P=null}if(t=l.__k)for(o=0;o<t.length;o++)t[o]&&I(t[o],u,i);null!=r&&a(r)}function L(n,l,u){return this.constructor(n,u)}function M(l,u,i){var t,o,c;n.__&&n.__(l,u),o=(t=i===r)?null:i&&i.__k||u.__k,l=v(p,null,[l]),c=[],T(u,(t?u:i||u).__k=l,o||f,f,void 0!==u.ownerSVGElement,i&&!t?[i]:o?null:u.childNodes.length?e.slice.call(u.childNodes):null,c,i||f,t),$(c,l)}function O(n,l){M(n,l,r)}function S(n,l){var u,i;for(i in l=s(s({},n.props),l),arguments.length>2&&(l.children=e.slice.call(arguments,2)),u={},l)"key"!==i&&"ref"!==i&&(u[i]=l[i]);return h(n.type,u,l.key||n.key,l.ref||n.ref,null)}function q(n){var l={},u={__c:"__cC"+o++,__:n,Consumer:function(n,l){return n.children(l)},Provider:function(n){var i,t=this;return this.getChildContext||(i=[],this.getChildContext=function(){return l[u.__c]=t,l},this.shouldComponentUpdate=function(n){t.props.value!==n.value&&i.some(function(l){l.context=n.value,w(l)})},this.sub=function(n){i.push(n);var l=n.componentWillUnmount;n.componentWillUnmount=function(){i.splice(i.indexOf(n),1),l&&l.call(n)}}),n.children}};return u.Consumer.contextType=u,u.Provider.__=u,u}n={__e:function(n,l){for(var u,i;l=l.__;)if((u=l.__c)&&!u.__)try{if(u.constructor&&null!=u.constructor.getDerivedStateFromError&&(i=!0,u.setState(u.constructor.getDerivedStateFromError(n))),null!=u.componentDidCatch&&(i=!0,u.componentDidCatch(n)),i)return w(u.__E=u)}catch(l){n=l}throw n}},l=function(n){return null!=n&&void 0===n.constructor},d.prototype.setState=function(n,l){var u;u=this.__s!==this.state?this.__s:this.__s=s({},this.state),"function"==typeof n&&(n=n(u,this.props)),n&&s(u,n),null!=n&&this.__v&&(l&&this.__h.push(l),w(this))},d.prototype.forceUpdate=function(n){this.__v&&(this.__e=!0,n&&this.__h.push(n),w(this))},d.prototype.render=p,u=[],i="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,m.__r=0,r=f,o=0;
7509
7509
  //# sourceMappingURL=preact.module.js.map
7510
7510
 
7511
- ;// CONCATENATED MODULE: ./src/client/helpers/event-subscriptions/index.ts
7512
- let subscriptions = [];
7513
-
7514
- const getNextUniqueId = (() => {
7515
- let lastId = 0;
7516
- return () => {
7517
- lastId += 1;
7518
- return lastId;
7519
- };
7520
- })();
7521
-
7522
- function unsubscribeEvent(id) {
7523
- subscriptions = subscriptions.filter(s => s.id !== id);
7524
- }
7525
- function subscribeEvent(eventKey, callback) {
7526
- const id = getNextUniqueId();
7527
- subscriptions.push({
7528
- eventKey,
7529
- callback,
7530
- id
7531
- });
7532
- return id;
7533
- }
7534
- function publishEvent(eventKey, data) {
7535
- subscriptions.forEach(subscription => {
7536
- // Using startsWith instead of === allows subscribing to a specific event OR a namespace,
7537
- // e.g. ada:campaigns subscribes to ada:campaigns:opened, ada:campaigns:engaged, and
7538
- // ada:campaigns:shown. Broadcasting this way simultaneously reaches subscriptions
7539
- // that have subscribed to a specific event, and those that have subscribed to a namespace
7540
- if (eventKey.startsWith(subscription.eventKey)) {
7541
- // try/catch to guard against missing or bad callbacks
7542
- try {
7543
- subscription.callback(data, {
7544
- eventKey
7545
- });
7546
- } catch {// silently fail and proceed with remaining callbacks
7547
- }
7548
- }
7549
- });
7550
- }
7551
7511
  ;// CONCATENATED MODULE: ./src/client/lib/contexts.ts
7552
7512
 
7553
7513
  const StoreContext = q(null);
@@ -15917,7 +15877,7 @@ const client = new error_tracker_BrowserClient({
15917
15877
  },
15918
15878
 
15919
15879
  environment: "production",
15920
- release: "1.6.24-6882ca0",
15880
+ release: "1.6.26-32e415b",
15921
15881
  sampleRate: 0.25,
15922
15882
  autoSessionTracking: false,
15923
15883
  // Integrations don't seem to work with Sentry: https://github.com/getsentry/sentry-javascript/issues/2541
@@ -16441,6 +16401,46 @@ let ActionTypes;
16441
16401
  ActionTypes["SET_CONNECTION_STATE_TYPE"] = "SET_CONNECTION_STATE";
16442
16402
  ActionTypes["INCREMENT_MESSAGE_COUNT_TYPE"] = "INCREMENT_MESSAGE_COUNT";
16443
16403
  })(ActionTypes || (ActionTypes = {}));
16404
+ ;// CONCATENATED MODULE: ./src/client/helpers/event-subscriptions/index.ts
16405
+ let subscriptions = [];
16406
+
16407
+ const getNextUniqueId = (() => {
16408
+ let lastId = 0;
16409
+ return () => {
16410
+ lastId += 1;
16411
+ return lastId;
16412
+ };
16413
+ })();
16414
+
16415
+ function unsubscribeEvent(id) {
16416
+ subscriptions = subscriptions.filter(s => s.id !== id);
16417
+ }
16418
+ function subscribeEvent(eventKey, callback) {
16419
+ const id = getNextUniqueId();
16420
+ subscriptions.push({
16421
+ eventKey,
16422
+ callback,
16423
+ id
16424
+ });
16425
+ return id;
16426
+ }
16427
+ function publishEvent(eventKey, data) {
16428
+ subscriptions.forEach(subscription => {
16429
+ // Using startsWith instead of === allows subscribing to a specific event OR a namespace,
16430
+ // e.g. ada:campaigns subscribes to ada:campaigns:opened, ada:campaigns:engaged, and
16431
+ // ada:campaigns:shown. Broadcasting this way simultaneously reaches subscriptions
16432
+ // that have subscribed to a specific event, and those that have subscribed to a namespace
16433
+ if (eventKey.startsWith(subscription.eventKey)) {
16434
+ // try/catch to guard against missing or bad callbacks
16435
+ try {
16436
+ subscription.callback(data, {
16437
+ eventKey
16438
+ });
16439
+ } catch {// silently fail and proceed with remaining callbacks
16440
+ }
16441
+ }
16442
+ });
16443
+ }
16444
16444
  // EXTERNAL MODULE: ./node_modules/@babel/runtime-corejs3/core-js-stable/url.js
16445
16445
  var url = __webpack_require__(9969);
16446
16446
  var url_default = /*#__PURE__*/__webpack_require__.n(url);
@@ -16547,7 +16547,7 @@ function getEmbedURL(_ref) {
16547
16547
  host = "http://".concat(window.location.hostname, ":9001");
16548
16548
  }
16549
16549
 
16550
- return "".concat(host, "/embed/").concat(frameName, "/").concat("6882ca0", "/index.html");
16550
+ return "".concat(host, "/embed/").concat(frameName, "/").concat("32e415b", "/index.html");
16551
16551
  }
16552
16552
 
16553
16553
  function constructQueryString(query) {
@@ -18199,9 +18199,9 @@ async function log(message, extra, options) {
18199
18199
  service: "embed",
18200
18200
  env: "production",
18201
18201
  embedVersion: 2,
18202
- version: "1.6.24",
18202
+ version: "1.6.26",
18203
18203
  isNpm: true,
18204
- commitHash: "6882ca0"
18204
+ commitHash: "32e415b"
18205
18205
  }))
18206
18206
  });
18207
18207
  }
@@ -18771,7 +18771,7 @@ class ChatFrame extends d {
18771
18771
  const hostPageUrlParams = new (url_default())(window.location.href).searchParams;
18772
18772
  const smsToken = hostPageUrlParams.get("adaSMSToken");
18773
18773
  const queryParams = {
18774
- embedVersion: "6882ca0".slice(0, 7),
18774
+ embedVersion: "32e415b".slice(0, 7),
18775
18775
  greeting,
18776
18776
  language,
18777
18777
  skipGreeting,
@@ -20776,219 +20776,202 @@ function embed_objectSpread(target) { for (var i = 1; i < arguments.length; i++)
20776
20776
 
20777
20777
 
20778
20778
 
20779
- class Embed {
20780
- constructor(adaSettings) {
20781
- var _this = this;
20782
-
20783
- _defineProperty(this, "client", void 0);
20784
-
20785
- _defineProperty(this, "storage", void 0);
20786
-
20787
- _defineProperty(this, "localChannel", void 0);
20788
-
20789
- _defineProperty(this, "store", void 0);
20790
-
20791
- _defineProperty(this, "messageService", void 0);
20792
-
20793
- _defineProperty(this, "adaSettings", void 0);
20794
-
20795
- _defineProperty(this, "initialized", void 0);
20796
-
20797
- _defineProperty(this, "entryContainer", void 0);
20798
-
20799
- _defineProperty(this, "initializationReject", void 0);
20800
-
20801
- _defineProperty(this, "initializationResolve", void 0);
20802
-
20803
- _defineProperty(this, "debounceCampaignTrigger", void 0);
20804
-
20805
- this.adaSettings = adaSettings;
20806
- this.messageService = new MessageService();
20807
- const initialState = getInitialState(adaSettings);
20808
- this.store = new StoreProxy(initialState, this.messageService);
20809
- this.localChannel = this.messageService.channels.local;
20810
- this.initialized = new Promise((resolve, reject) => {
20811
- this.initializationResolve = resolve;
20812
- this.initializationReject = reject;
20813
- });
20814
- this.renderPreactApp();
20815
- this.debounceCampaignTrigger = lodash_debounce_default()(async function (campaignKey) {
20816
- let triggerCampaignParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
20817
- await _this.initialized;
20818
- await _this.localChannel.fetch(TRIGGER_CAMPAIGN, TRIGGER_CAMPAIGN_RESPONSE, embed_objectSpread({
20819
- campaignKey
20820
- }, triggerCampaignParams));
20821
- }, 1000, {
20822
- leading: true
20779
+ function renderApp(_ref) {
20780
+ let {
20781
+ adaSettings,
20782
+ initializationResolve,
20783
+ initializationReject,
20784
+ messageService,
20785
+ store
20786
+ } = _ref;
20787
+ let parentContainer;
20788
+ const entryContainer = document.createElement("div");
20789
+ entryContainer.id = "ada-entry";
20790
+
20791
+ if (adaSettings.parentElement) {
20792
+ // Just to reduce the diff size in PR (can be removed)
20793
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
20794
+ parentContainer = getParentContainer({
20795
+ adaSettings
20823
20796
  });
20797
+ entryContainer.style.height = "100%";
20798
+ } else {
20799
+ parentContainer = document.body;
20824
20800
  }
20825
20801
 
20826
- renderPreactApp() {
20827
- let parentContainer;
20828
- this.entryContainer = document.createElement("div");
20829
- this.entryContainer.id = "ada-entry";
20830
-
20831
- if (this.adaSettings.parentElement) {
20832
- parentContainer = this.setUpFrameParent();
20833
- this.entryContainer.style.height = "100%";
20834
- } else {
20835
- parentContainer = document.body;
20836
- }
20837
-
20838
- if (!parentContainer) {
20839
- throw new AdaEmbedError("`parentContainer` is null");
20840
- }
20841
-
20842
- parentContainer.appendChild(this.entryContainer);
20843
- M(v(StoreContext.Provider, {
20844
- value: this.store
20845
- }, v(MessageServiceContext.Provider, {
20846
- value: this.messageService
20847
- }, v(ConnectedContainer, {
20848
- store: this.store,
20849
- messageService: this.messageService,
20850
- adaSettings: this.adaSettings,
20851
- entryContainer: this.entryContainer,
20852
- initializationReject: this.initializationReject,
20853
- initializationResolve: this.initializationResolve
20854
- }))), this.entryContainer);
20802
+ if (!parentContainer) {
20803
+ throw new AdaEmbedError("`parentContainer` is null");
20855
20804
  }
20856
20805
 
20857
- setUpFrameParent() {
20858
- const {
20859
- parentElement
20860
- } = this.adaSettings;
20861
- let targetElement = null;
20862
-
20863
- if (!parentElement) {
20864
- return null;
20865
- }
20866
-
20867
- if (typeof parentElement === "string") {
20868
- targetElement = document.getElementById(parentElement);
20869
- } else if (parentElement instanceof HTMLElement) {
20870
- targetElement = parentElement;
20871
- }
20806
+ parentContainer.appendChild(entryContainer);
20807
+ M(v(StoreContext.Provider, {
20808
+ value: store
20809
+ }, v(MessageServiceContext.Provider, {
20810
+ value: messageService
20811
+ }, v(ConnectedContainer, {
20812
+ store: store,
20813
+ messageService: messageService,
20814
+ adaSettings: adaSettings,
20815
+ entryContainer: entryContainer,
20816
+ initializationReject: initializationReject,
20817
+ initializationResolve: initializationResolve
20818
+ }))), entryContainer);
20819
+ }
20872
20820
 
20873
- if (!targetElement) {
20874
- throw new AdaEmbedError("parentElement requires a string or HTMLElement.");
20875
- }
20821
+ function getParentContainer(_ref2) {
20822
+ let {
20823
+ adaSettings
20824
+ } = _ref2;
20825
+ const {
20826
+ parentElement
20827
+ } = adaSettings;
20828
+ let targetElement = null;
20876
20829
 
20877
- return targetElement;
20830
+ if (!parentElement) {
20831
+ return null;
20878
20832
  }
20879
20833
 
20880
- async toggle() {
20881
- if (this.adaSettings.parentElement) {
20882
- throw new AdaEmbedError("Cannot toggle when using parentElement.");
20883
- }
20884
-
20885
- await this.initialized;
20886
- await this.localChannel.fetch(TOGGLE, TOGGLE_RESPONSE);
20834
+ if (typeof parentElement === "string") {
20835
+ targetElement = document.getElementById(parentElement);
20836
+ } else if (parentElement instanceof HTMLElement) {
20837
+ targetElement = parentElement;
20887
20838
  }
20888
20839
 
20889
- async getInfo() {
20890
- await this.initialized;
20891
- return this.localChannel.fetch(GET_INFO, GET_INFO_RESPONSE);
20840
+ if (!targetElement) {
20841
+ throw new AdaEmbedError("parentElement requires a string or HTMLElement.");
20892
20842
  }
20893
20843
 
20894
- async setMetaFields(options) {
20895
- await this.initialized;
20896
- await this.localChannel.fetch(SET_META_FIELDS, SET_META_FIELDS_RESPONSE, options);
20897
- }
20844
+ return targetElement;
20845
+ }
20898
20846
 
20899
- async setSensitiveMetaFields(options) {
20900
- await this.initialized;
20901
- await this.localChannel.fetch("SET_SENSITIVE_META_FIELDS", "SET_SENSITIVE_META_FIELDS_RESPONSE", options);
20902
- }
20847
+ function createEmbed(adaSettings) {
20848
+ const messageService = new MessageService();
20849
+ const localChannel = messageService.channels.local;
20850
+ const initialState = getInitialState(adaSettings);
20851
+ const store = new StoreProxy(initialState, messageService);
20852
+ const initialized = new Promise((resolve, reject) => {
20853
+ renderApp({
20854
+ adaSettings,
20855
+ messageService,
20856
+ store,
20857
+ initializationResolve: resolve,
20858
+ initializationReject: reject
20859
+ });
20860
+ });
20861
+ const debounceCampaignTrigger = lodash_debounce_default()(async function (campaignKey) {
20862
+ let triggerCampaignParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
20863
+ await initialized;
20864
+ await localChannel.fetch(TRIGGER_CAMPAIGN, TRIGGER_CAMPAIGN_RESPONSE, embed_objectSpread({
20865
+ campaignKey
20866
+ }, triggerCampaignParams));
20867
+ }, 1000, {
20868
+ leading: true
20869
+ });
20870
+ return {
20871
+ initialized,
20872
+ messageService,
20903
20873
 
20904
- async stop() {
20905
- await this.initialized;
20906
- await this.localChannel.fetch(STOP, STOP_RESPONSE);
20907
- }
20874
+ async toggle() {
20875
+ if (adaSettings.parentElement) {
20876
+ throw new AdaEmbedError("Cannot toggle when using parentElement.");
20877
+ }
20908
20878
 
20909
- async deleteHistory() {
20910
- await this.initialized;
20911
- await this.localChannel.fetch(DELETE_HISTORY, DELETE_HISTORY_RESPONSE);
20912
- }
20879
+ await initialized;
20880
+ await localChannel.fetch(TOGGLE, TOGGLE_RESPONSE);
20881
+ },
20913
20882
 
20914
- async reset() {
20915
- let resetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
20916
- await this.initialized;
20917
- await this.localChannel.fetch(RESET, RESET_RESPONSE, resetParams);
20918
- }
20883
+ async getInfo() {
20884
+ await initialized;
20885
+ return await localChannel.fetch(GET_INFO, GET_INFO_RESPONSE);
20886
+ },
20919
20887
 
20920
- async trackEvent(eventKey, value) {
20921
- let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
20922
- await this.initialized;
20923
- await this.localChannel.fetch(TRACK_EVENT, TRACK_EVENT_RESPONSE, {
20924
- eventKey,
20925
- value,
20926
- meta
20927
- });
20928
- }
20888
+ async setMetaFields(options) {
20889
+ await initialized;
20890
+ await localChannel.fetch(SET_META_FIELDS, SET_META_FIELDS_RESPONSE, options);
20891
+ },
20929
20892
 
20930
- async triggerCampaign(campaignKey) {
20931
- let triggerCampaignParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
20932
- this.debounceCampaignTrigger(campaignKey, triggerCampaignParams);
20933
- }
20893
+ async setSensitiveMetaFields(options) {
20894
+ await initialized;
20895
+ await localChannel.fetch("SET_SENSITIVE_META_FIELDS", "SET_SENSITIVE_META_FIELDS_RESPONSE", options);
20896
+ },
20934
20897
 
20935
- async evaluateCampaignConditions(options) {
20936
- await this.initialized;
20937
- await this.localChannel.fetch(EVAL_CAMPAIGN_CONDITIONS, EVAL_CAMPAIGN_CONDITIONS_RESPONSE, options);
20938
- }
20898
+ async stop() {
20899
+ await initialized;
20900
+ await localChannel.fetch(STOP, STOP_RESPONSE);
20901
+ },
20939
20902
 
20940
- async createProactive(body, duration, responseId) {
20941
- if (this.adaSettings.parentElement) {
20942
- throw new AdaEmbedError("Cannot call createProactive when using parentElement.");
20943
- }
20903
+ async deleteHistory() {
20904
+ await initialized;
20905
+ await localChannel.fetch(DELETE_HISTORY, DELETE_HISTORY_RESPONSE);
20906
+ },
20944
20907
 
20945
- await this.initialized;
20908
+ async reset() {
20909
+ let resetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
20910
+ await initialized;
20911
+ await localChannel.fetch(RESET, RESET_RESPONSE, resetParams);
20912
+ },
20946
20913
 
20947
- try {
20948
- await this.localChannel.fetch(CREATE_PROACTIVE, CREATE_PROACTIVE_RESPONSE, {
20949
- body,
20950
- duration,
20951
- responseId
20952
- }, // The timeoutOverride is the duration the proactive is open for, plus a
20953
- // 2s buffer. Without this, a very long duration could exceed the
20954
- // default timeout.
20955
- duration * 1000 + 2000);
20956
- } catch (e) {
20957
- throw new AdaEmbedError("".concat(e));
20958
- }
20959
- } // We want it in the class so clients can do `adaEmbed.subscribeEvent`
20960
- // eslint-disable-next-line class-methods-use-this
20914
+ async trackEvent(eventKey, value) {
20915
+ let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
20916
+ await initialized;
20917
+ await localChannel.fetch(TRACK_EVENT, TRACK_EVENT_RESPONSE, {
20918
+ eventKey,
20919
+ value,
20920
+ meta
20921
+ });
20922
+ },
20961
20923
 
20924
+ async triggerCampaign(campaignKey) {
20925
+ let triggerCampaignParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
20926
+ debounceCampaignTrigger(campaignKey, triggerCampaignParams);
20927
+ },
20962
20928
 
20963
- subscribeEvent(eventKey, callback) {
20964
- return subscribeEvent(eventKey, callback);
20965
- } // eslint-disable-next-line class-methods-use-this
20929
+ async evaluateCampaignConditions(options) {
20930
+ await initialized;
20931
+ await localChannel.fetch(EVAL_CAMPAIGN_CONDITIONS, EVAL_CAMPAIGN_CONDITIONS_RESPONSE, options);
20932
+ },
20966
20933
 
20934
+ async createProactive(body, duration, responseId) {
20935
+ if (adaSettings.parentElement) {
20936
+ throw new AdaEmbedError("Cannot call createProactive when using parentElement.");
20937
+ }
20967
20938
 
20968
- unsubscribeEvent(id) {
20969
- unsubscribeEvent(id);
20970
- }
20939
+ await initialized;
20971
20940
 
20972
- async closeCampaign() {
20973
- await this.initialized;
20974
- await this.localChannel.fetch(CLOSE_CAMPAIGN, CLOSE_CAMPAIGN_RESPONSE);
20975
- }
20941
+ try {
20942
+ await localChannel.fetch(CREATE_PROACTIVE, CREATE_PROACTIVE_RESPONSE, {
20943
+ body,
20944
+ duration,
20945
+ responseId
20946
+ }, // The timeoutOverride is the duration the proactive is open for, plus a
20947
+ // 2s buffer. Without this, a very long duration could exceed the
20948
+ // default timeout.
20949
+ duration * 1000 + 2000);
20950
+ } catch (e) {
20951
+ throw new AdaEmbedError("".concat(e));
20952
+ }
20953
+ },
20976
20954
 
20977
- async setDeviceToken(token) {
20978
- await this.initialized;
20979
- await this.localChannel.fetch(SET_DEVICE_TOKEN, SET_DEVICE_TOKEN_RESPONSE, {
20980
- token
20981
- });
20982
- }
20955
+ async closeCampaign() {
20956
+ await initialized;
20957
+ await localChannel.fetch(CLOSE_CAMPAIGN, CLOSE_CAMPAIGN_RESPONSE);
20958
+ },
20983
20959
 
20984
- }
20960
+ async setDeviceToken(token) {
20961
+ await initialized;
20962
+ await localChannel.fetch(SET_DEVICE_TOKEN, SET_DEVICE_TOKEN_RESPONSE, {
20963
+ token
20964
+ });
20965
+ }
20985
20966
 
20986
- _defineProperty(Embed, "embed2Version", "6882ca0");
20967
+ };
20968
+ }
20987
20969
  ;// CONCATENATED MODULE: ./src/interface.ts
20988
20970
 
20989
20971
 
20990
20972
 
20991
20973
 
20974
+
20992
20975
  const EMBED_NOT_INITIALIZED_ERROR = new AdaEmbedError("Actions cannot be called until Embed has been instantiated. Try running `adaEmbed.start({...})`.");
20993
20976
  /**
20994
20977
  * Returns the public Embed methods to be bound to the window object.
@@ -21006,7 +20989,7 @@ function createEmbedInterface() {
21006
20989
  throw new AdaEmbedError("Ada Embed has already been started.");
21007
20990
  }
21008
20991
 
21009
- embed = new Embed(adaSettings);
20992
+ embed = createEmbed(adaSettings);
21010
20993
 
21011
20994
  if (window.adaEmbedLoadedCallback) {
21012
20995
  window.adaEmbedLoadedCallback();
@@ -21071,7 +21054,7 @@ function createEmbedInterface() {
21071
21054
 
21072
21055
  log("Embed reset", {
21073
21056
  initialURL: window.location.href,
21074
- // not sure if the handle will be present so adding the URL to help out with id'ing the client
21057
+ // not sure if the handle will be present so adding the URL to help out with identifying the client
21075
21058
  resetChatHistory: resetParams === null || resetParams === void 0 ? void 0 : resetParams.resetChatHistory,
21076
21059
  greeting: resetParams === null || resetParams === void 0 ? void 0 : resetParams.greeting
21077
21060
  });
@@ -21112,20 +21095,8 @@ function createEmbedInterface() {
21112
21095
 
21113
21096
  return embed.evaluateCampaignConditions(options);
21114
21097
  },
21115
- subscribeEvent: async (eventKey, callback) => {
21116
- if (!embed) {
21117
- throw EMBED_NOT_INITIALIZED_ERROR;
21118
- }
21119
-
21120
- return embed.subscribeEvent(eventKey, callback);
21121
- },
21122
- unsubscribeEvent: async id => {
21123
- if (!embed) {
21124
- throw EMBED_NOT_INITIALIZED_ERROR;
21125
- }
21126
-
21127
- return embed.unsubscribeEvent(id);
21128
- },
21098
+ subscribeEvent: async (eventKey, callback) => subscribeEvent(eventKey, callback),
21099
+ unsubscribeEvent: async id => unsubscribeEvent(id),
21129
21100
  closeCampaign: async () => {
21130
21101
  if (!embed) {
21131
21102
  throw EMBED_NOT_INITIALIZED_ERROR;
@@ -21146,7 +21117,12 @@ function createEmbedInterface() {
21146
21117
  }
21147
21118
 
21148
21119
  const channel = embed.messageService.getChannel("chat");
21149
- channel === null || channel === void 0 ? void 0 : channel.postMessage("SET_LANGUAGE", {
21120
+
21121
+ if (!channel) {
21122
+ throw new AdaEmbedError("Chat is not ready yet to have language changed.");
21123
+ }
21124
+
21125
+ channel.postMessage("SET_LANGUAGE", {
21150
21126
  language
21151
21127
  });
21152
21128
  },
@@ -21167,7 +21143,12 @@ function createEmbedInterface() {
21167
21143
  }
21168
21144
 
21169
21145
  const channel = embed.messageService.getChannel("chat");
21170
- channel === null || channel === void 0 ? void 0 : channel.postMessage("TRIGGER_ANSWER", {
21146
+
21147
+ if (!channel) {
21148
+ throw new AdaEmbedError("Chat is not ready yet to have answer triggered.");
21149
+ }
21150
+
21151
+ channel.postMessage("TRIGGER_ANSWER", {
21171
21152
  answerId
21172
21153
  });
21173
21154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ada-support/embed2",
3
- "version": "1.6.24",
3
+ "version": "1.6.26",
4
4
  "description": "",
5
5
  "main": "dist/npm-entry",
6
6
  "typings": "dist/npm-entry/index-npm.d.ts",