@ministryofjustice/hmpps-probation-frontend-components 1.0.0-beta.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -39
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# hmpps-probation-components
|
|
1
|
+
# hmpps-probation-frontend-components
|
|
2
2
|
|
|
3
|
-
`hmpps-probation-components` is a Node.js client library to simplify the process of incorporating global components
|
|
4
|
-
within PDS applications. We welcome feedback on this
|
|
3
|
+
`hmpps-probation-frontend-components` is a Node.js client library to simplify the process of incorporating global components
|
|
4
|
+
within PDS applications. We welcome feedback on this Slack channel [here](https://moj.enterprise.slack.com/archives/C08RXCS63TM)
|
|
5
5
|
in order to improve it.
|
|
6
6
|
|
|
7
7
|
## Contents
|
|
@@ -16,9 +16,11 @@ in order to improve it.
|
|
|
16
16
|
|
|
17
17
|
The package assumes adherance to the standard [hmpps-template-typescript](https://github.com/ministryofjustice/hmpps-template-typescript) project.
|
|
18
18
|
It requires:
|
|
19
|
-
- a user object to be available on `res.locals` containing a token
|
|
19
|
+
- a user object to be available on `res.locals` containing a token and displayName.
|
|
20
20
|
- nunjucks to be setup
|
|
21
|
-
-
|
|
21
|
+
- the environment variable `COMPONENT_API_URL` to be set for each environment
|
|
22
|
+
- the environment variables `AUTH_CODE_CLIENT_ID` and `AUTH_CODE_CLIENT_SECRET` to be set to allow authenticating with the dev environment locally
|
|
23
|
+
- the environment variable `HMPPS_AUTH_URL` to be set to `https://sign-in-dev.hmpps.service.justice.gov.uk/auth` to authenticate with the dev environment locally
|
|
22
24
|
- to be run AFTER helmet middleware
|
|
23
25
|
|
|
24
26
|
### Installation
|
|
@@ -26,25 +28,47 @@ It requires:
|
|
|
26
28
|
To install the package, run the following command:
|
|
27
29
|
|
|
28
30
|
```bash
|
|
29
|
-
npm install @ministryofjustice/hmpps-probation-components
|
|
31
|
+
npm install @ministryofjustice/hmpps-probation-frontend-components
|
|
30
32
|
```
|
|
31
33
|
|
|
32
34
|
### Usage
|
|
33
35
|
|
|
36
|
+
Add environment variables to the `helm_deploy/values-{env}.yaml` files for `COMPONENT_API_URL`. Populate with the following values:
|
|
37
|
+
|
|
38
|
+
dev - https://probation-frontend-components-dev.hmpps.service.justice.gov.uk
|
|
39
|
+
|
|
40
|
+
preprod - https://probation-frontend-components-preprod.hmpps.service.justice.gov.uk
|
|
41
|
+
|
|
42
|
+
prod - https://probation-frontend-components.hmpps.service.justice.gov.uk
|
|
43
|
+
|
|
44
|
+
You can also add this to your `.env` or `docker-compose` files with the dev url, as follows:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
- COMPONENT_API_URL=https://probation-frontend-components-dev.hmpps.service.justice.gov.uk
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Add a block for the component library in the `apis` section of `server/config.ts`, for example:
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
probationApi: {
|
|
54
|
+
url: get('COMPONENT_API_URL', 'https://probation-frontend-components-dev.hmpps.service.justice.gov.uk', requiredInProduction),
|
|
55
|
+
healthPath: '/health/ping'
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
34
59
|
Currently, the package provides the header and the footer component.
|
|
35
60
|
|
|
36
|
-
To incorporate use the middleware for appropriate routes within your Express application:
|
|
61
|
+
To incorporate use the middleware for appropriate routes within your Express application (after the `setUpCurrentUser` middleware):
|
|
37
62
|
|
|
38
63
|
```javascript
|
|
39
|
-
import pdsComponents from '@ministryofjustice/hmpps-probation-components'
|
|
64
|
+
import pdsComponents from '@ministryofjustice/hmpps-probation-frontend-components'
|
|
40
65
|
|
|
41
66
|
...
|
|
42
67
|
|
|
43
68
|
app.use(pdsComponents.getPageComponents({
|
|
44
|
-
pdsUrl: config.
|
|
69
|
+
pdsUrl: config.apis.probationApi.url,
|
|
45
70
|
logger,
|
|
46
|
-
})
|
|
47
|
-
)
|
|
71
|
+
}))
|
|
48
72
|
```
|
|
49
73
|
|
|
50
74
|
**However, please 🙏 consider carefully whether you need the components for EVERY request.**
|
|
@@ -53,34 +77,13 @@ It may be sufficient for you app to only request components for GET requests for
|
|
|
53
77
|
|
|
54
78
|
```javascript
|
|
55
79
|
app.get('*', pdsComponents.getPageComponents({
|
|
56
|
-
pdsUrl: config.
|
|
80
|
+
pdsUrl: config.apis.probationApi.url,
|
|
57
81
|
logger,
|
|
58
82
|
})
|
|
59
83
|
)
|
|
60
84
|
```
|
|
61
85
|
|
|
62
|
-
|
|
63
|
-
handle form submission. This will help us to reduce the load on the micro frontend components API. You may wish to
|
|
64
|
-
go even further, for example avoiding routes that don't need components - the Prisoner Profile does
|
|
65
|
-
something like this to avoid the component API call for the following routes: `/api` (provides prisoner images) and `/`
|
|
66
|
-
(a redirect only route).
|
|
67
|
-
|
|
68
|
-
```javascript
|
|
69
|
-
app.get(
|
|
70
|
-
/^(?!\/api|^\/$).*/,
|
|
71
|
-
pdsComponents.getPageComponents({
|
|
72
|
-
pdsUrl: config.serviceUrls.digitalProbation,
|
|
73
|
-
logger,
|
|
74
|
-
}),
|
|
75
|
-
(req, res) => {
|
|
76
|
-
res.render('probationProfile')
|
|
77
|
-
},
|
|
78
|
-
)
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
There are a [number of options](./src/index.ts) available depending on your requirements.
|
|
82
|
-
|
|
83
|
-
Add the `hmpps-probation-components` path to the nunjucksSetup.ts file to enable css to be loaded:
|
|
86
|
+
Add the `hmpps-probation-frontend-components` path to the nunjucksSetup.ts file to enable css to be loaded:
|
|
84
87
|
|
|
85
88
|
```javascript
|
|
86
89
|
const njkEnv = nunjucks.configure(
|
|
@@ -90,7 +93,7 @@ Add the `hmpps-probation-components` path to the nunjucksSetup.ts file to enable
|
|
|
90
93
|
'node_modules/govuk-frontend/dist/components/',
|
|
91
94
|
'node_modules/@ministryofjustice/frontend/',
|
|
92
95
|
'node_modules/@ministryofjustice/frontend/moj/components/',
|
|
93
|
-
'node_modules/@ministryofjustice/hmpps-probation-components/dist/assets/',
|
|
96
|
+
'node_modules/@ministryofjustice/hmpps-probation-frontend-components/dist/assets/',
|
|
94
97
|
],
|
|
95
98
|
{
|
|
96
99
|
autoescape: true,
|
|
@@ -99,10 +102,10 @@ Add the `hmpps-probation-components` path to the nunjucksSetup.ts file to enable
|
|
|
99
102
|
)
|
|
100
103
|
```
|
|
101
104
|
|
|
102
|
-
Include the package scss within the
|
|
105
|
+
Include the package scss within the `index.scss` file
|
|
103
106
|
```scss
|
|
104
|
-
@import 'node_modules/@ministryofjustice/hmpps-probation-components/dist/assets/footer';
|
|
105
|
-
@import 'node_modules/@ministryofjustice/hmpps-probation-components/dist/assets/header';
|
|
107
|
+
@import 'node_modules/@ministryofjustice/hmpps-probation-frontend-components/dist/assets/footer';
|
|
108
|
+
@import 'node_modules/@ministryofjustice/hmpps-probation-frontend-components/dist/assets/header';
|
|
106
109
|
```
|
|
107
110
|
|
|
108
111
|
Include reference to the components in your layout.njk file:
|
|
@@ -143,7 +146,7 @@ of routes. e.g. in `setUpAuthentication.ts` on the `/autherror` path:
|
|
|
143
146
|
)
|
|
144
147
|
```
|
|
145
148
|
|
|
146
|
-
This will provide a stripped down header
|
|
149
|
+
This will provide a stripped down header if there is no user object on `res.locals`.
|
|
147
150
|
|
|
148
151
|
### CSP
|
|
149
152
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ministryofjustice/hmpps-probation-frontend-components",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A package to allow the inclusion of connect pds micro frontend components within pds applications",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|