import {z} from 'zod' export type AddOnAttachmentStudentSubmission = {courseWorkSubmissionId?: string | undefined, id?: string | undefined, pointsEarned?: number | undefined, postSubmissionState?: ('SUBMISSION_STATE_UNSPECIFIED' | 'NEW' | 'CREATED' | 'TURNED_IN' | 'RETURNED' | 'RECLAIMED_BY_STUDENT') | undefined, userId?: string | undefined}; export type PatchApiV1CoursesCourseIdPostsPostIdAddOnAttachmentsAttachmentIdStudentSubmissionsSubmissionIdArgs = {courseId: string, postId: string, attachmentId: string, submissionId: string, itemId?: string | undefined, updateMask?: unknown | undefined, body: AddOnAttachmentStudentSubmission}; export type PatchApiV1CoursesCourseIdPostsPostIdAddOnAttachmentsAttachmentIdStudentSubmissionsSubmissionIdOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const addOnAttachmentStudentSubmission = z.object({courseWorkSubmissionId: z.string().optional(), id: z.string().optional(), pointsEarned: z.number().optional(), postSubmissionState: z.enum(["SUBMISSION_STATE_UNSPECIFIED", "NEW", "CREATED", "TURNED_IN", "RETURNED", "RECLAIMED_BY_STUDENT"]).optional(), userId: 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 data associated with an add-on attachment submission. Requires the add-on to have been the original creator of the attachment and the attachment to have a positive `max_points` value set. 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}/posts/{postId}/addOnAttachments/{attachmentId}/studentSubmissions/{submissionId} */ export const patchApiV1CoursesCourseIdPostsPostIdAddOnAttachmentsAttachmentIdStudentSubmissionsSubmissionId = async (args: PatchApiV1CoursesCourseIdPostsPostIdAddOnAttachmentsAttachmentIdStudentSubmissionsSubmissionIdArgs, options?: PatchApiV1CoursesCourseIdPostsPostIdAddOnAttachmentsAttachmentIdStudentSubmissionsSubmissionIdOptions) => { 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.itemId != null) query.append("itemId", String(args.itemId)) 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))}/posts/${encodeURIComponent(String(args.postId))}/addOnAttachments/${encodeURIComponent(String(args.attachmentId))}/studentSubmissions/${encodeURIComponent(String(args.submissionId))}${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(addOnAttachmentStudentSubmission, await res.json()) };