import {z} from 'zod' export type GetApiApiUserEventsArgs = {page: number, per_page?: number | undefined, status?: string | undefined, user?: string | undefined, scouting_groups?: string | undefined, season?: string | undefined, type?: string | undefined, property_id?: number | undefined, property_name?: string | undefined, order_by?: string | undefined, order?: ('asc' | 'desc') | undefined}; export type GetApiApiUserEventsOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const personProfile = z.object({id: z.number().int().optional(), user_id: z.number().int().optional(), avatar_id: z.number().int().nullable().optional(), person_profile_job_role_id: z.number().int().nullable().optional(), market_id: z.number().int().nullable().optional(), name: z.string().optional(), job_title: z.string().nullable().optional(), location: z.string().nullable().optional(), school: z.string().nullable().optional(), info: z.string().nullable().optional(), suggested: z.number().int().nullable().optional(), previous_suggested: z.number().int().nullable().optional(), approved: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), deleted_at: z.string().optional()}); export const userEvent = z.object({id: z.number().int().optional(), delegator_id: z.number().int().nullable().optional(), captured_by: z.object({id: z.number().int().optional(), person_profile: personProfile.optional()}).nullable().optional(), captured_by_name: z.string().nullable().optional(), captured_by_email: z.string().nullable().optional(), user_id: z.number().int().optional(), event_id: z.number().int().optional(), team_id: z.number().int().optional(), status: z.number().int().nullable().optional(), type: z.number().int().optional(), due_date: z.string().nullable().optional(), attended_date: z.string().nullable().optional(), completed_at: z.string().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const getApiApiUserEventsResponse = z.object({data: z.array(userEvent).optional(), current_page: z.number().int().optional(), last_page: z.number().int().optional(), per_page: z.number().int().optional(), total: z.number().int().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 }; /** * List user events * * GET /api/user/events */ export const getApiApiUserEvents = async (args: GetApiApiUserEventsArgs, options: GetApiApiUserEventsOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.status != null) query.append("status", String(args.status)) if (args.user != null) query.append("user", String(args.user)) if (args.scouting_groups != null) query.append("scouting_groups", String(args.scouting_groups)) if (args.season != null) query.append("season", String(args.season)) if (args.type != null) query.append("type", String(args.type)) if (args.property_id != null) query.append("property_id", String(args.property_id)) if (args.property_name != null) query.append("property_name", String(args.property_name)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (args.order != null) query.append("order", String(args.order)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/user/events${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(getApiApiUserEventsResponse, await res.json()) };