@saasquatch/squatch-js 2.6.0-2 → 2.6.0-4
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/static.yml +89 -0
- package/coverage/clover.xml +64 -3
- package/coverage/coverage-final.json +2 -1
- package/coverage/lcov-report/DeclarativeWidget.ts.html +610 -0
- package/coverage/lcov-report/WidgetApi.ts.html +85 -85
- package/coverage/lcov-report/Widgets.ts.html +1057 -0
- package/coverage/lcov-report/api/AnalyticsApi.ts.html +46 -46
- package/coverage/lcov-report/api/WidgetApi.ts.html +11 -11
- 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 +85 -88
- package/coverage/lcov.info +133 -0
- package/dist/squatch.d.ts +1 -1
- package/dist/squatch.esm.js +54 -30
- package/dist/squatch.esm.js.map +1 -1
- package/dist/squatch.js +54 -30
- package/dist/squatch.js.map +1 -1
- package/dist/squatch.min.js +1 -1
- package/dist/widgets/EmbedWidget.d.ts +3 -0
- package/dist/widgets/declarative/DeclarativeWidget.d.ts +10 -1
- package/package.json +2 -2
package/dist/squatch.esm.js
CHANGED
|
@@ -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;
|
|
@@ -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
|
|
332
|
-
var
|
|
333
|
-
var
|
|
334
|
-
|
|
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
|
|
@@ -783,7 +788,10 @@ class EmbedWidget extends Widget {
|
|
|
783
788
|
_log$6("loaded");
|
|
784
789
|
}
|
|
785
790
|
});
|
|
786
|
-
}
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Un-hide if element is available and refresh data
|
|
794
|
+
*/
|
|
787
795
|
|
|
788
796
|
|
|
789
797
|
open() {
|
|
@@ -1110,7 +1118,7 @@ class Widgets {
|
|
|
1110
1118
|
return {
|
|
1111
1119
|
widget: this._renderWidget(response, clean, {
|
|
1112
1120
|
type: "upsert",
|
|
1113
|
-
user: clean.user
|
|
1121
|
+
user: clean.user,
|
|
1114
1122
|
engagementMedium: config.engagementMedium,
|
|
1115
1123
|
container: config.container,
|
|
1116
1124
|
trigger: config.trigger
|
|
@@ -1242,9 +1250,9 @@ class Widgets {
|
|
|
1242
1250
|
if (opts.widgetUrlMappings) {
|
|
1243
1251
|
opts.widgetUrlMappings.forEach(rule => {
|
|
1244
1252
|
if (Widgets._matchesUrl(rule.url)) {
|
|
1245
|
-
var _response$user, _response$
|
|
1253
|
+
var _response$user, _response$user$referr;
|
|
1246
1254
|
|
|
1247
|
-
if (rule.widgetType !== "CONVERSION_WIDGET" || (_response$user = response.user) != null &&
|
|
1255
|
+
if (rule.widgetType !== "CONVERSION_WIDGET" || (_response$user = response.user) != null && (_response$user$referr = _response$user.referredBy) != null && _response$user$referr.code) {
|
|
1248
1256
|
displayOnLoad = rule.displayOnLoad;
|
|
1249
1257
|
|
|
1250
1258
|
_log$4("Display " + rule.widgetType + " on " + rule.url);
|
|
@@ -1265,15 +1273,17 @@ class Widgets {
|
|
|
1265
1273
|
} = _ref;
|
|
1266
1274
|
|
|
1267
1275
|
if (Widgets._matchesUrl(url)) {
|
|
1268
|
-
var _response$
|
|
1276
|
+
var _response$user2, _response$user2$refer;
|
|
1269
1277
|
|
|
1270
1278
|
_log$4("Fuel Tank URL matches");
|
|
1271
1279
|
|
|
1272
|
-
if ((_response$
|
|
1280
|
+
if ((_response$user2 = response.user) != null && (_response$user2$refer = _response$user2.referredBy) != null && _response$user2$refer.code) {
|
|
1273
1281
|
var formAutofill = document.querySelector(formSelector);
|
|
1274
1282
|
|
|
1275
1283
|
if (formAutofill) {
|
|
1276
|
-
|
|
1284
|
+
var _response$user$referr2;
|
|
1285
|
+
|
|
1286
|
+
formAutofill.value = ((_response$user$referr2 = response.user.referredBy.referredReward) == null ? void 0 : _response$user$referr2.fuelTankCode) || "";
|
|
1277
1287
|
} else {
|
|
1278
1288
|
_log$4(new Error("Element with id/class " + formSelector + " was not found."));
|
|
1279
1289
|
}
|
|
@@ -1305,7 +1315,7 @@ class Widgets {
|
|
|
1305
1315
|
}
|
|
1306
1316
|
|
|
1307
1317
|
_renderEmbedWidget(params, container) {
|
|
1308
|
-
var widget = new EmbedWidget(params);
|
|
1318
|
+
var widget = new EmbedWidget(params, container);
|
|
1309
1319
|
widget.load();
|
|
1310
1320
|
return widget;
|
|
1311
1321
|
}
|
|
@@ -1360,6 +1370,9 @@ class Widgets {
|
|
|
1360
1370
|
|
|
1361
1371
|
static _matchesUrl(rule) {
|
|
1362
1372
|
// If there were no matches, null is returned.
|
|
1373
|
+
console.log({
|
|
1374
|
+
href: window.location.href
|
|
1375
|
+
});
|
|
1363
1376
|
return window.location.href.match(new RegExp(rule)) ? true : false;
|
|
1364
1377
|
}
|
|
1365
1378
|
|
|
@@ -1662,13 +1675,13 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1662
1675
|
this.token = void 0;
|
|
1663
1676
|
this.tenant = void 0;
|
|
1664
1677
|
this.widgetType = void 0;
|
|
1678
|
+
this.locale = void 0;
|
|
1665
1679
|
this.widgetApi = void 0;
|
|
1666
1680
|
this.analyticsApi = void 0;
|
|
1667
1681
|
this.type = void 0;
|
|
1668
1682
|
this.widgetInstance = void 0;
|
|
1669
1683
|
this.container = void 0;
|
|
1670
1684
|
this.element = void 0;
|
|
1671
|
-
this._hasChildren = void 0;
|
|
1672
1685
|
|
|
1673
1686
|
this._setWidget = (template, config) => {
|
|
1674
1687
|
var _this$config;
|
|
@@ -1715,6 +1728,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1715
1728
|
}
|
|
1716
1729
|
};
|
|
1717
1730
|
|
|
1731
|
+
this.reload = this.renderWidget;
|
|
1718
1732
|
this.show = this.open;
|
|
1719
1733
|
this.hide = this.close;
|
|
1720
1734
|
this.attachShadow({
|
|
@@ -1724,6 +1738,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1724
1738
|
this.token = window.squatchToken;
|
|
1725
1739
|
this.tenant = window.squatchTenant;
|
|
1726
1740
|
this.container = this;
|
|
1741
|
+
this.locale = validateLocale(navigator.language.replace(/\-/g, "_"));
|
|
1727
1742
|
}
|
|
1728
1743
|
|
|
1729
1744
|
_setupApis(config) {
|
|
@@ -1740,7 +1755,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1740
1755
|
}
|
|
1741
1756
|
|
|
1742
1757
|
async renderPasswordlessVariant() {
|
|
1743
|
-
var _configs$widgetConfig, _configs$widgetConfig2;
|
|
1758
|
+
var _configs$widgetConfig, _configs$widgetConfig2, _configs$widgetConfig3;
|
|
1744
1759
|
|
|
1745
1760
|
var configs = _getAutoConfig();
|
|
1746
1761
|
|
|
@@ -1748,7 +1763,8 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1748
1763
|
|
|
1749
1764
|
return await this.widgetApi.render({
|
|
1750
1765
|
engagementMedium: (configs == null ? void 0 : (_configs$widgetConfig = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig.engagementMedium) || this.type,
|
|
1751
|
-
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
|
|
1752
1768
|
}).then(res => this._setWidget(res.template, {
|
|
1753
1769
|
type: "passwordless"
|
|
1754
1770
|
})).catch(this.setErrorWidget);
|
|
@@ -1761,6 +1777,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1761
1777
|
if (!userObj) throw new Error("Could not load user information from jwt");
|
|
1762
1778
|
var widgetInstance = await this.widgetApi.upsertUser({
|
|
1763
1779
|
user: userObj,
|
|
1780
|
+
locale: this.locale,
|
|
1764
1781
|
engagementMedium: this.type,
|
|
1765
1782
|
widgetType: this.widgetType,
|
|
1766
1783
|
jwt: this.token
|
|
@@ -1773,6 +1790,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1773
1790
|
async getWidgetInstance() {
|
|
1774
1791
|
var widgetInstance;
|
|
1775
1792
|
this.widgetType = this.getAttribute("widget") || undefined;
|
|
1793
|
+
this.locale = this.getAttribute("locale") || this.locale;
|
|
1776
1794
|
if (!this.widgetType) throw new Error("No widget has been specified");
|
|
1777
1795
|
|
|
1778
1796
|
if (!this.token) {
|
|
@@ -1791,11 +1809,22 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1791
1809
|
await this.widgetInstance.load();
|
|
1792
1810
|
}
|
|
1793
1811
|
|
|
1812
|
+
/**
|
|
1813
|
+
* Calls `open` method of `widgetInstance`
|
|
1814
|
+
* @throws Throws an Error if called before the widget has loaded
|
|
1815
|
+
*/
|
|
1794
1816
|
open() {
|
|
1817
|
+
if (!this.widgetInstance) throw new Error("Widget has not loaded yet");
|
|
1795
1818
|
this.widgetInstance.open();
|
|
1796
1819
|
}
|
|
1820
|
+
/**
|
|
1821
|
+
* Calls `close` method of `widgetInstance`
|
|
1822
|
+
* @throws Throws an Error if called before the widget has loaded
|
|
1823
|
+
*/
|
|
1824
|
+
|
|
1797
1825
|
|
|
1798
1826
|
close() {
|
|
1827
|
+
if (!this.widgetInstance) throw new Error("Widget has not loaded yet");
|
|
1799
1828
|
this.widgetInstance.close();
|
|
1800
1829
|
}
|
|
1801
1830
|
|
|
@@ -1808,22 +1837,17 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1808
1837
|
}
|
|
1809
1838
|
|
|
1810
1839
|
static get observedAttributes() {
|
|
1811
|
-
return ["widget", "
|
|
1840
|
+
return ["widget", "locale"];
|
|
1812
1841
|
}
|
|
1813
1842
|
|
|
1814
1843
|
attributeChangedCallback(attr, oldVal, newVal) {
|
|
1815
1844
|
if (oldVal === newVal || !oldVal) return; // nothing to do
|
|
1816
1845
|
|
|
1817
1846
|
switch (attr) {
|
|
1847
|
+
case "locale":
|
|
1818
1848
|
case "widget":
|
|
1819
1849
|
this.connectedCallback();
|
|
1820
1850
|
break;
|
|
1821
|
-
// Specific to embed widgets
|
|
1822
|
-
|
|
1823
|
-
case "container":
|
|
1824
|
-
if (this.widgetInstance._findElement()) this.close();
|
|
1825
|
-
this.connectedCallback();
|
|
1826
|
-
break;
|
|
1827
1851
|
}
|
|
1828
1852
|
}
|
|
1829
1853
|
|
|
@@ -1849,14 +1873,14 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
1849
1873
|
}
|
|
1850
1874
|
|
|
1851
1875
|
static get observedAttributes() {
|
|
1852
|
-
return ["widget", "
|
|
1876
|
+
return ["widget", "locale"];
|
|
1853
1877
|
}
|
|
1854
1878
|
|
|
1855
1879
|
attributeChangedCallback(attr, oldVal, newVal) {
|
|
1856
1880
|
if (oldVal === newVal || !oldVal) return; // nothing to do
|
|
1857
1881
|
|
|
1858
1882
|
switch (attr) {
|
|
1859
|
-
case "
|
|
1883
|
+
case "locale":
|
|
1860
1884
|
case "widget":
|
|
1861
1885
|
this.connectedCallback();
|
|
1862
1886
|
break;
|
|
@@ -1901,7 +1925,7 @@ var _events = null;
|
|
|
1901
1925
|
*/
|
|
1902
1926
|
|
|
1903
1927
|
function api() {
|
|
1904
|
-
if (!_api)
|
|
1928
|
+
if (!_api) init({});
|
|
1905
1929
|
return _api;
|
|
1906
1930
|
}
|
|
1907
1931
|
/**
|
|
@@ -1913,7 +1937,7 @@ function api() {
|
|
|
1913
1937
|
*/
|
|
1914
1938
|
|
|
1915
1939
|
function widgets() {
|
|
1916
|
-
if (!_widgets)
|
|
1940
|
+
if (!_widgets) init({});
|
|
1917
1941
|
return _widgets;
|
|
1918
1942
|
}
|
|
1919
1943
|
/**
|
|
@@ -1925,7 +1949,7 @@ function widgets() {
|
|
|
1925
1949
|
*/
|
|
1926
1950
|
|
|
1927
1951
|
function events() {
|
|
1928
|
-
if (!_events)
|
|
1952
|
+
if (!_events) init({});
|
|
1929
1953
|
return _events;
|
|
1930
1954
|
}
|
|
1931
1955
|
/**
|
|
@@ -1997,7 +2021,7 @@ function init(configIn) {
|
|
|
1997
2021
|
* @example
|
|
1998
2022
|
* squatch.ready(function() {
|
|
1999
2023
|
* console.log("ready!");
|
|
2000
|
-
* squatch.api().upsertUser();
|
|
2024
|
+
* squatch.api().upsertUser({ ... });
|
|
2001
2025
|
* });
|
|
2002
2026
|
*/
|
|
2003
2027
|
|