Route web/src/api modules through shared apiFetch so Bearer headers, typed error envelopes, and GET/HEAD transient retries live in one place without swallowing domain failures used by existing error cards.
72 lines
2.0 KiB
TypeScript
72 lines
2.0 KiB
TypeScript
import { apiFetch } from './client';
|
|
|
|
export interface WorkflowDefinitionSummary {
|
|
id: number;
|
|
key: string;
|
|
name: string;
|
|
description: string;
|
|
status: string;
|
|
latest_published_version: number;
|
|
product_domain?: string;
|
|
}
|
|
|
|
export interface WorkflowVersionSummary {
|
|
id: number;
|
|
workflow_id: number;
|
|
version: number;
|
|
status: string;
|
|
definition_hash: string;
|
|
}
|
|
|
|
export interface ValidationIssue {
|
|
code: string;
|
|
message: string;
|
|
field?: string;
|
|
}
|
|
|
|
export async function listAdminWorkflows(): Promise<WorkflowDefinitionSummary[]> {
|
|
const resp = await apiFetch('/api/v1/admin/workflows');
|
|
if (!resp.ok) throw new Error('获取工作流列表失败');
|
|
const data = await resp.json();
|
|
return data.workflows ?? [];
|
|
}
|
|
|
|
export async function getAdminWorkflow(id: number): Promise<{
|
|
definition: WorkflowDefinitionSummary;
|
|
versions: WorkflowVersionSummary[];
|
|
}> {
|
|
const resp = await apiFetch(`/api/v1/admin/workflows/${id}`);
|
|
if (!resp.ok) throw new Error('获取工作流详情失败');
|
|
return resp.json();
|
|
}
|
|
|
|
export async function validateWorkflowVersion(workflowId: number, version: number): Promise<{
|
|
valid: boolean;
|
|
issues: ValidationIssue[];
|
|
}> {
|
|
const resp = await apiFetch(`/api/v1/admin/workflows/${workflowId}/versions/${version}/validate`, {
|
|
method: 'POST',
|
|
});
|
|
if (!resp.ok) throw new Error('校验失败');
|
|
return resp.json();
|
|
}
|
|
|
|
export async function publishWorkflowVersion(workflowId: number, version: number): Promise<void> {
|
|
const resp = await apiFetch(`/api/v1/admin/workflows/${workflowId}/versions/${version}/publish`, {
|
|
method: 'POST',
|
|
});
|
|
if (!resp.ok) {
|
|
const txt = await resp.text();
|
|
throw new Error(txt || '发布失败');
|
|
}
|
|
}
|
|
|
|
export async function listAdminTemplates(): Promise<
|
|
Array<{ id: number; asset_key: string; name: string; status: string }>
|
|
> {
|
|
const resp = await apiFetch('/api/v1/admin/templates');
|
|
if (!resp.ok) throw new Error('获取模板列表失败');
|
|
const data = await resp.json();
|
|
return data.templates ?? [];
|
|
}
|