From c667787ed9211b7ce2718dc982b340c50375bd50 Mon Sep 17 00:00:00 2001 From: Dylan Tackoor Date: Wed, 15 Sep 2021 22:19:04 -0400 Subject: [PATCH] Export more interfaces Adds `Secret` and `UnlessOptions` interfaces, and reuses `Secret` in `SecretLoader`. Made these changes because I'd like to do something like this: ```ts import jwt, { Options, UnlessOptions } from 'koa-jwt' const jwtOptions: Options = { secret: 'its', key: 'a', algorithms: ['me'], cookie: 'mario', passthrough: true, } const jwtAllowList: UnlessOptions = { path: ['/ping'] } export const jwtMiddleware = jwt(jwtOptions).unless(jwtAllowList) ``` --- types/index.d.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 4e55d7f..e6c77d5 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -11,7 +11,7 @@ declare function jwt(options: jwt.Options): jwt.Middleware; declare namespace jwt { export interface Options { - secret: string | string[] | Buffer | Buffer[] | SecretLoader; + secret: Secret | SecretLoader; key?: string; tokenKey?: string; getToken?(ctx: Koa.Context, opts: jwt.Options): string | null; @@ -24,9 +24,11 @@ declare namespace jwt { algorithms?: string[]; } - export type SecretLoader = (header: any, payload: any) => Promise; + export type Secret = string | string[] | Buffer | Buffer[]; + export type SecretLoader = (header: any, payload: any) => Promise; + export type UnlessOptions = (params?: {custom?: (ctx: Koa.Context) => boolean, path?: string | RegExp | (string | RegExp)[], ext?: string | string[], method?: string | string[]}) => Koa.Middleware export interface Middleware extends Koa.Middleware { - unless(params?: {custom?: (ctx: Koa.Context) => boolean, path?: string | RegExp | (string | RegExp)[], ext?: string | string[], method?: string | string[]}): Koa.Middleware; + unless: UnlessOptions; } }