import {z} from 'zod' export type GetApiApiRepoValidateArgs = {namespace?: (string | null) | undefined, name: string, description?: (string | null) | undefined}; export type GetApiApiRepoValidateOptions = {baseUrl: string, cookieAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const validateResponse = z.object({description: z.string().nullable().optional(), name: z.string().nullable().optional(), valid: z.boolean()}); /** * Validate Repository * * GET /api/repo/validate */ export const getApiApiRepoValidate = async (args: GetApiApiRepoValidateArgs, options: GetApiApiRepoValidateOptions) => { const {baseUrl, fetch: fetchFn = fetch, cookieAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.namespace != null) query.append("namespace", String(args.namespace)) if (args.name != null) query.append("name", String(args.name)) if (args.description != null) query.append("description", String(args.description)) if (cookieAuth !== undefined) cookies.push("gitarena-session=" + encodeURIComponent(cookieAuth)) const url = `${baseUrl.replace(/\/+$/, '')}/api/repo/validate${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(validateResponse, await res.json()) };