import {z} from 'zod' export type GetApiV1CoursesCourseIdAnnouncementsItemIdAddOnAttachmentsArgs = {courseId: string, itemId: string, pageSize?: number | undefined, pageToken?: string | undefined, postId?: string | undefined}; export type GetApiV1CoursesCourseIdAnnouncementsItemIdAddOnAttachmentsOptions = {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 listAddOnAttachmentsResponse = z.object({addOnAttachments: z.array(addOnAttachment).optional(), nextPageToken: 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 }; /** * Returns all attachments created by an add-on under the post. Requires the add-on to have active attachments on the post or have permission to create new attachments on the post. 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. * * GET /v1/courses/{courseId}/announcements/{itemId}/addOnAttachments * * Also accepts auth: Oauth2 + Oauth2c */ export const getApiV1CoursesCourseIdAnnouncementsItemIdAddOnAttachments = async (args: GetApiV1CoursesCourseIdAnnouncementsItemIdAddOnAttachmentsArgs, options?: GetApiV1CoursesCourseIdAnnouncementsItemIdAddOnAttachmentsOptions) => { const {baseUrl = "https://classroom.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (args.postId != null) query.append("postId", String(args.postId)) 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${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(listAddOnAttachmentsResponse, await res.json()) };