import {z} from 'zod' export type GetApiSearchUserIdCustomersArgs = {user_id: number, offset?: number | undefined, limit?: number | undefined, search?: string | undefined, from_gt?: string | undefined, from_lt?: string | undefined, location_ids?: string | undefined, repeat_guest?: boolean | undefined, active_guest?: boolean | undefined}; export type GetApiSearchUserIdCustomersOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const customer = z.object({archived: z.boolean().optional(), avatar_url: z.string().optional(), city: z.string().optional(), email: z.string().optional(), employee: z.boolean().optional(), first_name: z.string().optional(), id: z.number().int().optional(), last_departure: z.string().optional(), last_name: z.string().optional(), lifetime_value: z.number().optional(), num_reservations: z.number().int().optional(), owned_by_user_id: z.number().int().optional(), phone: z.string().optional(), state: z.string().optional(), street: z.string().optional(), total_reservations: z.number().int().optional(), zip: z.string().optional()}); export const getApiSearchUserIdCustomersResponse = z.array(customer); 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 }; /** * Search Customers for a dealer * * GET /search/{user_id}/customers * * Also accepts auth: API-Key */ export const getApiSearchUserIdCustomers = async (args: GetApiSearchUserIdCustomersArgs, options: GetApiSearchUserIdCustomersOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.search != null) query.append("search", String(args.search)) if (args.from_gt != null) query.append("from_gt", String(args.from_gt)) if (args.from_lt != null) query.append("from_lt", String(args.from_lt)) if (args.location_ids != null) query.append("location_ids", String(args.location_ids)) if (args.repeat_guest != null) query.append("repeat_guest", String(args.repeat_guest)) if (args.active_guest != null) query.append("active_guest", String(args.active_guest)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/search/${encodeURIComponent(String(args.user_id))}/customers${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(getApiSearchUserIdCustomersResponse, await res.json()) };