jagaapple / next-secure-headers

Sets secure response headers for Next.js.
MIT License
313 stars 13 forks source link

Export types for contentSecurityPolicy and directives #56

Open emilfjellstrom opened 2 years ago

emilfjellstrom commented 2 years ago

šŸŒ± Feature Request

Is your feature request related to a problem? Please describe.

A clear and concise description of what you want and what your use case is.

Hello, I have been working on my own interpretation of this package to handle specific headers for my company and I would like to import the types for directives in contentSecurityPolicy so that I'm able to extend the interface.

Describe the solution you'd like

A clear and concise description of what you want to happen.

Adding the types to the export would be the ideal way forward. Being able to export the types means that we can extend it to make certain keys and values strict to a specific value or to only accept string[]

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Currently, I have been trying to access the types through this method.

import { createSecureHeaders } from 'next-secure-headers';

type ArgumentTypes<F extends Function> = F extends (...args: infer A) => any ? A : never;

type SecureHeadersArguments = ArgumentTypes<typeof createSecureHeaders>[0];

export type Directives = SecureHeadersArguments['contentSecurityPolicy'];

But I'm getting a type error on the last line:

Property 'contentSecurityPolicy' does not exist on type 'Partial<{ contentSecurityPolicy: ContentSecurityPolicyOption; expectCT: ExpectCTOption; forceHTTPSRedirect: ForceHTTPSRedirectOption; ... 4 more ...; xssProtection: XSSProtectionOption; }> | undefined'.ts(2339)

Documentation, Adoption, Migration Strategy

If you can, explain how users will be able to use this and how it might be documented. Maybe a mock-up?

import { ContentSecurityPolicyOption } from "next-secure-headers";

type Directives = ContentSecurityPolicyOption['directives']