From 49b6e4c7fb0ed91d7bd71530d12682aafe3ddade Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 27 Jan 2025 18:42:18 +0000 Subject: [PATCH] types(index): export errors --- types/index.d.ts | 11 +++++++++++ types/index.test-d.ts | 10 +++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index f29e856..6030cc0 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -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 { @@ -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 } } diff --git a/types/index.test-d.ts b/types/index.test-d.ts index f523e16..1618458 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -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']), @@ -86,3 +87,10 @@ fastify().register(bearerAuth, pluginOptionsKeyArray) expectType(fastify().verifyBearerAuth) expectType(fastify().verifyBearerAuthFactory) + +expectType(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_KEYS_OPTION_TYPE) +expectType(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_LOG_LEVEL) +expectType(FastifyBearerAuthErrors.FST_BEARER_AUTH_KEYS_OPTION_INVALID_KEY_TYPE) +expectType(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_SPEC) +expectType(FastifyBearerAuthErrors.FST_BEARER_AUTH_MISSING_AUTHORIZATION_HEADER) +expectType(FastifyBearerAuthErrors.FST_BEARER_AUTH_INVALID_AUTHORIZATION_HEADER)