Skip to main content

Class: RouteUtils

Defined in: service-core/src/routes/RouteUtils.ts:23

Provides a set of utilities for converting Route classes to HTTP middleware.

Constructors

Constructor

new RouteUtils(): RouteUtils

Returns

RouteUtils

Properties

trustedRoles

protected trustedRoles: string[]

Defined in: service-core/src/routes/RouteUtils.ts:37

Methods

checkElevation()

checkElevation(lastStart?): RequestHandler

Defined in: service-core/src/routes/RouteUtils.ts:43

Creates a middleware function that checks if the user has elevated privileges and if not throws the AUTH_REQUIRES_ELEVATION error.

Parameters

lastStart?

number = -1

Returns

RequestHandler


checkRequiredPerms()

checkRequiredPerms(aclUid): RequestHandler

Defined in: service-core/src/routes/RouteUtils.ts:73

Creates a middleware function that verifies the incoming request is from a valid user with at least one of the specified roles.

Parameters

aclUid

string

Returns

RequestHandler


checkRequiredRoles()

checkRequiredRoles(requiredRoles): RequestHandler

Defined in: service-core/src/routes/RouteUtils.ts:100

Creates a middleware function that verifies the incoming request is from a valid user with at least one of the specified roles.

Parameters

requiredRoles

string[]

The list of roles that the authenticated user must have.

Returns

RequestHandler


checkRequiredScopes()

checkRequiredScopes(requiredScopes): RequestHandler

Defined in: service-core/src/routes/RouteUtils.ts:145

Creates a middleware function that verifies the incoming request's token carries at least one of the specified scopes. This is a coarse, token-level pre-check that runs before the per-resource ACL check — see RequiresScope.

Parameters

requiredScopes

string[]

The list of scopes of which the authenticated user's token must carry at least one.

Returns

RequestHandler


checkTrusedRoles()

checkTrusedRoles(): RequestHandler

Defined in: service-core/src/routes/RouteUtils.ts:121

Creates a middleware function that verifies the incoming request is from a valid user with at least one of the trusted roles.

Returns

RequestHandler


getFuncArray()

getFuncArray(route, funcs, send?): RequestHandler[]

Defined in: service-core/src/routes/RouteUtils.ts:172

Converts the given array of string or Function objects to functions bound to the given route object.

Parameters

route

any

The route object that the list of functions is bound to.

funcs

(string | Function)[]

The array of functions (or function names) to return.

send?

boolean = false

Set to true to have the last wrapped function send its payload to the client.

Returns

RequestHandler[]

An array of Function objects mapping to the route object.


getRouteMethods()

getRouteMethods(route): Map<string, any>

Defined in: service-core/src/routes/RouteUtils.ts:195

Searches an route object for any functions that implement a @Method decorator.

Parameters

route

any

The route object to search.

Returns

Map<string, any>

The list of @Method decorated functions that were found.


registerRoute()

registerRoute(app, route): Promise<void>

Defined in: service-core/src/routes/RouteUtils.ts:224

Registers the provided route object containing a set of decorated endpoints to the server.

Parameters

app

any

The HTTP application/router to register the route to.

route

any

The route object to register.

Returns

Promise<void>


wrapMiddleware()

wrapMiddleware(obj, func, send?): RequestHandler

Defined in: service-core/src/routes/RouteUtils.ts:433

Wraps the provided function with HTTP handling based on the function's defined decorators.

Parameters

obj

any

The bound object whose middleware function will be wrapped.

func

Function

The decorated function to wrap.

send?

boolean = false

Set to true to have func's result sent to the client.

Returns

RequestHandler