@dwp/govuk-casa 6.8.4 → 6.9.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/CHANGELOG.md +23 -0
- package/casa.js +4 -3
- package/dist/casa/css/casa-ie8.css +1 -1
- package/dist/casa/css/casa.css +1 -1
- package/dist/casa/js/casa.js +1 -1
- package/lib/ConfigIngestor.js +119 -94
- package/lib/GatherModifier.js +1 -1
- package/lib/I18n.js +12 -11
- package/lib/JourneyContext.js +33 -30
- package/lib/JourneyMap.js +24 -16
- package/lib/JourneyRoad.js +25 -18
- package/lib/Logger.js +3 -3
- package/lib/PageDirectory.js +3 -3
- package/lib/Plan.js +31 -30
- package/lib/Util.js +20 -20
- package/lib/Validation.js +1 -1
- package/lib/bootstrap/end-session.js +2 -2
- package/lib/bootstrap/load-definitions.js +9 -9
- package/lib/gather-modifiers/trimPostalAddressObject.js +5 -5
- package/lib/gather-modifiers/trimWhitespace.js +4 -4
- package/lib/utils/makeEditLink.js +6 -3
- package/lib/utils/sanitise.js +1 -1
- package/lib/validation/ArrayObjectField.js +5 -4
- package/lib/validation/ObjectField.js +4 -3
- package/lib/validation/SimpleField.js +4 -3
- package/lib/validation/ValidationError.js +5 -2
- package/lib/validation/processor/flattenErrorArray.js +3 -2
- package/lib/validation/processor/queue.js +28 -28
- package/lib/validation/processor.js +9 -5
- package/lib/validation/rules/dateObject.js +2 -2
- package/lib/validation/rules/email.js +1 -1
- package/lib/validation/rules/inArray.js +3 -3
- package/lib/validation/rules/nino.js +2 -2
- package/lib/validation/rules/optional.js +2 -2
- package/lib/validation/rules/postalAddressObject.js +2 -2
- package/lib/validation/rules/regex.js +1 -1
- package/lib/validation/rules/required.js +3 -3
- package/lib/validation/rules/strlen.js +1 -1
- package/lib/view-filters/formatDateObject.js +6 -3
- package/lib/view-filters/includes.js +4 -4
- package/lib/view-filters/index.js +1 -1
- package/lib/view-filters/mergeObjectsDeep.js +3 -2
- package/lib/view-filters/renderAsAttributes.js +1 -1
- package/middleware/headers/config-defaults.js +2 -0
- package/middleware/i18n/i18n.js +15 -15
- package/middleware/nunjucks/environment.js +8 -9
- package/middleware/page/csrf.js +1 -1
- package/middleware/page/gather.js +1 -1
- package/middleware/page/index.js +5 -5
- package/middleware/page/journey-continue.js +15 -2
- package/middleware/page/journey-rails.js +1 -1
- package/middleware/page/prepare-request.js +2 -2
- package/middleware/page/skip.js +1 -1
- package/middleware/page/utils.js +37 -36
- package/middleware/page/validate.js +1 -1
- package/middleware/session/index.js +1 -1
- package/middleware/static/index.js +12 -7
- package/middleware/static/prepare-assets.js +4 -4
- package/middleware/static/serve-assets.js +4 -7
- package/package.json +51 -53
- package/src/js/casa.js +10 -6
- package/views/casa/layouts/main.njk +9 -0
- package/src/robots.txt +0 -2
package/lib/JourneyMap.js
CHANGED
|
@@ -12,8 +12,10 @@ class JourneyMap {
|
|
|
12
12
|
* waypoints in order to help CASA identify which journey the user is
|
|
13
13
|
* requesting. Thefore, if used, then it must be a valid URL slug.
|
|
14
14
|
*
|
|
15
|
-
* @
|
|
16
|
-
* @param {string} guid An ID that uniquely represents this journey
|
|
15
|
+
* @class
|
|
16
|
+
* @param {string} guid An ID that uniquely represents this journey.
|
|
17
|
+
* @throws {TypeError} When guid is invalid
|
|
18
|
+
* @throws {SyntaxError} When guid is misformatted
|
|
17
19
|
*/
|
|
18
20
|
constructor(guid = null) {
|
|
19
21
|
if (guid !== null) {
|
|
@@ -33,7 +35,7 @@ class JourneyMap {
|
|
|
33
35
|
/**
|
|
34
36
|
* Get guid
|
|
35
37
|
*
|
|
36
|
-
* @
|
|
38
|
+
* @returns {string} Journey GUID
|
|
37
39
|
*/
|
|
38
40
|
get guid() {
|
|
39
41
|
return privates.get(this).guid;
|
|
@@ -43,8 +45,9 @@ class JourneyMap {
|
|
|
43
45
|
* Define the starting point for this map - the first road that will be
|
|
44
46
|
* traversed.
|
|
45
47
|
*
|
|
46
|
-
* @param {JourneyRoad} road First road on the journey
|
|
47
|
-
* @
|
|
48
|
+
* @param {JourneyRoad} road First road on the journey.
|
|
49
|
+
* @returns {ujMap} (chain).
|
|
50
|
+
* @throws {Error} When a non-Road is given as the starting point
|
|
48
51
|
*/
|
|
49
52
|
startAt(road) {
|
|
50
53
|
const priv = privates.get(this);
|
|
@@ -64,7 +67,8 @@ class JourneyMap {
|
|
|
64
67
|
* The order of the returned array is insignificant. The purpose of this method
|
|
65
68
|
* is to provide a means of determining if a waypoint exists on the map.
|
|
66
69
|
*
|
|
67
|
-
* @
|
|
70
|
+
* @returns {Array} List of all waypoints on the map.
|
|
71
|
+
* @throws {Error} When a starting waypoint is undefined.
|
|
68
72
|
*/
|
|
69
73
|
allWaypoints() {
|
|
70
74
|
const priv = privates.get(this);
|
|
@@ -80,9 +84,11 @@ class JourneyMap {
|
|
|
80
84
|
const followedRoads = [];
|
|
81
85
|
|
|
82
86
|
/**
|
|
83
|
-
*
|
|
87
|
+
* Follow a road.
|
|
88
|
+
*
|
|
89
|
+
* @param {JourneyRoad} road Road to follow.
|
|
84
90
|
* @returns {void}
|
|
85
|
-
* @throws {Error} For invalid POI type
|
|
91
|
+
* @throws {Error} For invalid POI type.
|
|
86
92
|
*/
|
|
87
93
|
function followRoad(road) {
|
|
88
94
|
if (followedRoads.indexOf(road) > -1) {
|
|
@@ -123,7 +129,7 @@ class JourneyMap {
|
|
|
123
129
|
* at _all_ waypoints in the map.
|
|
124
130
|
*
|
|
125
131
|
* @param {string} waypointId Waypoint ID to find.
|
|
126
|
-
* @
|
|
132
|
+
* @returns {boolean} Whether waypoint is present in the map or not.
|
|
127
133
|
*/
|
|
128
134
|
containsWaypoint(waypointId) {
|
|
129
135
|
return this.allWaypoints().indexOf(waypointId) > -1;
|
|
@@ -134,9 +140,9 @@ class JourneyMap {
|
|
|
134
140
|
* visiting/forking/merging along the way.
|
|
135
141
|
*
|
|
136
142
|
* The resulting list of waypoints include those that either a) have related
|
|
137
|
-
* data in context (i.e.
|
|
143
|
+
* data in context (i.e. Context[waypoint.id] exists and is not empty) and there
|
|
138
144
|
* are no validation errors on that waypoint, or b) exhaust the list of possible
|
|
139
|
-
* waypoints (we reach the end of the journey)
|
|
145
|
+
* waypoints (we reach the end of the journey).
|
|
140
146
|
*
|
|
141
147
|
* The context associated with a waypoint is considered not-empty if it is an
|
|
142
148
|
* object, and it has at least one attribute specified within that object.
|
|
@@ -148,9 +154,10 @@ class JourneyMap {
|
|
|
148
154
|
* a JourneyContext instance, for example) so that caller can arbitrarily decide
|
|
149
155
|
* whether or not to include a validation context whilst traversing.
|
|
150
156
|
*
|
|
151
|
-
* @param {object} dataContext Data for each waypoint in the journey
|
|
152
|
-
* @param {object} validationContext Validation errors for each waypoint in the journey
|
|
153
|
-
* @
|
|
157
|
+
* @param {object} dataContext Data for each waypoint in the journey.
|
|
158
|
+
* @param {object} validationContext Validation errors for each waypoint in the journey.
|
|
159
|
+
* @returns {Array} List of waypoint IDs that have been traversed (in order).
|
|
160
|
+
* @throws {Error} When start point is undefined.
|
|
154
161
|
*/
|
|
155
162
|
traverse(dataContext = {}, validationContext = {}) {
|
|
156
163
|
const priv = privates.get(this);
|
|
@@ -189,8 +196,9 @@ class JourneyMap {
|
|
|
189
196
|
* will not necessarily provide the expected data when executing that logic
|
|
190
197
|
* (because it may not have been gathered yet).
|
|
191
198
|
*
|
|
192
|
-
* @param {object} dataContext Data for each waypoint in the journey
|
|
193
|
-
* @
|
|
199
|
+
* @param {object} dataContext Data for each waypoint in the journey.
|
|
200
|
+
* @returns {Array} List of waypoint IDs that have been traversed (in order).
|
|
201
|
+
* @throws {Error} When a starting point is undefined
|
|
194
202
|
*/
|
|
195
203
|
traverseAhead(dataContext = {}) {
|
|
196
204
|
const priv = privates.get(this);
|
package/lib/JourneyRoad.js
CHANGED
|
@@ -3,11 +3,13 @@ const privates = new WeakMap();
|
|
|
3
3
|
/* --------------------------------------------------------------------- Road */
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Road
|
|
6
|
+
* Road.
|
|
7
7
|
*/
|
|
8
8
|
class JourneyRoad {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* JourneyRoad.
|
|
11
|
+
*
|
|
12
|
+
* @class
|
|
11
13
|
*/
|
|
12
14
|
constructor() {
|
|
13
15
|
// "Points of Interest" along our journey.
|
|
@@ -18,7 +20,7 @@ class JourneyRoad {
|
|
|
18
20
|
});
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
/**
|
|
23
|
+
/** ..
|
|
22
24
|
* Add a new waypoint(s) to the journey. A waypoint is simply a string (or a
|
|
23
25
|
* function - see below) that uniquely identifies a stopping point on the
|
|
24
26
|
* journey. Typically this will be the URL slug of a single page.
|
|
@@ -27,14 +29,14 @@ class JourneyRoad {
|
|
|
27
29
|
* the function will be executed (at runtime) to determine if the waypoint
|
|
28
30
|
* should be included or not (based on a given data context). In this case, pass
|
|
29
31
|
* the waypoint ID and function as an array:
|
|
30
|
-
*
|
|
32
|
+
* AddWaypoints([
|
|
31
33
|
* 'normal-waypoint',
|
|
32
34
|
* ['conditional-waypoint', (context) => {...return bool...}]
|
|
33
35
|
* ]);
|
|
34
36
|
*
|
|
35
37
|
* You can also define waypoints as objects, which supports additional
|
|
36
|
-
* functionality.
|
|
37
|
-
*
|
|
38
|
+
* functionality. E.g.
|
|
39
|
+
* AddWaypoints([
|
|
38
40
|
* 'normal-waypoint',
|
|
39
41
|
* {
|
|
40
42
|
* id: 'conditional-waypoint',
|
|
@@ -48,8 +50,10 @@ class JourneyRoad {
|
|
|
48
50
|
* held against that waypoint, and b) an absence of validation errors
|
|
49
51
|
* associated with the waypoint.
|
|
50
52
|
*
|
|
51
|
-
* @param {
|
|
52
|
-
* @
|
|
53
|
+
* @param {Array | string} points Add these waypoint(s) in the order defined.
|
|
54
|
+
* @returns {JourneyRoad} (chain).
|
|
55
|
+
* @throws {Error} When waypoint ordering is invalid
|
|
56
|
+
* @throws {TypeError} When any waypoint definitions are invalid
|
|
53
57
|
*/
|
|
54
58
|
addWaypoints(points) {
|
|
55
59
|
const priv = privates.get(this);
|
|
@@ -102,9 +106,9 @@ class JourneyRoad {
|
|
|
102
106
|
* This can be overriden per-waypoint by passing in a custom `is_passable`
|
|
103
107
|
* function.
|
|
104
108
|
*
|
|
105
|
-
* @param {object} dc Data context
|
|
106
|
-
* @param {object} vc Validation context
|
|
107
|
-
* @returns {bool} True if the waypoint is passable
|
|
109
|
+
* @param {object} dc Data context.
|
|
110
|
+
* @param {object} vc Validation context.
|
|
111
|
+
* @returns {bool} True if the waypoint is passable.
|
|
108
112
|
*/
|
|
109
113
|
function defaultPassableCondition(dc, vc) {
|
|
110
114
|
return (dc
|
|
@@ -185,9 +189,10 @@ class JourneyRoad {
|
|
|
185
189
|
* ... return one of the roads based on context ...
|
|
186
190
|
* }
|
|
187
191
|
*
|
|
188
|
-
* @param {
|
|
189
|
-
* @param {
|
|
190
|
-
* @
|
|
192
|
+
* @param {Array} roads Array of road choices (order is important)
|
|
193
|
+
* @param {Function} test Function used to determine which of the roads to take
|
|
194
|
+
* @returns {JourneyRoad} (chain)
|
|
195
|
+
* @throws {Error} When a fork is created prematurely
|
|
191
196
|
*/
|
|
192
197
|
fork(roads, test) {
|
|
193
198
|
const priv = privates.get(this);
|
|
@@ -233,8 +238,9 @@ class JourneyRoad {
|
|
|
233
238
|
/**
|
|
234
239
|
* Merge this road into another road.
|
|
235
240
|
*
|
|
236
|
-
* @param {JourneyRoad} road Road into which this one will merge
|
|
237
|
-
* @
|
|
241
|
+
* @param {JourneyRoad} road Road into which this one will merge.
|
|
242
|
+
* @returns {JourneyRoad} (chain).
|
|
243
|
+
* @throws {Error} When merge is create prematurely.
|
|
238
244
|
*/
|
|
239
245
|
mergeWith(road) {
|
|
240
246
|
const priv = privates.get(this);
|
|
@@ -273,7 +279,8 @@ class JourneyRoad {
|
|
|
273
279
|
/**
|
|
274
280
|
* Road ends here.
|
|
275
281
|
*
|
|
276
|
-
* @
|
|
282
|
+
* @returns {JourneyRoad} (chain).
|
|
283
|
+
* @throws {Error} When the road ends prematurely.
|
|
277
284
|
*/
|
|
278
285
|
end() {
|
|
279
286
|
const priv = privates.get(this);
|
|
@@ -300,7 +307,7 @@ class JourneyRoad {
|
|
|
300
307
|
/**
|
|
301
308
|
* Return a copy of all POIs along this road.
|
|
302
309
|
*
|
|
303
|
-
* @
|
|
310
|
+
* @returns {Array} POI objects.
|
|
304
311
|
*/
|
|
305
312
|
getPOIs() {
|
|
306
313
|
const priv = privates.get(this);
|
package/lib/Logger.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = function Logger(suffix) {
|
|
|
28
28
|
/**
|
|
29
29
|
* Set the session ID for all messages in this debugger.
|
|
30
30
|
*
|
|
31
|
-
* @param {string} sid Session ID]
|
|
31
|
+
* @param {string} sid Session ID].
|
|
32
32
|
* @returns {void}
|
|
33
33
|
*/
|
|
34
34
|
function setSessionId(sid) {
|
|
@@ -38,8 +38,8 @@ module.exports = function Logger(suffix) {
|
|
|
38
38
|
/**
|
|
39
39
|
* Wrapper for appending the session ID to all messages.
|
|
40
40
|
*
|
|
41
|
-
* @param {...string} args Message(s)
|
|
42
|
-
* @
|
|
41
|
+
* @param {...string} args Message(s).
|
|
42
|
+
* @returns {void}
|
|
43
43
|
*/
|
|
44
44
|
function writer(...args) {
|
|
45
45
|
const logArgs = args;
|
package/lib/PageDirectory.js
CHANGED
|
@@ -45,7 +45,7 @@ class PageDirectory {
|
|
|
45
45
|
/**
|
|
46
46
|
* Get all page IDs in the directory.
|
|
47
47
|
*
|
|
48
|
-
* @
|
|
48
|
+
* @returns {Array} Page IDs.
|
|
49
49
|
*/
|
|
50
50
|
getAllPageIds() {
|
|
51
51
|
const priv = privates.get(this);
|
|
@@ -56,7 +56,7 @@ class PageDirectory {
|
|
|
56
56
|
* Get page metadata for specific page
|
|
57
57
|
*
|
|
58
58
|
* @param {string} pageId Page ID
|
|
59
|
-
* @
|
|
59
|
+
* @returns {object} Page metadata
|
|
60
60
|
*/
|
|
61
61
|
getPageMeta(pageId) {
|
|
62
62
|
const priv = privates.get(this);
|
|
@@ -66,7 +66,7 @@ class PageDirectory {
|
|
|
66
66
|
/**
|
|
67
67
|
* Get all pages.
|
|
68
68
|
*
|
|
69
|
-
* @
|
|
69
|
+
* @returns {object} All pages indexed by waypoint ID.
|
|
70
70
|
*/
|
|
71
71
|
getPages() {
|
|
72
72
|
const priv = privates.get(this);
|
package/lib/Plan.js
CHANGED
|
@@ -6,9 +6,9 @@ const logger = require('./Logger.js')('class.Plan');
|
|
|
6
6
|
* Will check if the source waypoint has specifically passed validation, i.e
|
|
7
7
|
* there is a "null" validation entry for the route source.
|
|
8
8
|
*
|
|
9
|
-
* @param {object} r Route meta
|
|
10
|
-
* @param {JourneyContext} context Journey Context
|
|
11
|
-
* @returns {boolean}
|
|
9
|
+
* @param {object} r Route meta.
|
|
10
|
+
* @param {JourneyContext} context Journey Context.
|
|
11
|
+
* @returns {boolean} Condition result.
|
|
12
12
|
*/
|
|
13
13
|
function defaultNextFollow(r, context) {
|
|
14
14
|
const { validation: v = {} } = context.toObject();
|
|
@@ -19,9 +19,9 @@ function defaultNextFollow(r, context) {
|
|
|
19
19
|
* Will check if the target waypoint (the one we're moving back to) has
|
|
20
20
|
* specifically passed validation.
|
|
21
21
|
*
|
|
22
|
-
* @param {object} r Route meta
|
|
23
|
-
* @param {JourneyContext} context Journey context
|
|
24
|
-
* @returns {boolean}
|
|
22
|
+
* @param {object} r Route meta.
|
|
23
|
+
* @param {JourneyContext} context Journey context.
|
|
24
|
+
* @returns {boolean} Condition result.
|
|
25
25
|
*/
|
|
26
26
|
function defaultPrevFollow(r, context) {
|
|
27
27
|
const { validation: v = {} } = context.toObject();
|
|
@@ -53,9 +53,9 @@ function validateRouteCondition(val) {
|
|
|
53
53
|
* be used in userland. This is the object that will be passed into follow
|
|
54
54
|
* functions too as the "route" parameter.
|
|
55
55
|
*
|
|
56
|
-
* @param {object} dgraph Directed graph instance
|
|
57
|
-
* @param {object} edge Graph edge object
|
|
58
|
-
* @returns {object} Route
|
|
56
|
+
* @param {object} dgraph Directed graph instance.
|
|
57
|
+
* @param {object} edge Graph edge object.
|
|
58
|
+
* @returns {object} Route.
|
|
59
59
|
*/
|
|
60
60
|
const makeRouteObject = (dgraph, edge) => {
|
|
61
61
|
const label = dgraph.edge(edge) || {
|
|
@@ -131,9 +131,9 @@ class Plan {
|
|
|
131
131
|
* Return all outward routes (out-edges) from the given waypoint, to the
|
|
132
132
|
* optional target waypoint.
|
|
133
133
|
*
|
|
134
|
-
* @param {string} src Source waypoint
|
|
135
|
-
* @param {string} tgt Target waypoint (optional)
|
|
136
|
-
* @returns {Array<object>} Route objects found
|
|
134
|
+
* @param {string} src Source waypoint.
|
|
135
|
+
* @param {string} tgt Target waypoint (optional).
|
|
136
|
+
* @returns {Array<object>} Route objects found.
|
|
137
137
|
*/
|
|
138
138
|
getOutwardRoutes(src, tgt = null) {
|
|
139
139
|
const self = priv.get(this);
|
|
@@ -144,9 +144,9 @@ class Plan {
|
|
|
144
144
|
* Return all outward routes (out-edges) from the given waypoint, to the
|
|
145
145
|
* optional target waypoint, matching the "prev" name.
|
|
146
146
|
*
|
|
147
|
-
* @param {string} src Source waypoint
|
|
148
|
-
* @param {string} tgt Target waypoint (optional)
|
|
149
|
-
* @returns {Array<object>} Route objects found
|
|
147
|
+
* @param {string} src Source waypoint.
|
|
148
|
+
* @param {string} tgt Target waypoint (optional).
|
|
149
|
+
* @returns {Array<object>} Route objects found.
|
|
150
150
|
*/
|
|
151
151
|
getPrevOutwardRoutes(src, tgt = null) {
|
|
152
152
|
return this.getOutwardRoutes(src, tgt).filter((r) => r.name === 'prev');
|
|
@@ -201,11 +201,11 @@ class Plan {
|
|
|
201
201
|
* have been true, and so to reverse the direction we also need that same test
|
|
202
202
|
* to be true.
|
|
203
203
|
*
|
|
204
|
-
* @param {string} src Source waypoint
|
|
205
|
-
* @param {string} tgt Target waypoint
|
|
206
|
-
* @param {
|
|
207
|
-
* @param {
|
|
208
|
-
* @returns {Plan}
|
|
204
|
+
* @param {string} src Source waypoint.
|
|
205
|
+
* @param {string} tgt Target waypoint.
|
|
206
|
+
* @param {Function} followNext Follow test function.
|
|
207
|
+
* @param {Function} followPrev Follow test function.
|
|
208
|
+
* @returns {Plan} Self.
|
|
209
209
|
*/
|
|
210
210
|
setRoute(src, tgt, followNext = undefined, followPrev = undefined) {
|
|
211
211
|
this.setNamedRoute(src, tgt, 'next', followNext);
|
|
@@ -228,11 +228,11 @@ class Plan {
|
|
|
228
228
|
* Note that if you specify an origin in one waypoint, you must specify one in
|
|
229
229
|
* the other waypoint too.
|
|
230
230
|
*
|
|
231
|
-
* @param {string} srcId Source waypoint
|
|
232
|
-
* @param {string} tgtId Target waypoint
|
|
233
|
-
* @param {string} name Name of the route (must be unique for this waypoint pairing)
|
|
234
|
-
* @param {
|
|
235
|
-
* @
|
|
231
|
+
* @param {string} srcId Source waypoint.
|
|
232
|
+
* @param {string} tgtId Target waypoint.
|
|
233
|
+
* @param {string} name Name of the route (must be unique for this waypoint pairing).
|
|
234
|
+
* @param {Function} follow Test function to determine if route can be followed.
|
|
235
|
+
* @returns {Plan} Chain.
|
|
236
236
|
*/
|
|
237
237
|
setNamedRoute(srcId, tgtId, name, follow) {
|
|
238
238
|
const self = priv.get(this);
|
|
@@ -290,9 +290,9 @@ class Plan {
|
|
|
290
290
|
* This is a convenience method for traversing all "next" routes, and returning
|
|
291
291
|
* the IDs of all waypoints visited along the way.
|
|
292
292
|
*
|
|
293
|
-
* @param {JourneyContext} context Journey Context
|
|
294
|
-
* @param {object} options Options
|
|
295
|
-
* @returns {Array<string>} List of traversed waypoints
|
|
293
|
+
* @param {JourneyContext} context Journey Context.
|
|
294
|
+
* @param {object} options Options.
|
|
295
|
+
* @returns {Array<string>} List of traversed waypoints.
|
|
296
296
|
*/
|
|
297
297
|
traverse(context, options = {}) {
|
|
298
298
|
return this.traverseNextRoutes(context, options).map((e) => e.source);
|
|
@@ -312,7 +312,7 @@ class Plan {
|
|
|
312
312
|
* Exploration.
|
|
313
313
|
*
|
|
314
314
|
* The last route in the list will contain the source of the last waypoint that
|
|
315
|
-
* can be reached, i.e.
|
|
315
|
+
* can be reached, i.e. The waypoint that has no further satisfiable out-edges.
|
|
316
316
|
*
|
|
317
317
|
* If a cyclical set of routes are encountered, traversal will stop after
|
|
318
318
|
* reaching the first repeated waypoint.
|
|
@@ -326,6 +326,7 @@ class Plan {
|
|
|
326
326
|
* @param {JourneyContext} context Journey context
|
|
327
327
|
* @param {object} options Options
|
|
328
328
|
* @returns {Array<object>} Routes that were traversed
|
|
329
|
+
* @throws {TypeError} When context is not a JourneyContext
|
|
329
330
|
*/
|
|
330
331
|
traverseRoutes(context, options = {}) {
|
|
331
332
|
if (!(context instanceof JourneyContext)) {
|
|
@@ -412,7 +413,7 @@ class Plan {
|
|
|
412
413
|
* Get raw graph data structure. This can be used with other libraries to
|
|
413
414
|
* generate graph visualisations, for example.
|
|
414
415
|
*
|
|
415
|
-
* @returns {graphlib.Graph} Graph data structure
|
|
416
|
+
* @returns {graphlib.Graph} Graph data structure.
|
|
416
417
|
*/
|
|
417
418
|
getGraphStructure() {
|
|
418
419
|
return priv.get(this).dgraph;
|
package/lib/Util.js
CHANGED
|
@@ -8,8 +8,8 @@ const logger = require('./Logger')('util');
|
|
|
8
8
|
* Generate an object path string that we can use to traverse an object using
|
|
9
9
|
* `objectPathValue()`.
|
|
10
10
|
*
|
|
11
|
-
* @param {...string} paths Path components
|
|
12
|
-
* @
|
|
11
|
+
* @param {...string} paths Path components.
|
|
12
|
+
* @returns {string} Constructed path.
|
|
13
13
|
*/
|
|
14
14
|
function objectPathString(...paths) {
|
|
15
15
|
let pathString = paths.length ? paths.join('.') : '';
|
|
@@ -31,7 +31,7 @@ function objectPathString(...paths) {
|
|
|
31
31
|
* }
|
|
32
32
|
* }
|
|
33
33
|
* }
|
|
34
|
-
* ...
|
|
34
|
+
* ... A call to `objectPathValue(obj, 'rooms.lounge.objects[0]')` would
|
|
35
35
|
* return "TV".
|
|
36
36
|
*
|
|
37
37
|
* If using square-braces to access object keys, you also need to wrap the key
|
|
@@ -43,7 +43,7 @@ function objectPathString(...paths) {
|
|
|
43
43
|
*
|
|
44
44
|
* @param {object} obj Object to traverse
|
|
45
45
|
* @param {string} paths Path component(s) to use
|
|
46
|
-
* @
|
|
46
|
+
* @returns {any} The value of the object, or `undefined` if not found
|
|
47
47
|
*/
|
|
48
48
|
function objectPathValue(obj, ...paths) {
|
|
49
49
|
let pathString = objectPathString(...paths);
|
|
@@ -67,7 +67,7 @@ function objectPathValue(obj, ...paths) {
|
|
|
67
67
|
* no quotations.
|
|
68
68
|
*
|
|
69
69
|
* @param {string} pathString Path to normalize.
|
|
70
|
-
* @
|
|
70
|
+
* @returns {string} Normalized path.
|
|
71
71
|
*/
|
|
72
72
|
function normalizeHtmlObjectPath(pathString) {
|
|
73
73
|
return pathString.replace(/\[["']([^\]]+?)['"]\]/g, '[$1]').replace(/[[\]]/g, '.').replace(/\.+/g, '.').replace(/\.+/g, '][')
|
|
@@ -84,9 +84,9 @@ function normalizeHtmlObjectPath(pathString) {
|
|
|
84
84
|
• Options:
|
|
85
85
|
* RegExp regexRemove = characters matching this regex are removed before test
|
|
86
86
|
*
|
|
87
|
-
* @param {
|
|
87
|
+
* @param {any} e Value to check
|
|
88
88
|
* @param {object} options Options (see above)
|
|
89
|
-
* @
|
|
89
|
+
* @returns {boolean} True if the object is empty
|
|
90
90
|
*/
|
|
91
91
|
function isEmpty(e, options) {
|
|
92
92
|
let val = e;
|
|
@@ -114,7 +114,7 @@ function isEmpty(e, options) {
|
|
|
114
114
|
*
|
|
115
115
|
* @param {Array} journeys Array of UserJourney.Map instances
|
|
116
116
|
* @param {string} url URL to parse
|
|
117
|
-
* @
|
|
117
|
+
* @returns {UserJourney.Map|null} The associated journey
|
|
118
118
|
*/
|
|
119
119
|
function getJourneyFromUrl(journeys, url) {
|
|
120
120
|
// Single-journeys are not reflected in URLs
|
|
@@ -138,8 +138,8 @@ function getPageIdFromJourneyUrl(journey, url) {
|
|
|
138
138
|
/**
|
|
139
139
|
* Extract the originId, and current waypoint being visited from the given url.
|
|
140
140
|
*
|
|
141
|
-
* @param {string} url URL
|
|
142
|
-
* @returns {object} The origin ID, and current waypoint
|
|
141
|
+
* @param {string} url URL.
|
|
142
|
+
* @returns {object} The origin ID, and current waypoint.
|
|
143
143
|
*/
|
|
144
144
|
function parseOriginWaypointInUrl(url) {
|
|
145
145
|
try {
|
|
@@ -176,14 +176,14 @@ function isObjectWithKeys(target, keys = []) {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
179
|
+
* Discover the root folder of the specified npm module.
|
|
180
|
+
*
|
|
181
|
+
* @param {string} module Name of npm module to go and find.
|
|
182
|
+
* @param {Array} paths Paths to search on for module folder.
|
|
183
|
+
* @returns {string} The absolute path to the named module, if found.
|
|
184
|
+
* @throws Error When the module cannot be found.
|
|
185
|
+
* @throws SyntaxError When the module name contains invalid characters.
|
|
186
|
+
*/
|
|
187
187
|
function resolveModulePath(module = '', paths = []) {
|
|
188
188
|
// Strip rogue chars from module name; only valid npm package names are
|
|
189
189
|
// expected (https://docs.npmjs.com/files/package.json#name)
|
|
@@ -205,8 +205,8 @@ module.exports = {
|
|
|
205
205
|
* Convert a given URL into an ID that we can use to uniquely identify a
|
|
206
206
|
* specific page. This function will not verify the page ID is valid.
|
|
207
207
|
*
|
|
208
|
-
* @param {string} url Url to parse
|
|
209
|
-
* @
|
|
208
|
+
* @param {string} url Url to parse.
|
|
209
|
+
* @returns {string} Page ID.
|
|
210
210
|
*/
|
|
211
211
|
getPageIdFromUrl,
|
|
212
212
|
getPageIdFromJourneyUrl,
|
package/lib/Validation.js
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* Certain attributes will be persisted:
|
|
10
10
|
* language
|
|
11
11
|
*
|
|
12
|
-
* @param {
|
|
13
|
-
* @
|
|
12
|
+
* @param {object} req HTTP request on which to end the session
|
|
13
|
+
* @returns {Promise} Promise that is resolved once session is fully ended
|
|
14
14
|
*/
|
|
15
15
|
module.exports = function endSession(req = {}) {
|
|
16
16
|
return new Promise((resolve, reject) => {
|
|
@@ -8,9 +8,9 @@ const mwSessionTimeout = require('../../middleware/session/timeout.js');
|
|
|
8
8
|
/**
|
|
9
9
|
* Validate pages and generate a PageDirectory from them.
|
|
10
10
|
*
|
|
11
|
-
* @param {object} pages Page definitions, indexed by page id (url slug)
|
|
12
|
-
* @throws {TypeError}
|
|
13
|
-
* @returns {PageDirectory} Pages
|
|
11
|
+
* @param {object} pages Page definitions, indexed by page id (url slug).
|
|
12
|
+
* @throws {TypeError} For invalid pages type.
|
|
13
|
+
* @returns {PageDirectory} Pages.
|
|
14
14
|
*/
|
|
15
15
|
function buildPageDirectory(pages = {}) {
|
|
16
16
|
if (Object.prototype.toString.call(pages) !== '[object Object]') {
|
|
@@ -22,9 +22,9 @@ function buildPageDirectory(pages = {}) {
|
|
|
22
22
|
/**
|
|
23
23
|
* Validate journey plan.
|
|
24
24
|
*
|
|
25
|
-
* @param {Plan} plan User journey plan
|
|
26
|
-
* @throws {TypeError}
|
|
27
|
-
* @throws {Error}
|
|
25
|
+
* @param {Plan} plan User journey plan.
|
|
26
|
+
* @throws {TypeError} For invalid argument type.
|
|
27
|
+
* @throws {Error} For invalid arguments.
|
|
28
28
|
* @returns {void}
|
|
29
29
|
*/
|
|
30
30
|
function validatePlan(plan = []) {
|
|
@@ -44,9 +44,9 @@ function validatePlan(plan = []) {
|
|
|
44
44
|
* function once all custom routes and configuration has been put in place -
|
|
45
45
|
* it should be the last call made just before starting the HTTP server.
|
|
46
46
|
*
|
|
47
|
-
* @param {object} pages Page definitions, indexed by page id (url slug)
|
|
48
|
-
* @param {Plan} plan Journey plan definition
|
|
49
|
-
* @
|
|
47
|
+
* @param {object} pages Page definitions, indexed by page id (url slug).
|
|
48
|
+
* @param {Plan} plan Journey plan definition.
|
|
49
|
+
* @returns {void}
|
|
50
50
|
*/
|
|
51
51
|
|
|
52
52
|
module.exports = (app, router, config) => (pages, plan) => {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param {object} value Address object to mung
|
|
5
5
|
* @param {string} prop file property name
|
|
6
|
-
* @
|
|
6
|
+
* @returns {string} munged property
|
|
7
7
|
*/
|
|
8
8
|
function transferAndTrim(value, prop) {
|
|
9
9
|
if (typeof value === 'object' && prop in value && typeof value[prop] === 'string') {
|
|
@@ -13,7 +13,7 @@ function transferAndTrim(value, prop) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* Reformats a postcode into the standard form, as long as this results in a valid postcode
|
|
16
|
+
* Reformats a postcode into the standard form, as long as this results in a valid postcode.
|
|
17
17
|
*
|
|
18
18
|
* It removes all the spaces from the postcode, converts it to uppercase and then
|
|
19
19
|
* puts a single space back in to separate the last three characters.
|
|
@@ -29,7 +29,7 @@ function transferAndTrim(value, prop) {
|
|
|
29
29
|
* text, but instead are asked to correct their original
|
|
30
30
|
*
|
|
31
31
|
* @param {object} value Address object to test
|
|
32
|
-
* @
|
|
32
|
+
* @returns {object} GatherModifiered version of the Address object
|
|
33
33
|
*/
|
|
34
34
|
function reformatPostcodeIfValid(value) {
|
|
35
35
|
// convert to upper case
|
|
@@ -57,8 +57,8 @@ function reformatPostcodeIfValid(value) {
|
|
|
57
57
|
*
|
|
58
58
|
* Trims white space from the address items and reformats the post code.
|
|
59
59
|
*
|
|
60
|
-
* @param {object} value Address object to test
|
|
61
|
-
* @
|
|
60
|
+
* @param {object} value Address object to test.
|
|
61
|
+
* @returns {object} GatherModifiered version of the Address object.
|
|
62
62
|
*/
|
|
63
63
|
function trimPostalAddressObject(value) {
|
|
64
64
|
// copy only the expected address properties
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* It removes leading and tailing white space from the value
|
|
2
|
+
* TrimWhitespace is the most basic and useful munger.
|
|
3
|
+
* It removes leading and tailing white space from the value.
|
|
4
4
|
*
|
|
5
5
|
*
|
|
6
|
-
* @param {
|
|
7
|
-
* @
|
|
6
|
+
* @param {any} value Value to munge
|
|
7
|
+
* @returns {string} munged value
|
|
8
8
|
*/
|
|
9
9
|
function trimWhitespace(value) {
|
|
10
10
|
if (typeof value.fieldValue === 'string') {
|
|
@@ -6,21 +6,24 @@ const { validateMountUrl, validateWaypoint } = require('./validate.js');
|
|
|
6
6
|
* Create a URL that can be used to go and edit data at a particular waypoint.
|
|
7
7
|
*
|
|
8
8
|
* If no waypoint or mountUrl is defined, then just the query part of the URL
|
|
9
|
-
* will be generated (without the `?` delimiter), e.g. `&edit
|
|
9
|
+
* will be generated (without the `?` delimiter), e.g. `&edit`.
|
|
10
10
|
*
|
|
11
11
|
* Parameters:
|
|
12
12
|
* string waypoint = Waypoint to edit (including origin waypoint if applicable)
|
|
13
13
|
* string origin = The URL to which the user is returned after editing
|
|
14
|
-
* string mountUrl = The mount URL prefix
|
|
14
|
+
* string mountUrl = The mount URL prefix.
|
|
15
15
|
*
|
|
16
16
|
* Examples:
|
|
17
17
|
* makeEditLink({ waypoint: 'the-waypoint' })
|
|
18
|
-
* Generates: /the-waypoint?edit
|
|
18
|
+
* Generates: /the-waypoint?edit.
|
|
19
19
|
*
|
|
20
20
|
* makeEditLink({ waypoint: 'my-origin/the-waypoint', origin: '/some-url' })
|
|
21
21
|
* Generates: /my-origin/the-waypoint?edit&editorigin=%2Fsome-url
|
|
22
22
|
*
|
|
23
23
|
* @param {object} args See parameters above
|
|
24
|
+
* @param {string} args.waypoint Waypoint ID
|
|
25
|
+
* @param {string} args.origin Original URL to send user back to after editing
|
|
26
|
+
* @param {string} args.mountUrl Mount URL
|
|
24
27
|
* @returns {string} URL
|
|
25
28
|
*/
|
|
26
29
|
module.exports = ({ waypoint = '', origin = null, mountUrl = '/' }) => {
|
package/lib/utils/sanitise.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* an-origin/a-waypoint/with-forward-slash
|
|
8
8
|
*
|
|
9
9
|
* @param {string} waypoint Waypoint, including optional Plan origin
|
|
10
|
-
* @
|
|
10
|
+
* @returns {string} Waypoint
|
|
11
11
|
*/
|
|
12
12
|
function sanitiseWaypoint(waypoint = '') {
|
|
13
13
|
if (typeof waypoint !== 'string') {
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
* function, but the data against which it is tested is expected to be an array
|
|
4
4
|
* of objects that match the structure of the `obj` defined here.
|
|
5
5
|
*
|
|
6
|
-
* @param {object} obj Object of fields that will be tested
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {
|
|
9
|
-
* @
|
|
6
|
+
* @param {object} obj Object of fields that will be tested.
|
|
7
|
+
* @param {Array} validators Validation rules that must be satisfied.
|
|
8
|
+
* @param {Function | null} condition Condition to meet before validators are run.
|
|
9
|
+
* @returns {object} Validation object suitable for processing.
|
|
10
|
+
* @throws {TypeError} When arguments are invalid.
|
|
10
11
|
*/
|
|
11
12
|
module.exports = (obj = {}, validators = [], condition) => {
|
|
12
13
|
if (Object.prototype.toString.call(obj) !== '[object Object]') {
|