import {z} from 'zod' export type GetApiApiAssessmentsCompanyIdOptions = {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 assessmentQuestion = 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().optional(), single_select: z.boolean().optional(), single_correct: z.boolean().optional()}); export const assessment = z.object({id: z.string().optional(), questions: z.array(assessmentQuestion), created: z.string().optional(), modified: z.string().optional(), title: z.string().min(1).max(200), company: z.string().nullable().optional()}); export const trainingCompanyAssessment = z.object({id: z.string().optional(), assessment: assessment, created: z.string().optional(), modified: z.string().optional(), passing_grade: z.number().int().gte(-2147483648).lte(2147483647).optional(), retake_status: z.enum(["optional", "force_retake", "force_continue"]).optional(), is_active: z.boolean().optional(), position: z.number().int().gte(-32768).lte(32767).optional(), polymorphic_ctype: z.number().int().optional(), company: z.string(), created_by: z.string().nullable().optional(), curriculum: z.string(), lessons_to_skip: z.array(z.string()).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 }; /** * GET /api/assessments/company/{id} */ export const getApiApiAssessmentsCompanyId = async (options?: GetApiApiAssessmentsCompanyIdOptions) => { const {baseUrl = "https://app.haekka.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/assessments/company/${encodeURIComponent(String(args.id))}${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(trainingCompanyAssessment, await res.json()) };