import {z} from 'zod' export type GetApiV1BroadcastDndLeadsArgs = {limit?: string | undefined, last_seen_id?: string | undefined, list_id?: string | undefined, id?: string | undefined, Authorization: string}; export type GetApiV1BroadcastDndLeadsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1BroadcastDndLeadsResponse = z.object({}); 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 }; /** * Fetch List of Leads in DND List * * GET /v1/broadcast/dnd/leads */ export const getApiV1BroadcastDndLeads = async (args: GetApiV1BroadcastDndLeadsArgs, options?: GetApiV1BroadcastDndLeadsOptions) => { const {baseUrl = "https://api-smartflo.tatateleservices.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.last_seen_id != null) query.append("last_seen_id", String(args.last_seen_id)) if (args.list_id != null) query.append("list_id", String(args.list_id)) if (args.id != null) query.append("id", String(args.id)) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/broadcast/dnd/leads${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1BroadcastDndLeadsResponse, await res.json()) };