import {z} from 'zod' export type GroupKind = 'Group'; export type GroupMetadata = {name: string}; export type CLUSTER = {name: string, permissions?: (Array<'clusterViewBroker' | 'clusterEditSRCompatibility' | 'clusterEditBroker' | 'clusterViewACL' | 'clusterManageACL'>) | undefined, resourceType: 'PLATFORM' | 'CLUSTER' | 'TOPIC' | 'CONSUMER_GROUP' | 'KAFKA_CONNECT' | 'SUBJECT' | 'KSQLDB'}; export type PatternType = 'LITERAL' | 'PREFIXED'; export type CONSUMERGROUP1 = {cluster: string, name: string, patternType: PatternType, permissions?: (Array<'consumerGroupCreate' | 'consumerGroupReset' | 'consumerGroupDelete' | 'consumerGroupMetadataManage' | 'consumerGroupView'>) | undefined, resourceType: 'PLATFORM' | 'CLUSTER' | 'TOPIC' | 'CONSUMER_GROUP' | 'KAFKA_CONNECT' | 'SUBJECT' | 'KSQLDB'}; export type KAFKACONNECT = {cluster: string, kafkaConnect: string, name: string, patternType: PatternType, permissions?: (Array<'kafkaConnectorStatus' | 'kafkaConnectorEditConfig' | 'kafkaConnectorMetadataManage' | 'kafkaConnectorDelete' | 'kafkaConnectorCreate' | 'kafkaConnectorOffsetsView' | 'kafkaConnectorViewConfig' | 'kafkaConnectorStop' | 'kafkaConnectPauseResume' | 'kafkaConnectRestart' | 'kafkaConnectorOffsetsManage'>) | undefined, resourceType: 'PLATFORM' | 'CLUSTER' | 'TOPIC' | 'CONSUMER_GROUP' | 'KAFKA_CONNECT' | 'SUBJECT' | 'KSQLDB'}; export type KSQLDB = {cluster: string, ksqlDB: string, permissions?: Array<'ksqldbAccess'> | undefined, resourceType: 'PLATFORM' | 'CLUSTER' | 'TOPIC' | 'CONSUMER_GROUP' | 'KAFKA_CONNECT' | 'SUBJECT' | 'KSQLDB'}; export type PLATFORM = {permissions?: (Array<'taasView' | 'certificateManage' | 'userManage' | 'clusterConnectionsManage' | 'notificationChannelManage' | 'sqlManage' | 'datamaskingManage' | 'auditLogView' | 'chargebackManage' | 'chargebackView' | 'notificationChannelView' | 'clusterConnectionsView' | 'datamaskingView' | 'userView' | 'flinkManage'>) | undefined, resourceType: 'PLATFORM' | 'CLUSTER' | 'TOPIC' | 'CONSUMER_GROUP' | 'KAFKA_CONNECT' | 'SUBJECT' | 'KSQLDB'}; export type SUBJECT1 = {cluster: string, name: string, patternType: PatternType, permissions?: (Array<'subjectCreateUpdate' | 'subjectDelete' | 'subjectEditCompatibility' | 'subjectView' | 'subjectMetadataManage'>) | undefined, resourceType: 'PLATFORM' | 'CLUSTER' | 'TOPIC' | 'CONSUMER_GROUP' | 'KAFKA_CONNECT' | 'SUBJECT' | 'KSQLDB'}; export type TOPIC1 = {cluster: string, name: string, patternType: PatternType, permissions?: (Array<'topicViewConfig' | 'topicEmpty' | 'topicConsume' | 'topicProduce' | 'topicEditConfig' | 'topicMetadataManage' | 'topicAddPartition' | 'topicDelete' | 'topicDataQualityManage' | 'topicCreate'>) | undefined, resourceType: 'PLATFORM' | 'CLUSTER' | 'TOPIC' | 'CONSUMER_GROUP' | 'KAFKA_CONNECT' | 'SUBJECT' | 'KSQLDB'}; export type ResourcePermissions1 = CLUSTER | CONSUMERGROUP1 | KAFKACONNECT | KSQLDB | PLATFORM | SUBJECT1 | TOPIC1; export type GroupSpec = {displayName: string, description?: string | undefined, externalGroups?: Array | undefined, externalGroupRegex?: Array | undefined, members?: Array | undefined, membersFromExternalGroups?: Array | undefined, permissions?: Array | undefined}; export type GroupResourceV2 = {apiVersion: string, kind: GroupKind, metadata: GroupMetadata, spec: GroupSpec}; export type UpdateApiPublicIamV2GroupArgs = {dryMode?: boolean | undefined, body: GroupResourceV2}; export type UpdateApiPublicIamV2GroupOptions = {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 upsertResult = z.enum(["Created", "Updated", "NotChanged"]); export const groupApplyResultV2 = z.object({resource: groupResourceV2, upsertResult: upsertResult}); 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 }; /** * Create or update a Group * * PUT /public/iam/v2/group */ export const updateApiPublicIamV2Group = async (args: UpdateApiPublicIamV2GroupArgs, options: UpdateApiPublicIamV2GroupOptions) => { const {baseUrl, fetch: fetchFn = fetch, httpAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.dryMode != null) query.append("dryMode", String(args.dryMode)) 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: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(groupApplyResultV2, await res.json()) };