import {z} from 'zod' export type GetApiProfileArgs = {created_at?: unknown | undefined, first_name?: unknown | undefined, last_name?: unknown | undefined, avatar_url?: unknown | undefined, email?: unknown | undefined, id?: string | undefined, full_name?: unknown | undefined, updated_at?: unknown | undefined, billing_address?: unknown | undefined, payment_method?: unknown | undefined, timezone?: unknown | undefined, select?: string | undefined, order?: string | undefined, Range?: string | undefined, 'Range-Unit'?: string | undefined, offset?: string | undefined, limit?: string | undefined, Prefer?: 'count=none' | undefined}; export type GetApiProfileOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const profile = z.object({created_at: z.string(), first_name: z.string().optional(), last_name: z.string().optional(), avatar_url: z.string().optional(), email: z.string().optional(), id: z.string(), full_name: z.string().optional(), updated_at: z.string(), billing_address: z.unknown(), payment_method: z.unknown(), timezone: z.string().optional()}); export const getApiProfileResponse = z.array(profile); 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 }; /** * GET /profile */ export const getApiProfile = async (args: GetApiProfileArgs, options?: GetApiProfileOptions) => { const {baseUrl = "https://vnaabuozknwgxuvnfwjo.supabase.co:443", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.created_at != null) query.append("created_at", String(args.created_at)) if (args.first_name != null) query.append("first_name", String(args.first_name)) if (args.last_name != null) query.append("last_name", String(args.last_name)) if (args.avatar_url != null) query.append("avatar_url", String(args.avatar_url)) if (args.email != null) query.append("email", String(args.email)) if (args.id != null) query.append("id", String(args.id)) if (args.full_name != null) query.append("full_name", String(args.full_name)) if (args.updated_at != null) query.append("updated_at", String(args.updated_at)) if (args.billing_address != null) query.append("billing_address", String(args.billing_address)) if (args.payment_method != null) query.append("payment_method", String(args.payment_method)) if (args.timezone != null) query.append("timezone", String(args.timezone)) if (args.select != null) query.append("select", String(args.select)) if (args.order != null) query.append("order", String(args.order)) if (args.Range != null) headers.set("Range", String(args.Range)) if (args['Range-Unit'] != null) headers.set("Range-Unit", String(args['Range-Unit'])) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.Prefer != null) headers.set("Prefer", String(args.Prefer)) const url = `${baseUrl.replace(/\/+$/, '')}/profile${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(getApiProfileResponse, await res.json()) };