@saasquatch/squatch-js 2.6.0-0 → 2.6.0-2
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/README.md +87 -68
- package/coverage/clover.xml +3 -885
- package/coverage/coverage-final.json +1 -23
- package/coverage/lcov-report/WidgetApi.ts.html +631 -0
- package/coverage/lcov-report/api/AnalyticsApi.ts.html +4 -4
- package/coverage/lcov-report/api/WidgetApi.ts.html +36 -33
- package/coverage/lcov-report/api/graphql.ts.html +1 -1
- package/coverage/lcov-report/utils/domready.ts.html +2 -2
- package/coverage/lcov-report/utils/io.ts.html +31 -16
- package/coverage/lcov-report/utils/validate.ts.html +48 -48
- package/coverage/lcov-report/validate.ts.html +1 -1
- package/coverage/lcov-report/widgets/EmbedWidget.ts.html +21 -24
- package/coverage/lcov-report/widgets/PopupWidget.ts.html +72 -27
- package/coverage/lcov-report/widgets/Widget.ts.html +78 -21
- package/coverage/lcov-report/widgets/Widgets.ts.html +1060 -0
- package/coverage/lcov.info +0 -1628
- package/cucumber.js +3 -3
- package/dist/squatch.d.ts +0 -15
- package/dist/squatch.esm.js +145 -153
- package/dist/squatch.esm.js.map +1 -1
- package/dist/squatch.js +144 -153
- package/dist/squatch.js.map +1 -1
- package/dist/squatch.min.js +1 -1
- package/dist/utils/io.d.ts +1 -1
- package/dist/widgets/EmbedWidget.d.ts +5 -5
- package/dist/widgets/PopupWidget.d.ts +5 -5
- package/dist/widgets/Widget.d.ts +3 -2
- package/dist/widgets/Widgets.d.ts +1 -10
- package/dist/widgets/declarative/DeclarativeWidget.d.ts +4 -6
- package/jest.config.ts +3 -5
- package/package.json +5 -5
- package/tsconfig.json +1 -0
package/dist/squatch.js
CHANGED
|
@@ -41,7 +41,9 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
41
41
|
|
|
42
42
|
debug.debug("squatch-js:io");
|
|
43
43
|
|
|
44
|
-
async function doQuery(url, query, variables,
|
|
44
|
+
async function doQuery(url, query, variables, jwt) {
|
|
45
|
+
var token = jwt || window.squatchToken;
|
|
46
|
+
|
|
45
47
|
var headers = _extends({
|
|
46
48
|
Accept: "application/json",
|
|
47
49
|
"Content-Type": "application/json"
|
|
@@ -75,7 +77,8 @@ async function doGet(url, jwt) {
|
|
|
75
77
|
Accept: "application/json",
|
|
76
78
|
"Content-Type": "application/json"
|
|
77
79
|
};
|
|
78
|
-
|
|
80
|
+
var token = jwt || window.squatchToken;
|
|
81
|
+
if (token) headers["X-SaaSquatch-User-Token"] = token;
|
|
79
82
|
|
|
80
83
|
try {
|
|
81
84
|
var res = await fetch(url, {
|
|
@@ -95,7 +98,8 @@ async function doPost(url, data, jwt) {
|
|
|
95
98
|
Accept: "application/json",
|
|
96
99
|
"Content-Type": "application/json"
|
|
97
100
|
};
|
|
98
|
-
|
|
101
|
+
var token = jwt || window.squatchToken;
|
|
102
|
+
if (token) headers["X-SaaSquatch-User-Token"] = token;
|
|
99
103
|
|
|
100
104
|
try {
|
|
101
105
|
var res = await fetch(url, {
|
|
@@ -116,7 +120,8 @@ async function doPut(url, data, jwt) {
|
|
|
116
120
|
"Content-Type": "application/json",
|
|
117
121
|
"X-SaaSquatch-Referrer": window ? window.location.href : ""
|
|
118
122
|
};
|
|
119
|
-
|
|
123
|
+
var token = jwt || window.squatchToken;
|
|
124
|
+
if (token) headers["X-SaaSquatch-User-Token"] = token;
|
|
120
125
|
|
|
121
126
|
try {
|
|
122
127
|
var res = await fetch(url, {
|
|
@@ -184,8 +189,6 @@ var RENDER_WIDGET_QUERY = "\n query renderWidget ($user: UserIdInput, $engageme
|
|
|
184
189
|
*/
|
|
185
190
|
|
|
186
191
|
class WidgetApi {
|
|
187
|
-
// TODO: Support using new window variables for initialisation
|
|
188
|
-
|
|
189
192
|
/**
|
|
190
193
|
* Initialize a new {@link WidgetApi} instance.
|
|
191
194
|
*
|
|
@@ -238,8 +241,8 @@ class WidgetApi {
|
|
|
238
241
|
user
|
|
239
242
|
} = clean;
|
|
240
243
|
var tenantAlias = encodeURIComponent(this.tenantAlias);
|
|
241
|
-
var accountId = encodeURIComponent(user.accountId);
|
|
242
|
-
var userId = encodeURIComponent(user.id);
|
|
244
|
+
var accountId = user.accountId ? encodeURIComponent(user.accountId) : null;
|
|
245
|
+
var userId = user.id ? encodeURIComponent(user.id) : null;
|
|
243
246
|
|
|
244
247
|
var optionalParams = _buildParams({
|
|
245
248
|
widgetType,
|
|
@@ -279,8 +282,8 @@ class WidgetApi {
|
|
|
279
282
|
user
|
|
280
283
|
} = clean;
|
|
281
284
|
var tenantAlias = encodeURIComponent(this.tenantAlias);
|
|
282
|
-
var accountId = user ? encodeURIComponent(user.accountId) : null;
|
|
283
|
-
var userId = user ? encodeURIComponent(user.id) : null;
|
|
285
|
+
var accountId = user != null && user.accountId ? encodeURIComponent(user.accountId) : null;
|
|
286
|
+
var userId = user != null && user.id ? encodeURIComponent(user.id) : null;
|
|
284
287
|
var locale = (_clean$locale = clean.locale) != null ? _clean$locale : validateLocale(navigator.language.replace(/\-/g, "_"));
|
|
285
288
|
var path = "/api/v1/" + tenantAlias + "/graphql";
|
|
286
289
|
var url = this.domain + path;
|
|
@@ -463,6 +466,7 @@ class Widget {
|
|
|
463
466
|
_createFrame() {
|
|
464
467
|
var frame = document.createElement("iframe");
|
|
465
468
|
frame["squatchJsApi"] = this;
|
|
469
|
+
frame.id = "squatchFrame";
|
|
466
470
|
frame.width = "100%";
|
|
467
471
|
frame.src = "about:blank";
|
|
468
472
|
frame.scrolling = "no";
|
|
@@ -470,6 +474,13 @@ class Widget {
|
|
|
470
474
|
return frame;
|
|
471
475
|
}
|
|
472
476
|
|
|
477
|
+
_findFrame() {
|
|
478
|
+
var element = this._findElement();
|
|
479
|
+
|
|
480
|
+
var parent = element.shadowRoot || element;
|
|
481
|
+
return parent.querySelector("iframe#squatchFrame");
|
|
482
|
+
}
|
|
483
|
+
|
|
473
484
|
_loadEvent(sqh) {
|
|
474
485
|
var _this$analyticsApi$pu;
|
|
475
486
|
|
|
@@ -506,7 +517,7 @@ class Widget {
|
|
|
506
517
|
(_this$analyticsApi$pu = this.analyticsApi.pushAnalyticsLoadEvent(params)) == null ? void 0 : _this$analyticsApi$pu.then(response => {
|
|
507
518
|
_log$7(params.engagementMedium + " loaded event recorded.");
|
|
508
519
|
}).catch(ex => {
|
|
509
|
-
_log$7(
|
|
520
|
+
_log$7("ERROR: pushAnalyticsLoadEvent() " + ex);
|
|
510
521
|
});
|
|
511
522
|
}
|
|
512
523
|
|
|
@@ -521,7 +532,7 @@ class Widget {
|
|
|
521
532
|
}).then(response => {
|
|
522
533
|
_log$7(sqh.mode.widgetMode + " share " + medium + " event recorded. " + response);
|
|
523
534
|
}).catch(ex => {
|
|
524
|
-
_log$7(
|
|
535
|
+
_log$7("ERROR: pushAnalyticsShareClickedEvent() " + ex);
|
|
525
536
|
});
|
|
526
537
|
}
|
|
527
538
|
} // TODO: CA: Refactor how error templates are shown
|
|
@@ -576,12 +587,16 @@ class Widget {
|
|
|
576
587
|
*/
|
|
577
588
|
|
|
578
589
|
|
|
579
|
-
reload(
|
|
590
|
+
reload(_ref, jwt) {
|
|
580
591
|
var {
|
|
581
592
|
email,
|
|
582
593
|
firstName,
|
|
583
594
|
lastName
|
|
584
595
|
} = _ref;
|
|
596
|
+
|
|
597
|
+
var frame = this._findFrame();
|
|
598
|
+
|
|
599
|
+
if (!frame) throw new Error("Could not find widget iframe");
|
|
585
600
|
var frameWindow = frame.contentWindow;
|
|
586
601
|
var engagementMedium = this.context.engagementMedium || "POPUP";
|
|
587
602
|
|
|
@@ -592,6 +607,7 @@ class Widget {
|
|
|
592
607
|
var response;
|
|
593
608
|
|
|
594
609
|
if (this.context.type === "upsert") {
|
|
610
|
+
if (!this.context.user) throw new Error("Can't reload without user ids");
|
|
595
611
|
var userObj = {
|
|
596
612
|
email: email || null,
|
|
597
613
|
firstName: firstName || null,
|
|
@@ -628,9 +644,9 @@ class Widget {
|
|
|
628
644
|
email,
|
|
629
645
|
engagementMedium
|
|
630
646
|
}, () => {
|
|
631
|
-
this.load(
|
|
647
|
+
this.load(); // @ts-ignore -- open exists in the PopupWidget, so this call will always exist when it's called.
|
|
632
648
|
|
|
633
|
-
engagementMedium === "POPUP" && this.open(
|
|
649
|
+
engagementMedium === "POPUP" && this.open();
|
|
634
650
|
});
|
|
635
651
|
}
|
|
636
652
|
}).catch(_ref3 => {
|
|
@@ -667,6 +683,7 @@ class Widget {
|
|
|
667
683
|
function delay(duration) {
|
|
668
684
|
return new Promise(function (resolve, reject) {
|
|
669
685
|
setTimeout(function () {
|
|
686
|
+
/* istanbul ignore next */
|
|
670
687
|
resolve(() => {});
|
|
671
688
|
}, duration);
|
|
672
689
|
});
|
|
@@ -713,12 +730,18 @@ class EmbedWidget extends Widget {
|
|
|
713
730
|
this.hide = this.close;
|
|
714
731
|
}
|
|
715
732
|
|
|
716
|
-
async load(
|
|
733
|
+
async load() {
|
|
734
|
+
var frame = this._createFrame();
|
|
735
|
+
|
|
717
736
|
var element = this._findElement();
|
|
718
737
|
|
|
719
738
|
if (this.container) {
|
|
720
739
|
if (element.shadowRoot) {
|
|
721
|
-
|
|
740
|
+
var _element$shadowRoot$l;
|
|
741
|
+
|
|
742
|
+
if (((_element$shadowRoot$l = element.shadowRoot.lastChild) == null ? void 0 : _element$shadowRoot$l.nodeName) === "IFRAME") element.shadowRoot.replaceChild(frame, element.shadowRoot.lastChild);else {
|
|
743
|
+
element.shadowRoot.appendChild(frame);
|
|
744
|
+
}
|
|
722
745
|
} // Widget reloaded - replace existing element
|
|
723
746
|
else if (element.firstChild) {
|
|
724
747
|
element.replaceChild(frame, element.firstChild); // Add iframe for the first time
|
|
@@ -743,17 +766,7 @@ class EmbedWidget extends Widget {
|
|
|
743
766
|
frameDoc.write("<script src=\"" + this.npmCdn + "/resize-observer-polyfill@1.5.x\"></script>");
|
|
744
767
|
frameDoc.close();
|
|
745
768
|
domready(frameDoc, async () => {
|
|
746
|
-
var _sqh = contentWindow.squatch || contentWindow.widgetIdent;
|
|
747
|
-
|
|
748
|
-
var ctaElement = frameDoc.getElementById("cta");
|
|
749
|
-
|
|
750
|
-
if (ctaElement) {
|
|
751
|
-
if (!ctaElement.parentNode) {
|
|
752
|
-
throw new Error("ctaElement needs a parentNode");
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
ctaElement.parentNode.removeChild(ctaElement);
|
|
756
|
-
} // @ts-ignore -- number will be cast to string by browsers
|
|
769
|
+
var _sqh = contentWindow.squatch || contentWindow.widgetIdent; // @ts-ignore -- number will be cast to string by browsers
|
|
757
770
|
|
|
758
771
|
|
|
759
772
|
frame.height = frameDoc.body.scrollHeight; // Adjust frame height when size of body changes
|
|
@@ -778,9 +791,11 @@ class EmbedWidget extends Widget {
|
|
|
778
791
|
} // Un-hide if element is available and refresh data
|
|
779
792
|
|
|
780
793
|
|
|
781
|
-
open(
|
|
794
|
+
open() {
|
|
782
795
|
var _frame$contentDocumen, _frame$contentWindow, _frame$contentWindow2;
|
|
783
796
|
|
|
797
|
+
var frame = this._findFrame();
|
|
798
|
+
|
|
784
799
|
if (!frame) return _log$6("no target element to open");
|
|
785
800
|
|
|
786
801
|
var element = this._findElement();
|
|
@@ -797,7 +812,9 @@ class EmbedWidget extends Widget {
|
|
|
797
812
|
_log$6("loaded");
|
|
798
813
|
}
|
|
799
814
|
|
|
800
|
-
close(
|
|
815
|
+
close() {
|
|
816
|
+
var frame = this._findFrame();
|
|
817
|
+
|
|
801
818
|
if (!frame) return _log$6("no target element to close");
|
|
802
819
|
|
|
803
820
|
var element = this._findElement();
|
|
@@ -860,6 +877,7 @@ class PopupWidget extends Widget {
|
|
|
860
877
|
}
|
|
861
878
|
|
|
862
879
|
_initialiseCTA(frame) {
|
|
880
|
+
if (!this.trigger) return;
|
|
863
881
|
var triggerElement;
|
|
864
882
|
|
|
865
883
|
try {
|
|
@@ -874,21 +892,18 @@ class PopupWidget extends Widget {
|
|
|
874
892
|
|
|
875
893
|
if (triggerElement) {
|
|
876
894
|
triggerElement.onclick = () => {
|
|
877
|
-
this.open(
|
|
895
|
+
this.open();
|
|
878
896
|
};
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
var element = this._findElement(); // If widget is loaded with CTA, look for a 'squatchpop' element to use
|
|
897
|
+
} // const element = this._findElement();
|
|
898
|
+
// If widget is loaded with CTA, look for a 'squatchpop' element to use
|
|
882
899
|
// that element as a trigger as well.
|
|
900
|
+
// const triggerWhenCTA = element.querySelector(".squatchpop") as HTMLElement;
|
|
901
|
+
// if (this.trigger === "#cta" && triggerWhenCTA) {
|
|
902
|
+
// triggerWhenCTA.onclick = () => {
|
|
903
|
+
// this.open(frame);
|
|
904
|
+
// };
|
|
905
|
+
// }
|
|
883
906
|
|
|
884
|
-
|
|
885
|
-
var triggerWhenCTA = element.querySelector(".squatchpop");
|
|
886
|
-
|
|
887
|
-
if (this.trigger === "#cta" && triggerWhenCTA) {
|
|
888
|
-
triggerWhenCTA.onclick = () => {
|
|
889
|
-
this.open(frame);
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
907
|
}
|
|
893
908
|
|
|
894
909
|
_createPopupDialog() {
|
|
@@ -904,7 +919,11 @@ class PopupWidget extends Widget {
|
|
|
904
919
|
return dialog;
|
|
905
920
|
}
|
|
906
921
|
|
|
907
|
-
load(
|
|
922
|
+
load() {
|
|
923
|
+
var _dialogParent$lastChi;
|
|
924
|
+
|
|
925
|
+
var frame = this._createFrame();
|
|
926
|
+
|
|
908
927
|
this._initialiseCTA(frame);
|
|
909
928
|
|
|
910
929
|
var element = this._findElement();
|
|
@@ -914,7 +933,15 @@ class PopupWidget extends Widget {
|
|
|
914
933
|
var dialog = this._createPopupDialog();
|
|
915
934
|
|
|
916
935
|
dialog.appendChild(frame);
|
|
917
|
-
|
|
936
|
+
|
|
937
|
+
if (((_dialogParent$lastChi = dialogParent.lastChild) == null ? void 0 : _dialogParent$lastChi.nodeName) === "DIALOG") {
|
|
938
|
+
// Was reloaded
|
|
939
|
+
dialogParent.replaceChild(dialog, dialogParent.lastChild);
|
|
940
|
+
} else {
|
|
941
|
+
// First time rendering
|
|
942
|
+
dialogParent.appendChild(dialog);
|
|
943
|
+
}
|
|
944
|
+
|
|
918
945
|
var {
|
|
919
946
|
contentWindow
|
|
920
947
|
} = frame;
|
|
@@ -965,13 +992,17 @@ class PopupWidget extends Widget {
|
|
|
965
992
|
});
|
|
966
993
|
}
|
|
967
994
|
|
|
968
|
-
open(
|
|
995
|
+
open() {
|
|
969
996
|
var element = this._findElement();
|
|
970
997
|
|
|
971
998
|
var parent = element.shadowRoot || element;
|
|
972
999
|
var dialog = parent.querySelector("#" + this.id);
|
|
973
1000
|
if (!dialog) throw new Error("Could not determine container div");
|
|
974
1001
|
dialog.showModal();
|
|
1002
|
+
|
|
1003
|
+
var frame = this._findFrame();
|
|
1004
|
+
|
|
1005
|
+
if (!frame) throw new Error("Could not find iframe");
|
|
975
1006
|
var {
|
|
976
1007
|
contentWindow
|
|
977
1008
|
} = frame;
|
|
@@ -992,7 +1023,10 @@ class PopupWidget extends Widget {
|
|
|
992
1023
|
}
|
|
993
1024
|
|
|
994
1025
|
close() {
|
|
995
|
-
var
|
|
1026
|
+
var element = this._findElement();
|
|
1027
|
+
|
|
1028
|
+
var parent = element.shadowRoot || element;
|
|
1029
|
+
var dialog = parent.querySelector("#" + this.id);
|
|
996
1030
|
if (!dialog) throw new Error("Could not determine container div");
|
|
997
1031
|
dialog.close();
|
|
998
1032
|
|
|
@@ -1095,7 +1129,7 @@ class Widgets {
|
|
|
1095
1129
|
this._renderErrorWidget(err, config.engagementMedium);
|
|
1096
1130
|
}
|
|
1097
1131
|
|
|
1098
|
-
throw err;
|
|
1132
|
+
throw new Error(err);
|
|
1099
1133
|
}
|
|
1100
1134
|
}
|
|
1101
1135
|
/**
|
|
@@ -1133,7 +1167,7 @@ class Widgets {
|
|
|
1133
1167
|
this._renderErrorWidget(err, clean.engagementMedium);
|
|
1134
1168
|
}
|
|
1135
1169
|
|
|
1136
|
-
throw err;
|
|
1170
|
+
throw new Error(err);
|
|
1137
1171
|
}
|
|
1138
1172
|
}
|
|
1139
1173
|
/**
|
|
@@ -1145,17 +1179,19 @@ class Widgets {
|
|
|
1145
1179
|
*/
|
|
1146
1180
|
|
|
1147
1181
|
|
|
1148
|
-
autofill(selector) {
|
|
1182
|
+
async autofill(selector) {
|
|
1149
1183
|
var input = selector;
|
|
1150
1184
|
|
|
1151
1185
|
if (typeof input === "function") {
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1186
|
+
try {
|
|
1187
|
+
var response = await this.api.squatchReferralCookie();
|
|
1188
|
+
input(response);
|
|
1189
|
+
} catch (e) {
|
|
1190
|
+
_log$4("Autofill error", e);
|
|
1191
|
+
|
|
1192
|
+
throw new Error(e);
|
|
1193
|
+
}
|
|
1156
1194
|
|
|
1157
|
-
throw ex;
|
|
1158
|
-
});
|
|
1159
1195
|
return;
|
|
1160
1196
|
}
|
|
1161
1197
|
|
|
@@ -1172,14 +1208,13 @@ class Widgets {
|
|
|
1172
1208
|
throw new Error("Element id/class or function missing");
|
|
1173
1209
|
}
|
|
1174
1210
|
|
|
1175
|
-
|
|
1176
|
-
var
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
});
|
|
1211
|
+
try {
|
|
1212
|
+
var _response = await this.api.squatchReferralCookie();
|
|
1213
|
+
|
|
1214
|
+
elem.value = _response.codes[0];
|
|
1215
|
+
} catch (e) {
|
|
1216
|
+
throw new Error(e);
|
|
1217
|
+
}
|
|
1183
1218
|
}
|
|
1184
1219
|
/**
|
|
1185
1220
|
* @hidden
|
|
@@ -1192,15 +1227,17 @@ class Widgets {
|
|
|
1192
1227
|
|
|
1193
1228
|
|
|
1194
1229
|
_renderWidget(response, config, context) {
|
|
1230
|
+
var _opts$widget;
|
|
1231
|
+
|
|
1195
1232
|
_log$4("Rendering Widget...");
|
|
1196
1233
|
|
|
1197
1234
|
if (!response) throw new Error("Unable to get a response");
|
|
1198
1235
|
var widget;
|
|
1199
1236
|
var displayOnLoad = !!config.displayOnLoad;
|
|
1200
|
-
var opts = response.jsOptions ||
|
|
1237
|
+
var opts = response.jsOptions || {};
|
|
1201
1238
|
var params = {
|
|
1202
1239
|
content: response.template,
|
|
1203
|
-
type: config.widgetType || opts.widget.defaultWidgetType,
|
|
1240
|
+
type: config.widgetType || ((_opts$widget = opts.widget) == null ? void 0 : _opts$widget.defaultWidgetType),
|
|
1204
1241
|
api: this.api,
|
|
1205
1242
|
domain: this.domain,
|
|
1206
1243
|
npmCdn: this.npmCdn,
|
|
@@ -1210,7 +1247,9 @@ class Widgets {
|
|
|
1210
1247
|
if (opts.widgetUrlMappings) {
|
|
1211
1248
|
opts.widgetUrlMappings.forEach(rule => {
|
|
1212
1249
|
if (Widgets._matchesUrl(rule.url)) {
|
|
1213
|
-
|
|
1250
|
+
var _response$user, _response$user2, _response$user2$refer;
|
|
1251
|
+
|
|
1252
|
+
if (rule.widgetType !== "CONVERSION_WIDGET" || (_response$user = response.user) != null && _response$user.referredBy && (_response$user2 = response.user) != null && (_response$user2$refer = _response$user2.referredBy) != null && _response$user2$refer.code) {
|
|
1214
1253
|
displayOnLoad = rule.displayOnLoad;
|
|
1215
1254
|
|
|
1216
1255
|
_log$4("Display " + rule.widgetType + " on " + rule.url);
|
|
@@ -1224,16 +1263,18 @@ class Widgets {
|
|
|
1224
1263
|
if (opts.fuelTankAutofillUrls) {
|
|
1225
1264
|
_log$4("We found a fuel tank autofill!");
|
|
1226
1265
|
|
|
1227
|
-
opts.fuelTankAutofillUrls.forEach(
|
|
1266
|
+
opts.fuelTankAutofillUrls.forEach(_ref => {
|
|
1228
1267
|
var {
|
|
1229
1268
|
url,
|
|
1230
1269
|
formSelector
|
|
1231
|
-
} =
|
|
1270
|
+
} = _ref;
|
|
1232
1271
|
|
|
1233
1272
|
if (Widgets._matchesUrl(url)) {
|
|
1273
|
+
var _response$user3, _response$user4, _response$user4$refer;
|
|
1274
|
+
|
|
1234
1275
|
_log$4("Fuel Tank URL matches");
|
|
1235
1276
|
|
|
1236
|
-
if (response.user.referredBy && response.user.referredBy.code) {
|
|
1277
|
+
if ((_response$user3 = response.user) != null && _response$user3.referredBy && (_response$user4 = response.user) != null && (_response$user4$refer = _response$user4.referredBy) != null && _response$user4$refer.code) {
|
|
1237
1278
|
var formAutofill = document.querySelector(formSelector);
|
|
1238
1279
|
|
|
1239
1280
|
if (formAutofill) {
|
|
@@ -1247,7 +1288,7 @@ class Widgets {
|
|
|
1247
1288
|
}
|
|
1248
1289
|
|
|
1249
1290
|
if (config.engagementMedium === "EMBED") {
|
|
1250
|
-
this._renderEmbedWidget(params, params.context.container);
|
|
1291
|
+
widget = this._renderEmbedWidget(params, params.context.container);
|
|
1251
1292
|
} else if (config.engagementMedium === "POPUP") {
|
|
1252
1293
|
widget = this._renderPopupWidget(params);
|
|
1253
1294
|
if (displayOnLoad) widget.open();
|
|
@@ -1264,19 +1305,14 @@ class Widgets {
|
|
|
1264
1305
|
|
|
1265
1306
|
_renderPopupWidget(params) {
|
|
1266
1307
|
var widget = new PopupWidget(params, params.context.trigger);
|
|
1267
|
-
|
|
1268
|
-
var frame = widget._createFrame();
|
|
1269
|
-
|
|
1270
|
-
widget.load(frame);
|
|
1308
|
+
widget.load();
|
|
1271
1309
|
return widget;
|
|
1272
1310
|
}
|
|
1273
1311
|
|
|
1274
1312
|
_renderEmbedWidget(params, container) {
|
|
1275
1313
|
var widget = new EmbedWidget(params);
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
widget.load(frame);
|
|
1314
|
+
widget.load();
|
|
1315
|
+
return widget;
|
|
1280
1316
|
}
|
|
1281
1317
|
/**
|
|
1282
1318
|
* @hidden
|
|
@@ -1314,16 +1350,10 @@ class Widgets {
|
|
|
1314
1350
|
|
|
1315
1351
|
if (em === "EMBED") {
|
|
1316
1352
|
widget = new EmbedWidget(params);
|
|
1317
|
-
|
|
1318
|
-
var frame = widget._createFrame();
|
|
1319
|
-
|
|
1320
|
-
widget.load(frame);
|
|
1353
|
+
widget.load();
|
|
1321
1354
|
} else if (em === "POPUP") {
|
|
1322
1355
|
widget = new PopupWidget(params);
|
|
1323
|
-
|
|
1324
|
-
var _frame = widget._createFrame();
|
|
1325
|
-
|
|
1326
|
-
widget.load(_frame);
|
|
1356
|
+
widget.load();
|
|
1327
1357
|
}
|
|
1328
1358
|
}
|
|
1329
1359
|
/**
|
|
@@ -1337,30 +1367,6 @@ class Widgets {
|
|
|
1337
1367
|
// If there were no matches, null is returned.
|
|
1338
1368
|
return window.location.href.match(new RegExp(rule)) ? true : false;
|
|
1339
1369
|
}
|
|
1340
|
-
/**
|
|
1341
|
-
* @hidden
|
|
1342
|
-
* @param {Object} target Object containing the target DOM element
|
|
1343
|
-
* @param {Widget} widget A widget (EmbedWidget, PopupWidget)
|
|
1344
|
-
* @param {Object} params An object with valid parameters
|
|
1345
|
-
* (e.g) {email:'email', firstName:'firstName'}
|
|
1346
|
-
* @returns {void}
|
|
1347
|
-
*/
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
static _cb(target, widget, params) {
|
|
1351
|
-
var paramsObj; // If params is a string, then it should be an email
|
|
1352
|
-
|
|
1353
|
-
if (typeof params === "string" || params instanceof String) {
|
|
1354
|
-
paramsObj = {
|
|
1355
|
-
email: params
|
|
1356
|
-
};
|
|
1357
|
-
} else {
|
|
1358
|
-
paramsObj = params;
|
|
1359
|
-
} // TODO: Reload doesn't exist on all widget types
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
widget.reload(paramsObj);
|
|
1363
|
-
}
|
|
1364
1370
|
|
|
1365
1371
|
}
|
|
1366
1372
|
|
|
@@ -1665,16 +1671,14 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1665
1671
|
this.analyticsApi = void 0;
|
|
1666
1672
|
this.type = void 0;
|
|
1667
1673
|
this.widgetInstance = void 0;
|
|
1668
|
-
this.frame = void 0;
|
|
1669
1674
|
this.container = void 0;
|
|
1670
1675
|
this.element = void 0;
|
|
1676
|
+
this._hasChildren = void 0;
|
|
1671
1677
|
|
|
1672
1678
|
this._setWidget = (template, config) => {
|
|
1673
1679
|
var _this$config;
|
|
1674
1680
|
|
|
1675
|
-
|
|
1676
|
-
var Widget = this.type === "EMBED" ? EmbedWidget : PopupWidget;
|
|
1677
|
-
return new Widget({
|
|
1681
|
+
var params = {
|
|
1678
1682
|
api: this.widgetApi,
|
|
1679
1683
|
content: template,
|
|
1680
1684
|
context: {
|
|
@@ -1685,14 +1689,19 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1685
1689
|
domain: ((_this$config = this.config) == null ? void 0 : _this$config.domain) || DEFAULT_DOMAIN,
|
|
1686
1690
|
npmCdn: DEFAULT_NPM_CDN,
|
|
1687
1691
|
container: this.container || this
|
|
1688
|
-
}
|
|
1692
|
+
};
|
|
1693
|
+
|
|
1694
|
+
if (this.type === "EMBED") {
|
|
1695
|
+
return new EmbedWidget(params);
|
|
1696
|
+
} else {
|
|
1697
|
+
return new PopupWidget(params, this.firstChild ? null : undefined);
|
|
1698
|
+
}
|
|
1689
1699
|
};
|
|
1690
1700
|
|
|
1691
1701
|
this.setErrorWidget = e => {
|
|
1692
1702
|
var _this$config2;
|
|
1693
1703
|
|
|
1694
|
-
var
|
|
1695
|
-
return new Widget({
|
|
1704
|
+
var params = {
|
|
1696
1705
|
api: this.widgetApi,
|
|
1697
1706
|
content: "error",
|
|
1698
1707
|
context: {
|
|
@@ -1702,7 +1711,13 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1702
1711
|
domain: ((_this$config2 = this.config) == null ? void 0 : _this$config2.domain) || DEFAULT_DOMAIN,
|
|
1703
1712
|
npmCdn: DEFAULT_NPM_CDN,
|
|
1704
1713
|
container: this.container || this
|
|
1705
|
-
}
|
|
1714
|
+
};
|
|
1715
|
+
|
|
1716
|
+
if (this.type === "EMBED") {
|
|
1717
|
+
return new EmbedWidget(params);
|
|
1718
|
+
} else {
|
|
1719
|
+
return new PopupWidget(params, this.firstChild ? null : undefined);
|
|
1720
|
+
}
|
|
1706
1721
|
};
|
|
1707
1722
|
|
|
1708
1723
|
this.show = this.open;
|
|
@@ -1729,14 +1744,14 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1729
1744
|
});
|
|
1730
1745
|
}
|
|
1731
1746
|
|
|
1732
|
-
renderPasswordlessVariant() {
|
|
1747
|
+
async renderPasswordlessVariant() {
|
|
1733
1748
|
var _configs$widgetConfig, _configs$widgetConfig2;
|
|
1734
1749
|
|
|
1735
1750
|
var configs = _getAutoConfig();
|
|
1736
1751
|
|
|
1737
1752
|
this._setupApis(configs == null ? void 0 : configs.squatchConfig);
|
|
1738
1753
|
|
|
1739
|
-
return this.widgetApi.render({
|
|
1754
|
+
return await this.widgetApi.render({
|
|
1740
1755
|
engagementMedium: (configs == null ? void 0 : (_configs$widgetConfig = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig.engagementMedium) || this.type,
|
|
1741
1756
|
widgetType: (configs == null ? void 0 : (_configs$widgetConfig2 = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig2.widgetType) || this.widgetType
|
|
1742
1757
|
}).then(res => this._setWidget(res.template, {
|
|
@@ -1745,8 +1760,6 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1745
1760
|
}
|
|
1746
1761
|
|
|
1747
1762
|
async renderUserUpsertVariant() {
|
|
1748
|
-
if (!this.widgetType) throw new Error("Widget must be specified");
|
|
1749
|
-
|
|
1750
1763
|
this._setupApis();
|
|
1751
1764
|
|
|
1752
1765
|
var userObj = decodeUserJwt(this.token);
|
|
@@ -1780,17 +1793,15 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1780
1793
|
|
|
1781
1794
|
async renderWidget() {
|
|
1782
1795
|
await this.getWidgetInstance();
|
|
1783
|
-
|
|
1784
|
-
this.frame = this.widgetInstance._createFrame();
|
|
1785
|
-
await this.widgetInstance.load(this.frame);
|
|
1796
|
+
await this.widgetInstance.load();
|
|
1786
1797
|
}
|
|
1787
1798
|
|
|
1788
1799
|
open() {
|
|
1789
|
-
this.widgetInstance.open(
|
|
1800
|
+
this.widgetInstance.open();
|
|
1790
1801
|
}
|
|
1791
1802
|
|
|
1792
1803
|
close() {
|
|
1793
|
-
this.widgetInstance.close(
|
|
1804
|
+
this.widgetInstance.close();
|
|
1794
1805
|
}
|
|
1795
1806
|
|
|
1796
1807
|
}
|
|
@@ -1799,7 +1810,6 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1799
1810
|
constructor() {
|
|
1800
1811
|
super();
|
|
1801
1812
|
this.type = "EMBED";
|
|
1802
|
-
this.container = this.getAttribute("container") || this;
|
|
1803
1813
|
}
|
|
1804
1814
|
|
|
1805
1815
|
static get observedAttributes() {
|
|
@@ -1816,7 +1826,7 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1816
1826
|
// Specific to embed widgets
|
|
1817
1827
|
|
|
1818
1828
|
case "container":
|
|
1819
|
-
if (this.
|
|
1829
|
+
if (this.widgetInstance._findElement()) this.close();
|
|
1820
1830
|
this.connectedCallback();
|
|
1821
1831
|
break;
|
|
1822
1832
|
}
|
|
@@ -1825,9 +1835,10 @@ class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
|
1825
1835
|
async connectedCallback() {
|
|
1826
1836
|
var _ref, _this$shadowRoot;
|
|
1827
1837
|
|
|
1838
|
+
this.container = this.getAttribute("container") || this;
|
|
1828
1839
|
await this.renderWidget();
|
|
1829
1840
|
var slot = (_ref = this.shadowRoot && Array.from(this.shadowRoot.children)) == null ? void 0 : _ref.find(c => c.tagName === "SLOT");
|
|
1830
|
-
(_this$shadowRoot = this.shadowRoot) == null ? void 0 : _this$shadowRoot.removeChild(slot);
|
|
1841
|
+
if (slot) (_this$shadowRoot = this.shadowRoot) == null ? void 0 : _this$shadowRoot.removeChild(slot);
|
|
1831
1842
|
}
|
|
1832
1843
|
|
|
1833
1844
|
}
|
|
@@ -1895,7 +1906,7 @@ var _events = null;
|
|
|
1895
1906
|
*/
|
|
1896
1907
|
|
|
1897
1908
|
function api() {
|
|
1898
|
-
if (!_api)
|
|
1909
|
+
if (!_api) exports.init({});
|
|
1899
1910
|
return _api;
|
|
1900
1911
|
}
|
|
1901
1912
|
/**
|
|
@@ -1907,7 +1918,7 @@ function api() {
|
|
|
1907
1918
|
*/
|
|
1908
1919
|
|
|
1909
1920
|
function widgets() {
|
|
1910
|
-
if (!_widgets)
|
|
1921
|
+
if (!_widgets) exports.init({});
|
|
1911
1922
|
return _widgets;
|
|
1912
1923
|
}
|
|
1913
1924
|
/**
|
|
@@ -1919,7 +1930,7 @@ function widgets() {
|
|
|
1919
1930
|
*/
|
|
1920
1931
|
|
|
1921
1932
|
function events() {
|
|
1922
|
-
if (!_events)
|
|
1933
|
+
if (!_events) exports.init({});
|
|
1923
1934
|
return _events;
|
|
1924
1935
|
}
|
|
1925
1936
|
/**
|
|
@@ -2010,25 +2021,6 @@ function autofill(selector) {
|
|
|
2010
2021
|
// @ts-ignore -- will throw occasionally throw a null pointer exception at runtime
|
|
2011
2022
|
widgets().autofill(selector);
|
|
2012
2023
|
}
|
|
2013
|
-
/**
|
|
2014
|
-
* Overrides the default function that submits the user email. If you have
|
|
2015
|
-
* Security enabled, the email needs to be signed before it's submitted.
|
|
2016
|
-
*
|
|
2017
|
-
* @param {function} fn Callback function for the 'submit_email' event.
|
|
2018
|
-
* @returns {void}
|
|
2019
|
-
*
|
|
2020
|
-
* @example
|
|
2021
|
-
* squatch.submitEmail(function(target, widget, email) {
|
|
2022
|
-
* // Sign email and generate jwt token
|
|
2023
|
-
* var jwt = 'token';
|
|
2024
|
-
* widget.reload(email, jwt);
|
|
2025
|
-
* });
|
|
2026
|
-
*/
|
|
2027
|
-
|
|
2028
|
-
function submitEmail(fn) {
|
|
2029
|
-
// @ts-ignore -- will throw occasionally throw a null pointer exception at runtime
|
|
2030
|
-
widgets().submitEmail(fn);
|
|
2031
|
-
}
|
|
2032
2024
|
/**
|
|
2033
2025
|
* Manually set the _saasquatch cookie as a 1st party cookie if available as a URL parameter on the current page.
|
|
2034
2026
|
* This runs automatically immediately when squatch-js is loaded, except when window.SaaSquatchDoNotAutoDrop is true.
|
|
@@ -2067,7 +2059,6 @@ exports.help = help;
|
|
|
2067
2059
|
exports.init = init;
|
|
2068
2060
|
exports.pushCookie = pushCookie;
|
|
2069
2061
|
exports.ready = ready;
|
|
2070
|
-
exports.submitEmail = submitEmail;
|
|
2071
2062
|
exports.widget = widget;
|
|
2072
2063
|
exports.widgets = widgets;
|
|
2073
2064
|
//# sourceMappingURL=squatch.js.map
|