import {z} from 'zod' export type GetApiV1InstallsInstallSidReportsChurnArgs = {installSid: string, courseTitle?: string | undefined, examTitle?: string | undefined, email?: string | undefined, firstName?: string | undefined, lastName?: string | undefined, examOpenDate?: string | undefined, examCloseDate?: string | undefined, courseOfferingSid?: string | undefined, hasCancelled?: boolean | undefined, hasClosed?: boolean | undefined, currentStatus?: (Array<'Needs Proctor' | 'Closed' | 'Scheduled'>) | undefined, offset?: number | undefined, limit?: number | undefined, sortKeys?: (Array<'courseTitle' | 'examTitle' | 'createdDate'>) | undefined, sortOrder?: ('ASC' | 'DESC') | undefined}; export type GetApiV1InstallsInstallSidReportsChurnOptions = {baseUrl?: string | undefined, client?: string | undefined, fetch?: typeof fetch | undefined}; export const churnReportItem = z.object({courseTitle: z.string().nullable().optional(), examSid: z.string().nullable().optional(), examTitle: z.string().nullable().optional(), examType: z.string().nullable().optional(), userSid: z.string().nullable().optional(), enrollmentSid: z.string().nullable().optional(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), email: z.string().nullable().optional(), preferredEmail: z.string().nullable().optional(), homePhone: z.string().nullable().optional(), mobilePhone: z.string().nullable().optional(), currentSessionSid: z.string().nullable().optional(), currentStatus: z.string().nullable().optional(), cancelled: z.boolean().nullable().optional(), closed: z.boolean().nullable().optional()}); export const model23 = z.array(churnReportItem); export const churnReportResponse = z.object({total: z.number().nullable().optional(), first: z.string().nullable().optional(), next: z.string().nullable().optional(), prev: z.string().nullable().optional(), last: z.string().nullable().optional(), count: z.number().nullable().optional(), offset: z.number().nullable().optional(), results: model23.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 }; /** * Churn Report * * GET /v1/installs/{installSid}/reports/churn */ export const getApiV1InstallsInstallSidReportsChurn = async (args: GetApiV1InstallsInstallSidReportsChurnArgs, options?: GetApiV1InstallsInstallSidReportsChurnOptions) => { const {baseUrl = "https://api.smarterproctoring.com", fetch: fetchFn = fetch, client} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.courseTitle != null) query.append("courseTitle", String(args.courseTitle)) if (args.examTitle != null) query.append("examTitle", String(args.examTitle)) if (args.email != null) query.append("email", String(args.email)) if (args.firstName != null) query.append("firstName", String(args.firstName)) if (args.lastName != null) query.append("lastName", String(args.lastName)) if (args.examOpenDate != null) query.append("examOpenDate", String(args.examOpenDate)) if (args.examCloseDate != null) query.append("examCloseDate", String(args.examCloseDate)) if (args.courseOfferingSid != null) query.append("courseOfferingSid", String(args.courseOfferingSid)) if (args.hasCancelled != null) query.append("hasCancelled", String(args.hasCancelled)) if (args.hasClosed != null) query.append("hasClosed", String(args.hasClosed)) for (const item of args.currentStatus ?? []) query.append("currentStatus", String(item)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) for (const item of args.sortKeys ?? []) query.append("sortKeys", String(item)) if (args.sortOrder != null) query.append("sortOrder", String(args.sortOrder)) if (client !== undefined) headers.set("token", client) const url = `${baseUrl.replace(/\/+$/, '')}/v1/installs/${encodeURIComponent(String(args.installSid))}/reports/churn${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(churnReportResponse, await res.json()) };