mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 07:38:43 +01:00
* feat(feedback): a client's seat on the site itself; visitors follow notes without an account Step 3 — the seat reaches the site: - A member pass (#loki-member=) names the person, not the owner. Their project page's Open link and the widget's sign-in door give it to anyone on the project who does not build it. The widget stays the ordinary panel and sends it with each note; ingest files it through the same path as asking in Loki, so a client's note on the site builds on their allowance and goes live on their word. Membership is read when used. - The owner's own link is no longer what a client is sent: the preview's share card offers Invite them as Client. - An approved /change request seats its requester as the site's client (5 changes a month), and their request page says where to ask. Step 4 — the way back without an account: - The tracking link opens on the note's status (the My feedback card), for six months; an account is optional, below it. - A visitor who leaves an email gets the link by mail (three a day per address), and again in the shipped mail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx * chore(widget): keep the conversation within its length limit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx * chore(widget): hand the passes on through one helper Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx * test(feedback): the shared reporter card and the six-month link Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx --------- Co-authored-by: Claude <noreply@anthropic.com>
80 lines
3.0 KiB
TypeScript
80 lines
3.0 KiB
TypeScript
/**
|
|
* The one POST to Loki's feedback ingest. The panel's Send and Watch's
|
|
* automatic fix both file through it, so the clamps and the error reading
|
|
* exist once.
|
|
*
|
|
* Every field is clamped to the server's own cap (api/feedback/route.ts
|
|
* FeedbackBody — scripts/test/widget-server-caps-mirror.ts compares them). The
|
|
* ingest rejects the WHOLE submission with a bare "Invalid submission" naming
|
|
* no field, so one character over a cap silently loses someone's report.
|
|
*/
|
|
import type { FeedbackCapture } from "./feedback-capture";
|
|
import type { SelectedEl } from "./picker";
|
|
import type { ReportMoment } from "./moments-contract";
|
|
|
|
export type ReportFields = {
|
|
token: string;
|
|
suggestion: string;
|
|
/** Explicitly save a review note without starting development. */
|
|
intent?: "note" | "fix";
|
|
capture?: FeedbackCapture;
|
|
contact?: string;
|
|
scope: "element" | "page" | "site";
|
|
screenshots?: string[];
|
|
selectedElements?: SelectedEl[];
|
|
ownerPass?: string;
|
|
/** A project member's pass (member-pass.ts): the note is theirs. */
|
|
memberPass?: string;
|
|
/** Watch's remark signature, when the note IS a finding's fix (owner only). */
|
|
noticeKey?: string;
|
|
/** What was seen while each thing was said — clamped by moments-contract. */
|
|
moments?: ReportMoment[];
|
|
};
|
|
|
|
export type ReportAnswer = {
|
|
claimUrl?: string;
|
|
owner?: boolean;
|
|
building?: boolean;
|
|
buildNote?: string;
|
|
savedOnly?: boolean;
|
|
/** The owner's build, in Loki ("Watch the fix") — the receipt links to it. */
|
|
followUrl?: string;
|
|
/** Filed as a project member's own (their pass was honoured). */
|
|
member?: boolean;
|
|
/** What happened to a member's note, in Loki's words. */
|
|
say?: string;
|
|
};
|
|
|
|
/** File a report about the page the person is on. Throws the server's own
|
|
* words when it refuses, so the panel can show them. */
|
|
export async function sendReport(apiBase: string, fields: ReportFields): Promise<ReportAnswer> {
|
|
const { capture, ...report } = fields;
|
|
const res = await fetch(`${apiBase}/api/feedback`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
...report,
|
|
context: capture?.diagnostics,
|
|
contact: fields.contact?.trim().slice(0, 200) || undefined,
|
|
page: capture?.page ?? location.pathname.slice(0, 300),
|
|
url: capture?.url ?? location.href.slice(0, 1000),
|
|
pageTitle: (capture?.title ?? document.title.slice(0, 300)) || undefined,
|
|
screenshots: fields.screenshots?.length ? fields.screenshots : undefined,
|
|
selectedElements: capture
|
|
? capture.selected.length
|
|
? capture.selected
|
|
: undefined
|
|
: fields.selectedElements?.length
|
|
? fields.selectedElements
|
|
: undefined,
|
|
noticeKey: fields.noticeKey ? fields.noticeKey.slice(0, 300) : undefined,
|
|
moments: fields.moments?.length ? fields.moments : undefined,
|
|
}),
|
|
});
|
|
if (!res.ok) {
|
|
const body = (await res.json().catch(() => null)) as { error?: string } | null;
|
|
throw new Error(body?.error ?? `Request failed (${res.status})`);
|
|
}
|
|
return (await res.json()) as ReportAnswer;
|
|
}
|