import {z} from 'zod' export type GetApiApiV2TicketsTicketIdCommentsArgs = {'page[before]'?: string | undefined, 'page[after]'?: string | undefined, 'page[size]'?: number | undefined, sort?: ('created_at' | '-created_at') | undefined, include_inline_images?: boolean | undefined, include?: string | undefined}; export type GetApiApiV2TicketsTicketIdCommentsOptions = {baseUrl?: string | undefined, apiTokenAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const attachmentBaseObject = z.object({content_type: z.string().optional(), content_url: z.string().optional(), deleted: z.boolean().optional(), file_name: z.string().optional(), height: z.number().int().optional(), id: z.number().int().optional(), inline: z.boolean().optional(), malware_access_override: z.boolean().optional(), malware_scan_result: z.string().optional(), mapped_content_url: z.string().optional(), size: z.number().int().optional(), url: z.string().optional(), width: z.number().int().optional()}); export const attachmentObject = z.object({content_type: z.string().optional(), content_url: z.string().optional(), deleted: z.boolean().optional(), file_name: z.string().optional(), height: z.number().int().optional(), id: z.number().int().optional(), inline: z.boolean().optional(), malware_access_override: z.boolean().optional(), malware_scan_result: z.string().optional(), mapped_content_url: z.string().optional(), size: z.number().int().optional(), url: z.string().optional(), width: z.number().int().optional(), thumbnails: z.array(attachmentBaseObject).optional()}); export const ticketAuditViaObject = z.object({channel: z.string().optional(), source: z.record(z.string(), z.unknown()).optional()}); export const ticketCommentObject = z.object({attachments: z.array(attachmentObject).optional(), audit_id: z.number().int().optional(), author_id: z.number().int().optional(), body: z.string().optional(), created_at: z.string().optional(), html_body: z.string().optional(), id: z.number().int().optional(), metadata: z.record(z.string(), z.unknown()).optional(), plain_body: z.string().optional(), public: z.boolean().optional(), type: z.string().optional(), uploads: z.array(z.string()).optional(), via: ticketAuditViaObject.optional()}); export const ticketCommentsResponse = z.object({comments: z.array(ticketCommentObject).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 }; /** * List Comments * * GET /api/v2/tickets/{ticket_id}/comments */ export const getApiApiV2TicketsTicketIdComments = async (args: GetApiApiV2TicketsTicketIdCommentsArgs, options?: GetApiApiV2TicketsTicketIdCommentsOptions) => { const {baseUrl = "https://example.zendesk.com", fetch: fetchFn = fetch, apiTokenAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['page[before]'] != null) query.append("page[before]", String(args['page[before]'])) if (args['page[after]'] != null) query.append("page[after]", String(args['page[after]'])) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args.sort != null) query.append("sort", String(args.sort)) if (args.include_inline_images != null) query.append("include_inline_images", String(args.include_inline_images)) if (args.include != null) query.append("include", String(args.include)) if (apiTokenAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${apiTokenAuth.username}:${apiTokenAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/tickets/${encodeURIComponent(String(args.ticket_id))}/comments${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(ticketCommentsResponse, await res.json()) };