'use server'; import type * as t from './types'; import { getUrls } from '@/config/urls'; import type { CreateUrl } from '@/utils/url'; import type { WretchError } from 'wretch'; import wretch from 'wretch'; const urls = getUrls(); const api = wretch(urls.URL_UIS).errorType('json'); type Input = { createUrl: CreateUrl; payload?: unknown }; export async function getData({ createUrl }: Input) { const url = createUrl(''); return api .get(url) .res((cb) => cb.json()) .then((res) => res); } export async function getMetaData({ createUrl }: Input) { const url = createUrl('/meta'); return api .get(url) .res((res) => res.json()) .then((res) => res); } export async function getConfig({ createUrl }: Input) { const url = createUrl('/config'); return api .get(url) .res((res) => res.json()) .then((res) => res); } export async function getConditions({ createUrl }: Input) { const url = createUrl('/conditions'); return api .get(url) .res((res) => res.text()) .then((res) => res); } export async function validate({ createUrl, payload }: Input) { const url = createUrl('/validate'); return api .post(payload, url) .res((res) => res.ok) .then((res) => res) .catch((error: WretchError) => error.json as t.HttpValidationError); }