import {z} from 'zod' export type QuestionSetUpdate = {name?: (string | null) | undefined, description?: (string | null) | undefined}; export type PatchApiV1InterviewsInterviewIdQuestionSetsSetIdArgs = {interview_id: string, set_id: string, 'X-API-Key'?: (string | null) | undefined, body: QuestionSetUpdate}; export type PatchApiV1InterviewsInterviewIdQuestionSetsSetIdOptions = {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 }; /** * Update Question Set * * PATCH /v1/interviews/{interview_id}/question-sets/{set_id} */ export const patchApiV1InterviewsInterviewIdQuestionSetsSetId = async (args: PatchApiV1InterviewsInterviewIdQuestionSetsSetIdArgs, options: PatchApiV1InterviewsInterviewIdQuestionSetsSetIdOptions) => { 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/${encodeURIComponent(String(args.set_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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()) };