@saasquatch/squatch-js 2.4.2 → 2.4.3-1
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/CHANGELOG.md +267 -285
- package/README.md +0 -1
- package/demo/sandbox.ts +7 -5
- package/demo/toolbar.tsx +1 -1
- package/dist/api/WidgetApi.d.ts +4 -4
- package/dist/squatch.d.ts +11 -1
- package/dist/squatch.esm.js +271 -86
- package/dist/squatch.esm.js.map +1 -1
- package/dist/squatch.js +272 -85
- package/dist/squatch.js.map +1 -1
- package/dist/squatch.min.js +3 -3
- package/dist/squatch.min.js.map +1 -1
- package/dist/squatch.modern.js +1 -1
- package/dist/squatch.modern.js.map +1 -1
- package/dist/stats.html +1 -1
- package/dist/types.d.ts +8 -8
- package/dist/utils/cookieUtils.d.ts +1 -0
- package/dist/utils/io.d.ts +2 -1
- package/dist/utils/utmUtils.d.ts +14 -0
- package/dist/utils/validate.d.ts +1 -0
- package/dist/widgets/Widgets.d.ts +4 -3
- package/package.json +104 -104
package/dist/squatch.js
CHANGED
|
@@ -49,6 +49,45 @@ function _extends() {
|
|
|
49
49
|
return _extends.apply(this, arguments);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
53
|
+
if (source == null) return {};
|
|
54
|
+
var target = {};
|
|
55
|
+
var sourceKeys = Object.keys(source);
|
|
56
|
+
var key, i;
|
|
57
|
+
|
|
58
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
59
|
+
key = sourceKeys[i];
|
|
60
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
61
|
+
target[key] = source[key];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return target;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function doQuery(url, query, variables, token) {
|
|
68
|
+
const headers = _extends({
|
|
69
|
+
Accept: "application/json"
|
|
70
|
+
}, token ? {
|
|
71
|
+
Authorization: `Bearer ${token}`
|
|
72
|
+
} : {}, {
|
|
73
|
+
"X-SaaSquatch-Referrer": window ? window.location.href : ""
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const request = superagent__namespace.post(url).send({
|
|
77
|
+
query,
|
|
78
|
+
variables
|
|
79
|
+
}).set(headers);
|
|
80
|
+
return thenableSuperagent(request).then(response => response, error => {
|
|
81
|
+
let json;
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
json = JSON.parse(error.response.text);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
throw json;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
52
91
|
function doGet(url, jwt = "") {
|
|
53
92
|
const headers = {
|
|
54
93
|
Accept: "application/json",
|
|
@@ -191,6 +230,10 @@ function validateWidgetConfig(raw) {
|
|
|
191
230
|
|
|
192
231
|
return raw;
|
|
193
232
|
}
|
|
233
|
+
function validatePasswordlessConfig(raw) {
|
|
234
|
+
if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
|
|
235
|
+
return raw;
|
|
236
|
+
}
|
|
194
237
|
|
|
195
238
|
/**
|
|
196
239
|
*
|
|
@@ -313,7 +356,7 @@ class WidgetApi {
|
|
|
313
356
|
|
|
314
357
|
render(params) {
|
|
315
358
|
const raw = params;
|
|
316
|
-
const clean =
|
|
359
|
+
const clean = validatePasswordlessConfig(raw);
|
|
317
360
|
const {
|
|
318
361
|
widgetType,
|
|
319
362
|
engagementMedium = "POPUP",
|
|
@@ -321,17 +364,42 @@ class WidgetApi {
|
|
|
321
364
|
user
|
|
322
365
|
} = clean;
|
|
323
366
|
const tenantAlias = encodeURIComponent(this.tenantAlias);
|
|
324
|
-
const accountId = encodeURIComponent(user.accountId);
|
|
325
|
-
const userId = encodeURIComponent(user.id);
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
367
|
+
const accountId = user ? encodeURIComponent(user.accountId) : null;
|
|
368
|
+
const userId = user ? encodeURIComponent(user.id) : null;
|
|
369
|
+
const query = `
|
|
370
|
+
query renderWidget ($user: UserIdInput, $engagementMedium: UserEngagementMedium, $widgetType: WidgetType) {
|
|
371
|
+
renderWidget(user: $user, engagementMedium: $engagementMedium, widgetType: $widgetType) {
|
|
372
|
+
template
|
|
373
|
+
user {
|
|
374
|
+
id
|
|
375
|
+
accountId
|
|
376
|
+
}
|
|
377
|
+
jsOptions
|
|
378
|
+
widgetConfig {
|
|
379
|
+
values
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
`;
|
|
384
|
+
const path = `/api/v1/${tenantAlias}/graphql`;
|
|
333
385
|
const url = this.domain + path;
|
|
334
|
-
return
|
|
386
|
+
return new Promise(async (resolve, reject) => {
|
|
387
|
+
try {
|
|
388
|
+
var _res$body, _res$body$data;
|
|
389
|
+
|
|
390
|
+
const res = await doQuery(url, query, {
|
|
391
|
+
user: userId && accountId ? {
|
|
392
|
+
id: userId,
|
|
393
|
+
accountId
|
|
394
|
+
} : null,
|
|
395
|
+
engagementMedium,
|
|
396
|
+
widgetType
|
|
397
|
+
}, jwt);
|
|
398
|
+
resolve(res == null ? void 0 : (_res$body = res.body) == null ? void 0 : (_res$body$data = _res$body.data) == null ? void 0 : _res$body$data.renderWidget);
|
|
399
|
+
} catch (e) {
|
|
400
|
+
reject(e);
|
|
401
|
+
}
|
|
402
|
+
});
|
|
335
403
|
}
|
|
336
404
|
/**
|
|
337
405
|
* An API call to send out referral invites to contacts
|
|
@@ -365,21 +433,18 @@ class WidgetApi {
|
|
|
365
433
|
/**
|
|
366
434
|
* Looks up the referral code of the current user, if there is any.
|
|
367
435
|
*
|
|
368
|
-
* @return {Promise<
|
|
436
|
+
* @return {Promise<Object>} code referral code if true.
|
|
369
437
|
*/
|
|
370
438
|
|
|
371
439
|
|
|
372
|
-
|
|
440
|
+
squatchReferralCookie() {
|
|
373
441
|
const tenantAlias = encodeURIComponent(this.tenantAlias);
|
|
374
442
|
|
|
375
|
-
const _saasquatch = Cookies__default['default'].get("_saasquatch")
|
|
443
|
+
const _saasquatch = Cookies__default['default'].get("_saasquatch");
|
|
376
444
|
|
|
377
445
|
const cookie = _saasquatch ? `?cookies=${encodeURIComponent(_saasquatch)}` : ``;
|
|
378
446
|
const url = `${this.domain}/a/${tenantAlias}/widgets/squatchcookiejson${cookie}`;
|
|
379
|
-
|
|
380
|
-
return Promise.resolve(_extends({}, response, {
|
|
381
|
-
encodedCookie: _saasquatch
|
|
382
|
-
}));
|
|
447
|
+
return doGet(url);
|
|
383
448
|
}
|
|
384
449
|
|
|
385
450
|
} // builds a param string for widgets
|
|
@@ -448,7 +513,7 @@ class AnalyticsApi {
|
|
|
448
513
|
// @ts-check
|
|
449
514
|
/** @hidden */
|
|
450
515
|
|
|
451
|
-
const _log$
|
|
516
|
+
const _log$7 = debug__default['default']("squatch-js:widget");
|
|
452
517
|
/*
|
|
453
518
|
* The Widget class is the base class for the different widget types available
|
|
454
519
|
*
|
|
@@ -461,7 +526,7 @@ const _log$6 = debug__default['default']("squatch-js:widget");
|
|
|
461
526
|
|
|
462
527
|
class Widget {
|
|
463
528
|
constructor(params) {
|
|
464
|
-
_log$
|
|
529
|
+
_log$7("widget initializing ...");
|
|
465
530
|
|
|
466
531
|
this.content = params.content === "error" ? this._error(params.rsCode) : params.content;
|
|
467
532
|
this.type = params.type;
|
|
@@ -513,9 +578,9 @@ class Widget {
|
|
|
513
578
|
}
|
|
514
579
|
|
|
515
580
|
this.analyticsApi.pushAnalyticsLoadEvent(params).then(response => {
|
|
516
|
-
_log$
|
|
581
|
+
_log$7(`${params.engagementMedium} loaded event recorded.`);
|
|
517
582
|
}).catch(ex => {
|
|
518
|
-
_log$
|
|
583
|
+
_log$7(new Error(`pushAnalyticsLoadEvent() ${ex}`));
|
|
519
584
|
});
|
|
520
585
|
}
|
|
521
586
|
|
|
@@ -528,9 +593,9 @@ class Widget {
|
|
|
528
593
|
engagementMedium: sqh.mode.widgetMode,
|
|
529
594
|
shareMedium: medium
|
|
530
595
|
}).then(response => {
|
|
531
|
-
_log$
|
|
596
|
+
_log$7(`${sqh.mode.widgetMode} share ${medium} event recorded. ${response}`);
|
|
532
597
|
}).catch(ex => {
|
|
533
|
-
_log$
|
|
598
|
+
_log$7(new Error(`pushAnalyticsLoadEvent() ${ex}`));
|
|
534
599
|
});
|
|
535
600
|
}
|
|
536
601
|
}
|
|
@@ -543,9 +608,9 @@ class Widget {
|
|
|
543
608
|
userId: sqh.analytics.attributes.userId,
|
|
544
609
|
emailList
|
|
545
610
|
}).then(response => {
|
|
546
|
-
_log$
|
|
611
|
+
_log$7(`Sent email invites to share ${emailList}. ${response}`);
|
|
547
612
|
}).catch(ex => {
|
|
548
|
-
_log$
|
|
613
|
+
_log$7(new Error(`invite() ${ex}`));
|
|
549
614
|
});
|
|
550
615
|
}
|
|
551
616
|
}
|
|
@@ -634,6 +699,7 @@ class Widget {
|
|
|
634
699
|
email: email || null,
|
|
635
700
|
firstName: firstName || null,
|
|
636
701
|
lastName: lastName || null,
|
|
702
|
+
// FIXME: Double check this
|
|
637
703
|
id: this.context.user.id,
|
|
638
704
|
accountId: this.context.user.accountId
|
|
639
705
|
};
|
|
@@ -655,6 +721,13 @@ class Widget {
|
|
|
655
721
|
widgetType: this.type,
|
|
656
722
|
jwt
|
|
657
723
|
});
|
|
724
|
+
} else if (this.context.type === "passwordless") {
|
|
725
|
+
response = this.widgetApi.render({
|
|
726
|
+
user: undefined,
|
|
727
|
+
engagementMedium,
|
|
728
|
+
widgetType: this.type,
|
|
729
|
+
jwt: undefined
|
|
730
|
+
});
|
|
658
731
|
} else {
|
|
659
732
|
throw new Error("can't reload an error widget");
|
|
660
733
|
}
|
|
@@ -689,7 +762,7 @@ class Widget {
|
|
|
689
762
|
}).catch(({
|
|
690
763
|
message
|
|
691
764
|
}) => {
|
|
692
|
-
_log$
|
|
765
|
+
_log$7(`${message}`);
|
|
693
766
|
});
|
|
694
767
|
}
|
|
695
768
|
|
|
@@ -726,7 +799,7 @@ function domready(targetDoc, fn) {
|
|
|
726
799
|
|
|
727
800
|
// @ts-check
|
|
728
801
|
|
|
729
|
-
const _log$
|
|
802
|
+
const _log$6 = debug__default['default']("squatch-js:EMBEDwidget");
|
|
730
803
|
/**
|
|
731
804
|
* An EmbedWidget is displayed inline in part of your page.
|
|
732
805
|
*
|
|
@@ -744,22 +817,22 @@ class EmbedWidget extends Widget {
|
|
|
744
817
|
// selector is a string
|
|
745
818
|
element = document.querySelector(container);
|
|
746
819
|
|
|
747
|
-
_log$
|
|
820
|
+
_log$6("loading widget with selector", element); // selector is an HTML element
|
|
748
821
|
|
|
749
822
|
} else if (container instanceof HTMLElement) {
|
|
750
823
|
element = container;
|
|
751
824
|
|
|
752
|
-
_log$
|
|
825
|
+
_log$6("loading widget with container", element); // garbage container found
|
|
753
826
|
|
|
754
827
|
} else if (container) {
|
|
755
828
|
element = null;
|
|
756
829
|
|
|
757
|
-
_log$
|
|
830
|
+
_log$6("container must be an HTMLElement or string", container); // find element on page
|
|
758
831
|
|
|
759
832
|
} else {
|
|
760
833
|
element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed");
|
|
761
834
|
|
|
762
|
-
_log$
|
|
835
|
+
_log$6("loading widget with default selector", element);
|
|
763
836
|
}
|
|
764
837
|
|
|
765
838
|
if (!(element instanceof HTMLElement)) throw new Error(`element with selector '${container}' not found.'`);
|
|
@@ -825,7 +898,7 @@ class EmbedWidget extends Widget {
|
|
|
825
898
|
if (!this.context.container) {
|
|
826
899
|
this._loadEvent(_sqh);
|
|
827
900
|
|
|
828
|
-
_log$
|
|
901
|
+
_log$6("loaded");
|
|
829
902
|
}
|
|
830
903
|
});
|
|
831
904
|
} // Un-hide if element is available and refresh data
|
|
@@ -834,7 +907,7 @@ class EmbedWidget extends Widget {
|
|
|
834
907
|
open() {
|
|
835
908
|
var _this$frame, _this$frame$contentDo, _this$frame2, _this$frame2$contentW, _this$frame3, _this$frame3$contentW;
|
|
836
909
|
|
|
837
|
-
if (!this.frame) return _log$
|
|
910
|
+
if (!this.frame) return _log$6("no target element to open");
|
|
838
911
|
this.element.style.visibility = "unset";
|
|
839
912
|
this.element.style.height = "auto";
|
|
840
913
|
this.element.style["overflow-y"] = "auto";
|
|
@@ -844,16 +917,16 @@ class EmbedWidget extends Widget {
|
|
|
844
917
|
|
|
845
918
|
this._loadEvent(_sqh);
|
|
846
919
|
|
|
847
|
-
_log$
|
|
920
|
+
_log$6("loaded");
|
|
848
921
|
}
|
|
849
922
|
|
|
850
923
|
close() {
|
|
851
|
-
if (!this.frame) return _log$
|
|
924
|
+
if (!this.frame) return _log$6("no target element to close");
|
|
852
925
|
this.element.style.visibility = "hidden";
|
|
853
926
|
this.element.style.height = "0";
|
|
854
927
|
this.element.style["overflow-y"] = "hidden";
|
|
855
928
|
|
|
856
|
-
_log$
|
|
929
|
+
_log$6("Embed widget closed");
|
|
857
930
|
}
|
|
858
931
|
|
|
859
932
|
_error(rs, mode = "embed", style = "") {
|
|
@@ -864,7 +937,7 @@ class EmbedWidget extends Widget {
|
|
|
864
937
|
|
|
865
938
|
// @ts-check
|
|
866
939
|
|
|
867
|
-
const _log$
|
|
940
|
+
const _log$5 = debug__default['default']("squatch-js:POPUPwidget");
|
|
868
941
|
/**
|
|
869
942
|
* The PopupWidget is used to display popups (also known as "Modals").
|
|
870
943
|
* Popups widgets are rendered on top of other elements in a page.
|
|
@@ -882,9 +955,9 @@ class PopupWidget extends Widget {
|
|
|
882
955
|
this.triggerElement
|
|
883
956
|
/* HTMLButton */
|
|
884
957
|
= document.querySelector(trigger);
|
|
885
|
-
if (trigger && !this.triggerElement) _log$
|
|
958
|
+
if (trigger && !this.triggerElement) _log$5("No element found with trigger selector", trigger);
|
|
886
959
|
} catch (_unused) {
|
|
887
|
-
_log$
|
|
960
|
+
_log$5("Not a valid selector", trigger);
|
|
888
961
|
} // Trigger is optional
|
|
889
962
|
|
|
890
963
|
|
|
@@ -926,7 +999,7 @@ class PopupWidget extends Widget {
|
|
|
926
999
|
frameDoc.write(`<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"></script>`);
|
|
927
1000
|
frameDoc.close();
|
|
928
1001
|
|
|
929
|
-
_log$
|
|
1002
|
+
_log$5("Popup template loaded into iframe");
|
|
930
1003
|
|
|
931
1004
|
this._setupResizeHandler();
|
|
932
1005
|
}
|
|
@@ -999,7 +1072,7 @@ class PopupWidget extends Widget {
|
|
|
999
1072
|
|
|
1000
1073
|
this._loadEvent(_sqh);
|
|
1001
1074
|
|
|
1002
|
-
_log$
|
|
1075
|
+
_log$5("Popup opened");
|
|
1003
1076
|
});
|
|
1004
1077
|
}
|
|
1005
1078
|
|
|
@@ -1007,7 +1080,7 @@ class PopupWidget extends Widget {
|
|
|
1007
1080
|
this.popupdiv.style.visibility = "hidden";
|
|
1008
1081
|
this.popupdiv.style.top = "-2000px";
|
|
1009
1082
|
|
|
1010
|
-
_log$
|
|
1083
|
+
_log$5("Popup closed");
|
|
1011
1084
|
}
|
|
1012
1085
|
|
|
1013
1086
|
_clickedOutside({
|
|
@@ -1025,7 +1098,7 @@ class PopupWidget extends Widget {
|
|
|
1025
1098
|
|
|
1026
1099
|
}
|
|
1027
1100
|
|
|
1028
|
-
const _log$
|
|
1101
|
+
const _log$4 = debug__namespace("squatch-js:CTAwidget");
|
|
1029
1102
|
/**
|
|
1030
1103
|
* A CtaWidget is displayed on top of your page
|
|
1031
1104
|
*
|
|
@@ -1036,7 +1109,7 @@ const _log$3 = debug__namespace("squatch-js:CTAwidget");
|
|
|
1036
1109
|
|
|
1037
1110
|
class CtaWidget extends PopupWidget {
|
|
1038
1111
|
constructor(params, opts) {
|
|
1039
|
-
_log$
|
|
1112
|
+
_log$4("CTA constructor");
|
|
1040
1113
|
|
|
1041
1114
|
const ctaElement = document.createElement("div");
|
|
1042
1115
|
ctaElement.id = "cta";
|
|
@@ -1064,7 +1137,7 @@ class CtaWidget extends PopupWidget {
|
|
|
1064
1137
|
this.ctaFrame.setAttribute("style", `border:0; background-color:transparent; position:fixed; display:none;${this.side}${this.position}`);
|
|
1065
1138
|
document.body.appendChild(this.ctaFrame);
|
|
1066
1139
|
|
|
1067
|
-
_log$
|
|
1140
|
+
_log$4("ctaframe appended to body");
|
|
1068
1141
|
}
|
|
1069
1142
|
|
|
1070
1143
|
load() {
|
|
@@ -1128,10 +1201,10 @@ class CtaWidget extends PopupWidget {
|
|
|
1128
1201
|
});
|
|
1129
1202
|
ro.observe(ctaContainer);
|
|
1130
1203
|
|
|
1131
|
-
_log$
|
|
1204
|
+
_log$4("CTA template loaded into iframe");
|
|
1132
1205
|
});
|
|
1133
1206
|
} else {
|
|
1134
|
-
_log$
|
|
1207
|
+
_log$4(new Error("CTA element not found in theme"));
|
|
1135
1208
|
}
|
|
1136
1209
|
});
|
|
1137
1210
|
}
|
|
@@ -1154,7 +1227,7 @@ class CtaWidget extends PopupWidget {
|
|
|
1154
1227
|
|
|
1155
1228
|
}
|
|
1156
1229
|
|
|
1157
|
-
const _log$
|
|
1230
|
+
const _log$3 = debug__default['default']("squatch-js:widgets");
|
|
1158
1231
|
/**
|
|
1159
1232
|
*
|
|
1160
1233
|
* `Widgets` is a factory for creating widgets. It's possible to build your own widgets using the
|
|
@@ -1218,7 +1291,7 @@ class Widgets {
|
|
|
1218
1291
|
user: response.user
|
|
1219
1292
|
};
|
|
1220
1293
|
} catch (err) {
|
|
1221
|
-
_log$
|
|
1294
|
+
_log$3(err);
|
|
1222
1295
|
|
|
1223
1296
|
if (err.apiErrorCode) {
|
|
1224
1297
|
this._renderErrorWidget(err, config.engagementMedium);
|
|
@@ -1254,7 +1327,7 @@ class Widgets {
|
|
|
1254
1327
|
return {
|
|
1255
1328
|
widget: this._renderWidget(response, clean, {
|
|
1256
1329
|
type: "upsert",
|
|
1257
|
-
user: clean.user,
|
|
1330
|
+
user: clean.user || null,
|
|
1258
1331
|
engagementMedium: config.engagementMedium,
|
|
1259
1332
|
container: config.container,
|
|
1260
1333
|
trigger: config.trigger
|
|
@@ -1262,7 +1335,7 @@ class Widgets {
|
|
|
1262
1335
|
user: response.user
|
|
1263
1336
|
};
|
|
1264
1337
|
} catch (err) {
|
|
1265
|
-
_log$
|
|
1338
|
+
_log$3(err);
|
|
1266
1339
|
|
|
1267
1340
|
if (err.apiErrorCode) {
|
|
1268
1341
|
this._renderErrorWidget(err, config.engagementMedium);
|
|
@@ -1290,19 +1363,26 @@ class Widgets {
|
|
|
1290
1363
|
|
|
1291
1364
|
async render(config) {
|
|
1292
1365
|
const raw = config;
|
|
1293
|
-
const clean =
|
|
1366
|
+
const clean = validatePasswordlessConfig(raw);
|
|
1294
1367
|
|
|
1295
1368
|
try {
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1369
|
+
// TODO: Flagging default behaviour change
|
|
1370
|
+
// cookieUser returns a deprecated error from the API on the latest squatchJs version
|
|
1371
|
+
// More suitable for no auth render?
|
|
1372
|
+
const queryString = window.location.search;
|
|
1373
|
+
const urlParams = new URLSearchParams(queryString);
|
|
1374
|
+
const refParam = urlParams.get("_saasquatch") || "";
|
|
1375
|
+
|
|
1376
|
+
if (!config.showOnReferral || refParam) {
|
|
1377
|
+
const response = await this.api.render(clean);
|
|
1378
|
+
return {
|
|
1379
|
+
widget: this._renderWidget(response, clean, {
|
|
1380
|
+
type: "passwordless",
|
|
1381
|
+
engagementMedium: clean.engagementMedium
|
|
1382
|
+
}),
|
|
1383
|
+
user: response.user
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1306
1386
|
} catch (err) {
|
|
1307
1387
|
if (err.apiErrorCode) {
|
|
1308
1388
|
this._renderErrorWidget(err, clean.engagementMedium);
|
|
@@ -1325,7 +1405,7 @@ class Widgets {
|
|
|
1325
1405
|
|
|
1326
1406
|
if (typeof input === "function") {
|
|
1327
1407
|
this.api.squatchReferralCookie().then((...args) => input(...args)).catch(ex => {
|
|
1328
|
-
_log$
|
|
1408
|
+
_log$3("Autofill error", ex);
|
|
1329
1409
|
|
|
1330
1410
|
throw ex;
|
|
1331
1411
|
});
|
|
@@ -1340,7 +1420,7 @@ class Widgets {
|
|
|
1340
1420
|
// Only use the first element found
|
|
1341
1421
|
elem = elems[0];
|
|
1342
1422
|
} else {
|
|
1343
|
-
_log$
|
|
1423
|
+
_log$3("Element id/class or function missing");
|
|
1344
1424
|
|
|
1345
1425
|
throw new Error("Element id/class or function missing");
|
|
1346
1426
|
}
|
|
@@ -1373,16 +1453,17 @@ class Widgets {
|
|
|
1373
1453
|
* @param {Object} config Config details
|
|
1374
1454
|
* @param {string} config.widgetType The widget type (REFERRER_WIDGET, CONVERSION_WIDGET)
|
|
1375
1455
|
* @param {string} config.engagementMedium (POPUP, EMBED)
|
|
1456
|
+
* @param {string} config.showOnReferral Whether to show
|
|
1376
1457
|
* @returns {Widget} widget (PopupWidget, EmbedWidget, or CtaWidget)
|
|
1377
1458
|
*/
|
|
1378
1459
|
|
|
1379
1460
|
|
|
1380
1461
|
_renderWidget(response, config, context) {
|
|
1381
|
-
_log$
|
|
1462
|
+
_log$3("Rendering Widget...");
|
|
1382
1463
|
|
|
1383
1464
|
if (!response) throw new Error("Unable to get a response");
|
|
1384
1465
|
let widget;
|
|
1385
|
-
let displayOnLoad =
|
|
1466
|
+
let displayOnLoad = !!config.showOnReferral;
|
|
1386
1467
|
let displayCTA = false;
|
|
1387
1468
|
const opts = response.jsOptions || "";
|
|
1388
1469
|
const params = {
|
|
@@ -1401,9 +1482,9 @@ class Widgets {
|
|
|
1401
1482
|
displayOnLoad = rule.displayOnLoad;
|
|
1402
1483
|
displayCTA = rule.showAsCTA;
|
|
1403
1484
|
|
|
1404
|
-
_log$
|
|
1485
|
+
_log$3(`Display ${rule.widgetType} on ${rule.url}`);
|
|
1405
1486
|
} else {
|
|
1406
|
-
_log$
|
|
1487
|
+
_log$3(`Don't display ${rule.widgetType} when no referral on widget rule match ${rule.url}`);
|
|
1407
1488
|
}
|
|
1408
1489
|
}
|
|
1409
1490
|
});
|
|
@@ -1412,20 +1493,20 @@ class Widgets {
|
|
|
1412
1493
|
if (opts.conversionUrls) {
|
|
1413
1494
|
opts.conversionUrls.forEach(rule => {
|
|
1414
1495
|
if (response.user.referredBy && Widgets._matchesUrl(rule)) {
|
|
1415
|
-
_log$
|
|
1496
|
+
_log$3("This is a conversion URL", rule);
|
|
1416
1497
|
}
|
|
1417
1498
|
});
|
|
1418
1499
|
}
|
|
1419
1500
|
|
|
1420
1501
|
if (opts.fuelTankAutofillUrls) {
|
|
1421
|
-
_log$
|
|
1502
|
+
_log$3("We found a fuel tank autofill!");
|
|
1422
1503
|
|
|
1423
1504
|
opts.fuelTankAutofillUrls.forEach(({
|
|
1424
1505
|
url,
|
|
1425
1506
|
formSelector
|
|
1426
1507
|
}) => {
|
|
1427
1508
|
if (Widgets._matchesUrl(url)) {
|
|
1428
|
-
_log$
|
|
1509
|
+
_log$3("Fuel Tank URL matches");
|
|
1429
1510
|
|
|
1430
1511
|
if (response.user.referredBy && response.user.referredBy.code) {
|
|
1431
1512
|
const formAutofill = document.querySelector(formSelector);
|
|
@@ -1433,7 +1514,7 @@ class Widgets {
|
|
|
1433
1514
|
if (formAutofill) {
|
|
1434
1515
|
formAutofill.value = response.user.referredBy.referredReward.fuelTankCode || "";
|
|
1435
1516
|
} else {
|
|
1436
|
-
_log$
|
|
1517
|
+
_log$3(new Error(`Element with id/class ${formSelector} was not found.`));
|
|
1437
1518
|
}
|
|
1438
1519
|
}
|
|
1439
1520
|
}
|
|
@@ -1448,7 +1529,7 @@ class Widgets {
|
|
|
1448
1529
|
widget.load();
|
|
1449
1530
|
if (displayOnLoad) widget.open();
|
|
1450
1531
|
} else if (displayCTA) {
|
|
1451
|
-
_log$
|
|
1532
|
+
_log$3("display CTA");
|
|
1452
1533
|
|
|
1453
1534
|
const side = opts.cta.content.buttonSide;
|
|
1454
1535
|
const position = opts.cta.content.buttonPosition;
|
|
@@ -1459,7 +1540,7 @@ class Widgets {
|
|
|
1459
1540
|
widget.load();
|
|
1460
1541
|
if (displayOnLoad) widget.open();
|
|
1461
1542
|
} else {
|
|
1462
|
-
_log$
|
|
1543
|
+
_log$3("display popup on load");
|
|
1463
1544
|
|
|
1464
1545
|
widget = new PopupWidget(params);
|
|
1465
1546
|
widget.load();
|
|
@@ -1483,7 +1564,7 @@ class Widgets {
|
|
|
1483
1564
|
message
|
|
1484
1565
|
} = props;
|
|
1485
1566
|
|
|
1486
|
-
_log$
|
|
1567
|
+
_log$3(new Error(`${apiErrorCode} (${rsCode}) ${message}`));
|
|
1487
1568
|
|
|
1488
1569
|
const params = {
|
|
1489
1570
|
content: "error",
|
|
@@ -2013,7 +2094,7 @@ var URLSearchParams$1 = self.URLSearchParams;
|
|
|
2013
2094
|
|
|
2014
2095
|
/** @hidden */
|
|
2015
2096
|
|
|
2016
|
-
const _log$
|
|
2097
|
+
const _log$2 = debug__default['default']("squatch-js");
|
|
2017
2098
|
|
|
2018
2099
|
const isObject = item => typeof item === "object" && !Array.isArray(item);
|
|
2019
2100
|
|
|
@@ -2066,7 +2147,7 @@ function _pushCookie() {
|
|
|
2066
2147
|
try {
|
|
2067
2148
|
paramsJSON = JSON.parse(b64decode(refParam));
|
|
2068
2149
|
} catch (error) {
|
|
2069
|
-
_log$
|
|
2150
|
+
_log$2("Unable to decode params", error); // don't merge invalid params
|
|
2070
2151
|
|
|
2071
2152
|
|
|
2072
2153
|
return;
|
|
@@ -2075,26 +2156,26 @@ function _pushCookie() {
|
|
|
2075
2156
|
try {
|
|
2076
2157
|
existingCookie = JSON.parse(b64decode(Cookies__default['default'].get("_saasquatch")));
|
|
2077
2158
|
|
|
2078
|
-
_log$
|
|
2159
|
+
_log$2("existing cookie", existingCookie);
|
|
2079
2160
|
} catch (error) {
|
|
2080
|
-
_log$
|
|
2161
|
+
_log$2("Unable to retrieve cookie", error);
|
|
2081
2162
|
} // don't merge if there's no existing object
|
|
2082
2163
|
|
|
2083
2164
|
|
|
2084
2165
|
try {
|
|
2085
2166
|
const domain = getTopDomain();
|
|
2086
2167
|
|
|
2087
|
-
_log$
|
|
2168
|
+
_log$2("domain retrieved:", domain);
|
|
2088
2169
|
|
|
2089
2170
|
if (existingCookie) {
|
|
2090
2171
|
const newCookie = deepMerge(existingCookie, paramsJSON);
|
|
2091
2172
|
reEncodedCookie = b64encode(JSON.stringify(newCookie));
|
|
2092
2173
|
|
|
2093
|
-
_log$
|
|
2174
|
+
_log$2("cookie to store:", newCookie);
|
|
2094
2175
|
} else {
|
|
2095
2176
|
reEncodedCookie = b64encode(JSON.stringify(paramsJSON));
|
|
2096
2177
|
|
|
2097
|
-
_log$
|
|
2178
|
+
_log$2("cookie to store:", paramsJSON);
|
|
2098
2179
|
}
|
|
2099
2180
|
|
|
2100
2181
|
Cookies__default['default'].set("_saasquatch", reEncodedCookie, {
|
|
@@ -2105,17 +2186,90 @@ function _pushCookie() {
|
|
|
2105
2186
|
path: "/"
|
|
2106
2187
|
});
|
|
2107
2188
|
} catch (error) {
|
|
2108
|
-
_log$
|
|
2189
|
+
_log$2("Unable to set cookie", error);
|
|
2109
2190
|
}
|
|
2110
2191
|
}
|
|
2111
2192
|
}
|
|
2112
2193
|
|
|
2194
|
+
/** @hidden */
|
|
2195
|
+
|
|
2196
|
+
const _log$1 = debug__default['default']("squatch-js");
|
|
2197
|
+
|
|
2198
|
+
function _getAutoConfig(configIn) {
|
|
2199
|
+
const queryString = window.location.search;
|
|
2200
|
+
const urlParams = new URLSearchParams(queryString);
|
|
2201
|
+
const refParam = urlParams.get("_saasquatchExtra") || "";
|
|
2202
|
+
|
|
2203
|
+
if (!refParam) {
|
|
2204
|
+
_log$1("No _saasquatchExtra param");
|
|
2205
|
+
|
|
2206
|
+
return;
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
let raw;
|
|
2210
|
+
|
|
2211
|
+
try {
|
|
2212
|
+
raw = JSON.parse(b64decode(refParam));
|
|
2213
|
+
} catch (e) {
|
|
2214
|
+
_log$1("Unable to decode _saasquatchExtra config");
|
|
2215
|
+
|
|
2216
|
+
return;
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
const {
|
|
2220
|
+
domain,
|
|
2221
|
+
tenantAlias,
|
|
2222
|
+
widgetConfig
|
|
2223
|
+
} = convertExtraToConfig(raw);
|
|
2224
|
+
|
|
2225
|
+
if (!domain || !tenantAlias || !widgetConfig) {
|
|
2226
|
+
_log$1("_saasquatchExtra did not have an expected structure");
|
|
2227
|
+
|
|
2228
|
+
return undefined;
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
const {
|
|
2232
|
+
autoPopupWidgetType
|
|
2233
|
+
} = widgetConfig,
|
|
2234
|
+
rest = _objectWithoutPropertiesLoose(widgetConfig, ["autoPopupWidgetType"]);
|
|
2235
|
+
|
|
2236
|
+
return {
|
|
2237
|
+
widgetConfig: _extends({
|
|
2238
|
+
widgetType: autoPopupWidgetType
|
|
2239
|
+
}, rest),
|
|
2240
|
+
squatchConfig: _extends({}, configIn ? {
|
|
2241
|
+
configIn
|
|
2242
|
+
} : {}, {
|
|
2243
|
+
domain,
|
|
2244
|
+
tenantAlias
|
|
2245
|
+
})
|
|
2246
|
+
};
|
|
2247
|
+
}
|
|
2248
|
+
/**
|
|
2249
|
+
* Converts _saasquatchExtra into
|
|
2250
|
+
* @param obj
|
|
2251
|
+
*/
|
|
2252
|
+
|
|
2253
|
+
function convertExtraToConfig(obj) {
|
|
2254
|
+
var _obj$_domain;
|
|
2255
|
+
|
|
2256
|
+
const _domain = Object.keys(obj || {})[0];
|
|
2257
|
+
const tenantAlias = Object.keys((obj == null ? void 0 : obj[_domain]) || {})[0];
|
|
2258
|
+
const widgetConfig = obj == null ? void 0 : (_obj$_domain = obj[_domain]) == null ? void 0 : _obj$_domain[tenantAlias]; // domain in _saasquatchExtra doesn't contain "https://"
|
|
2259
|
+
|
|
2260
|
+
const domain = _domain ? `https://${_domain}` : undefined;
|
|
2261
|
+
return {
|
|
2262
|
+
domain,
|
|
2263
|
+
tenantAlias,
|
|
2264
|
+
widgetConfig
|
|
2265
|
+
};
|
|
2266
|
+
}
|
|
2267
|
+
|
|
2113
2268
|
// @ts-check
|
|
2114
2269
|
function help() {
|
|
2115
2270
|
console.log(`Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes.`);
|
|
2116
2271
|
}
|
|
2117
2272
|
|
|
2118
|
-
// @ts-check
|
|
2119
2273
|
// debug.disable("squatch-js*");
|
|
2120
2274
|
|
|
2121
2275
|
/** @hidden */
|
|
@@ -2163,6 +2317,37 @@ function widgets() {
|
|
|
2163
2317
|
function events() {
|
|
2164
2318
|
return _events;
|
|
2165
2319
|
}
|
|
2320
|
+
/**
|
|
2321
|
+
* Entry-point for high level API to render a widget using the instance of {@link Widgets} created when you call {@link #init init}.
|
|
2322
|
+
*/
|
|
2323
|
+
|
|
2324
|
+
function widget(widgetConfig) {
|
|
2325
|
+
var _widgets2;
|
|
2326
|
+
|
|
2327
|
+
return (_widgets2 = widgets()) == null ? void 0 : _widgets2.render(widgetConfig);
|
|
2328
|
+
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Initial concept for automatic widget rendering
|
|
2331
|
+
*
|
|
2332
|
+
* - `saasquatchExtra` utm param carries widgetIdent
|
|
2333
|
+
*/
|
|
2334
|
+
|
|
2335
|
+
function auto(configIn) {
|
|
2336
|
+
const configs = _getAutoConfig(configIn);
|
|
2337
|
+
|
|
2338
|
+
if (configs) {
|
|
2339
|
+
var _widgets3;
|
|
2340
|
+
|
|
2341
|
+
const {
|
|
2342
|
+
squatchConfig,
|
|
2343
|
+
widgetConfig
|
|
2344
|
+
} = configs;
|
|
2345
|
+
init(squatchConfig);
|
|
2346
|
+
return (_widgets3 = widgets()) == null ? void 0 : _widgets3.render(_extends({
|
|
2347
|
+
showOnReferral: true
|
|
2348
|
+
}, widgetConfig));
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2166
2351
|
/**
|
|
2167
2352
|
* Initializes the static `squatch` global. This sets up:
|
|
2168
2353
|
*
|
|
@@ -2273,6 +2458,7 @@ exports.PopupWidget = PopupWidget;
|
|
|
2273
2458
|
exports.WidgetApi = WidgetApi;
|
|
2274
2459
|
exports.Widgets = Widgets;
|
|
2275
2460
|
exports.api = api;
|
|
2461
|
+
exports.auto = auto;
|
|
2276
2462
|
exports.autofill = autofill;
|
|
2277
2463
|
exports.events = events;
|
|
2278
2464
|
exports.help = help;
|
|
@@ -2280,5 +2466,6 @@ exports.init = init;
|
|
|
2280
2466
|
exports.pushCookie = pushCookie;
|
|
2281
2467
|
exports.ready = ready;
|
|
2282
2468
|
exports.submitEmail = submitEmail;
|
|
2469
|
+
exports.widget = widget;
|
|
2283
2470
|
exports.widgets = widgets;
|
|
2284
2471
|
//# sourceMappingURL=squatch.js.map
|