discogs-marketplace-api-nodejs 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.MD +47 -39
  2. package/dist/data/{countries.data.d.ts → country.data.d.ts} +5 -2
  3. package/dist/data/{countries.data.js → country.data.js} +7 -4
  4. package/dist/data/{currencies.data.d.ts → currency.data.d.ts} +5 -2
  5. package/dist/data/{currencies.data.js → currency.data.js} +2 -2
  6. package/dist/index.d.ts +11 -3
  7. package/dist/index.js +6 -2
  8. package/dist/interfaces/{input.interface.d.ts → search-params.interface.d.ts} +39 -25
  9. package/dist/interfaces/{output-success.interface.d.ts → search-result.interface.d.ts} +19 -17
  10. package/dist/scrape.d.ts +10 -0
  11. package/dist/scrape.js +126 -0
  12. package/dist/search.d.ts +11 -0
  13. package/dist/search.js +154 -0
  14. package/dist/types/condition.type.d.ts +1 -2
  15. package/dist/types/currency.type.d.ts +1 -2
  16. package/dist/types/format-description.type.d.ts +1 -2
  17. package/dist/types/format.type.d.ts +1 -2
  18. package/dist/types/from.type.d.ts +1 -2
  19. package/dist/types/genre.type.d.ts +1 -2
  20. package/dist/types/lang.type.d.ts +1 -2
  21. package/dist/types/limit.type.d.ts +1 -2
  22. package/dist/types/search-type.type.d.ts +1 -2
  23. package/dist/types/sort.type.d.ts +1 -2
  24. package/dist/types/style.type.d.ts +1 -2
  25. package/package.json +25 -23
  26. package/dist/data/index.d.ts +0 -3
  27. package/dist/data/index.js +0 -10
  28. package/dist/interfaces/index.d.ts +0 -4
  29. package/dist/interfaces/output-error.interface.d.ts +0 -10
  30. package/dist/interfaces/output-error.interface.js +0 -2
  31. package/dist/interfaces/output-success.interface.js +0 -2
  32. package/dist/marketplace.d.ts +0 -27
  33. package/dist/marketplace.js +0 -291
  34. package/dist/types/index.d.ts +0 -12
  35. package/dist/types/index.js +0 -2
  36. /package/dist/interfaces/{index.js → search-params.interface.js} +0 -0
  37. /package/dist/interfaces/{input.interface.js → search-result.interface.js} +0 -0
package/README.MD CHANGED
@@ -17,11 +17,7 @@ npm i discogs-marketplace-api-nodejs
17
17
  Import `DiscogsMarketplace` into your project:
18
18
 
19
19
  ```js
20
- // With ECMAScript 6 and +
21
20
  import { DiscogsMarketplace } from 'discogs-marketplace-api-nodejs'
22
-
23
- // With CommonJS
24
- const DiscogsMarketplace = require('discogs-marketplace-api-nodejs').DiscogsMarketplace
25
21
  ```
26
22
 
27
23
  ## 🤔 Examples
@@ -104,15 +100,27 @@ const result = await DiscogsMarketplace.search({
104
100
  })
105
101
  ```
106
102
 
103
+ - If you are making a lot of requests, you can pass a playwright page instance to reuse it:
104
+
105
+ ```js
106
+ const browser = await playwright.launch()
107
+ const browserContext = await browser.newContext()
108
+ const browserPage = await browserContext.newPage()
109
+
110
+ const result = await DiscogsMarketplace.search({ searchType: 'q'}, browserPage)
111
+
112
+ await browserContext.close()
113
+ await browser.close()
114
+ ```
115
+
107
116
  ## 📃 Data format
108
117
 
109
118
  You can provide parameters to `DiscogsMarketplace.search` function according to this interface:
110
119
 
111
120
  ```ts
112
- interface InputInterface {
121
+ interface SearchParams {
113
122
  /**
114
123
  * Type of elements to search.
115
- * Default to `q`.
116
124
  * | Name | Description |
117
125
  * |:---------: |:--------------------------:|
118
126
  * | q | Basic query search |
@@ -121,36 +129,43 @@ interface InputInterface {
121
129
  * | label_id | Search in a label |
122
130
  * | artist_id | Search in a artist |
123
131
  * | user | Search in user wantlist |
132
+ * @default 'q'
124
133
  */
125
- searchType: SearchTypeType
134
+ searchType: Search
126
135
  /**
127
- * Value to search corresponding to searchType
136
+ * Value to search corresponding to the search type
128
137
  */
129
138
  searchValue?: string | number
130
139
  /**
131
140
  * Currency
141
+ * @example 'USD'
132
142
  */
133
- currency?: CurrencyType
143
+ currency?: Currency
134
144
  /**
135
145
  * Genre
146
+ * @example 'Rock'
136
147
  */
137
- genre?: GenreType
148
+ genre?: Genre
138
149
  /**
139
150
  * Styles
151
+ * @example ['Death Metal', 'Heavy Metal']
140
152
  */
141
- style?: Array<StyleType>
153
+ style?: Array<Style>
142
154
  /**
143
155
  * Formats
156
+ * @example ['Vinyl', 'CD']
144
157
  */
145
- format?: Array<FormatType>
158
+ format?: Array<Format>
146
159
  /**
147
160
  * Format descriptions
161
+ * @example ['Limited Edition', 'Numbered']
148
162
  */
149
- formatDescription?: Array<FormatDescriptionType>
163
+ formatDescription?: Array<FormatDescription>
150
164
  /**
151
165
  * Media conditions
166
+ * @example ['Mint (M)', 'Very Good Plus (VG+)']
152
167
  */
153
- condition?: Array<ConditionType>
168
+ condition?: Array<Condition>
154
169
  /**
155
170
  * Year (Do not use it with `years`)
156
171
  */
@@ -166,47 +181,50 @@ interface InputInterface {
166
181
  }
167
182
  /**
168
183
  * Is audio sample ?
184
+ * @default false
169
185
  */
170
186
  isAudioSample?: boolean
171
187
  /**
172
188
  * Is make an offer only ?
189
+ * @default false
173
190
  */
174
191
  isMakeAnOfferOnly?: boolean
175
192
  /**
176
193
  * Expedition country
194
+ * @example 'US'
177
195
  */
178
- from?: FromType
196
+ from?: From
179
197
  /**
180
198
  * Seller name
181
199
  */
182
200
  seller?: string
183
201
  /**
184
202
  * Sort elements by.
185
- * Default to `Listed Newest`.
203
+ * @default 'Listed Newest'
186
204
  */
187
- sort?: SortType
205
+ sort?: Sort
188
206
  /**
189
207
  * Limit of elements to search (25 | 50 | 100 | 250).
190
- * Default to `25`.
208
+ * @default 25
191
209
  */
192
- limit?: LimitType
210
+ limit?: Limit
193
211
  /**
194
212
  * Page (Must be < 401 or discogs will return an error 404).
195
- * Default to `1`.
213
+ * @default 1
196
214
  */
197
215
  page?: number
198
216
  /**
199
217
  * Lang to use for Discogs.
200
- * Default to `en`.
218
+ * @default 'en'
201
219
  */
202
- lang?: LangType
220
+ lang?: Lang
203
221
  }
204
222
  ```
205
223
 
206
224
  If success, it will return:
207
225
 
208
226
  ```ts
209
- interface OutputSuccessInterface {
227
+ interface SearchResult {
210
228
  items: Array<{
211
229
  id: number
212
230
  title: {
@@ -239,12 +257,15 @@ interface OutputSuccessInterface {
239
257
  notes: number
240
258
  }
241
259
  price: {
242
- base: string
243
- shipping: string
260
+ /** @example '12.34 USD' */
261
+ base: `${number} ${CurrencyValues}` | ''
262
+ /** @example '5.67 USD' */
263
+ shipping: `${number} ${CurrencyValues}` | ''
244
264
  }
245
265
  country: {
246
266
  name: string
247
- code: string
267
+ /** @example 'US' */
268
+ code: CountryValues
248
269
  }
249
270
  community: {
250
271
  have: number
@@ -263,23 +284,10 @@ interface OutputSuccessInterface {
263
284
  total: number
264
285
  perPage: number
265
286
  }
266
- search: {
267
- value: string | number
268
- type: SearchTypeType
269
- }
270
287
  urlGenerated: string
271
288
  }
272
289
  ```
273
290
 
274
- If error, it will throw:
275
-
276
- ```ts
277
- interface OutputErrorInterface {
278
- message: string
279
- code: number
280
- }
281
- ```
282
-
283
291
  ## 💡 How to contribute
284
292
 
285
293
  There is a [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers) on that project already configured, feel free to use it.
@@ -1,4 +1,4 @@
1
- declare const COUNTRIES: {
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 default COUNTRIES;
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 COUNTRIES_ISO = {
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 COUNTRIES_DISCOGS = {
271
+ const CountryDiscogs = {
272
272
  Azerbaidjan: 'AZ',
273
273
  Bolivia: 'BO',
274
274
  'Bosnia-Herzegovina': 'BA',
@@ -324,5 +324,8 @@ const COUNTRIES_DISCOGS = {
324
324
  Yugoslavia: 'GR',
325
325
  Zaire: 'CD',
326
326
  };
327
- const COUNTRIES = Object.assign(Object.assign({}, COUNTRIES_ISO), COUNTRIES_DISCOGS);
328
- exports.default = COUNTRIES;
327
+ const Country = {
328
+ ...CountryIso,
329
+ ...CountryDiscogs,
330
+ };
331
+ exports.default = Country;
@@ -1,4 +1,4 @@
1
- declare const CURRENCIES: {
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 default CURRENCIES;
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 CURRENCIES = {
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 = CURRENCIES;
35
+ exports.default = Currency;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,11 @@
1
- import DiscogsMarketplace from './marketplace.js';
2
- import type { InputInterface, OutputErrorInterface, OutputSuccessInterface } from './interfaces/index.js';
3
- export { DiscogsMarketplace, InputInterface, OutputErrorInterface, OutputSuccessInterface };
1
+ import search from './search';
2
+ import type SearchParams from './interfaces/search-params.interface';
3
+ import type SearchResult from './interfaces/search-result.interface';
4
+ /**
5
+ * Discogs Marketplace API
6
+ * @see https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS
7
+ */
8
+ export declare const DiscogsMarketplace: {
9
+ search: typeof search;
10
+ };
11
+ export type { SearchParams, SearchResult };
package/dist/index.js CHANGED
@@ -4,5 +4,9 @@ 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 marketplace_1 = __importDefault(require("./marketplace.js"));
8
- exports.DiscogsMarketplace = marketplace_1.default;
7
+ const search_1 = __importDefault(require("./search"));
8
+ /**
9
+ * Discogs Marketplace API
10
+ * @see https://github.com/KirianCaumes/Discogs-Marketplace-API-NodeJS
11
+ */
12
+ exports.DiscogsMarketplace = { search: search_1.default };
@@ -1,11 +1,20 @@
1
- import type { LimitType, GenreType, CurrencyType, FromType, StyleType, FormatType, ConditionType, SortType, LangType, FormatDescriptionType, SearchTypeType } from '../types/index.js';
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';
2
12
  /**
3
- * Element that can be provided by user
13
+ * Search parameters for Discogs Marketplace
4
14
  */
5
- interface InputInterface {
15
+ export default interface SearchParams {
6
16
  /**
7
17
  * Type of elements to search.
8
- * Default to `q`.
9
18
  * | Name | Description |
10
19
  * |:---------: |:--------------------------:|
11
20
  * | q | Basic query search |
@@ -14,36 +23,43 @@ interface InputInterface {
14
23
  * | label_id | Search in a label |
15
24
  * | artist_id | Search in a artist |
16
25
  * | user | Search in user wantlist |
26
+ * @default 'q'
17
27
  */
18
- searchType: SearchTypeType;
28
+ searchType: Search;
19
29
  /**
20
- * Value to search corresponding to searchType
30
+ * Value to search corresponding to the search type
21
31
  */
22
32
  searchValue?: string | number;
23
33
  /**
24
34
  * Currency
35
+ * @example 'USD'
25
36
  */
26
- currency?: CurrencyType;
37
+ currency?: Currency;
27
38
  /**
28
39
  * Genre
40
+ * @example 'Rock'
29
41
  */
30
- genre?: GenreType;
42
+ genre?: Genre;
31
43
  /**
32
44
  * Styles
45
+ * @example ['Death Metal', 'Heavy Metal']
33
46
  */
34
- style?: Array<StyleType>;
47
+ style?: Array<Style>;
35
48
  /**
36
49
  * Formats
50
+ * @example ['Vinyl', 'CD']
37
51
  */
38
- format?: Array<FormatType>;
52
+ format?: Array<Format>;
39
53
  /**
40
54
  * Format descriptions
55
+ * @example ['Limited Edition', 'Numbered']
41
56
  */
42
- formatDescription?: Array<FormatDescriptionType>;
57
+ formatDescription?: Array<FormatDescription>;
43
58
  /**
44
59
  * Media conditions
60
+ * @example ['Mint (M)', 'Very Good Plus (VG+)']
45
61
  */
46
- condition?: Array<ConditionType>;
62
+ condition?: Array<Condition>;
47
63
  /**
48
64
  * Year (Do not use it with `years`)
49
65
  */
@@ -59,43 +75,41 @@ interface InputInterface {
59
75
  };
60
76
  /**
61
77
  * Is audio sample ?
78
+ * @default false
62
79
  */
63
80
  isAudioSample?: boolean;
64
81
  /**
65
82
  * Is make an offer only ?
83
+ * @default false
66
84
  */
67
85
  isMakeAnOfferOnly?: boolean;
68
86
  /**
69
87
  * Expedition country
88
+ * @example 'US'
70
89
  */
71
- from?: FromType;
90
+ from?: From;
72
91
  /**
73
92
  * Seller name
74
93
  */
75
94
  seller?: string;
76
95
  /**
77
96
  * Sort elements by.
78
- *
79
- * Default to `Listed Newest`.
97
+ * @default 'Listed Newest'
80
98
  */
81
- sort?: SortType;
99
+ sort?: Sort;
82
100
  /**
83
101
  * Limit of elements to search (25 | 50 | 100 | 250).
84
- *
85
- * Default to `25`.
102
+ * @default 25
86
103
  */
87
- limit?: LimitType;
104
+ limit?: Limit;
88
105
  /**
89
106
  * Page (Must be < 401 or discogs will return an error 404).
90
- *
91
- * Default to `1`.
107
+ * @default 1
92
108
  */
93
109
  page?: number;
94
110
  /**
95
111
  * Lang to use for Discogs.
96
- *
97
- * Default to `en`.
112
+ * @default 'en'
98
113
  */
99
- lang?: LangType;
114
+ lang?: Lang;
100
115
  }
101
- export default InputInterface;
@@ -1,8 +1,9 @@
1
- import type { SearchTypeType } from '../types/index.js';
1
+ import type { CountryValues } from '../data/country.data';
2
+ import type { CurrencyValues } from '../data/currency.data';
2
3
  /**
3
- * Result provided to user
4
+ * Search result from Discogs Marketplace
4
5
  */
5
- interface OutputSuccessInterface {
6
+ export default interface SearchResult {
6
7
  /** Items */
7
8
  items: Array<{
8
9
  /** Id */
@@ -62,17 +63,26 @@ interface OutputSuccessInterface {
62
63
  };
63
64
  /** Price */
64
65
  price: {
65
- /** Base */
66
- base: string;
67
- /** Shipping */
68
- shipping: string;
66
+ /**
67
+ * Base
68
+ * @example '12.34 USD'
69
+ */
70
+ base: `${number} ${CurrencyValues}` | '';
71
+ /**
72
+ * Shipping
73
+ * @example '5.67 USD'
74
+ */
75
+ shipping: `${number} ${CurrencyValues}` | '';
69
76
  };
70
77
  /** From */
71
78
  country: {
72
79
  /** Name */
73
80
  name: string;
74
- /** Iso code */
75
- code: string;
81
+ /**
82
+ * Iso code
83
+ * @example 'US'
84
+ */
85
+ code: CountryValues;
76
86
  };
77
87
  /** Community */
78
88
  community: {
@@ -103,14 +113,6 @@ interface OutputSuccessInterface {
103
113
  /** PerPage */
104
114
  perPage: number;
105
115
  };
106
- /** Search */
107
- search: {
108
- /** Value */
109
- value: string | number;
110
- /** Type */
111
- type: SearchTypeType;
112
- };
113
116
  /** UrlGenerated */
114
117
  urlGenerated: string;
115
118
  }
116
- export default OutputSuccessInterface;
@@ -0,0 +1,10 @@
1
+ import type SearchResult from './interfaces/search-result.interface';
2
+ /**
3
+ * Parses the page and returns the items found.
4
+ * This function is called by the browser context when the page is loaded.
5
+ * @returns Items found and total
6
+ */
7
+ export default function scrape(): Pick<SearchResult, 'items'> & {
8
+ /** Total items found */
9
+ total: SearchResult['result']['total'];
10
+ };
package/dist/scrape.js ADDED
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = scrape;
4
+ // These variables are injected by the browser context when the page is loaded.
5
+ const { Country, Currency } = globalThis;
6
+ /**
7
+ * Parses the page and returns the items found.
8
+ * This function is called by the browser context when the page is loaded.
9
+ * @returns Items found and total
10
+ */
11
+ function scrape() {
12
+ /**
13
+ * Converts a currency string to a standardized format.
14
+ * @param value String to clean
15
+ * @returns Cleaned-up string
16
+ */
17
+ const convertCurrency = (value) => {
18
+ if (!value) {
19
+ return '';
20
+ }
21
+ const currencyFound = Object.keys(Currency).find(key => value.includes(key));
22
+ if (!currencyFound) {
23
+ return '';
24
+ }
25
+ const currencyClean = Currency[currencyFound];
26
+ const amount = value
27
+ .replace(currencyClean !== 'JPY' ? /[.](?=.*[.])/g : /\./g, '') // Remove all dots but the last, except for JPY
28
+ .replace(currencyFound, '') // Remove original currency
29
+ .replace(/\s\s+/g, ''); // Remove spaces
30
+ const amountParsed = Number.parseFloat(amount);
31
+ if (Number.isNaN(amountParsed)) {
32
+ return '';
33
+ }
34
+ return `${amountParsed} ${currencyClean}`;
35
+ };
36
+ /**
37
+ * Safely parses a number from a string.
38
+ * @param value String to parse
39
+ * @returns Parsed number or 0 if invalid
40
+ */
41
+ const safeParseInt = (value) => {
42
+ const parsed = Number.parseInt(value ?? '', 10);
43
+ return Number.isNaN(parsed) ? 0 : parsed;
44
+ };
45
+ /**
46
+ * Extracts and cleans text content from an element.
47
+ * @param selector CSS selector
48
+ * @param context Parent element to query from
49
+ * @returns Cleaned text content or an empty string
50
+ */
51
+ const getTextContent = (selector, context = document) => context.querySelector(selector)?.textContent?.trim() ?? '';
52
+ const total = safeParseInt(getTextContent('.pagination_total')
53
+ .split(' ')
54
+ .filter(x => x)
55
+ .pop()
56
+ ?.replace(/(,|\.|\s)/g, ''));
57
+ const items = [...document.querySelectorAll('table.table_block tbody tr')].map(el => {
58
+ const itemHref = el.querySelector('a.item_description_title')?.getAttribute('href') ?? '';
59
+ const mediaCondition = getTextContent('.item_condition span:nth-child(3)', el).split('\n')[0] ?? '';
60
+ const sleeveCondition = getTextContent('.item_condition span.item_sleeve_condition', el);
61
+ const countryName = getTextContent('.seller_info li:nth-child(3)', el).split(':').pop() ?? '';
62
+ const originalTitle = getTextContent('a.item_description_title', el);
63
+ const firstIndexOfDash = originalTitle.indexOf(' - ');
64
+ const lastIndexOfParenthesis = originalTitle.lastIndexOf(' (');
65
+ const releaseHref = el.querySelector('a.item_release_link')?.getAttribute('href') ?? '';
66
+ return {
67
+ id: safeParseInt(itemHref.split('/').pop()),
68
+ title: {
69
+ original: originalTitle,
70
+ artist: firstIndexOfDash > -1 ? originalTitle.substring(0, firstIndexOfDash) : '',
71
+ item: firstIndexOfDash > -1 && lastIndexOfParenthesis > -1
72
+ ? originalTitle.substring(firstIndexOfDash + 3, lastIndexOfParenthesis)
73
+ : '',
74
+ formats: lastIndexOfParenthesis > -1
75
+ ? originalTitle.substring(lastIndexOfParenthesis + 2, originalTitle.length - 1).split(', ')
76
+ : [],
77
+ },
78
+ url: `https://www.discogs.com${itemHref}`,
79
+ labels: [...el.querySelectorAll(".label_and_cat a[href^='https://www.discogs.com/']")]
80
+ .map(x => x.textContent?.trim() ?? '')
81
+ .filter((value, index, self) => self.indexOf(value) === index),
82
+ catnos: getTextContent('.label_and_cat .item_catno', el) // cspell:disable-line
83
+ .split(', ')
84
+ .filter(x => x !== 'none'),
85
+ imageUrl: el.querySelector('.marketplace_image')?.getAttribute('data-src') ?? '',
86
+ description: getTextContent('.item_condition + *', el),
87
+ isAcceptingOffer: getTextContent('.item_add_to_cart p a strong', el).split('/').length > 1,
88
+ isAvailable: !el.classList.contains('unavailable'),
89
+ condition: {
90
+ media: {
91
+ full: mediaCondition,
92
+ short: /\(([^)]+)\)/.exec(mediaCondition)?.[1] ?? '',
93
+ },
94
+ sleeve: {
95
+ full: sleeveCondition,
96
+ short: /\(([^)]+)\)/.exec(sleeveCondition)?.[1] ?? '',
97
+ },
98
+ },
99
+ seller: {
100
+ name: getTextContent('.seller_info a', el),
101
+ url: `https://www.discogs.com${el.querySelector('.seller_info a')?.getAttribute('href') ?? ''}`,
102
+ score: getTextContent('.seller_info li:nth-child(2) strong', el),
103
+ notes: safeParseInt(getTextContent('.seller_info li:nth-child(2) .section_link', el)),
104
+ },
105
+ price: {
106
+ base: convertCurrency(getTextContent('.price', el).replace(/,/, '.')),
107
+ shipping: convertCurrency(getTextContent('.item_shipping', el)
108
+ .replace(/(\s+|\+)/g, ' ')
109
+ .replace(',', '.')),
110
+ },
111
+ country: {
112
+ name: countryName,
113
+ code: Country[countryName],
114
+ },
115
+ community: {
116
+ have: safeParseInt(getTextContent('.community_summary .community_result:nth-child(1) .community_number', el)),
117
+ want: safeParseInt(getTextContent('.community_summary .community_result:nth-child(2) .community_number', el)),
118
+ },
119
+ release: {
120
+ id: safeParseInt(releaseHref.split('release/').pop()?.split('-').shift()),
121
+ url: `https://www.discogs.com${releaseHref}`,
122
+ },
123
+ };
124
+ });
125
+ return { total, items };
126
+ }
@@ -0,0 +1,11 @@
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';
4
+ /**
5
+ * Search elements on discogs marketplace
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
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>;