import {z} from 'zod' export type AssessmentAnswer = {id?: (string | null) | undefined, answer: string, correct?: (boolean | null) | undefined, position?: number | undefined, explanation?: (string | null) | undefined}; export type LessonImageInQuestionSerializers = {id?: string | undefined, company?: (string | null) | undefined, image_name?: (string | null) | undefined, image_url?: (string | null) | undefined, image_url_public?: (string | null) | undefined, editor_content?: (string | null) | undefined, content_type?: ('lesson' | 'quiz' | 'engagement_question' | 'engagement_message' | 'assessment_question_content' | null) | undefined}; export type EditorStateInQuestionSerializers = {id?: string | undefined, note_editor_state?: (string | null) | undefined, summary_editor_state?: (string | null) | undefined, question_editor_state?: (string | null) | undefined, quiz_editor_state?: (string | null) | undefined, quiz_message_state?: (string | null) | undefined, content?: Array | undefined}; export type AssessmentQuestionWrite = {id?: (string | null) | undefined, position?: number | undefined, answers?: Array | undefined, editor_content?: EditorStateInQuestionSerializers | undefined, image_ids?: (Array) | undefined, slack_markup: string, single_select?: boolean | undefined, single_correct?: boolean | undefined} | null; export type AssessmentSerializerWrite = {id?: string | undefined, questions?: (Array | null) | undefined, created?: string | undefined, modified?: string | undefined, title: string, company?: (string | null) | undefined}; export type CreateApiApiAssessmentsArgs = {body: AssessmentSerializerWrite}; export type CreateApiApiAssessmentsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const assessmentAnswer = z.object({id: z.string().nullable().optional(), answer: z.string().min(1).max(150), correct: z.boolean().nullable().optional(), position: z.number().int().gte(-32768).lte(32767).optional(), explanation: z.string().nullable().optional()}); export const lessonImageInQuestionSerializers = z.object({id: z.string().optional(), company: z.string().nullable().optional(), image_name: z.string().max(200).nullable().optional(), image_url: z.string().nullable().optional(), image_url_public: z.string().nullable().optional(), editor_content: z.string().nullable().optional(), content_type: z.enum(["lesson", "quiz", "engagement_question", "engagement_message", "assessment_question_content"]).nullable().optional()}); export const editorStateInQuestionSerializers = z.object({id: z.string().optional(), note_editor_state: z.string().nullable().optional(), summary_editor_state: z.string().nullable().optional(), question_editor_state: z.string().nullable().optional(), quiz_editor_state: z.string().nullable().optional(), quiz_message_state: z.string().nullable().optional(), content: z.array(lessonImageInQuestionSerializers).optional()}); export const assessmentQuestionWrite = z.object({id: z.string().nullable().optional(), position: z.number().int().gte(-32768).lte(32767).optional(), answers: z.array(assessmentAnswer).optional(), editor_content: editorStateInQuestionSerializers.optional(), image_ids: z.array(z.string().nullable()).optional(), slack_markup: z.string().min(1), single_select: z.boolean().optional(), single_correct: z.boolean().optional()}).nullable(); export const assessmentSerializerWrite = z.object({id: z.string().optional(), questions: z.array(assessmentQuestionWrite).nullable().optional(), created: z.string().optional(), modified: z.string().optional(), title: z.string().min(1).max(200), company: z.string().nullable().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 }; /** * POST /api/assessments/ */ export const createApiApiAssessments = async (args: CreateApiApiAssessmentsArgs, options?: CreateApiApiAssessmentsOptions) => { const {baseUrl = "https://app.haekka.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/assessments/${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(assessmentSerializerWrite, await res.json()) };