import {z} from 'zod' export type ContentImage = {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}; export type RichTextEditorState = {id?: string | undefined, editor_state?: (string | null) | undefined, content?: Array | undefined}; export type CompanyWeeklyQuizWrite = {id?: string | undefined, quiz: string, company: string, created_by?: (string | null) | undefined, active?: boolean | undefined, start_date?: (string | null) | undefined, channels?: Array | undefined, okta_groups_sync?: Array | undefined, auto_enroll?: boolean | undefined, send_cycle?: ('once' | 'weekly' | 'monthly' | 'quarterly' | 'semi-annual' | 'annual') | undefined, respect_users_tz?: boolean | undefined, owners: Array, welcome_message: RichTextEditorState, welcome_message_markup?: string | undefined, welcome_message_enabled?: boolean | undefined, welcome_message_button_text?: string | undefined, closing_message: RichTextEditorState, closing_message_markup?: string | undefined, closing_message_enabled?: boolean | undefined, review_enabled?: boolean | undefined}; export type UpdateApiApiQuizzesCompanyIdArgs = {body: CompanyWeeklyQuizWrite}; export type UpdateApiApiQuizzesCompanyIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const contentImage = 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()}); export const richTextEditorState = z.object({id: z.string().optional(), editor_state: z.string().nullable().optional(), content: z.array(contentImage).optional()}); export const companyWeeklyQuizWrite = z.object({id: z.string().optional(), quiz: z.string(), company: z.string(), created_by: z.string().nullable().optional(), active: z.boolean().optional(), start_date: z.string().nullable().optional(), channels: z.array(z.string().min(1).max(100)).optional(), okta_groups_sync: z.array(z.string().min(1).max(200)).optional(), auto_enroll: z.boolean().optional(), send_cycle: z.enum(["once", "weekly", "monthly", "quarterly", "semi-annual", "annual"]).optional(), respect_users_tz: z.boolean().optional(), owners: z.array(z.string()), welcome_message: richTextEditorState, welcome_message_markup: z.string().min(1).optional(), welcome_message_enabled: z.boolean().optional(), welcome_message_button_text: z.string().min(1).optional(), closing_message: richTextEditorState, closing_message_markup: z.string().min(1).optional(), closing_message_enabled: z.boolean().optional(), review_enabled: z.boolean().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 }; /** * PUT /api/quizzes/company/{id} */ export const updateApiApiQuizzesCompanyId = async (args: UpdateApiApiQuizzesCompanyIdArgs, options?: UpdateApiApiQuizzesCompanyIdOptions) => { 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/quizzes/company/${encodeURIComponent(String(args.id))}${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(companyWeeklyQuizWrite, await res.json()) };