import {z} from 'zod' export type CopyHistory = {attachmentId?: string | undefined, courseId?: string | undefined, itemId?: string | undefined, postId?: string | undefined}; export type Date = {day?: number | undefined, month?: number | undefined, year?: number | undefined}; export type TimeOfDay = {hours?: number | undefined, minutes?: number | undefined, nanos?: number | undefined, seconds?: number | undefined}; export type EmbedUri = {uri?: string | undefined}; export type AddOnAttachment = {copyHistory?: Array | undefined, courseId?: string | undefined, dueDate?: Date | undefined, dueTime?: TimeOfDay | undefined, gradeSyncEnabled?: boolean | undefined, id?: string | undefined, itemId?: string | undefined, maxPoints?: number | undefined, postId?: string | undefined, studentViewUri?: EmbedUri | undefined, studentWorkReviewUri?: EmbedUri | undefined, teacherViewUri?: EmbedUri | undefined, title?: string | undefined}; export type PatchApiV1CoursesCourseIdAnnouncementsItemIdAddOnAttachmentsAttachmentIdArgs = {courseId: string, itemId: string, attachmentId: string, postId?: string | undefined, updateMask?: unknown | undefined, body: AddOnAttachment}; export type PatchApiV1CoursesCourseIdAnnouncementsItemIdAddOnAttachmentsAttachmentIdOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const copyHistory = z.object({attachmentId: z.string().optional(), courseId: z.string().optional(), itemId: z.string().optional(), postId: z.string().optional()}); export const date = z.object({day: z.number().int().optional(), month: z.number().int().optional(), year: z.number().int().optional()}); export const timeOfDay = z.object({hours: z.number().int().optional(), minutes: z.number().int().optional(), nanos: z.number().int().optional(), seconds: z.number().int().optional()}); export const embedUri = z.object({uri: z.string().optional()}); export const addOnAttachment = z.object({copyHistory: z.array(copyHistory).optional(), courseId: z.string().optional(), dueDate: date.optional(), dueTime: timeOfDay.optional(), gradeSyncEnabled: z.boolean().optional(), id: z.string().optional(), itemId: z.string().optional(), maxPoints: z.number().optional(), postId: z.string().optional(), studentViewUri: embedUri.optional(), studentWorkReviewUri: embedUri.optional(), teacherViewUri: embedUri.optional(), title: z.string().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 }; /** * Updates an add-on attachment. Requires the add-on to have been the original creator of the attachment. This method returns the following error codes: * `PERMISSION_DENIED` for access errors. * `INVALID_ARGUMENT` if the request is malformed. * `NOT_FOUND` if one of the identified resources does not exist. * * PATCH /v1/courses/{courseId}/announcements/{itemId}/addOnAttachments/{attachmentId} */ export const patchApiV1CoursesCourseIdAnnouncementsItemIdAddOnAttachmentsAttachmentId = async (args: PatchApiV1CoursesCourseIdAnnouncementsItemIdAddOnAttachmentsAttachmentIdArgs, options?: PatchApiV1CoursesCourseIdAnnouncementsItemIdAddOnAttachmentsAttachmentIdOptions) => { const {baseUrl = "https://classroom.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.postId != null) query.append("postId", String(args.postId)) if (args.updateMask != null) query.append("updateMask", String(args.updateMask)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/courses/${encodeURIComponent(String(args.courseId))}/announcements/${encodeURIComponent(String(args.itemId))}/addOnAttachments/${encodeURIComponent(String(args.attachmentId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(addOnAttachment, await res.json()) };