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 Subject = {id: string, email?: string | undefined, issuer: string}; export type StringList = Array; export type GroupSpec = {subjects?: Array | undefined, userIDs?: StringList | undefined, serviceAccountIDs: StringList, roleIDs: StringList}; export type GroupWrite = {metadata: ResourceMetadata, spec: GroupSpec}; export type CreateApiApiV1OrganizationsOrganizationIDGroupsArgs = {body: GroupWrite}; export type CreateApiApiV1OrganizationsOrganizationIDGroupsOptions = {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 subject = z.object({id: z.string(), email: z.string().optional(), issuer: z.string()}); export const stringList = z.array(z.string()); export const groupSpec = z.object({subjects: z.array(subject).optional(), userIDs: stringList.optional(), serviceAccountIDs: stringList, roleIDs: stringList}); export const groupRead = z.object({metadata: organizationScopedResourceReadMetadata, spec: groupSpec}); 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 group * * POST /api/v1/organizations/{organizationID}/groups */ export const createApiApiV1OrganizationsOrganizationIDGroups = async (args: CreateApiApiV1OrganizationsOrganizationIDGroupsArgs, options: CreateApiApiV1OrganizationsOrganizationIDGroupsOptions) => { 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))}/groups${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(groupRead, await res.json()) };