@library-pals/isbn 0.0.0 → 1.0.0
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 +153 -0
- package/src/providers/google.d.ts.map +1 -0
- package/src/providers/google.js +77 -16
- 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 -14
- package/src/cli.js +0 -41
- package/src/providers/worldcat.js +0 -63
package/src/providers/google.js
CHANGED
|
@@ -5,32 +5,93 @@ import {
|
|
|
5
5
|
GOOGLE_BOOKS_API_BOOK,
|
|
6
6
|
} from "../provider-resolvers.js";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {import('../index.js').Book} Book
|
|
10
|
+
* @typedef {import('axios').AxiosRequestConfig} AxiosRequestConfig
|
|
11
|
+
*/
|
|
12
|
+
|
|
8
13
|
/**
|
|
9
14
|
* Resolves book information from Google Books API using the provided ISBN.
|
|
10
15
|
* @param {string} isbn - The ISBN of the book.
|
|
11
|
-
* @param {
|
|
12
|
-
* @returns {Promise<
|
|
16
|
+
* @param {AxiosRequestConfig} options - Additional options for the API request.
|
|
17
|
+
* @returns {Promise<Book>} The book information retrieved from the API.
|
|
13
18
|
* @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.
|
|
14
19
|
*/
|
|
15
20
|
export async function resolveGoogle(isbn, options) {
|
|
16
21
|
const requestOptions = {
|
|
17
22
|
...defaultOptions,
|
|
18
23
|
...options,
|
|
19
|
-
url: `${GOOGLE_BOOKS_API_BASE}${GOOGLE_BOOKS_API_BOOK}?q=isbn:${isbn}`,
|
|
20
24
|
};
|
|
25
|
+
const url = `${GOOGLE_BOOKS_API_BASE}${GOOGLE_BOOKS_API_BOOK}?q=isbn:${isbn}`;
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
try {
|
|
28
|
+
const response = await axios.get(url, requestOptions);
|
|
29
|
+
if (response.status !== 200) {
|
|
30
|
+
throw new Error(`Wrong response code: ${response.status}`);
|
|
31
|
+
}
|
|
32
|
+
const books = response.data;
|
|
33
|
+
if (!books.totalItems) {
|
|
34
|
+
throw new Error(`No books found with isbn: ${isbn}`);
|
|
35
|
+
}
|
|
36
|
+
// In very rare circumstances books.items[0] is undefined (see #2)
|
|
37
|
+
if (!books.items || books.items.length === 0) {
|
|
38
|
+
throw new Error(`No volume info found for book with isbn: ${isbn}`);
|
|
39
|
+
}
|
|
40
|
+
const book = books.items[0];
|
|
41
|
+
return standardize(book.volumeInfo, book.id, isbn);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw new Error(error.message);
|
|
29
44
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @typedef {object} GoogleBook
|
|
49
|
+
* @property {string} title - The title of the book.
|
|
50
|
+
* @property {string} subtitle - The subtitle of the book.
|
|
51
|
+
* @property {string[]} authors - The authors of the book.
|
|
52
|
+
* @property {string} publisher - The publisher of the book.
|
|
53
|
+
* @property {string} publishedDate - The published date of the book.
|
|
54
|
+
* @property {string} description - The description of the book.
|
|
55
|
+
* @property {object[]} industryIdentifiers - The industry identifiers of the book.
|
|
56
|
+
* @property {object} readingModes - The reading modes of the book.
|
|
57
|
+
* @property {number} pageCount - The number of pages in the book.
|
|
58
|
+
* @property {string} printType - The print type of the book.
|
|
59
|
+
* @property {string[]} categories - The categories of the book.
|
|
60
|
+
* @property {number} averageRating - The average rating of the book.
|
|
61
|
+
* @property {number} ratingsCount - The ratings count of the book.
|
|
62
|
+
* @property {string} maturityRating - The maturity rating of the book.
|
|
63
|
+
* @property {boolean} allowAnonLogging - The allow anon logging of the book.
|
|
64
|
+
* @property {string} contentVersion - The content version of the book.
|
|
65
|
+
* @property {object} panelizationSummary - The panelization summary of the book.
|
|
66
|
+
* @property {object} imageLinks - The image links of the book.
|
|
67
|
+
* @property {string} language - The language of the book.
|
|
68
|
+
* @property {string} previewLink - The preview link of the book.
|
|
69
|
+
* @property {string} infoLink - The info link of the book.
|
|
70
|
+
* @property {string} canonicalVolumeLink - The canonical volume link of the book.
|
|
71
|
+
* @property {object} saleInfo - The sale info of the book.
|
|
72
|
+
* @property {object} accessInfo - The access info of the book.
|
|
73
|
+
* @property {object} searchInfo - The search info of the book.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Standardizes a book object by extracting relevant information from the provided book object.
|
|
78
|
+
* @param {GoogleBook} book - The book object to be standardized.
|
|
79
|
+
* @param {string} id - The book's id.
|
|
80
|
+
* @param {string} isbn - The book's ISBN.
|
|
81
|
+
* @returns {Book} - The standardized book object.
|
|
82
|
+
*/
|
|
83
|
+
export function standardize(book, id, isbn) {
|
|
84
|
+
const standardBook = {
|
|
85
|
+
title: book.title,
|
|
86
|
+
authors: book.authors,
|
|
87
|
+
description: book.description,
|
|
88
|
+
pageCount: book.pageCount,
|
|
89
|
+
printType: book.printType,
|
|
90
|
+
categories: book.categories,
|
|
91
|
+
thumbnail: `https://books.google.com/books?id=${id}&printsec=frontcover&img=1&zoom=6&edge=curl&source=gbs_api`,
|
|
92
|
+
link: book.canonicalVolumeLink,
|
|
93
|
+
isbn,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return standardBook;
|
|
36
97
|
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('../index.js').Book} Book
|
|
3
|
+
* @typedef {import('axios').AxiosRequestConfig} AxiosRequestConfig
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Resolves the ISBN using the ISBNdb API.
|
|
7
|
+
* @param {string} isbn - The ISBN to resolve.
|
|
8
|
+
* @param {AxiosRequestConfig} options - Additional options for the request.
|
|
9
|
+
* @returns {Promise<Book>} - A promise that resolves to the standardized book data.
|
|
10
|
+
* @throws {Error} - If the response code is not 200 or if no books are found with the given ISBN.
|
|
11
|
+
*/
|
|
12
|
+
export function resolveIsbnDb(isbn: string, options: AxiosRequestConfig): Promise<Book>;
|
|
13
|
+
export type Book = import('../index.js').Book;
|
|
14
|
+
export type AxiosRequestConfig = import('axios').AxiosRequestConfig;
|
|
15
|
+
export type Dimension = {
|
|
16
|
+
/**
|
|
17
|
+
* - The unit of the dimension.
|
|
18
|
+
*/
|
|
19
|
+
unit: string;
|
|
20
|
+
/**
|
|
21
|
+
* - The value of the dimension.
|
|
22
|
+
*/
|
|
23
|
+
value: number;
|
|
24
|
+
};
|
|
25
|
+
export type Offset = {
|
|
26
|
+
/**
|
|
27
|
+
* - The x offset.
|
|
28
|
+
*/
|
|
29
|
+
x: string;
|
|
30
|
+
/**
|
|
31
|
+
* - The y offset.
|
|
32
|
+
*/
|
|
33
|
+
y: string;
|
|
34
|
+
};
|
|
35
|
+
export type Price = {
|
|
36
|
+
/**
|
|
37
|
+
* - The condition of the book.
|
|
38
|
+
*/
|
|
39
|
+
condition: string;
|
|
40
|
+
/**
|
|
41
|
+
* - The merchant selling the book.
|
|
42
|
+
*/
|
|
43
|
+
merchant: string;
|
|
44
|
+
/**
|
|
45
|
+
* - The logo of the merchant.
|
|
46
|
+
*/
|
|
47
|
+
merchant_logo: string;
|
|
48
|
+
/**
|
|
49
|
+
* - The offset of the merchant logo.
|
|
50
|
+
*/
|
|
51
|
+
merchant_logo_offset: Offset;
|
|
52
|
+
/**
|
|
53
|
+
* - The shipping cost.
|
|
54
|
+
*/
|
|
55
|
+
shipping: string;
|
|
56
|
+
/**
|
|
57
|
+
* - The price of the book.
|
|
58
|
+
*/
|
|
59
|
+
price: string;
|
|
60
|
+
/**
|
|
61
|
+
* - The total cost.
|
|
62
|
+
*/
|
|
63
|
+
total: string;
|
|
64
|
+
/**
|
|
65
|
+
* - The link to buy the book.
|
|
66
|
+
*/
|
|
67
|
+
link: string;
|
|
68
|
+
};
|
|
69
|
+
export type OtherIsbn = {
|
|
70
|
+
/**
|
|
71
|
+
* - The ISBN of the book.
|
|
72
|
+
*/
|
|
73
|
+
isbn: string;
|
|
74
|
+
/**
|
|
75
|
+
* - The binding of the book.
|
|
76
|
+
*/
|
|
77
|
+
binding: string;
|
|
78
|
+
};
|
|
79
|
+
export type IsbnDbBook = {
|
|
80
|
+
/**
|
|
81
|
+
* - The title of the book.
|
|
82
|
+
*/
|
|
83
|
+
title: string;
|
|
84
|
+
/**
|
|
85
|
+
* - The long title of the book.
|
|
86
|
+
*/
|
|
87
|
+
title_long: string;
|
|
88
|
+
/**
|
|
89
|
+
* - The ISBN of the book.
|
|
90
|
+
*/
|
|
91
|
+
isbn: string;
|
|
92
|
+
/**
|
|
93
|
+
* - The ISBN13 of the book.
|
|
94
|
+
*/
|
|
95
|
+
isbn13: string;
|
|
96
|
+
/**
|
|
97
|
+
* - The Dewey Decimal classification of the book.
|
|
98
|
+
*/
|
|
99
|
+
dewey_decimal: string;
|
|
100
|
+
/**
|
|
101
|
+
* - The binding of the book.
|
|
102
|
+
*/
|
|
103
|
+
binding: string;
|
|
104
|
+
/**
|
|
105
|
+
* - The publisher of the book.
|
|
106
|
+
*/
|
|
107
|
+
publisher: string;
|
|
108
|
+
/**
|
|
109
|
+
* - The language of the book.
|
|
110
|
+
*/
|
|
111
|
+
language: string;
|
|
112
|
+
/**
|
|
113
|
+
* - The published date of the book.
|
|
114
|
+
*/
|
|
115
|
+
date_published: string;
|
|
116
|
+
/**
|
|
117
|
+
* - The edition of the book.
|
|
118
|
+
*/
|
|
119
|
+
edition: string;
|
|
120
|
+
/**
|
|
121
|
+
* - The number of pages in the book.
|
|
122
|
+
*/
|
|
123
|
+
pages: number;
|
|
124
|
+
/**
|
|
125
|
+
* - The dimensions of the book.
|
|
126
|
+
*/
|
|
127
|
+
dimensions: string;
|
|
128
|
+
/**
|
|
129
|
+
* - The structured dimensions of the book.
|
|
130
|
+
*/
|
|
131
|
+
dimensions_structured: {
|
|
132
|
+
length: Dimension;
|
|
133
|
+
width: Dimension;
|
|
134
|
+
height: Dimension;
|
|
135
|
+
weight: Dimension;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* - The overview of the book.
|
|
139
|
+
*/
|
|
140
|
+
overview: string;
|
|
141
|
+
/**
|
|
142
|
+
* - The image link of the book.
|
|
143
|
+
*/
|
|
144
|
+
image: string;
|
|
145
|
+
/**
|
|
146
|
+
* - The manufacturer's suggested retail price of the book.
|
|
147
|
+
*/
|
|
148
|
+
msrp: number;
|
|
149
|
+
/**
|
|
150
|
+
* - The excerpt of the book.
|
|
151
|
+
*/
|
|
152
|
+
excerpt: string;
|
|
153
|
+
/**
|
|
154
|
+
* - The synopsis of the book.
|
|
155
|
+
*/
|
|
156
|
+
synopsis: string;
|
|
157
|
+
/**
|
|
158
|
+
* - The authors of the book.
|
|
159
|
+
*/
|
|
160
|
+
authors: string[];
|
|
161
|
+
/**
|
|
162
|
+
* - The subjects or categories of the book.
|
|
163
|
+
*/
|
|
164
|
+
subjects: string[];
|
|
165
|
+
/**
|
|
166
|
+
* - The reviews of the book.
|
|
167
|
+
*/
|
|
168
|
+
reviews: string[];
|
|
169
|
+
/**
|
|
170
|
+
* - The prices of the book.
|
|
171
|
+
*/
|
|
172
|
+
prices: Price[];
|
|
173
|
+
/**
|
|
174
|
+
* - The related books.
|
|
175
|
+
*/
|
|
176
|
+
related: {
|
|
177
|
+
type: string;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* - The other ISBNs of the book.
|
|
181
|
+
*/
|
|
182
|
+
other_isbns: OtherIsbn[];
|
|
183
|
+
};
|
|
184
|
+
//# sourceMappingURL=isbndb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isbndb.d.ts","sourceRoot":"","sources":["isbndb.js"],"names":[],"mappings":"AAOA;;;GAGG;AAEH;;;;;;GAMG;AACH,oCALW,MAAM,WACN,kBAAkB,GAChB,QAAQ,IAAI,CAAC,CA6BzB;mBArCY,OAAO,aAAa,EAAE,IAAI;iCAC1B,OAAO,OAAO,EAAE,kBAAkB;;;;;UAwCjC,MAAM;;;;WACN,MAAM;;;;;;OAKN,MAAM;;;;OACN,MAAM;;;;;;eAKN,MAAM;;;;cACN,MAAM;;;;mBACN,MAAM;;;;0BACN,MAAM;;;;cACN,MAAM;;;;WACN,MAAM;;;;WACN,MAAM;;;;UACN,MAAM;;;;;;UAKN,MAAM;;;;aACN,MAAM;;;;;;WAKN,MAAM;;;;gBACN,MAAM;;;;UACN,MAAM;;;;YACN,MAAM;;;;mBACN,MAAM;;;;aACN,MAAM;;;;eACN,MAAM;;;;cACN,MAAM;;;;oBACN,MAAM;;;;aACN,MAAM;;;;WACN,MAAM;;;;gBACN,MAAM;;;;;QAE2B,MAAM,EAAvC,SAAS;QACwB,KAAK,EAAtC,SAAS;QACwB,MAAM,EAAvC,SAAS;QACwB,MAAM,EAAvC,SAAS;;;;;cACT,MAAM;;;;WACN,MAAM;;;;UACN,MAAM;;;;aACN,MAAM;;;;cACN,MAAM;;;;aACN,MAAM,EAAE;;;;cACR,MAAM,EAAE;;;;aACR,MAAM,EAAE;;;;YACR,KAAK,EAAE;;;;;QAES,IAAI,EAApB,MAAM;;;;;iBACN,SAAS,EAAE"}
|
package/src/providers/isbndb.js
CHANGED
|
@@ -5,56 +5,124 @@ import {
|
|
|
5
5
|
ISBNDB_API_BOOK,
|
|
6
6
|
} from "../provider-resolvers.js";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {import('../index.js').Book} Book
|
|
10
|
+
* @typedef {import('axios').AxiosRequestConfig} AxiosRequestConfig
|
|
11
|
+
*/
|
|
12
|
+
|
|
8
13
|
/**
|
|
9
14
|
* Resolves the ISBN using the ISBNdb API.
|
|
10
15
|
* @param {string} isbn - The ISBN to resolve.
|
|
11
|
-
* @param {
|
|
12
|
-
* @returns {Promise<
|
|
16
|
+
* @param {AxiosRequestConfig} options - Additional options for the request.
|
|
17
|
+
* @returns {Promise<Book>} - A promise that resolves to the standardized book data.
|
|
13
18
|
* @throws {Error} - If the response code is not 200 or if no books are found with the given ISBN.
|
|
14
19
|
*/
|
|
15
20
|
export async function resolveIsbnDb(isbn, options) {
|
|
21
|
+
if (!process.env.ISBNDB_API_KEY) {
|
|
22
|
+
throw new Error(`ISBNdb requires an API key`);
|
|
23
|
+
}
|
|
24
|
+
|
|
16
25
|
const requestOptions = {
|
|
17
26
|
...defaultOptions,
|
|
18
27
|
...options,
|
|
19
|
-
|
|
20
|
-
headers: { Authorization: process.env.ISBNDB_API_KEY || "" },
|
|
28
|
+
headers: { Authorization: process.env.ISBNDB_API_KEY },
|
|
21
29
|
};
|
|
22
30
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
const url = `${ISBNDB_API_BASE}${ISBNDB_API_BOOK}/${isbn}`;
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const response = await axios.get(url, requestOptions);
|
|
35
|
+
if (response.status !== 200) {
|
|
36
|
+
throw new Error(`Wrong response code: ${response.status}`);
|
|
37
|
+
}
|
|
38
|
+
const books = response.data;
|
|
39
|
+
if (!books.book) {
|
|
40
|
+
throw new Error(`No books found with ISBN: ${isbn}`);
|
|
41
|
+
}
|
|
42
|
+
return standardize(books.book, isbn);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
throw new Error(error.message);
|
|
32
45
|
}
|
|
33
|
-
return standardize(books.book);
|
|
34
46
|
}
|
|
35
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @typedef {object} Dimension
|
|
50
|
+
* @property {string} unit - The unit of the dimension.
|
|
51
|
+
* @property {number} value - The value of the dimension.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {object} Offset
|
|
56
|
+
* @property {string} x - The x offset.
|
|
57
|
+
* @property {string} y - The y offset.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @typedef {object} Price
|
|
62
|
+
* @property {string} condition - The condition of the book.
|
|
63
|
+
* @property {string} merchant - The merchant selling the book.
|
|
64
|
+
* @property {string} merchant_logo - The logo of the merchant.
|
|
65
|
+
* @property {Offset} merchant_logo_offset - The offset of the merchant logo.
|
|
66
|
+
* @property {string} shipping - The shipping cost.
|
|
67
|
+
* @property {string} price - The price of the book.
|
|
68
|
+
* @property {string} total - The total cost.
|
|
69
|
+
* @property {string} link - The link to buy the book.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @typedef {object} OtherIsbn
|
|
74
|
+
* @property {string} isbn - The ISBN of the book.
|
|
75
|
+
* @property {string} binding - The binding of the book.
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @typedef {object} IsbnDbBook
|
|
80
|
+
* @property {string} title - The title of the book.
|
|
81
|
+
* @property {string} title_long - The long title of the book.
|
|
82
|
+
* @property {string} isbn - The ISBN of the book.
|
|
83
|
+
* @property {string} isbn13 - The ISBN13 of the book.
|
|
84
|
+
* @property {string} dewey_decimal - The Dewey Decimal classification of the book.
|
|
85
|
+
* @property {string} binding - The binding of the book.
|
|
86
|
+
* @property {string} publisher - The publisher of the book.
|
|
87
|
+
* @property {string} language - The language of the book.
|
|
88
|
+
* @property {string} date_published - The published date of the book.
|
|
89
|
+
* @property {string} edition - The edition of the book.
|
|
90
|
+
* @property {number} pages - The number of pages in the book.
|
|
91
|
+
* @property {string} dimensions - The dimensions of the book.
|
|
92
|
+
* @property {object} dimensions_structured - The structured dimensions of the book.
|
|
93
|
+
* @property {Dimension} dimensions_structured.length - The length of the book.
|
|
94
|
+
* @property {Dimension} dimensions_structured.width - The width of the book.
|
|
95
|
+
* @property {Dimension} dimensions_structured.height - The height of the book.
|
|
96
|
+
* @property {Dimension} dimensions_structured.weight - The weight of the book.
|
|
97
|
+
* @property {string} overview - The overview of the book.
|
|
98
|
+
* @property {string} image - The image link of the book.
|
|
99
|
+
* @property {number} msrp - The manufacturer's suggested retail price of the book.
|
|
100
|
+
* @property {string} excerpt - The excerpt of the book.
|
|
101
|
+
* @property {string} synopsis - The synopsis of the book.
|
|
102
|
+
* @property {string[]} authors - The authors of the book.
|
|
103
|
+
* @property {string[]} subjects - The subjects or categories of the book.
|
|
104
|
+
* @property {string[]} reviews - The reviews of the book.
|
|
105
|
+
* @property {Price[]} prices - The prices of the book.
|
|
106
|
+
* @property {object} related - The related books.
|
|
107
|
+
* @property {string} related.type - The type of the related books.
|
|
108
|
+
* @property {OtherIsbn[]} other_isbns - The other ISBNs of the book.
|
|
109
|
+
*/
|
|
110
|
+
|
|
36
111
|
/**
|
|
37
112
|
* Standardizes a book object by transforming its properties into a consistent format.
|
|
38
|
-
* @param {
|
|
39
|
-
* @
|
|
113
|
+
* @param {IsbnDbBook} book - The book object to be standardized.
|
|
114
|
+
* @param {string} isbn - The book's ISBN.
|
|
115
|
+
* @returns {Book} - The standardized book object.
|
|
40
116
|
*/
|
|
41
|
-
function standardize(book) {
|
|
117
|
+
function standardize(book, isbn) {
|
|
42
118
|
return {
|
|
43
119
|
title: book.title_long,
|
|
44
|
-
publishedDate: book.date_published,
|
|
45
120
|
authors: book.authors,
|
|
46
121
|
description: book.overview,
|
|
47
|
-
industryIdentifiers: [book.isbn, book.isbn13, book.dewey_decimal].filter(
|
|
48
|
-
Boolean
|
|
49
|
-
),
|
|
50
122
|
pageCount: book.pages,
|
|
51
123
|
printType: "BOOK",
|
|
52
124
|
categories: book.subjects,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
thumbnail: book.image,
|
|
56
|
-
},
|
|
57
|
-
publisher: book.publisher,
|
|
58
|
-
language: book.language,
|
|
125
|
+
thumbnail: book.image,
|
|
126
|
+
isbn,
|
|
59
127
|
};
|
|
60
128
|
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('../index.js').Book} Book
|
|
3
|
+
* @typedef {import('axios').AxiosRequestConfig} AxiosRequestConfig
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Resolves a book from the Open Library API using the provided ISBN.
|
|
7
|
+
* @param {string} isbn - The ISBN of the book.
|
|
8
|
+
* @param {AxiosRequestConfig} options - Additional options for the request.
|
|
9
|
+
* @returns {Promise<Book>} A promise that resolves to the standardized book object.
|
|
10
|
+
* @throws {Error} If the response code is not 200 or if no books are found with the provided ISBN.
|
|
11
|
+
*/
|
|
12
|
+
export function resolveOpenLibrary(isbn: string, options: AxiosRequestConfig): Promise<Book>;
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {object} Author
|
|
15
|
+
* @property {string} key - The key of the author.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {object} Language
|
|
19
|
+
* @property {string} key - The key of the language.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {object} Type
|
|
23
|
+
* @property {string} key - The key of the type.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {object} FirstSentence
|
|
27
|
+
* @property {string} type - The type of the first sentence.
|
|
28
|
+
* @property {string} value - The value of the first sentence.
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {object} Work
|
|
32
|
+
* @property {string} key - The key of the work.
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {object} DateTime
|
|
36
|
+
* @property {string} type - The type of the datetime.
|
|
37
|
+
* @property {string} value - The value of the datetime.
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* @typedef {object} OpenLibraryBook
|
|
41
|
+
* @property {object} identifiers - The identifiers of the book.
|
|
42
|
+
* @property {string} title - The title of the book.
|
|
43
|
+
* @property {Author[]} authors - The authors of the book.
|
|
44
|
+
* @property {string} publish_date - The publish date of the book.
|
|
45
|
+
* @property {string[]} publishers - The publishers of the book.
|
|
46
|
+
* @property {number[]} covers - The covers of the book.
|
|
47
|
+
* @property {string[]} contributions - The contributions to the book.
|
|
48
|
+
* @property {Language[]} languages - The languages of the book.
|
|
49
|
+
* @property {string[]} source_records - The source records of the book.
|
|
50
|
+
* @property {string[]} local_id - The local IDs of the book.
|
|
51
|
+
* @property {Type} type - The type of the book.
|
|
52
|
+
* @property {FirstSentence} first_sentence - The first sentence of the book.
|
|
53
|
+
* @property {string} key - The key of the book.
|
|
54
|
+
* @property {number} number_of_pages - The number of pages in the book.
|
|
55
|
+
* @property {Work[]} works - The works related to the book.
|
|
56
|
+
* @property {object} classifications - The classifications of the book.
|
|
57
|
+
* @property {string} ocaid - The Open Content Alliance ID of the book.
|
|
58
|
+
* @property {string[]} isbn_10 - The ISBN-10 of the book.
|
|
59
|
+
* @property {string[]} isbn_13 - The ISBN-13 of the book.
|
|
60
|
+
* @property {number} latest_revision - The latest revision of the book.
|
|
61
|
+
* @property {number} revision - The revision of the book.
|
|
62
|
+
* @property {DateTime} created - The creation datetime of the book.
|
|
63
|
+
* @property {DateTime} last_modified - The last modified datetime of the book.
|
|
64
|
+
*/
|
|
65
|
+
/**
|
|
66
|
+
* Standardizes a book object by extracting relevant information from the provided book object.
|
|
67
|
+
* @param {OpenLibraryBook} book - The book object to be standardized.
|
|
68
|
+
* @param {string} isbn - The book's isbn.
|
|
69
|
+
* @returns {Promise<Book>} - The standardized book object.
|
|
70
|
+
*/
|
|
71
|
+
export function standardize(book: OpenLibraryBook, isbn: string): Promise<Book>;
|
|
72
|
+
/**
|
|
73
|
+
* Retrieves the author names from OpenLibrary.
|
|
74
|
+
* @param {{key: string}[]} rawAuthors - List of author keys.
|
|
75
|
+
* @returns {Promise<string[]>} - List of author names.
|
|
76
|
+
*/
|
|
77
|
+
export function getAuthors(rawAuthors: {
|
|
78
|
+
key: string;
|
|
79
|
+
}[]): Promise<string[]>;
|
|
80
|
+
/**
|
|
81
|
+
* @typedef {object} OpenLibraryResponse
|
|
82
|
+
* @property {string} description - The description of the book.
|
|
83
|
+
* @property {string[]} subjects - The subjects of the book.
|
|
84
|
+
* @property {{author: {key: string}}[]} authors - The authors of the book.
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* Retrieves the description of the book from OpenLibrary.
|
|
88
|
+
* @param {OpenLibraryBook} book - The book object from OpenLibrary.
|
|
89
|
+
* @returns {Promise<{description: string, subjects: string[], rawAuthors: {key: string}[]}>} - Description of the book.
|
|
90
|
+
*/
|
|
91
|
+
export function getWorks(book: OpenLibraryBook): Promise<{
|
|
92
|
+
description: string;
|
|
93
|
+
subjects: string[];
|
|
94
|
+
rawAuthors: {
|
|
95
|
+
key: string;
|
|
96
|
+
}[];
|
|
97
|
+
}>;
|
|
98
|
+
export type Book = import('../index.js').Book;
|
|
99
|
+
export type AxiosRequestConfig = import('axios').AxiosRequestConfig;
|
|
100
|
+
export type Author = {
|
|
101
|
+
/**
|
|
102
|
+
* - The key of the author.
|
|
103
|
+
*/
|
|
104
|
+
key: string;
|
|
105
|
+
};
|
|
106
|
+
export type Language = {
|
|
107
|
+
/**
|
|
108
|
+
* - The key of the language.
|
|
109
|
+
*/
|
|
110
|
+
key: string;
|
|
111
|
+
};
|
|
112
|
+
export type Type = {
|
|
113
|
+
/**
|
|
114
|
+
* - The key of the type.
|
|
115
|
+
*/
|
|
116
|
+
key: string;
|
|
117
|
+
};
|
|
118
|
+
export type FirstSentence = {
|
|
119
|
+
/**
|
|
120
|
+
* - The type of the first sentence.
|
|
121
|
+
*/
|
|
122
|
+
type: string;
|
|
123
|
+
/**
|
|
124
|
+
* - The value of the first sentence.
|
|
125
|
+
*/
|
|
126
|
+
value: string;
|
|
127
|
+
};
|
|
128
|
+
export type Work = {
|
|
129
|
+
/**
|
|
130
|
+
* - The key of the work.
|
|
131
|
+
*/
|
|
132
|
+
key: string;
|
|
133
|
+
};
|
|
134
|
+
export type DateTime = {
|
|
135
|
+
/**
|
|
136
|
+
* - The type of the datetime.
|
|
137
|
+
*/
|
|
138
|
+
type: string;
|
|
139
|
+
/**
|
|
140
|
+
* - The value of the datetime.
|
|
141
|
+
*/
|
|
142
|
+
value: string;
|
|
143
|
+
};
|
|
144
|
+
export type OpenLibraryBook = {
|
|
145
|
+
/**
|
|
146
|
+
* - The identifiers of the book.
|
|
147
|
+
*/
|
|
148
|
+
identifiers: object;
|
|
149
|
+
/**
|
|
150
|
+
* - The title of the book.
|
|
151
|
+
*/
|
|
152
|
+
title: string;
|
|
153
|
+
/**
|
|
154
|
+
* - The authors of the book.
|
|
155
|
+
*/
|
|
156
|
+
authors: Author[];
|
|
157
|
+
/**
|
|
158
|
+
* - The publish date of the book.
|
|
159
|
+
*/
|
|
160
|
+
publish_date: string;
|
|
161
|
+
/**
|
|
162
|
+
* - The publishers of the book.
|
|
163
|
+
*/
|
|
164
|
+
publishers: string[];
|
|
165
|
+
/**
|
|
166
|
+
* - The covers of the book.
|
|
167
|
+
*/
|
|
168
|
+
covers: number[];
|
|
169
|
+
/**
|
|
170
|
+
* - The contributions to the book.
|
|
171
|
+
*/
|
|
172
|
+
contributions: string[];
|
|
173
|
+
/**
|
|
174
|
+
* - The languages of the book.
|
|
175
|
+
*/
|
|
176
|
+
languages: Language[];
|
|
177
|
+
/**
|
|
178
|
+
* - The source records of the book.
|
|
179
|
+
*/
|
|
180
|
+
source_records: string[];
|
|
181
|
+
/**
|
|
182
|
+
* - The local IDs of the book.
|
|
183
|
+
*/
|
|
184
|
+
local_id: string[];
|
|
185
|
+
/**
|
|
186
|
+
* - The type of the book.
|
|
187
|
+
*/
|
|
188
|
+
type: Type;
|
|
189
|
+
/**
|
|
190
|
+
* - The first sentence of the book.
|
|
191
|
+
*/
|
|
192
|
+
first_sentence: FirstSentence;
|
|
193
|
+
/**
|
|
194
|
+
* - The key of the book.
|
|
195
|
+
*/
|
|
196
|
+
key: string;
|
|
197
|
+
/**
|
|
198
|
+
* - The number of pages in the book.
|
|
199
|
+
*/
|
|
200
|
+
number_of_pages: number;
|
|
201
|
+
/**
|
|
202
|
+
* - The works related to the book.
|
|
203
|
+
*/
|
|
204
|
+
works: Work[];
|
|
205
|
+
/**
|
|
206
|
+
* - The classifications of the book.
|
|
207
|
+
*/
|
|
208
|
+
classifications: object;
|
|
209
|
+
/**
|
|
210
|
+
* - The Open Content Alliance ID of the book.
|
|
211
|
+
*/
|
|
212
|
+
ocaid: string;
|
|
213
|
+
/**
|
|
214
|
+
* - The ISBN-10 of the book.
|
|
215
|
+
*/
|
|
216
|
+
isbn_10: string[];
|
|
217
|
+
/**
|
|
218
|
+
* - The ISBN-13 of the book.
|
|
219
|
+
*/
|
|
220
|
+
isbn_13: string[];
|
|
221
|
+
/**
|
|
222
|
+
* - The latest revision of the book.
|
|
223
|
+
*/
|
|
224
|
+
latest_revision: number;
|
|
225
|
+
/**
|
|
226
|
+
* - The revision of the book.
|
|
227
|
+
*/
|
|
228
|
+
revision: number;
|
|
229
|
+
/**
|
|
230
|
+
* - The creation datetime of the book.
|
|
231
|
+
*/
|
|
232
|
+
created: DateTime;
|
|
233
|
+
/**
|
|
234
|
+
* - The last modified datetime of the book.
|
|
235
|
+
*/
|
|
236
|
+
last_modified: DateTime;
|
|
237
|
+
};
|
|
238
|
+
export type OpenLibraryResponse = {
|
|
239
|
+
/**
|
|
240
|
+
* - The description of the book.
|
|
241
|
+
*/
|
|
242
|
+
description: string;
|
|
243
|
+
/**
|
|
244
|
+
* - The subjects of the book.
|
|
245
|
+
*/
|
|
246
|
+
subjects: string[];
|
|
247
|
+
/**
|
|
248
|
+
* - The authors of the book.
|
|
249
|
+
*/
|
|
250
|
+
authors: {
|
|
251
|
+
author: {
|
|
252
|
+
key: string;
|
|
253
|
+
};
|
|
254
|
+
}[];
|
|
255
|
+
};
|
|
256
|
+
//# sourceMappingURL=open-library.d.ts.map
|