@ministryofjustice/hmpps-connect-dps-components 2.0.0 → 2.1.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.
@@ -10,21 +10,30 @@ const defaultOptions = {
10
10
  logger: console,
11
11
  timeoutOptions: { response: 2500, deadline: 2500 },
12
12
  includeSharedData: false,
13
+ useFallbacksByDefault: false,
13
14
  };
14
15
  function getFrontendComponents(requestOptions) {
15
- const { logger, timeoutOptions, includeSharedData } = {
16
+ const { logger, timeoutOptions, includeSharedData, useFallbacksByDefault } = {
16
17
  ...defaultOptions,
17
18
  ...requestOptions,
18
19
  };
19
20
  return async (_req, res, next) => {
20
- if (!res.locals.user) {
21
- logger.info('Using logged out user header');
21
+ const useFallbacks = (user) => {
22
22
  res.locals.feComponents = {
23
- header: (0, fallbacks_1.getFallbackHeader)(null, requestOptions),
24
- footer: (0, fallbacks_1.getFallbackFooter)(null, requestOptions),
23
+ header: (0, fallbacks_1.getFallbackHeader)(user, requestOptions),
24
+ footer: (0, fallbacks_1.getFallbackFooter)(user, requestOptions),
25
25
  cssIncludes: [],
26
26
  jsIncludes: [],
27
27
  };
28
+ };
29
+ if (!res.locals.user) {
30
+ logger.info('Using fallback frontend components when no user in context');
31
+ useFallbacks(null);
32
+ return next();
33
+ }
34
+ if (useFallbacksByDefault) {
35
+ logger.info('Using fallback frontend components by default');
36
+ useFallbacks(res.locals.user);
28
37
  return next();
29
38
  }
30
39
  try {
@@ -43,12 +52,7 @@ function getFrontendComponents(requestOptions) {
43
52
  }
44
53
  catch (error) {
45
54
  logger.error('Failed to retrieve front end components, using fallbacks');
46
- res.locals.feComponents = {
47
- header: (0, fallbacks_1.getFallbackHeader)(res.locals.user, requestOptions),
48
- footer: (0, fallbacks_1.getFallbackFooter)(res.locals.user, requestOptions),
49
- cssIncludes: [],
50
- jsIncludes: [],
51
- };
55
+ useFallbacks(res.locals.user);
52
56
  return next();
53
57
  }
54
58
  };
@@ -1 +1 @@
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BAAiB,EAAE,CAAC;gBACtB,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,GAAG,IAAI,CAAA;YAC3C,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;YACxE,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAC7B,OAAO,IAAI,EAAE,CAAA;QACf,CAAC;IACH,CAAC,CAAA;AACH,CAAC;AAvDD,wCAuDC"}
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ declare const _default: {
16
16
  * @param requestOptions.logger - pass in the bunyen logger if you want to use it. Falls back to console if not provided
17
17
  * @param requestOptions.timeoutOptions - timeout object for superagent. Defaults to 2500ms
18
18
  * @param requestOptions.includeSharedData - adds sharedData to res.locals.feComponents if true. Contains data that the components have collected in order to render, including: activeCaseLoad, caseLoads and available services for user
19
+ * @param requestOptions.useFallbacksByDefault - if your service requires only the basic fallback header and footer to be used by default, set this to true, it will not attempt to fetch the components from the frontend components service
19
20
  */
20
21
  getPageComponents: typeof getPageComponents;
21
22
  /**
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ exports.default = {
21
21
  * @param requestOptions.logger - pass in the bunyen logger if you want to use it. Falls back to console if not provided
22
22
  * @param requestOptions.timeoutOptions - timeout object for superagent. Defaults to 2500ms
23
23
  * @param requestOptions.includeSharedData - adds sharedData to res.locals.feComponents if true. Contains data that the components have collected in order to render, including: activeCaseLoad, caseLoads and available services for user
24
+ * @param requestOptions.useFallbacksByDefault - if your service requires only the basic fallback header and footer to be used by default, set this to true, it will not attempt to fetch the components from the frontend components service
24
25
  */
25
26
  getPageComponents: componentsService_1.default,
26
27
  /**
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,4EAAmD;AACnD,wEAAoD;AAEpD,kBAAe;IACb;;;;;;;;;;;;;;;OAeG;IACH,iBAAiB,EAAjB,2BAAiB;IAEjB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,oBAAoB,EAApB,yBAAoB;CACrB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,4EAAmD;AACnD,wEAAoD;AAEpD,kBAAe;IACb;;;;;;;;;;;;;;;;OAgBG;IACH,iBAAiB,EAAjB,2BAAiB;IAEjB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,oBAAoB,EAApB,yBAAoB;CACrB,CAAA"}
@@ -7,5 +7,6 @@ export default interface RequestOptions {
7
7
  environmentName?: 'DEV' | 'PRE-PRODUCTION' | 'PRODUCTION';
8
8
  logger?: bunyan | typeof console;
9
9
  includeSharedData?: boolean;
10
+ useFallbacksByDefault?: boolean;
10
11
  timeoutOptions?: TimeoutOptions;
11
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ministryofjustice/hmpps-connect-dps-components",
3
- "version": "2.0.0",
3
+ "version": "2.1.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",