discogs-marketplace-api-nodejs 1.16.3 → 1.16.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.
@@ -73,30 +73,32 @@ async function scrape({ currencies, genres, formats, formatDescriptions, conditi
73
73
  throw new Error(message || `An error ${response?.status() ?? '?'} occurred.`);
74
74
  }
75
75
  const result = (await response.json());
76
- const detailsResponse = await browserContext.request.post('https://www.discogs.com/graphql', {
77
- headers: {
78
- 'User-Agent': 'Discogs',
79
- 'Content-Type': 'application/json',
80
- },
81
- data: {
82
- // eslint-disable-next-line max-len
83
- query: 'query Releases($discogsIds: [Int], $first: Int) {\n releases(discogsIds: $discogsIds) {\n inWantlistCount\n inCollectionCount\n images(first: $first) {\n edges {\n node {\n thumbnail {\n webpUrl\n }\n }\n }\n }\n ratings(first: 1) {\n averageRating\n }\n discogsId\n }\n}',
84
- variables: {
85
- discogsIds: result.items?.map(z => z.release?.releaseId ?? 0).filter((x, i, self) => x && self.indexOf(x) === i),
86
- first: 1,
76
+ const { json: detailsResult, ...detailsResponse } = await browserPage.evaluate(async (discogsIds) => {
77
+ const res = await fetch('https://www.discogs.com/graphql', {
78
+ method: 'POST',
79
+ headers: {
80
+ 'User-Agent': 'Discogs',
81
+ 'Content-Type': 'application/json',
87
82
  },
88
- extensions: {
89
- persistedQuery: {
90
- version: 1,
91
- sha256Hash: 'ee9d48441023ebd1e6ca169e550581b45de216e88b40711acb6617e49e1bb0cb',
83
+ body: JSON.stringify({
84
+ // eslint-disable-next-line max-len
85
+ query: 'query Releases($discogsIds: [Int], $first: Int) {\n releases(discogsIds: $discogsIds) {\n inWantlistCount\n inCollectionCount\n images(first: $first) {\n edges {\n node {\n thumbnail {\n webpUrl\n }\n }\n }\n }\n ratings(first: 1) {\n averageRating\n }\n discogsId\n }\n}',
86
+ variables: { discogsIds, first: 1 },
87
+ extensions: {
88
+ persistedQuery: { version: 1, sha256Hash: 'ee9d48441023ebd1e6ca169e550581b45de216e88b40711acb6617e49e1bb0cb' },
92
89
  },
93
- },
94
- },
95
- });
96
- if (!detailsResponse.ok()) {
97
- throw new Error(`An error ${detailsResponse.status()} occurred.`);
90
+ }),
91
+ });
92
+ return {
93
+ ok: res.ok,
94
+ status: res.status,
95
+ json: (await res.json().catch(() => ({}))),
96
+ };
97
+ }, result.items?.map(z => z.release?.releaseId ?? 0).filter((x, i, self) => x && self.indexOf(x) === i));
98
+ await browserPage.close();
99
+ if (!detailsResponse.ok) {
100
+ throw new Error(`An error ${detailsResponse.status} occurred.`);
98
101
  }
99
- const detailsResult = (await detailsResponse.json());
100
102
  const details = Object.fromEntries(detailsResult.data?.releases?.map(release => {
101
103
  if (!release?.discogsId) {
102
104
  return [0, { imageUrl: null, want: 0, have: 0 }];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discogs-marketplace-api-nodejs",
3
- "version": "1.16.3",
3
+ "version": "1.16.4",
4
4
  "description": "Another (better ?) NodeJs library to fetch data from Discogs marketplace",
5
5
  "keywords": [
6
6
  "discogs",