import {z} from 'zod' export type GetApiPublicConsoleV2PartnerZonePartnerZoneNameArgs = {'partner-zone-name': string}; export type GetApiPublicConsoleV2PartnerZonePartnerZoneNameOptions = {baseUrl: string, httpAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const partnerZoneKind = z.literal("PartnerZone"); export const partnerZoneStatus = z.enum(["DELETED", "FAILED", "PENDING_CREATE", "PENDING_UPDATE", "READY", "TO_DELETE"]); export const mapLabelKeyString = z.record(z.string(), z.string()); export const partnerZoneMetadataOutput = z.object({name: z.string(), id: z.string(), updatedAt: z.string(), status: partnerZoneStatus, failedReason: z.string().optional(), 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 partnerZoneOutputResourceV2 = z.object({apiVersion: z.string(), kind: partnerZoneKind, metadata: partnerZoneMetadataOutput, spec: partnerZoneSpec}); 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 }; /** * Get PartnerZone by name * * GET /public/console/v2/partner-zone/{partner-zone-name} */ export const getApiPublicConsoleV2PartnerZonePartnerZoneName = async (args: GetApiPublicConsoleV2PartnerZonePartnerZoneNameArgs, options: GetApiPublicConsoleV2PartnerZonePartnerZoneNameOptions) => { const {baseUrl, fetch: fetchFn = fetch, httpAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (httpAuth !== undefined) headers.set('authorization', `Bearer ${httpAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/public/console/v2/partner-zone/${encodeURIComponent(String(args['partner-zone-name']))}${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(partnerZoneOutputResourceV2, await res.json()) };