import {z} from 'zod' export type PartnerZoneKind = 'PartnerZone'; export type MapLabelKeyString = {[key: string]: string}; export type PartnerZoneMetadata = {name: string, labels?: MapLabelKeyString | undefined}; export type PartnerZoneAuthenticationType = 'MTLS' | 'OAUTHBEARER' | 'PLAIN'; export type AuthenticationMode = {serviceAccount: string, type: PartnerZoneAuthenticationType}; export type PartnerZoneTopicPermission = 'READ' | 'WRITE'; export type PartnerZoneTopic = {name: string, backingTopic: string, permission: PartnerZoneTopicPermission}; export type Partner = {name: string, role?: string | undefined, email?: string | undefined, phone?: string | undefined}; export type TrafficControlPolicies = {maxProduceRate?: number | undefined, maxConsumeRate?: number | undefined, limitCommitOffset?: number | undefined}; export type ToAdd = {key: string, value: string, overrideIfExists: boolean}; export type ToRemove = {keyRegex: string}; export type Headers = {addOnProduce?: Array | undefined, removeOnConsume?: Array | undefined}; export type PartnerZoneSpec = {cluster: string, underlyingCluster?: string | undefined, displayName?: string | undefined, description?: string | undefined, url?: string | undefined, authenticationMode: AuthenticationMode, topics: Array, partner?: Partner | undefined, trafficControlPolicies?: TrafficControlPolicies | undefined, headers?: Headers | undefined, vclusterName?: string | undefined, skipInterceptorReconciliation?: boolean | undefined}; export type PartnerZoneResourceV2 = {apiVersion: string, kind: PartnerZoneKind, metadata: PartnerZoneMetadata, spec: PartnerZoneSpec}; export type UpdateApiPublicConsoleV2PartnerZoneArgs = {dryMode?: boolean | undefined, body: PartnerZoneResourceV2}; export type UpdateApiPublicConsoleV2PartnerZoneOptions = {baseUrl: string, httpAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const partnerZoneKind = z.literal("PartnerZone"); export const mapLabelKeyString = z.record(z.string(), z.string()); export const partnerZoneMetadata = z.object({name: z.string(), labels: mapLabelKeyString.optional()}); export const partnerZoneAuthenticationType = z.enum(["MTLS", "OAUTHBEARER", "PLAIN"]); export const authenticationMode = z.object({serviceAccount: z.string(), type: partnerZoneAuthenticationType}); export const partnerZoneTopicPermission = z.enum(["READ", "WRITE"]); export const partnerZoneTopic = z.object({name: z.string(), backingTopic: z.string(), permission: partnerZoneTopicPermission}); export const partner = z.object({name: z.string(), role: z.string().optional(), email: z.string().optional(), phone: z.string().optional()}); export const trafficControlPolicies = z.object({maxProduceRate: z.number().int().optional(), maxConsumeRate: z.number().int().optional(), limitCommitOffset: z.number().int().optional()}); export const toAdd = z.object({key: z.string(), value: z.string(), overrideIfExists: z.boolean()}); export const toRemove = z.object({keyRegex: z.string()}); export const headers = z.object({addOnProduce: z.array(toAdd).optional(), removeOnConsume: z.array(toRemove).optional()}); export const partnerZoneSpec = z.object({cluster: z.string(), underlyingCluster: z.string().optional(), displayName: z.string().optional(), description: z.string().optional(), url: z.string().optional(), authenticationMode: authenticationMode, topics: z.array(partnerZoneTopic), partner: partner.optional(), trafficControlPolicies: trafficControlPolicies.optional(), headers: headers.optional(), vclusterName: z.string().optional(), skipInterceptorReconciliation: z.boolean().optional()}); export const partnerZoneResourceV2 = z.object({apiVersion: z.string(), kind: partnerZoneKind, metadata: partnerZoneMetadata, spec: partnerZoneSpec}); export const upsertResult = z.enum(["Created", "Updated", "NotChanged"]); export const partnerZoneApplyResultV2 = z.object({resource: partnerZoneResourceV2, upsertResult: upsertResult}); 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 }; /** * Create or update a PartnerZone * * PUT /public/console/v2/partner-zone */ export const updateApiPublicConsoleV2PartnerZone = async (args: UpdateApiPublicConsoleV2PartnerZoneArgs, options: UpdateApiPublicConsoleV2PartnerZoneOptions) => { const {baseUrl, fetch: fetchFn = fetch, httpAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.dryMode != null) query.append("dryMode", String(args.dryMode)) if (httpAuth !== undefined) headers.set('authorization', `Bearer ${httpAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/public/console/v2/partner-zone${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(partnerZoneApplyResultV2, await res.json()) };