import {z} from 'zod' export type KafkaAclModel = {topic_name: string, operation: string, resource_pattern_type: string, resource?: string | undefined} | {[key: string]: unknown}; export type ProjectKeyKafkaConfig = {username: string, password: string, whitelist_ips?: (string | null) | undefined, kafka_acls?: Array | undefined, is_create_schema_registry?: boolean | undefined} | {[key: string]: unknown}; export type ToolProfile = 'full' | 'read-only' | 'agent-operator' | 'infra-admin'; export type ProjectKeyUpdateRequest = {name?: (string | null) | undefined, description?: (string | null) | undefined, role_ids?: (Array | null) | undefined, permission_ids?: (Array | null) | undefined, kafka_acls?: (Array | null) | undefined, whitelist_ips?: (string | null) | undefined, kafka_config?: (ProjectKeyKafkaConfig | null) | undefined, kafka_password?: (string | null) | undefined, tool_profile?: (ToolProfile | null) | undefined, allowed_tools?: (Array | null) | undefined, blocked_tools?: (Array | null) | undefined} | {[key: string]: unknown}; export type PatchApiProjectKeysProjectKeyIdArgs = {project_key_id: string, body: ProjectKeyUpdateRequest}; export type PatchApiProjectKeysProjectKeyIdOptions = {baseUrl?: string | undefined, FronteggHTTPAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const user = z.object({id: z.string(), email: z.string(), name: z.string(), profile_picture_url: z.string().nullable().optional(), phone_number: z.string().nullable().optional(), tenant_id: z.string(), created_at: z.union([z.string(), z.string()]).nullable().optional(), last_login: z.union([z.string(), z.string()]).nullable().optional()}); export const role = z.object({id: z.string(), key: z.string(), name: z.string(), description: z.string().nullable(), created_at: z.union([z.string(), z.string()]).nullable().optional(), updated_at: z.union([z.string(), z.string()]).nullable().optional(), permissions: z.array(z.string()).optional()}); export const toolProfile = z.enum(["full", "read-only", "agent-operator", "infra-admin"]); export const projectKeyApiCredentials = z.object({client_id: z.string(), client_secret: z.string(), token_endpoint: z.string(), api_url: z.string(), roles: z.array(z.string()).optional()}).and(z.record(z.string(), z.unknown())); export const projectKeyKafkaCredentials = z.object({username: z.string(), password: z.string(), bootstrap_servers: z.string(), security_protocol: z.string().optional(), sasl_mechanism: z.string().optional(), schema_registry_url: z.string().nullable().optional()}).and(z.record(z.string(), z.unknown())); export const projectKeyUpdateResponse = z.object({id: z.string(), name: z.string(), description: z.string().nullable().optional(), created_at: z.string().nullable().optional(), created_by_user: user.nullable().optional(), api_client_id: z.string().nullable().optional(), api_client_id_masked_secret: z.string().nullable().optional(), kafka_username: z.string().nullable().optional(), service_id: z.string(), roles: z.array(role).optional(), status: z.string(), last_used_at: z.string().nullable().optional(), tool_profile: toolProfile.nullable().optional(), allowed_tools: z.array(z.string()).nullable().optional(), blocked_tools: z.array(z.string()).nullable().optional(), agentic_enabled: z.boolean().optional(), agentic_secret_blob: z.string().nullable().optional(), new_api_credentials: projectKeyApiCredentials.nullable().optional(), new_kafka_credentials: projectKeyKafkaCredentials.nullable().optional(), token_ttl_seconds: z.number().int().optional(), warnings: z.array(z.string()).optional()}).and(z.record(z.string(), z.unknown())); 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 }; /** * Update Project Key * * PATCH /project-keys/{project_key_id} */ export const patchApiProjectKeysProjectKeyId = async (args: PatchApiProjectKeysProjectKeyIdArgs, options?: PatchApiProjectKeysProjectKeyIdOptions) => { const {baseUrl = "https://api.streamkap.com", fetch: fetchFn = fetch, FronteggHTTPAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (FronteggHTTPAuthentication !== undefined) headers.set('authorization', `Bearer ${FronteggHTTPAuthentication}`) const url = `${baseUrl.replace(/\/+$/, '')}/project-keys/${encodeURIComponent(String(args.project_key_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(projectKeyUpdateResponse, await res.json()) };