import {z} from 'zod' export type GetApiPublicIamV2GroupOptions = {baseUrl: string, httpAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const groupKind = z.literal("Group"); export const groupMetadata = z.object({name: z.string()}); export const cLUSTER = z.object({name: z.string(), permissions: z.array(z.enum(["clusterViewBroker", "clusterEditSRCompatibility", "clusterEditBroker", "clusterViewACL", "clusterManageACL"])).optional(), resourceType: z.enum(["PLATFORM", "CLUSTER", "TOPIC", "CONSUMER_GROUP", "KAFKA_CONNECT", "SUBJECT", "KSQLDB"])}); export const patternType = z.enum(["LITERAL", "PREFIXED"]); export const cONSUMERGROUP1 = z.object({cluster: z.string(), name: z.string(), patternType: patternType, permissions: z.array(z.enum(["consumerGroupCreate", "consumerGroupReset", "consumerGroupDelete", "consumerGroupMetadataManage", "consumerGroupView"])).optional(), resourceType: z.enum(["PLATFORM", "CLUSTER", "TOPIC", "CONSUMER_GROUP", "KAFKA_CONNECT", "SUBJECT", "KSQLDB"])}); export const kAFKACONNECT = z.object({cluster: z.string(), kafkaConnect: z.string(), name: z.string(), patternType: patternType, permissions: z.array(z.enum(["kafkaConnectorStatus", "kafkaConnectorEditConfig", "kafkaConnectorMetadataManage", "kafkaConnectorDelete", "kafkaConnectorCreate", "kafkaConnectorOffsetsView", "kafkaConnectorViewConfig", "kafkaConnectorStop", "kafkaConnectPauseResume", "kafkaConnectRestart", "kafkaConnectorOffsetsManage"])).optional(), resourceType: z.enum(["PLATFORM", "CLUSTER", "TOPIC", "CONSUMER_GROUP", "KAFKA_CONNECT", "SUBJECT", "KSQLDB"])}); export const kSQLDB = z.object({cluster: z.string(), ksqlDB: z.string(), permissions: z.array(z.literal("ksqldbAccess")).optional(), resourceType: z.enum(["PLATFORM", "CLUSTER", "TOPIC", "CONSUMER_GROUP", "KAFKA_CONNECT", "SUBJECT", "KSQLDB"])}); export const pLATFORM = z.object({permissions: z.array(z.enum(["taasView", "certificateManage", "userManage", "clusterConnectionsManage", "notificationChannelManage", "sqlManage", "datamaskingManage", "auditLogView", "chargebackManage", "chargebackView", "notificationChannelView", "clusterConnectionsView", "datamaskingView", "userView", "flinkManage"])).optional(), resourceType: z.enum(["PLATFORM", "CLUSTER", "TOPIC", "CONSUMER_GROUP", "KAFKA_CONNECT", "SUBJECT", "KSQLDB"])}); export const sUBJECT1 = z.object({cluster: z.string(), name: z.string(), patternType: patternType, permissions: z.array(z.enum(["subjectCreateUpdate", "subjectDelete", "subjectEditCompatibility", "subjectView", "subjectMetadataManage"])).optional(), resourceType: z.enum(["PLATFORM", "CLUSTER", "TOPIC", "CONSUMER_GROUP", "KAFKA_CONNECT", "SUBJECT", "KSQLDB"])}); export const tOPIC1 = z.object({cluster: z.string(), name: z.string(), patternType: patternType, permissions: z.array(z.enum(["topicViewConfig", "topicEmpty", "topicConsume", "topicProduce", "topicEditConfig", "topicMetadataManage", "topicAddPartition", "topicDelete", "topicDataQualityManage", "topicCreate"])).optional(), resourceType: z.enum(["PLATFORM", "CLUSTER", "TOPIC", "CONSUMER_GROUP", "KAFKA_CONNECT", "SUBJECT", "KSQLDB"])}); export const resourcePermissions1 = z.discriminatedUnion("resourceType", [cLUSTER, cONSUMERGROUP1, kAFKACONNECT, kSQLDB, pLATFORM, sUBJECT1, tOPIC1]); export const groupSpec = z.object({displayName: z.string(), description: z.string().optional(), externalGroups: z.array(z.string()).optional(), externalGroupRegex: z.array(z.string()).optional(), members: z.array(z.string()).optional(), membersFromExternalGroups: z.array(z.string()).optional(), permissions: z.array(resourcePermissions1).optional()}); export const groupResourceV2 = z.object({apiVersion: z.string(), kind: groupKind, metadata: groupMetadata, spec: groupSpec}); export const getApiPublicIamV2GroupResponse = z.array(groupResourceV2); 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 }; /** * List Group resources * * GET /public/iam/v2/group */ export const getApiPublicIamV2Group = async (options: GetApiPublicIamV2GroupOptions) => { const {baseUrl, fetch: fetchFn = fetch, httpAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (httpAuth !== undefined) headers.set('authorization', `Bearer ${httpAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/public/iam/v2/group${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(getApiPublicIamV2GroupResponse, await res.json()) };