@dwp/govuk-casa 9.0.0 → 9.2.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 +1 -1
- package/dist/assets/css/casa.css.map +1 -1
- package/dist/casa.d.ts +122 -95
- package/dist/casa.js +119 -86
- 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 +58 -40
- package/dist/lib/JourneyContext.js +132 -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 +20 -18
- package/dist/lib/field.js +35 -48
- 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 +11 -10
- 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 -27
- 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 +5 -9
- 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 -19
- package/dist/routes/static.js.map +1 -1
- package/package.json +20 -19
- package/src/casa.js +133 -100
- package/src/lib/CasaTemplateLoader.js +24 -19
- package/src/lib/JourneyContext.js +190 -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 +69 -58
- package/src/lib/index.js +12 -12
- package/src/lib/logger.js +9 -9
- package/src/lib/mount.js +70 -74
- 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 -41
- 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 +8 -15
- 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 -29
- 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/layouts/main.njk +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationError.js","sourceRoot":"","sources":["../../src/lib/ValidationError.js"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,MAAM,EAAE,aAAa,EAAE,GAAG,gBAAM,CAAC,CAAC,WAAW;AAE7C,MAAM,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;AAE7B;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AACH,MAAqB,eAAe;IAClC
|
|
1
|
+
{"version":3,"file":"ValidationError.js","sourceRoot":"","sources":["../../src/lib/ValidationError.js"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,MAAM,EAAE,aAAa,EAAE,GAAG,gBAAM,CAAC,CAAC,WAAW;AAE7C,MAAM,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;AAE7B;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AACH,MAAqB,eAAe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EAAE,OAAO,CAAC,CAAC;QAC3D,CAAC;QAED,iBAAiB;QACjB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACtB,IAAI,WAAW,CAAC;YAChB,IAAI,SAAS,GAAG,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC;YAC1C,IAAI,SAAS,CAAC,cAAc,EAAE,CAAC;gBAC7B,SAAS,IAAI,SAAS,CAAC,cAAc,CAAC;YACxC,CAAC;iBAAM,IAAI,SAAS,CAAC,WAAW,IAAI,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;gBACjE,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC;oBAChD,CAAC,CAAC,SAAS,CAAC,WAAW;oBACvB,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;gBAC5B,SAAS,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;YAC9B,CAAC;YAED,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,SAAS,GAAG,CAAC,SAAS,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC;YAClE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;YAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,EAAE,CAAC;QACvC,CAAC;QAED,qBAAqB;QACrB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,SAAS,CAAC;QAEhD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA7ID,kCA6IC"}
|
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @typedef {import("../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
2
3
|
* @access private
|
|
3
|
-
* @typedef {import('../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
+
* @typedef {import("./index").JourneyContext} JourneyContext
|
|
6
7
|
* @access private
|
|
7
|
-
* @typedef {import('./index').JourneyContext} JourneyContext
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
10
|
+
* @typedef {import("./index").ValidationError} ValidationError
|
|
10
11
|
* @access private
|
|
11
|
-
* @typedef {import('./index').ValidationError} ValidationError
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
|
+
* @typedef {import("../casa").ValidateContext} ValidateContext
|
|
14
15
|
* @access private
|
|
15
|
-
* @typedef {import('../casa').ValidateContext} ValidateContext
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
|
+
* @typedef {import("../casa").Validator} Validator
|
|
18
19
|
* @access private
|
|
19
|
-
* @typedef {import('../casa').Validator} Validator
|
|
20
20
|
*/
|
|
21
21
|
/**
|
|
22
22
|
* @typedef {Object<string, unknown>} ValidatorFactoryOptions
|
|
23
23
|
* @property {ErrorMessageConfig} errorMsg Error message
|
|
24
24
|
*/
|
|
25
25
|
/**
|
|
26
|
-
* @class
|
|
27
26
|
* @memberof module:@dwp/govuk-casa
|
|
27
|
+
* @class
|
|
28
28
|
*/
|
|
29
29
|
export default class ValidatorFactory {
|
|
30
30
|
/**
|
|
31
31
|
* This is a convenience method that will return a consistently object
|
|
32
32
|
* structure containing validation and sanitisation methods.
|
|
33
33
|
*
|
|
34
|
-
* @param {ValidatorFactoryOptions} config Validator config (custom to each
|
|
34
|
+
* @param {ValidatorFactoryOptions} config Validator config (custom to each
|
|
35
|
+
* validator)
|
|
35
36
|
* @returns {Validator} Validator object
|
|
36
37
|
* @throws {TypeError} When configuration is invalid.
|
|
37
38
|
*/
|
|
@@ -39,7 +40,8 @@ export default class ValidatorFactory {
|
|
|
39
40
|
/**
|
|
40
41
|
* NEVER CALL THIS DIRECTLY. USE `make()`.
|
|
41
42
|
*
|
|
42
|
-
* @param {ValidatorFactoryOptions} config Validator config (custom to each
|
|
43
|
+
* @param {ValidatorFactoryOptions} config Validator config (custom to each
|
|
44
|
+
* validator)
|
|
43
45
|
*/
|
|
44
46
|
constructor(config?: ValidatorFactoryOptions);
|
|
45
47
|
config: {
|
|
@@ -62,11 +64,11 @@ export default class ValidatorFactory {
|
|
|
62
64
|
*/
|
|
63
65
|
sanitise(fieldValue: any): any;
|
|
64
66
|
}
|
|
65
|
-
export type ErrorMessageConfig = import(
|
|
66
|
-
export type JourneyContext = import(
|
|
67
|
-
export type ValidationError = import(
|
|
68
|
-
export type ValidateContext = import(
|
|
69
|
-
export type Validator = import(
|
|
67
|
+
export type ErrorMessageConfig = import("../casa").ErrorMessageConfig;
|
|
68
|
+
export type JourneyContext = import("./index").JourneyContext;
|
|
69
|
+
export type ValidationError = import("./index").ValidationError;
|
|
70
|
+
export type ValidateContext = import("../casa").ValidateContext;
|
|
71
|
+
export type Validator = import("../casa").Validator;
|
|
70
72
|
export type ValidatorFactoryOptions = {
|
|
71
73
|
[x: string]: unknown;
|
|
72
74
|
};
|
|
@@ -7,50 +7,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const { isPlainObject } = lodash_1.default; // CommonJS
|
|
9
9
|
/**
|
|
10
|
+
* @typedef {import("../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
10
11
|
* @access private
|
|
11
|
-
* @typedef {import('../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
|
+
* @typedef {import("./index").JourneyContext} JourneyContext
|
|
14
15
|
* @access private
|
|
15
|
-
* @typedef {import('./index').JourneyContext} JourneyContext
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
|
+
* @typedef {import("./index").ValidationError} ValidationError
|
|
18
19
|
* @access private
|
|
19
|
-
* @typedef {import('./index').ValidationError} ValidationError
|
|
20
20
|
*/
|
|
21
21
|
/**
|
|
22
|
+
* @typedef {import("../casa").ValidateContext} ValidateContext
|
|
22
23
|
* @access private
|
|
23
|
-
* @typedef {import('../casa').ValidateContext} ValidateContext
|
|
24
24
|
*/
|
|
25
25
|
/**
|
|
26
|
+
* @typedef {import("../casa").Validator} Validator
|
|
26
27
|
* @access private
|
|
27
|
-
* @typedef {import('../casa').Validator} Validator
|
|
28
28
|
*/
|
|
29
29
|
/**
|
|
30
30
|
* @typedef {Object<string, unknown>} ValidatorFactoryOptions
|
|
31
31
|
* @property {ErrorMessageConfig} errorMsg Error message
|
|
32
32
|
*/
|
|
33
33
|
/**
|
|
34
|
-
* @class
|
|
35
34
|
* @memberof module:@dwp/govuk-casa
|
|
35
|
+
* @class
|
|
36
36
|
*/
|
|
37
37
|
class ValidatorFactory {
|
|
38
38
|
/**
|
|
39
39
|
* This is a convenience method that will return a consistently object
|
|
40
40
|
* structure containing validation and sanitisation methods.
|
|
41
41
|
*
|
|
42
|
-
* @param {ValidatorFactoryOptions} config Validator config (custom to each
|
|
42
|
+
* @param {ValidatorFactoryOptions} config Validator config (custom to each
|
|
43
|
+
* validator)
|
|
43
44
|
* @returns {Validator} Validator object
|
|
44
45
|
* @throws {TypeError} When configuration is invalid.
|
|
45
46
|
*/
|
|
46
47
|
static make(config = {}) {
|
|
47
48
|
if (!isPlainObject(config)) {
|
|
48
|
-
throw new TypeError(
|
|
49
|
+
throw new TypeError("Configuration must be an object");
|
|
49
50
|
}
|
|
50
51
|
const validator = Reflect.construct(this, [config]);
|
|
51
52
|
/* eslint-disable-next-line sonarjs/prefer-object-literal */
|
|
52
53
|
const instance = {};
|
|
53
|
-
instance.name = validator.name ||
|
|
54
|
+
instance.name = validator.name || "unknown";
|
|
54
55
|
instance.config = config;
|
|
55
56
|
instance.validate = validator.validate.bind(instance);
|
|
56
57
|
instance.sanitise = validator.sanitise.bind(instance);
|
|
@@ -60,11 +61,12 @@ class ValidatorFactory {
|
|
|
60
61
|
/**
|
|
61
62
|
* NEVER CALL THIS DIRECTLY. USE `make()`.
|
|
62
63
|
*
|
|
63
|
-
* @param {ValidatorFactoryOptions} config Validator config (custom to each
|
|
64
|
+
* @param {ValidatorFactoryOptions} config Validator config (custom to each
|
|
65
|
+
* validator)
|
|
64
66
|
*/
|
|
65
67
|
constructor(config = {}) {
|
|
66
68
|
if (new.target === ValidatorFactory) {
|
|
67
|
-
throw new TypeError(
|
|
69
|
+
throw new TypeError("Cannot instantiate the abstract class, ValidatorFactory");
|
|
68
70
|
}
|
|
69
71
|
this.config = config;
|
|
70
72
|
}
|
|
@@ -79,7 +81,7 @@ class ValidatorFactory {
|
|
|
79
81
|
* @throws {Error}
|
|
80
82
|
*/
|
|
81
83
|
validate(fieldValue, context) {
|
|
82
|
-
throw new Error(
|
|
84
|
+
throw new Error("validate() method has not been implemented");
|
|
83
85
|
}
|
|
84
86
|
/* eslint-disable-next-line jsdoc/require-returns-check */
|
|
85
87
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidatorFactory.js","sourceRoot":"","sources":["../../src/lib/ValidatorFactory.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C,oDAA4B;AAE5B,MAAM,EAAE,aAAa,EAAE,GAAG,gBAAM,CAAC,CAAC,WAAW;AAE7C;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AACH,MAAqB,gBAAgB;IACnC
|
|
1
|
+
{"version":3,"file":"ValidatorFactory.js","sourceRoot":"","sources":["../../src/lib/ValidatorFactory.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C,oDAA4B;AAE5B,MAAM,EAAE,aAAa,EAAE,GAAG,gBAAM,CAAC,CAAC,WAAW;AAE7C;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AACH,MAAqB,gBAAgB;IACnC;;;;;;;;OAQG;IACH,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,EAAE;QACrB,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,SAAS,CAAC,iCAAiC,CAAC,CAAC;QACzD,CAAC;QAED,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;QAEpD,4DAA4D;QAC5D,MAAM,QAAQ,GAAG,EAAE,CAAC;QACpB,QAAQ,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,IAAI,SAAS,CAAC;QAC5C,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QACzB,QAAQ,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACtD,QAAQ,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEtD,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAExB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACH,YAAY,MAAM,GAAG,EAAE;QACrB,IAAI,GAAG,CAAC,MAAM,KAAK,gBAAgB,EAAE,CAAC;YACpC,MAAM,IAAI,SAAS,CACjB,yDAAyD,CAC1D,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,mCAAmC;IAEnC,0DAA0D;IAC1D;;;;;;;OAOG;IACH,QAAQ,CAAC,UAAU,EAAE,OAAO;QAC1B,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,0DAA0D;IAC1D;;;;;OAKG;IACH,QAAQ,CAAC,UAAU;QACjB,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AArED,mCAqEC"}
|
|
@@ -1,140 +1,137 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Validates and sanitises i18n object.
|
|
3
3
|
*
|
|
4
|
-
* @access private
|
|
5
4
|
* @param {object} i18n Object to validate.
|
|
6
5
|
* @param {Function} cb Callback function that receives the validated value.
|
|
7
|
-
* @throws {TypeError} For invalid object.
|
|
8
6
|
* @returns {object} Sanitised i18n object.
|
|
7
|
+
* @throws {TypeError} For invalid object.
|
|
8
|
+
* @access private
|
|
9
9
|
*/
|
|
10
10
|
export function validateI18nObject(i18n?: object, cb?: Function): object;
|
|
11
11
|
/**
|
|
12
12
|
* Validates and sanitises i18n directory.
|
|
13
13
|
*
|
|
14
|
-
* @access private
|
|
15
14
|
* @param {Array} dirs Array of directories.
|
|
15
|
+
* @returns {Array} Array of directories.
|
|
16
16
|
* @throws {SyntaxError} For invalid directories.
|
|
17
17
|
* @throws {TypeError} For invalid type.
|
|
18
|
-
* @
|
|
18
|
+
* @access private
|
|
19
19
|
*/
|
|
20
20
|
export function validateI18nDirs(dirs?: any[]): any[];
|
|
21
21
|
/**
|
|
22
22
|
* Validates and sanitises i18n locales.
|
|
23
23
|
*
|
|
24
|
-
* @access private
|
|
25
24
|
* @param {Array} locales Array of locales.
|
|
25
|
+
* @returns {Array} Array of locales.
|
|
26
26
|
* @throws {SyntaxError} For invalid locales.
|
|
27
27
|
* @throws {TypeError} For invalid type.
|
|
28
|
-
* @
|
|
28
|
+
* @access private
|
|
29
29
|
*/
|
|
30
30
|
export function validateI18nLocales(locales?: any[]): any[];
|
|
31
31
|
/**
|
|
32
32
|
* Validates and sanitises mount url.
|
|
33
33
|
*
|
|
34
|
-
* @access private
|
|
35
34
|
* @param {string} mountUrl Prefix for all URLs in the browser address bar
|
|
35
|
+
* @returns {string | undefined} Sanitised URL.
|
|
36
36
|
* @throws {SyntaxError} For invalid URL.
|
|
37
|
-
* @
|
|
37
|
+
* @access private
|
|
38
38
|
*/
|
|
39
39
|
export function validateMountUrl(mountUrl: string): string | undefined;
|
|
40
40
|
/**
|
|
41
41
|
* Validates and sanitises sessions object.
|
|
42
42
|
*
|
|
43
|
-
* @access private
|
|
44
43
|
* @param {object} session Object to validate.
|
|
45
44
|
* @param {Function} cb Callback function that receives the validated value.
|
|
46
|
-
* @throws {TypeError} For invalid object.
|
|
47
45
|
* @returns {object} Sanitised sessions object.
|
|
46
|
+
* @throws {TypeError} For invalid object.
|
|
47
|
+
* @access private
|
|
48
48
|
*/
|
|
49
49
|
export function validateSessionObject(session?: object, cb?: Function): object;
|
|
50
50
|
/**
|
|
51
51
|
* Validates and sanitises view directory.
|
|
52
52
|
*
|
|
53
|
-
* @access private
|
|
54
53
|
* @param {Array} dirs Array of directories.
|
|
54
|
+
* @returns {Array} Array of directories.
|
|
55
55
|
* @throws {SyntaxError} For invalid directories.
|
|
56
56
|
* @throws {TypeError} For invalid type.
|
|
57
|
-
* @
|
|
57
|
+
* @access private
|
|
58
58
|
*/
|
|
59
59
|
export function validateViews(dirs?: any[]): any[];
|
|
60
60
|
/**
|
|
61
61
|
* Validates and sanitises sessions secret.
|
|
62
62
|
*
|
|
63
|
-
* @access private
|
|
64
63
|
* @param {string} secret Session secret.
|
|
64
|
+
* @returns {string} Secret.
|
|
65
65
|
* @throws {ReferenceError} For missing value type.
|
|
66
66
|
* @throws {TypeError} For invalid value.
|
|
67
|
-
* @
|
|
67
|
+
* @access private
|
|
68
68
|
*/
|
|
69
69
|
export function validateSessionSecret(secret: string): string;
|
|
70
70
|
/**
|
|
71
71
|
* Validates and sanitises sessions ttl.
|
|
72
72
|
*
|
|
73
|
-
* @access private
|
|
74
73
|
* @param {number} ttl Session ttl (seconds).
|
|
74
|
+
* @returns {number} Ttl.
|
|
75
75
|
* @throws {ReferenceError} For missing value type.
|
|
76
76
|
* @throws {TypeError} For invalid value.
|
|
77
|
-
* @
|
|
77
|
+
* @access private
|
|
78
78
|
*/
|
|
79
79
|
export function validateSessionTtl(ttl?: number): number;
|
|
80
80
|
/**
|
|
81
81
|
* Validates and sanitises sessions name.
|
|
82
82
|
*
|
|
83
|
-
* @
|
|
84
|
-
* @
|
|
83
|
+
* @param {string} [name=casa-session] Session name. Default is `casa-session`
|
|
84
|
+
* @returns {string} Name.
|
|
85
85
|
* @throws {ReferenceError} For missing value type.
|
|
86
86
|
* @throws {TypeError} For invalid value.
|
|
87
|
-
* @
|
|
87
|
+
* @access private
|
|
88
88
|
*/
|
|
89
89
|
export function validateSessionName(name?: string | undefined): string;
|
|
90
90
|
/**
|
|
91
91
|
* Validates and sanitises sessions secure flag.
|
|
92
92
|
*
|
|
93
|
-
* @access private
|
|
94
93
|
* @param {boolean} [secure] Session secure flag.
|
|
94
|
+
* @returns {string} Name.
|
|
95
95
|
* @throws {ReferenceError} For missing value type.
|
|
96
96
|
* @throws {TypeError} For invalid or missing value.
|
|
97
|
-
* @
|
|
97
|
+
* @access private
|
|
98
98
|
*/
|
|
99
99
|
export function validateSessionSecure(secure?: boolean | undefined): string;
|
|
100
100
|
/**
|
|
101
101
|
* Validates and sanitises sessions store.
|
|
102
102
|
*
|
|
103
|
-
* @access private
|
|
104
103
|
* @param {Function} store Session store.
|
|
105
104
|
* @returns {Function} Store.
|
|
105
|
+
* @access private
|
|
106
106
|
*/
|
|
107
107
|
export function validateSessionStore(store: Function): Function;
|
|
108
108
|
/**
|
|
109
109
|
* Validates and sanitises sessions cookie url path.
|
|
110
110
|
*
|
|
111
|
-
* @access private
|
|
112
111
|
* @param {string} cookiePath Session cookie url path.
|
|
113
112
|
* @param {string} defaultPath Default path if none specified.
|
|
114
113
|
* @returns {string} Cookie path.
|
|
114
|
+
* @access private
|
|
115
115
|
*/
|
|
116
116
|
export function validateSessionCookiePath(cookiePath: string, defaultPath?: string): string;
|
|
117
117
|
/**
|
|
118
|
-
* Validates and sanitises sessions cookie "sameSite" flag. One of:
|
|
119
|
-
*
|
|
120
|
-
* false (will not set the flag at all)
|
|
121
|
-
* Strict
|
|
122
|
-
* Lax
|
|
123
|
-
* None
|
|
118
|
+
* Validates and sanitises sessions cookie "sameSite" flag. One of: true
|
|
119
|
+
* (Strict) false (will not set the flag at all) Strict Lax None
|
|
124
120
|
*
|
|
125
|
-
* @access private
|
|
126
121
|
* @param {any} cookieSameSite Session cookie "sameSite" flag
|
|
127
122
|
* @param {any} defaultFlag Default path if none specified
|
|
128
|
-
* @returns {boolean}
|
|
123
|
+
* @returns {boolean} Cookie path
|
|
129
124
|
* @throws {TypeError} When invalid arguments are provided
|
|
125
|
+
* @access private
|
|
130
126
|
*/
|
|
131
127
|
/**
|
|
132
128
|
* Validates errorVisibility.
|
|
133
129
|
*
|
|
134
|
-
* @
|
|
135
|
-
*
|
|
130
|
+
* @param {string} errorVisibility Sets visibility flag for page validation
|
|
131
|
+
* error
|
|
132
|
+
* @returns {symbol | Function} Flag for error visibility.
|
|
136
133
|
* @throws {SyntaxError} For invalid errorVisibility flag.
|
|
137
|
-
* @
|
|
134
|
+
* @access private
|
|
138
135
|
*/
|
|
139
136
|
export function validateErrorVisibility(errorVisibility?: string): symbol | Function;
|
|
140
137
|
export function validateSessionCookieSameSite(cookieSameSite: any, defaultFlag: any): any;
|
|
@@ -148,10 +145,10 @@ export function validateEvents(events: any): any;
|
|
|
148
145
|
/**
|
|
149
146
|
* Validates helmet configuration function.
|
|
150
147
|
*
|
|
151
|
-
* @access private
|
|
152
148
|
* @param {HelmetConfigurator} helmetConfigurator Configuration function
|
|
153
149
|
* @returns {HelmetConfigurator} Validated configuration function
|
|
154
|
-
* @throws {TypeError}
|
|
150
|
+
* @throws {TypeError} When passed a non-function
|
|
151
|
+
* @access private
|
|
155
152
|
*/
|
|
156
153
|
export function validateHelmetConfigurator(helmetConfigurator: HelmetConfigurator): HelmetConfigurator;
|
|
157
154
|
export function validateFormMaxParams(value: any, defaultValue?: number): any;
|
|
@@ -160,11 +157,11 @@ export function validateContextIdGenerator(generator: any): any;
|
|
|
160
157
|
/**
|
|
161
158
|
* Ingest, validate, sanitise and manipulate configuration parameters.
|
|
162
159
|
*
|
|
163
|
-
* @access private
|
|
164
160
|
* @param {ConfigurationOptions} config Config to ingest.
|
|
165
|
-
* @throws {Error|SyntaxError|TypeError} For invalid config values.
|
|
166
161
|
* @returns {object} Immutable config object.
|
|
162
|
+
* @throws {Error | SyntaxError | TypeError} For invalid config values.
|
|
163
|
+
* @access private
|
|
167
164
|
*/
|
|
168
165
|
export default function ingest(config?: ConfigurationOptions): object;
|
|
169
|
-
export type ConfigurationOptions = import(
|
|
170
|
-
export type HelmetConfigurator = import(
|
|
166
|
+
export type ConfigurationOptions = import("../casa").ConfigurationOptions;
|
|
167
|
+
export type HelmetConfigurator = import("../casa").HelmetConfigurator;
|