import {z} from 'zod' export type EntityType = 'business' | 'prospect'; export type EventTypeEnum = 'award' | 'closing_office' | 'company_award' | 'cost_cutting' | 'decrease_in_all_departments' | 'decrease_in_customer_service_department' | 'decrease_in_engineering_department' | 'decrease_in_marketing_department' | 'decrease_in_operations_department' | 'decrease_in_sales_department' | 'executive_joined_company' | 'funding_round' | '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' | 'increase_in_all_departments' | 'increase_in_customer_service_department' | 'increase_in_engineering_department' | 'increase_in_marketing_department' | 'increase_in_operations_department' | 'increase_in_sales_department' | 'ipo_announcement' | 'lawsuits_and_legal_issues' | 'merger_and_acquisitions' | 'new_funding_round' | 'new_investment' | 'new_office' | 'new_partnership' | 'new_product' | 'outages_and_security_breaches' | 'prospect_changed_company' | 'prospect_changed_role' | 'prospect_job_start_anniversary'; export type V2ProspectsEventsRequest = {request_context?: (Record | null) | undefined, entity_type?: EntityType | undefined, event_types: Array, timestamp_to?: (string | string | null) | undefined, timestamp_from?: (string | string | null) | undefined, prospect_ids: Array}; export type CreateApiV2ProspectsEventsArgs = {body: V2ProspectsEventsRequest}; export type CreateApiV2ProspectsEventsOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const requestStatus = z.enum(["success", "miss", "failure"]); export const v2ResponseContext = z.object({correlation_id: z.string(), request_status: requestStatus, time_taken_in_seconds: z.number()}); export const eventTypeEnum = z.enum(["award", "closing_office", "company_award", "cost_cutting", "decrease_in_all_departments", "decrease_in_customer_service_department", "decrease_in_engineering_department", "decrease_in_marketing_department", "decrease_in_operations_department", "decrease_in_sales_department", "executive_joined_company", "funding_round", "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", "increase_in_all_departments", "increase_in_customer_service_department", "increase_in_engineering_department", "increase_in_marketing_department", "increase_in_operations_department", "increase_in_sales_department", "ipo_announcement", "lawsuits_and_legal_issues", "merger_and_acquisitions", "new_funding_round", "new_investment", "new_office", "new_partnership", "new_product", "outages_and_security_breaches", "prospect_changed_company", "prospect_changed_role", "prospect_job_start_anniversary"]); export const v2ProspectsEventOutput = z.object({event_name: eventTypeEnum, event_time: z.string(), event_id: z.string(), data: z.unknown(), prospect_id: z.string()}); export const v2ProspectsFetchEventsResponse = z.object({response_context: v2ResponseContext, output_events: z.array(v2ProspectsEventOutput)}); 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 Prospects Events * * POST /v2/prospects/events * * Also accepts auth: APIKeyHeader */ export const createApiV2ProspectsEvents = async (args: CreateApiV2ProspectsEventsArgs, options?: CreateApiV2ProspectsEventsOptions) => { 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 (APIKeyHeader !== undefined) headers.set("api_key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v2/prospects/events${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(v2ProspectsFetchEventsResponse, await res.json()) };