import {z} from 'zod' export type GetApiV1InterviewsInterviewIdConversationsArgs = {interview_id: string, department?: (string | null) | undefined, job_title?: (string | null) | undefined, company?: (string | null) | undefined, position?: (string | null) | undefined, level?: (string | null) | undefined, location?: (string | null) | undefined, workgroup1?: (string | null) | undefined, workgroup2?: (string | null) | undefined, workgroup3?: (string | null) | undefined, search?: (string | null) | undefined, status?: (string | null) | undefined, locale?: (string | null) | undefined, limit?: number | undefined, offset?: number | undefined, 'X-Ontora-Locale'?: (string | null) | undefined, 'Accept-Language'?: (string | null) | undefined, 'X-API-Key'?: (string | null) | undefined}; export type GetApiV1InterviewsInterviewIdConversationsOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const audienceFacetOut = z.object({key: z.string(), values: z.array(z.string())}); export const topicCountOut = z.object({fulfilled: z.number().int(), total: z.number().int()}); export const conversationRowOut = z.object({id: z.string(), contact_id: z.string().nullable(), name: z.string(), job_title: z.string().nullable(), department: z.string().nullable(), seniority_level: z.number().int().nullable(), status: z.string(), duration_minutes: z.number().int().nullable(), pain_point_count: z.number().int(), completed_at: z.string().nullable(), summary: z.string().nullable(), session_id: z.string().nullable().optional(), session_token: z.string().nullable().optional(), reminder_count: z.number().int().optional(), reinvited_from_contact_id: z.string().nullable().optional(), invitation_status: z.string().optional(), session_rating: z.number().nullable().optional(), is_anonymous_response: z.boolean().optional(), audience_filter_attributes: z.record(z.string(), z.array(z.string())).optional(), language_code: z.string().nullable().optional(), language_label: z.string().nullable().optional(), topic_count: topicCountOut.nullable().optional(), runs_in_new_mode: z.boolean().optional(), conversation_mode: z.string().optional()}); export const conversationsListOut = z.object({total: z.number().int(), departments: z.array(z.string()), job_titles: z.array(z.string()), facets: z.array(audienceFacetOut).optional(), items: z.array(conversationRowOut), avg_duration_minutes: z.number().nullable().optional(), is_anonymous: z.boolean().optional(), anonymity_level: z.string().optional(), hide_conversations: z.boolean().optional(), show_language_flags: z.boolean().optional(), show_conversation_modes: 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 Conversations * * GET /v1/interviews/{interview_id}/conversations */ export const getApiV1InterviewsInterviewIdConversations = async (args: GetApiV1InterviewsInterviewIdConversationsArgs, options: GetApiV1InterviewsInterviewIdConversationsOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.department != null) query.append("department", String(args.department)) if (args.job_title != null) query.append("job_title", String(args.job_title)) if (args.company != null) query.append("company", String(args.company)) if (args.position != null) query.append("position", String(args.position)) if (args.level != null) query.append("level", String(args.level)) if (args.location != null) query.append("location", String(args.location)) if (args.workgroup1 != null) query.append("workgroup1", String(args.workgroup1)) if (args.workgroup2 != null) query.append("workgroup2", String(args.workgroup2)) if (args.workgroup3 != null) query.append("workgroup3", String(args.workgroup3)) if (args.search != null) query.append("search", String(args.search)) if (args.status != null) query.append("status", String(args.status)) if (args.locale != null) query.append("locale", String(args.locale)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args['X-Ontora-Locale'] != null) headers.set("X-Ontora-Locale", String(args['X-Ontora-Locale'])) if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/interviews/${encodeURIComponent(String(args.interview_id))}/conversations${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(conversationsListOut, await res.json()) };