import {z} from 'zod' export type GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshexternalservicesArgs = {offset?: number | undefined, size?: number | undefined, filter?: ({key?: string | undefined, value?: string | undefined}) | undefined, mesh: string}; export type GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshexternalservicesOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const meshExternalServiceItem = z.object({type: z.literal("MeshExternalService"), mesh: z.string().optional(), kri: z.string().optional(), snis: z.array(z.object({port: z.number().int(), sni: z.string()})).optional(), name: z.string(), labels: z.record(z.string(), z.string()).optional(), spec: z.object({endpoints: z.array(z.object({address: z.string().min(1), port: z.number().int().gte(1).lte(65535), priority: z.number().int().gte(0).lte(128).optional()})).optional(), extension: z.object({config: z.unknown(), type: z.string()}).optional(), match: z.object({port: z.number().int().gte(1).lte(65535), protocol: z.enum(["tcp", "grpc", "http", "http2"]).optional(), type: z.literal("HostnameGenerator").optional()}), tls: z.object({allowRenegotiation: z.boolean().optional(), enabled: z.boolean().optional(), verification: z.object({caCert: z.object({inline: z.string().optional(), inlineString: z.string().optional(), secret: z.string().optional()}).optional(), clientCert: z.object({inline: z.string().optional(), inlineString: z.string().optional(), secret: z.string().optional()}).optional(), clientKey: z.object({inline: z.string().optional(), inlineString: z.string().optional(), secret: z.string().optional()}).optional(), mode: z.enum(["SkipSAN", "SkipCA", "Secured", "SkipAll"]).optional(), serverName: z.string().optional(), subjectAltNames: z.array(z.object({type: z.enum(["Exact", "Prefix"]).optional(), value: z.string()})).optional()}).optional(), version: z.object({max: z.enum(["TLSAuto", "TLS10", "TLS11", "TLS12", "TLS13"]).optional(), min: z.enum(["TLSAuto", "TLS10", "TLS11", "TLS12", "TLS13"]).optional()}).optional()}).optional()}), creationTime: z.string().optional(), modificationTime: z.string().optional(), status: z.object({addresses: z.array(z.object({hostname: z.string().optional(), hostnameGeneratorRef: z.object({coreName: z.string()}).optional(), origin: z.string().optional()})).optional(), hostnameGenerators: z.array(z.object({conditions: z.array(z.object({message: z.string().max(32768), reason: z.string().min(1).max(1024), status: z.enum(["True", "False", "Unknown"]), type: z.string().max(316)})).optional(), hostnameGeneratorRef: z.object({coreName: z.string()})})).optional(), vip: z.object({ip: z.string().optional()}).optional()}).optional()}); export const getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshexternalservicesResponse = z.object({items: z.array(meshExternalServiceItem).optional(), total: z.number().optional(), next: z.string().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 }; /** * Returns a list of MeshExternalService in the mesh. * * GET /v1/mesh/control-planes/{cpId}/api/meshes/{mesh}/meshexternalservices * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshexternalservices = async (args: GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshexternalservicesArgs, options?: GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshexternalservicesOptions) => { 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.offset != null) query.append("offset", String(args.offset)) if (args.size != null) query.append("size", String(args.size)) if (args.filter != null) query.append("filter", JSON.stringify(args.filter)) if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/mesh/control-planes/${encodeURIComponent(String(args.cpId))}/api/meshes/${encodeURIComponent(String(args.mesh))}/meshexternalservices${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(getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshexternalservicesResponse, await res.json()) };