exframe-middleware

Exframe Middleware ===

Usage no npm install needed!

<script type="module">
  import exframeMiddleware from 'https://cdn.skypack.dev/exframe-middleware';
</script>

README

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)
  )