import {z} from 'zod' export type GetApiKafkaV3ClustersClusterIdConsumerGroupsConsumerGroupIdOptions = {baseUrl?: string | undefined, resourceApiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const resourceMetadata = z.object({self: z.string(), resource_name: z.string().nullable().optional()}); export const consumerGroupState = z.string(); export const consumerGroupType = z.string(); export const relationship = z.object({related: z.string()}); export const consumerGroupData = z.object({kind: z.string(), metadata: resourceMetadata, cluster_id: z.string(), consumer_group_id: z.string(), is_simple: z.boolean(), partition_assignor: z.string(), state: consumerGroupState, type: consumerGroupType, is_mixed_consumer_group: z.boolean(), coordinator: relationship, consumers: relationship, lag_summary: relationship}); 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 * * GET /kafka/v3/clusters/{cluster_id}/consumer-groups/{consumer_group_id} * * Also accepts auth: external-access-token */ export const getApiKafkaV3ClustersClusterIdConsumerGroupsConsumerGroupId = async (options?: GetApiKafkaV3ClustersClusterIdConsumerGroupsConsumerGroupIdOptions) => { const {baseUrl = "https://api.confluent.cloud", fetch: fetchFn = fetch, resourceApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (resourceApiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${resourceApiKey.username}:${resourceApiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/kafka/v3/clusters/${encodeURIComponent(String(args.cluster_id))}/consumer-groups/${encodeURIComponent(String(args.consumer_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(consumerGroupData, await res.json()) };