@saar-ai/web-widget 0.18.0 → 0.21.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/dist/chunks/{chat-DHMjOVms.js → chat-DrpWeT5w.js} +26 -1
- package/dist/chunks/{form-fill-dom-D4ZMwxX1.js → form-fill-dom-DtxCQumL.js} +114 -15
- package/dist/chunks/{host-widget-BhtqtvaY.js → host-widget-D675mXsN.js} +276 -74
- package/dist/concierge-shell.css +1 -1
- package/dist/dock/dock-sheet.d.ts.map +1 -1
- package/dist/form-fill/form-fill-dom.d.ts +16 -13
- package/dist/form-fill/form-fill-dom.d.ts.map +1 -1
- package/dist/generated/concierge-shell-css.d.ts.map +1 -1
- package/dist/generated/widget-css.d.ts.map +1 -1
- package/dist/host-widget.d.ts.map +1 -1
- package/dist/index.js +14 -14
- package/dist/messages.d.ts +13 -0
- package/dist/messages.d.ts.map +1 -1
- package/dist/next/index.js +1 -1
- package/dist/scroll-row.d.ts +29 -0
- package/dist/scroll-row.d.ts.map +1 -0
- package/dist/spoken-transcript.d.ts +2 -0
- package/dist/spoken-transcript.d.ts.map +1 -1
- package/dist/turn-order.d.ts +2 -1
- package/dist/turn-order.d.ts.map +1 -1
- package/dist/use-chat-session.d.ts.map +1 -1
- package/dist/use-voice-session.d.ts.map +1 -1
- package/dist/widget/call-view.d.ts +32 -2
- package/dist/widget/call-view.d.ts.map +1 -1
- package/dist/widget/concierge-launcher.d.ts +6 -1
- package/dist/widget/concierge-launcher.d.ts.map +1 -1
- package/dist/widget/concierge-shell.d.ts +2 -0
- package/dist/widget/concierge-shell.d.ts.map +1 -1
- package/dist/widget/launcher-look.d.ts.map +1 -1
- package/dist/widget/mic-button.d.ts +4 -0
- package/dist/widget/mic-button.d.ts.map +1 -1
- package/dist/widget/shell-renderer.d.ts +1 -1
- package/dist/widget/shell-renderer.d.ts.map +1 -1
- package/dist/widget-cards.d.ts.map +1 -1
- package/dist/widget-cart-summary.d.ts.map +1 -1
- package/dist/widget.css +1 -1
- package/package.json +11 -7
- package/src/styles/call-view.css +13 -3
- package/src/styles/concierge-shell-entry.css +1 -0
- package/src/styles/concierge.css +3 -0
- package/src/styles/scroll-row.css +62 -0
- package/src/styles/tokens.css +1 -1
- package/src/styles/widget-entry.css +1 -0
|
@@ -309,6 +309,30 @@ var WidgetChatFillFormEventSchema = object({
|
|
|
309
309
|
fields: array(WidgetFillFormFieldSchema).min(1).max(30),
|
|
310
310
|
submit: boolean()
|
|
311
311
|
}).strict();
|
|
312
|
+
/**
|
|
313
|
+
* The widget reporting how a fill went, so the concierge can say "filled,
|
|
314
|
+
* press Send" or "the form is not on this page" (SAA-497). Enums and a count
|
|
315
|
+
* only: never a value, a selector or a control name. Client-asserted like
|
|
316
|
+
* every report; the enquiry was recorded before the fill was asked for.
|
|
317
|
+
*/
|
|
318
|
+
var WidgetFormFillReportSchema = object({
|
|
319
|
+
kind: literal("form_fill"),
|
|
320
|
+
outcome: _enum([
|
|
321
|
+
"submitted",
|
|
322
|
+
"needs-visitor",
|
|
323
|
+
"needs-challenge",
|
|
324
|
+
"not-found",
|
|
325
|
+
"refused"
|
|
326
|
+
]),
|
|
327
|
+
filled: number().int().min(0).max(30),
|
|
328
|
+
botProtection: _enum([
|
|
329
|
+
"recaptcha",
|
|
330
|
+
"hcaptcha",
|
|
331
|
+
"turnstile",
|
|
332
|
+
"friendly-captcha",
|
|
333
|
+
"sitekey"
|
|
334
|
+
]).nullable()
|
|
335
|
+
}).strict();
|
|
312
336
|
//#endregion
|
|
313
337
|
//#region ../widget-protocol/dist/chat.js
|
|
314
338
|
/**
|
|
@@ -849,7 +873,8 @@ var WidgetChatReportSchema = discriminatedUnion("kind", [
|
|
|
849
873
|
WidgetSpotlightFailedReportSchema,
|
|
850
874
|
WidgetNavigateFailedReportSchema,
|
|
851
875
|
WidgetVariantChoiceRequestReportSchema,
|
|
852
|
-
WidgetCaptureCardReportSchema
|
|
876
|
+
WidgetCaptureCardReportSchema,
|
|
877
|
+
WidgetFormFillReportSchema
|
|
853
878
|
]);
|
|
854
879
|
/**
|
|
855
880
|
* Parse a request body's `report` field. Never throws — the caller decides
|
|
@@ -4,7 +4,8 @@ import { a as isSafeFormSelector, i as isSafeFillValue, n as FILL_FORM_MARKER_AT
|
|
|
4
4
|
* Fill, and maybe submit, the host page's enquiry form, in its own lazy chunk
|
|
5
5
|
* (`form-fill.mjs`). Must import only `@saar-ai/widget-protocol/form-fill` so
|
|
6
6
|
* the chunk is byte-identical in both UI builds (a test pins this). Never
|
|
7
|
-
*
|
|
7
|
+
* solves or skips bot protection: it submits only once the page's own check
|
|
8
|
+
* holds the visitor's token (ADR 0020 D14). Behaviour: AGENTS.md, "Host form
|
|
8
9
|
* fill".
|
|
9
10
|
*/
|
|
10
11
|
var PROTECTION_MARKS = [
|
|
@@ -20,6 +21,15 @@ var PROTECTION_GLOBALS = [
|
|
|
20
21
|
["turnstile", "turnstile"],
|
|
21
22
|
["friendly-captcha", "friendlyChallenge"]
|
|
22
23
|
];
|
|
24
|
+
/** Where each vendor's widget puts the token the visitor's solved check produced. */
|
|
25
|
+
var TOKEN_FIELDS = "textarea[name=\"g-recaptcha-response\"],textarea[name=\"h-captcha-response\"],input[name=\"cf-turnstile-response\"]";
|
|
26
|
+
/** A check the visitor can see and complete; an invisible reCAPTCHA runs only on submit. */
|
|
27
|
+
var SHOWN_CHECK = "div.g-recaptcha:not([data-size=\"invisible\"]),div.h-captcha:not([data-size=\"invisible\"]),.cf-turnstile,iframe[src*=\"recaptcha/api2/anchor\"]:not([src*=\"size=invisible\"]),iframe[src*=\"hcaptcha.com\"]:not([src*=\"size=invisible\"]),iframe[src*=\"challenges.cloudflare.com\"]";
|
|
28
|
+
/** The watch on each form, so a second fill replaces the first. */
|
|
29
|
+
var watches = /* @__PURE__ */ new WeakMap();
|
|
30
|
+
/** How long a shown check is watched for the visitor's token (SAA-500). */
|
|
31
|
+
var CHALLENGE_WAIT_MS = 12e4;
|
|
32
|
+
var CHALLENGE_POLL_MS = 500;
|
|
23
33
|
var SENSITIVE_CONTROL = "input[type=\"password\"],input[type=\"file\"],[autocomplete^=\"cc-\"]";
|
|
24
34
|
var FILLABLE_INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
25
35
|
"",
|
|
@@ -43,6 +53,26 @@ function detectBotProtection(doc, form) {
|
|
|
43
53
|
for (const [kind, name] of PROTECTION_GLOBALS) if (view && view[name] !== void 0 && view[name] !== null) return kind;
|
|
44
54
|
return null;
|
|
45
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* The check's token, for this form: `null` with no token field (nothing to
|
|
58
|
+
* watch), else whether one is filled in. Read, never written.
|
|
59
|
+
*/
|
|
60
|
+
function challengeToken(form) {
|
|
61
|
+
try {
|
|
62
|
+
const fields = form.querySelectorAll(TOKEN_FIELDS);
|
|
63
|
+
if (fields.length === 0) return null;
|
|
64
|
+
return Array.from(fields).some((f) => f.value.trim() !== "");
|
|
65
|
+
} catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function checkShown(doc) {
|
|
70
|
+
try {
|
|
71
|
+
return Array.from(doc.querySelectorAll(SHOWN_CHECK)).some((el) => !hidden(el));
|
|
72
|
+
} catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
46
76
|
/** Hidden by attribute or by CSS, on the control or any ancestor: a honeypot looks like this. */
|
|
47
77
|
function hidden(element) {
|
|
48
78
|
if (element.closest("[hidden],[aria-hidden=\"true\"]") !== null) return true;
|
|
@@ -125,6 +155,26 @@ function handBack(form) {
|
|
|
125
155
|
(Array.from(form.querySelectorAll("[required]")).find((el) => !hidden(el) && !el.value) ?? form.querySelector("button[type=\"submit\"],input[type=\"submit\"],button:not([type])"))?.focus?.({ preventScroll: true });
|
|
126
156
|
} catch {}
|
|
127
157
|
}
|
|
158
|
+
/** Submit through the page's own path, or hand back a form its validation rejects. */
|
|
159
|
+
function send(form, filled, botProtection) {
|
|
160
|
+
if (!form.checkValidity()) {
|
|
161
|
+
form.reportValidity();
|
|
162
|
+
handBack(form);
|
|
163
|
+
return {
|
|
164
|
+
kind: "form_fill",
|
|
165
|
+
outcome: "needs-visitor",
|
|
166
|
+
filled,
|
|
167
|
+
botProtection
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
form.requestSubmit();
|
|
171
|
+
return {
|
|
172
|
+
kind: "form_fill",
|
|
173
|
+
outcome: "submitted",
|
|
174
|
+
filled,
|
|
175
|
+
botProtection
|
|
176
|
+
};
|
|
177
|
+
}
|
|
128
178
|
/**
|
|
129
179
|
* Fill the form `request` names and, when allowed, submit it.
|
|
130
180
|
*
|
|
@@ -132,9 +182,16 @@ function handBack(form) {
|
|
|
132
182
|
* own validation and the page's own submit handlers run exactly as when the
|
|
133
183
|
* visitor presses the button; a browser without it is handed back rather than
|
|
134
184
|
* posting with `submit()`, which would skip both.
|
|
185
|
+
*
|
|
186
|
+
* Behind bot protection (SAA-500) it submits only once the check's token is
|
|
187
|
+
* there: already, or, for `needs-challenge`, when the visitor completes the
|
|
188
|
+
* check within {@link CHALLENGE_WAIT_MS}; `later` then gets `submitted`, or
|
|
189
|
+
* `needs-visitor` on timeout. It stops, reporting nothing, once `live()` is
|
|
190
|
+
* false or the form leaves the page. No token field to watch: handed back.
|
|
135
191
|
*/
|
|
136
|
-
function fillHostForm(doc, request) {
|
|
192
|
+
function fillHostForm(doc, request, later, live = () => true) {
|
|
137
193
|
const none = (outcome) => ({
|
|
194
|
+
kind: "form_fill",
|
|
138
195
|
outcome,
|
|
139
196
|
filled: 0,
|
|
140
197
|
botProtection: null
|
|
@@ -160,32 +217,74 @@ function fillHostForm(doc, request) {
|
|
|
160
217
|
if (filled === 0) return none("not-found");
|
|
161
218
|
form.setAttribute(FILL_FORM_MARKER_ATTRIBUTE, "");
|
|
162
219
|
const botProtection = detectBotProtection(doc, form);
|
|
163
|
-
|
|
220
|
+
let token = botProtection === null ? true : challengeToken(form);
|
|
221
|
+
if (token === false && !checkShown(doc)) token = null;
|
|
222
|
+
if (token === null || !request.submit || filled < wanted || typeof form.requestSubmit !== "function") {
|
|
164
223
|
handBack(form);
|
|
165
224
|
return {
|
|
225
|
+
kind: "form_fill",
|
|
166
226
|
outcome: "needs-visitor",
|
|
167
227
|
filled,
|
|
168
228
|
botProtection
|
|
169
229
|
};
|
|
170
230
|
}
|
|
171
|
-
if (!form.checkValidity())
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return {
|
|
175
|
-
outcome: "needs-visitor",
|
|
176
|
-
filled,
|
|
177
|
-
botProtection: null
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
form.requestSubmit();
|
|
231
|
+
if (token || !form.checkValidity()) return send(form, filled, botProtection);
|
|
232
|
+
handBack(form);
|
|
233
|
+
watchChallenge(form, filled, botProtection, later, live);
|
|
181
234
|
return {
|
|
182
|
-
|
|
235
|
+
kind: "form_fill",
|
|
236
|
+
outcome: "needs-challenge",
|
|
183
237
|
filled,
|
|
184
|
-
botProtection
|
|
238
|
+
botProtection
|
|
185
239
|
};
|
|
186
240
|
} catch {
|
|
187
241
|
return none("not-found");
|
|
188
242
|
}
|
|
189
243
|
}
|
|
244
|
+
function watchChallenge(form, filled, botProtection, later, live) {
|
|
245
|
+
const deadline = Date.now() + CHALLENGE_WAIT_MS;
|
|
246
|
+
let done = false;
|
|
247
|
+
const finish = (result) => {
|
|
248
|
+
done = true;
|
|
249
|
+
form.removeEventListener("submit", onSubmit);
|
|
250
|
+
if (watches.get(form) === stop) watches.delete(form);
|
|
251
|
+
if (result !== null && live()) later?.(result);
|
|
252
|
+
};
|
|
253
|
+
const stop = () => finish(null);
|
|
254
|
+
watches.get(form)?.();
|
|
255
|
+
watches.set(form, stop);
|
|
256
|
+
const onSubmit = () => {
|
|
257
|
+
if (!done && challengeToken(form)) finish({
|
|
258
|
+
kind: "form_fill",
|
|
259
|
+
outcome: "submitted",
|
|
260
|
+
filled,
|
|
261
|
+
botProtection
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
form.addEventListener("submit", onSubmit);
|
|
265
|
+
const tick = () => {
|
|
266
|
+
if (done) return;
|
|
267
|
+
try {
|
|
268
|
+
if (!live() || !form.isConnected) return finish(null);
|
|
269
|
+
if (challengeToken(form)) {
|
|
270
|
+
form.removeEventListener("submit", onSubmit);
|
|
271
|
+
return finish(send(form, filled, botProtection));
|
|
272
|
+
}
|
|
273
|
+
if (Date.now() >= deadline) {
|
|
274
|
+
handBack(form);
|
|
275
|
+
return finish({
|
|
276
|
+
kind: "form_fill",
|
|
277
|
+
outcome: "needs-visitor",
|
|
278
|
+
filled,
|
|
279
|
+
botProtection
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
setTimeout(tick, CHALLENGE_POLL_MS);
|
|
283
|
+
} catch {
|
|
284
|
+
finish(null);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
setTimeout(tick, CHALLENGE_POLL_MS);
|
|
288
|
+
}
|
|
190
289
|
//#endregion
|
|
191
290
|
export { fillHostForm };
|