import {z} from 'zod' export type GetApiUsersUserIdFollowersArgs = {user_id: string | number, order?: ('natural' | 'follow_date' | 'follow_date_reverse') | undefined, page?: number | undefined, limit?: number | undefined}; export type GetApiUsersUserIdFollowersOptions = {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 getApiUsersUserIdFollowersResponse = z.object({users: z.array(z.object({content_type: z.string(), content_id: z.number().int(), follow_date: z.number().int(), user_id: z.number().int(), username: z.string(), username_html: z.string(), user_message_count: z.number().int(), user_register_date: z.number().int(), user_like_count: z.number().int(), user_like2_count: z.number().int(), contest_count: z.number().int(), trophy_count: z.number().int(), custom_title: z.string(), is_banned: z.number().int(), user_title: z.string(), user_is_valid: z.boolean(), user_is_verified: z.boolean(), user_is_followed: z.boolean(), user_last_seen_date: z.number().int(), user_following_count: z.number().int(), user_followers_count: z.number().int(), links: z.object({permalink: z.string(), detail: z.string(), avatar: z.string(), avatar_big: z.string(), avatar_small: z.string(), followers: z.string(), followings: z.string(), ignore: z.string(), timeline: z.string()}), permissions: z.object({edit: z.boolean(), follow: z.boolean(), ignore: z.boolean(), profile_post: z.boolean()}), user_is_ignored: z.boolean(), user_is_visitor: z.boolean(), user_group_id: z.number().int(), custom_fields: z.object({_4: z.string(), lztInnovation20Link: z.string(), lztInnovation30Link: z.string(), lztInnovationLink: z.string()})})), users_total: z.number().int(), links: z.object({pages: z.number().int(), page: z.number().int(), next: z.string()}), 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 User Followers * * GET /users/{user_id}/followers */ export const getApiUsersUserIdFollowers = async (args: GetApiUsersUserIdFollowersArgs, options?: GetApiUsersUserIdFollowersOptions) => { 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.order != null) query.append("order", String(args.order)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/users/${encodeURIComponent(String(args.user_id))}/followers${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(getApiUsersUserIdFollowersResponse, await res.json()) };