import {z} from 'zod' export type BaseFetchMode = 'full' | 'preview'; export type IncludesFilterCountryCodeAlpha2 = {negate?: boolean | undefined, values: Array}; export type IncludesFilterRegionCode = {negate?: boolean | undefined, values: Array}; export type NumberOfEmployeesRange = '1-10' | '11-50' | '51-200' | '201-500' | '501-1000' | '1001-5000' | '5001-10000' | '10001+'; export type IncludesFilterNumberOfEmployeesRange = {negate?: boolean | undefined, values: Array}; export type RevenueRange = '0-500K' | '500K-1M' | '1M-5M' | '5M-10M' | '10M-25M' | '25M-75M' | '75M-200M' | '200M-500M' | '500M-1B' | '1B-10B' | '10B-100B' | '100B-1T' | '1T-10T' | '10T+'; export type IncludesFilterRevenueRange = {negate?: boolean | undefined, values: Array}; export type CompanyAgeRange = '0-3' | '3-6' | '6-10' | '10-20' | '20+'; export type IncludesFilterCompanyAgeRange = {negate?: boolean | undefined, values: Array}; export type IncludesFilterStandardizedText = {negate?: boolean | undefined, values: Array}; export type IncludesFilterNAICS = {negate?: boolean | undefined, values: Array}; export type IncludesFilterText = {negate?: boolean | undefined, values: Array}; export type DynamicIncludesFilterOrganizationName = {negate?: boolean | undefined, values: Array}; export type NumberOfLocations = '0-1' | '2-5' | '6-20' | '21-50' | '51-100' | '101-1000' | '1001+'; export type IncludesFilterNumberOfLocations = {negate?: boolean | undefined, values: Array}; export type AnyMatchPhraseFilterText = {negate?: boolean | undefined, values: Array}; export type BusinessIntentTopicsIntentLevel = 'emerging_intent' | 'high_intent' | 'very_high_intent'; export type BusinessIntentTopicsFilter = {negate?: boolean | undefined, topics: Array, topic_intent_level?: (BusinessIntentTopicsIntentLevel | null) | undefined}; export type BusinessesEventIdentifier = 'ipo_announcement' | 'new_funding_round' | 'new_investment' | 'new_product' | 'new_office' | 'closing_office' | 'new_partnership' | 'increase_in_engineering_department' | 'increase_in_sales_department' | 'increase_in_marketing_department' | 'increase_in_operations_department' | 'increase_in_customer_service_department' | 'increase_in_all_departments' | 'decrease_in_engineering_department' | 'decrease_in_sales_department' | 'decrease_in_marketing_department' | 'decrease_in_operations_department' | 'decrease_in_customer_service_department' | 'decrease_in_all_departments' | 'employee_joined_company' | 'hiring_in_creative_department' | 'hiring_in_education_department' | 'hiring_in_engineering_department' | 'hiring_in_finance_department' | 'hiring_in_health_department' | 'hiring_in_human_resources_department' | 'hiring_in_legal_department' | 'hiring_in_marketing_department' | 'hiring_in_operations_department' | 'hiring_in_professional_service_department' | 'hiring_in_sales_department' | 'hiring_in_support_department' | 'hiring_in_trade_department' | 'hiring_in_unknown_department' | 'company_award' | 'outages_and_security_breaches' | 'cost_cutting' | 'merger_and_acquisitions' | 'lawsuits_and_legal_issues'; export type EventTypesFilterBusinessesEventIdentifier = {negate?: boolean | undefined, values: Array, last_occurrence: number}; export type ExistsFilter = {negate?: boolean | undefined, value: boolean}; export type BusinessesFetchFilters = {country_code?: (IncludesFilterCountryCodeAlpha2 | null) | undefined, region_country_code?: (IncludesFilterRegionCode | null) | undefined, company_size?: (IncludesFilterNumberOfEmployeesRange | null) | undefined, company_revenue?: (IncludesFilterRevenueRange | null) | undefined, company_age?: (IncludesFilterCompanyAgeRange | null) | undefined, google_category?: (IncludesFilterStandardizedText | null) | undefined, naics_category?: (IncludesFilterNAICS | null) | undefined, linkedin_category?: (IncludesFilterStandardizedText | null) | undefined, company_tech_stack_category?: (IncludesFilterText | null) | undefined, company_tech_stack_tech?: (IncludesFilterText | null) | undefined, company_name?: (DynamicIncludesFilterOrganizationName | null) | undefined, number_of_locations?: (IncludesFilterNumberOfLocations | null) | undefined, city_region_country?: (IncludesFilterText | null) | undefined, city_region?: (IncludesFilterText | null) | undefined, website_keywords?: (AnyMatchPhraseFilterText | null) | undefined, business_intent_topics?: (BusinessIntentTopicsFilter | null) | undefined, events?: (EventTypesFilterBusinessesEventIdentifier | null) | undefined, has_website?: (ExistsFilter | null) | undefined, is_public_company?: (ExistsFilter | null) | undefined}; export type BusinessesFetchRequest = {request_context?: (Record | null) | undefined, mode: BaseFetchMode, size: number, page_size: number, page?: (number | null) | undefined, exclude?: (Array | null) | undefined, filters?: (BusinessesFetchFilters | null) | undefined, next_cursor?: (string | null) | undefined}; export type CreateApiV1BusinessesArgs = {tenant?: string | undefined, body: BusinessesFetchRequest}; export type CreateApiV1BusinessesOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const requestStatus = z.enum(["success", "miss", "failure"]); export const responseContext = z.object({correlation_id: z.string(), request_status: requestStatus, time_took_in_seconds: z.number()}); export const numberOfEmployeesRange = z.enum(["1-10", "11-50", "51-200", "201-500", "501-1000", "1001-5000", "5001-10000", "10001+"]); export const revenueRange = z.enum(["0-500K", "500K-1M", "1M-5M", "5M-10M", "10M-25M", "25M-75M", "75M-200M", "200M-500M", "500M-1B", "1B-10B", "10B-100B", "100B-1T", "1T-10T", "10T+"]); export const business = z.object({business_id: z.string(), name: z.string().max(256), domain: z.string().max(2048).optional(), logo: z.string().optional(), country_name: z.string().optional(), city_name: z.string().optional(), number_of_employees_range: numberOfEmployeesRange.optional(), yearly_revenue_range: revenueRange.optional(), website: z.string().optional(), business_description: z.string().optional(), region: z.string().optional(), naics: z.number().int().optional(), naics_description: z.string().optional(), sic_code: z.string().optional(), sic_code_description: z.string().optional(), business_intent_topics: z.array(z.object({})).optional(), events: z.array(z.string()).optional()}); export const businessesFetchResponse = z.object({response_context: responseContext, data: z.array(business).optional(), total_results: z.number().int().gte(0).optional(), page: z.number().int().gte(0).optional(), total_pages: z.number().int().gte(0)}); export const partnerServiceModelsServicesRequestsPageInfo = z.object({size: z.number().int(), next_cursor: z.string().optional()}); export const businessesFetchResponseV2 = z.object({response_context: responseContext, data: z.array(business).optional(), total_results: z.number().int().gte(0).optional(), page: partnerServiceModelsServicesRequestsPageInfo}); export const createApiV1BusinessesResponse = z.union([businessesFetchResponse, businessesFetchResponseV2]); 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 }; /** * Fetch Businesses * * POST /v1/businesses * * Also accepts auth: APIKeyHeader */ export const createApiV1Businesses = async (args: CreateApiV1BusinessesArgs, options?: CreateApiV1BusinessesOptions) => { const {baseUrl = "https://api.explorium.ai", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.tenant != null) headers.set("tenant", String(args.tenant)) if (APIKeyHeader !== undefined) headers.set("api_key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/businesses${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(createApiV1BusinessesResponse, await res.json()) };