forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤖 Merge PR DefinitelyTyped#61072 Update types for koa-csrf v5.0 by @k…
…irillshvets97
- Loading branch information
1 parent
59bf2ca
commit 14e9784
Showing
2 changed files
with
32 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,40 @@ | ||
// Type definitions for koa-csrf 3.0 | ||
// Type definitions for koa-csrf 5.0 | ||
// Project: https://github.com/koajs/csrf | ||
// Definitions by: Haskaalo <https://github.com/haskaalo> | ||
// Kirill Shvets <https://github.com/kirillshvets97> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 2.3 | ||
|
||
/* =================== USAGE =================== | ||
import * as koaCsrf from 'koa-csrf'; | ||
import * as CSRF from "koa-csrf"; | ||
import * as Koa from "koa"; | ||
const app = new Koa(); | ||
app.use(new koaCsrf({ | ||
invalidSessionSecretMessage: 'Invalid session secret', | ||
invalidSessionSecretStatusCode: 403, | ||
invalidTokenMessage: 'Invalid CSRF token', | ||
invalidTokenStatusCode: 403, | ||
excludedMethods: [ 'GET', 'HEAD', 'OPTIONS' ], | ||
disableQuery: false | ||
app.use(new CSRF({ | ||
errorHandler(ctx) { | ||
return ctx.throw(403, 'Invalid CSRF token'); | ||
}, | ||
excludedMethods: ['GET', 'HEAD', 'OPTIONS'], | ||
disableQuery: false, | ||
ignoredPathGlobs: [] | ||
})); | ||
=============================================== */ | ||
|
||
export = koaCsrf; | ||
export = CSRF; | ||
|
||
import { Middleware } from 'koa'; | ||
import { Context, Middleware } from 'koa'; | ||
|
||
declare module "koa" { | ||
interface Context { | ||
csrf: string; | ||
declare module 'koa' { | ||
interface DefaultState { | ||
_csrf: string; | ||
} | ||
} | ||
|
||
declare const koaCsrf: { | ||
declare const CSRF: { | ||
new (opts?: { | ||
invalidSessionSecretMessage?: string | undefined; | ||
invalidSessionSecretStatusCode?: number | undefined; | ||
invalidTokenMessage?: string | undefined; | ||
invalidTokenStatusCode?: number | undefined; | ||
excludedMethods?: string[] | undefined; | ||
disableQuery?: boolean | undefined; | ||
errorHandler?: (ctx: Context) => never; | ||
excludedMethods?: string[]; | ||
disableQuery?: boolean; | ||
ignoredPathGlobs?: string[]; | ||
}): Middleware; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import koaCsrf = require("koa-csrf"); | ||
import Koa = require("koa"); | ||
import CSRF = require('koa-csrf'); | ||
import Koa = require('koa'); | ||
const app = new Koa(); | ||
|
||
app.use(new koaCsrf({ | ||
invalidSessionSecretMessage: 'Invalid session secret', | ||
invalidSessionSecretStatusCode: 403, | ||
invalidTokenMessage: 'Invalid CSRF token', | ||
invalidTokenStatusCode: 403, | ||
excludedMethods: [ 'GET', 'HEAD', 'OPTIONS' ], | ||
disableQuery: false | ||
})); | ||
app.use( | ||
new CSRF({ | ||
errorHandler(ctx) { | ||
return ctx.throw(403, 'Invalid CSRF token'); | ||
}, | ||
excludedMethods: ['GET', 'HEAD', 'OPTIONS'], | ||
disableQuery: false, | ||
ignoredPathGlobs: [], | ||
}), | ||
); |