discogs-marketplace-api-nodejs 1.3.3 → 1.3.4
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 +48 -43
- package/dist/enum/ECurrency.d.ts +2 -3
- package/dist/enum/ECurrency.js +2 -4
- package/dist/enum/EFormat.d.ts +2 -3
- package/dist/enum/EFormat.js +2 -4
- package/dist/enum/EFormatDescription.d.ts +2 -3
- package/dist/enum/EFormatDescription.js +2 -4
- package/dist/enum/EFrom.d.ts +2 -3
- package/dist/enum/EFrom.js +3 -4
- package/dist/enum/EFromIso.d.ts +53 -53
- package/dist/enum/EGenre.d.ts +2 -3
- package/dist/enum/EGenre.js +2 -4
- package/dist/enum/ELang.d.ts +2 -3
- package/dist/enum/ELang.js +2 -4
- package/dist/enum/EMediaCondition.d.ts +2 -3
- package/dist/enum/EMediaCondition.js +2 -4
- package/dist/enum/ESort.d.ts +2 -3
- package/dist/enum/ESort.js +2 -4
- package/dist/enum/EStyle.d.ts +2 -3
- package/dist/enum/EStyle.js +2 -4
- package/dist/enum/EType.d.ts +2 -3
- package/dist/enum/EType.js +2 -4
- package/dist/enum/iso/ECountryCode.d.ts +255 -0
- package/dist/enum/iso/ECountryCode.js +258 -0
- package/dist/enum/iso/ECountryName.d.ts +255 -0
- package/dist/enum/iso/ECountryName.js +258 -0
- package/dist/enum/iso/EDiscogsCountryNameToIsoCode.d.ts +69 -0
- package/dist/enum/iso/EDiscogsCountryNameToIsoCode.js +72 -0
- package/dist/enum/iso/EDiscogsCurrencyToIsoCode.d.ts +23 -0
- package/dist/enum/iso/EDiscogsCurrencyToIsoCode.js +26 -0
- package/dist/enum/iso/translate/EDiscogsCountryNameToIsoCode.d.ts +69 -0
- package/dist/enum/iso/translate/EDiscogsCountryNameToIsoCode.js +72 -0
- package/dist/enum/iso/translate/EDiscogsCurrencyToIsoCode.d.ts +23 -0
- package/dist/enum/iso/translate/EDiscogsCurrencyToIsoCode.js +26 -0
- package/dist/enum/iso/translates/EDiscogsCountryNameToIsoCode.d.ts +69 -0
- package/dist/enum/iso/translates/EDiscogsCountryNameToIsoCode.js +72 -0
- package/dist/enum/iso/translates/EDiscogsCurrencyToIsoCode.d.ts +23 -0
- package/dist/enum/iso/translates/EDiscogsCurrencyToIsoCode.js +26 -0
- package/dist/index.d.ts +14 -14
- package/dist/index.js +22 -21
- package/dist/interface/IDiscogsMarketplace.d.ts +1 -2
- package/dist/interface/IInput.d.ts +12 -12
- package/dist/interface/IInput.js +11 -0
- package/dist/interface/IItem.d.ts +11 -6
- package/dist/interface/IItem.js +5 -0
- package/dist/interface/IOutputError.d.ts +1 -1
- package/dist/interface/IOutputSuccess.d.ts +4 -4
- package/dist/interface/IOutputSuccess.js +1 -0
- package/dist/interface/IYears.d.ts +1 -1
- package/dist/marketplace.d.ts +28 -42
- package/dist/marketplace.js +119 -120
- package/dist/type/TLimit.d.ts +2 -3
- package/package.json +23 -16
- package/.gitattributes +0 -1
- package/notes.md +0 -9
- package/tsconfig.build.json +0 -40
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import IItem from "./IItem";
|
|
2
|
-
import
|
|
2
|
+
import EType from "../enum/EType";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Result provided to user
|
|
5
5
|
*/
|
|
6
6
|
export default interface IOutputSuccess {
|
|
7
|
-
|
|
7
|
+
items: IItem[];
|
|
8
8
|
page: {
|
|
9
9
|
current: number;
|
|
10
10
|
total: number;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
result: {
|
|
13
13
|
total: number;
|
|
14
14
|
perPage: number;
|
|
15
15
|
};
|
package/dist/marketplace.d.ts
CHANGED
|
@@ -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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
/** Url generated by
|
|
40
|
-
|
|
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
|
|
30
|
+
* @returns Items found
|
|
45
31
|
*/
|
|
46
32
|
search(): Promise<IOutputSuccess>;
|
|
47
33
|
/**
|
|
48
34
|
* Generate URL to be parsed
|
|
49
|
-
* @returns
|
|
35
|
+
* @returns Url
|
|
50
36
|
*/
|
|
51
37
|
private generateUrl;
|
|
52
38
|
/**
|
|
53
39
|
* Serialize params URL
|
|
54
|
-
* @param
|
|
55
|
-
* @returns
|
|
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
|
|
47
|
+
* @returns Cleanup string
|
|
62
48
|
*/
|
|
63
49
|
private convertDevise;
|
|
64
50
|
/**
|
|
65
51
|
* Parse HTML to clean result
|
|
66
|
-
* @param
|
|
67
|
-
* @returns
|
|
52
|
+
* @param document Document to parse
|
|
53
|
+
* @returns Items found
|
|
68
54
|
*/
|
|
69
55
|
private getItem;
|
|
70
56
|
}
|
package/dist/marketplace.js
CHANGED
|
@@ -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
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
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
|
|
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/translates/EDiscogsCurrencyToIsoCode"));
|
|
35
|
+
const EDiscogsCountryNameToIsoCode_1 = __importDefault(require("./enum/iso/translates/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.
|
|
33
|
-
/** Url generated by
|
|
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
|
|
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
|
|
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,178 @@ class Marketplace {
|
|
|
104
113
|
/** Get url */
|
|
105
114
|
this.url = page.url();
|
|
106
115
|
/** Get HTML */
|
|
107
|
-
const bodyHTML = yield page.evaluate(() => document.
|
|
116
|
+
const bodyHTML = yield page.evaluate(() => { var _a; return (_a = document.querySelector('table.table_block')) === 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((
|
|
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: (
|
|
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
|
|
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.
|
|
148
|
+
url += this.searchType === EType_1.default.USER ? 'mywants' : 'profile';
|
|
137
149
|
}
|
|
138
150
|
else {
|
|
139
|
-
url +=
|
|
140
|
-
url += this.searchType === EType_1.
|
|
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
|
|
147
|
-
* @returns
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
|
185
|
+
* @returns Cleanup string
|
|
176
186
|
*/
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
|
210
|
-
* @returns
|
|
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(/(
|
|
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
|
-
|
|
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((
|
|
220
|
-
const want = parseInt((
|
|
221
|
-
const
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
const
|
|
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, _60;
|
|
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 = ((_r = Object.keys(ECountryCode_1.default)
|
|
213
|
+
.find((key) => ECountryName_1.default[key] === countryName
|
|
214
|
+
|| EDiscogsCountryNameToIsoCode_1.default[countryName])) !== null && _r !== void 0 ? _r : '');
|
|
215
|
+
const releaseId = Number.parseInt((_w = (_v = (_u = (_t = (_s = el.querySelector('a.item_release_link')) === null || _s === void 0 ? void 0 : _s.href.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);
|
|
216
|
+
const itemId = Number.parseInt((_z = (_y = (_x = el.querySelector('a.item_description_title')) === null || _x === void 0 ? void 0 : _x.href) === null || _y === void 0 ? void 0 : _y.split('/').pop()) !== null && _z !== void 0 ? _z : '0', 10);
|
|
217
|
+
const notes = Number.parseInt((_6 = (_5 = (_4 = (_3 = (_2 = (_1 = (_0 = el.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);
|
|
218
|
+
const originalTitle = (_7 = el.querySelector('a.item_description_title')) === null || _7 === void 0 ? void 0 : _7.textContent;
|
|
219
|
+
const firstIndexOfDash = (_8 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.indexOf(' - ')) !== null && _8 !== void 0 ? _8 : -1;
|
|
220
|
+
const lastIndexOfParenthesis = (_9 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.lastIndexOf(' (')) !== null && _9 !== void 0 ? _9 : -1;
|
|
227
221
|
return {
|
|
228
|
-
itemId: isNaN(itemId) ? 0 : itemId,
|
|
222
|
+
itemId: Number.isNaN(itemId) ? 0 : itemId,
|
|
229
223
|
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
|
-
|
|
235
|
-
|
|
224
|
+
original: originalTitle !== null && originalTitle !== void 0 ? originalTitle : '',
|
|
225
|
+
artist: (_10 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(0, firstIndexOfDash)) !== null && _10 !== void 0 ? _10 : '',
|
|
226
|
+
item: firstIndexOfDash > -1 && lastIndexOfParenthesis > -1
|
|
227
|
+
? (_11 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(firstIndexOfDash + 3, lastIndexOfParenthesis)) !== null && _11 !== void 0 ? _11 : ''
|
|
228
|
+
: '',
|
|
229
|
+
formats: lastIndexOfParenthesis > -1
|
|
230
|
+
? ((_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 : [])
|
|
231
|
+
: [],
|
|
236
232
|
},
|
|
237
|
-
url: `https://www.discogs.com${(
|
|
238
|
-
labels:
|
|
239
|
-
catnos: (
|
|
240
|
-
imageUrl: (
|
|
241
|
-
description: (
|
|
242
|
-
isAcceptingOffer: ((
|
|
243
|
-
isAvailable: !((
|
|
233
|
+
url: `https://www.discogs.com${(_14 = el.querySelector('a.item_description_title')) === null || _14 === void 0 ? void 0 : _14.href}`,
|
|
234
|
+
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),
|
|
235
|
+
catnos: (_21 = (_20 = (_19 = (_18 = (_17 = el.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 : [],
|
|
236
|
+
imageUrl: (_23 = (_22 = el.querySelector('.marketplace_image')) === null || _22 === void 0 ? void 0 : _22.getAttribute('data-src')) !== null && _23 !== void 0 ? _23 : '',
|
|
237
|
+
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 : '',
|
|
238
|
+
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,
|
|
239
|
+
isAvailable: !((_33 = el.classList) === null || _33 === void 0 ? void 0 : _33.contains('unavailable')),
|
|
244
240
|
condition: {
|
|
245
241
|
media: {
|
|
246
|
-
full: (
|
|
247
|
-
short: (
|
|
242
|
+
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 : '',
|
|
243
|
+
short: (_43 = (_42 = (_41 = (_40 = (_39 = (_38 = el.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 : '',
|
|
248
244
|
},
|
|
249
245
|
sleeve: {
|
|
250
|
-
full: (
|
|
251
|
-
short: (
|
|
252
|
-
}
|
|
246
|
+
full: (_45 = (_44 = el.querySelector('.item_condition span.item_sleeve_condition')) === null || _44 === void 0 ? void 0 : _44.textContent) !== null && _45 !== void 0 ? _45 : '',
|
|
247
|
+
short: (_49 = (_48 = (_47 = (_46 = el.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 : '',
|
|
248
|
+
},
|
|
253
249
|
},
|
|
254
250
|
seller: {
|
|
255
|
-
name: (
|
|
256
|
-
|
|
257
|
-
|
|
251
|
+
name: (_51 = (_50 = el.querySelector('.seller_info a')) === null || _50 === void 0 ? void 0 : _50.textContent) !== null && _51 !== void 0 ? _51 : '',
|
|
252
|
+
url: `https://www.discogs.com${(_52 = el.querySelector('.seller_info a')) === null || _52 === void 0 ? void 0 : _52.href}`,
|
|
253
|
+
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 : '',
|
|
254
|
+
notes: Number.isNaN(notes) ? 0 : notes,
|
|
258
255
|
},
|
|
259
256
|
price: {
|
|
260
|
-
base: this.convertDevise((
|
|
261
|
-
shipping: isNaN(parseFloat(shipping)) ? null : shipping,
|
|
257
|
+
base: this.convertDevise((_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 : ''),
|
|
258
|
+
shipping: Number.isNaN(parseFloat(shipping)) ? null : shipping,
|
|
262
259
|
},
|
|
263
260
|
from: {
|
|
264
|
-
countryName
|
|
265
|
-
isoCountryName: (
|
|
266
|
-
|
|
261
|
+
countryName,
|
|
262
|
+
isoCountryName: (_59 = ECountryName_1.default[isoCountryCode]) !== null && _59 !== void 0 ? _59 : '',
|
|
263
|
+
isoCountryCode,
|
|
267
264
|
},
|
|
268
265
|
community: {
|
|
269
|
-
have: isNaN(have) ? 0 : have,
|
|
270
|
-
want: isNaN(want) ? 0 : want
|
|
266
|
+
have: Number.isNaN(have) ? 0 : have,
|
|
267
|
+
want: Number.isNaN(want) ? 0 : want,
|
|
268
|
+
},
|
|
269
|
+
release: {
|
|
270
|
+
id: Number.isNaN(releaseId) ? 0 : releaseId,
|
|
271
|
+
url: `https://www.discogs.com${(_60 = el.querySelector('a.item_release_link')) === null || _60 === void 0 ? void 0 : _60.href}`,
|
|
271
272
|
},
|
|
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
273
|
};
|
|
275
274
|
})) || [],
|
|
276
275
|
page: {
|
|
277
276
|
current: this.page,
|
|
278
|
-
total: Math.ceil(totalItems / this.limit)
|
|
277
|
+
total: Math.ceil(totalItems / this.limit),
|
|
279
278
|
},
|
|
280
|
-
|
|
279
|
+
result: {
|
|
281
280
|
total: totalItems,
|
|
282
281
|
perPage: this.limit,
|
|
283
282
|
},
|
|
284
283
|
search: {
|
|
285
|
-
value: this.searchValue,
|
|
286
|
-
type: this.searchType
|
|
284
|
+
value: (_f = this.searchValue) !== null && _f !== void 0 ? _f : '',
|
|
285
|
+
type: this.searchType,
|
|
287
286
|
},
|
|
288
|
-
urlGenerated: this.url
|
|
287
|
+
urlGenerated: this.url,
|
|
289
288
|
};
|
|
290
289
|
}
|
|
291
290
|
}
|
package/dist/type/TLimit.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "discogs-marketplace-api-nodejs",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
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 ./
|
|
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
|
-
"
|
|
28
|
-
"playwright-chromium": "^1.
|
|
29
|
-
"ts-node": "^10.
|
|
30
|
-
"tsconfig-paths": "^3.
|
|
31
|
-
"user-agents": "^1.0.
|
|
29
|
+
"linkedom": "^0.13.0",
|
|
30
|
+
"playwright-chromium": "^1.17.1",
|
|
31
|
+
"ts-node": "^10.4.0",
|
|
32
|
+
"tsconfig-paths": "^3.12.0",
|
|
33
|
+
"user-agents": "^1.0.889"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
|
-
"@types/jest": "^27.0
|
|
35
|
-
"@types/
|
|
36
|
-
"@types/node": "^16.10.2",
|
|
36
|
+
"@types/jest": "^27.4.0",
|
|
37
|
+
"@types/node": "^17.0.8",
|
|
37
38
|
"@types/puppeteer": "^5.4.4",
|
|
38
39
|
"@types/user-agents": "^1.0.2",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^5.9.0",
|
|
41
|
+
"@typescript-eslint/parser": "^5.9.0",
|
|
42
|
+
"eslint": "^8.6.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.2",
|
|
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
|
-
```
|
package/tsconfig.build.json
DELETED
|
@@ -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
|
-
}
|