@govuk-pay/pay-js-commons 3.7.0 → 3.8.2
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/.github/workflows/run-tests.yml +3 -3
- package/.idea/codeStyles/Project.xml +31 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/jpa-buddy.xml +6 -0
- package/.idea/misc.xml +9 -0
- package/.idea/modules.xml +8 -0
- package/.idea/pay-js-commons.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/images/custom/neath_port_talbet_council.png +0 -0
- package/lib/analytics/cookies/validate.js +4 -26
- package/lib/analytics/dist/cookies.js +724 -27
- package/lib/analytics/index.js +0 -1
- package/lib/browsered/field-validation/field-validation.js +4 -22
- package/lib/constants/index.js +1 -1
- package/lib/index.js +2 -7
- package/lib/logging/format.js +1 -2
- package/lib/logging/index.js +1 -4
- package/lib/logging/keys.js +67 -32
- package/lib/logging/request-log-format.js +0 -2
- package/lib/nunjucks-filters/country-iso-to-name.js +1 -2
- package/lib/nunjucks-filters/datetime.js +0 -3
- package/lib/nunjucks-filters/remove-indefinite-articles.js +1 -0
- package/lib/nunjucks-filters/slugify.js +0 -1
- package/lib/utils/countries.js +8 -10
- package/lib/utils/currency-formatter.js +2 -10
- package/lib/utils/field-validation-checks.js +6 -22
- package/lib/utils/is-valid-email.js +2 -3
- package/package.json +7 -7
- package/sass/custom/neath_port_talbet_council.scss +56 -0
package/lib/analytics/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var every = require('lodash/every'); // Local Dependencies
|
|
1
|
+
'use strict';
|
|
4
2
|
|
|
3
|
+
// NPM Dependencies
|
|
4
|
+
var every = require('lodash/every');
|
|
5
5
|
|
|
6
|
+
// Local Dependencies
|
|
6
7
|
var checks = require('../../utils/field-validation-checks');
|
|
7
|
-
|
|
8
8
|
exports.enableFieldValidation = function () {
|
|
9
9
|
var allForms = Array.prototype.slice.call(document.getElementsByTagName('form'));
|
|
10
10
|
allForms.filter(function (form) {
|
|
@@ -13,7 +13,6 @@ exports.enableFieldValidation = function () {
|
|
|
13
13
|
return form.addEventListener('submit', initValidation, false);
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
|
-
|
|
17
16
|
function initValidation(e) {
|
|
18
17
|
var form = e.target;
|
|
19
18
|
e.preventDefault();
|
|
@@ -21,14 +20,12 @@ function initValidation(e) {
|
|
|
21
20
|
var validatedFields = findFields(form).map(function (field) {
|
|
22
21
|
return validateField(form, field);
|
|
23
22
|
});
|
|
24
|
-
|
|
25
23
|
if (every(validatedFields)) {
|
|
26
24
|
form.submit();
|
|
27
25
|
} else {
|
|
28
26
|
populateErrorSummary(form);
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
function clearPreviousErrors() {
|
|
33
30
|
var previousErrorsMessages = Array.prototype.slice.call(document.querySelectorAll('.error-message, .error-summary'));
|
|
34
31
|
var previousErrorsFields = Array.prototype.slice.call(document.querySelectorAll('.form-group.error'));
|
|
@@ -39,14 +36,12 @@ function clearPreviousErrors() {
|
|
|
39
36
|
return errorField.classList.remove('error');
|
|
40
37
|
});
|
|
41
38
|
}
|
|
42
|
-
|
|
43
39
|
function findFields(form) {
|
|
44
40
|
var formFields = Array.prototype.slice.call(form.querySelectorAll('input, textarea, select'));
|
|
45
41
|
return formFields.filter(function (field) {
|
|
46
42
|
return field.hasAttribute('data-validate');
|
|
47
43
|
});
|
|
48
44
|
}
|
|
49
|
-
|
|
50
45
|
function validateField(form, field) {
|
|
51
46
|
var result;
|
|
52
47
|
var validationTypes = field.getAttribute('data-validate').split(' ');
|
|
@@ -55,60 +50,47 @@ function validateField(form, field) {
|
|
|
55
50
|
case 'required':
|
|
56
51
|
result = checks.isEmpty(field.value);
|
|
57
52
|
break;
|
|
58
|
-
|
|
59
53
|
case 'currency':
|
|
60
54
|
result = checks.isCurrency(field.value);
|
|
61
55
|
break;
|
|
62
|
-
|
|
63
56
|
case 'email':
|
|
64
57
|
result = checks.isValidEmail(field.value);
|
|
65
58
|
break;
|
|
66
|
-
|
|
67
59
|
case 'phone':
|
|
68
60
|
result = checks.isPhoneNumber(field.value);
|
|
69
61
|
break;
|
|
70
|
-
|
|
71
62
|
case 'https':
|
|
72
63
|
result = checks.isHttps(field.value);
|
|
73
64
|
break;
|
|
74
|
-
|
|
75
65
|
case 'belowMaxAmount':
|
|
76
66
|
result = checks.isAboveMaxAmount(field.value);
|
|
77
67
|
break;
|
|
78
|
-
|
|
79
68
|
case 'passwordLessThanTenChars':
|
|
80
69
|
result = checks.isPasswordLessThanTenChars(field.value);
|
|
81
70
|
break;
|
|
82
|
-
|
|
83
71
|
case 'isFieldGreaterThanMaxLengthChars':
|
|
84
72
|
result = checks.isFieldGreaterThanMaxLengthChars(field.value, field.getAttribute('data-validate-max-length'));
|
|
85
73
|
break;
|
|
86
|
-
|
|
87
74
|
case 'isNaxsiSafe':
|
|
88
75
|
result = checks.isNaxsiSafe(field.value);
|
|
89
76
|
break;
|
|
90
|
-
|
|
91
77
|
default:
|
|
92
78
|
result = false;
|
|
93
79
|
break;
|
|
94
80
|
}
|
|
95
|
-
|
|
96
81
|
if (result) {
|
|
97
82
|
applyErrorMessaging(form, field, result);
|
|
98
83
|
}
|
|
99
84
|
});
|
|
100
85
|
return !field.closest('.form-group').classList.contains('error');
|
|
101
86
|
}
|
|
102
|
-
|
|
103
87
|
function applyErrorMessaging(form, field, result) {
|
|
104
88
|
var formGroup = field.closest('.form-group');
|
|
105
|
-
|
|
106
89
|
if (!formGroup.classList.contains('error')) {
|
|
107
90
|
formGroup.classList.add('error');
|
|
108
91
|
document.querySelector('label[for="' + field.id + '"]').insertAdjacentHTML('beforeend', '<span class="error-message">' + result + '</span>');
|
|
109
92
|
}
|
|
110
93
|
}
|
|
111
|
-
|
|
112
94
|
function populateErrorSummary(form) {
|
|
113
95
|
var erroringFields = Array.prototype.slice.call(form.querySelectorAll('.form-group.error label'));
|
|
114
96
|
var errorMessages = erroringFields.map(function (field) {
|
package/lib/constants/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
|
|
2
3
|
/*
|
|
3
4
|
Metadata Column constants match up those defined:
|
|
4
5
|
https://github.com/alphagov/pay-java-commons/blob/master/model/src/main/java/uk/gov/pay/commons/model/charge/ExternalMetadata.java
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
7
|
module.exports = {
|
|
8
8
|
externalMetadata: {
|
|
9
9
|
MAX_KEY_VALUE_PAIRS: 10,
|
package/lib/index.js
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var browsered = require('./browsered');
|
|
4
|
-
|
|
5
4
|
var utils = require('./utils');
|
|
6
|
-
|
|
7
5
|
var nunjucksFilters = require('./nunjucks-filters');
|
|
8
|
-
|
|
9
6
|
var logging = require('./logging');
|
|
7
|
+
var constants = require('./constants');
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
// Add to window.GOVUKPAY if in browser context
|
|
14
10
|
if (typeof window !== 'undefined') {
|
|
15
11
|
window.GOVUKPAY = window.GOVUKPAY || {};
|
|
16
12
|
window.GOVUKPAY = {
|
|
17
13
|
browsered: browsered
|
|
18
14
|
};
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
module.exports = {
|
|
22
17
|
browsered: browsered,
|
|
23
18
|
utils: utils,
|
package/lib/logging/format.js
CHANGED
package/lib/logging/index.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var keys = require('./keys');
|
|
4
|
-
|
|
5
4
|
var _require = require('./format'),
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
govUkPayLoggingFormat = _require.govUkPayLoggingFormat;
|
|
8
6
|
var requestLogFormat = require('./request-log-format');
|
|
9
|
-
|
|
10
7
|
module.exports = {
|
|
11
8
|
govUkPayLoggingFormat: govUkPayLoggingFormat,
|
|
12
9
|
keys: keys,
|
package/lib/logging/keys.js
CHANGED
|
@@ -1,73 +1,108 @@
|
|
|
1
|
-
'use strict';
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// This file needs to be kept in sync with its Java consociate
|
|
2
4
|
// https://github.com/alphagov/pay-java-commons/blob/master/logging/src/main/java/uk/gov/pay/logging/LoggingKeys.java
|
|
5
|
+
|
|
3
6
|
// "card", "Direct Debit"
|
|
7
|
+
exports.PAYMENT_TYPE = 'payment_type';
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
// "payment", "mandate", "refund"
|
|
10
|
+
exports.RESOURCE_TYPE = 'resource_type';
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
// "sandbox", "Worldpay", "Smartpay", "ePDQ", "Stripe", "GoCardless"
|
|
13
|
+
exports.PROVIDER = 'provider';
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
// The digital wallet used for a payment
|
|
10
16
|
// Value must be a value of the WalletType enum
|
|
11
17
|
// https://github.com/alphagov/pay-connector/blob/master/src/main/java/uk/gov/pay/connector/wallets/WalletType.java
|
|
18
|
+
exports.WALLET = 'wallet';
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
// The type of a gateway account
|
|
14
21
|
// Value must be a value of the GatewayAccountEntity.Type enum
|
|
15
22
|
// https://github.com/alphagov/pay-connector/blob/master/src/main/java/uk/gov/pay/connector/gatewayaccount/model/GatewayAccountEntity.java
|
|
23
|
+
exports.GATEWAY_ACCOUNT_TYPE = 'gateway_account_type';
|
|
16
24
|
|
|
17
|
-
|
|
25
|
+
// The type of operation being performed with a gateway for a card payment
|
|
18
26
|
// Value must be a value of the OperationType enum
|
|
19
27
|
// https://github.com/alphagov/pay-connector/blob/master/src/main/java/uk/gov/pay/connector/paymentprocessor/model/OperationType.java
|
|
28
|
+
exports.GATEWAY_CARD_OPERATION = 'gateway_card_operation';
|
|
20
29
|
|
|
21
|
-
|
|
30
|
+
// The amount of a payment in pence
|
|
31
|
+
exports.AMOUNT = 'amount';
|
|
22
32
|
|
|
23
|
-
|
|
33
|
+
// Mandate external id
|
|
34
|
+
exports.MANDATE_EXTERNAL_ID = 'mandate_external_id';
|
|
24
35
|
|
|
25
|
-
|
|
36
|
+
// The PSP's identifier for a payment
|
|
37
|
+
exports.PROVIDER_PAYMENT_ID = 'provider_payment_id';
|
|
26
38
|
|
|
27
|
-
|
|
39
|
+
// The ID a provider gives to an event (e.g. one in a notification)
|
|
40
|
+
exports.PROVIDER_EVENT_ID = 'provider_event_id';
|
|
28
41
|
|
|
29
|
-
|
|
42
|
+
// The reference a partner service assigns to a payment, mandate etc.
|
|
43
|
+
exports.SERVICE_PAYMENT_REFERENCE = 'service_reference';
|
|
30
44
|
|
|
31
|
-
|
|
45
|
+
// The ID GOV.UK Pay gives to a gateway account
|
|
46
|
+
exports.GATEWAY_ACCOUNT_ID = 'gateway_account_id';
|
|
32
47
|
|
|
33
|
-
|
|
48
|
+
// The ID of an event emitted to ledger
|
|
49
|
+
exports.LEDGER_EVENT_ID = 'ledger_event_id';
|
|
34
50
|
|
|
35
|
-
|
|
51
|
+
// The type of an event emitted to ledger
|
|
52
|
+
exports.LEDGER_EVENT_TYPE = 'ledger_event_type';
|
|
36
53
|
|
|
37
|
-
|
|
54
|
+
// The type of an internal event recorded by Direct Debit
|
|
38
55
|
// Value must be a value from the GovUkPayEventType enum
|
|
39
56
|
// https://github.com/alphagov/pay-direct-debit-connector/blob/master/src/main/java/uk/gov/pay/directdebit/events/model/GovUkPayEventType.java
|
|
57
|
+
exports.DIRECT_DEBIT_INTERNAL_EVENT_TYPE = 'direct_debit_internal_event_type';
|
|
40
58
|
|
|
41
|
-
|
|
59
|
+
// The current (or new if transitioning) internal state of a payment, mandate etc.
|
|
60
|
+
exports.CURRENT_INTERNAL_STATE = 'current_internal_state';
|
|
42
61
|
|
|
43
|
-
|
|
62
|
+
// The previous internal state of a payment, mandate etc. when transitioning
|
|
63
|
+
exports.PREVIOUS_INTERNAL_STATUS = 'previous_internal_status';
|
|
44
64
|
|
|
45
|
-
|
|
65
|
+
// The last event (status) that Worldpay recorded for a payment, refund etc.
|
|
66
|
+
exports.WORLDPAY_LAST_EVENT = 'worldpay_last_event';
|
|
46
67
|
|
|
47
|
-
|
|
68
|
+
// The result code (status) that Smartpay recorded for a payment, refund etc.
|
|
69
|
+
exports.SMARTPAY_RESULT_CODE = 'smartpay_result_code';
|
|
48
70
|
|
|
49
|
-
|
|
71
|
+
// The status code that ePDQ recorded for a payment, refund etc.
|
|
72
|
+
exports.EPDQ_STATUS = 'epdq_status';
|
|
50
73
|
|
|
51
|
-
|
|
74
|
+
// The status that Stripe recorded for a payment, refund etc.
|
|
75
|
+
exports.STRIPE_STATUS = 'stripe_status';
|
|
52
76
|
|
|
53
|
-
|
|
77
|
+
// The action that GoCardless recorded for a payment, mandate etc.
|
|
78
|
+
exports.GOCARDLESS_PAYMENT_ACTION = 'gocardless_action';
|
|
54
79
|
|
|
55
|
-
|
|
80
|
+
// The HTTP status we sent to a client
|
|
81
|
+
exports.HTTP_STATUS = 'http_status';
|
|
56
82
|
|
|
57
|
-
|
|
83
|
+
// The HTTP status code we received from a remote server (e.g. a payment provider)
|
|
84
|
+
exports.REMOTE_HTTP_STATUS = 'remote_http_status';
|
|
58
85
|
|
|
59
|
-
|
|
86
|
+
// AWS error code
|
|
87
|
+
exports.AWS_ERROR_CODE = 'aws_error_code';
|
|
60
88
|
|
|
61
|
-
|
|
89
|
+
// The correlation id for the request
|
|
90
|
+
exports.CORRELATION_ID = 'x_request_id';
|
|
62
91
|
|
|
63
|
-
|
|
92
|
+
// Payment External Id
|
|
93
|
+
exports.PAYMENT_EXTERNAL_ID = 'payment_external_id';
|
|
64
94
|
|
|
65
|
-
|
|
95
|
+
// Refund External Id
|
|
96
|
+
exports.REFUND_EXTERNAL_ID = 'refund_external_id';
|
|
66
97
|
|
|
67
|
-
|
|
98
|
+
// Secure Token
|
|
99
|
+
exports.SECURE_TOKEN = 'secure_token';
|
|
68
100
|
|
|
69
|
-
|
|
101
|
+
// User external id
|
|
102
|
+
exports.USER_EXTERNAL_ID = 'user_external_id';
|
|
70
103
|
|
|
71
|
-
|
|
104
|
+
// A service's external id
|
|
105
|
+
exports.SERVICE_EXTERNAL_ID = 'service_external_id';
|
|
72
106
|
|
|
73
|
-
|
|
107
|
+
// product external id
|
|
108
|
+
exports.PRODUCT_EXTERNAL_ID = 'product_external_id';
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
module.exports = function () {
|
|
4
4
|
var correlationIdHeader = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'x-request-id';
|
|
5
|
-
|
|
6
5
|
var format = function format(tokens, req, res) {
|
|
7
6
|
return JSON.stringify({
|
|
8
7
|
/* eslint-disable camelcase */
|
|
@@ -18,7 +17,6 @@ module.exports = function () {
|
|
|
18
17
|
response_time: "".concat(tokens['response-time'](req, res), " ms"),
|
|
19
18
|
x_request_id: tokens.req(req, res, correlationIdHeader)
|
|
20
19
|
/* eslint-enable camelcase */
|
|
21
|
-
|
|
22
20
|
});
|
|
23
21
|
};
|
|
24
22
|
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var moment = require('moment-timezone');
|
|
4
|
-
|
|
5
4
|
module.exports = function (isoTimeString, format) {
|
|
6
5
|
var formatString = 'D MMMM YYYY h:mm:ssa z';
|
|
7
|
-
|
|
8
6
|
if (format === 'date') {
|
|
9
7
|
formatString = 'DD/MM/YYYY';
|
|
10
8
|
} else if (format === 'datelong') {
|
|
@@ -12,6 +10,5 @@ module.exports = function (isoTimeString, format) {
|
|
|
12
10
|
} else if (format === 'time') {
|
|
13
11
|
formatString = 'HH:mm:ss';
|
|
14
12
|
}
|
|
15
|
-
|
|
16
13
|
return moment(isoTimeString).tz('Europe/London').format(formatString);
|
|
17
14
|
};
|
package/lib/utils/countries.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var lodash = require('lodash'); // Local Dependencies
|
|
1
|
+
'use strict';
|
|
4
2
|
|
|
3
|
+
// NPM Dependencies
|
|
4
|
+
var lodash = require('lodash');
|
|
5
5
|
|
|
6
|
+
// Local Dependencies
|
|
6
7
|
var countries = require('../data/countries.json');
|
|
8
|
+
var extensions = require('../data/country-record-extension.json');
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
// Merge the additional data into the register data
|
|
11
11
|
countries.forEach(function (country) {
|
|
12
12
|
var extension = extensions.find(function (item) {
|
|
13
13
|
return item.country === country;
|
|
14
14
|
});
|
|
15
|
-
|
|
16
15
|
if (extension) {
|
|
17
16
|
country.entry.aliases = extension.aliases;
|
|
18
17
|
country.entry.weighting = extension.weighting;
|
|
@@ -21,8 +20,9 @@ countries.forEach(function (country) {
|
|
|
21
20
|
countries = lodash.compact(countries);
|
|
22
21
|
countries = lodash.sortBy(countries, function (country) {
|
|
23
22
|
return country.entry.name.toLowerCase();
|
|
24
|
-
});
|
|
23
|
+
});
|
|
25
24
|
|
|
25
|
+
// Exports
|
|
26
26
|
exports.retrieveCountries = function (selectedCountry) {
|
|
27
27
|
var countriesList = lodash.clone(countries);
|
|
28
28
|
countriesList.forEach(function (country) {
|
|
@@ -30,7 +30,6 @@ exports.retrieveCountries = function (selectedCountry) {
|
|
|
30
30
|
});
|
|
31
31
|
return countriesList;
|
|
32
32
|
};
|
|
33
|
-
|
|
34
33
|
exports.govukFrontendFormatted = function (selectedCountry) {
|
|
35
34
|
var countriesList = lodash.clone(countries);
|
|
36
35
|
countriesList.forEach(function (country) {
|
|
@@ -40,7 +39,6 @@ exports.govukFrontendFormatted = function (selectedCountry) {
|
|
|
40
39
|
});
|
|
41
40
|
return countriesList;
|
|
42
41
|
};
|
|
43
|
-
|
|
44
42
|
exports.translateAlpha2 = function (alpha2Code) {
|
|
45
43
|
return countries.find(function (country) {
|
|
46
44
|
return country.entry.country === alpha2Code;
|
|
@@ -1,44 +1,36 @@
|
|
|
1
|
-
'use strict';
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
// Local contants
|
|
3
4
|
var AMOUNT_FORMAT = /^(\d+)(?:\.(\d{1,2}))?$/;
|
|
4
|
-
|
|
5
5
|
var penceToPounds = function penceToPounds(amount) {
|
|
6
6
|
return (amount / 100).toFixed(2);
|
|
7
7
|
};
|
|
8
|
-
|
|
9
8
|
var poundsToPence = function poundsToPence(amount) {
|
|
10
9
|
return (amount * 100).toFixed(0);
|
|
11
10
|
};
|
|
12
|
-
|
|
13
11
|
var penceToPoundsWithCurrency = function penceToPoundsWithCurrency(amount) {
|
|
14
12
|
return new Intl.NumberFormat('en-gb', {
|
|
15
13
|
style: 'currency',
|
|
16
14
|
currency: 'GBP'
|
|
17
15
|
}).format(penceToPounds(amount));
|
|
18
16
|
};
|
|
19
|
-
|
|
20
17
|
var sanitisePoundsAndPenceInput = function sanitisePoundsAndPenceInput(amount) {
|
|
21
18
|
if (amount) {
|
|
22
19
|
var cleanedCurrencyString = amount.replace(/[^0-9.-]+/g, '');
|
|
23
20
|
var result = AMOUNT_FORMAT.exec(cleanedCurrencyString);
|
|
24
|
-
|
|
25
21
|
if (result) {
|
|
26
22
|
var pounds = result[1];
|
|
27
23
|
var pence = result[2];
|
|
28
|
-
|
|
29
24
|
if (pence === undefined) {
|
|
30
25
|
pence = '00';
|
|
31
26
|
} else if (pence.length === 1) {
|
|
32
27
|
pence += '0';
|
|
33
28
|
}
|
|
34
|
-
|
|
35
29
|
return parseInt(pounds + pence, 10);
|
|
36
30
|
}
|
|
37
|
-
|
|
38
31
|
return null;
|
|
39
32
|
}
|
|
40
33
|
};
|
|
41
|
-
|
|
42
34
|
module.exports = {
|
|
43
35
|
penceToPounds: penceToPounds,
|
|
44
36
|
poundsToPence: poundsToPence,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
'use strict';
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var emailValidator = require('./is-valid-email'); // Constants
|
|
3
|
+
// NPM dependencies
|
|
4
|
+
var parseInt = require('lodash/parseInt');
|
|
7
5
|
|
|
6
|
+
// Local dependencies
|
|
7
|
+
var emailValidator = require('./is-valid-email');
|
|
8
8
|
|
|
9
|
+
// Constants
|
|
9
10
|
var NUMBERS_ONLY = /^\d+$/;
|
|
10
11
|
var MAX_AMOUNT = 100000;
|
|
11
12
|
var validationErrors = {
|
|
@@ -19,70 +20,53 @@ var validationErrors = {
|
|
|
19
20
|
isGreaterThanMaxLengthChars: 'The text is too long',
|
|
20
21
|
invalidCharacters: 'You cannot use any of the following characters < > ; : ` ( ) " \' = | , ~ [ ]'
|
|
21
22
|
};
|
|
22
|
-
|
|
23
23
|
exports.isEmpty = function (value) {
|
|
24
24
|
if (value === '') {
|
|
25
25
|
return validationErrors.required;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
27
|
return false;
|
|
29
28
|
};
|
|
30
|
-
|
|
31
29
|
exports.isCurrency = function (value) {
|
|
32
30
|
if (!/^(\d+)(?:\.(\d{1,2}))?$/.test(value)) {
|
|
33
31
|
return validationErrors.currency;
|
|
34
32
|
}
|
|
35
|
-
|
|
36
33
|
return false;
|
|
37
34
|
};
|
|
38
|
-
|
|
39
35
|
exports.isValidEmail = function (value) {
|
|
40
36
|
if (!emailValidator(value)) {
|
|
41
37
|
return validationErrors.validEmail;
|
|
42
38
|
}
|
|
43
|
-
|
|
44
39
|
return false;
|
|
45
40
|
};
|
|
46
|
-
|
|
47
41
|
exports.isPhoneNumber = function (value) {
|
|
48
42
|
var trimmedTelephoneNumber = value.replace(/\s/g, '');
|
|
49
|
-
|
|
50
43
|
if (trimmedTelephoneNumber.length < 11 || !NUMBERS_ONLY.test(trimmedTelephoneNumber)) {
|
|
51
44
|
return validationErrors.phoneNumber;
|
|
52
45
|
}
|
|
53
|
-
|
|
54
46
|
return false;
|
|
55
47
|
};
|
|
56
|
-
|
|
57
48
|
exports.isHttps = function (value) {
|
|
58
49
|
if (value.substr(0, 8) !== 'https://') {
|
|
59
50
|
return validationErrors.isHttps;
|
|
60
51
|
}
|
|
61
|
-
|
|
62
52
|
return false;
|
|
63
53
|
};
|
|
64
|
-
|
|
65
54
|
exports.isAboveMaxAmount = function (value) {
|
|
66
55
|
if (!exports.isCurrency(value) && parseFloat(value) > MAX_AMOUNT) {
|
|
67
56
|
return validationErrors.isAboveMaxAmount;
|
|
68
57
|
}
|
|
69
|
-
|
|
70
58
|
return false;
|
|
71
59
|
};
|
|
72
|
-
|
|
73
60
|
exports.isFieldGreaterThanMaxLengthChars = function (value, maxLength) {
|
|
74
61
|
var parsedMaxLength = parseInt(maxLength);
|
|
75
62
|
return parsedMaxLength && value.length > parsedMaxLength ? validationErrors.isGreaterThanMaxLengthChars : false;
|
|
76
63
|
};
|
|
77
|
-
|
|
78
64
|
exports.isPasswordLessThanTenChars = function (value) {
|
|
79
65
|
return !value || value.length < 10 ? validationErrors.isPasswordLessThanTenChars : false;
|
|
80
66
|
};
|
|
81
|
-
|
|
82
67
|
exports.isNaxsiSafe = function (value) {
|
|
83
68
|
if (/[<>;:`()"'=|,~[\]]+/g.test(value)) {
|
|
84
69
|
return validationErrors.invalidCharacters;
|
|
85
70
|
}
|
|
86
|
-
|
|
87
71
|
return false;
|
|
88
72
|
};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
'use strict';
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
// NPM dependencies
|
|
3
4
|
var rfc822Validator = require('rfc822-validate');
|
|
4
|
-
|
|
5
5
|
module.exports = function (email) {
|
|
6
6
|
if (rfc822Validator(email)) {
|
|
7
7
|
var domain = email.split('@')[1];
|
|
8
8
|
return !(domain && domain.indexOf('.') === -1);
|
|
9
9
|
}
|
|
10
|
-
|
|
11
10
|
return false;
|
|
12
11
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@govuk-pay/pay-js-commons",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.2",
|
|
4
4
|
"description": "Reusable js scripts for GOV.UK Pay Node.js projects",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "^16.14.0"
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"jest": "^27.0.1",
|
|
115
115
|
"jest-environment-jsdom": "^27.0.1",
|
|
116
116
|
"js-cookie": "^3.0.0",
|
|
117
|
-
"jsdom": "^
|
|
117
|
+
"jsdom": "^20.0.1",
|
|
118
118
|
"jsdom-global": "^3.0.2",
|
|
119
119
|
"karma": "^6.0.0",
|
|
120
120
|
"karma-browserify": "^8.0.0",
|
|
@@ -123,21 +123,21 @@
|
|
|
123
123
|
"karma-mocha-reporter": "^2.2.5",
|
|
124
124
|
"karma-source-map-support": "^1.2.0",
|
|
125
125
|
"lint-staged": "^13.0.1",
|
|
126
|
-
"mocha": "^
|
|
126
|
+
"mocha": "^10.0.0",
|
|
127
127
|
"sinon": "^14.0.0",
|
|
128
|
-
"standard": "^
|
|
128
|
+
"standard": "^17.0.0",
|
|
129
129
|
"uglify-js": "^3.6.0",
|
|
130
130
|
"watchify": "^4.0.0",
|
|
131
|
-
"xo": "^0.
|
|
131
|
+
"xo": "^0.52.1"
|
|
132
132
|
},
|
|
133
133
|
"directories": {
|
|
134
134
|
"lib": "lib"
|
|
135
135
|
},
|
|
136
136
|
"dependencies": {
|
|
137
137
|
"lodash": "4.17.21",
|
|
138
|
-
"moment-timezone": "0.5.
|
|
138
|
+
"moment-timezone": "0.5.38",
|
|
139
139
|
"rfc822-validate": "1.0.0",
|
|
140
140
|
"slugify": "1.6.5",
|
|
141
|
-
"winston": "3.8.
|
|
141
|
+
"winston": "3.8.2"
|
|
142
142
|
}
|
|
143
143
|
}
|