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 V3Range = {min?: number | undefined, max?: number | undefined}; export type V3CompanyProspectingFilters = {names?: Array | undefined, domains?: Array | undefined, ids?: Array | undefined, searchText?: string | undefined, locations?: Array | undefined, sizes?: Array | undefined, revenues?: Array | undefined, technologies?: Array | undefined, technologiesCondition?: ('or' | 'and') | 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, signals?: ({types?: Array | undefined, startDate?: string | undefined, filterByLocation?: (Array<{country?: string | undefined, state?: string | undefined, startDate?: string | undefined}>) | undefined, filterByDepartment?: (Array<{department: string, startDate?: string | undefined}>) | undefined, filterByIntentCategory?: 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 V3ContactsOnCompanySearchFilters = {jobTitles?: Array | undefined, departments?: Array | undefined, seniorityIds?: Array | undefined, skills?: Array | undefined, locations?: Array | undefined, existingDataPoints?: Array | undefined}; export type V3ProspectingCompaniesRequest = {pagination: V3PaginationRequest, filters: {companies: {include: V3CompanyProspectingFilters, exclude?: V3CompanyProspectingFilters | undefined}, contacts?: ({include?: V3ContactsOnCompanySearchFilters | undefined, exclude?: V3ContactsOnCompanySearchFilters | undefined}) | undefined}, tableId?: string | undefined, options?: ({includePartialProfiles?: boolean | undefined}) | undefined}; export type CreateApiV3CompaniesProspectingArgs = {body: V3ProspectingCompaniesRequest}; export type CreateApiV3CompaniesProspectingOptions = {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 v3CompanyPreview = z.object({clientReferenceId: z.string().optional(), id: z.string().optional(), name: z.string().optional(), domain: z.string().optional(), employeeCount: z.object({exact: z.number().int().optional(), min: z.number().int().optional(), max: z.number().int().optional()}).optional(), industry: z.string().optional(), location: z.object({city: z.string().optional(), state: z.string().optional(), stateCode: z.string().optional(), country: z.string().optional(), countryIso2: z.string().optional(), continent: 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 v3PaginationResponse = z.object({page: z.number().int().optional(), size: z.number().int().optional(), total: z.number().int().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 v3ProspectingCompaniesResponse = z.object({requestId: z.string().optional(), results: z.array(v3CompanyPreview).optional(), pagination: v3PaginationResponse.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 Companies * * POST /v3/companies/prospecting */ export const createApiV3CompaniesProspecting = async (args: CreateApiV3CompaniesProspectingArgs, options?: CreateApiV3CompaniesProspectingOptions) => { 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/companies/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(v3ProspectingCompaniesResponse, await res.json()) };