@ons/design-system 73.4.1 → 73.6.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.
@@ -167,10 +167,27 @@ export function getCookie(name) {
167
167
  return null;
168
168
  }
169
169
 
170
+ function getCookieDomainPolicy() {
171
+ const banner = document.querySelector('.ons-cookies-banner');
172
+ const policy = banner ? banner.getAttribute('data-ons-cookie-domain-policy') : null;
173
+
174
+ // plan: add 'exact-host' policy in future and retire 'legacy' and 'day1'
175
+ switch (policy) {
176
+ case 'legacy':
177
+ case 'day1':
178
+ return policy;
179
+ default:
180
+ return 'legacy';
181
+ }
182
+ }
183
+
170
184
  export function getDomain(domain, cookieHandler = document) {
171
- if (domain.startsWith('www.')) {
185
+ const cookieDomainPolicy = getCookieDomainPolicy();
186
+
187
+ if (cookieDomainPolicy === 'legacy' && domain.startsWith('www.')) {
172
188
  domain = domain.substring(4);
173
189
  }
190
+
174
191
  let i = 0,
175
192
  domainName = domain,
176
193
  p = domainName.split('.'),
@@ -25,6 +25,7 @@ export const setMockcookie = {
25
25
  describe('script: getDomain()', () => {
26
26
  beforeEach(() => {
27
27
  mockCookieStore = {}; // clear the cookie between tests
28
+ document.body.innerHTML = '';
28
29
  });
29
30
 
30
31
  test('should return service-manual.ons.gov.uk as the domain name when cookies can be set at the full subdomain', () => {
@@ -37,6 +38,26 @@ describe('script: getDomain()', () => {
37
38
  expect(result).toBe('ons.gov.uk');
38
39
  });
39
40
 
41
+ test('removes `www` when cookieDomainPolicy is `legacy`', () => {
42
+ const banner = document.createElement('div');
43
+ banner.className = 'ons-cookies-banner';
44
+ banner.setAttribute('data-ons-cookie-domain-policy', 'legacy');
45
+ document.body.appendChild(banner);
46
+
47
+ const result = getDomain('www.ons.gov.uk', setMockcookie);
48
+ expect(result).toBe('ons.gov.uk');
49
+ });
50
+
51
+ test('does not remove `www` when cookieDomainPolicy is `day1`', () => {
52
+ const banner = document.createElement('div');
53
+ banner.className = 'ons-cookies-banner';
54
+ banner.setAttribute('data-ons-cookie-domain-policy', 'day1');
55
+ document.body.appendChild(banner);
56
+
57
+ const result = getDomain('www.ons.gov.uk', setMockcookie);
58
+ expect(result).toBe('www.ons.gov.uk');
59
+ });
60
+
40
61
  test('returns `ons.gov.uk` as the domain name when cookies can not be set at subdomain `new-website.ons.gov.uk`', () => {
41
62
  const result = getDomain('new-website.ons.gov.uk', setMockcookie);
42
63
  expect(result).toBe('ons.gov.uk');
@@ -62,7 +62,7 @@
62
62
  <head>
63
63
  <meta charset="utf-8" />
64
64
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
65
- <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
65
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
66
66
  <title>{{ pageTitle }}</title>
67
67
  <link rel="stylesheet" href="{{ assetsUrl }}/css/main.css" />
68
68
  <link rel="stylesheet" media="print" href="{{ assetsUrl }}/css/print.css" />
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ons/design-system",
3
3
  "description": "ONS Design System built CSS, JS, and Nunjucks templates",
4
- "version": "73.4.1",
4
+ "version": "73.6.0",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -54,17 +54,17 @@
54
54
  "not dead"
55
55
  ],
56
56
  "devDependencies": {
57
- "@babel/core": "7.28.5",
58
- "@babel/eslint-parser": "7.27.1",
59
- "@babel/node": "7.27.1",
57
+ "@babel/core": "7.29.0",
58
+ "@babel/eslint-parser": "7.28.6",
59
+ "@babel/node": "7.29.0",
60
60
  "@babel/plugin-proposal-class-properties": "7.18.6",
61
61
  "@babel/plugin-syntax-dynamic-import": "7.8.3",
62
- "@babel/plugin-transform-modules-commonjs": "7.27.1",
63
- "@babel/plugin-transform-runtime": "7.28.5",
64
- "@babel/preset-env": "7.28.5",
65
- "@babel/register": "7.27.1",
66
- "@babel/runtime": "7.28.4",
67
- "@eslint/eslintrc": "3.3.3",
62
+ "@babel/plugin-transform-modules-commonjs": "7.28.6",
63
+ "@babel/plugin-transform-runtime": "7.29.0",
64
+ "@babel/preset-env": "7.29.3",
65
+ "@babel/register": "7.29.3",
66
+ "@babel/runtime": "7.29.2",
67
+ "@eslint/eslintrc": "3.3.5",
68
68
  "@eslint/js": "9.39.2",
69
69
  "abortcontroller-polyfill": "1.7.8",
70
70
  "autoprefixer": "10.4.21",
@@ -143,6 +143,7 @@
143
143
  "pym.js": "1.3.2"
144
144
  },
145
145
  "resolutions": {
146
- "basic-ftp": "5.2.0"
146
+ "basic-ftp": "5.2.0",
147
+ "axios": "1.15.2"
147
148
  }
148
149
  }