import {z} from 'zod' export type Labels = {[key: string]: string | null}; export type EventGatewayACLOperation = {name: 'all' | 'alter' | 'alter_configs' | 'create' | 'delete' | 'describe' | 'describe_configs' | 'idempotent_write' | 'read' | 'write'}; export type EventGatewayACLResourceName = {match: unknown}; export type EventGatewayACLRule = {resource_type: 'topic' | 'group' | 'transactional_id' | 'cluster', action: 'allow' | 'deny', operations: Array, resource_names: Array}; export type EventGatewayACLPolicyConfig = {rules: Array}; export type EventGatewayACLsPolicy = {type: 'acls', name?: string | undefined, description?: string | undefined, enabled?: boolean | undefined, labels?: Labels | undefined, config: EventGatewayACLPolicyConfig, condition?: string | undefined}; export type UpdateApiV1EventGatewaysGatewayIdVirtualClustersVirtualClusterIdClusterPoliciesPolicyIdAclsArgs = {body: EventGatewayACLsPolicy}; export type UpdateApiV1EventGatewaysGatewayIdVirtualClustersVirtualClusterIdClusterPoliciesPolicyIdAclsOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const labels = z.record(z.string(), z.string().min(1).max(63).nullable()); export const createdAt = z.string(); export const updatedAt = z.string(); export const eventGatewayPolicy = z.object({type: z.string().min(1).max(255), name: z.string().max(255).optional(), description: z.string().max(512).optional(), enabled: z.boolean().optional(), labels: labels.optional(), id: z.string(), config: z.object({}).nullable().optional(), created_at: createdAt, parent_policy_id: z.string().nullable().optional(), updated_at: updatedAt, condition: z.string().max(1000).optional()}); 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 Cluster Policy for Virtual Cluster * * PUT /v1/event-gateways/{gatewayId}/virtual-clusters/{virtualClusterId}/cluster-policies/{policyId}#Acls * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const updateApiV1EventGatewaysGatewayIdVirtualClustersVirtualClusterIdClusterPoliciesPolicyIdAcls = async (args: UpdateApiV1EventGatewaysGatewayIdVirtualClustersVirtualClusterIdClusterPoliciesPolicyIdAclsArgs, options?: UpdateApiV1EventGatewaysGatewayIdVirtualClustersVirtualClusterIdClusterPoliciesPolicyIdAclsOptions) => { const {baseUrl = "https://global.api.konghq.com", fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/event-gateways/${encodeURIComponent(String(args.gatewayId))}/virtual-clusters/${encodeURIComponent(String(args.virtualClusterId))}/cluster-policies/${encodeURIComponent(String(args.policyId))}#Acls${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(eventGatewayPolicy, await res.json()) };