Integrada la búsqueda de bibliografía ahora también con Open Library y permitiendo obtener resultados de un idioma

- Se actualizó el contrato de búsqueda para enviar términos y parámetros por endpoint (Google y Open Library), y se consumió una respuesta unificada con origen por resultado.
- Se reemplazó el control de cantidad por un selector de idioma, y se mapearon los códigos a ISO 639-1 (Google) e ISO 639-2 (Open Library).
- Se forzó la obtención de resultados más recientes (orderBy="newest" y sort="new") y se ordenaron los resultados en frontend por año de publicación descendente, sin importar el endpoint.
- Se etiquetó cada sugerencia con un badge de origen (Google u Open Library).
This commit is contained in:
2026-03-09 17:03:47 -06:00
parent 203e8608a2
commit ab2510ba1c
4 changed files with 777 additions and 518 deletions

View File

@@ -42,8 +42,19 @@ const EDGE = {
export type BuscarBibliografiaRequest = {
searchTerms: {
q: string
maxResults: number
}
google: {
orderBy?: 'newest' | 'relevance'
langRestrict?: string
startIndex?: number
[k: string]: unknown
}
openLibrary: {
language?: string
page?: number
sort?: string
[k: string]: unknown
}
}
@@ -82,20 +93,22 @@ export type GoogleBooksVolume = {
[k: string]: unknown
}
export type OpenLibraryDoc = Record<string, unknown>
export type EndpointResult =
| { endpoint: 'google'; item: GoogleBooksVolume }
| { endpoint: 'open_library'; item: OpenLibraryDoc }
export async function buscar_bibliografia(
input: BuscarBibliografiaRequest,
): Promise<Array<GoogleBooksVolume>> {
): Promise<Array<EndpointResult>> {
const q = input.searchTerms.q
const maxResults = input.searchTerms.maxResults
if (typeof q !== 'string' || q.trim().length < 1) {
throw new Error('q es requerido')
}
if (!Number.isInteger(maxResults) || maxResults < 0 || maxResults > 40) {
throw new Error('maxResults debe ser entero entre 0 y 40')
}
return await invokeEdge<Array<GoogleBooksVolume>>(
return await invokeEdge<Array<EndpointResult>>(
EDGE.buscar_bibliografia,
input,
{ headers: { 'Content-Type': 'application/json' } },