@dwp/govuk-casa 8.0.0-alpha1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -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 +11 -3
- package/dist/lib/CasaTemplateLoader.js +38 -2
- package/dist/lib/JourneyContext.d.ts +51 -8
- package/dist/lib/JourneyContext.js +73 -147
- package/dist/lib/MutableRouter.d.ts +19 -19
- package/dist/lib/MutableRouter.js +30 -23
- package/dist/lib/Plan.d.ts +41 -6
- package/dist/lib/Plan.js +84 -17
- package/dist/lib/ValidationError.d.ts +6 -2
- package/dist/lib/ValidationError.js +7 -0
- package/dist/lib/ValidatorFactory.d.ts +72 -13
- package/dist/lib/ValidatorFactory.js +33 -14
- package/dist/lib/configuration-ingestor.d.ts +262 -0
- package/dist/lib/configuration-ingestor.js +464 -0
- package/dist/lib/configure.d.ts +39 -154
- package/dist/lib/configure.js +35 -59
- package/dist/lib/dirname.cjs +1 -1
- package/dist/lib/dirname.d.cts +2 -0
- package/dist/lib/end-session.d.ts +4 -3
- package/dist/lib/end-session.js +30 -8
- package/dist/lib/field.d.ts +53 -55
- package/dist/lib/field.js +96 -54
- 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.d.ts +11 -11
- package/dist/lib/nunjucks-filters.js +22 -36
- package/dist/lib/nunjucks.d.ts +7 -6
- package/dist/lib/nunjucks.js +6 -6
- package/dist/lib/utils.d.ts +26 -0
- package/dist/lib/utils.js +70 -1
- package/dist/lib/validators/dateObject.js +1 -1
- package/dist/lib/validators/email.js +1 -1
- package/dist/lib/validators/inArray.js +1 -1
- package/dist/lib/validators/index.js +0 -22
- package/dist/lib/validators/postalAddressObject.js +7 -3
- package/dist/lib/validators/required.js +1 -1
- package/dist/lib/waypoint-url.d.ts +13 -7
- package/dist/lib/waypoint-url.js +13 -7
- package/dist/middleware/body-parser.d.ts +2 -1
- package/dist/middleware/body-parser.js +20 -11
- package/dist/middleware/csrf.d.ts +1 -1
- package/dist/middleware/csrf.js +2 -2
- package/dist/middleware/data.d.ts +1 -2
- package/dist/middleware/data.js +19 -15
- package/dist/middleware/dirname.cjs +1 -1
- package/dist/middleware/dirname.d.cts +2 -0
- package/dist/middleware/gather-fields.d.ts +3 -2
- package/dist/middleware/gather-fields.js +14 -7
- package/dist/middleware/i18n.d.ts +1 -1
- package/dist/middleware/i18n.js +16 -11
- package/dist/middleware/post.d.ts +3 -1
- package/dist/middleware/post.js +24 -9
- package/dist/middleware/pre.js +15 -2
- package/dist/middleware/progress-journey.js +15 -17
- package/dist/middleware/sanitise-fields.js +15 -10
- package/dist/middleware/session.d.ts +2 -1
- package/dist/middleware/session.js +65 -52
- package/dist/middleware/skip-waypoint.js +10 -7
- package/dist/middleware/steer-journey.d.ts +3 -2
- package/dist/middleware/steer-journey.js +26 -8
- package/dist/middleware/validate-fields.js +15 -21
- package/dist/mjs/esm-wrapper.js +18 -7
- package/dist/routes/ancillary.d.ts +8 -1
- package/dist/routes/ancillary.js +7 -1
- package/dist/routes/dirname.cjs +1 -1
- package/dist/routes/dirname.d.cts +2 -0
- package/dist/routes/journey.js +20 -24
- package/dist/routes/static.js +10 -9
- package/package.json +41 -22
- package/views/casa/errors/static.njk +11 -0
- package/views/casa/layouts/main.njk +3 -3
package/dist/lib/field.js
CHANGED
|
@@ -16,42 +16,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
var _PageField_name, _PageField_processors, _PageField_validators, _PageField_conditions, _PageField_meta;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.PageField = void 0;
|
|
19
|
-
const utils_js_1 = require("./utils.js");
|
|
20
19
|
const lodash_1 = __importDefault(require("lodash"));
|
|
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 to make it suitable for this validator
|
|
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
|
-
* @return {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]`.
|
|
48
54
|
const reComplexType = /\[/;
|
|
49
|
-
const reInvalidName = /[^a-z0-9_
|
|
50
|
-
// Factory for convenience
|
|
51
|
-
function field(...args) {
|
|
52
|
-
return new PageField(...args);
|
|
53
|
-
}
|
|
54
|
-
exports.default = field;
|
|
55
|
+
const reInvalidName = /[^a-z0-9_.\-[\]]/i;
|
|
55
56
|
// This is never exposed via a public API, and instead users are encouraged to
|
|
56
57
|
// use the `field()` factory instead
|
|
57
58
|
class PageField {
|
|
@@ -61,19 +62,19 @@ class PageField {
|
|
|
61
62
|
*/
|
|
62
63
|
_PageField_name.set(this, void 0);
|
|
63
64
|
/**
|
|
64
|
-
* @type {
|
|
65
|
+
* @type {ProcessorFunction[]}
|
|
65
66
|
*/
|
|
66
67
|
_PageField_processors.set(this, void 0);
|
|
67
68
|
/**
|
|
68
|
-
* @type {
|
|
69
|
+
* @type {ValidateFunction[]}
|
|
69
70
|
*/
|
|
70
71
|
_PageField_validators.set(this, void 0);
|
|
71
72
|
/**
|
|
72
|
-
* @type {
|
|
73
|
+
* @type {ConditionFunction[]}
|
|
73
74
|
*/
|
|
74
75
|
_PageField_conditions.set(this, void 0);
|
|
75
76
|
/**
|
|
76
|
-
* @type {
|
|
77
|
+
* @type {object}
|
|
77
78
|
*/
|
|
78
79
|
_PageField_meta.set(this, void 0);
|
|
79
80
|
if (!name) {
|
|
@@ -96,8 +97,9 @@ class PageField {
|
|
|
96
97
|
* For complex fields, we need may need to drill into an object to extract the
|
|
97
98
|
* value.
|
|
98
99
|
*
|
|
99
|
-
* @param {
|
|
100
|
-
* @returns {any}
|
|
100
|
+
* @param {object} obj Object from which to extract the value
|
|
101
|
+
* @returns {any} Value extracted from object
|
|
102
|
+
* @throws {Error} When run on a complex field
|
|
101
103
|
*/
|
|
102
104
|
getValue(obj = Object.create(null)) {
|
|
103
105
|
if (!__classPrivateFieldGet(this, _PageField_meta, "f").complex) {
|
|
@@ -107,6 +109,7 @@ class PageField {
|
|
|
107
109
|
}
|
|
108
110
|
putValue(obj = Object.create(null), value) {
|
|
109
111
|
if (!__classPrivateFieldGet(this, _PageField_meta, "f").complex) {
|
|
112
|
+
/* eslint-disable-next-line no-param-reassign */
|
|
110
113
|
obj[__classPrivateFieldGet(this, _PageField_name, "f")] = value;
|
|
111
114
|
return this;
|
|
112
115
|
}
|
|
@@ -119,28 +122,47 @@ class PageField {
|
|
|
119
122
|
get meta() {
|
|
120
123
|
return __classPrivateFieldGet(this, _PageField_meta, "f");
|
|
121
124
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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 = []) {
|
|
134
|
+
if (!items.length) {
|
|
127
135
|
return __classPrivateFieldGet(this, _PageField_validators, "f");
|
|
136
|
+
}
|
|
128
137
|
__classPrivateFieldSet(this, _PageField_validators, [...__classPrivateFieldGet(this, _PageField_validators, "f"), ...(items.flat())], "f");
|
|
129
138
|
return this;
|
|
130
139
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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 = []) {
|
|
148
|
+
if (!items.length) {
|
|
135
149
|
return __classPrivateFieldGet(this, _PageField_processors, "f");
|
|
150
|
+
}
|
|
136
151
|
__classPrivateFieldSet(this, _PageField_processors, [...__classPrivateFieldGet(this, _PageField_processors, "f"), ...(items.flat())], "f");
|
|
137
152
|
return this;
|
|
138
153
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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 = []) {
|
|
163
|
+
if (!items.length) {
|
|
143
164
|
return __classPrivateFieldGet(this, _PageField_conditions, "f");
|
|
165
|
+
}
|
|
144
166
|
__classPrivateFieldSet(this, _PageField_conditions, [...__classPrivateFieldGet(this, _PageField_conditions, "f"), ...(items.flat())], "f");
|
|
145
167
|
return this;
|
|
146
168
|
}
|
|
@@ -159,7 +181,10 @@ class PageField {
|
|
|
159
181
|
}
|
|
160
182
|
let errors = [];
|
|
161
183
|
for (let i = 0, l = __classPrivateFieldGet(this, _PageField_validators, "f").length; i < l; i++) {
|
|
162
|
-
|
|
184
|
+
// ESLint disabled as `i` is an integer
|
|
185
|
+
/* eslint-disable security/detect-object-injection */
|
|
186
|
+
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 })));
|
|
187
|
+
/* eslint-enable security/detect-object-injection */
|
|
163
188
|
errors = [
|
|
164
189
|
...errors,
|
|
165
190
|
...(fieldErrors !== null && fieldErrors !== void 0 ? fieldErrors : []),
|
|
@@ -167,17 +192,27 @@ class PageField {
|
|
|
167
192
|
}
|
|
168
193
|
return errors;
|
|
169
194
|
}
|
|
170
|
-
|
|
195
|
+
/*
|
|
196
|
+
* Apply all the processors to the given value.
|
|
197
|
+
*
|
|
198
|
+
* @param {any} value Value to process
|
|
199
|
+
* @returns {any} Processed value
|
|
200
|
+
*/
|
|
171
201
|
applyProcessors(value) {
|
|
172
202
|
let processedValue = value;
|
|
173
203
|
// Some of the validators may have their own "sanitise()" methods. These
|
|
174
204
|
// should be run before any other processors
|
|
205
|
+
// ESLint disabled as `i` is an integer
|
|
206
|
+
/* eslint-disable security/detect-object-injection */
|
|
175
207
|
for (let i = 0, l = __classPrivateFieldGet(this, _PageField_validators, "f").length; i < l; i++) {
|
|
176
208
|
if (isFunction(__classPrivateFieldGet(this, _PageField_validators, "f")[i].sanitise)) {
|
|
177
209
|
processedValue = __classPrivateFieldGet(this, _PageField_validators, "f")[i].sanitise(processedValue);
|
|
178
210
|
}
|
|
179
211
|
}
|
|
212
|
+
/* eslint-enable security/detect-object-injection */
|
|
180
213
|
for (let i = 0, l = __classPrivateFieldGet(this, _PageField_processors, "f").length; i < l; i++) {
|
|
214
|
+
// ESLint disabled as `i` is an integer
|
|
215
|
+
/* eslint-disable-next-line security/detect-object-injection */
|
|
181
216
|
processedValue = __classPrivateFieldGet(this, _PageField_processors, "f")[i](processedValue);
|
|
182
217
|
}
|
|
183
218
|
return processedValue;
|
|
@@ -185,11 +220,11 @@ class PageField {
|
|
|
185
220
|
/**
|
|
186
221
|
* Apply all conditions to get the resulting boolean
|
|
187
222
|
*
|
|
188
|
-
* @param {
|
|
189
|
-
* @param {string} fieldValue Field value
|
|
190
|
-
* @param {string} waypoint Waypoint
|
|
191
|
-
* @param {object} journeyContext JourneyContext
|
|
192
|
-
* @returns {boolean}
|
|
223
|
+
* @param {object} params Parameters
|
|
224
|
+
* @param {string} params.fieldValue Field value
|
|
225
|
+
* @param {string} params.waypoint Waypoint
|
|
226
|
+
* @param {object} params.journeyContext JourneyContext
|
|
227
|
+
* @returns {boolean} True if all conditions pass
|
|
193
228
|
*/
|
|
194
229
|
testConditions({ fieldValue, waypoint, journeyContext }) {
|
|
195
230
|
const context = {
|
|
@@ -201,19 +236,21 @@ class PageField {
|
|
|
201
236
|
};
|
|
202
237
|
let result = true;
|
|
203
238
|
for (let i = 0, l = __classPrivateFieldGet(this, _PageField_conditions, "f").length; i < l; i++) {
|
|
239
|
+
// ESLint disabled as `i` is an integer
|
|
240
|
+
/* eslint-disable-next-line security/detect-object-injection */
|
|
204
241
|
result = result && __classPrivateFieldGet(this, _PageField_conditions, "f")[i](context);
|
|
205
242
|
}
|
|
206
243
|
return result;
|
|
207
244
|
}
|
|
208
245
|
/* ---------------------------------------------------------------- aliases */
|
|
209
|
-
validator(
|
|
210
|
-
return this.validators(
|
|
246
|
+
validator(validator) {
|
|
247
|
+
return this.validators([validator]);
|
|
211
248
|
}
|
|
212
|
-
processor(
|
|
213
|
-
return this.processors(
|
|
249
|
+
processor(processor) {
|
|
250
|
+
return this.processors([processor]);
|
|
214
251
|
}
|
|
215
|
-
condition(
|
|
216
|
-
return this.conditions(
|
|
252
|
+
condition(condition) {
|
|
253
|
+
return this.conditions([condition]);
|
|
217
254
|
}
|
|
218
255
|
if(...args) {
|
|
219
256
|
return this.conditions(...args);
|
|
@@ -221,3 +258,8 @@ class PageField {
|
|
|
221
258
|
}
|
|
222
259
|
exports.PageField = PageField;
|
|
223
260
|
_PageField_name = new WeakMap(), _PageField_processors = new WeakMap(), _PageField_validators = new WeakMap(), _PageField_conditions = new WeakMap(), _PageField_meta = new WeakMap();
|
|
261
|
+
// Factory for convenience
|
|
262
|
+
function field(...args) {
|
|
263
|
+
return new PageField(...args);
|
|
264
|
+
}
|
|
265
|
+
exports.default = field;
|
|
@@ -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
|
+
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export function mergeObjects(...objects: any[]): object;
|
|
2
2
|
export function includes(source?: any[], search?: string): boolean;
|
|
3
3
|
/**
|
|
4
|
-
* Format a given date.
|
|
5
|
-
*
|
|
6
|
-
* Requires NodeJS >= 14 to make use of bundled date locale data.
|
|
7
|
-
*
|
|
8
|
-
* `date` may be any of the following types:
|
|
9
|
-
* object - {dd:'', mm:'', yyyy:''}
|
|
10
|
-
*
|
|
11
|
-
* @param {object} date Date (see supported formats above)
|
|
12
|
-
* @param {object} config Holds locale
|
|
13
|
-
* @returns {string} Formatted date
|
|
14
|
-
*/
|
|
4
|
+
* Format a given date.
|
|
5
|
+
*
|
|
6
|
+
* Requires NodeJS >= 14 to make use of bundled date locale data.
|
|
7
|
+
*
|
|
8
|
+
* `date` may be any of the following types:
|
|
9
|
+
* object - {dd:'', mm:'', yyyy:''}
|
|
10
|
+
*
|
|
11
|
+
* @param {object} date Date (see supported formats above)
|
|
12
|
+
* @param {object} config Holds locale
|
|
13
|
+
* @returns {string} Formatted date
|
|
14
|
+
*/
|
|
15
15
|
export function formatDateObject(date: object, config?: object): string;
|
|
16
16
|
/**
|
|
17
17
|
* Attribute values will be HTML/attribute escaped.
|
|
@@ -1,37 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
4
|
};
|
|
24
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
6
|
exports.renderAsAttributes = exports.formatDateObject = exports.includes = exports.mergeObjects = void 0;
|
|
26
|
-
const deepmerge_1 =
|
|
7
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
27
8
|
const luxon_1 = require("luxon");
|
|
28
9
|
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
10
|
+
const { all: deepmergeAll } = deepmerge_1.default;
|
|
29
11
|
// Arrays will be merged such that elements at the same index will be merged
|
|
30
12
|
// into each other
|
|
31
13
|
// ref: https://www.npmjs.com/package/deepmerge
|
|
32
14
|
const combineMerge = (target, source, options) => {
|
|
33
15
|
const destination = target.slice();
|
|
34
16
|
source.forEach((item, index) => {
|
|
17
|
+
// ESLint disabled as `index` is only an integer
|
|
18
|
+
/* eslint-disable security/detect-object-injection */
|
|
35
19
|
if (typeof destination[index] === 'undefined') {
|
|
36
20
|
destination[index] = options.cloneUnlessOtherwiseSpecified(item, options);
|
|
37
21
|
}
|
|
@@ -41,31 +25,30 @@ const combineMerge = (target, source, options) => {
|
|
|
41
25
|
else if (target.indexOf(item) === -1) {
|
|
42
26
|
destination.push(item);
|
|
43
27
|
}
|
|
28
|
+
/* eslint-enable security/detect-object-injection */
|
|
44
29
|
});
|
|
45
30
|
return destination;
|
|
46
31
|
};
|
|
47
32
|
function mergeObjects(...objects) {
|
|
48
|
-
return (
|
|
33
|
+
return deepmergeAll([Object.create(null), ...objects], { arrayMerge: combineMerge });
|
|
49
34
|
}
|
|
50
35
|
exports.mergeObjects = mergeObjects;
|
|
51
|
-
;
|
|
52
36
|
function includes(source = [], search = '') {
|
|
53
37
|
return source.includes(search);
|
|
54
38
|
}
|
|
55
39
|
exports.includes = includes;
|
|
56
|
-
;
|
|
57
40
|
/**
|
|
58
|
-
* Format a given date.
|
|
59
|
-
*
|
|
60
|
-
* Requires NodeJS >= 14 to make use of bundled date locale data.
|
|
61
|
-
*
|
|
62
|
-
* `date` may be any of the following types:
|
|
63
|
-
* object - {dd:'', mm:'', yyyy:''}
|
|
64
|
-
*
|
|
65
|
-
* @param {object} date Date (see supported formats above)
|
|
66
|
-
* @param {object} config Holds locale
|
|
67
|
-
* @returns {string} Formatted date
|
|
68
|
-
*/
|
|
41
|
+
* Format a given date.
|
|
42
|
+
*
|
|
43
|
+
* Requires NodeJS >= 14 to make use of bundled date locale data.
|
|
44
|
+
*
|
|
45
|
+
* `date` may be any of the following types:
|
|
46
|
+
* object - {dd:'', mm:'', yyyy:''}
|
|
47
|
+
*
|
|
48
|
+
* @param {object} date Date (see supported formats above)
|
|
49
|
+
* @param {object} config Holds locale
|
|
50
|
+
* @returns {string} Formatted date
|
|
51
|
+
*/
|
|
69
52
|
function formatDateObject(date, config = {}) {
|
|
70
53
|
const { locale = 'en' } = config;
|
|
71
54
|
if (Object.prototype.toString.call(date) === '[object Object]'
|
|
@@ -81,7 +64,6 @@ function formatDateObject(date, config = {}) {
|
|
|
81
64
|
return 'INVALID DATE OBJECT';
|
|
82
65
|
}
|
|
83
66
|
exports.formatDateObject = formatDateObject;
|
|
84
|
-
;
|
|
85
67
|
/**
|
|
86
68
|
* Attribute values will be HTML/attribute escaped.
|
|
87
69
|
*
|
|
@@ -96,6 +78,10 @@ function renderAsAttributes(attrsObject) {
|
|
|
96
78
|
const attrsList = [];
|
|
97
79
|
if (typeof attrsObject === 'object') {
|
|
98
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 */
|
|
99
85
|
const value = String(attrsObject[key]).replace(/[<>"'&]/g, (m) => ({
|
|
100
86
|
'<': '<',
|
|
101
87
|
'>': '>',
|
|
@@ -103,10 +89,10 @@ function renderAsAttributes(attrsObject) {
|
|
|
103
89
|
'\'': ''',
|
|
104
90
|
'&': '&',
|
|
105
91
|
}[m]));
|
|
92
|
+
/* eslint-enable security/detect-object-injection */
|
|
106
93
|
attrsList.push(`${key}="${value}"`);
|
|
107
94
|
});
|
|
108
95
|
}
|
|
109
96
|
return new nunjucks_1.default.runtime.SafeString(attrsList.join(' '));
|
|
110
97
|
}
|
|
111
98
|
exports.renderAsAttributes = renderAsAttributes;
|
|
112
|
-
;
|
package/dist/lib/nunjucks.d.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @typedef {
|
|
3
|
-
* @property {string} [mountUrl=/] Mount URL
|
|
4
|
-
* @property {string[]} [views=[]]
|
|
2
|
+
* @typedef {object} NunjucksOptions
|
|
3
|
+
* @property {string} [mountUrl=/] Mount URL (optional, default /)
|
|
4
|
+
* @property {string[]} [views=[]] Template file directories (optional, default [])
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* Create a Nunjucks environment.
|
|
8
8
|
*
|
|
9
9
|
* @param {NunjucksOptions} options Nunjucks options
|
|
10
|
-
* @returns {
|
|
10
|
+
* @returns {Environment} Nunjucks Environment instance
|
|
11
11
|
*/
|
|
12
|
-
export default function
|
|
12
|
+
export default function nunjucksConfig({ mountUrl, views, }: NunjucksOptions): Environment;
|
|
13
13
|
export type NunjucksOptions = {
|
|
14
14
|
/**
|
|
15
15
|
* )
|
|
16
16
|
*/
|
|
17
17
|
mountUrl?: string | undefined;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Template file directories (optional, default [])
|
|
20
20
|
*/
|
|
21
21
|
views?: string[] | undefined;
|
|
22
22
|
};
|
|
23
|
+
import { Environment } from "nunjucks";
|
package/dist/lib/nunjucks.js
CHANGED
|
@@ -10,17 +10,17 @@ const dirname_cjs_1 = __importDefault(require("./dirname.cjs"));
|
|
|
10
10
|
const CasaTemplateLoader_js_1 = __importDefault(require("./CasaTemplateLoader.js"));
|
|
11
11
|
const nunjucks_filters_js_1 = require("./nunjucks-filters.js");
|
|
12
12
|
/**
|
|
13
|
-
* @typedef {
|
|
14
|
-
* @property {string} [mountUrl=/] Mount URL
|
|
15
|
-
* @property {string[]} [views=[]]
|
|
13
|
+
* @typedef {object} NunjucksOptions
|
|
14
|
+
* @property {string} [mountUrl=/] Mount URL (optional, default /)
|
|
15
|
+
* @property {string[]} [views=[]] Template file directories (optional, default [])
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
18
|
* Create a Nunjucks environment.
|
|
19
19
|
*
|
|
20
20
|
* @param {NunjucksOptions} options Nunjucks options
|
|
21
|
-
* @returns {
|
|
21
|
+
* @returns {Environment} Nunjucks Environment instance
|
|
22
22
|
*/
|
|
23
|
-
function
|
|
23
|
+
function nunjucksConfig({ mountUrl = '/', views = [], }) {
|
|
24
24
|
// Prepare a single Nunjucks environment for all responses to use. Note that
|
|
25
25
|
// we cannot prepare response-specific global functions/filters if we use a
|
|
26
26
|
// single environment, but the performance gains of doing so are significant.
|
|
@@ -46,4 +46,4 @@ function default_1({ mountUrl = '/', views = [], }) {
|
|
|
46
46
|
env.addGlobal('renderAsAttributes', nunjucks_filters_js_1.renderAsAttributes);
|
|
47
47
|
return env;
|
|
48
48
|
}
|
|
49
|
-
exports.default =
|
|
49
|
+
exports.default = nunjucksConfig;
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./configuration-ingestor').GlobalHook} GlobalHook
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('./configuration-ingestor').PageHook} PageHook
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {GlobalHook | PageHook} Hook
|
|
9
|
+
*/
|
|
1
10
|
/**
|
|
2
11
|
* Test is a value can be stringifed (numbers or strings)
|
|
3
12
|
*
|
|
@@ -20,3 +29,20 @@ export function stringifyInput(input: any, fallback: string, ...args: any[]): st
|
|
|
20
29
|
* @returns {boolean} True if the object is empty
|
|
21
30
|
*/
|
|
22
31
|
export function isEmpty(val: any): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Extract the middleware functions that are relevant for the given hook and
|
|
34
|
+
* path.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} hookName Hook name (including scope prefix)
|
|
37
|
+
* @param {string} path URL path to match (relative to mountUrl)
|
|
38
|
+
* @param {Hook[]} hooks Hooks to be applied at the page level
|
|
39
|
+
* @returns {Function[]} An array of middleware that should be applied
|
|
40
|
+
*/
|
|
41
|
+
export function resolveMiddlewareHooks(hookName: string, path: string, hooks?: Hook[]): Function[];
|
|
42
|
+
export function validateWaypoint(waypoint: any): void;
|
|
43
|
+
export function validateView(view: any): void;
|
|
44
|
+
export function validateHookName(hookName: any): void;
|
|
45
|
+
export function validateHookPath(path: any): void;
|
|
46
|
+
export type GlobalHook = import('./configuration-ingestor').GlobalHook;
|
|
47
|
+
export type PageHook = import('./configuration-ingestor').PageHook;
|
|
48
|
+
export type Hook = GlobalHook | PageHook;
|