@hmcts/opal-frontend-common 0.0.2

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 (262) hide show
  1. package/README.md +24 -0
  2. package/esm2022/hmcts-opal-frontend-common.mjs +5 -0
  3. package/esm2022/lib/components/govuk/govuk-button/govuk-button.component.mjs +34 -0
  4. package/esm2022/lib/components/govuk/govuk-text-input/govuk-text-input.component.mjs +57 -0
  5. package/esm2022/lib/components/govuk/index.mjs +3 -0
  6. package/esm2022/lib/guards/auth/auth.guard.mjs +20 -0
  7. package/esm2022/lib/guards/auth/index.mjs +2 -0
  8. package/esm2022/lib/guards/can-deactivate/can-deactivate.guard.mjs +6 -0
  9. package/esm2022/lib/guards/can-deactivate/index.mjs +5 -0
  10. package/esm2022/lib/guards/can-deactivate/interfaces/can-deactivate-can-component-deactivate.interface.mjs +2 -0
  11. package/esm2022/lib/guards/can-deactivate/interfaces/index.mjs +2 -0
  12. package/esm2022/lib/guards/has-flow-state/has-flow-state.guard.mjs +16 -0
  13. package/esm2022/lib/guards/has-flow-state/index.mjs +2 -0
  14. package/esm2022/lib/guards/helpers/get-guard-with-dummy-url.mjs +19 -0
  15. package/esm2022/lib/guards/helpers/handle-observable-result.mjs +13 -0
  16. package/esm2022/lib/guards/helpers/index.mjs +5 -0
  17. package/esm2022/lib/guards/helpers/run-auth-guard-with-context.mjs +15 -0
  18. package/esm2022/lib/guards/helpers/run-has-flow-state-guard-with-context.mjs +9 -0
  19. package/esm2022/lib/guards/index.mjs +10 -0
  20. package/esm2022/lib/guards/route-permissions/index.mjs +2 -0
  21. package/esm2022/lib/guards/route-permissions/route-permissions.guard.mjs +25 -0
  22. package/esm2022/lib/guards/signed-in/index.mjs +3 -0
  23. package/esm2022/lib/guards/signed-in/signed-in.guard.mjs +20 -0
  24. package/esm2022/lib/guards/types/can-deactivate.type.mjs +2 -0
  25. package/esm2022/lib/guards/types/guard-return.type.mjs +2 -0
  26. package/esm2022/lib/guards/types/index.mjs +3 -0
  27. package/esm2022/lib/interceptors/http-error/http-error.interceptor.mjs +24 -0
  28. package/esm2022/lib/interceptors/index.mjs +3 -0
  29. package/esm2022/lib/opal-frontend-common.module.mjs +22 -0
  30. package/esm2022/lib/pages/access-denied/access-denied.component.mjs +18 -0
  31. package/esm2022/lib/pages/index.mjs +4 -0
  32. package/esm2022/lib/pages/routing/constants/routing-paths.constant.mjs +9 -0
  33. package/esm2022/lib/pages/routing/constants/routing-titles.constant.mjs +9 -0
  34. package/esm2022/lib/pages/routing/interfaces/routing-paths.interface.mjs +2 -0
  35. package/esm2022/lib/pages/routing/pages.routes.mjs +24 -0
  36. package/esm2022/lib/pages/sign-in/interfaces/index.mjs +2 -0
  37. package/esm2022/lib/pages/sign-in/interfaces/sign-in-stub-form.interface.mjs +2 -0
  38. package/esm2022/lib/pages/sign-in/sign-in-sso/sign-in-sso.component.mjs +23 -0
  39. package/esm2022/lib/pages/sign-in/sign-in-stub/sign-in-stub.component.mjs +39 -0
  40. package/esm2022/lib/pages/sign-in/sign-in.component.mjs +38 -0
  41. package/esm2022/lib/resolvers/index.mjs +3 -0
  42. package/esm2022/lib/resolvers/title/index.mjs +2 -0
  43. package/esm2022/lib/resolvers/title/title.resolver.mjs +22 -0
  44. package/esm2022/lib/resolvers/user-state/index.mjs +2 -0
  45. package/esm2022/lib/resolvers/user-state/user-state.resolver.mjs +12 -0
  46. package/esm2022/lib/routing/constants/index.mjs +2 -0
  47. package/esm2022/lib/routing/constants/sso-endpoints.constant.mjs +7 -0
  48. package/esm2022/lib/routing/index.mjs +3 -0
  49. package/esm2022/lib/routing/interfaces/child-routing-paths.interface.mjs +2 -0
  50. package/esm2022/lib/routing/interfaces/index.mjs +4 -0
  51. package/esm2022/lib/routing/interfaces/nested-routes.interface.mjs +2 -0
  52. package/esm2022/lib/routing/interfaces/sso-endpoints.interface.mjs +2 -0
  53. package/esm2022/lib/services/app-initializer-service/app-initializer.service.mjs +36 -0
  54. package/esm2022/lib/services/app-initializer-service/index.mjs +2 -0
  55. package/esm2022/lib/services/app-insights/app-insights.service.mjs +73 -0
  56. package/esm2022/lib/services/app-insights/index.mjs +4 -0
  57. package/esm2022/lib/services/auth-service/auth.service.mjs +36 -0
  58. package/esm2022/lib/services/auth-service/index.mjs +2 -0
  59. package/esm2022/lib/services/date-service/date.service.mjs +182 -0
  60. package/esm2022/lib/services/date-service/index.mjs +4 -0
  61. package/esm2022/lib/services/index.mjs +12 -0
  62. package/esm2022/lib/services/launch-darkly/index.mjs +5 -0
  63. package/esm2022/lib/services/launch-darkly/launch-darkly.service.mjs +94 -0
  64. package/esm2022/lib/services/launch-darkly/mocks/index.mjs +3 -0
  65. package/esm2022/lib/services/launch-darkly/mocks/launch-darkly-change-flags.mock.mjs +5 -0
  66. package/esm2022/lib/services/launch-darkly/mocks/launch-darkly-flags.mock.mjs +5 -0
  67. package/esm2022/lib/services/permissions-service/index.mjs +4 -0
  68. package/esm2022/lib/services/permissions-service/permissions.service.mjs +40 -0
  69. package/esm2022/lib/services/session-service/constants/index.mjs +2 -0
  70. package/esm2022/lib/services/session-service/constants/session-endpoints.constant.mjs +5 -0
  71. package/esm2022/lib/services/session-service/index.mjs +7 -0
  72. package/esm2022/lib/services/session-service/interfaces/index.mjs +4 -0
  73. package/esm2022/lib/services/session-service/interfaces/session-endpoints.interface.mjs +2 -0
  74. package/esm2022/lib/services/session-service/interfaces/session-token-expiry.interface.mjs +2 -0
  75. package/esm2022/lib/services/session-service/interfaces/session-user-state.interface.mjs +2 -0
  76. package/esm2022/lib/services/session-service/mocks/index.mjs +3 -0
  77. package/esm2022/lib/services/session-service/mocks/session-token-expiry.mock.mjs +5 -0
  78. package/esm2022/lib/services/session-service/mocks/session-user-state.mock.mjs +386 -0
  79. package/esm2022/lib/services/session-service/session.service.mjs +64 -0
  80. package/esm2022/lib/services/sort-service/index.mjs +6 -0
  81. package/esm2022/lib/services/sort-service/interfaces/index.mjs +3 -0
  82. package/esm2022/lib/services/sort-service/interfaces/sort-service-values.interface.mjs +2 -0
  83. package/esm2022/lib/services/sort-service/interfaces/sort-service.interface.mjs +2 -0
  84. package/esm2022/lib/services/sort-service/sort-service.mjs +90 -0
  85. package/esm2022/lib/services/sort-service/types/index.mjs +2 -0
  86. package/esm2022/lib/services/sort-service/types/sort-service.type.mjs +2 -0
  87. package/esm2022/lib/services/transfer-state-service/index.mjs +6 -0
  88. package/esm2022/lib/services/transfer-state-service/interfaces/index.mjs +4 -0
  89. package/esm2022/lib/services/transfer-state-service/interfaces/transfer-state-app-insights-config.interface.mjs +2 -0
  90. package/esm2022/lib/services/transfer-state-service/interfaces/transfer-state-launch-darkly-config.interface.mjs +2 -0
  91. package/esm2022/lib/services/transfer-state-service/interfaces/transfer-state-server-state.interface.mjs +2 -0
  92. package/esm2022/lib/services/transfer-state-service/mocks/index.mjs +4 -0
  93. package/esm2022/lib/services/transfer-state-service/mocks/transfer-state-app-insights-config.mock.mjs +6 -0
  94. package/esm2022/lib/services/transfer-state-service/mocks/transfer-state-launch-darkly-config.mock.mjs +6 -0
  95. package/esm2022/lib/services/transfer-state-service/mocks/transfer-state.mock.mjs +8 -0
  96. package/esm2022/lib/services/transfer-state-service/transfer-state.service.mjs +59 -0
  97. package/esm2022/lib/services/transformation-service/index.mjs +5 -0
  98. package/esm2022/lib/services/transformation-service/interfaces/index.mjs +2 -0
  99. package/esm2022/lib/services/transformation-service/interfaces/transform-item.interface.mjs +2 -0
  100. package/esm2022/lib/services/transformation-service/transformation.service.mjs +69 -0
  101. package/esm2022/lib/services/utils/index.mjs +4 -0
  102. package/esm2022/lib/services/utils/utils.service.mjs +86 -0
  103. package/esm2022/lib/stores/global/global.store.mjs +33 -0
  104. package/esm2022/lib/stores/global/index.mjs +6 -0
  105. package/esm2022/lib/stores/global/interfaces/error-state.interface.mjs +2 -0
  106. package/esm2022/lib/stores/global/interfaces/index.mjs +2 -0
  107. package/esm2022/lib/stores/global/types/global-store.type.mjs +2 -0
  108. package/esm2022/lib/stores/global/types/index.mjs +2 -0
  109. package/esm2022/lib/stores/index.mjs +2 -0
  110. package/esm2022/lib/validators/alphabetical-text/alphabetical-text.validator.mjs +10 -0
  111. package/esm2022/lib/validators/amount/amount.validator.mjs +15 -0
  112. package/esm2022/lib/validators/date-after-year/date-after-year.validator.mjs +12 -0
  113. package/esm2022/lib/validators/date-before/date-before.validator.mjs +15 -0
  114. package/esm2022/lib/validators/date-of-birth/date-of-birth.validator.mjs +18 -0
  115. package/esm2022/lib/validators/future-date/future-date.validator.mjs +15 -0
  116. package/esm2022/lib/validators/index.mjs +20 -0
  117. package/esm2022/lib/validators/invalid-value/invalid-value.validator.mjs +9 -0
  118. package/esm2022/lib/validators/national-insurance-number/national-insurance-number.validator.mjs +16 -0
  119. package/esm2022/lib/validators/numerical-only/numerical-only.validator.mjs +10 -0
  120. package/esm2022/lib/validators/optional-max-length/optional-max-length.validator.mjs +10 -0
  121. package/esm2022/lib/validators/optional-valid-date/optional-valid-date.validator.mjs +23 -0
  122. package/esm2022/lib/validators/optional-valid-email-address/optional-valid-email-address.validator.mjs +11 -0
  123. package/esm2022/lib/validators/optional-valid-telephone/optional-valid-telephone.validator.mjs +14 -0
  124. package/esm2022/lib/validators/over-eighteen/over-eighteen.validator.mjs +45 -0
  125. package/esm2022/lib/validators/past-date/past-date.validator.mjs +16 -0
  126. package/esm2022/lib/validators/special-characters/special-characters.validator.mjs +11 -0
  127. package/esm2022/lib/validators/two-decimal-places/two-decimal-places.validator.mjs +12 -0
  128. package/esm2022/lib/validators/valid-value/valid-value.validator.mjs +9 -0
  129. package/esm2022/public-api.mjs +11 -0
  130. package/fesm2022/hmcts-opal-frontend-common-sign-in-stub.component-CysPzJGJ.mjs +41 -0
  131. package/fesm2022/hmcts-opal-frontend-common-sign-in-stub.component-CysPzJGJ.mjs.map +1 -0
  132. package/fesm2022/hmcts-opal-frontend-common.mjs +1947 -0
  133. package/fesm2022/hmcts-opal-frontend-common.mjs.map +1 -0
  134. package/index.d.ts +5 -0
  135. package/lib/components/govuk/govuk-button/govuk-button.component.d.ts +14 -0
  136. package/lib/components/govuk/govuk-text-input/govuk-text-input.component.d.ts +17 -0
  137. package/lib/components/govuk/index.d.ts +2 -0
  138. package/lib/guards/auth/auth.guard.d.ts +6 -0
  139. package/lib/guards/auth/index.d.ts +1 -0
  140. package/lib/guards/can-deactivate/can-deactivate.guard.d.ts +3 -0
  141. package/lib/guards/can-deactivate/index.d.ts +2 -0
  142. package/lib/guards/can-deactivate/interfaces/can-deactivate-can-component-deactivate.interface.d.ts +4 -0
  143. package/lib/guards/can-deactivate/interfaces/index.d.ts +2 -0
  144. package/lib/guards/has-flow-state/has-flow-state.guard.d.ts +2 -0
  145. package/lib/guards/has-flow-state/index.d.ts +1 -0
  146. package/lib/guards/helpers/get-guard-with-dummy-url.d.ts +12 -0
  147. package/lib/guards/helpers/handle-observable-result.d.ts +8 -0
  148. package/lib/guards/helpers/index.d.ts +4 -0
  149. package/lib/guards/helpers/run-auth-guard-with-context.d.ts +9 -0
  150. package/lib/guards/helpers/run-has-flow-state-guard-with-context.d.ts +3 -0
  151. package/lib/guards/index.d.ts +7 -0
  152. package/lib/guards/route-permissions/index.d.ts +1 -0
  153. package/lib/guards/route-permissions/route-permissions.guard.d.ts +2 -0
  154. package/lib/guards/signed-in/index.d.ts +1 -0
  155. package/lib/guards/signed-in/signed-in.guard.d.ts +8 -0
  156. package/lib/guards/types/can-deactivate.type.d.ts +3 -0
  157. package/lib/guards/types/guard-return.type.d.ts +2 -0
  158. package/lib/guards/types/index.d.ts +2 -0
  159. package/lib/interceptors/http-error/http-error.interceptor.d.ts +2 -0
  160. package/lib/interceptors/index.d.ts +2 -0
  161. package/lib/opal-frontend-common.module.d.ts +14 -0
  162. package/lib/pages/access-denied/access-denied.component.d.ts +7 -0
  163. package/lib/pages/index.d.ts +3 -0
  164. package/lib/pages/routing/constants/routing-paths.constant.d.ts +2 -0
  165. package/lib/pages/routing/constants/routing-titles.constant.d.ts +2 -0
  166. package/lib/pages/routing/interfaces/routing-paths.interface.d.ts +8 -0
  167. package/lib/pages/routing/pages.routes.d.ts +2 -0
  168. package/lib/pages/sign-in/interfaces/index.d.ts +2 -0
  169. package/lib/pages/sign-in/interfaces/sign-in-stub-form.interface.d.ts +3 -0
  170. package/lib/pages/sign-in/sign-in-sso/sign-in-sso.component.d.ts +11 -0
  171. package/lib/pages/sign-in/sign-in-stub/sign-in-stub.component.d.ts +19 -0
  172. package/lib/pages/sign-in/sign-in.component.d.ts +51 -0
  173. package/lib/resolvers/index.d.ts +2 -0
  174. package/lib/resolvers/title/index.d.ts +1 -0
  175. package/lib/resolvers/title/title.resolver.d.ts +10 -0
  176. package/lib/resolvers/user-state/index.d.ts +1 -0
  177. package/lib/resolvers/user-state/user-state.resolver.d.ts +7 -0
  178. package/lib/routing/constants/index.d.ts +1 -0
  179. package/lib/routing/constants/sso-endpoints.constant.d.ts +2 -0
  180. package/lib/routing/index.d.ts +2 -0
  181. package/lib/routing/interfaces/child-routing-paths.interface.d.ts +6 -0
  182. package/lib/routing/interfaces/index.d.ts +3 -0
  183. package/lib/routing/interfaces/nested-routes.interface.d.ts +4 -0
  184. package/lib/routing/interfaces/sso-endpoints.interface.d.ts +6 -0
  185. package/lib/services/app-initializer-service/app-initializer.service.d.ts +20 -0
  186. package/lib/services/app-initializer-service/index.d.ts +1 -0
  187. package/lib/services/app-insights/app-insights.service.d.ts +33 -0
  188. package/lib/services/app-insights/index.d.ts +1 -0
  189. package/lib/services/auth-service/auth.service.d.ts +8 -0
  190. package/lib/services/auth-service/index.d.ts +1 -0
  191. package/lib/services/date-service/date.service.d.ts +123 -0
  192. package/lib/services/date-service/index.d.ts +1 -0
  193. package/lib/services/index.d.ts +11 -0
  194. package/lib/services/launch-darkly/index.d.ts +2 -0
  195. package/lib/services/launch-darkly/launch-darkly.service.d.ts +41 -0
  196. package/lib/services/launch-darkly/mocks/index.d.ts +2 -0
  197. package/lib/services/launch-darkly/mocks/launch-darkly-change-flags.mock.d.ts +10 -0
  198. package/lib/services/launch-darkly/mocks/launch-darkly-flags.mock.d.ts +4 -0
  199. package/lib/services/permissions-service/index.d.ts +1 -0
  200. package/lib/services/permissions-service/permissions.service.d.ts +14 -0
  201. package/lib/services/session-service/constants/index.d.ts +1 -0
  202. package/lib/services/session-service/constants/session-endpoints.constant.d.ts +2 -0
  203. package/lib/services/session-service/index.d.ts +4 -0
  204. package/lib/services/session-service/interfaces/index.d.ts +3 -0
  205. package/lib/services/session-service/interfaces/session-endpoints.interface.d.ts +4 -0
  206. package/lib/services/session-service/interfaces/session-token-expiry.interface.d.ts +4 -0
  207. package/lib/services/session-service/interfaces/session-user-state.interface.d.ts +15 -0
  208. package/lib/services/session-service/mocks/index.d.ts +2 -0
  209. package/lib/services/session-service/mocks/session-token-expiry.mock.d.ts +2 -0
  210. package/lib/services/session-service/mocks/session-user-state.mock.d.ts +2 -0
  211. package/lib/services/session-service/session.service.d.ts +30 -0
  212. package/lib/services/sort-service/index.d.ts +3 -0
  213. package/lib/services/sort-service/interfaces/index.d.ts +2 -0
  214. package/lib/services/sort-service/interfaces/sort-service-values.interface.d.ts +6 -0
  215. package/lib/services/sort-service/interfaces/sort-service.interface.d.ts +4 -0
  216. package/lib/services/sort-service/sort-service.d.ts +64 -0
  217. package/lib/services/sort-service/types/index.d.ts +1 -0
  218. package/lib/services/sort-service/types/sort-service.type.d.ts +1 -0
  219. package/lib/services/transfer-state-service/index.d.ts +3 -0
  220. package/lib/services/transfer-state-service/interfaces/index.d.ts +3 -0
  221. package/lib/services/transfer-state-service/interfaces/transfer-state-app-insights-config.interface.d.ts +5 -0
  222. package/lib/services/transfer-state-service/interfaces/transfer-state-launch-darkly-config.interface.d.ts +5 -0
  223. package/lib/services/transfer-state-service/interfaces/transfer-state-server-state.interface.d.ts +7 -0
  224. package/lib/services/transfer-state-service/mocks/index.d.ts +3 -0
  225. package/lib/services/transfer-state-service/mocks/transfer-state-app-insights-config.mock.d.ts +5 -0
  226. package/lib/services/transfer-state-service/mocks/transfer-state-launch-darkly-config.mock.d.ts +5 -0
  227. package/lib/services/transfer-state-service/mocks/transfer-state.mock.d.ts +2 -0
  228. package/lib/services/transfer-state-service/transfer-state.service.d.ts +23 -0
  229. package/lib/services/transformation-service/index.d.ts +2 -0
  230. package/lib/services/transformation-service/interfaces/index.d.ts +1 -0
  231. package/lib/services/transformation-service/interfaces/transform-item.interface.d.ts +6 -0
  232. package/lib/services/transformation-service/transformation.service.d.ts +30 -0
  233. package/lib/services/utils/index.d.ts +1 -0
  234. package/lib/services/utils/utils.service.d.ts +54 -0
  235. package/lib/stores/global/global.store.d.ts +35 -0
  236. package/lib/stores/global/index.d.ts +3 -0
  237. package/lib/stores/global/interfaces/error-state.interface.d.ts +4 -0
  238. package/lib/stores/global/interfaces/index.d.ts +1 -0
  239. package/lib/stores/global/types/global-store.type.d.ts +2 -0
  240. package/lib/stores/global/types/index.d.ts +1 -0
  241. package/lib/stores/index.d.ts +1 -0
  242. package/lib/validators/alphabetical-text/alphabetical-text.validator.d.ts +2 -0
  243. package/lib/validators/amount/amount.validator.d.ts +2 -0
  244. package/lib/validators/date-after-year/date-after-year.validator.d.ts +2 -0
  245. package/lib/validators/date-before/date-before.validator.d.ts +2 -0
  246. package/lib/validators/date-of-birth/date-of-birth.validator.d.ts +2 -0
  247. package/lib/validators/future-date/future-date.validator.d.ts +2 -0
  248. package/lib/validators/index.d.ts +19 -0
  249. package/lib/validators/invalid-value/invalid-value.validator.d.ts +2 -0
  250. package/lib/validators/national-insurance-number/national-insurance-number.validator.d.ts +2 -0
  251. package/lib/validators/numerical-only/numerical-only.validator.d.ts +2 -0
  252. package/lib/validators/optional-max-length/optional-max-length.validator.d.ts +2 -0
  253. package/lib/validators/optional-valid-date/optional-valid-date.validator.d.ts +2 -0
  254. package/lib/validators/optional-valid-email-address/optional-valid-email-address.validator.d.ts +2 -0
  255. package/lib/validators/optional-valid-telephone/optional-valid-telephone.validator.d.ts +2 -0
  256. package/lib/validators/over-eighteen/over-eighteen.validator.d.ts +14 -0
  257. package/lib/validators/past-date/past-date.validator.d.ts +2 -0
  258. package/lib/validators/special-characters/special-characters.validator.d.ts +2 -0
  259. package/lib/validators/two-decimal-places/two-decimal-places.validator.d.ts +2 -0
  260. package/lib/validators/valid-value/valid-value.validator.d.ts +2 -0
  261. package/package.json +28 -0
  262. package/public-api.d.ts +10 -0
@@ -0,0 +1,1947 @@
1
+ import * as i0 from '@angular/core';
2
+ import { EventEmitter, Output, Input, ChangeDetectionStrategy, Component, NgModule, inject, Injectable, makeStateKey, PLATFORM_ID, Inject, Optional, ChangeDetectorRef } from '@angular/core';
3
+ import { CommonModule, isPlatformBrowser, ViewportScroller, DOCUMENT } from '@angular/common';
4
+ import * as i1 from '@angular/forms';
5
+ import { ReactiveFormsModule, FormsModule, Validators } from '@angular/forms';
6
+ import * as i1$1 from '@angular/router';
7
+ import { RouterModule, Router, ActivatedRouteSnapshot, UrlSegment } from '@angular/router';
8
+ import { tap, catchError, throwError, map, of, shareReplay, retry, timer, Observable, firstValueFrom } from 'rxjs';
9
+ import { HttpClient, HttpHeaders } from '@angular/common/http';
10
+ import { signalStore, withState, withMethods, patchState } from '@ngrx/signals';
11
+ import { ApplicationInsights } from '@microsoft/applicationinsights-web';
12
+ import { Duration, DateTime } from 'luxon';
13
+ import { initialize } from 'launchdarkly-js-client-sdk';
14
+ import { sort } from 'fast-sort';
15
+ import { TestBed } from '@angular/core/testing';
16
+ import * as i1$2 from '@angular/platform-browser';
17
+
18
+ class GovukButtonComponent {
19
+ buttonId;
20
+ type = 'button';
21
+ buttonClasses;
22
+ buttonClickEvent = new EventEmitter();
23
+ /**
24
+ * Handles the button click event.
25
+ */
26
+ handleButtonClick() {
27
+ this.buttonClickEvent.emit(true);
28
+ }
29
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: GovukButtonComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
30
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: GovukButtonComponent, isStandalone: true, selector: "opal-lib-govuk-button", inputs: { buttonId: "buttonId", type: "type", buttonClasses: "buttonClasses" }, outputs: { buttonClickEvent: "buttonClickEvent" }, ngImport: i0, template: "<button\n [id]=\"buttonId\"\n [type]=\"type\"\n class=\"govuk-button {{ buttonClasses }}\"\n data-module=\"govuk-button\"\n (click)=\"handleButtonClick()\"\n>\n <ng-content></ng-content>\n</button>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: ReactiveFormsModule }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
31
+ }
32
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: GovukButtonComponent, decorators: [{
33
+ type: Component,
34
+ args: [{ standalone: true, selector: 'opal-lib-govuk-button', imports: [CommonModule, ReactiveFormsModule], changeDetection: ChangeDetectionStrategy.OnPush, template: "<button\n [id]=\"buttonId\"\n [type]=\"type\"\n class=\"govuk-button {{ buttonClasses }}\"\n data-module=\"govuk-button\"\n (click)=\"handleButtonClick()\"\n>\n <ng-content></ng-content>\n</button>\n" }]
35
+ }], propDecorators: { buttonId: [{
36
+ type: Input,
37
+ args: [{ required: true }]
38
+ }], type: [{
39
+ type: Input,
40
+ args: [{ required: false }]
41
+ }], buttonClasses: [{
42
+ type: Input,
43
+ args: [{ required: false }]
44
+ }], buttonClickEvent: [{
45
+ type: Output
46
+ }] } });
47
+
48
+ class GovukTextInputComponent {
49
+ _control;
50
+ labelText;
51
+ labelClasses;
52
+ inputId;
53
+ inputName;
54
+ inputClasses;
55
+ hintText;
56
+ hintHtml;
57
+ errors = null;
58
+ set control(abstractControl) {
59
+ // Form controls are passed in as abstract controls, we need to re-cast it.
60
+ this._control = abstractControl;
61
+ }
62
+ get getControl() {
63
+ return this._control;
64
+ }
65
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: GovukTextInputComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
66
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.13", type: GovukTextInputComponent, isStandalone: true, selector: "opal-lib-govuk-text-input", inputs: { labelText: "labelText", labelClasses: "labelClasses", inputId: "inputId", inputName: "inputName", inputClasses: "inputClasses", hintText: "hintText", hintHtml: "hintHtml", errors: "errors", control: "control" }, ngImport: i0, template: "<div class=\"govuk-form-group\" [class.govuk-form-group--error]=\"!!errors\">\n <h1 class=\"govuk-label-wrapper\">\n <label class=\"govuk-label {{ labelClasses }}\" [for]=\"inputId\">\n {{ labelText }}\n </label>\n </h1>\n @if (hintText) {\n <div id=\"{{ inputId }}-hint\" class=\"govuk-hint\">\n {{ hintText }}\n </div>\n }\n\n @if (hintHtml) {\n <div id=\"{{ inputId }}-hint\" class=\"govuk-hint\"><ng-content></ng-content></div>\n }\n\n @if (errors) {\n <p id=\"{{ this.inputId }}-error-message\" class=\"govuk-error-message\">\n <span class=\"govuk-visually-hidden\">Error: </span> {{ errors }}\n </p>\n }\n\n <input\n class=\"govuk-input {{ inputClasses }}\"\n [id]=\"inputId\"\n [name]=\"inputName\"\n type=\"text\"\n [formControl]=\"getControl\"\n />\n</div>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
67
+ }
68
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: GovukTextInputComponent, decorators: [{
69
+ type: Component,
70
+ args: [{ standalone: true, selector: 'opal-lib-govuk-text-input', imports: [CommonModule, ReactiveFormsModule], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"govuk-form-group\" [class.govuk-form-group--error]=\"!!errors\">\n <h1 class=\"govuk-label-wrapper\">\n <label class=\"govuk-label {{ labelClasses }}\" [for]=\"inputId\">\n {{ labelText }}\n </label>\n </h1>\n @if (hintText) {\n <div id=\"{{ inputId }}-hint\" class=\"govuk-hint\">\n {{ hintText }}\n </div>\n }\n\n @if (hintHtml) {\n <div id=\"{{ inputId }}-hint\" class=\"govuk-hint\"><ng-content></ng-content></div>\n }\n\n @if (errors) {\n <p id=\"{{ this.inputId }}-error-message\" class=\"govuk-error-message\">\n <span class=\"govuk-visually-hidden\">Error: </span> {{ errors }}\n </p>\n }\n\n <input\n class=\"govuk-input {{ inputClasses }}\"\n [id]=\"inputId\"\n [name]=\"inputName\"\n type=\"text\"\n [formControl]=\"getControl\"\n />\n</div>\n" }]
71
+ }], propDecorators: { labelText: [{
72
+ type: Input,
73
+ args: [{ required: true }]
74
+ }], labelClasses: [{
75
+ type: Input,
76
+ args: [{ required: false }]
77
+ }], inputId: [{
78
+ type: Input,
79
+ args: [{ required: true }]
80
+ }], inputName: [{
81
+ type: Input,
82
+ args: [{ required: true }]
83
+ }], inputClasses: [{
84
+ type: Input,
85
+ args: [{ required: false }]
86
+ }], hintText: [{
87
+ type: Input,
88
+ args: [{ required: false }]
89
+ }], hintHtml: [{
90
+ type: Input,
91
+ args: [{ required: false }]
92
+ }], errors: [{
93
+ type: Input,
94
+ args: [{ required: false }]
95
+ }], control: [{
96
+ type: Input,
97
+ args: [{ required: true }]
98
+ }] } });
99
+
100
+ const GOV_UI_COMPONENTS = [GovukButtonComponent, GovukTextInputComponent];
101
+ class OpalFrontendCommonModule {
102
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: OpalFrontendCommonModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
103
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: OpalFrontendCommonModule, imports: [GovukButtonComponent, GovukTextInputComponent, CommonModule, FormsModule, ReactiveFormsModule, i1$1.RouterModule], exports: [GovukButtonComponent, GovukTextInputComponent] });
104
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: OpalFrontendCommonModule, imports: [GOV_UI_COMPONENTS, CommonModule, FormsModule, ReactiveFormsModule, RouterModule.forChild([])] });
105
+ }
106
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: OpalFrontendCommonModule, decorators: [{
107
+ type: NgModule,
108
+ args: [{
109
+ imports: [...GOV_UI_COMPONENTS, CommonModule, FormsModule, ReactiveFormsModule, RouterModule.forChild([])],
110
+ exports: [...GOV_UI_COMPONENTS],
111
+ }]
112
+ }] });
113
+
114
+ const PAGES_ROUTING_PATHS = {
115
+ root: '',
116
+ children: {
117
+ accessDenied: 'access-denied',
118
+ signIn: 'sign-in',
119
+ signInStub: 'sign-in-stub',
120
+ },
121
+ };
122
+
123
+ const SSO_ENDPOINTS = {
124
+ login: '/sso/login',
125
+ logout: '/sso/logout',
126
+ callback: '/sso/callback',
127
+ authenticated: '/sso/authenticated',
128
+ };
129
+
130
+ const GlobalStore = signalStore({ providedIn: 'root' }, withState(() => ({
131
+ authenticated: false,
132
+ error: { error: false, message: '' },
133
+ featureFlags: {},
134
+ userState: {},
135
+ ssoEnabled: false,
136
+ launchDarklyConfig: {},
137
+ tokenExpiry: {},
138
+ })), withMethods((store) => ({
139
+ setAuthenticated: (authenticated) => {
140
+ patchState(store, { authenticated });
141
+ },
142
+ setError: (error) => {
143
+ patchState(store, { error });
144
+ },
145
+ setFeatureFlags: (featureFlags) => {
146
+ patchState(store, { featureFlags });
147
+ },
148
+ setUserState: (userState) => {
149
+ patchState(store, { userState });
150
+ },
151
+ setSsoEnabled: (ssoEnabled) => {
152
+ patchState(store, { ssoEnabled });
153
+ },
154
+ setLaunchDarklyConfig: (config) => {
155
+ patchState(store, { launchDarklyConfig: config });
156
+ },
157
+ setTokenExpiry: (tokenExpiry) => {
158
+ patchState(store, { tokenExpiry });
159
+ },
160
+ })));
161
+
162
+ // STORE
163
+
164
+ class AuthService {
165
+ http = inject(HttpClient);
166
+ globalStore = inject(GlobalStore);
167
+ checkAuthenticated() {
168
+ return this.http
169
+ .get(SSO_ENDPOINTS.authenticated, {
170
+ headers: new HttpHeaders({
171
+ 'Cache-Control': 'no-cache',
172
+ Pragma: 'no-cache',
173
+ Expires: '0',
174
+ }),
175
+ })
176
+ .pipe(tap((resp) => {
177
+ this.globalStore.setAuthenticated(resp);
178
+ }))
179
+ .pipe(catchError((error) => {
180
+ this.globalStore.setAuthenticated(false);
181
+ return throwError(() => error);
182
+ }));
183
+ }
184
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AuthService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
185
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AuthService, providedIn: 'root' });
186
+ }
187
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AuthService, decorators: [{
188
+ type: Injectable,
189
+ args: [{
190
+ providedIn: 'root',
191
+ }]
192
+ }] });
193
+
194
+ /**
195
+ * A guard that checks if the user is authenticated before allowing access to a route.
196
+ * @returns An Observable that emits a boolean value indicating whether the user is authenticated.
197
+ */
198
+ const authGuard = () => {
199
+ const authService = inject(AuthService);
200
+ const router = inject(Router);
201
+ return authService.checkAuthenticated().pipe(map((resp) => {
202
+ return resp;
203
+ }), catchError(() => {
204
+ router.navigate([PAGES_ROUTING_PATHS.children.signIn]);
205
+ return of(false);
206
+ }));
207
+ };
208
+
209
+ const canDeactivateGuard = (component) => {
210
+ return component.canDeactivate()
211
+ ? true
212
+ : confirm('WARNING: You have unsaved changes. Press Cancel to go back and save these changes, or OK to lose these changes.');
213
+ };
214
+
215
+ // GUARD
216
+
217
+ function hasFlowStateGuard(getState, checkCondition, getNavigationPath) {
218
+ return (route) => {
219
+ const router = inject(Router);
220
+ const state = getState();
221
+ const { queryParams, fragment } = route;
222
+ return checkCondition(state)
223
+ ? true
224
+ : router.createUrlTree([getNavigationPath()], {
225
+ queryParams: queryParams ?? undefined,
226
+ fragment: fragment ?? undefined,
227
+ });
228
+ };
229
+ }
230
+
231
+ class PermissionsService {
232
+ storedUniquePermissionIds = [];
233
+ /**
234
+ * Retrieves the unique permission IDs associated with the user.
235
+ * If the unique permission IDs have not been stored yet, it calculates them based on the user's roles and permissions.
236
+ * @returns An array of unique permission IDs.
237
+ */
238
+ getUniquePermissions(userState) {
239
+ const roles = userState ? userState['business_unit_user'] : null;
240
+ if (!this.storedUniquePermissionIds.length && roles) {
241
+ const permissionIds = roles.flatMap((role) => {
242
+ return role.permissions.map(({ permission_id: permissionId }) => permissionId);
243
+ });
244
+ this.storedUniquePermissionIds = [...new Set(permissionIds)];
245
+ }
246
+ return this.storedUniquePermissionIds;
247
+ }
248
+ hasPermissionAccess(permissionId, businessUnitId, roles) {
249
+ if (roles?.length) {
250
+ // First we need to find the matching role
251
+ const role = roles?.find((role) => role.business_unit_id === businessUnitId);
252
+ // Then we need to find the matching permission
253
+ const hasPermission = !!role?.permissions.find((permission) => permission.permission_id === permissionId);
254
+ return hasPermission;
255
+ }
256
+ // if we don't have any roles, we can't have any permissions
257
+ return true;
258
+ }
259
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: PermissionsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
260
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: PermissionsService, providedIn: 'root' });
261
+ }
262
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: PermissionsService, decorators: [{
263
+ type: Injectable,
264
+ args: [{
265
+ providedIn: 'root',
266
+ }]
267
+ }] });
268
+
269
+ // SERVICE
270
+ // CONSTANTS, INTERFACES, AND MOCKS
271
+
272
+ const SESSION_ENDPOINTS = {
273
+ userState: '/session/user-state',
274
+ expiry: '/session/expiry',
275
+ };
276
+
277
+ class SessionService {
278
+ http = inject(HttpClient);
279
+ globalStore = inject(GlobalStore);
280
+ userStateCache$;
281
+ tokenExpiryCache$;
282
+ MAX_RETRIES = 5;
283
+ RETRY_DELAY_MS = 1000;
284
+ /**
285
+ * Retrieves the user state from the backend.
286
+ * If the user state is not available or needs to be refreshed, it makes an HTTP request to fetch the user state.
287
+ * The user state is then stored in the state service for future use.
288
+ * The user state is cached using the `shareReplay` operator to avoid unnecessary HTTP requests.
289
+ * @returns An observable that emits the user state.
290
+ */
291
+ getUserState() {
292
+ // The backend can return an empty object so...
293
+ // If we don't have a user state, then we need to refresh it...
294
+ // And override the shareReplay cache...
295
+ const refresh = !this.globalStore.userState()?.user_id;
296
+ if (!this.userStateCache$ || refresh) {
297
+ this.userStateCache$ = this.http
298
+ .get(SESSION_ENDPOINTS.userState)
299
+ .pipe(shareReplay(1))
300
+ .pipe(tap((userState) => {
301
+ this.globalStore.setUserState(userState);
302
+ }));
303
+ }
304
+ return this.userStateCache$;
305
+ }
306
+ /**
307
+ * Retrieves the token expiry information from the server.
308
+ * If the token expiry information is already cached, it returns the cached value.
309
+ * Otherwise, it makes an HTTP GET request to fetch the token expiry information,
310
+ * retries the request up to a maximum number of times if it fails, and caches the result.
311
+ *
312
+ * @returns {Observable<ISessionTokenExpiry>} An observable that emits the token expiry information.
313
+ */
314
+ getTokenExpiry() {
315
+ if (!this.tokenExpiryCache$) {
316
+ this.tokenExpiryCache$ = this.http.get(SESSION_ENDPOINTS.expiry).pipe(retry({
317
+ count: this.MAX_RETRIES,
318
+ delay: () => timer(this.RETRY_DELAY_MS),
319
+ }), tap((expiry) => {
320
+ this.globalStore.setTokenExpiry(expiry);
321
+ }), shareReplay(1));
322
+ }
323
+ return this.tokenExpiryCache$;
324
+ }
325
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SessionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
326
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SessionService, providedIn: 'root' });
327
+ }
328
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SessionService, decorators: [{
329
+ type: Injectable,
330
+ args: [{
331
+ providedIn: 'root',
332
+ }]
333
+ }] });
334
+
335
+ const SESSION_TOKEN_EXPIRY_MOCK = {
336
+ expiry: 'test',
337
+ warningThresholdInMilliseconds: 5,
338
+ };
339
+
340
+ const SESSION_USER_STATE_MOCK = {
341
+ user_id: 'gl.timTest',
342
+ user_name: 'timmyTest@HMCTS.NET',
343
+ name: 'Timmy Test',
344
+ business_unit_user: [
345
+ {
346
+ business_unit_user_id: 'L017KG',
347
+ business_unit_id: 17,
348
+ permissions: [
349
+ {
350
+ permission_id: 54,
351
+ permission_name: 'Account Enquiry',
352
+ },
353
+ {
354
+ permission_id: 41,
355
+ permission_name: 'Account Enquiry - Account Notes',
356
+ },
357
+ ],
358
+ },
359
+ {
360
+ business_unit_user_id: 'L016KG',
361
+ business_unit_id: 16,
362
+ permissions: [
363
+ {
364
+ permission_id: 54,
365
+ permission_name: 'Account Enquiry',
366
+ },
367
+ {
368
+ permission_id: 41,
369
+ permission_name: 'Account Enquiry - Account Notes',
370
+ },
371
+ ],
372
+ },
373
+ {
374
+ business_unit_user_id: 'L019KG',
375
+ business_unit_id: 19,
376
+ permissions: [
377
+ {
378
+ permission_id: 54,
379
+ permission_name: 'Account Enquiry',
380
+ },
381
+ {
382
+ permission_id: 41,
383
+ permission_name: 'Account Enquiry - Account Notes',
384
+ },
385
+ ],
386
+ },
387
+ {
388
+ business_unit_user_id: 'L013KG',
389
+ business_unit_id: 13,
390
+ permissions: [
391
+ {
392
+ permission_id: 54,
393
+ permission_name: 'Account Enquiry',
394
+ },
395
+ {
396
+ permission_id: 41,
397
+ permission_name: 'Account Enquiry - Account Notes',
398
+ },
399
+ ],
400
+ },
401
+ {
402
+ business_unit_user_id: 'L076KG',
403
+ business_unit_id: 76,
404
+ permissions: [
405
+ {
406
+ permission_id: 54,
407
+ permission_name: 'Account Enquiry',
408
+ },
409
+ {
410
+ permission_id: 41,
411
+ permission_name: 'Account Enquiry - Account Notes',
412
+ },
413
+ ],
414
+ },
415
+ {
416
+ business_unit_user_id: 'L081KG',
417
+ business_unit_id: 81,
418
+ permissions: [
419
+ {
420
+ permission_id: 54,
421
+ permission_name: 'Account Enquiry',
422
+ },
423
+ {
424
+ permission_id: 41,
425
+ permission_name: 'Account Enquiry - Account Notes',
426
+ },
427
+ ],
428
+ },
429
+ {
430
+ business_unit_user_id: 'L077KG',
431
+ business_unit_id: 77,
432
+ permissions: [
433
+ {
434
+ permission_id: 54,
435
+ permission_name: 'Account Enquiry',
436
+ },
437
+ {
438
+ permission_id: 41,
439
+ permission_name: 'Account Enquiry - Account Notes',
440
+ },
441
+ ],
442
+ },
443
+ {
444
+ business_unit_user_id: 'L078KG',
445
+ business_unit_id: 78,
446
+ permissions: [
447
+ {
448
+ permission_id: 54,
449
+ permission_name: 'Account Enquiry',
450
+ },
451
+ {
452
+ permission_id: 41,
453
+ permission_name: 'Account Enquiry - Account Notes',
454
+ },
455
+ ],
456
+ },
457
+ {
458
+ business_unit_user_id: 'L079KG',
459
+ business_unit_id: 79,
460
+ permissions: [
461
+ {
462
+ permission_id: 54,
463
+ permission_name: 'Account Enquiry',
464
+ },
465
+ {
466
+ permission_id: 41,
467
+ permission_name: 'Account Enquiry - Account Notes',
468
+ },
469
+ ],
470
+ },
471
+ {
472
+ business_unit_user_id: 'L040KG',
473
+ business_unit_id: 40,
474
+ permissions: [
475
+ {
476
+ permission_id: 54,
477
+ permission_name: 'Account Enquiry',
478
+ },
479
+ {
480
+ permission_id: 41,
481
+ permission_name: 'Account Enquiry - Account Notes',
482
+ },
483
+ ],
484
+ },
485
+ {
486
+ business_unit_user_id: 'L066KG',
487
+ business_unit_id: 66,
488
+ permissions: [
489
+ {
490
+ permission_id: 54,
491
+ permission_name: 'Account Enquiry',
492
+ },
493
+ {
494
+ permission_id: 41,
495
+ permission_name: 'Account Enquiry - Account Notes',
496
+ },
497
+ ],
498
+ },
499
+ {
500
+ business_unit_user_id: 'L072KG',
501
+ business_unit_id: 72,
502
+ permissions: [
503
+ {
504
+ permission_id: 54,
505
+ permission_name: 'Account Enquiry',
506
+ },
507
+ {
508
+ permission_id: 41,
509
+ permission_name: 'Account Enquiry - Account Notes',
510
+ },
511
+ ],
512
+ },
513
+ {
514
+ business_unit_user_id: 'L067KG',
515
+ business_unit_id: 67,
516
+ permissions: [
517
+ {
518
+ permission_id: 54,
519
+ permission_name: 'Account Enquiry',
520
+ },
521
+ {
522
+ permission_id: 41,
523
+ permission_name: 'Account Enquiry - Account Notes',
524
+ },
525
+ ],
526
+ },
527
+ {
528
+ business_unit_user_id: 'L073KG',
529
+ business_unit_id: 73,
530
+ permissions: [
531
+ {
532
+ permission_id: 54,
533
+ permission_name: 'Account Enquiry',
534
+ },
535
+ {
536
+ permission_id: 41,
537
+ permission_name: 'Account Enquiry - Account Notes',
538
+ },
539
+ ],
540
+ },
541
+ {
542
+ business_unit_user_id: 'L068KG',
543
+ business_unit_id: 68,
544
+ permissions: [
545
+ {
546
+ permission_id: 54,
547
+ permission_name: 'Account Enquiry',
548
+ },
549
+ {
550
+ permission_id: 41,
551
+ permission_name: 'Account Enquiry - Account Notes',
552
+ },
553
+ ],
554
+ },
555
+ {
556
+ business_unit_user_id: 'L074KG',
557
+ business_unit_id: 74,
558
+ permissions: [
559
+ {
560
+ permission_id: 54,
561
+ permission_name: 'Account Enquiry',
562
+ },
563
+ {
564
+ permission_id: 41,
565
+ permission_name: 'Account Enquiry - Account Notes',
566
+ },
567
+ ],
568
+ },
569
+ {
570
+ business_unit_user_id: 'L069KG',
571
+ business_unit_id: 69,
572
+ permissions: [
573
+ {
574
+ permission_id: 54,
575
+ permission_name: 'Account Enquiry',
576
+ },
577
+ {
578
+ permission_id: 41,
579
+ permission_name: 'Account Enquiry - Account Notes',
580
+ },
581
+ ],
582
+ },
583
+ {
584
+ business_unit_user_id: 'L075KG',
585
+ business_unit_id: 75,
586
+ permissions: [
587
+ {
588
+ permission_id: 54,
589
+ permission_name: 'Account Enquiry',
590
+ },
591
+ {
592
+ permission_id: 41,
593
+ permission_name: 'Account Enquiry - Account Notes',
594
+ },
595
+ ],
596
+ },
597
+ {
598
+ business_unit_user_id: 'L080KG',
599
+ business_unit_id: 80,
600
+ permissions: [
601
+ {
602
+ permission_id: 54,
603
+ permission_name: 'Account Enquiry',
604
+ },
605
+ {
606
+ permission_id: 41,
607
+ permission_name: 'Account Enquiry - Account Notes',
608
+ },
609
+ ],
610
+ },
611
+ {
612
+ business_unit_user_id: 'L062KG',
613
+ business_unit_id: 62,
614
+ permissions: [
615
+ {
616
+ permission_id: 54,
617
+ permission_name: 'Account Enquiry',
618
+ },
619
+ {
620
+ permission_id: 41,
621
+ permission_name: 'Account Enquiry - Account Notes',
622
+ },
623
+ ],
624
+ },
625
+ {
626
+ business_unit_user_id: 'L025KG',
627
+ business_unit_id: 25,
628
+ permissions: [
629
+ {
630
+ permission_id: 54,
631
+ permission_name: 'Account Enquiry',
632
+ },
633
+ {
634
+ permission_id: 41,
635
+ permission_name: 'Account Enquiry - Account Notes',
636
+ },
637
+ ],
638
+ },
639
+ {
640
+ business_unit_user_id: 'L032KG',
641
+ business_unit_id: 32,
642
+ permissions: [
643
+ {
644
+ permission_id: 54,
645
+ permission_name: 'Account Enquiry',
646
+ },
647
+ {
648
+ permission_id: 41,
649
+ permission_name: 'Account Enquiry - Account Notes',
650
+ },
651
+ ],
652
+ },
653
+ {
654
+ business_unit_user_id: 'L063KG',
655
+ business_unit_id: 63,
656
+ permissions: [
657
+ {
658
+ permission_id: 54,
659
+ permission_name: 'Account Enquiry',
660
+ },
661
+ {
662
+ permission_id: 41,
663
+ permission_name: 'Account Enquiry - Account Notes',
664
+ },
665
+ ],
666
+ },
667
+ {
668
+ business_unit_user_id: 'L064KG',
669
+ business_unit_id: 64,
670
+ permissions: [
671
+ {
672
+ permission_id: 54,
673
+ permission_name: 'Account Enquiry',
674
+ },
675
+ {
676
+ permission_id: 41,
677
+ permission_name: 'Account Enquiry - Account Notes',
678
+ },
679
+ ],
680
+ },
681
+ {
682
+ business_unit_user_id: 'L070KG',
683
+ business_unit_id: 70,
684
+ permissions: [
685
+ {
686
+ permission_id: 54,
687
+ permission_name: 'Account Enquiry',
688
+ },
689
+ {
690
+ permission_id: 41,
691
+ permission_name: 'Account Enquiry - Account Notes',
692
+ },
693
+ ],
694
+ },
695
+ {
696
+ business_unit_user_id: 'L065KG',
697
+ business_unit_id: 65,
698
+ permissions: [
699
+ {
700
+ permission_id: 54,
701
+ permission_name: 'Account Enquiry',
702
+ },
703
+ {
704
+ permission_id: 41,
705
+ permission_name: 'Account Enquiry - Account Notes',
706
+ },
707
+ ],
708
+ },
709
+ {
710
+ business_unit_user_id: 'L071KG',
711
+ business_unit_id: 71,
712
+ permissions: [
713
+ {
714
+ permission_id: 54,
715
+ permission_name: 'Account Enquiry',
716
+ },
717
+ {
718
+ permission_id: 41,
719
+ permission_name: 'Account Enquiry - Account Notes',
720
+ },
721
+ ],
722
+ },
723
+ ],
724
+ };
725
+
726
+ // SERVICE
727
+
728
+ const routePermissionsGuard = (route) => {
729
+ const permissionService = inject(PermissionsService);
730
+ const sessionService = inject(SessionService);
731
+ const router = inject(Router);
732
+ return sessionService.getUserState().pipe(map((resp) => {
733
+ const routePermissionId = route.data['routePermissionId'];
734
+ // Get the unique permission ids for the user
735
+ const uniquePermissionIds = permissionService.getUniquePermissions(resp);
736
+ // If we don't have a permission id for the route, or we don't have any unique permission ids, or the user doesn't have the required permission
737
+ // then redirect the user to the access denied page
738
+ if (!routePermissionId || uniquePermissionIds.length === 0 || !uniquePermissionIds.includes(routePermissionId)) {
739
+ return router.createUrlTree([`/${PAGES_ROUTING_PATHS.children.accessDenied}`]);
740
+ }
741
+ return true;
742
+ }), catchError(() => {
743
+ return of(false);
744
+ }));
745
+ };
746
+
747
+ class TransferStateService {
748
+ platformId;
749
+ serverTransferState;
750
+ transferState;
751
+ globalStore = inject(GlobalStore);
752
+ storedServerTransferState;
753
+ constructor(platformId, serverTransferState, transferState) {
754
+ this.platformId = platformId;
755
+ this.serverTransferState = serverTransferState;
756
+ this.transferState = transferState;
757
+ const storeKeyTransferState = makeStateKey('serverTransferState');
758
+ if (isPlatformBrowser(this.platformId)) {
759
+ // get user state from transfer state if browser side
760
+ this.serverTransferState = this.transferState.get(storeKeyTransferState, null);
761
+ if (this.serverTransferState) {
762
+ this.storedServerTransferState = this.serverTransferState;
763
+ }
764
+ }
765
+ else {
766
+ // server side: store server transfer state
767
+ this.transferState.set(storeKeyTransferState, this.serverTransferState);
768
+ }
769
+ }
770
+ /**
771
+ * Initializes the SSO (Single Sign-On) enabled state.
772
+ * Sets the SSO enabled state based on the stored server transfer state.
773
+ */
774
+ initializeSsoEnabled() {
775
+ this.globalStore.setSsoEnabled(this.storedServerTransferState?.ssoEnabled);
776
+ }
777
+ /**
778
+ * Initializes the LaunchDarkly configuration by assigning the stored server transfer state's
779
+ * launchDarklyConfig value to the globalStore's launchDarklyConfig property.
780
+ */
781
+ initializeLaunchDarklyConfig() {
782
+ this.globalStore.setLaunchDarklyConfig(this.storedServerTransferState?.launchDarklyConfig);
783
+ }
784
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TransferStateService, deps: [{ token: PLATFORM_ID }, { token: 'serverTransferState', optional: true }, { token: i0.TransferState }], target: i0.ɵɵFactoryTarget.Injectable });
785
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TransferStateService, providedIn: 'root' });
786
+ }
787
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TransferStateService, decorators: [{
788
+ type: Injectable,
789
+ args: [{
790
+ providedIn: 'root',
791
+ }]
792
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
793
+ type: Inject,
794
+ args: [PLATFORM_ID]
795
+ }] }, { type: undefined, decorators: [{
796
+ type: Optional
797
+ }, {
798
+ type: Inject,
799
+ args: ['serverTransferState']
800
+ }] }, { type: i0.TransferState }] });
801
+
802
+ const TRANSFER_STATE_APP_INSIGHTS_CONFIG_MOCK = {
803
+ enabled: true,
804
+ connectionString: 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://your-ingestion-endpoint/',
805
+ cloudRoleName: 'opal-frontend',
806
+ };
807
+
808
+ const TRANSFER_STATE_LAUNCH_DARKLY_CONFIG_MOCK = {
809
+ enabled: true,
810
+ clientId: '12345',
811
+ stream: true,
812
+ };
813
+
814
+ const TRANSFER_STATE_MOCK = {
815
+ launchDarklyConfig: TRANSFER_STATE_LAUNCH_DARKLY_CONFIG_MOCK,
816
+ ssoEnabled: true,
817
+ appInsightsConfig: TRANSFER_STATE_APP_INSIGHTS_CONFIG_MOCK,
818
+ };
819
+
820
+ // SERVICE
821
+
822
+ class AppInitializerService {
823
+ transferStateService = inject(TransferStateService);
824
+ /**
825
+ * Initializes the SSO (Single Sign-On) enabled state.
826
+ * This method calls the `initializeSsoEnabled` method of the `transferStateService`.
827
+ */
828
+ initializeSsoEnabled() {
829
+ this.transferStateService.initializeSsoEnabled();
830
+ }
831
+ /**
832
+ * Initializes the LaunchDarkly configuration.
833
+ */
834
+ initializeLaunchDarkly() {
835
+ this.transferStateService.initializeLaunchDarklyConfig();
836
+ }
837
+ /**
838
+ * Initializes the application.
839
+ * This method calls the necessary initialization functions.
840
+ */
841
+ initializeApp() {
842
+ this.initializeSsoEnabled();
843
+ this.initializeLaunchDarkly();
844
+ }
845
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AppInitializerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
846
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AppInitializerService, providedIn: 'root' });
847
+ }
848
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AppInitializerService, decorators: [{
849
+ type: Injectable,
850
+ args: [{
851
+ providedIn: 'root',
852
+ }]
853
+ }] });
854
+
855
+ class AppInsightsService {
856
+ appInsights;
857
+ appInsightsConfig;
858
+ platformId = inject(PLATFORM_ID);
859
+ transferStateService = inject(TransferStateService);
860
+ constructor() {
861
+ this.appInsightsConfig = this.transferStateService.serverTransferState?.appInsightsConfig;
862
+ if (isPlatformBrowser(this.platformId) && this.appInsightsConfig) {
863
+ if (this.appInsightsConfig.enabled) {
864
+ this.appInsights = new ApplicationInsights({
865
+ config: {
866
+ connectionString: this.appInsightsConfig.connectionString,
867
+ enableAutoRouteTracking: true,
868
+ },
869
+ });
870
+ this.appInsights.addTelemetryInitializer(this.telemetryInitializer.bind(this));
871
+ this.appInsights.loadAppInsights();
872
+ }
873
+ }
874
+ }
875
+ /**
876
+ * Adds a telemetry initializer to set the cloud role name for the telemetry item.
877
+ *
878
+ * @param envelope - The telemetry item to which the cloud role name will be added.
879
+ */
880
+ telemetryInitializer(envelope) {
881
+ envelope.tags = envelope.tags || {};
882
+ if (this.appInsightsConfig?.enabled) {
883
+ envelope.tags['ai.cloud.role'] = this.appInsightsConfig.cloudRoleName;
884
+ }
885
+ }
886
+ /**
887
+ * Logs a page view to the Application Insights service.
888
+ *
889
+ * @param name - The name of the page. Optional.
890
+ * @param url - The URL of the page. Optional.
891
+ *
892
+ * This method uses the Application Insights SDK to track a page view event.
893
+ * If the `name` or `url` parameters are not provided, the SDK will use default values.
894
+ */
895
+ logPageView(name, url) {
896
+ if (!this.appInsightsConfig?.enabled) {
897
+ return;
898
+ }
899
+ this.appInsights.trackPageView({ name, uri: url });
900
+ }
901
+ /**
902
+ * Logs an exception to the Application Insights service.
903
+ *
904
+ * @param exception - The error object to be logged.
905
+ * @param severityLevel - Optional. The severity level of the exception. If not provided, a default severity level will be used.
906
+ */
907
+ logException(exception, severityLevel) {
908
+ if (!this.appInsightsConfig?.enabled) {
909
+ return;
910
+ }
911
+ this.appInsights.trackException({ exception, severityLevel });
912
+ }
913
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AppInsightsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
914
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AppInsightsService, providedIn: 'root' });
915
+ }
916
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AppInsightsService, decorators: [{
917
+ type: Injectable,
918
+ args: [{
919
+ providedIn: 'root',
920
+ }]
921
+ }], ctorParameters: () => [] });
922
+
923
+ // SERVICE
924
+ // CONSTANTS, INTERFACES, AND MOCKS
925
+
926
+ class DateService {
927
+ /**
928
+ * Calculates the difference in minutes between two DateTime objects.
929
+ * @param startDate The start date and time.
930
+ * @param endDate The end date and time.
931
+ * @returns The difference in minutes between the start and end dates.
932
+ */
933
+ calculateMinutesDifference(startDate, endDate) {
934
+ const minuteDifference = endDate.diff(startDate, 'minutes');
935
+ return Math.max(0, Math.ceil(minuteDifference.minutes));
936
+ }
937
+ /**
938
+ * Converts milliseconds to minutes.
939
+ * @param milliseconds - The number of milliseconds to convert.
940
+ * @returns The equivalent number of minutes.
941
+ */
942
+ convertMillisecondsToMinutes(milliseconds) {
943
+ const minutes = Duration.fromMillis(milliseconds).as('minutes');
944
+ return Math.max(0, Math.ceil(minutes));
945
+ }
946
+ /**
947
+ * Calculates the age based on the given date of birth.
948
+ * @param dateOfBirth - The date of birth to calculate the age from.
949
+ * @param format - The format of the date of birth. Defaults to 'dd/MM/yyyy'.
950
+ * @returns The calculated age.
951
+ */
952
+ calculateAge(dateOfBirth, format = 'dd/MM/yyyy') {
953
+ const date = typeof dateOfBirth === 'string' ? this.getFromFormat(dateOfBirth, format) : dateOfBirth;
954
+ return Math.floor(DateTime.now().diff(date, 'years').years);
955
+ }
956
+ /**
957
+ * Checks if a given date is valid.
958
+ * @param dateInput - The date to be checked. It can be a DateTime object, a string, or null.
959
+ * @param format - The format of the date string (default: 'dd/MM/yyyy').
960
+ * @returns A boolean indicating whether the date is valid or not.
961
+ */
962
+ isValidDate(dateInput, format = 'dd/MM/yyyy') {
963
+ if (dateInput) {
964
+ const date = typeof dateInput === 'string' ? this.getFromFormat(dateInput, format) : dateInput;
965
+ return date.isValid;
966
+ }
967
+ return false;
968
+ }
969
+ /**
970
+ * Returns a string representation of a date subtracted by the given duration.
971
+ * @param duration A DurationLikeObject representing the amount of time to subtract from the current date.
972
+ * @returns A string representing the subtracted date in the format specified by the current locale.
973
+ */
974
+ getPreviousDate(duration) {
975
+ return DateTime.now().minus(duration).setLocale('en-gb').toLocaleString();
976
+ }
977
+ /**
978
+ * Parses a string value into a DateTime object based on the specified format.
979
+ * @param value - The string value to parse.
980
+ * @param format - The format of the string value.
981
+ * @returns A DateTime object representing the parsed value.
982
+ */
983
+ getFromFormat(value, format) {
984
+ return DateTime.fromFormat(value, format);
985
+ }
986
+ /**
987
+ * Parses a string value into a native JavaScript Date object based on the specified format.
988
+ * @param value - The string value to parse.
989
+ * @param format - The format of the string value.
990
+ * @returns A Date object representing the parsed value, or null if parsing fails.
991
+ */
992
+ getDateFromFormat(value, format) {
993
+ const dateTime = DateTime.fromFormat(value, format);
994
+ return dateTime.isValid ? dateTime.toJSDate() : null;
995
+ }
996
+ /**
997
+ * Converts a DateTime value to a formatted string.
998
+ *
999
+ * @param value - The DateTime value to format.
1000
+ * @param format - The format string to apply to the DateTime value.
1001
+ * @returns The formatted string representation of the DateTime value.
1002
+ */
1003
+ toFormat(value, format) {
1004
+ return value.toFormat(format);
1005
+ }
1006
+ /**
1007
+ * Converts a given Date object to a formatted string based on the specified format.
1008
+ *
1009
+ * @param value - The Date object to be formatted.
1010
+ * @param format - The string format to apply to the Date object.
1011
+ * @returns The formatted date string.
1012
+ */
1013
+ toDateStringFormat(value, format) {
1014
+ return DateTime.fromJSDate(value).toFormat(format);
1015
+ }
1016
+ /**
1017
+ * Converts a string in ISO format to a DateTime object.
1018
+ * @param value - The string value in ISO format.
1019
+ * @returns A DateTime object representing the given value.
1020
+ */
1021
+ getFromIso(value) {
1022
+ return DateTime.fromISO(value);
1023
+ }
1024
+ /**
1025
+ * Returns the current date and time.
1026
+ * @returns {DateTime} The current date and time.
1027
+ */
1028
+ getDateNow() {
1029
+ return DateTime.now();
1030
+ }
1031
+ /**
1032
+ * Adds a duration to a given date and returns the result in the specified format.
1033
+ * @param date - The date to which the duration will be added.
1034
+ * @param years - The number of years to add to the date (default: 0).
1035
+ * @param months - The number of months to add to the date (default: 0).
1036
+ * @param weeks - The number of weeks to add to the date (default: 0).
1037
+ * @param days - The number of days to add to the date (default: 0).
1038
+ * @param format - The format in which the resulting date will be returned (default: 'dd/MM/yyyy').
1039
+ * @returns The resulting date in the specified format.
1040
+ */
1041
+ addDurationToDate(date, years = 0, months = 0, weeks = 0, days = 0, format = 'dd/MM/yyyy') {
1042
+ const dateObj = this.getFromFormat(date, format);
1043
+ const newDate = dateObj.plus({ years, months, weeks, days });
1044
+ return newDate.toFormat(format);
1045
+ }
1046
+ /**
1047
+ * Calculates the number of days between two dates.
1048
+ * @param startDate - The start date in the specified format.
1049
+ * @param endDate - The end date in the specified format.
1050
+ * @param format - The format of the dates (default: 'dd/MM/yyyy').
1051
+ * @returns The number of days between the start and end dates.
1052
+ */
1053
+ calculateDaysBetweenDates(startDate, endDate, format = 'dd/MM/yyyy') {
1054
+ const start = this.getFromFormat(startDate, format);
1055
+ const end = this.getFromFormat(endDate, format);
1056
+ const diff = end.diff(start, 'days');
1057
+ return diff.days;
1058
+ }
1059
+ /**
1060
+ * Checks if a given date is in the past.
1061
+ * @param date - The date to check.
1062
+ * @param format - The format of the date string. Defaults to 'dd/MM/yyyy'.
1063
+ * @returns True if the date is in the past, false otherwise.
1064
+ */
1065
+ isDateInThePast(date, format = 'dd/MM/yyyy') {
1066
+ return this.getFromFormat(date, format) < DateTime.now();
1067
+ }
1068
+ /**
1069
+ * Checks if a given date is in the future.
1070
+ * @param date - The date to check.
1071
+ * @param yearsInTheFuture - Optional. The number of years in the future to compare against. If not provided, the current date is used.
1072
+ * @param format - Optional. The format of the input date. Defaults to 'dd/MM/yyyy'.
1073
+ * @returns True if the date is in the future, false otherwise.
1074
+ */
1075
+ isDateInTheFuture(date, yearsInTheFuture, format = 'dd/MM/yyyy') {
1076
+ const now = DateTime.now();
1077
+ const dateValue = this.getFromFormat(date, format);
1078
+ if (yearsInTheFuture) {
1079
+ const futureDate = now.plus({ years: yearsInTheFuture });
1080
+ return dateValue > futureDate;
1081
+ }
1082
+ return dateValue > now;
1083
+ }
1084
+ /**
1085
+ * Converts a date string from one format to another.
1086
+ *
1087
+ * @param date - The date string to be converted.
1088
+ * @param fromFormat - The format of the input date string.
1089
+ * @param toFormat - The desired format of the output date string.
1090
+ * @returns The date string in the desired format.
1091
+ */
1092
+ getFromFormatToFormat(date, fromFormat, toFormat) {
1093
+ return this.getFromFormat(date, fromFormat).toFormat(toFormat);
1094
+ }
1095
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1096
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DateService, providedIn: 'root' });
1097
+ }
1098
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DateService, decorators: [{
1099
+ type: Injectable,
1100
+ args: [{
1101
+ providedIn: 'root',
1102
+ }]
1103
+ }] });
1104
+
1105
+ // SERVICE
1106
+ // CONSTANTS, INTERFACES, AND MOCKS
1107
+
1108
+ class LaunchDarklyService {
1109
+ globalStore = inject(GlobalStore);
1110
+ ldClient;
1111
+ /**
1112
+ * Sets the LaunchDarkly flags by updating the featureFlags in the state service.
1113
+ */
1114
+ setLaunchDarklyFlags() {
1115
+ if (this.ldClient) {
1116
+ this.globalStore.setFeatureFlags(this.ldClient.allFlags());
1117
+ }
1118
+ }
1119
+ /**
1120
+ * Formats the LDFlagChangeset into an LDFlagSet.
1121
+ *
1122
+ * @param flags - The LDFlagChangeset to be formatted.
1123
+ * @returns The formatted LDFlagSet.
1124
+ */
1125
+ formatChangeFlags(flags) {
1126
+ return Object.keys(flags).reduce((flag, key) => {
1127
+ flag[key] = flags[key].current;
1128
+ return flag;
1129
+ }, {});
1130
+ }
1131
+ /**
1132
+ * Closes the LaunchDarkly client if it is open.
1133
+ */
1134
+ closeLaunchDarklyClient() {
1135
+ if (this.ldClient) {
1136
+ this.ldClient.close();
1137
+ }
1138
+ }
1139
+ /**
1140
+ * Initializes the LaunchDarkly change listener.
1141
+ * This method listens for changes in feature flags and updates the state accordingly.
1142
+ */
1143
+ initializeLaunchDarklyChangeListener() {
1144
+ if (this.ldClient && this.globalStore.launchDarklyConfig().stream) {
1145
+ this.ldClient.on('change', (flags) => {
1146
+ const updatedFlags = {
1147
+ ...this.globalStore.featureFlags(),
1148
+ ...this.formatChangeFlags(flags),
1149
+ };
1150
+ this.globalStore.setFeatureFlags(updatedFlags);
1151
+ });
1152
+ }
1153
+ }
1154
+ /**
1155
+ * Initializes the LaunchDarkly flags and sets them.
1156
+ * If the LD client is already initialized, it waits for initialization and then sets the flags.
1157
+ * If the LD client is not initialized, it returns a resolved promise.
1158
+ * @returns A promise that resolves when the flags are set.
1159
+ */
1160
+ async initializeLaunchDarklyFlags() {
1161
+ if (this.ldClient) {
1162
+ return this.ldClient
1163
+ .waitForInitialization()
1164
+ .then(() => this.setLaunchDarklyFlags())
1165
+ .catch((err) => {
1166
+ throw err;
1167
+ });
1168
+ }
1169
+ return Promise.resolve();
1170
+ }
1171
+ /**
1172
+ * Initializes the LaunchDarkly client.
1173
+ * If a stored LaunchDarkly client ID exists, it initializes the client with the ID and anonymous mode enabled.
1174
+ */
1175
+ initializeLaunchDarklyClient() {
1176
+ if (this.globalStore.launchDarklyConfig()) {
1177
+ const { enabled, clientId } = this.globalStore.launchDarklyConfig();
1178
+ if (enabled && clientId) {
1179
+ this.ldClient = initialize(clientId, {
1180
+ anonymous: true,
1181
+ });
1182
+ }
1183
+ }
1184
+ }
1185
+ ngOnDestroy() {
1186
+ this.closeLaunchDarklyClient();
1187
+ }
1188
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: LaunchDarklyService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1189
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: LaunchDarklyService, providedIn: 'root' });
1190
+ }
1191
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: LaunchDarklyService, decorators: [{
1192
+ type: Injectable,
1193
+ args: [{
1194
+ providedIn: 'root',
1195
+ }]
1196
+ }] });
1197
+
1198
+ const LAUNCH_DARKLY_CHANGE_FLAGS_MOCK = {
1199
+ flag1: { current: true, previous: false },
1200
+ flag2: { current: false, previous: true },
1201
+ };
1202
+
1203
+ const LAUNCH_DARKLY_FLAGS_MOCK = {
1204
+ flag1: true,
1205
+ flag2: false,
1206
+ };
1207
+
1208
+ // SERVICE
1209
+
1210
+ class SortService {
1211
+ /**
1212
+ * Sorts an array of values in ascending order.
1213
+ *
1214
+ * @param array - The array of values to be sorted.
1215
+ * @returns The sorted array in ascending order.
1216
+ */
1217
+ arraySortAsc(array) {
1218
+ return sort(array).asc();
1219
+ }
1220
+ /**
1221
+ * Sorts an array of values in descending order.
1222
+ *
1223
+ * @param array - The array of values to be sorted.
1224
+ * @returns The sorted array in descending order.
1225
+ */
1226
+ arraySortDesc(array) {
1227
+ return sort(array).desc();
1228
+ }
1229
+ /**
1230
+ * Sorts an array of objects based on a specified key and sort type.
1231
+ *
1232
+ * @param array - The array of objects to be sorted. Each object should implement the `ISortServiceValues` interface.
1233
+ * @param config - The configuration object containing the key to sort by and the sort type (ascending or descending).
1234
+ * @returns The sorted array of objects.
1235
+ *
1236
+ * @remarks
1237
+ * - If the input array is not an array or the config key is not provided, the original array is returned.
1238
+ * - The `sortType` can be either 'ascending' or 'descending'.
1239
+ *
1240
+ * @example
1241
+ * ```typescript
1242
+ * const array = [
1243
+ * { name: 'Alice', age: 30 },
1244
+ * { name: 'Bob', age: 25 },
1245
+ * ];
1246
+ * const config = { key: 'age', sortType: 'ascending' };
1247
+ * const sortedArray = getObjects(array, config);
1248
+ * // sortedArray will be:
1249
+ * // [
1250
+ * // { name: 'Bob', age: 25 },
1251
+ * // { name: 'Alice', age: 30 },
1252
+ * // ]
1253
+ * ```
1254
+ */
1255
+ sortObjectArray(array, config) {
1256
+ if (!Array.isArray(array) || !config.key) {
1257
+ return array;
1258
+ }
1259
+ const { key, sortType } = config;
1260
+ if (sortType === 'ascending') {
1261
+ return sort(array).asc((obj) => obj[key]);
1262
+ }
1263
+ else {
1264
+ return sort(array).desc((obj) => obj[key]);
1265
+ }
1266
+ }
1267
+ /**
1268
+ * Sorts an array of objects in ascending order based on the specified key.
1269
+ *
1270
+ * @param array - The array of objects to be sorted.
1271
+ * @param key - The key of the object property to sort by.
1272
+ * @returns The sorted array of objects.
1273
+ */
1274
+ sortObjectArrayAsc(array, key) {
1275
+ return this.sortObjectArray(array, { key, sortType: 'ascending' });
1276
+ }
1277
+ /**
1278
+ * Sorts an array of objects in descending order based on the specified key.
1279
+ *
1280
+ * @param array - The array of objects to be sorted. Each object should implement the ISortServiceValues interface.
1281
+ * @param key - The key of the object property to sort by.
1282
+ * @returns The sorted array of objects in descending order.
1283
+ */
1284
+ sortObjectArrayDesc(array, key) {
1285
+ return this.sortObjectArray(array, { key, sortType: 'descending' });
1286
+ }
1287
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SortService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1288
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SortService, providedIn: 'root' });
1289
+ }
1290
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SortService, decorators: [{
1291
+ type: Injectable,
1292
+ args: [{
1293
+ providedIn: 'root',
1294
+ }]
1295
+ }] });
1296
+
1297
+ // SERVICE
1298
+
1299
+ class TransformationService {
1300
+ dateService = inject(DateService);
1301
+ /**
1302
+ * Applies a transformation to the given value based on the specified transformation configuration.
1303
+ *
1304
+ * @param value - The value to be transformed.
1305
+ * @param transformItem - The configuration for the transformation, including the type of transformation and any necessary format details.
1306
+ * @returns The transformed value, or the original value if no transformation is applied.
1307
+ */
1308
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1309
+ applyTransformation(value, transformItem) {
1310
+ if (!value) {
1311
+ return value;
1312
+ }
1313
+ if (transformItem.transformType === 'date') {
1314
+ if (transformItem.dateInputFormat !== null && transformItem.dateOutputFormat !== null) {
1315
+ const parsedDate = this.dateService.getFromFormat(value, transformItem.dateInputFormat);
1316
+ if (this.dateService.isValidDate(parsedDate)) {
1317
+ return this.dateService.toFormat(parsedDate, transformItem.dateOutputFormat);
1318
+ }
1319
+ }
1320
+ return value;
1321
+ }
1322
+ return value;
1323
+ }
1324
+ /**
1325
+ * Transforms the values of an object based on a given transformation configuration.
1326
+ *
1327
+ * @param obj - The object whose values need to be transformed. It should be a non-null object.
1328
+ * @param toTransform - An array of transformation configurations, where each configuration specifies
1329
+ * the key to transform and the transformation details.
1330
+ * @returns The transformed object with values modified according to the transformation configuration.
1331
+ *
1332
+ * @remarks
1333
+ * - If the input `obj` is not an object or is null, it returns the input as is.
1334
+ * - The function recursively processes nested objects.
1335
+ */
1336
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1337
+ transformObjectValues(obj, toTransform) {
1338
+ if (typeof obj !== 'object' || obj === null) {
1339
+ return obj;
1340
+ }
1341
+ for (const [key, value] of Object.entries(obj)) {
1342
+ const transformItem = toTransform.find((item) => item.key === key);
1343
+ if (transformItem) {
1344
+ obj[key] = this.applyTransformation(value, transformItem);
1345
+ }
1346
+ else if (Array.isArray(value)) {
1347
+ obj[key] = value.map((item) => typeof item === 'object' ? this.transformObjectValues(item, toTransform) : item);
1348
+ }
1349
+ else if (typeof value === 'object') {
1350
+ obj[key] = this.transformObjectValues(value, toTransform); // Recursive call
1351
+ }
1352
+ }
1353
+ return obj;
1354
+ }
1355
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TransformationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1356
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TransformationService, providedIn: 'root' });
1357
+ }
1358
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TransformationService, decorators: [{
1359
+ type: Injectable,
1360
+ args: [{
1361
+ providedIn: 'root',
1362
+ }]
1363
+ }] });
1364
+
1365
+ // SERVICE
1366
+
1367
+ class UtilsService {
1368
+ viewportScroller = inject(ViewportScroller);
1369
+ /**
1370
+ * Converts the first letter of a string to uppercase.
1371
+ * @param str - The input string.
1372
+ * @returns The input string with the first letter capitalized.
1373
+ */
1374
+ upperCaseFirstLetter(str) {
1375
+ return str.charAt(0).toUpperCase() + str.slice(1);
1376
+ }
1377
+ /**
1378
+ * Converts the entire string to uppercase.
1379
+ * @param str - The input string.
1380
+ * @returns The input string in uppercase.
1381
+ */
1382
+ upperCaseAllLetters(str) {
1383
+ return str.toUpperCase();
1384
+ }
1385
+ /**
1386
+ * Converts a number to a monetary string representation.
1387
+ * @param amount - The number to convert.
1388
+ * @returns The monetary string representation of the number.
1389
+ */
1390
+ convertToMonetaryString(amount) {
1391
+ if (typeof amount === 'string') {
1392
+ amount = parseFloat(amount);
1393
+ }
1394
+ return `£${amount.toFixed(2)}`;
1395
+ }
1396
+ /**
1397
+ * Formats a 6-digit number or string as a sort code.
1398
+ * @param value - The 6-digit value to format.
1399
+ * @returns The formatted sort code string (xx-xx-xx).
1400
+ */
1401
+ formatSortCode(value) {
1402
+ const sortCode = value.toString();
1403
+ return `${sortCode.slice(0, 2)}-${sortCode.slice(2, 4)}-${sortCode.slice(4, 6)}`;
1404
+ }
1405
+ /**
1406
+ * Filters out null or empty strings from an array of address lines.
1407
+ *
1408
+ * @param address - An array of address lines which may contain strings or null values.
1409
+ * @returns A new array containing only non-empty strings from the input array.
1410
+ */
1411
+ formatAddress(address) {
1412
+ return address.filter((line) => !!line?.trim());
1413
+ }
1414
+ /**
1415
+ * Scrolls the viewport to the top of the page.
1416
+ * Utilizes the `viewportScroller` service to scroll to the position [0, 0].
1417
+ */
1418
+ scrollToTop() {
1419
+ this.viewportScroller.scrollToPosition([0, 0]);
1420
+ }
1421
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1422
+ checkFormValues(form) {
1423
+ return Object.values(form).some((value) => {
1424
+ return Array.isArray(value) ? value.length > 0 : Boolean(value);
1425
+ });
1426
+ }
1427
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1428
+ checkFormArrayValues(forms) {
1429
+ return forms.every((form) => this.checkFormValues(form));
1430
+ }
1431
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1432
+ getFormStatus(form, providedMessage, notProvidedMessage) {
1433
+ return this.checkFormValues(form) ? providedMessage : notProvidedMessage;
1434
+ }
1435
+ getArrayFormStatus(
1436
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1437
+ forms, providedMessage, notProvidedMessage) {
1438
+ return forms.every((form) => this.checkFormValues(form)) ? providedMessage : notProvidedMessage;
1439
+ }
1440
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: UtilsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1441
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: UtilsService, providedIn: 'root' });
1442
+ }
1443
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: UtilsService, decorators: [{
1444
+ type: Injectable,
1445
+ args: [{
1446
+ providedIn: 'root',
1447
+ }]
1448
+ }] });
1449
+
1450
+ // SERVICE
1451
+ // CONSTANTS, INTERFACES, AND MOCKS
1452
+
1453
+ /**
1454
+ * A guard that checks if the user is signed in.
1455
+ * If the user is signed in, it redirects to the default route.
1456
+ * If the user is not signed in, it allows access to the route.
1457
+ * @returns An Observable<boolean> indicating whether the user is signed in or not.
1458
+ */
1459
+ const signedInGuard = () => {
1460
+ const authService = inject(AuthService);
1461
+ const router = inject(Router);
1462
+ return authService.checkAuthenticated().pipe(map(() => {
1463
+ return router.createUrlTree(['/']);
1464
+ }), catchError(() => {
1465
+ return of(true);
1466
+ }));
1467
+ };
1468
+
1469
+ // GUARD
1470
+
1471
+ /**
1472
+ * Returns a function that invokes the specified guard with a dummy route and state.
1473
+ * The dummy route and state are created using the provided `urlPath`.
1474
+ *
1475
+ * @param guard - The guard function to be invoked.
1476
+ * @param urlPath - The URL path to be used in the dummy route and state.
1477
+ * @returns A function that invokes the guard with the dummy route and state.
1478
+ */
1479
+ function getGuardWithDummyUrl(guard, urlPath) {
1480
+ const dummyRoute = new ActivatedRouteSnapshot();
1481
+ dummyRoute.url = [new UrlSegment(urlPath, {})];
1482
+ const dummyState = {
1483
+ url: urlPath,
1484
+ root: new ActivatedRouteSnapshot(),
1485
+ };
1486
+ return () => guard(dummyRoute, dummyState);
1487
+ }
1488
+
1489
+ /**
1490
+ * Converts an Observable result to a Promise.
1491
+ * @param result The Observable result to handle.
1492
+ * @returns A Promise that resolves with the value of the Observable.
1493
+ */
1494
+ function handleObservableResult(result) {
1495
+ return new Promise((resolve) => {
1496
+ result.subscribe((value) => {
1497
+ resolve(value);
1498
+ });
1499
+ });
1500
+ }
1501
+
1502
+ /**
1503
+ * Runs an authentication guard function within the injection context of TestBed.
1504
+ *
1505
+ * @param authGuard - The authentication guard function to run.
1506
+ * @returns A promise that resolves to a boolean or UrlTree indicating whether the user is authenticated.
1507
+ */
1508
+ async function runAuthGuardWithContext(authGuard) {
1509
+ const result = TestBed.runInInjectionContext(authGuard);
1510
+ const authenticated = result instanceof Observable ? await handleObservableResult(result) : result;
1511
+ return authenticated;
1512
+ }
1513
+
1514
+ async function runHasFlowStateGuardWithContext(hasFlowStateGuard) {
1515
+ const result = TestBed.runInInjectionContext(hasFlowStateGuard);
1516
+ const emptyFlow = result instanceof Observable ? await handleObservableResult(result) : result;
1517
+ return emptyFlow;
1518
+ }
1519
+
1520
+ // GUARDS
1521
+
1522
+ const httpErrorInterceptor = (req, next) => {
1523
+ const globalStore = inject(GlobalStore);
1524
+ const appInsightsService = inject(AppInsightsService);
1525
+ return next(req).pipe(tap(() => {
1526
+ // Clear the state service on new requests
1527
+ globalStore.setError({ error: false, message: '' });
1528
+ }), catchError((error) => {
1529
+ // Ensure ErrorEvent is handled only in browser environments
1530
+ const isBrowser = typeof window !== 'undefined';
1531
+ const isErrorEvent = isBrowser && typeof ErrorEvent !== 'undefined' && error.error instanceof ErrorEvent;
1532
+ const errorMessage = isErrorEvent ? `Error: ${error.error.message}` : `Error: ${error.message}`;
1533
+ globalStore.setError({
1534
+ error: true,
1535
+ message: errorMessage,
1536
+ });
1537
+ appInsightsService.logException(error);
1538
+ return throwError(() => error);
1539
+ }));
1540
+ };
1541
+
1542
+ class AccessDeniedComponent {
1543
+ router = inject(Router);
1544
+ handleGoBackButtonClick() {
1545
+ // For now, test page will act as our 'Dashboard' page
1546
+ this.router.navigate(['/']);
1547
+ }
1548
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AccessDeniedComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1549
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: AccessDeniedComponent, isStandalone: true, selector: "opal-lib-access-denied", ngImport: i0, template: "<div class=\"govuk-grid-row\">\n <div class=\"govuk-grid-column-two-thirds\">\n <h1 class=\"govuk-heading-l\">Access Denied</h1>\n <p class=\"govuk-body\">You do not have the appropriate permissions to access this page.</p>\n <p class=\"govuk-body\">\n <opal-lib-govuk-button\n buttonClasses=\"govuk-button--secondary\"\n buttonId=\"go-back\"\n (buttonClickEvent)=\"handleGoBackButtonClick()\"\n >\n Back to dashboard</opal-lib-govuk-button\n >\n </p>\n </div>\n</div>\n", dependencies: [{ kind: "component", type: GovukButtonComponent, selector: "opal-lib-govuk-button", inputs: ["buttonId", "type", "buttonClasses"], outputs: ["buttonClickEvent"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1550
+ }
1551
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: AccessDeniedComponent, decorators: [{
1552
+ type: Component,
1553
+ args: [{ standalone: true, selector: 'opal-lib-access-denied', imports: [GovukButtonComponent], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"govuk-grid-row\">\n <div class=\"govuk-grid-column-two-thirds\">\n <h1 class=\"govuk-heading-l\">Access Denied</h1>\n <p class=\"govuk-body\">You do not have the appropriate permissions to access this page.</p>\n <p class=\"govuk-body\">\n <opal-lib-govuk-button\n buttonClasses=\"govuk-button--secondary\"\n buttonId=\"go-back\"\n (buttonClickEvent)=\"handleGoBackButtonClick()\"\n >\n Back to dashboard</opal-lib-govuk-button\n >\n </p>\n </div>\n</div>\n" }]
1554
+ }] });
1555
+
1556
+ var accessDenied_component = /*#__PURE__*/Object.freeze({
1557
+ __proto__: null,
1558
+ AccessDeniedComponent: AccessDeniedComponent
1559
+ });
1560
+
1561
+ class SignInSsoComponent {
1562
+ signInButtonClick = new EventEmitter();
1563
+ /**
1564
+ * Handles the button click event.
1565
+ * Emits the `signInButtonClick` event.
1566
+ */
1567
+ handleButtonClick() {
1568
+ this.signInButtonClick.emit();
1569
+ }
1570
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SignInSsoComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1571
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: SignInSsoComponent, isStandalone: true, selector: "opal-lib-sign-in-sso", outputs: { signInButtonClick: "signInButtonClick" }, ngImport: i0, template: "<div class=\"govuk-grid-column-two-thirds\">\n <h1 class=\"govuk-heading-m\">Sign in</h1>\n <p class=\"govuk-body\">Please sign in to continue using the application</p>\n\n <p class=\"govuk-body\">\n <opal-lib-govuk-button buttonId=\"signInButton\" (buttonClickEvent)=\"handleButtonClick()\">\n Sign in</opal-lib-govuk-button\n >\n </p>\n</div>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: GovukButtonComponent, selector: "opal-lib-govuk-button", inputs: ["buttonId", "type", "buttonClasses"], outputs: ["buttonClickEvent"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1572
+ }
1573
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SignInSsoComponent, decorators: [{
1574
+ type: Component,
1575
+ args: [{ standalone: true, selector: 'opal-lib-sign-in-sso', imports: [CommonModule, GovukButtonComponent], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"govuk-grid-column-two-thirds\">\n <h1 class=\"govuk-heading-m\">Sign in</h1>\n <p class=\"govuk-body\">Please sign in to continue using the application</p>\n\n <p class=\"govuk-body\">\n <opal-lib-govuk-button buttonId=\"signInButton\" (buttonClickEvent)=\"handleButtonClick()\">\n Sign in</opal-lib-govuk-button\n >\n </p>\n</div>\n" }]
1576
+ }], propDecorators: { signInButtonClick: [{
1577
+ type: Output
1578
+ }] } });
1579
+
1580
+ class SignInComponent {
1581
+ globalStore = inject(GlobalStore);
1582
+ ssoEnabled = true;
1583
+ document = inject(DOCUMENT);
1584
+ changeDetectorRef = inject(ChangeDetectorRef);
1585
+ /**
1586
+ * Handles the login button click event.
1587
+ */
1588
+ handleSsoSignInButtonClick() {
1589
+ this.document.location.href = SSO_ENDPOINTS.login;
1590
+ }
1591
+ /**
1592
+ * Handles the submission of the stub sign-in form.
1593
+ * Redirects the user to the SSO login page with the provided email.
1594
+ * @param formData - The form data containing the email.
1595
+ */
1596
+ handleStubSignInFormSubmit(formData) {
1597
+ this.document.location.href = `${SSO_ENDPOINTS.login}?email=${formData.email}`;
1598
+ }
1599
+ ngOnInit() {
1600
+ // This is to prevent a load flicker when switching between sso/stub sign in
1601
+ this.ssoEnabled = this.globalStore.ssoEnabled();
1602
+ this.changeDetectorRef.detectChanges();
1603
+ }
1604
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SignInComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1605
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.13", type: SignInComponent, isStandalone: true, selector: "opal-lib-sign-in", ngImport: i0, template: "@defer (when !ssoEnabled) {\n <opal-lib-sign-in-stub (signInFormSubmit)=\"handleStubSignInFormSubmit($event)\"></opal-lib-sign-in-stub>\n} @placeholder {\n <opal-lib-sign-in-sso (signInButtonClick)=\"handleSsoSignInButtonClick()\"></opal-lib-sign-in-sso>\n}\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: SignInSsoComponent, selector: "opal-lib-sign-in-sso", outputs: ["signInButtonClick"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, deferBlockDependencies: [() => [import('./hmcts-opal-frontend-common-sign-in-stub.component-CysPzJGJ.mjs').then(m => m.SignInStubComponent)]] });
1606
+ }
1607
+ i0.ɵɵngDeclareClassMetadataAsync({ minVersion: "18.0.0", version: "18.2.13", ngImport: i0, type: SignInComponent, resolveDeferredDeps: () => [import('./hmcts-opal-frontend-common-sign-in-stub.component-CysPzJGJ.mjs').then(m => m.SignInStubComponent)], resolveMetadata: SignInStubComponent => ({ decorators: [{
1608
+ type: Component,
1609
+ args: [{ standalone: true, selector: 'opal-lib-sign-in', imports: [CommonModule, SignInSsoComponent, SignInStubComponent], changeDetection: ChangeDetectionStrategy.OnPush, template: "@defer (when !ssoEnabled) {\n <opal-lib-sign-in-stub (signInFormSubmit)=\"handleStubSignInFormSubmit($event)\"></opal-lib-sign-in-stub>\n} @placeholder {\n <opal-lib-sign-in-sso (signInButtonClick)=\"handleSsoSignInButtonClick()\"></opal-lib-sign-in-sso>\n}\n" }]
1610
+ }], ctorParameters: null, propDecorators: null }) });
1611
+
1612
+ var signIn_component = /*#__PURE__*/Object.freeze({
1613
+ __proto__: null,
1614
+ SignInComponent: SignInComponent
1615
+ });
1616
+
1617
+ const PAGES_ROUTING_TITLES = {
1618
+ root: '',
1619
+ children: {
1620
+ accessDenied: 'Access denied',
1621
+ signIn: 'Sign in',
1622
+ signInStub: 'Sign in',
1623
+ },
1624
+ };
1625
+
1626
+ /**
1627
+ * Resolver function for retrieving the user state.
1628
+ * @returns A promise that resolves to the user state.
1629
+ */
1630
+ const userStateResolver = async () => {
1631
+ // Weirdly angular suggests using async/await - https://angular.dev/api/router/ResolveFn?tab=usage-notes
1632
+ return await firstValueFrom(inject(SessionService).getUserState());
1633
+ };
1634
+
1635
+ class TitleResolver {
1636
+ titleService;
1637
+ constructor(titleService) {
1638
+ this.titleService = titleService;
1639
+ }
1640
+ resolve(route) {
1641
+ const title = route.data['title'] ?? 'Frontend';
1642
+ this.titleService.setTitle(`OPAL - ${title}`);
1643
+ }
1644
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TitleResolver, deps: [{ token: i1$2.Title }], target: i0.ɵɵFactoryTarget.Injectable });
1645
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TitleResolver, providedIn: 'root' });
1646
+ }
1647
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TitleResolver, decorators: [{
1648
+ type: Injectable,
1649
+ args: [{
1650
+ providedIn: 'root',
1651
+ }]
1652
+ }], ctorParameters: () => [{ type: i1$2.Title }] });
1653
+
1654
+ const routing = [
1655
+ { path: '', redirectTo: 'dashboard', pathMatch: 'full' },
1656
+ {
1657
+ path: PAGES_ROUTING_PATHS.children.accessDenied,
1658
+ loadComponent: () => Promise.resolve().then(function () { return accessDenied_component; }).then((c) => c.AccessDeniedComponent),
1659
+ canActivate: [authGuard],
1660
+ data: { title: PAGES_ROUTING_TITLES.children.accessDenied },
1661
+ resolve: { userState: userStateResolver, title: TitleResolver },
1662
+ },
1663
+ {
1664
+ path: PAGES_ROUTING_PATHS.children.signIn,
1665
+ loadComponent: () => Promise.resolve().then(function () { return signIn_component; }).then((c) => c.SignInComponent),
1666
+ canActivate: [signedInGuard],
1667
+ data: { title: PAGES_ROUTING_TITLES.children.signIn },
1668
+ resolve: { title: TitleResolver },
1669
+ },
1670
+ ];
1671
+
1672
+ function alphabeticalTextValidator() {
1673
+ return (control) => {
1674
+ const value = control.value;
1675
+ if (value && !/^[a-zA-Z0-9'()*_., -]*$/.test(value)) {
1676
+ return { alphabeticalTextPattern: { value: value } };
1677
+ }
1678
+ return null;
1679
+ };
1680
+ }
1681
+
1682
+ function amountValidator(maxIntegers, maxDecimals) {
1683
+ return (control) => {
1684
+ if (control.value === null || control.value === undefined || control.value === '') {
1685
+ return null;
1686
+ }
1687
+ // Ensure the value is numerical, allowing only digits and optionally one decimal point
1688
+ if (isNaN(control.value)) {
1689
+ return { invalidAmountValue: true };
1690
+ }
1691
+ // Regex to match numbers with the specified integer and decimal places
1692
+ const regex = new RegExp(`^-?(0|[1-9]\\d{0,${maxIntegers - 1}})(\\.\\d{0,${maxDecimals}})?$`);
1693
+ return regex.test(control.value) ? null : { invalidAmount: true };
1694
+ };
1695
+ }
1696
+
1697
+ function dateAfterYearValidator(year) {
1698
+ return (control) => {
1699
+ if (control.value) {
1700
+ const yearInput = Number(control.value.split('/')[2]);
1701
+ if (yearInput <= year) {
1702
+ return { invalidYear: { value: control.value } };
1703
+ }
1704
+ }
1705
+ return null;
1706
+ };
1707
+ }
1708
+
1709
+ function dateBeforeValidator(targetDate) {
1710
+ return (control) => {
1711
+ const inputValue = control.value;
1712
+ if (!inputValue || !targetDate) {
1713
+ return null;
1714
+ }
1715
+ const [day, month, year] = inputValue.split('/').map(Number);
1716
+ const inputDate = new Date(year, month - 1, day);
1717
+ if (inputDate < targetDate) {
1718
+ return { dateNotBefore: { value: inputValue } };
1719
+ }
1720
+ return null;
1721
+ };
1722
+ }
1723
+
1724
+ function dateOfBirthValidator() {
1725
+ return (control) => {
1726
+ const value = control.value;
1727
+ if (value) {
1728
+ const [day, month, year] = value.split('/').map((part) => parseInt(part, 10));
1729
+ const date = new Date(year, month - 1, day);
1730
+ // Check if the date is in the past
1731
+ const today = new Date();
1732
+ // Set the time of today to the start of the day to avoid time comparison issues
1733
+ today.setHours(0, 0, 0, 0);
1734
+ if (date >= today) {
1735
+ return { invalidDateOfBirth: { value: value } };
1736
+ }
1737
+ }
1738
+ return null;
1739
+ };
1740
+ }
1741
+
1742
+ function futureDateValidator() {
1743
+ return (control) => {
1744
+ if (control.value) {
1745
+ const [day, month, year] = control.value.split('/');
1746
+ const date = new Date(Date.parse(`${month}/${day}/${year}`));
1747
+ // Check if the date is in the future
1748
+ const today = new Date();
1749
+ if (date >= today) {
1750
+ return { invalidFutureDate: { value: control.value } };
1751
+ }
1752
+ }
1753
+ return null;
1754
+ };
1755
+ }
1756
+
1757
+ function invalidValueValidator(invalidValues) {
1758
+ return (control) => {
1759
+ if (control.value === null || control.value === undefined || control.value === '') {
1760
+ return null;
1761
+ }
1762
+ return invalidValues.some((value) => value === control.value) ? { valueInArray: true } : null;
1763
+ };
1764
+ }
1765
+
1766
+ function nationalInsuranceNumberValidator() {
1767
+ return (control) => {
1768
+ const value = control.value;
1769
+ if (value) {
1770
+ // Remove all spaces and convert to uppercase for uniformity
1771
+ const cleanedValue = value.replace(/\s+/g, '').toUpperCase();
1772
+ // Check if the cleaned value has exactly 9 characters and matches the National Insurance number format
1773
+ const ninoRegex = /^[A-Z]{2}\d{6}[A-D]$/;
1774
+ if (cleanedValue.length !== 9 || !ninoRegex.test(cleanedValue)) {
1775
+ return { nationalInsuranceNumberPattern: { value: value } };
1776
+ }
1777
+ }
1778
+ return null;
1779
+ };
1780
+ }
1781
+
1782
+ function numericalTextValidator() {
1783
+ return (control) => {
1784
+ const value = control.value;
1785
+ if (value && !/^\d*$/.test(value)) {
1786
+ return { numericalTextPattern: { value: value } };
1787
+ }
1788
+ return null;
1789
+ };
1790
+ }
1791
+
1792
+ function optionalMaxLengthValidator(maxLength) {
1793
+ return (control) => {
1794
+ if (control.value) {
1795
+ return Validators.maxLength(maxLength)(control);
1796
+ }
1797
+ return null;
1798
+ };
1799
+ }
1800
+
1801
+ function optionalValidDateValidator() {
1802
+ return (control) => {
1803
+ const value = control.value;
1804
+ if (value) {
1805
+ // Check if the value matches the format dd/MM/yyyy
1806
+ const dateRegex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
1807
+ const match = value.match(dateRegex);
1808
+ if (!match) {
1809
+ return { invalidDateFormat: { value: value } };
1810
+ }
1811
+ const [, day, month, year] = match;
1812
+ // Check if the date is valid
1813
+ const date = new Date(`${year}-${month}-${day}`);
1814
+ if (date.getDate() !== parseInt(day, 10) ||
1815
+ date.getMonth() + 1 !== parseInt(month, 10) ||
1816
+ date.getFullYear() !== parseInt(year, 10)) {
1817
+ return { invalidDate: { value: value } };
1818
+ }
1819
+ }
1820
+ return null;
1821
+ };
1822
+ }
1823
+
1824
+ function optionalEmailAddressValidator() {
1825
+ const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
1826
+ return (control) => {
1827
+ if (control.value) {
1828
+ const valid = emailPattern.test(control.value);
1829
+ return valid ? null : { emailPattern: { value: control.value } };
1830
+ }
1831
+ return null;
1832
+ };
1833
+ }
1834
+
1835
+ function optionalPhoneNumberValidator() {
1836
+ const numericPattern = /^[\d\s]*$/;
1837
+ return (control) => {
1838
+ if (control.value) {
1839
+ const valueWithoutSpaces = control.value.replace(/\s+/g, '');
1840
+ const isValidPattern = numericPattern.test(control.value);
1841
+ const isValidLength = valueWithoutSpaces.length === 11;
1842
+ const valid = isValidPattern && isValidLength;
1843
+ return valid ? null : { phoneNumberPattern: { value: control.value } };
1844
+ }
1845
+ return null;
1846
+ };
1847
+ }
1848
+
1849
+ /**
1850
+ * Validates whether a date, constructed from provided form controls for day, month and year
1851
+ * is at least 18 years in the past.
1852
+ *
1853
+ * @param dayControl - Name of the control for the day portion of the date
1854
+ * @param monthControl - Name of the control for the month portion of the date
1855
+ * @param yearControl - Name of the control for the year portion of the date
1856
+ * @param dateService - An instance of DateService
1857
+ * @returns Validator function that returns null if the date is valid and the age is 18 years older,
1858
+ * or an error object within { underEighteen: true } if under 18.
1859
+ */
1860
+ const overEighteenValidator = (dayControl, monthControl, yearControl, dateService) => {
1861
+ return (group) => {
1862
+ const day = group.get(dayControl);
1863
+ const month = group.get(monthControl);
1864
+ const year = group.get(yearControl);
1865
+ // Return if controls are not defined or values are not provided
1866
+ if (!day || !month || !year || !day.value || !month.value || !year.value) {
1867
+ return null;
1868
+ }
1869
+ // Format day and month to ensure two digits
1870
+ const formattedDay = day.value.toString().padStart(2, '0');
1871
+ const formattedMonth = month.value.toString().padStart(2, '0');
1872
+ const formattedYear = year.value.toString();
1873
+ // Create the date string in the format dd/MM/yyyy
1874
+ const dateValue = `${formattedDay}/${formattedMonth}/${formattedYear}`;
1875
+ const inputDate = dateService.getFromFormat(dateValue, 'dd/MM/yyyy');
1876
+ if (inputDate.isValid) {
1877
+ // Verify if the entered date is at least 18 years in the past
1878
+ const underEighteen = inputDate.diffNow('years').years > -18;
1879
+ if (underEighteen) {
1880
+ year.setErrors({ underEighteen: true });
1881
+ return { underEighteen: true };
1882
+ }
1883
+ else {
1884
+ year.setErrors(null);
1885
+ return null;
1886
+ }
1887
+ }
1888
+ else {
1889
+ return null;
1890
+ }
1891
+ };
1892
+ };
1893
+
1894
+ function pastDateValidator() {
1895
+ const today = new Date();
1896
+ today.setHours(0, 0, 0, 0); // Set time to start of the day to avoid time comparison issues
1897
+ return (control) => {
1898
+ if (control.value) {
1899
+ const [day, month, year] = control.value.split('/');
1900
+ const date = new Date(Date.parse(`${month}/${day}/${year}`));
1901
+ // Check if the date is in the past
1902
+ if (date < today) {
1903
+ return { invalidPastDate: { value: control.value } };
1904
+ }
1905
+ }
1906
+ return null;
1907
+ };
1908
+ }
1909
+
1910
+ function specialCharactersValidator() {
1911
+ const specialCharactersPattern = /\*/;
1912
+ return (control) => {
1913
+ if (control.value) {
1914
+ const hasSpecialCharacters = specialCharactersPattern.test(control.value);
1915
+ return hasSpecialCharacters ? { specialCharactersPattern: { value: control.value } } : null;
1916
+ }
1917
+ return null;
1918
+ };
1919
+ }
1920
+
1921
+ function twoDecimalPlacesValidator() {
1922
+ return (control) => {
1923
+ const value = control.value;
1924
+ if (!value) {
1925
+ return null; // No validation if empty
1926
+ }
1927
+ // Check if the value is a valid number with up to 2 decimal places
1928
+ const decimalRegex = /^\d+(\.\d{0,2})?$/;
1929
+ return decimalRegex.test(value) ? null : { invalidDecimal: true };
1930
+ };
1931
+ }
1932
+
1933
+ function validValueValidator(validValues) {
1934
+ return (control) => {
1935
+ if (control.value === null || control.value === undefined || control.value === '') {
1936
+ return null;
1937
+ }
1938
+ return validValues.some((value) => value === control.value) ? null : { valueNotInArray: true };
1939
+ };
1940
+ }
1941
+
1942
+ /**
1943
+ * Generated bundle index. Do not edit.
1944
+ */
1945
+
1946
+ export { AccessDeniedComponent, AppInitializerService, AppInsightsService, AuthService, DateService, GOV_UI_COMPONENTS, GlobalStore, GovukButtonComponent, GovukTextInputComponent, LAUNCH_DARKLY_CHANGE_FLAGS_MOCK, LAUNCH_DARKLY_FLAGS_MOCK, LaunchDarklyService, OpalFrontendCommonModule, PermissionsService, SESSION_ENDPOINTS, SESSION_TOKEN_EXPIRY_MOCK, SESSION_USER_STATE_MOCK, SSO_ENDPOINTS, SessionService, SignInComponent, SortService, TRANSFER_STATE_APP_INSIGHTS_CONFIG_MOCK, TRANSFER_STATE_LAUNCH_DARKLY_CONFIG_MOCK, TRANSFER_STATE_MOCK, TitleResolver, TransferStateService, TransformationService, UtilsService, alphabeticalTextValidator, amountValidator, authGuard, canDeactivateGuard, dateAfterYearValidator, dateBeforeValidator, dateOfBirthValidator, futureDateValidator, getGuardWithDummyUrl, handleObservableResult, hasFlowStateGuard, httpErrorInterceptor, invalidValueValidator, nationalInsuranceNumberValidator, numericalTextValidator, optionalEmailAddressValidator, optionalMaxLengthValidator, optionalPhoneNumberValidator, optionalValidDateValidator, overEighteenValidator, pastDateValidator, routePermissionsGuard, routing, runAuthGuardWithContext, runHasFlowStateGuardWithContext, signedInGuard, specialCharactersValidator, twoDecimalPlacesValidator, userStateResolver, validValueValidator };
1947
+ //# sourceMappingURL=hmcts-opal-frontend-common.mjs.map