@defra/forms-engine-plugin 5.0.0-alpha.5 → 5.0.0-alpha.6

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.
Files changed (43) hide show
  1. package/.server/server/constants.d.ts +1 -0
  2. package/.server/server/constants.js +1 -0
  3. package/.server/server/constants.js.map +1 -1
  4. package/.server/server/plugins/engine/components/ComponentBase.d.ts +1 -0
  5. package/.server/server/plugins/engine/components/ComponentBase.js +2 -0
  6. package/.server/server/plugins/engine/components/ComponentBase.js.map +1 -1
  7. package/.server/server/plugins/engine/components/ComponentCollection.js +2 -1
  8. package/.server/server/plugins/engine/components/ComponentCollection.js.map +1 -1
  9. package/.server/server/plugins/engine/components/DeclarationField.js +1 -1
  10. package/.server/server/plugins/engine/components/DeclarationField.js.map +1 -1
  11. package/.server/server/plugins/engine/components/FormComponent.js +2 -2
  12. package/.server/server/plugins/engine/components/FormComponent.js.map +1 -1
  13. package/.server/server/plugins/engine/components/Markdown.js +1 -1
  14. package/.server/server/plugins/engine/components/Markdown.js.map +1 -1
  15. package/.server/server/plugins/engine/i18n/types.d.ts +1 -0
  16. package/.server/server/plugins/engine/i18n/types.js.map +1 -1
  17. package/.server/server/plugins/engine/models/SummaryViewModel.js +7 -3
  18. package/.server/server/plugins/engine/models/SummaryViewModel.js.map +1 -1
  19. package/.server/server/plugins/engine/outputFormatters/adapter/v1.js +3 -5
  20. package/.server/server/plugins/engine/outputFormatters/adapter/v1.js.map +1 -1
  21. package/.server/server/plugins/engine/pageControllers/RepeatPageController.js +3 -4
  22. package/.server/server/plugins/engine/pageControllers/RepeatPageController.js.map +1 -1
  23. package/.server/server/plugins/engine/pageControllers/SummaryPageController.js +5 -2
  24. package/.server/server/plugins/engine/pageControllers/SummaryPageController.js.map +1 -1
  25. package/.server/server/plugins/engine/services/notifyService.d.ts +1 -1
  26. package/.server/server/plugins/engine/services/notifyService.js +1 -1
  27. package/.server/server/plugins/engine/services/notifyService.js.map +1 -1
  28. package/.server/server/types.d.ts +1 -1
  29. package/.server/server/types.js.map +1 -1
  30. package/package.json +2 -2
  31. package/src/server/constants.js +1 -0
  32. package/src/server/plugins/engine/components/ComponentBase.ts +2 -0
  33. package/src/server/plugins/engine/components/ComponentCollection.ts +4 -5
  34. package/src/server/plugins/engine/components/DeclarationField.ts +1 -2
  35. package/src/server/plugins/engine/components/FormComponent.ts +2 -4
  36. package/src/server/plugins/engine/components/Markdown.ts +2 -3
  37. package/src/server/plugins/engine/i18n/types.ts +1 -0
  38. package/src/server/plugins/engine/models/SummaryViewModel.ts +4 -4
  39. package/src/server/plugins/engine/outputFormatters/adapter/v1.ts +3 -6
  40. package/src/server/plugins/engine/pageControllers/RepeatPageController.ts +2 -2
  41. package/src/server/plugins/engine/pageControllers/SummaryPageController.ts +7 -1
  42. package/src/server/plugins/engine/services/notifyService.ts +1 -0
  43. package/src/server/types.ts +1 -0
@@ -5,3 +5,4 @@ export const EXTERNAL_STATE_PAYLOAD: "EXTERNAL_STATE_PAYLOAD";
5
5
  export const EXTERNAL_STATE_APPENDAGE: "EXTERNAL_STATE_APPENDAGE";
6
6
  export const COMPONENT_STATE_ERROR: "COMPONENT_STATE_ERROR";
7
7
  export const PAYMENT_EXPIRED_NOTIFICATION: "PAYMENT_EXPIRED_NOTIFICATION";
8
+ export const EN_GB: "en-GB";
@@ -5,4 +5,5 @@ export const EXTERNAL_STATE_PAYLOAD = 'EXTERNAL_STATE_PAYLOAD';
5
5
  export const EXTERNAL_STATE_APPENDAGE = 'EXTERNAL_STATE_APPENDAGE';
6
6
  export const COMPONENT_STATE_ERROR = 'COMPONENT_STATE_ERROR';
7
7
  export const PAYMENT_EXPIRED_NOTIFICATION = 'PAYMENT_EXPIRED_NOTIFICATION';
8
+ export const EN_GB = 'en-GB';
8
9
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":["FORM_VERSION_METADATA_KEY","PREVIEW_PATH_PREFIX","FORM_PREFIX","EXTERNAL_STATE_PAYLOAD","EXTERNAL_STATE_APPENDAGE","COMPONENT_STATE_ERROR","PAYMENT_EXPIRED_NOTIFICATION"],"sources":["../../src/server/constants.js"],"sourcesContent":["export const FORM_VERSION_METADATA_KEY = '$$__formVersion'\nexport const PREVIEW_PATH_PREFIX = '/preview'\nexport const FORM_PREFIX = ''\nexport const EXTERNAL_STATE_PAYLOAD = 'EXTERNAL_STATE_PAYLOAD'\nexport const EXTERNAL_STATE_APPENDAGE = 'EXTERNAL_STATE_APPENDAGE'\nexport const COMPONENT_STATE_ERROR = 'COMPONENT_STATE_ERROR'\nexport const PAYMENT_EXPIRED_NOTIFICATION = 'PAYMENT_EXPIRED_NOTIFICATION'\n"],"mappings":"AAAA,OAAO,MAAMA,yBAAyB,GAAG,iBAAiB;AAC1D,OAAO,MAAMC,mBAAmB,GAAG,UAAU;AAC7C,OAAO,MAAMC,WAAW,GAAG,EAAE;AAC7B,OAAO,MAAMC,sBAAsB,GAAG,wBAAwB;AAC9D,OAAO,MAAMC,wBAAwB,GAAG,0BAA0B;AAClE,OAAO,MAAMC,qBAAqB,GAAG,uBAAuB;AAC5D,OAAO,MAAMC,4BAA4B,GAAG,8BAA8B","ignoreList":[]}
1
+ {"version":3,"file":"constants.js","names":["FORM_VERSION_METADATA_KEY","PREVIEW_PATH_PREFIX","FORM_PREFIX","EXTERNAL_STATE_PAYLOAD","EXTERNAL_STATE_APPENDAGE","COMPONENT_STATE_ERROR","PAYMENT_EXPIRED_NOTIFICATION","EN_GB"],"sources":["../../src/server/constants.js"],"sourcesContent":["export const FORM_VERSION_METADATA_KEY = '$$__formVersion'\nexport const PREVIEW_PATH_PREFIX = '/preview'\nexport const FORM_PREFIX = ''\nexport const EXTERNAL_STATE_PAYLOAD = 'EXTERNAL_STATE_PAYLOAD'\nexport const EXTERNAL_STATE_APPENDAGE = 'EXTERNAL_STATE_APPENDAGE'\nexport const COMPONENT_STATE_ERROR = 'COMPONENT_STATE_ERROR'\nexport const PAYMENT_EXPIRED_NOTIFICATION = 'PAYMENT_EXPIRED_NOTIFICATION'\nexport const EN_GB = 'en-GB'\n"],"mappings":"AAAA,OAAO,MAAMA,yBAAyB,GAAG,iBAAiB;AAC1D,OAAO,MAAMC,mBAAmB,GAAG,UAAU;AAC7C,OAAO,MAAMC,WAAW,GAAG,EAAE;AAC7B,OAAO,MAAMC,sBAAsB,GAAG,wBAAwB;AAC9D,OAAO,MAAMC,wBAAwB,GAAG,0BAA0B;AAClE,OAAO,MAAMC,qBAAqB,GAAG,uBAAuB;AAC5D,OAAO,MAAMC,4BAA4B,GAAG,8BAA8B;AAC1E,OAAO,MAAMC,KAAK,GAAG,OAAO","ignoreList":[]}
@@ -21,6 +21,7 @@ export declare class ComponentBase {
21
21
  }>['options'];
22
22
  isFormComponent: boolean;
23
23
  model: FormModel;
24
+ def: ComponentDef;
24
25
  /** joi schemas based on a component defined in the form JSON. This validates a user's answer and is generated from {@link ComponentDef} */
25
26
  formSchema: ComponentSchema;
26
27
  stateSchema: ComponentSchema;
@@ -12,6 +12,7 @@ export class ComponentBase {
12
12
  options;
13
13
  isFormComponent = false;
14
14
  model;
15
+ def;
15
16
 
16
17
  /** joi schemas based on a component defined in the form JSON. This validates a user's answer and is generated from {@link ComponentDef} */
17
18
  formSchema = joi.string();
@@ -21,6 +22,7 @@ export class ComponentBase {
21
22
  this.type = def.type;
22
23
  this.name = def.name;
23
24
  this.title = def.title;
25
+ this.def = def;
24
26
  if ('schema' in def) {
25
27
  this.schema = def.schema;
26
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ComponentBase.js","names":["isConditionalRevealType","joi","ComponentBase","id","page","parent","collection","type","name","title","schema","options","isFormComponent","model","formSchema","string","stateSchema","constructor","def","props","viewModel","attributes","autocomplete","classes","condition"],"sources":["../../../../../src/server/plugins/engine/components/ComponentBase.ts"],"sourcesContent":["import { isConditionalRevealType, type ComponentDef } from '@defra/forms-model'\nimport joi, {\n type ArraySchema,\n type BooleanSchema,\n type DateSchema,\n type NumberSchema,\n type ObjectSchema,\n type StringSchema\n} from 'joi'\n\nimport { type ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js'\nimport { type Component } from '~/src/server/plugins/engine/components/helpers/components.js'\nimport { type ViewModel } from '~/src/server/plugins/engine/components/types.js'\nimport { type FormModel } from '~/src/server/plugins/engine/models/index.js'\nimport { type PageControllerClass } from '~/src/server/plugins/engine/pageControllers/helpers/pages.js'\n\nexport class ComponentBase {\n id?: string\n page?: PageControllerClass\n parent: Component | undefined\n collection: ComponentCollection | undefined\n\n type: ComponentDef['type']\n name: ComponentDef['name']\n title: ComponentDef['title']\n schema?: Extract<ComponentDef, { schema?: object }>['schema']\n options?: Extract<ComponentDef, { options: object }>['options']\n\n isFormComponent = false\n model: FormModel\n\n /** joi schemas based on a component defined in the form JSON. This validates a user's answer and is generated from {@link ComponentDef} */\n formSchema: ComponentSchema = joi.string()\n stateSchema: ComponentSchema = joi.string()\n\n constructor(\n def: ComponentDef,\n props: {\n page?: PageControllerClass\n parent?: Component\n model: FormModel\n }\n ) {\n this.id = def.id\n this.type = def.type\n this.name = def.name\n this.title = def.title\n\n if ('schema' in def) {\n this.schema = def.schema\n }\n\n if ('options' in def) {\n this.options = def.options\n }\n\n this.page = props.page\n this.parent = props.parent\n this.model = props.model\n }\n\n get viewModel() {\n const { options, type } = this\n\n const viewModel: ViewModel = {\n attributes: {}\n }\n\n if (!options) {\n return viewModel\n }\n\n if ('autocomplete' in options) {\n viewModel.attributes.autocomplete = options.autocomplete\n }\n\n if ('classes' in options) {\n viewModel.classes = options.classes\n }\n\n if ('condition' in options && isConditionalRevealType(type)) {\n viewModel.condition = options.condition\n }\n\n return viewModel\n }\n}\n\nexport type ComponentSchema =\n | ArraySchema<string>\n | ArraySchema<number>\n | ArraySchema<boolean>\n | ArraySchema<object>\n | BooleanSchema<string>\n | BooleanSchema\n | DateSchema\n | NumberSchema<string>\n | NumberSchema\n | ObjectSchema\n | StringSchema\n"],"mappings":"AAAA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GAAGX,OAAO,CAACW,YAAY;IAC1D;IAEA,IAAI,SAAS,IAAIX,OAAO,EAAE;MACxBS,SAAS,CAACG,OAAO,GAAGZ,OAAO,CAACY,OAAO;IACrC;IAEA,IAAI,WAAW,IAAIZ,OAAO,IAAIX,uBAAuB,CAACO,IAAI,CAAC,EAAE;MAC3Da,SAAS,CAACI,SAAS,GAAGb,OAAO,CAACa,SAAS;IACzC;IAEA,OAAOJ,SAAS;EAClB;AACF","ignoreList":[]}
1
+ {"version":3,"file":"ComponentBase.js","names":["isConditionalRevealType","joi","ComponentBase","id","page","parent","collection","type","name","title","schema","options","isFormComponent","model","def","formSchema","string","stateSchema","constructor","props","viewModel","attributes","autocomplete","classes","condition"],"sources":["../../../../../src/server/plugins/engine/components/ComponentBase.ts"],"sourcesContent":["import { isConditionalRevealType, type ComponentDef } from '@defra/forms-model'\nimport joi, {\n type ArraySchema,\n type BooleanSchema,\n type DateSchema,\n type NumberSchema,\n type ObjectSchema,\n type StringSchema\n} from 'joi'\n\nimport { type ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js'\nimport { type Component } from '~/src/server/plugins/engine/components/helpers/components.js'\nimport { type ViewModel } from '~/src/server/plugins/engine/components/types.js'\nimport { type FormModel } from '~/src/server/plugins/engine/models/index.js'\nimport { type PageControllerClass } from '~/src/server/plugins/engine/pageControllers/helpers/pages.js'\n\nexport class ComponentBase {\n id?: string\n page?: PageControllerClass\n parent: Component | undefined\n collection: ComponentCollection | undefined\n\n type: ComponentDef['type']\n name: ComponentDef['name']\n title: ComponentDef['title']\n schema?: Extract<ComponentDef, { schema?: object }>['schema']\n options?: Extract<ComponentDef, { options: object }>['options']\n\n isFormComponent = false\n model: FormModel\n def: ComponentDef\n\n /** joi schemas based on a component defined in the form JSON. This validates a user's answer and is generated from {@link ComponentDef} */\n formSchema: ComponentSchema = joi.string()\n stateSchema: ComponentSchema = joi.string()\n\n constructor(\n def: ComponentDef,\n props: {\n page?: PageControllerClass\n parent?: Component\n model: FormModel\n }\n ) {\n this.id = def.id\n this.type = def.type\n this.name = def.name\n this.title = def.title\n this.def = def\n\n if ('schema' in def) {\n this.schema = def.schema\n }\n\n if ('options' in def) {\n this.options = def.options\n }\n\n this.page = props.page\n this.parent = props.parent\n this.model = props.model\n }\n\n get viewModel() {\n const { options, type } = this\n\n const viewModel: ViewModel = {\n attributes: {}\n }\n\n if (!options) {\n return viewModel\n }\n\n if ('autocomplete' in options) {\n viewModel.attributes.autocomplete = options.autocomplete\n }\n\n if ('classes' in options) {\n viewModel.classes = options.classes\n }\n\n if ('condition' in options && isConditionalRevealType(type)) {\n viewModel.condition = options.condition\n }\n\n return viewModel\n }\n}\n\nexport type ComponentSchema =\n | ArraySchema<string>\n | ArraySchema<number>\n | ArraySchema<boolean>\n | ArraySchema<object>\n | BooleanSchema<string>\n | BooleanSchema\n | DateSchema\n | NumberSchema<string>\n | NumberSchema\n | ObjectSchema\n | StringSchema\n"],"mappings":"AAAA,SAASA,uBAAuB,QAA2B,oBAAoB;AAC/E,OAAOC,GAAG,MAOH,KAAK;AAQZ,OAAO,MAAMC,aAAa,CAAC;EACzBC,EAAE;EACFC,IAAI;EACJC,MAAM;EACNC,UAAU;EAEVC,IAAI;EACJC,IAAI;EACJC,KAAK;EACLC,MAAM;EACNC,OAAO;EAEPC,eAAe,GAAG,KAAK;EACvBC,KAAK;EACLC,GAAG;;EAEH;EACAC,UAAU,GAAoBd,GAAG,CAACe,MAAM,CAAC,CAAC;EAC1CC,WAAW,GAAoBhB,GAAG,CAACe,MAAM,CAAC,CAAC;EAE3CE,WAAWA,CACTJ,GAAiB,EACjBK,KAIC,EACD;IACA,IAAI,CAAChB,EAAE,GAAGW,GAAG,CAACX,EAAE;IAChB,IAAI,CAACI,IAAI,GAAGO,GAAG,CAACP,IAAI;IACpB,IAAI,CAACC,IAAI,GAAGM,GAAG,CAACN,IAAI;IACpB,IAAI,CAACC,KAAK,GAAGK,GAAG,CAACL,KAAK;IACtB,IAAI,CAACK,GAAG,GAAGA,GAAG;IAEd,IAAI,QAAQ,IAAIA,GAAG,EAAE;MACnB,IAAI,CAACJ,MAAM,GAAGI,GAAG,CAACJ,MAAM;IAC1B;IAEA,IAAI,SAAS,IAAII,GAAG,EAAE;MACpB,IAAI,CAACH,OAAO,GAAGG,GAAG,CAACH,OAAO;IAC5B;IAEA,IAAI,CAACP,IAAI,GAAGe,KAAK,CAACf,IAAI;IACtB,IAAI,CAACC,MAAM,GAAGc,KAAK,CAACd,MAAM;IAC1B,IAAI,CAACQ,KAAK,GAAGM,KAAK,CAACN,KAAK;EAC1B;EAEA,IAAIO,SAASA,CAAA,EAAG;IACd,MAAM;MAAET,OAAO;MAAEJ;IAAK,CAAC,GAAG,IAAI;IAE9B,MAAMa,SAAoB,GAAG;MAC3BC,UAAU,EAAE,CAAC;IACf,CAAC;IAED,IAAI,CAACV,OAAO,EAAE;MACZ,OAAOS,SAAS;IAClB;IAEA,IAAI,cAAc,IAAIT,OAAO,EAAE;MAC7BS,SAAS,CAACC,UAAU,CAACC,YAAY,GAAGX,OAAO,CAACW,YAAY;IAC1D;IAEA,IAAI,SAAS,IAAIX,OAAO,EAAE;MACxBS,SAAS,CAACG,OAAO,GAAGZ,OAAO,CAACY,OAAO;IACrC;IAEA,IAAI,WAAW,IAAIZ,OAAO,IAAIX,uBAAuB,CAACO,IAAI,CAAC,EAAE;MAC3Da,SAAS,CAACI,SAAS,GAAGb,OAAO,CAACa,SAAS;IACzC;IAEA,OAAOJ,SAAS;EAClB;AACF","ignoreList":[]}
@@ -210,7 +210,8 @@ export class ComponentCollection {
210
210
  labelOverrides[subField.name] = patchedSchema;
211
211
  }
212
212
  } else {
213
- const translatedLabel = translator.tComponent(field, 'shortDescription') || translator.tComponent(field, 'title');
213
+ const fieldDef = field.def;
214
+ const translatedLabel = translator.tComponent(fieldDef, 'errorDescription') || translator.tComponent(fieldDef, 'shortDescription') || translator.tComponent(fieldDef, 'title');
214
215
  const messagesOverride = field.getValidationMessagesOverride(translator);
215
216
  let patchedSchema = field.formSchema;
216
217
  if (translatedLabel && translatedLabel !== field.label) {
@@ -1 +1 @@
1
- {"version":3,"file":"ComponentCollection.js","names":["joi","isFormState","isFormValue","createComponent","getErrors","buildLanguageMessages","validationOptions","opts","ComponentCollection","page","parent","components","fields","guidance","formSchema","stateSchema","constructor","defs","props","schema","map","def","filter","component","isFormComponent","object","required","field","collection","name","concat","keys","peers","and","isPresent","custom","flatMap","getFormDataFromState","state","payload","forEach","Object","assign","getFormValueFromState","value","entries","key","split","pop","getStateFromValidForm","getContextValueFromState","context","translator","errors","getFieldErrors","getViewErrors","getViewModel","result","type","model","overrideParentTitle","error","isErrorContext","local","title","missing","path","find","item","shift","child","label","length","tComponent","validate","messages","t","undefined","labelOverrides","messagesOverride","getValidationMessagesOverride","subField","translatedSubLabel","patchedSchema","translatedLabel","details","callback","list","fieldErrors","push"],"sources":["../../../../../src/server/plugins/engine/components/ComponentCollection.ts"],"sourcesContent":["import { type ComponentDef } from '@defra/forms-model'\nimport joi, {\n type CustomValidator,\n type ErrorReportCollection,\n type ObjectSchema\n} from 'joi'\n\nimport {\n isFormState,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport {\n createComponent,\n type Component,\n type Field,\n type Guidance\n} from '~/src/server/plugins/engine/components/helpers/components.js'\nimport {\n type ComponentViewModel,\n type RenderContext\n} from '~/src/server/plugins/engine/components/types.js'\nimport { getErrors } from '~/src/server/plugins/engine/helpers.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport { type FormModel } from '~/src/server/plugins/engine/models/index.js'\nimport { type PageControllerClass } from '~/src/server/plugins/engine/pageControllers/helpers/pages.js'\nimport {\n buildLanguageMessages,\n validationOptions as opts\n} from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type FormPayload,\n type FormState,\n type FormSubmissionError,\n type FormSubmissionState,\n type FormValidationResult\n} from '~/src/server/plugins/engine/types.js'\n\nexport class ComponentCollection {\n page?: PageControllerClass\n parent?: Component\n\n components: Component[]\n fields: Field[]\n guidance: Guidance[]\n\n formSchema: ObjectSchema<FormPayload>\n stateSchema: ObjectSchema<FormSubmissionState>\n\n constructor(\n defs: ComponentDef[],\n props: {\n page?: PageControllerClass\n parent?: Component\n model: FormModel\n },\n schema?: {\n /**\n * Defines an all-or-nothing relationship between keys where if one\n * of the peers is present, all of them are required as well\n */\n peers?: string[]\n\n /**\n * Defines a custom validation rule for the object schema\n */\n custom?: CustomValidator\n }\n ) {\n const components = defs.map((def) => createComponent(def, props))\n\n const fields = components.filter(\n (component): component is Field => component.isFormComponent\n )\n\n const guidance = components.filter(\n (component): component is Guidance => !component.isFormComponent\n )\n\n let formSchema = joi.object<FormPayload>().required()\n let stateSchema = joi.object<FormSubmissionState>().required()\n\n // Add each field or concat collection\n for (const field of fields) {\n const { collection, name } = field\n\n formSchema = collection\n ? formSchema.concat(collection.formSchema)\n : formSchema.keys({ [name]: field.formSchema })\n\n stateSchema = collection\n ? stateSchema.concat(collection.stateSchema)\n : stateSchema.keys({ [name]: field.stateSchema })\n }\n\n if (schema?.peers) {\n formSchema = formSchema.and(...schema.peers, {\n isPresent: isFormValue\n })\n }\n\n if (schema?.custom) {\n formSchema = formSchema.custom(schema.custom)\n }\n\n this.page = props.page\n this.parent = props.parent\n\n this.components = components\n this.fields = fields\n this.guidance = guidance\n\n this.formSchema = formSchema\n this.stateSchema = stateSchema\n }\n\n get keys() {\n return this.fields.flatMap((field) => {\n const { name, collection } = field\n\n if (collection) {\n const { fields } = collection\n return [name, ...fields.map(({ name }) => name)]\n }\n\n return [name]\n })\n }\n\n getFormDataFromState(state: FormSubmissionState) {\n const payload: FormPayload = {}\n\n this.fields.forEach((component) => {\n Object.assign(payload, component.getFormDataFromState(state))\n })\n\n return payload\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const payload: FormPayload = {}\n\n // Remove name prefix for formatted value\n for (const [name, value] of Object.entries(\n this.getFormDataFromState(state)\n )) {\n const key = name.split('__').pop()\n if (!key) {\n continue\n }\n\n payload[key] = value\n }\n\n return payload\n }\n\n getStateFromValidForm(payload: FormPayload) {\n const state: FormState = {}\n\n this.fields.forEach((component) => {\n Object.assign(state, component.getStateFromValidForm(payload))\n })\n\n return state\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const context: FormState = {}\n\n for (const component of this.fields) {\n context[component.name] = component.getContextValueFromState(state)\n }\n\n return context\n }\n\n /**\n * Get all errors for all fields in this collection\n */\n getErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n return this.getFieldErrors(\n (field) => field.getErrors(translator, errors),\n errors\n )\n }\n\n /**\n * Get view errors for all fields in this collection.\n * For most fields this means filtering to the first error in the list.\n * Composite fields like UKAddress can choose to return more than one error.\n */\n getViewErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n return this.getFieldErrors(\n (field) => field.getViewErrors(translator, errors),\n errors\n )\n }\n\n getViewModel(context: RenderContext) {\n const { components } = this\n\n const result: ComponentViewModel[] = components.map((component) => {\n const { isFormComponent, type } = component\n\n const model = component.getViewModel(context)\n\n return { type, isFormComponent, model }\n })\n\n return result\n }\n\n overrideParentTitle(\n formSchema: joi.ObjectSchema<FormPayload>,\n translator: Translator | undefined\n ) {\n // Add parent field title to collection field errors\n return formSchema.error((errors) => {\n return errors.flatMap((error) => {\n if (!isErrorContext(error.local) || error.local.title) {\n return error\n }\n\n // Use field key or first missing child field\n let { missing, key = missing?.[0] } = error.local\n\n // But avoid numeric key used by array payloads\n if (typeof key === 'number') {\n key = error.path[0]\n }\n\n // Find the parent field\n const parent = this.fields.find(\n (item) => item.name === key?.split('__').shift()\n )\n\n // Find the child field\n const child = (parent?.collection?.fields ?? this.fields).find(\n (item) => item.name === key\n )\n\n // Update error with child label\n if (child && (!error.local.label || error.local.label === 'value')) {\n error.local.label = child.title\n }\n\n // Fix error summary links for missing fields\n if (missing?.length) {\n error.path = missing\n error.local.key = missing[0]\n }\n\n // Update error with parent title\n if (translator && parent) {\n error.local.title ??= translator.tComponent(\n parent as ComponentDef,\n 'title'\n )\n } else {\n error.local.title ??= parent?.label\n }\n\n return error\n })\n })\n }\n\n /**\n * Validate form payload\n */\n validate(\n value: FormPayload = {},\n translator?: Translator\n ): FormValidationResult<FormPayload> {\n const messages = translator\n ? buildLanguageMessages(translator.t)\n : undefined\n\n // When translating, override Joi labels (and custom schema messages where\n // needed) so #label/#title in message templates resolve in the correct language.\n let schema = this.formSchema\n // Add parent field title to collection field errors\n schema = this.overrideParentTitle(schema, translator)\n\n if (translator) {\n const { t } = translator\n const labelOverrides: Record<string, joi.Schema> = {}\n\n for (const field of this.fields) {\n if (field.collection) {\n // Composite field: translate each sub-field's label using the key constant\n // (e.g. 'components.addressField.line1' → \"Llinell cyfeiriad 1\") and apply\n // any field-type-specific message overrides (e.g. objectMissing for dates).\n const messagesOverride =\n field.getValidationMessagesOverride(translator)\n for (const subField of field.collection.fields) {\n const translatedSubLabel = t(subField.title) || subField.label\n let patchedSchema = subField.formSchema.label(translatedSubLabel)\n if (messagesOverride) {\n patchedSchema = patchedSchema.messages(messagesOverride)\n }\n labelOverrides[subField.name] = patchedSchema\n }\n } else {\n const translatedLabel =\n translator.tComponent(\n field as unknown as ComponentDef,\n 'shortDescription'\n ) ||\n translator.tComponent(field as unknown as ComponentDef, 'title')\n const messagesOverride =\n field.getValidationMessagesOverride(translator)\n let patchedSchema = field.formSchema\n if (translatedLabel && translatedLabel !== field.label) {\n patchedSchema = patchedSchema.label(translatedLabel)\n }\n if (messagesOverride) {\n patchedSchema = patchedSchema.messages(messagesOverride)\n }\n if (patchedSchema !== field.formSchema) {\n labelOverrides[field.name] = patchedSchema\n }\n }\n }\n\n if (Object.keys(labelOverrides).length) {\n schema = schema.keys(labelOverrides)\n }\n }\n\n const result = schema.validate(value, {\n ...opts,\n ...(messages && { messages })\n })\n\n const details = result.error?.details\n\n return {\n value: (result.value ?? {}) as typeof value,\n errors: this.page?.getErrors(details) ?? getErrors(details)\n }\n }\n\n /**\n * Helper to get errors from all fields\n */\n private getFieldErrors(\n callback: (field: Field) => FormSubmissionError[] | undefined,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const { fields } = this\n\n if (!errors?.length) {\n return\n }\n\n const list: FormSubmissionError[] = []\n\n for (const field of fields) {\n const fieldErrors = callback(field)\n\n if (fieldErrors?.length) {\n list.push(...fieldErrors)\n }\n }\n\n if (!list.length) {\n return\n }\n\n return list\n }\n}\n\n/**\n * Check for field local state\n */\nexport function isErrorContext(\n value?: unknown\n): value is ErrorReportCollection['local'] {\n return isFormState(value) && typeof value.label === 'string'\n}\n"],"mappings":"AACA,OAAOA,GAAG,MAIH,KAAK;AAEZ,SACEC,WAAW,EACXC,WAAW;AAEb,SACEC,eAAe;AASjB,SAASC,SAAS;AAIlB,SACEC,qBAAqB,EACrBC,iBAAiB,IAAIC,IAAI;AAU3B,OAAO,MAAMC,mBAAmB,CAAC;EAC/BC,IAAI;EACJC,MAAM;EAENC,UAAU;EACVC,MAAM;EACNC,QAAQ;EAERC,UAAU;EACVC,WAAW;EAEXC,WAAWA,CACTC,IAAoB,EACpBC,KAIC,EACDC,MAWC,EACD;IACA,MAAMR,UAAU,GAAGM,IAAI,CAACG,GAAG,CAAEC,GAAG,IAAKlB,eAAe,CAACkB,GAAG,EAAEH,KAAK,CAAC,CAAC;IAEjE,MAAMN,MAAM,GAAGD,UAAU,CAACW,MAAM,CAC7BC,SAAS,IAAyBA,SAAS,CAACC,eAC/C,CAAC;IAED,MAAMX,QAAQ,GAAGF,UAAU,CAACW,MAAM,CAC/BC,SAAS,IAA4B,CAACA,SAAS,CAACC,eACnD,CAAC;IAED,IAAIV,UAAU,GAAGd,GAAG,CAACyB,MAAM,CAAc,CAAC,CAACC,QAAQ,CAAC,CAAC;IACrD,IAAIX,WAAW,GAAGf,GAAG,CAACyB,MAAM,CAAsB,CAAC,CAACC,QAAQ,CAAC,CAAC;;IAE9D;IACA,K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;MAC1B,MAAM4E,WAAW,GAAGF,QAAQ,CAAC3D,KAAK,CAAC;MAEnC,IAAI6D,WAAW,EAAEhB,MAAM,EAAE;QACvBe,IAAI,CAACE,IAAI,CAAC,GAAGD,WAAW,CAAC;MAC3B;IACF;IAEA,IAAI,CAACD,IAAI,CAACf,MAAM,EAAE;MAChB;IACF;IAEA,OAAOe,IAAI;EACb;AACF;;AAEA;AACA;AACA;AACA,OAAO,SAASzB,cAAcA,CAC5BlB,KAAe,EAC0B;EACzC,OAAO3C,WAAW,CAAC2C,KAAK,CAAC,IAAI,OAAOA,KAAK,CAAC2B,KAAK,KAAK,QAAQ;AAC9D","ignoreList":[]}
1
+ {"version":3,"file":"ComponentCollection.js","names":["joi","isFormState","isFormValue","createComponent","getErrors","buildLanguageMessages","validationOptions","opts","ComponentCollection","page","parent","components","fields","guidance","formSchema","stateSchema","constructor","defs","props","schema","map","def","filter","component","isFormComponent","object","required","field","collection","name","concat","keys","peers","and","isPresent","custom","flatMap","getFormDataFromState","state","payload","forEach","Object","assign","getFormValueFromState","value","entries","key","split","pop","getStateFromValidForm","getContextValueFromState","context","translator","errors","getFieldErrors","getViewErrors","getViewModel","result","type","model","overrideParentTitle","error","isErrorContext","local","title","missing","path","find","item","shift","child","label","length","tComponent","validate","messages","t","undefined","labelOverrides","messagesOverride","getValidationMessagesOverride","subField","translatedSubLabel","patchedSchema","fieldDef","translatedLabel","details","callback","list","fieldErrors","push"],"sources":["../../../../../src/server/plugins/engine/components/ComponentCollection.ts"],"sourcesContent":["import { type ComponentDef } from '@defra/forms-model'\nimport joi, {\n type CustomValidator,\n type ErrorReportCollection,\n type ObjectSchema\n} from 'joi'\n\nimport {\n isFormState,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport {\n createComponent,\n type Component,\n type Field,\n type Guidance\n} from '~/src/server/plugins/engine/components/helpers/components.js'\nimport {\n type ComponentViewModel,\n type RenderContext\n} from '~/src/server/plugins/engine/components/types.js'\nimport { getErrors } from '~/src/server/plugins/engine/helpers.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport { type FormModel } from '~/src/server/plugins/engine/models/index.js'\nimport { type PageControllerClass } from '~/src/server/plugins/engine/pageControllers/helpers/pages.js'\nimport {\n buildLanguageMessages,\n validationOptions as opts\n} from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type FormPayload,\n type FormState,\n type FormSubmissionError,\n type FormSubmissionState,\n type FormValidationResult\n} from '~/src/server/plugins/engine/types.js'\n\nexport class ComponentCollection {\n page?: PageControllerClass\n parent?: Component\n\n components: Component[]\n fields: Field[]\n guidance: Guidance[]\n\n formSchema: ObjectSchema<FormPayload>\n stateSchema: ObjectSchema<FormSubmissionState>\n\n constructor(\n defs: ComponentDef[],\n props: {\n page?: PageControllerClass\n parent?: Component\n model: FormModel\n },\n schema?: {\n /**\n * Defines an all-or-nothing relationship between keys where if one\n * of the peers is present, all of them are required as well\n */\n peers?: string[]\n\n /**\n * Defines a custom validation rule for the object schema\n */\n custom?: CustomValidator\n }\n ) {\n const components = defs.map((def) => createComponent(def, props))\n\n const fields = components.filter(\n (component): component is Field => component.isFormComponent\n )\n\n const guidance = components.filter(\n (component): component is Guidance => !component.isFormComponent\n )\n\n let formSchema = joi.object<FormPayload>().required()\n let stateSchema = joi.object<FormSubmissionState>().required()\n\n // Add each field or concat collection\n for (const field of fields) {\n const { collection, name } = field\n\n formSchema = collection\n ? formSchema.concat(collection.formSchema)\n : formSchema.keys({ [name]: field.formSchema })\n\n stateSchema = collection\n ? stateSchema.concat(collection.stateSchema)\n : stateSchema.keys({ [name]: field.stateSchema })\n }\n\n if (schema?.peers) {\n formSchema = formSchema.and(...schema.peers, {\n isPresent: isFormValue\n })\n }\n\n if (schema?.custom) {\n formSchema = formSchema.custom(schema.custom)\n }\n\n this.page = props.page\n this.parent = props.parent\n\n this.components = components\n this.fields = fields\n this.guidance = guidance\n\n this.formSchema = formSchema\n this.stateSchema = stateSchema\n }\n\n get keys() {\n return this.fields.flatMap((field) => {\n const { name, collection } = field\n\n if (collection) {\n const { fields } = collection\n return [name, ...fields.map(({ name }) => name)]\n }\n\n return [name]\n })\n }\n\n getFormDataFromState(state: FormSubmissionState) {\n const payload: FormPayload = {}\n\n this.fields.forEach((component) => {\n Object.assign(payload, component.getFormDataFromState(state))\n })\n\n return payload\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const payload: FormPayload = {}\n\n // Remove name prefix for formatted value\n for (const [name, value] of Object.entries(\n this.getFormDataFromState(state)\n )) {\n const key = name.split('__').pop()\n if (!key) {\n continue\n }\n\n payload[key] = value\n }\n\n return payload\n }\n\n getStateFromValidForm(payload: FormPayload) {\n const state: FormState = {}\n\n this.fields.forEach((component) => {\n Object.assign(state, component.getStateFromValidForm(payload))\n })\n\n return state\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const context: FormState = {}\n\n for (const component of this.fields) {\n context[component.name] = component.getContextValueFromState(state)\n }\n\n return context\n }\n\n /**\n * Get all errors for all fields in this collection\n */\n getErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n return this.getFieldErrors(\n (field) => field.getErrors(translator, errors),\n errors\n )\n }\n\n /**\n * Get view errors for all fields in this collection.\n * For most fields this means filtering to the first error in the list.\n * Composite fields like UKAddress can choose to return more than one error.\n */\n getViewErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n return this.getFieldErrors(\n (field) => field.getViewErrors(translator, errors),\n errors\n )\n }\n\n getViewModel(context: RenderContext) {\n const { components } = this\n\n const result: ComponentViewModel[] = components.map((component) => {\n const { isFormComponent, type } = component\n\n const model = component.getViewModel(context)\n\n return { type, isFormComponent, model }\n })\n\n return result\n }\n\n overrideParentTitle(\n formSchema: joi.ObjectSchema<FormPayload>,\n translator: Translator | undefined\n ) {\n // Add parent field title to collection field errors\n return formSchema.error((errors) => {\n return errors.flatMap((error) => {\n if (!isErrorContext(error.local) || error.local.title) {\n return error\n }\n\n // Use field key or first missing child field\n let { missing, key = missing?.[0] } = error.local\n\n // But avoid numeric key used by array payloads\n if (typeof key === 'number') {\n key = error.path[0]\n }\n\n // Find the parent field\n const parent = this.fields.find(\n (item) => item.name === key?.split('__').shift()\n )\n\n // Find the child field\n const child = (parent?.collection?.fields ?? this.fields).find(\n (item) => item.name === key\n )\n\n // Update error with child label\n if (child && (!error.local.label || error.local.label === 'value')) {\n error.local.label = child.title\n }\n\n // Fix error summary links for missing fields\n if (missing?.length) {\n error.path = missing\n error.local.key = missing[0]\n }\n\n // Update error with parent title\n if (translator && parent) {\n error.local.title ??= translator.tComponent(\n parent as ComponentDef,\n 'title'\n )\n } else {\n error.local.title ??= parent?.label\n }\n\n return error\n })\n })\n }\n\n /**\n * Validate form payload\n */\n validate(\n value: FormPayload = {},\n translator?: Translator\n ): FormValidationResult<FormPayload> {\n const messages = translator\n ? buildLanguageMessages(translator.t)\n : undefined\n\n // When translating, override Joi labels (and custom schema messages where\n // needed) so #label/#title in message templates resolve in the correct language.\n let schema = this.formSchema\n // Add parent field title to collection field errors\n schema = this.overrideParentTitle(schema, translator)\n\n if (translator) {\n const { t } = translator\n const labelOverrides: Record<string, joi.Schema> = {}\n\n for (const field of this.fields) {\n if (field.collection) {\n // Composite field: translate each sub-field's label using the key constant\n // (e.g. 'components.addressField.line1' → \"Llinell cyfeiriad 1\") and apply\n // any field-type-specific message overrides (e.g. objectMissing for dates).\n const messagesOverride =\n field.getValidationMessagesOverride(translator)\n for (const subField of field.collection.fields) {\n const translatedSubLabel = t(subField.title) || subField.label\n let patchedSchema = subField.formSchema.label(translatedSubLabel)\n if (messagesOverride) {\n patchedSchema = patchedSchema.messages(messagesOverride)\n }\n labelOverrides[subField.name] = patchedSchema\n }\n } else {\n const fieldDef = field.def\n const translatedLabel =\n translator.tComponent(fieldDef, 'errorDescription') ||\n translator.tComponent(fieldDef, 'shortDescription') ||\n translator.tComponent(fieldDef, 'title')\n const messagesOverride =\n field.getValidationMessagesOverride(translator)\n let patchedSchema = field.formSchema\n if (translatedLabel && translatedLabel !== field.label) {\n patchedSchema = patchedSchema.label(translatedLabel)\n }\n if (messagesOverride) {\n patchedSchema = patchedSchema.messages(messagesOverride)\n }\n if (patchedSchema !== field.formSchema) {\n labelOverrides[field.name] = patchedSchema\n }\n }\n }\n\n if (Object.keys(labelOverrides).length) {\n schema = schema.keys(labelOverrides)\n }\n }\n\n const result = schema.validate(value, {\n ...opts,\n ...(messages && { messages })\n })\n\n const details = result.error?.details\n\n return {\n value: (result.value ?? {}) as typeof value,\n errors: this.page?.getErrors(details) ?? getErrors(details)\n }\n }\n\n /**\n * Helper to get errors from all fields\n */\n private getFieldErrors(\n callback: (field: Field) => FormSubmissionError[] | undefined,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const { fields } = this\n\n if (!errors?.length) {\n return\n }\n\n const list: FormSubmissionError[] = []\n\n for (const field of fields) {\n const fieldErrors = callback(field)\n\n if (fieldErrors?.length) {\n list.push(...fieldErrors)\n }\n }\n\n if (!list.length) {\n return\n }\n\n return list\n }\n}\n\n/**\n * Check for field local state\n */\nexport function isErrorContext(\n value?: unknown\n): value is ErrorReportCollection['local'] {\n return isFormState(value) && typeof value.label === 'string'\n}\n"],"mappings":"AACA,OAAOA,GAAG,MAIH,KAAK;AAEZ,SACEC,WAAW,EACXC,WAAW;AAEb,SACEC,eAAe;AASjB,SAASC,SAAS;AAIlB,SACEC,qBAAqB,EACrBC,iBAAiB,IAAIC,IAAI;AAU3B,OAAO,MAAMC,mBAAmB,CAAC;EAC/BC,IAAI;EACJC,MAAM;EAENC,UAAU;EACVC,MAAM;EACNC,QAAQ;EAERC,UAAU;EACVC,WAAW;EAEXC,WAAWA,CACTC,IAAoB,EACpBC,KAIC,EACDC,MAWC,EACD;IACA,MAAMR,UAAU,GAAGM,IAAI,CAACG,GAAG,CAAEC,GAAG,IAAKlB,eAAe,CAACkB,GAAG,EAAEH,KAAK,CAAC,CAAC;I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,GAAG7B,MAAM,CAACI,KAAK,EAAEyB,OAAO;IAErC,OAAO;MACL1C,KAAK,EAAGa,MAAM,CAACb,KAAK,IAAI,CAAC,CAAkB;MAC3CS,MAAM,EAAE,IAAI,CAAC5C,IAAI,EAAEL,SAAS,CAACkF,OAAO,CAAC,IAAIlF,SAAS,CAACkF,OAAO;IAC5D,CAAC;EACH;;EAEA;AACF;AACA;EACUhC,cAAcA,CACpBiC,QAA6D,EAC7DlC,MAA8B,EACK;IACnC,MAAM;MAAEzC;IAAO,CAAC,GAAG,IAAI;IAEvB,IAAI,CAACyC,MAAM,EAAEmB,MAAM,EAAE;MACnB;IACF;IAEA,MAAMgB,IAA2B,GAAG,EAAE;IAEtC,KAAK,MAAM7D,KAAK,IAAIf,MAAM,EAAE;MAC1B,MAAM6E,WAAW,GAAGF,QAAQ,CAAC5D,KAAK,CAAC;MAEnC,IAAI8D,WAAW,EAAEjB,MAAM,EAAE;QACvBgB,IAAI,CAACE,IAAI,CAAC,GAAGD,WAAW,CAAC;MAC3B;IACF;IAEA,IAAI,CAACD,IAAI,CAAChB,MAAM,EAAE;MAChB;IACF;IAEA,OAAOgB,IAAI;EACb;AACF;;AAEA;AACA;AACA;AACA,OAAO,SAAS1B,cAAcA,CAC5BlB,KAAe,EAC0B;EACzC,OAAO3C,WAAW,CAAC2C,KAAK,CAAC,IAAI,OAAOA,KAAK,CAAC2B,KAAK,KAAK,QAAQ;AAC9D","ignoreList":[]}
@@ -93,7 +93,7 @@ export class DeclarationField extends FormComponent {
93
93
  hint,
94
94
  declarationConfirmationLabel = t('components.declarationField.defaultLabel')
95
95
  } = this;
96
- const content = tComponent(this, 'content');
96
+ const content = tComponent(this.def, 'content');
97
97
  const viewModel = super.getViewModel(context);
98
98
  let {
99
99
  fieldset,
@@ -1 +1 @@
1
- {"version":3,"file":"DeclarationField.js","names":["ComponentType","hasFormComponents","isFormType","joi","FormComponent","isFormValue","buildValidationMessages","messageTemplate","DeclarationField","headerStartLevel","constructor","def","props","options","content","checkboxSchema","string","valid","required","formSchema","array","items","strip","label","single","messages","declarationRequired","stateSchema","boolean","cast","declarationConfirmationLabel","formComponents","page","pageDef","components","numOfQuestionsOnPage","filter","q","type","length","hasGuidance","some","comp","idx","Markdown","getFormValueFromState","state","name","getFormDataFromState","getStateFromValidForm","payload","payloadValue","value","isValue","every","v","getContextValueFromFormValue","getFormValue","undefined","getValidationMessagesOverride","translator","t","msg","getDisplayStringFromFormValue","getViewModel","context","tComponent","hint","viewModel","fieldset","legend","text","classes","isChecked","Array","isArray","x","checked","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","isBool"],"sources":["../../../../../src/server/plugins/engine/components/DeclarationField.ts"],"sourcesContent":["import {\n ComponentType,\n hasFormComponents,\n isFormType,\n type ComponentDef,\n type DeclarationFieldComponent,\n type Item\n} from '@defra/forms-model'\nimport joi, {\n type ArraySchema,\n type BooleanSchema,\n type LanguageMessages,\n type StringSchema\n} from 'joi'\n\nimport {\n FormComponent,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { type RenderContext } from '~/src/server/plugins/engine/components/types.js'\nimport { buildValidationMessages } from '~/src/server/plugins/engine/i18n/buildValidationMessages.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionState,\n type FormValue\n} from '~/src/server/plugins/engine/types.js'\n\nexport class DeclarationField extends FormComponent {\n declare options: DeclarationFieldComponent['options']\n\n declare declarationConfirmationLabel: string | undefined\n\n declare formSchema: ArraySchema<StringSchema[]>\n declare stateSchema: BooleanSchema\n declare content: string\n headerStartLevel: number\n\n constructor(\n def: DeclarationFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options, content } = def\n\n let checkboxSchema = joi.string().valid('true')\n\n if (options.required !== false) {\n checkboxSchema = checkboxSchema.required()\n }\n\n const formSchema = joi\n .array()\n .items(checkboxSchema, joi.string().valid('unchecked').strip())\n .label(this.label)\n .single()\n .messages({\n 'any.required': messageTemplate.declarationRequired as string,\n 'any.unknown': messageTemplate.declarationRequired as string,\n 'array.includesRequiredUnknowns':\n messageTemplate.declarationRequired as string\n }) as ArraySchema<StringSchema[]>\n\n this.formSchema = formSchema\n this.stateSchema = joi.boolean().cast('string').label(this.label).required()\n\n this.options = options\n this.content = content\n // Store only the form-authored label (if provided). If absent, getViewModel\n // resolves the default via t() at render time so the correct language is used.\n this.declarationConfirmationLabel = options.declarationConfirmationLabel\n const formComponents = hasFormComponents(props.page?.pageDef)\n ? props.page.pageDef.components\n : []\n const numOfQuestionsOnPage = formComponents.filter((q) =>\n isFormType(q.type)\n ).length\n const hasGuidance = formComponents.some(\n (comp, idx) => comp.type === ComponentType.Markdown && idx === 0\n )\n this.headerStartLevel = numOfQuestionsOnPage < 2 && !hasGuidance ? 2 : 3\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return state[name] === true ? 'true' : 'false'\n }\n\n getFormDataFromState(state: FormSubmissionState): FormPayload {\n const { name } = this\n return { [name]: state[name] === true ? 'true' : 'false' }\n }\n\n getStateFromValidForm(payload: FormPayload): FormState {\n const { name } = this\n const payloadValue = payload[name]\n const value =\n this.isValue(payloadValue) &&\n payloadValue.length > 0 &&\n payloadValue.every((v) => {\n return v === 'true'\n })\n\n return { [name]: value }\n }\n\n getContextValueFromFormValue(value: FormValue | FormPayload): boolean {\n return value === 'true'\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getValidationMessagesOverride(translator: Translator) {\n const { declarationRequired } = buildValidationMessages(translator.t)\n const msg = declarationRequired as unknown as string\n return {\n 'any.required': msg,\n 'any.unknown': msg,\n 'array.includesRequiredUnknowns': msg\n } as unknown as LanguageMessages\n }\n\n getDisplayStringFromFormValue(\n value: FormValue | FormPayload,\n translator: Translator\n ): string {\n const { t } = translator\n return value === 'true'\n ? (this.declarationConfirmationLabel ??\n t('components.declarationField.defaultLabel'))\n : t('components.declarationField.notProvided')\n }\n\n getViewModel(context: RenderContext) {\n const { payload } = context\n const { t, tComponent } = context.translator\n\n const {\n hint,\n declarationConfirmationLabel = t(\n 'components.declarationField.defaultLabel'\n )\n } = this\n const content = tComponent(this as unknown as ComponentDef, 'content')\n\n const viewModel = super.getViewModel(context)\n let { fieldset, label } = viewModel\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n const payloadValue = payload[this.name]\n const isChecked =\n payloadValue === 'true' ||\n payloadValue === true ||\n (Array.isArray(payloadValue) && payloadValue.some((x) => x === 'true'))\n\n return {\n ...viewModel,\n hint: hint ? { text: hint } : undefined,\n fieldset,\n content,\n items: [\n {\n text: declarationConfirmationLabel,\n value: 'true',\n checked: isChecked\n }\n ],\n headerStartLevel: this.headerStartLevel\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 /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return DeclarationField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.declarationRequired }\n ],\n advancedSettingsErrors: []\n }\n }\n\n static isBool(value?: FormStateValue | FormState): value is boolean {\n return isFormValue(value) && typeof value === 'boolean'\n }\n}\n"],"mappings":"AAAA,SACEA,aAAa,EACbC,iBAAiB,EACjBC,UAAU,QAIL,oBAAoB;AAC3B,OAAOC,GAAG,MAKH,KAAK;AAEZ,SACEC,aAAa,EACbC,WAAW;AAGb,SAASC,uBAAuB;AAEhC,SAASC,eAAe;AAUxB,OA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"file":"DeclarationField.js","names":["ComponentType","hasFormComponents","isFormType","joi","FormComponent","isFormValue","buildValidationMessages","messageTemplate","DeclarationField","headerStartLevel","constructor","def","props","options","content","checkboxSchema","string","valid","required","formSchema","array","items","strip","label","single","messages","declarationRequired","stateSchema","boolean","cast","declarationConfirmationLabel","formComponents","page","pageDef","components","numOfQuestionsOnPage","filter","q","type","length","hasGuidance","some","comp","idx","Markdown","getFormValueFromState","state","name","getFormDataFromState","getStateFromValidForm","payload","payloadValue","value","isValue","every","v","getContextValueFromFormValue","getFormValue","undefined","getValidationMessagesOverride","translator","t","msg","getDisplayStringFromFormValue","getViewModel","context","tComponent","hint","viewModel","fieldset","legend","text","classes","isChecked","Array","isArray","x","checked","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","isBool"],"sources":["../../../../../src/server/plugins/engine/components/DeclarationField.ts"],"sourcesContent":["import {\n ComponentType,\n hasFormComponents,\n isFormType,\n type DeclarationFieldComponent,\n type Item\n} from '@defra/forms-model'\nimport joi, {\n type ArraySchema,\n type BooleanSchema,\n type LanguageMessages,\n type StringSchema\n} from 'joi'\n\nimport {\n FormComponent,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { type RenderContext } from '~/src/server/plugins/engine/components/types.js'\nimport { buildValidationMessages } from '~/src/server/plugins/engine/i18n/buildValidationMessages.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionState,\n type FormValue\n} from '~/src/server/plugins/engine/types.js'\n\nexport class DeclarationField extends FormComponent {\n declare options: DeclarationFieldComponent['options']\n\n declare declarationConfirmationLabel: string | undefined\n\n declare formSchema: ArraySchema<StringSchema[]>\n declare stateSchema: BooleanSchema\n declare content: string\n headerStartLevel: number\n\n constructor(\n def: DeclarationFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options, content } = def\n\n let checkboxSchema = joi.string().valid('true')\n\n if (options.required !== false) {\n checkboxSchema = checkboxSchema.required()\n }\n\n const formSchema = joi\n .array()\n .items(checkboxSchema, joi.string().valid('unchecked').strip())\n .label(this.label)\n .single()\n .messages({\n 'any.required': messageTemplate.declarationRequired as string,\n 'any.unknown': messageTemplate.declarationRequired as string,\n 'array.includesRequiredUnknowns':\n messageTemplate.declarationRequired as string\n }) as ArraySchema<StringSchema[]>\n\n this.formSchema = formSchema\n this.stateSchema = joi.boolean().cast('string').label(this.label).required()\n\n this.options = options\n this.content = content\n // Store only the form-authored label (if provided). If absent, getViewModel\n // resolves the default via t() at render time so the correct language is used.\n this.declarationConfirmationLabel = options.declarationConfirmationLabel\n const formComponents = hasFormComponents(props.page?.pageDef)\n ? props.page.pageDef.components\n : []\n const numOfQuestionsOnPage = formComponents.filter((q) =>\n isFormType(q.type)\n ).length\n const hasGuidance = formComponents.some(\n (comp, idx) => comp.type === ComponentType.Markdown && idx === 0\n )\n this.headerStartLevel = numOfQuestionsOnPage < 2 && !hasGuidance ? 2 : 3\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return state[name] === true ? 'true' : 'false'\n }\n\n getFormDataFromState(state: FormSubmissionState): FormPayload {\n const { name } = this\n return { [name]: state[name] === true ? 'true' : 'false' }\n }\n\n getStateFromValidForm(payload: FormPayload): FormState {\n const { name } = this\n const payloadValue = payload[name]\n const value =\n this.isValue(payloadValue) &&\n payloadValue.length > 0 &&\n payloadValue.every((v) => {\n return v === 'true'\n })\n\n return { [name]: value }\n }\n\n getContextValueFromFormValue(value: FormValue | FormPayload): boolean {\n return value === 'true'\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getValidationMessagesOverride(translator: Translator) {\n const { declarationRequired } = buildValidationMessages(translator.t)\n const msg = declarationRequired as unknown as string\n return {\n 'any.required': msg,\n 'any.unknown': msg,\n 'array.includesRequiredUnknowns': msg\n } as unknown as LanguageMessages\n }\n\n getDisplayStringFromFormValue(\n value: FormValue | FormPayload,\n translator: Translator\n ): string {\n const { t } = translator\n return value === 'true'\n ? (this.declarationConfirmationLabel ??\n t('components.declarationField.defaultLabel'))\n : t('components.declarationField.notProvided')\n }\n\n getViewModel(context: RenderContext) {\n const { payload } = context\n const { t, tComponent } = context.translator\n\n const {\n hint,\n declarationConfirmationLabel = t(\n 'components.declarationField.defaultLabel'\n )\n } = this\n const content = tComponent(this.def, 'content')\n\n const viewModel = super.getViewModel(context)\n let { fieldset, label } = viewModel\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n const payloadValue = payload[this.name]\n const isChecked =\n payloadValue === 'true' ||\n payloadValue === true ||\n (Array.isArray(payloadValue) && payloadValue.some((x) => x === 'true'))\n\n return {\n ...viewModel,\n hint: hint ? { text: hint } : undefined,\n fieldset,\n content,\n items: [\n {\n text: declarationConfirmationLabel,\n value: 'true',\n checked: isChecked\n }\n ],\n headerStartLevel: this.headerStartLevel\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 /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return DeclarationField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.declarationRequired }\n ],\n advancedSettingsErrors: []\n }\n }\n\n static isBool(value?: FormStateValue | FormState): value is boolean {\n return isFormValue(value) && typeof value === 'boolean'\n }\n}\n"],"mappings":"AAAA,SACEA,aAAa,EACbC,iBAAiB,EACjBC,UAAU,QAGL,oBAAoB;AAC3B,OAAOC,GAAG,MAKH,KAAK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/C,WAAW,CAAC+C,KAAK,CAAC,IAAI,OAAOA,KAAK,KAAK,SAAS;EACzD;AACF","ignoreList":[]}
@@ -128,12 +128,12 @@ export class FormComponent extends ComponentBase {
128
128
  } = translator;
129
129
  const isRequired = !('required' in options) || options.required !== false;
130
130
  const hideOptional = 'optionalText' in options && options.optionalText;
131
- const resolvedTitle = tComponent(this, 'title') || title;
131
+ const resolvedTitle = tComponent(this.def, 'title') || title;
132
132
  const optionalTag = !isRequired && !hideOptional ? ` ${t('common.optional')}` : '';
133
133
  const label = `${resolvedTitle}${optionalTag}`;
134
134
  if (hint) {
135
135
  viewModel.hint = {
136
- text: tComponent(this, 'hint') || hint
136
+ text: tComponent(this.def, 'hint') || hint
137
137
  };
138
138
  }
139
139
 
@@ -1 +1 @@
1
- {"version":3,"file":"FormComponent.js","names":["ComponentBase","FormComponent","type","hint","label","summaryLabel","isFormComponent","isAppendageStateSingleObject","constructor","def","props","getLabel","getSummaryLabel","errorDescription","shortDescription","title","keys","collection","name","fields","map","getFormDataFromState","state","getFormValue","getFormValueFromState","value","isValue","undefined","getStateFromValidForm","payload","getErrors","_translator","errors","list","filter","error","path","includes","length","getFirstError","translator","getViewErrors","firstError","getValidationMessagesOverride","getViewModel","isForceAccess","_isForceAccess","options","viewModel","t","tComponent","isRequired","required","hideOptional","optionalText","resolvedTitle","optionalTag","text","componentErrors","componentError","errorMessage","id","getDisplayStringFromFormValue","toString","getDisplayStringFromState","getContextValueFromFormValue","isState","values","Object","isFormValue","Array","isArray","getContextValueFromState","isFormState","getAllPossibleErrors","baseErrors","advancedSettingsErrors","onSubmit","_request","_metadata","_context","Promise","resolve","isRepeatState","every","isRepeatValue","itemId","isUploadState","isUploadValue","isGeospatialState","isGeospatialValue","uploadId"],"sources":["../../../../../src/server/plugins/engine/components/FormComponent.ts"],"sourcesContent":["import {\n type ComponentDef,\n type FormComponentsDef,\n type FormMetadata,\n type Item\n} from '@defra/forms-model'\nimport { type LanguageMessages } from 'joi'\n\nimport { ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\nimport { type RenderContext } from '~/src/server/plugins/engine/components/types.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport {\n type FormContext,\n type FormRequestPayload\n} from '~/src/server/plugins/engine/types/index.js'\nimport {\n type ErrorMessageTemplateList,\n type Feature,\n type FileState,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState,\n type FormValue,\n type GeospatialState,\n type RepeatItemState,\n type RepeatListState,\n type UploadState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class FormComponent extends ComponentBase {\n type: FormComponentsDef['type']\n hint: FormComponentsDef['hint']\n label: string\n summaryLabel: string\n\n isFormComponent = true\n isAppendageStateSingleObject = false\n\n constructor(\n def: FormComponentsDef,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { hint, type } = def\n\n this.type = type\n this.hint = hint\n\n this.label = this.getLabel(def)\n this.summaryLabel = this.getSummaryLabel(def)\n }\n\n getLabel(def: FormComponentsDef) {\n if ('errorDescription' in def && def.errorDescription) {\n return def.errorDescription\n }\n\n return this.getSummaryLabel(def)\n }\n\n getSummaryLabel(def: FormComponentsDef) {\n if ('shortDescription' in def && def.shortDescription) {\n return def.shortDescription\n }\n\n return def.title\n }\n\n get keys() {\n const { collection, name } = this\n\n if (collection) {\n const { fields } = collection\n return [name, ...fields.map(({ name }) => name)]\n }\n\n return [name]\n }\n\n getFormDataFromState(state: FormSubmissionState): FormPayload {\n const { collection, name } = this\n\n if (collection) {\n return collection.getFormDataFromState(state)\n }\n\n return {\n [name]: this.getFormValue(state[name])\n }\n }\n\n getFormValueFromState(state: FormSubmissionState): FormValue | FormPayload {\n const { collection, name } = this\n\n if (collection) {\n return collection.getFormValueFromState(state)\n }\n\n return this.getFormValue(state[name])\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getStateFromValidForm(payload: FormPayload): FormState {\n const { collection, name } = this\n\n if (collection) {\n return collection.getStateFromValidForm(payload)\n }\n\n return {\n [name]: this.getFormValue(payload[name]) ?? null\n }\n }\n\n getErrors(\n _translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const { name } = this\n\n // Filter component and child errors only\n const list = errors?.filter(\n (error) =>\n error.name === name ||\n error.path.includes(name) ||\n this.keys.includes(error.name)\n )\n\n if (!list?.length) {\n return\n }\n\n return list\n }\n\n getFirstError(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError | undefined {\n return this.getErrors(translator, errors)?.[0]\n }\n\n getViewErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const firstError = this.getFirstError(translator, errors)\n return firstError && [firstError]\n }\n\n /**\n * Override in composite fields to return translated Joi message overrides for\n * their sub-fields, applied at validation time so schema-level English messages\n * are replaced with the correct language. Return null to skip message patching.\n */\n getValidationMessagesOverride(\n _translator: Translator\n ): LanguageMessages | null {\n return null\n }\n\n getViewModel({\n payload,\n errors,\n translator,\n isForceAccess: _isForceAccess = false\n }: RenderContext) {\n const { hint, name, options = {}, title, viewModel } = this\n\n const { t, tComponent } = translator\n\n const isRequired = !('required' in options) || options.required !== false\n const hideOptional = 'optionalText' in options && options.optionalText\n\n const resolvedTitle =\n tComponent(this as unknown as ComponentDef, 'title') || title\n const optionalTag =\n !isRequired && !hideOptional ? ` ${t('common.optional')}` : ''\n const label = `${resolvedTitle}${optionalTag}`\n\n if (hint) {\n viewModel.hint = {\n text: tComponent(this as unknown as ComponentDef, 'hint') || hint\n }\n }\n\n // Filter component errors only\n const componentErrors = this.getErrors(translator, errors)\n const componentError = this.getFirstError(translator, componentErrors)\n\n if (componentErrors) {\n viewModel.errors = componentErrors\n }\n\n if (componentError) {\n viewModel.errorMessage = {\n text: componentError.text\n }\n }\n\n return {\n ...viewModel,\n label: {\n text: label\n },\n id: name,\n name,\n value: payload[name]\n }\n }\n\n getDisplayStringFromFormValue(\n value: FormValue | FormPayload,\n _translator: Translator\n ): string {\n // Map selected values to text\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n return this.isValue(value) ? value.toString() : ''\n }\n\n getDisplayStringFromState(\n state: FormSubmissionState,\n translator: Translator\n ): string {\n const value = this.getFormValueFromState(state)\n return this.getDisplayStringFromFormValue(value, translator)\n }\n\n getContextValueFromFormValue(\n value: FormValue | FormPayload\n ): Item['value'] | Item['value'][] | null {\n // Filter object field values\n if (this.isState(value)) {\n const values = Object.values(value).filter(isFormValue)\n return values.length ? values : null\n }\n\n // Filter array field values\n if (this.isValue(value) && Array.isArray(value)) {\n return value.filter(isFormValue)\n }\n\n return this.isValue(value) ? value : null\n }\n\n getContextValueFromState(\n state: FormSubmissionState\n ): Item['value'] | Item['value'][] | null {\n const value = this.getFormValueFromState(state)\n\n return this.getContextValueFromFormValue(value)\n }\n\n isValue(\n value?: FormStateValue | FormState\n ): value is NonNullable<FormStateValue> {\n return isFormValue(value)\n }\n\n isState(value?: FormStateValue | FormState): value is FormState {\n return isFormState(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return FormComponent.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [],\n advancedSettingsErrors: []\n }\n }\n\n onSubmit(\n _request: FormRequestPayload,\n _metadata: FormMetadata,\n _context: FormContext\n ): Promise<void> {\n return Promise.resolve()\n }\n}\n\n/**\n * Check for form value\n */\nexport function isFormValue(\n value?: unknown\n): value is string | number | boolean {\n return (\n (typeof value === 'string' && value.length > 0) ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n )\n}\n\n/**\n * Check for form state with nested values\n */\nexport function isFormState(value?: unknown): value is FormState {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return false\n }\n\n // Skip empty objects\n return !!Object.values(value).length\n}\n\n/**\n * Check for repeat list state\n */\nexport function isRepeatState(value?: unknown): value is RepeatListState {\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(isRepeatValue)\n}\n\n/**\n * Check for repeat list value\n */\nexport function isRepeatValue(value?: unknown): value is RepeatItemState {\n return isFormState(value) && typeof value.itemId === 'string'\n}\n\n/**\n * Check for upload state\n */\nexport function isUploadState(value?: unknown): value is UploadState {\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(isUploadValue)\n}\n\n/**\n * Check for geospatial state\n */\nexport function isGeospatialState(value?: unknown): value is GeospatialState {\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(isGeospatialValue)\n}\n\n/**\n * Check for upload state value\n */\nexport function isUploadValue(value?: unknown): value is FileState {\n return isFormState(value) && typeof value.uploadId === 'string'\n}\n\n/**\n * Check for geospatial state value\n */\nexport function isGeospatialValue(value?: unknown): value is Feature {\n return (\n isFormState(value) &&\n typeof value.type === 'string' &&\n value.type === 'Feature'\n )\n}\n"],"mappings":"AAQA,SAASA,aAAa;AAuBtB,OAAO,MAAMC,aAAa,SAASD,aAAa,CAAC;EAC/CE,IAAI;EACJC,IAAI;EACJC,KAAK;EACLC,YAAY;EAEZC,eAAe,GAAG,IAAI;EACtBC,4BAA4B,GAAG,KAAK;EAEpCC,WAAWA,CACTC,GAAsB,EACtBC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEP,IAAI;MAAED;IAAK,CAAC,GAAGO,GAAG;IAE1B,IAAI,CAACP,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,IAAI,GAAGA,IAAI;IAEhB,IAAI,CAACC,KAAK,GAAG,IAAI,CAACO,QAAQ,CAACF,GAAG,CAAC;IAC/B,IAAI,CAACJ,YAAY,GAAG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AAEA;AACA;AACA;AACA,OAAO,SAASA,aAAaA,CAAC5D,KAAe,EAA4B;EACvE,OAAOgD,WAAW,CAAChD,KAAK,CAAC,IAAI,OAAOA,KAAK,CAAC6D,MAAM,KAAK,QAAQ;AAC/D;;AAEA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAAC9D,KAAe,EAAwB;EACnE,IAAI,CAAC6C,KAAK,CAACC,OAAO,CAAC9C,KAAK,CAAC,EAAE;IACzB,OAAO,KAAK;EACd;;EAEA;EACA,IAAI,CAACA,KAAK,CAACa,MAAM,EAAE;IACjB,OAAO,IAAI;EACb;EAEA,OAAOb,KAAK,CAAC2D,KAAK,CAACI,aAAa,CAAC;AACnC;;AAEA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAAChE,KAAe,EAA4B;EAC3E,IAAI,CAAC6C,KAAK,CAACC,OAAO,CAAC9C,KAAK,CAAC,EAAE;IACzB,OAAO,KAAK;EACd;;EAEA;EACA,IAAI,CAACA,KAAK,CAACa,MAAM,EAAE;IACjB,OAAO,IAAI;EACb;EAEA,OAAOb,KAAK,CAAC2D,KAAK,CAACM,iBAAiB,CAAC;AACvC;;AAEA;AACA;AACA;AACA,OAAO,SAASF,aAAaA,CAAC/D,KAAe,EAAsB;EACjE,OAAOgD,WAAW,CAAChD,KAAK,CAAC,IAAI,OAAOA,KAAK,CAACkE,QAAQ,KAAK,QAAQ;AACjE;;AAEA;AACA;AACA;AACA,OAAO,SAASD,iBAAiBA,CAACjE,KAAe,EAAoB;EACnE,OACEgD,WAAW,CAAChD,KAAK,CAAC,IAClB,OAAOA,KAAK,CAACvB,IAAI,KAAK,QAAQ,IAC9BuB,KAAK,CAACvB,IAAI,KAAK,SAAS;AAE5B","ignoreList":[]}
1
+ {"version":3,"file":"FormComponent.js","names":["ComponentBase","FormComponent","type","hint","label","summaryLabel","isFormComponent","isAppendageStateSingleObject","constructor","def","props","getLabel","getSummaryLabel","errorDescription","shortDescription","title","keys","collection","name","fields","map","getFormDataFromState","state","getFormValue","getFormValueFromState","value","isValue","undefined","getStateFromValidForm","payload","getErrors","_translator","errors","list","filter","error","path","includes","length","getFirstError","translator","getViewErrors","firstError","getValidationMessagesOverride","getViewModel","isForceAccess","_isForceAccess","options","viewModel","t","tComponent","isRequired","required","hideOptional","optionalText","resolvedTitle","optionalTag","text","componentErrors","componentError","errorMessage","id","getDisplayStringFromFormValue","toString","getDisplayStringFromState","getContextValueFromFormValue","isState","values","Object","isFormValue","Array","isArray","getContextValueFromState","isFormState","getAllPossibleErrors","baseErrors","advancedSettingsErrors","onSubmit","_request","_metadata","_context","Promise","resolve","isRepeatState","every","isRepeatValue","itemId","isUploadState","isUploadValue","isGeospatialState","isGeospatialValue","uploadId"],"sources":["../../../../../src/server/plugins/engine/components/FormComponent.ts"],"sourcesContent":["import {\n type FormComponentsDef,\n type FormMetadata,\n type Item\n} from '@defra/forms-model'\nimport { type LanguageMessages } from 'joi'\n\nimport { ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\nimport { type RenderContext } from '~/src/server/plugins/engine/components/types.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport {\n type FormContext,\n type FormRequestPayload\n} from '~/src/server/plugins/engine/types/index.js'\nimport {\n type ErrorMessageTemplateList,\n type Feature,\n type FileState,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState,\n type FormValue,\n type GeospatialState,\n type RepeatItemState,\n type RepeatListState,\n type UploadState\n} from '~/src/server/plugins/engine/types.js'\n\nexport class FormComponent extends ComponentBase {\n type: FormComponentsDef['type']\n hint: FormComponentsDef['hint']\n label: string\n summaryLabel: string\n\n isFormComponent = true\n isAppendageStateSingleObject = false\n\n constructor(\n def: FormComponentsDef,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { hint, type } = def\n\n this.type = type\n this.hint = hint\n\n this.label = this.getLabel(def)\n this.summaryLabel = this.getSummaryLabel(def)\n }\n\n getLabel(def: FormComponentsDef) {\n if ('errorDescription' in def && def.errorDescription) {\n return def.errorDescription\n }\n\n return this.getSummaryLabel(def)\n }\n\n getSummaryLabel(def: FormComponentsDef) {\n if ('shortDescription' in def && def.shortDescription) {\n return def.shortDescription\n }\n\n return def.title\n }\n\n get keys() {\n const { collection, name } = this\n\n if (collection) {\n const { fields } = collection\n return [name, ...fields.map(({ name }) => name)]\n }\n\n return [name]\n }\n\n getFormDataFromState(state: FormSubmissionState): FormPayload {\n const { collection, name } = this\n\n if (collection) {\n return collection.getFormDataFromState(state)\n }\n\n return {\n [name]: this.getFormValue(state[name])\n }\n }\n\n getFormValueFromState(state: FormSubmissionState): FormValue | FormPayload {\n const { collection, name } = this\n\n if (collection) {\n return collection.getFormValueFromState(state)\n }\n\n return this.getFormValue(state[name])\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getStateFromValidForm(payload: FormPayload): FormState {\n const { collection, name } = this\n\n if (collection) {\n return collection.getStateFromValidForm(payload)\n }\n\n return {\n [name]: this.getFormValue(payload[name]) ?? null\n }\n }\n\n getErrors(\n _translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const { name } = this\n\n // Filter component and child errors only\n const list = errors?.filter(\n (error) =>\n error.name === name ||\n error.path.includes(name) ||\n this.keys.includes(error.name)\n )\n\n if (!list?.length) {\n return\n }\n\n return list\n }\n\n getFirstError(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError | undefined {\n return this.getErrors(translator, errors)?.[0]\n }\n\n getViewErrors(\n translator: Translator,\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const firstError = this.getFirstError(translator, errors)\n return firstError && [firstError]\n }\n\n /**\n * Override in composite fields to return translated Joi message overrides for\n * their sub-fields, applied at validation time so schema-level English messages\n * are replaced with the correct language. Return null to skip message patching.\n */\n getValidationMessagesOverride(\n _translator: Translator\n ): LanguageMessages | null {\n return null\n }\n\n getViewModel({\n payload,\n errors,\n translator,\n isForceAccess: _isForceAccess = false\n }: RenderContext) {\n const { hint, name, options = {}, title, viewModel } = this\n\n const { t, tComponent } = translator\n\n const isRequired = !('required' in options) || options.required !== false\n const hideOptional = 'optionalText' in options && options.optionalText\n\n const resolvedTitle = tComponent(this.def, 'title') || title\n const optionalTag =\n !isRequired && !hideOptional ? ` ${t('common.optional')}` : ''\n const label = `${resolvedTitle}${optionalTag}`\n\n if (hint) {\n viewModel.hint = {\n text: tComponent(this.def, 'hint') || hint\n }\n }\n\n // Filter component errors only\n const componentErrors = this.getErrors(translator, errors)\n const componentError = this.getFirstError(translator, componentErrors)\n\n if (componentErrors) {\n viewModel.errors = componentErrors\n }\n\n if (componentError) {\n viewModel.errorMessage = {\n text: componentError.text\n }\n }\n\n return {\n ...viewModel,\n label: {\n text: label\n },\n id: name,\n name,\n value: payload[name]\n }\n }\n\n getDisplayStringFromFormValue(\n value: FormValue | FormPayload,\n _translator: Translator\n ): string {\n // Map selected values to text\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n return this.isValue(value) ? value.toString() : ''\n }\n\n getDisplayStringFromState(\n state: FormSubmissionState,\n translator: Translator\n ): string {\n const value = this.getFormValueFromState(state)\n return this.getDisplayStringFromFormValue(value, translator)\n }\n\n getContextValueFromFormValue(\n value: FormValue | FormPayload\n ): Item['value'] | Item['value'][] | null {\n // Filter object field values\n if (this.isState(value)) {\n const values = Object.values(value).filter(isFormValue)\n return values.length ? values : null\n }\n\n // Filter array field values\n if (this.isValue(value) && Array.isArray(value)) {\n return value.filter(isFormValue)\n }\n\n return this.isValue(value) ? value : null\n }\n\n getContextValueFromState(\n state: FormSubmissionState\n ): Item['value'] | Item['value'][] | null {\n const value = this.getFormValueFromState(state)\n\n return this.getContextValueFromFormValue(value)\n }\n\n isValue(\n value?: FormStateValue | FormState\n ): value is NonNullable<FormStateValue> {\n return isFormValue(value)\n }\n\n isState(value?: FormStateValue | FormState): value is FormState {\n return isFormState(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return FormComponent.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [],\n advancedSettingsErrors: []\n }\n }\n\n onSubmit(\n _request: FormRequestPayload,\n _metadata: FormMetadata,\n _context: FormContext\n ): Promise<void> {\n return Promise.resolve()\n }\n}\n\n/**\n * Check for form value\n */\nexport function isFormValue(\n value?: unknown\n): value is string | number | boolean {\n return (\n (typeof value === 'string' && value.length > 0) ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n )\n}\n\n/**\n * Check for form state with nested values\n */\nexport function isFormState(value?: unknown): value is FormState {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return false\n }\n\n // Skip empty objects\n return !!Object.values(value).length\n}\n\n/**\n * Check for repeat list state\n */\nexport function isRepeatState(value?: unknown): value is RepeatListState {\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(isRepeatValue)\n}\n\n/**\n * Check for repeat list value\n */\nexport function isRepeatValue(value?: unknown): value is RepeatItemState {\n return isFormState(value) && typeof value.itemId === 'string'\n}\n\n/**\n * Check for upload state\n */\nexport function isUploadState(value?: unknown): value is UploadState {\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(isUploadValue)\n}\n\n/**\n * Check for geospatial state\n */\nexport function isGeospatialState(value?: unknown): value is GeospatialState {\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(isGeospatialValue)\n}\n\n/**\n * Check for upload state value\n */\nexport function isUploadValue(value?: unknown): value is FileState {\n return isFormState(value) && typeof value.uploadId === 'string'\n}\n\n/**\n * Check for geospatial state value\n */\nexport function isGeospatialValue(value?: unknown): value is Feature {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AAI;EACb;EAEA,OAAOb,KAAK,CAAC2D,KAAK,CAACM,iBAAiB,CAAC;AACvC;;AAEA;AACA;AACA;AACA,OAAO,SAASF,aAAaA,CAAC/D,KAAe,EAAsB;EACjE,OAAOgD,WAAW,CAAChD,KAAK,CAAC,IAAI,OAAOA,KAAK,CAACkE,QAAQ,KAAK,QAAQ;AACjE;;AAEA;AACA;AACA;AACA,OAAO,SAASD,iBAAiBA,CAACjE,KAAe,EAAoB;EACnE,OACEgD,WAAW,CAAChD,KAAK,CAAC,IAClB,OAAOA,KAAK,CAACvB,IAAI,KAAK,QAAQ,IAC9BuB,KAAK,CAACvB,IAAI,KAAK,SAAS;AAE5B","ignoreList":[]}
@@ -22,7 +22,7 @@ export class Markdown extends ComponentBase {
22
22
  } = context.translator;
23
23
  return {
24
24
  ...viewModel,
25
- content: tComponent(this, 'content') || content,
25
+ content: tComponent(this.def, 'content') || content,
26
26
  headerStartLevel: this.headerStartLevel
27
27
  };
28
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Markdown.js","names":["ComponentBase","Markdown","content","headerStartLevel","constructor","def","props","options","getViewModel","context","viewModel","tComponent","translator"],"sources":["../../../../../src/server/plugins/engine/components/Markdown.ts"],"sourcesContent":["import { type ComponentDef, type MarkdownComponent } from '@defra/forms-model'\n\nimport { ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\nimport { type RenderContext } from '~/src/server/plugins/engine/components/types.js'\n\nexport class Markdown extends ComponentBase {\n declare options: MarkdownComponent['options']\n content: MarkdownComponent['content']\n headerStartLevel: number\n\n constructor(\n def: MarkdownComponent,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { content, options } = def\n\n this.content = content\n this.options = options\n this.headerStartLevel = 2\n }\n\n getViewModel(context: RenderContext) {\n const { content, viewModel } = this\n\n const { tComponent } = context.translator\n\n return {\n ...viewModel,\n content:\n tComponent(this as unknown as ComponentDef, 'content') || content,\n headerStartLevel: this.headerStartLevel\n }\n }\n}\n"],"mappings":"AAEA,SAASA,aAAa;AAGtB,OAAO,MAAMC,QAAQ,SAASD,aAAa,CAAC;EAE1CE,OAAO;EACPC,gBAAgB;EAEhBC,WAAWA,CACTC,GAAsB,EACtBC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEJ,OAAO;MAAEK;IAAQ,CAAC,GAAGF,GAAG;IAEhC,IAAI,CAACH,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACK,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACJ,gBAAgB,GAAG,CAAC;EAC3B;EAEAK,YAAYA,CAACC,OAAsB,EAAE;IACnC,MAAM;MAAEP,OAAO;MAAEQ;IAAU,CAAC,GAAG,IAAI;IAEnC,MAAM;MAAEC;IAAW,CAAC,GAAGF,OAAO,CAACG,UAAU;IAEzC,OAAO;MACL,GAAGF,SAAS;MACZR,OAAO,EACLS,UAAU,CAAC,IAAI,EAA6B,SAAS,CAAC,IAAIT,OAAO;MACnEC,gBAAgB,EAAE,IAAI,CAACA;IACzB,CAAC;EACH;AACF","ignoreList":[]}
1
+ {"version":3,"file":"Markdown.js","names":["ComponentBase","Markdown","content","headerStartLevel","constructor","def","props","options","getViewModel","context","viewModel","tComponent","translator"],"sources":["../../../../../src/server/plugins/engine/components/Markdown.ts"],"sourcesContent":["import { type MarkdownComponent } from '@defra/forms-model'\n\nimport { ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\nimport { type RenderContext } from '~/src/server/plugins/engine/components/types.js'\n\nexport class Markdown extends ComponentBase {\n declare options: MarkdownComponent['options']\n content: MarkdownComponent['content']\n headerStartLevel: number\n\n constructor(\n def: MarkdownComponent,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { content, options } = def\n\n this.content = content\n this.options = options\n this.headerStartLevel = 2\n }\n\n getViewModel(context: RenderContext) {\n const { content, viewModel } = this\n\n const { tComponent } = context.translator\n\n return {\n ...viewModel,\n content: tComponent(this.def, 'content') || content,\n headerStartLevel: this.headerStartLevel\n }\n }\n}\n"],"mappings":"AAEA,SAASA,aAAa;AAGtB,OAAO,MAAMC,QAAQ,SAASD,aAAa,CAAC;EAE1CE,OAAO;EACPC,gBAAgB;EAEhBC,WAAWA,CACTC,GAAsB,EACtBC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEJ,OAAO;MAAEK;IAAQ,CAAC,GAAGF,GAAG;IAEhC,IAAI,CAACH,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACK,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACJ,gBAAgB,GAAG,CAAC;EAC3B;EAEAK,YAAYA,CAACC,OAAsB,EAAE;IACnC,MAAM;MAAEP,OAAO;MAAEQ;IAAU,CAAC,GAAG,IAAI;IAEnC,MAAM;MAAEC;IAAW,CAAC,GAAGF,OAAO,CAACG,UAAU;IAEzC,OAAO;MACL,GAAGF,SAAS;MACZR,OAAO,EAAES,UAAU,CAAC,IAAI,CAACN,GAAG,EAAE,SAAS,CAAC,IAAIH,OAAO;MACnDC,gBAAgB,EAAE,IAAI,CAACA;IACzB,CAAC;EACH;AACF","ignoreList":[]}
@@ -13,6 +13,7 @@ export type FormDefinitionTranslations = Record<string, {
13
13
  hint: string;
14
14
  content: string;
15
15
  shortDescription: string;
16
+ errorDescription: string;
16
17
  paymentDescription: string;
17
18
  }>>;
18
19
  sections: Record<string, Partial<Pick<Section, 'title'>>>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../../../src/server/plugins/engine/i18n/types.ts"],"sourcesContent":["import {\n type ComponentDef,\n type Item,\n type Page,\n type Section\n} from '@defra/forms-model'\n\n/**\n * Structure of the `translations` block in a form definition.\n * Also used to derive the valid property keys for the typed tX functions.\n */\nexport type FormDefinitionTranslations = Record<\n string,\n {\n pages: Record<string, Partial<{ title: string; repeatTitle: string }>>\n // ComponentDef is a discriminated union; Pick across the full union is not feasible.\n // The four keys below are the complete set of translatable component properties.\n components: Record<\n string,\n Partial<{\n title: string\n hint: string\n content: string\n shortDescription: string\n paymentDescription: string\n }>\n >\n sections: Record<string, Partial<Pick<Section, 'title'>>>\n listItems: Record<string, Partial<Pick<Item, 'text' | 'hint'>>>\n form: Record<string, string>\n }\n>\n\ntype EntityTranslations = FormDefinitionTranslations[string]\n\n/**\n * Scoped translator returned by model.createTranslator(language).\n * t — plugin namespace (UI strings, buttons, errors, sub-field labels)\n * tForm — form namespace: form attributes, currently only form name\n * tPage — form namespace: page titles\n * tComponent — form namespace: component titles, hints, shortDescriptions\n * tSection — form namespace: section titles\n * tListItem — form namespace: list item text\n * language - current language\n */\nexport interface Translator {\n t: (key: string, opts?: Record<string, unknown>) => string\n tForm: (prop: string) => string\n tPage: (page: Page, prop: keyof EntityTranslations['pages'][string]) => string\n tComponent: (\n component: ComponentDef,\n prop: keyof EntityTranslations['components'][string]\n ) => string\n tSection: (\n section: Section,\n prop: keyof EntityTranslations['sections'][string]\n ) => string\n tListItem: (\n item: Item,\n prop: keyof EntityTranslations['listItems'][string]\n ) => string\n language: string\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../../../src/server/plugins/engine/i18n/types.ts"],"sourcesContent":["import {\n type ComponentDef,\n type Item,\n type Page,\n type Section\n} from '@defra/forms-model'\n\n/**\n * Structure of the `translations` block in a form definition.\n * Also used to derive the valid property keys for the typed tX functions.\n */\nexport type FormDefinitionTranslations = Record<\n string,\n {\n pages: Record<string, Partial<{ title: string; repeatTitle: string }>>\n // ComponentDef is a discriminated union; Pick across the full union is not feasible.\n // The four keys below are the complete set of translatable component properties.\n components: Record<\n string,\n Partial<{\n title: string\n hint: string\n content: string\n shortDescription: string\n errorDescription: string\n paymentDescription: string\n }>\n >\n sections: Record<string, Partial<Pick<Section, 'title'>>>\n listItems: Record<string, Partial<Pick<Item, 'text' | 'hint'>>>\n form: Record<string, string>\n }\n>\n\ntype EntityTranslations = FormDefinitionTranslations[string]\n\n/**\n * Scoped translator returned by model.createTranslator(language).\n * t — plugin namespace (UI strings, buttons, errors, sub-field labels)\n * tForm — form namespace: form attributes, currently only form name\n * tPage — form namespace: page titles\n * tComponent — form namespace: component titles, hints, shortDescriptions\n * tSection — form namespace: section titles\n * tListItem — form namespace: list item text\n * language - current language\n */\nexport interface Translator {\n t: (key: string, opts?: Record<string, unknown>) => string\n tForm: (prop: string) => string\n tPage: (page: Page, prop: keyof EntityTranslations['pages'][string]) => string\n tComponent: (\n component: ComponentDef,\n prop: keyof EntityTranslations['components'][string]\n ) => string\n tSection: (\n section: Section,\n prop: keyof EntityTranslations['sections'][string]\n ) => string\n tListItem: (\n item: Item,\n prop: keyof EntityTranslations['listItems'][string]\n ) => string\n language: string\n}\n"],"mappings":"","ignoreList":[]}
@@ -164,12 +164,16 @@ function ItemRepeat(page, state, options, translator) {
164
164
  repeat
165
165
  } = page;
166
166
  const {
167
- name,
168
- title
167
+ name
169
168
  } = repeat.options;
169
+ const {
170
+ t,
171
+ tPage
172
+ } = translator;
173
+ const title = tPage(page.pageDef, 'repeatTitle') || repeat.options.title;
170
174
  const values = page.getListFromState(state);
171
175
  const count = values.length;
172
- const value = count === 0 ? '' : translator.t('pages.repeater.pageTitle', {
176
+ const value = count === 0 ? '' : t('pages.repeater.pageTitle', {
173
177
  count
174
178
  });
175
179
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"SummaryViewModel.js","names":["SchemaVersion","PaymentField","getAnswer","evaluateTemplate","getError","getPageHref","RepeatPageController","validationOptions","opts","SummaryViewModel","page","pageTitle","declaration","details","checkAnswers","context","name","backLink","feedbackLink","phaseTag","errors","serviceUrl","hasMissingNotificationEmail","components","allowSaveAndExit","paymentState","paymentDetails","t","_translator","paymentRequired","paymentPreAuthorized","constructor","request","translator","model","basePath","def","sections","isForceAccess","title","schema","V2","result","makeFilteredSchema","relevantPages","validate","relevantState","stripUnknown","error","map","summaryDetails","detail","rows","items","item","push","href","text","classes","visuallyHiddenText","label","key","value","html","actions","undefined","summaryList","state","forEach","section","sectionPages","filter","collection","path","ItemRepeat","getSummaryPath","field","fields","ItemField","length","sectionTitle","tSection","options","repeat","values","getListFromState","count","returnUrl","subItems","repeatState","fieldDef","id","type","shortDescription","rawLabel","tComponent","translatedLabel","rawTitle","translatedTitle","optional","required","getFirstError","format"],"sources":["../../../../../src/server/plugins/engine/models/SummaryViewModel.ts"],"sourcesContent":["import {\n SchemaVersion,\n type ComponentDef,\n type Section\n} from '@defra/forms-model'\n\nimport { PaymentField } from '~/src/server/plugins/engine/components/PaymentField.js'\nimport { type PaymentState } from '~/src/server/plugins/engine/components/PaymentField.types.js'\nimport {\n getAnswer,\n type Field\n} from '~/src/server/plugins/engine/components/helpers/components.js'\nimport {\n type BackLink,\n type ComponentViewModel\n} from '~/src/server/plugins/engine/components/types.js'\nimport {\n evaluateTemplate,\n getError,\n getPageHref\n} from '~/src/server/plugins/engine/helpers.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport {\n type Detail,\n type DetailItem,\n type DetailItemField,\n type DetailItemRepeat\n} from '~/src/server/plugins/engine/models/types.js'\nimport { RepeatPageController } from '~/src/server/plugins/engine/pageControllers/RepeatPageController.js'\nimport { type PageControllerClass } from '~/src/server/plugins/engine/pageControllers/helpers/pages.js'\nimport { validationOptions as opts } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type CheckAnswers,\n type FormContext,\n type FormContextRequest,\n type FormState,\n type FormSubmissionError,\n type SummaryListAction,\n type SummaryListRow\n} from '~/src/server/plugins/engine/types.js'\n\nexport class SummaryViewModel {\n /**\n * Responsible for parsing state values to the govuk-frontend summary list template\n */\n\n page: PageControllerClass\n pageTitle: string\n declaration?: string\n details: Detail[]\n checkAnswers: CheckAnswers[]\n context: FormContext\n name: string | undefined\n backLink?: BackLink\n feedbackLink?: string\n phaseTag?: string\n errors?: FormSubmissionError[]\n serviceUrl: string\n hasMissingNotificationEmail?: boolean\n components?: ComponentViewModel[]\n allowSaveAndExit = false\n paymentState?: PaymentState\n paymentDetails?: CheckAnswers\n t: (key: string, opts?: Record<string, unknown>) => string\n private readonly _translator!: Translator\n paymentRequired?: boolean\n paymentPreAuthorized?: boolean\n\n constructor(\n request: FormContextRequest,\n page: PageControllerClass,\n context: FormContext,\n translator: Translator\n ) {\n const { model } = page\n const { basePath, def, sections } = model\n const { isForceAccess } = context\n\n const { t } = translator\n this.t = t\n this._translator = translator\n\n this.page = page\n this.pageTitle = page.title\n if (def.schema === SchemaVersion.V2 && !page.title) {\n this.pageTitle = t('pages.summary.title')\n }\n\n this.serviceUrl = `/${basePath}`\n this.name = def.name\n this.declaration = def.declaration\n this.context = context\n\n const result = model\n .makeFilteredSchema(this.context.relevantPages)\n .validate(this.context.relevantState, { ...opts, stripUnknown: true })\n\n // Format errors\n this.errors = result.error?.details.map(getError)\n this.details = this.summaryDetails(request, sections, translator)\n\n // Format check answers\n this.checkAnswers = this.details.map((detail): CheckAnswers => {\n const { title } = detail\n\n const rows = detail.items.map((item): SummaryListRow => {\n const items: SummaryListAction[] = []\n\n // Remove summary list actions from previews\n if (!isForceAccess) {\n items.push({\n href: item.href,\n text: t('pages.summary.change'),\n classes: 'govuk-link--no-visited-state',\n visuallyHiddenText: item.label\n })\n }\n\n return {\n key: {\n text: evaluateTemplate(item.title, context)\n },\n value: {\n classes: 'app-prose-scope',\n html: item.value || t('pages.summary.notProvided')\n },\n actions: {\n items\n }\n }\n })\n\n return {\n title: title ? { text: title } : undefined,\n summaryList: { rows }\n }\n })\n }\n\n private summaryDetails(\n request: FormContextRequest,\n sections: Section[],\n translator: Translator\n ) {\n const { context, errors } = this\n const { relevantPages, state } = context\n\n const details: Detail[] = []\n\n ;[...sections, undefined].forEach((section) => {\n const items: DetailItem[] = []\n\n const sectionPages = relevantPages.filter(\n (page) => page.section === section\n )\n\n sectionPages.forEach((page) => {\n const { collection, path } = page\n\n if (page instanceof RepeatPageController) {\n items.push(\n ItemRepeat(\n page,\n state,\n {\n path: page.getSummaryPath(request),\n errors\n },\n translator\n )\n )\n } else {\n for (const field of collection.fields) {\n // PaymentField is rendered in its own section, skip it here\n if (field instanceof PaymentField) {\n continue\n }\n items.push(\n ItemField(page, state, field, { path, errors }, translator)\n )\n }\n }\n })\n\n if (items.length) {\n const sectionTitle = section\n ? translator.tSection(section, 'title') || section.title\n : undefined\n details.push({\n name: section?.name,\n title: sectionTitle,\n items\n })\n }\n })\n\n return details\n }\n}\n\n/**\n * Creates a repeater detail item\n * @see {@link DetailItemField}\n */\nfunction ItemRepeat(\n page: RepeatPageController,\n state: FormState,\n options: {\n path: string\n errors?: FormSubmissionError[]\n },\n translator: Translator\n): DetailItemRepeat {\n const { collection, repeat } = page\n const { name, title } = repeat.options\n\n const values = page.getListFromState(state)\n const count = values.length\n const value =\n count === 0 ? '' : translator.t('pages.repeater.pageTitle', { count })\n\n return {\n name,\n label: title,\n title,\n value,\n href: getPageHref(page, options.path, {\n returnUrl: getPageHref(page, page.getSummaryPath())\n }),\n state,\n page,\n\n // Repeater field detail items\n subItems: values.map((repeatState) =>\n collection.fields.map((field) =>\n ItemField(page, repeatState, field, options, translator)\n )\n )\n }\n}\n\n/**\n * Creates a form field detail item\n * @see {@link DetailItemField}\n */\nexport function ItemField(\n page: PageControllerClass,\n state: FormState,\n field: Field,\n options: {\n path: string\n errors?: FormSubmissionError[]\n },\n translator: Translator\n): DetailItemField {\n // FormComponent doesn't expose shortDescription/title as raw def properties,\n // so build a lookup object with English values to let tComponent's GUID lookup fire.\n const fieldDef = {\n id: field.id,\n type: field.type,\n shortDescription: field.label,\n title: field.title\n } as unknown as ComponentDef\n const rawLabel = translator.tComponent(fieldDef, 'shortDescription')\n const translatedLabel = rawLabel !== '' ? rawLabel : field.label\n const rawTitle = translator.tComponent(fieldDef, 'title')\n const translatedTitle = rawTitle !== '' ? rawTitle : field.title\n const optional =\n field.options.required === false\n ? ` ${translator.t('common.optional')}`\n : ''\n return {\n name: field.name,\n label: translatedTitle,\n title: `${translatedLabel}${optional}`,\n error: field.getFirstError(translator, options.errors),\n value: getAnswer(field, state, translator, { format: 'summary' }),\n href: getPageHref(page, options.path, {\n returnUrl: getPageHref(page, page.getSummaryPath())\n }),\n state,\n page,\n field\n }\n}\n"],"mappings":"AAAA,SACEA,aAAa,QAGR,oBAAoB;AAE3B,SAASC,YAAY;AAErB,SACEC,SAAS;AAOX,SACEC,gBAAgB,EAChBC,QAAQ,EACRC,WAAW;AASb,SAASC,oBAAoB;AAE7B,SAASC,iBAAiB,IAAIC,IAAI;AAWlC,OAAO,MAAMC,gBAAgB,CAAC;EAC5B;AACF;AACA;;EAEEC,IAAI;EACJC,SAAS;EACTC,WAAW;EACXC,OAAO;EACPC,YAAY;EACZC,OAAO;EACPC,IAAI;EACJC,QAAQ;EACRC,YAAY;EACZC,QAAQ;EACRC,MAAM;EACNC,UAAU;EACVC,2BAA2B;EAC3BC,UAAU;EACVC,gBAAgB,GAAG,KAAK;EACxBC,YAAY;EACZC,cAAc;EACdC,CAAC;EACgBC,WAAW;EAC5BC,eAAe;EACfC,oBAAoB;EAEpBC,WAAWA,CACTC,OAA2B,EAC3BtB,IAAyB,EACzBK,OAAoB,EACpBkB,UAAsB,EACtB;IACA,MAAM;MAAEC;IAAM,CAAC,GAAGxB,IAAI;IACtB,MAAM;MAAEyB,QAAQ;MAAEC,GAAG;MAAEC;IAAS,CAAC,GAAGH,KAAK;IACzC,MAAM;MAAEI;IAAc,CAAC,GAAGvB,OAAO;IAEjC,MAAM;MAAEY;IAAE,CAAC,GAAGM,UAAU;IACxB,IAAI,CAACN,CAAC,GAAGA,CAAC;IACV,IAAI,CAACC,WAAW,GAAGK,UAAU;IAE7B,IAAI,CAACvB,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,SAAS,GAAGD,IAAI,CAAC6B,KAAK;IAC3B,IAAIH,GAAG,CAACI,MAAM,KAAKxC,aAAa,CAACyC,EAAE,IAAI,CAAC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K,CAAC5D,IAAI;IAChB4C,KAAK,EAAEsC,eAAe;IACtB3D,KAAK,EAAE,GAAGyD,eAAe,GAAGG,QAAQ,EAAE;IACtCnD,KAAK,EAAE4B,KAAK,CAACyB,aAAa,CAACpE,UAAU,EAAEiD,OAAO,CAAC9D,MAAM,CAAC;IACtD0C,KAAK,EAAE5D,SAAS,CAAC0E,KAAK,EAAET,KAAK,EAAElC,UAAU,EAAE;MAAEqE,MAAM,EAAE;IAAU,CAAC,CAAC;IACjE9C,IAAI,EAAEnD,WAAW,CAACK,IAAI,EAAEwE,OAAO,CAACT,IAAI,EAAE;MACpCc,SAAS,EAAElF,WAAW,CAACK,IAAI,EAAEA,IAAI,CAACiE,cAAc,CAAC,CAAC;IACpD,CAAC,CAAC;IACFR,KAAK;IACLzD,IAAI;IACJkE;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"SummaryViewModel.js","names":["SchemaVersion","PaymentField","getAnswer","evaluateTemplate","getError","getPageHref","RepeatPageController","validationOptions","opts","SummaryViewModel","page","pageTitle","declaration","details","checkAnswers","context","name","backLink","feedbackLink","phaseTag","errors","serviceUrl","hasMissingNotificationEmail","components","allowSaveAndExit","paymentState","paymentDetails","t","_translator","paymentRequired","paymentPreAuthorized","constructor","request","translator","model","basePath","def","sections","isForceAccess","title","schema","V2","result","makeFilteredSchema","relevantPages","validate","relevantState","stripUnknown","error","map","summaryDetails","detail","rows","items","item","push","href","text","classes","visuallyHiddenText","label","key","value","html","actions","undefined","summaryList","state","forEach","section","sectionPages","filter","collection","path","ItemRepeat","getSummaryPath","field","fields","ItemField","length","sectionTitle","tSection","options","repeat","tPage","pageDef","values","getListFromState","count","returnUrl","subItems","repeatState","fieldDef","id","type","shortDescription","rawLabel","tComponent","translatedLabel","rawTitle","translatedTitle","optional","required","getFirstError","format"],"sources":["../../../../../src/server/plugins/engine/models/SummaryViewModel.ts"],"sourcesContent":["import {\n SchemaVersion,\n type ComponentDef,\n type Section\n} from '@defra/forms-model'\n\nimport { PaymentField } from '~/src/server/plugins/engine/components/PaymentField.js'\nimport { type PaymentState } from '~/src/server/plugins/engine/components/PaymentField.types.js'\nimport {\n getAnswer,\n type Field\n} from '~/src/server/plugins/engine/components/helpers/components.js'\nimport {\n type BackLink,\n type ComponentViewModel\n} from '~/src/server/plugins/engine/components/types.js'\nimport {\n evaluateTemplate,\n getError,\n getPageHref\n} from '~/src/server/plugins/engine/helpers.js'\nimport { type Translator } from '~/src/server/plugins/engine/i18n/types.js'\nimport {\n type Detail,\n type DetailItem,\n type DetailItemField,\n type DetailItemRepeat\n} from '~/src/server/plugins/engine/models/types.js'\nimport { RepeatPageController } from '~/src/server/plugins/engine/pageControllers/RepeatPageController.js'\nimport { type PageControllerClass } from '~/src/server/plugins/engine/pageControllers/helpers/pages.js'\nimport { validationOptions as opts } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type CheckAnswers,\n type FormContext,\n type FormContextRequest,\n type FormState,\n type FormSubmissionError,\n type SummaryListAction,\n type SummaryListRow\n} from '~/src/server/plugins/engine/types.js'\n\nexport class SummaryViewModel {\n /**\n * Responsible for parsing state values to the govuk-frontend summary list template\n */\n\n page: PageControllerClass\n pageTitle: string\n declaration?: string\n details: Detail[]\n checkAnswers: CheckAnswers[]\n context: FormContext\n name: string | undefined\n backLink?: BackLink\n feedbackLink?: string\n phaseTag?: string\n errors?: FormSubmissionError[]\n serviceUrl: string\n hasMissingNotificationEmail?: boolean\n components?: ComponentViewModel[]\n allowSaveAndExit = false\n paymentState?: PaymentState\n paymentDetails?: CheckAnswers\n t: (key: string, opts?: Record<string, unknown>) => string\n private readonly _translator!: Translator\n paymentRequired?: boolean\n paymentPreAuthorized?: boolean\n\n constructor(\n request: FormContextRequest,\n page: PageControllerClass,\n context: FormContext,\n translator: Translator\n ) {\n const { model } = page\n const { basePath, def, sections } = model\n const { isForceAccess } = context\n\n const { t } = translator\n this.t = t\n this._translator = translator\n\n this.page = page\n this.pageTitle = page.title\n if (def.schema === SchemaVersion.V2 && !page.title) {\n this.pageTitle = t('pages.summary.title')\n }\n\n this.serviceUrl = `/${basePath}`\n this.name = def.name\n this.declaration = def.declaration\n this.context = context\n\n const result = model\n .makeFilteredSchema(this.context.relevantPages)\n .validate(this.context.relevantState, { ...opts, stripUnknown: true })\n\n // Format errors\n this.errors = result.error?.details.map(getError)\n this.details = this.summaryDetails(request, sections, translator)\n\n // Format check answers\n this.checkAnswers = this.details.map((detail): CheckAnswers => {\n const { title } = detail\n\n const rows = detail.items.map((item): SummaryListRow => {\n const items: SummaryListAction[] = []\n\n // Remove summary list actions from previews\n if (!isForceAccess) {\n items.push({\n href: item.href,\n text: t('pages.summary.change'),\n classes: 'govuk-link--no-visited-state',\n visuallyHiddenText: item.label\n })\n }\n\n return {\n key: {\n text: evaluateTemplate(item.title, context)\n },\n value: {\n classes: 'app-prose-scope',\n html: item.value || t('pages.summary.notProvided')\n },\n actions: {\n items\n }\n }\n })\n\n return {\n title: title ? { text: title } : undefined,\n summaryList: { rows }\n }\n })\n }\n\n private summaryDetails(\n request: FormContextRequest,\n sections: Section[],\n translator: Translator\n ) {\n const { context, errors } = this\n const { relevantPages, state } = context\n\n const details: Detail[] = []\n\n ;[...sections, undefined].forEach((section) => {\n const items: DetailItem[] = []\n\n const sectionPages = relevantPages.filter(\n (page) => page.section === section\n )\n\n sectionPages.forEach((page) => {\n const { collection, path } = page\n\n if (page instanceof RepeatPageController) {\n items.push(\n ItemRepeat(\n page,\n state,\n {\n path: page.getSummaryPath(request),\n errors\n },\n translator\n )\n )\n } else {\n for (const field of collection.fields) {\n // PaymentField is rendered in its own section, skip it here\n if (field instanceof PaymentField) {\n continue\n }\n items.push(\n ItemField(page, state, field, { path, errors }, translator)\n )\n }\n }\n })\n\n if (items.length) {\n const sectionTitle = section\n ? translator.tSection(section, 'title') || section.title\n : undefined\n details.push({\n name: section?.name,\n title: sectionTitle,\n items\n })\n }\n })\n\n return details\n }\n}\n\n/**\n * Creates a repeater detail item\n * @see {@link DetailItemField}\n */\nfunction ItemRepeat(\n page: RepeatPageController,\n state: FormState,\n options: {\n path: string\n errors?: FormSubmissionError[]\n },\n translator: Translator\n): DetailItemRepeat {\n const { collection, repeat } = page\n const { name } = repeat.options\n const { t, tPage } = translator\n const title = tPage(page.pageDef, 'repeatTitle') || repeat.options.title\n const values = page.getListFromState(state)\n const count = values.length\n const value = count === 0 ? '' : t('pages.repeater.pageTitle', { count })\n\n return {\n name,\n label: title,\n title,\n value,\n href: getPageHref(page, options.path, {\n returnUrl: getPageHref(page, page.getSummaryPath())\n }),\n state,\n page,\n\n // Repeater field detail items\n subItems: values.map((repeatState) =>\n collection.fields.map((field) =>\n ItemField(page, repeatState, field, options, translator)\n )\n )\n }\n}\n\n/**\n * Creates a form field detail item\n * @see {@link DetailItemField}\n */\nexport function ItemField(\n page: PageControllerClass,\n state: FormState,\n field: Field,\n options: {\n path: string\n errors?: FormSubmissionError[]\n },\n translator: Translator\n): DetailItemField {\n // FormComponent doesn't expose shortDescription/title as raw def properties,\n // so build a lookup object with English values to let tComponent's GUID lookup fire.\n const fieldDef = {\n id: field.id,\n type: field.type,\n shortDescription: field.label,\n title: field.title\n } as unknown as ComponentDef\n const rawLabel = translator.tComponent(fieldDef, 'shortDescription')\n const translatedLabel = rawLabel !== '' ? rawLabel : field.label\n const rawTitle = translator.tComponent(fieldDef, 'title')\n const translatedTitle = rawTitle !== '' ? rawTitle : field.title\n const optional =\n field.options.required === false\n ? ` ${translator.t('common.optional')}`\n : ''\n return {\n name: field.name,\n label: translatedTitle,\n title: `${translatedLabel}${optional}`,\n error: field.getFirstError(translator, options.errors),\n value: getAnswer(field, state, translator, { format: 'summary' }),\n href: getPageHref(page, options.path, {\n returnUrl: getPageHref(page, page.getSummaryPath())\n }),\n state,\n page,\n field\n }\n}\n"],"mappings":"AAAA,SACEA,aAAa,QAGR,oBAAoB;AAE3B,SAASC,YAAY;AAErB,SACEC,SAAS;AAOX,SACEC,gBAAgB,EAChBC,QAAQ,E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Aa,CAACtE,UAAU,EAAEiD,OAAO,CAAC9D,MAAM,CAAC;IACtD0C,KAAK,EAAE5D,SAAS,CAAC0E,KAAK,EAAET,KAAK,EAAElC,UAAU,EAAE;MAAEuE,MAAM,EAAE;IAAU,CAAC,CAAC;IACjEhD,IAAI,EAAEnD,WAAW,CAACK,IAAI,EAAEwE,OAAO,CAACT,IAAI,EAAE;MACpCgB,SAAS,EAAEpF,WAAW,CAACK,IAAI,EAAEA,IAAI,CAACiE,cAAc,CAAC,CAAC;IACpD,CAAC,CAAC;IACFR,KAAK;IACLzD,IAAI;IACJkE;EACF,CAAC;AACH","ignoreList":[]}
@@ -1,3 +1,4 @@
1
+ import { EN_GB } from "../../../../constants.js";
1
2
  import { getFormVersion } from "../../helpers.js";
2
3
  import { categoriseData } from "../machine/v2.js";
3
4
  import { FormAdapterSubmissionSchemaVersion } from "../../types/enums.js";
@@ -17,15 +18,12 @@ export function format(context, items, model, submitResponse, formStatus, formMe
17
18
  formSlug: formMetadata?.slug ?? '',
18
19
  status: formStatus.state,
19
20
  isPreview: formStatus.isPreview,
20
- notificationEmail: formMetadata?.notificationEmail ?? ''
21
+ notificationEmail: formMetadata?.notificationEmail ?? '',
22
+ language: context.translator?.language ?? EN_GB
21
23
  };
22
24
  if (versionMetadata) {
23
25
  meta.versionMetadata = versionMetadata;
24
26
  }
25
- const definitionLanguage = model.def.metadata?.language;
26
- if (typeof definitionLanguage === 'string') {
27
- meta.language = definitionLanguage;
28
- }
29
27
  const main = Object.fromEntries(Object.entries(v2Main).map(([key, value]) => {
30
28
  if (value === undefined) {
31
29
  return [key, null];
@@ -1 +1 @@
1
- {"version":3,"file":"v1.js","names":["getFormVersion","categoriseData","FormAdapterSubmissionSchemaVersion","format","context","items","model","submitResponse","formStatus","formMetadata","csvFiles","extractCsvFiles","main","v2Main","v2Data","versionMetadata","def","meta","schemaVersion","V1","timestamp","Date","referenceNumber","formName","name","formId","id","formSlug","slug","status","state","isPreview","notificationEmail","definitionLanguage","metadata","language","Object","fromEntries","entries","map","key","value","undefined","data","result","files","payload","JSON","stringify","repeaters"],"sources":["../../../../../../src/server/plugins/engine/outputFormatters/adapter/v1.ts"],"sourcesContent":["import {\n type FormMetadata,\n type SubmitResponsePayload\n} from '@defra/forms-model'\n\nimport {\n getFormVersion,\n type checkFormStatus\n} from '~/src/server/plugins/engine/helpers.js'\nimport { type FormModel } from '~/src/server/plugins/engine/models/FormModel.js'\nimport { type DetailItem } from '~/src/server/plugins/engine/models/types.js'\nimport { categoriseData } from '~/src/server/plugins/engine/outputFormatters/machine/v2.js'\nimport { FormAdapterSubmissionSchemaVersion } from '~/src/server/plugins/engine/types/enums.js'\nimport {\n type FormAdapterSubmissionMessageData,\n type FormAdapterSubmissionMessageMeta,\n type FormAdapterSubmissionMessagePayload,\n type FormAdapterSubmissionMessageResult,\n type FormContext\n} from '~/src/server/plugins/engine/types.js'\n\nexport function format(\n context: FormContext,\n items: DetailItem[],\n model: FormModel,\n submitResponse: SubmitResponsePayload,\n formStatus: ReturnType<typeof checkFormStatus>,\n formMetadata?: FormMetadata\n): string {\n const csvFiles = extractCsvFiles(submitResponse)\n\n const { main: v2Main, ...v2Data } = categoriseData(items)\n\n const versionMetadata = getFormVersion(model.def)\n\n const meta: FormAdapterSubmissionMessageMeta = {\n schemaVersion: FormAdapterSubmissionSchemaVersion.V1,\n timestamp: new Date(),\n referenceNumber: context.referenceNumber,\n formName: model.name,\n formId: formMetadata?.id ?? '',\n formSlug: formMetadata?.slug ?? '',\n status: formStatus.state,\n isPreview: formStatus.isPreview,\n notificationEmail: formMetadata?.notificationEmail ?? ''\n }\n\n if (versionMetadata) {\n meta.versionMetadata = versionMetadata\n }\n\n const definitionLanguage = model.def.metadata?.language\n if (typeof definitionLanguage === 'string') {\n meta.language = definitionLanguage\n }\n\n const main = Object.fromEntries(\n Object.entries(v2Main).map(([key, value]) => {\n if (value === undefined) {\n return [key, null]\n }\n\n return [key, value]\n })\n )\n\n const data: FormAdapterSubmissionMessageData = {\n main,\n ...v2Data\n }\n\n const result: FormAdapterSubmissionMessageResult = {\n files: csvFiles\n }\n\n const payload: FormAdapterSubmissionMessagePayload = {\n meta,\n data,\n result\n }\n\n return JSON.stringify(payload)\n}\n\nfunction extractCsvFiles(\n submitResponse: SubmitResponsePayload\n): FormAdapterSubmissionMessageResult['files'] {\n const result =\n submitResponse.result as Partial<FormAdapterSubmissionMessageResult>\n\n return {\n main: result.files?.main ?? '',\n repeaters: result.files?.repeaters ?? {}\n }\n}\n"],"mappings":"AAKA,SACEA,cAAc;AAKhB,SAASC,cAAc;AACvB,SAASC,kCAAkC;AAS3C,OAAO,SAASC,MAAMA,CACpBC,OAAoB,EACpBC,KAAmB,EACnBC,KAAgB,EAChBC,cAAqC,EACrCC,UAA8C,EAC9CC,YAA2B,EACnB;EACR,MAAMC,QAAQ,GAAGC,eAAe,CAACJ,cAAc,CAAC;EAEhD,MAAM;IAAEK,IAAI,EAAEC,MAAM;IAAE,GAAGC;EAAO,CAAC,GAAGb,cAAc,CAACI,KAAK,CAAC;EAEzD,MAAMU,eAAe,GAAGf,cAAc,CAACM,KAAK,CAACU,GAAG,CAAC;EAEjD,MAAMC,IAAsC,GAAG;IAC7CC,aAAa,EAAEhB,kCAAkC,CAACiB,EAAE;IACpDC,SAAS,EAAE,IAAIC,IAAI,CAAC,CAAC;IACrBC,eAAe,EAAElB,OAAO,CAACkB,eAAe;IACxCC,QAAQ,EAAEjB,KAAK,CAACkB,IAAI;IACpBC,MAAM,EAAEhB,YAAY,EAAEiB,EAAE,IAAI,EAAE;IAC9BC,QAAQ,EAAElB,YAAY,EAAEmB,IAAI,IAAI,EAAE;IAClCC,MAAM,EAAErB,UAAU,CAACsB,KAAK;IACxBC,SAAS,EAAEvB,UAAU,CAACuB,SAAS;IAC/BC,iBAAiB,EAAEvB,YAAY,EAAEuB,iBAAiB,IAAI;EACxD,CAAC;EAED,IAAIjB,eAAe,EAAE;IACnBE,IAAI,CAACF,eAAe,GAAGA,eAAe;EACxC;EAEA,MAAMkB,kBAAkB,GAAG3B,KAAK,CAACU,GAAG,CAACkB,QAAQ,EAAEC,QAAQ;EACvD,IAAI,OAAOF,kBAAkB,KAAK,QAAQ,EAAE;IAC1ChB,IAAI,CAACkB,QAAQ,GAAGF,kBAAkB;EACpC;EAEA,MAAMrB,IAAI,GAAGwB,MAAM,CAACC,WAAW,CAC7BD,MAAM,CAACE,OAAO,CAACzB,MAAM,CAAC,CAAC0B,GAAG,CAAC,CAAC,CAACC,GAAG,EAAEC,KAAK,CAAC,KAAK;IAC3C,IAAIA,KAAK,KAAKC,SAAS,EAAE;MACvB,OAAO,CAACF,GAAG,EAAE,IAAI,CAAC;IACpB;IAEA,OAAO,CAACA,GAAG,EAAEC,KAAK,CAAC;EACrB,CAAC,CACH,CAAC;EAED,MAAME,IAAsC,GAAG;IAC7C/B,IAAI;IACJ,GAAGE;EACL,CAAC;EAED,MAAM8B,MAA0C,GAAG;IACjDC,KAAK,EAAEnC;EACT,CAAC;EAED,MAAMoC,OAA4C,GAAG;IACnD7B,IAAI;IACJ0B,IAAI;IACJC;EACF,CAAC;EAED,OAAOG,IAAI,CAACC,SAAS,CAACF,OAAO,CAAC;AAChC;AAEA,SAASnC,eAAeA,CACtBJ,cAAqC,EACQ;EAC7C,MAAMqC,MAAM,GACVrC,cAAc,CAACqC,MAAqD;EAEtE,OAAO;IACLhC,IAAI,EAAEgC,MAAM,CAACC,KAAK,EAAEjC,IAAI,IAAI,EAAE;IAC9BqC,SAAS,EAAEL,MAAM,CAACC,KAAK,EAAEI,SAAS,IAAI,CAAC;EACzC,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"v1.js","names":["EN_GB","getFormVersion","categoriseData","FormAdapterSubmissionSchemaVersion","format","context","items","model","submitResponse","formStatus","formMetadata","csvFiles","extractCsvFiles","main","v2Main","v2Data","versionMetadata","def","meta","schemaVersion","V1","timestamp","Date","referenceNumber","formName","name","formId","id","formSlug","slug","status","state","isPreview","notificationEmail","language","translator","Object","fromEntries","entries","map","key","value","undefined","data","result","files","payload","JSON","stringify","repeaters"],"sources":["../../../../../../src/server/plugins/engine/outputFormatters/adapter/v1.ts"],"sourcesContent":["import {\n type FormMetadata,\n type SubmitResponsePayload\n} from '@defra/forms-model'\n\nimport { EN_GB } from '~/src/server/constants.js'\nimport {\n getFormVersion,\n type checkFormStatus\n} from '~/src/server/plugins/engine/helpers.js'\nimport { type FormModel } from '~/src/server/plugins/engine/models/FormModel.js'\nimport { type DetailItem } from '~/src/server/plugins/engine/models/types.js'\nimport { categoriseData } from '~/src/server/plugins/engine/outputFormatters/machine/v2.js'\nimport { FormAdapterSubmissionSchemaVersion } from '~/src/server/plugins/engine/types/enums.js'\nimport {\n type FormAdapterSubmissionMessageData,\n type FormAdapterSubmissionMessageMeta,\n type FormAdapterSubmissionMessagePayload,\n type FormAdapterSubmissionMessageResult,\n type FormContext\n} from '~/src/server/plugins/engine/types.js'\n\nexport function format(\n context: FormContext,\n items: DetailItem[],\n model: FormModel,\n submitResponse: SubmitResponsePayload,\n formStatus: ReturnType<typeof checkFormStatus>,\n formMetadata?: FormMetadata\n): string {\n const csvFiles = extractCsvFiles(submitResponse)\n\n const { main: v2Main, ...v2Data } = categoriseData(items)\n\n const versionMetadata = getFormVersion(model.def)\n\n const meta: FormAdapterSubmissionMessageMeta = {\n schemaVersion: FormAdapterSubmissionSchemaVersion.V1,\n timestamp: new Date(),\n referenceNumber: context.referenceNumber,\n formName: model.name,\n formId: formMetadata?.id ?? '',\n formSlug: formMetadata?.slug ?? '',\n status: formStatus.state,\n isPreview: formStatus.isPreview,\n notificationEmail: formMetadata?.notificationEmail ?? '',\n language: context.translator?.language ?? EN_GB\n }\n\n if (versionMetadata) {\n meta.versionMetadata = versionMetadata\n }\n\n const main = Object.fromEntries(\n Object.entries(v2Main).map(([key, value]) => {\n if (value === undefined) {\n return [key, null]\n }\n\n return [key, value]\n })\n )\n\n const data: FormAdapterSubmissionMessageData = {\n main,\n ...v2Data\n }\n\n const result: FormAdapterSubmissionMessageResult = {\n files: csvFiles\n }\n\n const payload: FormAdapterSubmissionMessagePayload = {\n meta,\n data,\n result\n }\n\n return JSON.stringify(payload)\n}\n\nfunction extractCsvFiles(\n submitResponse: SubmitResponsePayload\n): FormAdapterSubmissionMessageResult['files'] {\n const result =\n submitResponse.result as Partial<FormAdapterSubmissionMessageResult>\n\n return {\n main: result.files?.main ?? '',\n repeaters: result.files?.repeaters ?? {}\n }\n}\n"],"mappings":"AAKA,SAASA,KAAK;AACd,SACEC,cAAc;AAKhB,SAASC,cAAc;AACvB,SAASC,kCAAkC;AAS3C,OAAO,SAASC,MAAMA,CACpBC,OAAoB,EACpBC,KAAmB,EACnBC,KAAgB,EAChBC,cAAqC,EACrCC,UAA8C,EAC9CC,YAA2B,EACnB;EACR,MAAMC,QAAQ,GAAGC,eAAe,CAACJ,cAAc,CAAC;EAEhD,MAAM;IAAEK,IAAI,EAAEC,MAAM;IAAE,GAAGC;EAAO,CAAC,GAAGb,cAAc,CAACI,KAAK,CAAC;EAEzD,MAAMU,eAAe,GAAGf,cAAc,CAACM,KAAK,CAACU,GAAG,CAAC;EAEjD,MAAMC,IAAsC,GAAG;IAC7CC,aAAa,EAAEhB,kCAAkC,CAACiB,EAAE;IACpDC,SAAS,EAAE,IAAIC,IAAI,CAAC,CAAC;IACrBC,eAAe,EAAElB,OAAO,CAACkB,eAAe;IACxCC,QAAQ,EAAEjB,KAAK,CAACkB,IAAI;IACpBC,MAAM,EAAEhB,YAAY,EAAEiB,EAAE,IAAI,EAAE;IAC9BC,QAAQ,EAAElB,YAAY,EAAEmB,IAAI,IAAI,EAAE;IAClCC,MAAM,EAAErB,UAAU,CAACsB,KAAK;IACxBC,SAAS,EAAEvB,UAAU,CAACuB,SAAS;IAC/BC,iBAAiB,EAAEvB,YAAY,EAAEuB,iBAAiB,IAAI,EAAE;IACxDC,QAAQ,EAAE7B,OAAO,CAAC8B,UAAU,EAAED,QAAQ,IAAIlC;EAC5C,CAAC;EAED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