@saasquatch/squatch-js 2.8.2-8 → 2.8.3-0

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