@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/squatch.js
CHANGED
|
@@ -41,6 +41,9 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
41
41
|
|
|
42
42
|
var DEFAULT_DOMAIN = "https://app.referralsaasquatch.com";
|
|
43
43
|
var DEFAULT_NPM_CDN = "https://fast.ssqt.io/npm";
|
|
44
|
+
var DEFAULT_NAMESPACE = "squatch";
|
|
45
|
+
var IMPACT_NAMESPACE = "impact";
|
|
46
|
+
|
|
44
47
|
function validateConfig(_raw) {
|
|
45
48
|
if (typeof _raw !== "object") throw new Error("config must be an object");
|
|
46
49
|
var tenant = window.squatchTenant;
|
|
@@ -215,6 +218,7 @@ class WidgetApi {
|
|
|
215
218
|
this.tenantAlias = void 0;
|
|
216
219
|
this.domain = void 0;
|
|
217
220
|
this.npmCdn = void 0;
|
|
221
|
+
this.referralCookie = this.squatchReferralCookie;
|
|
218
222
|
var raw = config;
|
|
219
223
|
var clean = validateConfig(raw);
|
|
220
224
|
this.tenantAlias = clean.tenantAlias;
|
|
@@ -342,12 +346,11 @@ function _buildParams(_ref) {
|
|
|
342
346
|
engagementMedium,
|
|
343
347
|
locale
|
|
344
348
|
} = _ref;
|
|
345
|
-
var
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
return queryString;
|
|
349
|
+
var queryParams = new URLSearchParams();
|
|
350
|
+
queryParams.append("engagementMedium", engagementMedium);
|
|
351
|
+
if (widgetType) queryParams.append("widgetType", widgetType);
|
|
352
|
+
if (locale) queryParams.append("locale", locale);
|
|
353
|
+
return "?" + queryParams.toString();
|
|
351
354
|
}
|
|
352
355
|
|
|
353
356
|
// @ts-check
|
|
@@ -424,6 +427,8 @@ var _log$8 = debug.debug("squatch-js:widget");
|
|
|
424
427
|
|
|
425
428
|
class Widget {
|
|
426
429
|
constructor(params) {
|
|
430
|
+
var _params$context;
|
|
431
|
+
|
|
427
432
|
this.type = void 0;
|
|
428
433
|
this.content = void 0;
|
|
429
434
|
this.analyticsApi = void 0;
|
|
@@ -442,7 +447,7 @@ class Widget {
|
|
|
442
447
|
domain: params.domain
|
|
443
448
|
});
|
|
444
449
|
this.context = params.context;
|
|
445
|
-
this.container = params.context.container;
|
|
450
|
+
this.container = ((_params$context = params.context) == null ? void 0 : _params$context.container) || params.container;
|
|
446
451
|
}
|
|
447
452
|
|
|
448
453
|
_findElement() {
|
|
@@ -465,12 +470,12 @@ class Widget {
|
|
|
465
470
|
_log$8("container must be an HTMLElement or string", this.container); // find element on page
|
|
466
471
|
|
|
467
472
|
} else {
|
|
468
|
-
element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed");
|
|
473
|
+
element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed") || document.querySelector("#impactembed") || document.querySelector(".impactembed");
|
|
469
474
|
|
|
470
475
|
_log$8("loading widget with default selector", element);
|
|
471
476
|
}
|
|
472
477
|
|
|
473
|
-
if (!(element instanceof HTMLElement)) throw new Error("element with selector '" + (this.container || "#squatchembed or .
|
|
478
|
+
if (!(element instanceof HTMLElement)) throw new Error("element with selector '" + (this.container || "#squatchembed, .squatchembed, #impactembed, or .impactembed") + "' not found.'");
|
|
474
479
|
return element;
|
|
475
480
|
}
|
|
476
481
|
|
|
@@ -743,10 +748,19 @@ class EmbedWidget extends Widget {
|
|
|
743
748
|
}
|
|
744
749
|
|
|
745
750
|
async load() {
|
|
751
|
+
var _this$context;
|
|
752
|
+
|
|
746
753
|
var frame = this._createFrame();
|
|
747
754
|
|
|
748
755
|
var element = this._findElement();
|
|
749
756
|
|
|
757
|
+
if ((_this$context = this.context) != null && _this$context.container) {
|
|
758
|
+
// Custom container is used
|
|
759
|
+
element.style.visibility = "hidden";
|
|
760
|
+
element.style.height = "0";
|
|
761
|
+
element.style["overflow-y"] = "hidden";
|
|
762
|
+
}
|
|
763
|
+
|
|
750
764
|
if (this.container) {
|
|
751
765
|
if (element.shadowRoot) {
|
|
752
766
|
var _element$shadowRoot$l;
|
|
@@ -794,6 +808,7 @@ class EmbedWidget extends Widget {
|
|
|
794
808
|
} = entry.contentRect; // @ts-ignore -- number will be cast to string by browsers
|
|
795
809
|
|
|
796
810
|
frame.height = height;
|
|
811
|
+
console.log("RESIZE");
|
|
797
812
|
}
|
|
798
813
|
});
|
|
799
814
|
var container = await this._findInnerContainer(frame);
|
|
@@ -812,20 +827,19 @@ class EmbedWidget extends Widget {
|
|
|
812
827
|
|
|
813
828
|
|
|
814
829
|
open() {
|
|
815
|
-
var _frame$contentDocumen, _frame$contentWindow, _frame$contentWindow2;
|
|
816
|
-
|
|
817
830
|
var frame = this._findFrame();
|
|
818
831
|
|
|
819
832
|
if (!frame) return _log$7("no target element to open");
|
|
833
|
+
if (!frame.contentWindow) return _log$7("Frame needs a content window");
|
|
820
834
|
|
|
821
835
|
var element = this._findElement();
|
|
822
836
|
|
|
823
837
|
element.style.visibility = "unset";
|
|
824
838
|
element.style.height = "auto";
|
|
825
839
|
element.style["overflow-y"] = "auto";
|
|
826
|
-
frame
|
|
840
|
+
frame.contentWindow.document.dispatchEvent(new CustomEvent("sq:refresh"));
|
|
827
841
|
|
|
828
|
-
var _sqh =
|
|
842
|
+
var _sqh = frame.contentWindow.squatch || frame.contentWindow.widgetIdent;
|
|
829
843
|
|
|
830
844
|
if (this.context.user) {
|
|
831
845
|
this._loadEvent(_sqh);
|
|
@@ -917,7 +931,7 @@ class PopupWidget extends Widget {
|
|
|
917
931
|
try {
|
|
918
932
|
triggerElement
|
|
919
933
|
/* HTMLButton */
|
|
920
|
-
= document.querySelector(this.trigger);
|
|
934
|
+
= document.querySelector(this.trigger) || document.querySelector(".impactpop");
|
|
921
935
|
if (this.trigger && !triggerElement) _log$6("No element found with trigger selector", this.trigger);
|
|
922
936
|
} catch (_unused) {
|
|
923
937
|
_log$6("Not a valid selector", this.trigger);
|
|
@@ -945,7 +959,7 @@ class PopupWidget extends Widget {
|
|
|
945
959
|
return dialog;
|
|
946
960
|
}
|
|
947
961
|
|
|
948
|
-
load() {
|
|
962
|
+
async load() {
|
|
949
963
|
var _dialogParent$lastChi;
|
|
950
964
|
|
|
951
965
|
var frame = this._createFrame();
|
|
@@ -983,10 +997,10 @@ class PopupWidget extends Widget {
|
|
|
983
997
|
|
|
984
998
|
_log$6("Popup template loaded into iframe");
|
|
985
999
|
|
|
986
|
-
this._setupResizeHandler(frame);
|
|
1000
|
+
await this._setupResizeHandler(frame);
|
|
987
1001
|
}
|
|
988
1002
|
|
|
989
|
-
_setupResizeHandler(frame) {
|
|
1003
|
+
async _setupResizeHandler(frame) {
|
|
990
1004
|
var {
|
|
991
1005
|
contentWindow
|
|
992
1006
|
} = frame;
|
|
@@ -1488,28 +1502,29 @@ function _validateTrackOptions(raw) {
|
|
|
1488
1502
|
}
|
|
1489
1503
|
|
|
1490
1504
|
/** @hidden */
|
|
1505
|
+
|
|
1491
1506
|
function asyncLoad() {
|
|
1492
|
-
var
|
|
1493
|
-
var namespace = window[impactNamespace] ? impactNamespace : "squatch";
|
|
1494
|
-
var loaded = window[namespace] || null;
|
|
1495
|
-
var cached = window["_" + namespace] || null;
|
|
1496
|
-
|
|
1497
|
-
if (loaded && cached) {
|
|
1498
|
-
var ready = cached.ready || [];
|
|
1499
|
-
setTimeout(() => window["impactTBD"] = window.squatch, 0);
|
|
1500
|
-
ready.forEach(cb => setTimeout(() => cb(), 0));
|
|
1501
|
-
setTimeout(() => {
|
|
1502
|
-
window.squatch._auto();
|
|
1503
|
-
}, 0); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
|
|
1507
|
+
var _window;
|
|
1504
1508
|
|
|
1505
|
-
|
|
1509
|
+
var namespace = window[IMPACT_NAMESPACE] ? IMPACT_NAMESPACE : DEFAULT_NAMESPACE;
|
|
1510
|
+
var cached = ((_window = window["_" + namespace]) == null ? void 0 : _window.ready) || [];
|
|
1511
|
+
var declarativeCache = window.impactOnReady || window.squatchOnReady;
|
|
1512
|
+
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
|
|
1506
1513
|
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1514
|
+
setTimeout(() => {
|
|
1515
|
+
// Exit early if module wasn't loaded onto window
|
|
1516
|
+
if (!window[DEFAULT_NAMESPACE]) return; // Set window.impact as an alias for window.squatch.
|
|
1517
|
+
|
|
1518
|
+
window[IMPACT_NAMESPACE] = window[DEFAULT_NAMESPACE]; // Run all the ready functions in a set timeout to they happen after namespace aliasing.
|
|
1519
|
+
|
|
1520
|
+
readyFns.forEach(cb => cb()); // Perform auto popup
|
|
1521
|
+
|
|
1522
|
+
window[DEFAULT_NAMESPACE]._auto(); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
|
|
1523
|
+
|
|
1524
|
+
|
|
1525
|
+
window["_" + namespace] = undefined;
|
|
1526
|
+
delete window["_" + namespace];
|
|
1527
|
+
}, 0);
|
|
1513
1528
|
}
|
|
1514
1529
|
|
|
1515
1530
|
/** @hidden */
|
|
@@ -1760,6 +1775,11 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1760
1775
|
* Container element to contain the widget iframe
|
|
1761
1776
|
* @default this
|
|
1762
1777
|
*/
|
|
1778
|
+
|
|
1779
|
+
/**
|
|
1780
|
+
* Flag for if the component has been loaded or not
|
|
1781
|
+
* @hidden
|
|
1782
|
+
*/
|
|
1763
1783
|
constructor() {
|
|
1764
1784
|
super();
|
|
1765
1785
|
this.config = void 0;
|
|
@@ -1773,6 +1793,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1773
1793
|
this.type = void 0;
|
|
1774
1794
|
this.container = void 0;
|
|
1775
1795
|
this.element = void 0;
|
|
1796
|
+
this.loaded = void 0;
|
|
1776
1797
|
|
|
1777
1798
|
this._setWidget = (template, config) => {
|
|
1778
1799
|
var _this$config;
|
|
@@ -1783,18 +1804,20 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1783
1804
|
context: {
|
|
1784
1805
|
type: config.type,
|
|
1785
1806
|
user: config.user,
|
|
1786
|
-
container: this.container ||
|
|
1807
|
+
container: this.container || undefined,
|
|
1787
1808
|
engagementMedium: this.type
|
|
1788
1809
|
},
|
|
1789
1810
|
type: this.widgetType,
|
|
1790
1811
|
domain: ((_this$config = this.config) == null ? void 0 : _this$config.domain) || DEFAULT_DOMAIN,
|
|
1791
|
-
npmCdn: DEFAULT_NPM_CDN
|
|
1812
|
+
npmCdn: DEFAULT_NPM_CDN,
|
|
1813
|
+
container: this
|
|
1792
1814
|
};
|
|
1793
1815
|
|
|
1794
1816
|
if (this.type === "EMBED") {
|
|
1795
|
-
return new EmbedWidget(params
|
|
1817
|
+
return new EmbedWidget(params);
|
|
1796
1818
|
} else {
|
|
1797
|
-
|
|
1819
|
+
var useFirstChildTrigger = this.firstChild ? null : undefined;
|
|
1820
|
+
return new PopupWidget(params, useFirstChildTrigger);
|
|
1798
1821
|
}
|
|
1799
1822
|
};
|
|
1800
1823
|
|
|
@@ -1806,17 +1829,19 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1806
1829
|
content: "error",
|
|
1807
1830
|
context: {
|
|
1808
1831
|
type: "error",
|
|
1809
|
-
container: this.container ||
|
|
1832
|
+
container: this.container || undefined
|
|
1810
1833
|
},
|
|
1811
1834
|
type: "ERROR_WIDGET",
|
|
1812
1835
|
domain: ((_this$config2 = this.config) == null ? void 0 : _this$config2.domain) || DEFAULT_DOMAIN,
|
|
1813
|
-
npmCdn: DEFAULT_NPM_CDN
|
|
1836
|
+
npmCdn: DEFAULT_NPM_CDN,
|
|
1837
|
+
container: this
|
|
1814
1838
|
};
|
|
1815
1839
|
|
|
1816
1840
|
if (this.type === "EMBED") {
|
|
1817
|
-
return new EmbedWidget(params
|
|
1841
|
+
return new EmbedWidget(params);
|
|
1818
1842
|
} else {
|
|
1819
|
-
|
|
1843
|
+
var useFirstChildTrigger = this.firstChild ? null : undefined;
|
|
1844
|
+
return new PopupWidget(params, useFirstChildTrigger);
|
|
1820
1845
|
}
|
|
1821
1846
|
};
|
|
1822
1847
|
|
|
@@ -1825,7 +1850,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1825
1850
|
this.hide = this.close;
|
|
1826
1851
|
this.attachShadow({
|
|
1827
1852
|
mode: "open"
|
|
1828
|
-
}).innerHTML = "<style>:host { display:
|
|
1853
|
+
}).innerHTML = "<style>:host { display: block; }</style><slot></slot>";
|
|
1829
1854
|
this.config = getConfig();
|
|
1830
1855
|
this.token = getToken();
|
|
1831
1856
|
this.tenant = window.squatchTenant;
|
|
@@ -1901,6 +1926,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1901
1926
|
}
|
|
1902
1927
|
|
|
1903
1928
|
this.widgetInstance = widgetInstance;
|
|
1929
|
+
if (this.widgetInstance) this.dispatchEvent(new CustomEvent("sq:widget-loaded"));
|
|
1904
1930
|
return widgetInstance;
|
|
1905
1931
|
}
|
|
1906
1932
|
/**
|
|
@@ -1959,6 +1985,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1959
1985
|
*/
|
|
1960
1986
|
|
|
1961
1987
|
this.type = "EMBED";
|
|
1988
|
+
this.loaded = false;
|
|
1962
1989
|
}
|
|
1963
1990
|
|
|
1964
1991
|
static get observedAttributes() {
|
|
@@ -1966,7 +1993,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1966
1993
|
}
|
|
1967
1994
|
|
|
1968
1995
|
attributeChangedCallback(attr, oldVal, newVal) {
|
|
1969
|
-
if (oldVal === newVal || !
|
|
1996
|
+
if (oldVal === newVal || !this.loaded) return; // nothing to do
|
|
1970
1997
|
|
|
1971
1998
|
switch (attr) {
|
|
1972
1999
|
case "locale":
|
|
@@ -1979,10 +2006,12 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1979
2006
|
async connectedCallback() {
|
|
1980
2007
|
var _ref, _this$shadowRoot;
|
|
1981
2008
|
|
|
1982
|
-
this.
|
|
2009
|
+
this.loaded = true;
|
|
2010
|
+
this.container = this.getAttribute("container");
|
|
1983
2011
|
await this.renderWidget();
|
|
1984
2012
|
var slot = (_ref = this.shadowRoot && Array.from(this.shadowRoot.children)) == null ? void 0 : _ref.find(c => c.tagName === "SLOT");
|
|
1985
2013
|
if (slot) (_this$shadowRoot = this.shadowRoot) == null ? void 0 : _this$shadowRoot.removeChild(slot);
|
|
2014
|
+
if (this.getAttribute("open") !== null) this.open();
|
|
1986
2015
|
}
|
|
1987
2016
|
|
|
1988
2017
|
}
|
|
@@ -2006,6 +2035,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
2006
2035
|
*/
|
|
2007
2036
|
|
|
2008
2037
|
this.type = "POPUP";
|
|
2038
|
+
this.loaded = false;
|
|
2009
2039
|
this.addEventListener("click", e => {
|
|
2010
2040
|
e.stopPropagation();
|
|
2011
2041
|
this.open();
|
|
@@ -2017,7 +2047,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
2017
2047
|
}
|
|
2018
2048
|
|
|
2019
2049
|
attributeChangedCallback(attr, oldVal, newVal) {
|
|
2020
|
-
if (oldVal === newVal || !
|
|
2050
|
+
if (oldVal === newVal || !this.loaded) return; // nothing to do
|
|
2021
2051
|
|
|
2022
2052
|
switch (attr) {
|
|
2023
2053
|
case "locale":
|
|
@@ -2028,7 +2058,8 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
2028
2058
|
}
|
|
2029
2059
|
|
|
2030
2060
|
async connectedCallback() {
|
|
2031
|
-
this.
|
|
2061
|
+
this.loaded = true;
|
|
2062
|
+
this.container = this.getAttribute("container");
|
|
2032
2063
|
await this.renderWidget();
|
|
2033
2064
|
if (this.getAttribute("open") !== null) this.open();
|
|
2034
2065
|
}
|