@saasquatch/squatch-js 2.8.3-3 → 2.8.3-30

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/babelregister.js +0 -1
  3. package/coverage/base.css +224 -0
  4. package/coverage/block-navigation.js +87 -0
  5. package/coverage/clover.xml +996 -0
  6. package/coverage/coverage-final.json +26 -0
  7. package/coverage/favicon.png +0 -0
  8. package/coverage/prettify.css +1 -0
  9. package/coverage/prettify.js +2 -0
  10. package/coverage/sort-arrow-sprite.png +0 -0
  11. package/coverage/sorter.js +210 -0
  12. package/demo/perf-benchmark.ts +363 -0
  13. package/demo/perf-compare.html +870 -0
  14. package/demo/perf-deploy/vercel.json +17 -0
  15. package/demo/perf-frame.html +417 -0
  16. package/demo/perf-server.ts +131 -0
  17. package/dist/ErrorTemplate-DUNm11h9.js +124 -0
  18. package/dist/ErrorTemplate-DUNm11h9.js.map +1 -0
  19. package/dist/ErrorTemplate-DumOlC5f.cjs +109 -0
  20. package/dist/ErrorTemplate-DumOlC5f.cjs.map +1 -0
  21. package/dist/SkeletonTemplate-B3Bk4NFu.cjs +243 -0
  22. package/dist/SkeletonTemplate-B3Bk4NFu.cjs.map +1 -0
  23. package/dist/SkeletonTemplate-Day_0iMM.js +246 -0
  24. package/dist/SkeletonTemplate-Day_0iMM.js.map +1 -0
  25. package/dist/squatch.cjs.js +33 -2523
  26. package/dist/squatch.cjs.js.map +1 -1
  27. package/dist/squatch.esm.js +928 -1956
  28. package/dist/squatch.esm.js.map +1 -1
  29. package/dist/squatch.js +227 -2373
  30. package/dist/squatch.js.map +1 -1
  31. package/dist/squatch.min.js +4 -5
  32. package/dist/types.d.ts +134 -1
  33. package/dist/utils/cookieUtils.d.ts +1 -0
  34. package/dist/utils/logger.d.ts +23 -0
  35. package/dist/widgets/EmbedWidget.d.ts +1 -1
  36. package/dist/widgets/ErrorTemplate.d.ts +9 -0
  37. package/dist/widgets/PopupWidget.d.ts +3 -5
  38. package/dist/widgets/SkeletonTemplate.d.ts +1 -4
  39. package/dist/widgets/Widget.d.ts +29 -2
  40. package/dist/widgets/declarative/DeclarativeWidget.d.ts +9 -1
  41. package/dist/widgets/declarative/DeclarativeWidgets.d.ts +0 -6
  42. package/package.json +11 -15
  43. package/vite-env.d.ts +2 -1
  44. package/vite.config.ts +17 -0
  45. package/babel.config.js +0 -8
  46. package/jest.config.ts +0 -200
@@ -1,608 +1,235 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- var _a;
5
- function getDefaultExportFromCjs(x) {
6
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
1
+ var Ae = Object.defineProperty;
2
+ var Ie = (o, t, e) => t in o ? Ae(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
3
+ var l = (o, t, e) => Ie(o, typeof t != "symbol" ? t + "" : t, e);
4
+ let _ = null;
5
+ function ve(o) {
6
+ const e = o.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
7
+ _ = new RegExp(`^${e}$`);
7
8
  }
8
- var browser = { exports: {} };
9
- var ms;
10
- var hasRequiredMs;
11
- function requireMs() {
12
- if (hasRequiredMs) return ms;
13
- hasRequiredMs = 1;
14
- var s = 1e3;
15
- var m = s * 60;
16
- var h = m * 60;
17
- var d = h * 24;
18
- var w = d * 7;
19
- var y = d * 365.25;
20
- ms = function(val, options) {
21
- options = options || {};
22
- var type = typeof val;
23
- if (type === "string" && val.length > 0) {
24
- return parse(val);
25
- } else if (type === "number" && isFinite(val)) {
26
- return options.long ? fmtLong(val) : fmtShort(val);
27
- }
28
- throw new Error(
29
- "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
30
- );
31
- };
32
- function parse(str) {
33
- str = String(str);
34
- if (str.length > 100) {
35
- return;
36
- }
37
- var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
38
- str
39
- );
40
- if (!match) {
41
- return;
42
- }
43
- var n = parseFloat(match[1]);
44
- var type = (match[2] || "ms").toLowerCase();
45
- switch (type) {
46
- case "years":
47
- case "year":
48
- case "yrs":
49
- case "yr":
50
- case "y":
51
- return n * y;
52
- case "weeks":
53
- case "week":
54
- case "w":
55
- return n * w;
56
- case "days":
57
- case "day":
58
- case "d":
59
- return n * d;
60
- case "hours":
61
- case "hour":
62
- case "hrs":
63
- case "hr":
64
- case "h":
65
- return n * h;
66
- case "minutes":
67
- case "minute":
68
- case "mins":
69
- case "min":
70
- case "m":
71
- return n * m;
72
- case "seconds":
73
- case "second":
74
- case "secs":
75
- case "sec":
76
- case "s":
77
- return n * s;
78
- case "milliseconds":
79
- case "millisecond":
80
- case "msecs":
81
- case "msec":
82
- case "ms":
83
- return n;
84
- default:
85
- return void 0;
86
- }
87
- }
88
- function fmtShort(ms2) {
89
- var msAbs = Math.abs(ms2);
90
- if (msAbs >= d) {
91
- return Math.round(ms2 / d) + "d";
92
- }
93
- if (msAbs >= h) {
94
- return Math.round(ms2 / h) + "h";
95
- }
96
- if (msAbs >= m) {
97
- return Math.round(ms2 / m) + "m";
98
- }
99
- if (msAbs >= s) {
100
- return Math.round(ms2 / s) + "s";
101
- }
102
- return ms2 + "ms";
103
- }
104
- function fmtLong(ms2) {
105
- var msAbs = Math.abs(ms2);
106
- if (msAbs >= d) {
107
- return plural(ms2, msAbs, d, "day");
108
- }
109
- if (msAbs >= h) {
110
- return plural(ms2, msAbs, h, "hour");
111
- }
112
- if (msAbs >= m) {
113
- return plural(ms2, msAbs, m, "minute");
114
- }
115
- if (msAbs >= s) {
116
- return plural(ms2, msAbs, s, "second");
117
- }
118
- return ms2 + " ms";
119
- }
120
- function plural(ms2, msAbs, n, name) {
121
- var isPlural = msAbs >= n * 1.5;
122
- return Math.round(ms2 / n) + " " + name + (isPlural ? "s" : "");
123
- }
124
- return ms;
9
+ function _e() {
10
+ _ = null;
125
11
  }
126
- var common;
127
- var hasRequiredCommon;
128
- function requireCommon() {
129
- if (hasRequiredCommon) return common;
130
- hasRequiredCommon = 1;
131
- function setup(env) {
132
- createDebug.debug = createDebug;
133
- createDebug.default = createDebug;
134
- createDebug.coerce = coerce;
135
- createDebug.disable = disable;
136
- createDebug.enable = enable;
137
- createDebug.enabled = enabled;
138
- createDebug.humanize = requireMs();
139
- Object.keys(env).forEach(function(key) {
140
- createDebug[key] = env[key];
141
- });
142
- createDebug.instances = [];
143
- createDebug.names = [];
144
- createDebug.skips = [];
145
- createDebug.formatters = {};
146
- function selectColor(namespace) {
147
- var hash = 0;
148
- for (var i = 0; i < namespace.length; i++) {
149
- hash = (hash << 5) - hash + namespace.charCodeAt(i);
150
- hash |= 0;
151
- }
152
- return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
153
- }
154
- createDebug.selectColor = selectColor;
155
- function createDebug(namespace) {
156
- var prevTime;
157
- function debug2() {
158
- if (!debug2.enabled) {
159
- return;
160
- }
161
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
162
- args[_key] = arguments[_key];
163
- }
164
- var self = debug2;
165
- var curr = Number(/* @__PURE__ */ new Date());
166
- var ms2 = curr - (prevTime || curr);
167
- self.diff = ms2;
168
- self.prev = prevTime;
169
- self.curr = curr;
170
- prevTime = curr;
171
- args[0] = createDebug.coerce(args[0]);
172
- if (typeof args[0] !== "string") {
173
- args.unshift("%O");
174
- }
175
- var index = 0;
176
- args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
177
- if (match === "%%") {
178
- return match;
179
- }
180
- index++;
181
- var formatter = createDebug.formatters[format];
182
- if (typeof formatter === "function") {
183
- var val = args[index];
184
- match = formatter.call(self, val);
185
- args.splice(index, 1);
186
- index--;
187
- }
188
- return match;
189
- });
190
- createDebug.formatArgs.call(self, args);
191
- var logFn = self.log || createDebug.log;
192
- logFn.apply(self, args);
193
- }
194
- debug2.namespace = namespace;
195
- debug2.enabled = createDebug.enabled(namespace);
196
- debug2.useColors = createDebug.useColors();
197
- debug2.color = selectColor(namespace);
198
- debug2.destroy = destroy;
199
- debug2.extend = extend;
200
- if (typeof createDebug.init === "function") {
201
- createDebug.init(debug2);
202
- }
203
- createDebug.instances.push(debug2);
204
- return debug2;
205
- }
206
- function destroy() {
207
- var index = createDebug.instances.indexOf(this);
208
- if (index !== -1) {
209
- createDebug.instances.splice(index, 1);
210
- return true;
211
- }
212
- return false;
213
- }
214
- function extend(namespace, delimiter) {
215
- return createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
216
- }
217
- function enable(namespaces) {
218
- createDebug.save(namespaces);
219
- createDebug.names = [];
220
- createDebug.skips = [];
221
- var i;
222
- var split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
223
- var len = split.length;
224
- for (i = 0; i < len; i++) {
225
- if (!split[i]) {
226
- continue;
227
- }
228
- namespaces = split[i].replace(/\*/g, ".*?");
229
- if (namespaces[0] === "-") {
230
- createDebug.skips.push(new RegExp("^" + namespaces.substr(1) + "$"));
231
- } else {
232
- createDebug.names.push(new RegExp("^" + namespaces + "$"));
233
- }
234
- }
235
- for (i = 0; i < createDebug.instances.length; i++) {
236
- var instance = createDebug.instances[i];
237
- instance.enabled = createDebug.enabled(instance.namespace);
238
- }
239
- }
240
- function disable() {
241
- createDebug.enable("");
242
- }
243
- function enabled(name) {
244
- if (name[name.length - 1] === "*") {
245
- return true;
246
- }
247
- var i;
248
- var len;
249
- for (i = 0, len = createDebug.skips.length; i < len; i++) {
250
- if (createDebug.skips[i].test(name)) {
251
- return false;
252
- }
253
- }
254
- for (i = 0, len = createDebug.names.length; i < len; i++) {
255
- if (createDebug.names[i].test(name)) {
256
- return true;
257
- }
258
- }
259
- return false;
260
- }
261
- function coerce(val) {
262
- if (val instanceof Error) {
263
- return val.stack || val.message;
264
- }
265
- return val;
12
+ function C(o) {
13
+ const t = (...e) => {
14
+ _ && _.test(o) && console.log(`[${o}]`, ...e);
15
+ };
16
+ return Object.defineProperty(t, "enabled", {
17
+ get() {
18
+ return !!(_ && _.test(o));
266
19
  }
267
- createDebug.enable(createDebug.load());
268
- return createDebug;
269
- }
270
- common = setup;
271
- return common;
20
+ }), t;
272
21
  }
273
- var hasRequiredBrowser;
274
- function requireBrowser() {
275
- if (hasRequiredBrowser) return browser.exports;
276
- hasRequiredBrowser = 1;
277
- (function(module, exports) {
278
- function _typeof(obj) {
279
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
280
- _typeof = function _typeof2(obj2) {
281
- return typeof obj2;
282
- };
283
- } else {
284
- _typeof = function _typeof2(obj2) {
285
- return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
286
- };
287
- }
288
- return _typeof(obj);
289
- }
290
- exports.log = log;
291
- exports.formatArgs = formatArgs;
292
- exports.save = save;
293
- exports.load = load;
294
- exports.useColors = useColors;
295
- exports.storage = localstorage();
296
- exports.colors = ["#0000CC", "#0000FF", "#0033CC", "#0033FF", "#0066CC", "#0066FF", "#0099CC", "#0099FF", "#00CC00", "#00CC33", "#00CC66", "#00CC99", "#00CCCC", "#00CCFF", "#3300CC", "#3300FF", "#3333CC", "#3333FF", "#3366CC", "#3366FF", "#3399CC", "#3399FF", "#33CC00", "#33CC33", "#33CC66", "#33CC99", "#33CCCC", "#33CCFF", "#6600CC", "#6600FF", "#6633CC", "#6633FF", "#66CC00", "#66CC33", "#9900CC", "#9900FF", "#9933CC", "#9933FF", "#99CC00", "#99CC33", "#CC0000", "#CC0033", "#CC0066", "#CC0099", "#CC00CC", "#CC00FF", "#CC3300", "#CC3333", "#CC3366", "#CC3399", "#CC33CC", "#CC33FF", "#CC6600", "#CC6633", "#CC9900", "#CC9933", "#CCCC00", "#CCCC33", "#FF0000", "#FF0033", "#FF0066", "#FF0099", "#FF00CC", "#FF00FF", "#FF3300", "#FF3333", "#FF3366", "#FF3399", "#FF33CC", "#FF33FF", "#FF6600", "#FF6633", "#FF9900", "#FF9933", "#FFCC00", "#FFCC33"];
297
- function useColors() {
298
- if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
299
- return true;
300
- }
301
- if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
302
- return false;
303
- }
304
- return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
305
- typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
306
- // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
307
- typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
308
- typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
309
- }
310
- function formatArgs(args) {
311
- args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
312
- if (!this.useColors) {
313
- return;
314
- }
315
- var c = "color: " + this.color;
316
- args.splice(1, 0, c, "color: inherit");
317
- var index = 0;
318
- var lastC = 0;
319
- args[0].replace(/%[a-zA-Z%]/g, function(match) {
320
- if (match === "%%") {
321
- return;
322
- }
323
- index++;
324
- if (match === "%c") {
325
- lastC = index;
326
- }
327
- });
328
- args.splice(lastC, 0, c);
329
- }
330
- function log() {
331
- var _console;
332
- return (typeof console === "undefined" ? "undefined" : _typeof(console)) === "object" && console.log && (_console = console).log.apply(_console, arguments);
333
- }
334
- function save(namespaces) {
335
- try {
336
- if (namespaces) {
337
- exports.storage.setItem("debug", namespaces);
338
- } else {
339
- exports.storage.removeItem("debug");
340
- }
341
- } catch (error) {
342
- }
343
- }
344
- function load() {
345
- var r;
346
- try {
347
- r = exports.storage.getItem("debug");
348
- } catch (error) {
349
- }
350
- if (!r && typeof process !== "undefined" && "env" in process) {
351
- r = process.env.DEBUG;
352
- }
353
- return r;
354
- }
355
- function localstorage() {
356
- try {
357
- return localStorage;
358
- } catch (error) {
359
- }
360
- }
361
- module.exports = requireCommon()(exports);
362
- var formatters = module.exports.formatters;
363
- formatters.j = function(v) {
364
- try {
365
- return JSON.stringify(v);
366
- } catch (error) {
367
- return "[UnexpectedJSONParseError]: " + error.message;
368
- }
369
- };
370
- })(browser, browser.exports);
371
- return browser.exports;
22
+ const A = C("squatch-js");
23
+ function V(o) {
24
+ const t = document.cookie.match(
25
+ new RegExp(
26
+ "(?:^|; )" + o.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "=([^;]*)"
27
+ )
28
+ );
29
+ return t ? decodeURIComponent(t[1]) : void 0;
372
30
  }
373
- var browserExports = requireBrowser();
374
- const debug = /* @__PURE__ */ getDefaultExportFromCjs(browserExports);
375
- /*! js-cookie v3.0.5 | MIT */
376
- function assign(target) {
377
- for (var i = 1; i < arguments.length; i++) {
378
- var source = arguments[i];
379
- for (var key in source) {
380
- target[key] = source[key];
381
- }
31
+ function ke(o, t, e) {
32
+ let n = `${encodeURIComponent(o)}=${encodeURIComponent(t)}`;
33
+ {
34
+ const i = /* @__PURE__ */ new Date();
35
+ i.setTime(i.getTime() + e.expires * 864e5), n += `; expires=${i.toUTCString()}`;
382
36
  }
383
- return target;
37
+ e.path && (n += `; path=${e.path}`), e.domain && (n += `; domain=${e.domain}`), e.sameSite && (n += `; SameSite=${e.sameSite}`), document.cookie = n;
384
38
  }
385
- var defaultConverter = {
386
- read: function(value) {
387
- if (value[0] === '"') {
388
- value = value.slice(1, -1);
389
- }
390
- return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
391
- },
392
- write: function(value) {
393
- return encodeURIComponent(value).replace(
394
- /%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
395
- decodeURIComponent
396
- );
397
- }
39
+ const se = (o) => typeof o == "object" && !Array.isArray(o), ce = (o, t) => {
40
+ const e = (i) => se(t[i]) && o.hasOwnProperty(i) && se(o[i]), n = Object.getOwnPropertyNames(t).map((i) => ({
41
+ [i]: e(i) ? ce(o[i], t[i]) : t[i]
42
+ })).reduce((i, s) => ({ ...i, ...s }), {});
43
+ return {
44
+ ...o,
45
+ ...n
46
+ };
398
47
  };
399
- function init$1(converter, defaultAttributes) {
400
- function set(name, value, attributes) {
401
- if (typeof document === "undefined") {
48
+ function L(o) {
49
+ const t = atob(o.replace(/_/g, "/").replace(/-/g, "+")), e = new Uint8Array(t.length);
50
+ for (let n = 0; n < t.length; n++)
51
+ e[n] = t.charCodeAt(n);
52
+ return new TextDecoder("utf8").decode(e);
53
+ }
54
+ function re(o) {
55
+ const t = new TextEncoder().encode(o), e = Array.from(
56
+ t,
57
+ (n) => String.fromCodePoint(n)
58
+ ).join("");
59
+ return btoa(e).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
60
+ }
61
+ function Se() {
62
+ var o, t, e = "weird_get_top_level_domain=cookie", n = document.location.hostname.split(".");
63
+ for (o = n.length - 1; o >= 0; o--)
64
+ if (t = n.slice(o).join("."), document.cookie = e + ";domain=." + t + ";", document.cookie.indexOf(e) > -1)
65
+ return document.cookie = e.split("=")[0] + "=;domain=." + t + ";expires=Thu, 01 Jan 1970 00:00:01 GMT;", t;
66
+ }
67
+ function Te() {
68
+ const o = window.location.search, e = new URLSearchParams(o).get("_saasquatch") || "";
69
+ if (e) {
70
+ let n = "", i = "", s = "";
71
+ try {
72
+ n = JSON.parse(L(e));
73
+ } catch (r) {
74
+ A("Unable to decode params", r);
402
75
  return;
403
76
  }
404
- attributes = assign({}, defaultAttributes, attributes);
405
- if (typeof attributes.expires === "number") {
406
- attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
407
- }
408
- if (attributes.expires) {
409
- attributes.expires = attributes.expires.toUTCString();
77
+ try {
78
+ i = JSON.parse(L(V("_saasquatch"))), A("existing cookie", i);
79
+ } catch (r) {
80
+ A("Unable to retrieve cookie", r);
410
81
  }
411
- name = encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
412
- var stringifiedAttributes = "";
413
- for (var attributeName in attributes) {
414
- if (!attributes[attributeName]) {
415
- continue;
416
- }
417
- stringifiedAttributes += "; " + attributeName;
418
- if (attributes[attributeName] === true) {
419
- continue;
420
- }
421
- stringifiedAttributes += "=" + attributes[attributeName].split(";")[0];
82
+ try {
83
+ const r = Se();
84
+ if (A("domain retrieved:", r), i) {
85
+ const a = ce(i, n);
86
+ s = re(JSON.stringify(a)), A("cookie to store:", a);
87
+ } else
88
+ s = re(JSON.stringify(n)), A("cookie to store:", n);
89
+ ke("_saasquatch", s, {
90
+ expires: 365,
91
+ secure: !1,
92
+ sameSite: "Lax",
93
+ domain: r,
94
+ path: "/"
95
+ });
96
+ } catch (r) {
97
+ A("Unable to set cookie", r);
422
98
  }
423
- return document.cookie = name + "=" + converter.write(value, name) + stringifiedAttributes;
424
99
  }
425
- function get(name) {
426
- if (typeof document === "undefined" || arguments.length && !name) {
427
- return;
428
- }
429
- var cookies = document.cookie ? document.cookie.split("; ") : [];
430
- var jar = {};
431
- for (var i = 0; i < cookies.length; i++) {
432
- var parts = cookies[i].split("=");
433
- var value = parts.slice(1).join("=");
434
- try {
435
- var found = decodeURIComponent(parts[0]);
436
- jar[found] = converter.read(value, found);
437
- if (name === found) {
438
- break;
439
- }
440
- } catch (e) {
441
- }
442
- }
443
- return name ? jar[name] : jar;
444
- }
445
- return Object.create(
446
- {
447
- set,
448
- get,
449
- remove: function(name, attributes) {
450
- set(
451
- name,
452
- "",
453
- assign({}, attributes, {
454
- expires: -1
455
- })
456
- );
457
- },
458
- withAttributes: function(attributes) {
459
- return init$1(this.converter, assign({}, this.attributes, attributes));
460
- },
461
- withConverter: function(converter2) {
462
- return init$1(assign({}, this.converter, converter2), this.attributes);
463
- }
464
- },
465
- {
466
- attributes: { value: Object.freeze(defaultAttributes) },
467
- converter: { value: Object.freeze(converter) }
468
- }
469
- );
470
100
  }
471
- var api$1 = init$1(defaultConverter, { path: "/" });
472
- const DEFAULT_DOMAIN = "https://app.referralsaasquatch.com";
473
- const DEFAULT_NPM_CDN = "https://fast.ssqt.io/npm";
474
- const DEFAULT_NAMESPACE = "squatch";
475
- const IMPACT_NAMESPACE = "impact";
476
- function validateConfig(_raw) {
477
- if (typeof _raw !== "object") throw new Error("config must be an object");
478
- const tenant = window.squatchTenant;
479
- const config = getConfig();
480
- const raw = {
481
- tenantAlias: (_raw == null ? void 0 : _raw["tenantAlias"]) || tenant,
482
- domain: (_raw == null ? void 0 : _raw["domain"]) || (config == null ? void 0 : config.domain),
483
- npmCdn: (_raw == null ? void 0 : _raw["npmCdn"]) || (config == null ? void 0 : config.npmCdn),
484
- debug: (_raw == null ? void 0 : _raw["debug"]) || (config == null ? void 0 : config.debug)
101
+ const k = "https://app.referralsaasquatch.com", X = "https://fast.ssqt.io/npm", M = "squatch", z = "impact";
102
+ function q(o) {
103
+ if (typeof o != "object") throw new Error("config must be an object");
104
+ const t = window.squatchTenant, e = Y(), n = {
105
+ tenantAlias: (o == null ? void 0 : o.tenantAlias) || t,
106
+ domain: (o == null ? void 0 : o.domain) || (e == null ? void 0 : e.domain),
107
+ npmCdn: (o == null ? void 0 : o.npmCdn) || (e == null ? void 0 : e.npmCdn),
108
+ debug: (o == null ? void 0 : o.debug) || (e == null ? void 0 : e.debug)
485
109
  };
486
- if (typeof raw.tenantAlias !== "string")
110
+ if (typeof n.tenantAlias != "string")
487
111
  throw new Error("tenantAlias not provided");
488
- const tenantAlias = raw.tenantAlias;
489
- const domain = typeof raw.domain === "string" && raw.domain || DEFAULT_DOMAIN;
490
- const debug2 = typeof raw.debug === "boolean" && raw.debug || false;
491
- const npmCdn = typeof raw.npmCdn === "string" && raw.npmCdn || DEFAULT_NPM_CDN;
112
+ const i = n.tenantAlias, s = typeof n.domain == "string" && n.domain || k, r = typeof n.debug == "boolean" && n.debug || !1, a = typeof n.npmCdn == "string" && n.npmCdn || X;
492
113
  return {
493
- tenantAlias,
494
- domain,
495
- debug: debug2,
496
- npmCdn
114
+ tenantAlias: i,
115
+ domain: s,
116
+ debug: r,
117
+ npmCdn: a
497
118
  };
498
119
  }
499
- function isObject$1(obj) {
500
- return typeof obj === "object" && !Array.isArray(obj) && obj !== null;
120
+ function S(o) {
121
+ return typeof o == "object" && !Array.isArray(o) && o !== null;
501
122
  }
502
- function validateLocale(locale) {
503
- if (locale && /^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(locale)) {
504
- return locale;
505
- }
123
+ function $e(o) {
124
+ if (o && /^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(o))
125
+ return o;
506
126
  }
507
- function validateWidgetConfig(raw) {
508
- if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
509
- if (!(raw == null ? void 0 : raw["user"])) throw new Error("Required properties missing.");
510
- return raw;
127
+ function de(o) {
128
+ if (!S(o)) throw new Error("Widget properties must be an object");
129
+ if (!(o != null && o.user)) throw new Error("Required properties missing.");
130
+ return o;
511
131
  }
512
- function validatePasswordlessConfig(raw) {
513
- if (!isObject$1(raw)) throw new Error("Widget properties must be an object");
514
- return raw;
132
+ function le(o) {
133
+ if (!S(o)) throw new Error("Widget properties must be an object");
134
+ return o;
515
135
  }
516
- function getToken() {
136
+ function W() {
517
137
  return window.impactToken || window.squatchToken;
518
138
  }
519
- function getConfig() {
139
+ function Y() {
520
140
  return window.impactConfig || window.squatchConfig;
521
141
  }
522
- browserExports.debug("squatch-js:io");
523
- async function doQuery(url, query, variables, jwt) {
524
- const token = jwt || getToken();
525
- const headers = {
142
+ const he = C("squatch-js:io");
143
+ function B(o) {
144
+ let t, e, n, i = o;
145
+ try {
146
+ const r = JSON.parse(o);
147
+ r && typeof r == "object" && (t = r.apiErrorCode, e = r.rsCode, n = r.statusCode, i = r.message || o);
148
+ } catch {
149
+ }
150
+ const s = new Error(i);
151
+ return t && (s.apiErrorCode = t), e && (s.rsCode = e), n !== void 0 && (s.statusCode = n), s;
152
+ }
153
+ async function xe(o, t, e, n) {
154
+ const i = n || W(), s = {
526
155
  Accept: "application/json",
527
156
  "Content-Type": "application/json",
528
- ...token ? { Authorization: `Bearer ${token}` } : {},
157
+ ...i ? { Authorization: `Bearer ${i}` } : {},
529
158
  "X-SaaSquatch-Referrer": window ? window.location.href : ""
530
159
  };
531
160
  try {
532
- const res = await fetch(url, {
161
+ const r = await fetch(o, {
533
162
  method: "POST",
534
- body: JSON.stringify({ query, variables }),
535
- headers
163
+ body: JSON.stringify({ query: t, variables: e }),
164
+ headers: s
536
165
  });
537
- if (!res.ok) throw new Error(await res.text());
538
- return await res.json();
539
- } catch (e) {
540
- throw e;
166
+ if (!r.ok) throw B(await r.text());
167
+ return await r.json();
168
+ } catch (r) {
169
+ throw r;
541
170
  }
542
171
  }
543
- async function doGet(url, jwt = "") {
544
- const headers = {
172
+ async function qe(o, t = "") {
173
+ const e = {
545
174
  Accept: "application/json",
546
175
  "Content-Type": "application/json"
547
- };
548
- const token = jwt || getToken();
549
- if (token) headers["X-SaaSquatch-User-Token"] = token;
176
+ }, n = t || W();
177
+ n ? e["X-SaaSquatch-User-Token"] = n : he(
178
+ "[DEBUG] doGet - No token found, proceeding without authentication header."
179
+ );
550
180
  try {
551
- const res = await fetch(url, {
181
+ const i = await fetch(o, {
552
182
  method: "GET",
553
183
  credentials: "include",
554
- headers
555
- });
556
- const reply = await res.text();
557
- if (!res.ok) throw new Error(reply);
558
- return reply ? JSON.parse(reply) : reply;
559
- } catch (e) {
560
- throw e;
184
+ headers: e
185
+ }), s = await i.text();
186
+ if (!i.ok) throw B(s);
187
+ return s && JSON.parse(s);
188
+ } catch (i) {
189
+ throw i;
561
190
  }
562
191
  }
563
- async function doPost(url, data, jwt) {
564
- const headers = {
192
+ async function Q(o, t, e) {
193
+ const n = {
565
194
  Accept: "application/json",
566
195
  "Content-Type": "application/json"
567
- };
568
- const token = jwt || getToken();
569
- if (token) headers["X-SaaSquatch-User-Token"] = token;
196
+ }, i = e || W();
197
+ i ? n["X-SaaSquatch-User-Token"] = i : he(
198
+ "[DEBUG] doPost - No token found, proceeding without authentication header."
199
+ );
570
200
  try {
571
- const res = await fetch(url, {
201
+ const s = await fetch(o, {
572
202
  method: "POST",
573
- body: data,
574
- headers
575
- });
576
- const reply = await res.text();
577
- if (!res.ok) throw new Error(reply);
578
- return reply ? JSON.parse(reply) : reply;
579
- } catch (e) {
580
- throw e;
203
+ body: t,
204
+ headers: n
205
+ }), r = await s.text();
206
+ if (!s.ok) throw B(r);
207
+ return r && JSON.parse(r);
208
+ } catch (s) {
209
+ throw s;
581
210
  }
582
211
  }
583
- async function doPut(url, data, jwt) {
584
- const headers = {
212
+ async function We(o, t, e) {
213
+ const n = {
585
214
  Accept: "application/json",
586
215
  "Content-Type": "application/json",
587
216
  "X-SaaSquatch-Referrer": window ? window.location.href : ""
588
- };
589
- const token = jwt || getToken();
590
- if (token) headers["X-SaaSquatch-User-Token"] = token;
217
+ }, i = e || W();
218
+ i && (n["X-SaaSquatch-User-Token"] = i);
591
219
  try {
592
- const res = await fetch(url, {
593
- headers,
220
+ const s = await fetch(o, {
221
+ headers: n,
594
222
  method: "PUT",
595
223
  credentials: "include",
596
- body: data
597
- });
598
- const reply = await res.text();
599
- if (!res.ok) throw new Error(reply);
600
- return reply ? JSON.parse(reply) : reply;
601
- } catch (e) {
602
- throw e;
224
+ body: t
225
+ }), r = await s.text();
226
+ if (!s.ok) throw B(r);
227
+ return r && JSON.parse(r);
228
+ } catch (s) {
229
+ throw s;
603
230
  }
604
231
  }
605
- const RENDER_WIDGET_QUERY = `
232
+ const Me = `
606
233
  query renderWidget ($user: UserIdInput, $engagementMedium: UserEngagementMedium, $widgetType: WidgetType, $locale: RSLocale) {
607
234
  renderWidget(user: $user, engagementMedium: $engagementMedium, widgetType: $widgetType, locale: $locale) {
608
235
  template
@@ -617,7 +244,7 @@ const RENDER_WIDGET_QUERY = `
617
244
  }
618
245
  }
619
246
  `;
620
- class WidgetApi {
247
+ class Z {
621
248
  /**
622
249
  * Initialize a new {@link WidgetApi} instance.
623
250
  *
@@ -634,16 +261,13 @@ class WidgetApi {
634
261
  * import {WidgetApi} from '@saasquatch/squatch-js';
635
262
  * let squatchApi = new WidgetApi({tenantAlias:'test_12b5bo1b25125'});
636
263
  */
637
- constructor(config) {
638
- __publicField(this, "tenantAlias");
639
- __publicField(this, "domain");
640
- __publicField(this, "npmCdn");
641
- __publicField(this, "referralCookie", this.squatchReferralCookie);
642
- const raw = config;
643
- const clean = validateConfig(raw);
644
- this.tenantAlias = clean.tenantAlias;
645
- this.domain = clean.domain;
646
- this.npmCdn = clean.npmCdn;
264
+ constructor(t) {
265
+ l(this, "tenantAlias");
266
+ l(this, "domain");
267
+ l(this, "npmCdn");
268
+ l(this, "referralCookie", this.squatchReferralCookie);
269
+ const n = q(t);
270
+ this.tenantAlias = n.tenantAlias, this.domain = n.domain, this.npmCdn = n.npmCdn;
647
271
  }
648
272
  /**
649
273
  * Creates/upserts user, requests widget template.
@@ -659,29 +283,19 @@ class WidgetApi {
659
283
  *
660
284
  * @return {Promise} string if true, with the widget template, jsOptions and user details.
661
285
  */
662
- upsertUser(params) {
663
- const raw = params;
664
- const clean = validateWidgetConfig(raw);
665
- const {
666
- widgetType,
667
- engagementMedium = "POPUP",
668
- jwt,
669
- locale,
670
- user
671
- } = clean;
672
- const tenantAlias = encodeURIComponent(this.tenantAlias);
673
- const accountId = user.accountId ? encodeURIComponent(user.accountId) : null;
674
- const userId = user.id ? encodeURIComponent(user.id) : null;
675
- const optionalParams = _buildParams({
676
- widgetType,
677
- engagementMedium,
678
- locale
679
- });
680
- const path = `/api/v1/${tenantAlias}/widget/account/${accountId}/user/${userId}/upsert${optionalParams}`;
681
- const url = this.domain + path;
682
- const cookies = (api$1 || window.Cookies).get("_saasquatch");
683
- if (cookies) user["cookies"] = cookies;
684
- return doPut(url, JSON.stringify(user), jwt);
286
+ upsertUser(t) {
287
+ const n = de(t), {
288
+ widgetType: i,
289
+ engagementMedium: s = "POPUP",
290
+ jwt: r,
291
+ locale: a,
292
+ user: c
293
+ } = n, d = encodeURIComponent(this.tenantAlias), h = c.accountId ? encodeURIComponent(c.accountId) : null, u = c.id ? encodeURIComponent(c.id) : null, m = Ue({
294
+ widgetType: i,
295
+ engagementMedium: s,
296
+ locale: a
297
+ }), p = `/api/v1/${d}/widget/account/${h}/user/${u}/upsert${m}`, g = this.domain + p, f = V("_saasquatch");
298
+ return f && (c.cookies = f), We(g, JSON.stringify(c), r);
685
299
  }
686
300
  /**
687
301
  * Requests widget template
@@ -696,34 +310,25 @@ class WidgetApi {
696
310
  * to validate the data (can be disabled)
697
311
  * @return {Promise} template html if true.
698
312
  */
699
- render(params) {
700
- const raw = params;
701
- const clean = validatePasswordlessConfig(raw);
702
- const { widgetType, engagementMedium = "POPUP", jwt, user } = clean;
703
- console.log({ params });
704
- const tenantAlias = encodeURIComponent(this.tenantAlias);
705
- const accountId = (user == null ? void 0 : user.accountId) ? encodeURIComponent(user.accountId) : null;
706
- const userId = (user == null ? void 0 : user.id) ? encodeURIComponent(user.id) : null;
707
- const locale = clean.locale ?? validateLocale(navigator.language.replace(/\-/g, "_"));
708
- const path = `/api/v1/${tenantAlias}/graphql`;
709
- const url = this.domain + path;
710
- return new Promise(async (resolve, reject) => {
711
- var _a2;
313
+ render(t) {
314
+ const n = le(t), { widgetType: i, engagementMedium: s = "POPUP", jwt: r, user: a } = n, c = encodeURIComponent(this.tenantAlias), d = 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, "_")), m = `/api/v1/${c}/graphql`, p = this.domain + m;
315
+ return new Promise(async (g, f) => {
316
+ var b;
712
317
  try {
713
- const res = await doQuery(
714
- url,
715
- RENDER_WIDGET_QUERY,
318
+ const w = await xe(
319
+ p,
320
+ Me,
716
321
  {
717
- user: userId && accountId ? { id: userId, accountId } : null,
718
- engagementMedium,
719
- widgetType,
720
- locale
322
+ user: h && d ? { id: h, accountId: d } : null,
323
+ engagementMedium: s,
324
+ widgetType: i,
325
+ locale: u
721
326
  },
722
- jwt
327
+ r
723
328
  );
724
- resolve((_a2 = res == null ? void 0 : res.data) == null ? void 0 : _a2.renderWidget);
725
- } catch (e) {
726
- reject(e);
329
+ g((b = w == null ? void 0 : w.data) == null ? void 0 : b.renderWidget);
330
+ } catch (w) {
331
+ f(w);
727
332
  }
728
333
  });
729
334
  }
@@ -733,64 +338,48 @@ class WidgetApi {
733
338
  * @return {Promise<ReferralCookie>} code referral code if true.
734
339
  */
735
340
  async squatchReferralCookie() {
736
- const tenantAlias = encodeURIComponent(this.tenantAlias);
737
- const _saasquatch = (api$1 || window.Cookies).get("_saasquatch") || "";
738
- const cookie = _saasquatch ? `?cookies=${encodeURIComponent(_saasquatch)}` : ``;
739
- const url = `${this.domain}/a/${tenantAlias}/widgets/squatchcookiejson${cookie}`;
740
- const response = await doGet(url);
341
+ const t = encodeURIComponent(this.tenantAlias), e = V("_saasquatch") || "", n = e ? `?cookies=${encodeURIComponent(e)}` : "", i = `${this.domain}/a/${t}/widgets/squatchcookiejson${n}`, s = await qe(i);
741
342
  return Promise.resolve({
742
- ...response,
743
- encodedCookie: _saasquatch
343
+ ...s,
344
+ encodedCookie: e
744
345
  });
745
346
  }
746
347
  }
747
- function _buildParams({
748
- widgetType,
749
- engagementMedium,
750
- locale
348
+ function Ue({
349
+ widgetType: o,
350
+ engagementMedium: t,
351
+ locale: e
751
352
  }) {
752
- const queryParams = new URLSearchParams();
753
- queryParams.append("engagementMedium", engagementMedium);
754
- if (widgetType) queryParams.append("widgetType", widgetType);
755
- if (locale) queryParams.append("locale", locale);
756
- return `?${queryParams.toString()}`;
353
+ const n = new URLSearchParams();
354
+ return n.append("engagementMedium", t), o && n.append("widgetType", o), e && n.append("locale", e), `?${n.toString()}`;
757
355
  }
758
356
  /*!
759
357
  * domready (c) Dustin Diaz 2014 - License MIT
760
358
  *
761
359
  */
762
- function domready(targetDoc, fn) {
763
- let fns = [];
764
- let listener;
765
- let doc = targetDoc;
766
- let hack = doc.documentElement.doScroll;
767
- let domContentLoaded = "DOMContentLoaded";
768
- let loaded = (hack ? /^loaded|^c/ : /^loaded|^i|^c/).test(doc.readyState);
769
- if (!loaded)
770
- doc.addEventListener(
771
- domContentLoaded,
772
- listener = () => {
773
- doc.removeEventListener(domContentLoaded, listener);
774
- loaded = true;
775
- while (listener = fns.shift()) listener();
776
- }
777
- );
778
- return loaded ? setTimeout(fn, 0) : fns.push(fn);
360
+ function x(o, t) {
361
+ let e = [], n, i = o, s = i.documentElement.doScroll, r = "DOMContentLoaded", a = (s ? /^loaded|^c/ : /^loaded|^i|^c/).test(i.readyState);
362
+ return a || i.addEventListener(
363
+ r,
364
+ n = () => {
365
+ for (i.removeEventListener(r, n), a = !0; n = e.shift(); ) n();
366
+ }
367
+ ), a ? setTimeout(t, 0) : e.push(t);
779
368
  }
780
- function formatWidth({
781
- value,
782
- unit
369
+ function O({
370
+ value: o,
371
+ unit: t
783
372
  }) {
784
- switch (unit) {
373
+ switch (t) {
785
374
  case "px":
786
- return `${value}px`;
375
+ return `${o}px`;
787
376
  case "%":
788
- return `${value}%`;
377
+ return `${o}%`;
789
378
  default:
790
- return `${value}px`;
379
+ return `${o}px`;
791
380
  }
792
381
  }
793
- class AnalyticsApi {
382
+ class ue {
794
383
  /**
795
384
  * Initialize a new {@link AnalyticsApi} instance.
796
385
  *
@@ -798,234 +387,191 @@ class AnalyticsApi {
798
387
  * @param {string} [config.domain='https://app.referralsaasquatch.com'] The server domain.
799
388
  *
800
389
  */
801
- constructor(config) {
802
- __publicField(this, "domain");
803
- var _a2;
804
- const raw = config;
805
- const clean = _validateAnalyticsConfig(raw);
806
- this.domain = (clean == null ? void 0 : clean["domain"]) || ((_a2 = getConfig()) == null ? void 0 : _a2.domain) || DEFAULT_DOMAIN;
807
- }
808
- pushAnalyticsLoadEvent(params) {
809
- if (!params.externalUserId || !params.externalAccountId) return;
810
- const tenantAlias = encodeURIComponent(params.tenantAlias);
811
- const accountId = encodeURIComponent(params.externalAccountId);
812
- const userId = encodeURIComponent(params.externalUserId);
813
- const engagementMedium = encodeURIComponent(params.engagementMedium);
814
- const programId = params.programId ? `&programId=${encodeURIComponent(params.programId)}` : ``;
815
- const path = `/a/${tenantAlias}/widgets/analytics/loaded?externalAccountId=${accountId}&externalUserId=${userId}&engagementMedium=${engagementMedium}${programId}`;
816
- const url = this.domain + path;
817
- return doPost(url, JSON.stringify({}));
818
- }
819
- pushAnalyticsShareClickedEvent(params) {
820
- const tenantAlias = encodeURIComponent(params.tenantAlias);
821
- const accountId = encodeURIComponent(params.externalAccountId);
822
- const userId = encodeURIComponent(params.externalUserId);
823
- const engagementMedium = encodeURIComponent(params.engagementMedium);
824
- const shareMedium = encodeURIComponent(params.shareMedium);
825
- const path = `/a/${tenantAlias}/widgets/analytics/shared?externalAccountId=${accountId}&externalUserId=${userId}&engagementMedium=${engagementMedium}&shareMedium=${shareMedium}`;
826
- const url = this.domain + path;
827
- return doPost(url, JSON.stringify({}));
390
+ constructor(t) {
391
+ l(this, "domain");
392
+ var i;
393
+ const n = Re(t);
394
+ this.domain = (n == null ? void 0 : n.domain) || ((i = Y()) == null ? void 0 : i.domain) || k;
395
+ }
396
+ pushAnalyticsLoadEvent(t) {
397
+ if (!t.externalUserId || !t.externalAccountId) return;
398
+ const e = window.location.search, n = new URLSearchParams(e), i = n == null ? void 0 : n.get("rsShareMedium"), s = encodeURIComponent(t.tenantAlias), r = encodeURIComponent(t.externalAccountId), a = encodeURIComponent(t.externalUserId), c = encodeURIComponent(t.engagementMedium), d = t.programId ? `&programId=${encodeURIComponent(t.programId)}` : "", h = i ? `&shareMedium=${encodeURIComponent(i)}` : "", u = `/a/${s}/widgets/analytics/loaded?externalAccountId=${r}&externalUserId=${a}&engagementMedium=${c}${h}${d}`, m = this.domain + u;
399
+ return Q(m, JSON.stringify({}));
400
+ }
401
+ pushAnalyticsShareClickedEvent(t) {
402
+ const e = encodeURIComponent(t.tenantAlias), n = encodeURIComponent(t.externalAccountId), i = encodeURIComponent(t.externalUserId), s = encodeURIComponent(t.engagementMedium), r = encodeURIComponent(t.shareMedium), a = `/a/${e}/widgets/analytics/shared?externalAccountId=${n}&externalUserId=${i}&engagementMedium=${s}&shareMedium=${r}`, c = this.domain + a;
403
+ return Q(c, JSON.stringify({}));
828
404
  }
829
405
  }
830
- function _validateAnalyticsConfig(raw) {
831
- if (!isObject$1(raw)) throw new Error("'options' should be an object");
832
- return raw;
406
+ function Re(o) {
407
+ if (!S(o)) throw new Error("'options' should be an object");
408
+ return o;
833
409
  }
834
- const _log$8 = browserExports.debug("squatch-js:widget");
835
- class Widget {
836
- constructor(params) {
837
- __publicField(this, "type");
838
- __publicField(this, "content");
839
- __publicField(this, "analyticsApi");
840
- __publicField(this, "widgetApi");
841
- __publicField(this, "context");
842
- __publicField(this, "npmCdn");
843
- __publicField(this, "container");
844
- __publicField(this, "loadEventListener", null);
845
- var _a2;
846
- _log$8("widget initializing ...");
847
- this.content = params.content === "error" ? this._error(params.rsCode) : params.content;
848
- this.type = params.type;
849
- this.widgetApi = params.api;
850
- this.npmCdn = params.npmCdn;
851
- this.analyticsApi = new AnalyticsApi({ domain: params.domain });
852
- this.context = params.context;
853
- this.container = ((_a2 = params.context) == null ? void 0 : _a2.container) || params.container;
410
+ const y = C("squatch-js:widget");
411
+ class me {
412
+ constructor(t) {
413
+ l(this, "type");
414
+ l(this, "content");
415
+ l(this, "analyticsApi");
416
+ l(this, "widgetApi");
417
+ l(this, "context");
418
+ l(this, "npmCdn");
419
+ l(this, "container");
420
+ l(this, "loadEventListener", null);
421
+ l(this, "errorInfo");
422
+ var e;
423
+ y("widget initializing ..."), t.content === "error" ? (this.content = "error", this.errorInfo = {
424
+ rsCode: t.rsCode,
425
+ apiErrorCode: t.apiErrorCode,
426
+ statusCode: t.statusCode,
427
+ message: t.errorMessage
428
+ }) : this.content = 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;
854
429
  }
855
- _findElement() {
856
- let element;
857
- if (typeof this.container === "string") {
858
- element = document.querySelector(this.container);
859
- _log$8("loading widget with selector", element);
860
- } else if (this.container instanceof HTMLElement) {
861
- element = this.container;
862
- _log$8("loading widget with container", element);
863
- } else if (this.container) {
864
- element = null;
865
- _log$8("container must be an HTMLElement or string", this.container);
866
- } else {
867
- element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed") || document.querySelector("#impactembed") || document.querySelector(".impactembed");
868
- _log$8("loading widget with default selector", element);
430
+ /**
431
+ * Returns the widget content, dynamically loading the error template if needed.
432
+ */
433
+ async _getContent() {
434
+ if (this.content === "error" && this.errorInfo) {
435
+ const { getErrorTemplate: t } = await import("./ErrorTemplate-DUNm11h9.js");
436
+ return t({
437
+ rsCode: this.errorInfo.rsCode,
438
+ apiErrorCode: this.errorInfo.apiErrorCode,
439
+ statusCode: this.errorInfo.statusCode,
440
+ mode: this._getErrorMode(),
441
+ style: this._getErrorStyle(),
442
+ message: this.errorInfo.message
443
+ });
869
444
  }
870
- if (!(element instanceof HTMLElement))
445
+ return this.content;
446
+ }
447
+ /** Override in subclasses to customize error template mode */
448
+ _getErrorMode() {
449
+ return "modal";
450
+ }
451
+ /** Override in subclasses to customize error template styles */
452
+ _getErrorStyle() {
453
+ return "";
454
+ }
455
+ _findElement() {
456
+ let t;
457
+ if (typeof this.container == "string" ? (t = document.querySelector(this.container), y("loading widget with selector", t)) : this.container instanceof HTMLElement ? (t = this.container, y("loading widget with container", t)) : this.container ? (t = null, y("container must be an HTMLElement or string", this.container)) : (t = document.querySelector("#squatchembed") || document.querySelector(".squatchembed") || document.querySelector("#impactembed") || document.querySelector(".impactembed"), y("loading widget with default selector", t)), !(t instanceof HTMLElement))
871
458
  throw new Error(
872
459
  `element with selector '${this.container || "#squatchembed, .squatchembed, #impactembed, or .impactembed"}' not found.'`
873
460
  );
874
- return element;
875
- }
876
- _createFrame(options) {
877
- const frame = document.createElement("iframe");
878
- frame["squatchJsApi"] = this;
879
- frame.id = "squatchFrame";
880
- frame.width = "100%";
881
- frame.src = "about:blank";
882
- frame.scrolling = "no";
883
- frame.setAttribute(
461
+ return t;
462
+ }
463
+ _createFrame(t) {
464
+ const e = document.createElement("iframe");
465
+ return e.squatchJsApi = this, e.id = "squatchFrame", e.width = "100%", e.src = "about:blank", e.scrolling = "no", e.setAttribute(
884
466
  "style",
885
- "border: 0; background-color: none; width: 1px; min-width: 100%;"
886
- );
887
- if (options == null ? void 0 : options.minWidth) frame.style.minWidth = options.minWidth;
888
- if (options == null ? void 0 : options.maxWidth) frame.style.maxWidth = options.maxWidth;
889
- if ((options == null ? void 0 : options.maxWidth) || (options == null ? void 0 : options.minWidth)) {
890
- frame.style.width = "100%";
891
- }
892
- if (options == null ? void 0 : options.initialHeight) {
893
- frame.height = options.initialHeight;
894
- }
895
- return frame;
467
+ "border: 0; background-color: none; width: 1px; min-width: 100%; display: block;"
468
+ ), t != null && t.minWidth && (e.style.minWidth = t.minWidth), t != null && t.maxWidth && (e.style.maxWidth = t.maxWidth), (t != null && t.maxWidth || t != null && t.minWidth) && (e.style.width = "100%"), t != null && t.initialHeight && (e.height = String(t.initialHeight)), e;
896
469
  }
897
470
  _findFrame() {
898
- const element = this.container ? this._findElement() : document.body;
899
- const parent = element.shadowRoot || element;
900
- return parent.querySelector(
471
+ const t = this.container ? this._findElement() : document.body;
472
+ return (t.shadowRoot || t).querySelector(
901
473
  "iframe#squatchFrame"
902
474
  );
903
475
  }
904
- _detachLoadEventListener(frameDoc) {
905
- if (this.loadEventListener) {
906
- frameDoc.removeEventListener(
907
- "sq:user-registration",
908
- this.loadEventListener
909
- );
910
- this.loadEventListener = null;
911
- }
912
- }
913
- _attachLoadEventListener(frameDoc, sqh) {
914
- if (this.loadEventListener === null) {
915
- this.loadEventListener = (e) => {
916
- this._loadEvent({
917
- ...sqh,
918
- userId: e.detail.userId,
919
- accountId: e.detail.accountId
920
- });
921
- };
922
- frameDoc.addEventListener("sq:user-registration", this.loadEventListener);
923
- }
476
+ _detachLoadEventListener(t) {
477
+ this.loadEventListener && (t.removeEventListener(
478
+ "sq:user-registration",
479
+ this.loadEventListener
480
+ ), this.loadEventListener = null);
481
+ }
482
+ _attachLoadEventListener(t, e) {
483
+ this.loadEventListener === null && (this.loadEventListener = (n) => {
484
+ this._loadEvent({
485
+ ...e,
486
+ userId: n.detail.userId,
487
+ accountId: n.detail.accountId
488
+ });
489
+ }, t.addEventListener("sq:user-registration", this.loadEventListener));
924
490
  }
925
- _loadEvent(sqh) {
926
- var _a2;
927
- if (!sqh) return;
928
- if (!isObject$1(sqh)) {
491
+ _loadEvent(t) {
492
+ var n;
493
+ if (!t) return;
494
+ if (!S(t))
929
495
  throw new Error("Widget Load event identity property is not an object");
930
- }
931
- let params;
932
- if ("programId" in sqh) {
933
- if (!sqh.tenantAlias || !sqh.accountId || !sqh.userId || !sqh.engagementMedium)
496
+ let e;
497
+ if ("programId" in t) {
498
+ if (!t.tenantAlias || !t.accountId || !t.userId || !t.engagementMedium)
934
499
  throw new Error("Widget Load event missing required properties");
935
- params = {
936
- tenantAlias: sqh.tenantAlias,
937
- externalAccountId: sqh.accountId,
938
- externalUserId: sqh.userId,
939
- engagementMedium: sqh.engagementMedium,
940
- programId: sqh.programId
500
+ e = {
501
+ tenantAlias: t.tenantAlias,
502
+ externalAccountId: t.accountId,
503
+ externalUserId: t.userId,
504
+ engagementMedium: t.engagementMedium,
505
+ programId: t.programId
941
506
  };
942
507
  } else {
943
- const { analytics, mode } = sqh;
944
- params = {
945
- tenantAlias: analytics.attributes.tenant,
946
- externalAccountId: analytics.attributes.accountId,
947
- externalUserId: analytics.attributes.userId,
948
- engagementMedium: mode.widgetMode
508
+ const { analytics: i, mode: s } = t;
509
+ e = {
510
+ tenantAlias: i.attributes.tenant,
511
+ externalAccountId: i.attributes.accountId,
512
+ externalUserId: i.attributes.userId,
513
+ engagementMedium: s.widgetMode
949
514
  };
950
515
  }
951
- (_a2 = this.analyticsApi.pushAnalyticsLoadEvent(params)) == null ? void 0 : _a2.then((response) => {
952
- _log$8(`${params.engagementMedium} loaded event recorded.`);
953
- }).catch((ex) => {
954
- _log$8(`ERROR: pushAnalyticsLoadEvent() ${ex}`);
516
+ (n = this.analyticsApi.pushAnalyticsLoadEvent(e)) == null || n.then((i) => {
517
+ y(`${e.engagementMedium} loaded event recorded.`);
518
+ }).catch((i) => {
519
+ y(`ERROR: pushAnalyticsLoadEvent() ${i}`);
955
520
  });
956
521
  }
957
- _shareEvent(sqh, medium) {
958
- if (sqh) {
959
- this.analyticsApi.pushAnalyticsShareClickedEvent({
960
- tenantAlias: sqh.analytics.attributes.tenant,
961
- externalAccountId: sqh.analytics.attributes.accountId,
962
- externalUserId: sqh.analytics.attributes.userId,
963
- engagementMedium: sqh.mode.widgetMode,
964
- shareMedium: medium
965
- }).then((response) => {
966
- _log$8(
967
- `${sqh.mode.widgetMode} share ${medium} event recorded. ${response}`
968
- );
969
- }).catch((ex) => {
970
- _log$8(`ERROR: pushAnalyticsShareClickedEvent() ${ex}`);
971
- });
972
- }
973
- }
974
- _error(rs, mode = "modal", style = "") {
975
- const errorTemplate = `<!DOCTYPE html>
976
- <!--[if IE 7]><html class="ie7 oldie" lang="en"><![endif]-->
977
- <!--[if IE 8]><html class="ie8 oldie" lang="en"><![endif]-->
978
- <!--[if gt IE 8]><!--><html lang="en"><!--<![endif]-->
979
- <head>
980
- <link rel="stylesheet" media="all" href="https://fast.ssqt.io/assets/css/widget/errorpage.css">
981
- <style>
982
- ${style}
983
- </style>
984
- </head>
985
- <body>
986
-
987
- <div class="squatch-container ${mode}" style="width:100%">
988
- <div class="errorheader">
989
- <button type="button" class="close" onclick="window.frameElement.squatchJsApi.close();">&times;</button>
990
- <p class="errortitle">Error</p>
991
- </div>
992
- <div class="errorbody">
993
- <div class="sadface"><img src="https://fast.ssqt.io/assets/images/face.png"></div>
994
- <h4>Our referral program is temporarily unavailable.</h4><br>
995
- <p>Please reload the page or check back later.</p>
996
- <p>If the persists please contact our support team.</p>
997
- <br>
998
- <br>
999
- <div class="right-align errtxt">
1000
- Error Code: ${rs}
1001
- </div>
1002
- </div>
1003
- </div>
1004
- </body>
1005
- </html>`;
1006
- return errorTemplate;
522
+ _shareEvent(t, e) {
523
+ t && this.analyticsApi.pushAnalyticsShareClickedEvent({
524
+ tenantAlias: t.analytics.attributes.tenant,
525
+ externalAccountId: t.analytics.attributes.accountId,
526
+ externalUserId: t.analytics.attributes.userId,
527
+ engagementMedium: t.mode.widgetMode,
528
+ shareMedium: e
529
+ }).then((n) => {
530
+ y(
531
+ `${t.mode.widgetMode} share ${e} event recorded. ${n}`
532
+ );
533
+ }).catch((n) => {
534
+ y(`ERROR: pushAnalyticsShareClickedEvent() ${n}`);
535
+ });
1007
536
  }
1008
- async _findInnerContainer(frame) {
1009
- const { contentWindow } = frame;
1010
- if (!contentWindow)
537
+ async _findInnerContainer(t) {
538
+ const { contentWindow: e } = t;
539
+ if (!e)
1011
540
  throw new Error("Squatch.js frame inner frame is empty");
1012
- const frameDoc = contentWindow.document;
1013
- function search() {
1014
- const containers = frameDoc.getElementsByTagName("sqh-global-container");
1015
- const legacyContainers = frameDoc.getElementsByClassName("squatch-container");
1016
- const fallback = containers.length > 0 ? containers[0] : legacyContainers.length > 0 ? legacyContainers[0] : null;
1017
- return fallback;
1018
- }
1019
- let found = null;
1020
- for (let i = 0; i < 5; i++) {
1021
- found = search();
1022
- if (found) break;
1023
- await delay(100);
1024
- }
1025
- if (!found) {
1026
- return frameDoc.body;
541
+ const n = e.document;
542
+ function i() {
543
+ const r = n.getElementsByTagName("sqh-global-container"), a = n.getElementsByClassName("squatch-container");
544
+ return r.length > 0 ? r[0] : a.length > 0 ? a[0] : null;
1027
545
  }
1028
- return found;
546
+ let s = null;
547
+ for (let r = 0; r < 5 && (s = i(), !s); r++)
548
+ await Pe(100);
549
+ return s || n.body;
550
+ }
551
+ /**
552
+ * Returns HTML for an in-iframe skeleton preload overlay that is removed
553
+ * once all custom elements in the widget are defined.
554
+ *
555
+ * Uses `customElements.whenDefined()` to wait for all custom element tags,
556
+ * then removes the skeleton after two animation frames. Includes a 10s
557
+ * timeout fallback.
558
+ *
559
+ * Only generates content for mint-components widgets; returns empty string otherwise.
560
+ */
561
+ async _getSkeletonPreloadHTML(t, e) {
562
+ if (!t) return "";
563
+ const { getSkeleton: n } = await import("./SkeletonTemplate-Day_0iMM.js"), i = this.context.type === "passwordless" ? "instant-access" : "verified-access", s = n({
564
+ type: i
565
+ }), r = /* @__PURE__ */ new Set(), a = /<([a-z][\w]*-[\w-]*)/gi;
566
+ let c;
567
+ for (; c = a.exec(this.content); ) r.add(c[1].toLowerCase());
568
+ const d = JSON.stringify([...r]);
569
+ return `
570
+ <div id="sq-preload" style="visibility: visible; position: absolute; top: 0; left: 0; width: 100%; z-index: 9999; background: ${(e || "white").replace(/[^a-zA-Z0-9#(),.\s%-]/g, "")};">
571
+ ${s}
572
+ </div>
573
+ <script>(${Le.toString()})(${d})<\/script>
574
+ `;
1029
575
  }
1030
576
  /**
1031
577
  * Reloads the current widget, makes updated request to API and renders result.
@@ -1033,365 +579,287 @@ class Widget {
1033
579
  * @param param0 Form field values
1034
580
  * @param jwt JWT for API authentication
1035
581
  */
1036
- reload({ email, firstName, lastName }, jwt) {
1037
- const frame = this._findFrame();
1038
- if (!frame) throw new Error("Could not find widget iframe");
1039
- const frameWindow = frame.contentWindow;
1040
- const engagementMedium = this.context.engagementMedium || "POPUP";
1041
- if (!frameWindow) {
582
+ reload({ email: t, firstName: e, lastName: n }, i) {
583
+ const s = this._findFrame();
584
+ if (!s) throw new Error("Could not find widget iframe");
585
+ const r = s.contentWindow, a = this.context.engagementMedium || "POPUP";
586
+ if (!r)
1042
587
  throw new Error("Frame needs a content window");
1043
- }
1044
- let response;
588
+ let c;
1045
589
  if (this.context.type === "upsert") {
1046
590
  if (!this.context.user) throw new Error("Can't reload without user ids");
1047
- let userObj = {
1048
- email: email || null,
1049
- firstName: firstName || null,
1050
- lastName: lastName || null,
591
+ let d = {
592
+ email: t || null,
593
+ firstName: e || null,
594
+ lastName: n || null,
1051
595
  id: this.context.user.id,
1052
596
  accountId: this.context.user.accountId
1053
597
  };
1054
- response = this.widgetApi.upsertUser({
1055
- user: userObj,
1056
- engagementMedium,
598
+ c = this.widgetApi.upsertUser({
599
+ user: d,
600
+ engagementMedium: a,
1057
601
  widgetType: this.type,
1058
- jwt
602
+ jwt: i
1059
603
  });
1060
- } else if (this.context.type === "passwordless") {
1061
- response = this.widgetApi.render({
604
+ } else if (this.context.type === "passwordless")
605
+ c = this.widgetApi.render({
1062
606
  user: void 0,
1063
- engagementMedium,
607
+ engagementMedium: a,
1064
608
  widgetType: this.type,
1065
609
  jwt: void 0
1066
610
  });
1067
- } else {
611
+ else
1068
612
  throw new Error("can't reload an error widget");
1069
- }
1070
- response.then(({ template }) => {
1071
- if (template) {
1072
- this.content = template;
1073
- this.__deprecated__register(
1074
- frame,
1075
- { email, engagementMedium },
1076
- () => {
1077
- this.load();
1078
- engagementMedium === "POPUP" && this.open();
1079
- }
1080
- );
1081
- }
1082
- }).catch(({ message }) => {
1083
- _log$8(`${message}`);
613
+ c.then(({ template: d }) => {
614
+ d && (this.content = d, this.__deprecated__register(
615
+ s,
616
+ { email: t, engagementMedium: a },
617
+ () => {
618
+ this.load(), a === "POPUP" && this.open();
619
+ }
620
+ ));
621
+ }).catch(({ message: d }) => {
622
+ y(`${d}`);
1084
623
  });
1085
624
  }
1086
- __deprecated__register(frame, params, onClick) {
1087
- const frameWindow = frame.contentWindow;
1088
- const frameDoc = frameWindow.document;
1089
- const showStatsBtn = frameDoc.createElement("button");
1090
- const registerForm = frameDoc.getElementsByClassName("squatch-register")[0];
1091
- if (registerForm) {
1092
- showStatsBtn.className = "btn btn-primary";
1093
- showStatsBtn.id = "show-stats-btn";
1094
- showStatsBtn.textContent = this.type === "REFERRER_WIDGET" ? "Show Stats" : "Show Reward";
1095
- const widgetStyle = params.engagementMedium === "POPUP" ? "margin-top: 10px; max-width: 130px; width: 100%;" : "margin-top: 10px;";
1096
- showStatsBtn.setAttribute("style", widgetStyle);
1097
- showStatsBtn.onclick = onClick;
1098
- registerForm.style.paddingTop = "30px";
1099
- registerForm.innerHTML = `<p><strong>${params.email}</strong><br>Has been successfully registered</p>`;
1100
- registerForm.appendChild(showStatsBtn);
625
+ __deprecated__register(t, e, n) {
626
+ const s = t.contentWindow.document, r = s.createElement("button"), a = s.getElementsByClassName("squatch-register")[0];
627
+ if (a) {
628
+ r.className = "btn btn-primary", r.id = "show-stats-btn", r.textContent = this.type === "REFERRER_WIDGET" ? "Show Stats" : "Show Reward";
629
+ const c = e.engagementMedium === "POPUP" ? "margin-top: 10px; max-width: 130px; width: 100%;" : "margin-top: 10px;";
630
+ r.setAttribute("style", c), r.onclick = n, a.style.paddingTop = "30px", a.innerHTML = `<p><strong>${e.email}</strong><br>Has been successfully registered</p>`, a.appendChild(r);
1101
631
  }
1102
632
  }
1103
633
  }
1104
- function delay(duration) {
1105
- return new Promise((resolve) => {
1106
- setTimeout(resolve, duration);
634
+ function Pe(o) {
635
+ return new Promise((t) => {
636
+ setTimeout(t, o);
1107
637
  });
1108
638
  }
1109
- const _log$7 = browserExports.debug("squatch-js:EMBEDwidget");
1110
- class EmbedWidget extends Widget {
1111
- constructor(params, container) {
1112
- super(params);
1113
- __publicField(this, "show", this.open);
1114
- __publicField(this, "hide", this.close);
1115
- if (container) {
1116
- this.container = container;
1117
- }
639
+ function Le(o) {
640
+ var t = setTimeout(e, 1e4);
641
+ function e() {
642
+ var i = document.getElementById("sq-preload");
643
+ i && i.remove(), clearTimeout(t);
644
+ }
645
+ function n() {
646
+ if (!o || !o.length) return e();
647
+ Promise.all(
648
+ o.map(function(i) {
649
+ return customElements.whenDefined(i);
650
+ })
651
+ ).then(function() {
652
+ requestAnimationFrame(function() {
653
+ requestAnimationFrame(e);
654
+ });
655
+ });
656
+ }
657
+ document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", n) : setTimeout(n, 0);
658
+ }
659
+ const I = C("squatch-js:EMBEDwidget");
660
+ class D extends me {
661
+ constructor(e, n) {
662
+ super(e);
663
+ l(this, "show", this.open);
664
+ l(this, "hide", this.close);
665
+ n && (this.container = n);
1118
666
  }
1119
667
  async load() {
1120
- var _a2, _b, _c, _d, _e, _f, _g;
1121
- const brandingConfig = (_b = (_a2 = this.context.widgetConfig) == null ? void 0 : _a2.values) == null ? void 0 : _b.brandingConfig;
1122
- const initialHeight = brandingConfig == null ? void 0 : brandingConfig.loadingHeight;
1123
- const sizes = (_c = brandingConfig == null ? void 0 : brandingConfig.widgetSize) == null ? void 0 : _c.embeddedWidgets;
1124
- const maxWidth = (sizes == null ? void 0 : sizes.maxWidth) ? formatWidth(sizes.maxWidth) : "";
1125
- const minWidth = (sizes == null ? void 0 : sizes.minWidth) ? formatWidth(sizes.minWidth) : "";
1126
- const frame = this._createFrame({
1127
- minWidth,
1128
- maxWidth,
1129
- initialHeight
1130
- });
1131
- const element = this._findElement();
1132
- if ((_d = this.context) == null ? void 0 : _d.container) {
1133
- element.style.visibility = "hidden";
1134
- element.style.height = "0";
1135
- element.style["overflow-y"] = "hidden";
1136
- }
1137
- if (this.container) {
1138
- if (element.shadowRoot) {
1139
- if (((_e = element.shadowRoot.lastChild) == null ? void 0 : _e.nodeName) === "IFRAME") {
1140
- element.shadowRoot.replaceChild(frame, element.shadowRoot.lastChild);
1141
- } else {
1142
- element.shadowRoot.appendChild(frame);
1143
- }
1144
- } else if (element.firstChild) {
1145
- element.replaceChild(frame, element.firstChild);
1146
- } else {
1147
- element.appendChild(frame);
1148
- }
1149
- } else if (!element.firstChild || element.firstChild.nodeName === "#text") {
1150
- element.appendChild(frame);
1151
- }
1152
- const { contentWindow } = frame;
1153
- if (!contentWindow) {
668
+ var g, f, b, w, T, ee, te, ne, ie;
669
+ const e = (f = (g = this.context.widgetConfig) == null ? void 0 : g.values) == null ? void 0 : f.brandingConfig, n = (b = this.content) == null ? void 0 : b.includes("mint-components"), i = (e == null ? void 0 : e.loadingHeight) || 500, s = (w = e == null ? void 0 : e.widgetSize) == null ? void 0 : w.embeddedWidgets, r = s != null && s.maxWidth ? O(s.maxWidth) : "", a = s != null && s.minWidth ? O(s.minWidth) : "", c = this._createFrame({
670
+ minWidth: a,
671
+ maxWidth: r,
672
+ initialHeight: i
673
+ }), d = this._findElement();
674
+ (T = this.context) != null && T.container && (d.style.visibility = "hidden", d.style.height = "0", d.style["overflow-y"] = "hidden"), this.container ? d.shadowRoot ? ((ee = d.shadowRoot.lastChild) == null ? void 0 : ee.nodeName) === "IFRAME" ? d.shadowRoot.replaceChild(c, d.shadowRoot.lastChild) : d.shadowRoot.appendChild(c) : d.firstChild ? d.replaceChild(c, d.firstChild) : d.appendChild(c) : (!d.firstChild || d.firstChild.nodeName === "#text") && d.appendChild(c);
675
+ const { contentWindow: h } = c;
676
+ if (!h)
1154
677
  throw new Error("Frame needs a content window");
678
+ const u = h.document;
679
+ if (u.open(), this.content === "error") {
680
+ u.write(await this._getContent()), u.close(), x(u, () => {
681
+ c.height = u.body.scrollHeight;
682
+ });
683
+ return;
1155
684
  }
1156
- const frameDoc = contentWindow.document;
1157
- frameDoc.open();
1158
- const domain = this.widgetApi.domain;
1159
- frameDoc.write(`
1160
- ${((_f = brandingConfig == null ? void 0 : brandingConfig.main) == null ? void 0 : _f.brandFont) ? `
1161
- <link rel="preconnect" href="https://fast${domain === "https://staging.referralsaasquatch.com" && "-staging"}.ssqt.io">
1162
- <link rel="preconnect" href="https://fonts.gstatic.com">
685
+ const p = this.widgetApi.domain === "https://staging.referralsaasquatch.com" ? "-staging" : "";
686
+ u.write(`
687
+ ${(te = e == null ? void 0 : e.main) != null && te.brandFont ? `
688
+ <link rel="preconnect" href="https://fast${p}.ssqt.io">
689
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
1163
690
  <link rel="preconnect" href="https://fonts.googleapis.com">
1164
691
  <link rel="preload" href="https://fonts.googleapis.com/css2?family=${encodeURIComponent(
1165
- (_g = brandingConfig == null ? void 0 : brandingConfig.main) == null ? void 0 : _g.brandFont
692
+ (ne = e == null ? void 0 : e.main) == null ? void 0 : ne.brandFont
1166
693
  )}" as="style">` : ""}
1167
- <script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>
694
+ <link rel="dns-prefetch" href="https://res.cloudinary.com">
695
+ <link rel="preconnect" href="https://res.cloudinary.com" crossorigin>
696
+ ${n ? `
1168
697
  <style data-styles>
1169
- html { visibility:hidden;}
1170
- </style>
1171
- ${this.content}
1172
-
1173
- `);
1174
- frameDoc.close();
1175
- domready(frameDoc, async () => {
1176
- const _sqh = contentWindow.squatch || contentWindow.widgetIdent;
1177
- frame.height = initialHeight || frameDoc.body.scrollHeight;
1178
- console.log({ height: frameDoc.body.scrollHeight });
1179
- const ro = new contentWindow["ResizeObserver"]((entries) => {
1180
- for (const entry of entries) {
1181
- const { height } = entry.contentRect;
1182
- frame.height = height;
698
+ html { visibility: hidden; }
699
+ </style>` : ""}
700
+ ${await this._getSkeletonPreloadHTML(n, (ie = e == null ? void 0 : e.color) == null ? void 0 : ie.backgroundColor)}
701
+ ${await this._getContent()}
702
+ `), u.close(), x(u, async () => {
703
+ const oe = h.squatch || h.widgetIdent;
704
+ c.height = i;
705
+ const fe = new h.ResizeObserver((Ee) => {
706
+ for (const Ce of Ee) {
707
+ const { height: be } = Ce.contentRect;
708
+ c.height = be;
1183
709
  }
1184
- });
1185
- const container = await this._findInnerContainer(frame);
1186
- ro.observe(container);
1187
- if (this._shouldFireLoadEvent()) {
1188
- this._loadEvent(_sqh);
1189
- _log$7("loaded");
1190
- } else if (frameDoc) {
1191
- this._attachLoadEventListener(frameDoc, _sqh);
1192
- }
710
+ }), ye = await this._findInnerContainer(c);
711
+ fe.observe(ye), this._shouldFireLoadEvent() ? (this._loadEvent(oe), I("loaded")) : u && this._attachLoadEventListener(u, oe);
1193
712
  });
1194
713
  }
1195
714
  /**
1196
715
  * Un-hide if element is available and refresh data
1197
716
  */
1198
717
  open() {
1199
- const frame = this._findFrame();
1200
- if (!frame) return _log$7("no target element to open");
1201
- if (!frame.contentWindow) return _log$7("Frame needs a content window");
1202
- const element = this._findElement();
1203
- element.style.visibility = "unset";
1204
- element.style.height = "auto";
1205
- element.style["overflow-y"] = "auto";
1206
- frame.contentWindow.document.dispatchEvent(new CustomEvent("sq:refresh"));
1207
- const _sqh = frame.contentWindow.squatch || frame.contentWindow.widgetIdent;
1208
- if (this.context.user) {
1209
- this._loadEvent(_sqh);
1210
- _log$7("loaded");
1211
- } else {
1212
- if (!frame.contentDocument) return;
1213
- this._attachLoadEventListener(frame.contentDocument, _sqh);
718
+ const e = this._findFrame();
719
+ if (!e) return I("no target element to open");
720
+ if (!e.contentWindow) return I("Frame needs a content window");
721
+ const n = this._findElement();
722
+ n.style.visibility = "unset", n.style.height = "auto", n.style["overflow-y"] = "auto", e.contentWindow.document.dispatchEvent(new CustomEvent("sq:refresh"));
723
+ const i = e.contentWindow.squatch || e.contentWindow.widgetIdent;
724
+ if (this.context.user)
725
+ this._loadEvent(i), I("loaded");
726
+ else {
727
+ if (!e.contentDocument) return;
728
+ this._attachLoadEventListener(e.contentDocument, i);
1214
729
  }
1215
730
  }
1216
731
  close() {
1217
- const frame = this._findFrame();
1218
- if (!frame) return _log$7("no target element to close");
1219
- if (frame.contentDocument)
1220
- this._detachLoadEventListener(frame.contentDocument);
1221
- const element = this._findElement();
1222
- element.style.visibility = "hidden";
1223
- element.style.height = "0";
1224
- element.style["overflow-y"] = "hidden";
1225
- _log$7("Embed widget closed");
1226
- }
1227
- _error(rs, mode = "embed", style = "") {
1228
- return super._error(rs, mode, style);
732
+ const e = this._findFrame();
733
+ if (!e) return I("no target element to close");
734
+ e.contentDocument && this._detachLoadEventListener(e.contentDocument);
735
+ const n = this._findElement();
736
+ n.style.visibility = "hidden", n.style.height = "0", n.style["overflow-y"] = "hidden", I("Embed widget closed");
737
+ }
738
+ _getErrorMode() {
739
+ return "embed";
1229
740
  }
1230
741
  _shouldFireLoadEvent() {
1231
- const noContainer = !this.container;
1232
- const isComponent = this.container instanceof HTMLElement && (this.container.tagName.startsWith("SQUATCH-") || this.container.tagName.startsWith("IMPACT-"));
1233
- const isVerified = !!this.context.user;
1234
- return isVerified && (noContainer || isComponent);
742
+ const e = !this.container, n = this.container instanceof HTMLElement && (this.container.tagName.startsWith("SQUATCH-") || this.container.tagName.startsWith("IMPACT-"));
743
+ return !!this.context.user && (e || n);
1235
744
  }
1236
745
  }
1237
- const _log$6 = browserExports.debug("squatch-js:POPUPwidget");
1238
- let popupId = 0;
1239
- class PopupWidget extends Widget {
1240
- constructor(params, trigger = ".squatchpop") {
1241
- super(params);
1242
- __publicField(this, "trigger");
1243
- __publicField(this, "id");
1244
- __publicField(this, "show", this.open);
1245
- __publicField(this, "hide", this.close);
1246
- this.trigger = trigger;
1247
- if (this.container) {
1248
- this.id = "squatchModal";
1249
- } else {
1250
- this.id = popupId === 0 ? `squatchModal` : `squatchModal__${popupId}`;
1251
- popupId = popupId + 1;
1252
- }
1253
- document.head.insertAdjacentHTML(
746
+ const v = C("squatch-js:POPUPwidget");
747
+ let U = 0;
748
+ class j extends me {
749
+ constructor(e, n = ".squatchpop") {
750
+ super(e);
751
+ l(this, "trigger");
752
+ l(this, "id");
753
+ l(this, "show", this.open);
754
+ l(this, "hide", this.close);
755
+ this.trigger = n, this.container ? this.id = "squatchModal" : (this.id = U === 0 ? "squatchModal" : `squatchModal__${U}`, U = U + 1), document.head.insertAdjacentHTML(
1254
756
  "beforeend",
1255
757
  `<style>#${this.id}::-webkit-scrollbar { display: none; }</style>`
1256
758
  );
1257
759
  }
1258
760
  _initialiseCTA() {
1259
761
  if (!this.trigger) return;
1260
- let triggerElement;
762
+ let e;
1261
763
  try {
1262
- triggerElement = document.querySelector(this.trigger) || document.querySelector(".impactpop");
1263
- if (this.trigger && !triggerElement)
1264
- _log$6("No element found with trigger selector", this.trigger);
764
+ e = document.querySelector(this.trigger) || document.querySelector(".impactpop"), this.trigger && !e && v("No element found with trigger selector", this.trigger);
1265
765
  } catch {
1266
- _log$6("Not a valid selector", this.trigger);
1267
- }
1268
- if (triggerElement) {
1269
- triggerElement.onclick = () => {
1270
- this.open();
1271
- };
766
+ v("Not a valid selector", this.trigger);
1272
767
  }
768
+ e && (e.onclick = () => {
769
+ this.open();
770
+ });
1273
771
  }
1274
- _createPopupDialog() {
1275
- var _a2, _b, _c;
1276
- const dialog = document.createElement("dialog");
1277
- const brandingConfig = (_b = (_a2 = this.context.widgetConfig) == null ? void 0 : _a2.values) == null ? void 0 : _b.brandingConfig;
1278
- const sizes = (_c = brandingConfig == null ? void 0 : brandingConfig.widgetSize) == null ? void 0 : _c.popupWidgets;
1279
- const minWidth = (sizes == null ? void 0 : sizes.minWidth) ? formatWidth(sizes.minWidth) : "auto";
1280
- const maxWidth = (sizes == null ? void 0 : sizes.maxWidth) ? formatWidth(sizes.maxWidth) : "500px";
1281
- dialog.id = this.id;
1282
- dialog.setAttribute(
772
+ _createPopupDialog(e) {
773
+ var c;
774
+ const n = document.createElement("dialog"), i = (c = e == null ? void 0 : e.widgetSize) == null ? void 0 : c.popupWidgets, s = i != null && i.minWidth ? O(i.minWidth) : "auto", r = i != null && i.maxWidth ? O(i.maxWidth) : "500px";
775
+ n.id = this.id, n.setAttribute(
1283
776
  "style",
1284
- `width: 100%; min-width: ${minWidth}; max-width: ${maxWidth}; border: none; padding: 0;`
777
+ `width: 100%; min-width: ${s}; max-width: ${r}; border: none; padding: 0;`
1285
778
  );
1286
- const onClick = (e) => {
1287
- e.stopPropagation();
1288
- if (e.target === dialog) dialog.close();
779
+ const a = (d) => {
780
+ d.stopPropagation(), d.target === n && n.close();
1289
781
  };
1290
- dialog.addEventListener("click", onClick);
1291
- return dialog;
782
+ return n.addEventListener("click", a), n;
1292
783
  }
1293
784
  async load() {
1294
- var _a2;
1295
- const frame = this._createFrame();
1296
- this._initialiseCTA();
1297
- const element = this.container ? this._findElement() : document.body;
1298
- const dialogParent = element.shadowRoot || element;
1299
- const dialog = this._createPopupDialog();
1300
- dialog.appendChild(frame);
1301
- if (((_a2 = dialogParent.lastChild) == null ? void 0 : _a2.nodeName) === "DIALOG") {
1302
- dialogParent.replaceChild(dialog, dialogParent.lastChild);
1303
- } else {
1304
- dialogParent.appendChild(dialog);
1305
- }
1306
- const { contentWindow } = frame;
1307
- if (!contentWindow) {
785
+ var m, p, g, f, b, w, T;
786
+ const e = (p = (m = this.context.widgetConfig) == null ? void 0 : m.values) == null ? void 0 : p.brandingConfig, n = (e == null ? void 0 : e.loadingHeight) || 500, i = (g = this.content) == null ? void 0 : g.includes("mint-components"), s = this._createFrame();
787
+ s.style.height = n + "px", this._initialiseCTA();
788
+ const r = this.container ? this._findElement() : document.body, a = (r == null ? void 0 : r.shadowRoot) || r, c = this._createPopupDialog(e);
789
+ c.appendChild(s), ((f = a.lastChild) == null ? void 0 : f.nodeName) === "DIALOG" ? a.replaceChild(c, a.lastChild) : a.appendChild(c);
790
+ const { contentWindow: d } = s;
791
+ if (!d)
1308
792
  throw new Error("Frame needs a content window");
793
+ const h = d.document;
794
+ if (h.open(), this.content === "error") {
795
+ h.write(await this._getContent()), h.close(), x(h, () => {
796
+ s.height = h.body.scrollHeight;
797
+ }), v("Popup error template loaded into iframe");
798
+ return;
1309
799
  }
1310
- const frameDoc = contentWindow.document;
1311
- frameDoc.open();
1312
- frameDoc.write(this.content);
1313
- frameDoc.write(
1314
- `<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>`
1315
- );
1316
- frameDoc.write(`
1317
- <style>
1318
- body {
1319
- height: 600px;
1320
- border: 2px solid #ccc;
1321
- background-color: red;
1322
- margin: 0;
1323
- padding: 0;
1324
- box-sizing: border-box;
1325
- }
1326
- </style>
1327
- `);
1328
- frameDoc.close();
1329
- _log$6("Popup template loaded into iframe");
1330
- await this._setupResizeHandler(frame);
1331
- }
1332
- async _setupResizeHandler(frame) {
1333
- const { contentWindow } = frame;
1334
- if (!contentWindow) {
800
+ const u = this.widgetApi.domain;
801
+ h.write(`
802
+ ${(b = e == null ? void 0 : e.main) != null && b.brandFont ? `
803
+ <link rel="preconnect" href="https://fast${u === "https://staging.referralsaasquatch.com" ? "-staging" : ""}.ssqt.io">
804
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
805
+ <link rel="preconnect" href="https://fonts.googleapis.com">
806
+ <link rel="preload" href="https://fonts.googleapis.com/css2?family=${encodeURIComponent(
807
+ (w = e == null ? void 0 : e.main) == null ? void 0 : w.brandFont
808
+ )}" as="style">` : ""}
809
+ <link rel="dns-prefetch" href="https://res.cloudinary.com">
810
+ <link rel="preconnect" href="https://res.cloudinary.com" crossorigin>
811
+ ${i ? `
812
+ <style data-styles>
813
+ html { visibility: hidden; }
814
+ </style>` : ""}
815
+ ${await this._getSkeletonPreloadHTML(i, (T = e == null ? void 0 : e.color) == null ? void 0 : T.backgroundColor)}
816
+ ${await this._getContent()}
817
+ `), h.close(), v("Popup template loaded into iframe"), await this._setupResizeHandler(s);
818
+ }
819
+ async _setupResizeHandler(e) {
820
+ const { contentWindow: n } = e;
821
+ if (!n)
1335
822
  throw new Error("Frame needs a content window");
1336
- }
1337
- const frameDoc = contentWindow.document;
1338
- domready(frameDoc, async () => {
1339
- frameDoc.body.style.overflowY = "hidden";
1340
- frame.height = `${frameDoc.body.offsetHeight}px`;
1341
- const ro = new contentWindow["ResizeObserver"]((entries) => {
1342
- for (const entry of entries) {
1343
- const { top, bottom } = entry.contentRect;
1344
- const computedHeight = bottom + top;
1345
- frame.height = computedHeight + "";
1346
- entry.target.style = ``;
823
+ const i = n.document;
824
+ x(i, async () => {
825
+ i.body.style.overflowY = "hidden";
826
+ let s = !0;
827
+ new n.ResizeObserver((a) => {
828
+ for (const c of a) {
829
+ const { top: d, bottom: h } = c.contentRect, u = h + d;
830
+ u <= 0 || (s ? (s = !1, e.style.height = "0", e.height = i.body.scrollHeight + "", e.style.height = "") : e.height = u + "", c.target.style = "");
1347
831
  }
1348
- });
1349
- ro.observe(await this._findInnerContainer(frame));
832
+ }).observe(await this._findInnerContainer(e));
1350
833
  });
1351
834
  }
1352
835
  open() {
1353
- const element = this.container ? this._findElement() : document.body;
1354
- const parent = element.shadowRoot || element;
1355
- const dialog = parent.querySelector(`#${this.id}`);
1356
- if (!dialog) throw new Error("Could not determine container div");
1357
- dialog.showModal();
1358
- const frame = this._findFrame();
1359
- if (!frame) throw new Error("Could not find iframe");
1360
- const { contentWindow } = frame;
1361
- if (!contentWindow) throw new Error("Squatch.js has an empty iframe");
1362
- const frameDoc = contentWindow.document;
1363
- domready(frameDoc, () => {
1364
- var _a2;
1365
- const _sqh = contentWindow.squatch || contentWindow.widgetIdent;
1366
- (_a2 = frame.contentDocument) == null ? void 0 : _a2.dispatchEvent(new CustomEvent("sq:refresh"));
1367
- if (this.context.user) {
1368
- this._loadEvent(_sqh);
1369
- _log$6("Popup opened");
1370
- } else {
1371
- this._attachLoadEventListener(frameDoc, _sqh);
1372
- }
836
+ const e = this.container ? this._findElement() : document.body, i = (e.shadowRoot || e).querySelector(`#${this.id}`);
837
+ if (!i) throw new Error("Could not determine container div");
838
+ i.showModal();
839
+ const s = this._findFrame();
840
+ if (!s) throw new Error("Could not find iframe");
841
+ const { contentWindow: r } = s;
842
+ if (!r) throw new Error("Squatch.js has an empty iframe");
843
+ const a = r.document;
844
+ x(a, () => {
845
+ var d;
846
+ const c = r.squatch || r.widgetIdent;
847
+ (d = s.contentDocument) == null || d.dispatchEvent(new CustomEvent("sq:refresh")), this.context.user ? (this._loadEvent(c), v("Popup opened")) : this._attachLoadEventListener(a, c);
1373
848
  });
1374
849
  }
1375
850
  close() {
1376
- const frame = this._findFrame();
1377
- if (frame == null ? void 0 : frame.contentDocument)
1378
- this._detachLoadEventListener(frame.contentDocument);
1379
- const element = this.container ? this._findElement() : document.body;
1380
- const parent = element.shadowRoot || element;
1381
- const dialog = parent.querySelector(`#${this.id}`);
1382
- if (!dialog) throw new Error("Could not determine container div");
1383
- dialog.close();
1384
- _log$6("Popup closed");
1385
- }
1386
- _clickedOutside({ target }) {
1387
- }
1388
- _error(rs, mode = "modal", style = "") {
1389
- const _style = "body { margin: 0; } .modal { box-shadow: none; border: 0; }";
1390
- return super._error(rs, mode, style || _style);
851
+ const e = this._findFrame();
852
+ e != null && e.contentDocument && this._detachLoadEventListener(e.contentDocument);
853
+ const n = this.container ? this._findElement() : document.body, s = (n.shadowRoot || n).querySelector(`#${this.id}`);
854
+ if (!s) throw new Error("Could not determine container div");
855
+ s.close(), v("Popup closed");
856
+ }
857
+ _getErrorStyle() {
858
+ return "body { margin: 0; } .modal { box-shadow: none; border: 0; }";
1391
859
  }
1392
860
  }
1393
- const _log$5 = browserExports.debug("squatch-js:widgets");
1394
- class Widgets {
861
+ const E = C("squatch-js:widgets");
862
+ class N {
1395
863
  /**
1396
864
  * Initialize a new {@link Widgets} instance.
1397
865
  *
@@ -1408,30 +876,27 @@ class Widgets {
1408
876
  * import {Widgets} from '@saasquatch/squatch-js';
1409
877
  * let widgets = new Widgets({tenantAlias:'test_12b5bo1b25125'});
1410
878
  */
1411
- constructor(configin) {
879
+ constructor(t) {
1412
880
  /**
1413
881
  * Instance of {@link WidgetApi}
1414
882
  */
1415
- __publicField(this, "api");
883
+ l(this, "api");
1416
884
  /**
1417
885
  * Tenant alias of SaaSquatch tenant
1418
886
  */
1419
- __publicField(this, "tenantAlias");
887
+ l(this, "tenantAlias");
1420
888
  /**
1421
889
  * SaaSquatch domain for API requests
1422
890
  * @default "https://app.referralsaasquatch.com"
1423
891
  */
1424
- __publicField(this, "domain");
892
+ l(this, "domain");
1425
893
  /**
1426
894
  * Hosted CDN for npm packages
1427
895
  * @default "https://fast.ssqt.io/npm"
1428
896
  */
1429
- __publicField(this, "npmCdn");
1430
- const config = validateConfig(configin);
1431
- this.tenantAlias = config.tenantAlias;
1432
- this.domain = config.domain;
1433
- this.npmCdn = config.npmCdn;
1434
- this.api = new WidgetApi(config);
897
+ l(this, "npmCdn");
898
+ const e = q(t);
899
+ this.tenantAlias = e.tenantAlias, this.domain = e.domain, this.npmCdn = e.npmCdn, this.api = new Z(e);
1435
900
  }
1436
901
  /**
1437
902
  * This function calls the {@link WidgetApi.upsertUser} method, and it renders
@@ -1449,32 +914,27 @@ class Widgets {
1449
914
  *
1450
915
  * @return {Promise<WidgetResult>} json object if true, with a Widget and user details
1451
916
  */
1452
- async upsertUser(config) {
1453
- const raw = config;
1454
- const clean = validateWidgetConfig(raw);
917
+ async upsertUser(t) {
918
+ const n = de(t);
1455
919
  try {
1456
- const response = await this.api.upsertUser(clean);
920
+ const i = await this.api.upsertUser(n);
1457
921
  return {
1458
- widget: this._renderWidget(response, clean, {
922
+ widget: this._renderWidget(i, n, {
1459
923
  type: "upsert",
1460
- user: clean.user,
1461
- engagementMedium: config.engagementMedium,
1462
- container: config.container,
1463
- trigger: config.trigger,
924
+ user: n.user,
925
+ engagementMedium: t.engagementMedium,
926
+ container: t.container,
927
+ trigger: t.trigger,
1464
928
  widgetConfig: {
1465
929
  values: {
1466
- brandingConfig: response == null ? void 0 : response.brandingConfig
930
+ brandingConfig: i == null ? void 0 : i.brandingConfig
1467
931
  }
1468
932
  }
1469
933
  }),
1470
- user: response.user
934
+ user: i.user
1471
935
  };
1472
- } catch (err) {
1473
- _log$5(err);
1474
- if (err.apiErrorCode) {
1475
- this._renderErrorWidget(err, config.engagementMedium);
1476
- }
1477
- throw new Error(err);
936
+ } catch (i) {
937
+ throw E(i), i.apiErrorCode && this._renderErrorWidget(i, t.engagementMedium), new Error(i);
1478
938
  }
1479
939
  }
1480
940
  /**
@@ -1492,30 +952,22 @@ class Widgets {
1492
952
  *
1493
953
  * @return {Promise<WidgetResult>} json object if true, with a Widget and user details
1494
954
  */
1495
- async render(config) {
1496
- const raw = config;
1497
- const clean = validatePasswordlessConfig(raw);
955
+ async render(t) {
956
+ const n = le(t);
1498
957
  try {
1499
- const response = await this.api.render(clean);
958
+ const i = await this.api.render(n);
1500
959
  return {
1501
- widget: this._renderWidget(response, clean, {
960
+ widget: this._renderWidget(i, n, {
1502
961
  type: "passwordless",
1503
- engagementMedium: clean.engagementMedium,
1504
- container: clean.container,
1505
- trigger: clean.trigger,
1506
- widgetConfig: {
1507
- values: {
1508
- brandingConfig: response == null ? void 0 : response.brandingConfig
1509
- }
1510
- }
962
+ engagementMedium: n.engagementMedium,
963
+ container: n.container,
964
+ trigger: n.trigger,
965
+ widgetConfig: i == null ? void 0 : i.widgetConfig
1511
966
  }),
1512
- user: response.user
967
+ user: i.user
1513
968
  };
1514
- } catch (err) {
1515
- if (err.apiErrorCode) {
1516
- this._renderErrorWidget(err, clean.engagementMedium);
1517
- }
1518
- throw new Error(err);
969
+ } catch (i) {
970
+ throw i.apiErrorCode && this._renderErrorWidget(i, n.engagementMedium), new Error(i);
1519
971
  }
1520
972
  }
1521
973
  /**
@@ -1525,33 +977,29 @@ class Widgets {
1525
977
  * @param selector Element class/id selector, or a callback function
1526
978
  * @returns
1527
979
  */
1528
- async autofill(selector) {
1529
- const input = selector;
1530
- if (typeof input === "function") {
980
+ async autofill(t) {
981
+ const e = t;
982
+ if (typeof e == "function") {
1531
983
  try {
1532
- const response = await this.api.squatchReferralCookie();
1533
- input(response);
1534
- } catch (e) {
1535
- _log$5("Autofill error", e);
1536
- throw new Error(e);
984
+ const s = await this.api.squatchReferralCookie();
985
+ e(s);
986
+ } catch (s) {
987
+ throw E("Autofill error", s), new Error(s);
1537
988
  }
1538
989
  return;
1539
990
  }
1540
- if (typeof input !== "string")
991
+ if (typeof e != "string")
1541
992
  throw new Error("Autofill accepts a string or function");
1542
- let elems = document.querySelectorAll(input);
1543
- let elem;
1544
- if (elems.length > 0) {
1545
- elem = elems[0];
1546
- } else {
1547
- _log$5("Element id/class or function missing");
1548
- throw new Error("Element id/class or function missing");
1549
- }
993
+ let n = document.querySelectorAll(e), i;
994
+ if (n.length > 0)
995
+ i = n[0];
996
+ else
997
+ throw E("Element id/class or function missing"), new Error("Element id/class or function missing");
1550
998
  try {
1551
- const response = await this.api.squatchReferralCookie();
1552
- elem.value = response.codes[0];
1553
- } catch (e) {
1554
- throw new Error(e);
999
+ const s = await this.api.squatchReferralCookie();
1000
+ i.value = s.codes[0];
1001
+ } catch (s) {
1002
+ throw new Error(s);
1555
1003
  }
1556
1004
  }
1557
1005
  /**
@@ -1562,74 +1010,42 @@ class Widgets {
1562
1010
  * @param {string} config.engagementMedium (POPUP, EMBED)
1563
1011
  * @returns {Widget} widget (PopupWidget or EmbedWidget)
1564
1012
  */
1565
- _renderWidget(response, config, context) {
1566
- var _a2;
1567
- _log$5("Rendering Widget...");
1568
- if (!response) throw new Error("Unable to get a response");
1569
- let widget2;
1570
- let displayOnLoad = !!config.displayOnLoad;
1571
- const opts = response.jsOptions || {};
1572
- const params = {
1573
- content: response.template,
1574
- type: config.widgetType || ((_a2 = opts.widget) == null ? void 0 : _a2.defaultWidgetType),
1013
+ _renderWidget(t, e, n) {
1014
+ var c;
1015
+ if (E("Rendering Widget..."), !t) throw new Error("Unable to get a response");
1016
+ let i, s = !!e.displayOnLoad;
1017
+ const r = t.jsOptions || {}, a = {
1018
+ content: t.template,
1019
+ type: e.widgetType || ((c = r.widget) == null ? void 0 : c.defaultWidgetType),
1575
1020
  api: this.api,
1576
1021
  domain: this.domain,
1577
1022
  npmCdn: this.npmCdn,
1578
- context
1023
+ context: n
1579
1024
  };
1580
- if (opts.widgetUrlMappings) {
1581
- opts.widgetUrlMappings.forEach((rule) => {
1582
- var _a3, _b;
1583
- if (Widgets._matchesUrl(rule.url)) {
1584
- if (rule.widgetType !== "CONVERSION_WIDGET" || ((_b = (_a3 = response.user) == null ? void 0 : _a3.referredBy) == null ? void 0 : _b.code)) {
1585
- displayOnLoad = rule.displayOnLoad;
1586
- _log$5(`Display ${rule.widgetType} on ${rule.url}`);
1587
- } else {
1588
- _log$5(
1589
- `Don't display ${rule.widgetType} when no referral on widget rule match ${rule.url}`
1590
- );
1591
- }
1592
- }
1593
- });
1594
- }
1595
- if (opts.fuelTankAutofillUrls) {
1596
- _log$5("We found a fuel tank autofill!");
1597
- opts.fuelTankAutofillUrls.forEach(({ url, formSelector }) => {
1598
- var _a3, _b, _c;
1599
- if (Widgets._matchesUrl(url)) {
1600
- _log$5("Fuel Tank URL matches");
1601
- if ((_b = (_a3 = response.user) == null ? void 0 : _a3.referredBy) == null ? void 0 : _b.code) {
1602
- const formAutofill = document.querySelector(formSelector);
1603
- if (formAutofill) {
1604
- formAutofill.value = ((_c = response.user.referredBy.referredReward) == null ? void 0 : _c.fuelTankCode) || "";
1605
- } else {
1606
- _log$5(
1607
- new Error(
1608
- `Element with id/class ${formSelector} was not found.`
1609
- )
1610
- );
1611
- }
1612
- }
1613
- }
1614
- });
1615
- }
1616
- if (config.engagementMedium === "EMBED") {
1617
- widget2 = this._renderEmbedWidget(params);
1618
- } else {
1619
- widget2 = this._renderPopupWidget(params);
1620
- if (displayOnLoad) widget2.open();
1621
- }
1622
- return widget2;
1025
+ return r.widgetUrlMappings && r.widgetUrlMappings.forEach((d) => {
1026
+ var h, u;
1027
+ N._matchesUrl(d.url) && (d.widgetType !== "CONVERSION_WIDGET" || (u = (h = t.user) == null ? void 0 : h.referredBy) != null && u.code ? (s = d.displayOnLoad, E(`Display ${d.widgetType} on ${d.url}`)) : E(
1028
+ `Don't display ${d.widgetType} when no referral on widget rule match ${d.url}`
1029
+ ));
1030
+ }), r.fuelTankAutofillUrls && (E("We found a fuel tank autofill!"), r.fuelTankAutofillUrls.forEach(({ url: d, formSelector: h }) => {
1031
+ var u, m, p;
1032
+ if (N._matchesUrl(d) && (E("Fuel Tank URL matches"), (m = (u = t.user) == null ? void 0 : u.referredBy) != null && m.code)) {
1033
+ const g = document.querySelector(h);
1034
+ g ? g.value = ((p = t.user.referredBy.referredReward) == null ? void 0 : p.fuelTankCode) || "" : E(
1035
+ new Error(
1036
+ `Element with id/class ${h} was not found.`
1037
+ )
1038
+ );
1039
+ }
1040
+ })), e.engagementMedium === "EMBED" ? i = this._renderEmbedWidget(a) : (i = this._renderPopupWidget(a), s && i.open()), i;
1623
1041
  }
1624
- _renderPopupWidget(params) {
1625
- const widget2 = new PopupWidget(params, params.context.trigger);
1626
- widget2.load();
1627
- return widget2;
1042
+ _renderPopupWidget(t) {
1043
+ const e = new j(t, t.context.trigger);
1044
+ return e.load(), e;
1628
1045
  }
1629
- _renderEmbedWidget(params) {
1630
- const widget2 = new EmbedWidget(params, params.context.container);
1631
- widget2.load();
1632
- return widget2;
1046
+ _renderEmbedWidget(t) {
1047
+ const e = new D(t, t.context.container);
1048
+ return e.load(), e;
1633
1049
  }
1634
1050
  /**
1635
1051
  * @hidden
@@ -1637,37 +1053,34 @@ class Widgets {
1637
1053
  * @param {string} em The engagementMedium
1638
1054
  * @returns {void}
1639
1055
  */
1640
- _renderErrorWidget(props, em = "POPUP") {
1641
- const { apiErrorCode, rsCode, message } = props;
1642
- _log$5(new Error(`${apiErrorCode} (${rsCode}) ${message}`));
1643
- const params = {
1056
+ _renderErrorWidget(t, e = "POPUP") {
1057
+ const { apiErrorCode: n, rsCode: i, statusCode: s, message: r } = t;
1058
+ E(new Error(`${n} (${i}) ${r}`));
1059
+ const a = {
1644
1060
  content: "error",
1645
- rsCode,
1061
+ rsCode: i,
1062
+ apiErrorCode: n,
1063
+ statusCode: s,
1064
+ errorMessage: r,
1646
1065
  api: this.api,
1647
1066
  domain: this.domain,
1648
1067
  npmCdn: this.npmCdn,
1649
1068
  type: "ERROR_WIDGET",
1650
1069
  context: { type: "error" }
1651
1070
  };
1652
- let widget2;
1653
- if (em === "EMBED") {
1654
- widget2 = new EmbedWidget(params);
1655
- widget2.load();
1656
- } else if (em === "POPUP") {
1657
- widget2 = new PopupWidget(params);
1658
- widget2.load();
1659
- }
1071
+ let c;
1072
+ e === "EMBED" ? (c = new D(a), c.load()) : e === "POPUP" && (c = new j(a), c.load());
1660
1073
  }
1661
1074
  /**
1662
1075
  * @hidden
1663
1076
  * @param {string} rule A regular expression
1664
1077
  * @returns {boolean} true if rule matches Url, false otherwise
1665
1078
  */
1666
- static _matchesUrl(rule) {
1667
- return window.location.href.match(new RegExp(rule)) ? true : false;
1079
+ static _matchesUrl(t) {
1080
+ return !!window.location.href.match(new RegExp(t));
1668
1081
  }
1669
1082
  }
1670
- class EventsApi {
1083
+ class Oe {
1671
1084
  /**
1672
1085
  * Initialize a new {@link EventsApi} instance.
1673
1086
  *
@@ -1684,13 +1097,11 @@ class EventsApi {
1684
1097
  * import {EventsApi} from '@saasquatch/squatch-js';
1685
1098
  * let squatchApi = new EventsApi({tenantAlias:'test_12b5bo1b25125'});
1686
1099
  */
1687
- constructor(config) {
1688
- __publicField(this, "tenantAlias");
1689
- __publicField(this, "domain");
1690
- const raw = config;
1691
- const clean = validateConfig(raw);
1692
- this.tenantAlias = clean.tenantAlias;
1693
- this.domain = clean.domain;
1100
+ constructor(t) {
1101
+ l(this, "tenantAlias");
1102
+ l(this, "domain");
1103
+ const n = q(t);
1104
+ this.tenantAlias = n.tenantAlias, this.domain = n.domain;
1694
1105
  }
1695
1106
  /**
1696
1107
  * Track an event for a user
@@ -1700,531 +1111,172 @@ class EventsApi {
1700
1111
  *
1701
1112
  * @return An ID to confirm the event has been accepted for asynchronous processing
1702
1113
  */
1703
- track(params, options) {
1704
- const raw = params;
1705
- const rawOpts = options;
1706
- const body = _validateEvent(raw);
1707
- const { jwt } = _validateTrackOptions(rawOpts);
1708
- const ta = encodeURIComponent(this.tenantAlias);
1709
- const userId = encodeURIComponent(body.userId);
1710
- const accountId = encodeURIComponent(body.accountId);
1711
- const path = `/api/v1/${ta}/open/account/${accountId}/user/${userId}/events`;
1712
- const url = this.domain + path;
1713
- return doPost(url, JSON.stringify(body), jwt);
1114
+ track(t, e) {
1115
+ const n = t, i = e, s = De(n), { jwt: r } = je(i), a = encodeURIComponent(this.tenantAlias), c = encodeURIComponent(s.userId), d = encodeURIComponent(s.accountId), h = `/api/v1/${a}/open/account/${d}/user/${c}/events`, u = this.domain + h;
1116
+ return Q(u, JSON.stringify(s), r);
1714
1117
  }
1715
1118
  }
1716
- function _validateEvent(raw) {
1717
- if (!isObject$1(raw)) throw new Error("tracking parameter must be an object");
1718
- if (!(raw == null ? void 0 : raw["accountId"])) throw new Error("accountId field is required");
1719
- if (!(raw == null ? void 0 : raw["events"])) throw new Error("events field is required");
1720
- if (!(raw == null ? void 0 : raw["userId"])) throw new Error("userId field is required");
1721
- const clean = raw;
1722
- if (!Array.isArray(clean.events))
1119
+ function De(o) {
1120
+ if (!S(o)) throw new Error("tracking parameter must be an object");
1121
+ if (!(o != null && o.accountId)) throw new Error("accountId field is required");
1122
+ if (!(o != null && o.events)) throw new Error("events field is required");
1123
+ if (!(o != null && o.userId)) throw new Error("userId field is required");
1124
+ const t = o;
1125
+ if (!Array.isArray(t.events))
1723
1126
  throw new Error("'events' should be an array");
1724
- return clean;
1127
+ return t;
1725
1128
  }
1726
- function _validateTrackOptions(raw) {
1727
- if (!isObject$1(raw)) throw new Error("'options' should be an object");
1728
- return raw;
1129
+ function je(o) {
1130
+ if (!S(o)) throw new Error("'options' should be an object");
1131
+ return o;
1729
1132
  }
1730
- function asyncLoad() {
1731
- var _a2;
1732
- const namespace = window[IMPACT_NAMESPACE] ? IMPACT_NAMESPACE : DEFAULT_NAMESPACE;
1733
- const cached = ((_a2 = window["_" + namespace]) == null ? void 0 : _a2.ready) || [];
1734
- const declarativeCache = window.impactOnReady || window.squatchOnReady;
1735
- const readyFns = [...cached, declarativeCache].filter((a) => !!a);
1133
+ function Ne() {
1134
+ var i;
1135
+ const o = window[z] ? z : M, t = ((i = window["_" + o]) == null ? void 0 : i.ready) || [], e = window.impactOnReady || window.squatchOnReady, n = [...t, e].filter((s) => !!s);
1736
1136
  setTimeout(() => {
1737
- if (!window[DEFAULT_NAMESPACE]) return;
1738
- window[IMPACT_NAMESPACE] = window[DEFAULT_NAMESPACE];
1739
- readyFns.forEach((cb) => cb());
1740
- window[DEFAULT_NAMESPACE]._auto();
1741
- window["_" + namespace] = void 0;
1742
- delete window["_" + namespace];
1137
+ window[M] && (window[z] = window[M], n.forEach((s) => s()), window[M]._auto(), window["_" + o] = void 0, delete window["_" + o]);
1743
1138
  }, 0);
1744
1139
  }
1745
- const _log$4 = browserExports.debug("squatch-js");
1746
- const isObject = (item) => typeof item === "object" && !Array.isArray(item);
1747
- const deepMerge = (target, source) => {
1748
- const isDeep = (prop) => isObject(source[prop]) && target.hasOwnProperty(prop) && isObject(target[prop]);
1749
- const replaced = Object.getOwnPropertyNames(source).map((prop) => ({
1750
- [prop]: isDeep(prop) ? deepMerge(target[prop], source[prop]) : source[prop]
1751
- })).reduce((a, b) => ({ ...a, ...b }), {});
1752
- return {
1753
- ...target,
1754
- ...replaced
1755
- };
1756
- };
1757
- function b64decode(input) {
1758
- const binary = atob(input.replace(/_/g, "/").replace(/-/g, "+"));
1759
- const bytes = new Uint8Array(binary.length);
1760
- for (let i = 0; i < binary.length; i++) {
1761
- bytes[i] = binary.charCodeAt(i);
1762
- }
1763
- return new TextDecoder("utf8").decode(bytes);
1764
- }
1765
- function b64encode(input) {
1766
- const encodedInput = new TextEncoder().encode(input);
1767
- const binary = Array.from(
1768
- encodedInput,
1769
- (byte) => String.fromCodePoint(byte)
1770
- ).join("");
1771
- return btoa(binary).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
1772
- }
1773
- function getTopDomain() {
1774
- var i, h, weird_cookie = "weird_get_top_level_domain=cookie", hostname = document.location.hostname.split(".");
1775
- for (i = hostname.length - 1; i >= 0; i--) {
1776
- h = hostname.slice(i).join(".");
1777
- document.cookie = weird_cookie + ";domain=." + h + ";";
1778
- if (document.cookie.indexOf(weird_cookie) > -1) {
1779
- document.cookie = weird_cookie.split("=")[0] + "=;domain=." + h + ";expires=Thu, 01 Jan 1970 00:00:01 GMT;";
1780
- return h;
1781
- }
1782
- }
1783
- }
1784
- function _pushCookie() {
1785
- const queryString = window.location.search;
1786
- const urlParams = new URLSearchParams(queryString);
1787
- const refParam = urlParams.get("_saasquatch") || "";
1788
- if (refParam) {
1789
- let paramsJSON = "", existingCookie = "", reEncodedCookie = "";
1790
- try {
1791
- paramsJSON = JSON.parse(b64decode(refParam));
1792
- } catch (error) {
1793
- _log$4("Unable to decode params", error);
1794
- return;
1795
- }
1796
- try {
1797
- existingCookie = JSON.parse(b64decode(api$1.get("_saasquatch")));
1798
- _log$4("existing cookie", existingCookie);
1799
- } catch (error) {
1800
- _log$4("Unable to retrieve cookie", error);
1801
- }
1802
- try {
1803
- const domain = getTopDomain();
1804
- _log$4("domain retrieved:", domain);
1805
- if (existingCookie) {
1806
- const newCookie = deepMerge(existingCookie, paramsJSON);
1807
- reEncodedCookie = b64encode(JSON.stringify(newCookie));
1808
- _log$4("cookie to store:", newCookie);
1809
- } else {
1810
- reEncodedCookie = b64encode(JSON.stringify(paramsJSON));
1811
- _log$4("cookie to store:", paramsJSON);
1812
- }
1813
- api$1.set("_saasquatch", reEncodedCookie, {
1814
- expires: 365,
1815
- secure: false,
1816
- sameSite: "Lax",
1817
- domain,
1818
- path: "/"
1819
- });
1820
- } catch (error) {
1821
- _log$4("Unable to set cookie", error);
1822
- }
1823
- }
1824
- }
1825
- const _log$3 = browserExports.debug("squatch-js");
1826
- function _getAutoConfig() {
1827
- var _a2;
1828
- const queryString = window.location.search;
1829
- const urlParams = new URLSearchParams(queryString);
1830
- const refParam = urlParams.get("_saasquatchExtra") || "";
1831
- if (!refParam) {
1832
- _log$3("No _saasquatchExtra param");
1140
+ const R = C("squatch-js");
1141
+ function Fe() {
1142
+ var u;
1143
+ const o = window.location.search, e = new URLSearchParams(o).get("_saasquatchExtra") || "";
1144
+ if (!e) {
1145
+ R("No _saasquatchExtra param");
1833
1146
  return;
1834
1147
  }
1835
- const config = validateConfig({
1148
+ const n = q({
1836
1149
  tenantAlias: "UNKNOWN"
1837
1150
  });
1838
- if (!config.domain) {
1839
- _log$3("domain must be provided in config to use _saasquatchExtra");
1151
+ if (!n.domain) {
1152
+ R("domain must be provided in config to use _saasquatchExtra");
1840
1153
  return;
1841
1154
  }
1842
- let raw;
1155
+ let i;
1843
1156
  try {
1844
- raw = JSON.parse(b64decode(refParam));
1845
- } catch (e) {
1846
- _log$3("Unable to decode _saasquatchExtra config");
1157
+ i = JSON.parse(L(e));
1158
+ } catch {
1159
+ R("Unable to decode _saasquatchExtra config");
1847
1160
  return;
1848
1161
  }
1849
- function normalizeDomain(domain) {
1850
- return domain.replace(/^https?:\/\//, "");
1162
+ function s(m) {
1163
+ return m.replace(/^https?:\/\//, "");
1851
1164
  }
1852
- const normalizedDomain = normalizeDomain(config.domain);
1853
- const tenantAlias = Object.keys((raw == null ? void 0 : raw[normalizedDomain]) || {})[0];
1854
- const widgetConfig = (_a2 = raw == null ? void 0 : raw[normalizedDomain]) == null ? void 0 : _a2[tenantAlias];
1855
- if (!widgetConfig) {
1856
- _log$3("_saasquatchExtra did not have an expected structure");
1857
- return void 0;
1165
+ const r = s(n.domain), a = Object.keys((i == null ? void 0 : i[r]) || {})[0], c = (u = i == null ? void 0 : i[r]) == null ? void 0 : u[a];
1166
+ if (!c) {
1167
+ R("_saasquatchExtra did not have an expected structure");
1168
+ return;
1858
1169
  }
1859
- const { autoPopupWidgetType, ...rest } = widgetConfig;
1170
+ const { autoPopupWidgetType: d, ...h } = c;
1860
1171
  return {
1861
1172
  widgetConfig: {
1862
- widgetType: autoPopupWidgetType,
1863
- displayOnLoad: true,
1864
- ...rest
1173
+ widgetType: d,
1174
+ displayOnLoad: !0,
1175
+ ...h
1865
1176
  },
1866
1177
  squatchConfig: {
1867
- ...config,
1868
- tenantAlias
1178
+ ...n,
1179
+ tenantAlias: a
1869
1180
  }
1870
1181
  };
1871
1182
  }
1872
- const getSkeleton = ({
1873
- type = "verified-access",
1874
- height = "500px",
1875
- skeletonBackgroundColor = "#e0e0e0",
1876
- skeletonShimmerColor = "#f5f5f5"
1877
- }) => {
1878
- const referrerHTML = `
1879
- <div class="hero-section">
1880
- <div class="hero-content">
1881
- <div class="skeleton sk-title-lg"></div>
1882
- <div class="skeleton sk-text"></div>
1883
- <div class="skeleton sk-text sk-text-short"></div>
1884
- </div>
1885
- <div class="skeleton hero-image"></div>
1886
- </div>
1887
-
1888
- <div class="share-section">
1889
- <div class="skeleton sk-label"></div>
1890
- <div class="skeleton sk-input"></div>
1891
- <div class="social-buttons">
1892
- <div class="skeleton sk-btn-social"></div>
1893
- <div class="skeleton sk-btn-social"></div>
1894
- <div class="skeleton sk-btn-social"></div>
1895
- <div class="skeleton sk-btn-social"></div>
1896
- </div>
1897
- </div>
1898
-
1899
- <div class="skeleton sk-title-md" style="margin-top: 0; width: 30%; margin-left: auto; margin-right: auto"></div>
1900
- <div class="skeleton sk-text" style="width: 60%; margin-left: auto; margin-right: auto"></div>
1901
-
1902
- <div class="stats-section">
1903
- <div class="stat-card">
1904
- <div class="skeleton sk-stat-num"></div>
1905
- <div class="skeleton sk-stat-label"></div>
1906
- </div>
1907
- <div class="stat-card stat-divider">
1908
- <div class="skeleton sk-stat-num"></div>
1909
- <div class="skeleton sk-stat-label"></div>
1910
- </div>
1911
- </div>
1912
-
1913
- <div class="skeleton sk-title-md"></div>
1914
-
1915
- <div class="table-header">
1916
- <div class="skeleton sk-th col-user"></div>
1917
- <div class="skeleton sk-th col-status"></div>
1918
- <div class="skeleton sk-th col-reward"></div>
1919
- <div class="skeleton sk-th col-date"></div>
1920
- </div>
1921
-
1922
- <div class="table-row">
1923
- <div class="col-user"><div class="skeleton sk-text" style="width: 70%; margin: 0"></div></div>
1924
- <div class="col-status"><div class="skeleton sk-badge" style="margin: 0"></div></div>
1925
- <div class="col-reward"><div class="skeleton sk-reward-block" style="margin: 0"></div></div>
1926
- <div class="col-date"><div class="skeleton sk-text" style="width: 80%; margin: 0"></div></div>
1927
- </div>
1928
-
1929
- <div class="table-row">
1930
- <div class="col-user"><div class="skeleton sk-text" style="width: 60%; margin: 0"></div></div>
1931
- <div class="col-status"><div class="skeleton sk-badge" style="margin: 0"></div></div>
1932
- <div class="col-reward"><div class="skeleton sk-reward-block" style="margin: 0"></div></div>
1933
- <div class="col-date"><div class="skeleton sk-text" style="width: 80%; margin: 0"></div></div>
1934
- </div>
1935
-
1936
- <div class="table-row">
1937
- <div class="col-user"><div class="skeleton sk-text" style="width: 75%; margin: 0"></div></div>
1938
- <div class="col-status"><div class="skeleton sk-badge" style="margin: 0"></div></div>
1939
- <div class="col-reward"><div class="skeleton sk-reward-block" style="margin: 0"></div></div>
1940
- <div class="col-date"><div class="skeleton sk-text" style="width: 80%; margin: 0"></div></div>
1941
- </div>
1942
-
1943
- <div class="pagination">
1944
- <div class="skeleton sk-btn-page"></div>
1945
- <div class="skeleton sk-btn-page"></div>
1946
- </div>
1947
- `;
1948
- const instantAccessHTML = `
1949
- <div class="hero-section instant-access-layout">
1950
- <div class="skeleton hero-image ia-image"></div>
1951
-
1952
- <div class="hero-content ia-content">
1953
- <div class="skeleton sk-title-lg ia-center"></div>
1954
- <div class="skeleton sk-text ia-center"></div>
1955
-
1956
- <div class="skeleton sk-btn-action"></div>
1957
-
1958
- <div class="skeleton sk-label"></div>
1959
- <div class="input-group">
1960
- <div class="skeleton sk-input"></div>
1961
- <div class="skeleton sk-btn-copy"></div>
1962
- </div>
1963
-
1964
- <div class="skeleton sk-text-short ia-center" style="margin-top: 20px; width: 30%"></div>
1965
- <div class="skeleton sk-text-short ia-center" style="width: 20%"></div>
1966
- </div>
1967
- </div>
1968
- `;
1969
- return `
1970
- <style>
1971
- * {
1972
- box-sizing: border-box;
1973
- padding: 0;
1974
- margin: 0;
1975
- }
1976
-
1977
- .widget-container {
1978
- background: white;
1979
- width: 100%;
1980
- padding: 40px;
1981
- box-sizing: border-box;
1982
- overflow: hidden;
1983
- }
1984
-
1985
- @keyframes shimmer {
1986
- 0% { background-position: -100% 0; }
1987
- 100% { background-position: 100% 0; }
1988
- }
1989
-
1990
- .skeleton {
1991
- background: ${skeletonBackgroundColor};
1992
- background: linear-gradient(
1993
- 90deg,
1994
- ${skeletonBackgroundColor} 25%,
1995
- ${skeletonShimmerColor} 50%,
1996
- ${skeletonBackgroundColor} 75%
1997
- );
1998
- background-size: 200% 100%;
1999
- animation: shimmer 1.5s infinite linear;
2000
- border-radius: 6px;
2001
- margin-bottom: 12px;
2002
- }
2003
-
2004
- /* Typography Skeletons */
2005
- .sk-title-lg { height: 36px; width: 80%; margin-bottom: 16px; }
2006
- .sk-title-md { height: 28px; width: 30%; margin-bottom: 20px; margin-top: 40px; }
2007
- .sk-text { height: 16px; width: 90%; margin-bottom: 8px; }
2008
- .sk-text-short { width: 40%; }
2009
- .sk-label { height: 14px; width: 25%; margin-bottom: 10px; }
2010
-
2011
- /* Layouts */
2012
- .hero-section {
2013
- display: flex;
2014
- gap: 40px;
2015
- margin-bottom: 40px;
2016
- padding-bottom: 40px;
2017
- flex-direction: row;
2018
- height: 100%;
2019
- /* Removed border-bottom */
2020
- }
2021
-
2022
- .hero-content {
2023
- flex: 1;
2024
- display: flex;
2025
- flex-direction: column;
2026
- justify-content: center;
2027
- }
2028
-
2029
- .hero-image {
2030
- flex: 1;
2031
- height: 300px;
2032
- border-radius: 12px;
2033
- }
2034
-
2035
- /* -- Specific Instant Access Overrides -- */
2036
- .instant-access-layout {
2037
- margin-bottom: 0;
2038
- padding-bottom: 0;
2039
- align-items: center;
2040
- }
2041
- .ia-image {
2042
- height: 400px;
2043
- }
2044
- .ia-center {
2045
- margin-left: auto;
2046
- margin-right: auto;
2047
- }
2048
- .ia-content {
2049
- align-items: center;
2050
- text-align: center;
2051
- }
2052
- .sk-btn-action {
2053
- height: 45px;
2054
- width: 140px;
2055
- border-radius: 6px;
2056
- margin: 24px auto;
2057
- }
2058
- .input-group {
2059
- display: flex;
2060
- gap: 10px;
2061
- width: 100%;
2062
- max-width: 400px;
2063
- }
2064
- .sk-btn-copy {
2065
- height: 50px;
2066
- width: 120px;
2067
- border-radius: 8px;
2068
- }
2069
- /* ------------------------------------- */
2070
-
2071
- .share-section { margin-bottom: 40px; }
2072
- .sk-input { height: 50px; width: 100%; border-radius: 8px; margin-bottom: 16px; }
2073
-
2074
- .social-buttons { display: flex; gap: 12px; }
2075
- .sk-btn-social { flex: 1; height: 50px; border-radius: 8px; }
2076
-
2077
- .stats-section {
2078
- display: flex;
2079
- gap: 24px;
2080
- margin-bottom: 40px;
2081
- padding: 30px 0;
2082
- /* Removed border-top and border-bottom */
2083
- }
2084
- .stat-card { flex: 1; display: flex; flex-direction: column; align-items: center; }
2085
- .stat-divider { padding-left: 24px; }
2086
- .sk-stat-num { height: 48px; width: 120px; margin-bottom: 8px; }
2087
- .sk-stat-label { height: 18px; width: 80px; }
2088
-
2089
- /* Table Styles */
2090
- .table-header { display: flex; gap: 16px; margin-bottom: 16px; }
2091
- .sk-th { height: 16px; }
2092
- .table-row {
2093
- display: flex;
2094
- align-items: center;
2095
- gap: 16px;
2096
- padding: 16px 0;
2097
- /* Removed border-bottom */
2098
- }
2099
-
2100
- .col-user { flex: 2; }
2101
- .col-status { flex: 1; }
2102
- .col-reward { flex: 2; }
2103
- .col-date { flex: 1; }
2104
-
2105
- .sk-badge { height: 28px; width: 90px; border-radius: 14px; }
2106
- .sk-reward-block { height: 36px; width: 100%; border-radius: 6px; }
2107
-
2108
- .pagination { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
2109
- .sk-btn-page { height: 36px; width: 64px; border-radius: 6px; margin-bottom: 0; }
2110
-
2111
- @media (max-width: 768px) {
2112
- body { padding: 20px; }
2113
- .widget-container { padding: 24px; }
2114
-
2115
- .hero-section { flex-direction: column-reverse; gap: 24px; }
2116
- .instant-access-layout { flex-direction: column; }
2117
-
2118
- .hero-image { height: 220px; width: 100%; }
2119
- .sk-title-lg { width: 100%; }
2120
-
2121
- .col-date { display: none; }
2122
- }
2123
- </style>
2124
-
2125
- <div class="widget-container">
2126
- ${type === "verified-access" ? referrerHTML : instantAccessHTML}
2127
- </div>
2128
- `;
2129
- };
2130
- const _log$2 = browserExports.debug("squatch-js:decodeUserJwt");
2131
- function decodeUserJwt(tokenStr) {
2132
- var _a2;
1183
+ const He = C("squatch-js:decodeUserJwt");
1184
+ function Je(o) {
1185
+ var t;
2133
1186
  try {
2134
- const base64Url = tokenStr.split(".")[1];
2135
- if (base64Url === void 0) return null;
2136
- const jsonStr = b64decode(base64Url);
2137
- return (_a2 = JSON.parse(jsonStr)) == null ? void 0 : _a2.user;
1187
+ const e = o.split(".")[1];
1188
+ if (e === void 0) return null;
1189
+ const n = L(e);
1190
+ return (t = JSON.parse(n)) == null ? void 0 : t.user;
2138
1191
  } catch (e) {
2139
- _log$2(e);
2140
- return null;
1192
+ return He(e), null;
2141
1193
  }
2142
1194
  }
2143
- const _log$1 = debug("squatch-js:DeclarativeWidget");
2144
- class DeclarativeWidget extends HTMLElement {
1195
+ const P = C("squatch-js:DeclarativeWidget");
1196
+ class ge extends HTMLElement {
2145
1197
  constructor() {
2146
1198
  super();
2147
1199
  /**
2148
1200
  * Configuration overrides
2149
1201
  * @default window.squatchConfig
2150
1202
  */
2151
- __publicField(this, "config");
1203
+ l(this, "config");
2152
1204
  /**
2153
1205
  * Signed JWT containing user information
2154
1206
  * @default window.squatchToken
2155
1207
  */
2156
- __publicField(this, "token");
1208
+ l(this, "token");
2157
1209
  /**
2158
1210
  * Tenant alias of SaaSquatch tenant
2159
1211
  * @default window.squatchTenant
2160
1212
  */
2161
- __publicField(this, "tenant");
1213
+ l(this, "tenant");
2162
1214
  /**
2163
1215
  * widgetType of widget to load
2164
1216
  */
2165
- __publicField(this, "widgetType");
1217
+ l(this, "widgetType");
2166
1218
  /**
2167
1219
  * Locale to render the widget in
2168
1220
  */
2169
- __publicField(this, "locale");
1221
+ l(this, "locale");
2170
1222
  /**
2171
1223
  * Instance of {@link WidgetApi}
2172
1224
  */
2173
- __publicField(this, "widgetApi");
1225
+ l(this, "widgetApi");
2174
1226
  /**
2175
1227
  * Instance of {@link AnalyticsApi}
2176
1228
  */
2177
- __publicField(this, "analyticsApi");
1229
+ l(this, "analyticsApi");
2178
1230
  /**
2179
1231
  * Instance of {@link EmbedWidget} or {@link PopupWidget}
2180
1232
  */
2181
- __publicField(this, "widgetInstance");
1233
+ l(this, "widgetInstance");
2182
1234
  /**
2183
1235
  * Determines whether to render the widget as an embedding widget or popup widget
2184
1236
  */
2185
- __publicField(this, "type");
1237
+ l(this, "type");
2186
1238
  /**
2187
1239
  * Container element to contain the widget iframe
2188
1240
  * @default this
2189
1241
  */
2190
- __publicField(this, "container");
2191
- __publicField(this, "element");
1242
+ l(this, "container");
1243
+ l(this, "element");
2192
1244
  /**
2193
1245
  * Flag for if the component has been loaded or not
2194
1246
  * @hidden
2195
1247
  */
2196
- __publicField(this, "loaded");
2197
- __publicField(this, "_setWidget", (res, config) => {
2198
- var _a2;
2199
- const params = {
1248
+ l(this, "loaded");
1249
+ l(this, "_setWidget", (e, n) => {
1250
+ var s;
1251
+ const i = {
2200
1252
  api: this.widgetApi,
2201
- content: res.template,
1253
+ content: e.template,
2202
1254
  context: {
2203
- type: config.type,
2204
- user: config.user,
1255
+ type: n.type,
1256
+ user: n.user,
2205
1257
  container: this.container || void 0,
2206
1258
  engagementMedium: this.type,
2207
- widgetConfig: res.widgetConfig
1259
+ widgetConfig: e.widgetConfig
2208
1260
  },
2209
1261
  type: this.widgetType,
2210
- domain: ((_a2 = this.config) == null ? void 0 : _a2.domain) || DEFAULT_DOMAIN,
2211
- npmCdn: DEFAULT_NPM_CDN,
1262
+ domain: ((s = this.config) == null ? void 0 : s.domain) || k,
1263
+ npmCdn: X,
2212
1264
  container: this
2213
1265
  };
2214
- if (this.type === "EMBED") {
2215
- return new EmbedWidget(params);
2216
- } else {
2217
- const useFirstChildTrigger = this.firstChild ? null : void 0;
2218
- return new PopupWidget(params, useFirstChildTrigger);
1266
+ if (this.type === "EMBED")
1267
+ return new D(i);
1268
+ {
1269
+ const r = this.firstChild ? null : void 0;
1270
+ return new j(i, r);
2219
1271
  }
2220
1272
  });
2221
1273
  /**
2222
1274
  * Builds a Widget instance for the default error widget
2223
1275
  * @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type`
2224
1276
  */
2225
- __publicField(this, "setErrorWidget", (e) => {
2226
- var _a2;
2227
- const params = {
1277
+ l(this, "setErrorWidget", (e) => {
1278
+ var c;
1279
+ const n = e instanceof Error ? e.message : e == null ? void 0 : e.message, i = e == null ? void 0 : e.apiErrorCode, s = e == null ? void 0 : e.rsCode, r = e == null ? void 0 : e.statusCode, a = {
2228
1280
  api: this.widgetApi,
2229
1281
  content: "error",
2230
1282
  context: {
@@ -2232,76 +1284,72 @@ class DeclarativeWidget extends HTMLElement {
2232
1284
  container: this.container || void 0
2233
1285
  },
2234
1286
  type: "ERROR_WIDGET",
2235
- domain: ((_a2 = this.config) == null ? void 0 : _a2.domain) || DEFAULT_DOMAIN,
2236
- npmCdn: DEFAULT_NPM_CDN,
2237
- container: this
1287
+ domain: ((c = this.config) == null ? void 0 : c.domain) || k,
1288
+ npmCdn: X,
1289
+ container: this,
1290
+ apiErrorCode: i,
1291
+ rsCode: s,
1292
+ statusCode: r,
1293
+ errorMessage: n
2238
1294
  };
2239
- if (this.type === "EMBED") {
2240
- return new EmbedWidget(params);
2241
- } else {
2242
- const useFirstChildTrigger = this.firstChild ? null : void 0;
2243
- return new PopupWidget(params, useFirstChildTrigger);
1295
+ if (this.type === "EMBED")
1296
+ return new D(a);
1297
+ {
1298
+ const d = this.firstChild ? null : void 0;
1299
+ return new j(a, d);
2244
1300
  }
2245
1301
  });
2246
- __publicField(this, "reload", this.renderWidget);
2247
- __publicField(this, "show", this.open);
2248
- __publicField(this, "hide", this.close);
1302
+ l(this, "reload", this.renderWidget);
1303
+ l(this, "show", this.open);
1304
+ l(this, "hide", this.close);
2249
1305
  this.attachShadow({
2250
1306
  mode: "open"
2251
- }).innerHTML = `<style>:host { display: block; }</style><slot></slot>`;
2252
- this.config = getConfig();
2253
- this.token = getToken();
2254
- this.tenant = window.squatchTenant;
2255
- this.container = this;
2256
- }
2257
- _setupApis(config) {
2258
- var _a2, _b;
1307
+ }).innerHTML = "<style>:host { display: block; }</style><slot></slot>", this.config = Y(), this.token = W(), this.tenant = window.squatchTenant, this.container = this;
1308
+ }
1309
+ _setupApis(e) {
1310
+ var n, i;
2259
1311
  if (!this.tenant) throw new Error("tenantAlias not provided");
2260
- this.widgetApi = new WidgetApi({
2261
- tenantAlias: (config == null ? void 0 : config.tenantAlias) || this.tenant,
2262
- domain: (config == null ? void 0 : config.domain) || ((_a2 = this.config) == null ? void 0 : _a2.domain) || DEFAULT_DOMAIN
2263
- });
2264
- this.analyticsApi = new AnalyticsApi({
2265
- domain: (config == null ? void 0 : config.domain) || ((_b = this.config) == null ? void 0 : _b.domain) || DEFAULT_DOMAIN
1312
+ this.widgetApi = new Z({
1313
+ tenantAlias: (e == null ? void 0 : e.tenantAlias) || this.tenant,
1314
+ domain: (e == null ? void 0 : e.domain) || ((n = this.config) == null ? void 0 : n.domain) || k
1315
+ }), this.analyticsApi = new ue({
1316
+ domain: (e == null ? void 0 : e.domain) || ((i = this.config) == null ? void 0 : i.domain) || k
2266
1317
  });
2267
1318
  }
2268
- getWidgetType(widgetType) {
2269
- if (widgetType && (widgetType.includes("websiteReferralWidget") || widgetType.includes("friendWidget"))) {
2270
- return "instant-access";
2271
- }
2272
- return "verified-access";
1319
+ getWidgetType(e) {
1320
+ return e && e.includes("friendWidget") ? "instant-access" : "verified-access";
2273
1321
  }
2274
1322
  async renderPasswordlessVariant() {
2275
- this._setupApis();
2276
- _log$1("Rendering as an Instant Access widget");
2277
- return await this.widgetApi.render({
1323
+ return this._setupApis(), P("Rendering as an Instant Access widget"), await this.widgetApi.render({
2278
1324
  engagementMedium: this.type,
2279
1325
  widgetType: this.widgetType,
2280
1326
  locale: this.locale
2281
- }).then((res) => this._setWidget(res, { type: "passwordless" })).catch(this.setErrorWidget);
1327
+ }).then((e) => this._setWidget(e, { type: "passwordless" })).catch(this.setErrorWidget);
2282
1328
  }
2283
1329
  async renderUserUpsertVariant() {
2284
1330
  this._setupApis();
2285
- const userObj = decodeUserJwt(this.token);
2286
- if (!userObj) {
1331
+ const e = Je(this.token);
1332
+ if (!e)
2287
1333
  return this.setErrorWidget(Error("No user object in token."));
1334
+ !this.locale && e.locale && (this.locale = e.locale), P("Rendering as a Verified widget");
1335
+ try {
1336
+ await this.widgetApi.upsertUser({
1337
+ user: e,
1338
+ locale: this.locale,
1339
+ engagementMedium: this.type,
1340
+ widgetType: this.widgetType,
1341
+ jwt: this.token
1342
+ });
1343
+ } catch (i) {
1344
+ return this.setErrorWidget(
1345
+ i
1346
+ );
2288
1347
  }
2289
- _log$1("Rendering as a Verified widget");
2290
- await this.widgetApi.upsertUser({
2291
- user: userObj,
2292
- locale: this.locale,
2293
- engagementMedium: this.type,
2294
- widgetType: this.widgetType,
2295
- jwt: this.token
2296
- });
2297
- const widgetInstance = await this.widgetApi.render({
1348
+ return await this.widgetApi.render({
2298
1349
  locale: this.locale,
2299
1350
  engagementMedium: this.type,
2300
1351
  widgetType: this.widgetType
2301
- }).then((res) => {
2302
- return this._setWidget(res, { type: "upsert", user: userObj });
2303
- }).catch(this.setErrorWidget);
2304
- return widgetInstance;
1352
+ }).then((i) => this._setWidget(i, { type: "upsert", user: e })).catch(this.setErrorWidget);
2305
1353
  }
2306
1354
  /**
2307
1355
  * Fetches widget content from SaaSquatch and builds a Widget instance to support rendering the widget in the DOM
@@ -2309,26 +1357,19 @@ class DeclarativeWidget extends HTMLElement {
2309
1357
  * @throws Throws an Error if `widgetType` is undefined
2310
1358
  */
2311
1359
  async getWidgetInstance() {
2312
- let widgetInstance;
2313
- this.widgetType = this.getAttribute("widget") || void 0;
2314
- this.locale = this.getAttribute("locale") || this.locale;
1360
+ let e;
1361
+ this.widgetType = this.getAttribute("widget") || void 0, this.locale = this.getAttribute("locale") || this.locale;
1362
+ const n = this.getWidgetType(this.widgetType);
2315
1363
  if (!this.widgetType) throw new Error("No widget has been specified");
2316
- if (!this.token) {
2317
- widgetInstance = await this.renderPasswordlessVariant();
2318
- } else {
2319
- widgetInstance = await this.renderUserUpsertVariant();
2320
- }
2321
- this.widgetInstance = widgetInstance;
2322
- if (this.widgetInstance)
2323
- this.dispatchEvent(new CustomEvent("sq:widget-loaded"));
2324
- return widgetInstance;
1364
+ return !this.token && n === "verified-access" && P(
1365
+ "[SquatchJS] Authentication token is required for this widget type."
1366
+ ), this.token ? e = await this.renderUserUpsertVariant() : e = await this.renderPasswordlessVariant(), this.widgetInstance = e, this.widgetInstance && this.dispatchEvent(new CustomEvent("sq:widget-loaded")), e;
2325
1367
  }
2326
1368
  /**
2327
1369
  * Calls {@link getWidgetInstance} to build the Widget instance and loads the widget iframe into the DOM
2328
1370
  */
2329
1371
  async renderWidget() {
2330
- await this.getWidgetInstance();
2331
- await this.widgetInstance.load();
1372
+ await this.getWidgetInstance(), await this.widgetInstance.load();
2332
1373
  }
2333
1374
  /**
2334
1375
  * Calls `open` method of `widgetInstance`
@@ -2346,197 +1387,128 @@ class DeclarativeWidget extends HTMLElement {
2346
1387
  if (!this.widgetInstance) throw new Error("Widget has not loaded yet");
2347
1388
  this.widgetInstance.close();
2348
1389
  }
2349
- }
2350
- class DeclarativeEmbedWidget extends DeclarativeWidget {
2351
- constructor() {
2352
- super();
2353
- this.type = "EMBED";
2354
- this.loaded = false;
2355
- }
2356
1390
  static get observedAttributes() {
2357
1391
  return ["widget", "locale"];
2358
1392
  }
2359
- attributeChangedCallback(attr, oldVal, newVal) {
2360
- if (oldVal === newVal || !this.loaded) return;
2361
- switch (attr) {
2362
- case "locale":
2363
- case "widget":
2364
- this.connectedCallback();
2365
- break;
2366
- }
1393
+ attributeChangedCallback(e, n, i) {
1394
+ if (!(n === i || !this.loaded))
1395
+ switch (e) {
1396
+ case "locale":
1397
+ case "widget":
1398
+ this.connectedCallback();
1399
+ break;
1400
+ }
2367
1401
  }
2368
1402
  async connectedCallback() {
2369
- this.loaded = true;
2370
- this.container = this.getAttribute("container");
2371
- this.widgetType = this.getAttribute("widget") || void 0;
2372
- console.log("widget type", this.widgetType);
2373
- const skeletonWidgetType = this.getWidgetType(this.widgetType);
2374
- const skeletonHTML = getSkeleton({
2375
- height: "100%",
2376
- type: skeletonWidgetType
2377
- });
2378
- const skeletonContainer = document.createElement("div");
2379
- skeletonContainer.id = "loading-skeleton";
2380
- skeletonContainer.innerHTML = skeletonHTML;
2381
- const root = this.shadowRoot || this.attachShadow({ mode: "open" });
2382
- root.innerHTML = "";
2383
- root.appendChild(skeletonContainer);
2384
- await this.renderWidget();
2385
- const loadingElement = root.getElementById("loading-skeleton");
2386
- if (loadingElement) {
2387
- loadingElement.remove();
1403
+ this.loaded = !0, this.container = this.getAttribute("container"), this.widgetType = this.getAttribute("widget") || void 0;
1404
+ const e = this.getWidgetType(this.widgetType), { getSkeleton: n } = await import("./SkeletonTemplate-Day_0iMM.js"), i = n({
1405
+ type: e
1406
+ }), s = document.createElement("div");
1407
+ s.id = "loading-skeleton", s.innerHTML = i;
1408
+ const r = this.shadowRoot || this.attachShadow({ mode: "open" });
1409
+ if (this.type === "POPUP") {
1410
+ const a = r.getElementById("squatchModal");
1411
+ a ? (a.innerHTML = "", a.appendChild(s)) : r.appendChild(s);
1412
+ } else
1413
+ r.innerHTML = "", r.appendChild(s);
1414
+ try {
1415
+ await this.renderWidget();
1416
+ } catch (a) {
1417
+ P("Failed to render widget", a);
1418
+ } finally {
1419
+ const a = r.getElementById("loading-skeleton");
1420
+ a && a.remove();
2388
1421
  }
2389
- if (this.getAttribute("open") !== null) this.open();
1422
+ this.getAttribute("open") !== null && this.open();
2390
1423
  }
2391
1424
  }
2392
- class DeclarativePopupWidget extends DeclarativeWidget {
1425
+ class pe extends ge {
2393
1426
  constructor() {
2394
- super();
2395
- this.type = "POPUP";
2396
- this.loaded = false;
2397
- this.addEventListener("click", (e) => {
2398
- e.stopPropagation();
2399
- this.open();
2400
- });
2401
- }
2402
- static get observedAttributes() {
2403
- return ["widget", "locale"];
1427
+ super(), this.type = "EMBED", this.loaded = !1;
2404
1428
  }
2405
- attributeChangedCallback(attr, oldVal, newVal) {
2406
- if (oldVal === newVal || !this.loaded) return;
2407
- switch (attr) {
2408
- case "locale":
2409
- case "widget":
2410
- this.connectedCallback();
2411
- break;
2412
- }
2413
- }
2414
- async connectedCallback() {
2415
- this.loaded = true;
2416
- this.container = this.getAttribute("container");
2417
- this.widgetType = this.getAttribute("widget") || void 0;
2418
- const skeletonWidgetType = this.getWidgetType(this.widgetType);
2419
- const skeletonHTML = getSkeleton({
2420
- height: "100%",
2421
- type: skeletonWidgetType
1429
+ }
1430
+ class we extends ge {
1431
+ constructor() {
1432
+ super(), this.type = "POPUP", this.loaded = !1, this.addEventListener("click", (t) => {
1433
+ t.stopPropagation(), this.open();
2422
1434
  });
2423
- const skeletonContainer = document.createElement("div");
2424
- skeletonContainer.id = "loading-skeleton";
2425
- skeletonContainer.innerHTML = skeletonHTML;
2426
- const root = this.shadowRoot || this.attachShadow({ mode: "open" });
2427
- const container = root.getElementById("#squatchModal");
2428
- console.log("Container is ", container);
2429
- if (container) {
2430
- container.innerHTML = "";
2431
- container.appendChild(skeletonContainer);
2432
- }
2433
- await this.renderWidget();
2434
- const loadingElement = root.getElementById("loading-skeleton");
2435
- if (loadingElement) {
2436
- loadingElement.remove();
2437
- }
2438
- if (this.getAttribute("open") !== null) this.open();
2439
1435
  }
2440
1436
  }
2441
- class SquatchEmbed extends DeclarativeEmbedWidget {
1437
+ class Be extends pe {
2442
1438
  }
2443
- class SquatchPopup extends DeclarativePopupWidget {
1439
+ class Ge extends we {
2444
1440
  }
2445
- class ImpactEmbed extends DeclarativeEmbedWidget {
1441
+ class ze extends pe {
2446
1442
  }
2447
- class ImpactPopup extends DeclarativePopupWidget {
1443
+ class Ve extends we {
2448
1444
  }
2449
- if (!window.customElements.get("squatch-embed"))
2450
- window.customElements.define("squatch-embed", SquatchEmbed);
2451
- if (!window.customElements.get("impact-embed"))
2452
- window.customElements.define("impact-embed", ImpactEmbed);
2453
- if (!window.customElements.get("squatch-popup"))
2454
- window.customElements.define("squatch-popup", SquatchPopup);
2455
- if (!window.customElements.get("impact-popup"))
2456
- window.customElements.define("impact-popup", ImpactPopup);
2457
- function help() {
1445
+ window.customElements.get("squatch-embed") || window.customElements.define("squatch-embed", Be);
1446
+ window.customElements.get("impact-embed") || window.customElements.define("impact-embed", ze);
1447
+ window.customElements.get("squatch-popup") || window.customElements.define("squatch-popup", Ge);
1448
+ window.customElements.get("impact-popup") || window.customElements.define("impact-popup", Ve);
1449
+ function Ye() {
2458
1450
  console.log(
2459
- `Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes.`
1451
+ "Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes."
2460
1452
  );
2461
1453
  }
2462
- const _log = browserExports.debug("squatch-js");
2463
- let _api = null;
2464
- let _widgets = null;
2465
- let _events = null;
2466
- function api() {
2467
- if (!_api) init({});
2468
- return _api;
1454
+ const $ = C("squatch-js");
1455
+ let F = null, H = null, J = null;
1456
+ function Ze() {
1457
+ return F || G({}), F;
2469
1458
  }
2470
- function widgets() {
2471
- if (!_widgets) init({});
2472
- return _widgets;
1459
+ function K() {
1460
+ return H || G({}), H;
2473
1461
  }
2474
- function events() {
2475
- if (!_events) init({});
2476
- return _events;
1462
+ function Ke() {
1463
+ return J || G({}), J;
2477
1464
  }
2478
- function widget(widgetConfig) {
2479
- var _a2;
2480
- return (_a2 = widgets()) == null ? void 0 : _a2.render(widgetConfig);
1465
+ function et(o) {
1466
+ var t;
1467
+ return (t = K()) == null ? void 0 : t.render(o);
2481
1468
  }
2482
- function _auto() {
2483
- var _a2;
2484
- const configs = _getAutoConfig();
2485
- if (configs) {
2486
- const { squatchConfig, widgetConfig } = configs;
2487
- init(squatchConfig);
2488
- return (_a2 = widgets()) == null ? void 0 : _a2.render(widgetConfig);
1469
+ function tt() {
1470
+ var t;
1471
+ const o = Fe();
1472
+ if (o) {
1473
+ const { squatchConfig: e, widgetConfig: n } = o;
1474
+ return G(e), (t = K()) == null ? void 0 : t.render(n);
2489
1475
  }
2490
1476
  }
2491
- function init(configIn) {
2492
- const raw = configIn;
2493
- const config = validateConfig(raw);
2494
- if (config.tenantAlias.match("^test") || config.debug) {
2495
- browserExports.debug.enable("squatch-js*");
2496
- } else {
2497
- browserExports.debug.disable();
2498
- }
2499
- _log("initializing ...");
2500
- _api = new WidgetApi(config);
2501
- _widgets = new Widgets(config);
2502
- _events = new EventsApi(config);
2503
- _log("Widget API instance", _api);
2504
- _log("Widgets instance", _widgets);
2505
- _log("Events API instance", _events);
1477
+ function G(o) {
1478
+ const e = q(o);
1479
+ e.tenantAlias.match("^test") || e.debug ? ve("squatch-js*") : _e(), $("initializing ..."), F = new Z(e), H = new N(e), J = new Oe(e), $("Widget API instance", F), $("Widgets instance", H), $("Events API instance", J);
2506
1480
  }
2507
- function ready(fn) {
2508
- fn();
1481
+ function nt(o) {
1482
+ o();
2509
1483
  }
2510
- function autofill(selector) {
2511
- widgets().autofill(selector);
1484
+ function it(o) {
1485
+ K().autofill(o);
2512
1486
  }
2513
- function pushCookie() {
2514
- _pushCookie();
1487
+ function Xe() {
1488
+ Te();
2515
1489
  }
2516
- if (typeof document !== "undefined" && !window.SaaSquatchDoNotAutoDrop) {
2517
- pushCookie();
2518
- }
2519
- if ((_a = window["squatch"]) == null ? void 0 : _a.init)
2520
- _log(
2521
- "Squatchjs is being loaded more than once. This may lead to multiple load events being sent, duplicated widgets, and inaccurate analytics."
2522
- );
2523
- if (typeof document !== "undefined") asyncLoad();
1490
+ typeof document < "u" && !window.SaaSquatchDoNotAutoDrop && Xe();
1491
+ var ae;
1492
+ (ae = window.squatch) != null && ae.init && $(
1493
+ "Squatchjs is being loaded more than once. This may lead to multiple load events being sent, duplicated widgets, and inaccurate analytics."
1494
+ );
1495
+ typeof document < "u" && Ne();
2524
1496
  export {
2525
- DeclarativeEmbedWidget,
2526
- DeclarativePopupWidget,
2527
- EmbedWidget,
2528
- PopupWidget,
2529
- WidgetApi,
2530
- Widgets,
2531
- _auto,
2532
- api,
2533
- autofill,
2534
- events,
2535
- help,
2536
- init,
2537
- pushCookie,
2538
- ready,
2539
- widget,
2540
- widgets
1497
+ pe as DeclarativeEmbedWidget,
1498
+ we as DeclarativePopupWidget,
1499
+ D as EmbedWidget,
1500
+ j as PopupWidget,
1501
+ Z as WidgetApi,
1502
+ N as Widgets,
1503
+ tt as _auto,
1504
+ Ze as api,
1505
+ it as autofill,
1506
+ Ke as events,
1507
+ Ye as help,
1508
+ G as init,
1509
+ Xe as pushCookie,
1510
+ nt as ready,
1511
+ et as widget,
1512
+ K as widgets
2541
1513
  };
2542
1514
  //# sourceMappingURL=squatch.esm.js.map