@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.
- package/CHANGELOG.md +3 -0
- package/README.md +14 -5
- package/coverage/clover.xml +582 -566
- package/coverage/coverage-final.json +20 -19
- package/coverage/lcov.info +964 -930
- package/dist/async.d.ts +4 -2
- package/dist/globals.d.ts +4 -0
- package/dist/squatch.esm.js +59 -49
- package/dist/squatch.esm.js.map +1 -1
- package/dist/squatch.js +59 -49
- package/dist/squatch.js.map +1 -1
- package/dist/squatch.min.js +1 -1
- package/dist/utils/validate.d.ts +0 -2
- package/dist/widgets/PopupWidget.d.ts +2 -2
- package/dist/widgets/Widgets.d.ts +8 -8
- package/dist/widgets/declarative/DeclarativeWidget.d.ts +10 -5
- package/package.json +1 -1
- 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/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/dist/squatch.min.js.map +0 -1
- package/dist/squatch.modern.js +0 -2
- package/dist/squatch.modern.js.map +0 -1
- package/dist/stats.html +0 -208
- package/dist/utils/domUtils.d.ts +0 -1
- package/dist/utils/loadEvent.d.ts +0 -2
- package/dist/widgets/CtaWidget.d.ts +0 -24
- package/dist/widgets/IREmbedWidget.d.ts +0 -29
- package/dist/widgets/IRPopupWidget.d.ts +0 -32
- package/dist/widgets/declarative/DeclarativeEmbedWidget.d.ts +0 -12
- 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;
|
|
@@ -81,10 +84,10 @@ function validatePasswordlessConfig(raw) {
|
|
|
81
84
|
return raw;
|
|
82
85
|
}
|
|
83
86
|
function getToken() {
|
|
84
|
-
return window.
|
|
87
|
+
return window.impactToken || window.squatchToken;
|
|
85
88
|
}
|
|
86
89
|
function getConfig() {
|
|
87
|
-
return window.
|
|
90
|
+
return window.impactConfig || window.squatchConfig;
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
debug.debug("squatch-js:io");
|
|
@@ -342,12 +345,11 @@ function _buildParams(_ref) {
|
|
|
342
345
|
engagementMedium,
|
|
343
346
|
locale
|
|
344
347
|
} = _ref;
|
|
345
|
-
var
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
return queryString;
|
|
348
|
+
var queryParams = new URLSearchParams();
|
|
349
|
+
queryParams.append("engagementMedium", engagementMedium);
|
|
350
|
+
if (widgetType) queryParams.append("widgetType", widgetType);
|
|
351
|
+
if (locale) queryParams.append("locale", locale);
|
|
352
|
+
return "?" + queryParams.toString();
|
|
351
353
|
}
|
|
352
354
|
|
|
353
355
|
// @ts-check
|
|
@@ -442,7 +444,7 @@ class Widget {
|
|
|
442
444
|
domain: params.domain
|
|
443
445
|
});
|
|
444
446
|
this.context = params.context;
|
|
445
|
-
this.container = params.context.container;
|
|
447
|
+
this.container = params.container || params.context.container;
|
|
446
448
|
}
|
|
447
449
|
|
|
448
450
|
_findElement() {
|
|
@@ -465,12 +467,12 @@ class Widget {
|
|
|
465
467
|
_log$8("container must be an HTMLElement or string", this.container); // find element on page
|
|
466
468
|
|
|
467
469
|
} else {
|
|
468
|
-
element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed");
|
|
470
|
+
element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed") || document.querySelector("#impactembed") || document.querySelector(".impactembed");
|
|
469
471
|
|
|
470
472
|
_log$8("loading widget with default selector", element);
|
|
471
473
|
}
|
|
472
474
|
|
|
473
|
-
if (!(element instanceof HTMLElement)) throw new Error("element with selector '" + (this.container || "#squatchembed or .
|
|
475
|
+
if (!(element instanceof HTMLElement)) throw new Error("element with selector '" + (this.container || "#squatchembed, .squatchembed, #impactembed, or .impactembed") + "' not found.'");
|
|
474
476
|
return element;
|
|
475
477
|
}
|
|
476
478
|
|
|
@@ -545,8 +547,7 @@ class Widget {
|
|
|
545
547
|
_log$8("ERROR: pushAnalyticsShareClickedEvent() " + ex);
|
|
546
548
|
});
|
|
547
549
|
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
+
}
|
|
550
551
|
|
|
551
552
|
_error(rs, mode, style) {
|
|
552
553
|
if (mode === void 0) {
|
|
@@ -813,20 +814,19 @@ class EmbedWidget extends Widget {
|
|
|
813
814
|
|
|
814
815
|
|
|
815
816
|
open() {
|
|
816
|
-
var _frame$contentDocumen, _frame$contentWindow, _frame$contentWindow2;
|
|
817
|
-
|
|
818
817
|
var frame = this._findFrame();
|
|
819
818
|
|
|
820
819
|
if (!frame) return _log$7("no target element to open");
|
|
820
|
+
if (!frame.contentWindow) return _log$7("Frame needs a content window");
|
|
821
821
|
|
|
822
822
|
var element = this._findElement();
|
|
823
823
|
|
|
824
824
|
element.style.visibility = "unset";
|
|
825
825
|
element.style.height = "auto";
|
|
826
826
|
element.style["overflow-y"] = "auto";
|
|
827
|
-
frame
|
|
827
|
+
frame.contentWindow.document.dispatchEvent(new CustomEvent("sq:refresh"));
|
|
828
828
|
|
|
829
|
-
var _sqh =
|
|
829
|
+
var _sqh = frame.contentWindow.squatch || frame.contentWindow.widgetIdent;
|
|
830
830
|
|
|
831
831
|
if (this.context.user) {
|
|
832
832
|
this._loadEvent(_sqh);
|
|
@@ -863,7 +863,7 @@ class EmbedWidget extends Widget {
|
|
|
863
863
|
|
|
864
864
|
_shouldFireLoadEvent() {
|
|
865
865
|
var noContainer = !this.container;
|
|
866
|
-
var isComponent = this.container instanceof HTMLElement && this.container.tagName.startsWith("SQUATCH-");
|
|
866
|
+
var isComponent = this.container instanceof HTMLElement && (this.container.tagName.startsWith("SQUATCH-") || this.container.tagName.startsWith("IMPACT-"));
|
|
867
867
|
var isVerified = !!this.context.user;
|
|
868
868
|
return isVerified && (noContainer || isComponent);
|
|
869
869
|
}
|
|
@@ -918,7 +918,7 @@ class PopupWidget extends Widget {
|
|
|
918
918
|
try {
|
|
919
919
|
triggerElement
|
|
920
920
|
/* HTMLButton */
|
|
921
|
-
= document.querySelector(this.trigger);
|
|
921
|
+
= document.querySelector(this.trigger) || document.querySelector(".impactpop");
|
|
922
922
|
if (this.trigger && !triggerElement) _log$6("No element found with trigger selector", this.trigger);
|
|
923
923
|
} catch (_unused) {
|
|
924
924
|
_log$6("Not a valid selector", this.trigger);
|
|
@@ -946,7 +946,7 @@ class PopupWidget extends Widget {
|
|
|
946
946
|
return dialog;
|
|
947
947
|
}
|
|
948
948
|
|
|
949
|
-
load() {
|
|
949
|
+
async load() {
|
|
950
950
|
var _dialogParent$lastChi;
|
|
951
951
|
|
|
952
952
|
var frame = this._createFrame();
|
|
@@ -984,10 +984,10 @@ class PopupWidget extends Widget {
|
|
|
984
984
|
|
|
985
985
|
_log$6("Popup template loaded into iframe");
|
|
986
986
|
|
|
987
|
-
this._setupResizeHandler(frame);
|
|
987
|
+
await this._setupResizeHandler(frame);
|
|
988
988
|
}
|
|
989
989
|
|
|
990
|
-
_setupResizeHandler(frame) {
|
|
990
|
+
async _setupResizeHandler(frame) {
|
|
991
991
|
var {
|
|
992
992
|
contentWindow
|
|
993
993
|
} = frame;
|
|
@@ -1091,11 +1091,11 @@ class Widgets {
|
|
|
1091
1091
|
*/
|
|
1092
1092
|
|
|
1093
1093
|
/**
|
|
1094
|
-
* Tenant alias of SaaSquatch tenant
|
|
1094
|
+
* Tenant alias of SaaSquatch tenant
|
|
1095
1095
|
*/
|
|
1096
1096
|
|
|
1097
1097
|
/**
|
|
1098
|
-
* SaaSquatch domain for API requests
|
|
1098
|
+
* SaaSquatch domain for API requests
|
|
1099
1099
|
* @default "https://app.referralsaasquatch.com"
|
|
1100
1100
|
*/
|
|
1101
1101
|
|
|
@@ -1139,13 +1139,13 @@ class Widgets {
|
|
|
1139
1139
|
* @param {Object} config.user The user details
|
|
1140
1140
|
* @param {string} config.user.id The user id
|
|
1141
1141
|
* @param {string} config.user.accountId The user account id
|
|
1142
|
-
* @param {WidgetType} config.widgetType The content of the widget
|
|
1143
|
-
* @param {EngagementMedium} config.engagementMedium How to display the widget
|
|
1142
|
+
* @param {WidgetType} config.widgetType The content of the widget
|
|
1143
|
+
* @param {EngagementMedium} config.engagementMedium How to display the widget
|
|
1144
1144
|
* @param {string} config.jwt the JSON Web Token (JWT) that is used to validate the data (can be disabled)
|
|
1145
1145
|
* @param {HTMLElement | string | undefined} config.container Element to load the widget into
|
|
1146
1146
|
* @param {string | undefined} config.trigger Trigger element for opening the popup widget
|
|
1147
1147
|
*
|
|
1148
|
-
* @return {Promise<WidgetResult>} json object if true, with a Widget and user details
|
|
1148
|
+
* @return {Promise<WidgetResult>} json object if true, with a Widget and user details
|
|
1149
1149
|
*/
|
|
1150
1150
|
|
|
1151
1151
|
|
|
@@ -1183,12 +1183,12 @@ class Widgets {
|
|
|
1183
1183
|
* @param {Object} config.user The user details
|
|
1184
1184
|
* @param {string} config.user.id The user id
|
|
1185
1185
|
* @param {string} config.user.accountId The user account id
|
|
1186
|
-
* @param {WidgetType} config.widgetType The content of the widget
|
|
1187
|
-
* @param {EngagementMedium} config.engagementMedium How to display the widget
|
|
1186
|
+
* @param {WidgetType} config.widgetType The content of the widget
|
|
1187
|
+
* @param {EngagementMedium} config.engagementMedium How to display the widget
|
|
1188
1188
|
* @param {string} config.jwt the JSON Web Token (JWT) that is used
|
|
1189
1189
|
* to validate the data (can be disabled)
|
|
1190
1190
|
*
|
|
1191
|
-
* @return {Promise<WidgetResult>} json object if true, with a Widget and user details
|
|
1191
|
+
* @return {Promise<WidgetResult>} json object if true, with a Widget and user details
|
|
1192
1192
|
*/
|
|
1193
1193
|
|
|
1194
1194
|
|
|
@@ -1489,19 +1489,17 @@ function _validateTrackOptions(raw) {
|
|
|
1489
1489
|
}
|
|
1490
1490
|
|
|
1491
1491
|
/** @hidden */
|
|
1492
|
+
|
|
1492
1493
|
function asyncLoad() {
|
|
1493
|
-
var
|
|
1494
|
-
var namespace = window[impactNamespace] ? impactNamespace : "squatch";
|
|
1495
|
-
console.log({
|
|
1496
|
-
namespace
|
|
1497
|
-
});
|
|
1494
|
+
var namespace = window[IMPACT_NAMESPACE] ? IMPACT_NAMESPACE : DEFAULT_NAMESPACE;
|
|
1498
1495
|
var loaded = window[namespace] || null;
|
|
1499
1496
|
var cached = window["_" + namespace] || null;
|
|
1497
|
+
var declarativeCache = window.impactOnReady || window.squatchOnReady;
|
|
1498
|
+
setTimeout(() => window[IMPACT_NAMESPACE] = window[DEFAULT_NAMESPACE], 0);
|
|
1499
|
+
if (declarativeCache) setTimeout(() => declarativeCache(), 0);
|
|
1500
1500
|
|
|
1501
|
-
if (loaded
|
|
1502
|
-
|
|
1503
|
-
setTimeout(() => window["impactTBD"] = window.squatch, 0);
|
|
1504
|
-
ready.forEach(cb => setTimeout(() => cb(), 0));
|
|
1501
|
+
if (loaded) {
|
|
1502
|
+
if (cached) (cached.ready || []).forEach(cb => setTimeout(() => cb(), 0));
|
|
1505
1503
|
setTimeout(() => {
|
|
1506
1504
|
window.squatch._auto();
|
|
1507
1505
|
}, 0); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
|
|
@@ -1690,7 +1688,7 @@ function convertExtraToConfig(obj) {
|
|
|
1690
1688
|
};
|
|
1691
1689
|
}
|
|
1692
1690
|
|
|
1693
|
-
var _log$2 = debug.debug("squatch-js:
|
|
1691
|
+
var _log$2 = debug.debug("squatch-js:decodeUserJwt");
|
|
1694
1692
|
|
|
1695
1693
|
function decodeUserJwt(tokenStr) {
|
|
1696
1694
|
try {
|
|
@@ -1709,7 +1707,7 @@ function decodeUserJwt(tokenStr) {
|
|
|
1709
1707
|
|
|
1710
1708
|
var _log$1 = debug__default['default']("squatch-js:DeclarativeWidget");
|
|
1711
1709
|
/**
|
|
1712
|
-
* Abstract class for building web-components that render SaaSquatch widgets to the DOM
|
|
1710
|
+
* Abstract class for building web-components that render SaaSquatch widgets to the DOM
|
|
1713
1711
|
* @abstract
|
|
1714
1712
|
* @example
|
|
1715
1713
|
* class TestWidgetElement extends DeclarativeWidget {}
|
|
@@ -1757,13 +1755,18 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1757
1755
|
*/
|
|
1758
1756
|
|
|
1759
1757
|
/**
|
|
1760
|
-
* Determines whether to render the widget as an embedding widget or popup widget
|
|
1758
|
+
* Determines whether to render the widget as an embedding widget or popup widget
|
|
1761
1759
|
*/
|
|
1762
1760
|
|
|
1763
1761
|
/**
|
|
1764
1762
|
* Container element to contain the widget iframe
|
|
1765
1763
|
* @default this
|
|
1766
1764
|
*/
|
|
1765
|
+
|
|
1766
|
+
/**
|
|
1767
|
+
* Flag for if the component has been loaded or not
|
|
1768
|
+
* @hidden
|
|
1769
|
+
*/
|
|
1767
1770
|
constructor() {
|
|
1768
1771
|
super();
|
|
1769
1772
|
this.config = void 0;
|
|
@@ -1777,6 +1780,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1777
1780
|
this.type = void 0;
|
|
1778
1781
|
this.container = void 0;
|
|
1779
1782
|
this.element = void 0;
|
|
1783
|
+
this.loaded = void 0;
|
|
1780
1784
|
|
|
1781
1785
|
this._setWidget = (template, config) => {
|
|
1782
1786
|
var _this$config;
|
|
@@ -1798,7 +1802,8 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1798
1802
|
if (this.type === "EMBED") {
|
|
1799
1803
|
return new EmbedWidget(params, params.context.container);
|
|
1800
1804
|
} else {
|
|
1801
|
-
|
|
1805
|
+
var useFirstChildTrigger = this.firstChild ? null : undefined;
|
|
1806
|
+
return new PopupWidget(params, useFirstChildTrigger);
|
|
1802
1807
|
}
|
|
1803
1808
|
};
|
|
1804
1809
|
|
|
@@ -1820,7 +1825,8 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1820
1825
|
if (this.type === "EMBED") {
|
|
1821
1826
|
return new EmbedWidget(params, params.context.container);
|
|
1822
1827
|
} else {
|
|
1823
|
-
|
|
1828
|
+
var useFirstChildTrigger = this.firstChild ? null : undefined;
|
|
1829
|
+
return new PopupWidget(params, useFirstChildTrigger);
|
|
1824
1830
|
}
|
|
1825
1831
|
};
|
|
1826
1832
|
|
|
@@ -1888,7 +1894,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1888
1894
|
}
|
|
1889
1895
|
|
|
1890
1896
|
/**
|
|
1891
|
-
* Fetches widget content from SaaSquatch and builds a Widget instance to support rendering the widget in the DOM
|
|
1897
|
+
* Fetches widget content from SaaSquatch and builds a Widget instance to support rendering the widget in the DOM
|
|
1892
1898
|
* @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type`
|
|
1893
1899
|
* @throws Throws an Error if `widgetType` is undefined
|
|
1894
1900
|
*/
|
|
@@ -1908,7 +1914,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1908
1914
|
return widgetInstance;
|
|
1909
1915
|
}
|
|
1910
1916
|
/**
|
|
1911
|
-
* Calls {@link getWidgetInstance} to build the Widget instance and loads the widget iframe into the DOM
|
|
1917
|
+
* Calls {@link getWidgetInstance} to build the Widget instance and loads the widget iframe into the DOM
|
|
1912
1918
|
*/
|
|
1913
1919
|
|
|
1914
1920
|
|
|
@@ -1917,7 +1923,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1917
1923
|
await this.widgetInstance.load();
|
|
1918
1924
|
}
|
|
1919
1925
|
/**
|
|
1920
|
-
* Builds a Widget instance for the default error widget
|
|
1926
|
+
* Builds a Widget instance for the default error widget
|
|
1921
1927
|
* @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type`
|
|
1922
1928
|
*/
|
|
1923
1929
|
|
|
@@ -1963,6 +1969,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1963
1969
|
*/
|
|
1964
1970
|
|
|
1965
1971
|
this.type = "EMBED";
|
|
1972
|
+
this.loaded = false;
|
|
1966
1973
|
}
|
|
1967
1974
|
|
|
1968
1975
|
static get observedAttributes() {
|
|
@@ -1970,7 +1977,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1970
1977
|
}
|
|
1971
1978
|
|
|
1972
1979
|
attributeChangedCallback(attr, oldVal, newVal) {
|
|
1973
|
-
if (oldVal === newVal || !
|
|
1980
|
+
if (oldVal === newVal || !this.loaded) return; // nothing to do
|
|
1974
1981
|
|
|
1975
1982
|
switch (attr) {
|
|
1976
1983
|
case "locale":
|
|
@@ -1987,6 +1994,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1987
1994
|
await this.renderWidget();
|
|
1988
1995
|
var slot = (_ref = this.shadowRoot && Array.from(this.shadowRoot.children)) == null ? void 0 : _ref.find(c => c.tagName === "SLOT");
|
|
1989
1996
|
if (slot) (_this$shadowRoot = this.shadowRoot) == null ? void 0 : _this$shadowRoot.removeChild(slot);
|
|
1997
|
+
this.loaded = true;
|
|
1990
1998
|
}
|
|
1991
1999
|
|
|
1992
2000
|
}
|
|
@@ -2010,6 +2018,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
2010
2018
|
*/
|
|
2011
2019
|
|
|
2012
2020
|
this.type = "POPUP";
|
|
2021
|
+
this.loaded = false;
|
|
2013
2022
|
this.addEventListener("click", e => {
|
|
2014
2023
|
e.stopPropagation();
|
|
2015
2024
|
this.open();
|
|
@@ -2021,7 +2030,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
2021
2030
|
}
|
|
2022
2031
|
|
|
2023
2032
|
attributeChangedCallback(attr, oldVal, newVal) {
|
|
2024
|
-
if (oldVal === newVal || !
|
|
2033
|
+
if (oldVal === newVal || !this.loaded) return; // nothing to do
|
|
2025
2034
|
|
|
2026
2035
|
switch (attr) {
|
|
2027
2036
|
case "locale":
|
|
@@ -2035,6 +2044,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
2035
2044
|
this.container = this.getAttribute("container") || this;
|
|
2036
2045
|
await this.renderWidget();
|
|
2037
2046
|
if (this.getAttribute("open") !== null) this.open();
|
|
2047
|
+
this.loaded = true;
|
|
2038
2048
|
}
|
|
2039
2049
|
|
|
2040
2050
|
}
|