hof-behaviour-address-lookup
Advanced tools
Comparing version 1.2.0 to 2.0.0
@@ -12,3 +12,3 @@ 'use strict'; | ||
super(options); | ||
this.options = Object.assign({}, defaults.POSTCODE_API, options); | ||
this.options = _.merge({}, defaults.POSTCODE_API, options); | ||
} | ||
@@ -32,3 +32,3 @@ | ||
requestConfig(options) { | ||
return Object.assign(super.requestConfig(options), { | ||
return _.merge(super.requestConfig(options), { | ||
timeout: 5000, | ||
@@ -35,0 +35,0 @@ headers: { |
@@ -18,7 +18,8 @@ 'use strict'; | ||
const getFields = (key, t) => ({ | ||
const getFields = (key, t, requiredValidate) => ({ | ||
[`${key}-postcode`]: { | ||
label: conditionalTranslate(`fields.${key}-postcode.label`, t) || defaults.POSTCODE_LABEL, | ||
mixin: 'input-text-code', | ||
validate: ['required', 'postcode'], | ||
validate: requiredValidate ? ['required', 'postcode'] : ['postcode'], | ||
formatter: 'uppercase' | ||
@@ -67,2 +68,3 @@ }, | ||
const addressKey = config.addressKey; | ||
const required = config.required; | ||
if (!addressKey) { | ||
@@ -79,10 +81,10 @@ throw new Error('addressKey must be provided'); | ||
configure(req, res, callback) { | ||
this.model = new Model(Object.assign({}, apiSettings, { validate })); | ||
this.model = new Model(_.merge({}, apiSettings, { validate })); | ||
req.query.step = req.query.step || 'postcode'; | ||
const subSteps = getConfig(addressKey); | ||
const step = subSteps[req.query.step]; | ||
Object.assign(req.form.options, { | ||
_.merge(req.form.options, { | ||
subSteps, | ||
addressKey, | ||
fields: _.pick(getFields(addressKey, req.translate), step.fields), | ||
fields: _.pick(getFields(addressKey, req.translate, required), step.fields), | ||
apiError: null | ||
@@ -98,5 +100,6 @@ }); | ||
const step = super.getNextStep(req, res, callback); | ||
if (req.query.step === 'postcode') { | ||
if (req.query.step === 'postcode' && req.form.values[`${addressKey}-postcode`]) { | ||
const nextSubStep = req.sessionModel.get(`${addressKey}-addresses`) ? 'lookup' : 'address'; | ||
const qs = querystring.stringify(Object.assign({}, req.query, { | ||
const qs = querystring.stringify(_.merge({}, req.query, { | ||
step: nextSubStep | ||
@@ -109,6 +112,2 @@ })); | ||
successHandler(req, res, cb) { | ||
super.successHandler(req, res, cb); | ||
} | ||
getValues(req, res, callback) { | ||
@@ -158,3 +157,3 @@ if (req.query.step === 'manual') { | ||
return Object.assign({}, locals, { | ||
return _.merge({}, locals, { | ||
postcodeEntered: conditionalTranslate('pages.address-lookup.postcode-entered', req.translate) || | ||
@@ -161,0 +160,0 @@ defaults.POSTCODE_ENTERED, |
{ | ||
"name": "hof-behaviour-address-lookup", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "A HOF Behaviour for a multi-step postcode lookup", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"test:lint": "eslint .", | ||
"test:functional": "funkie mocha ./functional-tests --opts ./functional-tests/mocha.opts" | ||
"test:functional": "funkie mocha" | ||
}, | ||
@@ -12,0 +12,0 @@ "keywords": [], |
@@ -24,2 +24,3 @@ # hof-behaviour-address-lookup | ||
* `addressKey` - REQUIRED - the key used to store the formatted address after lookup | ||
* `required` - if set to a truthy value then the address is required. By default a user can pass through without entering an address. | ||
* apiSettings - settings to pass to the Model on init. Default MOJ lookup api expects `hostname`, `authorization`, `paths.lookup` and `paths.validate` | ||
@@ -26,0 +27,0 @@ * `Model` - a custom Model which exposes a `fetch` method (and `validate` if using api validation). Both `fetch` and `validate` are expected to return a `Promise` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
53
1
18255
16
317