refactor: api.ts
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import {
|
||||
apiRequest,
|
||||
apiRequestWithMeta,
|
||||
buildCursorQuery,
|
||||
parseCursorPageMeta,
|
||||
type CursorListParams,
|
||||
type CursorPage,
|
||||
} from "./_shared";
|
||||
|
||||
// Workspace (Project) types - 对应 API.md 第七部分系统管理接口
|
||||
export type Workspace = {
|
||||
workspace_id: string;
|
||||
workspace_code: string;
|
||||
workspace_name: string;
|
||||
active_root_uri: string;
|
||||
quota_bytes: number;
|
||||
status: "active" | "archived" | "disabled";
|
||||
description: string | null;
|
||||
created_by: string;
|
||||
created_at: string;
|
||||
updated_at: string | null;
|
||||
};
|
||||
|
||||
export type WorkspaceCreatePayload = {
|
||||
workspace_code: string;
|
||||
workspace_name: string;
|
||||
quota_bytes?: number;
|
||||
description?: string;
|
||||
};
|
||||
|
||||
export type WorkspaceUpdatePayload = {
|
||||
workspace_name?: string;
|
||||
quota_bytes?: number;
|
||||
description?: string;
|
||||
status?: "active" | "archived";
|
||||
};
|
||||
|
||||
// Workspace (Project) Management APIs - 对应 API.md 第七部分系统管理接口
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
export async function listWorkspaces(
|
||||
input: CursorListParams = {},
|
||||
): Promise<CursorPage<Workspace>> {
|
||||
const query = buildCursorQuery(input);
|
||||
const { data, meta } = await apiRequestWithMeta<Workspace[]>(
|
||||
`/api/v1/platform/workspaces?${query}`,
|
||||
);
|
||||
return { items: data, meta: parseCursorPageMeta(meta) };
|
||||
}
|
||||
|
||||
export async function createWorkspace(
|
||||
input: WorkspaceCreatePayload,
|
||||
): Promise<Workspace> {
|
||||
return apiRequest<Workspace>(
|
||||
"/api/v1/platform/workspaces",
|
||||
{ method: "POST", body: JSON.stringify(input) },
|
||||
);
|
||||
}
|
||||
|
||||
export async function getWorkspace(workspaceId: string): Promise<Workspace> {
|
||||
return apiRequest<Workspace>(`/api/v1/platform/workspaces/${workspaceId}`);
|
||||
}
|
||||
|
||||
export async function updateWorkspace(
|
||||
workspaceId: string,
|
||||
input: WorkspaceUpdatePayload,
|
||||
): Promise<Workspace> {
|
||||
return apiRequest<Workspace>(
|
||||
`/api/v1/platform/workspaces/${workspaceId}`,
|
||||
{ method: "PATCH", body: JSON.stringify(input) },
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteWorkspace(workspaceId: string): Promise<{
|
||||
workspace_id: string;
|
||||
deleted: boolean;
|
||||
}> {
|
||||
return apiRequest(
|
||||
`/api/v1/platform/workspaces/${workspaceId}`,
|
||||
{ method: "DELETE" },
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user