import type { H3Event } from 'h3' interface LinkValue { value: string } export interface WishlistRow { id: number isbn: string | null thalia: string | null cover?: string | null books: LinkValue[] authors: LinkValue[] title: LinkValue[] } export function wishlistTable(event: H3Event): string { const { baserowWishlistTableId } = useRuntimeConfig(event) if (!baserowWishlistTableId) { throw createError({ statusCode: 500, statusMessage: 'NUXT_BASEROW_WISHLIST_TABLE_ID is not set' }) } return baserowWishlistTableId } export const OPEN_LIBRARY_COVER = /^https:\/\/covers\.openlibrary\.org\/b\/id\/\d+-M\.jpg$/ function values(links: LinkValue[] | null | undefined): string[] { return (links ?? []).map(link => link.value?.trim()).filter((value): value is string => !!value) } export function toWishlistBook(row: WishlistRow): WishlistBook { const germanTitle = values(row.title).join(' / ') return { id: row.id, isbn: (row.isbn ?? '').trim(), thalia: row.thalia?.trim() || null, cover: row.cover?.trim() || null, title: germanTitle || values(row.books).join(' / '), authors: [...new Set(values(row.authors))] } }