import {z} from 'zod' export type CourseOfferingUpdate = {title: string, matchStrings: string, startDate?: (string | null) | undefined, endDate?: (string | null) | undefined}; export type UpdateApiV1InstallsInstallSidCourseOfferingsOfferingSidArgs = {installSid: string, offeringSid: string, body: CourseOfferingUpdate}; export type UpdateApiV1InstallsInstallSidCourseOfferingsOfferingSidOptions = {baseUrl?: string | undefined, client?: string | undefined, fetch?: typeof fetch | undefined}; export const matchStrings = z.array(z.string()).nullable(); export const courseOfferingResponse = z.object({sid: z.string().nullable().optional(), lastActivityDate: z.string().nullable().optional(), title: z.string().nullable().optional(), matchStrings: matchStrings.optional(), startDate: z.string().nullable().optional(), endDate: z.string().nullable().optional(), createdDate: z.string().nullable().optional(), editDate: 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 }; /** * Update Course Offering * * PUT /v1/installs/{installSid}/courseOfferings/{offeringSid} */ export const updateApiV1InstallsInstallSidCourseOfferingsOfferingSid = async (args: UpdateApiV1InstallsInstallSidCourseOfferingsOfferingSidArgs, options?: UpdateApiV1InstallsInstallSidCourseOfferingsOfferingSidOptions) => { const {baseUrl = "https://api.smarterproctoring.com", fetch: fetchFn = fetch, client} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (client !== undefined) headers.set("token", client) const url = `${baseUrl.replace(/\/+$/, '')}/v1/installs/${encodeURIComponent(String(args.installSid))}/courseOfferings/${encodeURIComponent(String(args.offeringSid))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(courseOfferingResponse, await res.json()) };