diff --git a/index.d.ts b/index.d.ts index 4d7aa64..d89bdcd 100644 --- a/index.d.ts +++ b/index.d.ts @@ -10,9 +10,9 @@ declare module 'fastify' { } } -type FastifyHelmetOptions = Parameters[0] & { enableCSPNonces?: boolean }; +export type FastifyHelmetOptions = NonNullable[0] & { enableCSPNonces?: boolean }>; -export const fastifyHelmet: FastifyPluginCallback> & { +export const fastifyHelmet: FastifyPluginCallback & { contentSecurityPolicy: typeof helmet.contentSecurityPolicy; }; diff --git a/index.test-d.ts b/index.test-d.ts index a714a10..e7263df 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,13 +1,14 @@ -import fastify from "fastify"; -import { expectType } from "tsd"; +import fastify, { FastifyPluginCallback } from "fastify"; +import { expectAssignable, expectType } from "tsd"; import helmet from "helmet"; -import fastifyHelmet from "."; +import fastifyHelmet, { FastifyHelmetOptions } from "."; const app = fastify(); app.register(fastifyHelmet); app.register(fastifyHelmet, {}); -app.register(fastifyHelmet, { + +const helmetOptions = { contentSecurityPolicy: false, dnsPrefetchControl: false, expectCt: false, @@ -19,7 +20,10 @@ app.register(fastifyHelmet, { permittedCrossDomainPolicies: false, referrerPolicy: false, xssFilter: false -}); +}; + +expectAssignable(helmetOptions); +app.register(fastifyHelmet, helmetOptions); app.register(fastifyHelmet, { contentSecurityPolicy: { @@ -51,7 +55,7 @@ app.register(fastifyHelmet, { policy: 'foo' }, // these options are false or never - // hidePoweredBy: false + // hidePoweredBy: false // ieNoOpen: false, // noSniff: false, // xssFilter: false @@ -59,7 +63,7 @@ app.register(fastifyHelmet, { app.register(fastifyHelmet, { enableCSPNonces: true }); -app.register(fastifyHelmet, { +app.register(fastifyHelmet, { enableCSPNonces: true, contentSecurityPolicy: { directives: { @@ -77,3 +81,8 @@ app.get('/', function(request, reply) { const csp = fastifyHelmet.contentSecurityPolicy; expectType(csp); + +// fastify-helmet instance is using the FastifyHelmetOptions options +expectType & { + contentSecurityPolicy: typeof helmet.contentSecurityPolicy; +}>(fastifyHelmet);