Skip to content

Commit

Permalink
fix: 🏷️ export valid hash types
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-hemphill committed May 7, 2021
1 parent 5b72352 commit 4133b14
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "npm run build -- --watch",
"pre-push": "run-s build lint:* test:*",
"build": "tsup src/index.ts --sourcemap --dts --format cjs,esm",
"build": "tsup src/index.ts --sourcemap --dts --minify --format cjs,esm",
"log": "conventional-changelog -p angular -i CHANGELOG.md -s",
"lint": "run-s lint:*",
"lint:typescript": "eslint src --ext .ts --fix",
Expand Down
3 changes: 2 additions & 1 deletion src/csp.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ type HostNameScheme = `${string}.${string}`
type HostSource = `${HostProtocolSchemes}${HostNameScheme}${PortScheme}`

// Crypto Source Definition
export const validCrypto = ['nonce', 'sha256', 'sha384', 'sha512'] as const;
export const validHashes = ['sha256', 'sha384', 'sha512'] as const;
export const validCrypto = ['nonce', ...validHashes] as const;
type ValidCrypto = typeof validCrypto[number];
type CryptoSources = `${ValidCrypto}-${string}`

Expand Down
22 changes: 19 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { directiveMap, Directives, ReportTo, ReferrerHeaderOptions, referrerHeaderOptions, directiveValuesByCategory } from './csp.types.js';
import {
directiveMap,
Directives,
ReportTo,
ReferrerHeaderOptions,
referrerHeaderOptions,
directiveValuesByCategory,
validHashes,
validCrypto,
} from './csp.types.js';

type ReportTos = ReportTo | ReportTo[]
function normalizeArrayString<T> (arrS: T[] | T): T[] {
return Array.isArray(arrS) ? arrS : [arrS];
}

export const ValidHashes = validHashes;
export const ValidCrypto = validCrypto;
export const directiveNamesList = <(keyof typeof directiveMap)[]>Object.keys(directiveMap);
type DirectiveName = keyof typeof directiveMap;
type DirectiveValue = typeof directiveMap[DirectiveName]
Expand Down Expand Up @@ -38,7 +49,12 @@ export class CspDirectives {
public ReportOnly: Directives | false
public ReportTo: ReportTos
public ReferrerHeader: ReferrerHeaderOptions
constructor (csp?: Directives,sendReportsTo?: ReportTos, reportSubset?: Directives,referrerHeaderOverride?: ReferrerHeaderOptions){
constructor (
csp?: Directives,
sendReportsTo?: ReportTos,
reportSubset?: Directives,
referrerHeaderOverride?: ReferrerHeaderOptions,
){
this.CSP = csp || {};
this.ReportOnly = reportSubset || false;
this.ReportTo = sendReportsTo || [];
Expand Down

0 comments on commit 4133b14

Please sign in to comment.