@saasquatch/squatch-js 2.4.3-4 → 2.4.3

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/dist/squatch.js CHANGED
@@ -49,45 +49,6 @@ 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
- }
91
52
  function doGet(url, jwt = "") {
92
53
  const headers = {
93
54
  Accept: "application/json",
@@ -224,21 +185,12 @@ function validateConfig(raw) {
224
185
  npmCdn
225
186
  };
226
187
  }
227
- function validateLocale(locale) {
228
- if (locale && /^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(locale)) {
229
- return locale;
230
- }
231
- }
232
188
  function validateWidgetConfig(raw) {
233
189
  if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
234
190
  if (!assertProp(raw, "user")) ; // TODO: This should be better type checked
235
191
 
236
192
  return raw;
237
193
  }
238
- function validatePasswordlessConfig(raw) {
239
- if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
240
- return raw;
241
- }
242
194
 
243
195
  /**
244
196
  *
@@ -271,6 +223,39 @@ class WidgetApi {
271
223
  this.domain = clean.domain;
272
224
  this.npmCdn = clean.npmCdn;
273
225
  }
226
+ /**
227
+ * Creates/upserts an anonymous user.
228
+ *
229
+ * @param {Object} params Parameters for request
230
+ * @param {WidgetType} params.widgetType The content of the widget.
231
+ * @param {EngagementMedium} params.engagementMedium How to display the widget.
232
+ * @param {CookieUser} params.user An optional user object
233
+ * @param {string} params.jwt the JSON Web Token (JWT) that is used to
234
+ * validate the data (can be disabled)
235
+ *
236
+ * @return {Promise} json object if true, with the widget template, jsOptions and user details.
237
+ */
238
+
239
+
240
+ cookieUser(params) {
241
+ // validateInput(params, CookieUserSchema);
242
+ const {
243
+ widgetType,
244
+ engagementMedium = "POPUP",
245
+ jwt,
246
+ user
247
+ } = params;
248
+ const tenantAlias = encodeURIComponent(this.tenantAlias);
249
+
250
+ const optionalParams = _buildParams({
251
+ widgetType,
252
+ engagementMedium
253
+ });
254
+
255
+ const path = `/api/v1/${tenantAlias}/widget/user/cookie_user${optionalParams}`;
256
+ const url = this.domain + path;
257
+ return doPut(url, JSON.stringify(user ? user : {}), jwt);
258
+ }
274
259
  /**
275
260
  * Creates/upserts user.
276
261
  *
@@ -327,10 +312,8 @@ class WidgetApi {
327
312
 
328
313
 
329
314
  render(params) {
330
- var _clean$locale;
331
-
332
315
  const raw = params;
333
- const clean = validatePasswordlessConfig(raw);
316
+ const clean = validateWidgetConfig(raw);
334
317
  const {
335
318
  widgetType,
336
319
  engagementMedium = "POPUP",
@@ -338,44 +321,17 @@ class WidgetApi {
338
321
  user
339
322
  } = clean;
340
323
  const tenantAlias = encodeURIComponent(this.tenantAlias);
341
- const accountId = user ? encodeURIComponent(user.accountId) : null;
342
- const userId = user ? encodeURIComponent(user.id) : null;
343
- const locale = (_clean$locale = clean.locale) != null ? _clean$locale : validateLocale(navigator.language.replace(/\-/g, "_"));
344
- const query = `
345
- query renderWidget ($user: UserIdInput, $engagementMedium: UserEngagementMedium, $widgetType: WidgetType, $locale: RSLocale) {
346
- renderWidget(user: $user, engagementMedium: $engagementMedium, widgetType: $widgetType, locale: $locale) {
347
- template
348
- user {
349
- id
350
- accountId
351
- }
352
- jsOptions
353
- widgetConfig {
354
- values
355
- }
356
- }
357
- }
358
- `;
359
- const path = `/api/v1/${tenantAlias}/graphql`;
360
- const url = this.domain + path;
361
- return new Promise(async (resolve, reject) => {
362
- try {
363
- var _res$body, _res$body$data;
364
-
365
- const res = await doQuery(url, query, {
366
- user: userId && accountId ? {
367
- id: userId,
368
- accountId
369
- } : null,
370
- engagementMedium,
371
- widgetType,
372
- locale
373
- }, jwt);
374
- 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);
375
- } catch (e) {
376
- reject(e);
377
- }
324
+ const accountId = encodeURIComponent(user.accountId);
325
+ const userId = encodeURIComponent(user.id);
326
+
327
+ const optionalParams = _buildParams({
328
+ widgetType,
329
+ engagementMedium
378
330
  });
331
+
332
+ const path = `/api/v1/${tenantAlias}/widget/account/${accountId}/user/${userId}/render${optionalParams}`;
333
+ const url = this.domain + path;
334
+ return doGet(url, jwt);
379
335
  }
380
336
  /**
381
337
  * An API call to send out referral invites to contacts
@@ -409,18 +365,21 @@ class WidgetApi {
409
365
  /**
410
366
  * Looks up the referral code of the current user, if there is any.
411
367
  *
412
- * @return {Promise<Object>} code referral code if true.
368
+ * @return {Promise<ReferralCookie>} code referral code if true.
413
369
  */
414
370
 
415
371
 
416
- squatchReferralCookie() {
372
+ async squatchReferralCookie() {
417
373
  const tenantAlias = encodeURIComponent(this.tenantAlias);
418
374
 
419
- const _saasquatch = Cookies__default['default'].get("_saasquatch");
375
+ const _saasquatch = Cookies__default['default'].get("_saasquatch") || "";
420
376
 
421
377
  const cookie = _saasquatch ? `?cookies=${encodeURIComponent(_saasquatch)}` : ``;
422
378
  const url = `${this.domain}/a/${tenantAlias}/widgets/squatchcookiejson${cookie}`;
423
- return doGet(url);
379
+ const response = await doGet(url);
380
+ return Promise.resolve(_extends({}, response, {
381
+ encodedCookie: _saasquatch
382
+ }));
424
383
  }
425
384
 
426
385
  } // builds a param string for widgets
@@ -463,7 +422,6 @@ class AnalyticsApi {
463
422
  }
464
423
 
465
424
  pushAnalyticsLoadEvent(params) {
466
- if (!params.externalUserId || !params.externalAccountId) return;
467
425
  const tenantAlias = encodeURIComponent(params.tenantAlias);
468
426
  const accountId = encodeURIComponent(params.externalAccountId);
469
427
  const userId = encodeURIComponent(params.externalUserId);
@@ -490,7 +448,7 @@ class AnalyticsApi {
490
448
  // @ts-check
491
449
  /** @hidden */
492
450
 
493
- const _log$7 = debug__default['default']("squatch-js:widget");
451
+ const _log$6 = debug__default['default']("squatch-js:widget");
494
452
  /*
495
453
  * The Widget class is the base class for the different widget types available
496
454
  *
@@ -503,7 +461,7 @@ const _log$7 = debug__default['default']("squatch-js:widget");
503
461
 
504
462
  class Widget {
505
463
  constructor(params) {
506
- _log$7("widget initializing ...");
464
+ _log$6("widget initializing ...");
507
465
 
508
466
  this.content = params.content === "error" ? this._error(params.rsCode) : params.content;
509
467
  this.type = params.type;
@@ -521,8 +479,6 @@ class Widget {
521
479
  }
522
480
 
523
481
  _loadEvent(sqh) {
524
- var _this$analyticsApi$pu;
525
-
526
482
  if (!sqh) return; // No non-truthy value
527
483
 
528
484
  if (!isObject$1(sqh)) {
@@ -556,10 +512,10 @@ class Widget {
556
512
  };
557
513
  }
558
514
 
559
- (_this$analyticsApi$pu = this.analyticsApi.pushAnalyticsLoadEvent(params)) == null ? void 0 : _this$analyticsApi$pu.then(response => {
560
- _log$7(`${params.engagementMedium} loaded event recorded.`);
515
+ this.analyticsApi.pushAnalyticsLoadEvent(params).then(response => {
516
+ _log$6(`${params.engagementMedium} loaded event recorded.`);
561
517
  }).catch(ex => {
562
- _log$7(new Error(`pushAnalyticsLoadEvent() ${ex}`));
518
+ _log$6(new Error(`pushAnalyticsLoadEvent() ${ex}`));
563
519
  });
564
520
  }
565
521
 
@@ -572,9 +528,9 @@ class Widget {
572
528
  engagementMedium: sqh.mode.widgetMode,
573
529
  shareMedium: medium
574
530
  }).then(response => {
575
- _log$7(`${sqh.mode.widgetMode} share ${medium} event recorded. ${response}`);
531
+ _log$6(`${sqh.mode.widgetMode} share ${medium} event recorded. ${response}`);
576
532
  }).catch(ex => {
577
- _log$7(new Error(`pushAnalyticsLoadEvent() ${ex}`));
533
+ _log$6(new Error(`pushAnalyticsLoadEvent() ${ex}`));
578
534
  });
579
535
  }
580
536
  }
@@ -587,9 +543,9 @@ class Widget {
587
543
  userId: sqh.analytics.attributes.userId,
588
544
  emailList
589
545
  }).then(response => {
590
- _log$7(`Sent email invites to share ${emailList}. ${response}`);
546
+ _log$6(`Sent email invites to share ${emailList}. ${response}`);
591
547
  }).catch(ex => {
592
- _log$7(new Error(`invite() ${ex}`));
548
+ _log$6(new Error(`invite() ${ex}`));
593
549
  });
594
550
  }
595
551
  }
@@ -678,7 +634,6 @@ class Widget {
678
634
  email: email || null,
679
635
  firstName: firstName || null,
680
636
  lastName: lastName || null,
681
- // FIXME: Double check this
682
637
  id: this.context.user.id,
683
638
  accountId: this.context.user.accountId
684
639
  };
@@ -688,12 +643,17 @@ class Widget {
688
643
  widgetType: this.type,
689
644
  jwt
690
645
  });
691
- } else if (this.context.type === "passwordless") {
692
- response = this.widgetApi.render({
693
- user: undefined,
646
+ } else if (this.context.type === "cookie") {
647
+ let userObj = {
648
+ email: email || null,
649
+ firstName: firstName || null,
650
+ lastName: lastName || null
651
+ };
652
+ response = this.widgetApi.cookieUser({
653
+ user: userObj,
694
654
  engagementMedium,
695
655
  widgetType: this.type,
696
- jwt: undefined
656
+ jwt
697
657
  });
698
658
  } else {
699
659
  throw new Error("can't reload an error widget");
@@ -729,7 +689,7 @@ class Widget {
729
689
  }).catch(({
730
690
  message
731
691
  }) => {
732
- _log$7(`${message}`);
692
+ _log$6(`${message}`);
733
693
  });
734
694
  }
735
695
 
@@ -766,7 +726,7 @@ function domready(targetDoc, fn) {
766
726
 
767
727
  // @ts-check
768
728
 
769
- const _log$6 = debug__default['default']("squatch-js:EMBEDwidget");
729
+ const _log$5 = debug__default['default']("squatch-js:EMBEDwidget");
770
730
  /**
771
731
  * An EmbedWidget is displayed inline in part of your page.
772
732
  *
@@ -784,22 +744,22 @@ class EmbedWidget extends Widget {
784
744
  // selector is a string
785
745
  element = document.querySelector(container);
786
746
 
787
- _log$6("loading widget with selector", element); // selector is an HTML element
747
+ _log$5("loading widget with selector", element); // selector is an HTML element
788
748
 
789
749
  } else if (container instanceof HTMLElement) {
790
750
  element = container;
791
751
 
792
- _log$6("loading widget with container", element); // garbage container found
752
+ _log$5("loading widget with container", element); // garbage container found
793
753
 
794
754
  } else if (container) {
795
755
  element = null;
796
756
 
797
- _log$6("container must be an HTMLElement or string", container); // find element on page
757
+ _log$5("container must be an HTMLElement or string", container); // find element on page
798
758
 
799
759
  } else {
800
760
  element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed");
801
761
 
802
- _log$6("loading widget with default selector", element);
762
+ _log$5("loading widget with default selector", element);
803
763
  }
804
764
 
805
765
  if (!(element instanceof HTMLElement)) throw new Error(`element with selector '${container}' not found.'`);
@@ -865,7 +825,7 @@ class EmbedWidget extends Widget {
865
825
  if (!this.context.container) {
866
826
  this._loadEvent(_sqh);
867
827
 
868
- _log$6("loaded");
828
+ _log$5("loaded");
869
829
  }
870
830
  });
871
831
  } // Un-hide if element is available and refresh data
@@ -874,7 +834,7 @@ class EmbedWidget extends Widget {
874
834
  open() {
875
835
  var _this$frame, _this$frame$contentDo, _this$frame2, _this$frame2$contentW, _this$frame3, _this$frame3$contentW;
876
836
 
877
- if (!this.frame) return _log$6("no target element to open");
837
+ if (!this.frame) return _log$5("no target element to open");
878
838
  this.element.style.visibility = "unset";
879
839
  this.element.style.height = "auto";
880
840
  this.element.style["overflow-y"] = "auto";
@@ -884,16 +844,16 @@ class EmbedWidget extends Widget {
884
844
 
885
845
  this._loadEvent(_sqh);
886
846
 
887
- _log$6("loaded");
847
+ _log$5("loaded");
888
848
  }
889
849
 
890
850
  close() {
891
- if (!this.frame) return _log$6("no target element to close");
851
+ if (!this.frame) return _log$5("no target element to close");
892
852
  this.element.style.visibility = "hidden";
893
853
  this.element.style.height = "0";
894
854
  this.element.style["overflow-y"] = "hidden";
895
855
 
896
- _log$6("Embed widget closed");
856
+ _log$5("Embed widget closed");
897
857
  }
898
858
 
899
859
  _error(rs, mode = "embed", style = "") {
@@ -904,7 +864,7 @@ class EmbedWidget extends Widget {
904
864
 
905
865
  // @ts-check
906
866
 
907
- const _log$5 = debug__default['default']("squatch-js:POPUPwidget");
867
+ const _log$4 = debug__default['default']("squatch-js:POPUPwidget");
908
868
  /**
909
869
  * The PopupWidget is used to display popups (also known as "Modals").
910
870
  * Popups widgets are rendered on top of other elements in a page.
@@ -922,9 +882,9 @@ class PopupWidget extends Widget {
922
882
  this.triggerElement
923
883
  /* HTMLButton */
924
884
  = document.querySelector(trigger);
925
- if (trigger && !this.triggerElement) _log$5("No element found with trigger selector", trigger);
885
+ if (trigger && !this.triggerElement) _log$4("No element found with trigger selector", trigger);
926
886
  } catch (_unused) {
927
- _log$5("Not a valid selector", trigger);
887
+ _log$4("Not a valid selector", trigger);
928
888
  } // Trigger is optional
929
889
 
930
890
 
@@ -966,7 +926,7 @@ class PopupWidget extends Widget {
966
926
  frameDoc.write(`<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"></script>`);
967
927
  frameDoc.close();
968
928
 
969
- _log$5("Popup template loaded into iframe");
929
+ _log$4("Popup template loaded into iframe");
970
930
 
971
931
  this._setupResizeHandler();
972
932
  }
@@ -1039,7 +999,7 @@ class PopupWidget extends Widget {
1039
999
 
1040
1000
  this._loadEvent(_sqh);
1041
1001
 
1042
- _log$5("Popup opened");
1002
+ _log$4("Popup opened");
1043
1003
  });
1044
1004
  }
1045
1005
 
@@ -1047,7 +1007,7 @@ class PopupWidget extends Widget {
1047
1007
  this.popupdiv.style.visibility = "hidden";
1048
1008
  this.popupdiv.style.top = "-2000px";
1049
1009
 
1050
- _log$5("Popup closed");
1010
+ _log$4("Popup closed");
1051
1011
  }
1052
1012
 
1053
1013
  _clickedOutside({
@@ -1065,7 +1025,7 @@ class PopupWidget extends Widget {
1065
1025
 
1066
1026
  }
1067
1027
 
1068
- const _log$4 = debug__namespace("squatch-js:CTAwidget");
1028
+ const _log$3 = debug__namespace("squatch-js:CTAwidget");
1069
1029
  /**
1070
1030
  * A CtaWidget is displayed on top of your page
1071
1031
  *
@@ -1076,7 +1036,7 @@ const _log$4 = debug__namespace("squatch-js:CTAwidget");
1076
1036
 
1077
1037
  class CtaWidget extends PopupWidget {
1078
1038
  constructor(params, opts) {
1079
- _log$4("CTA constructor");
1039
+ _log$3("CTA constructor");
1080
1040
 
1081
1041
  const ctaElement = document.createElement("div");
1082
1042
  ctaElement.id = "cta";
@@ -1104,7 +1064,7 @@ class CtaWidget extends PopupWidget {
1104
1064
  this.ctaFrame.setAttribute("style", `border:0; background-color:transparent; position:fixed; display:none;${this.side}${this.position}`);
1105
1065
  document.body.appendChild(this.ctaFrame);
1106
1066
 
1107
- _log$4("ctaframe appended to body");
1067
+ _log$3("ctaframe appended to body");
1108
1068
  }
1109
1069
 
1110
1070
  load() {
@@ -1168,10 +1128,10 @@ class CtaWidget extends PopupWidget {
1168
1128
  });
1169
1129
  ro.observe(ctaContainer);
1170
1130
 
1171
- _log$4("CTA template loaded into iframe");
1131
+ _log$3("CTA template loaded into iframe");
1172
1132
  });
1173
1133
  } else {
1174
- _log$4(new Error("CTA element not found in theme"));
1134
+ _log$3(new Error("CTA element not found in theme"));
1175
1135
  }
1176
1136
  });
1177
1137
  }
@@ -1194,7 +1154,7 @@ class CtaWidget extends PopupWidget {
1194
1154
 
1195
1155
  }
1196
1156
 
1197
- const _log$3 = debug__default['default']("squatch-js:widgets");
1157
+ const _log$2 = debug__default['default']("squatch-js:widgets");
1198
1158
  /**
1199
1159
  *
1200
1160
  * `Widgets` is a factory for creating widgets. It's possible to build your own widgets using the
@@ -1232,6 +1192,41 @@ class Widgets {
1232
1192
 
1233
1193
  EventBus__namespace.addEventListener("submit_email", Widgets._cb);
1234
1194
  }
1195
+ /**
1196
+ * This function calls the {@link WidgetApi.cookieUser} method, and it renders
1197
+ * the widget if it is successful. Otherwise it shows the "error" widget.
1198
+ *
1199
+ * @param {Object} config Config details
1200
+ * @param {WidgetType} config.widgetType The content of the widget.
1201
+ * @param {EngagementMedium} config.engagementMedium How to display the widget.
1202
+ * @param {User} config.user An optional user to include
1203
+ * @param {string} config.jwt the JSON Web Token (JWT) that is used to
1204
+ * validate the data (can be disabled)
1205
+ *
1206
+ * @return {Promise<WidgetResult>} json object if true, with a Widget and user details.
1207
+ */
1208
+
1209
+
1210
+ async createCookieUser(config) {
1211
+ try {
1212
+ const response = await this.api.cookieUser(config);
1213
+ return {
1214
+ widget: this._renderWidget(response, config, {
1215
+ type: "cookie",
1216
+ engagementMedium: config.engagementMedium
1217
+ }),
1218
+ user: response.user
1219
+ };
1220
+ } catch (err) {
1221
+ _log$2(err);
1222
+
1223
+ if (err.apiErrorCode) {
1224
+ this._renderErrorWidget(err, config.engagementMedium);
1225
+ }
1226
+
1227
+ throw err;
1228
+ }
1229
+ }
1235
1230
  /**
1236
1231
  * This function calls the {@link WidgetApi.upsertUser} method, and it renders
1237
1232
  * the widget if it is successful. Otherwise it shows the "error" widget.
@@ -1259,7 +1254,7 @@ class Widgets {
1259
1254
  return {
1260
1255
  widget: this._renderWidget(response, clean, {
1261
1256
  type: "upsert",
1262
- user: clean.user || null,
1257
+ user: clean.user,
1263
1258
  engagementMedium: config.engagementMedium,
1264
1259
  container: config.container,
1265
1260
  trigger: config.trigger
@@ -1267,7 +1262,7 @@ class Widgets {
1267
1262
  user: response.user
1268
1263
  };
1269
1264
  } catch (err) {
1270
- _log$3(err);
1265
+ _log$2(err);
1271
1266
 
1272
1267
  if (err.apiErrorCode) {
1273
1268
  this._renderErrorWidget(err, config.engagementMedium);
@@ -1295,13 +1290,15 @@ class Widgets {
1295
1290
 
1296
1291
  async render(config) {
1297
1292
  const raw = config;
1298
- const clean = validatePasswordlessConfig(raw);
1293
+ const clean = validateWidgetConfig(raw);
1299
1294
 
1300
1295
  try {
1301
- const response = await this.api.render(clean);
1296
+ const response = await this.api.cookieUser(clean);
1302
1297
  return {
1303
- widget: this._renderWidget(response, clean, {
1304
- type: "passwordless",
1298
+ widget: this._renderWidget({
1299
+ template: response
1300
+ }, clean, {
1301
+ type: "cookie",
1305
1302
  engagementMedium: clean.engagementMedium
1306
1303
  }),
1307
1304
  user: response.user
@@ -1328,7 +1325,7 @@ class Widgets {
1328
1325
 
1329
1326
  if (typeof input === "function") {
1330
1327
  this.api.squatchReferralCookie().then((...args) => input(...args)).catch(ex => {
1331
- _log$3("Autofill error", ex);
1328
+ _log$2("Autofill error", ex);
1332
1329
 
1333
1330
  throw ex;
1334
1331
  });
@@ -1343,7 +1340,7 @@ class Widgets {
1343
1340
  // Only use the first element found
1344
1341
  elem = elems[0];
1345
1342
  } else {
1346
- _log$3("Element id/class or function missing");
1343
+ _log$2("Element id/class or function missing");
1347
1344
 
1348
1345
  throw new Error("Element id/class or function missing");
1349
1346
  }
@@ -1381,11 +1378,11 @@ class Widgets {
1381
1378
 
1382
1379
 
1383
1380
  _renderWidget(response, config, context) {
1384
- _log$3("Rendering Widget...");
1381
+ _log$2("Rendering Widget...");
1385
1382
 
1386
1383
  if (!response) throw new Error("Unable to get a response");
1387
1384
  let widget;
1388
- let displayOnLoad = !!config.displayOnLoad;
1385
+ let displayOnLoad = false;
1389
1386
  let displayCTA = false;
1390
1387
  const opts = response.jsOptions || "";
1391
1388
  const params = {
@@ -1404,9 +1401,9 @@ class Widgets {
1404
1401
  displayOnLoad = rule.displayOnLoad;
1405
1402
  displayCTA = rule.showAsCTA;
1406
1403
 
1407
- _log$3(`Display ${rule.widgetType} on ${rule.url}`);
1404
+ _log$2(`Display ${rule.widgetType} on ${rule.url}`);
1408
1405
  } else {
1409
- _log$3(`Don't display ${rule.widgetType} when no referral on widget rule match ${rule.url}`);
1406
+ _log$2(`Don't display ${rule.widgetType} when no referral on widget rule match ${rule.url}`);
1410
1407
  }
1411
1408
  }
1412
1409
  });
@@ -1415,20 +1412,20 @@ class Widgets {
1415
1412
  if (opts.conversionUrls) {
1416
1413
  opts.conversionUrls.forEach(rule => {
1417
1414
  if (response.user.referredBy && Widgets._matchesUrl(rule)) {
1418
- _log$3("This is a conversion URL", rule);
1415
+ _log$2("This is a conversion URL", rule);
1419
1416
  }
1420
1417
  });
1421
1418
  }
1422
1419
 
1423
1420
  if (opts.fuelTankAutofillUrls) {
1424
- _log$3("We found a fuel tank autofill!");
1421
+ _log$2("We found a fuel tank autofill!");
1425
1422
 
1426
1423
  opts.fuelTankAutofillUrls.forEach(({
1427
1424
  url,
1428
1425
  formSelector
1429
1426
  }) => {
1430
1427
  if (Widgets._matchesUrl(url)) {
1431
- _log$3("Fuel Tank URL matches");
1428
+ _log$2("Fuel Tank URL matches");
1432
1429
 
1433
1430
  if (response.user.referredBy && response.user.referredBy.code) {
1434
1431
  const formAutofill = document.querySelector(formSelector);
@@ -1436,7 +1433,7 @@ class Widgets {
1436
1433
  if (formAutofill) {
1437
1434
  formAutofill.value = response.user.referredBy.referredReward.fuelTankCode || "";
1438
1435
  } else {
1439
- _log$3(new Error(`Element with id/class ${formSelector} was not found.`));
1436
+ _log$2(new Error(`Element with id/class ${formSelector} was not found.`));
1440
1437
  }
1441
1438
  }
1442
1439
  }
@@ -1451,7 +1448,7 @@ class Widgets {
1451
1448
  widget.load();
1452
1449
  if (displayOnLoad) widget.open();
1453
1450
  } else if (displayCTA) {
1454
- _log$3("display CTA");
1451
+ _log$2("display CTA");
1455
1452
 
1456
1453
  const side = opts.cta.content.buttonSide;
1457
1454
  const position = opts.cta.content.buttonPosition;
@@ -1462,7 +1459,7 @@ class Widgets {
1462
1459
  widget.load();
1463
1460
  if (displayOnLoad) widget.open();
1464
1461
  } else {
1465
- _log$3("display popup on load");
1462
+ _log$2("display popup on load");
1466
1463
 
1467
1464
  widget = new PopupWidget(params);
1468
1465
  widget.load();
@@ -1486,7 +1483,7 @@ class Widgets {
1486
1483
  message
1487
1484
  } = props;
1488
1485
 
1489
- _log$3(new Error(`${apiErrorCode} (${rsCode}) ${message}`));
1486
+ _log$2(new Error(`${apiErrorCode} (${rsCode}) ${message}`));
1490
1487
 
1491
1488
  const params = {
1492
1489
  content: "error",
@@ -1626,8 +1623,7 @@ function asyncLoad() {
1626
1623
 
1627
1624
  if (loaded && cached) {
1628
1625
  const ready = cached.ready || [];
1629
- ready.forEach(cb => setTimeout(() => cb(), 0));
1630
- setTimeout(() => window.squatch.auto(), 0); // @ts-ignore -- intetionally deletes `_squatch` to cleanup initialization
1626
+ ready.forEach(cb => setTimeout(() => cb(), 0)); // @ts-ignore -- intetionally deletes `_squatch` to cleanup initialization
1631
1627
 
1632
1628
  window._squatch = undefined;
1633
1629
 
@@ -2017,7 +2013,7 @@ var URLSearchParams$1 = self.URLSearchParams;
2017
2013
 
2018
2014
  /** @hidden */
2019
2015
 
2020
- const _log$2 = debug__default['default']("squatch-js");
2016
+ const _log$1 = debug__default['default']("squatch-js");
2021
2017
 
2022
2018
  const isObject = item => typeof item === "object" && !Array.isArray(item);
2023
2019
 
@@ -2070,7 +2066,7 @@ function _pushCookie() {
2070
2066
  try {
2071
2067
  paramsJSON = JSON.parse(b64decode(refParam));
2072
2068
  } catch (error) {
2073
- _log$2("Unable to decode params", error); // don't merge invalid params
2069
+ _log$1("Unable to decode params", error); // don't merge invalid params
2074
2070
 
2075
2071
 
2076
2072
  return;
@@ -2079,26 +2075,26 @@ function _pushCookie() {
2079
2075
  try {
2080
2076
  existingCookie = JSON.parse(b64decode(Cookies__default['default'].get("_saasquatch")));
2081
2077
 
2082
- _log$2("existing cookie", existingCookie);
2078
+ _log$1("existing cookie", existingCookie);
2083
2079
  } catch (error) {
2084
- _log$2("Unable to retrieve cookie", error);
2080
+ _log$1("Unable to retrieve cookie", error);
2085
2081
  } // don't merge if there's no existing object
2086
2082
 
2087
2083
 
2088
2084
  try {
2089
2085
  const domain = getTopDomain();
2090
2086
 
2091
- _log$2("domain retrieved:", domain);
2087
+ _log$1("domain retrieved:", domain);
2092
2088
 
2093
2089
  if (existingCookie) {
2094
2090
  const newCookie = deepMerge(existingCookie, paramsJSON);
2095
2091
  reEncodedCookie = b64encode(JSON.stringify(newCookie));
2096
2092
 
2097
- _log$2("cookie to store:", newCookie);
2093
+ _log$1("cookie to store:", newCookie);
2098
2094
  } else {
2099
2095
  reEncodedCookie = b64encode(JSON.stringify(paramsJSON));
2100
2096
 
2101
- _log$2("cookie to store:", paramsJSON);
2097
+ _log$1("cookie to store:", paramsJSON);
2102
2098
  }
2103
2099
 
2104
2100
  Cookies__default['default'].set("_saasquatch", reEncodedCookie, {
@@ -2109,86 +2105,11 @@ function _pushCookie() {
2109
2105
  path: "/"
2110
2106
  });
2111
2107
  } catch (error) {
2112
- _log$2("Unable to set cookie", error);
2108
+ _log$1("Unable to set cookie", error);
2113
2109
  }
2114
2110
  }
2115
2111
  }
2116
2112
 
2117
- /** @hidden */
2118
-
2119
- const _log$1 = debug__default['default']("squatch-js");
2120
-
2121
- function _getAutoConfig(configIn) {
2122
- const queryString = window.location.search;
2123
- const urlParams = new URLSearchParams(queryString);
2124
- const refParam = urlParams.get("_saasquatchExtra") || "";
2125
-
2126
- if (!refParam) {
2127
- _log$1("No _saasquatchExtra param");
2128
-
2129
- return;
2130
- }
2131
-
2132
- let raw;
2133
-
2134
- try {
2135
- raw = JSON.parse(b64decode(refParam));
2136
- } catch (e) {
2137
- _log$1("Unable to decode _saasquatchExtra config");
2138
-
2139
- return;
2140
- }
2141
-
2142
- const {
2143
- domain,
2144
- tenantAlias,
2145
- widgetConfig
2146
- } = convertExtraToConfig(raw);
2147
-
2148
- if (!domain || !tenantAlias || !widgetConfig) {
2149
- _log$1("_saasquatchExtra did not have an expected structure");
2150
-
2151
- return undefined;
2152
- }
2153
-
2154
- const {
2155
- autoPopupWidgetType
2156
- } = widgetConfig,
2157
- rest = _objectWithoutPropertiesLoose(widgetConfig, ["autoPopupWidgetType"]);
2158
-
2159
- return {
2160
- widgetConfig: _extends({
2161
- widgetType: autoPopupWidgetType,
2162
- displayOnLoad: true
2163
- }, rest),
2164
- squatchConfig: _extends({}, configIn ? {
2165
- configIn
2166
- } : {}, {
2167
- domain,
2168
- tenantAlias
2169
- })
2170
- };
2171
- }
2172
- /**
2173
- * Converts _saasquatchExtra into
2174
- * @param obj
2175
- */
2176
-
2177
- function convertExtraToConfig(obj) {
2178
- var _obj$_domain;
2179
-
2180
- const _domain = Object.keys(obj || {})[0];
2181
- const tenantAlias = Object.keys((obj == null ? void 0 : obj[_domain]) || {})[0];
2182
- const widgetConfig = obj == null ? void 0 : (_obj$_domain = obj[_domain]) == null ? void 0 : _obj$_domain[tenantAlias]; // domain in _saasquatchExtra doesn't contain "https://"
2183
-
2184
- const domain = _domain ? `https://${_domain}` : undefined;
2185
- return {
2186
- domain,
2187
- tenantAlias,
2188
- widgetConfig
2189
- };
2190
- }
2191
-
2192
2113
  // @ts-check
2193
2114
  function help() {
2194
2115
  console.log(`Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes.`);
@@ -2242,35 +2163,6 @@ function widgets() {
2242
2163
  function events() {
2243
2164
  return _events;
2244
2165
  }
2245
- /**
2246
- * Entry-point for high level API to render a widget using the instance of {@link Widgets} created when you call {@link #init init}.
2247
- */
2248
-
2249
- function widget(widgetConfig) {
2250
- var _widgets2;
2251
-
2252
- return (_widgets2 = widgets()) == null ? void 0 : _widgets2.render(widgetConfig);
2253
- }
2254
- /**
2255
- * Initial concept for automatic widget rendering
2256
- *
2257
- * - `saasquatchExtra` utm param carries widgetIdent
2258
- */
2259
-
2260
- function auto(configIn) {
2261
- const configs = _getAutoConfig(configIn);
2262
-
2263
- if (configs) {
2264
- var _widgets3;
2265
-
2266
- const {
2267
- squatchConfig,
2268
- widgetConfig
2269
- } = configs;
2270
- init(squatchConfig);
2271
- return (_widgets3 = widgets()) == null ? void 0 : _widgets3.render(widgetConfig);
2272
- }
2273
- }
2274
2166
  /**
2275
2167
  * Initializes the static `squatch` global. This sets up:
2276
2168
  *
@@ -2313,7 +2205,7 @@ function init(configIn) {
2313
2205
  * @example
2314
2206
  * squatch.ready(function() {
2315
2207
  * console.log("ready!");
2316
- * squatch.api().upsertUser();
2208
+ * squatch.api().cookieUser();
2317
2209
  * });
2318
2210
  */
2319
2211
 
@@ -2381,7 +2273,6 @@ exports.PopupWidget = PopupWidget;
2381
2273
  exports.WidgetApi = WidgetApi;
2382
2274
  exports.Widgets = Widgets;
2383
2275
  exports.api = api;
2384
- exports.auto = auto;
2385
2276
  exports.autofill = autofill;
2386
2277
  exports.events = events;
2387
2278
  exports.help = help;
@@ -2389,6 +2280,5 @@ exports.init = init;
2389
2280
  exports.pushCookie = pushCookie;
2390
2281
  exports.ready = ready;
2391
2282
  exports.submitEmail = submitEmail;
2392
- exports.widget = widget;
2393
2283
  exports.widgets = widgets;
2394
2284
  //# sourceMappingURL=squatch.js.map