@defra/forms-model 3.0.644 → 3.0.645

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.
@@ -0,0 +1,7 @@
1
+ export let FormMetricType = /*#__PURE__*/function (FormMetricType) {
2
+ FormMetricType["HeadlineMetric"] = "headline-metric";
3
+ FormMetricType["OverviewMetric"] = "overview-metric";
4
+ FormMetricType["TimelineMetric"] = "timeline-metric";
5
+ return FormMetricType;
6
+ }({});
7
+ //# sourceMappingURL=enums.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enums.js","names":["FormMetricType"],"sources":["../../../../src/form/form-metrics/enums.ts"],"sourcesContent":["export enum FormMetricType {\n HeadlineMetric = 'headline-metric',\n OverviewMetric = 'overview-metric',\n TimelineMetric = 'timeline-metric'\n}\n"],"mappings":"AAAA,WAAYA,cAAc,0BAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAA,OAAdA,cAAc;AAAA","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../../src/form/form-metrics/types.ts"],"sourcesContent":["import { type FormStatus } from '~/src/common/enums.js'\nimport { type FormMetricType } from '~/src/form/form-metrics/enums.js'\n\nexport interface FormHeadlineDetail {\n count: number\n countSevenDaysAgo: number\n countThirtyDaysAgo: number\n countOneYearAgo: number\n}\n\nexport interface FormHeadlineMetric {\n type: FormMetricType.HeadlineMetric\n headlineCounts: Record<string, FormHeadlineDetail>\n updatedAt: Date\n}\n\nexport interface FormOverviewMetric {\n type: FormMetricType.OverviewMetric\n formId: string\n formStatus: FormStatus\n summaryMetrics: Record<string, number | string | string[]>\n featureCounts: Record<string, number>\n submissionsCount: number\n updatedAt: Date\n}\n\nexport interface FormTimelineMetric {\n type: FormMetricType.TimelineMetric\n formId: string\n formStatus: FormStatus\n metricName: string\n metricValue: number\n createdAt: Date\n}\n\nexport type FormMetric =\n | FormHeadlineMetric\n | FormOverviewMetric\n | FormTimelineMetric\n"],"mappings":"","ignoreList":[]}
@@ -10,6 +10,8 @@ export * from "./form/form-definition/index.js";
10
10
  export * from "./form/form-definition/types.js";
11
11
  export * from "./form/form-definition/helpers.js";
12
12
  export * from "./form/form-metadata/index.js";
13
+ export * from "./form/form-metrics/enums.js";
14
+ export * from "./form/form-metrics/types.js";
13
15
  export * from "./form/form-submission/index.js";
14
16
  export * from "./form/form-submission/enums.js";
15
17
  export * from "./form/utils/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from '~/src/common/enums.js'\nexport * from '~/src/common/random-id.js'\nexport * from '~/src/common/schema.js'\nexport * from '~/src/common/pagination/index.js'\nexport * from '~/src/common/search/index.js'\nexport * from '~/src/common/sorting/index.js'\nexport * from '~/src/components/index.js'\nexport * from '~/src/conditions/index.js'\nexport * from '~/src/form/form-definition/index.js'\nexport * from '~/src/form/form-definition/types.js'\nexport * from '~/src/form/form-definition/helpers.js'\nexport * from '~/src/form/form-metadata/index.js'\nexport * from '~/src/form/form-submission/index.js'\nexport * from '~/src/form/form-submission/enums.js'\nexport * from '~/src/form/utils/index.js'\nexport * from '~/src/form/form-editor/index.js'\nexport * from '~/src/form/form-editor/preview/index.js'\nexport * from '~/src/form/form-manager/types.js'\nexport * from '~/src/form/form-manager/errors.js'\nexport * from '~/src/manage/dead-letter-queues.js'\nexport * from '~/src/manage/roles.js'\nexport * from '~/src/manage/users.js'\nexport * from '~/src/pages/index.js'\nexport * from '~/src/utils/helpers.js'\nexport * from '~/src/utils/markdown.js'\nexport * from '~/src/form/form-audit/index.js'\nexport * from '~/src/form/form-audit/enums.js'\nexport * from '~/src/form/form-audit/consolidation.js'\n\nexport type * from '~/src/common/types.js'\nexport type * from '~/src/common/pagination/types.js'\nexport type * from '~/src/common/search/types.js'\nexport type * from '~/src/common/sorting/types.js'\nexport type * from '~/src/components/types.js'\nexport type * from '~/src/conditions/types.js'\nexport type * from '~/src/form/form-definition/types.js'\nexport type * from '~/src/form/form-metadata/types.js'\nexport type * from '~/src/form/form-submission/types.js'\nexport type * from '~/src/form/form-editor/preview/types.js'\nexport type * from '~/src/form/form-editor/types.js'\nexport type * from '~/src/form/form-editor/macros/types.js'\nexport type * from '~/src/form/form-audit/types.js'\nexport type * from '~/src/manage/types.js'\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from '~/src/common/enums.js'\nexport * from '~/src/common/random-id.js'\nexport * from '~/src/common/schema.js'\nexport * from '~/src/common/pagination/index.js'\nexport * from '~/src/common/search/index.js'\nexport * from '~/src/common/sorting/index.js'\nexport * from '~/src/components/index.js'\nexport * from '~/src/conditions/index.js'\nexport * from '~/src/form/form-definition/index.js'\nexport * from '~/src/form/form-definition/types.js'\nexport * from '~/src/form/form-definition/helpers.js'\nexport * from '~/src/form/form-metadata/index.js'\nexport * from '~/src/form/form-metrics/enums.js'\nexport * from '~/src/form/form-metrics/types.js'\nexport * from '~/src/form/form-submission/index.js'\nexport * from '~/src/form/form-submission/enums.js'\nexport * from '~/src/form/utils/index.js'\nexport * from '~/src/form/form-editor/index.js'\nexport * from '~/src/form/form-editor/preview/index.js'\nexport * from '~/src/form/form-manager/types.js'\nexport * from '~/src/form/form-manager/errors.js'\nexport * from '~/src/manage/dead-letter-queues.js'\nexport * from '~/src/manage/roles.js'\nexport * from '~/src/manage/users.js'\nexport * from '~/src/pages/index.js'\nexport * from '~/src/utils/helpers.js'\nexport * from '~/src/utils/markdown.js'\nexport * from '~/src/form/form-audit/index.js'\nexport * from '~/src/form/form-audit/enums.js'\nexport * from '~/src/form/form-audit/consolidation.js'\n\nexport type * from '~/src/common/types.js'\nexport type * from '~/src/common/pagination/types.js'\nexport type * from '~/src/common/search/types.js'\nexport type * from '~/src/common/sorting/types.js'\nexport type * from '~/src/components/types.js'\nexport type * from '~/src/conditions/types.js'\nexport type * from '~/src/form/form-definition/types.js'\nexport type * from '~/src/form/form-metadata/types.js'\nexport type * from '~/src/form/form-submission/types.js'\nexport type * from '~/src/form/form-editor/preview/types.js'\nexport type * from '~/src/form/form-editor/types.js'\nexport type * from '~/src/form/form-editor/macros/types.js'\nexport type * from '~/src/form/form-audit/types.js'\nexport type * from '~/src/manage/types.js'\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -86,6 +86,38 @@ export function onlyDeclarationComponents(components) {
86
86
  export function includesPaymentField(components) {
87
87
  return components.some(component => component.type === ComponentType.PaymentField);
88
88
  }
89
+
90
+ /**
91
+ * Helper function to determine if a payment question already exists in the form
92
+ */
93
+ export function hasPaymentQuestionInForm(definition) {
94
+ if (definition.pages.length === 0) {
95
+ return false;
96
+ }
97
+ for (const page of definition.pages) {
98
+ const hasPayment = hasComponents(page) ? includesPaymentField(page.components) : false;
99
+ if (hasPayment) {
100
+ return true;
101
+ }
102
+ }
103
+ return false;
104
+ }
105
+
106
+ /**
107
+ * Helper function to determine if a specific question type exists in the form
108
+ */
109
+ export function hasSpecificQuestionTypeInForm(definition, componentType) {
110
+ if (definition.pages.length === 0) {
111
+ return false;
112
+ }
113
+ for (const page of definition.pages) {
114
+ const hasPayment = hasComponents(page) ? page.components.some(component => component.type === componentType) : false;
115
+ if (hasPayment) {
116
+ return true;
117
+ }
118
+ }
119
+ return false;
120
+ }
89
121
  const SHOW_REPEATER_CONTROLLERS = [ControllerType.Page, ControllerType.Repeat];
90
122
  export function showRepeaterSettings(page) {
91
123
  if (page.controller && !SHOW_REPEATER_CONTROLLERS.includes(page.controller)) {
@@ -143,11 +175,15 @@ export function isSummaryPage(page) {
143
175
  * @returns {FormDefinition}
144
176
  */
145
177
  export function replaceCustomControllers(definition) {
146
- const standardControllers = new Set(Object.values(ControllerType).filter(x => x !== ControllerType.SummaryWithConfirmationEmail).map(x => x.toString()));
178
+ const standardControllers = new Set(Object.values(ControllerType).filter(x => x !== ControllerType.SummaryWithConfirmationEmail)
179
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion
180
+ .map(x => x.toString()));
147
181
  return {
148
182
  ...definition,
149
183
  pages: definition.pages.map(page => {
150
- if (!standardControllers.has((page.controller ?? ControllerType.Page).toString())) {
184
+ if (!standardControllers.has(
185
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion
186
+ (page.controller ?? ControllerType.Page).toString())) {
151
187
  return /** @type {Page} */{
152
188
  ...page,
153
189
  controller: ControllerType.Page
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","names":["ComponentType","hasFormField","isFormType","ControllerNames","ControllerTypes","ControllerType","PageTypes","getPageDefaults","page","nameOrPath","controller","Page","controllerNameFromPath","defaults","find","pageType","Error","structuredClone","hasComponents","hasNext","Array","isArray","components","hasComponentsEvenIfNoNext","undefined","hasFormComponents","Start","hasRepeater","Repeat","isControllerName","map","String","includes","Terminal","FileUpload","options","path","name","includesFileUploadField","some","component","type","FileUploadField","onlyDeclarationComponents","filter","comp","every","DeclarationField","includesPaymentField","PaymentField","SHOW_REPEATER_CONTROLLERS","showRepeaterSettings","getPageTitle","title","firstComp","getPageFromDefinition","definition","pageId","pages","x","id","summaryPageControllers","Summary","SummaryWithConfirmationEmail","isSummaryPage","replaceCustomControllers","standardControllers","Set","Object","values","toString","has","isPaymentPage","isEndPage"],"sources":["../../../src/pages/helpers.ts"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { hasFormField, isFormType } from '~/src/components/helpers.js'\nimport { type ComponentDef } from '~/src/components/types.js'\nimport {\n type Link,\n type Page,\n type PageFileUpload,\n type PageQuestion,\n type PageRepeat\n} from '~/src/form/form-definition/types.js'\nimport { type FormDefinition } from '~/src/index.js'\nimport {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\nimport { ControllerType } from '~/src/pages/enums.js'\nimport { PageTypes } from '~/src/pages/page-types.js'\n\n/**\n * Return component defaults by type\n */\nexport function getPageDefaults<PageType extends Page>(\n page?: Pick<PageType, 'controller'>\n) {\n const nameOrPath = page?.controller ?? ControllerType.Page\n const controller = controllerNameFromPath(nameOrPath)\n\n const defaults = PageTypes.find(\n (pageType) => pageType.controller === controller\n )\n\n if (!defaults) {\n throw new Error(`Defaults not found for page type '${nameOrPath}'`)\n }\n\n return structuredClone(defaults) as PageType\n}\n\n/**\n * Check page has components\n */\nexport function hasComponents(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return hasNext(page) && Array.isArray(page.components)\n}\n\n/**\n * Check if the page has components (the page can be any page type e.g. SummaryPage)\n */\nexport function hasComponentsEvenIfNoNext(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return (\n page !== undefined && 'components' in page && Array.isArray(page.components)\n )\n}\n\n/**\n * Check page has form components\n */\nexport function hasFormComponents(\n page?: Partial<Page>\n): page is PageQuestion | PageFileUpload {\n const controller = controllerNameFromPath(page?.controller)\n return hasComponents(page) && controller !== ControllerType.Start\n}\n\n/**\n * Check page has repeater\n */\nexport function hasRepeater(page?: Partial<Page>): page is PageRepeat {\n return controllerNameFromPath(page?.controller) === ControllerType.Repeat\n}\n\n/**\n * Check for known page controller names\n */\nexport function isControllerName(\n nameOrPath?: ControllerType | string\n): nameOrPath is ControllerType {\n return !!nameOrPath && ControllerNames.map(String).includes(nameOrPath)\n}\n\n/**\n * Check page has next link\n */\nexport function hasNext(\n page?: Partial<Page>\n): page is Extract<Page, { next: Link[] }> {\n if (!page || !('next' in page)) {\n return false\n }\n\n const controller = controllerNameFromPath(page.controller)\n\n return (\n !controller ||\n controller === ControllerType.Start ||\n controller === ControllerType.Page ||\n controller === ControllerType.Terminal ||\n controller === ControllerType.FileUpload ||\n controller === ControllerType.Repeat\n )\n}\n\n/**\n * Check and optionally replace legacy path with controller name\n * @param {string} [nameOrPath] - Controller name or legacy controller path\n */\nexport function controllerNameFromPath(nameOrPath?: ControllerType | string) {\n if (isControllerName(nameOrPath)) {\n return nameOrPath\n }\n\n const options = ControllerTypes.find(({ path }) => path === nameOrPath)\n return options?.name\n}\n\nexport function includesFileUploadField(components: ComponentDef[]): boolean {\n return components.some(\n (component) => component.type === ComponentType.FileUploadField\n )\n}\n\nexport function onlyDeclarationComponents(components: ComponentDef[]): boolean {\n return components\n .filter((comp) => isFormType(comp.type))\n .every((component) => component.type === ComponentType.DeclarationField)\n}\n\nexport function includesPaymentField(components: ComponentDef[]): boolean {\n return components.some(\n (component) => component.type === ComponentType.PaymentField\n )\n}\n\nconst SHOW_REPEATER_CONTROLLERS = [ControllerType.Page, ControllerType.Repeat]\n\nexport function showRepeaterSettings(page: Page): boolean {\n if (page.controller && !SHOW_REPEATER_CONTROLLERS.includes(page.controller)) {\n return false\n }\n if (hasComponents(page)) {\n if (includesFileUploadField(page.components)) {\n return false\n }\n if (onlyDeclarationComponents(page.components)) {\n return false\n }\n if (includesPaymentField(page.components)) {\n return false\n }\n }\n return true\n}\n\n/**\n * Gets page title, or title of first question (if no page title set)\n * @param {Page} page\n * @returns {string}\n */\nexport function getPageTitle(page: Page) {\n if (page.title !== '') {\n return page.title\n }\n\n if (hasComponentsEvenIfNoNext(page)) {\n const firstComp = page.components.find(hasFormField)\n if (firstComp) {\n return firstComp.title\n }\n }\n return 'Page title unknown'\n}\n\n/**\n *\n * @param {FormDefinition} definition\n * @param {string} pageId\n * @returns { Page | undefined }\n */\nexport function getPageFromDefinition(\n definition: FormDefinition,\n pageId: string\n): Page | undefined {\n return definition.pages.find((x) => x.id === pageId)\n}\n\nexport const summaryPageControllers = [\n ControllerType.Summary,\n ControllerType.SummaryWithConfirmationEmail\n]\n\nexport function isSummaryPage(page: Page | undefined) {\n return summaryPageControllers.includes(\n page?.controller ?? ControllerType.Page\n )\n}\n\n/**\n * Revert any custom controllers to their parent/base class since engine-plugin has no knowledge of them\n * @param {FormDefinition} definition\n * @returns {FormDefinition}\n */\nexport function replaceCustomControllers(definition: FormDefinition) {\n const standardControllers = new Set(\n Object.values(ControllerType)\n .filter((x) => x !== ControllerType.SummaryWithConfirmationEmail)\n .map((x) => x.toString())\n )\n\n return {\n ...definition,\n pages: definition.pages.map((page) => {\n if (\n !standardControllers.has(\n (page.controller ?? ControllerType.Page).toString()\n )\n ) {\n return /** @type {Page} */ {\n ...page,\n controller: ControllerType.Page\n }\n }\n return page\n })\n } as FormDefinition\n}\n\n/**\n * Helper function to determine if the current page contains a payment question\n * @param page - the page of the form\n * @returns {boolean}\n */\nexport function isPaymentPage(page: Page | undefined) {\n if (hasComponentsEvenIfNoNext(page)) {\n return page.components.some(\n (comp) => comp.type === ComponentType.PaymentField\n )\n }\n return false\n}\n\n/**\n * Helper function to determine if the current page is an end page i.e. summary page or payment page\n * @param page - the page of the form\n * @returns {boolean}\n */\nexport function isEndPage(page: Page | undefined) {\n return isSummaryPage(page) || isPaymentPage(page)\n}\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,YAAY,EAAEC,UAAU;AAUjC,SACEC,eAAe,EACfC,eAAe;AAEjB,SAASC,cAAc;AACvB,SAASC,SAAS;;AAElB;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,IAAmC,EACnC;EACA,MAAMC,UAAU,GAAGD,IAAI,EAAEE,UAAU,IAAIL,cAAc,CAACM,IAAI;EAC1D,MAAMD,UAAU,GAAGE,sBAAsB,CAACH,UAAU,CAAC;EAErD,MAAMI,QAAQ,GAAGP,SAAS,CAACQ,IAAI,CAC5BC,QAAQ,IAAKA,QAAQ,CAACL,UAAU,KAAKA,UACxC,CA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,QAAQ,CACpCxB,IAAI,EAAEE,UAAU,IAAIL,cAAc,CAACM,IACrC,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASsD,wBAAwBA,CAACT,UAA0B,EAAE;EACnE,MAAMU,mBAAmB,GAAG,IAAIC,GAAG,CACjCC,MAAM,CAACC,MAAM,CAAChE,cAAc,CAAC,CAC1BuC,MAAM,CAAEe,CAAC,IAAKA,CAAC,KAAKtD,cAAc,CAAC0D,4BAA4B,CAAC,CAChEjC,GAAG,CAAE6B,CAAC,IAAKA,CAAC,CAACW,QAAQ,CAAC,CAAC,CAC5B,CAAC;EAED,OAAO;IACL,GAAGd,UAAU;IACbE,KAAK,EAAEF,UAAU,CAACE,KAAK,CAAC5B,GAAG,CAAEtB,IAAI,IAAK;MACpC,IACE,CAAC0D,mBAAmB,CAACK,GAAG,CACtB,CAAC/D,IAAI,CAACE,UAAU,IAAIL,cAAc,CAACM,IAAI,EAAE2D,QAAQ,CAAC,CACpD,CAAC,EACD;QACA,OAAO,mBAAoB;UACzB,GAAG9D,IAAI;UACPE,UAAU,EAAEL,cAAc,CAACM;QAC7B,CAAC;MACH;MACA,OAAOH,IAAI;IACb,CAAC;EACH,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASgE,aAAaA,CAAChE,IAAsB,EAAE;EACpD,IAAIe,yBAAyB,CAACf,IAAI,CAAC,EAAE;IACnC,OAAOA,IAAI,CAACc,UAAU,CAACiB,IAAI,CACxBM,IAAI,IAAKA,IAAI,CAACJ,IAAI,KAAKzC,aAAa,CAACiD,YACxC,CAAC;EACH;EACA,OAAO,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASwB,SAASA,CAACjE,IAAsB,EAAE;EAChD,OAAOwD,aAAa,CAACxD,IAAI,CAAC,IAAIgE,aAAa,CAAChE,IAAI,CAAC;AACnD","ignoreList":[]}
1
+ {"version":3,"file":"helpers.js","names":["ComponentType","hasFormField","isFormType","ControllerNames","ControllerTypes","ControllerType","PageTypes","getPageDefaults","page","nameOrPath","controller","Page","controllerNameFromPath","defaults","find","pageType","Error","structuredClone","hasComponents","hasNext","Array","isArray","components","hasComponentsEvenIfNoNext","undefined","hasFormComponents","Start","hasRepeater","Repeat","isControllerName","map","String","includes","Terminal","FileUpload","options","path","name","includesFileUploadField","some","component","type","FileUploadField","onlyDeclarationComponents","filter","comp","every","DeclarationField","includesPaymentField","PaymentField","hasPaymentQuestionInForm","definition","pages","length","hasPayment","hasSpecificQuestionTypeInForm","componentType","SHOW_REPEATER_CONTROLLERS","showRepeaterSettings","getPageTitle","title","firstComp","getPageFromDefinition","pageId","x","id","summaryPageControllers","Summary","SummaryWithConfirmationEmail","isSummaryPage","replaceCustomControllers","standardControllers","Set","Object","values","toString","has","isPaymentPage","isEndPage"],"sources":["../../../src/pages/helpers.ts"],"sourcesContent":["import { ComponentType } from '~/src/components/enums.js'\nimport { hasFormField, isFormType } from '~/src/components/helpers.js'\nimport { type ComponentDef } from '~/src/components/types.js'\nimport {\n type Link,\n type Page,\n type PageFileUpload,\n type PageQuestion,\n type PageRepeat\n} from '~/src/form/form-definition/types.js'\nimport { type FormDefinition } from '~/src/index.js'\nimport {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\nimport { ControllerType } from '~/src/pages/enums.js'\nimport { PageTypes } from '~/src/pages/page-types.js'\n\n/**\n * Return component defaults by type\n */\nexport function getPageDefaults<PageType extends Page>(\n page?: Pick<PageType, 'controller'>\n) {\n const nameOrPath = page?.controller ?? ControllerType.Page\n const controller = controllerNameFromPath(nameOrPath)\n\n const defaults = PageTypes.find(\n (pageType) => pageType.controller === controller\n )\n\n if (!defaults) {\n throw new Error(`Defaults not found for page type '${nameOrPath}'`)\n }\n\n return structuredClone(defaults) as PageType\n}\n\n/**\n * Check page has components\n */\nexport function hasComponents(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return hasNext(page) && Array.isArray(page.components)\n}\n\n/**\n * Check if the page has components (the page can be any page type e.g. SummaryPage)\n */\nexport function hasComponentsEvenIfNoNext(\n page?: Partial<Page>\n): page is Extract<Page, { components: ComponentDef[] }> {\n return (\n page !== undefined && 'components' in page && Array.isArray(page.components)\n )\n}\n\n/**\n * Check page has form components\n */\nexport function hasFormComponents(\n page?: Partial<Page>\n): page is PageQuestion | PageFileUpload {\n const controller = controllerNameFromPath(page?.controller)\n return hasComponents(page) && controller !== ControllerType.Start\n}\n\n/**\n * Check page has repeater\n */\nexport function hasRepeater(page?: Partial<Page>): page is PageRepeat {\n return controllerNameFromPath(page?.controller) === ControllerType.Repeat\n}\n\n/**\n * Check for known page controller names\n */\nexport function isControllerName(\n nameOrPath?: ControllerType | string\n): nameOrPath is ControllerType {\n return !!nameOrPath && ControllerNames.map(String).includes(nameOrPath)\n}\n\n/**\n * Check page has next link\n */\nexport function hasNext(\n page?: Partial<Page>\n): page is Extract<Page, { next: Link[] }> {\n if (!page || !('next' in page)) {\n return false\n }\n\n const controller = controllerNameFromPath(page.controller)\n\n return (\n !controller ||\n controller === ControllerType.Start ||\n controller === ControllerType.Page ||\n controller === ControllerType.Terminal ||\n controller === ControllerType.FileUpload ||\n controller === ControllerType.Repeat\n )\n}\n\n/**\n * Check and optionally replace legacy path with controller name\n * @param {string} [nameOrPath] - Controller name or legacy controller path\n */\nexport function controllerNameFromPath(nameOrPath?: ControllerType | string) {\n if (isControllerName(nameOrPath)) {\n return nameOrPath\n }\n\n const options = ControllerTypes.find(({ path }) => path === nameOrPath)\n return options?.name\n}\n\nexport function includesFileUploadField(components: ComponentDef[]): boolean {\n return components.some(\n (component) => component.type === ComponentType.FileUploadField\n )\n}\n\nexport function onlyDeclarationComponents(components: ComponentDef[]): boolean {\n return components\n .filter((comp) => isFormType(comp.type))\n .every((component) => component.type === ComponentType.DeclarationField)\n}\n\nexport function includesPaymentField(components: ComponentDef[]): boolean {\n return components.some(\n (component) => component.type === ComponentType.PaymentField\n )\n}\n\n/**\n * Helper function to determine if a payment question already exists in the form\n */\nexport function hasPaymentQuestionInForm(definition: FormDefinition) {\n if (definition.pages.length === 0) {\n return false\n }\n\n for (const page of definition.pages) {\n const hasPayment = hasComponents(page)\n ? includesPaymentField(page.components)\n : false\n if (hasPayment) {\n return true\n }\n }\n return false\n}\n\n/**\n * Helper function to determine if a specific question type exists in the form\n */\nexport function hasSpecificQuestionTypeInForm(\n definition: FormDefinition,\n componentType: ComponentType\n) {\n if (definition.pages.length === 0) {\n return false\n }\n\n for (const page of definition.pages) {\n const hasPayment = hasComponents(page)\n ? page.components.some((component) => component.type === componentType)\n : false\n if (hasPayment) {\n return true\n }\n }\n return false\n}\n\nconst SHOW_REPEATER_CONTROLLERS = [ControllerType.Page, ControllerType.Repeat]\n\nexport function showRepeaterSettings(page: Page): boolean {\n if (page.controller && !SHOW_REPEATER_CONTROLLERS.includes(page.controller)) {\n return false\n }\n if (hasComponents(page)) {\n if (includesFileUploadField(page.components)) {\n return false\n }\n if (onlyDeclarationComponents(page.components)) {\n return false\n }\n if (includesPaymentField(page.components)) {\n return false\n }\n }\n return true\n}\n\n/**\n * Gets page title, or title of first question (if no page title set)\n * @param {Page} page\n * @returns {string}\n */\nexport function getPageTitle(page: Page) {\n if (page.title !== '') {\n return page.title\n }\n\n if (hasComponentsEvenIfNoNext(page)) {\n const firstComp = page.components.find(hasFormField)\n if (firstComp) {\n return firstComp.title\n }\n }\n return 'Page title unknown'\n}\n\n/**\n *\n * @param {FormDefinition} definition\n * @param {string} pageId\n * @returns { Page | undefined }\n */\nexport function getPageFromDefinition(\n definition: FormDefinition,\n pageId: string\n): Page | undefined {\n return definition.pages.find((x) => x.id === pageId)\n}\n\nexport const summaryPageControllers = [\n ControllerType.Summary,\n ControllerType.SummaryWithConfirmationEmail\n]\n\nexport function isSummaryPage(page: Page | undefined) {\n return summaryPageControllers.includes(\n page?.controller ?? ControllerType.Page\n )\n}\n\n/**\n * Revert any custom controllers to their parent/base class since engine-plugin has no knowledge of them\n * @param {FormDefinition} definition\n * @returns {FormDefinition}\n */\nexport function replaceCustomControllers(definition: FormDefinition) {\n const standardControllers = new Set(\n Object.values(ControllerType)\n .filter((x) => x !== ControllerType.SummaryWithConfirmationEmail)\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion\n .map((x) => x.toString())\n )\n\n return {\n ...definition,\n pages: definition.pages.map((page) => {\n if (\n !standardControllers.has(\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion\n (page.controller ?? ControllerType.Page).toString()\n )\n ) {\n return /** @type {Page} */ {\n ...page,\n controller: ControllerType.Page\n }\n }\n return page\n })\n } as FormDefinition\n}\n\n/**\n * Helper function to determine if the current page contains a payment question\n * @param page - the page of the form\n * @returns {boolean}\n */\nexport function isPaymentPage(page: Page | undefined) {\n if (hasComponentsEvenIfNoNext(page)) {\n return page.components.some(\n (comp) => comp.type === ComponentType.PaymentField\n )\n }\n return false\n}\n\n/**\n * Helper function to determine if the current page is an end page i.e. summary page or payment page\n * @param page - the page of the form\n * @returns {boolean}\n */\nexport function isEndPage(page: Page | undefined) {\n return isSummaryPage(page) || isPaymentPage(page)\n}\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,YAAY,EAAEC,UAAU;AAUjC,SACEC,eAAe,EACfC,eAAe;AAEjB,SAASC,cAAc;AACvB,SAASC,SAAS;;AAElB;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,IAAmC,EACnC;EACA,MAAMC,UAAU,GAAGD,IAAI,EAAEE,UAAU,IAAIL,cAAc,CAACM,IAAI;EAC1D,MAAMD,UAAU,GAAGE,sBAAsB,CAACH,UAAU,CAAC;EAErD,MAAMI,QAAQ,GAAGP,SAAS,CAACQ,IAAI,CAC5BC,QAAQ,IAAKA,QAAQ,CAACL,UAAU,KAAKA,UACxC,CAAC;EAED,IAAI,CAACG,QAAQ,EAAE;IACb,MAAM,IAAIG,KAAK,CAAC,qCAAqCP,UAAU,GAAG,CAAC;EACrE;EAEA,O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IAAK;MACpC,IACE,CAAC+D,mBAAmB,CAACK,GAAG;MACtB;MACA,CAACpE,IAAI,CAACE,UAAU,IAAIL,cAAc,CAACM,IAAI,EAAEgE,QAAQ,CAAC,CACpD,CAAC,EACD;QACA,OAAO,mBAAoB;UACzB,GAAGnE,IAAI;UACPE,UAAU,EAAEL,cAAc,CAACM;QAC7B,CAAC;MACH;MACA,OAAOH,IAAI;IACb,CAAC;EACH,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASqE,aAAaA,CAACrE,IAAsB,EAAE;EACpD,IAAIe,yBAAyB,CAACf,IAAI,CAAC,EAAE;IACnC,OAAOA,IAAI,CAACc,UAAU,CAACiB,IAAI,CACxBM,IAAI,IAAKA,IAAI,CAACJ,IAAI,KAAKzC,aAAa,CAACiD,YACxC,CAAC;EACH;EACA,OAAO,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS6B,SAASA,CAACtE,IAAsB,EAAE;EAChD,OAAO6D,aAAa,CAAC7D,IAAI,CAAC,IAAIqE,aAAa,CAACrE,IAAI,CAAC;AACnD","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  export { ControllerNames, ControllerTypes } from "./controller-types.js";
2
2
  export { PageTypes } from "./page-types.js";
3
- export { controllerNameFromPath, getPageDefaults, getPageFromDefinition, getPageTitle, hasComponents, hasComponentsEvenIfNoNext, hasFormComponents, hasNext, hasRepeater, includesFileUploadField, includesPaymentField, isControllerName, isEndPage, isPaymentPage, isSummaryPage, replaceCustomControllers, showRepeaterSettings, summaryPageControllers } from "./helpers.js";
3
+ export { controllerNameFromPath, getPageDefaults, getPageFromDefinition, getPageTitle, hasComponents, hasComponentsEvenIfNoNext, hasFormComponents, hasNext, hasPaymentQuestionInForm, hasRepeater, hasSpecificQuestionTypeInForm, includesFileUploadField, includesPaymentField, isControllerName, isEndPage, isPaymentPage, isSummaryPage, replaceCustomControllers, showRepeaterSettings, summaryPageControllers } from "./helpers.js";
4
4
  export { ControllerPath, ControllerType } from "./enums.js";
5
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["ControllerNames","ControllerTypes","PageTypes","controllerNameFromPath","getPageDefaults","getPageFromDefinition","getPageTitle","hasComponents","hasComponentsEvenIfNoNext","hasFormComponents","hasNext","hasRepeater","includesFileUploadField","includesPaymentField","isControllerName","isEndPage","isPaymentPage","isSummaryPage","replaceCustomControllers","showRepeaterSettings","summaryPageControllers","ControllerPath","ControllerType"],"sources":["../../../src/pages/index.ts"],"sourcesContent":["export {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\n\nexport { PageTypes } from '~/src/pages/page-types.js'\n\nexport {\n controllerNameFromPath,\n getPageDefaults,\n getPageFromDefinition,\n getPageTitle,\n hasComponents,\n hasComponentsEvenIfNoNext,\n hasFormComponents,\n hasNext,\n hasRepeater,\n includesFileUploadField,\n includesPaymentField,\n isControllerName,\n isEndPage,\n isPaymentPage,\n isSummaryPage,\n replaceCustomControllers,\n showRepeaterSettings,\n summaryPageControllers\n} from '~/src/pages/helpers.js'\n\nexport { ControllerPath, ControllerType } from '~/src/pages/enums.js'\n"],"mappings":"AAAA,SACEA,eAAe,EACfC,eAAe;AAGjB,SAASC,SAAS;AAElB,SACEC,sBAAsB,EACtBC,eAAe,EACfC,qBAAqB,EACrBC,YAAY,EACZC,aAAa,EACbC,yBAAyB,EACzBC,iBAAiB,EACjBC,OAAO,EACPC,WAAW,EACXC,uBAAuB,EACvBC,oBAAoB,EACpBC,gBAAgB,EAChBC,SAAS,EACTC,aAAa,EACbC,aAAa,EACbC,wBAAwB,EACxBC,oBAAoB,EACpBC,sBAAsB;AAGxB,SAASC,cAAc,EAAEC,cAAc","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["ControllerNames","ControllerTypes","PageTypes","controllerNameFromPath","getPageDefaults","getPageFromDefinition","getPageTitle","hasComponents","hasComponentsEvenIfNoNext","hasFormComponents","hasNext","hasPaymentQuestionInForm","hasRepeater","hasSpecificQuestionTypeInForm","includesFileUploadField","includesPaymentField","isControllerName","isEndPage","isPaymentPage","isSummaryPage","replaceCustomControllers","showRepeaterSettings","summaryPageControllers","ControllerPath","ControllerType"],"sources":["../../../src/pages/index.ts"],"sourcesContent":["export {\n ControllerNames,\n ControllerTypes\n} from '~/src/pages/controller-types.js'\n\nexport { PageTypes } from '~/src/pages/page-types.js'\n\nexport {\n controllerNameFromPath,\n getPageDefaults,\n getPageFromDefinition,\n getPageTitle,\n hasComponents,\n hasComponentsEvenIfNoNext,\n hasFormComponents,\n hasNext,\n hasPaymentQuestionInForm,\n hasRepeater,\n hasSpecificQuestionTypeInForm,\n includesFileUploadField,\n includesPaymentField,\n isControllerName,\n isEndPage,\n isPaymentPage,\n isSummaryPage,\n replaceCustomControllers,\n showRepeaterSettings,\n summaryPageControllers\n} from '~/src/pages/helpers.js'\n\nexport { ControllerPath, ControllerType } from '~/src/pages/enums.js'\n"],"mappings":"AAAA,SACEA,eAAe,EACfC,eAAe;AAGjB,SAASC,SAAS;AAElB,SACEC,sBAAsB,EACtBC,eAAe,EACfC,qBAAqB,EACrBC,YAAY,EACZC,aAAa,EACbC,yBAAyB,EACzBC,iBAAiB,EACjBC,OAAO,EACPC,wBAAwB,EACxBC,WAAW,EACXC,6BAA6B,EAC7BC,uBAAuB,EACvBC,oBAAoB,EACpBC,gBAAgB,EAChBC,SAAS,EACTC,aAAa,EACbC,aAAa,EACbC,wBAAwB,EACxBC,oBAAoB,EACpBC,sBAAsB;AAGxB,SAASC,cAAc,EAAEC,cAAc","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ export declare enum FormMetricType {
2
+ HeadlineMetric = "headline-metric",
3
+ OverviewMetric = "overview-metric",
4
+ TimelineMetric = "timeline-metric"
5
+ }
6
+ //# sourceMappingURL=enums.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../../../src/form/form-metrics/enums.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACxB,cAAc,oBAAoB;IAClC,cAAc,oBAAoB;IAClC,cAAc,oBAAoB;CACnC"}
@@ -0,0 +1,32 @@
1
+ import { type FormStatus } from '../../common/enums.js';
2
+ import { type FormMetricType } from '../../form/form-metrics/enums.js';
3
+ export interface FormHeadlineDetail {
4
+ count: number;
5
+ countSevenDaysAgo: number;
6
+ countThirtyDaysAgo: number;
7
+ countOneYearAgo: number;
8
+ }
9
+ export interface FormHeadlineMetric {
10
+ type: FormMetricType.HeadlineMetric;
11
+ headlineCounts: Record<string, FormHeadlineDetail>;
12
+ updatedAt: Date;
13
+ }
14
+ export interface FormOverviewMetric {
15
+ type: FormMetricType.OverviewMetric;
16
+ formId: string;
17
+ formStatus: FormStatus;
18
+ summaryMetrics: Record<string, number | string | string[]>;
19
+ featureCounts: Record<string, number>;
20
+ submissionsCount: number;
21
+ updatedAt: Date;
22
+ }
23
+ export interface FormTimelineMetric {
24
+ type: FormMetricType.TimelineMetric;
25
+ formId: string;
26
+ formStatus: FormStatus;
27
+ metricName: string;
28
+ metricValue: number;
29
+ createdAt: Date;
30
+ }
31
+ export type FormMetric = FormHeadlineMetric | FormOverviewMetric | FormTimelineMetric;
32
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/form/form-metrics/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,kCAAkC,CAAA;AAEtE,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,iBAAiB,EAAE,MAAM,CAAA;IACzB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,cAAc,CAAC,cAAc,CAAA;IACnC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAA;IAClD,SAAS,EAAE,IAAI,CAAA;CAChB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,cAAc,CAAC,cAAc,CAAA;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,UAAU,CAAA;IACtB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,CAAA;IAC1D,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,gBAAgB,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,IAAI,CAAA;CAChB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,cAAc,CAAC,cAAc,CAAA;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,IAAI,CAAA;CAChB;AAED,MAAM,MAAM,UAAU,GAClB,kBAAkB,GAClB,kBAAkB,GAClB,kBAAkB,CAAA"}
@@ -10,6 +10,8 @@ export * from './form/form-definition/index.js';
10
10
  export * from './form/form-definition/types.js';
11
11
  export * from './form/form-definition/helpers.js';
12
12
  export * from './form/form-metadata/index.js';
13
+ export * from './form/form-metrics/enums.js';
14
+ export * from './form/form-metrics/types.js';
13
15
  export * from './form/form-submission/index.js';
14
16
  export * from './form/form-submission/enums.js';
15
17
  export * from './form/utils/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,2BAA2B,CAAA;AACzC,cAAc,wBAAwB,CAAA;AACtC,cAAc,kCAAkC,CAAA;AAChD,cAAc,8BAA8B,CAAA;AAC5C,cAAc,+BAA+B,CAAA;AAC7C,cAAc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A2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,qCAAqC,CAAA;AACnD,cAAc,qCAAqC,CAAA;AACnD,cAAc,uCAAuC,CAAA;AACrD,cAAc,mCAAmC,CAAA;AACjD,cAAc,kCAAkC,CAAA;AAChD,cAAc,kCAAkC,CAAA;AAChD,cAAc,qCAAqC,CAAA;AACnD,cAAc,qCAAqC,CAAA;AACnD,cAAc,2BAA2B,CAAA;AACzC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,yCAAyC,CAAA;AACvD,cAAc,kCAAkC,CAAA;AAChD,cAAc,mCAAmC,CAAA;AACjD,cAAc,oCAAoC,CAAA;AAClD,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wCAAwC,CAAA;AAEtD,mBAAmB,uBAAuB,CAAA;AAC1C,mBAAmB,kCAAkC,CAAA;AACrD,mBAAmB,8BAA8B,CAAA;AACjD,mBAAmB,+BAA+B,CAAA;AAClD,mBAAmB,2BAA2B,CAAA;AAC9C,mBAAmB,2BAA2B,CAAA;AAC9C,mBAAmB,qCAAqC,CAAA;AACxD,mBAAmB,mCAAmC,CAAA;AACtD,mBAAmB,qCAAqC,CAAA;AACxD,mBAAmB,yCAAyC,CAAA;AAC5D,mBAAmB,iCAAiC,CAAA;AACpD,mBAAmB,wCAAwC,CAAA;AAC3D,mBAAmB,gCAAgC,CAAA;AACnD,mBAAmB,uBAAuB,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { ComponentType } from '../components/enums.js';
1
2
  import { type ComponentDef } from '../components/types.js';
2
3
  import { type Link, type Page, type PageFileUpload, type PageQuestion, type PageRepeat } from '../form/form-definition/types.js';
3
4
  import { type FormDefinition } from '../index.js';
@@ -44,6 +45,14 @@ export declare function controllerNameFromPath(nameOrPath?: ControllerType | str
44
45
  export declare function includesFileUploadField(components: ComponentDef[]): boolean;
45
46
  export declare function onlyDeclarationComponents(components: ComponentDef[]): boolean;
46
47
  export declare function includesPaymentField(components: ComponentDef[]): boolean;
48
+ /**
49
+ * Helper function to determine if a payment question already exists in the form
50
+ */
51
+ export declare function hasPaymentQuestionInForm(definition: FormDefinition): boolean;
52
+ /**
53
+ * Helper function to determine if a specific question type exists in the form
54
+ */
55
+ export declare function hasSpecificQuestionTypeInForm(definition: FormDefinition, componentType: ComponentType): boolean;
47
56
  export declare function showRepeaterSettings(page: Page): boolean;
48
57
  /**
49
58
  * Gets page title, or title of first question (if no page title set)
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/pages/helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EACL,KAAK,IAAI,EACT,KAAK,IAAI,EACT,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,UAAU,EAChB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAKpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGrD;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,SAAS,IAAI,EACnD,IAAI,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,GAaC,QAAQ,CAC7C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,GACnB,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE;IAAE,UAAU,EAAE,YAAY,EAAE,CAAA;CAAE,CAAC,CAEvD;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,GACnB,IAAI,IAAI,OAAO,C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I,GAAG,SAAS,WAInD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,cAAc,GAwB5D,cAAc,CACpB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,WAOnD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,WAE/C"}
@@ -1,5 +1,5 @@
1
1
  export { ControllerNames, ControllerTypes } from '../pages/controller-types.js';
2
2
  export { PageTypes } from '../pages/page-types.js';
3
- export { controllerNameFromPath, getPageDefaults, getPageFromDefinition, getPageTitle, hasComponents, hasComponentsEvenIfNoNext, hasFormComponents, hasNext, hasRepeater, includesFileUploadField, includesPaymentField, isControllerName, isEndPage, isPaymentPage, isSummaryPage, replaceCustomControllers, showRepeaterSettings, summaryPageControllers } from '../pages/helpers.js';
3
+ export { controllerNameFromPath, getPageDefaults, getPageFromDefinition, getPageTitle, hasComponents, hasComponentsEvenIfNoNext, hasFormComponents, hasNext, hasPaymentQuestionInForm, hasRepeater, hasSpecificQuestionTypeInForm, includesFileUploadField, includesPaymentField, isControllerName, isEndPage, isPaymentPage, isSummaryPage, replaceCustomControllers, showRepeaterSettings, summaryPageControllers } from '../pages/helpers.js';
4
4
  export { ControllerPath, ControllerType } from '../pages/enums.js';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EAChB,MAAM,iCAAiC,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,yBAAyB,EACzB,iBAAiB,EACjB,OAAO,EACP,WAAW,EACX,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EAChB,MAAM,iCAAiC,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,yBAAyB,EACzB,iBAAiB,EACjB,OAAO,EACP,wBAAwB,EACxB,WAAW,EACX,6BAA6B,EAC7B,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/forms-model",
3
- "version": "3.0.644",
3
+ "version": "3.0.645",
4
4
  "description": "A hapi plugin providing the model for Defra forms",
5
5
  "homepage": "https://github.com/DEFRA/forms-designer/tree/main/model#readme",
6
6
  "types": "dist/types/index.d.ts",
@@ -0,0 +1,5 @@
1
+ export enum FormMetricType {
2
+ HeadlineMetric = 'headline-metric',
3
+ OverviewMetric = 'overview-metric',
4
+ TimelineMetric = 'timeline-metric'
5
+ }
@@ -0,0 +1,39 @@
1
+ import { type FormStatus } from '~/src/common/enums.js'
2
+ import { type FormMetricType } from '~/src/form/form-metrics/enums.js'
3
+
4
+ export interface FormHeadlineDetail {
5
+ count: number
6
+ countSevenDaysAgo: number
7
+ countThirtyDaysAgo: number
8
+ countOneYearAgo: number
9
+ }
10
+
11
+ export interface FormHeadlineMetric {
12
+ type: FormMetricType.HeadlineMetric
13
+ headlineCounts: Record<string, FormHeadlineDetail>
14
+ updatedAt: Date
15
+ }
16
+
17
+ export interface FormOverviewMetric {
18
+ type: FormMetricType.OverviewMetric
19
+ formId: string
20
+ formStatus: FormStatus
21
+ summaryMetrics: Record<string, number | string | string[]>
22
+ featureCounts: Record<string, number>
23
+ submissionsCount: number
24
+ updatedAt: Date
25
+ }
26
+
27
+ export interface FormTimelineMetric {
28
+ type: FormMetricType.TimelineMetric
29
+ formId: string
30
+ formStatus: FormStatus
31
+ metricName: string
32
+ metricValue: number
33
+ createdAt: Date
34
+ }
35
+
36
+ export type FormMetric =
37
+ | FormHeadlineMetric
38
+ | FormOverviewMetric
39
+ | FormTimelineMetric
package/src/index.ts CHANGED
@@ -10,6 +10,8 @@ export * from '~/src/form/form-definition/index.js'
10
10
  export * from '~/src/form/form-definition/types.js'
11
11
  export * from '~/src/form/form-definition/helpers.js'
12
12
  export * from '~/src/form/form-metadata/index.js'
13
+ export * from '~/src/form/form-metrics/enums.js'
14
+ export * from '~/src/form/form-metrics/types.js'
13
15
  export * from '~/src/form/form-submission/index.js'
14
16
  export * from '~/src/form/form-submission/enums.js'
15
17
  export * from '~/src/form/utils/index.js'
@@ -135,6 +135,47 @@ export function includesPaymentField(components: ComponentDef[]): boolean {
135
135
  )
136
136
  }
137
137
 
138
+ /**
139
+ * Helper function to determine if a payment question already exists in the form
140
+ */
141
+ export function hasPaymentQuestionInForm(definition: FormDefinition) {
142
+ if (definition.pages.length === 0) {
143
+ return false
144
+ }
145
+
146
+ for (const page of definition.pages) {
147
+ const hasPayment = hasComponents(page)
148
+ ? includesPaymentField(page.components)
149
+ : false
150
+ if (hasPayment) {
151
+ return true
152
+ }
153
+ }
154
+ return false
155
+ }
156
+
157
+ /**
158
+ * Helper function to determine if a specific question type exists in the form
159
+ */
160
+ export function hasSpecificQuestionTypeInForm(
161
+ definition: FormDefinition,
162
+ componentType: ComponentType
163
+ ) {
164
+ if (definition.pages.length === 0) {
165
+ return false
166
+ }
167
+
168
+ for (const page of definition.pages) {
169
+ const hasPayment = hasComponents(page)
170
+ ? page.components.some((component) => component.type === componentType)
171
+ : false
172
+ if (hasPayment) {
173
+ return true
174
+ }
175
+ }
176
+ return false
177
+ }
178
+
138
179
  const SHOW_REPEATER_CONTROLLERS = [ControllerType.Page, ControllerType.Repeat]
139
180
 
140
181
  export function showRepeaterSettings(page: Page): boolean {
@@ -207,6 +248,7 @@ export function replaceCustomControllers(definition: FormDefinition) {
207
248
  const standardControllers = new Set(
208
249
  Object.values(ControllerType)
209
250
  .filter((x) => x !== ControllerType.SummaryWithConfirmationEmail)
251
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion
210
252
  .map((x) => x.toString())
211
253
  )
212
254
 
@@ -215,6 +257,7 @@ export function replaceCustomControllers(definition: FormDefinition) {
215
257
  pages: definition.pages.map((page) => {
216
258
  if (
217
259
  !standardControllers.has(
260
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion
218
261
  (page.controller ?? ControllerType.Page).toString()
219
262
  )
220
263
  ) {
@@ -14,7 +14,9 @@ export {
14
14
  hasComponentsEvenIfNoNext,
15
15
  hasFormComponents,
16
16
  hasNext,
17
+ hasPaymentQuestionInForm,
17
18
  hasRepeater,
19
+ hasSpecificQuestionTypeInForm,
18
20
  includesFileUploadField,
19
21
  includesPaymentField,
20
22
  isControllerName,