@akinon/next 1.42.0-rc.11 → 1.42.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.42.0-rc.12
4
+
5
+ ### Minor Changes
6
+
7
+ - 2d9b2b2: ZERO-2816: Add segment to headers
8
+
3
9
  ## 1.42.0-rc.11
4
10
 
5
11
  ### Minor Changes
package/api/client.ts CHANGED
@@ -4,6 +4,7 @@ import settings from 'settings';
4
4
  import logger from '../utils/log';
5
5
  import formatCookieString from '../utils/format-cookie-string';
6
6
  import cookieParser from 'set-cookie-parser';
7
+ import { cookies } from 'next/headers';
7
8
 
8
9
  interface RouteParams {
9
10
  params: {
@@ -74,6 +75,20 @@ async function proxyRequest(...args) {
74
75
  }
75
76
  } as RequestInit;
76
77
 
78
+ const nextCookies = cookies();
79
+ const segment = nextCookies.get('pz-segment')?.value;
80
+ const currency = nextCookies.get('pz-external-currency')?.value;
81
+
82
+ if (segment) {
83
+ fetchOptions.headers['X-Segment-Id'] = segment;
84
+ }
85
+
86
+ if (currency) {
87
+ fetchOptions.headers = Object.assign({}, fetchOptions.headers, {
88
+ 'x-currency': currency
89
+ });
90
+ }
91
+
77
92
  if (options.contentType) {
78
93
  fetchOptions.headers['Content-Type'] = options.contentType;
79
94
  }
@@ -84,7 +84,10 @@ const withPzDefault =
84
84
  req.nextUrl.pathname.includes('/orders/hooks/') ||
85
85
  req.nextUrl.pathname.includes('/orders/checkout-with-token/')
86
86
  ) {
87
- return NextResponse.rewrite(
87
+ const segment = url.searchParams.get('segment');
88
+ const currency = url.searchParams.get('currency');
89
+
90
+ const response = NextResponse.rewrite(
88
91
  new URL(
89
92
  `${Settings.commerceUrl}${req.nextUrl.pathname.replace(
90
93
  urlLocaleMatcherRegex,
@@ -92,6 +95,16 @@ const withPzDefault =
92
95
  )}`
93
96
  )
94
97
  );
98
+
99
+ if (segment) {
100
+ response.cookies.set('pz-segment', segment);
101
+ }
102
+
103
+ if (currency) {
104
+ response.cookies.set('pz-external-currency', currency);
105
+ }
106
+
107
+ return response;
95
108
  }
96
109
 
97
110
  if (req.nextUrl.pathname.startsWith('/orders/redirection/')) {
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.42.0-rc.11",
4
+ "version": "1.42.0-rc.12",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -30,7 +30,7 @@
30
30
  "set-cookie-parser": "2.6.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@akinon/eslint-plugin-projectzero": "1.42.0-rc.11",
33
+ "@akinon/eslint-plugin-projectzero": "1.42.0-rc.12",
34
34
  "@types/react-redux": "7.1.30",
35
35
  "@types/set-cookie-parser": "2.4.7",
36
36
  "@typescript-eslint/eslint-plugin": "6.7.4",