import {z} from 'zod' export type UserKind = 'User'; export type UserMetadata = {name: string, lastLoginDate?: string | undefined}; 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 UserSpec = {firstName?: string | undefined, lastName?: string | undefined, permissions?: Array | undefined}; export type UserResourceV2 = {apiVersion: string, kind: UserKind, metadata: UserMetadata, spec: UserSpec}; export type UpdateApiPublicIamV2UserArgs = {dryMode?: boolean | undefined, body: UserResourceV2}; export type UpdateApiPublicIamV2UserOptions = {baseUrl: string, httpAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const userKind = z.literal("User"); export const userMetadata = z.object({name: z.string(), lastLoginDate: z.string().optional()}); 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 userSpec = z.object({firstName: z.string().optional(), lastName: z.string().optional(), permissions: z.array(resourcePermissions1).optional()}); export const userResourceV2 = z.object({apiVersion: z.string(), kind: userKind, metadata: userMetadata, spec: userSpec}); export const upsertResult = z.enum(["Created", "Updated", "NotChanged"]); export const userApplyResultV2 = z.object({resource: userResourceV2, 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 User * * PUT /public/iam/v2/user */ export const updateApiPublicIamV2User = async (args: UpdateApiPublicIamV2UserArgs, options: UpdateApiPublicIamV2UserOptions) => { 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/user${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(userApplyResultV2, await res.json()) };