discogs-marketplace-api-nodejs 1.14.2 → 1.14.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/dist/interfaces/api/shop-details-result.api.interface.d.ts +17 -0
- package/dist/interfaces/api/shop-result-error.api.interface.d.ts +8 -0
- package/dist/interfaces/api/shop-result-error.api.interface.js +2 -0
- package/dist/interfaces/search-params.interface.d.ts +1 -0
- package/dist/scrapers/modern.scraper.js +17 -9
- package/package.json +1 -1
|
@@ -28,6 +28,23 @@ export default interface ShopDetailsResultApi {
|
|
|
28
28
|
};
|
|
29
29
|
/** DiscogsId */
|
|
30
30
|
discogsId?: number;
|
|
31
|
+
} | null>;
|
|
32
|
+
};
|
|
33
|
+
/** Errors */
|
|
34
|
+
errors?: Array<{
|
|
35
|
+
/** Message */
|
|
36
|
+
message?: string;
|
|
37
|
+
/** Path */
|
|
38
|
+
path?: [string, number];
|
|
39
|
+
}>;
|
|
40
|
+
/** Extensions */
|
|
41
|
+
extensions?: {
|
|
42
|
+
/** ValueCompletion */
|
|
43
|
+
valueCompletion?: Array<{
|
|
44
|
+
/** Message */
|
|
45
|
+
message?: string;
|
|
46
|
+
/** Path */
|
|
47
|
+
path?: [string, number];
|
|
31
48
|
}>;
|
|
32
49
|
};
|
|
33
50
|
}
|
|
@@ -164,6 +164,7 @@ interface SearchParamsModernBase extends SearchParamsBase {
|
|
|
164
164
|
sort?: Exclude<Sort, 'label,asc' | 'label,desc'>;
|
|
165
165
|
/**
|
|
166
166
|
* Number of results to return per page.
|
|
167
|
+
* It must be less than or equal to 250.
|
|
167
168
|
* @default 25
|
|
168
169
|
*/
|
|
169
170
|
limit?: number;
|
|
@@ -71,7 +71,10 @@ async function scrape({ currencies, genres, formats, formatDescriptions, conditi
|
|
|
71
71
|
referrer: 'https://discogs.com',
|
|
72
72
|
});
|
|
73
73
|
if (!response.ok) {
|
|
74
|
-
|
|
74
|
+
const message = response.headers.get('Content-Type')?.includes('application/json')
|
|
75
|
+
? (await response.json()).detail
|
|
76
|
+
: '';
|
|
77
|
+
throw new Error(message || response.statusText || `An error ${response.status} occurred.`);
|
|
75
78
|
}
|
|
76
79
|
const result = (await response.json());
|
|
77
80
|
const detailsResponse = await globalThis.fetch('https://www.discogs.com/graphql', {
|
|
@@ -100,14 +103,19 @@ async function scrape({ currencies, genres, formats, formatDescriptions, conditi
|
|
|
100
103
|
throw new Error(detailsResponse.statusText || `An error ${detailsResponse.status} occurred.`);
|
|
101
104
|
}
|
|
102
105
|
const detailsResult = (await detailsResponse.json());
|
|
103
|
-
const details = Object.fromEntries(detailsResult.data?.releases?.map(release =>
|
|
104
|
-
release
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
const details = Object.fromEntries(detailsResult.data?.releases?.map(release => {
|
|
107
|
+
if (!release?.discogsId) {
|
|
108
|
+
return [0, { imageUrl: null, want: 0, have: 0 }];
|
|
109
|
+
}
|
|
110
|
+
return [
|
|
111
|
+
release.discogsId ?? 0,
|
|
112
|
+
{
|
|
113
|
+
imageUrl: release.images?.edges?.[0]?.node?.thumbnail?.webpUrl ?? null,
|
|
114
|
+
want: release.inWantlistCount ?? 0,
|
|
115
|
+
have: release.inCollectionCount ?? 0,
|
|
116
|
+
},
|
|
117
|
+
];
|
|
118
|
+
}) ?? []);
|
|
111
119
|
const items = result.items?.map(item => {
|
|
112
120
|
const detail = details[item.release?.releaseId ?? 0];
|
|
113
121
|
return {
|