discogs-marketplace-api-nodejs 1.11.0 → 1.12.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 CHANGED
@@ -1,108 +1,115 @@
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%2FPg0KPHN2ZyBmaWxsPSIjZmZmIiBhcmlhLWhpZGRlbj0idHJ1ZSIgaGVpZ2h0PSIxNiIgdmlld0JveD0iMCAwIDE2IDE2IiB2ZXJzaW9uPSIxLjEiIHdpZHRoPSIxNiIgZGF0YS12aWV3LWNvbXBvbmVudD0idHJ1ZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgPg0KICAgIDxwYXRoIGQ9Ik04Ljc1Ljc1VjJoLjk4NWMuMzA0IDAgLjYwMy4wOC44NjcuMjMxbDEuMjkuNzM2Yy4wMzguMDIyLjA4LjAzMy4xMjQuMDMzaDIuMjM0YS43NS43NSAwIDAgMSAwIDEuNWgtLjQyN2wyLjExMSA0LjY5MmEuNzUuNzUgMCAwIDEtLjE1NC44MzhsLS41My0uNTMuNTI5LjUzMS0uMDAxLjAwMi0uMDAyLjAwMi0uMDA2LjAwNi0uMDA2LjAwNS0uMDEuMDEtLjA0NS4wNGMtLjIxLjE3Ni0uNDQxLjMyNy0uNjg2LjQ1QzE0LjU1NiAxMC43OCAxMy44OCAxMSAxMyAxMWE0LjQ5OCA0LjQ5OCAwIDAgMS0yLjAyMy0uNDU0IDMuNTQ0IDMuNTQ0IDAgMCAxLS42ODYtLjQ1bC0uMDQ1LS4wNC0uMDE2LS4wMTUtLjAwNi0uMDA2LS4wMDQtLjAwNHYtLjAwMWEuNzUuNzUgMCAwIDEtLjE1NC0uODM4TDEyLjE3OCA0LjVoLS4xNjJjLS4zMDUgMC0uNjA0LS4wNzktLjg2OC0uMjMxbC0xLjI5LS43MzZhLjI0NS4yNDUgMCAwIDAtLjEyNC0uMDMzSDguNzVWMTNoMi41YS43NS43NSAwIDAgMSAwIDEuNWgtNi41YS43NS43NSAwIDAgMSAwLTEuNWgyLjVWMy41aC0uOTg0YS4yNDUuMjQ1IDAgMCAwLS4xMjQuMDMzbC0xLjI4OS43MzdjLS4yNjUuMTUtLjU2NC4yMy0uODY5LjIzaC0uMTYybDIuMTEyIDQuNjkyYS43NS43NSAwIDAgMS0uMTU0LjgzOGwtLjUzLS41My41MjkuNTMxLS4wMDEuMDAyLS4wMDIuMDAyLS4wMDYuMDA2LS4wMTYuMDE1LS4wNDUuMDRjLS4yMS4xNzYtLjQ0MS4zMjctLjY4Ni40NUM0LjU1NiAxMC43OCAzLjg4IDExIDMgMTFhNC40OTggNC40OTggMCAwIDEtMi4wMjMtLjQ1NCAzLjU0NCAzLjU0NCAwIDAgMS0uNjg2LS40NWwtLjA0NS0uMDQtLjAxNi0uMDE1LS4wMDYtLjAwNi0uMDA0LS4wMDR2LS4wMDFhLjc1Ljc1IDAgMCAxLS4xNTQtLjgzOEwyLjE3OCA0LjVIMS43NWEuNzUuNzUgMCAwIDEgMC0xLjVoMi4yMzRhLjI0OS4yNDkgMCAwIDAgLjEyNS0uMDMzbDEuMjg4LS43MzdjLjI2NS0uMTUuNTY0LS4yMy44NjktLjIzaC45ODRWLjc1YS43NS43NSAwIDAgMSAxLjUgMFptMi45NDUgOC40NzdjLjI4NS4xMzUuNzE4LjI3MyAxLjMwNS4yNzNzMS4wMi0uMTM4IDEuMzA1LS4yNzNMMTMgNi4zMjdabS0xMCAwYy4yODUuMTM1LjcxOC4yNzMgMS4zMDUuMjczczEuMDItLjEzOCAxLjMwNS0uMjczTDMgNi4zMjdaIj48L3BhdGg%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
- Another (better ?) NodeJs library to fetch data from Discogs marketplace. 💿
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.
6
7
 
7
- ## 📂 Installation (with npm)
8
-
9
- Run the following command in your project:
8
+ ## 🚀 Installation
10
9
 
11
10
  ```sh
12
- npm i discogs-marketplace-api-nodejs
11
+ npm install discogs-marketplace-api-nodejs
13
12
  ```
14
13
 
15
- ## ▶️ Quick Start
16
-
17
- Import `DiscogsMarketplace` into your project:
14
+ ## ⚡ Quick Start
18
15
 
19
- ```js
16
+ ```ts
20
17
  import { DiscogsMarketplace } from 'discogs-marketplace-api-nodejs'
18
+
19
+ const result = await DiscogsMarketplace.search({
20
+ searchType: 'artist_id',
21
+ searchValue: 244819,
22
+ genre: 'Rock',
23
+ sort: 'price,asc',
24
+ limit: 50,
25
+ page: 1,
26
+ })
27
+
28
+ console.log(result.items)
21
29
  ```
22
30
 
23
- ## 🤔 Examples
31
+ ## 📚 Usage Examples
24
32
 
25
- - Get top 250 items, of the 2nd page, filtered by Rock, listed by newest, for a given artist
33
+ ### 1. Get 250 latest listings by a specific artist in the Rock genre, page 2
26
34
 
27
- ```js
35
+ ```ts
28
36
  // https://www.discogs.com/sell/list?sort=listed,desc&limit=250&artist_id=244819&page=2&genre=Rock
29
37
  const result = await DiscogsMarketplace.search({
30
- limit: 250,
31
- page: 2,
32
- genre: 'Rock',
33
- sort: 'Listed Newest',
34
38
  searchType: 'artist_id',
35
39
  searchValue: 244819,
40
+ genre: 'Rock',
41
+ sort: 'listed,desc',
42
+ limit: 250,
43
+ page: 2,
36
44
  })
37
45
  ```
38
46
 
39
- - Get top 50 items, of the 1st page, listed by price lowest, on a user wantlist
47
+ ### 2. Get listings of a user's wantlist, sorted by price, limit 50
40
48
 
41
- ```js
49
+ ```ts
42
50
  // https://www.discogs.com/sell/mywants?limit=50&user=Kirian_&sort=price,asc
43
51
  const result = await DiscogsMarketplace.search({
44
52
  limit: 50,
45
- page: 1,
46
- sort: 'Price Lowest',
53
+ sort: 'price,asc',
47
54
  searchType: 'user',
48
55
  searchValue: 'Kirian_',
49
56
  })
50
57
  ```
51
58
 
52
- - Get top 25 items, of the 1st page, listed by seller A-Z, on a release
59
+ ### 3. Get listings on a release, sorted by seller name
53
60
 
54
- ```js
55
- // https://www.discogs.com/sell/release/767931?sort=seller,asc&limit=25&page=1
61
+ ```ts
62
+ // https://www.discogs.com/sell/list?release_id=767931&sort=seller,asc&limit=25
63
+ // https://www.discogs.com/sell/release/767931?sort=seller,asc&limit=25
56
64
  const result = await DiscogsMarketplace.search({
57
- sort: 'Seller A-Z',
58
- page: 1,
59
65
  searchType: 'release_id',
60
66
  searchValue: '767931',
67
+ sort: 'seller,asc',
61
68
  })
62
69
  ```
63
70
 
64
- - Get top 100 items, of the 1st page, listed by newest, on a string search
71
+ ### 4. Get listings by a general search query (e.g., "in flames"), sorted by newest listings, limit 100
65
72
 
66
- ```js
73
+ ```ts
67
74
  // https://www.discogs.com/sell/list?sort=listed,desc&limit=100&q=in+flames&page=1
68
75
  const result = await DiscogsMarketplace.search({
69
- limit: 100,
70
- page: 1,
71
- sort: 'Listed Newest',
72
76
  searchType: 'q',
73
77
  searchValue: 'in flames',
78
+ sort: 'listed,desc',
79
+ limit: 100,
74
80
  })
75
81
  ```
76
82
 
77
- - Get top 25 items, of the 1st page, listed by newest, on a seller inventory
83
+ ### 5. Get newest listings on a seller inventory
78
84
 
79
- ```js
80
- // https://www.discogs.com/seller/Kirian_/profile?sort=listed,desc&limit=25&page=1
85
+ ```ts
86
+ // https://www.discogs.com/sell/list?sort=listed,desc&seller=Kirian_
87
+ // https://www.discogs.com/seller/Kirian_/profile?sort=listed,desc
81
88
  const result = await DiscogsMarketplace.search({
82
- sort: 'Listed Newest',
83
- page: 1,
89
+ sort: 'listed,desc',
84
90
  searchType: 'q',
85
- searchValue: '',
86
91
  seller: 'Kirian_',
87
92
  })
88
93
  ```
89
94
 
90
- - Get top 25 items, of the 1st page, listed by newest, on a user wantlist, on a seller inventory
95
+ ### 6. Get newest listings of a user's wantlist, on a seller inventory
91
96
 
92
- ```js
93
- // https://www.discogs.com/seller/Kirian_/mywants?sort=listed,desc&limit=25&user=Kirian_&page=1
97
+ ```ts
98
+ // https://www.discogs.com/sell/mywants?sort=listed,desc&seller=Kirian_&user=Kirian_
99
+ // https://www.discogs.com/seller/Kirian_/mywants?sort=listed,desc&user=Kirian_
94
100
  const result = await DiscogsMarketplace.search({
95
- sort: 'Listed Newest',
96
- page: 1,
101
+ sort: 'listed,desc',
97
102
  searchType: 'user',
98
103
  searchValue: 'Kirian_',
99
104
  seller: 'Kirian_',
100
105
  })
101
106
  ```
102
107
 
103
- - If you are making a lot of requests, you can pass a playwright page instance to reuse it:
108
+ ## 💁 Additional Features
104
109
 
105
- ```js
110
+ ### 1. Reuse a Playwright `Page` instance for faster scraping
111
+
112
+ ```ts
106
113
  const browser = await playwright.launch()
107
114
  const browserContext = await browser.newContext()
108
115
  const browserPage = await browserContext.newPage()
@@ -113,115 +120,134 @@ await browserContext.close()
113
120
  await browser.close()
114
121
  ```
115
122
 
116
- ## 📃 Data format
123
+ ### 2. Extract correct parameters from URL
124
+
125
+ ```ts
126
+ const searchParams = DiscogsMarketplace.getSearchParamsFromUrl('https://www.discogs.com/fr/sell/list?sort=listed,desc&limit=250&artist_id=244819&page=2&genre=Rock')
127
+ // {
128
+ // searchType: 'artist_id',
129
+ // searchValue: '244819',
130
+ // genre: 'Rock',
131
+ // sort: 'listed,desc',
132
+ // limit: 250,
133
+ // page: 2,
134
+ // lang: 'fr',
135
+ // }
136
+ ```
137
+
138
+ ## 🧩 API Reference
117
139
 
118
- You can provide parameters to `DiscogsMarketplace.search` function according to this interface:
140
+ The `DiscogsMarketplace.search` function accepts parameters defined by the following interface:
119
141
 
120
142
  ```ts
121
143
  interface SearchParams {
122
144
  /**
123
- * Type of elements to search.
124
- * | Name | Description |
125
- * |:---------: |:--------------------------:|
126
- * | q | Basic query search |
127
- * | master_id | Search in a master release |
128
- * | release_id | Search in a release |
129
- * | label_id | Search in a label |
130
- * | artist_id | Search in a artist |
131
- * | user | Search in user wantlist |
145
+ * The type of element to search.
146
+ * | Value | Description |
147
+ * |-------------|--------------------------------|
148
+ * | `q` | Basic query search |
149
+ * | `master_id` | Search within a master release |
150
+ * | `release_id`| Search within a release |
151
+ * | `label_id` | Search within a label |
152
+ * | `artist_id` | Search by artist |
153
+ * | `user` | Search a user's wantlist |
132
154
  * @default 'q'
133
155
  */
134
156
  searchType: Search
135
157
  /**
136
- * Value to search corresponding to the search type
158
+ * The search value corresponding to the selected `searchType`.
137
159
  */
138
160
  searchValue?: string | number
139
161
  /**
140
- * Currency
162
+ * Currency code for price filtering.
141
163
  * @example 'USD'
142
164
  */
143
165
  currency?: Currency
144
166
  /**
145
- * Genre
167
+ * Genre filter.
146
168
  * @example 'Rock'
147
169
  */
148
170
  genre?: Genre
149
171
  /**
150
- * Styles
172
+ * List of styles.
151
173
  * @example ['Death Metal', 'Heavy Metal']
152
174
  */
153
175
  style?: Array<Style>
154
176
  /**
155
- * Formats
177
+ * List of formats.
156
178
  * @example ['Vinyl', 'CD']
157
179
  */
158
180
  format?: Array<Format>
159
181
  /**
160
- * Format descriptions
182
+ * List of format descriptions.
161
183
  * @example ['Limited Edition', 'Numbered']
162
184
  */
163
185
  formatDescription?: Array<FormatDescription>
164
186
  /**
165
- * Media conditions
187
+ * List of media conditions.
166
188
  * @example ['Mint (M)', 'Very Good Plus (VG+)']
167
189
  */
168
190
  condition?: Array<Condition>
169
191
  /**
170
- * Year (Do not use it with `years`)
192
+ * Release year.
193
+ * Do not use together with `years`.
171
194
  */
172
195
  year?: number
173
196
  /**
174
- * Interval of years (Do not use it with `year`)
197
+ * Range of years.
198
+ * Do not use together with `year`.
175
199
  */
176
200
  years?: {
177
- /** Min */
201
+ /** Minimum year */
178
202
  min: number
179
- /** Max */
203
+ /** Maximum year */
180
204
  max: number
181
205
  }
182
206
  /**
183
- * Is audio sample ?
184
- * @default false
185
- */
186
- isAudioSample?: boolean
187
- /**
188
- * Is make an offer only ?
207
+ * If true, only listings that accept offers are returned.
189
208
  * @default false
190
209
  */
191
210
  isMakeAnOfferOnly?: boolean
192
211
  /**
193
- * Expedition country
212
+ * Expedition country filter (2-letter country code).
194
213
  * @example 'US'
195
214
  */
196
215
  from?: From
197
216
  /**
198
- * Seller name
217
+ * Seller's username filter.
199
218
  */
200
219
  seller?: string
201
220
  /**
202
- * Sort elements by.
203
- * @default 'Listed Newest'
221
+ * Hours range for wantlist searches.
222
+ * @example '0-24'
223
+ */
224
+ hoursRange?: HoursRange
225
+ /**
226
+ * Sort order for the results.
227
+ * @default 'listed,desc'
204
228
  */
205
229
  sort?: Sort
206
230
  /**
207
- * Limit of elements to search (25 | 50 | 100 | 250).
231
+ * Number of results to return per page.
232
+ * Allowed values: 25, 50, 100, 250.
208
233
  * @default 25
209
234
  */
210
235
  limit?: Limit
211
236
  /**
212
- * Page (Must be < 401 or discogs will return an error 404).
237
+ * Page number of results.
238
+ * Must be less than 401 to avoid Discogs 404 errors.
213
239
  * @default 1
214
240
  */
215
241
  page?: number
216
242
  /**
217
- * Lang to use for Discogs.
243
+ * Language code for Discogs interface.
218
244
  * @default 'en'
219
245
  */
220
246
  lang?: Lang
221
247
  }
222
248
  ```
223
249
 
224
- If success, it will return:
250
+ On success, it returns a result matching this interface:
225
251
 
226
252
  ```ts
227
253
  interface SearchResult {
@@ -288,28 +314,21 @@ interface SearchResult {
288
314
  }
289
315
  ```
290
316
 
291
- ## 💡 How to contribute
292
-
293
- There is a [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers) on that project already configured, feel free to use it.
294
-
295
- Install dependencies with:
296
-
297
- ```sh
298
- npm install
299
- ```
300
-
301
- You can open a pull request with your new additions.
302
-
303
- ## 🐛 Known issues/problems
317
+ ## 🛠️ Development & Contribution
304
318
 
305
- ### Playwright
319
+ - Clone the repo and use the included devcontainer/VSCode setup.
320
+ - Run: `npm install`
321
+ - Add your contribution.
322
+ - Use `npm test` to run unit tests.
323
+ - Open a pull request with your new additions! 🎉
306
324
 
307
- Install system dependencies:
325
+ ## 👉 Known Issues
308
326
 
309
- ```sh
310
- sudo npx playwright install-deps chromium
311
- ```
327
+ - Ensure all Playwright requirements are installed (see [Install system dependencies](https://playwright.dev/docs/browsers#install-system-dependencies)).
328
+ - Requests hitting page >400 will result in a 404.
329
+ - Some search parameters might not be compatible with every type of queries.
330
+ - For other edge cases, feel free to open an [issue on GitHub](https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS/issues).
312
331
 
313
- More information [here](https://playwright.dev/docs/browsers#install-system-dependencies).
332
+ ## 📃 License
314
333
 
315
- 👉 If you find another problem, feel free to open an issue.
334
+ Licensed under [MIT](https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS/blob/master/LICENSE).
@@ -0,0 +1,10 @@
1
+ import type SearchParams from './interfaces/search-params.interface.js';
2
+ /**
3
+ * Get search parameters from a Discogs Marketplace URL
4
+ * @param url Discogs Marketplace URL
5
+ * @returns Search parameters
6
+ * @example
7
+ * const searchParams = getSearchParamsFromUrl('https://www.discogs.com/sell/list?sort=listed,desc&limit=250&artist_id=244819&page=2&genre=Rock')
8
+ * // { searchType: 'artist_id', searchValue: '244819', genre: 'Rock', sort: 'listed,desc', limit: 250, page: 2 }
9
+ */
10
+ export default function getSearchParamsFromUrl(url: string): SearchParams;
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ /* eslint-disable no-restricted-syntax */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.default = getSearchParamsFromUrl;
5
+ /**
6
+ * Safely parse an integer from a string
7
+ * @param value String to parse
8
+ * @returns Parsed integer or undefined if parsing fails
9
+ */
10
+ const safeParseInt = (value) => {
11
+ const parsed = parseInt(value ?? '', 10);
12
+ return isNaN(parsed) ? undefined : parsed;
13
+ };
14
+ /**
15
+ * Get search parameters from a Discogs Marketplace URL
16
+ * @param url Discogs Marketplace URL
17
+ * @returns Search parameters
18
+ * @example
19
+ * const searchParams = getSearchParamsFromUrl('https://www.discogs.com/sell/list?sort=listed,desc&limit=250&artist_id=244819&page=2&genre=Rock')
20
+ * // { searchType: 'artist_id', searchValue: '244819', genre: 'Rock', sort: 'listed,desc', limit: 250, page: 2 }
21
+ */
22
+ function getSearchParamsFromUrl(url) {
23
+ const { searchParams: urlSearchParams, pathname, host } = new URL(url);
24
+ if (!host.includes('discogs.com')) {
25
+ throw new Error(`Invalid host: ${host}. Expected 'www.discogs.com' or 'discogs.com'.`);
26
+ }
27
+ const searchParams = {
28
+ searchType: 'q', // Default search type
29
+ };
30
+ // Retrieve the search type and value
31
+ const searchType = ['q', 'master_id', 'release_id', 'label_id', 'artist_id', 'user'].find(type => urlSearchParams.has(type));
32
+ if (searchType) {
33
+ searchParams.searchType = searchType;
34
+ const searchValue = urlSearchParams.get(searchType);
35
+ if (searchValue) {
36
+ searchParams.searchValue = searchValue;
37
+ }
38
+ }
39
+ // Retrieve basic search values
40
+ for (const key of ['currency', 'genre', 'ships_from', 'seller', 'sort', 'hours_range']) {
41
+ const value = urlSearchParams.get(key);
42
+ if (value) {
43
+ switch (key) {
44
+ case 'ships_from':
45
+ searchParams.from = value;
46
+ break;
47
+ case 'hours_range':
48
+ searchParams.hoursRange = value;
49
+ break;
50
+ default:
51
+ searchParams[key] = value;
52
+ break;
53
+ }
54
+ }
55
+ }
56
+ // Retrieve number search values
57
+ for (const key of ['limit', 'page']) {
58
+ const value = safeParseInt(urlSearchParams.get(key));
59
+ if (value) {
60
+ switch (key) {
61
+ case 'limit':
62
+ searchParams.limit = value;
63
+ break;
64
+ default:
65
+ searchParams[key] = value;
66
+ break;
67
+ }
68
+ }
69
+ }
70
+ // Retrieve array search values
71
+ for (const key of ['style', 'format', 'format_desc', 'condition']) {
72
+ const values = urlSearchParams.getAll(key);
73
+ if (values.length) {
74
+ switch (key) {
75
+ case 'format_desc':
76
+ searchParams.formatDescription = values;
77
+ break;
78
+ default:
79
+ searchParams[key] = values;
80
+ break;
81
+ }
82
+ }
83
+ }
84
+ // Check if search is on offers only
85
+ if (urlSearchParams.get('offers') === '1') {
86
+ searchParams.isMakeAnOfferOnly = true;
87
+ }
88
+ // Handle year and years
89
+ const year = safeParseInt(urlSearchParams.get('year'));
90
+ const year1 = safeParseInt(urlSearchParams.get('year1'));
91
+ const year2 = safeParseInt(urlSearchParams.get('year2'));
92
+ if (year) {
93
+ searchParams.year = year;
94
+ }
95
+ else if (year1 && year2) {
96
+ searchParams.years = { min: year1, max: year2 };
97
+ }
98
+ // Retrieve the language from the URL path
99
+ const pathSegments = pathname.split('/').filter(x => x);
100
+ if (/^[a-z]{2}$/i.test(pathSegments[0] ?? '')) {
101
+ searchParams.lang = pathSegments[0]?.toLowerCase();
102
+ }
103
+ // Handle specific case for release ID in the URL path
104
+ const releaseIdMatch = /\/sell\/release\/(\d+)/.exec(url);
105
+ if (releaseIdMatch?.[1]) {
106
+ searchParams.searchType = 'release_id';
107
+ searchParams.searchValue = releaseIdMatch[1];
108
+ }
109
+ // Handle specific case for seller profile in the URL path
110
+ const sellerProfileMatch = /\/seller\/([^/]+)\/profile/.exec(url);
111
+ if (sellerProfileMatch?.[1]) {
112
+ searchParams.seller = sellerProfileMatch[1];
113
+ }
114
+ // Handle specific case for seller name on wantlist in the URL path
115
+ const sellerMyWantsMatch = /\/seller\/([^/]+)\/mywants/.exec(url);
116
+ if (sellerMyWantsMatch?.[1]) {
117
+ searchParams.searchType = 'user';
118
+ searchParams.searchValue = urlSearchParams.get('user') ?? '';
119
+ searchParams.seller = sellerMyWantsMatch[1];
120
+ }
121
+ return searchParams;
122
+ }
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
- import search from './search';
2
- import type SearchParams from './interfaces/search-params.interface';
3
- import type SearchResult from './interfaces/search-result.interface';
1
+ import search from './search.js';
2
+ import getSearchParamsFromUrl from './get-search-params.js';
3
+ import type SearchParams from './interfaces/search-params.interface.js';
4
+ import type SearchResult from './interfaces/search-result.interface.js';
4
5
  /**
5
- * Discogs Marketplace API
6
- * @see https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS
6
+ * Discogs Marketplace API, tools for interacting with the Discogs Marketplace.
7
+ * @see {@link https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS GitHub Repository}
7
8
  */
8
9
  export declare const DiscogsMarketplace: {
9
10
  search: typeof search;
11
+ getSearchParamsFromUrl: typeof getSearchParamsFromUrl;
10
12
  };
11
13
  export type { SearchParams, SearchResult };
package/dist/index.js CHANGED
@@ -4,9 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DiscogsMarketplace = void 0;
7
- const search_1 = __importDefault(require("./search"));
7
+ const search_1 = __importDefault(require("./search.js"));
8
+ const get_search_params_1 = __importDefault(require("./get-search-params.js"));
8
9
  /**
9
- * Discogs Marketplace API
10
- * @see https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS
10
+ * Discogs Marketplace API, tools for interacting with the Discogs Marketplace.
11
+ * @see {@link https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS GitHub Repository}
11
12
  */
12
- exports.DiscogsMarketplace = { search: search_1.default };
13
+ exports.DiscogsMarketplace = { search: search_1.default, getSearchParamsFromUrl: get_search_params_1.default };
@@ -1,114 +1,119 @@
1
- import type { Condition } from '../types/condition.type';
2
- import type { Currency } from '../types/currency.type';
3
- import type { FormatDescription } from '../types/format-description.type';
4
- import type { Format } from '../types/format.type';
5
- import type { From } from '../types/from.type';
6
- import type { Genre } from '../types/genre.type';
7
- import type { Lang } from '../types/lang.type';
8
- import type { Limit } from '../types/limit.type';
9
- import type { Search } from '../types/search-type.type';
10
- import type { Sort } from '../types/sort.type';
11
- import type { Style } from '../types/style.type';
1
+ import type { Condition } from '../types/condition.type.js';
2
+ import type { Currency } from '../types/currency.type.js';
3
+ import type { FormatDescription } from '../types/format-description.type.js';
4
+ import type { Format } from '../types/format.type.js';
5
+ import type { From } from '../types/from.type.js';
6
+ import type { Genre } from '../types/genre.type.js';
7
+ import type { HoursRange } from '../types/hours-range.type.js';
8
+ import type { Lang } from '../types/lang.type.js';
9
+ import type { Limit } from '../types/limit.type.js';
10
+ import type { Search } from '../types/search-type.type.js';
11
+ import type { Sort } from '../types/sort.type.js';
12
+ import type { Style } from '../types/style.type.js';
12
13
  /**
13
- * Search parameters for Discogs Marketplace
14
+ * Parameters used to search listings on the Discogs Marketplace.
14
15
  */
15
16
  export default interface SearchParams {
16
17
  /**
17
- * Type of elements to search.
18
- * | Name | Description |
19
- * |:---------: |:--------------------------:|
20
- * | q | Basic query search |
21
- * | master_id | Search in a master release |
22
- * | release_id | Search in a release |
23
- * | label_id | Search in a label |
24
- * | artist_id | Search in a artist |
25
- * | user | Search in user wantlist |
18
+ * The type of element to search.
19
+ * | Value | Description |
20
+ * |-------------|--------------------------------|
21
+ * | `q` | Basic query search |
22
+ * | `master_id` | Search within a master release |
23
+ * | `release_id`| Search within a release |
24
+ * | `label_id` | Search within a label |
25
+ * | `artist_id` | Search by artist |
26
+ * | `user` | Search a user's wantlist |
26
27
  * @default 'q'
27
28
  */
28
29
  searchType: Search;
29
30
  /**
30
- * Value to search corresponding to the search type
31
+ * The search value corresponding to the selected `searchType`.
31
32
  */
32
33
  searchValue?: string | number;
33
34
  /**
34
- * Currency
35
+ * Currency code for price filtering.
35
36
  * @example 'USD'
36
37
  */
37
38
  currency?: Currency;
38
39
  /**
39
- * Genre
40
+ * Genre filter.
40
41
  * @example 'Rock'
41
42
  */
42
43
  genre?: Genre;
43
44
  /**
44
- * Styles
45
+ * List of styles.
45
46
  * @example ['Death Metal', 'Heavy Metal']
46
47
  */
47
48
  style?: Array<Style>;
48
49
  /**
49
- * Formats
50
+ * List of formats.
50
51
  * @example ['Vinyl', 'CD']
51
52
  */
52
53
  format?: Array<Format>;
53
54
  /**
54
- * Format descriptions
55
+ * List of format descriptions.
55
56
  * @example ['Limited Edition', 'Numbered']
56
57
  */
57
58
  formatDescription?: Array<FormatDescription>;
58
59
  /**
59
- * Media conditions
60
+ * List of media conditions.
60
61
  * @example ['Mint (M)', 'Very Good Plus (VG+)']
61
62
  */
62
63
  condition?: Array<Condition>;
63
64
  /**
64
- * Year (Do not use it with `years`)
65
+ * Release year.
66
+ * Do not use together with `years`.
65
67
  */
66
68
  year?: number;
67
69
  /**
68
- * Interval of years (Do not use it with `year`)
70
+ * Range of years.
71
+ * Do not use together with `year`.
69
72
  */
70
73
  years?: {
71
- /** Min */
74
+ /** Minimum year */
72
75
  min: number;
73
- /** Max */
76
+ /** Maximum year */
74
77
  max: number;
75
78
  };
76
79
  /**
77
- * Is audio sample ?
78
- * @default false
79
- */
80
- isAudioSample?: boolean;
81
- /**
82
- * Is make an offer only ?
80
+ * If true, only listings that accept offers are returned.
83
81
  * @default false
84
82
  */
85
83
  isMakeAnOfferOnly?: boolean;
86
84
  /**
87
- * Expedition country
85
+ * Expedition country filter (2-letter country code).
88
86
  * @example 'US'
89
87
  */
90
88
  from?: From;
91
89
  /**
92
- * Seller name
90
+ * Seller's username filter.
93
91
  */
94
92
  seller?: string;
95
93
  /**
96
- * Sort elements by.
97
- * @default 'Listed Newest'
94
+ * Hours range for wantlist searches.
95
+ * @example '0-24'
96
+ */
97
+ hoursRange?: HoursRange;
98
+ /**
99
+ * Sort order for the results.
100
+ * @default 'listed,desc'
98
101
  */
99
102
  sort?: Sort;
100
103
  /**
101
- * Limit of elements to search (25 | 50 | 100 | 250).
104
+ * Number of results to return per page.
105
+ * Allowed values: 25, 50, 100, 250.
102
106
  * @default 25
103
107
  */
104
108
  limit?: Limit;
105
109
  /**
106
- * Page (Must be < 401 or discogs will return an error 404).
110
+ * Page number of results.
111
+ * Must be less than 401 to avoid Discogs 404 errors.
107
112
  * @default 1
108
113
  */
109
114
  page?: number;
110
115
  /**
111
- * Lang to use for Discogs.
116
+ * Language code for Discogs interface.
112
117
  * @default 'en'
113
118
  */
114
119
  lang?: Lang;
@@ -1,118 +1,118 @@
1
- import type { CountryValues } from '../data/country.data';
2
- import type { CurrencyValues } from '../data/currency.data';
1
+ import type { CountryValues } from '../data/country.data.js';
2
+ import type { CurrencyValues } from '../data/currency.data.js';
3
3
  /**
4
- * Search result from Discogs Marketplace
4
+ * Result returned from a Discogs Marketplace search.
5
5
  */
6
6
  export default interface SearchResult {
7
- /** Items */
7
+ /** List of items matching the search query. */
8
8
  items: Array<{
9
- /** Id */
9
+ /** Unique identifier for the listing */
10
10
  id: number;
11
- /** Title */
11
+ /** Title details */
12
12
  title: {
13
- /** Original */
13
+ /** Full original title */
14
14
  original: string;
15
- /** Artist */
15
+ /** Artist name */
16
16
  artist: string;
17
- /** Item */
17
+ /** Item description */
18
18
  item: string;
19
- /** Formats */
19
+ /** Array of format names */
20
20
  formats: Array<string>;
21
21
  };
22
- /** Url */
22
+ /** URL to the listing on Discogs */
23
23
  url: string;
24
- /** Labels */
24
+ /** Array of label names */
25
25
  labels: Array<string>;
26
- /** Catnos */
26
+ /** Array of catalog numbers */
27
27
  catnos: Array<string>;
28
- /** ImageUrl */
28
+ /** URL to the item's image */
29
29
  imageUrl: string;
30
- /** Description */
30
+ /** Text description of the item */
31
31
  description: string;
32
- /** IsAcceptingOffer */
32
+ /** Indicates if offers are accepted */
33
33
  isAcceptingOffer: boolean;
34
- /** IsAvailable */
34
+ /** Availability status of the item */
35
35
  isAvailable: boolean;
36
- /** Condition */
36
+ /** Condition details */
37
37
  condition: {
38
- /** Media */
38
+ /** Media condition */
39
39
  media: {
40
- /** Full */
40
+ /** Full description */
41
41
  full: string;
42
- /** Short */
42
+ /** Short code */
43
43
  short: string;
44
44
  };
45
- /** Sleeve */
45
+ /** Sleeve condition */
46
46
  sleeve: {
47
- /** Full */
47
+ /** Full description */
48
48
  full: string;
49
- /** Short */
49
+ /** Short code */
50
50
  short: string;
51
51
  };
52
52
  };
53
- /** Seller */
53
+ /** Seller information */
54
54
  seller: {
55
- /** Name */
55
+ /** Seller's username */
56
56
  name: string;
57
- /** Url */
57
+ /** Seller's profile URL */
58
58
  url: string;
59
- /** Score */
59
+ /** Seller rating/score */
60
60
  score: string;
61
- /** Notes */
61
+ /** Number of notes/reviews */
62
62
  notes: number;
63
63
  };
64
- /** Price */
64
+ /** Pricing details */
65
65
  price: {
66
66
  /**
67
- * Base
67
+ * Base price as a string combining amount and currency.
68
68
  * @example '12.34 USD'
69
69
  */
70
70
  base: `${number} ${CurrencyValues}` | '';
71
71
  /**
72
- * Shipping
72
+ * Shipping cost as a string combining amount and currency.
73
73
  * @example '5.67 USD'
74
74
  */
75
75
  shipping: `${number} ${CurrencyValues}` | '';
76
76
  };
77
- /** From */
77
+ /** Shipping origin country */
78
78
  country: {
79
- /** Name */
79
+ /** Country name */
80
80
  name: string;
81
81
  /**
82
- * Iso code
82
+ * ISO country code
83
83
  * @example 'US'
84
84
  */
85
85
  code: CountryValues;
86
86
  };
87
- /** Community */
87
+ /** Community stats */
88
88
  community: {
89
- /** Have */
89
+ /** Number of users who have this item */
90
90
  have: number;
91
- /** Want */
91
+ /** Number of users who want this item */
92
92
  want: number;
93
93
  };
94
- /** Release */
94
+ /** Release details */
95
95
  release: {
96
- /** Id */
96
+ /** Release ID */
97
97
  id: number;
98
- /** Url */
98
+ /** Release URL */
99
99
  url: string;
100
100
  };
101
101
  }>;
102
- /** Page */
102
+ /** Pagination information */
103
103
  page: {
104
- /** Current */
104
+ /** Current page number */
105
105
  current: number;
106
- /** Total */
106
+ /** Total number of pages */
107
107
  total: number;
108
108
  };
109
- /** Result */
109
+ /** Overall search result metadata */
110
110
  result: {
111
- /** Total */
111
+ /** Total number of results found */
112
112
  total: number;
113
- /** PerPage */
113
+ /** Number of results per page */
114
114
  perPage: number;
115
115
  };
116
- /** UrlGenerated */
116
+ /** The generated URL used for the search */
117
117
  urlGenerated: string;
118
118
  }
package/dist/scrape.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type SearchResult from './interfaces/search-result.interface';
1
+ import type SearchResult from './interfaces/search-result.interface.js';
2
2
  /**
3
3
  * Parses the page and returns the items found.
4
4
  * This function is called by the browser context when the page is loaded.
package/dist/search.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { type Page } from 'playwright-chromium';
2
- import type SearchParams from './interfaces/search-params.interface';
3
- import type SearchResult from './interfaces/search-result.interface';
2
+ import type SearchParams from './interfaces/search-params.interface.js';
3
+ import type SearchResult from './interfaces/search-result.interface.js';
4
4
  /**
5
- * Search elements on discogs marketplace
5
+ * Performs a search on the Discogs marketplace using the provided parameters.
6
6
  * @param pageInstance
7
- * If you are making a lot of requests, you can pass a playwright page instance to reuse it.
8
- * That way, you can create a page once, reuse it for all requests and close it yourself at the end.
9
- * @returns Items found
7
+ * Optional Playwright page instance to reuse for multiple requests. This can be useful for reducing overhead when making numerous requests.
8
+ * If not provided, a new browser instance will be created and managed internally.
9
+ * @returns A promise that resolves to the search results, including items found, pagination details, and the generated URL.
10
10
  */
11
- export default function search({ searchType, searchValue, currency, genre, style, format, formatDescription, condition, year, years, isAudioSample, isMakeAnOfferOnly, from, seller, sort, limit, page, lang, }: SearchParams, pageInstance?: Page): Promise<SearchResult>;
11
+ export default function search({ searchType, searchValue, currency, genre, style, format, formatDescription, condition, year, years, isMakeAnOfferOnly, from, seller, hoursRange, sort, limit, page, lang, }: SearchParams, pageInstance?: Page): Promise<SearchResult>;
package/dist/search.js CHANGED
@@ -6,17 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.default = search;
7
7
  const user_agents_1 = __importDefault(require("user-agents"));
8
8
  const playwright_chromium_1 = require("playwright-chromium");
9
- const currency_data_1 = __importDefault(require("./data/currency.data"));
10
- const country_data_1 = __importDefault(require("./data/country.data"));
11
- const scrape_1 = __importDefault(require("./scrape"));
9
+ const currency_data_1 = __importDefault(require("./data/currency.data.js"));
10
+ const country_data_1 = __importDefault(require("./data/country.data.js"));
11
+ const scrape_1 = __importDefault(require("./scrape.js"));
12
12
  /**
13
- * Search elements on discogs marketplace
13
+ * Performs a search on the Discogs marketplace using the provided parameters.
14
14
  * @param pageInstance
15
- * If you are making a lot of requests, you can pass a playwright page instance to reuse it.
16
- * That way, you can create a page once, reuse it for all requests and close it yourself at the end.
17
- * @returns Items found
15
+ * Optional Playwright page instance to reuse for multiple requests. This can be useful for reducing overhead when making numerous requests.
16
+ * If not provided, a new browser instance will be created and managed internally.
17
+ * @returns A promise that resolves to the search results, including items found, pagination details, and the generated URL.
18
18
  */
19
- async function search({ searchType = 'q', searchValue, currency, genre, style, format, formatDescription, condition, year, years, isAudioSample = false, isMakeAnOfferOnly = false, from, seller, sort = 'Listed Newest', limit = 25, page = 1, lang = 'en', }, pageInstance) {
19
+ async function search({ searchType = 'q', searchValue, currency, genre, style, format, formatDescription, condition, year, years, isMakeAnOfferOnly = false, from, seller, hoursRange, sort = 'listed,desc', limit = 25, page = 1, lang = 'en', }, pageInstance) {
20
20
  /** Url to be called by the browser */
21
21
  const url = [
22
22
  generateUrl({ searchType, seller, lang }),
@@ -31,9 +31,9 @@ async function search({ searchType = 'q', searchValue, currency, genre, style, f
31
31
  year: year && !years ? year : null,
32
32
  year1: years?.min && !year ? years.min : null,
33
33
  year2: years?.max && !year ? years.max : null,
34
- audio: isAudioSample ? 1 : null,
35
34
  offers: isMakeAnOfferOnly ? 1 : null,
36
35
  ships_from: from,
36
+ hours_range: hoursRange,
37
37
  limit,
38
38
  page,
39
39
  sort,
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Hours range type
3
+ */
4
+ export type HoursRange = `${number}-${number}`;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,7 @@
1
+ type SortField = 'listed' | 'condition' | 'artist' | 'title' | 'label' | 'seller' | 'price';
2
+ type SortDirection = 'asc' | 'desc';
1
3
  /**
2
4
  * Sorts
3
5
  */
4
- export type Sort = 'Artist A-Z' | 'Artist Z-A' | 'Condition (M)-(P)' | 'Condition (P)-(M)' | 'Label A-Z' | 'Label Z-A' | 'Listed Newest' | 'Listed Oldest' | 'Price Highest' | 'Price Lowest' | 'Seller A-Z' | 'Seller Z-A' | 'Title A-Z' | 'Title Z-A' | ({} & string);
6
+ export type Sort = `${SortField},${SortDirection}` | ({} & string);
7
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discogs-marketplace-api-nodejs",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "description": "Another (better ?) NodeJs library to fetch data from Discogs marketplace",
5
5
  "keywords": [
6
6
  "discogs",
@@ -40,30 +40,30 @@
40
40
  }
41
41
  ],
42
42
  "dependencies": {
43
- "playwright-chromium": "^1.51.1",
44
- "user-agents": "^1.1.505"
43
+ "playwright-chromium": "^1.54.1",
44
+ "user-agents": "^1.1.603"
45
45
  },
46
46
  "devDependencies": {
47
- "@eslint/js": "^9.24.0",
48
- "@types/node": "^20.17.30",
47
+ "@eslint/js": "^9.31.0",
48
+ "@types/node": "^20.19.8",
49
49
  "@types/user-agents": "^1.0.4",
50
50
  "@typescript-eslint/eslint-plugin": "^8.29.1",
51
51
  "@typescript-eslint/parser": "^8.29.1",
52
- "cspell": "^8.18.1",
53
- "eslint": "^9.24.0",
54
- "eslint-config-prettier": "^10.1.2",
55
- "eslint-import-resolver-typescript": "^4.3.2",
56
- "eslint-plugin-import": "^2.31.0",
57
- "eslint-plugin-jsdoc": "^50.6.9",
58
- "globals": "^16.0.0",
52
+ "cspell": "^9.1.5",
53
+ "eslint": "^9.31.0",
54
+ "eslint-config-prettier": "^10.1.5",
55
+ "eslint-import-resolver-typescript": "^4.4.4",
56
+ "eslint-plugin-import": "^2.32.0",
57
+ "eslint-plugin-jsdoc": "^51.4.1",
58
+ "globals": "^16.3.0",
59
59
  "husky": "^9.1.7",
60
- "knip": "^5.50.2",
61
- "lint-staged": "^15.5.0",
62
- "prettier": "^3.5.3",
60
+ "knip": "^5.61.3",
61
+ "lint-staged": "^16.1.2",
62
+ "prettier": "^3.6.2",
63
63
  "rimraf": "^6.0.1",
64
- "tsc-alias": "^1.8.15",
65
- "tsx": "^4.19.3",
64
+ "tsc-alias": "^1.8.16",
65
+ "tsx": "^4.20.3",
66
66
  "typescript": "^5.8.3",
67
- "typescript-eslint": "^8.29.1"
67
+ "typescript-eslint": "^8.37.0"
68
68
  }
69
69
  }