discogs-marketplace-api-nodejs 1.16.9 → 1.17.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.
Files changed (46) hide show
  1. package/README.MD +111 -151
  2. package/dist/data/country.data.d.ts +1 -1
  3. package/dist/data/style.data.d.ts +763 -0
  4. package/dist/data/style.data.js +765 -0
  5. package/dist/index.d.ts +4 -1
  6. package/dist/index.js +2 -1
  7. package/dist/interfaces/api/marketplace-search-result.api.interface.d.ts +148 -0
  8. package/dist/interfaces/api/{shop-details-result.api.interface.d.ts → releases-result.api.interface.d.ts} +4 -1
  9. package/dist/interfaces/api/wantlist-result.api.interface.d.ts +109 -0
  10. package/dist/interfaces/search-params.interface.d.ts +76 -156
  11. package/dist/interfaces/search-result.interface.d.ts +21 -19
  12. package/dist/scrapers/browser-context.d.ts +9 -0
  13. package/dist/scrapers/browser-context.js +28 -0
  14. package/dist/scrapers/marketplace.scraper.d.ts +10 -0
  15. package/dist/scrapers/marketplace.scraper.js +292 -0
  16. package/dist/search.d.ts +4 -7
  17. package/dist/search.js +10 -57
  18. package/dist/types/condition.type.d.ts +4 -0
  19. package/dist/types/currency.type.d.ts +1 -1
  20. package/dist/types/format-description.type.d.ts +1 -1
  21. package/dist/types/sort.type.d.ts +1 -1
  22. package/dist/types/style.type.d.ts +2 -1
  23. package/dist/wantlist.d.ts +28 -0
  24. package/dist/wantlist.js +101 -0
  25. package/package.json +14 -16
  26. package/dist/data/currency.data.d.ts +0 -36
  27. package/dist/data/currency.data.js +0 -35
  28. package/dist/interfaces/api/shop-result-error.api.interface.d.ts +0 -8
  29. package/dist/interfaces/api/shop-result.api.interface.d.ts +0 -111
  30. package/dist/scrapers/extractors/legacy.extractor.d.ts +0 -11
  31. package/dist/scrapers/extractors/legacy.extractor.js +0 -138
  32. package/dist/scrapers/legacy.scraper.d.ts +0 -13
  33. package/dist/scrapers/legacy.scraper.js +0 -75
  34. package/dist/scrapers/modern.scraper.d.ts +0 -13
  35. package/dist/scrapers/modern.scraper.js +0 -199
  36. package/dist/scrapers/wantlist.scraper.d.ts +0 -13
  37. package/dist/scrapers/wantlist.scraper.js +0 -66
  38. package/dist/types/api.type.d.ts +0 -4
  39. package/dist/types/api.type.js +0 -2
  40. package/dist/types/lang.type.d.ts +0 -4
  41. package/dist/types/lang.type.js +0 -2
  42. package/dist/types/limit.type.d.ts +0 -4
  43. package/dist/types/limit.type.js +0 -2
  44. /package/dist/interfaces/api/{shop-details-result.api.interface.js → marketplace-search-result.api.interface.js} +0 -0
  45. /package/dist/interfaces/api/{shop-result-error.api.interface.js → releases-result.api.interface.js} +0 -0
  46. /package/dist/interfaces/api/{shop-result.api.interface.js → wantlist-result.api.interface.js} +0 -0
package/README.MD CHANGED
@@ -10,8 +10,20 @@ A modern TypeScript/Node.js client for scraping and retrieving Discogs Marketpla
10
10
  ```sh
11
11
  npm install discogs-marketplace-api-nodejs
12
12
 
13
- # Because we use Playwright to scrape the data, you may also need to run:
14
- # npx playwright install --with-deps chromium
13
+ # Because we use Patchright (an undetected Playwright fork) to scrape the data, you may also need to run:
14
+ # npx patchright install --with-deps chromium
15
+ ```
16
+
17
+ The searches go through the API of the Discogs shop (`https://www.discogs.com/shop/list`), from a headless browser.
18
+
19
+ You can also pass your own [Patchright](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright) browser as second parameter of `search`. You then manage its lifecycle.
20
+
21
+ ```ts
22
+ import { chromium } from 'patchright'
23
+
24
+ const browser = await chromium.launch({ headless: true })
25
+ const result = await DiscogsMarketplace.search({ artistIds: [244819] }, browser)
26
+ await browser.close()
15
27
  ```
16
28
 
17
29
  ## ⚡ Quick Start
@@ -20,12 +32,10 @@ npm install discogs-marketplace-api-nodejs
20
32
  import { DiscogsMarketplace } from 'discogs-marketplace-api-nodejs'
21
33
 
22
34
  const result = await DiscogsMarketplace.search({
23
- api: 'v2',
24
35
  artistIds: [244819],
25
36
  genres: ['Rock'],
26
37
  sort: 'price,asc',
27
38
  limit: 50,
28
- page: 1,
29
39
  })
30
40
 
31
41
  console.log(result.items)
@@ -33,192 +43,143 @@ console.log(result.items)
33
43
 
34
44
  ## 📚 Usage Examples
35
45
 
36
- This library offers two API modes to access Discogs Marketplace data. The required `api` parameter determines which endpoint to use:
46
+ ### 1. Get 250 latest listings by a specific artist in the Rock genre, then the next 250
37
47
 
38
- - **`api: 'v2'`** (Modern JSON API) - Recommended for most use cases, offers advanced filtering
39
- - **`api: 'legacy'`** (HTML scraping) - Required for certain search types and general queries
40
-
41
- Each API has different capabilities and available parameters. See the [API Reference](#-api-reference) section for complete details.
42
-
43
- ### 1. Get 250 latest listings by a specific artist in the Rock genre, page 2
48
+ Discogs paginates with cursors: each result gives the `nextCursor` to pass as `after` to get the next page.
44
49
 
45
50
  ```ts
46
- // https://www.discogs.com/sell/list?sort=listed,desc&limit=250&artist_id=244819&page=2&genre=Rock
47
- const result = await DiscogsMarketplace.search({
48
- api: 'legacy',
49
- artistId: 244819,
50
- genre: 'Rock',
51
- sort: 'listed,desc',
52
- limit: 250,
53
- page: 2,
54
- })
55
- // OR
56
- const result = await DiscogsMarketplace.search({
57
- api: 'v2',
51
+ // https://www.discogs.com/shop/list?artist=244819&genre=Rock&sort=date-listed&sortOrder=descending&size=250
52
+ const firstPage = await DiscogsMarketplace.search({
58
53
  artistIds: [244819],
59
54
  genres: ['Rock'],
60
55
  sort: 'listed,desc',
61
56
  limit: 250,
62
- page: 2,
63
57
  })
58
+
59
+ if (firstPage.nextCursor) {
60
+ const secondPage = await DiscogsMarketplace.search({
61
+ artistIds: [244819],
62
+ genres: ['Rock'],
63
+ sort: 'listed,desc',
64
+ limit: 250,
65
+ after: firstPage.nextCursor,
66
+ })
67
+ }
64
68
  ```
65
69
 
66
- ### 2. Get listings of a user's wantlist, sorted by price, limit 50
70
+ ### 2. Go through several pages with the cursor
71
+
72
+ ```ts
73
+ import { DiscogsMarketplace, type SearchResult } from 'discogs-marketplace-api-nodejs'
74
+
75
+ const items: SearchResult['items'] = []
76
+ let after: string | undefined
77
+
78
+ do {
79
+ const result = await DiscogsMarketplace.search({ artistIds: [244819], limit: 250, after })
80
+ items.push(...result.items)
81
+ after = result.nextCursor ?? undefined
82
+ } while (after && items.length < 1000) // Stop after 1000 items, or at the last page
83
+ ```
84
+
85
+ ### 3. Get listings of a user's wantlist, sorted by price, limit 50
86
+
87
+ Get the release IDs of the wantlist, then search them as `releaseIds` (at most 2000). You can keep the IDs on your side to reuse them in the next searches.
67
88
 
68
89
  ```ts
69
90
  // https://www.discogs.com/shop/mywants
70
- const result = await DiscogsMarketplace.search({
71
- api: 'v2',
72
- limit: 50,
73
- sort: 'price,asc',
74
- wantlist: 'Kirian_',
75
- })
91
+ // Every release of the wantlist, from the Discogs API (no browser needed)
92
+ const releaseIds = await DiscogsMarketplace.getWantlistReleaseIds('Kirian_')
93
+ // Or only the ones currently for sale, from the wantlist page (fewer IDs to search)
94
+ const releaseIdsForSale = await DiscogsMarketplace.getWantlistReleaseIds('Kirian_', { onlyForSale: true })
95
+
96
+ // An empty list means no filter, as for every other filter: there is nothing to search if the wantlist is empty
97
+ if (releaseIdsForSale.length) {
98
+ const result = await DiscogsMarketplace.search({
99
+ releaseIds: releaseIdsForSale,
100
+ sort: 'price,asc',
101
+ limit: 50,
102
+ })
103
+ }
76
104
  ```
77
105
 
78
- ### 3. Get listings on a release, sorted by seller name
106
+ ### 4. Get listings on a release, sorted by seller name
79
107
 
80
108
  ```ts
81
- // https://www.discogs.com/sell/list?release_id=767931&sort=seller,asc&limit=25
82
- // https://www.discogs.com/sell/release/767931?sort=seller,asc&limit=25
83
- const result = await DiscogsMarketplace.search({
84
- api: 'legacy',
85
- releaseId: 767931,
86
- sort: 'seller,asc',
87
- })
88
- // OR
109
+ // https://www.discogs.com/shop/list?release=767931&sort=seller&sortOrder=ascending
89
110
  const result = await DiscogsMarketplace.search({
90
- api: 'v2',
91
111
  releaseIds: [767931],
92
112
  sort: 'seller,asc',
93
113
  })
94
114
  ```
95
115
 
96
- ### 4. Get listings by a general search query (e.g., "in flames"), sorted by newest listings, limit 100
116
+ ### 5. Get listings by a general search query (e.g., "in flames"), sorted by newest listings, limit 100
97
117
 
98
118
  ```ts
99
- // https://www.discogs.com/sell/list?sort=listed,desc&limit=100&q=in+flames&page=1
119
+ // https://www.discogs.com/shop/list?q=in+flames&sort=date-listed&sortOrder=descending&size=100
100
120
  const result = await DiscogsMarketplace.search({
101
- api: 'legacy',
102
121
  query: 'in flames',
103
122
  sort: 'listed,desc',
104
123
  limit: 100,
105
124
  })
106
125
  ```
107
126
 
108
- ### 5. Get newest listings on a seller inventory
109
-
110
- ```ts
111
- // https://www.discogs.com/sell/list?sort=listed,desc&seller=Kirian_
112
- // https://www.discogs.com/seller/Kirian_/profile?sort=listed,desc
113
- const result = await DiscogsMarketplace.search({
114
- api: 'legacy',
115
- sort: 'listed,desc',
116
- seller: 'Kirian_',
117
- })
118
- // OR
119
- const result = await DiscogsMarketplace.search({
120
- api: 'v2',
121
- sort: 'listed,desc',
122
- sellerIds: [6562907],
123
- })
124
- ```
125
-
126
127
  ### 6. Get newest listings of a user's wantlist, on a seller inventory
127
128
 
128
129
  ```ts
129
- // https://www.discogs.com/seller/Kirian_/mywants?sort=listed,desc&user=Kirian_
130
+ // The seller ID can be found via the Discogs API: https://api.discogs.com/users/Kirian_
130
131
  const result = await DiscogsMarketplace.search({
131
- api: 'legacy',
132
132
  sort: 'listed,desc',
133
- seller: 'Kirian_',
134
- user: 'Kirian_',
135
- })
136
- // OR
137
- const result = await DiscogsMarketplace.search({
138
- api: 'v2',
139
- sort: 'listed,desc',
140
- wantlist: 'Kirian_',
133
+ releaseIds: await DiscogsMarketplace.getWantlistReleaseIds('Kirian_', { onlyForSale: true }),
141
134
  sellerIds: [6562907],
142
135
  })
143
136
  ```
144
137
 
145
- ### 7. Get listings by a general search query (e.g., "red"), sorted by newest listings, on a master release
138
+ ### 7. Get listings with photos, by a general search query (e.g., "red"), on a master release
146
139
 
147
140
  ```ts
148
- // https://www.discogs.com/sell/list?master_id=28291&q=red
141
+ // https://www.discogs.com/shop/list?q=red&master=2167270&hasItemPhotos=true
149
142
  const result = await DiscogsMarketplace.search({
150
- api: 'legacy',
151
- sort: 'listed,desc',
152
- masterId: 2167270,
153
143
  query: 'red',
144
+ masterIds: [2167270],
145
+ hasItemPhotos: true,
154
146
  })
155
147
  ```
156
148
 
157
149
  ## 🧩 API Reference
158
150
 
159
- This library provides two different ways to search the Discogs Marketplace:
160
-
161
- - **Modern API (`api: 'v2'`)** → JSON API, used by the Discogs "My Wants" page.
162
- - **Legacy API (`api: 'legacy'`)** → HTML scraping, required for some cases.
163
-
164
- Both share common search filters and extend them with API-specific options via the `SearchParams` interface.
165
-
166
- ### Modern API (`api: "v2"`), recommended for most use cases
167
-
168
- | Field | Type | Description | Example | Default |
169
- |-------------------------|---------------------|------------------------------------|-------------------------|---------|
170
- | `api` | `'v2'` | Selects the modern API. | `'v2'` | – |
171
- | `currencies` | `Currency[]` | Filter by multiple currencies. | `['USD', 'EUR']` | – |
172
- | `conditions` | `Condition[]` | List of media/sleeve conditions. | `['Mint (M)']` | – |
173
- | `genres` | `Genre[]` | Filter by multiple genres. | `['Rock', 'Jazz']` | – |
174
- | `from` | `From[]` | Filter by seller’s countries. | `['FR', 'DE']` | – |
175
- | `sort` | `Sort` | Sort and sort order. | `'listed,desc'` | `'listed,desc'` |
176
- | `limit` | `number` | Number of results per page. | `100` | `25` |
177
- | `artistIds` | `number[]` | Filter by artist IDs. | `[123, 456]` | – |
178
- | `sellerIds` | `number[]` | Filter by seller IDs. | `[789, 1011]` | – |
179
- | `priceRange.min`/`max` | `number` | Filter by price range. | `{ min: 10, max: 100 }` | – |
180
- | `sellerRatingMin` | `number (0–100)` | Minimum seller rating. | `90` | `0` |
181
- | `hideGenericSleeves` | `boolean` | Hide generic sleeves. | – | `false` |
182
- | `hideSleevelessMedia` | `boolean` | Hide sleeveless media. | – | `false` |
183
- | `showUnavailable` | `boolean` | Show unavailable items. | – | `true` |
184
- | `sellerRatingCountMin` | `number` | Minimum number of seller ratings. | `50` | `0` |
185
- | `wantlist`* | `string` | Search by wantlist username. | `"username"` | – |
186
- | `releaseIds`* | `number[]` | Search by release IDs. | `[12345, 67890]` | – |
187
-
188
- \* Only **one** of `wantlist` or `releaseIds` can be used.
189
-
190
- ### Legacy API (`api: "legacy"`)
191
-
192
- | Field | Type | Description | Example | Default |
193
- |--------------|-----------------|------------------------------------|--------------------------------|---------|
194
- | `api` | `'legacy'` | Selects the legacy API. | `'legacy'` | – |
195
- | `query` | `string` | Search string. | `"something"` | – |
196
- | `currency` | `Currency` | Currency code for price filtering. | `'USD'` | – |
197
- | `condition` | `Condition` | Media/sleeve conditions. | `'Mint (M)'` | – |
198
- | `genre` | `Genre` | Filter by genre. | `'Rock'` | – |
199
- | `styles` | `Style[]` | Filter by style. | `['Death Metal', 'Heavy Metal']` | – |
200
- | `from` | `From` | Filter by seller’s country. | `'FR'` | – |
201
- | `sort` | `Sort` | Sort order for results. | `'listed,desc'` | `'listed,desc'` |
202
- | `limit` | `25 \| 50 \| 100 \| 250` | Number of results per page. | `100` | `25` |
203
- | `seller` | `string` | Filter by seller username. | `"seller_name"` | – |
204
- | `user` | `string` | Filter by user. | `"my_username"` | – |
205
- | `lang` | `Lang` | Discogs interface language. | `'en'` | `'en'` |
206
- | `masterId`* | `number` | Search by master release ID. | `12345` | – |
207
- | `labelId`* | `number` | Search by label ID. | `67890` | – |
208
- | `releaseId`* | `number` | Search by release ID. | `11111` | – |
209
- | `artistId`* | `number` | Search by artist ID. | `22222` | – |
210
-
211
- \* Only **one** of `masterId`, `labelId`, `releaseId`, or `artistId` can be used.
212
-
213
- ### Common Parameters (all searches)
214
-
215
- | Field | Type | Description | Example | Default |
216
- |-----------------------|------------------------------|------------------------------------------------|----------------------------------------|---------|
217
- | `formats` | `Format[]` | List of formats. | `['Vinyl', 'CD']` | – |
218
- | `formatDescriptions` | `FormatDescription[]` | List of format descriptions. | `['Limited Edition', 'Numbered']` | – |
219
- | `years.min` / `max` | `number` | Year range. | `{ min: 1980, max: 1990 }` | – |
220
- | `isMakeAnOfferOnly` | `boolean` | Only return listings that accept offers. | – | `false` |
221
- | `page` | `number` | Page number (must be `< 401` to avoid 404). | `2` | `1` |
151
+ ### `DiscogsMarketplace.search(searchParams, browserInstance?)`
152
+
153
+ | Field | Type | Description | Example | Default |
154
+ |-------------------------|-----------------------|------------------------------------------------|-----------------------------------|-----------------|
155
+ | `query` | `string` | Search string. | `'in flames'` | – |
156
+ | `artistIds` | `number[]` | Filter by artist IDs. | `[244819]` | – |
157
+ | `labelIds` | `number[]` | Filter by label IDs. | `[11499]` | – |
158
+ | `masterIds` | `number[]` | Filter by master release IDs. | `[33474]` | – |
159
+ | `releaseIds` | `number[]` | Filter by release IDs (at most 2000). | `[12345, 67890]` | – |
160
+ | `sellerIds` | `number[]` | Filter by seller IDs. | `[6562907]` | – |
161
+ | `genres` | `Genre[]` | Filter by genres. | `['Rock', 'Jazz']` | – |
162
+ | `styles` | `Style[]` | Filter by styles. | `['Death Metal', 'Heavy Metal']` | – |
163
+ | `formats` | `Format[]` | Filter by formats. | `['Vinyl', 'CD']` | – |
164
+ | `formatDescriptions` | `FormatDescription[]` | Filter by format descriptions. | `['Limited Edition', 'Numbered']` | – |
165
+ | `mediaConditions` | `Condition[]` | Filter by media conditions. | `['Mint (M)']` | – |
166
+ | `sleeveConditions` | `SleeveCondition[]` | Filter by sleeve conditions. | `['Mint (M)', 'Generic']` | – |
167
+ | `from` | `From[]` | Filter by seller’s countries. | `['FR', 'DE']` | – |
168
+ | `currencies` | `Currency[]` | Filter by currencies. | `['USD', 'EUR']` | – |
169
+ | `priceRange.min`/`max` | `number` | Filter by price range. | `{ min: 10, max: 100 }` | – |
170
+ | `years.min`/`max` | `number` | Filter by year range. | `{ min: 1980, max: 1990 }` | – |
171
+ | `sellerRatingMin` | `number (0–100)` | Minimum seller rating (unrated sellers kept). | `99` | `0` |
172
+ | `sellerRatingCountMin` | `number` | Minimum number of seller ratings. | `50` | `0` |
173
+ | `isMakeAnOfferOnly` | `boolean` | Only return listings that accept offers. | – | `false` |
174
+ | `hasItemPhotos` | `boolean` | Only return listings with photos of the item. | – | `false` |
175
+ | `hideGenericSleeves` | `boolean` | Hide generic sleeves. | – | `false` |
176
+ | `hideSleevelessMedia` | `boolean` | Hide sleeveless media. | – | `false` |
177
+ | `showUnavailable` | `boolean` | Show unavailable items. | – | `true` |
178
+ | `sort` | `Sort` | Sort and sort order (see below). | `'price,asc'` | `'listed,desc'` |
179
+ | `limit` | `number` | Number of results per page (at most 250). | `100` | `25` |
180
+ | `after` | `string` | Cursor of the page, from `nextCursor`. | – | – |
181
+
182
+ `sort` is a field followed by `asc` or `desc` (e.g. `'price,asc'`), the field being one of `listed`, `condition` (media), `sleeveCondition`, `artist`, `title`, `year`, `releaseCountry`, `seller`, `sellerRating`, `sellerRatingCount`, `shipsFrom` or `price`.
222
183
 
223
184
  On success, a `SearchResult` interface is returned:
224
185
 
@@ -236,6 +197,9 @@ interface SearchResult {
236
197
  id: number
237
198
  name: string
238
199
  url: string
200
+ year: number | null
201
+ country: string | null
202
+ rating: number | null
239
203
  }
240
204
  formats: Array<string>
241
205
  labels: Array<{
@@ -247,6 +211,7 @@ interface SearchResult {
247
211
  listedAt: Date | null
248
212
  catnos: Array<string>
249
213
  imageUrl: string | null
214
+ photos: Array<string>
250
215
  description: string | null
251
216
  isAcceptingOffer: boolean
252
217
  isAvailable: boolean
@@ -261,16 +226,18 @@ interface SearchResult {
261
226
  }
262
227
  }
263
228
  seller: {
229
+ id: number
264
230
  name: string
265
231
  url: string
266
232
  score: string | null
267
233
  notes: number | null
234
+ isIndependent: boolean
268
235
  }
269
236
  price: {
270
237
  /** @example '12.34 USD' */
271
- base: `${number} ${CurrencyValues}`
238
+ base: `${number} ${Currency}`
272
239
  /** @example '5.67 USD' */
273
- shipping: `${number} ${CurrencyValues}` | null
240
+ shipping: `${number} ${Currency}` | null
274
241
  }
275
242
  country: {
276
243
  name: string
@@ -282,14 +249,8 @@ interface SearchResult {
282
249
  want: number
283
250
  }
284
251
  }>
285
- page: {
286
- current: number
287
- total: number
288
- }
289
- result: {
290
- total: number
291
- perPage: number
292
- }
252
+ total: number
253
+ nextCursor: string | null
293
254
  urlGenerated: string
294
255
  }
295
256
  ```
@@ -304,7 +265,6 @@ interface SearchResult {
304
265
 
305
266
  ## 👉 Known Issues
306
267
 
307
- - Requests hitting page >400 will result in a 404 on the legacy API.
308
268
  - Some search parameters might not be compatible with every type of queries.
309
269
  - For other edge cases, feel free to open an [issue on GitHub](https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS/issues).
310
270
 
@@ -303,7 +303,7 @@ declare const Country: {
303
303
  readonly Zambia: "ZM";
304
304
  readonly Zimbabwe: "ZW";
305
305
  };
306
- export type CountryType = typeof Country;
306
+ type CountryType = typeof Country;
307
307
  export type CountryKeys = keyof CountryType;
308
308
  export type CountryValues = CountryType[CountryKeys];
309
309
  export default Country;