@ministryofjustice/hmpps-mpop-frontend-components-lib 0.0.4 → 0.0.6

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.
Files changed (36) hide show
  1. package/README.md +42 -4
  2. package/dist/MPoPComponents.d.ts +6 -0
  3. package/dist/_all.scss +2 -1
  4. package/dist/components/pop-header/popHeader.test.d.ts +1 -0
  5. package/dist/components/supervision-package/partials/_early-engagement.test.d.ts +1 -0
  6. package/dist/components/supervision-package/partials/_progress-bar.test.d.ts +1 -0
  7. package/dist/components/supervision-package/partials/tags.test.d.ts +1 -0
  8. package/dist/index.cjs.js +112 -0
  9. package/dist/index.cjs.js.map +1 -1
  10. package/dist/index.d.ts +102 -1
  11. package/dist/index.esm.js +111 -1
  12. package/dist/index.esm.js.map +1 -1
  13. package/dist/mpop/components/pop-header/_pop-header.scss +12 -0
  14. package/dist/mpop/components/pop-header/macro.njk +3 -0
  15. package/dist/mpop/components/pop-header/template.njk +18 -0
  16. package/dist/mpop/components/supervision-package/_supervision-package.scss +25 -1
  17. package/dist/mpop/components/supervision-package/macro.njk +2 -2
  18. package/dist/mpop/components/supervision-package/partials/_early-engagement.njk +21 -0
  19. package/dist/mpop/components/supervision-package/partials/_progress-bar.njk +38 -0
  20. package/dist/mpop/components/supervision-package/partials/_tags.njk +19 -0
  21. package/dist/mpop/components/supervision-package/template.njk +55 -15
  22. package/dist/types/MPoPComponentsConfig.d.ts +2 -0
  23. package/dist/types/PersonalDetails.d.ts +18 -0
  24. package/dist/types/SupervisionPackage.d.ts +73 -0
  25. package/dist/utils/dateWithYear.d.ts +3 -0
  26. package/dist/utils/dateWithYear.test.d.ts +1 -0
  27. package/dist/utils/govukTime.d.ts +1 -0
  28. package/dist/utils/govukTime.test.d.ts +1 -0
  29. package/dist/utils/isBlank.d.ts +1 -0
  30. package/dist/utils/isBlank.test.d.ts +1 -0
  31. package/dist/utils/nunjucksFilters.d.ts +2 -0
  32. package/dist/utils/toTitleCase.d.ts +1 -0
  33. package/dist/utils/toTitleCase.test.d.ts +1 -0
  34. package/dist/utils/yearsSince.d.ts +1 -0
  35. package/dist/utils/yearsSince.test.d.ts +1 -0
  36. package/package.json +3 -1
package/README.md CHANGED
@@ -1,18 +1,58 @@
1
1
  # hmpps-mpop-frontend-components-lib
2
2
  MPoP front-end library
3
3
 
4
+ ## Usage
5
+
6
+ ### Installation
7
+
8
+ ```bash
9
+ npm install @ministryofjustice/hmpps-mpop-frontend-components-lib
10
+ ```
11
+
12
+ ### Nunjucks setup
13
+
14
+ The components in this library use custom Nunjucks filters. You must register them with your Nunjucks environment before rendering any components, otherwise you will see a `filter not found` error.
15
+
16
+ Call `mpopNunjucksSetup` once when configuring your application:
17
+
18
+ ```ts
19
+ import nunjucks from 'nunjucks'
20
+ import { mpopNunjucksSetup } from '@ministryofjustice/hmpps-mpop-frontend-components-lib'
21
+
22
+ const env = nunjucks.configure([...])
23
+ mpopNunjucksSetup(env)
24
+ ```
25
+
26
+ ### SCSS
27
+
28
+ Import the component styles in your SCSS entry point:
29
+
30
+ ```scss
31
+ @import '@ministryofjustice/hmpps-mpop-frontend-components-lib/dist/all';
32
+ ```
33
+
4
34
  ## Releasing
5
35
 
6
36
  This package is published to npm using GitHub Releases and npm Trusted Publishing.
7
37
 
38
+ You can view the npm page for this package here https://www.npmjs.com/package/@ministryofjustice/hmpps-mpop-frontend-components-lib
39
+
40
+ ### Pre-requisites
41
+
42
+ - Ensure GitHub CLI (gh) is installed and authenticated
43
+
44
+ ```bash
45
+ gh auth status || gh auth login
46
+ ```
47
+
8
48
  ### Release process
9
49
 
10
- 1. Create a branch from the latest `main` and update the package version:
50
+ 1. Create a unique branch name from the latest `main` and update the package version, such as:
11
51
 
12
52
  ```bash
13
53
  git checkout main
14
54
  git pull
15
- git checkout -b chore/bump-package-version
55
+ git checkout -b chore/bump-package-version-<version>
16
56
 
17
57
  npm version patch --no-git-tag-version
18
58
  ```
@@ -41,8 +81,6 @@ This package is published to npm using GitHub Releases and npm Trusted Publishin
41
81
 
42
82
  VERSION=$(node -p "require('./package.json').version")
43
83
 
44
- // Add a step to say github cli needs to be installed and you need to login to the github cli
45
-
46
84
  gh release create "v$VERSION" \
47
85
  --target main \
48
86
  --title "v$VERSION" \
@@ -3,9 +3,15 @@ import type { AuthenticationClient } from '@ministryofjustice/hmpps-auth-clients
3
3
  import type Logger from 'bunyan';
4
4
  import type { MPoPComponentsConfig } from './types/MPoPComponentsConfig';
5
5
  import type { LatestTierResponse, TierTag } from './types/TierCalculation';
6
+ import type { PersonalDetailsResponse } from './types/PersonalDetails';
7
+ import type { SupervisionPackageResponse } from './types/SupervisionPackage';
6
8
  export declare const tierTags: Record<string, TierTag>;
7
9
  export default class MPoPComponents {
8
10
  private readonly tierApiRestClient;
11
+ private readonly masApiRestClient;
12
+ private readonly supervisionPackageApiRestClient;
9
13
  constructor(authenticationClient: AuthenticationClient, config: MPoPComponentsConfig, logger?: Logger | Console);
10
14
  getTierDetails(authOptions: AuthOptions | string, crn: string): Promise<LatestTierResponse>;
15
+ getPersonalDetails(authOptions: AuthOptions | string, crn: string): Promise<PersonalDetailsResponse>;
16
+ getSupervisionPackage(authOptions: AuthOptions | string, crn: string): Promise<SupervisionPackageResponse>;
11
17
  }
package/dist/_all.scss CHANGED
@@ -1,4 +1,5 @@
1
1
  // MPOP Frontend Components Library
2
2
  // Requires govuk-frontend to be imported first
3
3
 
4
- @import "./mpop/components/supervision-package/supervision-package";
4
+ @import "./mpop/components/supervision-package/supervision-package";
5
+ @import "./mpop/components/pop-header/pop-header";
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.cjs.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var hmppsRestClient = require('@ministryofjustice/hmpps-rest-client');
4
+ var luxon = require('luxon');
4
5
 
5
6
  class SuppressingRestClient {
6
7
  constructor(restClient, logger) {
@@ -21,6 +22,18 @@ class SuppressingRestClient {
21
22
  }
22
23
  }
23
24
 
25
+ const isBlank = (str) => !str || /^\s*$/.test(str);
26
+
27
+ const yearsSince = (datetimeString) => {
28
+ if (!datetimeString || isBlank(datetimeString))
29
+ return null;
30
+ const dt = luxon.DateTime.fromISO(datetimeString, { zone: 'Europe/London' });
31
+ if (!dt.isValid)
32
+ return null;
33
+ const years = Math.trunc(luxon.DateTime.now().diff(dt, ['years', 'months']).years);
34
+ return years.toString();
35
+ };
36
+
24
37
  const tierTags = {
25
38
  missing: { text: 'Missing', color: 'red' },
26
39
  provisional: { text: 'Provisional', color: 'orange' },
@@ -29,7 +42,10 @@ const tierTags = {
29
42
  };
30
43
  class MPoPComponents {
31
44
  constructor(authenticationClient, config, logger = console) {
45
+ var _a, _b;
32
46
  this.tierApiRestClient = new SuppressingRestClient(new hmppsRestClient.RestClient('Tier API', config, logger, authenticationClient), logger);
47
+ this.masApiRestClient = new SuppressingRestClient(new hmppsRestClient.RestClient('MAS API', (_a = config.masApiConfig) !== null && _a !== void 0 ? _a : config, logger, authenticationClient), logger);
48
+ this.supervisionPackageApiRestClient = new SuppressingRestClient(new hmppsRestClient.RestClient('Supervision Package API', (_b = config.supervisionPackageApiConfig) !== null && _b !== void 0 ? _b : config, logger, authenticationClient), logger);
33
49
  }
34
50
  async getTierDetails(authOptions, crn) {
35
51
  let error = null;
@@ -86,7 +102,103 @@ class MPoPComponents {
86
102
  error,
87
103
  };
88
104
  }
105
+ async getPersonalDetails(authOptions, crn) {
106
+ let error = null;
107
+ let personalDetailsResponse;
108
+ try {
109
+ const response = await this.masApiRestClient.get(`/personal-details/${crn}/summary`, authOptions);
110
+ if (!response) {
111
+ personalDetailsResponse = {
112
+ personalDetails: null,
113
+ httpStatus: 404,
114
+ };
115
+ }
116
+ else {
117
+ personalDetailsResponse = {
118
+ personalDetails: { ...response, age: yearsSince(response.dateOfBirth) },
119
+ httpStatus: 200,
120
+ };
121
+ }
122
+ }
123
+ catch (err) {
124
+ error = err instanceof Error ? err : new Error('500 Internal Server Error');
125
+ const responseStatus = err === null || err === void 0 ? void 0 : err.responseStatus;
126
+ personalDetailsResponse = {
127
+ personalDetails: null,
128
+ httpStatus: responseStatus !== null && responseStatus !== void 0 ? responseStatus : 500,
129
+ };
130
+ }
131
+ return {
132
+ ...personalDetailsResponse,
133
+ error,
134
+ };
135
+ }
136
+ async getSupervisionPackage(authOptions, crn) {
137
+ let error = null;
138
+ let supervisionPackageResponse;
139
+ try {
140
+ const response = await this.supervisionPackageApiRestClient.get(`/case/${crn}/current-phase`, authOptions);
141
+ if (!response) {
142
+ supervisionPackageResponse = {
143
+ supervisionPackage: null,
144
+ httpStatus: 404,
145
+ };
146
+ }
147
+ else {
148
+ supervisionPackageResponse = {
149
+ supervisionPackage: response,
150
+ httpStatus: 200,
151
+ };
152
+ }
153
+ }
154
+ catch (err) {
155
+ const responseStatus = err === null || err === void 0 ? void 0 : err.responseStatus;
156
+ error = err instanceof Error ? err : new Error('500 Internal Server Error');
157
+ supervisionPackageResponse = {
158
+ supervisionPackage: null,
159
+ httpStatus: responseStatus !== null && responseStatus !== void 0 ? responseStatus : 500,
160
+ };
161
+ }
162
+ return {
163
+ ...supervisionPackageResponse,
164
+ error,
165
+ };
166
+ }
89
167
  }
90
168
 
169
+ const govukTime = (datetimeString) => {
170
+ if (!datetimeString || isBlank(datetimeString))
171
+ return null;
172
+ const datetime = luxon.DateTime.fromISO(datetimeString);
173
+ if (!datetime.isValid)
174
+ return null;
175
+ const hourMinuteFormat = datetime.minute === 0 ? 'ha' : 'h:mma';
176
+ return datetime.toFormat(hourMinuteFormat).toLowerCase();
177
+ };
178
+
179
+ const dateWithYear = (datetimeString, showTime = false) => {
180
+ if (!datetimeString || isBlank(datetimeString))
181
+ return null;
182
+ const dt = luxon.DateTime.fromISO(datetimeString, { zone: 'Europe/London' });
183
+ if (!dt.isValid)
184
+ return null;
185
+ const time = showTime ? govukTime(datetimeString) : null;
186
+ return `${dt.toFormat('d MMMM yyyy')}${time ? ` at ${time}` : ''}`;
187
+ };
188
+
189
+ const toTitleCase = (value) => {
190
+ if (!value)
191
+ return '';
192
+ const lower = value.toLowerCase();
193
+ return `${lower.charAt(0).toUpperCase()}${lower.substring(1)}`;
194
+ };
195
+
196
+ const mpopNunjucksSetup = (env) => {
197
+ env.addFilter('dateWithYear', dateWithYear);
198
+ env.addFilter('toTitleCase', toTitleCase);
199
+ };
200
+
91
201
  exports.MPoPComponents = MPoPComponents;
202
+ exports.addFilters = mpopNunjucksSetup;
203
+ exports.mpopNunjucksSetup = mpopNunjucksSetup;
92
204
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/SuppressingRestClient.ts","../src/MPoPComponents.ts"],"sourcesContent":[null,null],"names":["RestClient"],"mappings":";;;;MAGa,qBAAqB,CAAA;IAChC,WAAA,CACmB,UAAsB,EACtB,MAAwB,EAAA;QADxB,IAAA,CAAA,UAAU,GAAV,UAAU;QACV,IAAA,CAAA,MAAM,GAAN,MAAM;IACtB;AAEH,IAAA,MAAM,GAAG,CAAI,IAAY,EAAE,WAAiC,EAAA;AAC1D,QAAA,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CACxB;YACE,IAAI;YACJ,YAAY,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,KAAI;AAC3C,gBAAA,IAAI,KAAK,CAAC,cAAc,KAAK,GAAG,EAAE;oBAChC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA,iCAAA,EAAoC,MAAM,CAAA,EAAA,EAAK,WAAW,CAAA,CAAE,CAAC;AAC/E,oBAAA,OAAO,IAAI;gBACb;AACA,gBAAA,MAAM,KAAK;YACb,CAAC;SACF,EACD,WAAW,CACZ;IACH;AACD;;ACfM,MAAM,QAAQ,GAA4B;IAC/C,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE;IAC1C,WAAW,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,EAA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BAAA,GAAG,GAAG,EAAE,GAAG,QAAQ,CAAC,WAAW,EAAE;gBACnC;qBAAO;AACL,oBAAA,GAAG,GAAG,EAAE,GAAG,QAAQ,CAAC,IAAI,EAAE;gBAC5B;AAEA,gBAAA,WAAW,GAAG;AACZ,oBAAA,WAAW,EAAE,EAAE,GAAG,WAAW,EAAE,GAAG,EAAE;AACpC,oBAAA,UAAU,EAAE,GAAG;iBAChB;YACH;QACF;QAAE,OAAO,GAAG,EAAE;AACZ,YAAA,KAAK,GAAG,GAAG,YAAY,KAAK,GAAG,GAAG,GAAG,IAAI,KAAK,CAAC,2BAA2B,CAAC;YAC3E,MAAM,cAAc,GAAI,GAA0C,KAAA,IAAA,IAA1C,GAAG,KAAA,MAAA,GAAA,MAAA,GAAH,GAAG,CAAyC,cAAc;AAElF,YAAA,WAAW,GAAG;AACZ,gBAAA,WAAW,EAAE;AACX,oBAAA,SAAS,EAAE,EAAE;AACb,oBAAA,aAAa,EAAE,EAAE;AACjB,oBAAA,eAAe,EAAE,EAAE;AACnB,oBAAA,YAAY,EAAE,EAAE;AAChB,oBAAA,WAAW,EAAE,KAAK;AAClB,oBAAA,GAAG,EAAE,EAAE,GAAG,QAAQ,CAAC,WAAW,EAAE;AACjC,iBAAA;AACD,gBAAA,UAAU,EAAE,cAAc,KAAA,IAAA,IAAd,cAAc,KAAA,MAAA,GAAd,cAAc,GAAI,GAAG;aAClC;QACH;QAEA,OAAO;AACL,YAAA,GAAG,WAAW;YACd,KAAK;SACN;IACH;AACD;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/SuppressingRestClient.ts","../src/utils/isBlank.ts","../src/utils/yearsSince.ts","../src/MPoPComponents.ts","../src/utils/govukTime.ts","../src/utils/dateWithYear.ts","../src/utils/toTitleCase.ts","../src/utils/nunjucksFilters.ts"],"sourcesContent":[null,null,null,null,null,null,null,null],"names":["DateTime","RestClient"],"mappings":";;;;;MAGa,qBAAqB,CAAA;IAChC,WAAA,CACmB,UAAsB,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W,CAAC;AAC3C;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  import { ApiConfig, AuthOptions } from '@ministryofjustice/hmpps-rest-client';
2
2
  import { AuthenticationClient } from '@ministryofjustice/hmpps-auth-clients';
3
3
  import Logger from 'bunyan';
4
+ import { Environment } from 'nunjucks';
4
5
 
5
6
  interface MPoPComponentsConfig extends ApiConfig {
7
+ masApiConfig?: ApiConfig;
8
+ supervisionPackageApiConfig?: ApiConfig;
6
9
  }
7
10
 
8
11
  type TierTag = {
@@ -25,11 +28,109 @@ type LatestTierResponse = {
25
28
  error?: Error | null;
26
29
  };
27
30
 
31
+ type PersonalDetailsResponse = {
32
+ personalDetails: PersonalDetailsSummary | null;
33
+ httpStatus: number;
34
+ error?: Error | null;
35
+ };
36
+ type PersonalDetailsSummary = {
37
+ name: {
38
+ forename: string;
39
+ middleName: string;
40
+ surname: string;
41
+ };
42
+ crn: string;
43
+ offenderId: number;
44
+ pnc: string;
45
+ noms: string;
46
+ dateOfBirth: string;
47
+ age: string | null;
48
+ };
49
+
50
+ type SupervisionPackage = {
51
+ phase: {
52
+ name: {
53
+ code: string;
54
+ description: string;
55
+ };
56
+ startDate: string;
57
+ endDate: string;
58
+ };
59
+ earlyEngagement: {
60
+ startDate: string;
61
+ endDate: string;
62
+ weeks: number;
63
+ completed: number;
64
+ };
65
+ currentYear: {
66
+ startDate: string;
67
+ endDate: string;
68
+ isFirstYear: boolean;
69
+ appointments: {
70
+ allowance: number;
71
+ scheduled: number;
72
+ completed: number;
73
+ };
74
+ };
75
+ inputs: {
76
+ date: string;
77
+ gender: string;
78
+ integratedOffenderManagementRedRated: boolean;
79
+ offenderPersonalDisorderPathway: boolean;
80
+ intensiveSupervisionCourt: boolean;
81
+ nationalSecurityDivision: boolean;
82
+ contactSuspendedDate?: string;
83
+ finalThirdEligibility: {
84
+ eligible: boolean;
85
+ since: string;
86
+ };
87
+ sentences: Array<Sentence>;
88
+ };
89
+ };
90
+ type Sentence = {
91
+ eventNumber: string;
92
+ startDate: string;
93
+ endDate: string;
94
+ supervisionPackage: {
95
+ code: string;
96
+ description: string;
97
+ };
98
+ type: {
99
+ code: string;
100
+ description: string;
101
+ isCustodial: boolean;
102
+ };
103
+ custody: {
104
+ status: {
105
+ code: string;
106
+ description: string;
107
+ };
108
+ finalThirdDate: string;
109
+ releases: Array<Release>;
110
+ };
111
+ inBreach: boolean;
112
+ };
113
+ type Release = {
114
+ releaseDate: string;
115
+ recallDate?: string;
116
+ };
117
+ type SupervisionPackageResponse = {
118
+ supervisionPackage: SupervisionPackage | null;
119
+ httpStatus: number;
120
+ error?: Error | null;
121
+ };
122
+
28
123
  declare class MPoPComponents {
29
124
  private readonly tierApiRestClient;
125
+ private readonly masApiRestClient;
126
+ private readonly supervisionPackageApiRestClient;
30
127
  constructor(authenticationClient: AuthenticationClient, config: MPoPComponentsConfig, logger?: Logger | Console);
31
128
  getTierDetails(authOptions: AuthOptions | string, crn: string): Promise<LatestTierResponse>;
129
+ getPersonalDetails(authOptions: AuthOptions | string, crn: string): Promise<PersonalDetailsResponse>;
130
+ getSupervisionPackage(authOptions: AuthOptions | string, crn: string): Promise<SupervisionPackageResponse>;
32
131
  }
33
132
 
34
- export { MPoPComponents };
133
+ declare const mpopNunjucksSetup: (env: Environment) => void;
134
+
135
+ export { MPoPComponents, mpopNunjucksSetup as addFilters, mpopNunjucksSetup };
35
136
  export type { MPoPComponentsConfig };
package/dist/index.esm.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { RestClient } from '@ministryofjustice/hmpps-rest-client';
2
+ import { DateTime } from 'luxon';
2
3
 
3
4
  class SuppressingRestClient {
4
5
  constructor(restClient, logger) {
@@ -19,6 +20,18 @@ class SuppressingRestClient {
19
20
  }
20
21
  }
21
22
 
23
+ const isBlank = (str) => !str || /^\s*$/.test(str);
24
+
25
+ const yearsSince = (datetimeString) => {
26
+ if (!datetimeString || isBlank(datetimeString))
27
+ return null;
28
+ const dt = DateTime.fromISO(datetimeString, { zone: 'Europe/London' });
29
+ if (!dt.isValid)
30
+ return null;
31
+ const years = Math.trunc(DateTime.now().diff(dt, ['years', 'months']).years);
32
+ return years.toString();
33
+ };
34
+
22
35
  const tierTags = {
23
36
  missing: { text: 'Missing', color: 'red' },
24
37
  provisional: { text: 'Provisional', color: 'orange' },
@@ -27,7 +40,10 @@ const tierTags = {
27
40
  };
28
41
  class MPoPComponents {
29
42
  constructor(authenticationClient, config, logger = console) {
43
+ var _a, _b;
30
44
  this.tierApiRestClient = new SuppressingRestClient(new RestClient('Tier API', config, logger, authenticationClient), logger);
45
+ this.masApiRestClient = new SuppressingRestClient(new RestClient('MAS API', (_a = config.masApiConfig) !== null && _a !== void 0 ? _a : config, logger, authenticationClient), logger);
46
+ this.supervisionPackageApiRestClient = new SuppressingRestClient(new RestClient('Supervision Package API', (_b = config.supervisionPackageApiConfig) !== null && _b !== void 0 ? _b : config, logger, authenticationClient), logger);
31
47
  }
32
48
  async getTierDetails(authOptions, crn) {
33
49
  let error = null;
@@ -84,7 +100,101 @@ class MPoPComponents {
84
100
  error,
85
101
  };
86
102
  }
103
+ async getPersonalDetails(authOptions, crn) {
104
+ let error = null;
105
+ let personalDetailsResponse;
106
+ try {
107
+ const response = await this.masApiRestClient.get(`/personal-details/${crn}/summary`, authOptions);
108
+ if (!response) {
109
+ personalDetailsResponse = {
110
+ personalDetails: null,
111
+ httpStatus: 404,
112
+ };
113
+ }
114
+ else {
115
+ personalDetailsResponse = {
116
+ personalDetails: { ...response, age: yearsSince(response.dateOfBirth) },
117
+ httpStatus: 200,
118
+ };
119
+ }
120
+ }
121
+ catch (err) {
122
+ error = err instanceof Error ? err : new Error('500 Internal Server Error');
123
+ const responseStatus = err === null || err === void 0 ? void 0 : err.responseStatus;
124
+ personalDetailsResponse = {
125
+ personalDetails: null,
126
+ httpStatus: responseStatus !== null && responseStatus !== void 0 ? responseStatus : 500,
127
+ };
128
+ }
129
+ return {
130
+ ...personalDetailsResponse,
131
+ error,
132
+ };
133
+ }
134
+ async getSupervisionPackage(authOptions, crn) {
135
+ let error = null;
136
+ let supervisionPackageResponse;
137
+ try {
138
+ const response = await this.supervisionPackageApiRestClient.get(`/case/${crn}/current-phase`, authOptions);
139
+ if (!response) {
140
+ supervisionPackageResponse = {
141
+ supervisionPackage: null,
142
+ httpStatus: 404,
143
+ };
144
+ }
145
+ else {
146
+ supervisionPackageResponse = {
147
+ supervisionPackage: response,
148
+ httpStatus: 200,
149
+ };
150
+ }
151
+ }
152
+ catch (err) {
153
+ const responseStatus = err === null || err === void 0 ? void 0 : err.responseStatus;
154
+ error = err instanceof Error ? err : new Error('500 Internal Server Error');
155
+ supervisionPackageResponse = {
156
+ supervisionPackage: null,
157
+ httpStatus: responseStatus !== null && responseStatus !== void 0 ? responseStatus : 500,
158
+ };
159
+ }
160
+ return {
161
+ ...supervisionPackageResponse,
162
+ error,
163
+ };
164
+ }
87
165
  }
88
166
 
89
- export { MPoPComponents };
167
+ const govukTime = (datetimeString) => {
168
+ if (!datetimeString || isBlank(datetimeString))
169
+ return null;
170
+ const datetime = DateTime.fromISO(datetimeString);
171
+ if (!datetime.isValid)
172
+ return null;
173
+ const hourMinuteFormat = datetime.minute === 0 ? 'ha' : 'h:mma';
174
+ return datetime.toFormat(hourMinuteFormat).toLowerCase();
175
+ };
176
+
177
+ const dateWithYear = (datetimeString, showTime = false) => {
178
+ if (!datetimeString || isBlank(datetimeString))
179
+ return null;
180
+ const dt = DateTime.fromISO(datetimeString, { zone: 'Europe/London' });
181
+ if (!dt.isValid)
182
+ return null;
183
+ const time = showTime ? govukTime(datetimeString) : null;
184
+ return `${dt.toFormat('d MMMM yyyy')}${time ? ` at ${time}` : ''}`;
185
+ };
186
+
187
+ const toTitleCase = (value) => {
188
+ if (!value)
189
+ return '';
190
+ const lower = value.toLowerCase();
191
+ return `${lower.charAt(0).toUpperCase()}${lower.substring(1)}`;
192
+ };
193
+
194
+ const mpopNunjucksSetup = (env) => {
195
+ env.addFilter('dateWithYear', dateWithYear);
196
+ env.addFilter('toTitleCase', toTitleCase);
197
+ };
198
+
199
+ export { MPoPComponents, mpopNunjucksSetup as addFilters, mpopNunjucksSetup };
90
200
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/SuppressingRestClient.ts","../src/MPoPComponents.ts"],"sourcesContent":[null,null],"names":[],"mappings":";;MAGa,qBAAqB,CAAA;IAChC,WAAA,CACmB,UAAsB,EACtB,MAAwB,EAAA;QADxB,IAAA,CAAA,UAAU,GAAV,UAAU;QACV,IAAA,CAAA,MAAM,GAAN,MAAM;IACtB;AAEH,IAAA,MAAM,GAAG,CAAI,IAAY,EAAE,WAAiC,EAAA;AAC1D,QAAA,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CACxB;YACE,IAAI;YACJ,YAAY,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,KAAI;AAC3C,gBAAA,IAAI,KAAK,CAAC,cAAc,KAAK,GAAG,EAAE;oBAChC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA,iCAAA,EAAoC,MAAM,CAAA,EAAA,EAAK,WAAW,CAAA,CAAE,CAAC;AAC/E,oBAAA,OAAO,IAAI;gBACb;AACA,gBAAA,MAAM,KAAK;YACb,CAAC;SACF,EACD,WAAW,CACZ;IACH;AACD;;ACfM,MAAM,QAAQ,GAA4B;IAC/C,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE;IAC1C,WAAW,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,EAAE;IACrD,WAAW,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE;IACnD,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;CAClC;AAEa,MAAO,cAAc,CAAA;AAGjC,IAAA,WAAA,CACE,oBAA0C,EAC1C,MA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AAE;AACpC,oBAAA,UAAU,EAAE,GAAG;iBAChB;YACH;QACF;QAAE,OAAO,GAAG,EAAE;AACZ,YAAA,KAAK,GAAG,GAAG,YAAY,KAAK,GAAG,GAAG,GAAG,IAAI,KAAK,CAAC,2BAA2B,CAAC;YAC3E,MAAM,cAAc,GAAI,GAA0C,KAAA,IAAA,IAA1C,GAAG,KAAA,MAAA,GAAA,MAAA,GAAH,GAAG,CAAyC,cAAc;AAElF,YAAA,WAAW,GAAG;AACZ,gBAAA,WAAW,EAAE;AACX,oBAAA,SAAS,EAAE,EAAE;AACb,oBAAA,aAAa,EAAE,EAAE;AACjB,oBAAA,eAAe,EAAE,EAAE;AACnB,oBAAA,YAAY,EAAE,EAAE;AAChB,oBAAA,WAAW,EAAE,KAAK;AAClB,oBAAA,GAAG,EAAE,EAAE,GAAG,QAAQ,CAAC,WAAW,EAAE;AACjC,iBAAA;AACD,gBAAA,UAAU,EAAE,cAAc,KAAA,IAAA,IAAd,cAAc,KAAA,MAAA,GAAd,cAAc,GAAI,GAAG;aAClC;QACH;QAEA,OAAO;AACL,YAAA,GAAG,WAAW;YACd,KAAK;SACN;IACH;AACD;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/SuppressingRestClient.ts","../src/utils/isBlank.ts","../src/utils/yearsSince.ts","../src/MPoPComponents.ts","../src/utils/govukTime.ts","../src/utils/dateWithYear.ts","../src/utils/toTitleCase.ts","../src/utils/nunjucksFilters.ts"],"sourcesContent":[null,null,null,null,null,null,null,null],"names":[],"mappings":";;;MAGa,qBAAqB,CAAA;IAChC,WAAA,CACmB,UAAsB,EACtB,MAAwB,EAAA;QADxB,IAAA,CAAA,UAAU,GAAV,UAAU;QACV,IAAA,CAAA,MAAM,GAAN,MAAM;IACtB;AAEH,IAAA,MAAM,GAAG,CAAI,IAAY,EAAE,WAAiC,EAAA;AAC1D,QAAA,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CACxB;YACE,IAAI;YACJ,YAAY,EAAE,C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AAG,CAAC,cAAsB,EAAE,QAAQ,GAAG,KAAK,KAAmB;AACtF,IAAA,IAAI,CAAC,cAAc,IAAI,OAAO,CAAC,cAAc,CAAC;AAAE,QAAA,OAAO,IAAI;AAE3D,IAAA,MAAM,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;IACtE,IAAI,CAAC,EAAE,CAAC,OAAO;AAAE,QAAA,OAAO,IAAI;AAE5B,IAAA,MAAM,IAAI,GAAG,QAAQ,GAAG,SAAS,CAAC,cAAc,CAAC,GAAG,IAAI;IACxD,OAAO,CAAA,EAAG,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,IAAI,GAAG,CAAA,IAAA,EAAO,IAAI,CAAA,CAAE,GAAG,EAAE,EAAE;AACpE,CAAC;;ACZM,MAAM,WAAW,GAAG,CAAC,KAAgC,KAAY;AACtE,IAAA,IAAI,CAAC,KAAK;AAAE,QAAA,OAAO,EAAE;AACrB,IAAA,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE;AACjC,IAAA,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA,EAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;AAChE,CAAC;;ACAM,MAAM,iBAAiB,GAAG,CAAC,GAAgB,KAAU;AAC1D,IAAA,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,YAAY,CAAC;AAC3C,IAAA,GAAG,CAAC,SAAS,CAAC,aAAa,EAAE,WAAW,CAAC;AAC3C;;;;"}
@@ -0,0 +1,12 @@
1
+ .inline-list-from-tablet {
2
+ > li {
3
+ @include govuk-media-query($from: tablet) {
4
+ display: inline;
5
+ }
6
+ }
7
+ }
8
+
9
+
10
+ .pop-header__details {
11
+ display: flex;
12
+ }
@@ -0,0 +1,3 @@
1
+ {% macro popHeader(params) %}
2
+ {% include './template.njk' %}
3
+ {% endmacro %}
@@ -0,0 +1,18 @@
1
+ <div class='pop-header__details'>
2
+ <div>
3
+ <ul class='govuk-list govuk-caption-m inline-list-from-tablet'>
4
+ <li>CRN:
5
+ <span data-qa='crn'>{{ params.crn }}</span>
6
+ <span class='govuk-!-padding-left-3 govuk-!-padding-right-3 hide-mobile'>|</span>
7
+ </li>
8
+ <li>Date of birth:
9
+ <span data-qa='headerDateOfBirthValue'>{{ params.dob }}</span>
10
+ {% if params.age %}(<span data-qa='headerDateOfBirthAge'>{{ params.age }} years old</span>){% endif %}
11
+ <span class='govuk-!-padding-left-3 govuk-!-padding-right-3 hide-mobile'>|</span>
12
+ </li>
13
+ <li>Tier:{{' '}}
14
+ <a href='{{ params.historyHref }}' data-qa='tierLink' class='govuk-link'>{{ params.tierScore }}</a>
15
+ </li>
16
+ </ul>
17
+ </div>
18
+ </div>
@@ -18,5 +18,29 @@ $supervision-package-accent-colour: govuk-colour("blue");
18
18
  display: flex;
19
19
  align-items: center;
20
20
  gap: govuk-spacing(2);
21
+ flex-wrap: wrap;
21
22
  margin-bottom: govuk-spacing(3);
22
- }
23
+
24
+ > h2,
25
+ > h3 {
26
+ white-space: nowrap;
27
+ }
28
+ }
29
+
30
+ .appointment-progress {
31
+ background-color: govuk-colour("teal", $variant: "tint-80");
32
+ border-radius: 20px;
33
+ height: 19px;
34
+ overflow: hidden;
35
+ width: 100%;
36
+ }
37
+
38
+ .appointment-progress__bar {
39
+ background-color: govuk-colour("teal", $variant: "tint-25");
40
+ height: 100%;
41
+ }
42
+
43
+ .appointment-progress__bar-maximum {
44
+ background-color: govuk-colour("red");
45
+ height: 100%;
46
+ }
@@ -1,3 +1,3 @@
1
1
  {% macro supervisionPackage(params) %}
2
- {% include "./template.njk" %}
3
- {% endmacro %}
2
+ {% include './template.njk' %}
3
+ {% endmacro %}
@@ -0,0 +1,21 @@
1
+ {% if params.forename and (params.earlyEngagement.completed | int < params.earlyEngagement.weeks | int) %}
2
+ <p class='govuk-body'>You should see {{ params.forename }} every week for the first {{ params.earlyEngagement.weeks }} weeks of the sentence.</p>
3
+ {% endif %}
4
+
5
+ {% if params.forename and params.currentYear.appointments.allowance is defined and params.earlyEngagement.weeks is defined %}
6
+ <p class='govuk-body'>
7
+ Early engagement ends on {{ params.phase.endDate | dateWithYear }}{% if params.forename and (params.earlyEngagement.completed | int < params.earlyEngagement.weeks | int) %} if {{ params.forename }} attends the required appointments by then{% endif %}.
8
+ </p>
9
+ {% endif %}
10
+
11
+ {% if params.currentYear.appointments.allowance is defined and params.earlyEngagement.weeks is defined %}
12
+ <p class='govuk-body'>{{ params.forename }} will then have a maximum of {{ (params.currentYear.appointments.allowance | int) - (params.earlyEngagement.weeks | int) }} supervision appointments for the rest of this sentence year.</p>
13
+ {% endif %}
14
+
15
+ {% include './_progress-bar.njk' %}
16
+
17
+ {% if params.allAppointmentsHref %}
18
+ <p class='govuk-body'>
19
+ <a class='govuk-link govuk-link--no-visited-state' href='{{ params.allAppointmentsHref }}' >View all appointments</a>
20
+ </p>
21
+ {% endif %}
@@ -0,0 +1,38 @@
1
+ {% if params.phase.name.code == 'INIT' %}
2
+ {% set completed = params.earlyEngagement.completed | int %}
3
+ {% set allowance = params.earlyEngagement.weeks | int %}
4
+ {% else %}
5
+ {% set completed = params.currentYear.appointments.completed | int %}
6
+ {% set allowance = (params.currentYear.appointments.allowance | int) - (params.earlyEngagement.weeks | int) %}
7
+ {% endif %}
8
+
9
+ {% if allowance > 0 %}
10
+ {% set rawPercent = (completed / allowance * 100) | round %}
11
+ {% else %}
12
+ {% set rawPercent = 0 %}
13
+ {% endif %}
14
+
15
+ {% set widthPercent = 100 if rawPercent > 100 else (0 if rawPercent < 0 else rawPercent) %}
16
+
17
+ <p class='govuk-body'>{{ completed }} of {{ allowance }} appointments used</p>
18
+
19
+ <div class="appointment-progress" aria-hidden="true">
20
+ <div class="{{ 'appointment-progress__bar-maximum' if widthPercent == 100 else 'appointment-progress__bar' }}" style="width: {{ widthPercent }}%;"></div>
21
+ </div>
22
+
23
+ <div class='govuk-grid-row govuk-!-margin-top-4'>
24
+ <div class='govuk-grid-column-one-third'>
25
+ <p class='govuk-body govuk-!-margin-bottom-2'>Maximum</p>
26
+ <p class='govuk-body-l govuk-!-font-weight-bold'>{{ allowance }}</p>
27
+ </div>
28
+
29
+ <div class='govuk-grid-column-one-third'>
30
+ <p class='govuk-body govuk-!-margin-bottom-2'>Remaining</p>
31
+ <p class='govuk-body-l govuk-!-font-weight-bold'>{{ allowance - completed }}</p>
32
+ </div>
33
+
34
+ <div class='govuk-grid-column-one-third'>
35
+ <p class='govuk-body govuk-!-margin-bottom-2'>Upcoming</p>
36
+ <p class='govuk-body-l govuk-!-font-weight-bold'>{{ params.currentYear.appointments.scheduled | int }}</p>
37
+ </div>
38
+ </div>
@@ -0,0 +1,19 @@
1
+ {% if params.currentYear.appointments.allowance is defined and params.currentYear.appointments.completed is defined and (params.currentYear.appointments.completed | int) >= (params.currentYear.appointments.allowance | int) and not params.inputs.offenderPersonalDisorderPathway %}
2
+ <strong class='app-status-badge govuk-tag govuk-tag--red'>No appointments remaining</strong>
3
+ {% endif %}
4
+
5
+ {% if params.isInBreach %}
6
+ <strong class='app-status-badge govuk-tag govuk-tag--yellow'>In breach</strong>
7
+ {% endif %}
8
+
9
+ {% if params.isCustody %}
10
+ <strong class='app-status-badge govuk-tag govuk-tag--yellow'>In custody</strong>
11
+ {% endif %}
12
+
13
+ {% if params.inputs.offenderPersonalDisorderPathway %}
14
+ <strong class='app-status-badge govuk-tag govuk-tag--purple'>Offender personality disorder</strong>
15
+ {% endif %}
16
+
17
+ {% if params.inputs.integratedOffenderManagementRedRated %}
18
+ <strong class='app-status-badge govuk-tag govuk-tag--red'>IOM (Integrated Offender Management): Red</strong>
19
+ {% endif %}
@@ -1,37 +1,77 @@
1
- <div class="govuk-width-container supervision-package">
2
- <h2 class="govuk-heading-m">{{ params.heading or "Supervision package" }}</h2>
3
-
4
- <div class="govuk-grid-row">
5
- <div class="govuk-grid-column-two-thirds">
6
- <div class="app-tier-header">
7
- <h3 class="govuk-heading-s govuk-!-margin-bottom-0">
8
- Tier {{ params.tierScore }}
9
- </h3>
1
+ {% set standardAppointmentsComplete = params.currentYear.appointments.allowance is defined and params.currentYear.appointments.completed is defined and (params.currentYear.appointments.completed | int) >= (params.currentYear.appointments.allowance| int) %}
2
+ {% set hasSpecialStatus = params.inputs.offenderPersonalDisorderPathway or params.isInBreach or params.isCustody or params.inputs.integratedOffenderManagementRedRated %}
3
+
4
+ <div class='govuk-width-container supervision-package'>
5
+ {% if standardAppointmentsComplete or hasSpecialStatus %}
6
+ <div class='app-tier-header'>
7
+ <h2 class='govuk-heading-m govuk-!-margin-bottom-0'>{{ 'Supervision package: ' ~ params.sentenceType if params.sentenceType else 'Supervision package' }}</h2>
8
+ {% include './partials/_tags.njk' %}
9
+ </div>
10
+ {% else %}
11
+ <h2 class='govuk-heading-m'>{{ 'Supervision package: ' ~ params.sentenceType if params.sentenceType else 'Supervision package' }}</h2>
12
+ {% endif %}
10
13
 
14
+ <div class='govuk-grid-row'>
15
+ <div class='{{ "govuk-grid-column-one-half" if params.phase.name.description else "govuk-grid-column-two-thirds" }}'>
16
+ <div class='app-tier-header'>
17
+ <h3 class='govuk-heading-s govuk-!-margin-bottom-0'>
18
+ Tier {{ '' if params.tierScore == 'MISSING' else params.tierScore }}
19
+ </h3>
11
20
  {% if params.tag.text and params.tag.color %}
12
- <strong class="govuk-tag govuk-tag--{{ params.tag.color }}">{{ params.tag.text }}</strong>
21
+ <strong class='govuk-tag govuk-tag--{{ params.tag.color }}'>{{ params.tag.text }}</strong>
13
22
  {% endif %}
14
23
  </div>
15
24
 
25
+ {% if params.createdOn %}
26
+ <p class='govuk-body'>The supervision package was created on {{ params.createdOn }}.</p>
27
+ {% endif %}
28
+
16
29
  {% if params.tag.text == 'Provisional' %}
17
- <p class="govuk-body">
30
+ <p class='govuk-body'>
18
31
  We will calculate the supervision package once the tier is confirmed.
19
32
  </p>
20
33
  {% endif %}
21
34
 
22
35
  {% if params.tag.text == 'Unavailable' %}
23
- <p class="govuk-body">
36
+ <p class='govuk-body'>
24
37
  Tier information is currently unavailable.
25
38
  </p>
26
39
  {% endif %}
27
40
 
28
41
  {% if params.historyHref %}
29
- <p class="govuk-body">
30
- <a href="{{ params.historyHref }}" class="govuk-link govuk-link--no-visited-state">
31
- {{ params.historyText or "View tier change history" }}
42
+ <p class='govuk-body'>
43
+ <a href='{{ params.historyHref }}' class='govuk-link govuk-link--no-visited-state'>
44
+ {{ params.historyText or 'View tier change history' }}
32
45
  </a>
33
46
  </p>
34
47
  {% endif %}
48
+
49
+ {% if params.nextAppointment and params.nextAppointmentHref %}
50
+ <h3 class='govuk-heading-s'>Next appointment</h3>
51
+ <p class='govuk-body'>
52
+ <a href='{{ params.nextAppointmentHref }}' class='govuk-link govuk-link--no-visited-state'>{{ params.nextAppointment }}</a>
53
+ </p>
54
+ {% endif %}
35
55
  </div>
56
+
57
+ {% if params.phase.name.description %}
58
+ <div class='govuk-grid-column-one-half'>
59
+ <h3 class='govuk-heading-s'>{{ params.phase.name.description | toTitleCase }} stage</h3>
60
+ {% if params.phase.name.code == 'INIT' %}
61
+ {% include './partials/_early-engagement.njk' %}
62
+ {% endif %}
63
+ </div>
64
+ {% endif %}
36
65
  </div>
66
+
67
+ {% if params.arrangeAppointmentHref and params.updateRiskFlagHref %}
68
+ <div class='govuk-button-group'>
69
+ <a href='{{ params.arrangeAppointmentHref }}' role='button' draggable='false' class='govuk-button' data-module='govuk-button'>
70
+ Arrange an appointment
71
+ </a>
72
+ <a href='{{ params.updateRiskFlagHref }}' role='button' draggable='false' class='govuk-button govuk-button--secondary' data-module='govuk-button'>
73
+ Update NDelius risk flag
74
+ </a>
75
+ </div>
76
+ {% endif %}
37
77
  </div>
@@ -1,3 +1,5 @@
1
1
  import type { ApiConfig } from '@ministryofjustice/hmpps-rest-client';
2
2
  export interface MPoPComponentsConfig extends ApiConfig {
3
+ masApiConfig?: ApiConfig;
4
+ supervisionPackageApiConfig?: ApiConfig;
3
5
  }
@@ -0,0 +1,18 @@
1
+ export type PersonalDetailsResponse = {
2
+ personalDetails: PersonalDetailsSummary | null;
3
+ httpStatus: number;
4
+ error?: Error | null;
5
+ };
6
+ export type PersonalDetailsSummary = {
7
+ name: {
8
+ forename: string;
9
+ middleName: string;
10
+ surname: string;
11
+ };
12
+ crn: string;
13
+ offenderId: number;
14
+ pnc: string;
15
+ noms: string;
16
+ dateOfBirth: string;
17
+ age: string | null;
18
+ };
@@ -0,0 +1,73 @@
1
+ export type SupervisionPackage = {
2
+ phase: {
3
+ name: {
4
+ code: string;
5
+ description: string;
6
+ };
7
+ startDate: string;
8
+ endDate: string;
9
+ };
10
+ earlyEngagement: {
11
+ startDate: string;
12
+ endDate: string;
13
+ weeks: number;
14
+ completed: number;
15
+ };
16
+ currentYear: {
17
+ startDate: string;
18
+ endDate: string;
19
+ isFirstYear: boolean;
20
+ appointments: {
21
+ allowance: number;
22
+ scheduled: number;
23
+ completed: number;
24
+ };
25
+ };
26
+ inputs: {
27
+ date: string;
28
+ gender: string;
29
+ integratedOffenderManagementRedRated: boolean;
30
+ offenderPersonalDisorderPathway: boolean;
31
+ intensiveSupervisionCourt: boolean;
32
+ nationalSecurityDivision: boolean;
33
+ contactSuspendedDate?: string;
34
+ finalThirdEligibility: {
35
+ eligible: boolean;
36
+ since: string;
37
+ };
38
+ sentences: Array<Sentence>;
39
+ };
40
+ };
41
+ type Sentence = {
42
+ eventNumber: string;
43
+ startDate: string;
44
+ endDate: string;
45
+ supervisionPackage: {
46
+ code: string;
47
+ description: string;
48
+ };
49
+ type: {
50
+ code: string;
51
+ description: string;
52
+ isCustodial: boolean;
53
+ };
54
+ custody: {
55
+ status: {
56
+ code: string;
57
+ description: string;
58
+ };
59
+ finalThirdDate: string;
60
+ releases: Array<Release>;
61
+ };
62
+ inBreach: boolean;
63
+ };
64
+ type Release = {
65
+ releaseDate: string;
66
+ recallDate?: string;
67
+ };
68
+ export type SupervisionPackageResponse = {
69
+ supervisionPackage: SupervisionPackage | null;
70
+ httpStatus: number;
71
+ error?: Error | null;
72
+ };
73
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const dateWithYear: (datetimeString: string, showTime?: boolean) => string | null;
2
+ export declare const dateToLongDate: (dmyDate: string) => string | null;
3
+ export declare const dateWithYearTimeFirst: (datetimeString: string) => string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const govukTime: (datetimeString?: string) => string | null;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const isBlank: (str: string) => boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { Environment } from 'nunjucks';
2
+ export declare const mpopNunjucksSetup: (env: Environment) => void;
@@ -0,0 +1 @@
1
+ export declare const toTitleCase: (value: string | null | undefined) => string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const yearsSince: (datetimeString: string) => string | null;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ministryofjustice/hmpps-mpop-frontend-components-lib",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "MPOP front-end components library",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",
@@ -71,6 +71,7 @@
71
71
  "@types/bunyan": "^1.8.11",
72
72
  "@types/jest": "^30.0.0",
73
73
  "@types/jsdom": "^28.0.3",
74
+ "@types/luxon": "3.7.1",
74
75
  "@types/node": "25.9.1",
75
76
  "@typescript-eslint/eslint-plugin": "8.60.1",
76
77
  "babel-jest": "^30.4.1",
@@ -92,6 +93,7 @@
92
93
  },
93
94
  "type": "commonjs",
94
95
  "dependencies": {
96
+ "luxon": "3.7.2",
95
97
  "@ministryofjustice/hmpps-auth-clients": "^1.0.1",
96
98
  "@ministryofjustice/hmpps-rest-client": "^1.2.1",
97
99
  "@types/nunjucks": "3.2.6",