import {z} from 'zod' export type ModifyUserInput = {kudos?: number | undefined, concurrency?: number | undefined, usage_multiplier?: number | undefined, worker_invited?: number | undefined, moderator?: boolean | undefined, public_workers?: boolean | undefined, monthly_kudos?: number | undefined, username?: string | undefined, trusted?: boolean | undefined, flagged?: boolean | undefined, customizer?: boolean | undefined, vpn?: boolean | undefined, service?: boolean | undefined, education?: boolean | undefined, special?: boolean | undefined, filtered?: boolean | undefined, reset_suspicion?: boolean | undefined, contact?: string | undefined, admin_comment?: string | undefined}; export type UpdateApiV2UsersUserIdArgs = {apikey: string, 'Client-Agent'?: string | undefined, 'X-Fields'?: unknown | undefined, body: ModifyUserInput}; export type UpdateApiV2UsersUserIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const modifyUser = z.object({new_kudos: z.number().optional(), concurrency: z.number().int().optional(), usage_multiplier: z.number().optional(), worker_invited: z.number().int().optional(), moderator: z.boolean().optional(), public_workers: z.boolean().optional(), username: z.string().optional(), monthly_kudos: z.number().int().optional(), trusted: z.boolean().optional(), flagged: z.boolean().optional(), customizer: z.boolean().optional(), vpn: z.boolean().optional(), service: z.boolean().optional(), education: z.boolean().optional(), special: z.boolean().optional(), new_suspicion: z.number().int().optional(), contact: z.string().optional(), admin_comment: z.string().min(5).max(500).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 }; /** * Endpoint for horde admins to perform operations on users * * PUT /v2/users/{user_id} */ export const updateApiV2UsersUserId = async (args: UpdateApiV2UsersUserIdArgs, options: UpdateApiV2UsersUserIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.apikey != null) headers.set("apikey", String(args.apikey)) if (args['Client-Agent'] != null) headers.set("Client-Agent", String(args['Client-Agent'])) if (args['X-Fields'] != null) headers.set("X-Fields", String(args['X-Fields'])) const url = `${baseUrl.replace(/\/+$/, '')}/v2/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(modifyUser, await res.json()) };