import {z} from 'zod' export type CreateApiApiV1UsersDemoActivateArgs = {token?: string | undefined}; export type CreateApiApiV1UsersDemoActivateOptions = {baseUrl: string, 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 }; /** * Activate Demo User * * POST /api/v1/users/demo/activate */ export const createApiApiV1UsersDemoActivate = async (args: CreateApiApiV1UsersDemoActivateArgs, options: CreateApiApiV1UsersDemoActivateOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.token != null) query.append("token", String(args.token)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/users/demo/activate${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) 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()) };