import {z} from 'zod' export type CreateApiActivityLocationIdEventIdBookArgs = {location_id: number, event_id: number, Accept: string, 'Content-Type': string, body: BodyInit}; export type CreateApiActivityLocationIdEventIdBookOptions = {baseUrl?: string | undefined, BearerPartner?: string | undefined, fetch?: typeof fetch | undefined}; export const eventBookResponse = z.object({success: z.boolean().optional(), data: z.object({id: z.number().int().optional(), hash: z.string().optional()}).optional(), meta: z.array(z.object({})).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Book Event * * POST /activity/{location_id}/{event_id}/book */ export const createApiActivityLocationIdEventIdBook = async (args: CreateApiActivityLocationIdEventIdBookArgs, options?: CreateApiActivityLocationIdEventIdBookOptions) => { const {baseUrl = "https://api.alteg.io/api/v1", fetch: fetchFn = fetch, BearerPartner} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "*/*") headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (BearerPartner !== undefined) headers.set('authorization', `Bearer ${BearerPartner}`) const url = `${baseUrl.replace(/\/+$/, '')}/activity/${encodeURIComponent(String(args.location_id))}/${encodeURIComponent(String(args.event_id))}/book${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(eventBookResponse, await res.json()) };