From 4d8c66fdd9befb3347c9e099d7fcf22175df3007 Mon Sep 17 00:00:00 2001 From: Timothy Lehner Date: Tue, 7 Nov 2023 16:44:28 +0000 Subject: [PATCH] fix: add missingRequiredClaim to TokenValidationErrorCode (#403) 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 --- src/index.d.ts | 2 ++ test/types.spec.ts | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index 8a64e98..73f794f 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -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 { @@ -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' } diff --git a/test/types.spec.ts b/test/types.spec.ts index 03af010..f6c07f3 100644 --- a/test/types.spec.ts +++ b/test/types.spec.ts @@ -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 @@ -105,3 +105,6 @@ const signerOptionsNoAlg = { } } expectNotAssignable(signerOptionsNoAlg.header) + +// Check all errors are typed correctly +expectType(Object.values(TokenError.codes))