import {z} from 'zod' export type GetApiV1AiGatewaysGatewayIdIdentityArgs = {'page[size]'?: number | undefined, 'page[after]'?: string | undefined}; export type GetApiV1AiGatewaysGatewayIdIdentityOptions = {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 cursorMetaPage = z.object({first: z.string().optional(), last: z.string().optional(), next: z.string().nullable(), previous: z.string().nullable(), size: z.number()}); export const cursorMeta = z.object({page: cursorMetaPage}); export const getApiV1AiGatewaysGatewayIdIdentityResponse = z.object({data: z.array(aIGatewayIdentityProvider), meta: cursorMeta}); 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 }; /** * List AI Gateway Identity Providers * * GET /v1/ai-gateways/{gatewayId}/identity * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV1AiGatewaysGatewayIdIdentity = async (args: GetApiV1AiGatewaysGatewayIdIdentityArgs, options?: GetApiV1AiGatewaysGatewayIdIdentityOptions) => { 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 (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[after]'] != null) query.append("page[after]", String(args['page[after]'])) 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1AiGatewaysGatewayIdIdentityResponse, await res.json()) };