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

Revert "Remove node-fetch" #12093

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 removed .yarn/cache/fsevents-patch-6b67494872-10.zip
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: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,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 --max-old-space-size=3500 build/server.js",
"start": "NODE_ENV=production node --no-experimental-fetch --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 @@ -109,6 +109,7 @@
"helmet": "7.1.0",
"helmet-csp": "4.0.0",
"intersection-observer": "0.12.2",
"isomorphic-fetch": "3.0.0",
"jalaali-js": "1.2.7",
"js-cookie": "3.0.5",
"lru-cache": "11.0.1",
Expand All @@ -124,7 +125,6 @@
"react-lazyload": "3.2.1",
"react-router-config": "5.1.1",
"react-router-dom": "5.3.4",
"undici": "6.20.1",
"url-parse": "1.5.10",
"uuid": "8.3.2",
"winston": "patch:[email protected]#./patches/winston-file-descriptor.patch"
Expand Down Expand Up @@ -182,6 +182,7 @@
"@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.30.0",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.1",
Expand Down Expand Up @@ -234,6 +235,7 @@
"minimist": "1.2.8",
"mkdirp": "3.0.1",
"mocha-junit-reporter": "2.2.1",
"node-fetch": "2.6.12",
"npm-run-all2": "6.2.2",
"prettier": "3.2.5",
"retry": "0.13.1",
Expand Down
1 change: 1 addition & 0 deletions scripts/ampHtmlValidator/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* 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: 3 additions & 0 deletions scripts/ampHtmlValidator/index.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
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 = 635 - 5;
export const MAX_SIZE = 1175 + 5;
export const MIN_SIZE = 646 - 5;
export const MAX_SIZE = 1186 + 5;
1 change: 1 addition & 0 deletions scripts/dependencyFreshness.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* 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: 2 additions & 0 deletions scripts/linkeyTest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import fetch from 'node-fetch';

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

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

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

const badServices = [
Expand All @@ -20,38 +19,20 @@ 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 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 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 timeTable = [];

let csvContents;
Expand All @@ -60,9 +41,9 @@ const collectResults = async (link, service, type) => {
await fetchWithCert(link).then(response => {
if (response.ok) {
response.json().then(json => {
const jsondata = 'data' in json ? json.data : json;
if (!('status' in json && json.status === '404')) {
if (!jsondata || !('generated' in jsondata)) {
const jsondata = json.hasOwnProperty('data') ? json.data : json;
if (!(json.hasOwnProperty('status') && json.status === '404')) {
if (!jsondata || !jsondata.hasOwnProperty('generated')) {
console.log('json where no data', jsondata);
}
const generatedDateTime = new Date(jsondata.generated);
Expand All @@ -71,8 +52,9 @@ const collectResults = async (link, service, type) => {
const minutesSinceGenerated = Math.floor(
timeDifference / (1000 * 60),
);
const records =
'items' in jsondata ? jsondata.items : jsondata.records;
const records = jsondata.hasOwnProperty('items')
? jsondata.items
: jsondata.records;
const counts = records
.map(record => record.count)
.slice(0, 10)
Expand All @@ -99,23 +81,21 @@ 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;
}
if (a.service < b.service) {
else if (a.service < b.service) {
return -1;
}
if (a.type < b.type) {
else if (a.type < b.type) {
return -1;
}
if (a.type > b.type) {
else 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 @@ -131,7 +111,7 @@ const collectResults = async (link, service, type) => {

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

await Promise.all(promises);
})();
})();
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
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,5 +1,6 @@
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: 1 addition & 0 deletions src/app/lib/analyticsUtils/sendBeacon/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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: 0 additions & 4 deletions src/app/models/types/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { Agent } from 'undici';

export interface FetchError extends Error {
status: number;
}

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

export type InitialDataProps = {
Expand All @@ -7,5 +6,4 @@ export type InitialDataProps = {
pageType: PageTypes;
variant?: Variants;
toggles?: Toggles;
getAgent?: GetAgent;
};
3 changes: 1 addition & 2 deletions 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 { PageTypes, Services, Variants } from './global';
import { Services, Variants } from './global';

export default interface PageDataParams extends ParsedUrlQuery {
id: string;
Expand All @@ -9,5 +9,4 @@ export default interface PageDataParams extends ParsedUrlQuery {
// eslint-disable-next-line camelcase
renderer_env?: string;
resolvedUrl: string;
pageType: PageTypes;
}
3 changes: 2 additions & 1 deletion src/app/pages/HomePage/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
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 @@ -43,7 +44,7 @@ const Component = ({ service, variant }: StoryProps) => {
useEffect(() => {
const loadPageData = async () => {
const response = await fetch(
new Url(`data/${service}/homePage/index.json`).toString(),
new Url(`data/${service}/homePage/index.json`),
);
const { data } = await response.json();

Expand Down
1 change: 1 addition & 0 deletions src/app/pages/MostReadPage/index.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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