import {z} from 'zod' export type GetApiV2GroupsIdRelationshipsPublishedCourseVisibilityArgs = {id: string, 'filter[published_course_id]'?: (string | null) | undefined, 'filter[is_visible]'?: (boolean | null) | undefined, 'page[size]'?: number | undefined, 'page[cursor]'?: (string | null) | undefined}; export type GetApiV2GroupsIdRelationshipsPublishedCourseVisibilityOptions = {baseUrl: string, JWTAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const visibilityOverrideAttributes = z.object({published_course_id: z.string(), is_visible: z.boolean(), created_at: z.string(), modified_at: z.string()}); export const visibilityOverrideResource = z.object({type: z.literal("visibility-overrides").optional(), id: z.string(), attributes: visibilityOverrideAttributes}); export const paginationLinks = z.object({self: z.string().nullable().optional(), next: z.string().nullable().optional(), prev: z.string().nullable().optional()}); export const paginatedListResponseVisibilityOverrideResource = z.object({data: z.array(visibilityOverrideResource), meta: z.record(z.string(), z.unknown()).nullable().optional(), links: paginationLinks.nullable().optional(), included: z.array(z.record(z.string(), z.unknown())).nullable().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 }; /** * List visibility overrides for a group * * GET /v2/groups/{id}/relationships/published-course-visibility/ */ export const getApiV2GroupsIdRelationshipsPublishedCourseVisibility = async (args: GetApiV2GroupsIdRelationshipsPublishedCourseVisibilityArgs, options: GetApiV2GroupsIdRelationshipsPublishedCourseVisibilityOptions) => { const {baseUrl, fetch: fetchFn = fetch, JWTAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.api+json") if (args['filter[published_course_id]'] != null) query.append("filter[published_course_id]", String(args['filter[published_course_id]'])) if (args['filter[is_visible]'] != null) query.append("filter[is_visible]", String(args['filter[is_visible]'])) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[cursor]'] != null) query.append("page[cursor]", String(args['page[cursor]'])) if (JWTAuth !== undefined) headers.set('authorization', `Bearer ${JWTAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/groups/${encodeURIComponent(String(args.id))}/relationships/published-course-visibility/${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(paginatedListResponseVisibilityOverrideResource, await res.json()) };