Skip to content

Commit

Permalink
fix: update and use cookie directly
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Oct 10, 2024
1 parent 8e40724 commit 4af1423
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
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]
}
}

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

0 comments on commit 4af1423

Please sign in to comment.