discogs-marketplace-api-nodejs 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.MD CHANGED
@@ -12,21 +12,21 @@ npm install discogs-marketplace-api-nodejs
12
12
 
13
13
  ### Import and search
14
14
 
15
- In Typescript
15
+ With ECMAScript 6 and +
16
16
 
17
- ```ts
18
- import DiscogsMarketplace, { EType, IOutputSuccess, IOutputError } from 'discogs-marketplace-api-nodejs'
17
+ ```js
18
+ import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
19
19
 
20
20
  DiscogsMarketplace.search({ searchType: EType.ARTIST, searchValue: 244819 })
21
- .then((res: IOutputSuccess) => {
21
+ .then(res=> {
22
22
  console.log(res)
23
23
  })
24
- .catch((err: IOutputError) => {
24
+ .catch(err => {
25
25
  console.error(err)
26
26
  })
27
27
  ```
28
28
 
29
- In Javascript with require
29
+ With commonJS
30
30
 
31
31
  ```js
32
32
  const DiscogsMarketplace = require('discogs-marketplace-api-nodejs').default
@@ -218,14 +218,6 @@ Finally, you can open a pull request with your new additions.
218
218
 
219
219
  ## Know issues
220
220
 
221
- ### Playwright
222
-
223
- Try this if chrome wasn't installed with `npm i`:
224
-
225
- ```sh
226
- npx playwright install
227
- ```
228
-
229
221
  ### Linkedom
230
222
 
231
223
  If you are using this librairy on a Typescript project, you might encounter issues with `linkedom`.
@@ -31,5 +31,5 @@ export default abstract class Marketplace {
31
31
  * @param urlGenerated Url generated
32
32
  * @returns Items found
33
33
  */
34
- private static getItem;
34
+ private static getData;
35
35
  }
@@ -12,12 +12,12 @@ 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 playwright_chromium_1 = require("playwright-chromium");
16
15
  const user_agents_1 = __importDefault(require("user-agents"));
17
16
  const linkedom_1 = require("linkedom");
18
17
  const enums_1 = require("./enums/index.js");
19
18
  const translate_1 = require("./enums/iso/translate/index.js");
20
19
  const iso_1 = require("./enums/iso/index.js");
20
+ const axios_1 = __importDefault(require("axios"));
21
21
  /**
22
22
  * Discogs Marketplace
23
23
  */
@@ -26,81 +26,54 @@ class Marketplace {
26
26
  * Search elements on discogs
27
27
  * @returns Items found
28
28
  */
29
- static search({ searchType = enums_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 = enums_1.ESort.LISTED_NEWEST, limit = 25, page = 1, lang = enums_1.ELang.ENGLISH, }) {
30
- var _a, _b, _c, _d, _e, _f;
29
+ static search({ searchType = enums_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 = undefined, limit = 25, page = undefined, lang = enums_1.ELang.ENGLISH, }) {
30
+ var _a, _b, _c, _d;
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
32
  try {
33
- /** Init browser */
34
- const browser = yield playwright_chromium_1.chromium.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });
35
- /** Init context */
36
- const browserContext = yield browser.newContext({
37
- userAgent: new user_agents_1.default().toString(),
38
- });
39
- /** Init page */
40
- const browserPage = yield browserContext.newPage();
41
- /** Block useless ressources */
42
- yield browserPage.route('**/*', route => ([
43
- 'stylesheet',
44
- 'image',
45
- 'media',
46
- 'font',
47
- 'script',
48
- 'texttrack',
49
- 'xhr',
50
- 'fetch',
51
- 'eventsource',
52
- 'websocket',
53
- 'manifest',
54
- 'other',
55
- ].includes(route.request().resourceType()) ? route.abort() : route.continue()));
56
- /** Init page */
57
- const response = yield browserPage.goto(`${this.generateUrl({
58
- searchType,
59
- seller,
60
- lang,
61
- })}?${this.serializeParams({
62
- [searchType]: searchValue,
63
- currency,
64
- genre,
65
- style: (style === null || style === void 0 ? void 0 : style.length) ? style : undefined,
66
- format: (format === null || format === void 0 ? void 0 : format.length) ? format === null || format === void 0 ? void 0 : format[0] : undefined,
67
- format_desc: (formatDescription === null || formatDescription === void 0 ? void 0 : formatDescription.length) ? formatDescription[0] : undefined,
68
- condition: (mediaCondition === null || mediaCondition === void 0 ? void 0 : mediaCondition.length) ? mediaCondition[0] : undefined,
69
- year: year && !years ? year : undefined,
70
- year1: (years === null || years === void 0 ? void 0 : years.min) && !year ? years === null || years === void 0 ? void 0 : years.min : undefined,
71
- year2: (years === null || years === void 0 ? void 0 : years.max) && !year ? years === null || years === void 0 ? void 0 : years.max : undefined,
72
- audio: isAudioSample ? 1 : 0,
73
- offers: isMakeAnOfferOnly ? 1 : 0,
74
- ships_from: (from === null || from === void 0 ? void 0 : from.length) ? from : undefined,
75
- limit,
76
- page,
77
- sort,
78
- })}`, { waitUntil: 'domcontentloaded' });
79
- /** Get url */
80
- const urlGenerated = browserPage.url();
81
- /** Get HTML */
82
- const bodyHTML = yield browserPage.evaluate(() => { var _a; return (_a = document.getElementById('page_content')) === null || _a === void 0 ? void 0 : _a.outerHTML; });
83
- /** Close browser */
84
- yield browser.close();
85
- /** If error, reject */
86
- if (((_a = response === null || response === void 0 ? void 0 : response.status()) !== null && _a !== void 0 ? _a : 0) >= 400)
87
- // eslint-disable-next-line @typescript-eslint/no-throw-literal
88
- throw { document: bodyHTML, status: (_b = response === null || response === void 0 ? void 0 : response.status()) !== null && _b !== void 0 ? _b : 0 };
89
- return this.getItem((0, linkedom_1.parseHTML)(bodyHTML).document, urlGenerated, {
33
+ const config = {
34
+ url: this.generateUrl({ searchType, seller, lang }),
35
+ method: 'GET',
36
+ params: {
37
+ [searchType]: searchValue,
38
+ currency,
39
+ genre,
40
+ style: (style === null || style === void 0 ? void 0 : style.length) ? style : undefined,
41
+ format: (format === null || format === void 0 ? void 0 : format.length) ? format : undefined,
42
+ format_desc: (formatDescription === null || formatDescription === void 0 ? void 0 : formatDescription.length) ? formatDescription : undefined,
43
+ condition: (mediaCondition === null || mediaCondition === void 0 ? void 0 : mediaCondition.length) ? mediaCondition : undefined,
44
+ year: year && !years ? year : undefined,
45
+ year1: (years === null || years === void 0 ? void 0 : years.min) && !year ? years === null || years === void 0 ? void 0 : years.min : undefined,
46
+ year2: (years === null || years === void 0 ? void 0 : years.max) && !year ? years === null || years === void 0 ? void 0 : years.max : undefined,
47
+ audio: isAudioSample ? 1 : undefined,
48
+ offers: isMakeAnOfferOnly ? 1 : undefined,
49
+ ships_from: (from === null || from === void 0 ? void 0 : from.length) ? from : undefined,
50
+ limit,
51
+ page,
52
+ sort,
53
+ },
54
+ paramsSerializer: this.serializeParams,
55
+ headers: {
56
+ 'X-PJAX': 'true',
57
+ 'User-Agent': new user_agents_1.default().toString(),
58
+ },
59
+ };
60
+ const { data: bodyHTML } = yield axios_1.default.request(config);
61
+ return this.getData((0, linkedom_1.parseHTML)(bodyHTML).document, axios_1.default.getUri(config), {
90
62
  searchType, searchValue, limit, page,
91
63
  });
92
64
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
65
  }
94
66
  catch (error) {
95
- if ((error === null || error === void 0 ? void 0 : error.document) && error.status)
67
+ const { response, message } = error;
68
+ if ((response === null || response === void 0 ? void 0 : response.data) && response.status)
96
69
  // eslint-disable-next-line @typescript-eslint/no-throw-literal
97
70
  throw {
98
- message: (_f = (_e = (_d = (_c = (0, linkedom_1.parseHTML)(error.document).document) === null || _c === void 0 ? void 0 : _c.querySelector('h1 + p')) === null || _d === void 0 ? void 0 : _d.innerHTML) === null || _e === void 0 ? void 0 : _e.trim()) !== null && _f !== void 0 ? _f : 'An error occured',
99
- code: error.status,
71
+ message: (_d = (_c = (_b = (_a = (0, linkedom_1.parseHTML)(response.data).document) === null || _a === void 0 ? void 0 : _a.querySelector('h1 + p')) === null || _b === void 0 ? void 0 : _b.innerHTML) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : 'An error occured',
72
+ code: response.status,
100
73
  };
101
74
  // eslint-disable-next-line @typescript-eslint/no-throw-literal
102
75
  throw {
103
- message: (error === null || error === void 0 ? void 0 : error.message) || 'An error occured',
76
+ message: message || 'An error occured',
104
77
  code: 500,
105
78
  };
106
79
  }
@@ -175,7 +148,7 @@ class Marketplace {
175
148
  * @param urlGenerated Url generated
176
149
  * @returns Items found
177
150
  */
178
- static getItem(document, urlGenerated, { searchType = enums_1.EType.STRING, searchValue = undefined, limit = 25, page = 1, }) {
151
+ static getData(document, urlGenerated, { searchType = enums_1.EType.STRING, searchValue = undefined, limit = 25, page = 1, }) {
179
152
  var _a, _b, _c, _d, _e;
180
153
  const totalItems = parseFloat(
181
154
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discogs-marketplace-api-nodejs",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Another (better ?) NodeJs library to fetch data from Discog's marketplace",
5
5
  "keywords": [
6
6
  "discogs",
@@ -27,23 +27,23 @@
27
27
  "main": "dist/index.js",
28
28
  "types": "dist/index.d.ts",
29
29
  "dependencies": {
30
- "linkedom": "^0.14.16",
31
- "playwright-chromium": "^1.26.1",
32
- "user-agents": "^1.0.1151"
30
+ "axios": "^0.27.2",
31
+ "linkedom": "^0.14.17",
32
+ "user-agents": "^1.0.1168"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/jest": "^29.0.3",
36
- "@types/node": "^18.7.23",
35
+ "@types/jest": "^29.1.2",
36
+ "@types/node": "^18.8.5",
37
37
  "@types/user-agents": "^1.0.2",
38
- "@typescript-eslint/eslint-plugin": "^5.38.1",
39
- "@typescript-eslint/parser": "^5.38.1",
40
- "eslint": "^8.24.0",
38
+ "@typescript-eslint/eslint-plugin": "^5.40.0",
39
+ "@typescript-eslint/parser": "^5.40.0",
40
+ "eslint": "^8.25.0",
41
41
  "eslint-config-airbnb-base": "^15.0.0",
42
42
  "eslint-config-airbnb-typescript": "^17.0.0",
43
43
  "eslint-plugin-import": "^2.26.0",
44
44
  "eslint-plugin-jsdoc": "^39.3.6",
45
- "jest": "^29.0.3",
46
- "ts-jest": "^29.0.2",
45
+ "jest": "^29.2.0",
46
+ "ts-jest": "^29.0.3",
47
47
  "ts-node": "^10.9.1",
48
48
  "tsc-alias": "^1.7.0",
49
49
  "tsconfig-paths": "^4.1.0",