hof 22.9.0-beta.v1 → 22.9.0-beta.v3
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/config/hof-defaults.js +1 -0
- package/frontend/template-partials/views/cookies.html +6 -6
- package/frontend/template-partials/views/partials/cookie-banner.html +11 -6
- package/lib/settings.js +1 -0
- package/package.json +1 -1
- package/package/.eslintignore +0 -1
- package/package/CHANGELOG.md +0 -232
- package/package/LICENSE +0 -21
- package/package/README.md +0 -1887
- package/package/bin/hof-build +0 -10
- package/package/bin/hof-transpiler +0 -12
- package/package/build/helpers/importer.js +0 -29
- package/package/build/helpers/local.js +0 -35
- package/package/build/helpers/resolver/import.js +0 -32
- package/package/build/helpers/resolver/nearest-package-root.js +0 -33
- package/package/build/helpers/resolver/package.js +0 -29
- package/package/build/helpers/resolver.js +0 -16
- package/package/build/index.js +0 -49
- package/package/build/lib/env.js +0 -36
- package/package/build/lib/mkdir.js +0 -9
- package/package/build/lib/run.js +0 -17
- package/package/build/lib/spawn.js +0 -18
- package/package/build/tasks/browserify/compress.js +0 -15
- package/package/build/tasks/browserify/index.js +0 -48
- package/package/build/tasks/build/index.js +0 -6
- package/package/build/tasks/images/index.js +0 -27
- package/package/build/tasks/index.js +0 -8
- package/package/build/tasks/sass/index.js +0 -67
- package/package/build/tasks/translate/index.js +0 -20
- package/package/build/tasks/watch/index.js +0 -161
- package/package/components/address-lookup/default-model.js +0 -76
- package/package/components/address-lookup/defaults.js +0 -25
- package/package/components/address-lookup/index.js +0 -251
- package/package/components/address-lookup/templates/address-lookup.html +0 -14
- package/package/components/address-lookup/templates/address.html +0 -22
- package/package/components/address-lookup/templates/postcode.html +0 -9
- package/package/components/clear-session/Readme.md +0 -46
- package/package/components/clear-session/index.js +0 -26
- package/package/components/combine-and-loop-fields/Readme.md +0 -42
- package/package/components/combine-and-loop-fields/index.js +0 -156
- package/package/components/date/fields.js +0 -16
- package/package/components/date/index.js +0 -172
- package/package/components/date/templates/date.html +0 -20
- package/package/components/emailer/assets/images/govuk_logotype_email.png +0 -0
- package/package/components/emailer/assets/images/ho_crest_27px.png +0 -0
- package/package/components/emailer/assets/images/spacer.gif +0 -0
- package/package/components/emailer/email-service.js +0 -51
- package/package/components/emailer/emailer.js +0 -53
- package/package/components/emailer/index.js +0 -74
- package/package/components/emailer/transports/debug.js +0 -74
- package/package/components/emailer/transports/index.js +0 -8
- package/package/components/emailer/transports/ses.js +0 -36
- package/package/components/emailer/transports/smtp.js +0 -26
- package/package/components/emailer/transports/stub.js +0 -5
- package/package/components/emailer/views/layout.html +0 -63
- package/package/components/homeoffice-countries/index.js +0 -22
- package/package/components/index.js +0 -13
- package/package/components/notify/index.js +0 -62
- package/package/components/notify/notify.js +0 -51
- package/package/components/session-timeout-warning/index.js +0 -67
- package/package/components/summary/index.js +0 -237
- package/package/config/builder-defaults.js +0 -45
- package/package/config/component-defaults.js +0 -13
- package/package/config/hof-defaults.js +0 -65
- package/package/config/rate-limits.js +0 -20
- package/package/config/sanitisation-rules.js +0 -32
- package/package/controller/base-controller.js +0 -296
- package/package/controller/behaviour-hooks.js +0 -51
- package/package/controller/behaviour-session.js +0 -64
- package/package/controller/controller.js +0 -258
- package/package/controller/deprecate-error.js +0 -10
- package/package/controller/formatting/formatters.js +0 -70
- package/package/controller/formatting/index.js +0 -32
- package/package/controller/index.js +0 -17
- package/package/controller/validation/email.js +0 -30
- package/package/controller/validation/index.js +0 -101
- package/package/controller/validation/validators.js +0 -181
- package/package/controller/validation-error.js +0 -14
- package/package/frontend/govuk-template/build/config.js +0 -24
- package/package/frontend/govuk-template/build/govuk_template.html +0 -102
- package/package/frontend/govuk-template/build/index.js +0 -23
- package/package/frontend/govuk-template/govuk_template_generated.html +0 -102
- package/package/frontend/govuk-template/index.js +0 -29
- package/package/frontend/index.js +0 -9
- package/package/frontend/template-mixins/mixins/helpers.js +0 -103
- package/package/frontend/template-mixins/mixins/index.js +0 -37
- package/package/frontend/template-mixins/mixins/render.js +0 -12
- package/package/frontend/template-mixins/mixins/template-mixins.js +0 -520
- package/package/frontend/template-mixins/partials/forms/checkbox-group.html +0 -47
- package/package/frontend/template-mixins/partials/forms/checkbox.html +0 -16
- package/package/frontend/template-mixins/partials/forms/input-submit.html +0 -1
- package/package/frontend/template-mixins/partials/forms/input-text-date.html +0 -37
- package/package/frontend/template-mixins/partials/forms/input-text-group.html +0 -45
- package/package/frontend/template-mixins/partials/forms/option-group.html +0 -43
- package/package/frontend/template-mixins/partials/forms/select.html +0 -17
- package/package/frontend/template-mixins/partials/forms/textarea-group.html +0 -37
- package/package/frontend/template-mixins/partials/mixins/panel.html +0 -4
- package/package/frontend/template-partials/index.js +0 -9
- package/package/frontend/template-partials/translations/index.js +0 -26
- package/package/frontend/template-partials/translations/src/cy/base.json +0 -4
- package/package/frontend/template-partials/translations/src/cy/buttons.json +0 -6
- package/package/frontend/template-partials/translations/src/cy/cookies.json +0 -104
- package/package/frontend/template-partials/translations/src/cy/errorlist.json +0 -6
- package/package/frontend/template-partials/translations/src/cy/errors.json +0 -18
- package/package/frontend/template-partials/translations/src/cy/terms.json +0 -28
- package/package/frontend/template-partials/translations/src/en/accessibility.json +0 -43
- package/package/frontend/template-partials/translations/src/en/base.json +0 -5
- package/package/frontend/template-partials/translations/src/en/buttons.json +0 -10
- package/package/frontend/template-partials/translations/src/en/cookies.json +0 -116
- package/package/frontend/template-partials/translations/src/en/errorlist.json +0 -7
- package/package/frontend/template-partials/translations/src/en/errors.json +0 -35
- package/package/frontend/template-partials/translations/src/en/exit.json +0 -5
- package/package/frontend/template-partials/translations/src/en/fields.json +0 -5
- package/package/frontend/template-partials/translations/src/en/journey.json +0 -6
- package/package/frontend/template-partials/translations/src/en/save-and-exit.json +0 -4
- package/package/frontend/template-partials/translations/src/en/terms.json +0 -28
- package/package/frontend/template-partials/views/404.html +0 -9
- package/package/frontend/template-partials/views/accessibility.html +0 -55
- package/package/frontend/template-partials/views/confirm.html +0 -8
- package/package/frontend/template-partials/views/confirmation.html +0 -19
- package/package/frontend/template-partials/views/content/en/what-happens-next.md +0 -0
- package/package/frontend/template-partials/views/cookie-error.html +0 -1
- package/package/frontend/template-partials/views/cookies.html +0 -84
- package/package/frontend/template-partials/views/email/data-row.html +0 -4
- package/package/frontend/template-partials/views/email/formatted.html +0 -12
- package/package/frontend/template-partials/views/email/layout.html +0 -63
- package/package/frontend/template-partials/views/email/raw.html +0 -11
- package/package/frontend/template-partials/views/email/section-row.html +0 -3
- package/package/frontend/template-partials/views/error.html +0 -20
- package/package/frontend/template-partials/views/exit.html +0 -9
- package/package/frontend/template-partials/views/feedback-submitted.html +0 -11
- package/package/frontend/template-partials/views/layout.html +0 -55
- package/package/frontend/template-partials/views/partials/analytics-table.html +0 -25
- package/package/frontend/template-partials/views/partials/back.html +0 -5
- package/package/frontend/template-partials/views/partials/bullet-list.html +0 -7
- package/package/frontend/template-partials/views/partials/confirmation-alert.html +0 -6
- package/package/frontend/template-partials/views/partials/continue.html +0 -5
- package/package/frontend/template-partials/views/partials/cookie-banner.html +0 -29
- package/package/frontend/template-partials/views/partials/cookie-notification.html +0 -4
- package/package/frontend/template-partials/views/partials/cookie-settings-button.html +0 -1
- package/package/frontend/template-partials/views/partials/cookie-settings-radio.html +0 -8
- package/package/frontend/template-partials/views/partials/details-summary.html +0 -8
- package/package/frontend/template-partials/views/partials/external-link.html +0 -1
- package/package/frontend/template-partials/views/partials/form.html +0 -10
- package/package/frontend/template-partials/views/partials/gatag.html +0 -60
- package/package/frontend/template-partials/views/partials/head.html +0 -31
- package/package/frontend/template-partials/views/partials/heading.html +0 -11
- package/package/frontend/template-partials/views/partials/items-table.html +0 -32
- package/package/frontend/template-partials/views/partials/maincontent-left.html +0 -10
- package/package/frontend/template-partials/views/partials/navigation.html +0 -8
- package/package/frontend/template-partials/views/partials/page.html +0 -23
- package/package/frontend/template-partials/views/partials/panel-indent.html +0 -3
- package/package/frontend/template-partials/views/partials/session-cookies-table.html +0 -28
- package/package/frontend/template-partials/views/partials/session-timeout-warning.html +0 -38
- package/package/frontend/template-partials/views/partials/summary-table-row.html +0 -14
- package/package/frontend/template-partials/views/partials/summary-table.html +0 -8
- package/package/frontend/template-partials/views/partials/table.html +0 -18
- package/package/frontend/template-partials/views/partials/validation-list.html +0 -3
- package/package/frontend/template-partials/views/partials/validation-summary.html +0 -25
- package/package/frontend/template-partials/views/partials/warn.html +0 -7
- package/package/frontend/template-partials/views/rate-limit-error.html +0 -10
- package/package/frontend/template-partials/views/save-and-exit.html +0 -17
- package/package/frontend/template-partials/views/service-unavailable.html +0 -13
- package/package/frontend/template-partials/views/session-timeout.html +0 -7
- package/package/frontend/template-partials/views/step.html +0 -14
- package/package/frontend/template-partials/views/terms.html +0 -26
- package/package/frontend/themes/gov-uk/client-js/cookieSettings.js +0 -145
- package/package/frontend/themes/gov-uk/client-js/govuk-cookies.js +0 -121
- package/package/frontend/themes/gov-uk/client-js/index.js +0 -27
- package/package/frontend/themes/gov-uk/client-js/session-timeout-dialog.js +0 -348
- package/package/frontend/themes/gov-uk/client-js/skip-to-main.js +0 -19
- package/package/frontend/themes/gov-uk/index.js +0 -9
- package/package/frontend/themes/gov-uk/styles/_base.scss +0 -17
- package/package/frontend/themes/gov-uk/styles/_check_your_answers.scss +0 -155
- package/package/frontend/themes/gov-uk/styles/_cookie-banner.scss +0 -111
- package/package/frontend/themes/gov-uk/styles/_cookie-settings.scss +0 -33
- package/package/frontend/themes/gov-uk/styles/_govuk_frontend_toolkit.scss +0 -23
- package/package/frontend/themes/gov-uk/styles/_helpers.scss +0 -5
- package/package/frontend/themes/gov-uk/styles/_layout.scss +0 -125
- package/package/frontend/themes/gov-uk/styles/_panel-indent.scss +0 -27
- package/package/frontend/themes/gov-uk/styles/_pdf.scss +0 -42
- package/package/frontend/themes/gov-uk/styles/_session-timeout-dialog.scss +0 -121
- package/package/frontend/themes/gov-uk/styles/_typography.scss +0 -27
- package/package/frontend/themes/gov-uk/styles/_variables.scss +0 -11
- package/package/frontend/themes/gov-uk/styles/govuk.scss +0 -43
- package/package/frontend/themes/gov-uk/styles/mixins.scss +0 -16
- package/package/frontend/themes/gov-uk/styles/modules/_alerts.scss +0 -73
- package/package/frontend/themes/gov-uk/styles/modules/_buttons.scss +0 -5
- package/package/frontend/themes/gov-uk/styles/modules/_character-count.scss +0 -8
- package/package/frontend/themes/gov-uk/styles/modules/_confirm-page.scss +0 -20
- package/package/frontend/themes/gov-uk/styles/modules/_lists.scss +0 -5
- package/package/frontend/themes/gov-uk/styles/modules/_progressive-reveal.scss +0 -17
- package/package/frontend/themes/gov-uk/styles/modules/_validation.scss +0 -51
- package/package/frontend/themes/index.js +0 -5
- package/package/frontend/toolkit/assets/images/passports/new-window-link-blue.png +0 -0
- package/package/frontend/toolkit/assets/images/passports/new-window-link.png +0 -0
- package/package/frontend/toolkit/assets/images/spinner.gif +0 -0
- package/package/frontend/toolkit/assets/javascript/character-count.js +0 -99
- package/package/frontend/toolkit/assets/javascript/form-focus.js +0 -101
- package/package/frontend/toolkit/assets/javascript/helpers.js +0 -177
- package/package/frontend/toolkit/assets/javascript/progressive-reveal.js +0 -72
- package/package/frontend/toolkit/assets/javascript/validation.js +0 -71
- package/package/frontend/toolkit/assets/javascript/vendor/details.polyfill.js +0 -189
- package/package/frontend/toolkit/assets/javascript/vendor/indexof.polyfill.js +0 -39
- package/package/frontend/toolkit/assets/javascript/vendor/safari-cachebuster.js +0 -6
- package/package/frontend/toolkit/assets/stylesheets/_base.scss +0 -17
- package/package/frontend/toolkit/assets/stylesheets/_helpers.scss +0 -5
- package/package/frontend/toolkit/assets/stylesheets/_layout.scss +0 -118
- package/package/frontend/toolkit/assets/stylesheets/_typography.scss +0 -27
- package/package/frontend/toolkit/assets/stylesheets/_variables.scss +0 -11
- package/package/frontend/toolkit/assets/stylesheets/app.scss +0 -30
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_buttons.scss +0 -47
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_details.scss +0 -38
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_elements-typography.scss +0 -175
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_forms.scss +0 -167
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_helpers.scss +0 -39
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_layout.scss +0 -67
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_lists.scss +0 -40
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_panels.scss +0 -29
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_reset.scss +0 -33
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_tables.scss +0 -33
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/forms/_form-block-labels.scss +0 -63
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/forms/_form-date.scss +0 -39
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/forms/_form-validation.scss +0 -63
- package/package/frontend/toolkit/assets/stylesheets/mixins.scss +0 -16
- package/package/frontend/toolkit/assets/stylesheets/modules/_alerts.scss +0 -73
- package/package/frontend/toolkit/assets/stylesheets/modules/_buttons.scss +0 -5
- package/package/frontend/toolkit/assets/stylesheets/modules/_confirm-page.scss +0 -20
- package/package/frontend/toolkit/assets/stylesheets/modules/_lists.scss +0 -5
- package/package/frontend/toolkit/assets/stylesheets/modules/_progressive-reveal.scss +0 -17
- package/package/frontend/toolkit/assets/stylesheets/modules/_validation.scss +0 -51
- package/package/frontend/toolkit/index.js +0 -10
- package/package/index.js +0 -351
- package/package/lib/deindex.js +0 -18
- package/package/lib/encryption.js +0 -23
- package/package/lib/ga-tag.js +0 -89
- package/package/lib/health.js +0 -26
- package/package/lib/helpers.js +0 -66
- package/package/lib/logger.js +0 -65
- package/package/lib/markdown.js +0 -46
- package/package/lib/router.js +0 -111
- package/package/lib/serve-static.js +0 -12
- package/package/lib/sessions.js +0 -82
- package/package/lib/settings.js +0 -74
- package/package/lib/which.js +0 -28
- package/package/middleware/cookies.js +0 -43
- package/package/middleware/deep-translate.js +0 -32
- package/package/middleware/errors.js +0 -119
- package/package/middleware/index.js +0 -10
- package/package/middleware/not-found.js +0 -38
- package/package/middleware/rate-limiter.js +0 -98
- package/package/middleware/service-unavailable.js +0 -64
- package/package/model/apis/axios-settings.js +0 -21
- package/package/model/apis/html-to-pdf-converter.js +0 -35
- package/package/model/apis/index.js +0 -5
- package/package/model/index.js +0 -348
- package/package/package.json +0 -147
- package/package/sandbox/README.md +0 -66
- package/package/sandbox/apps/sandbox/behaviours/clear-session.js +0 -8
- package/package/sandbox/apps/sandbox/behaviours/country-select.js +0 -10
- package/package/sandbox/apps/sandbox/behaviours/international-number.js +0 -22
- package/package/sandbox/apps/sandbox/fields.js +0 -128
- package/package/sandbox/apps/sandbox/index.js +0 -99
- package/package/sandbox/apps/sandbox/lib/staticAppealStages.js +0 -189
- package/package/sandbox/apps/sandbox/sections/summary-data-sections.js +0 -43
- package/package/sandbox/apps/sandbox/translations/src/en/errors.json +0 -5
- package/package/sandbox/apps/sandbox/translations/src/en/exit.json +0 -4
- package/package/sandbox/apps/sandbox/translations/src/en/fields.json +0 -101
- package/package/sandbox/apps/sandbox/translations/src/en/journey.json +0 -7
- package/package/sandbox/apps/sandbox/translations/src/en/pages.json +0 -72
- package/package/sandbox/apps/sandbox/translations/src/en/validation.json +0 -54
- package/package/sandbox/apps/sandbox/views/form-guidance-link.html +0 -8
- package/package/sandbox/apps/sandbox/views/save-and-exit.html +0 -19
- package/package/sandbox/assets/images/icons/icon-caret-left.png +0 -0
- package/package/sandbox/assets/images/icons/icon-complete.png +0 -0
- package/package/sandbox/assets/images/icons/icon-cross-remove-sign.png +0 -0
- package/package/sandbox/assets/js/index.js +0 -70
- package/package/sandbox/assets/scss/app.scss +0 -27
- package/package/sandbox/codecept.conf.js +0 -15
- package/package/sandbox/config.js +0 -17
- package/package/sandbox/package.json +0 -26
- package/package/sandbox/server.js +0 -23
- package/package/sandbox/yarn.lock +0 -262
- package/package/transpiler/index.js +0 -2
- package/package/transpiler/lib/aggregate.js +0 -32
- package/package/transpiler/lib/build.js +0 -15
- package/package/transpiler/lib/compile.js +0 -12
- package/package/transpiler/lib/expand-dirs.js +0 -14
- package/package/transpiler/lib/write-files.js +0 -24
- package/package/utilities/autofill/index.js +0 -189
- package/package/utilities/autofill/inputs.js +0 -60
- package/package/utilities/countries.js +0 -12
- package/package/utilities/helpers/index.js +0 -189
- package/package/utilities/index.js +0 -9
- package/package/utilities/reqres/index.js +0 -18
- package/package/utilities/test-data/data/domain.json +0 -7
- package/package/utilities/test-data/data/firstname.json +0 -16
- package/package/utilities/test-data/data/lastname.json +0 -10
- package/package/utilities/test-data/data/postcode.json +0 -12
- package/package/utilities/test-data/data/streetname.json +0 -8
- package/package/utilities/test-data/data/streetsuffix.json +0 -7
- package/package/utilities/test-data/data/town.json +0 -9
- package/package/utilities/test-data/index.js +0 -67
- package/package/wizard/behaviours/complete.js +0 -20
- package/package/wizard/behaviours/index.js +0 -5
- package/package/wizard/index.js +0 -124
- package/package/wizard/middleware/back-links.js +0 -68
- package/package/wizard/middleware/check-complete.js +0 -13
- package/package/wizard/middleware/check-progress.js +0 -139
- package/package/wizard/middleware/check-session.js +0 -17
- package/package/wizard/middleware/csrf.js +0 -47
- package/package/wizard/middleware/session-model.js +0 -11
- package/package/wizard/middleware/session.js +0 -9
- package/package/wizard/model.js +0 -29
- package/package/wizard/util/constants.js +0 -5
- package/package/wizard/util/helpers.js +0 -19
@@ -1,17 +0,0 @@
|
|
1
|
-
.reveal {
|
2
|
-
float: left;
|
3
|
-
width: 100%;
|
4
|
-
.panel-indent {
|
5
|
-
margin-top: $gutter-half / 2;
|
6
|
-
margin-bottom: $gutter-half;
|
7
|
-
}
|
8
|
-
}
|
9
|
-
|
10
|
-
fieldset + .reveal {
|
11
|
-
margin-top: -$gutter-half;
|
12
|
-
margin-bottom: $gutter-half;
|
13
|
-
@include media(tablet) {
|
14
|
-
margin-top: -$gutter;
|
15
|
-
margin-bottom: $gutter;
|
16
|
-
}
|
17
|
-
}
|
@@ -1,51 +0,0 @@
|
|
1
|
-
.validation-summary {
|
2
|
-
padding-left: $gutter-half - $validation-bdr-size-lg;
|
3
|
-
padding-right: $gutter-half;
|
4
|
-
border-width: $validation-bdr-size-lg;
|
5
|
-
|
6
|
-
&:focus {
|
7
|
-
outline: $focus-outline;
|
8
|
-
}
|
9
|
-
|
10
|
-
h2 {
|
11
|
-
margin: 0.3em 0;
|
12
|
-
}
|
13
|
-
ul {
|
14
|
-
margin: 0;
|
15
|
-
li {
|
16
|
-
margin: 0;
|
17
|
-
padding: 3px 0;
|
18
|
-
}
|
19
|
-
}
|
20
|
-
a {
|
21
|
-
@include bold-19;
|
22
|
-
}
|
23
|
-
}
|
24
|
-
|
25
|
-
.govuk-form-group--error {
|
26
|
-
box-sizing: border-box;
|
27
|
-
padding-left: $gutter-half - $validation-bdr-size;
|
28
|
-
border-left: $validation-bdr-size-lg solid $error-colour;
|
29
|
-
|
30
|
-
&:focus {
|
31
|
-
outline: $focus-outline;
|
32
|
-
}
|
33
|
-
|
34
|
-
.form-control {
|
35
|
-
margin-bottom: $validation-bdr-size;
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
.govuk-error-message {
|
40
|
-
display: block;
|
41
|
-
@include media(tablet) {
|
42
|
-
margin-bottom: 0.5em;
|
43
|
-
}
|
44
|
-
@include bold-19;
|
45
|
-
color: $error-colour;
|
46
|
-
}
|
47
|
-
|
48
|
-
.invalid-input,
|
49
|
-
.govuk-form-group--error .date-input {
|
50
|
-
border: $validation-bdr-size solid $error-colour;
|
51
|
-
}
|
@@ -1,10 +0,0 @@
|
|
1
|
-
module.exports = {
|
2
|
-
helpers: require('./assets/javascript/helpers'),
|
3
|
-
formFocus: require('./assets/javascript/form-focus'),
|
4
|
-
progressiveReveal: require('./assets/javascript/progressive-reveal'),
|
5
|
-
validation: require('./assets/javascript/validation'),
|
6
|
-
detailsSummary: function () {
|
7
|
-
require('./assets/javascript/vendor/details.polyfill');
|
8
|
-
},
|
9
|
-
characterCount: require('./assets/javascript/character-count')
|
10
|
-
};
|
package/package/index.js
DELETED
@@ -1,351 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
const crypto = require('crypto');
|
4
|
-
const express = require('express');
|
5
|
-
const morgan = require('morgan');
|
6
|
-
const path = require('path');
|
7
|
-
const http = require('http');
|
8
|
-
const https = require('https');
|
9
|
-
const mixins = require('./frontend').mixins;
|
10
|
-
const hofMiddleware = require('./middleware');
|
11
|
-
const markdown = require('./lib/markdown');
|
12
|
-
const translate = require('i18n-future').middleware;
|
13
|
-
const router = require('./lib/router');
|
14
|
-
const health = require('./lib/health');
|
15
|
-
const serveStatic = require('./lib/serve-static');
|
16
|
-
const gaTagSetup = require('./lib/ga-tag');
|
17
|
-
const deIndexer = require('./lib/deindex');
|
18
|
-
const sessionStore = require('./lib/sessions');
|
19
|
-
const settings = require('./lib/settings');
|
20
|
-
const defaults = require('./config/hof-defaults');
|
21
|
-
const logger = require('./lib/logger');
|
22
|
-
const helmet = require('helmet');
|
23
|
-
const _ = require('lodash');
|
24
|
-
const deprecate = require('deprecate');
|
25
|
-
|
26
|
-
const customConfig = {};
|
27
|
-
|
28
|
-
const getConfig = function () {
|
29
|
-
const args = [].slice.call(arguments);
|
30
|
-
const config = _.merge.apply(_, [{}, defaults, customConfig].concat(args));
|
31
|
-
|
32
|
-
if (!config.theme) {
|
33
|
-
config.theme = require('./frontend').themes.govUK;
|
34
|
-
} else if (typeof config.theme === 'string') {
|
35
|
-
config.theme = require('./frontend').themes[config.theme];
|
36
|
-
}
|
37
|
-
|
38
|
-
config.markdown = config.markdown || {};
|
39
|
-
|
40
|
-
return config;
|
41
|
-
};
|
42
|
-
|
43
|
-
const loadRoutes = (app, config) => {
|
44
|
-
config.routes.forEach(route => {
|
45
|
-
const routeConfig = Object.assign({}, config, {
|
46
|
-
route,
|
47
|
-
sharedViews: app.get('views')
|
48
|
-
});
|
49
|
-
app.use(route.baseUrl || '/', router(routeConfig));
|
50
|
-
});
|
51
|
-
};
|
52
|
-
|
53
|
-
const applyErrorMiddlewares = (app, config) => {
|
54
|
-
if (config.serviceUnavailable === true) {
|
55
|
-
app.use(hofMiddleware.serviceUnavailable({
|
56
|
-
logger: config.logger
|
57
|
-
}));
|
58
|
-
}
|
59
|
-
|
60
|
-
app.use(hofMiddleware.notFound({
|
61
|
-
logger: config.logger
|
62
|
-
}));
|
63
|
-
|
64
|
-
app.use(hofMiddleware.errors({
|
65
|
-
logger: config.logger,
|
66
|
-
debug: config.env === 'development'
|
67
|
-
}));
|
68
|
-
};
|
69
|
-
|
70
|
-
const getContentSecurityPolicy = (config, res) => {
|
71
|
-
const csp = config.csp;
|
72
|
-
|
73
|
-
/* eslint-disable quotes */
|
74
|
-
const directives = {
|
75
|
-
defaultSrc: ["'none'"],
|
76
|
-
styleSrc: ["'self'"],
|
77
|
-
imgSrc: ["'self'"],
|
78
|
-
fontSrc: ["'self'", 'data:', 'https://design-system.service.gov.uk'],
|
79
|
-
scriptSrc: ["'self'", `'nonce-${res.locals.nonce}'`],
|
80
|
-
'frame-ancestors': ["'none'"]
|
81
|
-
};
|
82
|
-
/* eslint-enable quotes */
|
83
|
-
|
84
|
-
const gaDirectives = {
|
85
|
-
styleSrc: ['www.googletagmanager.com', 'fonts.googleapis.com', 'tagmanager.google.com'],
|
86
|
-
fontSrc: ['fonts.gstatic.com '],
|
87
|
-
scriptSrc: ['www.google-analytics.com', 'ssl.google-analytics.com'],
|
88
|
-
imgSrc: [
|
89
|
-
'www.google-analytics.com',
|
90
|
-
'ssl.gstatic.com',
|
91
|
-
'www.google.co.uk/ads/ga-audiences'
|
92
|
-
],
|
93
|
-
connectSrc: [
|
94
|
-
"'self'",
|
95
|
-
'https://www.google-analytics.com',
|
96
|
-
'https://region1.google-analytics.com',
|
97
|
-
'https://region1.analytics.google.com'
|
98
|
-
]
|
99
|
-
};
|
100
|
-
|
101
|
-
if (config.gaTagId) {
|
102
|
-
directives.styleSrc = directives.styleSrc.concat(gaDirectives.styleSrc);
|
103
|
-
directives.scriptSrc = directives.scriptSrc.concat(gaDirectives.scriptSrc);
|
104
|
-
directives.fontSrc = directives.fontSrc.concat(gaDirectives.fontSrc);
|
105
|
-
directives.imgSrc = directives.imgSrc.concat(gaDirectives.imgSrc);
|
106
|
-
directives.connectSrc = gaDirectives.connectSrc;
|
107
|
-
}
|
108
|
-
|
109
|
-
if (csp && !csp.disabled) {
|
110
|
-
_.each(csp, (value, name) => {
|
111
|
-
if (name === 'disabled') {
|
112
|
-
return;
|
113
|
-
}
|
114
|
-
if (directives[name] && directives[name].length) {
|
115
|
-
// concat unique directives with existing directives
|
116
|
-
directives[name] = _.uniq(directives[name].concat(value));
|
117
|
-
} else {
|
118
|
-
directives[name] = _.isArray(value) ? value : [value];
|
119
|
-
}
|
120
|
-
});
|
121
|
-
}
|
122
|
-
return directives;
|
123
|
-
};
|
124
|
-
|
125
|
-
/**
|
126
|
-
* Creates a new HOF application
|
127
|
-
*
|
128
|
-
* @param options {object} Configuration options for the HOF application
|
129
|
-
* @param options.behaviours {object | Array<object>} The HOF behaviour(s) to invoke for all sub-applications
|
130
|
-
* @param options.translations {string} The translations path for the application
|
131
|
-
* @param options.routes {Array<object>} The sub-applications for this app: for sandbox; require('./apps/sandbox')
|
132
|
-
* @param options.views {Array<string>} The view template paths for the application
|
133
|
-
* @param options.middleware {Array<function>} An array of Express middleware functions to use
|
134
|
-
* @param options.theme {string} Optional HOF theme - defaults to govuk
|
135
|
-
* @param options.markdown {object} Optional markdown options
|
136
|
-
* @param options.getTerms {boolean} Optional boolean - whether to mount the /terms endpoint
|
137
|
-
* @param options.getCookies {boolean} Optional boolean - whether to mount the /cookies endpoint
|
138
|
-
* @param options.noCache {boolean} Optional boolean - whether to disable caching
|
139
|
-
* @param options.getAccessibilityStatement {boolean} Optional boolean - whether to mount the
|
140
|
-
* /accessibility-statement endpoint
|
141
|
-
*
|
142
|
-
* @returns {object} A new HOF application using the configuration supplied in options
|
143
|
-
*/
|
144
|
-
function bootstrap(options) {
|
145
|
-
const config = getConfig(options);
|
146
|
-
|
147
|
-
const app = express();
|
148
|
-
const userMiddleware = express.Router();
|
149
|
-
|
150
|
-
app.use(helmet());
|
151
|
-
|
152
|
-
// Add common locals all pages can access
|
153
|
-
app.use((req, res, next) => {
|
154
|
-
res.locals.nonce = crypto.randomBytes(16).toString('hex');
|
155
|
-
res.locals.appName = config.appName;
|
156
|
-
res.locals.htmlLang = config.htmlLang;
|
157
|
-
res.locals.cookieName = config.session.name;
|
158
|
-
// session timeout warning configs
|
159
|
-
res.locals.sessionTimeOut = config.session.ttl;
|
160
|
-
res.locals.sessionTimeOutWarning = config.sessionTimeOutWarning;
|
161
|
-
res.locals.sessionTimeoutWarningContent = config.sessionTimeoutWarningContent;
|
162
|
-
res.locals.exitFormContent = config.exitFormContent;
|
163
|
-
res.locals.saveExitFormContent = config.saveExitFormContent;
|
164
|
-
res.locals.serviceUnavailable = config.serviceUnavailable;
|
165
|
-
res.locals.gaContainerId = config.ga4TagId;
|
166
|
-
next();
|
167
|
-
});
|
168
|
-
|
169
|
-
if (config.csp !== false && !config.csp.disabled) {
|
170
|
-
app.use((req, res, next) => {
|
171
|
-
helmet.contentSecurityPolicy({
|
172
|
-
directives: getContentSecurityPolicy(config, res)
|
173
|
-
})(req, res, next);
|
174
|
-
});
|
175
|
-
}
|
176
|
-
|
177
|
-
app.use(helmet.noSniff());
|
178
|
-
|
179
|
-
if (config.noCache && config.noCache !== 'false') {
|
180
|
-
app.use((req, res, next) => {
|
181
|
-
res.setHeader('cache-control', ['no-store', 'no-cache', 'must-revalidate', 'proxy-revalidate']);
|
182
|
-
res.setHeader('pragma', 'no-cache');
|
183
|
-
next();
|
184
|
-
});
|
185
|
-
}
|
186
|
-
|
187
|
-
if (!config || !config.routes || !config.routes.length) {
|
188
|
-
throw new Error('Must be called with a list of routes');
|
189
|
-
}
|
190
|
-
|
191
|
-
config.routes.forEach(route => {
|
192
|
-
if (!route.steps && !route.pages) {
|
193
|
-
throw new Error('Each app must have steps and/or pages');
|
194
|
-
}
|
195
|
-
});
|
196
|
-
|
197
|
-
if (config.middleware) {
|
198
|
-
config.middleware.forEach(middleware => app.use(middleware));
|
199
|
-
}
|
200
|
-
|
201
|
-
config.logger = logger(config);
|
202
|
-
|
203
|
-
morgan.token('id', req => _.get(req, 'session.id', 'N/A'));
|
204
|
-
|
205
|
-
app.use(morgan('sessionId=:id ' + morgan.combined, {
|
206
|
-
stream: config.logger.stream,
|
207
|
-
skip: (req, res) => config.loglevel !== 'debug' &&
|
208
|
-
(
|
209
|
-
res.statusCode >= 300 || !_.get(req, 'session.id') ||
|
210
|
-
config.ignoreMiddlewareLogs.some(v => req.originalUrl.includes(v))
|
211
|
-
)
|
212
|
-
}));
|
213
|
-
|
214
|
-
serveStatic(app, config);
|
215
|
-
settings(app, config);
|
216
|
-
gaTagSetup(app, config);
|
217
|
-
deIndexer(app, config);
|
218
|
-
|
219
|
-
const sessions = sessionStore(app, config);
|
220
|
-
app.use('/healthz', health(sessions));
|
221
|
-
|
222
|
-
app.use((req, res, next) => {
|
223
|
-
const id = _.get(req, 'session.id', 'N/A');
|
224
|
-
req.log = config.logger.logSession(id);
|
225
|
-
next();
|
226
|
-
});
|
227
|
-
|
228
|
-
app.use(translate({
|
229
|
-
resources: config.theme.translations,
|
230
|
-
path: path.resolve(config.root, config.translations) + '/__lng__/__ns__.json'
|
231
|
-
}));
|
232
|
-
app.use(mixins());
|
233
|
-
app.use(markdown(config.markdown));
|
234
|
-
// rate limits have to be loaded before all routes so it is applied to them
|
235
|
-
if (config.rateLimits.requests.active) {
|
236
|
-
app.use(hofMiddleware.rateLimiter(config, 'requests'));
|
237
|
-
}
|
238
|
-
|
239
|
-
// Set up routing so <YOUR-SITE-URL>/assets are served from /node_modules/govuk-frontend/govuk/assets
|
240
|
-
app.use('/assets', express.static(path.join(__dirname, '/node_modules/govuk-frontend/govuk/assets')));
|
241
|
-
// Check if service has been paused and redirect accordingly
|
242
|
-
const bypassPaths = ['/assets', '/healthcheck', '/service-unavailable'];
|
243
|
-
|
244
|
-
if (config.serviceUnavailable === true) {
|
245
|
-
app.use((req, res, next) => {
|
246
|
-
if (!bypassPaths.some(bypassPath => req.path.startsWith(bypassPath))) {
|
247
|
-
return res.redirect('/service-unavailable');
|
248
|
-
}
|
249
|
-
return next();
|
250
|
-
});
|
251
|
-
}
|
252
|
-
if (config.getAccessibility === true) {
|
253
|
-
deprecate(
|
254
|
-
'`getAccessibility` option is deprecated and may be removed in future versions.',
|
255
|
-
'Use `pages` to define static cookies page.'
|
256
|
-
);
|
257
|
-
app.get('/accessibility', (req, res) => {
|
258
|
-
const locals = Object.assign({}, req.translate('accessibility'));
|
259
|
-
res.render('accessibility', locals);
|
260
|
-
});
|
261
|
-
}
|
262
|
-
if (config.getCookies === true) {
|
263
|
-
deprecate(
|
264
|
-
'`getCookies` option is deprecated and may be removed in future versions.',
|
265
|
-
'Use `pages` to define static cookies page.'
|
266
|
-
);
|
267
|
-
app.get('/cookies', (req, res) => {
|
268
|
-
const locals = Object.assign({}, req.translate('cookies'));
|
269
|
-
res.render('cookies', locals);
|
270
|
-
});
|
271
|
-
}
|
272
|
-
if (config.getTerms === true) {
|
273
|
-
deprecate(
|
274
|
-
'`getTerms` option is deprecated and may be removed in future versions.',
|
275
|
-
'Use `pages` to define static terms and conditions page.'
|
276
|
-
);
|
277
|
-
app.get('/terms-and-conditions', (req, res) => {
|
278
|
-
const locals = Object.assign({}, req.translate('terms'));
|
279
|
-
res.render('terms', locals);
|
280
|
-
});
|
281
|
-
}
|
282
|
-
|
283
|
-
app.use(userMiddleware);
|
284
|
-
app.use(hofMiddleware.cookies(config));
|
285
|
-
loadRoutes(app, config);
|
286
|
-
applyErrorMiddlewares(app, config);
|
287
|
-
|
288
|
-
const instance = {
|
289
|
-
use() {
|
290
|
-
userMiddleware.use.apply(userMiddleware, arguments);
|
291
|
-
return instance;
|
292
|
-
},
|
293
|
-
|
294
|
-
server: null,
|
295
|
-
|
296
|
-
start: sConfig => {
|
297
|
-
let startConfig = sConfig;
|
298
|
-
startConfig = getConfig(config, startConfig);
|
299
|
-
|
300
|
-
const protocol = startConfig.protocol === 'http' ? http : https;
|
301
|
-
|
302
|
-
instance.server = protocol.createServer(app);
|
303
|
-
|
304
|
-
return new Promise((resolve, reject) => {
|
305
|
-
instance.server.listen(startConfig.port, startConfig.host, err => {
|
306
|
-
if (err) {
|
307
|
-
reject(new Error('Unable to connect to server'));
|
308
|
-
}
|
309
|
-
config.logger.log('info', `${config.appName} started!`);
|
310
|
-
resolve(instance);
|
311
|
-
});
|
312
|
-
});
|
313
|
-
},
|
314
|
-
|
315
|
-
stop() {
|
316
|
-
return new Promise((resolve, reject) => instance.server.close(err => {
|
317
|
-
if (err) {
|
318
|
-
reject(new Error('Unable to stop server'));
|
319
|
-
}
|
320
|
-
config.logger.log('info', `${config.appName} stopped!`);
|
321
|
-
resolve(instance);
|
322
|
-
}));
|
323
|
-
}
|
324
|
-
};
|
325
|
-
|
326
|
-
if (config.start !== false) {
|
327
|
-
instance.start(config);
|
328
|
-
}
|
329
|
-
|
330
|
-
return instance;
|
331
|
-
}
|
332
|
-
|
333
|
-
bootstrap.configure = function (key, val) {
|
334
|
-
if (arguments.length === 2 && typeof key === 'string') {
|
335
|
-
customConfig[key] = val;
|
336
|
-
} else if (typeof key === 'object') {
|
337
|
-
Object.assign(customConfig, key);
|
338
|
-
}
|
339
|
-
};
|
340
|
-
|
341
|
-
module.exports = bootstrap;
|
342
|
-
module.exports.build = require('./build/');
|
343
|
-
module.exports.transpiler = require('./transpiler/');
|
344
|
-
module.exports.middleware = require('./middleware');
|
345
|
-
module.exports.controller = require('./controller');
|
346
|
-
module.exports.model = require('./model');
|
347
|
-
module.exports.apis = require('./model/apis');
|
348
|
-
module.exports.wizard = require('./wizard');
|
349
|
-
module.exports.components = require('./components');
|
350
|
-
module.exports.utils = require('./utilities');
|
351
|
-
module.exports.frontend = require('./frontend');
|
package/package/lib/deindex.js
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
module.exports = (app, config) => {
|
4
|
-
// Ensure the value of deIndex is evaluated as a boolean regardless of if single quotes are used
|
5
|
-
// to have the expected conditional behaviour in the Mustache template
|
6
|
-
const deIndex = (config.deIndexForm === 'true' || config.deIndexForm === true);
|
7
|
-
|
8
|
-
app.use((req, res, next) => {
|
9
|
-
// Preparing common res.locals properties
|
10
|
-
const properties = {
|
11
|
-
deIndex: deIndex
|
12
|
-
};
|
13
|
-
res.locals = Object.assign(res.locals, properties);
|
14
|
-
next();
|
15
|
-
});
|
16
|
-
|
17
|
-
return app;
|
18
|
-
};
|
@@ -1,23 +0,0 @@
|
|
1
|
-
/* eslint-disable */
|
2
|
-
'use strict';
|
3
|
-
|
4
|
-
const crypto = require('crypto');
|
5
|
-
const algorithm = 'aes-256-cbc';
|
6
|
-
|
7
|
-
module.exports = password => ({
|
8
|
-
|
9
|
-
encrypt: text => {
|
10
|
-
const cipher = crypto.createCipher(algorithm, password);
|
11
|
-
let crypted = cipher.update(text, 'utf8', 'hex');
|
12
|
-
crypted += cipher.final('hex');
|
13
|
-
return crypted;
|
14
|
-
},
|
15
|
-
|
16
|
-
decrypt: text => {
|
17
|
-
const decipher = crypto.createDecipher(algorithm, password);
|
18
|
-
let dec = decipher.update(text, 'hex', 'utf8');
|
19
|
-
dec += decipher.final('utf8');
|
20
|
-
return dec;
|
21
|
-
}
|
22
|
-
|
23
|
-
});
|
package/package/lib/ga-tag.js
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
const _ = require('lodash');
|
4
|
-
|
5
|
-
const convertToGTMPage = text => {
|
6
|
-
// Remove leading and trailing slashes
|
7
|
-
let str = text.replace(/^\/|\/$/g, '');
|
8
|
-
// Replace hyphens with spaces and capitalize each word
|
9
|
-
str = str.replace(/-+/g, ' ').replace(/(^|\s)\S/g, function (match) {
|
10
|
-
return match.toUpperCase();
|
11
|
-
});
|
12
|
-
return str;
|
13
|
-
};
|
14
|
-
|
15
|
-
const pageView = (path, pageMap) => pageMap.get(path) || path;
|
16
|
-
|
17
|
-
const createUris = routes => {
|
18
|
-
const uris = _.map(routes, subApp => {
|
19
|
-
let subAppUris = Object.keys(subApp.steps || {});
|
20
|
-
const subAppBaseUrl = subApp.baseUrl;
|
21
|
-
|
22
|
-
if (subAppBaseUrl) {
|
23
|
-
subAppUris = _.map(subAppUris, uri => `${subAppBaseUrl}${uri}`);
|
24
|
-
subAppUris.unshift(subAppBaseUrl);
|
25
|
-
}
|
26
|
-
return subAppUris;
|
27
|
-
});
|
28
|
-
|
29
|
-
return _.flatten(uris);
|
30
|
-
};
|
31
|
-
|
32
|
-
const createIdentifiers = routes => _.map(routes, route => {
|
33
|
-
const routeIdentifier = route
|
34
|
-
.replace(/^[^A-Z0-9]+/gi, '')
|
35
|
-
.toLowerCase()
|
36
|
-
.replace(/([^A-Z0-9]+)(.)/ig, function () {
|
37
|
-
return arguments[2].toUpperCase();
|
38
|
-
});
|
39
|
-
|
40
|
-
return [route, routeIdentifier];
|
41
|
-
});
|
42
|
-
|
43
|
-
const setupPageMap = routes => {
|
44
|
-
let mappedRoutes = createUris(routes);
|
45
|
-
mappedRoutes = createIdentifiers(mappedRoutes);
|
46
|
-
|
47
|
-
const pageMap = new Map(mappedRoutes);
|
48
|
-
|
49
|
-
return pageMap;
|
50
|
-
};
|
51
|
-
|
52
|
-
module.exports = (app, config) => {
|
53
|
-
const gaTagId = config.gaTagId;
|
54
|
-
const ga4TagId = config.ga4TagId;
|
55
|
-
const gtm = config.gtm;
|
56
|
-
const gaCrossDomainTrackingTagId = config.gaCrossDomainTrackingTagId;
|
57
|
-
const routes = config.routes;
|
58
|
-
|
59
|
-
if (gaTagId || ga4TagId || gtm.tagId) {
|
60
|
-
const pageMap = setupPageMap(routes);
|
61
|
-
|
62
|
-
app.use((req, res, next) => {
|
63
|
-
const page = pageView(req.path, pageMap);
|
64
|
-
|
65
|
-
// Preparing common res.locals properties
|
66
|
-
const properties = {
|
67
|
-
gaAllowDebug: config.env === 'development',
|
68
|
-
gaTagId: gaTagId,
|
69
|
-
ga4TagId: ga4TagId,
|
70
|
-
gaCrossDomainTrackingTagId: gaCrossDomainTrackingTagId,
|
71
|
-
'ga-id': gaTagId,
|
72
|
-
'ga-page': page
|
73
|
-
};
|
74
|
-
|
75
|
-
// Adding extra properties if a GTM TAG is available
|
76
|
-
if (gtm.tagId) {
|
77
|
-
gtm.config.pageName = gtm.composePageName(page, convertToGTMPage);
|
78
|
-
Object.assign(properties, {
|
79
|
-
gtmConfig: JSON.stringify(gtm.config),
|
80
|
-
gtmTagId: gtm.tagId
|
81
|
-
});
|
82
|
-
}
|
83
|
-
res.locals = Object.assign(res.locals, properties);
|
84
|
-
next();
|
85
|
-
});
|
86
|
-
}
|
87
|
-
|
88
|
-
return app;
|
89
|
-
};
|
package/package/lib/health.js
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This file provides readiness and liveness checks for use with Kubernetes.
|
3
|
-
* For information on how to set them up, look at the Kubernetes documentation:
|
4
|
-
*
|
5
|
-
* https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
|
6
|
-
*
|
7
|
-
*/
|
8
|
-
'use strict';
|
9
|
-
|
10
|
-
const router = require('express').Router();
|
11
|
-
const healthCheck = require('express-healthcheck');
|
12
|
-
|
13
|
-
module.exports = redis => {
|
14
|
-
router.get('/ping', healthCheck());
|
15
|
-
|
16
|
-
router.get('/readiness', healthCheck({
|
17
|
-
test: () => {
|
18
|
-
if (!redis.connected && !redis.ready) {
|
19
|
-
return new Error('Session store unhealthy');
|
20
|
-
}
|
21
|
-
return 0;
|
22
|
-
}
|
23
|
-
}));
|
24
|
-
|
25
|
-
return router;
|
26
|
-
};
|
package/package/lib/helpers.js
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
const fs = require('fs');
|
4
|
-
const path = require('path');
|
5
|
-
|
6
|
-
const getPath = (config, part) => {
|
7
|
-
let result = config.route[part] && path.resolve(config.root, config.route[part]);
|
8
|
-
if (!result) {
|
9
|
-
result = config.route.name && path.resolve(config.root, `apps/${config.route.name}/${part}`);
|
10
|
-
}
|
11
|
-
return result;
|
12
|
-
};
|
13
|
-
|
14
|
-
module.exports = class Helpers {
|
15
|
-
static getPaths(config) {
|
16
|
-
return {
|
17
|
-
fields: {
|
18
|
-
base: config.fields && path.resolve(config.root, config.fields),
|
19
|
-
route: getPath(config, 'fields')
|
20
|
-
},
|
21
|
-
views: getPath(config, 'views'),
|
22
|
-
translations: getPath(config, 'translations')
|
23
|
-
};
|
24
|
-
}
|
25
|
-
|
26
|
-
static getViews(views, strict) {
|
27
|
-
if (views) {
|
28
|
-
try {
|
29
|
-
fs.accessSync(views);
|
30
|
-
} catch (err) {
|
31
|
-
if (strict) {
|
32
|
-
throw new Error(`Cannot find route views at ${views}`);
|
33
|
-
} else {
|
34
|
-
return null;
|
35
|
-
}
|
36
|
-
}
|
37
|
-
}
|
38
|
-
return views;
|
39
|
-
}
|
40
|
-
|
41
|
-
static getFields(pathFields) {
|
42
|
-
let routeFields;
|
43
|
-
let fields;
|
44
|
-
|
45
|
-
if (pathFields.base) {
|
46
|
-
try {
|
47
|
-
fields = require(pathFields.base);
|
48
|
-
} catch (err) {
|
49
|
-
throw new Error(`Cannot find fields at ${pathFields.base}`);
|
50
|
-
}
|
51
|
-
}
|
52
|
-
if (pathFields.route) {
|
53
|
-
try {
|
54
|
-
routeFields = require(pathFields.route);
|
55
|
-
} catch (err) {
|
56
|
-
throw new Error(`Cannot find route fields at ${pathFields.route}`);
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
|
-
if (!fields && !routeFields) {
|
61
|
-
throw new Error('Set base fields or route fields or both');
|
62
|
-
}
|
63
|
-
|
64
|
-
return Object.assign({}, fields, routeFields);
|
65
|
-
}
|
66
|
-
};
|