@saasquatch/squatch-js 2.6.0-5 → 2.6.0-7

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.
@@ -34,10 +34,58 @@ function _objectWithoutPropertiesLoose(source, excluded) {
34
34
  return target;
35
35
  }
36
36
 
37
+ var DEFAULT_DOMAIN = "https://app.referralsaasquatch.com";
38
+ var DEFAULT_NPM_CDN = "https://fast.ssqt.io/npm";
39
+ function validateConfig(_raw) {
40
+ if (typeof _raw !== "object") throw new Error("config must be an object");
41
+ var tenant = window.squatchTenant;
42
+ var config = getConfig();
43
+ var raw = {
44
+ tenantAlias: (_raw == null ? void 0 : _raw["tenantAlias"]) || tenant,
45
+ domain: (_raw == null ? void 0 : _raw["domain"]) || (config == null ? void 0 : config.domain),
46
+ npmCdn: (_raw == null ? void 0 : _raw["npmCdn"]) || (config == null ? void 0 : config.npmCdn),
47
+ debug: (_raw == null ? void 0 : _raw["debug"]) || (config == null ? void 0 : config.debug)
48
+ };
49
+ if (typeof raw.tenantAlias !== "string") throw new Error("tenantAlias not provided");
50
+ var tenantAlias = raw.tenantAlias;
51
+ var domain = typeof raw.domain === "string" && raw.domain || DEFAULT_DOMAIN;
52
+ var debug = typeof raw.debug === "boolean" && raw.debug || false;
53
+ var npmCdn = typeof raw.npmCdn === "string" && raw.npmCdn || DEFAULT_NPM_CDN;
54
+ return {
55
+ tenantAlias,
56
+ domain,
57
+ debug,
58
+ npmCdn
59
+ };
60
+ }
61
+ function isObject$1(obj) {
62
+ return typeof obj === "object" && !Array.isArray(obj) && obj !== null;
63
+ }
64
+ function validateLocale(locale) {
65
+ if (locale && /^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(locale)) {
66
+ return locale;
67
+ }
68
+ }
69
+ function validateWidgetConfig(raw) {
70
+ if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
71
+ if (!(raw != null && raw["user"])) throw new Error("Required properties missing.");
72
+ return raw;
73
+ }
74
+ function validatePasswordlessConfig(raw) {
75
+ if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
76
+ return raw;
77
+ }
78
+ function getToken() {
79
+ return window.impactTBDToken || window.squatchToken;
80
+ }
81
+ function getConfig() {
82
+ return window.impactTBDConfig || window.squatchConfig;
83
+ }
84
+
37
85
  debug("squatch-js:io");
38
86
 
39
87
  async function doQuery(url, query, variables, jwt) {
40
- var token = jwt || window.squatchToken;
88
+ var token = jwt || getToken();
41
89
 
42
90
  var headers = _extends({
43
91
  Accept: "application/json",
@@ -72,7 +120,7 @@ async function doGet(url, jwt) {
72
120
  Accept: "application/json",
73
121
  "Content-Type": "application/json"
74
122
  };
75
- var token = jwt || window.squatchToken;
123
+ var token = jwt || getToken();
76
124
  if (token) headers["X-SaaSquatch-User-Token"] = token;
77
125
 
78
126
  try {
@@ -93,7 +141,7 @@ async function doPost(url, data, jwt) {
93
141
  Accept: "application/json",
94
142
  "Content-Type": "application/json"
95
143
  };
96
- var token = jwt || window.squatchToken;
144
+ var token = jwt || getToken();
97
145
  if (token) headers["X-SaaSquatch-User-Token"] = token;
98
146
 
99
147
  try {
@@ -115,7 +163,7 @@ async function doPut(url, data, jwt) {
115
163
  "Content-Type": "application/json",
116
164
  "X-SaaSquatch-Referrer": window ? window.location.href : ""
117
165
  };
118
- var token = jwt || window.squatchToken;
166
+ var token = jwt || getToken();
119
167
  if (token) headers["X-SaaSquatch-User-Token"] = token;
120
168
 
121
169
  try {
@@ -133,48 +181,6 @@ async function doPut(url, data, jwt) {
133
181
  }
134
182
  }
135
183
 
136
- var DEFAULT_DOMAIN = "https://app.referralsaasquatch.com";
137
- var DEFAULT_NPM_CDN = "https://fast.ssqt.io/npm";
138
- function validateConfig(_raw) {
139
- var _window$squatchConfig, _window$squatchConfig2, _window$squatchConfig3;
140
-
141
- if (typeof _raw !== "object") throw new Error("config must be an object");
142
- var raw = {
143
- tenantAlias: (_raw == null ? void 0 : _raw["tenantAlias"]) || window.squatchTenant,
144
- domain: (_raw == null ? void 0 : _raw["domain"]) || ((_window$squatchConfig = window.squatchConfig) == null ? void 0 : _window$squatchConfig.domain),
145
- npmCdn: (_raw == null ? void 0 : _raw["npmCdn"]) || ((_window$squatchConfig2 = window.squatchConfig) == null ? void 0 : _window$squatchConfig2.npmCdn),
146
- debug: (_raw == null ? void 0 : _raw["debug"]) || ((_window$squatchConfig3 = window.squatchConfig) == null ? void 0 : _window$squatchConfig3.debug)
147
- };
148
- if (typeof raw.tenantAlias !== "string") throw new Error("tenantAlias not provided");
149
- var tenantAlias = raw.tenantAlias;
150
- var domain = typeof raw.domain === "string" && raw.domain || DEFAULT_DOMAIN;
151
- var debug = typeof raw.debug === "boolean" && raw.debug || false;
152
- var npmCdn = typeof raw.npmCdn === "string" && raw.npmCdn || DEFAULT_NPM_CDN;
153
- return {
154
- tenantAlias,
155
- domain,
156
- debug,
157
- npmCdn
158
- };
159
- }
160
- function isObject$1(obj) {
161
- return typeof obj === "object" && !Array.isArray(obj) && obj !== null;
162
- }
163
- function validateLocale(locale) {
164
- if (locale && /^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(locale)) {
165
- return locale;
166
- }
167
- }
168
- function validateWidgetConfig(raw) {
169
- if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
170
- if (!(raw != null && raw["user"])) throw new Error("Required properties missing.");
171
- return raw;
172
- }
173
- function validatePasswordlessConfig(raw) {
174
- if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
175
- return raw;
176
- }
177
-
178
184
  var RENDER_WIDGET_QUERY = "\n query renderWidget ($user: UserIdInput, $engagementMedium: UserEngagementMedium, $widgetType: WidgetType, $locale: RSLocale) {\n renderWidget(user: $user, engagementMedium: $engagementMedium, widgetType: $widgetType, locale: $locale) {\n template\n user {\n id\n accountId\n }\n jsOptions\n widgetConfig {\n values\n }\n }\n }\n";
179
185
 
180
186
  /**
@@ -357,14 +363,14 @@ class AnalyticsApi {
357
363
  *
358
364
  */
359
365
  constructor(config) {
360
- var _window$squatchConfig;
366
+ var _getConfig;
361
367
 
362
368
  this.domain = void 0;
363
369
  var raw = config;
364
370
 
365
371
  var clean = _validateAnalyticsConfig(raw);
366
372
 
367
- this.domain = (clean == null ? void 0 : clean["domain"]) || ((_window$squatchConfig = window.squatchConfig) == null ? void 0 : _window$squatchConfig.domain) || DEFAULT_DOMAIN;
373
+ this.domain = (clean == null ? void 0 : clean["domain"]) || ((_getConfig = getConfig()) == null ? void 0 : _getConfig.domain) || DEFAULT_DOMAIN;
368
374
  }
369
375
 
370
376
  pushAnalyticsLoadEvent(params) {
@@ -400,7 +406,7 @@ function _validateAnalyticsConfig(raw) {
400
406
  // @ts-check
401
407
  /** @hidden */
402
408
 
403
- var _log$7 = debug("squatch-js:widget");
409
+ var _log$8 = debug("squatch-js:widget");
404
410
  /*
405
411
  * The Widget class is the base class for the different widget types available
406
412
  *
@@ -421,7 +427,7 @@ class Widget {
421
427
  this.npmCdn = void 0;
422
428
  this.container = void 0;
423
429
 
424
- _log$7("widget initializing ...");
430
+ _log$8("widget initializing ...");
425
431
 
426
432
  this.content = params.content === "error" ? this._error(params.rsCode) : params.content;
427
433
  this.type = params.type;
@@ -431,7 +437,7 @@ class Widget {
431
437
  domain: params.domain
432
438
  });
433
439
  this.context = params.context;
434
- this.container = params.container;
440
+ this.container = params.context.container;
435
441
  }
436
442
 
437
443
  _findElement() {
@@ -441,22 +447,22 @@ class Widget {
441
447
  // selector is a string
442
448
  element = document.querySelector(this.container);
443
449
 
444
- _log$7("loading widget with selector", element); // selector is an HTML element
450
+ _log$8("loading widget with selector", element); // selector is an HTML element
445
451
 
446
452
  } else if (this.container instanceof HTMLElement) {
447
453
  element = this.container;
448
454
 
449
- _log$7("loading widget with container", element); // garbage container found
455
+ _log$8("loading widget with container", element); // garbage container found
450
456
 
451
457
  } else if (this.container) {
452
458
  element = null;
453
459
 
454
- _log$7("container must be an HTMLElement or string", this.container); // find element on page
460
+ _log$8("container must be an HTMLElement or string", this.container); // find element on page
455
461
 
456
462
  } else {
457
463
  element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed");
458
464
 
459
- _log$7("loading widget with default selector", element);
465
+ _log$8("loading widget with default selector", element);
460
466
  }
461
467
 
462
468
  if (!(element instanceof HTMLElement)) throw new Error("element with selector '" + (this.container || "#squatchembed or .squatchembed") + "' not found.'");
@@ -514,9 +520,9 @@ class Widget {
514
520
  }
515
521
 
516
522
  (_this$analyticsApi$pu = this.analyticsApi.pushAnalyticsLoadEvent(params)) == null ? void 0 : _this$analyticsApi$pu.then(response => {
517
- _log$7(params.engagementMedium + " loaded event recorded.");
523
+ _log$8(params.engagementMedium + " loaded event recorded.");
518
524
  }).catch(ex => {
519
- _log$7("ERROR: pushAnalyticsLoadEvent() " + ex);
525
+ _log$8("ERROR: pushAnalyticsLoadEvent() " + ex);
520
526
  });
521
527
  }
522
528
 
@@ -529,9 +535,9 @@ class Widget {
529
535
  engagementMedium: sqh.mode.widgetMode,
530
536
  shareMedium: medium
531
537
  }).then(response => {
532
- _log$7(sqh.mode.widgetMode + " share " + medium + " event recorded. " + response);
538
+ _log$8(sqh.mode.widgetMode + " share " + medium + " event recorded. " + response);
533
539
  }).catch(ex => {
534
- _log$7("ERROR: pushAnalyticsShareClickedEvent() " + ex);
540
+ _log$8("ERROR: pushAnalyticsShareClickedEvent() " + ex);
535
541
  });
536
542
  }
537
543
  } // TODO: CA: Refactor how error templates are shown
@@ -653,7 +659,7 @@ class Widget {
653
659
  message
654
660
  } = _ref3;
655
661
 
656
- _log$7("" + message);
662
+ _log$8("" + message);
657
663
  });
658
664
  }
659
665
 
@@ -680,7 +686,7 @@ class Widget {
680
686
  }
681
687
 
682
688
  function delay(duration) {
683
- return new Promise(function (resolve, reject) {
689
+ return new Promise(resolve => {
684
690
  setTimeout(resolve, duration);
685
691
  });
686
692
  }
@@ -710,7 +716,7 @@ function domready(targetDoc, fn) {
710
716
 
711
717
  // @ts-check
712
718
 
713
- var _log$6 = debug("squatch-js:EMBEDwidget");
719
+ var _log$7 = debug("squatch-js:EMBEDwidget");
714
720
  /**
715
721
  * An EmbedWidget is displayed inline in part of your page.
716
722
  *
@@ -729,6 +735,7 @@ class EmbedWidget extends Widget {
729
735
  super(params);
730
736
  this.show = this.open;
731
737
  this.hide = this.close;
738
+ if (container) this.container = container;
732
739
  }
733
740
 
734
741
  async load() {
@@ -740,7 +747,9 @@ class EmbedWidget extends Widget {
740
747
  if (element.shadowRoot) {
741
748
  var _element$shadowRoot$l;
742
749
 
743
- if (((_element$shadowRoot$l = element.shadowRoot.lastChild) == null ? void 0 : _element$shadowRoot$l.nodeName) === "IFRAME") element.shadowRoot.replaceChild(frame, element.shadowRoot.lastChild);else {
750
+ if (((_element$shadowRoot$l = element.shadowRoot.lastChild) == null ? void 0 : _element$shadowRoot$l.nodeName) === "IFRAME") {
751
+ element.shadowRoot.replaceChild(frame, element.shadowRoot.lastChild);
752
+ } else {
744
753
  element.shadowRoot.appendChild(frame);
745
754
  }
746
755
  } // Widget reloaded - replace existing element
@@ -784,12 +793,12 @@ class EmbedWidget extends Widget {
784
793
  }
785
794
  });
786
795
  var container = await this._findInnerContainer(frame);
787
- ro.observe(container); // Regular load - trigger event
796
+ ro.observe(container);
788
797
 
789
- if (!this.container || this.container instanceof HTMLElement && this.container.tagName.startsWith("SQUATCH-")) {
798
+ if (this._shouldFireLoadEvent()) {
790
799
  this._loadEvent(_sqh);
791
800
 
792
- _log$6("loaded");
801
+ _log$7("loaded");
793
802
  }
794
803
  });
795
804
  }
@@ -803,7 +812,7 @@ class EmbedWidget extends Widget {
803
812
 
804
813
  var frame = this._findFrame();
805
814
 
806
- if (!frame) return _log$6("no target element to open");
815
+ if (!frame) return _log$7("no target element to open");
807
816
 
808
817
  var element = this._findElement();
809
818
 
@@ -814,15 +823,17 @@ class EmbedWidget extends Widget {
814
823
 
815
824
  var _sqh = (frame == null ? void 0 : (_frame$contentWindow = frame.contentWindow) == null ? void 0 : _frame$contentWindow.squatch) || (frame == null ? void 0 : (_frame$contentWindow2 = frame.contentWindow) == null ? void 0 : _frame$contentWindow2.widgetIdent);
816
825
 
817
- this._loadEvent(_sqh);
826
+ if (this.context.user) {
827
+ this._loadEvent(_sqh);
818
828
 
819
- _log$6("loaded");
829
+ _log$7("loaded");
830
+ }
820
831
  }
821
832
 
822
833
  close() {
823
834
  var frame = this._findFrame();
824
835
 
825
- if (!frame) return _log$6("no target element to close");
836
+ if (!frame) return _log$7("no target element to close");
826
837
 
827
838
  var element = this._findElement();
828
839
 
@@ -830,7 +841,7 @@ class EmbedWidget extends Widget {
830
841
  element.style.height = "0";
831
842
  element.style["overflow-y"] = "hidden";
832
843
 
833
- _log$6("Embed widget closed");
844
+ _log$7("Embed widget closed");
834
845
  }
835
846
 
836
847
  _error(rs, mode, style) {
@@ -845,11 +856,18 @@ class EmbedWidget extends Widget {
845
856
  return super._error(rs, mode, style);
846
857
  }
847
858
 
859
+ _shouldFireLoadEvent() {
860
+ var noContainer = !this.container;
861
+ var isComponent = this.container instanceof HTMLElement && this.container.tagName.startsWith("SQUATCH-");
862
+ var isVerified = !!this.context.user;
863
+ return isVerified && (noContainer || isComponent);
864
+ }
865
+
848
866
  }
849
867
 
850
868
  // @ts-check
851
869
 
852
- var _log$5 = debug("squatch-js:POPUPwidget");
870
+ var _log$6 = debug("squatch-js:POPUPwidget");
853
871
 
854
872
  var popupId = 0;
855
873
  /**
@@ -896,9 +914,9 @@ class PopupWidget extends Widget {
896
914
  triggerElement
897
915
  /* HTMLButton */
898
916
  = document.querySelector(this.trigger);
899
- if (this.trigger && !triggerElement) _log$5("No element found with trigger selector", this.trigger);
917
+ if (this.trigger && !triggerElement) _log$6("No element found with trigger selector", this.trigger);
900
918
  } catch (_unused) {
901
- _log$5("Not a valid selector", this.trigger);
919
+ _log$6("Not a valid selector", this.trigger);
902
920
  } // Trigger is optional
903
921
 
904
922
 
@@ -906,16 +924,7 @@ class PopupWidget extends Widget {
906
924
  triggerElement.onclick = () => {
907
925
  this.open();
908
926
  };
909
- } // const element = this._findElement();
910
- // If widget is loaded with CTA, look for a 'squatchpop' element to use
911
- // that element as a trigger as well.
912
- // const triggerWhenCTA = element.querySelector(".squatchpop") as HTMLElement;
913
- // if (this.trigger === "#cta" && triggerWhenCTA) {
914
- // triggerWhenCTA.onclick = () => {
915
- // this.open(frame);
916
- // };
917
- // }
918
-
927
+ }
919
928
  }
920
929
 
921
930
  _createPopupDialog() {
@@ -924,6 +933,7 @@ class PopupWidget extends Widget {
924
933
  dialog.setAttribute("style", "width: 100%; max-width: 500px; border: none; padding: 0;");
925
934
 
926
935
  var onClick = e => {
936
+ e.stopPropagation();
927
937
  if (e.target === dialog) dialog.close();
928
938
  };
929
939
 
@@ -967,7 +977,7 @@ class PopupWidget extends Widget {
967
977
  frameDoc.write("<script src=\"" + this.npmCdn + "/resize-observer-polyfill@1.5.x\"></script>");
968
978
  frameDoc.close();
969
979
 
970
- _log$5("Popup template loaded into iframe");
980
+ _log$6("Popup template loaded into iframe");
971
981
 
972
982
  this._setupResizeHandler(frame);
973
983
  }
@@ -1026,9 +1036,11 @@ class PopupWidget extends Widget {
1026
1036
 
1027
1037
  (_frame$contentDocumen = frame.contentDocument) == null ? void 0 : _frame$contentDocumen.dispatchEvent(new CustomEvent("sq:refresh"));
1028
1038
 
1029
- this._loadEvent(_sqh);
1039
+ if (this.context.user) {
1040
+ this._loadEvent(_sqh);
1030
1041
 
1031
- _log$5("Popup opened");
1042
+ _log$6("Popup opened");
1043
+ }
1032
1044
  });
1033
1045
  }
1034
1046
 
@@ -1039,7 +1051,7 @@ class PopupWidget extends Widget {
1039
1051
  if (!dialog) throw new Error("Could not determine container div");
1040
1052
  dialog.close();
1041
1053
 
1042
- _log$5("Popup closed");
1054
+ _log$6("Popup closed");
1043
1055
  }
1044
1056
 
1045
1057
  _clickedOutside(_ref) {
@@ -1060,7 +1072,7 @@ class PopupWidget extends Widget {
1060
1072
 
1061
1073
  }
1062
1074
 
1063
- var _log$4 = debug("squatch-js:widgets");
1075
+ var _log$5 = debug("squatch-js:widgets");
1064
1076
  /**
1065
1077
  * `Widgets` is a factory for creating widgets. It's possible to build your own widgets using the
1066
1078
  * {@link WidgetApi} but most people will prefer to use these easy methods.
@@ -1149,7 +1161,7 @@ class Widgets {
1149
1161
  user: response.user
1150
1162
  };
1151
1163
  } catch (err) {
1152
- _log$4(err);
1164
+ _log$5(err);
1153
1165
 
1154
1166
  if (err.apiErrorCode) {
1155
1167
  this._renderErrorWidget(err, config.engagementMedium);
@@ -1215,7 +1227,7 @@ class Widgets {
1215
1227
  var response = await this.api.squatchReferralCookie();
1216
1228
  input(response);
1217
1229
  } catch (e) {
1218
- _log$4("Autofill error", e);
1230
+ _log$5("Autofill error", e);
1219
1231
 
1220
1232
  throw new Error(e);
1221
1233
  }
@@ -1231,7 +1243,7 @@ class Widgets {
1231
1243
  // Only use the first element found
1232
1244
  elem = elems[0];
1233
1245
  } else {
1234
- _log$4("Element id/class or function missing");
1246
+ _log$5("Element id/class or function missing");
1235
1247
 
1236
1248
  throw new Error("Element id/class or function missing");
1237
1249
  }
@@ -1257,7 +1269,7 @@ class Widgets {
1257
1269
  _renderWidget(response, config, context) {
1258
1270
  var _opts$widget;
1259
1271
 
1260
- _log$4("Rendering Widget...");
1272
+ _log$5("Rendering Widget...");
1261
1273
 
1262
1274
  if (!response) throw new Error("Unable to get a response");
1263
1275
  var widget;
@@ -1280,16 +1292,16 @@ class Widgets {
1280
1292
  if (rule.widgetType !== "CONVERSION_WIDGET" || (_response$user = response.user) != null && (_response$user$referr = _response$user.referredBy) != null && _response$user$referr.code) {
1281
1293
  displayOnLoad = rule.displayOnLoad;
1282
1294
 
1283
- _log$4("Display " + rule.widgetType + " on " + rule.url);
1295
+ _log$5("Display " + rule.widgetType + " on " + rule.url);
1284
1296
  } else {
1285
- _log$4("Don't display " + rule.widgetType + " when no referral on widget rule match " + rule.url);
1297
+ _log$5("Don't display " + rule.widgetType + " when no referral on widget rule match " + rule.url);
1286
1298
  }
1287
1299
  }
1288
1300
  });
1289
1301
  }
1290
1302
 
1291
1303
  if (opts.fuelTankAutofillUrls) {
1292
- _log$4("We found a fuel tank autofill!");
1304
+ _log$5("We found a fuel tank autofill!");
1293
1305
 
1294
1306
  opts.fuelTankAutofillUrls.forEach(_ref => {
1295
1307
  var {
@@ -1300,7 +1312,7 @@ class Widgets {
1300
1312
  if (Widgets._matchesUrl(url)) {
1301
1313
  var _response$user2, _response$user2$refer;
1302
1314
 
1303
- _log$4("Fuel Tank URL matches");
1315
+ _log$5("Fuel Tank URL matches");
1304
1316
 
1305
1317
  if ((_response$user2 = response.user) != null && (_response$user2$refer = _response$user2.referredBy) != null && _response$user2$refer.code) {
1306
1318
  var formAutofill = document.querySelector(formSelector);
@@ -1310,7 +1322,7 @@ class Widgets {
1310
1322
 
1311
1323
  formAutofill.value = ((_response$user$referr2 = response.user.referredBy.referredReward) == null ? void 0 : _response$user$referr2.fuelTankCode) || "";
1312
1324
  } else {
1313
- _log$4(new Error("Element with id/class " + formSelector + " was not found."));
1325
+ _log$5(new Error("Element with id/class " + formSelector + " was not found."));
1314
1326
  }
1315
1327
  }
1316
1328
  }
@@ -1318,15 +1330,9 @@ class Widgets {
1318
1330
  }
1319
1331
 
1320
1332
  if (config.engagementMedium === "EMBED") {
1321
- widget = this._renderEmbedWidget(params, params.context.container);
1322
- } else if (config.engagementMedium === "POPUP") {
1323
- widget = this._renderPopupWidget(params);
1324
- if (displayOnLoad) widget.open();
1333
+ widget = this._renderEmbedWidget(params);
1325
1334
  } else {
1326
- _log$4("display popup on load");
1327
-
1328
- widget = new PopupWidget(params);
1329
- widget.load();
1335
+ widget = this._renderPopupWidget(params);
1330
1336
  if (displayOnLoad) widget.open();
1331
1337
  }
1332
1338
 
@@ -1339,8 +1345,8 @@ class Widgets {
1339
1345
  return widget;
1340
1346
  }
1341
1347
 
1342
- _renderEmbedWidget(params, container) {
1343
- var widget = new EmbedWidget(params, container);
1348
+ _renderEmbedWidget(params) {
1349
+ var widget = new EmbedWidget(params, params.context.container);
1344
1350
  widget.load();
1345
1351
  return widget;
1346
1352
  }
@@ -1363,7 +1369,7 @@ class Widgets {
1363
1369
  message
1364
1370
  } = props;
1365
1371
 
1366
- _log$4(new Error(apiErrorCode + " (" + rsCode + ") " + message));
1372
+ _log$5(new Error(apiErrorCode + " (" + rsCode + ") " + message));
1367
1373
 
1368
1374
  var params = {
1369
1375
  content: "error",
@@ -1479,18 +1485,26 @@ function _validateTrackOptions(raw) {
1479
1485
 
1480
1486
  /** @hidden */
1481
1487
  function asyncLoad() {
1482
- var loaded = window.squatch || null;
1483
- var cached = window._squatch || null;
1488
+ var impactNamespace = "impactTBD";
1489
+ var namespace = window[impactNamespace] ? impactNamespace : "squatch";
1490
+ console.log({
1491
+ namespace
1492
+ });
1493
+ var loaded = window[namespace] || null;
1494
+ var cached = window["_" + namespace] || null;
1484
1495
 
1485
1496
  if (loaded && cached) {
1486
1497
  var ready = cached.ready || [];
1498
+ setTimeout(() => window["impactTBD"] = window.squatch, 0);
1487
1499
  ready.forEach(cb => setTimeout(() => cb(), 0));
1488
- setTimeout(() => window.squatch._auto(), 0); // @ts-ignore -- intetionally deletes `_squatch` to cleanup initialization
1500
+ setTimeout(() => {
1501
+ window.squatch._auto();
1502
+ }, 0); // @ts-ignore -- intentionally deletes `_squatch` to cleanup initialization
1489
1503
 
1490
- window._squatch = undefined;
1504
+ window["_" + namespace] = undefined;
1491
1505
 
1492
1506
  try {
1493
- delete window._squatch;
1507
+ delete window["_" + namespace];
1494
1508
  } catch (e) {
1495
1509
  throw e;
1496
1510
  }
@@ -1499,7 +1513,7 @@ function asyncLoad() {
1499
1513
 
1500
1514
  /** @hidden */
1501
1515
 
1502
- var _log$3 = debug("squatch-js");
1516
+ var _log$4 = debug("squatch-js");
1503
1517
 
1504
1518
  var isObject = item => typeof item === "object" && !Array.isArray(item);
1505
1519
 
@@ -1552,7 +1566,7 @@ function _pushCookie() {
1552
1566
  try {
1553
1567
  paramsJSON = JSON.parse(b64decode(refParam));
1554
1568
  } catch (error) {
1555
- _log$3("Unable to decode params", error); // don't merge invalid params
1569
+ _log$4("Unable to decode params", error); // don't merge invalid params
1556
1570
 
1557
1571
 
1558
1572
  return;
@@ -1561,26 +1575,26 @@ function _pushCookie() {
1561
1575
  try {
1562
1576
  existingCookie = JSON.parse(b64decode(Cookies.get("_saasquatch")));
1563
1577
 
1564
- _log$3("existing cookie", existingCookie);
1578
+ _log$4("existing cookie", existingCookie);
1565
1579
  } catch (error) {
1566
- _log$3("Unable to retrieve cookie", error);
1580
+ _log$4("Unable to retrieve cookie", error);
1567
1581
  } // don't merge if there's no existing object
1568
1582
 
1569
1583
 
1570
1584
  try {
1571
1585
  var domain = getTopDomain();
1572
1586
 
1573
- _log$3("domain retrieved:", domain);
1587
+ _log$4("domain retrieved:", domain);
1574
1588
 
1575
1589
  if (existingCookie) {
1576
1590
  var newCookie = deepMerge(existingCookie, paramsJSON);
1577
1591
  reEncodedCookie = b64encode(JSON.stringify(newCookie));
1578
1592
 
1579
- _log$3("cookie to store:", newCookie);
1593
+ _log$4("cookie to store:", newCookie);
1580
1594
  } else {
1581
1595
  reEncodedCookie = b64encode(JSON.stringify(paramsJSON));
1582
1596
 
1583
- _log$3("cookie to store:", paramsJSON);
1597
+ _log$4("cookie to store:", paramsJSON);
1584
1598
  }
1585
1599
 
1586
1600
  Cookies.set("_saasquatch", reEncodedCookie, {
@@ -1591,14 +1605,14 @@ function _pushCookie() {
1591
1605
  path: "/"
1592
1606
  });
1593
1607
  } catch (error) {
1594
- _log$3("Unable to set cookie", error);
1608
+ _log$4("Unable to set cookie", error);
1595
1609
  }
1596
1610
  }
1597
1611
  }
1598
1612
 
1599
1613
  /** @hidden */
1600
1614
 
1601
- var _log$2 = debug("squatch-js");
1615
+ var _log$3 = debug("squatch-js");
1602
1616
 
1603
1617
  function _getAutoConfig(configIn) {
1604
1618
  var queryString = window.location.search;
@@ -1606,7 +1620,7 @@ function _getAutoConfig(configIn) {
1606
1620
  var refParam = urlParams.get("_saasquatchExtra") || "";
1607
1621
 
1608
1622
  if (!refParam) {
1609
- _log$2("No _saasquatchExtra param");
1623
+ _log$3("No _saasquatchExtra param");
1610
1624
 
1611
1625
  return;
1612
1626
  }
@@ -1616,7 +1630,7 @@ function _getAutoConfig(configIn) {
1616
1630
  try {
1617
1631
  raw = JSON.parse(b64decode(refParam));
1618
1632
  } catch (e) {
1619
- _log$2("Unable to decode _saasquatchExtra config");
1633
+ _log$3("Unable to decode _saasquatchExtra config");
1620
1634
 
1621
1635
  return;
1622
1636
  }
@@ -1628,7 +1642,7 @@ function _getAutoConfig(configIn) {
1628
1642
  } = convertExtraToConfig(raw);
1629
1643
 
1630
1644
  if (!domain || !tenantAlias || !widgetConfig) {
1631
- _log$2("_saasquatchExtra did not have an expected structure");
1645
+ _log$3("_saasquatchExtra did not have an expected structure");
1632
1646
 
1633
1647
  return undefined;
1634
1648
  }
@@ -1671,7 +1685,7 @@ function convertExtraToConfig(obj) {
1671
1685
  };
1672
1686
  }
1673
1687
 
1674
- var _log$1 = debug("squatch-js:decodeJwt");
1688
+ var _log$2 = debug("squatch-js:decodeJwt");
1675
1689
 
1676
1690
  function decodeUserJwt(tokenStr) {
1677
1691
  try {
@@ -1682,13 +1696,13 @@ function decodeUserJwt(tokenStr) {
1682
1696
  var jsonStr = b64decode(base64Url);
1683
1697
  return (_JSON$parse = JSON.parse(jsonStr)) == null ? void 0 : _JSON$parse.user;
1684
1698
  } catch (e) {
1685
- _log$1(e);
1699
+ _log$2(e);
1686
1700
 
1687
1701
  return null;
1688
1702
  }
1689
1703
  }
1690
1704
 
1691
- debug$1("sqh:DeclarativeWidget");
1705
+ var _log$1 = debug$1("squatch-js:DeclarativeWidget");
1692
1706
  /**
1693
1707
  * Abstract class for building web-components that render SaaSquatch widgets to the DOM.
1694
1708
  * @abstract
@@ -1767,16 +1781,17 @@ class DeclarativeWidget extends HTMLElement {
1767
1781
  content: template,
1768
1782
  context: {
1769
1783
  type: config.type,
1784
+ user: config.user,
1785
+ container: this.container || this,
1770
1786
  engagementMedium: this.type
1771
1787
  },
1772
1788
  type: this.widgetType,
1773
1789
  domain: ((_this$config = this.config) == null ? void 0 : _this$config.domain) || DEFAULT_DOMAIN,
1774
- npmCdn: DEFAULT_NPM_CDN,
1775
- container: this.container || this
1790
+ npmCdn: DEFAULT_NPM_CDN
1776
1791
  };
1777
1792
 
1778
1793
  if (this.type === "EMBED") {
1779
- return new EmbedWidget(params);
1794
+ return new EmbedWidget(params, params.context.container);
1780
1795
  } else {
1781
1796
  return new PopupWidget(params, this.firstChild ? null : undefined);
1782
1797
  }
@@ -1789,16 +1804,16 @@ class DeclarativeWidget extends HTMLElement {
1789
1804
  api: this.widgetApi,
1790
1805
  content: "error",
1791
1806
  context: {
1792
- type: "error"
1807
+ type: "error",
1808
+ container: this.container || this
1793
1809
  },
1794
1810
  type: "ERROR_WIDGET",
1795
1811
  domain: ((_this$config2 = this.config) == null ? void 0 : _this$config2.domain) || DEFAULT_DOMAIN,
1796
- npmCdn: DEFAULT_NPM_CDN,
1797
- container: this.container || this
1812
+ npmCdn: DEFAULT_NPM_CDN
1798
1813
  };
1799
1814
 
1800
1815
  if (this.type === "EMBED") {
1801
- return new EmbedWidget(params);
1816
+ return new EmbedWidget(params, params.context.container);
1802
1817
  } else {
1803
1818
  return new PopupWidget(params, this.firstChild ? null : undefined);
1804
1819
  }
@@ -1810,8 +1825,8 @@ class DeclarativeWidget extends HTMLElement {
1810
1825
  this.attachShadow({
1811
1826
  mode: "open"
1812
1827
  }).innerHTML = "<style>:host { display: contents; }</style><slot></slot>";
1813
- this.config = window.squatchConfig;
1814
- this.token = window.squatchToken;
1828
+ this.config = getConfig();
1829
+ this.token = getToken();
1815
1830
  this.tenant = window.squatchTenant;
1816
1831
  this.container = this;
1817
1832
  }
@@ -1819,7 +1834,7 @@ class DeclarativeWidget extends HTMLElement {
1819
1834
  _setupApis(config) {
1820
1835
  var _this$config3, _this$config4;
1821
1836
 
1822
- if (!this.tenant) throw new Error("Requires tenantAlias");
1837
+ if (!this.tenant) throw new Error("tenantAlias not provided");
1823
1838
  this.widgetApi = new WidgetApi({
1824
1839
  tenantAlias: (config == null ? void 0 : config.tenantAlias) || this.tenant,
1825
1840
  domain: (config == null ? void 0 : config.domain) || ((_this$config3 = this.config) == null ? void 0 : _this$config3.domain) || DEFAULT_DOMAIN
@@ -1830,16 +1845,14 @@ class DeclarativeWidget extends HTMLElement {
1830
1845
  }
1831
1846
 
1832
1847
  async renderPasswordlessVariant() {
1833
- var _configs$widgetConfig, _configs$widgetConfig2, _configs$widgetConfig3;
1834
-
1835
- var configs = _getAutoConfig();
1848
+ this._setupApis();
1836
1849
 
1837
- this._setupApis(configs == null ? void 0 : configs.squatchConfig);
1850
+ _log$1("Rendering as an Instant Access widget");
1838
1851
 
1839
1852
  return await this.widgetApi.render({
1840
- engagementMedium: (configs == null ? void 0 : (_configs$widgetConfig = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig.engagementMedium) || this.type,
1841
- widgetType: (configs == null ? void 0 : (_configs$widgetConfig2 = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig2.widgetType) || this.widgetType,
1842
- locale: (configs == null ? void 0 : (_configs$widgetConfig3 = configs.widgetConfig) == null ? void 0 : _configs$widgetConfig3.locale) || this.locale
1853
+ engagementMedium: this.type,
1854
+ widgetType: this.widgetType,
1855
+ locale: this.locale
1843
1856
  }).then(res => this._setWidget(res.template, {
1844
1857
  type: "passwordless"
1845
1858
  })).catch(this.setErrorWidget);
@@ -1849,7 +1862,13 @@ class DeclarativeWidget extends HTMLElement {
1849
1862
  this._setupApis();
1850
1863
 
1851
1864
  var userObj = decodeUserJwt(this.token);
1852
- if (!userObj) throw new Error("Could not load user information from jwt");
1865
+
1866
+ if (!userObj) {
1867
+ return this.setErrorWidget(Error("No user object in token."));
1868
+ }
1869
+
1870
+ _log$1("Rendering as a Verified widget");
1871
+
1853
1872
  var widgetInstance = await this.widgetApi.upsertUser({
1854
1873
  user: userObj,
1855
1874
  locale: this.locale,
@@ -1857,7 +1876,8 @@ class DeclarativeWidget extends HTMLElement {
1857
1876
  widgetType: this.widgetType,
1858
1877
  jwt: this.token
1859
1878
  }).then(res => this._setWidget(res.template, {
1860
- type: "upsert"
1879
+ type: "upsert",
1880
+ user: userObj
1861
1881
  })).catch(this.setErrorWidget);
1862
1882
  return widgetInstance;
1863
1883
  }
@@ -1986,9 +2006,8 @@ class DeclarativePopupWidget extends DeclarativeWidget {
1986
2006
 
1987
2007
  this.type = "POPUP";
1988
2008
  this.addEventListener("click", e => {
1989
- e.stopPropagation(); // SQUATCH-POPUP target means something in the shadowDOM was clicked (i.e. the dialog element)
1990
-
1991
- if (e.target.tagName !== "SQUATCH-POPUP") this.open();
2009
+ e.stopPropagation();
2010
+ this.open();
1992
2011
  });
1993
2012
  }
1994
2013
 
@@ -2008,13 +2027,25 @@ class DeclarativePopupWidget extends DeclarativeWidget {
2008
2027
  }
2009
2028
 
2010
2029
  async connectedCallback() {
2030
+ this.container = this.getAttribute("container") || this;
2011
2031
  await this.renderWidget();
2012
2032
  if (this.getAttribute("open") !== null) this.open();
2013
2033
  }
2014
2034
 
2015
2035
  }
2016
- window.customElements.define("squatch-embed", DeclarativeEmbedWidget);
2017
- window.customElements.define("squatch-popup", DeclarativePopupWidget);
2036
+
2037
+ class SquatchEmbed extends DeclarativeEmbedWidget {}
2038
+
2039
+ class SquatchPopup extends DeclarativePopupWidget {}
2040
+
2041
+ class ImpactEmbed extends DeclarativeEmbedWidget {}
2042
+
2043
+ class ImpactPopup extends DeclarativePopupWidget {}
2044
+
2045
+ window.customElements.define("squatch-embed", SquatchEmbed);
2046
+ window.customElements.define("impact-embed", ImpactEmbed);
2047
+ window.customElements.define("squatch-popup", SquatchPopup);
2048
+ window.customElements.define("impact-popup", ImpactPopup);
2018
2049
 
2019
2050
  // @ts-check
2020
2051
  function help() {
@@ -2141,6 +2172,8 @@ function init(configIn) {
2141
2172
 
2142
2173
  if (config.tenantAlias.match("^test") || config.debug) {
2143
2174
  debug.enable("squatch-js*");
2175
+ } else {
2176
+ debug.disable();
2144
2177
  }
2145
2178
 
2146
2179
  _log("initializing ...");