import {z} from 'zod' export type MeshTraceItem = {type: 'MeshTrace', mesh?: string | undefined, kri?: string | undefined, name: string, labels?: {[key: string]: string} | undefined, spec: {default?: ({backends?: (Array<{datadog?: ({splitService?: boolean | undefined, url: string}) | undefined, openTelemetry?: ({backendRef?: ({kind: 'MeshOpenTelemetryBackend', labels?: {[key: string]: string} | undefined}) | undefined, endpoint?: string | undefined}) | undefined, type: 'Zipkin' | 'Datadog' | 'OpenTelemetry', zipkin?: ({apiVersion?: ('httpJson' | 'httpProto') | undefined, sharedSpanContext?: boolean | undefined, traceId128bit?: boolean | undefined, url: string}) | undefined}>) | undefined, sampling?: ({client?: (number | string) | undefined, overall?: (number | string) | undefined, random?: (number | string) | undefined}) | undefined, tags?: (Array<{header?: ({default?: string | undefined, name: string}) | undefined, literal?: string | undefined, name: string}>) | undefined}) | undefined, targetRef?: ({kind: 'Mesh' | 'MeshSubset' | 'MeshGateway' | 'MeshService' | 'MeshExternalService' | 'MeshMultiZoneService' | 'MeshServiceSubset' | 'MeshHTTPRoute' | 'Dataplane', labels?: {[key: string]: string} | undefined, mesh?: string | undefined, name?: string | undefined, namespace?: string | undefined, proxyTypes?: (Array<'Sidecar' | 'Gateway'>) | undefined, sectionName?: string | undefined, tags?: {[key: string]: string} | undefined}) | undefined}, creationTime?: string | undefined, modificationTime?: string | undefined, status?: ({conditions?: (Array<{message: string, reason: string, status: 'True' | 'False' | 'Unknown', type: string}>) | undefined}) | undefined}; export type UpdateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtracesNameArgs = {mesh: string, name: string, body: MeshTraceItem}; export type UpdateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtracesNameOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtracesNameResponse = z.object({warnings: z.array(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 }; /** * Creates or Updates MeshTrace entity * * PUT /v1/mesh/control-planes/{cpId}/api/meshes/{mesh}/meshtraces/{name} * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const updateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtracesName = async (args: UpdateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtracesNameArgs, options?: UpdateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtracesNameOptions) => { const {baseUrl = "https://global.api.konghq.com", fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") 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/${encodeURIComponent(String(args.name))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(updateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshtracesNameResponse, await res.json()) };