diff --git a/src/index.ts b/src/index.ts index fbaf20b..3f89c0c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -197,6 +197,10 @@ export function serialize( } } + if (opt.partitioned) { + str += "; Partitioned"; + } + return str; } diff --git a/src/types.ts b/src/types.ts index a6aea2a..7f97f24 100644 --- a/src/types.ts +++ b/src/types.ts @@ -108,6 +108,17 @@ export interface CookieSerializeOptions { * not have an HTTPS connection. */ secure?: boolean | 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; } /** diff --git a/test/serialize.test.ts b/test/serialize.test.ts index 1c82627..5ad32c5 100644 --- a/test/serialize.test.ts +++ b/test/serialize.test.ts @@ -261,4 +261,16 @@ describe("serialize(name, value, options)", () => { expect(serialize("foo", "bar", { secure: false })).toBe("foo=bar"); }); }); + + describe('with "partitioned" option', () => { + it("should include partitioned flag when true", () => { + expect(serialize("foo", "bar", { partitioned: true })).toBe( + "foo=bar; Partitioned", + ); + }); + + it("should not include partitioned flag when false", () => { + expect(serialize("foo", "bar", { partitioned: false })).toBe("foo=bar"); + }); + }); });