import {z} from 'zod' export type SavedContactsListIdsDto = {includes: Array}; export type ViewEnrichedContactsDto = {start?: number | undefined, take?: number | undefined, search?: string | undefined, tags?: Array | undefined, createdDate?: Array | undefined, excludeProspects?: boolean | undefined, emailStatus?: (Array<'valid' | 'risky' | 'bad'>) | undefined, revealType?: (Array<'profileOnly' | 'workEmail' | 'phone' | 'personalEmail' | 'imported'>) | undefined, listIds?: SavedContactsListIdsDto | undefined}; export type CreateApiV1EnrichContactSavedArgs = {body: ViewEnrichedContactsDto}; export type CreateApiV1EnrichContactSavedOptions = {baseUrl: string, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1EnrichContactSavedResponse = z.object({message: z.string().optional(), payload: z.object({profiles: z.array(z.object({id: z.number().optional(), full_name: z.string().optional(), job_title: z.string().optional(), department: z.string().optional(), management_level: z.string().optional(), company_name: z.string().optional(), company_domain: z.string().optional(), company_website: z.string().optional(), company_industry: z.string().optional(), company_size_range: z.string().optional(), linkedin_url: z.string().optional(), location_country: z.string().optional(), location_state: z.string().optional(), location_city: z.string().optional(), picture_url: z.string().nullable().optional(), emails: z.array(z.object({value: z.string().optional(), source: z.string().optional(), isLatest: z.boolean().optional()})).optional(), personalEmails: z.array(z.object({value: z.string().optional(), source: z.string().optional(), isLatest: z.boolean().optional()})).optional(), phones: z.array(z.object({value: z.string().optional(), source: z.string().optional(), isLatest: z.boolean().optional()})).optional(), revealType: z.string().optional(), isProspectCreated: z.boolean().optional(), tags: z.array(z.object({id: z.string().optional(), name: z.string().optional()})).optional(), lists: z.array(z.object({id: z.string().optional(), name: z.string().optional()})).optional()})).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 }; /** * List contacts already enriched or revealed in your account (Saved tab), with filters * * POST /v1/enrich/contact/saved */ export const createApiV1EnrichContactSaved = async (args: CreateApiV1EnrichContactSavedArgs, options: CreateApiV1EnrichContactSavedOptions) => { const {baseUrl, fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/enrich/contact/saved${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiV1EnrichContactSavedResponse, await res.json()) };