@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
|
@@ -8,13 +8,15 @@ const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"))
|
|
|
8
8
|
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
9
9
|
const utils_js_1 = require("../utils.js");
|
|
10
10
|
/**
|
|
11
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
11
12
|
* @access private
|
|
12
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
13
13
|
*/
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {object} RangeConfigOptions
|
|
16
|
-
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max
|
|
17
|
-
*
|
|
16
|
+
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max
|
|
17
|
+
* failure
|
|
18
|
+
* @property {ErrorMessageConfig} errorMsgMin Error message to use on min
|
|
19
|
+
* failure
|
|
18
20
|
* @property {number} max Maximum integer value
|
|
19
21
|
* @property {number} min Minimum integer value
|
|
20
22
|
*/
|
|
@@ -29,15 +31,15 @@ const utils_js_1 = require("../utils.js");
|
|
|
29
31
|
class Range extends ValidatorFactory_js_1.default {
|
|
30
32
|
constructor() {
|
|
31
33
|
super(...arguments);
|
|
32
|
-
this.name =
|
|
34
|
+
this.name = "range";
|
|
33
35
|
}
|
|
34
36
|
validate(inputValue, dataContext = {}) {
|
|
35
37
|
const { errorMsgMax = {
|
|
36
|
-
inline:
|
|
37
|
-
summary:
|
|
38
|
+
inline: "validation:rule.range.max.inline",
|
|
39
|
+
summary: "validation:rule.range.max.summary",
|
|
38
40
|
}, errorMsgMin = {
|
|
39
|
-
inline:
|
|
40
|
-
summary:
|
|
41
|
+
inline: "validation:rule.range.min.inline",
|
|
42
|
+
summary: "validation:rule.range.min.summary",
|
|
41
43
|
}, min = Number.MIN_VALUE, max = Number.MAX_VALUE, } = this.config;
|
|
42
44
|
let errorMsg;
|
|
43
45
|
let valid = true;
|
|
@@ -55,7 +57,7 @@ class Range extends ValidatorFactory_js_1.default {
|
|
|
55
57
|
var _a;
|
|
56
58
|
// treat an empty string as undefined
|
|
57
59
|
// when user submits empty form, it stores an empty string
|
|
58
|
-
if (value !==
|
|
60
|
+
if (value !== "" && value !== undefined) {
|
|
59
61
|
// add to custom validator docs to ensure not to return a falsy value as
|
|
60
62
|
// it doesn't show on screen
|
|
61
63
|
return (_a = (0, utils_js_1.coerceInputToInteger)(value)) === null || _a === void 0 ? void 0 : _a.toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.js","sourceRoot":"","sources":["../../../src/lib/validators/range.js"],"names":[],"mappings":";AAAA,2CAA2C;;;;;AAE3C,iFAAsD;AACtD,+EAAoD;AACpD,0CAAmD;AAEnD;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"range.js","sourceRoot":"","sources":["../../../src/lib/validators/range.js"],"names":[],"mappings":";A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AC;IACnB,CAAC;CACF;AA3CD,wBA2CC"}
|
|
@@ -1,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} RegexConfigOptions
|
|
@@ -21,7 +21,7 @@ export default class Regex extends ValidatorFactory {
|
|
|
21
21
|
validate(value?: string, dataContext?: {}): ValidationError[];
|
|
22
22
|
sanitise(value: any): string | undefined;
|
|
23
23
|
}
|
|
24
|
-
export type ErrorMessageConfig = import(
|
|
24
|
+
export type ErrorMessageConfig = import("../../casa").ErrorMessageConfig;
|
|
25
25
|
export type RegexConfigOptions = {
|
|
26
26
|
/**
|
|
27
27
|
* Error message config
|
|
@@ -36,5 +36,5 @@ export type RegexConfigOptions = {
|
|
|
36
36
|
*/
|
|
37
37
|
invert: boolean;
|
|
38
38
|
};
|
|
39
|
-
import ValidatorFactory from
|
|
40
|
-
import ValidationError from
|
|
39
|
+
import ValidatorFactory from "../ValidatorFactory.js";
|
|
40
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -8,8 +8,8 @@ const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"))
|
|
|
8
8
|
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
9
9
|
const utils_js_1 = require("../utils.js");
|
|
10
10
|
/**
|
|
11
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
11
12
|
* @access private
|
|
12
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
13
13
|
*/
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {object} RegexConfigOptions
|
|
@@ -28,15 +28,15 @@ const utils_js_1 = require("../utils.js");
|
|
|
28
28
|
class Regex extends ValidatorFactory_js_1.default {
|
|
29
29
|
constructor() {
|
|
30
30
|
super(...arguments);
|
|
31
|
-
this.name =
|
|
31
|
+
this.name = "regex";
|
|
32
32
|
}
|
|
33
|
-
validate(value =
|
|
33
|
+
validate(value = "", dataContext = {}) {
|
|
34
34
|
const invert = this.config.invert || false;
|
|
35
35
|
const match = value.match(this.config.pattern || /.*/);
|
|
36
36
|
const valid = invert ? !match : match;
|
|
37
37
|
const errorMsg = this.config.errorMsg || {
|
|
38
|
-
inline:
|
|
39
|
-
summary:
|
|
38
|
+
inline: "validation:rule.regex.inline",
|
|
39
|
+
summary: "validation:rule.regex.summary",
|
|
40
40
|
};
|
|
41
41
|
return valid ? [] : [ValidationError_js_1.default.make({ errorMsg, dataContext })];
|
|
42
42
|
}
|
|
@@ -1,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} RequiredConfigOptions
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
/**
|
|
10
10
|
* Test if value is present.
|
|
11
11
|
*
|
|
12
|
-
* Value is required. The following values will fail this rule:
|
|
13
|
-
*
|
|
12
|
+
* Value is required. The following values will fail this rule: (all values that
|
|
13
|
+
* satisfy `isEmpty()`) plus '\s'
|
|
14
14
|
*
|
|
15
15
|
* See {@link RequiredConfigOptions} for `make()` options.
|
|
16
16
|
*
|
|
@@ -24,12 +24,12 @@ export default class Required extends ValidatorFactory {
|
|
|
24
24
|
[k: string]: string | undefined;
|
|
25
25
|
} | undefined;
|
|
26
26
|
}
|
|
27
|
-
export type ErrorMessageConfig = import(
|
|
27
|
+
export type ErrorMessageConfig = import("../../casa").ErrorMessageConfig;
|
|
28
28
|
export type RequiredConfigOptions = {
|
|
29
29
|
/**
|
|
30
30
|
* Error message config
|
|
31
31
|
*/
|
|
32
32
|
errorMsg: ErrorMessageConfig;
|
|
33
33
|
};
|
|
34
|
-
import ValidatorFactory from
|
|
35
|
-
import ValidationError from
|
|
34
|
+
import ValidatorFactory from "../ValidatorFactory.js";
|
|
35
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -10,8 +10,8 @@ const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"))
|
|
|
10
10
|
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
11
11
|
const { isPlainObject } = lodash_1.default; // CommonJS
|
|
12
12
|
/**
|
|
13
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
13
14
|
* @access private
|
|
14
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
15
15
|
*/
|
|
16
16
|
/**
|
|
17
17
|
* @typedef {object} RequiredConfigOptions
|
|
@@ -20,8 +20,8 @@ const { isPlainObject } = lodash_1.default; // CommonJS
|
|
|
20
20
|
/**
|
|
21
21
|
* Test if value is present.
|
|
22
22
|
*
|
|
23
|
-
* Value is required. The following values will fail this rule:
|
|
24
|
-
*
|
|
23
|
+
* Value is required. The following values will fail this rule: (all values that
|
|
24
|
+
* satisfy `isEmpty()`) plus '\s'
|
|
25
25
|
*
|
|
26
26
|
* See {@link RequiredConfigOptions} for `make()` options.
|
|
27
27
|
*
|
|
@@ -31,24 +31,22 @@ const { isPlainObject } = lodash_1.default; // CommonJS
|
|
|
31
31
|
class Required extends ValidatorFactory_js_1.default {
|
|
32
32
|
constructor() {
|
|
33
33
|
super(...arguments);
|
|
34
|
-
this.name =
|
|
34
|
+
this.name = "required";
|
|
35
35
|
}
|
|
36
36
|
validate(value, dataContext = {}) {
|
|
37
37
|
const { errorMsg = {
|
|
38
|
-
inline:
|
|
39
|
-
summary:
|
|
38
|
+
inline: "validation:rule.required.inline",
|
|
39
|
+
summary: "validation:rule.required.summary",
|
|
40
40
|
}, } = this.config;
|
|
41
41
|
if (!(0, utils_js_1.isEmpty)(value)) {
|
|
42
42
|
return [];
|
|
43
43
|
}
|
|
44
|
-
return [
|
|
45
|
-
ValidationError_js_1.default.make({ errorMsg, dataContext }),
|
|
46
|
-
];
|
|
44
|
+
return [ValidationError_js_1.default.make({ errorMsg, dataContext })];
|
|
47
45
|
}
|
|
48
46
|
sanitise(value) {
|
|
49
47
|
const coerce = (val) => {
|
|
50
48
|
const s = (0, utils_js_1.stringifyInput)(val, undefined);
|
|
51
|
-
return s === undefined ? undefined : s.replace(/^\s+$/,
|
|
49
|
+
return s === undefined ? undefined : s.replace(/^\s+$/, "");
|
|
52
50
|
};
|
|
53
51
|
if ((0, utils_js_1.isStringable)(value)) {
|
|
54
52
|
return coerce(value);
|
|
@@ -61,7 +59,7 @@ class Required extends ValidatorFactory_js_1.default {
|
|
|
61
59
|
// Coerce all elements to Strings.
|
|
62
60
|
// This only supports a one dimensional object, with stringable elements.
|
|
63
61
|
if (isPlainObject(value)) {
|
|
64
|
-
return Object.fromEntries(Object.entries(value).map(([k, v]) =>
|
|
62
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, coerce(v)]));
|
|
65
63
|
}
|
|
66
64
|
return undefined;
|
|
67
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"required.js","sourceRoot":"","sources":["../../../src/lib/validators/required.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C,oDAA4B;AAC5B,0CAAoE;AACpE,iFAAsD;AACtD,+EAAoD;AAEpD,MAAM,EAAE,aAAa,EAAE,GAAG,gBAAM,CAAC,CAAC,WAAW;AAE7C;;;GAGG;AAEH;;;GAGG;AAEH;;;;;;;;;;GAUG;AACH,MAAqB,QAAS,SAAQ,6BAAgB;IAAtD;;QACE,SAAI,GAAG,UAAU,CAAC;IA2CpB,CAAC;IAzCC,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,EAAE;QAC9B,MAAM,EACJ,QAAQ,GAAG;YACT,MAAM,EAAE,iCAAiC;YACzC,OAA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AAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QAED,kCAAkC;QAClC,qEAAqE;QACrE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;QAED,kCAAkC;QAClC,yEAAyE;QACzE,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CACtD,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA5CD,2BA4CC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
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} StrlenConfigOptions
|
|
7
|
-
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max length
|
|
8
|
-
*
|
|
7
|
+
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max length
|
|
8
|
+
* failure
|
|
9
|
+
* @property {ErrorMessageConfig} errorMsgMin Error message to use on min length
|
|
10
|
+
* failure
|
|
9
11
|
* @property {number} max Maximum string length allowed
|
|
10
12
|
* @property {number} min Minimum string length required
|
|
11
13
|
*/
|
|
@@ -22,14 +24,16 @@ export default class Strlen extends ValidatorFactory {
|
|
|
22
24
|
validate(inputValue?: string, dataContext?: {}): ValidationError[];
|
|
23
25
|
sanitise(value: any): string | undefined;
|
|
24
26
|
}
|
|
25
|
-
export type ErrorMessageConfig = import(
|
|
27
|
+
export type ErrorMessageConfig = import("../../casa").ErrorMessageConfig;
|
|
26
28
|
export type StrlenConfigOptions = {
|
|
27
29
|
/**
|
|
28
|
-
* Error message to use on max length
|
|
30
|
+
* Error message to use on max length
|
|
31
|
+
* failure
|
|
29
32
|
*/
|
|
30
33
|
errorMsgMax: ErrorMessageConfig;
|
|
31
34
|
/**
|
|
32
|
-
* Error message to use on min length
|
|
35
|
+
* Error message to use on min length
|
|
36
|
+
* failure
|
|
33
37
|
*/
|
|
34
38
|
errorMsgMin: ErrorMessageConfig;
|
|
35
39
|
/**
|
|
@@ -41,5 +45,5 @@ export type StrlenConfigOptions = {
|
|
|
41
45
|
*/
|
|
42
46
|
min: number;
|
|
43
47
|
};
|
|
44
|
-
import ValidatorFactory from
|
|
45
|
-
import ValidationError from
|
|
48
|
+
import ValidatorFactory from "../ValidatorFactory.js";
|
|
49
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -8,13 +8,15 @@ const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"))
|
|
|
8
8
|
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
9
9
|
const utils_js_1 = require("../utils.js");
|
|
10
10
|
/**
|
|
11
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
11
12
|
* @access private
|
|
12
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
13
13
|
*/
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {object} StrlenConfigOptions
|
|
16
|
-
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max length
|
|
17
|
-
*
|
|
16
|
+
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max length
|
|
17
|
+
* failure
|
|
18
|
+
* @property {ErrorMessageConfig} errorMsgMin Error message to use on min length
|
|
19
|
+
* failure
|
|
18
20
|
* @property {number} max Maximum string length allowed
|
|
19
21
|
* @property {number} min Minimum string length required
|
|
20
22
|
*/
|
|
@@ -29,23 +31,23 @@ const utils_js_1 = require("../utils.js");
|
|
|
29
31
|
class Strlen extends ValidatorFactory_js_1.default {
|
|
30
32
|
constructor() {
|
|
31
33
|
super(...arguments);
|
|
32
|
-
this.name =
|
|
34
|
+
this.name = "strlen";
|
|
33
35
|
}
|
|
34
|
-
validate(inputValue =
|
|
36
|
+
validate(inputValue = "", dataContext = {}) {
|
|
35
37
|
const { errorMsgMax = {
|
|
36
|
-
inline:
|
|
37
|
-
summary:
|
|
38
|
+
inline: "validation:rule.strlen.max.inline",
|
|
39
|
+
summary: "validation:rule.strlen.max.summary",
|
|
38
40
|
}, errorMsgMin = {
|
|
39
|
-
inline:
|
|
40
|
-
summary:
|
|
41
|
+
inline: "validation:rule.strlen.min.inline",
|
|
42
|
+
summary: "validation:rule.strlen.min.summary",
|
|
41
43
|
}, min, max, } = this.config;
|
|
42
44
|
let errorMsg;
|
|
43
45
|
let valid = true;
|
|
44
|
-
if (typeof max !==
|
|
46
|
+
if (typeof max !== "undefined" && inputValue.length > max) {
|
|
45
47
|
valid = false;
|
|
46
48
|
errorMsg = errorMsgMax;
|
|
47
49
|
}
|
|
48
|
-
if (typeof min !==
|
|
50
|
+
if (typeof min !== "undefined" && inputValue.length < min) {
|
|
49
51
|
valid = false;
|
|
50
52
|
errorMsg = errorMsgMin;
|
|
51
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strlen.js","sourceRoot":"","sources":["../../../src/lib/validators/strlen.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C,iFAAsD;AACtD,+EAAoD;AACpD,0CAA6C;AAE7C;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"strlen.js","sourceRoot":"","sources":["../../../src/lib/validators/strlen.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C,iFAAsD;AACtD,+EAAoD;AACpD,0CAA6C;AAE7C;;;GAGG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,MAAqB,MAAO,S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Config
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {object} WordcountConfigOptions
|
|
7
|
-
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max length
|
|
8
|
-
*
|
|
7
|
+
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max length
|
|
8
|
+
* failure
|
|
9
|
+
* @property {ErrorMessageConfig} errorMsgMin Error message to use on min length
|
|
10
|
+
* failure
|
|
9
11
|
* @property {number} max Maximum string length allowed
|
|
10
12
|
* @property {number} min Minimum string length required
|
|
11
13
|
*/
|
|
@@ -23,14 +25,16 @@ export default class WordCount extends ValidatorFactory {
|
|
|
23
25
|
validate(inputValue?: string, dataContext?: {}): ValidationError[];
|
|
24
26
|
sanitise(value: any): string | undefined;
|
|
25
27
|
}
|
|
26
|
-
export type ErrorMessageConfig = import(
|
|
28
|
+
export type ErrorMessageConfig = import("../../casa").ErrorMessageConfig;
|
|
27
29
|
export type WordcountConfigOptions = {
|
|
28
30
|
/**
|
|
29
|
-
* Error message to use on max length
|
|
31
|
+
* Error message to use on max length
|
|
32
|
+
* failure
|
|
30
33
|
*/
|
|
31
34
|
errorMsgMax: ErrorMessageConfig;
|
|
32
35
|
/**
|
|
33
|
-
* Error message to use on min length
|
|
36
|
+
* Error message to use on min length
|
|
37
|
+
* failure
|
|
34
38
|
*/
|
|
35
39
|
errorMsgMin: ErrorMessageConfig;
|
|
36
40
|
/**
|
|
@@ -42,5 +46,5 @@ export type WordcountConfigOptions = {
|
|
|
42
46
|
*/
|
|
43
47
|
min: number;
|
|
44
48
|
};
|
|
45
|
-
import ValidatorFactory from
|
|
46
|
-
import ValidationError from
|
|
49
|
+
import ValidatorFactory from "../ValidatorFactory.js";
|
|
50
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -8,13 +8,15 @@ const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"))
|
|
|
8
8
|
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
9
9
|
const utils_js_1 = require("../utils.js");
|
|
10
10
|
/**
|
|
11
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
11
12
|
* @access private
|
|
12
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
13
13
|
*/
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {object} WordcountConfigOptions
|
|
16
|
-
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max length
|
|
17
|
-
*
|
|
16
|
+
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max length
|
|
17
|
+
* failure
|
|
18
|
+
* @property {ErrorMessageConfig} errorMsgMin Error message to use on min length
|
|
19
|
+
* failure
|
|
18
20
|
* @property {number} max Maximum string length allowed
|
|
19
21
|
* @property {number} min Minimum string length required
|
|
20
22
|
*/
|
|
@@ -29,26 +31,28 @@ const utils_js_1 = require("../utils.js");
|
|
|
29
31
|
class WordCount extends ValidatorFactory_js_1.default {
|
|
30
32
|
constructor() {
|
|
31
33
|
super(...arguments);
|
|
32
|
-
this.name =
|
|
34
|
+
this.name = "wordCount";
|
|
33
35
|
}
|
|
34
36
|
count(input) {
|
|
35
37
|
return (input.match(/\S+/g) || []).length;
|
|
36
38
|
}
|
|
37
|
-
validate(inputValue =
|
|
39
|
+
validate(inputValue = "", dataContext = {}) {
|
|
38
40
|
const { errorMsgMax = {
|
|
39
|
-
inline:
|
|
40
|
-
summary:
|
|
41
|
+
inline: "validation:rule.wordCount.max.inline",
|
|
42
|
+
summary: "validation:rule.wordCount.max.summary",
|
|
41
43
|
}, errorMsgMin = {
|
|
42
|
-
inline:
|
|
43
|
-
summary:
|
|
44
|
+
inline: "validation:rule.wordCount.min.inline",
|
|
45
|
+
summary: "validation:rule.wordCount.min.summary",
|
|
44
46
|
}, min, max, } = this.config;
|
|
45
47
|
let errorMsg;
|
|
46
48
|
let valid = true;
|
|
47
|
-
if (typeof max !==
|
|
49
|
+
if (typeof max !== "undefined" &&
|
|
50
|
+
(inputValue.match(/\S+/g) || []).length > max) {
|
|
48
51
|
valid = false;
|
|
49
52
|
errorMsg = errorMsgMax;
|
|
50
53
|
}
|
|
51
|
-
if (typeof min !==
|
|
54
|
+
if (typeof min !== "undefined" &&
|
|
55
|
+
(inputValue.match(/\S+/g) || []).length < min) {
|
|
52
56
|
valid = false;
|
|
53
57
|
errorMsg = errorMsgMin;
|
|
54
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wordCount.js","sourceRoot":"","sources":["../../../src/lib/validators/wordCount.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C,iFAAsD;AACtD,+EAAoD;AACpD,0CAA6C;AAE7C;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"wordCount.js","sourceRoot":"","sources":["../../../src/lib/validators/wordCount.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C,iFAAsD;AACtD,+EAAoD;AACpD,0CAA6C;AAE7C;;;GAGG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,MAAqB,SAAU,SAAQ,6BAAgB;IAAvD;;QACE,SAAI,GAAG,WAAW,CAAC;IAgDrB,CAAC;IA9CC,KAAK,CAAC,KAAK;QACT,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IAC5C,CAAC;IAED,QAAQ,CAAC,UAAU,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE;QACxC,MAAM,EACJ,WAAW,GAAG;YACZ,MAAM,EAAE,sCAAsC;YAC9C,OAAO,EAAE,uCAAuC;SACjD,EACD,WAAW,GAAG;YACZ,MAAM,EAAE,sCAAsC;YAC9C,OAAO,EAAE,uCAAuC;SACjD,EACD,GAAG,EACH,GAAG,GACJ,GAAG,IAAI,CAAC,MAAM,CAAC;QAEhB,IAAI,QAAQ,CAAC;QACb,IAAI,KAAK,GAAG,IAAI,CAAC;QAEjB,IACE,OAAO,GAAG,KAAK,WAAW;YAC1B,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,GAAG,EAC7C,CAAC;YACD,KAAK,GAAG,KAAK,CAAC;YACd,QAAQ,GAAG,WAAW,CAAC;QACzB,CAAC;QAED,IACE,OAAO,GAAG,KAAK,WAAW;YAC1B,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,GAAG,EAC7C,CAAC;YACD,KAAK,GAAG,KAAK,CAAC;YACd,QAAQ,GAAG,WAAW,CAAC;QACzB,CAAC;QAED,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,4BAAe,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,QAAQ,CAAC,KAAK;QACZ,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,IAAA,yBAAc,EAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAjDD,4BAiDC"}
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generate a URL pointing at a particular waypoint.
|
|
3
3
|
*
|
|
4
|
-
* @example
|
|
5
|
-
* // generates: /path/details?edit&editorigin=%2Fsomewhere%2Felse
|
|
6
|
-
* waypointUrl({
|
|
7
|
-
* mountUrl: '/path/',
|
|
8
|
-
* waypoint: 'details',
|
|
9
|
-
* edit: true,
|
|
10
|
-
* editOrigin: '/somewhere/else'
|
|
11
|
-
* })
|
|
12
4
|
* @memberof module:@dwp/govuk-casa
|
|
5
|
+
* @example
|
|
6
|
+
* // generates: /path/details?edit&editorigin=%2Fsomewhere%2Felse
|
|
7
|
+
* waypointUrl({
|
|
8
|
+
* mountUrl: "/path/",
|
|
9
|
+
* waypoint: "details",
|
|
10
|
+
* edit: true,
|
|
11
|
+
* editOrigin: "/somewhere/else",
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
13
14
|
* @param {object} obj Options
|
|
14
|
-
* @param {string} [obj.waypoint=""] Waypoint
|
|
15
|
-
* @param {string} [obj.mountUrl="/"] Mount URL
|
|
15
|
+
* @param {string} [obj.waypoint=""] Waypoint. Default is `""`
|
|
16
|
+
* @param {string} [obj.mountUrl="/"] Mount URL. Default is `"/"`
|
|
16
17
|
* @param {JourneyContext} [obj.journeyContext] JourneyContext
|
|
17
|
-
* @param {boolean} [obj.edit=false] Turn edit mode on or off
|
|
18
|
+
* @param {boolean} [obj.edit=false] Turn edit mode on or off. Default is
|
|
19
|
+
* `false`
|
|
18
20
|
* @param {string} [obj.editOrigin] Edit mode original URL
|
|
19
21
|
* @param {boolean} [obj.skipTo] Skip to this waypoint from the current one
|
|
20
|
-
* @param {string} [obj.routeName=next] Plan route name; next | prev
|
|
22
|
+
* @param {string} [obj.routeName=next] Plan route name; next | prev. Default is
|
|
23
|
+
* `next`
|
|
21
24
|
* @returns {string} URL
|
|
22
25
|
*/
|
|
23
26
|
export default function waypointUrl({ waypoint, mountUrl, journeyContext, edit, editOrigin, skipTo, routeName, }?: {
|
|
@@ -29,4 +32,4 @@ export default function waypointUrl({ waypoint, mountUrl, journeyContext, edit,
|
|
|
29
32
|
skipTo?: boolean | undefined;
|
|
30
33
|
routeName?: string | undefined;
|
|
31
34
|
}): string;
|
|
32
|
-
export type JourneyContext = import(
|
|
35
|
+
export type JourneyContext = import("./index").JourneyContext;
|
package/dist/lib/waypoint-url.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
+
* @typedef {import("./index").JourneyContext} JourneyContext
|
|
3
4
|
* @access private
|
|
4
|
-
* @typedef {import('./index').JourneyContext} JourneyContext
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
/** @access private */
|
|
@@ -9,22 +9,22 @@ const reUrlProtocolExtract = /^url:\/\/(.+)$/i;
|
|
|
9
9
|
/**
|
|
10
10
|
* Sanitise a waypoint string.
|
|
11
11
|
*
|
|
12
|
-
* @access private
|
|
13
12
|
* @param {string} w Waypoint
|
|
14
13
|
* @returns {string} Sanitised waypoint
|
|
14
|
+
* @access private
|
|
15
15
|
*/
|
|
16
|
-
const sanitiseWaypoint = (w) => w.replace(/[^/a-z0-9_-]/
|
|
16
|
+
const sanitiseWaypoint = (w) => w.replace(/[^/a-z0-9_-]/gi, "").replace(/\/+/g, "/");
|
|
17
17
|
/**
|
|
18
|
-
* Sanitise a waypoint string, with allowed URL parameters:
|
|
19
|
-
*
|
|
18
|
+
* Sanitise a waypoint string, with allowed URL parameters: contextid =
|
|
19
|
+
* JourneyContext ID
|
|
20
20
|
*
|
|
21
|
-
* @access private
|
|
22
21
|
* @param {string} w Waypoint and potential URL parameters
|
|
23
22
|
* @returns {string} Sanitised waypoint
|
|
23
|
+
* @access private
|
|
24
24
|
*/
|
|
25
25
|
const sanitiseWaypointWithAllowedParams = (w) => {
|
|
26
26
|
// Extract URL params
|
|
27
|
-
const parts = w.split(
|
|
27
|
+
const parts = w.split("?");
|
|
28
28
|
if (parts.length !== 2) {
|
|
29
29
|
return sanitiseWaypoint(w);
|
|
30
30
|
}
|
|
@@ -32,51 +32,54 @@ const sanitiseWaypointWithAllowedParams = (w) => {
|
|
|
32
32
|
const urlSearchParams = new URLSearchParams(rawParams);
|
|
33
33
|
// Strip all but those parameters allowed
|
|
34
34
|
const validatedUrlSearchParams = new URLSearchParams();
|
|
35
|
-
for (const pk of [
|
|
35
|
+
for (const pk of ["contextid"]) {
|
|
36
36
|
if (urlSearchParams.has(pk)) {
|
|
37
37
|
validatedUrlSearchParams.set(pk, urlSearchParams.get(pk));
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
return `${sanitiseWaypoint(waypoint)}?${validatedUrlSearchParams.toString()}`.replace(/\?$/,
|
|
40
|
+
return `${sanitiseWaypoint(waypoint)}?${validatedUrlSearchParams.toString()}`.replace(/\?$/, "");
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
43
43
|
* Generate a URL pointing at a particular waypoint.
|
|
44
44
|
*
|
|
45
|
-
* @example
|
|
46
|
-
* // generates: /path/details?edit&editorigin=%2Fsomewhere%2Felse
|
|
47
|
-
* waypointUrl({
|
|
48
|
-
* mountUrl: '/path/',
|
|
49
|
-
* waypoint: 'details',
|
|
50
|
-
* edit: true,
|
|
51
|
-
* editOrigin: '/somewhere/else'
|
|
52
|
-
* })
|
|
53
45
|
* @memberof module:@dwp/govuk-casa
|
|
46
|
+
* @example
|
|
47
|
+
* // generates: /path/details?edit&editorigin=%2Fsomewhere%2Felse
|
|
48
|
+
* waypointUrl({
|
|
49
|
+
* mountUrl: "/path/",
|
|
50
|
+
* waypoint: "details",
|
|
51
|
+
* edit: true,
|
|
52
|
+
* editOrigin: "/somewhere/else",
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
54
55
|
* @param {object} obj Options
|
|
55
|
-
* @param {string} [obj.waypoint=""] Waypoint
|
|
56
|
-
* @param {string} [obj.mountUrl="/"] Mount URL
|
|
56
|
+
* @param {string} [obj.waypoint=""] Waypoint. Default is `""`
|
|
57
|
+
* @param {string} [obj.mountUrl="/"] Mount URL. Default is `"/"`
|
|
57
58
|
* @param {JourneyContext} [obj.journeyContext] JourneyContext
|
|
58
|
-
* @param {boolean} [obj.edit=false] Turn edit mode on or off
|
|
59
|
+
* @param {boolean} [obj.edit=false] Turn edit mode on or off. Default is
|
|
60
|
+
* `false`
|
|
59
61
|
* @param {string} [obj.editOrigin] Edit mode original URL
|
|
60
62
|
* @param {boolean} [obj.skipTo] Skip to this waypoint from the current one
|
|
61
|
-
* @param {string} [obj.routeName=next] Plan route name; next | prev
|
|
63
|
+
* @param {string} [obj.routeName=next] Plan route name; next | prev. Default is
|
|
64
|
+
* `next`
|
|
62
65
|
* @returns {string} URL
|
|
63
66
|
*/
|
|
64
|
-
function waypointUrl({ waypoint =
|
|
65
|
-
const url = new URL(
|
|
67
|
+
function waypointUrl({ waypoint = "", mountUrl = "/", journeyContext, edit = false, editOrigin, skipTo, routeName = "next", } = Object.create(null)) {
|
|
68
|
+
const url = new URL("https://placeholder.test");
|
|
66
69
|
// Handle url:// protocol
|
|
67
70
|
// - This will generate a link to the root handler "_" for the given mount path
|
|
68
|
-
if (String(waypoint).substr(0, 7) ===
|
|
71
|
+
if (String(waypoint).substr(0, 7) === "url:///") {
|
|
69
72
|
const m = waypoint.match(reUrlProtocolExtract);
|
|
70
|
-
const u = new URL(sanitiseWaypointWithAllowedParams(m[1]),
|
|
73
|
+
const u = new URL(sanitiseWaypointWithAllowedParams(m[1]), "https://placeholder.test/");
|
|
71
74
|
url.pathname = `${sanitiseWaypoint(u.pathname)}/_/`;
|
|
72
|
-
url.searchParams.set(
|
|
73
|
-
url.searchParams.set(
|
|
75
|
+
url.searchParams.set("refmount", `url://${mountUrl}`);
|
|
76
|
+
url.searchParams.set("route", routeName);
|
|
74
77
|
for (const [uk, uv] of u.searchParams.entries()) {
|
|
75
78
|
url.searchParams.append(uk, uv);
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
else {
|
|
79
|
-
const u = new URL(sanitiseWaypointWithAllowedParams(`${mountUrl}${waypoint}`),
|
|
82
|
+
const u = new URL(sanitiseWaypointWithAllowedParams(`${mountUrl}${waypoint}`), "https://placeholder.test/");
|
|
80
83
|
url.pathname = u.pathname;
|
|
81
84
|
url.search = u.search;
|
|
82
85
|
}
|
|
@@ -84,22 +87,22 @@ function waypointUrl({ waypoint = '', mountUrl = '/', journeyContext, edit = fal
|
|
|
84
87
|
// To avoid messy URLs with duplicated content, this parameter will _not_ be
|
|
85
88
|
// added if the context ID already appears in the url path, i.e. to avoid
|
|
86
89
|
// `/path/1234-abcd/waypoint?contextid=1234-abcd` scenarios
|
|
87
|
-
if (journeyContext
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
url.searchParams.set(
|
|
90
|
+
if (journeyContext &&
|
|
91
|
+
!journeyContext.isDefault() &&
|
|
92
|
+
journeyContext.identity.id &&
|
|
93
|
+
!mountUrl.includes(`/${journeyContext.identity.id}/`)) {
|
|
94
|
+
url.searchParams.set("contextid", journeyContext.identity.id);
|
|
92
95
|
}
|
|
93
96
|
// Attach edit mode flag
|
|
94
97
|
if (edit === true) {
|
|
95
|
-
url.searchParams.set(
|
|
98
|
+
url.searchParams.set("edit", "true");
|
|
96
99
|
}
|
|
97
100
|
if (edit && editOrigin) {
|
|
98
|
-
url.searchParams.set(
|
|
101
|
+
url.searchParams.set("editorigin", sanitiseWaypointWithAllowedParams(editOrigin));
|
|
99
102
|
}
|
|
100
103
|
// Skipto
|
|
101
104
|
if (skipTo) {
|
|
102
|
-
url.searchParams.set(
|
|
105
|
+
url.searchParams.set("skipto", sanitiseWaypointWithAllowedParams(skipTo));
|
|
103
106
|
}
|
|
104
107
|
return `${sanitiseWaypoint(url.pathname)}${url.search}`;
|
|
105
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waypoint-url.js","sourceRoot":"","sources":["../../src/lib/waypoint-url.js"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,sBAAsB;AACtB,MAAM,oBAAoB,GAAG,iBAAiB,
|
|
1
|
+
{"version":3,"file":"waypoint-url.js","sourceRoot":"","sources":["../../src/lib/waypoint-url.js"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,sBAAsB;AACtB,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,gBAAgB,GAAG,CAAC,CAAC,EAAE,EAAE,CAC7B,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,iCAAiC,GAAG,CAAC,CAAC,EAAE,EAAE;IAC9C,qBAAqB;IACrB,MAAM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