@saasquatch/squatch-js 2.6.0-1 → 2.6.0-3
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/coverage/clover.xml +2 -2
- package/coverage/lcov-report/WidgetApi.ts.html +85 -85
- package/coverage/lcov-report/api/AnalyticsApi.ts.html +1 -1
- package/coverage/lcov-report/api/WidgetApi.ts.html +6 -6
- package/coverage/lcov-report/api/graphql.ts.html +1 -1
- package/coverage/lcov-report/utils/domready.ts.html +1 -1
- package/coverage/lcov-report/utils/io.ts.html +1 -1
- package/coverage/lcov-report/utils/validate.ts.html +9 -9
- package/coverage/lcov-report/widgets/EmbedWidget.ts.html +1 -1
- package/coverage/lcov-report/widgets/PopupWidget.ts.html +1 -1
- package/coverage/lcov-report/widgets/Widget.ts.html +12 -9
- package/coverage/lcov-report/widgets/Widgets.ts.html +79 -79
- package/dist/squatch.d.ts +1 -16
- package/dist/squatch.esm.js +43 -42
- package/dist/squatch.esm.js.map +1 -1
- package/dist/squatch.js +42 -42
- package/dist/squatch.js.map +1 -1
- package/dist/squatch.min.js +1 -1
- package/dist/widgets/declarative/DeclarativeWidget.d.ts +1 -0
- package/jest.config.ts +1 -3
- package/package.json +1 -1
package/dist/squatch.js
CHANGED
|
@@ -683,6 +683,7 @@ class Widget {
|
|
|
683
683
|
function delay(duration) {
|
|
684
684
|
return new Promise(function (resolve, reject) {
|
|
685
685
|
setTimeout(function () {
|
|
686
|
+
/* istanbul ignore next */
|
|
686
687
|
resolve(() => {});
|
|
687
688
|
}, duration);
|
|
688
689
|
});
|
|
@@ -1114,7 +1115,7 @@ class Widgets {
|
|
|
1114
1115
|
return {
|
|
1115
1116
|
widget: this._renderWidget(response, clean, {
|
|
1116
1117
|
type: "upsert",
|
|
1117
|
-
user: clean.user
|
|
1118
|
+
user: clean.user,
|
|
1118
1119
|
engagementMedium: config.engagementMedium,
|
|
1119
1120
|
container: config.container,
|
|
1120
1121
|
trigger: config.trigger
|
|
@@ -1226,15 +1227,17 @@ class Widgets {
|
|
|
1226
1227
|
|
|
1227
1228
|
|
|
1228
1229
|
_renderWidget(response, config, context) {
|
|
1230
|
+
var _opts$widget;
|
|
1231
|
+
|
|
1229
1232
|
_log$4("Rendering Widget...");
|
|
1230
1233
|
|
|
1231
1234
|
if (!response) throw new Error("Unable to get a response");
|
|
1232
1235
|
var widget;
|
|
1233
1236
|
var displayOnLoad = !!config.displayOnLoad;
|
|
1234
|
-
var opts = response.jsOptions ||
|
|
1237
|
+
var opts = response.jsOptions || {};
|
|
1235
1238
|
var params = {
|
|
1236
1239
|
content: response.template,
|
|
1237
|
-
type: config.widgetType || opts.widget.defaultWidgetType,
|
|
1240
|
+
type: config.widgetType || ((_opts$widget = opts.widget) == null ? void 0 : _opts$widget.defaultWidgetType),
|
|
1238
1241
|
api: this.api,
|
|
1239
1242
|
domain: this.domain,
|
|
1240
1243
|
npmCdn: this.npmCdn,
|
|
@@ -1244,7 +1247,15 @@ class Widgets {
|
|
|
1244
1247
|
if (opts.widgetUrlMappings) {
|
|
1245
1248
|
opts.widgetUrlMappings.forEach(rule => {
|
|
1246
1249
|
if (Widgets._matchesUrl(rule.url)) {
|
|
1247
|
-
|
|
1250
|
+
var _response$user, _response$user$referr;
|
|
1251
|
+
|
|
1252
|
+
console.log({
|
|
1253
|
+
response,
|
|
1254
|
+
rule
|
|
1255
|
+
});
|
|
1256
|
+
|
|
1257
|
+
if (rule.widgetType !== "CONVERSION_WIDGET" || (_response$user = response.user) != null && (_response$user$referr = _response$user.referredBy) != null && _response$user$referr.code) {
|
|
1258
|
+
console.log("HERE");
|
|
1248
1259
|
displayOnLoad = rule.displayOnLoad;
|
|
1249
1260
|
|
|
1250
1261
|
_log$4("Display " + rule.widgetType + " on " + rule.url);
|
|
@@ -1265,13 +1276,17 @@ class Widgets {
|
|
|
1265
1276
|
} = _ref;
|
|
1266
1277
|
|
|
1267
1278
|
if (Widgets._matchesUrl(url)) {
|
|
1279
|
+
var _response$user2, _response$user2$refer;
|
|
1280
|
+
|
|
1268
1281
|
_log$4("Fuel Tank URL matches");
|
|
1269
1282
|
|
|
1270
|
-
if (response.user.referredBy &&
|
|
1283
|
+
if ((_response$user2 = response.user) != null && (_response$user2$refer = _response$user2.referredBy) != null && _response$user2$refer.code) {
|
|
1271
1284
|
var formAutofill = document.querySelector(formSelector);
|
|
1272
1285
|
|
|
1273
1286
|
if (formAutofill) {
|
|
1274
|
-
|
|
1287
|
+
var _response$user$referr2;
|
|
1288
|
+
|
|
1289
|
+
formAutofill.value = ((_response$user$referr2 = response.user.referredBy.referredReward) == null ? void 0 : _response$user$referr2.fuelTankCode) || "";
|
|
1275
1290
|
} else {
|
|
1276
1291
|
_log$4(new Error("Element with id/class " + formSelector + " was not found."));
|
|
1277
1292
|
}
|
|
@@ -1281,7 +1296,7 @@ class Widgets {
|
|
|
1281
1296
|
}
|
|
1282
1297
|
|
|
1283
1298
|
if (config.engagementMedium === "EMBED") {
|
|
1284
|
-
this._renderEmbedWidget(params, params.context.container);
|
|
1299
|
+
widget = this._renderEmbedWidget(params, params.context.container);
|
|
1285
1300
|
} else if (config.engagementMedium === "POPUP") {
|
|
1286
1301
|
widget = this._renderPopupWidget(params);
|
|
1287
1302
|
if (displayOnLoad) widget.open();
|
|
@@ -1303,7 +1318,7 @@ class Widgets {
|
|
|
1303
1318
|
}
|
|
1304
1319
|
|
|
1305
1320
|
_renderEmbedWidget(params, container) {
|
|
1306
|
-
var widget = new EmbedWidget(params);
|
|
1321
|
+
var widget = new EmbedWidget(params, container);
|
|
1307
1322
|
widget.load();
|
|
1308
1323
|
return widget;
|
|
1309
1324
|
}
|
|
@@ -1660,6 +1675,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1660
1675
|
this.token = void 0;
|
|
1661
1676
|
this.tenant = void 0;
|
|
1662
1677
|
this.widgetType = void 0;
|
|
1678
|
+
this.locale = void 0;
|
|
1663
1679
|
this.widgetApi = void 0;
|
|
1664
1680
|
this.analyticsApi = void 0;
|
|
1665
1681
|
this.type = void 0;
|
|
@@ -1722,6 +1738,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1722
1738
|
this.token = window.squatchToken;
|
|
1723
1739
|
this.tenant = window.squatchTenant;
|
|
1724
1740
|
this.container = this;
|
|
1741
|
+
this.locale = validateLocale(navigator.language.replace(/\-/g, "_"));
|
|
1725
1742
|
}
|
|
1726
1743
|
|
|
1727
1744
|
_setupApis(config) {
|
|
@@ -1738,7 +1755,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1738
1755
|
}
|
|
1739
1756
|
|
|
1740
1757
|
async renderPasswordlessVariant() {
|
|
1741
|
-
var _configs$widgetConfig, _configs$widgetConfig2;
|
|
1758
|
+
var _configs$widgetConfig, _configs$widgetConfig2, _configs$widgetConfig3;
|
|
1742
1759
|
|
|
1743
1760
|
var configs = _getAutoConfig();
|
|
1744
1761
|
|
|
@@ -1746,7 +1763,8 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1746
1763
|
|
|
1747
1764
|
return await this.widgetApi.render({
|
|
1748
1765
|
engagementMedium: (configs == null ? void 0 : (_configs$widgetConfig = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig.engagementMedium) || this.type,
|
|
1749
|
-
widgetType: (configs == null ? void 0 : (_configs$widgetConfig2 = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig2.widgetType) || this.widgetType
|
|
1766
|
+
widgetType: (configs == null ? void 0 : (_configs$widgetConfig2 = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig2.widgetType) || this.widgetType,
|
|
1767
|
+
locale: (configs == null ? void 0 : (_configs$widgetConfig3 = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig3.locale) || this.locale
|
|
1750
1768
|
}).then(res => this._setWidget(res.template, {
|
|
1751
1769
|
type: "passwordless"
|
|
1752
1770
|
})).catch(this.setErrorWidget);
|
|
@@ -1771,6 +1789,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1771
1789
|
async getWidgetInstance() {
|
|
1772
1790
|
var widgetInstance;
|
|
1773
1791
|
this.widgetType = this.getAttribute("widget") || undefined;
|
|
1792
|
+
this.locale = this.getAttribute("locale") || this.locale;
|
|
1774
1793
|
if (!this.widgetType) throw new Error("No widget has been specified");
|
|
1775
1794
|
|
|
1776
1795
|
if (!this.token) {
|
|
@@ -1806,22 +1825,22 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1806
1825
|
}
|
|
1807
1826
|
|
|
1808
1827
|
static get observedAttributes() {
|
|
1809
|
-
return ["widget", "
|
|
1828
|
+
return ["widget", "locale"];
|
|
1810
1829
|
}
|
|
1811
1830
|
|
|
1812
1831
|
attributeChangedCallback(attr, oldVal, newVal) {
|
|
1813
1832
|
if (oldVal === newVal || !oldVal) return; // nothing to do
|
|
1814
1833
|
|
|
1815
1834
|
switch (attr) {
|
|
1835
|
+
case "locale":
|
|
1816
1836
|
case "widget":
|
|
1817
1837
|
this.connectedCallback();
|
|
1818
1838
|
break;
|
|
1819
|
-
// Specific to embed widgets
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
break;
|
|
1839
|
+
// // Specific to embed widgets
|
|
1840
|
+
// case "container":
|
|
1841
|
+
// if (this.widgetInstance._findElement()) this.close();
|
|
1842
|
+
// this.connectedCallback();
|
|
1843
|
+
// break;
|
|
1825
1844
|
}
|
|
1826
1845
|
}
|
|
1827
1846
|
|
|
@@ -1847,7 +1866,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
1847
1866
|
}
|
|
1848
1867
|
|
|
1849
1868
|
static get observedAttributes() {
|
|
1850
|
-
return ["widget", "id", "open"];
|
|
1869
|
+
return ["widget", "id", "open", "locale"];
|
|
1851
1870
|
}
|
|
1852
1871
|
|
|
1853
1872
|
attributeChangedCallback(attr, oldVal, newVal) {
|
|
@@ -1855,6 +1874,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
1855
1874
|
|
|
1856
1875
|
switch (attr) {
|
|
1857
1876
|
case "open":
|
|
1877
|
+
case "locale":
|
|
1858
1878
|
case "widget":
|
|
1859
1879
|
this.connectedCallback();
|
|
1860
1880
|
break;
|
|
@@ -1899,7 +1919,7 @@ var _events = null;
|
|
|
1899
1919
|
*/
|
|
1900
1920
|
|
|
1901
1921
|
function api() {
|
|
1902
|
-
if (!_api)
|
|
1922
|
+
if (!_api) init({});
|
|
1903
1923
|
return _api;
|
|
1904
1924
|
}
|
|
1905
1925
|
/**
|
|
@@ -1911,7 +1931,7 @@ function api() {
|
|
|
1911
1931
|
*/
|
|
1912
1932
|
|
|
1913
1933
|
function widgets() {
|
|
1914
|
-
if (!_widgets)
|
|
1934
|
+
if (!_widgets) init({});
|
|
1915
1935
|
return _widgets;
|
|
1916
1936
|
}
|
|
1917
1937
|
/**
|
|
@@ -1923,7 +1943,7 @@ function widgets() {
|
|
|
1923
1943
|
*/
|
|
1924
1944
|
|
|
1925
1945
|
function events() {
|
|
1926
|
-
if (!_events)
|
|
1946
|
+
if (!_events) init({});
|
|
1927
1947
|
return _events;
|
|
1928
1948
|
}
|
|
1929
1949
|
/**
|
|
@@ -1995,7 +2015,7 @@ function init(configIn) {
|
|
|
1995
2015
|
* @example
|
|
1996
2016
|
* squatch.ready(function() {
|
|
1997
2017
|
* console.log("ready!");
|
|
1998
|
-
* squatch.api().upsertUser();
|
|
2018
|
+
* squatch.api().upsertUser({ ... });
|
|
1999
2019
|
* });
|
|
2000
2020
|
*/
|
|
2001
2021
|
|
|
@@ -2014,25 +2034,6 @@ function autofill(selector) {
|
|
|
2014
2034
|
// @ts-ignore -- will throw occasionally throw a null pointer exception at runtime
|
|
2015
2035
|
widgets().autofill(selector);
|
|
2016
2036
|
}
|
|
2017
|
-
/**
|
|
2018
|
-
* Overrides the default function that submits the user email. If you have
|
|
2019
|
-
* Security enabled, the email needs to be signed before it's submitted.
|
|
2020
|
-
*
|
|
2021
|
-
* @param {function} fn Callback function for the 'submit_email' event.
|
|
2022
|
-
* @returns {void}
|
|
2023
|
-
*
|
|
2024
|
-
* @example
|
|
2025
|
-
* squatch.submitEmail(function(target, widget, email) {
|
|
2026
|
-
* // Sign email and generate jwt token
|
|
2027
|
-
* var jwt = 'token';
|
|
2028
|
-
* widget.reload(email, jwt);
|
|
2029
|
-
* });
|
|
2030
|
-
*/
|
|
2031
|
-
|
|
2032
|
-
function submitEmail(fn) {
|
|
2033
|
-
// @ts-ignore -- will throw occasionally throw a null pointer exception at runtime
|
|
2034
|
-
widgets().submitEmail(fn);
|
|
2035
|
-
}
|
|
2036
2037
|
/**
|
|
2037
2038
|
* Manually set the _saasquatch cookie as a 1st party cookie if available as a URL parameter on the current page.
|
|
2038
2039
|
* This runs automatically immediately when squatch-js is loaded, except when window.SaaSquatchDoNotAutoDrop is true.
|
|
@@ -2071,7 +2072,6 @@ exports.help = help;
|
|
|
2071
2072
|
exports.init = init;
|
|
2072
2073
|
exports.pushCookie = pushCookie;
|
|
2073
2074
|
exports.ready = ready;
|
|
2074
|
-
exports.submitEmail = submitEmail;
|
|
2075
2075
|
exports.widget = widget;
|
|
2076
2076
|
exports.widgets = widgets;
|
|
2077
2077
|
//# sourceMappingURL=squatch.js.map
|