import {z} from 'zod' export type GetApiV1ProspectsEventsEnrollmentsOptions = {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 eventName = z.enum(["prospect_changed_role", "prospect_changed_company", "prospect_job_start_anniversary", "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 const internalEventIdentifier = z.enum(["prospect_changed_role", "prospect_changed_company", "prospect_job_start_anniversary", "ipo_announcement", "new_funding_round", "new_investment", "new_product", "new_office", "closing_office", "new_partnership", "merger_and_acquisitions", "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_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", "company_award", "outages_and_security_breaches", "cost_cutting", "lawsuits_and_legal_issues"]); export const prospectsEnrollment = z.object({enrollment_id: z.string(), enrollment_key: z.string().min(4), event_types: z.array(z.union([eventName, internalEventIdentifier])), prospect_ids: z.array(z.string())}); export const prospectsEnrollmentsGetResponse = z.object({response_context: responseContext, enrollments: z.array(prospectsEnrollment)}); 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 }; /** * Get Prospects Enrollments * * GET /v1/prospects/events/enrollments * * Also accepts auth: APIKeyHeader */ export const getApiV1ProspectsEventsEnrollments = async (options?: GetApiV1ProspectsEventsEnrollmentsOptions) => { const {baseUrl = "https://api.explorium.ai", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("api_key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/prospects/events/enrollments${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(prospectsEnrollmentsGetResponse, await res.json()) };