@defra/forms-engine-plugin 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.server/server/forms/report-a-terrorist.json +7 -7
- package/.server/server/forms/runner-components-test.json +10 -10
- package/.server/server/forms/test.yaml +363 -0
- package/.server/server/utils/file-form-service.js +134 -0
- package/.server/server/utils/file-form-service.js.map +1 -0
- package/.server/server/utils/file-form-service.test.js +52 -0
- package/.server/server/utils/file-form-service.test.js.map +1 -0
- package/README.md +3 -1
- package/package.json +6 -3
- package/src/server/forms/report-a-terrorist.json +7 -7
- package/src/server/forms/runner-components-test.json +10 -10
- package/src/server/forms/test.yaml +363 -0
- package/src/server/plugins/engine/components/AutocompleteField.test.ts +5 -5
- package/src/server/plugins/engine/components/CheckboxesField.test.ts +7 -7
- package/src/server/plugins/engine/components/List.test.ts +3 -0
- package/src/server/plugins/engine/components/RadiosField.test.ts +5 -5
- package/src/server/plugins/engine/components/SelectField.test.ts +5 -5
- package/src/server/plugins/engine/pageControllers/QuestionPageController.test.ts +4 -0
- package/src/server/utils/file-form-service.js +144 -0
- package/src/server/utils/file-form-service.test.js +79 -0
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"schema": {}
|
|
55
55
|
},
|
|
56
56
|
{
|
|
57
|
-
"name": "
|
|
57
|
+
"name": "ajdOpV",
|
|
58
58
|
"options": {},
|
|
59
59
|
"type": "Details",
|
|
60
60
|
"title": "Help me take a screenshot",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"schema": {}
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
|
-
"name": "
|
|
65
|
+
"name": "LUBRMD",
|
|
66
66
|
"options": {},
|
|
67
67
|
"type": "RadiosField",
|
|
68
68
|
"title": "Do you have any evidence?",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"title": "Is there anything else you can tell us?",
|
|
93
93
|
"components": [
|
|
94
94
|
{
|
|
95
|
-
"name": "
|
|
95
|
+
"name": "HETMBo",
|
|
96
96
|
"title": "Html",
|
|
97
97
|
"options": {},
|
|
98
98
|
"type": "Html",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"schema": {}
|
|
101
101
|
},
|
|
102
102
|
{
|
|
103
|
-
"name": "
|
|
103
|
+
"name": "evZxIJ",
|
|
104
104
|
"options": {
|
|
105
105
|
"required": false
|
|
106
106
|
},
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
"title": "Yes I have evidence",
|
|
142
142
|
"components": [
|
|
143
143
|
{
|
|
144
|
-
"name": "
|
|
144
|
+
"name": "koExae",
|
|
145
145
|
"options": {
|
|
146
146
|
"required": false
|
|
147
147
|
},
|
|
@@ -230,7 +230,7 @@
|
|
|
230
230
|
"conditions": [
|
|
231
231
|
{
|
|
232
232
|
"field": {
|
|
233
|
-
"name": "PMXq1s.
|
|
233
|
+
"name": "PMXq1s.LUBRMD",
|
|
234
234
|
"type": "RadiosField",
|
|
235
235
|
"display": "Do you have any evidence? in PMXq1s"
|
|
236
236
|
},
|
|
@@ -252,7 +252,7 @@
|
|
|
252
252
|
"conditions": [
|
|
253
253
|
{
|
|
254
254
|
"field": {
|
|
255
|
-
"name": "PMXq1s.
|
|
255
|
+
"name": "PMXq1s.LUBRMD",
|
|
256
256
|
"type": "RadiosField",
|
|
257
257
|
"display": "Do you have any evidence? in PMXq1s"
|
|
258
258
|
},
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"path": "/do-you-own-a-vehicle",
|
|
7
7
|
"components": [
|
|
8
8
|
{
|
|
9
|
-
"name": "
|
|
9
|
+
"name": "qqbRwx",
|
|
10
10
|
"options": {},
|
|
11
11
|
"type": "YesNoField",
|
|
12
12
|
"title": "Do you own a vehicle?",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"title": "What address is the vehicle registered to?",
|
|
33
33
|
"components": [
|
|
34
34
|
{
|
|
35
|
-
"name": "
|
|
35
|
+
"name": "sFRxaX",
|
|
36
36
|
"options": {},
|
|
37
37
|
"type": "UkAddressField",
|
|
38
38
|
"title": "What address is the vehicle registered to?",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"schema": {}
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
-
"name": "
|
|
49
|
+
"name": "ZxGuyn",
|
|
50
50
|
"options": {},
|
|
51
51
|
"type": "CheckboxesField",
|
|
52
52
|
"title": "Which Clean Air Zones are you claiming an exemption for?",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"title": "Clean Air Zone (CAZ) Exemption",
|
|
67
67
|
"components": [
|
|
68
68
|
{
|
|
69
|
-
"name": "
|
|
69
|
+
"name": "MOBxxt",
|
|
70
70
|
"title": "Html",
|
|
71
71
|
"options": {},
|
|
72
72
|
"type": "Html",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"title": "Details about your vehicle",
|
|
87
87
|
"components": [
|
|
88
88
|
{
|
|
89
|
-
"name": "
|
|
89
|
+
"name": "xZVmNx",
|
|
90
90
|
"options": {},
|
|
91
91
|
"type": "AutocompleteField",
|
|
92
92
|
"title": "What is the make of you vehicle?",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"schema": {}
|
|
95
95
|
},
|
|
96
96
|
{
|
|
97
|
-
"name": "
|
|
97
|
+
"name": "gHSgox",
|
|
98
98
|
"options": {},
|
|
99
99
|
"type": "TextField",
|
|
100
100
|
"title": "Vehicle Model",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"schema": {}
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
|
-
"name": "
|
|
105
|
+
"name": "xLZxto",
|
|
106
106
|
"options": {},
|
|
107
107
|
"type": "DatePartsField",
|
|
108
108
|
"title": "Date you purchased the vehicle?",
|
|
@@ -152,7 +152,7 @@
|
|
|
152
152
|
"schema": {}
|
|
153
153
|
},
|
|
154
154
|
{
|
|
155
|
-
"name": "
|
|
155
|
+
"name": "xzLxbB",
|
|
156
156
|
"options": {},
|
|
157
157
|
"type": "TelephoneNumberField",
|
|
158
158
|
"title": "Contact number",
|
|
@@ -171,7 +171,7 @@
|
|
|
171
171
|
"title": "final steps",
|
|
172
172
|
"components": [
|
|
173
173
|
{
|
|
174
|
-
"name": "
|
|
174
|
+
"name": "fkdxav",
|
|
175
175
|
"options": {},
|
|
176
176
|
"type": "List",
|
|
177
177
|
"title": "Declaration",
|
|
@@ -179,7 +179,7 @@
|
|
|
179
179
|
"schema": {}
|
|
180
180
|
},
|
|
181
181
|
{
|
|
182
|
-
"name": "
|
|
182
|
+
"name": "LxxAYe",
|
|
183
183
|
"options": {},
|
|
184
184
|
"type": "EmailAddressField",
|
|
185
185
|
"title": "Your email address",
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
---
|
|
2
|
+
startPage: "/start"
|
|
3
|
+
pages:
|
|
4
|
+
- title: Start
|
|
5
|
+
path: "/start"
|
|
6
|
+
components: []
|
|
7
|
+
next:
|
|
8
|
+
- path: "/uk-passport"
|
|
9
|
+
controller: StartPageController
|
|
10
|
+
- path: "/uk-passport"
|
|
11
|
+
components:
|
|
12
|
+
- type: YesNoField
|
|
13
|
+
name: ukPassport
|
|
14
|
+
title: Do you have a UK passport?
|
|
15
|
+
options:
|
|
16
|
+
required: true
|
|
17
|
+
schema: {}
|
|
18
|
+
section: checkBeforeYouStart
|
|
19
|
+
next:
|
|
20
|
+
- path: "/how-many-people"
|
|
21
|
+
- path: "/no-uk-passport"
|
|
22
|
+
condition: doesntHaveUKPassport
|
|
23
|
+
title: Do you have a UK passport?
|
|
24
|
+
- path: "/no-uk-passport"
|
|
25
|
+
title: You're not eligible for this service
|
|
26
|
+
components:
|
|
27
|
+
- type: Html
|
|
28
|
+
name: html
|
|
29
|
+
title: Html
|
|
30
|
+
content: >-
|
|
31
|
+
<p class="govuk-body">
|
|
32
|
+
If you still think you're eligible please contact the Foreign and Commonwealth Office.
|
|
33
|
+
</p>
|
|
34
|
+
options: {}
|
|
35
|
+
schema: {}
|
|
36
|
+
next: []
|
|
37
|
+
- path: "/how-many-people"
|
|
38
|
+
section: applicantDetails
|
|
39
|
+
components:
|
|
40
|
+
- options:
|
|
41
|
+
classes: govuk-input--width-10
|
|
42
|
+
required: true
|
|
43
|
+
type: SelectField
|
|
44
|
+
name: numberOfApplicants
|
|
45
|
+
title: How many applicants are there?
|
|
46
|
+
list: numberOfApplicants
|
|
47
|
+
next:
|
|
48
|
+
- path: "/applicant-one"
|
|
49
|
+
title: How many applicants are there?
|
|
50
|
+
- path: "/applicant-one"
|
|
51
|
+
title: Applicant 1
|
|
52
|
+
section: applicantOneDetails
|
|
53
|
+
components:
|
|
54
|
+
- type: Html
|
|
55
|
+
name: html
|
|
56
|
+
title: Html
|
|
57
|
+
content: <p class="govuk-body">Provide the details as they appear on your passport.</p>
|
|
58
|
+
options: {}
|
|
59
|
+
schema: {}
|
|
60
|
+
- type: TextField
|
|
61
|
+
name: firstName
|
|
62
|
+
title: First name
|
|
63
|
+
options:
|
|
64
|
+
required: true
|
|
65
|
+
schema: {}
|
|
66
|
+
- options:
|
|
67
|
+
required: false
|
|
68
|
+
optionalText: false
|
|
69
|
+
type: TextField
|
|
70
|
+
name: middleName
|
|
71
|
+
title: Middle name
|
|
72
|
+
hint: If you have a middle name on your passport you must include it here
|
|
73
|
+
schema: {}
|
|
74
|
+
- type: TextField
|
|
75
|
+
name: lastName
|
|
76
|
+
title: Surname
|
|
77
|
+
options:
|
|
78
|
+
required: true
|
|
79
|
+
schema: {}
|
|
80
|
+
next:
|
|
81
|
+
- path: "/applicant-one-address"
|
|
82
|
+
- path: "/applicant-one-address"
|
|
83
|
+
section: applicantOneDetails
|
|
84
|
+
components:
|
|
85
|
+
- type: UkAddressField
|
|
86
|
+
name: address
|
|
87
|
+
title: Address
|
|
88
|
+
options:
|
|
89
|
+
required: true
|
|
90
|
+
schema: {}
|
|
91
|
+
next:
|
|
92
|
+
- path: "/applicant-two"
|
|
93
|
+
condition: moreThanOneApplicant
|
|
94
|
+
- path: "/contact-details"
|
|
95
|
+
title: Address
|
|
96
|
+
- path: "/applicant-two"
|
|
97
|
+
title: Applicant 2
|
|
98
|
+
section: applicantTwoDetails
|
|
99
|
+
components:
|
|
100
|
+
- type: Html
|
|
101
|
+
name: html
|
|
102
|
+
title: Html
|
|
103
|
+
content: <p class="govuk-body">Provide the details as they appear on your passport.</p>
|
|
104
|
+
options: {}
|
|
105
|
+
schema: {}
|
|
106
|
+
- type: TextField
|
|
107
|
+
name: firstName
|
|
108
|
+
title: First name
|
|
109
|
+
options:
|
|
110
|
+
required: true
|
|
111
|
+
schema: {}
|
|
112
|
+
- options:
|
|
113
|
+
required: false
|
|
114
|
+
optionalText: false
|
|
115
|
+
type: TextField
|
|
116
|
+
name: middleName
|
|
117
|
+
title: Middle name
|
|
118
|
+
hint: If you have a middle name on your passport you must include it here
|
|
119
|
+
schema: {}
|
|
120
|
+
- type: TextField
|
|
121
|
+
name: lastName
|
|
122
|
+
title: Surname
|
|
123
|
+
options:
|
|
124
|
+
required: true
|
|
125
|
+
schema: {}
|
|
126
|
+
next:
|
|
127
|
+
- path: "/applicant-two-address"
|
|
128
|
+
- path: "/applicant-two-address"
|
|
129
|
+
section: applicantTwoDetails
|
|
130
|
+
components:
|
|
131
|
+
- type: UkAddressField
|
|
132
|
+
name: address
|
|
133
|
+
title: Address
|
|
134
|
+
options:
|
|
135
|
+
required: true
|
|
136
|
+
schema: {}
|
|
137
|
+
next:
|
|
138
|
+
- path: "/applicant-three"
|
|
139
|
+
condition: moreThanTwoApplicants
|
|
140
|
+
- path: "/contact-details"
|
|
141
|
+
title: Address
|
|
142
|
+
- path: "/applicant-three"
|
|
143
|
+
title: Applicant 3
|
|
144
|
+
section: applicantThreeDetails
|
|
145
|
+
components:
|
|
146
|
+
- type: Html
|
|
147
|
+
name: html
|
|
148
|
+
title: Html
|
|
149
|
+
content: <p class="govuk-body">Provide the details as they appear on your passport.</p>
|
|
150
|
+
options: {}
|
|
151
|
+
schema: {}
|
|
152
|
+
- type: TextField
|
|
153
|
+
name: firstName
|
|
154
|
+
title: First name
|
|
155
|
+
options:
|
|
156
|
+
required: true
|
|
157
|
+
schema: {}
|
|
158
|
+
- options:
|
|
159
|
+
required: false
|
|
160
|
+
optionalText: false
|
|
161
|
+
type: TextField
|
|
162
|
+
name: middleName
|
|
163
|
+
title: Middle name
|
|
164
|
+
hint: If you have a middle name on your passport you must include it here
|
|
165
|
+
schema: {}
|
|
166
|
+
- type: TextField
|
|
167
|
+
name: lastName
|
|
168
|
+
title: Surname
|
|
169
|
+
options:
|
|
170
|
+
required: true
|
|
171
|
+
schema: {}
|
|
172
|
+
next:
|
|
173
|
+
- path: "/applicant-three-address"
|
|
174
|
+
- path: "/applicant-three-address"
|
|
175
|
+
section: applicantThreeDetails
|
|
176
|
+
components:
|
|
177
|
+
- type: UkAddressField
|
|
178
|
+
name: address
|
|
179
|
+
title: Address
|
|
180
|
+
options:
|
|
181
|
+
required: true
|
|
182
|
+
schema: {}
|
|
183
|
+
next:
|
|
184
|
+
- path: "/applicant-four"
|
|
185
|
+
condition: moreThanThreeApplicants
|
|
186
|
+
- path: "/contact-details"
|
|
187
|
+
title: Address
|
|
188
|
+
- path: "/applicant-four"
|
|
189
|
+
title: Applicant 4
|
|
190
|
+
section: applicantFourDetails
|
|
191
|
+
components:
|
|
192
|
+
- type: Html
|
|
193
|
+
name: html
|
|
194
|
+
title: Html
|
|
195
|
+
content: <p class="govuk-body">Provide the details as they appear on your passport.</p>
|
|
196
|
+
options: {}
|
|
197
|
+
schema: {}
|
|
198
|
+
- type: TextField
|
|
199
|
+
name: firstName
|
|
200
|
+
title: First name
|
|
201
|
+
options:
|
|
202
|
+
required: true
|
|
203
|
+
schema: {}
|
|
204
|
+
- options:
|
|
205
|
+
required: false
|
|
206
|
+
optionalText: false
|
|
207
|
+
type: TextField
|
|
208
|
+
name: middleName
|
|
209
|
+
title: Middle name
|
|
210
|
+
hint: If you have a middle name on your passport you must include it here
|
|
211
|
+
schema: {}
|
|
212
|
+
- type: TextField
|
|
213
|
+
name: lastName
|
|
214
|
+
title: Surname
|
|
215
|
+
options:
|
|
216
|
+
required: true
|
|
217
|
+
schema: {}
|
|
218
|
+
next:
|
|
219
|
+
- path: "/applicant-four-address"
|
|
220
|
+
- path: "/applicant-four-address"
|
|
221
|
+
section: applicantFourDetails
|
|
222
|
+
components:
|
|
223
|
+
- type: UkAddressField
|
|
224
|
+
name: address
|
|
225
|
+
title: Address
|
|
226
|
+
options:
|
|
227
|
+
required: true
|
|
228
|
+
schema: {}
|
|
229
|
+
next:
|
|
230
|
+
- path: "/contact-details"
|
|
231
|
+
title: Address
|
|
232
|
+
- path: "/contact-details"
|
|
233
|
+
section: applicantDetails
|
|
234
|
+
components:
|
|
235
|
+
- type: TelephoneNumberField
|
|
236
|
+
name: phoneNumber
|
|
237
|
+
title: Phone number
|
|
238
|
+
hint: If you haven't got a UK phone number, include country code
|
|
239
|
+
options:
|
|
240
|
+
required: true
|
|
241
|
+
schema: {}
|
|
242
|
+
- type: EmailAddressField
|
|
243
|
+
name: emailAddress
|
|
244
|
+
title: Your email address
|
|
245
|
+
options:
|
|
246
|
+
required: true
|
|
247
|
+
schema: {}
|
|
248
|
+
next:
|
|
249
|
+
- path: "/summary"
|
|
250
|
+
title: Applicant contact details
|
|
251
|
+
- path: "/summary"
|
|
252
|
+
controller: SummaryPageController
|
|
253
|
+
title: Summary
|
|
254
|
+
components: []
|
|
255
|
+
next: []
|
|
256
|
+
lists:
|
|
257
|
+
- name: numberOfApplicants
|
|
258
|
+
title: Number of people
|
|
259
|
+
type: number
|
|
260
|
+
items:
|
|
261
|
+
- text: '1'
|
|
262
|
+
value: 1
|
|
263
|
+
description: ''
|
|
264
|
+
condition: ''
|
|
265
|
+
- text: '2'
|
|
266
|
+
value: 2
|
|
267
|
+
description: ''
|
|
268
|
+
condition: ''
|
|
269
|
+
- text: '3'
|
|
270
|
+
value: 3
|
|
271
|
+
description: ''
|
|
272
|
+
condition: ''
|
|
273
|
+
- text: '4'
|
|
274
|
+
value: 4
|
|
275
|
+
description: ''
|
|
276
|
+
condition: ''
|
|
277
|
+
sections:
|
|
278
|
+
- name: checkBeforeYouStart
|
|
279
|
+
title: Check before you start
|
|
280
|
+
- name: applicantDetails
|
|
281
|
+
title: Applicant details
|
|
282
|
+
- name: applicantOneDetails
|
|
283
|
+
title: Applicant 1
|
|
284
|
+
- name: applicantTwoDetails
|
|
285
|
+
title: Applicant 2
|
|
286
|
+
- name: applicantThreeDetails
|
|
287
|
+
title: Applicant 3
|
|
288
|
+
- name: applicantFourDetails
|
|
289
|
+
title: Applicant 4
|
|
290
|
+
phaseBanner: {}
|
|
291
|
+
declaration: <p class="govuk-body">All the answers you have provided are true to the
|
|
292
|
+
best of your knowledge.</p>
|
|
293
|
+
conditions:
|
|
294
|
+
- name: hasUKPassport
|
|
295
|
+
displayName: hasUKPassport
|
|
296
|
+
value:
|
|
297
|
+
name: hasUKPassport
|
|
298
|
+
conditions:
|
|
299
|
+
- field:
|
|
300
|
+
name: checkBeforeYouStart.ukPassport
|
|
301
|
+
type: YesNoField
|
|
302
|
+
display: Do you have a UK passport?
|
|
303
|
+
operator: is
|
|
304
|
+
value:
|
|
305
|
+
type: Value
|
|
306
|
+
value: 'true'
|
|
307
|
+
display: 'true'
|
|
308
|
+
- name: doesntHaveUKPassport
|
|
309
|
+
displayName: doesntHaveUKPassport
|
|
310
|
+
value:
|
|
311
|
+
name: doesntHaveUKPassport
|
|
312
|
+
conditions:
|
|
313
|
+
- field:
|
|
314
|
+
name: checkBeforeYouStart.ukPassport
|
|
315
|
+
type: YesNoField
|
|
316
|
+
display: Do you have a UK passport?
|
|
317
|
+
operator: is
|
|
318
|
+
value:
|
|
319
|
+
type: Value
|
|
320
|
+
value: 'false'
|
|
321
|
+
display: 'false'
|
|
322
|
+
- name: moreThanOneApplicant
|
|
323
|
+
displayName: moreThanOneApplicant
|
|
324
|
+
value:
|
|
325
|
+
name: moreThanOneApplicant
|
|
326
|
+
conditions:
|
|
327
|
+
- field:
|
|
328
|
+
name: applicantDetails.numberOfApplicants
|
|
329
|
+
type: SelectField
|
|
330
|
+
display: How many applicants are there?
|
|
331
|
+
operator: is more than
|
|
332
|
+
value:
|
|
333
|
+
type: Value
|
|
334
|
+
value: '1'
|
|
335
|
+
display: '1'
|
|
336
|
+
- name: moreThanTwoApplicants
|
|
337
|
+
displayName: moreThanTwoApplicants
|
|
338
|
+
value:
|
|
339
|
+
name: moreThanTwoApplicants
|
|
340
|
+
conditions:
|
|
341
|
+
- field:
|
|
342
|
+
name: applicantDetails.numberOfApplicants
|
|
343
|
+
type: SelectField
|
|
344
|
+
display: How many applicants are there?
|
|
345
|
+
operator: is more than
|
|
346
|
+
value:
|
|
347
|
+
type: Value
|
|
348
|
+
value: '2'
|
|
349
|
+
display: '2'
|
|
350
|
+
- name: moreThanThreeApplicants
|
|
351
|
+
displayName: moreThanThreeApplicants
|
|
352
|
+
value:
|
|
353
|
+
name: moreThanThreeApplicants
|
|
354
|
+
conditions:
|
|
355
|
+
- field:
|
|
356
|
+
name: applicantDetails.numberOfApplicants
|
|
357
|
+
type: SelectField
|
|
358
|
+
display: How many applicants are there?
|
|
359
|
+
operator: is more than
|
|
360
|
+
value:
|
|
361
|
+
type: Value
|
|
362
|
+
value: '3'
|
|
363
|
+
display: '3'
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import YAML from 'yaml';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* FileFormService class
|
|
7
|
+
*/
|
|
8
|
+
export class FileFormService {
|
|
9
|
+
/**
|
|
10
|
+
* The map of form metadatas by slug
|
|
11
|
+
* @type {Map<string, FormMetadata>}
|
|
12
|
+
*/
|
|
13
|
+
#metadata = new Map();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The map of form definitions by id
|
|
17
|
+
* @type {Map<string, FormDefinition>}
|
|
18
|
+
*/
|
|
19
|
+
#definition = new Map();
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Add form from a file
|
|
23
|
+
* @param {string} filepath - the file path
|
|
24
|
+
* @param {FormMetadata} metadata - the metadata to use for this form
|
|
25
|
+
* @returns {Promise<FormDefinition>}
|
|
26
|
+
*/
|
|
27
|
+
async addForm(filepath, metadata) {
|
|
28
|
+
const definition = await this.readForm(filepath);
|
|
29
|
+
this.#metadata.set(metadata.slug, metadata);
|
|
30
|
+
this.#definition.set(metadata.id, definition);
|
|
31
|
+
return definition;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Read the form definition from file
|
|
36
|
+
* @param {string} filepath - the file path
|
|
37
|
+
* @returns {Promise<FormDefinition>}
|
|
38
|
+
*/
|
|
39
|
+
async readForm(filepath) {
|
|
40
|
+
const ext = path.extname(filepath).toLowerCase();
|
|
41
|
+
switch (ext) {
|
|
42
|
+
case '.json':
|
|
43
|
+
return this.readJsonForm(filepath);
|
|
44
|
+
case '.yaml':
|
|
45
|
+
return this.readYamlForm(filepath);
|
|
46
|
+
default:
|
|
47
|
+
throw new Error(`Invalid file extension '${ext}'`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Read the form definition from a json file
|
|
53
|
+
* @param {string} filepath - the file path
|
|
54
|
+
* @returns {Promise<FormDefinition>}
|
|
55
|
+
*/
|
|
56
|
+
async readJsonForm(filepath) {
|
|
57
|
+
/**
|
|
58
|
+
* @type {FormDefinition}
|
|
59
|
+
*/
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
61
|
+
const definition = JSON.parse(await fs.readFile(filepath, 'utf8'));
|
|
62
|
+
return definition;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Read the form definition from a yaml file
|
|
67
|
+
* @param {string} filepath - the file path
|
|
68
|
+
* @returns {Promise<FormDefinition>}
|
|
69
|
+
*/
|
|
70
|
+
async readYamlForm(filepath) {
|
|
71
|
+
/**
|
|
72
|
+
* @type {FormDefinition}
|
|
73
|
+
*/
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
75
|
+
const definition = YAML.parse(await fs.readFile(filepath, 'utf8'));
|
|
76
|
+
return definition;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get the form metadata by slug
|
|
81
|
+
* @param {string} slug - the form slug
|
|
82
|
+
* @returns {FormMetadata}
|
|
83
|
+
*/
|
|
84
|
+
getFormMetadata(slug) {
|
|
85
|
+
const metadata = this.#metadata.get(slug);
|
|
86
|
+
if (!metadata) {
|
|
87
|
+
throw new Error(`Form metadata '${slug}' not found`);
|
|
88
|
+
}
|
|
89
|
+
return metadata;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get the form defintion by id
|
|
94
|
+
* @param {string} id - the form id
|
|
95
|
+
* @returns {FormDefinition}
|
|
96
|
+
*/
|
|
97
|
+
getFormDefinition(id) {
|
|
98
|
+
const definition = this.#definition.get(id);
|
|
99
|
+
if (!definition) {
|
|
100
|
+
throw new Error(`Form definition '${id}' not found`);
|
|
101
|
+
}
|
|
102
|
+
return definition;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Returns a FormsService compliant interface
|
|
107
|
+
* @returns {import('~/src/server/types.js').FormsService}
|
|
108
|
+
*/
|
|
109
|
+
toFormsService() {
|
|
110
|
+
return {
|
|
111
|
+
/**
|
|
112
|
+
* Get the form metadata by slug
|
|
113
|
+
* @param {string} slug
|
|
114
|
+
* @returns {Promise<FormMetadata>}
|
|
115
|
+
*/
|
|
116
|
+
getFormMetadata: slug => {
|
|
117
|
+
return Promise.resolve(this.getFormMetadata(slug));
|
|
118
|
+
},
|
|
119
|
+
/**
|
|
120
|
+
* Get the form defintion by id
|
|
121
|
+
* @param {string} id
|
|
122
|
+
* @returns {Promise<FormDefinition>}
|
|
123
|
+
*/
|
|
124
|
+
getFormDefinition: id => {
|
|
125
|
+
return Promise.resolve(this.getFormDefinition(id));
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @import { FormMetadata, FormDefinition } from '@defra/forms-model'
|
|
133
|
+
*/
|
|
134
|
+
//# sourceMappingURL=file-form-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-form-service.js","names":["fs","path","YAML","FileFormService","metadata","Map","definition","addForm","filepath","readForm","set","slug","id","ext","extname","toLowerCase","readJsonForm","readYamlForm","Error","JSON","parse","readFile","getFormMetadata","get","getFormDefinition","toFormsService","Promise","resolve"],"sources":["../../../src/server/utils/file-form-service.js"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'node:path'\n\nimport YAML from 'yaml'\n\n/**\n * FileFormService class\n */\nexport class FileFormService {\n /**\n * The map of form metadatas by slug\n * @type {Map<string, FormMetadata>}\n */\n #metadata = new Map()\n\n /**\n * The map of form definitions by id\n * @type {Map<string, FormDefinition>}\n */\n #definition = new Map()\n\n /**\n * Add form from a file\n * @param {string} filepath - the file path\n * @param {FormMetadata} metadata - the metadata to use for this form\n * @returns {Promise<FormDefinition>}\n */\n async addForm(filepath, metadata) {\n const definition = await this.readForm(filepath)\n\n this.#metadata.set(metadata.slug, metadata)\n this.#definition.set(metadata.id, definition)\n\n return definition\n }\n\n /**\n * Read the form definition from file\n * @param {string} filepath - the file path\n * @returns {Promise<FormDefinition>}\n */\n async readForm(filepath) {\n const ext = path.extname(filepath).toLowerCase()\n\n switch (ext) {\n case '.json':\n return this.readJsonForm(filepath)\n case '.yaml':\n return this.readYamlForm(filepath)\n default:\n throw new Error(`Invalid file extension '${ext}'`)\n }\n }\n\n /**\n * Read the form definition from a json file\n * @param {string} filepath - the file path\n * @returns {Promise<FormDefinition>}\n */\n async readJsonForm(filepath) {\n /**\n * @type {FormDefinition}\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const definition = JSON.parse(await fs.readFile(filepath, 'utf8'))\n\n return definition\n }\n\n /**\n * Read the form definition from a yaml file\n * @param {string} filepath - the file path\n * @returns {Promise<FormDefinition>}\n */\n async readYamlForm(filepath) {\n /**\n * @type {FormDefinition}\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const definition = YAML.parse(await fs.readFile(filepath, 'utf8'))\n\n return definition\n }\n\n /**\n * Get the form metadata by slug\n * @param {string} slug - the form slug\n * @returns {FormMetadata}\n */\n getFormMetadata(slug) {\n const metadata = this.#metadata.get(slug)\n\n if (!metadata) {\n throw new Error(`Form metadata '${slug}' not found`)\n }\n\n return metadata\n }\n\n /**\n * Get the form defintion by id\n * @param {string} id - the form id\n * @returns {FormDefinition}\n */\n getFormDefinition(id) {\n const definition = this.#definition.get(id)\n\n if (!definition) {\n throw new Error(`Form definition '${id}' not found`)\n }\n\n return definition\n }\n\n /**\n * Returns a FormsService compliant interface\n * @returns {import('~/src/server/types.js').FormsService}\n */\n toFormsService() {\n return {\n /**\n * Get the form metadata by slug\n * @param {string} slug\n * @returns {Promise<FormMetadata>}\n */\n getFormMetadata: (slug) => {\n return Promise.resolve(this.getFormMetadata(slug))\n },\n\n /**\n * Get the form defintion by id\n * @param {string} id\n * @returns {Promise<FormDefinition>}\n */\n getFormDefinition: (id) => {\n return Promise.resolve(this.getFormDefinition(id))\n }\n }\n }\n}\n\n/**\n * @import { FormMetadata, FormDefinition } from '@defra/forms-model'\n */\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,aAAa;AAC5B,OAAOC,IAAI,MAAM,WAAW;AAE5B,OAAOC,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,OAAO,MAAMC,eAAe,CAAC;EAC3B;AACF;AACA;AACA;EACE,CAACC,QAAQ,GAAG,IAAIC,GAAG,CAAC,CAAC;;EAErB;AACF;AACA;AACA;EACE,CAAC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