import {z} from 'zod' export type V3PaginationRequest = {page: number, size: number}; export type V3Location = {city?: string | undefined, state?: string | undefined, country?: string | undefined, continent?: string | undefined, countryGrouping?: string | undefined, region?: string | undefined, countryIso2?: string | undefined}; export type V3ContactFilterCriteria = {names?: Array | undefined, jobTitles?: Array | undefined, jobTitlesExactMatch?: Array | undefined, normalizedJobTitles?: Array | undefined, searchText?: string | undefined, countries?: Array | undefined, locations?: Array | undefined, seniorityIds?: Array | undefined, departments?: Array | undefined, linkedinUrls?: Array | undefined, existingDataPoints?: Array | undefined, signals?: ({types?: (Array<'allSignals' | 'promotion' | 'companyChange'>) | undefined, startDate?: string | undefined}) | undefined, emails?: Array | undefined, previousEmails?: Array | undefined, previousJobTitle?: Array | undefined, skills?: Array | undefined, certifications?: Array | undefined, awards?: Array | undefined, ids?: Array | undefined, existingDataPointsCondition?: ('or' | 'and') | undefined, jobChangedAfterDate?: string | undefined, jobChangedLastViewDate?: string | undefined, education?: ({degrees?: Array | undefined, fieldsOfStudy?: Array | undefined, schools?: Array | undefined, startYearGte?: number | undefined, graduationYearLte?: number | undefined}) | undefined, score?: ({minScore?: number | undefined, maxScore?: number | undefined}) | undefined, geographicDetails?: (Array<{country?: string | undefined, zipcode?: string | undefined, distance?: number | undefined}>) | undefined}; export type V3Range = {min?: number | undefined, max?: number | undefined}; export type V3CompanyFilterCriteria = {names?: Array | undefined, domains?: Array | undefined, ids?: Array | undefined, locations?: Array | undefined, sizes?: Array | undefined, revenues?: Array | undefined, technologies?: Array | undefined, technologiesCondition?: ('or' | 'and') | undefined, industriesLabels?: Array | undefined, mainIndustriesIds?: Array | undefined, subIndustriesIds?: Array | undefined, intentTopics?: Array | undefined, intentTopicsCondition?: ('or' | 'and') | undefined, intentMinScore?: number | undefined, intentMaxScore?: number | undefined, intentTopicsOperator?: ('or' | 'and' | 'any' | 'all') | undefined, topicCountThreshold?: Array | undefined, sicCodes?: Array | undefined, naicsCodes?: Array | undefined, funding?: ({isIpo?: boolean | undefined, ranges?: (Array<{coverage?: ('last_funding' | 'any_round' | 'total_funds' | 'last_round') | undefined, min?: number | undefined, max?: number | undefined}>) | undefined, date?: ({coverage?: ('last_funding' | 'any_round' | 'total_funds' | 'last_round') | undefined, date?: string | undefined}) | undefined, rounds?: (Array<{coverage?: ('last_funding' | 'any_round' | 'total_funds' | 'last_round') | undefined, round?: ('pre_seed' | 'seed' | 'series_a' | 'series_b' | 'series_c' | 'series_d' | 'series_e' | 'series_f' | 'series_g' | 'series_h' | 'other') | undefined}>) | undefined, names?: (Array<{coverage?: ('last_funding' | 'any_round' | 'total_funds' | 'last_round') | undefined, name?: ('angel' | 'venture' | 'private_equity' | 'crowdfunding' | 'grant' | 'debt_financing' | 'other') | undefined}>) | undefined, investors?: Array | undefined, types?: Array | undefined}) | undefined, foundedYear?: (Array<{min?: number | undefined, max?: number | undefined}>) | undefined, businessModel?: (Array<'B2B' | 'B2C' | 'B2G'>) | undefined, companyType?: (Array<'Government' | 'Private Company' | 'Public Company' | 'Educational' | 'Non Profit' | 'Self Employed'>) | undefined, linkedinUrls?: Array | undefined, keywords?: Array | undefined, specialities?: Array | undefined, exactSpecialities?: Array | undefined, exactKeywords?: Array | undefined, keywordsSearchFields?: Array | undefined, previousCompanyDomains?: Array | undefined, previousCompanyNames?: Array | undefined, geographicDetails?: (Array<{country?: string | undefined, zipcode?: string | undefined, distance?: number | undefined}>) | undefined, locationsZipcodes?: (Array<{countryIso2?: string | undefined, zipcode?: string | undefined}>) | undefined, headquarterZipcodes?: (Array<{countryIso2?: string | undefined, zipcode?: string | undefined}>) | undefined}; export type V3ProspectingContactFilters = {contacts?: ({include?: V3ContactFilterCriteria | undefined, exclude?: V3ContactFilterCriteria | undefined}) | undefined, companies?: ({include?: V3CompanyFilterCriteria | undefined, exclude?: V3CompanyFilterCriteria | undefined}) | undefined}; export type V3ProspectingContactsRequest = {pagination: V3PaginationRequest, filters: V3ProspectingContactFilters, tableId?: string | undefined, options?: ({includePartialProfiles?: boolean | undefined, excludeDnc?: boolean | undefined, maxContactsPerCompany?: number | undefined}) | undefined}; export type CreateApiV3ContactsProspectingArgs = {body: V3ProspectingContactsRequest}; export type CreateApiV3ContactsProspectingOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const v3CanRevealItem = z.object({field: z.enum(["emails", "phones"]).optional(), credits: z.number().int().optional()}); export const v3ItemError = z.object({code: z.enum(["NOT_FOUND", "COMPLIANCE_RESTRICTED", "ENRICH_FAILED", "NO_SCORE"]).optional(), message: z.string().optional()}); export const v3ContactPreview = z.object({clientReferenceId: z.string().optional(), id: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), jobTitle: z.object({title: z.string().optional(), departments: z.array(z.string()).optional(), seniority: z.string().optional()}).optional(), company: z.object({id: z.string().optional(), name: z.string().optional(), domain: z.string().optional()}).optional(), location: z.object({country: z.string().optional(), state: z.string().optional(), city: z.string().optional()}).optional(), socialLinks: z.object({linkedin: z.string().optional()}).optional(), has: z.array(z.string()).optional(), canReveal: z.array(v3CanRevealItem).optional(), signalTypes: z.array(z.string()).optional(), error: v3ItemError.optional()}); export const v3ProspectingContactsPagination = z.object({page: z.number().int().optional(), size: z.number().int().optional(), total: z.number().int().optional(), totalGuaranteed: z.boolean().optional(), totalDescription: z.string().optional()}); export const tableWrite = z.object({tableId: z.string().optional(), added: z.number().int().optional(), alreadyPresent: z.number().int().optional(), columnsCreated: z.number().int().optional(), rowsProcessed: z.number().int().optional(), rowsCharged: z.number().int().optional(), rowsAlreadyPaidInTable: z.number().int().optional(), creditsCharged: z.number().int().optional()}); export const v3Billing = z.object({creditsCharged: z.number().int().optional(), resultsReturned: z.number().int().optional()}); export const v3ProspectingContactsResponse = z.object({requestId: z.string().optional(), results: z.array(v3ContactPreview).optional(), pagination: v3ProspectingContactsPagination.optional(), tableWrite: tableWrite.optional(), billing: v3Billing.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 }; /** * Prospecting Contacts * * POST /v3/contacts/prospecting */ export const createApiV3ContactsProspecting = async (args: CreateApiV3ContactsProspectingArgs, options?: CreateApiV3ContactsProspectingOptions) => { const {baseUrl = "https://api.lusha.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("api_key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v3/contacts/prospecting${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(v3ProspectingContactsResponse, await res.json()) };