import {z} from 'zod' export type SharedPhoneNumber = string; export type ContactsUpdateContact = {acting_team_member: string, allow_for_multiple_companies?: boolean | undefined, default_contact_for_company_management?: ('actionable' | 'read_only' | 'none') | undefined, default_contact_for_payable_and_receivable?: ('actionable' | 'read_only' | 'none') | undefined, is_archived?: boolean | undefined, email?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, phone_number?: SharedPhoneNumber | undefined}; export type PatchApiV1CompaniesCompanyIdContactsIdArgs = {company_id: string, id: string, body: ContactsUpdateContact}; export type PatchApiV1CompaniesCompanyIdContactsIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const sharedPhoneNumber = z.string().min(6).max(16); export const isoCountryCodeAll = z.enum(["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "XK", "XX", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"]).min(2).max(2); export const sharedSelfLink = z.string(); export const contactsContactLinks = z.object({company: z.string(), invitation_url: z.string().optional(), self: sharedSelfLink}); export const contactsContact = z.object({object: z.literal("Contact"), id: z.string(), default_contact_for_company_management: z.enum(["actionable", "read_only", "none", "", "self_managed"]), default_contact_for_payable_and_receivable: z.enum(["actionable", "read_only", "none", "", "self_managed"]), email: z.string().nullable().optional(), first_name: z.string().optional(), is_archived: z.boolean(), last_email_delivery_problem: z.enum(["auto_responder", "hard_bounce", "refused", "soft_bounce", "spam_complaint", "spam_notification", "transient", "unknown"]).nullable().optional(), last_name: z.string().optional(), phone_number: sharedPhoneNumber.nullable(), phone_number_country: isoCountryCodeAll.nullable(), links: contactsContactLinks}); 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 /v1/companies/{company_id}/contacts/{id} */ export const patchApiV1CompaniesCompanyIdContactsId = async (args: PatchApiV1CompaniesCompanyIdContactsIdArgs, options?: PatchApiV1CompaniesCompanyIdContactsIdOptions) => { const {baseUrl = "https://api.routable.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 (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/companies/${encodeURIComponent(String(args.company_id))}/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(contactsContact, await res.json()) };