import {z} from 'zod' export type UpdateApiV3ContactAccountsIdArgs = {id: number, body: {name: string, description?: (string | null) | undefined, domainName?: (string | null) | undefined, domainSecondary?: (string | null) | undefined, industry?: (string | null) | undefined, companySize?: ('Empty' | 'SelfEmployed' | '2-10' | '11-50' | '51-200' | '201-500' | '501-1000' | '1001-5000' | '5001-10000' | '10001+' | null) | undefined, country?: (string | null) | undefined, state?: (string | null) | undefined, city?: (string | null) | undefined, timeZoneId?: (string | null) | undefined, linkedInUrl?: (string | null) | undefined, phone?: (string | null) | undefined, twitterUrl?: (string | null) | undefined, logoUrl?: (string | null) | undefined, email?: (string | null) | undefined, ownerUserId?: number | undefined}}; export type UpdateApiV3ContactAccountsIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV3ContactAccountsIdResponse = z.object({id: z.number().int().optional(), ownerUserId: z.number().int().optional(), name: z.string().optional(), description: z.string().nullable().optional(), domainName: z.string().nullable().optional(), domainSecondary: z.string().nullable().optional(), industry: z.string().nullable().optional(), companySize: z.enum(["Empty", "SelfEmployed", "2-10", "11-50", "51-200", "201-500", "501-1000", "1001-5000", "5001-10000", "10001+"]).nullable().optional(), country: z.string().nullable().optional(), state: z.string().nullable().optional(), city: z.string().nullable().optional(), timeZoneId: z.string().nullable().optional(), linkedInUrl: z.string().nullable().optional(), phone: z.string().nullable().optional(), twitterUrl: z.string().nullable().optional(), logoUrl: z.string().nullable().optional(), email: z.string().nullable().optional(), emailProvider: z.enum(["other", "gSuite", "office", "zoho", "mimecast", "proofpoint", "yandex", "ovh", "goDaddy", "ionos", "gandi", "hostinger", "oneAndOne", "amazon", "barracuda", "spamexperts", "hotmail", "liveCom", "yahoo", "bloomberg", "gmail", "outlook", "ciscoSecureEmail", "titanMail", "protonmail", "namecheap", "appleMail", "linkedin"]).nullable().optional(), stage: z.object({id: z.number().int().optional(), name: z.string().optional(), colorId: z.number().int().optional()}).nullable().optional(), linkedProspectsCount: z.number().int().optional(), createdDate: z.string().optional(), lastActivityDate: 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 an account * * PUT /v3/contact-accounts/{id} */ export const updateApiV3ContactAccountsId = async (args: UpdateApiV3ContactAccountsIdArgs, options?: UpdateApiV3ContactAccountsIdOptions) => { 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/contact-accounts/${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(updateApiV3ContactAccountsIdResponse, await res.json()) };