@saasquatch/squatch-js 2.6.0-7 → 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 (49) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/README.md +14 -5
  3. package/coverage/clover.xml +582 -566
  4. package/coverage/coverage-final.json +20 -19
  5. package/coverage/lcov.info +964 -930
  6. package/dist/async.d.ts +4 -2
  7. package/dist/globals.d.ts +4 -0
  8. package/dist/squatch.esm.js +59 -49
  9. package/dist/squatch.esm.js.map +1 -1
  10. package/dist/squatch.js +59 -49
  11. package/dist/squatch.js.map +1 -1
  12. package/dist/squatch.min.js +1 -1
  13. package/dist/utils/validate.d.ts +0 -2
  14. package/dist/widgets/PopupWidget.d.ts +2 -2
  15. package/dist/widgets/Widgets.d.ts +8 -8
  16. package/dist/widgets/declarative/DeclarativeWidget.d.ts +10 -5
  17. package/package.json +1 -1
  18. package/coverage/lcov-report/DeclarativeWidget.ts.html +0 -790
  19. package/coverage/lcov-report/WidgetApi.ts.html +0 -631
  20. package/coverage/lcov-report/Widgets.ts.html +0 -1105
  21. package/coverage/lcov-report/api/AnalyticsApi.ts.html +0 -304
  22. package/coverage/lcov-report/api/EventsApi.ts.html +0 -352
  23. package/coverage/lcov-report/api/WidgetApi.ts.html +0 -658
  24. package/coverage/lcov-report/api/graphql.ts.html +0 -130
  25. package/coverage/lcov-report/squatch.ts.html +0 -721
  26. package/coverage/lcov-report/utils/cookieUtils.ts.html +0 -415
  27. package/coverage/lcov-report/utils/decodeUserJwt.ts.html +0 -133
  28. package/coverage/lcov-report/utils/domready.ts.html +0 -160
  29. package/coverage/lcov-report/utils/io.ts.html +0 -400
  30. package/coverage/lcov-report/utils/utmUtils.ts.html +0 -277
  31. package/coverage/lcov-report/utils/validate.ts.html +0 -268
  32. package/coverage/lcov-report/validate.ts.html +0 -268
  33. package/coverage/lcov-report/widgets/EmbedWidget.ts.html +0 -481
  34. package/coverage/lcov-report/widgets/PopupWidget.ts.html +0 -685
  35. package/coverage/lcov-report/widgets/Widget.ts.html +0 -1159
  36. package/coverage/lcov-report/widgets/Widgets.ts.html +0 -1102
  37. package/coverage/lcov-report/widgets/declarative/DeclarativeWidget.ts.html +0 -790
  38. package/coverage/lcov-report/widgets/declarative/DeclarativeWidgets.ts.html +0 -388
  39. package/dist/squatch.min.js.map +0 -1
  40. package/dist/squatch.modern.js +0 -2
  41. package/dist/squatch.modern.js.map +0 -1
  42. package/dist/stats.html +0 -208
  43. package/dist/utils/domUtils.d.ts +0 -1
  44. package/dist/utils/loadEvent.d.ts +0 -2
  45. package/dist/widgets/CtaWidget.d.ts +0 -24
  46. package/dist/widgets/IREmbedWidget.d.ts +0 -29
  47. package/dist/widgets/IRPopupWidget.d.ts +0 -32
  48. package/dist/widgets/declarative/DeclarativeEmbedWidget.d.ts +0 -12
  49. package/stats.json +0 -1
package/dist/async.d.ts CHANGED
@@ -5,13 +5,15 @@ 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;
11
13
  squatchToken: string;
12
14
  squatchConfig: Omit<ConfigOptions, "tenantAlias">;
13
- impactTBDToken: string;
14
- impactTBDConfig: Omit<ConfigOptions, "tenantAlias">;
15
+ impactToken: string;
16
+ impactConfig: Omit<ConfigOptions, "tenantAlias">;
15
17
  }
16
18
  }
17
19
  /** @hidden */
@@ -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;
@@ -76,10 +79,10 @@ function validatePasswordlessConfig(raw) {
76
79
  return raw;
77
80
  }
78
81
  function getToken() {
79
- return window.impactTBDToken || window.squatchToken;
82
+ return window.impactToken || window.squatchToken;
80
83
  }
81
84
  function getConfig() {
82
- return window.impactTBDConfig || window.squatchConfig;
85
+ return window.impactConfig || window.squatchConfig;
83
86
  }
84
87
 
85
88
  debug("squatch-js:io");
@@ -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
 
@@ -540,8 +542,7 @@ class Widget {
540
542
  _log$8("ERROR: pushAnalyticsShareClickedEvent() " + ex);
541
543
  });
542
544
  }
543
- } // TODO: CA: Refactor how error templates are shown
544
-
545
+ }
545
546
 
546
547
  _error(rs, mode, style) {
547
548
  if (mode === void 0) {
@@ -808,20 +809,19 @@ class EmbedWidget extends Widget {
808
809
 
809
810
 
810
811
  open() {
811
- var _frame$contentDocumen, _frame$contentWindow, _frame$contentWindow2;
812
-
813
812
  var frame = this._findFrame();
814
813
 
815
814
  if (!frame) return _log$7("no target element to open");
815
+ if (!frame.contentWindow) return _log$7("Frame needs a content window");
816
816
 
817
817
  var element = this._findElement();
818
818
 
819
819
  element.style.visibility = "unset";
820
820
  element.style.height = "auto";
821
821
  element.style["overflow-y"] = "auto";
822
- 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"));
823
823
 
824
- 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;
825
825
 
826
826
  if (this.context.user) {
827
827
  this._loadEvent(_sqh);
@@ -858,7 +858,7 @@ class EmbedWidget extends Widget {
858
858
 
859
859
  _shouldFireLoadEvent() {
860
860
  var noContainer = !this.container;
861
- var isComponent = this.container instanceof HTMLElement && this.container.tagName.startsWith("SQUATCH-");
861
+ var isComponent = this.container instanceof HTMLElement && (this.container.tagName.startsWith("SQUATCH-") || this.container.tagName.startsWith("IMPACT-"));
862
862
  var isVerified = !!this.context.user;
863
863
  return isVerified && (noContainer || isComponent);
864
864
  }
@@ -913,7 +913,7 @@ class PopupWidget extends Widget {
913
913
  try {
914
914
  triggerElement
915
915
  /* HTMLButton */
916
- = document.querySelector(this.trigger);
916
+ = document.querySelector(this.trigger) || document.querySelector(".impactpop");
917
917
  if (this.trigger && !triggerElement) _log$6("No element found with trigger selector", this.trigger);
918
918
  } catch (_unused) {
919
919
  _log$6("Not a valid selector", this.trigger);
@@ -941,7 +941,7 @@ class PopupWidget extends Widget {
941
941
  return dialog;
942
942
  }
943
943
 
944
- load() {
944
+ async load() {
945
945
  var _dialogParent$lastChi;
946
946
 
947
947
  var frame = this._createFrame();
@@ -979,10 +979,10 @@ class PopupWidget extends Widget {
979
979
 
980
980
  _log$6("Popup template loaded into iframe");
981
981
 
982
- this._setupResizeHandler(frame);
982
+ await this._setupResizeHandler(frame);
983
983
  }
984
984
 
985
- _setupResizeHandler(frame) {
985
+ async _setupResizeHandler(frame) {
986
986
  var {
987
987
  contentWindow
988
988
  } = frame;
@@ -1086,11 +1086,11 @@ class Widgets {
1086
1086
  */
1087
1087
 
1088
1088
  /**
1089
- * Tenant alias of SaaSquatch tenant.
1089
+ * Tenant alias of SaaSquatch tenant
1090
1090
  */
1091
1091
 
1092
1092
  /**
1093
- * SaaSquatch domain for API requests.
1093
+ * SaaSquatch domain for API requests
1094
1094
  * @default "https://app.referralsaasquatch.com"
1095
1095
  */
1096
1096
 
@@ -1134,13 +1134,13 @@ class Widgets {
1134
1134
  * @param {Object} config.user The user details
1135
1135
  * @param {string} config.user.id The user id
1136
1136
  * @param {string} config.user.accountId The user account id
1137
- * @param {WidgetType} config.widgetType The content of the widget.
1138
- * @param {EngagementMedium} config.engagementMedium How to display the widget.
1137
+ * @param {WidgetType} config.widgetType The content of the widget
1138
+ * @param {EngagementMedium} config.engagementMedium How to display the widget
1139
1139
  * @param {string} config.jwt the JSON Web Token (JWT) that is used to validate the data (can be disabled)
1140
1140
  * @param {HTMLElement | string | undefined} config.container Element to load the widget into
1141
1141
  * @param {string | undefined} config.trigger Trigger element for opening the popup widget
1142
1142
  *
1143
- * @return {Promise<WidgetResult>} json object if true, with a Widget and user details.
1143
+ * @return {Promise<WidgetResult>} json object if true, with a Widget and user details
1144
1144
  */
1145
1145
 
1146
1146
 
@@ -1178,12 +1178,12 @@ class Widgets {
1178
1178
  * @param {Object} config.user The user details
1179
1179
  * @param {string} config.user.id The user id
1180
1180
  * @param {string} config.user.accountId The user account id
1181
- * @param {WidgetType} config.widgetType The content of the widget.
1182
- * @param {EngagementMedium} config.engagementMedium How to display the widget.
1181
+ * @param {WidgetType} config.widgetType The content of the widget
1182
+ * @param {EngagementMedium} config.engagementMedium How to display the widget
1183
1183
  * @param {string} config.jwt the JSON Web Token (JWT) that is used
1184
1184
  * to validate the data (can be disabled)
1185
1185
  *
1186
- * @return {Promise<WidgetResult>} json object if true, with a Widget and user details.
1186
+ * @return {Promise<WidgetResult>} json object if true, with a Widget and user details
1187
1187
  */
1188
1188
 
1189
1189
 
@@ -1484,19 +1484,17 @@ function _validateTrackOptions(raw) {
1484
1484
  }
1485
1485
 
1486
1486
  /** @hidden */
1487
+
1487
1488
  function asyncLoad() {
1488
- var impactNamespace = "impactTBD";
1489
- var namespace = window[impactNamespace] ? impactNamespace : "squatch";
1490
- console.log({
1491
- namespace
1492
- });
1489
+ var namespace = window[IMPACT_NAMESPACE] ? IMPACT_NAMESPACE : DEFAULT_NAMESPACE;
1493
1490
  var loaded = window[namespace] || null;
1494
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);
1495
1495
 
1496
- if (loaded && cached) {
1497
- var ready = cached.ready || [];
1498
- setTimeout(() => window["impactTBD"] = window.squatch, 0);
1499
- ready.forEach(cb => setTimeout(() => cb(), 0));
1496
+ if (loaded) {
1497
+ if (cached) (cached.ready || []).forEach(cb => setTimeout(() => cb(), 0));
1500
1498
  setTimeout(() => {
1501
1499
  window.squatch._auto();
1502
1500
  }, 0); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
@@ -1685,7 +1683,7 @@ function convertExtraToConfig(obj) {
1685
1683
  };
1686
1684
  }
1687
1685
 
1688
- var _log$2 = debug("squatch-js:decodeJwt");
1686
+ var _log$2 = debug("squatch-js:decodeUserJwt");
1689
1687
 
1690
1688
  function decodeUserJwt(tokenStr) {
1691
1689
  try {
@@ -1704,7 +1702,7 @@ function decodeUserJwt(tokenStr) {
1704
1702
 
1705
1703
  var _log$1 = debug$1("squatch-js:DeclarativeWidget");
1706
1704
  /**
1707
- * Abstract class for building web-components that render SaaSquatch widgets to the DOM.
1705
+ * Abstract class for building web-components that render SaaSquatch widgets to the DOM
1708
1706
  * @abstract
1709
1707
  * @example
1710
1708
  * class TestWidgetElement extends DeclarativeWidget {}
@@ -1752,13 +1750,18 @@ class DeclarativeWidget extends HTMLElement {
1752
1750
  */
1753
1751
 
1754
1752
  /**
1755
- * Determines whether to render the widget as an embedding widget or popup widget.
1753
+ * Determines whether to render the widget as an embedding widget or popup widget
1756
1754
  */
1757
1755
 
1758
1756
  /**
1759
1757
  * Container element to contain the widget iframe
1760
1758
  * @default this
1761
1759
  */
1760
+
1761
+ /**
1762
+ * Flag for if the component has been loaded or not
1763
+ * @hidden
1764
+ */
1762
1765
  constructor() {
1763
1766
  super();
1764
1767
  this.config = void 0;
@@ -1772,6 +1775,7 @@ class DeclarativeWidget extends HTMLElement {
1772
1775
  this.type = void 0;
1773
1776
  this.container = void 0;
1774
1777
  this.element = void 0;
1778
+ this.loaded = void 0;
1775
1779
 
1776
1780
  this._setWidget = (template, config) => {
1777
1781
  var _this$config;
@@ -1793,7 +1797,8 @@ class DeclarativeWidget extends HTMLElement {
1793
1797
  if (this.type === "EMBED") {
1794
1798
  return new EmbedWidget(params, params.context.container);
1795
1799
  } else {
1796
- return new PopupWidget(params, this.firstChild ? null : undefined);
1800
+ var useFirstChildTrigger = this.firstChild ? null : undefined;
1801
+ return new PopupWidget(params, useFirstChildTrigger);
1797
1802
  }
1798
1803
  };
1799
1804
 
@@ -1815,7 +1820,8 @@ class DeclarativeWidget extends HTMLElement {
1815
1820
  if (this.type === "EMBED") {
1816
1821
  return new EmbedWidget(params, params.context.container);
1817
1822
  } else {
1818
- return new PopupWidget(params, this.firstChild ? null : undefined);
1823
+ var useFirstChildTrigger = this.firstChild ? null : undefined;
1824
+ return new PopupWidget(params, useFirstChildTrigger);
1819
1825
  }
1820
1826
  };
1821
1827
 
@@ -1883,7 +1889,7 @@ class DeclarativeWidget extends HTMLElement {
1883
1889
  }
1884
1890
 
1885
1891
  /**
1886
- * Fetches widget content from SaaSquatch and builds a Widget instance to support rendering the widget in the DOM.
1892
+ * Fetches widget content from SaaSquatch and builds a Widget instance to support rendering the widget in the DOM
1887
1893
  * @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type`
1888
1894
  * @throws Throws an Error if `widgetType` is undefined
1889
1895
  */
@@ -1903,7 +1909,7 @@ class DeclarativeWidget extends HTMLElement {
1903
1909
  return widgetInstance;
1904
1910
  }
1905
1911
  /**
1906
- * Calls {@link getWidgetInstance} to build the Widget instance and loads the widget iframe into the DOM.
1912
+ * Calls {@link getWidgetInstance} to build the Widget instance and loads the widget iframe into the DOM
1907
1913
  */
1908
1914
 
1909
1915
 
@@ -1912,7 +1918,7 @@ class DeclarativeWidget extends HTMLElement {
1912
1918
  await this.widgetInstance.load();
1913
1919
  }
1914
1920
  /**
1915
- * Builds a Widget instance for the default error widget.
1921
+ * Builds a Widget instance for the default error widget
1916
1922
  * @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type`
1917
1923
  */
1918
1924
 
@@ -1958,6 +1964,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
1958
1964
  */
1959
1965
 
1960
1966
  this.type = "EMBED";
1967
+ this.loaded = false;
1961
1968
  }
1962
1969
 
1963
1970
  static get observedAttributes() {
@@ -1965,7 +1972,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
1965
1972
  }
1966
1973
 
1967
1974
  attributeChangedCallback(attr, oldVal, newVal) {
1968
- if (oldVal === newVal || !oldVal) return; // nothing to do
1975
+ if (oldVal === newVal || !this.loaded) return; // nothing to do
1969
1976
 
1970
1977
  switch (attr) {
1971
1978
  case "locale":
@@ -1982,6 +1989,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
1982
1989
  await this.renderWidget();
1983
1990
  var slot = (_ref = this.shadowRoot && Array.from(this.shadowRoot.children)) == null ? void 0 : _ref.find(c => c.tagName === "SLOT");
1984
1991
  if (slot) (_this$shadowRoot = this.shadowRoot) == null ? void 0 : _this$shadowRoot.removeChild(slot);
1992
+ this.loaded = true;
1985
1993
  }
1986
1994
 
1987
1995
  }
@@ -2005,6 +2013,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
2005
2013
  */
2006
2014
 
2007
2015
  this.type = "POPUP";
2016
+ this.loaded = false;
2008
2017
  this.addEventListener("click", e => {
2009
2018
  e.stopPropagation();
2010
2019
  this.open();
@@ -2016,7 +2025,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
2016
2025
  }
2017
2026
 
2018
2027
  attributeChangedCallback(attr, oldVal, newVal) {
2019
- if (oldVal === newVal || !oldVal) return; // nothing to do
2028
+ if (oldVal === newVal || !this.loaded) return; // nothing to do
2020
2029
 
2021
2030
  switch (attr) {
2022
2031
  case "locale":
@@ -2030,6 +2039,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
2030
2039
  this.container = this.getAttribute("container") || this;
2031
2040
  await this.renderWidget();
2032
2041
  if (this.getAttribute("open") !== null) this.open();
2042
+ this.loaded = true;
2033
2043
  }
2034
2044
 
2035
2045
  }