import {z} from 'zod' export type PublicUpdateContactDto = {firstName?: string | undefined, lastName?: string | undefined, email?: string | undefined, company?: string | undefined, city?: string | undefined, country?: string | undefined, url?: string | undefined, linkedinUrl?: string | undefined, linkedinSalesUrl?: string | undefined, role?: string | undefined, allowPhoneCalls?: boolean | undefined, phoneNumbers?: Array | undefined, customFields?: {[key: string]: string} | undefined}; export type PatchApiV1ContactsIdArgs = {id: string, body: PublicUpdateContactDto}; export type PatchApiV1ContactsIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const publicContactDto = z.object({id: z.string(), firstName: z.string(), lastName: z.string(), email: z.object({}).nullable().optional(), company: z.object({}).nullable().optional(), city: z.object({}).nullable().optional(), country: z.object({}).nullable().optional(), url: z.object({}).nullable().optional(), linkedinUrl: z.object({}).nullable().optional(), linkedinSalesUrl: z.object({}).nullable().optional(), role: z.object({}).nullable().optional(), allowPhoneCalls: z.boolean(), callCount: z.number(), lastCallAt: z.string().nullable().optional(), teamId: z.string(), phoneNumbers: z.array(z.string()), customFields: z.record(z.string(), z.string()), createdAt: z.string(), updatedAt: z.string(), lastModificationSource: z.enum(["SKIPCALL", "API"])}); 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/contacts/{id} */ export const patchApiV1ContactsId = async (args: PatchApiV1ContactsIdArgs, options?: PatchApiV1ContactsIdOptions) => { const {baseUrl = "https://api-public.skipcall.app", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/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(publicContactDto, await res.json()) };