import {z} from 'zod' export type NestedEmailWrite = {id?: string | undefined, email?: string | undefined, email_type?: string | undefined, _destroy?: boolean | undefined}; export type NestedPhoneWrite = {id?: string | undefined, phone?: string | undefined, phone_type?: string | undefined, ext?: string | undefined, _destroy?: boolean | undefined}; export type NestedAddressWrite = {id?: string | undefined, address_type?: string | undefined, name?: string | undefined, street?: string | undefined, street1?: string | undefined, suburb?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, country?: string | undefined, attention_to?: string | undefined, zip_from_foreign_country?: string | undefined, _destroy?: boolean | undefined}; export type ContactWrite = {contact: {name: string, email?: string | undefined, phone?: string | undefined, ext?: string | undefined, title?: string | undefined, department?: string | undefined, company_id?: string | undefined, company_name?: string | undefined, website?: string | undefined, linkedin?: string | undefined, twitter?: string | undefined, facebook?: string | undefined, blog?: string | undefined, beeper_number?: string | undefined, background_info?: string | undefined, unsubscribe?: boolean | undefined, picture_url?: string | undefined, picture_filename?: string | undefined, picture_mimetype?: string | undefined, picture_size?: number | undefined, picture_key?: string | undefined, enable_customer_portal?: boolean | undefined, login?: string | undefined, password?: string | undefined, emails_attributes?: Array | undefined, phones_attributes?: Array | undefined, addresses_attributes?: Array | undefined}}; export type UpdateApiContactsIdArgs = {body: ContactWrite}; export type UpdateApiContactsIdOptions = {baseUrl?: string | undefined, accountId?: string | undefined, authToken?: string | undefined, fetch?: typeof fetch | undefined}; export const address = z.object({id: z.string().optional(), addressType: z.string().nullable().optional(), name: z.string().nullable().optional(), nameStreet: z.string().nullable().optional(), nameStreetCity: z.string().nullable().optional(), street: z.string().nullable().optional(), street1: z.string().nullable().optional(), suburb: z.string().nullable().optional(), city: z.string().nullable().optional(), zip: z.string().nullable().optional(), state: z.string().nullable().optional(), country: z.string().nullable().optional(), attentionTo: z.string().nullable().optional(), coordinates: z.object({latitude: z.number().nullable().optional(), longitude: z.number().nullable().optional()}).optional()}); export const email = z.object({id: z.string().optional(), email: z.string().optional(), emailType: z.string().nullable().optional()}); export const phone = z.object({id: z.string().optional(), phone: z.string().optional(), ext: z.string().nullable().optional(), phoneType: z.string().nullable().optional(), phoneWithExt: z.string().nullable().optional()}); export const namedRef = z.object({id: z.string().optional(), name: z.string().optional()}); export const contact = z.object({id: z.string().optional(), name: z.string().optional(), email: z.string().nullable().optional(), phone: z.string().nullable().optional(), phoneWithExt: z.string().nullable().optional(), ext: z.string().nullable().optional(), title: z.string().nullable().optional(), department: z.string().nullable().optional(), beeperNumber: z.string().nullable().optional(), website: z.string().nullable().optional(), blog: z.string().nullable().optional(), facebook: z.string().nullable().optional(), twitter: z.string().nullable().optional(), linkedin: z.string().nullable().optional(), active: z.boolean().optional(), companyId: z.string().optional(), enableCustomerPortal: z.boolean().optional(), login: z.string().nullable().optional(), notesCount: z.number().int().optional(), tasksCount: z.number().int().optional(), backgroundInfo: z.string().nullable().optional(), allowDelete: z.boolean().optional(), company: z.object({id: z.string().optional(), name: z.string().optional(), enableCustomerPortal: z.boolean().optional()}).optional(), addresses: z.array(address).optional(), emails: z.array(email).optional(), phones: z.array(phone).optional(), createdById: z.string().nullable().optional(), updatedById: z.string().nullable().optional(), createdBy: namedRef.optional(), updatedBy: namedRef.optional(), createdAt: z.string().optional(), updatedAt: z.string().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 }; /** * Update a contact * * PUT /contacts/{id} */ export const updateApiContactsId = async (args: UpdateApiContactsIdArgs, options?: UpdateApiContactsIdOptions) => { const {baseUrl = "https://api.shopvox.com/v1", fetch: fetchFn = fetch, accountId, authToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (accountId !== undefined) query.set("account_id", accountId) if (authToken !== undefined) query.set("authToken", authToken) const url = `${baseUrl.replace(/\/+$/, '')}/contacts/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(contact, await res.json()) };