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

fix: update @bundled-es-modules/cookie to 2.0.1 #2312

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 0 additions & 4 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
declare module '@bundled-es-modules/cookie' {
export * as default from 'cookie'
}

declare module '@bundled-es-modules/statuses' {
import * as statuses from 'statuses'
export default statuses
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@
],
"sideEffects": false,
"dependencies": {
"@bundled-es-modules/cookie": "^2.0.0",
"@bundled-es-modules/statuses": "^1.0.1",
"@bundled-es-modules/tough-cookie": "^0.1.6",
"@inquirer/confirm": "^3.0.0",
Expand All @@ -142,6 +141,7 @@
"@types/cookie": "^0.6.0",
"@types/statuses": "^2.0.4",
"chalk": "^4.1.2",
"cookie": "^1.0.0",
"graphql": "^16.8.1",
"headers-polyfill": "^4.0.2",
"is-node-process": "^1.2.0",
Expand Down
22 changes: 8 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions src/core/utils/request/getRequestCookies.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import cookieUtils from '@bundled-es-modules/cookie'
import * as cookieUtils from 'cookie'
import { cookieStore } from '../cookieStore'

function parseCookies(input: string): Record<string, string> {
const parsedCookies = cookieUtils.parse(input)
const cookies: Record<string, string> = {}

for (const cookieName in parsedCookies) {
if (typeof parsedCookies[cookieName] !== 'undefined') {
cookies[cookieName] = parsedCookies[cookieName]
Copy link
Member Author

Choose a reason for hiding this comment

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

Account for cookie@1.0 annotating the parsing result as Record<string, string | undefined>. Skip the cookies with undefined values.

}
}

return cookies
}

function getAllDocumentCookies() {
return cookieUtils.parse(document.cookie)
return parseCookies(document.cookie)
}

function getDocumentCookies(request: Request): Record<string, string> {
Expand Down Expand Up @@ -40,7 +53,7 @@ export function getAllRequestCookies(request: Request): Record<string, string> {
*/
const requestCookieHeader = request.headers.get('cookie')
const cookiesFromHeaders = requestCookieHeader
? cookieUtils.parse(requestCookieHeader)
? parseCookies(requestCookieHeader)
: {}

const cookiesFromDocument = getDocumentCookies(request)
Expand Down
6 changes: 2 additions & 4 deletions test/node/graphql-api/cookies.node.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* @vitest-environment node
*/
import cookieUtils from '@bundled-es-modules/cookie'
// @vitest-environment node
import * as cookieUtils from 'cookie'
import { graphql as executeGraphql, buildSchema } from 'graphql'
import { graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
Expand Down
Loading