import {z} from 'zod' export type V1ManagedFieldsEntry = {apiVersion?: string | undefined, fieldsType?: string | undefined, fieldsV1?: string | undefined, manager?: string | undefined, operation?: string | undefined, subresource?: string | undefined, time?: string | undefined}; export type V1OwnerReference = {apiVersion: string, blockOwnerDeletion?: boolean | undefined, controller?: boolean | undefined, kind: string, name: string, uid: string}; export type V1ObjectMeta = {annotations?: {[key: string]: string} | undefined, creationTimestamp?: string | undefined, deletionGracePeriodSeconds?: number | undefined, deletionTimestamp?: string | undefined, finalizers?: Array | undefined, generateName?: string | undefined, generation?: number | undefined, labels?: {[key: string]: string} | undefined, managedFields?: Array | undefined, name?: string | undefined, namespace?: string | undefined, ownerReferences?: Array | undefined, resourceVersion?: string | undefined, selfLink?: string | undefined, uid?: string | undefined}; export type V1NamespaceSpec = {finalizers?: Array | undefined}; export type V1NamespaceCondition = {lastTransitionTime?: string | undefined, message?: string | undefined, reason?: string | undefined, status: string, type: string}; export type V1NamespaceStatus = {conditions?: Array | undefined, phase?: string | undefined}; export type V1Namespace = {apiVersion?: string | undefined, kind?: string | undefined, metadata?: V1ObjectMeta | undefined, spec?: V1NamespaceSpec | undefined, status?: V1NamespaceStatus | undefined}; export type UpdateApiKapisTenantKubesphereIoV1beta1WorkspacesWorkspaceNamespacesNamespaceArgs = {workspace: string, namespace: string, body: V1Namespace}; export type UpdateApiKapisTenantKubesphereIoV1beta1WorkspacesWorkspaceNamespacesNamespaceOptions = {baseUrl: string, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const v1ManagedFieldsEntry = z.object({apiVersion: z.string().optional(), fieldsType: z.string().optional(), fieldsV1: z.string().optional(), manager: z.string().optional(), operation: z.string().optional(), subresource: z.string().optional(), time: z.string().optional()}); export const v1OwnerReference = z.object({apiVersion: z.string(), blockOwnerDeletion: z.boolean().optional(), controller: z.boolean().optional(), kind: z.string(), name: z.string(), uid: z.string()}); export const v1ObjectMeta = z.object({annotations: z.record(z.string(), z.string()).optional(), creationTimestamp: z.string().optional(), deletionGracePeriodSeconds: z.number().int().optional(), deletionTimestamp: z.string().optional(), finalizers: z.array(z.string()).optional(), generateName: z.string().optional(), generation: z.number().int().optional(), labels: z.record(z.string(), z.string()).optional(), managedFields: z.array(v1ManagedFieldsEntry).optional(), name: z.string().optional(), namespace: z.string().optional(), ownerReferences: z.array(v1OwnerReference).optional(), resourceVersion: z.string().optional(), selfLink: z.string().optional(), uid: z.string().optional()}); export const v1NamespaceSpec = z.object({finalizers: z.array(z.string()).optional()}); export const v1NamespaceCondition = z.object({lastTransitionTime: z.string().optional(), message: z.string().optional(), reason: z.string().optional(), status: z.string(), type: z.string()}); export const v1NamespaceStatus = z.object({conditions: z.array(v1NamespaceCondition).optional(), phase: z.string().optional()}); export const v1Namespace = z.object({apiVersion: z.string().optional(), kind: z.string().optional(), metadata: v1ObjectMeta.optional(), spec: v1NamespaceSpec.optional(), status: v1NamespaceStatus.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 }; /** * Update namespace * * PUT /kapis/tenant.kubesphere.io/v1beta1/workspaces/{workspace}/namespaces/{namespace} */ export const updateApiKapisTenantKubesphereIoV1beta1WorkspacesWorkspaceNamespacesNamespace = async (args: UpdateApiKapisTenantKubesphereIoV1beta1WorkspacesWorkspaceNamespacesNamespaceArgs, options: UpdateApiKapisTenantKubesphereIoV1beta1WorkspacesWorkspaceNamespacesNamespaceOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerToken !== undefined) headers.set("Authorization", BearerToken) const url = `${baseUrl.replace(/\/+$/, '')}/kapis/tenant.kubesphere.io/v1beta1/workspaces/${encodeURIComponent(String(args.workspace))}/namespaces/${encodeURIComponent(String(args.namespace))}${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(v1Namespace, await res.json()) };