@saasquatch/squatch-js 2.6.0-5 → 2.6.0-7
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 +393 -375
- package/coverage/coverage-final.json +15 -15
- 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 +684 -658
- package/dist/async.d.ts +3 -0
- package/dist/squatch.esm.js +186 -153
- package/dist/squatch.esm.js.map +1 -1
- package/dist/squatch.js +186 -153
- package/dist/squatch.js.map +1 -1
- package/dist/squatch.min.js +1 -1
- package/dist/types.d.ts +8 -6
- package/dist/utils/validate.d.ts +2 -0
- package/dist/widgets/EmbedWidget.d.ts +1 -0
- package/package.json +1 -1
package/dist/squatch.js
CHANGED
|
@@ -39,10 +39,58 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
39
39
|
return target;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
var DEFAULT_DOMAIN = "https://app.referralsaasquatch.com";
|
|
43
|
+
var DEFAULT_NPM_CDN = "https://fast.ssqt.io/npm";
|
|
44
|
+
function validateConfig(_raw) {
|
|
45
|
+
if (typeof _raw !== "object") throw new Error("config must be an object");
|
|
46
|
+
var tenant = window.squatchTenant;
|
|
47
|
+
var config = getConfig();
|
|
48
|
+
var raw = {
|
|
49
|
+
tenantAlias: (_raw == null ? void 0 : _raw["tenantAlias"]) || tenant,
|
|
50
|
+
domain: (_raw == null ? void 0 : _raw["domain"]) || (config == null ? void 0 : config.domain),
|
|
51
|
+
npmCdn: (_raw == null ? void 0 : _raw["npmCdn"]) || (config == null ? void 0 : config.npmCdn),
|
|
52
|
+
debug: (_raw == null ? void 0 : _raw["debug"]) || (config == null ? void 0 : config.debug)
|
|
53
|
+
};
|
|
54
|
+
if (typeof raw.tenantAlias !== "string") throw new Error("tenantAlias not provided");
|
|
55
|
+
var tenantAlias = raw.tenantAlias;
|
|
56
|
+
var domain = typeof raw.domain === "string" && raw.domain || DEFAULT_DOMAIN;
|
|
57
|
+
var debug = typeof raw.debug === "boolean" && raw.debug || false;
|
|
58
|
+
var npmCdn = typeof raw.npmCdn === "string" && raw.npmCdn || DEFAULT_NPM_CDN;
|
|
59
|
+
return {
|
|
60
|
+
tenantAlias,
|
|
61
|
+
domain,
|
|
62
|
+
debug,
|
|
63
|
+
npmCdn
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function isObject$1(obj) {
|
|
67
|
+
return typeof obj === "object" && !Array.isArray(obj) && obj !== null;
|
|
68
|
+
}
|
|
69
|
+
function validateLocale(locale) {
|
|
70
|
+
if (locale && /^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(locale)) {
|
|
71
|
+
return locale;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function validateWidgetConfig(raw) {
|
|
75
|
+
if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
|
|
76
|
+
if (!(raw != null && raw["user"])) throw new Error("Required properties missing.");
|
|
77
|
+
return raw;
|
|
78
|
+
}
|
|
79
|
+
function validatePasswordlessConfig(raw) {
|
|
80
|
+
if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
|
|
81
|
+
return raw;
|
|
82
|
+
}
|
|
83
|
+
function getToken() {
|
|
84
|
+
return window.impactTBDToken || window.squatchToken;
|
|
85
|
+
}
|
|
86
|
+
function getConfig() {
|
|
87
|
+
return window.impactTBDConfig || window.squatchConfig;
|
|
88
|
+
}
|
|
89
|
+
|
|
42
90
|
debug.debug("squatch-js:io");
|
|
43
91
|
|
|
44
92
|
async function doQuery(url, query, variables, jwt) {
|
|
45
|
-
var token = jwt ||
|
|
93
|
+
var token = jwt || getToken();
|
|
46
94
|
|
|
47
95
|
var headers = _extends({
|
|
48
96
|
Accept: "application/json",
|
|
@@ -77,7 +125,7 @@ async function doGet(url, jwt) {
|
|
|
77
125
|
Accept: "application/json",
|
|
78
126
|
"Content-Type": "application/json"
|
|
79
127
|
};
|
|
80
|
-
var token = jwt ||
|
|
128
|
+
var token = jwt || getToken();
|
|
81
129
|
if (token) headers["X-SaaSquatch-User-Token"] = token;
|
|
82
130
|
|
|
83
131
|
try {
|
|
@@ -98,7 +146,7 @@ async function doPost(url, data, jwt) {
|
|
|
98
146
|
Accept: "application/json",
|
|
99
147
|
"Content-Type": "application/json"
|
|
100
148
|
};
|
|
101
|
-
var token = jwt ||
|
|
149
|
+
var token = jwt || getToken();
|
|
102
150
|
if (token) headers["X-SaaSquatch-User-Token"] = token;
|
|
103
151
|
|
|
104
152
|
try {
|
|
@@ -120,7 +168,7 @@ async function doPut(url, data, jwt) {
|
|
|
120
168
|
"Content-Type": "application/json",
|
|
121
169
|
"X-SaaSquatch-Referrer": window ? window.location.href : ""
|
|
122
170
|
};
|
|
123
|
-
var token = jwt ||
|
|
171
|
+
var token = jwt || getToken();
|
|
124
172
|
if (token) headers["X-SaaSquatch-User-Token"] = token;
|
|
125
173
|
|
|
126
174
|
try {
|
|
@@ -138,48 +186,6 @@ async function doPut(url, data, jwt) {
|
|
|
138
186
|
}
|
|
139
187
|
}
|
|
140
188
|
|
|
141
|
-
var DEFAULT_DOMAIN = "https://app.referralsaasquatch.com";
|
|
142
|
-
var DEFAULT_NPM_CDN = "https://fast.ssqt.io/npm";
|
|
143
|
-
function validateConfig(_raw) {
|
|
144
|
-
var _window$squatchConfig, _window$squatchConfig2, _window$squatchConfig3;
|
|
145
|
-
|
|
146
|
-
if (typeof _raw !== "object") throw new Error("config must be an object");
|
|
147
|
-
var raw = {
|
|
148
|
-
tenantAlias: (_raw == null ? void 0 : _raw["tenantAlias"]) || window.squatchTenant,
|
|
149
|
-
domain: (_raw == null ? void 0 : _raw["domain"]) || ((_window$squatchConfig = window.squatchConfig) == null ? void 0 : _window$squatchConfig.domain),
|
|
150
|
-
npmCdn: (_raw == null ? void 0 : _raw["npmCdn"]) || ((_window$squatchConfig2 = window.squatchConfig) == null ? void 0 : _window$squatchConfig2.npmCdn),
|
|
151
|
-
debug: (_raw == null ? void 0 : _raw["debug"]) || ((_window$squatchConfig3 = window.squatchConfig) == null ? void 0 : _window$squatchConfig3.debug)
|
|
152
|
-
};
|
|
153
|
-
if (typeof raw.tenantAlias !== "string") throw new Error("tenantAlias not provided");
|
|
154
|
-
var tenantAlias = raw.tenantAlias;
|
|
155
|
-
var domain = typeof raw.domain === "string" && raw.domain || DEFAULT_DOMAIN;
|
|
156
|
-
var debug = typeof raw.debug === "boolean" && raw.debug || false;
|
|
157
|
-
var npmCdn = typeof raw.npmCdn === "string" && raw.npmCdn || DEFAULT_NPM_CDN;
|
|
158
|
-
return {
|
|
159
|
-
tenantAlias,
|
|
160
|
-
domain,
|
|
161
|
-
debug,
|
|
162
|
-
npmCdn
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
function isObject$1(obj) {
|
|
166
|
-
return typeof obj === "object" && !Array.isArray(obj) && obj !== null;
|
|
167
|
-
}
|
|
168
|
-
function validateLocale(locale) {
|
|
169
|
-
if (locale && /^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(locale)) {
|
|
170
|
-
return locale;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
function validateWidgetConfig(raw) {
|
|
174
|
-
if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
|
|
175
|
-
if (!(raw != null && raw["user"])) throw new Error("Required properties missing.");
|
|
176
|
-
return raw;
|
|
177
|
-
}
|
|
178
|
-
function validatePasswordlessConfig(raw) {
|
|
179
|
-
if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
|
|
180
|
-
return raw;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
189
|
var RENDER_WIDGET_QUERY = "\n query renderWidget ($user: UserIdInput, $engagementMedium: UserEngagementMedium, $widgetType: WidgetType, $locale: RSLocale) {\n renderWidget(user: $user, engagementMedium: $engagementMedium, widgetType: $widgetType, locale: $locale) {\n template\n user {\n id\n accountId\n }\n jsOptions\n widgetConfig {\n values\n }\n }\n }\n";
|
|
184
190
|
|
|
185
191
|
/**
|
|
@@ -362,14 +368,14 @@ class AnalyticsApi {
|
|
|
362
368
|
*
|
|
363
369
|
*/
|
|
364
370
|
constructor(config) {
|
|
365
|
-
var
|
|
371
|
+
var _getConfig;
|
|
366
372
|
|
|
367
373
|
this.domain = void 0;
|
|
368
374
|
var raw = config;
|
|
369
375
|
|
|
370
376
|
var clean = _validateAnalyticsConfig(raw);
|
|
371
377
|
|
|
372
|
-
this.domain = (clean == null ? void 0 : clean["domain"]) || ((
|
|
378
|
+
this.domain = (clean == null ? void 0 : clean["domain"]) || ((_getConfig = getConfig()) == null ? void 0 : _getConfig.domain) || DEFAULT_DOMAIN;
|
|
373
379
|
}
|
|
374
380
|
|
|
375
381
|
pushAnalyticsLoadEvent(params) {
|
|
@@ -405,7 +411,7 @@ function _validateAnalyticsConfig(raw) {
|
|
|
405
411
|
// @ts-check
|
|
406
412
|
/** @hidden */
|
|
407
413
|
|
|
408
|
-
var _log$
|
|
414
|
+
var _log$8 = debug.debug("squatch-js:widget");
|
|
409
415
|
/*
|
|
410
416
|
* The Widget class is the base class for the different widget types available
|
|
411
417
|
*
|
|
@@ -426,7 +432,7 @@ class Widget {
|
|
|
426
432
|
this.npmCdn = void 0;
|
|
427
433
|
this.container = void 0;
|
|
428
434
|
|
|
429
|
-
_log$
|
|
435
|
+
_log$8("widget initializing ...");
|
|
430
436
|
|
|
431
437
|
this.content = params.content === "error" ? this._error(params.rsCode) : params.content;
|
|
432
438
|
this.type = params.type;
|
|
@@ -436,7 +442,7 @@ class Widget {
|
|
|
436
442
|
domain: params.domain
|
|
437
443
|
});
|
|
438
444
|
this.context = params.context;
|
|
439
|
-
this.container = params.container;
|
|
445
|
+
this.container = params.context.container;
|
|
440
446
|
}
|
|
441
447
|
|
|
442
448
|
_findElement() {
|
|
@@ -446,22 +452,22 @@ class Widget {
|
|
|
446
452
|
// selector is a string
|
|
447
453
|
element = document.querySelector(this.container);
|
|
448
454
|
|
|
449
|
-
_log$
|
|
455
|
+
_log$8("loading widget with selector", element); // selector is an HTML element
|
|
450
456
|
|
|
451
457
|
} else if (this.container instanceof HTMLElement) {
|
|
452
458
|
element = this.container;
|
|
453
459
|
|
|
454
|
-
_log$
|
|
460
|
+
_log$8("loading widget with container", element); // garbage container found
|
|
455
461
|
|
|
456
462
|
} else if (this.container) {
|
|
457
463
|
element = null;
|
|
458
464
|
|
|
459
|
-
_log$
|
|
465
|
+
_log$8("container must be an HTMLElement or string", this.container); // find element on page
|
|
460
466
|
|
|
461
467
|
} else {
|
|
462
468
|
element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed");
|
|
463
469
|
|
|
464
|
-
_log$
|
|
470
|
+
_log$8("loading widget with default selector", element);
|
|
465
471
|
}
|
|
466
472
|
|
|
467
473
|
if (!(element instanceof HTMLElement)) throw new Error("element with selector '" + (this.container || "#squatchembed or .squatchembed") + "' not found.'");
|
|
@@ -519,9 +525,9 @@ class Widget {
|
|
|
519
525
|
}
|
|
520
526
|
|
|
521
527
|
(_this$analyticsApi$pu = this.analyticsApi.pushAnalyticsLoadEvent(params)) == null ? void 0 : _this$analyticsApi$pu.then(response => {
|
|
522
|
-
_log$
|
|
528
|
+
_log$8(params.engagementMedium + " loaded event recorded.");
|
|
523
529
|
}).catch(ex => {
|
|
524
|
-
_log$
|
|
530
|
+
_log$8("ERROR: pushAnalyticsLoadEvent() " + ex);
|
|
525
531
|
});
|
|
526
532
|
}
|
|
527
533
|
|
|
@@ -534,9 +540,9 @@ class Widget {
|
|
|
534
540
|
engagementMedium: sqh.mode.widgetMode,
|
|
535
541
|
shareMedium: medium
|
|
536
542
|
}).then(response => {
|
|
537
|
-
_log$
|
|
543
|
+
_log$8(sqh.mode.widgetMode + " share " + medium + " event recorded. " + response);
|
|
538
544
|
}).catch(ex => {
|
|
539
|
-
_log$
|
|
545
|
+
_log$8("ERROR: pushAnalyticsShareClickedEvent() " + ex);
|
|
540
546
|
});
|
|
541
547
|
}
|
|
542
548
|
} // TODO: CA: Refactor how error templates are shown
|
|
@@ -658,7 +664,7 @@ class Widget {
|
|
|
658
664
|
message
|
|
659
665
|
} = _ref3;
|
|
660
666
|
|
|
661
|
-
_log$
|
|
667
|
+
_log$8("" + message);
|
|
662
668
|
});
|
|
663
669
|
}
|
|
664
670
|
|
|
@@ -685,7 +691,7 @@ class Widget {
|
|
|
685
691
|
}
|
|
686
692
|
|
|
687
693
|
function delay(duration) {
|
|
688
|
-
return new Promise(
|
|
694
|
+
return new Promise(resolve => {
|
|
689
695
|
setTimeout(resolve, duration);
|
|
690
696
|
});
|
|
691
697
|
}
|
|
@@ -715,7 +721,7 @@ function domready(targetDoc, fn) {
|
|
|
715
721
|
|
|
716
722
|
// @ts-check
|
|
717
723
|
|
|
718
|
-
var _log$
|
|
724
|
+
var _log$7 = debug.debug("squatch-js:EMBEDwidget");
|
|
719
725
|
/**
|
|
720
726
|
* An EmbedWidget is displayed inline in part of your page.
|
|
721
727
|
*
|
|
@@ -734,6 +740,7 @@ class EmbedWidget extends Widget {
|
|
|
734
740
|
super(params);
|
|
735
741
|
this.show = this.open;
|
|
736
742
|
this.hide = this.close;
|
|
743
|
+
if (container) this.container = container;
|
|
737
744
|
}
|
|
738
745
|
|
|
739
746
|
async load() {
|
|
@@ -745,7 +752,9 @@ class EmbedWidget extends Widget {
|
|
|
745
752
|
if (element.shadowRoot) {
|
|
746
753
|
var _element$shadowRoot$l;
|
|
747
754
|
|
|
748
|
-
if (((_element$shadowRoot$l = element.shadowRoot.lastChild) == null ? void 0 : _element$shadowRoot$l.nodeName) === "IFRAME")
|
|
755
|
+
if (((_element$shadowRoot$l = element.shadowRoot.lastChild) == null ? void 0 : _element$shadowRoot$l.nodeName) === "IFRAME") {
|
|
756
|
+
element.shadowRoot.replaceChild(frame, element.shadowRoot.lastChild);
|
|
757
|
+
} else {
|
|
749
758
|
element.shadowRoot.appendChild(frame);
|
|
750
759
|
}
|
|
751
760
|
} // Widget reloaded - replace existing element
|
|
@@ -789,12 +798,12 @@ class EmbedWidget extends Widget {
|
|
|
789
798
|
}
|
|
790
799
|
});
|
|
791
800
|
var container = await this._findInnerContainer(frame);
|
|
792
|
-
ro.observe(container);
|
|
801
|
+
ro.observe(container);
|
|
793
802
|
|
|
794
|
-
if (
|
|
803
|
+
if (this._shouldFireLoadEvent()) {
|
|
795
804
|
this._loadEvent(_sqh);
|
|
796
805
|
|
|
797
|
-
_log$
|
|
806
|
+
_log$7("loaded");
|
|
798
807
|
}
|
|
799
808
|
});
|
|
800
809
|
}
|
|
@@ -808,7 +817,7 @@ class EmbedWidget extends Widget {
|
|
|
808
817
|
|
|
809
818
|
var frame = this._findFrame();
|
|
810
819
|
|
|
811
|
-
if (!frame) return _log$
|
|
820
|
+
if (!frame) return _log$7("no target element to open");
|
|
812
821
|
|
|
813
822
|
var element = this._findElement();
|
|
814
823
|
|
|
@@ -819,15 +828,17 @@ class EmbedWidget extends Widget {
|
|
|
819
828
|
|
|
820
829
|
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
830
|
|
|
822
|
-
this.
|
|
831
|
+
if (this.context.user) {
|
|
832
|
+
this._loadEvent(_sqh);
|
|
823
833
|
|
|
824
|
-
|
|
834
|
+
_log$7("loaded");
|
|
835
|
+
}
|
|
825
836
|
}
|
|
826
837
|
|
|
827
838
|
close() {
|
|
828
839
|
var frame = this._findFrame();
|
|
829
840
|
|
|
830
|
-
if (!frame) return _log$
|
|
841
|
+
if (!frame) return _log$7("no target element to close");
|
|
831
842
|
|
|
832
843
|
var element = this._findElement();
|
|
833
844
|
|
|
@@ -835,7 +846,7 @@ class EmbedWidget extends Widget {
|
|
|
835
846
|
element.style.height = "0";
|
|
836
847
|
element.style["overflow-y"] = "hidden";
|
|
837
848
|
|
|
838
|
-
_log$
|
|
849
|
+
_log$7("Embed widget closed");
|
|
839
850
|
}
|
|
840
851
|
|
|
841
852
|
_error(rs, mode, style) {
|
|
@@ -850,11 +861,18 @@ class EmbedWidget extends Widget {
|
|
|
850
861
|
return super._error(rs, mode, style);
|
|
851
862
|
}
|
|
852
863
|
|
|
864
|
+
_shouldFireLoadEvent() {
|
|
865
|
+
var noContainer = !this.container;
|
|
866
|
+
var isComponent = this.container instanceof HTMLElement && this.container.tagName.startsWith("SQUATCH-");
|
|
867
|
+
var isVerified = !!this.context.user;
|
|
868
|
+
return isVerified && (noContainer || isComponent);
|
|
869
|
+
}
|
|
870
|
+
|
|
853
871
|
}
|
|
854
872
|
|
|
855
873
|
// @ts-check
|
|
856
874
|
|
|
857
|
-
var _log$
|
|
875
|
+
var _log$6 = debug.debug("squatch-js:POPUPwidget");
|
|
858
876
|
|
|
859
877
|
var popupId = 0;
|
|
860
878
|
/**
|
|
@@ -901,9 +919,9 @@ class PopupWidget extends Widget {
|
|
|
901
919
|
triggerElement
|
|
902
920
|
/* HTMLButton */
|
|
903
921
|
= document.querySelector(this.trigger);
|
|
904
|
-
if (this.trigger && !triggerElement) _log$
|
|
922
|
+
if (this.trigger && !triggerElement) _log$6("No element found with trigger selector", this.trigger);
|
|
905
923
|
} catch (_unused) {
|
|
906
|
-
_log$
|
|
924
|
+
_log$6("Not a valid selector", this.trigger);
|
|
907
925
|
} // Trigger is optional
|
|
908
926
|
|
|
909
927
|
|
|
@@ -911,16 +929,7 @@ class PopupWidget extends Widget {
|
|
|
911
929
|
triggerElement.onclick = () => {
|
|
912
930
|
this.open();
|
|
913
931
|
};
|
|
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
|
-
|
|
932
|
+
}
|
|
924
933
|
}
|
|
925
934
|
|
|
926
935
|
_createPopupDialog() {
|
|
@@ -929,6 +938,7 @@ class PopupWidget extends Widget {
|
|
|
929
938
|
dialog.setAttribute("style", "width: 100%; max-width: 500px; border: none; padding: 0;");
|
|
930
939
|
|
|
931
940
|
var onClick = e => {
|
|
941
|
+
e.stopPropagation();
|
|
932
942
|
if (e.target === dialog) dialog.close();
|
|
933
943
|
};
|
|
934
944
|
|
|
@@ -972,7 +982,7 @@ class PopupWidget extends Widget {
|
|
|
972
982
|
frameDoc.write("<script src=\"" + this.npmCdn + "/resize-observer-polyfill@1.5.x\"></script>");
|
|
973
983
|
frameDoc.close();
|
|
974
984
|
|
|
975
|
-
_log$
|
|
985
|
+
_log$6("Popup template loaded into iframe");
|
|
976
986
|
|
|
977
987
|
this._setupResizeHandler(frame);
|
|
978
988
|
}
|
|
@@ -1031,9 +1041,11 @@ class PopupWidget extends Widget {
|
|
|
1031
1041
|
|
|
1032
1042
|
(_frame$contentDocumen = frame.contentDocument) == null ? void 0 : _frame$contentDocumen.dispatchEvent(new CustomEvent("sq:refresh"));
|
|
1033
1043
|
|
|
1034
|
-
this.
|
|
1044
|
+
if (this.context.user) {
|
|
1045
|
+
this._loadEvent(_sqh);
|
|
1035
1046
|
|
|
1036
|
-
|
|
1047
|
+
_log$6("Popup opened");
|
|
1048
|
+
}
|
|
1037
1049
|
});
|
|
1038
1050
|
}
|
|
1039
1051
|
|
|
@@ -1044,7 +1056,7 @@ class PopupWidget extends Widget {
|
|
|
1044
1056
|
if (!dialog) throw new Error("Could not determine container div");
|
|
1045
1057
|
dialog.close();
|
|
1046
1058
|
|
|
1047
|
-
_log$
|
|
1059
|
+
_log$6("Popup closed");
|
|
1048
1060
|
}
|
|
1049
1061
|
|
|
1050
1062
|
_clickedOutside(_ref) {
|
|
@@ -1065,7 +1077,7 @@ class PopupWidget extends Widget {
|
|
|
1065
1077
|
|
|
1066
1078
|
}
|
|
1067
1079
|
|
|
1068
|
-
var _log$
|
|
1080
|
+
var _log$5 = debug.debug("squatch-js:widgets");
|
|
1069
1081
|
/**
|
|
1070
1082
|
* `Widgets` is a factory for creating widgets. It's possible to build your own widgets using the
|
|
1071
1083
|
* {@link WidgetApi} but most people will prefer to use these easy methods.
|
|
@@ -1154,7 +1166,7 @@ class Widgets {
|
|
|
1154
1166
|
user: response.user
|
|
1155
1167
|
};
|
|
1156
1168
|
} catch (err) {
|
|
1157
|
-
_log$
|
|
1169
|
+
_log$5(err);
|
|
1158
1170
|
|
|
1159
1171
|
if (err.apiErrorCode) {
|
|
1160
1172
|
this._renderErrorWidget(err, config.engagementMedium);
|
|
@@ -1220,7 +1232,7 @@ class Widgets {
|
|
|
1220
1232
|
var response = await this.api.squatchReferralCookie();
|
|
1221
1233
|
input(response);
|
|
1222
1234
|
} catch (e) {
|
|
1223
|
-
_log$
|
|
1235
|
+
_log$5("Autofill error", e);
|
|
1224
1236
|
|
|
1225
1237
|
throw new Error(e);
|
|
1226
1238
|
}
|
|
@@ -1236,7 +1248,7 @@ class Widgets {
|
|
|
1236
1248
|
// Only use the first element found
|
|
1237
1249
|
elem = elems[0];
|
|
1238
1250
|
} else {
|
|
1239
|
-
_log$
|
|
1251
|
+
_log$5("Element id/class or function missing");
|
|
1240
1252
|
|
|
1241
1253
|
throw new Error("Element id/class or function missing");
|
|
1242
1254
|
}
|
|
@@ -1262,7 +1274,7 @@ class Widgets {
|
|
|
1262
1274
|
_renderWidget(response, config, context) {
|
|
1263
1275
|
var _opts$widget;
|
|
1264
1276
|
|
|
1265
|
-
_log$
|
|
1277
|
+
_log$5("Rendering Widget...");
|
|
1266
1278
|
|
|
1267
1279
|
if (!response) throw new Error("Unable to get a response");
|
|
1268
1280
|
var widget;
|
|
@@ -1285,16 +1297,16 @@ class Widgets {
|
|
|
1285
1297
|
if (rule.widgetType !== "CONVERSION_WIDGET" || (_response$user = response.user) != null && (_response$user$referr = _response$user.referredBy) != null && _response$user$referr.code) {
|
|
1286
1298
|
displayOnLoad = rule.displayOnLoad;
|
|
1287
1299
|
|
|
1288
|
-
_log$
|
|
1300
|
+
_log$5("Display " + rule.widgetType + " on " + rule.url);
|
|
1289
1301
|
} else {
|
|
1290
|
-
_log$
|
|
1302
|
+
_log$5("Don't display " + rule.widgetType + " when no referral on widget rule match " + rule.url);
|
|
1291
1303
|
}
|
|
1292
1304
|
}
|
|
1293
1305
|
});
|
|
1294
1306
|
}
|
|
1295
1307
|
|
|
1296
1308
|
if (opts.fuelTankAutofillUrls) {
|
|
1297
|
-
_log$
|
|
1309
|
+
_log$5("We found a fuel tank autofill!");
|
|
1298
1310
|
|
|
1299
1311
|
opts.fuelTankAutofillUrls.forEach(_ref => {
|
|
1300
1312
|
var {
|
|
@@ -1305,7 +1317,7 @@ class Widgets {
|
|
|
1305
1317
|
if (Widgets._matchesUrl(url)) {
|
|
1306
1318
|
var _response$user2, _response$user2$refer;
|
|
1307
1319
|
|
|
1308
|
-
_log$
|
|
1320
|
+
_log$5("Fuel Tank URL matches");
|
|
1309
1321
|
|
|
1310
1322
|
if ((_response$user2 = response.user) != null && (_response$user2$refer = _response$user2.referredBy) != null && _response$user2$refer.code) {
|
|
1311
1323
|
var formAutofill = document.querySelector(formSelector);
|
|
@@ -1315,7 +1327,7 @@ class Widgets {
|
|
|
1315
1327
|
|
|
1316
1328
|
formAutofill.value = ((_response$user$referr2 = response.user.referredBy.referredReward) == null ? void 0 : _response$user$referr2.fuelTankCode) || "";
|
|
1317
1329
|
} else {
|
|
1318
|
-
_log$
|
|
1330
|
+
_log$5(new Error("Element with id/class " + formSelector + " was not found."));
|
|
1319
1331
|
}
|
|
1320
1332
|
}
|
|
1321
1333
|
}
|
|
@@ -1323,15 +1335,9 @@ class Widgets {
|
|
|
1323
1335
|
}
|
|
1324
1336
|
|
|
1325
1337
|
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();
|
|
1338
|
+
widget = this._renderEmbedWidget(params);
|
|
1330
1339
|
} else {
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
widget = new PopupWidget(params);
|
|
1334
|
-
widget.load();
|
|
1340
|
+
widget = this._renderPopupWidget(params);
|
|
1335
1341
|
if (displayOnLoad) widget.open();
|
|
1336
1342
|
}
|
|
1337
1343
|
|
|
@@ -1344,8 +1350,8 @@ class Widgets {
|
|
|
1344
1350
|
return widget;
|
|
1345
1351
|
}
|
|
1346
1352
|
|
|
1347
|
-
_renderEmbedWidget(params
|
|
1348
|
-
var widget = new EmbedWidget(params, container);
|
|
1353
|
+
_renderEmbedWidget(params) {
|
|
1354
|
+
var widget = new EmbedWidget(params, params.context.container);
|
|
1349
1355
|
widget.load();
|
|
1350
1356
|
return widget;
|
|
1351
1357
|
}
|
|
@@ -1368,7 +1374,7 @@ class Widgets {
|
|
|
1368
1374
|
message
|
|
1369
1375
|
} = props;
|
|
1370
1376
|
|
|
1371
|
-
_log$
|
|
1377
|
+
_log$5(new Error(apiErrorCode + " (" + rsCode + ") " + message));
|
|
1372
1378
|
|
|
1373
1379
|
var params = {
|
|
1374
1380
|
content: "error",
|
|
@@ -1484,18 +1490,26 @@ function _validateTrackOptions(raw) {
|
|
|
1484
1490
|
|
|
1485
1491
|
/** @hidden */
|
|
1486
1492
|
function asyncLoad() {
|
|
1487
|
-
var
|
|
1488
|
-
var
|
|
1493
|
+
var impactNamespace = "impactTBD";
|
|
1494
|
+
var namespace = window[impactNamespace] ? impactNamespace : "squatch";
|
|
1495
|
+
console.log({
|
|
1496
|
+
namespace
|
|
1497
|
+
});
|
|
1498
|
+
var loaded = window[namespace] || null;
|
|
1499
|
+
var cached = window["_" + namespace] || null;
|
|
1489
1500
|
|
|
1490
1501
|
if (loaded && cached) {
|
|
1491
1502
|
var ready = cached.ready || [];
|
|
1503
|
+
setTimeout(() => window["impactTBD"] = window.squatch, 0);
|
|
1492
1504
|
ready.forEach(cb => setTimeout(() => cb(), 0));
|
|
1493
|
-
setTimeout(() =>
|
|
1505
|
+
setTimeout(() => {
|
|
1506
|
+
window.squatch._auto();
|
|
1507
|
+
}, 0); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
|
|
1494
1508
|
|
|
1495
|
-
window
|
|
1509
|
+
window["_" + namespace] = undefined;
|
|
1496
1510
|
|
|
1497
1511
|
try {
|
|
1498
|
-
delete window
|
|
1512
|
+
delete window["_" + namespace];
|
|
1499
1513
|
} catch (e) {
|
|
1500
1514
|
throw e;
|
|
1501
1515
|
}
|
|
@@ -1504,7 +1518,7 @@ function asyncLoad() {
|
|
|
1504
1518
|
|
|
1505
1519
|
/** @hidden */
|
|
1506
1520
|
|
|
1507
|
-
var _log$
|
|
1521
|
+
var _log$4 = debug.debug("squatch-js");
|
|
1508
1522
|
|
|
1509
1523
|
var isObject = item => typeof item === "object" && !Array.isArray(item);
|
|
1510
1524
|
|
|
@@ -1557,7 +1571,7 @@ function _pushCookie() {
|
|
|
1557
1571
|
try {
|
|
1558
1572
|
paramsJSON = JSON.parse(b64decode(refParam));
|
|
1559
1573
|
} catch (error) {
|
|
1560
|
-
_log$
|
|
1574
|
+
_log$4("Unable to decode params", error); // don't merge invalid params
|
|
1561
1575
|
|
|
1562
1576
|
|
|
1563
1577
|
return;
|
|
@@ -1566,26 +1580,26 @@ function _pushCookie() {
|
|
|
1566
1580
|
try {
|
|
1567
1581
|
existingCookie = JSON.parse(b64decode(Cookies__default['default'].get("_saasquatch")));
|
|
1568
1582
|
|
|
1569
|
-
_log$
|
|
1583
|
+
_log$4("existing cookie", existingCookie);
|
|
1570
1584
|
} catch (error) {
|
|
1571
|
-
_log$
|
|
1585
|
+
_log$4("Unable to retrieve cookie", error);
|
|
1572
1586
|
} // don't merge if there's no existing object
|
|
1573
1587
|
|
|
1574
1588
|
|
|
1575
1589
|
try {
|
|
1576
1590
|
var domain = getTopDomain();
|
|
1577
1591
|
|
|
1578
|
-
_log$
|
|
1592
|
+
_log$4("domain retrieved:", domain);
|
|
1579
1593
|
|
|
1580
1594
|
if (existingCookie) {
|
|
1581
1595
|
var newCookie = deepMerge(existingCookie, paramsJSON);
|
|
1582
1596
|
reEncodedCookie = b64encode(JSON.stringify(newCookie));
|
|
1583
1597
|
|
|
1584
|
-
_log$
|
|
1598
|
+
_log$4("cookie to store:", newCookie);
|
|
1585
1599
|
} else {
|
|
1586
1600
|
reEncodedCookie = b64encode(JSON.stringify(paramsJSON));
|
|
1587
1601
|
|
|
1588
|
-
_log$
|
|
1602
|
+
_log$4("cookie to store:", paramsJSON);
|
|
1589
1603
|
}
|
|
1590
1604
|
|
|
1591
1605
|
Cookies__default['default'].set("_saasquatch", reEncodedCookie, {
|
|
@@ -1596,14 +1610,14 @@ function _pushCookie() {
|
|
|
1596
1610
|
path: "/"
|
|
1597
1611
|
});
|
|
1598
1612
|
} catch (error) {
|
|
1599
|
-
_log$
|
|
1613
|
+
_log$4("Unable to set cookie", error);
|
|
1600
1614
|
}
|
|
1601
1615
|
}
|
|
1602
1616
|
}
|
|
1603
1617
|
|
|
1604
1618
|
/** @hidden */
|
|
1605
1619
|
|
|
1606
|
-
var _log$
|
|
1620
|
+
var _log$3 = debug.debug("squatch-js");
|
|
1607
1621
|
|
|
1608
1622
|
function _getAutoConfig(configIn) {
|
|
1609
1623
|
var queryString = window.location.search;
|
|
@@ -1611,7 +1625,7 @@ function _getAutoConfig(configIn) {
|
|
|
1611
1625
|
var refParam = urlParams.get("_saasquatchExtra") || "";
|
|
1612
1626
|
|
|
1613
1627
|
if (!refParam) {
|
|
1614
|
-
_log$
|
|
1628
|
+
_log$3("No _saasquatchExtra param");
|
|
1615
1629
|
|
|
1616
1630
|
return;
|
|
1617
1631
|
}
|
|
@@ -1621,7 +1635,7 @@ function _getAutoConfig(configIn) {
|
|
|
1621
1635
|
try {
|
|
1622
1636
|
raw = JSON.parse(b64decode(refParam));
|
|
1623
1637
|
} catch (e) {
|
|
1624
|
-
_log$
|
|
1638
|
+
_log$3("Unable to decode _saasquatchExtra config");
|
|
1625
1639
|
|
|
1626
1640
|
return;
|
|
1627
1641
|
}
|
|
@@ -1633,7 +1647,7 @@ function _getAutoConfig(configIn) {
|
|
|
1633
1647
|
} = convertExtraToConfig(raw);
|
|
1634
1648
|
|
|
1635
1649
|
if (!domain || !tenantAlias || !widgetConfig) {
|
|
1636
|
-
_log$
|
|
1650
|
+
_log$3("_saasquatchExtra did not have an expected structure");
|
|
1637
1651
|
|
|
1638
1652
|
return undefined;
|
|
1639
1653
|
}
|
|
@@ -1676,7 +1690,7 @@ function convertExtraToConfig(obj) {
|
|
|
1676
1690
|
};
|
|
1677
1691
|
}
|
|
1678
1692
|
|
|
1679
|
-
var _log$
|
|
1693
|
+
var _log$2 = debug.debug("squatch-js:decodeJwt");
|
|
1680
1694
|
|
|
1681
1695
|
function decodeUserJwt(tokenStr) {
|
|
1682
1696
|
try {
|
|
@@ -1687,13 +1701,13 @@ function decodeUserJwt(tokenStr) {
|
|
|
1687
1701
|
var jsonStr = b64decode(base64Url);
|
|
1688
1702
|
return (_JSON$parse = JSON.parse(jsonStr)) == null ? void 0 : _JSON$parse.user;
|
|
1689
1703
|
} catch (e) {
|
|
1690
|
-
_log$
|
|
1704
|
+
_log$2(e);
|
|
1691
1705
|
|
|
1692
1706
|
return null;
|
|
1693
1707
|
}
|
|
1694
1708
|
}
|
|
1695
1709
|
|
|
1696
|
-
debug__default['default']("
|
|
1710
|
+
var _log$1 = debug__default['default']("squatch-js:DeclarativeWidget");
|
|
1697
1711
|
/**
|
|
1698
1712
|
* Abstract class for building web-components that render SaaSquatch widgets to the DOM.
|
|
1699
1713
|
* @abstract
|
|
@@ -1772,16 +1786,17 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1772
1786
|
content: template,
|
|
1773
1787
|
context: {
|
|
1774
1788
|
type: config.type,
|
|
1789
|
+
user: config.user,
|
|
1790
|
+
container: this.container || this,
|
|
1775
1791
|
engagementMedium: this.type
|
|
1776
1792
|
},
|
|
1777
1793
|
type: this.widgetType,
|
|
1778
1794
|
domain: ((_this$config = this.config) == null ? void 0 : _this$config.domain) || DEFAULT_DOMAIN,
|
|
1779
|
-
npmCdn: DEFAULT_NPM_CDN
|
|
1780
|
-
container: this.container || this
|
|
1795
|
+
npmCdn: DEFAULT_NPM_CDN
|
|
1781
1796
|
};
|
|
1782
1797
|
|
|
1783
1798
|
if (this.type === "EMBED") {
|
|
1784
|
-
return new EmbedWidget(params);
|
|
1799
|
+
return new EmbedWidget(params, params.context.container);
|
|
1785
1800
|
} else {
|
|
1786
1801
|
return new PopupWidget(params, this.firstChild ? null : undefined);
|
|
1787
1802
|
}
|
|
@@ -1794,16 +1809,16 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1794
1809
|
api: this.widgetApi,
|
|
1795
1810
|
content: "error",
|
|
1796
1811
|
context: {
|
|
1797
|
-
type: "error"
|
|
1812
|
+
type: "error",
|
|
1813
|
+
container: this.container || this
|
|
1798
1814
|
},
|
|
1799
1815
|
type: "ERROR_WIDGET",
|
|
1800
1816
|
domain: ((_this$config2 = this.config) == null ? void 0 : _this$config2.domain) || DEFAULT_DOMAIN,
|
|
1801
|
-
npmCdn: DEFAULT_NPM_CDN
|
|
1802
|
-
container: this.container || this
|
|
1817
|
+
npmCdn: DEFAULT_NPM_CDN
|
|
1803
1818
|
};
|
|
1804
1819
|
|
|
1805
1820
|
if (this.type === "EMBED") {
|
|
1806
|
-
return new EmbedWidget(params);
|
|
1821
|
+
return new EmbedWidget(params, params.context.container);
|
|
1807
1822
|
} else {
|
|
1808
1823
|
return new PopupWidget(params, this.firstChild ? null : undefined);
|
|
1809
1824
|
}
|
|
@@ -1815,8 +1830,8 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1815
1830
|
this.attachShadow({
|
|
1816
1831
|
mode: "open"
|
|
1817
1832
|
}).innerHTML = "<style>:host { display: contents; }</style><slot></slot>";
|
|
1818
|
-
this.config =
|
|
1819
|
-
this.token =
|
|
1833
|
+
this.config = getConfig();
|
|
1834
|
+
this.token = getToken();
|
|
1820
1835
|
this.tenant = window.squatchTenant;
|
|
1821
1836
|
this.container = this;
|
|
1822
1837
|
}
|
|
@@ -1824,7 +1839,7 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1824
1839
|
_setupApis(config) {
|
|
1825
1840
|
var _this$config3, _this$config4;
|
|
1826
1841
|
|
|
1827
|
-
if (!this.tenant) throw new Error("
|
|
1842
|
+
if (!this.tenant) throw new Error("tenantAlias not provided");
|
|
1828
1843
|
this.widgetApi = new WidgetApi({
|
|
1829
1844
|
tenantAlias: (config == null ? void 0 : config.tenantAlias) || this.tenant,
|
|
1830
1845
|
domain: (config == null ? void 0 : config.domain) || ((_this$config3 = this.config) == null ? void 0 : _this$config3.domain) || DEFAULT_DOMAIN
|
|
@@ -1835,16 +1850,14 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1835
1850
|
}
|
|
1836
1851
|
|
|
1837
1852
|
async renderPasswordlessVariant() {
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
var configs = _getAutoConfig();
|
|
1853
|
+
this._setupApis();
|
|
1841
1854
|
|
|
1842
|
-
|
|
1855
|
+
_log$1("Rendering as an Instant Access widget");
|
|
1843
1856
|
|
|
1844
1857
|
return await this.widgetApi.render({
|
|
1845
|
-
engagementMedium:
|
|
1846
|
-
widgetType:
|
|
1847
|
-
locale:
|
|
1858
|
+
engagementMedium: this.type,
|
|
1859
|
+
widgetType: this.widgetType,
|
|
1860
|
+
locale: this.locale
|
|
1848
1861
|
}).then(res => this._setWidget(res.template, {
|
|
1849
1862
|
type: "passwordless"
|
|
1850
1863
|
})).catch(this.setErrorWidget);
|
|
@@ -1854,7 +1867,13 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1854
1867
|
this._setupApis();
|
|
1855
1868
|
|
|
1856
1869
|
var userObj = decodeUserJwt(this.token);
|
|
1857
|
-
|
|
1870
|
+
|
|
1871
|
+
if (!userObj) {
|
|
1872
|
+
return this.setErrorWidget(Error("No user object in token."));
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
_log$1("Rendering as a Verified widget");
|
|
1876
|
+
|
|
1858
1877
|
var widgetInstance = await this.widgetApi.upsertUser({
|
|
1859
1878
|
user: userObj,
|
|
1860
1879
|
locale: this.locale,
|
|
@@ -1862,7 +1881,8 @@ class DeclarativeWidget extends HTMLElement {
|
|
|
1862
1881
|
widgetType: this.widgetType,
|
|
1863
1882
|
jwt: this.token
|
|
1864
1883
|
}).then(res => this._setWidget(res.template, {
|
|
1865
|
-
type: "upsert"
|
|
1884
|
+
type: "upsert",
|
|
1885
|
+
user: userObj
|
|
1866
1886
|
})).catch(this.setErrorWidget);
|
|
1867
1887
|
return widgetInstance;
|
|
1868
1888
|
}
|
|
@@ -1991,9 +2011,8 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
1991
2011
|
|
|
1992
2012
|
this.type = "POPUP";
|
|
1993
2013
|
this.addEventListener("click", e => {
|
|
1994
|
-
e.stopPropagation();
|
|
1995
|
-
|
|
1996
|
-
if (e.target.tagName !== "SQUATCH-POPUP") this.open();
|
|
2014
|
+
e.stopPropagation();
|
|
2015
|
+
this.open();
|
|
1997
2016
|
});
|
|
1998
2017
|
}
|
|
1999
2018
|
|
|
@@ -2013,13 +2032,25 @@ class DeclarativePopupWidget extends DeclarativeWidget {
|
|
|
2013
2032
|
}
|
|
2014
2033
|
|
|
2015
2034
|
async connectedCallback() {
|
|
2035
|
+
this.container = this.getAttribute("container") || this;
|
|
2016
2036
|
await this.renderWidget();
|
|
2017
2037
|
if (this.getAttribute("open") !== null) this.open();
|
|
2018
2038
|
}
|
|
2019
2039
|
|
|
2020
2040
|
}
|
|
2021
|
-
|
|
2022
|
-
|
|
2041
|
+
|
|
2042
|
+
class SquatchEmbed extends DeclarativeEmbedWidget {}
|
|
2043
|
+
|
|
2044
|
+
class SquatchPopup extends DeclarativePopupWidget {}
|
|
2045
|
+
|
|
2046
|
+
class ImpactEmbed extends DeclarativeEmbedWidget {}
|
|
2047
|
+
|
|
2048
|
+
class ImpactPopup extends DeclarativePopupWidget {}
|
|
2049
|
+
|
|
2050
|
+
window.customElements.define("squatch-embed", SquatchEmbed);
|
|
2051
|
+
window.customElements.define("impact-embed", ImpactEmbed);
|
|
2052
|
+
window.customElements.define("squatch-popup", SquatchPopup);
|
|
2053
|
+
window.customElements.define("impact-popup", ImpactPopup);
|
|
2023
2054
|
|
|
2024
2055
|
// @ts-check
|
|
2025
2056
|
function help() {
|
|
@@ -2146,6 +2177,8 @@ function init(configIn) {
|
|
|
2146
2177
|
|
|
2147
2178
|
if (config.tenantAlias.match("^test") || config.debug) {
|
|
2148
2179
|
debug.debug.enable("squatch-js*");
|
|
2180
|
+
} else {
|
|
2181
|
+
debug.debug.disable();
|
|
2149
2182
|
}
|
|
2150
2183
|
|
|
2151
2184
|
_log("initializing ...");
|