Skip to content

Commit

Permalink
fix: add missingRequiredClaim to TokenValidationErrorCode (#403)
Browse files Browse the repository at this point in the history
this better reflects the actual source implementation
The unit tests is somewhat brittle, since it's too trusting of the .d.ts types.
I don't know how to overcome this limitation without just typing the whole project properly
  • Loading branch information
TimLehner authored Nov 7, 2023
1 parent 52e94dd commit 4d8c66f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type TokenValidationErrorCode =
| 'FAST_JWT_KEY_FETCHING_ERROR'
| 'FAST_JWT_SIGN_ERROR'
| 'FAST_JWT_VERIFY_ERROR'
| 'FAST_JWT_MISSING_REQUIRED_CLAIM'
| 'FAST_JWT_MISSING_SIGNATURE'

declare class TokenError extends Error {
Expand All @@ -52,6 +53,7 @@ declare class TokenError extends Error {
keyFetchingError: 'FAST_JWT_KEY_FETCHING_ERROR'
signError: 'FAST_JWT_SIGN_ERROR'
verifyError: 'FAST_JWT_VERIFY_ERROR'
missingRequiredClaim: 'FAST_JWT_MISSING_REQUIRED_CLAIM'
missingSignature: 'FAST_JWT_MISSING_SIGNATURE'
}

Expand Down
7 changes: 5 additions & 2 deletions test/types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-empty-function */

import { createDecoder, createSigner, createVerifier, DecodedJwt, JwtHeader, TokenError } from '..'
import { expectAssignable, expectNotAssignable } from 'tsd'
import { createDecoder, createSigner, createVerifier, DecodedJwt, JwtHeader, TokenError, TokenValidationErrorCode } from '..'
import { expectAssignable, expectNotAssignable, expectType } from 'tsd'

// Signing
// Buffer key, both async/callback styles
Expand Down Expand Up @@ -105,3 +105,6 @@ const signerOptionsNoAlg = {
}
}
expectNotAssignable<JwtHeader>(signerOptionsNoAlg.header)

// Check all errors are typed correctly
expectType<TokenValidationErrorCode[]>(Object.values(TokenError.codes))

0 comments on commit 4d8c66f

Please sign in to comment.