import { HttpMethod, RootAPIHelper } from './root-api'; /** * Passes a body to the Root API to validate the handlebars. * * Response contract: the endpoint returns 200 with `{ result: 'success' | 'error', message? }`. * Template-level failures (invalid handlebars, missing merge vars) come back as 200 + * `result: 'error'` — NOT as 4xx — so the `result === 'error'` branch at the call site * (validate-documents.ts) stays reachable even with `throwResponseErrors: true`. * Transport errors (5xx, network faults) correctly throw via the helper's error path. * * @param apiKey Root API key with CLI permissions * @param content The unmerged content */ export const validateDocument = async (params: { apiKey: string; content: string; host: string; }): Promise<{ result: 'success' | 'error'; message?: string }> => { const { host, apiKey, content } = params; const rootApi = new RootAPIHelper({ host, apiKey, throwResponseErrors: true }); return rootApi.send({ method: HttpMethod.Post, path: `/cli/validate-document-handlebars`, body: { content, }, }); };