import {z} from 'zod' export type GetApiUserContactsIdArgs = {id: string}; export type GetApiUserContactsIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiUserContactsIdResponse = z.object({id: z.string().optional(), name: z.string().min(1).max(64).optional(), email: z.string().max(128).optional(), company: z.string().max(128).optional(), title: z.string().max(128).optional(), business: z.string().max(128).optional(), business2: z.string().max(128).optional(), mobile_phone: z.string().max(128).optional(), mobile_phone2: z.string().max(128).optional(), home_phone: z.string().max(128).optional(), home_phone2: z.string().max(128).optional(), other: z.string().max(128).optional(), business_fax: z.string().max(128).optional(), home_fax: z.string().max(128).optional(), address: z.string().max(128).optional(), notes: z.string().max(1024).optional(), sync_type: z.literal("Microsoft 365").optional(), favorite: z.boolean().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 }; /** * Retrieve personal contact details * * GET /user/contacts/{id} */ export const getApiUserContactsId = async (args: GetApiUserContactsIdArgs, options?: GetApiUserContactsIdOptions) => { const {baseUrl = "https://HOSTNAME:8887/api", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/user/contacts/${encodeURIComponent(String(args.id))}${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(getApiUserContactsIdResponse, await res.json()) };