import {z} from 'zod' export type CreateApiThreadsIdFeatureArgs = {body: BodyInit}; export type CreateApiThreadsIdFeatureOptions = {baseUrl?: string | undefined, XFOAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const user = z.object({about: z.string().optional(), activity_visible: z.boolean().optional(), age: z.number().int().optional(), alert_optout: z.array(z.unknown()).optional(), allow_post_profile: z.string().optional(), allow_receive_news_feed: z.string().optional(), allow_send_personal_conversation: z.string().optional(), allow_view_identities: z.string().optional(), allow_view_profile: z.string().optional(), avatar_urls: z.object({}).optional(), profile_banner_urls: z.object({}).optional(), can_ban: z.boolean().optional(), can_converse: z.boolean().optional(), can_edit: z.boolean().optional(), can_follow: z.boolean().optional(), can_ignore: z.boolean().optional(), can_post_profile: z.boolean().optional(), can_view_profile: z.boolean().optional(), can_view_profile_posts: z.boolean().optional(), can_warn: z.boolean().optional(), content_show_signature: z.boolean().optional(), creation_watch_state: z.string().optional(), custom_fields: z.object({}).optional(), custom_title: z.string().optional(), dob: z.object({}).optional(), email: z.string().optional(), email_on_conversation: z.boolean().optional(), gravatar: z.string().optional(), interaction_watch_state: z.boolean().optional(), is_admin: z.boolean().optional(), is_banned: z.boolean().optional(), is_discouraged: z.boolean().optional(), is_followed: z.boolean().optional(), is_ignored: z.boolean().optional(), is_moderator: z.boolean().optional(), is_super_admin: z.boolean().optional(), last_activity: z.number().int().optional(), location: z.string().optional(), push_on_conversation: z.boolean().optional(), push_optout: z.array(z.unknown()).optional(), receive_admin_email: z.boolean().optional(), secondary_group_ids: z.array(z.unknown()).optional(), show_dob_date: z.boolean().optional(), show_dob_year: z.boolean().optional(), signature: z.string().optional(), timezone: z.string().optional(), use_tfa: z.boolean().optional(), user_group_id: z.number().int().optional(), user_state: z.string().optional(), user_title: z.string().optional(), visible: z.boolean().optional(), warning_points: z.number().int().optional(), website: z.string().optional(), view_url: z.string().optional(), user_id: z.number().int().optional(), username: z.string().optional(), message_count: z.number().int().optional(), question_solution_count: z.number().int().optional(), register_date: z.number().int().optional(), trophy_points: z.number().int().optional(), is_staff: z.boolean().optional(), reaction_score: z.number().int().optional(), vote_score: z.number().int().optional()}); export const featuredContent = z.object({content_username: z.string().optional(), title: z.string().optional(), image: z.string().nullable().optional(), snippet: z.string().optional(), view_url: z.string().optional(), can_view_content: z.boolean().optional(), feature_user_id: z.number().int().optional(), unfeature_date: z.number().int().optional(), auto_featured: z.boolean().optional(), always_visible: z.boolean().optional(), unfeature_days: z.number().int().optional(), is_customized: z.boolean().optional(), featured_content_id: z.number().int().optional(), content_type: z.string().optional(), content_id: z.number().int().optional(), content_container_id: z.number().int().optional(), content_user_id: z.number().int().optional(), content_date: z.number().int().optional(), content_visible: z.boolean().optional(), feature_date: z.number().int().optional(), image_date: z.number().int().optional(), ContentUser: user.optional()}); export const createApiThreadsIdFeatureResponse = z.object({success: z.boolean().optional(), feature: featuredContent.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 }; /** * Set feature state for the specified thread * * POST /threads/{id}/feature * * Also accepts auth: XF-Api-Key */ export const createApiThreadsIdFeature = async (args: CreateApiThreadsIdFeatureArgs, options?: CreateApiThreadsIdFeatureOptions) => { const {baseUrl = "https://example.com/api", fetch: fetchFn = fetch, XFOAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (XFOAuth2 !== undefined) headers.set('authorization', `Bearer ${XFOAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/threads/${encodeURIComponent(String(args.id))}/feature${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiThreadsIdFeatureResponse, await res.json()) };