@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
|
@@ -11,17 +11,17 @@ permissions:
|
|
|
11
11
|
|
|
12
12
|
jobs:
|
|
13
13
|
unit-tests:
|
|
14
|
-
runs-on: ubuntu-
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
15
|
name: Unit tests
|
|
16
16
|
|
|
17
17
|
steps:
|
|
18
18
|
- name: Checkout
|
|
19
|
-
uses: actions/checkout@
|
|
19
|
+
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
|
|
20
20
|
- name: Parse Node version
|
|
21
21
|
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
|
|
22
22
|
id: parse-node-version
|
|
23
23
|
- name: Setup
|
|
24
|
-
uses: actions/setup-node@
|
|
24
|
+
uses: actions/setup-node@969bd2663942d722d85b6a8626225850c2f7be4b
|
|
25
25
|
with:
|
|
26
26
|
node-version: "${{ steps.parse-node-version.outputs.NVMRC }}"
|
|
27
27
|
- name: Cache NPM packages
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
+
<code_scheme name="Project" version="173">
|
|
3
|
+
<JSCodeStyleSettings version="0">
|
|
4
|
+
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
|
|
5
|
+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
6
|
+
<option name="SPACE_BEFORE_GENERATOR_MULT" value="true" />
|
|
7
|
+
<option name="USE_DOUBLE_QUOTES" value="false" />
|
|
8
|
+
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
9
|
+
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
10
|
+
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
11
|
+
</JSCodeStyleSettings>
|
|
12
|
+
<JavaCodeStyleSettings>
|
|
13
|
+
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="1000" />
|
|
14
|
+
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="1000" />
|
|
15
|
+
</JavaCodeStyleSettings>
|
|
16
|
+
<codeStyleSettings language="JavaScript">
|
|
17
|
+
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
|
|
18
|
+
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
|
|
19
|
+
<option name="ALIGN_MULTILINE_FOR" value="false" />
|
|
20
|
+
<option name="SPACE_BEFORE_METHOD_PARENTHESES" value="true" />
|
|
21
|
+
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
|
|
22
|
+
<option name="KEEP_SIMPLE_BLOCKS_IN_ONE_LINE" value="true" />
|
|
23
|
+
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
|
|
24
|
+
<indentOptions>
|
|
25
|
+
<option name="INDENT_SIZE" value="2" />
|
|
26
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
27
|
+
<option name="TAB_SIZE" value="2" />
|
|
28
|
+
</indentOptions>
|
|
29
|
+
</codeStyleSettings>
|
|
30
|
+
</code_scheme>
|
|
31
|
+
</component>
|
package/.idea/misc.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/pay-js-commons.iml" filepath="$PROJECT_DIR$/.idea/pay-js-commons.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="JAVA_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
+
<exclude-output />
|
|
5
|
+
<content url="file://$MODULE_DIR$" />
|
|
6
|
+
<orderEntry type="inheritedJdk" />
|
|
7
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
+
</component>
|
|
9
|
+
</module>
|
package/.idea/vcs.xml
ADDED
|
Binary file
|
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var fs = require('fs');
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var template = fs.readFileSync("".concat(__dirname, "/banner.html"), 'utf-8');
|
|
4
|
+
var Cookies = require('js-cookie');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var template = fs.readFileSync(path.join(__dirname, 'banner.html'), 'utf-8');
|
|
9
7
|
var GOVUK_PAY_ANALYTICS_CONSENT_COOKIE_NAME = 'govuk_pay_cookie_policy';
|
|
10
8
|
var ANALYTICS_CONSENT_BANNER_ID = 'pay-cookie-banner';
|
|
11
|
-
|
|
12
9
|
function hasAnalyticsConsent() {
|
|
13
10
|
var cookie = Cookies.get(GOVUK_PAY_ANALYTICS_CONSENT_COOKIE_NAME);
|
|
14
11
|
var parsed = cookie && JSON.parse(cookie);
|
|
15
12
|
return Boolean(parsed) && parsed.analytics === true;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function getCookieDomain() {
|
|
19
15
|
var PROD_HOSTNAME = 'payments.service.gov.uk';
|
|
20
|
-
|
|
21
16
|
if (window.location.hostname.includes(PROD_HOSTNAME)) {
|
|
22
17
|
return PROD_HOSTNAME;
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
return undefined;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function setAnalyticsCookie() {
|
|
29
22
|
var userConsentedToAnalytics = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
30
23
|
var cookieValue = JSON.stringify({
|
|
@@ -37,19 +30,15 @@ function setAnalyticsCookie() {
|
|
|
37
30
|
};
|
|
38
31
|
Cookies.set(GOVUK_PAY_ANALYTICS_CONSENT_COOKIE_NAME, cookieValue, cookieAttributes);
|
|
39
32
|
}
|
|
40
|
-
|
|
41
33
|
function hideBannerIfExists(event) {
|
|
42
34
|
var banner = document.querySelector("#".concat(ANALYTICS_CONSENT_BANNER_ID));
|
|
43
|
-
|
|
44
35
|
if (banner) {
|
|
45
36
|
banner.style.display = 'none';
|
|
46
37
|
}
|
|
47
|
-
|
|
48
38
|
if (event.target) {
|
|
49
39
|
event.preventDefault();
|
|
50
40
|
}
|
|
51
41
|
}
|
|
52
|
-
|
|
53
42
|
function showConfirmationMessage(analyticsConsent) {
|
|
54
43
|
var messagePrefix = analyticsConsent ? 'You’ve accepted analytics cookies.' : 'You told us not to use analytics cookies.';
|
|
55
44
|
var $cookieBannerMainContent = document.querySelector('.pay-cookie-banner__wrapper');
|
|
@@ -59,17 +48,14 @@ function showConfirmationMessage(analyticsConsent) {
|
|
|
59
48
|
var $cookieBannerConfirmationWrapper = document.querySelector('.pay-cookie-banner__confirmation');
|
|
60
49
|
$cookieBannerConfirmationWrapper.style.display = 'block';
|
|
61
50
|
}
|
|
62
|
-
|
|
63
51
|
function acceptAnalyticsCookies() {
|
|
64
52
|
setAnalyticsCookie(true);
|
|
65
53
|
showConfirmationMessage(true);
|
|
66
54
|
}
|
|
67
|
-
|
|
68
55
|
function rejectAnalyticsCookies() {
|
|
69
56
|
setAnalyticsCookie(false);
|
|
70
57
|
showConfirmationMessage(false);
|
|
71
58
|
}
|
|
72
|
-
|
|
73
59
|
function createBannerHTMLElement() {
|
|
74
60
|
var consentProvidedCallback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
|
|
75
61
|
var banner = document.createElement('div');
|
|
@@ -77,39 +63,31 @@ function createBannerHTMLElement() {
|
|
|
77
63
|
banner.innerHTML = template.trim();
|
|
78
64
|
var acceptButton = banner.querySelector('button[data-accept-cookies=true]');
|
|
79
65
|
var rejectButton = banner.querySelector('button[data-accept-cookies=false]');
|
|
80
|
-
|
|
81
66
|
if (acceptButton && rejectButton) {
|
|
82
67
|
acceptButton.addEventListener('click', acceptAnalyticsCookies);
|
|
83
68
|
acceptButton.addEventListener('click', consentProvidedCallback);
|
|
84
69
|
rejectButton.addEventListener('click', rejectAnalyticsCookies);
|
|
85
70
|
}
|
|
86
|
-
|
|
87
71
|
var hideCookieBannerLink = banner.querySelector('button[data-hide-cookie-banner]');
|
|
88
|
-
|
|
89
72
|
if (hideCookieBannerLink) {
|
|
90
73
|
hideCookieBannerLink.addEventListener('click', hideBannerIfExists);
|
|
91
74
|
}
|
|
92
|
-
|
|
93
75
|
return banner;
|
|
94
76
|
}
|
|
77
|
+
|
|
95
78
|
/**
|
|
96
79
|
* ConsentProvidedCallback: function - generic callback that will be called
|
|
97
80
|
* if and only if the user provides consent
|
|
98
81
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
82
|
function showBannerIfConsentNotSet() {
|
|
102
83
|
var consentProvidedCallback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
|
|
103
84
|
var consentCookieNotSet = !Cookies.get(GOVUK_PAY_ANALYTICS_CONSENT_COOKIE_NAME);
|
|
104
85
|
var banner = document.querySelector("#".concat(ANALYTICS_CONSENT_BANNER_ID));
|
|
105
|
-
|
|
106
86
|
if (consentCookieNotSet && !banner) {
|
|
107
87
|
var _banner = createBannerHTMLElement(consentProvidedCallback);
|
|
108
|
-
|
|
109
88
|
document.body.prepend(_banner);
|
|
110
89
|
}
|
|
111
90
|
}
|
|
112
|
-
|
|
113
91
|
module.exports = {
|
|
114
92
|
hasAnalyticsConsent: hasAnalyticsConsent,
|
|
115
93
|
showBannerIfConsentNotSet: showBannerIfConsentNotSet
|