@defra/forms-engine-plugin 5.0.0-alpha.23 → 5.0.0-alpha.25
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/.public/javascripts/shared.min.js +1 -1
- package/.public/javascripts/shared.min.js.map +1 -1
- package/.server/client/javascripts/geospatial-map.d.ts +6 -0
- package/.server/client/javascripts/geospatial-map.js +2 -2
- package/.server/client/javascripts/geospatial-map.js.map +1 -1
- package/.server/client/javascripts/geospatial-map.test.js +152 -0
- package/.server/client/javascripts/geospatial-map.test.js.map +1 -0
- package/.server/client/javascripts/map.d.ts +2 -2
- package/.server/client/javascripts/map.js +0 -1
- package/.server/client/javascripts/map.js.map +1 -1
- package/.server/server/plugins/engine/components/ComponentCollection.js +1 -1
- package/.server/server/plugins/engine/components/ComponentCollection.js.map +1 -1
- package/.server/server/plugins/engine/components/helpers/geospatial.js +0 -1
- package/.server/server/plugins/engine/components/helpers/geospatial.js.map +1 -1
- package/.server/server/plugins/engine/views/summary.html +1 -0
- package/.server/server/plugins/nunjucks/enviroment.test.js +11 -4
- package/.server/server/plugins/nunjucks/enviroment.test.js.map +1 -1
- package/.server/server/plugins/postcode-lookup/models/index.js +16 -3
- package/.server/server/plugins/postcode-lookup/models/index.js.map +1 -1
- package/.server/server/plugins/postcode-lookup/routes/index.js +17 -3
- package/.server/server/plugins/postcode-lookup/routes/index.js.map +1 -1
- package/.server/typings/geodesy/index.d.js +2 -0
- package/.server/typings/geodesy/index.d.js.map +1 -0
- package/package.json +1 -1
- package/src/client/javascripts/geospatial-map.js +2 -2
- package/src/client/javascripts/map.js +0 -1
- package/src/server/plugins/engine/components/ComponentCollection.ts +1 -4
- package/src/server/plugins/engine/components/helpers/geospatial.ts +0 -1
- package/src/server/plugins/engine/views/summary.html +1 -0
- package/src/server/plugins/postcode-lookup/models/index.js +16 -3
- package/src/server/plugins/postcode-lookup/routes/index.js +23 -8
- package/src/typings/geodesy/index.d.ts +18 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Joi","t","i18nT","service","crumbSchema","postcodeQueryFieldName","buildingNameQueryFieldName","uprnFieldName","line1FieldName","line2FieldName","townFieldName","countyFieldName","postcodeFieldName","GOVUK_MARGIN_RIGHT_1","COMMON_BACK","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","language","id","name","label","hint","value","errorMessage","getSelectFields","payload","selectAddressText","type","uprn","items","concat","map","formatted","getManualFields","addressLine1","addressLine2","classes","town","county","postcode","stepSchema","string","valid","Object","keys","required","sharedPayloadSchemaKeys","crumb","step","createDetailsPayloadSchema","object","pattern","trim","messages","allow","createSelectPayloadSchema","createManualPayloadSchema","getHref","query","detailsViewModel","data","translator","componentId","componentHint","sourceUrl","languages","initial","tComponent","tForm","component","backLink","fields","continueButton","manualLink","selector","showTitle","serviceUrl","pageTitle","buttons","selectViewModel","session","title","formPath","searchAgainText","searchAgainLink","addressesFoundText","count","noAddressFoundText","manualViewModel","detailsLink"],"sources":["../../../../../src/server/plugins/postcode-lookup/models/index.js"],"sourcesContent":["import Joi from 'joi'\n\nimport { t as i18nT } from '~/src/server/plugins/engine/i18n/index.js'\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 GOVUK_MARGIN_RIGHT_1 = 'govuk-!-margin-right-1'\nconst COMMON_BACK = 'common.back'\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 * @param {string} language\n */\nfunction getDetailsFields(\n details,\n postcodeQueryError,\n buildingNameQueryError,\n language\n) {\n return {\n [postcodeQueryFieldName]: {\n id: postcodeQueryFieldName,\n name: postcodeQueryFieldName,\n label: {\n text: i18nT('postcodeLookup.postcodeLabel', language)\n },\n hint: {\n text: i18nT('postcodeLookup.postcodeHint', language)\n },\n value: details?.postcodeQuery,\n errorMessage: postcodeQueryError && { text: postcodeQueryError.message }\n },\n [buildingNameQueryFieldName]: {\n id: buildingNameQueryFieldName,\n name: buildingNameQueryFieldName,\n label: {\n text: i18nT('postcodeLookup.buildingNameLabel', language)\n },\n hint: {\n text: i18nT('postcodeLookup.buildingNameHint', language)\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 * @param {string} language\n */\nfunction getSelectFields(\n details,\n hasMultipleAddresses,\n singleAddress,\n payload,\n uprnError,\n addresses,\n language\n) {\n const selectAddressText = i18nT('postcodeLookup.selectAddress', language)\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: selectAddressText\n }\n : undefined,\n value: singleAddress ? singleAddress.uprn : payload?.uprn,\n errorMessage: uprnError && { text: uprnError.message },\n items: hasMultipleAddresses\n ? [{ text: selectAddressText, 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 * @param {string} language\n */\nfunction getManualFields(\n payload,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError,\n language\n) {\n return {\n [line1FieldName]: {\n id: line1FieldName,\n name: line1FieldName,\n label: {\n text: i18nT('postcodeLookup.addressLine1Label', language)\n },\n value: payload?.addressLine1,\n errorMessage: line1Error && { text: line1Error.message }\n },\n [line2FieldName]: {\n id: line2FieldName,\n name: line2FieldName,\n label: {\n text: i18nT('postcodeLookup.addressLine2Label', language)\n },\n value: payload?.addressLine2,\n errorMessage: line2Error && { text: line2Error.message }\n },\n [townFieldName]: {\n id: townFieldName,\n name: townFieldName,\n label: {\n text: i18nT('postcodeLookup.townLabel', language)\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: i18nT('postcodeLookup.countyLabel', language)\n },\n value: payload?.county,\n errorMessage: countyError && { text: countyError.message }\n },\n [postcodeFieldName]: {\n id: postcodeFieldName,\n name: postcodeFieldName,\n label: {\n text: i18nT('postcodeLookup.postcodeLabel', language)\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 * @param {string} [language]\n * @returns {ObjectSchema<PostcodeLookupDetailsPayload>}\n */\nexport function createDetailsPayloadSchema(language = 'en-GB') {\n return 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': i18nT(\n 'postcodeLookup.validation.invalidPostcode',\n language\n ),\n '*': i18nT('postcodeLookup.validation.requiredPostcode', language)\n }),\n [buildingNameQueryFieldName]: Joi.string()\n .trim()\n .required()\n .allow('')\n .trim()\n })\n .required()\n}\n\n/**\n * Postcode lookup select form payload schema\n * @param {string} [language]\n * @returns {ObjectSchema<PostcodeLookupSelectPayload>}\n */\nexport function createSelectPayloadSchema(language = 'en-GB') {\n return Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [uprnFieldName]: Joi.string()\n .required()\n .messages({\n '*': i18nT('postcodeLookup.validation.selectAddress', language)\n })\n })\n .required()\n}\n\n/**\n * Postcode lookup manual form payload schema\n * @param {string} [language]\n * @returns {ObjectSchema<PostcodeLookupManualPayload>}\n */\nexport function createManualPayloadSchema(language = 'en-GB') {\n return Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [line1FieldName]: Joi.string()\n .trim()\n .required()\n .messages({\n '*': i18nT('postcodeLookup.validation.requiredAddressLine1', language)\n }),\n [line2FieldName]: Joi.string().trim().allow('').required(),\n [townFieldName]: Joi.string()\n .trim()\n .required()\n .messages({\n '*': i18nT('postcodeLookup.validation.requiredTown', language)\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': i18nT(\n 'postcodeLookup.validation.invalidManualPostcode',\n language\n ),\n '*': i18nT(\n 'postcodeLookup.validation.requiredManualPostcode',\n language\n )\n })\n })\n .required()\n}\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 {Translator} translator\n * @param {PostcodeLookupDetailsData} [payload]\n * @param {Error} [err]\n */\nexport function detailsViewModel(data, translator, payload, err) {\n const { componentId, componentHint, sourceUrl, languages } = data.initial\n\n const { t, tComponent, tForm } = translator\n\n const component = /** @type {ComponentDef} */ ({ id: componentId })\n\n const backLink = {\n href: sourceUrl,\n text: t(COMMON_BACK)\n }\n\n const { errors, postcodeQueryError, buildingNameQueryError } =\n buildErrors(err)\n\n const fields = getDetailsFields(\n payload ?? data.details,\n postcodeQueryError,\n buildingNameQueryError,\n translator.language\n )\n\n const hint = componentHint && {\n text: tComponent(component, 'hint')\n }\n\n const continueButton = {\n text: t('postcodeLookup.findAddress'),\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const manualLink = {\n text: t('postcodeLookup.enterManually'),\n href: getHref(steps.manual)\n }\n\n const selector = languages?.length ? { languages } : {}\n\n return {\n step: steps.details,\n showTitle: true,\n name: tForm('title'),\n serviceUrl: sourceUrl,\n pageTitle: tComponent(component, 'title'),\n hint,\n backLink,\n errors,\n fields,\n buttons: { continueButton, manualLink },\n t,\n language: translator.language,\n ...selector\n }\n}\n\n/**\n * The postcode lookup select form view model\n * @param {{ session: PostcodeLookupSessionData, apiKey: string }} data\n * @param {Translator} translator\n * @param {PostcodeLookupSelectPayload} [payload]\n * @param {Error} [err]\n */\nexport async function selectViewModel(data, translator, payload, err) {\n const { session, apiKey } = data\n const { details, initial } = session\n const { postcodeQuery, buildingNameQuery } = details\n const { language, t, tComponent, tForm } = translator\n\n const {\n hasAddresses,\n hasMultipleAddresses,\n singleAddress,\n addresses,\n addressCount\n } = await getAddresses(postcodeQuery, buildingNameQuery, apiKey)\n\n const title = hasAddresses\n ? tComponent(\n /** @type {ComponentDef} */ ({ id: initial.componentId }),\n 'title'\n )\n : t('postcodeLookup.noAddressFoundTitle')\n const formPath = initial.sourceUrl\n const href = getHref()\n\n const backLink = {\n href,\n text: t(COMMON_BACK)\n }\n\n const { errors, uprnError } = buildErrors(err)\n\n const fields = getSelectFields(\n details,\n hasMultipleAddresses,\n singleAddress,\n payload,\n uprnError,\n addresses,\n language\n )\n\n const searchAgainText = t('postcodeLookup.searchAgain')\n\n const searchAgainLink = {\n text: searchAgainText,\n href\n }\n\n const continueButton = {\n href: hasAddresses ? undefined : href,\n text: hasAddresses ? t('postcodeLookup.useThisAddress') : searchAgainText,\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const manualLink = {\n text: t('postcodeLookup.enterManually'),\n href: `${href}?step=${steps.manual}`\n }\n\n const addressesFoundText = hasAddresses\n ? t('postcodeLookup.addressFound', { count: addressCount })\n : undefined\n const noAddressFoundText = !hasAddresses\n ? t('postcodeLookup.noAddressFoundBody')\n : undefined\n\n const selector = initial.languages?.length\n ? { languages: initial.languages }\n : {}\n\n return {\n step: steps.select,\n showTitle: true,\n name: tForm('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 addressesFoundText,\n noAddressFoundText,\n buttons: { continueButton, manualLink },\n t,\n language,\n ...selector\n }\n}\n\n/**\n * The postcode lookup manual form view model\n * @param {PostcodeLookupSessionData} data\n * @param {Translator} translator\n * @param {PostcodeLookupManualPayload} [payload]\n * @param {Error} [err]\n */\nexport function manualViewModel(data, translator, payload, err) {\n const { componentId, sourceUrl, componentHint, languages } = data.initial\n const formPath = sourceUrl\n const href = getHref()\n\n const { t, tComponent, tForm } = translator\n\n const component = /** @type {ComponentDef} */ ({ id: componentId })\n\n const backLink = {\n href,\n text: t(COMMON_BACK)\n }\n\n const {\n errors,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n } = buildErrors(err)\n\n const hint = componentHint && {\n text: tComponent(component, 'hint')\n }\n\n const fields = getManualFields(\n payload,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError,\n translator.language\n )\n\n const continueButton = {\n text: t('postcodeLookup.useThisAddress'),\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const detailsLink = {\n text: t('postcodeLookup.findAnAddressInstead'),\n href\n }\n\n const selector = languages?.length ? { languages } : {}\n\n return {\n step: steps.manual,\n showTitle: true,\n name: tForm('title'),\n serviceUrl: formPath,\n pageTitle: tComponent(component, 'title'),\n backLink,\n errors,\n hint,\n fields,\n buttons: { continueButton, detailsLink },\n t,\n language: translator.language,\n ...selector\n }\n}\n\n/** @typedef { ValidationErrorItem | undefined } OptionalValidationErrorItem */\n\n/**\n * @import { ObjectSchema, ValidationErrorItem } from 'joi'\n * @import { ComponentDef } from '@defra/forms-model'\n * @import { Address, PostcodeLookupDetailsData, PostcodeLookupDetailsPayload, PostcodeLookupManualPayload, PostcodeLookupSelectPayload, PostcodeLookupSessionData } from '~/src/server/plugins/postcode-lookup/types.js'\n * @import { Translator } from '~/src/server/plugins/engine/i18n/types.js'\n */\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AAErB,SAASC,CAAC,IAAIC,KAAK;AACnB,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,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;AACA;AACA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Joi","t","i18nT","service","crumbSchema","postcodeQueryFieldName","buildingNameQueryFieldName","uprnFieldName","line1FieldName","line2FieldName","townFieldName","countyFieldName","postcodeFieldName","GOVUK_MARGIN_RIGHT_1","COMMON_BACK","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","language","id","name","label","hint","value","errorMessage","getSelectFields","payload","selectAddressText","type","uprn","items","concat","map","formatted","getManualFields","addressLine1","addressLine2","classes","town","county","postcode","stepSchema","string","valid","Object","keys","required","detailsObjectSchema","object","bind","selectObjectSchema","manualObjectSchema","sharedPayloadSchemaKeys","crumb","step","createDetailsPayloadSchema","pattern","trim","messages","allow","createSelectPayloadSchema","createManualPayloadSchema","getHref","query","detailsViewModel","data","translator","componentId","componentHint","sourceUrl","languages","initial","tComponent","tForm","component","backLink","fields","continueButton","manualLink","selector","showTitle","serviceUrl","pageTitle","buttons","selectViewModel","session","title","formPath","searchAgainText","searchAgainLink","addressesFoundText","count","noAddressFoundText","manualViewModel","detailsLink"],"sources":["../../../../../src/server/plugins/postcode-lookup/models/index.js"],"sourcesContent":["import Joi from 'joi'\n\nimport { t as i18nT } from '~/src/server/plugins/engine/i18n/index.js'\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 GOVUK_MARGIN_RIGHT_1 = 'govuk-!-margin-right-1'\nconst COMMON_BACK = 'common.back'\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 * @param {string} language\n */\nfunction getDetailsFields(\n details,\n postcodeQueryError,\n buildingNameQueryError,\n language\n) {\n return {\n [postcodeQueryFieldName]: {\n id: postcodeQueryFieldName,\n name: postcodeQueryFieldName,\n label: {\n text: i18nT('postcodeLookup.postcodeLabel', language)\n },\n hint: {\n text: i18nT('postcodeLookup.postcodeHint', language)\n },\n value: details?.postcodeQuery,\n errorMessage: postcodeQueryError && { text: postcodeQueryError.message }\n },\n [buildingNameQueryFieldName]: {\n id: buildingNameQueryFieldName,\n name: buildingNameQueryFieldName,\n label: {\n text: i18nT('postcodeLookup.buildingNameLabel', language)\n },\n hint: {\n text: i18nT('postcodeLookup.buildingNameHint', language)\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 * @param {string} language\n */\nfunction getSelectFields(\n details,\n hasMultipleAddresses,\n singleAddress,\n payload,\n uprnError,\n addresses,\n language\n) {\n const selectAddressText = i18nT('postcodeLookup.selectAddress', language)\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: selectAddressText\n }\n : undefined,\n value: singleAddress ? singleAddress.uprn : payload?.uprn,\n errorMessage: uprnError && { text: uprnError.message },\n items: hasMultipleAddresses\n ? [{ text: selectAddressText, 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 * @param {string} language\n */\nfunction getManualFields(\n payload,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError,\n language\n) {\n return {\n [line1FieldName]: {\n id: line1FieldName,\n name: line1FieldName,\n label: {\n text: i18nT('postcodeLookup.addressLine1Label', language)\n },\n value: payload?.addressLine1,\n errorMessage: line1Error && { text: line1Error.message }\n },\n [line2FieldName]: {\n id: line2FieldName,\n name: line2FieldName,\n label: {\n text: i18nT('postcodeLookup.addressLine2Label', language)\n },\n value: payload?.addressLine2,\n errorMessage: line2Error && { text: line2Error.message }\n },\n [townFieldName]: {\n id: townFieldName,\n name: townFieldName,\n label: {\n text: i18nT('postcodeLookup.townLabel', language)\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: i18nT('postcodeLookup.countyLabel', language)\n },\n value: payload?.county,\n errorMessage: countyError && { text: countyError.message }\n },\n [postcodeFieldName]: {\n id: postcodeFieldName,\n name: postcodeFieldName,\n label: {\n text: i18nT('postcodeLookup.postcodeLabel', language)\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\n/**\n * Joi object schema factories typed with their payload, as JavaScript files\n * cannot pass type arguments to `Joi.object<T>()`\n */\n/** @type {() => ObjectSchema<PostcodeLookupDetailsPayload>} */\nconst detailsObjectSchema = Joi.object.bind(Joi)\n\n/** @type {() => ObjectSchema<PostcodeLookupSelectPayload>} */\nconst selectObjectSchema = Joi.object.bind(Joi)\n\n/** @type {() => ObjectSchema<PostcodeLookupManualPayload>} */\nconst manualObjectSchema = Joi.object.bind(Joi)\n\nconst sharedPayloadSchemaKeys = {\n crumb: crumbSchema,\n step: stepSchema\n}\n\n/**\n * Postcode lookup details form payload schema\n * @param {string} [language]\n * @returns {ObjectSchema<PostcodeLookupDetailsPayload>}\n */\nexport function createDetailsPayloadSchema(language = 'en-GB') {\n return detailsObjectSchema()\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': i18nT(\n 'postcodeLookup.validation.invalidPostcode',\n language\n ),\n '*': i18nT('postcodeLookup.validation.requiredPostcode', language)\n }),\n [buildingNameQueryFieldName]: Joi.string()\n .trim()\n .required()\n .allow('')\n .trim()\n })\n .required()\n}\n\n/**\n * Postcode lookup select form payload schema\n * @param {string} [language]\n * @returns {ObjectSchema<PostcodeLookupSelectPayload>}\n */\nexport function createSelectPayloadSchema(language = 'en-GB') {\n return selectObjectSchema()\n .keys({\n ...sharedPayloadSchemaKeys,\n [uprnFieldName]: Joi.string()\n .required()\n .messages({\n '*': i18nT('postcodeLookup.validation.selectAddress', language)\n })\n })\n .required()\n}\n\n/**\n * Postcode lookup manual form payload schema\n * @param {string} [language]\n * @returns {ObjectSchema<PostcodeLookupManualPayload>}\n */\nexport function createManualPayloadSchema(language = 'en-GB') {\n return manualObjectSchema()\n .keys({\n ...sharedPayloadSchemaKeys,\n [line1FieldName]: Joi.string()\n .trim()\n .required()\n .messages({\n '*': i18nT('postcodeLookup.validation.requiredAddressLine1', language)\n }),\n [line2FieldName]: Joi.string().trim().allow('').required(),\n [townFieldName]: Joi.string()\n .trim()\n .required()\n .messages({\n '*': i18nT('postcodeLookup.validation.requiredTown', language)\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': i18nT(\n 'postcodeLookup.validation.invalidManualPostcode',\n language\n ),\n '*': i18nT(\n 'postcodeLookup.validation.requiredManualPostcode',\n language\n )\n })\n })\n .required()\n}\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 {Translator} translator\n * @param {PostcodeLookupDetailsData} [payload]\n * @param {Error} [err]\n */\nexport function detailsViewModel(data, translator, payload, err) {\n const { componentId, componentHint, sourceUrl, languages } = data.initial\n\n const { t, tComponent, tForm } = translator\n\n const component = /** @type {ComponentDef} */ ({ id: componentId })\n\n const backLink = {\n href: sourceUrl,\n text: t(COMMON_BACK)\n }\n\n const { errors, postcodeQueryError, buildingNameQueryError } =\n buildErrors(err)\n\n const fields = getDetailsFields(\n payload ?? data.details,\n postcodeQueryError,\n buildingNameQueryError,\n translator.language\n )\n\n const hint = componentHint && {\n text: tComponent(component, 'hint')\n }\n\n const continueButton = {\n text: t('postcodeLookup.findAddress'),\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const manualLink = {\n text: t('postcodeLookup.enterManually'),\n href: getHref(steps.manual)\n }\n\n const selector = languages?.length ? { languages } : {}\n\n return {\n step: steps.details,\n showTitle: true,\n name: tForm('title'),\n serviceUrl: sourceUrl,\n pageTitle: tComponent(component, 'title'),\n hint,\n backLink,\n errors,\n fields,\n buttons: { continueButton, manualLink },\n t,\n language: translator.language,\n ...selector\n }\n}\n\n/**\n * The postcode lookup select form view model\n * @param {{ session: PostcodeLookupSessionData, apiKey: string }} data\n * @param {Translator} translator\n * @param {PostcodeLookupSelectPayload} [payload]\n * @param {Error} [err]\n */\nexport async function selectViewModel(data, translator, payload, err) {\n const { session, apiKey } = data\n const { details, initial } = session\n const { postcodeQuery, buildingNameQuery } = details\n const { language, t, tComponent, tForm } = translator\n\n const {\n hasAddresses,\n hasMultipleAddresses,\n singleAddress,\n addresses,\n addressCount\n } = await getAddresses(postcodeQuery, buildingNameQuery, apiKey)\n\n const title = hasAddresses\n ? tComponent(\n /** @type {ComponentDef} */ ({ id: initial.componentId }),\n 'title'\n )\n : t('postcodeLookup.noAddressFoundTitle')\n const formPath = initial.sourceUrl\n const href = getHref()\n\n const backLink = {\n href,\n text: t(COMMON_BACK)\n }\n\n const { errors, uprnError } = buildErrors(err)\n\n const fields = getSelectFields(\n details,\n hasMultipleAddresses,\n singleAddress,\n payload,\n uprnError,\n addresses,\n language\n )\n\n const searchAgainText = t('postcodeLookup.searchAgain')\n\n const searchAgainLink = {\n text: searchAgainText,\n href\n }\n\n const continueButton = {\n href: hasAddresses ? undefined : href,\n text: hasAddresses ? t('postcodeLookup.useThisAddress') : searchAgainText,\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const manualLink = {\n text: t('postcodeLookup.enterManually'),\n href: `${href}?step=${steps.manual}`\n }\n\n const addressesFoundText = hasAddresses\n ? t('postcodeLookup.addressFound', { count: addressCount })\n : undefined\n const noAddressFoundText = !hasAddresses\n ? t('postcodeLookup.noAddressFoundBody')\n : undefined\n\n const selector = initial.languages?.length\n ? { languages: initial.languages }\n : {}\n\n return {\n step: steps.select,\n showTitle: true,\n name: tForm('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 addressesFoundText,\n noAddressFoundText,\n buttons: { continueButton, manualLink },\n t,\n language,\n ...selector\n }\n}\n\n/**\n * The postcode lookup manual form view model\n * @param {PostcodeLookupSessionData} data\n * @param {Translator} translator\n * @param {PostcodeLookupManualPayload} [payload]\n * @param {Error} [err]\n */\nexport function manualViewModel(data, translator, payload, err) {\n const { componentId, sourceUrl, componentHint, languages } = data.initial\n const formPath = sourceUrl\n const href = getHref()\n\n const { t, tComponent, tForm } = translator\n\n const component = /** @type {ComponentDef} */ ({ id: componentId })\n\n const backLink = {\n href,\n text: t(COMMON_BACK)\n }\n\n const {\n errors,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n } = buildErrors(err)\n\n const hint = componentHint && {\n text: tComponent(component, 'hint')\n }\n\n const fields = getManualFields(\n payload,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError,\n translator.language\n )\n\n const continueButton = {\n text: t('postcodeLookup.useThisAddress'),\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const detailsLink = {\n text: t('postcodeLookup.findAnAddressInstead'),\n href\n }\n\n const selector = languages?.length ? { languages } : {}\n\n return {\n step: steps.manual,\n showTitle: true,\n name: tForm('title'),\n serviceUrl: formPath,\n pageTitle: tComponent(component, 'title'),\n backLink,\n errors,\n hint,\n fields,\n buttons: { continueButton, detailsLink },\n t,\n language: translator.language,\n ...selector\n }\n}\n\n/** @typedef { ValidationErrorItem | undefined } OptionalValidationErrorItem */\n\n/**\n * @import { ObjectSchema, ValidationErrorItem } from 'joi'\n * @import { ComponentDef } from '@defra/forms-model'\n * @import { Address, PostcodeLookupDetailsData, PostcodeLookupDetailsPayload, PostcodeLookupManualPayload, PostcodeLookupSelectPayload, PostcodeLookupSessionData } from '~/src/server/plugins/postcode-lookup/types.js'\n * @import { Translator } from '~/src/server/plugins/engine/i18n/types.js'\n */\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AAErB,SAASC,CAAC,IAAIC,KAAK;AACnB,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,oBAAoB,GAAG,wBAAwB;AACrD,MAAMC,WAAW,GAAG,aAAa;AAEjC,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,GAAGtB,GAAG,CAACuB,OAAO,CAACF,GAAG,CAAC,IAAIA,GAAG,CAACL,OAAO,CAACQ,MAAM,GAAG,CAAC;EAE5D,IAAI,CAACF,SAAS,EAAE;IACd,OAAO,CAAC,CAAC;EACX;;EAEA;AACF;AACA;AACA;EACE,MAAMG,QAAQ,GAAIC,SAAS,IAAK;IAC9B,OAAOL,GAAG,CAACL,OAAO,CAACW,IAAI,CAAEC,IAAI,IAAKA,IAAI,CAACC,IAAI,CAAC,CAAC,CAAC,KAAKH,SAAS,CAAC;EAC/D,CAAC;EAED,MAAMI,kBAAkB,GAAGL,QAAQ,CAACpB,sBAAsB,CAAC;EAC3D,MAAM0B,sBAAsB,GAAGN,QAAQ,CAACnB,0BAA0B,C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,IAAI,EAAExC,CAAC,CAAC,qCAAqC,CAAC;IAC9C0C;EACF,CAAC;EAED,MAAM2E,QAAQ,GAAGT,SAAS,EAAErF,MAAM,GAAG;IAAEqF;EAAU,CAAC,GAAG,CAAC,CAAC;EAEvD,OAAO;IACLhB,IAAI,EAAE9E,KAAK,CAACG,MAAM;IAClBqG,SAAS,EAAE,IAAI;IACf5D,IAAI,EAAEqD,KAAK,CAAC,OAAO,CAAC;IACpBQ,UAAU,EAAEM,QAAQ;IACpBL,SAAS,EAAEV,UAAU,CAACE,SAAS,EAAE,OAAO,CAAC;IACzCC,QAAQ;IACR5E,MAAM;IACNuB,IAAI;IACJsD,MAAM;IACNO,OAAO,EAAE;MAAEN,cAAc;MAAEiB;IAAY,CAAC;IACxCpI,CAAC;IACDwD,QAAQ,EAAEgD,UAAU,CAAChD,QAAQ;IAC7B,GAAG6D;EACL,CAAC;AACH;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -175,6 +175,19 @@ function postRoute(options) {
|
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Validate a payload against a schema. Joi types the value as `any` when
|
|
180
|
+
* validation fails, so it is typed here as the partially converted payload.
|
|
181
|
+
* @template TSchema
|
|
182
|
+
* @param {ObjectSchema<TSchema>} schema
|
|
183
|
+
* @param {unknown} payload
|
|
184
|
+
* @param {ValidationOptions} [options]
|
|
185
|
+
* @returns {{ value: TSchema, error: undefined } | { value: TSchema | undefined, error: ValidationError }}
|
|
186
|
+
*/
|
|
187
|
+
function validatePayload(schema, payload, options) {
|
|
188
|
+
return schema.validate(payload, options);
|
|
189
|
+
}
|
|
190
|
+
|
|
178
191
|
/**
|
|
179
192
|
* Post handler for the details step
|
|
180
193
|
* @param {PostcodeLookupPostRequest} request
|
|
@@ -191,7 +204,7 @@ async function detailsPostHandler(request, h, options) {
|
|
|
191
204
|
const {
|
|
192
205
|
value: details,
|
|
193
206
|
error
|
|
194
|
-
} = createDetailsPayloadSchema(language)
|
|
207
|
+
} = validatePayload(createDetailsPayloadSchema(language), request.payload);
|
|
195
208
|
let model;
|
|
196
209
|
if (error) {
|
|
197
210
|
model = detailsViewModel(session, translator, details, error);
|
|
@@ -231,7 +244,7 @@ async function selectPostHandler(request, h, options) {
|
|
|
231
244
|
const {
|
|
232
245
|
value: select,
|
|
233
246
|
error
|
|
234
|
-
} = createSelectPayloadSchema(language)
|
|
247
|
+
} = validatePayload(createSelectPayloadSchema(language), request.payload);
|
|
235
248
|
if (error) {
|
|
236
249
|
const model = await selectViewModel({
|
|
237
250
|
session,
|
|
@@ -266,7 +279,7 @@ async function manualPostHandler(request, h) {
|
|
|
266
279
|
const {
|
|
267
280
|
value: manual,
|
|
268
281
|
error
|
|
269
|
-
} = createManualPayloadSchema(language)
|
|
282
|
+
} = validatePayload(createManualPayloadSchema(language), request.payload, {
|
|
270
283
|
abortEarly: false
|
|
271
284
|
});
|
|
272
285
|
if (error) {
|
|
@@ -285,6 +298,7 @@ async function manualPostHandler(request, h) {
|
|
|
285
298
|
|
|
286
299
|
/**
|
|
287
300
|
* @import { ResponseToolkit, ServerRoute } from '@hapi/hapi'
|
|
301
|
+
* @import { ObjectSchema, ValidationError, ValidationOptions } from 'joi'
|
|
288
302
|
* @import { FormMetadata } from '@defra/forms-model'
|
|
289
303
|
* @import { PostcodeLookupManualPayload, Address, PostcodeLookupGetRequestRefs, PostcodeLookupPostRequestRefs, PostcodeLookupRequest, PostcodeLookupPostRequest, PostcodeLookupConfiguration, PostcodeLookupDispatchData, PostcodeLookupSessionData } from '../../../../server/plugins/postcode-lookup/types.js'
|
|
290
304
|
* @import { FormRequestPayload, FormResponseToolkit } from '../../../../server/routes/types.js'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Boom","StatusCodes","Joi","EXTERNAL_STATE_APPENDAGE","getCachedPluginTranslator","JOURNEY_BASE_URL","createDetailsPayloadSchema","createManualPayloadSchema","createSelectPayloadSchema","detailsViewModel","manualViewModel","selectViewModel","stepSchema","steps","service","resolveLanguage","viewName","getSessionState","request","state","yar","get","badRequest","flashComponentState","componentName","address","addressState","addressLine1","addressLine2","town","county","postcode","uprn","undefined","appendage","component","data","flash","getDispatchTranslator","initial","language","formId","formStatus","set","typedReq","lang","translator","id","dispatch","h","details","postcodeQuery","buildingNameQuery","query","step","redirect","code","SEE_OTHER","getRoutes","options","getRoute","postRoute","method","path","handler","session","model","manual","view","validate","object","keys","string","allow","optional","payload","detailsPostHandler","select","selectPostHandler","manualPostHandler","unknown","ordnanceSurveyApiKey","apiKey","value","error","addresses","searchByUPRN","property","at","internal","sourceUrl","abortEarly"],"sources":["../../../../../src/server/plugins/postcode-lookup/routes/index.js"],"sourcesContent":["import Boom from '@hapi/boom'\nimport { StatusCodes } from 'http-status-codes'\nimport Joi from 'joi'\n\nimport { EXTERNAL_STATE_APPENDAGE } from '~/src/server/constants.js'\nimport { getCachedPluginTranslator } from '~/src/server/plugins/engine/i18n/form.js'\nimport {\n JOURNEY_BASE_URL,\n createDetailsPayloadSchema,\n createManualPayloadSchema,\n createSelectPayloadSchema,\n detailsViewModel,\n manualViewModel,\n selectViewModel,\n stepSchema,\n steps\n} from '~/src/server/plugins/postcode-lookup/models/index.js'\nimport * as service from '~/src/server/plugins/postcode-lookup/service.js'\nimport { resolveLanguage } from '~/src/server/utils/utils.js'\n\nconst viewName = 'postcode-lookup-details'\n\n/**\n * Get the session state associated with this journey\n * @param {PostcodeLookupRequest} request\n */\nexport function getSessionState(request) {\n /**\n * @type {PostcodeLookupSessionData | null | undefined}\n */\n const state = request.yar.get(JOURNEY_BASE_URL)\n\n if (!state) {\n throw Boom.badRequest(\n `No postcode lookup data found for ${JOURNEY_BASE_URL}`\n )\n }\n\n return state\n}\n\n/**\n * Flash form component state\n * @param {PostcodeLookupRequest} request - the request\n * @param {string} componentName - the component name\n * @param {Address | PostcodeLookupManualPayload} address - the address from ordnance survey or manually entered\n */\nfunction flashComponentState(request, componentName, address) {\n const addressState = {\n addressLine1: address.addressLine1,\n addressLine2: address.addressLine2,\n town: address.town,\n county: address.county,\n postcode: address.postcode,\n uprn: 'uprn' in address && address.uprn ? address.uprn : undefined\n }\n\n /**\n * @type {ExternalStateAppendage}\n */\n const appendage = {\n component: componentName,\n data: addressState\n }\n\n request.yar.flash(EXTERNAL_STATE_APPENDAGE, appendage, true)\n}\n/**\n * Get a cached translator, or create a new one if not in the cache\n * @param {PostcodeLookupRequest} request\n * @param {PostcodeLookupDispatchData} initial\n * @param { string | string[] | undefined } language\n */\nexport async function getDispatchTranslator(request, initial, language) {\n const { formId, formStatus } = initial\n\n // Override language if passed as a query param\n if (language) {\n request.yar.set('language', language)\n }\n\n const typedReq = /** @type {AnyFormRequest} */ (/** @type {any} */ (request))\n const lang = resolveLanguage(typedReq)\n\n const translator = await getCachedPluginTranslator(\n typedReq,\n /** @type {FormMetadata} */ ({ id: formId }),\n formStatus,\n lang\n )\n\n return translator\n}\n\n/**\n * Initialises and dispatches the request to the postcode lookup journey\n * @param {FormRequestPayload} request - the source page\n * @param {FormResponseToolkit} h - the source page\n * @param {PostcodeLookupDispatchData} initial - the source data\n */\nexport function dispatch(request, h, initial) {\n /**\n * @type {PostcodeLookupSessionData}\n */\n const data = {\n initial,\n details: { postcodeQuery: '', buildingNameQuery: '' }\n }\n\n request.yar.set(JOURNEY_BASE_URL, data)\n\n const query = initial.step ? `?step=${initial.step}` : ''\n\n return h.redirect(`${JOURNEY_BASE_URL}${query}`).code(StatusCodes.SEE_OTHER)\n}\n\n/**\n * Gets the postcode lookup routes\n * @param {PostcodeLookupConfiguration} options - ordnance survey api key\n */\nexport function getRoutes(options) {\n return [getRoute(), postRoute(options)]\n}\n\n/**\n * @returns {ServerRoute<PostcodeLookupGetRequestRefs>}\n */\nfunction getRoute() {\n return {\n method: 'GET',\n path: JOURNEY_BASE_URL,\n async handler(request, h) {\n const { query } = request\n const { step, language } = query\n const session = getSessionState(request)\n\n const translator = await getDispatchTranslator(\n request,\n session.initial,\n language\n )\n\n const model =\n step === steps.manual\n ? manualViewModel(session, translator)\n : detailsViewModel(session, translator)\n\n return h.view(viewName, model)\n },\n options: {\n validate: {\n query: Joi.object()\n .keys({\n step: Joi.string().allow(steps.details, steps.manual).optional(),\n language: Joi.string().allow('en-GB', 'cy').optional()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * @param {PostcodeLookupConfiguration} options\n * @returns {ServerRoute<PostcodeLookupPostRequestRefs>}\n */\nfunction postRoute(options) {\n return {\n method: 'POST',\n path: JOURNEY_BASE_URL,\n async handler(request, h) {\n const { payload } = request\n const { step } = payload\n\n switch (step) {\n case steps.details: {\n return detailsPostHandler(request, h, options)\n }\n case steps.select: {\n return selectPostHandler(request, h, options)\n }\n case steps.manual: {\n return manualPostHandler(request, h)\n }\n default:\n throw Boom.badRequest(`Invalid step ${step}`)\n }\n },\n options: {\n validate: {\n payload: Joi.object()\n .keys({\n step: stepSchema\n })\n .unknown(true)\n }\n }\n }\n}\n\n/**\n * Post handler for the details step\n * @param {PostcodeLookupPostRequest} request\n * @param {ResponseToolkit<PostcodeLookupPostRequestRefs>} h\n * @param {PostcodeLookupConfiguration} options\n */\nasync function detailsPostHandler(request, h, options) {\n const session = getSessionState(request)\n const { ordnanceSurveyApiKey: apiKey } = options\n const translator = await getDispatchTranslator(\n request,\n session.initial,\n request.query.language\n )\n const language = translator.language\n\n const { value: details, error } = createDetailsPayloadSchema(\n language\n ).validate(request.payload)\n\n let model\n\n if (error) {\n model = detailsViewModel(session, translator, details, error)\n\n return h.view(viewName, model)\n }\n\n const { postcodeQuery, buildingNameQuery } = details\n session.details = { postcodeQuery, buildingNameQuery }\n\n // Store the updated session\n request.yar.set(JOURNEY_BASE_URL, session)\n\n model = await selectViewModel({ session, apiKey }, translator)\n\n return h.view(viewName, model)\n}\n\n/**\n * Post handler for the select step\n * @param {PostcodeLookupPostRequest} request\n * @param {ResponseToolkit<PostcodeLookupPostRequestRefs>} h\n * @param {PostcodeLookupConfiguration} options\n */\nasync function selectPostHandler(request, h, options) {\n const session = getSessionState(request)\n const { ordnanceSurveyApiKey: apiKey } = options\n const translator = await getDispatchTranslator(\n request,\n session.initial,\n request.query.language\n )\n const language = translator.language\n const { value: select, error } = createSelectPayloadSchema(language).validate(\n request.payload\n )\n\n if (error) {\n const model = await selectViewModel(\n { session, apiKey },\n translator,\n select,\n error\n )\n\n return h.view(viewName, model)\n }\n\n const addresses = await service.searchByUPRN(select.uprn, apiKey)\n const property = addresses.at(0)\n\n if (!property) {\n throw Boom.internal(`UPRN ${property} not found`)\n }\n\n const { componentName, sourceUrl } = session.initial\n flashComponentState(request, componentName, property)\n\n // Redirect back to the source form page\n return h.redirect(sourceUrl).code(StatusCodes.SEE_OTHER)\n}\n\n/**\n * Post handler for the manual step\n * @param {PostcodeLookupPostRequest} request\n * @param {ResponseToolkit<PostcodeLookupPostRequestRefs>} h\n */\nasync function manualPostHandler(request, h) {\n const session = getSessionState(request)\n const translator = await getDispatchTranslator(\n request,\n session.initial,\n request.query.language\n )\n const language = translator.language\n\n const { value: manual, error } = createManualPayloadSchema(language).validate(\n request.payload,\n {\n abortEarly: false\n }\n )\n\n if (error) {\n const model = manualViewModel(session, translator, manual, error)\n\n return h.view(viewName, model)\n }\n\n const { componentName, sourceUrl } = session.initial\n flashComponentState(request, componentName, manual)\n\n // Redirect back to the source form page\n return h.redirect(sourceUrl).code(StatusCodes.SEE_OTHER)\n}\n\n/**\n * @import { ResponseToolkit, ServerRoute } from '@hapi/hapi'\n * @import { FormMetadata } from '@defra/forms-model'\n * @import { PostcodeLookupManualPayload, Address, PostcodeLookupGetRequestRefs, PostcodeLookupPostRequestRefs, PostcodeLookupRequest, PostcodeLookupPostRequest, PostcodeLookupConfiguration, PostcodeLookupDispatchData, PostcodeLookupSessionData } from '~/src/server/plugins/postcode-lookup/types.js'\n * @import { FormRequestPayload, FormResponseToolkit } from '~/src/server/routes/types.js'\n * @import { AnyFormRequest, ExternalStateAppendage } from '~/src/server/plugins/engine/types.js'\n */\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,YAAY;AAC7B,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,OAAOC,GAAG,MAAM,KAAK;AAErB,SAASC,wBAAwB;AACjC,SAASC,yBAAyB;AAClC,SACEC,gBAAgB,EAChBC,0BAA0B,EAC1BC,yBAAyB,EACzBC,yBAAyB,EACzBC,gBAAgB,EAChBC,eAAe,EACfC,eAAe,EACfC,UAAU,EACVC,KAAK;AAEP,OAAO,KAAKC,OAAO;AACnB,SAASC,eAAe;AAExB,MAAMC,QAAQ,GAAG,yBAAyB;;AAE1C;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACC,OAAO,EAAE;EACvC;AACF;AACA;EACE,MAAMC,KAAK,GAAGD,OAAO,CAACE,GAAG,CAACC,GAAG,CAAChB,gBAAgB,CAAC;EAE/C,IAAI,CAACc,KAAK,EAAE;IACV,MAAMnB,IAAI,CAACsB,UAAU,CACnB,qCAAqCjB,gBAAgB,EACvD,CAAC;EACH;EAEA,OAAOc,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAASI,mBAAmBA,CAACL,OAAO,EAAEM,aAAa,EAAEC,OAAO,EAAE;EAC5D,MAAMC,YAAY,GAAG;IACnBC,YAAY,EAAEF,OAAO,CAACE,YAAY;IAClCC,YAAY,EAAEH,OAAO,CAACG,YAAY;IAClCC,IAAI,EAAEJ,OAAO,CAACI,IAAI;IAClBC,MAAM,EAAEL,OAAO,CAACK,MAAM;IACtBC,QAAQ,EAAEN,OAAO,CAACM,QAAQ;IAC1BC,IAAI,EAAE,MAAM,IAAIP,OAAO,IAAIA,OAAO,CAACO,IAAI,GAAGP,OAAO,CAACO,IAAI,GAAGC;EAC3D,CAAC;;EAED;AACF;AACA;EACE,MAAMC,SAAS,GAAG;IAChBC,SAAS,EAAEX,aAAa;IACxBY,IAAI,EAAEV;EACR,CAAC;EAEDR,OAAO,C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AAQ,CAC3EnD,OAAO,CAACyD,OAAO,EACf;IACEgB,UAAU,EAAE;EACd,CACF,CAAC;EAED,IAAIP,KAAK,EAAE;IACT,MAAMlB,KAAK,GAAGxD,eAAe,CAACuD,OAAO,EAAEnB,UAAU,EAAEqB,MAAM,EAAEiB,KAAK,CAAC;IAEjE,OAAOnC,CAAC,CAACmB,IAAI,CAACpD,QAAQ,EAAEkD,KAAK,CAAC;EAChC;EAEA,MAAM;IAAE1C,aAAa;IAAEkE;EAAU,CAAC,GAAGzB,OAAO,CAAC1B,OAAO;EACpDhB,mBAAmB,CAACL,OAAO,EAAEM,aAAa,EAAE2C,MAAM,CAAC;;EAEnD;EACA,OAAOlB,CAAC,CAACM,QAAQ,CAACmC,SAAS,CAAC,CAAClC,IAAI,CAACvD,WAAW,CAACwD,SAAS,CAAC;AAC1D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Boom","StatusCodes","Joi","EXTERNAL_STATE_APPENDAGE","getCachedPluginTranslator","JOURNEY_BASE_URL","createDetailsPayloadSchema","createManualPayloadSchema","createSelectPayloadSchema","detailsViewModel","manualViewModel","selectViewModel","stepSchema","steps","service","resolveLanguage","viewName","getSessionState","request","state","yar","get","badRequest","flashComponentState","componentName","address","addressState","addressLine1","addressLine2","town","county","postcode","uprn","undefined","appendage","component","data","flash","getDispatchTranslator","initial","language","formId","formStatus","set","typedReq","lang","translator","id","dispatch","h","details","postcodeQuery","buildingNameQuery","query","step","redirect","code","SEE_OTHER","getRoutes","options","getRoute","postRoute","method","path","handler","session","model","manual","view","validate","object","keys","string","allow","optional","payload","detailsPostHandler","select","selectPostHandler","manualPostHandler","unknown","validatePayload","schema","ordnanceSurveyApiKey","apiKey","value","error","addresses","searchByUPRN","property","at","internal","sourceUrl","abortEarly"],"sources":["../../../../../src/server/plugins/postcode-lookup/routes/index.js"],"sourcesContent":["import Boom from '@hapi/boom'\nimport { StatusCodes } from 'http-status-codes'\nimport Joi from 'joi'\n\nimport { EXTERNAL_STATE_APPENDAGE } from '~/src/server/constants.js'\nimport { getCachedPluginTranslator } from '~/src/server/plugins/engine/i18n/form.js'\nimport {\n JOURNEY_BASE_URL,\n createDetailsPayloadSchema,\n createManualPayloadSchema,\n createSelectPayloadSchema,\n detailsViewModel,\n manualViewModel,\n selectViewModel,\n stepSchema,\n steps\n} from '~/src/server/plugins/postcode-lookup/models/index.js'\nimport * as service from '~/src/server/plugins/postcode-lookup/service.js'\nimport { resolveLanguage } from '~/src/server/utils/utils.js'\n\nconst viewName = 'postcode-lookup-details'\n\n/**\n * Get the session state associated with this journey\n * @param {PostcodeLookupRequest} request\n */\nexport function getSessionState(request) {\n /**\n * @type {PostcodeLookupSessionData | null | undefined}\n */\n const state = request.yar.get(JOURNEY_BASE_URL)\n\n if (!state) {\n throw Boom.badRequest(\n `No postcode lookup data found for ${JOURNEY_BASE_URL}`\n )\n }\n\n return state\n}\n\n/**\n * Flash form component state\n * @param {PostcodeLookupRequest} request - the request\n * @param {string} componentName - the component name\n * @param {Address | PostcodeLookupManualPayload} address - the address from ordnance survey or manually entered\n */\nfunction flashComponentState(request, componentName, address) {\n const addressState = {\n addressLine1: address.addressLine1,\n addressLine2: address.addressLine2,\n town: address.town,\n county: address.county,\n postcode: address.postcode,\n uprn: 'uprn' in address && address.uprn ? address.uprn : undefined\n }\n\n /**\n * @type {ExternalStateAppendage}\n */\n const appendage = {\n component: componentName,\n data: addressState\n }\n\n request.yar.flash(EXTERNAL_STATE_APPENDAGE, appendage, true)\n}\n/**\n * Get a cached translator, or create a new one if not in the cache\n * @param {PostcodeLookupRequest} request\n * @param {PostcodeLookupDispatchData} initial\n * @param { string | string[] | undefined } language\n */\nexport async function getDispatchTranslator(request, initial, language) {\n const { formId, formStatus } = initial\n\n // Override language if passed as a query param\n if (language) {\n request.yar.set('language', language)\n }\n\n const typedReq = /** @type {AnyFormRequest} */ (/** @type {any} */ (request))\n const lang = resolveLanguage(typedReq)\n\n const translator = await getCachedPluginTranslator(\n typedReq,\n /** @type {FormMetadata} */ ({ id: formId }),\n formStatus,\n lang\n )\n\n return translator\n}\n\n/**\n * Initialises and dispatches the request to the postcode lookup journey\n * @param {FormRequestPayload} request - the source page\n * @param {FormResponseToolkit} h - the source page\n * @param {PostcodeLookupDispatchData} initial - the source data\n */\nexport function dispatch(request, h, initial) {\n /**\n * @type {PostcodeLookupSessionData}\n */\n const data = {\n initial,\n details: { postcodeQuery: '', buildingNameQuery: '' }\n }\n\n request.yar.set(JOURNEY_BASE_URL, data)\n\n const query = initial.step ? `?step=${initial.step}` : ''\n\n return h.redirect(`${JOURNEY_BASE_URL}${query}`).code(StatusCodes.SEE_OTHER)\n}\n\n/**\n * Gets the postcode lookup routes\n * @param {PostcodeLookupConfiguration} options - ordnance survey api key\n */\nexport function getRoutes(options) {\n return [getRoute(), postRoute(options)]\n}\n\n/**\n * @returns {ServerRoute<PostcodeLookupGetRequestRefs>}\n */\nfunction getRoute() {\n return {\n method: 'GET',\n path: JOURNEY_BASE_URL,\n async handler(request, h) {\n const { query } = request\n const { step, language } = query\n const session = getSessionState(request)\n\n const translator = await getDispatchTranslator(\n request,\n session.initial,\n language\n )\n\n const model =\n step === steps.manual\n ? manualViewModel(session, translator)\n : detailsViewModel(session, translator)\n\n return h.view(viewName, model)\n },\n options: {\n validate: {\n query: Joi.object()\n .keys({\n step: Joi.string().allow(steps.details, steps.manual).optional(),\n language: Joi.string().allow('en-GB', 'cy').optional()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * @param {PostcodeLookupConfiguration} options\n * @returns {ServerRoute<PostcodeLookupPostRequestRefs>}\n */\nfunction postRoute(options) {\n return {\n method: 'POST',\n path: JOURNEY_BASE_URL,\n async handler(request, h) {\n const { payload } = request\n const { step } = payload\n\n switch (step) {\n case steps.details: {\n return detailsPostHandler(request, h, options)\n }\n case steps.select: {\n return selectPostHandler(request, h, options)\n }\n case steps.manual: {\n return manualPostHandler(request, h)\n }\n default:\n throw Boom.badRequest(`Invalid step ${step}`)\n }\n },\n options: {\n validate: {\n payload: Joi.object()\n .keys({\n step: stepSchema\n })\n .unknown(true)\n }\n }\n }\n}\n\n/**\n * Validate a payload against a schema. Joi types the value as `any` when\n * validation fails, so it is typed here as the partially converted payload.\n * @template TSchema\n * @param {ObjectSchema<TSchema>} schema\n * @param {unknown} payload\n * @param {ValidationOptions} [options]\n * @returns {{ value: TSchema, error: undefined } | { value: TSchema | undefined, error: ValidationError }}\n */\nfunction validatePayload(schema, payload, options) {\n return schema.validate(payload, options)\n}\n\n/**\n * Post handler for the details step\n * @param {PostcodeLookupPostRequest} request\n * @param {ResponseToolkit<PostcodeLookupPostRequestRefs>} h\n * @param {PostcodeLookupConfiguration} options\n */\nasync function detailsPostHandler(request, h, options) {\n const session = getSessionState(request)\n const { ordnanceSurveyApiKey: apiKey } = options\n const translator = await getDispatchTranslator(\n request,\n session.initial,\n request.query.language\n )\n const language = translator.language\n\n const { value: details, error } = validatePayload(\n createDetailsPayloadSchema(language),\n request.payload\n )\n\n let model\n\n if (error) {\n model = detailsViewModel(session, translator, details, error)\n\n return h.view(viewName, model)\n }\n\n const { postcodeQuery, buildingNameQuery } = details\n session.details = { postcodeQuery, buildingNameQuery }\n\n // Store the updated session\n request.yar.set(JOURNEY_BASE_URL, session)\n\n model = await selectViewModel({ session, apiKey }, translator)\n\n return h.view(viewName, model)\n}\n\n/**\n * Post handler for the select step\n * @param {PostcodeLookupPostRequest} request\n * @param {ResponseToolkit<PostcodeLookupPostRequestRefs>} h\n * @param {PostcodeLookupConfiguration} options\n */\nasync function selectPostHandler(request, h, options) {\n const session = getSessionState(request)\n const { ordnanceSurveyApiKey: apiKey } = options\n const translator = await getDispatchTranslator(\n request,\n session.initial,\n request.query.language\n )\n const language = translator.language\n const { value: select, error } = validatePayload(\n createSelectPayloadSchema(language),\n request.payload\n )\n\n if (error) {\n const model = await selectViewModel(\n { session, apiKey },\n translator,\n select,\n error\n )\n\n return h.view(viewName, model)\n }\n\n const addresses = await service.searchByUPRN(select.uprn, apiKey)\n const property = addresses.at(0)\n\n if (!property) {\n throw Boom.internal(`UPRN ${property} not found`)\n }\n\n const { componentName, sourceUrl } = session.initial\n flashComponentState(request, componentName, property)\n\n // Redirect back to the source form page\n return h.redirect(sourceUrl).code(StatusCodes.SEE_OTHER)\n}\n\n/**\n * Post handler for the manual step\n * @param {PostcodeLookupPostRequest} request\n * @param {ResponseToolkit<PostcodeLookupPostRequestRefs>} h\n */\nasync function manualPostHandler(request, h) {\n const session = getSessionState(request)\n const translator = await getDispatchTranslator(\n request,\n session.initial,\n request.query.language\n )\n const language = translator.language\n\n const { value: manual, error } = validatePayload(\n createManualPayloadSchema(language),\n request.payload,\n { abortEarly: false }\n )\n\n if (error) {\n const model = manualViewModel(session, translator, manual, error)\n\n return h.view(viewName, model)\n }\n\n const { componentName, sourceUrl } = session.initial\n flashComponentState(request, componentName, manual)\n\n // Redirect back to the source form page\n return h.redirect(sourceUrl).code(StatusCodes.SEE_OTHER)\n}\n\n/**\n * @import { ResponseToolkit, ServerRoute } from '@hapi/hapi'\n * @import { ObjectSchema, ValidationError, ValidationOptions } from 'joi'\n * @import { FormMetadata } from '@defra/forms-model'\n * @import { PostcodeLookupManualPayload, Address, PostcodeLookupGetRequestRefs, PostcodeLookupPostRequestRefs, PostcodeLookupRequest, PostcodeLookupPostRequest, PostcodeLookupConfiguration, PostcodeLookupDispatchData, PostcodeLookupSessionData } from '~/src/server/plugins/postcode-lookup/types.js'\n * @import { FormRequestPayload, FormResponseToolkit } from '~/src/server/routes/types.js'\n * @import { AnyFormRequest, ExternalStateAppendage } from '~/src/server/plugins/engine/types.js'\n */\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,YAAY;AAC7B,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,OAAOC,GAAG,MAAM,KAAK;AAErB,SAASC,wBAAwB;AACjC,SAASC,yBAAyB;AAClC,SACEC,gBAAgB,EAChBC,0BAA0B,EAC1BC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AAM,CACtB,CAAC;EAED,IAAIP,KAAK,EAAE;IACT,MAAMpB,KAAK,GAAGxD,eAAe,CAACuD,OAAO,EAAEnB,UAAU,EAAEqB,MAAM,EAAEmB,KAAK,CAAC;IAEjE,OAAOrC,CAAC,CAACmB,IAAI,CAACpD,QAAQ,EAAEkD,KAAK,CAAC;EAChC;EAEA,MAAM;IAAE1C,aAAa;IAAEoE;EAAU,CAAC,GAAG3B,OAAO,CAAC1B,OAAO;EACpDhB,mBAAmB,CAACL,OAAO,EAAEM,aAAa,EAAE2C,MAAM,CAAC;;EAEnD;EACA,OAAOlB,CAAC,CAACM,QAAQ,CAACqC,SAAS,CAAC,CAACpC,IAAI,CAACvD,WAAW,CAACwD,SAAS,CAAC;AAC1D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.js","names":[],"sources":["../../../src/typings/geodesy/index.d.ts"],"sourcesContent":["declare module 'geodesy/osgridref.js' {\n export class LatLon {\n constructor(lat: number, lon: number, height?: number)\n get latitude(): number\n get longitude(): number\n get height(): number\n toOsGrid(): OsGridRef\n }\n\n export default class OsGridRef {\n constructor(easting: number, northing: number)\n easting: number\n northing: number\n toLatLon(): LatLon\n toString(digits?: number): string\n static parse(gridref: string): OsGridRef\n }\n}\n"],"mappings":"","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -490,7 +490,7 @@ function prepareGeometry(feature) {
|
|
|
490
490
|
* @param {GeoJSON} geojson
|
|
491
491
|
* @returns {FeaturesManager}
|
|
492
492
|
*/
|
|
493
|
-
function getFeaturesManager(geojson) {
|
|
493
|
+
export function getFeaturesManager(geojson) {
|
|
494
494
|
/**
|
|
495
495
|
* Get a feature from the geojson by id
|
|
496
496
|
* @type {GetFeatures}
|
|
@@ -528,9 +528,9 @@ function getFeaturesManager(geojson) {
|
|
|
528
528
|
|
|
529
529
|
// Ensure the feature exists in the geojson
|
|
530
530
|
if (feature) {
|
|
531
|
+
feature.geometry = geometry
|
|
531
532
|
feature.properties.coordinateGridReference = getCoordinateGridRef(feature)
|
|
532
533
|
feature.properties.centroidGridReference = getCentroidGridRef(feature)
|
|
533
|
-
feature.geometry = geometry
|
|
534
534
|
prepareGeometry(feature)
|
|
535
535
|
}
|
|
536
536
|
|
|
@@ -11,7 +11,6 @@ import createSearchPlugin from '@defra/interactive-map/plugins/search'
|
|
|
11
11
|
// @ts-expect-error - no types
|
|
12
12
|
import maplibreProvider from '@defra/interactive-map/providers/maplibre'
|
|
13
13
|
import { centroid } from '@turf/centroid'
|
|
14
|
-
// @ts-expect-error - no types
|
|
15
14
|
import OsGridRef, { LatLon } from 'geodesy/osgridref.js'
|
|
16
15
|
|
|
17
16
|
import { processGeospatial } from './geospatial-map.js'
|
|
@@ -259,10 +259,7 @@ export class ComponentCollection {
|
|
|
259
259
|
|
|
260
260
|
// Update error with parent title
|
|
261
261
|
if (translator && parent) {
|
|
262
|
-
error.local.title ??= translator
|
|
263
|
-
parent as ComponentDef,
|
|
264
|
-
'title'
|
|
265
|
-
)
|
|
262
|
+
error.local.title ??= getTranslatedLabel(parent.def, translator)
|
|
266
263
|
} else {
|
|
267
264
|
error.local.title ??= parent?.label
|
|
268
265
|
}
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
import Bourne from '@hapi/bourne'
|
|
6
6
|
import { booleanWithin } from '@turf/boolean-within'
|
|
7
7
|
import { point } from '@turf/helpers'
|
|
8
|
-
// @ts-expect-error - no types
|
|
9
8
|
import OsGridRef from 'geodesy/osgridref.js'
|
|
10
9
|
import JoiBase, { type CustomValidator } from 'joi'
|
|
11
10
|
|
|
@@ -88,6 +88,7 @@
|
|
|
88
88
|
When a better fix is implemented, this class can be removed and preventDoubleClick should be set back to true. #}
|
|
89
89
|
{{ govukButton({
|
|
90
90
|
text: submitButtonText,
|
|
91
|
+
classes: "prevent-multiple-clicks",
|
|
91
92
|
name: "action",
|
|
92
93
|
value: "send",
|
|
93
94
|
preventDoubleClick: false
|
|
@@ -298,6 +298,19 @@ export const stepSchema = Joi.string()
|
|
|
298
298
|
.valid(...Object.keys(steps))
|
|
299
299
|
.required()
|
|
300
300
|
|
|
301
|
+
/**
|
|
302
|
+
* Joi object schema factories typed with their payload, as JavaScript files
|
|
303
|
+
* cannot pass type arguments to `Joi.object<T>()`
|
|
304
|
+
*/
|
|
305
|
+
/** @type {() => ObjectSchema<PostcodeLookupDetailsPayload>} */
|
|
306
|
+
const detailsObjectSchema = Joi.object.bind(Joi)
|
|
307
|
+
|
|
308
|
+
/** @type {() => ObjectSchema<PostcodeLookupSelectPayload>} */
|
|
309
|
+
const selectObjectSchema = Joi.object.bind(Joi)
|
|
310
|
+
|
|
311
|
+
/** @type {() => ObjectSchema<PostcodeLookupManualPayload>} */
|
|
312
|
+
const manualObjectSchema = Joi.object.bind(Joi)
|
|
313
|
+
|
|
301
314
|
const sharedPayloadSchemaKeys = {
|
|
302
315
|
crumb: crumbSchema,
|
|
303
316
|
step: stepSchema
|
|
@@ -309,7 +322,7 @@ const sharedPayloadSchemaKeys = {
|
|
|
309
322
|
* @returns {ObjectSchema<PostcodeLookupDetailsPayload>}
|
|
310
323
|
*/
|
|
311
324
|
export function createDetailsPayloadSchema(language = 'en-GB') {
|
|
312
|
-
return
|
|
325
|
+
return detailsObjectSchema()
|
|
313
326
|
.keys({
|
|
314
327
|
...sharedPayloadSchemaKeys,
|
|
315
328
|
[postcodeQueryFieldName]: Joi.string()
|
|
@@ -338,7 +351,7 @@ export function createDetailsPayloadSchema(language = 'en-GB') {
|
|
|
338
351
|
* @returns {ObjectSchema<PostcodeLookupSelectPayload>}
|
|
339
352
|
*/
|
|
340
353
|
export function createSelectPayloadSchema(language = 'en-GB') {
|
|
341
|
-
return
|
|
354
|
+
return selectObjectSchema()
|
|
342
355
|
.keys({
|
|
343
356
|
...sharedPayloadSchemaKeys,
|
|
344
357
|
[uprnFieldName]: Joi.string()
|
|
@@ -356,7 +369,7 @@ export function createSelectPayloadSchema(language = 'en-GB') {
|
|
|
356
369
|
* @returns {ObjectSchema<PostcodeLookupManualPayload>}
|
|
357
370
|
*/
|
|
358
371
|
export function createManualPayloadSchema(language = 'en-GB') {
|
|
359
|
-
return
|
|
372
|
+
return manualObjectSchema()
|
|
360
373
|
.keys({
|
|
361
374
|
...sharedPayloadSchemaKeys,
|
|
362
375
|
[line1FieldName]: Joi.string()
|
|
@@ -198,6 +198,19 @@ function postRoute(options) {
|
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
+
/**
|
|
202
|
+
* Validate a payload against a schema. Joi types the value as `any` when
|
|
203
|
+
* validation fails, so it is typed here as the partially converted payload.
|
|
204
|
+
* @template TSchema
|
|
205
|
+
* @param {ObjectSchema<TSchema>} schema
|
|
206
|
+
* @param {unknown} payload
|
|
207
|
+
* @param {ValidationOptions} [options]
|
|
208
|
+
* @returns {{ value: TSchema, error: undefined } | { value: TSchema | undefined, error: ValidationError }}
|
|
209
|
+
*/
|
|
210
|
+
function validatePayload(schema, payload, options) {
|
|
211
|
+
return schema.validate(payload, options)
|
|
212
|
+
}
|
|
213
|
+
|
|
201
214
|
/**
|
|
202
215
|
* Post handler for the details step
|
|
203
216
|
* @param {PostcodeLookupPostRequest} request
|
|
@@ -214,9 +227,10 @@ async function detailsPostHandler(request, h, options) {
|
|
|
214
227
|
)
|
|
215
228
|
const language = translator.language
|
|
216
229
|
|
|
217
|
-
const { value: details, error } =
|
|
218
|
-
language
|
|
219
|
-
|
|
230
|
+
const { value: details, error } = validatePayload(
|
|
231
|
+
createDetailsPayloadSchema(language),
|
|
232
|
+
request.payload
|
|
233
|
+
)
|
|
220
234
|
|
|
221
235
|
let model
|
|
222
236
|
|
|
@@ -252,7 +266,8 @@ async function selectPostHandler(request, h, options) {
|
|
|
252
266
|
request.query.language
|
|
253
267
|
)
|
|
254
268
|
const language = translator.language
|
|
255
|
-
const { value: select, error } =
|
|
269
|
+
const { value: select, error } = validatePayload(
|
|
270
|
+
createSelectPayloadSchema(language),
|
|
256
271
|
request.payload
|
|
257
272
|
)
|
|
258
273
|
|
|
@@ -295,11 +310,10 @@ async function manualPostHandler(request, h) {
|
|
|
295
310
|
)
|
|
296
311
|
const language = translator.language
|
|
297
312
|
|
|
298
|
-
const { value: manual, error } =
|
|
313
|
+
const { value: manual, error } = validatePayload(
|
|
314
|
+
createManualPayloadSchema(language),
|
|
299
315
|
request.payload,
|
|
300
|
-
{
|
|
301
|
-
abortEarly: false
|
|
302
|
-
}
|
|
316
|
+
{ abortEarly: false }
|
|
303
317
|
)
|
|
304
318
|
|
|
305
319
|
if (error) {
|
|
@@ -317,6 +331,7 @@ async function manualPostHandler(request, h) {
|
|
|
317
331
|
|
|
318
332
|
/**
|
|
319
333
|
* @import { ResponseToolkit, ServerRoute } from '@hapi/hapi'
|
|
334
|
+
* @import { ObjectSchema, ValidationError, ValidationOptions } from 'joi'
|
|
320
335
|
* @import { FormMetadata } from '@defra/forms-model'
|
|
321
336
|
* @import { PostcodeLookupManualPayload, Address, PostcodeLookupGetRequestRefs, PostcodeLookupPostRequestRefs, PostcodeLookupRequest, PostcodeLookupPostRequest, PostcodeLookupConfiguration, PostcodeLookupDispatchData, PostcodeLookupSessionData } from '../types.js'
|
|
322
337
|
* @import { FormRequestPayload, FormResponseToolkit } from '../../../routes/types.js'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare module 'geodesy/osgridref.js' {
|
|
2
|
+
export class LatLon {
|
|
3
|
+
constructor(lat: number, lon: number, height?: number)
|
|
4
|
+
get latitude(): number
|
|
5
|
+
get longitude(): number
|
|
6
|
+
get height(): number
|
|
7
|
+
toOsGrid(): OsGridRef
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default class OsGridRef {
|
|
11
|
+
constructor(easting: number, northing: number)
|
|
12
|
+
easting: number
|
|
13
|
+
northing: number
|
|
14
|
+
toLatLon(): LatLon
|
|
15
|
+
toString(digits?: number): string
|
|
16
|
+
static parse(gridref: string): OsGridRef
|
|
17
|
+
}
|
|
18
|
+
}
|