UNPKG

@ne1410s/xprest

Version:
46 lines (45 loc) 2.26 kB
import { Xprest } from './xprest'; import { JwtIssuer } from '../security/jwt-issuer'; import { JwtToken } from '../security/jwt-token'; import { Mdw, PassiveMdw } from './middleware'; export declare class XprestSecure extends Xprest { private readonly jwtIssuer; constructor(jwtIssuer: JwtIssuer); /** * Specifies a (secure) static file resource. * @param apiRoute The api route. * @param localPath The file path, relative to the cwd. */ resourceSecure<TReq>(apiRoute: string, localPath: string, roles: string[], mdwPre?: PassiveMdw<TReq>[], mdwPost?: PassiveMdw<TReq>[]): void; /** * Specifies a (secure) dynamic file resource. * @param apiRoute The api route. * @param localPath The file path, relative to the cwd. * @param variables Exposed in the rendering of the file. For example: * <%= new Date().getTime() * myVar.myProp %> */ renderSecure<TReq>(apiRoute: string, localPath: string, variables: object, roles: string[], mdwPre?: PassiveMdw<TReq>[], mdwPost?: PassiveMdw<TReq>[]): void; /** * Specifies a (secure) streamable resource; e.g. video. * @param apiRoute The api route. * @param localPath The file path, relative to the cwd. * @param mime The mime type. */ streamSecure<TReq>(apiRoute: string, localPath: string, mime: string, roles: string[], mdwPre?: PassiveMdw<TReq>[]): void; /** * Specifies a (secure) restful api endpoint. * @param apiRoute The api route. * @param verb The verb. * @param handler Handles requests. */ endpointSecure<TReq, TRes>(apiRoute: string, verb: 'post' | 'get' | 'patch' | 'delete' | 'put', roles: string[], ...handlers: Mdw<TReq, TRes>[]): void; /** * Specifies a route at which to listen for POST login requests and a function * to dictate behaviour. For valid login attempts, return a payload object - * in accordance with the user. Subject (sub) and roles (rol) are suggested. * For invalid attempts, a null payload must be returned. */ authenticate<TReq>(apiRoute: string, payloadFn: (req: TReq) => JwtToken, mdwPre?: PassiveMdw<TReq>[], mdwPost?: PassiveMdw<TReq>[]): void; private mdw_IssueToken; private mdw_CheckRole; }