import {z} from 'zod' export type EConversationStatusView = number; export type CallsTableDateSearchApi = {skip?: number | undefined, limit?: number | undefined, sortProp?: (string | null) | undefined, isAscending?: boolean | undefined, fromDate: string, toDate: string, tags?: (Array | null) | undefined, statuses?: (Array | null) | undefined, searchInput?: (string | null) | undefined}; export type CreateApiV2PearlPearlIdCallsArgs = {pearlId: string, body: CallsTableDateSearchApi}; export type CreateApiV2PearlPearlIdCallsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const eConversationStatusView = z.number().int(); export const eCallStatusView = z.number().int(); export const callListApiView = z.object({id: z.string().nullable().optional(), startTime: z.string().nullable().optional(), conversationStatus: eConversationStatusView.optional(), status: eCallStatusView.optional(), from: z.string().nullable().optional(), to: z.string().nullable().optional(), duration: z.number().int().optional(), tags: z.array(z.string()).nullable().optional()}); export const callListApiViewTableSearchResult = z.object({count: z.number().int().optional(), results: z.array(callListApiView).nullable().optional()}); 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 }; /** * Get Calls * * POST /v2/Pearl/{pearlId}/Calls */ export const createApiV2PearlPearlIdCalls = async (args: CreateApiV2PearlPearlIdCallsArgs, options?: CreateApiV2PearlPearlIdCallsOptions) => { const {baseUrl = "https://api.nlpearl.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/Pearl/${encodeURIComponent(String(args.pearlId))}/Calls${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(callListApiViewTableSearchResult, await res.json()) };