@dwp/govuk-casa 8.0.0-alpha2 → 8.0.1
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 +14 -0
- package/README.md +1 -1
- package/dist/assets/css/casa-ie8.css +1 -1
- package/dist/assets/css/casa.css +1 -1
- package/dist/casa.d.ts +2 -1
- package/dist/casa.js +3 -1
- package/dist/lib/CasaTemplateLoader.d.ts +4 -2
- package/dist/lib/CasaTemplateLoader.js +26 -4
- package/dist/lib/JourneyContext.d.ts +38 -6
- package/dist/lib/JourneyContext.js +58 -17
- package/dist/lib/MutableRouter.js +6 -2
- package/dist/lib/Plan.d.ts +37 -4
- package/dist/lib/Plan.js +75 -11
- package/dist/lib/ValidationError.d.ts +6 -2
- package/dist/lib/ValidationError.js +7 -0
- package/dist/lib/ValidatorFactory.d.ts +72 -19
- package/dist/lib/ValidatorFactory.js +33 -20
- package/dist/lib/configuration-ingestor.d.ts +262 -0
- package/dist/lib/configuration-ingestor.js +464 -0
- package/dist/lib/configure.d.ts +26 -140
- package/dist/lib/configure.js +17 -45
- package/dist/lib/dirname.cjs +1 -1
- package/dist/lib/dirname.d.cts +2 -0
- package/dist/lib/end-session.d.ts +2 -1
- package/dist/lib/end-session.js +27 -7
- package/dist/lib/field.d.ts +39 -46
- package/dist/lib/field.js +75 -36
- package/dist/lib/index.d.ts +14 -0
- package/dist/lib/index.js +54 -0
- package/dist/lib/logger.d.ts +2 -1
- package/dist/lib/logger.js +3 -4
- package/dist/lib/nunjucks-filters.js +8 -0
- package/dist/lib/utils.d.ts +18 -2
- package/dist/lib/utils.js +56 -2
- package/dist/lib/validators/inArray.js +1 -1
- package/dist/lib/validators/index.js +0 -22
- package/dist/lib/validators/postalAddressObject.js +6 -2
- package/dist/lib/waypoint-url.d.ts +2 -1
- package/dist/lib/waypoint-url.js +3 -0
- package/dist/middleware/body-parser.d.ts +1 -0
- package/dist/middleware/body-parser.js +18 -9
- package/dist/middleware/data.d.ts +1 -2
- package/dist/middleware/data.js +9 -9
- package/dist/middleware/dirname.cjs +1 -1
- package/dist/middleware/dirname.d.cts +2 -0
- package/dist/middleware/gather-fields.d.ts +2 -1
- package/dist/middleware/gather-fields.js +6 -5
- package/dist/middleware/i18n.js +5 -1
- package/dist/middleware/post.js +6 -6
- package/dist/middleware/progress-journey.js +1 -1
- package/dist/middleware/sanitise-fields.js +9 -9
- package/dist/middleware/session.d.ts +2 -1
- package/dist/middleware/session.js +62 -55
- package/dist/middleware/skip-waypoint.js +2 -2
- package/dist/middleware/steer-journey.d.ts +2 -1
- package/dist/middleware/steer-journey.js +3 -0
- package/dist/middleware/validate-fields.js +7 -6
- package/dist/mjs/esm-wrapper.js +10 -0
- package/dist/routes/ancillary.d.ts +8 -1
- package/dist/routes/ancillary.js +7 -2
- package/dist/routes/dirname.cjs +1 -1
- package/dist/routes/dirname.d.cts +2 -0
- package/dist/routes/journey.js +14 -8
- package/dist/routes/static.js +4 -3
- package/package.json +42 -25
- package/views/casa/layouts/main.njk +2 -2
package/dist/lib/configure.js
CHANGED
|
@@ -8,6 +8,7 @@ const path_1 = require("path");
|
|
|
8
8
|
const module_1 = require("module");
|
|
9
9
|
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
10
10
|
const dirname_cjs_1 = __importDefault(require("./dirname.cjs"));
|
|
11
|
+
const configuration_ingestor_js_1 = __importDefault(require("./configuration-ingestor.js"));
|
|
11
12
|
const nunjucks_js_1 = __importDefault(require("./nunjucks.js"));
|
|
12
13
|
const static_js_1 = __importDefault(require("../routes/static.js"));
|
|
13
14
|
const ancillary_js_1 = __importDefault(require("../routes/ancillary.js"));
|
|
@@ -20,32 +21,13 @@ const data_js_1 = __importDefault(require("../middleware/data.js"));
|
|
|
20
21
|
const body_parser_js_1 = __importDefault(require("../middleware/body-parser.js"));
|
|
21
22
|
const csrf_js_1 = __importDefault(require("../middleware/csrf.js"));
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @typedef {object} SessionOptions
|
|
25
|
-
* @property {string} [name=casasession] Session name
|
|
26
|
-
* @property {string} [secret=secret] Encryption secret
|
|
27
|
-
* @property {number} [ttl=3600] Session ttl (seconds)
|
|
28
|
-
* @property {boolean} [secure=false] Whether to use secure session cookies
|
|
29
|
-
* @property {boolean|string} [cookieSameSite=true] SameSite (true = Strict)
|
|
30
|
-
* @property {object} [store] Session store (default MemoryStore)
|
|
31
|
-
*/
|
|
32
|
-
/**
|
|
33
|
-
* @typedef {object} GlobalHook Hook configuration
|
|
34
|
-
* @property {string} hook Hook name in format `<router>.<hook>`
|
|
35
|
-
* @property {Function} middleware Middleware function to insert at the hook point
|
|
36
|
-
* @property {string|RegExp} [path=undefined] Only run if route path matches this string/regexp
|
|
24
|
+
* @typedef {import('express').RequestHandler} ExpressRequestHandler
|
|
37
25
|
*/
|
|
38
26
|
/**
|
|
39
|
-
* @typedef {
|
|
40
|
-
* @property {string} hook Hook name (without a scope prefix)
|
|
41
|
-
* @property {Function} middleware Middleware function to insert at the hook point
|
|
27
|
+
* @typedef {import('./index').MutableRouter} MutableRouter
|
|
42
28
|
*/
|
|
43
29
|
/**
|
|
44
|
-
* @typedef {
|
|
45
|
-
* @property {string} waypoint The waypoint with which this page is associated
|
|
46
|
-
* @property {string} view Template path
|
|
47
|
-
* @property {PageHook[]} [hooks=[]] Page-specific hooks (optional, default [])
|
|
48
|
-
* @property {PageField[]} [fields=[]] Fields to be managed on this page (optional, default [])
|
|
30
|
+
* @typedef {import('./configuration-ingestor').ConfigurationOptions} ConfigurationOptions
|
|
49
31
|
*/
|
|
50
32
|
/**
|
|
51
33
|
* @typedef {object} ConfigureResult Result of a call to configure() function
|
|
@@ -53,13 +35,13 @@ const csrf_js_1 = __importDefault(require("../middleware/csrf.js"));
|
|
|
53
35
|
* @property {MutableRouter} staticRouter Router handling all static assets
|
|
54
36
|
* @property {MutableRouter} ancillaryRouter Router handling ancillary routes
|
|
55
37
|
* @property {MutableRouter} journeyRouter Router handling all waypoint requests
|
|
56
|
-
* @property {
|
|
57
|
-
* @property {
|
|
58
|
-
* @property {
|
|
59
|
-
* @property {
|
|
60
|
-
* @property {
|
|
61
|
-
* @property {
|
|
62
|
-
* @property {
|
|
38
|
+
* @property {ExpressRequestHandler[]} preMiddleware Middleware mounted before anything else
|
|
39
|
+
* @property {ExpressRequestHandler[]} postMiddleware Middleware mounted after everything else
|
|
40
|
+
* @property {ExpressRequestHandler[]} csrfMiddleware CSRF get/set middleware (useful for forms)
|
|
41
|
+
* @property {ExpressRequestHandler} sessionMiddleware Session middleware
|
|
42
|
+
* @property {ExpressRequestHandler[]} cookieParserMiddleware Cookie-parsing middleware
|
|
43
|
+
* @property {ExpressRequestHandler[]} i18nMiddleware I18n preparation middleware
|
|
44
|
+
* @property {ExpressRequestHandler} bodyParserMiddleware Body parsing middleware
|
|
63
45
|
* @property {Function} mount Function used to mount all CASA artifacts onto an ExpressJS app
|
|
64
46
|
*/
|
|
65
47
|
/**
|
|
@@ -68,17 +50,7 @@ const csrf_js_1 = __importDefault(require("../middleware/csrf.js"));
|
|
|
68
50
|
* `mountUrl` is used to ensure the CSS content uses the correct reference to
|
|
69
51
|
* static assets in the `govuk-frontend` module.
|
|
70
52
|
*
|
|
71
|
-
* @param {
|
|
72
|
-
* @param {string} [config.mountUrl=/] URL path to root of CASA app
|
|
73
|
-
* @param {string} [config.serviceName=common.serviceName] Service name (i18n key)
|
|
74
|
-
* @param {string[]} [config.views=[]] Template directories
|
|
75
|
-
* @param {SessionOptions} [config.session] Session configuration
|
|
76
|
-
* @param {Page[]} [config.pages=[]] Pages the represent waypoints
|
|
77
|
-
* @param {GlobalHook[]} [config.hooks=[]] Hooks to apply
|
|
78
|
-
* @param {object[]} [config.plugins=[]] Plugins
|
|
79
|
-
* @param {I18nOptions[]} [config.i18n] I18n configuration
|
|
80
|
-
* @param {Plan} config.plan CASA Plan
|
|
81
|
-
* @param {ContextEvent[]} [config.events=[]] Handlers for JourneyContext events
|
|
53
|
+
* @param {ConfigurationOptions} config Configuration options
|
|
82
54
|
* @returns {ConfigureResult} Result
|
|
83
55
|
*/
|
|
84
56
|
function configure(config = {}) {
|
|
@@ -89,18 +61,18 @@ function configure(config = {}) {
|
|
|
89
61
|
plugin.configure(config);
|
|
90
62
|
});
|
|
91
63
|
// Extract config
|
|
92
|
-
|
|
93
|
-
const { mountUrl = '/', serviceName = 'common:serviceName', views = [], session = {
|
|
64
|
+
const { mountUrl = '/', views = [], session = {
|
|
94
65
|
secret: 'secret',
|
|
95
66
|
name: 'casasession',
|
|
96
67
|
secure: false,
|
|
97
|
-
ttl:
|
|
68
|
+
ttl: 3600,
|
|
98
69
|
cookieSameSite: true,
|
|
70
|
+
cookiePath: '/',
|
|
99
71
|
store: undefined,
|
|
100
72
|
}, pages = [], plan = null, hooks = [], plugins = [], events = [], i18n = {
|
|
101
73
|
dirs: [],
|
|
102
74
|
locales: ['en', 'cy'],
|
|
103
|
-
}, } = config;
|
|
75
|
+
}, } = (0, configuration_ingestor_js_1.default)(config);
|
|
104
76
|
// Prepare all page hooks so they are prefixed with the `journey.` scope.
|
|
105
77
|
pages.forEach((page) => {
|
|
106
78
|
var _a;
|
|
@@ -131,6 +103,7 @@ function configure(config = {}) {
|
|
|
131
103
|
name: session.name,
|
|
132
104
|
ttl: session.ttl,
|
|
133
105
|
cookieSameSite: session.cookieSameSite,
|
|
106
|
+
cookiePath: session.cookiePath,
|
|
134
107
|
mountUrl,
|
|
135
108
|
store: (_b = session.store) !== null && _b !== void 0 ? _b : new express_session_1.MemoryStore(),
|
|
136
109
|
});
|
|
@@ -145,7 +118,6 @@ function configure(config = {}) {
|
|
|
145
118
|
const dataMiddleware = (0, data_js_1.default)({
|
|
146
119
|
plan,
|
|
147
120
|
mountUrl,
|
|
148
|
-
serviceName,
|
|
149
121
|
events,
|
|
150
122
|
});
|
|
151
123
|
// Prepare form middleware and its constiuent parts
|
package/dist/lib/dirname.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = __dirname;
|
|
1
|
+
module.exports = __dirname;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A convenience for ending the current session, but retaining some data in it,
|
|
3
|
-
* like the current language.
|
|
3
|
+
* like the current language. It persists an empty session before regenerating
|
|
4
|
+
* a new ID.
|
|
4
5
|
*
|
|
5
6
|
* Note: this will not remove the session from server-side storage, which will
|
|
6
7
|
* instead be left up to the storage mechanism to clean up.
|
package/dist/lib/end-session.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const logger_js_1 = __importDefault(require("./logger.js"));
|
|
7
|
+
const log = (0, logger_js_1.default)('lib:end-session');
|
|
3
8
|
/**
|
|
4
9
|
* A convenience for ending the current session, but retaining some data in it,
|
|
5
|
-
* like the current language.
|
|
10
|
+
* like the current language. It persists an empty session before regenerating
|
|
11
|
+
* a new ID.
|
|
6
12
|
*
|
|
7
13
|
* Note: this will not remove the session from server-side storage, which will
|
|
8
14
|
* instead be left up to the storage mechanism to clean up.
|
|
@@ -13,14 +19,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
19
|
*/
|
|
14
20
|
function endSession(req, next) {
|
|
15
21
|
const { language } = req.session;
|
|
16
|
-
req.session.
|
|
17
|
-
if (
|
|
18
|
-
|
|
22
|
+
Object.entries(req.session).forEach(([k]) => {
|
|
23
|
+
if (!['cookie'].includes(k)) {
|
|
24
|
+
// ESLint disabled as `Object.entries()` returns "own" properties, and
|
|
25
|
+
// all values are being null'd, so not assigned any user-controlled values
|
|
26
|
+
/* eslint-disable-next-line security/detect-object-injection */
|
|
27
|
+
req.session[k] = null;
|
|
19
28
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
});
|
|
30
|
+
req.session.save((saveErr) => {
|
|
31
|
+
if (saveErr) {
|
|
32
|
+
log.error(saveErr);
|
|
23
33
|
}
|
|
34
|
+
req.session.regenerate((err) => {
|
|
35
|
+
if (err) {
|
|
36
|
+
log.error(err);
|
|
37
|
+
next(err);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
req.session.language = language;
|
|
41
|
+
req.session.save(next);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
24
44
|
});
|
|
25
45
|
}
|
|
26
46
|
exports.default = endSession;
|
package/dist/lib/field.d.ts
CHANGED
|
@@ -10,12 +10,35 @@ export class PageField {
|
|
|
10
10
|
* @throws {Error} When run on a complex field
|
|
11
11
|
*/
|
|
12
12
|
getValue(obj?: object): any;
|
|
13
|
-
putValue(obj
|
|
13
|
+
putValue(obj?: any, value?: undefined): PageField;
|
|
14
14
|
get name(): string;
|
|
15
15
|
get meta(): object;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Add/get value validators
|
|
18
|
+
* Some validators will include a `sanitise()` method which will be run at the
|
|
19
|
+
* same time as other "processors".
|
|
20
|
+
*
|
|
21
|
+
* @param {ValidateFunction[]} items Validation functions
|
|
22
|
+
* @returns {PageField | ValidateFunction[]} Chain or return all validators
|
|
23
|
+
*/
|
|
24
|
+
validators(items?: ValidateFunction[]): PageField | ValidateFunction[];
|
|
25
|
+
/**
|
|
26
|
+
* Add/get value pre-processors
|
|
27
|
+
* This is most often used to sanitise values to a particular data type.
|
|
28
|
+
*
|
|
29
|
+
* @param {ProcessorFunction[]} items Processor functions
|
|
30
|
+
* @returns {PageField | ProcessorFunction[]} Chain or return all processors
|
|
31
|
+
*/
|
|
32
|
+
processors(items?: ProcessorFunction[]): PageField | ProcessorFunction[];
|
|
33
|
+
/**
|
|
34
|
+
* Add/get conditions
|
|
35
|
+
* All conditions must be met in order for this field to be considered
|
|
36
|
+
* "actionable".
|
|
37
|
+
*
|
|
38
|
+
* @param {ConditionFunction[]} items Condition functions
|
|
39
|
+
* @returns {PageField | ConditionFunction[]} Chain or return all conditions
|
|
40
|
+
*/
|
|
41
|
+
conditions(items?: ConditionFunction[]): PageField | ConditionFunction[];
|
|
19
42
|
/**
|
|
20
43
|
* Run all validators and return array of errors, if applicable.
|
|
21
44
|
*
|
|
@@ -23,7 +46,7 @@ export class PageField {
|
|
|
23
46
|
* @param {ValidateContext} context Contextual information
|
|
24
47
|
* @returns {ValidationError[]} Errors, or an empty array if all valid
|
|
25
48
|
*/
|
|
26
|
-
runValidators(value: any, context
|
|
49
|
+
runValidators(value: any, context?: any): ValidationError[];
|
|
27
50
|
applyProcessors(value: any): any;
|
|
28
51
|
/**
|
|
29
52
|
* Apply all conditions to get the resulting boolean
|
|
@@ -39,46 +62,16 @@ export class PageField {
|
|
|
39
62
|
waypoint: string;
|
|
40
63
|
journeyContext: object;
|
|
41
64
|
}): boolean;
|
|
42
|
-
validator(
|
|
43
|
-
processor(
|
|
44
|
-
condition(
|
|
45
|
-
if(...args: any[]):
|
|
65
|
+
validator(validator: any): any[] | PageField;
|
|
66
|
+
processor(processor: any): PageField | ProcessorFunction[];
|
|
67
|
+
condition(condition: any): PageField | ConditionFunction[];
|
|
68
|
+
if(...args: any[]): PageField | ConditionFunction[];
|
|
46
69
|
#private;
|
|
47
70
|
}
|
|
48
|
-
export type
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*/
|
|
56
|
-
sanitise: SanitiseFunction;
|
|
57
|
-
/**
|
|
58
|
-
* Configuration
|
|
59
|
-
*/
|
|
60
|
-
config: object;
|
|
61
|
-
/**
|
|
62
|
-
* Validator name
|
|
63
|
-
*/
|
|
64
|
-
name: string;
|
|
65
|
-
};
|
|
66
|
-
export type ValidateFunction = (value: any, context: ValidateContext) => any[];
|
|
67
|
-
export type SanitiseFunction = (value: any) => any;
|
|
68
|
-
/**
|
|
69
|
-
* Context passed to validate function
|
|
70
|
-
*/
|
|
71
|
-
export type ValidateContext = {
|
|
72
|
-
/**
|
|
73
|
-
* Journey context
|
|
74
|
-
*/
|
|
75
|
-
journeyContext: any;
|
|
76
|
-
/**
|
|
77
|
-
* Waypoint
|
|
78
|
-
*/
|
|
79
|
-
waypoint: string;
|
|
80
|
-
/**
|
|
81
|
-
* Name of field being processed
|
|
82
|
-
*/
|
|
83
|
-
fieldName: string;
|
|
84
|
-
};
|
|
71
|
+
export type JourneyContext = import('./index').JourneyContext;
|
|
72
|
+
export type Validator = import('./index').Validator;
|
|
73
|
+
export type ValidateFunction = import('./index').ValidateFunction;
|
|
74
|
+
export type ValidateContext = import('./index').ValidateContext;
|
|
75
|
+
export type ValidationError = import('./index').ValidationError;
|
|
76
|
+
export type ProcessorFunction = (value: any) => any;
|
|
77
|
+
export type ConditionFunction = (context: Object, fieldName: string, fieldValue: any, waypoint: string, waypointId: string, journeyContext: JourneyContext) => boolean;
|
package/dist/lib/field.js
CHANGED
|
@@ -20,28 +20,34 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
20
20
|
const utils_js_1 = require("./utils.js");
|
|
21
21
|
const { isFunction } = lodash_1.default;
|
|
22
22
|
/**
|
|
23
|
-
* @typedef {
|
|
24
|
-
* @property {ValidateFunction} validate Validation function
|
|
25
|
-
* @property {SanitiseFunction} sanitise Sanitise a given value prior to validation
|
|
26
|
-
* @property {object} config Configuration
|
|
27
|
-
* @property {string} name Validator name
|
|
23
|
+
* @typedef {import('./index').JourneyContext} JourneyContext
|
|
28
24
|
*/
|
|
29
25
|
/**
|
|
30
|
-
* @
|
|
31
|
-
* @param {any} value
|
|
32
|
-
* @param {ValidateContext} context
|
|
33
|
-
* @returns {ValidationError[]}
|
|
26
|
+
* @typedef {import('./index').Validator} Validator
|
|
34
27
|
*/
|
|
35
28
|
/**
|
|
36
|
-
* @
|
|
37
|
-
|
|
29
|
+
* @typedef {import('./index').ValidateFunction} ValidateFunction
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* @typedef {import('./index').ValidateContext} ValidateContext
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {import('./index').ValidationError} ValidationError
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* @callback ProcessorFunction
|
|
39
|
+
* @param {any} value Value to be processed
|
|
38
40
|
* @returns {any}
|
|
39
41
|
*/
|
|
40
42
|
/**
|
|
41
|
-
* @
|
|
42
|
-
* @
|
|
43
|
-
* @
|
|
44
|
-
* @
|
|
43
|
+
* @callback ConditionFunction
|
|
44
|
+
* @param {Object} context Value to be processed
|
|
45
|
+
* @param {string} context.fieldName Field name
|
|
46
|
+
* @param {any} context.fieldValue Field value
|
|
47
|
+
* @param {string} context.waypoint Waypoint
|
|
48
|
+
* @param {string} context.waypointId [DEPRECATED] Waypoint (for backwards compatibility with v7)
|
|
49
|
+
* @param {JourneyContext} journeyContext Journey Context
|
|
50
|
+
* @returns {boolean} True if the validators should be run
|
|
45
51
|
*/
|
|
46
52
|
// Quick check to see if the field name corresponds to a non-primitive complex
|
|
47
53
|
// type. For example, `my_field[nested]`.
|
|
@@ -56,15 +62,15 @@ class PageField {
|
|
|
56
62
|
*/
|
|
57
63
|
_PageField_name.set(this, void 0);
|
|
58
64
|
/**
|
|
59
|
-
* @type {
|
|
65
|
+
* @type {ProcessorFunction[]}
|
|
60
66
|
*/
|
|
61
67
|
_PageField_processors.set(this, void 0);
|
|
62
68
|
/**
|
|
63
|
-
* @type {
|
|
69
|
+
* @type {ValidateFunction[]}
|
|
64
70
|
*/
|
|
65
71
|
_PageField_validators.set(this, void 0);
|
|
66
72
|
/**
|
|
67
|
-
* @type {
|
|
73
|
+
* @type {ConditionFunction[]}
|
|
68
74
|
*/
|
|
69
75
|
_PageField_conditions.set(this, void 0);
|
|
70
76
|
/**
|
|
@@ -101,7 +107,7 @@ class PageField {
|
|
|
101
107
|
}
|
|
102
108
|
throw new Error('Not yet supporting complex field types');
|
|
103
109
|
}
|
|
104
|
-
putValue(obj = Object.create(null), value) {
|
|
110
|
+
putValue(obj = Object.create(null), value = undefined) {
|
|
105
111
|
if (!__classPrivateFieldGet(this, _PageField_meta, "f").complex) {
|
|
106
112
|
/* eslint-disable-next-line no-param-reassign */
|
|
107
113
|
obj[__classPrivateFieldGet(this, _PageField_name, "f")] = value;
|
|
@@ -116,28 +122,44 @@ class PageField {
|
|
|
116
122
|
get meta() {
|
|
117
123
|
return __classPrivateFieldGet(this, _PageField_meta, "f");
|
|
118
124
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Add/get value validators
|
|
127
|
+
* Some validators will include a `sanitise()` method which will be run at the
|
|
128
|
+
* same time as other "processors".
|
|
129
|
+
*
|
|
130
|
+
* @param {ValidateFunction[]} items Validation functions
|
|
131
|
+
* @returns {PageField | ValidateFunction[]} Chain or return all validators
|
|
132
|
+
*/
|
|
133
|
+
validators(items = []) {
|
|
123
134
|
if (!items.length) {
|
|
124
135
|
return __classPrivateFieldGet(this, _PageField_validators, "f");
|
|
125
136
|
}
|
|
126
137
|
__classPrivateFieldSet(this, _PageField_validators, [...__classPrivateFieldGet(this, _PageField_validators, "f"), ...(items.flat())], "f");
|
|
127
138
|
return this;
|
|
128
139
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Add/get value pre-processors
|
|
142
|
+
* This is most often used to sanitise values to a particular data type.
|
|
143
|
+
*
|
|
144
|
+
* @param {ProcessorFunction[]} items Processor functions
|
|
145
|
+
* @returns {PageField | ProcessorFunction[]} Chain or return all processors
|
|
146
|
+
*/
|
|
147
|
+
processors(items = []) {
|
|
132
148
|
if (!items.length) {
|
|
133
149
|
return __classPrivateFieldGet(this, _PageField_processors, "f");
|
|
134
150
|
}
|
|
135
151
|
__classPrivateFieldSet(this, _PageField_processors, [...__classPrivateFieldGet(this, _PageField_processors, "f"), ...(items.flat())], "f");
|
|
136
152
|
return this;
|
|
137
153
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Add/get conditions
|
|
156
|
+
* All conditions must be met in order for this field to be considered
|
|
157
|
+
* "actionable".
|
|
158
|
+
*
|
|
159
|
+
* @param {ConditionFunction[]} items Condition functions
|
|
160
|
+
* @returns {PageField | ConditionFunction[]} Chain or return all conditions
|
|
161
|
+
*/
|
|
162
|
+
conditions(items = []) {
|
|
141
163
|
if (!items.length) {
|
|
142
164
|
return __classPrivateFieldGet(this, _PageField_conditions, "f");
|
|
143
165
|
}
|
|
@@ -152,14 +174,24 @@ class PageField {
|
|
|
152
174
|
* @param {ValidateContext} context Contextual information
|
|
153
175
|
* @returns {ValidationError[]} Errors, or an empty array if all valid
|
|
154
176
|
*/
|
|
155
|
-
runValidators(value, context) {
|
|
177
|
+
runValidators(value, context = Object.create(null)) {
|
|
178
|
+
var _a;
|
|
156
179
|
// Skip validation if the field is empty and optional
|
|
157
180
|
if (__classPrivateFieldGet(this, _PageField_meta, "f").optional && (0, utils_js_1.isEmpty)(value)) {
|
|
158
181
|
return [];
|
|
159
182
|
}
|
|
183
|
+
// Skip validation if conditions are not met
|
|
184
|
+
// We duplicate value in context.fieldValue for historical reasons
|
|
185
|
+
context.fieldValue = (_a = context.fieldValue) !== null && _a !== void 0 ? _a : value;
|
|
186
|
+
if (!this.testConditions(context)) {
|
|
187
|
+
return [];
|
|
188
|
+
}
|
|
160
189
|
let errors = [];
|
|
161
190
|
for (let i = 0, l = __classPrivateFieldGet(this, _PageField_validators, "f").length; i < l; i++) {
|
|
191
|
+
// ESLint disabled as `i` is an integer
|
|
192
|
+
/* eslint-disable security/detect-object-injection */
|
|
162
193
|
const fieldErrors = __classPrivateFieldGet(this, _PageField_validators, "f")[i].validate(value, context).map((e) => e.withContext(Object.assign(Object.assign({}, context), { validator: __classPrivateFieldGet(this, _PageField_validators, "f")[i].name })));
|
|
194
|
+
/* eslint-enable security/detect-object-injection */
|
|
163
195
|
errors = [
|
|
164
196
|
...errors,
|
|
165
197
|
...(fieldErrors !== null && fieldErrors !== void 0 ? fieldErrors : []),
|
|
@@ -177,12 +209,17 @@ class PageField {
|
|
|
177
209
|
let processedValue = value;
|
|
178
210
|
// Some of the validators may have their own "sanitise()" methods. These
|
|
179
211
|
// should be run before any other processors
|
|
212
|
+
// ESLint disabled as `i` is an integer
|
|
213
|
+
/* eslint-disable security/detect-object-injection */
|
|
180
214
|
for (let i = 0, l = __classPrivateFieldGet(this, _PageField_validators, "f").length; i < l; i++) {
|
|
181
215
|
if (isFunction(__classPrivateFieldGet(this, _PageField_validators, "f")[i].sanitise)) {
|
|
182
216
|
processedValue = __classPrivateFieldGet(this, _PageField_validators, "f")[i].sanitise(processedValue);
|
|
183
217
|
}
|
|
184
218
|
}
|
|
219
|
+
/* eslint-enable security/detect-object-injection */
|
|
185
220
|
for (let i = 0, l = __classPrivateFieldGet(this, _PageField_processors, "f").length; i < l; i++) {
|
|
221
|
+
// ESLint disabled as `i` is an integer
|
|
222
|
+
/* eslint-disable-next-line security/detect-object-injection */
|
|
186
223
|
processedValue = __classPrivateFieldGet(this, _PageField_processors, "f")[i](processedValue);
|
|
187
224
|
}
|
|
188
225
|
return processedValue;
|
|
@@ -206,19 +243,21 @@ class PageField {
|
|
|
206
243
|
};
|
|
207
244
|
let result = true;
|
|
208
245
|
for (let i = 0, l = __classPrivateFieldGet(this, _PageField_conditions, "f").length; i < l; i++) {
|
|
246
|
+
// ESLint disabled as `i` is an integer
|
|
247
|
+
/* eslint-disable-next-line security/detect-object-injection */
|
|
209
248
|
result = result && __classPrivateFieldGet(this, _PageField_conditions, "f")[i](context);
|
|
210
249
|
}
|
|
211
250
|
return result;
|
|
212
251
|
}
|
|
213
252
|
/* ---------------------------------------------------------------- aliases */
|
|
214
|
-
validator(
|
|
215
|
-
return this.validators(
|
|
253
|
+
validator(validator) {
|
|
254
|
+
return this.validators([validator]);
|
|
216
255
|
}
|
|
217
|
-
processor(
|
|
218
|
-
return this.processors(
|
|
256
|
+
processor(processor) {
|
|
257
|
+
return this.processors([processor]);
|
|
219
258
|
}
|
|
220
|
-
condition(
|
|
221
|
-
return this.conditions(
|
|
259
|
+
condition(condition) {
|
|
260
|
+
return this.conditions([condition]);
|
|
222
261
|
}
|
|
223
262
|
if(...args) {
|
|
224
263
|
return this.conditions(...args);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import CasaTemplateLoader from "./CasaTemplateLoader.js";
|
|
2
|
+
import configure from "./configure.js";
|
|
3
|
+
import configurationIngestor from "./configuration-ingestor.js";
|
|
4
|
+
import endSession from "./end-session.js";
|
|
5
|
+
import field from "./field.js";
|
|
6
|
+
import { PageField } from "./field.js";
|
|
7
|
+
import JourneyContext from "./JourneyContext.js";
|
|
8
|
+
import MutableRouter from "./MutableRouter.js";
|
|
9
|
+
import Plan from "./Plan.js";
|
|
10
|
+
import * as utils from "./utils.js";
|
|
11
|
+
import ValidationError from "./ValidationError.js";
|
|
12
|
+
import ValidatorFactory from "./ValidatorFactory.js";
|
|
13
|
+
import waypointUrl from "./waypoint-url.js";
|
|
14
|
+
export { CasaTemplateLoader, configure, configurationIngestor, endSession, field, PageField, JourneyContext, MutableRouter, Plan, utils, ValidationError, ValidatorFactory, waypointUrl };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Just used to collate type information for intellisense. This should not get
|
|
4
|
+
* imported anywhere in code, other than JSDoc references.
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.waypointUrl = exports.ValidatorFactory = exports.ValidationError = exports.utils = exports.Plan = exports.MutableRouter = exports.JourneyContext = exports.PageField = exports.field = exports.endSession = exports.configurationIngestor = exports.configure = exports.CasaTemplateLoader = void 0;
|
|
30
|
+
const CasaTemplateLoader_js_1 = __importDefault(require("./CasaTemplateLoader.js"));
|
|
31
|
+
exports.CasaTemplateLoader = CasaTemplateLoader_js_1.default;
|
|
32
|
+
const configure_js_1 = __importDefault(require("./configure.js"));
|
|
33
|
+
exports.configure = configure_js_1.default;
|
|
34
|
+
const configuration_ingestor_js_1 = __importDefault(require("./configuration-ingestor.js"));
|
|
35
|
+
exports.configurationIngestor = configuration_ingestor_js_1.default;
|
|
36
|
+
const end_session_js_1 = __importDefault(require("./end-session.js"));
|
|
37
|
+
exports.endSession = end_session_js_1.default;
|
|
38
|
+
const field_js_1 = __importStar(require("./field.js"));
|
|
39
|
+
exports.field = field_js_1.default;
|
|
40
|
+
Object.defineProperty(exports, "PageField", { enumerable: true, get: function () { return field_js_1.PageField; } });
|
|
41
|
+
const JourneyContext_js_1 = __importDefault(require("./JourneyContext.js"));
|
|
42
|
+
exports.JourneyContext = JourneyContext_js_1.default;
|
|
43
|
+
const MutableRouter_js_1 = __importDefault(require("./MutableRouter.js"));
|
|
44
|
+
exports.MutableRouter = MutableRouter_js_1.default;
|
|
45
|
+
const Plan_js_1 = __importDefault(require("./Plan.js"));
|
|
46
|
+
exports.Plan = Plan_js_1.default;
|
|
47
|
+
const ValidationError_js_1 = __importDefault(require("./ValidationError.js"));
|
|
48
|
+
exports.ValidationError = ValidationError_js_1.default;
|
|
49
|
+
const ValidatorFactory_js_1 = __importDefault(require("./ValidatorFactory.js"));
|
|
50
|
+
exports.ValidatorFactory = ValidatorFactory_js_1.default;
|
|
51
|
+
const waypoint_url_js_1 = __importDefault(require("./waypoint-url.js"));
|
|
52
|
+
exports.waypointUrl = waypoint_url_js_1.default;
|
|
53
|
+
const utils = __importStar(require("./utils.js"));
|
|
54
|
+
exports.utils = utils;
|
package/dist/lib/logger.d.ts
CHANGED
package/dist/lib/logger.js
CHANGED
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const debug_1 = __importDefault(require("debug"));
|
|
7
7
|
const casaDebugger = (0, debug_1.default)('casa');
|
|
8
|
-
|
|
9
|
-
const logger = casaDebugger.extend(
|
|
8
|
+
exports.default = (namespace) => {
|
|
9
|
+
const logger = casaDebugger.extend(namespace);
|
|
10
10
|
return {
|
|
11
11
|
trace: logger.extend('trace'),
|
|
12
12
|
debug: logger.extend('debug'),
|
|
@@ -15,5 +15,4 @@ function default_1(ns) {
|
|
|
15
15
|
error: logger.extend('error'),
|
|
16
16
|
fatal: logger.extend('fatal'),
|
|
17
17
|
};
|
|
18
|
-
}
|
|
19
|
-
exports.default = default_1;
|
|
18
|
+
};
|
|
@@ -14,6 +14,8 @@ const { all: deepmergeAll } = deepmerge_1.default;
|
|
|
14
14
|
const combineMerge = (target, source, options) => {
|
|
15
15
|
const destination = target.slice();
|
|
16
16
|
source.forEach((item, index) => {
|
|
17
|
+
// ESLint disabled as `index` is only an integer
|
|
18
|
+
/* eslint-disable security/detect-object-injection */
|
|
17
19
|
if (typeof destination[index] === 'undefined') {
|
|
18
20
|
destination[index] = options.cloneUnlessOtherwiseSpecified(item, options);
|
|
19
21
|
}
|
|
@@ -23,6 +25,7 @@ const combineMerge = (target, source, options) => {
|
|
|
23
25
|
else if (target.indexOf(item) === -1) {
|
|
24
26
|
destination.push(item);
|
|
25
27
|
}
|
|
28
|
+
/* eslint-enable security/detect-object-injection */
|
|
26
29
|
});
|
|
27
30
|
return destination;
|
|
28
31
|
};
|
|
@@ -75,6 +78,10 @@ function renderAsAttributes(attrsObject) {
|
|
|
75
78
|
const attrsList = [];
|
|
76
79
|
if (typeof attrsObject === 'object') {
|
|
77
80
|
Object.keys(attrsObject).forEach((key) => {
|
|
81
|
+
// ESLint disable as `attrsObject` is dev-controlled, `Object.keys()` has
|
|
82
|
+
// been used (to get "own" properties) and `m` is one of the characters
|
|
83
|
+
// found by the regex.
|
|
84
|
+
/* eslint-disable security/detect-object-injection */
|
|
78
85
|
const value = String(attrsObject[key]).replace(/[<>"'&]/g, (m) => ({
|
|
79
86
|
'<': '<',
|
|
80
87
|
'>': '>',
|
|
@@ -82,6 +89,7 @@ function renderAsAttributes(attrsObject) {
|
|
|
82
89
|
'\'': ''',
|
|
83
90
|
'&': '&',
|
|
84
91
|
}[m]));
|
|
92
|
+
/* eslint-enable security/detect-object-injection */
|
|
85
93
|
attrsList.push(`${key}="${value}"`);
|
|
86
94
|
});
|
|
87
95
|
}
|