import {z} from 'zod' export type PUTContactType = {address1?: string | undefined, address2?: string | undefined, asBillTo?: boolean | undefined, asShipTo?: boolean | undefined, asSoldTo?: boolean | undefined, city?: string | undefined, contactDescription?: string | undefined, country?: string | undefined, county?: string | undefined, fax?: string | undefined, firstName?: string | undefined, homePhone?: string | undefined, lastName?: string | undefined, mobilePhone?: string | undefined, nickname?: string | undefined, otherPhone?: string | undefined, otherPhoneType?: ('Work' | 'Mobile' | 'Home' | 'Other') | undefined, personalEmail?: string | undefined, state?: string | undefined, taxRegion?: string | undefined, workEmail?: string | undefined, workPhone?: string | undefined, zipCode?: string | undefined} | {[key: string]: unknown}; export type UpdateApiV1ContactsContactIdArgs = {'Accept-Encoding'?: string | undefined, 'Content-Encoding'?: string | undefined, 'Zuora-Entity-Ids'?: string | undefined, 'Zuora-Org-Ids'?: string | undefined, 'Zuora-Track-Id'?: string | undefined, contactId: string, 'Zuora-Version'?: string | undefined, body: PUTContactType}; export type UpdateApiV1ContactsContactIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const contactResponse = z.object({accountId: z.string().optional(), accountNumber: z.string().optional(), address1: z.string().max(255).optional(), address2: z.string().max(255).optional(), asBillTo: z.boolean().optional(), asShipTo: z.boolean().optional(), asSoldTo: z.boolean().optional(), city: z.string().max(40).optional(), contactDescription: z.string().max(100).optional(), country: z.string().max(64).optional(), county: z.string().max(32).nullable().optional(), fax: z.string().max(40).optional(), firstName: z.string().max(100).optional(), homePhone: z.string().max(40).optional(), lastName: z.string().max(100).optional(), mobilePhone: z.string().max(100).optional(), nickname: z.string().max(100).optional(), otherPhone: z.string().max(40).optional(), otherPhoneType: z.enum(["Work", "Mobile", "Home", "Other"]).optional(), personalEmail: z.string().max(80).optional(), state: z.string().max(40).optional(), success: z.boolean().optional(), taxRegion: z.string().max(32).optional(), workEmail: z.string().max(80).optional(), workPhone: z.string().max(40).optional(), zipCode: z.string().max(20).optional()}).and(z.record(z.string(), z.unknown())); 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 /v1/contacts/{contactId} */ export const updateApiV1ContactsContactId = async (args: UpdateApiV1ContactsContactIdArgs, options?: UpdateApiV1ContactsContactIdOptions) => { const {baseUrl = "https://rest.test.zuora.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Accept-Encoding'] != null) headers.set("Accept-Encoding", String(args['Accept-Encoding'])) if (args['Content-Encoding'] != null) headers.set("Content-Encoding", String(args['Content-Encoding'])) if (args['Zuora-Entity-Ids'] != null) headers.set("Zuora-Entity-Ids", String(args['Zuora-Entity-Ids'])) if (args['Zuora-Org-Ids'] != null) headers.set("Zuora-Org-Ids", String(args['Zuora-Org-Ids'])) if (args['Zuora-Track-Id'] != null) headers.set("Zuora-Track-Id", String(args['Zuora-Track-Id'])) if (args['Zuora-Version'] != null) headers.set("Zuora-Version", String(args['Zuora-Version'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/contacts/${encodeURIComponent(String(args.contactId))}${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(contactResponse, await res.json()) };