@dwp/govuk-casa 9.7.0 → 10.1.0
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/dist/assets/css/casa.css +1 -1
- package/dist/assets/css/casa.css.map +1 -1
- package/dist/casa.d.ts +90 -44
- package/dist/casa.d.ts.map +1 -0
- package/dist/casa.js +85 -101
- package/dist/core-plugins/edit-snapshot/src/configure.d.ts +1 -0
- package/dist/core-plugins/edit-snapshot/src/configure.d.ts.map +1 -0
- package/dist/core-plugins/edit-snapshot/src/configure.js +7 -14
- package/dist/core-plugins/edit-snapshot/src/index.d.ts +1 -0
- package/dist/core-plugins/edit-snapshot/src/index.d.ts.map +1 -0
- package/dist/core-plugins/edit-snapshot/src/index.js +3 -9
- package/dist/core-plugins/edit-snapshot/src/post-steer-hook.d.ts +2 -1
- package/dist/core-plugins/edit-snapshot/src/post-steer-hook.d.ts.map +1 -0
- package/dist/core-plugins/edit-snapshot/src/post-steer-hook.js +8 -13
- package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.d.ts +2 -1
- package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.d.ts.map +1 -0
- package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.js +13 -18
- package/dist/core-plugins/edit-snapshot/src/utils.d.ts +8 -5
- package/dist/core-plugins/edit-snapshot/src/utils.d.ts.map +1 -0
- package/dist/core-plugins/edit-snapshot/src/utils.js +37 -19
- package/dist/core-plugins/index.d.ts +1 -0
- package/dist/core-plugins/index.d.ts.map +1 -0
- package/dist/core-plugins/index.js +1 -9
- package/dist/lib/CasaTemplateLoader.d.ts +1 -0
- package/dist/lib/CasaTemplateLoader.d.ts.map +1 -0
- package/dist/lib/CasaTemplateLoader.js +2 -6
- package/dist/lib/JourneyContext.d.ts +22 -11
- package/dist/lib/JourneyContext.d.ts.map +1 -0
- package/dist/lib/JourneyContext.js +40 -45
- package/dist/lib/MutableRouter.d.ts +79 -55
- package/dist/lib/MutableRouter.d.ts.map +1 -0
- package/dist/lib/MutableRouter.js +53 -45
- package/dist/lib/NullObject.d.ts +3 -0
- package/dist/lib/NullObject.d.ts.map +1 -0
- package/dist/lib/NullObject.js +3 -0
- package/dist/lib/Plan.d.ts +2 -1
- package/dist/lib/Plan.d.ts.map +1 -0
- package/dist/lib/Plan.js +44 -62
- package/dist/lib/ValidationError.d.ts +2 -1
- package/dist/lib/ValidationError.d.ts.map +1 -0
- package/dist/lib/ValidationError.js +3 -11
- package/dist/lib/ValidatorFactory.d.ts +5 -6
- package/dist/lib/ValidatorFactory.d.ts.map +1 -0
- package/dist/lib/ValidatorFactory.js +4 -12
- package/dist/lib/configuration-ingestor.d.ts +10 -22
- package/dist/lib/configuration-ingestor.d.ts.map +1 -0
- package/dist/lib/configuration-ingestor.js +61 -143
- package/dist/lib/configure.d.ts +2 -1
- package/dist/lib/configure.d.ts.map +1 -0
- package/dist/lib/configure.js +40 -52
- package/dist/lib/constants.d.ts +1 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +8 -12
- package/dist/lib/context-id-generators.d.ts +1 -0
- package/dist/lib/context-id-generators.d.ts.map +1 -0
- package/dist/lib/context-id-generators.js +4 -9
- package/dist/lib/end-session.d.ts +2 -1
- package/dist/lib/end-session.d.ts.map +1 -0
- package/dist/lib/end-session.js +4 -11
- package/dist/lib/field.d.ts +2 -1
- package/dist/lib/field.d.ts.map +1 -0
- package/dist/lib/field.js +11 -21
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +13 -65
- package/dist/lib/logger.d.ts +25 -2
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +18 -9
- package/dist/lib/mount.d.ts +1 -0
- package/dist/lib/mount.d.ts.map +1 -0
- package/dist/lib/mount.js +10 -16
- package/dist/lib/nunjucks-filters.d.ts +7 -3
- package/dist/lib/nunjucks-filters.d.ts.map +1 -0
- package/dist/lib/nunjucks-filters.js +58 -71
- package/dist/lib/nunjucks.d.ts +4 -4
- package/dist/lib/nunjucks.d.ts.map +1 -0
- package/dist/lib/nunjucks.js +14 -26
- package/dist/lib/utils.d.ts +4 -2
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +14 -28
- package/dist/lib/validators/dateObject.d.ts +1 -0
- package/dist/lib/validators/dateObject.d.ts.map +1 -0
- package/dist/lib/validators/dateObject.js +14 -21
- package/dist/lib/validators/email.d.ts +1 -0
- package/dist/lib/validators/email.d.ts.map +1 -0
- package/dist/lib/validators/email.js +8 -15
- package/dist/lib/validators/inArray.d.ts +1 -0
- package/dist/lib/validators/inArray.d.ts.map +1 -0
- package/dist/lib/validators/inArray.js +8 -15
- package/dist/lib/validators/index.d.ts +1 -0
- package/dist/lib/validators/index.d.ts.map +1 -0
- package/dist/lib/validators/index.js +21 -27
- package/dist/lib/validators/nino.d.ts +1 -0
- package/dist/lib/validators/nino.d.ts.map +1 -0
- package/dist/lib/validators/nino.js +6 -13
- package/dist/lib/validators/postalAddressObject.d.ts +1 -0
- package/dist/lib/validators/postalAddressObject.d.ts.map +1 -0
- package/dist/lib/validators/postalAddressObject.js +12 -19
- package/dist/lib/validators/range.d.ts +1 -0
- package/dist/lib/validators/range.d.ts.map +1 -0
- package/dist/lib/validators/range.js +6 -13
- package/dist/lib/validators/regex.d.ts +1 -0
- package/dist/lib/validators/regex.d.ts.map +1 -0
- package/dist/lib/validators/regex.js +6 -13
- package/dist/lib/validators/required.d.ts +1 -0
- package/dist/lib/validators/required.d.ts.map +1 -0
- package/dist/lib/validators/required.js +9 -17
- package/dist/lib/validators/strlen.d.ts +1 -0
- package/dist/lib/validators/strlen.d.ts.map +1 -0
- package/dist/lib/validators/strlen.js +6 -13
- package/dist/lib/validators/wordCount.d.ts +1 -0
- package/dist/lib/validators/wordCount.d.ts.map +1 -0
- package/dist/lib/validators/wordCount.js +6 -13
- package/dist/lib/waypoint-url.d.ts +3 -2
- package/dist/lib/waypoint-url.d.ts.map +1 -0
- package/dist/lib/waypoint-url.js +12 -19
- package/dist/middleware/body-parser.d.ts +1 -0
- package/dist/middleware/body-parser.d.ts.map +1 -0
- package/dist/middleware/body-parser.js +4 -9
- package/dist/middleware/csrf.d.ts +1 -0
- package/dist/middleware/csrf.d.ts.map +1 -0
- package/dist/middleware/csrf.js +4 -8
- package/dist/middleware/data.d.ts +2 -3
- package/dist/middleware/data.d.ts.map +1 -0
- package/dist/middleware/data.js +23 -25
- package/dist/middleware/gather-fields.d.ts +3 -1
- package/dist/middleware/gather-fields.d.ts.map +1 -0
- package/dist/middleware/gather-fields.js +13 -14
- package/dist/middleware/i18n.d.ts +1 -0
- package/dist/middleware/i18n.d.ts.map +1 -0
- package/dist/middleware/i18n.js +26 -31
- package/dist/middleware/post.d.ts +4 -2
- package/dist/middleware/post.d.ts.map +1 -0
- package/dist/middleware/post.js +6 -11
- package/dist/middleware/pre.d.ts +2 -1
- package/dist/middleware/pre.d.ts.map +1 -0
- package/dist/middleware/pre.js +6 -12
- package/dist/middleware/progress-journey.d.ts +5 -3
- package/dist/middleware/progress-journey.d.ts.map +1 -0
- package/dist/middleware/progress-journey.js +20 -18
- package/dist/middleware/sanitise-fields.d.ts +5 -3
- package/dist/middleware/sanitise-fields.d.ts.map +1 -0
- package/dist/middleware/sanitise-fields.js +25 -17
- package/dist/middleware/serve-first-waypoint.d.ts +1 -0
- package/dist/middleware/serve-first-waypoint.d.ts.map +1 -0
- package/dist/middleware/serve-first-waypoint.js +3 -6
- package/dist/middleware/session.d.ts +15 -0
- package/dist/middleware/session.d.ts.map +1 -0
- package/dist/middleware/session.js +53 -57
- package/dist/middleware/skip-waypoint.d.ts +3 -2
- package/dist/middleware/skip-waypoint.d.ts.map +1 -0
- package/dist/middleware/skip-waypoint.js +15 -14
- package/dist/middleware/steer-journey.d.ts +2 -1
- package/dist/middleware/steer-journey.d.ts.map +1 -0
- package/dist/middleware/steer-journey.js +7 -13
- package/dist/middleware/strip-proxy-path.d.ts +3 -2
- package/dist/middleware/strip-proxy-path.d.ts.map +1 -0
- package/dist/middleware/strip-proxy-path.js +24 -24
- package/dist/middleware/validate-fields.d.ts +7 -4
- package/dist/middleware/validate-fields.d.ts.map +1 -0
- package/dist/middleware/validate-fields.js +22 -11
- package/dist/routes/ancillary.d.ts +1 -0
- package/dist/routes/ancillary.d.ts.map +1 -0
- package/dist/routes/ancillary.js +3 -10
- package/dist/routes/journey.d.ts +7 -2
- package/dist/routes/journey.d.ts.map +1 -0
- package/dist/routes/journey.js +56 -55
- package/dist/routes/static.d.ts +1 -0
- package/dist/routes/static.d.ts.map +1 -0
- package/dist/routes/static.js +15 -23
- package/package.json +30 -36
- package/src/casa.js +63 -31
- package/src/core-plugins/edit-snapshot/src/post-steer-hook.js +1 -0
- package/src/core-plugins/edit-snapshot/src/pre-steer-hook.js +2 -1
- package/src/core-plugins/edit-snapshot/src/utils.js +29 -1
- package/src/lib/JourneyContext.js +31 -28
- package/src/lib/MutableRouter.js +52 -38
- package/src/lib/NullObject.js +4 -0
- package/src/lib/Plan.js +41 -55
- package/src/lib/ValidationError.js +2 -4
- package/src/lib/ValidatorFactory.js +3 -5
- package/src/lib/configuration-ingestor.js +18 -38
- package/src/lib/configure.js +7 -10
- package/src/lib/end-session.js +1 -1
- package/src/lib/field.js +7 -12
- package/src/lib/logger.js +16 -0
- package/src/lib/mount.js +1 -1
- package/src/lib/nunjucks-filters.js +51 -61
- package/src/lib/nunjucks.js +5 -13
- package/src/lib/utils.js +2 -1
- package/src/lib/validators/dateObject.js +3 -4
- package/src/lib/validators/postalAddressObject.js +6 -7
- package/src/lib/validators/required.js +1 -3
- package/src/lib/waypoint-url.js +15 -19
- package/src/middleware/csrf.js +1 -1
- package/src/middleware/data.js +13 -13
- package/src/middleware/gather-fields.js +8 -2
- package/src/middleware/i18n.js +9 -6
- package/src/middleware/post.js +3 -1
- package/src/middleware/pre.js +1 -1
- package/src/middleware/progress-journey.js +8 -0
- package/src/middleware/sanitise-fields.js +17 -2
- package/src/middleware/session.js +53 -12
- package/src/middleware/skip-waypoint.js +8 -1
- package/src/middleware/steer-journey.js +1 -1
- package/src/middleware/strip-proxy-path.js +21 -16
- package/src/middleware/validate-fields.js +19 -0
- package/src/routes/journey.js +18 -8
- package/src/routes/static.js +5 -4
- package/views/casa/layouts/journey.njk +1 -1
- package/views/casa/layouts/main.njk +11 -21
- package/dist/casa.js.map +0 -1
- package/dist/core-plugins/edit-snapshot/src/configure.js.map +0 -1
- package/dist/core-plugins/edit-snapshot/src/index.js.map +0 -1
- package/dist/core-plugins/edit-snapshot/src/post-steer-hook.js.map +0 -1
- package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.js.map +0 -1
- package/dist/core-plugins/edit-snapshot/src/utils.js.map +0 -1
- package/dist/core-plugins/index.js.map +0 -1
- package/dist/lib/CasaTemplateLoader.js.map +0 -1
- package/dist/lib/JourneyContext.js.map +0 -1
- package/dist/lib/MutableRouter.js.map +0 -1
- package/dist/lib/Plan.js.map +0 -1
- package/dist/lib/ValidationError.js.map +0 -1
- package/dist/lib/ValidatorFactory.js.map +0 -1
- package/dist/lib/configuration-ingestor.js.map +0 -1
- package/dist/lib/configure.js.map +0 -1
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/context-id-generators.js.map +0 -1
- package/dist/lib/dirname.cjs +0 -1
- package/dist/lib/dirname.d.cts +0 -2
- package/dist/lib/end-session.js.map +0 -1
- package/dist/lib/field.js.map +0 -1
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/logger.js.map +0 -1
- package/dist/lib/mount.js.map +0 -1
- package/dist/lib/nunjucks-filters.js.map +0 -1
- package/dist/lib/nunjucks.js.map +0 -1
- package/dist/lib/utils.js.map +0 -1
- package/dist/lib/validators/dateObject.js.map +0 -1
- package/dist/lib/validators/email.js.map +0 -1
- package/dist/lib/validators/inArray.js.map +0 -1
- package/dist/lib/validators/index.js.map +0 -1
- package/dist/lib/validators/nino.js.map +0 -1
- package/dist/lib/validators/postalAddressObject.js.map +0 -1
- package/dist/lib/validators/range.js.map +0 -1
- package/dist/lib/validators/regex.js.map +0 -1
- package/dist/lib/validators/required.js.map +0 -1
- package/dist/lib/validators/strlen.js.map +0 -1
- package/dist/lib/validators/wordCount.js.map +0 -1
- package/dist/lib/waypoint-url.js.map +0 -1
- package/dist/middleware/body-parser.js.map +0 -1
- package/dist/middleware/csrf.js.map +0 -1
- package/dist/middleware/data.js.map +0 -1
- package/dist/middleware/dirname.cjs +0 -1
- package/dist/middleware/dirname.d.cts +0 -2
- package/dist/middleware/gather-fields.js.map +0 -1
- package/dist/middleware/i18n.js.map +0 -1
- package/dist/middleware/post.js.map +0 -1
- package/dist/middleware/pre.js.map +0 -1
- package/dist/middleware/progress-journey.js.map +0 -1
- package/dist/middleware/sanitise-fields.js.map +0 -1
- package/dist/middleware/serve-first-waypoint.js.map +0 -1
- package/dist/middleware/session.js.map +0 -1
- package/dist/middleware/skip-waypoint.js.map +0 -1
- package/dist/middleware/steer-journey.js.map +0 -1
- package/dist/middleware/strip-proxy-path.js.map +0 -1
- package/dist/middleware/validate-fields.js.map +0 -1
- package/dist/mjs/esm-wrapper.js +0 -20
- package/dist/mjs/package.json +0 -3
- package/dist/package.json +0 -3
- package/dist/routes/ancillary.js.map +0 -1
- package/dist/routes/dirname.cjs +0 -1
- package/dist/routes/dirname.d.cts +0 -2
- package/dist/routes/journey.js.map +0 -1
- package/dist/routes/static.js.map +0 -1
- package/src/lib/dirname.cjs +0 -1
- package/src/middleware/dirname.cjs +0 -1
- package/src/routes/dirname.cjs +0 -1
package/dist/lib/mount.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const express_1 = require("express");
|
|
7
|
-
const path_to_regexp_1 = require("path-to-regexp");
|
|
8
|
-
const strip_proxy_path_js_1 = __importDefault(require("../middleware/strip-proxy-path.js"));
|
|
9
|
-
const serve_first_waypoint_js_1 = __importDefault(require("../middleware/serve-first-waypoint.js"));
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { pathToRegexp } from "path-to-regexp";
|
|
3
|
+
import stripProxyPathMiddlewareFactory from "../middleware/strip-proxy-path.js";
|
|
4
|
+
import serveFirstWaypointMiddlewareFactory from "../middleware/serve-first-waypoint.js";
|
|
10
5
|
/**
|
|
11
6
|
* @typedef {import("nunjucks").Environment} NunjucksEnvironment
|
|
12
7
|
* @access private
|
|
@@ -46,19 +41,19 @@ const serve_first_waypoint_js_1 = __importDefault(require("../middleware/serve-f
|
|
|
46
41
|
* @param {ExpressRequestHandler[]} args.postMiddleware Middleware
|
|
47
42
|
* @returns {Mounter} Mount
|
|
48
43
|
*/
|
|
49
|
-
|
|
44
|
+
export default ({ nunjucksEnv, mountUrl, plan, staticRouter, ancillaryRouter, journeyRouter, preMiddleware, sessionMiddleware, i18nMiddleware, bodyParserMiddleware, dataMiddleware, postMiddleware, }) => (app, { route = "/", serveFirstWaypoint = false } = {}) => {
|
|
50
45
|
nunjucksEnv.express(app);
|
|
51
46
|
app.set("view engine", "njk");
|
|
52
47
|
// If a `mountUrl` has been defined, then we're potentially in "proxy mode",
|
|
53
48
|
// in which we strip the proxy path prefix from the incoming request URLs.
|
|
54
49
|
if (mountUrl) {
|
|
55
|
-
app.use((
|
|
50
|
+
app.use(stripProxyPathMiddlewareFactory({ mountUrl }));
|
|
56
51
|
}
|
|
57
52
|
// Attach a handler to redirect requests for `/` to the first waypoint in
|
|
58
53
|
// the plan
|
|
59
54
|
if (serveFirstWaypoint && plan) {
|
|
60
|
-
const re =
|
|
61
|
-
app.use(re.regexp, (
|
|
55
|
+
const re = pathToRegexp(`${route}`.replace(/\/+/g, "/"));
|
|
56
|
+
app.use(re.regexp, serveFirstWaypointMiddlewareFactory({ plan }));
|
|
62
57
|
}
|
|
63
58
|
// Capture the mount path of this CASA app, before any parameterised path
|
|
64
59
|
// segments exert influence over `req.baseUrl` in the `router` further below.
|
|
@@ -76,14 +71,14 @@ exports.default = ({ nunjucksEnv, mountUrl, plan, staticRouter, ancillaryRouter,
|
|
|
76
71
|
const sealedStaticRouter = staticRouter.seal();
|
|
77
72
|
app.use(preMiddleware);
|
|
78
73
|
app.use(sealedStaticRouter);
|
|
79
|
-
const router =
|
|
74
|
+
const router = Router({
|
|
80
75
|
// Required so that any parameters in the URL are propagated to middleware
|
|
81
76
|
mergeParams: true,
|
|
82
77
|
});
|
|
83
78
|
router.use(preMiddleware);
|
|
79
|
+
router.use(bodyParserMiddleware);
|
|
84
80
|
router.use(sessionMiddleware);
|
|
85
81
|
router.use(i18nMiddleware);
|
|
86
|
-
router.use(bodyParserMiddleware);
|
|
87
82
|
router.use(dataMiddleware);
|
|
88
83
|
router.use(ancillaryRouter.seal());
|
|
89
84
|
router.use(journeyRouter.seal());
|
|
@@ -91,4 +86,3 @@ exports.default = ({ nunjucksEnv, mountUrl, plan, staticRouter, ancillaryRouter,
|
|
|
91
86
|
app.use(route, router);
|
|
92
87
|
return app;
|
|
93
88
|
};
|
|
94
|
-
//# sourceMappingURL=mount.js.map
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Merge multiple objects into one object
|
|
3
|
+
*
|
|
4
|
+
* @memberof NunjucksFilters
|
|
5
|
+
* @param {...(object | Array)} objects Objects to merge
|
|
3
6
|
* @returns {object} Merged object
|
|
4
7
|
*/
|
|
5
|
-
export function mergeObjects(...objects: any[]): object;
|
|
8
|
+
export function mergeObjects(...objects: (object | any[])[]): object;
|
|
6
9
|
/**
|
|
7
10
|
* Determine whether a value exists in a list.
|
|
8
11
|
*
|
|
9
12
|
* @memberof NunjucksFilters
|
|
10
|
-
* @param {
|
|
13
|
+
* @param {Array} source List of items to search
|
|
11
14
|
* @param {any} search Item to search within the `source`
|
|
12
15
|
* @returns {boolean} True if the search item was found
|
|
13
16
|
*/
|
|
@@ -48,3 +51,4 @@ export function formatDateObject(date: {
|
|
|
48
51
|
* @returns {string} Formatted
|
|
49
52
|
*/
|
|
50
53
|
export function renderAsAttributes(attrsObject: object): string;
|
|
54
|
+
//# sourceMappingURL=nunjucks-filters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nunjucks-filters.d.ts","sourceRoot":"","sources":["../../src/lib/nunjucks-filters.js"],"names":[],"mappings":"AA6CA;;;;;;GAMG;AACH,yCAHc,CAAC,MAAM,QAAQ,CAAC,EAAA,GACjB,MAAM,CAYlB;AAED;;;;;;;GAOG;AACH,kDAHW,GAAG,GACD,OAAO,CAInB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,uCARG;IAAqB,EAAE,EAAf,MAAM;IACO,EAAE,EAAf,MAAM;IACO,IAAI,EAAjB,MAAM;CACd,WACA;IAAwB,MAAM;IACN,MAAM;CAC9B,GAAU,MAAM,CAoBlB;AAED;;;;;;;;;GASG;AACH,gDAHW,MAAM,GACJ,MAAM,CA0BlB"}
|
|
@@ -1,83 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
// Allows objects to be deepmerged and retain their type, without becoming [object Object]
|
|
37
|
-
// ref: https://github.com/jonschlinkert/is-plain-object/blob/master/is-plain-object.js
|
|
38
|
-
/**
|
|
39
|
-
* @param {any} o Value to test
|
|
40
|
-
* @returns {boolean} True if an object
|
|
41
|
-
*/
|
|
42
|
-
function isObject(o) {
|
|
43
|
-
return Object.prototype.toString.call(o) === "[object Object]";
|
|
44
|
-
}
|
|
1
|
+
import deepmerge from "@fastify/deepmerge";
|
|
2
|
+
import { DateTime } from "luxon";
|
|
3
|
+
import nunjucks from "nunjucks";
|
|
4
|
+
import isPlainObject from "is-plain-obj";
|
|
5
|
+
import NullObject from "./NullObject.js";
|
|
6
|
+
const merge = deepmerge({
|
|
7
|
+
all: true,
|
|
8
|
+
onlyDefinedProperties: true,
|
|
9
|
+
isMergeableObject: isMergable,
|
|
10
|
+
mergeArray(options) {
|
|
11
|
+
const deepmerge = options.deepmerge;
|
|
12
|
+
const clone = options.clone;
|
|
13
|
+
return function (target, source) {
|
|
14
|
+
let i = 0;
|
|
15
|
+
const tl = target.length;
|
|
16
|
+
const sl = source.length;
|
|
17
|
+
const il = Math.max(tl, sl);
|
|
18
|
+
const result = new Array(il);
|
|
19
|
+
/* eslint-disable security/detect-object-injection */
|
|
20
|
+
for (i = 0; i < il; ++i) {
|
|
21
|
+
const targetItem = target[i];
|
|
22
|
+
const sourceItem = source[i];
|
|
23
|
+
if (i < sl) {
|
|
24
|
+
result[i] = deepmerge(targetItem, sourceItem);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
result[i] = clone(targetItem);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/* eslint-enable security/detect-object-injection */
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
});
|
|
45
35
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
36
|
+
* Returns true if object is mergable (plain object or Array)
|
|
37
|
+
*
|
|
38
|
+
* @param {object} object Input object
|
|
39
|
+
* @returns {boolean} Is mergable
|
|
48
40
|
*/
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
if (isObject(o) === false) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
const ctor = o.constructor;
|
|
57
|
-
if (ctor === undefined) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
const prot = ctor.prototype;
|
|
61
|
-
if (isObject(prot) === false) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
return Object.hasOwn(prot, "isPrototypeOf");
|
|
41
|
+
function isMergable(object) {
|
|
42
|
+
return Array.isArray(object) || isPlainObject(object);
|
|
65
43
|
}
|
|
66
44
|
/**
|
|
67
|
-
*
|
|
45
|
+
* Merge multiple objects into one object
|
|
46
|
+
*
|
|
47
|
+
* @memberof NunjucksFilters
|
|
48
|
+
* @param {...(object | Array)} objects Objects to merge
|
|
68
49
|
* @returns {object} Merged object
|
|
69
50
|
*/
|
|
70
51
|
function mergeObjects(...objects) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
52
|
+
const merged = merge(new NullObject(), ...objects);
|
|
53
|
+
if (merged === null) {
|
|
54
|
+
for (const object of objects) {
|
|
55
|
+
if (!isMergable(object)) {
|
|
56
|
+
throw new TypeError(`Cannot convert ${typeof object} to object`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return merged;
|
|
75
61
|
}
|
|
76
62
|
/**
|
|
77
63
|
* Determine whether a value exists in a list.
|
|
78
64
|
*
|
|
79
65
|
* @memberof NunjucksFilters
|
|
80
|
-
* @param {
|
|
66
|
+
* @param {Array} source List of items to search
|
|
81
67
|
* @param {any} search Item to search within the `source`
|
|
82
68
|
* @returns {boolean} True if the search item was found
|
|
83
69
|
*/
|
|
@@ -107,7 +93,7 @@ function formatDateObject(date, config = {}) {
|
|
|
107
93
|
"yyyy" in date &&
|
|
108
94
|
"mm" in date &&
|
|
109
95
|
"dd" in date) {
|
|
110
|
-
return
|
|
96
|
+
return DateTime.fromObject({
|
|
111
97
|
year: Math.max(0, parseInt(date.yyyy, 10)),
|
|
112
98
|
month: Math.max(0, parseInt(date.mm, 10)),
|
|
113
99
|
day: Math.max(1, parseInt(date.dd, 10)),
|
|
@@ -146,6 +132,7 @@ function renderAsAttributes(attrsObject) {
|
|
|
146
132
|
attrsList.push(`${key}="${value}"`);
|
|
147
133
|
}
|
|
148
134
|
}
|
|
149
|
-
return new
|
|
135
|
+
return new nunjucks.runtime.SafeString(attrsList.join(" "));
|
|
150
136
|
}
|
|
151
|
-
|
|
137
|
+
/** @namespace NunjucksFilters */
|
|
138
|
+
export { mergeObjects, includes, formatDateObject, renderAsAttributes };
|
package/dist/lib/nunjucks.d.ts
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* Create a Nunjucks environment.
|
|
8
8
|
*
|
|
9
9
|
* @param {NunjucksOptions} options Nunjucks options
|
|
10
|
-
* @
|
|
11
|
-
*
|
|
10
|
+
* @returns {import("../casa.js").CasaNunjucksEnvironment} Nunjucks Environment
|
|
11
|
+
* instance
|
|
12
12
|
* @access private
|
|
13
13
|
*/
|
|
14
|
-
export default function nunjucksConfig({ views
|
|
14
|
+
export default function nunjucksConfig({ views }: NunjucksOptions): import("../casa.js").CasaNunjucksEnvironment;
|
|
15
15
|
export type NunjucksOptions = {
|
|
16
16
|
/**
|
|
17
17
|
* Template file directories (optional, default
|
|
@@ -19,4 +19,4 @@ export type NunjucksOptions = {
|
|
|
19
19
|
*/
|
|
20
20
|
views?: string[] | undefined;
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
//# sourceMappingURL=nunjucks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nunjucks.d.ts","sourceRoot":"","sources":["../../src/lib/nunjucks.js"],"names":[],"mappings":"AAUA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,kDALW,eAAe,GACb,OAAO,YAAY,EAAE,uBAAuB,CAgCxD"}
|
package/dist/lib/nunjucks.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = nunjucksConfig;
|
|
7
|
-
const node_fs_1 = require("node:fs");
|
|
8
|
-
const node_path_1 = require("node:path");
|
|
9
|
-
const nunjucks_1 = require("nunjucks");
|
|
10
|
-
const dirname_cjs_1 = __importDefault(require("./dirname.cjs"));
|
|
11
|
-
const CasaTemplateLoader_js_1 = __importDefault(require("./CasaTemplateLoader.js"));
|
|
12
|
-
const nunjucks_filters_js_1 = require("./nunjucks-filters.js");
|
|
1
|
+
import { Environment } from "nunjucks";
|
|
2
|
+
import packageInfo from "../../package.json" with { type: "json" };
|
|
3
|
+
import CasaTemplateLoader from "./CasaTemplateLoader.js";
|
|
4
|
+
import { mergeObjects, includes, renderAsAttributes, formatDateObject, } from "./nunjucks-filters.js";
|
|
13
5
|
/**
|
|
14
6
|
* @typedef {object} NunjucksOptions
|
|
15
7
|
* @property {string[]} [views=[]] Template file directories (optional, default
|
|
@@ -19,19 +11,19 @@ const nunjucks_filters_js_1 = require("./nunjucks-filters.js");
|
|
|
19
11
|
* Create a Nunjucks environment.
|
|
20
12
|
*
|
|
21
13
|
* @param {NunjucksOptions} options Nunjucks options
|
|
22
|
-
* @
|
|
23
|
-
*
|
|
14
|
+
* @returns {import("../casa.js").CasaNunjucksEnvironment} Nunjucks Environment
|
|
15
|
+
* instance
|
|
24
16
|
* @access private
|
|
25
17
|
*/
|
|
26
|
-
function nunjucksConfig({ views = []
|
|
18
|
+
export default function nunjucksConfig({ views = [] }) {
|
|
27
19
|
// Prepare a single Nunjucks environment for all responses to use. Note that
|
|
28
20
|
// we cannot prepare response-specific global functions/filters if we use a
|
|
29
21
|
// single environment, but the performance gains of doing so are significant.
|
|
30
|
-
const loader = new
|
|
22
|
+
const loader = new CasaTemplateLoader(views, {
|
|
31
23
|
watch: false,
|
|
32
24
|
noCache: false,
|
|
33
25
|
});
|
|
34
|
-
const env = new
|
|
26
|
+
const env = new Environment(loader, {
|
|
35
27
|
autoescape: true,
|
|
36
28
|
throwOnUndefined: false,
|
|
37
29
|
trimBlocks: false,
|
|
@@ -41,14 +33,10 @@ function nunjucksConfig({ views = [], govukRebrand }) {
|
|
|
41
33
|
env.modifyBlock = loader.modifyBlock.bind(loader);
|
|
42
34
|
// Globals
|
|
43
35
|
// These can't be modified once set. But they can be overridden by res.locals.
|
|
44
|
-
env.addGlobal("casaVersion",
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
env.addGlobal("
|
|
48
|
-
env.addGlobal("
|
|
49
|
-
env.addGlobal("includes", nunjucks_filters_js_1.includes);
|
|
50
|
-
env.addGlobal("formatDateObject", nunjucks_filters_js_1.formatDateObject);
|
|
51
|
-
env.addGlobal("renderAsAttributes", nunjucks_filters_js_1.renderAsAttributes);
|
|
36
|
+
env.addGlobal("casaVersion", packageInfo.version);
|
|
37
|
+
env.addGlobal("mergeObjects", mergeObjects);
|
|
38
|
+
env.addGlobal("includes", includes);
|
|
39
|
+
env.addGlobal("formatDateObject", formatDateObject);
|
|
40
|
+
env.addGlobal("renderAsAttributes", renderAsAttributes);
|
|
52
41
|
return env;
|
|
53
42
|
}
|
|
54
|
-
//# sourceMappingURL=nunjucks.js.map
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -25,10 +25,11 @@ export function isStringable(value: any): boolean;
|
|
|
25
25
|
* @param {string} hookName Hook name (including scope prefix)
|
|
26
26
|
* @param {string} path URL path to match (relative to mountUrl)
|
|
27
27
|
* @param {Hook[]} hooks Hooks to be applied at the page level
|
|
28
|
-
* @returns {
|
|
28
|
+
* @returns {import("express").RequestHandler[]} An array of middleware that
|
|
29
|
+
* should be applied
|
|
29
30
|
* @access private
|
|
30
31
|
*/
|
|
31
|
-
export function resolveMiddlewareHooks(hookName: string, path: string, hooks?: Hook[]):
|
|
32
|
+
export function resolveMiddlewareHooks(hookName: string, path: string, hooks?: Hook[]): import("express").RequestHandler[];
|
|
32
33
|
/**
|
|
33
34
|
* Coerce an input to a string.
|
|
34
35
|
*
|
|
@@ -114,3 +115,4 @@ export function validateView(view: string): void;
|
|
|
114
115
|
*/
|
|
115
116
|
export function validateWaypoint(waypoint: string): void;
|
|
116
117
|
export type Hook = import("../casa").GlobalHook | import("../casa").PageHook;
|
|
118
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AACH,6BAJW,GAAG,GACD,OAAO,CAiBnB;AAED;;;;;;GAMG;AACH,oCAJW,GAAG,GACD,OAAO,CAKnB;AAED;;;;;;;;;;GAUG;AACH,iDAPW,MAAM,QACN,MAAM,UACN,IAAI,EAAE,GACJ,OAAO,SAAS,EAAE,cAAc,EAAE,CAa9C;AAED;;;;;;;GAOG;AACH,sCALW,GAAG,YACH,MAAM,mBACJ,MAAM,CAUlB;AAED;;;;;GAKG;AACH,4CAHW,GAAG,GACD,MAAM,GAAG,SAAS,CAI9B;AAED;;;;;;;;GAQG;AACH,uCANW,MAAM,WACN,MAAM,GACJ,MAAM,CAqClB;AAID;;;;;;;GAOG;AACH,8BALW,MAAM,GACJ,MAAM,CAalB;AAED;;;;;;;;GAQG;AACH,2CANW,MAAM,GACJ,IAAI,CAmBhB;AAED;;;;;;;GAOG;AACH,uCALW,MAAM,GACJ,IAAI,CAQhB;AAED;;;;;;;;GAQG;AACH,sCANW,MAAM,GACJ,MAAM,CAqBlB;AAED;;;;;;;;GAQG;AACH,mCANW,MAAM,GACJ,IAAI,CAmBhB;AAED;;;;;;;;GAQG;AACH,2CANW,MAAM,GACJ,IAAI,CAmBhB;mBA1QY,OAAO,SAAS,EAAE,UAAU,GAAG,OAAO,SAAS,EAAE,QAAQ"}
|
package/dist/lib/utils.js
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @typedef {import("../casa").GlobalHook | import("../casa").PageHook} Hook
|
|
4
3
|
* @access private
|
|
5
4
|
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.isEmpty = isEmpty;
|
|
8
|
-
exports.isStringable = isStringable;
|
|
9
|
-
exports.resolveMiddlewareHooks = resolveMiddlewareHooks;
|
|
10
|
-
exports.stringifyInput = stringifyInput;
|
|
11
|
-
exports.coerceInputToInteger = coerceInputToInteger;
|
|
12
|
-
exports.stripWhitespace = stripWhitespace;
|
|
13
|
-
exports.notProto = notProto;
|
|
14
|
-
exports.validateHookName = validateHookName;
|
|
15
|
-
exports.validateHookPath = validateHookPath;
|
|
16
|
-
exports.validateUrlPath = validateUrlPath;
|
|
17
|
-
exports.validateView = validateView;
|
|
18
|
-
exports.validateWaypoint = validateWaypoint;
|
|
19
5
|
/**
|
|
20
6
|
* Determine if value is empty. Recurse over objects.
|
|
21
7
|
*
|
|
@@ -23,7 +9,7 @@ exports.validateWaypoint = validateWaypoint;
|
|
|
23
9
|
* @returns {boolean} True if the object is empty
|
|
24
10
|
* @access private
|
|
25
11
|
*/
|
|
26
|
-
function isEmpty(val) {
|
|
12
|
+
export function isEmpty(val) {
|
|
27
13
|
if (val === null ||
|
|
28
14
|
typeof val === "undefined" ||
|
|
29
15
|
(typeof val === "string" && val === "")) {
|
|
@@ -43,7 +29,7 @@ function isEmpty(val) {
|
|
|
43
29
|
* @returns {boolean} Whether the value is stringable or not
|
|
44
30
|
* @access private
|
|
45
31
|
*/
|
|
46
|
-
function isStringable(value) {
|
|
32
|
+
export function isStringable(value) {
|
|
47
33
|
return typeof value === "string" || typeof value === "number";
|
|
48
34
|
}
|
|
49
35
|
/**
|
|
@@ -53,10 +39,11 @@ function isStringable(value) {
|
|
|
53
39
|
* @param {string} hookName Hook name (including scope prefix)
|
|
54
40
|
* @param {string} path URL path to match (relative to mountUrl)
|
|
55
41
|
* @param {Hook[]} hooks Hooks to be applied at the page level
|
|
56
|
-
* @returns {
|
|
42
|
+
* @returns {import("express").RequestHandler[]} An array of middleware that
|
|
43
|
+
* should be applied
|
|
57
44
|
* @access private
|
|
58
45
|
*/
|
|
59
|
-
function resolveMiddlewareHooks(hookName, path, hooks = []) {
|
|
46
|
+
export function resolveMiddlewareHooks(hookName, path, hooks = []) {
|
|
60
47
|
const pathMatch = (h) => h.path === undefined ||
|
|
61
48
|
(h.path instanceof RegExp && h.path.test(path)) ||
|
|
62
49
|
h.path === path;
|
|
@@ -73,7 +60,7 @@ function resolveMiddlewareHooks(hookName, path, hooks = []) {
|
|
|
73
60
|
* @returns {string} The stringified input
|
|
74
61
|
* @access private
|
|
75
62
|
*/
|
|
76
|
-
function stringifyInput(input, fallback) {
|
|
63
|
+
export function stringifyInput(input, fallback) {
|
|
77
64
|
// Not using param defaults here as the fallback may be explicitly "undefined"
|
|
78
65
|
const fb = arguments.length === 2 && (isStringable(fallback) || fallback === undefined)
|
|
79
66
|
? fallback
|
|
@@ -86,7 +73,7 @@ function stringifyInput(input, fallback) {
|
|
|
86
73
|
* @param {any} input Input to be coerced.
|
|
87
74
|
* @returns {number | undefined} The number as an integer or `undefined`.
|
|
88
75
|
*/
|
|
89
|
-
function coerceInputToInteger(input) {
|
|
76
|
+
export function coerceInputToInteger(input) {
|
|
90
77
|
return Number.isNaN(Number(input)) ? undefined : Math.floor(Number(input));
|
|
91
78
|
}
|
|
92
79
|
/**
|
|
@@ -98,7 +85,7 @@ function coerceInputToInteger(input) {
|
|
|
98
85
|
* @throws {TypeError}
|
|
99
86
|
* @access private
|
|
100
87
|
*/
|
|
101
|
-
function stripWhitespace(value, options) {
|
|
88
|
+
export function stripWhitespace(value, options) {
|
|
102
89
|
const opts = {
|
|
103
90
|
leading: "",
|
|
104
91
|
trailing: "",
|
|
@@ -135,7 +122,7 @@ function stripWhitespace(value, options) {
|
|
|
135
122
|
* @throws {Error} If proposed key is an invalid keyword
|
|
136
123
|
* @access private
|
|
137
124
|
*/
|
|
138
|
-
function notProto(key) {
|
|
125
|
+
export function notProto(key) {
|
|
139
126
|
if (["__proto__", "constructor", "prototype"].includes(String(key).toLowerCase())) {
|
|
140
127
|
throw new Error("Attempt to use prototype key disallowed");
|
|
141
128
|
}
|
|
@@ -150,7 +137,7 @@ function notProto(key) {
|
|
|
150
137
|
* @throws {SyntaxError}
|
|
151
138
|
* @access private
|
|
152
139
|
*/
|
|
153
|
-
function validateHookName(hookName) {
|
|
140
|
+
export function validateHookName(hookName) {
|
|
154
141
|
if (typeof hookName !== "string") {
|
|
155
142
|
throw new TypeError("Hook name must be a string");
|
|
156
143
|
}
|
|
@@ -169,7 +156,7 @@ function validateHookName(hookName) {
|
|
|
169
156
|
* @throws {TypeError}
|
|
170
157
|
* @access private
|
|
171
158
|
*/
|
|
172
|
-
function validateHookPath(path) {
|
|
159
|
+
export function validateHookPath(path) {
|
|
173
160
|
if (typeof path !== "string" && !(path instanceof RegExp)) {
|
|
174
161
|
throw new TypeError("Hook path must be a string or RegExp");
|
|
175
162
|
}
|
|
@@ -183,7 +170,7 @@ function validateHookPath(path) {
|
|
|
183
170
|
* @throws {SyntaxError}
|
|
184
171
|
* @access private
|
|
185
172
|
*/
|
|
186
|
-
function validateUrlPath(path) {
|
|
173
|
+
export function validateUrlPath(path) {
|
|
187
174
|
if (typeof path !== "string") {
|
|
188
175
|
throw new TypeError("URL path must be a string");
|
|
189
176
|
}
|
|
@@ -204,7 +191,7 @@ function validateUrlPath(path) {
|
|
|
204
191
|
* @throws {SyntaxError}
|
|
205
192
|
* @access private
|
|
206
193
|
*/
|
|
207
|
-
function validateView(view) {
|
|
194
|
+
export function validateView(view) {
|
|
208
195
|
if (typeof view !== "string") {
|
|
209
196
|
throw new TypeError("View must be a string");
|
|
210
197
|
}
|
|
@@ -224,7 +211,7 @@ function validateView(view) {
|
|
|
224
211
|
* @throws {SyntaxError}
|
|
225
212
|
* @access private
|
|
226
213
|
*/
|
|
227
|
-
function validateWaypoint(waypoint) {
|
|
214
|
+
export function validateWaypoint(waypoint) {
|
|
228
215
|
if (typeof waypoint !== "string") {
|
|
229
216
|
throw new TypeError("Waypoint must be a string");
|
|
230
217
|
}
|
|
@@ -235,4 +222,3 @@ function validateWaypoint(waypoint) {
|
|
|
235
222
|
throw new SyntaxError("Waypoint must contain only a-z, 0-9, -, _ and / characters");
|
|
236
223
|
}
|
|
237
224
|
}
|
|
238
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateObject.d.ts","sourceRoot":"","sources":["../../../src/lib/validators/dateObject.js"],"names":[],"mappings":"AAOA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;;;;GAUG;AACH;IACE,4DAA4D;IAC5D,aAAoB;IAEpB,0DAqHC;IAED,0BAWC;CACF;iCAzKY,OAAO,YAAY,EAAE,kBAAkB;;;;;cAMtC,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAVH,wBAAwB;4BADzB,uBAAuB;yBAF1B,OAAO"}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
9
|
-
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
10
|
-
const utils_js_1 = require("../utils.js");
|
|
11
|
-
const { isPlainObject } = lodash_1.default;
|
|
1
|
+
import isPlainObject from "is-plain-obj";
|
|
2
|
+
import { DateTime } from "luxon";
|
|
3
|
+
import NullObject from "../NullObject.js";
|
|
4
|
+
import ValidationError from "../ValidationError.js";
|
|
5
|
+
import ValidatorFactory from "../ValidatorFactory.js";
|
|
6
|
+
import { stringifyInput, stripWhitespace } from "../utils.js";
|
|
12
7
|
/**
|
|
13
8
|
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
14
9
|
* @access private
|
|
@@ -42,7 +37,7 @@ const { isPlainObject } = lodash_1.default;
|
|
|
42
37
|
* @memberof Validators
|
|
43
38
|
* @augments ValidatorFactory
|
|
44
39
|
*/
|
|
45
|
-
class DateObject extends
|
|
40
|
+
export default class DateObject extends ValidatorFactory {
|
|
46
41
|
/** @property {string} name Validator name ("dateObject") */
|
|
47
42
|
name = "dateObject";
|
|
48
43
|
validate(value, dataContext = {}) {
|
|
@@ -59,7 +54,7 @@ class DateObject extends ValidatorFactory_js_1.default {
|
|
|
59
54
|
inline: "validation:rule.dateObject.beforeOffset.inline",
|
|
60
55
|
summary: "validation:rule.dateObject.beforeOffset.summary",
|
|
61
56
|
},
|
|
62
|
-
now:
|
|
57
|
+
now: DateTime.local(),
|
|
63
58
|
allowSingleDigitDay: false,
|
|
64
59
|
allowSingleDigitMonth: false,
|
|
65
60
|
allowMonthNames: false,
|
|
@@ -102,7 +97,7 @@ class DateObject extends ValidatorFactory_js_1.default {
|
|
|
102
97
|
}
|
|
103
98
|
if (typeof value === "object") {
|
|
104
99
|
formats.find((format) => {
|
|
105
|
-
luxonDate =
|
|
100
|
+
luxonDate = DateTime.fromFormat([value.dd, value.mm, value.yyyy].join("-"), format).startOf("day");
|
|
106
101
|
valid = luxonDate.isValid;
|
|
107
102
|
return valid;
|
|
108
103
|
});
|
|
@@ -144,20 +139,18 @@ class DateObject extends ValidatorFactory_js_1.default {
|
|
|
144
139
|
errorMsg.focusSuffix = ["[dd]", "[mm]", "[yyyy]"];
|
|
145
140
|
}
|
|
146
141
|
}
|
|
147
|
-
return valid ? [] : [
|
|
142
|
+
return valid ? [] : [ValidationError.make({ errorMsg, dataContext })];
|
|
148
143
|
}
|
|
149
144
|
sanitise(value) {
|
|
150
145
|
if (value !== undefined) {
|
|
151
146
|
return isPlainObject(value)
|
|
152
147
|
? {
|
|
153
|
-
dd:
|
|
154
|
-
mm:
|
|
155
|
-
yyyy:
|
|
148
|
+
dd: stripWhitespace(stringifyInput(value.dd)),
|
|
149
|
+
mm: stripWhitespace(stringifyInput(value.mm)),
|
|
150
|
+
yyyy: stripWhitespace(stringifyInput(value.yyyy)),
|
|
156
151
|
}
|
|
157
|
-
:
|
|
152
|
+
: new NullObject();
|
|
158
153
|
}
|
|
159
154
|
return undefined;
|
|
160
155
|
}
|
|
161
156
|
}
|
|
162
|
-
exports.default = DateObject;
|
|
163
|
-
//# sourceMappingURL=dateObject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../../src/lib/validators/email.js"],"names":[],"mappings":"AAOA;;;GAGG;AAEH;;;GAGG;AAEH;;;;;;;;;GASG;AACH;IACE,uDAAuD;IACvD,aAAe;IAEf,0DAcC;IAED,yCAKC;CACF;iCA7CY,OAAO,YAAY,EAAE,kBAAkB;;;;;cAMtC,kBAAkB;;6BAZH,wBAAwB;4BADzB,uBAAuB"}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
const validator_1 = __importDefault(require("validator"));
|
|
7
|
-
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
8
|
-
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
9
|
-
const utils_js_1 = require("../utils.js");
|
|
10
|
-
const { isEmail } = validator_1.default; // CommonJS
|
|
1
|
+
import validatorPkg from "validator";
|
|
2
|
+
import ValidationError from "../ValidationError.js";
|
|
3
|
+
import ValidatorFactory from "../ValidatorFactory.js";
|
|
4
|
+
import { stringifyInput } from "../utils.js";
|
|
5
|
+
const { isEmail } = validatorPkg; // CommonJS
|
|
11
6
|
/**
|
|
12
7
|
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
13
8
|
* @access private
|
|
@@ -26,7 +21,7 @@ const { isEmail } = validator_1.default; // CommonJS
|
|
|
26
21
|
* @memberof Validators
|
|
27
22
|
* @augments ValidatorFactory
|
|
28
23
|
*/
|
|
29
|
-
class Email extends
|
|
24
|
+
export default class Email extends ValidatorFactory {
|
|
30
25
|
/** @property {string} name Validator name ("email") */
|
|
31
26
|
name = "email";
|
|
32
27
|
validate(value, dataContext = {}) {
|
|
@@ -41,14 +36,12 @@ class Email extends ValidatorFactory_js_1.default {
|
|
|
41
36
|
summary: "validation:rule.email.summary",
|
|
42
37
|
inline: "validation:rule.email.inline",
|
|
43
38
|
};
|
|
44
|
-
return isValid ? [] : [
|
|
39
|
+
return isValid ? [] : [ValidationError.make({ errorMsg, dataContext })];
|
|
45
40
|
}
|
|
46
41
|
sanitise(value) {
|
|
47
42
|
if (value !== undefined) {
|
|
48
|
-
return
|
|
43
|
+
return stringifyInput(value);
|
|
49
44
|
}
|
|
50
45
|
return undefined;
|
|
51
46
|
}
|
|
52
47
|
}
|
|
53
|
-
exports.default = Email;
|
|
54
|
-
//# sourceMappingURL=email.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inArray.d.ts","sourceRoot":"","sources":["../../../src/lib/validators/inArray.js"],"names":[],"mappings":"AAYA;;;GAGG;AAEH;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH;IACE,yDAAyD;IACzD,aAAiB;IAEjB,0DAqBC;IAED,oDAgBC;CACF;iCAjEY,OAAO,YAAY,EAAE,kBAAkB;;;;;cAMtC,kBAAkB;;;;YAClB,MAAM,EAAE;;6BAXO,wBAAwB;4BADzB,uBAAuB"}
|