@ministryofjustice/hmpps-connect-dps-components 3.0.0-beta.7 → 3.0.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 CHANGED
@@ -16,10 +16,14 @@ in order to improve it.
16
16
 
17
17
  The package assumes adherance to the standard [hmpps-template-typescript](https://github.com/ministryofjustice/hmpps-template-typescript) project.
18
18
  It requires:
19
+ - the [`hmpps-auth-clients` package](https://github.com/ministryofjustice/hmpps-typescript-lib/tree/main/packages/auth-clients) to be installed and setup so that you are able to create `AuthenticationClients`
19
20
  - a user object to be available on `res.locals` containing a token, displayName, and authSource.
20
21
  - nunjucks to be setup
21
- - an environment variable to be set for the micro frontend components api called `COMPONENT_API_URL`
22
22
  - to be run AFTER helmet middleware
23
+ - API configs defined for the following:
24
+ - [Component API](https://github.com/ministryofjustice/hmpps-micro-frontend-components)
25
+ - (If using the [caseload data middleware](./src/middleware/retrieveCaseLoadData.ts)) - Prison API
26
+ - (If using the [allocation job responsibilities middleware](./src/middleware/retrieveAllocationJobResponsibilities.ts)) - Allocations API config
23
27
 
24
28
  ### Installation
25
29
 
@@ -36,13 +40,16 @@ Currently, the package provides the header and the footer component.
36
40
  To incorporate use the middleware for appropriate routes within your Express application:
37
41
 
38
42
  ```javascript
39
- import dpsComponents from '@ministryofjustice/hmpps-connect-dps-components'
43
+ import { getFrontendComponents } from '@ministryofjustice/hmpps-connect-dps-components'
40
44
 
41
45
  ...
42
46
 
43
- app.use(dpsComponents.getPageComponents({
44
- dpsUrl: config.serviceUrls.digitalPrison,
47
+ app.use(getFrontendComponents({
45
48
  logger,
49
+ authenticationClient: new AuthenticationClient(config.apis.hmppsAuth, logger, services.dataAccess.tokenStore),
50
+ componentApiConfig: config.apis.componentApi,
51
+ dpsUrl: config.serviceUrls.digitalPrison,
52
+ requestOptions: { includeSharedData: true },
46
53
  })
47
54
  )
48
55
  ```
@@ -52,9 +59,12 @@ To incorporate use the middleware for appropriate routes within your Express app
52
59
  It may be sufficient for you app to only request components for GET requests for example, in which case
53
60
 
54
61
  ```javascript
55
- app.get('*', dpsComponents.getPageComponents({
56
- dpsUrl: config.serviceUrls.digitalPrison,
62
+ app.get('*', getFrontendComponents({
57
63
  logger,
64
+ authenticationClient: new AuthenticationClient(config.apis.hmppsAuth, logger, services.dataAccess.tokenStore),
65
+ componentApiConfig: config.apis.componentApi,
66
+ dpsUrl: config.serviceUrls.digitalPrison,
67
+ requestOptions: { includeSharedData: true },
58
68
  })
59
69
  )
60
70
  ```
@@ -68,9 +78,11 @@ something like this to avoid the component API call for the following routes: `/
68
78
  ```javascript
69
79
  app.get(
70
80
  /^(?!\/api|^\/$).*/,
71
- dpsComponents.getPageComponents({
72
- dpsUrl: config.serviceUrls.digitalPrison,
81
+ getFrontendComponents({
73
82
  logger,
83
+ authenticationClient: new AuthenticationClient(config.apis.hmppsAuth, logger, services.dataAccess.tokenStore),
84
+ componentApiConfig: config.apis.componentApi,
85
+ dpsUrl: config.serviceUrls.digitalPrison,
74
86
  }),
75
87
  (req, res) => {
76
88
  res.render('prisonerProfile')
@@ -135,7 +147,13 @@ of routes. e.g. in `setUpAuthentication.ts` on the `/autherror` path:
135
147
  ```javascript
136
148
  router.get(
137
149
  '/autherror',
138
- dpsComponents.getPageComponents({ dpsUrl: config.serviceUrls.digitalPrison }),
150
+ getFrontendComponents({
151
+ logger,
152
+ authenticationClient: new AuthenticationClient(config.apis.hmppsAuth, logger, services.dataAccess.tokenStore),
153
+ componentApiConfig: config.apis.componentApi,
154
+ dpsUrl: config.serviceUrls.digitalPrison,
155
+ requestOptions: { includeSharedData: true },
156
+ }),
139
157
  (req, res) => {
140
158
  res.status(401)
141
159
  return res.render('autherror')
@@ -152,7 +170,7 @@ be run after Helmet to prevent this being overwritten.
152
170
 
153
171
  ### Shared Data
154
172
 
155
- An optional parameter `includeSharedData: true` can be passed into the `get` method. Setting this will result in a
173
+ An optional parameter `includeSharedData: true` can be passed into the `get` methods request options. Setting this will result in a
156
174
  `sharedData` object being added to `res.locals.feComponents` containing data the components have collected to render.
157
175
  This includes:
158
176
 
@@ -179,10 +197,15 @@ call to Prison API to retrieve the data using the user token.
179
197
  To enable this, add the middleware after the component middleware as follows:
180
198
 
181
199
  ```javascript
182
- app.use(dpsComponents.retrieveCaseLoadData({ logger }))
183
- ```
200
+ import { retrieveCaseLoadData } from '@ministryofjustice/hmpps-connect-dps-components'
184
201
 
185
- Again there are a [number of options](./src/index.ts) available depending on your requirements.
202
+ app.use(retrieveCaseLoadData({
203
+ logger,
204
+ authenticationClient: new AuthenticationClient(config.apis.hmppsAuth, logger, services.dataAccess.tokenStore),
205
+ prisonApiConfig: config.apis.prisonApi,
206
+ }),
207
+ )
208
+ ```
186
209
 
187
210
  This middleware checks the `res.locals.user.authSource` so ensure that any mock auth data used in tests includes
188
211
  `auth_source: 'nomis'` in the response.
@@ -199,13 +222,15 @@ call to Allocations API to retrieve the data using the user token.
199
222
  To enable this, add the middleware after the component middleware as follows:
200
223
 
201
224
  ```javascript
202
- app.use(dpsComponents.retrieveAllocationJobResponsibilities({ logger }))
225
+ import { retrieveAllocationJobResponsibilities } from '@ministryofjustice/hmpps-connect-dps-components'
226
+ app.use(retrieveAllocationJobResponsibilities({
227
+ logger,
228
+ authenticationClient: new AuthenticationClient(config.apis.hmppsAuth, logger, services.dataAccess.tokenStore),
229
+ allocationsApiConfig: config.apis.allocationsApi,
230
+ }))
203
231
  ```
204
232
 
205
- This should go after `dpsComponents.retrieveCaseLoadData` so that `res.locals.user.activeCaseLoadId` will be populated.
206
- It also requires `ALLOCATIONS_API_URL` to be configured in the environment variables.
207
-
208
- Again there are a [number of options](./src/index.ts) available depending on your requirements.
233
+ This should go after `retrieveCaseLoadData` so that `res.locals.user.activeCaseLoadId` will be populated.
209
234
 
210
235
  This middleware checks the `res.locals.user.authSource` so ensure that any mock auth data used in tests includes
211
236
  `auth_source: 'nomis'` in the response. It also checks the `res.locals.user.activeCaseLoadId`, which is required for retrieving allocation job responsibilities.
package/dist/index.cjs CHANGED
@@ -131,7 +131,7 @@ class ComponentsService {
131
131
  }
132
132
  }
133
133
 
134
- function getFrontendComponents$1({ logger = console, componentApiConfig, authenticationClient, dpsUrl, requestOptions, }) {
134
+ function getFrontendComponents({ logger = console, componentApiConfig, authenticationClient, dpsUrl, requestOptions, }) {
135
135
  const service = ComponentsService.create({ logger, componentApiConfig, authenticationClient, dpsUrl });
136
136
  return service.getFrontendComponents(requestOptions);
137
137
  }
@@ -252,7 +252,7 @@ class AllocationService {
252
252
  }
253
253
  }
254
254
 
255
- function getFrontendComponents({ logger = console, allocationsApiConfig, authenticationClient, }) {
255
+ function retrieveAllocationJobResponsibilities({ logger = console, allocationsApiConfig, authenticationClient, }) {
256
256
  const service = AllocationService.create({ logger, allocationsApiConfig, authenticationClient });
257
257
  return service.retrieveAllocationJobResponsibilities();
258
258
  }
@@ -260,7 +260,7 @@ function getFrontendComponents({ logger = console, allocationsApiConfig, authent
260
260
  exports.AllocationService = AllocationService;
261
261
  exports.CaseLoadService = CaseLoadService;
262
262
  exports.ComponentsService = ComponentsService;
263
- exports.getFrontendComponents = getFrontendComponents$1;
264
- exports.retrieveAllocationJobResponsibilities = getFrontendComponents;
263
+ exports.getFrontendComponents = getFrontendComponents;
264
+ exports.retrieveAllocationJobResponsibilities = retrieveAllocationJobResponsibilities;
265
265
  exports.retrieveCaseLoadData = retrieveCaseLoadData;
266
266
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/data/componentApi/componentApiClient.ts","../src/utils/fallbacks.ts","../src/utils/updateCsp.ts","../src/componentsService.ts","../src/middleware/getFrontendComponents.ts","../src/data/prisonApi/prisonApiClient.ts","../src/caseLoadService.ts","../src/middleware/retrieveCaseLoadData.ts","../src/data/allocationsApi/allocationsApiClient.ts","../src/allocationService.ts","../src/middleware/retrieveAllocationJobResponsibilities.ts"],"sourcesContent":["import { ApiConfig, asSystem, AuthenticationClient, RestClient } from '@ministryofjustice/hmpps-rest-client'\nimport AvailableComponent from '../../types/AvailableComponent'\nimport Component from '../../types/Component'\nimport { ConnectDpsComponentLogger } from '../../types/ConnectDpsComponentLogger'\nimport { ComponentsSharedData } from '../../types/HeaderFooterSharedData'\n\nexport type ComponentsApiResponse<T extends AvailableComponent[]> = Record<T[number], Component> & {\n meta: ComponentsSharedData[T[number]] // TODO: rename 'meta' in the API response\n}\n\nexport default class ComponentApiClient extends RestClient {\n constructor(logger: ConnectDpsComponentLogger, config: ApiConfig, authenticationClient: AuthenticationClient) {\n super('Component API Client', config, logger, authenticationClient)\n }\n\n async getComponents<T extends AvailableComponent[]>(userToken: string): Promise<ComponentsApiResponse<T>> {\n return this.get<ComponentsApiResponse<T>>(\n {\n path: `/components`,\n query: 'component=header&component=footer',\n headers: { 'x-user-token': userToken },\n },\n asSystem(),\n )\n }\n}\n","import nunjucks from 'nunjucks'\nimport { HmppsUser } from '../types/HmppsUser'\n\nexport function getFallbackHeader(\n user: HmppsUser | null,\n dpsUrl: string,\n { environmentName, authUrl, supportUrl }: { environmentName?: string; authUrl?: string; supportUrl?: string },\n): string {\n return nunjucks.render('dpsComponents/header-bar.njk', {\n isPrisonUser: !user || user.authSource === 'nomis',\n user,\n dpsUrl,\n environmentName,\n authUrl,\n supportUrl,\n name: initialiseName(user?.displayName),\n })\n}\n\nexport function getFallbackFooter(\n user: HmppsUser | null,\n { authUrl, supportUrl }: { authUrl?: string; supportUrl?: string },\n): string {\n return nunjucks.render('dpsComponents/footer.njk', {\n isPrisonUser: !user || user.authSource === 'nomis',\n supportUrl,\n authUrl,\n })\n}\n\nfunction initialiseName(fullName?: string): string | null {\n if (!fullName) return null\n\n const array = fullName.split(' ')\n return `${array[0][0]}. ${array.reverse()[0]}`\n}\n","import { type Response } from 'express'\n\nexport default function updateCsp(feComponentsUrl: string, res: Response) {\n const csp = res.getHeaders()['content-security-policy']\n const allDirectives = csp?.split(';') ?? []\n const directivesToUpdate = ['script-src', 'style-src', 'img-src', 'font-src']\n\n const updatedCspDirectives = allDirectives.map(directive => {\n // if directive is not in cspToUpdate or includes fe components url already return as is\n if (directive.includes(feComponentsUrl as string) || !directivesToUpdate.some(p => directive.includes(`${p} `)))\n return directive\n\n // if directive is in cspToUpdate and does not have fe components url, add in\n return `${directive} ${feComponentsUrl}`\n })\n\n const requiredAndNotPresent = directivesToUpdate\n .filter(p => !updatedCspDirectives.find(directive => directive.includes(`${p} `)))\n .map(p => `${p} 'self' ${feComponentsUrl}`)\n\n res.set('content-security-policy', [...updatedCspDirectives, ...requiredAndNotPresent].join(';'))\n}\n","import { type NextFunction, type Request, type Response, type RequestHandler } from 'express'\nimport { ApiConfig, AuthenticationClient } from '@ministryofjustice/hmpps-rest-client'\nimport ComponentApiClient from './data/componentApi/componentApiClient'\nimport { getFallbackFooter, getFallbackHeader } from './utils/fallbacks'\nimport updateCsp from './utils/updateCsp'\nimport { HmppsUser } from './types/HmppsUser'\nimport { ConnectDpsComponentLogger } from './types/ConnectDpsComponentLogger'\n\nexport interface FrontendComponentRequestOptions {\n authUrl?: string\n supportUrl?: string\n environmentName?: 'DEV' | 'PRE-PRODUCTION' | 'PRODUCTION'\n includeSharedData?: boolean\n useFallbacksByDefault?: boolean\n}\n\nconst defaultOptions: Partial<FrontendComponentRequestOptions> = {\n includeSharedData: false,\n useFallbacksByDefault: false,\n}\n\nexport default class ComponentsService {\n constructor(\n private readonly logger: ConnectDpsComponentLogger,\n private readonly componentApiConfig: ApiConfig,\n private readonly componentApiClient: ComponentApiClient,\n private readonly dpsUrl: string,\n ) {}\n\n static create({\n logger = console,\n componentApiConfig,\n authenticationClient,\n dpsUrl,\n }: {\n logger?: ConnectDpsComponentLogger\n componentApiConfig: ApiConfig\n authenticationClient: AuthenticationClient\n dpsUrl: string\n }) {\n return new ComponentsService(\n logger,\n componentApiConfig,\n new ComponentApiClient(logger, componentApiConfig, authenticationClient),\n dpsUrl,\n )\n }\n\n getFrontendComponents(requestOptions?: FrontendComponentRequestOptions): RequestHandler {\n const requestOptionsWithDefaults = {\n ...defaultOptions,\n ...(requestOptions || {}),\n }\n const { includeSharedData, useFallbacksByDefault } = requestOptionsWithDefaults\n\n return async (_req: Request, res: Response, next: NextFunction) => {\n const useFallbacks = (user: HmppsUser | null) => {\n res.locals.feComponents = {\n header: getFallbackHeader(user, this.dpsUrl, {\n environmentName: requestOptionsWithDefaults.environmentName,\n authUrl: requestOptionsWithDefaults.authUrl,\n supportUrl: requestOptionsWithDefaults.supportUrl,\n }),\n footer: getFallbackFooter(user, {\n authUrl: requestOptionsWithDefaults.authUrl,\n supportUrl: requestOptionsWithDefaults.supportUrl,\n }),\n cssIncludes: [],\n jsIncludes: [],\n }\n }\n\n if (!res.locals.user) {\n this.logger.info('Using fallback frontend components when no user in context')\n useFallbacks(null)\n return next()\n }\n\n if (useFallbacksByDefault) {\n this.logger.info('Using fallback frontend components by default')\n useFallbacks(res.locals.user)\n return next()\n }\n\n try {\n const { header, footer, meta } = await this.componentApiClient.getComponents(res.locals.user.token as string)\n\n res.locals.feComponents = {\n header: header.html,\n footer: footer.html,\n cssIncludes: [...header.css, ...footer.css],\n jsIncludes: [...header.javascript, ...footer.javascript],\n }\n\n if (includeSharedData) {\n res.locals.feComponents.sharedData = meta\n }\n\n updateCsp(this.componentApiConfig.url, res)\n\n return next()\n } catch (_error) {\n this.logger.error('Failed to retrieve front end components, using fallbacks')\n useFallbacks(res.locals.user)\n return next()\n }\n }\n }\n}\n","import { type RequestHandler } from 'express'\nimport ComponentsService, { FrontendComponentRequestOptions } from '../componentsService'\n\ntype MiddlewareOptions = {\n requestOptions?: FrontendComponentRequestOptions\n} & Parameters<typeof ComponentsService.create>[0]\n\nexport default function getFrontendComponents({\n logger = console,\n componentApiConfig,\n authenticationClient,\n dpsUrl,\n requestOptions,\n}: MiddlewareOptions): RequestHandler {\n const service = ComponentsService.create({ logger, componentApiConfig, authenticationClient, dpsUrl })\n return service.getFrontendComponents(requestOptions)\n}\n","import { ApiConfig, asUser, AuthenticationClient, RestClient } from '@ministryofjustice/hmpps-rest-client'\nimport CaseLoad from '../../types/CaseLoad'\nimport { ConnectDpsComponentLogger } from '../../types/ConnectDpsComponentLogger'\n\nexport default class PrisonApiClient extends RestClient {\n constructor(logger: ConnectDpsComponentLogger, config: ApiConfig, authenticationClient: AuthenticationClient) {\n super('Prison API Client', config, logger, authenticationClient)\n }\n\n async getUserCaseLoads(userToken: string): Promise<CaseLoad[]> {\n return this.get<CaseLoad[]>(\n {\n path: '/api/users/me/caseLoads',\n query: 'allCaseloads=true',\n },\n asUser(userToken),\n )\n }\n}\n","import { type RequestHandler } from 'express'\nimport { ApiConfig, AuthenticationClient } from '@ministryofjustice/hmpps-rest-client'\nimport CaseLoad from './types/CaseLoad'\nimport PrisonApiClient from './data/prisonApi/prisonApiClient'\nimport { ConnectDpsComponentLogger } from './types/ConnectDpsComponentLogger'\n\nexport default class CaseLoadService {\n constructor(\n private readonly logger: ConnectDpsComponentLogger,\n private readonly prisonApiClient: PrisonApiClient,\n ) {}\n\n static create({\n logger = console,\n prisonApiConfig,\n authenticationClient,\n }: {\n logger?: ConnectDpsComponentLogger\n prisonApiConfig: ApiConfig\n authenticationClient: AuthenticationClient\n }) {\n return new CaseLoadService(logger, new PrisonApiClient(logger, prisonApiConfig, authenticationClient))\n }\n\n retrieveCaseLoadData(): RequestHandler {\n return async (req, res, next) => {\n if (!req.session) throw new Error('User session required in order to cache case loads')\n\n if (res.locals.user && res.locals.user.token && res.locals.user.authSource === 'nomis') {\n try {\n // Update cache with values from res.feComponents.sharedData if present\n if (res.locals.feComponents && res.locals.feComponents.sharedData) {\n req.session.caseLoads = res.locals.feComponents.sharedData.caseLoads\n req.session.activeCaseLoad = res.locals.feComponents.sharedData.activeCaseLoad\n req.session.activeCaseLoadId = res.locals.feComponents.sharedData.activeCaseLoad?.caseLoadId\n }\n\n // If cache is empty, fetch data from Prison API\n if (!req.session.caseLoads) {\n this.logger.info(`Falling back to Prison API to retrieve case loads for: ${res.locals.user.username}`)\n const userCaseLoads = await this.prisonApiClient.getUserCaseLoads(res.locals.user.token)\n const caseLoads = userCaseLoads.filter(caseload => caseload.type !== 'APP')\n const activeCaseLoad = caseLoads.find((caseLoad: CaseLoad) => caseLoad.currentlyActive)\n\n req.session.caseLoads = caseLoads\n req.session.activeCaseLoad = activeCaseLoad\n req.session.activeCaseLoadId = activeCaseLoad?.caseLoadId\n }\n\n // Populate res.locals.user with values from cache\n res.locals.user.caseLoads = req.session.caseLoads\n res.locals.user.activeCaseLoad = req.session.activeCaseLoad\n res.locals.user.activeCaseLoadId = req.session.activeCaseLoadId\n } catch (error) {\n this.logger.error(error, `Failed to retrieve case loads for: ${res.locals.user.username}`)\n return next(error)\n }\n }\n\n return next()\n }\n }\n}\n","import { type RequestHandler } from 'express'\nimport CaseLoadService from '../caseLoadService'\n\nexport default function retrieveCaseLoadData({\n logger = console,\n prisonApiConfig,\n authenticationClient,\n}: Parameters<typeof CaseLoadService.create>[0]): RequestHandler {\n const service = CaseLoadService.create({ logger, prisonApiConfig, authenticationClient })\n return service.retrieveCaseLoadData()\n}\n","import { ApiConfig, asSystem, AuthenticationClient, RestClient } from '@ministryofjustice/hmpps-rest-client'\nimport { PrisonUser } from '../../types/HmppsUser'\nimport { AllocationJobResponsibility } from '../../types/AllocationJobResponsibility'\nimport { ConnectDpsComponentLogger } from '../../types/ConnectDpsComponentLogger'\n\nexport default class AllocationsApiClient extends RestClient {\n constructor(logger: ConnectDpsComponentLogger, config: ApiConfig, authenticationClient: AuthenticationClient) {\n super('Allocations API Client', config, logger, authenticationClient)\n }\n\n async getStaffAllocationPolicies(user: PrisonUser): Promise<{ policies: AllocationJobResponsibility[] }> {\n return this.get<{ policies: AllocationJobResponsibility[] }>(\n {\n path: `/prisons/${user.activeCaseLoadId}/staff/${user.userId}/job-classifications`,\n },\n asSystem(),\n )\n }\n}\n","import { type RequestHandler } from 'express'\nimport { ApiConfig, AuthenticationClient } from '@ministryofjustice/hmpps-rest-client'\nimport AllocationsApiClient from './data/allocationsApi/allocationsApiClient'\nimport { ConnectDpsComponentLogger } from './types/ConnectDpsComponentLogger'\n\nexport default class AllocationService {\n constructor(\n private readonly logger: ConnectDpsComponentLogger,\n private readonly allocationsApiClient: AllocationsApiClient,\n ) {}\n\n static create({\n logger = console,\n allocationsApiConfig,\n authenticationClient,\n }: {\n logger?: ConnectDpsComponentLogger\n allocationsApiConfig: ApiConfig\n authenticationClient: AuthenticationClient\n }) {\n return new AllocationService(logger, new AllocationsApiClient(logger, allocationsApiConfig, authenticationClient))\n }\n\n public retrieveAllocationJobResponsibilities(): RequestHandler {\n return async (req, res, next) => {\n if (!req.session) throw new Error('User session required in order to cache allocation job responsibilities')\n if (!res.locals.user.token)\n throw new Error(\n 'Caseload details needs to be populated before retrieving allocation job responsibilities. Please run retrieveCaseLoadData before retrieveAllocationJobResponsibilities.',\n )\n\n if (res.locals.user && res.locals.user.authSource === 'nomis') {\n try {\n // Update cache with values from res.feComponents.sharedData if present\n if (res.locals.feComponents && res.locals.feComponents.sharedData) {\n req.session.allocationJobResponsibilities = res.locals.feComponents.sharedData.allocationJobResponsibilities\n }\n\n // If cache is empty, fetch data from Prison API\n if (!req.session.allocationJobResponsibilities) {\n this.logger.info(\n `Falling back to Allocations API to retrieve job responsibilities for: ${res.locals.user.username}`,\n )\n const allocationPolicies = await this.allocationsApiClient.getStaffAllocationPolicies(res.locals.user)\n req.session.allocationJobResponsibilities = allocationPolicies.policies\n }\n\n // Populate res.locals.user with values from cache\n res.locals.user.allocationJobResponsibilities = req.session.allocationJobResponsibilities\n } catch (error) {\n this.logger.error(\n error,\n `Failed to retrieve allocation job responsibilities for: ${res.locals.user.username}`,\n )\n return next(error)\n }\n }\n\n return next()\n }\n }\n}\n","import { type RequestHandler } from 'express'\nimport AllocationService from '../allocationService'\n\nexport default function getFrontendComponents({\n logger = console,\n allocationsApiConfig,\n authenticationClient,\n}: Parameters<typeof AllocationService.create>[0]): RequestHandler {\n const service = AllocationService.create({ logger, allocationsApiConfig, authenticationClient })\n return service.retrieveAllocationJobResponsibilities()\n}\n"],"names":["RestClient","asSystem","getFrontendComponents","asUser"],"mappings":";;;;;AAUc,MAAO,kBAAmB,SAAQA,0BAAU,CAAA;AACxD,IAAA,WAAA,CAAY,MAAiC,EAAE,MAAiB,EAAE,oBAA0C,EAAA;QAC1G,KAAK,CAAC,sBAAsB,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,CAAC;IACrE;IAEA,MAAM,aAAa,CAAiC,SAAiB,EAAA;QACnE,OAAO,IAAI,CAAC,GAAG,CACb;AACE,YAAA,IAAI,EAAE,CAAA,WAAA,CAAa;AACnB,YAAA,KAAK,EAAE,mCAAmC;AAC1C,YAAA,OAAO,EAAE,EAAE,cAAc,EAAE,SAAS,EAAE;SACvC,EACDC,wBAAQ,EAAE,CACX;IACH;AACD;;ACtBK,SAAU,iBAAiB,CAC/B,IAAsB,EACtB,MAAc,EACd,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAuE,EAAA;AAE7G,IAAA,OAAO,QAAQ,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;AACV,QAAA,IAAI,EAAE,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC;AACxC,KAAA,CAAC;AACJ;AAEM,SAAU,iBAAiB,CAC/B,IAAsB,EACtB,EAAE,OAAO,EAAE,UAAU,EAA6C,EAAA;AAElE,IAAA,OAAO,QAAQ,CAAC,MAAM,CAAC,0BAA0B,EAAE;QACjD,YAAY,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,OAAO;QAClD,UAAU;QACV,OAAO;AACR,KAAA,CAAC;AACJ;AAEA,SAAS,cAAc,CAAC,QAAiB,EAAA;AACvC,IAAA,IAAI,CAAC,QAAQ;AAAE,QAAA,OAAO,IA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index.cjs","sources":["../src/data/componentApi/componentApiClient.ts","../src/utils/fallbacks.ts","../src/utils/updateCsp.ts","../src/componentsService.ts","../src/middleware/getFrontendComponents.ts","../src/data/prisonApi/prisonApiClient.ts","../src/caseLoadService.ts","../src/middleware/retrieveCaseLoadData.ts","../src/data/allocationsApi/allocationsApiClient.ts","../src/allocationService.ts","../src/middleware/retrieveAllocationJobResponsibilities.ts"],"sourcesContent":["import { ApiConfig, asSystem, AuthenticationClient, RestClient } from '@ministryofjustice/hmpps-rest-client'\nimport AvailableComponent from '../../types/AvailableComponent'\nimport Component from '../../types/Component'\nimport { ConnectDpsComponentLogger } from '../../types/ConnectDpsComponentLogger'\nimport { ComponentsSharedData } from '../../types/HeaderFooterSharedData'\n\nexport type ComponentsApiResponse<T extends AvailableComponent[]> = Record<T[number], Component> & {\n meta: ComponentsSharedData[T[number]] // TODO: rename 'meta' in the API response\n}\n\nexport default class ComponentApiClient extends RestClient {\n constructor(logger: ConnectDpsComponentLogger, config: ApiConfig, authenticationClient: AuthenticationClient) {\n super('Component API Client', config, logger, authenticationClient)\n }\n\n async getComponents<T extends AvailableComponent[]>(userToken: string): Promise<ComponentsApiResponse<T>> {\n return this.get<ComponentsApiResponse<T>>(\n {\n path: `/components`,\n query: 'component=header&component=footer',\n headers: { 'x-user-token': userToken },\n },\n asSystem(),\n )\n }\n}\n","import nunjucks from 'nunjucks'\nimport { HmppsUser } from '../types/HmppsUser'\n\nexport function getFallbackHeader(\n user: HmppsUser | null,\n dpsUrl: string,\n { environmentName, authUrl, supportUrl }: { environmentName?: string; authUrl?: string; supportUrl?: string },\n): string {\n return nunjucks.render('dpsComponents/header-bar.njk', {\n isPrisonUser: !user || user.authSource === 'nomis',\n user,\n dpsUrl,\n environmentName,\n authUrl,\n supportUrl,\n name: initialiseName(user?.displayName),\n })\n}\n\nexport function getFallbackFooter(\n user: HmppsUser | null,\n { authUrl, supportUrl }: { authUrl?: string; supportUrl?: string },\n): string {\n return nunjucks.render('dpsComponents/footer.njk', {\n isPrisonUser: !user || user.authSource === 'nomis',\n supportUrl,\n authUrl,\n })\n}\n\nfunction initialiseName(fullName?: string): string | null {\n if (!fullName) return null\n\n const array = fullName.split(' ')\n return `${array[0][0]}. ${array.reverse()[0]}`\n}\n","import { type Response } from 'express'\n\nexport default function updateCsp(feComponentsUrl: string, res: Response) {\n const csp = res.getHeaders()['content-security-policy']\n const allDirectives = csp?.split(';') ?? []\n const directivesToUpdate = ['script-src', 'style-src', 'img-src', 'font-src']\n\n const updatedCspDirectives = allDirectives.map(directive => {\n // if directive is not in cspToUpdate or includes fe components url already return as is\n if (directive.includes(feComponentsUrl as string) || !directivesToUpdate.some(p => directive.includes(`${p} `)))\n return directive\n\n // if directive is in cspToUpdate and does not have fe components url, add in\n return `${directive} ${feComponentsUrl}`\n })\n\n const requiredAndNotPresent = directivesToUpdate\n .filter(p => !updatedCspDirectives.find(directive => directive.includes(`${p} `)))\n .map(p => `${p} 'self' ${feComponentsUrl}`)\n\n res.set('content-security-policy', [...updatedCspDirectives, ...requiredAndNotPresent].join(';'))\n}\n","import { type NextFunction, type Request, type Response, type RequestHandler } from 'express'\nimport { ApiConfig, AuthenticationClient } from '@ministryofjustice/hmpps-rest-client'\nimport ComponentApiClient from './data/componentApi/componentApiClient'\nimport { getFallbackFooter, getFallbackHeader } from './utils/fallbacks'\nimport updateCsp from './utils/updateCsp'\nimport { HmppsUser } from './types/HmppsUser'\nimport { ConnectDpsComponentLogger } from './types/ConnectDpsComponentLogger'\n\nexport interface FrontendComponentRequestOptions {\n authUrl?: string\n supportUrl?: string\n environmentName?: 'DEV' | 'PRE-PRODUCTION' | 'PRODUCTION'\n includeSharedData?: boolean\n useFallbacksByDefault?: boolean\n}\n\nconst defaultOptions: Partial<FrontendComponentRequestOptions> = {\n includeSharedData: false,\n useFallbacksByDefault: false,\n}\n\nexport default class ComponentsService {\n constructor(\n private readonly logger: ConnectDpsComponentLogger,\n private readonly componentApiConfig: ApiConfig,\n private readonly componentApiClient: ComponentApiClient,\n private readonly dpsUrl: string,\n ) {}\n\n static create({\n logger = console,\n componentApiConfig,\n authenticationClient,\n dpsUrl,\n }: {\n logger?: ConnectDpsComponentLogger\n componentApiConfig: ApiConfig\n authenticationClient: AuthenticationClient\n dpsUrl: string\n }) {\n return new ComponentsService(\n logger,\n componentApiConfig,\n new ComponentApiClient(logger, componentApiConfig, authenticationClient),\n dpsUrl,\n )\n }\n\n getFrontendComponents(requestOptions?: FrontendComponentRequestOptions): RequestHandler {\n const requestOptionsWithDefaults = {\n ...defaultOptions,\n ...(requestOptions || {}),\n }\n const { includeSharedData, useFallbacksByDefault } = requestOptionsWithDefaults\n\n return async (_req: Request, res: Response, next: NextFunction) => {\n const useFallbacks = (user: HmppsUser | null) => {\n res.locals.feComponents = {\n header: getFallbackHeader(user, this.dpsUrl, {\n environmentName: requestOptionsWithDefaults.environmentName,\n authUrl: requestOptionsWithDefaults.authUrl,\n supportUrl: requestOptionsWithDefaults.supportUrl,\n }),\n footer: getFallbackFooter(user, {\n authUrl: requestOptionsWithDefaults.authUrl,\n supportUrl: requestOptionsWithDefaults.supportUrl,\n }),\n cssIncludes: [],\n jsIncludes: [],\n }\n }\n\n if (!res.locals.user) {\n this.logger.info('Using fallback frontend components when no user in context')\n useFallbacks(null)\n return next()\n }\n\n if (useFallbacksByDefault) {\n this.logger.info('Using fallback frontend components by default')\n useFallbacks(res.locals.user)\n return next()\n }\n\n try {\n const { header, footer, meta } = await this.componentApiClient.getComponents(res.locals.user.token as string)\n\n res.locals.feComponents = {\n header: header.html,\n footer: footer.html,\n cssIncludes: [...header.css, ...footer.css],\n jsIncludes: [...header.javascript, ...footer.javascript],\n }\n\n if (includeSharedData) {\n res.locals.feComponents.sharedData = meta\n }\n\n updateCsp(this.componentApiConfig.url, res)\n\n return next()\n } catch (_error) {\n this.logger.error('Failed to retrieve front end components, using fallbacks')\n useFallbacks(res.locals.user)\n return next()\n }\n }\n }\n}\n","import { type RequestHandler } from 'express'\nimport ComponentsService, { FrontendComponentRequestOptions } from '../componentsService'\n\ntype MiddlewareOptions = {\n requestOptions?: FrontendComponentRequestOptions\n} & Parameters<typeof ComponentsService.create>[0]\n\nexport default function getFrontendComponents({\n logger = console,\n componentApiConfig,\n authenticationClient,\n dpsUrl,\n requestOptions,\n}: MiddlewareOptions): RequestHandler {\n const service = ComponentsService.create({ logger, componentApiConfig, authenticationClient, dpsUrl })\n return service.getFrontendComponents(requestOptions)\n}\n","import { ApiConfig, asUser, AuthenticationClient, RestClient } from '@ministryofjustice/hmpps-rest-client'\nimport CaseLoad from '../../types/CaseLoad'\nimport { ConnectDpsComponentLogger } from '../../types/ConnectDpsComponentLogger'\n\nexport default class PrisonApiClient extends RestClient {\n constructor(logger: ConnectDpsComponentLogger, config: ApiConfig, authenticationClient: AuthenticationClient) {\n super('Prison API Client', config, logger, authenticationClient)\n }\n\n async getUserCaseLoads(userToken: string): Promise<CaseLoad[]> {\n return this.get<CaseLoad[]>(\n {\n path: '/api/users/me/caseLoads',\n query: 'allCaseloads=true',\n },\n asUser(userToken),\n )\n }\n}\n","import { type RequestHandler } from 'express'\nimport { ApiConfig, AuthenticationClient } from '@ministryofjustice/hmpps-rest-client'\nimport CaseLoad from './types/CaseLoad'\nimport PrisonApiClient from './data/prisonApi/prisonApiClient'\nimport { ConnectDpsComponentLogger } from './types/ConnectDpsComponentLogger'\n\nexport default class CaseLoadService {\n constructor(\n private readonly logger: ConnectDpsComponentLogger,\n private readonly prisonApiClient: PrisonApiClient,\n ) {}\n\n static create({\n logger = console,\n prisonApiConfig,\n authenticationClient,\n }: {\n logger?: ConnectDpsComponentLogger\n prisonApiConfig: ApiConfig\n authenticationClient: AuthenticationClient\n }) {\n return new CaseLoadService(logger, new PrisonApiClient(logger, prisonApiConfig, authenticationClient))\n }\n\n retrieveCaseLoadData(): RequestHandler {\n return async (req, res, next) => {\n if (!req.session) throw new Error('User session required in order to cache case loads')\n\n if (res.locals.user && res.locals.user.token && res.locals.user.authSource === 'nomis') {\n try {\n // Update cache with values from res.feComponents.sharedData if present\n if (res.locals.feComponents && res.locals.feComponents.sharedData) {\n req.session.caseLoads = res.locals.feComponents.sharedData.caseLoads\n req.session.activeCaseLoad = res.locals.feComponents.sharedData.activeCaseLoad\n req.session.activeCaseLoadId = res.locals.feComponents.sharedData.activeCaseLoad?.caseLoadId\n }\n\n // If cache is empty, fetch data from Prison API\n if (!req.session.caseLoads) {\n this.logger.info(`Falling back to Prison API to retrieve case loads for: ${res.locals.user.username}`)\n const userCaseLoads = await this.prisonApiClient.getUserCaseLoads(res.locals.user.token)\n const caseLoads = userCaseLoads.filter(caseload => caseload.type !== 'APP')\n const activeCaseLoad = caseLoads.find((caseLoad: CaseLoad) => caseLoad.currentlyActive)\n\n req.session.caseLoads = caseLoads\n req.session.activeCaseLoad = activeCaseLoad\n req.session.activeCaseLoadId = activeCaseLoad?.caseLoadId\n }\n\n // Populate res.locals.user with values from cache\n res.locals.user.caseLoads = req.session.caseLoads\n res.locals.user.activeCaseLoad = req.session.activeCaseLoad\n res.locals.user.activeCaseLoadId = req.session.activeCaseLoadId\n } catch (error) {\n this.logger.error(error, `Failed to retrieve case loads for: ${res.locals.user.username}`)\n return next(error)\n }\n }\n\n return next()\n }\n }\n}\n","import { type RequestHandler } from 'express'\nimport CaseLoadService from '../caseLoadService'\n\nexport default function retrieveCaseLoadData({\n logger = console,\n prisonApiConfig,\n authenticationClient,\n}: Parameters<typeof CaseLoadService.create>[0]): RequestHandler {\n const service = CaseLoadService.create({ logger, prisonApiConfig, authenticationClient })\n return service.retrieveCaseLoadData()\n}\n","import { ApiConfig, asSystem, AuthenticationClient, RestClient } from '@ministryofjustice/hmpps-rest-client'\nimport { PrisonUser } from '../../types/HmppsUser'\nimport { AllocationJobResponsibility } from '../../types/AllocationJobResponsibility'\nimport { ConnectDpsComponentLogger } from '../../types/ConnectDpsComponentLogger'\n\nexport default class AllocationsApiClient extends RestClient {\n constructor(logger: ConnectDpsComponentLogger, config: ApiConfig, authenticationClient: AuthenticationClient) {\n super('Allocations API Client', config, logger, authenticationClient)\n }\n\n async getStaffAllocationPolicies(user: PrisonUser): Promise<{ policies: AllocationJobResponsibility[] }> {\n return this.get<{ policies: AllocationJobResponsibility[] }>(\n {\n path: `/prisons/${user.activeCaseLoadId}/staff/${user.userId}/job-classifications`,\n },\n asSystem(),\n )\n }\n}\n","import { type RequestHandler } from 'express'\nimport { ApiConfig, AuthenticationClient } from '@ministryofjustice/hmpps-rest-client'\nimport AllocationsApiClient from './data/allocationsApi/allocationsApiClient'\nimport { ConnectDpsComponentLogger } from './types/ConnectDpsComponentLogger'\n\nexport default class AllocationService {\n constructor(\n private readonly logger: ConnectDpsComponentLogger,\n private readonly allocationsApiClient: AllocationsApiClient,\n ) {}\n\n static create({\n logger = console,\n allocationsApiConfig,\n authenticationClient,\n }: {\n logger?: ConnectDpsComponentLogger\n allocationsApiConfig: ApiConfig\n authenticationClient: AuthenticationClient\n }) {\n return new AllocationService(logger, new AllocationsApiClient(logger, allocationsApiConfig, authenticationClient))\n }\n\n public retrieveAllocationJobResponsibilities(): RequestHandler {\n return async (req, res, next) => {\n if (!req.session) throw new Error('User session required in order to cache allocation job responsibilities')\n if (!res.locals.user.token)\n throw new Error(\n 'Caseload details needs to be populated before retrieving allocation job responsibilities. Please run retrieveCaseLoadData before retrieveAllocationJobResponsibilities.',\n )\n\n if (res.locals.user && res.locals.user.authSource === 'nomis') {\n try {\n // Update cache with values from res.feComponents.sharedData if present\n if (res.locals.feComponents && res.locals.feComponents.sharedData) {\n req.session.allocationJobResponsibilities = res.locals.feComponents.sharedData.allocationJobResponsibilities\n }\n\n // If cache is empty, fetch data from Prison API\n if (!req.session.allocationJobResponsibilities) {\n this.logger.info(\n `Falling back to Allocations API to retrieve job responsibilities for: ${res.locals.user.username}`,\n )\n const allocationPolicies = await this.allocationsApiClient.getStaffAllocationPolicies(res.locals.user)\n req.session.allocationJobResponsibilities = allocationPolicies.policies\n }\n\n // Populate res.locals.user with values from cache\n res.locals.user.allocationJobResponsibilities = req.session.allocationJobResponsibilities\n } catch (error) {\n this.logger.error(\n error,\n `Failed to retrieve allocation job responsibilities for: ${res.locals.user.username}`,\n )\n return next(error)\n }\n }\n\n return next()\n }\n }\n}\n","import { type RequestHandler } from 'express'\nimport AllocationService from '../allocationService'\n\nexport default function retrieveAllocationJobResponsibilities({\n logger = console,\n allocationsApiConfig,\n authenticationClient,\n}: Parameters<typeof AllocationService.create>[0]): RequestHandler {\n const service = AllocationService.create({ logger, allocationsApiConfig, authenticationClient })\n return service.retrieveAllocationJobResponsibilities()\n}\n"],"names":["RestClient","asSystem","asUser"],"mappings":";;;;;AAUc,MAAO,kBAAmB,SAAQA,0BAAU,CAAA;AACxD,IAAA,WAAA,CAAY,MAAiC,EAAE,MAAiB,EAAE,oBAA0C,EAAA;QAC1G,KAAK,CAAC,sBAAsB,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,CAAC;IACrE;IAEA,MAAM,aAAa,CAAiC,SAAiB,EAAA;QACnE,OAAO,IAAI,CAAC,GAAG,CACb;AACE,YAAA,IAAI,EAAE,CAAA,WAAA,CAAa;AACnB,YAAA,KAAK,EAAE,mCAAmC;AAC1C,YAAA,OAAO,EAAE,EAAE,cAAc,EAAE,SAAS,EAAE;SACvC,EACDC,wBAAQ,EAAE,CACX;IACH;AACD;;ACtBK,SAAU,iBAAiB,CAC/B,IAAsB,EACtB,MAAc,EACd,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAuE,EAAA;AAE7G,IAAA,OAAO,QAAQ,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;AACV,QAAA,IAAI,EAAE,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC;AACxC,KAAA,CAAC;AACJ;AAEM,SAAU,iBAAiB,CAC/B,IAAsB,EACtB,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H;AACD;;AC1Da,SAAU,qCAAqC,CAAC,EAC5D,MAAM,GAAG,OAAO,EAChB,oBAAoB,EACpB,oBAAoB,GAC2B,EAAA;AAC/C,IAAA,MAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,CAAC;AAChG,IAAA,OAAO,OAAO,CAAC,qCAAqC,EAAE;AACxD;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -140,10 +140,10 @@ declare class AllocationService {
140
140
  type MiddlewareOptions = {
141
141
  requestOptions?: FrontendComponentRequestOptions;
142
142
  } & Parameters<typeof ComponentsService.create>[0];
143
- declare function getFrontendComponents$1({ logger, componentApiConfig, authenticationClient, dpsUrl, requestOptions, }: MiddlewareOptions): RequestHandler;
143
+ declare function getFrontendComponents({ logger, componentApiConfig, authenticationClient, dpsUrl, requestOptions, }: MiddlewareOptions): RequestHandler;
144
144
 
145
145
  declare function retrieveCaseLoadData({ logger, prisonApiConfig, authenticationClient, }: Parameters<typeof CaseLoadService.create>[0]): RequestHandler;
146
146
 
147
- declare function getFrontendComponents({ logger, allocationsApiConfig, authenticationClient, }: Parameters<typeof AllocationService.create>[0]): RequestHandler;
147
+ declare function retrieveAllocationJobResponsibilities({ logger, allocationsApiConfig, authenticationClient, }: Parameters<typeof AllocationService.create>[0]): RequestHandler;
148
148
 
149
- export { AllocationService, CaseLoadService, ComponentsService, getFrontendComponents$1 as getFrontendComponents, getFrontendComponents as retrieveAllocationJobResponsibilities, retrieveCaseLoadData };
149
+ export { AllocationService, CaseLoadService, ComponentsService, getFrontendComponents, retrieveAllocationJobResponsibilities, retrieveCaseLoadData };
package/dist/index.esm.js CHANGED
@@ -129,7 +129,7 @@ class ComponentsService {
129
129
  }
130
130
  }
131
131
 
132
- function getFrontendComponents$1({ logger = console, componentApiConfig, authenticationClient, dpsUrl, requestOptions, }) {
132
+ function getFrontendComponents({ logger = console, componentApiConfig, authenticationClient, dpsUrl, requestOptions, }) {
133
133
  const service = ComponentsService.create({ logger, componentApiConfig, authenticationClient, dpsUrl });
134
134
  return service.getFrontendComponents(requestOptions);
135
135
  }
@@ -250,10 +250,10 @@ class AllocationService {
250
250
  }
251
251
  }
252
252
 
253
- function getFrontendComponents({ logger = console, allocationsApiConfig, authenticationClient, }) {
253
+ function retrieveAllocationJobResponsibilities({ logger = console, allocationsApiConfig, authenticationClient, }) {
254
254
  const service = AllocationService.create({ logger, allocationsApiConfig, authenticationClient });
255
255
  return service.retrieveAllocationJobResponsibilities();
256
256
  }
257
257
 
258
- export { AllocationService, CaseLoadService, ComponentsService, getFrontendComponents$1 as getFrontendComponents, getFrontendComponents as retrieveAllocationJobResponsibilities, retrieveCaseLoadData };
258
+ export { AllocationService, CaseLoadService, ComponentsService, getFrontendComponents, retrieveAllocationJobResponsibilities, retrieveCaseLoadData };
259
259
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/data/componentApi/componentApiClient.ts","../src/utils/fallbacks.ts","../src/utils/updateCsp.ts","../src/componentsService.ts","../src/middleware/getFrontendComponents.ts","../src/data/prisonApi/prisonApiClient.ts","../src/caseLoadService.ts","../src/middleware/retrieveCaseLoadData.ts","../src/data/allocationsApi/allocationsApiClient.ts","../src/allocationService.ts","../src/middleware/retrieveAllocationJobResponsibilities.ts"],"sourcesContent":["import { ApiConfig, asSystem, AuthenticationClient, RestClient } from '@ministryofjustice/hmpps-rest-client'\nimport AvailableComponent from '../../types/AvailableComponent'\nimport Component from '../../types/Component'\nimport { ConnectDpsComponentLogger } from '../../types/ConnectDpsComponentLogger'\nimport { ComponentsSharedData } from '../../types/HeaderFooterSharedData'\n\nexport type ComponentsApiResponse<T extends AvailableComponent[]> = Record<T[number], Component> & {\n meta: ComponentsSharedData[T[number]] // TODO: rename 'meta' in the API response\n}\n\nexport default class ComponentApiClient extends RestClient {\n constructor(logger: ConnectDpsComponentLogger, config: ApiConfig, authenticationClient: AuthenticationClient) {\n super('Component API Client', config, logger, authenticationClient)\n }\n\n async getComponents<T extends AvailableComponent[]>(userToken: string): Promise<ComponentsApiResponse<T>> {\n return this.get<ComponentsApiResponse<T>>(\n {\n path: `/components`,\n query: 'component=header&component=footer',\n headers: { 'x-user-token': userToken },\n },\n asSystem(),\n )\n }\n}\n","import nunjucks from 'nunjucks'\nimport { HmppsUser } from '../types/HmppsUser'\n\nexport function getFallbackHeader(\n user: HmppsUser | null,\n dpsUrl: string,\n { environmentName, authUrl, supportUrl }: { environmentName?: string; authUrl?: string; supportUrl?: string },\n): string {\n return nunjucks.render('dpsComponents/header-bar.njk', {\n isPrisonUser: !user || user.authSource === 'nomis',\n user,\n dpsUrl,\n environmentName,\n authUrl,\n supportUrl,\n name: initialiseName(user?.displayName),\n })\n}\n\nexport function getFallbackFooter(\n user: HmppsUser | null,\n { authUrl, supportUrl }: { authUrl?: string; supportUrl?: string },\n): string {\n return nunjucks.render('dpsComponents/footer.njk', {\n isPrisonUser: !user || user.authSource === 'nomis',\n supportUrl,\n authUrl,\n })\n}\n\nfunction initialiseName(fullName?: string): string | null {\n if (!fullName) return null\n\n const array = fullName.split(' ')\n return `${array[0][0]}. ${array.reverse()[0]}`\n}\n","import { type Response } from 'express'\n\nexport default function updateCsp(feComponentsUrl: string, res: Response) {\n const csp = res.getHeaders()['content-security-policy']\n const allDirectives = csp?.split(';') ?? []\n const directivesToUpdate = ['script-src', 'style-src', 'img-src', 'font-src']\n\n const updatedCspDirectives = allDirectives.map(directive => {\n // if directive is not in cspToUpdate or includes fe components url already return as is\n if (directive.includes(feComponentsUrl as string) || !directivesToUpdate.some(p => directive.includes(`${p} `)))\n return directive\n\n // if directive is in cspToUpdate and does not have fe components url, add in\n return `${directive} ${feComponentsUrl}`\n })\n\n const requiredAndNotPresent = directivesToUpdate\n .filter(p => !updatedCspDirectives.find(directive => directive.includes(`${p} `)))\n .map(p => `${p} 'self' ${feComponentsUrl}`)\n\n res.set('content-security-policy', [...updatedCspDirectives, ...requiredAndNotPresent].join(';'))\n}\n","import { type NextFunction, type Request, type Response, type RequestHandler } from 'express'\nimport { ApiConfig, AuthenticationClient } from '@ministryofjustice/hmpps-rest-client'\nimport ComponentApiClient from './data/componentApi/componentApiClient'\nimport { getFallbackFooter, getFallbackHeader } from './utils/fallbacks'\nimport updateCsp from './utils/updateCsp'\nimport { HmppsUser } from './types/HmppsUser'\nimport { ConnectDpsComponentLogger } from './types/ConnectDpsComponentLogger'\n\nexport interface FrontendComponentRequestOptions {\n authUrl?: string\n supportUrl?: string\n environmentName?: 'DEV' | 'PRE-PRODUCTION' | 'PRODUCTION'\n includeSharedData?: boolean\n useFallbacksByDefault?: boolean\n}\n\nconst defaultOptions: Partial<FrontendComponentRequestOptions> = {\n includeSharedData: false,\n useFallbacksByDefault: false,\n}\n\nexport default class ComponentsService {\n constructor(\n private readonly logger: ConnectDpsComponentLogger,\n private readonly componentApiConfig: ApiConfig,\n private readonly componentApiClient: ComponentApiClient,\n private readonly dpsUrl: string,\n ) {}\n\n static create({\n logger = console,\n componentApiConfig,\n authenticationClient,\n dpsUrl,\n }: {\n logger?: ConnectDpsComponentLogger\n componentApiConfig: ApiConfig\n authenticationClient: AuthenticationClient\n dpsUrl: string\n }) {\n return new ComponentsService(\n logger,\n componentApiConfig,\n new ComponentApiClient(logger, componentApiConfig, authenticationClient),\n dpsUrl,\n )\n }\n\n getFrontendComponents(requestOptions?: FrontendComponentRequestOptions): RequestHandler {\n const requestOptionsWithDefaults = {\n ...defaultOptions,\n ...(requestOptions || {}),\n }\n const { includeSharedData, useFallbacksByDefault } = requestOptionsWithDefaults\n\n return async (_req: Request, res: Response, next: NextFunction) => {\n const useFallbacks = (user: HmppsUser | null) => {\n res.locals.feComponents = {\n header: getFallbackHeader(user, this.dpsUrl, {\n environmentName: requestOptionsWithDefaults.environmentName,\n authUrl: requestOptionsWithDefaults.authUrl,\n supportUrl: requestOptionsWithDefaults.supportUrl,\n }),\n footer: getFallbackFooter(user, {\n authUrl: requestOptionsWithDefaults.authUrl,\n supportUrl: requestOptionsWithDefaults.supportUrl,\n }),\n cssIncludes: [],\n jsIncludes: [],\n }\n }\n\n if (!res.locals.user) {\n this.logger.info('Using fallback frontend components when no user in context')\n useFallbacks(null)\n return next()\n }\n\n if (useFallbacksByDefault) {\n this.logger.info('Using fallback frontend components by default')\n useFallbacks(res.locals.user)\n return next()\n }\n\n try {\n const { header, footer, meta } = await this.componentApiClient.getComponents(res.locals.user.token as string)\n\n res.locals.feComponents = {\n header: header.html,\n footer: footer.html,\n cssIncludes: [...header.css, ...footer.css],\n jsIncludes: [...header.javascript, ...footer.javascript],\n }\n\n if (includeSharedData) {\n res.locals.feComponents.sharedData = meta\n }\n\n updateCsp(this.componentApiConfig.url, res)\n\n return next()\n } catch (_error) {\n this.logger.error('Failed to retrieve front end components, using fallbacks')\n useFallbacks(res.locals.user)\n return next()\n }\n }\n }\n}\n","import { type RequestHandler } from 'express'\nimport ComponentsService, { FrontendComponentRequestOptions } from '../componentsService'\n\ntype MiddlewareOptions = {\n requestOptions?: FrontendComponentRequestOptions\n} & Parameters<typeof ComponentsService.create>[0]\n\nexport default function getFrontendComponents({\n logger = console,\n componentApiConfig,\n authenticationClient,\n dpsUrl,\n requestOptions,\n}: MiddlewareOptions): RequestHandler {\n const service = ComponentsService.create({ logger, componentApiConfig, authenticationClient, dpsUrl })\n return service.getFrontendComponents(requestOptions)\n}\n","import { ApiConfig, asUser, AuthenticationClient, RestClient } from '@ministryofjustice/hmpps-rest-client'\nimport CaseLoad from '../../types/CaseLoad'\nimport { ConnectDpsComponentLogger } from '../../types/ConnectDpsComponentLogger'\n\nexport default class PrisonApiClient extends RestClient {\n constructor(logger: ConnectDpsComponentLogger, config: ApiConfig, authenticationClient: AuthenticationClient) {\n super('Prison API Client', config, logger, authenticationClient)\n }\n\n async getUserCaseLoads(userToken: string): Promise<CaseLoad[]> {\n return this.get<CaseLoad[]>(\n {\n path: '/api/users/me/caseLoads',\n query: 'allCaseloads=true',\n },\n asUser(userToken),\n )\n }\n}\n","import { type RequestHandler } from 'express'\nimport { ApiConfig, AuthenticationClient } from '@ministryofjustice/hmpps-rest-client'\nimport CaseLoad from './types/CaseLoad'\nimport PrisonApiClient from './data/prisonApi/prisonApiClient'\nimport { ConnectDpsComponentLogger } from './types/ConnectDpsComponentLogger'\n\nexport default class CaseLoadService {\n constructor(\n private readonly logger: ConnectDpsComponentLogger,\n private readonly prisonApiClient: PrisonApiClient,\n ) {}\n\n static create({\n logger = console,\n prisonApiConfig,\n authenticationClient,\n }: {\n logger?: ConnectDpsComponentLogger\n prisonApiConfig: ApiConfig\n authenticationClient: AuthenticationClient\n }) {\n return new CaseLoadService(logger, new PrisonApiClient(logger, prisonApiConfig, authenticationClient))\n }\n\n retrieveCaseLoadData(): RequestHandler {\n return async (req, res, next) => {\n if (!req.session) throw new Error('User session required in order to cache case loads')\n\n if (res.locals.user && res.locals.user.token && res.locals.user.authSource === 'nomis') {\n try {\n // Update cache with values from res.feComponents.sharedData if present\n if (res.locals.feComponents && res.locals.feComponents.sharedData) {\n req.session.caseLoads = res.locals.feComponents.sharedData.caseLoads\n req.session.activeCaseLoad = res.locals.feComponents.sharedData.activeCaseLoad\n req.session.activeCaseLoadId = res.locals.feComponents.sharedData.activeCaseLoad?.caseLoadId\n }\n\n // If cache is empty, fetch data from Prison API\n if (!req.session.caseLoads) {\n this.logger.info(`Falling back to Prison API to retrieve case loads for: ${res.locals.user.username}`)\n const userCaseLoads = await this.prisonApiClient.getUserCaseLoads(res.locals.user.token)\n const caseLoads = userCaseLoads.filter(caseload => caseload.type !== 'APP')\n const activeCaseLoad = caseLoads.find((caseLoad: CaseLoad) => caseLoad.currentlyActive)\n\n req.session.caseLoads = caseLoads\n req.session.activeCaseLoad = activeCaseLoad\n req.session.activeCaseLoadId = activeCaseLoad?.caseLoadId\n }\n\n // Populate res.locals.user with values from cache\n res.locals.user.caseLoads = req.session.caseLoads\n res.locals.user.activeCaseLoad = req.session.activeCaseLoad\n res.locals.user.activeCaseLoadId = req.session.activeCaseLoadId\n } catch (error) {\n this.logger.error(error, `Failed to retrieve case loads for: ${res.locals.user.username}`)\n return next(error)\n }\n }\n\n return next()\n }\n }\n}\n","import { type RequestHandler } from 'express'\nimport CaseLoadService from '../caseLoadService'\n\nexport default function retrieveCaseLoadData({\n logger = console,\n prisonApiConfig,\n authenticationClient,\n}: Parameters<typeof CaseLoadService.create>[0]): RequestHandler {\n const service = CaseLoadService.create({ logger, prisonApiConfig, authenticationClient })\n return service.retrieveCaseLoadData()\n}\n","import { ApiConfig, asSystem, AuthenticationClient, RestClient } from '@ministryofjustice/hmpps-rest-client'\nimport { PrisonUser } from '../../types/HmppsUser'\nimport { AllocationJobResponsibility } from '../../types/AllocationJobResponsibility'\nimport { ConnectDpsComponentLogger } from '../../types/ConnectDpsComponentLogger'\n\nexport default class AllocationsApiClient extends RestClient {\n constructor(logger: ConnectDpsComponentLogger, config: ApiConfig, authenticationClient: AuthenticationClient) {\n super('Allocations API Client', config, logger, authenticationClient)\n }\n\n async getStaffAllocationPolicies(user: PrisonUser): Promise<{ policies: AllocationJobResponsibility[] }> {\n return this.get<{ policies: AllocationJobResponsibility[] }>(\n {\n path: `/prisons/${user.activeCaseLoadId}/staff/${user.userId}/job-classifications`,\n },\n asSystem(),\n )\n }\n}\n","import { type RequestHandler } from 'express'\nimport { ApiConfig, AuthenticationClient } from '@ministryofjustice/hmpps-rest-client'\nimport AllocationsApiClient from './data/allocationsApi/allocationsApiClient'\nimport { ConnectDpsComponentLogger } from './types/ConnectDpsComponentLogger'\n\nexport default class AllocationService {\n constructor(\n private readonly logger: ConnectDpsComponentLogger,\n private readonly allocationsApiClient: AllocationsApiClient,\n ) {}\n\n static create({\n logger = console,\n allocationsApiConfig,\n authenticationClient,\n }: {\n logger?: ConnectDpsComponentLogger\n allocationsApiConfig: ApiConfig\n authenticationClient: AuthenticationClient\n }) {\n return new AllocationService(logger, new AllocationsApiClient(logger, allocationsApiConfig, authenticationClient))\n }\n\n public retrieveAllocationJobResponsibilities(): RequestHandler {\n return async (req, res, next) => {\n if (!req.session) throw new Error('User session required in order to cache allocation job responsibilities')\n if (!res.locals.user.token)\n throw new Error(\n 'Caseload details needs to be populated before retrieving allocation job responsibilities. Please run retrieveCaseLoadData before retrieveAllocationJobResponsibilities.',\n )\n\n if (res.locals.user && res.locals.user.authSource === 'nomis') {\n try {\n // Update cache with values from res.feComponents.sharedData if present\n if (res.locals.feComponents && res.locals.feComponents.sharedData) {\n req.session.allocationJobResponsibilities = res.locals.feComponents.sharedData.allocationJobResponsibilities\n }\n\n // If cache is empty, fetch data from Prison API\n if (!req.session.allocationJobResponsibilities) {\n this.logger.info(\n `Falling back to Allocations API to retrieve job responsibilities for: ${res.locals.user.username}`,\n )\n const allocationPolicies = await this.allocationsApiClient.getStaffAllocationPolicies(res.locals.user)\n req.session.allocationJobResponsibilities = allocationPolicies.policies\n }\n\n // Populate res.locals.user with values from cache\n res.locals.user.allocationJobResponsibilities = req.session.allocationJobResponsibilities\n } catch (error) {\n this.logger.error(\n error,\n `Failed to retrieve allocation job responsibilities for: ${res.locals.user.username}`,\n )\n return next(error)\n }\n }\n\n return next()\n }\n }\n}\n","import { type RequestHandler } from 'express'\nimport AllocationService from '../allocationService'\n\nexport default function getFrontendComponents({\n logger = console,\n allocationsApiConfig,\n authenticationClient,\n}: Parameters<typeof AllocationService.create>[0]): RequestHandler {\n const service = AllocationService.create({ logger, allocationsApiConfig, authenticationClient })\n return service.retrieveAllocationJobResponsibilities()\n}\n"],"names":["getFrontendComponents"],"mappings":";;;AAUc,MAAO,kBAAmB,SAAQ,UAAU,CAAA;AACxD,IAAA,WAAA,CAAY,MAAiC,EAAE,MAAiB,EAAE,oBAA0C,EAAA;QAC1G,KAAK,CAAC,sBAAsB,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,CAAC;IACrE;IAEA,MAAM,aAAa,CAAiC,SAAiB,EAAA;QACnE,OAAO,IAAI,CAAC,GAAG,CACb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,CAAE,CACpG;AACD,wBAAA,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,0BAA0B,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;wBACtG,GAAG,CAAC,OAAO,CAAC,6BAA6B,GAAG,kBAAkB,CAAC,QAAQ;oBACzE;;AAGA,oBAAA,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6B,GAAG,GAAG,CAAC,OAAO,CAAC,6BAA6B;gBAC3F;gBAAE,OAAO,KAAK,EAAE;AACd,oBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,KAAK,EACL,CAAA,wDAAA,EAA2D,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAA,CAAE,CACtF;AACD,oBAAA,OAAO,IAAI,CAAC,KAAK,CAAC;gBACpB;YACF;YAEA,OAAO,IAAI,EAAE;AACf,QAAA,CAAC;IACH;AACD;;AC1Da,SAAU,qBAAqB,CAAC,EAC5C,MAAM,GAAG,OAAO,EAChB,oBAAoB,EACpB,oBAAoB,GAC2B,EAAA;AAC/C,IAAA,MAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,CAAC;AAChG,IAAA,OAAO,OAAO,CAAC,qCAAqC,EAAE;AACxD;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/data/componentApi/componentApiClient.ts","../src/utils/fallbacks.ts","../src/utils/updateCsp.ts","../src/componentsService.ts","../src/middleware/getFrontendComponents.ts","../src/data/prisonApi/prisonApiClient.ts","../src/caseLoadService.ts","../src/middleware/retrieveCaseLoadData.ts","../src/data/allocationsApi/allocationsApiClient.ts","../src/allocationService.ts","../src/middleware/retrieveAllocationJobResponsibilities.ts"],"sourcesContent":["import { ApiConfig, asSystem, AuthenticationClient, RestClient } from '@ministryofjustice/hmpps-rest-client'\nimport AvailableComponent from '../../types/AvailableComponent'\nimport Component from '../../types/Component'\nimport { ConnectDpsComponentLogger } from '../../types/ConnectDpsComponentLogger'\nimport { ComponentsSharedData } from '../../types/HeaderFooterSharedData'\n\nexport type ComponentsApiResponse<T extends AvailableComponent[]> = Record<T[number], Component> & {\n meta: ComponentsSharedData[T[number]] // TODO: rename 'meta' in the API response\n}\n\nexport default class ComponentApiClient extends RestClient {\n constructor(logger: ConnectDpsComponentLogger, config: ApiConfig, authenticationClient: AuthenticationClient) {\n super('Component API Client', config, logger, authenticationClient)\n }\n\n async getComponents<T extends AvailableComponent[]>(userToken: string): Promise<ComponentsApiResponse<T>> {\n return this.get<ComponentsApiResponse<T>>(\n {\n path: `/components`,\n query: 'component=header&component=footer',\n headers: { 'x-user-token': userToken },\n },\n asSystem(),\n )\n }\n}\n","import nunjucks from 'nunjucks'\nimport { HmppsUser } from '../types/HmppsUser'\n\nexport function getFallbackHeader(\n user: HmppsUser | null,\n dpsUrl: string,\n { environmentName, authUrl, supportUrl }: { environmentName?: string; authUrl?: string; supportUrl?: string },\n): string {\n return nunjucks.render('dpsComponents/header-bar.njk', {\n isPrisonUser: !user || user.authSource === 'nomis',\n user,\n dpsUrl,\n environmentName,\n authUrl,\n supportUrl,\n name: initialiseName(user?.displayName),\n })\n}\n\nexport function getFallbackFooter(\n user: HmppsUser | null,\n { authUrl, supportUrl }: { authUrl?: string; supportUrl?: string },\n): string {\n return nunjucks.render('dpsComponents/footer.njk', {\n isPrisonUser: !user || user.authSource === 'nomis',\n supportUrl,\n authUrl,\n })\n}\n\nfunction initialiseName(fullName?: string): string | null {\n if (!fullName) return null\n\n const array = fullName.split(' ')\n return `${array[0][0]}. ${array.reverse()[0]}`\n}\n","import { type Response } from 'express'\n\nexport default function updateCsp(feComponentsUrl: string, res: Response) {\n const csp = res.getHeaders()['content-security-policy']\n const allDirectives = csp?.split(';') ?? []\n const directivesToUpdate = ['script-src', 'style-src', 'img-src', 'font-src']\n\n const updatedCspDirectives = allDirectives.map(directive => {\n // if directive is not in cspToUpdate or includes fe components url already return as is\n if (directive.includes(feComponentsUrl as string) || !directivesToUpdate.some(p => directive.includes(`${p} `)))\n return directive\n\n // if directive is in cspToUpdate and does not have fe components url, add in\n return `${directive} ${feComponentsUrl}`\n })\n\n const requiredAndNotPresent = directivesToUpdate\n .filter(p => !updatedCspDirectives.find(directive => directive.includes(`${p} `)))\n .map(p => `${p} 'self' ${feComponentsUrl}`)\n\n res.set('content-security-policy', [...updatedCspDirectives, ...requiredAndNotPresent].join(';'))\n}\n","import { type NextFunction, type Request, type Response, type RequestHandler } from 'express'\nimport { ApiConfig, AuthenticationClient } from '@ministryofjustice/hmpps-rest-client'\nimport ComponentApiClient from './data/componentApi/componentApiClient'\nimport { getFallbackFooter, getFallbackHeader } from './utils/fallbacks'\nimport updateCsp from './utils/updateCsp'\nimport { HmppsUser } from './types/HmppsUser'\nimport { ConnectDpsComponentLogger } from './types/ConnectDpsComponentLogger'\n\nexport interface FrontendComponentRequestOptions {\n authUrl?: string\n supportUrl?: string\n environmentName?: 'DEV' | 'PRE-PRODUCTION' | 'PRODUCTION'\n includeSharedData?: boolean\n useFallbacksByDefault?: boolean\n}\n\nconst defaultOptions: Partial<FrontendComponentRequestOptions> = {\n includeSharedData: false,\n useFallbacksByDefault: false,\n}\n\nexport default class ComponentsService {\n constructor(\n private readonly logger: ConnectDpsComponentLogger,\n private readonly componentApiConfig: ApiConfig,\n private readonly componentApiClient: ComponentApiClient,\n private readonly dpsUrl: string,\n ) {}\n\n static create({\n logger = console,\n componentApiConfig,\n authenticationClient,\n dpsUrl,\n }: {\n logger?: ConnectDpsComponentLogger\n componentApiConfig: ApiConfig\n authenticationClient: AuthenticationClient\n dpsUrl: string\n }) {\n return new ComponentsService(\n logger,\n componentApiConfig,\n new ComponentApiClient(logger, componentApiConfig, authenticationClient),\n dpsUrl,\n )\n }\n\n getFrontendComponents(requestOptions?: FrontendComponentRequestOptions): RequestHandler {\n const requestOptionsWithDefaults = {\n ...defaultOptions,\n ...(requestOptions || {}),\n }\n const { includeSharedData, useFallbacksByDefault } = requestOptionsWithDefaults\n\n return async (_req: Request, res: Response, next: NextFunction) => {\n const useFallbacks = (user: HmppsUser | null) => {\n res.locals.feComponents = {\n header: getFallbackHeader(user, this.dpsUrl, {\n environmentName: requestOptionsWithDefaults.environmentName,\n authUrl: requestOptionsWithDefaults.authUrl,\n supportUrl: requestOptionsWithDefaults.supportUrl,\n }),\n footer: getFallbackFooter(user, {\n authUrl: requestOptionsWithDefaults.authUrl,\n supportUrl: requestOptionsWithDefaults.supportUrl,\n }),\n cssIncludes: [],\n jsIncludes: [],\n }\n }\n\n if (!res.locals.user) {\n this.logger.info('Using fallback frontend components when no user in context')\n useFallbacks(null)\n return next()\n }\n\n if (useFallbacksByDefault) {\n this.logger.info('Using fallback frontend components by default')\n useFallbacks(res.locals.user)\n return next()\n }\n\n try {\n const { header, footer, meta } = await this.componentApiClient.getComponents(res.locals.user.token as string)\n\n res.locals.feComponents = {\n header: header.html,\n footer: footer.html,\n cssIncludes: [...header.css, ...footer.css],\n jsIncludes: [...header.javascript, ...footer.javascript],\n }\n\n if (includeSharedData) {\n res.locals.feComponents.sharedData = meta\n }\n\n updateCsp(this.componentApiConfig.url, res)\n\n return next()\n } catch (_error) {\n this.logger.error('Failed to retrieve front end components, using fallbacks')\n useFallbacks(res.locals.user)\n return next()\n }\n }\n }\n}\n","import { type RequestHandler } from 'express'\nimport ComponentsService, { FrontendComponentRequestOptions } from '../componentsService'\n\ntype MiddlewareOptions = {\n requestOptions?: FrontendComponentRequestOptions\n} & Parameters<typeof ComponentsService.create>[0]\n\nexport default function getFrontendComponents({\n logger = console,\n componentApiConfig,\n authenticationClient,\n dpsUrl,\n requestOptions,\n}: MiddlewareOptions): RequestHandler {\n const service = ComponentsService.create({ logger, componentApiConfig, authenticationClient, dpsUrl })\n return service.getFrontendComponents(requestOptions)\n}\n","import { ApiConfig, asUser, AuthenticationClient, RestClient } from '@ministryofjustice/hmpps-rest-client'\nimport CaseLoad from '../../types/CaseLoad'\nimport { ConnectDpsComponentLogger } from '../../types/ConnectDpsComponentLogger'\n\nexport default class PrisonApiClient extends RestClient {\n constructor(logger: ConnectDpsComponentLogger, config: ApiConfig, authenticationClient: AuthenticationClient) {\n super('Prison API Client', config, logger, authenticationClient)\n }\n\n async getUserCaseLoads(userToken: string): Promise<CaseLoad[]> {\n return this.get<CaseLoad[]>(\n {\n path: '/api/users/me/caseLoads',\n query: 'allCaseloads=true',\n },\n asUser(userToken),\n )\n }\n}\n","import { type RequestHandler } from 'express'\nimport { ApiConfig, AuthenticationClient } from '@ministryofjustice/hmpps-rest-client'\nimport CaseLoad from './types/CaseLoad'\nimport PrisonApiClient from './data/prisonApi/prisonApiClient'\nimport { ConnectDpsComponentLogger } from './types/ConnectDpsComponentLogger'\n\nexport default class CaseLoadService {\n constructor(\n private readonly logger: ConnectDpsComponentLogger,\n private readonly prisonApiClient: PrisonApiClient,\n ) {}\n\n static create({\n logger = console,\n prisonApiConfig,\n authenticationClient,\n }: {\n logger?: ConnectDpsComponentLogger\n prisonApiConfig: ApiConfig\n authenticationClient: AuthenticationClient\n }) {\n return new CaseLoadService(logger, new PrisonApiClient(logger, prisonApiConfig, authenticationClient))\n }\n\n retrieveCaseLoadData(): RequestHandler {\n return async (req, res, next) => {\n if (!req.session) throw new Error('User session required in order to cache case loads')\n\n if (res.locals.user && res.locals.user.token && res.locals.user.authSource === 'nomis') {\n try {\n // Update cache with values from res.feComponents.sharedData if present\n if (res.locals.feComponents && res.locals.feComponents.sharedData) {\n req.session.caseLoads = res.locals.feComponents.sharedData.caseLoads\n req.session.activeCaseLoad = res.locals.feComponents.sharedData.activeCaseLoad\n req.session.activeCaseLoadId = res.locals.feComponents.sharedData.activeCaseLoad?.caseLoadId\n }\n\n // If cache is empty, fetch data from Prison API\n if (!req.session.caseLoads) {\n this.logger.info(`Falling back to Prison API to retrieve case loads for: ${res.locals.user.username}`)\n const userCaseLoads = await this.prisonApiClient.getUserCaseLoads(res.locals.user.token)\n const caseLoads = userCaseLoads.filter(caseload => caseload.type !== 'APP')\n const activeCaseLoad = caseLoads.find((caseLoad: CaseLoad) => caseLoad.currentlyActive)\n\n req.session.caseLoads = caseLoads\n req.session.activeCaseLoad = activeCaseLoad\n req.session.activeCaseLoadId = activeCaseLoad?.caseLoadId\n }\n\n // Populate res.locals.user with values from cache\n res.locals.user.caseLoads = req.session.caseLoads\n res.locals.user.activeCaseLoad = req.session.activeCaseLoad\n res.locals.user.activeCaseLoadId = req.session.activeCaseLoadId\n } catch (error) {\n this.logger.error(error, `Failed to retrieve case loads for: ${res.locals.user.username}`)\n return next(error)\n }\n }\n\n return next()\n }\n }\n}\n","import { type RequestHandler } from 'express'\nimport CaseLoadService from '../caseLoadService'\n\nexport default function retrieveCaseLoadData({\n logger = console,\n prisonApiConfig,\n authenticationClient,\n}: Parameters<typeof CaseLoadService.create>[0]): RequestHandler {\n const service = CaseLoadService.create({ logger, prisonApiConfig, authenticationClient })\n return service.retrieveCaseLoadData()\n}\n","import { ApiConfig, asSystem, AuthenticationClient, RestClient } from '@ministryofjustice/hmpps-rest-client'\nimport { PrisonUser } from '../../types/HmppsUser'\nimport { AllocationJobResponsibility } from '../../types/AllocationJobResponsibility'\nimport { ConnectDpsComponentLogger } from '../../types/ConnectDpsComponentLogger'\n\nexport default class AllocationsApiClient extends RestClient {\n constructor(logger: ConnectDpsComponentLogger, config: ApiConfig, authenticationClient: AuthenticationClient) {\n super('Allocations API Client', config, logger, authenticationClient)\n }\n\n async getStaffAllocationPolicies(user: PrisonUser): Promise<{ policies: AllocationJobResponsibility[] }> {\n return this.get<{ policies: AllocationJobResponsibility[] }>(\n {\n path: `/prisons/${user.activeCaseLoadId}/staff/${user.userId}/job-classifications`,\n },\n asSystem(),\n )\n }\n}\n","import { type RequestHandler } from 'express'\nimport { ApiConfig, AuthenticationClient } from '@ministryofjustice/hmpps-rest-client'\nimport AllocationsApiClient from './data/allocationsApi/allocationsApiClient'\nimport { ConnectDpsComponentLogger } from './types/ConnectDpsComponentLogger'\n\nexport default class AllocationService {\n constructor(\n private readonly logger: ConnectDpsComponentLogger,\n private readonly allocationsApiClient: AllocationsApiClient,\n ) {}\n\n static create({\n logger = console,\n allocationsApiConfig,\n authenticationClient,\n }: {\n logger?: ConnectDpsComponentLogger\n allocationsApiConfig: ApiConfig\n authenticationClient: AuthenticationClient\n }) {\n return new AllocationService(logger, new AllocationsApiClient(logger, allocationsApiConfig, authenticationClient))\n }\n\n public retrieveAllocationJobResponsibilities(): RequestHandler {\n return async (req, res, next) => {\n if (!req.session) throw new Error('User session required in order to cache allocation job responsibilities')\n if (!res.locals.user.token)\n throw new Error(\n 'Caseload details needs to be populated before retrieving allocation job responsibilities. Please run retrieveCaseLoadData before retrieveAllocationJobResponsibilities.',\n )\n\n if (res.locals.user && res.locals.user.authSource === 'nomis') {\n try {\n // Update cache with values from res.feComponents.sharedData if present\n if (res.locals.feComponents && res.locals.feComponents.sharedData) {\n req.session.allocationJobResponsibilities = res.locals.feComponents.sharedData.allocationJobResponsibilities\n }\n\n // If cache is empty, fetch data from Prison API\n if (!req.session.allocationJobResponsibilities) {\n this.logger.info(\n `Falling back to Allocations API to retrieve job responsibilities for: ${res.locals.user.username}`,\n )\n const allocationPolicies = await this.allocationsApiClient.getStaffAllocationPolicies(res.locals.user)\n req.session.allocationJobResponsibilities = allocationPolicies.policies\n }\n\n // Populate res.locals.user with values from cache\n res.locals.user.allocationJobResponsibilities = req.session.allocationJobResponsibilities\n } catch (error) {\n this.logger.error(\n error,\n `Failed to retrieve allocation job responsibilities for: ${res.locals.user.username}`,\n )\n return next(error)\n }\n }\n\n return next()\n }\n }\n}\n","import { type RequestHandler } from 'express'\nimport AllocationService from '../allocationService'\n\nexport default function retrieveAllocationJobResponsibilities({\n logger = console,\n allocationsApiConfig,\n authenticationClient,\n}: Parameters<typeof AllocationService.create>[0]): RequestHandler {\n const service = AllocationService.create({ logger, allocationsApiConfig, authenticationClient })\n return service.retrieveAllocationJobResponsibilities()\n}\n"],"names":[],"mapp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AA6B,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,6BAA6B;oBAC9G;;AAGA,oBAAA,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,6BAA6B,EAAE;AAC9C,wBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,CAAA,sEAAA,EAAyE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAA,CAAE,CACpG;AACD,wBAAA,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,0BAA0B,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;wBACtG,GAAG,CAAC,OAAO,CAAC,6BAA6B,GAAG,kBAAkB,CAAC,QAAQ;oBACzE;;AAGA,oBAAA,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6B,GAAG,GAAG,CAAC,OAAO,CAAC,6BAA6B;gBAC3F;gBAAE,OAAO,KAAK,EAAE;AACd,oBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,KAAK,EACL,CAAA,wDAAA,EAA2D,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAA,CAAE,CACtF;AACD,oBAAA,OAAO,IAAI,CAAC,KAAK,CAAC;gBACpB;YACF;YAEA,OAAO,IAAI,EAAE;AACf,QAAA,CAAC;IACH;AACD;;AC1Da,SAAU,qCAAqC,CAAC,EAC5D,MAAM,GAAG,OAAO,EAChB,oBAAoB,EACpB,oBAAoB,GAC2B,EAAA;AAC/C,IAAA,MAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,CAAC;AAChG,IAAA,OAAO,OAAO,CAAC,qCAAqC,EAAE;AACxD;;;;"}
@@ -1,3 +1,3 @@
1
1
  import { type RequestHandler } from 'express';
2
2
  import AllocationService from '../allocationService';
3
- export default function getFrontendComponents({ logger, allocationsApiConfig, authenticationClient, }: Parameters<typeof AllocationService.create>[0]): RequestHandler;
3
+ export default function retrieveAllocationJobResponsibilities({ logger, allocationsApiConfig, authenticationClient, }: Parameters<typeof AllocationService.create>[0]): RequestHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ministryofjustice/hmpps-connect-dps-components",
3
- "version": "3.0.0-beta.7",
3
+ "version": "3.0.1",
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",
@@ -11,8 +11,9 @@
11
11
  "scripts": {
12
12
  "prepare": "hmpps-precommit-hooks-prepare",
13
13
  "build": "rollup -c rollup.config.ts --bundleConfigAsCjs && npm run copy:assets",
14
+ "clean": "rm -rf ./dist/",
14
15
  "test": "jest",
15
- "test:ci": "jest --runInBand --passWithNoTests",
16
+ "test:ci": "jest --runInBand",
16
17
  "typecheck": "tsc",
17
18
  "lint": "eslint . --cache --max-warnings 0",
18
19
  "lint:fix": "eslint . --cache --max-warnings 0 --fix",
@@ -42,7 +43,7 @@
42
43
  },
43
44
  "homepage": "https://github.com/ministryofjustice/hmpps-connect-dps-components#readme",
44
45
  "devDependencies": {
45
- "@ministryofjustice/eslint-config-hmpps": "^0.0.1",
46
+ "@ministryofjustice/eslint-config-hmpps": "^0.0.3",
46
47
  "@ministryofjustice/hmpps-auth-clients": "^0.0.1",
47
48
  "@ministryofjustice/hmpps-precommit-hooks": "^0.0.3",
48
49
  "@rollup/plugin-commonjs": "^28.0.6",
@@ -73,10 +74,10 @@
73
74
  "tslib": "^2.8.1"
74
75
  },
75
76
  "dependencies": {
76
- "@ministryofjustice/hmpps-rest-client": "^0.0.1",
77
- "@types/node": "22.12.0",
77
+ "@ministryofjustice/hmpps-rest-client": "^0.0.3",
78
+ "@types/node": "22.18.6",
78
79
  "@types/nunjucks": "^3.2.6",
79
80
  "nunjucks": "^3.2.4",
80
- "superagent": "^9.0.2"
81
+ "superagent": "^10.2.3"
81
82
  }
82
83
  }