import {z} from 'zod' export type PatchApiV3ContactsIdArgs = {id: number, body: {email?: string | undefined, firstName?: string | undefined, lastName?: string | undefined, phone?: string | undefined, phone2?: string | undefined, title?: string | undefined, company?: string | undefined, companySize?: ('Empty' | 'SelfEmployed' | 'Ten' | 'Fifty' | 'TwoHundred' | 'FiveHundred' | 'OneThousand' | 'FiveThousand' | 'TenThousand' | 'OverTenThousand') | undefined, industry?: string | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined, timeZoneId?: string | undefined, linkedInUrl?: string | undefined, linkedInSalesNavigatorUrl?: string | undefined, linkedInRecruiterUrl?: string | undefined, notes?: string | undefined, isOptedOut?: (boolean | null) | undefined, callStatus?: ('none' | 'toCall' | 'called' | null) | undefined, meetingStatus?: ('none' | 'meetingBooked' | null) | undefined, ownerUserId?: (number | null) | undefined, accountId?: (number | null) | undefined, customFields?: (Array<{id?: (number | null) | undefined, name?: (string | null) | undefined, value?: (string | null) | undefined}>) | undefined}}; export type PatchApiV3ContactsIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiV3ContactsIdResponse = z.object({id: z.number().int().optional(), email: z.string().optional(), domain: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), phone: z.string().optional(), title: z.string().optional(), company: z.string().optional(), companySize: z.enum(["empty", "selfEmployed", "ten", "fifty", "twoHundred", "fiveHundred", "oneThousand", "fiveThousand", "tenThousand", "overTenThousand"]).optional(), industry: z.string().optional(), city: z.string().optional(), state: z.string().optional(), country: z.string().optional(), timeZoneId: z.string().optional(), linkedInUrl: z.string().optional(), linkedInSalesNavigatorUrl: z.string().optional(), linkedInRecruiterUrl: z.string().optional(), phoneStatus: z.enum(["pending", "invalid", "valid", "validationFailed", "notValidated"]).optional(), notes: z.string().optional(), ownerUserId: z.number().int().optional(), accountId: z.number().int().nullable().optional(), isOptedOut: z.boolean().optional(), callStatus: z.enum(["none", "toCall", "called"]).optional(), meetingStatus: z.enum(["none", "meetingBooked"]).optional(), addingDate: z.string().nullable().optional(), createdAt: z.string().nullable().optional(), lastModifiedAt: z.string().nullable().optional(), customFields: z.array(z.object({key: z.string(), value: z.string().nullable().optional()})).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 /v3/contacts/{id} */ export const patchApiV3ContactsId = async (args: PatchApiV3ContactsIdArgs, options?: PatchApiV3ContactsIdOptions) => { const {baseUrl = "https://api.reply.io", 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/contacts/${encodeURIComponent(String(args.id))}${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(patchApiV3ContactsIdResponse, await res.json()) };