import {apiClient} from "@/api/api"; export interface MskCluster { ClusterArn?: string; ClusterName?: string; State?: string; KafkaVersion?: string; NumberOfBrokerNodes?: number; } export interface CreateMskClusterInput { clusterName: string; kafkaVersion: string; numberOfBrokerNodes: number; brokerNodeGroupInfo: {clientSubnets: string[]}; } export interface MskTopic { name: string; partitionCount: number; } export interface MskMessage { partition: number; offset: string; timestamp: string; key?: string; value?: string; headers: Record; } export interface MskConsumerGroupLag { topic: string; totalLag: number; partitions: Array<{partition: number; currentOffset: string; endOffset: string; lag: number}>; } function clusterPath(clusterArn: string): string { return `/msk/clusters/${encodeURIComponent(clusterArn)}`; } export async function listMskClusters(signal?: AbortSignal): Promise { return (await apiClient.get("/msk/clusters", {signal})).data; } export async function createMskCluster(input: CreateMskClusterInput): Promise { return (await apiClient.post("/msk/clusters", input)).data; } export async function deleteMskCluster(clusterArn: string): Promise { await apiClient.delete(clusterPath(clusterArn)); } export async function getMskBootstrapBrokers(clusterArn: string): Promise { return (await apiClient.get<{bootstrapBrokers: string}>(`${clusterPath(clusterArn)}/bootstrap-brokers`)).data.bootstrapBrokers; } export async function listMskTopics(clusterArn: string, signal?: AbortSignal): Promise { return (await apiClient.get(`${clusterPath(clusterArn)}/topics`, {signal})).data; } export async function createMskTopic(clusterArn: string, input: {topic: string; numPartitions?: number; replicationFactor?: number; configEntries?: Array<{name: string; value: string}>}): Promise { await apiClient.post(`${clusterPath(clusterArn)}/topics`, input); } export async function deleteMskTopic(clusterArn: string, topic: string): Promise { await apiClient.delete(`${clusterPath(clusterArn)}/topics/${encodeURIComponent(topic)}`); } export async function produceMskMessage(clusterArn: string, topic: string, input: {key?: string; value: string; headers?: Record}): Promise> { return (await apiClient.post, typeof input>(`${clusterPath(clusterArn)}/topics/${encodeURIComponent(topic)}/messages`, input)).data; } export async function peekMskMessages(clusterArn: string, topic: string, limit: number): Promise { return (await apiClient.get(`${clusterPath(clusterArn)}/topics/${encodeURIComponent(topic)}/messages`, {params: {limit}})).data; } export async function getMskConsumerGroupLag(clusterArn: string, groupId: string, topic?: string): Promise { return (await apiClient.get(`${clusterPath(clusterArn)}/consumer-groups/${encodeURIComponent(groupId)}/lag`, {params: {topic}})).data; }