import {z} from 'zod' export type ELeadStatusInputView = number; export type LeadSearch = {skip?: number | undefined, limit?: number | undefined, sortProp?: (string | null) | undefined, isAscending?: boolean | undefined, statuses?: (Array | null) | undefined, searchInput?: (string | null) | undefined}; export type CreateApiV1OutboundOutboundIdLeadsArgs = {outboundId: string, body: LeadSearch}; export type CreateApiV1OutboundOutboundIdLeadsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const eLeadStatusView = z.number().int(); export const leadListApiView = z.object({id: z.string().nullable().optional(), externalId: z.string().nullable().optional(), phoneNumber: z.string().nullable().optional(), timeZoneId: z.string().nullable().optional(), status: eLeadStatusView.optional(), created: z.string().optional(), callData: z.record(z.string(), z.string()).nullable().optional()}); export const leadListApiViewTableSearchResult = z.object({count: z.number().int().optional(), results: z.array(leadListApiView).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 }; /** * Search Leads * * POST /v1/Outbound/{outboundId}/Leads */ export const createApiV1OutboundOutboundIdLeads = async (args: CreateApiV1OutboundOutboundIdLeadsArgs, options?: CreateApiV1OutboundOutboundIdLeadsOptions) => { 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(/\/+$/, '')}/v1/Outbound/${encodeURIComponent(String(args.outboundId))}/Leads${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(leadListApiViewTableSearchResult, await res.json()) };