discogs-marketplace-api-nodejs 1.10.1 → 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 +160 -133
- package/dist/data/{countries.data.d.ts → country.data.d.ts} +5 -2
- package/dist/data/{countries.data.js → country.data.js} +6 -6
- package/dist/data/{currencies.data.d.ts → currency.data.d.ts} +5 -2
- package/dist/data/{currencies.data.js → currency.data.js} +2 -2
- package/dist/get-search-params.d.ts +10 -0
- package/dist/get-search-params.js +122 -0
- package/dist/index.d.ts +13 -4
- package/dist/index.js +7 -2
- package/dist/interfaces/search-params.interface.d.ts +120 -0
- package/dist/interfaces/search-result.interface.d.ts +118 -0
- package/dist/scrape.d.ts +10 -0
- package/dist/scrape.js +126 -0
- package/dist/search.d.ts +11 -0
- package/dist/search.js +154 -0
- package/dist/types/condition.type.d.ts +1 -1
- package/dist/types/currency.type.d.ts +1 -1
- package/dist/types/format-description.type.d.ts +1 -1
- package/dist/types/format.type.d.ts +1 -1
- package/dist/types/from.type.d.ts +1 -1
- package/dist/types/genre.type.d.ts +1 -1
- package/dist/types/hours-range.type.d.ts +4 -0
- package/dist/types/lang.type.d.ts +1 -1
- package/dist/types/limit.type.d.ts +1 -1
- package/dist/types/search-type.type.d.ts +1 -1
- package/dist/types/sort.type.d.ts +4 -1
- package/dist/types/style.type.d.ts +1 -1
- package/package.json +19 -18
- package/dist/data/index.d.ts +0 -3
- package/dist/data/index.js +0 -10
- package/dist/interfaces/index.d.ts +0 -4
- package/dist/interfaces/input.interface.d.ts +0 -100
- package/dist/interfaces/output-error.interface.d.ts +0 -9
- package/dist/interfaces/output-success.interface.d.ts +0 -115
- package/dist/interfaces/output-success.interface.js +0 -2
- package/dist/marketplace.d.ts +0 -27
- package/dist/marketplace.js +0 -311
- package/dist/types/index.d.ts +0 -12
- package/dist/types/index.js +0 -2
- /package/dist/interfaces/{index.js → search-params.interface.js} +0 -0
- /package/dist/interfaces/{input.interface.js → search-result.interface.js} +0 -0
- /package/dist/{interfaces/output-error.interface.js → types/hours-range.type.js} +0 -0
package/README.MD
CHANGED
|
@@ -1,212 +1,256 @@
|
|
|
1
|
-
# Discogs Marketplace API NodeJS
|
|
1
|
+
# 🎧 Discogs Marketplace API NodeJS
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/discogs-marketplace-api-nodejs)  [](https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS/blob/master/LICENSE) [](https://www.paypal.me/KirianCaumes)
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
##
|
|
8
|
-
|
|
9
|
-
Run the following command in your project:
|
|
8
|
+
## 🚀 Installation
|
|
10
9
|
|
|
11
10
|
```sh
|
|
12
|
-
npm
|
|
11
|
+
npm install discogs-marketplace-api-nodejs
|
|
13
12
|
```
|
|
14
13
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
Import `DiscogsMarketplace` into your project:
|
|
14
|
+
## ⚡ Quick Start
|
|
18
15
|
|
|
19
|
-
```
|
|
20
|
-
// With ECMAScript 6 and +
|
|
16
|
+
```ts
|
|
21
17
|
import { DiscogsMarketplace } from 'discogs-marketplace-api-nodejs'
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
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)
|
|
25
29
|
```
|
|
26
30
|
|
|
27
|
-
##
|
|
31
|
+
## 📚 Usage Examples
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
### 1. Get 250 latest listings by a specific artist in the Rock genre, page 2
|
|
30
34
|
|
|
31
|
-
```
|
|
35
|
+
```ts
|
|
32
36
|
// https://www.discogs.com/sell/list?sort=listed,desc&limit=250&artist_id=244819&page=2&genre=Rock
|
|
33
37
|
const result = await DiscogsMarketplace.search({
|
|
34
|
-
limit: 250,
|
|
35
|
-
page: 2,
|
|
36
|
-
genre: 'Rock',
|
|
37
|
-
sort: 'Listed Newest',
|
|
38
38
|
searchType: 'artist_id',
|
|
39
39
|
searchValue: 244819,
|
|
40
|
+
genre: 'Rock',
|
|
41
|
+
sort: 'listed,desc',
|
|
42
|
+
limit: 250,
|
|
43
|
+
page: 2,
|
|
40
44
|
})
|
|
41
45
|
```
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
### 2. Get listings of a user's wantlist, sorted by price, limit 50
|
|
44
48
|
|
|
45
|
-
```
|
|
49
|
+
```ts
|
|
46
50
|
// https://www.discogs.com/sell/mywants?limit=50&user=Kirian_&sort=price,asc
|
|
47
51
|
const result = await DiscogsMarketplace.search({
|
|
48
52
|
limit: 50,
|
|
49
|
-
|
|
50
|
-
sort: 'Price Lowest',
|
|
53
|
+
sort: 'price,asc',
|
|
51
54
|
searchType: 'user',
|
|
52
55
|
searchValue: 'Kirian_',
|
|
53
56
|
})
|
|
54
57
|
```
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
### 3. Get listings on a release, sorted by seller name
|
|
57
60
|
|
|
58
|
-
```
|
|
59
|
-
// https://www.discogs.com/sell/
|
|
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
|
|
60
64
|
const result = await DiscogsMarketplace.search({
|
|
61
|
-
sort: 'Seller A-Z',
|
|
62
|
-
page: 1,
|
|
63
65
|
searchType: 'release_id',
|
|
64
66
|
searchValue: '767931',
|
|
67
|
+
sort: 'seller,asc',
|
|
65
68
|
})
|
|
66
69
|
```
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
### 4. Get listings by a general search query (e.g., "in flames"), sorted by newest listings, limit 100
|
|
69
72
|
|
|
70
|
-
```
|
|
73
|
+
```ts
|
|
71
74
|
// https://www.discogs.com/sell/list?sort=listed,desc&limit=100&q=in+flames&page=1
|
|
72
75
|
const result = await DiscogsMarketplace.search({
|
|
73
|
-
limit: 100,
|
|
74
|
-
page: 1,
|
|
75
|
-
sort: 'Listed Newest',
|
|
76
76
|
searchType: 'q',
|
|
77
77
|
searchValue: 'in flames',
|
|
78
|
+
sort: 'listed,desc',
|
|
79
|
+
limit: 100,
|
|
78
80
|
})
|
|
79
81
|
```
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
### 5. Get newest listings on a seller inventory
|
|
82
84
|
|
|
83
|
-
```
|
|
84
|
-
// https://www.discogs.com/
|
|
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
|
|
85
88
|
const result = await DiscogsMarketplace.search({
|
|
86
|
-
sort: '
|
|
87
|
-
page: 1,
|
|
89
|
+
sort: 'listed,desc',
|
|
88
90
|
searchType: 'q',
|
|
89
|
-
searchValue: '',
|
|
90
91
|
seller: 'Kirian_',
|
|
91
92
|
})
|
|
92
93
|
```
|
|
93
94
|
|
|
94
|
-
|
|
95
|
+
### 6. Get newest listings of a user's wantlist, on a seller inventory
|
|
95
96
|
|
|
96
|
-
```
|
|
97
|
-
// https://www.discogs.com/
|
|
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_
|
|
98
100
|
const result = await DiscogsMarketplace.search({
|
|
99
|
-
sort: '
|
|
100
|
-
page: 1,
|
|
101
|
+
sort: 'listed,desc',
|
|
101
102
|
searchType: 'user',
|
|
102
103
|
searchValue: 'Kirian_',
|
|
103
104
|
seller: 'Kirian_',
|
|
104
105
|
})
|
|
105
106
|
```
|
|
106
107
|
|
|
107
|
-
##
|
|
108
|
+
## 💁 Additional Features
|
|
109
|
+
|
|
110
|
+
### 1. Reuse a Playwright `Page` instance for faster scraping
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const browser = await playwright.launch()
|
|
114
|
+
const browserContext = await browser.newContext()
|
|
115
|
+
const browserPage = await browserContext.newPage()
|
|
116
|
+
|
|
117
|
+
const result = await DiscogsMarketplace.search({ searchType: 'q'}, browserPage)
|
|
118
|
+
|
|
119
|
+
await browserContext.close()
|
|
120
|
+
await browser.close()
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 2. Extract correct parameters from URL
|
|
108
124
|
|
|
109
|
-
|
|
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
|
|
139
|
+
|
|
140
|
+
The `DiscogsMarketplace.search` function accepts parameters defined by the following interface:
|
|
110
141
|
|
|
111
142
|
```ts
|
|
112
|
-
interface
|
|
143
|
+
interface SearchParams {
|
|
113
144
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* |
|
|
119
|
-
* |
|
|
120
|
-
* |
|
|
121
|
-
* |
|
|
122
|
-
* |
|
|
123
|
-
*
|
|
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 |
|
|
154
|
+
* @default 'q'
|
|
124
155
|
*/
|
|
125
|
-
searchType:
|
|
156
|
+
searchType: Search
|
|
126
157
|
/**
|
|
127
|
-
*
|
|
158
|
+
* The search value corresponding to the selected `searchType`.
|
|
128
159
|
*/
|
|
129
160
|
searchValue?: string | number
|
|
130
161
|
/**
|
|
131
|
-
* Currency
|
|
162
|
+
* Currency code for price filtering.
|
|
163
|
+
* @example 'USD'
|
|
132
164
|
*/
|
|
133
|
-
currency?:
|
|
165
|
+
currency?: Currency
|
|
134
166
|
/**
|
|
135
|
-
* Genre
|
|
167
|
+
* Genre filter.
|
|
168
|
+
* @example 'Rock'
|
|
136
169
|
*/
|
|
137
|
-
genre?:
|
|
170
|
+
genre?: Genre
|
|
138
171
|
/**
|
|
139
|
-
*
|
|
172
|
+
* List of styles.
|
|
173
|
+
* @example ['Death Metal', 'Heavy Metal']
|
|
140
174
|
*/
|
|
141
|
-
style?: Array<
|
|
175
|
+
style?: Array<Style>
|
|
142
176
|
/**
|
|
143
|
-
*
|
|
177
|
+
* List of formats.
|
|
178
|
+
* @example ['Vinyl', 'CD']
|
|
144
179
|
*/
|
|
145
|
-
format?: Array<
|
|
180
|
+
format?: Array<Format>
|
|
146
181
|
/**
|
|
147
|
-
*
|
|
182
|
+
* List of format descriptions.
|
|
183
|
+
* @example ['Limited Edition', 'Numbered']
|
|
148
184
|
*/
|
|
149
|
-
formatDescription?: Array<
|
|
185
|
+
formatDescription?: Array<FormatDescription>
|
|
150
186
|
/**
|
|
151
|
-
*
|
|
187
|
+
* List of media conditions.
|
|
188
|
+
* @example ['Mint (M)', 'Very Good Plus (VG+)']
|
|
152
189
|
*/
|
|
153
|
-
condition?: Array<
|
|
190
|
+
condition?: Array<Condition>
|
|
154
191
|
/**
|
|
155
|
-
*
|
|
192
|
+
* Release year.
|
|
193
|
+
* Do not use together with `years`.
|
|
156
194
|
*/
|
|
157
195
|
year?: number
|
|
158
196
|
/**
|
|
159
|
-
*
|
|
197
|
+
* Range of years.
|
|
198
|
+
* Do not use together with `year`.
|
|
160
199
|
*/
|
|
161
200
|
years?: {
|
|
162
|
-
/**
|
|
201
|
+
/** Minimum year */
|
|
163
202
|
min: number
|
|
164
|
-
/**
|
|
203
|
+
/** Maximum year */
|
|
165
204
|
max: number
|
|
166
205
|
}
|
|
167
206
|
/**
|
|
168
|
-
*
|
|
169
|
-
|
|
170
|
-
isAudioSample?: boolean
|
|
171
|
-
/**
|
|
172
|
-
* Is make an offer only ?
|
|
207
|
+
* If true, only listings that accept offers are returned.
|
|
208
|
+
* @default false
|
|
173
209
|
*/
|
|
174
210
|
isMakeAnOfferOnly?: boolean
|
|
175
211
|
/**
|
|
176
|
-
* Expedition country
|
|
212
|
+
* Expedition country filter (2-letter country code).
|
|
213
|
+
* @example 'US'
|
|
177
214
|
*/
|
|
178
|
-
from?:
|
|
215
|
+
from?: From
|
|
179
216
|
/**
|
|
180
|
-
* Seller
|
|
217
|
+
* Seller's username filter.
|
|
181
218
|
*/
|
|
182
219
|
seller?: string
|
|
183
220
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
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'
|
|
186
228
|
*/
|
|
187
|
-
sort?:
|
|
229
|
+
sort?: Sort
|
|
188
230
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
231
|
+
* Number of results to return per page.
|
|
232
|
+
* Allowed values: 25, 50, 100, 250.
|
|
233
|
+
* @default 25
|
|
191
234
|
*/
|
|
192
|
-
limit?:
|
|
235
|
+
limit?: Limit
|
|
193
236
|
/**
|
|
194
|
-
* Page
|
|
195
|
-
*
|
|
237
|
+
* Page number of results.
|
|
238
|
+
* Must be less than 401 to avoid Discogs 404 errors.
|
|
239
|
+
* @default 1
|
|
196
240
|
*/
|
|
197
241
|
page?: number
|
|
198
242
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
243
|
+
* Language code for Discogs interface.
|
|
244
|
+
* @default 'en'
|
|
201
245
|
*/
|
|
202
|
-
lang?:
|
|
246
|
+
lang?: Lang
|
|
203
247
|
}
|
|
204
248
|
```
|
|
205
249
|
|
|
206
|
-
|
|
250
|
+
On success, it returns a result matching this interface:
|
|
207
251
|
|
|
208
252
|
```ts
|
|
209
|
-
interface
|
|
253
|
+
interface SearchResult {
|
|
210
254
|
items: Array<{
|
|
211
255
|
id: number
|
|
212
256
|
title: {
|
|
@@ -239,12 +283,15 @@ interface OutputSuccessInterface {
|
|
|
239
283
|
notes: number
|
|
240
284
|
}
|
|
241
285
|
price: {
|
|
242
|
-
|
|
243
|
-
|
|
286
|
+
/** @example '12.34 USD' */
|
|
287
|
+
base: `${number} ${CurrencyValues}` | ''
|
|
288
|
+
/** @example '5.67 USD' */
|
|
289
|
+
shipping: `${number} ${CurrencyValues}` | ''
|
|
244
290
|
}
|
|
245
291
|
country: {
|
|
246
292
|
name: string
|
|
247
|
-
|
|
293
|
+
/** @example 'US' */
|
|
294
|
+
code: CountryValues
|
|
248
295
|
}
|
|
249
296
|
community: {
|
|
250
297
|
have: number
|
|
@@ -263,45 +310,25 @@ interface OutputSuccessInterface {
|
|
|
263
310
|
total: number
|
|
264
311
|
perPage: number
|
|
265
312
|
}
|
|
266
|
-
search: {
|
|
267
|
-
value: string | number
|
|
268
|
-
type: SearchTypeType
|
|
269
|
-
}
|
|
270
313
|
urlGenerated: string
|
|
271
314
|
}
|
|
272
315
|
```
|
|
273
316
|
|
|
274
|
-
|
|
317
|
+
## 🛠️ Development & Contribution
|
|
275
318
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
## 💡 How to contribute
|
|
284
|
-
|
|
285
|
-
There is a [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers) on that project already configured, feel free to use it.
|
|
286
|
-
|
|
287
|
-
Install dependencies with:
|
|
288
|
-
|
|
289
|
-
```sh
|
|
290
|
-
npm install
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
You can open a pull request with your new additions.
|
|
294
|
-
|
|
295
|
-
## 🐛 Known issues/problems
|
|
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! 🎉
|
|
296
324
|
|
|
297
|
-
|
|
325
|
+
## 👉 Known Issues
|
|
298
326
|
|
|
299
|
-
Install system dependencies
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
```
|
|
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).
|
|
304
331
|
|
|
305
|
-
|
|
332
|
+
## 📃 License
|
|
306
333
|
|
|
307
|
-
|
|
334
|
+
Licensed under [MIT](https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS/blob/master/LICENSE).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const
|
|
1
|
+
declare const Country: {
|
|
2
2
|
readonly Azerbaidjan: "AZ";
|
|
3
3
|
readonly Bolivia: "BO";
|
|
4
4
|
readonly 'Bosnia-Herzegovina': "BA";
|
|
@@ -303,4 +303,7 @@ declare const COUNTRIES: {
|
|
|
303
303
|
readonly Zambia: "ZM";
|
|
304
304
|
readonly Zimbabwe: "ZW";
|
|
305
305
|
};
|
|
306
|
-
export
|
|
306
|
+
export type CountryType = typeof Country;
|
|
307
|
+
export type CountryKeys = keyof CountryType;
|
|
308
|
+
export type CountryValues = CountryType[CountryKeys];
|
|
309
|
+
export default Country;
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
* ISO name
|
|
6
6
|
* {@link https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes}
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
8
|
+
const CountryIso = {
|
|
9
9
|
Afghanistan: 'AF',
|
|
10
10
|
'Åland Islands': 'AX',
|
|
11
11
|
Albania: 'AL',
|
|
@@ -268,7 +268,7 @@ const COUNTRIES_ISO = {
|
|
|
268
268
|
* .filter(x => !Object.keys(COUNTRIES_ISO).includes(x))
|
|
269
269
|
* .reduce((a,b) => ({ ...a, [b]: null }), {})
|
|
270
270
|
*/
|
|
271
|
-
const
|
|
271
|
+
const CountryDiscogs = {
|
|
272
272
|
Azerbaidjan: 'AZ',
|
|
273
273
|
Bolivia: 'BO',
|
|
274
274
|
'Bosnia-Herzegovina': 'BA',
|
|
@@ -324,8 +324,8 @@ const COUNTRIES_DISCOGS = {
|
|
|
324
324
|
Yugoslavia: 'GR',
|
|
325
325
|
Zaire: 'CD',
|
|
326
326
|
};
|
|
327
|
-
const
|
|
328
|
-
...
|
|
329
|
-
...
|
|
327
|
+
const Country = {
|
|
328
|
+
...CountryIso,
|
|
329
|
+
...CountryDiscogs,
|
|
330
330
|
};
|
|
331
|
-
exports.default =
|
|
331
|
+
exports.default = Country;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const
|
|
1
|
+
declare const Currency: {
|
|
2
2
|
readonly $US: "USD";
|
|
3
3
|
readonly US$: "USD";
|
|
4
4
|
readonly USD: "USD";
|
|
@@ -30,4 +30,7 @@ declare const CURRENCIES: {
|
|
|
30
30
|
readonly '\u00A3': "GBP";
|
|
31
31
|
readonly '\u00A5': "JPY";
|
|
32
32
|
};
|
|
33
|
-
export
|
|
33
|
+
export type CurrencyType = typeof Currency;
|
|
34
|
+
export type CurrencyKeys = keyof CurrencyType;
|
|
35
|
+
export type CurrencyValues = CurrencyType[CurrencyKeys];
|
|
36
|
+
export default Currency;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const Currency = {
|
|
4
4
|
$US: 'USD',
|
|
5
5
|
US$: 'USD',
|
|
6
6
|
USD: 'USD',
|
|
@@ -32,4 +32,4 @@ const CURRENCIES = {
|
|
|
32
32
|
'£': 'GBP',
|
|
33
33
|
'¥': 'JPY',
|
|
34
34
|
};
|
|
35
|
-
exports.default =
|
|
35
|
+
exports.default = Currency;
|
|
@@ -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,4 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
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';
|
|
5
|
+
/**
|
|
6
|
+
* Discogs Marketplace API, tools for interacting with the Discogs Marketplace.
|
|
7
|
+
* @see {@link https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS GitHub Repository}
|
|
8
|
+
*/
|
|
9
|
+
export declare const DiscogsMarketplace: {
|
|
10
|
+
search: typeof search;
|
|
11
|
+
getSearchParamsFromUrl: typeof getSearchParamsFromUrl;
|
|
12
|
+
};
|
|
13
|
+
export type { SearchParams, SearchResult };
|