fix typings and add fastify dependency

This commit is contained in:
Jannik Keye
2018-09-24 22:09:51 +02:00
parent 9321b48329
commit 7536b1c7d8
3 changed files with 30 additions and 15 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
import { IncomingMessage, Server, ServerResponse } from "http";
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify-jwt";
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
const fastify: FastifyInstance<Server, IncomingMessage, ServerResponse> = {
jwt: {
+23 -14
View File
@@ -3,24 +3,33 @@
// Definitions by: My Self <https://github.com/jannikkeye>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import fastify = require("fastify");
import { Secret, SignOptions, VerifyOptions, VerifyCallback, SignCallback, DecodeOptions } from 'jsonwebtoken';
export interface FastifyInstance<HttpServer, HttpRequest, HttpResponse> {
jwt: jwt;
declare module "fastify" {
interface FastifyInstance<HttpServer, HttpRequest, HttpResponse> {
jwt: jwt;
}
interface jwt {
sign: (payload: any, options?: SignOptions, callback?: SignCallback) => void;
verify: (token: string, options?: VerifyOptions, callback?: VerifyCallback) => void;
decode: (token: string, options?: DecodeOptions) => null | { [key: string]: any } | string;
secret: Secret;
}
interface FastifyRequest<HttpRequest> {
jwtVerify: (options?: VerifyOptions | VerifyCallback, next?: VerifyCallback) => Promise<null | { [key: string]: any } | string> | null | { [key: string]: any } | string;
}
interface FastifyReply<HttpResponse> {
jwtSign: (payload: any, options?: SignOptions | SignCallback, next?: SignCallback) => void;
}
}
export interface jwt {
sign: (payload: any, options?: SignOptions, callback?: SignCallback) => void;
verify: (token: string, options?: VerifyOptions, callback?: VerifyCallback) => void;
decode: (token: string, options?: DecodeOptions) => null | { [key: string]: any } | string;
secret: Secret;
}
declare function fastifyJwt (): void;
export interface FastifyRequest<HttpRequest> {
jwtVerify: (options?: VerifyOptions | VerifyCallback, next?: VerifyCallback) => Promise<null | { [key: string]: any } | string> | null | { [key: string]: any } | string;
}
declare namespace fastifyJwt {}
export interface FastifyReply<HttpResponse> {
jwtSign: (payload: any, options?: SignOptions | SignCallback, next?: SignCallback) => void;
}
export = fastifyJwt;
+6
View File
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"fastify": "^1.11.2"
}
}