Skip to content

Commit

Permalink
types(index): export errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Feb 4, 2025
1 parent 56c3a36 commit 49b6e4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 11 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import {
FastifyReply,
FastifyPluginCallback
} from 'fastify'
import { FastifyError } from '@fastify/error'

declare interface FastifyBearerAuthErrors {
FST_BEARER_AUTH_INVALID_KEYS_OPTION_TYPE: FastifyError
FST_BEARER_AUTH_INVALID_LOG_LEVEL: FastifyError
FST_BEARER_AUTH_KEYS_OPTION_INVALID_KEY_TYPE: FastifyError
FST_BEARER_AUTH_INVALID_SPEC: FastifyError
FST_BEARER_AUTH_MISSING_AUTHORIZATION_HEADER: FastifyError
FST_BEARER_AUTH_INVALID_AUTHORIZATION_HEADER: FastifyError
}

declare module 'fastify' {
interface FastifyInstance {
Expand All @@ -29,6 +39,7 @@ declare namespace fastifyBearerAuth {
export type verifyBearerAuthFactory = (options: fastifyBearerAuth.FastifyBearerAuthOptions) => verifyBearerAuth

export const fastifyBearerAuth: FastifyBearerAuth
export const FastifyBearerAuthErrors: FastifyBearerAuthErrors
export { fastifyBearerAuth as default }
}

Expand Down
10 changes: 9 additions & 1 deletion types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fastify, { FastifyRequest } from 'fastify'
import { FastifyError } from '@fastify/error'
import { expectAssignable, expectType } from 'tsd'
import bearerAuth, { FastifyBearerAuthOptions, verifyBearerAuth, verifyBearerAuthFactory } from '..'
import bearerAuth, { FastifyBearerAuthErrors, FastifyBearerAuthOptions, verifyBearerAuth, verifyBearerAuthFactory } from '..'

const pluginOptions: FastifyBearerAuthOptions = {
keys: new Set(['foo']),
Expand Down Expand Up @@ -86,3 +87,10 @@ fastify().register(bearerAuth, pluginOptionsKeyArray)

expectType<verifyBearerAuth | undefined>(fastify().verifyBearerAuth)
expectType<verifyBearerAuthFactory | undefined>(fastify().verifyBearerAuthFactory)

expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_KEYS_OPTION_TYPE)
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_LOG_LEVEL)
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_KEYS_OPTION_INVALID_KEY_TYPE)
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_SPEC)
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_MISSING_AUTHORIZATION_HEADER)
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_AUTHORIZATION_HEADER)

0 comments on commit 49b6e4c

Please sign in to comment.