discogs-marketplace-api-nodejs 1.4.0 → 1.5.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
|
@@ -12,21 +12,21 @@ npm install discogs-marketplace-api-nodejs
|
|
|
12
12
|
|
|
13
13
|
### Import and search
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
With ECMAScript 6 and +
|
|
16
16
|
|
|
17
|
-
```
|
|
18
|
-
import DiscogsMarketplace, { EType
|
|
17
|
+
```js
|
|
18
|
+
import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
|
|
19
19
|
|
|
20
20
|
DiscogsMarketplace.search({ searchType: EType.ARTIST, searchValue: 244819 })
|
|
21
|
-
.then(
|
|
21
|
+
.then(res => {
|
|
22
22
|
console.log(res)
|
|
23
23
|
})
|
|
24
|
-
.catch(
|
|
24
|
+
.catch(err => {
|
|
25
25
|
console.error(err)
|
|
26
26
|
})
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
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`.
|
|
@@ -34,7 +34,7 @@ declare enum EDiscogsCountryNameToIsoCode {
|
|
|
34
34
|
'Martinique (French)' = "MQ",
|
|
35
35
|
'Micronesia' = "FM",
|
|
36
36
|
'Netherlands Antilles' = "CW",
|
|
37
|
-
'Neutral Zone' = "
|
|
37
|
+
'Neutral Zone' = "",
|
|
38
38
|
'New Caledonia (French)' = "NC",
|
|
39
39
|
'Pitcairn Island' = "PN",
|
|
40
40
|
'Polynesia (French)' = "PF",
|
|
@@ -37,7 +37,7 @@ var EDiscogsCountryNameToIsoCode;
|
|
|
37
37
|
EDiscogsCountryNameToIsoCode["Martinique (French)"] = "MQ";
|
|
38
38
|
EDiscogsCountryNameToIsoCode["Micronesia"] = "FM";
|
|
39
39
|
EDiscogsCountryNameToIsoCode["Netherlands Antilles"] = "CW";
|
|
40
|
-
EDiscogsCountryNameToIsoCode["Neutral Zone"] = "
|
|
40
|
+
EDiscogsCountryNameToIsoCode["Neutral Zone"] = "";
|
|
41
41
|
EDiscogsCountryNameToIsoCode["New Caledonia (French)"] = "NC";
|
|
42
42
|
EDiscogsCountryNameToIsoCode["Pitcairn Island"] = "PN";
|
|
43
43
|
EDiscogsCountryNameToIsoCode["Polynesia (French)"] = "PF";
|
package/dist/marketplace.d.ts
CHANGED
package/dist/marketplace.js
CHANGED
|
@@ -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 =
|
|
30
|
-
var _a, _b, _c, _d
|
|
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
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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: (
|
|
99
|
-
code:
|
|
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:
|
|
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
|
|
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.
|
|
3
|
+
"version": "1.5.1",
|
|
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
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"user-agents": "^1.0.
|
|
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.
|
|
36
|
-
"@types/node": "^18.
|
|
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.
|
|
39
|
-
"@typescript-eslint/parser": "^5.
|
|
40
|
-
"eslint": "^8.
|
|
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
|
|
46
|
-
"ts-jest": "^29.0.
|
|
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",
|