import {z} from 'zod' export type Assessment = {markType?: string | undefined, markNumber?: string | undefined, openDate?: string | undefined, dueDate?: string | undefined, content?: string | undefined}; export type PatchApiOfferingsOfferingIdAssessmentsAssessmentIdArgs = {offeringId: string, assessmentId: string, body: Assessment}; export type PatchApiOfferingsOfferingIdAssessmentsAssessmentIdOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const document = z.object({id: z.string().optional(), url: z.string().optional(), createdAt: z.string().optional(), filename: z.string().optional(), mimetype: z.string().optional(), size: z.number().int().optional()}); export const themeResponse = z.object({filter: z.string().optional(), numberOfQuestions: z.string().optional()}); export const assessmentResponse = z.object({id: z.string().optional(), pid: z.string().optional(), title: z.string().optional(), type: z.string().optional(), content: z.string().optional(), points: z.string().optional(), hidden: z.boolean().optional(), filename: z.string().optional(), maxAttempts: z.number().int().optional(), durationMinutes: z.number().int().optional(), totalQuestions: z.number().int().optional(), totalThemes: z.number().int().optional(), documents: z.array(document).optional(), themes: z.array(themeResponse).optional(), markType: z.string().min(1).optional(), markNumber: z.string().min(1).optional(), openDate: z.string().optional(), dueDate: 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 }; /** * Update assessment details * * PATCH /offerings/{offeringId}/assessments/{assessmentId} */ export const patchApiOfferingsOfferingIdAssessmentsAssessmentId = async (args: PatchApiOfferingsOfferingIdAssessmentsAssessmentIdArgs, options?: PatchApiOfferingsOfferingIdAssessmentsAssessmentIdOptions) => { const {baseUrl = "https://api.iqualify.com/v1", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/offerings/${encodeURIComponent(String(args.offeringId))}/assessments/${encodeURIComponent(String(args.assessmentId))}${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(assessmentResponse, await res.json()) };