import {z} from 'zod' export type DeleteApiProjectsProjectIdCommentsCommentIdAttachmentsAttachmentIdArgs = {projectId: number, commentId: number, attachmentId: number}; export type DeleteApiProjectsProjectIdCommentsCommentIdAttachmentsAttachmentIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const stringComment = z.object({id: z.number().int().optional(), text: z.string().optional(), userId: z.number().int().optional(), user: z.object({id: z.number().int().optional(), username: z.string().optional(), fullName: z.string().optional(), avatarUrl: z.string().optional()}).optional(), projectId: z.number().int().optional(), languageId: z.string().optional(), type: z.string().optional(), issueType: z.string().optional(), issueStatus: z.string().optional(), resolverId: z.number().int().optional(), resolver: z.object({}).optional(), resolvedAt: z.string().optional(), createdAt: z.string().optional(), attachments: z.array(z.object({id: z.number().int().optional(), name: z.string().optional(), mime: z.string().optional(), size: z.number().int().optional(), category: z.string().optional(), thumbnailUrl: z.string().nullable().optional(), url: z.string().optional(), downloadUrl: z.string().optional()})).optional(), stringId: z.number().int().optional(), string: z.object({id: z.number().int().optional(), text: z.string().optional(), type: z.string().optional(), hasPlurals: z.boolean().optional(), isIcu: z.boolean().optional(), context: z.string().optional(), fileId: z.number().int().optional()}).optional()}); export const stringCommentResource = z.object({data: stringComment}); 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 }; /** * Delete Attachment from String Comment * * DELETE /projects/{projectId}/comments/{commentId}/attachments/{attachmentId} */ export const deleteApiProjectsProjectIdCommentsCommentIdAttachmentsAttachmentId = async (args: DeleteApiProjectsProjectIdCommentsCommentIdAttachmentsAttachmentIdArgs, options?: DeleteApiProjectsProjectIdCommentsCommentIdAttachmentsAttachmentIdOptions) => { const {baseUrl = "https://api.crowdin.com/api/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.projectId))}/comments/${encodeURIComponent(String(args.commentId))}/attachments/${encodeURIComponent(String(args.attachmentId))}${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(stringCommentResource, await res.json()) };