import {z} from 'zod' export type GetApiV3AiSdrApprovalsArgs = {top?: number | undefined, skip?: number | undefined, sequenceId?: number | undefined, userId?: number | undefined, channel?: ('email' | 'linkedIn') | undefined, sortMode?: ('newestFirst' | 'oldestFirst') | undefined}; export type GetApiV3AiSdrApprovalsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV3AiSdrApprovalsResponse = z.object({items: z.array(z.object({sequenceId: z.number().int().optional(), contactId: z.number().int().optional(), contactFullName: z.string().optional(), contactTitle: z.string().optional(), contactCompany: z.string().optional(), sequenceName: z.string().optional(), channel: z.enum(["email", "linkedIn"]).optional(), stepDisplayName: z.string().optional(), messageSubject: z.string().nullable().optional(), messageContent: z.string().optional(), isRegenerating: z.boolean().optional(), createdAt: z.string().optional()})).optional(), hasMore: z.boolean().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 }; /** * List pending approvals * * GET /v3/ai-sdr/approvals */ export const getApiV3AiSdrApprovals = async (args: GetApiV3AiSdrApprovalsArgs, options?: GetApiV3AiSdrApprovalsOptions) => { const {baseUrl = "https://api.reply.io", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.top != null) query.append("top", String(args.top)) if (args.skip != null) query.append("skip", String(args.skip)) if (args.sequenceId != null) query.append("sequenceId", String(args.sequenceId)) if (args.userId != null) query.append("userId", String(args.userId)) if (args.channel != null) query.append("channel", String(args.channel)) if (args.sortMode != null) query.append("sortMode", String(args.sortMode)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/ai-sdr/approvals${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(getApiV3AiSdrApprovalsResponse, await res.json()) };