import {z} from 'zod' export type DeleteApiTicketsTicketIdReplyBlockArgs = {ticket_id: number}; export type DeleteApiTicketsTicketIdReplyBlockOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const appWebapiSchemasTicketsTicketMessageResponse = z.object({id: z.number().int(), user_id: z.number().int(), message_text: z.string(), is_from_admin: z.boolean(), has_media: z.boolean(), media_type: z.string().nullable().optional(), media_file_id: z.string().nullable().optional(), media_caption: z.string().nullable().optional(), created_at: z.string()}); export const appWebapiSchemasTicketsTicketResponse = z.object({id: z.number().int(), user_id: z.number().int(), title: z.string(), status: z.string(), priority: z.string(), created_at: z.string(), updated_at: z.string(), closed_at: z.string().nullable().optional(), user_reply_block_permanent: z.boolean(), user_reply_block_until: z.string().nullable().optional(), messages: z.array(appWebapiSchemasTicketsTicketMessageResponse).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 }; /** * Clear Reply Block * * DELETE /tickets/{ticket_id}/reply-block */ export const deleteApiTicketsTicketIdReplyBlock = async (args: DeleteApiTicketsTicketIdReplyBlockArgs, options: DeleteApiTicketsTicketIdReplyBlockOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/tickets/${encodeURIComponent(String(args.ticket_id))}/reply-block${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(appWebapiSchemasTicketsTicketResponse, await res.json()) };