@dwp/govuk-casa 7.0.6 → 8.0.0-alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +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 +10 -0
- package/dist/casa.js +44 -0
- package/dist/lib/CasaTemplateLoader.d.ts +19 -0
- package/dist/lib/CasaTemplateLoader.js +57 -0
- package/dist/lib/JourneyContext.d.ts +255 -0
- package/dist/lib/JourneyContext.js +681 -0
- package/dist/lib/MutableRouter.d.ts +155 -0
- package/dist/lib/MutableRouter.js +272 -0
- package/dist/lib/Plan.d.ts +119 -0
- package/dist/lib/Plan.js +382 -0
- package/dist/lib/ValidationError.d.ts +70 -0
- package/dist/lib/ValidationError.js +156 -0
- package/dist/lib/ValidatorFactory.d.ts +24 -0
- package/dist/lib/ValidatorFactory.js +87 -0
- package/dist/lib/configure.d.ts +205 -0
- package/dist/lib/configure.js +215 -0
- package/dist/lib/dirname.cjs +1 -0
- package/dist/lib/end-session.d.ts +12 -0
- package/dist/lib/end-session.js +24 -0
- package/dist/lib/field.d.ts +79 -0
- package/dist/lib/field.js +223 -0
- package/dist/lib/logger.d.ts +8 -0
- package/dist/lib/logger.js +19 -0
- package/dist/lib/nunjucks-filters.d.ts +26 -0
- package/dist/lib/nunjucks-filters.js +112 -0
- package/dist/lib/nunjucks.d.ts +22 -0
- package/dist/lib/nunjucks.js +49 -0
- package/dist/lib/utils.d.ts +22 -0
- package/dist/lib/utils.js +44 -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 +17 -0
- package/dist/lib/waypoint-url.js +46 -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 +6 -0
- package/dist/middleware/data.js +53 -0
- package/dist/middleware/dirname.cjs +1 -0
- package/dist/middleware/gather-fields.d.ts +5 -0
- package/dist/middleware/gather-fields.js +39 -0
- package/dist/middleware/i18n.d.ts +4 -0
- package/dist/middleware/i18n.js +87 -0
- package/dist/middleware/post.d.ts +1 -0
- package/dist/middleware/post.js +42 -0
- package/dist/middleware/pre.d.ts +3 -0
- package/dist/middleware/pre.js +38 -0
- package/dist/middleware/progress-journey.d.ts +6 -0
- package/dist/middleware/progress-journey.js +82 -0
- package/dist/middleware/sanitise-fields.d.ts +5 -0
- package/dist/middleware/sanitise-fields.js +48 -0
- package/dist/middleware/session.d.ts +10 -0
- package/dist/middleware/session.js +115 -0
- package/dist/middleware/skip-waypoint.d.ts +5 -0
- package/dist/middleware/skip-waypoint.js +40 -0
- package/dist/middleware/steer-journey.d.ts +6 -0
- package/dist/middleware/steer-journey.js +44 -0
- package/dist/middleware/validate-fields.d.ts +7 -0
- package/dist/middleware/validate-fields.js +76 -0
- package/dist/mjs/esm-wrapper.js +10 -0
- package/dist/mjs/package.json +3 -0
- package/dist/package.json +3 -0
- package/dist/routes/ancillary.d.ts +4 -0
- package/dist/routes/ancillary.js +19 -0
- package/dist/routes/dirname.cjs +1 -0
- package/dist/routes/journey.d.ts +8 -0
- package/dist/routes/journey.js +130 -0
- package/dist/routes/static.d.ts +26 -0
- package/dist/routes/static.js +67 -0
- package/package.json +45 -86
- 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/layouts/journey.njk +26 -9
- package/views/casa/layouts/main.njk +6 -19
- 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
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// If a session ID already exists, then a call here would indicate that
|
|
2
|
-
// the session ID is associated with a session that no longer exists, i.e.
|
|
3
|
-
// it has been removed from storage through either expiry, or error.
|
|
4
|
-
// Setting `req.casaSessionExpired` flags the session for destruction by
|
|
5
|
-
// the next middleware in the chain.
|
|
6
|
-
// We can only check for an undefined req.session here because by the time
|
|
7
|
-
// this function returns, a new session will have been created.
|
|
8
|
-
|
|
9
|
-
const uid = require('uid-safe');
|
|
10
|
-
|
|
11
|
-
module.exports = (logger) => (req) => {
|
|
12
|
-
if (req.sessionID && typeof req.session === 'undefined') {
|
|
13
|
-
logger.debug('Server session %s has expired. Flagging for destruction.', req.sessionID);
|
|
14
|
-
req.casaSessionExpired = req.sessionID;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return uid.sync(32);
|
|
18
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prepare session.
|
|
3
|
-
*
|
|
4
|
-
* Enhances `req` with:
|
|
5
|
-
* object session = Current session
|
|
6
|
-
* model/claim claim = Current Claim state.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const logger = require('../../lib/Logger.js')('session');
|
|
10
|
-
const mwInit = require('./init.js');
|
|
11
|
-
const mwExpiry = require('./expiry.js');
|
|
12
|
-
const mwSeed = require('./seed.js');
|
|
13
|
-
|
|
14
|
-
module.exports = (app, mountUrl, sessionExpiryController, sessionConfig) => {
|
|
15
|
-
app.use(mwInit(logger, sessionConfig));
|
|
16
|
-
app.use(mwExpiry(logger, mountUrl, sessionExpiryController, sessionConfig));
|
|
17
|
-
app.use(mwSeed(logger));
|
|
18
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Use session middleware.
|
|
3
|
-
* This will hydrate the HTTP request with a `session` object containing the
|
|
4
|
-
* session data.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const expressSession = require('express-session');
|
|
8
|
-
const genid = require('./genid.js');
|
|
9
|
-
|
|
10
|
-
module.exports = (logger, config) => expressSession({
|
|
11
|
-
store: config.store,
|
|
12
|
-
secret: config.secret,
|
|
13
|
-
resave: false,
|
|
14
|
-
saveUninitialized: false,
|
|
15
|
-
cookie: {
|
|
16
|
-
secure: config.secure,
|
|
17
|
-
httpOnly: true,
|
|
18
|
-
path: config.cookiePath,
|
|
19
|
-
maxAge: null,
|
|
20
|
-
sameSite: config.cookieSameSite,
|
|
21
|
-
},
|
|
22
|
-
name: config.name,
|
|
23
|
-
unset: 'destroy',
|
|
24
|
-
genid: genid(logger),
|
|
25
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// Create an object in `req.casa.journeyContext` to represent the data gathered
|
|
2
|
-
// during the user's journey through the defined pages.
|
|
3
|
-
|
|
4
|
-
const { DEFAULT_CONTEXT_ID } = require('../../lib/enums.js');
|
|
5
|
-
const commonBodyParser = require('../../lib/commonBodyParser.js');
|
|
6
|
-
const JourneyContext = require('../../lib/JourneyContext.js');
|
|
7
|
-
|
|
8
|
-
const extractRequestedContextId = (request) => {
|
|
9
|
-
let contextId;
|
|
10
|
-
|
|
11
|
-
switch (request.method) {
|
|
12
|
-
case 'GET':
|
|
13
|
-
contextId = request.query.contextid;
|
|
14
|
-
break;
|
|
15
|
-
case 'POST':
|
|
16
|
-
contextId = request.body.contextid;
|
|
17
|
-
break;
|
|
18
|
-
default:
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return contextId || DEFAULT_CONTEXT_ID;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
module.exports = (logger) => ([commonBodyParser, (req, res, next) => {
|
|
26
|
-
if (!req.session) {
|
|
27
|
-
next();
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
req.casa = req.casa || Object.create(null);
|
|
32
|
-
|
|
33
|
-
// Load requested journey context from session. This will remain the "active
|
|
34
|
-
// context" for the duration of the request.
|
|
35
|
-
JourneyContext.initContextStore(req.session);
|
|
36
|
-
let contextId = extractRequestedContextId(req);
|
|
37
|
-
try {
|
|
38
|
-
contextId = JourneyContext.validateContextId(contextId);
|
|
39
|
-
req.casa.journeyContext = JourneyContext.getContextById(req.session, contextId);
|
|
40
|
-
} catch (ex) {
|
|
41
|
-
logger.error(ex.message);
|
|
42
|
-
}
|
|
43
|
-
if (!req.casa.journeyContext) {
|
|
44
|
-
logger.info(`Context '${contextId}' not found. Will use 'default'`);
|
|
45
|
-
req.casa.journeyContext = JourneyContext.getContextById(req.session, DEFAULT_CONTEXT_ID);
|
|
46
|
-
// TODO: remove contextid from req.query / req.body?
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
next();
|
|
50
|
-
}]);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
|
|
3
|
-
module.exports = (logger, packagesMeta = {}) => {
|
|
4
|
-
const casaPackageVersions = Object.create(null);
|
|
5
|
-
|
|
6
|
-
Object.keys(packagesMeta).forEach((k) => {
|
|
7
|
-
let version;
|
|
8
|
-
try {
|
|
9
|
-
// read() rather than require() to avoid accidental execution of source
|
|
10
|
-
({ version } = JSON.parse(fs.readFileSync(packagesMeta[k], 'utf8')));
|
|
11
|
-
} catch (ex) {
|
|
12
|
-
logger.debug('Cannot parse file %s (%s) to find version', k, packagesMeta[k]);
|
|
13
|
-
logger.error(ex);
|
|
14
|
-
version = '';
|
|
15
|
-
}
|
|
16
|
-
casaPackageVersions[k] = version;
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
return (req, res, next) => {
|
|
20
|
-
res.locals.casa.packageVersions = casaPackageVersions;
|
|
21
|
-
next();
|
|
22
|
-
};
|
|
23
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configure GOVUK templates, and CASA static resources.
|
|
3
|
-
*
|
|
4
|
-
* CASA resources are compiled on-the-fly, stored in the specified
|
|
5
|
-
* `compiledAssetsDir` directory and served from the `/govuk/casa/(css/js)/*`
|
|
6
|
-
* folders.
|
|
7
|
-
*
|
|
8
|
-
* The `govuk_template_jinja` module provides the main Nunjucks templates, as
|
|
9
|
-
* well as some static image/css/js assets. We point the virtual `/govuk/tpl/`
|
|
10
|
-
* URL prefix to these assets.
|
|
11
|
-
*
|
|
12
|
-
* The `govuk_frontend_toolkit` modules provides some static image
|
|
13
|
-
* assets. We point the virtual `/govuk/kit/images/` URL prefix to these. It
|
|
14
|
-
* also provides some static JS assets, which are concatenated on-the-fly and
|
|
15
|
-
* accessed via the `/govuk/kit/js/govuk_toolkit.js` URL.
|
|
16
|
-
*
|
|
17
|
-
* Mounted on `app` rather than `router` otherwise all other `app`-bound
|
|
18
|
-
* middleware continues to execute after router has completed, which isn't
|
|
19
|
-
* what we want for static resources.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
const path = require('path');
|
|
23
|
-
const fs = require('fs');
|
|
24
|
-
const logger = require('../../lib/Logger.js')('static');
|
|
25
|
-
|
|
26
|
-
const mwPrepareAssets = require('./prepare-assets.js');
|
|
27
|
-
const mwServeAssets = require('./serve-assets.js');
|
|
28
|
-
const mwVersions = require('./asset-versions.js');
|
|
29
|
-
|
|
30
|
-
const onehour = 3600000;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Arguments object:
|
|
34
|
-
* app: Express app instance <Express.App>
|
|
35
|
-
* mountUrl: CASA application mount url <string>
|
|
36
|
-
* proxyMountUrl: CASA application proxy mount url <string>
|
|
37
|
-
* compiledAssetsDir: Absolute path to diretory that will contain static
|
|
38
|
-
* npmPackages: List of paths to npm packages <object>
|
|
39
|
-
* govukFrontend: govuk-frontend npm package path <string>,
|
|
40
|
-
* govukTemplateJinja: govuk_template_jinja npm package path <string>
|
|
41
|
-
* govukCasa: @dwp/govuk-casa npm package path <string>
|
|
42
|
-
*
|
|
43
|
-
* @param {object} args See above
|
|
44
|
-
* @returns {void}
|
|
45
|
-
* @throws {ReferenceError}
|
|
46
|
-
*/
|
|
47
|
-
module.exports = (args) => {
|
|
48
|
-
const {
|
|
49
|
-
app,
|
|
50
|
-
mountUrl = '/',
|
|
51
|
-
proxyMountUrl = mountUrl,
|
|
52
|
-
compiledAssetsDir: cAssetsDir,
|
|
53
|
-
npmPackages: {
|
|
54
|
-
govukFrontend = '',
|
|
55
|
-
govukTemplateJinja = '',
|
|
56
|
-
govukCasa = '',
|
|
57
|
-
} = Object.create(null),
|
|
58
|
-
} = args;
|
|
59
|
-
|
|
60
|
-
const compiledAssetsDir = path.resolve(cAssetsDir);
|
|
61
|
-
logger.debug('Preparing compiled assets directory, %s', compiledAssetsDir);
|
|
62
|
-
try {
|
|
63
|
-
fs.accessSync(compiledAssetsDir, fs.F_OK);
|
|
64
|
-
} catch (e) {
|
|
65
|
-
throw new ReferenceError('Compiled static assets directory does not exist');
|
|
66
|
-
}
|
|
67
|
-
logger.info('Compiled static assets dir: %s', compiledAssetsDir);
|
|
68
|
-
|
|
69
|
-
// Store GOVUK template virtual URL prefix for other places to use it. This
|
|
70
|
-
// is the URL from which all GOVUK Frontend client-side assets are served.
|
|
71
|
-
const govukFrontendVirtualUrl = `${mountUrl}/govuk/frontend`.replace(/\/+/g, '/');
|
|
72
|
-
app.set('casaGovukFrontendVirtualUrl', govukFrontendVirtualUrl);
|
|
73
|
-
const govukFrontendVirtualUrlProxy = `${proxyMountUrl}/govuk/frontend`.replace(/\/+/g, '/');
|
|
74
|
-
|
|
75
|
-
const prefixCasa = `${proxyMountUrl}/govuk/casa`.replace(/\/+/g, '/');
|
|
76
|
-
|
|
77
|
-
logger.trace('Calling prepare-assets');
|
|
78
|
-
mwPrepareAssets({
|
|
79
|
-
logger,
|
|
80
|
-
npmGovukCasa: govukCasa,
|
|
81
|
-
compiledAssetsDir,
|
|
82
|
-
mountUrl,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
logger.trace('Calling serve-assets');
|
|
86
|
-
mwServeAssets({
|
|
87
|
-
logger,
|
|
88
|
-
app,
|
|
89
|
-
compiledAssetsDir,
|
|
90
|
-
prefixCasa,
|
|
91
|
-
govukFrontendVirtualUrlProxy,
|
|
92
|
-
npmGovukFrontend: govukFrontend,
|
|
93
|
-
npmGovukTemplateJinja: govukTemplateJinja,
|
|
94
|
-
maxAge: onehour,
|
|
95
|
-
proxyMountUrl,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
logger.trace('Calling asset-versions');
|
|
99
|
-
app.use(mwVersions(logger, {
|
|
100
|
-
govukFrontend: path.resolve(govukFrontend, 'package.json'),
|
|
101
|
-
govukTemplateJinja: path.resolve(govukTemplateJinja, 'package.json'),
|
|
102
|
-
casaMain: path.resolve(__dirname, '../../package.json'),
|
|
103
|
-
}));
|
|
104
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Inject the configured `mountUrl` into the pre-compiled CSS sources, and copy
|
|
3
|
-
* all CSS and JS to the `compiledAssetsDir` directory.
|
|
4
|
-
*
|
|
5
|
-
* @param {string} npmGovukCasa Path to root of `govuk-casa` module.
|
|
6
|
-
* @param {string} compiledAssetsDir Directory where compiled assets are saved.
|
|
7
|
-
* @param {string} mountUrl Mount point.
|
|
8
|
-
* @returns {void}
|
|
9
|
-
* @throws {Error} For any IO errors.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const path = require('path');
|
|
13
|
-
const klaw = require('klaw-sync');
|
|
14
|
-
const {
|
|
15
|
-
readFileSync,
|
|
16
|
-
ensureDirSync,
|
|
17
|
-
writeFileSync,
|
|
18
|
-
copyFile,
|
|
19
|
-
} = require('fs-extra');
|
|
20
|
-
|
|
21
|
-
module.exports = (args) => {
|
|
22
|
-
const {
|
|
23
|
-
logger,
|
|
24
|
-
npmGovukCasa,
|
|
25
|
-
compiledAssetsDir,
|
|
26
|
-
mountUrl,
|
|
27
|
-
} = args;
|
|
28
|
-
|
|
29
|
-
const srcDir = path.resolve(npmGovukCasa, 'dist', 'casa');
|
|
30
|
-
const dstDir = path.resolve(compiledAssetsDir, 'casa');
|
|
31
|
-
const MOUNT_URL_PLACEHOLDER = /~~~CASA_MOUNT_URL~~~/g;
|
|
32
|
-
|
|
33
|
-
// Inject mountUrl into CSS sources and copy across
|
|
34
|
-
klaw(`${srcDir}/css`).map((f) => (f.path)).forEach((file) => {
|
|
35
|
-
const css = readFileSync(file, { encoding: 'utf8' }).replace(MOUNT_URL_PLACEHOLDER, mountUrl);
|
|
36
|
-
const dstPath = path.resolve(`${dstDir}/css`, path.relative(`${srcDir}/css`, file));
|
|
37
|
-
logger.debug('Copying CSS asset from %s to %s', file, dstPath);
|
|
38
|
-
ensureDirSync(path.dirname(dstPath));
|
|
39
|
-
writeFileSync(dstPath, css, {
|
|
40
|
-
encoding: 'utf8',
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// Copy JS sources
|
|
45
|
-
klaw(`${srcDir}/js`).map((f) => (f.path)).forEach((file) => {
|
|
46
|
-
const dstPath = path.resolve(`${dstDir}/js`, path.relative(`${srcDir}/js`, file));
|
|
47
|
-
logger.debug('Copying JS asset from %s to %s', file, dstPath);
|
|
48
|
-
ensureDirSync(path.dirname(dstPath));
|
|
49
|
-
copyFile(file, dstPath);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Serve up all CASA assets from the `compiledAssetsDir` directory, and all
|
|
3
|
-
* third party assets from their respective npm package directories.
|
|
4
|
-
*
|
|
5
|
-
* @param {Function} app Express app.
|
|
6
|
-
* @param {Function} static Static module from ExpressJS.
|
|
7
|
-
* @param {string} compiledAssetsDir Directory where static assets are saved.
|
|
8
|
-
* @param {string} prefixCasa Virtual URL prefix.
|
|
9
|
-
* @returns {void}
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const path = require('path');
|
|
13
|
-
const expStatic = require('express').static;
|
|
14
|
-
|
|
15
|
-
module.exports = (args) => {
|
|
16
|
-
const {
|
|
17
|
-
logger,
|
|
18
|
-
app,
|
|
19
|
-
compiledAssetsDir,
|
|
20
|
-
prefixCasa,
|
|
21
|
-
govukFrontendVirtualUrlProxy,
|
|
22
|
-
npmGovukFrontend,
|
|
23
|
-
npmGovukTemplateJinja,
|
|
24
|
-
maxAge = 3600000,
|
|
25
|
-
proxyMountUrl = '/',
|
|
26
|
-
} = args;
|
|
27
|
-
|
|
28
|
-
const mounts = [{
|
|
29
|
-
url: prefixCasa,
|
|
30
|
-
path: path.resolve(compiledAssetsDir, 'casa'),
|
|
31
|
-
}, {
|
|
32
|
-
url: `${govukFrontendVirtualUrlProxy}/js/all.js`,
|
|
33
|
-
path: `${npmGovukFrontend}/govuk/all.js`,
|
|
34
|
-
}, {
|
|
35
|
-
url: `${govukFrontendVirtualUrlProxy}/assets`,
|
|
36
|
-
path: `${npmGovukFrontend}/govuk/assets`,
|
|
37
|
-
}, {
|
|
38
|
-
url: `${govukFrontendVirtualUrlProxy}/js/govuk-template.js`,
|
|
39
|
-
path: `${npmGovukTemplateJinja}/assets/javascripts/govuk-template.js`,
|
|
40
|
-
}, {
|
|
41
|
-
url: `${proxyMountUrl}browserconfig.xml`,
|
|
42
|
-
path: path.resolve(__dirname, '../../src/browserconfig.xml'),
|
|
43
|
-
}];
|
|
44
|
-
|
|
45
|
-
mounts.forEach((m) => {
|
|
46
|
-
logger.debug('Mounting %s to serve from %s', m.url, m.path);
|
|
47
|
-
app.use(m.url, expStatic(m.path, {
|
|
48
|
-
etag: true,
|
|
49
|
-
lastModified: false,
|
|
50
|
-
maxAge,
|
|
51
|
-
}));
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// Catch-all 404s
|
|
55
|
-
[prefixCasa, govukFrontendVirtualUrlProxy].forEach((root) => {
|
|
56
|
-
app.use(root, (req, res) => res.status(404).send('Not found'));
|
|
57
|
-
});
|
|
58
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const logger = require('../../lib/Logger.js')('variables');
|
|
2
|
-
const mwVariables = require('./variables.js');
|
|
3
|
-
|
|
4
|
-
module.exports = (app, mountUrl, phase, serviceName) => {
|
|
5
|
-
app.use(mwVariables({
|
|
6
|
-
logger,
|
|
7
|
-
serviceName,
|
|
8
|
-
govukFrontendVirtualUrl: app.get('casaGovukFrontendVirtualUrl'),
|
|
9
|
-
mountUrl,
|
|
10
|
-
phase,
|
|
11
|
-
}));
|
|
12
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
module.exports = (args) => (req, res, next) => {
|
|
2
|
-
const {
|
|
3
|
-
logger,
|
|
4
|
-
serviceName,
|
|
5
|
-
govukFrontendVirtualUrl,
|
|
6
|
-
mountUrl,
|
|
7
|
-
phase,
|
|
8
|
-
} = args;
|
|
9
|
-
|
|
10
|
-
logger.trace(
|
|
11
|
-
'Setting template variables (govukFrontendVirtualUrl: %s, serviceName: %s, mountUrl: %s, phase: %s)',
|
|
12
|
-
govukFrontendVirtualUrl,
|
|
13
|
-
serviceName,
|
|
14
|
-
mountUrl,
|
|
15
|
-
phase,
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
// Required by GOVUK Frontend
|
|
19
|
-
res.locals.govuk = {
|
|
20
|
-
assetPath: `${govukFrontendVirtualUrl}/assets`,
|
|
21
|
-
components: {
|
|
22
|
-
header: {
|
|
23
|
-
assetsPath: `${govukFrontendVirtualUrl}/assets/images`,
|
|
24
|
-
serviceName: req.i18nTranslator.t(serviceName),
|
|
25
|
-
serviceUrl: mountUrl,
|
|
26
|
-
homepageUrl: 'https://www.gov.uk/',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// CASA-specific vars
|
|
32
|
-
res.locals.casa.mountUrl = mountUrl;
|
|
33
|
-
res.locals.casa.phase = phase;
|
|
34
|
-
next();
|
|
35
|
-
}
|
package/src/browserconfig.xml
DELETED
package/src/js/casa.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/* eslint sonarjs/cognitive-complexity: 0 */
|
|
2
|
-
/**
|
|
3
|
-
* Common setup of a CASA page.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
(function casaJs() {
|
|
7
|
-
/**
|
|
8
|
-
* Polyfill for attaching event listeners to elements.
|
|
9
|
-
*
|
|
10
|
-
* @param {HTMLElement} obj Element to which event is attached.
|
|
11
|
-
* @param {string} ev Event name.
|
|
12
|
-
* @param {Function} func Listener.
|
|
13
|
-
* @returns {void}
|
|
14
|
-
* @throws {Error}
|
|
15
|
-
*/
|
|
16
|
-
function attachEventPolyfill(obj, ev, func) {
|
|
17
|
-
if (obj.addEventListener) {
|
|
18
|
-
obj.addEventListener(ev, func, false);
|
|
19
|
-
} else if (obj.attachEvent) {
|
|
20
|
-
obj.attachEvent('on' + ev, func);
|
|
21
|
-
} else {
|
|
22
|
-
throw new Error('This browser does not support modern event listeners');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Remove the trailing "#" after a redirect
|
|
27
|
-
if ('pushState' in window.history && window.location.hash === '') {
|
|
28
|
-
window.history.replaceState(
|
|
29
|
-
'',
|
|
30
|
-
document.title,
|
|
31
|
-
window.location.pathname + window.location.search
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Focus on error summary, if present. This will allow screen readers to
|
|
36
|
-
// immediately focus on the errors in the form.
|
|
37
|
-
var errorSummary = document.getElementById('error-summary-title');
|
|
38
|
-
if (errorSummary) {
|
|
39
|
-
errorSummary.focus();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Workaround unwanted bfcache (back-forward cache) behaviour in Safari (until
|
|
43
|
-
// we can investigate more into issue #2)
|
|
44
|
-
// Problem:
|
|
45
|
-
// - Pressing back button after submitted a completed form presents a
|
|
46
|
-
// pre-modified version of the form showing stale data.
|
|
47
|
-
// Fix:
|
|
48
|
-
// - When a page is retrieved from the bfcache, force a page reload to show the
|
|
49
|
-
// updated form data
|
|
50
|
-
attachEventPolyfill(window, 'pageshow', function hPageShow(ev) {
|
|
51
|
-
if (ev.persisted) {
|
|
52
|
-
window.location.reload();
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// Initialise all js-controlled GOVUK Frontend UI components
|
|
57
|
-
GOVUKFrontend.initAll();
|
|
58
|
-
|
|
59
|
-
/* ------------------------------------------------ Show/Hide functionality */
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Attach show/hide functionalty.
|
|
63
|
-
*
|
|
64
|
-
* @param {HTMLElement} node Element to init.
|
|
65
|
-
* @returns {void}
|
|
66
|
-
*/
|
|
67
|
-
function casaV1InitShowHide(node) {
|
|
68
|
-
var fieldName = node.getAttribute('name');
|
|
69
|
-
var initNodes = document.querySelectorAll('[name="' + fieldName + '"]:not([data-target-init-done])');
|
|
70
|
-
var nodeGroup = document.querySelectorAll('[name="' + fieldName + '"]');
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Show target.
|
|
74
|
-
*
|
|
75
|
-
* @param {HTMLElement} targetEl Target.
|
|
76
|
-
* @returns {void}
|
|
77
|
-
*/
|
|
78
|
-
function showTarget(targetEl) {
|
|
79
|
-
/* eslint-disable-next-line no-param-reassign */
|
|
80
|
-
targetEl.className = targetEl.className.replace(/ *js-hidden/, '');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Hide target.
|
|
85
|
-
*
|
|
86
|
-
* @param {HTMLElement} targetEl Target.
|
|
87
|
-
* @returns {void}
|
|
88
|
-
*/
|
|
89
|
-
function hideTarget(targetEl) {
|
|
90
|
-
/* eslint-disable-next-line no-param-reassign */
|
|
91
|
-
targetEl.className = targetEl.className.replace(/ *js-hidden/, '') + ' js-hidden';
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Click node.
|
|
96
|
-
*
|
|
97
|
-
* @returns {void}
|
|
98
|
-
*/
|
|
99
|
-
function clickNode() {
|
|
100
|
-
for (var i = 0, l = nodeGroup.length; i < l; i += 1) {
|
|
101
|
-
if (nodeGroup[i].getAttribute('data-target')) {
|
|
102
|
-
var targetEl = document.getElementById(nodeGroup[i].getAttribute('data-target'));
|
|
103
|
-
if (nodeGroup[i].checked) {
|
|
104
|
-
showTarget(targetEl);
|
|
105
|
-
} else {
|
|
106
|
-
hideTarget(targetEl);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
for (var i = 0, l = initNodes.length; i < l; i += 1) {
|
|
113
|
-
attachEventPolyfill(initNodes[i], 'click', clickNode);
|
|
114
|
-
initNodes[i].setAttribute('data-target-init-done', true);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Initialise state based on pre-populated inputs
|
|
118
|
-
clickNode();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
document.onreadystatechange = function hReayStateChange() {
|
|
122
|
-
var nodeList;
|
|
123
|
-
var i;
|
|
124
|
-
var l;
|
|
125
|
-
if (document.readyState === 'complete') {
|
|
126
|
-
nodeList = document.querySelectorAll('[data-target]');
|
|
127
|
-
for (i = 0, l = nodeList.length; i < l; i += 1) {
|
|
128
|
-
casaV1InitShowHide(nodeList[i]);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}());
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// JavaScript-managed hidden elements
|
|
2
|
-
// govuk_template_jinja uses its js-hidden class slightly differently to CASA;
|
|
3
|
-
// it adds the class using JavaScript vs CASA's method of showing it and only
|
|
4
|
-
// hiding if the `.js-enabled` root class is set.
|
|
5
|
-
.js-hidden {
|
|
6
|
-
display: block;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.js-enabled .js-hidden {
|
|
10
|
-
display: none;
|
|
11
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This contains a few styles taken directly from the govuk_template_jinja
|
|
3
|
-
* module, which saves us having to import the whole
|
|
4
|
-
* `assets/stylesheets/govuk-template.css` file and running into possible
|
|
5
|
-
* conflicts with the `govuk-frontend` styles.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/* ---------------------------------------------------- Global cookie message */
|
|
9
|
-
#global-header-bar, #global-cookie-message p, #footer .footer-wrapper {
|
|
10
|
-
max-width: 960px;
|
|
11
|
-
margin: 0 15px; }
|
|
12
|
-
@media (min-width: 641px) {
|
|
13
|
-
#global-header-bar, #global-cookie-message p, #footer .footer-wrapper {
|
|
14
|
-
margin: 0 30px; } }
|
|
15
|
-
@media (min-width: 1020px) {
|
|
16
|
-
#global-header-bar, #global-cookie-message p, #footer .footer-wrapper {
|
|
17
|
-
margin: 0 auto; } }
|
|
18
|
-
|
|
19
|
-
.js-enabled #global-cookie-message {
|
|
20
|
-
display: none;
|
|
21
|
-
/* shown with JS, always on for non-JS */ }
|
|
22
|
-
|
|
23
|
-
#global-cookie-message {
|
|
24
|
-
width: 100%;
|
|
25
|
-
background-color: #d5e8f3;
|
|
26
|
-
padding-top: 10px;
|
|
27
|
-
padding-bottom: 10px; }
|
|
28
|
-
#global-cookie-message p {
|
|
29
|
-
font-family: "nta", Arial, sans-serif;
|
|
30
|
-
font-weight: 400;
|
|
31
|
-
text-transform: none;
|
|
32
|
-
font-size: 14px;
|
|
33
|
-
line-height: 1.14286;
|
|
34
|
-
margin-top: 0;
|
|
35
|
-
margin-bottom: 0; }
|
|
36
|
-
@media (min-width: 641px) {
|
|
37
|
-
#global-cookie-message p {
|
|
38
|
-
font-size: 16px;
|
|
39
|
-
line-height: 1.25; } }
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// URL prefix that will be used to serve up static assets from the
|
|
2
|
-
// `govuk_frontend_toolkit` images directory.
|
|
3
|
-
// Usage in your own sass source:
|
|
4
|
-
// $casaMountUrl: "/path/to/your/defined/mount/url";
|
|
5
|
-
// @import 'node_modules/govuk-casa/src/css/casaMountUrl';
|
|
6
|
-
|
|
7
|
-
$casaMountUrl: "~~~CASA_MOUNT_URL~~~" !default;
|
|
8
|
-
$govuk-assets-path: $casaMountUrl + "govuk/frontend/assets/";
|
package/src/scss/casa-ie8.scss
DELETED
package/src/scss/casa.scss
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// Sets the mount url
|
|
2
|
-
// In the CASA middleware, this will be import the configured mount url
|
|
3
|
-
// dynamically.
|
|
4
|
-
@import 'casaMountUrl.scss';
|
|
5
|
-
|
|
6
|
-
// Import GOV.UK elements, this will import from govuk-frontend.
|
|
7
|
-
@import 'all.scss';
|
|
8
|
-
|
|
9
|
-
// Some polyfilled CSS taken from the govuk_template_jinja module, because
|
|
10
|
-
// we don't want to inherit all its CSS
|
|
11
|
-
@import 'casaGovukTemplateJinjaPolyfill.scss';
|
|
12
|
-
|
|
13
|
-
// Some CASA-specific styles
|
|
14
|
-
@import 'casaElements.scss';
|