feat: complete TASK-WP0-03 browser gate

This commit is contained in:
suyx
2026-07-27 18:23:20 +08:00
parent dbe3e73b91
commit 878788b1e2
25 changed files with 3227 additions and 21 deletions
+41
View File
@@ -2,6 +2,47 @@
export interface ClientOptions { baseUrl?: string; fetch?: typeof globalThis.fetch; headers?: HeadersInit; }
export async function checkBrowserSupport(body: {
"brands": Array<{
"brand": string;
"version": string;
}>;
"full_version_list": Array<{
"brand": string;
"version": string;
}>;
"platform": string;
}, options: ClientOptions = {}): Promise<{
"app_version": string;
"browser": {
"brand": "Google Chrome" | "Microsoft Edge";
"major": number;
};
"status": "supported";
"supported_browsers": Array<{
"brand": "Google Chrome" | "Microsoft Edge";
"major": number;
}>;
}> {
const request = options.fetch ?? globalThis.fetch;
const headers = new Headers(options.headers);
headers.set("Content-Type", "application/json");
const response = await request(`${options.baseUrl ?? ""}/api/v1/support/check`, { body: JSON.stringify(body), method: "POST", headers });
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return response.json() as Promise<{
"app_version": string;
"browser": {
"brand": "Google Chrome" | "Microsoft Edge";
"major": number;
};
"status": "supported";
"supported_browsers": Array<{
"brand": "Google Chrome" | "Microsoft Edge";
"major": number;
}>;
}>;
}
export async function getBootstrap(options: ClientOptions = {}): Promise<{
"app_version": string;
"dependencies": Array<{
+37
View File
@@ -18,6 +18,33 @@ export type BootstrapResponse = {
}>;
};
export type BrowserSupportRequest = {
"brands": Array<{
"brand": string;
"version": string;
}>;
"full_version_list": Array<{
"brand": string;
"version": string;
}>;
"platform": string;
};
export type BrowserSupportSuccess = {
"app_version": string;
"browser": {
"brand": "Google Chrome" | "Microsoft Edge";
"major": number;
};
"status": "supported";
"supported_browsers": Array<{
"brand": "Google Chrome" | "Microsoft Edge";
"major": number;
}>;
};
export type BrowserUnsupportedReason = "platform_unsupported" | "brand_unsupported" | "version_unsupported" | "identity_unavailable";
export type CorrelationId = string;
export type ErrorDetails = {
@@ -28,7 +55,12 @@ export type ErrorDetails = {
"message_key": string;
}>;
"latest_version"?: number | string;
"reason"?: "platform_unsupported" | "brand_unsupported" | "version_unsupported" | "identity_unavailable";
"remaining_bytes"?: number;
"supported_browsers"?: Array<{
"brand": "Google Chrome" | "Microsoft Edge";
"major": number;
}>;
};
export type ErrorEnvelope = {
@@ -43,7 +75,12 @@ export type ErrorEnvelope = {
"message_key": string;
}>;
"latest_version"?: number | string;
"reason"?: "platform_unsupported" | "brand_unsupported" | "version_unsupported" | "identity_unavailable";
"remaining_bytes"?: number;
"supported_browsers"?: Array<{
"brand": "Google Chrome" | "Microsoft Edge";
"major": number;
}>;
};
"error_category"?: "upstream_timeout" | "upstream_failed" | "safety_rejected" | "model_disabled" | "gateway_balance_insufficient" | "gateway_contract_invalid" | "reference_invalid" | "unknown_retryable" | "unknown_non_retryable";
"message_key": string;