import {z} from 'zod' export type GetApiPublicIamV2UserUserNameArgs = {'user-name': string}; export type GetApiPublicIamV2UserUserNameOptions = {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 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 }; /** * Get User by name * * GET /public/iam/v2/user/{user-name} */ export const getApiPublicIamV2UserUserName = async (args: GetApiPublicIamV2UserUserNameArgs, options: GetApiPublicIamV2UserUserNameOptions) => { 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/user/${encodeURIComponent(String(args['user-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(userResourceV2, await res.json()) };