@library-pals/isbn 0.2.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -41
- package/package.json +18 -22
- package/src/index.d.ts +84 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +36 -42
- package/src/provider-resolvers.d.ts +33 -0
- package/src/provider-resolvers.d.ts.map +1 -0
- package/src/provider-resolvers.js +16 -11
- package/src/providers/google.d.ts +187 -0
- package/src/providers/google.d.ts.map +1 -0
- package/src/providers/google.js +110 -15
- package/src/providers/isbndb.d.ts +184 -0
- package/src/providers/isbndb.d.ts.map +1 -0
- package/src/providers/isbndb.js +95 -27
- package/src/providers/open-library.d.ts +256 -0
- package/src/providers/open-library.d.ts.map +1 -0
- package/src/providers/open-library.js +173 -41
- package/.gitattributes +0 -2
- package/.github/workflows/npm-publish.yml +0 -30
- package/.github/workflows/test.yml +0 -16
- package/src/cli.js +0 -41
- package/src/providers/worldcat.js +0 -63
package/README.md
CHANGED
|
@@ -5,7 +5,6 @@ following providers:
|
|
|
5
5
|
|
|
6
6
|
- [Google Books API](https://developers.google.com/books/)
|
|
7
7
|
- [Open Library Books API](https://openlibrary.org/dev/docs/api/books)
|
|
8
|
-
- [WorldCat xISBN API](http://xisbn.worldcat.org/xisbnadmin/doc/api.htm)
|
|
9
8
|
- [ISBNdb API](https://isbndb.com/apidocs/v2) using API key in the environment
|
|
10
9
|
variable `ISBNDB_API_KEY`
|
|
11
10
|
|
|
@@ -25,9 +24,10 @@ Supports Node.js versions 20.x and greater.
|
|
|
25
24
|
## Examples
|
|
26
25
|
|
|
27
26
|
```javascript
|
|
28
|
-
import
|
|
27
|
+
import Isbn from "@library-pals/isbn";
|
|
29
28
|
|
|
30
29
|
try {
|
|
30
|
+
const isbn = new Isbn();
|
|
31
31
|
const book = await isbn.resolve("9780374104092");
|
|
32
32
|
console.log("Book found %j", book);
|
|
33
33
|
} catch (err) {
|
|
@@ -38,9 +38,10 @@ try {
|
|
|
38
38
|
### Setting a timeout
|
|
39
39
|
|
|
40
40
|
```javascript
|
|
41
|
-
import
|
|
41
|
+
import Isbn from "@library-pals/isbn";
|
|
42
42
|
|
|
43
43
|
try {
|
|
44
|
+
const isbn = new Isbn();
|
|
44
45
|
const book = await isbn.resolve("9780374104092", { timeout: 15000 });
|
|
45
46
|
console.log("Book found %j", book);
|
|
46
47
|
} catch (err) {
|
|
@@ -56,37 +57,15 @@ information.
|
|
|
56
57
|
|
|
57
58
|
```json
|
|
58
59
|
{
|
|
60
|
+
"isbn": 9780374104092,
|
|
59
61
|
"title": "Annihilation",
|
|
60
|
-
"subtitle": "A Novel",
|
|
61
62
|
"authors": ["Jeff VanderMeer"],
|
|
62
|
-
"publisher": "Macmillan",
|
|
63
|
-
"publishedDate": "2014-02-04",
|
|
64
63
|
"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
|
-
"industryIdentifiers": [
|
|
66
|
-
{ "type": "ISBN_13", "identifier": "9780374104092" },
|
|
67
|
-
{ "type": "ISBN_10", "identifier": "0374104093" }
|
|
68
|
-
],
|
|
69
|
-
"readingModes": { "text": false, "image": false },
|
|
70
64
|
"pageCount": 209,
|
|
71
65
|
"printType": "BOOK",
|
|
72
66
|
"categories": ["Fiction"],
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"maturityRating": "NOT_MATURE",
|
|
76
|
-
"allowAnonLogging": false,
|
|
77
|
-
"contentVersion": "0.5.1.0.preview.0",
|
|
78
|
-
"panelizationSummary": {
|
|
79
|
-
"containsEpubBubbles": false,
|
|
80
|
-
"containsImageBubbles": false
|
|
81
|
-
},
|
|
82
|
-
"imageLinks": {
|
|
83
|
-
"smallThumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api",
|
|
84
|
-
"thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
|
|
85
|
-
},
|
|
86
|
-
"language": "en",
|
|
87
|
-
"previewLink": "http://books.google.com/books?id=2cl7AgAAQBAJ&printsec=frontcover&dq=isbn:9780374104092&hl=&cd=1&source=gbs_api",
|
|
88
|
-
"infoLink": "http://books.google.com/books?id=2cl7AgAAQBAJ&dq=isbn:9780374104092&hl=&source=gbs_api",
|
|
89
|
-
"canonicalVolumeLink": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ"
|
|
67
|
+
"thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
|
|
68
|
+
"link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ"
|
|
90
69
|
}
|
|
91
70
|
```
|
|
92
71
|
|
|
@@ -96,12 +75,12 @@ You can optionally specify the providers that you want to use, in the order you
|
|
|
96
75
|
need them to be invoked.
|
|
97
76
|
|
|
98
77
|
```javascript
|
|
99
|
-
import
|
|
100
|
-
|
|
101
|
-
// This request will search first in the Open Library API and then in the Google Books API
|
|
102
|
-
isbn.provider(["openlibrary", "google"]);
|
|
78
|
+
import Isbn from "@library-pals/isbn";
|
|
103
79
|
|
|
104
80
|
try {
|
|
81
|
+
const isbn = new Isbn();
|
|
82
|
+
// This request will search first in the Open Library API and then in the Google Books API
|
|
83
|
+
isbn.provider(["openlibrary", "google"]);
|
|
105
84
|
const book = await isbn.resolve("9780374104092");
|
|
106
85
|
console.log("Book isbn:" + input + " found %j", book);
|
|
107
86
|
} catch (err) {
|
|
@@ -110,12 +89,12 @@ try {
|
|
|
110
89
|
```
|
|
111
90
|
|
|
112
91
|
```javascript
|
|
113
|
-
import
|
|
114
|
-
|
|
115
|
-
// This request will search ONLY in the Google Books API
|
|
116
|
-
isbn.provider( "google"]);
|
|
92
|
+
import Isbn from "@library-pals/isbn";
|
|
117
93
|
|
|
118
94
|
try {
|
|
95
|
+
const isbn = new Isbn();
|
|
96
|
+
// This request will search ONLY in the Google Books API
|
|
97
|
+
isbn.provider( "google"]);
|
|
119
98
|
const book = await isbn.resolve("9780374104092");
|
|
120
99
|
console.log("Book isbn:" + input + " found %j", book);
|
|
121
100
|
} catch (err) {
|
|
@@ -127,12 +106,13 @@ If you do not like using strings to specify the providers, you could grab the
|
|
|
127
106
|
providers from `isbn.PROVIDER_NAMES` constant that the library provides!
|
|
128
107
|
|
|
129
108
|
```javascript
|
|
130
|
-
import
|
|
131
|
-
|
|
132
|
-
// This request will search ONLY in the Google Books API
|
|
133
|
-
isbn.provider([isbn.PROVIDER_NAMES.GOOGLE]);
|
|
109
|
+
import Isbn from "@library-pals/isbn";
|
|
134
110
|
|
|
135
111
|
try {
|
|
112
|
+
const isbn = new Isbn();
|
|
113
|
+
// This request will search ONLY in the Google Books API
|
|
114
|
+
isbn.provider([isbn.PROVIDER_NAMES.GOOGLE]);
|
|
115
|
+
|
|
136
116
|
const book = await isbn.resolve("9780374104092");
|
|
137
117
|
console.log("Book isbn:" + input + " found %j", book);
|
|
138
118
|
} catch (err) {
|
|
@@ -147,5 +127,4 @@ try {
|
|
|
147
127
|
See also
|
|
148
128
|
[Google Books API Terms of Service](https://developers.google.com/books/terms),
|
|
149
129
|
[Open Library Licensing](https://openlibrary.org/developers/licensing),
|
|
150
|
-
[WorldCat xISBN Terms of Service](http://www.oclc.org/worldcat/community/terms.en.html),
|
|
151
130
|
[ISBNdb Terms and Conditions](https://isbndb.com/terms-and-conditions).
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@library-pals/isbn",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Find books by ISBN",
|
|
5
|
-
"
|
|
5
|
+
"exports": "./src/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
6
7
|
"type": "module",
|
|
7
8
|
"engines": {
|
|
8
9
|
"node": ">=20.0.0"
|
|
9
10
|
},
|
|
10
|
-
"bin": {
|
|
11
|
-
"isbn": "src/cli.js"
|
|
12
|
-
},
|
|
13
11
|
"scripts": {
|
|
12
|
+
"build": "tsc --version && tsc --build --clean && tsc --build",
|
|
13
|
+
"prepack": "npm run build",
|
|
14
14
|
"lint": "eslint .",
|
|
15
|
-
"pretest": "npm run lint",
|
|
16
|
-
"test": "
|
|
17
|
-
"
|
|
15
|
+
"pretest": "npm run build && npm run lint",
|
|
16
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
|
|
17
|
+
"format": "prettier . --log-level warn --write"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -26,31 +26,27 @@
|
|
|
26
26
|
"google",
|
|
27
27
|
"openlibrary",
|
|
28
28
|
"api",
|
|
29
|
-
"worldcat",
|
|
30
29
|
"isbndb"
|
|
31
30
|
],
|
|
32
31
|
"author": "Katy DeCorah <@katydecorah>",
|
|
33
32
|
"license": "AGPL-3.0-or-later",
|
|
34
33
|
"devDependencies": {
|
|
35
34
|
"@eslint/js": "^9.2.0",
|
|
36
|
-
"@types/nock": "^11.1.0",
|
|
37
35
|
"eslint": "^9.2.0",
|
|
38
|
-
"eslint-plugin-
|
|
39
|
-
"eslint-plugin-
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
36
|
+
"eslint-plugin-jest": "^28.5.0",
|
|
37
|
+
"eslint-plugin-jsdoc": "^48.2.4",
|
|
38
|
+
"eslint-plugin-unicorn": "^53.0.0",
|
|
39
|
+
"globals": "^15.2.0",
|
|
40
|
+
"jest": "^29.7.0",
|
|
41
|
+
"prettier": "^3.2.5",
|
|
42
|
+
"prettier-2": "npm:prettier@^2",
|
|
43
|
+
"typescript": "^5.4.5"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"axios": "^1.6.8"
|
|
47
47
|
},
|
|
48
48
|
"bugs": {
|
|
49
|
-
"url": "https://github.com/
|
|
49
|
+
"url": "https://github.com/library-pals/isbn/issues"
|
|
50
50
|
},
|
|
51
|
-
"homepage": "https://github.com/
|
|
52
|
-
"directories": {
|
|
53
|
-
"example": "examples",
|
|
54
|
-
"test": "test"
|
|
55
|
-
}
|
|
51
|
+
"homepage": "https://github.com/library-pals/isbn#readme"
|
|
56
52
|
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} Book
|
|
3
|
+
* @property {string} isbn - The ISBN of the book.
|
|
4
|
+
* @property {string} title - The long title of the book.
|
|
5
|
+
* @property {string[]} authors - The authors of the book.
|
|
6
|
+
* @property {string} description - The overview of the book.
|
|
7
|
+
* @property {number} pageCount - The number of pages in the book.
|
|
8
|
+
* @property {string} printType - The print type of the book. Always "BOOK" for this context.
|
|
9
|
+
* @property {string[]} categories - The subjects or categories of the book.
|
|
10
|
+
* @property {string | undefined} [thumbnail] - The thumbnail image link of the book.
|
|
11
|
+
* @property {string} [link] - The link of the book.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {import('./provider-resolvers.js').Providers} Providers
|
|
15
|
+
* @typedef {import('axios').AxiosRequestConfig} AxiosRequestConfig
|
|
16
|
+
*/
|
|
17
|
+
export default class Isbn {
|
|
18
|
+
/**
|
|
19
|
+
* @type {Providers}
|
|
20
|
+
*/
|
|
21
|
+
_providers: import("./provider-resolvers.js").Providers;
|
|
22
|
+
PROVIDER_NAMES: {
|
|
23
|
+
GOOGLE: string;
|
|
24
|
+
OPENLIBRARY: string;
|
|
25
|
+
ISBNDB: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Sets the providers for the ISBN lookup.
|
|
29
|
+
* @param {string[]} providers - An array of provider names.
|
|
30
|
+
* @returns {object} - The current instance of the ISBN lookup.
|
|
31
|
+
* @throws {TypeError} - If `providers` is not an array.
|
|
32
|
+
* @throws {Error} - If any of the provided providers are not supported.
|
|
33
|
+
*/
|
|
34
|
+
provider(providers: string[]): object;
|
|
35
|
+
/**
|
|
36
|
+
* Resolves the book information for the given ISBN.
|
|
37
|
+
* @param {string} isbn - The ISBN of the book.
|
|
38
|
+
* @param {AxiosRequestConfig} options - The options for the request.
|
|
39
|
+
* @returns {Promise<Book>} - A Promise that resolves to the book information.
|
|
40
|
+
* @throws {Error} - If an error occurs while resolving the book information.
|
|
41
|
+
*/
|
|
42
|
+
resolve(isbn: string, options?: AxiosRequestConfig): Promise<Book>;
|
|
43
|
+
}
|
|
44
|
+
export type Book = {
|
|
45
|
+
/**
|
|
46
|
+
* - The ISBN of the book.
|
|
47
|
+
*/
|
|
48
|
+
isbn: string;
|
|
49
|
+
/**
|
|
50
|
+
* - The long title of the book.
|
|
51
|
+
*/
|
|
52
|
+
title: string;
|
|
53
|
+
/**
|
|
54
|
+
* - The authors of the book.
|
|
55
|
+
*/
|
|
56
|
+
authors: string[];
|
|
57
|
+
/**
|
|
58
|
+
* - The overview of the book.
|
|
59
|
+
*/
|
|
60
|
+
description: string;
|
|
61
|
+
/**
|
|
62
|
+
* - The number of pages in the book.
|
|
63
|
+
*/
|
|
64
|
+
pageCount: number;
|
|
65
|
+
/**
|
|
66
|
+
* - The print type of the book. Always "BOOK" for this context.
|
|
67
|
+
*/
|
|
68
|
+
printType: string;
|
|
69
|
+
/**
|
|
70
|
+
* - The subjects or categories of the book.
|
|
71
|
+
*/
|
|
72
|
+
categories: string[];
|
|
73
|
+
/**
|
|
74
|
+
* - The thumbnail image link of the book.
|
|
75
|
+
*/
|
|
76
|
+
thumbnail?: string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* - The link of the book.
|
|
79
|
+
*/
|
|
80
|
+
link?: string;
|
|
81
|
+
};
|
|
82
|
+
export type Providers = import('./provider-resolvers.js').Providers;
|
|
83
|
+
export type AxiosRequestConfig = import('axios').AxiosRequestConfig;
|
|
84
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;GAWG;AAEH;;;GAGG;AAEH;IACE;;OAEG;IACH,wDAA+B;IAG7B;;;;MAAoC;IAGtC;;;;;;OAMG;IACH,oBALW,MAAM,EAAE,GACN,MAAM,CAwBlB;IAED;;;;;;OAMG;IACH,cALW,MAAM,YACN,kBAAkB,GAChB,QAAQ,IAAI,CAAC,CAkBzB;CACF;;;;;UA9Ea,MAAM;;;;WACN,MAAM;;;;aACN,MAAM,EAAE;;;;iBACR,MAAM;;;;eACN,MAAM;;;;eACN,MAAM;;;;gBACN,MAAM,EAAE;;;;gBACR,MAAM,GAAG,SAAS;;;;WAClB,MAAM;;wBAIP,OAAO,yBAAyB,EAAE,SAAS;iCAC3C,OAAO,OAAO,EAAE,kBAAkB"}
|
package/src/index.js
CHANGED
|
@@ -5,21 +5,31 @@ import {
|
|
|
5
5
|
} from "./provider-resolvers.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* @typedef {object} Book
|
|
9
|
+
* @property {string} isbn - The ISBN of the book.
|
|
10
|
+
* @property {string} title - The long title of the book.
|
|
11
|
+
* @property {string[]} authors - The authors of the book.
|
|
12
|
+
* @property {string} description - The overview of the book.
|
|
13
|
+
* @property {number} pageCount - The number of pages in the book.
|
|
14
|
+
* @property {string} printType - The print type of the book. Always "BOOK" for this context.
|
|
15
|
+
* @property {string[]} categories - The subjects or categories of the book.
|
|
16
|
+
* @property {string | undefined} [thumbnail] - The thumbnail image link of the book.
|
|
17
|
+
* @property {string} [link] - The link of the book.
|
|
10
18
|
*/
|
|
11
|
-
class Isbn {
|
|
12
|
-
constructor() {
|
|
13
|
-
this.PROVIDER_NAMES = PROVIDER_NAMES;
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {import('./provider-resolvers.js').Providers} Providers
|
|
22
|
+
* @typedef {import('axios').AxiosRequestConfig} AxiosRequestConfig
|
|
23
|
+
*/
|
|
17
24
|
|
|
25
|
+
export default class Isbn {
|
|
18
26
|
/**
|
|
19
|
-
*
|
|
27
|
+
* @type {Providers}
|
|
20
28
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
_providers = DEFAULT_PROVIDERS;
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
this.PROVIDER_NAMES = PROVIDER_NAMES;
|
|
23
33
|
}
|
|
24
34
|
|
|
25
35
|
/**
|
|
@@ -39,11 +49,11 @@ class Isbn {
|
|
|
39
49
|
}
|
|
40
50
|
|
|
41
51
|
const unsupportedProviders = providers.filter(
|
|
42
|
-
(p) => !DEFAULT_PROVIDERS.includes(p)
|
|
52
|
+
(p) => !DEFAULT_PROVIDERS.includes(p),
|
|
43
53
|
);
|
|
44
54
|
if (unsupportedProviders.length > 0) {
|
|
45
55
|
throw new Error(
|
|
46
|
-
`Unsupported providers: ${unsupportedProviders.join(", ")}
|
|
56
|
+
`Unsupported providers: ${unsupportedProviders.join(", ")}`,
|
|
47
57
|
);
|
|
48
58
|
}
|
|
49
59
|
|
|
@@ -52,42 +62,26 @@ class Isbn {
|
|
|
52
62
|
}
|
|
53
63
|
|
|
54
64
|
/**
|
|
55
|
-
*
|
|
56
|
-
* @param {Array<string>} providers - The list of providers to retrieve book information from.
|
|
65
|
+
* Resolves the book information for the given ISBN.
|
|
57
66
|
* @param {string} isbn - The ISBN of the book.
|
|
58
|
-
* @param {
|
|
59
|
-
* @returns {Promise<
|
|
60
|
-
* @throws {Error} If
|
|
67
|
+
* @param {AxiosRequestConfig} options - The options for the request.
|
|
68
|
+
* @returns {Promise<Book>} - A Promise that resolves to the book information.
|
|
69
|
+
* @throws {Error} - If an error occurs while resolving the book information.
|
|
61
70
|
*/
|
|
62
|
-
async
|
|
63
|
-
|
|
71
|
+
async resolve(isbn, options = {}) {
|
|
72
|
+
const messages = [];
|
|
73
|
+
for (const provider of this._providers) {
|
|
64
74
|
try {
|
|
65
75
|
return await PROVIDER_RESOLVERS[provider](isbn, options);
|
|
66
|
-
} catch {
|
|
67
|
-
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (error.message) messages.push(`${provider}: ${error.message}`);
|
|
68
78
|
}
|
|
69
79
|
}
|
|
70
80
|
// If none of the providers worked, we throw an error.
|
|
71
|
-
throw new Error(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* @param {string} isbn - The ISBN of the book.
|
|
77
|
-
* @param {object} options - The options for the request.
|
|
78
|
-
* @returns {Promise<object>} - A Promise that resolves to the book information.
|
|
79
|
-
* @throws {Error} - If an error occurs while resolving the book information.
|
|
80
|
-
*/
|
|
81
|
-
async resolve(isbn, options = {}) {
|
|
82
|
-
try {
|
|
83
|
-
const book = await this._getBookInfo(this._providers, isbn, options);
|
|
84
|
-
this._resetProviders();
|
|
85
|
-
return book;
|
|
86
|
-
} catch (error) {
|
|
87
|
-
this._resetProviders();
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
81
|
+
throw new Error(
|
|
82
|
+
`All providers failed${
|
|
83
|
+
messages.length > 0 ? `\n${messages.join("\n")}` : ""
|
|
84
|
+
}`,
|
|
85
|
+
);
|
|
90
86
|
}
|
|
91
87
|
}
|
|
92
|
-
|
|
93
|
-
export default new Isbn();
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {string[]} Providers
|
|
3
|
+
* @typedef {import('axios').AxiosRequestConfig} AxiosRequestConfig
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Default options for the provider resolvers.
|
|
7
|
+
* @type {AxiosRequestConfig}
|
|
8
|
+
* @property {number} timeout - The timeout value in milliseconds.
|
|
9
|
+
*/
|
|
10
|
+
export const defaultOptions: AxiosRequestConfig;
|
|
11
|
+
export const GOOGLE_BOOKS_API_BASE: "https://www.googleapis.com";
|
|
12
|
+
export const GOOGLE_BOOKS_API_BOOK: "/books/v1/volumes";
|
|
13
|
+
export const OPENLIBRARY_API_BASE: "https://openlibrary.org";
|
|
14
|
+
export const OPENLIBRARY_API_BOOK: "/isbn";
|
|
15
|
+
export const ISBNDB_API_BASE: "https://api2.isbndb.com";
|
|
16
|
+
export const ISBNDB_API_BOOK: "/book";
|
|
17
|
+
export namespace PROVIDER_NAMES {
|
|
18
|
+
let GOOGLE: string;
|
|
19
|
+
let OPENLIBRARY: string;
|
|
20
|
+
let ISBNDB: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Default providers for resolving ISBN information.
|
|
24
|
+
* @type {Providers}
|
|
25
|
+
*/
|
|
26
|
+
export const DEFAULT_PROVIDERS: Providers;
|
|
27
|
+
export const PROVIDER_RESOLVERS: {
|
|
28
|
+
[x: string]: typeof resolveGoogle;
|
|
29
|
+
};
|
|
30
|
+
export type Providers = string[];
|
|
31
|
+
export type AxiosRequestConfig = import('axios').AxiosRequestConfig;
|
|
32
|
+
import { resolveGoogle } from "./providers/google.js";
|
|
33
|
+
//# sourceMappingURL=provider-resolvers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-resolvers.d.ts","sourceRoot":"","sources":["provider-resolvers.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;;GAIG;AACH,6BAHU,kBAAkB,CAK1B;AAEF,iEAAkE;AAClE,wDAAyD;AAEzD,6DAA8D;AAC9D,2CAA4C;AAE5C,wDAAyD;AACzD,sCAAuC;;;;;;AAOvC;;;GAGG;AACH,0CAIE;AACF;;EAIE;wBAxCW,MAAM,EAAE;iCACR,OAAO,OAAO,EAAE,kBAAkB;8BANjB,uBAAuB"}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { resolveGoogle } from "./providers/google.js";
|
|
2
2
|
import { resolveOpenLibrary } from "./providers/open-library.js";
|
|
3
|
-
import { resolveWorldcat } from "./providers/worldcat.js";
|
|
4
3
|
import { resolveIsbnDb } from "./providers/isbndb.js";
|
|
5
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {string[]} Providers
|
|
7
|
+
* @typedef {import('axios').AxiosRequestConfig} AxiosRequestConfig
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Default options for the provider resolvers.
|
|
12
|
+
* @type {AxiosRequestConfig}
|
|
13
|
+
* @property {number} timeout - The timeout value in milliseconds.
|
|
14
|
+
*/
|
|
6
15
|
export const defaultOptions = {
|
|
7
|
-
poll: {
|
|
8
|
-
maxSockets: 500,
|
|
9
|
-
},
|
|
10
16
|
timeout: 5000,
|
|
11
17
|
};
|
|
12
18
|
|
|
@@ -14,28 +20,27 @@ export const GOOGLE_BOOKS_API_BASE = "https://www.googleapis.com";
|
|
|
14
20
|
export const GOOGLE_BOOKS_API_BOOK = "/books/v1/volumes";
|
|
15
21
|
|
|
16
22
|
export const OPENLIBRARY_API_BASE = "https://openlibrary.org";
|
|
17
|
-
export const OPENLIBRARY_API_BOOK = "/
|
|
18
|
-
|
|
19
|
-
export const WORLDCAT_API_BASE = "http://xisbn.worldcat.org";
|
|
20
|
-
export const WORLDCAT_API_BOOK = "/webservices/xid/isbn";
|
|
23
|
+
export const OPENLIBRARY_API_BOOK = "/isbn";
|
|
21
24
|
|
|
22
25
|
export const ISBNDB_API_BASE = "https://api2.isbndb.com";
|
|
23
26
|
export const ISBNDB_API_BOOK = "/book";
|
|
24
27
|
export const PROVIDER_NAMES = {
|
|
25
28
|
GOOGLE: "google",
|
|
26
29
|
OPENLIBRARY: "openlibrary",
|
|
27
|
-
WORLDCAT: "worldcat",
|
|
28
30
|
ISBNDB: "isbndb",
|
|
29
31
|
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Default providers for resolving ISBN information.
|
|
35
|
+
* @type {Providers}
|
|
36
|
+
*/
|
|
30
37
|
export const DEFAULT_PROVIDERS = [
|
|
31
38
|
PROVIDER_NAMES.GOOGLE,
|
|
32
39
|
PROVIDER_NAMES.OPENLIBRARY,
|
|
33
|
-
PROVIDER_NAMES.WORLDCAT,
|
|
34
40
|
PROVIDER_NAMES.ISBNDB,
|
|
35
41
|
];
|
|
36
42
|
export const PROVIDER_RESOLVERS = {
|
|
37
43
|
[PROVIDER_NAMES.GOOGLE]: resolveGoogle,
|
|
38
44
|
[PROVIDER_NAMES.OPENLIBRARY]: resolveOpenLibrary,
|
|
39
|
-
[PROVIDER_NAMES.WORLDCAT]: resolveWorldcat,
|
|
40
45
|
[PROVIDER_NAMES.ISBNDB]: resolveIsbnDb,
|
|
41
46
|
};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('../index.js').Book} Book
|
|
3
|
+
* @typedef {import('axios').AxiosRequestConfig} AxiosRequestConfig
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Resolves book information from Google Books API using the provided ISBN.
|
|
7
|
+
* @param {string} isbn - The ISBN of the book.
|
|
8
|
+
* @param {AxiosRequestConfig} options - Additional options for the API request.
|
|
9
|
+
* @returns {Promise<Book>} The book information retrieved from the API.
|
|
10
|
+
* @throws {Error} If the API response code is not 200, or if no books are found with the provided ISBN, or if no volume information is found for the book.
|
|
11
|
+
*/
|
|
12
|
+
export function resolveGoogle(isbn: string, options: AxiosRequestConfig): Promise<Book>;
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {object} ImageLinks
|
|
15
|
+
* @property {string} [extraLarge] - extraLarge
|
|
16
|
+
* @property {string} [large] - large
|
|
17
|
+
* @property {string} [medium] - medium
|
|
18
|
+
* @property {string} [small] - small
|
|
19
|
+
* @property {string} [thumbnail] - thumbnail
|
|
20
|
+
* @property {string} [smallThumbnail] - smallThumbnail
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {object} GoogleBook
|
|
24
|
+
* @property {string} title - The title of the book.
|
|
25
|
+
* @property {string} subtitle - The subtitle of the book.
|
|
26
|
+
* @property {string[]} authors - The authors of the book.
|
|
27
|
+
* @property {string} publisher - The publisher of the book.
|
|
28
|
+
* @property {string} publishedDate - The published date of the book.
|
|
29
|
+
* @property {string} description - The description of the book.
|
|
30
|
+
* @property {object[]} industryIdentifiers - The industry identifiers of the book.
|
|
31
|
+
* @property {object} readingModes - The reading modes of the book.
|
|
32
|
+
* @property {number} pageCount - The number of pages in the book.
|
|
33
|
+
* @property {string} printType - The print type of the book.
|
|
34
|
+
* @property {string[]} categories - The categories of the book.
|
|
35
|
+
* @property {number} averageRating - The average rating of the book.
|
|
36
|
+
* @property {number} ratingsCount - The ratings count of the book.
|
|
37
|
+
* @property {string} maturityRating - The maturity rating of the book.
|
|
38
|
+
* @property {boolean} allowAnonLogging - The allow anon logging of the book.
|
|
39
|
+
* @property {string} contentVersion - The content version of the book.
|
|
40
|
+
* @property {object} panelizationSummary - The panelization summary of the book.
|
|
41
|
+
* @property {ImageLinks} [imageLinks] - The image links of the book.
|
|
42
|
+
* @property {string} language - The language of the book.
|
|
43
|
+
* @property {string} previewLink - The preview link of the book.
|
|
44
|
+
* @property {string} infoLink - The info link of the book.
|
|
45
|
+
* @property {string} canonicalVolumeLink - The canonical volume link of the book.
|
|
46
|
+
* @property {object} saleInfo - The sale info of the book.
|
|
47
|
+
* @property {object} accessInfo - The access info of the book.
|
|
48
|
+
* @property {object} searchInfo - The search info of the book.
|
|
49
|
+
*/
|
|
50
|
+
/**
|
|
51
|
+
* Standardizes a book object by extracting relevant information from the provided book object.
|
|
52
|
+
* @param {GoogleBook} book - The book object to be standardized.
|
|
53
|
+
* @param {string} isbn - The book's ISBN.
|
|
54
|
+
* @returns {Book} The standardized book object.
|
|
55
|
+
*/
|
|
56
|
+
export function standardize(book: GoogleBook, isbn: string): Book;
|
|
57
|
+
export type Book = import('../index.js').Book;
|
|
58
|
+
export type AxiosRequestConfig = import('axios').AxiosRequestConfig;
|
|
59
|
+
export type ImageLinks = {
|
|
60
|
+
/**
|
|
61
|
+
* - extraLarge
|
|
62
|
+
*/
|
|
63
|
+
extraLarge?: string;
|
|
64
|
+
/**
|
|
65
|
+
* - large
|
|
66
|
+
*/
|
|
67
|
+
large?: string;
|
|
68
|
+
/**
|
|
69
|
+
* - medium
|
|
70
|
+
*/
|
|
71
|
+
medium?: string;
|
|
72
|
+
/**
|
|
73
|
+
* - small
|
|
74
|
+
*/
|
|
75
|
+
small?: string;
|
|
76
|
+
/**
|
|
77
|
+
* - thumbnail
|
|
78
|
+
*/
|
|
79
|
+
thumbnail?: string;
|
|
80
|
+
/**
|
|
81
|
+
* - smallThumbnail
|
|
82
|
+
*/
|
|
83
|
+
smallThumbnail?: string;
|
|
84
|
+
};
|
|
85
|
+
export type GoogleBook = {
|
|
86
|
+
/**
|
|
87
|
+
* - The title of the book.
|
|
88
|
+
*/
|
|
89
|
+
title: string;
|
|
90
|
+
/**
|
|
91
|
+
* - The subtitle of the book.
|
|
92
|
+
*/
|
|
93
|
+
subtitle: string;
|
|
94
|
+
/**
|
|
95
|
+
* - The authors of the book.
|
|
96
|
+
*/
|
|
97
|
+
authors: string[];
|
|
98
|
+
/**
|
|
99
|
+
* - The publisher of the book.
|
|
100
|
+
*/
|
|
101
|
+
publisher: string;
|
|
102
|
+
/**
|
|
103
|
+
* - The published date of the book.
|
|
104
|
+
*/
|
|
105
|
+
publishedDate: string;
|
|
106
|
+
/**
|
|
107
|
+
* - The description of the book.
|
|
108
|
+
*/
|
|
109
|
+
description: string;
|
|
110
|
+
/**
|
|
111
|
+
* - The industry identifiers of the book.
|
|
112
|
+
*/
|
|
113
|
+
industryIdentifiers: object[];
|
|
114
|
+
/**
|
|
115
|
+
* - The reading modes of the book.
|
|
116
|
+
*/
|
|
117
|
+
readingModes: object;
|
|
118
|
+
/**
|
|
119
|
+
* - The number of pages in the book.
|
|
120
|
+
*/
|
|
121
|
+
pageCount: number;
|
|
122
|
+
/**
|
|
123
|
+
* - The print type of the book.
|
|
124
|
+
*/
|
|
125
|
+
printType: string;
|
|
126
|
+
/**
|
|
127
|
+
* - The categories of the book.
|
|
128
|
+
*/
|
|
129
|
+
categories: string[];
|
|
130
|
+
/**
|
|
131
|
+
* - The average rating of the book.
|
|
132
|
+
*/
|
|
133
|
+
averageRating: number;
|
|
134
|
+
/**
|
|
135
|
+
* - The ratings count of the book.
|
|
136
|
+
*/
|
|
137
|
+
ratingsCount: number;
|
|
138
|
+
/**
|
|
139
|
+
* - The maturity rating of the book.
|
|
140
|
+
*/
|
|
141
|
+
maturityRating: string;
|
|
142
|
+
/**
|
|
143
|
+
* - The allow anon logging of the book.
|
|
144
|
+
*/
|
|
145
|
+
allowAnonLogging: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* - The content version of the book.
|
|
148
|
+
*/
|
|
149
|
+
contentVersion: string;
|
|
150
|
+
/**
|
|
151
|
+
* - The panelization summary of the book.
|
|
152
|
+
*/
|
|
153
|
+
panelizationSummary: object;
|
|
154
|
+
/**
|
|
155
|
+
* - The image links of the book.
|
|
156
|
+
*/
|
|
157
|
+
imageLinks?: ImageLinks;
|
|
158
|
+
/**
|
|
159
|
+
* - The language of the book.
|
|
160
|
+
*/
|
|
161
|
+
language: string;
|
|
162
|
+
/**
|
|
163
|
+
* - The preview link of the book.
|
|
164
|
+
*/
|
|
165
|
+
previewLink: string;
|
|
166
|
+
/**
|
|
167
|
+
* - The info link of the book.
|
|
168
|
+
*/
|
|
169
|
+
infoLink: string;
|
|
170
|
+
/**
|
|
171
|
+
* - The canonical volume link of the book.
|
|
172
|
+
*/
|
|
173
|
+
canonicalVolumeLink: string;
|
|
174
|
+
/**
|
|
175
|
+
* - The sale info of the book.
|
|
176
|
+
*/
|
|
177
|
+
saleInfo: object;
|
|
178
|
+
/**
|
|
179
|
+
* - The access info of the book.
|
|
180
|
+
*/
|
|
181
|
+
accessInfo: object;
|
|
182
|
+
/**
|
|
183
|
+
* - The search info of the book.
|
|
184
|
+
*/
|
|
185
|
+
searchInfo: object;
|
|
186
|
+
};
|
|
187
|
+
//# sourceMappingURL=google.d.ts.map
|