diff --git a/packages/manager/package.json b/packages/manager/package.json index 8cbc99109..4c098fdfd 100644 --- a/packages/manager/package.json +++ b/packages/manager/package.json @@ -71,7 +71,7 @@ "@prismicio/types-internal": "^2.8.0", "@segment/analytics-node": "^2.1.2", "@slicemachine/plugin-kit": "workspace:*", - "cookie": "^0.5.0", + "cookie": "^1.0.1", "cors": "^2.8.5", "execa": "^7.1.1", "file-type": "^18.2.1", @@ -95,7 +95,6 @@ "@amplitude/experiment-node-server": "1.8.1", "@prismicio/mock": "0.2.0", "@size-limit/preset-small-lib": "8.2.4", - "@types/cookie": "0.5.1", "@types/express": "4.17.17", "@types/semver": "7.3.13", "@typescript-eslint/eslint-plugin": "5.55.0", diff --git a/packages/manager/src/lib/serializeCookies.ts b/packages/manager/src/lib/serializeCookies.ts index 6eea443ee..66bb41416 100644 --- a/packages/manager/src/lib/serializeCookies.ts +++ b/packages/manager/src/lib/serializeCookies.ts @@ -4,7 +4,9 @@ const COOKIE_SEPARATOR = "; "; type Cookies = string | string[] | Record; -const castParsedCookies = (cookies: Cookies): Record => { +const castParsedCookies = ( + cookies: Cookies, +): Record => { if (Array.isArray(cookies)) { return cookie.parse(cookies.join(COOKIE_SEPARATOR)); } else if (typeof cookies === "string") { @@ -33,12 +35,15 @@ export const serializeCookies = ( const items: string[] = []; for (const name in cookiesToSerialize) { - items.push( - cookie.serialize(name, cookiesToSerialize[name], { - // Cookies need be stored raw (not encoded or escaped), so that consumers can format them the way they want them to be formatted. - encode: (cookie) => cookie, - }), - ); + const cookieValue = cookiesToSerialize[name]; + if (cookieValue) { + items.push( + cookie.serialize(name, cookieValue, { + // Cookies need be stored raw (not encoded or escaped), so that consumers can format them the way they want them to be formatted. + encode: (cookie) => cookie, + }), + ); + } } return items.join(COOKIE_SEPARATOR); diff --git a/packages/manager/test/PrismicAuthManager-getAuthenticationCookies.test.ts b/packages/manager/test/PrismicAuthManager-getAuthenticationCookies.test.ts index 77c710d01..7d6c23d5f 100644 --- a/packages/manager/test/PrismicAuthManager-getAuthenticationCookies.test.ts +++ b/packages/manager/test/PrismicAuthManager-getAuthenticationCookies.test.ts @@ -19,7 +19,7 @@ it("returns parsed cookies from the auth state file", async (ctx) => { const authenticationCookies = await prismicAuthManager.getAuthenticationCookies(); - expect(authenticationCookies).toStrictEqual({ + expect(authenticationCookies).toEqual({ "prismic-auth": "token", SESSION: "session", }); diff --git a/packages/manager/test/SliceMachineManager-user-getAuthenticationCookies.test.ts b/packages/manager/test/SliceMachineManager-user-getAuthenticationCookies.test.ts index f47e9a7d4..8f58368f5 100644 --- a/packages/manager/test/SliceMachineManager-user-getAuthenticationCookies.test.ts +++ b/packages/manager/test/SliceMachineManager-user-getAuthenticationCookies.test.ts @@ -25,7 +25,7 @@ it("returns parsed cookies from the auth state file", async (ctx) => { const authenticationCookies = await manager.user.getAuthenticationCookies(); - expect(authenticationCookies).toStrictEqual({ + expect(authenticationCookies).toEqual({ "prismic-auth": "token", SESSION: "session", }); diff --git a/yarn.lock b/yarn.lock index c9e7f19ce..7c373715f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9235,13 +9235,12 @@ __metadata: "@segment/analytics-node": ^2.1.2 "@size-limit/preset-small-lib": 8.2.4 "@slicemachine/plugin-kit": "workspace:*" - "@types/cookie": 0.5.1 "@types/express": 4.17.17 "@types/semver": 7.3.13 "@typescript-eslint/eslint-plugin": 5.55.0 "@typescript-eslint/parser": 5.55.0 "@vitest/coverage-v8": 0.32.0 - cookie: ^0.5.0 + cookie: ^1.0.1 cors: ^2.8.5 depcheck: 1.4.3 eslint: 8.37.0 @@ -11082,13 +11081,6 @@ __metadata: languageName: node linkType: hard -"@types/cookie@npm:0.5.1": - version: 0.5.1 - resolution: "@types/cookie@npm:0.5.1" - checksum: 9a8d60fc84797122bc399d6bd330fe5780dc7aab032321de705049ea925339f74658bfa418de483a625d51858770efef58df633ff2e20f1bdf7fbd74a52847e2 - languageName: node - linkType: hard - "@types/cookie@npm:^0.4.1": version: 0.4.1 resolution: "@types/cookie@npm:0.4.1" @@ -15880,10 +15872,10 @@ __metadata: languageName: node linkType: hard -"cookie@npm:^0.5.0": - version: 0.5.0 - resolution: "cookie@npm:0.5.0" - checksum: 1f4bd2ca5765f8c9689a7e8954183f5332139eb72b6ff783d8947032ec1fdf43109852c178e21a953a30c0dd42257828185be01b49d1eb1a67fd054ca588a180 +"cookie@npm:^1.0.1": + version: 1.0.1 + resolution: "cookie@npm:1.0.1" + checksum: e2ff4879d816ea27dab69651c06d328b1f4214ccefa1023b6ebf85787bc23b3cad777ed51b4e54c01d161c374a05fc86e45e51ee3d9fafb48a836439c56b2458 languageName: node linkType: hard