import {z} from 'zod' export type AttachmentUpdateInput = {malware_access_override?: boolean | undefined}; export type AttachmentUpdateRequest = {attachment?: AttachmentUpdateInput | undefined}; export type UpdateApiApiV2AttachmentsAttachmentIdArgs = {attachment_id: number, body: AttachmentUpdateRequest}; export type UpdateApiApiV2AttachmentsAttachmentIdOptions = {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 attachmentResponse = z.object({attachment: attachmentObject.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 }; /** * Update Attachment for Malware * * PUT /api/v2/attachments/{attachment_id} */ export const updateApiApiV2AttachmentsAttachmentId = async (args: UpdateApiApiV2AttachmentsAttachmentIdArgs, options?: UpdateApiApiV2AttachmentsAttachmentIdOptions) => { const {baseUrl = "https://example.zendesk.com", fetch: fetchFn = fetch, apiTokenAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiTokenAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${apiTokenAuth.username}:${apiTokenAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/attachments/${encodeURIComponent(String(args.attachment_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(attachmentResponse, await res.json()) };