import {z} from 'zod' export type GetApiV1ContactsContactIdEnrichArgs = {contact_id: string}; export type GetApiV1ContactsContactIdEnrichOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const workExperience = z.object({title: z.string().optional(), company: z.string().optional(), start_date: z.string().optional(), end_date: z.string().nullable().optional(), is_primary: z.boolean().optional()}); export const education = z.object({school: z.string().optional(), start_date: z.string().optional(), end_date: z.string().nullable().optional()}); export const enrichedContact = z.object({id: z.string().optional(), full_name: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), sex: z.string().optional(), job_title: z.string().optional(), job_title_role: z.string().optional(), job_title_levels: z.array(z.string()).optional(), job_company_name: z.string().optional(), job_company_website: z.string().optional(), job_company_size: z.string().optional(), job_company_industry: z.string().optional(), work_email: z.string().nullable().optional(), personal_emails: z.array(z.string()).optional(), mobile_phone: z.string().nullable().optional(), phone_numbers: z.array(z.string()).optional(), linkedin_url: z.string().optional(), facebook_url: z.string().nullable().optional(), location_name: z.string().optional(), location_locality: z.string().optional(), location_region: z.string().optional(), location_country: z.string().optional(), location_geo: z.string().optional(), skills: z.array(z.string()).optional(), experience: z.array(workExperience).optional(), education: z.array(education).optional(), profiles: z.array(z.object({network: z.string().optional(), url: z.string().optional()})).optional(), credits: z.object({remaining: z.number().int().optional(), total: z.number().int().optional(), used: z.number().int().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 }; /** * Enrich a contact profile * * GET /v1/contacts/{contact_id}/enrich */ export const getApiV1ContactsContactIdEnrich = async (args: GetApiV1ContactsContactIdEnrichArgs, options?: GetApiV1ContactsContactIdEnrichOptions) => { const {baseUrl = "https://api.runalphaloops.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/contacts/${encodeURIComponent(String(args.contact_id))}/enrich${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(enrichedContact, await res.json()) };