discogs-marketplace-api-nodejs 1.18.0 → 1.18.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 CHANGED
@@ -1,11 +1,11 @@
1
- # 🎧 Discogs Marketplace API NodeJS
1
+ # Discogs Marketplace API NodeJS
2
2
 
3
3
  [![NPM Version](https://img.shields.io/npm/v/discogs-marketplace-api-nodejs?logo=npm&color=CB3837)](https://www.npmjs.com/package/discogs-marketplace-api-nodejs) ![GitHub Repo stars](https://img.shields.io/github/stars/KirianCaumes/Discogs-Marketplace-API-NodeJS?style=flat&logo=github&label=Stars&color=%23181717) [![GitHub License](https://img.shields.io/github/license/KirianCaumes/Discogs-Marketplace-API-NodeJS?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI%2FPg0KPHN2ZyBmaWxsPSIjZmZmIiBhcmlhLWhpZGRlbj0idHJ1ZSIgaGVpZ2h0PSIxNiIgdmlld0JveD0iMCAwIDE2IDE2IiB2ZXJzaW9uPSIxLjEiIHdpZHRoPSIxNiIgZGF0YS12aWV3LWNvbXBvbmVudD0idHJ1ZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgPg0KICAgIDxwYXRoIGQ9Ik04Ljc1Ljc1VjJoLjk4NWMuMzA0IDAgLjYwMy4wOC44NjcuMjMxbDEuMjkuNzM2Yy4wMzguMDIyLjA4LjAzMy4xMjQuMDMzaDIuMjM0YS43NS43NSAwIDAgMSAwIDEuNWgtLjQyN2wyLjExMSA0LjY5MmEuNzUuNzUgMCAwIDEtLjE1NC44MzhsLS41My0uNTMuNTI5LjUzMS0uMDAxLjAwMi0uMDAyLjAwMi0uMDA2LjAwNi0uMDA2LjAwNS0uMDEuMDEtLjA0NS4w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DAgMSAxLjUgMFptMi45NDUgOC40NzdjLjI4NS4xMzUuNzE4LjI3MyAxLjMwNS4yNzNzMS4wMi0uMTM4IDEuMzA1LS4yNzNMMTMgNi4zMjdabS0xMCAwYy4yODUuMTM1LjcxOC4yNzMgMS4zMDUuMjczczEuMDItLjEzOCAxLjMwNS0uMjczTDMgNi4zMjdaIj48L3BhdGg%2BDQo8L3N2Zz4%3D&logoColor=fff&label=License)](https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS/blob/master/LICENSE) [![Support this project](https://img.shields.io/badge/Support%20this%20project-003087?logo=PayPal&logoColor=fff)](https://www.paypal.me/KirianCaumes)
4
4
 
5
- A modern TypeScript/Node.js client for scraping and retrieving Discogs Marketplace listings — flexible, type safe, and easy to use. 💿
6
- > 💪 No Discogs API token required — this client scrapes public Marketplace data.
5
+ A modern TypeScript/Node.js client for scraping and retrieving Discogs Marketplace listings — flexible, type safe, and easy to use.
6
+ > No Discogs API token required — this client scrapes public Marketplace data.
7
7
 
8
- ## 🚀 Installation
8
+ ## Installation
9
9
 
10
10
  ```sh
11
11
  npm install discogs-marketplace-api-nodejs
@@ -15,20 +15,9 @@ npm install discogs-marketplace-api-nodejs
15
15
  ```
16
16
 
17
17
  The searches go through the API of the Discogs shop (`https://www.discogs.com/shop/list`), from a headless browser.
18
+ For many searches, or on a server, see [Browser](#browser).
18
19
 
19
- You can also pass your own [Patchright](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright) browser context as second parameter of
20
- `search`, used as is: it keeps the clearance of Cloudflare (`cf_clearance` cookie) from one search to another. You then
21
- manage its lifecycle.
22
-
23
- ```ts
24
- import { chromium } from 'patchright'
25
-
26
- const context = await chromium.launchPersistentContext('./profile', { channel: 'chrome', headless: false, viewport: null })
27
- const result = await DiscogsMarketplace.search({ artistIds: [244819] }, context)
28
- await context.close()
29
- ```
30
-
31
- ## ⚡ Quick Start
20
+ ## Quick Start
32
21
 
33
22
  ```ts
34
23
  import { DiscogsMarketplace } from 'discogs-marketplace-api-nodejs'
@@ -43,7 +32,7 @@ const result = await DiscogsMarketplace.search({
43
32
  console.log(result.items)
44
33
  ```
45
34
 
46
- ## 📚 Usage Examples
35
+ ## Usage Examples
47
36
 
48
37
  ### 1. Get 250 latest listings by a specific artist in the Rock genre, then the next 250
49
38
 
@@ -148,7 +137,59 @@ const result = await DiscogsMarketplace.search({
148
137
  })
149
138
  ```
150
139
 
151
- ## 🧩 API Reference
140
+ ## Browser
141
+
142
+ By default, each call launches a headless Chromium and closes it. Every search then starts without the clearance of
143
+ Cloudflare (`cf_clearance` cookie), and is blocked more often, especially from a datacenter IP.
144
+
145
+ For many searches, or on a server, pass your own [Patchright](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright)
146
+ browser context as last parameter of `search` and `getWantlistReleaseIds`. It keeps the clearance from one search to
147
+ another, and you manage its lifecycle.
148
+
149
+ ```ts
150
+ import { chromium } from 'patchright'
151
+
152
+ const context = await chromium.launchPersistentContext('./profile', {
153
+ channel: 'chrome',
154
+ headless: false,
155
+ viewport: null,
156
+ args: ['--no-sandbox', '--disable-dev-shm-usage'],
157
+ })
158
+ const result = await DiscogsMarketplace.search({ artistIds: [244819] }, context)
159
+ await context.close()
160
+ ```
161
+
162
+ - **One context for the whole app**, not one per search, so that every search benefits from the clearance.
163
+ - **Real Chrome, headful** (`channel: 'chrome'`, `headless: false`): it passes Cloudflare far more often. Install it
164
+ with `npx patchright install --with-deps chrome`.
165
+ - **Persistent profile** (`'./profile'`), so the clearance survives restarts. After a crash, delete its `Singleton*`
166
+ files, or Chrome refuses to start.
167
+ - **Without GPU** (server, Docker), add `--disable-gpu --enable-unsafe-swiftshader` to `args`, so Chrome does not hang
168
+ and keeps WebGL.
169
+ - **`env`**: Chrome gets your whole environment, secrets included. Pass only what it needs (`PATH`, `HOME`, `DISPLAY`,
170
+ `XAUTHORITY`...), and its language with `LANG` rather than the `locale` option.
171
+ - **Still blocked?** The IP is the problem: go through a residential proxy (`proxy` option).
172
+
173
+ On a server, headful Chrome needs a display: run your app under Xvfb (`xvfb-run -a node index.js`). With Docker:
174
+
175
+ ```dockerfile
176
+ FROM node:24-slim
177
+
178
+ RUN apt-get update \
179
+ && apt-get install -y --no-install-recommends ca-certificates curl tini xauth xvfb \
180
+ && rm -rf /var/lib/apt/lists/*
181
+
182
+ WORKDIR /app
183
+ COPY package*.json ./
184
+ RUN npm ci && npx patchright install --with-deps chrome
185
+ COPY . .
186
+
187
+ # -g passes the stop signal to the app, which xvfb-run does not
188
+ ENTRYPOINT ["/usr/bin/tini", "-g", "--", "xvfb-run", "-a"]
189
+ CMD ["node", "index.js"]
190
+ ```
191
+
192
+ ## API Reference
152
193
 
153
194
  ### `DiscogsMarketplace.search(searchParams, browserContext?)`
154
195
 
@@ -177,6 +218,7 @@ const result = await DiscogsMarketplace.search({
177
218
  | `hideGenericSleeves` | `boolean` | Hide generic sleeves. | – | `false` |
178
219
  | `hideSleevelessMedia` | `boolean` | Hide sleeveless media. | – | `false` |
179
220
  | `showUnavailable` | `boolean` | Show unavailable items. | – | `true` |
221
+ | `withCommunityStats` | `boolean` | Get `community` and `release.rating` (slower). | – | `true` |
180
222
  | `sort` | `Sort` | Sort and sort order (see below). | `'price,asc'` | `'listed,desc'` |
181
223
  | `limit` | `number` | Number of results per page (at most 250). | `100` | `25` |
182
224
  | `after` | `string` | Cursor of the page, from `nextCursor`. | – | – |
@@ -257,19 +299,19 @@ interface SearchResult {
257
299
  }
258
300
  ```
259
301
 
260
- ## 🛠️ Development & Contribution
302
+ ## Development & Contribution
261
303
 
262
304
  - Clone the repo and use the included devcontainer/VSCode setup.
263
305
  - Run: `npm install`
264
306
  - Add your contribution.
265
307
  - Use `npm test` to run unit tests.
266
- - Open a pull request with your new additions! 🎉
308
+ - Open a pull request with your new additions!
267
309
 
268
- ## 👉 Known Issues
310
+ ## Known Issues
269
311
 
270
312
  - Some search parameters might not be compatible with every type of queries.
271
313
  - For other edge cases, feel free to open an [issue on GitHub](https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS/issues).
272
314
 
273
- ## 📃 License
315
+ ## License
274
316
 
275
317
  Licensed under [MIT](https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS/blob/master/LICENSE).
@@ -131,6 +131,12 @@ export interface SearchParams {
131
131
  * @default true
132
132
  */
133
133
  showUnavailable?: boolean;
134
+ /**
135
+ * Get the community stats of the releases (`community` and `release.rating`), at the cost of a second request.
136
+ * If false, `community` is 0 and `release.rating` is null.
137
+ * @default true
138
+ */
139
+ withCommunityStats?: boolean;
134
140
  /**
135
141
  * Sort order for the results.
136
142
  * @default 'listed,desc'
@@ -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({ query, artistIds, labelIds, masterIds, releaseIds, sellerIds, genres, styles, formats, formatDescriptions, mediaConditions, sleeveConditions, from, currencies, priceRange, sellerRatingMin, sellerRatingCountMin, years, isMakeAnOfferOnly, hasItemPhotos, hideGenericSleeves, hideSleevelessMedia, showUnavailable, sort, limit, after, }: SearchParams, browserContext: BrowserContext): Promise<SearchResult>;
10
+ export default function scrapeMarketplace({ query, artistIds, labelIds, masterIds, releaseIds, sellerIds, genres, styles, formats, formatDescriptions, mediaConditions, sleeveConditions, from, currencies, priceRange, sellerRatingMin, sellerRatingCountMin, years, isMakeAnOfferOnly, hasItemPhotos, hideGenericSleeves, hideSleevelessMedia, showUnavailable, withCommunityStats, sort, limit, after, }: SearchParams, browserContext: BrowserContext): Promise<SearchResult>;
@@ -75,6 +75,7 @@ async function queryGraphql(page, operationName, variables) {
75
75
  method: 'POST',
76
76
  headers: { 'Content-Type': 'application/json' },
77
77
  body: JSON.stringify(body),
78
+ signal: AbortSignal.timeout(30_000),
78
79
  });
79
80
  return {
80
81
  status: res.status,
@@ -139,7 +140,7 @@ function decodeHtmlEntities(text) {
139
140
  * @param browserContext Patchright browser context
140
141
  * @returns Items found, total, next cursor and url of the same search on Discogs
141
142
  */
142
- async function scrapeMarketplace({ 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, sort = 'listed,desc', limit = 25, after, }, browserContext) {
143
+ async function scrapeMarketplace({ 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, }, browserContext) {
143
144
  const [sortField = 'listed', sortOrder = 'desc'] = sort.split(',');
144
145
  const countries = from?.flatMap(code => {
145
146
  const names = Object.keys(country_data_1.default).filter(key => code === country_data_1.default[key]);
@@ -230,10 +231,10 @@ async function scrapeMarketplace({ query, artistIds, labelIds, masterIds, releas
230
231
  after,
231
232
  })).data?.marketplaceSearch;
232
233
  const nodes = result?.edges?.map(x => x.node ?? {}) ?? [];
233
- const releaseIdsFound = [...new Set(nodes.map(x => x.release?.discogsId ?? 0).filter(x => !!x))];
234
+ // The community stats and the rating of the releases are not part of the listings
235
+ const releaseIdsFound = withCommunityStats ? [...new Set(nodes.map(x => x.release?.discogsId ?? 0).filter(x => !!x))] : [];
234
236
  const { data: details } = releaseIdsFound.length
235
- ? // The community stats and the rating of the releases are not part of the listings
236
- await queryGraphql(browserPage, 'Releases', { discogsIds: releaseIdsFound, first: 1 })
237
+ ? await queryGraphql(browserPage, 'Releases', { discogsIds: releaseIdsFound, first: 1 })
237
238
  : { data: undefined };
238
239
  const releaseDetails = new Map(details?.releases?.map(x => [x?.discogsId ?? 0, x]) ?? []);
239
240
  const items = nodes.map(node => {
package/dist/wantlist.js CHANGED
@@ -32,6 +32,7 @@ function fetchWantlist(username, token) {
32
32
  page: pageNumber.toString(),
33
33
  per_page: API_PER_PAGE.toString(),
34
34
  }).toString()}`, {
35
+ signal: AbortSignal.timeout(30_000),
35
36
  headers: {
36
37
  'User-Agent': `DiscogsMarketplaceApiNodeJS-${username}`,
37
38
  ...(token ? { Authorization: `Discogs token=${token}` } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discogs-marketplace-api-nodejs",
3
- "version": "1.18.0",
3
+ "version": "1.18.1",
4
4
  "description": "Another (better ?) NodeJs library to fetch data from Discogs marketplace",
5
5
  "keywords": [
6
6
  "discogs",
@@ -40,28 +40,28 @@
40
40
  }
41
41
  ],
42
42
  "dependencies": {
43
- "patchright": "^1.63.0"
43
+ "patchright": "^1.64.2"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@eslint/js": "^9.39.5",
47
- "@types/node": "^24.13.6",
48
- "@typescript-eslint/eslint-plugin": "^8.70.0",
49
- "@typescript-eslint/parser": "^8.70.0",
50
- "cspell": "^10.3.3",
47
+ "@types/node": "^24.19.2",
48
+ "@typescript-eslint/eslint-plugin": "^8.72.1",
49
+ "@typescript-eslint/parser": "^8.72.1",
50
+ "cspell": "^10.4.0",
51
51
  "eslint": "^9.39.5",
52
52
  "eslint-config-prettier": "^10.1.8",
53
53
  "eslint-import-resolver-typescript": "^4.4.5",
54
54
  "eslint-plugin-import": "^2.32.0",
55
- "eslint-plugin-jsdoc": "^64.5.4",
56
- "globals": "^17.12.0",
55
+ "eslint-plugin-jsdoc": "^65.4.2",
56
+ "globals": "^17.13.0",
57
57
  "husky": "^9.1.7",
58
- "knip": "^6.37.0",
59
- "lint-staged": "^17.5.1",
60
- "prettier": "^3.9.8",
58
+ "knip": "^6.43.0",
59
+ "lint-staged": "^17.6.0",
60
+ "prettier": "^3.9.10",
61
61
  "rimraf": "^6.1.3",
62
- "tsc-alias": "^1.9.5",
62
+ "tsc-alias": "^1.9.9",
63
63
  "tsx": "^4.23.15",
64
64
  "typescript": "^6.0.3",
65
- "typescript-eslint": "^8.70.0"
65
+ "typescript-eslint": "^8.72.1"
66
66
  }
67
67
  }