discogs-marketplace-api-nodejs 1.8.1 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.MD CHANGED
@@ -4,10 +4,15 @@ Another (better ?) NodeJs library to fetch data from Discogs marketplace. 💿
4
4
 
5
5
  ## 📂 Installation (with npm)
6
6
 
7
+ This library works with two different `strategies` to scrape data: with a classic HTTP fetch request (Axios) or by creating a new instance of a browser (Playwright). Take a look at the "[About strategies](#-about-strategies)" chapter to learn more.
8
+
7
9
  Run the following command in your project:
8
10
 
9
11
  ```sh
10
12
  npm install discogs-marketplace-api-nodejs
13
+
14
+ # Or to avoid installing Playwright
15
+ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install discogs-marketplace-api-nodejs
11
16
  ```
12
17
 
13
18
  ## ▶️ Quick Start
@@ -102,6 +107,31 @@ const result = await DiscogsMarketplace.search({
102
107
  })
103
108
  ```
104
109
 
110
+ ## 🤠 About strategies
111
+
112
+ > Which `strategy` should I choose?
113
+
114
+ This project provides two ways to scrape data:
115
+
116
+ - `fetch` (default): Get the result with a classic HTTP fetch request (Axios).
117
+ - For the moment, this is the simplest and fastest solution to choose.
118
+ - `browser`: Get the result by creating a new instance of a browser (Playwright) to scrape the page.
119
+ - This can help bypass Cloudflare (or other) protection for some cases.
120
+ - Slightly slower than `fetch` (see [benchmarks](https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS/releases/tag/v1.8.1))
121
+
122
+ **Both strategies will give you the exact same result.**
123
+
124
+ I choose to maintain this two solutions, because over time Discogs is changing: one day they activated a protection that prevented a `fetch` solution from working, so I implemented to `browser` solution. But a few days later, they disabled that protection and the original solution became the best again.
125
+
126
+ With both strategies, you are free to choose the one that suits you!
127
+
128
+ ```js
129
+ const result = await DiscogsMarketplace.search({
130
+ // ...
131
+ strategy: 'fetch' // or 'browser'
132
+ })
133
+ ```
134
+
105
135
  ## 📃 Data format
106
136
 
107
137
  You can provide parameters to `DiscogsMarketplace.search` function according to this interface:
@@ -198,6 +228,12 @@ interface InputInterface {
198
228
  * Default to `en`.
199
229
  */
200
230
  lang?: LangType
231
+ /**
232
+ * Strategy to scrape data:
233
+ * - `fetch` (default): Get the result with a classic HTTP fetch request (Axios).
234
+ * - `browser`: Get the result by creating a new instance of a browser (Playwright) to scrape the page. This can help bypass Cloudflare (or other) protection for some cases.
235
+ */
236
+ strategy?: 'fetch' | 'browser'
201
237
  }
202
238
  ```
203
239
 
@@ -292,6 +328,20 @@ You can open a pull request with your new additions.
292
328
 
293
329
  ## 🐛 Known issues/problems
294
330
 
331
+ ### Linkedom
332
+
333
+ If you are using this library on a Typescript project, you might encounter issues with `linkedom`.
334
+
335
+ To fix it, use this in command line: `--skipLibCheck` or add that in you `tsconfig.json`:
336
+
337
+ ```json
338
+ {
339
+ "compilerOptions": {
340
+ "skipLibCheck": true
341
+ }
342
+ }
343
+ ```
344
+
295
345
  ### Playwright
296
346
 
297
347
  Install system dependencies:
@@ -302,4 +352,4 @@ sudo npx playwright install-deps chromium
302
352
 
303
353
  More information [here](https://playwright.dev/docs/browsers#install-system-dependencies).
304
354
 
305
- If you found another problem, feel free to open an issue.
355
+ 👉 If you find another problem, feel free to open an issue.
@@ -291,12 +291,12 @@ const COUNTRIES_DISCOGS = {
291
291
  Macedonia: 'MK',
292
292
  'Martinique (French)': 'MQ',
293
293
  Micronesia: 'FM',
294
- 'Netherlands Antilles': 'CW',
294
+ 'Netherlands Antilles': 'CW', // Or SX
295
295
  'Neutral Zone': '',
296
296
  'New Caledonia (French)': 'NC',
297
297
  'Pitcairn Island': 'PN',
298
298
  'Polynesia (French)': 'PF',
299
- 'Reunion (French)': 'RE',
299
+ 'Reunion (French)': 'RE', //
300
300
  'S. Georgia & S. Sandwich Isls.': 'GS',
301
301
  'Saint Helena': 'SH',
302
302
  'Saint Kitts & Nevis Anguilla': 'KN',
@@ -304,7 +304,7 @@ const COUNTRIES_DISCOGS = {
304
304
  'Saint Vincent & Grenadines': 'VC',
305
305
  'Slovak Republic': 'SK',
306
306
  'South Korea': 'KR',
307
- 'Spain (Canary Islands)': 'IC',
307
+ 'Spain (Canary Islands)': 'IC', //
308
308
  'Svalbard and Jan Mayen Islands': 'SJ',
309
309
  Swaziland: 'SZ',
310
310
  Syria: 'SY',
@@ -75,23 +75,34 @@ interface InputInterface {
75
75
  seller?: string;
76
76
  /**
77
77
  * Sort elements by.
78
+ *
78
79
  * Default to `Listed Newest`.
79
80
  */
80
81
  sort?: SortType;
81
82
  /**
82
83
  * Limit of elements to search (25 | 50 | 100 | 250).
84
+ *
83
85
  * Default to `25`.
84
86
  */
85
87
  limit?: LimitType;
86
88
  /**
87
89
  * Page (Must be < 401 or discogs will return an error 404).
90
+ *
88
91
  * Default to `1`.
89
92
  */
90
93
  page?: number;
91
94
  /**
92
95
  * Lang to use for Discogs.
96
+ *
93
97
  * Default to `en`.
94
98
  */
95
99
  lang?: LangType;
100
+ /**
101
+ * Strategy to scrape data:
102
+ * - `fetch` (default): Get the result with a classic HTTP fetch request (Axios).
103
+ * - `browser`: Get the result by creating a new instance of a browser (Playwright) to scrape the page.
104
+ * This can help bypass Cloudflare (or other) protection for some cases.
105
+ */
106
+ strategy?: 'fetch' | 'browser';
96
107
  }
97
108
  export default InputInterface;
@@ -7,7 +7,7 @@ export default abstract class Marketplace {
7
7
  * Search elements on discogs
8
8
  * @returns Items found
9
9
  */
10
- static search({ searchType, searchValue, currency, genre, style, format, formatDescription, condition, year, years, isAudioSample, isMakeAnOfferOnly, from, seller, sort, limit, page, lang, }: InputInterface): Promise<OutputSuccessInterface>;
10
+ static search({ searchType, searchValue, currency, genre, style, format, formatDescription, condition, year, years, isAudioSample, isMakeAnOfferOnly, from, seller, sort, limit, page, lang, strategy, }: InputInterface): Promise<OutputSuccessInterface>;
11
11
  /**
12
12
  * Generate URL to be parsed
13
13
  * @returns Url
@@ -19,6 +19,16 @@ export default abstract class Marketplace {
19
19
  * @returns Url
20
20
  */
21
21
  private static serializeParams;
22
+ /**
23
+ * Get result with a classic HTTP fetch request (Axios)
24
+ * @param url Url
25
+ */
26
+ private static getResultWithFetch;
27
+ /**
28
+ * Get result by creating a new instance of a navigator (Playwright) to crawl the page
29
+ * @param url Url
30
+ */
31
+ private static getResultWithBrowser;
22
32
  /**
23
33
  * Parse HTML to clean result
24
34
  * @returns Items found
@@ -5,6 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const user_agents_1 = __importDefault(require("user-agents"));
7
7
  const playwright_chromium_1 = require("playwright-chromium");
8
+ const linkedom_1 = require("linkedom");
9
+ const axios_1 = __importDefault(require("axios"));
8
10
  const data_1 = require("./data/index.js");
9
11
  /**
10
12
  * Discogs Marketplace
@@ -14,40 +16,8 @@ class Marketplace {
14
16
  * Search elements on discogs
15
17
  * @returns Items found
16
18
  */
17
- static async search({ searchType = 'q', searchValue = undefined, currency = undefined, genre = undefined, style = [], format = [], formatDescription = [], condition = [], year = undefined, years = undefined, isAudioSample = false, isMakeAnOfferOnly = false, from = undefined, seller = undefined, sort = 'Listed Newest', limit = 25, page = 1, lang = 'en', }) {
18
- var _a;
19
+ static async search({ searchType = 'q', searchValue = undefined, currency = undefined, genre = undefined, style = [], format = [], formatDescription = [], condition = [], year = undefined, years = undefined, isAudioSample = false, isMakeAnOfferOnly = false, from = undefined, seller = undefined, sort = 'Listed Newest', limit = 25, page = 1, lang = 'en', strategy = 'fetch', }) {
19
20
  try {
20
- /** Init browser */
21
- const browser = await playwright_chromium_1.chromium.launch({
22
- args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gl-drawing-for-tests'],
23
- });
24
- /** Init context */
25
- const browserContext = await browser.newContext({
26
- userAgent: new user_agents_1.default({ platform: 'Win32' }).toString(),
27
- extraHTTPHeaders: {
28
- 'X-PJAX': 'true',
29
- },
30
- javaScriptEnabled: false,
31
- });
32
- /** Init page */
33
- const browserPage = await browserContext.newPage();
34
- /** Block useless resources */
35
- await browserPage.route('**/*', route => [
36
- 'stylesheet',
37
- 'image',
38
- 'media',
39
- 'font',
40
- 'script',
41
- 'texttrack',
42
- 'xhr',
43
- 'fetch',
44
- 'eventsource',
45
- 'websocket',
46
- 'manifest',
47
- 'other',
48
- ].includes(route.request().resourceType())
49
- ? route.abort()
50
- : route.continue());
51
21
  /** Url to call */
52
22
  const url = [
53
23
  this.generateUrl({ searchType, seller, lang }),
@@ -70,39 +40,23 @@ class Marketplace {
70
40
  sort,
71
41
  }),
72
42
  ].join('?');
73
- /** Init page */
74
- const response = await browserPage.goto(url, { waitUntil: 'domcontentloaded' });
75
- /** Status code from the page */
76
- const status = (response === null || response === void 0 ? void 0 : response.status()) || 500;
77
- /** If error, reject */
78
- if (status >= 400) {
79
- // eslint-disable-next-line @typescript-eslint/no-throw-literal
80
- throw {
81
- message: (_a = (await browserPage.evaluate(() => { var _a, _b; return (_b = (_a = document === null || document === void 0 ? void 0 : document.querySelector('h1 + p')) === null || _a === void 0 ? void 0 : _a.innerHTML) === null || _b === void 0 ? void 0 : _b.trim(); }))) !== null && _a !== void 0 ? _a : 'An error occurred',
82
- code: status,
83
- };
84
- }
85
- /** Url generated by browser */
86
- const urlGenerated = browserPage.url();
87
- /**
88
- * Result from scraping.
89
- * Scraping inside Playwright is faster (x2) compare to exporting HTML outside and parsing it with another library.
90
- */
91
- const result = await browserPage.evaluate(this.getResult, {
92
- input: {
93
- page,
94
- limit,
95
- searchValue,
96
- searchType,
97
- },
98
- dependencies: {
99
- urlGenerated,
100
- CURRENCIES: data_1.CURRENCIES,
101
- COUNTRIES: data_1.COUNTRIES,
102
- },
103
- });
104
- /** Close browser */
105
- await browser.close();
43
+ /** Result got by different strategy type */
44
+ const result = await (async () => {
45
+ switch (strategy) {
46
+ case 'fetch':
47
+ return this.getResultWithFetch({
48
+ input: { page, limit, searchValue, searchType },
49
+ dependencies: { url },
50
+ });
51
+ case 'browser':
52
+ return this.getResultWithBrowser({
53
+ input: { page, limit, searchValue, searchType },
54
+ dependencies: { url },
55
+ });
56
+ default:
57
+ throw new Error('Unreachable');
58
+ }
59
+ })();
106
60
  return result;
107
61
  }
108
62
  catch (error) {
@@ -166,11 +120,115 @@ class Marketplace {
166
120
  }
167
121
  return param.join('&');
168
122
  }
123
+ /**
124
+ * Get result with a classic HTTP fetch request (Axios)
125
+ * @param url Url
126
+ */
127
+ static async getResultWithFetch({ input: { page, limit, searchValue, searchType }, dependencies: { url }, }) {
128
+ var _a, _b, _c;
129
+ const { data: bodyHTML, status } = await axios_1.default.get(url, {
130
+ headers: {
131
+ // cspell: disable-next-line
132
+ 'X-PJAX': 'true',
133
+ 'User-Agent': new user_agents_1.default({ platform: 'Win32' }).toString(),
134
+ },
135
+ });
136
+ /** Generate document */
137
+ const { document } = (0, linkedom_1.parseHTML)(bodyHTML);
138
+ /** If error, reject */
139
+ if (status >= 400) {
140
+ // eslint-disable-next-line @typescript-eslint/no-throw-literal
141
+ throw {
142
+ message: (_c = (_b = (_a = document === null || document === void 0 ? void 0 : document.querySelector('h1 + p')) === null || _a === void 0 ? void 0 : _a.innerHTML) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : 'An error occurred',
143
+ code: status,
144
+ };
145
+ }
146
+ const result = this.getResult({
147
+ input: { page, limit, searchValue, searchType },
148
+ dependencies: { urlGenerated: url, CURRENCIES: data_1.CURRENCIES, COUNTRIES: data_1.COUNTRIES },
149
+ document,
150
+ });
151
+ return result;
152
+ }
153
+ /**
154
+ * Get result by creating a new instance of a navigator (Playwright) to crawl the page
155
+ * @param url Url
156
+ */
157
+ static async getResultWithBrowser({ input: { page, limit, searchValue, searchType }, dependencies: { url }, }) {
158
+ var _a;
159
+ /** Init browser */
160
+ const browser = await playwright_chromium_1.chromium.launch({
161
+ args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gl-drawing-for-tests'],
162
+ });
163
+ /** Init context */
164
+ const browserContext = await browser.newContext({
165
+ userAgent: new user_agents_1.default({ platform: 'Win32' }).toString(),
166
+ extraHTTPHeaders: {
167
+ 'X-PJAX': 'true',
168
+ },
169
+ javaScriptEnabled: false,
170
+ });
171
+ /** Init page */
172
+ const browserPage = await browserContext.newPage();
173
+ /** Block useless resources */
174
+ await browserPage.route('**/*', route => [
175
+ 'stylesheet',
176
+ 'image',
177
+ 'media',
178
+ 'font',
179
+ 'script',
180
+ 'texttrack',
181
+ 'xhr',
182
+ 'fetch',
183
+ 'eventsource',
184
+ 'websocket',
185
+ 'manifest',
186
+ 'other',
187
+ ].includes(route.request().resourceType())
188
+ ? route.abort()
189
+ : route.continue());
190
+ /** Init page */
191
+ const response = await browserPage.goto(url, { waitUntil: 'domcontentloaded' });
192
+ /** Status code from the page */
193
+ const status = (response === null || response === void 0 ? void 0 : response.status()) || 500;
194
+ /** If error, reject */
195
+ if (status >= 400) {
196
+ // eslint-disable-next-line @typescript-eslint/no-throw-literal
197
+ throw {
198
+ message: (_a = (await browserPage.evaluate(() => { var _a, _b; return (_b = (_a = document === null || document === void 0 ? void 0 : document.querySelector('h1 + p')) === null || _a === void 0 ? void 0 : _a.innerHTML) === null || _b === void 0 ? void 0 : _b.trim(); }))) !== null && _a !== void 0 ? _a : 'An error occurred',
199
+ code: status,
200
+ };
201
+ }
202
+ /** Url generated by browser */
203
+ const urlGenerated = browserPage.url();
204
+ /**
205
+ * Result from scraping.
206
+ * Scraping inside Playwright is faster (x2) compare to exporting HTML outside and parsing it with another library.
207
+ */
208
+ const result = await browserPage.evaluate(this.getResult, {
209
+ input: {
210
+ page,
211
+ limit,
212
+ searchValue,
213
+ searchType,
214
+ },
215
+ dependencies: {
216
+ urlGenerated,
217
+ CURRENCIES: data_1.CURRENCIES,
218
+ COUNTRIES: data_1.COUNTRIES,
219
+ },
220
+ });
221
+ /** Close context/browser */
222
+ await browserContext.close();
223
+ await browser.close();
224
+ return result;
225
+ }
169
226
  /**
170
227
  * Parse HTML to clean result
171
228
  * @returns Items found
172
229
  */
173
- static getResult({ input: { page, limit, searchValue, searchType }, dependencies: { urlGenerated, CURRENCIES, COUNTRIES }, }) {
230
+ static getResult({ input: { page, limit, searchValue, searchType }, dependencies: { urlGenerated, CURRENCIES, COUNTRIES }, document = globalThis.document, // Note: this default value will only work with Playwright
231
+ }) {
174
232
  var _a, _b, _c, _d, _e;
175
233
  /**
176
234
  * Function to convert currency to ISO name
@@ -197,7 +255,7 @@ class Marketplace {
197
255
  .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');
198
256
  return {
199
257
  items: ((_e = [...document.querySelectorAll('table.table_block tbody tr')]) === null || _e === void 0 ? void 0 : _e.map(el => {
200
- 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;
258
+ 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, _59;
201
259
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
202
260
  const shipping = convertCurrency((_g = (_f = (_e = (_d = (_c = (_b = (_a = el
203
261
  .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 : '');
@@ -205,54 +263,56 @@ class Marketplace {
205
263
  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);
206
264
  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.pop()) !== null && _q !== void 0 ? _q : '';
207
265
  const countryCode = COUNTRIES[countryName];
208
- 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);
209
- 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);
210
- const notes = Number.parseInt((_5 = (_4 = (_3 = (_2 = (_1 = (_0 = (_z = el
211
- .querySelector('.seller_info li:nth-child(2) .section_link')) === null || _z === void 0 ? void 0 : _z.textContent) === null || _0 === void 0 ? void 0 : _0.replace(/\s+/g, ' ')) === null || _1 === void 0 ? void 0 : _1.trim()) === null || _2 === void 0 ? void 0 : _2.split(' ')) === null || _3 === void 0 ? void 0 : _3[0]) === null || _4 === void 0 ? void 0 : _4.replace(/,/g, '')) !== null && _5 !== void 0 ? _5 : '', 10);
212
- const originalTitle = (_6 = el.querySelector('a.item_description_title')) === null || _6 === void 0 ? void 0 : _6.textContent;
213
- const firstIndexOfDash = (_7 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.indexOf(' - ')) !== null && _7 !== void 0 ? _7 : -1;
214
- const lastIndexOfParenthesis = (_8 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.lastIndexOf(' (')) !== null && _8 !== void 0 ? _8 : -1;
266
+ const releaseId = Number.parseInt((_w = (_v = (_u = (_t = (_s = (_r = el
267
+ .querySelector('a.item_release_link')) === null || _r === void 0 ? void 0 : _r.getAttribute('href')) === null || _s === void 0 ? void 0 : _s.split('release/')) === null || _t === void 0 ? void 0 : _t.pop()) === null || _u === void 0 ? void 0 : _u.split('-')) === null || _v === void 0 ? void 0 : _v.shift()) !== null && _w !== void 0 ? _w : '0', 10);
268
+ const itemId = Number.parseInt((_z = (_y = (_x = el.querySelector('a.item_description_title')) === null || _x === void 0 ? void 0 : _x.getAttribute('href')) === null || _y === void 0 ? void 0 : _y.split('/').pop()) !== null && _z !== void 0 ? _z : '0', 10);
269
+ const notes = Number.parseInt((_6 = (_5 = (_4 = (_3 = (_2 = (_1 = (_0 = el
270
+ .querySelector('.seller_info li:nth-child(2) .section_link')) === null || _0 === void 0 ? void 0 : _0.textContent) === null || _1 === void 0 ? void 0 : _1.replace(/\s+/g, ' ')) === null || _2 === void 0 ? void 0 : _2.trim()) === null || _3 === void 0 ? void 0 : _3.split(' ')) === null || _4 === void 0 ? void 0 : _4[0]) === null || _5 === void 0 ? void 0 : _5.replace(/,/g, '')) !== null && _6 !== void 0 ? _6 : '', 10);
271
+ const originalTitle = (_7 = el.querySelector('a.item_description_title')) === null || _7 === void 0 ? void 0 : _7.textContent;
272
+ const firstIndexOfDash = (_8 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.indexOf(' - ')) !== null && _8 !== void 0 ? _8 : -1;
273
+ const lastIndexOfParenthesis = (_9 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.lastIndexOf(' (')) !== null && _9 !== void 0 ? _9 : -1;
215
274
  return {
216
275
  id: Number.isNaN(itemId) ? 0 : itemId,
217
276
  title: {
218
277
  original: originalTitle !== null && originalTitle !== void 0 ? originalTitle : '',
219
- artist: (_9 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(0, firstIndexOfDash)) !== null && _9 !== void 0 ? _9 : '',
278
+ artist: (_10 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(0, firstIndexOfDash)) !== null && _10 !== void 0 ? _10 : '',
220
279
  item: firstIndexOfDash > -1 && lastIndexOfParenthesis > -1
221
- ? (_10 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(firstIndexOfDash + 3, lastIndexOfParenthesis)) !== null && _10 !== void 0 ? _10 : ''
280
+ ? (_11 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(firstIndexOfDash + 3, lastIndexOfParenthesis)) !== null && _11 !== void 0 ? _11 : ''
222
281
  : '',
223
282
  formats: lastIndexOfParenthesis > -1
224
- ? (_12 = (_11 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(lastIndexOfParenthesis + 2, originalTitle.length - 1)) === null || _11 === void 0 ? void 0 : _11.split(', ')) !== null && _12 !== void 0 ? _12 : []
283
+ ? (_13 = (_12 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(lastIndexOfParenthesis + 2, originalTitle.length - 1)) === null || _12 === void 0 ? void 0 : _12.split(', ')) !== null && _13 !== void 0 ? _13 : []
225
284
  : [],
226
285
  },
227
- url: `https://www.discogs.com${(_13 = el.querySelector('a.item_description_title')) === null || _13 === void 0 ? void 0 : _13.href}`,
228
- labels: (_15 = (_14 = [...el.querySelectorAll(".label_and_cat a[href^='https://www.discogs.com/']")]) === null || _14 === void 0 ? void 0 : _14.map(x => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.textContent) !== null && _a !== void 0 ? _a : ''; })) === null || _15 === void 0 ? void 0 : _15.filter((value, index, self) => self.indexOf(value) === index),
229
- catnos: (_20 = (_19 = (_18 = (_17 = (_16 = el
286
+ url: `https://www.discogs.com${(_14 = el
287
+ .querySelector('a.item_description_title')) === null || _14 === void 0 ? void 0 : _14.getAttribute('href')}`,
288
+ labels: (_16 = (_15 = [...el.querySelectorAll(".label_and_cat a[href^='https://www.discogs.com/']")]) === null || _15 === void 0 ? void 0 : _15.map(x => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.textContent) !== null && _a !== void 0 ? _a : ''; })) === null || _16 === void 0 ? void 0 : _16.filter((value, index, self) => self.indexOf(value) === index),
289
+ catnos: (_21 = (_20 = (_19 = (_18 = (_17 = el
230
290
  // cspell: disable-next-line
231
- .querySelector('.label_and_cat .item_catno')) === null || _16 === void 0 ? void 0 : _16.textContent) === null || _17 === void 0 ? void 0 : _17.replace(/\s+/g, ' ')) === null || _18 === void 0 ? void 0 : _18.split(', ')) === null || _19 === void 0 ? void 0 : _19.filter(x => x !== 'none')) !== null && _20 !== void 0 ? _20 : [],
232
- imageUrl: (_22 = (_21 = el.querySelector('.marketplace_image')) === null || _21 === void 0 ? void 0 : _21.getAttribute('data-src')) !== null && _22 !== void 0 ? _22 : '',
233
- description: (_27 = (_26 = (_25 = (_24 = (_23 = el.querySelector('.item_condition')) === null || _23 === void 0 ? void 0 : _23.nextElementSibling) === null || _24 === void 0 ? void 0 : _24.textContent) === null || _25 === void 0 ? void 0 : _25.replace(/\s+/g, ' ')) === null || _26 === void 0 ? void 0 : _26.trim()) !== null && _27 !== void 0 ? _27 : '',
234
- isAcceptingOffer: ((_31 = (_30 = (_29 = (_28 = el.querySelector('.item_add_to_cart p a strong')) === null || _28 === void 0 ? void 0 : _28.textContent) === null || _29 === void 0 ? void 0 : _29.split('/')) === null || _30 === void 0 ? void 0 : _30.length) !== null && _31 !== void 0 ? _31 : 0) > 1,
235
- isAvailable: !((_32 = el.classList) === null || _32 === void 0 ? void 0 : _32.contains('unavailable')),
291
+ .querySelector('.label_and_cat .item_catno')) === null || _17 === void 0 ? void 0 : _17.textContent) === null || _18 === void 0 ? void 0 : _18.replace(/\s+/g, ' ')) === null || _19 === void 0 ? void 0 : _19.split(', ')) === null || _20 === void 0 ? void 0 : _20.filter(x => x !== 'none')) !== null && _21 !== void 0 ? _21 : [],
292
+ imageUrl: (_23 = (_22 = el.querySelector('.marketplace_image')) === null || _22 === void 0 ? void 0 : _22.getAttribute('data-src')) !== null && _23 !== void 0 ? _23 : '',
293
+ description: (_28 = (_27 = (_26 = (_25 = (_24 = el.querySelector('.item_condition')) === null || _24 === void 0 ? void 0 : _24.nextElementSibling) === null || _25 === void 0 ? void 0 : _25.textContent) === null || _26 === void 0 ? void 0 : _26.replace(/\s+/g, ' ')) === null || _27 === void 0 ? void 0 : _27.trim()) !== null && _28 !== void 0 ? _28 : '',
294
+ isAcceptingOffer: ((_32 = (_31 = (_30 = (_29 = el.querySelector('.item_add_to_cart p a strong')) === null || _29 === void 0 ? void 0 : _29.textContent) === null || _30 === void 0 ? void 0 : _30.split('/')) === null || _31 === void 0 ? void 0 : _31.length) !== null && _32 !== void 0 ? _32 : 0) > 1,
295
+ isAvailable: !((_33 = el.classList) === null || _33 === void 0 ? void 0 : _33.contains('unavailable')),
236
296
  condition: {
237
297
  media: {
238
- full: (_36 = (_35 = (_34 = (_33 = el.querySelector('.item_condition span:nth-child(3)')) === null || _33 === void 0 ? void 0 : _33.textContent) === null || _34 === void 0 ? void 0 : _34.replace(/\s+/g, ' ')) === null || _35 === void 0 ? void 0 : _35.trim()) !== null && _36 !== void 0 ? _36 : '',
239
- short: (_42 = (_41 = (_40 = (_39 = (_38 = (_37 = el
240
- .querySelector('.item_condition span:nth-child(3)')) === null || _37 === void 0 ? void 0 : _37.textContent) === null || _38 === void 0 ? void 0 : _38.replace(/\s+/g, ' ')) === null || _39 === void 0 ? void 0 : _39.trim()) === null || _40 === void 0 ? void 0 : _40.match(/\(([^)]+)\)/)) === null || _41 === void 0 ? void 0 : _41[1]) !== null && _42 !== void 0 ? _42 : '',
298
+ full: (_37 = (_36 = (_35 = (_34 = el.querySelector('.item_condition span:nth-child(3)')) === null || _34 === void 0 ? void 0 : _34.textContent) === null || _35 === void 0 ? void 0 : _35.replace(/\s+/g, ' ')) === null || _36 === void 0 ? void 0 : _36.trim()) !== null && _37 !== void 0 ? _37 : '',
299
+ short: (_43 = (_42 = (_41 = (_40 = (_39 = (_38 = el
300
+ .querySelector('.item_condition span:nth-child(3)')) === null || _38 === void 0 ? void 0 : _38.textContent) === null || _39 === void 0 ? void 0 : _39.replace(/\s+/g, ' ')) === null || _40 === void 0 ? void 0 : _40.trim()) === null || _41 === void 0 ? void 0 : _41.match(/\(([^)]+)\)/)) === null || _42 === void 0 ? void 0 : _42[1]) !== null && _43 !== void 0 ? _43 : '',
241
301
  },
242
302
  sleeve: {
243
- full: (_44 = (_43 = el.querySelector('.item_condition span.item_sleeve_condition')) === null || _43 === void 0 ? void 0 : _43.textContent) !== null && _44 !== void 0 ? _44 : '',
244
- short: (_48 = (_47 = (_46 = (_45 = el
245
- .querySelector('.item_condition span.item_sleeve_condition')) === null || _45 === void 0 ? void 0 : _45.textContent) === null || _46 === void 0 ? void 0 : _46.match(/\(([^)]+)\)/)) === null || _47 === void 0 ? void 0 : _47[1]) !== null && _48 !== void 0 ? _48 : '',
303
+ full: (_45 = (_44 = el.querySelector('.item_condition span.item_sleeve_condition')) === null || _44 === void 0 ? void 0 : _44.textContent) !== null && _45 !== void 0 ? _45 : '',
304
+ short: (_49 = (_48 = (_47 = (_46 = el
305
+ .querySelector('.item_condition span.item_sleeve_condition')) === null || _46 === void 0 ? void 0 : _46.textContent) === null || _47 === void 0 ? void 0 : _47.match(/\(([^)]+)\)/)) === null || _48 === void 0 ? void 0 : _48[1]) !== null && _49 !== void 0 ? _49 : '',
246
306
  },
247
307
  },
248
308
  seller: {
249
- name: (_50 = (_49 = el.querySelector('.seller_info a')) === null || _49 === void 0 ? void 0 : _49.textContent) !== null && _50 !== void 0 ? _50 : '',
250
- url: `https://www.discogs.com${(_51 = el.querySelector('.seller_info a')) === null || _51 === void 0 ? void 0 : _51.href}`,
251
- score: (_53 = (_52 = el.querySelector('.seller_info li:nth-child(2) strong')) === null || _52 === void 0 ? void 0 : _52.textContent) !== null && _53 !== void 0 ? _53 : '',
309
+ name: (_51 = (_50 = el.querySelector('.seller_info a')) === null || _50 === void 0 ? void 0 : _50.textContent) !== null && _51 !== void 0 ? _51 : '',
310
+ url: `https://www.discogs.com${(_52 = el.querySelector('.seller_info a')) === null || _52 === void 0 ? void 0 : _52.getAttribute('href')}`,
311
+ score: (_54 = (_53 = el.querySelector('.seller_info li:nth-child(2) strong')) === null || _53 === void 0 ? void 0 : _53.textContent) !== null && _54 !== void 0 ? _54 : '',
252
312
  notes: Number.isNaN(notes) ? 0 : notes,
253
313
  },
254
314
  price: {
255
- base: 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 : ''),
315
+ base: convertCurrency((_58 = (_57 = (_56 = (_55 = el.querySelector('.price')) === null || _55 === void 0 ? void 0 : _55.textContent) === null || _56 === void 0 ? void 0 : _56.replace(/\s+/g, ' ')) === null || _57 === void 0 ? void 0 : _57.replace(/,/, '.')) !== null && _58 !== void 0 ? _58 : ''),
256
316
  shipping: Number.isNaN(parseFloat(shipping)) ? null : shipping,
257
317
  },
258
318
  country: {
@@ -265,7 +325,7 @@ class Marketplace {
265
325
  },
266
326
  release: {
267
327
  id: Number.isNaN(releaseId) ? 0 : releaseId,
268
- url: `https://www.discogs.com${(_58 = el.querySelector('a.item_release_link')) === null || _58 === void 0 ? void 0 : _58.href}`,
328
+ url: `https://www.discogs.com${(_59 = el.querySelector('a.item_release_link')) === null || _59 === void 0 ? void 0 : _59.getAttribute('href')}`,
269
329
  },
270
330
  };
271
331
  })) || [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discogs-marketplace-api-nodejs",
3
- "version": "1.8.1",
3
+ "version": "1.9.1",
4
4
  "description": "Another (better ?) NodeJs library to fetch data from Discogs marketplace",
5
5
  "keywords": [
6
6
  "discogs",
@@ -25,7 +25,8 @@
25
25
  "eslint": "eslint src test --ext .ts,.js",
26
26
  "prettier": "prettier --check .",
27
27
  "prettier:fix": "prettier --write .",
28
- "cspell": "npx cspell ./ --no-progress"
28
+ "cspell": "npx cspell ./ --no-progress",
29
+ "knip": "knip"
29
30
  },
30
31
  "main": "dist/index.js",
31
32
  "types": "dist/index.d.ts",
@@ -33,31 +34,35 @@
33
34
  "node": ">=14.0.0"
34
35
  },
35
36
  "dependencies": {
36
- "playwright-chromium": "^1.40.0",
37
- "user-agents": "^1.1.24"
37
+ "axios": "^1.6.5",
38
+ "linkedom": "^0.16.6",
39
+ "playwright-chromium": "^1.40.1",
40
+ "user-agents": "^1.1.75"
38
41
  },
39
42
  "devDependencies": {
40
- "@types/jest": "^29.5.8",
41
- "@types/node": "^18.18.9",
43
+ "@types/jest": "^29.5.11",
44
+ "@types/node": "^18.19.4",
42
45
  "@types/user-agents": "^1.0.4",
43
- "@typescript-eslint/eslint-plugin": "^6.11.0",
44
- "@typescript-eslint/parser": "^6.11.0",
45
- "cspell": "^8.0.0",
46
- "eslint": "^8.53.0",
46
+ "@typescript-eslint/eslint-plugin": "^6.17.0",
47
+ "@typescript-eslint/parser": "^6.17.0",
48
+ "cspell": "^8.3.2",
49
+ "eslint": "^8.56.0",
47
50
  "eslint-config-airbnb-base": "^15.0.0",
48
51
  "eslint-config-airbnb-typescript": "^17.1.0",
49
- "eslint-config-prettier": "^9.0.0",
52
+ "eslint-config-prettier": "^9.1.0",
50
53
  "eslint-import-resolver-typescript": "^3.6.1",
51
- "eslint-plugin-import": "^2.29.0",
52
- "eslint-plugin-jsdoc": "^46.9.0",
54
+ "eslint-plugin-import": "^2.29.1",
55
+ "eslint-plugin-jsdoc": "^48.0.2",
53
56
  "husky": "^8.0.3",
54
57
  "jest": "^29.7.0",
55
- "lint-staged": "^15.1.0",
56
- "prettier": "^3.1.0",
58
+ "knip": "^3.12.0",
59
+ "lint-staged": "^15.2.0",
60
+ "nodemon": "^3.0.2",
61
+ "prettier": "^3.1.1",
62
+ "rimraf": "^5.0.5",
57
63
  "ts-jest": "^29.1.1",
58
- "ts-node": "^10.9.1",
59
64
  "tsc-alias": "^1.8.8",
60
65
  "tsconfig-paths": "^4.2.0",
61
- "typescript": "^5.2.2"
66
+ "typescript": "^5.3.3"
62
67
  }
63
68
  }