import {z} from 'zod' export type BackendClusterName = string; export type BackendClusterAuthenticationAnonymous = {type: 'anonymous'}; export type GatewaySecretReferenceOrLiteral = string; export type GatewaySecret = string; export type BackendClusterAuthenticationSaslPlainSensitiveDataAware = {type: 'sasl_plain', username: GatewaySecretReferenceOrLiteral, password?: GatewaySecret | undefined}; export type BackendClusterAuthenticationSaslScramSensitiveDataAware = {type: 'sasl_scram', algorithm: 'sha256' | 'sha512', username: GatewaySecretReferenceOrLiteral, password?: GatewaySecret | undefined}; export type BackendClusterAuthenticationSaslAwsIam = {type: 'sasl_aws_iam', sasl_aws_iam: {type: 'default_provider_chain'} | {type: 'assume_role', arn: string, session_name?: string | undefined}}; export type BackendClusterAuthenticationSensitiveDataAwareScheme = BackendClusterAuthenticationAnonymous | BackendClusterAuthenticationSaslPlainSensitiveDataAware | BackendClusterAuthenticationSaslScramSensitiveDataAware | BackendClusterAuthenticationSaslAwsIam; export type BootstrapServers = Array; export type BackendClusterTLS = {enabled: boolean, insecure_skip_verify?: boolean | undefined, ca_bundle?: GatewaySecretReferenceOrLiteral | undefined, tls_versions?: (Array<'tls12' | 'tls13'>) | undefined, client_identity?: {certificate: GatewaySecretReferenceOrLiteral, key: GatewaySecret} | undefined}; export type BackendMetadataUpdateIntervalSeconds = number; export type Labels = {[key: string]: string}; export type UpdateApiV1EventGatewaysGatewayIdBackendClustersBackendClusterIdArgs = {body: {name: BackendClusterName, description?: string | undefined, authentication: BackendClusterAuthenticationSensitiveDataAwareScheme, insecure_allow_anonymous_virtual_cluster_auth?: boolean | undefined, bootstrap_servers: BootstrapServers, tls: BackendClusterTLS, metadata_update_interval_seconds?: BackendMetadataUpdateIntervalSeconds | undefined, labels?: Labels | undefined}}; export type UpdateApiV1EventGatewaysGatewayIdBackendClustersBackendClusterIdOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const backendClusterName = z.string().min(1).max(255); export const backendClusterAuthenticationAnonymous = z.object({type: z.literal("anonymous")}); export const gatewaySecretReferenceOrLiteral = z.string().min(1); export const gatewaySecret = z.string().min(1); export const backendClusterAuthenticationSaslPlainSensitiveDataAware = z.object({type: z.literal("sasl_plain"), username: gatewaySecretReferenceOrLiteral, password: gatewaySecret.optional()}); export const backendClusterAuthenticationSaslScramSensitiveDataAware = z.object({type: z.literal("sasl_scram"), algorithm: z.enum(["sha256", "sha512"]), username: gatewaySecretReferenceOrLiteral, password: gatewaySecret.optional()}); export const backendClusterAuthenticationSaslAwsIam = z.object({type: z.literal("sasl_aws_iam"), sasl_aws_iam: z.discriminatedUnion("type", [z.object({type: z.literal("default_provider_chain")}), z.object({type: z.literal("assume_role"), arn: z.string().min(10).max(2048), session_name: z.string().optional()})])}); export const backendClusterAuthenticationSensitiveDataAwareScheme = z.discriminatedUnion("type", [backendClusterAuthenticationAnonymous, backendClusterAuthenticationSaslPlainSensitiveDataAware, backendClusterAuthenticationSaslScramSensitiveDataAware, backendClusterAuthenticationSaslAwsIam]); export const bootstrapServers = z.array(z.string().min(1)); export const backendClusterTLS = z.object({enabled: z.boolean(), insecure_skip_verify: z.boolean().optional(), ca_bundle: gatewaySecretReferenceOrLiteral.optional(), tls_versions: z.array(z.enum(["tls12", "tls13"])).optional(), client_identity: z.object({certificate: gatewaySecretReferenceOrLiteral, key: gatewaySecret}).optional()}); export const backendMetadataUpdateIntervalSeconds = z.number().int().gte(1).lte(43200); export const labels = z.record(z.string(), z.string().min(1).max(63)); export const createdAt = z.string(); export const updatedAt = z.string(); export const backendCluster = z.object({id: z.string(), name: backendClusterName, description: z.string().max(512).optional(), authentication: backendClusterAuthenticationSensitiveDataAwareScheme, insecure_allow_anonymous_virtual_cluster_auth: z.boolean().optional(), bootstrap_servers: bootstrapServers, tls: backendClusterTLS, metadata_update_interval_seconds: backendMetadataUpdateIntervalSeconds.optional(), labels: labels.optional(), created_at: createdAt, updated_at: updatedAt}); 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 Backend Cluster * * PUT /v1/event-gateways/{gatewayId}/backend-clusters/{backendClusterId} * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const updateApiV1EventGatewaysGatewayIdBackendClustersBackendClusterId = async (args: UpdateApiV1EventGatewaysGatewayIdBackendClustersBackendClusterIdArgs, options?: UpdateApiV1EventGatewaysGatewayIdBackendClustersBackendClusterIdOptions) => { 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))}/backend-clusters/${encodeURIComponent(String(args.backendClusterId))}${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(backendCluster, await res.json()) };