UNPKG

open-library-client

Version:

A modern TypeScript API wrapper for the OpenLibrary REST API

113 lines 3.8 kB
import { OpenLibraryClientConfig, BookSearchParams, BookSearchResponse, WorkDetails, EditionDetails, BookDetails, ApiResponse } from '../types'; /** * Main client for interacting with the OpenLibrary API */ export declare class OpenLibraryClient { private readonly httpClient; private readonly config; /** * Create a new OpenLibrary client instance * @param config - Configuration options for the client */ constructor(config?: OpenLibraryClientConfig); /** * Setup request and response interceptors */ private setupInterceptors; /** * Handle and format API errors */ private handleError; /** * Search for books using the OpenLibrary search API * @param params - Search parameters * @returns Promise resolving to search results * * @example * ```typescript * const client = new OpenLibraryClient(); * const results = await client.searchBooks({ * q: 'The Lord of the Rings', * author: 'Tolkien', * limit: 5 * }); * ``` */ searchBooks(params: BookSearchParams): Promise<ApiResponse<BookSearchResponse>>; /** * Get detailed information about a specific work * @param workKey - The OpenLibrary work key (e.g., "OL45804W") * @returns Promise resolving to work details * * @example * ```typescript * const client = new OpenLibraryClient(); * const work = await client.getWork("OL45804W"); * console.log(work.data.title); * ``` */ getWork(workKey: string): Promise<ApiResponse<WorkDetails>>; /** * Get detailed information about a specific edition * @param editionKey - The OpenLibrary edition key (e.g., "OL7353617M") * @returns Promise resolving to edition details * * @example * ```typescript * const client = new OpenLibraryClient(); * const edition = await client.getEdition("OL7353617M"); * console.log(edition.data.title); * ``` */ getEdition(editionKey: string): Promise<ApiResponse<EditionDetails>>; /** * Get book information by ISBN * @param isbn - The ISBN (10 or 13 digits) * @returns Promise resolving to book details * * @example * ```typescript * const client = new OpenLibraryClient(); * const book = await client.getBookByISBN("9780140328721"); * console.log(book.data.title); * ``` */ getBookByISBN(isbn: string): Promise<ApiResponse<BookDetails>>; /** * Generate cover image URL from cover ID * @param coverId - The cover ID number * @param size - Size of the cover image ('S', 'M', or 'L') * @returns Cover image URL * * @example * ```typescript * const client = new OpenLibraryClient(); * const coverUrl = client.getCoverUrl(8739161, 'M'); * console.log(coverUrl); // https://covers.openlibrary.org/b/id/8739161-M.jpg * ``` */ getCoverUrl(coverId: number, size?: 'S' | 'M' | 'L'): string; /** * Generate cover image URL from ISBN * @param isbn - The ISBN (10 or 13 digits) * @param size - Size of the cover image ('S', 'M', or 'L') * @returns Cover image URL * * @example * ```typescript * const client = new OpenLibraryClient(); * const coverUrl = client.getCoverUrlByISBN('9780547928227', 'L'); * console.log(coverUrl); // https://covers.openlibrary.org/b/isbn/9780547928227-L.jpg * ``` */ getCoverUrlByISBN(isbn: string, size?: 'S' | 'M' | 'L'): string; /** * Get the current client configuration */ getConfig(): Required<OpenLibraryClientConfig>; /** * Get the base URL being used by the client */ getBaseURL(): string; } //# sourceMappingURL=OpenLibraryClient.d.ts.map