Merge pull request #21639 from crutchcorn/master

[lusca] Added typings
This commit is contained in:
Benjamin Lichtman
2017-11-21 11:29:07 -08:00
committed by GitHub
4 changed files with 126 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
// Type definitions for lusca 1.5
// Project: https://github.com/krakenjs/lusca#readme
// Definitions by: Corbin Crutchley <https://github.com/crutchcorn>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import express = require('express');
declare function lusca(options?: lusca.LuscaOptions): express.RequestHandler;
declare namespace lusca {
/*~ Documentation declares that:
*~ Setting any value to false will disable it.
*/
interface LuscaOptions {
csrf?: csrfOptions | boolean;
csp?: cspOptions | false;
xframe?: string | false;
p3p?: string | false;
hsts?: hstsOptions | false;
xssProtection?: xssProtectionOptions | boolean;
nosniff?: boolean;
referrerPolicy?: string | false;
}
interface cspOptions {
policy?: string | object | Array<object | string>;
reportOnly?: boolean;
reportUri?: string;
styleNonce?: boolean;
scriptNonce?: boolean;
}
interface hstsOptions {
maxAge?: number;
includeSubDomains?: boolean;
preload?: boolean;
}
type csrfOptions = csrfOptionsAngular | csrfOptionsNonAngular;
interface csrfOptionsAngular {
key?: string;
secret?: string;
impl?: () => any;
cookie?: string | {
options?: object;
};
angular: true;
}
interface csrfOptionsNonAngular {
key?: string;
secret?: string;
impl?: () => any;
cookie?: string | {
name: string;
options?: object;
};
angular?: false;
}
interface xssProtectionOptions {
enabled?: boolean;
mode?: string;
}
function csrf(options?: csrfOptions): express.RequestHandler;
function csp(options?: cspOptions): express.RequestHandler;
function xframe(value: string): express.RequestHandler;
function p3p(value: string): express.RequestHandler;
function hsts(options?: hstsOptions): express.RequestHandler;
function xssProtection(options?: xssProtectionOptions | true): express.RequestHandler;
function nosniff(): express.RequestHandler;
function referrerPolicy(value: string): express.RequestHandler;
}
export = lusca;
+24
View File
@@ -0,0 +1,24 @@
import express = require('express');
import lusca = require('lusca');
const app = express();
app.use(lusca({
csrf: true,
csp: { policy: "referrer no-referrer"},
xframe: 'SAMEORIGIN',
p3p: 'ABCDEF',
hsts: {maxAge: 31536000, includeSubDomains: true, preload: true},
xssProtection: true,
nosniff: true,
referrerPolicy: 'same-origin'
}));
app.use(lusca.csrf());
app.use(lusca.csp({policy: [{ "img-src": "'self' http:" }, "block-all-mixed-content"], reportOnly: false}));
app.use(lusca.xframe('SAMEORIGIN'));
app.use(lusca.p3p('ABCDEF'));
app.use(lusca.hsts({ maxAge: 31536000 }));
app.use(lusca.xssProtection(true));
app.use(lusca.nosniff());
app.use(lusca.referrerPolicy('same-origin'));
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"lusca-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }