import {z} from 'zod' export type BomboraIntentEnrichmentParams = {topics?: Array | undefined, min_score?: number | undefined}; export type BomboraIntentBulkEnrichRequest = {request_context?: (Record | null) | undefined, parameters?: BomboraIntentEnrichmentParams | undefined, business_ids: Array}; export type CreateApiV1BusinessesBomboraIntentBulkEnrichArgs = {body: BomboraIntentBulkEnrichRequest}; export type CreateApiV1BusinessesBomboraIntentBulkEnrichOptions = {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 bomboraIntentOutputSchema = z.object({business_id: z.string().optional(), company_name: z.string().max(256).optional(), company_website: z.string().max(2048).optional(), date_stamp: z.string().optional(), intent_topics: z.string(), level_of_intent: z.string().optional(), topic_count: z.string().optional()}); export const businessesBulkEnrichRowBomboraIntentOutputSchema = z.object({business_id: z.string(), data: bomboraIntentOutputSchema.optional()}); export const businessesBulkEnrichResponseBomboraIntentOutputSchema = z.object({response_context: responseContext, data: z.array(businessesBulkEnrichRowBomboraIntentOutputSchema).optional(), entity_id: z.union([z.string(), z.string()]).optional(), total_results: z.number().int()}); 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 }; /** * Bombora Intent * * POST /v1/businesses/bombora_intent/bulk_enrich * * Also accepts auth: APIKeyHeader */ export const createApiV1BusinessesBomboraIntentBulkEnrich = async (args: CreateApiV1BusinessesBomboraIntentBulkEnrichArgs, options?: CreateApiV1BusinessesBomboraIntentBulkEnrichOptions) => { 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(/\/+$/, '')}/v1/businesses/bombora_intent/bulk_enrich${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(businessesBulkEnrichResponseBomboraIntentOutputSchema, await res.json()) };