import {z} from 'zod' export type Address = {street?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, postal_code?: (string | null) | undefined, country?: (string | null) | undefined}; export type Account = {name: string, industry?: (string | null) | undefined, type?: (string | null) | undefined, phone?: (string | null) | undefined, website?: (string | null) | undefined, revenue?: (number | null) | undefined, employees?: (number | null) | undefined, address?: (Address | null) | undefined, description?: (string | null) | undefined, rating?: (string | null) | undefined}; export type Contact = {first_name?: (string | null) | undefined, last_name: string, email?: (string | null) | undefined, phone?: (string | null) | undefined, mobile?: (string | null) | undefined, title?: (string | null) | undefined, department?: (string | null) | undefined, account_id?: (string | null) | undefined, address?: (Address | null) | undefined, description?: (string | null) | undefined, source?: (string | null) | undefined}; export type Opportunity = {name: string, stage: string, close_date: string, amount?: (number | null) | undefined, probability?: (number | null) | undefined, account_id?: (string | null) | undefined, type?: (string | null) | undefined, source?: (string | null) | undefined, next_step?: (string | null) | undefined, description?: (string | null) | undefined}; export type Lead = {first_name?: (string | null) | undefined, last_name: string, company: string, email?: (string | null) | undefined, phone?: (string | null) | undefined, mobile?: (string | null) | undefined, title?: (string | null) | undefined, status?: (string | null) | undefined, source?: (string | null) | undefined, industry?: (string | null) | undefined, rating?: (string | null) | undefined, address?: (Address | null) | undefined, website?: (string | null) | undefined, description?: (string | null) | undefined, employees?: (number | null) | undefined, revenue?: (number | null) | undefined}; export type Case = {subject: string, status?: (string | null) | undefined, priority?: (string | null) | undefined, origin?: (string | null) | undefined, type?: (string | null) | undefined, reason?: (string | null) | undefined, account_id?: (string | null) | undefined, contact_id?: (string | null) | undefined, description?: (string | null) | undefined, customer_email?: (string | null) | undefined, customer_name?: (string | null) | undefined, customer_phone?: (string | null) | undefined}; export type Campaign = {name: string, type?: (string | null) | undefined, status?: (string | null) | undefined, start_date?: (string | null) | undefined, end_date?: (string | null) | undefined, expected_revenue?: (number | null) | undefined, budget?: (number | null) | undefined, actual_cost?: (number | null) | undefined, description?: (string | null) | undefined, active?: (boolean | null) | undefined}; export type SalesforceDataInput = {accounts?: (Array | null) | undefined, contacts?: (Array | null) | undefined, opportunities?: (Array | null) | undefined, leads?: (Array | null) | undefined, cases?: (Array | null) | undefined, campaigns?: (Array | null) | undefined}; export type CreateApiSandboxSalesforceSandboxIdInitializeArgs = {sandbox_id: string, init_default_data?: boolean | undefined, body: SalesforceDataInput | null}; export type CreateApiSandboxSalesforceSandboxIdInitializeOptions = {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 salesforce sandbox with data * * POST /sandbox/salesforce/{sandbox_id}/initialize */ export const createApiSandboxSalesforceSandboxIdInitialize = async (args: CreateApiSandboxSalesforceSandboxIdInitializeArgs, options?: CreateApiSandboxSalesforceSandboxIdInitializeOptions) => { 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/salesforce/${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()) };