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

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.
@@ -91,7 +91,7 @@ function V(o, t) {
91
91
  }
92
92
  var P = V($e, { path: "/" });
93
93
  const A = "https://app.referralsaasquatch.com", X = "https://fast.ssqt.io/npm", q = "squatch", z = "impact";
94
- function U(o) {
94
+ function T(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 U(o) {
112
112
  function I(o) {
113
113
  return typeof o == "object" && !Array.isArray(o) && o !== null;
114
114
  }
115
- function Te(o) {
115
+ function Ue(o) {
116
116
  if (o && /^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(o))
117
117
  return o;
118
118
  }
@@ -131,18 +131,21 @@ function W() {
131
131
  function K() {
132
132
  return window.impactConfig || window.squatchConfig;
133
133
  }
134
- function J(o) {
134
+ function G(o) {
135
135
  console.log("[DEBUG] parseErrorResponse - raw responseText:", o);
136
136
  try {
137
137
  const t = JSON.parse(o);
138
138
  if (console.log("[DEBUG] parseErrorResponse - parsed JSON:", t), t && typeof t == "object")
139
- return console.log("[DEBUG] parseErrorResponse - returning parsed object with apiErrorCode:", t.apiErrorCode), t;
139
+ return console.log(
140
+ "[DEBUG] parseErrorResponse - returning parsed object with apiErrorCode:",
141
+ t.apiErrorCode
142
+ ), t;
140
143
  } catch (t) {
141
144
  console.log("[DEBUG] parseErrorResponse - JSON parse failed:", t);
142
145
  }
143
146
  return { message: o };
144
147
  }
145
- async function Ue(o, t, e, n) {
148
+ async function Te(o, t, e, n) {
146
149
  const i = n || W(), s = {
147
150
  Accept: "application/json",
148
151
  "Content-Type": "application/json",
@@ -155,7 +158,7 @@ async function Ue(o, t, e, n) {
155
158
  body: JSON.stringify({ query: t, variables: e }),
156
159
  headers: s
157
160
  });
158
- if (!r.ok) throw J(await r.text());
161
+ if (!r.ok) throw G(await r.text());
159
162
  return await r.json();
160
163
  } catch (r) {
161
164
  throw r;
@@ -166,14 +169,16 @@ async function We(o, t = "") {
166
169
  Accept: "application/json",
167
170
  "Content-Type": "application/json"
168
171
  }, n = t || W();
169
- n && (e["X-SaaSquatch-User-Token"] = n);
172
+ n ? (e["X-SaaSquatch-User-Token"] = n, console.log("[DEBUG] doGet - Adding token to headers:", n)) : console.log(
173
+ "[DEBUG] doGet - No token found, proceeding without authentication header."
174
+ );
170
175
  try {
171
176
  const i = await fetch(o, {
172
177
  method: "GET",
173
178
  credentials: "include",
174
179
  headers: e
175
180
  }), s = await i.text();
176
- if (!i.ok) throw J(s);
181
+ if (!i.ok) throw G(s);
177
182
  return s && JSON.parse(s);
178
183
  } catch (i) {
179
184
  throw i;
@@ -184,14 +189,16 @@ async function Q(o, t, e) {
184
189
  Accept: "application/json",
185
190
  "Content-Type": "application/json"
186
191
  }, i = e || W();
187
- i && (n["X-SaaSquatch-User-Token"] = i);
192
+ i ? (console.log("[DEBUG] doPost - Adding token to headers:", i), n["X-SaaSquatch-User-Token"] = i) : console.log(
193
+ "[DEBUG] doPost - No token found, proceeding without authentication header."
194
+ );
188
195
  try {
189
196
  const s = await fetch(o, {
190
197
  method: "POST",
191
198
  body: t,
192
199
  headers: n
193
200
  }), r = await s.text();
194
- if (!s.ok) throw J(r);
201
+ if (!s.ok) throw G(r);
195
202
  return r && JSON.parse(r);
196
203
  } catch (s) {
197
204
  throw s;
@@ -211,7 +218,7 @@ async function Se(o, t, e) {
211
218
  credentials: "include",
212
219
  body: t
213
220
  }), r = await s.text();
214
- if (!s.ok) throw J(r);
221
+ if (!s.ok) throw G(r);
215
222
  return r && JSON.parse(r);
216
223
  } catch (s) {
217
224
  throw s;
@@ -254,7 +261,7 @@ class Z {
254
261
  l(this, "domain");
255
262
  l(this, "npmCdn");
256
263
  l(this, "referralCookie", this.squatchReferralCookie);
257
- const n = U(t);
264
+ const n = T(t);
258
265
  this.tenantAlias = n.tenantAlias, this.domain = n.domain, this.npmCdn = n.npmCdn;
259
266
  }
260
267
  /**
@@ -299,11 +306,11 @@ class Z {
299
306
  * @return {Promise} template html if true.
300
307
  */
301
308
  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 ?? Te(navigator.language.replace(/\-/g, "_")), p = `/api/v1/${d}/graphql`, m = this.domain + p;
309
+ 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`, m = this.domain + p;
303
310
  return new Promise(async (g, w) => {
304
311
  var b;
305
312
  try {
306
- const f = await Ue(
313
+ const f = await Te(
307
314
  m,
308
315
  qe,
309
316
  {
@@ -798,7 +805,7 @@ class ge {
798
805
  <p class="errortitle">Error</p>
799
806
  </div>
800
807
  <div class="errorbody">
801
- <div class="sadface"><img src="https://fast.ssqt.io/assets/images/face.png"></div>
808
+ <div class="sadface"><img src="https://res.cloudinary.com/saasquatch-staging/image/upload/v1774538373/whoops-error-image_km94z1.svg"></div>
802
809
  <h4>Our referral program is temporarily unavailable.</h4>
803
810
  <p>Please reload the page or check back later.</p>
804
811
  <p>If the problem persists please contact our support team.</p>
@@ -1172,7 +1179,7 @@ class j {
1172
1179
  * @default "https://fast.ssqt.io/npm"
1173
1180
  */
1174
1181
  l(this, "npmCdn");
1175
- const e = U(t);
1182
+ const e = T(t);
1176
1183
  this.tenantAlias = e.tenantAlias, this.domain = e.domain, this.npmCdn = e.npmCdn, this.api = new Z(e);
1177
1184
  }
1178
1185
  /**
@@ -1383,7 +1390,7 @@ class De {
1383
1390
  constructor(t) {
1384
1391
  l(this, "tenantAlias");
1385
1392
  l(this, "domain");
1386
- const n = U(t);
1393
+ const n = T(t);
1387
1394
  this.tenantAlias = n.tenantAlias, this.domain = n.domain;
1388
1395
  }
1389
1396
  /**
@@ -1442,13 +1449,13 @@ function ae(o) {
1442
1449
  ).join("");
1443
1450
  return btoa(e).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
1444
1451
  }
1445
- function He() {
1452
+ function Be() {
1446
1453
  var o, t, e = "weird_get_top_level_domain=cookie", n = document.location.hostname.split(".");
1447
1454
  for (o = n.length - 1; o >= 0; o--)
1448
1455
  if (t = n.slice(o).join("."), document.cookie = e + ";domain=." + t + ";", document.cookie.indexOf(e) > -1)
1449
1456
  return document.cookie = e.split("=")[0] + "=;domain=." + t + ";expires=Thu, 01 Jan 1970 00:00:01 GMT;", t;
1450
1457
  }
1451
- function Be() {
1458
+ function He() {
1452
1459
  const o = window.location.search, e = new URLSearchParams(o).get("_saasquatch") || "";
1453
1460
  if (e) {
1454
1461
  let n = "", i = "", s = "";
@@ -1464,7 +1471,7 @@ function Be() {
1464
1471
  E("Unable to retrieve cookie", r);
1465
1472
  }
1466
1473
  try {
1467
- const r = He();
1474
+ const r = Be();
1468
1475
  if (E("domain retrieved:", r), i) {
1469
1476
  const a = me(i, n);
1470
1477
  s = ae(JSON.stringify(a)), E("cookie to store:", a);
@@ -1483,14 +1490,14 @@ function Be() {
1483
1490
  }
1484
1491
  }
1485
1492
  const M = k("squatch-js");
1486
- function Je() {
1493
+ function Ge() {
1487
1494
  var u;
1488
1495
  const o = window.location.search, e = new URLSearchParams(o).get("_saasquatchExtra") || "";
1489
1496
  if (!e) {
1490
1497
  M("No _saasquatchExtra param");
1491
1498
  return;
1492
1499
  }
1493
- const n = U({
1500
+ const n = T({
1494
1501
  tenantAlias: "UNKNOWN"
1495
1502
  });
1496
1503
  if (!n.domain) {
@@ -1525,7 +1532,7 @@ function Je() {
1525
1532
  }
1526
1533
  };
1527
1534
  }
1528
- const Ge = k("squatch-js:decodeUserJwt");
1535
+ const Je = k("squatch-js:decodeUserJwt");
1529
1536
  function ze(o) {
1530
1537
  var t;
1531
1538
  try {
@@ -1534,7 +1541,7 @@ function ze(o) {
1534
1541
  const n = N(e);
1535
1542
  return (t = JSON.parse(n)) == null ? void 0 : t.user;
1536
1543
  } catch (e) {
1537
- return Ge(e), null;
1544
+ return Je(e), null;
1538
1545
  }
1539
1546
  }
1540
1547
  const de = k("squatch-js:DeclarativeWidget");
@@ -1787,16 +1794,16 @@ function et() {
1787
1794
  "Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes."
1788
1795
  );
1789
1796
  }
1790
- const T = k("squatch-js");
1791
- let F = null, H = null, B = null;
1797
+ const U = k("squatch-js");
1798
+ let F = null, B = null, H = null;
1792
1799
  function tt() {
1793
- return F || G({}), F;
1800
+ return F || J({}), F;
1794
1801
  }
1795
1802
  function ee() {
1796
- return H || G({}), H;
1803
+ return B || J({}), B;
1797
1804
  }
1798
1805
  function nt() {
1799
- return B || G({}), B;
1806
+ return H || J({}), H;
1800
1807
  }
1801
1808
  function it(o) {
1802
1809
  var t;
@@ -1804,15 +1811,15 @@ function it(o) {
1804
1811
  }
1805
1812
  function ot() {
1806
1813
  var t;
1807
- const o = Je();
1814
+ const o = Ge();
1808
1815
  if (o) {
1809
1816
  const { squatchConfig: e, widgetConfig: n } = o;
1810
- return G(e), (t = ee()) == null ? void 0 : t.render(n);
1817
+ return J(e), (t = ee()) == null ? void 0 : t.render(n);
1811
1818
  }
1812
1819
  }
1813
- function G(o) {
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);
1820
+ function J(o) {
1821
+ const e = T(o);
1822
+ e.tenantAlias.match("^test") || e.debug ? Ie("squatch-js*") : _e(), U("initializing ..."), F = new Z(e), B = new j(e), H = new De(e), U("Widget API instance", F), U("Widgets instance", B), U("Events API instance", H);
1816
1823
  }
1817
1824
  function st(o) {
1818
1825
  o();
@@ -1821,11 +1828,11 @@ function rt(o) {
1821
1828
  ee().autofill(o);
1822
1829
  }
1823
1830
  function Ke() {
1824
- Be();
1831
+ He();
1825
1832
  }
1826
1833
  typeof document < "u" && !window.SaaSquatchDoNotAutoDrop && Ke();
1827
1834
  var ce;
1828
- (ce = window.squatch) != null && ce.init && T(
1835
+ (ce = window.squatch) != null && ce.init && U(
1829
1836
  "Squatchjs is being loaded more than once. This may lead to multiple load events being sent, duplicated widgets, and inaccurate analytics."
1830
1837
  );
1831
1838
  typeof document < "u" && Fe();
@@ -1841,7 +1848,7 @@ export {
1841
1848
  rt as autofill,
1842
1849
  nt as events,
1843
1850
  et as help,
1844
- G as init,
1851
+ J as init,
1845
1852
  Ke as pushCookie,
1846
1853
  st as ready,
1847
1854
  it as widget,