@saasquatch/squatch-js 2.8.3-4 → 2.8.3-6

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.
@@ -20,7 +20,7 @@ function k(o) {
20
20
  }), t;
21
21
  }
22
22
  /*! js-cookie v3.0.5 | MIT */
23
- function q(o) {
23
+ function S(o) {
24
24
  for (var t = 1; t < arguments.length; t++) {
25
25
  var e = arguments[t];
26
26
  for (var n in e)
@@ -28,7 +28,7 @@ function q(o) {
28
28
  }
29
29
  return o;
30
30
  }
31
- var Te = {
31
+ var $e = {
32
32
  read: function(o) {
33
33
  return o[0] === '"' && (o = o.slice(1, -1)), o.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
34
34
  },
@@ -42,7 +42,7 @@ var Te = {
42
42
  function V(o, t) {
43
43
  function e(i, s, r) {
44
44
  if (!(typeof document > "u")) {
45
- r = q({}, t, r), typeof r.expires == "number" && (r.expires = new Date(Date.now() + r.expires * 864e5)), r.expires && (r.expires = r.expires.toUTCString()), i = encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
45
+ r = S({}, t, r), typeof r.expires == "number" && (r.expires = new Date(Date.now() + r.expires * 864e5)), r.expires && (r.expires = r.expires.toUTCString()), i = encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
46
46
  var a = "";
47
47
  for (var d in r)
48
48
  r[d] && (a += "; " + d, r[d] !== !0 && (a += "=" + r[d].split(";")[0]));
@@ -71,16 +71,16 @@ function V(o, t) {
71
71
  e(
72
72
  i,
73
73
  "",
74
- q({}, s, {
74
+ S({}, s, {
75
75
  expires: -1
76
76
  })
77
77
  );
78
78
  },
79
79
  withAttributes: function(i) {
80
- return V(this.converter, q({}, this.attributes, i));
80
+ return V(this.converter, S({}, this.attributes, i));
81
81
  },
82
82
  withConverter: function(i) {
83
- return V(q({}, this.converter, i), this.attributes);
83
+ return V(S({}, this.converter, i), this.attributes);
84
84
  }
85
85
  },
86
86
  {
@@ -89,9 +89,9 @@ function V(o, t) {
89
89
  }
90
90
  );
91
91
  }
92
- var M = V(Te, { path: "/" });
93
- const A = "https://app.referralsaasquatch.com", X = "https://fast.ssqt.io/npm", S = "squatch", z = "impact";
94
- function W(o) {
92
+ var P = V($e, { path: "/" });
93
+ const A = "https://app.referralsaasquatch.com", X = "https://fast.ssqt.io/npm", q = "squatch", z = "impact";
94
+ function U(o) {
95
95
  if (typeof o != "object") throw new Error("config must be an object");
96
96
  const t = window.squatchTenant, e = K(), n = {
97
97
  tenantAlias: (o == null ? void 0 : o.tenantAlias) || t,
@@ -112,7 +112,7 @@ function W(o) {
112
112
  function I(o) {
113
113
  return typeof o == "object" && !Array.isArray(o) && o !== null;
114
114
  }
115
- function Ue(o) {
115
+ function Te(o) {
116
116
  if (o && /^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(o))
117
117
  return o;
118
118
  }
@@ -125,7 +125,7 @@ function he(o) {
125
125
  if (!I(o)) throw new Error("Widget properties must be an object");
126
126
  return o;
127
127
  }
128
- function $() {
128
+ function W() {
129
129
  return window.impactToken || window.squatchToken;
130
130
  }
131
131
  function K() {
@@ -142,8 +142,8 @@ function J(o) {
142
142
  }
143
143
  return { message: o };
144
144
  }
145
- async function We(o, t, e, n) {
146
- const i = n || $(), s = {
145
+ async function Ue(o, t, e, n) {
146
+ const i = n || W(), s = {
147
147
  Accept: "application/json",
148
148
  "Content-Type": "application/json",
149
149
  ...i ? { Authorization: `Bearer ${i}` } : {},
@@ -161,11 +161,11 @@ async function We(o, t, e, n) {
161
161
  throw r;
162
162
  }
163
163
  }
164
- async function $e(o, t = "") {
164
+ async function We(o, t = "") {
165
165
  const e = {
166
166
  Accept: "application/json",
167
167
  "Content-Type": "application/json"
168
- }, n = t || $();
168
+ }, n = t || W();
169
169
  n && (e["X-SaaSquatch-User-Token"] = n);
170
170
  try {
171
171
  const i = await fetch(o, {
@@ -183,7 +183,7 @@ async function Q(o, t, e) {
183
183
  const n = {
184
184
  Accept: "application/json",
185
185
  "Content-Type": "application/json"
186
- }, i = e || $();
186
+ }, i = e || W();
187
187
  i && (n["X-SaaSquatch-User-Token"] = i);
188
188
  try {
189
189
  const s = await fetch(o, {
@@ -197,12 +197,12 @@ async function Q(o, t, e) {
197
197
  throw s;
198
198
  }
199
199
  }
200
- async function qe(o, t, e) {
200
+ async function Se(o, t, e) {
201
201
  const n = {
202
202
  Accept: "application/json",
203
203
  "Content-Type": "application/json",
204
204
  "X-SaaSquatch-Referrer": window ? window.location.href : ""
205
- }, i = e || $();
205
+ }, i = e || W();
206
206
  i && (n["X-SaaSquatch-User-Token"] = i);
207
207
  try {
208
208
  const s = await fetch(o, {
@@ -217,7 +217,7 @@ async function qe(o, t, e) {
217
217
  throw s;
218
218
  }
219
219
  }
220
- const Se = `
220
+ const qe = `
221
221
  query renderWidget ($user: UserIdInput, $engagementMedium: UserEngagementMedium, $widgetType: WidgetType, $locale: RSLocale) {
222
222
  renderWidget(user: $user, engagementMedium: $engagementMedium, widgetType: $widgetType, locale: $locale) {
223
223
  template
@@ -254,7 +254,7 @@ class Z {
254
254
  l(this, "domain");
255
255
  l(this, "npmCdn");
256
256
  l(this, "referralCookie", this.squatchReferralCookie);
257
- const n = W(t);
257
+ const n = U(t);
258
258
  this.tenantAlias = n.tenantAlias, this.domain = n.domain, this.npmCdn = n.npmCdn;
259
259
  }
260
260
  /**
@@ -282,8 +282,8 @@ class Z {
282
282
  widgetType: i,
283
283
  engagementMedium: s,
284
284
  locale: a
285
- }), g = `/api/v1/${c}/widget/account/${h}/user/${u}/upsert${p}`, m = this.domain + g, w = (M || window.Cookies).get("_saasquatch");
286
- return w && (d.cookies = w), qe(m, JSON.stringify(d), r);
285
+ }), m = `/api/v1/${c}/widget/account/${h}/user/${u}/upsert${p}`, g = this.domain + m, w = (P || window.Cookies).get("_saasquatch");
286
+ return w && (d.cookies = w), Se(g, JSON.stringify(d), r);
287
287
  }
288
288
  /**
289
289
  * Requests widget template
@@ -299,13 +299,13 @@ class Z {
299
299
  * @return {Promise} template html if true.
300
300
  */
301
301
  render(t) {
302
- const n = he(t), { widgetType: i, engagementMedium: s = "POPUP", jwt: r, user: a } = n, d = encodeURIComponent(this.tenantAlias), c = a != null && a.accountId ? encodeURIComponent(a.accountId) : null, h = a != null && a.id ? encodeURIComponent(a.id) : null, u = n.locale ?? Ue(navigator.language.replace(/\-/g, "_")), p = `/api/v1/${d}/graphql`, g = this.domain + p;
303
- return new Promise(async (m, w) => {
302
+ const n = he(t), { widgetType: i, engagementMedium: s = "POPUP", jwt: r, user: a } = n, d = encodeURIComponent(this.tenantAlias), c = a != null && a.accountId ? encodeURIComponent(a.accountId) : null, h = a != null && a.id ? encodeURIComponent(a.id) : null, u = n.locale ?? Te(navigator.language.replace(/\-/g, "_")), p = `/api/v1/${d}/graphql`, m = this.domain + p;
303
+ return new Promise(async (g, w) => {
304
304
  var b;
305
305
  try {
306
- const f = await We(
307
- g,
308
- Se,
306
+ const f = await Ue(
307
+ m,
308
+ qe,
309
309
  {
310
310
  user: h && c ? { id: h, accountId: c } : null,
311
311
  engagementMedium: s,
@@ -314,7 +314,7 @@ class Z {
314
314
  },
315
315
  r
316
316
  );
317
- m((b = f == null ? void 0 : f.data) == null ? void 0 : b.renderWidget);
317
+ g((b = f == null ? void 0 : f.data) == null ? void 0 : b.renderWidget);
318
318
  } catch (f) {
319
319
  w(f);
320
320
  }
@@ -326,7 +326,7 @@ class Z {
326
326
  * @return {Promise<ReferralCookie>} code referral code if true.
327
327
  */
328
328
  async squatchReferralCookie() {
329
- const t = encodeURIComponent(this.tenantAlias), e = (M || window.Cookies).get("_saasquatch") || "", n = e ? `?cookies=${encodeURIComponent(e)}` : "", i = `${this.domain}/a/${t}/widgets/squatchcookiejson${n}`, s = await $e(i);
329
+ const t = encodeURIComponent(this.tenantAlias), e = (P || window.Cookies).get("_saasquatch") || "", n = e ? `?cookies=${encodeURIComponent(e)}` : "", i = `${this.domain}/a/${t}/widgets/squatchcookiejson${n}`, s = await We(i);
330
330
  return Promise.resolve({
331
331
  ...s,
332
332
  encodedCookie: e
@@ -378,7 +378,7 @@ class ue {
378
378
  constructor(t) {
379
379
  l(this, "domain");
380
380
  var i;
381
- const n = Pe(t);
381
+ const n = Me(t);
382
382
  this.domain = (n == null ? void 0 : n.domain) || ((i = K()) == null ? void 0 : i.domain) || A;
383
383
  }
384
384
  pushAnalyticsLoadEvent(t) {
@@ -391,7 +391,7 @@ class ue {
391
391
  return Q(d, JSON.stringify({}));
392
392
  }
393
393
  }
394
- function Pe(o) {
394
+ function Me(o) {
395
395
  if (!I(o)) throw new Error("'options' should be an object");
396
396
  return o;
397
397
  }
@@ -649,11 +649,11 @@ const pe = ({
649
649
  `}
650
650
  </div>
651
651
  `;
652
- }, Me = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
652
+ }, Pe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
653
653
  __proto__: null,
654
654
  getSkeleton: pe
655
655
  }, Symbol.toStringTag, { value: "Module" })), y = k("squatch-js:widget");
656
- class me {
656
+ class ge {
657
657
  constructor(t) {
658
658
  l(this, "type");
659
659
  l(this, "content");
@@ -664,7 +664,12 @@ class me {
664
664
  l(this, "container");
665
665
  l(this, "loadEventListener", null);
666
666
  var e;
667
- y("widget initializing ..."), this.content = t.content === "error" ? this._error(t.rsCode) : t.content, this.type = t.type, this.widgetApi = t.api, this.npmCdn = t.npmCdn, this.analyticsApi = new ue({ domain: t.domain }), this.context = t.context, this.container = ((e = t.context) == null ? void 0 : e.container) || t.container;
667
+ y("widget initializing ..."), this.content = t.content === "error" ? this._error({
668
+ rsCode: t.rsCode,
669
+ apiErrorCode: t.apiErrorCode,
670
+ statusCode: t.statusCode,
671
+ message: t.errorMessage
672
+ }) : t.content, this.type = t.type, this.widgetApi = t.api, this.npmCdn = t.npmCdn, this.analyticsApi = new ue({ domain: t.domain }), this.context = t.context, this.container = ((e = t.context) == null ? void 0 : e.container) || t.container;
668
673
  }
669
674
  _findElement() {
670
675
  let t;
@@ -749,6 +754,7 @@ class me {
749
754
  });
750
755
  }
751
756
  _error(t, e = "modal", n = "") {
757
+ const { rsCode: i, apiErrorCode: s, statusCode: r, message: a } = t || {};
752
758
  return `<!DOCTYPE html>
753
759
  <!--[if IE 7]><html class="ie7 oldie" lang="en"><![endif]-->
754
760
  <!--[if IE 8]><html class="ie8 oldie" lang="en"><![endif]-->
@@ -757,6 +763,31 @@ class me {
757
763
  <link rel="stylesheet" media="all" href="https://fast.ssqt.io/assets/css/widget/errorpage.css">
758
764
  <style>
759
765
  ${n}
766
+ .error-details {
767
+ margin-top: 16px;
768
+ padding: 12px;
769
+ background: #f8f8f8;
770
+ border-radius: 4px;
771
+ text-align: left;
772
+ font-size: 13px;
773
+ color: #666;
774
+ }
775
+ .error-details dt {
776
+ font-weight: 600;
777
+ color: #333;
778
+ margin-top: 8px;
779
+ }
780
+ .error-details dt:first-child {
781
+ margin-top: 0;
782
+ }
783
+ .error-details dd {
784
+ margin: 4px 0 0 0;
785
+ word-break: break-word;
786
+ font-family: monospace;
787
+ }
788
+ .error-details dd.message {
789
+ font-family: inherit;
790
+ }
760
791
  </style>
761
792
  </head>
762
793
  <body>
@@ -768,14 +799,18 @@ class me {
768
799
  </div>
769
800
  <div class="errorbody">
770
801
  <div class="sadface"><img src="https://fast.ssqt.io/assets/images/face.png"></div>
771
- <h4>Our referral program is temporarily unavailable.</h4><br>
802
+ <h4>Our referral program is temporarily unavailable.</h4>
772
803
  <p>Please reload the page or check back later.</p>
773
- <p>If the persists please contact our support team.</p>
774
- <br>
775
- <br>
776
- <div class="right-align errtxt">
777
- Error Code: ${t}
778
- </div>
804
+ <p>If the problem persists please contact our support team.</p>
805
+
806
+ ${r || s || i || a ? `
807
+ <dl class="error-details">
808
+ ${r ? `<dt>Status Code</dt><dd>${r}</dd>` : ""}
809
+ ${s ? `<dt>API Error Code</dt><dd>${s}</dd>` : ""}
810
+ ${i ? `<dt>RS Code</dt><dd>${i}</dd>` : ""}
811
+ ${a ? `<dt>Message</dt><dd class="message">${a}</dd>` : ""}
812
+ </dl>
813
+ ` : ""}
779
814
  </div>
780
815
  </div>
781
816
  </body>
@@ -905,7 +940,7 @@ function Oe() {
905
940
  document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", e) : setTimeout(e, 0);
906
941
  }
907
942
  const x = k("squatch-js:EMBEDwidget");
908
- class O extends me {
943
+ class O extends ge {
909
944
  constructor(e, n) {
910
945
  super(e);
911
946
  l(this, "show", this.open);
@@ -913,8 +948,8 @@ class O extends me {
913
948
  n && (this.container = n);
914
949
  }
915
950
  async load() {
916
- var m, w, b, f, _, te, ne, ie, oe;
917
- const e = (w = (m = this.context.widgetConfig) == null ? void 0 : m.values) == null ? void 0 : w.brandingConfig, n = (b = this.content) == null ? void 0 : b.includes("mint-components"), i = (e == null ? void 0 : e.loadingHeight) || 500, s = (f = e == null ? void 0 : e.widgetSize) == null ? void 0 : f.embeddedWidgets, r = s != null && s.maxWidth ? L(s.maxWidth) : "", a = s != null && s.minWidth ? L(s.minWidth) : "", d = this._createFrame({
951
+ var g, w, b, f, _, te, ne, ie, oe;
952
+ const e = (w = (g = this.context.widgetConfig) == null ? void 0 : g.values) == null ? void 0 : w.brandingConfig, n = (b = this.content) == null ? void 0 : b.includes("mint-components"), i = (e == null ? void 0 : e.loadingHeight) || 500, s = (f = e == null ? void 0 : e.widgetSize) == null ? void 0 : f.embeddedWidgets, r = s != null && s.maxWidth ? L(s.maxWidth) : "", a = s != null && s.minWidth ? L(s.minWidth) : "", d = this._createFrame({
918
953
  minWidth: a,
919
954
  maxWidth: r,
920
955
  initialHeight: i
@@ -925,10 +960,10 @@ class O extends me {
925
960
  throw new Error("Frame needs a content window");
926
961
  const u = h.document;
927
962
  u.open();
928
- const g = this.widgetApi.domain === "https://staging.referralsaasquatch.com" ? "-staging" : "";
963
+ const m = this.widgetApi.domain === "https://staging.referralsaasquatch.com" ? "-staging" : "";
929
964
  u.write(`
930
965
  ${(ne = e == null ? void 0 : e.main) != null && ne.brandFont ? `
931
- <link rel="preconnect" href="https://fast${g}.ssqt.io">
966
+ <link rel="preconnect" href="https://fast${m}.ssqt.io">
932
967
  <link rel="preconnect" href="https://fonts.gstatic.com">
933
968
  <link rel="preconnect" href="https://fonts.googleapis.com">
934
969
  <link rel="preload" href="https://fonts.googleapis.com/css2?family=${encodeURIComponent(
@@ -987,9 +1022,9 @@ class O extends me {
987
1022
  return !!this.context.user && (e || n);
988
1023
  }
989
1024
  }
990
- const T = k("squatch-js:POPUPwidget");
1025
+ const $ = k("squatch-js:POPUPwidget");
991
1026
  let R = 0;
992
- class D extends me {
1027
+ class D extends ge {
993
1028
  constructor(e, n = ".squatchpop") {
994
1029
  super(e);
995
1030
  l(this, "trigger");
@@ -1005,9 +1040,9 @@ class D extends me {
1005
1040
  if (!this.trigger) return;
1006
1041
  let e;
1007
1042
  try {
1008
- e = document.querySelector(this.trigger) || document.querySelector(".impactpop"), this.trigger && !e && T("No element found with trigger selector", this.trigger);
1043
+ e = document.querySelector(this.trigger) || document.querySelector(".impactpop"), this.trigger && !e && $("No element found with trigger selector", this.trigger);
1009
1044
  } catch {
1010
- T("Not a valid selector", this.trigger);
1045
+ $("Not a valid selector", this.trigger);
1011
1046
  }
1012
1047
  e && (e.onclick = () => {
1013
1048
  this.open();
@@ -1026,8 +1061,8 @@ class D extends me {
1026
1061
  return n.addEventListener("click", a), n;
1027
1062
  }
1028
1063
  async load() {
1029
- var p, g, m, w, b, f, _;
1030
- const e = (g = (p = this.context.widgetConfig) == null ? void 0 : p.values) == null ? void 0 : g.brandingConfig, n = (e == null ? void 0 : e.loadingHeight) || 500, i = (m = this.content) == null ? void 0 : m.includes("mint-components"), s = this._createFrame();
1064
+ var p, m, g, w, b, f, _;
1065
+ const e = (m = (p = this.context.widgetConfig) == null ? void 0 : p.values) == null ? void 0 : m.brandingConfig, n = (e == null ? void 0 : e.loadingHeight) || 500, i = (g = this.content) == null ? void 0 : g.includes("mint-components"), s = this._createFrame();
1031
1066
  s.style.height = n + "px", this._initialiseCTA();
1032
1067
  const r = this.container ? this._findElement() : document.body, a = (r == null ? void 0 : r.shadowRoot) || r, d = this._createPopupDialog(e);
1033
1068
  d.appendChild(s), ((w = a.lastChild) == null ? void 0 : w.nodeName) === "DIALOG" ? a.replaceChild(d, a.lastChild) : a.appendChild(d);
@@ -1054,7 +1089,7 @@ class D extends me {
1054
1089
  ${this._getSkeletonPreloadHTML(i, (_ = e == null ? void 0 : e.color) == null ? void 0 : _.backgroundColor)}
1055
1090
  ${this.content}
1056
1091
  <script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>
1057
- `), h.close(), T("Popup template loaded into iframe"), await this._setupResizeHandler(s);
1092
+ `), h.close(), $("Popup template loaded into iframe"), await this._setupResizeHandler(s);
1058
1093
  }
1059
1094
  async _setupResizeHandler(e) {
1060
1095
  const { contentWindow: n } = e;
@@ -1084,7 +1119,7 @@ class D extends me {
1084
1119
  Y(a, () => {
1085
1120
  var c;
1086
1121
  const d = r.squatch || r.widgetIdent;
1087
- (c = s.contentDocument) == null || c.dispatchEvent(new CustomEvent("sq:refresh")), this.context.user ? (this._loadEvent(d), T("Popup opened")) : this._attachLoadEventListener(a, d);
1122
+ (c = s.contentDocument) == null || c.dispatchEvent(new CustomEvent("sq:refresh")), this.context.user ? (this._loadEvent(d), $("Popup opened")) : this._attachLoadEventListener(a, d);
1088
1123
  });
1089
1124
  }
1090
1125
  close() {
@@ -1092,7 +1127,7 @@ class D extends me {
1092
1127
  e != null && e.contentDocument && this._detachLoadEventListener(e.contentDocument);
1093
1128
  const n = this.container ? this._findElement() : document.body, s = (n.shadowRoot || n).querySelector(`#${this.id}`);
1094
1129
  if (!s) throw new Error("Could not determine container div");
1095
- s.close(), T("Popup closed");
1130
+ s.close(), $("Popup closed");
1096
1131
  }
1097
1132
  _clickedOutside({ target: e }) {
1098
1133
  }
@@ -1137,7 +1172,7 @@ class j {
1137
1172
  * @default "https://fast.ssqt.io/npm"
1138
1173
  */
1139
1174
  l(this, "npmCdn");
1140
- const e = W(t);
1175
+ const e = U(t);
1141
1176
  this.tenantAlias = e.tenantAlias, this.domain = e.domain, this.npmCdn = e.npmCdn, this.api = new Z(e);
1142
1177
  }
1143
1178
  /**
@@ -1176,7 +1211,13 @@ class j {
1176
1211
  user: i.user
1177
1212
  };
1178
1213
  } catch (i) {
1179
- throw console.log("[DEBUG] Widgets.upsertUser catch - err:", i), console.log("[DEBUG] Widgets.upsertUser catch - typeof err:", typeof i), console.log("[DEBUG] Widgets.upsertUser catch - err.apiErrorCode:", i.apiErrorCode), console.log("[DEBUG] Widgets.upsertUser catch - err keys:", Object.keys(i || {})), v(i), i.apiErrorCode && (console.log("[DEBUG] Widgets.upsertUser - calling _renderErrorWidget"), this._renderErrorWidget(i, t.engagementMedium)), new Error(i);
1214
+ throw console.log("[DEBUG] Widgets.upsertUser catch - err:", i), console.log("[DEBUG] Widgets.upsertUser catch - typeof err:", typeof i), console.log(
1215
+ "[DEBUG] Widgets.upsertUser catch - err.apiErrorCode:",
1216
+ i.apiErrorCode
1217
+ ), console.log(
1218
+ "[DEBUG] Widgets.upsertUser catch - err keys:",
1219
+ Object.keys(i || {})
1220
+ ), v(i), i.apiErrorCode && (console.log("[DEBUG] Widgets.upsertUser - calling _renderErrorWidget"), this._renderErrorWidget(i, t.engagementMedium)), new Error(i);
1180
1221
  }
1181
1222
  }
1182
1223
  /**
@@ -1270,10 +1311,10 @@ class j {
1270
1311
  `Don't display ${c.widgetType} when no referral on widget rule match ${c.url}`
1271
1312
  ));
1272
1313
  }), r.fuelTankAutofillUrls && (v("We found a fuel tank autofill!"), r.fuelTankAutofillUrls.forEach(({ url: c, formSelector: h }) => {
1273
- var u, p, g;
1314
+ var u, p, m;
1274
1315
  if (j._matchesUrl(c) && (v("Fuel Tank URL matches"), (p = (u = t.user) == null ? void 0 : u.referredBy) != null && p.code)) {
1275
- const m = document.querySelector(h);
1276
- m ? m.value = ((g = t.user.referredBy.referredReward) == null ? void 0 : g.fuelTankCode) || "" : v(
1316
+ const g = document.querySelector(h);
1317
+ g ? g.value = ((m = t.user.referredBy.referredReward) == null ? void 0 : m.fuelTankCode) || "" : v(
1277
1318
  new Error(
1278
1319
  `Element with id/class ${h} was not found.`
1279
1320
  )
@@ -1296,19 +1337,22 @@ class j {
1296
1337
  * @returns {void}
1297
1338
  */
1298
1339
  _renderErrorWidget(t, e = "POPUP") {
1299
- const { apiErrorCode: n, rsCode: i, message: s } = t;
1300
- v(new Error(`${n} (${i}) ${s}`));
1301
- const r = {
1340
+ const { apiErrorCode: n, rsCode: i, statusCode: s, message: r } = t;
1341
+ v(new Error(`${n} (${i}) ${r}`));
1342
+ const a = {
1302
1343
  content: "error",
1303
1344
  rsCode: i,
1345
+ apiErrorCode: n,
1346
+ statusCode: s,
1347
+ errorMessage: r,
1304
1348
  api: this.api,
1305
1349
  domain: this.domain,
1306
1350
  npmCdn: this.npmCdn,
1307
1351
  type: "ERROR_WIDGET",
1308
1352
  context: { type: "error" }
1309
1353
  };
1310
- let a;
1311
- e === "EMBED" ? (a = new O(r), a.load()) : e === "POPUP" && (a = new D(r), a.load());
1354
+ let d;
1355
+ e === "EMBED" ? (d = new O(a), d.load()) : e === "POPUP" && (d = new D(a), d.load());
1312
1356
  }
1313
1357
  /**
1314
1358
  * @hidden
@@ -1339,7 +1383,7 @@ class De {
1339
1383
  constructor(t) {
1340
1384
  l(this, "tenantAlias");
1341
1385
  l(this, "domain");
1342
- const n = W(t);
1386
+ const n = U(t);
1343
1387
  this.tenantAlias = n.tenantAlias, this.domain = n.domain;
1344
1388
  }
1345
1389
  /**
@@ -1371,14 +1415,14 @@ function Ne(o) {
1371
1415
  }
1372
1416
  function Fe() {
1373
1417
  var i;
1374
- const o = window[z] ? z : S, t = ((i = window["_" + o]) == null ? void 0 : i.ready) || [], e = window.impactOnReady || window.squatchOnReady, n = [...t, e].filter((s) => !!s);
1418
+ const o = window[z] ? z : q, t = ((i = window["_" + o]) == null ? void 0 : i.ready) || [], e = window.impactOnReady || window.squatchOnReady, n = [...t, e].filter((s) => !!s);
1375
1419
  setTimeout(() => {
1376
- window[S] && (window[z] = window[S], n.forEach((s) => s()), window[S]._auto(), window["_" + o] = void 0, delete window["_" + o]);
1420
+ window[q] && (window[z] = window[q], n.forEach((s) => s()), window[q]._auto(), window["_" + o] = void 0, delete window["_" + o]);
1377
1421
  }, 0);
1378
1422
  }
1379
- const E = k("squatch-js"), re = (o) => typeof o == "object" && !Array.isArray(o), ge = (o, t) => {
1423
+ const E = k("squatch-js"), re = (o) => typeof o == "object" && !Array.isArray(o), me = (o, t) => {
1380
1424
  const e = (i) => re(t[i]) && o.hasOwnProperty(i) && re(o[i]), n = Object.getOwnPropertyNames(t).map((i) => ({
1381
- [i]: e(i) ? ge(o[i], t[i]) : t[i]
1425
+ [i]: e(i) ? me(o[i], t[i]) : t[i]
1382
1426
  })).reduce((i, s) => ({ ...i, ...s }), {});
1383
1427
  return {
1384
1428
  ...o,
@@ -1415,18 +1459,18 @@ function Be() {
1415
1459
  return;
1416
1460
  }
1417
1461
  try {
1418
- i = JSON.parse(N(M.get("_saasquatch"))), E("existing cookie", i);
1462
+ i = JSON.parse(N(P.get("_saasquatch"))), E("existing cookie", i);
1419
1463
  } catch (r) {
1420
1464
  E("Unable to retrieve cookie", r);
1421
1465
  }
1422
1466
  try {
1423
1467
  const r = He();
1424
1468
  if (E("domain retrieved:", r), i) {
1425
- const a = ge(i, n);
1469
+ const a = me(i, n);
1426
1470
  s = ae(JSON.stringify(a)), E("cookie to store:", a);
1427
1471
  } else
1428
1472
  s = ae(JSON.stringify(n)), E("cookie to store:", n);
1429
- M.set("_saasquatch", s, {
1473
+ P.set("_saasquatch", s, {
1430
1474
  expires: 365,
1431
1475
  secure: !1,
1432
1476
  sameSite: "Lax",
@@ -1438,26 +1482,26 @@ function Be() {
1438
1482
  }
1439
1483
  }
1440
1484
  }
1441
- const P = k("squatch-js");
1485
+ const M = k("squatch-js");
1442
1486
  function Je() {
1443
1487
  var u;
1444
1488
  const o = window.location.search, e = new URLSearchParams(o).get("_saasquatchExtra") || "";
1445
1489
  if (!e) {
1446
- P("No _saasquatchExtra param");
1490
+ M("No _saasquatchExtra param");
1447
1491
  return;
1448
1492
  }
1449
- const n = W({
1493
+ const n = U({
1450
1494
  tenantAlias: "UNKNOWN"
1451
1495
  });
1452
1496
  if (!n.domain) {
1453
- P("domain must be provided in config to use _saasquatchExtra");
1497
+ M("domain must be provided in config to use _saasquatchExtra");
1454
1498
  return;
1455
1499
  }
1456
1500
  let i;
1457
1501
  try {
1458
1502
  i = JSON.parse(N(e));
1459
1503
  } catch {
1460
- P("Unable to decode _saasquatchExtra config");
1504
+ M("Unable to decode _saasquatchExtra config");
1461
1505
  return;
1462
1506
  }
1463
1507
  function s(p) {
@@ -1465,7 +1509,7 @@ function Je() {
1465
1509
  }
1466
1510
  const r = s(n.domain), a = Object.keys((i == null ? void 0 : i[r]) || {})[0], d = (u = i == null ? void 0 : i[r]) == null ? void 0 : u[a];
1467
1511
  if (!d) {
1468
- P("_saasquatchExtra did not have an expected structure");
1512
+ M("_saasquatchExtra did not have an expected structure");
1469
1513
  return;
1470
1514
  }
1471
1515
  const { autoPopupWidgetType: c, ...h } = d;
@@ -1576,8 +1620,8 @@ class fe extends HTMLElement {
1576
1620
  * @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type`
1577
1621
  */
1578
1622
  l(this, "setErrorWidget", (e) => {
1579
- var i;
1580
- const n = {
1623
+ var d;
1624
+ const n = e instanceof Error ? e.message : e == null ? void 0 : e.message, i = e instanceof Error || e == null ? void 0 : e.apiErrorCode, s = e instanceof Error || e == null ? void 0 : e.rsCode, r = e instanceof Error || e == null ? void 0 : e.statusCode, a = {
1581
1625
  api: this.widgetApi,
1582
1626
  content: "error",
1583
1627
  context: {
@@ -1585,15 +1629,19 @@ class fe extends HTMLElement {
1585
1629
  container: this.container || void 0
1586
1630
  },
1587
1631
  type: "ERROR_WIDGET",
1588
- domain: ((i = this.config) == null ? void 0 : i.domain) || A,
1632
+ domain: ((d = this.config) == null ? void 0 : d.domain) || A,
1589
1633
  npmCdn: X,
1590
- container: this
1634
+ container: this,
1635
+ apiErrorCode: i,
1636
+ rsCode: s,
1637
+ statusCode: r,
1638
+ errorMessage: n
1591
1639
  };
1592
1640
  if (this.type === "EMBED")
1593
- return new O(n);
1641
+ return new O(a);
1594
1642
  {
1595
- const s = this.firstChild ? null : void 0;
1596
- return new D(n, s);
1643
+ const c = this.firstChild ? null : void 0;
1644
+ return new D(a, c);
1597
1645
  }
1598
1646
  });
1599
1647
  l(this, "reload", this.renderWidget);
@@ -1601,7 +1649,7 @@ class fe extends HTMLElement {
1601
1649
  l(this, "hide", this.close);
1602
1650
  this.attachShadow({
1603
1651
  mode: "open"
1604
- }).innerHTML = "<style>:host { display: block; }</style><slot></slot>", this.config = K(), this.token = $(), this.tenant = window.squatchTenant, this.container = this;
1652
+ }).innerHTML = "<style>:host { display: block; }</style><slot></slot>", this.config = K(), this.token = W(), this.tenant = window.squatchTenant, this.container = this;
1605
1653
  }
1606
1654
  _setupApis(e) {
1607
1655
  var n, i;
@@ -1626,17 +1674,27 @@ class fe extends HTMLElement {
1626
1674
  async renderUserUpsertVariant() {
1627
1675
  this._setupApis();
1628
1676
  const e = ze(this.token);
1629
- return e ? (de("Rendering as a Verified widget"), await this.widgetApi.upsertUser({
1630
- user: e,
1631
- locale: this.locale,
1632
- engagementMedium: this.type,
1633
- widgetType: this.widgetType,
1634
- jwt: this.token
1635
- }), await this.widgetApi.render({
1677
+ if (!e)
1678
+ return this.setErrorWidget(Error("No user object in token."));
1679
+ de("Rendering as a Verified widget");
1680
+ try {
1681
+ await this.widgetApi.upsertUser({
1682
+ user: e,
1683
+ locale: this.locale,
1684
+ engagementMedium: this.type,
1685
+ widgetType: this.widgetType,
1686
+ jwt: this.token
1687
+ });
1688
+ } catch (i) {
1689
+ return this.setErrorWidget(
1690
+ i
1691
+ );
1692
+ }
1693
+ return await this.widgetApi.render({
1636
1694
  locale: this.locale,
1637
1695
  engagementMedium: this.type,
1638
1696
  widgetType: this.widgetType
1639
- }).then((i) => this._setWidget(i, { type: "upsert", user: e })).catch(this.setErrorWidget)) : this.setErrorWidget(Error("No user object in token."));
1697
+ }).then((i) => this._setWidget(i, { type: "upsert", user: e })).catch(this.setErrorWidget);
1640
1698
  }
1641
1699
  /**
1642
1700
  * Fetches widget content from SaaSquatch and builds a Widget instance to support rendering the widget in the DOM
@@ -1684,7 +1742,7 @@ class fe extends HTMLElement {
1684
1742
  }
1685
1743
  async connectedCallback() {
1686
1744
  this.loaded = !0, this.container = this.getAttribute("container"), this.widgetType = this.getAttribute("widget") || void 0;
1687
- const e = this.getWidgetType(this.widgetType), { getSkeleton: n } = await Promise.resolve().then(() => Me), i = n({
1745
+ const e = this.getWidgetType(this.widgetType), { getSkeleton: n } = await Promise.resolve().then(() => Pe), i = n({
1688
1746
  height: "100%",
1689
1747
  type: e
1690
1748
  }), s = document.createElement("div");
@@ -1729,7 +1787,7 @@ function et() {
1729
1787
  "Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes."
1730
1788
  );
1731
1789
  }
1732
- const U = k("squatch-js");
1790
+ const T = k("squatch-js");
1733
1791
  let F = null, H = null, B = null;
1734
1792
  function tt() {
1735
1793
  return F || G({}), F;
@@ -1753,8 +1811,8 @@ function ot() {
1753
1811
  }
1754
1812
  }
1755
1813
  function G(o) {
1756
- const e = W(o);
1757
- e.tenantAlias.match("^test") || e.debug ? Ie("squatch-js*") : _e(), U("initializing ..."), F = new Z(e), H = new j(e), B = new De(e), U("Widget API instance", F), U("Widgets instance", H), U("Events API instance", B);
1814
+ const e = U(o);
1815
+ e.tenantAlias.match("^test") || e.debug ? Ie("squatch-js*") : _e(), T("initializing ..."), F = new Z(e), H = new j(e), B = new De(e), T("Widget API instance", F), T("Widgets instance", H), T("Events API instance", B);
1758
1816
  }
1759
1817
  function st(o) {
1760
1818
  o();
@@ -1767,7 +1825,7 @@ function Ke() {
1767
1825
  }
1768
1826
  typeof document < "u" && !window.SaaSquatchDoNotAutoDrop && Ke();
1769
1827
  var ce;
1770
- (ce = window.squatch) != null && ce.init && U(
1828
+ (ce = window.squatch) != null && ce.init && T(
1771
1829
  "Squatchjs is being loaded more than once. This may lead to multiple load events being sent, duplicated widgets, and inaccurate analytics."
1772
1830
  );
1773
1831
  typeof document < "u" && Fe();