import {z} from 'zod' export type GetApiUsersIgnoredArgs = {total?: boolean | undefined}; export type GetApiUsersIgnoredOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const respSystemInfo = z.object({visitor_id: z.number().int(), time: z.number().int(), log_id: z.number().int()}); export const getApiUsersIgnoredResponse = z.object({users: z.array(z.object({can_edit: z.boolean(), can_follow: z.boolean(), can_ignore: z.boolean(), can_post_profile: z.boolean(), can_view_profile: z.boolean(), can_view_profile_posts: z.boolean(), can_warn: z.boolean(), contest_count: z.number().int(), conv_welcome_message: z.string(), convertedDeposit: z.number().int(), custom_fields: z.object({_4: z.string(), scamURL: z.unknown(), lztLikesZeroing: z.unknown(), lztLikesIncreasing: z.unknown(), lztSympathyZeroing: z.unknown(), lztSympathyIncreasing: z.unknown(), telegram: z.unknown(), vk: z.string(), discord: z.string(), steam: z.string(), matrix: z.unknown(), jabber: z.string(), github: z.string()}), deposit: z.number().int(), homepage: z.string(), ignored_info: z.object({ignore_content: z.number().int(), ignore_conversations: z.number().int(), restrict_view_profile: z.number().int()}), is_admin: z.boolean(), is_banned: z.boolean(), is_followed: z.boolean(), is_ignored: z.boolean(), is_moderator: z.boolean(), is_staff: z.boolean(), last_activity: z.number().int(), like2_count: z.number().int(), like_count: z.number().int(), location: z.string(), message_count: z.number().int(), register_date: z.number().int(), rendered: z.object({username: z.string(), avatars: z.object({l: z.string(), m: z.string(), s: z.string()}), backgrounds: z.array(z.unknown()), link: z.string()}), short_link: z.string(), trophy_points: z.number().int(), user_id: z.number().int(), user_title: z.string(), username: z.string(), view_url: z.string(), warning_points: z.number().int()})), system_info: respSystemInfo}); 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 }; /** * Get Ignored Users * * GET /users/ignored */ export const getApiUsersIgnored = async (args: GetApiUsersIgnoredArgs, options?: GetApiUsersIgnoredOptions) => { const {baseUrl = "https://api.lolz.team", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.total != null) query.append("total", String(args.total)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/users/ignored${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiUsersIgnoredResponse, await res.json()) };