import {z} from 'zod' export type GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtracesArgs = {offset?: number | undefined, size?: number | undefined, filter?: ({key?: string | undefined, value?: string | undefined}) | undefined, mesh: string}; export type GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtracesOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const meshTraceItem = z.object({type: z.literal("MeshTrace"), mesh: z.string().optional(), kri: z.string().optional(), name: z.string(), labels: z.record(z.string(), z.string()).optional(), spec: z.object({default: z.object({backends: z.array(z.object({datadog: z.object({splitService: z.boolean().optional(), url: z.string()}).optional(), openTelemetry: z.object({backendRef: z.object({kind: z.literal("MeshOpenTelemetryBackend"), labels: z.record(z.string(), z.string()).optional()}).optional(), endpoint: z.string().optional()}).optional(), type: z.enum(["Zipkin", "Datadog", "OpenTelemetry"]), zipkin: z.object({apiVersion: z.enum(["httpJson", "httpProto"]).optional(), sharedSpanContext: z.boolean().optional(), traceId128bit: z.boolean().optional(), url: z.string()}).optional()})).optional(), sampling: z.object({client: z.union([z.number().int(), z.string()]).optional(), overall: z.union([z.number().int(), z.string()]).optional(), random: z.union([z.number().int(), z.string()]).optional()}).optional(), tags: z.array(z.object({header: z.object({default: z.string().optional(), name: z.string()}).optional(), literal: z.string().optional(), name: z.string()})).optional()}).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(), status: 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()}).optional()}); export const getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtracesResponse = z.object({items: z.array(meshTraceItem).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 MeshTrace in the mesh. * * GET /v1/mesh/control-planes/{cpId}/api/meshes/{mesh}/meshtraces * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtraces = async (args: GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtracesArgs, options?: GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtracesOptions) => { 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))}/meshtraces${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(getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtracesResponse, await res.json()) };