mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-08 10:46:06 +00:00
feat(cli): forward feedback submissions to the backend feedback endpoint (#2003)
* feat(cli): forward feedback submissions to backend endpoint * fix(cli): truncate feedback fields to backend caps + ack before forwarding Addresses PR review (via): - Truncate comment (2000) / cli_version (100) / env (500) to the backend DTO caps before POSTing, so a pasted stack trace is forwarded truncated instead of rejected with a 422 the best-effort path swallows silently. - Print "Thanks for the feedback!" before the best-effort forward so the ack isn't blocked behind the (bounded) network call. * fix(cli): type feedback fetch mock
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { getPublishApiBaseUrl } from "./publishProject.js";
|
||||
|
||||
// Match the backend DTO caps (HyperframesFeedbackRequest). Truncate here so an
|
||||
// over-long field (e.g. a pasted stack trace) is still forwarded truncated,
|
||||
// rather than rejected by the backend with a 422 the best-effort path swallows.
|
||||
const MAX_COMMENT = 2000;
|
||||
const MAX_CLI_VERSION = 100;
|
||||
const MAX_ENV = 500;
|
||||
|
||||
function cap(value: string | undefined, max: number): string | undefined {
|
||||
if (value === undefined) return undefined;
|
||||
return value.length > max ? value.slice(0, max) : value;
|
||||
}
|
||||
|
||||
export async function submitFeedback(input: {
|
||||
rating: number;
|
||||
comment?: string;
|
||||
cliVersion: string;
|
||||
env?: string;
|
||||
}): Promise<void> {
|
||||
try {
|
||||
const apiBaseUrl = getPublishApiBaseUrl();
|
||||
await fetch(`${apiBaseUrl}/v1/hyperframes/feedback`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
rating: input.rating,
|
||||
comment: cap(input.comment, MAX_COMMENT),
|
||||
cli_version: cap(input.cliVersion, MAX_CLI_VERSION),
|
||||
env: cap(input.env, MAX_ENV),
|
||||
}),
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
heygen_route: "canary",
|
||||
},
|
||||
signal: AbortSignal.timeout(5000),
|
||||
});
|
||||
} catch {
|
||||
// Best-effort only.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user