import {z} from 'zod' export type GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshhttproutesArgs = {offset?: number | undefined, size?: number | undefined, filter?: ({key?: string | undefined, value?: string | undefined}) | undefined, mesh: string}; export type GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshhttproutesOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const meshHTTPRouteItem = z.object({type: z.literal("MeshHTTPRoute"), mesh: z.string().optional(), kri: z.string().optional(), name: z.string(), labels: z.record(z.string(), z.string()).optional(), spec: z.object({targetRef: z.object({kind: z.enum(["Mesh", "MeshSubset", "MeshGateway", "MeshService", "MeshExternalService", "MeshMultiZoneService", "MeshServiceSubset", "MeshHTTPRoute", "Dataplane"]), labels: z.record(z.string(), z.string()).optional(), mesh: z.string().optional(), name: z.string().optional(), namespace: z.string().optional(), proxyTypes: z.array(z.enum(["Sidecar", "Gateway"])).optional(), sectionName: z.string().optional(), tags: z.record(z.string(), z.string()).optional()}).optional(), to: z.array(z.object({hostnames: z.array(z.string()).optional(), rules: z.array(z.object({default: z.object({backendRefs: z.array(z.object({kind: z.enum(["Mesh", "MeshSubset", "MeshGateway", "MeshService", "MeshExternalService", "MeshMultiZoneService", "MeshServiceSubset", "MeshHTTPRoute", "Dataplane"]), labels: z.record(z.string(), z.string()).optional(), mesh: z.string().optional(), name: z.string().optional(), namespace: z.string().optional(), port: z.number().int().optional(), proxyTypes: z.array(z.enum(["Sidecar", "Gateway"])).optional(), sectionName: z.string().optional(), tags: z.record(z.string(), z.string()).optional(), weight: z.number().int().gte(0).optional()})).optional(), filters: z.array(z.object({requestHeaderModifier: z.object({add: z.array(z.object({name: z.string().min(1).max(256), value: z.string()})).optional(), remove: z.array(z.string()).optional(), set: z.array(z.object({name: z.string().min(1).max(256), value: z.string()})).optional()}).optional(), requestMirror: z.object({backendRef: z.object({kind: z.enum(["Mesh", "MeshSubset", "MeshGateway", "MeshService", "MeshExternalService", "MeshMultiZoneService", "MeshServiceSubset", "MeshHTTPRoute", "Dataplane"]), labels: z.record(z.string(), z.string()).optional(), mesh: z.string().optional(), name: z.string().optional(), namespace: z.string().optional(), port: z.number().int().optional(), proxyTypes: z.array(z.enum(["Sidecar", "Gateway"])).optional(), sectionName: z.string().optional(), tags: z.record(z.string(), z.string()).optional(), weight: z.number().int().gte(0).optional()}), percentage: z.union([z.number().int(), z.string()]).optional()}).optional(), requestRedirect: z.object({hostname: z.string().min(1).max(253).optional(), path: z.object({replaceFullPath: z.string().optional(), replacePrefixMatch: z.string().optional(), type: z.enum(["ReplaceFullPath", "ReplacePrefixMatch"])}).optional(), port: z.number().int().gte(1).lte(65535).optional(), scheme: z.enum(["http", "https"]).optional(), statusCode: z.union([z.literal(301), z.literal(302), z.literal(303), z.literal(307), z.literal(308)]).optional()}).optional(), responseHeaderModifier: z.object({add: z.array(z.object({name: z.string().min(1).max(256), value: z.string()})).optional(), remove: z.array(z.string()).optional(), set: z.array(z.object({name: z.string().min(1).max(256), value: z.string()})).optional()}).optional(), type: z.enum(["RequestHeaderModifier", "ResponseHeaderModifier", "RequestRedirect", "URLRewrite", "RequestMirror"]), urlRewrite: z.object({hostToBackendHostname: z.boolean().optional(), hostname: z.string().min(1).max(253).optional(), path: z.object({replaceFullPath: z.string().optional(), replacePrefixMatch: z.string().optional(), type: z.enum(["ReplaceFullPath", "ReplacePrefixMatch"])}).optional()}).optional()})).optional()}), matches: z.array(z.object({headers: z.array(z.object({name: z.string().min(1).max(256), type: z.enum(["Exact", "Present", "RegularExpression", "Absent", "Prefix"]).optional(), value: z.string().optional()})).optional(), method: z.enum(["CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "TRACE"]).optional(), path: z.object({type: z.enum(["Exact", "PathPrefix", "RegularExpression"]), value: z.string().min(1)}).optional(), queryParams: z.array(z.object({name: z.string().min(1), type: z.enum(["Exact", "RegularExpression"]), value: z.string()})).optional()}))})), targetRef: z.object({kind: z.enum(["Mesh", "MeshSubset", "MeshGateway", "MeshService", "MeshExternalService", "MeshMultiZoneService", "MeshServiceSubset", "MeshHTTPRoute", "Dataplane"]), labels: z.record(z.string(), z.string()).optional(), mesh: z.string().optional(), name: z.string().optional(), namespace: z.string().optional(), proxyTypes: z.array(z.enum(["Sidecar", "Gateway"])).optional(), sectionName: z.string().optional(), tags: z.record(z.string(), z.string()).optional()})})).optional()}), creationTime: z.string().optional(), modificationTime: z.string().optional()}); export const getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshhttproutesResponse = z.object({items: z.array(meshHTTPRouteItem).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 MeshHTTPRoute in the mesh. * * GET /v1/mesh/control-planes/{cpId}/api/meshes/{mesh}/meshhttproutes * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshhttproutes = async (args: GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshhttproutesArgs, options?: GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshhttproutesOptions) => { 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))}/meshhttproutes${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(getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshhttproutesResponse, await res.json()) };