diff --git a/README.md b/README.md index de4d45e..6401fe9 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,6 @@ information. ```json { - "isbn": 9780374104092, "title": "Annihilation", "authors": ["Jeff VanderMeer"], "description": "Describes the 12th expedition to “Area X,” a region cut off from the continent for decades, by a group of intrepid women scientists who try to ignore the high mortality rates of those on the previous 11 missions. Original. 75,000 first printing.", @@ -65,7 +64,10 @@ information. "printType": "BOOK", "categories": ["Fiction"], "thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api", - "link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ" + "link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ", + "publisher": "Macmillan", + "publishedDate": "2014-02-04", + "isbn": "9780374104092" } ``` diff --git a/src/index.d.ts b/src/index.d.ts index 39fbcf6..43915f7 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,12 +1,14 @@ /** * @typedef {object} Book * @property {string} isbn - The ISBN of the book. - * @property {string} title - The long title of the book. + * @property {string} title - The title of the book. * @property {string[]} authors - The authors of the book. * @property {string} description - The overview of the book. * @property {number} pageCount - The number of pages in the book. - * @property {string} printType - The print type of the book. Always "BOOK" for this context. + * @property {string} printType - The print type of the book. * @property {string[]} categories - The subjects or categories of the book. + * @property {string} publisher - The publisher of the book. + * @property {string} publishedDate - The date the book was published. * @property {string | undefined} [thumbnail] - The thumbnail image link of the book. * @property {string} [link] - The link of the book. */ @@ -47,7 +49,7 @@ export type Book = { */ isbn: string; /** - * - The long title of the book. + * - The title of the book. */ title: string; /** @@ -63,13 +65,21 @@ export type Book = { */ pageCount: number; /** - * - The print type of the book. Always "BOOK" for this context. + * - The print type of the book. */ printType: string; /** * - The subjects or categories of the book. */ categories: string[]; + /** + * - The publisher of the book. + */ + publisher: string; + /** + * - The date the book was published. + */ + publishedDate: string; /** * - The thumbnail image link of the book. */ diff --git a/src/index.js b/src/index.js index 8456f41..a9fa666 100644 --- a/src/index.js +++ b/src/index.js @@ -7,12 +7,14 @@ import { /** * @typedef {object} Book * @property {string} isbn - The ISBN of the book. - * @property {string} title - The long title of the book. + * @property {string} title - The title of the book. * @property {string[]} authors - The authors of the book. * @property {string} description - The overview of the book. * @property {number} pageCount - The number of pages in the book. - * @property {string} printType - The print type of the book. Always "BOOK" for this context. + * @property {string} printType - The print type of the book. * @property {string[]} categories - The subjects or categories of the book. + * @property {string} publisher - The publisher of the book. + * @property {string} publishedDate - The date the book was published. * @property {string | undefined} [thumbnail] - The thumbnail image link of the book. * @property {string} [link] - The link of the book. */ diff --git a/src/providers/google.js b/src/providers/google.js index 8544331..356141e 100644 --- a/src/providers/google.js +++ b/src/providers/google.js @@ -99,6 +99,8 @@ export function standardize(book, isbn) { categories: book.categories, thumbnail: getLargestThumbnail(book.imageLinks), link: book.canonicalVolumeLink, + publisher: book.publisher, + publishedDate: book.publishedDate, isbn, }; diff --git a/src/providers/isbndb.js b/src/providers/isbndb.js index e765bb3..7059d1d 100644 --- a/src/providers/isbndb.js +++ b/src/providers/isbndb.js @@ -123,6 +123,8 @@ function standardize(book, isbn) { printType: "BOOK", categories: book.subjects, thumbnail: book.image, + publisher: book.publisher, + publishedDate: book.date_published, isbn, }; } diff --git a/src/providers/open-library.js b/src/providers/open-library.js index 4a5e654..6b0cab0 100644 --- a/src/providers/open-library.js +++ b/src/providers/open-library.js @@ -118,6 +118,8 @@ export async function standardize(book, isbn) { link: book.key ? `${OPENLIBRARY_API_BASE}${book.key}` : `${OPENLIBRARY_API_BASE}${OPENLIBRARY_API_BOOK}/${isbn}`, + publisher: book.publishers?.join(", "), + publishedDate: book.publish_date, isbn, }; diff --git a/test/end-to-end.test.js b/test/end-to-end.test.js index 78ed781..23f6a56 100644 --- a/test/end-to-end.test.js +++ b/test/end-to-end.test.js @@ -24,6 +24,8 @@ describe("End to end", () => { "link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ", "pageCount": 209, "printType": "BOOK", + "publishedDate": "2014-02-04", + "publisher": "Macmillan", "thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api", "title": "Annihilation", } @@ -86,6 +88,8 @@ describe("End to end", () => { "link": "https://openlibrary.org/books/OL31444108M", "pageCount": 208, "printType": "BOOK", + "publishedDate": "2014", + "publisher": "Farrar, Straus and Giroux", "thumbnail": "https://covers.openlibrary.org/b/id/10520611-L.jpg", "title": "Annihilation", } @@ -107,6 +111,8 @@ describe("End to end", () => { "link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ", "pageCount": 209, "printType": "BOOK", + "publishedDate": "2014-02-04", + "publisher": "Macmillan", "thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api", "title": "Annihilation", } diff --git a/test/index.test.js b/test/index.test.js index 0ccbaf5..179ee63 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -48,6 +48,8 @@ describe("ISBN Resolver API", () => { "link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ", "pageCount": 209, "printType": "BOOK", + "publishedDate": "2014-02-04", + "publisher": "Macmillan", "thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api", "title": "Annihilation", } @@ -83,6 +85,8 @@ describe("ISBN Resolver API", () => { "link": "https://openlibrary.org/books/OL7353617M", "pageCount": 96, "printType": "BOOK", + "publishedDate": "October 1, 1988", + "publisher": "Puffin", "thumbnail": "https://covers.openlibrary.org/b/id/8739161-L.jpg", "title": "Fantastic Mr. Fox", } @@ -145,6 +149,8 @@ describe("ISBN Resolver API", () => { "isbn": "9780374104092", "pageCount": 174, "printType": "BOOK", + "publishedDate": "1992-12-13", + "publisher": "Turtle Bay Books", "thumbnail": "https://images.isbndb.com/covers/30/23/9781484233023.jpg", "title": "Book Title", } @@ -236,6 +242,8 @@ describe("ISBN Resolver API", () => { "link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ", "pageCount": 209, "printType": "BOOK", + "publishedDate": "2014-02-04", + "publisher": "Macmillan", "thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api", "title": "Annihilation", } @@ -268,6 +276,8 @@ describe("ISBN Resolver API", () => { "link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ", "pageCount": 209, "printType": "BOOK", + "publishedDate": "2014-02-04", + "publisher": "Macmillan", "thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api", "title": "Annihilation", } diff --git a/test/providers/google.test.js b/test/providers/google.test.js index 0d1dada..85f7a43 100644 --- a/test/providers/google.test.js +++ b/test/providers/google.test.js @@ -38,6 +38,8 @@ describe("resolveGoogle", () => { "link": undefined, "pageCount": undefined, "printType": undefined, + "publishedDate": undefined, + "publisher": undefined, "thumbnail": undefined, "title": "Test Book", } diff --git a/test/providers/isbndb.test.js b/test/providers/isbndb.test.js index ab887ef..5d43462 100644 --- a/test/providers/isbndb.test.js +++ b/test/providers/isbndb.test.js @@ -47,6 +47,8 @@ describe("resolveIsbnDb", () => { "isbn": "1234567890", "pageCount": 123, "printType": "BOOK", + "publishedDate": "2022-01-01", + "publisher": "Test Publisher", "thumbnail": "http://example.com/test.jpg", "title": "Test Book", } diff --git a/test/providers/open-library.test.js b/test/providers/open-library.test.js index 0aecbae..d6c26f9 100644 --- a/test/providers/open-library.test.js +++ b/test/providers/open-library.test.js @@ -82,6 +82,8 @@ describe("resolveOpenLibrary", () => { "link": "https://openlibrary.org/books/OL7353617M", "pageCount": 96, "printType": "BOOK", + "publishedDate": "October 1, 1988", + "publisher": "Puffin", "thumbnail": "https://covers.openlibrary.org/b/id/8739161-L.jpg", "title": "Fantastic Mr. Fox", } @@ -111,6 +113,8 @@ describe("resolveOpenLibrary", () => { "link": "https://openlibrary.org/isbn/9780374104092", "pageCount": 96, "printType": "BOOK", + "publishedDate": "October 1, 1988", + "publisher": undefined, "thumbnail": "https://covers.openlibrary.org/b/id/8739161-L.jpg", "title": "Fantastic Mr. Fox", } @@ -126,7 +130,7 @@ describe("resolveOpenLibrary", () => { }); await expect(resolveOpenLibrary(isbn, {})).rejects.toThrow( - `No books found with ISBN: ${isbn}`, + `No books found with ISBN: ${isbn}` ); }); @@ -139,7 +143,7 @@ describe("resolveOpenLibrary", () => { }); await expect(resolveOpenLibrary(isbn, {})).rejects.toThrow( - "Wrong response code: 404", + "Wrong response code: 404" ); }); }); @@ -181,7 +185,7 @@ describe("getAuthors", () => { axios.get.mockResolvedValueOnce({ status: 404 }); await expect(getAuthors(rawAuthors)).rejects.toThrow( - "Unable to get author /authors/OL1A: 404", + "Unable to get author /authors/OL1A: 404" ); }); }); @@ -258,7 +262,7 @@ describe("getWorks", () => { axios.get.mockResolvedValueOnce({ status: 404 }); await expect(getWorks({ works })).rejects.toThrow( - "Unable to get /works/OL1A: 404", + "Unable to get /works/OL1A: 404" ); }); });