@dwp/govuk-casa 8.15.0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -9
- package/dist/assets/css/casa.css +2 -1
- package/dist/assets/css/casa.css.map +1 -0
- package/dist/casa.d.ts +122 -99
- package/dist/casa.js +120 -88
- package/dist/casa.js.map +1 -1
- package/dist/lib/CasaTemplateLoader.d.ts +4 -4
- package/dist/lib/CasaTemplateLoader.js +16 -16
- package/dist/lib/CasaTemplateLoader.js.map +1 -1
- package/dist/lib/JourneyContext.d.ts +38 -40
- package/dist/lib/JourneyContext.js +89 -75
- package/dist/lib/JourneyContext.js.map +1 -1
- package/dist/lib/MutableRouter.d.ts +40 -41
- package/dist/lib/MutableRouter.js +64 -71
- package/dist/lib/MutableRouter.js.map +1 -1
- package/dist/lib/Plan.d.ts +29 -26
- package/dist/lib/Plan.js +85 -71
- package/dist/lib/Plan.js.map +1 -1
- package/dist/lib/ValidationError.d.ts +16 -15
- package/dist/lib/ValidationError.js +21 -20
- package/dist/lib/ValidationError.js.map +1 -1
- package/dist/lib/ValidatorFactory.d.ts +15 -13
- package/dist/lib/ValidatorFactory.js +14 -12
- package/dist/lib/ValidatorFactory.js.map +1 -1
- package/dist/lib/configuration-ingestor.d.ts +37 -40
- package/dist/lib/configuration-ingestor.js +93 -93
- package/dist/lib/configuration-ingestor.js.map +1 -1
- package/dist/lib/configure.d.ts +6 -6
- package/dist/lib/configure.js +14 -12
- package/dist/lib/configure.js.map +1 -1
- package/dist/lib/constants.d.ts +1 -3
- package/dist/lib/constants.js +9 -11
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/context-id-generators.d.ts +3 -5
- package/dist/lib/context-id-generators.js +7 -6
- package/dist/lib/context-id-generators.js.map +1 -1
- package/dist/lib/end-session.d.ts +4 -4
- package/dist/lib/end-session.js +5 -5
- package/dist/lib/field.d.ts +24 -29
- package/dist/lib/field.js +41 -70
- package/dist/lib/field.js.map +1 -1
- package/dist/lib/index.d.ts +13 -13
- package/dist/lib/logger.d.ts +7 -6
- package/dist/lib/logger.js +7 -7
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/mount.d.ts +5 -5
- package/dist/lib/mount.js +12 -17
- package/dist/lib/mount.js.map +1 -1
- package/dist/lib/nunjucks-filters.d.ts +10 -12
- package/dist/lib/nunjucks-filters.js +35 -35
- package/dist/lib/nunjucks-filters.js.map +1 -1
- package/dist/lib/nunjucks.d.ts +7 -5
- package/dist/lib/nunjucks.js +10 -8
- package/dist/lib/nunjucks.js.map +1 -1
- package/dist/lib/utils.d.ts +19 -19
- package/dist/lib/utils.js +62 -55
- package/dist/lib/utils.js.map +1 -1
- package/dist/lib/validators/dateObject.d.ts +29 -22
- package/dist/lib/validators/dateObject.js +58 -49
- package/dist/lib/validators/dateObject.js.map +1 -1
- package/dist/lib/validators/email.d.ts +4 -4
- package/dist/lib/validators/email.js +4 -4
- package/dist/lib/validators/inArray.d.ts +4 -4
- package/dist/lib/validators/inArray.js +7 -8
- package/dist/lib/validators/inArray.js.map +1 -1
- package/dist/lib/validators/index.d.ts +10 -10
- package/dist/lib/validators/index.js +1 -3
- package/dist/lib/validators/index.js.map +1 -1
- package/dist/lib/validators/nino.d.ts +9 -8
- package/dist/lib/validators/nino.js +14 -10
- package/dist/lib/validators/nino.js.map +1 -1
- package/dist/lib/validators/postalAddressObject.d.ts +37 -24
- package/dist/lib/validators/postalAddressObject.js +65 -46
- package/dist/lib/validators/postalAddressObject.js.map +1 -1
- package/dist/lib/validators/range.d.ts +12 -8
- package/dist/lib/validators/range.js +11 -9
- package/dist/lib/validators/range.js.map +1 -1
- package/dist/lib/validators/regex.d.ts +4 -4
- package/dist/lib/validators/regex.js +5 -5
- package/dist/lib/validators/required.d.ts +6 -6
- package/dist/lib/validators/required.js +9 -11
- package/dist/lib/validators/required.js.map +1 -1
- package/dist/lib/validators/strlen.d.ts +12 -8
- package/dist/lib/validators/strlen.js +13 -11
- package/dist/lib/validators/strlen.js.map +1 -1
- package/dist/lib/validators/wordCount.d.ts +12 -8
- package/dist/lib/validators/wordCount.js +15 -11
- package/dist/lib/validators/wordCount.js.map +1 -1
- package/dist/lib/waypoint-url.d.ts +16 -13
- package/dist/lib/waypoint-url.js +39 -36
- package/dist/lib/waypoint-url.js.map +1 -1
- package/dist/middleware/body-parser.d.ts +1 -1
- package/dist/middleware/body-parser.js +6 -6
- package/dist/middleware/body-parser.js.map +1 -1
- package/dist/middleware/data.d.ts +1 -1
- package/dist/middleware/data.js +8 -7
- package/dist/middleware/data.js.map +1 -1
- package/dist/middleware/gather-fields.d.ts +2 -2
- package/dist/middleware/gather-fields.js +6 -4
- package/dist/middleware/gather-fields.js.map +1 -1
- package/dist/middleware/i18n.js +13 -15
- package/dist/middleware/i18n.js.map +1 -1
- package/dist/middleware/post.js +30 -18
- package/dist/middleware/post.js.map +1 -1
- package/dist/middleware/pre.d.ts +2 -2
- package/dist/middleware/pre.js +46 -26
- package/dist/middleware/pre.js.map +1 -1
- package/dist/middleware/progress-journey.d.ts +1 -1
- package/dist/middleware/progress-journey.js +5 -5
- package/dist/middleware/progress-journey.js.map +1 -1
- package/dist/middleware/sanitise-fields.d.ts +1 -1
- package/dist/middleware/sanitise-fields.js +13 -11
- package/dist/middleware/sanitise-fields.js.map +1 -1
- package/dist/middleware/serve-first-waypoint.d.ts +3 -3
- package/dist/middleware/serve-first-waypoint.js +8 -6
- package/dist/middleware/serve-first-waypoint.js.map +1 -1
- package/dist/middleware/session.js +14 -11
- package/dist/middleware/session.js.map +1 -1
- package/dist/middleware/skip-waypoint.d.ts +1 -1
- package/dist/middleware/skip-waypoint.js +3 -3
- package/dist/middleware/skip-waypoint.js.map +1 -1
- package/dist/middleware/steer-journey.d.ts +1 -1
- package/dist/middleware/steer-journey.js +16 -14
- package/dist/middleware/steer-journey.js.map +1 -1
- package/dist/middleware/strip-proxy-path.d.ts +1 -1
- package/dist/middleware/strip-proxy-path.js +3 -3
- package/dist/middleware/strip-proxy-path.js.map +1 -1
- package/dist/middleware/validate-fields.d.ts +1 -1
- package/dist/middleware/validate-fields.js +2 -5
- package/dist/middleware/validate-fields.js.map +1 -1
- package/dist/routes/ancillary.d.ts +3 -3
- package/dist/routes/ancillary.js +4 -4
- package/dist/routes/ancillary.js.map +1 -1
- package/dist/routes/journey.d.ts +2 -2
- package/dist/routes/journey.js +91 -39
- package/dist/routes/journey.js.map +1 -1
- package/dist/routes/static.d.ts +7 -5
- package/dist/routes/static.js +20 -20
- package/dist/routes/static.js.map +1 -1
- package/package.json +17 -16
- package/src/casa.js +134 -102
- package/src/lib/CasaTemplateLoader.js +24 -19
- package/src/lib/JourneyContext.js +147 -107
- package/src/lib/MutableRouter.js +72 -74
- package/src/lib/Plan.js +145 -97
- package/src/lib/ValidationError.js +25 -21
- package/src/lib/ValidatorFactory.js +17 -13
- package/src/lib/configuration-ingestor.js +147 -110
- package/src/lib/configure.js +34 -32
- package/src/lib/constants.js +9 -11
- package/src/lib/context-id-generators.js +40 -43
- package/src/lib/end-session.js +6 -6
- package/src/lib/field.js +74 -78
- package/src/lib/index.js +12 -12
- package/src/lib/logger.js +9 -9
- package/src/lib/mount.js +70 -80
- package/src/lib/nunjucks-filters.js +56 -59
- package/src/lib/nunjucks.js +23 -18
- package/src/lib/utils.js +78 -57
- package/src/lib/validators/dateObject.js +71 -60
- package/src/lib/validators/email.js +8 -8
- package/src/lib/validators/inArray.js +10 -11
- package/src/lib/validators/index.js +12 -14
- package/src/lib/validators/nino.js +29 -15
- package/src/lib/validators/postalAddressObject.js +87 -63
- package/src/lib/validators/range.js +14 -12
- package/src/lib/validators/regex.js +8 -8
- package/src/lib/validators/required.js +16 -16
- package/src/lib/validators/strlen.js +16 -14
- package/src/lib/validators/wordCount.js +22 -14
- package/src/lib/waypoint-url.js +64 -46
- package/src/middleware/body-parser.js +10 -10
- package/src/middleware/csrf.js +1 -1
- package/src/middleware/data.js +28 -24
- package/src/middleware/gather-fields.js +10 -9
- package/src/middleware/i18n.js +35 -37
- package/src/middleware/post.js +41 -21
- package/src/middleware/pre.js +62 -40
- package/src/middleware/progress-journey.js +32 -18
- package/src/middleware/sanitise-fields.js +43 -20
- package/src/middleware/serve-first-waypoint.js +14 -12
- package/src/middleware/session.js +74 -61
- package/src/middleware/skip-waypoint.js +7 -9
- package/src/middleware/steer-journey.js +40 -28
- package/src/middleware/strip-proxy-path.js +8 -7
- package/src/middleware/validate-fields.js +5 -12
- package/src/routes/ancillary.js +5 -7
- package/src/routes/journey.js +159 -85
- package/src/routes/static.js +62 -30
- package/views/casa/components/character-count/README.md +2 -2
- package/views/casa/components/checkboxes/README.md +6 -6
- package/views/casa/components/date-input/README.md +7 -7
- package/views/casa/components/input/README.md +2 -2
- package/views/casa/components/journey-form/README.md +33 -14
- package/views/casa/components/postal-address-object/README.md +4 -4
- package/views/casa/components/radios/README.md +6 -6
- package/views/casa/components/select/README.md +6 -6
- package/views/casa/components/textarea/README.md +2 -2
- package/views/casa/partials/scripts.njk +5 -3
- package/views/casa/partials/styles.njk +1 -4
- package/dist/assets/css/casa-ie8.css +0 -1
package/dist/casa.js
CHANGED
|
@@ -56,9 +56,7 @@ const contextIdGenerators = __importStar(require("./lib/context-id-generators.js
|
|
|
56
56
|
exports.contextIdGenerators = contextIdGenerators;
|
|
57
57
|
/* ----------------------------------------------------------------- Typedefs */
|
|
58
58
|
// These exist here so that consumer can import CASA's internal types
|
|
59
|
-
/**
|
|
60
|
-
* @typedef {import('./lib/field').PageField} PageField
|
|
61
|
-
*/
|
|
59
|
+
/** @typedef {import("./lib/field").PageField} PageField */
|
|
62
60
|
/**
|
|
63
61
|
* @typedef {object} ContextEventHandlerOptions
|
|
64
62
|
* @property {JourneyContext} journeyContext Context including changes
|
|
@@ -73,7 +71,8 @@ exports.contextIdGenerators = contextIdGenerators;
|
|
|
73
71
|
*/
|
|
74
72
|
/**
|
|
75
73
|
* @typedef {object} ContextEventUserInfo
|
|
76
|
-
* @property {symbol} [casaRequestPhase] Request phase at which event is
|
|
74
|
+
* @property {symbol} [casaRequestPhase] Request phase at which event is
|
|
75
|
+
* triggered
|
|
77
76
|
*/
|
|
78
77
|
/**
|
|
79
78
|
* @typedef {object} ContextEvent
|
|
@@ -82,43 +81,53 @@ exports.contextIdGenerators = contextIdGenerators;
|
|
|
82
81
|
* @property {ContextEventHandler} handler Handler to invoke when change happens
|
|
83
82
|
*/
|
|
84
83
|
/**
|
|
85
|
-
* @typedef {object} Page Page configuration. A Page is the interactive
|
|
84
|
+
* @typedef {object} Page Page configuration. A Page is the interactive
|
|
85
|
+
* representation of a waypoint
|
|
86
86
|
* @property {string} waypoint The waypoint with which this page is associated
|
|
87
87
|
* @property {string} view Template path
|
|
88
|
-
* @property {PageHook[]} [hooks=[]] Page-specific hooks (optional, default [])
|
|
89
|
-
*
|
|
88
|
+
* @property {PageHook[]} [hooks=[]] Page-specific hooks (optional, default []).
|
|
89
|
+
* Default is `[]`
|
|
90
|
+
* @property {PageField[]} [fields=[]] Fields to be managed on this page
|
|
91
|
+
* (optional, default []). Default is `[]`
|
|
90
92
|
*/
|
|
91
93
|
/**
|
|
92
94
|
* @typedef {object} I18nOptions
|
|
93
95
|
* @property {string[]} dirs Directories to search for locale dictionaries
|
|
94
|
-
* @property {string[]} [locales=['en', 'cy']] Supported locales
|
|
96
|
+
* @property {string[]} [locales=['en', 'cy']] Supported locales. Default is
|
|
97
|
+
* `['en', 'cy']`
|
|
95
98
|
*/
|
|
96
99
|
/**
|
|
97
100
|
* @typedef {object} GlobalHook Hook configuration
|
|
98
101
|
* @property {string} hook Hook name in format `<router>.<hook>`
|
|
99
|
-
* @property {Function} middleware Middleware function to insert at the hook
|
|
100
|
-
*
|
|
102
|
+
* @property {Function} middleware Middleware function to insert at the hook
|
|
103
|
+
* point
|
|
104
|
+
* @property {string | RegExp} [path=undefined] Only run if route path matches
|
|
105
|
+
* this string/regexp. Default is `undefined`
|
|
101
106
|
*/
|
|
102
107
|
/**
|
|
103
108
|
* @typedef {object} PageHook (extends GlobalHook)
|
|
104
109
|
* @property {string} hook Hook name (without a scope prefix)
|
|
105
|
-
* @property {Function} middleware Middleware function to insert at the hook
|
|
110
|
+
* @property {Function} middleware Middleware function to insert at the hook
|
|
111
|
+
* point
|
|
106
112
|
*/
|
|
107
113
|
/**
|
|
108
114
|
* @typedef {object} SessionOptions
|
|
109
|
-
* @property {string} [name=casasession] Session name
|
|
110
|
-
* @property {string} [secret=secret] Encryption secret
|
|
111
|
-
* @property {number} [ttl=3600] Session ttl (seconds)
|
|
112
|
-
* @property {boolean} [secure=false] Whether to use secure session cookies
|
|
113
|
-
*
|
|
115
|
+
* @property {string} [name=casasession] Session name. Default is `casasession`
|
|
116
|
+
* @property {string} [secret=secret] Encryption secret. Default is `secret`
|
|
117
|
+
* @property {number} [ttl=3600] Session ttl (seconds). Default is `3600`
|
|
118
|
+
* @property {boolean} [secure=false] Whether to use secure session cookies.
|
|
119
|
+
* Default is `false`
|
|
120
|
+
* @property {boolean | string} [cookieSameSite=true] SameSite (true = Strict).
|
|
121
|
+
* Default is `true`
|
|
114
122
|
* @property {object} [store] Session store (default MemoryStore)
|
|
115
|
-
* @property {string} [cookiePath]
|
|
116
|
-
*
|
|
123
|
+
* @property {string} [cookiePath] The URL path on which the session cookie is
|
|
124
|
+
* valid (defaults to '/')
|
|
117
125
|
*/
|
|
118
126
|
/**
|
|
119
127
|
* @typedef {object} IPlugin Plugin interface
|
|
120
128
|
* @property {PluginConfigureFunction} [configure] Modify the app config
|
|
121
|
-
* @property {PluginBootstrapFunction} [bootstrap] Modify post-configuration
|
|
129
|
+
* @property {PluginBootstrapFunction} [bootstrap] Modify post-configuration
|
|
130
|
+
* artifacts
|
|
122
131
|
*/
|
|
123
132
|
/**
|
|
124
133
|
* @callback PluginConfigureFunction
|
|
@@ -136,91 +145,104 @@ exports.contextIdGenerators = contextIdGenerators;
|
|
|
136
145
|
/**
|
|
137
146
|
* Mounting function.
|
|
138
147
|
*
|
|
139
|
-
* This will mount all of the routes and middleware in the correct order on
|
|
140
|
-
*
|
|
148
|
+
* This will mount all of the routes and middleware in the correct order on the
|
|
149
|
+
* given ExpressJS app.
|
|
141
150
|
*
|
|
142
151
|
* Once this is called, you will not be able to modify any of the routers as
|
|
143
152
|
* they will be "sealed".
|
|
144
153
|
*
|
|
145
154
|
* @callback Mounter
|
|
146
|
-
* @param {import(
|
|
155
|
+
* @param {import("express").Express} app Express application
|
|
147
156
|
* @param {object} opts Mounting options
|
|
148
|
-
* @param {string} [opts.route='/'] Optional route to attach all
|
|
149
|
-
*
|
|
157
|
+
* @param {string} [opts.route='/'] Optional route to attach all
|
|
158
|
+
* middleware/routers too. Default is `'/'`
|
|
159
|
+
* @returns {import("express").Express} The prepared ExpressJS app instance
|
|
150
160
|
*/
|
|
151
161
|
/**
|
|
152
162
|
* Configure some middleware for use in creating a new CASA app.
|
|
153
163
|
*
|
|
154
164
|
* @typedef {object} ConfigurationOptions Configuration options
|
|
155
165
|
* @property {string} [mountUrl] Prefix for all URLS in browser address bar
|
|
156
|
-
* @property {string[]} [views=[]] Template directories
|
|
166
|
+
* @property {string[]} [views=[]] Template directories. Default is `[]`
|
|
157
167
|
* @property {SessionOptions} [session] Session configuration
|
|
158
|
-
* @property {Page[]} [pages=[]] Pages the represent waypoints
|
|
159
|
-
* @property {GlobalHook[]} [hooks=[]] Hooks to apply
|
|
160
|
-
* @property {IPlugin[]} [plugins=[]] Plugins
|
|
168
|
+
* @property {Page[]} [pages=[]] Pages the represent waypoints. Default is `[]`
|
|
169
|
+
* @property {GlobalHook[]} [hooks=[]] Hooks to apply. Default is `[]`
|
|
170
|
+
* @property {IPlugin[]} [plugins=[]] Plugins. Default is `[]`
|
|
161
171
|
* @property {I18nOptions} [i18n] I18n configuration
|
|
162
172
|
* @property {Plan} [plan] CASA Plan
|
|
163
|
-
* @property {ContextEvent[]} [events=[]] Handlers for JourneyContext events
|
|
164
|
-
*
|
|
165
|
-
* @property {
|
|
166
|
-
*
|
|
167
|
-
* @property {
|
|
168
|
-
*
|
|
173
|
+
* @property {ContextEvent[]} [events=[]] Handlers for JourneyContext events.
|
|
174
|
+
* Default is `[]`
|
|
175
|
+
* @property {HelmetConfigurator} [helmetConfigurator] Helmet configuration
|
|
176
|
+
* manipulator function
|
|
177
|
+
* @property {number} [formMaxParams=25] Max number of form parameters to
|
|
178
|
+
* ingest. Default is `25`
|
|
179
|
+
* @property {number | string} [formMaxBytes="50KB"] Max total form payload size
|
|
180
|
+
* to ingest. Default is `"50KB"`
|
|
181
|
+
* @property {ContextIdGenerator} [contextIdGenerator] Custom context ID
|
|
182
|
+
* generator
|
|
183
|
+
* @property {symbol | Function} [errorVisibility] Option to keep page errors
|
|
184
|
+
* active on GET request
|
|
169
185
|
*/
|
|
170
186
|
/**
|
|
171
187
|
* @typedef {object} ConfigureResult Result of a call to configure() function
|
|
172
|
-
* @property {import(
|
|
188
|
+
* @property {import("nunjucks").Environment} nunjucksEnv Nunjucks environment
|
|
173
189
|
* @property {MutableRouter} staticRouter Router handling all static assets
|
|
174
190
|
* @property {MutableRouter} ancillaryRouter Router handling ancillary routes
|
|
175
191
|
* @property {MutableRouter} journeyRouter Router handling all waypoint requests
|
|
176
|
-
* @property {import(
|
|
177
|
-
*
|
|
178
|
-
* @property {import(
|
|
179
|
-
*
|
|
180
|
-
* @property {import(
|
|
181
|
-
*
|
|
182
|
-
* @property {import(
|
|
183
|
-
*
|
|
184
|
-
* @property {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
192
|
+
* @property {import("express").RequestHandler[]} preMiddleware Middleware
|
|
193
|
+
* mounted before everything
|
|
194
|
+
* @property {import("express").RequestHandler[]} postMiddleware Middleware
|
|
195
|
+
* mounted after everything
|
|
196
|
+
* @property {import("express").RequestHandler[]} csrfMiddleware CSRF get/set
|
|
197
|
+
* form middleware
|
|
198
|
+
* @property {import("express").RequestHandler} sessionMiddleware Session
|
|
199
|
+
* middleware
|
|
200
|
+
* @property {import("express").RequestHandler[]} cookieParserMiddleware
|
|
201
|
+
* Cookie-parsing middleware
|
|
202
|
+
* @property {import("express").RequestHandler[]} i18nMiddleware I18n
|
|
203
|
+
* preparation middleware
|
|
204
|
+
* @property {import("express").RequestHandler} bodyParserMiddleware Body
|
|
205
|
+
* parsing middleware
|
|
206
|
+
* @property {Mounter} mount Function used to mount all CASA artifacts onto an
|
|
207
|
+
* ExpressJS app
|
|
208
|
+
* @property {ConfigurationOptions} config Ingested config supplied to
|
|
209
|
+
* `configure()`
|
|
210
|
+
*/
|
|
211
|
+
/**
|
|
212
|
+
* Configuration for generating a ValidationError. i.e. `new
|
|
213
|
+
* ValidationError(configObject)` <br/><br/>
|
|
190
214
|
*
|
|
191
|
-
* The `fieldKeySuffix` is used to differentiate errors attached to
|
|
192
|
-
*
|
|
215
|
+
* The `fieldKeySuffix` is used to differentiate errors attached to the same
|
|
216
|
+
* field name. For example, given these fields inputs ...<pre> <input
|
|
217
|
+
* name="dateOfBirth[dd]" /> <input name="dateOfBirth[mm]" /> <input
|
|
218
|
+
* name="dateOfBirth[yyyy]" /> </pre>
|
|
193
219
|
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* <input name="dateOfBirth[mm]" />
|
|
197
|
-
* <input name="dateOfBirth[yyyy]" />
|
|
198
|
-
* </pre>
|
|
220
|
+
* If we wanted to generate an error specifically for the `dd` element, then
|
|
221
|
+
* we'd include `{ fieldKeySuffix: '[dd]' }` in this config. <br/><br/>
|
|
199
222
|
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
223
|
+
* We can also use `focusSuffix` to control which properties of an object field
|
|
224
|
+
* should be highlighted with a red border when in error. Looking again at the
|
|
225
|
+
* `dateOfBirth` example above, if we did not specify any `focusSuffix`, then
|
|
226
|
+
* all three inputs would be highlighted. However, if we use `{ focusSuffix:
|
|
227
|
+
* ['[dd]', '[yyyy]'] }` then only the `[dd]` and `[yyyy]` inputs would be
|
|
228
|
+
* highlighted. <br/><br/>
|
|
204
229
|
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* again at the `dateOfBirth` example above, if we did not specify
|
|
208
|
-
* any `focusSuffix`, then all three inputs would be highlighted.
|
|
209
|
-
* However, if we use `{ focusSuffix: ['[dd]', '[yyyy]'] }` then only
|
|
210
|
-
* the `[dd]` and `[yyyy]` inputs would be highlighted.
|
|
211
|
-
* <br/><br/>
|
|
212
|
-
*
|
|
213
|
-
* The `fieldHref` and `field` properties are strictly for
|
|
214
|
-
* internal use only and public access may be removed at any point.
|
|
230
|
+
* The `fieldHref` and `field` properties are strictly for internal use only and
|
|
231
|
+
* public access may be removed at any point.
|
|
215
232
|
*
|
|
216
233
|
* @typedef {object} ErrorMessageConfigObject
|
|
217
234
|
* @property {string} summary Summary message
|
|
218
|
-
* @property {string} [inline] Inline message (@deprecated now uses summary
|
|
219
|
-
*
|
|
220
|
-
* @property {string} [
|
|
221
|
-
*
|
|
235
|
+
* @property {string} [inline] Inline message (@deprecated now uses summary
|
|
236
|
+
* everywhere)
|
|
237
|
+
* @property {string | string[]} [focusSuffix] String(s) to append to URL hash
|
|
238
|
+
* for focusing inputs
|
|
239
|
+
* @property {string} [fieldKeySuffix] Object fields may use this to show errors
|
|
240
|
+
* per sub-property
|
|
241
|
+
* @property {object | ErrorMessageVariablesGenerator} [variables]
|
|
242
|
+
* Interpolation variables
|
|
222
243
|
* @property {string} [validator] Name of the validator
|
|
223
|
-
* @property {string} [fieldHref] (internal) URL hash to link to field in UI,
|
|
244
|
+
* @property {string} [fieldHref] (internal) URL hash to link to field in UI,
|
|
245
|
+
* i.e `#f-..`
|
|
224
246
|
* @property {string} [field] (internal) Field name, including any focus suffix
|
|
225
247
|
*/
|
|
226
248
|
/**
|
|
@@ -234,10 +256,13 @@ exports.contextIdGenerators = contextIdGenerators;
|
|
|
234
256
|
/**
|
|
235
257
|
* @callback ErrorMessageConfigGenerator
|
|
236
258
|
* @param {ValidateContext} dataContext Data context
|
|
237
|
-
* @returns {string|ErrorMessageConfigObject} Compiled error message config
|
|
259
|
+
* @returns {string | ErrorMessageConfigObject} Compiled error message config
|
|
238
260
|
*/
|
|
239
261
|
/**
|
|
240
|
-
* @typedef {string
|
|
262
|
+
* @typedef {string
|
|
263
|
+
* | ErrorMessageConfigObject
|
|
264
|
+
* | ErrorMessageConfigGenerator
|
|
265
|
+
* | Error} ErrorMessageConfig
|
|
241
266
|
*/
|
|
242
267
|
/**
|
|
243
268
|
* @typedef {object} ValidateContext Context passed to validate function
|
|
@@ -250,7 +275,7 @@ exports.contextIdGenerators = contextIdGenerators;
|
|
|
250
275
|
/**
|
|
251
276
|
* @callback ValidateFunction
|
|
252
277
|
* @param {any} value
|
|
253
|
-
* @param {ValidateContext} context
|
|
278
|
+
* @param {ValidateContext} context Validation context
|
|
254
279
|
* @returns {ValidationError[]}
|
|
255
280
|
*/
|
|
256
281
|
/**
|
|
@@ -261,7 +286,8 @@ exports.contextIdGenerators = contextIdGenerators;
|
|
|
261
286
|
/**
|
|
262
287
|
* @typedef {object} Validator
|
|
263
288
|
* @property {ValidateFunction} validate Validation function
|
|
264
|
-
* @property {FieldProcessorFunction} sanitise Sanitise a given value prior to
|
|
289
|
+
* @property {FieldProcessorFunction} sanitise Sanitise a given value prior to
|
|
290
|
+
* validation
|
|
265
291
|
* @property {object} config Configuration
|
|
266
292
|
* @property {string} name Validator name
|
|
267
293
|
*/
|
|
@@ -270,7 +296,6 @@ exports.contextIdGenerators = contextIdGenerators;
|
|
|
270
296
|
* @property {string} fieldName Field name
|
|
271
297
|
* @property {any} fieldValue Field value
|
|
272
298
|
* @property {string} waypoint Waypoint
|
|
273
|
-
* @property {string} waypointId [DEPRECATED] Waypoint (for backwards compatibility with v7)
|
|
274
299
|
* @property {JourneyContext} journeyContext Journey Context
|
|
275
300
|
*/
|
|
276
301
|
/**
|
|
@@ -295,26 +320,31 @@ exports.contextIdGenerators = contextIdGenerators;
|
|
|
295
320
|
*/
|
|
296
321
|
/**
|
|
297
322
|
* @typedef PlanTraverseOptions
|
|
298
|
-
* @property {string} [startWaypoint] Waypoint from which to start (defaults to
|
|
323
|
+
* @property {string} [startWaypoint] Waypoint from which to start (defaults to
|
|
324
|
+
* first in list)
|
|
299
325
|
* @property {string} routeName Follow routes matching this name (next | prev)
|
|
300
326
|
* @property {Map} history Used to detect loops in traversal (INTERNAL USE ONLY)
|
|
301
|
-
* @property {Function} [stopCondition] If true, traversal will be stopped
|
|
302
|
-
*
|
|
327
|
+
* @property {Function} [stopCondition] If true, traversal will be stopped
|
|
328
|
+
* (useful for performance)
|
|
329
|
+
* @property {string | PlanArbiter} [arbiter] Multiple target routes found, this
|
|
330
|
+
* decides which to use
|
|
303
331
|
*/
|
|
304
332
|
/**
|
|
305
333
|
* @typedef {object} PlanArbiterParams
|
|
306
334
|
* @property {PlanRoute[]} targets Potential target routes that need arbitration
|
|
307
335
|
* @property {JourneyContext} journeyContext Journey Context
|
|
308
|
-
* @property {PlanTraverseOptions} traverseOptions Original traverse options
|
|
336
|
+
* @property {PlanTraverseOptions} traverseOptions Original traverse options
|
|
337
|
+
* passed to `traverse()`
|
|
309
338
|
*/
|
|
310
339
|
/**
|
|
311
340
|
* @callback PlanArbiter
|
|
312
341
|
* @param {PlanArbiterParams} route Route metadata
|
|
313
|
-
* @returns {PlanRoute[]} Returns all routes, excluding those that the arbiter
|
|
342
|
+
* @returns {PlanRoute[]} Returns all routes, excluding those that the arbiter
|
|
343
|
+
* could eliminate
|
|
314
344
|
*/
|
|
315
345
|
/**
|
|
316
346
|
* @typedef {object} JourneyContextObject Journey Context Object
|
|
317
|
-
* @property {Record<string,any>} [data] Data
|
|
347
|
+
* @property {Record<string, any>} [data] Data
|
|
318
348
|
* @property {any} [validation] Validation state
|
|
319
349
|
* @property {any} [nav] Navigation meta
|
|
320
350
|
* @property {any} [identity] Identity meta
|
|
@@ -322,14 +352,16 @@ exports.contextIdGenerators = contextIdGenerators;
|
|
|
322
352
|
/**
|
|
323
353
|
* @typedef ContextIdGeneratorParams
|
|
324
354
|
* @property {object} args Arguments
|
|
325
|
-
* @property {import(
|
|
326
|
-
* @property {[string]} args.reservedIds List of IDs already in use in session
|
|
355
|
+
* @property {import("express").Request} args.req Request
|
|
356
|
+
* @property {[string]} args.reservedIds List of IDs already in use in session
|
|
357
|
+
* or request
|
|
327
358
|
*/
|
|
328
359
|
/**
|
|
329
360
|
* Generates a GUID for use as a journey context ID. This ID must not clash with
|
|
330
361
|
* any other context IDs in the given session.
|
|
331
362
|
*
|
|
332
363
|
* The resulting ID must match these criteria:
|
|
364
|
+
*
|
|
333
365
|
* - A string
|
|
334
366
|
* - Between 1 and 64 characters
|
|
335
367
|
* - Contain only the characters a-z, 0-9, -
|
package/dist/casa.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"casa.js","sourceRoot":"","sources":["../src/casa.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4EAA4E;AAC5E,sEAA2C;AAgBzC,oBAhBK,sBAAS,CAgBL;AAfX,yEAAmD;AAgBjD,qBAhBK,kBAAU,CAgBL;AAfZ,8DAAmC;AAgBjC,gBAhBK,kBAAK,CAgBL;AAfP,4DAAiC;AAgB/B,eAhBK,iBAAI,CAgBL;AAfN,gFAAqD;AAgBnD,yBAhBK,2BAAc,CAgBL;AAfhB,oFAAyD;AAgBvD,2BAhBK,6BAAgB,CAgBL;AAflB,kFAAuD;AAgBrD,0BAhBK,4BAAe,CAgBL;AAfjB,8EAAmD;AAgBjD,wBAhBK,0BAAa,CAgBL;AAff,4EAAgD;AAkB9C,sBAlBK,yBAAW,CAkBL;AAjBb,0EAA8C;AAkB5C,qBAlBK,wBAAU,CAkBL;AAjBZ,2EAA6D;AAoB3D,0CAAe;AAnBjB,8DAAgD;AAsB9C,8BAAS;AArBX,oFAAsE;AAwBpE,kDAAmB;AAGrB,gFAAgF;AAChF,qEAAqE;AAErE
|
|
1
|
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;;;;;;GAMG;AAEH;;;;;;GAMG;AAEH;;;;;;GAMG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;GAUG;AAEH;;;;;;GAMG;AAEH;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;;;GAaG"}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* @returns {string} The modified template source
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
|
-
* @access private
|
|
8
7
|
* @augments FileSystemLoader
|
|
8
|
+
* @access private
|
|
9
9
|
*/
|
|
10
10
|
export default class CasaTemplateLoader extends FileSystemLoader {
|
|
11
11
|
/**
|
|
@@ -26,7 +26,7 @@ export default class CasaTemplateLoader extends FileSystemLoader {
|
|
|
26
26
|
modifyBlock(block: string, modifier: BlockModifier): void;
|
|
27
27
|
#private;
|
|
28
28
|
}
|
|
29
|
-
export type FileSystemLoaderOptions = import(
|
|
30
|
-
export type LoaderSource = import(
|
|
29
|
+
export type FileSystemLoaderOptions = import("nunjucks").FileSystemLoaderOptions;
|
|
30
|
+
export type LoaderSource = import("nunjucks").LoaderSource;
|
|
31
31
|
export type BlockModifier = (templateName: string) => string;
|
|
32
|
-
import { FileSystemLoader } from
|
|
32
|
+
import { FileSystemLoader } from "nunjucks";
|
|
@@ -14,27 +14,27 @@ var _CasaTemplateLoader_instances, _CasaTemplateLoader_blockModifiers, _CasaTemp
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const nunjucks_1 = require("nunjucks");
|
|
16
16
|
/**
|
|
17
|
+
* @typedef {import("nunjucks").FileSystemLoaderOptions} FileSystemLoaderOptions
|
|
17
18
|
* @access private
|
|
18
|
-
* @typedef {import('nunjucks').FileSystemLoaderOptions} FileSystemLoaderOptions
|
|
19
19
|
*/
|
|
20
20
|
/**
|
|
21
|
+
* @typedef {import("nunjucks").LoaderSource} LoaderSource
|
|
21
22
|
* @access private
|
|
22
|
-
* @typedef {import('nunjucks').LoaderSource} LoaderSource
|
|
23
23
|
*/
|
|
24
24
|
const VALID_BLOCKS = [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
"beforeContent",
|
|
26
|
+
"bodyEnd",
|
|
27
|
+
"bodyStart",
|
|
28
|
+
"casaPageTitle",
|
|
29
|
+
"content",
|
|
30
|
+
"footer",
|
|
31
|
+
"head",
|
|
32
|
+
"header",
|
|
33
|
+
"headIcons",
|
|
34
|
+
"journey_form",
|
|
35
|
+
"main",
|
|
36
|
+
"pageTitle",
|
|
37
|
+
"skipLink",
|
|
38
38
|
];
|
|
39
39
|
/**
|
|
40
40
|
* @callback BlockModifier
|
|
@@ -42,8 +42,8 @@ const VALID_BLOCKS = [
|
|
|
42
42
|
* @returns {string} The modified template source
|
|
43
43
|
*/
|
|
44
44
|
/**
|
|
45
|
-
* @access private
|
|
46
45
|
* @augments FileSystemLoader
|
|
46
|
+
* @access private
|
|
47
47
|
*/
|
|
48
48
|
class CasaTemplateLoader extends nunjucks_1.FileSystemLoader {
|
|
49
49
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CasaTemplateLoader.js","sourceRoot":"","sources":["../../src/lib/CasaTemplateLoader.js"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uCAA4C;AAE5C;;;GAGG;AAEH;;;GAGG;AAEH,MAAM,YAAY,GAAG;IACnB,eAAe;IACf,SAAS;IACT,WAAW;IACX,eAAe;IACf,SAAS;IACT,QAAQ;IACR,MAAM;IACN,QAAQ;IACR,WAAW;IACX,cAAc;IACd,MAAM;IACN,WAAW;IACX,UAAU;CACX,CAAC;AAEF;;;;GAIG;AAEH;;;GAGG;AACH,MAAqB,kBAAmB,SAAQ,2BAAgB;IAG9D;;;;;OAKG;IACH,YAAY,WAA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|
3
|
-
* @typedef {import('../casa').ContextEventUserInfo} ContextEventUserInfo
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
+
* @typedef {import("../casa").Page} Page
|
|
6
7
|
* @access private
|
|
7
|
-
* @typedef {import('../casa').Page} Page
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
10
|
+
* @typedef {import("../casa").ContextEventHandler} ContextEventHandler
|
|
10
11
|
* @access private
|
|
11
|
-
* @typedef {import('../casa').ContextEventHandler} ContextEventHandler
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
|
+
* @typedef {import("../casa").ContextEvent} ContextEvent
|
|
14
15
|
* @access private
|
|
15
|
-
* @typedef {import('../casa').ContextEvent} ContextEvent
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
|
+
* @typedef {import("../casa").JourneyContextObject} JourneyContextObject
|
|
18
19
|
* @access private
|
|
19
|
-
* @typedef {import('../casa').JourneyContextObject} JourneyContextObject
|
|
20
20
|
*/
|
|
21
21
|
/**
|
|
22
|
+
* @typedef {import("express").Request} ExpressRequest
|
|
22
23
|
* @access private
|
|
23
|
-
* @typedef {import('express').Request} ExpressRequest
|
|
24
24
|
*/
|
|
25
25
|
export function validateObjectKey(key?: string): string;
|
|
26
|
-
/**
|
|
27
|
-
* @memberof module:@dwp/govuk-casa
|
|
28
|
-
*/
|
|
26
|
+
/** @memberof module:@dwp/govuk-casa */
|
|
29
27
|
export default class JourneyContext {
|
|
30
28
|
static DEFAULT_CONTEXT_ID: string;
|
|
31
|
-
/**
|
|
32
|
-
* @type {symbol}
|
|
33
|
-
*/
|
|
29
|
+
/** @type {symbol} */
|
|
34
30
|
static ID_GENERATOR_REQ_LOG: symbol;
|
|
35
|
-
/**
|
|
36
|
-
* @type {symbol}
|
|
37
|
-
*/
|
|
31
|
+
/** @type {symbol} */
|
|
38
32
|
static ID_GENERATOR_REQ_KEY: symbol;
|
|
39
33
|
/**
|
|
40
34
|
* Create a new JourneyContext using the plain object.
|
|
@@ -72,6 +66,7 @@ export default class JourneyContext {
|
|
|
72
66
|
static initContextStore(session: object): void;
|
|
73
67
|
/**
|
|
74
68
|
* Validate the format of a context ID:
|
|
69
|
+
*
|
|
75
70
|
* - Between 1 and 64 characters
|
|
76
71
|
* - Contain only the characters a-z, 0-9, -
|
|
77
72
|
*
|
|
@@ -82,8 +77,8 @@ export default class JourneyContext {
|
|
|
82
77
|
*/
|
|
83
78
|
static validateContextId(id: string): string;
|
|
84
79
|
/**
|
|
85
|
-
* Generate a new context ID, validate it, and throw if the ID has already
|
|
86
|
-
* generated during this request lifecycle. This may happen if an ID was
|
|
80
|
+
* Generate a new context ID, validate it, and throw if the ID has already
|
|
81
|
+
* been generated during this request lifecycle. This may happen if an ID was
|
|
87
82
|
* generated, but never used to store a new context in the session. Therefore
|
|
88
83
|
* it is important for user code to always call `putContext()` before
|
|
89
84
|
* generating another ID.
|
|
@@ -122,9 +117,9 @@ export default class JourneyContext {
|
|
|
122
117
|
*
|
|
123
118
|
* @param {object} session Request session
|
|
124
119
|
* @param {string} tag Context tag
|
|
125
|
-
* @returns {
|
|
120
|
+
* @returns {JourneyContext[]} The discovered JourneyContext instance
|
|
126
121
|
*/
|
|
127
|
-
static getContextsByTag(session: object, tag: string):
|
|
122
|
+
static getContextsByTag(session: object, tag: string): JourneyContext[];
|
|
128
123
|
/**
|
|
129
124
|
* Return all contexts currently stored in the session.
|
|
130
125
|
*
|
|
@@ -138,7 +133,8 @@ export default class JourneyContext {
|
|
|
138
133
|
* @param {object} session Request session
|
|
139
134
|
* @param {JourneyContext} context Context
|
|
140
135
|
* @param {object} options Options
|
|
141
|
-
* @param {ContextEventUserInfo|object} [options.userInfo] Pass-through
|
|
136
|
+
* @param {ContextEventUserInfo | object} [options.userInfo] Pass-through
|
|
137
|
+
* event info
|
|
142
138
|
* @returns {void}
|
|
143
139
|
* @throws {TypeError} When session is not a valid type, or context has no ID
|
|
144
140
|
*/
|
|
@@ -187,9 +183,9 @@ export default class JourneyContext {
|
|
|
187
183
|
/**
|
|
188
184
|
* Extract the Journey Context referred to in the incoming request.
|
|
189
185
|
*
|
|
190
|
-
* This will look in `req.params`, `req.query` and
|
|
191
|
-
* `
|
|
192
|
-
*
|
|
186
|
+
* This will look in `req.params`, `req.query` and `req.body` for a
|
|
187
|
+
* `contextid` parameter, and use that to load the correct Journey Context
|
|
188
|
+
* from the session.
|
|
193
189
|
*
|
|
194
190
|
* @param {ExpressRequest} req ExpressJS incoming request
|
|
195
191
|
* @returns {JourneyContext} The Journey Context
|
|
@@ -200,7 +196,7 @@ export default class JourneyContext {
|
|
|
200
196
|
*
|
|
201
197
|
* `data` is the "single source of truth" for all data gathered during the
|
|
202
198
|
* user's journey. This is referred to as the "canonical data model".
|
|
203
|
-
*
|
|
199
|
+
* Page-specific "views" of this data are generated at runtime in order to
|
|
204
200
|
* populate/validate specific form fields.
|
|
205
201
|
*
|
|
206
202
|
* `validation` holds the results of form field validation carried out when
|
|
@@ -213,10 +209,11 @@ export default class JourneyContext {
|
|
|
213
209
|
* `identity` holds information that helps uniquely identify this context
|
|
214
210
|
* among a group of contexts stored in the session.
|
|
215
211
|
*
|
|
216
|
-
* @param {Record<string,any>} data Entire journey data.
|
|
212
|
+
* @param {Record<string, any>} data Entire journey data.
|
|
217
213
|
* @param {object} validation Page errors (indexed by waypoint id).
|
|
218
214
|
* @param {object} nav Navigation context.
|
|
219
|
-
* @param {object} identity Some metadata for identifying this context among
|
|
215
|
+
* @param {object} identity Some metadata for identifying this context among
|
|
216
|
+
* others.
|
|
220
217
|
*/
|
|
221
218
|
constructor(data?: Record<string, any>, validation?: object, nav?: object, identity?: object);
|
|
222
219
|
/**
|
|
@@ -233,7 +230,7 @@ export default class JourneyContext {
|
|
|
233
230
|
/**
|
|
234
231
|
* Get data context for a specific a specific page.
|
|
235
232
|
*
|
|
236
|
-
* @param
|
|
233
|
+
* @param {string | Page} page Page waypoint ID, or Page object.
|
|
237
234
|
* @returns {object} Page data.
|
|
238
235
|
* @throws {TypeError} When page is invalid.
|
|
239
236
|
*/
|
|
@@ -303,12 +300,13 @@ export default class JourneyContext {
|
|
|
303
300
|
*/
|
|
304
301
|
getValidationErrorsForPage(pageId: string): ValidationError[];
|
|
305
302
|
/**
|
|
306
|
-
* Same as `getValidationErrorsForPage()`, but the return value is
|
|
307
|
-
*
|
|
303
|
+
* Same as `getValidationErrorsForPage()`, but the return value is an object
|
|
304
|
+
* whose keys are the field names, and values are the list of errors
|
|
308
305
|
* associated with that particular field.
|
|
309
306
|
*
|
|
310
307
|
* @param {string} pageId Page ID.
|
|
311
|
-
* @returns {object} Object indexed by field names; values containing list of
|
|
308
|
+
* @returns {object} Object indexed by field names; values containing list of
|
|
309
|
+
* errors
|
|
312
310
|
*/
|
|
313
311
|
getValidationErrorsForPageByField(pageId: string): object;
|
|
314
312
|
/**
|
|
@@ -348,8 +346,8 @@ export default class JourneyContext {
|
|
|
348
346
|
*/
|
|
349
347
|
invalidate(waypoints?: string[]): void;
|
|
350
348
|
/**
|
|
351
|
-
* Event listeners are transient. They are not stored in session, and
|
|
352
|
-
* only apply for the current request.
|
|
349
|
+
* Event listeners are transient. They are not stored in session, and
|
|
350
|
+
* generally only apply for the current request.
|
|
353
351
|
*
|
|
354
352
|
* They also only act on a fixed snapshot of this context's state, which is
|
|
355
353
|
* taken at the point of attaching the listeners (in the "data" middleware).
|
|
@@ -369,7 +367,7 @@ export default class JourneyContext {
|
|
|
369
367
|
* @param {object} params Params
|
|
370
368
|
* @param {string} params.event Event (waypoint-change | context-change)
|
|
371
369
|
* @param {object} params.session Session
|
|
372
|
-
* @param {ContextEventUserInfo|object} [params.userInfo] Pass-through info
|
|
370
|
+
* @param {ContextEventUserInfo | object} [params.userInfo] Pass-through info
|
|
373
371
|
* @returns {JourneyContext} Chain
|
|
374
372
|
*/
|
|
375
373
|
applyEventListeners({ event, session, userInfo }: {
|
|
@@ -385,10 +383,10 @@ export default class JourneyContext {
|
|
|
385
383
|
isDefault(): boolean;
|
|
386
384
|
#private;
|
|
387
385
|
}
|
|
388
|
-
export type ContextEventUserInfo = import(
|
|
389
|
-
export type Page = import(
|
|
390
|
-
export type ContextEventHandler = import(
|
|
391
|
-
export type ContextEvent = import(
|
|
392
|
-
export type JourneyContextObject = import(
|
|
393
|
-
export type ExpressRequest = import(
|
|
394
|
-
import ValidationError from
|
|
386
|
+
export type ContextEventUserInfo = import("../casa").ContextEventUserInfo;
|
|
387
|
+
export type Page = import("../casa").Page;
|
|
388
|
+
export type ContextEventHandler = import("../casa").ContextEventHandler;
|
|
389
|
+
export type ContextEvent = import("../casa").ContextEvent;
|
|
390
|
+
export type JourneyContextObject = import("../casa").JourneyContextObject;
|
|
391
|
+
export type ExpressRequest = import("express").Request;
|
|
392
|
+
import ValidationError from "./ValidationError.js";
|