@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.
@@ -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",
@@ -197,21 +158,12 @@ function validateConfig(raw) {
197
158
  npmCdn
198
159
  };
199
160
  }
200
- function validateLocale(locale) {
201
- if (locale && /^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(locale)) {
202
- return locale;
203
- }
204
- }
205
161
  function validateWidgetConfig(raw) {
206
162
  if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
207
163
  if (!assertProp(raw, "user")) ; // TODO: This should be better type checked
208
164
 
209
165
  return raw;
210
166
  }
211
- function validatePasswordlessConfig(raw) {
212
- if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
213
- return raw;
214
- }
215
167
 
216
168
  /**
217
169
  *
@@ -244,6 +196,39 @@ class WidgetApi {
244
196
  this.domain = clean.domain;
245
197
  this.npmCdn = clean.npmCdn;
246
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
+ }
247
232
  /**
248
233
  * Creates/upserts user.
249
234
  *
@@ -300,10 +285,8 @@ class WidgetApi {
300
285
 
301
286
 
302
287
  render(params) {
303
- var _clean$locale;
304
-
305
288
  const raw = params;
306
- const clean = validatePasswordlessConfig(raw);
289
+ const clean = validateWidgetConfig(raw);
307
290
  const {
308
291
  widgetType,
309
292
  engagementMedium = "POPUP",
@@ -311,44 +294,17 @@ class WidgetApi {
311
294
  user
312
295
  } = clean;
313
296
  const tenantAlias = encodeURIComponent(this.tenantAlias);
314
- const accountId = user ? encodeURIComponent(user.accountId) : null;
315
- const userId = user ? encodeURIComponent(user.id) : null;
316
- const locale = (_clean$locale = clean.locale) != null ? _clean$locale : validateLocale(navigator.language.replace(/\-/g, "_"));
317
- const query = `
318
- query renderWidget ($user: UserIdInput, $engagementMedium: UserEngagementMedium, $widgetType: WidgetType, $locale: RSLocale) {
319
- renderWidget(user: $user, engagementMedium: $engagementMedium, widgetType: $widgetType, locale: $locale) {
320
- template
321
- user {
322
- id
323
- accountId
324
- }
325
- jsOptions
326
- widgetConfig {
327
- values
328
- }
329
- }
330
- }
331
- `;
332
- const path = `/api/v1/${tenantAlias}/graphql`;
333
- const url = this.domain + path;
334
- return new Promise(async (resolve, reject) => {
335
- try {
336
- var _res$body, _res$body$data;
337
-
338
- const res = await doQuery(url, query, {
339
- user: userId && accountId ? {
340
- id: userId,
341
- accountId
342
- } : null,
343
- engagementMedium,
344
- widgetType,
345
- locale
346
- }, jwt);
347
- 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);
348
- } catch (e) {
349
- reject(e);
350
- }
297
+ const accountId = encodeURIComponent(user.accountId);
298
+ const userId = encodeURIComponent(user.id);
299
+
300
+ const optionalParams = _buildParams({
301
+ widgetType,
302
+ engagementMedium
351
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);
352
308
  }
353
309
  /**
354
310
  * An API call to send out referral invites to contacts
@@ -382,18 +338,21 @@ class WidgetApi {
382
338
  /**
383
339
  * Looks up the referral code of the current user, if there is any.
384
340
  *
385
- * @return {Promise<Object>} code referral code if true.
341
+ * @return {Promise<ReferralCookie>} code referral code if true.
386
342
  */
387
343
 
388
344
 
389
- squatchReferralCookie() {
345
+ async squatchReferralCookie() {
390
346
  const tenantAlias = encodeURIComponent(this.tenantAlias);
391
347
 
392
- const _saasquatch = Cookies.get("_saasquatch");
348
+ const _saasquatch = Cookies.get("_saasquatch") || "";
393
349
 
394
350
  const cookie = _saasquatch ? `?cookies=${encodeURIComponent(_saasquatch)}` : ``;
395
351
  const url = `${this.domain}/a/${tenantAlias}/widgets/squatchcookiejson${cookie}`;
396
- return doGet(url);
352
+ const response = await doGet(url);
353
+ return Promise.resolve(_extends({}, response, {
354
+ encodedCookie: _saasquatch
355
+ }));
397
356
  }
398
357
 
399
358
  } // builds a param string for widgets
@@ -436,7 +395,6 @@ class AnalyticsApi {
436
395
  }
437
396
 
438
397
  pushAnalyticsLoadEvent(params) {
439
- if (!params.externalUserId || !params.externalAccountId) return;
440
398
  const tenantAlias = encodeURIComponent(params.tenantAlias);
441
399
  const accountId = encodeURIComponent(params.externalAccountId);
442
400
  const userId = encodeURIComponent(params.externalUserId);
@@ -463,7 +421,7 @@ class AnalyticsApi {
463
421
  // @ts-check
464
422
  /** @hidden */
465
423
 
466
- const _log$7 = debug__default("squatch-js:widget");
424
+ const _log$6 = debug__default("squatch-js:widget");
467
425
  /*
468
426
  * The Widget class is the base class for the different widget types available
469
427
  *
@@ -476,7 +434,7 @@ const _log$7 = debug__default("squatch-js:widget");
476
434
 
477
435
  class Widget {
478
436
  constructor(params) {
479
- _log$7("widget initializing ...");
437
+ _log$6("widget initializing ...");
480
438
 
481
439
  this.content = params.content === "error" ? this._error(params.rsCode) : params.content;
482
440
  this.type = params.type;
@@ -494,8 +452,6 @@ class Widget {
494
452
  }
495
453
 
496
454
  _loadEvent(sqh) {
497
- var _this$analyticsApi$pu;
498
-
499
455
  if (!sqh) return; // No non-truthy value
500
456
 
501
457
  if (!isObject$1(sqh)) {
@@ -529,10 +485,10 @@ class Widget {
529
485
  };
530
486
  }
531
487
 
532
- (_this$analyticsApi$pu = this.analyticsApi.pushAnalyticsLoadEvent(params)) == null ? void 0 : _this$analyticsApi$pu.then(response => {
533
- _log$7(`${params.engagementMedium} loaded event recorded.`);
488
+ this.analyticsApi.pushAnalyticsLoadEvent(params).then(response => {
489
+ _log$6(`${params.engagementMedium} loaded event recorded.`);
534
490
  }).catch(ex => {
535
- _log$7(new Error(`pushAnalyticsLoadEvent() ${ex}`));
491
+ _log$6(new Error(`pushAnalyticsLoadEvent() ${ex}`));
536
492
  });
537
493
  }
538
494
 
@@ -545,9 +501,9 @@ class Widget {
545
501
  engagementMedium: sqh.mode.widgetMode,
546
502
  shareMedium: medium
547
503
  }).then(response => {
548
- _log$7(`${sqh.mode.widgetMode} share ${medium} event recorded. ${response}`);
504
+ _log$6(`${sqh.mode.widgetMode} share ${medium} event recorded. ${response}`);
549
505
  }).catch(ex => {
550
- _log$7(new Error(`pushAnalyticsLoadEvent() ${ex}`));
506
+ _log$6(new Error(`pushAnalyticsLoadEvent() ${ex}`));
551
507
  });
552
508
  }
553
509
  }
@@ -560,9 +516,9 @@ class Widget {
560
516
  userId: sqh.analytics.attributes.userId,
561
517
  emailList
562
518
  }).then(response => {
563
- _log$7(`Sent email invites to share ${emailList}. ${response}`);
519
+ _log$6(`Sent email invites to share ${emailList}. ${response}`);
564
520
  }).catch(ex => {
565
- _log$7(new Error(`invite() ${ex}`));
521
+ _log$6(new Error(`invite() ${ex}`));
566
522
  });
567
523
  }
568
524
  }
@@ -651,7 +607,6 @@ class Widget {
651
607
  email: email || null,
652
608
  firstName: firstName || null,
653
609
  lastName: lastName || null,
654
- // FIXME: Double check this
655
610
  id: this.context.user.id,
656
611
  accountId: this.context.user.accountId
657
612
  };
@@ -661,12 +616,17 @@ class Widget {
661
616
  widgetType: this.type,
662
617
  jwt
663
618
  });
664
- } else if (this.context.type === "passwordless") {
665
- response = this.widgetApi.render({
666
- 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,
667
627
  engagementMedium,
668
628
  widgetType: this.type,
669
- jwt: undefined
629
+ jwt
670
630
  });
671
631
  } else {
672
632
  throw new Error("can't reload an error widget");
@@ -702,7 +662,7 @@ class Widget {
702
662
  }).catch(({
703
663
  message
704
664
  }) => {
705
- _log$7(`${message}`);
665
+ _log$6(`${message}`);
706
666
  });
707
667
  }
708
668
 
@@ -739,7 +699,7 @@ function domready(targetDoc, fn) {
739
699
 
740
700
  // @ts-check
741
701
 
742
- const _log$6 = debug__default("squatch-js:EMBEDwidget");
702
+ const _log$5 = debug__default("squatch-js:EMBEDwidget");
743
703
  /**
744
704
  * An EmbedWidget is displayed inline in part of your page.
745
705
  *
@@ -757,22 +717,22 @@ class EmbedWidget extends Widget {
757
717
  // selector is a string
758
718
  element = document.querySelector(container);
759
719
 
760
- _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
761
721
 
762
722
  } else if (container instanceof HTMLElement) {
763
723
  element = container;
764
724
 
765
- _log$6("loading widget with container", element); // garbage container found
725
+ _log$5("loading widget with container", element); // garbage container found
766
726
 
767
727
  } else if (container) {
768
728
  element = null;
769
729
 
770
- _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
771
731
 
772
732
  } else {
773
733
  element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed");
774
734
 
775
- _log$6("loading widget with default selector", element);
735
+ _log$5("loading widget with default selector", element);
776
736
  }
777
737
 
778
738
  if (!(element instanceof HTMLElement)) throw new Error(`element with selector '${container}' not found.'`);
@@ -838,7 +798,7 @@ class EmbedWidget extends Widget {
838
798
  if (!this.context.container) {
839
799
  this._loadEvent(_sqh);
840
800
 
841
- _log$6("loaded");
801
+ _log$5("loaded");
842
802
  }
843
803
  });
844
804
  } // Un-hide if element is available and refresh data
@@ -847,7 +807,7 @@ class EmbedWidget extends Widget {
847
807
  open() {
848
808
  var _this$frame, _this$frame$contentDo, _this$frame2, _this$frame2$contentW, _this$frame3, _this$frame3$contentW;
849
809
 
850
- if (!this.frame) return _log$6("no target element to open");
810
+ if (!this.frame) return _log$5("no target element to open");
851
811
  this.element.style.visibility = "unset";
852
812
  this.element.style.height = "auto";
853
813
  this.element.style["overflow-y"] = "auto";
@@ -857,16 +817,16 @@ class EmbedWidget extends Widget {
857
817
 
858
818
  this._loadEvent(_sqh);
859
819
 
860
- _log$6("loaded");
820
+ _log$5("loaded");
861
821
  }
862
822
 
863
823
  close() {
864
- if (!this.frame) return _log$6("no target element to close");
824
+ if (!this.frame) return _log$5("no target element to close");
865
825
  this.element.style.visibility = "hidden";
866
826
  this.element.style.height = "0";
867
827
  this.element.style["overflow-y"] = "hidden";
868
828
 
869
- _log$6("Embed widget closed");
829
+ _log$5("Embed widget closed");
870
830
  }
871
831
 
872
832
  _error(rs, mode = "embed", style = "") {
@@ -877,7 +837,7 @@ class EmbedWidget extends Widget {
877
837
 
878
838
  // @ts-check
879
839
 
880
- const _log$5 = debug__default("squatch-js:POPUPwidget");
840
+ const _log$4 = debug__default("squatch-js:POPUPwidget");
881
841
  /**
882
842
  * The PopupWidget is used to display popups (also known as "Modals").
883
843
  * Popups widgets are rendered on top of other elements in a page.
@@ -895,9 +855,9 @@ class PopupWidget extends Widget {
895
855
  this.triggerElement
896
856
  /* HTMLButton */
897
857
  = document.querySelector(trigger);
898
- 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);
899
859
  } catch (_unused) {
900
- _log$5("Not a valid selector", trigger);
860
+ _log$4("Not a valid selector", trigger);
901
861
  } // Trigger is optional
902
862
 
903
863
 
@@ -939,7 +899,7 @@ class PopupWidget extends Widget {
939
899
  frameDoc.write(`<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"></script>`);
940
900
  frameDoc.close();
941
901
 
942
- _log$5("Popup template loaded into iframe");
902
+ _log$4("Popup template loaded into iframe");
943
903
 
944
904
  this._setupResizeHandler();
945
905
  }
@@ -1012,7 +972,7 @@ class PopupWidget extends Widget {
1012
972
 
1013
973
  this._loadEvent(_sqh);
1014
974
 
1015
- _log$5("Popup opened");
975
+ _log$4("Popup opened");
1016
976
  });
1017
977
  }
1018
978
 
@@ -1020,7 +980,7 @@ class PopupWidget extends Widget {
1020
980
  this.popupdiv.style.visibility = "hidden";
1021
981
  this.popupdiv.style.top = "-2000px";
1022
982
 
1023
- _log$5("Popup closed");
983
+ _log$4("Popup closed");
1024
984
  }
1025
985
 
1026
986
  _clickedOutside({
@@ -1038,7 +998,7 @@ class PopupWidget extends Widget {
1038
998
 
1039
999
  }
1040
1000
 
1041
- const _log$4 = debug("squatch-js:CTAwidget");
1001
+ const _log$3 = debug("squatch-js:CTAwidget");
1042
1002
  /**
1043
1003
  * A CtaWidget is displayed on top of your page
1044
1004
  *
@@ -1049,7 +1009,7 @@ const _log$4 = debug("squatch-js:CTAwidget");
1049
1009
 
1050
1010
  class CtaWidget extends PopupWidget {
1051
1011
  constructor(params, opts) {
1052
- _log$4("CTA constructor");
1012
+ _log$3("CTA constructor");
1053
1013
 
1054
1014
  const ctaElement = document.createElement("div");
1055
1015
  ctaElement.id = "cta";
@@ -1077,7 +1037,7 @@ class CtaWidget extends PopupWidget {
1077
1037
  this.ctaFrame.setAttribute("style", `border:0; background-color:transparent; position:fixed; display:none;${this.side}${this.position}`);
1078
1038
  document.body.appendChild(this.ctaFrame);
1079
1039
 
1080
- _log$4("ctaframe appended to body");
1040
+ _log$3("ctaframe appended to body");
1081
1041
  }
1082
1042
 
1083
1043
  load() {
@@ -1141,10 +1101,10 @@ class CtaWidget extends PopupWidget {
1141
1101
  });
1142
1102
  ro.observe(ctaContainer);
1143
1103
 
1144
- _log$4("CTA template loaded into iframe");
1104
+ _log$3("CTA template loaded into iframe");
1145
1105
  });
1146
1106
  } else {
1147
- _log$4(new Error("CTA element not found in theme"));
1107
+ _log$3(new Error("CTA element not found in theme"));
1148
1108
  }
1149
1109
  });
1150
1110
  }
@@ -1167,7 +1127,7 @@ class CtaWidget extends PopupWidget {
1167
1127
 
1168
1128
  }
1169
1129
 
1170
- const _log$3 = debug__default("squatch-js:widgets");
1130
+ const _log$2 = debug__default("squatch-js:widgets");
1171
1131
  /**
1172
1132
  *
1173
1133
  * `Widgets` is a factory for creating widgets. It's possible to build your own widgets using the
@@ -1205,6 +1165,41 @@ class Widgets {
1205
1165
 
1206
1166
  EventBus.addEventListener("submit_email", Widgets._cb);
1207
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
+ }
1208
1203
  /**
1209
1204
  * This function calls the {@link WidgetApi.upsertUser} method, and it renders
1210
1205
  * the widget if it is successful. Otherwise it shows the "error" widget.
@@ -1232,7 +1227,7 @@ class Widgets {
1232
1227
  return {
1233
1228
  widget: this._renderWidget(response, clean, {
1234
1229
  type: "upsert",
1235
- user: clean.user || null,
1230
+ user: clean.user,
1236
1231
  engagementMedium: config.engagementMedium,
1237
1232
  container: config.container,
1238
1233
  trigger: config.trigger
@@ -1240,7 +1235,7 @@ class Widgets {
1240
1235
  user: response.user
1241
1236
  };
1242
1237
  } catch (err) {
1243
- _log$3(err);
1238
+ _log$2(err);
1244
1239
 
1245
1240
  if (err.apiErrorCode) {
1246
1241
  this._renderErrorWidget(err, config.engagementMedium);
@@ -1268,13 +1263,15 @@ class Widgets {
1268
1263
 
1269
1264
  async render(config) {
1270
1265
  const raw = config;
1271
- const clean = validatePasswordlessConfig(raw);
1266
+ const clean = validateWidgetConfig(raw);
1272
1267
 
1273
1268
  try {
1274
- const response = await this.api.render(clean);
1269
+ const response = await this.api.cookieUser(clean);
1275
1270
  return {
1276
- widget: this._renderWidget(response, clean, {
1277
- type: "passwordless",
1271
+ widget: this._renderWidget({
1272
+ template: response
1273
+ }, clean, {
1274
+ type: "cookie",
1278
1275
  engagementMedium: clean.engagementMedium
1279
1276
  }),
1280
1277
  user: response.user
@@ -1301,7 +1298,7 @@ class Widgets {
1301
1298
 
1302
1299
  if (typeof input === "function") {
1303
1300
  this.api.squatchReferralCookie().then((...args) => input(...args)).catch(ex => {
1304
- _log$3("Autofill error", ex);
1301
+ _log$2("Autofill error", ex);
1305
1302
 
1306
1303
  throw ex;
1307
1304
  });
@@ -1316,7 +1313,7 @@ class Widgets {
1316
1313
  // Only use the first element found
1317
1314
  elem = elems[0];
1318
1315
  } else {
1319
- _log$3("Element id/class or function missing");
1316
+ _log$2("Element id/class or function missing");
1320
1317
 
1321
1318
  throw new Error("Element id/class or function missing");
1322
1319
  }
@@ -1354,11 +1351,11 @@ class Widgets {
1354
1351
 
1355
1352
 
1356
1353
  _renderWidget(response, config, context) {
1357
- _log$3("Rendering Widget...");
1354
+ _log$2("Rendering Widget...");
1358
1355
 
1359
1356
  if (!response) throw new Error("Unable to get a response");
1360
1357
  let widget;
1361
- let displayOnLoad = !!config.displayOnLoad;
1358
+ let displayOnLoad = false;
1362
1359
  let displayCTA = false;
1363
1360
  const opts = response.jsOptions || "";
1364
1361
  const params = {
@@ -1377,9 +1374,9 @@ class Widgets {
1377
1374
  displayOnLoad = rule.displayOnLoad;
1378
1375
  displayCTA = rule.showAsCTA;
1379
1376
 
1380
- _log$3(`Display ${rule.widgetType} on ${rule.url}`);
1377
+ _log$2(`Display ${rule.widgetType} on ${rule.url}`);
1381
1378
  } else {
1382
- _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}`);
1383
1380
  }
1384
1381
  }
1385
1382
  });
@@ -1388,20 +1385,20 @@ class Widgets {
1388
1385
  if (opts.conversionUrls) {
1389
1386
  opts.conversionUrls.forEach(rule => {
1390
1387
  if (response.user.referredBy && Widgets._matchesUrl(rule)) {
1391
- _log$3("This is a conversion URL", rule);
1388
+ _log$2("This is a conversion URL", rule);
1392
1389
  }
1393
1390
  });
1394
1391
  }
1395
1392
 
1396
1393
  if (opts.fuelTankAutofillUrls) {
1397
- _log$3("We found a fuel tank autofill!");
1394
+ _log$2("We found a fuel tank autofill!");
1398
1395
 
1399
1396
  opts.fuelTankAutofillUrls.forEach(({
1400
1397
  url,
1401
1398
  formSelector
1402
1399
  }) => {
1403
1400
  if (Widgets._matchesUrl(url)) {
1404
- _log$3("Fuel Tank URL matches");
1401
+ _log$2("Fuel Tank URL matches");
1405
1402
 
1406
1403
  if (response.user.referredBy && response.user.referredBy.code) {
1407
1404
  const formAutofill = document.querySelector(formSelector);
@@ -1409,7 +1406,7 @@ class Widgets {
1409
1406
  if (formAutofill) {
1410
1407
  formAutofill.value = response.user.referredBy.referredReward.fuelTankCode || "";
1411
1408
  } else {
1412
- _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.`));
1413
1410
  }
1414
1411
  }
1415
1412
  }
@@ -1424,7 +1421,7 @@ class Widgets {
1424
1421
  widget.load();
1425
1422
  if (displayOnLoad) widget.open();
1426
1423
  } else if (displayCTA) {
1427
- _log$3("display CTA");
1424
+ _log$2("display CTA");
1428
1425
 
1429
1426
  const side = opts.cta.content.buttonSide;
1430
1427
  const position = opts.cta.content.buttonPosition;
@@ -1435,7 +1432,7 @@ class Widgets {
1435
1432
  widget.load();
1436
1433
  if (displayOnLoad) widget.open();
1437
1434
  } else {
1438
- _log$3("display popup on load");
1435
+ _log$2("display popup on load");
1439
1436
 
1440
1437
  widget = new PopupWidget(params);
1441
1438
  widget.load();
@@ -1459,7 +1456,7 @@ class Widgets {
1459
1456
  message
1460
1457
  } = props;
1461
1458
 
1462
- _log$3(new Error(`${apiErrorCode} (${rsCode}) ${message}`));
1459
+ _log$2(new Error(`${apiErrorCode} (${rsCode}) ${message}`));
1463
1460
 
1464
1461
  const params = {
1465
1462
  content: "error",
@@ -1599,8 +1596,7 @@ function asyncLoad() {
1599
1596
 
1600
1597
  if (loaded && cached) {
1601
1598
  const ready = cached.ready || [];
1602
- ready.forEach(cb => setTimeout(() => cb(), 0));
1603
- 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
1604
1600
 
1605
1601
  window._squatch = undefined;
1606
1602
 
@@ -1990,7 +1986,7 @@ var URLSearchParams$1 = self.URLSearchParams;
1990
1986
 
1991
1987
  /** @hidden */
1992
1988
 
1993
- const _log$2 = debug__default("squatch-js");
1989
+ const _log$1 = debug__default("squatch-js");
1994
1990
 
1995
1991
  const isObject = item => typeof item === "object" && !Array.isArray(item);
1996
1992
 
@@ -2043,7 +2039,7 @@ function _pushCookie() {
2043
2039
  try {
2044
2040
  paramsJSON = JSON.parse(b64decode(refParam));
2045
2041
  } catch (error) {
2046
- _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
2047
2043
 
2048
2044
 
2049
2045
  return;
@@ -2052,26 +2048,26 @@ function _pushCookie() {
2052
2048
  try {
2053
2049
  existingCookie = JSON.parse(b64decode(Cookies.get("_saasquatch")));
2054
2050
 
2055
- _log$2("existing cookie", existingCookie);
2051
+ _log$1("existing cookie", existingCookie);
2056
2052
  } catch (error) {
2057
- _log$2("Unable to retrieve cookie", error);
2053
+ _log$1("Unable to retrieve cookie", error);
2058
2054
  } // don't merge if there's no existing object
2059
2055
 
2060
2056
 
2061
2057
  try {
2062
2058
  const domain = getTopDomain();
2063
2059
 
2064
- _log$2("domain retrieved:", domain);
2060
+ _log$1("domain retrieved:", domain);
2065
2061
 
2066
2062
  if (existingCookie) {
2067
2063
  const newCookie = deepMerge(existingCookie, paramsJSON);
2068
2064
  reEncodedCookie = b64encode(JSON.stringify(newCookie));
2069
2065
 
2070
- _log$2("cookie to store:", newCookie);
2066
+ _log$1("cookie to store:", newCookie);
2071
2067
  } else {
2072
2068
  reEncodedCookie = b64encode(JSON.stringify(paramsJSON));
2073
2069
 
2074
- _log$2("cookie to store:", paramsJSON);
2070
+ _log$1("cookie to store:", paramsJSON);
2075
2071
  }
2076
2072
 
2077
2073
  Cookies.set("_saasquatch", reEncodedCookie, {
@@ -2082,86 +2078,11 @@ function _pushCookie() {
2082
2078
  path: "/"
2083
2079
  });
2084
2080
  } catch (error) {
2085
- _log$2("Unable to set cookie", error);
2081
+ _log$1("Unable to set cookie", error);
2086
2082
  }
2087
2083
  }
2088
2084
  }
2089
2085
 
2090
- /** @hidden */
2091
-
2092
- const _log$1 = debug__default("squatch-js");
2093
-
2094
- function _getAutoConfig(configIn) {
2095
- const queryString = window.location.search;
2096
- const urlParams = new URLSearchParams(queryString);
2097
- const refParam = urlParams.get("_saasquatchExtra") || "";
2098
-
2099
- if (!refParam) {
2100
- _log$1("No _saasquatchExtra param");
2101
-
2102
- return;
2103
- }
2104
-
2105
- let raw;
2106
-
2107
- try {
2108
- raw = JSON.parse(b64decode(refParam));
2109
- } catch (e) {
2110
- _log$1("Unable to decode _saasquatchExtra config");
2111
-
2112
- return;
2113
- }
2114
-
2115
- const {
2116
- domain,
2117
- tenantAlias,
2118
- widgetConfig
2119
- } = convertExtraToConfig(raw);
2120
-
2121
- if (!domain || !tenantAlias || !widgetConfig) {
2122
- _log$1("_saasquatchExtra did not have an expected structure");
2123
-
2124
- return undefined;
2125
- }
2126
-
2127
- const {
2128
- autoPopupWidgetType
2129
- } = widgetConfig,
2130
- rest = _objectWithoutPropertiesLoose(widgetConfig, ["autoPopupWidgetType"]);
2131
-
2132
- return {
2133
- widgetConfig: _extends({
2134
- widgetType: autoPopupWidgetType,
2135
- displayOnLoad: true
2136
- }, rest),
2137
- squatchConfig: _extends({}, configIn ? {
2138
- configIn
2139
- } : {}, {
2140
- domain,
2141
- tenantAlias
2142
- })
2143
- };
2144
- }
2145
- /**
2146
- * Converts _saasquatchExtra into
2147
- * @param obj
2148
- */
2149
-
2150
- function convertExtraToConfig(obj) {
2151
- var _obj$_domain;
2152
-
2153
- const _domain = Object.keys(obj || {})[0];
2154
- const tenantAlias = Object.keys((obj == null ? void 0 : obj[_domain]) || {})[0];
2155
- const widgetConfig = obj == null ? void 0 : (_obj$_domain = obj[_domain]) == null ? void 0 : _obj$_domain[tenantAlias]; // domain in _saasquatchExtra doesn't contain "https://"
2156
-
2157
- const domain = _domain ? `https://${_domain}` : undefined;
2158
- return {
2159
- domain,
2160
- tenantAlias,
2161
- widgetConfig
2162
- };
2163
- }
2164
-
2165
2086
  // @ts-check
2166
2087
  function help() {
2167
2088
  console.log(`Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes.`);
@@ -2215,35 +2136,6 @@ function widgets() {
2215
2136
  function events() {
2216
2137
  return _events;
2217
2138
  }
2218
- /**
2219
- * Entry-point for high level API to render a widget using the instance of {@link Widgets} created when you call {@link #init init}.
2220
- */
2221
-
2222
- function widget(widgetConfig) {
2223
- var _widgets2;
2224
-
2225
- return (_widgets2 = widgets()) == null ? void 0 : _widgets2.render(widgetConfig);
2226
- }
2227
- /**
2228
- * Initial concept for automatic widget rendering
2229
- *
2230
- * - `saasquatchExtra` utm param carries widgetIdent
2231
- */
2232
-
2233
- function auto(configIn) {
2234
- const configs = _getAutoConfig(configIn);
2235
-
2236
- if (configs) {
2237
- var _widgets3;
2238
-
2239
- const {
2240
- squatchConfig,
2241
- widgetConfig
2242
- } = configs;
2243
- init(squatchConfig);
2244
- return (_widgets3 = widgets()) == null ? void 0 : _widgets3.render(widgetConfig);
2245
- }
2246
- }
2247
2139
  /**
2248
2140
  * Initializes the static `squatch` global. This sets up:
2249
2141
  *
@@ -2286,7 +2178,7 @@ function init(configIn) {
2286
2178
  * @example
2287
2179
  * squatch.ready(function() {
2288
2180
  * console.log("ready!");
2289
- * squatch.api().upsertUser();
2181
+ * squatch.api().cookieUser();
2290
2182
  * });
2291
2183
  */
2292
2184
 
@@ -2348,5 +2240,5 @@ if (typeof document !== "undefined" && !window.SaaSquatchDoNotAutoDrop) {
2348
2240
 
2349
2241
  if (typeof document !== "undefined") asyncLoad();
2350
2242
 
2351
- 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 };
2352
2244
  //# sourceMappingURL=squatch.esm.js.map