@saasquatch/squatch-js 2.6.0-5 → 2.6.0-6
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 +244 -238
- package/coverage/coverage-final.json +9 -9
- package/coverage/lcov-report/api/AnalyticsApi.ts.html +6 -6
- package/coverage/lcov-report/api/WidgetApi.ts.html +43 -43
- package/coverage/lcov-report/api/graphql.ts.html +1 -1
- package/coverage/lcov-report/utils/cookieUtils.ts.html +10 -10
- package/coverage/lcov-report/utils/decodeUserJwt.ts.html +19 -19
- package/coverage/lcov-report/utils/domready.ts.html +1 -1
- package/coverage/lcov-report/utils/io.ts.html +7 -7
- package/coverage/lcov-report/utils/utmUtils.ts.html +22 -22
- package/coverage/lcov-report/utils/validate.ts.html +21 -21
- package/coverage/lcov-report/widgets/EmbedWidget.ts.html +45 -18
- package/coverage/lcov-report/widgets/PopupWidget.ts.html +7 -7
- package/coverage/lcov-report/widgets/Widget.ts.html +7 -16
- package/coverage/lcov-report/widgets/declarative/DeclarativeWidget.ts.html +81 -84
- package/coverage/lcov.info +412 -406
- package/dist/squatch.esm.js +100 -94
- package/dist/squatch.esm.js.map +1 -1
- package/dist/squatch.js +100 -94
- package/dist/squatch.js.map +1 -1
- package/dist/squatch.min.js +1 -1
- package/dist/types.d.ts +8 -6
- package/dist/widgets/EmbedWidget.d.ts +1 -0
- package/package.json +1 -1
package/dist/squatch.js
CHANGED
|
@@ -405,7 +405,7 @@ function _validateAnalyticsConfig(raw) {
|
|
|
405
405
|
// @ts-check
|
|
406
406
|
/** @hidden */
|
|
407
407
|
|
|
408
|
-
var _log$
|
|
408
|
+
var _log$8 = debug.debug("squatch-js:widget");
|
|
409
409
|
/*
|
|
410
410
|
* The Widget class is the base class for the different widget types available
|
|
411
411
|
*
|
|
@@ -426,7 +426,7 @@ class Widget {
|
|
|
426
426
|
this.npmCdn = void 0;
|
|
427
427
|
this.container = void 0;
|
|
428
428
|
|
|
429
|
-
_log$
|
|
429
|
+
_log$8("widget initializing ...");
|
|
430
430
|
|
|
431
431
|
this.content = params.content === "error" ? this._error(params.rsCode) : params.content;
|
|
432
432
|
this.type = params.type;
|
|
@@ -436,7 +436,7 @@ class Widget {
|
|
|
436
436
|
domain: params.domain
|
|
437
437
|
});
|
|
438
438
|
this.context = params.context;
|
|
439
|
-
this.container = params.container;
|
|
439
|
+
this.container = params.context.container;
|
|
440
440
|
}
|
|
441
441
|
|
|
442
442
|
_findElement() {
|
|
@@ -446,22 +446,22 @@ class Widget {
|
|
|
446
446
|
// selector is a string
|
|
447
447
|
element = document.querySelector(this.container);
|
|
448
448
|
|
|
449
|
-
_log$
|
|
449
|
+
_log$8("loading widget with selector", element); // selector is an HTML element
|
|
450
450
|
|
|
451
451
|
} else if (this.container instanceof HTMLElement) {
|
|
452
452
|
element = this.container;
|
|
453
453
|
|
|
454
|
-
_log$
|
|
454
|
+
_log$8("loading widget with container", element); // garbage container found
|
|
455
455
|
|
|
456
456
|
} else if (this.container) {
|
|
457
457
|
element = null;
|
|
458
458
|
|
|
459
|
-
_log$
|
|
459
|
+
_log$8("container must be an HTMLElement or string", this.container); // find element on page
|
|
460
460
|
|
|
461
461
|
} else {
|
|
462
462
|
element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed");
|
|
463
463
|
|
|
464
|
-
_log$
|
|
464
|
+
_log$8("loading widget with default selector", element);
|
|
465
465
|
}
|
|
466
466
|
|
|
467
467
|
if (!(element instanceof HTMLElement)) throw new Error("element with selector '" + (this.container || "#squatchembed or .squatchembed") + "' not found.'");
|
|
@@ -519,9 +519,9 @@ class Widget {
|
|
|
519
519
|
}
|
|
520
520
|
|
|
521
521
|
(_this$analyticsApi$pu = this.analyticsApi.pushAnalyticsLoadEvent(params)) == null ? void 0 : _this$analyticsApi$pu.then(response => {
|
|
522
|
-
_log$
|
|
522
|
+
_log$8(params.engagementMedium + " loaded event recorded.");
|
|
523
523
|
}).catch(ex => {
|
|
524
|
-
_log$
|
|
524
|
+
_log$8("ERROR: pushAnalyticsLoadEvent() " + ex);
|
|
525
525
|
});
|
|
526
526
|
}
|
|
527
527
|
|
|
@@ -534,9 +534,9 @@ class Widget {
|
|
|
534
534
|
engagementMedium: sqh.mode.widgetMode,
|
|
535
535
|
shareMedium: medium
|
|
536
536
|
}).then(response => {
|
|
537
|
-
_log$
|
|
537
|
+
_log$8(sqh.mode.widgetMode + " share " + medium + " event recorded. " + response);
|
|
538
538
|
}).catch(ex => {
|
|
539
|
-
_log$
|
|
539
|
+
_log$8("ERROR: pushAnalyticsShareClickedEvent() " + ex);
|
|
540
540
|
});
|
|
541
541
|
}
|
|
542
542
|
} // TODO: CA: Refactor how error templates are shown
|
|
@@ -658,7 +658,7 @@ class Widget {
|
|
|
658
658
|
message
|
|
659
659
|
} = _ref3;
|
|
660
660
|
|
|
661
|
-
_log$
|
|
661
|
+
_log$8("" + message);
|
|
662
662
|
});
|
|
663
663
|
}
|
|
664
664
|
|
|
@@ -715,7 +715,7 @@ function domready(targetDoc, fn) {
|
|
|
715
715
|
|
|
716
716
|
// @ts-check
|
|
717
717
|
|
|
718
|
-
var _log$
|
|
718
|
+
var _log$7 = debug.debug("squatch-js:EMBEDwidget");
|
|
719
719
|
/**
|
|
720
720
|
* An EmbedWidget is displayed inline in part of your page.
|
|
721
721
|
*
|
|
@@ -734,6 +734,7 @@ class EmbedWidget extends Widget {
|
|
|
734
734
|
super(params);
|
|
735
735
|
this.show = this.open;
|
|
736
736
|
this.hide = this.close;
|
|
737
|
+
if (container) this.container = container;
|
|
737
738
|
}
|
|
738
739
|
|
|
739
740
|
async load() {
|
|
@@ -789,12 +790,12 @@ class EmbedWidget extends Widget {
|
|
|
789
790
|
}
|
|
790
791
|
});
|
|
791
792
|
var container = await this._findInnerContainer(frame);
|
|
792
|
-
ro.observe(container);
|
|
793
|
+
ro.observe(container);
|
|
793
794
|
|
|
794
|
-
if (
|
|
795
|
+
if (this._shouldFireLoadEvent()) {
|
|
795
796
|
this._loadEvent(_sqh);
|
|
796
797
|
|
|
797
|
-
_log$
|
|
798
|
+
_log$7("loaded");
|
|
798
799
|
}
|
|
799
800
|
});
|
|
800
801
|
}
|
|
@@ -808,7 +809,7 @@ class EmbedWidget extends Widget {
|
|
|
808
809
|
|
|
809
810
|
var frame = this._findFrame();
|
|
810
811
|
|
|
811
|
-
if (!frame) return _log$
|
|
812
|
+
if (!frame) return _log$7("no target element to open");
|
|
812
813
|
|
|
813
814
|
var element = this._findElement();
|
|
814
815
|
|
|
@@ -819,15 +820,17 @@ class EmbedWidget extends Widget {
|
|
|
819
820
|
|
|
820
821
|
var _sqh = (frame == null ? void 0 : (_frame$contentWindow = frame.contentWindow) == null ? void 0 : _frame$contentWindow.squatch) || (frame == null ? void 0 : (_frame$contentWindow2 = frame.contentWindow) == null ? void 0 : _frame$contentWindow2.widgetIdent);
|
|
821
822
|
|
|
822
|
-
this.
|
|
823
|
+
if (this.context.user) {
|
|
824
|
+
this._loadEvent(_sqh);
|
|
823
825
|
|
|
824
|
-
|
|
826
|
+
_log$7("loaded");
|
|
827
|
+
}
|
|
825
828
|
}
|
|
826
829
|
|
|
827
830
|
close() {
|
|
828
831
|
var frame = this._findFrame();
|
|
829
832
|
|
|
830
|
-
if (!frame) return _log$
|
|
833
|
+
if (!frame) return _log$7("no target element to close");
|
|
831
834
|
|
|
832
835
|
var element = this._findElement();
|
|
833
836
|
|
|
@@ -835,7 +838,7 @@ class EmbedWidget extends Widget {
|
|
|
835
838
|
element.style.height = "0";
|
|
836
839
|
element.style["overflow-y"] = "hidden";
|
|
837
840
|
|
|
838
|
-
_log$
|
|
841
|
+
_log$7("Embed widget closed");
|
|
839
842
|
}
|
|
840
843
|
|
|
841
844
|
_error(rs, mode, style) {
|
|
@@ -850,11 +853,18 @@ class EmbedWidget extends Widget {
|
|
|
850
853
|
return super._error(rs, mode, style);
|
|
851
854
|
}
|
|
852
855
|
|
|
856
|
+
_shouldFireLoadEvent() {
|
|
857
|
+
var noContainer = !this.container;
|
|
858
|
+
var isComponent = this.container instanceof HTMLElement && this.container.tagName.startsWith("SQUATCH-");
|
|
859
|
+
var isVerified = !!this.context.user;
|
|
860
|
+
return isVerified && (noContainer || isComponent);
|
|
861
|
+
}
|
|
862
|
+
|
|
853
863
|
}
|
|
854
864
|
|
|
855
865
|
// @ts-check
|
|
856
866
|
|
|
857
|
-
var _log$
|
|
867
|
+
var _log$6 = debug.debug("squatch-js:POPUPwidget");
|
|
858
868
|
|
|
859
869
|
var popupId = 0;
|
|
860
870
|
/**
|
|
@@ -901,9 +911,9 @@ class PopupWidget extends Widget {
|
|
|
901
911
|
triggerElement
|
|
902
912
|
/* HTMLButton */
|
|
903
913
|
= document.querySelector(this.trigger);
|
|
904
|
-
if (this.trigger && !triggerElement) _log$
|
|
914
|
+
if (this.trigger && !triggerElement) _log$6("No element found with trigger selector", this.trigger);
|
|
905
915
|
} catch (_unused) {
|
|
906
|
-
_log$
|
|
916
|
+
_log$6("Not a valid selector", this.trigger);
|
|
907
917
|
} // Trigger is optional
|
|
908
918
|
|
|
909
919
|
|
|
@@ -911,16 +921,7 @@ class PopupWidget extends Widget {
|
|
|
911
921
|
triggerElement.onclick = () => {
|
|
912
922
|
this.open();
|
|
913
923
|
};
|
|
914
|
-
}
|
|
915
|
-
// If widget is loaded with CTA, look for a 'squatchpop' element to use
|
|
916
|
-
// that element as a trigger as well.
|
|
917
|
-
// const triggerWhenCTA = element.querySelector(".squatchpop") as HTMLElement;
|
|
918
|
-
// if (this.trigger === "#cta" && triggerWhenCTA) {
|
|
919
|
-
// triggerWhenCTA.onclick = () => {
|
|
920
|
-
// this.open(frame);
|
|
921
|
-
// };
|
|
922
|
-
// }
|
|
923
|
-
|
|
924
|
+
}
|
|
924
925
|
}
|
|
925
926
|
|
|
926
927
|
_createPopupDialog() {
|
|
@@ -929,6 +930,7 @@ class PopupWidget extends Widget {
|
|
|
929
930
|
dialog.setAttribute("style", "width: 100%; max-width: 500px; border: none; padding: 0;");
|
|
930
931
|
|
|
931
932
|
var onClick = e => {
|
|
933
|
+
e.stopPropagation();
|
|
932
934
|
if (e.target === dialog) dialog.close();
|
|
933
935
|
};
|
|
934
936
|
|
|
@@ -972,7 +974,7 @@ class PopupWidget extends Widget {
|
|
|
972
974
|
frameDoc.write("<script src=\"" + this.npmCdn + "/resize-observer-polyfill@1.5.x\"></script>");
|
|
973
975
|
frameDoc.close();
|
|
974
976
|
|
|
975
|
-
_log$
|
|
977
|
+
_log$6("Popup template loaded into iframe");
|
|
976
978
|
|
|
977
979
|
this._setupResizeHandler(frame);
|
|
978
980
|
}
|
|
@@ -1031,9 +1033,11 @@ class PopupWidget extends Widget {
|
|
|
1031
1033
|
|
|
1032
1034
|
(_frame$contentDocumen = frame.contentDocument) == null ? void 0 : _frame$contentDocumen.dispatchEvent(new CustomEvent("sq:refresh"));
|
|
1033
1035
|
|
|
1034
|
-
this.
|
|
1036
|
+
if (this.context.user) {
|
|
1037
|
+
this._loadEvent(_sqh);
|
|
1035
1038
|
|
|
1036
|
-
|
|
1039
|
+
_log$6("Popup opened");
|
|
1040
|
+
}
|
|
1037
1041
|
});
|
|
1038
1042
|
}
|
|
1039
1043
|
|
|
@@ -1044,7 +1048,7 @@ class PopupWidget extends Widget {
|
|
|
1044
1048
|
if (!dialog) throw new Error("Could not determine container div");
|
|
1045
1049
|
dialog.close();
|
|
1046
1050
|
|
|
1047
|
-
_log$
|
|
1051
|
+
_log$6("Popup closed");
|
|
1048
1052
|
}
|
|
1049
1053
|
|
|
1050
1054
|
_clickedOutside(_ref) {
|
|
@@ -1065,7 +1069,7 @@ class PopupWidget extends Widget {
|
|
|
1065
1069
|
|
|
1066
1070
|
}
|
|
1067
1071
|
|
|
1068
|
-
var _log$
|
|
1072
|
+
var _log$5 = debug.debug("squatch-js:widgets");
|
|
1069
1073
|
/**
|
|
1070
1074
|
* `Widgets` is a factory for creating widgets. It's possible to build your own widgets using the
|
|
1071
1075
|
* {@link WidgetApi} but most people will prefer to use these easy methods.
|
|
@@ -1154,7 +1158,7 @@ class Widgets {
|
|
|
1154
1158
|
user: response.user
|
|
1155
1159
|
};
|
|
1156
1160
|
} catch (err) {
|
|
1157
|
-
_log$
|
|
1161
|
+
_log$5(err);
|
|
1158
1162
|
|
|
1159
1163
|
if (err.apiErrorCode) {
|
|
1160
1164
|
this._renderErrorWidget(err, config.engagementMedium);
|
|
@@ -1220,7 +1224,7 @@ class Widgets {
|
|
|
1220
1224
|
var response = await this.api.squatchReferralCookie();
|
|
1221
1225
|
input(response);
|
|
1222
1226
|
} catch (e) {
|
|
1223
|
-
_log$
|
|
1227
|
+
_log$5("Autofill error", e);
|
|
1224
1228
|
|
|
1225
1229
|
throw new Error(e);
|
|
1226
1230
|
}
|
|
@@ -1236,7 +1240,7 @@ class Widgets {
|
|
|
1236
1240
|
// Only use the first element found
|
|
1237
1241
|
elem = elems[0];
|
|
1238
1242
|
} else {
|
|
1239
|
-
_log$
|
|
1243
|
+
_log$5("Element id/class or function missing");
|
|
1240
1244
|
|
|
1241
1245
|
throw new Error("Element id/class or function missing");
|
|
1242
1246
|
}
|
|
@@ -1262,7 +1266,7 @@ class Widgets {
|
|
|
1262
1266
|
_renderWidget(response, config, context) {
|
|
1263
1267
|
var _opts$widget;
|
|
1264
1268
|
|
|
1265
|
-
_log$
|
|
1269
|
+
_log$5("Rendering Widget...");
|
|
1266
1270
|
|
|
1267
1271
|
if (!response) throw new Error("Unable to get a response");
|
|
1268
1272
|
var widget;
|
|
@@ -1285,16 +1289,16 @@ class Widgets {
|
|
|
1285
1289
|
if (rule.widgetType !== "CONVERSION_WIDGET" || (_response$user = response.user) != null && (_response$user$referr = _response$user.referredBy) != null && _response$user$referr.code) {
|
|
1286
1290
|
displayOnLoad = rule.displayOnLoad;
|
|
1287
1291
|
|
|
1288
|
-
_log$
|
|
1292
|
+
_log$5("Display " + rule.widgetType + " on " + rule.url);
|
|
1289
1293
|
} else {
|
|
1290
|
-
_log$
|
|
1294
|
+
_log$5("Don't display " + rule.widgetType + " when no referral on widget rule match " + rule.url);
|
|
1291
1295
|
}
|
|
1292
1296
|
}
|
|
1293
1297
|
});
|
|
1294
1298
|
}
|
|
1295
1299
|
|
|
1296
1300
|
if (opts.fuelTankAutofillUrls) {
|
|
1297
|
-
_log$
|
|
1301
|
+
_log$5("We found a fuel tank autofill!");
|
|
1298
1302
|
|
|
1299
1303
|
opts.fuelTankAutofillUrls.forEach(_ref => {
|
|
1300
1304
|
var {
|
|
@@ -1305,7 +1309,7 @@ class Widgets {
|
|
|
1305
1309
|
if (Widgets._matchesUrl(url)) {
|
|
1306
1310
|
var _response$user2, _response$user2$refer;
|
|
1307
1311
|
|
|
1308
|
-
_log$
|
|
1312
|
+
_log$5("Fuel Tank URL matches");
|
|
1309
1313
|
|
|
1310
1314
|
if ((_response$user2 = response.user) != null && (_response$user2$refer = _response$user2.referredBy) != null && _response$user2$refer.code) {
|
|
1311
1315
|
var formAutofill = document.querySelector(formSelector);
|
|
@@ -1315,7 +1319,7 @@ class Widgets {
|
|
|
1315
1319
|
|
|
1316
1320
|
formAutofill.value = ((_response$user$referr2 = response.user.referredBy.referredReward) == null ? void 0 : _response$user$referr2.fuelTankCode) || "";
|
|
1317
1321
|
} else {
|
|
1318
|
-
_log$
|
|
1322
|
+
_log$5(new Error("Element with id/class " + formSelector + " was not found."));
|
|
1319
1323
|
}
|
|
1320
1324
|
}
|
|
1321
1325
|
}
|
|
@@ -1323,15 +1327,9 @@ class Widgets {
|
|
|
1323
1327
|
}
|
|
1324
1328
|
|
|
1325
1329
|
if (config.engagementMedium === "EMBED") {
|
|
1326
|
-
widget = this._renderEmbedWidget(params
|
|
1327
|
-
} else if (config.engagementMedium === "POPUP") {
|
|
1328
|
-
widget = this._renderPopupWidget(params);
|
|
1329
|
-
if (displayOnLoad) widget.open();
|
|
1330
|
+
widget = this._renderEmbedWidget(params);
|
|
1330
1331
|
} else {
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
widget = new PopupWidget(params);
|
|
1334
|
-
widget.load();
|
|
1332
|
+
widget = this._renderPopupWidget(params);
|
|
1335
1333
|
if (displayOnLoad) widget.open();
|
|
1336
1334
|
}
|
|
1337
1335
|
|
|
@@ -1344,8 +1342,8 @@ class Widgets {
|
|
|
1344
1342
|
return widget;
|
|
1345
1343
|
}
|
|
1346
1344
|
|
|
1347
|
-
_renderEmbedWidget(params
|
|
1348
|
-
var widget = new EmbedWidget(params, container);
|
|
1345
|
+
_renderEmbedWidget(params) {
|
|
1346
|
+
var widget = new EmbedWidget(params, params.context.container);
|
|
1349
1347
|
widget.load();
|
|
1350
1348
|
return widget;
|
|
1351
1349
|
}
|
|
@@ -1368,7 +1366,7 @@ class Widgets {
|
|
|
1368
1366
|
message
|
|
1369
1367
|
} = props;
|
|
1370
1368
|
|
|
1371
|
-
_log$
|
|
1369
|
+
_log$5(new Error(apiErrorCode + " (" + rsCode + ") " + message));
|
|
1372
1370
|
|
|
1373
1371
|
var params = {
|
|
1374
1372
|
content: "error",
|
|
@@ -1504,7 +1502,7 @@ function asyncLoad() {
|
|
|
1504
1502
|
|
|
1505
1503
|
/** @hidden */
|
|
1506
1504
|
|
|
1507
|
-
var _log$
|
|
1505
|
+
var _log$4 = debug.debug("squatch-js");
|
|
1508
1506
|
|
|
1509
1507
|
var isObject = item => typeof item === "object" && !Array.isArray(item);
|
|
1510
1508
|
|
|
@@ -1557,7 +1555,7 @@ function _pushCookie() {
|
|
|
1557
1555
|
try {
|
|
1558
1556
|
paramsJSON = JSON.parse(b64decode(refParam));
|
|
1559
1557
|
} catch (error) {
|
|
1560
|
-
_log$
|
|
1558
|
+
_log$4("Unable to decode params", error); // don't merge invalid params
|
|
1561
1559
|
|
|
1562
1560
|
|
|
1563
1561
|
return;
|
|
@@ -1566,26 +1564,26 @@ function _pushCookie() {
|
|
|
1566
1564
|
try {
|
|
1567
1565
|
existingCookie = JSON.parse(b64decode(Cookies__default['default'].get("_saasquatch")));
|
|
1568
1566
|
|
|
1569
|
-
_log$
|
|
1567
|
+
_log$4("existing cookie", existingCookie);
|
|
1570
1568
|
} catch (error) {
|
|
1571
|
-
_log$
|
|
1569
|
+
_log$4("Unable to retrieve cookie", error);
|
|
1572
1570
|
} // don't merge if there's no existing object
|
|
1573
1571
|
|
|
1574
1572
|
|
|
1575
1573
|
try {
|
|
1576
1574
|
var domain = getTopDomain();
|
|
1577
1575
|
|
|
1578
|
-
_log$
|
|
1576
|
+
_log$4("domain retrieved:", domain);
|
|
1579
1577
|
|
|
1580
1578
|
if (existingCookie) {
|
|
1581
1579
|
var newCookie = deepMerge(existingCookie, paramsJSON);
|
|
1582
1580
|
reEncodedCookie = b64encode(JSON.stringify(newCookie));
|
|
1583
1581
|
|
|
1584
|
-
_log$
|
|
1582
|
+
_log$4("cookie to store:", newCookie);
|
|
1585
1583
|
} else {
|
|
1586
1584
|
reEncodedCookie = b64encode(JSON.stringify(paramsJSON));
|
|
1587
1585
|
|
|
1588
|
-
_log$
|
|
1586
|
+
_log$4("cookie to store:", paramsJSON);
|
|
1589
1587
|
}
|
|
1590
1588
|
|
|
1591
1589
|
Cookies__default['default'].set("_saasquatch", reEncodedCookie, {
|
|
@@ -1596,14 +1594,14 @@ function _pushCookie() {
|
|
|
1596
1594
|
path: "/"
|
|
1597
1595
|
});
|
|
1598
1596
|
} catch (error) {
|
|
1599
|
-
_log$
|
|
1597
|
+
_log$4("Unable to set cookie", error);
|
|
1600
1598
|
}
|
|
1601
1599
|
}
|
|
1602
1600
|
}
|
|
1603
1601
|
|
|
1604
1602
|
/** @hidden */
|
|
1605
1603
|
|
|
1606
|
-
var _log$
|
|
1604
|
+
var _log$3 = debug.debug("squatch-js");
|
|
1607
1605
|
|
|
1608
1606
|
function _getAutoConfig(configIn) {
|
|
1609
1607
|
var queryString = window.location.search;
|
|
@@ -1611,7 +1609,7 @@ function _getAutoConfig(configIn) {
|
|
|
1611
1609
|
var refParam = urlParams.get("_saasquatchExtra") || "";
|
|
1612
1610
|
|
|
1613
1611
|
if (!refParam) {
|
|
1614
|
-
_log$
|
|
1612
|
+
_log$3("No _saasquatchExtra param");
|
|
1615
1613
|
|
|
1616
1614
|
return;
|
|
1617
1615
|
}
|
|
@@ -1621,7 +1619,7 @@ function _getAutoConfig(configIn) {
|
|
|
1621
1619
|
try {
|
|
1622
1620
|
raw = JSON.parse(b64decode(refParam));
|
|
1623
1621
|
} catch (e) {
|
|
1624
|
-
_log$
|
|
1622
|
+
_log$3("Unable to decode _saasquatchExtra config");
|
|
1625
1623
|
|
|
1626
1624
|
return;
|
|
1627
1625
|
}
|
|
@@ -1633,7 +1631,7 @@ function _getAutoConfig(configIn) {
|
|
|
1633
1631
|
} = convertExtraToConfig(raw);
|
|
1634
1632
|
|
|
1635
1633
|
if (!domain || !tenantAlias || !widgetConfig) {
|
|
1636
|
-
_log$
|
|
1634
|
+
_log$3("_saasquatchExtra did not have an expected structure");
|
|
1637
1635
|
|
|
1638
1636
|
return undefined;
|
|
1639
1637
|
}
|
|
@@ -1676,7 +1674,7 @@ function convertExtraToConfig(obj) {
|
|
|
1676
1674
|
};
|
|
1677
1675
|
}
|
|
1678
1676
|
|
|
1679
|
-
var _log$
|
|
1677
|
+
var _log$2 = debug.debug("squatch-js:decodeJwt");
|
|
1680
1678
|
|
|
1681
1679
|
function decodeUserJwt(tokenStr) {
|
|
1682
1680
|
try {
|
|
@@ -1687,13 +1685,13 @@ function decodeUserJwt(tokenStr) {
|
|
|
1687
1685
|
var jsonStr = b64decode(base64Url);
|
|
1688
1686
|
return (_JSON$parse = JSON.parse(jsonStr)) == null ? void 0 : _JSON$parse.user;
|
|
1689
1687
|
} catch (e) {
|
|
1690
|
-
_log$
|
|
1688
|
+
_log$2(e);
|
|
1691
1689
|
|
|
1692
1690
|
return null;
|
|
1693
1691
|
}
|
|
1694
1692
|
}
|
|
1695
1693
|
|
|
1696
|
-
debug__default['default']("
|
|
1694
|
+
var _log$1 = debug__default['default']("squatch-js:DeclarativeWidget");
|
|
1697
1695
|
/**
|
|
1698
1696
|
* Abstract class for building web-components that render SaaSquatch widgets to the DOM.
|
|
1699
1697
|
* @abstract
|
|
@@ -1772,16 +1770,17 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1772
1770
|
content: template,
|
|
1773
1771
|
context: {
|
|
1774
1772
|
type: config.type,
|
|
1773
|
+
user: config.user,
|
|
1774
|
+
container: this.container || this,
|
|
1775
1775
|
engagementMedium: this.type
|
|
1776
1776
|
},
|
|
1777
1777
|
type: this.widgetType,
|
|
1778
1778
|
domain: ((_this$config = this.config) == null ? void 0 : _this$config.domain) || DEFAULT_DOMAIN,
|
|
1779
|
-
npmCdn: DEFAULT_NPM_CDN
|
|
1780
|
-
container: this.container || this
|
|
1779
|
+
npmCdn: DEFAULT_NPM_CDN
|
|
1781
1780
|
};
|
|
1782
1781
|
|
|
1783
1782
|
if (this.type === "EMBED") {
|
|
1784
|
-
return new EmbedWidget(params);
|
|
1783
|
+
return new EmbedWidget(params, params.context.container);
|
|
1785
1784
|
} else {
|
|
1786
1785
|
return new PopupWidget(params, this.firstChild ? null : undefined);
|
|
1787
1786
|
}
|
|
@@ -1794,16 +1793,16 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1794
1793
|
api: this.widgetApi,
|
|
1795
1794
|
content: "error",
|
|
1796
1795
|
context: {
|
|
1797
|
-
type: "error"
|
|
1796
|
+
type: "error",
|
|
1797
|
+
container: this.container || this
|
|
1798
1798
|
},
|
|
1799
1799
|
type: "ERROR_WIDGET",
|
|
1800
1800
|
domain: ((_this$config2 = this.config) == null ? void 0 : _this$config2.domain) || DEFAULT_DOMAIN,
|
|
1801
|
-
npmCdn: DEFAULT_NPM_CDN
|
|
1802
|
-
container: this.container || this
|
|
1801
|
+
npmCdn: DEFAULT_NPM_CDN
|
|
1803
1802
|
};
|
|
1804
1803
|
|
|
1805
1804
|
if (this.type === "EMBED") {
|
|
1806
|
-
return new EmbedWidget(params);
|
|
1805
|
+
return new EmbedWidget(params, params.context.container);
|
|
1807
1806
|
} else {
|
|
1808
1807
|
return new PopupWidget(params, this.firstChild ? null : undefined);
|
|
1809
1808
|
}
|
|
@@ -1824,7 +1823,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1824
1823
|
_setupApis(config) {
|
|
1825
1824
|
var _this$config3, _this$config4;
|
|
1826
1825
|
|
|
1827
|
-
if (!this.tenant) throw new Error("
|
|
1826
|
+
if (!this.tenant) throw new Error("tenantAlias not provided");
|
|
1828
1827
|
this.widgetApi = new WidgetApi({
|
|
1829
1828
|
tenantAlias: (config == null ? void 0 : config.tenantAlias) || this.tenant,
|
|
1830
1829
|
domain: (config == null ? void 0 : config.domain) || ((_this$config3 = this.config) == null ? void 0 : _this$config3.domain) || DEFAULT_DOMAIN
|
|
@@ -1835,16 +1834,14 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1835
1834
|
}
|
|
1836
1835
|
|
|
1837
1836
|
async renderPasswordlessVariant() {
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
var configs = _getAutoConfig();
|
|
1837
|
+
this._setupApis();
|
|
1841
1838
|
|
|
1842
|
-
|
|
1839
|
+
_log$1("Rendering as an Instant Access widget");
|
|
1843
1840
|
|
|
1844
1841
|
return await this.widgetApi.render({
|
|
1845
|
-
engagementMedium:
|
|
1846
|
-
widgetType:
|
|
1847
|
-
locale:
|
|
1842
|
+
engagementMedium: this.type,
|
|
1843
|
+
widgetType: this.widgetType,
|
|
1844
|
+
locale: this.locale
|
|
1848
1845
|
}).then(res => this._setWidget(res.template, {
|
|
1849
1846
|
type: "passwordless"
|
|
1850
1847
|
})).catch(this.setErrorWidget);
|
|
@@ -1854,7 +1851,13 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1854
1851
|
this._setupApis();
|
|
1855
1852
|
|
|
1856
1853
|
var userObj = decodeUserJwt(this.token);
|
|
1857
|
-
|
|
1854
|
+
|
|
1855
|
+
if (!userObj) {
|
|
1856
|
+
return this.setErrorWidget(Error("No user object in token."));
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
_log$1("Rendering as a Verified widget");
|
|
1860
|
+
|
|
1858
1861
|
var widgetInstance = await this.widgetApi.upsertUser({
|
|
1859
1862
|
user: userObj,
|
|
1860
1863
|
locale: this.locale,
|
|
@@ -1862,7 +1865,8 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1862
1865
|
widgetType: this.widgetType,
|
|
1863
1866
|
jwt: this.token
|
|
1864
1867
|
}).then(res => this._setWidget(res.template, {
|
|
1865
|
-
type: "upsert"
|
|
1868
|
+
type: "upsert",
|
|
1869
|
+
user: userObj
|
|
1866
1870
|
})).catch(this.setErrorWidget);
|
|
1867
1871
|
return widgetInstance;
|
|
1868
1872
|
}
|
|
@@ -1991,9 +1995,8 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
1991
1995
|
|
|
1992
1996
|
this.type = "POPUP";
|
|
1993
1997
|
this.addEventListener("click", e => {
|
|
1994
|
-
e.stopPropagation();
|
|
1995
|
-
|
|
1996
|
-
if (e.target.tagName !== "SQUATCH-POPUP") this.open();
|
|
1998
|
+
e.stopPropagation();
|
|
1999
|
+
this.open();
|
|
1997
2000
|
});
|
|
1998
2001
|
}
|
|
1999
2002
|
|
|
@@ -2013,6 +2016,7 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
2013
2016
|
}
|
|
2014
2017
|
|
|
2015
2018
|
async connectedCallback() {
|
|
2019
|
+
this.container = this.getAttribute("container") || this;
|
|
2016
2020
|
await this.renderWidget();
|
|
2017
2021
|
if (this.getAttribute("open") !== null) this.open();
|
|
2018
2022
|
}
|
|
@@ -2146,6 +2150,8 @@ function init(configIn) {
|
|
|
2146
2150
|
|
|
2147
2151
|
if (config.tenantAlias.match("^test") || config.debug) {
|
|
2148
2152
|
debug.debug.enable("squatch-js*");
|
|
2153
|
+
} else {
|
|
2154
|
+
debug.debug.disable();
|
|
2149
2155
|
}
|
|
2150
2156
|
|
|
2151
2157
|
_log("initializing ...");
|