@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.
@@ -11,17 +11,17 @@ permissions:
11
11
 
12
12
  jobs:
13
13
  unit-tests:
14
- runs-on: ubuntu-18.04
14
+ runs-on: ubuntu-latest
15
15
  name: Unit tests
16
16
 
17
17
  steps:
18
18
  - name: Checkout
19
- uses: actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748
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@9ced9a43a244f3ac94f13bfd896db8c8f30da67a
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>
@@ -0,0 +1,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="USE_PER_PROJECT_SETTINGS" value="true" />
4
+ </state>
5
+ </component>
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="StandardJS" enabled="true" level="ERROR" enabled_by_default="true" />
5
+ </profile>
6
+ </component>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JpaBuddyIdeaProjectConfig">
4
+ <option name="renamerInitialized" value="true" />
5
+ </component>
6
+ </project>
package/.idea/misc.xml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager">
4
+ <output url="file://$PROJECT_DIR$/out" />
5
+ </component>
6
+ <component name="ProjectType">
7
+ <option name="id" value="jpab" />
8
+ </component>
9
+ </project>
@@ -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
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -1,30 +1,23 @@
1
1
  "use strict";
2
2
 
3
3
  var fs = require('fs');
4
-
5
- var Cookies = require('js-cookie'); // eslint-disable-next-line node/no-path-concat
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