@defra/forms-engine-plugin 4.0.42 → 4.0.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.public/javascripts/shared.min.js +1 -1
- package/.public/javascripts/shared.min.js.map +1 -1
- package/.public/stylesheets/application.min.css +1 -1
- package/.public/stylesheets/application.min.css.map +1 -1
- package/.server/client/javascripts/location-map.js +8 -4
- package/.server/client/javascripts/location-map.js.map +1 -1
- package/.server/client/stylesheets/_payment-field.scss +8 -0
- package/.server/client/stylesheets/application.scss +2 -0
- package/.server/index.js +3 -1
- package/.server/index.js.map +1 -1
- package/.server/server/constants.d.ts +1 -0
- package/.server/server/constants.js +1 -0
- package/.server/server/constants.js.map +1 -1
- package/.server/server/forms/payment-test.yaml +42 -0
- package/.server/server/forms/register-as-a-unicorn-breeder.yaml +14 -0
- package/.server/server/plugins/engine/components/FormComponent.d.ts +1 -0
- package/.server/server/plugins/engine/components/FormComponent.js +1 -0
- package/.server/server/plugins/engine/components/FormComponent.js.map +1 -1
- package/.server/server/plugins/engine/components/PaymentField.d.ts +135 -0
- package/.server/server/plugins/engine/components/PaymentField.js +228 -0
- package/.server/server/plugins/engine/components/PaymentField.js.map +1 -0
- package/.server/server/plugins/engine/components/PaymentField.types.d.ts +21 -0
- package/.server/server/plugins/engine/components/PaymentField.types.js +2 -0
- package/.server/server/plugins/engine/components/PaymentField.types.js.map +1 -0
- package/.server/server/plugins/engine/components/UkAddressField.d.ts +1 -1
- package/.server/server/plugins/engine/components/UkAddressField.js +3 -1
- package/.server/server/plugins/engine/components/UkAddressField.js.map +1 -1
- package/.server/server/plugins/engine/components/helpers/components.d.ts +1 -1
- package/.server/server/plugins/engine/components/helpers/components.js +3 -0
- package/.server/server/plugins/engine/components/helpers/components.js.map +1 -1
- package/.server/server/plugins/engine/components/index.d.ts +1 -0
- package/.server/server/plugins/engine/components/index.js +1 -0
- package/.server/server/plugins/engine/components/index.js.map +1 -1
- package/.server/server/plugins/engine/configureEnginePlugin.d.ts +1 -1
- package/.server/server/plugins/engine/configureEnginePlugin.js +4 -2
- package/.server/server/plugins/engine/configureEnginePlugin.js.map +1 -1
- package/.server/server/plugins/engine/helpers.d.ts +1 -0
- package/.server/server/plugins/engine/models/SummaryViewModel.d.ts +3 -0
- package/.server/server/plugins/engine/models/SummaryViewModel.js +7 -0
- package/.server/server/plugins/engine/models/SummaryViewModel.js.map +1 -1
- package/.server/server/plugins/engine/options.js +2 -1
- package/.server/server/plugins/engine/options.js.map +1 -1
- package/.server/server/plugins/engine/outputFormatters/human/v1.js +34 -1
- package/.server/server/plugins/engine/outputFormatters/human/v1.js.map +1 -1
- package/.server/server/plugins/engine/outputFormatters/machine/v2.d.ts +22 -0
- package/.server/server/plugins/engine/outputFormatters/machine/v2.js +43 -1
- package/.server/server/plugins/engine/outputFormatters/machine/v2.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/QuestionPageController.js +29 -8
- package/.server/server/plugins/engine/pageControllers/QuestionPageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/StartPageController.d.ts +2 -0
- package/.server/server/plugins/engine/pageControllers/SummaryPageController.d.ts +17 -0
- package/.server/server/plugins/engine/pageControllers/SummaryPageController.js +173 -51
- package/.server/server/plugins/engine/pageControllers/SummaryPageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/errors.d.ts +31 -0
- package/.server/server/plugins/engine/pageControllers/errors.js +59 -2
- package/.server/server/plugins/engine/pageControllers/errors.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/helpers/submission.d.ts +27 -0
- package/.server/server/plugins/engine/pageControllers/helpers/submission.js +77 -0
- package/.server/server/plugins/engine/pageControllers/helpers/submission.js.map +1 -0
- package/.server/server/plugins/engine/plugin.js +10 -5
- package/.server/server/plugins/engine/plugin.js.map +1 -1
- package/.server/server/plugins/engine/routes/index.js +8 -4
- package/.server/server/plugins/engine/routes/index.js.map +1 -1
- package/.server/server/plugins/engine/routes/payment-helper.d.ts +14 -0
- package/.server/server/plugins/engine/routes/payment-helper.js +41 -0
- package/.server/server/plugins/engine/routes/payment-helper.js.map +1 -0
- package/.server/server/plugins/engine/routes/payment-helper.test.js +81 -0
- package/.server/server/plugins/engine/routes/payment-helper.test.js.map +1 -0
- package/.server/server/plugins/engine/routes/payment.d.ts +8 -0
- package/.server/server/plugins/engine/routes/payment.js +140 -0
- package/.server/server/plugins/engine/routes/payment.js.map +1 -0
- package/.server/server/plugins/engine/routes/payment.test.js +187 -0
- package/.server/server/plugins/engine/routes/payment.test.js.map +1 -0
- package/.server/server/plugins/engine/services/localFormsService.js +6 -0
- package/.server/server/plugins/engine/services/localFormsService.js.map +1 -1
- package/.server/server/plugins/engine/types/schema.js +7 -0
- package/.server/server/plugins/engine/types/schema.js.map +1 -1
- package/.server/server/plugins/engine/types.d.ts +20 -1
- package/.server/server/plugins/engine/types.js +4 -0
- package/.server/server/plugins/engine/types.js.map +1 -1
- package/.server/server/plugins/engine/validationHelpers.d.ts +1 -1
- package/.server/server/plugins/engine/validationHelpers.js.map +1 -1
- package/.server/server/plugins/engine/views/components/paymentfield.html +42 -0
- package/.server/server/plugins/engine/views/index.html +9 -1
- package/.server/server/plugins/engine/views/partials/form.html +20 -5
- package/.server/server/plugins/engine/views/summary.html +17 -1
- package/.server/server/plugins/map/routes/get-os-token.d.ts +6 -0
- package/.server/server/plugins/map/routes/get-os-token.js +41 -0
- package/.server/server/plugins/map/routes/get-os-token.js.map +1 -0
- package/.server/server/plugins/map/routes/get-os-token.test.js +49 -0
- package/.server/server/plugins/map/routes/get-os-token.test.js.map +1 -0
- package/.server/server/plugins/map/routes/index.d.ts +1 -11
- package/.server/server/plugins/map/routes/index.js +60 -16
- package/.server/server/plugins/map/routes/index.js.map +1 -1
- package/.server/server/plugins/map/types.d.ts +1 -0
- package/.server/server/plugins/map/types.js +1 -0
- package/.server/server/plugins/map/types.js.map +1 -1
- package/.server/server/plugins/nunjucks/filters/field.d.ts +1 -1
- package/.server/server/plugins/payment/helper.d.ts +30 -0
- package/.server/server/plugins/payment/helper.js +49 -0
- package/.server/server/plugins/payment/helper.js.map +1 -0
- package/.server/server/plugins/payment/helper.test.js +37 -0
- package/.server/server/plugins/payment/helper.test.js.map +1 -0
- package/.server/server/plugins/payment/service.d.ts +40 -0
- package/.server/server/plugins/payment/service.js +129 -0
- package/.server/server/plugins/payment/service.js.map +1 -0
- package/.server/server/plugins/payment/service.test.js +162 -0
- package/.server/server/plugins/payment/service.test.js.map +1 -0
- package/.server/server/plugins/payment/types.d.ts +172 -0
- package/.server/server/plugins/payment/types.js +78 -0
- package/.server/server/plugins/payment/types.js.map +1 -0
- package/.server/server/types.d.ts +3 -0
- package/.server/server/types.js.map +1 -1
- package/.server/typings/hapi/index.d.js.map +1 -1
- package/README.md +12 -9
- package/package.json +2 -2
- package/src/client/javascripts/location-map.js +12 -4
- package/src/client/stylesheets/_payment-field.scss +8 -0
- package/src/client/stylesheets/application.scss +2 -0
- package/src/index.ts +5 -1
- package/src/server/constants.js +1 -0
- package/src/server/forms/payment-test.yaml +42 -0
- package/src/server/forms/register-as-a-unicorn-breeder.yaml +14 -0
- package/src/server/plugins/engine/components/FormComponent.ts +1 -0
- package/src/server/plugins/engine/components/PaymentField.test.ts +611 -0
- package/src/server/plugins/engine/components/PaymentField.ts +367 -0
- package/src/server/plugins/engine/components/PaymentField.types.ts +21 -0
- package/src/server/plugins/engine/components/UkAddressField.ts +2 -1
- package/src/server/plugins/engine/components/helpers/components.ts +5 -0
- package/src/server/plugins/engine/components/index.ts +1 -0
- package/src/server/plugins/engine/configureEnginePlugin.ts +4 -2
- package/src/server/plugins/engine/models/SummaryViewModel.ts +8 -0
- package/src/server/plugins/engine/options.js +2 -1
- package/src/server/plugins/engine/outputFormatters/human/v1.payment.test.ts +147 -0
- package/src/server/plugins/engine/outputFormatters/human/v1.test.ts +105 -103
- package/src/server/plugins/engine/outputFormatters/human/v1.ts +61 -2
- package/src/server/plugins/engine/outputFormatters/machine/v2.payment.test.ts +115 -0
- package/src/server/plugins/engine/outputFormatters/machine/v2.ts +60 -1
- package/src/server/plugins/engine/pageControllers/QuestionPageController.ts +32 -6
- package/src/server/plugins/engine/pageControllers/SummaryPageController.ts +247 -72
- package/src/server/plugins/engine/pageControllers/errors.test.ts +13 -1
- package/src/server/plugins/engine/pageControllers/errors.ts +79 -4
- package/src/server/plugins/engine/pageControllers/helpers/submission.test.ts +299 -0
- package/src/server/plugins/engine/pageControllers/helpers/submission.ts +110 -0
- package/src/server/plugins/engine/plugin.ts +17 -10
- package/src/server/plugins/engine/routes/index.ts +17 -16
- package/src/server/plugins/engine/routes/payment-helper.js +39 -0
- package/src/server/plugins/engine/routes/payment-helper.test.js +90 -0
- package/src/server/plugins/engine/routes/payment.js +151 -0
- package/src/server/plugins/engine/routes/payment.test.js +180 -0
- package/src/server/plugins/engine/services/localFormsService.js +7 -0
- package/src/server/plugins/engine/types/schema.ts +9 -0
- package/src/server/plugins/engine/types.ts +25 -1
- package/src/server/plugins/engine/validationHelpers.ts +1 -1
- package/src/server/plugins/engine/views/components/paymentfield.html +42 -0
- package/src/server/plugins/engine/views/index.html +9 -1
- package/src/server/plugins/engine/views/partials/form.html +20 -5
- package/src/server/plugins/engine/views/summary.html +17 -1
- package/src/server/plugins/map/routes/get-os-token.js +41 -0
- package/src/server/plugins/map/routes/get-os-token.test.js +55 -0
- package/src/server/plugins/map/routes/index.js +70 -24
- package/src/server/plugins/map/types.js +1 -0
- package/src/server/plugins/payment/helper.js +56 -0
- package/src/server/plugins/payment/helper.test.js +52 -0
- package/src/server/plugins/payment/service.js +171 -0
- package/src/server/plugins/payment/service.test.js +205 -0
- package/src/server/plugins/payment/types.js +77 -0
- package/src/server/types.ts +3 -0
- package/src/typings/hapi/index.d.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureEnginePlugin.js","names":["join","parse","FORM_PREFIX","FormModel","plugin","defaultServices","formsService","findPackageRoot","devtoolContext","configureEnginePlugin","formFileName","formFilePath","services","controllers","preparePageEventRequestOptions","onRequest","saveAndExit","ordnanceSurveyApiKey","cache","model","definition","getForm","name","initialBasePath","basePath","options","nunjucks","baseLayoutPath","paths","viewContext","baseUrl","importPath","ext","attributes","type","formImport","with","default"],"sources":["../../../../src/server/plugins/engine/configureEnginePlugin.ts"],"sourcesContent":["import { join, parse } from 'node:path'\n\nimport { type FormDefinition } from '@defra/forms-model'\n\nimport { FORM_PREFIX } from '~/src/server/constants.js'\nimport { FormModel } from '~/src/server/plugins/engine/models/FormModel.js'\nimport { plugin } from '~/src/server/plugins/engine/plugin.js'\nimport * as defaultServices from '~/src/server/plugins/engine/services/index.js'\nimport { formsService } from '~/src/server/plugins/engine/services/localFormsService.js'\nimport { type PluginOptions } from '~/src/server/plugins/engine/types.js'\nimport { findPackageRoot } from '~/src/server/plugins/engine/vision.js'\nimport { devtoolContext } from '~/src/server/plugins/nunjucks/context.js'\nimport { type CacheService } from '~/src/server/services/cacheService.js'\nimport { type RouteConfig } from '~/src/server/types.js'\n\nexport const configureEnginePlugin = async (\n {\n formFileName,\n formFilePath,\n services,\n controllers,\n preparePageEventRequestOptions,\n onRequest,\n saveAndExit,\n ordnanceSurveyApiKey\n }: RouteConfig = {},\n cache?: CacheService\n): Promise<{\n plugin: typeof plugin\n options: PluginOptions\n}> => {\n let model: FormModel | undefined\n\n if (formFileName && formFilePath) {\n const definition = await getForm(join(formFilePath, formFileName))\n const { name } = parse(formFileName)\n\n const initialBasePath = `${FORM_PREFIX}${name}`\n\n model = new FormModel(\n definition,\n { basePath: initialBasePath, ordnanceSurveyApiKey },\n services,\n controllers\n )\n }\n\n return {\n plugin,\n options: {\n model,\n services: services ?? {\n // services for testing, else use the disk loader option for running this service locally\n ...defaultServices,\n formsService: await formsService()\n },\n controllers,\n cache: cache ?? 'session',\n nunjucks: {\n baseLayoutPath: 'dxt-devtool-baselayout.html',\n paths: [join(findPackageRoot(), 'src/server/devserver')] // custom layout to make it really clear this is not the same as the runner\n },\n viewContext: devtoolContext,\n preparePageEventRequestOptions,\n onRequest,\n baseUrl: 'http://localhost:3009', // always runs locally\n saveAndExit,\n ordnanceSurveyApiKey\n }\n }\n}\n\nexport async function getForm(importPath: string) {\n const { ext } = parse(importPath)\n\n const attributes: ImportAttributes = {\n type: ext === '.json' ? 'json' : 'module'\n }\n\n const formImport = import(importPath, { with: attributes }) as Promise<{\n default: FormDefinition\n }>\n\n const { default: definition } = await formImport\n return definition\n}\n"],"mappings":"AAAA,SAASA,IAAI,EAAEC,KAAK,QAAQ,WAAW;AAIvC,SAASC,WAAW;AACpB,SAASC,SAAS;AAClB,SAASC,MAAM;AACf,OAAO,KAAKC,eAAe;AAC3B,SAASC,YAAY;AAErB,SAASC,eAAe;AACxB,SAASC,cAAc;AAIvB,OAAO,MAAMC,qBAAqB,GAAG,MAAAA,CACnC;EACEC,YAAY;EACZC,YAAY;EACZC,QAAQ;EACRC,WAAW;EACXC,8BAA8B;EAC9BC,SAAS;EACTC,WAAW;EACXC;AACW,CAAC,GAAG,CAAC,CAAC,EACnBC,KAAoB,KAIhB;EACJ,IAAIC,KAA4B;EAEhC,
|
|
1
|
+
{"version":3,"file":"configureEnginePlugin.js","names":["join","parse","FORM_PREFIX","FormModel","plugin","defaultServices","formsService","findPackageRoot","devtoolContext","configureEnginePlugin","formFileName","formFilePath","services","controllers","preparePageEventRequestOptions","onRequest","saveAndExit","ordnanceSurveyApiKey","ordnanceSurveyApiSecret","cache","model","definition","getForm","name","initialBasePath","basePath","options","nunjucks","baseLayoutPath","paths","viewContext","baseUrl","importPath","ext","attributes","type","formImport","with","default"],"sources":["../../../../src/server/plugins/engine/configureEnginePlugin.ts"],"sourcesContent":["import { join, parse } from 'node:path'\n\nimport { type FormDefinition } from '@defra/forms-model'\n\nimport { FORM_PREFIX } from '~/src/server/constants.js'\nimport { FormModel } from '~/src/server/plugins/engine/models/FormModel.js'\nimport { plugin } from '~/src/server/plugins/engine/plugin.js'\nimport * as defaultServices from '~/src/server/plugins/engine/services/index.js'\nimport { formsService } from '~/src/server/plugins/engine/services/localFormsService.js'\nimport { type PluginOptions } from '~/src/server/plugins/engine/types.js'\nimport { findPackageRoot } from '~/src/server/plugins/engine/vision.js'\nimport { devtoolContext } from '~/src/server/plugins/nunjucks/context.js'\nimport { type CacheService } from '~/src/server/services/cacheService.js'\nimport { type RouteConfig } from '~/src/server/types.js'\n\nexport const configureEnginePlugin = async (\n {\n formFileName,\n formFilePath,\n services,\n controllers,\n preparePageEventRequestOptions,\n onRequest,\n saveAndExit,\n ordnanceSurveyApiKey,\n ordnanceSurveyApiSecret\n }: RouteConfig = {},\n cache?: CacheService\n): Promise<{\n plugin: typeof plugin\n options: PluginOptions\n}> => {\n let model: FormModel | undefined\n\n if (formFileName && formFilePath) {\n const definition = await getForm(join(formFilePath, formFileName))\n const { name } = parse(formFileName)\n\n const initialBasePath = `${FORM_PREFIX}${name}`\n\n model = new FormModel(\n definition,\n { basePath: initialBasePath, ordnanceSurveyApiKey },\n services,\n controllers\n )\n }\n\n return {\n plugin,\n options: {\n model,\n services: services ?? {\n // services for testing, else use the disk loader option for running this service locally\n ...defaultServices,\n formsService: await formsService()\n },\n controllers,\n cache: cache ?? 'session',\n nunjucks: {\n baseLayoutPath: 'dxt-devtool-baselayout.html',\n paths: [join(findPackageRoot(), 'src/server/devserver')] // custom layout to make it really clear this is not the same as the runner\n },\n viewContext: devtoolContext,\n preparePageEventRequestOptions,\n onRequest,\n baseUrl: 'http://localhost:3009', // always runs locally\n saveAndExit,\n ordnanceSurveyApiKey,\n ordnanceSurveyApiSecret\n }\n }\n}\n\nexport async function getForm(importPath: string) {\n const { ext } = parse(importPath)\n\n const attributes: ImportAttributes = {\n type: ext === '.json' ? 'json' : 'module'\n }\n\n const formImport = import(importPath, { with: attributes }) as Promise<{\n default: FormDefinition\n }>\n\n const { default: definition } = await formImport\n return definition\n}\n"],"mappings":"AAAA,SAASA,IAAI,EAAEC,KAAK,QAAQ,WAAW;AAIvC,SAASC,WAAW;AACpB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F,CAAC;AACH,CAAC;AAED,OAAO,eAAeI,OAAOA,CAACU,UAAkB,EAAE;EAChD,MAAM;IAAEC;EAAI,CAAC,GAAGhC,KAAK,CAAC+B,UAAU,CAAC;EAEjC,MAAME,UAA4B,GAAG;IACnCC,IAAI,EAAEF,GAAG,KAAK,OAAO,GAAG,MAAM,GAAG;EACnC,CAAC;EAED,MAAMG,UAAU,GAAG,MAAM,CAACJ,UAAU,EAAE;IAAEK,IAAI,EAAEH;EAAW,CAAC,CAExD;EAEF,MAAM;IAAEI,OAAO,EAAEjB;EAAW,CAAC,GAAG,MAAMe,UAAU;EAChD,OAAOf,UAAU;AACnB","ignoreList":[]}
|
|
@@ -71,6 +71,7 @@ export declare function getPluginOptions(server: Server): {
|
|
|
71
71
|
cacheService: import("../../services/cacheService.js").CacheService;
|
|
72
72
|
viewContext?: (request: AnyFormRequest | null) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
73
73
|
saveAndExit?: import("~/src/server/plugins/engine/types.js").PluginOptions["saveAndExit"];
|
|
74
|
+
baseUrl: string;
|
|
74
75
|
};
|
|
75
76
|
/**
|
|
76
77
|
* Handles logging and issuing a permanent redirect for legacy routes.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PaymentState } from '~/src/server/plugins/engine/components/PaymentField.types.js';
|
|
1
2
|
import { type Field } from '~/src/server/plugins/engine/components/helpers/components.js';
|
|
2
3
|
import { type BackLink, type ComponentViewModel } from '~/src/server/plugins/engine/components/types.js';
|
|
3
4
|
import { type Detail, type DetailItemField } from '~/src/server/plugins/engine/models/types.js';
|
|
@@ -22,6 +23,8 @@ export declare class SummaryViewModel {
|
|
|
22
23
|
hasMissingNotificationEmail?: boolean;
|
|
23
24
|
components?: ComponentViewModel[];
|
|
24
25
|
allowSaveAndExit: boolean;
|
|
26
|
+
paymentState?: PaymentState;
|
|
27
|
+
paymentDetails?: CheckAnswers;
|
|
25
28
|
constructor(request: FormContextRequest, page: PageControllerClass, context: FormContext);
|
|
26
29
|
private summaryDetails;
|
|
27
30
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SchemaVersion } from '@defra/forms-model';
|
|
2
|
+
import { PaymentField } from "../components/PaymentField.js";
|
|
2
3
|
import { getAnswer } from "../components/helpers/components.js";
|
|
3
4
|
import { evaluateTemplate, getError, getPageHref } from "../helpers.js";
|
|
4
5
|
import { RepeatPageController } from "../pageControllers/RepeatPageController.js";
|
|
@@ -23,6 +24,8 @@ export class SummaryViewModel {
|
|
|
23
24
|
hasMissingNotificationEmail;
|
|
24
25
|
components;
|
|
25
26
|
allowSaveAndExit = false;
|
|
27
|
+
paymentState;
|
|
28
|
+
paymentDetails;
|
|
26
29
|
constructor(request, page, context) {
|
|
27
30
|
const {
|
|
28
31
|
model
|
|
@@ -118,6 +121,10 @@ export class SummaryViewModel {
|
|
|
118
121
|
}));
|
|
119
122
|
} else {
|
|
120
123
|
for (const field of collection.fields) {
|
|
124
|
+
// PaymentField is rendered in its own section, skip it here
|
|
125
|
+
if (field instanceof PaymentField) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
121
128
|
items.push(ItemField(page, state, field, {
|
|
122
129
|
path,
|
|
123
130
|
errors
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SummaryViewModel.js","names":["SchemaVersion","getAnswer","evaluateTemplate","getError","getPageHref","RepeatPageController","validationOptions","opts","SummaryViewModel","page","pageTitle","declaration","details","checkAnswers","context","name","backLink","feedbackLink","phaseTag","errors","serviceUrl","hasMissingNotificationEmail","components","allowSaveAndExit","constructor","request","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","options","repeat","values","getListFromState","unit","returnUrl","subItems","repeatState","required","getFirstError"],"sources":["../../../../../src/server/plugins/engine/models/SummaryViewModel.ts"],"sourcesContent":["import { SchemaVersion, type Section } from '@defra/forms-model'\n\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 {\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\n constructor(\n request: FormContextRequest,\n page: PageControllerClass,\n context: FormContext\n ) {\n const { model } = page\n const { basePath, def, sections } = model\n const { isForceAccess } = context\n\n this.page = page\n this.pageTitle = page.title\n if (def.schema === SchemaVersion.V2 && !page.title) {\n this.pageTitle = 'Check your answers before sending your form'\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)\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: '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 || 'Not provided'\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(request: FormContextRequest, sections: Section[]) {\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(page, state, {\n path: page.getSummaryPath(request),\n errors\n })\n )\n } else {\n for (const field of collection.fields) {\n items.push(ItemField(page, state, field, { path, errors }))\n }\n }\n })\n\n if (items.length) {\n details.push({\n name: section?.name,\n title: section?.title,\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): DetailItemRepeat {\n const { collection, repeat } = page\n const { name, title } = repeat.options\n\n const values = page.getListFromState(state)\n const unit = values.length === 1 ? title : `${title}s`\n\n return {\n name,\n label: title,\n title: values.length ? `${unit} added` : unit,\n value: values.length ? `You added ${values.length} ${unit}` : '',\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)\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): DetailItemField {\n return {\n name: field.name,\n label: field.title,\n title:\n field.options.required === false\n ? `${field.label} (optional)`\n : field.label,\n error: field.getFirstError(options.errors),\n value: getAnswer(field, state),\n href: getPageHref(page, options.path, {\n returnUrl: getPageHref(page, page.getSummaryPath())\n }),\n state,\n page,\n field\n }\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAsB,oBAAoB;AAEhE,SACEC,SAAS;AAOX,SACEC,gBAAgB,EAChBC,QAAQ,EACRC,WAAW;AAQb,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;EAExBC,WAAWA,CACTC,OAA2B,EAC3BhB,IAAyB,EACzBK,OAAoB,EACpB;IACA,MAAM;MAAEY;IAAM,CAAC,GAAGjB,IAAI;IACtB,MAAM;MAAEkB,QAAQ;MAAEC,GAAG;MAAEC;IAAS,CAAC,GAAGH,KAAK;IACzC,MAAM;MAAEI;IAAc,CAAC,GAAGhB,OAAO;IAEjC,IAAI,CAACL,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,SAAS,GAAGD,IAAI,CAACsB,KAAK;IAC3B,IAAIH,GAAG,CAACI,MAAM,KAAKhC,aAAa,CAACiC,EAAE,IAAI,CAACxB,IAAI,CAACsB,KAAK,EAAE;MAClD,IAAI,CAACrB,SAAS,G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AI,EAAEsE,WAAW,EAAEX,KAAK,EAAEI,OAAO,CAC7C,CACF;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASF,SAASA,CACvB7D,IAAyB,EACzBkD,KAAgB,EAChBS,KAAY,EACZI,OAGC,EACgB;EACjB,OAAO;IACLzD,IAAI,EAAEqD,KAAK,CAACrD,IAAI;IAChBqC,KAAK,EAAEgB,KAAK,CAACrC,KAAK;IAClBA,KAAK,EACHqC,KAAK,CAACI,OAAO,CAACQ,QAAQ,KAAK,KAAK,GAC5B,GAAGZ,KAAK,CAAChB,KAAK,aAAa,GAC3BgB,KAAK,CAAChB,KAAK;IACjBZ,KAAK,EAAE4B,KAAK,CAACa,aAAa,CAACT,OAAO,CAACrD,MAAM,CAAC;IAC1CmC,KAAK,EAAErD,SAAS,CAACmE,KAAK,EAAET,KAAK,CAAC;IAC9BX,IAAI,EAAE5C,WAAW,CAACK,IAAI,EAAE+D,OAAO,CAACP,IAAI,EAAE;MACpCY,SAAS,EAAEzE,WAAW,CAACK,IAAI,EAAEA,IAAI,CAAC0D,cAAc,CAAC,CAAC;IACpD,CAAC,CAAC;IACFR,KAAK;IACLlD,IAAI;IACJ2D;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","constructor","request","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","options","repeat","values","getListFromState","unit","returnUrl","subItems","repeatState","required","getFirstError"],"sources":["../../../../../src/server/plugins/engine/models/SummaryViewModel.ts"],"sourcesContent":["import { SchemaVersion, type Section } 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 {\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\n constructor(\n request: FormContextRequest,\n page: PageControllerClass,\n context: FormContext\n ) {\n const { model } = page\n const { basePath, def, sections } = model\n const { isForceAccess } = context\n\n this.page = page\n this.pageTitle = page.title\n if (def.schema === SchemaVersion.V2 && !page.title) {\n this.pageTitle = 'Check your answers before sending your form'\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)\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: '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 || 'Not provided'\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(request: FormContextRequest, sections: Section[]) {\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(page, state, {\n path: page.getSummaryPath(request),\n errors\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(ItemField(page, state, field, { path, errors }))\n }\n }\n })\n\n if (items.length) {\n details.push({\n name: section?.name,\n title: section?.title,\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): DetailItemRepeat {\n const { collection, repeat } = page\n const { name, title } = repeat.options\n\n const values = page.getListFromState(state)\n const unit = values.length === 1 ? title : `${title}s`\n\n return {\n name,\n label: title,\n title: values.length ? `${unit} added` : unit,\n value: values.length ? `You added ${values.length} ${unit}` : '',\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)\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): DetailItemField {\n return {\n name: field.name,\n label: field.title,\n title:\n field.options.required === false\n ? `${field.label} (optional)`\n : field.label,\n error: field.getFirstError(options.errors),\n value: getAnswer(field, state),\n href: getPageHref(page, options.path, {\n returnUrl: getPageHref(page, page.getSummaryPath())\n }),\n state,\n page,\n field\n }\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAsB,oBAAoB;AAEhE,SAASC,YAAY;AAErB,SACEC,SAAS;AAOX,SACEC,gBAAgB,EAChBC,QAAQ,EACRC,WAAW;AAQb,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;EAEdC,WAAWA,CACTC,OAA2B,EAC3BlB,IAAyB,EACzBK,OAAoB,EACpB;IACA,MAAM;MAAEc;IAAM,CAAC,GAAGnB,IAAI;IACtB,MAAM;MAAEoB,QAAQ;MAAEC,GAAG;MAAEC;IAAS,CAAC,GAAGH,KAAK;IACzC,MAAM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AAI,EAAEiE,OAAO,CAACP,IAAI,EAAE;MACpCY,SAAS,EAAE3E,WAAW,CAACK,IAAI,EAAEA,IAAI,CAAC4D,cAAc,CAAC,CAAC;IACpD,CAAC,CAAC;IACFR,KAAK;IACLpD,IAAI;IAEJ;IACAuE,QAAQ,EAAEJ,MAAM,CAACjC,GAAG,CAAEsC,WAAW,IAC/Bf,UAAU,CAACK,MAAM,CAAC5B,GAAG,CAAE2B,KAAK,IAC1BE,SAAS,CAAC/D,IAAI,EAAEwE,WAAW,EAAEX,KAAK,EAAEI,OAAO,CAC7C,CACF;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASF,SAASA,CACvB/D,IAAyB,EACzBoD,KAAgB,EAChBS,KAAY,EACZI,OAGC,EACgB;EACjB,OAAO;IACL3D,IAAI,EAAEuD,KAAK,CAACvD,IAAI;IAChBuC,KAAK,EAAEgB,KAAK,CAACrC,KAAK;IAClBA,KAAK,EACHqC,KAAK,CAACI,OAAO,CAACQ,QAAQ,KAAK,KAAK,GAC5B,GAAGZ,KAAK,CAAChB,KAAK,aAAa,GAC3BgB,KAAK,CAAChB,KAAK;IACjBZ,KAAK,EAAE4B,KAAK,CAACa,aAAa,CAACT,OAAO,CAACvD,MAAM,CAAC;IAC1CqC,KAAK,EAAEvD,SAAS,CAACqE,KAAK,EAAET,KAAK,CAAC;IAC9BX,IAAI,EAAE9C,WAAW,CAACK,IAAI,EAAEiE,OAAO,CAACP,IAAI,EAAE;MACpCY,SAAS,EAAE3E,WAAW,CAACK,IAAI,EAAEA,IAAI,CAAC4D,cAAc,CAAC,CAAC;IACpD,CAAC,CAAC;IACFR,KAAK;IACLpD,IAAI;IACJ6D;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -20,7 +20,8 @@ const pluginRegistrationOptionsSchema = Joi.object({
|
|
|
20
20
|
onRequest: Joi.function().optional(),
|
|
21
21
|
baseUrl: Joi.string().uri().required(),
|
|
22
22
|
saveAndExit: Joi.function().optional(),
|
|
23
|
-
ordnanceSurveyApiKey: Joi.string().optional()
|
|
23
|
+
ordnanceSurveyApiKey: Joi.string().optional(),
|
|
24
|
+
ordnanceSurveyApiSecret: Joi.string().optional()
|
|
24
25
|
});
|
|
25
26
|
|
|
26
27
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","names":["getErrorMessage","Joi","createLogger","CacheService","logger","pluginRegistrationOptionsSchema","object","model","optional","services","controllers","pattern","string","any","cache","alternatives","try","instance","globals","filters","pluginPath","nunjucks","baseLayoutPath","required","paths","array","items","viewContext","function","preparePageEventRequestOptions","onRequest","baseUrl","uri","saveAndExit","ordnanceSurveyApiKey","validatePluginOptions","options","result","validate","abortEarly","error","Error","value"],"sources":["../../../../src/server/plugins/engine/options.js"],"sourcesContent":["import { getErrorMessage } from '@defra/forms-model'\nimport Joi from 'joi'\n\nimport { createLogger } from '~/src/server/common/helpers/logging/logger.js'\nimport { CacheService } from '~/src/server/services/index.js'\n\nconst logger = createLogger()\n\nconst pluginRegistrationOptionsSchema = Joi.object({\n model: Joi.object().optional(),\n services: Joi.object().optional(),\n controllers: Joi.object().pattern(Joi.string(), Joi.any()).optional(),\n cache: Joi.alternatives().try(\n Joi.object().instance(CacheService),\n Joi.string()\n ),\n globals: Joi.object().pattern(Joi.string(), Joi.any()).optional(),\n filters: Joi.object().pattern(Joi.string(), Joi.any()).optional(),\n pluginPath: Joi.string().optional(),\n nunjucks: Joi.object({\n baseLayoutPath: Joi.string().required(),\n paths: Joi.array().items(Joi.string()).required()\n }).required(),\n viewContext: Joi.function().required(),\n preparePageEventRequestOptions: Joi.function().optional(),\n onRequest: Joi.function().optional(),\n baseUrl: Joi.string().uri().required(),\n saveAndExit: Joi.function().optional(),\n ordnanceSurveyApiKey: Joi.string().optional()\n})\n\n/**\n * Validates the plugin options against the schema and returns the validated value.\n * @param {PluginOptions} options\n * @returns {PluginOptions}\n */\nexport function validatePluginOptions(options) {\n const result = pluginRegistrationOptionsSchema.validate(options, {\n abortEarly: false\n })\n\n if (result.error) {\n logger.error(\n result.error,\n `Missing required properties in plugin options: ${getErrorMessage(result.error)}`\n )\n throw new Error('Invalid plugin options', result.error)\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result.value\n}\n\n/**\n * @import { PluginOptions } from '~/src/server/plugins/engine/types.js'\n */\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,oBAAoB;AACpD,OAAOC,GAAG,MAAM,KAAK;AAErB,SAASC,YAAY;AACrB,SAASC,YAAY;AAErB,MAAMC,MAAM,GAAGF,YAAY,CAAC,CAAC;AAE7B,MAAMG,+BAA+B,GAAGJ,GAAG,CAACK,MAAM,CAAC;EACjDC,KAAK,EAAEN,GAAG,CAACK,MAAM,CAAC,CAAC,CAACE,QAAQ,CAAC,CAAC;EAC9BC,QAAQ,EAAER,GAAG,CAACK,MAAM,CAAC,CAAC,CAACE,QAAQ,CAAC,CAAC;EACjCE,WAAW,EAAET,GAAG,CAACK,MAAM,CAAC,CAAC,CAACK,OAAO,CAACV,GAAG,CAACW,MAAM,CAAC,CAAC,EAAEX,GAAG,CAACY,GAAG,CAAC,CAAC,CAAC,CAACL,QAAQ,CAAC,CAAC;EACrEM,KAAK,EAAEb,GAAG,CAACc,YAAY,CAAC,CAAC,CAACC,GAAG,CAC3Bf,GAAG,CAACK,MAAM,CAAC,CAAC,CAACW,QAAQ,CAACd,YAAY,CAAC,EACnCF,GAAG,CAACW,MAAM,CAAC,CACb,CAAC;EACDM,OAAO,EAAEjB,GAAG,CAACK,MAAM,CAAC,CAAC,CAACK,OAAO,CAACV,GAAG,CAACW,MAAM,CAAC,CAAC,EAAEX,GAAG,CAACY,GAAG,CAAC,CAAC,CAAC,CAACL,QAAQ,CAAC,CAAC;EACjEW,OAAO,EAAElB,GAAG,CAACK,MAAM,CAAC,CAAC,CAACK,OAAO,CAACV,GAAG,CAACW,MAAM,CAAC,CAAC,EAAEX,GAAG,CAACY,GAAG,CAAC,CAAC,CAAC,CAACL,QAAQ,CAAC,CAAC;EACjEY,UAAU,EAAEnB,GAAG,CAACW,MAAM,CAAC,CAAC,CAACJ,QAAQ,CAAC,CAAC;EACnCa,QAAQ,EAAEpB,GAAG,CAACK,MAAM,CAAC;IACnBgB,cAAc,EAAErB,GAAG,CAACW,MAAM,CAAC,CAAC,CAACW,QAAQ,CAAC,CAAC;IACvCC,KAAK,EAAEvB,GAAG,CAACwB,KAAK,CAAC,CAAC,CAACC,KAAK,CAACzB,GAAG,CAACW,MAAM,CAAC,CAAC,CAAC,CAACW,QAAQ,CAAC;EAClD,CAAC,CAAC,CAACA,QAAQ,CAAC,CAAC;EACbI,WAAW,EAAE1B,GAAG,CAAC2B,QAAQ,CAAC,CAAC,CAACL,QAAQ,CAAC,CAAC;EACtCM,8BAA8B,EAAE5B,GAAG,CAAC2B,QAAQ,CAAC,CAAC,CAACpB,QAAQ,CAAC,CAAC;EACzDsB,SAAS,EAAE7B,GAAG,CAAC2B,QAAQ,CAAC,CAAC,CAACpB,QAAQ,CAAC,CAAC;EACpCuB,OAAO,EAAE9B,GAAG,CAACW,MAAM,CAAC,CAAC,CAACoB,GAAG,CAAC,CAAC,CAACT,QAAQ,CAAC,CAAC;EACtCU,WAAW,EAAEhC,GAAG,CAAC2B,QAAQ,CAAC,CAAC,CAACpB,QAAQ,CAAC,CAAC;EACtC0B,oBAAoB,EAAEjC,GAAG,CAACW,MAAM,CAAC,CAAC,CAACJ,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"options.js","names":["getErrorMessage","Joi","createLogger","CacheService","logger","pluginRegistrationOptionsSchema","object","model","optional","services","controllers","pattern","string","any","cache","alternatives","try","instance","globals","filters","pluginPath","nunjucks","baseLayoutPath","required","paths","array","items","viewContext","function","preparePageEventRequestOptions","onRequest","baseUrl","uri","saveAndExit","ordnanceSurveyApiKey","ordnanceSurveyApiSecret","validatePluginOptions","options","result","validate","abortEarly","error","Error","value"],"sources":["../../../../src/server/plugins/engine/options.js"],"sourcesContent":["import { getErrorMessage } from '@defra/forms-model'\nimport Joi from 'joi'\n\nimport { createLogger } from '~/src/server/common/helpers/logging/logger.js'\nimport { CacheService } from '~/src/server/services/index.js'\n\nconst logger = createLogger()\n\nconst pluginRegistrationOptionsSchema = Joi.object({\n model: Joi.object().optional(),\n services: Joi.object().optional(),\n controllers: Joi.object().pattern(Joi.string(), Joi.any()).optional(),\n cache: Joi.alternatives().try(\n Joi.object().instance(CacheService),\n Joi.string()\n ),\n globals: Joi.object().pattern(Joi.string(), Joi.any()).optional(),\n filters: Joi.object().pattern(Joi.string(), Joi.any()).optional(),\n pluginPath: Joi.string().optional(),\n nunjucks: Joi.object({\n baseLayoutPath: Joi.string().required(),\n paths: Joi.array().items(Joi.string()).required()\n }).required(),\n viewContext: Joi.function().required(),\n preparePageEventRequestOptions: Joi.function().optional(),\n onRequest: Joi.function().optional(),\n baseUrl: Joi.string().uri().required(),\n saveAndExit: Joi.function().optional(),\n ordnanceSurveyApiKey: Joi.string().optional(),\n ordnanceSurveyApiSecret: Joi.string().optional()\n})\n\n/**\n * Validates the plugin options against the schema and returns the validated value.\n * @param {PluginOptions} options\n * @returns {PluginOptions}\n */\nexport function validatePluginOptions(options) {\n const result = pluginRegistrationOptionsSchema.validate(options, {\n abortEarly: false\n })\n\n if (result.error) {\n logger.error(\n result.error,\n `Missing required properties in plugin options: ${getErrorMessage(result.error)}`\n )\n throw new Error('Invalid plugin options', result.error)\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result.value\n}\n\n/**\n * @import { PluginOptions } from '~/src/server/plugins/engine/types.js'\n */\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,oBAAoB;AACpD,OAAOC,GAAG,MAAM,KAAK;AAErB,SAASC,YAAY;AACrB,SAASC,YAAY;AAErB,MAAMC,MAAM,GAAGF,YAAY,CAAC,CAAC;AAE7B,MAAMG,+BAA+B,GAAGJ,GAAG,CAACK,MAAM,CAAC;EACjDC,KAAK,EAAEN,GAA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CAACL,QAAQ,CAAC,CAAC;EACtCM,8BAA8B,EAAE5B,GAAG,CAAC2B,QAAQ,CAAC,CAAC,CAACpB,QAAQ,CAAC,CAAC;EACzDsB,SAAS,EAAE7B,GAAG,CAAC2B,QAAQ,CAAC,CAAC,CAACpB,QAAQ,CAAC,CAAC;EACpCuB,OAAO,EAAE9B,GAAG,CAACW,MAAM,CAAC,CAAC,CAACoB,GAAG,CAAC,CAAC,CAACT,QAAQ,CAAC,CAAC;EACtCU,WAAW,EAAEhC,GAAG,CAAC2B,QAAQ,CAAC,CAAC,CAACpB,QAAQ,CAAC,CAAC;EACtC0B,oBAAoB,EAAEjC,GAAG,CAACW,MAAM,CAAC,CAAC,CAACJ,QAAQ,CAAC,CAAC;EAC7C2B,uBAAuB,EAAElC,GAAG,CAACW,MAAM,CAAC,CAAC,CAACJ,QAAQ,CAAC;AACjD,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS4B,qBAAqBA,CAACC,OAAO,EAAE;EAC7C,MAAMC,MAAM,GAAGjC,+BAA+B,CAACkC,QAAQ,CAACF,OAAO,EAAE;IAC/DG,UAAU,EAAE;EACd,CAAC,CAAC;EAEF,IAAIF,MAAM,CAACG,KAAK,EAAE;IAChBrC,MAAM,CAACqC,KAAK,CACVH,MAAM,CAACG,KAAK,EACZ,kDAAkDzC,eAAe,CAACsC,MAAM,CAACG,KAAK,CAAC,EACjF,CAAC;IACD,MAAM,IAAIC,KAAK,CAAC,wBAAwB,EAAEJ,MAAM,CAACG,KAAK,CAAC;EACzD;;EAEA;EACA,OAAOH,MAAM,CAACK,KAAK;AACrB;;AAEA;AACA;AACA","ignoreList":[]}
|
|
@@ -2,6 +2,8 @@ import { addDays, format as dateFormat } from 'date-fns';
|
|
|
2
2
|
import { config } from "../../../../../config/index.js";
|
|
3
3
|
import { getAnswer } from "../../components/helpers/components.js";
|
|
4
4
|
import { escapeMarkdown } from "../../components/helpers/index.js";
|
|
5
|
+
import { PaymentField } from "../../components/index.js";
|
|
6
|
+
import { formatPaymentAmount, formatPaymentDate } from "../../../payment/helper.js";
|
|
5
7
|
const designerUrl = config.get('designerUrl');
|
|
6
8
|
export function format(_context, items, model, submitResponse, formStatus, _formMetadata) {
|
|
7
9
|
const {
|
|
@@ -24,7 +26,9 @@ export function format(_context, items, model, submitResponse, formStatus, _form
|
|
|
24
26
|
}
|
|
25
27
|
lines.push(`${formName} form received at ${escapeMarkdown(formattedNow)}.\n`);
|
|
26
28
|
lines.push('---\n');
|
|
27
|
-
items.
|
|
29
|
+
const regularItems = items.filter(item => !isPaymentItem(item));
|
|
30
|
+
const paymentItems = items.filter(item => isPaymentItem(item));
|
|
31
|
+
regularItems.forEach(item => {
|
|
28
32
|
const label = escapeMarkdown(item.label);
|
|
29
33
|
lines.push(`## ${label}\n`);
|
|
30
34
|
if ('subItems' in item) {
|
|
@@ -40,6 +44,35 @@ export function format(_context, items, model, submitResponse, formStatus, _form
|
|
|
40
44
|
});
|
|
41
45
|
const filename = escapeMarkdown('Download main form (CSV)');
|
|
42
46
|
lines.push(`[${filename}](${designerUrl}/file-download/${files.main})\n`);
|
|
47
|
+
appendPaymentSection(paymentItems, lines);
|
|
43
48
|
return lines.join('\n');
|
|
44
49
|
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Check if an item is a PaymentField
|
|
53
|
+
*/
|
|
54
|
+
function isPaymentItem(item) {
|
|
55
|
+
if ('subItems' in item) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return item.field instanceof PaymentField;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Appends the payment details section to the email lines if payment exists
|
|
63
|
+
*/
|
|
64
|
+
function appendPaymentSection(paymentItems, lines) {
|
|
65
|
+
if (paymentItems.length === 0) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const paymentItem = paymentItems[0];
|
|
69
|
+
const paymentField = paymentItem.field;
|
|
70
|
+
const paymentState = paymentField.getPaymentStateFromState(paymentItem.state);
|
|
71
|
+
if (!paymentState) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const formattedAmount = formatPaymentAmount(paymentState.amount);
|
|
75
|
+
const dateOfPayment = paymentState.preAuth?.createdAt ? formatPaymentDate(paymentState.preAuth.createdAt) : '';
|
|
76
|
+
lines.push('---\n', `# Your payment of ${formattedAmount} was successful\n`, '## Payment for\n', `${escapeMarkdown(paymentState.description)}\n`, '---\n', '## Total amount\n', `${formattedAmount}\n`, '---\n', '## Date of payment\n', `${escapeMarkdown(dateOfPayment)}\n`, '---\n');
|
|
77
|
+
}
|
|
45
78
|
//# sourceMappingURL=v1.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v1.js","names":["addDays","format","dateFormat","config","getAnswer","escapeMarkdown","designerUrl","get","_context","items","model","submitResponse","formStatus","_formMetadata","files","result","formName","name","now","Date","formattedNow","fileExpiryDate","formattedExpiryDate","lines","push","isPreview","state","
|
|
1
|
+
{"version":3,"file":"v1.js","names":["addDays","format","dateFormat","config","getAnswer","escapeMarkdown","PaymentField","formatPaymentAmount","formatPaymentDate","designerUrl","get","_context","items","model","submitResponse","formStatus","_formMetadata","files","result","formName","name","now","Date","formattedNow","fileExpiryDate","formattedExpiryDate","lines","push","isPreview","state","regularItems","filter","item","isPaymentItem","paymentItems","forEach","label","filename","fileId","repeaters","field","main","appendPaymentSection","join","length","paymentItem","paymentField","paymentState","getPaymentStateFromState","formattedAmount","amount","dateOfPayment","preAuth","createdAt","description"],"sources":["../../../../../../src/server/plugins/engine/outputFormatters/human/v1.ts"],"sourcesContent":["import {\n type FormMetadata,\n type SubmitResponsePayload\n} from '@defra/forms-model'\nimport { addDays, format as dateFormat } from 'date-fns'\n\nimport { config } from '~/src/config/index.js'\nimport { getAnswer } from '~/src/server/plugins/engine/components/helpers/components.js'\nimport { escapeMarkdown } from '~/src/server/plugins/engine/components/helpers/index.js'\nimport { PaymentField } from '~/src/server/plugins/engine/components/index.js'\nimport { type checkFormStatus } from '~/src/server/plugins/engine/helpers.js'\nimport { type FormModel } from '~/src/server/plugins/engine/models/index.js'\nimport {\n type DetailItem,\n type DetailItemField\n} from '~/src/server/plugins/engine/models/types.js'\nimport { type FormContext } from '~/src/server/plugins/engine/types.js'\nimport {\n formatPaymentAmount,\n formatPaymentDate\n} from '~/src/server/plugins/payment/helper.js'\n\nconst designerUrl = config.get('designerUrl')\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) {\n const { files } = submitResponse.result\n\n const formName = escapeMarkdown(model.name)\n\n /**\n * @todo Refactor this below but the code to\n * generate the question and answers works for now\n */\n const now = new Date()\n const formattedNow = `${dateFormat(now, 'h:mmaaa')} on ${dateFormat(now, 'd MMMM yyyy')}`\n\n const fileExpiryDate = addDays(now, 90)\n const formattedExpiryDate = `${dateFormat(fileExpiryDate, 'h:mmaaa')} on ${dateFormat(fileExpiryDate, 'eeee d MMMM yyyy')}`\n\n const lines: string[] = []\n\n lines.push(\n `^ For security reasons, the links in this email expire at ${escapeMarkdown(formattedExpiryDate)}\\n`\n )\n\n if (formStatus.isPreview) {\n lines.push(`This is a test of the ${formName} ${formStatus.state} form.\\n`)\n }\n\n lines.push(`${formName} form received at ${escapeMarkdown(formattedNow)}.\\n`)\n lines.push('---\\n')\n\n const regularItems = items.filter((item) => !isPaymentItem(item))\n const paymentItems = items.filter((item) => isPaymentItem(item))\n\n regularItems.forEach((item) => {\n const label = escapeMarkdown(item.label)\n\n lines.push(`## ${label}\\n`)\n\n if ('subItems' in item) {\n const filename = escapeMarkdown(`Download ${label} (CSV)`)\n const fileId = files.repeaters[item.name]\n\n lines.push(`[${filename}](${designerUrl}/file-download/${fileId})\\n`)\n } else {\n lines.push(\n getAnswer(item.field, item.state, {\n format: 'email'\n })\n )\n }\n\n lines.push('---\\n')\n })\n\n const filename = escapeMarkdown('Download main form (CSV)')\n lines.push(`[${filename}](${designerUrl}/file-download/${files.main})\\n`)\n\n appendPaymentSection(paymentItems, lines)\n\n return lines.join('\\n')\n}\n\n/**\n * Check if an item is a PaymentField\n */\nfunction isPaymentItem(item: DetailItem): boolean {\n if ('subItems' in item) {\n return false\n }\n return item.field instanceof PaymentField\n}\n\n/**\n * Appends the payment details section to the email lines if payment exists\n */\nfunction appendPaymentSection(paymentItems: DetailItem[], lines: string[]) {\n if (paymentItems.length === 0) {\n return\n }\n\n const paymentItem = paymentItems[0] as DetailItemField\n const paymentField = paymentItem.field as PaymentField\n const paymentState = paymentField.getPaymentStateFromState(paymentItem.state)\n\n if (!paymentState) {\n return\n }\n\n const formattedAmount = formatPaymentAmount(paymentState.amount)\n const dateOfPayment = paymentState.preAuth?.createdAt\n ? formatPaymentDate(paymentState.preAuth.createdAt)\n : ''\n\n lines.push(\n '---\\n',\n `# Your payment of ${formattedAmount} was successful\\n`,\n '## Payment for\\n',\n `${escapeMarkdown(paymentState.description)}\\n`,\n '---\\n',\n '## Total amount\\n',\n `${formattedAmount}\\n`,\n '---\\n',\n '## Date of payment\\n',\n `${escapeMarkdown(dateOfPayment)}\\n`,\n '---\\n'\n )\n}\n"],"mappings":"AAIA,SAASA,OAAO,EAAEC,MAAM,IAAIC,UAAU,QAAQ,UAAU;AAExD,SAASC,MAAM;AACf,SAASC,SAAS;AAClB,SAASC,cAAc;AACvB,SAASC,YAAY;AAQrB,SACEC,mBAAmB,EACnBC,iBAAiB;AAGnB,MAAMC,WAAW,GAAGN,MAAM,CAACO,GAAG,CAAC,aAAa,CAAC;AAE7C,OAAO,SAAST,MAAMA,CACpBU,QAAqB,EACrBC,KAAmB,EACnBC,KAAgB,EAChBC,cAAqC,EACrCC,UAA8C,EAC9CC,aAA4B,EAC5B;EACA,MAAM;IAAEC;EAAM,CAAC,GAAGH,cAAc,CAACI,MAAM;EAEvC,MAAMC,QAAQ,GAAGd,cAAc,CAACQ,K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AAG1C,mBAAmB,CAACwC,YAAY,CAACG,MAAM,CAAC;EAChE,MAAMC,aAAa,GAAGJ,YAAY,CAACK,OAAO,EAAEC,SAAS,GACjD7C,iBAAiB,CAACuC,YAAY,CAACK,OAAO,CAACC,SAAS,CAAC,GACjD,EAAE;EAEN3B,KAAK,CAACC,IAAI,CACR,OAAO,EACP,qBAAqBsB,eAAe,mBAAmB,EACvD,kBAAkB,EAClB,GAAG5C,cAAc,CAAC0C,YAAY,CAACO,WAAW,CAAC,IAAI,EAC/C,OAAO,EACP,mBAAmB,EACnB,GAAGL,eAAe,IAAI,EACtB,OAAO,EACP,sBAAsB,EACtB,GAAG5C,cAAc,CAAC8C,aAAa,CAAC,IAAI,EACpC,OACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -3,6 +3,17 @@ import { type checkFormStatus } from '~/src/server/plugins/engine/helpers.js';
|
|
|
3
3
|
import { type FormModel } from '~/src/server/plugins/engine/models/index.js';
|
|
4
4
|
import { type DetailItem } from '~/src/server/plugins/engine/models/types.js';
|
|
5
5
|
import { type FormContext, type RichFormValue } from '~/src/server/plugins/engine/types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Payment data for the machine output format
|
|
8
|
+
* Defined locally to avoid circular dependency with types.ts
|
|
9
|
+
*/
|
|
10
|
+
interface PaymentOutput {
|
|
11
|
+
paymentId: string;
|
|
12
|
+
reference: string;
|
|
13
|
+
amount: number;
|
|
14
|
+
description: string;
|
|
15
|
+
createdAt: string;
|
|
16
|
+
}
|
|
6
17
|
export declare function format(context: FormContext, items: DetailItem[], model: FormModel, _submitResponse: SubmitResponsePayload, _formStatus: ReturnType<typeof checkFormStatus>): string;
|
|
7
18
|
/**
|
|
8
19
|
* Categories the form submission data into the "main" body and "repeaters".
|
|
@@ -29,6 +40,15 @@ export declare function format(context: FormContext, items: DetailItem[], model:
|
|
|
29
40
|
* userDownloadLink: 'https://forms-designer/file-download/123-456-789'
|
|
30
41
|
* }
|
|
31
42
|
* ]
|
|
43
|
+
* },
|
|
44
|
+
* payments: {
|
|
45
|
+
* paymentComponentName: {
|
|
46
|
+
* paymentId: 'abc123',
|
|
47
|
+
* reference: 'REF-123',
|
|
48
|
+
* amount: 10.00,
|
|
49
|
+
* description: 'Application fee',
|
|
50
|
+
* createdAt: '2025-01-23T10:30:00.000Z'
|
|
51
|
+
* }
|
|
32
52
|
* }
|
|
33
53
|
* }
|
|
34
54
|
*/
|
|
@@ -40,4 +60,6 @@ export declare function categoriseData(items: DetailItem[]): {
|
|
|
40
60
|
fileName: string;
|
|
41
61
|
userDownloadLink: string;
|
|
42
62
|
}[]>;
|
|
63
|
+
payment?: PaymentOutput;
|
|
43
64
|
};
|
|
65
|
+
export {};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { config } from "../../../../../config/index.js";
|
|
2
|
-
import { FileUploadField } from "../../components/index.js";
|
|
2
|
+
import { FileUploadField, PaymentField } from "../../components/index.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Payment data for the machine output format
|
|
6
|
+
* Defined locally to avoid circular dependency with types.ts
|
|
7
|
+
*/
|
|
8
|
+
|
|
3
9
|
const designerUrl = config.get('designerUrl');
|
|
4
10
|
export function format(context, items, model, _submitResponse, _formStatus) {
|
|
5
11
|
const now = new Date();
|
|
@@ -43,6 +49,15 @@ export function format(context, items, model, _submitResponse, _formStatus) {
|
|
|
43
49
|
* userDownloadLink: 'https://forms-designer/file-download/123-456-789'
|
|
44
50
|
* }
|
|
45
51
|
* ]
|
|
52
|
+
* },
|
|
53
|
+
* payments: {
|
|
54
|
+
* paymentComponentName: {
|
|
55
|
+
* paymentId: 'abc123',
|
|
56
|
+
* reference: 'REF-123',
|
|
57
|
+
* amount: 10.00,
|
|
58
|
+
* description: 'Application fee',
|
|
59
|
+
* createdAt: '2025-01-23T10:30:00.000Z'
|
|
60
|
+
* }
|
|
46
61
|
* }
|
|
47
62
|
* }
|
|
48
63
|
*/
|
|
@@ -61,6 +76,11 @@ export function categoriseData(items) {
|
|
|
61
76
|
output.repeaters[name] = extractRepeaters(item);
|
|
62
77
|
} else if (isFileUploadFieldItem(item)) {
|
|
63
78
|
output.files[name] = extractFileUploads(item);
|
|
79
|
+
} else if (isPaymentFieldItem(item)) {
|
|
80
|
+
const payment = extractPayment(item);
|
|
81
|
+
if (payment) {
|
|
82
|
+
output.payment = payment;
|
|
83
|
+
}
|
|
64
84
|
} else {
|
|
65
85
|
output.main[name] = item.field.getFormValueFromState(state);
|
|
66
86
|
}
|
|
@@ -110,4 +130,26 @@ function extractFileUploads(item) {
|
|
|
110
130
|
function isFileUploadFieldItem(item) {
|
|
111
131
|
return item.field instanceof FileUploadField;
|
|
112
132
|
}
|
|
133
|
+
function isPaymentFieldItem(item) {
|
|
134
|
+
return item.field instanceof PaymentField;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Returns the "payments" section of the response body
|
|
139
|
+
* @param item - the payment item in the form
|
|
140
|
+
* @returns the payment data
|
|
141
|
+
*/
|
|
142
|
+
function extractPayment(item) {
|
|
143
|
+
const paymentState = item.field.getPaymentStateFromState(item.state);
|
|
144
|
+
if (!paymentState) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
paymentId: paymentState.paymentId,
|
|
149
|
+
reference: paymentState.reference,
|
|
150
|
+
amount: paymentState.amount,
|
|
151
|
+
description: paymentState.description,
|
|
152
|
+
createdAt: paymentState.preAuth?.createdAt ?? ''
|
|
153
|
+
};
|
|
154
|
+
}
|
|
113
155
|
//# sourceMappingURL=v2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v2.js","names":["config","FileUploadField","designerUrl","get","format","context","items","model","_submitResponse","_formStatus","now","Date","categorisedData","categoriseData","meta","schemaVersion","timestamp","toISOString","definition","def","referenceNumber","data","body","JSON","stringify","output","main","repeaters","files","forEach","item","name","state","extractRepeaters","isFileUploadFieldItem","extractFileUploads","field","getFormValueFromState","subItems","inputRepeaterItem","outputRepeaterItem","repeaterComponent","push","fileUploadState","map","fileState","file","status","form","fileId","fileName","filename","userDownloadLink"],"sources":["../../../../../../src/server/plugins/engine/outputFormatters/machine/v2.ts"],"sourcesContent":["import { type SubmitResponsePayload } from '@defra/forms-model'\n\nimport { config } from '~/src/config/index.js'\nimport {
|
|
1
|
+
{"version":3,"file":"v2.js","names":["config","FileUploadField","PaymentField","designerUrl","get","format","context","items","model","_submitResponse","_formStatus","now","Date","categorisedData","categoriseData","meta","schemaVersion","timestamp","toISOString","definition","def","referenceNumber","data","body","JSON","stringify","output","main","repeaters","files","forEach","item","name","state","extractRepeaters","isFileUploadFieldItem","extractFileUploads","isPaymentFieldItem","payment","extractPayment","field","getFormValueFromState","subItems","inputRepeaterItem","outputRepeaterItem","repeaterComponent","push","fileUploadState","map","fileState","file","status","form","fileId","fileName","filename","userDownloadLink","paymentState","getPaymentStateFromState","undefined","paymentId","reference","amount","description","createdAt","preAuth"],"sources":["../../../../../../src/server/plugins/engine/outputFormatters/machine/v2.ts"],"sourcesContent":["import { type SubmitResponsePayload } from '@defra/forms-model'\n\nimport { config } from '~/src/config/index.js'\nimport {\n FileUploadField,\n PaymentField\n} from '~/src/server/plugins/engine/components/index.js'\nimport { type checkFormStatus } from '~/src/server/plugins/engine/helpers.js'\nimport { type FormModel } from '~/src/server/plugins/engine/models/index.js'\nimport {\n type DetailItem,\n type DetailItemField,\n type DetailItemRepeat\n} from '~/src/server/plugins/engine/models/types.js'\nimport {\n type FileUploadFieldDetailitem,\n type FormAdapterFile,\n type FormContext,\n type RichFormValue\n} from '~/src/server/plugins/engine/types.js'\n\n/**\n * Payment data for the machine output format\n * Defined locally to avoid circular dependency with types.ts\n */\ninterface PaymentOutput {\n paymentId: string\n reference: string\n amount: number\n description: string\n createdAt: string\n}\n\nconst designerUrl = config.get('designerUrl')\n\nexport function format(\n context: FormContext,\n items: DetailItem[],\n model: FormModel,\n _submitResponse: SubmitResponsePayload,\n _formStatus: ReturnType<typeof checkFormStatus>\n) {\n const now = new Date()\n\n const categorisedData = categoriseData(items)\n\n const meta: Record<string, unknown> = {\n schemaVersion: '2',\n timestamp: now.toISOString(),\n definition: model.def,\n referenceNumber: context.referenceNumber\n }\n\n const data = {\n meta,\n data: categorisedData\n }\n\n const body = JSON.stringify(data)\n\n return body\n}\n\n/**\n * Categories the form submission data into the \"main\" body and \"repeaters\".\n *\n * {\n * main: {\n * componentName: 'componentValue',\n * },\n * repeaters: {\n * repeaterName: [\n * {\n * textComponentName: 'componentValue'\n * },\n * {\n * richComponentName: { foo: 'bar', 'baz': true }\n * }\n * ]\n * },\n * files: {\n * fileComponentName: [\n * {\n * fileId: '123-456-789',\n * fileName: 'example.pdf',\n * userDownloadLink: 'https://forms-designer/file-download/123-456-789'\n * }\n * ]\n * },\n * payments: {\n * paymentComponentName: {\n * paymentId: 'abc123',\n * reference: 'REF-123',\n * amount: 10.00,\n * description: 'Application fee',\n * createdAt: '2025-01-23T10:30:00.000Z'\n * }\n * }\n * }\n */\nexport function categoriseData(items: DetailItem[]) {\n const output: {\n main: Record<string, RichFormValue>\n repeaters: Record<string, Record<string, RichFormValue>[]>\n files: Record<\n string,\n { fileId: string; fileName: string; userDownloadLink: string }[]\n >\n payment?: PaymentOutput\n } = { main: {}, repeaters: {}, files: {} }\n\n items.forEach((item) => {\n const { name, state } = item\n\n if ('subItems' in item) {\n output.repeaters[name] = extractRepeaters(item)\n } else if (isFileUploadFieldItem(item)) {\n output.files[name] = extractFileUploads(item)\n } else if (isPaymentFieldItem(item)) {\n const payment = extractPayment(item)\n if (payment) {\n output.payment = payment\n }\n } else {\n output.main[name] = item.field.getFormValueFromState(state)\n }\n })\n\n return output\n}\n\n/**\n * Returns the \"repeaters\" section of the response body\n * @param item - the repeater item\n * @returns the repeater item\n */\nfunction extractRepeaters(item: DetailItemRepeat) {\n const repeaters: Record<string, RichFormValue>[] = []\n\n item.subItems.forEach((inputRepeaterItem) => {\n const outputRepeaterItem: Record<string, RichFormValue> = {}\n\n inputRepeaterItem.forEach((repeaterComponent) => {\n const { field, state } = repeaterComponent\n\n outputRepeaterItem[repeaterComponent.name] =\n field.getFormValueFromState(state)\n })\n\n repeaters.push(outputRepeaterItem)\n })\n\n return repeaters\n}\n\n/**\n * Returns the \"files\" section of the response body\n * @param item - the file upload item in the form\n * @returns the file upload data\n */\nfunction extractFileUploads(\n item: FileUploadFieldDetailitem\n): FormAdapterFile[] {\n const fileUploadState = item.field.getFormValueFromState(item.state) ?? []\n\n return fileUploadState.map((fileState) => {\n const { file } = fileState.status.form\n return {\n fileId: file.fileId,\n fileName: file.filename,\n userDownloadLink: `${designerUrl}/file-download/${file.fileId}`\n }\n })\n}\n\nfunction isFileUploadFieldItem(\n item: DetailItemField\n): item is FileUploadFieldDetailitem {\n return item.field instanceof FileUploadField\n}\n\nfunction isPaymentFieldItem(item: DetailItemField): item is DetailItemField & {\n field: PaymentField\n} {\n return item.field instanceof PaymentField\n}\n\n/**\n * Returns the \"payments\" section of the response body\n * @param item - the payment item in the form\n * @returns the payment data\n */\nfunction extractPayment(\n item: DetailItemField & { field: PaymentField }\n): PaymentOutput | undefined {\n const paymentState = item.field.getPaymentStateFromState(item.state)\n\n if (!paymentState) {\n return undefined\n }\n\n return {\n paymentId: paymentState.paymentId,\n reference: paymentState.reference,\n amount: paymentState.amount,\n description: paymentState.description,\n createdAt: paymentState.preAuth?.createdAt ?? ''\n }\n}\n"],"mappings":"AAEA,SAASA,MAAM;AACf,SACEC,eAAe,EACfC,YAAY;;AAgBd;AACA;AACA;AACA;;AASA,MAAMC,WAAW,GAAGH,MAAM,CAACI,GAAG,CAAC,aAAa,CAAC;AAE7C,OAAO,SAASC,MAAMA,CACpBC,OAAoB,EACpBC,KAAmB,EACnBC,KAAgB,EAChBC,eAAsC,EACtCC,WAA+C,EAC/C;EACA,MAAMC,GAAG,GAAG,IAAIC,IAAI,CAAC,CAAC;EAEtB,MAAMC,eAAe,GAAGC,cAAc,CAACP,KAAK,CAAC;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AACS,KAAK,YAAYvC,eAAe;AAC9C;AAEA,SAASoC,kBAAkBA,CAACN,IAAqB,EAE/C;EACA,OAAOA,IAAI,CAACS,KAAK,YAAYtC,YAAY;AAC3C;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASqC,cAAcA,CACrBR,IAA+C,EACpB;EAC3B,MAAM0B,YAAY,GAAG1B,IAAI,CAACS,KAAK,CAACkB,wBAAwB,CAAC3B,IAAI,CAACE,KAAK,CAAC;EAEpE,IAAI,CAACwB,YAAY,EAAE;IACjB,OAAOE,SAAS;EAClB;EAEA,OAAO;IACLC,SAAS,EAAEH,YAAY,CAACG,SAAS;IACjCC,SAAS,EAAEJ,YAAY,CAACI,SAAS;IACjCC,MAAM,EAAEL,YAAY,CAACK,MAAM;IAC3BC,WAAW,EAAEN,YAAY,CAACM,WAAW;IACrCC,SAAS,EAAEP,YAAY,CAACQ,OAAO,EAAED,SAAS,IAAI;EAChD,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ComponentType, ControllerType, Engine, hasComponents, hasNext, hasRepeater } from '@defra/forms-model';
|
|
2
2
|
import Boom from '@hapi/boom';
|
|
3
|
-
import { COMPONENT_STATE_ERROR, EXTERNAL_STATE_APPENDAGE, EXTERNAL_STATE_PAYLOAD } from "../../../constants.js";
|
|
3
|
+
import { COMPONENT_STATE_ERROR, EXTERNAL_STATE_APPENDAGE, EXTERNAL_STATE_PAYLOAD, PAYMENT_EXPIRED_NOTIFICATION } from "../../../constants.js";
|
|
4
4
|
import { ComponentCollection } from "../components/ComponentCollection.js";
|
|
5
5
|
import { optionalText } from "../components/constants.js";
|
|
6
|
-
import { getCacheService, getErrors, getSaveAndExitHelpers, normalisePath, proceed } from "../helpers.js";
|
|
6
|
+
import { checkFormStatus, getCacheService, getErrors, getSaveAndExitHelpers, normalisePath, proceed } from "../helpers.js";
|
|
7
7
|
import { PageController } from "./PageController.js";
|
|
8
8
|
import { clearNotYetValidatedState, prefillStateFromQueryParameters } from "./helpers/state.js";
|
|
9
9
|
import { getComponentsByType } from "../validationHelpers.js";
|
|
10
|
-
import { FormAction } from "../../../routes/types.js";
|
|
10
|
+
import { FormAction, FormStatus } from "../../../routes/types.js";
|
|
11
11
|
import { actionSchema, crumbSchema, paramsSchema } from "../../../schemas/index.js";
|
|
12
12
|
import { merge } from "../../../services/cacheService.js";
|
|
13
13
|
export class QuestionPageController extends PageController {
|
|
@@ -132,6 +132,15 @@ export class QuestionPageController extends PageController {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
+
const hasIncompletePayment = components.some(({
|
|
136
|
+
model
|
|
137
|
+
}) => {
|
|
138
|
+
if ('paymentState' in model) {
|
|
139
|
+
const paymentState = model.paymentState;
|
|
140
|
+
return !paymentState?.preAuth?.status;
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
});
|
|
135
144
|
return {
|
|
136
145
|
...viewModel,
|
|
137
146
|
backLink: this.getBackLink(request, context),
|
|
@@ -139,7 +148,8 @@ export class QuestionPageController extends PageController {
|
|
|
139
148
|
showTitle,
|
|
140
149
|
components,
|
|
141
150
|
errors,
|
|
142
|
-
allowSaveAndExit: this.shouldShowSaveAndExit(request.server)
|
|
151
|
+
allowSaveAndExit: this.shouldShowSaveAndExit(request.server),
|
|
152
|
+
showSubmitButton: !hasIncompletePayment
|
|
143
153
|
};
|
|
144
154
|
}
|
|
145
155
|
getRelevantPath(request, context) {
|
|
@@ -336,6 +346,8 @@ export class QuestionPageController extends PageController {
|
|
|
336
346
|
const flashedError = request.yar.flash(COMPONENT_STATE_ERROR);
|
|
337
347
|
const flashedErrors = !Array.isArray(flashedError) ? [flashedError] : [];
|
|
338
348
|
viewModel.errors = (viewModel.errors ?? []).concat(flashedErrors);
|
|
349
|
+
const paymentExpiredFlash = request.yar.flash(PAYMENT_EXPIRED_NOTIFICATION);
|
|
350
|
+
viewModel.showPaymentExpiredNotification = !Array.isArray(paymentExpiredFlash);
|
|
339
351
|
|
|
340
352
|
/**
|
|
341
353
|
* Content components can be hidden based on a condition. If the condition evaluates to true, it is safe to be kept, otherwise discard it
|
|
@@ -432,7 +444,7 @@ export class QuestionPageController extends PageController {
|
|
|
432
444
|
} = context;
|
|
433
445
|
const action = request.payload.action;
|
|
434
446
|
if (action?.startsWith(FormAction.External)) {
|
|
435
|
-
return this.dispatchExternal(request, h, context);
|
|
447
|
+
return await this.dispatchExternal(request, h, context);
|
|
436
448
|
}
|
|
437
449
|
|
|
438
450
|
/**
|
|
@@ -460,7 +472,7 @@ export class QuestionPageController extends PageController {
|
|
|
460
472
|
return this.proceed(request, h, this.getNextPath(context));
|
|
461
473
|
};
|
|
462
474
|
}
|
|
463
|
-
dispatchExternal(request, h, context) {
|
|
475
|
+
async dispatchExternal(request, h, context) {
|
|
464
476
|
const {
|
|
465
477
|
externalComponents
|
|
466
478
|
} = getComponentsByType();
|
|
@@ -493,11 +505,20 @@ export class QuestionPageController extends PageController {
|
|
|
493
505
|
|
|
494
506
|
// Clear any previous state appendage
|
|
495
507
|
request.yar.clear(EXTERNAL_STATE_APPENDAGE);
|
|
496
|
-
|
|
508
|
+
|
|
509
|
+
// Determine if this is a live form (not preview/draft)
|
|
510
|
+
const {
|
|
511
|
+
state,
|
|
512
|
+
isPreview
|
|
513
|
+
} = checkFormStatus(request.params);
|
|
514
|
+
const isLive = state === FormStatus.Live;
|
|
515
|
+
return await selectedComponent.dispatcher(request, h, {
|
|
497
516
|
component,
|
|
498
517
|
controller: this,
|
|
499
518
|
sourceUrl: request.url.toString(),
|
|
500
|
-
actionArgs: args
|
|
519
|
+
actionArgs: args,
|
|
520
|
+
isLive,
|
|
521
|
+
isPreview
|
|
501
522
|
});
|
|
502
523
|
}
|
|
503
524
|
proceed(request, h, nextPath) {
|