import {z} from 'zod' export type IncludesFilterExactMatchDto = {includes?: Array | undefined, exactMatch?: number | undefined}; export type IncludesExcludesFilter1Dto = {includes?: Array | undefined, excludes?: Array | undefined, exactMatch?: number | undefined}; export type PeopleDepartmentIncludesExcludesDto = {includes?: Array | undefined, excludes?: Array | undefined}; export type IncludesFilterDto = {includes?: Array | undefined}; export type IncludesExcludesFilterDto = {includes?: Array | undefined, excludes?: Array | undefined, exactMatch?: number | undefined, shouldSearchPast?: number | undefined}; export type PeopleManagementLevelIncludesExcludesDto = {includes?: Array | undefined, excludes?: Array | undefined}; export type RangeFilterDto = {min?: string | undefined, max?: string | undefined}; export type PeopleCompanyIndustryIncludesExcludesDto = {includes?: Array | undefined, excludes?: Array | undefined}; export type IncludesExcludesFilter2Dto = {includes?: Array | undefined, excludes?: Array | undefined, exactMatch?: number | undefined, shouldSearchPast?: number | undefined}; export type PeopleEducationDegreeIncludesExcludesDto = {includes?: Array | undefined, excludes?: Array | undefined}; export type IncludesExcludesFilter4Dto = {includes?: Array | undefined, excludes?: Array | undefined}; export type SearchLeadsOpenAPIDto = {full_name?: IncludesFilterExactMatchDto | undefined, decision_maker?: boolean | undefined, company_bootstraped?: boolean | undefined, is_b2b?: boolean | undefined, linkedin_url?: Array | undefined, location?: IncludesExcludesFilter1Dto | undefined, department?: PeopleDepartmentIncludesExcludesDto | undefined, company_hq_location?: IncludesExcludesFilter1Dto | undefined, certifications?: IncludesFilterDto | undefined, job_title?: IncludesExcludesFilterDto | undefined, management_level?: PeopleManagementLevelIncludesExcludesDto | undefined, jobs_changed_within?: RangeFilterDto | undefined, company_annual_revenue?: RangeFilterDto | undefined, company_funding_amount?: RangeFilterDto | undefined, company_funding_date?: RangeFilterDto | undefined, company_founded_year?: RangeFilterDto | undefined, skills?: IncludesExcludesFilter1Dto | undefined, current_company_experience?: RangeFilterDto | undefined, current_role_tenure?: RangeFilterDto | undefined, total_experience?: RangeFilterDto | undefined, company_industry?: PeopleCompanyIndustryIncludesExcludesDto | undefined, company_name?: IncludesExcludesFilter2Dto | undefined, projected_base_salary?: RangeFilterDto | undefined, company_size?: RangeFilterDto | undefined, linkedin_connection_count?: RangeFilterDto | undefined, linkedin_followers_count?: RangeFilterDto | undefined, education_degrees?: PeopleEducationDegreeIncludesExcludesDto | undefined, social_link?: IncludesFilterDto | undefined, keywords?: IncludesFilterDto | undefined, page?: number | undefined, tab?: ('total' | 'netNew') | undefined, limitPerCompany?: number | undefined, company_domain?: IncludesExcludesFilter4Dto | undefined}; export type CreateApiV1SearchPeopleArgs = {body: SearchLeadsOpenAPIDto}; export type CreateApiV1SearchPeopleOptions = {baseUrl: string, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1SearchPeopleResponse = z.union([z.object({message: z.string().optional(), payload: z.object({status: z.string().optional(), display_limit: z.number().optional(), total_results: z.number().optional(), page: z.number().optional(), per_page: z.number().optional(), total_pages: z.number().optional(), has_next_page: z.boolean().optional(), has_previous_page: z.boolean().optional(), people: z.array(z.object({id: z.number().optional(), full_name: z.string().optional(), picture_url: z.string().optional(), job_title: z.string().optional(), company_name: z.string().optional(), company_logo_url: z.string().nullable().optional(), company_website: z.string().optional(), department: z.string().optional(), location: z.object({country: z.string().optional(), state: z.string().optional(), city: z.string().optional()}).optional(), total_experience: z.number().optional(), decision_maker: z.boolean().optional(), company_is_b2b: z.boolean().nullable().optional(), isRevealed: z.boolean().optional(), revealType: z.enum(["profileOnly", "email", "phone", "emailphone", "personalEmail", "personalEmailPhone", "emailPersonalEmailPhone", "emailPersonalEmail", "imported"]).nullable().optional()})).optional()}).optional()}), z.object({message: z.string().optional(), payload: z.array(z.unknown()).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 }; /** * Search leads by filters * * POST /v1/search/people */ export const createApiV1SearchPeople = async (args: CreateApiV1SearchPeopleArgs, options: CreateApiV1SearchPeopleOptions) => { 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/search/people${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(createApiV1SearchPeopleResponse, await res.json()) };