feat(web): licence banner, settings page and feature gating

This commit is contained in:
2026-07-24 15:25:29 +01:00
parent ee4dff09c9
commit 8626898e5e
8 changed files with 217 additions and 4 deletions
+25
View File
@@ -791,3 +791,28 @@ export const api = {
return `/api/runs/${runId}/servers/${serverId}/logs/stream`;
},
};
export type LicenseState = "valid" | "expired" | "invalid";
export interface LicenseInfo {
instance_id: string;
state: LicenseState;
reason?: string;
tier?: string;
expires_at?: string;
days_remaining?: number;
limits: { max_servers: number; max_secret_groups: number; max_channels: number };
features: Record<string, boolean>;
usage: { servers: number; secret_groups: number; channels: number };
source: string;
}
// `request` already prefixes /api, so these paths do not repeat it.
export const licence = {
get(): Promise<LicenseInfo> {
return request<LicenseInfo>("/license");
},
put(blob: string): Promise<{ state: LicenseState; tier: string; expires_at?: string }> {
return request("/license", { method: "POST", body: JSON.stringify({ blob }) });
},
};
+21
View File
@@ -0,0 +1,21 @@
"use client";
import { useQuery } from "@tanstack/react-query";
import { licence, type LicenseInfo } from "@/lib/api";
export function useLicense() {
const { data, isLoading } = useQuery<LicenseInfo>({
queryKey: ["license"],
queryFn: licence.get,
staleTime: 60_000,
});
return {
license: data,
isLoading,
isActive: data?.state === "valid",
// Features render disabled rather than hidden, so treat "unknown while
// loading" as available to avoid a flash of disabled controls.
hasFeature: (name: string) => (data ? Boolean(data.features?.[name]) : true),
};
}