Skip to content

Commit

Permalink
feat: add partitioned option (#21)
Browse files Browse the repository at this point in the history
* feat: partitioned cookies

* test: partitioned cookies

* fix: run lint:fix

* lint

* sync docs with @types/cookie

---------

Co-authored-by: Pooya Parsa <pooya@pi0.io>
  • Loading branch information
AlexXanderGrib and pi0 authored Mar 29, 2024
1 parent bcf66c0 commit 1de517e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ export function serialize(
}
}

if (opt.partitioned) {
str += "; Partitioned";
}

return str;
}

Expand Down
11 changes: 11 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions test/serialize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
});

0 comments on commit 1de517e

Please sign in to comment.