npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ministryofjustice/hmpps-connect-dps-components

v1.3.1

Published

A package to allow the inclusion of connect dps micro frontend components within dps applications

Downloads

1,753

Readme

hmpps-connect-dps-components

hmpps-connect-dps-components is a Node.js client library to simplify the process of incorporating global components within DPS applications.

Contents

  1. Publishing to NPM

Implementation

Prerequisites

The package assumes adherance to the standard hmpps-template-typescript project. It requires:

  • a user object to be available on res.locals containing a token, displayName, and authSource.
  • nunjucks to be setup
  • an environment variable to be set for the micro frontend components api called COMPONENT_API_URL
  • to be run after helmet middleware

Installation

To install the package, run the following command:

npm install @ministryofjustice/hmpps-connect-dps-components

Usage

Currently, the package provides the header and the footer component.

To incorporate use as middleware for appropriate routes within your Express application:

    app.get('*', dpsComponents.get({
      dpsUrl: config.serviceUrls.digitalPrison,
    })
  )

There are a number of options available depending on your requirements.

Add the hmpps-connect-dps-components path to the nunjucksSetup.ts file to enable css to be loaded:

    const njkEnv = nunjucks.configure(
  [
    path.join(__dirname, '../../server/views'),
    'node_modules/govuk-frontend/dist/',
    'node_modules/govuk-frontend/dist/components/',
    'node_modules/@ministryofjustice/frontend/',
    'node_modules/@ministryofjustice/frontend/moj/components/',
    'node_modules/@ministryofjustice/hmpps-connect-dps-components/dist/assets/',
  ],
  {
    autoescape: true,
    express: app,
  },
)

Include the package scss within the all.scss file

  @import 'node_modules/@ministryofjustice/hmpps-connect-dps-components/dist/assets/footer';
  @import 'node_modules/@ministryofjustice/hmpps-connect-dps-components/dist/assets/header-bar';

Include reference to the components in your layout.njk file:

{% for js in feComponents.jsIncludes %}
    <script src="{{ js }}" nonce="{{ cspNonce }}"></script>
{% endfor %}

{% for css in feComponents.cssIncludes %}
    <link href="{{ css }}" nonce="{{ cspNonce }}" rel="stylesheet" />
{% endfor %}
{% block header %}
  {{ feComponents.header | safe }}
{% endblock %}
{% block footer %}
    {{ feComponents.footer | safe }}
{% endblock %}

Extra calls

It may be that you need to add some extra requests for the page components for pages that do not fit the normal flow of routes. e.g. in setUpAuthentication.ts on the /autherror path:

     router.get(
      '/autherror',
      dpsComponents.getPageComponents({ dpsUrl: config.serviceUrls.digitalPrison }),
      (req, res) => {
        res.status(401)
        return res.render('autherror')
      },
  )

This will provide a stripped down header for if there is no user object on res.locals.

CSP

The package updates the content-security-middleware to include references to the fe-components API. This package should be run after Helmet to prevent this being overwritten.

Metadata

An optional parameter includeMeta: true can be passed into the get method. Setting this will result in a feComponentsMeta beind added to res.locals containing data the components have collected to render. This includes:

  • activeCaseLoad (the active caseload of the user)
  • caseLoads (all caseloads the user has access to)
  • services (information on services the user has access to used for global navigation)

This can be useful e.g. for when your service needs access to activeCaseLoad information to prevent extra calls to the api and takes advantage of the caching that the micro frontend api does.

Note

In the event of a failure to retrieve the components, the package will populate the html fields with fallback components. However, feComponentsMeta will not be populated. If you rely on the data from the micro frontend api, you should handle the data not being present within your application.