import {z} from 'zod' export type GetApiThreadsFollowedArgs = {total?: boolean | undefined, fields_include?: (Array<'*' | 'latest_posts'>) | undefined}; export type GetApiThreadsFollowedOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const respPostModel = z.object({avatar_url: z.string(), can_edit: z.boolean(), can_hard_delete: z.boolean(), can_like: z.boolean(), can_reply: z.boolean(), can_report: z.boolean(), can_soft_delete: z.boolean(), can_stick: z.boolean(), can_undelete: z.boolean(), can_unstick: z.boolean(), can_view: z.boolean(), edit_count: z.number().int(), is_banned: z.boolean(), is_first_post: z.boolean(), is_ignored: z.boolean(), is_last_post: z.boolean(), is_like2_node: z.boolean(), is_liked: z.boolean(), is_staff: z.boolean(), is_sticked: z.boolean(), is_unread: z.boolean(), last_edit_date: z.number().int(), last_edit_user_id: z.number().int(), like_date: z.number().int(), likes: z.number().int(), message: z.string(), message_html: z.string(), message_plain_text: z.string(), message_state: z.string(), node_id: z.number().int(), position: z.number().int(), post_date: z.number().int(), post_id: z.number().int(), signature: z.string(), signature_html: z.string(), signature_plain_text: z.string(), sticky_user_id: z.number().int(), thread_id: z.number().int(), thread_is_closed: z.boolean(), thread_is_deleted: z.boolean(), update_date: z.number().int(), user_id: z.number().int(), username: z.string(), username_html: z.string(), view_url: z.string(), warning_id: z.number().int(), warning_message: z.string(), comment_count: z.number().int()}); export const respThreadModel = z.object({allow_ask_hidden_content: z.boolean(), avatar_url: z.string(), bump: z.object({can: z.boolean(), available_count: z.number().int(), error: z.string(), next_available_time: z.number().int()}), can_edit: z.boolean(), can_edit_tags: z.boolean(), can_edit_title: z.boolean(), can_hard_delete: z.boolean(), can_reply: z.boolean(), can_soft_delete: z.boolean(), can_view: z.boolean(), can_watch: z.boolean(), comment_ignore_group: z.boolean(), discussion_open: z.boolean(), discussion_state: z.string(), discussion_type: z.string(), first_post: respPostModel, first_post_id: z.number().int(), first_post_likes: z.number().int(), hide_contacts: z.boolean(), is_bumped: z.boolean(), is_hidden: z.boolean(), is_hot: z.boolean(), is_ignored: z.boolean(), is_like2_node: z.boolean(), is_liked: z.boolean(), is_starred: z.boolean(), is_unread: z.boolean(), is_watched: z.boolean(), last_bump_date: z.number().int(), last_post_date: z.number().int(), last_post_id: z.number().int(), last_post_user_id: z.number().int(), last_post_username: z.string(), node_id: z.number().int(), node_title: z.string(), post_count: z.number().int(), post_date: z.number().int(), prefix_id: z.number().int(), prefix_ids: z.array(z.number().int()), reply_count: z.number().int(), reply_group_id: z.number().int(), review_negative_count: z.number().int(), review_paid_count: z.number().int(), review_positive_count: z.number().int(), review_score: z.number(), review_share: z.number(), review_total_count: z.number().int(), review_unproven_count: z.number().int(), sticky: z.boolean(), tags: z.array(z.string()), thread_id: z.number().int(), title: z.string(), title_en: z.string(), user_id: z.number().int(), username: z.string(), username_html: z.string(), view_count: z.number().int(), view_url: z.string(), visitor_post_count: z.number().int(), contest: z.object({type: z.string(), finish_date: z.number().int(), now_count_members: z.number().int(), needed_members: z.number().int(), is_finished: z.number().int(), count_winners: z.number().int(), require_like_count: z.number().int(), require_total_like_count: z.number().int(), prize_type: z.string(), prize_type_phrase: z.string(), prize_data: z.union([z.record(z.string(), z.number()), z.number()]), prize_cost: z.number().int(), is_money_places: z.number().int(), chance_to_win: z.number(), prize_per_winner: z.number().int().nullable(), prize_places: z.object({place: z.number().int(), amount: z.number().int()}).nullable(), already_participate: z.boolean(), permissions: z.object({can_finish: z.boolean(), can_participate: z.boolean(), can_participate_error: z.string(), can_view_user_list: z.boolean()})})}); export const respSystemInfo = z.object({visitor_id: z.number().int(), time: z.number().int(), log_id: z.number().int()}); export const getApiThreadsFollowedResponse = z.object({threads: z.array(respThreadModel), threads_total: 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 Followed Threads * * GET /threads/followed */ export const getApiThreadsFollowed = async (args: GetApiThreadsFollowedArgs, options?: GetApiThreadsFollowedOptions) => { 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 (args.fields_include != null) query.append("fields_include", args.fields_include.join(',')) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/threads/followed${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(getApiThreadsFollowedResponse, await res.json()) };