discogs-marketplace-api-nodejs 1.3.2 → 1.3.6

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 (56) hide show
  1. package/README.MD +78 -43
  2. package/dist/enum/ECurrency.d.ts +2 -3
  3. package/dist/enum/ECurrency.js +2 -4
  4. package/dist/enum/EFormat.d.ts +2 -3
  5. package/dist/enum/EFormat.js +2 -4
  6. package/dist/enum/EFormatDescription.d.ts +2 -3
  7. package/dist/enum/EFormatDescription.js +2 -4
  8. package/dist/enum/EFrom.d.ts +2 -3
  9. package/dist/enum/EFrom.js +3 -4
  10. package/dist/enum/EFromIso.d.ts +53 -53
  11. package/dist/enum/EGenre.d.ts +2 -3
  12. package/dist/enum/EGenre.js +2 -4
  13. package/dist/enum/ELang.d.ts +2 -3
  14. package/dist/enum/ELang.js +2 -4
  15. package/dist/enum/EMediaCondition.d.ts +2 -3
  16. package/dist/enum/EMediaCondition.js +2 -4
  17. package/dist/enum/ESort.d.ts +2 -3
  18. package/dist/enum/ESort.js +2 -4
  19. package/dist/enum/EStyle.d.ts +2 -3
  20. package/dist/enum/EStyle.js +2 -4
  21. package/dist/enum/EType.d.ts +2 -3
  22. package/dist/enum/EType.js +2 -4
  23. package/dist/enum/iso/ECountryCode.d.ts +255 -0
  24. package/dist/enum/iso/ECountryCode.js +258 -0
  25. package/dist/enum/iso/ECountryName.d.ts +255 -0
  26. package/dist/enum/iso/ECountryName.js +258 -0
  27. package/dist/enum/iso/EDiscogsCountryNameToIsoCode.d.ts +69 -0
  28. package/dist/enum/iso/EDiscogsCountryNameToIsoCode.js +72 -0
  29. package/dist/enum/iso/EDiscogsCurrencyToIsoCode.d.ts +23 -0
  30. package/dist/enum/iso/EDiscogsCurrencyToIsoCode.js +26 -0
  31. package/dist/enum/iso/translate/EDiscogsCountryNameToIsoCode.d.ts +69 -0
  32. package/dist/enum/iso/translate/EDiscogsCountryNameToIsoCode.js +72 -0
  33. package/dist/enum/iso/translate/EDiscogsCurrencyToIsoCode.d.ts +23 -0
  34. package/dist/enum/iso/translate/EDiscogsCurrencyToIsoCode.js +26 -0
  35. package/dist/enum/iso/translates/EDiscogsCountryNameToIsoCode.d.ts +69 -0
  36. package/dist/enum/iso/translates/EDiscogsCountryNameToIsoCode.js +72 -0
  37. package/dist/enum/iso/translates/EDiscogsCurrencyToIsoCode.d.ts +23 -0
  38. package/dist/enum/iso/translates/EDiscogsCurrencyToIsoCode.js +26 -0
  39. package/dist/index.d.ts +14 -14
  40. package/dist/index.js +22 -21
  41. package/dist/interface/IDiscogsMarketplace.d.ts +1 -2
  42. package/dist/interface/IInput.d.ts +12 -12
  43. package/dist/interface/IInput.js +11 -0
  44. package/dist/interface/IItem.d.ts +11 -6
  45. package/dist/interface/IItem.js +5 -0
  46. package/dist/interface/IOutputError.d.ts +1 -1
  47. package/dist/interface/IOutputSuccess.d.ts +4 -4
  48. package/dist/interface/IOutputSuccess.js +1 -0
  49. package/dist/interface/IYears.d.ts +1 -1
  50. package/dist/marketplace.d.ts +28 -42
  51. package/dist/marketplace.js +118 -120
  52. package/dist/type/TLimit.d.ts +2 -3
  53. package/package.json +23 -16
  54. package/.gitattributes +0 -1
  55. package/notes.md +0 -9
  56. package/tsconfig.build.json +0 -40
@@ -1,15 +1,15 @@
1
1
  import IItem from "./IItem";
2
- import { EType } from "../enum/EType";
2
+ import EType from "../enum/EType";
3
3
  /**
4
- * @interface IOutputSuccess Result provided to user
4
+ * Result provided to user
5
5
  */
6
6
  export default interface IOutputSuccess {
7
- result: IItem[];
7
+ items: IItem[];
8
8
  page: {
9
9
  current: number;
10
10
  total: number;
11
11
  };
12
- item: {
12
+ result: {
13
13
  total: number;
14
14
  perPage: number;
15
15
  };
@@ -4,3 +4,4 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const IItem_1 = __importDefault(require("./IItem"));
7
+ const EType_1 = __importDefault(require("../enum/EType"));
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @interface IInput Provide interval of years
2
+ * Provide interval of years
3
3
  */
4
4
  export default interface IYears {
5
5
  min: number;
@@ -1,70 +1,56 @@
1
- import { ECurrency } from "./enum/ECurrency";
2
- import { EFormat } from "./enum/EFormat";
3
- import { EFormatDescription } from "./enum/EFormatDescription";
4
- import { EFrom } from "./enum/EFrom";
5
- import { EGenre } from "./enum/EGenre";
6
- import { ELang } from "./enum/ELang";
7
- import { EMediaCondition } from "./enum/EMediaCondition";
8
- import { ESort } from "./enum/ESort";
9
- import { EStyle } from "./enum/EStyle";
10
- import { EType } from "./enum/EType";
11
1
  import IInput from "./interface/IInput";
12
2
  import IOutputSuccess from "./interface/IOutputSuccess";
13
- import IYears from "./interface/IYears";
14
- import { TLimit } from "./type/TLimit";
15
3
  /**
16
4
  * Discogs Marketplace
17
- * @class
18
- * @implements {IInput}
19
5
  */
20
6
  export default class Marketplace {
21
- protected searchType: EType;
22
- protected searchValue: string | number | undefined;
23
- protected currency?: ECurrency;
24
- protected genre?: EGenre;
25
- protected style?: EStyle[];
26
- protected format?: EFormat[];
27
- protected formatDescription?: EFormatDescription[];
28
- protected mediaCondition?: EMediaCondition[];
29
- protected year?: number;
30
- protected years?: IYears;
31
- protected isAudioSample: boolean;
32
- protected isMakeAnOfferOnly: boolean;
33
- protected from?: EFrom;
34
- protected seller?: string;
35
- protected sort: ESort;
36
- protected limit: TLimit;
37
- protected page: number;
38
- protected lang: ELang;
39
- /** Url generated by Puppetter */
40
- protected url: string;
41
- constructor({ searchType, searchValue, currency, genre, style, format, formatDescription, mediaCondition, year, years, isAudioSample, isMakeAnOfferOnly, from, seller, sort, limit, page, lang }: IInput);
7
+ private searchType;
8
+ private searchValue;
9
+ private currency?;
10
+ private genre?;
11
+ private style?;
12
+ private format?;
13
+ private formatDescription?;
14
+ private mediaCondition?;
15
+ private year?;
16
+ private years?;
17
+ private isAudioSample;
18
+ private isMakeAnOfferOnly;
19
+ private from?;
20
+ private seller?;
21
+ private sort;
22
+ private limit;
23
+ private page;
24
+ private lang;
25
+ /** Url generated by Playwright */
26
+ private url;
27
+ constructor({ searchType, searchValue, currency, genre, style, format, formatDescription, mediaCondition, year, years, isAudioSample, isMakeAnOfferOnly, from, seller, sort, limit, page, lang, }: IInput);
42
28
  /**
43
29
  * Search elements on discogs
44
- * @returns {Promise<IOutputSuccess>} Items found
30
+ * @returns Items found
45
31
  */
46
32
  search(): Promise<IOutputSuccess>;
47
33
  /**
48
34
  * Generate URL to be parsed
49
- * @returns {string} Url
35
+ * @returns Url
50
36
  */
51
37
  private generateUrl;
52
38
  /**
53
39
  * Serialize params URL
54
- * @param {any} params Object of GET parameters
55
- * @returns {string} Url
40
+ * @param params Object of GET parameters
41
+ * @returns Url
56
42
  */
57
43
  private serializeParams;
58
44
  /**
59
45
  * Function to convert devise to ISO name
60
46
  * @param str String to clean
61
- * @returns {string} Cleanup string
47
+ * @returns Cleanup string
62
48
  */
63
49
  private convertDevise;
64
50
  /**
65
51
  * Parse HTML to clean result
66
- * @param {Document} document Document to parse
67
- * @returns {IOutputSuccess} Items found
52
+ * @param document Document to parse
53
+ * @returns Items found
68
54
  */
69
55
  private getItem;
70
56
  }
@@ -12,25 +12,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const EFromIso_1 = require("./enum/EFromIso");
16
- const ELang_1 = require("./enum/ELang");
17
- const ESort_1 = require("./enum/ESort");
18
- const EType_1 = require("./enum/EType");
15
+ const ECountryCode_1 = __importDefault(require("./enum/iso/ECountryCode"));
16
+ const ECountryName_1 = __importDefault(require("./enum/iso/ECountryName"));
17
+ const ECurrency_1 = __importDefault(require("./enum/ECurrency"));
18
+ const EFormat_1 = __importDefault(require("./enum/EFormat"));
19
+ const EFormatDescription_1 = __importDefault(require("./enum/EFormatDescription"));
20
+ const EFrom_1 = __importDefault(require("./enum/EFrom"));
21
+ const EGenre_1 = __importDefault(require("./enum/EGenre"));
22
+ const ELang_1 = __importDefault(require("./enum/ELang"));
23
+ const EMediaCondition_1 = __importDefault(require("./enum/EMediaCondition"));
24
+ const ESort_1 = __importDefault(require("./enum/ESort"));
25
+ const EStyle_1 = __importDefault(require("./enum/EStyle"));
26
+ const EType_1 = __importDefault(require("./enum/EType"));
19
27
  const IInput_1 = __importDefault(require("./interface/IInput"));
20
28
  const IOutputError_1 = __importDefault(require("./interface/IOutputError"));
21
29
  const IOutputSuccess_1 = __importDefault(require("./interface/IOutputSuccess"));
22
30
  const IYears_1 = __importDefault(require("./interface/IYears"));
23
- const jsdom_1 = require("jsdom");
31
+ const TLimit_1 = __importDefault(require("./type/TLimit"));
24
32
  const playwright_chromium_1 = require("playwright-chromium");
25
33
  const user_agents_1 = __importDefault(require("user-agents"));
34
+ const EDiscogsCurrencyToIsoCode_1 = __importDefault(require("./enum/iso/translate/EDiscogsCurrencyToIsoCode"));
35
+ const EDiscogsCountryNameToIsoCode_1 = __importDefault(require("./enum/iso/translate/EDiscogsCountryNameToIsoCode"));
36
+ const linkedom_1 = require("linkedom");
26
37
  /**
27
38
  * Discogs Marketplace
28
- * @class
29
- * @implements {IInput}
30
39
  */
31
40
  class Marketplace {
32
- constructor({ searchType = EType_1.EType.STRING, searchValue = undefined, currency = undefined, genre = undefined, style = [], format = [], formatDescription = [], mediaCondition = [], year = undefined, years = undefined, isAudioSample = false, isMakeAnOfferOnly = false, from = undefined, seller = undefined, sort = ESort_1.ESort.LISTED_NEWEST, limit = 25, page = 1, lang = ELang_1.ELang.ENGLISH }) {
33
- /** Url generated by Puppetter */
41
+ constructor({ searchType = EType_1.default.STRING, searchValue = undefined, currency = undefined, genre = undefined, style = [], format = [], formatDescription = [], mediaCondition = [], year = undefined, years = undefined, isAudioSample = false, isMakeAnOfferOnly = false, from = undefined, seller = undefined, sort = ESort_1.default.LISTED_NEWEST, limit = 25, page = 1, lang = ELang_1.default.ENGLISH, }) {
42
+ /** Url generated by Playwright */
34
43
  this.url = '';
35
44
  this.searchType = searchType;
36
45
  this.searchValue = searchValue;
@@ -53,10 +62,10 @@ class Marketplace {
53
62
  }
54
63
  /**
55
64
  * Search elements on discogs
56
- * @returns {Promise<IOutputSuccess>} Items found
65
+ * @returns Items found
57
66
  */
58
67
  search() {
59
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
68
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
60
69
  return __awaiter(this, void 0, void 0, function* () {
61
70
  try {
62
71
  /** Init browser */
@@ -104,188 +113,177 @@ class Marketplace {
104
113
  /** Get url */
105
114
  this.url = page.url();
106
115
  /** Get HTML */
107
- const bodyHTML = yield page.evaluate(() => document.body.innerHTML);
116
+ const bodyHTML = yield page.evaluate(() => { var _a; return (_a = document.getElementById('page_content')) === null || _a === void 0 ? void 0 : _a.outerHTML; });
108
117
  /** Close browser */
109
118
  yield browser.close();
110
119
  /** If error, reject */
111
120
  if (((_l = response === null || response === void 0 ? void 0 : response.status()) !== null && _l !== void 0 ? _l : 0) >= 400)
121
+ // eslint-disable-next-line @typescript-eslint/no-throw-literal
112
122
  throw { document: bodyHTML, status: (_m = response === null || response === void 0 ? void 0 : response.status()) !== null && _m !== void 0 ? _m : 0 };
113
- return this.getItem((new jsdom_1.JSDOM(bodyHTML)).window.document);
123
+ return this.getItem((0, linkedom_1.parseHTML)(bodyHTML).document);
114
124
  }
115
125
  catch (error) {
116
126
  if ((error === null || error === void 0 ? void 0 : error.document) && error.status)
127
+ // eslint-disable-next-line @typescript-eslint/no-throw-literal
117
128
  throw {
118
- message: (_s = (_r = (_q = (_p = (_o = (new jsdom_1.JSDOM(error === null || error === void 0 ? void 0 : error.document))) === null || _o === void 0 ? void 0 : _o.window) === null || _p === void 0 ? void 0 : _p.querySelector('h1 + p')) === null || _q === void 0 ? void 0 : _q.innerHTML) === null || _r === void 0 ? void 0 : _r.trim()) !== null && _s !== void 0 ? _s : 'An error occured',
119
- code: error.status
129
+ message: (_r = (_q = (_p = (_o = (0, linkedom_1.parseHTML)(error.document).document) === null || _o === void 0 ? void 0 : _o.querySelector('h1 + p')) === null || _p === void 0 ? void 0 : _p.innerHTML) === null || _q === void 0 ? void 0 : _q.trim()) !== null && _r !== void 0 ? _r : 'An error occured',
130
+ code: error.status,
120
131
  };
132
+ // eslint-disable-next-line @typescript-eslint/no-throw-literal
121
133
  throw {
122
134
  message: 'An error occured',
123
- code: 500
135
+ code: 500,
124
136
  };
125
137
  }
126
138
  });
127
139
  }
128
140
  /**
129
141
  * Generate URL to be parsed
130
- * @returns {string} Url
142
+ * @returns Url
131
143
  */
132
144
  generateUrl() {
133
145
  let url = `https://www.discogs.com/${this.lang}/`;
134
146
  if (this.seller) {
135
147
  url += `seller/${this.seller}/`;
136
- url += this.searchType === EType_1.EType.USER ? `mywants` : 'profile';
148
+ url += this.searchType === EType_1.default.USER ? 'mywants' : 'profile';
137
149
  }
138
150
  else {
139
- url += `sell/`;
140
- url += this.searchType === EType_1.EType.USER ? `mywants` : `list`;
151
+ url += 'sell/';
152
+ url += this.searchType === EType_1.default.USER ? 'mywants' : 'list';
141
153
  }
142
154
  return url;
143
155
  }
144
156
  /**
145
157
  * Serialize params URL
146
- * @param {any} params Object of GET parameters
147
- * @returns {string} Url
158
+ * @param params Object of GET parameters
159
+ * @returns Url
148
160
  */
161
+ // eslint-disable-next-line class-methods-use-this
149
162
  serializeParams(params) {
150
- let param = [];
151
- for (let key in params) {
152
- if (params[key] === undefined || params[key] === null) {
163
+ const param = [];
164
+ // eslint-disable-next-line no-restricted-syntax
165
+ for (const key in params)
166
+ if (params[key] === undefined || params[key] === null)
167
+ // eslint-disable-next-line no-continue
153
168
  continue;
154
- }
155
- else if (Array.isArray(params[key])) {
169
+ else if (Array.isArray(params[key]))
156
170
  /** Custom handle for array */
157
- if (params[key].length > 0) {
158
- for (const el of params[key]) {
159
- param.push(key + '=' + encodeURIComponent(el));
160
- }
161
- }
162
- else {
171
+ if (params[key].length > 0)
172
+ // eslint-disable-next-line no-restricted-syntax
173
+ for (const el of params[key])
174
+ param.push(`${key}=${encodeURIComponent(el)}`);
175
+ else
176
+ // eslint-disable-next-line no-continue
163
177
  continue;
164
- }
165
- }
166
- else {
167
- param.push(key + '=' + encodeURIComponent(params[key]));
168
- }
169
- }
178
+ else
179
+ param.push(`${key}=${encodeURIComponent(params[key])}`);
170
180
  return param.join('&');
171
181
  }
172
182
  /**
173
183
  * Function to convert devise to ISO name
174
184
  * @param str String to clean
175
- * @returns {string} Cleanup string
185
+ * @returns Cleanup string
176
186
  */
177
- convertDevise(str) {
178
- if (!str)
179
- return str;
180
- const data = {
181
- '\$US': 'USD',
182
- '£GB': 'GBP',
183
- '\$CA': 'CAD',
184
- '\$AU': 'AUD',
185
- 'JPY': 'JPY',
186
- 'CHF': 'CHF',
187
- 'MX\$': 'MXN',
188
- '\$NZ': 'NZD',
189
- 'SEK': 'SEK',
190
- 'ZAR': 'ZAR',
191
- 'CA\$': 'AUD',
192
- 'A\$': 'AUD',
193
- 'R\$': 'BRL',
194
- '€': 'EUR',
195
- '\$': 'USD',
196
- '£': 'GBP',
197
- '¥': 'JPY',
198
- };
199
- Object.keys(data).forEach(x => {
200
- if (str.includes(`${x}`)) {
201
- str = str.replace(`${x}`, '');
202
- str = `${str} ${data[x]}`.replace(/\s\s+/g, ' '); //Replace multiple space by one
203
- }
204
- });
205
- return str;
187
+ // eslint-disable-next-line class-methods-use-this
188
+ convertDevise(value) {
189
+ var _a;
190
+ if (!value)
191
+ return value;
192
+ const currency = (_a = Object.keys(EDiscogsCurrencyToIsoCode_1.default).find(key => value.includes(key))) !== null && _a !== void 0 ? _a : '';
193
+ if (!currency)
194
+ return value;
195
+ return `${value.replace(currency, '')} ${EDiscogsCurrencyToIsoCode_1.default[currency]}`.replace(/\s\s+/g, ' ');
206
196
  }
207
197
  /**
208
198
  * Parse HTML to clean result
209
- * @param {Document} document Document to parse
210
- * @returns {IOutputSuccess} Items found
199
+ * @param document Document to parse
200
+ * @returns Items found
211
201
  */
212
202
  getItem(document) {
213
- var _a, _b, _c, _d, _e;
214
- const totalItems = parseFloat(((_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');
203
+ var _a, _b, _c, _d, _e, _f;
204
+ const totalItems = parseFloat(((_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');
215
205
  return {
216
- result: ((_e = [...document.querySelectorAll('table.table_block tbody tr')]) === null || _e === void 0 ? void 0 : _e.map(el => {
217
- 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;
218
- const shipping = this.convertDevise((_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(',', '.'));
219
- const have = parseInt((_g = el.querySelector('.community_summary .community_result:nth-child(1) .community_number')) === null || _g === void 0 ? void 0 : _g.textContent);
220
- const want = parseInt((_h = el.querySelector('.community_summary .community_result:nth-child(2) .community_number')) === null || _h === void 0 ? void 0 : _h.textContent);
221
- const country = (_l = (_k = (_j = el.querySelector('.seller_info li:nth-child(3)')) === null || _j === void 0 ? void 0 : _j.textContent) === null || _k === void 0 ? void 0 : _k.split(':')) === null || _l === void 0 ? void 0 : _l[1];
222
- const releaseId = parseInt((_r = (_q = (_p = (_o = (_m = el.querySelector('a.item_release_link')) === null || _m === void 0 ? void 0 : _m.href.split('release/')) === null || _o === void 0 ? void 0 : _o.pop()) === null || _p === void 0 ? void 0 : _p.split('-')) === null || _q === void 0 ? void 0 : _q.shift()) !== null && _r !== void 0 ? _r : '0');
223
- const itemId = parseInt((_u = (_t = (_s = el.querySelector('a.item_description_title')) === null || _s === void 0 ? void 0 : _s.href) === null || _t === void 0 ? void 0 : _t.split('/').pop()) !== null && _u !== void 0 ? _u : '0');
224
- const originalTitle = (_v = el.querySelector('a.item_description_title')) === null || _v === void 0 ? void 0 : _v.textContent;
225
- const firstIndexOfDash = (_w = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.lastIndexOf(' - ')) !== null && _w !== void 0 ? _w : -1;
226
- const lastIndexOfParenthesis = (_x = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.lastIndexOf(' (')) !== null && _x !== void 0 ? _x : -1;
206
+ items: ((_e = [...document.querySelectorAll('table.table_block tbody tr')]) === null || _e === void 0 ? void 0 : _e.map(el => {
207
+ 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;
208
+ const shipping = this.convertDevise((_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 : '');
209
+ 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);
210
+ 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);
211
+ 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 : '';
212
+ const isoCountryCode = (Object.keys(ECountryCode_1.default).find((key) => (ECountryName_1.default[key] === countryName))
213
+ || EDiscogsCountryNameToIsoCode_1.default[countryName]);
214
+ 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);
215
+ 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);
216
+ const notes = Number.parseInt((_5 = (_4 = (_3 = (_2 = (_1 = (_0 = (_z = el.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);
217
+ const originalTitle = (_6 = el.querySelector('a.item_description_title')) === null || _6 === void 0 ? void 0 : _6.textContent;
218
+ const firstIndexOfDash = (_7 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.indexOf(' - ')) !== null && _7 !== void 0 ? _7 : -1;
219
+ const lastIndexOfParenthesis = (_8 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.lastIndexOf(' (')) !== null && _8 !== void 0 ? _8 : -1;
227
220
  return {
228
- itemId: isNaN(itemId) ? 0 : itemId,
221
+ itemId: Number.isNaN(itemId) ? 0 : itemId,
229
222
  title: {
230
- original: originalTitle,
231
- artist: originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(0, firstIndexOfDash),
232
- item: firstIndexOfDash > -1 && lastIndexOfParenthesis > -1 ?
233
- originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(firstIndexOfDash + 3, lastIndexOfParenthesis) : '',
234
- formats: lastIndexOfParenthesis > -1 ?
235
- ((_z = (_y = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(lastIndexOfParenthesis + 2, originalTitle.length - 1)) === null || _y === void 0 ? void 0 : _y.split(', ')) !== null && _z !== void 0 ? _z : []) : [],
223
+ original: originalTitle !== null && originalTitle !== void 0 ? originalTitle : '',
224
+ artist: (_9 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(0, firstIndexOfDash)) !== null && _9 !== void 0 ? _9 : '',
225
+ item: firstIndexOfDash > -1 && lastIndexOfParenthesis > -1
226
+ ? (_10 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(firstIndexOfDash + 3, lastIndexOfParenthesis)) !== null && _10 !== void 0 ? _10 : ''
227
+ : '',
228
+ formats: lastIndexOfParenthesis > -1
229
+ ? ((_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 : [])
230
+ : [],
236
231
  },
237
- url: `https://www.discogs.com${(_0 = el.querySelector('a.item_description_title')) === null || _0 === void 0 ? void 0 : _0.href}`,
238
- labels: [...new Set((_1 = [...el.querySelectorAll('.label_and_cat a[href^=\'https://www.discogs.com/\']')]) === null || _1 === void 0 ? void 0 : _1.map(x => x === null || x === void 0 ? void 0 : x.textContent))],
239
- catnos: (_5 = (_4 = (_3 = (_2 = el.querySelector('.label_and_cat .item_catno')) === null || _2 === void 0 ? void 0 : _2.textContent) === null || _3 === void 0 ? void 0 : _3.replace(/\s+/g, ' ')) === null || _4 === void 0 ? void 0 : _4.split(', ')) === null || _5 === void 0 ? void 0 : _5.filter(x => x !== 'none'),
240
- imageUrl: (_6 = el.querySelector('.marketplace_image')) === null || _6 === void 0 ? void 0 : _6.getAttribute('data-src'),
241
- description: (_9 = (_8 = (_7 = el.querySelector('.item_description > p.hide_mobile:not(.label_and_cat)')) === null || _7 === void 0 ? void 0 : _7.textContent) === null || _8 === void 0 ? void 0 : _8.replace(/\s+/g, ' ')) === null || _9 === void 0 ? void 0 : _9.trim(),
242
- isAcceptingOffer: ((_12 = (_11 = (_10 = el.querySelector('.item_add_to_cart p a strong')) === null || _10 === void 0 ? void 0 : _10.textContent) === null || _11 === void 0 ? void 0 : _11.split('/')) === null || _12 === void 0 ? void 0 : _12.length) > 1,
243
- isAvailable: !((_13 = el.classList) === null || _13 === void 0 ? void 0 : _13.contains('unavailable')),
232
+ url: `https://www.discogs.com${(_13 = el.querySelector('a.item_description_title')) === null || _13 === void 0 ? void 0 : _13.href}`,
233
+ 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),
234
+ catnos: (_20 = (_19 = (_18 = (_17 = (_16 = el.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 : [],
235
+ imageUrl: (_22 = (_21 = el.querySelector('.marketplace_image')) === null || _21 === void 0 ? void 0 : _21.getAttribute('data-src')) !== null && _22 !== void 0 ? _22 : '',
236
+ 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 : '',
237
+ 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,
238
+ isAvailable: !((_32 = el.classList) === null || _32 === void 0 ? void 0 : _32.contains('unavailable')),
244
239
  condition: {
245
240
  media: {
246
- full: (_16 = (_15 = (_14 = el.querySelector('.item_condition span:nth-child(3)')) === null || _14 === void 0 ? void 0 : _14.textContent) === null || _15 === void 0 ? void 0 : _15.replace(/\s+/g, ' ')) === null || _16 === void 0 ? void 0 : _16.trim(),
247
- short: (_21 = (_20 = (_19 = (_18 = (_17 = el.querySelector('.item_condition span:nth-child(3)')) === 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.trim()) === null || _20 === void 0 ? void 0 : _20.match(/\(([^)]+)\)/)) === null || _21 === void 0 ? void 0 : _21[1]
241
+ 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 : '',
242
+ short: (_42 = (_41 = (_40 = (_39 = (_38 = (_37 = el.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 : '',
248
243
  },
249
244
  sleeve: {
250
- full: (_22 = el.querySelector('.item_condition span.item_sleeve_condition')) === null || _22 === void 0 ? void 0 : _22.textContent,
251
- short: (_25 = (_24 = (_23 = el.querySelector('.item_condition span.item_sleeve_condition')) === null || _23 === void 0 ? void 0 : _23.textContent) === null || _24 === void 0 ? void 0 : _24.match(/\(([^)]+)\)/)) === null || _25 === void 0 ? void 0 : _25[1]
252
- }
245
+ full: (_44 = (_43 = el.querySelector('.item_condition span.item_sleeve_condition')) === null || _43 === void 0 ? void 0 : _43.textContent) !== null && _44 !== void 0 ? _44 : '',
246
+ short: (_48 = (_47 = (_46 = (_45 = el.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 : '',
247
+ },
253
248
  },
254
249
  seller: {
255
- name: (_26 = el.querySelector('.seller_info a')) === null || _26 === void 0 ? void 0 : _26.textContent,
256
- score: (_27 = el.querySelector('.seller_info li:nth-child(2) strong')) === null || _27 === void 0 ? void 0 : _27.textContent,
257
- notes: (_32 = (_31 = (_30 = (_29 = (_28 = el.querySelector('.seller_info li:nth-child(2) .section_link')) === null || _28 === void 0 ? void 0 : _28.textContent) === null || _29 === void 0 ? void 0 : _29.replace(/\s+/g, ' ')) === null || _30 === void 0 ? void 0 : _30.trim()) === null || _31 === void 0 ? void 0 : _31.split(' ')) === null || _32 === void 0 ? void 0 : _32[0]
250
+ name: (_50 = (_49 = el.querySelector('.seller_info a')) === null || _49 === void 0 ? void 0 : _49.textContent) !== null && _50 !== void 0 ? _50 : '',
251
+ url: `https://www.discogs.com${(_51 = el.querySelector('.seller_info a')) === null || _51 === void 0 ? void 0 : _51.href}`,
252
+ 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 : '',
253
+ notes: Number.isNaN(notes) ? 0 : notes,
258
254
  },
259
255
  price: {
260
- base: this.convertDevise((_35 = (_34 = (_33 = el.querySelector('.price')) === 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.replace(/,/, '.')),
261
- shipping: isNaN(parseFloat(shipping)) ? null : shipping,
256
+ base: this.convertDevise((_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 : ''),
257
+ shipping: Number.isNaN(parseFloat(shipping)) ? null : shipping,
262
258
  },
263
259
  from: {
264
- countryName: country,
265
- isoCountryName: (_37 = (_36 = EFromIso_1.EFromIso[country]) !== null && _36 !== void 0 ? _36 : country) !== null && _37 !== void 0 ? _37 : '',
266
- isoCode: EFromIso_1.EFromIsoCode[(_39 = (_38 = EFromIso_1.EFromIso[country]) !== null && _38 !== void 0 ? _38 : country) !== null && _39 !== void 0 ? _39 : ''],
260
+ countryName,
261
+ isoCountryName: (_58 = ECountryName_1.default[isoCountryCode]) !== null && _58 !== void 0 ? _58 : '',
262
+ isoCountryCode,
267
263
  },
268
264
  community: {
269
- have: isNaN(have) ? 0 : have,
270
- want: isNaN(want) ? 0 : want
265
+ have: Number.isNaN(have) ? 0 : have,
266
+ want: Number.isNaN(want) ? 0 : want,
267
+ },
268
+ release: {
269
+ id: Number.isNaN(releaseId) ? 0 : releaseId,
270
+ url: `https://www.discogs.com${(_59 = el.querySelector('a.item_release_link')) === null || _59 === void 0 ? void 0 : _59.href}`,
271
271
  },
272
- releaseUrl: `https://www.discogs.com${(_40 = el.querySelector('a.item_release_link')) === null || _40 === void 0 ? void 0 : _40.href}`,
273
- releaseId: isNaN(releaseId) ? 0 : releaseId,
274
272
  };
275
273
  })) || [],
276
274
  page: {
277
275
  current: this.page,
278
- total: Math.ceil(totalItems / this.limit)
276
+ total: Math.ceil(totalItems / this.limit),
279
277
  },
280
- item: {
278
+ result: {
281
279
  total: totalItems,
282
280
  perPage: this.limit,
283
281
  },
284
282
  search: {
285
- value: this.searchValue,
286
- type: this.searchType
283
+ value: (_f = this.searchValue) !== null && _f !== void 0 ? _f : '',
284
+ type: this.searchType,
287
285
  },
288
- urlGenerated: this.url
286
+ urlGenerated: this.url,
289
287
  };
290
288
  }
291
289
  }
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Limits per page
3
- * @type {number[]}
4
- * @readonly
5
3
  */
6
- export declare type TLimit = 25 | 50 | 100 | 250;
4
+ declare type TLimit = 25 | 50 | 100 | 250;
5
+ export default TLimit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discogs-marketplace-api-nodejs",
3
- "version": "1.3.2",
3
+ "version": "1.3.6",
4
4
  "description": "Another (better ?) NodeJs library to fetch data from Discog's marketplace",
5
5
  "keywords": [
6
6
  "discogs",
@@ -16,30 +16,37 @@
16
16
  "author": "KirianCaumes",
17
17
  "license": "MIT",
18
18
  "scripts": {
19
- "start": "nodemon -r tsconfig-paths/register ./lib/index.ts",
20
- "build": "ttsc --project tsconfig.build.json ",
19
+ "start": "nodemon -r tsconfig-paths/register ./src/index.ts",
20
+ "build": "ttsc --project tsconfig.build.json --skipLibCheck",
21
21
  "test": "jest",
22
- "prepare": "npm run build"
22
+ "prepare": "npm run build",
23
+ "lint:fix": "eslint \"src/**/*.ts\" --fix",
24
+ "lint": "eslint \"src/**/*.ts\""
23
25
  },
24
26
  "main": "dist/index.js",
25
27
  "types": "dist/index.d.ts",
26
28
  "dependencies": {
27
- "jsdom": "^17.0.0",
28
- "playwright-chromium": "^1.15.1",
29
- "ts-node": "^10.2.1",
30
- "tsconfig-paths": "^3.11.0",
31
- "user-agents": "^1.0.793"
29
+ "linkedom": "^0.13.0",
30
+ "playwright-chromium": "^1.17.2",
31
+ "ts-node": "^10.4.0",
32
+ "tsconfig-paths": "^3.12.0",
33
+ "user-agents": "^1.0.899"
32
34
  },
33
35
  "devDependencies": {
34
- "@types/jest": "^27.0.2",
35
- "@types/jsdom": "^16.2.13",
36
- "@types/node": "^16.10.2",
36
+ "@types/jest": "^27.4.0",
37
+ "@types/node": "^17.0.9",
37
38
  "@types/puppeteer": "^5.4.4",
38
39
  "@types/user-agents": "^1.0.2",
39
- "jest": "^27.2.4",
40
- "ts-jest": "^27.0.5",
41
- "ttypescript": "^1.5.12",
42
- "typescript": "^4.4.3",
40
+ "@typescript-eslint/eslint-plugin": "^5.10.0",
41
+ "@typescript-eslint/parser": "^5.10.0",
42
+ "eslint": "^8.7.0",
43
+ "eslint-config-airbnb-base": "^15.0.0",
44
+ "eslint-config-airbnb-typescript": "^16.1.0",
45
+ "eslint-plugin-import": "^2.25.4",
46
+ "jest": "^27.4.7",
47
+ "ts-jest": "^27.1.3",
48
+ "ttypescript": "^1.5.13",
49
+ "typescript": "^4.5.4",
43
50
  "typescript-transform-paths": "^3.3.1"
44
51
  }
45
52
  }
package/.gitattributes DELETED
@@ -1 +0,0 @@
1
- test/html/* linguist-vendored
package/notes.md DELETED
@@ -1,9 +0,0 @@
1
- ```js
2
- //Get data from Enum on discogs
3
- var res= {}
4
- ;[...temp2.querySelectorAll('a')].forEach(x => {
5
- const urlParams = new URLSearchParams(x.href)
6
-
7
- res[x.querySelector('.link_text').innerText.replace(/(\s|\-|\&|\_|\/|,|\'|\.)/g, '').toUpperCase()] = urlParams.get('format')
8
- })
9
- ```
@@ -1,40 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es6",
4
- "module": "commonjs",
5
- "declaration": true,
6
- "outDir": "./dist",
7
- "strict": true,
8
- "esModuleInterop": true,
9
- "baseUrl": "./",
10
- "paths": {
11
- "@enum/*": [
12
- "lib/enum/*"
13
- ],
14
- "@interface/*": [
15
- "lib/interface/*"
16
- ],
17
- "@type/*": [
18
- "lib/type/*"
19
- ],
20
- "@main/*": [
21
- "lib/*"
22
- ],
23
- },
24
- "plugins": [
25
- {
26
- "transform": "typescript-transform-paths"
27
- },
28
- {
29
- "transform": "typescript-transform-paths",
30
- "afterDeclarations": true
31
- }
32
- ]
33
- },
34
- "include": [
35
- "lib/**/*"
36
- ],
37
- "exclude": [
38
- "node_modules"
39
- ]
40
- }