export type ValueType = 'ARRAY' | 'OBJECT' | 'STRING' | 'NUMBER' | 'TRUE' | 'FALSE' | 'NULL'; export type JsonValue = {valueType?: ValueType | undefined}; export type CreateApiValidateArgs = {body: {[key: string]: JsonValue}}; export type CreateApiValidateOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * POST /validate */ export const createApiValidate = async (args: CreateApiValidateArgs, options: CreateApiValidateOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/validate${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };