feat(settings): add browser setup and administration (#10)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import type {
|
||||
SetupStatusResponse,
|
||||
SetupRequest,
|
||||
ChangePasswordRequest,
|
||||
SessionSettingsResponse,
|
||||
ClaudeStatusResponse,
|
||||
SystemInfoResponse,
|
||||
} from "@shellbook/core";
|
||||
import { HttpError } from "./api";
|
||||
async function request<T>(path: string, body?: unknown): Promise<T> {
|
||||
const response = await fetch(`/api${path}`, {
|
||||
method: body === undefined ? "GET" : "POST",
|
||||
credentials: "same-origin",
|
||||
headers: body === undefined ? {} : { "Content-Type": "application/json" },
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
});
|
||||
if (!response.ok) throw new HttpError(response.status);
|
||||
return response.status === 204
|
||||
? (undefined as T)
|
||||
: (response.json() as Promise<T>);
|
||||
}
|
||||
export const settingsApi = {
|
||||
setupStatus: () => request<SetupStatusResponse>("/auth/setup"),
|
||||
setup: (body: SetupRequest) => request<void>("/auth/setup", body),
|
||||
password: (body: ChangePasswordRequest) =>
|
||||
request<void>("/settings/password", body),
|
||||
revoke: () => request<void>("/settings/sessions/revoke", {}),
|
||||
session: () => request<SessionSettingsResponse>("/settings/session"),
|
||||
claude: () => request<ClaudeStatusResponse>("/settings/claude"),
|
||||
system: () => request<SystemInfoResponse>("/settings/system"),
|
||||
};
|
||||
Reference in New Issue
Block a user