Skip to content

Commit

Permalink
bump @edge-runtime/cookies for Partitioned cookie support (#62889)
Browse files Browse the repository at this point in the history
Bumps `@edge-runtime/cookies` to add support for `set-Cookie:
Partitioned` attribute

- vercel/edge-runtime#825
-
https://developer.mozilla.org/en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies
  • Loading branch information
rezof authored Mar 5, 2024
1 parent 02c4ce1 commit 8d8ec75
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"@babel/traverse": "7.22.5",
"@babel/types": "7.22.5",
"@capsizecss/metrics": "2.0.0",
"@edge-runtime/cookies": "4.0.2",
"@edge-runtime/cookies": "4.1.0",
"@edge-runtime/ponyfill": "2.4.1",
"@edge-runtime/primitives": "4.0.2",
"@hapi/accept": "5.0.2",
Expand Down
21 changes: 13 additions & 8 deletions packages/next/src/compiled/@edge-runtime/cookies/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// Type definitions for cookie 0.5
// Project: https://github.com/jshttp/cookie
// Definitions by: Pine Mizune <https://github.com/pine>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/**
* Basic HTTP cookie parser and serializer for HTTP servers.
*/
Expand Down Expand Up @@ -62,6 +56,17 @@ interface CookieSerializeOptions {
* point to the same date and time.
*/
maxAge?: number | undefined;
/**
* Specifies the `boolean` value for the [`Partitioned` `Set-Cookie`](rfc-cutler-httpbis-partitioned-cookies)
* attribute. When truthy, the `Partitioned` attribute is set, otherwise it is not. By default, the
* `Partitioned` attribute is not set.
*
* **note** This is an attribute that has not yet been fully standardized, and may change in the future.
* This also means many clients may ignore this attribute until they understand it.
*
* More information about can be found in [the proposal](https://github.com/privacycg/CHIPS)
*/
partitioned?: boolean | undefined;
/**
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.4|`Path` `Set-Cookie` attribute}.
* By default, the path is considered the "default path".
Expand Down Expand Up @@ -114,7 +119,7 @@ interface CookieSerializeOptions {
* {@link https://wicg.github.io/cookie-store/#dictdef-cookielistitem CookieListItem}
* as specified by W3C.
*/
interface CookieListItem extends Pick<CookieSerializeOptions, 'domain' | 'path' | 'secure' | 'sameSite'> {
interface CookieListItem extends Pick<CookieSerializeOptions, 'domain' | 'path' | 'secure' | 'sameSite' | 'partitioned'> {
/** A string with the name of a cookie. */
name: string;
/** A string containing the value of the cookie. */
Expand Down Expand Up @@ -193,4 +198,4 @@ declare function parseCookie(cookie: string): Map<string, string>;
/** Parse a `Set-Cookie` header value */
declare function parseSetCookie(setCookie: string): undefined | ResponseCookie;

export { CookieListItem, RequestCookie, RequestCookies, ResponseCookie, ResponseCookies, parseCookie, parseSetCookie, stringifyCookie };
export { type CookieListItem, type RequestCookie, RequestCookies, type ResponseCookie, ResponseCookies, parseCookie, parseSetCookie, stringifyCookie };
5 changes: 4 additions & 1 deletion packages/next/src/compiled/@edge-runtime/cookies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function stringifyCookie(c) {
"secure" in c && c.secure && "Secure",
"httpOnly" in c && c.httpOnly && "HttpOnly",
"sameSite" in c && c.sameSite && `SameSite=${c.sameSite}`,
"partitioned" in c && c.partitioned && "Partitioned",
"priority" in c && c.priority && `Priority=${c.priority}`
].filter(Boolean);
return `${c.name}=${encodeURIComponent((_a = c.value) != null ? _a : "")}; ${attrs.join("; ")}`;
Expand Down Expand Up @@ -74,6 +75,7 @@ function parseSetCookie(setCookie) {
path,
samesite,
secure,
partitioned,
priority
} = Object.fromEntries(
attributes.map(([key, value2]) => [key.toLowerCase(), value2])
Expand All @@ -88,7 +90,8 @@ function parseSetCookie(setCookie) {
path,
...samesite && { sameSite: parseSameSite(samesite) },
...secure && { secure: true },
...priority && { priority: parsePriority(priority) }
...priority && { priority: parsePriority(priority) },
...partitioned && { partitioned: true }
};
return compact(cookie);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"@edge-runtime/cookies","version":"4.0.2","main":"./index.js","license":"MPL-2.0"}
{"name":"@edge-runtime/cookies","version":"4.1.0","main":"./index.js","license":"MPL-2.0"}
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

0 comments on commit 8d8ec75

Please sign in to comment.