import {z} from 'zod' export type GetApiAccountServiceApiGroupsArgs = {page?: number | undefined, size?: number | undefined, sort?: Array | undefined, id?: (number | null) | undefined, status?: (number | null) | undefined, createTimeFrom?: (string | null) | undefined, createTimeTo?: (string | null) | undefined, updateTimeFrom?: (string | null) | undefined, updateTimeTo?: (string | null) | undefined, exactMatch?: (boolean | null) | undefined, excludeMatch?: (boolean | null) | undefined, excludeList?: (string | null) | undefined, name?: (string | null) | undefined}; export type GetApiAccountServiceApiGroupsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const pageable = z.object({content: z.array(z.unknown()), totalPages: z.number().int(), totalElements: z.number().int(), last: z.boolean(), size: z.number().int(), number: z.number().int(), sort: z.array(z.string()).optional(), numberOfElements: z.number().int(), first: z.boolean(), empty: z.boolean()}); 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 User Groups * * GET /account-service/api/groups */ export const getApiAccountServiceApiGroups = async (args: GetApiAccountServiceApiGroupsArgs, options: GetApiAccountServiceApiGroupsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) for (const item of args.sort ?? []) query.append("sort", String(item)) if (args.id != null) query.append("id", String(args.id)) if (args.status != null) query.append("status", String(args.status)) if (args.createTimeFrom != null) query.append("createTimeFrom", String(args.createTimeFrom)) if (args.createTimeTo != null) query.append("createTimeTo", String(args.createTimeTo)) if (args.updateTimeFrom != null) query.append("updateTimeFrom", String(args.updateTimeFrom)) if (args.updateTimeTo != null) query.append("updateTimeTo", String(args.updateTimeTo)) if (args.exactMatch != null) query.append("exactMatch", String(args.exactMatch)) if (args.excludeMatch != null) query.append("excludeMatch", String(args.excludeMatch)) if (args.excludeList != null) query.append("excludeList", String(args.excludeList)) if (args.name != null) query.append("name", String(args.name)) const url = `${baseUrl.replace(/\/+$/, '')}/account-service/api/groups${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(pageable, await res.json()) };