import {z} from 'zod' export type GetApiV1EventGatewaysGatewayIdVirtualClustersVirtualClusterIdClusterPoliciesPolicyIdRequestRuleValidatorOptions = {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 }; /** * Get a Cluster Policy for Virtual Cluster * * GET /v1/event-gateways/{gatewayId}/virtual-clusters/{virtualClusterId}/cluster-policies/{policyId}#RequestRuleValidator * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV1EventGatewaysGatewayIdVirtualClustersVirtualClusterIdClusterPoliciesPolicyIdRequestRuleValidator = async (options?: GetApiV1EventGatewaysGatewayIdVirtualClustersVirtualClusterIdClusterPoliciesPolicyIdRequestRuleValidatorOptions) => { const {baseUrl = "https://global.api.konghq.com", fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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))}#RequestRuleValidator${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(eventGatewayPolicy, await res.json()) };