import {z} from 'zod' export type GetApiApiV2UiGlobalpermissiongroupsIdUserMembersArgs = {id: number}; export type GetApiApiV2UiGlobalpermissiongroupsIdUserMembersOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const userListResponse = z.object({jsonapi: z.object({version: z.string(), ext: z.array(z.string()).optional()}), links: z.object({self: z.string(), first: z.string(), last: z.string().nullable(), next: z.string().nullable(), prev: z.string().nullable()}), meta: z.object({page: z.object({total_elements: z.number().int()})}), data: z.array(z.object({id: z.number().int(), type: z.literal("user"), attributes: z.object({name: z.string(), email: z.string().optional(), isValid: z.boolean().optional(), isComputedPassword: z.boolean().optional(), lastLoginDate: z.number().int().optional(), registeredSince: z.number().int().optional(), sessionLifetime: z.number().int().optional(), globalPermissionGroupId: z.number().int().optional()}), links: z.object({self: z.string()}), relationships: z.object({accessGroups: z.object({links: z.object({self: z.string(), related: z.string()}), data: z.array(z.object({type: z.literal("accessGroup"), id: z.number().int()})).optional()}), globalPermissionGroup: z.object({links: z.object({self: z.string(), related: z.string()}), data: z.object({type: z.literal("globalPermissionGroup"), id: z.number().int()}).nullable().optional()})})})), included: z.array(z.discriminatedUnion("type", [z.object({id: z.number().int(), type: z.literal("globalPermissionGroup"), attributes: z.object({name: z.string(), permissions: z.record(z.string(), z.boolean())})}), z.object({id: z.number().int(), type: z.literal("accessGroup"), attributes: z.object({groupName: 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 }; /** * Get GlobalPermissionGroups * * GET /api/v2/ui/globalpermissiongroups/{id}/userMembers */ export const getApiApiV2UiGlobalpermissiongroupsIdUserMembers = async (args: GetApiApiV2UiGlobalpermissiongroupsIdUserMembersArgs, options: GetApiApiV2UiGlobalpermissiongroupsIdUserMembersOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.api+json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/ui/globalpermissiongroups/${encodeURIComponent(String(args.id))}/userMembers${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(userListResponse, await res.json()) };