@dwp/govuk-casa 8.2.1 → 8.2.4
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 +9 -0
- package/README.md +1 -0
- package/dist/casa.d.ts +203 -1
- package/dist/casa.js +131 -2
- package/dist/lib/CasaTemplateLoader.d.ts +4 -0
- package/dist/lib/CasaTemplateLoader.js +5 -0
- package/dist/lib/JourneyContext.d.ts +85 -13
- package/dist/lib/JourneyContext.js +78 -5
- package/dist/lib/Plan.d.ts +122 -49
- package/dist/lib/Plan.js +161 -37
- package/dist/lib/ValidationError.d.ts +38 -48
- package/dist/lib/ValidationError.js +30 -42
- package/dist/lib/ValidatorFactory.d.ts +42 -52
- package/dist/lib/ValidatorFactory.js +37 -48
- package/dist/lib/configuration-ingestor.d.ts +18 -4
- package/dist/lib/configuration-ingestor.js +23 -10
- package/dist/lib/configure.d.ts +4 -0
- package/dist/lib/configure.js +20 -52
- package/dist/lib/end-session.d.ts +3 -2
- package/dist/lib/end-session.js +2 -1
- package/dist/lib/field.d.ts +97 -35
- package/dist/lib/field.js +90 -41
- package/dist/lib/nunjucks-filters.d.ts +12 -2
- package/dist/lib/nunjucks-filters.js +11 -1
- package/dist/lib/nunjucks.d.ts +1 -0
- package/dist/lib/nunjucks.js +1 -0
- package/dist/lib/utils.d.ts +46 -14
- package/dist/lib/utils.js +43 -26
- package/dist/lib/validators/dateObject.d.ts +75 -1
- package/dist/lib/validators/dateObject.js +29 -18
- package/dist/lib/validators/email.d.ts +28 -1
- package/dist/lib/validators/email.js +20 -9
- package/dist/lib/validators/inArray.d.ts +34 -1
- package/dist/lib/validators/inArray.js +21 -0
- package/dist/lib/validators/index.js +3 -0
- package/dist/lib/validators/nino.d.ts +34 -1
- package/dist/lib/validators/nino.js +17 -7
- package/dist/lib/validators/postalAddressObject.d.ts +68 -1
- package/dist/lib/validators/postalAddressObject.js +27 -15
- package/dist/lib/validators/regex.d.ts +35 -1
- package/dist/lib/validators/regex.js +17 -7
- package/dist/lib/validators/required.d.ts +28 -1
- package/dist/lib/validators/required.js +19 -6
- package/dist/lib/validators/strlen.d.ts +40 -1
- package/dist/lib/validators/strlen.js +18 -8
- package/dist/lib/validators/wordCount.d.ts +40 -1
- package/dist/lib/validators/wordCount.js +18 -8
- package/dist/lib/waypoint-url.d.ts +1 -0
- package/dist/lib/waypoint-url.js +10 -0
- package/dist/middleware/data.js +21 -5
- package/dist/middleware/gather-fields.js +1 -0
- package/dist/middleware/pre.js +1 -0
- package/dist/middleware/steer-journey.js +2 -1
- package/dist/middleware/strip-proxy-path.d.ts +4 -0
- package/dist/middleware/strip-proxy-path.js +56 -0
- package/dist/middleware/validate-fields.js +3 -0
- package/dist/routes/ancillary.d.ts +16 -5
- package/dist/routes/ancillary.js +7 -3
- package/dist/routes/journey.d.ts +30 -6
- package/dist/routes/journey.js +27 -0
- package/dist/routes/static.d.ts +1 -0
- package/dist/routes/static.js +2 -1
- package/package.json +16 -11
- package/views/casa/components/character-count/README.md +1 -1
- package/views/casa/components/input/README.md +1 -1
- package/views/casa/components/radios/README.md +2 -2
- package/views/casa/components/textarea/README.md +1 -1
|
@@ -1,6 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @access private
|
|
3
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} RegexConfigOptions
|
|
7
|
+
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
8
|
+
* @property {RegExp} pattern Regular expression to test against
|
|
9
|
+
* @property {boolean} invert Return error on positive regex match
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Match a string pattern.
|
|
13
|
+
*
|
|
14
|
+
* See {@link RegexConfigOptions} for `make()` options.
|
|
15
|
+
*
|
|
16
|
+
* @memberof Validators
|
|
17
|
+
* @augments ValidatorFactory
|
|
18
|
+
*/
|
|
1
19
|
export default class Regex extends ValidatorFactory {
|
|
2
20
|
name: string;
|
|
3
|
-
validate(value?: string, dataContext?: {}):
|
|
21
|
+
validate(value?: string, dataContext?: {}): ValidationError[];
|
|
4
22
|
sanitise(value: any): string | undefined;
|
|
5
23
|
}
|
|
24
|
+
export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
|
|
25
|
+
export type RegexConfigOptions = {
|
|
26
|
+
/**
|
|
27
|
+
* Error message config
|
|
28
|
+
*/
|
|
29
|
+
errorMsg: ErrorMessageConfig;
|
|
30
|
+
/**
|
|
31
|
+
* Regular expression to test against
|
|
32
|
+
*/
|
|
33
|
+
pattern: RegExp;
|
|
34
|
+
/**
|
|
35
|
+
* Return error on positive regex match
|
|
36
|
+
*/
|
|
37
|
+
invert: boolean;
|
|
38
|
+
};
|
|
6
39
|
import ValidatorFactory from "../ValidatorFactory.js";
|
|
40
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -4,17 +4,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
/* eslint-disable class-methods-use-this */
|
|
7
|
+
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
8
|
+
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
9
|
+
const utils_js_1 = require("../utils.js");
|
|
10
|
+
/**
|
|
11
|
+
* @access private
|
|
12
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {object} RegexConfigOptions
|
|
16
|
+
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
17
|
+
* @property {RegExp} pattern Regular expression to test against
|
|
18
|
+
* @property {boolean} invert Return error on positive regex match
|
|
19
|
+
*/
|
|
7
20
|
/**
|
|
8
21
|
* Match a string pattern.
|
|
9
22
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
23
|
+
* See {@link RegexConfigOptions} for `make()` options.
|
|
24
|
+
*
|
|
25
|
+
* @memberof Validators
|
|
26
|
+
* @augments ValidatorFactory
|
|
14
27
|
*/
|
|
15
|
-
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
16
|
-
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
17
|
-
const utils_js_1 = require("../utils.js");
|
|
18
28
|
class Regex extends ValidatorFactory_js_1.default {
|
|
19
29
|
constructor() {
|
|
20
30
|
super(...arguments);
|
|
@@ -1,8 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @access private
|
|
3
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} RequiredConfigOptions
|
|
7
|
+
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Test if value is present.
|
|
11
|
+
*
|
|
12
|
+
* Value is required. The following values will fail this rule:
|
|
13
|
+
* (all values that satisify `isEmpty()`) plus '\s'
|
|
14
|
+
*
|
|
15
|
+
* See {@link RequiredConfigOptions} for `make()` options.
|
|
16
|
+
*
|
|
17
|
+
* @memberof Validators
|
|
18
|
+
* @augments ValidatorFactory
|
|
19
|
+
*/
|
|
1
20
|
export default class Required extends ValidatorFactory {
|
|
2
21
|
name: string;
|
|
3
|
-
validate(value: any, dataContext?: {}):
|
|
22
|
+
validate(value: any, dataContext?: {}): ValidationError[];
|
|
4
23
|
sanitise(value: any): string | (string | undefined)[] | {
|
|
5
24
|
[k: string]: string | undefined;
|
|
6
25
|
} | undefined;
|
|
7
26
|
}
|
|
27
|
+
export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
|
|
28
|
+
export type RequiredConfigOptions = {
|
|
29
|
+
/**
|
|
30
|
+
* Error message config
|
|
31
|
+
*/
|
|
32
|
+
errorMsg: ErrorMessageConfig;
|
|
33
|
+
};
|
|
8
34
|
import ValidatorFactory from "../ValidatorFactory.js";
|
|
35
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -4,17 +4,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
/* eslint-disable class-methods-use-this */
|
|
7
|
-
/**
|
|
8
|
-
* Test is value is present.
|
|
9
|
-
*
|
|
10
|
-
* Value is required. The following values will fail this rule:
|
|
11
|
-
* (all values that satisify `isEmpty()`) plus '\s'
|
|
12
|
-
*/
|
|
13
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
14
8
|
const utils_js_1 = require("../utils.js");
|
|
15
9
|
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
16
10
|
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
17
11
|
const { isPlainObject } = lodash_1.default; // CommonJS
|
|
12
|
+
/**
|
|
13
|
+
* @access private
|
|
14
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {object} RequiredConfigOptions
|
|
18
|
+
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Test if value is present.
|
|
22
|
+
*
|
|
23
|
+
* Value is required. The following values will fail this rule:
|
|
24
|
+
* (all values that satisify `isEmpty()`) plus '\s'
|
|
25
|
+
*
|
|
26
|
+
* See {@link RequiredConfigOptions} for `make()` options.
|
|
27
|
+
*
|
|
28
|
+
* @memberof Validators
|
|
29
|
+
* @augments ValidatorFactory
|
|
30
|
+
*/
|
|
18
31
|
class Required extends ValidatorFactory_js_1.default {
|
|
19
32
|
constructor() {
|
|
20
33
|
super(...arguments);
|
|
@@ -1,6 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @access private
|
|
3
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} StrlenConfigOptions
|
|
7
|
+
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max length failure
|
|
8
|
+
* @property {ErrorMessageConfig} errorMsgMin Error message to use on min length failure
|
|
9
|
+
* @property {number} max Maximum string length allowed
|
|
10
|
+
* @property {number} min Minimum string length required
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Test the length of a string.
|
|
14
|
+
*
|
|
15
|
+
* See {@link StrlenConfigOptions} for `make()` options.
|
|
16
|
+
*
|
|
17
|
+
* @memberof Validators
|
|
18
|
+
* @augments ValidatorFactory
|
|
19
|
+
*/
|
|
1
20
|
export default class Strlen extends ValidatorFactory {
|
|
2
21
|
name: string;
|
|
3
|
-
validate(inputValue?: string, dataContext?: {}):
|
|
22
|
+
validate(inputValue?: string, dataContext?: {}): ValidationError[];
|
|
4
23
|
sanitise(value: any): string | undefined;
|
|
5
24
|
}
|
|
25
|
+
export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
|
|
26
|
+
export type StrlenConfigOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* Error message to use on max length failure
|
|
29
|
+
*/
|
|
30
|
+
errorMsgMax: ErrorMessageConfig;
|
|
31
|
+
/**
|
|
32
|
+
* Error message to use on min length failure
|
|
33
|
+
*/
|
|
34
|
+
errorMsgMin: ErrorMessageConfig;
|
|
35
|
+
/**
|
|
36
|
+
* Maximum string length allowed
|
|
37
|
+
*/
|
|
38
|
+
max: number;
|
|
39
|
+
/**
|
|
40
|
+
* Minimum string length required
|
|
41
|
+
*/
|
|
42
|
+
min: number;
|
|
43
|
+
};
|
|
6
44
|
import ValidatorFactory from "../ValidatorFactory.js";
|
|
45
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -4,18 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
/* eslint-disable class-methods-use-this */
|
|
7
|
+
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
8
|
+
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
9
|
+
const utils_js_1 = require("../utils.js");
|
|
10
|
+
/**
|
|
11
|
+
* @access private
|
|
12
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {object} StrlenConfigOptions
|
|
16
|
+
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max length failure
|
|
17
|
+
* @property {ErrorMessageConfig} errorMsgMin Error message to use on min length failure
|
|
18
|
+
* @property {number} max Maximum string length allowed
|
|
19
|
+
* @property {number} min Minimum string length required
|
|
20
|
+
*/
|
|
7
21
|
/**
|
|
8
22
|
* Test the length of a string.
|
|
9
23
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* int min = Minimum string length required
|
|
24
|
+
* See {@link StrlenConfigOptions} for `make()` options.
|
|
25
|
+
*
|
|
26
|
+
* @memberof Validators
|
|
27
|
+
* @augments ValidatorFactory
|
|
15
28
|
*/
|
|
16
|
-
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
17
|
-
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
18
|
-
const utils_js_1 = require("../utils.js");
|
|
19
29
|
class Strlen extends ValidatorFactory_js_1.default {
|
|
20
30
|
constructor() {
|
|
21
31
|
super(...arguments);
|
|
@@ -1,7 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @access private
|
|
3
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} WordcountConfigOptions
|
|
7
|
+
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max length failure
|
|
8
|
+
* @property {ErrorMessageConfig} errorMsgMin Error message to use on min length failure
|
|
9
|
+
* @property {number} max Maximum string length allowed
|
|
10
|
+
* @property {number} min Minimum string length required
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Test the number of words in a string.
|
|
14
|
+
*
|
|
15
|
+
* See {@link WordcountConfigOptions} for `make()` options.
|
|
16
|
+
*
|
|
17
|
+
* @memberof Validators
|
|
18
|
+
* @augments ValidatorFactory
|
|
19
|
+
*/
|
|
1
20
|
export default class WordCount extends ValidatorFactory {
|
|
2
21
|
name: string;
|
|
3
22
|
count(input: any): any;
|
|
4
|
-
validate(inputValue?: string, dataContext?: {}):
|
|
23
|
+
validate(inputValue?: string, dataContext?: {}): ValidationError[];
|
|
5
24
|
sanitise(value: any): string | undefined;
|
|
6
25
|
}
|
|
26
|
+
export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
|
|
27
|
+
export type WordcountConfigOptions = {
|
|
28
|
+
/**
|
|
29
|
+
* Error message to use on max length failure
|
|
30
|
+
*/
|
|
31
|
+
errorMsgMax: ErrorMessageConfig;
|
|
32
|
+
/**
|
|
33
|
+
* Error message to use on min length failure
|
|
34
|
+
*/
|
|
35
|
+
errorMsgMin: ErrorMessageConfig;
|
|
36
|
+
/**
|
|
37
|
+
* Maximum string length allowed
|
|
38
|
+
*/
|
|
39
|
+
max: number;
|
|
40
|
+
/**
|
|
41
|
+
* Minimum string length required
|
|
42
|
+
*/
|
|
43
|
+
min: number;
|
|
44
|
+
};
|
|
7
45
|
import ValidatorFactory from "../ValidatorFactory.js";
|
|
46
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -4,18 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
/* eslint-disable class-methods-use-this */
|
|
7
|
+
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
8
|
+
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
9
|
+
const utils_js_1 = require("../utils.js");
|
|
10
|
+
/**
|
|
11
|
+
* @access private
|
|
12
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {object} WordcountConfigOptions
|
|
16
|
+
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max length failure
|
|
17
|
+
* @property {ErrorMessageConfig} errorMsgMin Error message to use on min length failure
|
|
18
|
+
* @property {number} max Maximum string length allowed
|
|
19
|
+
* @property {number} min Minimum string length required
|
|
20
|
+
*/
|
|
7
21
|
/**
|
|
8
22
|
* Test the number of words in a string.
|
|
9
23
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* int min = Minimum word count required
|
|
24
|
+
* See {@link WordcountConfigOptions} for `make()` options.
|
|
25
|
+
*
|
|
26
|
+
* @memberof Validators
|
|
27
|
+
* @augments ValidatorFactory
|
|
15
28
|
*/
|
|
16
|
-
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
17
|
-
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
18
|
-
const utils_js_1 = require("../utils.js");
|
|
19
29
|
class WordCount extends ValidatorFactory_js_1.default {
|
|
20
30
|
constructor() {
|
|
21
31
|
super(...arguments);
|
package/dist/lib/waypoint-url.js
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
+
* @access private
|
|
3
4
|
* @typedef {import('./index').JourneyContext} JourneyContext
|
|
4
5
|
*/
|
|
5
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
/** @access private */
|
|
6
8
|
const reUrlProtocolExtract = /^url:\/\/(.+)$/i;
|
|
9
|
+
/**
|
|
10
|
+
* Sanitise a waypoint string.
|
|
11
|
+
*
|
|
12
|
+
* @access private
|
|
13
|
+
* @param {string} w Waypoint
|
|
14
|
+
* @returns {string} Sanitised waypoint
|
|
15
|
+
*/
|
|
7
16
|
const sanitiseWaypoint = (w) => w.replace(/[^/a-z0-9_-]/ig, '').replace(/\/+/g, '/');
|
|
8
17
|
/**
|
|
9
18
|
* Generate a URL pointing at a particular waypoint.
|
|
10
19
|
*
|
|
20
|
+
* @memberof module:@dwp/govuk-casa
|
|
11
21
|
* @param {object} obj Options
|
|
12
22
|
* @param {string} obj.waypoint Waypoint
|
|
13
23
|
* @param {string} obj.mountUrl Mount URL
|
package/dist/middleware/data.js
CHANGED
|
@@ -35,12 +35,28 @@ function dataMiddleware({ plan, events, }) {
|
|
|
35
35
|
// Grab chosen language from session
|
|
36
36
|
req.casa.journeyContext.nav.language = req.session.language;
|
|
37
37
|
/* ------------------------------------------------- Template variables */
|
|
38
|
-
//
|
|
38
|
+
// Capture mount URL that will be used in generating all browser URLs
|
|
39
39
|
const mountUrl = (0, utils_js_1.validateUrlPath)(`${req.baseUrl}/`.replace(/\/+/g, '/'));
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
|
|
40
|
+
// If this CASA app is mounted on a parameterised route, then all of its
|
|
41
|
+
// static assets (served by `staticRouter`) will, by default, be served
|
|
42
|
+
// from that dynamic path, for example:
|
|
43
|
+
// markup: <link href="{{ mountUrl }}css/static.css" />
|
|
44
|
+
// resolved URL: /mount/<some-id-here>/css/static.css
|
|
45
|
+
// baseUrl: /mount/<some-id>
|
|
46
|
+
//
|
|
47
|
+
// From a performance point of view, this is very inefficient as we can't
|
|
48
|
+
// take advantage of any intermediate caches. So we instead provide am
|
|
49
|
+
// alternative URL path in the `staticMountUrl` property that excludes the
|
|
50
|
+
// parameterised element, eg:
|
|
51
|
+
// markup: <link href="{{ staticMountUrl }}css/static.css" />
|
|
52
|
+
// resolved URL: /mount/css/static.css
|
|
53
|
+
// baseUrl: /mount
|
|
54
|
+
//
|
|
55
|
+
// As the staticRouter is mounted on both the CASA app, and its internal
|
|
56
|
+
// Router, the `baseUrl` is different in each case, so we cannot rely
|
|
57
|
+
// on it to be consistent. Hence the need for this property, which will
|
|
58
|
+
// always be the non-parameterised version of the baseUrl.
|
|
59
|
+
const staticMountUrl = (0, utils_js_1.validateUrlPath)(`${req.unparameterisedBaseUrl}/`.replace(/\/+/g, '/'));
|
|
44
60
|
// CASA and userland templates
|
|
45
61
|
res.locals.casa = {
|
|
46
62
|
mountUrl,
|
|
@@ -9,6 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
const JourneyContext_js_1 = __importDefault(require("../lib/JourneyContext.js"));
|
|
11
11
|
/**
|
|
12
|
+
* @access private
|
|
12
13
|
* @typedef {import('../lib/field').PageField} PageField
|
|
13
14
|
*/
|
|
14
15
|
/**
|
package/dist/middleware/pre.js
CHANGED
|
@@ -9,6 +9,7 @@ const waypoint_url_js_1 = __importDefault(require("../lib/waypoint-url.js"));
|
|
|
9
9
|
const logger_js_1 = __importDefault(require("../lib/logger.js"));
|
|
10
10
|
const log = (0, logger_js_1.default)('middleware:steer-journey');
|
|
11
11
|
/**
|
|
12
|
+
* @access private
|
|
12
13
|
* @typedef {import('../lib/Plan')} Plan
|
|
13
14
|
*/
|
|
14
15
|
/**
|
|
@@ -40,7 +41,7 @@ exports.default = ({ waypoint, plan, }) => [
|
|
|
40
41
|
// Edit mode
|
|
41
42
|
// Cannot be in edit mode if we're already on the `editorigin` URL
|
|
42
43
|
if (req.casa.editMode) {
|
|
43
|
-
const { pathname: currentPathname } = new URL(req.originalUrl, '
|
|
44
|
+
const { pathname: currentPathname } = new URL(req.originalUrl, 'https://placeholder.test/');
|
|
44
45
|
if (req.casa.editOrigin === currentPathname) {
|
|
45
46
|
log.debug(`Disabling edit mode as we are on the edit origin (${req.casa.editOrigin})`);
|
|
46
47
|
req.casa.editMode = false;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Strip any "proxy path" prefix present on the request URL
|
|
3
|
+
//
|
|
4
|
+
// The default "mountUrl" will be match whatever path that the CASA app
|
|
5
|
+
// instance will be mounted onto. So if you mount on `/a/b/c` then all
|
|
6
|
+
// URLs generated for the browser will be prefixed with `/a/b/c`.
|
|
7
|
+
//
|
|
8
|
+
// Defining a `mountUrl` will change that behaviour into a "proxy mode".
|
|
9
|
+
// This mode assumes you have a forwarding proxy that will alter
|
|
10
|
+
// the incoming request paths from `mountUrl` to the original path you
|
|
11
|
+
// have mounted this CASA app instance onto.
|
|
12
|
+
//
|
|
13
|
+
// For example, if you mount the app on `/a/b/c/x`, but want the browser
|
|
14
|
+
// URLs to just use the `/x` prefix, then pass a `mountUrl` of `/x`.
|
|
15
|
+
//
|
|
16
|
+
// See docs in `docs/guides/setup-behind-a-proxy.md`
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
const logger_js_1 = __importDefault(require("../lib/logger.js"));
|
|
22
|
+
const log = (0, logger_js_1.default)('casa:middleware:strip-proxy-path');
|
|
23
|
+
exports.default = ({ mountUrl = '/', }) => [
|
|
24
|
+
(req, res, next) => {
|
|
25
|
+
// TODO:
|
|
26
|
+
// We _may_ have to start tracking the various prefix in order to differentiate
|
|
27
|
+
// between a proxy prefix, and a parent app's path.
|
|
28
|
+
var _a;
|
|
29
|
+
// Assume everything before `mountUrl` is the proxy path prefix and remove it
|
|
30
|
+
req.originalBaseUrl = (_a = req.originalBaseUrl) !== null && _a !== void 0 ? _a : req.baseUrl;
|
|
31
|
+
req.baseUrl = mountUrl.replace(/\/$/, '');
|
|
32
|
+
// If the app has been mounted directly on the specific `mountUrl`, then
|
|
33
|
+
// there's nothing we need to do and can let this request pass-through.
|
|
34
|
+
if (req.baseUrl === req.originalBaseUrl) {
|
|
35
|
+
next();
|
|
36
|
+
}
|
|
37
|
+
else if (req.__CASA_BASE_URL_REWRITTEN__) {
|
|
38
|
+
delete req.__CASA_BASE_URL_REWRITTEN__;
|
|
39
|
+
next();
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// Strip the proxy path prefix from the original URL so that
|
|
43
|
+
// subsequnt middleware sees the URL path as though proxy wasn't there.
|
|
44
|
+
// req.url will already have the proxy prefix and mountUrl removed.
|
|
45
|
+
/* eslint-disable security/detect-non-literal-regexp */
|
|
46
|
+
log.trace(`req.originalUrl before proxy stripping: ${req.originalUrl}`);
|
|
47
|
+
req.originalUrl = req.originalUrl.replace(new RegExp(`^/.+?${mountUrl}`), mountUrl);
|
|
48
|
+
log.trace(`req.originalUrl after proxy stripping: ${req.originalUrl}`);
|
|
49
|
+
/* eslint-enable security/detect-non-literal-regexp */
|
|
50
|
+
// Issuing this call will re-run this same middleware, so we use this
|
|
51
|
+
// `__CASA_BASE_URL_REWRITTEN__` flag to prevent recursion.
|
|
52
|
+
req.__CASA_BASE_URL_REWRITTEN__ = true;
|
|
53
|
+
req.app.handle(req, res, next);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
];
|
|
@@ -20,6 +20,8 @@ exports.default = ({ waypoint, fields = [], plan, }) => [
|
|
|
20
20
|
(req, res, next) => {
|
|
21
21
|
var _a, _b;
|
|
22
22
|
const mountUrl = `${req.baseUrl}/`;
|
|
23
|
+
// Run validators for every field to build up a compelte list of errors
|
|
24
|
+
// currently associated with this waypoint.
|
|
23
25
|
let errors = [];
|
|
24
26
|
for (let i = 0, l = fields.length; i < l; i++) {
|
|
25
27
|
/* eslint-disable security/detect-object-injection */
|
|
@@ -27,6 +29,7 @@ exports.default = ({ waypoint, fields = [], plan, }) => [
|
|
|
27
29
|
const field = fields[i];
|
|
28
30
|
const fieldName = field.name;
|
|
29
31
|
const fieldValue = (_b = (_a = req.casa.journeyContext.data) === null || _a === void 0 ? void 0 : _a[waypoint]) === null || _b === void 0 ? void 0 : _b[fieldName];
|
|
32
|
+
// (type = ValidateContext)
|
|
30
33
|
const context = {
|
|
31
34
|
fieldName,
|
|
32
35
|
fieldValue,
|
|
@@ -1,11 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} AncillaryRouterOptions Options to configure static router
|
|
3
|
+
* @property {number} sessionTtl Session timeout (seconds)
|
|
4
|
+
*/
|
|
1
5
|
/**
|
|
2
6
|
* Create an instance of the ancillary router.
|
|
3
7
|
*
|
|
4
|
-
* @
|
|
5
|
-
* @param {
|
|
6
|
-
* @returns {MutableRouter}
|
|
8
|
+
* @access private
|
|
9
|
+
* @param {AncillaryRouterOptions} options Options
|
|
10
|
+
* @returns {MutableRouter} ExpressJS Router instance
|
|
11
|
+
*/
|
|
12
|
+
export default function ancillaryRouter({ sessionTtl, }: AncillaryRouterOptions): MutableRouter;
|
|
13
|
+
/**
|
|
14
|
+
* Options to configure static router
|
|
7
15
|
*/
|
|
8
|
-
export
|
|
16
|
+
export type AncillaryRouterOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* Session timeout (seconds)
|
|
19
|
+
*/
|
|
9
20
|
sessionTtl: number;
|
|
10
|
-
}
|
|
21
|
+
};
|
|
11
22
|
import MutableRouter from "../lib/MutableRouter.js";
|
package/dist/routes/ancillary.js
CHANGED
|
@@ -4,12 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const MutableRouter_js_1 = __importDefault(require("../lib/MutableRouter.js"));
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {object} AncillaryRouterOptions Options to configure static router
|
|
9
|
+
* @property {number} sessionTtl Session timeout (seconds)
|
|
10
|
+
*/
|
|
7
11
|
/**
|
|
8
12
|
* Create an instance of the ancillary router.
|
|
9
13
|
*
|
|
10
|
-
* @
|
|
11
|
-
* @param {
|
|
12
|
-
* @returns {MutableRouter}
|
|
14
|
+
* @access private
|
|
15
|
+
* @param {AncillaryRouterOptions} options Options
|
|
16
|
+
* @returns {MutableRouter} ExpressJS Router instance
|
|
13
17
|
*/
|
|
14
18
|
function ancillaryRouter({ sessionTtl, }) {
|
|
15
19
|
// Router
|
package/dist/routes/journey.d.ts
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Create an instance of the router for all waypoints visited during a Journey
|
|
3
|
+
* through the Plan.
|
|
4
|
+
*
|
|
5
|
+
* @access private
|
|
6
|
+
* @param {JourneyRouterOptions} opts Options
|
|
7
|
+
* @returns {MutableRouter} Router
|
|
8
|
+
*/
|
|
9
|
+
export default function journeyRouter({ globalHooks, pages, plan, csrfMiddleware, }: JourneyRouterOptions): MutableRouter;
|
|
10
|
+
/**
|
|
11
|
+
* Options to configure static router
|
|
12
|
+
*/
|
|
13
|
+
export type JourneyRouterOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* Global hooks
|
|
16
|
+
*/
|
|
17
|
+
globalHooks: GlobalHook[];
|
|
18
|
+
/**
|
|
19
|
+
* Page definitions
|
|
20
|
+
*/
|
|
21
|
+
pages: Page[];
|
|
22
|
+
/**
|
|
23
|
+
* Plan
|
|
24
|
+
*/
|
|
25
|
+
plan: Plan;
|
|
26
|
+
/**
|
|
27
|
+
* Middleware for providing CSRF controls
|
|
28
|
+
*/
|
|
29
|
+
csrfMiddleware: Function[];
|
|
30
|
+
};
|
|
7
31
|
import MutableRouter from "../lib/MutableRouter.js";
|
package/dist/routes/journey.js
CHANGED
|
@@ -15,6 +15,25 @@ const waypoint_url_js_1 = __importDefault(require("../lib/waypoint-url.js"));
|
|
|
15
15
|
const logger_js_1 = __importDefault(require("../lib/logger.js"));
|
|
16
16
|
const utils_js_1 = require("../lib/utils.js");
|
|
17
17
|
const log = (0, logger_js_1.default)('routes:journey');
|
|
18
|
+
/**
|
|
19
|
+
* @access private
|
|
20
|
+
* @param {import('../casa.js').GlobalHook} GlobalHook
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* @access private
|
|
24
|
+
* @param {import('../casa.js').Page} Page
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* @access private
|
|
28
|
+
* @param {import('../casa.js').Plan} Plan
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {object} JourneyRouterOptions Options to configure static router
|
|
32
|
+
* @property {GlobalHook[]} globalHooks Global hooks
|
|
33
|
+
* @property {Page[]} pages Page definitions
|
|
34
|
+
* @property {Plan} plan Plan
|
|
35
|
+
* @property {Function[]} csrfMiddleware Middleware for providing CSRF controls
|
|
36
|
+
*/
|
|
18
37
|
const renderMiddlewareFactory = (view, contextFactory) => [
|
|
19
38
|
(req, res, next) => {
|
|
20
39
|
res.render(view, Object.assign({
|
|
@@ -29,6 +48,14 @@ const renderMiddlewareFactory = (view, contextFactory) => [
|
|
|
29
48
|
});
|
|
30
49
|
},
|
|
31
50
|
];
|
|
51
|
+
/**
|
|
52
|
+
* Create an instance of the router for all waypoints visited during a Journey
|
|
53
|
+
* through the Plan.
|
|
54
|
+
*
|
|
55
|
+
* @access private
|
|
56
|
+
* @param {JourneyRouterOptions} opts Options
|
|
57
|
+
* @returns {MutableRouter} Router
|
|
58
|
+
*/
|
|
32
59
|
function journeyRouter({ globalHooks, pages, plan, csrfMiddleware, }) {
|
|
33
60
|
// Router
|
|
34
61
|
const router = new MutableRouter_js_1.default();
|