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 V1LabelSelectorRequirement = {key: string, operator: string, values?: Array | undefined}; export type V1LabelSelector = {matchExpressions?: Array | undefined, matchLabels?: {[key: string]: string} | undefined}; export type V1beta1GenericClusterReference = {name: string}; export type V1beta1GenericPlacement = {clusterSelector?: V1LabelSelector | undefined, clusters?: Array | undefined}; export type V1beta1ObjectMeta = {annotations?: {[key: string]: string} | undefined, labels?: {[key: string]: string} | undefined}; export type V1beta1WorkspaceSpec = {manager?: string | undefined}; export type V1beta1Template = {metadata?: V1beta1ObjectMeta | undefined, spec?: V1beta1WorkspaceSpec | undefined}; export type V1beta1WorkspaceTemplateSpec = {placement: V1beta1GenericPlacement, template: V1beta1Template}; export type V1beta1WorkspaceTemplate = {apiVersion?: string | undefined, kind?: string | undefined, metadata?: V1ObjectMeta | undefined, spec?: V1beta1WorkspaceTemplateSpec | undefined}; export type UpdateApiKapisTenantKubesphereIoV1beta1WorkspacesWorkspaceArgs = {workspace: string, body: V1beta1WorkspaceTemplate}; export type UpdateApiKapisTenantKubesphereIoV1beta1WorkspacesWorkspaceOptions = {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 v1LabelSelectorRequirement = z.object({key: z.string(), operator: z.string(), values: z.array(z.string()).optional()}); export const v1LabelSelector = z.object({matchExpressions: z.array(v1LabelSelectorRequirement).optional(), matchLabels: z.record(z.string(), z.string()).optional()}); export const v1beta1GenericClusterReference = z.object({name: z.string()}); export const v1beta1GenericPlacement = z.object({clusterSelector: v1LabelSelector.optional(), clusters: z.array(v1beta1GenericClusterReference).optional()}); export const v1beta1ObjectMeta = z.object({annotations: z.record(z.string(), z.string()).optional(), labels: z.record(z.string(), z.string()).optional()}); export const v1beta1WorkspaceSpec = z.object({manager: z.string().optional()}); export const v1beta1Template = z.object({metadata: v1beta1ObjectMeta.optional(), spec: v1beta1WorkspaceSpec.optional()}); export const v1beta1WorkspaceTemplateSpec = z.object({placement: v1beta1GenericPlacement, template: v1beta1Template}); export const v1beta1WorkspaceTemplate = z.object({apiVersion: z.string().optional(), kind: z.string().optional(), metadata: v1ObjectMeta.optional(), spec: v1beta1WorkspaceTemplateSpec.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 workspace * * PUT /kapis/tenant.kubesphere.io/v1beta1/workspaces/{workspace} */ export const updateApiKapisTenantKubesphereIoV1beta1WorkspacesWorkspace = async (args: UpdateApiKapisTenantKubesphereIoV1beta1WorkspacesWorkspaceArgs, options: UpdateApiKapisTenantKubesphereIoV1beta1WorkspacesWorkspaceOptions) => { 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))}${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(v1beta1WorkspaceTemplate, await res.json()) };