import root from "$lib/Utility/root"; export interface ACDBBirthday { character_image: string; name: string; origin: string; } const isACDBBirthday = (entry: unknown): entry is ACDBBirthday => typeof entry === "object" && entry !== null && typeof (entry as { character_image?: unknown }).character_image === "string" && typeof (entry as { name?: unknown }).name === "string" && typeof (entry as { origin?: unknown }).origin === "string"; export const ACDBBirthdays = async ( month: number, day: number, ): Promise => { const response = await fetch( root(`/api/birthdays/secondary?month=${month}&day=${day}`), { headers: { Accept: "application/json", "Content-Type": "application/json", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0", }, }, ); if (!response.ok) throw new Error( `Secondary birthdays request failed with ${response.status}.`, ); const data: unknown = await response.json(); if ( typeof data !== "object" || data === null || !Array.isArray((data as { characters?: unknown }).characters) ) throw new Error( "Secondary birthdays response did not include a characters array.", ); return (data as { characters: unknown[] }).characters.filter(isACDBBirthday); };