import {z} from 'zod' export type CustomerId = number; export type PatchApiContactsPublicContactIdArgs = {contactId: CustomerId, body: {account_id?: (number | null) | undefined, address?: ({address1?: string | undefined, address2?: (string | null) | undefined, city?: string | undefined, country?: string | undefined, postal_code?: string | undefined, state?: string | undefined} | null) | undefined, email?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, notes?: (string | null) | undefined, phone?: (string | null) | undefined, phone_ext?: (string | null) | undefined, salesperson?: ({email?: string | undefined} | null) | undefined}}; export type PatchApiContactsPublicContactIdOptions = {baseUrl?: string | undefined, appId?: string | undefined, fetch?: typeof fetch | undefined}; export const address = z.object({id: z.number().int().optional(), address1: z.string().max(250).optional(), address2: z.string().max(250).nullable().optional(), city: z.string().max(100).optional(), state: z.string().optional(), postal_code: z.string().optional(), country: z.string().max(3).optional(), erp_code: z.string().max(50).optional()}); export const salesPerson = z.object({uuid: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), erp_code: z.string().optional()}); export const contact = z.object({address: address.optional(), account_id: z.number().int().nullable().optional(), created: z.string().optional(), email: z.string().optional(), first_name: z.string().optional(), id: z.number().int().optional(), last_name: z.string().optional(), notes: z.string().nullable().optional(), phone: z.string().nullable().optional(), phone_ext: z.string().nullable().optional(), country_code: z.string().nullable().optional(), metadata: z.object({}).nullable().optional(), salesperson: salesPerson.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 * * PATCH /contacts/public/{contactId} */ export const patchApiContactsPublicContactId = async (args: PatchApiContactsPublicContactIdArgs, options?: PatchApiContactsPublicContactIdOptions) => { const {baseUrl = "https://api.paperlessparts.com/v1", fetch: fetchFn = fetch, appId} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (appId !== undefined) headers.set("Authorization", appId) const url = `${baseUrl.replace(/\/+$/, '')}/contacts/public/${encodeURIComponent(String(args.contactId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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()) };