@ministryofjustice/hmpps-connect-dps-components 5.0.1 → 5.1.1
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 +22 -10
- package/dist/index.d.ts +7 -7
- package/package.json +5 -3
- package/scripts/install.ts +19 -0
- package/scripts/patch.diff +170 -0
package/README.md
CHANGED
|
@@ -39,7 +39,20 @@ npm install @ministryofjustice/hmpps-connect-dps-components
|
|
|
39
39
|
|
|
40
40
|
Currently, the package provides the header and the footer component.
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
#### Automatic installation
|
|
43
|
+
|
|
44
|
+
You can use this script to attempt to automatically install DPS components. It is designed to work with the latest
|
|
45
|
+
[hmpps-template-typescript](https://github.com/ministryofjustice/hmpps-template-typescript) file layout.
|
|
46
|
+
|
|
47
|
+
```shell
|
|
48
|
+
npx @ministryofjustice/hmpps-connect-dps-components
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Do take care to check the diff carefully, in case your repository has diverged from the template.
|
|
52
|
+
|
|
53
|
+
#### Manual installation
|
|
54
|
+
|
|
55
|
+
To incorporate, use the middleware for appropriate routes within your Express application:
|
|
43
56
|
|
|
44
57
|
```javascript
|
|
45
58
|
import { getFrontendComponents } from '@ministryofjustice/hmpps-connect-dps-components'
|
|
@@ -51,8 +64,7 @@ To incorporate use the middleware for appropriate routes within your Express app
|
|
|
51
64
|
componentApiConfig: config.apis.componentApi,
|
|
52
65
|
dpsUrl: config.serviceUrls.digitalPrison,
|
|
53
66
|
requestOptions: { includeSharedData: true },
|
|
54
|
-
})
|
|
55
|
-
)
|
|
67
|
+
}))
|
|
56
68
|
```
|
|
57
69
|
|
|
58
70
|
**However, please 🙏 consider carefully whether you need the components for EVERY request.**
|
|
@@ -94,7 +106,7 @@ There are a [number of options](./src/index.ts) available depending on your requ
|
|
|
94
106
|
Add the `hmpps-connect-dps-components` path to the nunjucksSetup.ts file to enable css to be loaded:
|
|
95
107
|
|
|
96
108
|
```javascript
|
|
97
|
-
|
|
109
|
+
const njkEnv = nunjucks.configure(
|
|
98
110
|
[
|
|
99
111
|
path.join(__dirname, '../../server/views'),
|
|
100
112
|
'node_modules/govuk-frontend/dist/',
|
|
@@ -112,13 +124,13 @@ Add the `hmpps-connect-dps-components` path to the nunjucksSetup.ts file to enab
|
|
|
112
124
|
|
|
113
125
|
Include the package scss within the all.scss file
|
|
114
126
|
```scss
|
|
115
|
-
|
|
116
|
-
|
|
127
|
+
@import '@ministryofjustice/hmpps-connect-dps-components/dist/assets/footer';
|
|
128
|
+
@import '@ministryofjustice/hmpps-connect-dps-components/dist/assets/header-bar';
|
|
117
129
|
```
|
|
118
130
|
|
|
119
131
|
Include reference to the components in your layout.njk file:
|
|
120
132
|
|
|
121
|
-
```
|
|
133
|
+
```nunjucks
|
|
122
134
|
{% for js in feComponents.jsIncludes %}
|
|
123
135
|
<script src="{{ js }}" nonce="{{ cspNonce }}"></script>
|
|
124
136
|
{% endfor %}
|
|
@@ -127,12 +139,12 @@ Include reference to the components in your layout.njk file:
|
|
|
127
139
|
<link href="{{ css }}" nonce="{{ cspNonce }}" rel="stylesheet" />
|
|
128
140
|
{% endfor %}
|
|
129
141
|
```
|
|
130
|
-
```
|
|
142
|
+
```nunjucks
|
|
131
143
|
{% block header %}
|
|
132
144
|
{{ feComponents.header | safe }}
|
|
133
145
|
{% endblock %}
|
|
134
146
|
```
|
|
135
|
-
```
|
|
147
|
+
```nunjucks
|
|
136
148
|
{% block footer %}
|
|
137
149
|
{{ feComponents.footer | safe }}
|
|
138
150
|
{% endblock %}
|
|
@@ -156,7 +168,7 @@ of routes. e.g. in `setUpAuthentication.ts` on the `/autherror` path:
|
|
|
156
168
|
res.status(401)
|
|
157
169
|
return res.render('autherror')
|
|
158
170
|
},
|
|
159
|
-
|
|
171
|
+
)
|
|
160
172
|
```
|
|
161
173
|
|
|
162
174
|
This will provide a stripped down header for if there is no user object on `res.locals`.
|
package/dist/index.d.ts
CHANGED
|
@@ -70,11 +70,6 @@ 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
|
-
|
|
78
73
|
declare class PrisonApiClient extends RestClient {
|
|
79
74
|
constructor(logger: ConnectDpsComponentLogger, config: ApiConfig);
|
|
80
75
|
getUserCaseLoads(userToken: string): Promise<CaseLoad[]>;
|
|
@@ -91,8 +86,6 @@ declare class CaseLoadService {
|
|
|
91
86
|
retrieveCaseLoadData(): RequestHandler;
|
|
92
87
|
}
|
|
93
88
|
|
|
94
|
-
declare function retrieveCaseLoadData({ logger, prisonApiConfig, }: Parameters<typeof CaseLoadService.create>[0]): RequestHandler;
|
|
95
|
-
|
|
96
89
|
type AuthSource = 'nomis' | 'delius' | 'external' | 'azuread';
|
|
97
90
|
/**
|
|
98
91
|
* These are the details that all user types share.
|
|
@@ -142,6 +135,13 @@ declare class AllocationService {
|
|
|
142
135
|
retrieveAllocationJobResponsibilities(): RequestHandler;
|
|
143
136
|
}
|
|
144
137
|
|
|
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,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ministryofjustice/hmpps-connect-dps-components",
|
|
3
|
-
"version": "5.
|
|
4
|
-
"description": "A package to allow the inclusion of connect
|
|
3
|
+
"version": "5.1.1",
|
|
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",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
|
-
"dist/**/*"
|
|
9
|
+
"dist/**/*",
|
|
10
|
+
"scripts/**/*"
|
|
10
11
|
],
|
|
12
|
+
"bin": "./scripts/install.ts",
|
|
11
13
|
"scripts": {
|
|
12
14
|
"prepare": "hmpps-precommit-hooks-prepare",
|
|
13
15
|
"build": "rollup -c rollup.config.ts --bundleConfigAsCjs && npm run copy:assets",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env -S npx tsx
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
import { execSync } from 'node:child_process'
|
|
4
|
+
import { resolve } from 'node:path'
|
|
5
|
+
|
|
6
|
+
console.info('→ Installing @ministryofjustice/hmpps-connect-dps-components')
|
|
7
|
+
execSync('npm install --save-prod @ministryofjustice/hmpps-connect-dps-components')
|
|
8
|
+
|
|
9
|
+
console.info('→ Applying patch')
|
|
10
|
+
const patchFile = resolve(__dirname, 'patch.diff')
|
|
11
|
+
execSync(`git apply ${patchFile}`)
|
|
12
|
+
|
|
13
|
+
console.info('→ Connect DPS components have been installed')
|
|
14
|
+
console.info(
|
|
15
|
+
'However, please consider whether you need the components for EVERY request; see README in hmpps-connect-dps-components.',
|
|
16
|
+
)
|
|
17
|
+
console.info(
|
|
18
|
+
'Make sure to resolve merge conflicts and check the diff carefully (eg. for duplicate environment variables)',
|
|
19
|
+
)
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
diff --git a/assets/scss/index.scss b/assets/scss/index.scss
|
|
2
|
+
index 70feedd..a7cd9fd 100644
|
|
3
|
+
--- a/assets/scss/index.scss
|
|
4
|
+
+++ b/assets/scss/index.scss
|
|
5
|
+
@@ -6,6 +6,8 @@ $govuk-page-width: $moj-page-width;
|
|
6
|
+
|
|
7
|
+
@import "govuk-frontend/dist/govuk/index";
|
|
8
|
+
@import "@ministryofjustice/frontend/moj/all";
|
|
9
|
+
+@import "@ministryofjustice/hmpps-connect-dps-components/dist/assets/footer";
|
|
10
|
+
+@import "@ministryofjustice/hmpps-connect-dps-components/dist/assets/header-bar";
|
|
11
|
+
|
|
12
|
+
@import './components/header-bar';
|
|
13
|
+
@import './overrides/local';
|
|
14
|
+
diff --git a/feature.env b/feature.env
|
|
15
|
+
index 9a3f344..11b4654 100644
|
|
16
|
+
--- a/feature.env
|
|
17
|
+
+++ b/feature.env
|
|
18
|
+
@@ -1,6 +1,8 @@
|
|
19
|
+
PORT=3007
|
|
20
|
+
HMPPS_AUTH_URL=http://localhost:9091/auth
|
|
21
|
+
TOKEN_VERIFICATION_API_URL=http://localhost:9091/verification
|
|
22
|
+
+COMPONENT_API_URL=http://localhost:9091/frontend-components
|
|
23
|
+
+DPS_HOME_PAGE_URL=http://localhost:9091/dpshomepage
|
|
24
|
+
EXAMPLE_API_URL=http://localhost:9091/example-api
|
|
25
|
+
TOKEN_VERIFICATION_ENABLED=true
|
|
26
|
+
REDIS_ENABLED=false
|
|
27
|
+
diff --git a/helm_deploy/values-dev.yaml b/helm_deploy/values-dev.yaml
|
|
28
|
+
index f40e7d3..52b7431 100644
|
|
29
|
+
--- a/helm_deploy/values-dev.yaml
|
|
30
|
+
+++ b/helm_deploy/values-dev.yaml
|
|
31
|
+
@@ -11,6 +11,8 @@ generic-service:
|
|
32
|
+
INGRESS_URL: "https://template-typescript-dev.hmpps.service.justice.gov.uk"
|
|
33
|
+
HMPPS_AUTH_URL: "https://sign-in-dev.hmpps.service.justice.gov.uk/auth"
|
|
34
|
+
TOKEN_VERIFICATION_API_URL: "https://token-verification-api-dev.prison.service.justice.gov.uk"
|
|
35
|
+
+ COMPONENT_API_URL: "https://frontend-components-dev.hmpps.service.justice.gov.uk"
|
|
36
|
+
+ DPS_HOME_PAGE_URL: "https://digital-dev.prison.service.justice.gov.uk"
|
|
37
|
+
EXAMPLE_API_URL: 'https://template-kotlin-dev.hmpps.service.justice.gov.uk'
|
|
38
|
+
ENVIRONMENT_NAME: DEV
|
|
39
|
+
AUDIT_ENABLED: "false"
|
|
40
|
+
diff --git a/helm_deploy/values-preprod.yaml b/helm_deploy/values-preprod.yaml
|
|
41
|
+
index 554e19a..0d577b2 100644
|
|
42
|
+
--- a/helm_deploy/values-preprod.yaml
|
|
43
|
+
+++ b/helm_deploy/values-preprod.yaml
|
|
44
|
+
@@ -11,6 +11,8 @@ generic-service:
|
|
45
|
+
INGRESS_URL: "https://template-typescript-preprod.hmpps.service.justice.gov.uk"
|
|
46
|
+
HMPPS_AUTH_URL: "https://sign-in-preprod.hmpps.service.justice.gov.uk/auth"
|
|
47
|
+
TOKEN_VERIFICATION_API_URL: "https://token-verification-api-preprod.prison.service.justice.gov.uk"
|
|
48
|
+
+ COMPONENT_API_URL: "https://frontend-components-preprod.hmpps.service.justice.gov.uk"
|
|
49
|
+
+ DPS_HOME_PAGE_URL: "https://digital-preprod.prison.service.justice.gov.uk"
|
|
50
|
+
EXAMPLE_API_URL: 'https://template-kotlin-preprod.hmpps.service.justice.gov.uk'
|
|
51
|
+
ENVIRONMENT_NAME: PRE-PRODUCTION
|
|
52
|
+
AUDIT_ENABLED: "false"
|
|
53
|
+
diff --git a/helm_deploy/values-prod.yaml b/helm_deploy/values-prod.yaml
|
|
54
|
+
index 6bb4e41..3a2ae46 100644
|
|
55
|
+
--- a/helm_deploy/values-prod.yaml
|
|
56
|
+
+++ b/helm_deploy/values-prod.yaml
|
|
57
|
+
@@ -9,6 +9,8 @@ generic-service:
|
|
58
|
+
INGRESS_URL: "https://template-typescript.hmpps.service.justice.gov.uk"
|
|
59
|
+
HMPPS_AUTH_URL: "https://sign-in.hmpps.service.justice.gov.uk/auth"
|
|
60
|
+
TOKEN_VERIFICATION_API_URL: "https://token-verification-api.prison.service.justice.gov.uk"
|
|
61
|
+
+ COMPONENT_API_URL: "https://frontend-components.hmpps.service.justice.gov.uk"
|
|
62
|
+
+ DPS_HOME_PAGE_URL: "https://digital.prison.service.justice.gov.uk"
|
|
63
|
+
EXAMPLE_API_URL: 'https://template-kotlin.hmpps.service.justice.gov.uk'
|
|
64
|
+
AUDIT_ENABLED: "false"
|
|
65
|
+
|
|
66
|
+
diff --git a/server/app.ts b/server/app.ts
|
|
67
|
+
index eddaa67..0dfb1fe 100755
|
|
68
|
+
--- a/server/app.ts
|
|
69
|
+
+++ b/server/app.ts
|
|
70
|
+
@@ -1,7 +1,10 @@
|
|
71
|
+
import express from 'express'
|
|
72
|
+
+import { getFrontendComponents } from '@ministryofjustice/hmpps-connect-dps-components'
|
|
73
|
+
|
|
74
|
+
import createError from 'http-errors'
|
|
75
|
+
|
|
76
|
+
+import logger from '../logger'
|
|
77
|
+
+import config from './config'
|
|
78
|
+
import nunjucksSetup from './utils/nunjucksSetup'
|
|
79
|
+
import errorHandler from './errorHandler'
|
|
80
|
+
import { appInsightsMiddleware } from './utils/azureAppInsights'
|
|
81
|
+
@@ -38,6 +41,15 @@ export default function createApp(services: Services): express.Application {
|
|
82
|
+
app.use(setUpCsrf())
|
|
83
|
+
app.use(setUpCurrentUser())
|
|
84
|
+
|
|
85
|
+
+ app.use(
|
|
86
|
+
+ getFrontendComponents({
|
|
87
|
+
+ logger,
|
|
88
|
+
+ componentApiConfig: config.apis.componentApi,
|
|
89
|
+
+ dpsUrl: config.serviceUrls.digitalPrison,
|
|
90
|
+
+ requestOptions: { includeSharedData: true },
|
|
91
|
+
+ }),
|
|
92
|
+
+ )
|
|
93
|
+
+
|
|
94
|
+
app.use(routes(services))
|
|
95
|
+
|
|
96
|
+
app.use((req, res, next) => next(createError(404, 'Not found')))
|
|
97
|
+
diff --git a/server/config.ts b/server/config.ts
|
|
98
|
+
index e49a07b..9bbba57 100755
|
|
99
|
+
--- a/server/config.ts
|
|
100
|
+
+++ b/server/config.ts
|
|
101
|
+
@@ -72,6 +72,15 @@ export default {
|
|
102
|
+
agent: new AgentConfig(Number(get('TOKEN_VERIFICATION_API_TIMEOUT_RESPONSE', 5000))),
|
|
103
|
+
enabled: get('TOKEN_VERIFICATION_ENABLED', 'false') === 'true',
|
|
104
|
+
},
|
|
105
|
+
+ componentApi: {
|
|
106
|
+
+ url: get('COMPONENT_API_URL', 'http://localhost:8082', requiredInProduction),
|
|
107
|
+
+ healthPath: '/ping',
|
|
108
|
+
+ timeout: {
|
|
109
|
+
+ response: Number(get('COMPONENT_API_TIMEOUT_RESPONSE', 2500)),
|
|
110
|
+
+ deadline: Number(get('COMPONENT_API_TIMEOUT_DEADLINE', 2500)),
|
|
111
|
+
+ },
|
|
112
|
+
+ agent: new AgentConfig(Number(get('COMPONENT_TIMEOUT_DEADLINE', 10000))),
|
|
113
|
+
+ },
|
|
114
|
+
exampleApi: {
|
|
115
|
+
url: get('EXAMPLE_API_URL', 'http://localhost:8080', requiredInProduction),
|
|
116
|
+
healthPath: '/health/ping',
|
|
117
|
+
@@ -82,6 +91,7 @@ export default {
|
|
118
|
+
agent: new AgentConfig(Number(get('EXAMPLE_API_TIMEOUT_RESPONSE', 5000))),
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
+ serviceUrls: { digitalPrison: get('DPS_HOME_PAGE_URL', 'http://localhost:3001', requiredInProduction) },
|
|
122
|
+
sqs: {
|
|
123
|
+
audit: auditConfig(),
|
|
124
|
+
},
|
|
125
|
+
diff --git a/server/utils/nunjucksSetup.ts b/server/utils/nunjucksSetup.ts
|
|
126
|
+
index 1d00293..69a787c 100644
|
|
127
|
+
--- a/server/utils/nunjucksSetup.ts
|
|
128
|
+
+++ b/server/utils/nunjucksSetup.ts
|
|
129
|
+
@@ -30,6 +30,7 @@ export default function nunjucksSetup(app: express.Express): void {
|
|
130
|
+
path.join(__dirname, '../../server/views'),
|
|
131
|
+
'node_modules/govuk-frontend/dist/',
|
|
132
|
+
'node_modules/@ministryofjustice/frontend/',
|
|
133
|
+
+ 'node_modules/@ministryofjustice/hmpps-connect-dps-components/dist/assets/',
|
|
134
|
+
],
|
|
135
|
+
{
|
|
136
|
+
autoescape: true,
|
|
137
|
+
diff --git a/server/views/partials/layout.njk b/server/views/partials/layout.njk
|
|
138
|
+
index 63653a0..d87b07a 100644
|
|
139
|
+
--- a/server/views/partials/layout.njk
|
|
140
|
+
+++ b/server/views/partials/layout.njk
|
|
141
|
+
@@ -2,17 +2,28 @@
|
|
142
|
+
|
|
143
|
+
{% block head %}
|
|
144
|
+
<link href="{{ '/assets/css/index.css' | assetMap }}" rel="stylesheet"/>
|
|
145
|
+
+
|
|
146
|
+
+ {% for js in feComponents.jsIncludes %}
|
|
147
|
+
+ <script src="{{ js }}" nonce="{{ cspNonce }}"></script>
|
|
148
|
+
+ {% endfor %}
|
|
149
|
+
+ {% for css in feComponents.cssIncludes %}
|
|
150
|
+
+ <link href="{{ css }}" nonce="{{ cspNonce }}" rel="stylesheet" />
|
|
151
|
+
+ {% endfor %}
|
|
152
|
+
{% endblock %}
|
|
153
|
+
|
|
154
|
+
{% block pageTitle %}{{pageTitle | default(applicationName)}}{% endblock %}
|
|
155
|
+
|
|
156
|
+
{% block header %}
|
|
157
|
+
- {% include "./header.njk" %}
|
|
158
|
+
+ {{ feComponents.header | safe }}
|
|
159
|
+
{% endblock %}
|
|
160
|
+
|
|
161
|
+
{% block bodyStart %}
|
|
162
|
+
{% endblock %}
|
|
163
|
+
|
|
164
|
+
+{% block footer %}
|
|
165
|
+
+ {{ feComponents.footer | safe }}
|
|
166
|
+
+{% endblock %}
|
|
167
|
+
+
|
|
168
|
+
{% block bodyEnd %}
|
|
169
|
+
<script type="module" src="{{ '/assets/js/index.js' | assetMap }}"></script>
|
|
170
|
+
{% endblock %}
|