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 Axios #2006

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from
Open

Remove Axios #2006

wants to merge 22 commits into from

Conversation

addy-pathania
Copy link
Contributor

@addy-pathania addy-pathania commented Jan 8, 2025

Description / Motivation

This change is motivated by the security vulnerabilities found with the Axios library. This PR removes the default use of Axios for data fetching across the monorepo and transitions to the native fetch API.

Testing Details

  • Unit Test Added
  • Manual Test/Other (Please elaborate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@addy-pathania addy-pathania requested a review from a team January 8, 2025 14:12
Copy link
Contributor

@art-alexeyenko art-alexeyenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work. Also a good catch that Native fetcher needs some extra unit tests.
Still, some things I'd like you to take a look at and adjust. Please check the comments.

@@ -47,15 +47,14 @@
"eslint": "^8.56.0",
"eslint-plugin-jsdoc": "48.7.0",
"mocha": "^10.2.0",
"nock": "^13.0.5",
"nock": "14.0.0-beta.7",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to comment on why this specific version is used, for history.
Using beta version to fix this issue: nock/nock#2397 and allow testing for component library service
Using specific beta.7 version to not encounter this error: nock/nock#2789

packages/sitecore-jss/src/data-fetcher.ts Show resolved Hide resolved
packages/sitecore-jss/src/data-fetcher.ts Show resolved Hide resolved
packages/sitecore-jss/src/native-fetcher.test.ts Outdated Show resolved Hide resolved
packages/sitecore-jss/src/native-fetcher.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@illiakovalenko illiakovalenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good! See some questions/comments below
Applications are failing to build/start:

  1. Angular sxp
  2. Next.js styleguide application types check is failing
  3. Next.js xmcloud application types check is failing

CHANGELOG.md Outdated
@@ -22,6 +22,8 @@ Our versioning strategy is as follows:
### 🐛 Bug Fixes

* `[sitecore-jss-nextjs]` Fixed handling of ? inside square brackets [] in regex patterns to prevent incorrect escaping ([#1999](https://github.com/Sitecore/jss/pull/1999))
* `[sitecore-jss]``[create-sitecore-jss]``[sitecore-jss-nextjs]``[sitecore-jss-react]``[sitecore-jss-dev-tools]``[sitecore-jss-vue]` Remove Axios ([#2006](https://github.com/Sitecore/jss/pull/2006))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chengelog entry should mention all the removed and replaced API references. However, more details should be mentioned in upgrade guide
Also, it's a breaking change, not a bugfix

Copy link
Contributor

@illiakovalenko illiakovalenko Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addy-pathania Changelog is unchanged

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aah i forgot push my last commit.

packages/sitecore-jss/src/native-fetcher.ts Outdated Show resolved Hide resolved
packages/sitecore-jss/src/native-fetcher.ts Outdated Show resolved Hide resolved
packages/sitecore-jss/src/native-fetcher.ts Show resolved Hide resolved
packages/sitecore-jss/src/native-fetcher.ts Outdated Show resolved Hide resolved
packages/sitecore-jss/src/native-fetcher.ts Outdated Show resolved Hide resolved
expect(layoutServiceData.headers['X-Forwarded-For']).to.equal('192.168.1.10');
expect(layoutServiceData.data).to.deep.equal({
.then((layoutServiceData: LayoutServiceData & NativeDataFetcherConfig) => {
if (layoutServiceData.headers instanceof Headers) {
Copy link
Contributor

@illiakovalenko illiakovalenko Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

layoutServiceData can't contain headers, so you are not verifying headers anymore
check rest of unit tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addy-pathania we are still missing headers configuration and verification in unit tests

.reply(200, (_, requestBody) => ({
requestBody: requestBody,
data: { sitecore: { context: {}, route: { name: 'xxx' } } },
headers: {
Copy link
Contributor

@illiakovalenko illiakovalenko Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not testing response headers anymore, check rest of unit tests as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addy-pathania we are still missing headers configuration and verification in unit tests

packages/sitecore-jss/src/layout/rest-layout-service.ts Outdated Show resolved Hide resolved
packages/sitecore-jss/src/layout/rest-layout-service.ts Outdated Show resolved Hide resolved
packages/sitecore-jss-dev-tools/src/package-deploy.ts Outdated Show resolved Hide resolved
packages/sitecore-jss-dev-tools/src/package-deploy.ts Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
.reply(200, (_, requestBody) => ({
requestBody: requestBody,
data: { sitecore: { context: {}, route: { name: 'xxx' } } },
headers: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addy-pathania we are still missing headers configuration and verification in unit tests

Copy link
Contributor

@illiakovalenko illiakovalenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, it's close to be finished!
See one re-opened comment above, related to "headers" test, still missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants