@ministryofjustice/hmpps-connect-dps-components 1.0.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 CHANGED
@@ -35,7 +35,6 @@ To incorporate use as middleware for appropriate routes within your Express appl
35
35
  ```javascript
36
36
  app.get('*', dpsComponents.get({
37
37
  dpsUrl: config.serviceUrls.digitalPrison,
38
- environmentName: 'DEV',
39
38
  })
40
39
  )
41
40
  ```
@@ -89,6 +88,23 @@ Include reference to the components in your layout.njk file:
89
88
  {% endblock %}
90
89
  ```
91
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
+
92
108
  ## CSP
93
109
 
94
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.
@@ -13,7 +13,7 @@
13
13
 
14
14
  <a class="fallback-dps-header__link fallback-dps-header__title__service-name" href="{{ authUrl }}">Digital Services</a>
15
15
 
16
- {% if environmentName !== 'PRODUCTION' %}
16
+ {% if environmentName and environmentName !== 'PRODUCTION' %}
17
17
  {{ govukTag({
18
18
  text: environmentName,
19
19
  classes: environmentNameColour
@@ -24,7 +24,7 @@
24
24
  Digital Prison Services
25
25
  </a>
26
26
 
27
- {% if environmentName !== 'PRODUCTION' %}
27
+ {% if environmentName and environmentName !== 'PRODUCTION' %}
28
28
  {{ govukTag({
29
29
  text: environmentName,
30
30
  classes: environmentNameColour
@@ -32,18 +32,20 @@
32
32
  {% endif %}
33
33
  </div>
34
34
 
35
- <nav aria-label="Account navigation">
36
- <ul class="fallback-dps-header__navigation">
37
- {% if name %}
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
- <span data-qa=header-user-name>{{ name }}</span>
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
- {% endif %}
42
-
43
- <li class="fallback-dps-header__navigation__item">
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,GAAG,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAA;YACpC,CAAC;YAED,IAAA,mBAAS,EAAC,GAAG,CAAC,CAAA;YAEd,IAAI,EAAE,CAAA;QACR,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;Y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to the dps homepage to be used in the header
12
12
  * @param requestOptions.authUrl - if your service has users with non-nomis auth sources, pass in the url to the auth service for the home link
13
13
  * @param requestOptions.supportUrl - if your service has users with non-nomis auth sources, pass in the support url for the support link
14
- * @param requestOptions.environmentName - "DEV", "PRE-PRODUCTION" or "PRODUCTION" to be used in the header
14
+ * @param requestOptions.environmentName - if you require environment tags on the fallback banner "DEV", "PRE-PRODUCTION" or "PRODUCTION" can be passed in
15
15
  * @param requestOptions.logger - pass in the bunyen logger if you want to use it. Falls back to console if not provided
16
16
  * @param requestOptions.timeoutOptions - timeout object for superagent. Defaults to 2500ms
17
17
  * @param requestOptions.includeMeta - adds feComponentsMeta to res.locals if true. Contains metadata for components including activeCaseLoad, caseLoads and available services for user
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ exports.default = {
16
16
  * @param requestOptions.dpsUrl - url to the dps homepage to be used in the header
17
17
  * @param requestOptions.authUrl - if your service has users with non-nomis auth sources, pass in the url to the auth service for the home link
18
18
  * @param requestOptions.supportUrl - if your service has users with non-nomis auth sources, pass in the support url for the support link
19
- * @param requestOptions.environmentName - "DEV", "PRE-PRODUCTION" or "PRODUCTION" to be used in the header
19
+ * @param requestOptions.environmentName - if you require environment tags on the fallback banner "DEV", "PRE-PRODUCTION" or "PRODUCTION" can be passed in
20
20
  * @param requestOptions.logger - pass in the bunyen logger if you want to use it. Falls back to console if not provided
21
21
  * @param requestOptions.timeoutOptions - timeout object for superagent. Defaults to 2500ms
22
22
  * @param requestOptions.includeMeta - adds feComponentsMeta to res.locals if true. Contains metadata for components including activeCaseLoad, caseLoads and available services for user
@@ -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;
@@ -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', { isPrisonUser: user.authSource === 'nomis', supportUrl, authUrl });
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,IAAU,EAAE,cAA8B;IAC1E,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,cAAc,CAAA;IACvE,OAAO,kBAAQ,CAAC,MAAM,CAAC,8BAA8B,EAAE;QACrD,YAAY,EAAE,IAAI,CAAC,UAAU,KAAK,OAAO;QACzC,IAAI;QACJ,MAAM;QACN,eAAe;QACf,OAAO;QACP,UAAU;QACV,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC;KACvC,CAAC,CAAA;AACJ,CAAC;AAXD,8CAWC;AAED,SAAgB,iBAAiB,CAAC,IAAU,EAAE,cAA8B;IAC1E,M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,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.0.0",
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",