import {z} from 'zod' export type HubSpotCompanyInput = {company_name: string, website_domain?: (string | null) | undefined, industry?: (string | null) | undefined, city?: (string | null) | undefined, state_region?: (string | null) | undefined, country?: (string | null) | undefined, phone_number?: (string | null) | undefined, employee_count?: (string | null) | undefined, yearly_revenue?: (string | null) | undefined}; export type HubSpotContactInput = {first_name: string, last_name: string, email_address: string, phone_number?: (string | null) | undefined, job_title?: (string | null) | undefined}; export type HubSpotDealInput = {title: string, value?: (string | null) | undefined, stage?: (string | null) | undefined, pipeline?: (string | null) | undefined, expected_close_date?: (string | null) | undefined}; export type HubSpotTicketInput = {title: string, description?: (string | null) | undefined, pipeline?: (string | null) | undefined, workflow_stage?: (string | null) | undefined, priority_level?: (string | null) | undefined}; export type HubSpotTaskInput = {title: string, description?: (string | null) | undefined, task_status?: (string | null) | undefined, priority_level?: (string | null) | undefined, deadline?: (string | null) | undefined}; export type HubSpotDataInput = {companies?: (Array | null) | undefined, contacts?: (Array | null) | undefined, deals?: (Array | null) | undefined, tickets?: (Array | null) | undefined, tasks?: (Array | null) | undefined}; export type CreateApiSandboxHubspotSandboxIdInitializeArgs = {sandbox_id: string, init_default_data?: boolean | undefined, body: HubSpotDataInput | null}; export type CreateApiSandboxHubspotSandboxIdInitializeOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const sandboxStatus = z.enum(["idle", "occupied", "error"]); export const initializeSandboxResponse = z.object({sandbox_id: z.string(), status: sandboxStatus, message: z.string()}); 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 }; /** * Initialize hubspot sandbox with data * * POST /sandbox/hubspot/{sandbox_id}/initialize */ export const createApiSandboxHubspotSandboxIdInitialize = async (args: CreateApiSandboxHubspotSandboxIdInitializeArgs, options?: CreateApiSandboxHubspotSandboxIdInitializeOptions) => { const {baseUrl = "https://api.klavis.ai", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.init_default_data != null) query.append("init_default_data", String(args.init_default_data)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/sandbox/hubspot/${encodeURIComponent(String(args.sandbox_id))}/initialize${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(initializeSandboxResponse, await res.json()) };