Skip to content

Commit 9bc0d33

Browse files
cesarvsprUzlopak
andauthored
nodenext compatibility (#207)
* declare namespace * fix: use FastifyPluginAsync * fix Co-authored-by: Uzlopak <aras.abbasi@googlemail.com>
1 parent e288315 commit 9bc0d33

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { randomBytes } = require('crypto')
44
const fp = require('fastify-plugin')
55
const helmet = require('helmet')
66

7-
async function helmetPlugin (fastify, options) {
7+
async function fastifyHelmet (fastify, options) {
88
// helmet will throw when any option is explicitly set to "true"
99
// using ECMAScript destructuring is a clean workaround as we do not need to alter options
1010
const { enableCSPNonces, global, ...globalConfiguration } = options
@@ -138,9 +138,11 @@ function done (error) {
138138
if (error) throw error
139139
}
140140

141-
module.exports = fp(helmetPlugin, {
141+
module.exports = fp(fastifyHelmet, {
142142
fastify: '4.x',
143143
name: '@fastify/helmet'
144144
})
145+
module.exports.default = fastifyHelmet
146+
module.exports.fastifyHelmet = fastifyHelmet
145147

146148
module.exports.contentSecurityPolicy = helmet.contentSecurityPolicy

types/index.d.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import helmet, { contentSecurityPolicy, HelmetOptions } from 'helmet';
44
declare module 'fastify' {
55
export interface RouteShorthandOptions<
66
RawServer extends RawServerBase = RawServerDefault
7-
> extends FastifyHelmetRouteOptions {}
7+
> extends fastifyHelmet.FastifyHelmetRouteOptions { }
88

99
interface FastifyReply {
1010
cspNonce: {
@@ -14,20 +14,27 @@ declare module 'fastify' {
1414
helmet: (opts?: HelmetOptions) => typeof helmet
1515
}
1616

17-
export interface RouteOptions extends FastifyHelmetRouteOptions {}
17+
export interface RouteOptions extends fastifyHelmet.FastifyHelmetRouteOptions { }
1818
}
1919

20-
export interface FastifyHelmetRouteOptions {
21-
helmet?: Omit<FastifyHelmetOptions, 'global'> | false;
22-
}
23-
24-
export interface FastifyHelmetOptions extends NonNullable<HelmetOptions> {
25-
enableCSPNonces?: boolean,
26-
global?: boolean;
27-
}
28-
29-
export const fastifyHelmet: FastifyPluginAsync<FastifyHelmetOptions> & {
20+
type FastifyHelmet = FastifyPluginAsync<fastifyHelmet.FastifyHelmetOptions> & {
3021
contentSecurityPolicy: typeof contentSecurityPolicy;
3122
};
3223

33-
export default fastifyHelmet;
24+
declare namespace fastifyHelmet {
25+
26+
export interface FastifyHelmetRouteOptions {
27+
helmet?: Omit<FastifyHelmetOptions, 'global'> | false;
28+
}
29+
30+
export interface FastifyHelmetOptions extends NonNullable<HelmetOptions> {
31+
enableCSPNonces?: boolean,
32+
global?: boolean;
33+
}
34+
35+
export const fastifyHelmet: FastifyHelmet
36+
export { fastifyHelmet as default }
37+
}
38+
39+
declare function fastifyHelmet(...params: Parameters<FastifyHelmet>): ReturnType<FastifyHelmet>
40+
export = fastifyHelmet

0 commit comments

Comments
 (0)