@ministryofjustice/hmpps-connect-dps-components 1.1.0 → 1.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 +17 -0
- package/dist/assets/dpsComponents/prison-header.njk +13 -11
- package/dist/componentsService.js +12 -2
- package/dist/componentsService.js.map +1 -1
- package/dist/utils/fallbacks.d.ts +1 -1
- package/dist/utils/fallbacks.js +7 -3
- package/dist/utils/fallbacks.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,6 +88,23 @@ Include reference to the components in your layout.njk file:
|
|
|
88
88
|
{% endblock %}
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
## Extra calls
|
|
92
|
+
|
|
93
|
+
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:
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
router.get(
|
|
97
|
+
'/autherror',
|
|
98
|
+
dpsComponents.getPageComponents({ dpsUrl: config.serviceUrls.digitalPrison }),
|
|
99
|
+
(req, res) => {
|
|
100
|
+
res.status(401)
|
|
101
|
+
return res.render('autherror')
|
|
102
|
+
},
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
This will provide a stripped down header for if there is no user object on `res.locals`.
|
|
107
|
+
|
|
91
108
|
## CSP
|
|
92
109
|
|
|
93
110
|
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.
|
|
@@ -32,18 +32,20 @@
|
|
|
32
32
|
{% endif %}
|
|
33
33
|
</div>
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
<
|
|
37
|
-
|
|
35
|
+
{% if user %}
|
|
36
|
+
<nav aria-label="Account navigation">
|
|
37
|
+
<ul class="fallback-dps-header__navigation">
|
|
38
|
+
{% if name %}
|
|
39
|
+
<li class="fallback-dps-header__navigation__item">
|
|
40
|
+
<span data-qa=header-user-name>{{ name }}</span>
|
|
41
|
+
</li>
|
|
42
|
+
{% endif %}
|
|
43
|
+
|
|
38
44
|
<li class="fallback-dps-header__navigation__item">
|
|
39
|
-
<
|
|
45
|
+
<a data-qa="signOut" class="fallback-dps-header__link fallback-dps-header__link--no-underline fallback-dps-header__sign-out" href="/sign-out">Sign out</a>
|
|
40
46
|
</li>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
<a data-qa="signOut" class="fallback-dps-header__link fallback-dps-header__link--no-underline fallback-dps-header__sign-out" href="/sign-out">Sign out</a>
|
|
45
|
-
</li>
|
|
46
|
-
</ul>
|
|
47
|
-
</nav>
|
|
47
|
+
</ul>
|
|
48
|
+
</nav>
|
|
49
|
+
{% endif %}
|
|
48
50
|
</div>
|
|
49
51
|
</header>
|
|
@@ -17,6 +17,16 @@ function getFrontendComponents(requestOptions) {
|
|
|
17
17
|
...requestOptions,
|
|
18
18
|
};
|
|
19
19
|
return async (_req, res, next) => {
|
|
20
|
+
if (!res.locals.user) {
|
|
21
|
+
logger.info('Using logged out user header');
|
|
22
|
+
res.locals.feComponents = {
|
|
23
|
+
header: (0, fallbacks_1.getFallbackHeader)(null, requestOptions),
|
|
24
|
+
footer: (0, fallbacks_1.getFallbackFooter)(null, requestOptions),
|
|
25
|
+
cssIncludes: [],
|
|
26
|
+
jsIncludes: [],
|
|
27
|
+
};
|
|
28
|
+
return next();
|
|
29
|
+
}
|
|
20
30
|
try {
|
|
21
31
|
const { header, footer, meta } = await componentApiClient_1.default.getComponents(res.locals.user.token, timeoutOptions, logger);
|
|
22
32
|
res.locals.feComponents = {
|
|
@@ -29,7 +39,7 @@ function getFrontendComponents(requestOptions) {
|
|
|
29
39
|
res.locals.feComponentsMeta = meta;
|
|
30
40
|
}
|
|
31
41
|
(0, updateCsp_1.default)(res);
|
|
32
|
-
next();
|
|
42
|
+
return next();
|
|
33
43
|
}
|
|
34
44
|
catch (error) {
|
|
35
45
|
logger.error('Failed to retrieve front end components, using fallbacks');
|
|
@@ -39,7 +49,7 @@ function getFrontendComponents(requestOptions) {
|
|
|
39
49
|
cssIncludes: [],
|
|
40
50
|
jsIncludes: [],
|
|
41
51
|
};
|
|
42
|
-
next();
|
|
52
|
+
return next();
|
|
43
53
|
}
|
|
44
54
|
};
|
|
45
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"componentsService.js","sourceRoot":"","sources":["../src/componentsService.ts"],"names":[],"mappings":";;;;;AACA,8EAAqD;AACrD,iDAAwE;AAExE,kEAAyC;AAEzC,MAAM,cAAc,GAA4B;IAC9C,MAAM,EAAE,OAAO;IACf,cAAc,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE;IAClD,WAAW,EAAE,KAAK;CACnB,CAAA;AAED,SAAwB,qBAAqB,CAAC,cAA+B;IAC3E,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG;QAC9C,GAAG,cAAc;QACjB,GAAG,cAAc;KAClB,CAAA;IAED,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC/B,IAAI,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,4BAAkB,CAAC,aAAa,CACrE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EACrB,cAAc,EACd,MAAM,CACP,CAAA;YAED,GAAG,CAAC,MAAM,CAAC,YAAY,GAAG;gBACxB,MAAM,EAAE,MAAM,CAAC,IAAI;gBACnB,MAAM,EAAE,MAAM,CAAC,IAAI;gBACnB,WAAW,EAAE,CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC;gBAC3C,UAAU,EAAE,CAAC,GAAG,MAAM,CAAC,UAAU,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC;aACzD,CAAA;YAED,IAAI,WAAW,EAAE,CAAC;gBAChB,G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gBACxB,MAAM,EAAE,MAAM,CAAC,IAAI;gBACnB,MAAM,EAAE,MAAM,CAAC,IAAI;gBACnB,WAAW,EAAE,CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC;gBAC3C,UAAU,EAAE,CAAC,GAAG,MAAM,CAAC,UAAU,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC;aACzD,CAAA;YAED,IAAI,WAAW,EAAE,CAAC;gBAChB,GAAG,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAA;YACpC,CAAC;YAED,IAAA,mBAAS,EAAC,GAAG,CAAC,CAAA;YAEd,OAAO,IAAI,EAAE,CAAA;QACf,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAA;YAExE,GAAG,CAAC,MAAM,CAAC,YAAY,GAAG;gBACxB,MAAM,EAAE,IAAA,6BAAiB,EAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC;gBAC1D,MAAM,EAAE,IAAA,6BAAiB,EAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC;gBAC1D,WAAW,EAAE,EAAE;gBACf,UAAU,EAAE,EAAE;aACf,CAAA;YAED,OAAO,IAAI,EAAE,CAAA;QACf,CAAC;IACH,CAAC,CAAA;AACH,CAAC;AApDD,wCAoDC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { User } from '../types/User';
|
|
2
2
|
import RequestOptions from '../types/RequestOptions';
|
|
3
|
-
export declare function getFallbackHeader(user: User, requestOptions: RequestOptions): string;
|
|
3
|
+
export declare function getFallbackHeader(user: User | null, requestOptions: RequestOptions): string;
|
|
4
4
|
export declare function getFallbackFooter(user: User, requestOptions: RequestOptions): string;
|
package/dist/utils/fallbacks.js
CHANGED
|
@@ -8,19 +8,23 @@ const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
|
8
8
|
function getFallbackHeader(user, requestOptions) {
|
|
9
9
|
const { dpsUrl, environmentName, authUrl, supportUrl } = requestOptions;
|
|
10
10
|
return nunjucks_1.default.render('dpsComponents/header-bar.njk', {
|
|
11
|
-
isPrisonUser: user.authSource === 'nomis',
|
|
11
|
+
isPrisonUser: !user || user.authSource === 'nomis',
|
|
12
12
|
user,
|
|
13
13
|
dpsUrl,
|
|
14
14
|
environmentName,
|
|
15
15
|
authUrl,
|
|
16
16
|
supportUrl,
|
|
17
|
-
name: initialiseName(user.displayName),
|
|
17
|
+
name: initialiseName(user === null || user === void 0 ? void 0 : user.displayName),
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
exports.getFallbackHeader = getFallbackHeader;
|
|
21
21
|
function getFallbackFooter(user, requestOptions) {
|
|
22
22
|
const { supportUrl, authUrl } = requestOptions;
|
|
23
|
-
return nunjucks_1.default.render('dpsComponents/footer.njk', {
|
|
23
|
+
return nunjucks_1.default.render('dpsComponents/footer.njk', {
|
|
24
|
+
isPrisonUser: !user || user.authSource === 'nomis',
|
|
25
|
+
supportUrl,
|
|
26
|
+
authUrl,
|
|
27
|
+
});
|
|
24
28
|
}
|
|
25
29
|
exports.getFallbackFooter = getFallbackFooter;
|
|
26
30
|
function initialiseName(fullName) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fallbacks.js","sourceRoot":"","sources":["../../src/utils/fallbacks.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA+B;AAI/B,SAAgB,iBAAiB,CAAC,
|
|
1
|
+
{"version":3,"file":"fallbacks.js","sourceRoot":"","sources":["../../src/utils/fallbacks.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA+B;AAI/B,SAAgB,iBAAiB,CAAC,IAAiB,EAAE,cAA8B;IACjF,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,cAAc,CAAA;IAEvE,OAAO,kBAAQ,CAAC,MAAM,CAAC,8BAA8B,EAAE;QACrD,YAAY,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,OAAO;QAClD,IAAI;QACJ,MAAM;QACN,eAAe;QACf,OAAO;QACP,UAAU;QACV,IAAI,EAAE,cAAc,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC;KACxC,CAAC,CAAA;AACJ,CAAC;AAZD,8CAYC;AAED,SAAgB,iBAAiB,CAAC,IAAU,EAAE,cAA8B;IAC1E,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,cAAc,CAAA;IAC9C,OAAO,kBAAQ,CAAC,MAAM,CAAC,0BAA0B,EAAE;QACjD,YAAY,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,OAAO;QAClD,UAAU;QACV,OAAO;KACR,CAAC,CAAA;AACJ,CAAC;AAPD,8CAOC;AAED,SAAS,cAAc,CAAC,QAAiB;IACvC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAA;IAE1B,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACjC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;AAChD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ministryofjustice/hmpps-connect-dps-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.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.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|