@defra/forms-engine-plugin 4.1.0 → 4.1.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.
|
@@ -307,7 +307,8 @@ export const manualPayloadSchema = Joi.object().keys({
|
|
|
307
307
|
'*': 'Enter town or city'
|
|
308
308
|
}),
|
|
309
309
|
[countyFieldName]: Joi.string().trim().allow('').required(),
|
|
310
|
-
[postcodeFieldName]: Joi.string().trim().required().messages({
|
|
310
|
+
[postcodeFieldName]: Joi.string().pattern(/^[a-zA-Z]{1,2}\d[a-zA-Z\d]?\s?\d[a-zA-Z]{2}$/).trim().required().messages({
|
|
311
|
+
'string.pattern.base': 'Enter a valid postcode',
|
|
311
312
|
'*': 'Enter postcode'
|
|
312
313
|
})
|
|
313
314
|
}).required();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Joi","service","crumbSchema","postcodeQueryFieldName","buildingNameQueryFieldName","uprnFieldName","line1FieldName","line2FieldName","townFieldName","countyFieldName","postcodeFieldName","selectLabelText","GOVUK_MARGIN_RIGHT_1","steps","details","select","manual","JOURNEY_BASE_URL","buildErrors","err","hasErrors","isError","length","getError","fieldName","find","item","path","postcodeQueryError","buildingNameQueryError","uprnError","line1Error","line2Error","townError","countyError","postcodeError","errors","pushError","push","text","message","href","getAddresses","postcodeQuery","buildingNameQuery","apiKey","addresses","search","addressCount","singleAddress","at","undefined","hasAddresses","hasMultipleAddresses","getDetailsFields","id","name","label","hint","value","errorMessage","getSelectFields","payload","type","uprn","items","concat","map","formatted","getManualFields","addressLine1","addressLine2","classes","town","county","postcode","stepSchema","string","valid","Object","keys","required","sharedPayloadSchemaKeys","crumb","step","detailsPayloadSchema","object","pattern","trim","messages","allow","selectPayloadSchema","manualPayloadSchema","getHref","query","detailsViewModel","data","componentTitle","pageTitle","formName","sourceUrl","initial","backLink","fields","continueButton","manualLink","showTitle","serviceUrl","buttons","selectViewModel","session","title","formPath","searchAgainLink","manualViewModel","componentHint","detailsLink"],"sources":["../../../../../src/server/plugins/postcode-lookup/models/index.js"],"sourcesContent":["import Joi from 'joi'\n\nimport * as service from '~/src/server/plugins/postcode-lookup/service.js'\nimport { crumbSchema } from '~/src/server/schemas/index.js'\n\n// Field names/ids\nconst postcodeQueryFieldName = 'postcodeQuery'\nconst buildingNameQueryFieldName = 'buildingNameQuery'\nconst uprnFieldName = 'uprn'\n\nconst line1FieldName = 'addressLine1'\nconst line2FieldName = 'addressLine2'\nconst townFieldName = 'town'\nconst countyFieldName = 'county'\nconst postcodeFieldName = 'postcode'\n\nconst selectLabelText = 'Select an address'\n\nconst GOVUK_MARGIN_RIGHT_1 = 'govuk-!-margin-right-1'\n\nexport const steps = {\n // Step 1: Postcode/building name input\n details: 'details',\n // Step 2: Select address\n select: 'select',\n // Step 3: Manual address\n manual: 'manual'\n}\n\nexport const JOURNEY_BASE_URL = '/postcode-lookup'\n\n/**\n * Build form errors\n * @param {Error} [err]\n */\nfunction buildErrors(err) {\n const hasErrors = Joi.isError(err) && err.details.length > 0\n\n if (!hasErrors) {\n return {}\n }\n\n /**\n * Get error by path\n * @param {string} fieldName\n */\n const getError = (fieldName) => {\n return err.details.find((item) => item.path[0] === fieldName)\n }\n\n const postcodeQueryError = getError(postcodeQueryFieldName)\n const buildingNameQueryError = getError(buildingNameQueryFieldName)\n const uprnError = getError(uprnFieldName)\n const line1Error = getError(line1FieldName)\n const line2Error = getError(line2FieldName)\n const townError = getError(townFieldName)\n const countyError = getError(countyFieldName)\n const postcodeError = getError(postcodeFieldName)\n\n /**\n * @type {{ text: string, href: string }[]}\n */\n const errors = []\n\n /**\n * Push error\n * @param {string} fieldName - the field name\n * @param {ValidationErrorItem} [item] - the joi validation error\n */\n const pushError = (fieldName, item) => {\n if (item) {\n errors.push({\n text: item.message,\n href: `#${fieldName}`\n })\n }\n }\n\n pushError(postcodeQueryFieldName, postcodeQueryError)\n pushError(buildingNameQueryFieldName, buildingNameQueryError)\n pushError(uprnFieldName, uprnError)\n pushError(line1FieldName, line1Error)\n pushError(line2FieldName, line2Error)\n pushError(townFieldName, townError)\n pushError(countyFieldName, countyError)\n pushError(postcodeFieldName, postcodeError)\n\n return {\n errors,\n postcodeQueryError,\n buildingNameQueryError,\n uprnError,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n }\n}\n\n/**\n * Search ordnance survey for addresses\n * @param {string} postcodeQuery\n * @param {string} buildingNameQuery\n * @param {string} apiKey\n */\nasync function getAddresses(postcodeQuery, buildingNameQuery, apiKey) {\n const addresses = await service.search(\n postcodeQuery,\n buildingNameQuery,\n apiKey\n )\n const addressCount = addresses.length\n const singleAddress = addressCount === 1 ? addresses.at(0) : undefined\n const hasAddresses = addressCount > 0\n const hasMultipleAddresses = addressCount > 1\n\n return {\n hasAddresses,\n hasMultipleAddresses,\n singleAddress,\n addresses,\n addressCount\n }\n}\n\n/**\n * Get the details view fields\n * @param {PostcodeLookupDetailsData | undefined} details\n * @param {OptionalValidationErrorItem} postcodeQueryError\n * @param {OptionalValidationErrorItem} buildingNameQueryError\n */\nfunction getDetailsFields(details, postcodeQueryError, buildingNameQueryError) {\n return {\n [postcodeQueryFieldName]: {\n id: postcodeQueryFieldName,\n name: postcodeQueryFieldName,\n label: {\n text: 'Postcode'\n },\n hint: {\n text: 'For example, AA3 1AB'\n },\n value: details?.postcodeQuery,\n errorMessage: postcodeQueryError && { text: postcodeQueryError.message }\n },\n [buildingNameQueryFieldName]: {\n id: buildingNameQueryFieldName,\n name: buildingNameQueryFieldName,\n label: {\n text: 'Building name or number (optional)'\n },\n hint: {\n text: 'For example, 15 or Prospect Cottage'\n },\n value: details?.buildingNameQuery,\n errorMessage: buildingNameQueryError && {\n text: buildingNameQueryError.message\n }\n }\n }\n}\n\n/**\n * Get the select view fields\n * @param {PostcodeLookupDetailsData} details\n * @param {boolean} hasMultipleAddresses\n * @param {Address | undefined} singleAddress\n * @param {PostcodeLookupSelectPayload | undefined} payload\n * @param {OptionalValidationErrorItem} uprnError\n * @param {Address[]} addresses\n */\nfunction getSelectFields(\n details,\n hasMultipleAddresses,\n singleAddress,\n payload,\n uprnError,\n addresses\n) {\n return {\n [postcodeQueryFieldName]: {\n id: postcodeQueryFieldName,\n name: postcodeQueryFieldName,\n type: 'hidden',\n value: details.postcodeQuery\n },\n [buildingNameQueryFieldName]: {\n id: buildingNameQueryFieldName,\n name: buildingNameQueryFieldName,\n type: 'hidden',\n value: details.buildingNameQuery\n },\n [uprnFieldName]: {\n id: uprnFieldName,\n name: uprnFieldName,\n label: hasMultipleAddresses\n ? {\n text: selectLabelText\n }\n : undefined,\n value: singleAddress ? singleAddress.uprn : payload?.uprn,\n errorMessage: uprnError && { text: uprnError.message },\n items: hasMultipleAddresses\n ? [{ text: selectLabelText, value: '' }].concat(\n addresses.map((item) => ({\n text: item.formatted,\n value: item.uprn\n }))\n )\n : undefined,\n type: singleAddress ? 'hidden' : undefined\n }\n }\n}\n\n/**\n * Get the manual view fields\n * @param {PostcodeLookupManualPayload | undefined} payload\n * @param {OptionalValidationErrorItem} line1Error\n * @param {OptionalValidationErrorItem} line2Error\n * @param {OptionalValidationErrorItem} townError\n * @param {OptionalValidationErrorItem} countyError\n * @param {OptionalValidationErrorItem} postcodeError\n */\nfunction getManualFields(\n payload,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n) {\n return {\n [line1FieldName]: {\n id: line1FieldName,\n name: line1FieldName,\n label: {\n text: 'Address line 1'\n },\n value: payload?.addressLine1,\n errorMessage: line1Error && { text: line1Error.message }\n },\n [line2FieldName]: {\n id: line2FieldName,\n name: line2FieldName,\n label: {\n text: 'Address line 2 (optional)'\n },\n value: payload?.addressLine2,\n errorMessage: line2Error && { text: line2Error.message }\n },\n [townFieldName]: {\n id: townFieldName,\n name: townFieldName,\n label: {\n text: 'Town or city'\n },\n classes: 'govuk-!-width-two-thirds',\n value: payload?.town,\n errorMessage: townError && { text: townError.message }\n },\n [countyFieldName]: {\n id: countyFieldName,\n name: countyFieldName,\n label: {\n text: 'County (optional)'\n },\n value: payload?.county,\n errorMessage: countyError && { text: countyError.message }\n },\n [postcodeFieldName]: {\n id: postcodeFieldName,\n name: postcodeFieldName,\n label: {\n text: 'Postcode'\n },\n classes: 'govuk-input--width-10',\n value: payload?.postcode,\n errorMessage: postcodeError && { text: postcodeError.message }\n }\n }\n}\n\nexport const stepSchema = Joi.string()\n .valid(...Object.keys(steps))\n .required()\n\nconst sharedPayloadSchemaKeys = {\n crumb: crumbSchema,\n step: stepSchema\n}\n\n/**\n * Postcode lookup details form payload schema\n * @type {ObjectSchema<PostcodeLookupDetailsPayload>}\n */\nexport const detailsPayloadSchema = Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [postcodeQueryFieldName]: Joi.string()\n .pattern(/^[a-zA-Z]{1,2}\\d[a-zA-Z\\d]?\\s?\\d[a-zA-Z]{2}$/)\n .trim()\n .required()\n .messages({\n 'string.pattern.base':\n 'Enter a valid postcode or enter an address manually',\n '*': 'Enter a postcode'\n }),\n [buildingNameQueryFieldName]: Joi.string()\n .trim()\n .required()\n .allow('')\n .trim()\n })\n .required()\n\n/**\n * Postcode lookup select form payload schema\n * @type {ObjectSchema<PostcodeLookupSelectPayload>}\n */\nexport const selectPayloadSchema = Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [uprnFieldName]: Joi.string().required().messages({\n '*': selectLabelText\n })\n })\n .required()\n\n/**\n * Postcode lookup manual form payload schema\n * @type {ObjectSchema<PostcodeLookupManualPayload>}\n */\nexport const manualPayloadSchema = Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [line1FieldName]: Joi.string().trim().required().messages({\n '*': 'Enter address line 1'\n }),\n [line2FieldName]: Joi.string().trim().allow('').required(),\n [townFieldName]: Joi.string().trim().required().messages({\n '*': 'Enter town or city'\n }),\n [countyFieldName]: Joi.string().trim().allow('').required(),\n [postcodeFieldName]: Joi.string().trim().required().messages({\n '*': 'Enter postcode'\n })\n })\n .required()\n\n/**\n * Get the postcode lookup href\n * @param {string} [step] - the postcode lookup step\n */\nfunction getHref(step) {\n const query = step ? `?step=${step}` : ''\n\n return `${JOURNEY_BASE_URL}${query}`\n}\n\n/**\n * The postcode lookup details form view model\n * @param {PostcodeLookupSessionData} data\n * @param {PostcodeLookupDetailsData} [payload]\n * @param {Error} [err]\n */\nexport function detailsViewModel(data, payload, err) {\n const { componentTitle: pageTitle, formName, sourceUrl } = data.initial\n\n const backLink = {\n href: sourceUrl\n }\n\n const { errors, postcodeQueryError, buildingNameQueryError } =\n buildErrors(err)\n\n // Model fields\n const fields = getDetailsFields(\n payload ?? data.details,\n postcodeQueryError,\n buildingNameQueryError\n )\n\n // Model buttons\n const continueButton = {\n text: 'Find address',\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const manualLink = {\n text: 'enter address manually',\n href: getHref(steps.manual)\n }\n\n return {\n step: steps.details,\n showTitle: true,\n name: formName,\n serviceUrl: sourceUrl,\n pageTitle,\n backLink,\n errors,\n fields,\n buttons: { continueButton, manualLink }\n }\n}\n\n/**\n * The postcode lookup select form view model\n * @param {{ session: PostcodeLookupSessionData, apiKey: string }} data\n * @param {PostcodeLookupSelectPayload} [payload]\n * @param {Error} [err]\n */\nexport async function selectViewModel(data, payload, err) {\n const { session, apiKey } = data\n const { details, initial } = session\n const { postcodeQuery, buildingNameQuery } = details\n\n // Search for addresses\n const {\n hasAddresses,\n hasMultipleAddresses,\n singleAddress,\n addresses,\n addressCount\n } = await getAddresses(postcodeQuery, buildingNameQuery, apiKey)\n\n const title = hasAddresses ? initial.componentTitle : 'No address found'\n const formPath = initial.sourceUrl\n const href = getHref()\n\n const backLink = { href }\n\n const { errors, uprnError } = buildErrors(err)\n\n // Model fields\n const fields = getSelectFields(\n details,\n hasMultipleAddresses,\n singleAddress,\n payload,\n uprnError,\n addresses\n )\n\n const searchAgainLink = {\n text: 'Search again',\n href\n }\n\n // Model buttons\n const continueButton = {\n href: hasAddresses ? undefined : href,\n text: hasAddresses ? 'Use this address' : 'Search again',\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const manualLink = {\n text: 'enter address manually',\n href: `${href}?step=${steps.manual}`\n }\n\n return {\n step: steps.select,\n showTitle: true,\n name: title,\n serviceUrl: formPath,\n pageTitle: title,\n backLink,\n errors,\n searchAgainLink,\n fields,\n details,\n addressCount,\n singleAddress,\n hasAddresses,\n hasMultipleAddresses,\n buttons: { continueButton, manualLink }\n }\n}\n\n/**\n * The postcode lookup manual form view model\n * @param {PostcodeLookupSessionData} data\n * @param {PostcodeLookupManualPayload} [payload]\n * @param {Error} [err]\n */\nexport function manualViewModel(data, payload, err) {\n const { componentTitle, sourceUrl, componentHint } = data.initial\n const formPath = sourceUrl\n const href = getHref()\n\n const backLink = {\n href\n }\n\n const {\n errors,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n } = buildErrors(err)\n\n // Model hint\n const hint = componentHint && {\n text: componentHint\n }\n\n // Model fields\n const fields = getManualFields(\n payload,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n )\n\n // Model buttons\n const continueButton = {\n text: 'Use this address',\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const detailsLink = {\n text: 'find an address instead',\n href\n }\n\n return {\n step: steps.manual,\n showTitle: true,\n name: componentTitle,\n serviceUrl: formPath,\n pageTitle: componentTitle,\n backLink,\n errors,\n hint,\n fields,\n buttons: { continueButton, detailsLink }\n }\n}\n\n/** @typedef { ValidationErrorItem | undefined } OptionalValidationErrorItem */\n\n/**\n * @import { ObjectSchema, ValidationErrorItem } from 'joi'\n * @import { Address, PostcodeLookupDetailsData, PostcodeLookupDetailsPayload, PostcodeLookupManualPayload, PostcodeLookupSelectPayload, PostcodeLookupSessionData } from '~/src/server/plugins/postcode-lookup/types.js'\n */\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AAErB,OAAO,KAAKC,OAAO;AACnB,SAASC,WAAW;;AAEpB;AACA,MAAMC,sBAAsB,GAAG,eAAe;AAC9C,MA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AGnB,IAAI,CAACK,OAAO;EACjE,MAAMW,QAAQ,GAAGZ,SAAS;EAC1B,MAAM3D,IAAI,GAAGoD,OAAO,CAAC,CAAC;EAEtB,MAAMS,QAAQ,GAAG;IACf7D;EACF,CAAC;EAED,MAAM;IACJL,MAAM;IACNL,UAAU;IACVC,UAAU;IACVC,SAAS;IACTC,WAAW;IACXC;EACF,CAAC,GAAGjB,WAAW,CAACC,GAAG,CAAC;;EAEpB;EACA,MAAMuC,IAAI,GAAGyD,aAAa,IAAI;IAC5B5E,IAAI,EAAE4E;EACR,CAAC;;EAED;EACA,MAAMZ,MAAM,GAAGlC,eAAe,CAC5BP,OAAO,EACP/B,UAAU,EACVC,UAAU,EACVC,SAAS,EACTC,WAAW,EACXC,aACF,CAAC;;EAED;EACA,MAAMqE,cAAc,GAAG;IACrBjE,IAAI,EAAE,kBAAkB;IACxBiC,OAAO,EAAE5D;EACX,CAAC;EACD,MAAMwG,WAAW,GAAG;IAClB7E,IAAI,EAAE,yBAAyB;IAC/BE;EACF,CAAC;EAED,OAAO;IACL2C,IAAI,EAAEvE,KAAK,CAACG,MAAM;IAClB0F,SAAS,EAAE,IAAI;IACflD,IAAI,EAAEyC,cAAc;IACpBU,UAAU,EAAEK,QAAQ;IACpBd,SAAS,EAAED,cAAc;IACzBK,QAAQ;IACRlE,MAAM;IACNsB,IAAI;IACJ6C,MAAM;IACNK,OAAO,EAAE;MAAEJ,cAAc;MAAEY;IAAY;EACzC,CAAC;AACH;;AAEA;;AAEA;AACA;AACA;AACA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Joi","service","crumbSchema","postcodeQueryFieldName","buildingNameQueryFieldName","uprnFieldName","line1FieldName","line2FieldName","townFieldName","countyFieldName","postcodeFieldName","selectLabelText","GOVUK_MARGIN_RIGHT_1","steps","details","select","manual","JOURNEY_BASE_URL","buildErrors","err","hasErrors","isError","length","getError","fieldName","find","item","path","postcodeQueryError","buildingNameQueryError","uprnError","line1Error","line2Error","townError","countyError","postcodeError","errors","pushError","push","text","message","href","getAddresses","postcodeQuery","buildingNameQuery","apiKey","addresses","search","addressCount","singleAddress","at","undefined","hasAddresses","hasMultipleAddresses","getDetailsFields","id","name","label","hint","value","errorMessage","getSelectFields","payload","type","uprn","items","concat","map","formatted","getManualFields","addressLine1","addressLine2","classes","town","county","postcode","stepSchema","string","valid","Object","keys","required","sharedPayloadSchemaKeys","crumb","step","detailsPayloadSchema","object","pattern","trim","messages","allow","selectPayloadSchema","manualPayloadSchema","getHref","query","detailsViewModel","data","componentTitle","pageTitle","formName","sourceUrl","initial","backLink","fields","continueButton","manualLink","showTitle","serviceUrl","buttons","selectViewModel","session","title","formPath","searchAgainLink","manualViewModel","componentHint","detailsLink"],"sources":["../../../../../src/server/plugins/postcode-lookup/models/index.js"],"sourcesContent":["import Joi from 'joi'\n\nimport * as service from '~/src/server/plugins/postcode-lookup/service.js'\nimport { crumbSchema } from '~/src/server/schemas/index.js'\n\n// Field names/ids\nconst postcodeQueryFieldName = 'postcodeQuery'\nconst buildingNameQueryFieldName = 'buildingNameQuery'\nconst uprnFieldName = 'uprn'\n\nconst line1FieldName = 'addressLine1'\nconst line2FieldName = 'addressLine2'\nconst townFieldName = 'town'\nconst countyFieldName = 'county'\nconst postcodeFieldName = 'postcode'\n\nconst selectLabelText = 'Select an address'\n\nconst GOVUK_MARGIN_RIGHT_1 = 'govuk-!-margin-right-1'\n\nexport const steps = {\n // Step 1: Postcode/building name input\n details: 'details',\n // Step 2: Select address\n select: 'select',\n // Step 3: Manual address\n manual: 'manual'\n}\n\nexport const JOURNEY_BASE_URL = '/postcode-lookup'\n\n/**\n * Build form errors\n * @param {Error} [err]\n */\nfunction buildErrors(err) {\n const hasErrors = Joi.isError(err) && err.details.length > 0\n\n if (!hasErrors) {\n return {}\n }\n\n /**\n * Get error by path\n * @param {string} fieldName\n */\n const getError = (fieldName) => {\n return err.details.find((item) => item.path[0] === fieldName)\n }\n\n const postcodeQueryError = getError(postcodeQueryFieldName)\n const buildingNameQueryError = getError(buildingNameQueryFieldName)\n const uprnError = getError(uprnFieldName)\n const line1Error = getError(line1FieldName)\n const line2Error = getError(line2FieldName)\n const townError = getError(townFieldName)\n const countyError = getError(countyFieldName)\n const postcodeError = getError(postcodeFieldName)\n\n /**\n * @type {{ text: string, href: string }[]}\n */\n const errors = []\n\n /**\n * Push error\n * @param {string} fieldName - the field name\n * @param {ValidationErrorItem} [item] - the joi validation error\n */\n const pushError = (fieldName, item) => {\n if (item) {\n errors.push({\n text: item.message,\n href: `#${fieldName}`\n })\n }\n }\n\n pushError(postcodeQueryFieldName, postcodeQueryError)\n pushError(buildingNameQueryFieldName, buildingNameQueryError)\n pushError(uprnFieldName, uprnError)\n pushError(line1FieldName, line1Error)\n pushError(line2FieldName, line2Error)\n pushError(townFieldName, townError)\n pushError(countyFieldName, countyError)\n pushError(postcodeFieldName, postcodeError)\n\n return {\n errors,\n postcodeQueryError,\n buildingNameQueryError,\n uprnError,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n }\n}\n\n/**\n * Search ordnance survey for addresses\n * @param {string} postcodeQuery\n * @param {string} buildingNameQuery\n * @param {string} apiKey\n */\nasync function getAddresses(postcodeQuery, buildingNameQuery, apiKey) {\n const addresses = await service.search(\n postcodeQuery,\n buildingNameQuery,\n apiKey\n )\n const addressCount = addresses.length\n const singleAddress = addressCount === 1 ? addresses.at(0) : undefined\n const hasAddresses = addressCount > 0\n const hasMultipleAddresses = addressCount > 1\n\n return {\n hasAddresses,\n hasMultipleAddresses,\n singleAddress,\n addresses,\n addressCount\n }\n}\n\n/**\n * Get the details view fields\n * @param {PostcodeLookupDetailsData | undefined} details\n * @param {OptionalValidationErrorItem} postcodeQueryError\n * @param {OptionalValidationErrorItem} buildingNameQueryError\n */\nfunction getDetailsFields(details, postcodeQueryError, buildingNameQueryError) {\n return {\n [postcodeQueryFieldName]: {\n id: postcodeQueryFieldName,\n name: postcodeQueryFieldName,\n label: {\n text: 'Postcode'\n },\n hint: {\n text: 'For example, AA3 1AB'\n },\n value: details?.postcodeQuery,\n errorMessage: postcodeQueryError && { text: postcodeQueryError.message }\n },\n [buildingNameQueryFieldName]: {\n id: buildingNameQueryFieldName,\n name: buildingNameQueryFieldName,\n label: {\n text: 'Building name or number (optional)'\n },\n hint: {\n text: 'For example, 15 or Prospect Cottage'\n },\n value: details?.buildingNameQuery,\n errorMessage: buildingNameQueryError && {\n text: buildingNameQueryError.message\n }\n }\n }\n}\n\n/**\n * Get the select view fields\n * @param {PostcodeLookupDetailsData} details\n * @param {boolean} hasMultipleAddresses\n * @param {Address | undefined} singleAddress\n * @param {PostcodeLookupSelectPayload | undefined} payload\n * @param {OptionalValidationErrorItem} uprnError\n * @param {Address[]} addresses\n */\nfunction getSelectFields(\n details,\n hasMultipleAddresses,\n singleAddress,\n payload,\n uprnError,\n addresses\n) {\n return {\n [postcodeQueryFieldName]: {\n id: postcodeQueryFieldName,\n name: postcodeQueryFieldName,\n type: 'hidden',\n value: details.postcodeQuery\n },\n [buildingNameQueryFieldName]: {\n id: buildingNameQueryFieldName,\n name: buildingNameQueryFieldName,\n type: 'hidden',\n value: details.buildingNameQuery\n },\n [uprnFieldName]: {\n id: uprnFieldName,\n name: uprnFieldName,\n label: hasMultipleAddresses\n ? {\n text: selectLabelText\n }\n : undefined,\n value: singleAddress ? singleAddress.uprn : payload?.uprn,\n errorMessage: uprnError && { text: uprnError.message },\n items: hasMultipleAddresses\n ? [{ text: selectLabelText, value: '' }].concat(\n addresses.map((item) => ({\n text: item.formatted,\n value: item.uprn\n }))\n )\n : undefined,\n type: singleAddress ? 'hidden' : undefined\n }\n }\n}\n\n/**\n * Get the manual view fields\n * @param {PostcodeLookupManualPayload | undefined} payload\n * @param {OptionalValidationErrorItem} line1Error\n * @param {OptionalValidationErrorItem} line2Error\n * @param {OptionalValidationErrorItem} townError\n * @param {OptionalValidationErrorItem} countyError\n * @param {OptionalValidationErrorItem} postcodeError\n */\nfunction getManualFields(\n payload,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n) {\n return {\n [line1FieldName]: {\n id: line1FieldName,\n name: line1FieldName,\n label: {\n text: 'Address line 1'\n },\n value: payload?.addressLine1,\n errorMessage: line1Error && { text: line1Error.message }\n },\n [line2FieldName]: {\n id: line2FieldName,\n name: line2FieldName,\n label: {\n text: 'Address line 2 (optional)'\n },\n value: payload?.addressLine2,\n errorMessage: line2Error && { text: line2Error.message }\n },\n [townFieldName]: {\n id: townFieldName,\n name: townFieldName,\n label: {\n text: 'Town or city'\n },\n classes: 'govuk-!-width-two-thirds',\n value: payload?.town,\n errorMessage: townError && { text: townError.message }\n },\n [countyFieldName]: {\n id: countyFieldName,\n name: countyFieldName,\n label: {\n text: 'County (optional)'\n },\n value: payload?.county,\n errorMessage: countyError && { text: countyError.message }\n },\n [postcodeFieldName]: {\n id: postcodeFieldName,\n name: postcodeFieldName,\n label: {\n text: 'Postcode'\n },\n classes: 'govuk-input--width-10',\n value: payload?.postcode,\n errorMessage: postcodeError && { text: postcodeError.message }\n }\n }\n}\n\nexport const stepSchema = Joi.string()\n .valid(...Object.keys(steps))\n .required()\n\nconst sharedPayloadSchemaKeys = {\n crumb: crumbSchema,\n step: stepSchema\n}\n\n/**\n * Postcode lookup details form payload schema\n * @type {ObjectSchema<PostcodeLookupDetailsPayload>}\n */\nexport const detailsPayloadSchema = Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [postcodeQueryFieldName]: Joi.string()\n .pattern(/^[a-zA-Z]{1,2}\\d[a-zA-Z\\d]?\\s?\\d[a-zA-Z]{2}$/)\n .trim()\n .required()\n .messages({\n 'string.pattern.base':\n 'Enter a valid postcode or enter an address manually',\n '*': 'Enter a postcode'\n }),\n [buildingNameQueryFieldName]: Joi.string()\n .trim()\n .required()\n .allow('')\n .trim()\n })\n .required()\n\n/**\n * Postcode lookup select form payload schema\n * @type {ObjectSchema<PostcodeLookupSelectPayload>}\n */\nexport const selectPayloadSchema = Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [uprnFieldName]: Joi.string().required().messages({\n '*': selectLabelText\n })\n })\n .required()\n\n/**\n * Postcode lookup manual form payload schema\n * @type {ObjectSchema<PostcodeLookupManualPayload>}\n */\nexport const manualPayloadSchema = Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [line1FieldName]: Joi.string().trim().required().messages({\n '*': 'Enter address line 1'\n }),\n [line2FieldName]: Joi.string().trim().allow('').required(),\n [townFieldName]: Joi.string().trim().required().messages({\n '*': 'Enter town or city'\n }),\n [countyFieldName]: Joi.string().trim().allow('').required(),\n [postcodeFieldName]: Joi.string()\n .pattern(/^[a-zA-Z]{1,2}\\d[a-zA-Z\\d]?\\s?\\d[a-zA-Z]{2}$/)\n .trim()\n .required()\n .messages({\n 'string.pattern.base': 'Enter a valid postcode',\n '*': 'Enter postcode'\n })\n })\n .required()\n\n/**\n * Get the postcode lookup href\n * @param {string} [step] - the postcode lookup step\n */\nfunction getHref(step) {\n const query = step ? `?step=${step}` : ''\n\n return `${JOURNEY_BASE_URL}${query}`\n}\n\n/**\n * The postcode lookup details form view model\n * @param {PostcodeLookupSessionData} data\n * @param {PostcodeLookupDetailsData} [payload]\n * @param {Error} [err]\n */\nexport function detailsViewModel(data, payload, err) {\n const { componentTitle: pageTitle, formName, sourceUrl } = data.initial\n\n const backLink = {\n href: sourceUrl\n }\n\n const { errors, postcodeQueryError, buildingNameQueryError } =\n buildErrors(err)\n\n // Model fields\n const fields = getDetailsFields(\n payload ?? data.details,\n postcodeQueryError,\n buildingNameQueryError\n )\n\n // Model buttons\n const continueButton = {\n text: 'Find address',\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const manualLink = {\n text: 'enter address manually',\n href: getHref(steps.manual)\n }\n\n return {\n step: steps.details,\n showTitle: true,\n name: formName,\n serviceUrl: sourceUrl,\n pageTitle,\n backLink,\n errors,\n fields,\n buttons: { continueButton, manualLink }\n }\n}\n\n/**\n * The postcode lookup select form view model\n * @param {{ session: PostcodeLookupSessionData, apiKey: string }} data\n * @param {PostcodeLookupSelectPayload} [payload]\n * @param {Error} [err]\n */\nexport async function selectViewModel(data, payload, err) {\n const { session, apiKey } = data\n const { details, initial } = session\n const { postcodeQuery, buildingNameQuery } = details\n\n // Search for addresses\n const {\n hasAddresses,\n hasMultipleAddresses,\n singleAddress,\n addresses,\n addressCount\n } = await getAddresses(postcodeQuery, buildingNameQuery, apiKey)\n\n const title = hasAddresses ? initial.componentTitle : 'No address found'\n const formPath = initial.sourceUrl\n const href = getHref()\n\n const backLink = { href }\n\n const { errors, uprnError } = buildErrors(err)\n\n // Model fields\n const fields = getSelectFields(\n details,\n hasMultipleAddresses,\n singleAddress,\n payload,\n uprnError,\n addresses\n )\n\n const searchAgainLink = {\n text: 'Search again',\n href\n }\n\n // Model buttons\n const continueButton = {\n href: hasAddresses ? undefined : href,\n text: hasAddresses ? 'Use this address' : 'Search again',\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const manualLink = {\n text: 'enter address manually',\n href: `${href}?step=${steps.manual}`\n }\n\n return {\n step: steps.select,\n showTitle: true,\n name: title,\n serviceUrl: formPath,\n pageTitle: title,\n backLink,\n errors,\n searchAgainLink,\n fields,\n details,\n addressCount,\n singleAddress,\n hasAddresses,\n hasMultipleAddresses,\n buttons: { continueButton, manualLink }\n }\n}\n\n/**\n * The postcode lookup manual form view model\n * @param {PostcodeLookupSessionData} data\n * @param {PostcodeLookupManualPayload} [payload]\n * @param {Error} [err]\n */\nexport function manualViewModel(data, payload, err) {\n const { componentTitle, sourceUrl, componentHint } = data.initial\n const formPath = sourceUrl\n const href = getHref()\n\n const backLink = {\n href\n }\n\n const {\n errors,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n } = buildErrors(err)\n\n // Model hint\n const hint = componentHint && {\n text: componentHint\n }\n\n // Model fields\n const fields = getManualFields(\n payload,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n )\n\n // Model buttons\n const continueButton = {\n text: 'Use this address',\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const detailsLink = {\n text: 'find an address instead',\n href\n }\n\n return {\n step: steps.manual,\n showTitle: true,\n name: componentTitle,\n serviceUrl: formPath,\n pageTitle: componentTitle,\n backLink,\n errors,\n hint,\n fields,\n buttons: { continueButton, detailsLink }\n }\n}\n\n/** @typedef { ValidationErrorItem | undefined } OptionalValidationErrorItem */\n\n/**\n * @import { ObjectSchema, ValidationErrorItem } from 'joi'\n * @import { Address, PostcodeLookupDetailsData, PostcodeLookupDetailsPayload, PostcodeLookupManualPayload, PostcodeLookupSelectPayload, PostcodeLookupSessionData } from '~/src/server/plugins/postcode-lookup/types.js'\n */\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AAErB,OAAO,KAAKC,OAAO;AACnB,SAASC,WAAW;;AAEpB;AACA,MAAMC,sBAAsB,GAAG,eAAe;AAC9C,MAAMC,0BAA0B,GAAG,mBAAmB;AACtD,MAAMC,aAAa,GAAG,MAAM;AAE5B,MAAMC,cAAc,GAAG,cAAc;AACrC,MAAMC,cAAc,GAAG,cAAc;AACrC,MAAMC,aAAa,GAAG,MAAM;AAC5B,MAAMC,eAAe,GAAG,QAAQ;AAChC,MAAMC,iBAAiB,GAAG,UAAU;AAEpC,MAAMC,eAAe,GAAG,mBAAmB;AAE3C,MAAMC,oBAAoB,GAAG,wBAAwB;AAErD,OAAO,MAAMC,KAAK,GAAG;EACnB;EACAC,OAAO,EAAE,SAAS;EAClB;EACAC,MAAM,EAAE,QAAQ;EAChB;EACAC,MAAM,EAAE;AACV,CAAC;AAED,OAAO,MAAMC,gBAAgB,GAAG,kBAAkB;;AAElD;AACA;AACA;AACA;AACA,SAASC,WAAWA,CAACC,GAAG,EAAE;EACxB,MAAMC,SAAS,GAAGpB,GAAG,CAACqB,OAAO,CAACF,GAAG,CAAC,IAAIA,GAAG,CAACL,OAAO,CAACQ,MAAM,GAAG,CAAC;EAE5D,IAAI,CAACF,SAAS,EAAE;IACd,OAAO,CAAC,CA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B;IAC/BE;EACF,CAAC;EAED,OAAO;IACL2C,IAAI,EAAEvE,KAAK,CAACG,MAAM;IAClB0F,SAAS,EAAE,IAAI;IACflD,IAAI,EAAEyC,cAAc;IACpBU,UAAU,EAAEK,QAAQ;IACpBd,SAAS,EAAED,cAAc;IACzBK,QAAQ;IACRlE,MAAM;IACNsB,IAAI;IACJ6C,MAAM;IACNK,OAAO,EAAE;MAAEJ,cAAc;MAAEY;IAAY;EACzC,CAAC;AACH;;AAEA;;AAEA;AACA;AACA;AACA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -343,9 +343,14 @@ export const manualPayloadSchema = Joi.object()
|
|
|
343
343
|
'*': 'Enter town or city'
|
|
344
344
|
}),
|
|
345
345
|
[countyFieldName]: Joi.string().trim().allow('').required(),
|
|
346
|
-
[postcodeFieldName]: Joi.string()
|
|
347
|
-
|
|
348
|
-
|
|
346
|
+
[postcodeFieldName]: Joi.string()
|
|
347
|
+
.pattern(/^[a-zA-Z]{1,2}\d[a-zA-Z\d]?\s?\d[a-zA-Z]{2}$/)
|
|
348
|
+
.trim()
|
|
349
|
+
.required()
|
|
350
|
+
.messages({
|
|
351
|
+
'string.pattern.base': 'Enter a valid postcode',
|
|
352
|
+
'*': 'Enter postcode'
|
|
353
|
+
})
|
|
349
354
|
})
|
|
350
355
|
.required()
|
|
351
356
|
|