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

Update to helmet v4 #84

Merged
merged 8 commits into from
Aug 3, 2020
Merged

Update to helmet v4 #84

merged 8 commits into from
Aug 3, 2020

Conversation

mcollina
Copy link
Member

Fixes fastify/help#225

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

@mcollina mcollina requested a review from delvedor July 28, 2020 17:40
@@ -129,7 +99,7 @@ test('disabling one header does not disable the other headers', (t) => {
'x-dns-prefetch-control': 'off',

Choose a reason for hiding this comment

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

If relevant, there are some other headers that are set by default. You can see that tested in Helmet's source code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

@mcollina
Copy link
Member Author

@EvanHahn Do you think you could export the HelmetOptions interface? So I can simplify https://github.com/fastify/fastify-helmet/blob/master/index.d.ts.

@EvanHahn
Copy link

Does the Parameters<typeof helmet> type work for you? If not, I can export it and publish a new release candidate.

@mcollina
Copy link
Member Author

I don't think it would work. I'm getting Readonly<HelmetOptions> | undefined as the first parameter of helmet, however It does not satisfy the other constraints for FastifyPluginOptions.

   ✖  14:43  Type Readonly<HelmetOptions> | undefined does not satisfy the constraint FastifyPluginOptions.
  Type undefined is not assignable to type FastifyPluginOptions.

cc @Ethan-Arrowood

@mcollina
Copy link
Member Author

Can you export that type as well?

@mcollina
Copy link
Member Author

Overall, I have no idea on how to reuse the types from helmet, so any help on this front would be handy.

@Ethan-Arrowood
Copy link
Member

Does HelmetOptions extend from FastifyPluginOptions? If not it won't be able to satisfy that constraint (unless you separately copy all the types in FastifyPluginOptions). I haven't looked past just this comment so there may be more details to the solution here.

@mcollina
Copy link
Member Author

As I said, I have no clue about what I'm doing :). If you could push to this branch @Ethan-Arrowood that would be amazing. The types for the options are already fully typed in helmet, so we should be able to reuse that, shouldn't we?

@Ethan-Arrowood
Copy link
Member

I'll take a stab now

@Ethan-Arrowood
Copy link
Member

@EvanHahn yes please export the option interface!

@EvanHahn
Copy link

Will do! I'll plan to release a new release candidate later today.

@EvanHahn
Copy link

Just published [email protected], which you should be able to install with npm install helmet@next.

@Ethan-Arrowood
Copy link
Member

Okay so I've done the given type change (which I believe is correct from looking at index.js). But as expected the test file is blowing up. Im assuming the api for helmet has changed in this major? Tomorrow I can look at fixing the test file but I don't totally see the purpose of all the tests if we are strictly dependent on helmet now. The tests would be more valuable on helmet side (might be a good cross project collaboration or good-first-issue on Evan's project)

@Ethan-Arrowood
Copy link
Member

You can see the sort of change necessary in the diff from commit 60d9c3a

@EvanHahn
Copy link

I don't think I fully understand the problem, but Helmet 4 introduced some breaking changes which you can see in the changelog.

@Ethan-Arrowood
Copy link
Member

Nothing to worry about Evan. The new helmet types are 💯

Either our previous types were a little inaccurate or some things have changed. I only know this because we have a file for testing our type definitions (powered by the tsd library). To complete this PR we need to update that test file so it correctly follows your types.

I'll be able to work on this more tomorrow

@Ethan-Arrowood Ethan-Arrowood marked this pull request as ready for review July 30, 2020 20:35
package.json Outdated Show resolved Hide resolved
Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

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

LGTM

@mcollina mcollina merged commit 3eb99a2 into master Aug 3, 2020
@mcollina mcollina deleted the update-to-helmet-v4 branch August 3, 2020 15:26
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.

Helmet 4 with fastify-helmet
4 participants