exframe-middleware

1.5.4 • Public • Published

Exframe Middleware

This module aims to provide a singular repo of commonly used middleware functions for Express apps and RabbitMQ rpc apps

Functions

authorizeUser

Checks for the user object and throws an Unauthorized error if it doesn't exist

buildCspFromMessage

builds the csp object from the message containing companyCode, state, and product on the top most level

buildExpressRequestContext

builds the request context for express, acquiring the requestId, accessToken, log, and user objects into the context object within the request

handleErrors

error handler middleware for mq and express, it handles thrown errors and reports their status and message

  const { handleErrors } = require('exframe-middleware');

  // express instance
  app.use(handleErrors().express);

  // exframe-mq instance
  client.use(handleErrors().mq);

standardRouteResponseBuilder

builds the response object based on input and if single or multi response

example from in production

  subscribe(
    'startBoBTransfers',
    validateRequestRPC(schemas.startBoBTransfer),
    (context, message) => startBoBTransfer.start(context, message).then(standardRouteResponseBuilder.singleItem)
  )

Readme

Keywords

none

Package Sidebar

Install

npm i exframe-middleware

Weekly Downloads

358

Version

1.5.4

License

ISC

Unpacked Size

25.8 kB

Total Files

18

Last publish

Collaborators

  • exzeo_usa
  • exzeodevops