@sightspool/sdk 0.2.1 → 0.4.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/CHANGELOG.md +15 -0
- package/README.md +111 -333
- package/SECURITY.md +16 -0
- package/dist/index.cjs +159 -1080
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -41
- package/dist/index.d.ts +20 -41
- package/dist/index.js +160 -734
- package/dist/index.js.map +1 -1
- package/dist/release.json +21 -0
- package/dist/sdk.global.js +2 -38
- package/dist/sdk.global.js.map +1 -1
- package/dist/source.json +11 -0
- package/package.json +14 -12
- package/site/CNAME +1 -0
- package/site/demo.html +6 -0
- package/site/demo.js +27 -0
- package/site/index.html +74 -0
- package/site/release.js +20 -0
- package/site/releases/0.4.0/2acf3463db7571c459ca01a4516341891bb4c2ec6265962f494ca8b553cc0e9f/release.json +21 -0
- package/site/releases/0.4.0/2acf3463db7571c459ca01a4516341891bb4c2ec6265962f494ca8b553cc0e9f/sdk.global.js +3 -0
- package/site/releases/0.4.0/2acf3463db7571c459ca01a4516341891bb4c2ec6265962f494ca8b553cc0e9f/sdk.global.js.map +1 -0
- package/site/releases/0.4.0/2acf3463db7571c459ca01a4516341891bb4c2ec6265962f494ca8b553cc0e9f/source.json +11 -0
- package/site/releases/0.4.0/c21bee307a5c53e3ebb49d21f0f1ef2cce06a4483fa9824122bd6897ad6ca3ac/release.json +21 -0
- package/site/releases/0.4.0/c21bee307a5c53e3ebb49d21f0f1ef2cce06a4483fa9824122bd6897ad6ca3ac/sdk.global.js +3 -0
- package/site/releases/0.4.0/c21bee307a5c53e3ebb49d21f0f1ef2cce06a4483fa9824122bd6897ad6ca3ac/sdk.global.js.map +1 -0
- package/site/releases/0.4.0/c21bee307a5c53e3ebb49d21f0f1ef2cce06a4483fa9824122bd6897ad6ca3ac/source.json +11 -0
- package/site/styles.css +69 -0
- package/site/trust.html +36 -0
- package/dist/chunk-4PADVIIO.js +0 -41
- package/dist/chunk-4PADVIIO.js.map +0 -1
- package/dist/prompt-GDFYC75D.js +0 -139
- package/dist/prompt-GDFYC75D.js.map +0 -1
- package/dist/survey-CICJQ5VI.js +0 -145
- package/dist/survey-CICJQ5VI.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -2,1137 +2,216 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
5
|
+
// src/research.ts
|
|
6
|
+
var slot = /* @__PURE__ */ Symbol.for("sightspool.research.runtime.v1");
|
|
7
|
+
var host = () => typeof window === "undefined" ? null : window;
|
|
8
|
+
var current = () => {
|
|
9
|
+
var _a;
|
|
10
|
+
return (_a = host()) == null ? void 0 : _a[slot];
|
|
9
11
|
};
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
LONG_DIGITS_RE = /\d{6,}/g;
|
|
51
|
-
MAX_LABEL_LEN = 280;
|
|
52
|
-
ATTACH_DISCLOSURE = "Session and account attached automatically.";
|
|
53
|
-
REDACTED = "\u2039redacted\u203A";
|
|
54
|
-
IGNORE_ATTR = "data-sightspool-ignore";
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// src/prompt.ts
|
|
59
|
-
var prompt_exports = {};
|
|
60
|
-
__export(prompt_exports, {
|
|
61
|
-
showPrompt: () => showPrompt
|
|
62
|
-
});
|
|
63
|
-
function showPrompt(opts) {
|
|
64
|
-
return new Promise((resolve) => {
|
|
65
|
-
if (typeof document === "undefined") {
|
|
66
|
-
resolve({ answer: "dismissed" });
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
let settled = false;
|
|
70
|
-
const host = document.createElement("div");
|
|
71
|
-
const shadow = host.attachShadow({ mode: "open" });
|
|
72
|
-
function finish(result) {
|
|
73
|
-
if (settled) return;
|
|
74
|
-
settled = true;
|
|
75
|
-
try {
|
|
76
|
-
host.remove();
|
|
77
|
-
} catch (e) {
|
|
78
|
-
}
|
|
79
|
-
resolve(result);
|
|
80
|
-
}
|
|
81
|
-
const style = document.createElement("style");
|
|
82
|
-
style.textContent = STYLE;
|
|
83
|
-
shadow.appendChild(style);
|
|
84
|
-
const wrap = document.createElement("div");
|
|
85
|
-
wrap.className = "wrap";
|
|
86
|
-
shadow.appendChild(wrap);
|
|
87
|
-
function render(node) {
|
|
88
|
-
wrap.innerHTML = "";
|
|
89
|
-
const card = document.createElement("div");
|
|
90
|
-
card.className = "card";
|
|
91
|
-
card.style.position = "relative";
|
|
92
|
-
const x = document.createElement("button");
|
|
93
|
-
x.className = "x";
|
|
94
|
-
x.textContent = "\xD7";
|
|
95
|
-
x.setAttribute("aria-label", "Dismiss");
|
|
96
|
-
x.onclick = () => finish({ answer: "dismissed" });
|
|
97
|
-
card.appendChild(x);
|
|
98
|
-
card.appendChild(node);
|
|
99
|
-
const disc = document.createElement("p");
|
|
100
|
-
disc.className = "disc";
|
|
101
|
-
disc.textContent = ATTACH_DISCLOSURE;
|
|
102
|
-
card.appendChild(disc);
|
|
103
|
-
wrap.appendChild(card);
|
|
104
|
-
}
|
|
105
|
-
function stateA() {
|
|
106
|
-
const node = document.createElement("div");
|
|
107
|
-
const q = document.createElement("p");
|
|
108
|
-
q.className = "q";
|
|
109
|
-
q.textContent = "Were you able to do what you came here to do today?";
|
|
110
|
-
node.appendChild(q);
|
|
111
|
-
const row = document.createElement("div");
|
|
112
|
-
row.className = "row";
|
|
113
|
-
const yes = document.createElement("button");
|
|
114
|
-
yes.className = "primary";
|
|
115
|
-
yes.textContent = "Yes";
|
|
116
|
-
yes.onclick = () => finish({ answer: "yes" });
|
|
117
|
-
const no = document.createElement("button");
|
|
118
|
-
no.textContent = "Not really";
|
|
119
|
-
no.onclick = () => stateB();
|
|
120
|
-
row.append(yes, no);
|
|
121
|
-
node.appendChild(row);
|
|
122
|
-
render(node);
|
|
123
|
-
}
|
|
124
|
-
function stateB() {
|
|
125
|
-
const node = document.createElement("div");
|
|
126
|
-
const q = document.createElement("p");
|
|
127
|
-
q.className = "q";
|
|
128
|
-
q.textContent = "What were you trying to do?";
|
|
129
|
-
node.appendChild(q);
|
|
130
|
-
for (const c of opts.candidates.slice(0, 4)) {
|
|
131
|
-
const b = document.createElement("button");
|
|
132
|
-
b.className = "cand";
|
|
133
|
-
b.textContent = c;
|
|
134
|
-
b.onclick = () => finish({ answer: "not_really", intent: c });
|
|
135
|
-
node.appendChild(b);
|
|
136
|
-
}
|
|
137
|
-
const se = document.createElement("button");
|
|
138
|
-
se.className = "cand";
|
|
139
|
-
se.textContent = "Something else\u2026";
|
|
140
|
-
se.onclick = () => stateText();
|
|
141
|
-
node.appendChild(se);
|
|
142
|
-
render(node);
|
|
143
|
-
}
|
|
144
|
-
function stateText() {
|
|
145
|
-
const node = document.createElement("div");
|
|
146
|
-
const q = document.createElement("p");
|
|
147
|
-
q.className = "q";
|
|
148
|
-
q.textContent = "What were you trying to do?";
|
|
149
|
-
node.appendChild(q);
|
|
150
|
-
const input = document.createElement("input");
|
|
151
|
-
input.type = "text";
|
|
152
|
-
input.placeholder = "In your own words\u2026";
|
|
153
|
-
node.appendChild(input);
|
|
154
|
-
const row = document.createElement("div");
|
|
155
|
-
row.className = "row";
|
|
156
|
-
const submit = document.createElement("button");
|
|
157
|
-
submit.className = "primary";
|
|
158
|
-
submit.textContent = "Send";
|
|
159
|
-
submit.onclick = () => finish({ answer: "not_really", verbatim: input.value.trim() || void 0 });
|
|
160
|
-
row.appendChild(submit);
|
|
161
|
-
node.appendChild(row);
|
|
162
|
-
render(node);
|
|
163
|
-
try {
|
|
164
|
-
input.focus();
|
|
165
|
-
} catch (e) {
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
try {
|
|
169
|
-
document.body.appendChild(host);
|
|
170
|
-
stateA();
|
|
171
|
-
} catch (e) {
|
|
172
|
-
finish({ answer: "dismissed" });
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
var STYLE;
|
|
177
|
-
var init_prompt = __esm({
|
|
178
|
-
"src/prompt.ts"() {
|
|
179
|
-
init_privacy();
|
|
180
|
-
STYLE = `
|
|
181
|
-
:host { all: initial; }
|
|
182
|
-
.wrap { position: fixed; bottom: 20px; right: 20px; z-index: 2147483000;
|
|
183
|
-
width: 320px; max-width: calc(100vw - 32px); font-family: system-ui, -apple-system, sans-serif; }
|
|
184
|
-
.card { background: #fff; color: #18181b; border: 1px solid #e4e4e7; border-radius: 12px;
|
|
185
|
-
box-shadow: 0 10px 30px rgba(0,0,0,.12); padding: 16px; }
|
|
186
|
-
.q { font-size: 14px; font-weight: 600; margin: 0 0 12px; line-height: 1.35; }
|
|
187
|
-
.row { display: flex; gap: 8px; flex-wrap: wrap; }
|
|
188
|
-
button { font: inherit; font-size: 13px; cursor: pointer; border-radius: 8px; padding: 8px 12px;
|
|
189
|
-
border: 1px solid #e4e4e7; background: #fafafa; color: #18181b; }
|
|
190
|
-
button:hover { background: #f4f4f5; }
|
|
191
|
-
button.primary { background: #18181b; color: #fff; border-color: #18181b; }
|
|
192
|
-
.cand { display: block; width: 100%; text-align: left; margin-bottom: 6px; }
|
|
193
|
-
.disc { font-size: 11px; color: #71717a; margin: 12px 0 0; }
|
|
194
|
-
.x { position: absolute; top: 8px; right: 10px; border: none; background: none; font-size: 16px;
|
|
195
|
-
color: #a1a1aa; padding: 2px 6px; }
|
|
196
|
-
input { font: inherit; font-size: 13px; width: 100%; box-sizing: border-box; padding: 8px 10px;
|
|
197
|
-
border: 1px solid #e4e4e7; border-radius: 8px; margin-bottom: 8px; }
|
|
198
|
-
`;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
// src/survey.ts
|
|
203
|
-
var survey_exports = {};
|
|
204
|
-
__export(survey_exports, {
|
|
205
|
-
showSurvey: () => showSurvey
|
|
206
|
-
});
|
|
207
|
-
function showSurvey(config) {
|
|
208
|
-
return new Promise((resolve) => {
|
|
209
|
-
if (typeof document === "undefined") {
|
|
210
|
-
resolve({ dismissed: true });
|
|
12
|
+
var eligible = (r) => r.audience === "all_visitors" || r.identified;
|
|
13
|
+
function remove(r) {
|
|
14
|
+
var _a;
|
|
15
|
+
(_a = r.button) == null ? void 0 : _a.remove();
|
|
16
|
+
r.button = null;
|
|
17
|
+
r.offer = null;
|
|
18
|
+
}
|
|
19
|
+
function invalidate(r) {
|
|
20
|
+
var _a;
|
|
21
|
+
r.generation += 1;
|
|
22
|
+
(_a = r.pending) == null ? void 0 : _a.abort();
|
|
23
|
+
r.pending = null;
|
|
24
|
+
remove(r);
|
|
25
|
+
}
|
|
26
|
+
function status(r, value) {
|
|
27
|
+
r.status = value;
|
|
28
|
+
}
|
|
29
|
+
async function check(r) {
|
|
30
|
+
if (r.disposed || r.paused || !eligible(r) || r.pending || document.visibilityState !== "visible") return;
|
|
31
|
+
const generation = r.generation;
|
|
32
|
+
const request = new AbortController();
|
|
33
|
+
r.pending = request;
|
|
34
|
+
const timeout = window.setTimeout(() => request.abort(), 1e4);
|
|
35
|
+
if (!r.button) status(r, "checking");
|
|
36
|
+
try {
|
|
37
|
+
const response = await fetch(r.endpoint + "/widget-offer", {
|
|
38
|
+
method: "POST",
|
|
39
|
+
credentials: "omit",
|
|
40
|
+
cache: "no-store",
|
|
41
|
+
referrerPolicy: "no-referrer",
|
|
42
|
+
headers: { "Content-Type": "application/json" },
|
|
43
|
+
body: JSON.stringify({ operation: "offer", key: r.key, device: r.device }),
|
|
44
|
+
signal: request.signal
|
|
45
|
+
});
|
|
46
|
+
if (!response.ok) throw Error("offer unavailable");
|
|
47
|
+
const result = await response.json();
|
|
48
|
+
if (r.disposed || generation !== r.generation || r.paused || !eligible(r)) return;
|
|
49
|
+
if (result.available !== true || typeof result.offer !== "string" || !result.offer) {
|
|
50
|
+
remove(r);
|
|
51
|
+
status(r, "unavailable");
|
|
211
52
|
return;
|
|
212
53
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
54
|
+
r.offer = result.offer;
|
|
55
|
+
status(r, "available");
|
|
56
|
+
if (r.button) return;
|
|
57
|
+
const button = document.createElement("button");
|
|
58
|
+
button.type = "button";
|
|
59
|
+
button.textContent = "Talk to the founder \xB7 5 min";
|
|
60
|
+
button.setAttribute("aria-label", "Sightspool: join a five-minute user interview");
|
|
61
|
+
button.style.cssText = "position:fixed;bottom:20px;right:20px;z-index:2147483000;padding:14px 18px;border:0;border-radius:16px;background:#171717;color:white;font:500 14px system-ui;box-shadow:0 8px 30px #0003;cursor:pointer;max-width:calc(100vw - 40px)";
|
|
62
|
+
button.onclick = () => {
|
|
217
63
|
try {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
function finish(result, thank) {
|
|
223
|
-
if (settled) return;
|
|
224
|
-
settled = true;
|
|
225
|
-
resolve(result);
|
|
226
|
-
if (thank) {
|
|
227
|
-
thankYou();
|
|
228
|
-
setTimeout(teardown, THANKS_MS);
|
|
229
|
-
} else {
|
|
230
|
-
teardown();
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
const style = document.createElement("style");
|
|
234
|
-
style.textContent = STYLE2;
|
|
235
|
-
shadow.appendChild(style);
|
|
236
|
-
const wrap = document.createElement("div");
|
|
237
|
-
wrap.className = "wrap";
|
|
238
|
-
shadow.appendChild(wrap);
|
|
239
|
-
function card() {
|
|
240
|
-
wrap.innerHTML = "";
|
|
241
|
-
const c = document.createElement("div");
|
|
242
|
-
c.className = "card";
|
|
243
|
-
wrap.appendChild(c);
|
|
244
|
-
return c;
|
|
245
|
-
}
|
|
246
|
-
function withClose(c) {
|
|
247
|
-
const x = document.createElement("button");
|
|
248
|
-
x.className = "x";
|
|
249
|
-
x.textContent = "\xD7";
|
|
250
|
-
x.setAttribute("aria-label", "Dismiss");
|
|
251
|
-
x.onclick = () => finish({ dismissed: true }, false);
|
|
252
|
-
c.appendChild(x);
|
|
253
|
-
}
|
|
254
|
-
function question() {
|
|
255
|
-
var _a2, _b, _c;
|
|
256
|
-
const c = card();
|
|
257
|
-
withClose(c);
|
|
258
|
-
const q = document.createElement("p");
|
|
259
|
-
q.className = "q";
|
|
260
|
-
q.textContent = config.question;
|
|
261
|
-
c.appendChild(q);
|
|
262
|
-
for (const opt of ((_a2 = config.options) != null ? _a2 : []).slice(0, 6)) {
|
|
263
|
-
const b = document.createElement("button");
|
|
264
|
-
b.className = "opt";
|
|
265
|
-
b.textContent = opt;
|
|
266
|
-
b.onclick = () => finish({ choice: opt }, true);
|
|
267
|
-
c.appendChild(b);
|
|
268
|
-
}
|
|
269
|
-
if (config.allow_text) {
|
|
270
|
-
const se = document.createElement("button");
|
|
271
|
-
se.className = "opt";
|
|
272
|
-
se.textContent = ((_c = (_b = config.options) == null ? void 0 : _b.length) != null ? _c : 0) > 0 ? "Something else\u2026" : "Answer\u2026";
|
|
273
|
-
se.onclick = freeText;
|
|
274
|
-
c.appendChild(se);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
function freeText() {
|
|
278
|
-
const c = card();
|
|
279
|
-
withClose(c);
|
|
280
|
-
const q = document.createElement("p");
|
|
281
|
-
q.className = "q";
|
|
282
|
-
q.textContent = config.question;
|
|
283
|
-
c.appendChild(q);
|
|
284
|
-
const input = document.createElement("input");
|
|
285
|
-
input.type = "text";
|
|
286
|
-
input.placeholder = "In your own words\u2026";
|
|
287
|
-
c.appendChild(input);
|
|
288
|
-
const row = document.createElement("div");
|
|
289
|
-
row.className = "row";
|
|
290
|
-
const send = document.createElement("button");
|
|
291
|
-
send.className = "primary";
|
|
292
|
-
send.textContent = "Send";
|
|
293
|
-
const submit = () => {
|
|
294
|
-
const text = input.value.trim();
|
|
295
|
-
if (!text) {
|
|
296
|
-
finish({ dismissed: true }, false);
|
|
64
|
+
if (r.disposed || r.paused || !eligible(r) || !r.offer) return;
|
|
65
|
+
if (r.popup && !r.popup.closed) {
|
|
66
|
+
r.popup.focus();
|
|
297
67
|
return;
|
|
298
68
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
send.onclick = submit;
|
|
302
|
-
input.onkeydown = (e) => {
|
|
303
|
-
if (e.key === "Enter") submit();
|
|
304
|
-
};
|
|
305
|
-
row.appendChild(send);
|
|
306
|
-
c.appendChild(row);
|
|
307
|
-
try {
|
|
308
|
-
input.focus();
|
|
309
|
-
} catch (e) {
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
function thankYou() {
|
|
313
|
-
const c = card();
|
|
314
|
-
const p = document.createElement("p");
|
|
315
|
-
p.className = "done";
|
|
316
|
-
p.textContent = "Thanks \u2014 that helps.";
|
|
317
|
-
c.appendChild(p);
|
|
318
|
-
}
|
|
319
|
-
try {
|
|
320
|
-
document.body.appendChild(host);
|
|
321
|
-
question();
|
|
322
|
-
} catch (e) {
|
|
323
|
-
finish({ dismissed: true }, false);
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
var STYLE2, THANKS_MS;
|
|
328
|
-
var init_survey = __esm({
|
|
329
|
-
"src/survey.ts"() {
|
|
330
|
-
STYLE2 = `
|
|
331
|
-
:host { all: initial; }
|
|
332
|
-
.wrap { position: fixed; bottom: 20px; right: 20px; z-index: 2147483000;
|
|
333
|
-
width: 340px; max-width: calc(100vw - 32px); font-family: system-ui, -apple-system, sans-serif; }
|
|
334
|
-
.card { position: relative; background: #fff; color: #18181b; border: 1px solid #e4e4e7;
|
|
335
|
-
border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.12); padding: 16px; }
|
|
336
|
-
.q { font-size: 14px; font-weight: 600; margin: 0 0 12px; line-height: 1.35; padding-right: 16px; }
|
|
337
|
-
.row { display: flex; gap: 8px; flex-wrap: wrap; }
|
|
338
|
-
button { font: inherit; font-size: 13px; cursor: pointer; border-radius: 8px; padding: 8px 12px;
|
|
339
|
-
border: 1px solid #e4e4e7; background: #fafafa; color: #18181b; }
|
|
340
|
-
button:hover { background: #f4f4f5; }
|
|
341
|
-
button.primary { background: #18181b; color: #fff; border-color: #18181b; }
|
|
342
|
-
.opt { display: block; width: 100%; text-align: left; margin-bottom: 6px; }
|
|
343
|
-
.x { position: absolute; top: 8px; right: 10px; border: none; background: none; font-size: 16px;
|
|
344
|
-
color: #a1a1aa; padding: 2px 6px; cursor: pointer; }
|
|
345
|
-
.done { font-size: 13px; color: #18181b; margin: 0; }
|
|
346
|
-
input { font: inherit; font-size: 13px; width: 100%; box-sizing: border-box; padding: 8px 10px;
|
|
347
|
-
border: 1px solid #e4e4e7; border-radius: 8px; margin-bottom: 8px; }
|
|
348
|
-
`;
|
|
349
|
-
THANKS_MS = 1100;
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
// src/capture.ts
|
|
354
|
-
init_privacy();
|
|
355
|
-
var TRAIL_MAX = 30;
|
|
356
|
-
var DEAD_CLICK_MS = 700;
|
|
357
|
-
var RAGE_WINDOW_MS = 1e3;
|
|
358
|
-
var RAGE_COUNT = 3;
|
|
359
|
-
function hasDom() {
|
|
360
|
-
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
361
|
-
}
|
|
362
|
-
function createCapture(opts) {
|
|
363
|
-
var _a2, _b;
|
|
364
|
-
const redactSelectors = (_a2 = opts.redact) != null ? _a2 : [];
|
|
365
|
-
const blockSelectors = (_b = opts.block) != null ? _b : [];
|
|
366
|
-
let buf = [];
|
|
367
|
-
let lastError;
|
|
368
|
-
let started = false;
|
|
369
|
-
const subs = [];
|
|
370
|
-
const cleanups = [];
|
|
371
|
-
let recentClicks = [];
|
|
372
|
-
function notify() {
|
|
373
|
-
for (const cb of subs) {
|
|
374
|
-
try {
|
|
375
|
-
cb();
|
|
69
|
+
const hash = new URLSearchParams({ offer: r.offer, device: r.device });
|
|
70
|
+
r.popup = window.open(r.endpoint + "/interview-widget#" + hash, "sightspool-interview", "popup,width=520,height=760");
|
|
376
71
|
} catch (e) {
|
|
377
72
|
}
|
|
73
|
+
};
|
|
74
|
+
r.button = button;
|
|
75
|
+
document.body.appendChild(button);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
if (!r.disposed && generation === r.generation) {
|
|
78
|
+
remove(r);
|
|
79
|
+
status(r, "error");
|
|
378
80
|
}
|
|
81
|
+
} finally {
|
|
82
|
+
window.clearTimeout(timeout);
|
|
83
|
+
if (r.pending === request) r.pending = null;
|
|
379
84
|
}
|
|
380
|
-
function push(type, label) {
|
|
381
|
-
try {
|
|
382
|
-
buf.push({ t: Date.now(), type, label: label ? redactText(label) : void 0 });
|
|
383
|
-
if (buf.length > TRAIL_MAX) buf = buf.slice(-TRAIL_MAX);
|
|
384
|
-
if (opts.debug) console.debug("[sightspool] event", type, label);
|
|
385
|
-
notify();
|
|
386
|
-
} catch (e) {
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
function currentRoute() {
|
|
390
|
-
try {
|
|
391
|
-
return location.pathname + location.search;
|
|
392
|
-
} catch (e) {
|
|
393
|
-
return "";
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
function currentLabel() {
|
|
397
|
-
try {
|
|
398
|
-
return document.title || "";
|
|
399
|
-
} catch (e) {
|
|
400
|
-
return "";
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
function onClick(ev) {
|
|
404
|
-
var _a3;
|
|
405
|
-
try {
|
|
406
|
-
const target = ev.target;
|
|
407
|
-
if (isIgnoredElement(target, blockSelectors)) return;
|
|
408
|
-
const text = target && (((_a3 = target.getAttribute) == null ? void 0 : _a3.call(target, "aria-label")) || target.textContent) || "";
|
|
409
|
-
const label = matchesRedactSelector(target, redactSelectors) ? REDACTED : text.trim().slice(0, 60);
|
|
410
|
-
const t = Date.now();
|
|
411
|
-
recentClicks = recentClicks.filter((ts) => t - ts <= RAGE_WINDOW_MS);
|
|
412
|
-
recentClicks.push(t);
|
|
413
|
-
const isRage = recentClicks.length >= RAGE_COUNT;
|
|
414
|
-
push(isRage ? "rage_click" : "click", label);
|
|
415
|
-
const routeBefore = currentRoute();
|
|
416
|
-
let mutated = false;
|
|
417
|
-
let observer = null;
|
|
418
|
-
try {
|
|
419
|
-
observer = new MutationObserver(() => {
|
|
420
|
-
mutated = true;
|
|
421
|
-
});
|
|
422
|
-
observer.observe(document.body, { childList: true, subtree: true, attributes: true });
|
|
423
|
-
} catch (e) {
|
|
424
|
-
}
|
|
425
|
-
window.setTimeout(() => {
|
|
426
|
-
try {
|
|
427
|
-
observer == null ? void 0 : observer.disconnect();
|
|
428
|
-
if (!mutated && currentRoute() === routeBefore && label) {
|
|
429
|
-
push("dead_click", label);
|
|
430
|
-
}
|
|
431
|
-
} catch (e) {
|
|
432
|
-
}
|
|
433
|
-
}, DEAD_CLICK_MS);
|
|
434
|
-
} catch (e) {
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
function onError(ev) {
|
|
438
|
-
try {
|
|
439
|
-
lastError = String(ev.message || "error");
|
|
440
|
-
push("error", lastError);
|
|
441
|
-
} catch (e) {
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
function onRejection(ev) {
|
|
445
|
-
try {
|
|
446
|
-
const reason = ev.reason;
|
|
447
|
-
lastError = reason instanceof Error ? reason.message : String(reason);
|
|
448
|
-
push("error", lastError);
|
|
449
|
-
} catch (e) {
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
function installRouteTracking() {
|
|
453
|
-
try {
|
|
454
|
-
const fire = () => push("route", currentRoute());
|
|
455
|
-
const origPush = history.pushState;
|
|
456
|
-
const origReplace = history.replaceState;
|
|
457
|
-
history.pushState = function(...args) {
|
|
458
|
-
const r = origPush.apply(this, args);
|
|
459
|
-
fire();
|
|
460
|
-
return r;
|
|
461
|
-
};
|
|
462
|
-
history.replaceState = function(...args) {
|
|
463
|
-
const r = origReplace.apply(this, args);
|
|
464
|
-
fire();
|
|
465
|
-
return r;
|
|
466
|
-
};
|
|
467
|
-
window.addEventListener("popstate", fire);
|
|
468
|
-
cleanups.push(() => {
|
|
469
|
-
history.pushState = origPush;
|
|
470
|
-
history.replaceState = origReplace;
|
|
471
|
-
window.removeEventListener("popstate", fire);
|
|
472
|
-
});
|
|
473
|
-
push("route", currentRoute());
|
|
474
|
-
} catch (e) {
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
function installFetchTracking() {
|
|
478
|
-
try {
|
|
479
|
-
if (typeof window.fetch !== "function") return;
|
|
480
|
-
const orig = window.fetch.bind(window);
|
|
481
|
-
window.fetch = async (...args) => {
|
|
482
|
-
try {
|
|
483
|
-
const res = await orig(...args);
|
|
484
|
-
if (!res.ok) push("request_error", `HTTP ${res.status}`);
|
|
485
|
-
return res;
|
|
486
|
-
} catch (err) {
|
|
487
|
-
push("request_error", err instanceof Error ? err.message : "network error");
|
|
488
|
-
throw err;
|
|
489
|
-
}
|
|
490
|
-
};
|
|
491
|
-
cleanups.push(() => {
|
|
492
|
-
window.fetch = orig;
|
|
493
|
-
});
|
|
494
|
-
} catch (e) {
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
return {
|
|
498
|
-
start() {
|
|
499
|
-
if (started || !hasDom()) return;
|
|
500
|
-
started = true;
|
|
501
|
-
try {
|
|
502
|
-
document.addEventListener("click", onClick, true);
|
|
503
|
-
window.addEventListener("error", onError);
|
|
504
|
-
window.addEventListener("unhandledrejection", onRejection);
|
|
505
|
-
cleanups.push(() => {
|
|
506
|
-
document.removeEventListener("click", onClick, true);
|
|
507
|
-
window.removeEventListener("error", onError);
|
|
508
|
-
window.removeEventListener("unhandledrejection", onRejection);
|
|
509
|
-
});
|
|
510
|
-
installRouteTracking();
|
|
511
|
-
installFetchTracking();
|
|
512
|
-
} catch (e) {
|
|
513
|
-
}
|
|
514
|
-
},
|
|
515
|
-
stop() {
|
|
516
|
-
started = false;
|
|
517
|
-
for (const c of cleanups.splice(0)) {
|
|
518
|
-
try {
|
|
519
|
-
c();
|
|
520
|
-
} catch (e) {
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
},
|
|
524
|
-
trail() {
|
|
525
|
-
return buf.slice();
|
|
526
|
-
},
|
|
527
|
-
route: currentRoute,
|
|
528
|
-
label: currentLabel,
|
|
529
|
-
error() {
|
|
530
|
-
return lastError;
|
|
531
|
-
},
|
|
532
|
-
onEvent(cb) {
|
|
533
|
-
subs.push(cb);
|
|
534
|
-
},
|
|
535
|
-
recordSearch(query, zeroResult) {
|
|
536
|
-
const q = query.trim();
|
|
537
|
-
if (!q) return;
|
|
538
|
-
push(zeroResult ? "zero_result" : "search", q);
|
|
539
|
-
}
|
|
540
|
-
};
|
|
541
85
|
}
|
|
542
|
-
|
|
543
|
-
// src/harvest.ts
|
|
544
|
-
init_privacy();
|
|
545
|
-
var SEARCH_HINT_RE = /search|filter|find|query|command|lookup/i;
|
|
546
|
-
var DEBOUNCE_MS = 800;
|
|
547
|
-
function looksLikeSearch(el) {
|
|
86
|
+
function init(config) {
|
|
548
87
|
try {
|
|
549
|
-
const
|
|
550
|
-
if (
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
].filter(Boolean).join(" ");
|
|
560
|
-
return SEARCH_HINT_RE.test(hay);
|
|
561
|
-
} catch (e) {
|
|
562
|
-
return false;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
function createHarvest(capture, opts) {
|
|
566
|
-
var _a2, _b;
|
|
567
|
-
let hint;
|
|
568
|
-
let timer = null;
|
|
569
|
-
let started = false;
|
|
570
|
-
const redactSelectors = (_a2 = opts.redact) != null ? _a2 : [];
|
|
571
|
-
const blockSelectors = (_b = opts.block) != null ? _b : [];
|
|
572
|
-
function onInput(ev) {
|
|
88
|
+
const browser = host();
|
|
89
|
+
if (!browser || !config || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(config.key)) return;
|
|
90
|
+
if (config.audience !== "all_visitors" && config.audience !== "signed_in") return;
|
|
91
|
+
const url = new URL(config.endpoint || "https://www.sightspool.com");
|
|
92
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname))) return;
|
|
93
|
+
if (url.username || url.password) return;
|
|
94
|
+
const previous = current();
|
|
95
|
+
if (previous && previous.key === config.key && previous.endpoint === url.origin && previous.audience === config.audience) return;
|
|
96
|
+
if (previous) destroy();
|
|
97
|
+
let device = "";
|
|
573
98
|
try {
|
|
574
|
-
|
|
575
|
-
if (!target || target.tagName !== "INPUT" && target.tagName !== "TEXTAREA") return;
|
|
576
|
-
if (!looksLikeSearch(target)) return;
|
|
577
|
-
if (isIgnoredElement(target, blockSelectors) || matchesRedactSelector(target, redactSelectors))
|
|
578
|
-
return;
|
|
579
|
-
const value = (target.value || "").trim();
|
|
580
|
-
if (value.length < 2) return;
|
|
581
|
-
if (timer !== null) window.clearTimeout(timer);
|
|
582
|
-
timer = window.setTimeout(() => {
|
|
583
|
-
hint = value;
|
|
584
|
-
capture.recordSearch(value);
|
|
585
|
-
if (opts.debug) console.debug("[sightspool] harvested intent", value);
|
|
586
|
-
}, DEBOUNCE_MS);
|
|
99
|
+
device = sessionStorage.getItem("sightspool-widget-device:" + config.key) || "";
|
|
587
100
|
} catch (e) {
|
|
588
101
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
if (started || typeof document === "undefined") return;
|
|
593
|
-
started = true;
|
|
594
|
-
try {
|
|
595
|
-
document.addEventListener("input", onInput, true);
|
|
596
|
-
} catch (e) {
|
|
597
|
-
}
|
|
598
|
-
},
|
|
599
|
-
stop() {
|
|
600
|
-
started = false;
|
|
102
|
+
if (!/^ss_fcd_[A-Za-z0-9_-]{43}$/.test(device)) {
|
|
103
|
+
const bytes = crypto.getRandomValues(new Uint8Array(32));
|
|
104
|
+
device = "ss_fcd_" + btoa(String.fromCharCode(...bytes)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
601
105
|
try {
|
|
602
|
-
|
|
603
|
-
if (timer !== null) window.clearTimeout(timer);
|
|
106
|
+
sessionStorage.setItem("sightspool-widget-device:" + config.key, device);
|
|
604
107
|
} catch (e) {
|
|
605
108
|
}
|
|
606
|
-
},
|
|
607
|
-
lastIntentHint() {
|
|
608
|
-
return hint;
|
|
609
109
|
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
if (ok) {
|
|
631
|
-
if (opts.debug) console.debug("[sightspool] beacon", signals.length);
|
|
632
|
-
return;
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
void fetch(url, {
|
|
636
|
-
method: "POST",
|
|
637
|
-
headers: { "Content-Type": "text/plain" },
|
|
638
|
-
body: json,
|
|
639
|
-
keepalive: true,
|
|
640
|
-
mode: "cors",
|
|
641
|
-
credentials: "omit"
|
|
642
|
-
}).catch(() => {
|
|
643
|
-
});
|
|
644
|
-
} catch (e) {
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
function onVisibility() {
|
|
648
|
-
try {
|
|
649
|
-
if (document.visibilityState === "hidden") flush();
|
|
650
|
-
} catch (e) {
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
function flush() {
|
|
654
|
-
if (queue.length === 0) return;
|
|
655
|
-
const batch = queue;
|
|
656
|
-
queue = [];
|
|
657
|
-
send(batch);
|
|
658
|
-
}
|
|
659
|
-
return {
|
|
660
|
-
start() {
|
|
661
|
-
if (started || typeof window === "undefined") return;
|
|
662
|
-
started = true;
|
|
663
|
-
try {
|
|
664
|
-
document.addEventListener("visibilitychange", onVisibility);
|
|
665
|
-
window.addEventListener("pagehide", flush);
|
|
666
|
-
interval = window.setInterval(flush, FLUSH_INTERVAL_MS);
|
|
667
|
-
} catch (e) {
|
|
668
|
-
}
|
|
669
|
-
},
|
|
670
|
-
stop() {
|
|
671
|
-
started = false;
|
|
110
|
+
const r = {
|
|
111
|
+
key: config.key,
|
|
112
|
+
endpoint: url.origin,
|
|
113
|
+
audience: config.audience,
|
|
114
|
+
identified: false,
|
|
115
|
+
paused: false,
|
|
116
|
+
disposed: false,
|
|
117
|
+
generation: 0,
|
|
118
|
+
device,
|
|
119
|
+
offer: null,
|
|
120
|
+
button: null,
|
|
121
|
+
popup: null,
|
|
122
|
+
pending: null,
|
|
123
|
+
timer: 0,
|
|
124
|
+
visibility: () => {
|
|
125
|
+
},
|
|
126
|
+
status: "signed_out"
|
|
127
|
+
};
|
|
128
|
+
browser[slot] = r;
|
|
129
|
+
r.visibility = () => {
|
|
672
130
|
try {
|
|
673
|
-
document.
|
|
674
|
-
|
|
675
|
-
|
|
131
|
+
if (document.visibilityState === "visible") void check(r);
|
|
132
|
+
else {
|
|
133
|
+
invalidate(r);
|
|
134
|
+
status(r, r.paused ? "paused" : eligible(r) ? "unavailable" : "signed_out");
|
|
135
|
+
}
|
|
676
136
|
} catch (e) {
|
|
677
137
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
flush,
|
|
685
|
-
setIdentity(next) {
|
|
686
|
-
identity = next;
|
|
687
|
-
}
|
|
688
|
-
};
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
// src/triggers.ts
|
|
692
|
-
var RAGE_CLICK_COUNT = 3;
|
|
693
|
-
var RAGE_WINDOW_MS2 = 1e3;
|
|
694
|
-
var FRICTION_RETRY_COUNT = 3;
|
|
695
|
-
var FRICTION_WINDOW_MS = 8e3;
|
|
696
|
-
function detectFriction(trail, now, windowMs = FRICTION_WINDOW_MS) {
|
|
697
|
-
var _a2;
|
|
698
|
-
const recent = trail.filter((e) => now - e.t <= windowMs);
|
|
699
|
-
if (recent.some((e) => e.type === "error" || e.type === "request_error")) return "error";
|
|
700
|
-
const clicks = recent.filter((e) => e.type === "click" || e.type === "rage_click");
|
|
701
|
-
for (let i = 0; i < clicks.length; i++) {
|
|
702
|
-
const burst = clicks.filter(
|
|
703
|
-
(e) => e.t >= clicks[i].t && e.t - clicks[i].t <= RAGE_WINDOW_MS2
|
|
704
|
-
);
|
|
705
|
-
if (burst.length >= RAGE_CLICK_COUNT) return "rage";
|
|
706
|
-
}
|
|
707
|
-
if (recent.some((e) => e.type === "dead_click")) return "dead_end";
|
|
708
|
-
const byLabel = /* @__PURE__ */ new Map();
|
|
709
|
-
for (const e of clicks) {
|
|
710
|
-
if (!e.label) continue;
|
|
711
|
-
const n = ((_a2 = byLabel.get(e.label)) != null ? _a2 : 0) + 1;
|
|
712
|
-
byLabel.set(e.label, n);
|
|
713
|
-
if (n >= FRICTION_RETRY_COUNT) return "retry";
|
|
714
|
-
}
|
|
715
|
-
return null;
|
|
716
|
-
}
|
|
717
|
-
var DEFAULT_CAPS = {
|
|
718
|
-
maxPromptsPerSession: 1,
|
|
719
|
-
cooldownMs: 5 * 6e4
|
|
720
|
-
};
|
|
721
|
-
function canPrompt(state, now, caps = DEFAULT_CAPS) {
|
|
722
|
-
if (state.promptsShown >= caps.maxPromptsPerSession) return false;
|
|
723
|
-
if (state.lastPromptAt !== null && now - state.lastPromptAt < caps.cooldownMs) return false;
|
|
724
|
-
return true;
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
// src/intervention.ts
|
|
728
|
-
var RENDERABLE = /* @__PURE__ */ new Set(["survey"]);
|
|
729
|
-
function str(v, max) {
|
|
730
|
-
if (typeof v !== "string") return void 0;
|
|
731
|
-
const t = v.trim();
|
|
732
|
-
return t ? t.slice(0, max) : void 0;
|
|
733
|
-
}
|
|
734
|
-
function buildServeContext(route, identity) {
|
|
735
|
-
const ctx = {};
|
|
736
|
-
const r = str(route, 500);
|
|
737
|
-
if (r) ctx.route = r;
|
|
738
|
-
const account = str(identity == null ? void 0 : identity.account, 200);
|
|
739
|
-
if (account) ctx.account = account;
|
|
740
|
-
const plan = str(identity == null ? void 0 : identity.plan, 80);
|
|
741
|
-
if (plan) ctx.plan = plan;
|
|
742
|
-
return ctx;
|
|
743
|
-
}
|
|
744
|
-
function normalizeServed(raw) {
|
|
745
|
-
if (!raw || typeof raw !== "object") return null;
|
|
746
|
-
const r = raw;
|
|
747
|
-
const id = str(r.id, 64);
|
|
748
|
-
const type = str(r.type, 40);
|
|
749
|
-
if (!id || !type || !RENDERABLE.has(type)) return null;
|
|
750
|
-
const cfg = r.config && typeof r.config === "object" ? r.config : {};
|
|
751
|
-
const question = str(cfg.question, 500);
|
|
752
|
-
if (!question) return null;
|
|
753
|
-
const options = Array.isArray(cfg.options) ? cfg.options.map((o) => str(o, 200)).filter((o) => !!o).slice(0, 6) : void 0;
|
|
754
|
-
const config = {
|
|
755
|
-
question,
|
|
756
|
-
...options && options.length ? { options } : {},
|
|
757
|
-
allow_text: cfg.allow_text === true
|
|
758
|
-
};
|
|
759
|
-
return { id, type, config };
|
|
760
|
-
}
|
|
761
|
-
function pickRespondentKey(userId, persisted, sessionRef) {
|
|
762
|
-
const uid = str(userId, 200);
|
|
763
|
-
if (uid) return uid;
|
|
764
|
-
const p = str(persisted, 200);
|
|
765
|
-
if (p) return p;
|
|
766
|
-
return sessionRef;
|
|
767
|
-
}
|
|
768
|
-
var RK_STORAGE_KEY = "sightspool_rk";
|
|
769
|
-
function getRespondentKey(identity, sessionRef) {
|
|
770
|
-
const uid = str(identity == null ? void 0 : identity.userId, 200);
|
|
771
|
-
if (uid) return uid;
|
|
772
|
-
try {
|
|
773
|
-
let v = localStorage.getItem(RK_STORAGE_KEY);
|
|
774
|
-
if (!v) {
|
|
775
|
-
v = "anon-" + Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
776
|
-
localStorage.setItem(RK_STORAGE_KEY, v);
|
|
777
|
-
}
|
|
778
|
-
return pickRespondentKey(void 0, v, sessionRef);
|
|
779
|
-
} catch (e) {
|
|
780
|
-
return sessionRef;
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
function serveUrl(endpoint, path) {
|
|
784
|
-
return `${endpoint.replace(/\/+$/, "")}/api/sdk/${path}`;
|
|
785
|
-
}
|
|
786
|
-
async function fetchIntervention(opts) {
|
|
787
|
-
var _a2;
|
|
788
|
-
try {
|
|
789
|
-
if (typeof fetch !== "function") return null;
|
|
790
|
-
const res = await fetch(serveUrl(opts.endpoint, "serve"), {
|
|
791
|
-
method: "POST",
|
|
792
|
-
headers: { "Content-Type": "text/plain" },
|
|
793
|
-
body: JSON.stringify({
|
|
794
|
-
key: opts.key,
|
|
795
|
-
context: opts.ctx,
|
|
796
|
-
respondent_key: opts.respondentKey
|
|
797
|
-
}),
|
|
798
|
-
mode: "cors",
|
|
799
|
-
credentials: "omit"
|
|
800
|
-
});
|
|
801
|
-
if (!res.ok) return null;
|
|
802
|
-
const data = await res.json();
|
|
803
|
-
const served = normalizeServed(data == null ? void 0 : data.intervention);
|
|
804
|
-
if (opts.debug) console.debug("[sightspool] serve", (_a2 = served == null ? void 0 : served.id) != null ? _a2 : "(none)");
|
|
805
|
-
return served;
|
|
806
|
-
} catch (e) {
|
|
807
|
-
return null;
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
function submitResponse(opts) {
|
|
811
|
-
try {
|
|
812
|
-
const url = serveUrl(opts.endpoint, "respond");
|
|
813
|
-
const json = JSON.stringify({
|
|
814
|
-
key: opts.key,
|
|
815
|
-
intervention_id: opts.interventionId,
|
|
816
|
-
response: opts.response,
|
|
817
|
-
respondent_key: opts.respondentKey
|
|
818
|
-
});
|
|
819
|
-
if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
|
|
820
|
-
const blob = new Blob([json], { type: "text/plain" });
|
|
821
|
-
if (navigator.sendBeacon(url, blob)) return;
|
|
822
|
-
}
|
|
823
|
-
if (typeof fetch === "function") {
|
|
824
|
-
void fetch(url, {
|
|
825
|
-
method: "POST",
|
|
826
|
-
headers: { "Content-Type": "text/plain" },
|
|
827
|
-
body: json,
|
|
828
|
-
keepalive: true,
|
|
829
|
-
mode: "cors",
|
|
830
|
-
credentials: "omit"
|
|
831
|
-
}).catch(() => {
|
|
832
|
-
});
|
|
833
|
-
}
|
|
834
|
-
} catch (e) {
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
// src/env.ts
|
|
839
|
-
var LOCAL_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "0.0.0.0", "::1", ""]);
|
|
840
|
-
function isLocalhost(hostname) {
|
|
841
|
-
const h = (hostname != null ? hostname : "").trim().toLowerCase();
|
|
842
|
-
if (LOCAL_HOSTS.has(h)) return true;
|
|
843
|
-
return h.endsWith(".local") || h.endsWith(".localhost");
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
// src/index.ts
|
|
847
|
-
var DEFAULT_ENDPOINT = "https://www.sightspool.com";
|
|
848
|
-
var FRICTION_EMIT_COOLDOWN_MS = 3e4;
|
|
849
|
-
var EVENT_DEBOUNCE_MS = 600;
|
|
850
|
-
var SERVE_SETTLE_MS = 2500;
|
|
851
|
-
var MAX_INTERVENTIONS_PER_SESSION = 1;
|
|
852
|
-
function currentHostname() {
|
|
853
|
-
try {
|
|
854
|
-
return typeof location !== "undefined" ? location.hostname : "";
|
|
138
|
+
};
|
|
139
|
+
document.addEventListener("visibilitychange", r.visibility);
|
|
140
|
+
r.timer = window.setInterval(() => {
|
|
141
|
+
void check(r);
|
|
142
|
+
}, 15e3);
|
|
143
|
+
if (eligible(r)) void check(r);
|
|
855
144
|
} catch (e) {
|
|
856
|
-
return "";
|
|
857
145
|
}
|
|
858
146
|
}
|
|
859
|
-
|
|
860
|
-
function uuid() {
|
|
147
|
+
function identify(userId) {
|
|
861
148
|
try {
|
|
862
|
-
|
|
863
|
-
|
|
149
|
+
const r = current();
|
|
150
|
+
if (!r) return;
|
|
151
|
+
const identified = typeof userId === "string" && userId.trim().length > 0;
|
|
152
|
+
if (!identified && !r.identified) {
|
|
153
|
+
if (!r.paused && eligible(r)) void check(r);
|
|
154
|
+
return;
|
|
864
155
|
}
|
|
156
|
+
invalidate(r);
|
|
157
|
+
r.identified = identified;
|
|
158
|
+
status(r, r.paused ? "paused" : eligible(r) ? "unavailable" : "signed_out");
|
|
159
|
+
if (eligible(r) && !r.paused) void check(r);
|
|
865
160
|
} catch (e) {
|
|
866
161
|
}
|
|
867
|
-
return "s-" + Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
868
162
|
}
|
|
869
|
-
function
|
|
870
|
-
const out = [];
|
|
871
|
-
const hint = c.harvest.lastIntentHint();
|
|
872
|
-
if (hint) out.push(`Searching for \u201C${hint}\u201D`);
|
|
873
|
-
const label = c.capture.label();
|
|
874
|
-
if (label) out.push(`Something on \u201C${label.slice(0, 40)}\u201D`);
|
|
875
|
-
return out;
|
|
876
|
-
}
|
|
877
|
-
function buildSignal(c, trigger, extra = {}) {
|
|
878
|
-
const err = c.capture.error();
|
|
879
|
-
return {
|
|
880
|
-
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
881
|
-
route: c.capture.route(),
|
|
882
|
-
client_label: c.capture.label(),
|
|
883
|
-
trail: c.capture.trail(),
|
|
884
|
-
session_ref: c.sessionRef,
|
|
885
|
-
trigger,
|
|
886
|
-
intent_hint: c.harvest.lastIntentHint(),
|
|
887
|
-
error: err,
|
|
888
|
-
outcome: err || trigger === "friction" ? "failed" : "unknown",
|
|
889
|
-
...extra
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
|
-
async function maybePrompt(c, trigger) {
|
|
893
|
-
var _a2;
|
|
894
|
-
const now = Date.now();
|
|
895
|
-
if (canPrompt(c.fatigue, now, DEFAULT_CAPS)) {
|
|
896
|
-
c.fatigue.promptsShown += 1;
|
|
897
|
-
c.fatigue.lastPromptAt = now;
|
|
898
|
-
try {
|
|
899
|
-
const { showPrompt: showPrompt2 } = await Promise.resolve().then(() => (init_prompt(), prompt_exports));
|
|
900
|
-
const result = await showPrompt2({ candidates: deriveCandidates(c) });
|
|
901
|
-
c.egress.enqueue(
|
|
902
|
-
buildSignal(c, trigger, {
|
|
903
|
-
answer: result.answer,
|
|
904
|
-
verbatim: result.verbatim,
|
|
905
|
-
intent_hint: (_a2 = result.intent) != null ? _a2 : c.harvest.lastIntentHint(),
|
|
906
|
-
outcome: result.answer === "yes" ? "achieved" : "failed"
|
|
907
|
-
})
|
|
908
|
-
);
|
|
909
|
-
} catch (e) {
|
|
910
|
-
c.egress.enqueue(buildSignal(c, trigger));
|
|
911
|
-
}
|
|
912
|
-
} else {
|
|
913
|
-
c.egress.enqueue(buildSignal(c, trigger));
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
async function maybeServeIntervention(c) {
|
|
917
|
-
if (!c.running || !c.interventionsEnabled || c.suppressed) return;
|
|
918
|
-
if (c.surveyOnScreen) return;
|
|
919
|
-
if (c.interventionsShown >= MAX_INTERVENTIONS_PER_SESSION) return;
|
|
920
|
-
const now = Date.now();
|
|
921
|
-
if (c.fatigue.lastPromptAt !== null && now - c.fatigue.lastPromptAt < DEFAULT_CAPS.cooldownMs)
|
|
922
|
-
return;
|
|
923
|
-
const respondentKey = getRespondentKey(c.identity, c.sessionRef);
|
|
924
|
-
const served = await fetchIntervention({
|
|
925
|
-
endpoint: c.config.endpoint,
|
|
926
|
-
key: c.config.key,
|
|
927
|
-
ctx: buildServeContext(c.capture.route(), c.identity),
|
|
928
|
-
respondentKey,
|
|
929
|
-
debug: c.config.debug
|
|
930
|
-
});
|
|
931
|
-
if (!served || !c.running) return;
|
|
932
|
-
c.surveyOnScreen = true;
|
|
933
|
-
c.interventionsShown += 1;
|
|
934
|
-
c.fatigue.lastPromptAt = Date.now();
|
|
163
|
+
function pause() {
|
|
935
164
|
try {
|
|
936
|
-
const
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
key: c.config.key,
|
|
942
|
-
interventionId: served.id,
|
|
943
|
-
response: { choice: result.choice, text: result.text },
|
|
944
|
-
respondentKey
|
|
945
|
-
});
|
|
165
|
+
const r = current();
|
|
166
|
+
if (r) {
|
|
167
|
+
r.paused = true;
|
|
168
|
+
invalidate(r);
|
|
169
|
+
status(r, "paused");
|
|
946
170
|
}
|
|
947
171
|
} catch (e) {
|
|
948
|
-
} finally {
|
|
949
|
-
c.surveyOnScreen = false;
|
|
950
172
|
}
|
|
951
173
|
}
|
|
952
|
-
function
|
|
953
|
-
const c = ctrl;
|
|
954
|
-
if (!c || !c.running) return;
|
|
174
|
+
function resume() {
|
|
955
175
|
try {
|
|
956
|
-
const
|
|
957
|
-
if (
|
|
958
|
-
|
|
959
|
-
|
|
176
|
+
const r = current();
|
|
177
|
+
if (r) {
|
|
178
|
+
r.paused = false;
|
|
179
|
+
if (!eligible(r)) status(r, "signed_out");
|
|
180
|
+
void check(r);
|
|
960
181
|
}
|
|
961
182
|
} catch (e) {
|
|
962
183
|
}
|
|
963
|
-
if (c.eventTimer !== null) return;
|
|
964
|
-
c.eventTimer = (typeof window !== "undefined" ? window.setTimeout : setTimeout)(() => {
|
|
965
|
-
c.eventTimer = null;
|
|
966
|
-
try {
|
|
967
|
-
const now = Date.now();
|
|
968
|
-
if (now - c.lastFrictionEmitAt < FRICTION_EMIT_COOLDOWN_MS) return;
|
|
969
|
-
const kind = detectFriction(c.capture.trail(), now);
|
|
970
|
-
if (!kind) return;
|
|
971
|
-
c.lastFrictionEmitAt = now;
|
|
972
|
-
void maybePrompt(c, "friction");
|
|
973
|
-
} catch (e) {
|
|
974
|
-
}
|
|
975
|
-
}, EVENT_DEBOUNCE_MS);
|
|
976
184
|
}
|
|
977
|
-
function
|
|
978
|
-
const c = ctrl;
|
|
979
|
-
if (!c || !c.running || !c.config.boundaryAsk) return;
|
|
185
|
+
function destroy() {
|
|
980
186
|
try {
|
|
981
|
-
|
|
187
|
+
const r = current();
|
|
188
|
+
if (!r) return;
|
|
189
|
+
r.disposed = true;
|
|
190
|
+
invalidate(r);
|
|
191
|
+
window.clearInterval(r.timer);
|
|
192
|
+
document.removeEventListener("visibilitychange", r.visibility);
|
|
193
|
+
delete host()[slot];
|
|
982
194
|
} catch (e) {
|
|
983
195
|
}
|
|
984
196
|
}
|
|
985
|
-
function
|
|
986
|
-
|
|
987
|
-
if (c.suppressed) {
|
|
988
|
-
if (c.config.debug)
|
|
989
|
-
console.debug(
|
|
990
|
-
"[sightspool] capture suppressed on localhost (set captureOnLocalhost:true to override)"
|
|
991
|
-
);
|
|
992
|
-
return;
|
|
993
|
-
}
|
|
994
|
-
c.running = true;
|
|
995
|
-
c.capture.start();
|
|
996
|
-
c.harvest.start();
|
|
997
|
-
c.egress.start();
|
|
998
|
-
c.capture.onEvent(onCaptureEvent);
|
|
197
|
+
function getStatus() {
|
|
198
|
+
var _a, _b;
|
|
999
199
|
try {
|
|
1000
|
-
|
|
200
|
+
return (_b = (_a = current()) == null ? void 0 : _a.status) != null ? _b : "not_initialized";
|
|
1001
201
|
} catch (e) {
|
|
202
|
+
return "error";
|
|
1002
203
|
}
|
|
1003
|
-
if (c.interventionsEnabled) {
|
|
1004
|
-
c.lastServeRoute = (() => {
|
|
1005
|
-
try {
|
|
1006
|
-
return c.capture.route();
|
|
1007
|
-
} catch (e) {
|
|
1008
|
-
return null;
|
|
1009
|
-
}
|
|
1010
|
-
})();
|
|
1011
|
-
(typeof window !== "undefined" ? window.setTimeout : setTimeout)(() => {
|
|
1012
|
-
void maybeServeIntervention(c);
|
|
1013
|
-
}, SERVE_SETTLE_MS);
|
|
1014
|
-
}
|
|
1015
|
-
if (c.config.debug) console.debug("[sightspool] started", c.sessionRef);
|
|
1016
|
-
}
|
|
1017
|
-
function init(config) {
|
|
1018
|
-
try {
|
|
1019
|
-
if (!config || !config.key) {
|
|
1020
|
-
console.warn("[sightspool] init: a `key` is required");
|
|
1021
|
-
return;
|
|
1022
|
-
}
|
|
1023
|
-
if (ctrl) return;
|
|
1024
|
-
const endpoint = config.endpoint || DEFAULT_ENDPOINT;
|
|
1025
|
-
const privacyOpts = { redact: config.redact, block: config.block };
|
|
1026
|
-
const capture = createCapture({ debug: !!config.debug, ...privacyOpts });
|
|
1027
|
-
const harvest = createHarvest(capture, { debug: !!config.debug, ...privacyOpts });
|
|
1028
|
-
const egress = createEgress({ key: config.key, endpoint, debug: !!config.debug });
|
|
1029
|
-
ctrl = {
|
|
1030
|
-
config: {
|
|
1031
|
-
...config,
|
|
1032
|
-
key: config.key,
|
|
1033
|
-
endpoint,
|
|
1034
|
-
boundaryAsk: config.boundaryAsk !== false,
|
|
1035
|
-
debug: !!config.debug
|
|
1036
|
-
},
|
|
1037
|
-
capture,
|
|
1038
|
-
harvest,
|
|
1039
|
-
egress,
|
|
1040
|
-
identity: {},
|
|
1041
|
-
sessionRef: uuid(),
|
|
1042
|
-
fatigue: { promptsShown: 0, lastPromptAt: null },
|
|
1043
|
-
lastFrictionEmitAt: 0,
|
|
1044
|
-
eventTimer: null,
|
|
1045
|
-
running: false,
|
|
1046
|
-
suppressed: isLocalhost(currentHostname()) && config.captureOnLocalhost !== true,
|
|
1047
|
-
interventionsEnabled: config.interventions !== false,
|
|
1048
|
-
lastServeRoute: null,
|
|
1049
|
-
surveyOnScreen: false,
|
|
1050
|
-
interventionsShown: 0
|
|
1051
|
-
};
|
|
1052
|
-
if (config.consent !== false) startRuntime(ctrl);
|
|
1053
|
-
} catch (err) {
|
|
1054
|
-
try {
|
|
1055
|
-
console.warn("[sightspool] init failed", err);
|
|
1056
|
-
} catch (e) {
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
function identify(userId, traits) {
|
|
1061
|
-
try {
|
|
1062
|
-
if (!ctrl) return;
|
|
1063
|
-
ctrl.identity = { userId, account: traits == null ? void 0 : traits.account, plan: traits == null ? void 0 : traits.plan };
|
|
1064
|
-
ctrl.egress.setIdentity(ctrl.identity);
|
|
1065
|
-
} catch (e) {
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
function start() {
|
|
1069
|
-
try {
|
|
1070
|
-
if (ctrl) startRuntime(ctrl);
|
|
1071
|
-
} catch (e) {
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
function consent(granted) {
|
|
1075
|
-
try {
|
|
1076
|
-
if (!ctrl) return;
|
|
1077
|
-
if (granted) startRuntime(ctrl);
|
|
1078
|
-
else stop();
|
|
1079
|
-
} catch (e) {
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
function stop() {
|
|
1083
|
-
try {
|
|
1084
|
-
if (!ctrl) return;
|
|
1085
|
-
ctrl.running = false;
|
|
1086
|
-
ctrl.capture.stop();
|
|
1087
|
-
ctrl.harvest.stop();
|
|
1088
|
-
ctrl.egress.stop();
|
|
1089
|
-
try {
|
|
1090
|
-
document.removeEventListener("mouseout", onExitIntent);
|
|
1091
|
-
} catch (e) {
|
|
1092
|
-
}
|
|
1093
|
-
} catch (e) {
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
var api = { init, identify, start, stop, consent };
|
|
1097
|
-
var src_default = api;
|
|
1098
|
-
var _a;
|
|
1099
|
-
try {
|
|
1100
|
-
if (typeof document !== "undefined") {
|
|
1101
|
-
const el = (_a = document.currentScript) != null ? _a : document.querySelector("script[data-sightspool-key]");
|
|
1102
|
-
const key = el == null ? void 0 : el.getAttribute("data-sightspool-key");
|
|
1103
|
-
if (key) {
|
|
1104
|
-
let endpoint = (el == null ? void 0 : el.getAttribute("data-sightspool-endpoint")) || void 0;
|
|
1105
|
-
if (!endpoint && (el == null ? void 0 : el.src)) {
|
|
1106
|
-
try {
|
|
1107
|
-
endpoint = new URL(el.src).origin;
|
|
1108
|
-
} catch (e) {
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
const list = (attr) => {
|
|
1112
|
-
const raw = el == null ? void 0 : el.getAttribute(attr);
|
|
1113
|
-
if (!raw) return void 0;
|
|
1114
|
-
const out = raw.split(",").map((s) => s.trim()).filter(Boolean);
|
|
1115
|
-
return out.length ? out : void 0;
|
|
1116
|
-
};
|
|
1117
|
-
init({
|
|
1118
|
-
key,
|
|
1119
|
-
endpoint,
|
|
1120
|
-
redact: list("data-sightspool-redact"),
|
|
1121
|
-
block: list("data-sightspool-block"),
|
|
1122
|
-
captureOnLocalhost: (el == null ? void 0 : el.hasAttribute("data-sightspool-capture-localhost")) || void 0,
|
|
1123
|
-
interventions: (el == null ? void 0 : el.hasAttribute("data-sightspool-no-interventions")) ? false : void 0,
|
|
1124
|
-
debug: (el == null ? void 0 : el.hasAttribute("data-sightspool-debug")) || void 0
|
|
1125
|
-
});
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
} catch (e) {
|
|
1129
204
|
}
|
|
1130
205
|
|
|
1131
|
-
|
|
206
|
+
// src/index.ts
|
|
207
|
+
var src_default = { init, identify, pause, resume, destroy, getStatus };
|
|
208
|
+
|
|
1132
209
|
exports.default = src_default;
|
|
210
|
+
exports.destroy = destroy;
|
|
211
|
+
exports.getStatus = getStatus;
|
|
1133
212
|
exports.identify = identify;
|
|
1134
213
|
exports.init = init;
|
|
1135
|
-
exports.
|
|
1136
|
-
exports.
|
|
214
|
+
exports.pause = pause;
|
|
215
|
+
exports.resume = resume;
|
|
1137
216
|
//# sourceMappingURL=index.cjs.map
|
|
1138
217
|
//# sourceMappingURL=index.cjs.map
|