@saasquatch/squatch-js 2.6.0-8 → 2.6.0-9

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/coverage/clover.xml +584 -569
  3. package/coverage/coverage-final.json +20 -19
  4. package/coverage/lcov.info +965 -937
  5. package/dist/async.d.ts +2 -0
  6. package/dist/globals.d.ts +4 -0
  7. package/dist/squatch.esm.js +41 -27
  8. package/dist/squatch.esm.js.map +1 -1
  9. package/dist/squatch.js +41 -27
  10. package/dist/squatch.js.map +1 -1
  11. package/dist/squatch.min.js +1 -1
  12. package/dist/utils/validate.d.ts +0 -2
  13. package/dist/widgets/PopupWidget.d.ts +2 -2
  14. package/dist/widgets/declarative/DeclarativeWidget.d.ts +5 -0
  15. package/package.json +1 -1
  16. package/coverage/lcov-report/DeclarativeWidget.ts.html +0 -790
  17. package/coverage/lcov-report/WidgetApi.ts.html +0 -631
  18. package/coverage/lcov-report/Widgets.ts.html +0 -1105
  19. package/coverage/lcov-report/api/AnalyticsApi.ts.html +0 -304
  20. package/coverage/lcov-report/api/EventsApi.ts.html +0 -352
  21. package/coverage/lcov-report/api/WidgetApi.ts.html +0 -658
  22. package/coverage/lcov-report/api/graphql.ts.html +0 -130
  23. package/coverage/lcov-report/squatch.ts.html +0 -721
  24. package/coverage/lcov-report/utils/cookieUtils.ts.html +0 -415
  25. package/coverage/lcov-report/utils/decodeUserJwt.ts.html +0 -133
  26. package/coverage/lcov-report/utils/domready.ts.html +0 -160
  27. package/coverage/lcov-report/utils/io.ts.html +0 -400
  28. package/coverage/lcov-report/utils/utmUtils.ts.html +0 -277
  29. package/coverage/lcov-report/utils/validate.ts.html +0 -268
  30. package/coverage/lcov-report/validate.ts.html +0 -268
  31. package/coverage/lcov-report/widgets/EmbedWidget.ts.html +0 -481
  32. package/coverage/lcov-report/widgets/PopupWidget.ts.html +0 -685
  33. package/coverage/lcov-report/widgets/Widget.ts.html +0 -1159
  34. package/coverage/lcov-report/widgets/Widgets.ts.html +0 -1102
  35. package/coverage/lcov-report/widgets/declarative/DeclarativeWidget.ts.html +0 -790
  36. package/coverage/lcov-report/widgets/declarative/DeclarativeWidgets.ts.html +0 -388
  37. package/dist/squatch.min.js.map +0 -1
  38. package/dist/squatch.modern.js +0 -2
  39. package/dist/squatch.modern.js.map +0 -1
  40. package/dist/stats.html +0 -208
  41. package/dist/utils/domUtils.d.ts +0 -1
  42. package/dist/utils/loadEvent.d.ts +0 -2
  43. package/dist/widgets/CtaWidget.d.ts +0 -24
  44. package/dist/widgets/IREmbedWidget.d.ts +0 -29
  45. package/dist/widgets/IRPopupWidget.d.ts +0 -32
  46. package/dist/widgets/declarative/DeclarativeEmbedWidget.d.ts +0 -12
  47. package/stats.json +0 -1
package/dist/async.d.ts CHANGED
@@ -5,6 +5,8 @@ declare global {
5
5
  _squatch?: {
6
6
  ready: any[];
7
7
  };
8
+ impactOnReady?: () => {};
9
+ squatchOnReady?: () => {};
8
10
  squatch: any;
9
11
  widgetIdent: any;
10
12
  squatchTenant: string;
@@ -0,0 +1,4 @@
1
+ export declare const DEFAULT_DOMAIN = "https://app.referralsaasquatch.com";
2
+ export declare const DEFAULT_NPM_CDN = "https://fast.ssqt.io/npm";
3
+ export declare const DEFAULT_NAMESPACE = "squatch";
4
+ export declare const IMPACT_NAMESPACE = "impact";
@@ -36,6 +36,9 @@ function _objectWithoutPropertiesLoose(source, excluded) {
36
36
 
37
37
  var DEFAULT_DOMAIN = "https://app.referralsaasquatch.com";
38
38
  var DEFAULT_NPM_CDN = "https://fast.ssqt.io/npm";
39
+ var DEFAULT_NAMESPACE = "squatch";
40
+ var IMPACT_NAMESPACE = "impact";
41
+
39
42
  function validateConfig(_raw) {
40
43
  if (typeof _raw !== "object") throw new Error("config must be an object");
41
44
  var tenant = window.squatchTenant;
@@ -337,12 +340,11 @@ function _buildParams(_ref) {
337
340
  engagementMedium,
338
341
  locale
339
342
  } = _ref;
340
- var engagementMediumP = "engagementMedium=" + encodeURIComponent(engagementMedium);
341
- var widgetTypeP = widgetType && "widgetType=" + encodeURIComponent(widgetType);
342
- var localeP = locale && "locale=" + encodeURIComponent(locale);
343
- var params = [engagementMediumP, widgetTypeP, localeP].filter(x => !!x);
344
- var queryString = "?" + params.join("&");
345
- return queryString;
343
+ var queryParams = new URLSearchParams();
344
+ queryParams.append("engagementMedium", engagementMedium);
345
+ if (widgetType) queryParams.append("widgetType", widgetType);
346
+ if (locale) queryParams.append("locale", locale);
347
+ return "?" + queryParams.toString();
346
348
  }
347
349
 
348
350
  // @ts-check
@@ -437,7 +439,7 @@ class Widget {
437
439
  domain: params.domain
438
440
  });
439
441
  this.context = params.context;
440
- this.container = params.context.container;
442
+ this.container = params.container || params.context.container;
441
443
  }
442
444
 
443
445
  _findElement() {
@@ -460,12 +462,12 @@ class Widget {
460
462
  _log$8("container must be an HTMLElement or string", this.container); // find element on page
461
463
 
462
464
  } else {
463
- element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed");
465
+ element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed") || document.querySelector("#impactembed") || document.querySelector(".impactembed");
464
466
 
465
467
  _log$8("loading widget with default selector", element);
466
468
  }
467
469
 
468
- if (!(element instanceof HTMLElement)) throw new Error("element with selector '" + (this.container || "#squatchembed or .squatchembed") + "' not found.'");
470
+ if (!(element instanceof HTMLElement)) throw new Error("element with selector '" + (this.container || "#squatchembed, .squatchembed, #impactembed, or .impactembed") + "' not found.'");
469
471
  return element;
470
472
  }
471
473
 
@@ -807,20 +809,19 @@ class EmbedWidget extends Widget {
807
809
 
808
810
 
809
811
  open() {
810
- var _frame$contentDocumen, _frame$contentWindow, _frame$contentWindow2;
811
-
812
812
  var frame = this._findFrame();
813
813
 
814
814
  if (!frame) return _log$7("no target element to open");
815
+ if (!frame.contentWindow) return _log$7("Frame needs a content window");
815
816
 
816
817
  var element = this._findElement();
817
818
 
818
819
  element.style.visibility = "unset";
819
820
  element.style.height = "auto";
820
821
  element.style["overflow-y"] = "auto";
821
- frame == null ? void 0 : (_frame$contentDocumen = frame.contentDocument) == null ? void 0 : _frame$contentDocumen.dispatchEvent(new CustomEvent("sq:refresh"));
822
+ frame.contentWindow.document.dispatchEvent(new CustomEvent("sq:refresh"));
822
823
 
823
- var _sqh = (frame == null ? void 0 : (_frame$contentWindow = frame.contentWindow) == null ? void 0 : _frame$contentWindow.squatch) || (frame == null ? void 0 : (_frame$contentWindow2 = frame.contentWindow) == null ? void 0 : _frame$contentWindow2.widgetIdent);
824
+ var _sqh = frame.contentWindow.squatch || frame.contentWindow.widgetIdent;
824
825
 
825
826
  if (this.context.user) {
826
827
  this._loadEvent(_sqh);
@@ -912,7 +913,7 @@ class PopupWidget extends Widget {
912
913
  try {
913
914
  triggerElement
914
915
  /* HTMLButton */
915
- = document.querySelector(this.trigger);
916
+ = document.querySelector(this.trigger) || document.querySelector(".impactpop");
916
917
  if (this.trigger && !triggerElement) _log$6("No element found with trigger selector", this.trigger);
917
918
  } catch (_unused) {
918
919
  _log$6("Not a valid selector", this.trigger);
@@ -940,7 +941,7 @@ class PopupWidget extends Widget {
940
941
  return dialog;
941
942
  }
942
943
 
943
- load() {
944
+ async load() {
944
945
  var _dialogParent$lastChi;
945
946
 
946
947
  var frame = this._createFrame();
@@ -978,10 +979,10 @@ class PopupWidget extends Widget {
978
979
 
979
980
  _log$6("Popup template loaded into iframe");
980
981
 
981
- this._setupResizeHandler(frame);
982
+ await this._setupResizeHandler(frame);
982
983
  }
983
984
 
984
- _setupResizeHandler(frame) {
985
+ async _setupResizeHandler(frame) {
985
986
  var {
986
987
  contentWindow
987
988
  } = frame;
@@ -1483,16 +1484,17 @@ function _validateTrackOptions(raw) {
1483
1484
  }
1484
1485
 
1485
1486
  /** @hidden */
1487
+
1486
1488
  function asyncLoad() {
1487
- var impactNamespace = "impactTBD";
1488
- var namespace = window[impactNamespace] ? impactNamespace : "squatch";
1489
+ var namespace = window[IMPACT_NAMESPACE] ? IMPACT_NAMESPACE : DEFAULT_NAMESPACE;
1489
1490
  var loaded = window[namespace] || null;
1490
1491
  var cached = window["_" + namespace] || null;
1492
+ var declarativeCache = window.impactOnReady || window.squatchOnReady;
1493
+ setTimeout(() => window[IMPACT_NAMESPACE] = window[DEFAULT_NAMESPACE], 0);
1494
+ if (declarativeCache) setTimeout(() => declarativeCache(), 0);
1491
1495
 
1492
- if (loaded && cached) {
1493
- var ready = cached.ready || [];
1494
- setTimeout(() => window["impactTBD"] = window.squatch, 0);
1495
- ready.forEach(cb => setTimeout(() => cb(), 0));
1496
+ if (loaded) {
1497
+ if (cached) (cached.ready || []).forEach(cb => setTimeout(() => cb(), 0));
1496
1498
  setTimeout(() => {
1497
1499
  window.squatch._auto();
1498
1500
  }, 0); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
@@ -1755,6 +1757,11 @@ class DeclarativeWidget extends HTMLElement {
1755
1757
  * Container element to contain the widget iframe
1756
1758
  * @default this
1757
1759
  */
1760
+
1761
+ /**
1762
+ * Flag for if the component has been loaded or not
1763
+ * @hidden
1764
+ */
1758
1765
  constructor() {
1759
1766
  super();
1760
1767
  this.config = void 0;
@@ -1768,6 +1775,7 @@ class DeclarativeWidget extends HTMLElement {
1768
1775
  this.type = void 0;
1769
1776
  this.container = void 0;
1770
1777
  this.element = void 0;
1778
+ this.loaded = void 0;
1771
1779
 
1772
1780
  this._setWidget = (template, config) => {
1773
1781
  var _this$config;
@@ -1789,7 +1797,8 @@ class DeclarativeWidget extends HTMLElement {
1789
1797
  if (this.type === "EMBED") {
1790
1798
  return new EmbedWidget(params, params.context.container);
1791
1799
  } else {
1792
- return new PopupWidget(params, this.firstChild ? null : undefined);
1800
+ var useFirstChildTrigger = this.firstChild ? null : undefined;
1801
+ return new PopupWidget(params, useFirstChildTrigger);
1793
1802
  }
1794
1803
  };
1795
1804
 
@@ -1811,7 +1820,8 @@ class DeclarativeWidget extends HTMLElement {
1811
1820
  if (this.type === "EMBED") {
1812
1821
  return new EmbedWidget(params, params.context.container);
1813
1822
  } else {
1814
- return new PopupWidget(params, this.firstChild ? null : undefined);
1823
+ var useFirstChildTrigger = this.firstChild ? null : undefined;
1824
+ return new PopupWidget(params, useFirstChildTrigger);
1815
1825
  }
1816
1826
  };
1817
1827
 
@@ -1954,6 +1964,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
1954
1964
  */
1955
1965
 
1956
1966
  this.type = "EMBED";
1967
+ this.loaded = false;
1957
1968
  }
1958
1969
 
1959
1970
  static get observedAttributes() {
@@ -1961,7 +1972,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
1961
1972
  }
1962
1973
 
1963
1974
  attributeChangedCallback(attr, oldVal, newVal) {
1964
- if (oldVal === newVal || !oldVal) return; // nothing to do
1975
+ if (oldVal === newVal || !this.loaded) return; // nothing to do
1965
1976
 
1966
1977
  switch (attr) {
1967
1978
  case "locale":
@@ -1978,6 +1989,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
1978
1989
  await this.renderWidget();
1979
1990
  var slot = (_ref = this.shadowRoot && Array.from(this.shadowRoot.children)) == null ? void 0 : _ref.find(c => c.tagName === "SLOT");
1980
1991
  if (slot) (_this$shadowRoot = this.shadowRoot) == null ? void 0 : _this$shadowRoot.removeChild(slot);
1992
+ this.loaded = true;
1981
1993
  }
1982
1994
 
1983
1995
  }
@@ -2001,6 +2013,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
2001
2013
  */
2002
2014
 
2003
2015
  this.type = "POPUP";
2016
+ this.loaded = false;
2004
2017
  this.addEventListener("click", e => {
2005
2018
  e.stopPropagation();
2006
2019
  this.open();
@@ -2012,7 +2025,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
2012
2025
  }
2013
2026
 
2014
2027
  attributeChangedCallback(attr, oldVal, newVal) {
2015
- if (oldVal === newVal || !oldVal) return; // nothing to do
2028
+ if (oldVal === newVal || !this.loaded) return; // nothing to do
2016
2029
 
2017
2030
  switch (attr) {
2018
2031
  case "locale":
@@ -2026,6 +2039,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
2026
2039
  this.container = this.getAttribute("container") || this;
2027
2040
  await this.renderWidget();
2028
2041
  if (this.getAttribute("open") !== null) this.open();
2042
+ this.loaded = true;
2029
2043
  }
2030
2044
 
2031
2045
  }