@saasquatch/squatch-js 2.8.2 → 2.8.3-1

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