discogs-marketplace-api-nodejs 1.16.3 → 1.16.5

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.
@@ -64,6 +64,10 @@ async function scrape({ currencies, genres, formats, formatDescriptions, conditi
64
64
  ].filter(([, p]) => !!p)).toString(),
65
65
  ].join('?');
66
66
  const browserPage = await browserContext.newPage();
67
+ await browserPage.setExtraHTTPHeaders({
68
+ 'User-Agent': 'Discogs',
69
+ 'Content-Type': 'application/json',
70
+ });
67
71
  const response = await browserPage.goto(urlGenerated);
68
72
  if (!response?.ok()) {
69
73
  const message = response?.headers()['content-type']?.includes('application/json')
@@ -73,30 +77,32 @@ async function scrape({ currencies, genres, formats, formatDescriptions, conditi
73
77
  throw new Error(message || `An error ${response?.status() ?? '?'} occurred.`);
74
78
  }
75
79
  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,
80
+ const { json: detailsResult, ...detailsResponse } = await browserPage.evaluate(async (discogsIds = [0]) => {
81
+ const res = await fetch('https://www.discogs.com/graphql', {
82
+ method: 'POST',
83
+ headers: {
84
+ 'User-Agent': 'Discogs',
85
+ 'Content-Type': 'application/json',
87
86
  },
88
- extensions: {
89
- persistedQuery: {
90
- version: 1,
91
- sha256Hash: 'ee9d48441023ebd1e6ca169e550581b45de216e88b40711acb6617e49e1bb0cb',
87
+ body: JSON.stringify({
88
+ // eslint-disable-next-line max-len
89
+ 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}',
90
+ variables: { discogsIds, first: 1 },
91
+ extensions: {
92
+ persistedQuery: { version: 1, sha256Hash: 'ee9d48441023ebd1e6ca169e550581b45de216e88b40711acb6617e49e1bb0cb' },
92
93
  },
93
- },
94
- },
95
- });
96
- if (!detailsResponse.ok()) {
97
- throw new Error(`An error ${detailsResponse.status()} occurred.`);
94
+ }),
95
+ });
96
+ return {
97
+ ok: res.ok,
98
+ status: res.status,
99
+ json: (await res.json().catch(() => ({}))),
100
+ };
101
+ }, result.items?.map(z => z.release?.releaseId ?? 0).filter((x, i, self) => x && self.indexOf(x) === i));
102
+ await browserPage.close();
103
+ if (!detailsResponse.ok) {
104
+ throw new Error(`An error ${detailsResponse.status} occurred.`);
98
105
  }
99
- const detailsResult = (await detailsResponse.json());
100
106
  const details = Object.fromEntries(detailsResult.data?.releases?.map(release => {
101
107
  if (!release?.discogsId) {
102
108
  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.5",
4
4
  "description": "Another (better ?) NodeJs library to fetch data from Discogs marketplace",
5
5
  "keywords": [
6
6
  "discogs",