@dwp/govuk-casa 8.15.0 → 9.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/README.md +9 -9
- package/dist/assets/css/casa.css +2 -1
- package/dist/assets/css/casa.css.map +1 -0
- package/dist/casa.d.ts +122 -99
- package/dist/casa.js +120 -88
- package/dist/casa.js.map +1 -1
- package/dist/lib/CasaTemplateLoader.d.ts +4 -4
- package/dist/lib/CasaTemplateLoader.js +16 -16
- package/dist/lib/CasaTemplateLoader.js.map +1 -1
- package/dist/lib/JourneyContext.d.ts +38 -40
- package/dist/lib/JourneyContext.js +89 -75
- package/dist/lib/JourneyContext.js.map +1 -1
- package/dist/lib/MutableRouter.d.ts +40 -41
- package/dist/lib/MutableRouter.js +64 -71
- package/dist/lib/MutableRouter.js.map +1 -1
- package/dist/lib/Plan.d.ts +29 -26
- package/dist/lib/Plan.js +85 -71
- package/dist/lib/Plan.js.map +1 -1
- package/dist/lib/ValidationError.d.ts +16 -15
- package/dist/lib/ValidationError.js +21 -20
- package/dist/lib/ValidationError.js.map +1 -1
- package/dist/lib/ValidatorFactory.d.ts +15 -13
- package/dist/lib/ValidatorFactory.js +14 -12
- package/dist/lib/ValidatorFactory.js.map +1 -1
- package/dist/lib/configuration-ingestor.d.ts +37 -40
- package/dist/lib/configuration-ingestor.js +93 -93
- package/dist/lib/configuration-ingestor.js.map +1 -1
- package/dist/lib/configure.d.ts +6 -6
- package/dist/lib/configure.js +14 -12
- package/dist/lib/configure.js.map +1 -1
- package/dist/lib/constants.d.ts +1 -3
- package/dist/lib/constants.js +9 -11
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/context-id-generators.d.ts +3 -5
- package/dist/lib/context-id-generators.js +7 -6
- package/dist/lib/context-id-generators.js.map +1 -1
- package/dist/lib/end-session.d.ts +4 -4
- package/dist/lib/end-session.js +5 -5
- package/dist/lib/field.d.ts +24 -29
- package/dist/lib/field.js +41 -70
- package/dist/lib/field.js.map +1 -1
- package/dist/lib/index.d.ts +13 -13
- package/dist/lib/logger.d.ts +7 -6
- package/dist/lib/logger.js +7 -7
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/mount.d.ts +5 -5
- package/dist/lib/mount.js +12 -17
- package/dist/lib/mount.js.map +1 -1
- package/dist/lib/nunjucks-filters.d.ts +10 -12
- package/dist/lib/nunjucks-filters.js +35 -35
- package/dist/lib/nunjucks-filters.js.map +1 -1
- package/dist/lib/nunjucks.d.ts +7 -5
- package/dist/lib/nunjucks.js +10 -8
- package/dist/lib/nunjucks.js.map +1 -1
- package/dist/lib/utils.d.ts +19 -19
- package/dist/lib/utils.js +62 -55
- package/dist/lib/utils.js.map +1 -1
- package/dist/lib/validators/dateObject.d.ts +29 -22
- package/dist/lib/validators/dateObject.js +58 -49
- package/dist/lib/validators/dateObject.js.map +1 -1
- package/dist/lib/validators/email.d.ts +4 -4
- package/dist/lib/validators/email.js +4 -4
- package/dist/lib/validators/inArray.d.ts +4 -4
- package/dist/lib/validators/inArray.js +7 -8
- package/dist/lib/validators/inArray.js.map +1 -1
- package/dist/lib/validators/index.d.ts +10 -10
- package/dist/lib/validators/index.js +1 -3
- package/dist/lib/validators/index.js.map +1 -1
- package/dist/lib/validators/nino.d.ts +9 -8
- package/dist/lib/validators/nino.js +14 -10
- package/dist/lib/validators/nino.js.map +1 -1
- package/dist/lib/validators/postalAddressObject.d.ts +37 -24
- package/dist/lib/validators/postalAddressObject.js +65 -46
- package/dist/lib/validators/postalAddressObject.js.map +1 -1
- package/dist/lib/validators/range.d.ts +12 -8
- package/dist/lib/validators/range.js +11 -9
- package/dist/lib/validators/range.js.map +1 -1
- package/dist/lib/validators/regex.d.ts +4 -4
- package/dist/lib/validators/regex.js +5 -5
- package/dist/lib/validators/required.d.ts +6 -6
- package/dist/lib/validators/required.js +9 -11
- package/dist/lib/validators/required.js.map +1 -1
- package/dist/lib/validators/strlen.d.ts +12 -8
- package/dist/lib/validators/strlen.js +13 -11
- package/dist/lib/validators/strlen.js.map +1 -1
- package/dist/lib/validators/wordCount.d.ts +12 -8
- package/dist/lib/validators/wordCount.js +15 -11
- package/dist/lib/validators/wordCount.js.map +1 -1
- package/dist/lib/waypoint-url.d.ts +16 -13
- package/dist/lib/waypoint-url.js +39 -36
- package/dist/lib/waypoint-url.js.map +1 -1
- package/dist/middleware/body-parser.d.ts +1 -1
- package/dist/middleware/body-parser.js +6 -6
- package/dist/middleware/body-parser.js.map +1 -1
- package/dist/middleware/data.d.ts +1 -1
- package/dist/middleware/data.js +8 -7
- package/dist/middleware/data.js.map +1 -1
- package/dist/middleware/gather-fields.d.ts +2 -2
- package/dist/middleware/gather-fields.js +6 -4
- package/dist/middleware/gather-fields.js.map +1 -1
- package/dist/middleware/i18n.js +13 -15
- package/dist/middleware/i18n.js.map +1 -1
- package/dist/middleware/post.js +30 -18
- package/dist/middleware/post.js.map +1 -1
- package/dist/middleware/pre.d.ts +2 -2
- package/dist/middleware/pre.js +46 -26
- package/dist/middleware/pre.js.map +1 -1
- package/dist/middleware/progress-journey.d.ts +1 -1
- package/dist/middleware/progress-journey.js +5 -5
- package/dist/middleware/progress-journey.js.map +1 -1
- package/dist/middleware/sanitise-fields.d.ts +1 -1
- package/dist/middleware/sanitise-fields.js +13 -11
- package/dist/middleware/sanitise-fields.js.map +1 -1
- package/dist/middleware/serve-first-waypoint.d.ts +3 -3
- package/dist/middleware/serve-first-waypoint.js +8 -6
- package/dist/middleware/serve-first-waypoint.js.map +1 -1
- package/dist/middleware/session.js +14 -11
- package/dist/middleware/session.js.map +1 -1
- package/dist/middleware/skip-waypoint.d.ts +1 -1
- package/dist/middleware/skip-waypoint.js +3 -3
- package/dist/middleware/skip-waypoint.js.map +1 -1
- package/dist/middleware/steer-journey.d.ts +1 -1
- package/dist/middleware/steer-journey.js +16 -14
- package/dist/middleware/steer-journey.js.map +1 -1
- package/dist/middleware/strip-proxy-path.d.ts +1 -1
- package/dist/middleware/strip-proxy-path.js +3 -3
- package/dist/middleware/strip-proxy-path.js.map +1 -1
- package/dist/middleware/validate-fields.d.ts +1 -1
- package/dist/middleware/validate-fields.js +2 -5
- package/dist/middleware/validate-fields.js.map +1 -1
- package/dist/routes/ancillary.d.ts +3 -3
- package/dist/routes/ancillary.js +4 -4
- package/dist/routes/ancillary.js.map +1 -1
- package/dist/routes/journey.d.ts +2 -2
- package/dist/routes/journey.js +91 -39
- package/dist/routes/journey.js.map +1 -1
- package/dist/routes/static.d.ts +7 -5
- package/dist/routes/static.js +20 -20
- package/dist/routes/static.js.map +1 -1
- package/package.json +17 -16
- package/src/casa.js +134 -102
- package/src/lib/CasaTemplateLoader.js +24 -19
- package/src/lib/JourneyContext.js +147 -107
- package/src/lib/MutableRouter.js +72 -74
- package/src/lib/Plan.js +145 -97
- package/src/lib/ValidationError.js +25 -21
- package/src/lib/ValidatorFactory.js +17 -13
- package/src/lib/configuration-ingestor.js +147 -110
- package/src/lib/configure.js +34 -32
- package/src/lib/constants.js +9 -11
- package/src/lib/context-id-generators.js +40 -43
- package/src/lib/end-session.js +6 -6
- package/src/lib/field.js +74 -78
- package/src/lib/index.js +12 -12
- package/src/lib/logger.js +9 -9
- package/src/lib/mount.js +70 -80
- package/src/lib/nunjucks-filters.js +56 -59
- package/src/lib/nunjucks.js +23 -18
- package/src/lib/utils.js +78 -57
- package/src/lib/validators/dateObject.js +71 -60
- package/src/lib/validators/email.js +8 -8
- package/src/lib/validators/inArray.js +10 -11
- package/src/lib/validators/index.js +12 -14
- package/src/lib/validators/nino.js +29 -15
- package/src/lib/validators/postalAddressObject.js +87 -63
- package/src/lib/validators/range.js +14 -12
- package/src/lib/validators/regex.js +8 -8
- package/src/lib/validators/required.js +16 -16
- package/src/lib/validators/strlen.js +16 -14
- package/src/lib/validators/wordCount.js +22 -14
- package/src/lib/waypoint-url.js +64 -46
- package/src/middleware/body-parser.js +10 -10
- package/src/middleware/csrf.js +1 -1
- package/src/middleware/data.js +28 -24
- package/src/middleware/gather-fields.js +10 -9
- package/src/middleware/i18n.js +35 -37
- package/src/middleware/post.js +41 -21
- package/src/middleware/pre.js +62 -40
- package/src/middleware/progress-journey.js +32 -18
- package/src/middleware/sanitise-fields.js +43 -20
- package/src/middleware/serve-first-waypoint.js +14 -12
- package/src/middleware/session.js +74 -61
- package/src/middleware/skip-waypoint.js +7 -9
- package/src/middleware/steer-journey.js +40 -28
- package/src/middleware/strip-proxy-path.js +8 -7
- package/src/middleware/validate-fields.js +5 -12
- package/src/routes/ancillary.js +5 -7
- package/src/routes/journey.js +159 -85
- package/src/routes/static.js +62 -30
- package/views/casa/components/character-count/README.md +2 -2
- package/views/casa/components/checkboxes/README.md +6 -6
- package/views/casa/components/date-input/README.md +7 -7
- package/views/casa/components/input/README.md +2 -2
- package/views/casa/components/journey-form/README.md +33 -14
- package/views/casa/components/postal-address-object/README.md +4 -4
- package/views/casa/components/radios/README.md +6 -6
- package/views/casa/components/select/README.md +6 -6
- package/views/casa/components/textarea/README.md +2 -2
- package/views/casa/partials/scripts.njk +5 -3
- package/views/casa/partials/styles.njk +1 -4
- package/dist/assets/css/casa-ie8.css +0 -1
package/dist/lib/utils.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
+
* @typedef {import("../casa").GlobalHook | import("../casa").PageHook} Hook
|
|
3
4
|
* @access private
|
|
4
|
-
* @typedef {import('../casa').GlobalHook | import('../casa').PageHook} Hook
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.validateWaypoint = exports.validateView = exports.validateUrlPath = exports.validateHookPath = exports.validateHookName = exports.notProto = exports.stripWhitespace = exports.coerceInputToInteger = exports.stringifyInput = exports.resolveMiddlewareHooks = exports.isStringable = exports.isEmpty = void 0;
|
|
8
8
|
/**
|
|
9
9
|
* Determine if value is empty. Recurse over objects.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
12
|
-
* @param {any} val Value to check
|
|
11
|
+
* @param {any} val Value to check
|
|
13
12
|
* @returns {boolean} True if the object is empty
|
|
13
|
+
* @access private
|
|
14
14
|
*/
|
|
15
15
|
function isEmpty(val) {
|
|
16
|
-
if (val === null
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if (val === null ||
|
|
17
|
+
typeof val === "undefined" ||
|
|
18
|
+
(typeof val === "string" && val === "")) {
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
|
-
if (Array.isArray(val) || typeof val ===
|
|
21
|
+
if (Array.isArray(val) || typeof val === "object") {
|
|
22
22
|
// ESLint disabled as `k` is an "own property" (thanks to `Object.keys()`)
|
|
23
23
|
/* eslint-disable-next-line security/detect-object-injection */
|
|
24
24
|
return Object.keys(val).filter((k) => !isEmpty(val[k])).length === 0;
|
|
@@ -29,41 +29,48 @@ exports.isEmpty = isEmpty;
|
|
|
29
29
|
/**
|
|
30
30
|
* Test is a value can be stringified (numbers or strings)
|
|
31
31
|
*
|
|
32
|
-
* @access private
|
|
33
32
|
* @param {any} value Item to test
|
|
34
33
|
* @returns {boolean} Whether the value is stringable or not
|
|
34
|
+
* @access private
|
|
35
35
|
*/
|
|
36
36
|
function isStringable(value) {
|
|
37
|
-
return typeof value ===
|
|
37
|
+
return typeof value === "string" || typeof value === "number";
|
|
38
38
|
}
|
|
39
39
|
exports.isStringable = isStringable;
|
|
40
40
|
/**
|
|
41
41
|
* Extract the middleware functions that are relevant for the given hook and
|
|
42
42
|
* path.
|
|
43
43
|
*
|
|
44
|
-
* @access private
|
|
45
44
|
* @param {string} hookName Hook name (including scope prefix)
|
|
46
45
|
* @param {string} path URL path to match (relative to mountUrl)
|
|
47
46
|
* @param {Hook[]} hooks Hooks to be applied at the page level
|
|
48
47
|
* @returns {Function[]} An array of middleware that should be applied
|
|
48
|
+
* @access private
|
|
49
49
|
*/
|
|
50
50
|
function resolveMiddlewareHooks(hookName, path, hooks = []) {
|
|
51
51
|
/* eslint-disable-next-line max-len */
|
|
52
|
-
const pathMatch = (h) => h.path === undefined ||
|
|
53
|
-
|
|
52
|
+
const pathMatch = (h) => h.path === undefined ||
|
|
53
|
+
(h.path instanceof RegExp && h.path.test(path)) ||
|
|
54
|
+
h.path === path;
|
|
55
|
+
return hooks
|
|
56
|
+
.filter((h) => h.hook === hookName)
|
|
57
|
+
.filter(pathMatch)
|
|
58
|
+
.map((h) => h.middleware);
|
|
54
59
|
}
|
|
55
60
|
exports.resolveMiddlewareHooks = resolveMiddlewareHooks;
|
|
56
61
|
/**
|
|
57
62
|
* Coerce an input to a string.
|
|
58
63
|
*
|
|
59
|
-
* @access private
|
|
60
64
|
* @param {any} input Input to be stringified
|
|
61
65
|
* @param {string} fallback Fallback to use if input can't be stringified
|
|
62
66
|
* @returns {string} The stringified input
|
|
67
|
+
* @access private
|
|
63
68
|
*/
|
|
64
69
|
function stringifyInput(input, fallback) {
|
|
65
70
|
// Not using param defaults here as the fallback may be explicitly "undefined"
|
|
66
|
-
const fb = arguments.length === 2 && (isStringable(fallback) || fallback === undefined)
|
|
71
|
+
const fb = arguments.length === 2 && (isStringable(fallback) || fallback === undefined)
|
|
72
|
+
? fallback
|
|
73
|
+
: "";
|
|
67
74
|
return isStringable(input) ? String(input) : fb;
|
|
68
75
|
}
|
|
69
76
|
exports.stringifyInput = stringifyInput;
|
|
@@ -71,7 +78,7 @@ exports.stringifyInput = stringifyInput;
|
|
|
71
78
|
* Coerce an input to an integer.
|
|
72
79
|
*
|
|
73
80
|
* @param {any} input Input to be coerced.
|
|
74
|
-
* @returns {number|undefined} The number as an integer or `undefined`.
|
|
81
|
+
* @returns {number | undefined} The number as an integer or `undefined`.
|
|
75
82
|
*/
|
|
76
83
|
function coerceInputToInteger(input) {
|
|
77
84
|
return Number.isNaN(Number(input)) ? undefined : Math.floor(Number(input));
|
|
@@ -80,25 +87,25 @@ exports.coerceInputToInteger = coerceInputToInteger;
|
|
|
80
87
|
/**
|
|
81
88
|
* Strip whitespace from a string.
|
|
82
89
|
*
|
|
83
|
-
* @
|
|
84
|
-
* @param {
|
|
85
|
-
* @
|
|
86
|
-
* @returns {string} value stripped of white space
|
|
90
|
+
* @param {string} value Value to be stripped of whitespace
|
|
91
|
+
* @param {object} options Overrides for the default whitespace replacements
|
|
92
|
+
* @returns {string} Value stripped of white space
|
|
87
93
|
* @throws {TypeError}
|
|
94
|
+
* @access private
|
|
88
95
|
*/
|
|
89
96
|
function stripWhitespace(value, options) {
|
|
90
|
-
const opts = Object.assign({ leading:
|
|
91
|
-
if (typeof value !==
|
|
92
|
-
throw new TypeError(
|
|
97
|
+
const opts = Object.assign({ leading: "", trailing: "", nested: " " }, options);
|
|
98
|
+
if (typeof value !== "string") {
|
|
99
|
+
throw new TypeError("value must be a string");
|
|
93
100
|
}
|
|
94
|
-
if (typeof opts.leading !==
|
|
95
|
-
throw new TypeError(
|
|
101
|
+
if (typeof opts.leading !== "string") {
|
|
102
|
+
throw new TypeError("leading must be a string");
|
|
96
103
|
}
|
|
97
|
-
if (typeof opts.trailing !==
|
|
98
|
-
throw new TypeError(
|
|
104
|
+
if (typeof opts.trailing !== "string") {
|
|
105
|
+
throw new TypeError("trailing must be a string");
|
|
99
106
|
}
|
|
100
|
-
if (typeof opts.nested !==
|
|
101
|
-
throw new TypeError(
|
|
107
|
+
if (typeof opts.nested !== "string") {
|
|
108
|
+
throw new TypeError("nested must be a string");
|
|
102
109
|
}
|
|
103
110
|
return value
|
|
104
111
|
.replace(/^\s+/, opts.leading)
|
|
@@ -110,14 +117,14 @@ exports.stripWhitespace = stripWhitespace;
|
|
|
110
117
|
/**
|
|
111
118
|
* Checks if the given string can be used as an object key.
|
|
112
119
|
*
|
|
113
|
-
* @access private
|
|
114
120
|
* @param {string} key Proposed Object key
|
|
115
121
|
* @returns {string} Same key if it's valid
|
|
116
|
-
* @throws {Error}
|
|
122
|
+
* @throws {Error} If proposed key is an invalid keyword
|
|
123
|
+
* @access private
|
|
117
124
|
*/
|
|
118
125
|
function notProto(key) {
|
|
119
|
-
if ([
|
|
120
|
-
throw new Error(
|
|
126
|
+
if (["__proto__", "constructor", "prototype"].includes(String(key).toLowerCase())) {
|
|
127
|
+
throw new Error("Attempt to use prototype key disallowed");
|
|
121
128
|
}
|
|
122
129
|
return key;
|
|
123
130
|
}
|
|
@@ -125,56 +132,56 @@ exports.notProto = notProto;
|
|
|
125
132
|
/**
|
|
126
133
|
* Validate a hook name.
|
|
127
134
|
*
|
|
128
|
-
* @access private
|
|
129
135
|
* @param {string} hookName Hook name
|
|
130
136
|
* @returns {void}
|
|
131
137
|
* @throws {TypeError}
|
|
132
138
|
* @throws {SyntaxError}
|
|
139
|
+
* @access private
|
|
133
140
|
*/
|
|
134
141
|
function validateHookName(hookName) {
|
|
135
|
-
if (typeof hookName !==
|
|
136
|
-
throw new TypeError(
|
|
142
|
+
if (typeof hookName !== "string") {
|
|
143
|
+
throw new TypeError("Hook name must be a string");
|
|
137
144
|
}
|
|
138
145
|
if (!hookName.length) {
|
|
139
|
-
throw new SyntaxError(
|
|
146
|
+
throw new SyntaxError("Hook name must not be empty");
|
|
140
147
|
}
|
|
141
148
|
if (!hookName.match(/^([a-z_]+\.|)[a-z_]+$/i)) {
|
|
142
|
-
throw new SyntaxError(
|
|
149
|
+
throw new SyntaxError("Hook name must match either <scope>.<hookname> or <hookname> formats");
|
|
143
150
|
}
|
|
144
151
|
}
|
|
145
152
|
exports.validateHookName = validateHookName;
|
|
146
153
|
/**
|
|
147
154
|
* Validate a hook path.
|
|
148
155
|
*
|
|
149
|
-
* @access private
|
|
150
156
|
* @param {string} path URL path
|
|
151
157
|
* @returns {void}
|
|
152
158
|
* @throws {TypeError}
|
|
159
|
+
* @access private
|
|
153
160
|
*/
|
|
154
161
|
function validateHookPath(path) {
|
|
155
|
-
if (typeof path !==
|
|
156
|
-
throw new TypeError(
|
|
162
|
+
if (typeof path !== "string" && !(path instanceof RegExp)) {
|
|
163
|
+
throw new TypeError("Hook path must be a string or RegExp");
|
|
157
164
|
}
|
|
158
165
|
}
|
|
159
166
|
exports.validateHookPath = validateHookPath;
|
|
160
167
|
/**
|
|
161
168
|
* Validate a URL path.
|
|
162
169
|
*
|
|
163
|
-
* @access private
|
|
164
170
|
* @param {string} path URL path
|
|
165
171
|
* @returns {string} Same string, if valid
|
|
166
172
|
* @throws {TypeError}
|
|
167
173
|
* @throws {SyntaxError}
|
|
174
|
+
* @access private
|
|
168
175
|
*/
|
|
169
176
|
function validateUrlPath(path) {
|
|
170
|
-
if (typeof path !==
|
|
171
|
-
throw new TypeError(
|
|
177
|
+
if (typeof path !== "string") {
|
|
178
|
+
throw new TypeError("URL path must be a string");
|
|
172
179
|
}
|
|
173
180
|
if (path.match(/[^/a-z0-9_-]/)) {
|
|
174
|
-
throw new SyntaxError(
|
|
181
|
+
throw new SyntaxError("URL path must contain only a-z, 0-9, -, _ and / characters");
|
|
175
182
|
}
|
|
176
183
|
if (path.match(/\/{2,}/)) {
|
|
177
|
-
throw new SyntaxError(
|
|
184
|
+
throw new SyntaxError("URL path must not contain consecutive /");
|
|
178
185
|
}
|
|
179
186
|
return path;
|
|
180
187
|
}
|
|
@@ -182,42 +189,42 @@ exports.validateUrlPath = validateUrlPath;
|
|
|
182
189
|
/**
|
|
183
190
|
* Validate a template name.
|
|
184
191
|
*
|
|
185
|
-
* @access private
|
|
186
192
|
* @param {string} view Template name
|
|
187
193
|
* @returns {void}
|
|
188
194
|
* @throws {TypeError}
|
|
189
195
|
* @throws {SyntaxError}
|
|
196
|
+
* @access private
|
|
190
197
|
*/
|
|
191
198
|
function validateView(view) {
|
|
192
|
-
if (typeof view !==
|
|
193
|
-
throw new TypeError(
|
|
199
|
+
if (typeof view !== "string") {
|
|
200
|
+
throw new TypeError("View must be a string");
|
|
194
201
|
}
|
|
195
202
|
if (!view.length) {
|
|
196
|
-
throw new SyntaxError(
|
|
203
|
+
throw new SyntaxError("View must not be empty");
|
|
197
204
|
}
|
|
198
205
|
if (!view.match(/^[a-z0-9/_-]+\.njk$/i)) {
|
|
199
|
-
throw new SyntaxError(
|
|
206
|
+
throw new SyntaxError("View must contain only a-z, 0-9, -, _ and / characters, and end in .njk");
|
|
200
207
|
}
|
|
201
208
|
}
|
|
202
209
|
exports.validateView = validateView;
|
|
203
210
|
/**
|
|
204
211
|
* Validate a waypoint.
|
|
205
212
|
*
|
|
206
|
-
* @access private
|
|
207
213
|
* @param {string} waypoint Waypoint
|
|
208
214
|
* @returns {void}
|
|
209
215
|
* @throws {TypeError}
|
|
210
216
|
* @throws {SyntaxError}
|
|
217
|
+
* @access private
|
|
211
218
|
*/
|
|
212
219
|
function validateWaypoint(waypoint) {
|
|
213
|
-
if (typeof waypoint !==
|
|
214
|
-
throw new TypeError(
|
|
220
|
+
if (typeof waypoint !== "string") {
|
|
221
|
+
throw new TypeError("Waypoint must be a string");
|
|
215
222
|
}
|
|
216
223
|
if (!waypoint.length) {
|
|
217
|
-
throw new SyntaxError(
|
|
224
|
+
throw new SyntaxError("Waypoint must not be empty");
|
|
218
225
|
}
|
|
219
226
|
if (waypoint.match(/[^/a-z0-9_-]/)) {
|
|
220
|
-
throw new SyntaxError(
|
|
227
|
+
throw new SyntaxError("Waypoint must contain only a-z, 0-9, -, _ and / characters");
|
|
221
228
|
}
|
|
222
229
|
}
|
|
223
230
|
exports.validateWaypoint = validateWaypoint;
|
package/dist/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/lib/utils.js"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;GAMG;AACH,SAAgB,OAAO,CAAC,GAAG;IACzB,IACE,GAAG,KAAK,IAAI;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/lib/utils.js"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;GAMG;AACH,SAAgB,OAAO,CAAC,GAAG;IACzB,IACE,GAAG,KAAK,IAAI;QACZ,OAAO,GAAG,KAAK,WAAW;QAC1B,CAAC,OAAO,GAAG,KAAK,QAA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C;AAdD,4CAcC"}
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
2
3
|
* @access private
|
|
3
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {object} DateObjectConfigOptions
|
|
7
7
|
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
8
8
|
* @property {object} [afterOffsetFromNow] Offset from now
|
|
9
|
-
* @property {ErrorMessageConfig} [errorMsgAfterOffset] Error if date is after
|
|
9
|
+
* @property {ErrorMessageConfig} [errorMsgAfterOffset] Error if date is after
|
|
10
|
+
* this offset
|
|
10
11
|
* @property {object} [beforeOffsetFromNow] Offset from now
|
|
11
|
-
* @property {ErrorMessageConfig} [errorMsgBeforeOffset] Error if date is before
|
|
12
|
-
*
|
|
13
|
-
* @property {boolean} [
|
|
14
|
-
*
|
|
15
|
-
* @property {
|
|
12
|
+
* @property {ErrorMessageConfig} [errorMsgBeforeOffset] Error if date is before
|
|
13
|
+
* this offset
|
|
14
|
+
* @property {boolean} [allowMonthNames=false] Allow "Jan", "January", etc.
|
|
15
|
+
* Default is `false`
|
|
16
|
+
* @property {boolean} [allowSingleDigitDay=false] Allow "1" rather than "01".
|
|
17
|
+
* Default is `false`
|
|
18
|
+
* @property {boolean} [allowSingleDigitMonth=false] Allow "1" rather than "01".
|
|
19
|
+
* Default is `false`
|
|
20
|
+
* @property {DateTime} [now=false] Override the notion of "now" (useful for
|
|
21
|
+
* testing). Default is `false`
|
|
16
22
|
*/
|
|
17
23
|
/**
|
|
18
|
-
* Date object format:
|
|
19
|
-
* {
|
|
20
|
-
* dd: <string>,
|
|
21
|
-
* mm: <string>,
|
|
22
|
-
* yyyy: <string>
|
|
23
|
-
* }.
|
|
24
|
+
* Date object format: { dd: <string>, mm: <string>, yyyy: <string> }.
|
|
24
25
|
*
|
|
25
26
|
* Note that the time part will be zero'ed, as we are only interested in the
|
|
26
27
|
* date component (minimum day resolution).
|
|
@@ -36,7 +37,7 @@ export default class DateObject extends ValidatorFactory {
|
|
|
36
37
|
validate(value: any, dataContext?: {}): ValidationError[];
|
|
37
38
|
sanitise(value: any): any;
|
|
38
39
|
}
|
|
39
|
-
export type ErrorMessageConfig = import(
|
|
40
|
+
export type ErrorMessageConfig = import("../../casa").ErrorMessageConfig;
|
|
40
41
|
export type DateObjectConfigOptions = {
|
|
41
42
|
/**
|
|
42
43
|
* Error message config
|
|
@@ -47,7 +48,8 @@ export type DateObjectConfigOptions = {
|
|
|
47
48
|
*/
|
|
48
49
|
afterOffsetFromNow?: object | undefined;
|
|
49
50
|
/**
|
|
50
|
-
* Error if date is after
|
|
51
|
+
* Error if date is after
|
|
52
|
+
* this offset
|
|
51
53
|
*/
|
|
52
54
|
errorMsgAfterOffset?: import("../../casa").ErrorMessageConfig | undefined;
|
|
53
55
|
/**
|
|
@@ -55,25 +57,30 @@ export type DateObjectConfigOptions = {
|
|
|
55
57
|
*/
|
|
56
58
|
beforeOffsetFromNow?: object | undefined;
|
|
57
59
|
/**
|
|
58
|
-
* Error if date is before
|
|
60
|
+
* Error if date is before
|
|
61
|
+
* this offset
|
|
59
62
|
*/
|
|
60
63
|
errorMsgBeforeOffset?: import("../../casa").ErrorMessageConfig | undefined;
|
|
61
64
|
/**
|
|
62
|
-
* Allow "Jan", "January", etc
|
|
65
|
+
* Allow "Jan", "January", etc.
|
|
66
|
+
* Default is `false`
|
|
63
67
|
*/
|
|
64
68
|
allowMonthNames?: boolean | undefined;
|
|
65
69
|
/**
|
|
66
|
-
* Allow "1" rather than "01"
|
|
70
|
+
* Allow "1" rather than "01".
|
|
71
|
+
* Default is `false`
|
|
67
72
|
*/
|
|
68
73
|
allowSingleDigitDay?: boolean | undefined;
|
|
69
74
|
/**
|
|
70
|
-
* Allow "1" rather than "01"
|
|
75
|
+
* Allow "1" rather than "01".
|
|
76
|
+
* Default is `false`
|
|
71
77
|
*/
|
|
72
78
|
allowSingleDigitMonth?: boolean | undefined;
|
|
73
79
|
/**
|
|
74
|
-
* Override the notion of "now" (useful for
|
|
80
|
+
* Override the notion of "now" (useful for
|
|
81
|
+
* testing). Default is `false`
|
|
75
82
|
*/
|
|
76
83
|
now?: any;
|
|
77
84
|
};
|
|
78
|
-
import ValidatorFactory from
|
|
79
|
-
import ValidationError from
|
|
85
|
+
import ValidatorFactory from "../ValidatorFactory.js";
|
|
86
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -11,28 +11,29 @@ const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"))
|
|
|
11
11
|
const utils_js_1 = require("../utils.js");
|
|
12
12
|
const { isPlainObject } = lodash_1.default;
|
|
13
13
|
/**
|
|
14
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
14
15
|
* @access private
|
|
15
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
18
|
* @typedef {object} DateObjectConfigOptions
|
|
19
19
|
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
20
20
|
* @property {object} [afterOffsetFromNow] Offset from now
|
|
21
|
-
* @property {ErrorMessageConfig} [errorMsgAfterOffset] Error if date is after
|
|
21
|
+
* @property {ErrorMessageConfig} [errorMsgAfterOffset] Error if date is after
|
|
22
|
+
* this offset
|
|
22
23
|
* @property {object} [beforeOffsetFromNow] Offset from now
|
|
23
|
-
* @property {ErrorMessageConfig} [errorMsgBeforeOffset] Error if date is before
|
|
24
|
-
*
|
|
25
|
-
* @property {boolean} [
|
|
26
|
-
*
|
|
27
|
-
* @property {
|
|
24
|
+
* @property {ErrorMessageConfig} [errorMsgBeforeOffset] Error if date is before
|
|
25
|
+
* this offset
|
|
26
|
+
* @property {boolean} [allowMonthNames=false] Allow "Jan", "January", etc.
|
|
27
|
+
* Default is `false`
|
|
28
|
+
* @property {boolean} [allowSingleDigitDay=false] Allow "1" rather than "01".
|
|
29
|
+
* Default is `false`
|
|
30
|
+
* @property {boolean} [allowSingleDigitMonth=false] Allow "1" rather than "01".
|
|
31
|
+
* Default is `false`
|
|
32
|
+
* @property {DateTime} [now=false] Override the notion of "now" (useful for
|
|
33
|
+
* testing). Default is `false`
|
|
28
34
|
*/
|
|
29
35
|
/**
|
|
30
|
-
* Date object format:
|
|
31
|
-
* {
|
|
32
|
-
* dd: <string>,
|
|
33
|
-
* mm: <string>,
|
|
34
|
-
* yyyy: <string>
|
|
35
|
-
* }.
|
|
36
|
+
* Date object format: { dd: <string>, mm: <string>, yyyy: <string> }.
|
|
36
37
|
*
|
|
37
38
|
* Note that the time part will be zero'ed, as we are only interested in the
|
|
38
39
|
* date component (minimum day resolution).
|
|
@@ -46,49 +47,55 @@ class DateObject extends ValidatorFactory_js_1.default {
|
|
|
46
47
|
constructor() {
|
|
47
48
|
super(...arguments);
|
|
48
49
|
/** @property {string} name Validator name ("dateObject") */
|
|
49
|
-
this.name =
|
|
50
|
+
this.name = "dateObject";
|
|
50
51
|
}
|
|
51
52
|
validate(value, dataContext = {}) {
|
|
52
53
|
const config = Object.assign({ errorMsg: {
|
|
53
|
-
inline:
|
|
54
|
-
summary:
|
|
54
|
+
inline: "validation:rule.dateObject.inline",
|
|
55
|
+
summary: "validation:rule.dateObject.summary",
|
|
55
56
|
}, errorMsgAfterOffset: {
|
|
56
|
-
inline:
|
|
57
|
-
summary:
|
|
57
|
+
inline: "validation:rule.dateObject.afterOffset.inline",
|
|
58
|
+
summary: "validation:rule.dateObject.afterOffset.summary",
|
|
58
59
|
}, errorMsgBeforeOffset: {
|
|
59
|
-
inline:
|
|
60
|
-
summary:
|
|
60
|
+
inline: "validation:rule.dateObject.beforeOffset.inline",
|
|
61
|
+
summary: "validation:rule.dateObject.beforeOffset.summary",
|
|
61
62
|
}, now: luxon_1.DateTime.local(), allowSingleDigitDay: false, allowSingleDigitMonth: false, allowMonthNames: false, afterOffsetFromNow: undefined, beforeOffsetFromNow: undefined }, this.config);
|
|
62
63
|
let valid = false;
|
|
63
64
|
let { errorMsg } = config;
|
|
64
65
|
let luxonDate;
|
|
65
|
-
const NOW = config.now.startOf(
|
|
66
|
+
const NOW = config.now.startOf("day");
|
|
66
67
|
// Accepted formats
|
|
67
|
-
let formats = [
|
|
68
|
-
const formatTests = [
|
|
68
|
+
let formats = ["dd-MM-yyyy"];
|
|
69
|
+
const formatTests = [
|
|
70
|
+
{
|
|
69
71
|
flags: [config.allowSingleDigitDay],
|
|
70
|
-
formats: [
|
|
71
|
-
},
|
|
72
|
+
formats: ["d-MM-yyyy"],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
72
75
|
flags: [config.allowSingleDigitDay, config.allowSingleDigitMonth],
|
|
73
|
-
formats: [
|
|
74
|
-
},
|
|
76
|
+
formats: ["d-M-yyyy"],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
75
79
|
flags: [config.allowSingleDigitDay, config.allowMonthNames],
|
|
76
|
-
formats: [
|
|
77
|
-
},
|
|
80
|
+
formats: ["d-MMM-yyyy", "d-MMMM-yyyy"],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
78
83
|
flags: [config.allowSingleDigitMonth],
|
|
79
|
-
formats: [
|
|
80
|
-
},
|
|
84
|
+
formats: ["dd-M-yyyy"],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
81
87
|
flags: [config.allowMonthNames],
|
|
82
|
-
formats: [
|
|
83
|
-
}
|
|
88
|
+
formats: ["dd-MMM-yyyy", "dd-MMMM-yyyy"],
|
|
89
|
+
},
|
|
90
|
+
];
|
|
84
91
|
formatTests.forEach((test) => {
|
|
85
92
|
if (test.flags.every((v) => v === true)) {
|
|
86
93
|
formats = [...formats, ...test.formats];
|
|
87
94
|
}
|
|
88
95
|
});
|
|
89
|
-
if (typeof value ===
|
|
96
|
+
if (typeof value === "object") {
|
|
90
97
|
formats.find((format) => {
|
|
91
|
-
luxonDate = luxon_1.DateTime.fromFormat([value.dd, value.mm, value.yyyy].join(
|
|
98
|
+
luxonDate = luxon_1.DateTime.fromFormat([value.dd, value.mm, value.yyyy].join("-"), format).startOf("day");
|
|
92
99
|
valid = luxonDate.isValid;
|
|
93
100
|
return valid;
|
|
94
101
|
});
|
|
@@ -96,7 +103,7 @@ class DateObject extends ValidatorFactory_js_1.default {
|
|
|
96
103
|
// Check date is after the specified duration from now.
|
|
97
104
|
// Need to use UTC() otherwise DST shifts can affect the calculated offset
|
|
98
105
|
if (config.afterOffsetFromNow) {
|
|
99
|
-
const offsetDate = NOW.plus(config.afterOffsetFromNow).startOf(
|
|
106
|
+
const offsetDate = NOW.plus(config.afterOffsetFromNow).startOf("day");
|
|
100
107
|
if (luxonDate <= offsetDate) {
|
|
101
108
|
valid = false;
|
|
102
109
|
errorMsg = config.errorMsgAfterOffset;
|
|
@@ -105,7 +112,7 @@ class DateObject extends ValidatorFactory_js_1.default {
|
|
|
105
112
|
// Check date is before the specified duration from now
|
|
106
113
|
// Need to use UTC() otherwise DST shifts can affect the calculated offset
|
|
107
114
|
if (config.beforeOffsetFromNow) {
|
|
108
|
-
const offsetDate = NOW.plus(config.beforeOffsetFromNow).startOf(
|
|
115
|
+
const offsetDate = NOW.plus(config.beforeOffsetFromNow).startOf("day");
|
|
109
116
|
if (luxonDate >= offsetDate) {
|
|
110
117
|
valid = false;
|
|
111
118
|
errorMsg = config.errorMsgBeforeOffset;
|
|
@@ -115,30 +122,32 @@ class DateObject extends ValidatorFactory_js_1.default {
|
|
|
115
122
|
// Check presence of each object component (dd, mm, yyyy) in order to log
|
|
116
123
|
// which specific parts are in error
|
|
117
124
|
errorMsg.focusSuffix = [];
|
|
118
|
-
if (!Object.prototype.hasOwnProperty.call(value,
|
|
119
|
-
errorMsg.focusSuffix.push(
|
|
125
|
+
if (!Object.prototype.hasOwnProperty.call(value, "dd") || !value.dd) {
|
|
126
|
+
errorMsg.focusSuffix.push("[dd]");
|
|
120
127
|
}
|
|
121
|
-
if (!Object.prototype.hasOwnProperty.call(value,
|
|
122
|
-
errorMsg.focusSuffix.push(
|
|
128
|
+
if (!Object.prototype.hasOwnProperty.call(value, "mm") || !value.mm) {
|
|
129
|
+
errorMsg.focusSuffix.push("[mm]");
|
|
123
130
|
}
|
|
124
|
-
if (!Object.prototype.hasOwnProperty.call(value,
|
|
125
|
-
errorMsg.focusSuffix.push(
|
|
131
|
+
if (!Object.prototype.hasOwnProperty.call(value, "yyyy") || !value.yyyy) {
|
|
132
|
+
errorMsg.focusSuffix.push("[yyyy]");
|
|
126
133
|
}
|
|
127
134
|
// If the date is invalid, but not specific parts have been highlighted in
|
|
128
135
|
// error, then highlight all inputs, focusing on the [dd] first
|
|
129
136
|
if (!valid && !errorMsg.focusSuffix.length) {
|
|
130
|
-
errorMsg.focusSuffix = [
|
|
137
|
+
errorMsg.focusSuffix = ["[dd]", "[mm]", "[yyyy]"];
|
|
131
138
|
}
|
|
132
139
|
}
|
|
133
140
|
return valid ? [] : [ValidationError_js_1.default.make({ errorMsg, dataContext })];
|
|
134
141
|
}
|
|
135
142
|
sanitise(value) {
|
|
136
143
|
if (value !== undefined) {
|
|
137
|
-
return isPlainObject(value)
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
return isPlainObject(value)
|
|
145
|
+
? {
|
|
146
|
+
dd: (0, utils_js_1.stripWhitespace)((0, utils_js_1.stringifyInput)(value.dd)),
|
|
147
|
+
mm: (0, utils_js_1.stripWhitespace)((0, utils_js_1.stringifyInput)(value.mm)),
|
|
148
|
+
yyyy: (0, utils_js_1.stripWhitespace)((0, utils_js_1.stringifyInput)(value.yyyy)),
|
|
149
|
+
}
|
|
150
|
+
: Object.create(null);
|
|
142
151
|
}
|
|
143
152
|
return undefined;
|
|
144
153
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateObject.js","sourceRoot":"","sources":["../../../src/lib/validators/dateObject.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3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6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
2
3
|
* @access private
|
|
3
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {object} EmailConfigOptions
|
|
@@ -22,12 +22,12 @@ export default class Email extends ValidatorFactory {
|
|
|
22
22
|
validate(value: any, dataContext?: {}): ValidationError[];
|
|
23
23
|
sanitise(value: any): string | undefined;
|
|
24
24
|
}
|
|
25
|
-
export type ErrorMessageConfig = import(
|
|
25
|
+
export type ErrorMessageConfig = import("../../casa").ErrorMessageConfig;
|
|
26
26
|
export type EmailConfigOptions = {
|
|
27
27
|
/**
|
|
28
28
|
* Error message config
|
|
29
29
|
*/
|
|
30
30
|
errorMsg: ErrorMessageConfig;
|
|
31
31
|
};
|
|
32
|
-
import ValidatorFactory from
|
|
33
|
-
import ValidationError from
|
|
32
|
+
import ValidatorFactory from "../ValidatorFactory.js";
|
|
33
|
+
import ValidationError from "../ValidationError.js";
|