@saasquatch/squatch-js 2.4.2 → 2.4.3-0
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 +265 -84
- package/dist/squatch.esm.js.map +1 -1
- package/dist/squatch.js +266 -83
- 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 +3 -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
|
}
|
|
@@ -1378,7 +1458,7 @@ class Widgets {
|
|
|
1378
1458
|
|
|
1379
1459
|
|
|
1380
1460
|
_renderWidget(response, config, context) {
|
|
1381
|
-
_log$
|
|
1461
|
+
_log$3("Rendering Widget...");
|
|
1382
1462
|
|
|
1383
1463
|
if (!response) throw new Error("Unable to get a response");
|
|
1384
1464
|
let widget;
|
|
@@ -1401,9 +1481,9 @@ class Widgets {
|
|
|
1401
1481
|
displayOnLoad = rule.displayOnLoad;
|
|
1402
1482
|
displayCTA = rule.showAsCTA;
|
|
1403
1483
|
|
|
1404
|
-
_log$
|
|
1484
|
+
_log$3(`Display ${rule.widgetType} on ${rule.url}`);
|
|
1405
1485
|
} else {
|
|
1406
|
-
_log$
|
|
1486
|
+
_log$3(`Don't display ${rule.widgetType} when no referral on widget rule match ${rule.url}`);
|
|
1407
1487
|
}
|
|
1408
1488
|
}
|
|
1409
1489
|
});
|
|
@@ -1412,20 +1492,20 @@ class Widgets {
|
|
|
1412
1492
|
if (opts.conversionUrls) {
|
|
1413
1493
|
opts.conversionUrls.forEach(rule => {
|
|
1414
1494
|
if (response.user.referredBy && Widgets._matchesUrl(rule)) {
|
|
1415
|
-
_log$
|
|
1495
|
+
_log$3("This is a conversion URL", rule);
|
|
1416
1496
|
}
|
|
1417
1497
|
});
|
|
1418
1498
|
}
|
|
1419
1499
|
|
|
1420
1500
|
if (opts.fuelTankAutofillUrls) {
|
|
1421
|
-
_log$
|
|
1501
|
+
_log$3("We found a fuel tank autofill!");
|
|
1422
1502
|
|
|
1423
1503
|
opts.fuelTankAutofillUrls.forEach(({
|
|
1424
1504
|
url,
|
|
1425
1505
|
formSelector
|
|
1426
1506
|
}) => {
|
|
1427
1507
|
if (Widgets._matchesUrl(url)) {
|
|
1428
|
-
_log$
|
|
1508
|
+
_log$3("Fuel Tank URL matches");
|
|
1429
1509
|
|
|
1430
1510
|
if (response.user.referredBy && response.user.referredBy.code) {
|
|
1431
1511
|
const formAutofill = document.querySelector(formSelector);
|
|
@@ -1433,7 +1513,7 @@ class Widgets {
|
|
|
1433
1513
|
if (formAutofill) {
|
|
1434
1514
|
formAutofill.value = response.user.referredBy.referredReward.fuelTankCode || "";
|
|
1435
1515
|
} else {
|
|
1436
|
-
_log$
|
|
1516
|
+
_log$3(new Error(`Element with id/class ${formSelector} was not found.`));
|
|
1437
1517
|
}
|
|
1438
1518
|
}
|
|
1439
1519
|
}
|
|
@@ -1448,7 +1528,7 @@ class Widgets {
|
|
|
1448
1528
|
widget.load();
|
|
1449
1529
|
if (displayOnLoad) widget.open();
|
|
1450
1530
|
} else if (displayCTA) {
|
|
1451
|
-
_log$
|
|
1531
|
+
_log$3("display CTA");
|
|
1452
1532
|
|
|
1453
1533
|
const side = opts.cta.content.buttonSide;
|
|
1454
1534
|
const position = opts.cta.content.buttonPosition;
|
|
@@ -1459,7 +1539,7 @@ class Widgets {
|
|
|
1459
1539
|
widget.load();
|
|
1460
1540
|
if (displayOnLoad) widget.open();
|
|
1461
1541
|
} else {
|
|
1462
|
-
_log$
|
|
1542
|
+
_log$3("display popup on load");
|
|
1463
1543
|
|
|
1464
1544
|
widget = new PopupWidget(params);
|
|
1465
1545
|
widget.load();
|
|
@@ -1483,7 +1563,7 @@ class Widgets {
|
|
|
1483
1563
|
message
|
|
1484
1564
|
} = props;
|
|
1485
1565
|
|
|
1486
|
-
_log$
|
|
1566
|
+
_log$3(new Error(`${apiErrorCode} (${rsCode}) ${message}`));
|
|
1487
1567
|
|
|
1488
1568
|
const params = {
|
|
1489
1569
|
content: "error",
|
|
@@ -2013,7 +2093,7 @@ var URLSearchParams$1 = self.URLSearchParams;
|
|
|
2013
2093
|
|
|
2014
2094
|
/** @hidden */
|
|
2015
2095
|
|
|
2016
|
-
const _log$
|
|
2096
|
+
const _log$2 = debug__default['default']("squatch-js");
|
|
2017
2097
|
|
|
2018
2098
|
const isObject = item => typeof item === "object" && !Array.isArray(item);
|
|
2019
2099
|
|
|
@@ -2066,7 +2146,7 @@ function _pushCookie() {
|
|
|
2066
2146
|
try {
|
|
2067
2147
|
paramsJSON = JSON.parse(b64decode(refParam));
|
|
2068
2148
|
} catch (error) {
|
|
2069
|
-
_log$
|
|
2149
|
+
_log$2("Unable to decode params", error); // don't merge invalid params
|
|
2070
2150
|
|
|
2071
2151
|
|
|
2072
2152
|
return;
|
|
@@ -2075,26 +2155,26 @@ function _pushCookie() {
|
|
|
2075
2155
|
try {
|
|
2076
2156
|
existingCookie = JSON.parse(b64decode(Cookies__default['default'].get("_saasquatch")));
|
|
2077
2157
|
|
|
2078
|
-
_log$
|
|
2158
|
+
_log$2("existing cookie", existingCookie);
|
|
2079
2159
|
} catch (error) {
|
|
2080
|
-
_log$
|
|
2160
|
+
_log$2("Unable to retrieve cookie", error);
|
|
2081
2161
|
} // don't merge if there's no existing object
|
|
2082
2162
|
|
|
2083
2163
|
|
|
2084
2164
|
try {
|
|
2085
2165
|
const domain = getTopDomain();
|
|
2086
2166
|
|
|
2087
|
-
_log$
|
|
2167
|
+
_log$2("domain retrieved:", domain);
|
|
2088
2168
|
|
|
2089
2169
|
if (existingCookie) {
|
|
2090
2170
|
const newCookie = deepMerge(existingCookie, paramsJSON);
|
|
2091
2171
|
reEncodedCookie = b64encode(JSON.stringify(newCookie));
|
|
2092
2172
|
|
|
2093
|
-
_log$
|
|
2173
|
+
_log$2("cookie to store:", newCookie);
|
|
2094
2174
|
} else {
|
|
2095
2175
|
reEncodedCookie = b64encode(JSON.stringify(paramsJSON));
|
|
2096
2176
|
|
|
2097
|
-
_log$
|
|
2177
|
+
_log$2("cookie to store:", paramsJSON);
|
|
2098
2178
|
}
|
|
2099
2179
|
|
|
2100
2180
|
Cookies__default['default'].set("_saasquatch", reEncodedCookie, {
|
|
@@ -2105,11 +2185,83 @@ function _pushCookie() {
|
|
|
2105
2185
|
path: "/"
|
|
2106
2186
|
});
|
|
2107
2187
|
} catch (error) {
|
|
2108
|
-
_log$
|
|
2188
|
+
_log$2("Unable to set cookie", error);
|
|
2109
2189
|
}
|
|
2110
2190
|
}
|
|
2111
2191
|
}
|
|
2112
2192
|
|
|
2193
|
+
/** @hidden */
|
|
2194
|
+
|
|
2195
|
+
const _log$1 = debug__default['default']("squatch-js");
|
|
2196
|
+
|
|
2197
|
+
function _getConfig(configIn) {
|
|
2198
|
+
const queryString = window.location.search;
|
|
2199
|
+
const urlParams = new URLSearchParams(queryString);
|
|
2200
|
+
const refParam = urlParams.get("_saasquatchExtra") || "";
|
|
2201
|
+
|
|
2202
|
+
if (!refParam) {
|
|
2203
|
+
_log$1("No _saasquatchExtra param");
|
|
2204
|
+
|
|
2205
|
+
return;
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
let raw;
|
|
2209
|
+
|
|
2210
|
+
try {
|
|
2211
|
+
raw = JSON.parse(b64decode(refParam));
|
|
2212
|
+
} catch (e) {
|
|
2213
|
+
_log$1("Unable to decode _saasquatchExtra config");
|
|
2214
|
+
|
|
2215
|
+
return;
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
const {
|
|
2219
|
+
domain,
|
|
2220
|
+
tenantAlias,
|
|
2221
|
+
widgetConfig
|
|
2222
|
+
} = convertExtraToConfig(raw);
|
|
2223
|
+
|
|
2224
|
+
if (!domain || !tenantAlias || !widgetConfig) {
|
|
2225
|
+
_log$1("_saasquatchExtra did not have an expected structure");
|
|
2226
|
+
|
|
2227
|
+
return undefined;
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
const {
|
|
2231
|
+
autoPopupWidgetType
|
|
2232
|
+
} = widgetConfig,
|
|
2233
|
+
rest = _objectWithoutPropertiesLoose(widgetConfig, ["autoPopupWidgetType"]);
|
|
2234
|
+
|
|
2235
|
+
return {
|
|
2236
|
+
widgetConfig: _extends({
|
|
2237
|
+
widgetType: autoPopupWidgetType
|
|
2238
|
+
}, rest),
|
|
2239
|
+
squatchConfig: _extends({}, configIn ? {
|
|
2240
|
+
configIn
|
|
2241
|
+
} : {}, {
|
|
2242
|
+
domain,
|
|
2243
|
+
tenantAlias
|
|
2244
|
+
})
|
|
2245
|
+
};
|
|
2246
|
+
}
|
|
2247
|
+
/**
|
|
2248
|
+
* Converts _saasquatchExtra into
|
|
2249
|
+
* @param obj
|
|
2250
|
+
*/
|
|
2251
|
+
|
|
2252
|
+
function convertExtraToConfig(obj) {
|
|
2253
|
+
var _obj$domain;
|
|
2254
|
+
|
|
2255
|
+
const domain = Object.keys(obj || {})[0];
|
|
2256
|
+
const tenantAlias = Object.keys((obj == null ? void 0 : obj[domain]) || {})[0];
|
|
2257
|
+
const widgetConfig = obj == null ? void 0 : (_obj$domain = obj[domain]) == null ? void 0 : _obj$domain[tenantAlias];
|
|
2258
|
+
return {
|
|
2259
|
+
domain,
|
|
2260
|
+
tenantAlias,
|
|
2261
|
+
widgetConfig
|
|
2262
|
+
};
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2113
2265
|
// @ts-check
|
|
2114
2266
|
function help() {
|
|
2115
2267
|
console.log(`Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes.`);
|
|
@@ -2163,6 +2315,35 @@ function widgets() {
|
|
|
2163
2315
|
function events() {
|
|
2164
2316
|
return _events;
|
|
2165
2317
|
}
|
|
2318
|
+
/**
|
|
2319
|
+
* Entry-point for high level API to render a widget using the instance of {@link Widgets} created when you call {@link #init init}.
|
|
2320
|
+
*/
|
|
2321
|
+
|
|
2322
|
+
function widget(widgetConfig) {
|
|
2323
|
+
var _widgets2;
|
|
2324
|
+
|
|
2325
|
+
return (_widgets2 = widgets()) == null ? void 0 : _widgets2.render(widgetConfig);
|
|
2326
|
+
}
|
|
2327
|
+
/**
|
|
2328
|
+
* Initial concept for automatic widget rendering
|
|
2329
|
+
*
|
|
2330
|
+
* - `saasquatchExtra` utm param carries widgetIdent
|
|
2331
|
+
*/
|
|
2332
|
+
|
|
2333
|
+
function auto(configIn) {
|
|
2334
|
+
const configs = _getConfig(configIn);
|
|
2335
|
+
|
|
2336
|
+
if (configs) {
|
|
2337
|
+
var _widgets3;
|
|
2338
|
+
|
|
2339
|
+
const {
|
|
2340
|
+
squatchConfig,
|
|
2341
|
+
widgetConfig
|
|
2342
|
+
} = configs;
|
|
2343
|
+
init(squatchConfig);
|
|
2344
|
+
return widgetConfig && ((_widgets3 = widgets()) == null ? void 0 : _widgets3.render(widgetConfig));
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2166
2347
|
/**
|
|
2167
2348
|
* Initializes the static `squatch` global. This sets up:
|
|
2168
2349
|
*
|
|
@@ -2273,6 +2454,7 @@ exports.PopupWidget = PopupWidget;
|
|
|
2273
2454
|
exports.WidgetApi = WidgetApi;
|
|
2274
2455
|
exports.Widgets = Widgets;
|
|
2275
2456
|
exports.api = api;
|
|
2457
|
+
exports.auto = auto;
|
|
2276
2458
|
exports.autofill = autofill;
|
|
2277
2459
|
exports.events = events;
|
|
2278
2460
|
exports.help = help;
|
|
@@ -2280,5 +2462,6 @@ exports.init = init;
|
|
|
2280
2462
|
exports.pushCookie = pushCookie;
|
|
2281
2463
|
exports.ready = ready;
|
|
2282
2464
|
exports.submitEmail = submitEmail;
|
|
2465
|
+
exports.widget = widget;
|
|
2283
2466
|
exports.widgets = widgets;
|
|
2284
2467
|
//# sourceMappingURL=squatch.js.map
|