@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.js
CHANGED
|
@@ -238,6 +238,7 @@ class WidgetApi {
|
|
|
238
238
|
widgetType,
|
|
239
239
|
engagementMedium = "POPUP",
|
|
240
240
|
jwt,
|
|
241
|
+
locale,
|
|
241
242
|
user
|
|
242
243
|
} = clean;
|
|
243
244
|
var tenantAlias = encodeURIComponent(this.tenantAlias);
|
|
@@ -246,7 +247,8 @@ class WidgetApi {
|
|
|
246
247
|
|
|
247
248
|
var optionalParams = _buildParams({
|
|
248
249
|
widgetType,
|
|
249
|
-
engagementMedium
|
|
250
|
+
engagementMedium,
|
|
251
|
+
locale
|
|
250
252
|
});
|
|
251
253
|
|
|
252
254
|
var path = "/api/v1/" + tenantAlias + "/widget/account/" + accountId + "/user/" + userId + "/upsert" + optionalParams;
|
|
@@ -331,12 +333,15 @@ class WidgetApi {
|
|
|
331
333
|
function _buildParams(_ref) {
|
|
332
334
|
var {
|
|
333
335
|
widgetType,
|
|
334
|
-
engagementMedium
|
|
336
|
+
engagementMedium,
|
|
337
|
+
locale
|
|
335
338
|
} = _ref;
|
|
336
|
-
var
|
|
337
|
-
var
|
|
338
|
-
var
|
|
339
|
-
|
|
339
|
+
var engagementMediumP = "engagementMedium=" + encodeURIComponent(engagementMedium);
|
|
340
|
+
var widgetTypeP = widgetType && "widgetType=" + encodeURIComponent(widgetType);
|
|
341
|
+
var localeP = locale && "locale=" + encodeURIComponent(locale);
|
|
342
|
+
var params = [engagementMediumP, widgetTypeP, localeP].filter(x => !!x);
|
|
343
|
+
var queryString = "?" + params.join("&");
|
|
344
|
+
return queryString;
|
|
340
345
|
}
|
|
341
346
|
|
|
342
347
|
// @ts-check
|
|
@@ -788,7 +793,10 @@ class EmbedWidget extends Widget {
|
|
|
788
793
|
_log$6("loaded");
|
|
789
794
|
}
|
|
790
795
|
});
|
|
791
|
-
}
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Un-hide if element is available and refresh data
|
|
799
|
+
*/
|
|
792
800
|
|
|
793
801
|
|
|
794
802
|
open() {
|
|
@@ -1115,7 +1123,7 @@ class Widgets {
|
|
|
1115
1123
|
return {
|
|
1116
1124
|
widget: this._renderWidget(response, clean, {
|
|
1117
1125
|
type: "upsert",
|
|
1118
|
-
user: clean.user
|
|
1126
|
+
user: clean.user,
|
|
1119
1127
|
engagementMedium: config.engagementMedium,
|
|
1120
1128
|
container: config.container,
|
|
1121
1129
|
trigger: config.trigger
|
|
@@ -1247,9 +1255,9 @@ class Widgets {
|
|
|
1247
1255
|
if (opts.widgetUrlMappings) {
|
|
1248
1256
|
opts.widgetUrlMappings.forEach(rule => {
|
|
1249
1257
|
if (Widgets._matchesUrl(rule.url)) {
|
|
1250
|
-
var _response$user, _response$
|
|
1258
|
+
var _response$user, _response$user$referr;
|
|
1251
1259
|
|
|
1252
|
-
if (rule.widgetType !== "CONVERSION_WIDGET" || (_response$user = response.user) != null &&
|
|
1260
|
+
if (rule.widgetType !== "CONVERSION_WIDGET" || (_response$user = response.user) != null && (_response$user$referr = _response$user.referredBy) != null && _response$user$referr.code) {
|
|
1253
1261
|
displayOnLoad = rule.displayOnLoad;
|
|
1254
1262
|
|
|
1255
1263
|
_log$4("Display " + rule.widgetType + " on " + rule.url);
|
|
@@ -1270,15 +1278,17 @@ class Widgets {
|
|
|
1270
1278
|
} = _ref;
|
|
1271
1279
|
|
|
1272
1280
|
if (Widgets._matchesUrl(url)) {
|
|
1273
|
-
var _response$
|
|
1281
|
+
var _response$user2, _response$user2$refer;
|
|
1274
1282
|
|
|
1275
1283
|
_log$4("Fuel Tank URL matches");
|
|
1276
1284
|
|
|
1277
|
-
if ((_response$
|
|
1285
|
+
if ((_response$user2 = response.user) != null && (_response$user2$refer = _response$user2.referredBy) != null && _response$user2$refer.code) {
|
|
1278
1286
|
var formAutofill = document.querySelector(formSelector);
|
|
1279
1287
|
|
|
1280
1288
|
if (formAutofill) {
|
|
1281
|
-
|
|
1289
|
+
var _response$user$referr2;
|
|
1290
|
+
|
|
1291
|
+
formAutofill.value = ((_response$user$referr2 = response.user.referredBy.referredReward) == null ? void 0 : _response$user$referr2.fuelTankCode) || "";
|
|
1282
1292
|
} else {
|
|
1283
1293
|
_log$4(new Error("Element with id/class " + formSelector + " was not found."));
|
|
1284
1294
|
}
|
|
@@ -1310,7 +1320,7 @@ class Widgets {
|
|
|
1310
1320
|
}
|
|
1311
1321
|
|
|
1312
1322
|
_renderEmbedWidget(params, container) {
|
|
1313
|
-
var widget = new EmbedWidget(params);
|
|
1323
|
+
var widget = new EmbedWidget(params, container);
|
|
1314
1324
|
widget.load();
|
|
1315
1325
|
return widget;
|
|
1316
1326
|
}
|
|
@@ -1365,6 +1375,9 @@ class Widgets {
|
|
|
1365
1375
|
|
|
1366
1376
|
static _matchesUrl(rule) {
|
|
1367
1377
|
// If there were no matches, null is returned.
|
|
1378
|
+
console.log({
|
|
1379
|
+
href: window.location.href
|
|
1380
|
+
});
|
|
1368
1381
|
return window.location.href.match(new RegExp(rule)) ? true : false;
|
|
1369
1382
|
}
|
|
1370
1383
|
|
|
@@ -1667,13 +1680,13 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1667
1680
|
this.token = void 0;
|
|
1668
1681
|
this.tenant = void 0;
|
|
1669
1682
|
this.widgetType = void 0;
|
|
1683
|
+
this.locale = void 0;
|
|
1670
1684
|
this.widgetApi = void 0;
|
|
1671
1685
|
this.analyticsApi = void 0;
|
|
1672
1686
|
this.type = void 0;
|
|
1673
1687
|
this.widgetInstance = void 0;
|
|
1674
1688
|
this.container = void 0;
|
|
1675
1689
|
this.element = void 0;
|
|
1676
|
-
this._hasChildren = void 0;
|
|
1677
1690
|
|
|
1678
1691
|
this._setWidget = (template, config) => {
|
|
1679
1692
|
var _this$config;
|
|
@@ -1720,6 +1733,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1720
1733
|
}
|
|
1721
1734
|
};
|
|
1722
1735
|
|
|
1736
|
+
this.reload = this.renderWidget;
|
|
1723
1737
|
this.show = this.open;
|
|
1724
1738
|
this.hide = this.close;
|
|
1725
1739
|
this.attachShadow({
|
|
@@ -1729,6 +1743,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1729
1743
|
this.token = window.squatchToken;
|
|
1730
1744
|
this.tenant = window.squatchTenant;
|
|
1731
1745
|
this.container = this;
|
|
1746
|
+
this.locale = validateLocale(navigator.language.replace(/\-/g, "_"));
|
|
1732
1747
|
}
|
|
1733
1748
|
|
|
1734
1749
|
_setupApis(config) {
|
|
@@ -1745,7 +1760,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1745
1760
|
}
|
|
1746
1761
|
|
|
1747
1762
|
async renderPasswordlessVariant() {
|
|
1748
|
-
var _configs$widgetConfig, _configs$widgetConfig2;
|
|
1763
|
+
var _configs$widgetConfig, _configs$widgetConfig2, _configs$widgetConfig3;
|
|
1749
1764
|
|
|
1750
1765
|
var configs = _getAutoConfig();
|
|
1751
1766
|
|
|
@@ -1753,7 +1768,8 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1753
1768
|
|
|
1754
1769
|
return await this.widgetApi.render({
|
|
1755
1770
|
engagementMedium: (configs == null ? void 0 : (_configs$widgetConfig = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig.engagementMedium) || this.type,
|
|
1756
|
-
widgetType: (configs == null ? void 0 : (_configs$widgetConfig2 = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig2.widgetType) || this.widgetType
|
|
1771
|
+
widgetType: (configs == null ? void 0 : (_configs$widgetConfig2 = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig2.widgetType) || this.widgetType,
|
|
1772
|
+
locale: (configs == null ? void 0 : (_configs$widgetConfig3 = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig3.locale) || this.locale
|
|
1757
1773
|
}).then(res => this._setWidget(res.template, {
|
|
1758
1774
|
type: "passwordless"
|
|
1759
1775
|
})).catch(this.setErrorWidget);
|
|
@@ -1766,6 +1782,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1766
1782
|
if (!userObj) throw new Error("Could not load user information from jwt");
|
|
1767
1783
|
var widgetInstance = await this.widgetApi.upsertUser({
|
|
1768
1784
|
user: userObj,
|
|
1785
|
+
locale: this.locale,
|
|
1769
1786
|
engagementMedium: this.type,
|
|
1770
1787
|
widgetType: this.widgetType,
|
|
1771
1788
|
jwt: this.token
|
|
@@ -1778,6 +1795,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1778
1795
|
async getWidgetInstance() {
|
|
1779
1796
|
var widgetInstance;
|
|
1780
1797
|
this.widgetType = this.getAttribute("widget") || undefined;
|
|
1798
|
+
this.locale = this.getAttribute("locale") || this.locale;
|
|
1781
1799
|
if (!this.widgetType) throw new Error("No widget has been specified");
|
|
1782
1800
|
|
|
1783
1801
|
if (!this.token) {
|
|
@@ -1796,11 +1814,22 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1796
1814
|
await this.widgetInstance.load();
|
|
1797
1815
|
}
|
|
1798
1816
|
|
|
1817
|
+
/**
|
|
1818
|
+
* Calls `open` method of `widgetInstance`
|
|
1819
|
+
* @throws Throws an Error if called before the widget has loaded
|
|
1820
|
+
*/
|
|
1799
1821
|
open() {
|
|
1822
|
+
if (!this.widgetInstance) throw new Error("Widget has not loaded yet");
|
|
1800
1823
|
this.widgetInstance.open();
|
|
1801
1824
|
}
|
|
1825
|
+
/**
|
|
1826
|
+
* Calls `close` method of `widgetInstance`
|
|
1827
|
+
* @throws Throws an Error if called before the widget has loaded
|
|
1828
|
+
*/
|
|
1829
|
+
|
|
1802
1830
|
|
|
1803
1831
|
close() {
|
|
1832
|
+
if (!this.widgetInstance) throw new Error("Widget has not loaded yet");
|
|
1804
1833
|
this.widgetInstance.close();
|
|
1805
1834
|
}
|
|
1806
1835
|
|
|
@@ -1813,22 +1842,17 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1813
1842
|
}
|
|
1814
1843
|
|
|
1815
1844
|
static get observedAttributes() {
|
|
1816
|
-
return ["widget", "
|
|
1845
|
+
return ["widget", "locale"];
|
|
1817
1846
|
}
|
|
1818
1847
|
|
|
1819
1848
|
attributeChangedCallback(attr, oldVal, newVal) {
|
|
1820
1849
|
if (oldVal === newVal || !oldVal) return; // nothing to do
|
|
1821
1850
|
|
|
1822
1851
|
switch (attr) {
|
|
1852
|
+
case "locale":
|
|
1823
1853
|
case "widget":
|
|
1824
1854
|
this.connectedCallback();
|
|
1825
1855
|
break;
|
|
1826
|
-
// Specific to embed widgets
|
|
1827
|
-
|
|
1828
|
-
case "container":
|
|
1829
|
-
if (this.widgetInstance._findElement()) this.close();
|
|
1830
|
-
this.connectedCallback();
|
|
1831
|
-
break;
|
|
1832
1856
|
}
|
|
1833
1857
|
}
|
|
1834
1858
|
|
|
@@ -1854,14 +1878,14 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
1854
1878
|
}
|
|
1855
1879
|
|
|
1856
1880
|
static get observedAttributes() {
|
|
1857
|
-
return ["widget", "
|
|
1881
|
+
return ["widget", "locale"];
|
|
1858
1882
|
}
|
|
1859
1883
|
|
|
1860
1884
|
attributeChangedCallback(attr, oldVal, newVal) {
|
|
1861
1885
|
if (oldVal === newVal || !oldVal) return; // nothing to do
|
|
1862
1886
|
|
|
1863
1887
|
switch (attr) {
|
|
1864
|
-
case "
|
|
1888
|
+
case "locale":
|
|
1865
1889
|
case "widget":
|
|
1866
1890
|
this.connectedCallback();
|
|
1867
1891
|
break;
|
|
@@ -1906,7 +1930,7 @@ var _events = null;
|
|
|
1906
1930
|
*/
|
|
1907
1931
|
|
|
1908
1932
|
function api() {
|
|
1909
|
-
if (!_api)
|
|
1933
|
+
if (!_api) init({});
|
|
1910
1934
|
return _api;
|
|
1911
1935
|
}
|
|
1912
1936
|
/**
|
|
@@ -1918,7 +1942,7 @@ function api() {
|
|
|
1918
1942
|
*/
|
|
1919
1943
|
|
|
1920
1944
|
function widgets() {
|
|
1921
|
-
if (!_widgets)
|
|
1945
|
+
if (!_widgets) init({});
|
|
1922
1946
|
return _widgets;
|
|
1923
1947
|
}
|
|
1924
1948
|
/**
|
|
@@ -1930,7 +1954,7 @@ function widgets() {
|
|
|
1930
1954
|
*/
|
|
1931
1955
|
|
|
1932
1956
|
function events() {
|
|
1933
|
-
if (!_events)
|
|
1957
|
+
if (!_events) init({});
|
|
1934
1958
|
return _events;
|
|
1935
1959
|
}
|
|
1936
1960
|
/**
|
|
@@ -2002,7 +2026,7 @@ function init(configIn) {
|
|
|
2002
2026
|
* @example
|
|
2003
2027
|
* squatch.ready(function() {
|
|
2004
2028
|
* console.log("ready!");
|
|
2005
|
-
* squatch.api().upsertUser();
|
|
2029
|
+
* squatch.api().upsertUser({ ... });
|
|
2006
2030
|
* });
|
|
2007
2031
|
*/
|
|
2008
2032
|
|