import {z} from 'zod' export type GetApiClustersClusterIdBrokersBrokerIdConfigsNameOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const resourceMetadata = z.object({self: z.string(), resource_name: z.string().nullable().optional()}); export const configSource = z.string(); export const configSynonymData = z.object({name: z.string(), value: z.string().nullable().optional(), source: configSource}); export const brokerConfigData = z.object({kind: z.string(), metadata: resourceMetadata, cluster_id: z.string(), name: z.string(), value: z.string().nullable().optional(), is_default: z.boolean(), is_read_only: z.boolean(), is_sensitive: z.boolean(), source: configSource, synonyms: z.array(configSynonymData), broker_id: z.number().int()}); 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 Broker Config * * GET /clusters/{cluster_id}/brokers/{broker_id}/configs/{name} */ export const getApiClustersClusterIdBrokersBrokerIdConfigsName = async (options?: GetApiClustersClusterIdBrokersBrokerIdConfigsNameOptions) => { const {baseUrl = "http://localhost:8082/v3", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/clusters/${encodeURIComponent(String(args.cluster_id))}/brokers/${encodeURIComponent(String(args.broker_id))}/configs/${encodeURIComponent(String(args.name))}${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(brokerConfigData, await res.json()) };