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

[2.x] chore: Replace isomorphic-unfetch with node-fetch #2566

Draft
wants to merge 4 commits into
base: 2.x
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@rollup/plugin-graphql": "^1.0.0",
"dataloader": "^2.1.0",
"fast-deep-equal": "^3.1.3",
"isomorphic-unfetch": "^3.1.0",
"node-fetch": "^2.7.0",
"p-limit": "^3.1.0",
"sanitize-html": "^2.11.0"
},
Expand All @@ -55,6 +55,7 @@
"@graphql-codegen/cli": "2.2.0",
"@graphql-codegen/typescript": "2.2.2",
"@types/express": "^4.17.16",
"@types/node-fetch": "^2.6.12",
"@types/sanitize-html": "^2.9.1",
"concurrently": "^6.2.1",
"copyfiles": "^2.4.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/platforms/vtex/clients/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fetch from 'isomorphic-unfetch'
import fetch, { RequestInfo, RequestInit, Headers } from 'node-fetch'
import packageJson from '../../../../package.json'

const USER_AGENT = `${packageJson.name}@${packageJson.version}`
Expand All @@ -7,7 +7,7 @@ interface FetchAPIOptions {
storeCookies?: (headers: Headers) => void
}

export const fetchAPI = async (
export const fetchAPI = async <T>(
info: RequestInfo,
init?: RequestInit,
options?: FetchAPIOptions
Expand All @@ -25,7 +25,7 @@ export const fetchAPI = async (
options.storeCookies(response.headers)
}

return response.status !== 204 ? response.json() : undefined
return (response.status !== 204 ? response.json() : undefined) as Promise<T>
}

console.error(info, init, response)
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/platforms/vtex/utils/cookies.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Context } from '../index'
import { Headers } from 'node-fetch'

export interface ContextForCookies {
headers: Context['headers']
Expand Down Expand Up @@ -36,7 +37,7 @@ export const updatesContextStorageCookies = (

export const setCookie = (ctx: Pick<Context, 'storage'>, headers: Headers) => {
headers
.getSetCookie()
.raw()['set-cookie']
.forEach((setCookieValue) =>
updatesContextStorageCookies(ctx, setCookieValue)
)
Expand Down
1 change: 1 addition & 0 deletions packages/api/test/vtex.cookies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../src/platforms/vtex/utils/cookies'
import type { ContextForCookies } from '../src/platforms/vtex/utils/cookies'
import type { Context } from '../src/platforms/vtex'
import { Headers } from 'node-fetch'

describe('getUpdatedCookie', () => {
it('Should return undefined if context has no headers', () => {
Expand Down
Loading
Loading