Skip to content

Commit 3b11ba3

Browse files
committed
types(index): export errors
1 parent 9faf62e commit 3b11ba3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

types/index.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import {
33
FastifyReply,
44
FastifyPluginCallback
55
} from 'fastify'
6+
import { FastifyError } from '@fastify/error'
7+
8+
declare interface FastifyBearerAuthErrors {
9+
FST_BEARER_AUTH_INVALID_KEYS_OPTION_TYPE: FastifyError
10+
FST_BEARER_AUTH_INVALID_LOG_LEVEL: FastifyError
11+
FST_BEARER_AUTH_KEYS_OPTION_INVALID_KEY_TYPE: FastifyError
12+
FST_BEARER_AUTH_INVALID_SPEC: FastifyError
13+
FST_BEARER_AUTH_MISSING_AUTHORIZATION_HEADER: FastifyError
14+
FST_BEARER_AUTH_INVALID_AUTHORIZATION_HEADER: FastifyError
15+
}
616

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

3141
export const fastifyBearerAuth: FastifyBearerAuth
42+
export const FastifyBearerAuthErrors: FastifyBearerAuthErrors
3243
export { fastifyBearerAuth as default }
3344
}
3445

types/index.test-d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fastify, { FastifyRequest } from 'fastify'
2+
import { FastifyError } from '@fastify/error'
23
import { expectAssignable, expectType } from 'tsd'
3-
import bearerAuth, { FastifyBearerAuthOptions, verifyBearerAuth, verifyBearerAuthFactory } from '..'
4+
import bearerAuth, { FastifyBearerAuthErrors, FastifyBearerAuthOptions, verifyBearerAuth, verifyBearerAuthFactory } from '..'
45

56
const pluginOptions: FastifyBearerAuthOptions = {
67
keys: new Set(['foo']),
@@ -68,3 +69,10 @@ fastify().register(bearerAuth, pluginOptionsKeyArray)
6869

6970
expectType<verifyBearerAuth | undefined>(fastify().verifyBearerAuth)
7071
expectType<verifyBearerAuthFactory | undefined>(fastify().verifyBearerAuthFactory)
72+
73+
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_KEYS_OPTION_TYPE)
74+
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_LOG_LEVEL)
75+
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_KEYS_OPTION_INVALID_KEY_TYPE)
76+
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_SPEC)
77+
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_MISSING_AUTHORIZATION_HEADER)
78+
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_AUTHORIZATION_HEADER)

0 commit comments

Comments
 (0)