import {z} from 'zod' export type WebhookSimulationEventType = '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' | 'employee_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 WebhookSimulation = {event_name?: WebhookSimulationEventType | undefined, number_of_events?: number | undefined, event_time?: string | undefined}; export type WebhookCheckConnectivityRequest = {request_context?: (Record | null) | undefined, partner_id: string, simulation?: WebhookSimulation | undefined}; export type CreateApiV1WebhooksCheckConnectivityArgs = {tenant?: string | undefined, body: WebhookCheckConnectivityRequest}; export type CreateApiV1WebhooksCheckConnectivityOptions = {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 webhookCheckConnectivityResponse = z.object({response_context: responseContext}); 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 }; /** * Check Webhook Connectivity * * POST /v1/webhooks/check_connectivity * * Also accepts auth: APIKeyHeader */ export const createApiV1WebhooksCheckConnectivity = async (args: CreateApiV1WebhooksCheckConnectivityArgs, options?: CreateApiV1WebhooksCheckConnectivityOptions) => { 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/webhooks/check_connectivity${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(webhookCheckConnectivityResponse, await res.json()) };