discogs-marketplace-api-nodejs 1.5.1 → 1.5.2
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 +104 -37
- package/dist/interfaces/item.interface.d.ts +6 -8
- package/dist/marketplace.js +6 -7
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -1,49 +1,117 @@
|
|
|
1
1
|
# Discogs Marketplace API NodeJS · [](https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS/blob/master/LICENSE) [](https://www.npmjs.com/package/discogs-marketplace-api-nodejs)
|
|
2
2
|
|
|
3
|
-
Another (better ?) NodeJs library to fetch data from
|
|
3
|
+
Another (better ?) NodeJs library to fetch data from Discogs marketplace. 💿
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation (with npm)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Run the following command in your project:
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
10
|
npm install discogs-marketplace-api-nodejs
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
## Quick Start
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Import `DiscogsMarketplace` into your project:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
// With ECMAScript 6 and +
|
|
19
|
+
import DiscogsMarketplace from 'discogs-marketplace-api-nodejs'
|
|
20
|
+
|
|
21
|
+
// With CommonJS
|
|
22
|
+
const DiscogsMarketplace = require('discogs-marketplace-api-nodejs').default
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Examples
|
|
26
|
+
|
|
27
|
+
- Get top 250 items, of the 2nd page, filtered by Rock, listed by newest, for a given artist
|
|
16
28
|
|
|
17
29
|
```js
|
|
18
30
|
import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
|
|
19
31
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
// https://www.discogs.com/sell/list?sort=listed,desc&limit=250&artist_id=244819&page=2&genre=Rock
|
|
33
|
+
const result = await DiscogsMarketplace.search({
|
|
34
|
+
limit: 250,
|
|
35
|
+
page: 2,
|
|
36
|
+
genre: EGenre.ROCK,
|
|
37
|
+
sort: ESort.LISTED_NEWEST,
|
|
38
|
+
searchType: EType.ARTIST,
|
|
39
|
+
searchValue: 244819,
|
|
40
|
+
})
|
|
27
41
|
```
|
|
28
42
|
|
|
29
|
-
|
|
43
|
+
- Get top 50 items, of the 1st page, listed by price lowest, on a user wantlist
|
|
30
44
|
|
|
31
45
|
```js
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
DiscogsMarketplace.search({
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
|
|
47
|
+
|
|
48
|
+
// https://www.discogs.com/sell/mywants?limit=50&user=Kirian_&sort=price,asc
|
|
49
|
+
const result = await DiscogsMarketplace.search({
|
|
50
|
+
limit: 50,
|
|
51
|
+
sort: ESort.PRICE_LOWEST,
|
|
52
|
+
searchType: EType.USER,
|
|
53
|
+
searchValue: 'Kirian_',
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- Get top 25 items, of the 1st page, listed by seller A-Z, on a release
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
|
|
61
|
+
|
|
62
|
+
// https://www.discogs.com/sell/release/767931?sort=seller,asc&limit=25&page=1
|
|
63
|
+
const result = await DiscogsMarketplace.search({
|
|
64
|
+
sort: ESort.SELLER_AZ,
|
|
65
|
+
searchType: EType.RELEASE,
|
|
66
|
+
searchValue: '767931',
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- Get top 100 items, of the 1st page, listed by newest, on a string search
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
|
|
74
|
+
|
|
75
|
+
// https://www.discogs.com/sell/list?sort=listed,desc&limit=100&q=in+flames&page=1
|
|
76
|
+
const result = await DiscogsMarketplace.search({
|
|
77
|
+
limit: 100,
|
|
78
|
+
sort: ESort.LISTED_NEWEST,
|
|
79
|
+
searchType: EType.STRING,
|
|
80
|
+
searchValue: 'in flames',
|
|
81
|
+
})
|
|
42
82
|
```
|
|
43
83
|
|
|
44
|
-
|
|
84
|
+
- Get top 25 items, of the 1st page, listed by newest, on a seller inventory
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
|
|
88
|
+
|
|
89
|
+
// https://www.discogs.com/seller/Kirian_/profile?sort=listed,desc&limit=25&page=1
|
|
90
|
+
const result = await DiscogsMarketplace.search({
|
|
91
|
+
sort: ESort.LISTED_NEWEST,
|
|
92
|
+
searchType: EType.STRING,
|
|
93
|
+
searchValue: '',
|
|
94
|
+
seller: 'Kirian_',
|
|
95
|
+
})
|
|
96
|
+
```
|
|
45
97
|
|
|
46
|
-
|
|
98
|
+
- Get top 25 items, of the 1st page, listed by newest, on a user wantlist, on a seller inventory
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
|
|
102
|
+
|
|
103
|
+
// https://www.discogs.com/seller/Kirian_/mywants?sort=listed,desc&limit=25&user=Kirian_&page=1
|
|
104
|
+
const result = await DiscogsMarketplace.search({
|
|
105
|
+
sort: ESort.LISTED_NEWEST,
|
|
106
|
+
searchType: EType.USER,
|
|
107
|
+
searchValue: 'Kirian_',
|
|
108
|
+
seller: 'Kirian_',
|
|
109
|
+
})
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Data format
|
|
113
|
+
|
|
114
|
+
You can provide parameters to `DiscogsMarketplace.search` function according to this interface:
|
|
47
115
|
|
|
48
116
|
```ts
|
|
49
117
|
interface IInput {
|
|
@@ -122,7 +190,7 @@ interface IInput {
|
|
|
122
190
|
}
|
|
123
191
|
```
|
|
124
192
|
|
|
125
|
-
If success, it will return
|
|
193
|
+
If success, it will return:
|
|
126
194
|
|
|
127
195
|
```ts
|
|
128
196
|
interface IOutputSuccess {
|
|
@@ -177,15 +245,14 @@ interface IItem {
|
|
|
177
245
|
base: string
|
|
178
246
|
shipping: string
|
|
179
247
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
isoCountryCode: ECountryCode
|
|
248
|
+
country: {
|
|
249
|
+
name: string
|
|
250
|
+
code: ECountryCode
|
|
184
251
|
}
|
|
185
252
|
community: {
|
|
186
253
|
have: number
|
|
187
254
|
want: number
|
|
188
|
-
}
|
|
255
|
+
}
|
|
189
256
|
release: {
|
|
190
257
|
id: number
|
|
191
258
|
url: string
|
|
@@ -193,7 +260,7 @@ interface IItem {
|
|
|
193
260
|
}
|
|
194
261
|
```
|
|
195
262
|
|
|
196
|
-
If error, it will throw
|
|
263
|
+
If error, it will throw:
|
|
197
264
|
|
|
198
265
|
```ts
|
|
199
266
|
interface IOutputError {
|
|
@@ -202,19 +269,19 @@ interface IOutputError {
|
|
|
202
269
|
}
|
|
203
270
|
```
|
|
204
271
|
|
|
272
|
+
Other interfaces can be found in `src/interfaces`.
|
|
273
|
+
|
|
205
274
|
## How to contribute
|
|
206
275
|
|
|
207
|
-
There is a devcontainer on that project already configured, feel free to use it.
|
|
276
|
+
There is a [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers) on that project already configured, feel free to use it.
|
|
208
277
|
|
|
209
278
|
You can install dependecies with:
|
|
210
279
|
|
|
211
280
|
```sh
|
|
212
|
-
npm
|
|
281
|
+
npm install
|
|
213
282
|
```
|
|
214
283
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
Finally, you can open a pull request with your new additions.
|
|
284
|
+
You can open a pull request with your new additions.
|
|
218
285
|
|
|
219
286
|
## Know issues
|
|
220
287
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ECountryCode
|
|
1
|
+
import { ECountryCode } from '../enums/iso/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* One item from discogs
|
|
4
4
|
*/
|
|
@@ -66,13 +66,11 @@ export default interface IItem {
|
|
|
66
66
|
shipping: string;
|
|
67
67
|
};
|
|
68
68
|
/** From */
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
/** IsoCountryCode */
|
|
75
|
-
isoCountryCode: ECountryCode;
|
|
69
|
+
country: {
|
|
70
|
+
/** Name */
|
|
71
|
+
name: string;
|
|
72
|
+
/** Iso code */
|
|
73
|
+
code: ECountryCode;
|
|
76
74
|
};
|
|
77
75
|
/** Community */
|
|
78
76
|
community: {
|
package/dist/marketplace.js
CHANGED
|
@@ -155,13 +155,13 @@ class Marketplace {
|
|
|
155
155
|
((_d = (_c = (_b = (_a = document.querySelector('.pagination_total')) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.split(' ')) === null || _c === void 0 ? void 0 : _c.filter((x) => x).pop()) === null || _d === void 0 ? void 0 : _d.replace(/(,|\.|\s)/g, '')) || '0');
|
|
156
156
|
return {
|
|
157
157
|
items: ((_e = [...document.querySelectorAll('table.table_block tbody tr')]) === null || _e === void 0 ? void 0 : _e.map(el => {
|
|
158
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58
|
|
158
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58;
|
|
159
159
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
160
160
|
const shipping = this.convertCurrency((_g = (_f = (_e = (_d = (_c = (_b = (_a = el.querySelector('.item_shipping')) === null || _a === void 0 ? void 0 : _a.childNodes) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.textContent) === null || _d === void 0 ? void 0 : _d.replace(/(\s+|\+)/g, ' ')) === null || _e === void 0 ? void 0 : _e.trim()) === null || _f === void 0 ? void 0 : _f.replace(',', '.')) !== null && _g !== void 0 ? _g : '');
|
|
161
161
|
const have = Number.parseInt((_j = (_h = el.querySelector('.community_summary .community_result:nth-child(1) .community_number')) === null || _h === void 0 ? void 0 : _h.textContent) !== null && _j !== void 0 ? _j : '', 10);
|
|
162
162
|
const want = Number.parseInt((_l = (_k = el.querySelector('.community_summary .community_result:nth-child(2) .community_number')) === null || _k === void 0 ? void 0 : _k.textContent) !== null && _l !== void 0 ? _l : '', 10);
|
|
163
163
|
const countryName = (_q = (_p = (_o = (_m = el.querySelector('.seller_info li:nth-child(3)')) === null || _m === void 0 ? void 0 : _m.textContent) === null || _o === void 0 ? void 0 : _o.split(':')) === null || _p === void 0 ? void 0 : _p[1]) !== null && _q !== void 0 ? _q : '';
|
|
164
|
-
const
|
|
164
|
+
const countryCode = (Object.keys(iso_1.ECountryCode).find((key) => (iso_1.ECountryName[key] === countryName))
|
|
165
165
|
|| translate_1.EDiscogsCountryNameToIsoCode[countryName]);
|
|
166
166
|
const releaseId = Number.parseInt((_v = (_u = (_t = (_s = (_r = el.querySelector('a.item_release_link')) === null || _r === void 0 ? void 0 : _r.href.split('release/')) === null || _s === void 0 ? void 0 : _s.pop()) === null || _t === void 0 ? void 0 : _t.split('-')) === null || _u === void 0 ? void 0 : _u.shift()) !== null && _v !== void 0 ? _v : '0', 10);
|
|
167
167
|
const itemId = Number.parseInt((_y = (_x = (_w = el.querySelector('a.item_description_title')) === null || _w === void 0 ? void 0 : _w.href) === null || _x === void 0 ? void 0 : _x.split('/').pop()) !== null && _y !== void 0 ? _y : '0', 10);
|
|
@@ -208,10 +208,9 @@ class Marketplace {
|
|
|
208
208
|
base: this.convertCurrency((_57 = (_56 = (_55 = (_54 = el.querySelector('.price')) === null || _54 === void 0 ? void 0 : _54.textContent) === null || _55 === void 0 ? void 0 : _55.replace(/\s+/g, ' ')) === null || _56 === void 0 ? void 0 : _56.replace(/,/, '.')) !== null && _57 !== void 0 ? _57 : ''),
|
|
209
209
|
shipping: Number.isNaN(parseFloat(shipping)) ? null : shipping,
|
|
210
210
|
},
|
|
211
|
-
|
|
212
|
-
countryName,
|
|
213
|
-
|
|
214
|
-
isoCountryCode,
|
|
211
|
+
country: {
|
|
212
|
+
name: countryName,
|
|
213
|
+
code: countryCode,
|
|
215
214
|
},
|
|
216
215
|
community: {
|
|
217
216
|
have: Number.isNaN(have) ? 0 : have,
|
|
@@ -219,7 +218,7 @@ class Marketplace {
|
|
|
219
218
|
},
|
|
220
219
|
release: {
|
|
221
220
|
id: Number.isNaN(releaseId) ? 0 : releaseId,
|
|
222
|
-
url: `https://www.discogs.com${(
|
|
221
|
+
url: `https://www.discogs.com${(_58 = el.querySelector('a.item_release_link')) === null || _58 === void 0 ? void 0 : _58.href}`,
|
|
223
222
|
},
|
|
224
223
|
};
|
|
225
224
|
})) || [],
|