import {z} from 'zod' export type GetApiApiV2TechCompaniesArgs = {'X-API-Key': string, tech: string, variations?: Array | undefined, lookback_days?: number | undefined, page?: number | undefined, exclude_vendor?: boolean | undefined, exclude_aggregators?: boolean | undefined, exclude_company_slugs?: Array | undefined, include_evidence?: boolean | undefined, enrich?: boolean | undefined, hq_country_code?: (string | null) | undefined, min_employee_count?: (number | null) | undefined, max_employee_count?: (number | null) | undefined}; export type GetApiApiV2TechCompaniesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const filtersApplied = z.object({hq_country_code: z.string().nullable().optional(), min_employee_count: z.number().int().nullable().optional(), max_employee_count: z.number().int().nullable().optional()}); export const companyEvidence = z.object({title: z.string().nullable().optional(), url: z.string().nullable().optional(), created: z.string().nullable().optional(), snippet: z.string().nullable().optional()}); export const companyHit = z.object({company_slug: z.string(), company_name: z.string().nullable().optional(), post_count: z.number().int(), first_posted_at: z.string().nullable().optional(), last_posted_at: z.string().nullable().optional(), evidence: companyEvidence.nullable().optional(), enriched: z.boolean().optional(), website: z.string().nullable().optional(), linkedin_url: z.string().nullable().optional(), linkedin_org_id: z.string().nullable().optional(), linkedin_follower_count: z.number().int().nullable().optional(), employee_count: z.number().int().nullable().optional(), industries: z.array(z.string()).nullable().optional(), description: z.string().nullable().optional(), hq_city: z.string().nullable().optional(), hq_region: z.string().nullable().optional(), hq_country: z.string().nullable().optional(), hq_country_code: z.string().nullable().optional(), funding_stage: z.string().nullable().optional(), total_funding_usd: z.number().int().nullable().optional(), latest_funding_usd: z.number().int().nullable().optional(), revenue_usd: z.number().int().nullable().optional()}); export const companiesResponse = z.object({tech: z.string(), variations: z.array(z.string()).optional(), lookback_days: z.number().int(), page: z.number().int(), page_size: z.number().int(), total_results: z.number().int(), has_more: z.boolean(), total_companies_matched: z.number().int(), filters_applied: filtersApplied.optional(), companies: z.array(companyHit), credits_consumed: z.number().int().optional(), latency_ms: z.number().int().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 Tech Stack * * GET /api/v2/tech/companies */ export const getApiApiV2TechCompanies = async (args: GetApiApiV2TechCompaniesArgs, options?: GetApiApiV2TechCompaniesOptions) => { const {baseUrl = "https://api.openfunnel.dev", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) if (args.tech != null) query.append("tech", String(args.tech)) for (const item of args.variations ?? []) query.append("variations", String(item)) if (args.lookback_days != null) query.append("lookback_days", String(args.lookback_days)) if (args.page != null) query.append("page", String(args.page)) if (args.exclude_vendor != null) query.append("exclude_vendor", String(args.exclude_vendor)) if (args.exclude_aggregators != null) query.append("exclude_aggregators", String(args.exclude_aggregators)) for (const item of args.exclude_company_slugs ?? []) query.append("exclude_company_slugs", String(item)) if (args.include_evidence != null) query.append("include_evidence", String(args.include_evidence)) if (args.enrich != null) query.append("enrich", String(args.enrich)) if (args.hq_country_code != null) query.append("hq_country_code", String(args.hq_country_code)) if (args.min_employee_count != null) query.append("min_employee_count", String(args.min_employee_count)) if (args.max_employee_count != null) query.append("max_employee_count", String(args.max_employee_count)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/tech/companies${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(companiesResponse, await res.json()) };