@saasquatch/squatch-js 2.4.3-3 → 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.
@@ -22,45 +22,6 @@ function _extends() {
22
22
  return _extends.apply(this, arguments);
23
23
  }
24
24
 
25
- function _objectWithoutPropertiesLoose(source, excluded) {
26
- if (source == null) return {};
27
- var target = {};
28
- var sourceKeys = Object.keys(source);
29
- var key, i;
30
-
31
- for (i = 0; i < sourceKeys.length; i++) {
32
- key = sourceKeys[i];
33
- if (excluded.indexOf(key) >= 0) continue;
34
- target[key] = source[key];
35
- }
36
-
37
- return target;
38
- }
39
-
40
- function doQuery(url, query, variables, token) {
41
- const headers = _extends({
42
- Accept: "application/json"
43
- }, token ? {
44
- Authorization: `Bearer ${token}`
45
- } : {}, {
46
- "X-SaaSquatch-Referrer": window ? window.location.href : ""
47
- });
48
-
49
- const request = superagent.post(url).send({
50
- query,
51
- variables
52
- }).set(headers);
53
- return thenableSuperagent(request).then(response => response, error => {
54
- let json;
55
-
56
- try {
57
- json = JSON.parse(error.response.text);
58
- } catch (e) {
59
- }
60
-
61
- throw json;
62
- });
63
- }
64
25
  function doGet(url, jwt = "") {
65
26
  const headers = {
66
27
  Accept: "application/json",
@@ -203,10 +164,6 @@ function validateWidgetConfig(raw) {
203
164
 
204
165
  return raw;
205
166
  }
206
- function validatePasswordlessConfig(raw) {
207
- if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
208
- return raw;
209
- }
210
167
 
211
168
  /**
212
169
  *
@@ -239,6 +196,39 @@ class WidgetApi {
239
196
  this.domain = clean.domain;
240
197
  this.npmCdn = clean.npmCdn;
241
198
  }
199
+ /**
200
+ * Creates/upserts an anonymous user.
201
+ *
202
+ * @param {Object} params Parameters for request
203
+ * @param {WidgetType} params.widgetType The content of the widget.
204
+ * @param {EngagementMedium} params.engagementMedium How to display the widget.
205
+ * @param {CookieUser} params.user An optional user object
206
+ * @param {string} params.jwt the JSON Web Token (JWT) that is used to
207
+ * validate the data (can be disabled)
208
+ *
209
+ * @return {Promise} json object if true, with the widget template, jsOptions and user details.
210
+ */
211
+
212
+
213
+ cookieUser(params) {
214
+ // validateInput(params, CookieUserSchema);
215
+ const {
216
+ widgetType,
217
+ engagementMedium = "POPUP",
218
+ jwt,
219
+ user
220
+ } = params;
221
+ const tenantAlias = encodeURIComponent(this.tenantAlias);
222
+
223
+ const optionalParams = _buildParams({
224
+ widgetType,
225
+ engagementMedium
226
+ });
227
+
228
+ const path = `/api/v1/${tenantAlias}/widget/user/cookie_user${optionalParams}`;
229
+ const url = this.domain + path;
230
+ return doPut(url, JSON.stringify(user ? user : {}), jwt);
231
+ }
242
232
  /**
243
233
  * Creates/upserts user.
244
234
  *
@@ -296,7 +286,7 @@ class WidgetApi {
296
286
 
297
287
  render(params) {
298
288
  const raw = params;
299
- const clean = validatePasswordlessConfig(raw);
289
+ const clean = validateWidgetConfig(raw);
300
290
  const {
301
291
  widgetType,
302
292
  engagementMedium = "POPUP",
@@ -304,43 +294,17 @@ class WidgetApi {
304
294
  user
305
295
  } = clean;
306
296
  const tenantAlias = encodeURIComponent(this.tenantAlias);
307
- const accountId = user ? encodeURIComponent(user.accountId) : null;
308
- const userId = user ? encodeURIComponent(user.id) : null; // TODO: Add locale as parameter to renderWidget
309
-
310
- const query = `
311
- query renderWidget ($user: UserIdInput, $engagementMedium: UserEngagementMedium, $widgetType: WidgetType) {
312
- renderWidget(user: $user, engagementMedium: $engagementMedium, widgetType: $widgetType) {
313
- template
314
- user {
315
- id
316
- accountId
317
- }
318
- jsOptions
319
- widgetConfig {
320
- values
321
- }
322
- }
323
- }
324
- `;
325
- const path = `/api/v1/${tenantAlias}/graphql`;
326
- const url = this.domain + path;
327
- return new Promise(async (resolve, reject) => {
328
- try {
329
- var _res$body, _res$body$data;
330
-
331
- const res = await doQuery(url, query, {
332
- user: userId && accountId ? {
333
- id: userId,
334
- accountId
335
- } : null,
336
- engagementMedium,
337
- widgetType
338
- }, jwt);
339
- 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);
340
- } catch (e) {
341
- reject(e);
342
- }
297
+ const accountId = encodeURIComponent(user.accountId);
298
+ const userId = encodeURIComponent(user.id);
299
+
300
+ const optionalParams = _buildParams({
301
+ widgetType,
302
+ engagementMedium
343
303
  });
304
+
305
+ const path = `/api/v1/${tenantAlias}/widget/account/${accountId}/user/${userId}/render${optionalParams}`;
306
+ const url = this.domain + path;
307
+ return doGet(url, jwt);
344
308
  }
345
309
  /**
346
310
  * An API call to send out referral invites to contacts
@@ -374,18 +338,21 @@ class WidgetApi {
374
338
  /**
375
339
  * Looks up the referral code of the current user, if there is any.
376
340
  *
377
- * @return {Promise<Object>} code referral code if true.
341
+ * @return {Promise<ReferralCookie>} code referral code if true.
378
342
  */
379
343
 
380
344
 
381
- squatchReferralCookie() {
345
+ async squatchReferralCookie() {
382
346
  const tenantAlias = encodeURIComponent(this.tenantAlias);
383
347
 
384
- const _saasquatch = Cookies.get("_saasquatch");
348
+ const _saasquatch = Cookies.get("_saasquatch") || "";
385
349
 
386
350
  const cookie = _saasquatch ? `?cookies=${encodeURIComponent(_saasquatch)}` : ``;
387
351
  const url = `${this.domain}/a/${tenantAlias}/widgets/squatchcookiejson${cookie}`;
388
- return doGet(url);
352
+ const response = await doGet(url);
353
+ return Promise.resolve(_extends({}, response, {
354
+ encodedCookie: _saasquatch
355
+ }));
389
356
  }
390
357
 
391
358
  } // builds a param string for widgets
@@ -428,7 +395,6 @@ class AnalyticsApi {
428
395
  }
429
396
 
430
397
  pushAnalyticsLoadEvent(params) {
431
- if (!params.externalUserId || !params.externalAccountId) return;
432
398
  const tenantAlias = encodeURIComponent(params.tenantAlias);
433
399
  const accountId = encodeURIComponent(params.externalAccountId);
434
400
  const userId = encodeURIComponent(params.externalUserId);
@@ -455,7 +421,7 @@ class AnalyticsApi {
455
421
  // @ts-check
456
422
  /** @hidden */
457
423
 
458
- const _log$7 = debug__default("squatch-js:widget");
424
+ const _log$6 = debug__default("squatch-js:widget");
459
425
  /*
460
426
  * The Widget class is the base class for the different widget types available
461
427
  *
@@ -468,7 +434,7 @@ const _log$7 = debug__default("squatch-js:widget");
468
434
 
469
435
  class Widget {
470
436
  constructor(params) {
471
- _log$7("widget initializing ...");
437
+ _log$6("widget initializing ...");
472
438
 
473
439
  this.content = params.content === "error" ? this._error(params.rsCode) : params.content;
474
440
  this.type = params.type;
@@ -486,8 +452,6 @@ class Widget {
486
452
  }
487
453
 
488
454
  _loadEvent(sqh) {
489
- var _this$analyticsApi$pu;
490
-
491
455
  if (!sqh) return; // No non-truthy value
492
456
 
493
457
  if (!isObject$1(sqh)) {
@@ -521,10 +485,10 @@ class Widget {
521
485
  };
522
486
  }
523
487
 
524
- (_this$analyticsApi$pu = this.analyticsApi.pushAnalyticsLoadEvent(params)) == null ? void 0 : _this$analyticsApi$pu.then(response => {
525
- _log$7(`${params.engagementMedium} loaded event recorded.`);
488
+ this.analyticsApi.pushAnalyticsLoadEvent(params).then(response => {
489
+ _log$6(`${params.engagementMedium} loaded event recorded.`);
526
490
  }).catch(ex => {
527
- _log$7(new Error(`pushAnalyticsLoadEvent() ${ex}`));
491
+ _log$6(new Error(`pushAnalyticsLoadEvent() ${ex}`));
528
492
  });
529
493
  }
530
494
 
@@ -537,9 +501,9 @@ class Widget {
537
501
  engagementMedium: sqh.mode.widgetMode,
538
502
  shareMedium: medium
539
503
  }).then(response => {
540
- _log$7(`${sqh.mode.widgetMode} share ${medium} event recorded. ${response}`);
504
+ _log$6(`${sqh.mode.widgetMode} share ${medium} event recorded. ${response}`);
541
505
  }).catch(ex => {
542
- _log$7(new Error(`pushAnalyticsLoadEvent() ${ex}`));
506
+ _log$6(new Error(`pushAnalyticsLoadEvent() ${ex}`));
543
507
  });
544
508
  }
545
509
  }
@@ -552,9 +516,9 @@ class Widget {
552
516
  userId: sqh.analytics.attributes.userId,
553
517
  emailList
554
518
  }).then(response => {
555
- _log$7(`Sent email invites to share ${emailList}. ${response}`);
519
+ _log$6(`Sent email invites to share ${emailList}. ${response}`);
556
520
  }).catch(ex => {
557
- _log$7(new Error(`invite() ${ex}`));
521
+ _log$6(new Error(`invite() ${ex}`));
558
522
  });
559
523
  }
560
524
  }
@@ -643,7 +607,6 @@ class Widget {
643
607
  email: email || null,
644
608
  firstName: firstName || null,
645
609
  lastName: lastName || null,
646
- // FIXME: Double check this
647
610
  id: this.context.user.id,
648
611
  accountId: this.context.user.accountId
649
612
  };
@@ -653,12 +616,17 @@ class Widget {
653
616
  widgetType: this.type,
654
617
  jwt
655
618
  });
656
- } else if (this.context.type === "passwordless") {
657
- response = this.widgetApi.render({
658
- user: undefined,
619
+ } else if (this.context.type === "cookie") {
620
+ let userObj = {
621
+ email: email || null,
622
+ firstName: firstName || null,
623
+ lastName: lastName || null
624
+ };
625
+ response = this.widgetApi.cookieUser({
626
+ user: userObj,
659
627
  engagementMedium,
660
628
  widgetType: this.type,
661
- jwt: undefined
629
+ jwt
662
630
  });
663
631
  } else {
664
632
  throw new Error("can't reload an error widget");
@@ -694,7 +662,7 @@ class Widget {
694
662
  }).catch(({
695
663
  message
696
664
  }) => {
697
- _log$7(`${message}`);
665
+ _log$6(`${message}`);
698
666
  });
699
667
  }
700
668
 
@@ -731,7 +699,7 @@ function domready(targetDoc, fn) {
731
699
 
732
700
  // @ts-check
733
701
 
734
- const _log$6 = debug__default("squatch-js:EMBEDwidget");
702
+ const _log$5 = debug__default("squatch-js:EMBEDwidget");
735
703
  /**
736
704
  * An EmbedWidget is displayed inline in part of your page.
737
705
  *
@@ -749,22 +717,22 @@ class EmbedWidget extends Widget {
749
717
  // selector is a string
750
718
  element = document.querySelector(container);
751
719
 
752
- _log$6("loading widget with selector", element); // selector is an HTML element
720
+ _log$5("loading widget with selector", element); // selector is an HTML element
753
721
 
754
722
  } else if (container instanceof HTMLElement) {
755
723
  element = container;
756
724
 
757
- _log$6("loading widget with container", element); // garbage container found
725
+ _log$5("loading widget with container", element); // garbage container found
758
726
 
759
727
  } else if (container) {
760
728
  element = null;
761
729
 
762
- _log$6("container must be an HTMLElement or string", container); // find element on page
730
+ _log$5("container must be an HTMLElement or string", container); // find element on page
763
731
 
764
732
  } else {
765
733
  element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed");
766
734
 
767
- _log$6("loading widget with default selector", element);
735
+ _log$5("loading widget with default selector", element);
768
736
  }
769
737
 
770
738
  if (!(element instanceof HTMLElement)) throw new Error(`element with selector '${container}' not found.'`);
@@ -830,7 +798,7 @@ class EmbedWidget extends Widget {
830
798
  if (!this.context.container) {
831
799
  this._loadEvent(_sqh);
832
800
 
833
- _log$6("loaded");
801
+ _log$5("loaded");
834
802
  }
835
803
  });
836
804
  } // Un-hide if element is available and refresh data
@@ -839,7 +807,7 @@ class EmbedWidget extends Widget {
839
807
  open() {
840
808
  var _this$frame, _this$frame$contentDo, _this$frame2, _this$frame2$contentW, _this$frame3, _this$frame3$contentW;
841
809
 
842
- if (!this.frame) return _log$6("no target element to open");
810
+ if (!this.frame) return _log$5("no target element to open");
843
811
  this.element.style.visibility = "unset";
844
812
  this.element.style.height = "auto";
845
813
  this.element.style["overflow-y"] = "auto";
@@ -849,16 +817,16 @@ class EmbedWidget extends Widget {
849
817
 
850
818
  this._loadEvent(_sqh);
851
819
 
852
- _log$6("loaded");
820
+ _log$5("loaded");
853
821
  }
854
822
 
855
823
  close() {
856
- if (!this.frame) return _log$6("no target element to close");
824
+ if (!this.frame) return _log$5("no target element to close");
857
825
  this.element.style.visibility = "hidden";
858
826
  this.element.style.height = "0";
859
827
  this.element.style["overflow-y"] = "hidden";
860
828
 
861
- _log$6("Embed widget closed");
829
+ _log$5("Embed widget closed");
862
830
  }
863
831
 
864
832
  _error(rs, mode = "embed", style = "") {
@@ -869,7 +837,7 @@ class EmbedWidget extends Widget {
869
837
 
870
838
  // @ts-check
871
839
 
872
- const _log$5 = debug__default("squatch-js:POPUPwidget");
840
+ const _log$4 = debug__default("squatch-js:POPUPwidget");
873
841
  /**
874
842
  * The PopupWidget is used to display popups (also known as "Modals").
875
843
  * Popups widgets are rendered on top of other elements in a page.
@@ -887,9 +855,9 @@ class PopupWidget extends Widget {
887
855
  this.triggerElement
888
856
  /* HTMLButton */
889
857
  = document.querySelector(trigger);
890
- if (trigger && !this.triggerElement) _log$5("No element found with trigger selector", trigger);
858
+ if (trigger && !this.triggerElement) _log$4("No element found with trigger selector", trigger);
891
859
  } catch (_unused) {
892
- _log$5("Not a valid selector", trigger);
860
+ _log$4("Not a valid selector", trigger);
893
861
  } // Trigger is optional
894
862
 
895
863
 
@@ -931,7 +899,7 @@ class PopupWidget extends Widget {
931
899
  frameDoc.write(`<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"></script>`);
932
900
  frameDoc.close();
933
901
 
934
- _log$5("Popup template loaded into iframe");
902
+ _log$4("Popup template loaded into iframe");
935
903
 
936
904
  this._setupResizeHandler();
937
905
  }
@@ -1004,7 +972,7 @@ class PopupWidget extends Widget {
1004
972
 
1005
973
  this._loadEvent(_sqh);
1006
974
 
1007
- _log$5("Popup opened");
975
+ _log$4("Popup opened");
1008
976
  });
1009
977
  }
1010
978
 
@@ -1012,7 +980,7 @@ class PopupWidget extends Widget {
1012
980
  this.popupdiv.style.visibility = "hidden";
1013
981
  this.popupdiv.style.top = "-2000px";
1014
982
 
1015
- _log$5("Popup closed");
983
+ _log$4("Popup closed");
1016
984
  }
1017
985
 
1018
986
  _clickedOutside({
@@ -1030,7 +998,7 @@ class PopupWidget extends Widget {
1030
998
 
1031
999
  }
1032
1000
 
1033
- const _log$4 = debug("squatch-js:CTAwidget");
1001
+ const _log$3 = debug("squatch-js:CTAwidget");
1034
1002
  /**
1035
1003
  * A CtaWidget is displayed on top of your page
1036
1004
  *
@@ -1041,7 +1009,7 @@ const _log$4 = debug("squatch-js:CTAwidget");
1041
1009
 
1042
1010
  class CtaWidget extends PopupWidget {
1043
1011
  constructor(params, opts) {
1044
- _log$4("CTA constructor");
1012
+ _log$3("CTA constructor");
1045
1013
 
1046
1014
  const ctaElement = document.createElement("div");
1047
1015
  ctaElement.id = "cta";
@@ -1069,7 +1037,7 @@ class CtaWidget extends PopupWidget {
1069
1037
  this.ctaFrame.setAttribute("style", `border:0; background-color:transparent; position:fixed; display:none;${this.side}${this.position}`);
1070
1038
  document.body.appendChild(this.ctaFrame);
1071
1039
 
1072
- _log$4("ctaframe appended to body");
1040
+ _log$3("ctaframe appended to body");
1073
1041
  }
1074
1042
 
1075
1043
  load() {
@@ -1133,10 +1101,10 @@ class CtaWidget extends PopupWidget {
1133
1101
  });
1134
1102
  ro.observe(ctaContainer);
1135
1103
 
1136
- _log$4("CTA template loaded into iframe");
1104
+ _log$3("CTA template loaded into iframe");
1137
1105
  });
1138
1106
  } else {
1139
- _log$4(new Error("CTA element not found in theme"));
1107
+ _log$3(new Error("CTA element not found in theme"));
1140
1108
  }
1141
1109
  });
1142
1110
  }
@@ -1159,7 +1127,7 @@ class CtaWidget extends PopupWidget {
1159
1127
 
1160
1128
  }
1161
1129
 
1162
- const _log$3 = debug__default("squatch-js:widgets");
1130
+ const _log$2 = debug__default("squatch-js:widgets");
1163
1131
  /**
1164
1132
  *
1165
1133
  * `Widgets` is a factory for creating widgets. It's possible to build your own widgets using the
@@ -1197,6 +1165,41 @@ class Widgets {
1197
1165
 
1198
1166
  EventBus.addEventListener("submit_email", Widgets._cb);
1199
1167
  }
1168
+ /**
1169
+ * This function calls the {@link WidgetApi.cookieUser} method, and it renders
1170
+ * the widget if it is successful. Otherwise it shows the "error" widget.
1171
+ *
1172
+ * @param {Object} config Config details
1173
+ * @param {WidgetType} config.widgetType The content of the widget.
1174
+ * @param {EngagementMedium} config.engagementMedium How to display the widget.
1175
+ * @param {User} config.user An optional user to include
1176
+ * @param {string} config.jwt the JSON Web Token (JWT) that is used to
1177
+ * validate the data (can be disabled)
1178
+ *
1179
+ * @return {Promise<WidgetResult>} json object if true, with a Widget and user details.
1180
+ */
1181
+
1182
+
1183
+ async createCookieUser(config) {
1184
+ try {
1185
+ const response = await this.api.cookieUser(config);
1186
+ return {
1187
+ widget: this._renderWidget(response, config, {
1188
+ type: "cookie",
1189
+ engagementMedium: config.engagementMedium
1190
+ }),
1191
+ user: response.user
1192
+ };
1193
+ } catch (err) {
1194
+ _log$2(err);
1195
+
1196
+ if (err.apiErrorCode) {
1197
+ this._renderErrorWidget(err, config.engagementMedium);
1198
+ }
1199
+
1200
+ throw err;
1201
+ }
1202
+ }
1200
1203
  /**
1201
1204
  * This function calls the {@link WidgetApi.upsertUser} method, and it renders
1202
1205
  * the widget if it is successful. Otherwise it shows the "error" widget.
@@ -1224,7 +1227,7 @@ class Widgets {
1224
1227
  return {
1225
1228
  widget: this._renderWidget(response, clean, {
1226
1229
  type: "upsert",
1227
- user: clean.user || null,
1230
+ user: clean.user,
1228
1231
  engagementMedium: config.engagementMedium,
1229
1232
  container: config.container,
1230
1233
  trigger: config.trigger
@@ -1232,7 +1235,7 @@ class Widgets {
1232
1235
  user: response.user
1233
1236
  };
1234
1237
  } catch (err) {
1235
- _log$3(err);
1238
+ _log$2(err);
1236
1239
 
1237
1240
  if (err.apiErrorCode) {
1238
1241
  this._renderErrorWidget(err, config.engagementMedium);
@@ -1260,13 +1263,15 @@ class Widgets {
1260
1263
 
1261
1264
  async render(config) {
1262
1265
  const raw = config;
1263
- const clean = validatePasswordlessConfig(raw);
1266
+ const clean = validateWidgetConfig(raw);
1264
1267
 
1265
1268
  try {
1266
- const response = await this.api.render(clean);
1269
+ const response = await this.api.cookieUser(clean);
1267
1270
  return {
1268
- widget: this._renderWidget(response, clean, {
1269
- type: "passwordless",
1271
+ widget: this._renderWidget({
1272
+ template: response
1273
+ }, clean, {
1274
+ type: "cookie",
1270
1275
  engagementMedium: clean.engagementMedium
1271
1276
  }),
1272
1277
  user: response.user
@@ -1293,7 +1298,7 @@ class Widgets {
1293
1298
 
1294
1299
  if (typeof input === "function") {
1295
1300
  this.api.squatchReferralCookie().then((...args) => input(...args)).catch(ex => {
1296
- _log$3("Autofill error", ex);
1301
+ _log$2("Autofill error", ex);
1297
1302
 
1298
1303
  throw ex;
1299
1304
  });
@@ -1308,7 +1313,7 @@ class Widgets {
1308
1313
  // Only use the first element found
1309
1314
  elem = elems[0];
1310
1315
  } else {
1311
- _log$3("Element id/class or function missing");
1316
+ _log$2("Element id/class or function missing");
1312
1317
 
1313
1318
  throw new Error("Element id/class or function missing");
1314
1319
  }
@@ -1346,11 +1351,11 @@ class Widgets {
1346
1351
 
1347
1352
 
1348
1353
  _renderWidget(response, config, context) {
1349
- _log$3("Rendering Widget...");
1354
+ _log$2("Rendering Widget...");
1350
1355
 
1351
1356
  if (!response) throw new Error("Unable to get a response");
1352
1357
  let widget;
1353
- let displayOnLoad = !!config.displayOnLoad;
1358
+ let displayOnLoad = false;
1354
1359
  let displayCTA = false;
1355
1360
  const opts = response.jsOptions || "";
1356
1361
  const params = {
@@ -1369,9 +1374,9 @@ class Widgets {
1369
1374
  displayOnLoad = rule.displayOnLoad;
1370
1375
  displayCTA = rule.showAsCTA;
1371
1376
 
1372
- _log$3(`Display ${rule.widgetType} on ${rule.url}`);
1377
+ _log$2(`Display ${rule.widgetType} on ${rule.url}`);
1373
1378
  } else {
1374
- _log$3(`Don't display ${rule.widgetType} when no referral on widget rule match ${rule.url}`);
1379
+ _log$2(`Don't display ${rule.widgetType} when no referral on widget rule match ${rule.url}`);
1375
1380
  }
1376
1381
  }
1377
1382
  });
@@ -1380,20 +1385,20 @@ class Widgets {
1380
1385
  if (opts.conversionUrls) {
1381
1386
  opts.conversionUrls.forEach(rule => {
1382
1387
  if (response.user.referredBy && Widgets._matchesUrl(rule)) {
1383
- _log$3("This is a conversion URL", rule);
1388
+ _log$2("This is a conversion URL", rule);
1384
1389
  }
1385
1390
  });
1386
1391
  }
1387
1392
 
1388
1393
  if (opts.fuelTankAutofillUrls) {
1389
- _log$3("We found a fuel tank autofill!");
1394
+ _log$2("We found a fuel tank autofill!");
1390
1395
 
1391
1396
  opts.fuelTankAutofillUrls.forEach(({
1392
1397
  url,
1393
1398
  formSelector
1394
1399
  }) => {
1395
1400
  if (Widgets._matchesUrl(url)) {
1396
- _log$3("Fuel Tank URL matches");
1401
+ _log$2("Fuel Tank URL matches");
1397
1402
 
1398
1403
  if (response.user.referredBy && response.user.referredBy.code) {
1399
1404
  const formAutofill = document.querySelector(formSelector);
@@ -1401,7 +1406,7 @@ class Widgets {
1401
1406
  if (formAutofill) {
1402
1407
  formAutofill.value = response.user.referredBy.referredReward.fuelTankCode || "";
1403
1408
  } else {
1404
- _log$3(new Error(`Element with id/class ${formSelector} was not found.`));
1409
+ _log$2(new Error(`Element with id/class ${formSelector} was not found.`));
1405
1410
  }
1406
1411
  }
1407
1412
  }
@@ -1416,7 +1421,7 @@ class Widgets {
1416
1421
  widget.load();
1417
1422
  if (displayOnLoad) widget.open();
1418
1423
  } else if (displayCTA) {
1419
- _log$3("display CTA");
1424
+ _log$2("display CTA");
1420
1425
 
1421
1426
  const side = opts.cta.content.buttonSide;
1422
1427
  const position = opts.cta.content.buttonPosition;
@@ -1427,7 +1432,7 @@ class Widgets {
1427
1432
  widget.load();
1428
1433
  if (displayOnLoad) widget.open();
1429
1434
  } else {
1430
- _log$3("display popup on load");
1435
+ _log$2("display popup on load");
1431
1436
 
1432
1437
  widget = new PopupWidget(params);
1433
1438
  widget.load();
@@ -1451,7 +1456,7 @@ class Widgets {
1451
1456
  message
1452
1457
  } = props;
1453
1458
 
1454
- _log$3(new Error(`${apiErrorCode} (${rsCode}) ${message}`));
1459
+ _log$2(new Error(`${apiErrorCode} (${rsCode}) ${message}`));
1455
1460
 
1456
1461
  const params = {
1457
1462
  content: "error",
@@ -1591,8 +1596,7 @@ function asyncLoad() {
1591
1596
 
1592
1597
  if (loaded && cached) {
1593
1598
  const ready = cached.ready || [];
1594
- ready.forEach(cb => setTimeout(() => cb(), 0));
1595
- setTimeout(() => window.squatch.auto(), 0); // @ts-ignore -- intetionally deletes `_squatch` to cleanup initialization
1599
+ ready.forEach(cb => setTimeout(() => cb(), 0)); // @ts-ignore -- intetionally deletes `_squatch` to cleanup initialization
1596
1600
 
1597
1601
  window._squatch = undefined;
1598
1602
 
@@ -1982,7 +1986,7 @@ var URLSearchParams$1 = self.URLSearchParams;
1982
1986
 
1983
1987
  /** @hidden */
1984
1988
 
1985
- const _log$2 = debug__default("squatch-js");
1989
+ const _log$1 = debug__default("squatch-js");
1986
1990
 
1987
1991
  const isObject = item => typeof item === "object" && !Array.isArray(item);
1988
1992
 
@@ -2035,7 +2039,7 @@ function _pushCookie() {
2035
2039
  try {
2036
2040
  paramsJSON = JSON.parse(b64decode(refParam));
2037
2041
  } catch (error) {
2038
- _log$2("Unable to decode params", error); // don't merge invalid params
2042
+ _log$1("Unable to decode params", error); // don't merge invalid params
2039
2043
 
2040
2044
 
2041
2045
  return;
@@ -2044,26 +2048,26 @@ function _pushCookie() {
2044
2048
  try {
2045
2049
  existingCookie = JSON.parse(b64decode(Cookies.get("_saasquatch")));
2046
2050
 
2047
- _log$2("existing cookie", existingCookie);
2051
+ _log$1("existing cookie", existingCookie);
2048
2052
  } catch (error) {
2049
- _log$2("Unable to retrieve cookie", error);
2053
+ _log$1("Unable to retrieve cookie", error);
2050
2054
  } // don't merge if there's no existing object
2051
2055
 
2052
2056
 
2053
2057
  try {
2054
2058
  const domain = getTopDomain();
2055
2059
 
2056
- _log$2("domain retrieved:", domain);
2060
+ _log$1("domain retrieved:", domain);
2057
2061
 
2058
2062
  if (existingCookie) {
2059
2063
  const newCookie = deepMerge(existingCookie, paramsJSON);
2060
2064
  reEncodedCookie = b64encode(JSON.stringify(newCookie));
2061
2065
 
2062
- _log$2("cookie to store:", newCookie);
2066
+ _log$1("cookie to store:", newCookie);
2063
2067
  } else {
2064
2068
  reEncodedCookie = b64encode(JSON.stringify(paramsJSON));
2065
2069
 
2066
- _log$2("cookie to store:", paramsJSON);
2070
+ _log$1("cookie to store:", paramsJSON);
2067
2071
  }
2068
2072
 
2069
2073
  Cookies.set("_saasquatch", reEncodedCookie, {
@@ -2074,86 +2078,11 @@ function _pushCookie() {
2074
2078
  path: "/"
2075
2079
  });
2076
2080
  } catch (error) {
2077
- _log$2("Unable to set cookie", error);
2081
+ _log$1("Unable to set cookie", error);
2078
2082
  }
2079
2083
  }
2080
2084
  }
2081
2085
 
2082
- /** @hidden */
2083
-
2084
- const _log$1 = debug__default("squatch-js");
2085
-
2086
- function _getAutoConfig(configIn) {
2087
- const queryString = window.location.search;
2088
- const urlParams = new URLSearchParams(queryString);
2089
- const refParam = urlParams.get("_saasquatchExtra") || "";
2090
-
2091
- if (!refParam) {
2092
- _log$1("No _saasquatchExtra param");
2093
-
2094
- return;
2095
- }
2096
-
2097
- let raw;
2098
-
2099
- try {
2100
- raw = JSON.parse(b64decode(refParam));
2101
- } catch (e) {
2102
- _log$1("Unable to decode _saasquatchExtra config");
2103
-
2104
- return;
2105
- }
2106
-
2107
- const {
2108
- domain,
2109
- tenantAlias,
2110
- widgetConfig
2111
- } = convertExtraToConfig(raw);
2112
-
2113
- if (!domain || !tenantAlias || !widgetConfig) {
2114
- _log$1("_saasquatchExtra did not have an expected structure");
2115
-
2116
- return undefined;
2117
- }
2118
-
2119
- const {
2120
- autoPopupWidgetType
2121
- } = widgetConfig,
2122
- rest = _objectWithoutPropertiesLoose(widgetConfig, ["autoPopupWidgetType"]);
2123
-
2124
- return {
2125
- widgetConfig: _extends({
2126
- widgetType: autoPopupWidgetType,
2127
- displayOnLoad: true
2128
- }, rest),
2129
- squatchConfig: _extends({}, configIn ? {
2130
- configIn
2131
- } : {}, {
2132
- domain,
2133
- tenantAlias
2134
- })
2135
- };
2136
- }
2137
- /**
2138
- * Converts _saasquatchExtra into
2139
- * @param obj
2140
- */
2141
-
2142
- function convertExtraToConfig(obj) {
2143
- var _obj$_domain;
2144
-
2145
- const _domain = Object.keys(obj || {})[0];
2146
- const tenantAlias = Object.keys((obj == null ? void 0 : obj[_domain]) || {})[0];
2147
- const widgetConfig = obj == null ? void 0 : (_obj$_domain = obj[_domain]) == null ? void 0 : _obj$_domain[tenantAlias]; // domain in _saasquatchExtra doesn't contain "https://"
2148
-
2149
- const domain = _domain ? `https://${_domain}` : undefined;
2150
- return {
2151
- domain,
2152
- tenantAlias,
2153
- widgetConfig
2154
- };
2155
- }
2156
-
2157
2086
  // @ts-check
2158
2087
  function help() {
2159
2088
  console.log(`Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes.`);
@@ -2207,35 +2136,6 @@ function widgets() {
2207
2136
  function events() {
2208
2137
  return _events;
2209
2138
  }
2210
- /**
2211
- * Entry-point for high level API to render a widget using the instance of {@link Widgets} created when you call {@link #init init}.
2212
- */
2213
-
2214
- function widget(widgetConfig) {
2215
- var _widgets2;
2216
-
2217
- return (_widgets2 = widgets()) == null ? void 0 : _widgets2.render(widgetConfig);
2218
- }
2219
- /**
2220
- * Initial concept for automatic widget rendering
2221
- *
2222
- * - `saasquatchExtra` utm param carries widgetIdent
2223
- */
2224
-
2225
- function auto(configIn) {
2226
- const configs = _getAutoConfig(configIn);
2227
-
2228
- if (configs) {
2229
- var _widgets3;
2230
-
2231
- const {
2232
- squatchConfig,
2233
- widgetConfig
2234
- } = configs;
2235
- init(squatchConfig);
2236
- return (_widgets3 = widgets()) == null ? void 0 : _widgets3.render(widgetConfig);
2237
- }
2238
- }
2239
2139
  /**
2240
2140
  * Initializes the static `squatch` global. This sets up:
2241
2141
  *
@@ -2340,5 +2240,5 @@ if (typeof document !== "undefined" && !window.SaaSquatchDoNotAutoDrop) {
2340
2240
 
2341
2241
  if (typeof document !== "undefined") asyncLoad();
2342
2242
 
2343
- export { CtaWidget, EmbedWidget, PopupWidget, WidgetApi, Widgets, api, auto, autofill, events, help, init, pushCookie, ready, submitEmail, widget, widgets };
2243
+ export { CtaWidget, EmbedWidget, PopupWidget, WidgetApi, Widgets, api, autofill, events, help, init, pushCookie, ready, submitEmail, widgets };
2344
2244
  //# sourceMappingURL=squatch.esm.js.map