export type GetApiApiFairsArgs = {status?: ('current' | 'running' | 'closed' | 'upcoming' | 'running_and_upcoming' | 'closing_soon' | 'active') | undefined, offset?: number | undefined, size?: string | undefined, cursor?: string | undefined, sample?: string | undefined, sort?: ('created_at' | '-created_at' | 'start_at' | '-start_at' | 'name' | '-name') | undefined}; export type GetApiApiFairsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Retrieve a collection of fairs. * * GET /api/fairs */ export const getApiApiFairs = async (args: GetApiApiFairsArgs, options: GetApiApiFairsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.status != null) query.append("status", String(args.status)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.size != null) query.append("size", String(args.size)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.sample != null) query.append("sample", String(args.sample)) if (args.sort != null) query.append("sort", String(args.sort)) const url = `${baseUrl.replace(/\/+$/, '')}/api/fairs${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 undefined };