import {z} from 'zod' export type CompanyNameFilterDto = {includes?: Array | undefined, excludes?: Array | undefined, exactMatch?: number | undefined}; export type CompanyIncludesExcludesFilterDto = {includes?: Array | undefined, excludes?: Array | undefined, exactMatch?: number | undefined}; export type CompanyRangeFilterDto = {min?: string | undefined, max?: string | undefined}; export type CompanyIndustryIncludesExcludesDto = {includes?: Array | undefined, excludes?: Array | undefined}; export type CompanyIncludesExcludesSimpleFilterDto = {includes?: Array | undefined, excludes?: Array | undefined}; export type CompanyIncludesFilterDto = {includes?: Array | undefined}; export type ProductReviewScoreChangeFilter = {duration?: ('current' | 'monthly' | 'quarterly' | 'yearly') | undefined, direction?: ('up' | 'down' | 'any') | undefined, points_range?: CompanyRangeFilterDto | undefined}; export type LastFundingRoundNameIncludesDto = {includes?: Array | undefined}; export type FundingRoundsNameIncludesDto = {includes?: Array | undefined}; export type SeniorityCountFilterDto = {group?: ('owner' | 'founder' | 'clevel' | 'partner' | 'vp' | 'head' | 'director' | 'manager' | 'senior' | 'mid' | 'junior' | 'intern' | 'specialist' | 'other_management') | undefined, count?: CompanyRangeFilterDto | undefined}; export type DepartmentCountFilterDto = {group?: ('medical' | 'sales' | 'hr' | 'legal' | 'marketing' | 'finance' | 'technical' | 'consulting' | 'operations' | 'product' | 'general_management' | 'administrative' | 'customer_service' | 'project_management' | 'design' | 'research' | 'trades' | 'real_estate' | 'education' | 'other_department') | undefined, count?: CompanyRangeFilterDto | undefined}; export type BaseSalaryFilterDto = {title?: CompanyIncludesExcludesFilterDto | undefined, range?: CompanyRangeFilterDto | undefined}; export type LookAlikeFilterDto = {value?: string | undefined, company_id?: number | undefined, _company_name?: string | undefined, _industry?: string | undefined, _categories_and_keywords?: Array | undefined, _technologies_used?: Array | undefined, _competitors?: Array | undefined, _annual_revenue?: number | undefined, _followers_count_linkedin?: number | undefined, _total_website_visits_monthly?: number | undefined, _ownership_status?: string | undefined}; export type VisitsBreakdownByCountryFilterDto = {country?: string | undefined, percentage?: CompanyRangeFilterDto | undefined}; export type VisitsBreakdownByGenderFilterDto = {gender?: ('male' | 'female') | undefined, percentage?: CompanyRangeFilterDto | undefined}; export type SearchCompaniesOpenAPIDto = {signalIds?: Array | undefined, newsIds?: Array | undefined, company_name?: CompanyNameFilterDto | undefined, company_hq_location?: CompanyIncludesExcludesFilterDto | undefined, company_founded_year?: CompanyRangeFilterDto | undefined, company_industry?: CompanyIndustryIncludesExcludesDto | undefined, company_domain?: CompanyIncludesExcludesSimpleFilterDto | undefined, type?: ('Privately Held' | 'Public Company' | 'Self-Owned' | 'Self-Employed' | 'Partnership' | 'Nonprofit' | 'Educational' | 'Government Agency') | undefined, sic_codes?: CompanyIncludesFilterDto | undefined, naics_codes?: CompanyIncludesFilterDto | undefined, product_reviews_score_change?: ProductReviewScoreChangeFilter | undefined, is_b2b?: boolean | undefined, technologies_used?: CompanyIncludesFilterDto | undefined, last_funding_round_name?: LastFundingRoundNameIncludesDto | undefined, last_funding_round_amount_raised?: CompanyRangeFilterDto | undefined, last_funding_round_announced_date?: CompanyRangeFilterDto | undefined, funding_rounds_name?: FundingRoundsNameIncludesDto | undefined, company_funding_amount?: CompanyRangeFilterDto | undefined, company_funding_date?: CompanyRangeFilterDto | undefined, company_annual_revenue?: CompanyRangeFilterDto | undefined, company_size?: CompanyRangeFilterDto | undefined, employee_count_seniority?: Array | undefined, employee_count_department?: Array | undefined, base_salary?: Array | undefined, ownership_status?: ('Private' | 'Public' | 'Other') | undefined, website?: CompanyIncludesFilterDto | undefined, look_alike_company_name?: Array | undefined, linkedin_url?: CompanyIncludesExcludesFilterDto | undefined, followers_count_linkedin?: CompanyRangeFilterDto | undefined, active_job_postings_title?: CompanyIncludesFilterDto | undefined, active_job_postings_count?: CompanyRangeFilterDto | undefined, total_website_visits_monthly?: CompanyRangeFilterDto | undefined, rank_global?: CompanyRangeFilterDto | undefined, visits_breakdown_by_country?: Array | undefined, visits_breakdown_by_gender?: Array | undefined, product_reviews_aggregate_score?: CompanyRangeFilterDto | undefined, product_reviews_count?: CompanyRangeFilterDto | undefined, employee_reviews_total_count?: CompanyRangeFilterDto | undefined, employee_reviews_aggregate_score?: CompanyRangeFilterDto | undefined, employee_reviews_business_outlook?: CompanyRangeFilterDto | undefined, employee_reviews_ceo_approval?: CompanyRangeFilterDto | undefined, employee_reviews_career_opportunities?: CompanyRangeFilterDto | undefined, employee_reviews_recommend?: CompanyRangeFilterDto | undefined, employee_reviews_work_life_balance?: CompanyRangeFilterDto | undefined, employee_reviews_culture_values?: CompanyRangeFilterDto | undefined, keywords?: CompanyIncludesFilterDto | undefined, social_urls?: CompanyIncludesFilterDto | undefined, page?: number | undefined, tab?: ('total' | 'netNew') | undefined}; export type CreateApiV1SearchCompaniesArgs = {body: SearchCompaniesOpenAPIDto}; export type CreateApiV1SearchCompaniesOptions = {baseUrl: string, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1SearchCompaniesResponse = 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(), company: z.array(z.object({id: z.number().optional(), name: z.string().optional(), linkedin_url: z.string().optional(), website_domain: z.string().optional(), twitter_url: z.string().optional(), discord_url: z.string().optional(), facebook_url: z.string().optional(), instagram_url: z.string().optional(), pinterest_url: z.string().optional(), tiktok_url: z.string().optional(), youtube_url: z.string().optional(), github_url: z.string().optional(), reddit_url: z.string().optional(), crunchbase_url: z.string().optional(), location: z.object({city: z.string().optional(), state: z.string().optional(), country: z.string().optional()}).optional(), company_locations: z.array(z.object({location_address: z.string().optional(), is_primary: z.boolean().optional(), country: z.string().optional(), city: z.string().optional(), state: z.string().optional(), street: z.string().optional(), zip_code: z.string().optional(), regions: z.array(z.string()).optional()})).optional(), founded_year: z.number().optional(), industry: z.string().optional(), type: z.string().nullable().optional(), is_b2b: z.boolean().nullable().optional(), sic_codes: z.array(z.string()).optional(), naics_codes: z.array(z.string()).optional(), employee_count: z.number().nullable().optional(), revealType: z.enum(["enriched", "notEnriched", "imported"]).nullable().optional(), socials: z.array(z.string()).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 companies by filters * * POST /v1/search/companies */ export const createApiV1SearchCompanies = async (args: CreateApiV1SearchCompaniesArgs, options: CreateApiV1SearchCompaniesOptions) => { 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/companies${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(createApiV1SearchCompaniesResponse, await res.json()) };