Files
hyperframes/packages/cli/src/utils/submitFeedback.ts
T
Miguel Ángel 08934bfd55 revert(cli): keep HeyGen API traffic on stable prod (#3202)
* Revert "fix(cli): route HeyGen API calls through canary (#3201)"

This reverts commit 5545521556.

* fix(cli): remove remaining EF canary routes
2026-08-10 21:41:21 -04:00

42 lines
1.3 KiB
TypeScript

import { getPublishApiBaseUrl } from "./publishProject.js";
import { FEEDBACK_RATING_SCALE } from "./feedbackRating.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,
rating_scale: FEEDBACK_RATING_SCALE,
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",
},
signal: AbortSignal.timeout(5000),
});
} catch {
// Best-effort only.
}
}