import {z} from 'zod' export type KubernetesLabelValue = string; export type Tag = {name: string, value: string}; export type TagList = Array; export type ResourceMetadata = {name: KubernetesLabelValue, description?: string | undefined, tags?: TagList | undefined}; export type UserState = 'active' | 'pending' | 'suspended'; export type GroupIDs = Array; export type UserSpec = {subject: string, state: UserState, groupIDs: GroupIDs}; export type UserWrite = {metadata?: ResourceMetadata | undefined, spec: UserSpec}; export type UpdateApiApiV1OrganizationsOrganizationIDUsersUserIDArgs = {body: UserWrite}; export type UpdateApiApiV1OrganizationsOrganizationIDUsersUserIDOptions = {baseUrl: string, oauth2Authentication?: string | undefined, fetch?: typeof fetch | undefined}; export const kubernetesLabelValue = z.string(); export const tag = z.object({name: z.string(), value: z.string()}); export const tagList = z.array(tag); export const resourceProvisioningStatus = z.enum(["unknown", "provisioning", "provisioned", "deprovisioning", "error"]); export const resourceHealthStatus = z.enum(["unknown", "healthy", "degraded", "error"]); export const organizationScopedResourceReadMetadata = z.object({name: kubernetesLabelValue, description: z.string().optional(), tags: tagList.optional(), id: z.string(), creationTime: z.string(), createdBy: z.string().optional(), modifiedTime: z.string().optional(), modifiedBy: z.string().optional(), deletionTime: z.string().optional(), provisioningStatus: resourceProvisioningStatus, healthStatus: resourceHealthStatus, organizationId: z.string()}); export const userState = z.enum(["active", "pending", "suspended"]); export const groupIDs = z.array(z.string()); export const userSpec = z.object({subject: z.string(), state: userState, groupIDs: groupIDs}); export const userStatus = z.object({lastActive: z.string().optional()}); export const userRead = z.object({metadata: organizationScopedResourceReadMetadata, spec: userSpec, status: userStatus}); 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 user * * PUT /api/v1/organizations/{organizationID}/users/{userID} */ export const updateApiApiV1OrganizationsOrganizationIDUsersUserID = async (args: UpdateApiApiV1OrganizationsOrganizationIDUsersUserIDArgs, options: UpdateApiApiV1OrganizationsOrganizationIDUsersUserIDOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2Authentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2Authentication !== undefined) headers.set('authorization', `Bearer ${oauth2Authentication}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/organizations/${encodeURIComponent(String(args.organizationID))}/users/${encodeURIComponent(String(args.userID))}${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(userRead, await res.json()) };