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

fix: types-compabitility for express-jwt @ 7 #301

Merged
merged 3 commits into from
May 6, 2022
Merged

fix: types-compabitility for express-jwt @ 7 #301

merged 3 commits into from
May 6, 2022

Conversation

carboneater
Copy link
Contributor

@carboneater carboneater commented May 5, 2022

By submitting a PR to this repository, you agree to the terms within the Auth0 Code of Conduct. Please see the contributing guidelines for how to create and submit a high-quality PR for this repo.

Description

As described in #299, although the lib is able to use express-jwt@7, its type definitions were conflicting preventing any and all typescript users to use jwks-rsa@2 with express-jwt@7

References

#299

Testing

Describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.

Please include any manual steps for testing end-to-end or functionality not covered by unit/integration tests.

Also include details of the environment this PR was developed in (language/platform/browser version).

  • This change adds test coverage for new/changed/fixed functionality

Testing of the types changes can be confirmed using

  • npm run clean:ts
  • npx tsc

(There won't be output, which is a success when compared to the errors we had previously)

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs: None
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not master

bombillazo
bombillazo previously approved these changes May 6, 2022
@@ -44,4 +46,22 @@ describe('typescript definition', () => {
const key = await client.getSigningKey('NkFCNEE1NDFDNTQ5RTQ5OTE1QzRBMjYyMzY0NEJCQTJBMjJBQkZCMA');
expect(key.kid).to.equal('NkFCNEE1NDFDNTQ5RTQ5OTE1QzRBMjYyMzY0NEJCQTJBMjJBQkZCMA');
});

it.skip('Types-Only Validation with express-jwt', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it.skip('Types-Only Validation with express-jwt', () => {
it('Types-Only Validation with express-jwt', () => {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had a skip marker here as I was only testing the transpilation, which was the issue at hand.

I've removed the skip marker in c98ac1f
Now, the test may fail at transpilation due to mismatched types.
Or it may fail if something throws at initialization.

I've purposely not duplicated the test suite from tests/express.es5.tests.js as I didn't see any gains from doing so

@@ -24,7 +26,7 @@ describe('typescript definition', () => {
});
});

describe('getKeysInterceptor', async () => {
it('getKeysInterceptor', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for spotting this, looks like you've uncovered a failing test.

Could you replace keySetResponse with https://github.com/auth0/node-jwks-rsa/blob/master/tests/keys.js#L2 to fix

Gabriel Fournier added 2 commits May 6, 2022 08:29
Going from types-only test to types & unexpected throw at initialization...
Copy link
Contributor

@adamjmcgrath adamjmcgrath left a comment

Choose a reason for hiding this comment

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

Thanks @carboneater!

import { Agent as HttpAgent } from 'http';
import { Agent as HttpsAgent } from 'https';
import type {Jwt, Secret} from 'jsonwebtoken'
Copy link

Choose a reason for hiding this comment

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

This change makes jwks-rsa only compatible with Typescript 3.8+ as the type-only imports and exports feature was release with TS 3.8. For one of my projects, we are on TS 3.7.3, which means this breaks our compatibility

Also - this line is missing a semicolon :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, my bad.

Internally, I'd say update typescript on the project.

If that's not possible, then you may want to open a merge request to address that issue

Choose a reason for hiding this comment

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

No problem - we just attempted to upgrade and ran into a couple of other issues. We will be putting up a pull request soon!

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.

None yet

4 participants