/** * Form template catalog API — wraps /api/oa/form-templates. * * The backend stores form/flow schemas as JSON TEXT and parses them back, so a * template view here mirrors the frontend engine `FormTemplate` shape * ({ id, name, category, org, form, flow, instructions }). */ import { http } from './http' import type { FormTemplate } from '../engine/types' /** Template view as returned by the backend (adds builtin/publishedAt). */ export type ApiTemplate = FormTemplate & { builtin?: boolean; publishedAt?: string | null } /** GET /form-templates[?category=] */ export function listTemplates(category?: string): Promise { return http.get('/form-templates', category ? { category } : undefined) } /** GET /form-templates/{id} */ export function getTemplate(id: string): Promise { return http.get(`/form-templates/${encodeURIComponent(id)}`) } /** POST /form-templates — publish a template authored in the low-code designer. */ export function createTemplate(input: { id?: string name: string category?: string org?: string form: FormTemplate['form'] flow: FormTemplate['flow'] instructions?: string }): Promise { return http.post('/form-templates', input) } /** * PUT /form-templates/{id}/enabled — 启停模板(流程中心「停用/启用」)。 * 传 enabled 直接设为该值;省略则后端翻转当前状态。停用后「新建事项」发起列表会隐藏它。 */ export function setTemplateEnabled(id: string, enabled?: boolean): Promise { return http.put( `/form-templates/${encodeURIComponent(id)}/enabled`, enabled === undefined ? {} : { enabled } ) }