Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#61072 Update types for koa-csrf v5.0 by @k…
Browse files Browse the repository at this point in the history
…irillshvets97
  • Loading branch information
kirillshvets authored Aug 17, 2022
1 parent 59bf2ca commit 14e9784
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
41 changes: 20 additions & 21 deletions types/koa-csrf/index.d.ts
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;
};
22 changes: 12 additions & 10 deletions types/koa-csrf/koa-csrf-tests.ts
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: [],
}),
);

0 comments on commit 14e9784

Please sign in to comment.