@defra/fcp-sfd-frontend-engine 0.9.1 → 0.10.0
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/dist/index.cjs +305 -273
- package/dist/index.js +304 -273
- package/package.json +2 -1
- package/src/index.js +3 -2
- package/src/mutations/mutations.js +5 -0
- package/src/mutations/personal/update-customer-name.js +15 -0
- package/src/utils/format-full-name.js +14 -0
- package/src/utils/utils.js +2 -0
package/dist/index.cjs
CHANGED
|
@@ -31,12 +31,106 @@ var index_exports = {};
|
|
|
31
31
|
__export(index_exports, {
|
|
32
32
|
constants: () => constants,
|
|
33
33
|
mappers: () => mappers,
|
|
34
|
+
mutations: () => mutations,
|
|
34
35
|
presenters: () => presenters,
|
|
35
36
|
schemas: () => schemas,
|
|
36
37
|
utils: () => utils
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(index_exports);
|
|
39
40
|
|
|
41
|
+
// src/constants/validation-fields.js
|
|
42
|
+
var FIRST_NAME_MAX = 100;
|
|
43
|
+
var LAST_NAME_MAX = 100;
|
|
44
|
+
var MIDDLE_NAMES_MAX = 100;
|
|
45
|
+
var BUSINESS_NAME_MAX = 160;
|
|
46
|
+
var EMAIL_MAX = 254;
|
|
47
|
+
var PHONE_NUMBER_MIN = 10;
|
|
48
|
+
var PHONE_NUMBER_MAX = 50;
|
|
49
|
+
var MAX_AGE_YEARS = 120;
|
|
50
|
+
var ADDRESS_LINE_MAX = 100;
|
|
51
|
+
var TOWN_CITY_MAX = 60;
|
|
52
|
+
var COUNTY_MAX = 60;
|
|
53
|
+
var COUNTRY_MAX = 60;
|
|
54
|
+
var POSTCODE_MAX = 8;
|
|
55
|
+
|
|
56
|
+
// src/constants/status-codes.js
|
|
57
|
+
var OK = 200;
|
|
58
|
+
var BAD_REQUEST = 400;
|
|
59
|
+
var UNAUTHORIZED = 401;
|
|
60
|
+
var FORBIDDEN = 403;
|
|
61
|
+
var NOT_FOUND = 404;
|
|
62
|
+
var NO_CONTENT = 204;
|
|
63
|
+
var FOUND = 302;
|
|
64
|
+
var INTERNAL_SERVER_ERROR = 500;
|
|
65
|
+
var SERVICE_UNAVAILABLE = 503;
|
|
66
|
+
|
|
67
|
+
// src/constants/patterns.js
|
|
68
|
+
var PHONE_NUMBER_PATTERN = /^\+?(?=[\d ()]*\d)[\d ()]*$/;
|
|
69
|
+
var NO_CONTROL_CHARS_PATTERN = /^[^\x00-\x1f\x7f-\x9f]*$/;
|
|
70
|
+
|
|
71
|
+
// src/constants/month-map.js
|
|
72
|
+
var MONTH_MAP = {
|
|
73
|
+
january: 1,
|
|
74
|
+
jan: 1,
|
|
75
|
+
february: 2,
|
|
76
|
+
feb: 2,
|
|
77
|
+
march: 3,
|
|
78
|
+
mar: 3,
|
|
79
|
+
april: 4,
|
|
80
|
+
apr: 4,
|
|
81
|
+
may: 5,
|
|
82
|
+
june: 6,
|
|
83
|
+
jun: 6,
|
|
84
|
+
july: 7,
|
|
85
|
+
jul: 7,
|
|
86
|
+
august: 8,
|
|
87
|
+
aug: 8,
|
|
88
|
+
september: 9,
|
|
89
|
+
sep: 9,
|
|
90
|
+
sept: 9,
|
|
91
|
+
october: 10,
|
|
92
|
+
oct: 10,
|
|
93
|
+
november: 11,
|
|
94
|
+
nov: 11,
|
|
95
|
+
december: 12,
|
|
96
|
+
dec: 12
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// src/constants/index.js
|
|
100
|
+
var constants = {
|
|
101
|
+
statusCodes: {
|
|
102
|
+
BAD_REQUEST,
|
|
103
|
+
UNAUTHORIZED,
|
|
104
|
+
FORBIDDEN,
|
|
105
|
+
NOT_FOUND,
|
|
106
|
+
OK,
|
|
107
|
+
NO_CONTENT,
|
|
108
|
+
FOUND,
|
|
109
|
+
INTERNAL_SERVER_ERROR,
|
|
110
|
+
SERVICE_UNAVAILABLE
|
|
111
|
+
},
|
|
112
|
+
validationFields: {
|
|
113
|
+
FIRST_NAME_MAX,
|
|
114
|
+
LAST_NAME_MAX,
|
|
115
|
+
MIDDLE_NAMES_MAX,
|
|
116
|
+
BUSINESS_NAME_MAX,
|
|
117
|
+
EMAIL_MAX,
|
|
118
|
+
PHONE_NUMBER_MIN,
|
|
119
|
+
PHONE_NUMBER_MAX,
|
|
120
|
+
MAX_AGE_YEARS,
|
|
121
|
+
ADDRESS_LINE_MAX,
|
|
122
|
+
TOWN_CITY_MAX,
|
|
123
|
+
COUNTY_MAX,
|
|
124
|
+
COUNTRY_MAX,
|
|
125
|
+
POSTCODE_MAX
|
|
126
|
+
},
|
|
127
|
+
patterns: {
|
|
128
|
+
PHONE_NUMBER_PATTERN,
|
|
129
|
+
NO_CONTROL_CHARS_PATTERN
|
|
130
|
+
},
|
|
131
|
+
monthMap: MONTH_MAP
|
|
132
|
+
};
|
|
133
|
+
|
|
40
134
|
// src/mappers/personal-business-details-mapper.js
|
|
41
135
|
var mapPersonalBusinessDetails = (value) => {
|
|
42
136
|
return {
|
|
@@ -130,14 +224,201 @@ var mappers = {
|
|
|
130
224
|
businessDetails: mapBusinessDetails
|
|
131
225
|
};
|
|
132
226
|
|
|
133
|
-
// src/
|
|
134
|
-
var
|
|
227
|
+
// src/mutations/personal/update-customer-name.js
|
|
228
|
+
var updateCustomerNameMutation = `
|
|
229
|
+
mutation UpdateCustomerName($input: UpdateCustomerNameInput!) {
|
|
230
|
+
updateCustomerName(input: $input) {
|
|
231
|
+
customer {
|
|
232
|
+
info {
|
|
233
|
+
name {
|
|
234
|
+
first
|
|
235
|
+
last
|
|
236
|
+
middle
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
`;
|
|
135
243
|
|
|
136
|
-
// src/
|
|
137
|
-
var
|
|
138
|
-
|
|
244
|
+
// src/mutations/mutations.js
|
|
245
|
+
var mutations = {
|
|
246
|
+
updateCustomerName: updateCustomerNameMutation
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// src/presenters/base-presenter.js
|
|
250
|
+
var BACK_LINK_DISPLAY_MAX = 50;
|
|
251
|
+
var formatBackLink = (businessName) => {
|
|
252
|
+
if (businessName.length > BACK_LINK_DISPLAY_MAX) {
|
|
253
|
+
return `Back to ${businessName.slice(0, BACK_LINK_DISPLAY_MAX)}\u2026`;
|
|
254
|
+
}
|
|
255
|
+
return `Back to ${businessName}`;
|
|
256
|
+
};
|
|
257
|
+
var formatNumber = (payloadNumber, changedNumber, originalNumber) => {
|
|
258
|
+
if (payloadNumber !== void 0) {
|
|
259
|
+
return payloadNumber;
|
|
260
|
+
}
|
|
261
|
+
if (changedNumber !== void 0) {
|
|
262
|
+
return changedNumber;
|
|
263
|
+
}
|
|
264
|
+
return originalNumber;
|
|
265
|
+
};
|
|
266
|
+
var formatDisplayAddress = (address) => {
|
|
267
|
+
const { lookup, manual, postcode, country, city } = address;
|
|
268
|
+
let addressLines = [];
|
|
269
|
+
if (lookup.uprn) {
|
|
270
|
+
const buildingAndStreet = [
|
|
271
|
+
lookup.buildingNumberRange,
|
|
272
|
+
lookup.street
|
|
273
|
+
].filter(Boolean).join(" ");
|
|
274
|
+
addressLines = [
|
|
275
|
+
lookup.pafOrganisationName,
|
|
276
|
+
lookup.flatName,
|
|
277
|
+
lookup.buildingName,
|
|
278
|
+
buildingAndStreet,
|
|
279
|
+
lookup.doubleDependentLocality,
|
|
280
|
+
lookup.dependentLocality,
|
|
281
|
+
city,
|
|
282
|
+
lookup.county
|
|
283
|
+
];
|
|
284
|
+
} else {
|
|
285
|
+
addressLines = [
|
|
286
|
+
manual.line1,
|
|
287
|
+
manual.line2,
|
|
288
|
+
manual.line3,
|
|
289
|
+
city,
|
|
290
|
+
manual.line4,
|
|
291
|
+
// County
|
|
292
|
+
manual.line5
|
|
293
|
+
];
|
|
294
|
+
}
|
|
295
|
+
return [
|
|
296
|
+
...addressLines.filter(Boolean),
|
|
297
|
+
postcode,
|
|
298
|
+
country
|
|
299
|
+
];
|
|
300
|
+
};
|
|
301
|
+
var buildAddressLine = (parts) => {
|
|
302
|
+
return parts.filter(Boolean).join(", ") || null;
|
|
303
|
+
};
|
|
304
|
+
var buildStreetLine = (buildingRange, street) => {
|
|
305
|
+
return [buildingRange, street].filter(Boolean).join(" ") || null;
|
|
306
|
+
};
|
|
307
|
+
var formatLookupAddress = (lookup, city, country, postcode) => ({
|
|
308
|
+
address1: buildAddressLine([lookup.pafOrganisationName, lookup.flatName, lookup.buildingName]),
|
|
309
|
+
address2: buildStreetLine(lookup.buildingNumberRange, lookup.street),
|
|
310
|
+
address3: buildAddressLine([lookup.doubleDependentLocality, lookup.dependentLocality]),
|
|
311
|
+
county: lookup.county ?? null,
|
|
312
|
+
city: city ?? null,
|
|
313
|
+
country: country ?? null,
|
|
314
|
+
postcode: postcode ?? null
|
|
315
|
+
});
|
|
316
|
+
var formatManualAddress = (manual, city, country, postcode) => ({
|
|
317
|
+
address1: manual.line1 ?? null,
|
|
318
|
+
address2: manual.line2 ?? null,
|
|
319
|
+
address3: manual.line3 ?? null,
|
|
320
|
+
city: city ?? null,
|
|
321
|
+
county: manual.line4 ?? null,
|
|
322
|
+
country: country ?? null,
|
|
323
|
+
postcode: postcode ?? null
|
|
324
|
+
});
|
|
325
|
+
var formatOriginalAddress = (originalAddress) => {
|
|
326
|
+
const { lookup, manual, city, country, postcode } = originalAddress;
|
|
327
|
+
return lookup.uprn ? formatLookupAddress(lookup, city, country, postcode) : formatManualAddress(manual, city, country, postcode);
|
|
328
|
+
};
|
|
329
|
+
var formatChangedAddress = (changeBusinessAddress) => {
|
|
330
|
+
if (!changeBusinessAddress.uprn) {
|
|
331
|
+
return changeBusinessAddress;
|
|
332
|
+
}
|
|
333
|
+
const {
|
|
334
|
+
pafOrganisationName,
|
|
335
|
+
flatName,
|
|
336
|
+
buildingName,
|
|
337
|
+
buildingNumberRange,
|
|
338
|
+
street,
|
|
339
|
+
doubleDependentLocality,
|
|
340
|
+
dependentLocality,
|
|
341
|
+
city,
|
|
342
|
+
county,
|
|
343
|
+
country,
|
|
344
|
+
postcode
|
|
345
|
+
} = changeBusinessAddress;
|
|
346
|
+
return {
|
|
347
|
+
address1: buildAddressLine([pafOrganisationName, flatName, buildingName]),
|
|
348
|
+
address2: buildStreetLine(buildingNumberRange, street),
|
|
349
|
+
address3: buildAddressLine([doubleDependentLocality, dependentLocality]),
|
|
350
|
+
city: city ?? null,
|
|
351
|
+
county: county ?? null,
|
|
352
|
+
country: country ?? null,
|
|
353
|
+
postcode: postcode ?? null
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
var formatDisplayAddresses = (addresses, previouslyPickedAddress) => {
|
|
357
|
+
const displayAddresses = addresses.map((address) => ({
|
|
358
|
+
value: `${address.uprn}${address.displayAddress}`,
|
|
359
|
+
text: address.displayAddress,
|
|
360
|
+
selected: (previouslyPickedAddress == null ? void 0 : previouslyPickedAddress.uprn) === address.uprn && (previouslyPickedAddress == null ? void 0 : previouslyPickedAddress.displayAddress) === address.displayAddress
|
|
361
|
+
}));
|
|
362
|
+
const hasSelectedAddress = displayAddresses.some((addr) => addr.selected);
|
|
363
|
+
const text = addresses.length === 1 ? "1 address found" : `${addresses.length} addresses found`;
|
|
364
|
+
displayAddresses.unshift({
|
|
365
|
+
value: "display",
|
|
366
|
+
text,
|
|
367
|
+
selected: !hasSelectedAddress
|
|
368
|
+
});
|
|
369
|
+
return displayAddresses;
|
|
370
|
+
};
|
|
371
|
+
var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDER) => {
|
|
372
|
+
const sortedErrors = [];
|
|
373
|
+
for (const section of orderedSectionsToFix) {
|
|
374
|
+
const fieldsInSection = SECTION_FIELD_ORDER[section] || [];
|
|
375
|
+
for (const field of fieldsInSection) {
|
|
376
|
+
if (errors[field]) {
|
|
377
|
+
sortedErrors.push({
|
|
378
|
+
field,
|
|
379
|
+
...errors[field]
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return sortedErrors;
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
// src/presenters/business-details-presenter.js
|
|
388
|
+
var getActionText = (value) => {
|
|
389
|
+
return value ? "Change" : "Add";
|
|
390
|
+
};
|
|
391
|
+
var formatCph = (countyParishHoldings) => {
|
|
392
|
+
return (countyParishHoldings || []).filter((cph) => cph == null ? void 0 : cph.cphNumber).map((cph) => cph.cphNumber);
|
|
393
|
+
};
|
|
394
|
+
var formatCphText = (count) => {
|
|
395
|
+
return `County Parish Holding (CPH) number${count !== 1 ? "s" : ""}`;
|
|
396
|
+
};
|
|
397
|
+
var formatBusinessAddress = (businessAddress) => {
|
|
398
|
+
var _a, _b;
|
|
399
|
+
if (((_a = businessAddress == null ? void 0 : businessAddress.lookup) == null ? void 0 : _a.uprn) || ((_b = businessAddress == null ? void 0 : businessAddress.manual) == null ? void 0 : _b.line1)) {
|
|
400
|
+
return formatDisplayAddress(businessAddress);
|
|
401
|
+
}
|
|
402
|
+
return [];
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
// src/presenters/presenters.js
|
|
406
|
+
var presenters = {
|
|
407
|
+
formatBackLink,
|
|
408
|
+
formatNumber,
|
|
409
|
+
formatDisplayAddress,
|
|
410
|
+
formatOriginalAddress,
|
|
411
|
+
formatChangedAddress,
|
|
412
|
+
formatDisplayAddresses,
|
|
413
|
+
sortErrorsBySectionOrder,
|
|
414
|
+
getActionText,
|
|
415
|
+
formatCph,
|
|
416
|
+
formatCphText,
|
|
417
|
+
formatBusinessAddress
|
|
418
|
+
};
|
|
139
419
|
|
|
140
420
|
// src/utils/joi.js
|
|
421
|
+
var import_joi = __toESM(require("joi"), 1);
|
|
141
422
|
var Joi = import_joi.default.extend((joi) => ({
|
|
142
423
|
type: "string",
|
|
143
424
|
base: joi.string(),
|
|
@@ -152,29 +433,14 @@ var Joi = import_joi.default.extend((joi) => ({
|
|
|
152
433
|
}
|
|
153
434
|
}));
|
|
154
435
|
|
|
155
|
-
// src/schemas/business/business-sbi-schema.js
|
|
156
|
-
var businessSbiSchema = Joi.object({
|
|
157
|
-
sbi: Joi.string().pattern(/^\d{9}$/).allow("").optional().messages({
|
|
158
|
-
"string.pattern.base": "Enter the full SBI",
|
|
159
|
-
"string.noControlChars": "SBI must not contain invalid characters"
|
|
160
|
-
})
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// src/constants/validation-fields.js
|
|
164
|
-
var FIRST_NAME_MAX = 100;
|
|
165
|
-
var LAST_NAME_MAX = 100;
|
|
166
|
-
var MIDDLE_NAMES_MAX = 100;
|
|
167
|
-
var BUSINESS_NAME_MAX = 160;
|
|
168
|
-
var EMAIL_MAX = 254;
|
|
169
|
-
var PHONE_NUMBER_MIN = 10;
|
|
170
|
-
var PHONE_NUMBER_MAX = 50;
|
|
171
|
-
var MAX_AGE_YEARS = 120;
|
|
172
|
-
var ADDRESS_LINE_MAX = 100;
|
|
173
|
-
var TOWN_CITY_MAX = 60;
|
|
174
|
-
var COUNTY_MAX = 60;
|
|
175
|
-
var COUNTRY_MAX = 60;
|
|
176
|
-
var POSTCODE_MAX = 8;
|
|
177
|
-
|
|
436
|
+
// src/schemas/business/business-sbi-schema.js
|
|
437
|
+
var businessSbiSchema = Joi.object({
|
|
438
|
+
sbi: Joi.string().pattern(/^\d{9}$/).allow("").optional().messages({
|
|
439
|
+
"string.pattern.base": "Enter the full SBI",
|
|
440
|
+
"string.noControlChars": "SBI must not contain invalid characters"
|
|
441
|
+
})
|
|
442
|
+
});
|
|
443
|
+
|
|
178
444
|
// src/schemas/shared/address-schema.js
|
|
179
445
|
var addressSchema = Joi.object({
|
|
180
446
|
address1: Joi.string().trim().required().max(ADDRESS_LINE_MAX).messages({
|
|
@@ -333,34 +599,6 @@ var personalNameSchema = Joi.object({
|
|
|
333
599
|
})
|
|
334
600
|
});
|
|
335
601
|
|
|
336
|
-
// src/constants/month-map.js
|
|
337
|
-
var MONTH_MAP = {
|
|
338
|
-
january: 1,
|
|
339
|
-
jan: 1,
|
|
340
|
-
february: 2,
|
|
341
|
-
feb: 2,
|
|
342
|
-
march: 3,
|
|
343
|
-
mar: 3,
|
|
344
|
-
april: 4,
|
|
345
|
-
apr: 4,
|
|
346
|
-
may: 5,
|
|
347
|
-
june: 6,
|
|
348
|
-
jun: 6,
|
|
349
|
-
july: 7,
|
|
350
|
-
jul: 7,
|
|
351
|
-
august: 8,
|
|
352
|
-
aug: 8,
|
|
353
|
-
september: 9,
|
|
354
|
-
sep: 9,
|
|
355
|
-
sept: 9,
|
|
356
|
-
october: 10,
|
|
357
|
-
oct: 10,
|
|
358
|
-
november: 11,
|
|
359
|
-
nov: 11,
|
|
360
|
-
december: 12,
|
|
361
|
-
dec: 12
|
|
362
|
-
};
|
|
363
|
-
|
|
364
602
|
// src/schemas/personal/personal-dob-schema.js
|
|
365
603
|
var personalDobSchema = Joi.object({
|
|
366
604
|
day: Joi.string().allow(""),
|
|
@@ -581,6 +819,15 @@ var schemas = {
|
|
|
581
819
|
osPlaces: osPlacesSchemas
|
|
582
820
|
};
|
|
583
821
|
|
|
822
|
+
// src/utils/format-full-name.js
|
|
823
|
+
var formatFullName = (nameData) => {
|
|
824
|
+
return [
|
|
825
|
+
nameData.first,
|
|
826
|
+
nameData.middle,
|
|
827
|
+
nameData.last
|
|
828
|
+
].filter(Boolean).join(" ");
|
|
829
|
+
};
|
|
830
|
+
|
|
584
831
|
// src/utils/format-validation-errors.js
|
|
585
832
|
var formatValidationErrors = (errors) => {
|
|
586
833
|
const formattedErrors = {};
|
|
@@ -609,229 +856,14 @@ var formatValidationErrors = (errors) => {
|
|
|
609
856
|
|
|
610
857
|
// src/utils/utils.js
|
|
611
858
|
var utils = {
|
|
859
|
+
formatFullName,
|
|
612
860
|
formatValidationErrors
|
|
613
861
|
};
|
|
614
|
-
|
|
615
|
-
// src/presenters/base-presenter.js
|
|
616
|
-
var BACK_LINK_DISPLAY_MAX = 50;
|
|
617
|
-
var formatBackLink = (businessName) => {
|
|
618
|
-
if (businessName.length > BACK_LINK_DISPLAY_MAX) {
|
|
619
|
-
return `Back to ${businessName.slice(0, BACK_LINK_DISPLAY_MAX)}\u2026`;
|
|
620
|
-
}
|
|
621
|
-
return `Back to ${businessName}`;
|
|
622
|
-
};
|
|
623
|
-
var formatNumber = (payloadNumber, changedNumber, originalNumber) => {
|
|
624
|
-
if (payloadNumber !== void 0) {
|
|
625
|
-
return payloadNumber;
|
|
626
|
-
}
|
|
627
|
-
if (changedNumber !== void 0) {
|
|
628
|
-
return changedNumber;
|
|
629
|
-
}
|
|
630
|
-
return originalNumber;
|
|
631
|
-
};
|
|
632
|
-
var formatDisplayAddress = (address) => {
|
|
633
|
-
const { lookup, manual, postcode, country, city } = address;
|
|
634
|
-
let addressLines = [];
|
|
635
|
-
if (lookup.uprn) {
|
|
636
|
-
const buildingAndStreet = [
|
|
637
|
-
lookup.buildingNumberRange,
|
|
638
|
-
lookup.street
|
|
639
|
-
].filter(Boolean).join(" ");
|
|
640
|
-
addressLines = [
|
|
641
|
-
lookup.pafOrganisationName,
|
|
642
|
-
lookup.flatName,
|
|
643
|
-
lookup.buildingName,
|
|
644
|
-
buildingAndStreet,
|
|
645
|
-
lookup.doubleDependentLocality,
|
|
646
|
-
lookup.dependentLocality,
|
|
647
|
-
city,
|
|
648
|
-
lookup.county
|
|
649
|
-
];
|
|
650
|
-
} else {
|
|
651
|
-
addressLines = [
|
|
652
|
-
manual.line1,
|
|
653
|
-
manual.line2,
|
|
654
|
-
manual.line3,
|
|
655
|
-
city,
|
|
656
|
-
manual.line4,
|
|
657
|
-
// County
|
|
658
|
-
manual.line5
|
|
659
|
-
];
|
|
660
|
-
}
|
|
661
|
-
return [
|
|
662
|
-
...addressLines.filter(Boolean),
|
|
663
|
-
postcode,
|
|
664
|
-
country
|
|
665
|
-
];
|
|
666
|
-
};
|
|
667
|
-
var buildAddressLine = (parts) => {
|
|
668
|
-
return parts.filter(Boolean).join(", ") || null;
|
|
669
|
-
};
|
|
670
|
-
var buildStreetLine = (buildingRange, street) => {
|
|
671
|
-
return [buildingRange, street].filter(Boolean).join(" ") || null;
|
|
672
|
-
};
|
|
673
|
-
var formatLookupAddress = (lookup, city, country, postcode) => ({
|
|
674
|
-
address1: buildAddressLine([lookup.pafOrganisationName, lookup.flatName, lookup.buildingName]),
|
|
675
|
-
address2: buildStreetLine(lookup.buildingNumberRange, lookup.street),
|
|
676
|
-
address3: buildAddressLine([lookup.doubleDependentLocality, lookup.dependentLocality]),
|
|
677
|
-
county: lookup.county ?? null,
|
|
678
|
-
city: city ?? null,
|
|
679
|
-
country: country ?? null,
|
|
680
|
-
postcode: postcode ?? null
|
|
681
|
-
});
|
|
682
|
-
var formatManualAddress = (manual, city, country, postcode) => ({
|
|
683
|
-
address1: manual.line1 ?? null,
|
|
684
|
-
address2: manual.line2 ?? null,
|
|
685
|
-
address3: manual.line3 ?? null,
|
|
686
|
-
city: city ?? null,
|
|
687
|
-
county: manual.line4 ?? null,
|
|
688
|
-
country: country ?? null,
|
|
689
|
-
postcode: postcode ?? null
|
|
690
|
-
});
|
|
691
|
-
var formatOriginalAddress = (originalAddress) => {
|
|
692
|
-
const { lookup, manual, city, country, postcode } = originalAddress;
|
|
693
|
-
return lookup.uprn ? formatLookupAddress(lookup, city, country, postcode) : formatManualAddress(manual, city, country, postcode);
|
|
694
|
-
};
|
|
695
|
-
var formatChangedAddress = (changeBusinessAddress) => {
|
|
696
|
-
if (!changeBusinessAddress.uprn) {
|
|
697
|
-
return changeBusinessAddress;
|
|
698
|
-
}
|
|
699
|
-
const {
|
|
700
|
-
pafOrganisationName,
|
|
701
|
-
flatName,
|
|
702
|
-
buildingName,
|
|
703
|
-
buildingNumberRange,
|
|
704
|
-
street,
|
|
705
|
-
doubleDependentLocality,
|
|
706
|
-
dependentLocality,
|
|
707
|
-
city,
|
|
708
|
-
county,
|
|
709
|
-
country,
|
|
710
|
-
postcode
|
|
711
|
-
} = changeBusinessAddress;
|
|
712
|
-
return {
|
|
713
|
-
address1: buildAddressLine([pafOrganisationName, flatName, buildingName]),
|
|
714
|
-
address2: buildStreetLine(buildingNumberRange, street),
|
|
715
|
-
address3: buildAddressLine([doubleDependentLocality, dependentLocality]),
|
|
716
|
-
city: city ?? null,
|
|
717
|
-
county: county ?? null,
|
|
718
|
-
country: country ?? null,
|
|
719
|
-
postcode: postcode ?? null
|
|
720
|
-
};
|
|
721
|
-
};
|
|
722
|
-
var formatDisplayAddresses = (addresses, previouslyPickedAddress) => {
|
|
723
|
-
const displayAddresses = addresses.map((address) => ({
|
|
724
|
-
value: `${address.uprn}${address.displayAddress}`,
|
|
725
|
-
text: address.displayAddress,
|
|
726
|
-
selected: (previouslyPickedAddress == null ? void 0 : previouslyPickedAddress.uprn) === address.uprn && (previouslyPickedAddress == null ? void 0 : previouslyPickedAddress.displayAddress) === address.displayAddress
|
|
727
|
-
}));
|
|
728
|
-
const hasSelectedAddress = displayAddresses.some((addr) => addr.selected);
|
|
729
|
-
const text = addresses.length === 1 ? "1 address found" : `${addresses.length} addresses found`;
|
|
730
|
-
displayAddresses.unshift({
|
|
731
|
-
value: "display",
|
|
732
|
-
text,
|
|
733
|
-
selected: !hasSelectedAddress
|
|
734
|
-
});
|
|
735
|
-
return displayAddresses;
|
|
736
|
-
};
|
|
737
|
-
var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDER) => {
|
|
738
|
-
const sortedErrors = [];
|
|
739
|
-
for (const section of orderedSectionsToFix) {
|
|
740
|
-
const fieldsInSection = SECTION_FIELD_ORDER[section] || [];
|
|
741
|
-
for (const field of fieldsInSection) {
|
|
742
|
-
if (errors[field]) {
|
|
743
|
-
sortedErrors.push({
|
|
744
|
-
field,
|
|
745
|
-
...errors[field]
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
return sortedErrors;
|
|
751
|
-
};
|
|
752
|
-
|
|
753
|
-
// src/presenters/business-details-presenter.js
|
|
754
|
-
var getActionText = (value) => {
|
|
755
|
-
return value ? "Change" : "Add";
|
|
756
|
-
};
|
|
757
|
-
var formatCph = (countyParishHoldings) => {
|
|
758
|
-
return (countyParishHoldings || []).filter((cph) => cph == null ? void 0 : cph.cphNumber).map((cph) => cph.cphNumber);
|
|
759
|
-
};
|
|
760
|
-
var formatCphText = (count) => {
|
|
761
|
-
return `County Parish Holding (CPH) number${count !== 1 ? "s" : ""}`;
|
|
762
|
-
};
|
|
763
|
-
var formatBusinessAddress = (businessAddress) => {
|
|
764
|
-
var _a, _b;
|
|
765
|
-
if (((_a = businessAddress == null ? void 0 : businessAddress.lookup) == null ? void 0 : _a.uprn) || ((_b = businessAddress == null ? void 0 : businessAddress.manual) == null ? void 0 : _b.line1)) {
|
|
766
|
-
return formatDisplayAddress(businessAddress);
|
|
767
|
-
}
|
|
768
|
-
return [];
|
|
769
|
-
};
|
|
770
|
-
|
|
771
|
-
// src/presenters/presenters.js
|
|
772
|
-
var presenters = {
|
|
773
|
-
formatBackLink,
|
|
774
|
-
formatNumber,
|
|
775
|
-
formatDisplayAddress,
|
|
776
|
-
formatOriginalAddress,
|
|
777
|
-
formatChangedAddress,
|
|
778
|
-
formatDisplayAddresses,
|
|
779
|
-
sortErrorsBySectionOrder,
|
|
780
|
-
getActionText,
|
|
781
|
-
formatCph,
|
|
782
|
-
formatCphText,
|
|
783
|
-
formatBusinessAddress
|
|
784
|
-
};
|
|
785
|
-
|
|
786
|
-
// src/constants/status-codes.js
|
|
787
|
-
var OK = 200;
|
|
788
|
-
var BAD_REQUEST = 400;
|
|
789
|
-
var UNAUTHORIZED = 401;
|
|
790
|
-
var FORBIDDEN = 403;
|
|
791
|
-
var NOT_FOUND = 404;
|
|
792
|
-
var NO_CONTENT = 204;
|
|
793
|
-
var FOUND = 302;
|
|
794
|
-
var INTERNAL_SERVER_ERROR = 500;
|
|
795
|
-
var SERVICE_UNAVAILABLE = 503;
|
|
796
|
-
|
|
797
|
-
// src/constants/index.js
|
|
798
|
-
var constants = {
|
|
799
|
-
statusCodes: {
|
|
800
|
-
BAD_REQUEST,
|
|
801
|
-
UNAUTHORIZED,
|
|
802
|
-
FORBIDDEN,
|
|
803
|
-
NOT_FOUND,
|
|
804
|
-
OK,
|
|
805
|
-
NO_CONTENT,
|
|
806
|
-
FOUND,
|
|
807
|
-
INTERNAL_SERVER_ERROR,
|
|
808
|
-
SERVICE_UNAVAILABLE
|
|
809
|
-
},
|
|
810
|
-
validationFields: {
|
|
811
|
-
FIRST_NAME_MAX,
|
|
812
|
-
LAST_NAME_MAX,
|
|
813
|
-
MIDDLE_NAMES_MAX,
|
|
814
|
-
BUSINESS_NAME_MAX,
|
|
815
|
-
EMAIL_MAX,
|
|
816
|
-
PHONE_NUMBER_MIN,
|
|
817
|
-
PHONE_NUMBER_MAX,
|
|
818
|
-
MAX_AGE_YEARS,
|
|
819
|
-
ADDRESS_LINE_MAX,
|
|
820
|
-
TOWN_CITY_MAX,
|
|
821
|
-
COUNTY_MAX,
|
|
822
|
-
COUNTRY_MAX,
|
|
823
|
-
POSTCODE_MAX
|
|
824
|
-
},
|
|
825
|
-
patterns: {
|
|
826
|
-
PHONE_NUMBER_PATTERN,
|
|
827
|
-
NO_CONTROL_CHARS_PATTERN
|
|
828
|
-
},
|
|
829
|
-
monthMap: MONTH_MAP
|
|
830
|
-
};
|
|
831
862
|
// Annotate the CommonJS export names for ESM import in node:
|
|
832
863
|
0 && (module.exports = {
|
|
833
864
|
constants,
|
|
834
865
|
mappers,
|
|
866
|
+
mutations,
|
|
835
867
|
presenters,
|
|
836
868
|
schemas,
|
|
837
869
|
utils
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
+
// src/constants/validation-fields.js
|
|
2
|
+
var FIRST_NAME_MAX = 100;
|
|
3
|
+
var LAST_NAME_MAX = 100;
|
|
4
|
+
var MIDDLE_NAMES_MAX = 100;
|
|
5
|
+
var BUSINESS_NAME_MAX = 160;
|
|
6
|
+
var EMAIL_MAX = 254;
|
|
7
|
+
var PHONE_NUMBER_MIN = 10;
|
|
8
|
+
var PHONE_NUMBER_MAX = 50;
|
|
9
|
+
var MAX_AGE_YEARS = 120;
|
|
10
|
+
var ADDRESS_LINE_MAX = 100;
|
|
11
|
+
var TOWN_CITY_MAX = 60;
|
|
12
|
+
var COUNTY_MAX = 60;
|
|
13
|
+
var COUNTRY_MAX = 60;
|
|
14
|
+
var POSTCODE_MAX = 8;
|
|
15
|
+
|
|
16
|
+
// src/constants/status-codes.js
|
|
17
|
+
var OK = 200;
|
|
18
|
+
var BAD_REQUEST = 400;
|
|
19
|
+
var UNAUTHORIZED = 401;
|
|
20
|
+
var FORBIDDEN = 403;
|
|
21
|
+
var NOT_FOUND = 404;
|
|
22
|
+
var NO_CONTENT = 204;
|
|
23
|
+
var FOUND = 302;
|
|
24
|
+
var INTERNAL_SERVER_ERROR = 500;
|
|
25
|
+
var SERVICE_UNAVAILABLE = 503;
|
|
26
|
+
|
|
27
|
+
// src/constants/patterns.js
|
|
28
|
+
var PHONE_NUMBER_PATTERN = /^\+?(?=[\d ()]*\d)[\d ()]*$/;
|
|
29
|
+
var NO_CONTROL_CHARS_PATTERN = /^[^\x00-\x1f\x7f-\x9f]*$/;
|
|
30
|
+
|
|
31
|
+
// src/constants/month-map.js
|
|
32
|
+
var MONTH_MAP = {
|
|
33
|
+
january: 1,
|
|
34
|
+
jan: 1,
|
|
35
|
+
february: 2,
|
|
36
|
+
feb: 2,
|
|
37
|
+
march: 3,
|
|
38
|
+
mar: 3,
|
|
39
|
+
april: 4,
|
|
40
|
+
apr: 4,
|
|
41
|
+
may: 5,
|
|
42
|
+
june: 6,
|
|
43
|
+
jun: 6,
|
|
44
|
+
july: 7,
|
|
45
|
+
jul: 7,
|
|
46
|
+
august: 8,
|
|
47
|
+
aug: 8,
|
|
48
|
+
september: 9,
|
|
49
|
+
sep: 9,
|
|
50
|
+
sept: 9,
|
|
51
|
+
october: 10,
|
|
52
|
+
oct: 10,
|
|
53
|
+
november: 11,
|
|
54
|
+
nov: 11,
|
|
55
|
+
december: 12,
|
|
56
|
+
dec: 12
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/constants/index.js
|
|
60
|
+
var constants = {
|
|
61
|
+
statusCodes: {
|
|
62
|
+
BAD_REQUEST,
|
|
63
|
+
UNAUTHORIZED,
|
|
64
|
+
FORBIDDEN,
|
|
65
|
+
NOT_FOUND,
|
|
66
|
+
OK,
|
|
67
|
+
NO_CONTENT,
|
|
68
|
+
FOUND,
|
|
69
|
+
INTERNAL_SERVER_ERROR,
|
|
70
|
+
SERVICE_UNAVAILABLE
|
|
71
|
+
},
|
|
72
|
+
validationFields: {
|
|
73
|
+
FIRST_NAME_MAX,
|
|
74
|
+
LAST_NAME_MAX,
|
|
75
|
+
MIDDLE_NAMES_MAX,
|
|
76
|
+
BUSINESS_NAME_MAX,
|
|
77
|
+
EMAIL_MAX,
|
|
78
|
+
PHONE_NUMBER_MIN,
|
|
79
|
+
PHONE_NUMBER_MAX,
|
|
80
|
+
MAX_AGE_YEARS,
|
|
81
|
+
ADDRESS_LINE_MAX,
|
|
82
|
+
TOWN_CITY_MAX,
|
|
83
|
+
COUNTY_MAX,
|
|
84
|
+
COUNTRY_MAX,
|
|
85
|
+
POSTCODE_MAX
|
|
86
|
+
},
|
|
87
|
+
patterns: {
|
|
88
|
+
PHONE_NUMBER_PATTERN,
|
|
89
|
+
NO_CONTROL_CHARS_PATTERN
|
|
90
|
+
},
|
|
91
|
+
monthMap: MONTH_MAP
|
|
92
|
+
};
|
|
93
|
+
|
|
1
94
|
// src/mappers/personal-business-details-mapper.js
|
|
2
95
|
var mapPersonalBusinessDetails = (value) => {
|
|
3
96
|
return {
|
|
@@ -91,14 +184,201 @@ var mappers = {
|
|
|
91
184
|
businessDetails: mapBusinessDetails
|
|
92
185
|
};
|
|
93
186
|
|
|
94
|
-
// src/
|
|
95
|
-
|
|
187
|
+
// src/mutations/personal/update-customer-name.js
|
|
188
|
+
var updateCustomerNameMutation = `
|
|
189
|
+
mutation UpdateCustomerName($input: UpdateCustomerNameInput!) {
|
|
190
|
+
updateCustomerName(input: $input) {
|
|
191
|
+
customer {
|
|
192
|
+
info {
|
|
193
|
+
name {
|
|
194
|
+
first
|
|
195
|
+
last
|
|
196
|
+
middle
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
`;
|
|
96
203
|
|
|
97
|
-
// src/
|
|
98
|
-
var
|
|
99
|
-
|
|
204
|
+
// src/mutations/mutations.js
|
|
205
|
+
var mutations = {
|
|
206
|
+
updateCustomerName: updateCustomerNameMutation
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/presenters/base-presenter.js
|
|
210
|
+
var BACK_LINK_DISPLAY_MAX = 50;
|
|
211
|
+
var formatBackLink = (businessName) => {
|
|
212
|
+
if (businessName.length > BACK_LINK_DISPLAY_MAX) {
|
|
213
|
+
return `Back to ${businessName.slice(0, BACK_LINK_DISPLAY_MAX)}\u2026`;
|
|
214
|
+
}
|
|
215
|
+
return `Back to ${businessName}`;
|
|
216
|
+
};
|
|
217
|
+
var formatNumber = (payloadNumber, changedNumber, originalNumber) => {
|
|
218
|
+
if (payloadNumber !== void 0) {
|
|
219
|
+
return payloadNumber;
|
|
220
|
+
}
|
|
221
|
+
if (changedNumber !== void 0) {
|
|
222
|
+
return changedNumber;
|
|
223
|
+
}
|
|
224
|
+
return originalNumber;
|
|
225
|
+
};
|
|
226
|
+
var formatDisplayAddress = (address) => {
|
|
227
|
+
const { lookup, manual, postcode, country, city } = address;
|
|
228
|
+
let addressLines = [];
|
|
229
|
+
if (lookup.uprn) {
|
|
230
|
+
const buildingAndStreet = [
|
|
231
|
+
lookup.buildingNumberRange,
|
|
232
|
+
lookup.street
|
|
233
|
+
].filter(Boolean).join(" ");
|
|
234
|
+
addressLines = [
|
|
235
|
+
lookup.pafOrganisationName,
|
|
236
|
+
lookup.flatName,
|
|
237
|
+
lookup.buildingName,
|
|
238
|
+
buildingAndStreet,
|
|
239
|
+
lookup.doubleDependentLocality,
|
|
240
|
+
lookup.dependentLocality,
|
|
241
|
+
city,
|
|
242
|
+
lookup.county
|
|
243
|
+
];
|
|
244
|
+
} else {
|
|
245
|
+
addressLines = [
|
|
246
|
+
manual.line1,
|
|
247
|
+
manual.line2,
|
|
248
|
+
manual.line3,
|
|
249
|
+
city,
|
|
250
|
+
manual.line4,
|
|
251
|
+
// County
|
|
252
|
+
manual.line5
|
|
253
|
+
];
|
|
254
|
+
}
|
|
255
|
+
return [
|
|
256
|
+
...addressLines.filter(Boolean),
|
|
257
|
+
postcode,
|
|
258
|
+
country
|
|
259
|
+
];
|
|
260
|
+
};
|
|
261
|
+
var buildAddressLine = (parts) => {
|
|
262
|
+
return parts.filter(Boolean).join(", ") || null;
|
|
263
|
+
};
|
|
264
|
+
var buildStreetLine = (buildingRange, street) => {
|
|
265
|
+
return [buildingRange, street].filter(Boolean).join(" ") || null;
|
|
266
|
+
};
|
|
267
|
+
var formatLookupAddress = (lookup, city, country, postcode) => ({
|
|
268
|
+
address1: buildAddressLine([lookup.pafOrganisationName, lookup.flatName, lookup.buildingName]),
|
|
269
|
+
address2: buildStreetLine(lookup.buildingNumberRange, lookup.street),
|
|
270
|
+
address3: buildAddressLine([lookup.doubleDependentLocality, lookup.dependentLocality]),
|
|
271
|
+
county: lookup.county ?? null,
|
|
272
|
+
city: city ?? null,
|
|
273
|
+
country: country ?? null,
|
|
274
|
+
postcode: postcode ?? null
|
|
275
|
+
});
|
|
276
|
+
var formatManualAddress = (manual, city, country, postcode) => ({
|
|
277
|
+
address1: manual.line1 ?? null,
|
|
278
|
+
address2: manual.line2 ?? null,
|
|
279
|
+
address3: manual.line3 ?? null,
|
|
280
|
+
city: city ?? null,
|
|
281
|
+
county: manual.line4 ?? null,
|
|
282
|
+
country: country ?? null,
|
|
283
|
+
postcode: postcode ?? null
|
|
284
|
+
});
|
|
285
|
+
var formatOriginalAddress = (originalAddress) => {
|
|
286
|
+
const { lookup, manual, city, country, postcode } = originalAddress;
|
|
287
|
+
return lookup.uprn ? formatLookupAddress(lookup, city, country, postcode) : formatManualAddress(manual, city, country, postcode);
|
|
288
|
+
};
|
|
289
|
+
var formatChangedAddress = (changeBusinessAddress) => {
|
|
290
|
+
if (!changeBusinessAddress.uprn) {
|
|
291
|
+
return changeBusinessAddress;
|
|
292
|
+
}
|
|
293
|
+
const {
|
|
294
|
+
pafOrganisationName,
|
|
295
|
+
flatName,
|
|
296
|
+
buildingName,
|
|
297
|
+
buildingNumberRange,
|
|
298
|
+
street,
|
|
299
|
+
doubleDependentLocality,
|
|
300
|
+
dependentLocality,
|
|
301
|
+
city,
|
|
302
|
+
county,
|
|
303
|
+
country,
|
|
304
|
+
postcode
|
|
305
|
+
} = changeBusinessAddress;
|
|
306
|
+
return {
|
|
307
|
+
address1: buildAddressLine([pafOrganisationName, flatName, buildingName]),
|
|
308
|
+
address2: buildStreetLine(buildingNumberRange, street),
|
|
309
|
+
address3: buildAddressLine([doubleDependentLocality, dependentLocality]),
|
|
310
|
+
city: city ?? null,
|
|
311
|
+
county: county ?? null,
|
|
312
|
+
country: country ?? null,
|
|
313
|
+
postcode: postcode ?? null
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
var formatDisplayAddresses = (addresses, previouslyPickedAddress) => {
|
|
317
|
+
const displayAddresses = addresses.map((address) => ({
|
|
318
|
+
value: `${address.uprn}${address.displayAddress}`,
|
|
319
|
+
text: address.displayAddress,
|
|
320
|
+
selected: (previouslyPickedAddress == null ? void 0 : previouslyPickedAddress.uprn) === address.uprn && (previouslyPickedAddress == null ? void 0 : previouslyPickedAddress.displayAddress) === address.displayAddress
|
|
321
|
+
}));
|
|
322
|
+
const hasSelectedAddress = displayAddresses.some((addr) => addr.selected);
|
|
323
|
+
const text = addresses.length === 1 ? "1 address found" : `${addresses.length} addresses found`;
|
|
324
|
+
displayAddresses.unshift({
|
|
325
|
+
value: "display",
|
|
326
|
+
text,
|
|
327
|
+
selected: !hasSelectedAddress
|
|
328
|
+
});
|
|
329
|
+
return displayAddresses;
|
|
330
|
+
};
|
|
331
|
+
var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDER) => {
|
|
332
|
+
const sortedErrors = [];
|
|
333
|
+
for (const section of orderedSectionsToFix) {
|
|
334
|
+
const fieldsInSection = SECTION_FIELD_ORDER[section] || [];
|
|
335
|
+
for (const field of fieldsInSection) {
|
|
336
|
+
if (errors[field]) {
|
|
337
|
+
sortedErrors.push({
|
|
338
|
+
field,
|
|
339
|
+
...errors[field]
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return sortedErrors;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// src/presenters/business-details-presenter.js
|
|
348
|
+
var getActionText = (value) => {
|
|
349
|
+
return value ? "Change" : "Add";
|
|
350
|
+
};
|
|
351
|
+
var formatCph = (countyParishHoldings) => {
|
|
352
|
+
return (countyParishHoldings || []).filter((cph) => cph == null ? void 0 : cph.cphNumber).map((cph) => cph.cphNumber);
|
|
353
|
+
};
|
|
354
|
+
var formatCphText = (count) => {
|
|
355
|
+
return `County Parish Holding (CPH) number${count !== 1 ? "s" : ""}`;
|
|
356
|
+
};
|
|
357
|
+
var formatBusinessAddress = (businessAddress) => {
|
|
358
|
+
var _a, _b;
|
|
359
|
+
if (((_a = businessAddress == null ? void 0 : businessAddress.lookup) == null ? void 0 : _a.uprn) || ((_b = businessAddress == null ? void 0 : businessAddress.manual) == null ? void 0 : _b.line1)) {
|
|
360
|
+
return formatDisplayAddress(businessAddress);
|
|
361
|
+
}
|
|
362
|
+
return [];
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
// src/presenters/presenters.js
|
|
366
|
+
var presenters = {
|
|
367
|
+
formatBackLink,
|
|
368
|
+
formatNumber,
|
|
369
|
+
formatDisplayAddress,
|
|
370
|
+
formatOriginalAddress,
|
|
371
|
+
formatChangedAddress,
|
|
372
|
+
formatDisplayAddresses,
|
|
373
|
+
sortErrorsBySectionOrder,
|
|
374
|
+
getActionText,
|
|
375
|
+
formatCph,
|
|
376
|
+
formatCphText,
|
|
377
|
+
formatBusinessAddress
|
|
378
|
+
};
|
|
100
379
|
|
|
101
380
|
// src/utils/joi.js
|
|
381
|
+
import BaseJoi from "joi";
|
|
102
382
|
var Joi = BaseJoi.extend((joi) => ({
|
|
103
383
|
type: "string",
|
|
104
384
|
base: joi.string(),
|
|
@@ -113,29 +393,14 @@ var Joi = BaseJoi.extend((joi) => ({
|
|
|
113
393
|
}
|
|
114
394
|
}));
|
|
115
395
|
|
|
116
|
-
// src/schemas/business/business-sbi-schema.js
|
|
117
|
-
var businessSbiSchema = Joi.object({
|
|
118
|
-
sbi: Joi.string().pattern(/^\d{9}$/).allow("").optional().messages({
|
|
119
|
-
"string.pattern.base": "Enter the full SBI",
|
|
120
|
-
"string.noControlChars": "SBI must not contain invalid characters"
|
|
121
|
-
})
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// src/constants/validation-fields.js
|
|
125
|
-
var FIRST_NAME_MAX = 100;
|
|
126
|
-
var LAST_NAME_MAX = 100;
|
|
127
|
-
var MIDDLE_NAMES_MAX = 100;
|
|
128
|
-
var BUSINESS_NAME_MAX = 160;
|
|
129
|
-
var EMAIL_MAX = 254;
|
|
130
|
-
var PHONE_NUMBER_MIN = 10;
|
|
131
|
-
var PHONE_NUMBER_MAX = 50;
|
|
132
|
-
var MAX_AGE_YEARS = 120;
|
|
133
|
-
var ADDRESS_LINE_MAX = 100;
|
|
134
|
-
var TOWN_CITY_MAX = 60;
|
|
135
|
-
var COUNTY_MAX = 60;
|
|
136
|
-
var COUNTRY_MAX = 60;
|
|
137
|
-
var POSTCODE_MAX = 8;
|
|
138
|
-
|
|
396
|
+
// src/schemas/business/business-sbi-schema.js
|
|
397
|
+
var businessSbiSchema = Joi.object({
|
|
398
|
+
sbi: Joi.string().pattern(/^\d{9}$/).allow("").optional().messages({
|
|
399
|
+
"string.pattern.base": "Enter the full SBI",
|
|
400
|
+
"string.noControlChars": "SBI must not contain invalid characters"
|
|
401
|
+
})
|
|
402
|
+
});
|
|
403
|
+
|
|
139
404
|
// src/schemas/shared/address-schema.js
|
|
140
405
|
var addressSchema = Joi.object({
|
|
141
406
|
address1: Joi.string().trim().required().max(ADDRESS_LINE_MAX).messages({
|
|
@@ -294,34 +559,6 @@ var personalNameSchema = Joi.object({
|
|
|
294
559
|
})
|
|
295
560
|
});
|
|
296
561
|
|
|
297
|
-
// src/constants/month-map.js
|
|
298
|
-
var MONTH_MAP = {
|
|
299
|
-
january: 1,
|
|
300
|
-
jan: 1,
|
|
301
|
-
february: 2,
|
|
302
|
-
feb: 2,
|
|
303
|
-
march: 3,
|
|
304
|
-
mar: 3,
|
|
305
|
-
april: 4,
|
|
306
|
-
apr: 4,
|
|
307
|
-
may: 5,
|
|
308
|
-
june: 6,
|
|
309
|
-
jun: 6,
|
|
310
|
-
july: 7,
|
|
311
|
-
jul: 7,
|
|
312
|
-
august: 8,
|
|
313
|
-
aug: 8,
|
|
314
|
-
september: 9,
|
|
315
|
-
sep: 9,
|
|
316
|
-
sept: 9,
|
|
317
|
-
october: 10,
|
|
318
|
-
oct: 10,
|
|
319
|
-
november: 11,
|
|
320
|
-
nov: 11,
|
|
321
|
-
december: 12,
|
|
322
|
-
dec: 12
|
|
323
|
-
};
|
|
324
|
-
|
|
325
562
|
// src/schemas/personal/personal-dob-schema.js
|
|
326
563
|
var personalDobSchema = Joi.object({
|
|
327
564
|
day: Joi.string().allow(""),
|
|
@@ -542,6 +779,15 @@ var schemas = {
|
|
|
542
779
|
osPlaces: osPlacesSchemas
|
|
543
780
|
};
|
|
544
781
|
|
|
782
|
+
// src/utils/format-full-name.js
|
|
783
|
+
var formatFullName = (nameData) => {
|
|
784
|
+
return [
|
|
785
|
+
nameData.first,
|
|
786
|
+
nameData.middle,
|
|
787
|
+
nameData.last
|
|
788
|
+
].filter(Boolean).join(" ");
|
|
789
|
+
};
|
|
790
|
+
|
|
545
791
|
// src/utils/format-validation-errors.js
|
|
546
792
|
var formatValidationErrors = (errors) => {
|
|
547
793
|
const formattedErrors = {};
|
|
@@ -570,228 +816,13 @@ var formatValidationErrors = (errors) => {
|
|
|
570
816
|
|
|
571
817
|
// src/utils/utils.js
|
|
572
818
|
var utils = {
|
|
819
|
+
formatFullName,
|
|
573
820
|
formatValidationErrors
|
|
574
821
|
};
|
|
575
|
-
|
|
576
|
-
// src/presenters/base-presenter.js
|
|
577
|
-
var BACK_LINK_DISPLAY_MAX = 50;
|
|
578
|
-
var formatBackLink = (businessName) => {
|
|
579
|
-
if (businessName.length > BACK_LINK_DISPLAY_MAX) {
|
|
580
|
-
return `Back to ${businessName.slice(0, BACK_LINK_DISPLAY_MAX)}\u2026`;
|
|
581
|
-
}
|
|
582
|
-
return `Back to ${businessName}`;
|
|
583
|
-
};
|
|
584
|
-
var formatNumber = (payloadNumber, changedNumber, originalNumber) => {
|
|
585
|
-
if (payloadNumber !== void 0) {
|
|
586
|
-
return payloadNumber;
|
|
587
|
-
}
|
|
588
|
-
if (changedNumber !== void 0) {
|
|
589
|
-
return changedNumber;
|
|
590
|
-
}
|
|
591
|
-
return originalNumber;
|
|
592
|
-
};
|
|
593
|
-
var formatDisplayAddress = (address) => {
|
|
594
|
-
const { lookup, manual, postcode, country, city } = address;
|
|
595
|
-
let addressLines = [];
|
|
596
|
-
if (lookup.uprn) {
|
|
597
|
-
const buildingAndStreet = [
|
|
598
|
-
lookup.buildingNumberRange,
|
|
599
|
-
lookup.street
|
|
600
|
-
].filter(Boolean).join(" ");
|
|
601
|
-
addressLines = [
|
|
602
|
-
lookup.pafOrganisationName,
|
|
603
|
-
lookup.flatName,
|
|
604
|
-
lookup.buildingName,
|
|
605
|
-
buildingAndStreet,
|
|
606
|
-
lookup.doubleDependentLocality,
|
|
607
|
-
lookup.dependentLocality,
|
|
608
|
-
city,
|
|
609
|
-
lookup.county
|
|
610
|
-
];
|
|
611
|
-
} else {
|
|
612
|
-
addressLines = [
|
|
613
|
-
manual.line1,
|
|
614
|
-
manual.line2,
|
|
615
|
-
manual.line3,
|
|
616
|
-
city,
|
|
617
|
-
manual.line4,
|
|
618
|
-
// County
|
|
619
|
-
manual.line5
|
|
620
|
-
];
|
|
621
|
-
}
|
|
622
|
-
return [
|
|
623
|
-
...addressLines.filter(Boolean),
|
|
624
|
-
postcode,
|
|
625
|
-
country
|
|
626
|
-
];
|
|
627
|
-
};
|
|
628
|
-
var buildAddressLine = (parts) => {
|
|
629
|
-
return parts.filter(Boolean).join(", ") || null;
|
|
630
|
-
};
|
|
631
|
-
var buildStreetLine = (buildingRange, street) => {
|
|
632
|
-
return [buildingRange, street].filter(Boolean).join(" ") || null;
|
|
633
|
-
};
|
|
634
|
-
var formatLookupAddress = (lookup, city, country, postcode) => ({
|
|
635
|
-
address1: buildAddressLine([lookup.pafOrganisationName, lookup.flatName, lookup.buildingName]),
|
|
636
|
-
address2: buildStreetLine(lookup.buildingNumberRange, lookup.street),
|
|
637
|
-
address3: buildAddressLine([lookup.doubleDependentLocality, lookup.dependentLocality]),
|
|
638
|
-
county: lookup.county ?? null,
|
|
639
|
-
city: city ?? null,
|
|
640
|
-
country: country ?? null,
|
|
641
|
-
postcode: postcode ?? null
|
|
642
|
-
});
|
|
643
|
-
var formatManualAddress = (manual, city, country, postcode) => ({
|
|
644
|
-
address1: manual.line1 ?? null,
|
|
645
|
-
address2: manual.line2 ?? null,
|
|
646
|
-
address3: manual.line3 ?? null,
|
|
647
|
-
city: city ?? null,
|
|
648
|
-
county: manual.line4 ?? null,
|
|
649
|
-
country: country ?? null,
|
|
650
|
-
postcode: postcode ?? null
|
|
651
|
-
});
|
|
652
|
-
var formatOriginalAddress = (originalAddress) => {
|
|
653
|
-
const { lookup, manual, city, country, postcode } = originalAddress;
|
|
654
|
-
return lookup.uprn ? formatLookupAddress(lookup, city, country, postcode) : formatManualAddress(manual, city, country, postcode);
|
|
655
|
-
};
|
|
656
|
-
var formatChangedAddress = (changeBusinessAddress) => {
|
|
657
|
-
if (!changeBusinessAddress.uprn) {
|
|
658
|
-
return changeBusinessAddress;
|
|
659
|
-
}
|
|
660
|
-
const {
|
|
661
|
-
pafOrganisationName,
|
|
662
|
-
flatName,
|
|
663
|
-
buildingName,
|
|
664
|
-
buildingNumberRange,
|
|
665
|
-
street,
|
|
666
|
-
doubleDependentLocality,
|
|
667
|
-
dependentLocality,
|
|
668
|
-
city,
|
|
669
|
-
county,
|
|
670
|
-
country,
|
|
671
|
-
postcode
|
|
672
|
-
} = changeBusinessAddress;
|
|
673
|
-
return {
|
|
674
|
-
address1: buildAddressLine([pafOrganisationName, flatName, buildingName]),
|
|
675
|
-
address2: buildStreetLine(buildingNumberRange, street),
|
|
676
|
-
address3: buildAddressLine([doubleDependentLocality, dependentLocality]),
|
|
677
|
-
city: city ?? null,
|
|
678
|
-
county: county ?? null,
|
|
679
|
-
country: country ?? null,
|
|
680
|
-
postcode: postcode ?? null
|
|
681
|
-
};
|
|
682
|
-
};
|
|
683
|
-
var formatDisplayAddresses = (addresses, previouslyPickedAddress) => {
|
|
684
|
-
const displayAddresses = addresses.map((address) => ({
|
|
685
|
-
value: `${address.uprn}${address.displayAddress}`,
|
|
686
|
-
text: address.displayAddress,
|
|
687
|
-
selected: (previouslyPickedAddress == null ? void 0 : previouslyPickedAddress.uprn) === address.uprn && (previouslyPickedAddress == null ? void 0 : previouslyPickedAddress.displayAddress) === address.displayAddress
|
|
688
|
-
}));
|
|
689
|
-
const hasSelectedAddress = displayAddresses.some((addr) => addr.selected);
|
|
690
|
-
const text = addresses.length === 1 ? "1 address found" : `${addresses.length} addresses found`;
|
|
691
|
-
displayAddresses.unshift({
|
|
692
|
-
value: "display",
|
|
693
|
-
text,
|
|
694
|
-
selected: !hasSelectedAddress
|
|
695
|
-
});
|
|
696
|
-
return displayAddresses;
|
|
697
|
-
};
|
|
698
|
-
var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDER) => {
|
|
699
|
-
const sortedErrors = [];
|
|
700
|
-
for (const section of orderedSectionsToFix) {
|
|
701
|
-
const fieldsInSection = SECTION_FIELD_ORDER[section] || [];
|
|
702
|
-
for (const field of fieldsInSection) {
|
|
703
|
-
if (errors[field]) {
|
|
704
|
-
sortedErrors.push({
|
|
705
|
-
field,
|
|
706
|
-
...errors[field]
|
|
707
|
-
});
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
return sortedErrors;
|
|
712
|
-
};
|
|
713
|
-
|
|
714
|
-
// src/presenters/business-details-presenter.js
|
|
715
|
-
var getActionText = (value) => {
|
|
716
|
-
return value ? "Change" : "Add";
|
|
717
|
-
};
|
|
718
|
-
var formatCph = (countyParishHoldings) => {
|
|
719
|
-
return (countyParishHoldings || []).filter((cph) => cph == null ? void 0 : cph.cphNumber).map((cph) => cph.cphNumber);
|
|
720
|
-
};
|
|
721
|
-
var formatCphText = (count) => {
|
|
722
|
-
return `County Parish Holding (CPH) number${count !== 1 ? "s" : ""}`;
|
|
723
|
-
};
|
|
724
|
-
var formatBusinessAddress = (businessAddress) => {
|
|
725
|
-
var _a, _b;
|
|
726
|
-
if (((_a = businessAddress == null ? void 0 : businessAddress.lookup) == null ? void 0 : _a.uprn) || ((_b = businessAddress == null ? void 0 : businessAddress.manual) == null ? void 0 : _b.line1)) {
|
|
727
|
-
return formatDisplayAddress(businessAddress);
|
|
728
|
-
}
|
|
729
|
-
return [];
|
|
730
|
-
};
|
|
731
|
-
|
|
732
|
-
// src/presenters/presenters.js
|
|
733
|
-
var presenters = {
|
|
734
|
-
formatBackLink,
|
|
735
|
-
formatNumber,
|
|
736
|
-
formatDisplayAddress,
|
|
737
|
-
formatOriginalAddress,
|
|
738
|
-
formatChangedAddress,
|
|
739
|
-
formatDisplayAddresses,
|
|
740
|
-
sortErrorsBySectionOrder,
|
|
741
|
-
getActionText,
|
|
742
|
-
formatCph,
|
|
743
|
-
formatCphText,
|
|
744
|
-
formatBusinessAddress
|
|
745
|
-
};
|
|
746
|
-
|
|
747
|
-
// src/constants/status-codes.js
|
|
748
|
-
var OK = 200;
|
|
749
|
-
var BAD_REQUEST = 400;
|
|
750
|
-
var UNAUTHORIZED = 401;
|
|
751
|
-
var FORBIDDEN = 403;
|
|
752
|
-
var NOT_FOUND = 404;
|
|
753
|
-
var NO_CONTENT = 204;
|
|
754
|
-
var FOUND = 302;
|
|
755
|
-
var INTERNAL_SERVER_ERROR = 500;
|
|
756
|
-
var SERVICE_UNAVAILABLE = 503;
|
|
757
|
-
|
|
758
|
-
// src/constants/index.js
|
|
759
|
-
var constants = {
|
|
760
|
-
statusCodes: {
|
|
761
|
-
BAD_REQUEST,
|
|
762
|
-
UNAUTHORIZED,
|
|
763
|
-
FORBIDDEN,
|
|
764
|
-
NOT_FOUND,
|
|
765
|
-
OK,
|
|
766
|
-
NO_CONTENT,
|
|
767
|
-
FOUND,
|
|
768
|
-
INTERNAL_SERVER_ERROR,
|
|
769
|
-
SERVICE_UNAVAILABLE
|
|
770
|
-
},
|
|
771
|
-
validationFields: {
|
|
772
|
-
FIRST_NAME_MAX,
|
|
773
|
-
LAST_NAME_MAX,
|
|
774
|
-
MIDDLE_NAMES_MAX,
|
|
775
|
-
BUSINESS_NAME_MAX,
|
|
776
|
-
EMAIL_MAX,
|
|
777
|
-
PHONE_NUMBER_MIN,
|
|
778
|
-
PHONE_NUMBER_MAX,
|
|
779
|
-
MAX_AGE_YEARS,
|
|
780
|
-
ADDRESS_LINE_MAX,
|
|
781
|
-
TOWN_CITY_MAX,
|
|
782
|
-
COUNTY_MAX,
|
|
783
|
-
COUNTRY_MAX,
|
|
784
|
-
POSTCODE_MAX
|
|
785
|
-
},
|
|
786
|
-
patterns: {
|
|
787
|
-
PHONE_NUMBER_PATTERN,
|
|
788
|
-
NO_CONTROL_CHARS_PATTERN
|
|
789
|
-
},
|
|
790
|
-
monthMap: MONTH_MAP
|
|
791
|
-
};
|
|
792
822
|
export {
|
|
793
823
|
constants,
|
|
794
824
|
mappers,
|
|
825
|
+
mutations,
|
|
795
826
|
presenters,
|
|
796
827
|
schemas,
|
|
797
828
|
utils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra/fcp-sfd-frontend-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Shared frontend engine used by both the internal and external frontend applications.",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"exports": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@vitest/coverage-v8": "4.1.10",
|
|
42
42
|
"eslint": "9.39.2",
|
|
43
|
+
"graphql": "16.13.2",
|
|
43
44
|
"neostandard": "0.13.0",
|
|
44
45
|
"tsup": "8.5.1",
|
|
45
46
|
"vitest": "4.1.10"
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
export { constants } from './constants/index.js'
|
|
1
2
|
export { mappers } from './mappers/mappers.js'
|
|
3
|
+
export { mutations } from './mutations/mutations.js'
|
|
4
|
+
export { presenters } from './presenters/presenters.js'
|
|
2
5
|
export { schemas } from './schemas/schemas.js'
|
|
3
6
|
export { utils } from './utils/utils.js'
|
|
4
|
-
export { presenters } from './presenters/presenters.js'
|
|
5
|
-
export { constants } from './constants/index.js'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Joins the parts of a name (first, middle, last) into a single display string,
|
|
3
|
+
* omitting any empty parts.
|
|
4
|
+
*
|
|
5
|
+
* @param {object} nameData - An object with `first`, `middle` and `last` name parts
|
|
6
|
+
* @returns {string} The formatted full name
|
|
7
|
+
*/
|
|
8
|
+
export const formatFullName = (nameData) => {
|
|
9
|
+
return [
|
|
10
|
+
nameData.first,
|
|
11
|
+
nameData.middle,
|
|
12
|
+
nameData.last
|
|
13
|
+
].filter(Boolean).join(' ')
|
|
14
|
+
}
|