Fix hapi-auth-jwt2 and hapi-decorators

Remove redundant `export`s inside hapi-auth-jw2 and remove repeated hapi
definitions in hapi-decorators
This commit is contained in:
Alexander James Phillips
2017-05-07 21:16:40 +01:00
parent 02389001d7
commit 92c0981ea3
3 changed files with 15 additions and 66 deletions

View File

@@ -11,7 +11,7 @@ declare namespace hapiAuthJwt2 {
* @param decoded the *decoded* but *unverified* JWT received from client
* @param callback the key lookup callback
*/
export type KeyLookup = (decoded: any, callback: KeyLookupCallback) => void;
type KeyLookup = (decoded: any, callback: KeyLookupCallback) => void;
/**
* Called when key lookup function has completed
@@ -22,7 +22,7 @@ declare namespace hapiAuthJwt2 {
* to use in `validateFunc` which can be accessed via
* `request.plugins['hapi-auth-jwt2'].extraInfo`
*/
export type KeyLookupCallback = (err: any, key: string, extraInfo?: any) => void;
type KeyLookupCallback = (err: any, key: string, extraInfo?: any) => void;
/**
* Called when Validation has completed
@@ -31,12 +31,12 @@ declare namespace hapiAuthJwt2 {
* @param valid `true` if the JWT was valid, otherwise `false`
* @param credentials alternative credentials to be set instead of `decoded`
*/
export type ValidateCallback = (err: any, valid: boolean, credentials?: any) => void;
type ValidateCallback = (err: any, valid: boolean, credentials?: any) => void;
/**
* Options passed to `hapi.auth.strategy` when this plugin is used
*/
export interface Options {
interface Options {
/**
* The secret key used to check the signature of the token *or* a *key lookup function*
*/

View File

@@ -4,7 +4,7 @@ import { controller, get, post, put, cache, config, route, validate, Controller
@controller('/test')
class TestController implements Controller {
baseUrl: string;
routes: () => hapi.IRouteConfiguration[];
routes: () => hapi.RouteConfiguration[];
@get('/')
@config({
@@ -16,22 +16,22 @@ class TestController implements Controller {
@validate({
payload: false
})
getHandler(request: hapi.Request, reply: hapi.IReply) {
getHandler(request: hapi.Request, reply: hapi.ReplyNoContinue) {
reply({ success: true });
}
@post('/')
postHandler(request: hapi.Request, reply: hapi.IReply) {
postHandler(request: hapi.Request, reply: hapi.ReplyNoContinue) {
reply({ success: true });
}
@put('/{id}')
putHandler(request: hapi.Request, reply: hapi.IReply) {
putHandler(request: hapi.Request, reply: hapi.ReplyNoContinue) {
reply({ success: true });
}
@route('delete', '/{id}')
deleteHandler(request: hapi.Request, reply: hapi.IReply) {
deleteHandler(request: hapi.Request, reply: hapi.ReplyNoContinue) {
reply({ success: true });
}
}
@@ -50,7 +50,7 @@ class SimpleTestController implements Controller {
}
baseUrl: string;
routes: () => hapi.IRouteConfiguration[];
routes: () => hapi.RouteConfiguration[];
}
server.route(new SimpleTestController('bar').routes());

View File

@@ -4,12 +4,13 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import * as hapi from 'hapi';
import * as Joi from 'joi';
interface ControllerStatic {
new (...args: any[]): Controller;
}
export interface Controller {
baseUrl: string;
routes: () => hapi.IRouteConfiguration[];
routes: () => hapi.RouteConfiguration[];
}
export function controller(baseUrl: string): (target: ControllerStatic) => void;
interface IRouteSetup {
@@ -28,61 +29,9 @@ export const put: IRouteConfig;
// export const delete: IRouteConfig;
export const patch: IRouteConfig;
export const all: IRouteConfig;
export function config(config: hapi.IRouteAdditionalConfigurationOptions): (target: any, key: any, descriptor: any) => any;
interface IValidateConfig {
/** validation rules for incoming request headers.Values allowed:
* trueany headers allowed (no validation performed).This is the default.
falseno headers allowed (this will cause all valid HTTP requests to fail).
a Joi validation object.
a validation function using the signature function(value, options, next) where:
valuethe object containing the request headers.
optionsthe server validation options.
next(err, value)the callback function called when validation is completed.
*/
headers?: boolean | hapi.IJoi | hapi.IValidationFunction;
/** validation rules for incoming request path parameters, after matching the path against the route and extracting any parameters then stored in request.params.Values allowed:
trueany path parameters allowed (no validation performed).This is the default.
falseno path variables allowed.
a Joi validation object.
a validation function using the signature function(value, options, next) where:
valuethe object containing the path parameters.
optionsthe server validation options.
next(err, value)the callback function called when validation is completed. */
params?: boolean | hapi.IJoi | hapi.IValidationFunction;
/** validation rules for an incoming request URI query component (the key- value part of the URI between '?' and '#').The query is parsed into its individual key- value pairs (using the qs module) and stored in request.query prior to validation.Values allowed:
trueany query parameters allowed (no validation performed).This is the default.
falseno query parameters allowed.
a Joi validation object.
a validation function using the signature function(value, options, next) where:
valuethe object containing the query parameters.
optionsthe server validation options.
next(err, value)the callback function called when validation is completed. */
query?: boolean | hapi.IJoi | hapi.IValidationFunction;
/** validation rules for an incoming request payload (request body).Values allowed:
trueany payload allowed (no validation performed).This is the default.
falseno payload allowed.
a Joi validation object.
a validation function using the signature function(value, options, next) where:
valuethe object containing the payload object.
optionsthe server validation options.
next(err, value)the callback function called when validation is completed. */
payload?: boolean | hapi.IJoi | hapi.IValidationFunction;
/** an optional object with error fields copied into every validation error response. */
errorFields?: any;
/** determines how to handle invalid requests.Allowed values are:
'error'return a Bad Request (400) error response.This is the default value.
'log'log the error but continue processing the request.
'ignore'take no action.
OR a custom error handler function with the signature 'function(request, reply, source, error)` where:
requestthe request object.
replythe continuation reply interface.
sourcethe source of the invalid field (e.g. 'path', 'query', 'payload').
errorthe error object prepared for the client response (including the validation function error under error.data). */
failAction?: string | hapi.IRouteFailFunction;
/** options to pass to Joi.Useful to set global options such as stripUnknown or abortEarly (the complete list is available here: https://github.com/hapijs/joi#validatevalue-schema-options-callback ).Defaults to no options. */
options?: any;
}
export function validate(config: IValidateConfig): (target: any, key: any, descriptor: any) => any;
export function config(config: hapi.RouteAdditionalConfigurationOptions): (target: any, key: any, descriptor: any) => any;
export function validate(config: hapi.RouteValidationConfigurationObject): (target: any, key: any, descriptor: any) => any;
interface ICacheConfig {
privacy?: string;
expiresIn?: number;