import {z} from 'zod' export type GetApiKafkaV3ClustersClusterIdLinksLinkNameArgs = {include_tasks?: boolean | undefined}; export type GetApiKafkaV3ClustersClusterIdLinksLinkNameOptions = {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 linkError = z.string(); export const linkState = z.string(); export const linkTaskState = z.string(); export const linkTaskError = z.object({error_code: z.string(), error_message: z.string()}); export const linkTask = z.object({task_name: z.string(), state: linkTaskState, errors: z.array(linkTaskError)}); export const stateCategory = z.string(); export const linkCategory = z.object({state_category: stateCategory, count: z.number().int()}); export const listLinksResponseData = z.object({kind: z.string(), metadata: resourceMetadata, source_cluster_id: z.string().nullable().optional(), destination_cluster_id: z.string().nullable().optional(), remote_cluster_id: z.string().nullable().optional(), link_name: z.string(), link_id: z.string().optional(), cluster_link_id: z.string(), topic_names: z.array(z.string()), link_error: linkError.optional(), link_error_message: z.string().nullable().optional(), link_state: linkState.optional(), tasks: z.array(linkTask).nullable().optional(), category_counts: z.array(linkCategory).nullable().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 }; /** * Describe the cluster link * * GET /kafka/v3/clusters/{cluster_id}/links/{link_name} * * Also accepts auth: external-access-token */ export const getApiKafkaV3ClustersClusterIdLinksLinkName = async (args: GetApiKafkaV3ClustersClusterIdLinksLinkNameArgs, options?: GetApiKafkaV3ClustersClusterIdLinksLinkNameOptions) => { 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 (args.include_tasks != null) query.append("include_tasks", String(args.include_tasks)) if (resourceApiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${resourceApiKey.username}:${resourceApiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/kafka/v3/clusters/${encodeURIComponent(String(args.cluster_id))}/links/${encodeURIComponent(String(args.link_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(listLinksResponseData, await res.json()) };