@ministryofjustice/hmpps-connect-dps-components 5.1.1 → 5.2.2

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 CHANGED
@@ -1,6 +1,9 @@
1
1
  # hmpps-connect-dps-components
2
2
 
3
- `hmpps-connect-dps-components` is a Node.js client library to simplify the process of incorporating global components
3
+ [![repo standards badge](https://img.shields.io/badge/endpoint.svg?&style=flat&logo=github&url=https%3A%2F%2Foperations-engineering-reports.cloud-platform.service.justice.gov.uk%2Fapi%2Fv1%2Fcompliant_public_repositories%2Fhmpps-connect-dps-components)](https://operations-engineering-reports.cloud-platform.service.justice.gov.uk/public-report/hmpps-connect-dps-components "Link to report")
4
+ [![Test, lint & publish](https://github.com/ministryofjustice/hmpps-connect-dps-components/actions/workflows/pipeline.yml/badge.svg?branch=main)](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.1.1",
3
+ "version": "5.2.2",
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",
@@ -23,7 +26,8 @@
23
26
  "security_audit": "npx audit-ci --config audit-ci.json",
24
27
  "precommit:secrets": "gitleaks git --pre-commit --redact --staged --verbose --config .gitleaks/config.toml",
25
28
  "precommit:lint": "lint-staged",
26
- "precommit:verify": "npm run typecheck && npm test"
29
+ "precommit:verify": "npm run typecheck && npm test",
30
+ "setup": "npm ci && hmpps-npm-script-run-allowlist"
27
31
  },
28
32
  "lint-staged": {
29
33
  "*.{ts,css}": [
@@ -45,36 +49,38 @@
45
49
  },
46
50
  "homepage": "https://github.com/ministryofjustice/hmpps-connect-dps-components#readme",
47
51
  "devDependencies": {
48
- "@ministryofjustice/eslint-config-hmpps": "^0.0.5",
49
- "@ministryofjustice/hmpps-auth-clients": "^0.0.1",
50
- "@ministryofjustice/hmpps-precommit-hooks": "^0.0.3",
51
- "@rollup/plugin-commonjs": "^28.0.6",
52
- "@rollup/plugin-multi-entry": "^6.0.1",
53
- "@rollup/plugin-node-resolve": "^16.0.1",
54
- "@rollup/plugin-typescript": "^12.1.4",
55
- "@tsconfig/node22": "^22.0.2",
52
+ "@ministryofjustice/eslint-config-hmpps": "^1.0.1",
53
+ "@ministryofjustice/hmpps-auth-clients": "^1.0.1",
54
+ "@ministryofjustice/hmpps-precommit-hooks": "^1.0.2",
55
+ "@rollup/plugin-commonjs": "^29.0.0",
56
+ "@rollup/plugin-multi-entry": "^7.1.0",
57
+ "@rollup/plugin-node-resolve": "^16.0.3",
58
+ "@rollup/plugin-typescript": "^12.3.0",
59
+ "@tsconfig/node24": "24.0.4",
56
60
  "@types/bunyan": "^1.8.11",
57
- "@types/express": "^4.17.22",
58
- "@types/jest": "^29.5.14",
61
+ "@types/express": "^5.0.6",
62
+ "@types/jest": "^30.0.0",
59
63
  "@types/superagent": "^8.1.9",
60
64
  "@types/supertest": "^6.0.3",
61
- "cheerio": "^1.0.0",
62
- "express": "^4.21.2",
63
- "govuk-frontend": "^5.10.1",
64
- "jest": "^29.7.0",
65
- "jest-html-reporter": "^3.10.2",
65
+ "cheerio": "^1.1.2",
66
+ "express": "^5.2.1",
67
+ "govuk-frontend": "5.14.0",
68
+ "jest": "^30.2.0",
69
+ "jest-html-reporter": "^4.3.0",
66
70
  "jest-junit": "^16.0.0",
67
- "lint-staged": "^16.1.2",
68
- "nock": "^13.5.6",
69
- "rollup": "^4.45.1",
70
- "rollup-plugin-dts": "^6.2.1",
71
- "supertest": "^7.1.1",
72
- "ts-jest": "^29.3.4",
73
- "tslib": "^2.8.1"
71
+ "lint-staged": "^16.2.7",
72
+ "nock": "^14.0.10",
73
+ "rollup": "4.55.2",
74
+ "rollup-plugin-dts": "^6.3.0",
75
+ "supertest": "^7.1.4",
76
+ "ts-jest": "^29.4.6",
77
+ "tslib": "^2.8.1",
78
+ "typescript": "5.9.3"
74
79
  },
75
80
  "dependencies": {
76
- "@ministryofjustice/hmpps-rest-client": "^0.0.3",
77
- "@types/node": "22.18.6",
81
+ "@ministryofjustice/hmpps-npm-script-allowlist": "0.0.3",
82
+ "@ministryofjustice/hmpps-rest-client": "^1.0.0",
83
+ "@types/node": "24.10.9",
78
84
  "@types/nunjucks": "^3.2.6",
79
85
  "nunjucks": "^3.2.4",
80
86
  "superagent": "^10.2.3"
@@ -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 100755
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 100755
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 {