import {z} from 'zod' export type QuestionType = 'open_ended' | 'single_choice' | 'multiple_choice' | 'likert_scale' | 'ranking' | 'statement' | 'range_slider' | 'matrix'; export type FollowUpRule = 'auto' | 'none' | 'on_short_answers' | 'one_followup' | 'up_to_three' | 'no_followup_allowed'; export type QuestionCreate = {question_text: string, is_required?: boolean | undefined, sort_order?: number | undefined, question_type?: QuestionType | undefined, options?: Array | undefined, component_config?: ({[key: string]: unknown} | null) | undefined, follow_up_rule?: FollowUpRule | undefined, follow_up_guideline?: string | undefined, requires_screen_share?: boolean | undefined, screen_share_prompt?: string | undefined}; export type QuestionSetCreate = {name: string, description?: (string | null) | undefined, sort_order?: number | undefined, topic_metadata?: ({[key: string]: unknown} | null) | undefined, questions?: Array | undefined}; export type CreateApiV1InterviewsInterviewIdQuestionSetsArgs = {interview_id: string, 'X-API-Key'?: (string | null) | undefined, body: QuestionSetCreate}; export type CreateApiV1InterviewsInterviewIdQuestionSetsOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const questionType = z.enum(["open_ended", "single_choice", "multiple_choice", "likert_scale", "ranking", "statement", "range_slider", "matrix"]); export const followUpRule = z.enum(["auto", "none", "on_short_answers", "one_followup", "up_to_three", "no_followup_allowed"]); export const questionOut = z.object({id: z.string(), question_set_id: z.string(), question_text: z.string(), is_required: z.boolean(), sort_order: z.number().int(), question_type: questionType, options: z.array(z.string()), component_config: z.record(z.string(), z.unknown()).nullable().optional(), follow_up_rule: followUpRule, follow_up_guideline: z.string().optional(), requires_screen_share: z.boolean().optional(), screen_share_prompt: z.string().optional(), created_at: z.string()}); export const questionSetOut = z.object({id: z.string(), interview_id: z.string(), name: z.string(), description: z.string().nullable(), sort_order: z.number().int(), section_type: z.string().nullable().optional(), topic_metadata: z.record(z.string(), z.unknown()).nullable().optional(), questions: z.array(questionOut).optional(), created_at: z.string()}); 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 }; /** * Create Question Set * * POST /v1/interviews/{interview_id}/question-sets */ export const createApiV1InterviewsInterviewIdQuestionSets = async (args: CreateApiV1InterviewsInterviewIdQuestionSetsArgs, options: CreateApiV1InterviewsInterviewIdQuestionSetsOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") 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))}/question-sets${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(questionSetOut, await res.json()) };