@akinon/next 1.92.0-rc.11 → 1.92.0-rc.12

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.92.0-rc.12
4
+
5
+ ### Minor Changes
6
+
7
+ - f7fd459: ZERO-3445: Refactor setCookie function to include domain handling and improve cookie string construction
8
+
3
9
  ## 1.92.0-rc.11
4
10
 
5
11
  ### Minor Changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "1.92.0-rc.11",
4
+ "version": "1.92.0-rc.12",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -34,7 +34,7 @@
34
34
  "set-cookie-parser": "2.6.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@akinon/eslint-plugin-projectzero": "1.92.0-rc.11",
37
+ "@akinon/eslint-plugin-projectzero": "1.92.0-rc.12",
38
38
  "@babel/core": "7.26.10",
39
39
  "@babel/preset-env": "7.26.9",
40
40
  "@babel/preset-typescript": "7.27.0",
package/utils/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import settings from 'settings';
2
2
  import { LocaleUrlStrategy } from '../localization';
3
3
  import { CDNOptions, ClientRequestOptions } from '../types';
4
+ import getRootHostname from './get-root-hostname';
4
5
 
5
6
  export * from './get-currency';
6
7
  export * from './menu-generator';
@@ -20,14 +21,25 @@ export function getCookie(name: string) {
20
21
  }
21
22
  }
22
23
 
23
- export function setCookie(name: string, val: string) {
24
- const date = new Date();
25
- const value = val;
26
-
27
- date.setTime(date.getTime() + 7 * 24 * 60 * 60 * 1000);
28
-
29
- document.cookie =
30
- name + '=' + value + '; expires=' + date.toUTCString() + '; path=/';
24
+ export function setCookie(name: string, value: string) {
25
+ const WEEK_IN_MS = 7 * 24 * 60 * 60 * 1000;
26
+ const hostname = process.env.NEXT_PUBLIC_URL || '';
27
+ const domain =
28
+ localeUrlStrategy === LocaleUrlStrategy.Subdomain
29
+ ? getRootHostname(hostname)
30
+ : null;
31
+ const domainStr = domain ? `Domain=${domain};` : '';
32
+ const expiryDate = new Date();
33
+ expiryDate.setTime(expiryDate.getTime() + WEEK_IN_MS);
34
+
35
+ const cookieString = [
36
+ `${name}=${value}`,
37
+ `expires=${expiryDate.toUTCString()}`,
38
+ `path=/`,
39
+ domainStr
40
+ ].join('; ');
41
+
42
+ document.cookie = cookieString;
31
43
  }
32
44
 
33
45
  export function removeCookie(name: string) {