import {z} from 'zod' export type MeshIdentityItem = {type: 'MeshIdentity', mesh?: string | undefined, kri?: string | undefined, name: string, labels?: {[key: string]: string} | undefined, spec: {provider?: ({bundled?: ({autogenerate?: ({enabled?: boolean | undefined}) | undefined, ca?: ({certificate?: ({envVar?: {name: string} | undefined, file?: {path: string} | undefined, insecureInline?: {value: string} | undefined, secretRef?: {kind: 'Secret', name: string} | undefined, type: 'File' | 'Secret' | 'EnvVar' | 'InsecureInline'}) | undefined, privateKey?: ({envVar?: {name: string} | undefined, file?: {path: string} | undefined, insecureInline?: {value: string} | undefined, secretRef?: {kind: 'Secret', name: string} | undefined, type: 'File' | 'Secret' | 'EnvVar' | 'InsecureInline'}) | undefined}) | undefined, certificateParameters?: ({expiry?: string | undefined}) | undefined, insecureAllowSelfSigned?: boolean | undefined, meshTrustCreation?: ('Enabled' | 'Disabled') | undefined}) | undefined, extension?: {config: unknown, name: string} | undefined, spire?: ({agent?: ({timeout?: string | undefined}) | undefined}) | undefined, type: 'Bundled' | 'Spire' | 'Extension'}) | undefined, selector?: ({dataplane?: ({matchLabels?: {[key: string]: string} | undefined}) | undefined}) | undefined, spiffeID?: ({path?: string | undefined, trustDomain?: 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 UpdateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshidentitiesNameArgs = {mesh: string, name: string, body: MeshIdentityItem}; export type UpdateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshidentitiesNameOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshidentitiesNameResponse = 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 MeshIdentity entity * * PUT /v1/mesh/control-planes/{cpId}/api/meshes/{mesh}/meshidentities/{name} * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const updateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshidentitiesName = async (args: UpdateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshidentitiesNameArgs, options?: UpdateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshidentitiesNameOptions) => { 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))}/meshidentities/${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(updateApiV1MeshControlPlanesCpIdApiMeshesMeshMeshidentitiesNameResponse, await res.json()) };