@defra/forms-engine-plugin 4.11.1 → 4.11.2
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/.server/server/plugins/engine/components/CheckboxesField.js +3 -3
- package/.server/server/plugins/engine/components/CheckboxesField.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/validationOptions.js +4 -1
- package/.server/server/plugins/engine/pageControllers/validationOptions.js.map +1 -1
- package/.server/server/plugins/engine/routes/payment.test.js +3 -0
- package/.server/server/plugins/engine/routes/payment.test.js.map +1 -1
- package/.server/server/plugins/map/routes/index.js +8 -0
- package/.server/server/plugins/map/routes/index.js.map +1 -1
- package/package.json +1 -1
- package/src/server/plugins/engine/components/CheckboxesField.ts +3 -3
- package/src/server/plugins/engine/pageControllers/validationOptions.ts +4 -1
- package/src/server/plugins/map/routes/index.js +8 -0
|
@@ -15,9 +15,9 @@ export class CheckboxesField extends SelectionControlField {
|
|
|
15
15
|
let formSchema = type === 'string' ? joi.array() : joi.array();
|
|
16
16
|
const itemsSchema = joi[type]().valid(...this.values).label(this.label);
|
|
17
17
|
formSchema = formSchema.items(itemsSchema).single().label(this.label).required().messages({
|
|
18
|
-
'array.min':
|
|
19
|
-
'array.max':
|
|
20
|
-
'array.length':
|
|
18
|
+
'array.min': messageTemplate.arrayMin,
|
|
19
|
+
'array.max': messageTemplate.arrayMax,
|
|
20
|
+
'array.length': messageTemplate.arrayLength
|
|
21
21
|
});
|
|
22
22
|
if (options.required === false) {
|
|
23
23
|
formSchema = formSchema.optional();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckboxesField.js","names":["joi","isFormValue","SelectionControlField","messageTemplate","CheckboxesField","constructor","def","props","listType","type","options","schema","formSchema","array","itemsSchema","valid","values","label","items","single","required","messages","optional","length","min","max","default","stateSchema","allow","getFormValueFromState","state","name","getFormValue","selected","filter","item","includes","value","map","undefined","isValue","getDisplayStringFromFormValue","text","join","getContextValueFromFormValue","getDisplayStringFromState","getContextValueFromState","getAllPossibleErrors","parentErrors","advancedSettingsErrors","template","
|
|
1
|
+
{"version":3,"file":"CheckboxesField.js","names":["joi","isFormValue","SelectionControlField","messageTemplate","CheckboxesField","constructor","def","props","listType","type","options","schema","formSchema","array","itemsSchema","valid","values","label","items","single","required","messages","arrayMin","arrayMax","arrayLength","optional","length","min","max","default","stateSchema","allow","getFormValueFromState","state","name","getFormValue","selected","filter","item","includes","value","map","undefined","isValue","getDisplayStringFromFormValue","text","join","getContextValueFromFormValue","getDisplayStringFromState","getContextValueFromState","getAllPossibleErrors","parentErrors","advancedSettingsErrors","template","Array","isArray","every"],"sources":["../../../../../src/server/plugins/engine/components/CheckboxesField.ts"],"sourcesContent":["import { type CheckboxesFieldComponent, type Item } from '@defra/forms-model'\nimport joi, { type ArraySchema } from 'joi'\n\nimport { isFormValue } from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { SelectionControlField } from '~/src/server/plugins/engine/components/SelectionControlField.js'\nimport { type FormModel } from '~/src/server/plugins/engine/models/FormModel.js'\nimport { type QuestionPageController } from '~/src/server/plugins/engine/pageControllers/QuestionPageController.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormState,\n type FormStateValue,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class CheckboxesField extends SelectionControlField {\n declare options: CheckboxesFieldComponent['options']\n declare schema: CheckboxesFieldComponent['schema']\n declare formSchema: ArraySchema<string> | ArraySchema<number>\n declare stateSchema: ArraySchema<string> | ArraySchema<number>\n\n constructor(\n def: CheckboxesFieldComponent,\n props: ConstructorParameters<typeof SelectionControlField>[1]\n ) {\n super(def, props)\n\n const { listType: type } = this\n const { options, schema } = def\n\n let formSchema =\n type === 'string' ? joi.array<string>() : joi.array<number>()\n\n const itemsSchema = joi[type]()\n .valid(...this.values)\n .label(this.label)\n\n formSchema = formSchema\n .items(itemsSchema)\n .single()\n .label(this.label)\n .required()\n .messages({\n 'array.min': messageTemplate.arrayMin as string,\n 'array.max': messageTemplate.arrayMax as string,\n 'array.length': messageTemplate.arrayLength as string\n })\n\n if (options.required === false) {\n formSchema = formSchema.optional()\n }\n\n if (typeof schema?.length === 'number') {\n formSchema = formSchema.length(schema.length)\n } else {\n if (typeof schema?.min === 'number') {\n formSchema = formSchema.min(schema.min)\n }\n\n if (typeof schema?.max === 'number') {\n formSchema = formSchema.max(schema.max)\n }\n }\n\n this.formSchema = formSchema.default([])\n this.stateSchema = formSchema.default(null).allow(null)\n this.options = options\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { items, name } = this\n\n // State checkbox values\n const values = this.getFormValue(state[name]) ?? []\n\n // Map (or discard) state values to item values\n const selected = items\n .filter((item) => values.includes(item.value))\n .map((item) => item.value)\n\n return selected.length ? selected : undefined\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getDisplayStringFromFormValue(\n selected: (string | number | boolean)[] | undefined\n ) {\n const { items } = this\n\n if (!selected) {\n return ''\n }\n\n // Map selected values to text\n return items\n .filter((item) => selected.includes(item.value))\n .map((item) => item.text)\n .join(', ')\n }\n\n getContextValueFromFormValue(\n values: (string | number | boolean)[] | undefined\n ): (string | number | boolean)[] {\n /**\n * For evaluation context purposes, optional {@link CheckboxesField}\n * with an undefined value (i.e. nothing selected) should default to [].\n * This way conditions are not evaluated against `undefined` which throws errors.\n * Currently these errors are caught and the evaluation returns default `false`.\n * @see {@link QuestionPageController.getNextPath} for `undefined` return value\n * @see {@link FormModel.makeCondition} for try/catch block with default `false`\n * For negative conditions this is a problem because E.g.\n * The condition: 'selectedchecks' does not contain 'someval'\n * should return true IF 'selectedchecks' is undefined, not throw and return false.\n */\n return values ?? []\n }\n\n getDisplayStringFromState(state: FormSubmissionState) {\n // Selected checkbox values\n const selected = this.getFormValueFromState(state) ?? []\n\n // Map selected values to text\n return this.getDisplayStringFromFormValue(selected)\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const values = this.getFormValueFromState(state)\n\n return this.getContextValueFromFormValue(values)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return CheckboxesField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n const parentErrors = SelectionControlField.getAllPossibleErrors()\n\n return {\n ...parentErrors,\n advancedSettingsErrors: [\n ...parentErrors.advancedSettingsErrors,\n { type: 'array.min', template: messageTemplate.arrayMin },\n { type: 'array.max', template: messageTemplate.arrayMax },\n { type: 'array.length', template: messageTemplate.arrayLength }\n ]\n }\n }\n\n isValue(value?: FormStateValue | FormState): value is Item['value'][] {\n if (!Array.isArray(value)) {\n return false\n }\n\n // Skip checks when empty\n if (!value.length) {\n return true\n }\n\n return value.every(isFormValue)\n }\n}\n"],"mappings":"AACA,OAAOA,GAAG,MAA4B,KAAK;AAE3C,SAASC,WAAW;AACpB,SAASC,qBAAqB;AAG9B,SAASC,eAAe;AAQxB,OAAO,MAAMC,eAAe,SAASF,qBAAqB,CAAC;EAMzDG,WAAWA,CACTC,GAA6B,EAC7BC,KAA6D,EAC7D;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,QAAQ,EAAEC;IAAK,CAAC,GAAG,IAAI;IAC/B,MAAM;MAAEC,OAAO;MAAEC;IAAO,CAAC,GAAGL,GAAG;IAE/B,IAAIM,UAAU,GACZH,IAAI,KAAK,QAAQ,GAAGT,GAAG,CAACa,KAAK,CAAS,CAAC,GAAGb,GAAG,CAACa,KAAK,CAAS,CAAC;IAE/D,MAAMC,WAAW,GAAGd,GAAG,CAACS,IAAI,CAAC,CAAC,CAAC,CAC5BM,KAAK,CAAC,GAAG,IAAI,CAACC,MAAM,CAAC,CACrBC,KAAK,CAAC,IAAI,CAACA,KAAK,CAAC;IAEpBL,UAAU,GAA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AAoBA,CAAA,EAA6B;IAC/C,OAAO9C,eAAe,CAAC8C,oBAAoB,CAAC,CAAC;EAC/C;;EAEA;AACF;AACA;EACE,OAAOA,oBAAoBA,CAAA,EAA6B;IACtD,MAAMC,YAAY,GAAGjD,qBAAqB,CAACgD,oBAAoB,CAAC,CAAC;IAEjE,OAAO;MACL,GAAGC,YAAY;MACfC,sBAAsB,EAAE,CACtB,GAAGD,YAAY,CAACC,sBAAsB,EACtC;QAAE3C,IAAI,EAAE,WAAW;QAAE4C,QAAQ,EAAElD,eAAe,CAACmB;MAAS,CAAC,EACzD;QAAEb,IAAI,EAAE,WAAW;QAAE4C,QAAQ,EAAElD,eAAe,CAACoB;MAAS,CAAC,EACzD;QAAEd,IAAI,EAAE,cAAc;QAAE4C,QAAQ,EAAElD,eAAe,CAACqB;MAAY,CAAC;IAEnE,CAAC;EACH;EAEAmB,OAAOA,CAACH,KAAkC,EAA4B;IACpE,IAAI,CAACc,KAAK,CAACC,OAAO,CAACf,KAAK,CAAC,EAAE;MACzB,OAAO,KAAK;IACd;;IAEA;IACA,IAAI,CAACA,KAAK,CAACd,MAAM,EAAE;MACjB,OAAO,IAAI;IACb;IAEA,OAAOc,KAAK,CAACgB,KAAK,CAACvD,WAAW,CAAC;EACjC;AACF","ignoreList":[]}
|
|
@@ -34,7 +34,10 @@ export const messageTemplate = {
|
|
|
34
34
|
objectMissing: joi.expression('{{#title}} must include a {{lowerFirst(#label)}}', opts),
|
|
35
35
|
dateFormat: '{{#title}} must be a real date',
|
|
36
36
|
dateMin: '{{#title}} must be the same as or after {{#limit}}',
|
|
37
|
-
dateMax: '{{#title}} must be the same as or before {{#limit}}'
|
|
37
|
+
dateMax: '{{#title}} must be the same as or before {{#limit}}',
|
|
38
|
+
arrayMin: 'Select at least {{#limit}} options from the list',
|
|
39
|
+
arrayMax: 'Only {{#limit}} can be selected from the list',
|
|
40
|
+
arrayLength: 'Select only {{#limit}} options from the list'
|
|
38
41
|
};
|
|
39
42
|
export const messages = {
|
|
40
43
|
'string.base': messageTemplate.required,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationOptions.js","names":["joi","lowerFirstPreserveProperNouns","opts","functions","lowerFirst","messageTemplate","declarationRequired","expression","required","selectRequired","selectYesNoRequired","max","min","minMax","pattern","format","unicode","number","numberPrecision","numberInteger","numberMin","numberMax","maxWords","objectRequired","objectMissing","dateFormat","dateMin","dateMax","messages","messagesPre","validationOptions","abortEarly","errors","wrap","array","label"],"sources":["../../../../../src/server/plugins/engine/pageControllers/validationOptions.ts"],"sourcesContent":["// Declaration above is needed for: https://github.com/hapijs/joi/issues/3064\n\nimport joi, {\n type JoiExpression,\n type LanguageMessages,\n type LanguageMessagesExt,\n type ReferenceOptions,\n type ValidationOptions\n} from 'joi'\n\nimport { lowerFirstPreserveProperNouns } from '~/src/server/plugins/engine/components/helpers/index.js'\n\nconst opts = {\n functions: {\n lowerFirst: lowerFirstPreserveProperNouns\n }\n} as ReferenceOptions\n\n/**\n * see @link https://joi.dev/api/?v=17.4.2#template-syntax for template syntax\n */\nexport const messageTemplate: Record<string, JoiExpression> = {\n declarationRequired: joi.expression(\n 'You must confirm you understand and agree with the {{lowerFirst(#label)}} to continue',\n opts\n ) as JoiExpression,\n required: joi.expression(\n 'Enter {{lowerFirst(#label)}}',\n opts\n ) as JoiExpression,\n selectRequired: joi.expression(\n 'Select {{lowerFirst(#label)}}',\n opts\n ) as JoiExpression,\n selectYesNoRequired: '{{#label}} - select yes or no',\n max: '{{#label}} must be {{#limit}} characters or less',\n min: '{{#label}} must be {{#limit}} characters or more',\n minMax: '{{#label}} must be between {{#min}} and {{#max}} characters',\n pattern: joi.expression(\n 'Enter a valid {{lowerFirst(#label)}}',\n opts\n ) as JoiExpression,\n format: joi.expression(\n 'Enter {{lowerFirst(#label)}} in the correct format',\n opts\n ) as JoiExpression,\n unicode: '{{#label}} includes invalid characters, for example, long dashes',\n number: '{{#label}} must be a number',\n numberPrecision: '{{#label}} must have {{#limit}} or fewer decimal places',\n numberInteger: '{{#label}} must be a whole number',\n numberMin: '{{#label}} must be {{#limit}} or higher',\n numberMax: '{{#label}} must be {{#limit}} or lower',\n maxWords: '{{#label}} must be {{#limit}} words or fewer',\n\n // Nested fields use component title\n\n objectRequired: joi.expression('Enter {{#label}}', opts) as JoiExpression,\n objectMissing: joi.expression(\n '{{#title}} must include a {{lowerFirst(#label)}}',\n opts\n ) as JoiExpression,\n dateFormat: '{{#title}} must be a real date',\n dateMin: '{{#title}} must be the same as or after {{#limit}}',\n dateMax: '{{#title}} must be the same as or before {{#limit}}'\n}\n\nexport const messages: LanguageMessagesExt = {\n 'string.base': messageTemplate.required,\n 'string.min': messageTemplate.min,\n 'string.empty': messageTemplate.required,\n 'string.max': messageTemplate.max,\n 'string.email': messageTemplate.format,\n 'string.unicode': messageTemplate.unicode,\n 'string.pattern.base': messageTemplate.pattern,\n 'string.maxWords': messageTemplate.maxWords,\n\n 'number.base': messageTemplate.number,\n 'number.precision': messageTemplate.numberPrecision,\n 'number.integer': messageTemplate.numberInteger,\n 'number.unsafe': messageTemplate.format,\n 'number.min': messageTemplate.numberMin,\n 'number.max': messageTemplate.numberMax,\n\n 'object.required': messageTemplate.objectRequired,\n 'object.and': messageTemplate.objectMissing,\n\n 'any.only': messageTemplate.selectRequired,\n 'any.required': messageTemplate.selectRequired,\n 'any.empty': messageTemplate.required,\n\n 'date.base': messageTemplate.dateFormat,\n 'date.format': messageTemplate.dateFormat,\n 'date.min': messageTemplate.dateMin,\n 'date.max': messageTemplate.dateMax,\n\n 'object.invalidjson': messageTemplate.format\n}\n\nexport const messagesPre: LanguageMessages =\n messages as unknown as LanguageMessages\n\nexport const validationOptions: ValidationOptions = {\n abortEarly: false,\n messages: messagesPre,\n errors: {\n wrap: {\n array: false,\n label: false\n }\n }\n}\n"],"mappings":"AAAA;;AAEA,OAAOA,GAAG,MAMH,KAAK;AAEZ,SAASC,6BAA6B;AAEtC,MAAMC,IAAI,GAAG;EACXC,SAAS,EAAE;IACTC,UAAU,EAAEH;EACd;AACF,CAAqB;;AAErB;AACA;AACA;AACA,OAAO,MAAMI,eAA8C,GAAG;EAC5DC,mBAAmB,EAAEN,GAAG,CAACO,UAAU,CACjC,uFAAuF,EACvFL,IACF,CAAkB;EAClBM,QAAQ,EAAER,GAAG,CAACO,UAAU,CACtB,8BAA8B,EAC9BL,IACF,CAAkB;EAClBO,cAAc,EAAET,GAAG,CAACO,UAAU,CAC5B,+BAA+B,EAC/BL,IACF,CAAkB;EAClBQ,mBAAmB,EAAE,+BAA+B;EACpDC,GAAG,EAAE,kDAAkD;EACvDC,GAAG,EAAE,kDAAkD;EACvDC,MAAM,EAAE,6DAA6D;EACrEC,OAAO,EAAEd,GAAG,CAACO,UAAU,CACrB,sCAAsC,EACtCL,IACF,CAAkB;EAClBa,MAAM,EAAEf,GAAG,CAACO,UAAU,CACpB,oDAAoD,EACpDL,IACF,CAAkB;EAClBc,OAAO,EAAE,kEAAkE;EAC3EC,MAAM,EAAE,6BAA6B;EACrCC,eAAe,EAAE,yDAAyD;EAC1EC,aAAa,EAAE,mCAAmC;EAClDC,SAAS,EAAE,yCAAyC;EACpDC,SAAS,EAAE,wCAAwC;EACnDC,QAAQ,EAAE,8CAA8C;EAExD;;EAEAC,cAAc,EAAEvB,GAAG,CAACO,UAAU,CAAC,kBAAkB,EAAEL,IAAI,CAAkB;EACzEsB,aAAa,EAAExB,GAAG,CAACO,UAAU,CAC3B,kDAAkD,EAClDL,IACF,CAAkB;EAClBuB,UAAU,EAAE,gCAAgC;EAC5CC,OAAO,EAAE,oDAAoD;EAC7DC,OAAO,EAAE;
|
|
1
|
+
{"version":3,"file":"validationOptions.js","names":["joi","lowerFirstPreserveProperNouns","opts","functions","lowerFirst","messageTemplate","declarationRequired","expression","required","selectRequired","selectYesNoRequired","max","min","minMax","pattern","format","unicode","number","numberPrecision","numberInteger","numberMin","numberMax","maxWords","objectRequired","objectMissing","dateFormat","dateMin","dateMax","arrayMin","arrayMax","arrayLength","messages","messagesPre","validationOptions","abortEarly","errors","wrap","array","label"],"sources":["../../../../../src/server/plugins/engine/pageControllers/validationOptions.ts"],"sourcesContent":["// Declaration above is needed for: https://github.com/hapijs/joi/issues/3064\n\nimport joi, {\n type JoiExpression,\n type LanguageMessages,\n type LanguageMessagesExt,\n type ReferenceOptions,\n type ValidationOptions\n} from 'joi'\n\nimport { lowerFirstPreserveProperNouns } from '~/src/server/plugins/engine/components/helpers/index.js'\n\nconst opts = {\n functions: {\n lowerFirst: lowerFirstPreserveProperNouns\n }\n} as ReferenceOptions\n\n/**\n * see @link https://joi.dev/api/?v=17.4.2#template-syntax for template syntax\n */\nexport const messageTemplate: Record<string, JoiExpression> = {\n declarationRequired: joi.expression(\n 'You must confirm you understand and agree with the {{lowerFirst(#label)}} to continue',\n opts\n ) as JoiExpression,\n required: joi.expression(\n 'Enter {{lowerFirst(#label)}}',\n opts\n ) as JoiExpression,\n selectRequired: joi.expression(\n 'Select {{lowerFirst(#label)}}',\n opts\n ) as JoiExpression,\n selectYesNoRequired: '{{#label}} - select yes or no',\n max: '{{#label}} must be {{#limit}} characters or less',\n min: '{{#label}} must be {{#limit}} characters or more',\n minMax: '{{#label}} must be between {{#min}} and {{#max}} characters',\n pattern: joi.expression(\n 'Enter a valid {{lowerFirst(#label)}}',\n opts\n ) as JoiExpression,\n format: joi.expression(\n 'Enter {{lowerFirst(#label)}} in the correct format',\n opts\n ) as JoiExpression,\n unicode: '{{#label}} includes invalid characters, for example, long dashes',\n number: '{{#label}} must be a number',\n numberPrecision: '{{#label}} must have {{#limit}} or fewer decimal places',\n numberInteger: '{{#label}} must be a whole number',\n numberMin: '{{#label}} must be {{#limit}} or higher',\n numberMax: '{{#label}} must be {{#limit}} or lower',\n maxWords: '{{#label}} must be {{#limit}} words or fewer',\n\n // Nested fields use component title\n\n objectRequired: joi.expression('Enter {{#label}}', opts) as JoiExpression,\n objectMissing: joi.expression(\n '{{#title}} must include a {{lowerFirst(#label)}}',\n opts\n ) as JoiExpression,\n dateFormat: '{{#title}} must be a real date',\n dateMin: '{{#title}} must be the same as or after {{#limit}}',\n dateMax: '{{#title}} must be the same as or before {{#limit}}',\n arrayMin: 'Select at least {{#limit}} options from the list',\n arrayMax: 'Only {{#limit}} can be selected from the list',\n arrayLength: 'Select only {{#limit}} options from the list'\n}\n\nexport const messages: LanguageMessagesExt = {\n 'string.base': messageTemplate.required,\n 'string.min': messageTemplate.min,\n 'string.empty': messageTemplate.required,\n 'string.max': messageTemplate.max,\n 'string.email': messageTemplate.format,\n 'string.unicode': messageTemplate.unicode,\n 'string.pattern.base': messageTemplate.pattern,\n 'string.maxWords': messageTemplate.maxWords,\n\n 'number.base': messageTemplate.number,\n 'number.precision': messageTemplate.numberPrecision,\n 'number.integer': messageTemplate.numberInteger,\n 'number.unsafe': messageTemplate.format,\n 'number.min': messageTemplate.numberMin,\n 'number.max': messageTemplate.numberMax,\n\n 'object.required': messageTemplate.objectRequired,\n 'object.and': messageTemplate.objectMissing,\n\n 'any.only': messageTemplate.selectRequired,\n 'any.required': messageTemplate.selectRequired,\n 'any.empty': messageTemplate.required,\n\n 'date.base': messageTemplate.dateFormat,\n 'date.format': messageTemplate.dateFormat,\n 'date.min': messageTemplate.dateMin,\n 'date.max': messageTemplate.dateMax,\n\n 'object.invalidjson': messageTemplate.format\n}\n\nexport const messagesPre: LanguageMessages =\n messages as unknown as LanguageMessages\n\nexport const validationOptions: ValidationOptions = {\n abortEarly: false,\n messages: messagesPre,\n errors: {\n wrap: {\n array: false,\n label: false\n }\n }\n}\n"],"mappings":"AAAA;;AAEA,OAAOA,GAAG,MAMH,KAAK;AAEZ,SAASC,6BAA6B;AAEtC,MAAMC,IAAI,GAAG;EACXC,SAAS,EAAE;IACTC,UAAU,EAAEH;EACd;AACF,CAAqB;;AAErB;AACA;AACA;AACA,OAAO,MAAMI,eAA8C,GAAG;EAC5DC,mBAAmB,EAAEN,GAAG,CAACO,UAAU,CACjC,uFAAuF,EACvFL,IACF,CAAkB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,OAAO;EAC9C,iBAAiB,EAAET,eAAe,CAACiB,QAAQ;EAE3C,aAAa,EAAEjB,eAAe,CAACY,MAAM;EACrC,kBAAkB,EAAEZ,eAAe,CAACa,eAAe;EACnD,gBAAgB,EAAEb,eAAe,CAACc,aAAa;EAC/C,eAAe,EAAEd,eAAe,CAACU,MAAM;EACvC,YAAY,EAAEV,eAAe,CAACe,SAAS;EACvC,YAAY,EAAEf,eAAe,CAACgB,SAAS;EAEvC,iBAAiB,EAAEhB,eAAe,CAACkB,cAAc;EACjD,YAAY,EAAElB,eAAe,CAACmB,aAAa;EAE3C,UAAU,EAAEnB,eAAe,CAACI,cAAc;EAC1C,cAAc,EAAEJ,eAAe,CAACI,cAAc;EAC9C,WAAW,EAAEJ,eAAe,CAACG,QAAQ;EAErC,WAAW,EAAEH,eAAe,CAACoB,UAAU;EACvC,aAAa,EAAEpB,eAAe,CAACoB,UAAU;EACzC,UAAU,EAAEpB,eAAe,CAACqB,OAAO;EACnC,UAAU,EAAErB,eAAe,CAACsB,OAAO;EAEnC,oBAAoB,EAAEtB,eAAe,CAACU;AACxC,CAAC;AAED,OAAO,MAAMiB,WAA6B,GACxCD,QAAuC;AAEzC,OAAO,MAAME,iBAAoC,GAAG;EAClDC,UAAU,EAAE,KAAK;EACjBH,QAAQ,EAAEC,WAAW;EACrBG,MAAM,EAAE;IACNC,IAAI,EAAE;MACJC,KAAK,EAAE,KAAK;MACZC,KAAK,EAAE;IACT;EACF;AACF,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment.test.js","names":["StatusCodes","createServer","getPaymentContext","renderResponse","jest","mock","describe","server","beforeAll","initialize","beforeEach","resetAllMocks","uuid","options","method","url","paymentSessionData","formId","reference","paymentId","amount","description","isLivePayment","componentName","returnUrl","failureUrl","sessionKey","test","each","status","finalUrl","row","paymentStatus","_links","next_url","href","self","state","finished","mocked","mockResolvedValueOnce","session","response","expect","statusCode","toBe","SEE_OTHER","headers","location","it","BAD_REQUEST","result","message","INTERNAL_SERVER_ERROR","payment_id","email"],"sources":["../../../../../src/server/plugins/engine/routes/payment.test.js"],"sourcesContent":["import { StatusCodes } from 'http-status-codes'\n\nimport { createServer } from '~/src/server/index.js'\nimport { getPaymentContext } from '~/src/server/plugins/engine/routes/payment-helper.js'\nimport { renderResponse } from '~/test/helpers/component-helpers.js'\n\njest.mock('~/src/server/plugins/engine/routes/payment-helper.js')\n\ndescribe('Payment routes', () => {\n /** @type {Server} */\n let server\n\n beforeAll(async () => {\n server = await createServer()\n await server.initialize()\n })\n\n beforeEach(() => {\n jest.resetAllMocks()\n })\n\n describe('Return route /payment-callback', () => {\n const uuid = '06a5b11e-e3e0-48a2-8ac3-56c0fcb6c20d'\n const options = {\n method: 'get',\n url: `/payment-callback?uuid=${uuid}`\n }\n\n const paymentSessionData = {\n uuid,\n formId: 'form-id',\n reference: 'form-ref-123',\n paymentId: 'payment-id',\n amount: 123,\n description: 'Payment desc',\n isLivePayment: false,\n componentName: 'my-component',\n returnUrl: 'http://host.com/return-url',\n failureUrl: 'http://host.com/failure-url'\n }\n const sessionKey = 'session-key'\n\n test.each([\n {\n status: 'capturable',\n finalUrl: 'http://host.com/return-url?paymentComplete=true'\n },\n {\n status: 'success',\n finalUrl: 'http://host.com/return-url?paymentComplete=true'\n },\n { status: 'cancelled', finalUrl: 'http://host.com/failure-url' },\n { status: 'failed', finalUrl: 'http://host.com/failure-url' },\n { status: 'error', finalUrl: 'http://host.com/failure-url' },\n { status: 'created', finalUrl: '/next-url' },\n { status: 'started', finalUrl: '/next-url' },\n { status: 'submitted', finalUrl: '/next-url' }\n ])('should handle payment status of $row.status', async (row) => {\n const paymentStatus = {\n paymentId: 'new-payment-id',\n amount: 125,\n _links: {\n next_url: {\n href: '/next-url',\n method: 'get'\n },\n self: {\n href: '/self',\n method: 'get'\n }\n },\n state: /** @type {PaymentResponseState} */ ({\n status: row.status,\n finished: true\n })\n }\n jest.mocked(getPaymentContext).mockResolvedValueOnce({\n session: paymentSessionData,\n sessionKey,\n paymentStatus\n })\n const { response } = await renderResponse(server, options)\n\n expect(response.statusCode).toBe(StatusCodes.SEE_OTHER)\n expect(response.headers.location).toBe(row.finalUrl)\n })\n\n it('should throw if nextUrl is missing', async () => {\n const paymentStatus = {\n paymentId: 'new-payment-id',\n _links: {\n next_url: {},\n self: {\n href: '/self',\n method: 'get'\n }\n },\n state: /** @type {PaymentResponseState} */ ({\n status: 'created',\n finished: true\n })\n }\n jest.mocked(getPaymentContext).mockResolvedValueOnce({\n session: paymentSessionData,\n sessionKey,\n // @ts-expect-error - deliberate missing element from object\n paymentStatus\n })\n const { response } = await renderResponse(server, options)\n\n expect(response.statusCode).toBe(StatusCodes.BAD_REQUEST)\n // @ts-expect-error - error object\n expect(response.result?.message).toBe(\n \"Payment in state 'created' but no next_url available\"\n )\n })\n\n it('should throw if invalid status', async () => {\n const paymentStatus = {\n paymentId: 'new-payment-id',\n _links: {\n next_url: {\n href: '/next-url',\n method: 'get'\n },\n self: {\n href: '/self',\n method: 'get'\n }\n },\n state: {\n status: 'invalid',\n finished: true\n }\n }\n jest.mocked(getPaymentContext).mockResolvedValueOnce({\n session: paymentSessionData,\n sessionKey,\n // @ts-expect-error - deliberate invalid value which doesnt meet type\n paymentStatus\n })\n const { response } = await renderResponse(server, options)\n\n expect(response.statusCode).toBe(StatusCodes.INTERNAL_SERVER_ERROR)\n // @ts-expect-error - error object\n expect(response.result?.message).toBe('Unknown payment status: invalid')\n })\n\n it('should handle payment with email from GOV.UK Pay response', async () => {\n const paymentStatus = {\n paymentId: 'new-payment-id',\n payment_id: 'new-payment-id',\n amount: 125,\n email: 'payer@example.com',\n _links: {\n next_url: {\n href: '/next-url',\n method: 'get'\n },\n self: {\n href: '/self',\n method: 'get'\n }\n },\n state: /** @type {PaymentResponseState} */ ({\n status: 'success',\n finished: true\n })\n }\n jest.mocked(getPaymentContext).mockResolvedValueOnce({\n session: paymentSessionData,\n sessionKey,\n paymentStatus\n })\n const { response } = await renderResponse(server, options)\n\n expect(response.statusCode).toBe(StatusCodes.SEE_OTHER)\n expect(response.headers.location).toBe(\n 'http://host.com/return-url?paymentComplete=true'\n )\n })\n })\n})\n\n/**\n * @import { Server } from '@hapi/hapi'\n * @import { PaymentResponseState } from '~/src/server/plugins/payment/types.js'\n */\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,mBAAmB;AAE/C,SAASC,YAAY;AACrB,SAASC,iBAAiB;AAC1B,SAASC,cAAc;AAEvBC,IAAI,CAACC,IAAI,sBAAuD,CAAC;AAEjEC,QAAQ,CAAC,gBAAgB,EAAE,MAAM;EAC/B;EACA,IAAIC,MAAM;EAEVC,SAAS,CAAC,YAAY;IACpBD,MAAM,GAAG,MAAMN,YAAY,CAAC,CAAC;IAC7B,MAAMM,MAAM,CAACE,UAAU,CAAC,CAAC;EAC3B,CAAC,CAAC;EAEFC,UAAU,CAAC,MAAM;IACfN,IAAI,CAACO,aAAa,CAAC,CAAC;EACtB,CAAC,CAAC;EAEFL,QAAQ,CAAC,gCAAgC,EAAE,MAAM;IAC/C,MAAMM,IAAI,GAAG,sCAAsC;IACnD,MAAMC,OAAO,GAAG;MACdC,MAAM,EAAE,KAAK;MACbC,GAAG,EAAE,0BAA0BH,IAAI;IACrC,CAAC;IAED,MAAMI,kBAAkB,GAAG;MACzBJ,IAAI;MACJK,MAAM,EAAE,SAAS;MACjBC,SAAS,EAAE,cAAc;MACzBC,SAAS,EAAE,YAAY;MACvBC,MAAM,EAAE,GAAG;MACXC,WAAW,EAAE,cAAc;MAC3BC,aAAa,EAAE,KAAK;MACpBC,aAAa,EAAE,cAAc;MAC7BC,SAAS,EAAE,4BAA4B;MACvCC,UAAU,EAAE;IACd,CAAC;IACD,MAAMC,UAAU,GAAG,aAAa;IAEhCC,IAAI,CAACC,IAAI,CAAC,CACR;MACEC,MAAM,EAAE,YAAY;MACpBC,QAAQ,EAAE;IACZ,CAAC,EACD;MACED,MAAM,EAAE,SAAS;MACjBC,QA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F;AACA;AACA;AACA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"payment.test.js","names":["StatusCodes","createServer","getPaymentContext","renderResponse","jest","mock","describe","server","beforeAll","initialize","beforeEach","resetAllMocks","uuid","options","method","url","paymentSessionData","formId","reference","paymentId","amount","description","isLivePayment","componentName","returnUrl","failureUrl","sessionKey","test","each","status","finalUrl","row","paymentStatus","_links","next_url","href","self","state","finished","mocked","mockResolvedValueOnce","session","response","expect","statusCode","toBe","SEE_OTHER","headers","location","it","BAD_REQUEST","result","message","INTERNAL_SERVER_ERROR","payment_id","email","afterAll","stop"],"sources":["../../../../../src/server/plugins/engine/routes/payment.test.js"],"sourcesContent":["import { StatusCodes } from 'http-status-codes'\n\nimport { createServer } from '~/src/server/index.js'\nimport { getPaymentContext } from '~/src/server/plugins/engine/routes/payment-helper.js'\nimport { renderResponse } from '~/test/helpers/component-helpers.js'\n\njest.mock('~/src/server/plugins/engine/routes/payment-helper.js')\n\ndescribe('Payment routes', () => {\n /** @type {Server} */\n let server\n\n beforeAll(async () => {\n server = await createServer()\n await server.initialize()\n })\n\n beforeEach(() => {\n jest.resetAllMocks()\n })\n\n describe('Return route /payment-callback', () => {\n const uuid = '06a5b11e-e3e0-48a2-8ac3-56c0fcb6c20d'\n const options = {\n method: 'get',\n url: `/payment-callback?uuid=${uuid}`\n }\n\n const paymentSessionData = {\n uuid,\n formId: 'form-id',\n reference: 'form-ref-123',\n paymentId: 'payment-id',\n amount: 123,\n description: 'Payment desc',\n isLivePayment: false,\n componentName: 'my-component',\n returnUrl: 'http://host.com/return-url',\n failureUrl: 'http://host.com/failure-url'\n }\n const sessionKey = 'session-key'\n\n test.each([\n {\n status: 'capturable',\n finalUrl: 'http://host.com/return-url?paymentComplete=true'\n },\n {\n status: 'success',\n finalUrl: 'http://host.com/return-url?paymentComplete=true'\n },\n { status: 'cancelled', finalUrl: 'http://host.com/failure-url' },\n { status: 'failed', finalUrl: 'http://host.com/failure-url' },\n { status: 'error', finalUrl: 'http://host.com/failure-url' },\n { status: 'created', finalUrl: '/next-url' },\n { status: 'started', finalUrl: '/next-url' },\n { status: 'submitted', finalUrl: '/next-url' }\n ])('should handle payment status of $row.status', async (row) => {\n const paymentStatus = {\n paymentId: 'new-payment-id',\n amount: 125,\n _links: {\n next_url: {\n href: '/next-url',\n method: 'get'\n },\n self: {\n href: '/self',\n method: 'get'\n }\n },\n state: /** @type {PaymentResponseState} */ ({\n status: row.status,\n finished: true\n })\n }\n jest.mocked(getPaymentContext).mockResolvedValueOnce({\n session: paymentSessionData,\n sessionKey,\n paymentStatus\n })\n const { response } = await renderResponse(server, options)\n\n expect(response.statusCode).toBe(StatusCodes.SEE_OTHER)\n expect(response.headers.location).toBe(row.finalUrl)\n })\n\n it('should throw if nextUrl is missing', async () => {\n const paymentStatus = {\n paymentId: 'new-payment-id',\n _links: {\n next_url: {},\n self: {\n href: '/self',\n method: 'get'\n }\n },\n state: /** @type {PaymentResponseState} */ ({\n status: 'created',\n finished: true\n })\n }\n jest.mocked(getPaymentContext).mockResolvedValueOnce({\n session: paymentSessionData,\n sessionKey,\n // @ts-expect-error - deliberate missing element from object\n paymentStatus\n })\n const { response } = await renderResponse(server, options)\n\n expect(response.statusCode).toBe(StatusCodes.BAD_REQUEST)\n // @ts-expect-error - error object\n expect(response.result?.message).toBe(\n \"Payment in state 'created' but no next_url available\"\n )\n })\n\n it('should throw if invalid status', async () => {\n const paymentStatus = {\n paymentId: 'new-payment-id',\n _links: {\n next_url: {\n href: '/next-url',\n method: 'get'\n },\n self: {\n href: '/self',\n method: 'get'\n }\n },\n state: {\n status: 'invalid',\n finished: true\n }\n }\n jest.mocked(getPaymentContext).mockResolvedValueOnce({\n session: paymentSessionData,\n sessionKey,\n // @ts-expect-error - deliberate invalid value which doesnt meet type\n paymentStatus\n })\n const { response } = await renderResponse(server, options)\n\n expect(response.statusCode).toBe(StatusCodes.INTERNAL_SERVER_ERROR)\n // @ts-expect-error - error object\n expect(response.result?.message).toBe('Unknown payment status: invalid')\n })\n\n it('should handle payment with email from GOV.UK Pay response', async () => {\n const paymentStatus = {\n paymentId: 'new-payment-id',\n payment_id: 'new-payment-id',\n amount: 125,\n email: 'payer@example.com',\n _links: {\n next_url: {\n href: '/next-url',\n method: 'get'\n },\n self: {\n href: '/self',\n method: 'get'\n }\n },\n state: /** @type {PaymentResponseState} */ ({\n status: 'success',\n finished: true\n })\n }\n jest.mocked(getPaymentContext).mockResolvedValueOnce({\n session: paymentSessionData,\n sessionKey,\n paymentStatus\n })\n const { response } = await renderResponse(server, options)\n\n expect(response.statusCode).toBe(StatusCodes.SEE_OTHER)\n expect(response.headers.location).toBe(\n 'http://host.com/return-url?paymentComplete=true'\n )\n })\n })\n\n afterAll(async () => {\n await server.stop()\n })\n})\n\n/**\n * @import { Server } from '@hapi/hapi'\n * @import { PaymentResponseState } from '~/src/server/plugins/payment/types.js'\n */\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,mBAAmB;AAE/C,SAASC,YAAY;AACrB,SAASC,iBAAiB;AAC1B,SAASC,cAAc;AAEvBC,IAAI,CAACC,IAAI,sBAAuD,CAAC;AAEjEC,QAAQ,CAAC,gBAAgB,EAAE,MAAM;EAC/B;EACA,IAAIC,MAAM;EAEVC,SAAS,CAAC,YAAY;IACpBD,MAAM,GAAG,MAAMN,YAAY,CAAC,CAAC;IAC7B,MAAMM,MAAM,CAACE,UAAU,CAAC,CAAC;EAC3B,CAAC,CAAC;EAEFC,UAAU,CAAC,MAAM;IACfN,IAAI,CAACO,aAAa,CAAC,CAAC;EACtB,CAAC,CAAC;EAEFL,QAAQ,CAAC,gCAAgC,EAAE,MAAM;IAC/C,MAAMM,IAAI,GAAG,sCAAsC;IACnD,MAAMC,OAAO,GAAG;MACdC,MAAM,EAAE,KAAK;MACbC,GAAG,EAAE,0BAA0BH,IAAI;IACrC,CAAC;IAED,MAAMI,kBAAkB,GAAG;MACzBJ,IAAI;MACJK,MAAM,EAAE,SAAS;MACjBC,SAAS,EAAE,cAAc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AU;QACVM;MACF,CAAC,CAAC;MACF,MAAM;QAAEU;MAAS,CAAC,GAAG,MAAMvC,cAAc,CAACI,MAAM,EAAEM,OAAO,CAAC;MAE1D8B,MAAM,CAACD,QAAQ,CAACE,UAAU,CAAC,CAACC,IAAI,CAAC7C,WAAW,CAAC8C,SAAS,CAAC;MACvDH,MAAM,CAACD,QAAQ,CAACK,OAAO,CAACC,QAAQ,CAAC,CAACH,IAAI,CACpC,iDACF,CAAC;IACH,CAAC,CAAC;EACJ,CAAC,CAAC;EAEFW,QAAQ,CAAC,YAAY;IACnB,MAAMjD,MAAM,CAACkD,IAAI,CAAC,CAAC;EACrB,CAAC,CAAC;AACJ,CAAC,CAAC;;AAEF;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -55,6 +55,7 @@ function mapProxyRoute(options) {
|
|
|
55
55
|
return response;
|
|
56
56
|
},
|
|
57
57
|
options: {
|
|
58
|
+
auth: false,
|
|
58
59
|
validate: {
|
|
59
60
|
query: Joi.object().keys({
|
|
60
61
|
url: Joi.string().required()
|
|
@@ -98,6 +99,9 @@ function tileProxyRoute(options) {
|
|
|
98
99
|
return h.response('Tile fetch failed').code(res.statusCode);
|
|
99
100
|
}
|
|
100
101
|
return h.response(payload).type('application/x-protobuf').header('Cache-Control', 'public, max-age=86400');
|
|
102
|
+
},
|
|
103
|
+
options: {
|
|
104
|
+
auth: false
|
|
101
105
|
}
|
|
102
106
|
};
|
|
103
107
|
}
|
|
@@ -120,6 +124,7 @@ function geocodeProxyRoute(options) {
|
|
|
120
124
|
return data;
|
|
121
125
|
},
|
|
122
126
|
options: {
|
|
127
|
+
auth: false,
|
|
123
128
|
validate: {
|
|
124
129
|
query: Joi.object().keys({
|
|
125
130
|
query: Joi.string().required()
|
|
@@ -148,6 +153,7 @@ function reverseGeocodeProxyRoute(options) {
|
|
|
148
153
|
return data;
|
|
149
154
|
},
|
|
150
155
|
options: {
|
|
156
|
+
auth: false,
|
|
151
157
|
validate: {
|
|
152
158
|
query: Joi.object().keys({
|
|
153
159
|
easting: Joi.number().required(),
|
|
@@ -167,6 +173,7 @@ function mapStyleResourceRoutes() {
|
|
|
167
173
|
method: 'GET',
|
|
168
174
|
path: '/api/maps/vts/{path*}',
|
|
169
175
|
options: {
|
|
176
|
+
auth: false,
|
|
170
177
|
handler: {
|
|
171
178
|
directory: {
|
|
172
179
|
path: resolve(import.meta.dirname, './vts')
|
|
@@ -204,6 +211,7 @@ function getGeospatialCountries() {
|
|
|
204
211
|
return countries;
|
|
205
212
|
},
|
|
206
213
|
options: {
|
|
214
|
+
auth: false,
|
|
207
215
|
validate: {
|
|
208
216
|
query: Joi.object().keys({
|
|
209
217
|
omit: countrySchema.optional(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fs","resolve","GeospatialFieldOptionsCountryEnum","StatusCodes","Joi","getAccessToken","find","nearest","get","request","httpRequest","filePath","import","meta","dirname","countries","JSON","parse","readFileSync","countrySchema","string","valid","Object","values","getRoutes","options","mapStyleResourceRoutes","mapProxyRoute","tileProxyRoute","geocodeProxyRoute","reverseGeocodeProxyRoute","getGeospatialCountries","method","path","handler","h","query","targetUrl","URL","decodeURIComponent","url","token","searchParams","set","proxyResponse","toString","headers","Authorization","buffer","payload","contentType","res","response","type","validate","object","keys","required","optional","z","y","x","params","getBuffer","Accept","json","gunzip","statusCode","OK","valueOf","code","header","_h","data","ordnanceSurveyApiKey","easting","northing","number","directory","omit","only","features","filter","feature","id"],"sources":["../../../../../src/server/plugins/map/routes/index.js"],"sourcesContent":["import fs from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport { GeospatialFieldOptionsCountryEnum } from '@defra/forms-model'\nimport { StatusCodes } from 'http-status-codes'\nimport Joi from 'joi'\n\nimport { getAccessToken } from '~/src/server/plugins/map/routes/get-os-token.js'\nimport { find, nearest } from '~/src/server/plugins/map/service.js'\nimport {\n get,\n request as httpRequest\n} from '~/src/server/services/httpService.js'\n\nconst filePath = resolve(import.meta.dirname, './vts/countries.geojson')\n\n/**\n * @type {FeatureCollection}\n */\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nexport const countries = JSON.parse(fs.readFileSync(filePath, 'utf8'))\n\nexport const countrySchema = Joi.string().valid(\n ...Object.values(GeospatialFieldOptionsCountryEnum)\n)\n\n/**\n * Gets the map support routes\n * @param {MapConfiguration} options - ordnance survey names api key\n */\nexport function getRoutes(options) {\n return [\n mapStyleResourceRoutes(),\n mapProxyRoute(options),\n tileProxyRoute(options),\n geocodeProxyRoute(options),\n reverseGeocodeProxyRoute(options),\n getGeospatialCountries()\n ]\n}\n\n/**\n * Proxies ordnance survey requests from the front end to api.os.com\n * Used for the VTS map source by forwarding on the request\n * and adding the auth token and SRS (spatial reference system)\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction mapProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/map-proxy',\n handler: async (request, h) => {\n const { query } = request\n const targetUrl = new URL(decodeURIComponent(query.url))\n const token = await getAccessToken(options)\n\n targetUrl.searchParams.set('srs', '3857')\n\n const proxyResponse = await httpRequest('get', targetUrl.toString(), {\n headers: {\n Authorization: `Bearer ${token}`\n }\n })\n const buffer = proxyResponse.payload\n const contentType = proxyResponse.res.headers['content-type']\n const response = h.response(buffer)\n\n if (contentType) {\n response.type(contentType)\n }\n\n return response\n },\n options: {\n validate: {\n query: Joi.object()\n .keys({\n url: Joi.string().required()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * Proxies ordnance survey requests from the front end to api.os.uk\n * Used for VTS map tiles forwarding on the request and adding the auth token\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction tileProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/tile/{z}/{y}/{x}.pbf',\n handler: async (request, h) => {\n const { z, y, x } = request.params\n const token = await getAccessToken(options)\n\n const url = `https://api.os.uk/maps/vector/v1/vts/tile/${z}/${y}/${x}.pbf?srs=3857`\n\n const getBuffer = /** @type {typeof get<Buffer>} */ (get)\n\n const { payload, res } = await getBuffer(url, {\n headers: {\n Authorization: `Bearer ${token}`,\n Accept: 'application/x-protobuf'\n },\n json: false,\n gunzip: true\n })\n\n if (res.statusCode && res.statusCode !== StatusCodes.OK.valueOf()) {\n return h.response('Tile fetch failed').code(res.statusCode)\n }\n\n return h\n .response(payload)\n .type('application/x-protobuf')\n .header('Cache-Control', 'public, max-age=86400')\n }\n }\n}\n\n/**\n * Proxies ordnance survey geocode requests from the front end to api.os.uk\n * Used for the gazzeteer address lookup to find name from query strings like postcode and place names\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapGeocodeGetRequestRefs>}\n */\nfunction geocodeProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/geocode-proxy',\n async handler(request, _h) {\n const { query } = request\n const data = await find(query.query, options.ordnanceSurveyApiKey)\n\n return data\n },\n options: {\n validate: {\n query: Joi.object()\n .keys({\n query: Joi.string().required()\n })\n .required()\n }\n }\n }\n}\n\n/**\n * Proxies ordnance survey reverse geocode requests from the front end to api.os.uk\n * Used to find name from easting and northing points.\n * N.B this endpoint is currently not used by the front end but will be soon in \"maps V2\"\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapReverseGeocodeGetRequestRefs>}\n */\nfunction reverseGeocodeProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/reverse-geocode-proxy',\n async handler(request, _h) {\n const { query } = request\n const data = await nearest(\n query.easting,\n query.northing,\n options.ordnanceSurveyApiKey\n )\n\n return data\n },\n options: {\n validate: {\n query: Joi.object()\n .keys({\n easting: Joi.number().required(),\n northing: Joi.number().required()\n })\n .required()\n }\n }\n }\n}\n\n/**\n * Resource routes to return sprites and glyphs\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction mapStyleResourceRoutes() {\n return {\n method: 'GET',\n path: '/api/maps/vts/{path*}',\n options: {\n handler: {\n directory: {\n path: resolve(import.meta.dirname, './vts')\n }\n }\n }\n }\n}\n\n/**\n * Resource routes to return sprites and glyphs\n * @returns {ServerRoute<GeospatialCountriesGetRequestRefs>}\n */\nfunction getGeospatialCountries() {\n return {\n method: 'GET',\n path: '/api/maps/countries.geojson',\n handler: (request) => {\n const { omit, only } = request.query\n\n if (omit) {\n return {\n ...countries,\n features: countries.features.filter((feature) => feature.id !== omit)\n }\n }\n\n if (only) {\n return {\n ...countries,\n features: countries.features.filter((feature) => feature.id === only)\n }\n }\n\n return countries\n },\n options: {\n validate: {\n query: Joi.object()\n .keys({\n omit: countrySchema.optional(),\n only: countrySchema.optional()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * @import { ServerRoute } from '@hapi/hapi'\n * @import { FeatureCollection } from 'geojson'\n * @import { MapConfiguration, MapProxyGetRequestRefs, MapGeocodeGetRequestRefs, MapReverseGeocodeGetRequestRefs, GeospatialCountriesGetRequestRefs } from '~/src/server/plugins/map/types.js'\n */\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,SAAS;AACxB,SAASC,OAAO,QAAQ,WAAW;AAEnC,SAASC,iCAAiC,QAAQ,oBAAoB;AACtE,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,OAAOC,GAAG,MAAM,KAAK;AAErB,SAASC,cAAc;AACvB,SAASC,IAAI,EAAEC,OAAO;AACtB,SACEC,GAAG,EACHC,OAAO,IAAIC,WAAW;AAGxB,MAAMC,QAAQ,GAAGV,OAAO,CAACW,MAAM,CAACC,IAAI,CAACC,OAAO,EAAE,yBAAyB,CAAC;;AAExE;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAGC,IAAI,CAACC,KAAK,CAACjB,EAAE,CAACkB,YAAY,CAACP,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEtE,OAAO,MAAMQ,aAAa,GAAGf,GAAG,CAACgB,MAAM,CAAC,CAAC,CAACC,KAAK,CAC7C,GAAGC,MAAM,CAACC,MAAM,CAACrB,iCAAiC,CACpD,CAAC;;AAED;AAC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AAC,CAAC;UAC9BsB,IAAI,EAAE7D,aAAa,CAACuC,QAAQ,CAAC;QAC/B,CAAC,CAAC,CACDA,QAAQ,CAAC;MACd;IACF;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["fs","resolve","GeospatialFieldOptionsCountryEnum","StatusCodes","Joi","getAccessToken","find","nearest","get","request","httpRequest","filePath","import","meta","dirname","countries","JSON","parse","readFileSync","countrySchema","string","valid","Object","values","getRoutes","options","mapStyleResourceRoutes","mapProxyRoute","tileProxyRoute","geocodeProxyRoute","reverseGeocodeProxyRoute","getGeospatialCountries","method","path","handler","h","query","targetUrl","URL","decodeURIComponent","url","token","searchParams","set","proxyResponse","toString","headers","Authorization","buffer","payload","contentType","res","response","type","auth","validate","object","keys","required","optional","z","y","x","params","getBuffer","Accept","json","gunzip","statusCode","OK","valueOf","code","header","_h","data","ordnanceSurveyApiKey","easting","northing","number","directory","omit","only","features","filter","feature","id"],"sources":["../../../../../src/server/plugins/map/routes/index.js"],"sourcesContent":["import fs from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport { GeospatialFieldOptionsCountryEnum } from '@defra/forms-model'\nimport { StatusCodes } from 'http-status-codes'\nimport Joi from 'joi'\n\nimport { getAccessToken } from '~/src/server/plugins/map/routes/get-os-token.js'\nimport { find, nearest } from '~/src/server/plugins/map/service.js'\nimport {\n get,\n request as httpRequest\n} from '~/src/server/services/httpService.js'\n\nconst filePath = resolve(import.meta.dirname, './vts/countries.geojson')\n\n/**\n * @type {FeatureCollection}\n */\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nexport const countries = JSON.parse(fs.readFileSync(filePath, 'utf8'))\n\nexport const countrySchema = Joi.string().valid(\n ...Object.values(GeospatialFieldOptionsCountryEnum)\n)\n\n/**\n * Gets the map support routes\n * @param {MapConfiguration} options - ordnance survey names api key\n */\nexport function getRoutes(options) {\n return [\n mapStyleResourceRoutes(),\n mapProxyRoute(options),\n tileProxyRoute(options),\n geocodeProxyRoute(options),\n reverseGeocodeProxyRoute(options),\n getGeospatialCountries()\n ]\n}\n\n/**\n * Proxies ordnance survey requests from the front end to api.os.com\n * Used for the VTS map source by forwarding on the request\n * and adding the auth token and SRS (spatial reference system)\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction mapProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/map-proxy',\n handler: async (request, h) => {\n const { query } = request\n const targetUrl = new URL(decodeURIComponent(query.url))\n const token = await getAccessToken(options)\n\n targetUrl.searchParams.set('srs', '3857')\n\n const proxyResponse = await httpRequest('get', targetUrl.toString(), {\n headers: {\n Authorization: `Bearer ${token}`\n }\n })\n const buffer = proxyResponse.payload\n const contentType = proxyResponse.res.headers['content-type']\n const response = h.response(buffer)\n\n if (contentType) {\n response.type(contentType)\n }\n\n return response\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n url: Joi.string().required()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * Proxies ordnance survey requests from the front end to api.os.uk\n * Used for VTS map tiles forwarding on the request and adding the auth token\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction tileProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/tile/{z}/{y}/{x}.pbf',\n handler: async (request, h) => {\n const { z, y, x } = request.params\n const token = await getAccessToken(options)\n\n const url = `https://api.os.uk/maps/vector/v1/vts/tile/${z}/${y}/${x}.pbf?srs=3857`\n\n const getBuffer = /** @type {typeof get<Buffer>} */ (get)\n\n const { payload, res } = await getBuffer(url, {\n headers: {\n Authorization: `Bearer ${token}`,\n Accept: 'application/x-protobuf'\n },\n json: false,\n gunzip: true\n })\n\n if (res.statusCode && res.statusCode !== StatusCodes.OK.valueOf()) {\n return h.response('Tile fetch failed').code(res.statusCode)\n }\n\n return h\n .response(payload)\n .type('application/x-protobuf')\n .header('Cache-Control', 'public, max-age=86400')\n },\n options: {\n auth: false\n }\n }\n}\n\n/**\n * Proxies ordnance survey geocode requests from the front end to api.os.uk\n * Used for the gazzeteer address lookup to find name from query strings like postcode and place names\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapGeocodeGetRequestRefs>}\n */\nfunction geocodeProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/geocode-proxy',\n async handler(request, _h) {\n const { query } = request\n const data = await find(query.query, options.ordnanceSurveyApiKey)\n\n return data\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n query: Joi.string().required()\n })\n .required()\n }\n }\n }\n}\n\n/**\n * Proxies ordnance survey reverse geocode requests from the front end to api.os.uk\n * Used to find name from easting and northing points.\n * N.B this endpoint is currently not used by the front end but will be soon in \"maps V2\"\n * @param {MapConfiguration} options - the map options\n * @returns {ServerRoute<MapReverseGeocodeGetRequestRefs>}\n */\nfunction reverseGeocodeProxyRoute(options) {\n return {\n method: 'GET',\n path: '/api/reverse-geocode-proxy',\n async handler(request, _h) {\n const { query } = request\n const data = await nearest(\n query.easting,\n query.northing,\n options.ordnanceSurveyApiKey\n )\n\n return data\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n easting: Joi.number().required(),\n northing: Joi.number().required()\n })\n .required()\n }\n }\n }\n}\n\n/**\n * Resource routes to return sprites and glyphs\n * @returns {ServerRoute<MapProxyGetRequestRefs>}\n */\nfunction mapStyleResourceRoutes() {\n return {\n method: 'GET',\n path: '/api/maps/vts/{path*}',\n options: {\n auth: false,\n handler: {\n directory: {\n path: resolve(import.meta.dirname, './vts')\n }\n }\n }\n }\n}\n\n/**\n * Resource routes to return sprites and glyphs\n * @returns {ServerRoute<GeospatialCountriesGetRequestRefs>}\n */\nfunction getGeospatialCountries() {\n return {\n method: 'GET',\n path: '/api/maps/countries.geojson',\n handler: (request) => {\n const { omit, only } = request.query\n\n if (omit) {\n return {\n ...countries,\n features: countries.features.filter((feature) => feature.id !== omit)\n }\n }\n\n if (only) {\n return {\n ...countries,\n features: countries.features.filter((feature) => feature.id === only)\n }\n }\n\n return countries\n },\n options: {\n auth: false,\n validate: {\n query: Joi.object()\n .keys({\n omit: countrySchema.optional(),\n only: countrySchema.optional()\n })\n .optional()\n }\n }\n }\n}\n\n/**\n * @import { ServerRoute } from '@hapi/hapi'\n * @import { FeatureCollection } from 'geojson'\n * @import { MapConfiguration, MapProxyGetRequestRefs, MapGeocodeGetRequestRefs, MapReverseGeocodeGetRequestRefs, GeospatialCountriesGetRequestRefs } from '~/src/server/plugins/map/types.js'\n */\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,SAAS;AACxB,SAASC,OAAO,QAAQ,WAAW;AAEnC,SAASC,iCAAiC,QAAQ,oBAAoB;AACtE,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,OAAOC,GAAG,MAAM,KAAK;AAErB,SAASC,cAAc;AACvB,SAASC,IAAI,EAAEC,OAAO;AACtB,SACEC,GAAG,EACHC,OAAO,IAAIC,WAAW;AAGxB,MAAMC,QAAQ,GAAGV,OAAO,CAACW,MAAM,CAACC,IAAI,CAACC,OAAO,EAAE,yBAAyB,CAAC;;AAExE;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAGC,IAAI,CAACC,KAAK,CAACjB,EAAE,CAACkB,YAAY,CAACP,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEtE,OAAO,MAAMQ,aAAa,GAAGf,GAAG,CAACgB,MAAM,CAAC,CAAC,CAACC,KAAK,CAC7C,GAAGC,MAAM,CAACC,MAAM,CAACrB,iCAAiC,CACpD,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,SAASsB,SAASA,CAACC,OAAO,EAAE;EACjC,OAAO,CACLC,sBAAsB,CAAC,CAAC,EACxBC,aAAa,CAACF,OAAO,CAAC,EACtBG,cAAc,CAACH,OAAO,CAAC,EACvBI,iBAAiB,CAACJ,OAAO,CAAC,EAC1BK,wBAAwB,CAACL,OAAO,CAAC,EACj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CAAC;QAC/B,CAAC,CAAC,CACDA,QAAQ,CAAC;MACd;IACF;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -41,9 +41,9 @@ export class CheckboxesField extends SelectionControlField {
|
|
|
41
41
|
.label(this.label)
|
|
42
42
|
.required()
|
|
43
43
|
.messages({
|
|
44
|
-
'array.min':
|
|
45
|
-
'array.max':
|
|
46
|
-
'array.length':
|
|
44
|
+
'array.min': messageTemplate.arrayMin as string,
|
|
45
|
+
'array.max': messageTemplate.arrayMax as string,
|
|
46
|
+
'array.length': messageTemplate.arrayLength as string
|
|
47
47
|
})
|
|
48
48
|
|
|
49
49
|
if (options.required === false) {
|
|
@@ -61,7 +61,10 @@ export const messageTemplate: Record<string, JoiExpression> = {
|
|
|
61
61
|
) as JoiExpression,
|
|
62
62
|
dateFormat: '{{#title}} must be a real date',
|
|
63
63
|
dateMin: '{{#title}} must be the same as or after {{#limit}}',
|
|
64
|
-
dateMax: '{{#title}} must be the same as or before {{#limit}}'
|
|
64
|
+
dateMax: '{{#title}} must be the same as or before {{#limit}}',
|
|
65
|
+
arrayMin: 'Select at least {{#limit}} options from the list',
|
|
66
|
+
arrayMax: 'Only {{#limit}} can be selected from the list',
|
|
67
|
+
arrayLength: 'Select only {{#limit}} options from the list'
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
export const messages: LanguageMessagesExt = {
|
|
@@ -73,6 +73,7 @@ function mapProxyRoute(options) {
|
|
|
73
73
|
return response
|
|
74
74
|
},
|
|
75
75
|
options: {
|
|
76
|
+
auth: false,
|
|
76
77
|
validate: {
|
|
77
78
|
query: Joi.object()
|
|
78
79
|
.keys({
|
|
@@ -119,6 +120,9 @@ function tileProxyRoute(options) {
|
|
|
119
120
|
.response(payload)
|
|
120
121
|
.type('application/x-protobuf')
|
|
121
122
|
.header('Cache-Control', 'public, max-age=86400')
|
|
123
|
+
},
|
|
124
|
+
options: {
|
|
125
|
+
auth: false
|
|
122
126
|
}
|
|
123
127
|
}
|
|
124
128
|
}
|
|
@@ -140,6 +144,7 @@ function geocodeProxyRoute(options) {
|
|
|
140
144
|
return data
|
|
141
145
|
},
|
|
142
146
|
options: {
|
|
147
|
+
auth: false,
|
|
143
148
|
validate: {
|
|
144
149
|
query: Joi.object()
|
|
145
150
|
.keys({
|
|
@@ -173,6 +178,7 @@ function reverseGeocodeProxyRoute(options) {
|
|
|
173
178
|
return data
|
|
174
179
|
},
|
|
175
180
|
options: {
|
|
181
|
+
auth: false,
|
|
176
182
|
validate: {
|
|
177
183
|
query: Joi.object()
|
|
178
184
|
.keys({
|
|
@@ -194,6 +200,7 @@ function mapStyleResourceRoutes() {
|
|
|
194
200
|
method: 'GET',
|
|
195
201
|
path: '/api/maps/vts/{path*}',
|
|
196
202
|
options: {
|
|
203
|
+
auth: false,
|
|
197
204
|
handler: {
|
|
198
205
|
directory: {
|
|
199
206
|
path: resolve(import.meta.dirname, './vts')
|
|
@@ -231,6 +238,7 @@ function getGeospatialCountries() {
|
|
|
231
238
|
return countries
|
|
232
239
|
},
|
|
233
240
|
options: {
|
|
241
|
+
auth: false,
|
|
234
242
|
validate: {
|
|
235
243
|
query: Joi.object()
|
|
236
244
|
.keys({
|