diff --git a/README.md b/README.md index 08c4ae9..279c908 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,8 @@ information. "publisher": "Macmillan", "publishedDate": "2014-02-04", "language": "en", - "isbn": "9780374104092" + "isbn": "9780374104092", + "bookProvider": "Google Books" } ``` @@ -146,7 +147,8 @@ information. "publisher": "Farrar, Straus and Giroux", "publishedDate": "2014", "language": "en", - "isbn": "9780374104092" + "isbn": "9780374104092", + "bookProvider": "Open Library" } ``` diff --git a/src/index.d.ts b/src/index.d.ts index ccef194..ab8558f 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -12,6 +12,7 @@ * @property {string | undefined} [language] - The language of the book. * @property {string | undefined} [thumbnail] - The thumbnail image link of the book. * @property {string} [link] - The link of the book. + * @property {string} bookProvider - The provider of the book information. */ /** * @typedef {import('./provider-resolvers.js').Providers} Providers @@ -93,6 +94,10 @@ export type Book = { * - The link of the book. */ link?: string; + /** + * - The provider of the book information. + */ + bookProvider: string; }; export type Providers = import('./provider-resolvers.js').Providers; export type AxiosRequestConfig = import('axios').AxiosRequestConfig; diff --git a/src/index.js b/src/index.js index 6cbcd3b..edfbea3 100644 --- a/src/index.js +++ b/src/index.js @@ -18,6 +18,7 @@ import { * @property {string | undefined} [language] - The language of the book. * @property {string | undefined} [thumbnail] - The thumbnail image link of the book. * @property {string} [link] - The link of the book. + * @property {string} bookProvider - The provider of the book information. */ /** diff --git a/src/providers/google.js b/src/providers/google.js index 41470c6..f73a513 100644 --- a/src/providers/google.js +++ b/src/providers/google.js @@ -107,6 +107,7 @@ export async function standardize(book, id, isbn) { publishedDate: book.publishedDate, language: book.language, isbn, + bookProvider: "Google Books", }; return standardBook; diff --git a/src/providers/isbndb.js b/src/providers/isbndb.js index eccd975..3dbc0e1 100644 --- a/src/providers/isbndb.js +++ b/src/providers/isbndb.js @@ -127,5 +127,6 @@ function standardize(book, isbn) { publishedDate: book.date_published, language: book.language, isbn, + bookProvider: "ISBNdb", }; } diff --git a/src/providers/open-library.js b/src/providers/open-library.js index fc1435d..b3b729a 100644 --- a/src/providers/open-library.js +++ b/src/providers/open-library.js @@ -122,6 +122,7 @@ export async function standardize(book, isbn) { publishedDate: book.publish_date, language: formatLanguage(book.languages), isbn, + bookProvider: "Open Library", }; return standardBook; diff --git a/test/__snapshots__/end-to-end.test.js.snap b/test/__snapshots__/end-to-end.test.js.snap index 03149b2..f92d20b 100644 --- a/test/__snapshots__/end-to-end.test.js.snap +++ b/test/__snapshots__/end-to-end.test.js.snap @@ -5,6 +5,7 @@ exports[`End to end Annihilation { name: 'default', providers: [] } 1`] = ` "authors": [ "Jeff VanderMeer", ], + "bookProvider": "Google Books", "categories": [ "Fiction", "Fiction / General", @@ -34,6 +35,7 @@ exports[`End to end Annihilation { name: 'google', providers: [Array] } 1`] = ` "authors": [ "Jeff VanderMeer", ], + "bookProvider": "Google Books", "categories": [ "Fiction", "Fiction / General", @@ -63,6 +65,7 @@ exports[`End to end Annihilation { name: 'openlibrary', providers: [Array] } 1`] "authors": [ "Jeff VanderMeer", ], + "bookProvider": "Open Library", "categories": [ "Nebula Award Winner", "award:nebula_award=novel", @@ -125,6 +128,7 @@ exports[`End to end Fantastic Mr. Fox { name: 'default', providers: [] } 1`] = ` "authors": [ "Roald Dahl", ], + "bookProvider": "Google Books", "categories": [ "Juvenile Fiction", "Juvenile Fiction / Animals / Foxes", @@ -148,6 +152,7 @@ exports[`End to end Fantastic Mr. Fox { name: 'google', providers: [Array] } 1`] "authors": [ "Roald Dahl", ], + "bookProvider": "Google Books", "categories": [ "Juvenile Fiction", "Juvenile Fiction / Animals / Foxes", @@ -171,6 +176,7 @@ exports[`End to end Fantastic Mr. Fox { name: 'openlibrary', providers: [Array] "authors": [ "Roald Dahl", ], + "bookProvider": "Open Library", "categories": [ "Animals", "Hunger", @@ -226,6 +232,7 @@ exports[`End to end Transcendent Kingdom { name: 'default', providers: [] } 1`] "authors": [ "Yaa Gyasi", ], + "bookProvider": "Google Books", "categories": [ "Fiction", "Fiction / Literary", @@ -252,6 +259,7 @@ exports[`End to end Transcendent Kingdom { name: 'google', providers: [Array] } "authors": [ "Yaa Gyasi", ], + "bookProvider": "Google Books", "categories": [ "Fiction", "Fiction / Literary", @@ -278,6 +286,7 @@ exports[`End to end Transcendent Kingdom { name: 'openlibrary', providers: [Arra "authors": [ "Yaa Gyasi", ], + "bookProvider": "Open Library", "categories": [ "American literature", "nyt:combined-print-and-e-book-fiction=2020-09-20", diff --git a/test/index.test.js b/test/index.test.js index 3903cf3..aaf0c3d 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -40,6 +40,7 @@ describe("ISBN Resolver API", () => { "authors": [ "Jeff VanderMeer", ], + "bookProvider": "Google Books", "categories": [ "Fiction", ], @@ -80,6 +81,7 @@ describe("ISBN Resolver API", () => { expect(book).toMatchInlineSnapshot(` { "authors": [], + "bookProvider": "Open Library", "categories": [], "description": "", "isbn": "9780374104092", @@ -146,6 +148,7 @@ describe("ISBN Resolver API", () => { "authors": [ "Aswin Pranam", ], + "bookProvider": "ISBNdb", "categories": undefined, "description": undefined, "isbn": "9780374104092", @@ -237,6 +240,7 @@ describe("ISBN Resolver API", () => { "authors": [ "Jeff VanderMeer", ], + "bookProvider": "Google Books", "categories": [ "Fiction", ], diff --git a/test/providers/google.test.js b/test/providers/google.test.js index 0af6353..6b01d67 100644 --- a/test/providers/google.test.js +++ b/test/providers/google.test.js @@ -64,6 +64,7 @@ describe("resolveGoogle", () => { "authors": [ "Test Author", ], + "bookProvider": "Google Books", "categories": [ "Fiction", "Fiction / General", @@ -150,6 +151,7 @@ describe("resolveGoogle", () => { "authors": [ "Test Author", ], + "bookProvider": "Google Books", "categories": [ "Fiction", "Fiction / General", @@ -217,6 +219,7 @@ describe("resolveGoogle", () => { "authors": [ "Test Author", ], + "bookProvider": "Google Books", "categories": [], "description": undefined, "isbn": "1234567890", @@ -258,6 +261,7 @@ describe("resolveGoogle", () => { "authors": [ "Test Author", ], + "bookProvider": "Google Books", "categories": [], "description": undefined, "isbn": "1234567890", diff --git a/test/providers/isbndb.test.js b/test/providers/isbndb.test.js index d8d908f..6615276 100644 --- a/test/providers/isbndb.test.js +++ b/test/providers/isbndb.test.js @@ -40,6 +40,7 @@ describe("resolveIsbnDb", () => { "authors": [ "Test Author", ], + "bookProvider": "ISBNdb", "categories": [ "Test subject", ], diff --git a/test/providers/open-library.test.js b/test/providers/open-library.test.js index f2059a1..a87125b 100644 --- a/test/providers/open-library.test.js +++ b/test/providers/open-library.test.js @@ -40,6 +40,7 @@ describe("resolveOpenLibrary", () => { "authors": [ "Roald Dahl", ], + "bookProvider": "Open Library", "categories": [ "Animals", "Hunger", @@ -109,6 +110,7 @@ describe("resolveOpenLibrary", () => { expect(book).toMatchInlineSnapshot(` { "authors": [], + "bookProvider": "Open Library", "categories": [], "description": "", "isbn": "9780374104092", @@ -133,7 +135,7 @@ describe("resolveOpenLibrary", () => { }); await expect(resolveOpenLibrary(isbn, {})).rejects.toThrow( - `No books found with ISBN: ${isbn}`, + `No books found with ISBN: ${isbn}` ); }); @@ -146,7 +148,7 @@ describe("resolveOpenLibrary", () => { }); await expect(resolveOpenLibrary(isbn, {})).rejects.toThrow( - "Wrong response code: 404", + "Wrong response code: 404" ); }); }); @@ -188,7 +190,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" ); }); }); @@ -265,7 +267,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" ); }); });