import {z} from 'zod' export type GetApiContactReverseEmailBulkEnrichmentIdArgs = {enrichment_id: string}; export type GetApiContactReverseEmailBulkEnrichmentIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const contactReverseEmailInput = z.object({email: z.string().optional()}); export const personSocialProfile = z.object({professional_network: z.object({id: z.number().int().optional(), url: z.string().optional(), handle: z.string().optional(), connection_count: z.number().int().optional()}).optional()}); export const personEducation = z.object({school_name: z.string().optional(), degree: z.string().optional(), start_at: z.string().optional(), end_at: z.string().optional()}); export const personLanguage = z.object({language: z.string().optional(), proficiency: z.string().optional()}); export const companyAddress = z.object({line1: z.string().optional(), line2: z.string().optional(), city: z.string().optional(), region: z.string().optional(), country: z.string().optional(), country_code: z.string().optional()}); export const officeAddress = z.object({line1: z.string().optional(), line2: z.string().optional()}); export const companySocialProfile = z.object({professional_network: z.object({id: z.number().int().optional(), url: z.string().optional(), handle: z.string().optional(), connection_count: z.number().int().optional()}).optional()}); export const employmentCompany = z.object({id: z.string().optional(), name: z.string().optional(), domain: z.string().optional(), website: z.string().optional(), description: z.string().optional(), year_founded: z.number().int().optional(), headcount: z.number().int().optional(), headcount_range: z.string().optional(), company_type: z.string().optional(), specialties: z.array(z.string()).optional(), technologies: z.array(z.object({name: z.string().optional(), logo_url: z.string().optional()})).optional(), locations: z.object({headquarters: companyAddress.optional(), offices: z.array(officeAddress).nullable().optional()}).optional(), industry: z.object({main_industry: z.string().optional()}).optional(), social_profiles: companySocialProfile.optional(), logo_url: z.string().optional()}); export const employment = z.object({title: z.string().optional(), seniority: z.string().optional(), job_functions: z.array(z.object({function: z.string().optional(), sub_function: z.string().optional()})).optional(), description: z.string().optional(), company: employmentCompany.optional(), is_current: z.boolean().optional(), start_at: z.string().optional(), end_at: z.string().optional()}); export const person = z.object({id: z.string().optional(), full_name: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), headline: z.string().optional(), description: z.string().optional(), location: z.object({country: z.string().optional(), country_code: z.string().optional(), city: z.string().optional(), region: z.string().optional()}).optional(), social_profiles: personSocialProfile.optional(), educations: z.array(personEducation).optional(), languages: z.array(personLanguage).optional(), skills: z.array(z.string()).optional(), employment: z.object({current: employment.optional(), all: z.array(employment).optional()}).optional()}); export const recordReverseEmail = z.object({input: contactReverseEmailInput.optional(), custom: z.object({}).optional(), profile: person.optional()}); export const cost = z.object({credits: z.number().int().optional()}); export const responseGetContactBulkReverseEmail = z.object({id: z.string().optional(), name: z.string().optional(), status: z.enum(["CREATED", "IN_PROGRESS", "CANCELED", "CREDITS_INSUFFICIENT", "FINISHED", "RATE_LIMIT", "UNKNOWN"]).optional(), data: z.array(recordReverseEmail).optional(), cost: cost.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 }; /** * Get Bulk Reverse Email Results * * GET /contact/reverse/email/bulk/{enrichment_id} */ export const getApiContactReverseEmailBulkEnrichmentId = async (args: GetApiContactReverseEmailBulkEnrichmentIdArgs, options?: GetApiContactReverseEmailBulkEnrichmentIdOptions) => { const {baseUrl = "https://app.fullenrich.com/api/v2", 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(/\/+$/, '')}/contact/reverse/email/bulk/${encodeURIComponent(String(args.enrichment_id))}${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(responseGetContactBulkReverseEmail, await res.json()) };