import {z} from 'zod' 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 V2WebhookSimulation = {event_name?: EventTypeEnum | undefined, number_of_events?: number | undefined, event_time?: string | undefined}; export type WebhookConnectivityRequest = {simulation?: V2WebhookSimulation | undefined}; export type CreateApiV2WebhooksWebhookIdCheckConnectivityArgs = {webhook_id: string, body: WebhookConnectivityRequest}; export type CreateApiV2WebhooksWebhookIdCheckConnectivityOptions = {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 webhookConnectivityResponse = z.object({response_context: v2ResponseContext}); 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 Connectivity * * POST /v2/webhooks/{webhook_id}/check_connectivity * * Also accepts auth: APIKeyHeader */ export const createApiV2WebhooksWebhookIdCheckConnectivity = async (args: CreateApiV2WebhooksWebhookIdCheckConnectivityArgs, options?: CreateApiV2WebhooksWebhookIdCheckConnectivityOptions) => { 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/webhooks/${encodeURIComponent(String(args.webhook_id))}/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(webhookConnectivityResponse, await res.json()) };