@dwp/govuk-casa 7.0.6 → 8.0.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +22 -17
- package/dist/{casa → assets}/css/casa-ie8.css +1 -1
- package/dist/assets/css/casa.css +1 -0
- package/dist/casa.d.ts +11 -0
- package/dist/casa.js +46 -0
- package/dist/lib/CasaTemplateLoader.d.ts +29 -0
- package/dist/lib/CasaTemplateLoader.js +74 -0
- package/dist/lib/JourneyContext.d.ts +297 -0
- package/dist/lib/JourneyContext.js +581 -0
- package/dist/lib/MutableRouter.d.ts +155 -0
- package/dist/lib/MutableRouter.js +277 -0
- package/dist/lib/Plan.d.ts +154 -0
- package/dist/lib/Plan.js +442 -0
- package/dist/lib/ValidationError.d.ts +74 -0
- package/dist/lib/ValidationError.js +159 -0
- package/dist/lib/ValidatorFactory.d.ts +83 -0
- package/dist/lib/ValidatorFactory.js +106 -0
- package/dist/lib/configuration-ingestor.d.ts +262 -0
- package/dist/lib/configuration-ingestor.js +490 -0
- package/dist/lib/configure.d.ts +90 -0
- package/dist/lib/configure.js +192 -0
- package/dist/lib/dirname.cjs +1 -0
- package/dist/lib/dirname.d.cts +2 -0
- package/dist/lib/end-session.d.ts +13 -0
- package/dist/lib/end-session.js +43 -0
- package/dist/lib/field.d.ts +77 -0
- package/dist/lib/field.js +255 -0
- package/dist/lib/index.d.ts +14 -0
- package/dist/lib/index.js +54 -0
- package/dist/lib/logger.d.ts +9 -0
- package/dist/lib/logger.js +18 -0
- package/dist/lib/nunjucks-filters.d.ts +26 -0
- package/dist/lib/nunjucks-filters.js +90 -0
- package/dist/lib/nunjucks.d.ts +23 -0
- package/dist/lib/nunjucks.js +49 -0
- package/dist/lib/utils.d.ts +48 -0
- package/dist/lib/utils.js +111 -0
- package/dist/lib/validators/dateObject.d.ts +4 -0
- package/dist/lib/validators/dateObject.js +135 -0
- package/dist/lib/validators/email.d.ts +4 -0
- package/dist/lib/validators/email.js +46 -0
- package/dist/lib/validators/inArray.d.ts +4 -0
- package/dist/lib/validators/inArray.js +60 -0
- package/dist/lib/validators/index.d.ts +21 -0
- package/dist/lib/validators/index.js +47 -0
- package/dist/lib/validators/nino.d.ts +4 -0
- package/dist/lib/validators/nino.js +46 -0
- package/dist/lib/validators/postalAddressObject.d.ts +4 -0
- package/dist/lib/validators/postalAddressObject.js +123 -0
- package/dist/lib/validators/regex.d.ts +4 -0
- package/dist/lib/validators/regex.js +40 -0
- package/dist/lib/validators/required.d.ts +4 -0
- package/dist/lib/validators/required.js +56 -0
- package/dist/lib/validators/strlen.d.ts +4 -0
- package/dist/lib/validators/strlen.js +51 -0
- package/dist/lib/validators/wordCount.d.ts +5 -0
- package/dist/lib/validators/wordCount.js +54 -0
- package/dist/lib/waypoint-url.d.ts +23 -0
- package/dist/lib/waypoint-url.js +52 -0
- package/dist/middleware/body-parser.d.ts +1 -0
- package/dist/middleware/body-parser.js +24 -0
- package/dist/middleware/csrf.d.ts +1 -0
- package/dist/middleware/csrf.js +31 -0
- package/dist/middleware/data.d.ts +5 -0
- package/dist/middleware/data.js +53 -0
- package/dist/middleware/dirname.cjs +1 -0
- package/dist/middleware/dirname.d.cts +2 -0
- package/dist/middleware/gather-fields.d.ts +6 -0
- package/dist/middleware/gather-fields.js +48 -0
- package/dist/middleware/i18n.d.ts +4 -0
- package/dist/middleware/i18n.js +88 -0
- package/dist/middleware/post.d.ts +3 -0
- package/dist/middleware/post.js +57 -0
- package/dist/middleware/pre.d.ts +3 -0
- package/dist/middleware/pre.js +51 -0
- package/dist/middleware/progress-journey.d.ts +6 -0
- package/dist/middleware/progress-journey.js +80 -0
- package/dist/middleware/sanitise-fields.d.ts +5 -0
- package/dist/middleware/sanitise-fields.js +53 -0
- package/dist/middleware/session.d.ts +11 -0
- package/dist/middleware/session.js +121 -0
- package/dist/middleware/skip-waypoint.d.ts +5 -0
- package/dist/middleware/skip-waypoint.js +43 -0
- package/dist/middleware/steer-journey.d.ts +7 -0
- package/dist/middleware/steer-journey.js +62 -0
- package/dist/middleware/validate-fields.d.ts +7 -0
- package/dist/middleware/validate-fields.js +67 -0
- package/dist/mjs/esm-wrapper.js +11 -0
- package/dist/mjs/package.json +3 -0
- package/dist/package.json +3 -0
- package/dist/routes/ancillary.d.ts +11 -0
- package/dist/routes/ancillary.js +27 -0
- package/dist/routes/dirname.cjs +1 -0
- package/dist/routes/dirname.d.cts +2 -0
- package/dist/routes/journey.d.ts +8 -0
- package/dist/routes/journey.js +127 -0
- package/dist/routes/static.d.ts +26 -0
- package/dist/routes/static.js +68 -0
- package/package.json +64 -89
- package/views/casa/components/checkboxes/template.njk +4 -1
- package/views/casa/components/date-input/template.njk +3 -3
- package/views/casa/components/journey-form/README.md +3 -1
- package/views/casa/components/journey-form/template.njk +1 -1
- package/views/casa/components/postal-address-object/template.njk +5 -5
- package/views/casa/components/radios/template.njk +1 -1
- package/views/casa/errors/static.njk +11 -0
- package/views/casa/layouts/journey.njk +26 -9
- package/views/casa/layouts/main.njk +7 -20
- package/views/casa/partials/scripts.njk +8 -3
- package/views/casa/partials/styles.njk +2 -2
- package/casa.js +0 -208
- package/definitions/review-page.js +0 -60
- package/dist/casa/css/casa.css +0 -1
- package/dist/casa/js/casa.js +0 -1
- package/index.d.ts +0 -121
- package/lib/ConfigIngestor.js +0 -588
- package/lib/GatherModifier.js +0 -14
- package/lib/I18n.js +0 -160
- package/lib/JourneyContext.d.ts +0 -97
- package/lib/JourneyContext.js +0 -552
- package/lib/JourneyMap.js +0 -233
- package/lib/JourneyRoad.js +0 -330
- package/lib/Logger.js +0 -59
- package/lib/PageDictionary.d.ts +0 -11
- package/lib/PageDirectory.js +0 -77
- package/lib/Plan.js +0 -423
- package/lib/RoadConverter.js +0 -153
- package/lib/UserJourney.js +0 -8
- package/lib/Util.js +0 -227
- package/lib/Validation.js +0 -20
- package/lib/bootstrap/end-session.js +0 -44
- package/lib/bootstrap/load-definitions.js +0 -64
- package/lib/commonBodyParser.js +0 -15
- package/lib/enums.js +0 -6
- package/lib/gather-modifiers/index.js +0 -7
- package/lib/gather-modifiers/trimPostalAddressObject.js +0 -75
- package/lib/gather-modifiers/trimWhitespace.js +0 -16
- package/lib/utils/createGetRequest.d.ts +0 -5
- package/lib/utils/createGetRequest.js +0 -59
- package/lib/utils/index.js +0 -11
- package/lib/utils/parseRequest.d.ts +0 -5
- package/lib/utils/parseRequest.js +0 -72
- package/lib/utils/sanitise.js +0 -74
- package/lib/utils/validate.js +0 -32
- package/lib/validation/ArrayObjectField.js +0 -49
- package/lib/validation/ObjectField.js +0 -53
- package/lib/validation/SimpleField.d.ts +0 -11
- package/lib/validation/SimpleField.js +0 -46
- package/lib/validation/ValidationError.d.ts +0 -14
- package/lib/validation/ValidationError.js +0 -170
- package/lib/validation/ValidatorFactory.d.ts +0 -32
- package/lib/validation/ValidatorFactory.js +0 -91
- package/lib/validation/index.js +0 -22
- package/lib/validation/processor/flattenErrorArray.js +0 -24
- package/lib/validation/processor/queue.js +0 -214
- package/lib/validation/processor.js +0 -84
- package/lib/validation/rules/README.md +0 -3
- package/lib/validation/rules/ValidationRules.d.ts +0 -22
- package/lib/validation/rules/dateObject.js +0 -156
- package/lib/validation/rules/email.js +0 -44
- package/lib/validation/rules/inArray.js +0 -61
- package/lib/validation/rules/index.js +0 -23
- package/lib/validation/rules/nino.js +0 -48
- package/lib/validation/rules/optional.js +0 -14
- package/lib/validation/rules/postalAddressObject.js +0 -142
- package/lib/validation/rules/regex.js +0 -39
- package/lib/validation/rules/required.js +0 -57
- package/lib/validation/rules/strlen.js +0 -57
- package/lib/validation/rules/wordCount.js +0 -61
- package/lib/view-filters/formatDateObject.js +0 -35
- package/lib/view-filters/includes.js +0 -10
- package/lib/view-filters/index.js +0 -23
- package/lib/view-filters/mergeObjectsDeep.js +0 -21
- package/lib/view-filters/renderAsAttributes.js +0 -33
- package/middleware/errors/404.js +0 -12
- package/middleware/errors/catch-all.js +0 -27
- package/middleware/errors/index.js +0 -9
- package/middleware/headers/config-defaults.js +0 -57
- package/middleware/headers/headers.js +0 -40
- package/middleware/headers/index.js +0 -9
- package/middleware/i18n/i18n.js +0 -56
- package/middleware/i18n/index.js +0 -16
- package/middleware/index.js +0 -55
- package/middleware/mount/index.js +0 -9
- package/middleware/mount/mount.js +0 -10
- package/middleware/nunjucks/environment.js +0 -57
- package/middleware/nunjucks/index.js +0 -8
- package/middleware/page/csrf.js +0 -37
- package/middleware/page/edit-mode.js +0 -52
- package/middleware/page/gather.js +0 -75
- package/middleware/page/index.js +0 -103
- package/middleware/page/journey-continue.js +0 -157
- package/middleware/page/journey-rails.js +0 -102
- package/middleware/page/prepare-request.js +0 -77
- package/middleware/page/render.js +0 -75
- package/middleware/page/skip.js +0 -72
- package/middleware/page/utils.js +0 -206
- package/middleware/page/validate.js +0 -67
- package/middleware/session/expiry.js +0 -95
- package/middleware/session/genid.js +0 -18
- package/middleware/session/index.js +0 -18
- package/middleware/session/init.js +0 -25
- package/middleware/session/seed.js +0 -50
- package/middleware/session/timeout.js +0 -5
- package/middleware/static/asset-versions.js +0 -23
- package/middleware/static/index.js +0 -104
- package/middleware/static/prepare-assets.js +0 -51
- package/middleware/static/serve-assets.js +0 -58
- package/middleware/variables/index.js +0 -12
- package/middleware/variables/variables.js +0 -35
- package/src/browserconfig.xml +0 -5
- package/src/js/casa.js +0 -132
- package/src/scss/_casaElements.scss +0 -11
- package/src/scss/_casaGovukTemplateJinjaPolyfill.scss +0 -39
- package/src/scss/_casaMountUrl.scss +0 -8
- package/src/scss/casa-ie8.scss +0 -3
- package/src/scss/casa.scss +0 -14
- package/test/unit/templates/README.md +0 -5
- package/test/utils/BaseTestWaypoint.js +0 -106
- package/test/utils/concatWaypoints.js +0 -26
- package/test/utils/index.js +0 -6
- package/test/utils/testTraversal.js +0 -90
- package/views/casa/partials/cookie_message.njk +0 -3
- package/views/casa/partials/phase_banner_alpha.njk +0 -8
- package/views/casa/partials/phase_banner_beta.njk +0 -8
- package/views/casa/review/page-block.njk +0 -8
- package/views/casa/review/review.njk +0 -47
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
namePrefix: '',
|
|
22
22
|
attributes: mergedAttributes,
|
|
23
23
|
items: [
|
|
24
|
-
|
|
24
|
+
mergeObjects({
|
|
25
25
|
label: t('macros:dateInput.day'),
|
|
26
26
|
classes: 'govuk-input--width-2 ' + (inputErrorClass if includes(fieldErrors[0].focusSuffix, '[dd]') or not hasSuffixHighlights)
|
|
27
27
|
}, params.items[0] if params.items[0] else {}, {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
name: params.namePrefix + '[dd]',
|
|
30
30
|
value: params.casaValue.dd
|
|
31
31
|
}),
|
|
32
|
-
|
|
32
|
+
mergeObjects({
|
|
33
33
|
label: t('macros:dateInput.month'),
|
|
34
34
|
classes: 'govuk-input--width-2 ' + (inputErrorClass if includes(fieldErrors[0].focusSuffix, '[mm]') or not hasSuffixHighlights)
|
|
35
35
|
}, params.items[1] if params.items[1] else {}, {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
name: params.namePrefix + '[mm]',
|
|
38
38
|
value: params.casaValue.mm
|
|
39
39
|
}),
|
|
40
|
-
|
|
40
|
+
mergeObjects({
|
|
41
41
|
label: t('macros:dateInput.year'),
|
|
42
42
|
classes: 'govuk-input--width-4 ' + (inputErrorClass if includes(fieldErrors[0].focusSuffix, '[yyyy]') or not hasSuffixHighlights)
|
|
43
43
|
}, params.items[2] if params.items[2] else {}, {
|
|
@@ -10,6 +10,7 @@ A "Continue" button (and "Cancel" link if in edit mode) will also be added.
|
|
|
10
10
|
{% from "casa/components/journey-form/macro.njk" import casaJourneyForm with context %}
|
|
11
11
|
|
|
12
12
|
{% call casaJourneyForm({
|
|
13
|
+
formUrl: '/form/url',
|
|
13
14
|
csrfToken: casa.csrfToken,
|
|
14
15
|
inEditMode: true,
|
|
15
16
|
editOriginUrl: '/url/to/review/page',
|
|
@@ -23,7 +24,7 @@ A "Continue" button (and "Cancel" link if in edit mode) will also be added.
|
|
|
23
24
|
Which will render something like this:
|
|
24
25
|
|
|
25
26
|
```html
|
|
26
|
-
<form action="
|
|
27
|
+
<form action="/form/url" method="post" autocomplete="off" novalidate class="casa-journey-form">
|
|
27
28
|
<input type="hidden" name="_csrf" value="..." />
|
|
28
29
|
<input type="hidden" name="edit" value="true" />
|
|
29
30
|
<input type="hidden" name="editorigin" value="/url/to/review/page" />
|
|
@@ -47,6 +48,7 @@ Note that the submit button is configured to prevent double-clicks and avoid dup
|
|
|
47
48
|
|
|
48
49
|
| Name | Type | Required | Description |
|
|
49
50
|
|------|------|----------|-------------|
|
|
51
|
+
| `formUrl` | string | Yes | The form's "action", available in a `formUrl` template variable |
|
|
50
52
|
| `csrfToken` | string | Yes | Token used to protect form from CSRF (available to user's templates via the global `casa.csrfToken` variable) |
|
|
51
53
|
| `inEditMode` | boolean | No | Toggle edit-mode of the form (available to page templates using default GET/POST handlers via the local `inEditMode` variable) |
|
|
52
54
|
| `editOriginUrl` | string | No | Absolute URL to the page from which the edit request came (defaults to `review`) (available to user's templates using default GET/POST handlers via the local `editOriginUrl` variable) |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{% from "govuk/components/button/macro.njk" import govukButton %}
|
|
2
2
|
|
|
3
|
-
<form action="
|
|
3
|
+
<form action="{{ params.formUrl }}" method="post" autocomplete="off" novalidate class="casa-journey-form">
|
|
4
4
|
<input type="hidden" name="_csrf" value="{{ params.csrfToken }}" />
|
|
5
5
|
{% if params.inEditMode %}<input type="hidden" name="edit" value="true" />{% endif %}
|
|
6
6
|
{% if params.inEditMode and params.editOriginUrl %}<input type="hidden" name="editorigin" value="{{ params.editOriginUrl }}" />{% endif %}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
{% if fieldAddress1Errors %}
|
|
15
15
|
{% set fieldAttributes = mergeObjects(fieldAttributes, {'data-validation': {fn: params.name + '[address1]', va: fieldAddress1Errors[0].validator} | dump}) %}
|
|
16
16
|
{% endif %}
|
|
17
|
-
{{ govukInput(
|
|
17
|
+
{{ govukInput(mergeObjects({
|
|
18
18
|
label: {
|
|
19
19
|
html: t('macros:postalAddressObject.address1')
|
|
20
20
|
},
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
{% if fieldAddress2Errors %}
|
|
34
34
|
{% set fieldAttributes = mergeObjects(fieldAttributes, {'data-validation': {fn: params.name + '[address2]', va: fieldAddress2Errors[0].validator} | dump}) %}
|
|
35
35
|
{% endif %}
|
|
36
|
-
{{ govukInput(
|
|
36
|
+
{{ govukInput(mergeObjects({
|
|
37
37
|
label: {
|
|
38
38
|
html: t('macros:postalAddressObject.address2')
|
|
39
39
|
},
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
{% if fieldErrors %}
|
|
55
55
|
{% set fieldAttributes = mergeObjects(fieldAttributes, {'data-validation': {fn: params.name + '[address3]', va: fieldErrors[0].validator} | dump}) %}
|
|
56
56
|
{% endif %}
|
|
57
|
-
{{ govukInput(
|
|
57
|
+
{{ govukInput(mergeObjects({
|
|
58
58
|
classes: "govuk-!-width-two-thirds",
|
|
59
59
|
label: {
|
|
60
60
|
html: t('macros:postalAddressObject.address3')
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
{% if fieldErrors %}
|
|
76
76
|
{% set fieldAttributes = mergeObjects(fieldAttributes, {'data-validation': {fn: params.name + '[address4]', va: fieldErrors[0].validator} | dump}) %}
|
|
77
77
|
{% endif %}
|
|
78
|
-
{{ govukInput(
|
|
78
|
+
{{ govukInput(mergeObjects({
|
|
79
79
|
classes: "govuk-!-width-two-thirds",
|
|
80
80
|
label: {
|
|
81
81
|
html: t('macros:postalAddressObject.address4')
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
{% if fieldErrors %}
|
|
97
97
|
{% set fieldAttributes = mergeObjects(fieldAttributes, {'data-validation': {fn: params.name + '[postcode]', va: fieldErrors[0].validator} | dump}) %}
|
|
98
98
|
{% endif %}
|
|
99
|
-
{{ govukInput(
|
|
99
|
+
{{ govukInput(mergeObjects({
|
|
100
100
|
classes: "govuk-input--width-10",
|
|
101
101
|
label: {
|
|
102
102
|
html: t('macros:postalAddressObject.postcode')
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
|
|
37
37
|
{# Ensure that the first item has the id matching `f-<name>` in order for error summary linkage to work #}
|
|
38
38
|
{% if not mergedParams.items[0].id %}
|
|
39
|
-
{% set mergedParams =
|
|
39
|
+
{% set mergedParams = mergeObjects(mergedParams, {
|
|
40
40
|
items: [{
|
|
41
41
|
id: 'f-' + params.name
|
|
42
42
|
}]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{% extends "casa/layouts/main.njk" %}
|
|
2
|
+
|
|
3
|
+
{% block pageTitle %}
|
|
4
|
+
Sorry, there is a problem with the service
|
|
5
|
+
{% endblock %}
|
|
6
|
+
|
|
7
|
+
{% block content %}
|
|
8
|
+
<h1 class="govuk-heading-xl">Sorry, there is a problem with the service</h1>
|
|
9
|
+
|
|
10
|
+
<p class="govuk-body">Try again in a few moments.</p>
|
|
11
|
+
{% endblock %}
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
{% extends "casa/layouts/main.njk" %}
|
|
2
2
|
|
|
3
3
|
{% from "govuk/components/back-link/macro.njk" import govukBackLink %}
|
|
4
|
+
{% from "govuk/components/error-summary/macro.njk" import govukErrorSummary %}
|
|
5
|
+
{% from "casa/components/journey-form/macro.njk" import casaJourneyForm with context %}
|
|
6
|
+
|
|
4
7
|
|
|
5
8
|
{# Automatically apply padding with/without back link #}
|
|
6
9
|
{% set mainClasses %}{{ mainClasses }} govuk-main-wrapper--auto-spacing{% endset %}
|
|
7
10
|
|
|
8
11
|
|
|
12
|
+
{# Add back link, if appropriate #}
|
|
9
13
|
{% block beforeContent %}
|
|
10
|
-
{# Phase banner #}
|
|
11
|
-
{# TODO: remove phase variable - just get template author to override a `casa/partials/phase_banner.njk` template #}
|
|
12
|
-
{% if casa.phase == 'alpha' %}
|
|
13
|
-
{% include "casa/partials/phase_banner_alpha.njk" %}
|
|
14
|
-
{% elseif casa.phase == 'beta' %}
|
|
15
|
-
{% include "casa/partials/phase_banner_beta.njk" %}
|
|
16
|
-
{% endif %}
|
|
17
|
-
|
|
18
|
-
{# Add back link, if appropriate #}
|
|
19
14
|
{% if not inEditMode and casa.journeyPreviousUrl %}
|
|
20
15
|
{{ govukBackLink({
|
|
21
16
|
text: t('common:back'),
|
|
@@ -30,3 +25,25 @@
|
|
|
30
25
|
{{- t("error:documentTtlePrefix") if formErrors -}}
|
|
31
26
|
{% block casaPageTitle %}{% endblock %}
|
|
32
27
|
{%- endblock %}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
{# A default content block. Override this if you want a customised form #}
|
|
31
|
+
{% block content %}
|
|
32
|
+
{% if formErrorsGovukArray %}
|
|
33
|
+
{{ govukErrorSummary({
|
|
34
|
+
titleText: t("error:summary.h1"),
|
|
35
|
+
descriptionText: errorDescription or t('error:summary.defaultDescription'),
|
|
36
|
+
errorList: formErrorsGovukArray
|
|
37
|
+
}) }}
|
|
38
|
+
{% endif %}
|
|
39
|
+
|
|
40
|
+
{% call casaJourneyForm({
|
|
41
|
+
formUrl: formUrl,
|
|
42
|
+
csrfToken: casa.csrfToken,
|
|
43
|
+
inEditMode: inEditMode,
|
|
44
|
+
editOriginUrl: editOriginUrl,
|
|
45
|
+
activeContextId: activeContextId
|
|
46
|
+
}) %}
|
|
47
|
+
{% block journey_form %}{% endblock %}
|
|
48
|
+
{% endcall %}
|
|
49
|
+
{% endblock %}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
{% extends "govuk/template.njk" %}
|
|
2
2
|
|
|
3
|
-
{% set assetPath = govuk.assetPath %}
|
|
4
|
-
|
|
5
3
|
|
|
6
4
|
{% block head %}
|
|
7
5
|
{% include "casa/partials/styles.njk" %}
|
|
@@ -12,29 +10,18 @@
|
|
|
12
10
|
{# Harcoding content for the skip link as t() may not be availble on some error pages #}
|
|
13
11
|
{{ govukSkipLink({
|
|
14
12
|
href: '#main-content',
|
|
15
|
-
text:
|
|
13
|
+
text: "Neidio i'r prif gynnwys" if locale === 'cy' else 'Skip to main content'
|
|
16
14
|
}) }}
|
|
17
15
|
{% endblock %}
|
|
18
16
|
|
|
19
17
|
|
|
20
|
-
{% block bodyStart %}
|
|
21
|
-
<div id="global-cookie-message" class="js-hidden">
|
|
22
|
-
{% include "casa/partials/cookie_message.njk" %}
|
|
23
|
-
</div>
|
|
24
|
-
{% endblock %}
|
|
25
|
-
|
|
26
|
-
|
|
27
18
|
{% block header %}
|
|
28
|
-
{{ govukHeader(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
{% include "casa/partials/phase_banner_alpha.njk" %}
|
|
35
|
-
{% elseif casa.phase == 'beta' %}
|
|
36
|
-
{% include "casa/partials/phase_banner_beta.njk" %}
|
|
37
|
-
{% endif %}
|
|
19
|
+
{{ govukHeader({
|
|
20
|
+
assetsPath: assetPath + "/images",
|
|
21
|
+
serviceName: t('common:serviceName') if t else '',
|
|
22
|
+
serviceUrl: casa.mountUrl,
|
|
23
|
+
homepageUrl: "https://www.gov.uk/"
|
|
24
|
+
}) }}
|
|
38
25
|
{% endblock %}
|
|
39
26
|
|
|
40
27
|
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
<!-- CASA -->
|
|
2
|
-
<script src="{{ casa.mountUrl }}govuk/
|
|
3
|
-
<script
|
|
4
|
-
|
|
2
|
+
<script src="{{ casa.mountUrl }}govuk/assets/js/all.js?{{ casaVersion }}"></script>
|
|
3
|
+
<script nonce="{{ cspNonce }}">
|
|
4
|
+
window.GOVUKFrontend.initAll();
|
|
5
|
+
if (window.history.replaceState) {
|
|
6
|
+
// Prevent re-submission of POST on refreshing page
|
|
7
|
+
window.history.replaceState(null, null, window.location.href);
|
|
8
|
+
};
|
|
9
|
+
</script>
|
|
5
10
|
<!-- /CASA -->
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!-- CASA -->
|
|
2
|
-
<!--[if gt IE 8]><!--><link href="{{ casa.mountUrl }}
|
|
2
|
+
<!--[if gt IE 8]><!--><link href="{{ casa.mountUrl }}casa/assets/css/casa.css?{{ casaVersion }}" rel="stylesheet" /><!--<![endif]-->
|
|
3
3
|
<!--[if lte IE 8]>
|
|
4
|
-
<link href="{{ casa.mountUrl }}
|
|
4
|
+
<link href="{{ casa.mountUrl }}casa/assets/css/casa-ie8.css?{{ casaVersion }}" rel="stylesheet" />
|
|
5
5
|
<![endif]-->
|
|
6
6
|
<!-- /CASA -->
|
package/casa.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CASA configuration entry point.
|
|
3
|
-
*
|
|
4
|
-
* Once your CASA app instance is created, you must attach your own project
|
|
5
|
-
* route handlers to the Express router generated by CASA; available in the
|
|
6
|
-
* `.router` property of the returned CASA app instance.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const util = require('util');
|
|
10
|
-
|
|
11
|
-
// Globals
|
|
12
|
-
// @deprecated
|
|
13
|
-
global.GOVUK_CASA_DIR = __dirname;
|
|
14
|
-
|
|
15
|
-
// Deps
|
|
16
|
-
const expressJs = require('express');
|
|
17
|
-
const favicon = require('serve-favicon');
|
|
18
|
-
const path = require('path');
|
|
19
|
-
const nutil = require('util');
|
|
20
|
-
|
|
21
|
-
const logger = require('./lib/Logger.js')('boot');
|
|
22
|
-
const I18n = require('./lib/I18n.js');
|
|
23
|
-
const { ingest } = require('./lib/ConfigIngestor.js');
|
|
24
|
-
const Util = require('./lib/Util.js');
|
|
25
|
-
|
|
26
|
-
const endSession = require('./lib/bootstrap/end-session.js');
|
|
27
|
-
const loadDefinitionsConstructor = require('./lib/bootstrap/load-definitions.js');
|
|
28
|
-
|
|
29
|
-
const mwCsrfProtection = require('./middleware/page/csrf.js');
|
|
30
|
-
const mwHeaders = require('./middleware/headers/index.js');
|
|
31
|
-
const mwI18n = require('./middleware/i18n/index.js');
|
|
32
|
-
const mwMount = require('./middleware/mount/index.js');
|
|
33
|
-
const mwNunjucks = require('./middleware/nunjucks/index.js');
|
|
34
|
-
const mwSession = require('./middleware/session/index.js');
|
|
35
|
-
const mwStatic = require('./middleware/static/index.js');
|
|
36
|
-
const mwVariables = require('./middleware/variables/index.js');
|
|
37
|
-
|
|
38
|
-
// Ingest config
|
|
39
|
-
function ingestConfig(config) {
|
|
40
|
-
try {
|
|
41
|
-
const validatedConfig = ingest(config);
|
|
42
|
-
const jsonConfig = JSON.stringify(validatedConfig, (k, v) => (['store', 'secret'].indexOf(k) > -1 ? '[NOT PARSED]' : v));
|
|
43
|
-
logger.info('Parsed config: %s', jsonConfig);
|
|
44
|
-
return validatedConfig;
|
|
45
|
-
} catch (ex) {
|
|
46
|
-
throw new Error(nutil.format('[CONFIG ERROR] %s', ex.message));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Make an I18nUtility instance
|
|
51
|
-
function i18nFactory(dirs = [], locales = []) {
|
|
52
|
-
const localeDirs = [
|
|
53
|
-
path.resolve(__dirname, './locales'),
|
|
54
|
-
...dirs,
|
|
55
|
-
];
|
|
56
|
-
return I18n(localeDirs, locales);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Mount all the required CASA middleware
|
|
60
|
-
function mountCasaMiddleware(app, config, i18nUtility) {
|
|
61
|
-
const staticModulePaths = {
|
|
62
|
-
govukFrontend: Util.resolveModulePath('govuk-frontend', module.paths),
|
|
63
|
-
govukTemplateJinja: Util.resolveModulePath('govuk_template_jinja', module.paths),
|
|
64
|
-
govukCasa: __dirname,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// Serve default, implicit favicon
|
|
68
|
-
app.use(config.proxyMountUrl, favicon(require.resolve('govuk-frontend/govuk/assets/images/favicon.ico')));
|
|
69
|
-
|
|
70
|
-
mwHeaders(app, config.csp, config.headers.disabled);
|
|
71
|
-
mwMount(app, config.mountUrl);
|
|
72
|
-
mwStatic({
|
|
73
|
-
app,
|
|
74
|
-
mountUrl: config.mountUrl,
|
|
75
|
-
proxyMountUrl: config.proxyMountUrl,
|
|
76
|
-
compiledAssetsDir: config.compiledAssetsDir,
|
|
77
|
-
npmPackages: staticModulePaths,
|
|
78
|
-
});
|
|
79
|
-
mwNunjucks(app, config.views.dirs, staticModulePaths.govukFrontend);
|
|
80
|
-
mwSession(
|
|
81
|
-
app,
|
|
82
|
-
config.mountUrl,
|
|
83
|
-
config.sessionExpiryController,
|
|
84
|
-
{
|
|
85
|
-
secure: config.sessions.secure,
|
|
86
|
-
store: config.sessions.store,
|
|
87
|
-
name: config.sessions.name,
|
|
88
|
-
secret: config.sessions.secret,
|
|
89
|
-
cookiePath: config.sessions.cookiePath,
|
|
90
|
-
cookieSameSite: config.sessions.cookieSameSite,
|
|
91
|
-
ttl: config.sessions.ttl,
|
|
92
|
-
},
|
|
93
|
-
);
|
|
94
|
-
mwI18n(app, config.i18n.locales, i18nUtility);
|
|
95
|
-
mwVariables(app, config.mountUrl, config.phase, config.serviceName);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Prepare an Express app to run as a CASA application.
|
|
100
|
-
*
|
|
101
|
-
* @param {express} expressApp The ExpressJS app to decorate.
|
|
102
|
-
* @param {object} config CASA configuration.
|
|
103
|
-
* @returns {object} CASA assets.
|
|
104
|
-
*/
|
|
105
|
-
function CasaBootstrap(expressApp, config) {
|
|
106
|
-
// Create a Router instance on which some CASA middleware will be mounted
|
|
107
|
-
const expressRouter = expressJs.Router();
|
|
108
|
-
|
|
109
|
-
// Ingest config
|
|
110
|
-
const validatedConfig = ingestConfig(config);
|
|
111
|
-
|
|
112
|
-
// Create a configured I18n utility instance
|
|
113
|
-
const i18nUtility = i18nFactory(validatedConfig.i18n.dirs, validatedConfig.i18n.locales);
|
|
114
|
-
|
|
115
|
-
// Prepare a `casa` namespace on both the request and response `locals`
|
|
116
|
-
// objects, which will house various variables, accumulated through middleware.
|
|
117
|
-
expressApp.use((req, res, next) => {
|
|
118
|
-
req.casa = Object.create(null);
|
|
119
|
-
res.locals.casa = Object.create(null);
|
|
120
|
-
next();
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// Mount all CASA pre-journey middleware, allowing `mountController` - if
|
|
124
|
-
// specified - to control the mounting order
|
|
125
|
-
const mountCallback = mountCasaMiddleware.bind(null, expressApp, validatedConfig, i18nUtility);
|
|
126
|
-
if (typeof validatedConfig.mountController === 'function') {
|
|
127
|
-
validatedConfig.mountController.call({ expressApp, expressRouter }, mountCallback);
|
|
128
|
-
} else {
|
|
129
|
-
mountCallback();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Mount the router onto the path defined in `proxyMountUrl`.
|
|
133
|
-
// This must be done after all CASA middleware has been mounted.
|
|
134
|
-
expressApp.use(validatedConfig.proxyMountUrl, expressRouter);
|
|
135
|
-
logger.info('Routes mounted onto %s', validatedConfig.proxyMountUrl);
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
config: validatedConfig,
|
|
139
|
-
router: expressRouter,
|
|
140
|
-
loadDefinitions: loadDefinitionsConstructor(expressApp, expressRouter, validatedConfig),
|
|
141
|
-
csrfMiddleware: mwCsrfProtection,
|
|
142
|
-
endSession,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/* eslint-disable global-require */
|
|
147
|
-
const modules = {
|
|
148
|
-
// Bootstrap
|
|
149
|
-
configure: CasaBootstrap,
|
|
150
|
-
ConfigIngestor: require('./lib/ConfigIngestor.js'),
|
|
151
|
-
middleware: require('./middleware/index.js'),
|
|
152
|
-
endSession: require('./lib/bootstrap/end-session.js'),
|
|
153
|
-
|
|
154
|
-
// Page meta
|
|
155
|
-
gatherModifiers: require('./lib/gather-modifiers/index.js'),
|
|
156
|
-
PageDirectory: require('./lib/PageDirectory.js'),
|
|
157
|
-
|
|
158
|
-
// Validation
|
|
159
|
-
validationRules: require('./lib/validation/rules/index.js'),
|
|
160
|
-
validationProcessor: require('./lib/validation/processor.js'),
|
|
161
|
-
arrayObjectFieldValidation: require('./lib/validation/ArrayObjectField.js'),
|
|
162
|
-
objectFieldValidation: require('./lib/validation/ObjectField.js'),
|
|
163
|
-
simpleFieldValidation: require('./lib/validation/SimpleField.js'),
|
|
164
|
-
ValidationError: require('./lib/validation/ValidationError.js'),
|
|
165
|
-
ValidatorFactory: require('./lib/validation/ValidatorFactory.js'),
|
|
166
|
-
|
|
167
|
-
// User journey elements
|
|
168
|
-
Plan: require('./lib/Plan.js'),
|
|
169
|
-
JourneyContext: require('./lib/JourneyContext.js'),
|
|
170
|
-
|
|
171
|
-
// Utilities
|
|
172
|
-
utils: require('./lib/utils/index.js'),
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// Add test utilities
|
|
176
|
-
// Here we're using lazy-loading as the test utils will only be needed during
|
|
177
|
-
// development/build rather than runtime.
|
|
178
|
-
Object.defineProperty(modules, 'testutils', {
|
|
179
|
-
get: () => (require('./test/utils/index.js')),
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
module.exports = modules;
|
|
183
|
-
|
|
184
|
-
/* -------------------------------------------------------- Deprecated assets */
|
|
185
|
-
|
|
186
|
-
const JourneyMapDeprecated = require('./lib/JourneyMap.js');
|
|
187
|
-
const JourneyRoadDeprecated = require('./lib/JourneyRoad.js');
|
|
188
|
-
|
|
189
|
-
module.exports.JourneyData = function JourneyData(...args) {
|
|
190
|
-
return util.deprecate(
|
|
191
|
-
() => new module.exports.JourneyContext(...args),
|
|
192
|
-
'JourneyData is deprecated. Use JourneyContext instead.',
|
|
193
|
-
)();
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
module.exports.JourneyRoad = function JourneyRoad(...args) {
|
|
197
|
-
return util.deprecate(
|
|
198
|
-
() => new JourneyRoadDeprecated(...args),
|
|
199
|
-
'JourneyRoad is deprecated. Use Plan for building user journey plans instead.',
|
|
200
|
-
)();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
module.exports.JourneyMap = function JourneyMap(...args) {
|
|
204
|
-
return util.deprecate(
|
|
205
|
-
() => new JourneyMapDeprecated(...args),
|
|
206
|
-
'JourneyMap is deprecated. Use Plan for building user journey plans instead.',
|
|
207
|
-
)();
|
|
208
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Definition for the built-in 'review' page in CASA.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const JourneyContext = require('../lib/JourneyContext.js');
|
|
6
|
-
const { rules, SimpleField } = require('../lib/validation/index.js');
|
|
7
|
-
const { createGetRequest } = require('../lib/utils/index.js');
|
|
8
|
-
|
|
9
|
-
module.exports = function reviewPageDefinition(pagesMeta = {}) {
|
|
10
|
-
return {
|
|
11
|
-
view: 'casa/review/review.njk',
|
|
12
|
-
fieldValidators: {
|
|
13
|
-
reviewed: SimpleField([
|
|
14
|
-
rules.required,
|
|
15
|
-
]),
|
|
16
|
-
},
|
|
17
|
-
hooks: {
|
|
18
|
-
prerender(req, res, next) {
|
|
19
|
-
req.casa = req.casa || Object.create(null);
|
|
20
|
-
|
|
21
|
-
// Determine active journey in order to define the "edit origin" URL,
|
|
22
|
-
// and make journey data and errors available to templates
|
|
23
|
-
const userJourney = req.casa.plan;
|
|
24
|
-
const { journeyOrigin } = req.casa;
|
|
25
|
-
res.locals.changeUrlPrefix = `${res.locals.casa.mountUrl}${journeyOrigin.originId || ''}/`.replace(/\/+/g, '/');
|
|
26
|
-
res.locals.journeyContext = req.casa.journeyContext.getData();
|
|
27
|
-
res.locals.reviewErrors = req.casa.journeyContext.getValidationErrors();
|
|
28
|
-
|
|
29
|
-
// Determine which pages have been traversed in the user's journey in
|
|
30
|
-
// order to get to this review point (not all journey waypoints will
|
|
31
|
-
// have been touched, but may contain data which needs to be ignored)
|
|
32
|
-
let waypointsTraversed;
|
|
33
|
-
const traversalOptions = {
|
|
34
|
-
startWaypoint: journeyOrigin.waypoint,
|
|
35
|
-
};
|
|
36
|
-
if (req.casa.journeyContext) {
|
|
37
|
-
waypointsTraversed = userJourney.traverse(req.casa.journeyContext, traversalOptions);
|
|
38
|
-
} else {
|
|
39
|
-
waypointsTraversed = userJourney.traverse(new JourneyContext(), traversalOptions);
|
|
40
|
-
}
|
|
41
|
-
res.locals.reviewBlocks = waypointsTraversed.map((waypointId) => {
|
|
42
|
-
const meta = pagesMeta[waypointId] || Object.create(null);
|
|
43
|
-
return meta.reviewBlockView ? {
|
|
44
|
-
waypointId,
|
|
45
|
-
waypointEditUrl: createGetRequest({
|
|
46
|
-
mountUrl: res.locals.casa.mountUrl,
|
|
47
|
-
waypoint: `${journeyOrigin.originId || ''}/${waypointId}`,
|
|
48
|
-
editMode: true,
|
|
49
|
-
editOrigin: req.editOriginUrl,
|
|
50
|
-
contextId: req.casa.journeyContext.identity.id,
|
|
51
|
-
}),
|
|
52
|
-
reviewBlockView: meta.reviewBlockView,
|
|
53
|
-
} : null;
|
|
54
|
-
}).filter((o) => o !== null);
|
|
55
|
-
|
|
56
|
-
next();
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
};
|