import {z} from 'zod' export type GetApiConsumerGroupsGroupIdArgs = {group_id: string, page?: number | undefined, page_size?: number | undefined, include_assignments?: boolean | undefined, topic_search?: (string | null) | undefined}; export type GetApiConsumerGroupsGroupIdOptions = {baseUrl?: string | undefined, FronteggHTTPAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const consumerGroupMember = z.object({member_id: z.string(), client_id: z.string(), host: z.string()}).and(z.record(z.string(), z.unknown())); export const topicPartitionAssignment = z.object({topic: z.string(), partition: z.number().int(), member_id: z.string(), current_offset: z.number().int().nullable().optional(), log_end_offset: z.number().int().nullable().optional(), lag: z.number().int().nullable().optional()}).and(z.record(z.string(), z.unknown())); export const consumerGroupDetail = z.object({group_id: z.string(), state: z.string(), is_simple_consumer_group: z.boolean(), partition_assignor: z.string().nullable().optional(), members: z.array(consumerGroupMember).optional(), total_members: z.number().int(), topics: z.array(topicPartitionAssignment).optional(), total_topics: z.number().int(), page: z.number().int(), page_size: z.number().int(), total_lag: z.number().int().optional(), coordinator: z.string().nullable().optional()}).and(z.record(z.string(), z.unknown())); 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 Consumer Group Detail * * GET /consumer-groups/{group_id} */ export const getApiConsumerGroupsGroupId = async (args: GetApiConsumerGroupsGroupIdArgs, options?: GetApiConsumerGroupsGroupIdOptions) => { const {baseUrl = "https://api.streamkap.com", fetch: fetchFn = fetch, FronteggHTTPAuthentication} = 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.page_size != null) query.append("page_size", String(args.page_size)) if (args.include_assignments != null) query.append("include_assignments", String(args.include_assignments)) if (args.topic_search != null) query.append("topic_search", String(args.topic_search)) if (FronteggHTTPAuthentication !== undefined) headers.set('authorization', `Bearer ${FronteggHTTPAuthentication}`) const url = `${baseUrl.replace(/\/+$/, '')}/consumer-groups/${encodeURIComponent(String(args.group_id))}${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(consumerGroupDetail, await res.json()) };