Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove node-fetch #11266

Draft
wants to merge 116 commits into
base: latest
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 113 commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
52d649d
Revert "Revert "Remove `node-fetch` (#11122)" (#11261)"
amoore108 Jan 8, 2024
da3236e
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Jan 16, 2024
c32be71
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Jan 22, 2024
3594fc5
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Jan 25, 2024
10a7403
Update [[...variant]].page.tsx
amoore108 Jan 26, 2024
a6f0cc1
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 5, 2024
49d0260
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 8, 2024
0c13a0a
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 8, 2024
67bd3f0
Remove node-fetch references
amoore108 Feb 9, 2024
ec0b2d1
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 9, 2024
ebd3521
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 12, 2024
8b97775
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 13, 2024
d46fe8e
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 14, 2024
8cc9287
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 14, 2024
edb6f2e
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 16, 2024
8785176
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 19, 2024
b1c41fe
Update package.json
amoore108 Feb 19, 2024
189164e
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 20, 2024
6e3527f
Add cert checks to `fetchDataFromBFF`
amoore108 Feb 20, 2024
19988b2
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 21, 2024
8a3decf
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 22, 2024
8d46d8e
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 22, 2024
b2f8b76
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 27, 2024
af1c666
Update bundleSizeConfig.js
amoore108 Feb 27, 2024
e14db9c
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 28, 2024
3cf656f
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 28, 2024
c4e133f
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Feb 29, 2024
9eab5a0
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 4, 2024
4c144de
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 5, 2024
295ab8c
Update bundleSizeConfig.js
amoore108 Mar 5, 2024
466cb99
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 5, 2024
2951575
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 6, 2024
48f53cb
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 6, 2024
b22a7c3
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 7, 2024
6495536
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 7, 2024
b30b6ca
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 11, 2024
d711a54
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 13, 2024
8a6340d
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 14, 2024
feb5628
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 19, 2024
1608fff
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 19, 2024
7361e8d
Update bundleSizeConfig.js
amoore108 Mar 19, 2024
d9fb466
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 20, 2024
5c92513
Update package.json
amoore108 Mar 20, 2024
33d8241
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 20, 2024
1e03e53
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 22, 2024
5c37b37
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 25, 2024
c26878d
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 26, 2024
345f08d
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 26, 2024
773c003
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Mar 27, 2024
b4e60a9
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 2, 2024
fd92cbd
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 3, 2024
91053d4
update
amoore108 Apr 3, 2024
4ff92d6
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 3, 2024
89f2fcf
yarn
amoore108 Apr 3, 2024
7176a51
yarn fix
amoore108 Apr 3, 2024
78b46d4
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 4, 2024
1f26537
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 4, 2024
114b6ce
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 4, 2024
2169521
Update getPageData.test.ts
amoore108 Apr 4, 2024
c3b2bc9
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 4, 2024
8aba21f
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 4, 2024
3263d76
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 4, 2024
d18531e
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 4, 2024
0cd77c1
undici update
amoore108 Apr 4, 2024
6ec646e
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 5, 2024
13fe2ad
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 5, 2024
efdb4b6
cache
amoore108 Apr 5, 2024
4bf7b30
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 8, 2024
f43ca23
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 9, 2024
ebd824c
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 9, 2024
27548d5
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 9, 2024
563c7e6
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 10, 2024
b5b6a7d
cache
amoore108 Apr 10, 2024
4973117
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 10, 2024
ec50aa9
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 11, 2024
53b6c65
cache
amoore108 Apr 11, 2024
e659300
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 12, 2024
342af42
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 12, 2024
b8bb138
cache
amoore108 Apr 12, 2024
4a13fb1
Update bundleSizeConfig.js
amoore108 Apr 12, 2024
94ea74d
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 18, 2024
112de65
cache
amoore108 Apr 18, 2024
373639e
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 22, 2024
f168a45
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 24, 2024
43319c5
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 25, 2024
3580d84
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Apr 30, 2024
49521bf
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 May 7, 2024
f4b4619
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 May 8, 2024
dceb280
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 May 10, 2024
c9544e6
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 May 13, 2024
1c1c955
yarn cache updates
amoore108 May 13, 2024
904d31a
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 May 14, 2024
181fd90
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 May 14, 2024
5b85963
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 May 16, 2024
bbc74d9
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 May 21, 2024
41fda0d
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 May 23, 2024
09b2c6b
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 May 23, 2024
2821825
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 May 23, 2024
7bbce64
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 May 29, 2024
0268e49
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 May 29, 2024
538f3a8
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Jun 3, 2024
a263448
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Jun 11, 2024
1049f29
Create undici-npm-6.11.1-7a6c072033-1294806846.zip
amoore108 Jun 11, 2024
fe3bcdd
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Jun 13, 2024
ec88769
cache
amoore108 Jun 13, 2024
abd6f78
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Jun 13, 2024
0bb332e
Create undici-npm-6.18.2-c1115b72ab-27c66d84d0.zip
amoore108 Jun 13, 2024
c246889
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Jun 14, 2024
3cfd585
Update undici
amoore108 Jun 14, 2024
9ba5269
Consolidate Nextjs pages fetch
amoore108 Jun 14, 2024
bb31d44
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Jun 19, 2024
84366cb
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Jun 20, 2024
b7d3587
Update bundleSizeConfig.js
amoore108 Jun 21, 2024
0da0da7
Remove `JEST_WORKER_ID` checks
amoore108 Jun 21, 2024
b592b6c
Keep BFF path check
amoore108 Jun 21, 2024
8764ab3
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
amoore108 Jun 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
"cypress:adhoc": "yarn cypress:interactive -- --project ./AdHocCypress/.",
"setupDevEnv": "cp envConfig/local.env .env && rm -rf envConfig/secret.env && ./scripts/checkSecretEnvVariables.sh",
"dependencyFreshness": "node ./scripts/dependencyFreshness",
"dev": "yarn setupDevEnv && rm -rf build && run-p webpack:dev:client webpack:dev:server",
"esmDependencyCheck": "node ./scripts/esmDependencyCheck.js",
"dev": "yarn setupDevEnv && rm -rf build && NODE_OPTIONS=--no-experimental-fetch run-p webpack:dev:client webpack:dev:server",
"lighthouse": "./scripts/lighthouseRun.sh",
"mostReadAndWatchedCollectionData": "node ./scripts/mostReadAndWatchedCollectionData",
"postshrinkwrap": "test -z $CI && ./scripts/packagelockHttps.sh; git update-index --assume-unchanged .env",
"prepare": "husky install",
"preinstall": "node scripts/check-package-manager.js",
"start": "NODE_ENV=production node --no-experimental-fetch --max-old-space-size=3500 build/server.js",
"start": "NODE_ENV=production node --max-old-space-size=3500 build/server.js",
"stop": "./scripts/killApp.sh",
"storybook": "node .storybook/buildFontPreloads && storybook dev -p 9001 -c .storybook",
"test": "yarn build && yarn test:local",
Expand Down Expand Up @@ -110,7 +110,6 @@
"helmet": "7.1.0",
"helmet-csp": "3.4.0",
"intersection-observer": "0.12.2",
"isomorphic-fetch": "3.0.0",
"jalaali-js": "1.2.6",
"js-cookie": "3.0.5",
"lru-cache": "7.7.1",
Expand All @@ -126,6 +125,7 @@
"react-lazyload": "3.2.1",
"react-router-config": "5.1.1",
"react-router-dom": "5.3.4",
"undici": "6.19.0",
"url-parse": "1.5.10",
"uuid": "8.3.2",
"winston": "patch:winston@3.8.2#./patches/winston-file-descriptor.patch",
Expand Down Expand Up @@ -179,7 +179,6 @@
"@types/js-cookie": "^3.0.3",
"@types/jsdom": "^21.0.0",
"@types/loadable__component": "5.13.9",
"@types/node-fetch": "^2.6.11",
"@types/ramda": "0.28.15",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
Expand Down Expand Up @@ -235,7 +234,6 @@
"mkdirp": "3.0.1",
"mocha": "10.4.0",
"mocha-junit-reporter": "2.2.1",
"node-fetch": "2.6.12",
"npm-run-all2": "6.2.0",
"prettier": "3.2.5",
"retry": "0.13.1",
Expand Down
1 change: 0 additions & 1 deletion scripts/ampHtmlValidator/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable no-console */
const fetch = require('isomorphic-fetch');
const amphtmlValidator = require('amphtml-validator');
const { getPageUrls } = require('../../cypress/support/helpers/getPageUrls');

Expand Down
3 changes: 0 additions & 3 deletions scripts/ampHtmlValidator/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const fetch = require('isomorphic-fetch');

jest.mock('isomorphic-fetch');
fetch.mockImplementation(() => ({ text: () => '<html amp></html>' }));
const log = jest.spyOn(global.console, 'log');
log.mockImplementation(jest.fn);
Expand Down
4 changes: 2 additions & 2 deletions scripts/bundleSize/bundleSizeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
* We are allowing a variance of -5 on `MIN_SIZE` and +5 on `MAX_SIZE` to avoid the need for frequent changes, as bundle sizes can fluctuate
*/

export const MIN_SIZE = 634 - 5;
export const MAX_SIZE = 1093 + 5;
export const MIN_SIZE = 635 - 5;
export const MAX_SIZE = 1079 + 5;
1 change: 0 additions & 1 deletion scripts/dependencyFreshness.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-console */
const { exec } = require('child_process');
const fs = require('fs');
const fetch = require('node-fetch');
const { dependencies, devDependencies } = require('../package.json');

const allDependencies = { ...dependencies, ...devDependencies };
Expand Down
2 changes: 0 additions & 2 deletions scripts/linkeyTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fetch from 'node-fetch';

/* eslint-disable no-undef */
const getServiceName = serviceConfig => {
if (serviceConfig.default) {
Expand Down
59 changes: 39 additions & 20 deletions scripts/mostReadAndWatchedCollectionData.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const { Agent } = require('https');
const fetch = require('node-fetch');
const fsPromises = require('fs/promises');
const { Agent } = require('undici');
const { createSecureContext } = require('tls');
const allServices = require('../cypress/support/config/settings')();

const badServices = [
Expand All @@ -19,18 +20,37 @@ const services = Object.keys(allServices);

console.log('services', services);

const loadCerts = ({ caPath, certChainPath, keyPath }) =>
Promise.all([
fsPromises.readFile(caPath, 'UTF-8'),
fsPromises.readFile(certChainPath, 'UTF-8'),
fsPromises.readFile(keyPath, 'UTF-8'),
]);

const fetchWithCert = async (url, options) => {
const cert = fs.readFileSync(
process.env.CERT_CHAIN_PATH || '/etc/pki/tls/certs/client.crt',
);
const ca = fs.readFileSync(
process.env.CA_PATH || '/etc/pki/tls/certs/ca-bundle.crt',
);
const key = fs.readFileSync(
process.env.KEY_PATH || '/etc/pki/tls/private/client.key',
);
const agent = new Agent({ cert, ca, key });
return fetch(url, { agent, ...options });
const caPath = process.env.CA_PATH || '/etc/pki/tls/certs/ca-bundle.crt';
const certChainPath =
process.env.CERT_CHAIN_PATH || '/etc/pki/tls/certs/client.crt';
const keyPath = process.env.KEY_PATH || '/etc/pki/tls/private/client.key';

const [ca, certChain, key] = await loadCerts({
caPath,
certChainPath,
keyPath,
});

return fetch(url, {
dispatcher: new Agent({
connect: {
secureContext: createSecureContext({
cert: certChain,
key,
ca,
}),
},
}),
...options,
});
};

const timeTable = [];
Expand All @@ -41,9 +61,9 @@ const collectResults = async (link, service, type) => {
await fetchWithCert(link).then(response => {
if (response.ok) {
response.json().then(json => {
const jsondata = json.hasOwnProperty('data') ? json.data : json;
if (!(json.hasOwnProperty('status') && json.status === '404')) {
if (!jsondata || !jsondata.hasOwnProperty('generated')) {
const jsondata = 'data' in json ? json.data : json;
if (!('status' in json && json.status === '404')) {
if (!jsondata || !('generated' in jsondata)) {
console.log('json where no data', jsondata);
}
const generatedDateTime = new Date(jsondata.generated);
Expand All @@ -52,9 +72,8 @@ const collectResults = async (link, service, type) => {
const minutesSinceGenerated = Math.floor(
timeDifference / (1000 * 60),
);
const records = jsondata.hasOwnProperty('items')
? jsondata.items
: jsondata.records;
const records =
'items' in jsondata ? jsondata.items : jsondata.records;
const counts = records
.map(record => record.count)
.slice(0, 10)
Expand Down Expand Up @@ -97,7 +116,7 @@ const collectResults = async (link, service, type) => {

services
.filter(service => !badServices.includes(service))
.forEach((service, i) => {
.forEach(service => {
let serviceToCall = service;
if (servicesWithVariants.some(variant => service.includes(variant))) {
serviceToCall = service.replace(/([A-Z])/, '_$1').toLowerCase();
Expand Down
74 changes: 47 additions & 27 deletions scripts/mostReadCollectionTimes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const { Agent } = require('https');
const fetch = require('node-fetch');
const fsPromises = require('fs/promises');
const { Agent } = require('undici');
const { createSecureContext } = require('tls');
const allServices = require('../cypress/support/config/settings')();

const badServices = [
Expand All @@ -19,20 +20,38 @@ const services = Object.keys(allServices);

console.log('services', services);

const loadCerts = ({ caPath, certChainPath, keyPath }) =>
Promise.all([
fsPromises.readFile(caPath, 'UTF-8'),
fsPromises.readFile(certChainPath, 'UTF-8'),
fsPromises.readFile(keyPath, 'UTF-8'),
]);

const fetchWithCert = async (url, options) => {
const cert = fs.readFileSync(
process.env.CERT_CHAIN_PATH || '/etc/pki/tls/certs/client.crt',
);
const ca = fs.readFileSync(
process.env.CA_PATH || '/etc/pki/tls/certs/ca-bundle.crt',
);
const key = fs.readFileSync(
process.env.KEY_PATH || '/etc/pki/tls/private/client.key',
);
const agent = new Agent({ cert, ca, key });
return fetch(url, { agent, ...options });
};
const caPath = process.env.CA_PATH || '/etc/pki/tls/certs/ca-bundle.crt';
const certChainPath =
process.env.CERT_CHAIN_PATH || '/etc/pki/tls/certs/client.crt';
const keyPath = process.env.KEY_PATH || '/etc/pki/tls/private/client.key';

const [ca, certChain, key] = await loadCerts({
caPath,
certChainPath,
keyPath,
});

return fetch(url, {
dispatcher: new Agent({
connect: {
secureContext: createSecureContext({
cert: certChain,
key,
ca,
}),
},
}),
...options,
});
};
const timeTable = [];

let csvContents;
Expand All @@ -41,9 +60,9 @@ const collectResults = async (link, service, type) => {
await fetchWithCert(link).then(response => {
if (response.ok) {
response.json().then(json => {
const jsondata = json.hasOwnProperty('data') ? json.data : json;
if (!(json.hasOwnProperty('status') && json.status === '404')) {
if (!jsondata || !jsondata.hasOwnProperty('generated')) {
const jsondata = 'data' in json ? json.data : json;
if (!('status' in json && json.status === '404')) {
if (!jsondata || !('generated' in jsondata)) {
console.log('json where no data', jsondata);
}
const generatedDateTime = new Date(jsondata.generated);
Expand All @@ -52,9 +71,8 @@ const collectResults = async (link, service, type) => {
const minutesSinceGenerated = Math.floor(
timeDifference / (1000 * 60),
);
const records = jsondata.hasOwnProperty('items')
? jsondata.items
: jsondata.records;
const records =
'items' in jsondata ? jsondata.items : jsondata.records;
const counts = records
.map(record => record.count)
.slice(0, 10)
Expand All @@ -81,21 +99,23 @@ const collectResults = async (link, service, type) => {
if (timeTable.length === (services.length - badServices.length) * 2) {
csvContents =
'service, type, link, generated, timeSinceGenerated, lastRecordTimeStamp, firstRecordTimeStamp, sequence, totalRecords, rank1, rank2, rank3, rank4, rank5, rank6, rank7, rank8, rank9, rank10';
timeTable.sort((a, b) => {
timeTable
.sort((a, b) => {
if (a.service > b.service) {
return 1;
}
else if (a.service < b.service) {
if (a.service < b.service) {
return -1;
}
else if (a.type < b.type) {
if (a.type < b.type) {
return -1;
}
else if (a.type > b.type) {
if (a.type > b.type) {
return 1;
}
return 0;
}).forEach(result => {
})
.forEach(result => {
csvContents += `\n${result.service},${result.type},${result.link},${result.generated},${result.minutesSinceGenerated},${result.lastRecordTimestamp},${result.firstRecordTimestamp},${result.sequence},${result.totalRecords},${result.counts}`;
});
fs.writeFileSync('./mostReadCollectionTimes.csv', csvContents);
Expand All @@ -111,7 +131,7 @@ const collectResults = async (link, service, type) => {

services
.filter(service => !badServices.includes(service))
.forEach((service, i) => {
.forEach(service => {
let serviceToCall = service;
if (servicesWithVariants.some(variant => service.includes(variant))) {
serviceToCall = service.replace(/([A-Z])/, '_$1').toLowerCase();
Expand Down Expand Up @@ -139,4 +159,4 @@ const collectResults = async (link, service, type) => {
});

await Promise.all(promises);
})();
})();
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'isomorphic-fetch';
import path from 'ramda/src/path';

import getCookieOvenEndpoints from './getCookieOvenEndpoints';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState, useContext } from 'react';
import { useTheme } from '@emotion/react';
import 'isomorphic-fetch';
import styled from '@emotion/styled';
import moment from 'moment';
import {
Expand Down
1 change: 0 additions & 1 deletion src/app/lib/analyticsUtils/sendBeacon/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import onClient from '../../utilities/onClient';
import nodeLogger from '../../logger.node';
import { ATI_LOGGING_ERROR } from '../../logger.const';
import 'isomorphic-fetch';

const logger = nodeLogger(__filename);

Expand Down
4 changes: 4 additions & 0 deletions src/app/models/types/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { Agent } from 'undici';

export interface FetchError extends Error {
status: number;
}

export type GetAgent = () => Promise<Agent>;
3 changes: 2 additions & 1 deletion src/app/models/types/pageDataParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ParsedUrlQuery } from 'querystring';
import { Services, Variants } from './global';
import { PageTypes, Services, Variants } from './global';

export default interface PageDataParams extends ParsedUrlQuery {
id: string;
Expand All @@ -9,4 +9,5 @@ export default interface PageDataParams extends ParsedUrlQuery {
// eslint-disable-next-line camelcase
renderer_env?: string;
resolvedUrl: string;
pageType: PageTypes;
}
3 changes: 1 addition & 2 deletions src/app/pages/HomePage/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import React, { useEffect, useState } from 'react';
import Url from 'url-parse';
import { HOME_PAGE } from '#app/routes/utils/pageTypes';
import fetch from 'node-fetch';
import { Curation } from '#app/models/types/curationData';
import { Services } from '#app/models/types/global';
import withServicesDecorator from '#storybook/withServicesDecorator';
Expand Down Expand Up @@ -44,7 +43,7 @@ const Component = ({ service, variant }: StoryProps) => {
useEffect(() => {
const loadPageData = async () => {
const response = await fetch(
new Url(`data/${service}/homePage/index.json`),
new Url(`data/${service}/homePage/index.json`).toString(),
);
const { data } = await response.json();

Expand Down
1 change: 0 additions & 1 deletion src/app/pages/MostReadPage/index.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useState } from 'react';
import fetch from 'node-fetch';
import Url from 'url-parse';
import { BrowserRouter } from 'react-router-dom';
import { MOST_READ_PAGE } from '#app/routes/utils/pageTypes';
Expand Down
Loading
Loading