import {z} from 'zod' export type GetApiServiceDeskMentionsDiagnoseTicketIdArgs = {ticketId: number}; export type GetApiServiceDeskMentionsDiagnoseTicketIdOptions = {baseUrl?: string | undefined, JWTBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getServiceDeskMentionDiagnosticNoteView = z.object({conversationId: z.number().int().nullable().optional(), createdUtc: z.string().nullable().optional(), private: z.boolean().optional(), incoming: z.boolean().optional(), authorUserId: z.number().int().nullable().optional(), notifiedAddresses: z.array(z.string()).optional(), notifiesYou: z.boolean().optional(), verdict: z.string().nullable().optional()}); export const meta = z.object({page: z.number().int().optional(), pageSize: z.number().int().optional(), total: z.number().int().optional()}); export const getServiceDeskMentionDiagnosticResponse = z.object({ticketId: z.number().int().optional(), yourAddresses: z.array(z.string()).optional(), watermarkUtc: z.string().nullable().optional(), lastRunUtc: z.string().nullable().optional(), alreadyRecorded: z.boolean().optional(), notes: z.array(getServiceDeskMentionDiagnosticNoteView).optional(), meta: meta.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 }; /** * Service Desk - why is this ticket not in my mentions * * GET /ServiceDesk/Mentions/Diagnose/{ticketId} */ export const getApiServiceDeskMentionsDiagnoseTicketId = async (args: GetApiServiceDeskMentionsDiagnoseTicketIdArgs, options?: GetApiServiceDeskMentionsDiagnoseTicketIdOptions) => { const {baseUrl = "https://api.tonbridge.school", fetch: fetchFn = fetch, JWTBearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (JWTBearerAuth !== undefined) headers.set('authorization', `Bearer ${JWTBearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/ServiceDesk/Mentions/Diagnose/${encodeURIComponent(String(args.ticketId))}${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(getServiceDeskMentionDiagnosticResponse, await res.json()) };