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

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 S(o) {
23
+ function q(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 S(o) {
28
28
  }
29
29
  return o;
30
30
  }
31
- var $e = {
31
+ var Te = {
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 $e = {
42
42
  function V(o, t) {
43
43
  function e(i, s, r) {
44
44
  if (!(typeof document > "u")) {
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);
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);
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
- S({}, s, {
74
+ q({}, s, {
75
75
  expires: -1
76
76
  })
77
77
  );
78
78
  },
79
79
  withAttributes: function(i) {
80
- return V(this.converter, S({}, this.attributes, i));
80
+ return V(this.converter, q({}, this.attributes, i));
81
81
  },
82
82
  withConverter: function(i) {
83
- return V(S({}, this.converter, i), this.attributes);
83
+ return V(q({}, 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 P = V($e, { path: "/" });
93
- const A = "https://app.referralsaasquatch.com", X = "https://fast.ssqt.io/npm", q = "squatch", z = "impact";
94
- function T(o) {
92
+ var P = V(Te, { path: "/" });
93
+ const A = "https://app.referralsaasquatch.com", X = "https://fast.ssqt.io/npm", S = "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 T(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 $e(o) {
116
116
  if (o && /^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(o))
117
117
  return o;
118
118
  }
@@ -145,7 +145,7 @@ function G(o) {
145
145
  }
146
146
  return { message: o };
147
147
  }
148
- async function Te(o, t, e, n) {
148
+ async function Ue(o, t, e, n) {
149
149
  const i = n || W(), s = {
150
150
  Accept: "application/json",
151
151
  "Content-Type": "application/json",
@@ -204,7 +204,7 @@ async function Q(o, t, e) {
204
204
  throw s;
205
205
  }
206
206
  }
207
- async function Se(o, t, e) {
207
+ async function qe(o, t, e) {
208
208
  const n = {
209
209
  Accept: "application/json",
210
210
  "Content-Type": "application/json",
@@ -224,7 +224,7 @@ async function Se(o, t, e) {
224
224
  throw s;
225
225
  }
226
226
  }
227
- const qe = `
227
+ const Se = `
228
228
  query renderWidget ($user: UserIdInput, $engagementMedium: UserEngagementMedium, $widgetType: WidgetType, $locale: RSLocale) {
229
229
  renderWidget(user: $user, engagementMedium: $engagementMedium, widgetType: $widgetType, locale: $locale) {
230
230
  template
@@ -261,7 +261,7 @@ class Z {
261
261
  l(this, "domain");
262
262
  l(this, "npmCdn");
263
263
  l(this, "referralCookie", this.squatchReferralCookie);
264
- const n = T(t);
264
+ const n = U(t);
265
265
  this.tenantAlias = n.tenantAlias, this.domain = n.domain, this.npmCdn = n.npmCdn;
266
266
  }
267
267
  /**
@@ -290,7 +290,7 @@ class Z {
290
290
  engagementMedium: s,
291
291
  locale: a
292
292
  }), m = `/api/v1/${c}/widget/account/${h}/user/${u}/upsert${p}`, g = this.domain + m, w = (P || window.Cookies).get("_saasquatch");
293
- return w && (d.cookies = w), Se(g, JSON.stringify(d), r);
293
+ return w && (d.cookies = w), qe(g, JSON.stringify(d), r);
294
294
  }
295
295
  /**
296
296
  * Requests widget template
@@ -306,13 +306,13 @@ class Z {
306
306
  * @return {Promise} template html if true.
307
307
  */
308
308
  render(t) {
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;
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 ?? $e(navigator.language.replace(/\-/g, "_")), p = `/api/v1/${d}/graphql`, m = this.domain + p;
310
310
  return new Promise(async (g, w) => {
311
311
  var b;
312
312
  try {
313
- const f = await Te(
313
+ const f = await Ue(
314
314
  m,
315
- qe,
315
+ Se,
316
316
  {
317
317
  user: h && c ? { id: h, accountId: c } : null,
318
318
  engagementMedium: s,
@@ -1029,7 +1029,7 @@ class O extends ge {
1029
1029
  return !!this.context.user && (e || n);
1030
1030
  }
1031
1031
  }
1032
- const $ = k("squatch-js:POPUPwidget");
1032
+ const T = k("squatch-js:POPUPwidget");
1033
1033
  let R = 0;
1034
1034
  class D extends ge {
1035
1035
  constructor(e, n = ".squatchpop") {
@@ -1047,9 +1047,9 @@ class D extends ge {
1047
1047
  if (!this.trigger) return;
1048
1048
  let e;
1049
1049
  try {
1050
- e = document.querySelector(this.trigger) || document.querySelector(".impactpop"), this.trigger && !e && $("No element found with trigger selector", this.trigger);
1050
+ e = document.querySelector(this.trigger) || document.querySelector(".impactpop"), this.trigger && !e && T("No element found with trigger selector", this.trigger);
1051
1051
  } catch {
1052
- $("Not a valid selector", this.trigger);
1052
+ T("Not a valid selector", this.trigger);
1053
1053
  }
1054
1054
  e && (e.onclick = () => {
1055
1055
  this.open();
@@ -1096,7 +1096,7 @@ class D extends ge {
1096
1096
  ${this._getSkeletonPreloadHTML(i, (_ = e == null ? void 0 : e.color) == null ? void 0 : _.backgroundColor)}
1097
1097
  ${this.content}
1098
1098
  <script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>
1099
- `), h.close(), $("Popup template loaded into iframe"), await this._setupResizeHandler(s);
1099
+ `), h.close(), T("Popup template loaded into iframe"), await this._setupResizeHandler(s);
1100
1100
  }
1101
1101
  async _setupResizeHandler(e) {
1102
1102
  const { contentWindow: n } = e;
@@ -1126,7 +1126,7 @@ class D extends ge {
1126
1126
  Y(a, () => {
1127
1127
  var c;
1128
1128
  const d = r.squatch || r.widgetIdent;
1129
- (c = s.contentDocument) == null || c.dispatchEvent(new CustomEvent("sq:refresh")), this.context.user ? (this._loadEvent(d), $("Popup opened")) : this._attachLoadEventListener(a, d);
1129
+ (c = s.contentDocument) == null || c.dispatchEvent(new CustomEvent("sq:refresh")), this.context.user ? (this._loadEvent(d), T("Popup opened")) : this._attachLoadEventListener(a, d);
1130
1130
  });
1131
1131
  }
1132
1132
  close() {
@@ -1134,7 +1134,7 @@ class D extends ge {
1134
1134
  e != null && e.contentDocument && this._detachLoadEventListener(e.contentDocument);
1135
1135
  const n = this.container ? this._findElement() : document.body, s = (n.shadowRoot || n).querySelector(`#${this.id}`);
1136
1136
  if (!s) throw new Error("Could not determine container div");
1137
- s.close(), $("Popup closed");
1137
+ s.close(), T("Popup closed");
1138
1138
  }
1139
1139
  _clickedOutside({ target: e }) {
1140
1140
  }
@@ -1179,7 +1179,7 @@ class j {
1179
1179
  * @default "https://fast.ssqt.io/npm"
1180
1180
  */
1181
1181
  l(this, "npmCdn");
1182
- const e = T(t);
1182
+ const e = U(t);
1183
1183
  this.tenantAlias = e.tenantAlias, this.domain = e.domain, this.npmCdn = e.npmCdn, this.api = new Z(e);
1184
1184
  }
1185
1185
  /**
@@ -1390,7 +1390,7 @@ class De {
1390
1390
  constructor(t) {
1391
1391
  l(this, "tenantAlias");
1392
1392
  l(this, "domain");
1393
- const n = T(t);
1393
+ const n = U(t);
1394
1394
  this.tenantAlias = n.tenantAlias, this.domain = n.domain;
1395
1395
  }
1396
1396
  /**
@@ -1422,9 +1422,9 @@ function Ne(o) {
1422
1422
  }
1423
1423
  function Fe() {
1424
1424
  var i;
1425
- 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);
1425
+ 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);
1426
1426
  setTimeout(() => {
1427
- window[q] && (window[z] = window[q], n.forEach((s) => s()), window[q]._auto(), window["_" + o] = void 0, delete window["_" + o]);
1427
+ window[S] && (window[z] = window[S], n.forEach((s) => s()), window[S]._auto(), window["_" + o] = void 0, delete window["_" + o]);
1428
1428
  }, 0);
1429
1429
  }
1430
1430
  const E = k("squatch-js"), re = (o) => typeof o == "object" && !Array.isArray(o), me = (o, t) => {
@@ -1497,7 +1497,7 @@ function Ge() {
1497
1497
  M("No _saasquatchExtra param");
1498
1498
  return;
1499
1499
  }
1500
- const n = T({
1500
+ const n = U({
1501
1501
  tenantAlias: "UNKNOWN"
1502
1502
  });
1503
1503
  if (!n.domain) {
@@ -1710,8 +1710,12 @@ class fe extends HTMLElement {
1710
1710
  */
1711
1711
  async getWidgetInstance() {
1712
1712
  let e;
1713
- if (this.widgetType = this.getAttribute("widget") || void 0, this.locale = this.getAttribute("locale") || this.locale, !this.widgetType) throw new Error("No widget has been specified");
1714
- return this.token ? e = await this.renderUserUpsertVariant() : e = await this.renderPasswordlessVariant(), this.widgetInstance = e, this.widgetInstance && this.dispatchEvent(new CustomEvent("sq:widget-loaded")), e;
1713
+ this.widgetType = this.getAttribute("widget") || void 0, this.locale = this.getAttribute("locale") || this.locale;
1714
+ const n = this.getWidgetType(this.widgetType);
1715
+ if (!this.widgetType) throw new Error("No widget has been specified");
1716
+ return !this.token && n === "verified-access" ? this.setErrorWidget(
1717
+ Error("A valid token is required to render this widget.")
1718
+ ) : (n === "instant-access" ? e = await this.renderPasswordlessVariant() : e = await this.renderUserUpsertVariant(), this.widgetInstance = e, this.widgetInstance && this.dispatchEvent(new CustomEvent("sq:widget-loaded")), e);
1715
1719
  }
1716
1720
  /**
1717
1721
  * Calls {@link getWidgetInstance} to build the Widget instance and loads the widget iframe into the DOM
@@ -1794,7 +1798,7 @@ function et() {
1794
1798
  "Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes."
1795
1799
  );
1796
1800
  }
1797
- const U = k("squatch-js");
1801
+ const $ = k("squatch-js");
1798
1802
  let F = null, B = null, H = null;
1799
1803
  function tt() {
1800
1804
  return F || J({}), F;
@@ -1818,8 +1822,8 @@ function ot() {
1818
1822
  }
1819
1823
  }
1820
1824
  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);
1825
+ const e = U(o);
1826
+ e.tenantAlias.match("^test") || e.debug ? Ie("squatch-js*") : _e(), $("initializing ..."), F = new Z(e), B = new j(e), H = new De(e), $("Widget API instance", F), $("Widgets instance", B), $("Events API instance", H);
1823
1827
  }
1824
1828
  function st(o) {
1825
1829
  o();
@@ -1832,7 +1836,7 @@ function Ke() {
1832
1836
  }
1833
1837
  typeof document < "u" && !window.SaaSquatchDoNotAutoDrop && Ke();
1834
1838
  var ce;
1835
- (ce = window.squatch) != null && ce.init && U(
1839
+ (ce = window.squatch) != null && ce.init && $(
1836
1840
  "Squatchjs is being loaded more than once. This may lead to multiple load events being sent, duplicated widgets, and inaccurate analytics."
1837
1841
  );
1838
1842
  typeof document < "u" && Fe();