import {z} from 'zod' export type UserUpdate = {name?: string | undefined, surname?: string | undefined, email?: string | undefined, organization_id?: number | undefined, active_study_area_id: number, active_data_upload_ids: Array, storage: number, limit_scenarios: number, roles?: Array | undefined, study_areas?: Array | undefined, password?: string | undefined, is_active?: boolean | undefined}; export type UpdateApiApiV1UsersUserIdArgs = {user_id: number, body: UserUpdate}; export type UpdateApiApiV1UsersUserIdOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const user = z.object({name: z.string(), surname: z.string(), email: z.string(), organization_id: z.number().int(), active_study_area_id: z.number().int(), active_data_upload_ids: z.array(z.number().int()), storage: z.number().int(), limit_scenarios: z.number().int(), id: z.number().int().optional(), hashed_password: z.string().optional(), is_active: z.boolean().optional(), newsletter: z.boolean().optional(), occupation: z.string().optional(), domain: z.string().optional(), creation_date: z.string().optional(), language_preference: z.string()}); 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/users/{user_id} */ export const updateApiApiV1UsersUserId = async (args: UpdateApiApiV1UsersUserIdArgs, options: UpdateApiApiV1UsersUserIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/users/${encodeURIComponent(String(args.user_id))}${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(user, await res.json()) };