import {z} from 'zod' export type UpdateApiApiOrganisationsArgs = {body: {name?: string | undefined, displayName?: string | undefined, preferences?: ({themeLogo?: string | undefined, themePrimaryColor?: string | undefined, emailSignupDomains?: string | undefined}) | undefined}}; export type UpdateApiApiOrganisationsOptions = {baseUrl: string, internalAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiApiOrganisationsResponse = z.object({id: z.string(), name: z.string(), displayName: z.string(), onboarded: z.boolean(), license: z.string().optional(), licenseData: z.object({kind: z.enum(["online", "offline", "null"]).nullable().optional(), createdAt: z.string().nullable().optional(), expiresAt: z.string().nullable().optional(), environmentState: z.enum(["initial", "connected", "disabled"]), organisationStatus: z.enum(["active", "disabled", "invalid", "grace", "expired"]), environmentLimits: z.object({users: z.number().optional(), projects: z.number().optional(), documents: z.number().optional(), deployments: z.number().optional(), enableDeploymentsWorkflows: z.boolean().optional(), enableSSO: z.boolean().optional(), enableAuditLogs: z.boolean().optional(), enableBranding: z.boolean().optional(), evaluateByRelease: z.boolean().optional(), diffModel: z.boolean().optional(), diffRelease: z.boolean().optional(), activeSimulation: z.boolean().optional(), testEventsShared: z.boolean().optional(), enableLLM: z.boolean().optional(), enableRoles: z.boolean().optional()}).optional()}).optional(), url: z.string().optional(), themeLogo: z.string(), themePrimaryColor: z.string(), preferences: z.object({emailSignupDomains: z.string().optional(), themePrimaryColor: z.string().optional(), themeLogo: z.string().optional()}), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string().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 the organisation * * PUT /api/organisations */ export const updateApiApiOrganisations = async (args: UpdateApiApiOrganisationsArgs, options: UpdateApiApiOrganisationsOptions) => { const {baseUrl, fetch: fetchFn = fetch, internalAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (internalAuth !== undefined) headers.set('authorization', `internal ${internalAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/organisations${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(updateApiApiOrganisationsResponse, await res.json()) };