@defra/fcp-sfd-frontend-engine 0.9.1 → 0.11.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 +322 -273
- package/dist/index.js +321 -273
- package/package.json +2 -1
- package/src/index.js +3 -2
- package/src/mutations/business/update-business-email.js +14 -0
- package/src/mutations/mutations.js +7 -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,218 @@ var mappers = {
|
|
|
130
224
|
businessDetails: mapBusinessDetails
|
|
131
225
|
};
|
|
132
226
|
|
|
133
|
-
// src/
|
|
134
|
-
var
|
|
227
|
+
// src/mutations/business/update-business-email.js
|
|
228
|
+
var updateBusinessEmailMutation = `
|
|
229
|
+
mutation Mutation($input: UpdateBusinessEmailInput!) {
|
|
230
|
+
updateBusinessEmail(input: $input) {
|
|
231
|
+
business {
|
|
232
|
+
info {
|
|
233
|
+
email {
|
|
234
|
+
address
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
success
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
`;
|
|
242
|
+
|
|
243
|
+
// src/mutations/personal/update-customer-name.js
|
|
244
|
+
var updateCustomerNameMutation = `
|
|
245
|
+
mutation UpdateCustomerName($input: UpdateCustomerNameInput!) {
|
|
246
|
+
updateCustomerName(input: $input) {
|
|
247
|
+
customer {
|
|
248
|
+
info {
|
|
249
|
+
name {
|
|
250
|
+
first
|
|
251
|
+
last
|
|
252
|
+
middle
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
`;
|
|
135
259
|
|
|
136
|
-
// src/
|
|
137
|
-
var
|
|
138
|
-
|
|
260
|
+
// src/mutations/mutations.js
|
|
261
|
+
var mutations = {
|
|
262
|
+
updateBusinessEmail: updateBusinessEmailMutation,
|
|
263
|
+
updateCustomerName: updateCustomerNameMutation
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// src/presenters/base-presenter.js
|
|
267
|
+
var BACK_LINK_DISPLAY_MAX = 50;
|
|
268
|
+
var formatBackLink = (businessName) => {
|
|
269
|
+
if (businessName.length > BACK_LINK_DISPLAY_MAX) {
|
|
270
|
+
return `Back to ${businessName.slice(0, BACK_LINK_DISPLAY_MAX)}\u2026`;
|
|
271
|
+
}
|
|
272
|
+
return `Back to ${businessName}`;
|
|
273
|
+
};
|
|
274
|
+
var formatNumber = (payloadNumber, changedNumber, originalNumber) => {
|
|
275
|
+
if (payloadNumber !== void 0) {
|
|
276
|
+
return payloadNumber;
|
|
277
|
+
}
|
|
278
|
+
if (changedNumber !== void 0) {
|
|
279
|
+
return changedNumber;
|
|
280
|
+
}
|
|
281
|
+
return originalNumber;
|
|
282
|
+
};
|
|
283
|
+
var formatDisplayAddress = (address) => {
|
|
284
|
+
const { lookup, manual, postcode, country, city } = address;
|
|
285
|
+
let addressLines = [];
|
|
286
|
+
if (lookup.uprn) {
|
|
287
|
+
const buildingAndStreet = [
|
|
288
|
+
lookup.buildingNumberRange,
|
|
289
|
+
lookup.street
|
|
290
|
+
].filter(Boolean).join(" ");
|
|
291
|
+
addressLines = [
|
|
292
|
+
lookup.pafOrganisationName,
|
|
293
|
+
lookup.flatName,
|
|
294
|
+
lookup.buildingName,
|
|
295
|
+
buildingAndStreet,
|
|
296
|
+
lookup.doubleDependentLocality,
|
|
297
|
+
lookup.dependentLocality,
|
|
298
|
+
city,
|
|
299
|
+
lookup.county
|
|
300
|
+
];
|
|
301
|
+
} else {
|
|
302
|
+
addressLines = [
|
|
303
|
+
manual.line1,
|
|
304
|
+
manual.line2,
|
|
305
|
+
manual.line3,
|
|
306
|
+
city,
|
|
307
|
+
manual.line4,
|
|
308
|
+
// County
|
|
309
|
+
manual.line5
|
|
310
|
+
];
|
|
311
|
+
}
|
|
312
|
+
return [
|
|
313
|
+
...addressLines.filter(Boolean),
|
|
314
|
+
postcode,
|
|
315
|
+
country
|
|
316
|
+
];
|
|
317
|
+
};
|
|
318
|
+
var buildAddressLine = (parts) => {
|
|
319
|
+
return parts.filter(Boolean).join(", ") || null;
|
|
320
|
+
};
|
|
321
|
+
var buildStreetLine = (buildingRange, street) => {
|
|
322
|
+
return [buildingRange, street].filter(Boolean).join(" ") || null;
|
|
323
|
+
};
|
|
324
|
+
var formatLookupAddress = (lookup, city, country, postcode) => ({
|
|
325
|
+
address1: buildAddressLine([lookup.pafOrganisationName, lookup.flatName, lookup.buildingName]),
|
|
326
|
+
address2: buildStreetLine(lookup.buildingNumberRange, lookup.street),
|
|
327
|
+
address3: buildAddressLine([lookup.doubleDependentLocality, lookup.dependentLocality]),
|
|
328
|
+
county: lookup.county ?? null,
|
|
329
|
+
city: city ?? null,
|
|
330
|
+
country: country ?? null,
|
|
331
|
+
postcode: postcode ?? null
|
|
332
|
+
});
|
|
333
|
+
var formatManualAddress = (manual, city, country, postcode) => ({
|
|
334
|
+
address1: manual.line1 ?? null,
|
|
335
|
+
address2: manual.line2 ?? null,
|
|
336
|
+
address3: manual.line3 ?? null,
|
|
337
|
+
city: city ?? null,
|
|
338
|
+
county: manual.line4 ?? null,
|
|
339
|
+
country: country ?? null,
|
|
340
|
+
postcode: postcode ?? null
|
|
341
|
+
});
|
|
342
|
+
var formatOriginalAddress = (originalAddress) => {
|
|
343
|
+
const { lookup, manual, city, country, postcode } = originalAddress;
|
|
344
|
+
return lookup.uprn ? formatLookupAddress(lookup, city, country, postcode) : formatManualAddress(manual, city, country, postcode);
|
|
345
|
+
};
|
|
346
|
+
var formatChangedAddress = (changeBusinessAddress) => {
|
|
347
|
+
if (!changeBusinessAddress.uprn) {
|
|
348
|
+
return changeBusinessAddress;
|
|
349
|
+
}
|
|
350
|
+
const {
|
|
351
|
+
pafOrganisationName,
|
|
352
|
+
flatName,
|
|
353
|
+
buildingName,
|
|
354
|
+
buildingNumberRange,
|
|
355
|
+
street,
|
|
356
|
+
doubleDependentLocality,
|
|
357
|
+
dependentLocality,
|
|
358
|
+
city,
|
|
359
|
+
county,
|
|
360
|
+
country,
|
|
361
|
+
postcode
|
|
362
|
+
} = changeBusinessAddress;
|
|
363
|
+
return {
|
|
364
|
+
address1: buildAddressLine([pafOrganisationName, flatName, buildingName]),
|
|
365
|
+
address2: buildStreetLine(buildingNumberRange, street),
|
|
366
|
+
address3: buildAddressLine([doubleDependentLocality, dependentLocality]),
|
|
367
|
+
city: city ?? null,
|
|
368
|
+
county: county ?? null,
|
|
369
|
+
country: country ?? null,
|
|
370
|
+
postcode: postcode ?? null
|
|
371
|
+
};
|
|
372
|
+
};
|
|
373
|
+
var formatDisplayAddresses = (addresses, previouslyPickedAddress) => {
|
|
374
|
+
const displayAddresses = addresses.map((address) => ({
|
|
375
|
+
value: `${address.uprn}${address.displayAddress}`,
|
|
376
|
+
text: address.displayAddress,
|
|
377
|
+
selected: (previouslyPickedAddress == null ? void 0 : previouslyPickedAddress.uprn) === address.uprn && (previouslyPickedAddress == null ? void 0 : previouslyPickedAddress.displayAddress) === address.displayAddress
|
|
378
|
+
}));
|
|
379
|
+
const hasSelectedAddress = displayAddresses.some((addr) => addr.selected);
|
|
380
|
+
const text = addresses.length === 1 ? "1 address found" : `${addresses.length} addresses found`;
|
|
381
|
+
displayAddresses.unshift({
|
|
382
|
+
value: "display",
|
|
383
|
+
text,
|
|
384
|
+
selected: !hasSelectedAddress
|
|
385
|
+
});
|
|
386
|
+
return displayAddresses;
|
|
387
|
+
};
|
|
388
|
+
var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDER) => {
|
|
389
|
+
const sortedErrors = [];
|
|
390
|
+
for (const section of orderedSectionsToFix) {
|
|
391
|
+
const fieldsInSection = SECTION_FIELD_ORDER[section] || [];
|
|
392
|
+
for (const field of fieldsInSection) {
|
|
393
|
+
if (errors[field]) {
|
|
394
|
+
sortedErrors.push({
|
|
395
|
+
field,
|
|
396
|
+
...errors[field]
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return sortedErrors;
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
// src/presenters/business-details-presenter.js
|
|
405
|
+
var getActionText = (value) => {
|
|
406
|
+
return value ? "Change" : "Add";
|
|
407
|
+
};
|
|
408
|
+
var formatCph = (countyParishHoldings) => {
|
|
409
|
+
return (countyParishHoldings || []).filter((cph) => cph == null ? void 0 : cph.cphNumber).map((cph) => cph.cphNumber);
|
|
410
|
+
};
|
|
411
|
+
var formatCphText = (count) => {
|
|
412
|
+
return `County Parish Holding (CPH) number${count !== 1 ? "s" : ""}`;
|
|
413
|
+
};
|
|
414
|
+
var formatBusinessAddress = (businessAddress) => {
|
|
415
|
+
var _a, _b;
|
|
416
|
+
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)) {
|
|
417
|
+
return formatDisplayAddress(businessAddress);
|
|
418
|
+
}
|
|
419
|
+
return [];
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
// src/presenters/presenters.js
|
|
423
|
+
var presenters = {
|
|
424
|
+
formatBackLink,
|
|
425
|
+
formatNumber,
|
|
426
|
+
formatDisplayAddress,
|
|
427
|
+
formatOriginalAddress,
|
|
428
|
+
formatChangedAddress,
|
|
429
|
+
formatDisplayAddresses,
|
|
430
|
+
sortErrorsBySectionOrder,
|
|
431
|
+
getActionText,
|
|
432
|
+
formatCph,
|
|
433
|
+
formatCphText,
|
|
434
|
+
formatBusinessAddress
|
|
435
|
+
};
|
|
139
436
|
|
|
140
437
|
// src/utils/joi.js
|
|
438
|
+
var import_joi = __toESM(require("joi"), 1);
|
|
141
439
|
var Joi = import_joi.default.extend((joi) => ({
|
|
142
440
|
type: "string",
|
|
143
441
|
base: joi.string(),
|
|
@@ -152,29 +450,14 @@ var Joi = import_joi.default.extend((joi) => ({
|
|
|
152
450
|
}
|
|
153
451
|
}));
|
|
154
452
|
|
|
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
|
-
|
|
453
|
+
// src/schemas/business/business-sbi-schema.js
|
|
454
|
+
var businessSbiSchema = Joi.object({
|
|
455
|
+
sbi: Joi.string().pattern(/^\d{9}$/).allow("").optional().messages({
|
|
456
|
+
"string.pattern.base": "Enter the full SBI",
|
|
457
|
+
"string.noControlChars": "SBI must not contain invalid characters"
|
|
458
|
+
})
|
|
459
|
+
});
|
|
460
|
+
|
|
178
461
|
// src/schemas/shared/address-schema.js
|
|
179
462
|
var addressSchema = Joi.object({
|
|
180
463
|
address1: Joi.string().trim().required().max(ADDRESS_LINE_MAX).messages({
|
|
@@ -333,34 +616,6 @@ var personalNameSchema = Joi.object({
|
|
|
333
616
|
})
|
|
334
617
|
});
|
|
335
618
|
|
|
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
619
|
// src/schemas/personal/personal-dob-schema.js
|
|
365
620
|
var personalDobSchema = Joi.object({
|
|
366
621
|
day: Joi.string().allow(""),
|
|
@@ -581,6 +836,15 @@ var schemas = {
|
|
|
581
836
|
osPlaces: osPlacesSchemas
|
|
582
837
|
};
|
|
583
838
|
|
|
839
|
+
// src/utils/format-full-name.js
|
|
840
|
+
var formatFullName = (nameData) => {
|
|
841
|
+
return [
|
|
842
|
+
nameData.first,
|
|
843
|
+
nameData.middle,
|
|
844
|
+
nameData.last
|
|
845
|
+
].filter(Boolean).join(" ");
|
|
846
|
+
};
|
|
847
|
+
|
|
584
848
|
// src/utils/format-validation-errors.js
|
|
585
849
|
var formatValidationErrors = (errors) => {
|
|
586
850
|
const formattedErrors = {};
|
|
@@ -609,229 +873,14 @@ var formatValidationErrors = (errors) => {
|
|
|
609
873
|
|
|
610
874
|
// src/utils/utils.js
|
|
611
875
|
var utils = {
|
|
876
|
+
formatFullName,
|
|
612
877
|
formatValidationErrors
|
|
613
878
|
};
|
|
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
879
|
// Annotate the CommonJS export names for ESM import in node:
|
|
832
880
|
0 && (module.exports = {
|
|
833
881
|
constants,
|
|
834
882
|
mappers,
|
|
883
|
+
mutations,
|
|
835
884
|
presenters,
|
|
836
885
|
schemas,
|
|
837
886
|
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,218 @@ var mappers = {
|
|
|
91
184
|
businessDetails: mapBusinessDetails
|
|
92
185
|
};
|
|
93
186
|
|
|
94
|
-
// src/
|
|
95
|
-
|
|
187
|
+
// src/mutations/business/update-business-email.js
|
|
188
|
+
var updateBusinessEmailMutation = `
|
|
189
|
+
mutation Mutation($input: UpdateBusinessEmailInput!) {
|
|
190
|
+
updateBusinessEmail(input: $input) {
|
|
191
|
+
business {
|
|
192
|
+
info {
|
|
193
|
+
email {
|
|
194
|
+
address
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
success
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
`;
|
|
202
|
+
|
|
203
|
+
// src/mutations/personal/update-customer-name.js
|
|
204
|
+
var updateCustomerNameMutation = `
|
|
205
|
+
mutation UpdateCustomerName($input: UpdateCustomerNameInput!) {
|
|
206
|
+
updateCustomerName(input: $input) {
|
|
207
|
+
customer {
|
|
208
|
+
info {
|
|
209
|
+
name {
|
|
210
|
+
first
|
|
211
|
+
last
|
|
212
|
+
middle
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
`;
|
|
96
219
|
|
|
97
|
-
// src/
|
|
98
|
-
var
|
|
99
|
-
|
|
220
|
+
// src/mutations/mutations.js
|
|
221
|
+
var mutations = {
|
|
222
|
+
updateBusinessEmail: updateBusinessEmailMutation,
|
|
223
|
+
updateCustomerName: updateCustomerNameMutation
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// src/presenters/base-presenter.js
|
|
227
|
+
var BACK_LINK_DISPLAY_MAX = 50;
|
|
228
|
+
var formatBackLink = (businessName) => {
|
|
229
|
+
if (businessName.length > BACK_LINK_DISPLAY_MAX) {
|
|
230
|
+
return `Back to ${businessName.slice(0, BACK_LINK_DISPLAY_MAX)}\u2026`;
|
|
231
|
+
}
|
|
232
|
+
return `Back to ${businessName}`;
|
|
233
|
+
};
|
|
234
|
+
var formatNumber = (payloadNumber, changedNumber, originalNumber) => {
|
|
235
|
+
if (payloadNumber !== void 0) {
|
|
236
|
+
return payloadNumber;
|
|
237
|
+
}
|
|
238
|
+
if (changedNumber !== void 0) {
|
|
239
|
+
return changedNumber;
|
|
240
|
+
}
|
|
241
|
+
return originalNumber;
|
|
242
|
+
};
|
|
243
|
+
var formatDisplayAddress = (address) => {
|
|
244
|
+
const { lookup, manual, postcode, country, city } = address;
|
|
245
|
+
let addressLines = [];
|
|
246
|
+
if (lookup.uprn) {
|
|
247
|
+
const buildingAndStreet = [
|
|
248
|
+
lookup.buildingNumberRange,
|
|
249
|
+
lookup.street
|
|
250
|
+
].filter(Boolean).join(" ");
|
|
251
|
+
addressLines = [
|
|
252
|
+
lookup.pafOrganisationName,
|
|
253
|
+
lookup.flatName,
|
|
254
|
+
lookup.buildingName,
|
|
255
|
+
buildingAndStreet,
|
|
256
|
+
lookup.doubleDependentLocality,
|
|
257
|
+
lookup.dependentLocality,
|
|
258
|
+
city,
|
|
259
|
+
lookup.county
|
|
260
|
+
];
|
|
261
|
+
} else {
|
|
262
|
+
addressLines = [
|
|
263
|
+
manual.line1,
|
|
264
|
+
manual.line2,
|
|
265
|
+
manual.line3,
|
|
266
|
+
city,
|
|
267
|
+
manual.line4,
|
|
268
|
+
// County
|
|
269
|
+
manual.line5
|
|
270
|
+
];
|
|
271
|
+
}
|
|
272
|
+
return [
|
|
273
|
+
...addressLines.filter(Boolean),
|
|
274
|
+
postcode,
|
|
275
|
+
country
|
|
276
|
+
];
|
|
277
|
+
};
|
|
278
|
+
var buildAddressLine = (parts) => {
|
|
279
|
+
return parts.filter(Boolean).join(", ") || null;
|
|
280
|
+
};
|
|
281
|
+
var buildStreetLine = (buildingRange, street) => {
|
|
282
|
+
return [buildingRange, street].filter(Boolean).join(" ") || null;
|
|
283
|
+
};
|
|
284
|
+
var formatLookupAddress = (lookup, city, country, postcode) => ({
|
|
285
|
+
address1: buildAddressLine([lookup.pafOrganisationName, lookup.flatName, lookup.buildingName]),
|
|
286
|
+
address2: buildStreetLine(lookup.buildingNumberRange, lookup.street),
|
|
287
|
+
address3: buildAddressLine([lookup.doubleDependentLocality, lookup.dependentLocality]),
|
|
288
|
+
county: lookup.county ?? null,
|
|
289
|
+
city: city ?? null,
|
|
290
|
+
country: country ?? null,
|
|
291
|
+
postcode: postcode ?? null
|
|
292
|
+
});
|
|
293
|
+
var formatManualAddress = (manual, city, country, postcode) => ({
|
|
294
|
+
address1: manual.line1 ?? null,
|
|
295
|
+
address2: manual.line2 ?? null,
|
|
296
|
+
address3: manual.line3 ?? null,
|
|
297
|
+
city: city ?? null,
|
|
298
|
+
county: manual.line4 ?? null,
|
|
299
|
+
country: country ?? null,
|
|
300
|
+
postcode: postcode ?? null
|
|
301
|
+
});
|
|
302
|
+
var formatOriginalAddress = (originalAddress) => {
|
|
303
|
+
const { lookup, manual, city, country, postcode } = originalAddress;
|
|
304
|
+
return lookup.uprn ? formatLookupAddress(lookup, city, country, postcode) : formatManualAddress(manual, city, country, postcode);
|
|
305
|
+
};
|
|
306
|
+
var formatChangedAddress = (changeBusinessAddress) => {
|
|
307
|
+
if (!changeBusinessAddress.uprn) {
|
|
308
|
+
return changeBusinessAddress;
|
|
309
|
+
}
|
|
310
|
+
const {
|
|
311
|
+
pafOrganisationName,
|
|
312
|
+
flatName,
|
|
313
|
+
buildingName,
|
|
314
|
+
buildingNumberRange,
|
|
315
|
+
street,
|
|
316
|
+
doubleDependentLocality,
|
|
317
|
+
dependentLocality,
|
|
318
|
+
city,
|
|
319
|
+
county,
|
|
320
|
+
country,
|
|
321
|
+
postcode
|
|
322
|
+
} = changeBusinessAddress;
|
|
323
|
+
return {
|
|
324
|
+
address1: buildAddressLine([pafOrganisationName, flatName, buildingName]),
|
|
325
|
+
address2: buildStreetLine(buildingNumberRange, street),
|
|
326
|
+
address3: buildAddressLine([doubleDependentLocality, dependentLocality]),
|
|
327
|
+
city: city ?? null,
|
|
328
|
+
county: county ?? null,
|
|
329
|
+
country: country ?? null,
|
|
330
|
+
postcode: postcode ?? null
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
var formatDisplayAddresses = (addresses, previouslyPickedAddress) => {
|
|
334
|
+
const displayAddresses = addresses.map((address) => ({
|
|
335
|
+
value: `${address.uprn}${address.displayAddress}`,
|
|
336
|
+
text: address.displayAddress,
|
|
337
|
+
selected: (previouslyPickedAddress == null ? void 0 : previouslyPickedAddress.uprn) === address.uprn && (previouslyPickedAddress == null ? void 0 : previouslyPickedAddress.displayAddress) === address.displayAddress
|
|
338
|
+
}));
|
|
339
|
+
const hasSelectedAddress = displayAddresses.some((addr) => addr.selected);
|
|
340
|
+
const text = addresses.length === 1 ? "1 address found" : `${addresses.length} addresses found`;
|
|
341
|
+
displayAddresses.unshift({
|
|
342
|
+
value: "display",
|
|
343
|
+
text,
|
|
344
|
+
selected: !hasSelectedAddress
|
|
345
|
+
});
|
|
346
|
+
return displayAddresses;
|
|
347
|
+
};
|
|
348
|
+
var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDER) => {
|
|
349
|
+
const sortedErrors = [];
|
|
350
|
+
for (const section of orderedSectionsToFix) {
|
|
351
|
+
const fieldsInSection = SECTION_FIELD_ORDER[section] || [];
|
|
352
|
+
for (const field of fieldsInSection) {
|
|
353
|
+
if (errors[field]) {
|
|
354
|
+
sortedErrors.push({
|
|
355
|
+
field,
|
|
356
|
+
...errors[field]
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return sortedErrors;
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
// src/presenters/business-details-presenter.js
|
|
365
|
+
var getActionText = (value) => {
|
|
366
|
+
return value ? "Change" : "Add";
|
|
367
|
+
};
|
|
368
|
+
var formatCph = (countyParishHoldings) => {
|
|
369
|
+
return (countyParishHoldings || []).filter((cph) => cph == null ? void 0 : cph.cphNumber).map((cph) => cph.cphNumber);
|
|
370
|
+
};
|
|
371
|
+
var formatCphText = (count) => {
|
|
372
|
+
return `County Parish Holding (CPH) number${count !== 1 ? "s" : ""}`;
|
|
373
|
+
};
|
|
374
|
+
var formatBusinessAddress = (businessAddress) => {
|
|
375
|
+
var _a, _b;
|
|
376
|
+
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)) {
|
|
377
|
+
return formatDisplayAddress(businessAddress);
|
|
378
|
+
}
|
|
379
|
+
return [];
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
// src/presenters/presenters.js
|
|
383
|
+
var presenters = {
|
|
384
|
+
formatBackLink,
|
|
385
|
+
formatNumber,
|
|
386
|
+
formatDisplayAddress,
|
|
387
|
+
formatOriginalAddress,
|
|
388
|
+
formatChangedAddress,
|
|
389
|
+
formatDisplayAddresses,
|
|
390
|
+
sortErrorsBySectionOrder,
|
|
391
|
+
getActionText,
|
|
392
|
+
formatCph,
|
|
393
|
+
formatCphText,
|
|
394
|
+
formatBusinessAddress
|
|
395
|
+
};
|
|
100
396
|
|
|
101
397
|
// src/utils/joi.js
|
|
398
|
+
import BaseJoi from "joi";
|
|
102
399
|
var Joi = BaseJoi.extend((joi) => ({
|
|
103
400
|
type: "string",
|
|
104
401
|
base: joi.string(),
|
|
@@ -113,29 +410,14 @@ var Joi = BaseJoi.extend((joi) => ({
|
|
|
113
410
|
}
|
|
114
411
|
}));
|
|
115
412
|
|
|
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
|
-
|
|
413
|
+
// src/schemas/business/business-sbi-schema.js
|
|
414
|
+
var businessSbiSchema = Joi.object({
|
|
415
|
+
sbi: Joi.string().pattern(/^\d{9}$/).allow("").optional().messages({
|
|
416
|
+
"string.pattern.base": "Enter the full SBI",
|
|
417
|
+
"string.noControlChars": "SBI must not contain invalid characters"
|
|
418
|
+
})
|
|
419
|
+
});
|
|
420
|
+
|
|
139
421
|
// src/schemas/shared/address-schema.js
|
|
140
422
|
var addressSchema = Joi.object({
|
|
141
423
|
address1: Joi.string().trim().required().max(ADDRESS_LINE_MAX).messages({
|
|
@@ -294,34 +576,6 @@ var personalNameSchema = Joi.object({
|
|
|
294
576
|
})
|
|
295
577
|
});
|
|
296
578
|
|
|
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
579
|
// src/schemas/personal/personal-dob-schema.js
|
|
326
580
|
var personalDobSchema = Joi.object({
|
|
327
581
|
day: Joi.string().allow(""),
|
|
@@ -542,6 +796,15 @@ var schemas = {
|
|
|
542
796
|
osPlaces: osPlacesSchemas
|
|
543
797
|
};
|
|
544
798
|
|
|
799
|
+
// src/utils/format-full-name.js
|
|
800
|
+
var formatFullName = (nameData) => {
|
|
801
|
+
return [
|
|
802
|
+
nameData.first,
|
|
803
|
+
nameData.middle,
|
|
804
|
+
nameData.last
|
|
805
|
+
].filter(Boolean).join(" ");
|
|
806
|
+
};
|
|
807
|
+
|
|
545
808
|
// src/utils/format-validation-errors.js
|
|
546
809
|
var formatValidationErrors = (errors) => {
|
|
547
810
|
const formattedErrors = {};
|
|
@@ -570,228 +833,13 @@ var formatValidationErrors = (errors) => {
|
|
|
570
833
|
|
|
571
834
|
// src/utils/utils.js
|
|
572
835
|
var utils = {
|
|
836
|
+
formatFullName,
|
|
573
837
|
formatValidationErrors
|
|
574
838
|
};
|
|
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
839
|
export {
|
|
793
840
|
constants,
|
|
794
841
|
mappers,
|
|
842
|
+
mutations,
|
|
795
843
|
presenters,
|
|
796
844
|
schemas,
|
|
797
845
|
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.11.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,7 @@
|
|
|
1
|
+
import { updateBusinessEmailMutation } from './business/update-business-email.js'
|
|
2
|
+
import { updateCustomerNameMutation } from './personal/update-customer-name.js'
|
|
3
|
+
|
|
4
|
+
export const mutations = {
|
|
5
|
+
updateBusinessEmail: updateBusinessEmailMutation,
|
|
6
|
+
updateCustomerName: updateCustomerNameMutation
|
|
7
|
+
}
|
|
@@ -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
|
+
}
|