@saasquatch/squatch-js 2.8.2-8 → 2.8.3-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage/clover.xml +944 -0
- package/coverage/coverage-final.json +22 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +1714 -0
- package/dist/SkeletonTemplate-CIRGs_GB.js +258 -0
- package/dist/SkeletonTemplate-CIRGs_GB.js.map +1 -0
- package/dist/SkeletonTemplate-hwDwv3Ys.cjs +250 -0
- package/dist/SkeletonTemplate-hwDwv3Ys.cjs.map +1 -0
- package/dist/squatch.cjs.js +25 -2592
- package/dist/squatch.cjs.js.map +1 -1
- package/dist/squatch.esm.js +812 -1987
- package/dist/squatch.esm.js.map +1 -1
- package/dist/squatch.js +250 -2573
- package/dist/squatch.js.map +1 -1
- package/dist/squatch.min.js +4 -5
- package/dist/utils/logger.d.ts +20 -0
- package/dist/widgets/PopupWidget.d.ts +2 -2
- package/dist/widgets/SkeletonTemplate.d.ts +3 -2
- package/dist/widgets/declarative/DeclarativeWidget.d.ts +4 -0
- package/dist/widgets/declarative/DeclarativeWidgets.d.ts +0 -6
- package/package.json +1 -2
- 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 Ee=Object.defineProperty;var Ce=(o,t,e)=>t in o?Ee(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var l=(o,t,e)=>Ce(o,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let L=null;function ve(o){const e=o.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");L=new RegExp(`^${e}$`)}function be(){L=null}function E(o){return(...t)=>{L&&L.test(o)&&console.log(`[${o}]`,...t)}}/*! js-cookie v3.0.5 | MIT */function P(o){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var i in e)o[i]=e[i]}return o}var Ae={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 V(o,t){function e(n,s,r){if(!(typeof document>"u")){r=P({},t,r),typeof r.expires=="number"&&(r.expires=new Date(Date.now()+r.expires*864e5)),r.expires&&(r.expires=r.expires.toUTCString()),n=encodeURIComponent(n).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var c in r)r[c]&&(a+="; "+c,r[c]!==!0&&(a+="="+r[c].split(";")[0]));return document.cookie=n+"="+o.write(s,n)+a}}function i(n){if(!(typeof document>"u"||arguments.length&&!n)){for(var s=document.cookie?document.cookie.split("; "):[],r={},a=0;a<s.length;a++){var c=s[a].split("="),d=c.slice(1).join("=");try{var h=decodeURIComponent(c[0]);if(r[h]=o.read(d,h),n===h)break}catch{}}return n?r[n]:r}}return Object.create({set:e,get:i,remove:function(n,s){e(n,"",P({},s,{expires:-1}))},withAttributes:function(n){return V(this.converter,P({},this.attributes,n))},withConverter:function(n){return V(P({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(t)},converter:{value:Object.freeze(o)}})}var j=V(Ae,{path:"/"});const A="https://app.referralsaasquatch.com",X="https://fast.ssqt.io/npm",S="squatch",z="impact";function U(o){if(typeof o!="object")throw new Error("config must be an object");const t=window.squatchTenant,e=K(),i={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 i.tenantAlias!="string")throw new Error("tenantAlias not provided");const n=i.tenantAlias,s=typeof i.domain=="string"&&i.domain||A,r=typeof i.debug=="boolean"&&i.debug||!1,a=typeof i.npmCdn=="string"&&i.npmCdn||X;return{tenantAlias:n,domain:s,debug:r,npmCdn:a}}function I(o){return typeof o=="object"&&!Array.isArray(o)&&o!==null}function Ie(o){if(o&&/^[a-z]{2}_(?:[A-Z]{2}|[0-9]{3})$/.test(o))return o}function ae(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 ce(o){if(!I(o))throw new Error("Widget properties must be an object");return o}function R(){return window.impactToken||window.squatchToken}function K(){return window.impactConfig||window.squatchConfig}async function _e(o,t,e,i){const n=i||R(),s={Accept:"application/json","Content-Type":"application/json",...n?{Authorization:`Bearer ${n}`}:{},"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 ke(o,t=""){const e={Accept:"application/json","Content-Type":"application/json"},i=t||R();i&&(e["X-SaaSquatch-User-Token"]=i);try{const n=await fetch(o,{method:"GET",credentials:"include",headers:e}),s=await n.text();if(!n.ok)throw new Error(s);return s&&JSON.parse(s)}catch(n){throw n}}async function Q(o,t,e){const i={Accept:"application/json","Content-Type":"application/json"},n=e||R();n&&(i["X-SaaSquatch-User-Token"]=n);try{const s=await fetch(o,{method:"POST",body:t,headers:i}),r=await s.text();if(!s.ok)throw new Error(r);return r&&JSON.parse(r)}catch(s){throw s}}async function We(o,t,e){const i={Accept:"application/json","Content-Type":"application/json","X-SaaSquatch-Referrer":window?window.location.href:""},n=e||R();n&&(i["X-SaaSquatch-User-Token"]=n);try{const s=await fetch(o,{headers:i,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 xe=`
|
|
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,375 +12,22 @@ 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
|
-
console.log({ params });
|
|
706
|
-
const tenantAlias = encodeURIComponent(this.tenantAlias);
|
|
707
|
-
const accountId = (user == null ? void 0 : user.accountId) ? encodeURIComponent(user.accountId) : null;
|
|
708
|
-
const userId = (user == null ? void 0 : user.id) ? encodeURIComponent(user.id) : null;
|
|
709
|
-
const locale = clean.locale ?? validateLocale(navigator.language.replace(/\-/g, "_"));
|
|
710
|
-
const path = `/api/v1/${tenantAlias}/graphql`;
|
|
711
|
-
const url = this.domain + path;
|
|
712
|
-
return new Promise(async (resolve, reject) => {
|
|
713
|
-
var _a2;
|
|
714
|
-
try {
|
|
715
|
-
const res = await doQuery(
|
|
716
|
-
url,
|
|
717
|
-
RENDER_WIDGET_QUERY,
|
|
718
|
-
{
|
|
719
|
-
user: userId && accountId ? { id: userId, accountId } : null,
|
|
720
|
-
engagementMedium,
|
|
721
|
-
widgetType,
|
|
722
|
-
locale
|
|
723
|
-
},
|
|
724
|
-
jwt
|
|
725
|
-
);
|
|
726
|
-
resolve((_a2 = res == null ? void 0 : res.data) == null ? void 0 : _a2.renderWidget);
|
|
727
|
-
} catch (e) {
|
|
728
|
-
reject(e);
|
|
729
|
-
}
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
/**
|
|
733
|
-
* Looks up the referral code of the current user, if there is any.
|
|
734
|
-
*
|
|
735
|
-
* @return {Promise<ReferralCookie>} code referral code if true.
|
|
736
|
-
*/
|
|
737
|
-
async squatchReferralCookie() {
|
|
738
|
-
const tenantAlias = encodeURIComponent(this.tenantAlias);
|
|
739
|
-
const _saasquatch = (api$1 || window.Cookies).get("_saasquatch") || "";
|
|
740
|
-
const cookie = _saasquatch ? `?cookies=${encodeURIComponent(_saasquatch)}` : ``;
|
|
741
|
-
const url = `${this.domain}/a/${tenantAlias}/widgets/squatchcookiejson${cookie}`;
|
|
742
|
-
const response = await doGet(url);
|
|
743
|
-
return Promise.resolve({
|
|
744
|
-
...response,
|
|
745
|
-
encodedCookie: _saasquatch
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
function _buildParams({
|
|
750
|
-
widgetType,
|
|
751
|
-
engagementMedium,
|
|
752
|
-
locale
|
|
753
|
-
}) {
|
|
754
|
-
const queryParams = new URLSearchParams();
|
|
755
|
-
queryParams.append("engagementMedium", engagementMedium);
|
|
756
|
-
if (widgetType) queryParams.append("widgetType", widgetType);
|
|
757
|
-
if (locale) queryParams.append("locale", locale);
|
|
758
|
-
return `?${queryParams.toString()}`;
|
|
759
|
-
}
|
|
760
|
-
/*!
|
|
15
|
+
`;class J{constructor(t){l(this,"tenantAlias");l(this,"domain");l(this,"npmCdn");l(this,"referralCookie",this.squatchReferralCookie);const i=U(t);this.tenantAlias=i.tenantAlias,this.domain=i.domain,this.npmCdn=i.npmCdn}upsertUser(t){const i=ae(t),{widgetType:n,engagementMedium:s="POPUP",jwt:r,locale:a,user:c}=i,d=encodeURIComponent(this.tenantAlias),h=c.accountId?encodeURIComponent(c.accountId):null,u=c.id?encodeURIComponent(c.id):null,p=qe({widgetType:n,engagementMedium:s,locale:a}),m=`/api/v1/${d}/widget/account/${h}/user/${u}/upsert${p}`,g=this.domain+m,f=(j||window.Cookies).get("_saasquatch");return f&&(c.cookies=f),We(g,JSON.stringify(c),r)}render(t){const i=ce(t),{widgetType:n,engagementMedium:s="POPUP",jwt:r,user:a}=i,c=encodeURIComponent(this.tenantAlias),d=a!=null&&a.accountId?encodeURIComponent(a.accountId):null,h=a!=null&&a.id?encodeURIComponent(a.id):null,u=i.locale??Ie(navigator.language.replace(/\-/g,"_")),p=`/api/v1/${c}/graphql`,m=this.domain+p;return new Promise(async(g,f)=>{var _;try{const C=await _e(m,xe,{user:h&&d?{id:h,accountId:d}:null,engagementMedium:s,widgetType:n,locale:u},r);g((_=C==null?void 0:C.data)==null?void 0:_.renderWidget)}catch(C){f(C)}})}async squatchReferralCookie(){const t=encodeURIComponent(this.tenantAlias),e=(j||window.Cookies).get("_saasquatch")||"",i=e?`?cookies=${encodeURIComponent(e)}`:"",n=`${this.domain}/a/${t}/widgets/squatchcookiejson${i}`,s=await ke(n);return Promise.resolve({...s,encodedCookie:e})}}function qe({widgetType:o,engagementMedium:t,locale:e}){const i=new URLSearchParams;return i.append("engagementMedium",t),o&&i.append("widgetType",o),e&&i.append("locale",e),`?${i.toString()}`}/*!
|
|
761
16
|
* domready (c) Dustin Diaz 2014 - License MIT
|
|
762
17
|
*
|
|
763
|
-
*/
|
|
764
|
-
function domready(targetDoc, fn) {
|
|
765
|
-
let fns = [];
|
|
766
|
-
let listener;
|
|
767
|
-
let doc = targetDoc;
|
|
768
|
-
let hack = doc.documentElement.doScroll;
|
|
769
|
-
let domContentLoaded = "DOMContentLoaded";
|
|
770
|
-
let loaded = (hack ? /^loaded|^c/ : /^loaded|^i|^c/).test(doc.readyState);
|
|
771
|
-
if (!loaded)
|
|
772
|
-
doc.addEventListener(
|
|
773
|
-
domContentLoaded,
|
|
774
|
-
listener = () => {
|
|
775
|
-
doc.removeEventListener(domContentLoaded, listener);
|
|
776
|
-
loaded = true;
|
|
777
|
-
while (listener = fns.shift()) listener();
|
|
778
|
-
}
|
|
779
|
-
);
|
|
780
|
-
return loaded ? setTimeout(fn, 0) : fns.push(fn);
|
|
781
|
-
}
|
|
782
|
-
function formatWidth({
|
|
783
|
-
value,
|
|
784
|
-
unit
|
|
785
|
-
}) {
|
|
786
|
-
switch (unit) {
|
|
787
|
-
case "px":
|
|
788
|
-
return `${value}px`;
|
|
789
|
-
case "%":
|
|
790
|
-
return `${value}%`;
|
|
791
|
-
default:
|
|
792
|
-
return `${value}px`;
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
class AnalyticsApi {
|
|
796
|
-
/**
|
|
797
|
-
* Initialize a new {@link AnalyticsApi} instance.
|
|
798
|
-
*
|
|
799
|
-
* @param {Object} config Config details
|
|
800
|
-
* @param {string} [config.domain='https://app.referralsaasquatch.com'] The server domain.
|
|
801
|
-
*
|
|
802
|
-
*/
|
|
803
|
-
constructor(config) {
|
|
804
|
-
__publicField(this, "domain");
|
|
805
|
-
var _a2;
|
|
806
|
-
const raw = config;
|
|
807
|
-
const clean = _validateAnalyticsConfig(raw);
|
|
808
|
-
this.domain = (clean == null ? void 0 : clean["domain"]) || ((_a2 = getConfig()) == null ? void 0 : _a2.domain) || DEFAULT_DOMAIN;
|
|
809
|
-
}
|
|
810
|
-
pushAnalyticsLoadEvent(params) {
|
|
811
|
-
if (!params.externalUserId || !params.externalAccountId) return;
|
|
812
|
-
const tenantAlias = encodeURIComponent(params.tenantAlias);
|
|
813
|
-
const accountId = encodeURIComponent(params.externalAccountId);
|
|
814
|
-
const userId = encodeURIComponent(params.externalUserId);
|
|
815
|
-
const engagementMedium = encodeURIComponent(params.engagementMedium);
|
|
816
|
-
const programId = params.programId ? `&programId=${encodeURIComponent(params.programId)}` : ``;
|
|
817
|
-
const path = `/a/${tenantAlias}/widgets/analytics/loaded?externalAccountId=${accountId}&externalUserId=${userId}&engagementMedium=${engagementMedium}${programId}`;
|
|
818
|
-
const url = this.domain + path;
|
|
819
|
-
return doPost(url, JSON.stringify({}));
|
|
820
|
-
}
|
|
821
|
-
pushAnalyticsShareClickedEvent(params) {
|
|
822
|
-
const tenantAlias = encodeURIComponent(params.tenantAlias);
|
|
823
|
-
const accountId = encodeURIComponent(params.externalAccountId);
|
|
824
|
-
const userId = encodeURIComponent(params.externalUserId);
|
|
825
|
-
const engagementMedium = encodeURIComponent(params.engagementMedium);
|
|
826
|
-
const shareMedium = encodeURIComponent(params.shareMedium);
|
|
827
|
-
const path = `/a/${tenantAlias}/widgets/analytics/shared?externalAccountId=${accountId}&externalUserId=${userId}&engagementMedium=${engagementMedium}&shareMedium=${shareMedium}`;
|
|
828
|
-
const url = this.domain + path;
|
|
829
|
-
return doPost(url, JSON.stringify({}));
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
function _validateAnalyticsConfig(raw) {
|
|
833
|
-
if (!isObject$1(raw)) throw new Error("'options' should be an object");
|
|
834
|
-
return raw;
|
|
835
|
-
}
|
|
836
|
-
const _log$8 = browserExports.debug("squatch-js:widget");
|
|
837
|
-
class Widget {
|
|
838
|
-
constructor(params) {
|
|
839
|
-
__publicField(this, "type");
|
|
840
|
-
__publicField(this, "content");
|
|
841
|
-
__publicField(this, "analyticsApi");
|
|
842
|
-
__publicField(this, "widgetApi");
|
|
843
|
-
__publicField(this, "context");
|
|
844
|
-
__publicField(this, "npmCdn");
|
|
845
|
-
__publicField(this, "container");
|
|
846
|
-
__publicField(this, "loadEventListener", null);
|
|
847
|
-
var _a2;
|
|
848
|
-
_log$8("widget initializing ...");
|
|
849
|
-
this.content = params.content === "error" ? this._error(params.rsCode) : params.content;
|
|
850
|
-
this.type = params.type;
|
|
851
|
-
this.widgetApi = params.api;
|
|
852
|
-
this.npmCdn = params.npmCdn;
|
|
853
|
-
this.analyticsApi = new AnalyticsApi({ domain: params.domain });
|
|
854
|
-
this.context = params.context;
|
|
855
|
-
this.container = ((_a2 = params.context) == null ? void 0 : _a2.container) || params.container;
|
|
856
|
-
}
|
|
857
|
-
_findElement() {
|
|
858
|
-
let element;
|
|
859
|
-
if (typeof this.container === "string") {
|
|
860
|
-
element = document.querySelector(this.container);
|
|
861
|
-
_log$8("loading widget with selector", element);
|
|
862
|
-
} else if (this.container instanceof HTMLElement) {
|
|
863
|
-
element = this.container;
|
|
864
|
-
_log$8("loading widget with container", element);
|
|
865
|
-
} else if (this.container) {
|
|
866
|
-
element = null;
|
|
867
|
-
_log$8("container must be an HTMLElement or string", this.container);
|
|
868
|
-
} else {
|
|
869
|
-
element = document.querySelector("#squatchembed") || document.querySelector(".squatchembed") || document.querySelector("#impactembed") || document.querySelector(".impactembed");
|
|
870
|
-
_log$8("loading widget with default selector", element);
|
|
871
|
-
}
|
|
872
|
-
if (!(element instanceof HTMLElement))
|
|
873
|
-
throw new Error(
|
|
874
|
-
`element with selector '${this.container || "#squatchembed, .squatchembed, #impactembed, or .impactembed"}' not found.'`
|
|
875
|
-
);
|
|
876
|
-
return element;
|
|
877
|
-
}
|
|
878
|
-
_createFrame(options) {
|
|
879
|
-
const frame = document.createElement("iframe");
|
|
880
|
-
frame["squatchJsApi"] = this;
|
|
881
|
-
frame.id = "squatchFrame";
|
|
882
|
-
frame.width = "100%";
|
|
883
|
-
frame.src = "about:blank";
|
|
884
|
-
frame.scrolling = "no";
|
|
885
|
-
frame.setAttribute(
|
|
886
|
-
"style",
|
|
887
|
-
"border: 0; background-color: none; width: 1px; min-width: 100%;"
|
|
888
|
-
);
|
|
889
|
-
if (options == null ? void 0 : options.minWidth) frame.style.minWidth = options.minWidth;
|
|
890
|
-
if (options == null ? void 0 : options.maxWidth) frame.style.maxWidth = options.maxWidth;
|
|
891
|
-
if ((options == null ? void 0 : options.maxWidth) || (options == null ? void 0 : options.minWidth)) {
|
|
892
|
-
frame.style.width = "100%";
|
|
893
|
-
}
|
|
894
|
-
if (options == null ? void 0 : options.initialHeight) {
|
|
895
|
-
frame.height = options.initialHeight;
|
|
896
|
-
}
|
|
897
|
-
return frame;
|
|
898
|
-
}
|
|
899
|
-
_findFrame() {
|
|
900
|
-
const element = this.container ? this._findElement() : document.body;
|
|
901
|
-
const parent = element.shadowRoot || element;
|
|
902
|
-
return parent.querySelector(
|
|
903
|
-
"iframe#squatchFrame"
|
|
904
|
-
);
|
|
905
|
-
}
|
|
906
|
-
_detachLoadEventListener(frameDoc) {
|
|
907
|
-
if (this.loadEventListener) {
|
|
908
|
-
frameDoc.removeEventListener(
|
|
909
|
-
"sq:user-registration",
|
|
910
|
-
this.loadEventListener
|
|
911
|
-
);
|
|
912
|
-
this.loadEventListener = null;
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
_attachLoadEventListener(frameDoc, sqh) {
|
|
916
|
-
if (this.loadEventListener === null) {
|
|
917
|
-
this.loadEventListener = (e) => {
|
|
918
|
-
this._loadEvent({
|
|
919
|
-
...sqh,
|
|
920
|
-
userId: e.detail.userId,
|
|
921
|
-
accountId: e.detail.accountId
|
|
922
|
-
});
|
|
923
|
-
};
|
|
924
|
-
frameDoc.addEventListener("sq:user-registration", this.loadEventListener);
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
_loadEvent(sqh) {
|
|
928
|
-
var _a2;
|
|
929
|
-
if (!sqh) return;
|
|
930
|
-
if (!isObject$1(sqh)) {
|
|
931
|
-
throw new Error("Widget Load event identity property is not an object");
|
|
932
|
-
}
|
|
933
|
-
let params;
|
|
934
|
-
if ("programId" in sqh) {
|
|
935
|
-
if (!sqh.tenantAlias || !sqh.accountId || !sqh.userId || !sqh.engagementMedium)
|
|
936
|
-
throw new Error("Widget Load event missing required properties");
|
|
937
|
-
params = {
|
|
938
|
-
tenantAlias: sqh.tenantAlias,
|
|
939
|
-
externalAccountId: sqh.accountId,
|
|
940
|
-
externalUserId: sqh.userId,
|
|
941
|
-
engagementMedium: sqh.engagementMedium,
|
|
942
|
-
programId: sqh.programId
|
|
943
|
-
};
|
|
944
|
-
} else {
|
|
945
|
-
const { analytics, mode } = sqh;
|
|
946
|
-
params = {
|
|
947
|
-
tenantAlias: analytics.attributes.tenant,
|
|
948
|
-
externalAccountId: analytics.attributes.accountId,
|
|
949
|
-
externalUserId: analytics.attributes.userId,
|
|
950
|
-
engagementMedium: mode.widgetMode
|
|
951
|
-
};
|
|
952
|
-
}
|
|
953
|
-
(_a2 = this.analyticsApi.pushAnalyticsLoadEvent(params)) == null ? void 0 : _a2.then((response) => {
|
|
954
|
-
_log$8(`${params.engagementMedium} loaded event recorded.`);
|
|
955
|
-
}).catch((ex) => {
|
|
956
|
-
_log$8(`ERROR: pushAnalyticsLoadEvent() ${ex}`);
|
|
957
|
-
});
|
|
958
|
-
}
|
|
959
|
-
_shareEvent(sqh, medium) {
|
|
960
|
-
if (sqh) {
|
|
961
|
-
this.analyticsApi.pushAnalyticsShareClickedEvent({
|
|
962
|
-
tenantAlias: sqh.analytics.attributes.tenant,
|
|
963
|
-
externalAccountId: sqh.analytics.attributes.accountId,
|
|
964
|
-
externalUserId: sqh.analytics.attributes.userId,
|
|
965
|
-
engagementMedium: sqh.mode.widgetMode,
|
|
966
|
-
shareMedium: medium
|
|
967
|
-
}).then((response) => {
|
|
968
|
-
_log$8(
|
|
969
|
-
`${sqh.mode.widgetMode} share ${medium} event recorded. ${response}`
|
|
970
|
-
);
|
|
971
|
-
}).catch((ex) => {
|
|
972
|
-
_log$8(`ERROR: pushAnalyticsShareClickedEvent() ${ex}`);
|
|
973
|
-
});
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
_error(rs, mode = "modal", style = "") {
|
|
977
|
-
const errorTemplate = `<!DOCTYPE html>
|
|
18
|
+
*/function Y(o,t){let e=[],i,n=o,s=n.documentElement.doScroll,r="DOMContentLoaded",a=(s?/^loaded|^c/:/^loaded|^i|^c/).test(n.readyState);return a||n.addEventListener(r,i=()=>{for(n.removeEventListener(r,i),a=!0;i=e.shift();)i()}),a?setTimeout(t,0):e.push(t)}function D({value:o,unit:t}){switch(t){case"px":return`${o}px`;case"%":return`${o}%`;default:return`${o}px`}}class de{constructor(t){l(this,"domain");var n;const i=Te(t);this.domain=(i==null?void 0:i.domain)||((n=K())==null?void 0:n.domain)||A}pushAnalyticsLoadEvent(t){if(!t.externalUserId||!t.externalAccountId)return;const e=encodeURIComponent(t.tenantAlias),i=encodeURIComponent(t.externalAccountId),n=encodeURIComponent(t.externalUserId),s=encodeURIComponent(t.engagementMedium),r=t.programId?`&programId=${encodeURIComponent(t.programId)}`:"",a=`/a/${e}/widgets/analytics/loaded?externalAccountId=${i}&externalUserId=${n}&engagementMedium=${s}${r}`,c=this.domain+a;return Q(c,JSON.stringify({}))}pushAnalyticsShareClickedEvent(t){const e=encodeURIComponent(t.tenantAlias),i=encodeURIComponent(t.externalAccountId),n=encodeURIComponent(t.externalUserId),s=encodeURIComponent(t.engagementMedium),r=encodeURIComponent(t.shareMedium),a=`/a/${e}/widgets/analytics/shared?externalAccountId=${i}&externalUserId=${n}&engagementMedium=${s}&shareMedium=${r}`,c=this.domain+a;return Q(c,JSON.stringify({}))}}function Te(o){if(!I(o))throw new Error("'options' should be an object");return o}const w=E("squatch-js:widget");class le{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;w("widget initializing ..."),this.content=t.content==="error"?this._error(t.rsCode):t.content,this.type=t.type,this.widgetApi=t.api,this.npmCdn=t.npmCdn,this.analyticsApi=new de({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),w("loading widget with selector",t)):this.container instanceof HTMLElement?(t=this.container,w("loading widget with container",t)):this.container?(t=null,w("container must be an HTMLElement or string",this.container)):(t=document.querySelector("#squatchembed")||document.querySelector(".squatchembed")||document.querySelector("#impactembed")||document.querySelector(".impactembed"),w("loading widget with default selector",t)),!(t instanceof HTMLElement))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=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=i=>{this._loadEvent({...e,userId:i.detail.userId,accountId:i.detail.accountId})},t.addEventListener("sq:user-registration",this.loadEventListener))}_loadEvent(t){var i;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:n,mode:s}=t;e={tenantAlias:n.attributes.tenant,externalAccountId:n.attributes.accountId,externalUserId:n.attributes.userId,engagementMedium:s.widgetMode}}(i=this.analyticsApi.pushAnalyticsLoadEvent(e))==null||i.then(n=>{w(`${e.engagementMedium} loaded event recorded.`)}).catch(n=>{w(`ERROR: pushAnalyticsLoadEvent() ${n}`)})}_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(i=>{w(`${t.mode.widgetMode} share ${e} event recorded. ${i}`)}).catch(i=>{w(`ERROR: pushAnalyticsShareClickedEvent() ${i}`)})}_error(t,e="modal",i=""){return`<!DOCTYPE html>
|
|
978
19
|
<!--[if IE 7]><html class="ie7 oldie" lang="en"><![endif]-->
|
|
979
20
|
<!--[if IE 8]><html class="ie8 oldie" lang="en"><![endif]-->
|
|
980
21
|
<!--[if gt IE 8]><!--><html lang="en"><!--<![endif]-->
|
|
981
22
|
<head>
|
|
982
23
|
<link rel="stylesheet" media="all" href="https://fast.ssqt.io/assets/css/widget/errorpage.css">
|
|
983
24
|
<style>
|
|
984
|
-
${
|
|
25
|
+
${i}
|
|
985
26
|
</style>
|
|
986
27
|
</head>
|
|
987
28
|
<body>
|
|
988
29
|
|
|
989
|
-
<div class="squatch-container ${
|
|
30
|
+
<div class="squatch-container ${e}" style="width:100%">
|
|
990
31
|
<div class="errorheader">
|
|
991
32
|
<button type="button" class="close" onclick="window.frameElement.squatchJsApi.close();">×</button>
|
|
992
33
|
<p class="errortitle">Error</p>
|
|
@@ -999,1644 +40,36 @@ class Widget {
|
|
|
999
40
|
<br>
|
|
1000
41
|
<br>
|
|
1001
42
|
<div class="right-align errtxt">
|
|
1002
|
-
Error Code: ${
|
|
43
|
+
Error Code: ${t}
|
|
1003
44
|
</div>
|
|
1004
45
|
</div>
|
|
1005
46
|
</div>
|
|
1006
47
|
</body>
|
|
1007
|
-
</html
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
return fallback;
|
|
1020
|
-
}
|
|
1021
|
-
let found = null;
|
|
1022
|
-
for (let i = 0; i < 5; i++) {
|
|
1023
|
-
found = search();
|
|
1024
|
-
if (found) break;
|
|
1025
|
-
await delay(100);
|
|
1026
|
-
}
|
|
1027
|
-
if (!found) {
|
|
1028
|
-
return frameDoc.body;
|
|
1029
|
-
}
|
|
1030
|
-
return found;
|
|
1031
|
-
}
|
|
1032
|
-
/**
|
|
1033
|
-
* Reloads the current widget, makes updated request to API and renders result.
|
|
1034
|
-
* Primarily for Classic widgets with registration
|
|
1035
|
-
* @param param0 Form field values
|
|
1036
|
-
* @param jwt JWT for API authentication
|
|
1037
|
-
*/
|
|
1038
|
-
reload({ email, firstName, lastName }, jwt) {
|
|
1039
|
-
const frame = this._findFrame();
|
|
1040
|
-
if (!frame) throw new Error("Could not find widget iframe");
|
|
1041
|
-
const frameWindow = frame.contentWindow;
|
|
1042
|
-
const engagementMedium = this.context.engagementMedium || "POPUP";
|
|
1043
|
-
if (!frameWindow) {
|
|
1044
|
-
throw new Error("Frame needs a content window");
|
|
1045
|
-
}
|
|
1046
|
-
let response;
|
|
1047
|
-
if (this.context.type === "upsert") {
|
|
1048
|
-
if (!this.context.user) throw new Error("Can't reload without user ids");
|
|
1049
|
-
let userObj = {
|
|
1050
|
-
email: email || null,
|
|
1051
|
-
firstName: firstName || null,
|
|
1052
|
-
lastName: lastName || null,
|
|
1053
|
-
id: this.context.user.id,
|
|
1054
|
-
accountId: this.context.user.accountId
|
|
1055
|
-
};
|
|
1056
|
-
response = this.widgetApi.upsertUser({
|
|
1057
|
-
user: userObj,
|
|
1058
|
-
engagementMedium,
|
|
1059
|
-
widgetType: this.type,
|
|
1060
|
-
jwt
|
|
1061
|
-
});
|
|
1062
|
-
} else if (this.context.type === "passwordless") {
|
|
1063
|
-
response = this.widgetApi.render({
|
|
1064
|
-
user: void 0,
|
|
1065
|
-
engagementMedium,
|
|
1066
|
-
widgetType: this.type,
|
|
1067
|
-
jwt: void 0
|
|
1068
|
-
});
|
|
1069
|
-
} else {
|
|
1070
|
-
throw new Error("can't reload an error widget");
|
|
1071
|
-
}
|
|
1072
|
-
response.then(({ template }) => {
|
|
1073
|
-
if (template) {
|
|
1074
|
-
this.content = template;
|
|
1075
|
-
this.__deprecated__register(
|
|
1076
|
-
frame,
|
|
1077
|
-
{ email, engagementMedium },
|
|
1078
|
-
() => {
|
|
1079
|
-
this.load();
|
|
1080
|
-
engagementMedium === "POPUP" && this.open();
|
|
1081
|
-
}
|
|
1082
|
-
);
|
|
1083
|
-
}
|
|
1084
|
-
}).catch(({ message }) => {
|
|
1085
|
-
_log$8(`${message}`);
|
|
1086
|
-
});
|
|
1087
|
-
}
|
|
1088
|
-
__deprecated__register(frame, params, onClick) {
|
|
1089
|
-
const frameWindow = frame.contentWindow;
|
|
1090
|
-
const frameDoc = frameWindow.document;
|
|
1091
|
-
const showStatsBtn = frameDoc.createElement("button");
|
|
1092
|
-
const registerForm = frameDoc.getElementsByClassName("squatch-register")[0];
|
|
1093
|
-
if (registerForm) {
|
|
1094
|
-
showStatsBtn.className = "btn btn-primary";
|
|
1095
|
-
showStatsBtn.id = "show-stats-btn";
|
|
1096
|
-
showStatsBtn.textContent = this.type === "REFERRER_WIDGET" ? "Show Stats" : "Show Reward";
|
|
1097
|
-
const widgetStyle = params.engagementMedium === "POPUP" ? "margin-top: 10px; max-width: 130px; width: 100%;" : "margin-top: 10px;";
|
|
1098
|
-
showStatsBtn.setAttribute("style", widgetStyle);
|
|
1099
|
-
showStatsBtn.onclick = onClick;
|
|
1100
|
-
registerForm.style.paddingTop = "30px";
|
|
1101
|
-
registerForm.innerHTML = `<p><strong>${params.email}</strong><br>Has been successfully registered</p>`;
|
|
1102
|
-
registerForm.appendChild(showStatsBtn);
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
function delay(duration) {
|
|
1107
|
-
return new Promise((resolve) => {
|
|
1108
|
-
setTimeout(resolve, duration);
|
|
1109
|
-
});
|
|
1110
|
-
}
|
|
1111
|
-
const getSkeleton = ({
|
|
1112
|
-
height = "500px",
|
|
1113
|
-
skeletonBackgroundColor = "#e0e0e0",
|
|
1114
|
-
skeletonShimmerColor = "#f5f5f5",
|
|
1115
|
-
borderColor = "#ccc"
|
|
1116
|
-
}) => {
|
|
1117
|
-
return `
|
|
1118
|
-
<style>
|
|
1119
|
-
* {
|
|
1120
|
-
box-sizing: border-box;
|
|
1121
|
-
padding: 0;
|
|
1122
|
-
margin: 0;
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
.widget-container {
|
|
1126
|
-
background: white;
|
|
1127
|
-
width: 100%;
|
|
1128
|
-
max-width: 900px;
|
|
1129
|
-
padding: 40px;
|
|
1130
|
-
border-radius: 12px;
|
|
1131
|
-
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
|
|
1132
|
-
box-sizing: border-box;
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
@keyframes shimmer {
|
|
1136
|
-
0% {
|
|
1137
|
-
background-position: -100% 0;
|
|
1138
|
-
}
|
|
1139
|
-
100% {
|
|
1140
|
-
background-position: 100% 0;
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
.skeleton {
|
|
1145
|
-
background: ${skeletonBackgroundColor};
|
|
1146
|
-
background: linear-gradient(
|
|
1147
|
-
90deg,
|
|
1148
|
-
${skeletonBackgroundColor} 25%,
|
|
1149
|
-
${skeletonShimmerColor} 50%,
|
|
1150
|
-
${skeletonBackgroundColor} 75%
|
|
1151
|
-
);
|
|
1152
|
-
background-size: 200% 100%;
|
|
1153
|
-
animation: shimmer 1.5s infinite linear;
|
|
1154
|
-
border-radius: 6px;
|
|
1155
|
-
margin-bottom: 12px;
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
.sk-title-lg {
|
|
1159
|
-
height: 36px;
|
|
1160
|
-
width: 50%;
|
|
1161
|
-
margin-bottom: 16px;
|
|
1162
|
-
}
|
|
1163
|
-
.sk-title-md {
|
|
1164
|
-
height: 28px;
|
|
1165
|
-
width: 30%;
|
|
1166
|
-
margin-bottom: 20px;
|
|
1167
|
-
margin-top: 40px;
|
|
1168
|
-
}
|
|
1169
|
-
.sk-text {
|
|
1170
|
-
height: 16px;
|
|
1171
|
-
width: 80%;
|
|
1172
|
-
margin-bottom: 8px;
|
|
1173
|
-
}
|
|
1174
|
-
.sk-text-short {
|
|
1175
|
-
width: 40%;
|
|
1176
|
-
}
|
|
1177
|
-
.sk-label {
|
|
1178
|
-
height: 14px;
|
|
1179
|
-
width: 25%;
|
|
1180
|
-
margin-bottom: 10px;
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
.hero-section {
|
|
1184
|
-
display: flex;
|
|
1185
|
-
gap: 40px;
|
|
1186
|
-
margin-bottom: 40px;
|
|
1187
|
-
border-bottom: 1px solid ${borderColor};
|
|
1188
|
-
padding-bottom: 40px;
|
|
1189
|
-
flex-direction: row;
|
|
1190
|
-
}
|
|
1191
|
-
.hero-content {
|
|
1192
|
-
flex: 1;
|
|
1193
|
-
display: flex;
|
|
1194
|
-
flex-direction: column;
|
|
1195
|
-
justify-content: center;
|
|
1196
|
-
}
|
|
1197
|
-
.hero-image {
|
|
1198
|
-
flex: 1;
|
|
1199
|
-
height: 300px;
|
|
1200
|
-
border-radius: 12px;
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
.share-section {
|
|
1204
|
-
margin-bottom: 40px;
|
|
1205
|
-
}
|
|
1206
|
-
.sk-input {
|
|
1207
|
-
height: 50px;
|
|
1208
|
-
width: 100%;
|
|
1209
|
-
border-radius: 8px;
|
|
1210
|
-
margin-bottom: 16px;
|
|
1211
|
-
}
|
|
1212
|
-
.social-buttons {
|
|
1213
|
-
display: flex;
|
|
1214
|
-
gap: 12px;
|
|
1215
|
-
}
|
|
1216
|
-
.sk-btn-social {
|
|
1217
|
-
flex: 1;
|
|
1218
|
-
height: 50px;
|
|
1219
|
-
border-radius: 8px;
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
|
-
.stats-section {
|
|
1223
|
-
display: flex;
|
|
1224
|
-
gap: 24px;
|
|
1225
|
-
margin-bottom: 40px;
|
|
1226
|
-
padding: 30px 0;
|
|
1227
|
-
border-top: 1px solid ${borderColor};
|
|
1228
|
-
border-bottom: 1px solid ${borderColor};
|
|
1229
|
-
}
|
|
1230
|
-
.stat-card {
|
|
1231
|
-
flex: 1;
|
|
1232
|
-
display: flex;
|
|
1233
|
-
flex-direction: column;
|
|
1234
|
-
align-items: center;
|
|
1235
|
-
}
|
|
1236
|
-
.stat-divider {
|
|
1237
|
-
padding-left: 24px;
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
.sk-stat-num {
|
|
1241
|
-
height: 48px;
|
|
1242
|
-
width: 120px;
|
|
1243
|
-
margin-bottom: 8px;
|
|
1244
|
-
}
|
|
1245
|
-
.sk-stat-label {
|
|
1246
|
-
height: 18px;
|
|
1247
|
-
width: 80px;
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
.table-header {
|
|
1251
|
-
display: flex;
|
|
1252
|
-
gap: 16px;
|
|
1253
|
-
margin-bottom: 16px;
|
|
1254
|
-
}
|
|
1255
|
-
.sk-th {
|
|
1256
|
-
height: 16px;
|
|
1257
|
-
}
|
|
1258
|
-
.table-row {
|
|
1259
|
-
display: flex;
|
|
1260
|
-
align-items: center;
|
|
1261
|
-
gap: 16px;
|
|
1262
|
-
padding: 16px 0;
|
|
1263
|
-
border-bottom: 1px solid ${borderColor};
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
.col-user {
|
|
1267
|
-
flex: 2;
|
|
1268
|
-
}
|
|
1269
|
-
.col-status {
|
|
1270
|
-
flex: 1;
|
|
1271
|
-
}
|
|
1272
|
-
.col-reward {
|
|
1273
|
-
flex: 2;
|
|
1274
|
-
}
|
|
1275
|
-
.col-date {
|
|
1276
|
-
flex: 1;
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
.sk-badge {
|
|
1280
|
-
height: 28px;
|
|
1281
|
-
width: 90px;
|
|
1282
|
-
border-radius: 14px;
|
|
1283
|
-
}
|
|
1284
|
-
.sk-reward-block {
|
|
1285
|
-
height: 36px;
|
|
1286
|
-
width: 100%;
|
|
1287
|
-
border-radius: 6px;
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
.pagination {
|
|
1291
|
-
display: flex;
|
|
1292
|
-
justify-content: flex-end;
|
|
1293
|
-
gap: 8px;
|
|
1294
|
-
margin-top: 24px;
|
|
1295
|
-
}
|
|
1296
|
-
.sk-btn-page {
|
|
1297
|
-
height: 36px;
|
|
1298
|
-
width: 64px;
|
|
1299
|
-
border-radius: 6px;
|
|
1300
|
-
margin-bottom: 0;
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
@media (max-width: 768px) {
|
|
1304
|
-
body {
|
|
1305
|
-
padding: 20px;
|
|
1306
|
-
}
|
|
1307
|
-
.widget-container {
|
|
1308
|
-
padding: 24px;
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
.hero-section {
|
|
1312
|
-
flex-direction: column-reverse;
|
|
1313
|
-
gap: 24px;
|
|
1314
|
-
}
|
|
1315
|
-
.hero-image {
|
|
1316
|
-
height: 220px;
|
|
1317
|
-
width: 100%;
|
|
1318
|
-
}
|
|
1319
|
-
.sk-title-lg {
|
|
1320
|
-
width: 80%;
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
.col-date {
|
|
1324
|
-
display: none;
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
@media (max-width: 480px) {
|
|
1329
|
-
body {
|
|
1330
|
-
padding: 10px;
|
|
1331
|
-
}
|
|
1332
|
-
.widget-container {
|
|
1333
|
-
padding: 16px;
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
.sk-stat-num {
|
|
1337
|
-
width: 80px;
|
|
1338
|
-
height: 40px;
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
.col-reward {
|
|
1342
|
-
display: none;
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
.col-user {
|
|
1346
|
-
flex: 3;
|
|
1347
|
-
}
|
|
1348
|
-
.col-status {
|
|
1349
|
-
flex: 2;
|
|
1350
|
-
display: flex;
|
|
1351
|
-
justify-content: flex-end;
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
</style>
|
|
1355
|
-
|
|
1356
|
-
<div class="widget-container">
|
|
1357
|
-
<div class="hero-section">
|
|
1358
|
-
<div class="hero-content">
|
|
1359
|
-
<div class="skeleton sk-title-lg"></div>
|
|
1360
|
-
<div class="skeleton sk-text"></div>
|
|
1361
|
-
<div class="skeleton sk-text sk-text-short"></div>
|
|
1362
|
-
</div>
|
|
1363
|
-
<div class="skeleton hero-image"></div>
|
|
1364
|
-
</div>
|
|
1365
|
-
|
|
1366
|
-
<div class="share-section">
|
|
1367
|
-
<div class="skeleton sk-label"></div>
|
|
1368
|
-
<div class="skeleton sk-input"></div>
|
|
1369
|
-
<div class="social-buttons">
|
|
1370
|
-
<div class="skeleton sk-btn-social"></div>
|
|
1371
|
-
<div class="skeleton sk-btn-social"></div>
|
|
1372
|
-
<div class="skeleton sk-btn-social"></div>
|
|
1373
|
-
<div class="skeleton sk-btn-social"></div>
|
|
1374
|
-
</div>
|
|
1375
|
-
</div>
|
|
1376
|
-
|
|
1377
|
-
<div
|
|
1378
|
-
class="skeleton sk-title-md"
|
|
1379
|
-
style="margin-top: 0; width: 30%; margin-left: auto; margin-right: auto"
|
|
1380
|
-
></div>
|
|
1381
|
-
<div
|
|
1382
|
-
class="skeleton sk-text"
|
|
1383
|
-
style="width: 60%; margin-left: auto; margin-right: auto"
|
|
1384
|
-
></div>
|
|
1385
|
-
|
|
1386
|
-
<div class="stats-section">
|
|
1387
|
-
<div class="stat-card">
|
|
1388
|
-
<div class="skeleton sk-stat-num"></div>
|
|
1389
|
-
<div class="skeleton sk-stat-label"></div>
|
|
1390
|
-
</div>
|
|
1391
|
-
<div class="stat-card stat-divider">
|
|
1392
|
-
<div class="skeleton sk-stat-num"></div>
|
|
1393
|
-
<div class="skeleton sk-stat-label"></div>
|
|
1394
|
-
</div>
|
|
1395
|
-
</div>
|
|
1396
|
-
|
|
1397
|
-
<div class="skeleton sk-title-md"></div>
|
|
1398
|
-
|
|
1399
|
-
<div class="table-header">
|
|
1400
|
-
<div class="skeleton sk-th col-user"></div>
|
|
1401
|
-
<div class="skeleton sk-th col-status"></div>
|
|
1402
|
-
<div class="skeleton sk-th col-reward"></div>
|
|
1403
|
-
<div class="skeleton sk-th col-date"></div>
|
|
1404
|
-
</div>
|
|
1405
|
-
|
|
1406
|
-
<div class="table-row">
|
|
1407
|
-
<div class="col-user">
|
|
1408
|
-
<div class="skeleton sk-text" style="width: 70%; margin: 0"></div>
|
|
1409
|
-
</div>
|
|
1410
|
-
<div class="col-status">
|
|
1411
|
-
<div class="skeleton sk-badge" style="margin: 0"></div>
|
|
1412
|
-
</div>
|
|
1413
|
-
<div class="col-reward">
|
|
1414
|
-
<div class="skeleton sk-reward-block" style="margin: 0"></div>
|
|
1415
|
-
</div>
|
|
1416
|
-
<div class="col-date">
|
|
1417
|
-
<div class="skeleton sk-text" style="width: 80%; margin: 0"></div>
|
|
1418
|
-
</div>
|
|
1419
|
-
</div>
|
|
1420
|
-
<div class="table-row">
|
|
1421
|
-
<div class="col-user">
|
|
1422
|
-
<div class="skeleton sk-text" style="width: 60%; margin: 0"></div>
|
|
1423
|
-
</div>
|
|
1424
|
-
<div class="col-status">
|
|
1425
|
-
<div class="skeleton sk-badge" style="margin: 0"></div>
|
|
1426
|
-
</div>
|
|
1427
|
-
<div class="col-reward">
|
|
1428
|
-
<div class="skeleton sk-reward-block" style="margin: 0"></div>
|
|
1429
|
-
</div>
|
|
1430
|
-
<div class="col-date">
|
|
1431
|
-
<div class="skeleton sk-text" style="width: 80%; margin: 0"></div>
|
|
1432
|
-
</div>
|
|
1433
|
-
</div>
|
|
1434
|
-
<div class="table-row">
|
|
1435
|
-
<div class="col-user">
|
|
1436
|
-
<div class="skeleton sk-text" style="width: 75%; margin: 0"></div>
|
|
1437
|
-
</div>
|
|
1438
|
-
<div class="col-status">
|
|
1439
|
-
<div class="skeleton sk-badge" style="margin: 0"></div>
|
|
1440
|
-
</div>
|
|
1441
|
-
<div class="col-reward">
|
|
1442
|
-
<div class="skeleton sk-reward-block" style="margin: 0"></div>
|
|
1443
|
-
</div>
|
|
1444
|
-
<div class="col-date">
|
|
1445
|
-
<div class="skeleton sk-text" style="width: 80%; margin: 0"></div>
|
|
1446
|
-
</div>
|
|
1447
|
-
</div>
|
|
48
|
+
</html>`}async _findInnerContainer(t){const{contentWindow:e}=t;if(!e)throw new Error("Squatch.js frame inner frame is empty");const i=e.document;function n(){const r=i.getElementsByTagName("sqh-global-container"),a=i.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=n(),!s);r++)await Ue(100);return s||i.body}reload({email:t,firstName:e,lastName:i},n){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 c;if(this.context.type==="upsert"){if(!this.context.user)throw new Error("Can't reload without user ids");let d={email:t||null,firstName:e||null,lastName:i||null,id:this.context.user.id,accountId:this.context.user.accountId};c=this.widgetApi.upsertUser({user:d,engagementMedium:a,widgetType:this.type,jwt:n})}else if(this.context.type==="passwordless")c=this.widgetApi.render({user:void 0,engagementMedium:a,widgetType:this.type,jwt:void 0});else throw new Error("can't reload an error widget");c.then(({template:d})=>{d&&(this.content=d,this.__deprecated__register(s,{email:t,engagementMedium:a},()=>{this.load(),a==="POPUP"&&this.open()}))}).catch(({message:d})=>{w(`${d}`)})}__deprecated__register(t,e,i){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 c=e.engagementMedium==="POPUP"?"margin-top: 10px; max-width: 130px; width: 100%;":"margin-top: 10px;";r.setAttribute("style",c),r.onclick=i,a.style.paddingTop="30px",a.innerHTML=`<p><strong>${e.email}</strong><br>Has been successfully registered</p>`,a.appendChild(r)}}}function Ue(o){return new Promise(t=>{setTimeout(t,o)})}const b=E("squatch-js:EMBEDwidget");class x extends le{constructor(e,i){super(e);l(this,"show",this.open);l(this,"hide",this.close);i&&(this.container=i)}async load(){var p,m,g,f,_,C,te;const e=(m=(p=this.context.widgetConfig)==null?void 0:p.values)==null?void 0:m.brandingConfig,i=e==null?void 0:e.loadingHeight,n=(g=e==null?void 0:e.widgetSize)==null?void 0:g.embeddedWidgets,s=n!=null&&n.maxWidth?D(n.maxWidth):"",r=n!=null&&n.minWidth?D(n.minWidth):"",a=this._createFrame({minWidth:r,maxWidth:s,initialHeight:i}),c=this._findElement();(f=this.context)!=null&&f.container&&(c.style.visibility="hidden",c.style.height="0",c.style["overflow-y"]="hidden"),this.container?c.shadowRoot?((_=c.shadowRoot.lastChild)==null?void 0:_.nodeName)==="IFRAME"?c.shadowRoot.replaceChild(a,c.shadowRoot.lastChild):c.shadowRoot.appendChild(a):c.firstChild?c.replaceChild(a,c.firstChild):c.appendChild(a):(!c.firstChild||c.firstChild.nodeName==="#text")&&c.appendChild(a);const{contentWindow:d}=a;if(!d)throw new Error("Frame needs a content window");const h=d.document;h.open();const u=this.widgetApi.domain;h.write(`
|
|
49
|
+
${(C=e==null?void 0:e.main)!=null&&C.brandFont?`
|
|
50
|
+
<link rel="preconnect" href="https://fast${u==="https://staging.referralsaasquatch.com"&&"-staging"}.ssqt.io">
|
|
51
|
+
<link rel="preconnect" href="https://fonts.gstatic.com">
|
|
52
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
53
|
+
<link rel="preload" href="https://fonts.googleapis.com/css2?family=${encodeURIComponent((te=e==null?void 0:e.main)==null?void 0:te.brandFont)}" as="style">`:""}
|
|
54
|
+
<link rel="dns-prefetch" href="https://res.cloudinary.com">
|
|
55
|
+
<link rel="preconnect" href="https://res.cloudinary.com" crossorigin>
|
|
56
|
+
<style data-styles>
|
|
57
|
+
html { visibility:hidden;}
|
|
58
|
+
</style>
|
|
59
|
+
${this.content}
|
|
1448
60
|
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
</div>
|
|
1453
|
-
</div>
|
|
1454
|
-
`;
|
|
1455
|
-
};
|
|
1456
|
-
const _log$7 = browserExports.debug("squatch-js:EMBEDwidget");
|
|
1457
|
-
class EmbedWidget extends Widget {
|
|
1458
|
-
constructor(params, container) {
|
|
1459
|
-
super(params);
|
|
1460
|
-
__publicField(this, "show", this.open);
|
|
1461
|
-
__publicField(this, "hide", this.close);
|
|
1462
|
-
if (container) {
|
|
1463
|
-
this.container = container;
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
async load() {
|
|
1467
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1468
|
-
const brandingConfig = (_b = (_a2 = this.context.widgetConfig) == null ? void 0 : _a2.values) == null ? void 0 : _b.brandingConfig;
|
|
1469
|
-
const initialHeight = brandingConfig == null ? void 0 : brandingConfig.loadingHeight;
|
|
1470
|
-
const skeletonBackgroundColor = (_d = (_c = brandingConfig == null ? void 0 : brandingConfig.color) == null ? void 0 : _c.loadingSkeleton) == null ? void 0 : _d.background;
|
|
1471
|
-
const skeletonShimmerColor = (_f = (_e = brandingConfig == null ? void 0 : brandingConfig.color) == null ? void 0 : _e.loadingSkeleton) == null ? void 0 : _f.animationBackground;
|
|
1472
|
-
const borderColor = (_g = brandingConfig == null ? void 0 : brandingConfig.border) == null ? void 0 : _g.borderColor;
|
|
1473
|
-
const sizes = (_h = brandingConfig == null ? void 0 : brandingConfig.widgetSize) == null ? void 0 : _h.embeddedWidgets;
|
|
1474
|
-
const maxWidth = (sizes == null ? void 0 : sizes.maxWidth) ? formatWidth(sizes.maxWidth) : "";
|
|
1475
|
-
const minWidth = (sizes == null ? void 0 : sizes.minWidth) ? formatWidth(sizes.minWidth) : "";
|
|
1476
|
-
console.log({
|
|
1477
|
-
brandingConfig,
|
|
1478
|
-
initialHeight,
|
|
1479
|
-
widgetConfig: this.context.widgetConfig
|
|
1480
|
-
});
|
|
1481
|
-
const skeletonHTML = getSkeleton({
|
|
1482
|
-
height: initialHeight,
|
|
1483
|
-
skeletonBackgroundColor,
|
|
1484
|
-
skeletonShimmerColor,
|
|
1485
|
-
borderColor
|
|
1486
|
-
});
|
|
1487
|
-
const skeletonContainer = document.createElement("div");
|
|
1488
|
-
skeletonContainer.innerHTML = skeletonHTML;
|
|
1489
|
-
const frame = this._createFrame({
|
|
1490
|
-
minWidth,
|
|
1491
|
-
maxWidth,
|
|
1492
|
-
initialHeight
|
|
1493
|
-
});
|
|
1494
|
-
const element = this._findElement();
|
|
1495
|
-
element.innerHTML = skeletonHTML;
|
|
1496
|
-
frame.style.display = "none";
|
|
1497
|
-
const injectContents = (target) => {
|
|
1498
|
-
target.appendChild(skeletonContainer);
|
|
1499
|
-
target.appendChild(frame);
|
|
1500
|
-
};
|
|
1501
|
-
if ((_i = this.context) == null ? void 0 : _i.container) {
|
|
1502
|
-
element.style.visibility = "hidden";
|
|
1503
|
-
element.style.height = "0";
|
|
1504
|
-
element.style["overflow-y"] = "hidden";
|
|
1505
|
-
}
|
|
1506
|
-
if (this.container) {
|
|
1507
|
-
if (element.shadowRoot) {
|
|
1508
|
-
if (((_j = element.shadowRoot.lastChild) == null ? void 0 : _j.nodeName) === "IFRAME") {
|
|
1509
|
-
element.shadowRoot.replaceChild(frame, element.shadowRoot.lastChild);
|
|
1510
|
-
} else {
|
|
1511
|
-
injectContents(element.shadowRoot);
|
|
1512
|
-
}
|
|
1513
|
-
} else if (element.firstChild) {
|
|
1514
|
-
element.innerHTML = "";
|
|
1515
|
-
injectContents(element);
|
|
1516
|
-
} else {
|
|
1517
|
-
injectContents(element);
|
|
1518
|
-
}
|
|
1519
|
-
} else if (!element.firstChild || element.firstChild.nodeName === "#text") {
|
|
1520
|
-
injectContents(element);
|
|
1521
|
-
}
|
|
1522
|
-
const { contentWindow } = frame;
|
|
1523
|
-
if (!contentWindow) {
|
|
1524
|
-
throw new Error("Frame needs a content window");
|
|
1525
|
-
}
|
|
1526
|
-
const frameDoc = contentWindow.document;
|
|
1527
|
-
frameDoc.open();
|
|
1528
|
-
console.log({ content: this.content, context: this.context, this: this });
|
|
1529
|
-
const domain = this.widgetApi.domain;
|
|
1530
|
-
frameDoc.write(`
|
|
1531
|
-
${((_k = brandingConfig == null ? void 0 : brandingConfig.main) == null ? void 0 : _k.brandFont) && `
|
|
1532
|
-
<link rel="preconnect" href="https://fast${domain === "https://staging.referralsaasquatch.com" && "-staging"}.ssqt.io">
|
|
61
|
+
`),h.close(),Y(h,async()=>{const ne=d.squatch||d.widgetIdent;a.height=i||h.body.scrollHeight;const me=new ResizeObserver(fe=>{for(const we of fe){const{height:ye}=we.contentRect;a.height=ye}}),ge=await this._findInnerContainer(a);me.observe(ge),this._shouldFireLoadEvent()?(this._loadEvent(ne),b("loaded")):h&&this._attachLoadEventListener(h,ne)})}open(){const e=this._findFrame();if(!e)return b("no target element to open");if(!e.contentWindow)return b("Frame needs a content window");const i=this._findElement();i.style.visibility="unset",i.style.height="auto",i.style["overflow-y"]="auto",e.contentWindow.document.dispatchEvent(new CustomEvent("sq:refresh"));const n=e.contentWindow.squatch||e.contentWindow.widgetIdent;if(this.context.user)this._loadEvent(n),b("loaded");else{if(!e.contentDocument)return;this._attachLoadEventListener(e.contentDocument,n)}}close(){const e=this._findFrame();if(!e)return b("no target element to close");e.contentDocument&&this._detachLoadEventListener(e.contentDocument);const i=this._findElement();i.style.visibility="hidden",i.style.height="0",i.style["overflow-y"]="hidden",b("Embed widget closed")}_error(e,i="embed",n=""){return super._error(e,i,n)}_shouldFireLoadEvent(){const e=!this.container,i=this.container instanceof HTMLElement&&(this.container.tagName.startsWith("SQUATCH-")||this.container.tagName.startsWith("IMPACT-"));return!!this.context.user&&(e||i)}}const k=E("squatch-js:POPUPwidget");let M=0;class q extends le{constructor(e,i=".squatchpop"){super(e);l(this,"trigger");l(this,"id");l(this,"show",this.open);l(this,"hide",this.close);this.trigger=i,this.container?this.id="squatchModal":(this.id=M===0?"squatchModal":`squatchModal__${M}`,M=M+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&&k("No element found with trigger selector",this.trigger)}catch{k("Not a valid selector",this.trigger)}e&&(e.onclick=()=>{this.open()})}_createPopupDialog(e){var c;const i=document.createElement("dialog"),n=(c=e==null?void 0:e.widgetSize)==null?void 0:c.popupWidgets,s=n!=null&&n.minWidth?D(n.minWidth):"auto",r=n!=null&&n.maxWidth?D(n.maxWidth):"500px";i.id=this.id,i.setAttribute("style",`width: 100%; min-width: ${s}; max-width: ${r}; border: none; padding: 0;`);const a=d=>{d.stopPropagation(),d.target===i&&i.close()};return i.addEventListener("click",a),i}async load(){var u,p,m,g,f;const e=(p=(u=this.context.widgetConfig)==null?void 0:u.values)==null?void 0:p.brandingConfig,i=e==null?void 0:e.loadingHeight,n=this._createFrame({initialHeight:i});this._initialiseCTA();const s=this.container?this._findElement():document.body,r=s.shadowRoot||s,a=this._createPopupDialog(e);a.appendChild(n),((m=r.lastChild)==null?void 0:m.nodeName)==="DIALOG"?r.replaceChild(a,r.lastChild):r.appendChild(a);const{contentWindow:c}=n;if(!c)throw new Error("Frame needs a content window");const d=c.document;d.open();const h=this.widgetApi.domain;d.write(`
|
|
62
|
+
${(g=e==null?void 0:e.main)!=null&&g.brandFont?`
|
|
63
|
+
<link rel="preconnect" href="https://fast${h==="https://staging.referralsaasquatch.com"&&"-staging"}.ssqt.io">
|
|
1533
64
|
<link rel="preconnect" href="https://fonts.gstatic.com">
|
|
1534
65
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
1535
|
-
<link rel="preload" href="https://fonts.googleapis.com/css2?family=${encodeURIComponent(
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>
|
|
66
|
+
<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">`:""}
|
|
67
|
+
<link rel="dns-prefetch" href="https://res.cloudinary.com">
|
|
68
|
+
<link rel="preconnect" href="https://res.cloudinary.com" crossorigin>
|
|
1539
69
|
<style data-styles>
|
|
1540
70
|
html { visibility:hidden;}
|
|
1541
71
|
</style>
|
|
1542
72
|
${this.content}
|
|
1543
73
|
|
|
1544
|
-
`);
|
|
1545
|
-
frameDoc.close();
|
|
1546
|
-
domready(frameDoc, async () => {
|
|
1547
|
-
if (skeletonContainer && skeletonContainer.parentNode) {
|
|
1548
|
-
skeletonContainer.parentNode.removeChild(skeletonContainer);
|
|
1549
|
-
}
|
|
1550
|
-
frame.style.display = "block";
|
|
1551
|
-
const _sqh = contentWindow.squatch || contentWindow.widgetIdent;
|
|
1552
|
-
frame.height = initialHeight || frameDoc.body.scrollHeight;
|
|
1553
|
-
console.log({ height: frameDoc.body.scrollHeight });
|
|
1554
|
-
const ro = new contentWindow["ResizeObserver"]((entries) => {
|
|
1555
|
-
for (const entry of entries) {
|
|
1556
|
-
const { height } = entry.contentRect;
|
|
1557
|
-
frame.height = height;
|
|
1558
|
-
}
|
|
1559
|
-
});
|
|
1560
|
-
const container = await this._findInnerContainer(frame);
|
|
1561
|
-
ro.observe(container);
|
|
1562
|
-
if (this._shouldFireLoadEvent()) {
|
|
1563
|
-
this._loadEvent(_sqh);
|
|
1564
|
-
_log$7("loaded");
|
|
1565
|
-
} else if (frameDoc) {
|
|
1566
|
-
this._attachLoadEventListener(frameDoc, _sqh);
|
|
1567
|
-
}
|
|
1568
|
-
});
|
|
1569
|
-
}
|
|
1570
|
-
/**
|
|
1571
|
-
* Un-hide if element is available and refresh data
|
|
1572
|
-
*/
|
|
1573
|
-
open() {
|
|
1574
|
-
const frame = this._findFrame();
|
|
1575
|
-
if (!frame) return _log$7("no target element to open");
|
|
1576
|
-
if (!frame.contentWindow) return _log$7("Frame needs a content window");
|
|
1577
|
-
const element = this._findElement();
|
|
1578
|
-
element.style.visibility = "unset";
|
|
1579
|
-
element.style.height = "auto";
|
|
1580
|
-
element.style["overflow-y"] = "auto";
|
|
1581
|
-
frame.contentWindow.document.dispatchEvent(new CustomEvent("sq:refresh"));
|
|
1582
|
-
const _sqh = frame.contentWindow.squatch || frame.contentWindow.widgetIdent;
|
|
1583
|
-
if (this.context.user) {
|
|
1584
|
-
this._loadEvent(_sqh);
|
|
1585
|
-
_log$7("loaded");
|
|
1586
|
-
} else {
|
|
1587
|
-
if (!frame.contentDocument) return;
|
|
1588
|
-
this._attachLoadEventListener(frame.contentDocument, _sqh);
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
close() {
|
|
1592
|
-
const frame = this._findFrame();
|
|
1593
|
-
if (!frame) return _log$7("no target element to close");
|
|
1594
|
-
if (frame.contentDocument)
|
|
1595
|
-
this._detachLoadEventListener(frame.contentDocument);
|
|
1596
|
-
const element = this._findElement();
|
|
1597
|
-
element.style.visibility = "hidden";
|
|
1598
|
-
element.style.height = "0";
|
|
1599
|
-
element.style["overflow-y"] = "hidden";
|
|
1600
|
-
_log$7("Embed widget closed");
|
|
1601
|
-
}
|
|
1602
|
-
_error(rs, mode = "embed", style = "") {
|
|
1603
|
-
return super._error(rs, mode, style);
|
|
1604
|
-
}
|
|
1605
|
-
_shouldFireLoadEvent() {
|
|
1606
|
-
const noContainer = !this.container;
|
|
1607
|
-
const isComponent = this.container instanceof HTMLElement && (this.container.tagName.startsWith("SQUATCH-") || this.container.tagName.startsWith("IMPACT-"));
|
|
1608
|
-
const isVerified = !!this.context.user;
|
|
1609
|
-
return isVerified && (noContainer || isComponent);
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
const _log$6 = browserExports.debug("squatch-js:POPUPwidget");
|
|
1613
|
-
let popupId = 0;
|
|
1614
|
-
class PopupWidget extends Widget {
|
|
1615
|
-
constructor(params, trigger = ".squatchpop") {
|
|
1616
|
-
super(params);
|
|
1617
|
-
__publicField(this, "trigger");
|
|
1618
|
-
__publicField(this, "id");
|
|
1619
|
-
__publicField(this, "show", this.open);
|
|
1620
|
-
__publicField(this, "hide", this.close);
|
|
1621
|
-
this.trigger = trigger;
|
|
1622
|
-
if (this.container) {
|
|
1623
|
-
this.id = "squatchModal";
|
|
1624
|
-
} else {
|
|
1625
|
-
this.id = popupId === 0 ? `squatchModal` : `squatchModal__${popupId}`;
|
|
1626
|
-
popupId = popupId + 1;
|
|
1627
|
-
}
|
|
1628
|
-
document.head.insertAdjacentHTML(
|
|
1629
|
-
"beforeend",
|
|
1630
|
-
`<style>#${this.id}::-webkit-scrollbar { display: none; }</style>`
|
|
1631
|
-
);
|
|
1632
|
-
}
|
|
1633
|
-
_initialiseCTA() {
|
|
1634
|
-
if (!this.trigger) return;
|
|
1635
|
-
let triggerElement;
|
|
1636
|
-
try {
|
|
1637
|
-
triggerElement = document.querySelector(this.trigger) || document.querySelector(".impactpop");
|
|
1638
|
-
if (this.trigger && !triggerElement)
|
|
1639
|
-
_log$6("No element found with trigger selector", this.trigger);
|
|
1640
|
-
} catch {
|
|
1641
|
-
_log$6("Not a valid selector", this.trigger);
|
|
1642
|
-
}
|
|
1643
|
-
if (triggerElement) {
|
|
1644
|
-
triggerElement.onclick = () => {
|
|
1645
|
-
this.open();
|
|
1646
|
-
};
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
_createPopupDialog() {
|
|
1650
|
-
var _a2, _b, _c;
|
|
1651
|
-
const dialog = document.createElement("dialog");
|
|
1652
|
-
const brandingConfig = (_b = (_a2 = this.context.widgetConfig) == null ? void 0 : _a2.values) == null ? void 0 : _b.brandingConfig;
|
|
1653
|
-
const sizes = (_c = brandingConfig == null ? void 0 : brandingConfig.widgetSize) == null ? void 0 : _c.popupWidgets;
|
|
1654
|
-
const minWidth = (sizes == null ? void 0 : sizes.minWidth) ? formatWidth(sizes.minWidth) : "auto";
|
|
1655
|
-
const maxWidth = (sizes == null ? void 0 : sizes.maxWidth) ? formatWidth(sizes.maxWidth) : "500px";
|
|
1656
|
-
dialog.id = this.id;
|
|
1657
|
-
dialog.setAttribute(
|
|
1658
|
-
"style",
|
|
1659
|
-
`width: 100%; min-width: ${minWidth}; max-width: ${maxWidth}; border: none; padding: 0;`
|
|
1660
|
-
);
|
|
1661
|
-
const onClick = (e) => {
|
|
1662
|
-
e.stopPropagation();
|
|
1663
|
-
if (e.target === dialog) dialog.close();
|
|
1664
|
-
};
|
|
1665
|
-
dialog.addEventListener("click", onClick);
|
|
1666
|
-
return dialog;
|
|
1667
|
-
}
|
|
1668
|
-
async load() {
|
|
1669
|
-
var _a2;
|
|
1670
|
-
const frame = this._createFrame();
|
|
1671
|
-
this._initialiseCTA();
|
|
1672
|
-
const element = this.container ? this._findElement() : document.body;
|
|
1673
|
-
const dialogParent = element.shadowRoot || element;
|
|
1674
|
-
const dialog = this._createPopupDialog();
|
|
1675
|
-
dialog.appendChild(frame);
|
|
1676
|
-
if (((_a2 = dialogParent.lastChild) == null ? void 0 : _a2.nodeName) === "DIALOG") {
|
|
1677
|
-
dialogParent.replaceChild(dialog, dialogParent.lastChild);
|
|
1678
|
-
} else {
|
|
1679
|
-
dialogParent.appendChild(dialog);
|
|
1680
|
-
}
|
|
1681
|
-
const { contentWindow } = frame;
|
|
1682
|
-
if (!contentWindow) {
|
|
1683
|
-
throw new Error("Frame needs a content window");
|
|
1684
|
-
}
|
|
1685
|
-
const frameDoc = contentWindow.document;
|
|
1686
|
-
frameDoc.open();
|
|
1687
|
-
frameDoc.write(this.content);
|
|
1688
|
-
frameDoc.write(
|
|
1689
|
-
`<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>`
|
|
1690
|
-
);
|
|
1691
|
-
frameDoc.close();
|
|
1692
|
-
_log$6("Popup template loaded into iframe");
|
|
1693
|
-
await this._setupResizeHandler(frame);
|
|
1694
|
-
}
|
|
1695
|
-
async _setupResizeHandler(frame) {
|
|
1696
|
-
const { contentWindow } = frame;
|
|
1697
|
-
if (!contentWindow) {
|
|
1698
|
-
throw new Error("Frame needs a content window");
|
|
1699
|
-
}
|
|
1700
|
-
const frameDoc = contentWindow.document;
|
|
1701
|
-
domready(frameDoc, async () => {
|
|
1702
|
-
frameDoc.body.style.overflowY = "hidden";
|
|
1703
|
-
frame.height = `${frameDoc.body.offsetHeight}px`;
|
|
1704
|
-
const ro = new contentWindow["ResizeObserver"]((entries) => {
|
|
1705
|
-
for (const entry of entries) {
|
|
1706
|
-
const { top, bottom } = entry.contentRect;
|
|
1707
|
-
const computedHeight = bottom + top;
|
|
1708
|
-
frame.height = computedHeight + "";
|
|
1709
|
-
entry.target.style = ``;
|
|
1710
|
-
}
|
|
1711
|
-
});
|
|
1712
|
-
ro.observe(await this._findInnerContainer(frame));
|
|
1713
|
-
});
|
|
1714
|
-
}
|
|
1715
|
-
open() {
|
|
1716
|
-
const element = this.container ? this._findElement() : document.body;
|
|
1717
|
-
const parent = element.shadowRoot || element;
|
|
1718
|
-
const dialog = parent.querySelector(`#${this.id}`);
|
|
1719
|
-
if (!dialog) throw new Error("Could not determine container div");
|
|
1720
|
-
dialog.showModal();
|
|
1721
|
-
const frame = this._findFrame();
|
|
1722
|
-
if (!frame) throw new Error("Could not find iframe");
|
|
1723
|
-
const { contentWindow } = frame;
|
|
1724
|
-
if (!contentWindow) throw new Error("Squatch.js has an empty iframe");
|
|
1725
|
-
const frameDoc = contentWindow.document;
|
|
1726
|
-
domready(frameDoc, () => {
|
|
1727
|
-
var _a2;
|
|
1728
|
-
const _sqh = contentWindow.squatch || contentWindow.widgetIdent;
|
|
1729
|
-
(_a2 = frame.contentDocument) == null ? void 0 : _a2.dispatchEvent(new CustomEvent("sq:refresh"));
|
|
1730
|
-
if (this.context.user) {
|
|
1731
|
-
this._loadEvent(_sqh);
|
|
1732
|
-
_log$6("Popup opened");
|
|
1733
|
-
} else {
|
|
1734
|
-
this._attachLoadEventListener(frameDoc, _sqh);
|
|
1735
|
-
}
|
|
1736
|
-
});
|
|
1737
|
-
}
|
|
1738
|
-
close() {
|
|
1739
|
-
const frame = this._findFrame();
|
|
1740
|
-
if (frame == null ? void 0 : frame.contentDocument)
|
|
1741
|
-
this._detachLoadEventListener(frame.contentDocument);
|
|
1742
|
-
const element = this.container ? this._findElement() : document.body;
|
|
1743
|
-
const parent = element.shadowRoot || element;
|
|
1744
|
-
const dialog = parent.querySelector(`#${this.id}`);
|
|
1745
|
-
if (!dialog) throw new Error("Could not determine container div");
|
|
1746
|
-
dialog.close();
|
|
1747
|
-
_log$6("Popup closed");
|
|
1748
|
-
}
|
|
1749
|
-
_clickedOutside({ target }) {
|
|
1750
|
-
}
|
|
1751
|
-
_error(rs, mode = "modal", style = "") {
|
|
1752
|
-
const _style = "body { margin: 0; } .modal { box-shadow: none; border: 0; }";
|
|
1753
|
-
return super._error(rs, mode, style || _style);
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
const _log$5 = browserExports.debug("squatch-js:widgets");
|
|
1757
|
-
class Widgets {
|
|
1758
|
-
/**
|
|
1759
|
-
* Initialize a new {@link Widgets} instance.
|
|
1760
|
-
*
|
|
1761
|
-
* @param {ConfigOptions} config Config details
|
|
1762
|
-
*
|
|
1763
|
-
* @example <caption>Browser example</caption>
|
|
1764
|
-
* var widgets = new squatch.Widgets({tenantAlias:'test_12b5bo1b25125'});
|
|
1765
|
-
*
|
|
1766
|
-
* @example <caption>Browserify/Webpack example</caption>
|
|
1767
|
-
* var Widgets = require('@saasquatch/squatch-js').Widgets;
|
|
1768
|
-
* var widgets = new Widgets({tenantAlias:'test_12b5bo1b25125'});
|
|
1769
|
-
*
|
|
1770
|
-
* @example <caption>Babel+Browserify/Webpack example</caption>
|
|
1771
|
-
* import {Widgets} from '@saasquatch/squatch-js';
|
|
1772
|
-
* let widgets = new Widgets({tenantAlias:'test_12b5bo1b25125'});
|
|
1773
|
-
*/
|
|
1774
|
-
constructor(configin) {
|
|
1775
|
-
/**
|
|
1776
|
-
* Instance of {@link WidgetApi}
|
|
1777
|
-
*/
|
|
1778
|
-
__publicField(this, "api");
|
|
1779
|
-
/**
|
|
1780
|
-
* Tenant alias of SaaSquatch tenant
|
|
1781
|
-
*/
|
|
1782
|
-
__publicField(this, "tenantAlias");
|
|
1783
|
-
/**
|
|
1784
|
-
* SaaSquatch domain for API requests
|
|
1785
|
-
* @default "https://app.referralsaasquatch.com"
|
|
1786
|
-
*/
|
|
1787
|
-
__publicField(this, "domain");
|
|
1788
|
-
/**
|
|
1789
|
-
* Hosted CDN for npm packages
|
|
1790
|
-
* @default "https://fast.ssqt.io/npm"
|
|
1791
|
-
*/
|
|
1792
|
-
__publicField(this, "npmCdn");
|
|
1793
|
-
const config = validateConfig(configin);
|
|
1794
|
-
this.tenantAlias = config.tenantAlias;
|
|
1795
|
-
this.domain = config.domain;
|
|
1796
|
-
this.npmCdn = config.npmCdn;
|
|
1797
|
-
this.api = new WidgetApi(config);
|
|
1798
|
-
}
|
|
1799
|
-
/**
|
|
1800
|
-
* This function calls the {@link WidgetApi.upsertUser} method, and it renders
|
|
1801
|
-
* the widget if it is successful. Otherwise it shows the "error" widget.
|
|
1802
|
-
*
|
|
1803
|
-
* @param {Object} config Config details
|
|
1804
|
-
* @param {Object} config.user The user details
|
|
1805
|
-
* @param {string} config.user.id The user id
|
|
1806
|
-
* @param {string} config.user.accountId The user account id
|
|
1807
|
-
* @param {WidgetType} config.widgetType The content of the widget
|
|
1808
|
-
* @param {EngagementMedium} config.engagementMedium How to display the widget
|
|
1809
|
-
* @param {string} config.jwt the JSON Web Token (JWT) that is used to validate the data (can be disabled)
|
|
1810
|
-
* @param {HTMLElement | string | undefined} config.container Element to load the widget into
|
|
1811
|
-
* @param {string | undefined} config.trigger Trigger element for opening the popup widget
|
|
1812
|
-
*
|
|
1813
|
-
* @return {Promise<WidgetResult>} json object if true, with a Widget and user details
|
|
1814
|
-
*/
|
|
1815
|
-
async upsertUser(config) {
|
|
1816
|
-
const raw = config;
|
|
1817
|
-
const clean = validateWidgetConfig(raw);
|
|
1818
|
-
try {
|
|
1819
|
-
const response = await this.api.upsertUser(clean);
|
|
1820
|
-
return {
|
|
1821
|
-
widget: this._renderWidget(response, clean, {
|
|
1822
|
-
type: "upsert",
|
|
1823
|
-
user: clean.user,
|
|
1824
|
-
engagementMedium: config.engagementMedium,
|
|
1825
|
-
container: config.container,
|
|
1826
|
-
trigger: config.trigger,
|
|
1827
|
-
widgetConfig: {
|
|
1828
|
-
values: {
|
|
1829
|
-
brandingConfig: response == null ? void 0 : response.brandingConfig
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
}),
|
|
1833
|
-
user: response.user
|
|
1834
|
-
};
|
|
1835
|
-
} catch (err) {
|
|
1836
|
-
_log$5(err);
|
|
1837
|
-
if (err.apiErrorCode) {
|
|
1838
|
-
this._renderErrorWidget(err, config.engagementMedium);
|
|
1839
|
-
}
|
|
1840
|
-
throw new Error(err);
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
/**
|
|
1844
|
-
* This function calls the {@link WidgetApi.render} method, and it renders
|
|
1845
|
-
* the widget if it is successful. Otherwise it shows the "error" widget.
|
|
1846
|
-
*
|
|
1847
|
-
* @param {Object} config Config details
|
|
1848
|
-
* @param {Object} config.user The user details
|
|
1849
|
-
* @param {string} config.user.id The user id
|
|
1850
|
-
* @param {string} config.user.accountId The user account id
|
|
1851
|
-
* @param {WidgetType} config.widgetType The content of the widget
|
|
1852
|
-
* @param {EngagementMedium} config.engagementMedium How to display the widget
|
|
1853
|
-
* @param {string} config.jwt the JSON Web Token (JWT) that is used
|
|
1854
|
-
* to validate the data (can be disabled)
|
|
1855
|
-
*
|
|
1856
|
-
* @return {Promise<WidgetResult>} json object if true, with a Widget and user details
|
|
1857
|
-
*/
|
|
1858
|
-
async render(config) {
|
|
1859
|
-
const raw = config;
|
|
1860
|
-
const clean = validatePasswordlessConfig(raw);
|
|
1861
|
-
try {
|
|
1862
|
-
const response = await this.api.render(clean);
|
|
1863
|
-
return {
|
|
1864
|
-
widget: this._renderWidget(response, clean, {
|
|
1865
|
-
type: "passwordless",
|
|
1866
|
-
engagementMedium: clean.engagementMedium,
|
|
1867
|
-
container: clean.container,
|
|
1868
|
-
trigger: clean.trigger,
|
|
1869
|
-
widgetConfig: {
|
|
1870
|
-
values: {
|
|
1871
|
-
brandingConfig: response == null ? void 0 : response.brandingConfig
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
}),
|
|
1875
|
-
user: response.user
|
|
1876
|
-
};
|
|
1877
|
-
} catch (err) {
|
|
1878
|
-
if (err.apiErrorCode) {
|
|
1879
|
-
this._renderErrorWidget(err, clean.engagementMedium);
|
|
1880
|
-
}
|
|
1881
|
-
throw new Error(err);
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
/**
|
|
1885
|
-
* Autofills a referral code into an element when someone has been referred.
|
|
1886
|
-
* Uses {@link WidgetApi.squatchReferralCookie} behind the scenes.
|
|
1887
|
-
*
|
|
1888
|
-
* @param selector Element class/id selector, or a callback function
|
|
1889
|
-
* @returns
|
|
1890
|
-
*/
|
|
1891
|
-
async autofill(selector) {
|
|
1892
|
-
const input = selector;
|
|
1893
|
-
if (typeof input === "function") {
|
|
1894
|
-
try {
|
|
1895
|
-
const response = await this.api.squatchReferralCookie();
|
|
1896
|
-
input(response);
|
|
1897
|
-
} catch (e) {
|
|
1898
|
-
_log$5("Autofill error", e);
|
|
1899
|
-
throw new Error(e);
|
|
1900
|
-
}
|
|
1901
|
-
return;
|
|
1902
|
-
}
|
|
1903
|
-
if (typeof input !== "string")
|
|
1904
|
-
throw new Error("Autofill accepts a string or function");
|
|
1905
|
-
let elems = document.querySelectorAll(input);
|
|
1906
|
-
let elem;
|
|
1907
|
-
if (elems.length > 0) {
|
|
1908
|
-
elem = elems[0];
|
|
1909
|
-
} else {
|
|
1910
|
-
_log$5("Element id/class or function missing");
|
|
1911
|
-
throw new Error("Element id/class or function missing");
|
|
1912
|
-
}
|
|
1913
|
-
try {
|
|
1914
|
-
const response = await this.api.squatchReferralCookie();
|
|
1915
|
-
elem.value = response.codes[0];
|
|
1916
|
-
} catch (e) {
|
|
1917
|
-
throw new Error(e);
|
|
1918
|
-
}
|
|
1919
|
-
}
|
|
1920
|
-
/**
|
|
1921
|
-
* @hidden
|
|
1922
|
-
* @param {Object} response The json object return from the WidgetApi
|
|
1923
|
-
* @param {Object} config Config details
|
|
1924
|
-
* @param {string} config.widgetType The widget type (REFERRER_WIDGET, CONVERSION_WIDGET)
|
|
1925
|
-
* @param {string} config.engagementMedium (POPUP, EMBED)
|
|
1926
|
-
* @returns {Widget} widget (PopupWidget or EmbedWidget)
|
|
1927
|
-
*/
|
|
1928
|
-
_renderWidget(response, config, context) {
|
|
1929
|
-
var _a2;
|
|
1930
|
-
_log$5("Rendering Widget...");
|
|
1931
|
-
if (!response) throw new Error("Unable to get a response");
|
|
1932
|
-
let widget2;
|
|
1933
|
-
let displayOnLoad = !!config.displayOnLoad;
|
|
1934
|
-
const opts = response.jsOptions || {};
|
|
1935
|
-
const params = {
|
|
1936
|
-
content: response.template,
|
|
1937
|
-
type: config.widgetType || ((_a2 = opts.widget) == null ? void 0 : _a2.defaultWidgetType),
|
|
1938
|
-
api: this.api,
|
|
1939
|
-
domain: this.domain,
|
|
1940
|
-
npmCdn: this.npmCdn,
|
|
1941
|
-
context
|
|
1942
|
-
};
|
|
1943
|
-
if (opts.widgetUrlMappings) {
|
|
1944
|
-
opts.widgetUrlMappings.forEach((rule) => {
|
|
1945
|
-
var _a3, _b;
|
|
1946
|
-
if (Widgets._matchesUrl(rule.url)) {
|
|
1947
|
-
if (rule.widgetType !== "CONVERSION_WIDGET" || ((_b = (_a3 = response.user) == null ? void 0 : _a3.referredBy) == null ? void 0 : _b.code)) {
|
|
1948
|
-
displayOnLoad = rule.displayOnLoad;
|
|
1949
|
-
_log$5(`Display ${rule.widgetType} on ${rule.url}`);
|
|
1950
|
-
} else {
|
|
1951
|
-
_log$5(
|
|
1952
|
-
`Don't display ${rule.widgetType} when no referral on widget rule match ${rule.url}`
|
|
1953
|
-
);
|
|
1954
|
-
}
|
|
1955
|
-
}
|
|
1956
|
-
});
|
|
1957
|
-
}
|
|
1958
|
-
if (opts.fuelTankAutofillUrls) {
|
|
1959
|
-
_log$5("We found a fuel tank autofill!");
|
|
1960
|
-
opts.fuelTankAutofillUrls.forEach(({ url, formSelector }) => {
|
|
1961
|
-
var _a3, _b, _c;
|
|
1962
|
-
if (Widgets._matchesUrl(url)) {
|
|
1963
|
-
_log$5("Fuel Tank URL matches");
|
|
1964
|
-
if ((_b = (_a3 = response.user) == null ? void 0 : _a3.referredBy) == null ? void 0 : _b.code) {
|
|
1965
|
-
const formAutofill = document.querySelector(formSelector);
|
|
1966
|
-
if (formAutofill) {
|
|
1967
|
-
formAutofill.value = ((_c = response.user.referredBy.referredReward) == null ? void 0 : _c.fuelTankCode) || "";
|
|
1968
|
-
} else {
|
|
1969
|
-
_log$5(
|
|
1970
|
-
new Error(
|
|
1971
|
-
`Element with id/class ${formSelector} was not found.`
|
|
1972
|
-
)
|
|
1973
|
-
);
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
}
|
|
1977
|
-
});
|
|
1978
|
-
}
|
|
1979
|
-
if (config.engagementMedium === "EMBED") {
|
|
1980
|
-
widget2 = this._renderEmbedWidget(params);
|
|
1981
|
-
} else {
|
|
1982
|
-
widget2 = this._renderPopupWidget(params);
|
|
1983
|
-
if (displayOnLoad) widget2.open();
|
|
1984
|
-
}
|
|
1985
|
-
return widget2;
|
|
1986
|
-
}
|
|
1987
|
-
_renderPopupWidget(params) {
|
|
1988
|
-
const widget2 = new PopupWidget(params, params.context.trigger);
|
|
1989
|
-
widget2.load();
|
|
1990
|
-
return widget2;
|
|
1991
|
-
}
|
|
1992
|
-
_renderEmbedWidget(params) {
|
|
1993
|
-
const widget2 = new EmbedWidget(params, params.context.container);
|
|
1994
|
-
widget2.load();
|
|
1995
|
-
return widget2;
|
|
1996
|
-
}
|
|
1997
|
-
/**
|
|
1998
|
-
* @hidden
|
|
1999
|
-
* @param {Object} error The json object containing the error details
|
|
2000
|
-
* @param {string} em The engagementMedium
|
|
2001
|
-
* @returns {void}
|
|
2002
|
-
*/
|
|
2003
|
-
_renderErrorWidget(props, em = "POPUP") {
|
|
2004
|
-
const { apiErrorCode, rsCode, message } = props;
|
|
2005
|
-
_log$5(new Error(`${apiErrorCode} (${rsCode}) ${message}`));
|
|
2006
|
-
const params = {
|
|
2007
|
-
content: "error",
|
|
2008
|
-
rsCode,
|
|
2009
|
-
api: this.api,
|
|
2010
|
-
domain: this.domain,
|
|
2011
|
-
npmCdn: this.npmCdn,
|
|
2012
|
-
type: "ERROR_WIDGET",
|
|
2013
|
-
context: { type: "error" }
|
|
2014
|
-
};
|
|
2015
|
-
let widget2;
|
|
2016
|
-
if (em === "EMBED") {
|
|
2017
|
-
widget2 = new EmbedWidget(params);
|
|
2018
|
-
widget2.load();
|
|
2019
|
-
} else if (em === "POPUP") {
|
|
2020
|
-
widget2 = new PopupWidget(params);
|
|
2021
|
-
widget2.load();
|
|
2022
|
-
}
|
|
2023
|
-
}
|
|
2024
|
-
/**
|
|
2025
|
-
* @hidden
|
|
2026
|
-
* @param {string} rule A regular expression
|
|
2027
|
-
* @returns {boolean} true if rule matches Url, false otherwise
|
|
2028
|
-
*/
|
|
2029
|
-
static _matchesUrl(rule) {
|
|
2030
|
-
return window.location.href.match(new RegExp(rule)) ? true : false;
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2033
|
-
class EventsApi {
|
|
2034
|
-
/**
|
|
2035
|
-
* Initialize a new {@link EventsApi} instance.
|
|
2036
|
-
*
|
|
2037
|
-
* @param {ConfigOptions} config Config details
|
|
2038
|
-
*
|
|
2039
|
-
* @example <caption>Browser example</caption>
|
|
2040
|
-
* var squatchApi = new squatch.EventsApi({tenantAlias:'test_12b5bo1b25125'});
|
|
2041
|
-
*
|
|
2042
|
-
* @example <caption>Browserify/Webpack example</caption>
|
|
2043
|
-
* var EventsApi = require('@saasquatch/squatch-js').EventsApi;
|
|
2044
|
-
* var squatchApi = new EventsApi({tenantAlias:'test_12b5bo1b25125'});
|
|
2045
|
-
*
|
|
2046
|
-
* @example <caption>Babel+Browserify/Webpack example</caption>
|
|
2047
|
-
* import {EventsApi} from '@saasquatch/squatch-js';
|
|
2048
|
-
* let squatchApi = new EventsApi({tenantAlias:'test_12b5bo1b25125'});
|
|
2049
|
-
*/
|
|
2050
|
-
constructor(config) {
|
|
2051
|
-
__publicField(this, "tenantAlias");
|
|
2052
|
-
__publicField(this, "domain");
|
|
2053
|
-
const raw = config;
|
|
2054
|
-
const clean = validateConfig(raw);
|
|
2055
|
-
this.tenantAlias = clean.tenantAlias;
|
|
2056
|
-
this.domain = clean.domain;
|
|
2057
|
-
}
|
|
2058
|
-
/**
|
|
2059
|
-
* Track an event for a user
|
|
2060
|
-
*
|
|
2061
|
-
* @param params Parameters for request
|
|
2062
|
-
* @param options.jwt the JSON Web Token (JWT) that is used to authenticate the user
|
|
2063
|
-
*
|
|
2064
|
-
* @return An ID to confirm the event has been accepted for asynchronous processing
|
|
2065
|
-
*/
|
|
2066
|
-
track(params, options) {
|
|
2067
|
-
const raw = params;
|
|
2068
|
-
const rawOpts = options;
|
|
2069
|
-
const body = _validateEvent(raw);
|
|
2070
|
-
const { jwt } = _validateTrackOptions(rawOpts);
|
|
2071
|
-
const ta = encodeURIComponent(this.tenantAlias);
|
|
2072
|
-
const userId = encodeURIComponent(body.userId);
|
|
2073
|
-
const accountId = encodeURIComponent(body.accountId);
|
|
2074
|
-
const path = `/api/v1/${ta}/open/account/${accountId}/user/${userId}/events`;
|
|
2075
|
-
const url = this.domain + path;
|
|
2076
|
-
return doPost(url, JSON.stringify(body), jwt);
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
function _validateEvent(raw) {
|
|
2080
|
-
if (!isObject$1(raw)) throw new Error("tracking parameter must be an object");
|
|
2081
|
-
if (!(raw == null ? void 0 : raw["accountId"])) throw new Error("accountId field is required");
|
|
2082
|
-
if (!(raw == null ? void 0 : raw["events"])) throw new Error("events field is required");
|
|
2083
|
-
if (!(raw == null ? void 0 : raw["userId"])) throw new Error("userId field is required");
|
|
2084
|
-
const clean = raw;
|
|
2085
|
-
if (!Array.isArray(clean.events))
|
|
2086
|
-
throw new Error("'events' should be an array");
|
|
2087
|
-
return clean;
|
|
2088
|
-
}
|
|
2089
|
-
function _validateTrackOptions(raw) {
|
|
2090
|
-
if (!isObject$1(raw)) throw new Error("'options' should be an object");
|
|
2091
|
-
return raw;
|
|
2092
|
-
}
|
|
2093
|
-
function asyncLoad() {
|
|
2094
|
-
var _a2;
|
|
2095
|
-
const namespace = window[IMPACT_NAMESPACE] ? IMPACT_NAMESPACE : DEFAULT_NAMESPACE;
|
|
2096
|
-
const cached = ((_a2 = window["_" + namespace]) == null ? void 0 : _a2.ready) || [];
|
|
2097
|
-
const declarativeCache = window.impactOnReady || window.squatchOnReady;
|
|
2098
|
-
const readyFns = [...cached, declarativeCache].filter((a) => !!a);
|
|
2099
|
-
setTimeout(() => {
|
|
2100
|
-
if (!window[DEFAULT_NAMESPACE]) return;
|
|
2101
|
-
window[IMPACT_NAMESPACE] = window[DEFAULT_NAMESPACE];
|
|
2102
|
-
readyFns.forEach((cb) => cb());
|
|
2103
|
-
window[DEFAULT_NAMESPACE]._auto();
|
|
2104
|
-
window["_" + namespace] = void 0;
|
|
2105
|
-
delete window["_" + namespace];
|
|
2106
|
-
}, 0);
|
|
2107
|
-
}
|
|
2108
|
-
const _log$4 = browserExports.debug("squatch-js");
|
|
2109
|
-
const isObject = (item) => typeof item === "object" && !Array.isArray(item);
|
|
2110
|
-
const deepMerge = (target, source) => {
|
|
2111
|
-
const isDeep = (prop) => isObject(source[prop]) && target.hasOwnProperty(prop) && isObject(target[prop]);
|
|
2112
|
-
const replaced = Object.getOwnPropertyNames(source).map((prop) => ({
|
|
2113
|
-
[prop]: isDeep(prop) ? deepMerge(target[prop], source[prop]) : source[prop]
|
|
2114
|
-
})).reduce((a, b) => ({ ...a, ...b }), {});
|
|
2115
|
-
return {
|
|
2116
|
-
...target,
|
|
2117
|
-
...replaced
|
|
2118
|
-
};
|
|
2119
|
-
};
|
|
2120
|
-
function b64decode(input) {
|
|
2121
|
-
const binary = atob(input.replace(/_/g, "/").replace(/-/g, "+"));
|
|
2122
|
-
const bytes = new Uint8Array(binary.length);
|
|
2123
|
-
for (let i = 0; i < binary.length; i++) {
|
|
2124
|
-
bytes[i] = binary.charCodeAt(i);
|
|
2125
|
-
}
|
|
2126
|
-
return new TextDecoder("utf8").decode(bytes);
|
|
2127
|
-
}
|
|
2128
|
-
function b64encode(input) {
|
|
2129
|
-
const encodedInput = new TextEncoder().encode(input);
|
|
2130
|
-
const binary = Array.from(
|
|
2131
|
-
encodedInput,
|
|
2132
|
-
(byte) => String.fromCodePoint(byte)
|
|
2133
|
-
).join("");
|
|
2134
|
-
return btoa(binary).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
2135
|
-
}
|
|
2136
|
-
function getTopDomain() {
|
|
2137
|
-
var i, h, weird_cookie = "weird_get_top_level_domain=cookie", hostname = document.location.hostname.split(".");
|
|
2138
|
-
for (i = hostname.length - 1; i >= 0; i--) {
|
|
2139
|
-
h = hostname.slice(i).join(".");
|
|
2140
|
-
document.cookie = weird_cookie + ";domain=." + h + ";";
|
|
2141
|
-
if (document.cookie.indexOf(weird_cookie) > -1) {
|
|
2142
|
-
document.cookie = weird_cookie.split("=")[0] + "=;domain=." + h + ";expires=Thu, 01 Jan 1970 00:00:01 GMT;";
|
|
2143
|
-
return h;
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
function _pushCookie() {
|
|
2148
|
-
const queryString = window.location.search;
|
|
2149
|
-
const urlParams = new URLSearchParams(queryString);
|
|
2150
|
-
const refParam = urlParams.get("_saasquatch") || "";
|
|
2151
|
-
if (refParam) {
|
|
2152
|
-
let paramsJSON = "", existingCookie = "", reEncodedCookie = "";
|
|
2153
|
-
try {
|
|
2154
|
-
paramsJSON = JSON.parse(b64decode(refParam));
|
|
2155
|
-
} catch (error) {
|
|
2156
|
-
_log$4("Unable to decode params", error);
|
|
2157
|
-
return;
|
|
2158
|
-
}
|
|
2159
|
-
try {
|
|
2160
|
-
existingCookie = JSON.parse(b64decode(api$1.get("_saasquatch")));
|
|
2161
|
-
_log$4("existing cookie", existingCookie);
|
|
2162
|
-
} catch (error) {
|
|
2163
|
-
_log$4("Unable to retrieve cookie", error);
|
|
2164
|
-
}
|
|
2165
|
-
try {
|
|
2166
|
-
const domain = getTopDomain();
|
|
2167
|
-
_log$4("domain retrieved:", domain);
|
|
2168
|
-
if (existingCookie) {
|
|
2169
|
-
const newCookie = deepMerge(existingCookie, paramsJSON);
|
|
2170
|
-
reEncodedCookie = b64encode(JSON.stringify(newCookie));
|
|
2171
|
-
_log$4("cookie to store:", newCookie);
|
|
2172
|
-
} else {
|
|
2173
|
-
reEncodedCookie = b64encode(JSON.stringify(paramsJSON));
|
|
2174
|
-
_log$4("cookie to store:", paramsJSON);
|
|
2175
|
-
}
|
|
2176
|
-
api$1.set("_saasquatch", reEncodedCookie, {
|
|
2177
|
-
expires: 365,
|
|
2178
|
-
secure: false,
|
|
2179
|
-
sameSite: "Lax",
|
|
2180
|
-
domain,
|
|
2181
|
-
path: "/"
|
|
2182
|
-
});
|
|
2183
|
-
} catch (error) {
|
|
2184
|
-
_log$4("Unable to set cookie", error);
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2187
|
-
}
|
|
2188
|
-
const _log$3 = browserExports.debug("squatch-js");
|
|
2189
|
-
function _getAutoConfig() {
|
|
2190
|
-
var _a2;
|
|
2191
|
-
const queryString = window.location.search;
|
|
2192
|
-
const urlParams = new URLSearchParams(queryString);
|
|
2193
|
-
const refParam = urlParams.get("_saasquatchExtra") || "";
|
|
2194
|
-
if (!refParam) {
|
|
2195
|
-
_log$3("No _saasquatchExtra param");
|
|
2196
|
-
return;
|
|
2197
|
-
}
|
|
2198
|
-
const config = validateConfig({
|
|
2199
|
-
tenantAlias: "UNKNOWN"
|
|
2200
|
-
});
|
|
2201
|
-
if (!config.domain) {
|
|
2202
|
-
_log$3("domain must be provided in config to use _saasquatchExtra");
|
|
2203
|
-
return;
|
|
2204
|
-
}
|
|
2205
|
-
let raw;
|
|
2206
|
-
try {
|
|
2207
|
-
raw = JSON.parse(b64decode(refParam));
|
|
2208
|
-
} catch (e) {
|
|
2209
|
-
_log$3("Unable to decode _saasquatchExtra config");
|
|
2210
|
-
return;
|
|
2211
|
-
}
|
|
2212
|
-
function normalizeDomain(domain) {
|
|
2213
|
-
return domain.replace(/^https?:\/\//, "");
|
|
2214
|
-
}
|
|
2215
|
-
const normalizedDomain = normalizeDomain(config.domain);
|
|
2216
|
-
const tenantAlias = Object.keys((raw == null ? void 0 : raw[normalizedDomain]) || {})[0];
|
|
2217
|
-
const widgetConfig = (_a2 = raw == null ? void 0 : raw[normalizedDomain]) == null ? void 0 : _a2[tenantAlias];
|
|
2218
|
-
if (!widgetConfig) {
|
|
2219
|
-
_log$3("_saasquatchExtra did not have an expected structure");
|
|
2220
|
-
return void 0;
|
|
2221
|
-
}
|
|
2222
|
-
const { autoPopupWidgetType, ...rest } = widgetConfig;
|
|
2223
|
-
return {
|
|
2224
|
-
widgetConfig: {
|
|
2225
|
-
widgetType: autoPopupWidgetType,
|
|
2226
|
-
displayOnLoad: true,
|
|
2227
|
-
...rest
|
|
2228
|
-
},
|
|
2229
|
-
squatchConfig: {
|
|
2230
|
-
...config,
|
|
2231
|
-
tenantAlias
|
|
2232
|
-
}
|
|
2233
|
-
};
|
|
2234
|
-
}
|
|
2235
|
-
const _log$2 = browserExports.debug("squatch-js:decodeUserJwt");
|
|
2236
|
-
function decodeUserJwt(tokenStr) {
|
|
2237
|
-
var _a2;
|
|
2238
|
-
try {
|
|
2239
|
-
const base64Url = tokenStr.split(".")[1];
|
|
2240
|
-
if (base64Url === void 0) return null;
|
|
2241
|
-
const jsonStr = b64decode(base64Url);
|
|
2242
|
-
return (_a2 = JSON.parse(jsonStr)) == null ? void 0 : _a2.user;
|
|
2243
|
-
} catch (e) {
|
|
2244
|
-
_log$2(e);
|
|
2245
|
-
return null;
|
|
2246
|
-
}
|
|
2247
|
-
}
|
|
2248
|
-
const _log$1 = debug("squatch-js:DeclarativeWidget");
|
|
2249
|
-
class DeclarativeWidget extends HTMLElement {
|
|
2250
|
-
constructor() {
|
|
2251
|
-
super();
|
|
2252
|
-
/**
|
|
2253
|
-
* Configuration overrides
|
|
2254
|
-
* @default window.squatchConfig
|
|
2255
|
-
*/
|
|
2256
|
-
__publicField(this, "config");
|
|
2257
|
-
/**
|
|
2258
|
-
* Signed JWT containing user information
|
|
2259
|
-
* @default window.squatchToken
|
|
2260
|
-
*/
|
|
2261
|
-
__publicField(this, "token");
|
|
2262
|
-
/**
|
|
2263
|
-
* Tenant alias of SaaSquatch tenant
|
|
2264
|
-
* @default window.squatchTenant
|
|
2265
|
-
*/
|
|
2266
|
-
__publicField(this, "tenant");
|
|
2267
|
-
/**
|
|
2268
|
-
* widgetType of widget to load
|
|
2269
|
-
*/
|
|
2270
|
-
__publicField(this, "widgetType");
|
|
2271
|
-
/**
|
|
2272
|
-
* Locale to render the widget in
|
|
2273
|
-
*/
|
|
2274
|
-
__publicField(this, "locale");
|
|
2275
|
-
/**
|
|
2276
|
-
* Instance of {@link WidgetApi}
|
|
2277
|
-
*/
|
|
2278
|
-
__publicField(this, "widgetApi");
|
|
2279
|
-
/**
|
|
2280
|
-
* Instance of {@link AnalyticsApi}
|
|
2281
|
-
*/
|
|
2282
|
-
__publicField(this, "analyticsApi");
|
|
2283
|
-
/**
|
|
2284
|
-
* Instance of {@link EmbedWidget} or {@link PopupWidget}
|
|
2285
|
-
*/
|
|
2286
|
-
__publicField(this, "widgetInstance");
|
|
2287
|
-
/**
|
|
2288
|
-
* Determines whether to render the widget as an embedding widget or popup widget
|
|
2289
|
-
*/
|
|
2290
|
-
__publicField(this, "type");
|
|
2291
|
-
/**
|
|
2292
|
-
* Container element to contain the widget iframe
|
|
2293
|
-
* @default this
|
|
2294
|
-
*/
|
|
2295
|
-
__publicField(this, "container");
|
|
2296
|
-
__publicField(this, "element");
|
|
2297
|
-
/**
|
|
2298
|
-
* Flag for if the component has been loaded or not
|
|
2299
|
-
* @hidden
|
|
2300
|
-
*/
|
|
2301
|
-
__publicField(this, "loaded");
|
|
2302
|
-
__publicField(this, "_setWidget", (res, config) => {
|
|
2303
|
-
var _a2;
|
|
2304
|
-
const params = {
|
|
2305
|
-
api: this.widgetApi,
|
|
2306
|
-
content: res.template,
|
|
2307
|
-
context: {
|
|
2308
|
-
type: config.type,
|
|
2309
|
-
user: config.user,
|
|
2310
|
-
container: this.container || void 0,
|
|
2311
|
-
engagementMedium: this.type,
|
|
2312
|
-
widgetConfig: res.widgetConfig
|
|
2313
|
-
},
|
|
2314
|
-
type: this.widgetType,
|
|
2315
|
-
domain: ((_a2 = this.config) == null ? void 0 : _a2.domain) || DEFAULT_DOMAIN,
|
|
2316
|
-
npmCdn: DEFAULT_NPM_CDN,
|
|
2317
|
-
container: this
|
|
2318
|
-
};
|
|
2319
|
-
if (this.type === "EMBED") {
|
|
2320
|
-
return new EmbedWidget(params);
|
|
2321
|
-
} else {
|
|
2322
|
-
const useFirstChildTrigger = this.firstChild ? null : void 0;
|
|
2323
|
-
return new PopupWidget(params, useFirstChildTrigger);
|
|
2324
|
-
}
|
|
2325
|
-
});
|
|
2326
|
-
/**
|
|
2327
|
-
* Builds a Widget instance for the default error widget
|
|
2328
|
-
* @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type`
|
|
2329
|
-
*/
|
|
2330
|
-
__publicField(this, "setErrorWidget", (e) => {
|
|
2331
|
-
var _a2;
|
|
2332
|
-
const params = {
|
|
2333
|
-
api: this.widgetApi,
|
|
2334
|
-
content: "error",
|
|
2335
|
-
context: {
|
|
2336
|
-
type: "error",
|
|
2337
|
-
container: this.container || void 0
|
|
2338
|
-
},
|
|
2339
|
-
type: "ERROR_WIDGET",
|
|
2340
|
-
domain: ((_a2 = this.config) == null ? void 0 : _a2.domain) || DEFAULT_DOMAIN,
|
|
2341
|
-
npmCdn: DEFAULT_NPM_CDN,
|
|
2342
|
-
container: this
|
|
2343
|
-
};
|
|
2344
|
-
if (this.type === "EMBED") {
|
|
2345
|
-
return new EmbedWidget(params);
|
|
2346
|
-
} else {
|
|
2347
|
-
const useFirstChildTrigger = this.firstChild ? null : void 0;
|
|
2348
|
-
return new PopupWidget(params, useFirstChildTrigger);
|
|
2349
|
-
}
|
|
2350
|
-
});
|
|
2351
|
-
__publicField(this, "reload", this.renderWidget);
|
|
2352
|
-
__publicField(this, "show", this.open);
|
|
2353
|
-
__publicField(this, "hide", this.close);
|
|
2354
|
-
this.attachShadow({
|
|
2355
|
-
mode: "open"
|
|
2356
|
-
}).innerHTML = `<style>:host { display: block; }</style><slot></slot>`;
|
|
2357
|
-
this.config = getConfig();
|
|
2358
|
-
this.token = getToken();
|
|
2359
|
-
this.tenant = window.squatchTenant;
|
|
2360
|
-
this.container = this;
|
|
2361
|
-
}
|
|
2362
|
-
_setupApis(config) {
|
|
2363
|
-
var _a2, _b;
|
|
2364
|
-
if (!this.tenant) throw new Error("tenantAlias not provided");
|
|
2365
|
-
this.widgetApi = new WidgetApi({
|
|
2366
|
-
tenantAlias: (config == null ? void 0 : config.tenantAlias) || this.tenant,
|
|
2367
|
-
domain: (config == null ? void 0 : config.domain) || ((_a2 = this.config) == null ? void 0 : _a2.domain) || DEFAULT_DOMAIN
|
|
2368
|
-
});
|
|
2369
|
-
this.analyticsApi = new AnalyticsApi({
|
|
2370
|
-
domain: (config == null ? void 0 : config.domain) || ((_b = this.config) == null ? void 0 : _b.domain) || DEFAULT_DOMAIN
|
|
2371
|
-
});
|
|
2372
|
-
}
|
|
2373
|
-
async renderPasswordlessVariant() {
|
|
2374
|
-
this._setupApis();
|
|
2375
|
-
_log$1("Rendering as an Instant Access widget");
|
|
2376
|
-
return await this.widgetApi.render({
|
|
2377
|
-
engagementMedium: this.type,
|
|
2378
|
-
widgetType: this.widgetType,
|
|
2379
|
-
locale: this.locale
|
|
2380
|
-
}).then((res) => this._setWidget(res, { type: "passwordless" })).catch(this.setErrorWidget);
|
|
2381
|
-
}
|
|
2382
|
-
async renderUserUpsertVariant() {
|
|
2383
|
-
this._setupApis();
|
|
2384
|
-
const userObj = decodeUserJwt(this.token);
|
|
2385
|
-
if (!userObj) {
|
|
2386
|
-
return this.setErrorWidget(Error("No user object in token."));
|
|
2387
|
-
}
|
|
2388
|
-
_log$1("Rendering as a Verified widget");
|
|
2389
|
-
await this.widgetApi.upsertUser({
|
|
2390
|
-
user: userObj,
|
|
2391
|
-
locale: this.locale,
|
|
2392
|
-
engagementMedium: this.type,
|
|
2393
|
-
widgetType: this.widgetType,
|
|
2394
|
-
jwt: this.token
|
|
2395
|
-
});
|
|
2396
|
-
const widgetInstance = await this.widgetApi.render({
|
|
2397
|
-
locale: this.locale,
|
|
2398
|
-
engagementMedium: this.type,
|
|
2399
|
-
widgetType: this.widgetType
|
|
2400
|
-
}).then((res) => {
|
|
2401
|
-
return this._setWidget(res, { type: "upsert", user: userObj });
|
|
2402
|
-
}).catch(this.setErrorWidget);
|
|
2403
|
-
return widgetInstance;
|
|
2404
|
-
}
|
|
2405
|
-
/**
|
|
2406
|
-
* Fetches widget content from SaaSquatch and builds a Widget instance to support rendering the widget in the DOM
|
|
2407
|
-
* @returns Instance of either {@link EmbedWidget} or {@link PopupWidget} depending on `this.type`
|
|
2408
|
-
* @throws Throws an Error if `widgetType` is undefined
|
|
2409
|
-
*/
|
|
2410
|
-
async getWidgetInstance() {
|
|
2411
|
-
let widgetInstance;
|
|
2412
|
-
this.widgetType = this.getAttribute("widget") || void 0;
|
|
2413
|
-
this.locale = this.getAttribute("locale") || this.locale;
|
|
2414
|
-
if (!this.widgetType) throw new Error("No widget has been specified");
|
|
2415
|
-
if (!this.token) {
|
|
2416
|
-
widgetInstance = await this.renderPasswordlessVariant();
|
|
2417
|
-
} else {
|
|
2418
|
-
widgetInstance = await this.renderUserUpsertVariant();
|
|
2419
|
-
}
|
|
2420
|
-
this.widgetInstance = widgetInstance;
|
|
2421
|
-
if (this.widgetInstance)
|
|
2422
|
-
this.dispatchEvent(new CustomEvent("sq:widget-loaded"));
|
|
2423
|
-
return widgetInstance;
|
|
2424
|
-
}
|
|
2425
|
-
/**
|
|
2426
|
-
* Calls {@link getWidgetInstance} to build the Widget instance and loads the widget iframe into the DOM
|
|
2427
|
-
*/
|
|
2428
|
-
async renderWidget() {
|
|
2429
|
-
await this.getWidgetInstance();
|
|
2430
|
-
await this.widgetInstance.load();
|
|
2431
|
-
}
|
|
2432
|
-
/**
|
|
2433
|
-
* Calls `open` method of `widgetInstance`
|
|
2434
|
-
* @throws Throws an Error if called before the widget has loaded
|
|
2435
|
-
*/
|
|
2436
|
-
open() {
|
|
2437
|
-
if (!this.widgetInstance) throw new Error("Widget has not loaded yet");
|
|
2438
|
-
this.widgetInstance.open();
|
|
2439
|
-
}
|
|
2440
|
-
/**
|
|
2441
|
-
* Calls `close` method of `widgetInstance`
|
|
2442
|
-
* @throws Throws an Error if called before the widget has loaded
|
|
2443
|
-
*/
|
|
2444
|
-
close() {
|
|
2445
|
-
if (!this.widgetInstance) throw new Error("Widget has not loaded yet");
|
|
2446
|
-
this.widgetInstance.close();
|
|
2447
|
-
}
|
|
2448
|
-
}
|
|
2449
|
-
class DeclarativeEmbedWidget extends DeclarativeWidget {
|
|
2450
|
-
constructor() {
|
|
2451
|
-
super();
|
|
2452
|
-
this.type = "EMBED";
|
|
2453
|
-
this.loaded = false;
|
|
2454
|
-
}
|
|
2455
|
-
static get observedAttributes() {
|
|
2456
|
-
return ["widget", "locale"];
|
|
2457
|
-
}
|
|
2458
|
-
attributeChangedCallback(attr, oldVal, newVal) {
|
|
2459
|
-
if (oldVal === newVal || !this.loaded) return;
|
|
2460
|
-
switch (attr) {
|
|
2461
|
-
case "locale":
|
|
2462
|
-
case "widget":
|
|
2463
|
-
this.connectedCallback();
|
|
2464
|
-
break;
|
|
2465
|
-
}
|
|
2466
|
-
}
|
|
2467
|
-
async connectedCallback() {
|
|
2468
|
-
var _a2;
|
|
2469
|
-
this.loaded = true;
|
|
2470
|
-
this.container = this.getAttribute("container");
|
|
2471
|
-
const skeletonHTML = `
|
|
2472
|
-
<div>
|
|
2473
|
-
<h1>Dynamic Content</h1>
|
|
2474
|
-
<p>This content was dynamically added to the widget before it loaded.</p>
|
|
2475
|
-
</div>
|
|
2476
|
-
`;
|
|
2477
|
-
const skeletonContainer = document.createElement("div");
|
|
2478
|
-
skeletonContainer.id = "loading-skeleton";
|
|
2479
|
-
skeletonContainer.innerHTML = skeletonHTML;
|
|
2480
|
-
if (!this.shadowRoot) {
|
|
2481
|
-
this.attachShadow({ mode: "open" });
|
|
2482
|
-
}
|
|
2483
|
-
if (this.shadowRoot) {
|
|
2484
|
-
this.shadowRoot.innerHTML = skeletonHTML;
|
|
2485
|
-
}
|
|
2486
|
-
await this.renderWidget();
|
|
2487
|
-
const loadingElement = (_a2 = this.shadowRoot) == null ? void 0 : _a2.getElementById("loading-skeleton");
|
|
2488
|
-
if (loadingElement) {
|
|
2489
|
-
loadingElement.remove();
|
|
2490
|
-
}
|
|
2491
|
-
if (this.getAttribute("open") !== null) this.open();
|
|
2492
|
-
}
|
|
2493
|
-
}
|
|
2494
|
-
class DeclarativePopupWidget extends DeclarativeWidget {
|
|
2495
|
-
constructor() {
|
|
2496
|
-
super();
|
|
2497
|
-
this.type = "POPUP";
|
|
2498
|
-
this.loaded = false;
|
|
2499
|
-
this.addEventListener("click", (e) => {
|
|
2500
|
-
e.stopPropagation();
|
|
2501
|
-
this.open();
|
|
2502
|
-
});
|
|
2503
|
-
}
|
|
2504
|
-
static get observedAttributes() {
|
|
2505
|
-
return ["widget", "locale"];
|
|
2506
|
-
}
|
|
2507
|
-
attributeChangedCallback(attr, oldVal, newVal) {
|
|
2508
|
-
if (oldVal === newVal || !this.loaded) return;
|
|
2509
|
-
switch (attr) {
|
|
2510
|
-
case "locale":
|
|
2511
|
-
case "widget":
|
|
2512
|
-
this.connectedCallback();
|
|
2513
|
-
break;
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
async connectedCallback() {
|
|
2517
|
-
var _a2;
|
|
2518
|
-
this.loaded = true;
|
|
2519
|
-
this.container = this.getAttribute("container");
|
|
2520
|
-
const skeletonHTML = `
|
|
2521
|
-
<div>
|
|
2522
|
-
<h1>Dynamic Content</h1>
|
|
2523
|
-
<p>This content was dynamically added to the widget before it loaded.</p>
|
|
2524
|
-
</div>
|
|
2525
|
-
`;
|
|
2526
|
-
const skeletonContainer = document.createElement("div");
|
|
2527
|
-
skeletonContainer.id = "loading-skeleton";
|
|
2528
|
-
skeletonContainer.innerHTML = skeletonHTML;
|
|
2529
|
-
if (!this.shadowRoot) {
|
|
2530
|
-
this.attachShadow({ mode: "open" });
|
|
2531
|
-
}
|
|
2532
|
-
if (this.shadowRoot) {
|
|
2533
|
-
this.shadowRoot.innerHTML = skeletonHTML;
|
|
2534
|
-
}
|
|
2535
|
-
await this.renderWidget();
|
|
2536
|
-
const loadingElement = (_a2 = this.shadowRoot) == null ? void 0 : _a2.getElementById("loading-skeleton");
|
|
2537
|
-
if (loadingElement) {
|
|
2538
|
-
loadingElement.remove();
|
|
2539
|
-
}
|
|
2540
|
-
if (this.getAttribute("open") !== null) this.open();
|
|
2541
|
-
}
|
|
2542
|
-
}
|
|
2543
|
-
class SquatchEmbed extends DeclarativeEmbedWidget {
|
|
2544
|
-
}
|
|
2545
|
-
class SquatchPopup extends DeclarativePopupWidget {
|
|
2546
|
-
}
|
|
2547
|
-
class ImpactEmbed extends DeclarativeEmbedWidget {
|
|
2548
|
-
}
|
|
2549
|
-
class ImpactPopup extends DeclarativePopupWidget {
|
|
2550
|
-
}
|
|
2551
|
-
if (!window.customElements.get("squatch-embed"))
|
|
2552
|
-
window.customElements.define("squatch-embed", SquatchEmbed);
|
|
2553
|
-
if (!window.customElements.get("impact-embed"))
|
|
2554
|
-
window.customElements.define("impact-embed", ImpactEmbed);
|
|
2555
|
-
if (!window.customElements.get("squatch-popup"))
|
|
2556
|
-
window.customElements.define("squatch-popup", SquatchPopup);
|
|
2557
|
-
if (!window.customElements.get("impact-popup"))
|
|
2558
|
-
window.customElements.define("impact-popup", ImpactPopup);
|
|
2559
|
-
function help() {
|
|
2560
|
-
console.log(
|
|
2561
|
-
`Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes.`
|
|
2562
|
-
);
|
|
2563
|
-
}
|
|
2564
|
-
const _log = browserExports.debug("squatch-js");
|
|
2565
|
-
let _api = null;
|
|
2566
|
-
let _widgets = null;
|
|
2567
|
-
let _events = null;
|
|
2568
|
-
function api() {
|
|
2569
|
-
if (!_api) init({});
|
|
2570
|
-
return _api;
|
|
2571
|
-
}
|
|
2572
|
-
function widgets() {
|
|
2573
|
-
if (!_widgets) init({});
|
|
2574
|
-
return _widgets;
|
|
2575
|
-
}
|
|
2576
|
-
function events() {
|
|
2577
|
-
if (!_events) init({});
|
|
2578
|
-
return _events;
|
|
2579
|
-
}
|
|
2580
|
-
function widget(widgetConfig) {
|
|
2581
|
-
var _a2;
|
|
2582
|
-
return (_a2 = widgets()) == null ? void 0 : _a2.render(widgetConfig);
|
|
2583
|
-
}
|
|
2584
|
-
function _auto() {
|
|
2585
|
-
var _a2;
|
|
2586
|
-
const configs = _getAutoConfig();
|
|
2587
|
-
if (configs) {
|
|
2588
|
-
const { squatchConfig, widgetConfig } = configs;
|
|
2589
|
-
init(squatchConfig);
|
|
2590
|
-
return (_a2 = widgets()) == null ? void 0 : _a2.render(widgetConfig);
|
|
2591
|
-
}
|
|
2592
|
-
}
|
|
2593
|
-
function init(configIn) {
|
|
2594
|
-
const raw = configIn;
|
|
2595
|
-
const config = validateConfig(raw);
|
|
2596
|
-
if (config.tenantAlias.match("^test") || config.debug) {
|
|
2597
|
-
browserExports.debug.enable("squatch-js*");
|
|
2598
|
-
} else {
|
|
2599
|
-
browserExports.debug.disable();
|
|
2600
|
-
}
|
|
2601
|
-
_log("initializing ...");
|
|
2602
|
-
_api = new WidgetApi(config);
|
|
2603
|
-
_widgets = new Widgets(config);
|
|
2604
|
-
_events = new EventsApi(config);
|
|
2605
|
-
_log("Widget API instance", _api);
|
|
2606
|
-
_log("Widgets instance", _widgets);
|
|
2607
|
-
_log("Events API instance", _events);
|
|
2608
|
-
}
|
|
2609
|
-
function ready(fn) {
|
|
2610
|
-
fn();
|
|
2611
|
-
}
|
|
2612
|
-
function autofill(selector) {
|
|
2613
|
-
widgets().autofill(selector);
|
|
2614
|
-
}
|
|
2615
|
-
function pushCookie() {
|
|
2616
|
-
_pushCookie();
|
|
2617
|
-
}
|
|
2618
|
-
if (typeof document !== "undefined" && !window.SaaSquatchDoNotAutoDrop) {
|
|
2619
|
-
pushCookie();
|
|
2620
|
-
}
|
|
2621
|
-
if ((_a = window["squatch"]) == null ? void 0 : _a.init)
|
|
2622
|
-
_log(
|
|
2623
|
-
"Squatchjs is being loaded more than once. This may lead to multiple load events being sent, duplicated widgets, and inaccurate analytics."
|
|
2624
|
-
);
|
|
2625
|
-
if (typeof document !== "undefined") asyncLoad();
|
|
2626
|
-
exports.DeclarativeEmbedWidget = DeclarativeEmbedWidget;
|
|
2627
|
-
exports.DeclarativePopupWidget = DeclarativePopupWidget;
|
|
2628
|
-
exports.EmbedWidget = EmbedWidget;
|
|
2629
|
-
exports.PopupWidget = PopupWidget;
|
|
2630
|
-
exports.WidgetApi = WidgetApi;
|
|
2631
|
-
exports.Widgets = Widgets;
|
|
2632
|
-
exports._auto = _auto;
|
|
2633
|
-
exports.api = api;
|
|
2634
|
-
exports.autofill = autofill;
|
|
2635
|
-
exports.events = events;
|
|
2636
|
-
exports.help = help;
|
|
2637
|
-
exports.init = init;
|
|
2638
|
-
exports.pushCookie = pushCookie;
|
|
2639
|
-
exports.ready = ready;
|
|
2640
|
-
exports.widget = widget;
|
|
2641
|
-
exports.widgets = widgets;
|
|
74
|
+
`),d.close(),k("Popup template loaded into iframe"),await this._setupResizeHandler(n,i)}async _setupResizeHandler(e,i){const{contentWindow:n}=e;if(!n)throw new Error("Frame needs a content window");const s=n.document;Y(s,async()=>{s.body.style.overflowY="hidden",e.height=i||s.body.offsetHeight,new ResizeObserver(a=>{for(const c of a){const{top:d,bottom:h}=c.contentRect,u=h+d;e.height=u+"",c.target.style=""}}).observe(await this._findInnerContainer(e))})}open(){const e=this.container?this._findElement():document.body,n=(e.shadowRoot||e).querySelector(`#${this.id}`);if(!n)throw new Error("Could not determine container div");n.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;Y(a,()=>{var d;const c=r.squatch||r.widgetIdent;(d=s.contentDocument)==null||d.dispatchEvent(new CustomEvent("sq:refresh")),this.context.user?(this._loadEvent(c),k("Popup opened")):this._attachLoadEventListener(a,c)})}close(){const e=this._findFrame();e!=null&&e.contentDocument&&this._detachLoadEventListener(e.contentDocument);const i=this.container?this._findElement():document.body,s=(i.shadowRoot||i).querySelector(`#${this.id}`);if(!s)throw new Error("Could not determine container div");s.close(),k("Popup closed")}_clickedOutside({target:e}){}_error(e,i="modal",n=""){return super._error(e,i,n||"body { margin: 0; } .modal { box-shadow: none; border: 0; }")}}const y=E("squatch-js:widgets");class T{constructor(t){l(this,"api");l(this,"tenantAlias");l(this,"domain");l(this,"npmCdn");const e=U(t);this.tenantAlias=e.tenantAlias,this.domain=e.domain,this.npmCdn=e.npmCdn,this.api=new J(e)}async upsertUser(t){const i=ae(t);try{const n=await this.api.upsertUser(i);return{widget:this._renderWidget(n,i,{type:"upsert",user:i.user,engagementMedium:t.engagementMedium,container:t.container,trigger:t.trigger,widgetConfig:{values:{brandingConfig:n==null?void 0:n.brandingConfig}}}),user:n.user}}catch(n){throw y(n),n.apiErrorCode&&this._renderErrorWidget(n,t.engagementMedium),new Error(n)}}async render(t){const i=ce(t);try{const n=await this.api.render(i);return{widget:this._renderWidget(n,i,{type:"passwordless",engagementMedium:i.engagementMedium,container:i.container,trigger:i.trigger,widgetConfig:n==null?void 0:n.widgetConfig}),user:n.user}}catch(n){throw n.apiErrorCode&&this._renderErrorWidget(n,i.engagementMedium),new Error(n)}}async autofill(t){const e=t;if(typeof e=="function"){try{const s=await this.api.squatchReferralCookie();e(s)}catch(s){throw y("Autofill error",s),new Error(s)}return}if(typeof e!="string")throw new Error("Autofill accepts a string or function");let i=document.querySelectorAll(e),n;if(i.length>0)n=i[0];else throw y("Element id/class or function missing"),new Error("Element id/class or function missing");try{const s=await this.api.squatchReferralCookie();n.value=s.codes[0]}catch(s){throw new Error(s)}}_renderWidget(t,e,i){var c;if(y("Rendering Widget..."),!t)throw new Error("Unable to get a response");let n,s=!!e.displayOnLoad;const r=t.jsOptions||{},a={content:t.template,type:e.widgetType||((c=r.widget)==null?void 0:c.defaultWidgetType),api:this.api,domain:this.domain,npmCdn:this.npmCdn,context:i};return r.widgetUrlMappings&&r.widgetUrlMappings.forEach(d=>{var h,u;T._matchesUrl(d.url)&&(d.widgetType!=="CONVERSION_WIDGET"||(u=(h=t.user)==null?void 0:h.referredBy)!=null&&u.code?(s=d.displayOnLoad,y(`Display ${d.widgetType} on ${d.url}`)):y(`Don't display ${d.widgetType} when no referral on widget rule match ${d.url}`))}),r.fuelTankAutofillUrls&&(y("We found a fuel tank autofill!"),r.fuelTankAutofillUrls.forEach(({url:d,formSelector:h})=>{var u,p,m;if(T._matchesUrl(d)&&(y("Fuel Tank URL matches"),(p=(u=t.user)==null?void 0:u.referredBy)!=null&&p.code)){const g=document.querySelector(h);g?g.value=((m=t.user.referredBy.referredReward)==null?void 0:m.fuelTankCode)||"":y(new Error(`Element with id/class ${h} was not found.`))}})),e.engagementMedium==="EMBED"?n=this._renderEmbedWidget(a):(n=this._renderPopupWidget(a),s&&n.open()),n}_renderPopupWidget(t){const e=new q(t,t.context.trigger);return e.load(),e}_renderEmbedWidget(t){const e=new x(t,t.context.container);return e.load(),e}_renderErrorWidget(t,e="POPUP"){const{apiErrorCode:i,rsCode:n,message:s}=t;y(new Error(`${i} (${n}) ${s}`));const r={content:"error",rsCode:n,api:this.api,domain:this.domain,npmCdn:this.npmCdn,type:"ERROR_WIDGET",context:{type:"error"}};let a;e==="EMBED"?(a=new x(r),a.load()):e==="POPUP"&&(a=new q(r),a.load())}static _matchesUrl(t){return!!window.location.href.match(new RegExp(t))}}class Re{constructor(t){l(this,"tenantAlias");l(this,"domain");const i=U(t);this.tenantAlias=i.tenantAlias,this.domain=i.domain}track(t,e){const i=t,n=e,s=$e(i),{jwt:r}=Pe(n),a=encodeURIComponent(this.tenantAlias),c=encodeURIComponent(s.userId),d=encodeURIComponent(s.accountId),h=`/api/v1/${a}/open/account/${d}/user/${c}/events`,u=this.domain+h;return Q(u,JSON.stringify(s),r)}}function $e(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 Pe(o){if(!I(o))throw new Error("'options' should be an object");return o}function Se(){var n;const o=window[z]?z:S,t=((n=window["_"+o])==null?void 0:n.ready)||[],e=window.impactOnReady||window.squatchOnReady,i=[...t,e].filter(s=>!!s);setTimeout(()=>{window[S]&&(window[z]=window[S],i.forEach(s=>s()),window[S]._auto(),window["_"+o]=void 0,delete window["_"+o])},0)}const v=E("squatch-js"),ie=o=>typeof o=="object"&&!Array.isArray(o),he=(o,t)=>{const e=n=>ie(t[n])&&o.hasOwnProperty(n)&&ie(o[n]),i=Object.getOwnPropertyNames(t).map(n=>({[n]:e(n)?he(o[n],t[n]):t[n]})).reduce((n,s)=>({...n,...s}),{});return{...o,...i}};function N(o){const t=atob(o.replace(/_/g,"/").replace(/-/g,"+")),e=new Uint8Array(t.length);for(let i=0;i<t.length;i++)e[i]=t.charCodeAt(i);return new TextDecoder("utf8").decode(e)}function oe(o){const t=new TextEncoder().encode(o),e=Array.from(t,i=>String.fromCodePoint(i)).join("");return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function Me(){var o,t,e="weird_get_top_level_domain=cookie",i=document.location.hostname.split(".");for(o=i.length-1;o>=0;o--)if(t=i.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 Oe(){const o=window.location.search,e=new URLSearchParams(o).get("_saasquatch")||"";if(e){let i="",n="",s="";try{i=JSON.parse(N(e))}catch(r){v("Unable to decode params",r);return}try{n=JSON.parse(N(j.get("_saasquatch"))),v("existing cookie",n)}catch(r){v("Unable to retrieve cookie",r)}try{const r=Me();if(v("domain retrieved:",r),n){const a=he(n,i);s=oe(JSON.stringify(a)),v("cookie to store:",a)}else s=oe(JSON.stringify(i)),v("cookie to store:",i);j.set("_saasquatch",s,{expires:365,secure:!1,sameSite:"Lax",domain:r,path:"/"})}catch(r){v("Unable to set cookie",r)}}}const O=E("squatch-js");function Le(){var u;const o=window.location.search,e=new URLSearchParams(o).get("_saasquatchExtra")||"";if(!e){O("No _saasquatchExtra param");return}const i=U({tenantAlias:"UNKNOWN"});if(!i.domain){O("domain must be provided in config to use _saasquatchExtra");return}let n;try{n=JSON.parse(N(e))}catch{O("Unable to decode _saasquatchExtra config");return}function s(p){return p.replace(/^https?:\/\//,"")}const r=s(i.domain),a=Object.keys((n==null?void 0:n[r])||{})[0],c=(u=n==null?void 0:n[r])==null?void 0:u[a];if(!c){O("_saasquatchExtra did not have an expected structure");return}const{autoPopupWidgetType:d,...h}=c;return{widgetConfig:{widgetType:d,displayOnLoad:!0,...h},squatchConfig:{...i,tenantAlias:a}}}const je=E("squatch-js:decodeUserJwt");function De(o){var t;try{const e=o.split(".")[1];if(e===void 0)return null;const i=N(e);return(t=JSON.parse(i))==null?void 0:t.user}catch(e){return je(e),null}}const se=E("squatch-js:DeclarativeWidget");class ue 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,i)=>{var s;const n={api:this.widgetApi,content:e.template,context:{type:i.type,user:i.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:X,container:this};if(this.type==="EMBED")return new x(n);{const r=this.firstChild?null:void 0;return new q(n,r)}});l(this,"setErrorWidget",e=>{var n;const i={api:this.widgetApi,content:"error",context:{type:"error",container:this.container||void 0},type:"ERROR_WIDGET",domain:((n=this.config)==null?void 0:n.domain)||A,npmCdn:X,container:this};if(this.type==="EMBED")return new x(i);{const s=this.firstChild?null:void 0;return new q(i,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=K(),this.token=R(),this.tenant=window.squatchTenant,this.container=this}_setupApis(e){var i,n;if(!this.tenant)throw new Error("tenantAlias not provided");this.widgetApi=new J({tenantAlias:(e==null?void 0:e.tenantAlias)||this.tenant,domain:(e==null?void 0:e.domain)||((i=this.config)==null?void 0:i.domain)||A}),this.analyticsApi=new de({domain:(e==null?void 0:e.domain)||((n=this.config)==null?void 0:n.domain)||A})}getWidgetType(e){return e&&(e.includes("websiteReferralWidget")||e.includes("friendWidget"))?"instant-access":"verified-access"}async renderPasswordlessVariant(){return this._setupApis(),se("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=De(this.token);return e?(se("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(n=>this._setWidget(n,{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,i,n){if(!(i===n||!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:i}=await Promise.resolve().then(()=>require("./SkeletonTemplate-hwDwv3Ys.cjs")),n=i({height:"100%",type:e}),s=document.createElement("div");s.id="loading-skeleton",s.innerHTML=n;const r=this.shadowRoot||this.attachShadow({mode:"open"});if(this.type==="POPUP"){const c=r.getElementById("#squatchModal");c&&(c.innerHTML="",c.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 Z extends ue{constructor(){super(),this.type="EMBED",this.loaded=!1}}class ee extends ue{constructor(){super(),this.type="POPUP",this.loaded=!1,this.addEventListener("click",t=>{t.stopPropagation(),this.open()})}}class Ne extends Z{}class Fe extends ee{}class He extends Z{}class Be extends ee{}window.customElements.get("squatch-embed")||window.customElements.define("squatch-embed",Ne);window.customElements.get("impact-embed")||window.customElements.define("impact-embed",He);window.customElements.get("squatch-popup")||window.customElements.define("squatch-popup",Fe);window.customElements.get("impact-popup")||window.customElements.define("impact-popup",Be);function Je(){console.log("Having trouble using Squatch.js? Go to https://docs.referralsaasquatch.com/developer/ for tutorials, references and error codes.")}const W=E("squatch-js");let F=null,H=null,B=null;function Ge(){return F||$({}),F}function G(){return H||$({}),H}function ze(){return B||$({}),B}function Ve(o){var t;return(t=G())==null?void 0:t.render(o)}function Xe(){var t;const o=Le();if(o){const{squatchConfig:e,widgetConfig:i}=o;return $(e),(t=G())==null?void 0:t.render(i)}}function $(o){const e=U(o);e.tenantAlias.match("^test")||e.debug?ve("squatch-js*"):be(),W("initializing ..."),F=new J(e),H=new T(e),B=new Re(e),W("Widget API instance",F),W("Widgets instance",H),W("Events API instance",B)}function Qe(o){o()}function Ye(o){G().autofill(o)}function pe(){Oe()}typeof document<"u"&&!window.SaaSquatchDoNotAutoDrop&&pe();var re;(re=window.squatch)!=null&&re.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"&&Se();exports.DeclarativeEmbedWidget=Z;exports.DeclarativePopupWidget=ee;exports.EmbedWidget=x;exports.PopupWidget=q;exports.WidgetApi=J;exports.Widgets=T;exports._auto=Xe;exports.api=Ge;exports.autofill=Ye;exports.events=ze;exports.help=Je;exports.init=$;exports.pushCookie=pe;exports.ready=Qe;exports.widget=Ve;exports.widgets=G;
|
|
2642
75
|
//# sourceMappingURL=squatch.cjs.js.map
|