@saasquatch/squatch-js 2.6.0-8 → 2.6.0
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.
- package/.github/workflows/size-limit.yml +14 -14
- package/.github/workflows/static.yml +89 -89
- package/CHANGELOG.md +388 -326
- package/LICENSE +20 -20
- package/README.md +259 -208
- package/babel.config.js +7 -7
- package/cucumber.js +45 -45
- package/demo/sandbox.ts +124 -124
- package/demo/toolbar.tsx +526 -526
- package/dist/api/WidgetApi.d.ts +1 -0
- package/dist/async.d.ts +2 -0
- package/dist/globals.d.ts +4 -0
- package/dist/squatch.esm.js +80 -49
- package/dist/squatch.esm.js.map +1 -1
- package/dist/squatch.js +80 -49
- package/dist/squatch.js.map +1 -1
- package/dist/squatch.min.js +1 -1
- package/dist/squatch.min.js.br +0 -0
- package/dist/squatch.min.js.map +1 -1
- package/dist/squatch.modern.js +1 -1
- package/dist/squatch.modern.js.map +1 -1
- package/dist/stats.html +1 -1
- package/dist/utils/decodeJwt.d.ts +1 -0
- package/dist/utils/validate.d.ts +0 -2
- package/dist/widgets/PopupWidget.d.ts +2 -2
- package/dist/widgets/declarative/DeclarativeWidget.d.ts +5 -0
- package/jest.config.ts +200 -200
- package/package.json +123 -123
- package/tsconfig.json +23 -23
- package/coverage/clover.xml +0 -865
- package/coverage/coverage-final.json +0 -20
- package/coverage/lcov-report/DeclarativeWidget.ts.html +0 -790
- package/coverage/lcov-report/WidgetApi.ts.html +0 -631
- package/coverage/lcov-report/Widgets.ts.html +0 -1105
- package/coverage/lcov-report/api/AnalyticsApi.ts.html +0 -304
- package/coverage/lcov-report/api/EventsApi.ts.html +0 -352
- package/coverage/lcov-report/api/WidgetApi.ts.html +0 -658
- package/coverage/lcov-report/api/graphql.ts.html +0 -130
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/squatch.ts.html +0 -721
- package/coverage/lcov-report/utils/cookieUtils.ts.html +0 -415
- package/coverage/lcov-report/utils/decodeUserJwt.ts.html +0 -133
- package/coverage/lcov-report/utils/domready.ts.html +0 -160
- package/coverage/lcov-report/utils/io.ts.html +0 -400
- package/coverage/lcov-report/utils/utmUtils.ts.html +0 -277
- package/coverage/lcov-report/utils/validate.ts.html +0 -268
- package/coverage/lcov-report/validate.ts.html +0 -268
- package/coverage/lcov-report/widgets/EmbedWidget.ts.html +0 -481
- package/coverage/lcov-report/widgets/PopupWidget.ts.html +0 -685
- package/coverage/lcov-report/widgets/Widget.ts.html +0 -1159
- package/coverage/lcov-report/widgets/Widgets.ts.html +0 -1102
- package/coverage/lcov-report/widgets/declarative/DeclarativeWidget.ts.html +0 -790
- package/coverage/lcov-report/widgets/declarative/DeclarativeWidgets.ts.html +0 -388
- package/coverage/lcov.info +0 -1593
- package/stats.json +0 -1
package/dist/api/WidgetApi.d.ts
CHANGED
package/dist/async.d.ts
CHANGED
package/dist/squatch.esm.js
CHANGED
|
@@ -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;
|
|
@@ -210,6 +213,7 @@ class WidgetApi {
|
|
|
210
213
|
this.tenantAlias = void 0;
|
|
211
214
|
this.domain = void 0;
|
|
212
215
|
this.npmCdn = void 0;
|
|
216
|
+
this.referralCookie = this.squatchReferralCookie;
|
|
213
217
|
var raw = config;
|
|
214
218
|
var clean = validateConfig(raw);
|
|
215
219
|
this.tenantAlias = clean.tenantAlias;
|
|
@@ -337,12 +341,11 @@ function _buildParams(_ref) {
|
|
|
337
341
|
engagementMedium,
|
|
338
342
|
locale
|
|
339
343
|
} = _ref;
|
|
340
|
-
var
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
return queryString;
|
|
344
|
+
var queryParams = new URLSearchParams();
|
|
345
|
+
queryParams.append("engagementMedium", engagementMedium);
|
|
346
|
+
if (widgetType) queryParams.append("widgetType", widgetType);
|
|
347
|
+
if (locale) queryParams.append("locale", locale);
|
|
348
|
+
return "?" + queryParams.toString();
|
|
346
349
|
}
|
|
347
350
|
|
|
348
351
|
// @ts-check
|
|
@@ -419,6 +422,8 @@ var _log$8 = debug("squatch-js:widget");
|
|
|
419
422
|
|
|
420
423
|
class Widget {
|
|
421
424
|
constructor(params) {
|
|
425
|
+
var _params$context;
|
|
426
|
+
|
|
422
427
|
this.type = void 0;
|
|
423
428
|
this.content = void 0;
|
|
424
429
|
this.analyticsApi = void 0;
|
|
@@ -437,7 +442,7 @@ class Widget {
|
|
|
437
442
|
domain: params.domain
|
|
438
443
|
});
|
|
439
444
|
this.context = params.context;
|
|
440
|
-
this.container = params.context.container;
|
|
445
|
+
this.container = ((_params$context = params.context) == null ? void 0 : _params$context.container) || params.container;
|
|
441
446
|
}
|
|
442
447
|
|
|
443
448
|
_findElement() {
|
|
@@ -460,12 +465,12 @@ class Widget {
|
|
|
460
465
|
_log$8("container must be an HTMLElement or string", this.container); // find element on page
|
|
461
466
|
|
|
462
467
|
} else {
|
|
463
|
-
element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed");
|
|
468
|
+
element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed") || document.querySelector("#impactembed") || document.querySelector(".impactembed");
|
|
464
469
|
|
|
465
470
|
_log$8("loading widget with default selector", element);
|
|
466
471
|
}
|
|
467
472
|
|
|
468
|
-
if (!(element instanceof HTMLElement)) throw new Error("element with selector '" + (this.container || "#squatchembed or .
|
|
473
|
+
if (!(element instanceof HTMLElement)) throw new Error("element with selector '" + (this.container || "#squatchembed, .squatchembed, #impactembed, or .impactembed") + "' not found.'");
|
|
469
474
|
return element;
|
|
470
475
|
}
|
|
471
476
|
|
|
@@ -738,10 +743,19 @@ class EmbedWidget extends Widget {
|
|
|
738
743
|
}
|
|
739
744
|
|
|
740
745
|
async load() {
|
|
746
|
+
var _this$context;
|
|
747
|
+
|
|
741
748
|
var frame = this._createFrame();
|
|
742
749
|
|
|
743
750
|
var element = this._findElement();
|
|
744
751
|
|
|
752
|
+
if ((_this$context = this.context) != null && _this$context.container) {
|
|
753
|
+
// Custom container is used
|
|
754
|
+
element.style.visibility = "hidden";
|
|
755
|
+
element.style.height = "0";
|
|
756
|
+
element.style["overflow-y"] = "hidden";
|
|
757
|
+
}
|
|
758
|
+
|
|
745
759
|
if (this.container) {
|
|
746
760
|
if (element.shadowRoot) {
|
|
747
761
|
var _element$shadowRoot$l;
|
|
@@ -789,6 +803,7 @@ class EmbedWidget extends Widget {
|
|
|
789
803
|
} = entry.contentRect; // @ts-ignore -- number will be cast to string by browsers
|
|
790
804
|
|
|
791
805
|
frame.height = height;
|
|
806
|
+
console.log("RESIZE");
|
|
792
807
|
}
|
|
793
808
|
});
|
|
794
809
|
var container = await this._findInnerContainer(frame);
|
|
@@ -807,20 +822,19 @@ class EmbedWidget extends Widget {
|
|
|
807
822
|
|
|
808
823
|
|
|
809
824
|
open() {
|
|
810
|
-
var _frame$contentDocumen, _frame$contentWindow, _frame$contentWindow2;
|
|
811
|
-
|
|
812
825
|
var frame = this._findFrame();
|
|
813
826
|
|
|
814
827
|
if (!frame) return _log$7("no target element to open");
|
|
828
|
+
if (!frame.contentWindow) return _log$7("Frame needs a content window");
|
|
815
829
|
|
|
816
830
|
var element = this._findElement();
|
|
817
831
|
|
|
818
832
|
element.style.visibility = "unset";
|
|
819
833
|
element.style.height = "auto";
|
|
820
834
|
element.style["overflow-y"] = "auto";
|
|
821
|
-
frame
|
|
835
|
+
frame.contentWindow.document.dispatchEvent(new CustomEvent("sq:refresh"));
|
|
822
836
|
|
|
823
|
-
var _sqh =
|
|
837
|
+
var _sqh = frame.contentWindow.squatch || frame.contentWindow.widgetIdent;
|
|
824
838
|
|
|
825
839
|
if (this.context.user) {
|
|
826
840
|
this._loadEvent(_sqh);
|
|
@@ -912,7 +926,7 @@ class PopupWidget extends Widget {
|
|
|
912
926
|
try {
|
|
913
927
|
triggerElement
|
|
914
928
|
/* HTMLButton */
|
|
915
|
-
= document.querySelector(this.trigger);
|
|
929
|
+
= document.querySelector(this.trigger) || document.querySelector(".impactpop");
|
|
916
930
|
if (this.trigger && !triggerElement) _log$6("No element found with trigger selector", this.trigger);
|
|
917
931
|
} catch (_unused) {
|
|
918
932
|
_log$6("Not a valid selector", this.trigger);
|
|
@@ -940,7 +954,7 @@ class PopupWidget extends Widget {
|
|
|
940
954
|
return dialog;
|
|
941
955
|
}
|
|
942
956
|
|
|
943
|
-
load() {
|
|
957
|
+
async load() {
|
|
944
958
|
var _dialogParent$lastChi;
|
|
945
959
|
|
|
946
960
|
var frame = this._createFrame();
|
|
@@ -978,10 +992,10 @@ class PopupWidget extends Widget {
|
|
|
978
992
|
|
|
979
993
|
_log$6("Popup template loaded into iframe");
|
|
980
994
|
|
|
981
|
-
this._setupResizeHandler(frame);
|
|
995
|
+
await this._setupResizeHandler(frame);
|
|
982
996
|
}
|
|
983
997
|
|
|
984
|
-
_setupResizeHandler(frame) {
|
|
998
|
+
async _setupResizeHandler(frame) {
|
|
985
999
|
var {
|
|
986
1000
|
contentWindow
|
|
987
1001
|
} = frame;
|
|
@@ -1483,28 +1497,29 @@ function _validateTrackOptions(raw) {
|
|
|
1483
1497
|
}
|
|
1484
1498
|
|
|
1485
1499
|
/** @hidden */
|
|
1500
|
+
|
|
1486
1501
|
function asyncLoad() {
|
|
1487
|
-
var
|
|
1488
|
-
var namespace = window[impactNamespace] ? impactNamespace : "squatch";
|
|
1489
|
-
var loaded = window[namespace] || null;
|
|
1490
|
-
var cached = window["_" + namespace] || null;
|
|
1491
|
-
|
|
1492
|
-
if (loaded && cached) {
|
|
1493
|
-
var ready = cached.ready || [];
|
|
1494
|
-
setTimeout(() => window["impactTBD"] = window.squatch, 0);
|
|
1495
|
-
ready.forEach(cb => setTimeout(() => cb(), 0));
|
|
1496
|
-
setTimeout(() => {
|
|
1497
|
-
window.squatch._auto();
|
|
1498
|
-
}, 0); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
|
|
1502
|
+
var _window;
|
|
1499
1503
|
|
|
1500
|
-
|
|
1504
|
+
var namespace = window[IMPACT_NAMESPACE] ? IMPACT_NAMESPACE : DEFAULT_NAMESPACE;
|
|
1505
|
+
var cached = ((_window = window["_" + namespace]) == null ? void 0 : _window.ready) || [];
|
|
1506
|
+
var declarativeCache = window.impactOnReady || window.squatchOnReady;
|
|
1507
|
+
var readyFns = [...cached, declarativeCache].filter(a => !!a); // Run all of this in a setTimeout because we need to wait for the squatch module to finish loading
|
|
1501
1508
|
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1509
|
+
setTimeout(() => {
|
|
1510
|
+
// Exit early if module wasn't loaded onto window
|
|
1511
|
+
if (!window[DEFAULT_NAMESPACE]) return; // Set window.impact as an alias for window.squatch.
|
|
1512
|
+
|
|
1513
|
+
window[IMPACT_NAMESPACE] = window[DEFAULT_NAMESPACE]; // Run all the ready functions in a set timeout to they happen after namespace aliasing.
|
|
1514
|
+
|
|
1515
|
+
readyFns.forEach(cb => cb()); // Perform auto popup
|
|
1516
|
+
|
|
1517
|
+
window[DEFAULT_NAMESPACE]._auto(); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
|
|
1518
|
+
|
|
1519
|
+
|
|
1520
|
+
window["_" + namespace] = undefined;
|
|
1521
|
+
delete window["_" + namespace];
|
|
1522
|
+
}, 0);
|
|
1508
1523
|
}
|
|
1509
1524
|
|
|
1510
1525
|
/** @hidden */
|
|
@@ -1755,6 +1770,11 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1755
1770
|
* Container element to contain the widget iframe
|
|
1756
1771
|
* @default this
|
|
1757
1772
|
*/
|
|
1773
|
+
|
|
1774
|
+
/**
|
|
1775
|
+
* Flag for if the component has been loaded or not
|
|
1776
|
+
* @hidden
|
|
1777
|
+
*/
|
|
1758
1778
|
constructor() {
|
|
1759
1779
|
super();
|
|
1760
1780
|
this.config = void 0;
|
|
@@ -1768,6 +1788,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1768
1788
|
this.type = void 0;
|
|
1769
1789
|
this.container = void 0;
|
|
1770
1790
|
this.element = void 0;
|
|
1791
|
+
this.loaded = void 0;
|
|
1771
1792
|
|
|
1772
1793
|
this._setWidget = (template, config) => {
|
|
1773
1794
|
var _this$config;
|
|
@@ -1778,18 +1799,20 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1778
1799
|
context: {
|
|
1779
1800
|
type: config.type,
|
|
1780
1801
|
user: config.user,
|
|
1781
|
-
container: this.container ||
|
|
1802
|
+
container: this.container || undefined,
|
|
1782
1803
|
engagementMedium: this.type
|
|
1783
1804
|
},
|
|
1784
1805
|
type: this.widgetType,
|
|
1785
1806
|
domain: ((_this$config = this.config) == null ? void 0 : _this$config.domain) || DEFAULT_DOMAIN,
|
|
1786
|
-
npmCdn: DEFAULT_NPM_CDN
|
|
1807
|
+
npmCdn: DEFAULT_NPM_CDN,
|
|
1808
|
+
container: this
|
|
1787
1809
|
};
|
|
1788
1810
|
|
|
1789
1811
|
if (this.type === "EMBED") {
|
|
1790
|
-
return new EmbedWidget(params
|
|
1812
|
+
return new EmbedWidget(params);
|
|
1791
1813
|
} else {
|
|
1792
|
-
|
|
1814
|
+
var useFirstChildTrigger = this.firstChild ? null : undefined;
|
|
1815
|
+
return new PopupWidget(params, useFirstChildTrigger);
|
|
1793
1816
|
}
|
|
1794
1817
|
};
|
|
1795
1818
|
|
|
@@ -1801,17 +1824,19 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1801
1824
|
content: "error",
|
|
1802
1825
|
context: {
|
|
1803
1826
|
type: "error",
|
|
1804
|
-
container: this.container ||
|
|
1827
|
+
container: this.container || undefined
|
|
1805
1828
|
},
|
|
1806
1829
|
type: "ERROR_WIDGET",
|
|
1807
1830
|
domain: ((_this$config2 = this.config) == null ? void 0 : _this$config2.domain) || DEFAULT_DOMAIN,
|
|
1808
|
-
npmCdn: DEFAULT_NPM_CDN
|
|
1831
|
+
npmCdn: DEFAULT_NPM_CDN,
|
|
1832
|
+
container: this
|
|
1809
1833
|
};
|
|
1810
1834
|
|
|
1811
1835
|
if (this.type === "EMBED") {
|
|
1812
|
-
return new EmbedWidget(params
|
|
1836
|
+
return new EmbedWidget(params);
|
|
1813
1837
|
} else {
|
|
1814
|
-
|
|
1838
|
+
var useFirstChildTrigger = this.firstChild ? null : undefined;
|
|
1839
|
+
return new PopupWidget(params, useFirstChildTrigger);
|
|
1815
1840
|
}
|
|
1816
1841
|
};
|
|
1817
1842
|
|
|
@@ -1820,7 +1845,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1820
1845
|
this.hide = this.close;
|
|
1821
1846
|
this.attachShadow({
|
|
1822
1847
|
mode: "open"
|
|
1823
|
-
}).innerHTML = "<style>:host { display:
|
|
1848
|
+
}).innerHTML = "<style>:host { display: block; }</style><slot></slot>";
|
|
1824
1849
|
this.config = getConfig();
|
|
1825
1850
|
this.token = getToken();
|
|
1826
1851
|
this.tenant = window.squatchTenant;
|
|
@@ -1896,6 +1921,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1896
1921
|
}
|
|
1897
1922
|
|
|
1898
1923
|
this.widgetInstance = widgetInstance;
|
|
1924
|
+
if (this.widgetInstance) this.dispatchEvent(new CustomEvent("sq:widget-loaded"));
|
|
1899
1925
|
return widgetInstance;
|
|
1900
1926
|
}
|
|
1901
1927
|
/**
|
|
@@ -1954,6 +1980,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1954
1980
|
*/
|
|
1955
1981
|
|
|
1956
1982
|
this.type = "EMBED";
|
|
1983
|
+
this.loaded = false;
|
|
1957
1984
|
}
|
|
1958
1985
|
|
|
1959
1986
|
static get observedAttributes() {
|
|
@@ -1961,7 +1988,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1961
1988
|
}
|
|
1962
1989
|
|
|
1963
1990
|
attributeChangedCallback(attr, oldVal, newVal) {
|
|
1964
|
-
if (oldVal === newVal || !
|
|
1991
|
+
if (oldVal === newVal || !this.loaded) return; // nothing to do
|
|
1965
1992
|
|
|
1966
1993
|
switch (attr) {
|
|
1967
1994
|
case "locale":
|
|
@@ -1974,10 +2001,12 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1974
2001
|
async connectedCallback() {
|
|
1975
2002
|
var _ref, _this$shadowRoot;
|
|
1976
2003
|
|
|
1977
|
-
this.
|
|
2004
|
+
this.loaded = true;
|
|
2005
|
+
this.container = this.getAttribute("container");
|
|
1978
2006
|
await this.renderWidget();
|
|
1979
2007
|
var slot = (_ref = this.shadowRoot && Array.from(this.shadowRoot.children)) == null ? void 0 : _ref.find(c => c.tagName === "SLOT");
|
|
1980
2008
|
if (slot) (_this$shadowRoot = this.shadowRoot) == null ? void 0 : _this$shadowRoot.removeChild(slot);
|
|
2009
|
+
if (this.getAttribute("open") !== null) this.open();
|
|
1981
2010
|
}
|
|
1982
2011
|
|
|
1983
2012
|
}
|
|
@@ -2001,6 +2030,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
2001
2030
|
*/
|
|
2002
2031
|
|
|
2003
2032
|
this.type = "POPUP";
|
|
2033
|
+
this.loaded = false;
|
|
2004
2034
|
this.addEventListener("click", e => {
|
|
2005
2035
|
e.stopPropagation();
|
|
2006
2036
|
this.open();
|
|
@@ -2012,7 +2042,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
2012
2042
|
}
|
|
2013
2043
|
|
|
2014
2044
|
attributeChangedCallback(attr, oldVal, newVal) {
|
|
2015
|
-
if (oldVal === newVal || !
|
|
2045
|
+
if (oldVal === newVal || !this.loaded) return; // nothing to do
|
|
2016
2046
|
|
|
2017
2047
|
switch (attr) {
|
|
2018
2048
|
case "locale":
|
|
@@ -2023,7 +2053,8 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
2023
2053
|
}
|
|
2024
2054
|
|
|
2025
2055
|
async connectedCallback() {
|
|
2026
|
-
this.
|
|
2056
|
+
this.loaded = true;
|
|
2057
|
+
this.container = this.getAttribute("container");
|
|
2027
2058
|
await this.renderWidget();
|
|
2028
2059
|
if (this.getAttribute("open") !== null) this.open();
|
|
2029
2060
|
}
|