Skip to content

Commit 6ed7f06

Browse files
authored
types(index): export errors (#210)
* types(index): export errors * types(index): add new hook error
1 parent b7e6302 commit 6ed7f06

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

types/index.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ 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_HOOK: FastifyError
11+
FST_BEARER_AUTH_INVALID_LOG_LEVEL: FastifyError
12+
FST_BEARER_AUTH_KEYS_OPTION_INVALID_KEY_TYPE: FastifyError
13+
FST_BEARER_AUTH_INVALID_SPEC: FastifyError
14+
FST_BEARER_AUTH_MISSING_AUTHORIZATION_HEADER: FastifyError
15+
FST_BEARER_AUTH_INVALID_AUTHORIZATION_HEADER: FastifyError
16+
}
617

718
declare module 'fastify' {
819
interface FastifyInstance {
@@ -29,6 +40,7 @@ declare namespace fastifyBearerAuth {
2940
export type verifyBearerAuthFactory = (options: fastifyBearerAuth.FastifyBearerAuthOptions) => verifyBearerAuth
3041

3142
export const fastifyBearerAuth: FastifyBearerAuth
43+
export const FastifyBearerAuthErrors: FastifyBearerAuthErrors
3244
export { fastifyBearerAuth as default }
3345
}
3446

types/index.test-d.ts

+10-1
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']),
@@ -87,3 +88,11 @@ fastify().register(bearerAuth, pluginOptionsKeyArray)
8788

8889
expectType<verifyBearerAuth | undefined>(fastify().verifyBearerAuth)
8990
expectType<verifyBearerAuthFactory | undefined>(fastify().verifyBearerAuthFactory)
91+
92+
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_KEYS_OPTION_TYPE)
93+
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_HOOK)
94+
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_LOG_LEVEL)
95+
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_KEYS_OPTION_INVALID_KEY_TYPE)
96+
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_SPEC)
97+
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_MISSING_AUTHORIZATION_HEADER)
98+
expectType<FastifyError>(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_AUTHORIZATION_HEADER)

0 commit comments

Comments
 (0)