@saasquatch/squatch-js 2.6.0-3 → 2.6.0-5

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 (37) hide show
  1. package/.github/workflows/static.yml +89 -0
  2. package/coverage/clover.xml +843 -3
  3. package/coverage/coverage-final.json +20 -1
  4. package/coverage/lcov-report/DeclarativeWidget.ts.html +790 -0
  5. package/coverage/lcov-report/Widgets.ts.html +1105 -0
  6. package/coverage/lcov-report/api/AnalyticsApi.ts.html +22 -22
  7. package/coverage/lcov-report/api/EventsApi.ts.html +352 -0
  8. package/coverage/lcov-report/api/WidgetApi.ts.html +84 -57
  9. package/coverage/lcov-report/api/graphql.ts.html +1 -1
  10. package/coverage/lcov-report/squatch.ts.html +721 -0
  11. package/coverage/lcov-report/utils/cookieUtils.ts.html +1 -1
  12. package/coverage/lcov-report/utils/decodeUserJwt.ts.html +1 -1
  13. package/coverage/lcov-report/utils/domready.ts.html +1 -1
  14. package/coverage/lcov-report/utils/io.ts.html +7 -7
  15. package/coverage/lcov-report/utils/utmUtils.ts.html +22 -22
  16. package/coverage/lcov-report/utils/validate.ts.html +41 -41
  17. package/coverage/lcov-report/validate.ts.html +1 -1
  18. package/coverage/lcov-report/widgets/EmbedWidget.ts.html +24 -3
  19. package/coverage/lcov-report/widgets/PopupWidget.ts.html +17 -2
  20. package/coverage/lcov-report/widgets/Widget.ts.html +1 -1
  21. package/coverage/lcov-report/widgets/Widgets.ts.html +110 -68
  22. package/coverage/lcov-report/widgets/declarative/DeclarativeWidget.ts.html +368 -74
  23. package/coverage/lcov-report/widgets/declarative/DeclarativeWidgets.ts.html +388 -0
  24. package/coverage/lcov.info +1561 -0
  25. package/dist/api/WidgetApi.d.ts +2 -2
  26. package/dist/squatch.d.ts +28 -1
  27. package/dist/squatch.esm.js +205 -47
  28. package/dist/squatch.esm.js.map +1 -1
  29. package/dist/squatch.js +205 -47
  30. package/dist/squatch.js.map +1 -1
  31. package/dist/squatch.min.js +1 -1
  32. package/dist/widgets/EmbedWidget.d.ts +8 -0
  33. package/dist/widgets/PopupWidget.d.ts +6 -1
  34. package/dist/widgets/Widgets.d.ts +15 -2
  35. package/dist/widgets/declarative/DeclarativeWidget.d.ts +66 -2
  36. package/dist/widgets/declarative/DeclarativeWidgets.d.ts +22 -0
  37. package/package.json +2 -2
@@ -26,7 +26,7 @@ export default class WidgetApi {
26
26
  */
27
27
  constructor(config?: ConfigOptions);
28
28
  /**
29
- * Creates/upserts user.
29
+ * Creates/upserts user, requests widget template.
30
30
  *
31
31
  * @param {Object} params Parameters for request
32
32
  * @param {Object?} params.user The user details
@@ -41,7 +41,7 @@ export default class WidgetApi {
41
41
  */
42
42
  upsertUser(params: WithRequired<WidgetConfig, "user">): Promise<any>;
43
43
  /**
44
- * Description here.
44
+ * Requests widget template
45
45
  *
46
46
  * @param {Object} params Parameters for request
47
47
  * @param {Object} params.user The user details
package/dist/squatch.d.ts CHANGED
@@ -14,6 +14,10 @@ export { Widgets, EmbedWidget, PopupWidget, DeclarativeEmbedWidget, DeclarativeP
14
14
  * Read the {@link WidgetApi} docs.
15
15
  *
16
16
  * @returns WidgetApi static instance
17
+ * @example
18
+ * squatch.api().render({ ... })
19
+ * squatch.api().upsertUser({ ... })
20
+ * squatch.api().squatchReferralCookie()
17
21
  */
18
22
  export declare function api(): WidgetApi | null;
19
23
  /**
@@ -22,6 +26,10 @@ export declare function api(): WidgetApi | null;
22
26
  * Read the {@link Widgets} docs.
23
27
  *
24
28
  * @returns static instance
29
+ * @example
30
+ * squatch.widgets().render({ widgetType: "w/widget-type" })
31
+ * squatch.widgets().upsertUser({ user: { ... }, widgetType: "w/widget-type" })
32
+ * squatch.widgets().autofill(".referral-code")
25
33
  */
26
34
  export declare function widgets(): Widgets | null;
27
35
  /**
@@ -30,14 +38,27 @@ export declare function widgets(): Widgets | null;
30
38
  * Read the {@link EventsApi} docs.
31
39
  *
32
40
  * @returns EventsApi static instance
41
+ *
42
+ * @example
43
+ * squatch.events().track({ ... })
33
44
  */
34
45
  export declare function events(): EventsApi | null;
35
46
  /**
36
47
  * Entry-point for high level API to render a widget using the instance of {@link Widgets} created when you call {@link #init init}.
48
+ *
49
+ * Read the {@link Widgets.render} docs.
50
+ *
51
+ * @example
52
+ * squatch.widget().then(res => {
53
+ * const widget = res.widget
54
+ * }).catch(e => console.error("Did not render widget:", e))
37
55
  */
38
56
  export declare function widget(widgetConfig: WidgetConfig): Promise<WidgetResult | undefined> | undefined;
39
57
  /**
40
58
  * Extracts widget configuration from `_saasquatchExtra` UTM parameter. Initialises `squatch` and renders the widget as a {@link PopupWidget} via static instanct of {@link Widgets}.
59
+ *
60
+ * Called by default on startup via the loader script.
61
+ * @private
41
62
  */
42
63
  export declare function _auto(configIn: ConfigOptions): Promise<WidgetResult | undefined> | undefined;
43
64
  /**
@@ -50,7 +71,9 @@ export declare function _auto(configIn: ConfigOptions): Promise<WidgetResult | u
50
71
  * @param config Configuration details
51
72
  *
52
73
  * @example
53
- * squatch.init({tenantAlias:'test_basbtabstq51v'});
74
+ * squatch.init({
75
+ * tenantAlias:'test_basbtabstq51v',
76
+ * });
54
77
  */
55
78
  export declare function init(configIn: ConfigOptions): void;
56
79
  /**
@@ -72,6 +95,10 @@ export declare function ready(fn: () => any): void;
72
95
  *
73
96
  * @param {string} selector Element class/id
74
97
  * @returns {void}
98
+ *
99
+ * @example
100
+ * squatch.autofill("input.referral-code")
101
+ * squatch.autofill("input#referral-code")
75
102
  */
76
103
  export declare function autofill(selector: string): void;
77
104
  /**
@@ -211,7 +211,7 @@ class WidgetApi {
211
211
  this.npmCdn = clean.npmCdn;
212
212
  }
213
213
  /**
214
- * Creates/upserts user.
214
+ * Creates/upserts user, requests widget template.
215
215
  *
216
216
  * @param {Object} params Parameters for request
217
217
  * @param {Object?} params.user The user details
@@ -233,6 +233,7 @@ class WidgetApi {
233
233
  widgetType,
234
234
  engagementMedium = "POPUP",
235
235
  jwt,
236
+ locale,
236
237
  user
237
238
  } = clean;
238
239
  var tenantAlias = encodeURIComponent(this.tenantAlias);
@@ -241,7 +242,8 @@ class WidgetApi {
241
242
 
242
243
  var optionalParams = _buildParams({
243
244
  widgetType,
244
- engagementMedium
245
+ engagementMedium,
246
+ locale
245
247
  });
246
248
 
247
249
  var path = "/api/v1/" + tenantAlias + "/widget/account/" + accountId + "/user/" + userId + "/upsert" + optionalParams;
@@ -251,7 +253,7 @@ class WidgetApi {
251
253
  return doPut(url, JSON.stringify(user), jwt);
252
254
  }
253
255
  /**
254
- * Description here.
256
+ * Requests widget template
255
257
  *
256
258
  * @param {Object} params Parameters for request
257
259
  * @param {Object} params.user The user details
@@ -326,12 +328,15 @@ class WidgetApi {
326
328
  function _buildParams(_ref) {
327
329
  var {
328
330
  widgetType,
329
- engagementMedium
331
+ engagementMedium,
332
+ locale
330
333
  } = _ref;
331
- var widgetTypeP = widgetType ? "?widgetType=" + encodeURIComponent(widgetType) : "";
332
- var engagementMediumP = (widgetType ? "&" : "?") + "engagementMedium=" + encodeURIComponent(engagementMedium);
333
- var optionalParams = widgetTypeP + engagementMediumP;
334
- return optionalParams;
334
+ var engagementMediumP = "engagementMedium=" + encodeURIComponent(engagementMedium);
335
+ var widgetTypeP = widgetType && "widgetType=" + encodeURIComponent(widgetType);
336
+ var localeP = locale && "locale=" + encodeURIComponent(locale);
337
+ var params = [engagementMediumP, widgetTypeP, localeP].filter(x => !!x);
338
+ var queryString = "?" + params.join("&");
339
+ return queryString;
335
340
  }
336
341
 
337
342
  // @ts-check
@@ -470,8 +475,7 @@ class Widget {
470
475
  }
471
476
 
472
477
  _findFrame() {
473
- var element = this._findElement();
474
-
478
+ var element = this.container ? this._findElement() : document.body;
475
479
  var parent = element.shadowRoot || element;
476
480
  return parent.querySelector("iframe#squatchFrame");
477
481
  }
@@ -677,10 +681,7 @@ class Widget {
677
681
 
678
682
  function delay(duration) {
679
683
  return new Promise(function (resolve, reject) {
680
- setTimeout(function () {
681
- /* istanbul ignore next */
682
- resolve(() => {});
683
- }, duration);
684
+ setTimeout(resolve, duration);
684
685
  });
685
686
  }
686
687
 
@@ -715,6 +716,11 @@ var _log$6 = debug("squatch-js:EMBEDwidget");
715
716
  *
716
717
  * To create an EmbedWidget use {@link Widgets}
717
718
  *
719
+ * @example
720
+ * const widget = new EmbedWidget({ ... })
721
+ * widget.load() // Loads widget into the DOM
722
+ * widget.open() // Makes the iframe container visible
723
+ * widget.close() // Hides the iframe container
718
724
  */
719
725
 
720
726
 
@@ -766,6 +772,8 @@ class EmbedWidget extends Widget {
766
772
 
767
773
  frame.height = frameDoc.body.scrollHeight; // Adjust frame height when size of body changes
768
774
 
775
+ /* istanbul ignore next: hard to test */
776
+
769
777
  var ro = new contentWindow["ResizeObserver"](entries => {
770
778
  for (var entry of entries) {
771
779
  var {
@@ -775,15 +783,19 @@ class EmbedWidget extends Widget {
775
783
  frame.height = height;
776
784
  }
777
785
  });
778
- ro.observe(await this._findInnerContainer(frame)); // Regular load - trigger event
786
+ var container = await this._findInnerContainer(frame);
787
+ ro.observe(container); // Regular load - trigger event
779
788
 
780
- if (!this.container) {
789
+ if (!this.container || this.container instanceof HTMLElement && this.container.tagName.startsWith("SQUATCH-")) {
781
790
  this._loadEvent(_sqh);
782
791
 
783
792
  _log$6("loaded");
784
793
  }
785
794
  });
786
- } // Un-hide if element is available and refresh data
795
+ }
796
+ /**
797
+ * Un-hide if element is available and refresh data
798
+ */
787
799
 
788
800
 
789
801
  open() {
@@ -846,6 +858,11 @@ var popupId = 0;
846
858
  *
847
859
  * To create a PopupWidget use {@link Widgets}
848
860
  *
861
+ * @example
862
+ * const widget = new PopupWidget({ ... })
863
+ * widget.load() // Loads the widget into a dialog element
864
+ * widget.open() // Opens the dialog element
865
+ * widget.close() // Hides the dialog element
849
866
  */
850
867
 
851
868
  class PopupWidget extends Widget {
@@ -871,7 +888,7 @@ class PopupWidget extends Widget {
871
888
  document.head.insertAdjacentHTML("beforeend", "<style>#" + this.id + "::-webkit-scrollbar { display: none; }</style>");
872
889
  }
873
890
 
874
- _initialiseCTA(frame) {
891
+ _initialiseCTA() {
875
892
  if (!this.trigger) return;
876
893
  var triggerElement;
877
894
 
@@ -919,10 +936,9 @@ class PopupWidget extends Widget {
919
936
 
920
937
  var frame = this._createFrame();
921
938
 
922
- this._initialiseCTA(frame);
923
-
924
- var element = this._findElement();
939
+ this._initialiseCTA();
925
940
 
941
+ var element = this.container ? this._findElement() : document.body;
926
942
  var dialogParent = element.shadowRoot || element;
927
943
 
928
944
  var dialog = this._createPopupDialog();
@@ -988,8 +1004,7 @@ class PopupWidget extends Widget {
988
1004
  }
989
1005
 
990
1006
  open() {
991
- var element = this._findElement();
992
-
1007
+ var element = this.container ? this._findElement() : document.body;
993
1008
  var parent = element.shadowRoot || element;
994
1009
  var dialog = parent.querySelector("#" + this.id);
995
1010
  if (!dialog) throw new Error("Could not determine container div");
@@ -1018,8 +1033,7 @@ class PopupWidget extends Widget {
1018
1033
  }
1019
1034
 
1020
1035
  close() {
1021
- var element = this._findElement();
1022
-
1036
+ var element = this.container ? this._findElement() : document.body;
1023
1037
  var parent = element.shadowRoot || element;
1024
1038
  var dialog = parent.querySelector("#" + this.id);
1025
1039
  if (!dialog) throw new Error("Could not determine container div");
@@ -1048,14 +1062,31 @@ class PopupWidget extends Widget {
1048
1062
 
1049
1063
  var _log$4 = debug("squatch-js:widgets");
1050
1064
  /**
1051
- *
1052
1065
  * `Widgets` is a factory for creating widgets. It's possible to build your own widgets using the
1053
1066
  * {@link WidgetApi} but most people will prefer to use these easy methods.
1054
- *
1067
+ * @class
1055
1068
  */
1056
1069
 
1057
1070
 
1058
1071
  class Widgets {
1072
+ /**
1073
+ * Instance of {@link WidgetApi}
1074
+ */
1075
+
1076
+ /**
1077
+ * Tenant alias of SaaSquatch tenant.
1078
+ */
1079
+
1080
+ /**
1081
+ * SaaSquatch domain for API requests.
1082
+ * @default "https://app.referralsaasquatch.com"
1083
+ */
1084
+
1085
+ /**
1086
+ * Hosted CDN for npm packages
1087
+ * @default "https://fast.ssqt.io/npm"
1088
+ */
1089
+
1059
1090
  /**
1060
1091
  * Initialize a new {@link Widgets} instance.
1061
1092
  *
@@ -1081,7 +1112,7 @@ class Widgets {
1081
1112
  this.tenantAlias = config.tenantAlias;
1082
1113
  this.domain = config.domain;
1083
1114
  this.npmCdn = config.npmCdn;
1084
- this.api = new WidgetApi(config); // listens to a 'submit_email' event in the theme.
1115
+ this.api = new WidgetApi(config);
1085
1116
  }
1086
1117
  /**
1087
1118
  * This function calls the {@link WidgetApi.upsertUser} method, and it renders
@@ -1153,7 +1184,9 @@ class Widgets {
1153
1184
  return {
1154
1185
  widget: this._renderWidget(response, clean, {
1155
1186
  type: "passwordless",
1156
- engagementMedium: clean.engagementMedium
1187
+ engagementMedium: clean.engagementMedium,
1188
+ container: clean.container,
1189
+ trigger: clean.trigger
1157
1190
  }),
1158
1191
  user: response.user
1159
1192
  };
@@ -1244,13 +1277,7 @@ class Widgets {
1244
1277
  if (Widgets._matchesUrl(rule.url)) {
1245
1278
  var _response$user, _response$user$referr;
1246
1279
 
1247
- console.log({
1248
- response,
1249
- rule
1250
- });
1251
-
1252
1280
  if (rule.widgetType !== "CONVERSION_WIDGET" || (_response$user = response.user) != null && (_response$user$referr = _response$user.referredBy) != null && _response$user$referr.code) {
1253
- console.log("HERE");
1254
1281
  displayOnLoad = rule.displayOnLoad;
1255
1282
 
1256
1283
  _log$4("Display " + rule.widgetType + " on " + rule.url);
@@ -1662,8 +1689,62 @@ function decodeUserJwt(tokenStr) {
1662
1689
  }
1663
1690
 
1664
1691
  debug$1("sqh:DeclarativeWidget");
1692
+ /**
1693
+ * Abstract class for building web-components that render SaaSquatch widgets to the DOM.
1694
+ * @abstract
1695
+ * @example
1696
+ * class TestWidgetElement extends DeclarativeWidget {}
1697
+ * const testWidget = new TestWidgetElement()
1698
+ * testWidget.widgetType = 'w/widget-type'
1699
+ * testWidget.type = 'EMBED'
1700
+ * testWidget.renderWidget()
1701
+ */
1702
+
1665
1703
 
1666
1704
  class DeclarativeWidget extends HTMLElement {
1705
+ /**
1706
+ * Configuration overrides
1707
+ * @default window.squatchConfig
1708
+ */
1709
+
1710
+ /**
1711
+ * Signed JWT containing user information
1712
+ * @default window.squatchToken
1713
+ */
1714
+
1715
+ /**
1716
+ * Tenant alias of SaaSquatch tenant
1717
+ * @default window.squatchTenant
1718
+ */
1719
+
1720
+ /**
1721
+ * widgetType of widget to load
1722
+ */
1723
+
1724
+ /**
1725
+ * Locale to render the widget in
1726
+ */
1727
+
1728
+ /**
1729
+ * Instance of {@link WidgetApi}
1730
+ */
1731
+
1732
+ /**
1733
+ * Instance of {@link AnalyticsApi}
1734
+ */
1735
+
1736
+ /**
1737
+ * Instance of {@link EmbedWidget} or {@link PopupWidget}
1738
+ */
1739
+
1740
+ /**
1741
+ * Determines whether to render the widget as an embedding widget or popup widget.
1742
+ */
1743
+
1744
+ /**
1745
+ * Container element to contain the widget iframe
1746
+ * @default this
1747
+ */
1667
1748
  constructor() {
1668
1749
  super();
1669
1750
  this.config = void 0;
@@ -1673,11 +1754,10 @@ class DeclarativeWidget extends HTMLElement {
1673
1754
  this.locale = void 0;
1674
1755
  this.widgetApi = void 0;
1675
1756
  this.analyticsApi = void 0;
1676
- this.type = void 0;
1677
1757
  this.widgetInstance = void 0;
1758
+ this.type = void 0;
1678
1759
  this.container = void 0;
1679
1760
  this.element = void 0;
1680
- this._hasChildren = void 0;
1681
1761
 
1682
1762
  this._setWidget = (template, config) => {
1683
1763
  var _this$config;
@@ -1724,6 +1804,7 @@ class DeclarativeWidget extends HTMLElement {
1724
1804
  }
1725
1805
  };
1726
1806
 
1807
+ this.reload = this.renderWidget;
1727
1808
  this.show = this.open;
1728
1809
  this.hide = this.close;
1729
1810
  this.attachShadow({
@@ -1733,7 +1814,6 @@ class DeclarativeWidget extends HTMLElement {
1733
1814
  this.token = window.squatchToken;
1734
1815
  this.tenant = window.squatchTenant;
1735
1816
  this.container = this;
1736
- this.locale = validateLocale(navigator.language.replace(/\-/g, "_"));
1737
1817
  }
1738
1818
 
1739
1819
  _setupApis(config) {
@@ -1772,6 +1852,7 @@ class DeclarativeWidget extends HTMLElement {
1772
1852
  if (!userObj) throw new Error("Could not load user information from jwt");
1773
1853
  var widgetInstance = await this.widgetApi.upsertUser({
1774
1854
  user: userObj,
1855
+ locale: this.locale,
1775
1856
  engagementMedium: this.type,
1776
1857
  widgetType: this.widgetType,
1777
1858
  jwt: this.token
@@ -1781,6 +1862,11 @@ class DeclarativeWidget extends HTMLElement {
1781
1862
  return widgetInstance;
1782
1863
  }
1783
1864
 
1865
+ /**
1866
+ * Fetches widget content from SaaSquatch and builds a Widget instance to support rendering the widget in the DOM.
1867
+ * @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type`
1868
+ * @throws Throws an Error if `widgetType` is undefined
1869
+ */
1784
1870
  async getWidgetInstance() {
1785
1871
  var widgetInstance;
1786
1872
  this.widgetType = this.getAttribute("widget") || undefined;
@@ -1793,29 +1879,64 @@ class DeclarativeWidget extends HTMLElement {
1793
1879
  widgetInstance = await this.renderUserUpsertVariant();
1794
1880
  }
1795
1881
 
1796
- if (!widgetInstance) throw new Error("Could not create widget.");
1797
1882
  this.widgetInstance = widgetInstance;
1798
1883
  return widgetInstance;
1799
1884
  }
1885
+ /**
1886
+ * Calls {@link getWidgetInstance} to build the Widget instance and loads the widget iframe into the DOM.
1887
+ */
1888
+
1800
1889
 
1801
1890
  async renderWidget() {
1802
1891
  await this.getWidgetInstance();
1803
1892
  await this.widgetInstance.load();
1804
1893
  }
1894
+ /**
1895
+ * Builds a Widget instance for the default error widget.
1896
+ * @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type`
1897
+ */
1898
+
1805
1899
 
1900
+ /**
1901
+ * Calls `open` method of `widgetInstance`
1902
+ * @throws Throws an Error if called before the widget has loaded
1903
+ */
1806
1904
  open() {
1905
+ if (!this.widgetInstance) throw new Error("Widget has not loaded yet");
1807
1906
  this.widgetInstance.open();
1808
1907
  }
1908
+ /**
1909
+ * Calls `close` method of `widgetInstance`
1910
+ * @throws Throws an Error if called before the widget has loaded
1911
+ */
1912
+
1809
1913
 
1810
1914
  close() {
1915
+ if (!this.widgetInstance) throw new Error("Widget has not loaded yet");
1811
1916
  this.widgetInstance.close();
1812
1917
  }
1813
1918
 
1814
1919
  }
1815
1920
 
1921
+ /**
1922
+ * Base class for `squatch-embed` web-component
1923
+ * @extends {DeclarativeWidget}
1924
+ * @class
1925
+ * @example
1926
+ * window.createCustomElement('squatch-embed', DeclarativeEmbedWidget)
1927
+ * const widget = document.querySelector('squatch-embed') as DeclarativeEmbedWidget
1928
+ * widget.open()
1929
+ * widget.close()
1930
+ * widget.reload()
1931
+ */
1932
+
1816
1933
  class DeclarativeEmbedWidget extends DeclarativeWidget {
1817
1934
  constructor() {
1818
1935
  super();
1936
+ /**
1937
+ * @static
1938
+ */
1939
+
1819
1940
  this.type = "EMBED";
1820
1941
  }
1821
1942
 
@@ -1831,11 +1952,6 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
1831
1952
  case "widget":
1832
1953
  this.connectedCallback();
1833
1954
  break;
1834
- // // Specific to embed widgets
1835
- // case "container":
1836
- // if (this.widgetInstance._findElement()) this.close();
1837
- // this.connectedCallback();
1838
- // break;
1839
1955
  }
1840
1956
  }
1841
1957
 
@@ -1849,9 +1965,25 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
1849
1965
  }
1850
1966
 
1851
1967
  }
1968
+ /**
1969
+ * Base class for `squatch-popup` web-component
1970
+ * @extends {DeclarativeWidget}
1971
+ * @class
1972
+ * @example
1973
+ * window.createCustomElement('squatch-popup', DeclarativePopupWidget)
1974
+ * const widget = document.querySelector('squatch-popup') as DeclarativePopupWidget
1975
+ * widget.open()
1976
+ * widget.close()
1977
+ * widget.reload()
1978
+ */
1979
+
1852
1980
  class DeclarativePopupWidget extends DeclarativeWidget {
1853
1981
  constructor() {
1854
1982
  super();
1983
+ /**
1984
+ * @static
1985
+ */
1986
+
1855
1987
  this.type = "POPUP";
1856
1988
  this.addEventListener("click", e => {
1857
1989
  e.stopPropagation(); // SQUATCH-POPUP target means something in the shadowDOM was clicked (i.e. the dialog element)
@@ -1861,14 +1993,13 @@ class DeclarativePopupWidget extends DeclarativeWidget {
1861
1993
  }
1862
1994
 
1863
1995
  static get observedAttributes() {
1864
- return ["widget", "id", "open", "locale"];
1996
+ return ["widget", "locale"];
1865
1997
  }
1866
1998
 
1867
1999
  attributeChangedCallback(attr, oldVal, newVal) {
1868
2000
  if (oldVal === newVal || !oldVal) return; // nothing to do
1869
2001
 
1870
2002
  switch (attr) {
1871
- case "open":
1872
2003
  case "locale":
1873
2004
  case "widget":
1874
2005
  this.connectedCallback();
@@ -1911,6 +2042,10 @@ var _events = null;
1911
2042
  * Read the {@link WidgetApi} docs.
1912
2043
  *
1913
2044
  * @returns WidgetApi static instance
2045
+ * @example
2046
+ * squatch.api().render({ ... })
2047
+ * squatch.api().upsertUser({ ... })
2048
+ * squatch.api().squatchReferralCookie()
1914
2049
  */
1915
2050
 
1916
2051
  function api() {
@@ -1923,6 +2058,10 @@ function api() {
1923
2058
  * Read the {@link Widgets} docs.
1924
2059
  *
1925
2060
  * @returns static instance
2061
+ * @example
2062
+ * squatch.widgets().render({ widgetType: "w/widget-type" })
2063
+ * squatch.widgets().upsertUser({ user: { ... }, widgetType: "w/widget-type" })
2064
+ * squatch.widgets().autofill(".referral-code")
1926
2065
  */
1927
2066
 
1928
2067
  function widgets() {
@@ -1935,6 +2074,9 @@ function widgets() {
1935
2074
  * Read the {@link EventsApi} docs.
1936
2075
  *
1937
2076
  * @returns EventsApi static instance
2077
+ *
2078
+ * @example
2079
+ * squatch.events().track({ ... })
1938
2080
  */
1939
2081
 
1940
2082
  function events() {
@@ -1943,6 +2085,13 @@ function events() {
1943
2085
  }
1944
2086
  /**
1945
2087
  * Entry-point for high level API to render a widget using the instance of {@link Widgets} created when you call {@link #init init}.
2088
+ *
2089
+ * Read the {@link Widgets.render} docs.
2090
+ *
2091
+ * @example
2092
+ * squatch.widget().then(res => {
2093
+ * const widget = res.widget
2094
+ * }).catch(e => console.error("Did not render widget:", e))
1946
2095
  */
1947
2096
 
1948
2097
  function widget(widgetConfig) {
@@ -1952,6 +2101,9 @@ function widget(widgetConfig) {
1952
2101
  }
1953
2102
  /**
1954
2103
  * Extracts widget configuration from `_saasquatchExtra` UTM parameter. Initialises `squatch` and renders the widget as a {@link PopupWidget} via static instanct of {@link Widgets}.
2104
+ *
2105
+ * Called by default on startup via the loader script.
2106
+ * @private
1955
2107
  */
1956
2108
 
1957
2109
  function _auto(configIn) {
@@ -1978,7 +2130,9 @@ function _auto(configIn) {
1978
2130
  * @param config Configuration details
1979
2131
  *
1980
2132
  * @example
1981
- * squatch.init({tenantAlias:'test_basbtabstq51v'});
2133
+ * squatch.init({
2134
+ * tenantAlias:'test_basbtabstq51v',
2135
+ * });
1982
2136
  */
1983
2137
 
1984
2138
  function init(configIn) {
@@ -2023,6 +2177,10 @@ function ready(fn) {
2023
2177
  *
2024
2178
  * @param {string} selector Element class/id
2025
2179
  * @returns {void}
2180
+ *
2181
+ * @example
2182
+ * squatch.autofill("input.referral-code")
2183
+ * squatch.autofill("input#referral-code")
2026
2184
  */
2027
2185
 
2028
2186
  function autofill(selector) {