import {z} from 'zod' export type GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshservicesArgs = {offset?: number | undefined, size?: number | undefined, filter?: ({key?: string | undefined, value?: string | undefined}) | undefined, mesh: string}; export type GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshservicesOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const meshServiceItem = z.object({type: z.literal("MeshService"), 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({identities: z.array(z.object({type: z.enum(["ServiceTag", "SpiffeID"]), value: z.string()})).optional(), ports: z.array(z.object({appProtocol: z.string().optional(), name: z.string().optional(), port: z.number().int(), targetPort: z.union([z.number().int(), z.string()]).optional()})).optional(), selector: z.object({dataplaneLabels: z.object({matchLabels: z.record(z.string(), z.string()).optional()}).optional(), dataplaneRef: z.object({name: z.string().optional()}).optional(), dataplaneTags: z.record(z.string(), z.string()).optional()}).optional(), state: z.enum(["Available", "Unavailable"]).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(), dataplaneProxies: z.object({connected: z.number().int().optional(), healthy: z.number().int().optional(), total: z.number().int().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(), tls: z.object({status: z.enum(["Ready", "NotReady"]).optional()}).optional(), vips: z.array(z.object({ip: z.string().optional()})).optional()}).optional()}); export const getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshservicesResponse = z.object({items: z.array(meshServiceItem).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 MeshService in the mesh. * * GET /v1/mesh/control-planes/{cpId}/api/meshes/{mesh}/meshservices * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshservices = async (args: GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshservicesArgs, options?: GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshservicesOptions) => { 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))}/meshservices${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(getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshservicesResponse, await res.json()) };