Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cookies): align RequestCookies and ResponseCookies #181

Merged

Conversation

balazsorban44
Copy link
Member

@balazsorban44 balazsorban44 commented Oct 23, 2022

Using the same interface as CookieStore whenever possible.

Also, both RequestCookies and ResponseCooies will only receive Headars in the constructor, as they don't need more than that. (strictly speaking, we could just pass the cookie header value too...)

@changeset-bot
Copy link

changeset-bot bot commented Oct 23, 2022

🦋 Changeset detected

Latest commit: e1d71d0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@edge-runtime/cookies Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Oct 23, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
edge-runtime ✅ Ready (Inspect) Visit Preview Oct 23, 2022 at 3:21PM (UTC)

@balazsorban44 balazsorban44 changed the title feat: align RequestCookies and ResponseCookies feat(cookies): align RequestCookies and ResponseCookies Oct 23, 2022
@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2022

Codecov Report

Merging #181 (d7ec963) into main (94ad6e1) will decrease coverage by 3.37%.
The diff coverage is 85.50%.

@@            Coverage Diff             @@
##             main     #181      +/-   ##
==========================================
- Coverage   87.91%   84.53%   -3.38%     
==========================================
  Files          14       21       +7     
  Lines        1704     1785      +81     
  Branches      213      182      -31     
==========================================
+ Hits         1498     1509      +11     
- Misses        192      252      +60     
- Partials       14       24      +10     
Impacted Files Coverage Δ
packages/runtime/src/server/body-streams.ts 36.44% <68.96%> (-26.20%) ⬇️
packages/runtime/src/edge-runtime.ts 94.11% <72.72%> (-2.92%) ⬇️
packages/jest-environment/src/index.ts 97.95% <75.00%> (-2.05%) ⬇️
packages/runtime/src/server/create-handler.ts 80.88% <75.00%> (-13.43%) ⬇️
packages/cookies/src/request-cookies.ts 77.57% <77.57%> (ø)
packages/cookies/src/response-cookies.ts 80.64% <80.64%> (ø)
packages/cookies/src/serialize.ts 93.58% <93.58%> (ø)
packages/user-agent/src/index.ts 97.72% <97.72%> (ø)
jest.setup.js 100.00% <100.00%> (ø)
packages/cookies/src/cached.ts 100.00% <100.00%> (ø)
... and 13 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment on lines -10 to -11
constructor(request: Request) {
this.#headers = request.headers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used that type to hint that we need a request here and not a response

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new RequestCookies(request) looks nicer than new RequestCookies(request.headers), the latter feels kinda leaky to me. wdyt?

packages/cookies/src/types.ts Outdated Show resolved Hide resolved
packages/cookies/src/serialize.ts Show resolved Hide resolved
Comment on lines 92 to 96
clear(...args: [key: string] | [options: ResponseCookie] | []): this {
const key = typeof args[0] === 'string' ? args[0] : args[0]?.name
this.getAll(key).forEach((c) => this.delete(c))
if (key) this.getAll(key).forEach((c) => this.delete(c))
return this
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this method is confusing. response.cookies.clear() might make people believe they can clear all user cookies. this is not the case. Although, this clearly say "response.cookies.clear" so maybe it's not confusing?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should iterate this in the comment?

Copy link
Member Author

@balazsorban44 balazsorban44 Oct 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it so that you can call response.cookies.clear() which will on invalidate all cookies. 👍 added tests for it too

.changeset/breezy-geese-sneeze.md Outdated Show resolved Hide resolved
Comment on lines +13 to +14
constructor(responseHeaders: Headers) {
this.#headers = responseHeaders
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as RequestCookies

Co-authored-by: Gal Schlezinger <gal@spitfire.co.il>
…b.com:balazsorban44/edge-runtime into feat/align-request-response-cookie-interfaces
@Schniz Schniz merged commit 672a06e into vercel:main Oct 23, 2022
This was referenced Oct 23, 2022
ijjk pushed a commit to vercel/next.js that referenced this pull request Oct 27, 2022
…and `ResponseCookies` (#41526)

Ref: [Slack
thread](https://vercel.slack.com/archives/C035J346QQL/p1666056382299069?thread_ts=1666041444.633059&cid=C035J346QQL),
[docs update](vercel/front#17090)

Spec: https://wicg.github.io/cookie-store/

BREAKING CHANGE:

Ref: vercel/edge-runtime#177,
vercel/edge-runtime#181

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
jridgewell pushed a commit to jridgewell/edge-runtime that referenced this pull request Jun 23, 2023
Co-authored-by: Gal Schlezinger <gal@spitfire.co.il>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants