discogs-marketplace-api-nodejs 1.18.1 → 1.18.3
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 +18 -6
- package/dist/data/country.data.d.ts +4 -4
- package/dist/data/country.data.js +5 -5
- package/dist/interfaces/search-params.interface.d.ts +1 -1
- package/dist/interfaces/search-result.interface.d.ts +2 -2
- package/dist/scrapers/marketplace.scraper.d.ts +1 -1
- package/dist/scrapers/marketplace.scraper.js +28 -21
- package/dist/wantlist.d.ts +4 -0
- package/dist/wantlist.js +4 -1
- package/package.json +14 -18
package/README.MD
CHANGED
|
@@ -170,25 +170,37 @@ await context.close()
|
|
|
170
170
|
`XAUTHORITY`...), and its language with `LANG` rather than the `locale` option.
|
|
171
171
|
- **Still blocked?** The IP is the problem: go through a residential proxy (`proxy` option).
|
|
172
172
|
|
|
173
|
-
On a server, headful Chrome needs a display: run your app under Xvfb (`xvfb-run -a node index.js`). With Docker
|
|
173
|
+
On a server, headful Chrome needs a display: run your app under Xvfb (`xvfb-run -a node index.js`). With Docker, start
|
|
174
|
+
Xvfb from an entrypoint that then `exec`s your app, so that it gets the stop signal:
|
|
174
175
|
|
|
175
176
|
```dockerfile
|
|
176
177
|
FROM node:24-slim
|
|
177
178
|
|
|
178
179
|
RUN apt-get update \
|
|
179
|
-
&& apt-get install -y --no-install-recommends ca-certificates curl tini
|
|
180
|
+
&& apt-get install -y --no-install-recommends ca-certificates curl tini xvfb \
|
|
180
181
|
&& rm -rf /var/lib/apt/lists/*
|
|
181
182
|
|
|
183
|
+
ENV DISPLAY=:99
|
|
184
|
+
|
|
182
185
|
WORKDIR /app
|
|
183
186
|
COPY package*.json ./
|
|
184
187
|
RUN npm ci && npx patchright install --with-deps chrome
|
|
185
188
|
COPY . .
|
|
186
189
|
|
|
187
|
-
|
|
188
|
-
ENTRYPOINT ["/usr/bin/tini", "-g", "--", "xvfb-run", "-a"]
|
|
190
|
+
ENTRYPOINT ["/usr/bin/tini", "--", "sh", "/app/entrypoint.sh"]
|
|
189
191
|
CMD ["node", "index.js"]
|
|
190
192
|
```
|
|
191
193
|
|
|
194
|
+
```sh
|
|
195
|
+
# entrypoint.sh
|
|
196
|
+
Xvfb "$DISPLAY" -screen 0 1280x1024x24 -ac -nolisten tcp >/dev/null 2>&1 &
|
|
197
|
+
|
|
198
|
+
# Wait for the display, 6 seconds at most
|
|
199
|
+
for i in $(seq 30); do [ -e "/tmp/.X11-unix/X${DISPLAY#:}" ] && break; sleep 0.2; done
|
|
200
|
+
|
|
201
|
+
exec "$@"
|
|
202
|
+
```
|
|
203
|
+
|
|
192
204
|
## API Reference
|
|
193
205
|
|
|
194
206
|
### `DiscogsMarketplace.search(searchParams, browserContext?)`
|
|
@@ -209,7 +221,7 @@ CMD ["node", "index.js"]
|
|
|
209
221
|
| `sleeveConditions` | `SleeveCondition[]` | Filter by sleeve conditions. | `['Mint (M)', 'Generic']` | – |
|
|
210
222
|
| `from` | `From[]` | Filter by seller’s countries. | `['FR', 'DE']` | – |
|
|
211
223
|
| `currencies` | `Currency[]` | Filter by currencies. | `['USD', 'EUR']` | – |
|
|
212
|
-
| `priceRange.min`/`max` | `number` | Filter by price range.
|
|
224
|
+
| `priceRange.min`/`max` | `number` | Filter by price range, in US dollars. | `{ min: 10, max: 100 }` | – |
|
|
213
225
|
| `years.min`/`max` | `number` | Filter by year range. | `{ min: 1980, max: 1990 }` | – |
|
|
214
226
|
| `sellerRatingMin` | `number (0–100)` | Minimum seller rating (unrated sellers kept). | `99` | `0` |
|
|
215
227
|
| `sellerRatingCountMin` | `number` | Minimum number of seller ratings. | `50` | `0` |
|
|
@@ -286,7 +298,7 @@ interface SearchResult {
|
|
|
286
298
|
country: {
|
|
287
299
|
name: string
|
|
288
300
|
/** @example 'US' */
|
|
289
|
-
code: CountryValues
|
|
301
|
+
code: CountryValues | null
|
|
290
302
|
}
|
|
291
303
|
community: {
|
|
292
304
|
have: number
|
|
@@ -9,7 +9,7 @@ declare const Country: {
|
|
|
9
9
|
readonly 'Former Czechoslovakia': "CZ";
|
|
10
10
|
readonly 'Former USSR': "RU";
|
|
11
11
|
readonly 'France (European Territory)': "FR";
|
|
12
|
-
readonly 'French Guyana': "
|
|
12
|
+
readonly 'French Guyana': "GF";
|
|
13
13
|
readonly 'Guadeloupe (French)': "GP";
|
|
14
14
|
readonly 'Guam (USA)': "GU";
|
|
15
15
|
readonly 'Guinea Bissau': "GW";
|
|
@@ -34,7 +34,7 @@ declare const Country: {
|
|
|
34
34
|
readonly 'Saint Vincent & Grenadines': "VC";
|
|
35
35
|
readonly 'Slovak Republic': "SK";
|
|
36
36
|
readonly 'South Korea': "KR";
|
|
37
|
-
readonly 'Spain (Canary Islands)': "
|
|
37
|
+
readonly 'Spain (Canary Islands)': "ES";
|
|
38
38
|
readonly 'Svalbard and Jan Mayen Islands': "SJ";
|
|
39
39
|
readonly Swaziland: "SZ";
|
|
40
40
|
readonly Syria: "SY";
|
|
@@ -43,7 +43,7 @@ declare const Country: {
|
|
|
43
43
|
readonly Tanzania: "TZ";
|
|
44
44
|
readonly 'United Kingdom': "GB";
|
|
45
45
|
readonly 'Northern Ireland': "GB";
|
|
46
|
-
readonly 'United Kingdom (Channel Islands)': "";
|
|
46
|
+
readonly 'United Kingdom (Channel Islands)': "GB";
|
|
47
47
|
readonly 'United States': "US";
|
|
48
48
|
readonly 'USA Minor Outlying Islands': "UM";
|
|
49
49
|
readonly 'Vatican City State': "VA";
|
|
@@ -51,7 +51,7 @@ declare const Country: {
|
|
|
51
51
|
readonly Vietnam: "VN";
|
|
52
52
|
readonly 'Virgin Islands (USA)': "VI";
|
|
53
53
|
readonly 'Wallis and Futuna Islands': "WF";
|
|
54
|
-
readonly Yugoslavia: "
|
|
54
|
+
readonly Yugoslavia: "RS";
|
|
55
55
|
readonly Zaire: "CD";
|
|
56
56
|
readonly Afghanistan: "AF";
|
|
57
57
|
readonly '\u00C5land Islands': "AX";
|
|
@@ -279,7 +279,7 @@ const CountryDiscogs = {
|
|
|
279
279
|
'Former Czechoslovakia': 'CZ',
|
|
280
280
|
'Former USSR': 'RU',
|
|
281
281
|
'France (European Territory)': 'FR',
|
|
282
|
-
'French Guyana': '
|
|
282
|
+
'French Guyana': 'GF',
|
|
283
283
|
'Guadeloupe (French)': 'GP',
|
|
284
284
|
'Guam (USA)': 'GU',
|
|
285
285
|
'Guinea Bissau': 'GW',
|
|
@@ -296,7 +296,7 @@ const CountryDiscogs = {
|
|
|
296
296
|
'New Caledonia (French)': 'NC',
|
|
297
297
|
'Pitcairn Island': 'PN',
|
|
298
298
|
'Polynesia (French)': 'PF',
|
|
299
|
-
'Reunion (French)': 'RE',
|
|
299
|
+
'Reunion (French)': 'RE',
|
|
300
300
|
'S. Georgia & S. Sandwich Isls.': 'GS',
|
|
301
301
|
'Saint Helena': 'SH',
|
|
302
302
|
'Saint Kitts & Nevis Anguilla': 'KN',
|
|
@@ -304,7 +304,7 @@ const CountryDiscogs = {
|
|
|
304
304
|
'Saint Vincent & Grenadines': 'VC',
|
|
305
305
|
'Slovak Republic': 'SK',
|
|
306
306
|
'South Korea': 'KR',
|
|
307
|
-
'Spain (Canary Islands)': '
|
|
307
|
+
'Spain (Canary Islands)': 'ES',
|
|
308
308
|
'Svalbard and Jan Mayen Islands': 'SJ',
|
|
309
309
|
Swaziland: 'SZ',
|
|
310
310
|
Syria: 'SY',
|
|
@@ -313,7 +313,7 @@ const CountryDiscogs = {
|
|
|
313
313
|
Tanzania: 'TZ',
|
|
314
314
|
'United Kingdom': 'GB',
|
|
315
315
|
'Northern Ireland': 'GB',
|
|
316
|
-
'United Kingdom (Channel Islands)': '',
|
|
316
|
+
'United Kingdom (Channel Islands)': 'GB',
|
|
317
317
|
'United States': 'US',
|
|
318
318
|
'USA Minor Outlying Islands': 'UM',
|
|
319
319
|
'Vatican City State': 'VA',
|
|
@@ -321,7 +321,7 @@ const CountryDiscogs = {
|
|
|
321
321
|
Vietnam: 'VN',
|
|
322
322
|
'Virgin Islands (USA)': 'VI',
|
|
323
323
|
'Wallis and Futuna Islands': 'WF',
|
|
324
|
-
Yugoslavia: '
|
|
324
|
+
Yugoslavia: 'RS',
|
|
325
325
|
Zaire: 'CD',
|
|
326
326
|
};
|
|
327
327
|
const Country = {
|
|
@@ -36,7 +36,7 @@ export default interface SearchResult {
|
|
|
36
36
|
};
|
|
37
37
|
/** List of formats */
|
|
38
38
|
formats: Array<string>;
|
|
39
|
-
/**
|
|
39
|
+
/** Labels */
|
|
40
40
|
labels: Array<{
|
|
41
41
|
/** Label ID */
|
|
42
42
|
id: number;
|
|
@@ -114,7 +114,7 @@ export default interface SearchResult {
|
|
|
114
114
|
* ISO country code
|
|
115
115
|
* @example 'US'
|
|
116
116
|
*/
|
|
117
|
-
code: CountryValues;
|
|
117
|
+
code: CountryValues | null;
|
|
118
118
|
};
|
|
119
119
|
/** Community stats */
|
|
120
120
|
community: {
|
|
@@ -7,4 +7,4 @@ import type { BrowserContext } from 'patchright';
|
|
|
7
7
|
* @param browserContext Patchright browser context
|
|
8
8
|
* @returns Items found, total, next cursor and url of the same search on Discogs
|
|
9
9
|
*/
|
|
10
|
-
export default function scrapeMarketplace(
|
|
10
|
+
export default function scrapeMarketplace(searchParams: SearchParams, browserContext: BrowserContext): Promise<SearchResult>;
|
|
@@ -91,12 +91,13 @@ async function queryGraphql(page, operationName, variables) {
|
|
|
91
91
|
response = await run();
|
|
92
92
|
}
|
|
93
93
|
const { status, cfMitigated, cfRay, json } = response;
|
|
94
|
+
// eslint-disable-next-line typescript/no-unsafe-type-assertion -- The GraphQL answer has the shape of the query it answers, which the caller names
|
|
94
95
|
const result = json;
|
|
95
96
|
if (cfMitigated) {
|
|
96
97
|
throw new Error(`An error ${status} occurred: blocked by Cloudflare (${cfMitigated}, cf-ray ${cfRay ?? '?'}).`);
|
|
97
98
|
}
|
|
98
99
|
if (!result?.data) {
|
|
99
|
-
// eslint-disable-next-line
|
|
100
|
+
// eslint-disable-next-line typescript/prefer-nullish-coalescing -- An empty list of errors joins into an empty message, which falls back too
|
|
100
101
|
throw new Error(result?.errors?.map(x => x.message).join(', ') || `An error ${status} occurred.`);
|
|
101
102
|
}
|
|
102
103
|
return result;
|
|
@@ -109,6 +110,7 @@ async function queryGraphql(page, operationName, variables) {
|
|
|
109
110
|
* @returns Price
|
|
110
111
|
*/
|
|
111
112
|
function formatPrice(price) {
|
|
113
|
+
// eslint-disable-next-line typescript/no-unsafe-type-assertion -- toFixed keeps the trailing zeros, which the `${number}` of the return type cannot express
|
|
112
114
|
return `${price?.currency === 'JPY' ? (price.amount ?? 0) : (price?.amount ?? 0).toFixed(2)} ${price?.currency ?? ''}`;
|
|
113
115
|
}
|
|
114
116
|
/**
|
|
@@ -121,7 +123,7 @@ function toCondition(value) {
|
|
|
121
123
|
return { full, short: /\(([^)]+)\)/.exec(full ?? '')?.[1] ?? null };
|
|
122
124
|
}
|
|
123
125
|
/** HTML entities the notes of the sellers can hold, besides the numeric ones */
|
|
124
|
-
const HTML_ENTITIES = { quot: '"', apos: "'", lt: '<', gt: '>', nbsp: '\
|
|
126
|
+
const HTML_ENTITIES = { quot: '"', apos: "'", lt: '<', gt: '>', nbsp: '\u00A0' }; // cspell: disable-line
|
|
125
127
|
/**
|
|
126
128
|
* Decode the HTML entities of a text, as the notes of the sellers come HTML escaped
|
|
127
129
|
* @param text Text
|
|
@@ -129,10 +131,10 @@ const HTML_ENTITIES = { quot: '"', apos: "'", lt: '<', gt: '>', nbsp: '\u00a0' }
|
|
|
129
131
|
*/
|
|
130
132
|
function decodeHtmlEntities(text) {
|
|
131
133
|
return text
|
|
132
|
-
.
|
|
133
|
-
.
|
|
134
|
-
.
|
|
135
|
-
.
|
|
134
|
+
.replaceAll(/&#(\d+);/g, (_, code) => String.fromCodePoint(Number(code)))
|
|
135
|
+
.replaceAll(/&#x([\da-f]+);/gi, (_, code) => String.fromCodePoint(parseInt(code, 16)))
|
|
136
|
+
.replaceAll(new RegExp(`&(${Object.keys(HTML_ENTITIES).join('|')});`, 'g'), (_, name) => HTML_ENTITIES[name] ?? '')
|
|
137
|
+
.replaceAll('&', '&');
|
|
136
138
|
}
|
|
137
139
|
/**
|
|
138
140
|
* Searches the listings through the `MarketplaceSearch` GraphQL query of the Discogs shop.
|
|
@@ -140,14 +142,17 @@ function decodeHtmlEntities(text) {
|
|
|
140
142
|
* @param browserContext Patchright browser context
|
|
141
143
|
* @returns Items found, total, next cursor and url of the same search on Discogs
|
|
142
144
|
*/
|
|
143
|
-
async function scrapeMarketplace(
|
|
145
|
+
async function scrapeMarketplace(searchParams, browserContext) {
|
|
146
|
+
const { query, artistIds, labelIds, masterIds, releaseIds, sellerIds, genres, styles, formats, formatDescriptions, mediaConditions, sleeveConditions, from, currencies, priceRange, sellerRatingMin, sellerRatingCountMin, years, isMakeAnOfferOnly = false, hasItemPhotos = false, hideGenericSleeves = false, hideSleevelessMedia = false, showUnavailable = true, withCommunityStats = true, sort = 'listed,desc', limit = 25, after, } = searchParams;
|
|
144
147
|
const [sortField = 'listed', sortOrder = 'desc'] = sort.split(',');
|
|
145
148
|
const countries = from?.flatMap(code => {
|
|
146
|
-
const names = Object.
|
|
147
|
-
|
|
149
|
+
const names = Object.entries(country_data_1.default)
|
|
150
|
+
.filter(([, value]) => value === code)
|
|
151
|
+
.map(([key]) => key);
|
|
152
|
+
return names.length > 0 ? names : [code];
|
|
148
153
|
});
|
|
149
154
|
const styleIds = styles?.flatMap(name => {
|
|
150
|
-
const ids = style_data_1.default
|
|
155
|
+
const ids = new Map(Object.entries(style_data_1.default)).get(name);
|
|
151
156
|
return ids ? [ids] : [];
|
|
152
157
|
}) ?? [];
|
|
153
158
|
/** Url of the same search on the Discogs shop */
|
|
@@ -198,8 +203,8 @@ async function scrapeMarketplace({ query, artistIds, labelIds, masterIds, releas
|
|
|
198
203
|
seller: sellerIds,
|
|
199
204
|
genre: genres,
|
|
200
205
|
genreAnd: genres?.length ? true : undefined,
|
|
201
|
-
styleId: styleIds.length ? [...new Set(styleIds.flat())] : undefined,
|
|
202
|
-
styleIdAnd: styleIds.length ? styleIds.every(x => x.length === 1) : undefined,
|
|
206
|
+
styleId: styleIds.length > 0 ? [...new Set(styleIds.flat())] : undefined,
|
|
207
|
+
styleIdAnd: styleIds.length > 0 ? styleIds.every(x => x.length === 1) : undefined,
|
|
203
208
|
formatName: formats,
|
|
204
209
|
formatNameAnd: formats?.length ? true : undefined,
|
|
205
210
|
formatDescription: formatDescriptions,
|
|
@@ -219,10 +224,11 @@ async function scrapeMarketplace({ query, artistIds, labelIds, masterIds, releas
|
|
|
219
224
|
hideGenericSleeves: hideGenericSleeves || undefined,
|
|
220
225
|
hideSleevelessMedia: hideSleevelessMedia || undefined,
|
|
221
226
|
showUnavailable: showUnavailable || undefined,
|
|
222
|
-
}).filter(([, x]) => x !== undefined && !(Array.isArray(x) &&
|
|
227
|
+
}).filter(([, x]) => x !== undefined && !(Array.isArray(x) && x.length === 0)));
|
|
223
228
|
const result = (await queryGraphql(browserPage, 'MarketplaceSearch', {
|
|
224
|
-
|
|
225
|
-
|
|
229
|
+
// eslint-disable-next-line typescript/prefer-nullish-coalescing -- An empty query searches everything, as no query
|
|
230
|
+
query: query || undefined,
|
|
231
|
+
filter: Object.keys(filter).length > 0 ? filter : undefined,
|
|
226
232
|
sort: {
|
|
227
233
|
dimension: SORT_DIMENSIONS[sortField] ?? SORT_DIMENSIONS.listed,
|
|
228
234
|
direction: sortOrder === 'asc' ? 'ASCENDING' : 'DESCENDING',
|
|
@@ -233,10 +239,10 @@ async function scrapeMarketplace({ query, artistIds, labelIds, masterIds, releas
|
|
|
233
239
|
const nodes = result?.edges?.map(x => x.node ?? {}) ?? [];
|
|
234
240
|
// The community stats and the rating of the releases are not part of the listings
|
|
235
241
|
const releaseIdsFound = withCommunityStats ? [...new Set(nodes.map(x => x.release?.discogsId ?? 0).filter(x => !!x))] : [];
|
|
236
|
-
const { data: details } = releaseIdsFound.length
|
|
242
|
+
const { data: details } = releaseIdsFound.length > 0
|
|
237
243
|
? await queryGraphql(browserPage, 'Releases', { discogsIds: releaseIdsFound, first: 1 })
|
|
238
244
|
: { data: undefined };
|
|
239
|
-
const releaseDetails = new Map(details?.releases?.map(x => [x?.discogsId ?? 0, x])
|
|
245
|
+
const releaseDetails = new Map(details?.releases?.map(x => [x?.discogsId ?? 0, x]));
|
|
240
246
|
const items = nodes.map(node => {
|
|
241
247
|
const release = node.release ?? {};
|
|
242
248
|
const artists = release.primaryArtists ?? [];
|
|
@@ -259,7 +265,8 @@ async function scrapeMarketplace({ query, artistIds, labelIds, masterIds, releas
|
|
|
259
265
|
url: `https://www.discogs.com/release/${release.discogsId ?? 0}`,
|
|
260
266
|
year: year || null,
|
|
261
267
|
country: release.country ?? null,
|
|
262
|
-
|
|
268
|
+
// eslint-disable-next-line typescript/prefer-nullish-coalescing -- A release without votes has a 0 average, shown as no rating
|
|
269
|
+
rating: releaseDetail?.ratings?.averageRating || null,
|
|
263
270
|
},
|
|
264
271
|
formats: [
|
|
265
272
|
...new Set([
|
|
@@ -277,7 +284,7 @@ async function scrapeMarketplace({ query, artistIds, labelIds, masterIds, releas
|
|
|
277
284
|
listedAt: node.listedDate ? new Date(node.listedDate) : null,
|
|
278
285
|
catnos: labels.map(x => x.catalogNumber ?? '').filter(x => !!x),
|
|
279
286
|
imageUrl: release.images?.edges?.[0]?.node?.thumbnail?.webpUrl ?? null,
|
|
280
|
-
photos:
|
|
287
|
+
photos: (node.itemPhotos ?? []).toSorted((a, b) => (a.position ?? 0) - (b.position ?? 0)).map(x => x.url ?? ''),
|
|
281
288
|
description: node.publicNotes ? decodeHtmlEntities(node.publicNotes) : null,
|
|
282
289
|
isAcceptingOffer: node.offerOk ?? false,
|
|
283
290
|
isAvailable: node.availability?.isAvailable ?? true,
|
|
@@ -299,7 +306,7 @@ async function scrapeMarketplace({ query, artistIds, labelIds, masterIds, releas
|
|
|
299
306
|
},
|
|
300
307
|
country: {
|
|
301
308
|
name: node.sellerInfo?.shipsFrom ?? '',
|
|
302
|
-
code: country_data_1.default[node.sellerInfo?.shipsFrom],
|
|
309
|
+
code: country_data_1.default[node.sellerInfo?.shipsFrom ?? ''] ?? null,
|
|
303
310
|
},
|
|
304
311
|
community: {
|
|
305
312
|
have: releaseDetail?.inCollectionCount ?? 0,
|
|
@@ -310,7 +317,7 @@ async function scrapeMarketplace({ query, artistIds, labelIds, masterIds, releas
|
|
|
310
317
|
return {
|
|
311
318
|
items,
|
|
312
319
|
total: result?.totalCount ?? 0,
|
|
313
|
-
// eslint-disable-next-line
|
|
320
|
+
// eslint-disable-next-line typescript/prefer-nullish-coalescing -- No next page or an empty cursor both mean the last page
|
|
314
321
|
nextCursor: (result?.pageInfo?.hasNextPage && result.pageInfo.endCursor) || null,
|
|
315
322
|
urlGenerated,
|
|
316
323
|
};
|
package/dist/wantlist.d.ts
CHANGED
|
@@ -8,8 +8,10 @@ export type WantlistOptions = {
|
|
|
8
8
|
* @see {@link https://www.discogs.com/settings/developers}
|
|
9
9
|
*/
|
|
10
10
|
token?: string;
|
|
11
|
+
/** Not with `token`: the public wantlist page is read without one */
|
|
11
12
|
onlyForSale?: never;
|
|
12
13
|
} | {
|
|
14
|
+
/** Not with `onlyForSale`: the token only serves the API */
|
|
13
15
|
token?: never;
|
|
14
16
|
/**
|
|
15
17
|
* If true, only the releases currently for sale are returned, read from the public wantlist page with a browser.
|
|
@@ -22,6 +24,8 @@ export type WantlistOptions = {
|
|
|
22
24
|
* By default, it reads the public Discogs API (limited to 25 requests per minute without token, 60 with).
|
|
23
25
|
* @param username - Username whose wantlist is read.
|
|
24
26
|
* @param options - Options.
|
|
27
|
+
* @param options.token - Discogs personal access token, for the API.
|
|
28
|
+
* @param options.onlyForSale - Whether to keep only the releases for sale, read from the public wantlist page.
|
|
25
29
|
* @param browserContext - Optional Patchright browser context, only used with `onlyForSale`. If provided, you must manage its lifecycle.
|
|
26
30
|
* @returns A promise that resolves to the release IDs.
|
|
27
31
|
*/
|
package/dist/wantlist.js
CHANGED
|
@@ -38,6 +38,7 @@ function fetchWantlist(username, token) {
|
|
|
38
38
|
...(token ? { Authorization: `Discogs token=${token}` } : {}),
|
|
39
39
|
},
|
|
40
40
|
});
|
|
41
|
+
// eslint-disable-next-line typescript/no-unsafe-type-assertion -- The Discogs API answer is trusted as documented, a library keeping no schema dependency
|
|
41
42
|
const json = (await response.json().catch(() => null));
|
|
42
43
|
if (!response.ok) {
|
|
43
44
|
throw new Error(json?.message ?? `An error ${response.status} occurred.`);
|
|
@@ -79,7 +80,7 @@ function scrapeWantlist(username, browserContext) {
|
|
|
79
80
|
: `An error ${status} occurred.`);
|
|
80
81
|
}
|
|
81
82
|
const { total, ids } = await browserPage.evaluate(() => ({
|
|
82
|
-
total: +(document.querySelector('.pagination_total')?.textContent.split(' of ').pop()?.
|
|
83
|
+
total: +(document.querySelector('.pagination_total')?.textContent.split(' of ').pop()?.replaceAll(',', '') ?? '0'),
|
|
83
84
|
// The releases for sale are the ones with a link to their listings
|
|
84
85
|
ids: [...document.querySelectorAll('.marketplace_for_sale_count a')].map(x => +(new URL(x.href).pathname.split('/').pop() ?? '0')),
|
|
85
86
|
}));
|
|
@@ -95,6 +96,8 @@ function scrapeWantlist(username, browserContext) {
|
|
|
95
96
|
* By default, it reads the public Discogs API (limited to 25 requests per minute without token, 60 with).
|
|
96
97
|
* @param username - Username whose wantlist is read.
|
|
97
98
|
* @param options - Options.
|
|
99
|
+
* @param options.token - Discogs personal access token, for the API.
|
|
100
|
+
* @param options.onlyForSale - Whether to keep only the releases for sale, read from the public wantlist page.
|
|
98
101
|
* @param browserContext - Optional Patchright browser context, only used with `onlyForSale`. If provided, you must manage its lifecycle.
|
|
99
102
|
* @returns A promise that resolves to the release IDs.
|
|
100
103
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "discogs-marketplace-api-nodejs",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.3",
|
|
4
4
|
"description": "Another (better ?) NodeJs library to fetch data from Discogs marketplace",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"discogs",
|
|
@@ -21,10 +21,11 @@
|
|
|
21
21
|
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
22
22
|
"start:dev": "node --import tsx --watch ./src/index.ts",
|
|
23
23
|
"test": "node --import tsx --test ./test/*.test.ts",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
24
|
+
"check-types": "tsc --noEmit",
|
|
25
|
+
"oxlint": "oxlint",
|
|
26
|
+
"oxlint:fix": "oxlint --fix",
|
|
27
|
+
"oxfmt": "oxfmt --check",
|
|
28
|
+
"oxfmt:fix": "oxfmt",
|
|
28
29
|
"cspell": "npx cspell ./ --no-progress",
|
|
29
30
|
"knip": "knip"
|
|
30
31
|
},
|
|
@@ -43,25 +44,20 @@
|
|
|
43
44
|
"patchright": "^1.64.2"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@types/node": "^24.19.2",
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "^8.72.1",
|
|
49
|
-
"@typescript-eslint/parser": "^8.72.1",
|
|
47
|
+
"@types/node": "^26.6.6",
|
|
50
48
|
"cspell": "^10.4.0",
|
|
51
|
-
"eslint": "^
|
|
52
|
-
"eslint-
|
|
53
|
-
"eslint-import-resolver-typescript": "^4.4.5",
|
|
54
|
-
"eslint-plugin-import": "^2.32.0",
|
|
55
|
-
"eslint-plugin-jsdoc": "^65.4.2",
|
|
56
|
-
"globals": "^17.13.0",
|
|
49
|
+
"eslint-plugin-jsdoc": "^65.5.4",
|
|
50
|
+
"eslint-plugin-regexp": "^3.3.3",
|
|
57
51
|
"husky": "^9.1.7",
|
|
58
52
|
"knip": "^6.43.0",
|
|
59
53
|
"lint-staged": "^17.6.0",
|
|
60
|
-
"
|
|
54
|
+
"oxfmt": "^0.79.0",
|
|
55
|
+
"oxlint": "^1.95.0",
|
|
56
|
+
"oxlint-plugin-eslint": "^1.95.0",
|
|
57
|
+
"oxlint-tsgolint": "^7.0.2008",
|
|
61
58
|
"rimraf": "^6.1.3",
|
|
62
59
|
"tsc-alias": "^1.9.9",
|
|
63
60
|
"tsx": "^4.23.15",
|
|
64
|
-
"typescript": "^6.0.3"
|
|
65
|
-
"typescript-eslint": "^8.72.1"
|
|
61
|
+
"typescript": "^6.0.3"
|
|
66
62
|
}
|
|
67
63
|
}
|