@ministryofjustice/hmpps-connect-dps-components 5.1.1 → 5.2.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 +19 -16
- package/dist/index.d.ts +7 -7
- package/package.json +25 -22
- package/scripts/patch.diff +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# hmpps-connect-dps-components
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://operations-engineering-reports.cloud-platform.service.justice.gov.uk/public-report/hmpps-connect-dps-components "Link to report")
|
|
4
|
+
[](https://github.com/ministryofjustice/hmpps-connect-dps-components/actions/workflows/pipeline.yml)
|
|
5
|
+
|
|
6
|
+
`hmpps-connect-dps-components` is a Node.js client library to simplify the process of incorporating global components
|
|
4
7
|
within DPS applications. We welcome feedback on this README [here](https://moj.enterprise.slack.com/archives/C04JFG3QJE6)
|
|
5
8
|
in order to improve it.
|
|
6
9
|
|
|
@@ -84,7 +87,7 @@ It may be sufficient for you app to only request components for GET requests for
|
|
|
84
87
|
may be more appropriate, especially if you use the [PRG pattern](https://en.wikipedia.org/wiki/Post/Redirect/Get) to
|
|
85
88
|
handle form submission. This will help us to reduce the load on the micro frontend components API. You may wish to
|
|
86
89
|
go even further, for example avoiding routes that don't need components - the Prisoner Profile does
|
|
87
|
-
something like this to avoid the component API call for the following routes: `/api` (provides prisoner images) and `/`
|
|
90
|
+
something like this to avoid the component API call for the following routes: `/api` (provides prisoner images) and `/`
|
|
88
91
|
(a redirect only route).
|
|
89
92
|
|
|
90
93
|
```javascript
|
|
@@ -152,7 +155,7 @@ Include reference to the components in your layout.njk file:
|
|
|
152
155
|
|
|
153
156
|
### Extra calls
|
|
154
157
|
|
|
155
|
-
It may be that you need to add some extra requests for the page components for pages that do not fit the normal flow
|
|
158
|
+
It may be that you need to add some extra requests for the page components for pages that do not fit the normal flow
|
|
156
159
|
of routes. e.g. in `setUpAuthentication.ts` on the `/autherror` path:
|
|
157
160
|
|
|
158
161
|
```javascript
|
|
@@ -175,13 +178,13 @@ This will provide a stripped down header for if there is no user object on `res.
|
|
|
175
178
|
|
|
176
179
|
### CSP
|
|
177
180
|
|
|
178
|
-
The package updates the content-security-middleware to include references to the fe-components API. This package should
|
|
181
|
+
The package updates the content-security-middleware to include references to the fe-components API. This package should
|
|
179
182
|
be run after Helmet to prevent this being overwritten.
|
|
180
183
|
|
|
181
|
-
### Shared Data
|
|
184
|
+
### Shared Data
|
|
182
185
|
|
|
183
|
-
An optional parameter `includeSharedData: true` can be passed into the `get` methods request options. Setting this will result in a
|
|
184
|
-
`sharedData` object being added to `res.locals.feComponents` containing data the components have collected to render.
|
|
186
|
+
An optional parameter `includeSharedData: true` can be passed into the `get` methods request options. Setting this will result in a
|
|
187
|
+
`sharedData` object being added to `res.locals.feComponents` containing data the components have collected to render.
|
|
185
188
|
This includes:
|
|
186
189
|
|
|
187
190
|
- activeCaseLoad (the active caseload of the user)
|
|
@@ -189,19 +192,19 @@ This includes:
|
|
|
189
192
|
- services (information on services the user has access to used for global navigation)
|
|
190
193
|
- allocationJobResponsibilities (the allocation policy codes the user has the associated job responsibility for. Allocation policy codes are: `KEY_WORKER`, meaning the user is a key worker and `PERSONAL_OFFICER`, meaning the user is a personal officer.)
|
|
191
194
|
|
|
192
|
-
This can be useful e.g. for when your service needs access to activeCaseLoad information to prevent extra calls to the
|
|
195
|
+
This can be useful e.g. for when your service needs access to activeCaseLoad information to prevent extra calls to the
|
|
193
196
|
api and takes advantage of the caching that the micro frontend api does.
|
|
194
197
|
|
|
195
198
|
### Populating res.locals.user with the shared case load data
|
|
196
199
|
|
|
197
|
-
Many services typically add case load information to the user object on `res.locals`. This library provides some
|
|
200
|
+
Many services typically add case load information to the user object on `res.locals`. This library provides some
|
|
198
201
|
optional middleware which populates:
|
|
199
202
|
- `res.locals.user.caseLoads` with all case loads the user has access to
|
|
200
203
|
- `res.locals.user.activeCaseLoad` with the active case load of the user
|
|
201
204
|
- `res.locals.user.activeCaseLoadId` with the id of the active case load
|
|
202
205
|
|
|
203
|
-
It uses the `sharedData` object if it is present and caches in `req.session` so that any subsequent routes that do not
|
|
204
|
-
use the component middleware can still use the data. If there is no data in the cache, it will fall back to making a
|
|
206
|
+
It uses the `sharedData` object if it is present and caches in `req.session` so that any subsequent routes that do not
|
|
207
|
+
use the component middleware can still use the data. If there is no data in the cache, it will fall back to making a
|
|
205
208
|
call to Prison API to retrieve the data using the user token.
|
|
206
209
|
|
|
207
210
|
To enable this, add the middleware after the component middleware as follows:
|
|
@@ -216,7 +219,7 @@ app.use(retrieveCaseLoadData({
|
|
|
216
219
|
)
|
|
217
220
|
```
|
|
218
221
|
|
|
219
|
-
This middleware checks the `res.locals.user.authSource` so ensure that any mock auth data used in tests includes
|
|
222
|
+
This middleware checks the `res.locals.user.authSource` so ensure that any mock auth data used in tests includes
|
|
220
223
|
`auth_source: 'nomis'` in the response.
|
|
221
224
|
|
|
222
225
|
### Populating res.locals.user with the shared allocation job responsibilities
|
|
@@ -232,7 +235,7 @@ To enable this, add the middleware after the component middleware as follows:
|
|
|
232
235
|
|
|
233
236
|
```javascript
|
|
234
237
|
import { retrieveAllocationJobResponsibilities } from '@ministryofjustice/hmpps-connect-dps-components'
|
|
235
|
-
app.use(retrieveAllocationJobResponsibilities({
|
|
238
|
+
app.use(retrieveAllocationJobResponsibilities({
|
|
236
239
|
logger,
|
|
237
240
|
authenticationClient: new AuthenticationClient(config.apis.hmppsAuth, logger, services.dataAccess.tokenStore),
|
|
238
241
|
allocationsApiConfig: config.apis.allocationsApi,
|
|
@@ -244,14 +247,14 @@ This should go after `retrieveCaseLoadData` so that `res.locals.user.activeCaseL
|
|
|
244
247
|
This middleware checks the `res.locals.user.authSource` so ensure that any mock auth data used in tests includes
|
|
245
248
|
`auth_source: 'nomis'` in the response. It also checks the `res.locals.user.activeCaseLoadId`, which is required for retrieving allocation job responsibilities.
|
|
246
249
|
|
|
247
|
-
Your service will need to be set up with client credentials in order to use this middleware, although it currently
|
|
250
|
+
Your service will need to be set up with client credentials in order to use this middleware, although it currently
|
|
248
251
|
does not need any specific role.
|
|
249
252
|
|
|
250
253
|
### Note
|
|
251
254
|
|
|
252
255
|
In the event of a failure to retrieve the components, the package will populate the html fields with fallback components.
|
|
253
|
-
The `feComponents.sharedData` will not be populated, but if you use the retrieveCaseLoadData middleware (see above) it
|
|
254
|
-
will either take case load data from the cache or make a call to the Prison API to retrieve it.
|
|
256
|
+
The `feComponents.sharedData` will not be populated, but if you use the retrieveCaseLoadData middleware (see above) it
|
|
257
|
+
will either take case load data from the cache or make a call to the Prison API to retrieve it.
|
|
255
258
|
|
|
256
259
|
|
|
257
260
|
## For library developers:
|
package/dist/index.d.ts
CHANGED
|
@@ -70,6 +70,11 @@ declare class ComponentsService {
|
|
|
70
70
|
getFrontendComponents(requestOptions?: FrontendComponentRequestOptions): RequestHandler;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
type MiddlewareOptions = {
|
|
74
|
+
requestOptions?: FrontendComponentRequestOptions;
|
|
75
|
+
} & Parameters<typeof ComponentsService.create>[0];
|
|
76
|
+
declare function getFrontendComponents({ logger, componentApiConfig, dpsUrl, requestOptions, }: MiddlewareOptions): RequestHandler;
|
|
77
|
+
|
|
73
78
|
declare class PrisonApiClient extends RestClient {
|
|
74
79
|
constructor(logger: ConnectDpsComponentLogger, config: ApiConfig);
|
|
75
80
|
getUserCaseLoads(userToken: string): Promise<CaseLoad[]>;
|
|
@@ -86,6 +91,8 @@ declare class CaseLoadService {
|
|
|
86
91
|
retrieveCaseLoadData(): RequestHandler;
|
|
87
92
|
}
|
|
88
93
|
|
|
94
|
+
declare function retrieveCaseLoadData({ logger, prisonApiConfig, }: Parameters<typeof CaseLoadService.create>[0]): RequestHandler;
|
|
95
|
+
|
|
89
96
|
type AuthSource = 'nomis' | 'delius' | 'external' | 'azuread';
|
|
90
97
|
/**
|
|
91
98
|
* These are the details that all user types share.
|
|
@@ -135,13 +142,6 @@ declare class AllocationService {
|
|
|
135
142
|
retrieveAllocationJobResponsibilities(): RequestHandler;
|
|
136
143
|
}
|
|
137
144
|
|
|
138
|
-
type MiddlewareOptions = {
|
|
139
|
-
requestOptions?: FrontendComponentRequestOptions;
|
|
140
|
-
} & Parameters<typeof ComponentsService.create>[0];
|
|
141
|
-
declare function getFrontendComponents({ logger, componentApiConfig, dpsUrl, requestOptions, }: MiddlewareOptions): RequestHandler;
|
|
142
|
-
|
|
143
|
-
declare function retrieveCaseLoadData({ logger, prisonApiConfig, }: Parameters<typeof CaseLoadService.create>[0]): RequestHandler;
|
|
144
|
-
|
|
145
145
|
declare function retrieveAllocationJobResponsibilities({ logger, allocationsApiConfig, authenticationClient, }: Parameters<typeof AllocationService.create>[0]): RequestHandler;
|
|
146
146
|
|
|
147
147
|
export { AllocationService, CaseLoadService, ComponentsService, getFrontendComponents, retrieveAllocationJobResponsibilities, retrieveCaseLoadData };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ministryofjustice/hmpps-connect-dps-components",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "A package to allow the inclusion of connect DPS micro frontend components within DPS applications",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
"scripts/**/*"
|
|
11
11
|
],
|
|
12
12
|
"bin": "./scripts/install.ts",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": "20 || 22 || 24"
|
|
15
|
+
},
|
|
13
16
|
"scripts": {
|
|
14
17
|
"prepare": "hmpps-precommit-hooks-prepare",
|
|
15
18
|
"build": "rollup -c rollup.config.ts --bundleConfigAsCjs && npm run copy:assets",
|
|
@@ -45,36 +48,36 @@
|
|
|
45
48
|
},
|
|
46
49
|
"homepage": "https://github.com/ministryofjustice/hmpps-connect-dps-components#readme",
|
|
47
50
|
"devDependencies": {
|
|
48
|
-
"@ministryofjustice/eslint-config-hmpps": "^0.0
|
|
49
|
-
"@ministryofjustice/hmpps-auth-clients": "^0.0
|
|
50
|
-
"@ministryofjustice/hmpps-precommit-hooks": "^
|
|
51
|
-
"@rollup/plugin-commonjs": "^
|
|
52
|
-
"@rollup/plugin-multi-entry": "^
|
|
53
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
54
|
-
"@rollup/plugin-typescript": "^12.
|
|
55
|
-
"@tsconfig/
|
|
51
|
+
"@ministryofjustice/eslint-config-hmpps": "^1.0.0",
|
|
52
|
+
"@ministryofjustice/hmpps-auth-clients": "^1.0.0",
|
|
53
|
+
"@ministryofjustice/hmpps-precommit-hooks": "^1.0.2",
|
|
54
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
55
|
+
"@rollup/plugin-multi-entry": "^7.1.0",
|
|
56
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
57
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
58
|
+
"@tsconfig/node24": "^24.0.1",
|
|
56
59
|
"@types/bunyan": "^1.8.11",
|
|
57
|
-
"@types/express": "^
|
|
58
|
-
"@types/jest": "^
|
|
60
|
+
"@types/express": "^5.0.5",
|
|
61
|
+
"@types/jest": "^30.0.0",
|
|
59
62
|
"@types/superagent": "^8.1.9",
|
|
60
63
|
"@types/supertest": "^6.0.3",
|
|
61
64
|
"cheerio": "^1.0.0",
|
|
62
|
-
"express": "^
|
|
63
|
-
"govuk-frontend": "^5.
|
|
64
|
-
"jest": "^
|
|
65
|
-
"jest-html-reporter": "^3.
|
|
65
|
+
"express": "^5.1.0",
|
|
66
|
+
"govuk-frontend": "^5.13.0",
|
|
67
|
+
"jest": "^30.2.0",
|
|
68
|
+
"jest-html-reporter": "^4.3.0",
|
|
66
69
|
"jest-junit": "^16.0.0",
|
|
67
|
-
"lint-staged": "^16.
|
|
68
|
-
"nock": "^
|
|
69
|
-
"rollup": "^4.
|
|
70
|
-
"rollup-plugin-dts": "^6.2.
|
|
70
|
+
"lint-staged": "^16.2.6",
|
|
71
|
+
"nock": "^14.0.10",
|
|
72
|
+
"rollup": "^4.53.2",
|
|
73
|
+
"rollup-plugin-dts": "^6.2.3",
|
|
71
74
|
"supertest": "^7.1.1",
|
|
72
|
-
"ts-jest": "^29.
|
|
75
|
+
"ts-jest": "^29.4.5",
|
|
73
76
|
"tslib": "^2.8.1"
|
|
74
77
|
},
|
|
75
78
|
"dependencies": {
|
|
76
|
-
"@ministryofjustice/hmpps-rest-client": "^0.0
|
|
77
|
-
"@types/node": "
|
|
79
|
+
"@ministryofjustice/hmpps-rest-client": "^1.0.0",
|
|
80
|
+
"@types/node": "^24.10.0",
|
|
78
81
|
"@types/nunjucks": "^3.2.6",
|
|
79
82
|
"nunjucks": "^3.2.4",
|
|
80
83
|
"superagent": "^10.2.3"
|
package/scripts/patch.diff
CHANGED
|
@@ -64,7 +64,7 @@ index 6bb4e41..3a2ae46 100644
|
|
|
64
64
|
AUDIT_ENABLED: "false"
|
|
65
65
|
|
|
66
66
|
diff --git a/server/app.ts b/server/app.ts
|
|
67
|
-
index eddaa67..0dfb1fe
|
|
67
|
+
index eddaa67..0dfb1fe 100644
|
|
68
68
|
--- a/server/app.ts
|
|
69
69
|
+++ b/server/app.ts
|
|
70
70
|
@@ -1,7 +1,10 @@
|
|
@@ -95,7 +95,7 @@ index eddaa67..0dfb1fe 100755
|
|
|
95
95
|
|
|
96
96
|
app.use((req, res, next) => next(createError(404, 'Not found')))
|
|
97
97
|
diff --git a/server/config.ts b/server/config.ts
|
|
98
|
-
index e49a07b..9bbba57
|
|
98
|
+
index e49a07b..9bbba57 100644
|
|
99
99
|
--- a/server/config.ts
|
|
100
100
|
+++ b/server/config.ts
|
|
101
101
|
@@ -72,6 +72,15 @@ export default {
|