import {z} from 'zod' export type AIGatewayEntityIdentifier = string; export type PublicLabels = {[key: string]: string}; export type ManagedBy = {[key: string]: string}; export type AIGatewayIdentityProviderKeyAuth = {display_name: string, name: AIGatewayEntityIdentifier, labels?: PublicLabels | undefined, managed_by?: ManagedBy | undefined, type: 'key-auth', config?: ({hide_credentials?: boolean | undefined, key_in_body?: boolean | undefined, key_in_header?: boolean | undefined, key_in_query?: boolean | undefined, key_names?: Array | undefined, principals?: ({enabled?: boolean | undefined, directory?: string | undefined, error_on_miss?: boolean | undefined}) | undefined} | {[key: string]: unknown}) | undefined}; export type AIGatewayIdentityProviderOpenIDConnect = {display_name: string, name: AIGatewayEntityIdentifier, labels?: PublicLabels | undefined, managed_by?: ManagedBy | undefined, type: 'openid-connect', config?: ({auth_methods?: (Array<'authorization_code' | 'bearer' | 'client_credentials' | 'introspection' | 'kong_oauth2' | 'password' | 'refresh_token' | 'session' | 'userinfo'>) | undefined, client_id?: Array | undefined, client_secret?: Array | undefined, client_alg?: (Array<'HS256' | 'HS384' | 'HS512' | 'RS256' | 'RS384' | 'RS512' | 'ES256' | 'ES384' | 'ES512' | 'PS256' | 'PS384' | 'PS512' | 'EdDSA'>) | undefined, client_auth?: (Array<'client_secret_basic' | 'client_secret_post' | 'client_secret_jwt' | 'private_key_jwt' | 'tls_client_auth' | 'self_signed_tls_client_auth' | 'none'>) | undefined, consumer_claims?: Array> | undefined, consumer_groups_claim?: Array | undefined, consumer_groups_optional?: boolean | undefined, consumer_by?: (Array<'id' | 'username' | 'custom_id'>) | undefined, consumer_optional?: boolean | undefined, credential_claim?: Array | undefined, credential_claims?: Array> | undefined, issuer?: string | undefined, introspection_endpoint?: string | undefined, mtls_introspection_endpoint?: string | undefined, cache_introspection?: boolean | undefined, jwks_endpoint?: string | undefined, leeway?: number | undefined, scopes?: Array | undefined, audience_required?: Array | undefined, ssl_verify?: boolean | undefined, hide_credentials?: boolean | undefined, keepalive?: boolean | undefined, timeout?: number | undefined, http_version?: number | undefined, http_proxy?: string | undefined, http_proxy_authorization?: string | undefined, https_proxy?: string | undefined, https_proxy_authorization?: string | undefined, no_proxy?: string | undefined, upstream_headers?: Array<{header: string, path: Array}> | undefined, cache_tokens_salt: string, principals?: ({enabled?: boolean | undefined, directory?: string | undefined, principal_by?: string | undefined, principal_claim?: Array | undefined, match_consumer?: boolean | undefined, match_consumer_groups?: boolean | undefined, error_on_miss?: boolean | undefined}) | undefined} | {[key: string]: unknown}) | undefined}; export type CreateAIGatewayIdentityProviderRequest = AIGatewayIdentityProviderKeyAuth | AIGatewayIdentityProviderOpenIDConnect; export type CreateApiV1AiGatewaysGatewayIdIdentityArgs = {body: CreateAIGatewayIdentityProviderRequest}; export type CreateApiV1AiGatewaysGatewayIdIdentityOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const aIGatewayEntityIdentifier = z.string().min(1).max(256); export const publicLabels = z.record(z.string(), z.string().min(1).max(63)); export const managedBy = z.record(z.string(), z.string().min(1).max(63)); export const uUID = z.string(); export const createdAt = z.string(); export const updatedAt = z.string(); export const aIGatewayIdentityProviderKeyAuthResponse = z.object({display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), type: z.literal("key-auth"), config: z.object({hide_credentials: z.boolean().optional(), key_in_body: z.boolean().optional(), key_in_header: z.boolean().optional(), key_in_query: z.boolean().optional(), key_names: z.array(z.string()).optional(), principals: z.object({enabled: z.boolean().optional(), directory: z.string().optional(), error_on_miss: z.boolean().optional()}).optional()}).and(z.record(z.string(), z.unknown())).optional(), id: uUID, created_at: createdAt, updated_at: updatedAt}); export const aIGatewayIdentityProviderOpenIDConnectResponse = z.object({display_name: z.string().min(1).max(256), name: aIGatewayEntityIdentifier, labels: publicLabels.optional(), managed_by: managedBy.optional(), type: z.literal("openid-connect"), config: z.object({auth_methods: z.array(z.enum(["authorization_code", "bearer", "client_credentials", "introspection", "kong_oauth2", "password", "refresh_token", "session", "userinfo"])).optional(), client_id: z.array(z.string()).optional(), client_secret: z.array(z.string()).optional(), client_alg: z.array(z.enum(["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "EdDSA"])).optional(), client_auth: z.array(z.enum(["client_secret_basic", "client_secret_post", "client_secret_jwt", "private_key_jwt", "tls_client_auth", "self_signed_tls_client_auth", "none"])).optional(), consumer_claims: z.array(z.array(z.string())).optional(), consumer_groups_claim: z.array(z.string()).optional(), consumer_groups_optional: z.boolean().optional(), consumer_by: z.array(z.enum(["id", "username", "custom_id"])).optional(), consumer_optional: z.boolean().optional(), credential_claim: z.array(z.string()).optional(), credential_claims: z.array(z.array(z.string())).optional(), issuer: z.string().optional(), introspection_endpoint: z.string().optional(), mtls_introspection_endpoint: z.string().optional(), cache_introspection: z.boolean().optional(), jwks_endpoint: z.string().optional(), leeway: z.number().int().gte(0).optional(), scopes: z.array(z.string()).optional(), audience_required: z.array(z.string()).optional(), ssl_verify: z.boolean().optional(), hide_credentials: z.boolean().optional(), keepalive: z.boolean().optional(), timeout: z.number().int().gte(0).optional(), http_version: z.union([z.literal(1), z.literal(1.1)]).optional(), http_proxy: z.string().optional(), http_proxy_authorization: z.string().optional(), https_proxy: z.string().optional(), https_proxy_authorization: z.string().optional(), no_proxy: z.string().optional(), upstream_headers: z.array(z.object({header: z.string(), path: z.array(z.string())})).optional(), cache_tokens_salt: z.string(), principals: z.object({enabled: z.boolean().optional(), directory: z.string().optional(), principal_by: z.string().min(1).optional(), principal_claim: z.array(z.string().min(1)).optional(), match_consumer: z.boolean().optional(), match_consumer_groups: z.boolean().optional(), error_on_miss: z.boolean().optional()}).optional()}).and(z.record(z.string(), z.unknown())).optional(), id: uUID, created_at: createdAt, updated_at: updatedAt}); export const aIGatewayIdentityProvider = z.discriminatedUnion("type", [aIGatewayIdentityProviderKeyAuthResponse, aIGatewayIdentityProviderOpenIDConnectResponse]); 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 }; /** * Create an AI Gateway Identity Provider * * POST /v1/ai-gateways/{gatewayId}/identity * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const createApiV1AiGatewaysGatewayIdIdentity = async (args: CreateApiV1AiGatewaysGatewayIdIdentityArgs, options?: CreateApiV1AiGatewaysGatewayIdIdentityOptions) => { 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/ai-gateways/${encodeURIComponent(String(args.gatewayId))}/identity${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(aIGatewayIdentityProvider, await res.json()) };