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